diff options
716 files changed, 0 insertions, 88264 deletions
diff --git a/bundles/org.eclipse.core.databinding.beans/.classpath b/bundles/org.eclipse.core.databinding.beans/.classpath deleted file mode 100644 index ce739334..00000000 --- a/bundles/org.eclipse.core.databinding.beans/.classpath +++ /dev/null @@ -1,7 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" path="src"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/> - <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> - <classpathentry kind="output" path="bin"/> -</classpath> diff --git a/bundles/org.eclipse.core.databinding.beans/.cvsignore b/bundles/org.eclipse.core.databinding.beans/.cvsignore deleted file mode 100644 index ba077a40..00000000 --- a/bundles/org.eclipse.core.databinding.beans/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -bin diff --git a/bundles/org.eclipse.core.databinding.beans/.project b/bundles/org.eclipse.core.databinding.beans/.project deleted file mode 100644 index 85f5bb3c..00000000 --- a/bundles/org.eclipse.core.databinding.beans/.project +++ /dev/null @@ -1,34 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<projectDescription> - <name>org.eclipse.core.databinding.beans</name> - <comment></comment> - <projects> - </projects> - <buildSpec> - <buildCommand> - <name>org.eclipse.jdt.core.javabuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.ManifestBuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.SchemaBuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name> - <arguments> - </arguments> - </buildCommand> - </buildSpec> - <natures> - <nature>org.eclipse.pde.PluginNature</nature> - <nature>org.eclipse.jdt.core.javanature</nature> - <nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature> - </natures> -</projectDescription> diff --git a/bundles/org.eclipse.core.databinding.beans/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.core.databinding.beans/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index a274426d..00000000 --- a/bundles/org.eclipse.core.databinding.beans/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,353 +0,0 @@ -#Mon Dec 03 13:50:43 EST 2007 -eclipse.preferences.version=1 -org.eclipse.jdt.core.builder.cleanOutputFolder=clean -org.eclipse.jdt.core.builder.duplicateResourceTask=warning -org.eclipse.jdt.core.builder.invalidClasspath=abort -org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=*.launch -org.eclipse.jdt.core.circularClasspath=error -org.eclipse.jdt.core.classpath.exclusionPatterns=enabled -org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled -org.eclipse.jdt.core.codeComplete.argumentPrefixes= -org.eclipse.jdt.core.codeComplete.argumentSuffixes= -org.eclipse.jdt.core.codeComplete.fieldPrefixes= -org.eclipse.jdt.core.codeComplete.fieldSuffixes= -org.eclipse.jdt.core.codeComplete.localPrefixes= -org.eclipse.jdt.core.codeComplete.localSuffixes= -org.eclipse.jdt.core.codeComplete.staticFieldPrefixes= -org.eclipse.jdt.core.codeComplete.staticFieldSuffixes= -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.4 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.doc.comment.support=enabled -org.eclipse.jdt.core.compiler.maxProblemPerUnit=100 -org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.autoboxing=ignore -org.eclipse.jdt.core.compiler.problem.deprecation=warning -org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled -org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled -org.eclipse.jdt.core.compiler.problem.discouragedReference=error -org.eclipse.jdt.core.compiler.problem.emptyStatement=warning -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore -org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled -org.eclipse.jdt.core.compiler.problem.fieldHiding=warning -org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning -org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=error -org.eclipse.jdt.core.compiler.problem.forbiddenReference=error -org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=error -org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=error -org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore -org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=error -org.eclipse.jdt.core.compiler.problem.invalidJavadoc=error -org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled -org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled -org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled -org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=private -org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore -org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=error -org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore -org.eclipse.jdt.core.compiler.problem.missingJavadocComments=error -org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled -org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public -org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag -org.eclipse.jdt.core.compiler.problem.missingJavadocTags=error -org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled -org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=protected -org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore -org.eclipse.jdt.core.compiler.problem.missingSerialVersion=error -org.eclipse.jdt.core.compiler.problem.noEffectAssignment=error -org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=error -org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=error -org.eclipse.jdt.core.compiler.problem.nullReference=warning -org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=error -org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore -org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning -org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore -org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning -org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore -org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled -org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=error -org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled -org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore -org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning -org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning -org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore -org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning -org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning -org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning -org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=enabled -org.eclipse.jdt.core.compiler.problem.unusedImport=error -org.eclipse.jdt.core.compiler.problem.unusedLabel=error -org.eclipse.jdt.core.compiler.problem.unusedLocal=error -org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore -org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled -org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=enabled -org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=enabled -org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=error -org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning -org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -org.eclipse.jdt.core.compiler.source=1.3 -org.eclipse.jdt.core.formatter.align_type_members_on_columns=false -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16 -org.eclipse.jdt.core.formatter.alignment_for_assignment=0 -org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 -org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 -org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 -org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0 -org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 -org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 -org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16 -org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 -org.eclipse.jdt.core.formatter.blank_lines_after_imports=1 -org.eclipse.jdt.core.formatter.blank_lines_after_package=1 -org.eclipse.jdt.core.formatter.blank_lines_before_field=0 -org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0 -org.eclipse.jdt.core.formatter.blank_lines_before_imports=1 -org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1 -org.eclipse.jdt.core.formatter.blank_lines_before_method=1 -org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1 -org.eclipse.jdt.core.formatter.blank_lines_before_package=0 -org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1 -org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1 -org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line -org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false -org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false -org.eclipse.jdt.core.formatter.comment.format_block_comments=true -org.eclipse.jdt.core.formatter.comment.format_header=false -org.eclipse.jdt.core.formatter.comment.format_html=true -org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true -org.eclipse.jdt.core.formatter.comment.format_line_comments=true -org.eclipse.jdt.core.formatter.comment.format_source_code=true -org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true -org.eclipse.jdt.core.formatter.comment.indent_root_tags=true -org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert -org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert -org.eclipse.jdt.core.formatter.comment.line_length=80 -org.eclipse.jdt.core.formatter.compact_else_if=true -org.eclipse.jdt.core.formatter.continuation_indentation=2 -org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 -org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true -org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true -org.eclipse.jdt.core.formatter.indent_empty_lines=false -org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true -org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true -org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true -org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false -org.eclipse.jdt.core.formatter.indentation.size=4 -org.eclipse.jdt.core.formatter.insert_new_line_after_annotation=insert -org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert -org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert -org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert -org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert -org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert -org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert -org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert -org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert -org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert -org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert -org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert -org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert -org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert -org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert -org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert -org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false -org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false -org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false -org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false -org.eclipse.jdt.core.formatter.lineSplit=80 -org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false -org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false -org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 -org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 -org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true -org.eclipse.jdt.core.formatter.tabulation.char=tab -org.eclipse.jdt.core.formatter.tabulation.size=4 -org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false -org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true -org.eclipse.jdt.core.incompatibleJDKLevel=ignore -org.eclipse.jdt.core.incompleteClasspath=error diff --git a/bundles/org.eclipse.core.databinding.beans/.settings/org.eclipse.jdt.ui.prefs b/bundles/org.eclipse.core.databinding.beans/.settings/org.eclipse.jdt.ui.prefs deleted file mode 100644 index 75506813..00000000 --- a/bundles/org.eclipse.core.databinding.beans/.settings/org.eclipse.jdt.ui.prefs +++ /dev/null @@ -1,116 +0,0 @@ -#Mon Dec 03 13:50:43 EST 2007 -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_serial_version_id=false -cleanup.always_use_blocks=true -cleanup.always_use_parentheses_in_expressions=false -cleanup.always_use_this_for_non_static_field_access=false -cleanup.always_use_this_for_non_static_method_access=false -cleanup.convert_to_enhanced_for_loop=false -cleanup.correct_indentation=false -cleanup.format_source_code=false -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_variable_declarations_final=false -cleanup.never_use_blocks=false -cleanup.never_use_parentheses_in_expressions=true -cleanup.organize_imports=false -cleanup.qualify_static_field_accesses_with_declaring_class=false -cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true -cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true -cleanup.qualify_static_member_accesses_with_declaring_class=true -cleanup.qualify_static_method_accesses_with_declaring_class=false -cleanup.remove_private_constructors=true -cleanup.remove_trailing_whitespaces=false -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=false -cleanup.use_blocks_only_for_return_and_throw=false -cleanup.use_parentheses_in_expressions=false -cleanup.use_this_for_non_static_field_access=false -cleanup.use_this_for_non_static_field_access_only_if_necessary=true -cleanup.use_this_for_non_static_method_access=false -cleanup.use_this_for_non_static_method_access_only_if_necessary=true -cleanup_profile=org.eclipse.jdt.ui.default.eclipse_clean_up_profile -cleanup_settings_version=2 -eclipse.preferences.version=1 -editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=false -formatter_profile=org.eclipse.jdt.ui.default.eclipse_profile -formatter_settings_version=11 -org.eclipse.jdt.ui.exception.name=e -org.eclipse.jdt.ui.gettersetter.use.is=true -org.eclipse.jdt.ui.ignorelowercasenames=true -org.eclipse.jdt.ui.importorder=java;javax;org;com; -org.eclipse.jdt.ui.javadoc=true -org.eclipse.jdt.ui.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"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\r\n * @return Returns the ${bare_field_name}.\r\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\r\n * @param ${param} The ${bare_field_name} to set.\r\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="true" 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) ${year} IBM Corporation 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 * IBM Corporation - initial API and implementation\r\n ******************************************************************************/\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 * @since 3.3\r\n *\r\n * ${tags}\r\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\r\n * \r\n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="true" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/* (non-Javadoc)\r\n * ${see_to_overridden}\r\n */</template><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\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\r\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\r\n${body_statement}</template><template autoinsert\="true" 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}\r\n// ${todo} Auto-generated constructor stub</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><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\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\r\n * ${tags}\r\n * ${see_to_target}\r\n */</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_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=false -sp_cleanup.format_source_code=false -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_variable_declarations_final=true -sp_cleanup.never_use_blocks=false -sp_cleanup.never_use_parentheses_in_expressions=true -sp_cleanup.on_save_use_additional_actions=false -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=false -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=false -sp_cleanup.remove_unused_imports=false -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=false -sp_cleanup.use_blocks_only_for_return_and_throw=false -sp_cleanup.use_parentheses_in_expressions=false -sp_cleanup.use_this_for_non_static_field_access=false -sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true -sp_cleanup.use_this_for_non_static_method_access=false -sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true diff --git a/bundles/org.eclipse.core.databinding.beans/.settings/org.eclipse.pde.prefs b/bundles/org.eclipse.core.databinding.beans/.settings/org.eclipse.pde.prefs deleted file mode 100644 index 4ea08b3e..00000000 --- a/bundles/org.eclipse.core.databinding.beans/.settings/org.eclipse.pde.prefs +++ /dev/null @@ -1,18 +0,0 @@ -#Mon Dec 03 13:51:14 EST 2007 -compilers.incompatible-environment=1 -compilers.p.build=1 -compilers.p.deprecated=0 -compilers.p.illegal-att-value=0 -compilers.p.missing-bundle-classpath-entries=1 -compilers.p.missing-packages=2 -compilers.p.no-required-att=0 -compilers.p.not-externalized-att=0 -compilers.p.unknown-attribute=0 -compilers.p.unknown-class=0 -compilers.p.unknown-element=1 -compilers.p.unknown-resource=0 -compilers.p.unresolved-ex-points=0 -compilers.p.unresolved-import=0 -compilers.p.unused-element-or-attribute=1 -compilers.use-project=true -eclipse.preferences.version=1 diff --git a/bundles/org.eclipse.core.databinding.beans/META-INF/MANIFEST.MF b/bundles/org.eclipse.core.databinding.beans/META-INF/MANIFEST.MF deleted file mode 100644 index 6601ca6d..00000000 --- a/bundles/org.eclipse.core.databinding.beans/META-INF/MANIFEST.MF +++ /dev/null @@ -1,13 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: %pluginName -Bundle-SymbolicName: org.eclipse.core.databinding.beans -Bundle-Version: 1.1.1.qualifier -Bundle-ClassPath: . -Bundle-Vendor: %providerName -Bundle-Localization: plugin -Export-Package: org.eclipse.core.databinding.beans, - org.eclipse.core.internal.databinding.beans;x-internal:=true -Require-Bundle: org.eclipse.core.databinding;bundle-version="[1.0.0,2.0.0)", - org.eclipse.equinox.common;bundle-version="[3.2.0,4.0.0)" -Bundle-RequiredExecutionEnvironment: J2SE-1.4 diff --git a/bundles/org.eclipse.core.databinding.beans/about.html b/bundles/org.eclipse.core.databinding.beans/about.html deleted file mode 100644 index 46023304..00000000 --- a/bundles/org.eclipse.core.databinding.beans/about.html +++ /dev/null @@ -1,28 +0,0 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml"> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> -<title>About</title> -</head> -<body lang="EN-US"> -<h2>About This Content</h2> - -<p>June 2, 2006</p> -<h3>License</h3> - -<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise -indicated below, the Content is provided to you under the terms and conditions of the -Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available -at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>. -For purposes of the EPL, "Program" will mean the Content.</p> - -<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is -being redistributed by another party ("Redistributor") and different terms and conditions may -apply to your use of any object code in the Content. Check the Redistributor's license that was -provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise -indicated below, the terms and conditions of the EPL still apply to any source code in the Content -and such source code may be obtained at <a href="http://www.eclipse.org">http://www.eclipse.org</a>.</p> - -</body> -</html>
\ No newline at end of file diff --git a/bundles/org.eclipse.core.databinding.beans/build.properties b/bundles/org.eclipse.core.databinding.beans/build.properties deleted file mode 100644 index 6f0a513e..00000000 --- a/bundles/org.eclipse.core.databinding.beans/build.properties +++ /dev/null @@ -1,17 +0,0 @@ -############################################################################### -# Copyright (c) 2006 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -bin.includes = .,\ - META-INF/,\ - plugin.properties,\ - about.html -output.databinding.jar = bin/ -src.includes = about.html -source.. = src/ diff --git a/bundles/org.eclipse.core.databinding.beans/plugin.properties b/bundles/org.eclipse.core.databinding.beans/plugin.properties deleted file mode 100644 index 083e360f..00000000 --- a/bundles/org.eclipse.core.databinding.beans/plugin.properties +++ /dev/null @@ -1,12 +0,0 @@ -############################################################################### -# Copyright (c) 2006 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -pluginName = JFace Data Binding for JavaBeans -providerName = Eclipse.org diff --git a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/BeansObservables.java b/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/BeansObservables.java deleted file mode 100644 index bd05b9e1..00000000 --- a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/BeansObservables.java +++ /dev/null @@ -1,554 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164268, 171616 - * Brad Reynolds - bug 147515 - * Matthew Hall - bug 221704 - * Thomas Kratz - bug 213787 - *******************************************************************************/ -package org.eclipse.core.databinding.beans; - -import java.beans.BeanInfo; -import java.beans.IntrospectionException; -import java.beans.Introspector; -import java.beans.PropertyDescriptor; - -import org.eclipse.core.databinding.BindingException; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.masterdetail.MasterDetailObservables; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.internal.databinding.beans.BeanObservableListDecorator; -import org.eclipse.core.internal.databinding.beans.BeanObservableMapDecorator; -import org.eclipse.core.internal.databinding.beans.BeanObservableSetDecorator; -import org.eclipse.core.internal.databinding.beans.BeanObservableValueDecorator; -import org.eclipse.core.internal.databinding.beans.JavaBeanObservableList; -import org.eclipse.core.internal.databinding.beans.JavaBeanObservableMap; -import org.eclipse.core.internal.databinding.beans.JavaBeanObservableSet; -import org.eclipse.core.internal.databinding.beans.JavaBeanObservableValue; -import org.eclipse.core.internal.databinding.beans.JavaBeanPropertyObservableMap; -import org.eclipse.core.runtime.Assert; - -/** - * A factory for creating observable objects of Java objects that conform to the - * <a href="http://java.sun.com/products/javabeans/docs/spec.html">JavaBean - * specification</a> for bound properties. - * - * @since 1.1 - * - */ -final public class BeansObservables { - - /** - * - */ - public static final boolean DEBUG = true; - - /** - * Returns an observable value in the default realm tracking the current - * value of the named property of the given bean. - * - * @param bean - * the object - * @param propertyName - * the name of the property - * @return an observable value tracking the current value of the named - * property of the given bean - */ - public static IObservableValue observeValue(Object bean, String propertyName) { - return observeValue(Realm.getDefault(), bean, propertyName); - } - - /** - * Returns an observable value in the given realm tracking the current value - * of the named property of the given bean. - * - * @param realm - * the realm - * @param bean - * the object - * @param propertyName - * the name of the property - * @return an observable value tracking the current value of the named - * property of the given bean - */ - public static IObservableValue observeValue(Realm realm, Object bean, - String propertyName) { - PropertyDescriptor descriptor = getPropertyDescriptor(bean.getClass(), - propertyName); - return new JavaBeanObservableValue(realm, bean, descriptor); - } - - /** - * Returns an observable map in the default realm tracking the current - * values of the named property for the beans in the given set. - * - * @param domain - * the set of bean objects - * @param beanClass - * the common base type of bean objects that may be in the set - * @param propertyName - * the name of the property - * @return an observable map tracking the current values of the named - * property for the beans in the given domain set - */ - public static IObservableMap observeMap(IObservableSet domain, - Class beanClass, String propertyName) { - PropertyDescriptor descriptor = getPropertyDescriptor(beanClass, - propertyName); - return new JavaBeanObservableMap(domain, descriptor); - } - - /** - * Returns an observable map in the given realm tracking the map-typed named - * property of the given bean object. - * - * @param realm - * the realm - * @param bean - * the bean object - * @param propertyName - * the name of the property - * @return an observable map tracking the map-typed named property of the - * given bean object - * @since 1.1 - */ - public static IObservableMap observeMap(Realm realm, Object bean, - String propertyName) { - PropertyDescriptor descriptor = getPropertyDescriptor(bean.getClass(), - propertyName); - return new JavaBeanPropertyObservableMap(realm, bean, descriptor); - } - - /*package*/ static PropertyDescriptor getPropertyDescriptor(Class beanClass, - String propertyName) { - BeanInfo beanInfo; - try { - beanInfo = Introspector.getBeanInfo(beanClass); - } catch (IntrospectionException e) { - // cannot introspect, give up - return null; - } - PropertyDescriptor[] propertyDescriptors = beanInfo - .getPropertyDescriptors(); - for (int i = 0; i < propertyDescriptors.length; i++) { - PropertyDescriptor descriptor = propertyDescriptors[i]; - if (descriptor.getName().equals(propertyName)) { - return descriptor; - } - } - throw new BindingException( - "Could not find property with name " + propertyName + " in class " + beanClass); //$NON-NLS-1$ //$NON-NLS-2$ - } - - /** - * Returns an array of observable maps in the default realm tracking the - * current values of the named propertys for the beans in the given set. - * - * @param domain - * the set of objects - * @param beanClass - * the common base type of objects that may be in the set - * @param propertyNames - * the array of property names - * @return an array of observable maps tracking the current values of the - * named propertys for the beans in the given domain set - */ - public static IObservableMap[] observeMaps(IObservableSet domain, - Class beanClass, String[] propertyNames) { - IObservableMap[] result = new IObservableMap[propertyNames.length]; - for (int i = 0; i < propertyNames.length; i++) { - result[i] = observeMap(domain, beanClass, propertyNames[i]); - } - return result; - } - - /** - * Returns an observable list in the given realm tracking the - * collection-typed named property of the given bean object. The returned - * list is mutable. - * - * @param realm - * the realm - * @param bean - * the object - * @param propertyName - * the name of the collection-typed property - * @return an observable list tracking the collection-typed named property - * of the given bean object - * @see #observeList(Realm, Object, String, Class) - */ - public static IObservableList observeList(Realm realm, Object bean, - String propertyName) { - return observeList(realm, bean, propertyName, null); - } - - /** - * Returns an observable list in the given realm tracking the - * collection-typed named property of the given bean object. The returned - * list is mutable. When an item is added or removed the setter is invoked - * for the list on the parent bean to provide notification to other - * listeners via <code>PropertyChangeEvents</code>. This is done to - * provide the same behavior as is expected from arrays as specified in the - * bean spec in section 7.2. - * - * @param realm - * the realm - * @param bean - * the bean object - * @param propertyName - * the name of the property - * @param elementType - * type of the elements in the list. If <code>null</code> and - * the property is an array the type will be inferred. If - * <code>null</code> and the property type cannot be inferred - * element type will be <code>null</code>. - * @return an observable list tracking the collection-typed named property - * of the given bean object - */ - public static IObservableList observeList(Realm realm, Object bean, - String propertyName, Class elementType) { - PropertyDescriptor propertyDescriptor = getPropertyDescriptor(bean - .getClass(), propertyName); - elementType = getCollectionElementType(elementType, propertyDescriptor); - - return new JavaBeanObservableList(realm, bean, propertyDescriptor, - elementType); - } - - /** - * Returns an observable set in the given realm tracking the - * collection-typed named property of the given bean object - * - * @param realm - * the realm - * @param bean - * the bean object - * @param propertyName - * the name of the property - * @return an observable set tracking the collection-typed named property of - * the given bean object - */ - public static IObservableSet observeSet(Realm realm, Object bean, - String propertyName) { - return observeSet(realm, bean, propertyName, null); - } - - /** - * Returns a factory for creating obervable values tracking the given - * property of a particular bean object - * - * @param realm - * the realm to use - * @param propertyName - * the name of the property - * @return an observable value factory - */ - public static IObservableFactory valueFactory(final Realm realm, - final String propertyName) { - return new IObservableFactory() { - public IObservable createObservable(Object target) { - return observeValue(realm, target, propertyName); - } - }; - } - - /** - * Returns a factory for creating obervable lists tracking the given - * property of a particular bean object - * - * @param realm - * the realm to use - * @param propertyName - * the name of the property - * @param elementType - * @return an observable list factory - */ - public static IObservableFactory listFactory(final Realm realm, - final String propertyName, final Class elementType) { - return new IObservableFactory() { - public IObservable createObservable(Object target) { - return observeList(realm, target, propertyName, elementType); - } - }; - } - - /** - * Returns a factory for creating obervable sets tracking the given property - * of a particular bean object - * - * @param realm - * the realm to use - * @param propertyName - * the name of the property - * @return an observable set factory - */ - public static IObservableFactory setFactory(final Realm realm, - final String propertyName) { - return new IObservableFactory() { - public IObservable createObservable(Object target) { - return observeSet(realm, target, propertyName); - } - }; - } - - /** - * Helper method for - * <code>MasterDetailObservables.detailValue(master, valueFactory(realm, - propertyName), propertyType)</code> - * - * @param realm - * @param master - * @param propertyName - * @param propertyType - * can be <code>null</code> - * @return an observable value that tracks the current value of the named - * property for the current value of the master observable value - * - * @see MasterDetailObservables - */ - public static IObservableValue observeDetailValue(Realm realm, - IObservableValue master, String propertyName, Class propertyType) { - - IObservableValue value = MasterDetailObservables.detailValue(master, - valueFactory(realm, propertyName), propertyType); - BeanObservableValueDecorator decorator = new BeanObservableValueDecorator( - value, master, getValueTypePropertyDescriptor(master, - propertyName)); - - return decorator; - } - - /** - * Helper method for - * <code>MasterDetailObservables.detailValue(master, valueFactory(realm, - * propertyName), propertyType)</code>. - * This method returns an {@link IBeanObservable} with a - * {@link PropertyDescriptor} based on the given master type and property - * name. - * - * @param realm - * the realm - * @param master - * the master observable value, for example tracking the - * selection in a list - * @param masterType - * the type of the master observable value - * @param propertyName - * the property name - * @param propertyType - * can be <code>null</code> - * @return an observable value that tracks the current value of the named - * property for the current value of the master observable value - * - * @see MasterDetailObservables - * @since 1.1 - */ - public static IObservableValue observeDetailValue(Realm realm, - IObservableValue master, Class masterType, String propertyName, Class propertyType) { - Assert.isNotNull(masterType, "masterType cannot be null"); //$NON-NLS-1$ - IObservableValue value = MasterDetailObservables.detailValue(master, - valueFactory(realm, propertyName), propertyType); - BeanObservableValueDecorator decorator = new BeanObservableValueDecorator( - value, master, getPropertyDescriptor(masterType, - propertyName)); - - return decorator; - } - - /** - * Helper method for - * <code>MasterDetailObservables.detailList(master, listFactory(realm, - propertyName, propertyType), propertyType)</code> - * - * @param realm - * @param master - * @param propertyName - * @param propertyType - * can be <code>null</code> - * @return an observable list that tracks the named property for the current - * value of the master observable value - * - * @see MasterDetailObservables - */ - public static IObservableList observeDetailList(Realm realm, - IObservableValue master, String propertyName, Class propertyType) { - IObservableList observableList = MasterDetailObservables.detailList( - master, listFactory(realm, propertyName, propertyType), - propertyType); - BeanObservableListDecorator decorator = new BeanObservableListDecorator( - observableList, master, getValueTypePropertyDescriptor(master, - propertyName)); - - return decorator; - } - - /** - * Helper method for - * <code>MasterDetailObservables.detailSet(master, setFactory(realm, - propertyName), propertyType)</code> - * - * @param realm - * @param master - * @param propertyName - * @param propertyType - * can be <code>null</code> - * @return an observable set that tracks the named property for the current - * value of the master observable value - * - * @see MasterDetailObservables - */ - public static IObservableSet observeDetailSet(Realm realm, - IObservableValue master, String propertyName, Class propertyType) { - - IObservableSet observableSet = MasterDetailObservables.detailSet( - master, setFactory(realm, propertyName, propertyType), - propertyType); - BeanObservableSetDecorator decorator = new BeanObservableSetDecorator( - observableSet, master, getValueTypePropertyDescriptor(master, - propertyName)); - - return decorator; - } - - /** - * Helper method for - * <code>MasterDetailObservables.detailMap(master, mapFactory(realm, propertyName))</code> - * - * @param realm - * the realm - * @param master - * @param propertyName - * @return an observable map that tracks the map-type named property for the - * current value of the master observable value. - * @since 1.1 - */ - public static IObservableMap observeDetailMap(Realm realm, - IObservableValue master, String propertyName) { - IObservableMap observableMap = MasterDetailObservables.detailMap( - master, mapPropertyFactory(realm, propertyName)); - BeanObservableMapDecorator decorator = new BeanObservableMapDecorator( - observableMap, master, getValueTypePropertyDescriptor(master, - propertyName)); - return decorator; - } - - /** - * @param realm - * @param bean - * @param propertyName - * @param elementType - * can be <code>null</code> - * @return an observable set that tracks the current value of the named - * property for given bean object - */ - public static IObservableSet observeSet(Realm realm, Object bean, - String propertyName, Class elementType) { - PropertyDescriptor propertyDescriptor = getPropertyDescriptor(bean - .getClass(), propertyName); - elementType = getCollectionElementType(elementType, propertyDescriptor); - - return new JavaBeanObservableSet(realm, bean, propertyDescriptor, - elementType); - } - - /** - * @param realm - * @param propertyName - * @param elementType - * can be <code>null</code> - * @return an observable set factory for creating observable sets - */ - public static IObservableFactory setFactory(final Realm realm, - final String propertyName, final Class elementType) { - return new IObservableFactory() { - public IObservable createObservable(Object target) { - return observeSet(realm, target, propertyName, elementType); - } - }; - } - - /** - * Returns a factory for creating an observable map. The factory, when - * provided with an {@link IObservableSet}, will create an - * {@link IObservableMap} in the same realm as the underlying set that - * tracks the current values of the named property for the beans in the - * given set. - * - * @param beanClass - * the common base type of bean objects that may be in the set - * @param propertyName - * the name of the property - * @return a factory for creating {@link IObservableMap} objects - * - * @since 1.1 - */ - public static IObservableFactory setToMapFactory(final Class beanClass, final String propertyName) { - return new IObservableFactory() { - public IObservable createObservable(Object target) { - return observeMap((IObservableSet) target, beanClass, propertyName); - } - }; - } - - /** - * Returns a factory for creating an observable map. The factory, when - * provided with a bean object, will create an {@link IObservableMap} in the - * given realm that tracks the map-typed named property for the specified - * bean. - * - * @param realm - * the realm assigned to observables created by the returned - * factory. - * @param propertyName - * the name of the property - * @return a factory for creating {@link IObservableMap} objects. - * @since 1.1 - */ - public static IObservableFactory mapPropertyFactory(final Realm realm, - final String propertyName) { - return new IObservableFactory() { - public IObservable createObservable(Object target) { - return observeMap(realm, target, propertyName); - } - }; - } - - /** - * @param elementType - * can be <code>null</code> - * @param propertyDescriptor - * @return type of the items in a collection/array property - */ - /*package*/ static Class getCollectionElementType(Class elementType, - PropertyDescriptor propertyDescriptor) { - if (elementType == null) { - Class propertyType = propertyDescriptor.getPropertyType(); - elementType = propertyType.isArray() ? propertyType - .getComponentType() : Object.class; - } - - return elementType; - } - - /** - * @param observable - * @param propertyName - * @return property descriptor or <code>null</code> - */ - /* package*/ static PropertyDescriptor getValueTypePropertyDescriptor( - IObservableValue observable, String propertyName) { - return (observable.getValueType() != null) ? getPropertyDescriptor( - (Class) observable.getValueType(), propertyName) : null; - } -} diff --git a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/IBeanObservable.java b/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/IBeanObservable.java deleted file mode 100644 index c2545ef4..00000000 --- a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/IBeanObservable.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Brad Reynolds - bug 147515 - ******************************************************************************/ - -package org.eclipse.core.databinding.beans; - -import java.beans.PropertyDescriptor; - -import org.eclipse.core.databinding.observable.IObserving; - -/** - * Provides access to details of bean observables. - * <p> - * This interface is not meant to be implemented by clients. - * </p> - * - * @since 3.3 - */ -public interface IBeanObservable extends IObserving { - /** - * @return property descriptor of the property being observed, - * <code>null</code> if the runtime time information was not - * provided on construction of the observable - */ - public PropertyDescriptor getPropertyDescriptor(); -} diff --git a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/PojoObservables.java b/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/PojoObservables.java deleted file mode 100644 index cb508224..00000000 --- a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/PojoObservables.java +++ /dev/null @@ -1,433 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 221704 - *******************************************************************************/ - -package org.eclipse.core.databinding.beans; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyDescriptor; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.masterdetail.MasterDetailObservables; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.internal.databinding.beans.BeanObservableListDecorator; -import org.eclipse.core.internal.databinding.beans.BeanObservableMapDecorator; -import org.eclipse.core.internal.databinding.beans.BeanObservableSetDecorator; -import org.eclipse.core.internal.databinding.beans.BeanObservableValueDecorator; -import org.eclipse.core.internal.databinding.beans.JavaBeanObservableList; -import org.eclipse.core.internal.databinding.beans.JavaBeanObservableMap; -import org.eclipse.core.internal.databinding.beans.JavaBeanObservableSet; -import org.eclipse.core.internal.databinding.beans.JavaBeanObservableValue; -import org.eclipse.core.internal.databinding.beans.JavaBeanPropertyObservableMap; - -/** - * A factory for creating observable objects for POJOs (plain old java objects) - * that conform to idea of an object with getters and setters but does not - * provide {@link PropertyChangeEvent property change events} on change. This - * factory is identical to {@link BeansObservables} except for this fact. - * - * @since 1.1 - */ -final public class PojoObservables { - - /** - * Returns an observable value in the default realm tracking the current - * value of the named property of the given pojo. - * - * @param pojo - * the object - * @param propertyName - * the name of the property - * @return an observable value tracking the current value of the named - * property of the given pojo - */ - public static IObservableValue observeValue(Object pojo, String propertyName) { - return observeValue(Realm.getDefault(), pojo, propertyName); - } - - /** - * Returns an observable value in the given realm tracking the current value - * of the named property of the given pojo. - * - * @param realm - * the realm - * @param pojo - * the object - * @param propertyName - * the name of the property - * @return an observable value tracking the current value of the named - * property of the given pojo - */ - public static IObservableValue observeValue(Realm realm, Object pojo, - String propertyName) { - - PropertyDescriptor descriptor = BeansObservables.getPropertyDescriptor( - pojo.getClass(), propertyName); - return new JavaBeanObservableValue(realm, pojo, descriptor, false); - } - - /** - * Returns an observable map in the default realm tracking the current - * values of the named property for the pojos in the given set. - * - * @param domain - * the set of pojo objects - * @param pojoClass - * the common base type of pojo objects that may be in the set - * @param propertyName - * the name of the property - * @return an observable map tracking the current values of the named - * property for the pojos in the given domain set - */ - public static IObservableMap observeMap(IObservableSet domain, - Class pojoClass, String propertyName) { - PropertyDescriptor descriptor = BeansObservables.getPropertyDescriptor( - pojoClass, propertyName); - return new JavaBeanObservableMap(domain, descriptor, false); - } - - /** - * Returns an array of observable maps in the default realm tracking the - * current values of the named propertys for the pojos in the given set. - * - * @param domain - * the set of objects - * @param pojoClass - * the common base type of objects that may be in the set - * @param propertyNames - * the array of property names - * @return an array of observable maps tracking the current values of the - * named propertys for the pojos in the given domain set - */ - public static IObservableMap[] observeMaps(IObservableSet domain, - Class pojoClass, String[] propertyNames) { - IObservableMap[] result = new IObservableMap[propertyNames.length]; - for (int i = 0; i < propertyNames.length; i++) { - result[i] = observeMap(domain, pojoClass, propertyNames[i]); - } - return result; - } - - /** - * Returns an observable map in the given realm tracking the map-typed named - * property of the given pojo object. - * - * @param realm - * the realm - * @param pojo - * the pojo object - * @param propertyName - * the name of the property - * @return an observable map tracking the map-typed named property of the - * given pojo object - */ - public static IObservableMap observeMap(Realm realm, Object pojo, - String propertyName) { - PropertyDescriptor descriptor = BeansObservables.getPropertyDescriptor( - pojo.getClass(), propertyName); - return new JavaBeanPropertyObservableMap(realm, pojo, descriptor, false); - } - - /** - * Returns an observable list in the given realm tracking the - * collection-typed named property of the given pojo object. The returned - * list is mutable. - * - * @param realm - * the realm - * @param pojo - * the object - * @param propertyName - * the name of the collection-typed property - * @return an observable list tracking the collection-typed named property - * of the given pojo object - * @see #observeList(Realm, Object, String, Class) - */ - public static IObservableList observeList(Realm realm, Object pojo, - String propertyName) { - return observeList(realm, pojo, propertyName, null); - } - - /** - * Returns an observable list in the given realm tracking the - * collection-typed named property of the given bean object. The returned - * list is mutable. When an item is added or removed the setter is invoked - * for the list on the parent bean to provide notification to other - * listeners via <code>PropertyChangeEvents</code>. This is done to - * provide the same behavior as is expected from arrays as specified in the - * bean spec in section 7.2. - * - * @param realm - * the realm - * @param pojo - * the bean object - * @param propertyName - * the name of the property - * @param elementType - * type of the elements in the list. If <code>null</code> and - * the property is an array the type will be inferred. If - * <code>null</code> and the property type cannot be inferred - * element type will be <code>null</code>. - * @return an observable list tracking the collection-typed named property - * of the given bean object - */ - public static IObservableList observeList(Realm realm, Object pojo, - String propertyName, Class elementType) { - PropertyDescriptor propertyDescriptor = BeansObservables - .getPropertyDescriptor(pojo.getClass(), propertyName); - elementType = BeansObservables.getCollectionElementType(elementType, - propertyDescriptor); - - return new JavaBeanObservableList(realm, pojo, propertyDescriptor, - elementType, false); - } - - /** - * Returns an observable set in the given realm tracking the - * collection-typed named property of the given pojo object. - * - * @param realm - * the realm - * @param pojo - * the pojo object - * @param propertyName - * the name of the property - * @return an observable set tracking the collection-typed named property of - * the given pojo object - */ - public static IObservableSet observeSet(Realm realm, Object pojo, - String propertyName) { - return observeSet(realm, pojo, propertyName, null); - } - - /** - * @param realm - * @param pojo - * @param propertyName - * @param elementType - * can be <code>null</code> - * @return an observable set that tracks the current value of the named - * property for given pojo object - */ - public static IObservableSet observeSet(Realm realm, Object pojo, - String propertyName, Class elementType) { - PropertyDescriptor propertyDescriptor = BeansObservables - .getPropertyDescriptor(pojo.getClass(), propertyName); - elementType = BeansObservables.getCollectionElementType(elementType, - propertyDescriptor); - - return new JavaBeanObservableSet(realm, pojo, propertyDescriptor, - elementType, false); - } - - /** - * Returns a factory for creating obervable values tracking the given - * property of a particular pojo object - * - * @param realm - * the realm to use - * @param propertyName - * the name of the property - * @return an observable value factory - */ - public static IObservableFactory valueFactory(final Realm realm, - final String propertyName) { - return new IObservableFactory() { - public IObservable createObservable(Object target) { - return observeValue(realm, target, propertyName); - } - }; - } - - /** - * Returns a factory for creating obervable lists tracking the given - * property of a particular pojo object - * - * @param realm - * the realm to use - * @param propertyName - * the name of the property - * @param elementType - * @return an observable list factory - */ - public static IObservableFactory listFactory(final Realm realm, - final String propertyName, final Class elementType) { - return new IObservableFactory() { - public IObservable createObservable(Object target) { - return observeList(realm, target, propertyName, elementType); - } - }; - } - - /** - * Returns a factory for creating obervable sets tracking the given property - * of a particular pojo object - * - * @param realm - * the realm to use - * @param propertyName - * the name of the property - * @return an observable set factory - */ - public static IObservableFactory setFactory(final Realm realm, - final String propertyName) { - return new IObservableFactory() { - public IObservable createObservable(Object target) { - return observeSet(realm, target, propertyName); - } - }; - } - - /** - * @param realm - * @param propertyName - * @param elementType - * can be <code>null</code> - * @return an observable set factory for creating observable sets - */ - public static IObservableFactory setFactory(final Realm realm, - final String propertyName, final Class elementType) { - return new IObservableFactory() { - public IObservable createObservable(Object target) { - return observeSet(realm, target, propertyName, elementType); - } - }; - } - - /** - * Returns a factory for creating an observable map. The factory, when - * provided with a pojo object, will create an {@link IObservableMap} in the - * given realm that tracks the map-typed named property for the specified - * pojo. - * - * @param realm - * the realm assigned to observables created by the returned - * factory. - * @param propertyName - * the name of the property - * @return a factory for creating {@link IObservableMap} objects. - */ - public static IObservableFactory mapPropertyFactory(final Realm realm, - final String propertyName) { - return new IObservableFactory() { - public IObservable createObservable(Object target) { - return observeMap(realm, target, propertyName); - } - }; - } - - /** - * Helper method for - * <code>MasterDetailObservables.detailValue(master, valueFactory(realm, - propertyName), propertyType)</code> - * - * @param realm - * @param master - * @param propertyName - * @param propertyType - * can be <code>null</code> - * @return an observable value that tracks the current value of the named - * property for the current value of the master observable value - * - * @see MasterDetailObservables - */ - public static IObservableValue observeDetailValue(Realm realm, - IObservableValue master, String propertyName, Class propertyType) { - - IObservableValue value = MasterDetailObservables.detailValue(master, - valueFactory(realm, propertyName), propertyType); - BeanObservableValueDecorator decorator = new BeanObservableValueDecorator( - value, master, BeansObservables.getValueTypePropertyDescriptor( - master, propertyName)); - - return decorator; - } - - /** - * Helper method for - * <code>MasterDetailObservables.detailList(master, listFactory(realm, - propertyName, propertyType), propertyType)</code> - * - * @param realm - * @param master - * @param propertyName - * @param propertyType - * can be <code>null</code> - * @return an observable list that tracks the named property for the current - * value of the master observable value - * - * @see MasterDetailObservables - */ - public static IObservableList observeDetailList(Realm realm, - IObservableValue master, String propertyName, Class propertyType) { - IObservableList observableList = MasterDetailObservables.detailList( - master, listFactory(realm, propertyName, propertyType), - propertyType); - BeanObservableListDecorator decorator = new BeanObservableListDecorator( - observableList, master, BeansObservables - .getValueTypePropertyDescriptor(master, propertyName)); - - return decorator; - } - - /** - * Helper method for - * <code>MasterDetailObservables.detailSet(master, setFactory(realm, - propertyName), propertyType)</code> - * - * @param realm - * @param master - * @param propertyName - * @param propertyType - * can be <code>null</code> - * @return an observable set that tracks the named property for the current - * value of the master observable value - * - * @see MasterDetailObservables - */ - public static IObservableSet observeDetailSet(Realm realm, - IObservableValue master, String propertyName, Class propertyType) { - - IObservableSet observableSet = MasterDetailObservables.detailSet( - master, setFactory(realm, propertyName, propertyType), - propertyType); - BeanObservableSetDecorator decorator = new BeanObservableSetDecorator( - observableSet, master, BeansObservables - .getValueTypePropertyDescriptor(master, propertyName)); - - return decorator; - } - - /** - * Helper method for - * <code>MasterDetailObservables.detailMap(master, mapFactory(realm, propertyName))</code> - * - * @param realm - * @param master - * @param propertyName - * @return an observable map that tracks the map-type named property for the - * current value of the master observable value. - */ - public static IObservableMap observeDetailMap(Realm realm, - IObservableValue master, String propertyName) { - IObservableMap observableMap = MasterDetailObservables.detailMap( - master, mapPropertyFactory(realm, propertyName)); - BeanObservableMapDecorator decorator = new BeanObservableMapDecorator( - observableMap, master, BeansObservables - .getValueTypePropertyDescriptor(master, propertyName)); - return decorator; - } -} diff --git a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/package.html b/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/package.html deleted file mode 100644 index c290e497..00000000 --- a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/package.html +++ /dev/null @@ -1,16 +0,0 @@ -<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> - <meta name="Author" content="IBM"> - <meta name="GENERATOR" content="Mozilla/4.5 [en] (Win98; I) [Netscape]"> - <title>Package-level Javadoc</title> -</head> -<body> -Provides classes for observing JavaBeans(tm) objects. -<h2> -Package Specification</h2> -<p> -This package provides classes that can be used to observe objects that conform to the <a href="http://java.sun.com/products/javabeans/docs/spec.html">JavaBean specification</a> for bound properties.</p> -</body> -</html> diff --git a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/BeanObservableListDecorator.java b/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/BeanObservableListDecorator.java deleted file mode 100644 index 42fd0ae6..00000000 --- a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/BeanObservableListDecorator.java +++ /dev/null @@ -1,229 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bugs 208858, 245183 - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.beans; - -import java.beans.PropertyDescriptor; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.eclipse.core.databinding.beans.IBeanObservable; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.databinding.observable.list.AbstractObservableList; -import org.eclipse.core.databinding.observable.list.IListChangeListener; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.ListChangeEvent; -import org.eclipse.core.internal.databinding.Util; - -/** - * {@link IBeanObservable} decorator for an {@link IObservableList}. - * - * @since 3.3 - */ -public class BeanObservableListDecorator extends AbstractObservableList - implements IBeanObservable { - private IObservableList delegate; - private IStaleListener delegateStaleListener; - private IListChangeListener delegateListChangeListener; - - private Object observed; - private PropertyDescriptor propertyDescriptor; - - /** - * @param delegate - * @param observed - * @param propertyDescriptor - */ - public BeanObservableListDecorator(IObservableList delegate, - Object observed, PropertyDescriptor propertyDescriptor) { - super(delegate.getRealm()); - this.delegate = delegate; - this.observed = observed; - this.propertyDescriptor = propertyDescriptor; - } - - public void add(int index, Object element) { - delegate.add(index, element); - } - - public boolean add(Object o) { - return delegate.add(o); - } - - public boolean addAll(Collection c) { - return delegate.addAll(c); - } - - public boolean addAll(int index, Collection c) { - return delegate.addAll(index, c); - } - - public void clear() { - delegate.clear(); - } - - public void dispose() { - delegate.dispose(); - super.dispose(); - } - - public boolean equals(Object o) { - getterCalled(); - if (o == this) - return true; - if (o == null) - return true; - if (getClass() == o.getClass()) { - BeanObservableListDecorator other = (BeanObservableListDecorator) o; - return Util.equals(other.delegate, delegate); - } - return delegate.equals(o); - } - - public Object get(int index) { - getterCalled(); - return delegate.get(index); - } - - public Object getElementType() { - return delegate.getElementType(); - } - - public int hashCode() { - getterCalled(); - return delegate.hashCode(); - } - - public int indexOf(Object o) { - getterCalled(); - return delegate.indexOf(o); - } - - public Iterator iterator() { - getterCalled(); - return delegate.iterator(); - } - - public int lastIndexOf(Object o) { - getterCalled(); - return delegate.lastIndexOf(o); - } - - public ListIterator listIterator() { - getterCalled(); - return delegate.listIterator(); - } - - public ListIterator listIterator(int index) { - getterCalled(); - return delegate.listIterator(index); - } - - public Object move(int oldIndex, int newIndex) { - return delegate.move(oldIndex, newIndex); - } - - public Object remove(int index) { - return delegate.remove(index); - } - - public boolean remove(Object o) { - return delegate.remove(o); - } - - public boolean removeAll(Collection c) { - return delegate.removeAll(c); - } - - public boolean retainAll(Collection c) { - return delegate.retainAll(c); - } - - public Object set(int index, Object element) { - return delegate.set(index, element); - } - - protected int doGetSize() { - return delegate.size(); - } - - public List subList(int fromIndex, int toIndex) { - getterCalled(); - return delegate.subList(fromIndex, toIndex); - } - - public Object[] toArray() { - getterCalled(); - return delegate.toArray(); - } - - public Object[] toArray(Object[] a) { - return delegate.toArray(a); - } - - protected void firstListenerAdded() { - delegateStaleListener = new IStaleListener() { - public void handleStale(StaleEvent staleEvent) { - fireStale(); - } - }; - delegate.addStaleListener(delegateStaleListener); - - delegateListChangeListener = new IListChangeListener() { - public void handleListChange(ListChangeEvent event) { - fireListChange(event.diff); - } - }; - delegate.addListChangeListener(delegateListChangeListener); - } - - protected void lastListenerRemoved() { - delegate.removeStaleListener(delegateStaleListener); - delegateStaleListener = null; - - delegate.removeListChangeListener(delegateListChangeListener); - delegateListChangeListener = null; - } - - private void getterCalled() { - ObservableTracker.getterCalled(this); - } - - /** - * @return list being delegated to - */ - public IObservableList getDelegate() { - return delegate; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.beans.IBeanObservable#getObserved() - */ - public Object getObserved() { - return observed; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.beans.IBeanObservable#getPropertyDescriptor() - */ - public PropertyDescriptor getPropertyDescriptor() { - return propertyDescriptor; - } -} diff --git a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/BeanObservableMapDecorator.java b/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/BeanObservableMapDecorator.java deleted file mode 100644 index 33baeace..00000000 --- a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/BeanObservableMapDecorator.java +++ /dev/null @@ -1,165 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 221704) - * Matthew Hall - bug 245183 - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.beans; - -import java.beans.PropertyDescriptor; -import java.util.Collection; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.databinding.beans.IBeanObservable; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.map.IMapChangeListener; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.internal.databinding.Util; - -/** - * {@link IBeanObservable} decorator for an {@link IObservableMap}. - * - * @since 3.3 - */ -public class BeanObservableMapDecorator implements IObservableMap, IBeanObservable { - private IObservableMap delegate; - private Object observed; - private PropertyDescriptor propertyDescriptor; - - /** - * @param delegate - * @param observed - * @param propertyDescriptor - */ - public BeanObservableMapDecorator(IObservableMap delegate, - Object observed, - PropertyDescriptor propertyDescriptor) { - - this.delegate = delegate; - this.observed = observed; - this.propertyDescriptor = propertyDescriptor; - } - - public Realm getRealm() { - return delegate.getRealm(); - } - - public boolean isStale() { - return delegate.isStale(); - } - - public boolean containsKey(Object key) { - return delegate.containsKey(key); - } - - public boolean containsValue(Object value) { - return delegate.containsValue(value); - } - - public Set entrySet() { - return delegate.entrySet(); - } - - public Object get(Object key) { - return delegate.get(key); - } - - public Set keySet() { - return delegate.keySet(); - } - - public Object put(Object key, Object value) { - return delegate.put(key, value); - } - - public Object remove(Object key) { - return delegate.remove(key); - } - - public Collection values() { - return delegate.values(); - } - - public void putAll(Map map) { - delegate.putAll(map); - } - - public void clear() { - delegate.clear(); - } - - public boolean isEmpty() { - return delegate.isEmpty(); - } - - public int size() { - return delegate.size(); - } - - public Object getObserved() { - return observed; - } - - public PropertyDescriptor getPropertyDescriptor() { - return propertyDescriptor; - } - - /** - * @return the wrapped map - */ - public IObservableMap getDelegate() { - return delegate; - } - public void dispose() { - delegate.dispose(); - } - - public void addChangeListener(IChangeListener listener) { - delegate.addChangeListener(listener); - } - - public void removeChangeListener(IChangeListener listener) { - delegate.removeChangeListener(listener); - } - - public void addMapChangeListener(IMapChangeListener listener) { - delegate.addMapChangeListener(listener); - } - - public void removeMapChangeListener(IMapChangeListener listener) { - delegate.removeMapChangeListener(listener); - } - - public void addStaleListener(IStaleListener listener) { - delegate.addStaleListener(listener); - } - - public void removeStaleListener(IStaleListener listener) { - delegate.removeStaleListener(listener); - } - - public boolean equals(Object obj) { - if (obj == this) - return true; - if (obj == null) - return false; - if (getClass() == obj.getClass()) { - BeanObservableMapDecorator other = (BeanObservableMapDecorator) obj; - return Util.equals(other.delegate, delegate); - } - return delegate.equals(obj); - } - - public int hashCode() { - return delegate.hashCode(); - } -} diff --git a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/BeanObservableSetDecorator.java b/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/BeanObservableSetDecorator.java deleted file mode 100644 index 92b88b57..00000000 --- a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/BeanObservableSetDecorator.java +++ /dev/null @@ -1,179 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bug 245183 - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.beans; - -import java.beans.PropertyDescriptor; -import java.util.Collection; -import java.util.Iterator; - -import org.eclipse.core.databinding.beans.IBeanObservable; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.ISetChangeListener; -import org.eclipse.core.internal.databinding.Util; - -/** - * {@link IBeanObservable} decorator for an {@link IObservableSet}. - * - * @since 3.3 - */ -public class BeanObservableSetDecorator implements IObservableSet, IBeanObservable { - private IObservableSet delegate; - private Object observed; - private PropertyDescriptor propertyDescriptor; - - /** - * @param delegate - * @param observed - * @param propertyDescriptor - */ - public BeanObservableSetDecorator(IObservableSet delegate, - Object observed, - PropertyDescriptor propertyDescriptor) { - - this.delegate = delegate; - this.observed = observed; - this.propertyDescriptor = propertyDescriptor; - } - - public boolean add(Object o) { - return delegate.add(o); - } - - public boolean addAll(Collection c) { - return delegate.addAll(c); - } - - public void addChangeListener(IChangeListener listener) { - delegate.addChangeListener(listener); - } - - public void addSetChangeListener(ISetChangeListener listener) { - delegate.addSetChangeListener(listener); - } - - public void addStaleListener(IStaleListener listener) { - delegate.addStaleListener(listener); - } - - public void clear() { - delegate.clear(); - } - - public boolean contains(Object o) { - return delegate.contains(o); - } - - public boolean containsAll(Collection c) { - return delegate.containsAll(c); - } - - public void dispose() { - delegate.dispose(); - } - - public boolean equals(Object obj) { - if (obj == this) - return true; - if (obj == null) - return false; - if (getClass() == obj.getClass()) { - BeanObservableSetDecorator other = (BeanObservableSetDecorator) obj; - return Util.equals(other.delegate, delegate); - } - return delegate.equals(obj); - } - - public Object getElementType() { - return delegate.getElementType(); - } - - public Realm getRealm() { - return delegate.getRealm(); - } - - public int hashCode() { - return delegate.hashCode(); - } - - public boolean isEmpty() { - return delegate.isEmpty(); - } - - public boolean isStale() { - return delegate.isStale(); - } - - public Iterator iterator() { - return delegate.iterator(); - } - - public boolean remove(Object o) { - return delegate.remove(o); - } - - public boolean removeAll(Collection c) { - return delegate.removeAll(c); - } - - public void removeChangeListener(IChangeListener listener) { - delegate.removeChangeListener(listener); - } - - public void removeSetChangeListener(ISetChangeListener listener) { - delegate.removeSetChangeListener(listener); - } - - public void removeStaleListener(IStaleListener listener) { - delegate.removeStaleListener(listener); - } - - public boolean retainAll(Collection c) { - return delegate.retainAll(c); - } - - public int size() { - return delegate.size(); - } - - public Object[] toArray() { - return delegate.toArray(); - } - - public Object[] toArray(Object[] a) { - return delegate.toArray(a); - } - - /* (non-Javadoc) - * @see org.eclipse.core.databinding.beans.IBeanObservable#getObserved() - */ - public Object getObserved() { - return observed; - } - - /* (non-Javadoc) - * @see org.eclipse.core.databinding.beans.IBeanObservable#getPropertyDescriptor() - */ - public PropertyDescriptor getPropertyDescriptor() { - return propertyDescriptor; - } - - /** - * @return the wrapped set - */ - public IObservableSet getDelegate() { - return delegate; - } -} diff --git a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/BeanObservableValueDecorator.java b/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/BeanObservableValueDecorator.java deleted file mode 100644 index cf43e3cb..00000000 --- a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/BeanObservableValueDecorator.java +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bug 245183 - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.beans; - -import java.beans.PropertyDescriptor; - -import org.eclipse.core.databinding.beans.IBeanObservable; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.internal.databinding.Util; - -/** - * {@link IBeanObservable} decorator for an {@link IObservableValue}. - * - * @since 3.3 - */ -public class BeanObservableValueDecorator implements IObservableValue, - IBeanObservable { - private final IObservableValue delegate; - private final PropertyDescriptor descriptor; - private final IObservableValue observed; - - /** - * @param delegate - * @param observed - * @param descriptor - */ - public BeanObservableValueDecorator(IObservableValue delegate, IObservableValue observed, - PropertyDescriptor descriptor) { - this.delegate = delegate; - this.observed = observed; - this.descriptor = descriptor; - } - - public void addChangeListener(IChangeListener listener) { - delegate.addChangeListener(listener); - } - - public void addStaleListener(IStaleListener listener) { - delegate.addStaleListener(listener); - } - - public void addValueChangeListener(IValueChangeListener listener) { - delegate.addValueChangeListener(listener); - } - - public void dispose() { - delegate.dispose(); - } - - public boolean equals(Object obj) { - if (obj == this) - return true; - if (obj == null) - return false; - if (getClass() == obj.getClass()) { - BeanObservableValueDecorator other = (BeanObservableValueDecorator) obj; - return Util.equals(other.delegate, delegate); - } - return delegate.equals(obj); - } - - public Realm getRealm() { - return delegate.getRealm(); - } - - public Object getValue() { - return delegate.getValue(); - } - - public Object getValueType() { - return delegate.getValueType(); - } - - public int hashCode() { - return delegate.hashCode(); - } - - public boolean isStale() { - return delegate.isStale(); - } - - public void removeChangeListener(IChangeListener listener) { - delegate.removeChangeListener(listener); - } - - public void removeStaleListener(IStaleListener listener) { - delegate.removeStaleListener(listener); - } - - public void removeValueChangeListener(IValueChangeListener listener) { - delegate.removeValueChangeListener(listener); - } - - public void setValue(Object value) { - delegate.setValue(value); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.beans.IBeanObservable#getObserved() - */ - public Object getObserved() { - return observed.getValue(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.beans.IBeanObservable#getPropertyDescriptor() - */ - public PropertyDescriptor getPropertyDescriptor() { - return descriptor; - } - - /** - * @return observable value delegate - */ - public IObservableValue getDelegate() { - return delegate; - } -} diff --git a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/IdentityWrapper.java b/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/IdentityWrapper.java deleted file mode 100644 index 5be54547..00000000 --- a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/IdentityWrapper.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Daniel Kruegler - bug 137435 - *******************************************************************************/ - -package org.eclipse.core.internal.databinding.beans; - -/** - * Used for wrapping objects that define their own implementations of equals() - * and hashCode() when putting them in sets or hashmaps to ensure identity - * comparison. - * - * @since 1.0 - * - */ -public class IdentityWrapper { - final Object o; - - /** - * @param o - */ - public IdentityWrapper(Object o) { - this.o = o; - } - - /** - * @return the unwrapped object - */ - public Object unwrap() { - return o; - } - - public boolean equals(Object obj) { - if (obj == null || obj.getClass() != IdentityWrapper.class) { - return false; - } - return o == ((IdentityWrapper) obj).o; - } - - public int hashCode() { - return System.identityHashCode(o); - } -} diff --git a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/JavaBeanObservableList.java b/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/JavaBeanObservableList.java deleted file mode 100644 index 9300e2a7..00000000 --- a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/JavaBeanObservableList.java +++ /dev/null @@ -1,399 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006-2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 171616 - * Matthew Hall - bugs 208858, 221351, 213145, 223164, 244098 - * Mike Evans - bug 217558 - *******************************************************************************/ - -package org.eclipse.core.internal.databinding.beans; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyDescriptor; -import java.lang.reflect.Array; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.databinding.BindingException; -import org.eclipse.core.databinding.beans.IBeanObservable; -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.ListDiffEntry; -import org.eclipse.core.databinding.observable.list.ObservableList; - -/** - * @since 1.0 - * - */ -public class JavaBeanObservableList extends ObservableList implements - IBeanObservable { - - private final Object object; - - private boolean updating = false; - - private PropertyDescriptor descriptor; - - private ListenerSupport listenerSupport; - - /** - * @param realm - * @param object - * @param descriptor - * @param elementType - */ - public JavaBeanObservableList(Realm realm, Object object, - PropertyDescriptor descriptor, Class elementType) { - this(realm, object, descriptor, elementType, true); - } - - /** - * @param realm - * @param object - * @param descriptor - * @param elementType - * @param attachListeners - */ - public JavaBeanObservableList(Realm realm, Object object, - PropertyDescriptor descriptor, Class elementType, - boolean attachListeners) { - - super(realm, new ArrayList(), elementType); - this.object = object; - this.descriptor = descriptor; - - if (attachListeners) { - PropertyChangeListener listener = new PropertyChangeListener() { - public void propertyChange(java.beans.PropertyChangeEvent event) { - if (!updating) { - getRealm().exec(new Runnable() { - public void run() { - updateWrappedList(new ArrayList(Arrays - .asList(getValues()))); - } - }); - } - } - }; - this.listenerSupport = new ListenerSupport(listener, - descriptor.getName()); - listenerSupport.hookListener(this.object); - } - - // initialize list without firing events - wrappedList.addAll(Arrays.asList(getValues())); - } - - public void dispose() { - if (listenerSupport != null) { - listenerSupport.dispose(); - listenerSupport = null; - } - super.dispose(); - } - - private Object primGetValues() { - Exception ex = null; - try { - Method readMethod = descriptor.getReadMethod(); - if (!readMethod.isAccessible()) { - readMethod.setAccessible(true); - } - return readMethod.invoke(object, new Object[0]); - } catch (IllegalArgumentException e) { - ex = e; - } catch (IllegalAccessException e) { - ex = e; - } catch (InvocationTargetException e) { - ex = e; - } - throw new BindingException("Could not read collection values", ex); //$NON-NLS-1$ - } - - private Object[] getValues() { - Object[] values = null; - - Object result = primGetValues(); - if (descriptor.getPropertyType().isArray()) - values = (Object[]) result; - else { - // TODO add jUnit for POJO (var. SettableValue) collections - Collection list = (Collection) result; - if (list != null) { - values = list.toArray(); - } - } - if (values == null) - values = new Object[0]; - return values; - } - - public Object getObserved() { - return object; - } - - public PropertyDescriptor getPropertyDescriptor() { - return descriptor; - } - - private void setValues() { - if (descriptor.getPropertyType().isArray()) { - Class componentType = descriptor.getPropertyType() - .getComponentType(); - Object[] newArray = (Object[]) Array.newInstance(componentType, - wrappedList.size()); - wrappedList.toArray(newArray); - primSetValues(newArray); - } else { - // assume that it is a java.util.List - primSetValues(new ArrayList(wrappedList)); - } - } - - private void primSetValues(Object newValue) { - Exception ex = null; - try { - Method writeMethod = descriptor.getWriteMethod(); - if (!writeMethod.isAccessible()) { - writeMethod.setAccessible(true); - } - writeMethod.invoke(object, new Object[] { newValue }); - return; - } catch (IllegalArgumentException e) { - ex = e; - } catch (IllegalAccessException e) { - ex = e; - } catch (InvocationTargetException e) { - ex = e; - } - throw new BindingException("Could not write collection values", ex); //$NON-NLS-1$ - } - - public Object set(int index, Object element) { - getterCalled(); - updating = true; - try { - Object oldElement = wrappedList.set(index, element); - setValues(); - fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry( - index, false, oldElement), Diffs.createListDiffEntry(index, - true, element))); - return oldElement; - } finally { - updating = false; - } - } - - public Object move(int oldIndex, int newIndex) { - getterCalled(); - updating = true; - try { - int size = wrappedList.size(); - if (oldIndex < 0 || oldIndex >= size) - throw new IndexOutOfBoundsException( - "oldIndex: " + oldIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$ - if (newIndex < 0 || newIndex >= size) - throw new IndexOutOfBoundsException( - "newIndex: " + newIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$ - if (oldIndex == newIndex) - return wrappedList.get(oldIndex); - Object element = wrappedList.remove(oldIndex); - wrappedList.add(newIndex, element); - setValues(); - fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry( - oldIndex, false, element), Diffs.createListDiffEntry( - newIndex, true, element))); - return element; - } finally { - updating = false; - } - } - - public Object remove(int index) { - getterCalled(); - updating = true; - try { - Object oldElement = wrappedList.remove(index); - setValues(); - fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry( - index, false, oldElement))); - return oldElement; - } finally { - updating = false; - } - } - - public boolean add(Object element) { - updating = true; - try { - int index = wrappedList.size(); - boolean result = wrappedList.add(element); - setValues(); - fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry( - index, true, element))); - return result; - } finally { - updating = false; - } - } - - public void add(int index, Object element) { - updating = true; - try { - wrappedList.add(index, element); - setValues(); - fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry( - index, true, element))); - } finally { - updating = false; - } - } - - public boolean addAll(Collection c) { - if (c.isEmpty()) { - return false; - } - updating = true; - try { - int index = wrappedList.size(); - boolean result = wrappedList.addAll(c); - setValues(); - ListDiffEntry[] entries = new ListDiffEntry[c.size()]; - int i = 0; - for (Iterator it = c.iterator(); it.hasNext();) { - Object o = it.next(); - entries[i++] = Diffs.createListDiffEntry(index++, true, o); - } - fireListChange(Diffs.createListDiff(entries)); - return result; - } finally { - updating = false; - } - } - - public boolean addAll(int index, Collection c) { - if (c.isEmpty()) { - return false; - } - updating = true; - try { - boolean result = wrappedList.addAll(index, c); - setValues(); - ListDiffEntry[] entries = new ListDiffEntry[c.size()]; - int i = 0; - for (Iterator it = c.iterator(); it.hasNext();) { - Object o = it.next(); - entries[i++] = Diffs.createListDiffEntry(index++, true, o); - } - fireListChange(Diffs.createListDiff(entries)); - return result; - } finally { - updating = false; - } - } - - public boolean remove(Object o) { - getterCalled(); - int index = wrappedList.indexOf(o); - if (index == -1) { - return false; - } - updating = true; - try { - Object oldElement = wrappedList.remove(index); - setValues(); - fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry( - index, false, oldElement))); - return true; - } finally { - updating = false; - } - } - - public boolean removeAll(Collection c) { - getterCalled(); - boolean changed = false; - updating = true; - try { - List diffEntries = new ArrayList(); - for (Iterator it = c.iterator(); it.hasNext();) { - Object o = it.next(); - int index = wrappedList.indexOf(o); - if (index != -1) { - changed = true; - Object oldElement = wrappedList.remove(index); - diffEntries.add(Diffs.createListDiffEntry(index, false, - oldElement)); - } - } - if (changed) { - setValues(); - fireListChange(Diffs - .createListDiff((ListDiffEntry[]) diffEntries - .toArray(new ListDiffEntry[diffEntries.size()]))); - } - return changed; - } finally { - updating = false; - } - } - - public boolean retainAll(Collection c) { - getterCalled(); - boolean changed = false; - updating = true; - try { - List diffEntries = new ArrayList(); - int index = 0; - for (Iterator it = wrappedList.iterator(); it.hasNext();) { - Object o = it.next(); - boolean retain = c.contains(o); - if (retain) { - index++; - } else { - changed = true; - it.remove(); - diffEntries.add(Diffs.createListDiffEntry(index, false, o)); - } - } - if (changed) { - setValues(); - fireListChange(Diffs - .createListDiff((ListDiffEntry[]) diffEntries - .toArray(new ListDiffEntry[diffEntries.size()]))); - } - return changed; - } finally { - updating = false; - } - } - - public void clear() { - updating = true; - try { - List diffEntries = new ArrayList(); - for (Iterator it = wrappedList.iterator(); it.hasNext();) { - Object o = it.next(); - diffEntries.add(Diffs.createListDiffEntry(0, false, o)); - } - wrappedList.clear(); - setValues(); - fireListChange(Diffs.createListDiff((ListDiffEntry[]) diffEntries - .toArray(new ListDiffEntry[diffEntries.size()]))); - } finally { - updating = false; - } - } - -} diff --git a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/JavaBeanObservableMap.java b/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/JavaBeanObservableMap.java deleted file mode 100644 index c41ed3de..00000000 --- a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/JavaBeanObservableMap.java +++ /dev/null @@ -1,142 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 171616 - * Matthew hall - bug 223164 - *******************************************************************************/ - -package org.eclipse.core.internal.databinding.beans; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyDescriptor; -import java.lang.reflect.Method; - -import org.eclipse.core.databinding.beans.IBeanObservable; -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.map.ComputedObservableMap; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.util.Policy; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; - -/** - * @since 1.0 - * - */ -public class JavaBeanObservableMap extends ComputedObservableMap implements - IBeanObservable { - - private PropertyDescriptor propertyDescriptor; - - private PropertyChangeListener elementListener = new PropertyChangeListener() { - public void propertyChange(final java.beans.PropertyChangeEvent event) { - if (!updating) { - getRealm().exec(new Runnable() { - public void run() { - fireMapChange(Diffs.createMapDiffSingleChange( - event.getSource(), event.getOldValue(), event - .getNewValue())); - } - }); - } - } - }; - - private ListenerSupport listenerSupport; - - private boolean updating = false; - - private boolean attachListeners; - - /** - * @param domain - * @param propertyDescriptor - */ - public JavaBeanObservableMap(IObservableSet domain, - PropertyDescriptor propertyDescriptor) { - this(domain, propertyDescriptor, true); - } - - /** - * @param domain - * @param propertyDescriptor - * @param attachListeners - */ - public JavaBeanObservableMap(IObservableSet domain, - PropertyDescriptor propertyDescriptor, boolean attachListeners) { - super(domain); - - this.propertyDescriptor = propertyDescriptor; - this.attachListeners = attachListeners; - if (attachListeners) { - this.listenerSupport = new ListenerSupport(elementListener, - propertyDescriptor.getName()); - } - init(); - } - - protected void hookListener(Object domainElement) { - if (attachListeners && domainElement != null) { - listenerSupport.hookListener(domainElement); - } - } - - protected void unhookListener(Object domainElement) { - if (attachListeners && domainElement != null) { - listenerSupport.unhookListener(domainElement); - } - } - - protected Object doGet(Object key) { - if (key == null) { - return null; - } - try { - Method readMethod = propertyDescriptor.getReadMethod(); - if (!readMethod.isAccessible()) { - readMethod.setAccessible(true); - } - return readMethod.invoke(key, new Object[0]); - } catch (Exception e) { - Policy.getLog().log( - new Status(IStatus.ERROR, Policy.JFACE_DATABINDING, - IStatus.ERROR, "cannot get value", e)); //$NON-NLS-1$ - throw new RuntimeException(e); - } - } - - protected Object doPut(Object key, Object value) { - try { - Object oldValue = get(key); - propertyDescriptor.getWriteMethod().invoke(key, - new Object[] { value }); - keySet().add(key); - return oldValue; - } catch (Exception e) { - Policy.getLog().log( - new Status(IStatus.ERROR, Policy.JFACE_DATABINDING, - IStatus.ERROR, "cannot set value", e)); //$NON-NLS-1$ - throw new RuntimeException(e); - } - } - - /* (non-Javadoc) - * @see org.eclipse.core.databinding.beans.IBeanObservable#getObserved() - */ - public Object getObserved() { - return keySet(); - } - - /* (non-Javadoc) - * @see org.eclipse.core.databinding.beans.IBeanObservable#getPropertyDescriptor() - */ - public PropertyDescriptor getPropertyDescriptor() { - return propertyDescriptor; - } -} diff --git a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/JavaBeanObservableSet.java b/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/JavaBeanObservableSet.java deleted file mode 100644 index c7172713..00000000 --- a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/JavaBeanObservableSet.java +++ /dev/null @@ -1,301 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006-2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 171616 - * Matthew Hall - bugs 221351, 223164, 244098 - *******************************************************************************/ - -package org.eclipse.core.internal.databinding.beans; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyDescriptor; -import java.lang.reflect.Array; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.databinding.BindingException; -import org.eclipse.core.databinding.beans.IBeanObservable; -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.set.ObservableSet; -import org.eclipse.core.runtime.Assert; - -/** - * @since 1.0 - * - */ -public class JavaBeanObservableSet extends ObservableSet implements IBeanObservable { - - private final Object object; - - private boolean updating = false; - - private PropertyDescriptor descriptor; - - private ListenerSupport listenerSupport; - - /** - * @param realm - * @param object - * @param descriptor - * @param elementType - */ - public JavaBeanObservableSet(Realm realm, Object object, - PropertyDescriptor descriptor, Class elementType) { - this(realm, object, descriptor, elementType, true); - } - - /** - * @param realm - * @param object - * @param descriptor - * @param elementType - * @param attachListeners - */ - public JavaBeanObservableSet(Realm realm, Object object, - PropertyDescriptor descriptor, Class elementType, - boolean attachListeners) { - super(realm, new HashSet(), elementType); - this.object = object; - this.descriptor = descriptor; - if (attachListeners) { - PropertyChangeListener listener = new PropertyChangeListener() { - public void propertyChange(java.beans.PropertyChangeEvent event) { - if (!updating) { - getRealm().exec(new Runnable() { - public void run() { - Set newElements = new HashSet(Arrays - .asList(getValues())); - Set addedElements = new HashSet(newElements); - Set removedElements = new HashSet(wrappedSet); - // remove all new elements from old elements to - // compute - // the removed elements - removedElements.removeAll(newElements); - addedElements.removeAll(wrappedSet); - wrappedSet = newElements; - fireSetChange(Diffs.createSetDiff( - addedElements, removedElements)); - } - }); - } - } - }; - this.listenerSupport = new ListenerSupport(listener, descriptor - .getName()); - listenerSupport.hookListener(this.object); - } - - wrappedSet.addAll(Arrays.asList(getValues())); - } - - private Object primGetValues() { - try { - Method readMethod = descriptor.getReadMethod(); - if (!readMethod.isAccessible()) { - readMethod.setAccessible(true); - } - return readMethod.invoke(object, new Object[0]); - } catch (IllegalArgumentException e) { - } catch (IllegalAccessException e) { - } catch (InvocationTargetException e) { - } - Assert.isTrue(false, "Could not read collection values"); //$NON-NLS-1$ - return null; - } - - private Object[] getValues() { - Object[] values = null; - - Object result = primGetValues(); - if (descriptor.getPropertyType().isArray()) - values = (Object[]) result; - else { - // TODO add jUnit for POJO (var. SettableValue) collections - Collection list = (Collection) result; - if (list != null) - values = list.toArray(); - } - if (values == null) - values = new Object[0]; - return values; - } - - private void setValues() { - if (descriptor.getPropertyType().isArray()) { - Class componentType = descriptor.getPropertyType() - .getComponentType(); - Object[] newArray = (Object[]) Array.newInstance(componentType, - wrappedSet.size()); - wrappedSet.toArray(newArray); - primSetValues(newArray); - } else { - // assume that it is a java.util.Set - primSetValues(new HashSet(wrappedSet)); - } - } - - public boolean add(Object o) { - getterCalled(); - updating = true; - try { - boolean added = wrappedSet.add(o); - if (added) { - setValues(); - fireSetChange(Diffs.createSetDiff(Collections.singleton(o), - Collections.EMPTY_SET)); - } - return added; - } finally { - updating = false; - } - } - - public boolean remove(Object o) { - getterCalled(); - updating = true; - try { - boolean removed = wrappedSet.remove(o); - if (removed) { - setValues(); - fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, - Collections.singleton(o))); - } - return removed; - } finally { - updating = false; - } - } - - public boolean addAll(Collection c) { - getterCalled(); - updating = true; - try { - Set additions = new HashSet(); - for (Iterator iterator = c.iterator(); iterator.hasNext();) { - Object element = iterator.next(); - if (wrappedSet.add(element)) - additions.add(element); - } - boolean changed = !additions.isEmpty(); - if (changed) { - setValues(); - fireSetChange(Diffs.createSetDiff(additions, - Collections.EMPTY_SET)); - } - return changed; - } finally { - updating = false; - } - } - - public boolean removeAll(Collection c) { - getterCalled(); - updating = true; - try { - Set removals = new HashSet(); - for (Iterator iterator = c.iterator(); iterator.hasNext();) { - Object element = iterator.next(); - if (wrappedSet.remove(element)) - removals.add(element); - } - boolean changed = !removals.isEmpty(); - if (changed) { - setValues(); - fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, - removals)); - } - return changed; - } finally { - updating = false; - } - } - - public boolean retainAll(Collection c) { - getterCalled(); - updating = true; - try { - Set removals = new HashSet(); - for (Iterator iterator = wrappedSet.iterator(); iterator.hasNext();) { - Object element = iterator.next(); - if (!c.contains(element)) { - iterator.remove(); - removals.add(element); - } - } - boolean changed = !removals.isEmpty(); - if (changed) { - setValues(); - fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, - removals)); - } - return changed; - } finally { - updating = false; - } - } - - public void clear() { - getterCalled(); - if (wrappedSet.isEmpty()) - return; - - updating = true; - try { - Set removals = new HashSet(wrappedSet); - wrappedSet.clear(); - setValues(); - fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, removals)); - } finally { - updating = false; - } - } - - private void primSetValues(Object newValue) { - Exception ex = null; - try { - Method writeMethod = descriptor.getWriteMethod(); - if (!writeMethod.isAccessible()) { - writeMethod.setAccessible(true); - } - writeMethod.invoke(object, new Object[] { newValue }); - return; - } catch (IllegalArgumentException e) { - ex = e; - } catch (IllegalAccessException e) { - ex = e; - } catch (InvocationTargetException e) { - ex = e; - } - throw new BindingException("Could not write collection values", ex); //$NON-NLS-1$ - } - - public Object getObserved() { - return object; - } - - public PropertyDescriptor getPropertyDescriptor() { - return descriptor; - } - - public synchronized void dispose() { - if (listenerSupport != null) { - listenerSupport.dispose(); - listenerSupport = null; - } - - super.dispose(); - } -} diff --git a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/JavaBeanObservableValue.java b/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/JavaBeanObservableValue.java deleted file mode 100644 index c2d4810a..00000000 --- a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/JavaBeanObservableValue.java +++ /dev/null @@ -1,190 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - * Brad Reynolds - bug 164134, 171616 - *******************************************************************************/ -package org.eclipse.core.internal.databinding.beans; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyDescriptor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import org.eclipse.core.databinding.BindingException; -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.beans.IBeanObservable; -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.AbstractObservableValue; -import org.eclipse.core.databinding.observable.value.ValueDiff; -import org.eclipse.core.databinding.util.Policy; -import org.eclipse.core.internal.databinding.Util; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; - -/** - * @since 1.0 - * - */ -public class JavaBeanObservableValue extends AbstractObservableValue implements IBeanObservable { - private final Object object; - private boolean updating = false; - - private final PropertyDescriptor propertyDescriptor; - private ListenerSupport listenerSupport; - - private boolean attachListeners; - - /** - * @param realm - * @param object - * @param descriptor - */ - public JavaBeanObservableValue(Realm realm, Object object, - PropertyDescriptor descriptor) { - this(realm, object, descriptor, true); - } - - /** - * @param realm - * @param object - * @param descriptor - * @param attachListeners - */ - public JavaBeanObservableValue(Realm realm, Object object, - PropertyDescriptor descriptor, boolean attachListeners) { - super(realm); - this.object = object; - this.propertyDescriptor = descriptor; - this.attachListeners = attachListeners; - } - - protected void firstListenerAdded() { - if (!attachListeners) { - return; - } - - PropertyChangeListener listener = new PropertyChangeListener() { - public void propertyChange(java.beans.PropertyChangeEvent event) { - if (!updating) { - final ValueDiff diff = Diffs.createValueDiff(event.getOldValue(), - event.getNewValue()); - getRealm().exec(new Runnable(){ - public void run() { - fireValueChange(diff); - }}); - } - } - }; - - if (listenerSupport == null) { - listenerSupport = new ListenerSupport(listener, propertyDescriptor.getName()); - } - - listenerSupport.hookListener(object); - } - - public void doSetValue(Object value) { - updating = true; - try { - Object oldValue = doGetValue(); - - if (Util.equals(oldValue, value)) { - return; - } - - Method writeMethod = propertyDescriptor.getWriteMethod(); - if (!writeMethod.isAccessible()) { - writeMethod.setAccessible(true); - } - writeMethod.invoke(object, new Object[] { value }); - fireValueChange(Diffs.createValueDiff(oldValue, doGetValue())); - } catch (InvocationTargetException e) { - /* - * InvocationTargetException wraps any exception thrown by the - * invoked method. - */ - throw new RuntimeException(e.getCause()); - } catch (Exception e) { - if (BeansObservables.DEBUG) { - Policy - .getLog() - .log( - new Status( - IStatus.WARNING, - Policy.JFACE_DATABINDING, - IStatus.OK, - "Could not change value of " + object + "." + propertyDescriptor.getName(), e)); //$NON-NLS-1$ //$NON-NLS-2$ - } - } finally { - updating = false; - } - } - - public Object doGetValue() { - try { - Method readMethod = propertyDescriptor.getReadMethod(); - if (readMethod == null) { - throw new BindingException(propertyDescriptor.getName() - + " property does not have a read method."); //$NON-NLS-1$ - } - if (!readMethod.isAccessible()) { - readMethod.setAccessible(true); - } - return readMethod.invoke(object, null); - } catch (InvocationTargetException e) { - /* - * InvocationTargetException wraps any exception thrown by the - * invoked method. - */ - throw new RuntimeException(e.getCause()); - } catch (Exception e) { - if (BeansObservables.DEBUG) { - Policy - .getLog() - .log( - new Status( - IStatus.WARNING, - Policy.JFACE_DATABINDING, - IStatus.OK, - "Could not read value of " + object + "." + propertyDescriptor.getName(), e)); //$NON-NLS-1$ //$NON-NLS-2$ - } - return null; - } - } - - protected void lastListenerRemoved() { - unhookListener(); - } - - private void unhookListener() { - if (listenerSupport != null) { - listenerSupport.dispose(); - listenerSupport = null; - } - } - - public Object getValueType() { - return propertyDescriptor.getPropertyType(); - } - - public Object getObserved() { - return object; - } - - public PropertyDescriptor getPropertyDescriptor() { - return propertyDescriptor; - } - - public synchronized void dispose() { - unhookListener(); - super.dispose(); - } -} diff --git a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/JavaBeanPropertyObservableMap.java b/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/JavaBeanPropertyObservableMap.java deleted file mode 100644 index e604dbcb..00000000 --- a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/JavaBeanPropertyObservableMap.java +++ /dev/null @@ -1,235 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 221704) - * Matthew Hall - bugs 223164, 244098 - *******************************************************************************/ - -package org.eclipse.core.internal.databinding.beans; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.beans.PropertyDescriptor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.databinding.BindingException; -import org.eclipse.core.databinding.beans.IBeanObservable; -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.map.ObservableMap; -import org.eclipse.core.internal.databinding.Util; -import org.eclipse.core.runtime.Assert; - -/** - * @since 1.0 - * - */ -public class JavaBeanPropertyObservableMap extends ObservableMap implements - IBeanObservable { - - private final Object object; - - private boolean updating = false; - - private PropertyDescriptor descriptor; - - private ListenerSupport listenerSupport; - - /** - * @param realm - * @param object - * @param descriptor - */ - public JavaBeanPropertyObservableMap(Realm realm, Object object, - PropertyDescriptor descriptor) { - this(realm, object, descriptor, true); - } - - /** - * @param realm - * @param object - * @param descriptor - * @param attachListeners - */ - public JavaBeanPropertyObservableMap(Realm realm, Object object, - PropertyDescriptor descriptor, boolean attachListeners) { - super(realm, new HashMap()); - this.object = object; - this.descriptor = descriptor; - if (attachListeners) { - PropertyChangeListener listener = new PropertyChangeListener() { - public void propertyChange(final PropertyChangeEvent event) { - if (!updating) { - getRealm().exec(new Runnable() { - public void run() { - Map oldValue = wrappedMap; - Map newValue = (Map) event.getNewValue(); - wrappedMap = new HashMap(newValue); - - fireMapChange(Diffs.computeMapDiff(oldValue, newValue)); - } - }); - } - } - }; - - listenerSupport = new ListenerSupport(listener, - descriptor.getName()); - listenerSupport.hookListener(this.object); - } - - wrappedMap.putAll(getMap()); - } - - private Object primGetMap() { - try { - Method readMethod = descriptor.getReadMethod(); - if (!readMethod.isAccessible()) { - readMethod.setAccessible(true); - } - return readMethod.invoke(object, new Object[0]); - } catch (IllegalArgumentException e) { - } catch (IllegalAccessException e) { - } catch (InvocationTargetException e) { - } - Assert.isTrue(false, "Could not read collection values"); //$NON-NLS-1$ - return null; - } - - private void primSetMap(Object newValue) { - Exception ex = null; - try { - Method writeMethod = descriptor.getWriteMethod(); - if (!writeMethod.isAccessible()) { - writeMethod.setAccessible(true); - } - writeMethod.invoke(object, new Object[] { newValue }); - return; - } catch (IllegalArgumentException e) { - ex = e; - } catch (IllegalAccessException e) { - ex = e; - } catch (InvocationTargetException e) { - ex = e; - } - throw new BindingException("Could not write collection values", ex); //$NON-NLS-1$ - } - - private Map getMap() { - Map result = (Map) primGetMap(); - - if (result == null) - result = new HashMap(); - return result; - } - - private void setMap() { - primSetMap(new HashMap(wrappedMap)); - } - - public Object put(Object key, Object value) { - checkRealm(); - updating = true; - try { - Object result = wrappedMap.put(key, value); - if (!Util.equals(result, value)) { - setMap(); - if (result == null) { - fireMapChange(Diffs.createMapDiffSingleAdd(key, value)); - } else { - fireMapChange(Diffs.createMapDiffSingleChange(key, result, - value)); - } - } - return result; - } finally { - updating = false; - } - } - - public void putAll(Map map) { - checkRealm(); - updating = true; - try { - Set addedKeys = new HashSet(map.size()); - Map changes = new HashMap(map.size()); - for (Iterator it = map.entrySet().iterator(); it.hasNext();) { - Map.Entry entry = (Entry) it.next(); - Object key = entry.getKey(); - Object newValue = entry.getValue(); - Object oldValue = wrappedMap.put(key, newValue); - if (oldValue == null) { - addedKeys.add(key); - } else if (!Util.equals(oldValue, newValue)) { - changes.put(key, oldValue); - } - } - if (!addedKeys.isEmpty() || !changes.isEmpty()) { - setMap(); - fireMapChange(Diffs.createMapDiff(addedKeys, - Collections.EMPTY_SET, changes.keySet(), changes, - wrappedMap)); - } - } finally { - updating = false; - } - } - - public Object remove(Object key) { - checkRealm(); - updating = true; - try { - Object result = wrappedMap.remove(key); - if (result!=null) { - setMap(); - fireMapChange(Diffs.createMapDiffSingleRemove(key, result)); - } - return result; - } finally { - updating = false; - } - } - - public void clear() { - checkRealm(); - if (wrappedMap.isEmpty()) - return; - updating = true; - try { - Map oldMap = wrappedMap; - wrappedMap = new HashMap(); - setMap(); - fireMapChange(Diffs.computeMapDiff(oldMap, Collections.EMPTY_MAP)); - } finally { - updating = false; - } - } - - public Object getObserved() { - return object; - } - - public PropertyDescriptor getPropertyDescriptor() { - return descriptor; - } - - public synchronized void dispose() { - if (listenerSupport != null) { - listenerSupport.dispose(); - listenerSupport = null; - } - super.dispose(); - } -} diff --git a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/ListenerSupport.java b/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/ListenerSupport.java deleted file mode 100644 index 6e82157f..00000000 --- a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/internal/databinding/beans/ListenerSupport.java +++ /dev/null @@ -1,216 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 118516 - *******************************************************************************/ -package org.eclipse.core.internal.databinding.beans; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.util.Policy; -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; - -/** - * This is a helper that will hook up and listen for <code>PropertyChangeEvent</code> events - * for a set of target JavaBeans - * - * @since 1.0 - */ -public class ListenerSupport { - - private Set elementsListenedTo = new HashSet(); - - private PropertyChangeListener listener; - - private String propertyName; - - /** - * Constructs a new instance. - * - * @param listener is the callback that will be called - * when a <code>PropertyChangeEvent</code> is fired on any - * of the target objects. Will only receive change events - * when the provided <code>propertyName</code> changes. - * @param propertyName - */ - public ListenerSupport(final PropertyChangeListener listener, - final String propertyName) { - Assert.isNotNull(listener, "Listener cannot be null"); //$NON-NLS-1$ - Assert.isNotNull(propertyName, "Property name cannot be null"); //$NON-NLS-1$ - - this.propertyName = propertyName; - this.listener = new PropertyChangeListener() { - public void propertyChange(PropertyChangeEvent evt) { - if (propertyName.equals(evt.getPropertyName())) { - listener.propertyChange(evt); - } - } - }; - } - - /** - * Start listen to target (if it supports the JavaBean property change listener pattern) - * - * @param target - */ - public void hookListener(Object target) { - if (processListener( - "addPropertyChangeListener", "Could not attach listener to ", target)) { //$NON-NLS-1$ //$NON-NLS-2$ - elementsListenedTo.add(new IdentityWrapper(target)); - } - } - - /** - * Add listeners for new targets (those this instance of<code>ListenerSupport</code> does not - * already listen to), - * Stop to listen to those object that this instance listen to and is one of the object in targets - * - * @param targets - */ - public void setHookTargets(Object[] targets) { - Set elementsToUnhook = new HashSet(elementsListenedTo); - if (targets!=null) { - for (int i = 0; i < targets.length; i++) { - Object newValue = targets[i]; - IdentityWrapper identityWrapper = new IdentityWrapper(newValue); - if(!elementsToUnhook.remove(identityWrapper)) - hookListener(newValue); - } - } - - for (Iterator it = elementsToUnhook.iterator(); it.hasNext();) { - Object o = it.next(); - if (o.getClass()!=IdentityWrapper.class) - o = new IdentityWrapper(o); - elementsListenedTo.remove(o); - unhookListener(o); - } - } - - /** - * Stop listen to target - * - * @param target - */ - public void unhookListener(Object target) { - if (target.getClass() == IdentityWrapper.class) - target = ((IdentityWrapper) target).unwrap(); - - if (processListener( - "removePropertyChangeListener", "Cound not remove listener from ", target)) { //$NON-NLS-1$//$NON-NLS-2$ - elementsListenedTo.remove(new IdentityWrapper(target)); - } - } - - - /** - * - */ - public void dispose() { - if (elementsListenedTo!=null) { - Object[] targets = elementsListenedTo.toArray(); - for (int i = 0; i < targets.length; i++) { - unhookListener(targets[i]); - } - elementsListenedTo=null; - listener=null; - } - } - - /** - * @return elements that were registred to - */ - public Object[] getHookedTargets() { - Object[] targets = null; - if (elementsListenedTo!=null && elementsListenedTo.size()>0) { - Object[] identityList = elementsListenedTo.toArray(); - targets = new Object[identityList.length]; - for (int i = 0; i < identityList.length; i++) - targets[i]=((IdentityWrapper)identityList[i]).unwrap(); - } - return targets; - } - - /** - * Invokes the method for the provided <code>methodName</code> attempting - * to first use the method with the property name and then the unnamed - * version. - * - * @param methodName - * either addPropertyChangeListener or - * removePropertyChangeListener - * @param message - * string that will be prefixed to the target in an error message - * @param target - * object to invoke the method on - * @return <code>true</code> if the method was invoked successfully - */ - private boolean processListener(String methodName, String message, - Object target) { - Method method = null; - Object[] parameters = null; - - try { - try { - method = target.getClass().getMethod( - methodName, - new Class[] { String.class, - PropertyChangeListener.class }); - - parameters = new Object[] { propertyName, listener }; - } catch (NoSuchMethodException e) { - method = target.getClass().getMethod(methodName, - new Class[] { PropertyChangeListener.class }); - - parameters = new Object[] { listener }; - } - } catch (SecurityException e) { - // ignore - } catch (NoSuchMethodException e) { - log(IStatus.WARNING, message + target, e); - } - - if (method != null) { - if (!method.isAccessible()) { - method.setAccessible(true); - } - try { - method.invoke(target, parameters); - return true; - } catch (IllegalArgumentException e) { - log(IStatus.WARNING, message + target, e); - } catch (IllegalAccessException e) { - log(IStatus.WARNING, message + target, e); - } catch (InvocationTargetException e) { - log(IStatus.WARNING, message + target, e); - } - } - return false; - } - - /** - * Logs a message to the Data Binding logger. - */ - private void log(int severity, String message, Throwable throwable) { - if (BeansObservables.DEBUG) { - Policy.getLog().log( - new Status(severity, Policy.JFACE_DATABINDING, IStatus.OK, - message, throwable)); - } - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/AbstractObservable.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/AbstractObservable.java deleted file mode 100644 index 90e9b587..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/AbstractObservable.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - * Matthew Hall - bug 118516 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.AssertionFailedException; - -/** - * @since 1.0 - */ -public abstract class AbstractObservable extends ChangeManager implements IObservable { - - /** - * @param realm - */ - public AbstractObservable(Realm realm) { - super(realm); - } - - public synchronized void addChangeListener(IChangeListener listener) { - addListener(ChangeEvent.TYPE, listener); - } - - public synchronized void removeChangeListener(IChangeListener listener) { - removeListener(ChangeEvent.TYPE, listener); - } - - public synchronized void addStaleListener(IStaleListener listener) { - addListener(StaleEvent.TYPE, listener); - } - - public synchronized void removeStaleListener(IStaleListener listener) { - removeListener(StaleEvent.TYPE, listener); - } - - protected void fireChange() { - checkRealm(); - fireEvent(new ChangeEvent(this)); - } - - protected void fireStale() { - checkRealm(); - fireEvent(new StaleEvent(this)); - } - - /** - * - */ - public synchronized void dispose() { - super.dispose(); - } - - /** - * Asserts that the realm is the current realm. - * - * @see Realm#isCurrent() - * @throws AssertionFailedException if the realm is not the current realm - */ - protected void checkRealm() { - Assert.isTrue(getRealm().isCurrent(), - "This operation must be run within the observable's realm"); //$NON-NLS-1$ - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/ChangeEvent.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/ChangeEvent.java deleted file mode 100644 index 60950cf2..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/ChangeEvent.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable; - -/** - * Generic change event denoting that the state of an {@link IObservable} object - * has changed. This event does not carry information about the kind of change - * that occurred. - * - * @since 1.0 - * - */ -public class ChangeEvent extends ObservableEvent { - - /** - * - */ - private static final long serialVersionUID = -3241193109844979384L; - static final Object TYPE = new Object(); - - /** - * Creates a new change event object. - * - * @param source - * the observable that changed state - */ - public ChangeEvent(IObservable source) { - super(source); - } - - protected void dispatch(IObservablesListener listener) { - ((IChangeListener) listener).handleChange(this); - } - - protected Object getListenerType() { - return TYPE; - } - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/ChangeManager.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/ChangeManager.java deleted file mode 100644 index bf2be9ad..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/ChangeManager.java +++ /dev/null @@ -1,162 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 118516 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.ListenerList; - -/** - * Listener management implementation. Exposed to subclasses in form of - * {@link AbstractObservable} and {@link ChangeSupport}. - * - * @since 1.0 - * - */ -/* package */ class ChangeManager { - - ListenerList[] listenerLists = null; - Object listenerTypes[] = null; - private Realm realm; - - /** - * @param realm - * - */ - /* package */ ChangeManager(Realm realm) { - Assert.isNotNull(realm, "Realm cannot be null"); //$NON-NLS-1$ - this.realm = realm; - } - - /** - * @param listenerType - * @param listener - */ - protected void addListener(Object listenerType, - IObservablesListener listener) { - int listenerTypeIndex = findListenerTypeIndex(listenerType); - if (listenerTypeIndex == -1) { - int length; - if (listenerTypes == null) { - length = 0; - listenerTypes = new Object[1]; - listenerLists = new ListenerList[1]; - } else { - length = listenerTypes.length; - System.arraycopy(listenerTypes, 0, - listenerTypes = new Object[length + 1], 0, length); - System - .arraycopy(listenerLists, 0, - listenerLists = new ListenerList[length + 1], - 0, length); - } - listenerTypes[length] = listenerType; - listenerLists[length] = new ListenerList(); - boolean hadListeners = hasListeners(); - listenerLists[length].add(listener); - if (!hadListeners) { - this.firstListenerAdded(); - } - return; - } - ListenerList listenerList = listenerLists[listenerTypeIndex]; - boolean hadListeners = true; - if (listenerList.size() == 0) { - hadListeners = hasListeners(); - } - listenerList.add(listener); - if (!hadListeners) { - firstListenerAdded(); - } - } - - /** - * @param listenerType - * @param listener - */ - protected void removeListener(Object listenerType, - IObservablesListener listener) { - int listenerTypeIndex = findListenerTypeIndex(listenerType); - if (listenerTypeIndex != -1) { - listenerLists[listenerTypeIndex].remove(listener); - if (listenerLists[listenerTypeIndex].size() == 0) { - if (!hasListeners()) { - this.lastListenerRemoved(); - } - } - } - } - - protected boolean hasListeners() { - if (listenerTypes == null) { - return false; - } - for (int i = 0; i < listenerTypes.length; i++) { - if (listenerLists[i].size() > 0) { - return true; - } - } - return false; - } - - private int findListenerTypeIndex(Object listenerType) { - if (listenerTypes != null) { - for (int i = 0; i < listenerTypes.length; i++) { - if (listenerTypes[i] == listenerType) { - return i; - } - } - } - return -1; - } - - protected void fireEvent(ObservableEvent event) { - Object listenerType = event.getListenerType(); - int listenerTypeIndex = findListenerTypeIndex(listenerType); - if (listenerTypeIndex != -1) { - Object[] listeners = listenerLists[listenerTypeIndex] - .getListeners(); - for (int i = 0; i < listeners.length; i++) { - event.dispatch((IObservablesListener) listeners[i]); - } - } - } - - /** - * - */ - protected void firstListenerAdded() { - } - - /** - * - */ - protected void lastListenerRemoved() { - } - - /** - * - */ - public void dispose() { - listenerLists = null; - listenerTypes = null; - realm = null; - } - - /** - * @return Returns the realm. - */ - public Realm getRealm() { - return realm; - } - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/ChangeSupport.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/ChangeSupport.java deleted file mode 100644 index e91daeb3..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/ChangeSupport.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable; - -/** - * @since 1.0 - * - */ -public abstract class ChangeSupport extends ChangeManager { - - /** - * @param realm - */ - public ChangeSupport(Realm realm) { - super(realm); - } - - public void addListener(Object listenerType, - IObservablesListener listener) { - super.addListener(listenerType, listener); - } - - public void removeListener(Object listenerType, - IObservablesListener listener) { - super.removeListener(listenerType, listener); - } - - public void fireEvent(ObservableEvent event) { - super.fireEvent(event); - } - - /** - * - */ - protected abstract void firstListenerAdded(); - - /** - * - */ - protected abstract void lastListenerRemoved(); - - /** - * @param listener - */ - public void addChangeListener(IChangeListener listener) { - addListener(ChangeEvent.TYPE, listener); - } - - /** - * @param listener - */ - public void removeChangeListener(IChangeListener listener) { - removeListener(ChangeEvent.TYPE, listener); - } - - /** - * @param listener - */ - public void addStaleListener(IStaleListener listener) { - addListener(StaleEvent.TYPE, listener); - } - - /** - * @param listener - */ - public void removeStaleListener(IStaleListener listener) { - removeListener(StaleEvent.TYPE, listener); - } - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/Diffs.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/Diffs.java deleted file mode 100644 index 9500537e..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/Diffs.java +++ /dev/null @@ -1,470 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 226216 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.Map.Entry; - -import org.eclipse.core.databinding.observable.list.ListDiff; -import org.eclipse.core.databinding.observable.list.ListDiffEntry; -import org.eclipse.core.databinding.observable.map.MapDiff; -import org.eclipse.core.databinding.observable.set.SetDiff; -import org.eclipse.core.databinding.observable.value.ValueDiff; -import org.eclipse.core.internal.databinding.Util; - -/** - * @since 1.0 - * - */ -public class Diffs { - - /** - * @param oldList - * @param newList - * @return the differences between oldList and newList - */ - public static ListDiff computeListDiff(List oldList, List newList) { - List diffEntries = new ArrayList(); - createListDiffs(new ArrayList(oldList), newList, diffEntries); - ListDiff listDiff = createListDiff((ListDiffEntry[]) diffEntries - .toArray(new ListDiffEntry[diffEntries.size()])); - return listDiff; - } - - /** - * adapted from EMF's ListDifferenceAnalyzer - */ - private static void createListDiffs(List oldList, List newList, - List listDiffs) { - int index = 0; - for (Iterator it = newList.iterator(); it.hasNext();) { - Object newValue = it.next(); - if (oldList.size() <= index) { - // append newValue to newList - listDiffs.add(createListDiffEntry(index, true, newValue)); - } else { - boolean done; - do { - done = true; - Object oldValue = oldList.get(index); - if (oldValue == null ? newValue != null : !oldValue.equals(newValue)) { - int oldIndexOfNewValue = listIndexOf(oldList, newValue, index); - if (oldIndexOfNewValue != -1) { - int newIndexOfOldValue = listIndexOf(newList, oldValue, index); - if (newIndexOfOldValue == -1) { - // removing oldValue from list[index] - listDiffs.add(createListDiffEntry(index, false, oldValue)); - oldList.remove(index); - done = false; - } else if (newIndexOfOldValue > oldIndexOfNewValue) { - // moving oldValue from list[index] to [newIndexOfOldValue] - if (oldList.size() <= newIndexOfOldValue) { - // The element cannot be moved to the correct index - // now, however later iterations will insert elements - // in front of it, eventually moving it into the - // correct spot. - newIndexOfOldValue = oldList.size() - 1; - } - listDiffs.add(createListDiffEntry(index, false, oldValue)); - oldList.remove(index); - listDiffs.add(createListDiffEntry(newIndexOfOldValue, true, oldValue)); - oldList.add(newIndexOfOldValue, oldValue); - done = false; - } else { - // move newValue from list[oldIndexOfNewValue] to [index] - listDiffs.add(createListDiffEntry(oldIndexOfNewValue, false, newValue)); - oldList.remove(oldIndexOfNewValue); - listDiffs.add(createListDiffEntry(index, true, newValue)); - oldList.add(index, newValue); - } - } else { - // add newValue at list[index] - oldList.add(index, newValue); - listDiffs.add(createListDiffEntry(index, true, newValue)); - } - } - } while (!done); - } - ++index; - } - for (int i = oldList.size(); i > index;) { - // remove excess trailing elements not present in newList - listDiffs.add(createListDiffEntry(--i, false, oldList.get(i))); - } - } - - /** - * @param list - * @param object - * @param index - * @return the index, or -1 if not found - */ - private static int listIndexOf(List list, Object object, int index) { - int size = list.size(); - for (int i=index; i<size;i++) { - Object candidate = list.get(i); - if (candidate==null ? object==null : candidate.equals(object)) { - return i; - } - } - return -1; - } - - /** - * Checks whether the two objects are <code>null</code> -- allowing for - * <code>null</code>. - * - * @param left - * The left object to compare; may be <code>null</code>. - * @param right - * The right object to compare; may be <code>null</code>. - * @return <code>true</code> if the two objects are equivalent; - * <code>false</code> otherwise. - */ - public static final boolean equals(final Object left, final Object right) { - return left == null ? right == null : ((right != null) && left - .equals(right)); - } - - /** - * @param oldSet - * @param newSet - * @return a set diff - */ - public static SetDiff computeSetDiff(Set oldSet, Set newSet) { - Set additions = new HashSet(newSet); - additions.removeAll(oldSet); - Set removals = new HashSet(oldSet); - removals.removeAll(newSet); - return createSetDiff(additions, removals); - } - - /** - * Computes the difference between two maps. - * - * @param oldMap - * @param newMap - * @return a map diff representing the changes needed to turn oldMap into - * newMap - */ - public static MapDiff computeMapDiff(Map oldMap, Map newMap) { - // starts out with all keys from the new map, we will remove keys from - // the old map as we go - final Set addedKeys = new HashSet(newMap.keySet()); - final Set removedKeys = new HashSet(); - final Set changedKeys = new HashSet(); - final Map oldValues = new HashMap(); - final Map newValues = new HashMap(); - for (Iterator it = oldMap.entrySet().iterator(); it.hasNext();) { - Map.Entry oldEntry = (Entry) it.next(); - Object oldKey = oldEntry.getKey(); - if (addedKeys.remove(oldKey)) { - // potentially changed key since it is in oldMap and newMap - Object oldValue = oldEntry.getValue(); - Object newValue = newMap.get(oldKey); - if (!Util.equals(oldValue, newValue)) { - changedKeys.add(oldKey); - oldValues.put(oldKey, oldValue); - newValues.put(oldKey, newValue); - } - } else { - removedKeys.add(oldKey); - oldValues.put(oldKey, oldEntry.getValue()); - } - } - for (Iterator it = addedKeys.iterator(); it.hasNext();) { - Object newKey = it.next(); - newValues.put(newKey, newMap.get(newKey)); - } - return new MapDiff() { - public Set getAddedKeys() { - return addedKeys; - } - - public Set getChangedKeys() { - return changedKeys; - } - - public Set getRemovedKeys() { - return removedKeys; - } - - public Object getNewValue(Object key) { - return newValues.get(key); - } - - public Object getOldValue(Object key) { - return oldValues.get(key); - } - }; - } - - /** - * @param oldValue - * @param newValue - * @return a value diff - */ - public static ValueDiff createValueDiff(final Object oldValue, - final Object newValue) { - return new ValueDiff() { - - public Object getOldValue() { - return oldValue; - } - - public Object getNewValue() { - return newValue; - } - }; - } - - /** - * @param additions - * @param removals - * @return a set diff - */ - public static SetDiff createSetDiff(Set additions, Set removals) { - final Set unmodifiableAdditions = Collections - .unmodifiableSet(additions); - final Set unmodifiableRemovals = Collections.unmodifiableSet(removals); - return new SetDiff() { - - public Set getAdditions() { - return unmodifiableAdditions; - } - - public Set getRemovals() { - return unmodifiableRemovals; - } - }; - } - - /** - * @param difference - * @return a list diff with one differing entry - */ - public static ListDiff createListDiff(ListDiffEntry difference) { - return createListDiff(new ListDiffEntry[] { difference }); - } - - /** - * @param difference1 - * @param difference2 - * @return a list diff with two differing entries - */ - public static ListDiff createListDiff(ListDiffEntry difference1, - ListDiffEntry difference2) { - return createListDiff(new ListDiffEntry[] { difference1, difference2 }); - } - - /** - * @param differences - * @return a list diff with the given entries - */ - public static ListDiff createListDiff(final ListDiffEntry[] differences) { - return new ListDiff() { - public ListDiffEntry[] getDifferences() { - return differences; - } - }; - } - - /** - * @param position - * @param isAddition - * @param element - * @return a list diff entry - */ - public static ListDiffEntry createListDiffEntry(final int position, - final boolean isAddition, final Object element) { - return new ListDiffEntry() { - - public int getPosition() { - return position; - } - - public boolean isAddition() { - return isAddition; - } - - public Object getElement() { - return element; - } - }; - } - - /** - * @param addedKey - * @param newValue - * @return a map diff - */ - public static MapDiff createMapDiffSingleAdd(final Object addedKey, - final Object newValue) { - return new MapDiff() { - - public Set getAddedKeys() { - return Collections.singleton(addedKey); - } - - public Set getChangedKeys() { - return Collections.EMPTY_SET; - } - - public Object getNewValue(Object key) { - return newValue; - } - - public Object getOldValue(Object key) { - return null; - } - - public Set getRemovedKeys() { - return Collections.EMPTY_SET; - } - }; - } - - /** - * @param existingKey - * @param oldValue - * @param newValue - * @return a map diff - */ - public static MapDiff createMapDiffSingleChange(final Object existingKey, - final Object oldValue, final Object newValue) { - return new MapDiff() { - - public Set getAddedKeys() { - return Collections.EMPTY_SET; - } - - public Set getChangedKeys() { - return Collections.singleton(existingKey); - } - - public Object getNewValue(Object key) { - return newValue; - } - - public Object getOldValue(Object key) { - return oldValue; - } - - public Set getRemovedKeys() { - return Collections.EMPTY_SET; - } - }; - } - - /** - * @param removedKey - * @param oldValue - * @return a map diff - */ - public static MapDiff createMapDiffSingleRemove(final Object removedKey, - final Object oldValue) { - return new MapDiff() { - - public Set getAddedKeys() { - return Collections.EMPTY_SET; - } - - public Set getChangedKeys() { - return Collections.EMPTY_SET; - } - - public Object getNewValue(Object key) { - return null; - } - - public Object getOldValue(Object key) { - return oldValue; - } - - public Set getRemovedKeys() { - return Collections.singleton(removedKey); - } - }; - } - - /** - * @param copyOfOldMap - * @return a map diff - */ - public static MapDiff createMapDiffRemoveAll(final Map copyOfOldMap) { - return new MapDiff() { - - public Set getAddedKeys() { - return Collections.EMPTY_SET; - } - - public Set getChangedKeys() { - return Collections.EMPTY_SET; - } - - public Object getNewValue(Object key) { - return null; - } - - public Object getOldValue(Object key) { - return copyOfOldMap.get(key); - } - - public Set getRemovedKeys() { - return copyOfOldMap.keySet(); - } - }; - } - - /** - * @param addedKeys - * @param removedKeys - * @param changedKeys - * @param oldValues - * @param newValues - * @return a map diff - */ - public static MapDiff createMapDiff(final Set addedKeys, - final Set removedKeys, final Set changedKeys, final Map oldValues, - final Map newValues) { - return new MapDiff() { - - public Set getAddedKeys() { - return addedKeys; - } - - public Set getChangedKeys() { - return changedKeys; - } - - public Object getNewValue(Object key) { - return newValues.get(key); - } - - public Object getOldValue(Object key) { - return oldValues.get(key); - } - - public Set getRemovedKeys() { - return removedKeys; - } - }; - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/IChangeListener.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/IChangeListener.java deleted file mode 100644 index d0a5cee9..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/IChangeListener.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable; - -import org.eclipse.core.databinding.observable.list.IListChangeListener; -import org.eclipse.core.databinding.observable.map.IMapChangeListener; -import org.eclipse.core.databinding.observable.set.ISetChangeListener; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; - -/** - * Listener for generic change events. Note that the change events do not carry - * information about the change, they only specify the affected observable. To - * listen for specific change events, use more specific change listeners. - * - * @see IValueChangeListener - * @see IListChangeListener - * @see ISetChangeListener - * @see IMapChangeListener - * - * @since 1.0 - */ -public interface IChangeListener extends IObservablesListener { - - /** - * Handle a generic change to the given observable. The given event object - * must only be used locally in this method because it may be reused for - * other change notifications. - * - * @param event - */ - public void handleChange(ChangeEvent event); - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/IObservable.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/IObservable.java deleted file mode 100644 index de8e8cde..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/IObservable.java +++ /dev/null @@ -1,109 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.core.databinding.observable; - -/** - * An object with state that allows to listen for state changes. - * - * <p> - * Implementations must not manage listeners themselves, listener management - * must be delegated to a private instance of type {@link ChangeSupport} if it - * is not inherited from {@link AbstractObservable}. - * </p> - * - * @noextend This interface is not intended to be extended by clients. - * @noimplement This interface is not intended to be implemented by clients. - * Clients should instead subclass one of the classes in the - * framework that implement this interface. Note that direct - * implementers of this interface outside of the framework will be - * broken in future releases when methods are added to this - * interface. - * - * @since 1.0 - * - */ -public interface IObservable { - - /** - * Returns the realm for this observable. Unless otherwise specified, - * getters and setters must be accessed from within this realm. Listeners - * will be within this realm when they receive events from this observable. - * <p> - * Because observables can only be accessed from within one realm, and they - * always fire events on that realm, their state can be observed in an - * incremental way. It is always safe to call getters of an observable from - * within a change listener attached to that observable. - * </p> - * - * @return the realm - */ - public Realm getRealm(); - - /** - * Adds the given change listener to the list of change listeners. Change - * listeners are notified about changes of the state of this observable in a - * generic way, without specifying the change that happened. To get the - * changed state, a change listener needs to query for the current state of - * this observable. - * - * @param listener - */ - public void addChangeListener(IChangeListener listener); - - /** - * Removes the given change listener from the list of change listeners. Has - * no effect if the given listener is not registered as a change listener. - * - * @param listener - */ - public void removeChangeListener(IChangeListener listener); - - /** - * Adds the given stale listener to the list of stale listeners. Stale - * listeners are notified when an observable object becomes stale, not when - * is becomes non-stale. - * - * @param listener - * - * @see #isStale() - */ - public void addStaleListener(IStaleListener listener); - - /** - * Removes the given stale listener from the list of stale listeners. Has no - * effect if the given listener is not registered as a stale listener. - * - * @param listener - */ - public void removeStaleListener(IStaleListener listener); - - /** - * Returns whether the state of this observable is stale and is expected to - * change soon. A non-stale observable that becomes stale will notify its - * stale listeners. A stale object that becomes non-stale does so by - * changing its state and notifying its change listeners, it does <b>not</b> - * notify its stale listeners about becoming non-stale. Clients that do not - * expect asynchronous changes may ignore staleness of observable objects. - * - * @return true if this observable's state is stale and will change soon. - * - * @TrackedGetter - implementers must call - * {@link ObservableTracker#getterCalled(IObservable)}. - */ - public boolean isStale(); - - /** - * Disposes of this observable object, removing all listeners registered - * with this object, and all listeners this object might have registered on - * other objects. - */ - public void dispose(); -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/IObservableCollection.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/IObservableCollection.java deleted file mode 100644 index 66e669af..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/IObservableCollection.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable; - -import java.util.Collection; - -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.set.IObservableSet; - -/** - * Interface for observable collections. Only general change listeners can be - * added to an observable collection. Listeners interested in incremental - * changes have to be added using more concrete subtypes such as - * {@link IObservableList} or {@link IObservableSet}. - * - * @noextend This interface is not intended to be extended by clients. - * @noimplement This interface is not intended to be implemented by clients. - * Clients should instead subclass one of the classes that - * implement this interface. Note that direct implementers of this - * interface outside of the framework will be broken in future - * releases when methods are added to this interface. - * </p> - * - * @since 1.0 - */ -public interface IObservableCollection extends IObservable, Collection { - - /** - * @return the element type of this observable value, or <code>null</code> - * if this observable collection is untyped. - */ - Object getElementType(); - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/IObservablesListener.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/IObservablesListener.java deleted file mode 100644 index bc0687c9..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/IObservablesListener.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable; - -/** - * Marker interface for all listener types in the observables framework. - * - * @noimplement This interface is not intended to be implemented by clients. - * - * @since 1.0 - */ -public interface IObservablesListener { - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/IObserving.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/IObserving.java deleted file mode 100644 index 1c9fc139..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/IObserving.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.databinding.observable; - -/** - * - * Mixin interface for IObservables that observe other objects. - * - * @since 1.0 - * - */ -public interface IObserving { - - /** - * Returns the observed object, or <code>null</code> if this observing - * object does not currently observe an object. - * - * @return the observed object, or <code>null</code> - */ - public Object getObserved(); - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/IStaleListener.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/IStaleListener.java deleted file mode 100644 index 57291983..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/IStaleListener.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable; - -/** - * Listener for staleness events. An observable object is stale if its state - * will change eventually. - * - * @since 1.0 - */ -public interface IStaleListener extends IObservablesListener { - - /** - * Handle the event that the given observable object is now stale. The given - * event object must only be used locally in this method because it may be - * reused for other change notifications. - * - * @param staleEvent - */ - public void handleStale(StaleEvent staleEvent); - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/ObservableEvent.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/ObservableEvent.java deleted file mode 100644 index 38a865c5..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/ObservableEvent.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable; - -import java.util.EventObject; - -/** - * Abstract event object for events fired by {@link IObservable} objects. All - * events fired by observables must be derived from this class so that the way - * of dispatching events can be improved in later versions of the framework. - * - * @since 1.0 - * - */ -public abstract class ObservableEvent extends EventObject { - - /** - * Creates a new observable event. - * - * @param source - */ - public ObservableEvent(IObservable source) { - super(source); - } - - /** - * - */ - private static final long serialVersionUID = 7693906965267871813L; - - /** - * Returns the observable that generated this event. - * - * @return the observable that generated this event - */ - public IObservable getObservable() { - return (IObservable) getSource(); - } - - /** - * Dispatch this event to the given listener. Subclasses must implement this - * method by calling the appropriate type-safe event handling method on the - * given listener according to the type of this event. - * - * @param listener - * the listener that should handle the event - */ - protected abstract void dispatch(IObservablesListener listener); - - /** - * Returns a unique object used for distinguishing this event type from - * others. - * - * @return a unique object representing the concrete type of this event. - */ - protected abstract Object getListenerType(); - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/ObservableTracker.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/ObservableTracker.java deleted file mode 100644 index 8e3fca96..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/ObservableTracker.java +++ /dev/null @@ -1,200 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - Fix NPE, more detailed assert messages (bug 210115) - *******************************************************************************/ -package org.eclipse.core.databinding.observable; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.internal.databinding.IdentityWrapper; -import org.eclipse.core.runtime.Assert; - -/** - * This class makes it possible to monitor whenever an IObservable is read from. - * This can be used to automatically attach and remove listeners. How to use it: - * - * <p> - * If you are implementing an IObservable, invoke getterCalled(this) whenever a - * getter is called - that is, whenever your observable is read from. You only - * need to do this once per method call. If one getter delegates to another, the - * outer getter doesn't need to call the method since the inner one will. - * </p> - * - * <p> - * If you want to determine what observables were used in a particular block of - * code, call runAndMonitor(Runnable). This will execute the given runnable and - * return the set of observables that were read from. - * </p> - * - * <p> - * This can be used to automatically attach listeners. For example, imagine you - * have a block of code that updates some widget by reading from a bunch of - * observables. Whenever one of those observables changes, you want to re-run - * the code and cause the widget to be refreshed. You could do this in the - * traditional manner by attaching one listener to each observable and - * re-running your widget update code whenever one of them changes, but this - * code is repetitive and requires updating the listener code whenever you - * refactor the widget updating code. - * </p> - * - * <p> - * Alternatively, you could use a utility class that runs the code in a - * runAndMonitor block and automatically attach listeners to any observable used - * in updating the widget. The advantage of the latter approach is that it, - * eliminates the code for attaching and detaching listeners and will always - * stay in synch with changes to the widget update logic. - * </p> - * - * @since 1.0 - */ -public class ObservableTracker { - - /** - * Threadlocal storage pointing to the current Set of IObservables, or null - * if none. Note that this is actually the top of a stack. Whenever a method - * changes the current value, it remembers the old value as a local variable - * and restores the old value when the method exits. - */ - private static ThreadLocal currentChangeListener = new ThreadLocal(); - - private static ThreadLocal currentStaleListener = new ThreadLocal(); - - private static ThreadLocal currentObservableSet = new ThreadLocal(); - - /** - * Invokes the given runnable, and returns the set of IObservables that were - * read by the runnable. If the runnable calls this method recursively, the - * result will not contain IObservables that were used within the inner - * runnable. - * - * @param runnable - * runnable to execute - * @param changeListener - * listener to register with all accessed observables - * @param staleListener - * listener to register with all accessed observables, or - * <code>null</code> if no stale listener is to be registered - * @return an array of unique observable objects - */ - public static IObservable[] runAndMonitor(Runnable runnable, - IChangeListener changeListener, IStaleListener staleListener) { - // Remember the previous value in the listener stack - Set lastObservableSet = (Set) currentObservableSet.get(); - IChangeListener lastChangeListener = (IChangeListener) currentChangeListener - .get(); - IStaleListener lastStaleListener = (IStaleListener) currentStaleListener - .get(); - - Set observableSet = new HashSet(); - // Push the new listeners to the top of the stack - currentObservableSet.set(observableSet); - currentChangeListener.set(changeListener); - currentStaleListener.set(staleListener); - try { - runnable.run(); - } finally { - // Pop the new listener off the top of the stack (by restoring the - // previous listener) - currentObservableSet.set(lastObservableSet); - currentChangeListener.set(lastChangeListener); - currentStaleListener.set(lastStaleListener); - } - - int i = 0; - IObservable[] result = new IObservable[observableSet.size()]; - for (Iterator it = observableSet.iterator(); it.hasNext();) { - IdentityWrapper wrapper = (IdentityWrapper) it.next(); - result[i++] = (IObservable) wrapper.unwrap(); - } - - return result; - } - - /** - * Runs the given runnable without tracking dependencies. - * @param runnable - * - * @since 1.1 - */ - public static void runAndIgnore(Runnable runnable) { - // Remember the previous value in the listener stack - Set lastObservableSet = (Set) currentObservableSet.get(); - IChangeListener lastChangeListener = (IChangeListener) currentChangeListener - .get(); - IStaleListener lastStaleListener = (IStaleListener) currentStaleListener - .get(); - currentObservableSet.set(null); - currentChangeListener.set(null); - currentStaleListener.set(null); - try { - runnable.run(); - } finally { - // Pop the new listener off the top of the stack (by restoring the - // previous listener) - currentObservableSet.set(lastObservableSet); - currentChangeListener.set(lastChangeListener); - currentStaleListener.set(lastStaleListener); - } - } - - /* - * Returns the same string as the default Object.toString() implementation. - * getterCalled() uses this method IObservable.toString() to avoid infinite - * recursion and stack overflow. - */ - private static String toString(IObservable observable) { - return observable.getClass().getName() + "@" //$NON-NLS-1$ - + Integer.toHexString(System.identityHashCode(observable)); - } - - /** - * Notifies the ObservableTracker that an observable was read from. The - * JavaDoc for methods that invoke this method should include the following - * tag: "@TrackedGetter This method will notify ObservableTracker that the - * receiver has been read from". This lets callers know that they can rely - * on automatic updates from the object without explicitly attaching a - * listener. - * - * @param observable - */ - public static void getterCalled(IObservable observable) { - Realm realm = observable.getRealm(); - if (realm == null) // observable.isDisposed() would be more appropriate if it existed - Assert.isTrue(false, "Getter called on disposed observable " //$NON-NLS-1$ - + toString(observable)); - if (!realm.isCurrent()) - Assert.isTrue(false, "Getter called outside realm of observable " //$NON-NLS-1$ - + toString(observable)); - - Set lastObservableSet = (Set) currentObservableSet.get(); - if (lastObservableSet == null) { - return; - } - IChangeListener lastChangeListener = (IChangeListener) currentChangeListener - .get(); - IStaleListener lastStaleListener = (IStaleListener) currentStaleListener - .get(); - - boolean added = false; - if (lastObservableSet != null) { - added = lastObservableSet.add(new IdentityWrapper(observable)); - } - - // If anyone is listening for observable usage... - if (added && lastChangeListener != null) { - observable.addChangeListener(lastChangeListener); - } - if (added && lastStaleListener != null) { - observable.addStaleListener(lastStaleListener); - } - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/Observables.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/Observables.java deleted file mode 100644 index f2720801..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/Observables.java +++ /dev/null @@ -1,514 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006-2008 Cerner Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Brad Reynolds - initial API and implementation - * Matt Carter - bug 212518 (constantObservableValue) - * Matthew Hall - bugs 208332, 212518, 219909, 184830 - * Marko Topolnik - bug 184830 - ******************************************************************************/ - -package org.eclipse.core.databinding.observable; - -import java.util.List; -import java.util.Set; - -import org.eclipse.core.databinding.observable.list.IListChangeListener; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.ObservableList; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.masterdetail.MasterDetailObservables; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.ISetChangeListener; -import org.eclipse.core.databinding.observable.set.ObservableSet; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.internal.databinding.observable.ConstantObservableValue; -import org.eclipse.core.internal.databinding.observable.EmptyObservableList; -import org.eclipse.core.internal.databinding.observable.EmptyObservableSet; -import org.eclipse.core.internal.databinding.observable.MapEntryObservableValue; -import org.eclipse.core.internal.databinding.observable.ProxyObservableList; -import org.eclipse.core.internal.databinding.observable.ProxyObservableSet; -import org.eclipse.core.internal.databinding.observable.StalenessObservableValue; -import org.eclipse.core.internal.databinding.observable.UnmodifiableObservableList; -import org.eclipse.core.internal.databinding.observable.UnmodifiableObservableSet; -import org.eclipse.core.internal.databinding.observable.UnmodifiableObservableValue; -import org.eclipse.core.runtime.Assert; - -/** - * Contains static methods to operate on or return - * {@link IObservable Observables}. - * - * @since 1.0 - */ -public class Observables { - /** - * Returns an unmodifiable observable value backed by the given observable - * value. - * - * @param value - * the value to wrap in an unmodifiable value - * @return an unmodifiable observable value backed by the given observable - * value - * @since 1.1 - */ - public static IObservableValue unmodifiableObservableValue( - IObservableValue value) { - Assert.isNotNull(value, "Argument 'value' cannot be null"); //$NON-NLS-1$ - return new UnmodifiableObservableValue(value); - } - - /** - * Returns an observable value with the given constant value. - * - * @param realm - * the observable's realm - * @param value - * the observable's constant value - * @param valueType - * the observable's value type - * @return an immutable observable value with the given constant value - * @since 1.1 - */ - public static IObservableValue constantObservableValue(Realm realm, - Object value, Object valueType) { - return new ConstantObservableValue(realm, value, valueType); - } - - /** - * Returns an observable value with the given constant value. - * - * @param realm - * the observable's realm - * @param value - * the observable's constant value - * @return an immutable observable value with the given constant value - * @since 1.1 - */ - public static IObservableValue constantObservableValue(Realm realm, - Object value) { - return constantObservableValue(realm, value, null); - } - - /** - * Returns an observable value with the given constant value. - * - * @param value - * the observable's constant value - * @param valueType - * the observable's value type - * @return an immutable observable value with the given constant value - * @since 1.1 - */ - public static IObservableValue constantObservableValue(Object value, - Object valueType) { - return constantObservableValue(Realm.getDefault(), value, valueType); - } - - /** - * Returns an observable value with the given constant value. - * - * @param value - * the observable's constant value - * @return an immutable observable value with the given constant value - * @since 1.1 - */ - public static IObservableValue constantObservableValue(Object value) { - return constantObservableValue(Realm.getDefault(), value, null); - } - - /** - * Returns an unmodifiable observable list backed by the given observable - * list. - * - * @param list - * the list to wrap in an unmodifiable list - * @return an unmodifiable observable list backed by the given observable - * list - */ - public static IObservableList unmodifiableObservableList( - IObservableList list) { - if (list == null) { - throw new IllegalArgumentException("List parameter cannot be null."); //$NON-NLS-1$ - } - - return new UnmodifiableObservableList(list); - } - - /** - * Returns an unmodifiable observable set backed by the given observable - * set. - * - * @param set - * the set to wrap in an unmodifiable set - * @return an unmodifiable observable set backed by the given observable set - * @since 1.1 - */ - public static IObservableSet unmodifiableObservableSet(IObservableSet set) { - if (set == null) { - throw new IllegalArgumentException("Set parameter cannot be null"); //$NON-NLS-1$ - } - - return new UnmodifiableObservableSet(set); - } - - /** - * Returns an empty observable list. The returned list continues to work - * after it has been disposed of and can be disposed of multiple times. - * - * @return an empty observable list. - */ - public static IObservableList emptyObservableList() { - return emptyObservableList(Realm.getDefault(), null); - } - - /** - * Returns an empty observable list of the given element type. The returned - * list continues to work after it has been disposed of and can be disposed - * of multiple times. - * - * @param elementType - * the element type of the returned list - * @return an empty observable list - * @since 1.1 - */ - public static IObservableList emptyObservableList(Object elementType) { - return emptyObservableList(Realm.getDefault(), elementType); - } - - /** - * Returns an empty observable list belonging to the given realm. The - * returned list continues to work after it has been disposed of and can be - * disposed of multiple times. - * - * @param realm - * the realm of the returned list - * @return an empty observable list. - */ - public static IObservableList emptyObservableList(Realm realm) { - return emptyObservableList(realm, null); - } - - /** - * Returns an empty observable list of the given element type and belonging - * to the given realm. The returned list continues to work after it has been - * disposed of and can be disposed of multiple times. - * - * @param realm - * the realm of the returned list - * @param elementType - * the element type of the returned list - * @return an empty observable list - * @since 1.1 - */ - public static IObservableList emptyObservableList(Realm realm, - Object elementType) { - return new EmptyObservableList(realm, elementType); - } - - /** - * Returns an empty observable set. The returned set continues to work after - * it has been disposed of and can be disposed of multiple times. - * - * @return an empty observable set. - */ - public static IObservableSet emptyObservableSet() { - return emptyObservableSet(Realm.getDefault(), null); - } - - /** - * Returns an empty observable set of the given element type. The returned - * set continues to work after it has been disposed of and can be disposed - * of multiple times. - * - * @param elementType - * the element type of the returned set - * @return an empty observable set - * @since 1.1 - */ - public static IObservableSet emptyObservableSet(Object elementType) { - return emptyObservableSet(Realm.getDefault(), elementType); - } - - /** - * Returns an empty observable set belonging to the given realm. The - * returned set continues to work after it has been disposed of and can be - * disposed of multiple times. - * - * @param realm - * the realm of the returned set - * @return an empty observable set. - */ - public static IObservableSet emptyObservableSet(Realm realm) { - return emptyObservableSet(realm, null); - } - - /** - * Returns an empty observable set of the given element type and belonging - * to the given realm. The returned set continues to work after it has been - * disposed of and can be disposed of multiple times. - * - * @param realm - * the realm of the returned set - * @param elementType - * the element type of the returned set - * @return an empty observable set - * @since 1.1 - */ - public static IObservableSet emptyObservableSet(Realm realm, - Object elementType) { - return new EmptyObservableSet(realm, elementType); - } - - /** - * Returns an observable set backed by the given set. - * - * @param set - * the set to wrap in an IObservableSet - * @return an observable set backed by the given set - */ - public static IObservableSet staticObservableSet(Set set) { - return staticObservableSet(Realm.getDefault(), set, Object.class); - } - - /** - * Returns an observable set of the given element type, backed by the given - * set. - * - * @param set - * the set to wrap in an IObservableSet - * @param elementType - * the element type of the returned set - * @return Returns an observable set backed by the given unchanging set - * @since 1.1 - */ - public static IObservableSet staticObservableSet(Set set, Object elementType) { - return staticObservableSet(Realm.getDefault(), set, elementType); - } - - /** - * Returns an observable set belonging to the given realm, backed by the - * given set. - * - * @param realm - * the realm of the returned set - * @param set - * the set to wrap in an IObservableSet - * @return an observable set backed by the given unchanging set - */ - public static IObservableSet staticObservableSet(Realm realm, Set set) { - return staticObservableSet(realm, set, Object.class); - } - - /** - * Returns an observable set of the given element type and belonging to the - * given realm, backed by the given set. - * - * @param realm - * the realm of the returned set - * @param set - * the set to wrap in an IObservableSet - * @param elementType - * the element type of the returned set - * @return an observable set backed by the given set - * @since 1.1 - */ - public static IObservableSet staticObservableSet(Realm realm, Set set, - Object elementType) { - return new ObservableSet(realm, set, elementType) { - public void addChangeListener(IChangeListener listener) { - } - - public void addStaleListener(IStaleListener listener) { - } - - public void addSetChangeListener(ISetChangeListener listener) { - } - }; - } - - /** - * Returns an observable set that contains the same elements as the given - * set, and fires the same events as the given set, but can be disposed of - * without disposing of the wrapped set. - * - * @param target - * the set to wrap - * @return a disposable proxy for the given observable set - */ - public static IObservableSet proxyObservableSet(IObservableSet target) { - return new ProxyObservableSet(target); - } - - /** - * Returns an observable list that contains the same elements as the given - * list, and fires the same events as the given list, but can be disposed of - * without disposing of the wrapped list. - * - * @param target - * the list to wrap - * @return a disposable proxy for the given observable list - * @since 1.1 - */ - public static IObservableList proxyObservableList(IObservableList target) { - return new ProxyObservableList(target); - } - - /** - * Returns an observable list backed by the given list. - * - * @param list - * the list to wrap in an IObservableList - * @return an observable list backed by the given unchanging list - */ - public static IObservableList staticObservableList(List list) { - return staticObservableList(Realm.getDefault(), list, Object.class); - } - - /** - * Returns an observable list of the given element type, backed by the given - * list. - * - * @param list - * the list to wrap in an IObservableList - * @param elementType - * the element type of the returned list - * @return an observable list backed by the given unchanging list - * @since 1.1 - */ - public static IObservableList staticObservableList(List list, - Object elementType) { - return staticObservableList(Realm.getDefault(), list, elementType); - } - - /** - * Returns an observable list belonging to the given realm, backed by the - * given list. - * - * @param realm - * the realm of the returned list - * @param list - * the list to wrap in an IObservableList - * @return an observable list backed by the given unchanging list - */ - public static IObservableList staticObservableList(Realm realm, List list) { - return staticObservableList(realm, list, Object.class); - } - - /** - * Returns an observable list of the given element type and belonging to the - * given realm, backed by the given list. - * - * @param realm - * the realm of the returned list - * @param list - * the list to wrap in an IObservableList - * @param elementType - * the element type of the returned list - * @return an observable list backed by the given unchanging list - * @since 1.1 - */ - public static IObservableList staticObservableList(Realm realm, List list, - Object elementType) { - return new ObservableList(realm, list, elementType) { - public void addChangeListener(IChangeListener listener) { - } - - public void addStaleListener(IStaleListener listener) { - } - - public void addListChangeListener(IListChangeListener listener) { - } - }; - } - - /** - * Returns an observable value of type <code>Boolean.TYPE</code> which - * tracks whether the given observable is stale. - * - * @param observable - * the observable to track - * @return an observable value which tracks whether the given observable is - * stale - * - * @since 1.1 - */ - public static IObservableValue observeStale(IObservable observable) { - return new StalenessObservableValue(observable); - } - - /** - * Returns an observable value that tracks changes to the value of an - * observable map's entry specified by its key. - * <p> - * The state where the key does not exist in the map is equivalent to the - * state where the key exists and its value is <code>null</code>. The - * transition between these two states is not considered a value change and - * no event is fired. - * - * @param map - * the observable map whose entry will be tracked. - * @param key - * the key identifying the map entry to track. - * @param valueType - * the type of the value. May be <code>null</code>, meaning - * the value is untyped. - * @return an observable value that tracks the value associated with the - * specified key in the given map - * @since 1.1 - */ - public static IObservableValue observeMapEntry(IObservableMap map, - Object key, Object valueType) { - return new MapEntryObservableValue(map, key, valueType); - } - - /** - * Returns a factory for creating obervable values tracking the value of the - * {@link IObservableMap observable map} entry identified by a particular - * key. - * - * @param map - * the observable map whose entry will be tracked. - * @param valueType - * the type of the value. May be <code>null</code>, meaning - * the value is untyped. - * @return a factory for creating observable values tracking the value of - * the observable map entry identified by a particular key object. - * @since 1.1 - */ - public static IObservableFactory mapEntryValueFactory( - final IObservableMap map, final Object valueType) { - return new IObservableFactory() { - public IObservable createObservable(Object key) { - return observeMapEntry(map, key, valueType); - } - }; - } - - /** - * Helper method for <code>MasterDetailObservables.detailValue(master, - * mapEntryValueFactory(map, valueType), valueType)</code>. - * - * @param map - * the observable map whose entry will be tracked. - * @param master - * the observable value that identifies which map entry to track. - * @param valueType - * the type of the value. May be <code>null</code>, meaning - * the value is untyped. - * @return an observable value tracking the current value of the specified - * key in the given map an observable value that tracks the current - * value of the named property for the current value of the master - * observable value - * @since 1.1 - */ - public static IObservableValue observeDetailMapEntry(IObservableMap map, - IObservableValue master, Object valueType) { - return MasterDetailObservables.detailValue(master, - mapEntryValueFactory(map, valueType), valueType); - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/Realm.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/Realm.java deleted file mode 100644 index 27d08ff7..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/Realm.java +++ /dev/null @@ -1,293 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 168153 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable; - -import org.eclipse.core.databinding.Binding; -import org.eclipse.core.databinding.util.Policy; -import org.eclipse.core.internal.databinding.Queue; -import org.eclipse.core.runtime.ISafeRunnable; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.SafeRunner; -import org.eclipse.core.runtime.Status; - -/** - * A realm defines a context from which objects implementing {@link IObservable} - * must be accessed, and on which these objects will notify their listeners. To - * bridge between observables from different realms, subclasses of - * {@link Binding} can be used. - * <p> - * A block of code is said to be executing within a realm if calling - * {@link #isCurrent()} from that block returns true. Code reached by calling - * methods from that block will execute within the same realm, with the - * exception of methods on this class that can be used to execute code within a - * specific realm. Clients can use {@link #syncExec(Runnable)}, - * {@link #asyncExec(Runnable)}, or {@link #exec(Runnable)} to execute a - * runnable within this realm. Note that using {@link #syncExec(Runnable)} can - * lead to deadlocks and should be avoided if the current thread holds any - * locks. - * </p> - * <p> - * It is instructive to think about possible implementations of Realm: It can be - * based on executing on a designated thread such as a UI thread, or based on - * holding a lock. In the former case, calling syncExec on a realm that is not - * the current realm will execute the given runnable on a different thread (the - * designated thread). In the latter case, calling syncExec may execute the - * given runnable on the calling thread, but calling - * {@link #asyncExec(Runnable)} will execute the given runnable on a different - * thread. Therefore, no assumptions can be made about the thread that will - * execute arguments to {@link #asyncExec(Runnable)}, - * {@link #syncExec(Runnable)}, or {@link #exec(Runnable)}. - * </p> - * <p> - * It is possible that a block of code is executing within more than one realm. - * This can happen for implementations of Realm that are based on holding a lock - * but don't use a separate thread to run runnables given to - * {@link #syncExec(Runnable)}. Realm implementations of this kind should be - * appropriately documented because it increases the opportunity for deadlock. - * </p> - * <p> - * Some implementations of {@link IObservable} provide constructors which do not - * take a Realm argument and are specified to create the observable instance - * with the current default realm. The default realm can be set for the - * currently executing thread by using {@link #runWithDefault(Realm, Runnable)}. - * Note that the default realm does not have to be the current realm. - * </p> - * <p> - * Subclasses must override at least one of asyncExec()/syncExec(). For realms - * based on a designated thread, it may be easier to implement asyncExec and - * keep the default implementation of syncExec. For realms based on holding a - * lock, it may be easier to implement syncExec and keep the default - * implementation of asyncExec. - * </p> - * - * @since 1.0 - * - * @see IObservable - */ -public abstract class Realm { - - private static ThreadLocal defaultRealm = new ThreadLocal(); - - /** - * Returns the default realm for the calling thread, or <code>null</code> - * if no default realm has been set. - * - * @return the default realm, or <code>null</code> - */ - public static Realm getDefault() { - return (Realm) defaultRealm.get(); - } - - /** - * Sets the default realm for the calling thread, returning the current - * default thread. This method is inherently unsafe, it is recommended to - * use {@link #runWithDefault(Realm, Runnable)} instead. This method is - * exposed to subclasses to facilitate testing. - * - * @param realm - * the new default realm, or <code>null</code> - * @return the previous default realm, or <code>null</code> - */ - protected static Realm setDefault(Realm realm) { - Realm oldValue = getDefault(); - defaultRealm.set(realm); - return oldValue; - } - - /** - * @return true if the caller is executing in this realm. This method must - * not have side-effects (such as, for example, implicitly placing - * the caller in this realm). - */ - abstract public boolean isCurrent(); - - private Thread workerThread; - - Queue workQueue = new Queue(); - - /** - * Runs the given runnable. If an exception occurs within the runnable, it - * is logged and not re-thrown. If the runnable implements - * {@link ISafeRunnable}, the exception is passed to its - * <code>handleException<code> method. - * - * @param runnable - */ - protected static void safeRun(final Runnable runnable) { - ISafeRunnable safeRunnable; - if (runnable instanceof ISafeRunnable) { - safeRunnable = (ISafeRunnable) runnable; - } else { - safeRunnable = new ISafeRunnable() { - public void handleException(Throwable exception) { - Policy - .getLog() - .log( - new Status( - IStatus.ERROR, - Policy.JFACE_DATABINDING, - IStatus.OK, - "Unhandled exception: " + exception.getMessage(), exception)); //$NON-NLS-1$ - } - public void run() throws Exception { - runnable.run(); - } - }; - } - SafeRunner.run(safeRunnable); - } - - /** - * Causes the <code>run()</code> method of the runnable to be invoked from - * within this realm. If the caller is executing in this realm, the - * runnable's run method is invoked directly, otherwise it is run at the - * next reasonable opportunity using asyncExec. - * <p> - * If the given runnable is an instance of {@link ISafeRunnable}, its - * exception handler method will be called if any exceptions occur while - * running it. Otherwise, the exception will be logged. - * </p> - * - * @param runnable - */ - public void exec(Runnable runnable) { - if (isCurrent()) { - safeRun(runnable); - } else { - asyncExec(runnable); - } - } - - /** - * Causes the <code>run()</code> method of the runnable to be invoked from - * within this realm at the next reasonable opportunity. The caller of this - * method continues to run in parallel, and is not notified when the - * runnable has completed. - * <p> - * If the given runnable is an instance of {@link ISafeRunnable}, its - * exception handler method will be called if any exceptions occur while - * running it. Otherwise, the exception will be logged. - * </p> - * <p> - * Subclasses should use {@link #safeRun(Runnable)} to run the runnable. - * </p> - * - * @param runnable - */ - public void asyncExec(Runnable runnable) { - synchronized (workQueue) { - ensureWorkerThreadIsRunning(); - workQueue.enqueue(runnable); - workQueue.notifyAll(); - } - } - - /** - * - */ - private void ensureWorkerThreadIsRunning() { - if (workerThread == null) { - workerThread = new Thread() { - public void run() { - try { - while (true) { - Runnable work = null; - synchronized (workQueue) { - while (workQueue.isEmpty()) { - workQueue.wait(); - } - work = (Runnable) workQueue.dequeue(); - } - syncExec(work); - } - } catch (InterruptedException e) { - // exit - } - } - }; - workerThread.start(); - } - } - - /** - * Causes the <code>run()</code> method of the runnable to be invoked from - * within this realm at the next reasonable opportunity. This method is - * blocking the caller until the runnable completes. - * <p> - * If the given runnable is an instance of {@link ISafeRunnable}, its - * exception handler method will be called if any exceptions occur while - * running it. Otherwise, the exception will be logged. - * </p> - * <p> - * Subclasses should use {@link #safeRun(Runnable)} to run the runnable. - * </p> - * <p> - * Note: This class is not meant to be called by clients and therefore has - * only protected access. - * </p> - * - * @param runnable - */ - protected void syncExec(Runnable runnable) { - SyncRunnable syncRunnable = new SyncRunnable(runnable); - asyncExec(syncRunnable); - synchronized (syncRunnable) { - while (!syncRunnable.hasRun) { - try { - syncRunnable.wait(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - } - } - } - - static class SyncRunnable implements Runnable { - boolean hasRun = false; - - private Runnable runnable; - - SyncRunnable(Runnable runnable) { - this.runnable = runnable; - } - - public void run() { - try { - safeRun(runnable); - } finally { - synchronized (this) { - hasRun = true; - this.notifyAll(); - } - } - } - } - - /** - * Sets the provided <code>realm</code> as the default for the duration of - * {@link Runnable#run()} and resets the previous realm after completion. - * Note that this will not set the given realm as the current realm. - * - * @param realm - * @param runnable - */ - public static void runWithDefault(Realm realm, Runnable runnable) { - Realm oldRealm = Realm.getDefault(); - try { - defaultRealm.set(realm); - runnable.run(); - } finally { - defaultRealm.set(oldRealm); - } - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/StaleEvent.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/StaleEvent.java deleted file mode 100644 index 14e8c76b..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/StaleEvent.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable; - -/** - * Generic event denoting that the state of an {@link IObservable} object is - * about to change. Note that this event is only fired when an observable - * becomes stale, not when it becomes unstale; an observable that becomes - * unstale should always fire a change event. Staleness can be used (for - * example) to notify listeners when an observable has started a background - * thread for updating its state. Clients can safely ignore staleness. - * - * @see IObservable#isStale() - * - * @since 1.0 - * - */ -public class StaleEvent extends ObservableEvent { - - /** - * Creates a new stale event. - * - * @param source - * the source observable - */ - public StaleEvent(IObservable source) { - super(source); - } - - /** - * - */ - private static final long serialVersionUID = 3491012225431471077L; - - static final Object TYPE = new Object(); - - protected void dispatch(IObservablesListener listener) { - ((IStaleListener) listener).handleStale(this); - } - - protected Object getListenerType() { - return TYPE; - } - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/AbstractObservableList.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/AbstractObservableList.java deleted file mode 100644 index 658ff7f6..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/AbstractObservableList.java +++ /dev/null @@ -1,312 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - * Brad Reynolds - bug 167204 - * Matthew Hall - bug 118516 - * Matthew Hall - bug 208858 - * Matthew Hall - bug 208332 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.list; - -import java.util.AbstractList; -import java.util.Collection; -import java.util.Iterator; - -import org.eclipse.core.databinding.observable.ChangeEvent; -import org.eclipse.core.databinding.observable.ChangeSupport; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.AssertionFailedException; - -/** - * Subclasses should override at least get(int index) and size(). - * - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * - * @since 1.0 - * - */ -public abstract class AbstractObservableList extends AbstractList implements - IObservableList { - - private ChangeSupport changeSupport; - - /** - * @param realm - * - */ - public AbstractObservableList(Realm realm) { - Assert.isNotNull(realm, "Realm cannot be null"); //$NON-NLS-1$ - changeSupport = new ChangeSupport(realm){ - protected void firstListenerAdded() { - AbstractObservableList.this.firstListenerAdded(); - } - protected void lastListenerRemoved() { - AbstractObservableList.this.lastListenerRemoved(); - } - }; - } - - /** - * - */ - public AbstractObservableList() { - this(Realm.getDefault()); - } - - public boolean isStale() { - getterCalled(); - return false; - } - - public synchronized void addListChangeListener(IListChangeListener listener) { - changeSupport.addListener(ListChangeEvent.TYPE, listener); - } - - public synchronized void removeListChangeListener(IListChangeListener listener) { - changeSupport.removeListener(ListChangeEvent.TYPE, listener); - } - - protected void fireListChange(ListDiff diff) { - // fire general change event first - fireChange(); - changeSupport.fireEvent(new ListChangeEvent(this, diff)); - } - - public synchronized void addChangeListener(IChangeListener listener) { - changeSupport.addChangeListener(listener); - } - - public synchronized void removeChangeListener(IChangeListener listener) { - changeSupport.removeChangeListener(listener); - } - - public synchronized void addStaleListener(IStaleListener listener) { - changeSupport.addStaleListener(listener); - } - - public synchronized void removeStaleListener(IStaleListener listener) { - changeSupport.removeStaleListener(listener); - } - - /** - * Fires change event. Must be invoked from the current realm. - */ - protected void fireChange() { - checkRealm(); - changeSupport.fireEvent(new ChangeEvent(this)); - } - - /** - * Fires stale event. Must be invoked from the current realm. - */ - protected void fireStale() { - checkRealm(); - changeSupport.fireEvent(new StaleEvent(this)); - } - - /** - * - */ - protected void firstListenerAdded() { - } - - /** - * - */ - protected void lastListenerRemoved() { - } - - /** - * - */ - public synchronized void dispose() { - changeSupport = null; - lastListenerRemoved(); - } - - public final int size() { - getterCalled(); - return doGetSize(); - } - - /** - * @return the size - */ - protected abstract int doGetSize(); - - /** - * - */ - private void getterCalled() { - ObservableTracker.getterCalled(this); - } - - public boolean isEmpty() { - getterCalled(); - return super.isEmpty(); - } - - public boolean contains(Object o) { - getterCalled(); - return super.contains(o); - } - - public Iterator iterator() { - getterCalled(); - final Iterator wrappedIterator = super.iterator(); - return new Iterator() { - public void remove() { - wrappedIterator.remove(); - } - - public boolean hasNext() { - return wrappedIterator.hasNext(); - } - - public Object next() { - return wrappedIterator.next(); - } - }; - } - - public Object[] toArray() { - getterCalled(); - return super.toArray(); - } - - public Object[] toArray(Object a[]) { - getterCalled(); - return super.toArray(a); - } - - // Modification Operations - - public boolean add(Object o) { - getterCalled(); - return super.add(o); - } - - /** - * Moves the element located at <code>oldIndex</code> to - * <code>newIndex</code>. This method is equivalent to calling - * <code>add(newIndex, remove(oldIndex))</code>. - * <p> - * Subclasses should override this method to deliver list change - * notification for the remove and add operations in the same - * ListChangeEvent, as this allows {@link ListDiff#accept(ListDiffVisitor)} - * to recognize the operation as a move. - * - * @param oldIndex - * the element's position before the move. Must be within the - * range <code>0 <= oldIndex < size()</code>. - * @param newIndex - * the element's position after the move. Must be within the - * range <code>0 <= newIndex < size()</code>. - * @return the element that was moved. - * @throws IndexOutOfBoundsException - * if either argument is out of range (<code>0 <= index < size()</code>). - * @see ListDiffVisitor#handleMove(int, int, Object) - * @see ListDiff#accept(ListDiffVisitor) - * @since 1.1 - */ - public Object move(int oldIndex, int newIndex) { - checkRealm(); - int size = doGetSize(); - if (oldIndex < 0 || oldIndex >= size) - throw new IndexOutOfBoundsException( - "oldIndex: " + oldIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$ - if (newIndex < 0 || newIndex >= size) - throw new IndexOutOfBoundsException( - "newIndex: " + newIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$ - Object element = remove(oldIndex); - add(newIndex, element); - return element; - } - - public boolean remove(Object o) { - getterCalled(); - return super.remove(o); - } - - // Bulk Modification Operations - - public boolean containsAll(Collection c) { - getterCalled(); - return super.containsAll(c); - } - - public boolean addAll(Collection c) { - getterCalled(); - return super.addAll(c); - } - - public boolean addAll(int index, Collection c) { - getterCalled(); - return super.addAll(c); - } - - public boolean removeAll(Collection c) { - getterCalled(); - return super.removeAll(c); - } - - public boolean retainAll(Collection c) { - getterCalled(); - return super.retainAll(c); - } - - // Comparison and hashing - - public boolean equals(Object o) { - getterCalled(); - return super.equals(o); - } - - public int hashCode() { - getterCalled(); - return super.hashCode(); - } - - public int indexOf(Object o) { - getterCalled(); - return super.indexOf(o); - } - - public int lastIndexOf(Object o) { - getterCalled(); - return super.lastIndexOf(o); - } - - public Realm getRealm() { - return changeSupport.getRealm(); - } - - /** - * Asserts that the realm is the current realm. - * - * @see Realm#isCurrent() - * @throws AssertionFailedException - * if the realm is not the current realm - */ - protected void checkRealm() { - Assert.isTrue(getRealm().isCurrent(), - "This operation must be run within the observable's realm"); //$NON-NLS-1$ - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/ComputedList.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/ComputedList.java deleted file mode 100644 index e7f6b2b8..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/ComputedList.java +++ /dev/null @@ -1,290 +0,0 @@ -/************************************************************************************************************ - * Copyright (c) 2007 Matthew Hall 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: - * Matthew Hall - initial API and implementation - * IBM Corporation - initial API and implementation - * Brad Reynolds - initial API and implementation (through bug 116920 and bug 147515) - * Matthew Hall - bug 211786 - ***********************************************************************************************************/ -package org.eclipse.core.databinding.observable.list; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.eclipse.core.databinding.observable.ChangeEvent; -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.StaleEvent; - -/** - * A Lazily calculated list that automatically computes and registers listeners - * on its dependencies as long as all of its dependencies are IObservable - * objects - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * - * @since 1.1 - */ -public abstract class ComputedList extends AbstractObservableList { - private List cachedList = new ArrayList(); - - private boolean dirty = true; - private boolean stale = false; - - private IObservable[] dependencies = new IObservable[0]; - - /** - * Creates a computed list in the default realm and with an unknown (null) - * element type. - */ - public ComputedList() { - this(Realm.getDefault(), null); - } - - /** - * Creates a computed list in the default realm and with the given element - * type. - * - * @param elementType - * the element type, may be <code>null</code> to indicate - * unknown element type - */ - public ComputedList(Object elementType) { - this(Realm.getDefault(), elementType); - } - - /** - * Creates a computed list in given realm and with an unknown (null) element - * type. - * - * @param realm - * the realm - * - */ - public ComputedList(Realm realm) { - this(realm, null); - } - - /** - * Creates a computed list in the given realm and with the given element - * type. - * - * @param realm - * the realm - * @param elementType - * the element type, may be <code>null</code> to indicate - * unknown element type - */ - public ComputedList(Realm realm, Object elementType) { - super(realm); - this.elementType = elementType; - } - - /** - * Inner class that implements interfaces that we don't want to expose as - * public API. Each interface could have been implemented using a separate - * anonymous class, but we combine them here to reduce the memory overhead - * and number of classes. - * - * <p> - * The Runnable calls calculate and stores the result in cachedList. - * </p> - * - * <p> - * The IChangeListener stores each observable in the dependencies list. This - * is registered as the listener when calling ObservableTracker, to detect - * every observable that is used by computeValue. - * </p> - * - * <p> - * The IChangeListener is attached to every dependency. - * </p> - * - */ - private class PrivateInterface implements Runnable, IChangeListener, - IStaleListener { - public void run() { - cachedList = calculate(); - if (cachedList == null) - cachedList = Collections.EMPTY_LIST; - } - - public void handleStale(StaleEvent event) { - if (!dirty) - makeStale(); - } - - public void handleChange(ChangeEvent event) { - makeDirty(); - } - } - - private PrivateInterface privateInterface = new PrivateInterface(); - - private Object elementType; - - protected int doGetSize() { - return doGetList().size(); - } - - public Object get(int index) { - getterCalled(); - return doGetList().get(index); - } - - private final List getList() { - getterCalled(); - return doGetList(); - } - - final List doGetList() { - if (dirty) { - // This line will do the following: - // - Run the calculate method - // - While doing so, add any observable that is touched to the - // dependencies list - IObservable[] newDependencies = ObservableTracker.runAndMonitor( - privateInterface, privateInterface, null); - - // If any dependencies are stale, a stale event will be fired here - // even if we were already stale before recomputing. This is in case - // clients assume that a list change is indicative of non-staleness. - stale = false; - for (int i = 0; i < newDependencies.length; i++) { - if (newDependencies[i].isStale()) { - makeStale(); - break; - } - } - - if (!stale) { - for (int i = 0; i < newDependencies.length; i++) { - newDependencies[i].addStaleListener(privateInterface); - } - } - - dependencies = newDependencies; - - dirty = false; - } - - return cachedList; - } - - private void getterCalled() { - ObservableTracker.getterCalled(this); - } - - /** - * Subclasses must override this method to calculate the list contents. - * - * @return the object's list. - */ - protected abstract List calculate(); - - private void makeDirty() { - if (!dirty) { - dirty = true; - - makeStale(); - - stopListening(); - - // copy the old list - final List oldList = new ArrayList(cachedList); - // Fire the "dirty" event. This implementation recomputes the new - // list lazily. - fireListChange(new ListDiff() { - ListDiffEntry[] differences; - - public ListDiffEntry[] getDifferences() { - if (differences == null) - differences = Diffs.computeListDiff(oldList, getList()) - .getDifferences(); - return differences; - } - }); - } - } - - private void stopListening() { - if (dependencies != null) { - for (int i = 0; i < dependencies.length; i++) { - IObservable observable = dependencies[i]; - - observable.removeChangeListener(privateInterface); - observable.removeStaleListener(privateInterface); - } - dependencies = null; - } - } - - private void makeStale() { - if (!stale) { - stale = true; - fireStale(); - } - } - - public boolean isStale() { - // recalculate list if dirty, to ensure staleness is correct. - getList(); - return stale; - } - - public Object getElementType() { - return elementType; - } - - public synchronized void addChangeListener(IChangeListener listener) { - super.addChangeListener(listener); - // If somebody is listening, we need to make sure we attach our own - // listeners - computeListForListeners(); - } - - public synchronized void addListChangeListener(IListChangeListener listener) { - super.addListChangeListener(listener); - // If somebody is listening, we need to make sure we attach our own - // listeners - computeListForListeners(); - } - - private void computeListForListeners() { - // Some clients just add a listener and expect to get notified even if - // they never called getValue(), so we have to call getValue() ourselves - // here to be sure. Need to be careful about realms though, this method - // can be called outside of our realm. - // See also bug 198211. If a client calls this outside of our realm, - // they may receive change notifications before the runnable below has - // been executed. It is their job to figure out what to do with those - // notifications. - getRealm().exec(new Runnable() { - public void run() { - if (dependencies == null) { - // We are not currently listening. - // But someone is listening for changes. Call getValue() - // to make sure we start listening to the observables we - // depend on. - getList(); - } - } - }); - } - - public synchronized void dispose() { - stopListening(); - super.dispose(); - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/IListChangeListener.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/IListChangeListener.java deleted file mode 100644 index 83727299..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/IListChangeListener.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.list; - -import org.eclipse.core.databinding.observable.IObservablesListener; - -/** - * Listener for changes to observable lists. - * - * @since 1.0 - */ -public interface IListChangeListener extends IObservablesListener { - - /** - * Handle a change to an observable list. The change is described by the - * diff object. The given event object must only be used locally in this - * method because it may be reused for other change notifications. The diff - * object referenced by the event is immutable and may be used non-locally. - * - * @param event - */ - void handleListChange(ListChangeEvent event); - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/IObservableList.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/IObservableList.java deleted file mode 100644 index 097d3678..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/IObservableList.java +++ /dev/null @@ -1,198 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 167204 - * Matthew Hall - bug 208858 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.list; - -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.eclipse.core.databinding.observable.IObservableCollection; - -/** - * A list whose changes can be tracked by list change listeners. - * - * @noextend This interface is not intended to be extended by clients. - * @noimplement This interface is not intended to be implemented by clients. - * Clients should instead subclass one of the framework classes - * that implement this interface. Note that direct implementers of - * this interface outside of the framework will be broken in future - * releases when methods are added to this interface. - * - * @see AbstractObservableList - * @see ObservableList - * - * @since 1.0 - */ -public interface IObservableList extends List, IObservableCollection { - - /** - * Adds the given list change listener to the list of list change listeners. - * @param listener - */ - public void addListChangeListener(IListChangeListener listener); - - /** - * Removes the given list change listener from the list of list change listeners. - * Has no effect if the given listener is not registered as a list change listener. - * - * @param listener - */ - public void removeListChangeListener(IListChangeListener listener); - - /** - * @TrackedGetter - */ - public int size(); - - /** - * @TrackedGetter - */ - public boolean isEmpty(); - - /** - * @TrackedGetter - */ - public boolean contains(Object o); - - /** - * @TrackedGetter - */ - public Iterator iterator(); - - /** - * @TrackedGetter - */ - public Object[] toArray(); - - /** - * @TrackedGetter - */ - public Object[] toArray(Object a[]); - - /** - * - */ - public boolean add(Object o); - - /** - * - */ - public boolean remove(Object o); - - /** - * @TrackedGetter - */ - public boolean containsAll(Collection c); - - /** - * - */ - public boolean addAll(Collection c); - - /** - * - */ - public boolean addAll(int index, Collection c); - - /** - * - */ - public boolean removeAll(Collection c); - - /** - * - */ - public boolean retainAll(Collection c); - - /** - * @TrackedGetter - */ - public boolean equals(Object o); - - /** - * @TrackedGetter - */ - public int hashCode(); - - /** - * @TrackedGetter - */ - public Object get(int index); - - /** - * - */ - public Object set(int index, Object element); - - /** - * Moves the element located at <code>oldIndex</code> to - * <code>newIndex</code>. This method is equivalent to calling - * <code>add(newIndex, remove(oldIndex))</code>. - * <p> - * Implementors should deliver list change notification for the remove and - * add operations in the same ListChangeEvent, as this allows - * {@link ListDiff#accept(ListDiffVisitor)} to recognize the operation as a - * move. - * - * @param oldIndex - * the element's position before the move. Must be within the - * range <code>0 <= oldIndex < size()</code>. - * @param newIndex - * the element's position after the move. Must be within the - * range <code>0 <= newIndex < size()</code>. - * @return the element that was moved. - * @throws IndexOutOfBoundsException - * if either argument is out of range (<code>0 <= index < size()</code>). - * @see ListDiffVisitor#handleMove(int, int, Object) - * @see ListDiff#accept(ListDiffVisitor) - * @since 1.1 - */ - public Object move(int oldIndex, int newIndex); - - /** - * - */ - public Object remove(int index); - - /** - * @TrackedGetter - */ - public int indexOf(Object o); - - /** - * @TrackedGetter - */ - public int lastIndexOf(Object o); - - /** - * @TrackedGetter - */ - public ListIterator listIterator(); - - /** - * @TrackedGetter - */ - public ListIterator listIterator(int index); - - /** - * @TrackedGetter - */ - public List subList(int fromIndex, int toIndex); - - /** - * @return the type of the elements or <code>null</code> if untyped - */ - Object getElementType(); -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/ListChangeEvent.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/ListChangeEvent.java deleted file mode 100644 index 1b2ce4d7..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/ListChangeEvent.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.list; - -import org.eclipse.core.databinding.observable.IObservablesListener; -import org.eclipse.core.databinding.observable.ObservableEvent; - -/** - * List change event describing an incremental change of an - * {@link IObservableList} object. - * - * @since 1.0 - */ -public class ListChangeEvent extends ObservableEvent { - - /** - * - */ - private static final long serialVersionUID = -9154315534258776672L; - - static final Object TYPE = new Object(); - - /** - * Description of the change to the source observable list. Listeners must - * not change this field. - */ - public ListDiff diff; - - /** - * Creates a new list change event. - * - * @param source - * the source observable list - * @param diff - * the list change - */ - public ListChangeEvent(IObservableList source, ListDiff diff) { - super(source); - this.diff = diff; - } - - /** - * Returns the observable list from which this event originated. - * - * @return the observable list from which this event originated - */ - public IObservableList getObservableList() { - return (IObservableList) getSource(); - } - - protected void dispatch(IObservablesListener listener) { - ((IListChangeListener) listener).handleListChange(this); - } - - protected Object getListenerType() { - return TYPE; - } - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/ListDiff.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/ListDiff.java deleted file mode 100644 index df98632d..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/ListDiff.java +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 208858 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.list; - -import org.eclipse.core.internal.databinding.Util; - -/** - * Object describing a diff between two lists. - * - * @since 1.0 - */ -public abstract class ListDiff { - - /** - * Returns a ListDiffEntry array representing the differences in the list, - * in the order they are to be processed. - * - * @return a ListDiffEntry array representing the differences in the list, - * in the order they are to be processed. - */ - public abstract ListDiffEntry[] getDifferences(); - - /** - * Traverses the {@link #getDifferences()} array, calling the appropriate - * method in <code>visitor</code> for each difference. - * <ol> - * <li>{@link ListDiffVisitor#handleReplace(int, Object, Object)} is called - * whenever a remove entry is immediately followed by an add entry which - * shares the same list index. - * <li>{@link ListDiffVisitor#handleMove(int, int, Object)} is called - * whenever a remove entry is immediately followed by an add entry with an - * equivalent element. - * <li>{@link ListDiffVisitor#handleRemove(int, Object)} is called whenever - * a remove entry does not match conditions 1 or 2. - * <li>{@link ListDiffVisitor#handleAdd(int, Object)} is called whenever an - * add entry does not match conditions in 1 or 2. - * </ol> - * - * @param visitor - * the visitor to receive callbacks. - * @see ListDiffVisitor - * @since 1.1 - */ - public void accept(ListDiffVisitor visitor) { - ListDiffEntry[] differences = getDifferences(); - for (int i = 0; i < differences.length; i++) { - ListDiffEntry entry = differences[i]; - int position = entry.getPosition(); - Object element = entry.getElement(); - boolean addition = entry.isAddition(); - - if (!addition && i + 1 < differences.length) { - ListDiffEntry entry2 = differences[i + 1]; - if (entry2.isAddition()) { - int position2 = entry2.getPosition(); - Object element2 = entry2.getElement(); - if (position == position2) { - visitor.handleReplace(position, element, element2); - i++; - continue; - } - if (Util.equals(element, element2)) { - visitor.handleMove(position, position2, element); - i++; - continue; - } - } - } - if (addition) - visitor.handleAdd(position, element); - else - visitor.handleRemove(position, element); - } - } - - /** - * @see java.lang.Object#toString() - */ - public String toString() { - ListDiffEntry[] differences = getDifferences(); - StringBuffer buffer = new StringBuffer(); - buffer.append(getClass().getName()); - - if (differences == null || differences.length == 0) { - buffer - .append("{}"); //$NON-NLS-1$ - } else { - buffer - .append("{"); //$NON-NLS-1$ - - for (int i = 0; i < differences.length; i++) { - if (i > 0) - buffer.append(", "); //$NON-NLS-1$ - - buffer - .append("difference[") //$NON-NLS-1$ - .append(i) - .append("] [") //$NON-NLS-1$ - .append(differences[i] != null ? differences[i].toString() : "null") //$NON-NLS-1$ - .append("]"); //$NON-NLS-1$ - } - buffer.append("}"); //$NON-NLS-1$ - } - - return buffer.toString(); - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/ListDiffEntry.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/ListDiffEntry.java deleted file mode 100644 index da2e79ff..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/ListDiffEntry.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.databinding.observable.list; - -/** - * A single addition of an element to a list or removal of an element from a list. - * - * @since 1.0 - */ -public abstract class ListDiffEntry { - - /** - * @return the 0-based position of the addition or removal - */ - public abstract int getPosition(); - - /** - * @return true if this represents an addition, false if this represents a removal - */ - public abstract boolean isAddition(); - - /** - * @return the element that was added or removed - */ - public abstract Object getElement(); - - /** - * @see java.lang.Object#toString() - */ - public String toString() { - StringBuffer buffer = new StringBuffer(); - buffer - .append(this.getClass().getName()) - .append("{position [") //$NON-NLS-1$ - .append(getPosition()) - .append("], isAddition [") //$NON-NLS-1$ - .append(isAddition()) - .append("], element [") //$NON-NLS-1$ - .append(getElement() != null ? getElement().toString() : "null") //$NON-NLS-1$ - .append("]}"); //$NON-NLS-1$ - - return buffer.toString(); - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/ListDiffVisitor.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/ListDiffVisitor.java deleted file mode 100644 index e2d13891..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/ListDiffVisitor.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 208858) - ******************************************************************************/ - -package org.eclipse.core.databinding.observable.list; - -import java.util.List; - -/** - * A visitor for processing differences in a ListDiff. - * - * @see ListDiff#accept(ListDiffVisitor) - * @since 1.1 - */ -public abstract class ListDiffVisitor { - /** - * Notifies the visitor that <code>element</code> was added to the list at - * position <code>index</code>. - * - * @param index - * the index where the element was added - * @param element - * the element that was added - */ - public abstract void handleAdd(int index, Object element); - - /** - * Notifies the visitor that <code>element</code> was removed from the - * list at position <code>index</code>. - * - * @param index - * the index where the element was removed - * @param element - * the element that was removed - */ - public abstract void handleRemove(int index, Object element); - - /** - * Notifies the visitor that <code>element</code> was moved in the list - * from position <code>oldIndex</code> to position <code>newIndex</code>. - * <p> - * The default implementation of this method calls - * {@link #handleRemove(int, Object)} with the old position, then - * {@link #handleAdd(int, Object)} with the new position. Clients which are - * interested in recognizing "moves" in a list (i.e. calls to - * {@link IObservableList#move(int, int)}) should override this method. - * - * @param oldIndex - * the index that the element was moved from. - * @param newIndex - * the index that the element was moved to. - * @param element - * the element that was moved - * @see IObservableList#move(int, int) - */ - public void handleMove(int oldIndex, int newIndex, Object element) { - handleRemove(oldIndex, element); - handleAdd(newIndex, element); - } - - /** - * Notifies the visitor that <code>oldElement</code>, located at position - * <code>index</code> in the list, was replaced by <code>newElement</code>. - * <p> - * The default implementation of this method calls - * {@link #handleRemove(int, Object)} with the old element, then - * {@link #handleAdd(int, Object)} with the new element. Clients which are - * interested in recognizing "replaces" in a list (i.e. calls to - * {@link List#set(int, Object)}) should override this method. - * - * @param index - * the index where the element was replaced. - * @param oldElement - * the element being replaced. - * @param newElement - * the element that replaced oldElement. - * @see List#set(int, Object) - */ - public void handleReplace(int index, Object oldElement, Object newElement) { - handleRemove(index, oldElement); - handleAdd(index, newElement); - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/ObservableList.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/ObservableList.java deleted file mode 100644 index 7a7eeef3..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/ObservableList.java +++ /dev/null @@ -1,379 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bugs 164653, 167204 - * Matthew Hall - bugs 208858, 208332, 245183 - * Tom Schindl - bug 245183 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.list; - -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.eclipse.core.databinding.observable.AbstractObservable; -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.Realm; - -/** - * - * Abstract implementation of {@link IObservableList}, based on an underlying regular list. - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * @since 1.0 - * - */ -public abstract class ObservableList extends AbstractObservable implements - IObservableList { - - protected List wrappedList; - - /** - * Stale state of the list. Access must occur in the current realm. - */ - private boolean stale = false; - - private Object elementType; - - protected ObservableList(List wrappedList, Object elementType) { - this(Realm.getDefault(), wrappedList, elementType); - } - - protected ObservableList(Realm realm, List wrappedList, Object elementType) { - super(realm); - this.wrappedList = wrappedList; - this.elementType = elementType; - } - - public synchronized void addListChangeListener(IListChangeListener listener) { - addListener(ListChangeEvent.TYPE, listener); - } - - public synchronized void removeListChangeListener(IListChangeListener listener) { - removeListener(ListChangeEvent.TYPE, listener); - } - - protected void fireListChange(ListDiff diff) { - // fire general change event first - super.fireChange(); - fireEvent(new ListChangeEvent(this, diff)); - } - - public boolean contains(Object o) { - getterCalled(); - return wrappedList.contains(o); - } - - public boolean containsAll(Collection c) { - getterCalled(); - return wrappedList.containsAll(c); - } - - public boolean equals(Object o) { - getterCalled(); - - if (o == this) - return true; - if (o == null) - return false; - if (getClass() == o.getClass()) { - return wrappedList.equals(((ObservableList) o).wrappedList); - } - - return wrappedList.equals(o); - } - - public int hashCode() { - getterCalled(); - return wrappedList.hashCode(); - } - - public boolean isEmpty() { - getterCalled(); - return wrappedList.isEmpty(); - } - - public Iterator iterator() { - getterCalled(); - final Iterator wrappedIterator = wrappedList.iterator(); - return new Iterator() { - - public void remove() { - throw new UnsupportedOperationException(); - } - - public boolean hasNext() { - return wrappedIterator.hasNext(); - } - - public Object next() { - return wrappedIterator.next(); - } - }; - } - - public int size() { - getterCalled(); - return wrappedList.size(); - } - - public Object[] toArray() { - getterCalled(); - return wrappedList.toArray(); - } - - public Object[] toArray(Object[] a) { - getterCalled(); - return wrappedList.toArray(a); - } - - public String toString() { - getterCalled(); - return wrappedList.toString(); - } - - /** - * @TrackedGetter - */ - public Object get(int index) { - getterCalled(); - return wrappedList.get(index); - } - - /** - * @TrackedGetter - */ - public int indexOf(Object o) { - getterCalled(); - return wrappedList.indexOf(o); - } - - /** - * @TrackedGetter - */ - public int lastIndexOf(Object o) { - getterCalled(); - return wrappedList.lastIndexOf(o); - } - - // List Iterators - - /** - * @TrackedGetter - */ - public ListIterator listIterator() { - return listIterator(0); - } - - /** - * @TrackedGetter - */ - public ListIterator listIterator(int index) { - getterCalled(); - final ListIterator wrappedIterator = wrappedList.listIterator(index); - return new ListIterator() { - - public int nextIndex() { - return wrappedIterator.nextIndex(); - } - - public int previousIndex() { - return wrappedIterator.previousIndex(); - } - - public void remove() { - throw new UnsupportedOperationException(); - } - - public boolean hasNext() { - return wrappedIterator.hasNext(); - } - - public boolean hasPrevious() { - return wrappedIterator.hasPrevious(); - } - - public Object next() { - return wrappedIterator.next(); - } - - public Object previous() { - return wrappedIterator.previous(); - } - - public void add(Object o) { - throw new UnsupportedOperationException(); - } - - public void set(Object o) { - throw new UnsupportedOperationException(); - } - }; - } - - - public List subList(final int fromIndex, final int toIndex) { - getterCalled(); - if (fromIndex < 0 || fromIndex > toIndex || toIndex > size()) { - throw new IndexOutOfBoundsException(); - } - return new AbstractObservableList(getRealm()) { - - public Object getElementType() { - return ObservableList.this.getElementType(); - } - - public Object get(int location) { - return ObservableList.this.get(fromIndex + location); - } - - protected int doGetSize() { - return toIndex - fromIndex; - } - }; - } - - protected void getterCalled() { - ObservableTracker.getterCalled(this); - } - - public Object set(int index, Object element) { - throw new UnsupportedOperationException(); - } - - /** - * Moves the element located at <code>oldIndex</code> to - * <code>newIndex</code>. This method is equivalent to calling - * <code>add(newIndex, remove(oldIndex))</code>. - * <p> - * Subclasses should override this method to deliver list change - * notification for the remove and add operations in the same - * ListChangeEvent, as this allows {@link ListDiff#accept(ListDiffVisitor)} - * to recognize the operation as a move. - * - * @param oldIndex - * the element's position before the move. Must be within the - * range <code>0 <= oldIndex < size()</code>. - * @param newIndex - * the element's position after the move. Must be within the - * range <code>0 <= newIndex < size()</code>. - * @return the element that was moved. - * @throws IndexOutOfBoundsException - * if either argument is out of range (<code>0 <= index < size()</code>). - * @see ListDiffVisitor#handleMove(int, int, Object) - * @see ListDiff#accept(ListDiffVisitor) - * @since 1.1 - */ - public Object move(int oldIndex, int newIndex) { - checkRealm(); - int size = wrappedList.size(); - if (oldIndex < 0 || oldIndex >= size) - throw new IndexOutOfBoundsException( - "oldIndex: " + oldIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$ - if (newIndex < 0 || newIndex >= size) - throw new IndexOutOfBoundsException( - "newIndex: " + newIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$ - Object element = remove(oldIndex); - add(newIndex, element); - return element; - } - - public Object remove(int index) { - throw new UnsupportedOperationException(); - } - - public boolean add(Object o) { - throw new UnsupportedOperationException(); - } - - public void add(int index, Object element) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(int index, Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - throw new UnsupportedOperationException(); - } - - /** - * Returns the stale state. Must be invoked from the current realm. - * - * @return stale state - */ - public boolean isStale() { - getterCalled(); - return stale; - } - - /** - * Sets the stale state. Must be invoked from the current realm. - * - * @param stale - * The stale state to list. This will fire a stale event if the - * given boolean is true and this observable list was not already - * stale. - */ - public void setStale(boolean stale) { - checkRealm(); - - boolean wasStale = this.stale; - this.stale = stale; - if (!wasStale && stale) { - fireStale(); - } - } - - protected void fireChange() { - throw new RuntimeException("fireChange should not be called, use fireListChange() instead"); //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.jface.provisional.databinding.observable.AbstractObservable#dispose() - */ - public synchronized void dispose() { - super.dispose(); - } - - public Object getElementType() { - return elementType; - } - - protected void updateWrappedList(List newList) { - List oldList = wrappedList; - ListDiff listDiff = Diffs.computeListDiff(oldList, newList); - wrappedList = newList; - fireListChange(listDiff); - } - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/WritableList.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/WritableList.java deleted file mode 100644 index ca0c7503..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/WritableList.java +++ /dev/null @@ -1,239 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - * Brad Reynolds - bug 167204 - * Gautam Saggar - bug 169529 - * Brad Reynolds - bug 147515 - * Matthew Hall - bug 208858, 213145 - *******************************************************************************/ -package org.eclipse.core.databinding.observable.list; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; - -/** - * Mutable observable list backed by an ArrayList. - * - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * - * @since 1.0 - */ -public class WritableList extends ObservableList { - - /** - * Creates an empty writable list in the default realm with a - * <code>null</code> element type. - * - */ - public WritableList() { - this(Realm.getDefault()); - } - - /** - * Creates an empty writable list with a <code>null</code> element type. - * - * @param realm - */ - public WritableList(Realm realm) { - this(realm, new ArrayList(), null); - } - - /** - * Constructs a new instance with the default realm. - * - * @param toWrap - * @param elementType - * can be <code>null</code> - */ - public WritableList(List toWrap, Object elementType) { - this(Realm.getDefault(), toWrap, elementType); - } - - /** - * Creates a writable list containing elements of the given type, wrapping - * an existing client-supplied list. - * - * @param realm - * @param toWrap - * The java.utilList to wrap - * @param elementType - * can be <code>null</code> - */ - public WritableList(Realm realm, List toWrap, Object elementType) { - super(realm, toWrap, elementType); - } - - public Object set(int index, Object element) { - checkRealm(); - Object oldElement = wrappedList.set(index, element); - fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry(index, - false, oldElement), Diffs.createListDiffEntry(index, true, - element))); - return oldElement; - } - - /** - * @since 1.1 - */ - public Object move(int oldIndex, int newIndex) { - checkRealm(); - int size = wrappedList.size(); - if (oldIndex < 0 || oldIndex >= size) - throw new IndexOutOfBoundsException( - "oldIndex: " + oldIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$ - if (newIndex < 0 || newIndex >= size) - throw new IndexOutOfBoundsException( - "newIndex: " + newIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$ - if (oldIndex == newIndex) - return wrappedList.get(oldIndex); - Object element = wrappedList.remove(oldIndex); - wrappedList.add(newIndex, element); - fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry(oldIndex, - false, element), Diffs.createListDiffEntry(newIndex, true, - element))); - return element; - } - - public Object remove(int index) { - checkRealm(); - Object oldElement = wrappedList.remove(index); - fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry(index, - false, oldElement))); - return oldElement; - } - - public boolean add(Object element) { - checkRealm(); - boolean added = wrappedList.add(element); - if (added) { - fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry( - wrappedList.size() - 1, true, element))); - } - return added; - } - - public void add(int index, Object element) { - checkRealm(); - wrappedList.add(index, element); - fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry(index, - true, element))); - } - - public boolean addAll(Collection c) { - checkRealm(); - ListDiffEntry[] entries = new ListDiffEntry[c.size()]; - int i = 0; - int addIndex = wrappedList.size(); - for (Iterator it = c.iterator(); it.hasNext();) { - Object element = it.next(); - entries[i++] = Diffs.createListDiffEntry(addIndex++, true, element); - } - boolean added = wrappedList.addAll(c); - fireListChange(Diffs.createListDiff(entries)); - return added; - } - - public boolean addAll(int index, Collection c) { - checkRealm(); - ListDiffEntry[] entries = new ListDiffEntry[c.size()]; - int i = 0; - int addIndex = index; - for (Iterator it = c.iterator(); it.hasNext();) { - Object element = it.next(); - entries[i++] = Diffs.createListDiffEntry(addIndex++, true, element); - } - boolean added = wrappedList.addAll(index, c); - fireListChange(Diffs.createListDiff(entries)); - return added; - } - - public boolean remove(Object o) { - checkRealm(); - int index = wrappedList.indexOf(o); - if (index == -1) { - return false; - } - wrappedList.remove(index); - fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry(index, - false, o))); - return true; - } - - public boolean removeAll(Collection c) { - checkRealm(); - List entries = new ArrayList(); - for (Iterator it = c.iterator(); it.hasNext();) { - Object element = it.next(); - int removeIndex = wrappedList.indexOf(element); - if (removeIndex != -1) { - wrappedList.remove(removeIndex); - entries.add(Diffs.createListDiffEntry(removeIndex, false, - element)); - } - } - if (entries.size() > 0) - fireListChange(Diffs.createListDiff((ListDiffEntry[]) entries - .toArray(new ListDiffEntry[entries.size()]))); - return entries.size() > 0; - } - - public boolean retainAll(Collection c) { - checkRealm(); - List entries = new ArrayList(); - int removeIndex = 0; - for (Iterator it = wrappedList.iterator(); it.hasNext();) { - Object element = it.next(); - if (!c.contains(element)) { - entries.add(Diffs.createListDiffEntry(removeIndex, false, - element)); - it.remove(); - } else { - // only increment if we haven't removed the current element - removeIndex++; - } - } - if (entries.size() > 0) - fireListChange(Diffs.createListDiff((ListDiffEntry[]) entries - .toArray(new ListDiffEntry[entries.size()]))); - return entries.size() > 0; - } - - public void clear() { - checkRealm(); - List entries = new ArrayList(); - for (Iterator it = wrappedList.iterator(); it.hasNext();) { - Object element = it.next(); - // always report 0 as the remove index - entries.add(Diffs.createListDiffEntry(0, false, element)); - it.remove(); - } - fireListChange(Diffs.createListDiff((ListDiffEntry[]) entries - .toArray(new ListDiffEntry[entries.size()]))); - } - - /** - * @param elementType - * can be <code>null</code> - * @return new list with the default realm. - */ - public static WritableList withElementType(Object elementType) { - return new WritableList(Realm.getDefault(), new ArrayList(), - elementType); - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/package.html b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/package.html deleted file mode 100644 index 2c2f1db6..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/package.html +++ /dev/null @@ -1,16 +0,0 @@ -<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> - <meta name="Author" content="IBM"> - <meta name="GENERATOR" content="Mozilla/4.5 [en] (Win98; I) [Netscape]"> - <title>Package-level Javadoc</title> -</head> -<body> -Provides classes for observing changes in lists. -<h2> -Package Specification</h2> -<p> -This package provides classes for observing changes in lists.</p> -</body> -</html> diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/AbstractObservableMap.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/AbstractObservableMap.java deleted file mode 100644 index e35f655f..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/AbstractObservableMap.java +++ /dev/null @@ -1,181 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - * Matthew Hall - bugs 118516, 240931 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.map; - -import java.util.AbstractMap; - -import org.eclipse.core.databinding.observable.ChangeEvent; -import org.eclipse.core.databinding.observable.ChangeSupport; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.AssertionFailedException; - -/** - * - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * @since 1.0 - */ -public abstract class AbstractObservableMap extends AbstractMap implements - IObservableMap { - - private ChangeSupport changeSupport; - - private boolean stale; - - /** - */ - public AbstractObservableMap() { - this(Realm.getDefault()); - } - - /** - * - */ - protected void lastListenerRemoved() { - } - - /** - * - */ - protected void firstListenerAdded() { - } - - /** - * @param realm - */ - public AbstractObservableMap(Realm realm) { - Assert.isNotNull(realm, "Realm cannot be null"); //$NON-NLS-1$ - changeSupport = new ChangeSupport(realm){ - protected void firstListenerAdded() { - AbstractObservableMap.this.firstListenerAdded(); - } - protected void lastListenerRemoved() { - AbstractObservableMap.this.lastListenerRemoved(); - } - }; - } - - public synchronized void addMapChangeListener(IMapChangeListener listener) { - if (changeSupport != null) { - changeSupport.addListener(MapChangeEvent.TYPE, listener); - } - } - - public synchronized void removeMapChangeListener(IMapChangeListener listener) { - if (changeSupport != null) { - changeSupport.removeListener(MapChangeEvent.TYPE, listener); - } - } - - public synchronized void addChangeListener(IChangeListener listener) { - if (changeSupport != null) { - changeSupport.addChangeListener(listener); - } - } - - public synchronized void addStaleListener(IStaleListener listener) { - if (changeSupport != null) { - changeSupport.addStaleListener(listener); - } - } - - public synchronized void dispose() { - if (changeSupport != null) { - changeSupport.dispose(); - changeSupport = null; - } - } - - public Realm getRealm() { - if (changeSupport != null) { - return changeSupport.getRealm(); - } - return null; - } - - public boolean isStale() { - checkRealm(); - return stale; - } - - public synchronized void removeChangeListener(IChangeListener listener) { - if (changeSupport != null) { - changeSupport.removeChangeListener(listener); - } - } - - public synchronized void removeStaleListener(IStaleListener listener) { - if (changeSupport != null) { - changeSupport.removeStaleListener(listener); - } - } - - /** - * Sets the stale state. Must be invoked from the current realm. - * - * @param stale - */ - public void setStale(boolean stale) { - checkRealm(); - this.stale = stale; - if (stale) { - fireStale(); - } - } - - /** - * Fires stale events. Must be invoked from current realm. - */ - protected void fireStale() { - checkRealm(); - changeSupport.fireEvent(new StaleEvent(this)); - } - - /** - * Fires change events. Must be invoked from current realm. - */ - protected void fireChange() { - checkRealm(); - changeSupport.fireEvent(new ChangeEvent(this)); - } - - /** - * Fires map change events. Must be invoked from current realm. - * - * @param diff - */ - protected void fireMapChange(MapDiff diff) { - checkRealm(); - changeSupport.fireEvent(new MapChangeEvent(this, diff)); - } - - /** - * Asserts that the realm is the current realm. - * - * @see Realm#isCurrent() - * @throws AssertionFailedException - * if the realm is not the current realm - */ - protected void checkRealm() { - Assert.isTrue(getRealm().isCurrent(), - "This operation must be run within the observable's realm"); //$NON-NLS-1$ - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/BidirectionalMap.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/BidirectionalMap.java deleted file mode 100644 index c83f6eef..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/BidirectionalMap.java +++ /dev/null @@ -1,104 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.core.databinding.observable.map; - -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.databinding.observable.Realm; - -/** - * - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * @since 1.0 - * - */ -public class BidirectionalMap extends ObservableMap { - - private Map valueToElements = new HashMap(); - - private IMapChangeListener mapListener = new IMapChangeListener() { - - public void handleMapChange(MapChangeEvent event) { - MapDiff diff = event.diff; - for (Iterator it = diff.getAddedKeys().iterator(); it.hasNext();) { - Object addedKey = it.next(); - addMapping(addedKey, diff.getNewValue(addedKey)); - } - for (Iterator it = diff.getChangedKeys().iterator(); it.hasNext();) { - Object changedKey = it.next(); - removeMapping(changedKey, diff.getOldValue(changedKey)); - addMapping(changedKey, diff.getNewValue(changedKey)); - } - for (Iterator it = diff.getRemovedKeys().iterator(); it.hasNext();) { - Object removedKey = it.next(); - removeMapping(removedKey, diff.getOldValue(removedKey)); - } - fireMapChange(diff); - } - }; - - /** - * @param wrappedMap - */ - public BidirectionalMap(IObservableMap wrappedMap) { - super(wrappedMap.getRealm(), wrappedMap); - wrappedMap.addMapChangeListener(mapListener); - for (Iterator it = wrappedMap.entrySet().iterator(); it.hasNext();) { - Map.Entry entry = (Entry) it.next(); - addMapping(entry.getKey(), entry.getValue()); - } - } - - /** - * @param key - * @param value - */ - private void addMapping(Object key, Object value) { - Object elementOrSet = valueToElements.get(value); - if (elementOrSet == null) { - valueToElements.put(value, key); - return; - } - if (!(elementOrSet instanceof Set)) { - elementOrSet = new HashSet(Collections.singleton(elementOrSet)); - valueToElements.put(value, elementOrSet); - } - Set set = (Set) elementOrSet; - set.add(key); - } - - /** - * @param functionValue - * @param element - */ - private void removeMapping(Object functionValue, Object element) { - Object elementOrSet = valueToElements.get(functionValue); - if (elementOrSet instanceof Set) { - Set set = (Set) elementOrSet; - set.remove(element); - if (set.size() == 0) { - valueToElements.remove(functionValue); - } - } else { - valueToElements.remove(functionValue); - } - } - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/CompositeMap.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/CompositeMap.java deleted file mode 100644 index 8f3bbb61..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/CompositeMap.java +++ /dev/null @@ -1,361 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.core.databinding.observable.map; - -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.set.WritableSet; -import org.eclipse.core.runtime.Assert; - -/** - * A read-only observable map formed by the composition of two observable maps. - * If map1 maps keys a:A to values b1:B, and map2 maps keys b2:B to values c:C, - * the composite map maps keys a:A to values c:C. For example, map1 could map - * Order objects to their corresponding Customer objects, and map2 could map - * Customer objects to their "last name" property of type String. The composite - * map of map1 and map2 would then map Order objects to their customers' last - * names. - * - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * - * @since 1.1 - * - */ -public class CompositeMap extends ObservableMap { - - private Map valueToElements = new HashMap(); - - // adds that need to go through the second map and thus will be picked up by - // secondMapListener. - private Set pendingAdds = new HashSet(); - - // Removes that need to go through the second map and thus will be picked up - // by - // secondMapListener. Maps from value being removed to key being removed. - private Map pendingRemoves = new HashMap(); - - // Changes that need to go through the second map and thus will be picked up - // by - // secondMapListener. Maps from old value to new value and new value to old - // value. - private Map pendingChanges = new HashMap(); - - private IMapChangeListener firstMapListener = new IMapChangeListener() { - - public void handleMapChange(MapChangeEvent event) { - MapDiff diff = event.diff; - Set rangeSetAdditions = new HashSet(); - Set rangeSetRemovals = new HashSet(); - final Set adds = new HashSet(); - final Set changes = new HashSet(); - final Set removes = new HashSet(); - final Map oldValues = new HashMap(); - - for (Iterator it = diff.getAddedKeys().iterator(); it.hasNext();) { - Object addedKey = it.next(); - Object newValue = diff.getNewValue(addedKey); - addMapping(addedKey, newValue); - if (!rangeSet.contains(newValue)) { - pendingAdds.add(newValue); - rangeSetAdditions.add(newValue); - } else { - adds.add(addedKey); - wrappedMap.put(addedKey, secondMap.get(newValue)); - } - } - for (Iterator it = diff.getChangedKeys().iterator(); it.hasNext();) { - Object changedKey = it.next(); - Object oldValue = diff.getOldValue(changedKey); - Object newValue = diff.getNewValue(changedKey); - boolean removed = removeMapping(changedKey, oldValue); - addMapping(changedKey, newValue); - boolean added = !rangeSet.contains(newValue); - if (removed) { - pendingRemoves.put(oldValue, changedKey); - rangeSetRemovals.add(oldValue); - } - if (added) { - pendingAdds.add(newValue); - rangeSetAdditions.add(newValue); - } - if (added || removed) { - pendingChanges.put(oldValue, newValue); - pendingChanges.put(newValue, oldValue); - } else { - changes.add(changedKey); - oldValues.put(changedKey, oldValue); - wrappedMap.put(changedKey, secondMap.get(newValue)); - } - } - for (Iterator it = diff.getRemovedKeys().iterator(); it.hasNext();) { - Object removedKey = it.next(); - Object oldValue = diff.getOldValue(removedKey); - if (removeMapping(removedKey, oldValue)) { - pendingRemoves.put(oldValue, removedKey); - rangeSetRemovals.add(oldValue); - } else { - removes.add(removedKey); - oldValues.put(removedKey, secondMap.get(oldValue)); - wrappedMap.remove(removedKey); - } - } - - if (adds.size() > 0 || removes.size() > 0 || changes.size() > 0) { - fireMapChange(new MapDiff() { - - public Set getAddedKeys() { - return adds; - } - - public Set getChangedKeys() { - return changes; - } - - public Object getNewValue(Object key) { - return wrappedMap.get(key); - } - - public Object getOldValue(Object key) { - return oldValues.get(key); - } - - public Set getRemovedKeys() { - return removes; - } - }); - } - - if (rangeSetAdditions.size() > 0 || rangeSetRemovals.size() > 0) { - rangeSet.addAndRemove(rangeSetAdditions, rangeSetRemovals); - } - } - }; - - private IMapChangeListener secondMapListener = new IMapChangeListener() { - - public void handleMapChange(MapChangeEvent event) { - MapDiff diff = event.diff; - final Set adds = new HashSet(); - final Set changes = new HashSet(); - final Set removes = new HashSet(); - final Map oldValues = new HashMap(); - final Map newValues = new HashMap(); - Set addedKeys = new HashSet(diff.getAddedKeys()); - Set removedKeys = new HashSet(diff.getRemovedKeys()); - - for (Iterator it = addedKeys.iterator(); it.hasNext();) { - Object addedKey = it.next(); - Set elements = getElementsForValue(addedKey); - Object newValue = diff.getNewValue(addedKey); - if (pendingChanges.containsKey(addedKey)) { - Object oldKey = pendingChanges.remove(addedKey); - Object oldValue; - if (removedKeys.remove(oldKey)) { - oldValue = diff.getOldValue(oldKey); - } else { - oldValue = secondMap.get(oldKey); - } - pendingChanges.remove(oldKey); - pendingAdds.remove(addedKey); - pendingRemoves.remove(oldKey); - for (Iterator it2 = elements.iterator(); it2.hasNext();) { - Object element = it2.next(); - changes.add(element); - oldValues.put(element, oldValue); - newValues.put(element, newValue); - wrappedMap.put(element, newValue); - } - } else if (pendingAdds.remove(addedKey)) { - for (Iterator it2 = elements.iterator(); it2.hasNext();) { - Object element = it2.next(); - adds.add(element); - newValues.put(element, newValue); - wrappedMap.put(element, newValue); - } - } else { - Assert.isTrue(false, "unexpected case"); //$NON-NLS-1$ - } - } - for (Iterator it = diff.getChangedKeys().iterator(); it.hasNext();) { - Object changedKey = it.next(); - Set elements = getElementsForValue(changedKey); - for (Iterator it2 = elements.iterator(); it2.hasNext();) { - Object element = it2.next(); - changes.add(element); - oldValues.put(element, diff.getOldValue(changedKey)); - Object newValue = diff.getNewValue(changedKey); - newValues.put(element, newValue); - wrappedMap.put(element, newValue); - } - } - for (Iterator it = removedKeys.iterator(); it.hasNext();) { - Object removedKey = it.next(); - Object element = pendingRemoves.remove(removedKey); - if (element != null) { - if (pendingChanges.containsKey(removedKey)) { - Object newKey = pendingChanges.remove(removedKey); - pendingChanges.remove(newKey); - pendingAdds.remove(newKey); - pendingRemoves.remove(removedKey); - changes.add(element); - oldValues.put(element, diff.getOldValue(removedKey)); - Object newValue = secondMap.get(newKey); - newValues.put(element, newValue); - wrappedMap.put(element, newValue); - } else { - removes.add(element); - Object oldValue = diff.getOldValue(removedKey); - oldValues.put(element, oldValue); - wrappedMap.remove(element); - } - } else { - Assert.isTrue(false, "unexpected case"); //$NON-NLS-1$ - } - } - - if (adds.size() > 0 || removes.size() > 0 || changes.size() > 0) { - fireMapChange(new MapDiff() { - - public Set getAddedKeys() { - return adds; - } - - public Set getChangedKeys() { - return changes; - } - - public Object getNewValue(Object key) { - return newValues.get(key); - } - - public Object getOldValue(Object key) { - return oldValues.get(key); - } - - public Set getRemovedKeys() { - return removes; - } - }); - } - } - }; - - private IObservableMap firstMap; - private IObservableMap secondMap; - - private static class WritableSetPlus extends WritableSet { - void addAndRemove(Set additions, Set removals) { - wrappedSet.removeAll(removals); - wrappedSet.addAll(additions); - fireSetChange(Diffs.createSetDiff(additions, removals)); - } - } - - private WritableSetPlus rangeSet = new WritableSetPlus(); - - /** - * Creates a new composite map. Because the key set of the second map is - * determined by the value set of the given observable map - * <code>firstMap</code>, it cannot be passed in as an argument. Instead, - * the second map will be created by calling - * <code>secondMapFactory.createObservable(valueSet())</code>. - * - * @param firstMap - * the first map - * @param secondMapFactory - * a factory that creates the second map when given an observable - * set representing the value set of <code>firstMap</code>. - */ - public CompositeMap(IObservableMap firstMap, - IObservableFactory secondMapFactory) { - super(firstMap.getRealm(), new HashMap()); - this.firstMap = firstMap; - firstMap.addMapChangeListener(firstMapListener); - for (Iterator it = firstMap.entrySet().iterator(); it.hasNext();) { - Map.Entry entry = (Entry) it.next(); - addMapping(entry.getKey(), entry.getValue()); - rangeSet.add(entry.getValue()); - } - this.secondMap = (IObservableMap) secondMapFactory - .createObservable(rangeSet); - secondMap.addMapChangeListener(secondMapListener); - for (Iterator it = firstMap.entrySet().iterator(); it.hasNext();) { - Map.Entry entry = (Entry) it.next(); - wrappedMap.put(entry.getKey(), secondMap.get(entry.getValue())); - } - } - - /** - * @param key - * @param value - */ - private void addMapping(Object key, Object value) { - Object elementOrSet = valueToElements.get(value); - if (elementOrSet == null) { - valueToElements.put(value, key); - return; - } - if (!(elementOrSet instanceof Set)) { - elementOrSet = new HashSet(Collections.singleton(elementOrSet)); - valueToElements.put(value, elementOrSet); - } - Set set = (Set) elementOrSet; - set.add(key); - } - - /** - * @param key - * @param value - */ - private boolean removeMapping(Object key, Object value) { - Object elementOrSet = valueToElements.get(value); - if (elementOrSet instanceof Set) { - Set set = (Set) elementOrSet; - set.remove(key); - if (set.size() == 0) { - valueToElements.remove(value); - return true; - } - return false; - } - valueToElements.remove(value); - return true; - } - - private Set getElementsForValue(Object value) { - Object elementOrSet = valueToElements.get(value); - if (elementOrSet instanceof Set) { - return (Set) elementOrSet; - } - return elementOrSet == null ? Collections.EMPTY_SET : Collections - .singleton(elementOrSet); - } - - public synchronized void dispose() { - super.dispose(); - firstMap.removeMapChangeListener(firstMapListener); - firstMap = null; - secondMap = null; - } - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/ComputedObservableMap.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/ComputedObservableMap.java deleted file mode 100644 index f7438926..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/ComputedObservableMap.java +++ /dev/null @@ -1,161 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.map; - -import java.util.AbstractSet; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.ISetChangeListener; -import org.eclipse.core.databinding.observable.set.SetChangeEvent; - -/** - * Maps objects to one of their attributes. Tracks changes to the underlying - * observable set of objects (keys), as well as changes to attribute values. - */ -public abstract class ComputedObservableMap extends AbstractObservableMap { - - private final IObservableSet keySet; - - private ISetChangeListener setChangeListener = new ISetChangeListener() { - public void handleSetChange(SetChangeEvent event) { - Set addedKeys = new HashSet(event.diff.getAdditions()); - Set removedKeys = new HashSet(event.diff.getRemovals()); - Map oldValues = new HashMap(); - Map newValues = new HashMap(); - for (Iterator it = removedKeys.iterator(); it.hasNext();) { - Object removedKey = it.next(); - Object oldValue = doGet(removedKey); - unhookListener(removedKey); - if (oldValue != null) { - oldValues.put(removedKey, oldValue); - } - } - for (Iterator it = addedKeys.iterator(); it.hasNext();) { - Object addedKey = it.next(); - hookListener(addedKey); - Object newValue = doGet(addedKey); - newValues.put(addedKey, newValue); - } - fireMapChange(Diffs.createMapDiff(addedKeys, removedKeys, - Collections.EMPTY_SET, oldValues, newValues)); - } - }; - - private Set entrySet = new EntrySet(); - - private class EntrySet extends AbstractSet { - - public Iterator iterator() { - final Iterator keyIterator = keySet.iterator(); - return new Iterator() { - - public boolean hasNext() { - return keyIterator.hasNext(); - } - - public Object next() { - final Object key = keyIterator.next(); - return new Map.Entry() { - - public Object getKey() { - return key; - } - - public Object getValue() { - return get(getKey()); - } - - public Object setValue(Object value) { - return put(getKey(), value); - } - }; - } - - public void remove() { - keyIterator.remove(); - } - }; - } - - public int size() { - return keySet.size(); - } - - } - - /** - * @param keySet - */ - public ComputedObservableMap(IObservableSet keySet) { - super(keySet.getRealm()); - this.keySet = keySet; - this.keySet.addSetChangeListener(setChangeListener); - } - - protected void init() { - for (Iterator it = this.keySet.iterator(); it.hasNext();) { - Object key = it.next(); - hookListener(key); - } - } - - protected final void fireSingleChange(Object key, Object oldValue, - Object newValue) { - fireMapChange(Diffs.createMapDiffSingleChange(key, oldValue, newValue)); - } - - public Set entrySet() { - return entrySet; - } - - public Set keySet() { - return keySet; - } - - final public Object get(Object key) { - return doGet(key); - } - - final public Object put(Object key, Object value) { - return doPut(key, value); - } - - /** - * @param removedKey - */ - protected abstract void unhookListener(Object removedKey); - - /** - * @param addedKey - */ - protected abstract void hookListener(Object addedKey); - - /** - * @param key - * @return the value for the given key - */ - protected abstract Object doGet(Object key); - - /** - * @param key - * @param value - * @return the old value for the given key - */ - protected abstract Object doPut(Object key, Object value); -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/IMapChangeListener.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/IMapChangeListener.java deleted file mode 100644 index 3bc829e9..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/IMapChangeListener.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.map; - -import org.eclipse.core.databinding.observable.IObservablesListener; - -/** - * Listener for changes to observable maps. - * - * @since 1.0 - * - */ -public interface IMapChangeListener extends IObservablesListener { - - /** - * Handle a change an observable map. The given event object must only be - * used locally in this method because it may be reused for other change - * notifications. The diff object referenced by the event is immutable and - * may be used non-locally. - * - * @param event - * the event - */ - void handleMapChange(MapChangeEvent event); - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/IObservableMap.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/IObservableMap.java deleted file mode 100644 index 78a0db0f..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/IObservableMap.java +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.map; - -import java.util.Collection; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.databinding.observable.IObservable; - -/** - * Observable Map. - * - * @noextend This interface is not intended to be extended by clients. - * @noimplement This interface is not intended to be implemented by clients. - * Clients should instead subclass one of the classes that - * implement this interface. Note that direct implementers of this - * interface outside of the framework will be broken in future - * releases when methods are added to this interface. - * - * @see AbstractObservableMap - * @see ObservableMap - * - * @since 1.1 - */ -public interface IObservableMap extends Map, IObservable { - - /** - * @param listener - */ - public void addMapChangeListener(IMapChangeListener listener); - - /** - * @param listener - */ - public void removeMapChangeListener(IMapChangeListener listener); - - /** - * @TrackedGetter - */ - public int size(); - - /** - * @TrackedGetter - */ - public boolean isEmpty(); - - /** - * @TrackedGetter - */ - public boolean containsKey(Object key); - - /** - * @TrackedGetter - */ - public boolean containsValue(Object value); - - /** - * @TrackedGetter - */ - public Object get(Object key); - - /** - * - */ - public Object put(Object key, Object value); - - /** - * - */ - public Object remove(Object key); - - /** - * @TrackedGetter - */ - public Set keySet(); - - /** - * @TrackedGetter - */ - public Collection values(); - - /** - * @TrackedGetter - */ - public Set entrySet(); - - /** - * @TrackedGetter - */ - public boolean equals(Object o); - - /** - * @TrackedGetter - */ - public int hashCode(); -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/MapChangeEvent.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/MapChangeEvent.java deleted file mode 100644 index 90bfef93..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/MapChangeEvent.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.databinding.observable.map; - -import org.eclipse.core.databinding.observable.IObservablesListener; -import org.eclipse.core.databinding.observable.ObservableEvent; - -/** - * Map change event describing an incremental change of an - * {@link IObservableMap} object. - * - * @since 1.0 - * - */ -public class MapChangeEvent extends ObservableEvent { - - /** - * - */ - private static final long serialVersionUID = -8092347212410548463L; - static final Object TYPE = new Object(); - - /** - * Description of the change to the source observable map. Listeners must - * not change this field. - */ - public MapDiff diff; - - /** - * Creates a new map change event - * - * @param source - * the source observable map - * @param diff - * the map change - */ - public MapChangeEvent(IObservableMap source, MapDiff diff) { - super(source); - this.diff = diff; - } - - /** - * Returns the observable map from which this event originated. - * - * @return the observable map from which this event originated - */ - public IObservableMap getObservableMap() { - return (IObservableMap) getSource(); - } - - protected void dispatch(IObservablesListener listener) { - ((IMapChangeListener) listener).handleMapChange(this); - } - - protected Object getListenerType() { - return TYPE; - } - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/MapDiff.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/MapDiff.java deleted file mode 100644 index f54c37cd..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/MapDiff.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.map; - -import java.util.Set; - -/** - * @since 1.1 - * - */ -public abstract class MapDiff { - - /** - * @return the set of keys which were added - */ - public abstract Set getAddedKeys(); - - /** - * @return the set of keys which were removed - */ - public abstract Set getRemovedKeys(); - - /** - * @return the set of keys for which the value has changed - */ - public abstract Set getChangedKeys(); - - /** - * Returns the old value for the given key, which must be an element of - * {@link #getRemovedKeys()} or {@link #getChangedKeys()}. - * - * @param key - * @return the old value for the given key. - */ - public abstract Object getOldValue(Object key); - - /** - * Returns the new value for the given key, which must be an element of - * {@link #getChangedKeys()} or {@link #getAddedKeys()}. - * - * @param key - * @return the new value for the given key. - */ - public abstract Object getNewValue(Object key); -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/ObservableMap.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/ObservableMap.java deleted file mode 100644 index b52b3f9c..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/ObservableMap.java +++ /dev/null @@ -1,182 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - * Matthew Hall - bug 245183 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.map; - -import java.util.Collection; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.databinding.observable.AbstractObservable; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.Realm; - -/** - * - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * @since 1.0 - */ -public class ObservableMap extends AbstractObservable implements IObservableMap { - - protected Map wrappedMap; - - private boolean stale = false; - - /** - * @param wrappedMap - */ - public ObservableMap(Map wrappedMap) { - this(Realm.getDefault(), wrappedMap); - } - - /** - * @param realm - * @param wrappedMap - */ - public ObservableMap(Realm realm, Map wrappedMap) { - super(realm); - this.wrappedMap = wrappedMap; - } - - public synchronized void addMapChangeListener(IMapChangeListener listener) { - addListener(MapChangeEvent.TYPE, listener); - } - - public synchronized void removeMapChangeListener(IMapChangeListener listener) { - removeListener(MapChangeEvent.TYPE, listener); - } - - protected void getterCalled() { - ObservableTracker.getterCalled(this); - } - - protected void fireMapChange(MapDiff diff) { - checkRealm(); - - // fire general change event first - super.fireChange(); - - fireEvent(new MapChangeEvent(this, diff)); - } - - public boolean containsKey(Object key) { - getterCalled(); - return wrappedMap.containsKey(key); - } - - public boolean containsValue(Object value) { - getterCalled(); - return wrappedMap.containsValue(value); - } - - public Set entrySet() { - getterCalled(); - return wrappedMap.entrySet(); - } - - public Object get(Object key) { - getterCalled(); - return wrappedMap.get(key); - } - - public boolean isEmpty() { - getterCalled(); - return wrappedMap.isEmpty(); - } - - public Set keySet() { - getterCalled(); - return wrappedMap.keySet(); - } - - public int size() { - getterCalled(); - return wrappedMap.size(); - } - - public Collection values() { - getterCalled(); - return wrappedMap.values(); - } - - /** - * Returns the stale state. Must be invoked from the current realm. - * - * @return stale state - */ - public boolean isStale() { - checkRealm(); - return stale; - } - - /** - * Sets the stale state. Must be invoked from the current realm. - * - * @param stale - * The stale state to set. This will fire a stale event if the - * given boolean is true and this observable set was not already - * stale. - */ - public void setStale(boolean stale) { - checkRealm(); - boolean wasStale = this.stale; - this.stale = stale; - if (!wasStale && stale) { - fireStale(); - } - } - - public Object put(Object key, Object value) { - throw new UnsupportedOperationException(); - } - - public Object remove(Object key) { - throw new UnsupportedOperationException(); - } - - public void clear() { - throw new UnsupportedOperationException(); - } - - public void putAll(Map arg0) { - throw new UnsupportedOperationException(); - } - - public synchronized void dispose() { - super.dispose(); - } - - public boolean equals(Object obj) { - getterCalled(); - - if (obj == this) - return true; - if (obj == null) - return false; - if (getClass() == obj.getClass()) { - return wrappedMap.equals(((ObservableMap) obj).wrappedMap); - } - - return wrappedMap.equals(obj); - } - - public int hashCode() { - getterCalled(); - - return wrappedMap.hashCode(); - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/WritableMap.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/WritableMap.java deleted file mode 100644 index 4e534221..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/WritableMap.java +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006-2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - * Matthew Hall - bug 184830 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.map; - -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.internal.databinding.Util; - -/** - * - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * @since 1.0 - */ -public class WritableMap extends ObservableMap { - - /** - * Constructs a new WritableMap on the default realm. - */ - public WritableMap() { - this(Realm.getDefault()); - } - - /** - * Constructs a new WritableMap on the given realm. - * - * @param realm - * the realm - */ - public WritableMap(Realm realm) { - super(realm, new HashMap()); - } - - /** - * Associates the provided <code>value</code> with the <code>key</code>. Must be invoked from the current realm. - */ - public Object put(Object key, Object value) { - checkRealm(); - Object result = wrappedMap.put(key, value); - if (!Util.equals(result, value)) { - if (result==null) { - fireMapChange(Diffs.createMapDiffSingleAdd(key, value)); - } else { - fireMapChange(Diffs.createMapDiffSingleChange(key, result, - value)); - } - } - return result; - } - - /** - * Removes the value with the provide <code>key</code>. Must be invoked from the current realm. - */ - public Object remove(Object key) { - checkRealm(); - Object result = wrappedMap.remove(key); - if (result!=null) { - fireMapChange(Diffs.createMapDiffSingleRemove(key, result)); - } - return result; - } - - /** - * Clears the map. Must be invoked from the current realm. - */ - public void clear() { - checkRealm(); - if (!isEmpty()) { - Map copy = new HashMap(wrappedMap); - wrappedMap.clear(); - fireMapChange(Diffs.createMapDiffRemoveAll(copy)); - } - } - - /** - * Adds the provided <code>map</code>'s contents to this map. Must be invoked from the current realm. - */ - public void putAll(Map map) { - checkRealm(); - Set addedKeys = new HashSet(map.size()); - Map changes = new HashMap(map.size()); - for (Iterator it = map.entrySet().iterator(); it.hasNext();) { - Map.Entry entry = (Entry) it.next(); - Object previousValue = wrappedMap.put(entry.getKey(), entry.getValue()); - if (previousValue==null) { - addedKeys.add(entry.getKey()); - } else { - changes.put(entry.getKey(), previousValue); - } - } - if (!addedKeys.isEmpty() || !changes.isEmpty()) { - fireMapChange(Diffs.createMapDiff(addedKeys, Collections.EMPTY_SET, changes.keySet(), changes, wrappedMap)); - } - } - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/package.html b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/package.html deleted file mode 100644 index 22107ea3..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/package.html +++ /dev/null @@ -1,16 +0,0 @@ -<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> - <meta name="Author" content="IBM"> - <meta name="GENERATOR" content="Mozilla/4.5 [en] (Win98; I) [Netscape]"> - <title>Package-level Javadoc</title> -</head> -<body> -Provides classes that can be used to observe changes in maps. -<h2> -Package Specification</h2> -<p> -This package provides classes that can be used to observe changes in maps.</p> -</body> -</html> diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/masterdetail/IObservableFactory.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/masterdetail/IObservableFactory.java deleted file mode 100644 index e113f141..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/masterdetail/IObservableFactory.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.masterdetail; - -import org.eclipse.core.databinding.observable.IObservable; - -/** - * Generates an {@link IObservable} when passed a target instance. - * - * @since 1.0 - */ -public interface IObservableFactory { - - /** - * Creates an observable for the given target object. - * - * @param target - * @return the new observable - */ - public IObservable createObservable(Object target); - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/masterdetail/MasterDetailObservables.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/masterdetail/MasterDetailObservables.java deleted file mode 100644 index 77832e3f..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/masterdetail/MasterDetailObservables.java +++ /dev/null @@ -1,119 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 147515 - * Matthew Hall - bug 221704 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.masterdetail; - -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.internal.databinding.observable.masterdetail.DetailObservableList; -import org.eclipse.core.internal.databinding.observable.masterdetail.DetailObservableMap; -import org.eclipse.core.internal.databinding.observable.masterdetail.DetailObservableSet; -import org.eclipse.core.internal.databinding.observable.masterdetail.DetailObservableValue; - -/** - * Allows for the observation of an attribute, the detail, of an observable - * representing selection or another transient instance, the master. - * - * @since 1.0 - */ -public class MasterDetailObservables { - - /** - * Creates a detail observable value from a master observable value and a - * factory. This can be used to create observable values that represent a - * property of a selected object in a table. - * - * @param master - * the observable value to track - * @param detailFactory - * a factory for creating {@link IObservableValue} instances - * given a current value of the master - * @param detailType - * the value type of the detail observable value, typically of - * type java.lang.Class and can be <code>null</code> - * @return an observable value of the given value type that, for any current - * value of the given master value, behaves like the observable - * value created by the factory for that current value. - */ - public static IObservableValue detailValue(IObservableValue master, - IObservableFactory detailFactory, Object detailType) { - return new DetailObservableValue(master, detailFactory, detailType); - } - - /** - * Creates a detail observable list from a master observable value and a - * factory. This can be used to create observable lists that represent a - * list property of a selected object in a table. - * - * @param master - * the observable value to track - * @param detailFactory - * a factory for creating {@link IObservableList} instances given - * a current value of the master - * @param detailElementType - * the element type of the detail observable list, typically of - * type java.lang.Class and can be <code>null</code> - * @return an observable list with the given element type that, for any - * current value of the given master value, behaves like the - * observable list created by the factory for that current value. - */ - public static IObservableList detailList(IObservableValue master, - IObservableFactory detailFactory, Object detailElementType) { - return new DetailObservableList(detailFactory, master, - detailElementType); - } - - /** - * Creates a detail observable set from a master observable value and a - * factory. This can be used to create observable sets that represent a set - * property of a selected object in a table. - * - * @param master - * the observable value to track - * @param detailFactory - * a factory for creating {@link IObservableSet} instances given - * a current value of the master - * @param detailElementType - * the element type of the detail observable set, typically of - * type java.lang.Class and can be <code>null</code> - * @return an observable set with the given element type that, for any - * current value of the given master value, behaves like the - * observable set created by the factory for that current value. - */ - public static IObservableSet detailSet(IObservableValue master, - IObservableFactory detailFactory, Object detailElementType) { - return new DetailObservableSet(detailFactory, master, detailElementType); - } - - /** - * Creates a detail observable map from a master observable value and a - * factory. This can be used to create observable maps that represent a map - * property of a selected object in a table. - * - * @param master - * the observable value to track - * @param detailFactory - * a factory for createing {@link IObservableMap} instances given - * a current value of the master - * @return an observable map that, for any current value of the given master - * value, behaves like the observable map created by the factory for - * that current value. - * @since 1.1 - */ - public static IObservableMap detailMap(IObservableValue master, - IObservableFactory detailFactory) { - return new DetailObservableMap(detailFactory, master); - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/masterdetail/package.html b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/masterdetail/package.html deleted file mode 100644 index 07b72e5b..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/masterdetail/package.html +++ /dev/null @@ -1,17 +0,0 @@ -<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> - <meta name="Author" content="IBM"> - <meta name="GENERATOR" content="Mozilla/4.5 [en] (Win98; I) [Netscape]"> - <title>Package-level Javadoc</title> -</head> -<body> -Provides classes that can be used to observe a detail of a master object. -<h2> -Package Specification</h2> -<p> -This package provides classes that can be used to observe a detail of a master object. -A common use case for master detail is observing the detail (e.g. name) of a master (e.g. selected Person) of a list of elements.</p> -</body> -</html> diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/package.html b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/package.html deleted file mode 100644 index 0739c1ca..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/package.html +++ /dev/null @@ -1,16 +0,0 @@ -<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> - <meta name="Author" content="IBM"> - <meta name="GENERATOR" content="Mozilla/4.5 [en] (Win98; I) [Netscape]"> - <title>Package-level Javadoc</title> -</head> -<body> -Provides the core APIs for observing changes in objects. -<h2> -Package Specification</h2> -<p> -This package provides the core APIs for observing changes in objects.</p> -</body> -</html> diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/AbstractObservableSet.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/AbstractObservableSet.java deleted file mode 100644 index 5c9d0b7f..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/AbstractObservableSet.java +++ /dev/null @@ -1,218 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 208332 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.set; - -import java.util.Collection; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.databinding.observable.AbstractObservable; -import org.eclipse.core.databinding.observable.ChangeSupport; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.Realm; - -/** - * - * Abstract implementation of {@link IObservableSet}. - * - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * - * @since 1.0 - */ -public abstract class AbstractObservableSet extends AbstractObservable implements - IObservableSet { - - private ChangeSupport changeSupport; - - private boolean stale = false; - - protected AbstractObservableSet() { - this(Realm.getDefault()); - } - - protected void firstListenerAdded() { - super.firstListenerAdded(); - } - - protected void lastListenerRemoved() { - super.lastListenerRemoved(); - } - - protected AbstractObservableSet(Realm realm) { - super(realm); - changeSupport = new ChangeSupport(realm){ - protected void firstListenerAdded() { - AbstractObservableSet.this.firstListenerAdded(); - } - protected void lastListenerRemoved() { - AbstractObservableSet.this.lastListenerRemoved(); - } - }; - } - - public synchronized void addSetChangeListener(ISetChangeListener listener) { - changeSupport.addListener(SetChangeEvent.TYPE, listener); - } - - public synchronized void removeSetChangeListener(ISetChangeListener listener) { - changeSupport.removeListener(SetChangeEvent.TYPE, listener); - } - - protected abstract Set getWrappedSet(); - - protected void fireSetChange(SetDiff diff) { - // fire general change event first - super.fireChange(); - - changeSupport.fireEvent(new SetChangeEvent(this, diff)); - } - - public boolean contains(Object o) { - getterCalled(); - return getWrappedSet().contains(o); - } - - public boolean containsAll(Collection c) { - getterCalled(); - return getWrappedSet().containsAll(c); - } - - public boolean equals(Object o) { - getterCalled(); - return getWrappedSet().equals(o); - } - - public int hashCode() { - getterCalled(); - return getWrappedSet().hashCode(); - } - - public boolean isEmpty() { - getterCalled(); - return getWrappedSet().isEmpty(); - } - - public Iterator iterator() { - getterCalled(); - final Iterator wrappedIterator = getWrappedSet().iterator(); - return new Iterator() { - - public void remove() { - throw new UnsupportedOperationException(); - } - - public boolean hasNext() { - ObservableTracker.getterCalled(AbstractObservableSet.this); - return wrappedIterator.hasNext(); - } - - public Object next() { - ObservableTracker.getterCalled(AbstractObservableSet.this); - return wrappedIterator.next(); - } - }; - } - - public int size() { - getterCalled(); - return getWrappedSet().size(); - } - - public Object[] toArray() { - getterCalled(); - return getWrappedSet().toArray(); - } - - public Object[] toArray(Object[] a) { - getterCalled(); - return getWrappedSet().toArray(a); - } - - public String toString() { - getterCalled(); - return getWrappedSet().toString(); - } - - protected void getterCalled() { - ObservableTracker.getterCalled(this); - } - - public boolean add(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - throw new UnsupportedOperationException(); - } - - /** - * @return Returns the stale state. - */ - public boolean isStale() { - getterCalled(); - return stale; - } - - /** - * @param stale - * The stale state to set. This will fire a stale event if the - * given boolean is true and this observable set was not already - * stale. - */ - public void setStale(boolean stale) { - checkRealm(); - boolean wasStale = this.stale; - this.stale = stale; - if (!wasStale && stale) { - fireStale(); - } - } - - - protected void fireChange() { - throw new RuntimeException("fireChange should not be called, use fireSetChange() instead"); //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.jface.provisional.databinding.observable.AbstractObservable#dispose() - */ - public synchronized void dispose() { - super.dispose(); - - if (changeSupport != null) { - changeSupport.dispose(); - changeSupport = null; - } - } - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/IObservableSet.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/IObservableSet.java deleted file mode 100644 index 0efecf66..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/IObservableSet.java +++ /dev/null @@ -1,129 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.set; - -import java.util.Collection; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.databinding.observable.IObservableCollection; - -/** - * A set whose changes can be tracked by set change listeners. - * - * @noextend This interface is not intended to be extended by clients. - * @noimplement This interface is not intended to be implemented by clients. - * Clients should instead subclass one of the classes that - * implement this interface. Note that direct implementers of this - * interface outside of the framework will be broken in future - * releases when methods are added to this interface. - * - * @see AbstractObservableSet - * @see ObservableSet - * - * @since 1.0 - * - */ -public interface IObservableSet extends Set, IObservableCollection { - - /** - * @param listener - */ - public void addSetChangeListener(ISetChangeListener listener); - - /** - * @param listener - */ - public void removeSetChangeListener(ISetChangeListener listener); - - /** - * @return the element type or <code>null</code> if untyped - */ - public Object getElementType(); - - /** - * @TrackedGetter - */ - int size(); - - /** - * @TrackedGetter - */ - boolean isEmpty(); - - /** - * @TrackedGetter - */ - boolean contains(Object o); - - /** - * @TrackedGetter - */ - Iterator iterator(); - - /** - * @TrackedGetter - */ - Object[] toArray(); - - /** - * @TrackedGetter - */ - Object[] toArray(Object a[]); - - // Modification Operations - - /** - * @TrackedGetter - */ - boolean add(Object o); - - /** - * @TrackedGetter - */ - boolean remove(Object o); - - // Bulk Operations - - /** - * @TrackedGetter - */ - boolean containsAll(Collection c); - - /** - * @TrackedGetter - */ - boolean addAll(Collection c); - - /** - * @TrackedGetter - */ - boolean retainAll(Collection c); - - /** - * @TrackedGetter - */ - boolean removeAll(Collection c); - - // Comparison and hashing - - /** - * @TrackedGetter - */ - boolean equals(Object o); - - /** - * @TrackedGetter - */ - int hashCode(); - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/ISetChangeListener.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/ISetChangeListener.java deleted file mode 100644 index 51c429a3..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/ISetChangeListener.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.set; - -import org.eclipse.core.databinding.observable.IObservablesListener; - -/** - * Listener for changes to observable sets. - * - * @since 1.0 - * - */ -public interface ISetChangeListener extends IObservablesListener { - - /** - * Handle a change to an observable set. The given event object must only be - * used locally in this method because it may be reused for other change - * notifications. The diff object referenced by the event is immutable and - * may be used non-locally. - * - * @param event - * the event - */ - void handleSetChange(SetChangeEvent event); - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/ListToSetAdapter.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/ListToSetAdapter.java deleted file mode 100644 index e145fb3c..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/ListToSetAdapter.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.set; - -import java.util.HashSet; -import java.util.Set; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IListChangeListener; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.ListChangeEvent; -import org.eclipse.core.databinding.observable.list.ListDiffEntry; - -/** - * Observable set backed by an observable list. The wrapped list must not - * contain duplicate elements. - * - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * - * @since 1.0 - * - */ -public class ListToSetAdapter extends ObservableSet { - - private final IObservableList list; - - private IListChangeListener listener = new IListChangeListener() { - - public void handleListChange(ListChangeEvent event) { - Set added = new HashSet(); - Set removed = new HashSet(); - ListDiffEntry[] differences = event.diff.getDifferences(); - for (int i = 0; i < differences.length; i++) { - ListDiffEntry entry = differences[i]; - Object element = entry.getElement(); - if (entry.isAddition()) { - if (wrappedSet.add(element)) { - if (!removed.remove(element)) - added.add(element); - } - } else { - if (wrappedSet.remove(element)) { - removed.add(element); - added.remove(element); - } - } - } - fireSetChange(Diffs.createSetDiff(added, removed)); - } - }; - - /** - * @param list - */ - public ListToSetAdapter(IObservableList list) { - super(list.getRealm(), new HashSet(), list.getElementType()); - this.list = list; - wrappedSet.addAll(list); - this.list.addListChangeListener(listener); - } - - public synchronized void dispose() { - super.dispose(); - if (list != null && listener != null) { - list.removeListChangeListener(listener); - listener = null; - } - } - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/MappedSet.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/MappedSet.java deleted file mode 100644 index c51c0c5c..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/MappedSet.java +++ /dev/null @@ -1,157 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.set; - -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.map.IMapChangeListener; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.map.MapChangeEvent; -import org.eclipse.core.databinding.observable.map.MapDiff; - -/** - * - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * - * @since 1.0 - * - */ -public class MappedSet extends ObservableSet { - - private final IObservableMap wrappedMap; - - /* - * Map from values (range elements) to Integer ref counts - */ - private Map valueCounts = new HashMap(); - - private ISetChangeListener domainListener = new ISetChangeListener() { - public void handleSetChange(SetChangeEvent event) { - Set additions = new HashSet(); - for (Iterator it = event.diff.getAdditions().iterator(); it.hasNext();) { - Object added = it.next(); - Object mapValue = wrappedMap.get(added); - if (handleAddition(mapValue)) { - additions.add(mapValue); - } - } - Set removals = new HashSet(); - for (Iterator it = event.diff.getRemovals().iterator(); it.hasNext();) { - Object removed = it.next(); - Object mapValue = wrappedMap.get(removed); - if (handleRemoval(mapValue)) { - removals.add(mapValue); - } - } - fireSetChange(Diffs.createSetDiff(additions, removals)); - } - }; - - private IMapChangeListener mapChangeListener = new IMapChangeListener() { - public void handleMapChange(MapChangeEvent event) { - MapDiff diff = event.diff; - Set additions = new HashSet(); - Set removals = new HashSet(); - for (Iterator it = diff.getRemovedKeys().iterator(); it.hasNext();) { - Object key = it.next(); - Object oldValue = diff.getOldValue(key); - if (handleRemoval(oldValue)) { - removals.add(oldValue); - } - } - for (Iterator it = diff.getChangedKeys().iterator(); it.hasNext();) { - Object key = it.next(); - Object oldValue = diff.getOldValue(key); - Object newValue = diff.getNewValue(key); - if (handleRemoval(oldValue)) { - removals.add(oldValue); - } - if (handleAddition(newValue)) { - additions.add(newValue); - } - } - for (Iterator it = diff.getAddedKeys().iterator(); it.hasNext();) { - Object key = it.next(); - Object newValue = diff.getNewValue(key); - if (handleAddition(newValue)) { - additions.add(newValue); - } - } - fireSetChange(Diffs.createSetDiff(additions, removals)); - } - }; - - private IObservableSet input; - - /** - * @param input - * @param map - */ - public MappedSet(IObservableSet input, IObservableMap map) { - super(input.getRealm(), Collections.EMPTY_SET, Object.class); - setWrappedSet(valueCounts.keySet()); - this.wrappedMap = map; - this.input = input; - for (Iterator it = input.iterator(); it.hasNext();) { - Object element = it.next(); - Object functionValue = wrappedMap.get(element); - handleAddition(functionValue); - } - input.addSetChangeListener(domainListener); - map.addMapChangeListener(mapChangeListener); - } - - /** - * @param mapValue - * @return true if the given mapValue was an addition - */ - protected boolean handleAddition(Object mapValue) { - Integer count = (Integer) valueCounts.get(mapValue); - if (count == null) { - valueCounts.put(mapValue, new Integer(1)); - return true; - } - valueCounts.put(mapValue, new Integer(count.intValue() + 1)); - return false; - } - - /** - * @param mapValue - * @return true if the given mapValue has been removed - */ - protected boolean handleRemoval(Object mapValue) { - Integer count = (Integer) valueCounts.get(mapValue); - if (count.intValue() <= 1) { - valueCounts.remove(mapValue); - return true; - } - valueCounts.put(mapValue, new Integer(count.intValue() - 1)); - return false; - } - - public synchronized void dispose() { - wrappedMap.removeMapChangeListener(mapChangeListener); - input.removeSetChangeListener(domainListener); - } - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/ObservableSet.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/ObservableSet.java deleted file mode 100644 index 433a0f83..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/ObservableSet.java +++ /dev/null @@ -1,217 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bugs 208332, 245183 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.set; - -import java.util.Collection; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.databinding.observable.AbstractObservable; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.Realm; - -/** - * - * Abstract implementation of {@link IObservableSet}. - * - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * - * @since 1.0 - * - */ -public abstract class ObservableSet extends AbstractObservable implements - IObservableSet { - - protected Set wrappedSet; - - private boolean stale = false; - - protected Object elementType; - - protected ObservableSet(Set wrappedSet, Object elementType) { - this(Realm.getDefault(), wrappedSet, elementType); - } - - protected ObservableSet(Realm realm, Set wrappedSet, Object elementType) { - super(realm); - this.wrappedSet = wrappedSet; - this.elementType = elementType; - } - - public synchronized void addSetChangeListener(ISetChangeListener listener) { - addListener(SetChangeEvent.TYPE, listener); - } - - public synchronized void removeSetChangeListener(ISetChangeListener listener) { - removeListener(SetChangeEvent.TYPE, listener); - } - - protected void fireSetChange(SetDiff diff) { - // fire general change event first - super.fireChange(); - - fireEvent(new SetChangeEvent(this, diff)); - } - - public boolean contains(Object o) { - getterCalled(); - return wrappedSet.contains(o); - } - - public boolean containsAll(Collection c) { - getterCalled(); - return wrappedSet.containsAll(c); - } - - public boolean equals(Object o) { - getterCalled(); - - if (o == this) - return true; - if (o == null) - return false; - if (getClass() == o.getClass()) { - return wrappedSet.equals(((ObservableSet) o).wrappedSet); - } - - return wrappedSet.equals(o); - } - - public int hashCode() { - getterCalled(); - return wrappedSet.hashCode(); - } - - public boolean isEmpty() { - getterCalled(); - return wrappedSet.isEmpty(); - } - - public Iterator iterator() { - getterCalled(); - final Iterator wrappedIterator = wrappedSet.iterator(); - return new Iterator() { - - public void remove() { - throw new UnsupportedOperationException(); - } - - public boolean hasNext() { - ObservableTracker.getterCalled(ObservableSet.this); - return wrappedIterator.hasNext(); - } - - public Object next() { - ObservableTracker.getterCalled(ObservableSet.this); - return wrappedIterator.next(); - } - }; - } - - public int size() { - getterCalled(); - return wrappedSet.size(); - } - - public Object[] toArray() { - getterCalled(); - return wrappedSet.toArray(); - } - - public Object[] toArray(Object[] a) { - getterCalled(); - return wrappedSet.toArray(a); - } - - public String toString() { - getterCalled(); - return wrappedSet.toString(); - } - - protected void getterCalled() { - ObservableTracker.getterCalled(this); - } - - public boolean add(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - throw new UnsupportedOperationException(); - } - - /** - * @return Returns the stale state. - */ - public boolean isStale() { - getterCalled(); - return stale; - } - - /** - * @param stale - * The stale state to set. This will fire a stale event if the - * given boolean is true and this observable set was not already - * stale. - */ - public void setStale(boolean stale) { - checkRealm(); - boolean wasStale = this.stale; - this.stale = stale; - if (!wasStale && stale) { - fireStale(); - } - } - - /** - * @param wrappedSet The wrappedSet to set. - */ - protected void setWrappedSet(Set wrappedSet) { - this.wrappedSet = wrappedSet; - } - - protected void fireChange() { - throw new RuntimeException("fireChange should not be called, use fireSetChange() instead"); //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.jface.provisional.databinding.observable.AbstractObservable#dispose() - */ - public synchronized void dispose() { - super.dispose(); - } - - public Object getElementType() { - return elementType; - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/SetChangeEvent.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/SetChangeEvent.java deleted file mode 100644 index 4873885e..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/SetChangeEvent.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.databinding.observable.set; - -import org.eclipse.core.databinding.observable.IObservablesListener; -import org.eclipse.core.databinding.observable.ObservableEvent; - -/** - * List change event describing an incremental change of an - * {@link IObservableSet} object. - * - * @since 1.0 - * - */ -public class SetChangeEvent extends ObservableEvent { - - /** - * - */ - private static final long serialVersionUID = 7436547103857482256L; - static final Object TYPE = new Object(); - - /** - * Description of the change to the source observable set. Listeners must - * not change this field. - */ - public SetDiff diff; - - /** - * Creates a new set change event. - * - * @param source - * the source observable set - * @param diff - * the set change - */ - public SetChangeEvent(IObservableSet source, SetDiff diff) { - super(source); - this.diff = diff; - } - - /** - * Returns the observable set from which this event originated. - * - * @return the observable set from which this event originated - */ - public IObservableSet getObservableSet() { - return (IObservableSet) getSource(); - } - - protected void dispatch(IObservablesListener listener) { - ((ISetChangeListener) listener).handleSetChange(this); - } - - protected Object getListenerType() { - return TYPE; - } - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/SetDiff.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/SetDiff.java deleted file mode 100644 index d1a2f138..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/SetDiff.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.set; - -import java.util.Set; - -/** - * @since 1.0 - * - */ -public abstract class SetDiff { - - /** - * @return the set of added elements - */ - public abstract Set getAdditions(); - - /** - * @return the set of removed elements - */ - public abstract Set getRemovals(); - - /** - * @see java.lang.Object#toString() - */ - public String toString() { - StringBuffer buffer = new StringBuffer(); - buffer - .append(getClass().getName()) - .append("{additions [") //$NON-NLS-1$ - .append(getAdditions() != null ? getAdditions().toString() : "null") //$NON-NLS-1$ - .append("], removals [") //$NON-NLS-1$ - .append(getRemovals() != null ? getRemovals().toString() : "null") //$NON-NLS-1$ - .append("]}"); //$NON-NLS-1$ - - return buffer.toString(); - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/UnionSet.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/UnionSet.java deleted file mode 100644 index 768c62d6..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/UnionSet.java +++ /dev/null @@ -1,210 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 208332 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.set; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.internal.databinding.observable.IStalenessConsumer; -import org.eclipse.core.internal.databinding.observable.StalenessTracker; - -/** - * Represents a set consisting of the union of elements from one or more other - * sets. This object does not need to be explicitly disposed. If nobody is - * listening to the UnionSet, the set will remove its listeners. - * - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * - * @since 1.0 - */ -public final class UnionSet extends ObservableSet { - - /** - * child sets - */ - private IObservableSet[] childSets; - - private boolean stale = false; - - /** - * Map of elements onto Integer reference counts. This map is constructed - * when the first listener is added to the union set. Null if nobody is - * listening to the UnionSet. - */ - private HashMap refCounts = null; - - private StalenessTracker stalenessTracker; - - /** - * @param childSets - */ - public UnionSet(IObservableSet[] childSets) { - super(childSets[0].getRealm(), null, childSets[0].getElementType()); - System.arraycopy(childSets, 0, this.childSets = new IObservableSet[childSets.length], 0, childSets.length); - this.stalenessTracker = new StalenessTracker(childSets, - stalenessConsumer); - } - - private ISetChangeListener childSetChangeListener = new ISetChangeListener() { - public void handleSetChange(SetChangeEvent event) { - processAddsAndRemoves(event.diff.getAdditions(), event.diff.getRemovals()); - } - }; - - private IStalenessConsumer stalenessConsumer = new IStalenessConsumer() { - public void setStale(boolean stale) { - boolean oldStale = UnionSet.this.stale; - UnionSet.this.stale = stale; - if (stale && !oldStale) { - fireStale(); - } - } - }; - - public boolean isStale() { - getterCalled(); - if (refCounts != null) { - return stale; - } - - for (int i = 0; i < childSets.length; i++) { - IObservableSet childSet = childSets[i]; - - if (childSet.isStale()) { - return true; - } - } - return false; - } - - private void processAddsAndRemoves(Set adds, Set removes) { - Set addsToFire = new HashSet(); - Set removesToFire = new HashSet(); - - for (Iterator iter = adds.iterator(); iter.hasNext();) { - Object added = iter.next(); - - Integer refCount = (Integer) refCounts.get(added); - if (refCount == null) { - refCounts.put(added, new Integer(1)); - addsToFire.add(added); - } else { - int refs = refCount.intValue(); - refCount = new Integer(refs + 1); - refCounts.put(added, refCount); - } - } - - for (Iterator iter = removes.iterator(); iter.hasNext();) { - Object removed = iter.next(); - - Integer refCount = (Integer) refCounts.get(removed); - if (refCount != null) { - int refs = refCount.intValue(); - if (refs <= 1) { - removesToFire.add(removed); - refCounts.remove(removed); - } else { - refCount = new Integer(refCount.intValue() - 1); - refCounts.put(removed, refCount); - } - } - } - - // just in case the removes overlapped with the adds - addsToFire.removeAll(removesToFire); - - if (addsToFire.size() > 0 || removesToFire.size() > 0) { - fireSetChange(Diffs.createSetDiff(addsToFire, removesToFire)); - } - } - - protected void firstListenerAdded() { - super.firstListenerAdded(); - - refCounts = new HashMap(); - for (int i = 0; i < childSets.length; i++) { - IObservableSet next = childSets[i]; - next.addSetChangeListener(childSetChangeListener); - incrementRefCounts(next); - } - stalenessTracker = new StalenessTracker(childSets, stalenessConsumer); - setWrappedSet(refCounts.keySet()); - } - - protected void lastListenerRemoved() { - super.lastListenerRemoved(); - - for (int i = 0; i < childSets.length; i++) { - IObservableSet next = childSets[i]; - - next.removeSetChangeListener(childSetChangeListener); - stalenessTracker.removeObservable(next); - } - refCounts = null; - stalenessTracker = null; - setWrappedSet(null); - } - - private ArrayList incrementRefCounts(Collection added) { - ArrayList adds = new ArrayList(); - - for (Iterator iter = added.iterator(); iter.hasNext();) { - Object next = iter.next(); - - Integer refCount = (Integer) refCounts.get(next); - if (refCount == null) { - adds.add(next); - refCount = new Integer(1); - refCounts.put(next, refCount); - } else { - refCount = new Integer(refCount.intValue() + 1); - refCounts.put(next, refCount); - } - } - return adds; - } - - protected void getterCalled() { - super.getterCalled(); - if (refCounts == null) { - // no listeners, recompute - setWrappedSet(computeElements()); - } - } - - private Set computeElements() { - // If there is no cached value, compute the union from scratch - if (refCounts == null) { - Set result = new HashSet(); - for (int i = 0; i < childSets.length; i++) { - result.addAll(childSets[i]); - } - return result; - } - - // Else there is a cached value. Return it. - return refCounts.keySet(); - } - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/WritableSet.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/WritableSet.java deleted file mode 100644 index 52ded9dd..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/WritableSet.java +++ /dev/null @@ -1,171 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006-2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 147515 - * Matthew Hall - bug 221351 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.set; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; - -/** - * Mutable (writable) implementation of {@link IObservableSet}. - * - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * - * @since 1.0 - */ -public class WritableSet extends ObservableSet { - - /** - * Constructs a new empty instance in the default realm with a - * <code>null</code> element type. - * - */ - public WritableSet() { - this(Realm.getDefault()); - } - - /** - * Constructs a new instance in the default realm containing the - * elements of the given collection. Changes to the given collection after - * calling this method do not affect the contents of the created WritableSet. - * - * @param c - * @param elementType - * can be <code>null</code> - */ - public WritableSet(Collection c, Object elementType) { - this(Realm.getDefault(), new HashSet(c), elementType); - } - - /** - * Constructs a new empty instance in the given realm and a - * <code>null</code> element type. - * - * @param realm - */ - public WritableSet(Realm realm) { - this(realm, new HashSet(), null); - } - - /** - * Constructs a new instance in the default realm with the given element - * type, containing the elements of the given collection. Changes to the - * given collection after calling this method do not affect the contents of - * the created WritableSet. - * - * @param realm - * @param c - * @param elementType - * can be <code>null</code> - */ - public WritableSet(Realm realm, Collection c, Object elementType) { - super(realm, new HashSet(c), elementType); - this.elementType = elementType; - } - - public boolean add(Object o) { - getterCalled(); - boolean added = wrappedSet.add(o); - if (added) { - fireSetChange(Diffs.createSetDiff(Collections.singleton(o), Collections.EMPTY_SET)); - } - return added; - } - - public boolean addAll(Collection c) { - getterCalled(); - Set additions = new HashSet(); - Iterator it = c.iterator(); - while (it.hasNext()) { - Object element = it.next(); - if (wrappedSet.add(element)) { - additions.add(element); - } - } - if (additions.size() > 0) { - fireSetChange(Diffs.createSetDiff(additions, Collections.EMPTY_SET)); - return true; - } - return false; - } - - public boolean remove(Object o) { - getterCalled(); - boolean removed = wrappedSet.remove(o); - if (removed) { - fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, Collections - .singleton(o))); - } - return removed; - } - - public boolean removeAll(Collection c) { - getterCalled(); - Set removes = new HashSet(); - Iterator it = c.iterator(); - while (it.hasNext()) { - Object element = it.next(); - if (wrappedSet.remove(element)) { - removes.add(element); - } - } - if (removes.size() > 0) { - fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, removes)); - return true; - } - return false; - } - - public boolean retainAll(Collection c) { - getterCalled(); - Set removes = new HashSet(); - Iterator it = wrappedSet.iterator(); - while (it.hasNext()) { - Object element = it.next(); - if (!c.contains(element)) { - it.remove(); - removes.add(element); - } - } - if (removes.size() > 0) { - fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, removes)); - return true; - } - return false; - } - - public void clear() { - getterCalled(); - Set removes = new HashSet(wrappedSet); - wrappedSet.clear(); - fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, removes)); - } - - /** - * @param elementType can be <code>null</code> - * @return new instance with the default realm - */ - public static WritableSet withElementType(Object elementType) { - return new WritableSet(Realm.getDefault(), new HashSet(), elementType); - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/package.html b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/package.html deleted file mode 100644 index 5a57448a..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/set/package.html +++ /dev/null @@ -1,16 +0,0 @@ -<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> - <meta name="Author" content="IBM"> - <meta name="GENERATOR" content="Mozilla/4.5 [en] (Win98; I) [Netscape]"> - <title>Package-level Javadoc</title> -</head> -<body> -Provides classes that can be used to observe changes in sets. -<h2> -Package Specification</h2> -<p> -This package provides classes that can be used to observe changes in sets.</p> -</body> -</html> diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/AbstractObservableValue.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/AbstractObservableValue.java deleted file mode 100644 index 1c615894..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/AbstractObservableValue.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - * Matthew Hall - bug 208332 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.value; - -import org.eclipse.core.databinding.observable.AbstractObservable; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.Realm; - -/** - * - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * @since 1.0 - * - */ -abstract public class AbstractObservableValue extends AbstractObservable implements IObservableValue { - /** - * Constructs a new instance with the default realm. - */ - public AbstractObservableValue() { - this(Realm.getDefault()); - } - - /** - * @param realm - */ - public AbstractObservableValue(Realm realm) { - super(realm); - } - - public synchronized void addValueChangeListener(IValueChangeListener listener) { - addListener(ValueChangeEvent.TYPE, listener); - } - - public synchronized void removeValueChangeListener(IValueChangeListener listener) { - removeListener(ValueChangeEvent.TYPE, listener); - } - - final public void setValue(Object value) { - checkRealm(); - doSetValue(value); - } - - /** - * Template method for setting the value of the observable. By default the - * method throws an {@link UnsupportedOperationException}. - * - * @param value - */ - protected void doSetValue(Object value) { - throw new UnsupportedOperationException(); - } - - protected void fireValueChange(ValueDiff diff) { - // fire general change event first - super.fireChange(); - fireEvent(new ValueChangeEvent(this, diff)); - } - - public final Object getValue() { - getterCalled(); - return doGetValue(); - } - - abstract protected Object doGetValue(); - - public boolean isStale() { - getterCalled(); - return false; - } - - private void getterCalled() { - ObservableTracker.getterCalled(this); - } - - protected void fireChange() { - throw new RuntimeException( - "fireChange should not be called, use fireValueChange() instead"); //$NON-NLS-1$ - } - - public synchronized void dispose() { - super.dispose(); - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/AbstractVetoableValue.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/AbstractVetoableValue.java deleted file mode 100644 index d3cff74b..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/AbstractVetoableValue.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - *******************************************************************************/ -package org.eclipse.core.databinding.observable.value; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.internal.databinding.Util; - -/** - * - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * @since 1.0 - * - */ -public abstract class AbstractVetoableValue extends AbstractObservableValue - implements IVetoableValue { - - /** - * Creates a new vetoable value. - */ - public AbstractVetoableValue() { - this(Realm.getDefault()); - } - - /** - * @param realm - */ - public AbstractVetoableValue(Realm realm) { - super(realm); - } - - final protected void doSetValue(Object value) { - Object currentValue = doGetValue(); - ValueDiff diff = Diffs.createValueDiff(currentValue, value); - boolean okToProceed = fireValueChanging(diff); - if (!okToProceed) { - throw new ChangeVetoException("Change not permitted"); //$NON-NLS-1$ - } - doSetApprovedValue(value); - - if (!Util.equals(diff.getOldValue(), diff.getNewValue())) { - fireValueChange(diff); - } - } - - /** - * Sets the value. Invoked after performing veto checks. Should not fire change events. - * - * @param value - */ - protected abstract void doSetApprovedValue(Object value); - - public synchronized void addValueChangingListener( - IValueChangingListener listener) { - addListener(ValueChangingEvent.TYPE, listener); - } - - public synchronized void removeValueChangingListener( - IValueChangingListener listener) { - removeListener(ValueChangingEvent.TYPE, listener); - } - - /** - * Notifies listeners about a pending change, and returns true if no - * listener vetoed the change. - * - * @param diff - * @return false if the change was vetoed, true otherwise - */ - protected boolean fireValueChanging(ValueDiff diff) { - checkRealm(); - - ValueChangingEvent event = new ValueChangingEvent(this, diff); - fireEvent(event); - return !event.veto; - } - - public synchronized void dispose() { - super.dispose(); - } - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/ChangeVetoException.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/ChangeVetoException.java deleted file mode 100644 index 3c9261ff..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/ChangeVetoException.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.core.databinding.observable.value; - -/** - * @since 1.0 - * - */ -public class ChangeVetoException extends RuntimeException { - - /** - * @param string - */ - public ChangeVetoException(String string) { - super(string); - } - - private static final long serialVersionUID = 1L; - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/ComputedValue.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/ComputedValue.java deleted file mode 100644 index 755063aa..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/ComputedValue.java +++ /dev/null @@ -1,261 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 116920 - * Brad Reynolds - bug 147515 - *******************************************************************************/ -package org.eclipse.core.databinding.observable.value; - -import org.eclipse.core.databinding.observable.ChangeEvent; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.StaleEvent; - -/** - * A Lazily calculated value that automatically computes and registers listeners - * on its dependencies as long as all of its dependencies are IObservable - * objects - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * - * @since 1.0 - */ -public abstract class ComputedValue extends AbstractObservableValue { - - private boolean dirty = true; - - private boolean stale = false; - - private Object cachedValue = null; - - /** - * Array of observables this computed value depends on. This field has a - * value of <code>null</code> if we are not currently listening. - */ - private IObservable[] dependencies = null; - - /** - * - */ - public ComputedValue() { - this(Realm.getDefault(), null); - } - - /** - * @param valueType - * can be <code>null</code> - */ - public ComputedValue(Object valueType) { - this(Realm.getDefault(), valueType); - } - - /** - * @param realm - * - */ - public ComputedValue(Realm realm) { - this(realm, null); - } - - /** - * @param realm - * @param valueType - */ - public ComputedValue(Realm realm, Object valueType) { - super(realm); - this.valueType = valueType; - } - - /** - * Inner class that implements interfaces that we don't want to expose as - * public API. Each interface could have been implemented using a separate - * anonymous class, but we combine them here to reduce the memory overhead - * and number of classes. - * - * <p> - * The Runnable calls computeValue and stores the result in cachedValue. - * </p> - * - * <p> - * The IChangeListener stores each observable in the dependencies list. This - * is registered as the listener when calling ObservableTracker, to detect - * every observable that is used by computeValue. - * </p> - * - * <p> - * The IChangeListener is attached to every dependency. - * </p> - * - */ - private class PrivateInterface implements Runnable, IChangeListener, - IStaleListener { - public void run() { - cachedValue = calculate(); - } - - public void handleStale(StaleEvent event) { - if (!dirty && !stale) { - stale = true; - fireStale(); - } - } - - public void handleChange(ChangeEvent event) { - makeDirty(); - } - } - - private PrivateInterface privateInterface = new PrivateInterface(); - - private Object valueType; - - protected final Object doGetValue() { - if (dirty) { - // This line will do the following: - // - Run the calculate method - // - While doing so, add any observable that is touched to the - // dependencies list - IObservable[] newDependencies = ObservableTracker.runAndMonitor( - privateInterface, privateInterface, null); - - stale = false; - for (int i = 0; i < newDependencies.length; i++) { - IObservable observable = newDependencies[i]; - // Add a change listener to the new dependency. - if (observable.isStale()) { - stale = true; - } else { - observable.addStaleListener(privateInterface); - } - } - - dependencies = newDependencies; - - dirty = false; - } - - return cachedValue; - } - - /** - * Subclasses must override this method to provide the object's value. - * - * @return the object's value - */ - protected abstract Object calculate(); - - protected final void makeDirty() { - if (!dirty) { - dirty = true; - - stopListening(); - - // copy the old value - final Object oldValue = cachedValue; - // Fire the "dirty" event. This implementation recomputes the new - // value lazily. - fireValueChange(new ValueDiff() { - - public Object getOldValue() { - return oldValue; - } - - public Object getNewValue() { - return getValue(); - } - }); - } - } - - /** - * - */ - private void stopListening() { - // Stop listening for dependency changes. - if (dependencies != null) { - for (int i = 0; i < dependencies.length; i++) { - IObservable observable = dependencies[i]; - - observable.removeChangeListener(privateInterface); - observable.removeStaleListener(privateInterface); - } - dependencies = null; - } - } - - public boolean isStale() { - // we need to recompute, otherwise staleness wouldn't mean anything - getValue(); - return stale; - } - - public Object getValueType() { - return valueType; - } - - // this method exists here so that we can call it from the runnable below. - /** - * @since 1.1 - */ - protected boolean hasListeners() { - return super.hasListeners(); - } - - public synchronized void addChangeListener(IChangeListener listener) { - super.addChangeListener(listener); - // If somebody is listening, we need to make sure we attach our own - // listeners - computeValueForListeners(); - } - - /** - * Some clients just add a listener and expect to get notified even if they - * never called getValue(), so we have to call getValue() ourselves here to - * be sure. Need to be careful about realms though, this method can be - * called outside of our realm. See also bug 198211. If a client calls this - * outside of our realm, they may receive change notifications before the - * runnable below has been executed. It is their job to figure out what to - * do with those notifications. - */ - private void computeValueForListeners() { - getRealm().exec(new Runnable() { - public void run() { - if (dependencies == null) { - // We are not currently listening. - if (hasListeners()) { - // But someone is listening for changes. Call getValue() - // to make sure we start listening to the observables we - // depend on. - getValue(); - } - } - } - }); - } - - public synchronized void addValueChangeListener( - IValueChangeListener listener) { - super.addValueChangeListener(listener); - // If somebody is listening, we need to make sure we attach our own - // listeners - computeValueForListeners(); - } - - public synchronized void dispose() { - super.dispose(); - stopListening(); - } - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/IObservableValue.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/IObservableValue.java deleted file mode 100644 index 630b1c47..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/IObservableValue.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.value; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; - -/** - * A value whose changes can be tracked by value change listeners. - * - * @noextend This interface is not intended to be extended by clients. - * @noimplement This interface is not intended to be implemented by clients. - * Clients should instead subclass one of the classes that - * implement this interface. Note that direct implementers of this - * interface outside of the framework will be broken in future - * releases when methods are added to this interface. - * - * @see AbstractObservableValue - * - * @since 1.0 - */ -public interface IObservableValue extends IObservable { - - /** - * The value type of this observable value, or <code>null</code> if this - * observable value is untyped. - * - * @return the value type, or <code>null</null> - */ - public Object getValueType(); - - /** - * Returns the value. Must be invoked in the {@link Realm} of the observable. - * - * @return the current value - * @TrackedGetter - */ - public Object getValue(); - - /** - * Sets the value. Must be invoked in the {@link Realm} of the observable. - * - * @param value - * the value to set - * @throws UnsupportedOperationException - * if this observable value cannot be set. - */ - public void setValue(Object value); - - /** - * - * @param listener - */ - public void addValueChangeListener(IValueChangeListener listener); - - /** - * @param listener - */ - public void removeValueChangeListener(IValueChangeListener listener); -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/IValueChangeListener.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/IValueChangeListener.java deleted file mode 100644 index 7af53822..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/IValueChangeListener.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.value; - -import org.eclipse.core.databinding.observable.IObservablesListener; - -/** - * Listener for changes to observable values. - * - * @since 1.0 - * - */ -public interface IValueChangeListener extends IObservablesListener { - - /** - * Handles a change to an observable value. The given event object must only - * be used locally in this method because it may be reused for other change - * notifications. The diff object referenced by the event is immutable and - * may be used non-locally. - * - * @param event - * the event - */ - void handleValueChange(ValueChangeEvent event); - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/IValueChangingListener.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/IValueChangingListener.java deleted file mode 100644 index ceb07b74..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/IValueChangingListener.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.core.databinding.observable.value; - -import org.eclipse.core.databinding.observable.IObservablesListener; - -/** - * Listener for pre-change events for observable values. - * - * @since 1.0 - * - */ -public interface IValueChangingListener extends IObservablesListener { - - /** - * This method is called when the value is about to change and provides an - * opportunity to veto the change. The given event object must only be used - * locally in this method because it may be reused for other change - * notifications. The diff object referenced by the event is immutable and - * may be used non-locally. - * - * @param event - */ - public void handleValueChanging(ValueChangingEvent event); - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/IVetoableValue.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/IVetoableValue.java deleted file mode 100644 index 1b795eda..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/IVetoableValue.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.core.databinding.observable.value; - -/** - * An observable value whose changes can be vetoed by listeners. - * - * @noextend This interface is not intended to be extended by clients. - * @noimplement This interface is not intended to be implemented by clients. - * Clients should instead subclass one of the classes that - * implement this interface. Note that direct implementers of this - * interface outside of the framework will be broken in future - * releases when methods are added to this interface. - * - * @since 1.0 - * - */ -public interface IVetoableValue extends IObservableValue { - - /** - * @param listener - */ - public void addValueChangingListener(IValueChangingListener listener); - - /** - * @param listener - */ - public void removeValueChangingListener(IValueChangingListener listener); - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/ValueChangeEvent.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/ValueChangeEvent.java deleted file mode 100644 index 3d4fba90..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/ValueChangeEvent.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.databinding.observable.value; - -import org.eclipse.core.databinding.observable.IObservablesListener; -import org.eclipse.core.databinding.observable.ObservableEvent; - -/** - * Value change event describing a change of an {@link IObservableValue} - * object's current value. - * - * @since 1.0 - * - */ -public class ValueChangeEvent extends ObservableEvent { - - /** - * - */ - private static final long serialVersionUID = 2305345286999701156L; - - static final Object TYPE = new Object(); - - /** - * Description of the change to the source observable value. Listeners must - * not change this field. - */ - public ValueDiff diff; - - /** - * Creates a new value change event. - * - * @param source - * the source observable value - * @param diff - * the value change - */ - public ValueChangeEvent(IObservableValue source, ValueDiff diff) { - super(source); - this.diff = diff; - } - - /** - * Returns the observable value from which this event originated. - * - * @return returns the observable value from which this event originated - */ - public IObservableValue getObservableValue() { - return (IObservableValue) source; - } - - protected void dispatch(IObservablesListener listener) { - ((IValueChangeListener) listener).handleValueChange(this); - } - - protected Object getListenerType() { - return TYPE; - } - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/ValueChangingEvent.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/ValueChangingEvent.java deleted file mode 100644 index f92cde7b..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/ValueChangingEvent.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.databinding.observable.value; - -import org.eclipse.core.databinding.observable.IObservablesListener; -import org.eclipse.core.databinding.observable.ObservableEvent; - -/** - * Value changing event describing a pending change of an - * {@link IObservableValue} object's current value. Listeners can veto the - * pending change by setting {@link #veto} to <code>true</code>. - * - * @since 1.0 - * - */ -public class ValueChangingEvent extends ObservableEvent { - - /** - * - */ - private static final long serialVersionUID = 2305345286999701156L; - - static final Object TYPE = new Object(); - - /** - * Description of the change to the source observable value. Listeners must - * not change this field. - */ - public ValueDiff diff; - - /** - * Flag for vetoing this change. Default value is <code>false</code>, can - * be set to <code>true</code> by listeners to veto this change. - */ - public boolean veto = false; - - /** - * Creates a new value changing event. - * - * @param source - * the source observable value - * @param diff - * the value change - */ - public ValueChangingEvent(IObservableValue source, ValueDiff diff) { - super(source); - this.diff = diff; - } - - /** - * @return the observable value from which this event originated - */ - public IObservableValue getObservableValue() { - return (IObservableValue) source; - } - - protected void dispatch(IObservablesListener listener) { - ((IValueChangingListener) listener).handleValueChanging(this); - } - - protected Object getListenerType() { - return TYPE; - } - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/ValueDiff.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/ValueDiff.java deleted file mode 100644 index 62a2f866..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/ValueDiff.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.value; - -import org.eclipse.core.databinding.observable.Diffs; - -/** - * @since 1.0 - * - */ -public abstract class ValueDiff { - /** - * Creates a value diff. - */ - public ValueDiff() { - } - - /** - * @return the old value - */ - public abstract Object getOldValue(); - - /** - * @return the new value - */ - public abstract Object getNewValue(); - - public boolean equals(Object obj) { - if (obj instanceof ValueDiff) { - ValueDiff val = (ValueDiff) obj; - - return Diffs.equals(val.getNewValue(), getNewValue()) - && Diffs.equals(val.getOldValue(), getOldValue()); - - } - return false; - } - - public int hashCode() { - final int prime = 31; - int result = 1; - Object nv = getNewValue(); - Object ov = getOldValue(); - result = prime * result + ((nv == null) ? 0 : nv.hashCode()); - result = prime * result + ((ov == null) ? 0 : ov.hashCode()); - return result; - } - - /** - * @see java.lang.Object#toString() - */ - public String toString() { - StringBuffer buffer = new StringBuffer(); - buffer - .append(getClass().getName()) - .append("{oldValue [") //$NON-NLS-1$ - .append(getOldValue() != null ? getOldValue().toString() : "null") //$NON-NLS-1$ - .append("], newValue [") //$NON-NLS-1$ - .append(getNewValue() != null ? getNewValue().toString() : "null") //$NON-NLS-1$ - .append("]}"); //$NON-NLS-1$ - - return buffer.toString(); - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/WritableValue.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/WritableValue.java deleted file mode 100644 index 5d794f1a..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/WritableValue.java +++ /dev/null @@ -1,113 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 158687 - * Brad Reynolds - bug 164653, 147515 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.value; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; - -/** - * Mutable (writable) implementation of {@link IObservableValue} that will maintain a value and fire - * change events when the value changes. - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * @since 1.0 - */ -public class WritableValue extends AbstractObservableValue { - - private final Object valueType; - - /** - * Constructs a new instance with the default realm, a <code>null</code> - * value type, and a <code>null</code> value. - */ - public WritableValue() { - this(null, null); - } - - /** - * Constructs a new instance with the default realm. - * - * @param initialValue - * can be <code>null</code> - * @param valueType - * can be <code>null</code> - */ - public WritableValue(Object initialValue, Object valueType) { - this(Realm.getDefault(), initialValue, valueType); - } - - /** - * Constructs a new instance with the provided <code>realm</code>, a - * <code>null</code> value type, and a <code>null</code> initial value. - * - * @param realm - */ - public WritableValue(Realm realm) { - this(realm, null, null); - } - - /** - * Constructs a new instance. - * - * @param realm - * @param initialValue - * can be <code>null</code> - * @param valueType - * can be <code>null</code> - */ - public WritableValue(Realm realm, Object initialValue, Object valueType) { - super(realm); - this.valueType = valueType; - this.value = initialValue; - } - - private Object value = null; - - public Object doGetValue() { - return value; - } - - /** - * @param value - * The value to set. - */ - public void doSetValue(Object value) { - boolean changed = false; - - if (this.value == null && value != null) { - changed = true; - } else if (this.value != null && !this.value.equals(value)) { - changed = true; - } - - if (changed) { - fireValueChange(Diffs.createValueDiff(this.value, this.value = value)); - } - } - - public Object getValueType() { - return valueType; - } - - /** - * @param elementType can be <code>null</code> - * @return new instance with the default realm and a value of <code>null</code> - */ - public static WritableValue withValueType(Object elementType) { - return new WritableValue(Realm.getDefault(), null, elementType); - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/package.html b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/package.html deleted file mode 100644 index 4ce13df5..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/package.html +++ /dev/null @@ -1,16 +0,0 @@ -<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> - <meta name="Author" content="IBM"> - <meta name="GENERATOR" content="Mozilla/4.5 [en] (Win98; I) [Netscape]"> - <title>Package-level Javadoc</title> -</head> -<body> -Provides classes that can be used to observe changes in discrete values. -<h2> -Package Specification</h2> -<p> -This package provides classes that can be used to observe changes in discrete values.</p> -</body> -</html> diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/util/ILogger.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/util/ILogger.java deleted file mode 100644 index 652d7193..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/util/ILogger.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Chris Gross (schtoo@schtoo.com) - initial API and implementation - * (bug 49497 [RCP] JFace dependency on org.eclipse.core.runtime enlarges standalone JFace applications) - *******************************************************************************/ - -package org.eclipse.core.databinding.util; - -import org.eclipse.core.runtime.IStatus; - -/** - * A mechanism to log errors throughout JFace Data Binding. - * <p> - * Clients may provide their own implementation to change how errors are logged - * from within JFace Data Binding. - * </p> - * - * @see Policy#getLog() - * @see Policy#setLog(ILogger) - * @since 1.1 - */ -public interface ILogger { - - /** - * Logs the given status. - * - * @param status - * the status to log - */ - public void log(IStatus status); - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/util/Policy.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/util/Policy.java deleted file mode 100644 index 45467ba2..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/util/Policy.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Chris Gross (schtoo@schtoo.com) - support for ILogger added - * (bug 49497 [RCP] JFace dependency on org.eclipse.core.runtime enlarges standalone JFace applications) - * Brad Reynolds - bug 164653 - * Tom Schindl <tom.schindl@bestsolution.at> - bug 194587 - *******************************************************************************/ -package org.eclipse.core.databinding.util; - -import org.eclipse.core.runtime.IStatus; - -/** - * The Policy class handles settings for behaviour, debug flags and logging - * within JFace Data Binding. - * - * @since 1.1 - */ -public class Policy { - - /** - * Constant for the the default setting for debug options. - */ - public static final boolean DEFAULT = false; - - /** - * The unique identifier of the JFace plug-in. - */ - public static final String JFACE_DATABINDING = "org.eclipse.core.databinding";//$NON-NLS-1$ - - private static ILogger log; - - /** - * Returns the dummy log to use if none has been set - */ - private static ILogger getDummyLog() { - return new ILogger() { - public void log(IStatus status) { - System.err.println(status.getPlugin() + " - " + status.getCode() + " - " + status.getMessage()); //$NON-NLS-1$//$NON-NLS-2$ - if( status.getException() != null ) { - status.getException().printStackTrace(System.err); - } - } - }; - } - - /** - * Sets the logger used by JFace Data Binding to log errors. - * - * @param logger - * the logger to use, or <code>null</code> to use the default - * logger - */ - public static synchronized void setLog(ILogger logger) { - log = logger; - } - - /** - * Returns the logger used by JFace Data Binding to log errors. - * <p> - * The default logger prints the status to <code>System.err</code>. - * </p> - * - * @return the logger - */ - public static synchronized ILogger getLog() { - if (log == null) { - log = getDummyLog(); - } - return log; - } - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/util/package.html b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/util/package.html deleted file mode 100644 index 0b186a7b..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/util/package.html +++ /dev/null @@ -1,16 +0,0 @@ -<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> - <meta name="Author" content="IBM"> - <meta name="GENERATOR" content="Mozilla/4.5 [en] (Win98; I) [Netscape]"> - <title>Package-level Javadoc</title> -</head> -<body> -Provides general utilities for data binding. -<h2> -Package Specification</h2> -<p> -This package provides general utilities for data binding.</p> -</body> -</html> diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/ConstantObservableValue.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/ConstantObservableValue.java deleted file mode 100644 index f143efb5..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/ConstantObservableValue.java +++ /dev/null @@ -1,110 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007-2008 Matt Carter 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: - * Matt Carter - initial API and implementation (bug 212518) - * Matthew Hall - bug 212518 - *******************************************************************************/ -package org.eclipse.core.internal.databinding.observable; - -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.runtime.Assert; - -/** - * An immutable {@link IObservableValue}. - * - * @see WritableValue - */ -public class ConstantObservableValue implements IObservableValue { - final Realm realm; - final Object value; - final Object type; - - /** - * Construct a constant value of the given type, in the default realm. - * - * @param value - * immutable value - * @param type - * type - */ - public ConstantObservableValue(Object value, Object type) { - this(Realm.getDefault(), value, type); - } - - /** - * Construct a constant value of the given type, in the given realm. - * - * @param realm - * Realm - * @param value - * immutable value - * @param type - * type - */ - public ConstantObservableValue(Realm realm, Object value, Object type) { - Assert.isNotNull(realm, "Realm cannot be null"); //$NON-NLS-1$ - this.realm = realm; - this.value = value; - this.type = type; - } - - public Object getValueType() { - return type; - } - - public Object getValue() { - ObservableTracker.getterCalled(this); - return value; - } - - public void setValue(Object value) { - throw new UnsupportedOperationException(); - } - - public void addValueChangeListener(IValueChangeListener listener) { - // ignore - } - - public void removeValueChangeListener(IValueChangeListener listener) { - // ignore - } - - public void addChangeListener(IChangeListener listener) { - // ignore - } - - public void addStaleListener(IStaleListener listener) { - // ignore - } - - public void dispose() { - // nothing to dispose - } - - public Realm getRealm() { - return realm; - } - - public boolean isStale() { - return false; - } - - public void removeChangeListener(IChangeListener listener) { - // ignore - } - - public void removeStaleListener(IStaleListener listener) { - // ignore - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/EmptyObservableList.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/EmptyObservableList.java deleted file mode 100644 index 1b53b34b..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/EmptyObservableList.java +++ /dev/null @@ -1,224 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 208858 - * Matthew Hall - bug 208332 - *******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable; - -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IListChangeListener; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.runtime.Assert; - -/** - * Singleton empty list - */ -public class EmptyObservableList implements IObservableList { - - private static final List emptyList = Collections.EMPTY_LIST; - - private Realm realm; - private Object elementType; - - /** - * Creates an empty list. This list may be disposed multiple times - * without any side-effects. - * - * @param realm - * the realm of the constructed list - */ - public EmptyObservableList(Realm realm) { - this(realm, null); - } - - /** - * Creates an empty list. This list may be disposed multiple times - * without any side-effects. - * - * @param realm - * the realm of the constructed list - * @param elementType - * the element type of the constructed list - * @since 1.1 - */ - public EmptyObservableList(Realm realm, Object elementType) { - this.realm = realm; - this.elementType = elementType; - } - - public void addListChangeListener(IListChangeListener listener) { - // ignore - } - - public void removeListChangeListener(IListChangeListener listener) { - // ignore - } - - public Object getElementType() { - return elementType; - } - - public int size() { - checkRealm(); - return 0; - } - - void checkRealm() { - Assert.isTrue(realm.isCurrent(), - "Observable cannot be accessed outside its realm"); //$NON-NLS-1$ - } - - public boolean isEmpty() { - checkRealm(); - return true; - } - - public boolean contains(Object o) { - checkRealm(); - return false; - } - - public Iterator iterator() { - checkRealm(); - return emptyList.iterator(); - } - - public Object[] toArray() { - checkRealm(); - return emptyList.toArray(); - } - - public Object[] toArray(Object[] a) { - return emptyList.toArray(a); - } - - public boolean add(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean containsAll(Collection c) { - checkRealm(); - return c.isEmpty(); - } - - public boolean addAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - throw new UnsupportedOperationException(); - } - - public void addChangeListener(IChangeListener listener) { - } - - public void removeChangeListener(IChangeListener listener) { - } - - public void addStaleListener(IStaleListener listener) { - } - - public void removeStaleListener(IStaleListener listener) { - } - - public boolean isStale() { - checkRealm(); - return false; - } - - public void dispose() { - } - - public boolean addAll(int index, Collection c) { - throw new UnsupportedOperationException(); - } - - public Object get(int index) { - return emptyList.get(index); - } - - public int indexOf(Object o) { - return -1; - } - - public int lastIndexOf(Object o) { - return -1; - } - - public ListIterator listIterator() { - return emptyList.listIterator(); - } - - public ListIterator listIterator(int index) { - return emptyList.listIterator(index); - } - - public Object remove(int index) { - throw new UnsupportedOperationException(); - } - - public Object set(int index, Object element) { - throw new UnsupportedOperationException(); - } - - public Object move(int oldIndex, int newIndex) { - throw new UnsupportedOperationException(); - } - - public List subList(int fromIndex, int toIndex) { - return emptyList.subList(fromIndex, toIndex); - } - - public void add(int index, Object o) { - throw new UnsupportedOperationException(); - } - - public Realm getRealm() { - return realm; - } - - public boolean equals(Object obj) { - checkRealm(); - if (obj == this) - return true; - if (obj == null) - return false; - if (!(obj instanceof List)) - return false; - - return ((List) obj).isEmpty(); - } - - public int hashCode() { - checkRealm(); - return 1; - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/EmptyObservableSet.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/EmptyObservableSet.java deleted file mode 100644 index dab53c49..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/EmptyObservableSet.java +++ /dev/null @@ -1,176 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 208332 - *******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable; - -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.ISetChangeListener; -import org.eclipse.core.runtime.Assert; - -/** - * Singleton empty set - */ -public class EmptyObservableSet implements IObservableSet { - - private static final Set emptySet = Collections.EMPTY_SET; - - private Realm realm; - private Object elementType; - - /** - * Creates a singleton empty set. This set may be disposed multiple times - * without any side-effects. - * - * @param realm - * the realm of the constructed set - */ - public EmptyObservableSet(Realm realm) { - this(realm, null); - } - - /** - * Creates a singleton empty set. This set may be disposed multiple times - * without any side-effects. - * - * @param realm - * the realm of the constructed set - * @param elementType - * the element type of the constructed set - * @since 1.1 - */ - public EmptyObservableSet(Realm realm, Object elementType) { - this.realm = realm; - this.elementType = elementType; - } - - public void addSetChangeListener(ISetChangeListener listener) { - } - - public void removeSetChangeListener(ISetChangeListener listener) { - } - - public Object getElementType() { - return elementType; - } - - public int size() { - checkRealm(); - return 0; - } - - private void checkRealm() { - Assert.isTrue(realm.isCurrent(), - "Observable cannot be accessed outside its realm"); //$NON-NLS-1$ - } - - public boolean isEmpty() { - checkRealm(); - return true; - } - - public boolean contains(Object o) { - checkRealm(); - return false; - } - - public Iterator iterator() { - checkRealm(); - return emptySet.iterator(); - } - - public Object[] toArray() { - checkRealm(); - return emptySet.toArray(); - } - - public Object[] toArray(Object[] a) { - return emptySet.toArray(a); - } - - public boolean add(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean containsAll(Collection c) { - checkRealm(); - return c.isEmpty(); - } - - public boolean addAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - throw new UnsupportedOperationException(); - } - - public void addChangeListener(IChangeListener listener) { - } - - public void removeChangeListener(IChangeListener listener) { - } - - public void addStaleListener(IStaleListener listener) { - } - - public void removeStaleListener(IStaleListener listener) { - } - - public boolean isStale() { - checkRealm(); - return false; - } - - public void dispose() { - } - - public Realm getRealm() { - return realm; - } - - public boolean equals(Object obj) { - checkRealm(); - if (obj == this) - return true; - if (obj == null) - return false; - if (!(obj instanceof Set)) - return false; - - return ((Set) obj).isEmpty(); - } - - public int hashCode() { - checkRealm(); - return 0; - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/IStalenessConsumer.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/IStalenessConsumer.java deleted file mode 100644 index cfe5c612..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/IStalenessConsumer.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable; - -/** - * @since 1.0 - * - */ -public interface IStalenessConsumer { - /** - * @param stale - * - */ - public void setStale(boolean stale); -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/MapEntryObservableValue.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/MapEntryObservableValue.java deleted file mode 100644 index 3340eb6e..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/MapEntryObservableValue.java +++ /dev/null @@ -1,109 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Marko Topolnik 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: - * Marko Topolnik - initial API and implementation (bug 184830) - * Matthew Hall - bug 184830 - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.databinding.observable.map.IMapChangeListener; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.map.MapChangeEvent; -import org.eclipse.core.databinding.observable.value.AbstractObservableValue; -import org.eclipse.core.databinding.observable.value.IObservableValue; - -/** - * An {@link IObservableValue} that tracks the value of an entry in an - * {@link IObservableMap}, identified by the entry's key. - * - * @since 1.1 - */ -public class MapEntryObservableValue extends AbstractObservableValue { - private IObservableMap map; - private Object key; - private Object valueType; - - private IMapChangeListener changeListener = new IMapChangeListener() { - public void handleMapChange(final MapChangeEvent event) { - if (event.diff.getAddedKeys().contains(key)) { - final Object newValue = event.diff.getNewValue(key); - if (newValue != null) { - fireValueChange(Diffs.createValueDiff(null, newValue)); - } - } else if (event.diff.getChangedKeys().contains(key)) { - fireValueChange(Diffs.createValueDiff(event.diff - .getOldValue(key), event.diff.getNewValue(key))); - } else if (event.diff.getRemovedKeys().contains(key)) { - final Object oldValue = event.diff.getOldValue(key); - if (oldValue != null) { - fireValueChange(Diffs.createValueDiff(oldValue, null)); - } - } - } - }; - - private IStaleListener staleListener = new IStaleListener() { - public void handleStale(StaleEvent staleEvent) { - fireStale(); - } - }; - - /** - * Creates a map entry observable. - * - * @param map - * the observable map whose entry will be tracked - * @param key - * the key identifying the entry whose value will be tracked - * @param valueType - * the type of the value - */ - public MapEntryObservableValue(IObservableMap map, Object key, - Object valueType) { - super(map.getRealm()); - this.map = map; - this.key = key; - this.valueType = valueType; - - map.addMapChangeListener(changeListener); - map.addStaleListener(staleListener); - } - - public Object getValueType() { - return this.valueType; - } - - public boolean isStale() { - ObservableTracker.getterCalled(this); - return map.isStale(); - } - - public synchronized void dispose() { - if (map != null) { - map.removeMapChangeListener(changeListener); - map.removeStaleListener(staleListener); - map = null; - changeListener = null; - staleListener = null; - } - super.dispose(); - } - - protected Object doGetValue() { - return this.map.get(this.key); - } - - protected void doSetValue(Object value) { - this.map.put(this.key, value); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/ProxyObservableList.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/ProxyObservableList.java deleted file mode 100644 index 6d15f2c5..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/ProxyObservableList.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 208332) - * IBM Corporation - initial API and implementation - * (through ProxyObservableSet.java) - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable; - -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.databinding.observable.list.*; - -/** - * Wraps an observable list. This object acts like an exact copy of the original - * list, and tracks all the changes in the original. The only difference is that - * disposing the wrapper will not dispose the original. You can use this - * whenever you need to return an IObservableList from a method that expects the - * caller to dispose the list, but you have an IObservableList that you don't - * want disposed. - * - * @since 1.1 - */ -public class ProxyObservableList extends ObservableList { - private IListChangeListener listChangelistener = new IListChangeListener() { - public void handleListChange(ListChangeEvent event) { - fireListChange(event.diff); - } - }; - - private IStaleListener staleListener = new IStaleListener() { - public void handleStale(StaleEvent event) { - fireStale(); - } - }; - - private IObservableList wrappedList; - - /** - * Constructs a ProxyObservableList that tracks the state of the given list. - * - * @param wrappedList - * the list being wrapped - */ - public ProxyObservableList(IObservableList wrappedList) { - super(wrappedList.getRealm(), wrappedList, wrappedList.getElementType()); - this.wrappedList = wrappedList; - wrappedList.addListChangeListener(listChangelistener); - wrappedList.addStaleListener(staleListener); - } - - public boolean isStale() { - getterCalled(); - return wrappedList == null ? false : wrappedList.isStale(); - } - - public void dispose() { - if (wrappedList != null) { - wrappedList.removeListChangeListener(listChangelistener); - listChangelistener = null; - wrappedList.removeStaleListener(staleListener); - staleListener = null; - wrappedList = null; - } - super.dispose(); - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/ProxyObservableSet.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/ProxyObservableSet.java deleted file mode 100644 index 55a0b24c..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/ProxyObservableSet.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 208332 - *******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable; - -import java.util.Collections; -import java.util.Set; - -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.databinding.observable.set.AbstractObservableSet; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.ISetChangeListener; -import org.eclipse.core.databinding.observable.set.SetChangeEvent; - -/** - * Wraps an observable set. This object acts like an exact copy of the original - * set, and tracks all the changes in the original. The only difference is that - * disposing the wrapper will not dispose the original. You can use this - * whenever you need to return an IObservableSet from a method that expects the - * caller to dispose the set, but you have an IObservableSet that you don't want - * disposed. - */ -public class ProxyObservableSet extends AbstractObservableSet { - private IObservableSet wrappedSet; - private Object elementType; - - private ISetChangeListener setChangeListener = new ISetChangeListener() { - public void handleSetChange(SetChangeEvent event) { - fireSetChange(event.diff); - } - }; - - private IStaleListener staleListener = new IStaleListener() { - public void handleStale(StaleEvent staleEvent) { - fireStale(); - } - }; - - /** - * Constructs a ProxyObservableSet that tracks the state of the given set. - * - * @param wrappedSet - * the set being wrapped - */ - public ProxyObservableSet(IObservableSet wrappedSet) { - super(wrappedSet.getRealm()); - this.wrappedSet = wrappedSet; - this.elementType = wrappedSet.getElementType(); - wrappedSet.addSetChangeListener(setChangeListener); - wrappedSet.addStaleListener(staleListener); - } - - protected Set getWrappedSet() { - return wrappedSet == null ? Collections.EMPTY_SET : wrappedSet; - } - - public Object getElementType() { - return elementType; - } - - public boolean isStale() { - getterCalled(); - return wrappedSet == null ? false : wrappedSet.isStale(); - } - - public void dispose() { - if (wrappedSet != null) { - wrappedSet.removeSetChangeListener(setChangeListener); - setChangeListener = null; - wrappedSet.removeStaleListener(staleListener); - staleListener = null; - wrappedSet = null; - } - elementType = null; - super.dispose(); - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/StalenessObservableValue.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/StalenessObservableValue.java deleted file mode 100644 index 6a07fad3..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/StalenessObservableValue.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Boris Bokowski, IBM Corporation - initial API and implementation - * Matthew Hall - bug 212468 - *******************************************************************************/ -package org.eclipse.core.internal.databinding.observable; - -import org.eclipse.core.databinding.observable.ChangeEvent; -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.databinding.observable.value.AbstractObservableValue; - -/** - * An observable value that tracks the staleness of an {@link IObservable}. - * - * @since 1.1 - */ -public class StalenessObservableValue extends AbstractObservableValue { - - private class MyListener implements IChangeListener, IStaleListener { - public void handleChange(ChangeEvent event) { - if (stale && !event.getObservable().isStale()) { - stale = false; - fireValueChange(Diffs.createValueDiff(Boolean.TRUE, - Boolean.FALSE)); - } - } - - public void handleStale(StaleEvent staleEvent) { - if (!stale) { - stale = true; - fireValueChange(Diffs.createValueDiff(Boolean.FALSE, - Boolean.TRUE)); - } - } - } - - private IObservable tracked; - private boolean stale; - private MyListener listener = new MyListener(); - - /** - * Constructs a StalenessObservableValue that tracks the staleness of the - * given {@link IObservable}. - * - * @param observable - * the observable to track - */ - public StalenessObservableValue(IObservable observable) { - super(observable.getRealm()); - this.tracked = observable; - this.stale = observable.isStale(); - tracked.addChangeListener(listener); - tracked.addStaleListener(listener); - } - - protected Object doGetValue() { - return tracked.isStale() ? Boolean.TRUE : Boolean.FALSE; - } - - public Object getValueType() { - return Boolean.TYPE; - } - - public synchronized void dispose() { - if (tracked != null) { - tracked.removeChangeListener(listener); - tracked.removeStaleListener(listener); - tracked = null; - listener = null; - } - super.dispose(); - } - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/StalenessTracker.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/StalenessTracker.java deleted file mode 100644 index 6324325e..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/StalenessTracker.java +++ /dev/null @@ -1,127 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable; - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.databinding.observable.ChangeEvent; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.internal.databinding.IdentityWrapper; - -/** - * @since 1.0 - * - */ -public class StalenessTracker { - - private Map staleMap = new HashMap(); - - private int staleCount = 0; - - private final IStalenessConsumer stalenessConsumer; - - private class ChildListener implements IStaleListener, IChangeListener { - public void handleStale(StaleEvent event) { - processStalenessChange((IObservable) event.getSource(), true); - } - - public void handleChange(ChangeEvent event) { - processStalenessChange((IObservable) event.getSource(), true); - } - } - - private ChildListener childListener = new ChildListener(); - - /** - * @param observables - * @param stalenessConsumer - */ - public StalenessTracker(IObservable[] observables, - IStalenessConsumer stalenessConsumer) { - this.stalenessConsumer = stalenessConsumer; - for (int i = 0; i < observables.length; i++) { - IObservable observable = observables[i]; - doAddObservable(observable, false); - } - stalenessConsumer.setStale(staleCount > 0); - } - - /** - * @param child - * @param callback - */ - public void processStalenessChange(IObservable child, boolean callback) { - boolean oldStale = staleCount > 0; - IdentityWrapper wrappedChild = new IdentityWrapper(child); - boolean oldChildStale = getOldChildStale(wrappedChild); - boolean newChildStale = child.isStale(); - if (oldChildStale != newChildStale) { - if (oldChildStale) { - staleCount--; - } else { - staleCount++; - } - staleMap.put(wrappedChild, newChildStale ? Boolean.TRUE : Boolean.FALSE); - } - boolean newStale = staleCount > 0; - if (callback && (newStale != oldStale)) { - stalenessConsumer.setStale(newStale); - } - } - - /** - * @param wrappedChild - */ - private boolean getOldChildStale(IdentityWrapper wrappedChild) { - Object oldChildValue = staleMap.get(wrappedChild); - boolean oldChildStale = oldChildValue == null ? false - : ((Boolean) oldChildValue).booleanValue(); - return oldChildStale; - } - - /** - * @param observable - */ - public void addObservable(IObservable observable) { - doAddObservable(observable, true); - } - - private void doAddObservable(IObservable observable, boolean callback) { - processStalenessChange(observable, callback); - observable.addChangeListener(childListener); - observable.addStaleListener(childListener); - } - - /** - * @param observable - */ - public void removeObservable(IObservable observable) { - boolean oldStale = staleCount > 0; - IdentityWrapper wrappedChild = new IdentityWrapper(observable); - boolean oldChildStale = getOldChildStale(wrappedChild); - if (oldChildStale) { - staleCount--; - } - staleMap.remove(wrappedChild); - observable.removeChangeListener(childListener); - observable.removeStaleListener(childListener); - boolean newStale = staleCount > 0; - if (newStale != oldStale) { - stalenessConsumer.setStale(newStale); - } - } - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/UnmodifiableObservableList.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/UnmodifiableObservableList.java deleted file mode 100644 index 6f34e1eb..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/UnmodifiableObservableList.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006-2008 Cerner Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bug 208332 - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable; - -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.databinding.observable.list.IListChangeListener; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.ListChangeEvent; -import org.eclipse.core.databinding.observable.list.ObservableList; - -/** - * ObservableList implementation that prevents modification by consumers. Events - * in the originating wrapped list are propagated and thrown from this instance - * when appropriate. All mutators throw an UnsupportedOperationException. - * - * @since 1.0 - */ -/* - * Implementation makes the assumption that the superclass (ObservableList) is - * unmodifiable and that all modify methods throw an - * UnsupportedOperationException. - */ -public class UnmodifiableObservableList extends ObservableList { - /** - * List that is being made unmodifiable. - */ - private IObservableList wrappedList; - - private IListChangeListener listChangeListener = new IListChangeListener() { - public void handleListChange(ListChangeEvent event) { - // Fires a Change and then ListChange event. - fireListChange(event.diff); - } - }; - - private IStaleListener staleListener = new IStaleListener() { - public void handleStale(StaleEvent event) { - fireStale(); - } - }; - - /** - * @param wrappedList - */ - public UnmodifiableObservableList(IObservableList wrappedList) { - super(wrappedList.getRealm(), wrappedList, wrappedList.getElementType()); - this.wrappedList = wrappedList; - - wrappedList.addListChangeListener(listChangeListener); - - wrappedList.addStaleListener(staleListener); - } - - /** - * Because this instance is immutable staleness cannot be changed. - * - * @throws UnsupportedOperationException - * because this instance is unmodifiable. - */ - public void setStale(boolean stale) { - throw new UnsupportedOperationException(); - } - - public boolean isStale() { - getterCalled(); - return wrappedList == null ? false : wrappedList.isStale(); - } - - public synchronized void dispose() { - if (wrappedList != null) { - wrappedList.removeListChangeListener(listChangeListener); - wrappedList.removeStaleListener(staleListener); - wrappedList = null; - } - listChangeListener = null; - staleListener = null; - super.dispose(); - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/UnmodifiableObservableSet.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/UnmodifiableObservableSet.java deleted file mode 100644 index ee38b252..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/UnmodifiableObservableSet.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 208332) - * Brad Reynolds - initial API and implementation - * (through UnmodifiableObservableList.java) - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable; - -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.databinding.observable.set.*; - -/** - * ObservableList implementation that prevents modification by consumers. Events - * in the originating wrapped list are propagated and thrown from this instance - * when appropriate. All mutators throw an UnsupportedOperationException. - * - * @since 1.1 - */ -public class UnmodifiableObservableSet extends ObservableSet { - private ISetChangeListener setChangeListener = new ISetChangeListener() { - public void handleSetChange(SetChangeEvent event) { - fireSetChange(event.diff); - } - }; - - private IStaleListener staleListener = new IStaleListener() { - public void handleStale(StaleEvent event) { - fireStale(); - } - }; - - private IObservableSet wrappedSet; - - /** - * @param wrappedSet - */ - public UnmodifiableObservableSet(IObservableSet wrappedSet) { - super(wrappedSet.getRealm(), wrappedSet, wrappedSet.getElementType()); - - this.wrappedSet = wrappedSet; - - wrappedSet.addSetChangeListener(setChangeListener); - wrappedSet.addStaleListener(staleListener); - } - - /** - * Because this instance is immutable staleness cannot be changed. - */ - public void setStale(boolean stale) { - throw new UnsupportedOperationException(); - } - - public boolean isStale() { - getterCalled(); - return wrappedSet == null ? false : wrappedSet.isStale(); - } - - public synchronized void dispose() { - if (wrappedSet != null) { - wrappedSet.removeSetChangeListener(setChangeListener); - wrappedSet.removeStaleListener(staleListener); - wrappedSet = null; - } - setChangeListener = null; - staleListener = null; - super.dispose(); - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/UnmodifiableObservableValue.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/UnmodifiableObservableValue.java deleted file mode 100644 index e35712c3..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/UnmodifiableObservableValue.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 219909) - * Matthew Hall - bug 237884 - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable; - -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.databinding.observable.value.AbstractObservableValue; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.observable.value.ValueChangeEvent; - -/** - * An unmodifiable wrapper class for IObservableValue instances. - * @since 1.1 - */ -public class UnmodifiableObservableValue extends AbstractObservableValue { - private IObservableValue wrappedValue; - - /** - * Constructs an UnmodifiableObservableValue which wraps the given - * observable value - * - * @param wrappedValue - * the observable value to wrap in an unmodifiable instance. - */ - public UnmodifiableObservableValue(IObservableValue wrappedValue) { - super(wrappedValue.getRealm()); - - this.wrappedValue = wrappedValue; - wrappedValue.addValueChangeListener(new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - fireValueChange(event.diff); - } - }); - wrappedValue.addStaleListener(new IStaleListener() { - public void handleStale(StaleEvent staleEvent) { - fireStale(); - } - }); - } - - protected Object doGetValue() { - return wrappedValue.getValue(); - } - - public Object getValueType() { - return wrappedValue.getValueType(); - } - - public boolean isStale() { - return wrappedValue.isStale(); - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/ValidatedObservableList.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/ValidatedObservableList.java deleted file mode 100644 index c1fa4612..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/ValidatedObservableList.java +++ /dev/null @@ -1,393 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 218269) - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.databinding.observable.list.IListChangeListener; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.ListChangeEvent; -import org.eclipse.core.databinding.observable.list.ListDiff; -import org.eclipse.core.databinding.observable.list.ListDiffEntry; -import org.eclipse.core.databinding.observable.list.ListDiffVisitor; -import org.eclipse.core.databinding.observable.list.ObservableList; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.observable.value.ValueChangeEvent; -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.IStatus; - -/** - * @since 3.3 - * - */ -public class ValidatedObservableList extends ObservableList { - private IObservableList target; - private IObservableValue validationStatus; - - // Only true when out of sync with target due to validation status - private boolean stale; - - // True when validaton status changes from invalid to valid. - private boolean computeNextDiff = false; - - private boolean updatingTarget = false; - - private IListChangeListener targetChangeListener = new IListChangeListener() { - public void handleListChange(ListChangeEvent event) { - if (updatingTarget) - return; - IStatus status = (IStatus) validationStatus.getValue(); - if (isValid(status)) { - if (stale) { - // this.stale means we are out of sync with target, - // so reset wrapped list to exactly mirror target - stale = false; - updateWrappedList(new ArrayList(target)); - } else { - ListDiff diff = event.diff; - if (computeNextDiff) { - diff = Diffs.computeListDiff(wrappedList, target); - computeNextDiff = false; - } - applyDiff(diff, wrappedList); - fireListChange(diff); - } - } else { - makeStale(); - } - } - }; - - private static boolean isValid(IStatus status) { - return status.isOK() || status.matches(IStatus.INFO | IStatus.WARNING); - } - - private IStaleListener targetStaleListener = new IStaleListener() { - public void handleStale(StaleEvent staleEvent) { - fireStale(); - } - }; - - private IValueChangeListener validationStatusChangeListener = new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - IStatus oldStatus = (IStatus) event.diff.getOldValue(); - IStatus newStatus = (IStatus) event.diff.getNewValue(); - if (stale && !isValid(oldStatus) && isValid(newStatus)) { - // this.stale means we are out of sync with target, - // reset wrapped list to exactly mirror target - stale = false; - updateWrappedList(new ArrayList(target)); - - // If the validation status becomes valid because of a change in - // target observable - computeNextDiff = true; - } - } - }; - - /** - * @param target - * @param validationStatus - */ - public ValidatedObservableList(final IObservableList target, - final IObservableValue validationStatus) { - super(target.getRealm(), new ArrayList(target), target.getElementType()); - Assert.isNotNull(validationStatus, - "Validation status observable cannot be null"); //$NON-NLS-1$ - Assert - .isTrue(target.getRealm().equals(validationStatus.getRealm()), - "Target and validation status observables must be on the same realm"); //$NON-NLS-1$ - this.target = target; - this.validationStatus = validationStatus; - target.addListChangeListener(targetChangeListener); - target.addStaleListener(targetStaleListener); - validationStatus.addValueChangeListener(validationStatusChangeListener); - } - - private void makeStale() { - if (!stale) { - stale = true; - fireStale(); - } - } - - private void updateTargetList(ListDiff diff) { - updatingTarget = true; - try { - if (stale) { - stale = false; - applyDiff(Diffs.computeListDiff(target, wrappedList), target); - } else { - applyDiff(diff, target); - } - } finally { - updatingTarget = false; - } - } - - private void applyDiff(ListDiff diff, final List list) { - diff.accept(new ListDiffVisitor() { - public void handleAdd(int index, Object element) { - list.add(index, element); - } - - public void handleRemove(int index, Object element) { - list.remove(index); - } - - public void handleReplace(int index, Object oldElement, - Object newElement) { - list.set(index, newElement); - } - }); - } - - public boolean isStale() { - ObservableTracker.getterCalled(this); - return stale || target.isStale(); - } - - public void add(int index, Object element) { - checkRealm(); - wrappedList.add(index, element); - ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry(index, - true, element)); - updateTargetList(diff); - fireListChange(diff); - } - - public boolean add(Object o) { - checkRealm(); - add(wrappedList.size(), o); - return true; - } - - public boolean addAll(Collection c) { - checkRealm(); - return addAll(wrappedList.size(), c); - } - - public boolean addAll(int index, Collection c) { - checkRealm(); - Object[] elements = c.toArray(); - ListDiffEntry[] entries = new ListDiffEntry[elements.length]; - for (int i = 0; i < elements.length; i++) { - wrappedList.add(index + i, elements[i]); - entries[i] = Diffs - .createListDiffEntry(index + i, true, elements[i]); - } - ListDiff diff = Diffs.createListDiff(entries); - updateTargetList(diff); - fireListChange(diff); - return true; - } - - public void clear() { - checkRealm(); - if (isEmpty()) - return; - ListDiff diff = Diffs.computeListDiff(wrappedList, - Collections.EMPTY_LIST); - wrappedList.clear(); - updateTargetList(diff); - fireListChange(diff); - } - - public Iterator iterator() { - getterCalled(); - final ListIterator wrappedIterator = wrappedList.listIterator(); - return new Iterator() { - Object last = null; - - public boolean hasNext() { - return wrappedIterator.hasNext(); - } - - public Object next() { - return last = wrappedIterator.next(); - } - - public void remove() { - int index = wrappedIterator.previousIndex(); - wrappedIterator.remove(); - ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry( - index, false, last)); - updateTargetList(diff); - fireListChange(diff); - } - }; - } - - public ListIterator listIterator() { - return listIterator(0); - } - - public ListIterator listIterator(int index) { - getterCalled(); - final ListIterator wrappedIterator = wrappedList.listIterator(index); - return new ListIterator() { - int lastIndex = -1; - Object last = null; - - public void add(Object o) { - wrappedIterator.add(o); - lastIndex = previousIndex(); - ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry( - lastIndex, true, o)); - updateTargetList(diff); - fireListChange(diff); - } - - public boolean hasNext() { - return wrappedIterator.hasNext(); - } - - public boolean hasPrevious() { - return wrappedIterator.hasPrevious(); - } - - public Object next() { - last = wrappedIterator.next(); - lastIndex = previousIndex(); - return last; - } - - public int nextIndex() { - return wrappedIterator.nextIndex(); - } - - public Object previous() { - last = wrappedIterator.previous(); - lastIndex = nextIndex(); - return last; - } - - public int previousIndex() { - return wrappedIterator.previousIndex(); - } - - public void remove() { - wrappedIterator.remove(); - ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry( - lastIndex, false, last)); - lastIndex = -1; - updateTargetList(diff); - fireListChange(diff); - } - - public void set(Object o) { - wrappedIterator.set(o); - ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry( - lastIndex, false, last), Diffs.createListDiffEntry( - lastIndex, true, o)); - last = o; - updateTargetList(diff); - fireListChange(diff); - } - }; - } - - public Object move(int oldIndex, int newIndex) { - checkRealm(); - int size = wrappedList.size(); - if (oldIndex >= size) - throw new IndexOutOfBoundsException( - "oldIndex: " + oldIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$ - if (newIndex >= size) - throw new IndexOutOfBoundsException( - "newIndex: " + newIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$ - if (oldIndex == newIndex) - return wrappedList.get(oldIndex); - Object element = wrappedList.remove(oldIndex); - wrappedList.add(newIndex, element); - ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry( - oldIndex, false, element), Diffs.createListDiffEntry(newIndex, - true, element)); - updateTargetList(diff); - fireListChange(diff); - return element; - } - - public Object remove(int index) { - checkRealm(); - Object element = wrappedList.remove(index); - ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry(index, - false, element)); - updateTargetList(diff); - fireListChange(diff); - return element; - } - - public boolean remove(Object o) { - checkRealm(); - int index = wrappedList.indexOf(o); - if (index == -1) - return false; - remove(index); - return true; - } - - public boolean removeAll(Collection c) { - checkRealm(); - List list = new ArrayList(wrappedList); - boolean changed = list.removeAll(c); - if (changed) { - ListDiff diff = Diffs.computeListDiff(wrappedList, list); - wrappedList = list; - updateTargetList(diff); - fireListChange(diff); - } - return changed; - } - - public boolean retainAll(Collection c) { - checkRealm(); - List list = new ArrayList(wrappedList); - boolean changed = list.retainAll(c); - if (changed) { - ListDiff diff = Diffs.computeListDiff(wrappedList, list); - wrappedList = list; - updateTargetList(diff); - fireListChange(diff); - } - return changed; - } - - public Object set(int index, Object element) { - checkRealm(); - Object oldElement = wrappedList.set(index, element); - ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry(index, - false, oldElement), Diffs.createListDiffEntry(index, true, - element)); - updateTargetList(diff); - fireListChange(diff); - return oldElement; - } - - public synchronized void dispose() { - target.removeListChangeListener(targetChangeListener); - target.removeStaleListener(targetStaleListener); - validationStatus - .removeValueChangeListener(validationStatusChangeListener); - super.dispose(); - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/ValidatedObservableMap.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/ValidatedObservableMap.java deleted file mode 100644 index 1261f69c..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/ValidatedObservableMap.java +++ /dev/null @@ -1,228 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 218269) - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.databinding.observable.map.IMapChangeListener; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.map.MapChangeEvent; -import org.eclipse.core.databinding.observable.map.MapDiff; -import org.eclipse.core.databinding.observable.map.ObservableMap; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.observable.value.ValueChangeEvent; -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.IStatus; - -/** - * @since 3.3 - * - */ -public class ValidatedObservableMap extends ObservableMap { - private IObservableMap target; - private IObservableValue validationStatus; - - // Only true when out of sync with target due to validation status - private boolean stale; - - // True when validation status changes from invalid to valid. - private boolean computeNextDiff = false; - - private boolean updatingTarget = false; - - private IMapChangeListener targetChangeListener = new IMapChangeListener() { - public void handleMapChange(MapChangeEvent event) { - if (updatingTarget) - return; - IStatus status = (IStatus) validationStatus.getValue(); - if (isValid(status)) { - if (stale) { - // this.stale means we are out of sync with target, - // so reset wrapped list to exactly mirror target - stale = false; - updateWrappedMap(new HashMap(target)); - } else { - MapDiff diff = event.diff; - if (computeNextDiff) { - diff = Diffs.computeMapDiff(wrappedMap, target); - computeNextDiff = false; - } - applyDiff(diff, wrappedMap); - fireMapChange(diff); - } - } else { - makeStale(); - } - } - }; - - private IStaleListener targetStaleListener = new IStaleListener() { - public void handleStale(StaleEvent staleEvent) { - fireStale(); - } - }; - - private IValueChangeListener validationStatusChangeListener = new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - IStatus oldStatus = (IStatus) event.diff.getOldValue(); - IStatus newStatus = (IStatus) event.diff.getNewValue(); - if (stale && !isValid(oldStatus) && isValid(newStatus)) { - // this.stale means we are out of sync with target, - // reset wrapped map to exactly mirror target - stale = false; - updateWrappedMap(new HashMap(target)); - - // If the validation status becomes valid because of a change in - // target observable - computeNextDiff = true; - } - } - }; - - /** - * @param target - * @param validationStatus - */ - public ValidatedObservableMap(final IObservableMap target, - final IObservableValue validationStatus) { - super(target.getRealm(), new HashMap(target)); - Assert.isNotNull(validationStatus, - "Validation status observable cannot be null"); //$NON-NLS-1$ - Assert - .isTrue(target.getRealm().equals(validationStatus.getRealm()), - "Target and validation status observables must be on the same realm"); //$NON-NLS-1$ - this.target = target; - this.validationStatus = validationStatus; - target.addMapChangeListener(targetChangeListener); - target.addStaleListener(targetStaleListener); - validationStatus.addValueChangeListener(validationStatusChangeListener); - } - - private void updateWrappedMap(Map newMap) { - Map oldMap = wrappedMap; - MapDiff diff = Diffs.computeMapDiff(oldMap, newMap); - wrappedMap = newMap; - fireMapChange(diff); - } - - private static boolean isValid(IStatus status) { - return status.isOK() || status.matches(IStatus.INFO | IStatus.WARNING); - } - - private void applyDiff(MapDiff diff, Map map) { - for (Iterator iterator = diff.getRemovedKeys().iterator(); iterator - .hasNext();) - map.remove(iterator.next()); - for (Iterator iterator = diff.getChangedKeys().iterator(); iterator - .hasNext();) { - Object key = iterator.next(); - map.put(key, diff.getNewValue(key)); - } - for (Iterator iterator = diff.getAddedKeys().iterator(); iterator - .hasNext();) { - Object key = iterator.next(); - map.put(key, diff.getNewValue(key)); - } - } - - private void makeStale() { - if (!stale) { - stale = true; - fireStale(); - } - } - - private void updateTargetMap(MapDiff diff) { - updatingTarget = true; - try { - if (stale) { - stale = false; - applyDiff(Diffs.computeMapDiff(target, wrappedMap), target); - } else { - applyDiff(diff, target); - } - } finally { - updatingTarget = false; - } - } - - public boolean isStale() { - getterCalled(); - return stale || target.isStale(); - } - - public void clear() { - checkRealm(); - if (isEmpty()) - return; - MapDiff diff = Diffs.computeMapDiff(wrappedMap, Collections.EMPTY_MAP); - wrappedMap = new HashMap(); - updateTargetMap(diff); - fireMapChange(diff); - } - - public Object put(Object key, Object value) { - checkRealm(); - MapDiff diff; - Object oldValue; - if (wrappedMap.containsKey(key)) { - oldValue = wrappedMap.put(key, value); - if (wrappedMap.containsKey(key)) { // Changed - diff = Diffs.createMapDiffSingleChange(key, oldValue, value); - } else { // Removed - diff = Diffs.createMapDiffSingleRemove(key, oldValue); - } - } else { // Added - oldValue = wrappedMap.put(key, value); - diff = Diffs.createMapDiffSingleAdd(key, value); - } - updateTargetMap(diff); - fireMapChange(diff); - return oldValue; - } - - public void putAll(Map m) { - checkRealm(); - Map map = new HashMap(wrappedMap); - map.putAll(m); - MapDiff diff = Diffs.computeMapDiff(wrappedMap, map); - wrappedMap = map; - updateTargetMap(diff); - fireMapChange(diff); - } - - public Object remove(Object key) { - checkRealm(); - if (!wrappedMap.containsKey(key)) - return null; - Object oldValue = wrappedMap.remove(key); - MapDiff diff = Diffs.createMapDiffSingleRemove(key, oldValue); - updateTargetMap(diff); - fireMapChange(diff); - return oldValue; - } - - public synchronized void dispose() { - target.removeMapChangeListener(targetChangeListener); - target.removeStaleListener(targetStaleListener); - validationStatus - .removeValueChangeListener(validationStatusChangeListener); - super.dispose(); - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/ValidatedObservableSet.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/ValidatedObservableSet.java deleted file mode 100644 index bb7c6e68..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/ValidatedObservableSet.java +++ /dev/null @@ -1,270 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 218269) - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.ISetChangeListener; -import org.eclipse.core.databinding.observable.set.ObservableSet; -import org.eclipse.core.databinding.observable.set.SetChangeEvent; -import org.eclipse.core.databinding.observable.set.SetDiff; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.observable.value.ValueChangeEvent; -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.IStatus; - -/** - * @since 3.3 - * - */ -public class ValidatedObservableSet extends ObservableSet { - private IObservableSet target; - private IObservableValue validationStatus; - - // Only true when out of sync with target due to validation status - private boolean stale; - - // True when validation status changes from invalid to valid. - private boolean computeNextDiff = false; - - private boolean updatingTarget = false; - - private ISetChangeListener targetChangeListener = new ISetChangeListener() { - public void handleSetChange(SetChangeEvent event) { - if (updatingTarget) - return; - IStatus status = (IStatus) validationStatus.getValue(); - if (isValid(status)) { - if (stale) { - // this.stale means we are out of sync with target, - // so reset wrapped list to exactly mirror target - stale = false; - updateWrappedSet(new HashSet(target)); - } else { - SetDiff diff = event.diff; - if (computeNextDiff) { - diff = Diffs.computeSetDiff(wrappedSet, target); - computeNextDiff = false; - } - applyDiff(diff, wrappedSet); - fireSetChange(diff); - } - } else { - makeStale(); - } - } - }; - - private IStaleListener targetStaleListener = new IStaleListener() { - public void handleStale(StaleEvent staleEvent) { - fireStale(); - } - }; - - private IValueChangeListener validationStatusChangeListener = new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - IStatus oldStatus = (IStatus) event.diff.getOldValue(); - IStatus newStatus = (IStatus) event.diff.getNewValue(); - if (stale && !isValid(oldStatus) && isValid(newStatus)) { - // this.stale means we are out of sync with target, - // reset wrapped set to exactly mirror target - stale = false; - updateWrappedSet(new HashSet(target)); - - // If the validation status becomes valid because of a change in - // target observable - computeNextDiff = true; - } - } - }; - - /** - * @param target - * @param validationStatus - */ - public ValidatedObservableSet(final IObservableSet target, - final IObservableValue validationStatus) { - super(target.getRealm(), new HashSet(target), target.getElementType()); - Assert.isNotNull(validationStatus, - "Validation status observable cannot be null"); //$NON-NLS-1$ - Assert - .isTrue(target.getRealm().equals(validationStatus.getRealm()), - "Target and validation status observables must be on the same realm"); //$NON-NLS-1$ - this.target = target; - this.validationStatus = validationStatus; - target.addSetChangeListener(targetChangeListener); - target.addStaleListener(targetStaleListener); - validationStatus.addValueChangeListener(validationStatusChangeListener); - } - - private void updateWrappedSet(Set newSet) { - Set oldSet = wrappedSet; - SetDiff diff = Diffs.computeSetDiff(oldSet, newSet); - wrappedSet = newSet; - fireSetChange(diff); - } - - private static boolean isValid(IStatus status) { - return status.isOK() || status.matches(IStatus.INFO | IStatus.WARNING); - } - - private void applyDiff(SetDiff diff, Set set) { - for (Iterator iterator = diff.getRemovals().iterator(); iterator - .hasNext();) { - set.remove(iterator.next()); - } - for (Iterator iterator = diff.getAdditions().iterator(); iterator - .hasNext();) { - set.add(iterator.next()); - } - } - - private void makeStale() { - if (!stale) { - stale = true; - fireStale(); - } - } - - private void updateTargetSet(SetDiff diff) { - updatingTarget = true; - try { - if (stale) { - stale = false; - applyDiff(Diffs.computeSetDiff(target, wrappedSet), target); - } else { - applyDiff(diff, target); - } - } finally { - updatingTarget = false; - } - } - - public boolean isStale() { - getterCalled(); - return stale || target.isStale(); - } - - public boolean add(Object o) { - getterCalled(); - boolean changed = wrappedSet.add(o); - if (changed) { - SetDiff diff = Diffs.createSetDiff(Collections.singleton(o), - Collections.EMPTY_SET); - updateTargetSet(diff); - fireSetChange(diff); - } - return changed; - } - - public boolean addAll(Collection c) { - getterCalled(); - HashSet set = new HashSet(wrappedSet); - boolean changed = set.addAll(c); - if (changed) { - SetDiff diff = Diffs.computeSetDiff(wrappedSet, set); - wrappedSet = set; - updateTargetSet(diff); - fireSetChange(diff); - } - return changed; - } - - public void clear() { - getterCalled(); - if (isEmpty()) - return; - SetDiff diff = Diffs.createSetDiff(Collections.EMPTY_SET, wrappedSet); - wrappedSet = new HashSet(); - updateTargetSet(diff); - fireSetChange(diff); - } - - public Iterator iterator() { - getterCalled(); - final Iterator wrappedIterator = wrappedSet.iterator(); - return new Iterator() { - Object last = null; - - public boolean hasNext() { - return wrappedIterator.hasNext(); - } - - public Object next() { - return last = wrappedIterator.next(); - } - - public void remove() { - wrappedIterator.remove(); - SetDiff diff = Diffs.createSetDiff(Collections.EMPTY_SET, - Collections.singleton(last)); - updateTargetSet(diff); - fireSetChange(diff); - } - }; - } - - public boolean remove(Object o) { - getterCalled(); - boolean changed = wrappedSet.remove(o); - if (changed) { - SetDiff diff = Diffs.createSetDiff(Collections.EMPTY_SET, - Collections.singleton(o)); - updateTargetSet(diff); - fireSetChange(diff); - } - return changed; - } - - public boolean removeAll(Collection c) { - getterCalled(); - Set set = new HashSet(wrappedSet); - boolean changed = set.removeAll(c); - if (changed) { - SetDiff diff = Diffs.computeSetDiff(wrappedSet, set); - wrappedSet = set; - updateTargetSet(diff); - fireSetChange(diff); - } - return changed; - } - - public boolean retainAll(Collection c) { - getterCalled(); - Set set = new HashSet(wrappedSet); - boolean changed = set.retainAll(c); - if (changed) { - SetDiff diff = Diffs.computeSetDiff(wrappedSet, set); - wrappedSet = set; - updateTargetSet(diff); - fireSetChange(diff); - } - return changed; - } - - public synchronized void dispose() { - target.removeSetChangeListener(targetChangeListener); - target.removeStaleListener(targetStaleListener); - validationStatus - .removeValueChangeListener(validationStatusChangeListener); - super.dispose(); - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/ValidatedObservableValue.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/ValidatedObservableValue.java deleted file mode 100644 index 1164f539..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/ValidatedObservableValue.java +++ /dev/null @@ -1,170 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 218269) - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.databinding.observable.value.AbstractObservableValue; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.observable.value.IVetoableValue; -import org.eclipse.core.databinding.observable.value.ValueChangeEvent; -import org.eclipse.core.databinding.observable.value.ValueChangingEvent; -import org.eclipse.core.internal.databinding.Util; -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.IStatus; - -/** - * An {@link IObservableValue} wrapper that stays in sync with the target - * observable as long as a given validation status is valid. - * <ul> - * <li>While status is valid, ValidatedObservableValue stays in sync with its - * target. - * <li>When status becomes invalid, ValidatedObservableValue will retain the - * last valid value of its target. - * <li>While status is invalid, changes in the target observable cause - * ValidatedObservableValue to fire a stale event, to indicate that changes are - * pending. - * <li>When status becomes valid, pending value changes are performed (if any) - * and synchronization resumes. - * </ul> - * <p> - * Note: - * <ul> - * <li>By default, a status is valid if its - * {@link IStatus#getSeverity() severity} is {@link IStatus#OK OK}, - * {@link IStatus#INFO INFO}, or {@link IStatus#WARNING WARNING} - * <li>Calls to {@link #setValue(Object)} on the validated observable changes - * the value regardless of the validation status. - * <li>This class will not forward {@link ValueChangingEvent} events from a - * wrapped {@link IVetoableValue}. - * </ul> - * - * @since 1.2 - */ -public class ValidatedObservableValue extends AbstractObservableValue { - private IObservableValue target; - private IObservableValue validationStatus; - - private Object cachedValue; - private boolean stale; - private boolean updatingTarget = false; - - private IValueChangeListener targetChangeListener = new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - if (updatingTarget) - return; - IStatus status = (IStatus) validationStatus.getValue(); - if (isValid(status)) - internalSetValue(event.diff.getNewValue(), false); - else - makeStale(); - } - }; - - private static boolean isValid(IStatus status) { - return status.isOK() || status.matches(IStatus.INFO | IStatus.WARNING); - } - - private IStaleListener targetStaleListener = new IStaleListener() { - public void handleStale(StaleEvent staleEvent) { - fireStale(); - } - }; - - private IValueChangeListener validationStatusChangeListener = new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - IStatus oldStatus = (IStatus) event.diff.getOldValue(); - IStatus newStatus = (IStatus) event.diff.getNewValue(); - if (stale && !isValid(oldStatus) && isValid(newStatus)) { - internalSetValue(target.getValue(), false); - } - } - }; - - /** - * Constructs an observable value - * - * @param target - * the observable value to be wrapped - * @param validationStatus - * an observable value of type {@link IStatus}.class which - * contains the current validation status - */ - public ValidatedObservableValue(IObservableValue target, - IObservableValue validationStatus) { - super(target.getRealm()); - Assert.isNotNull(validationStatus, - "Validation status observable cannot be null"); //$NON-NLS-1$ - Assert - .isTrue(target.getRealm().equals(validationStatus.getRealm()), - "Target and validation status observables must be on the same realm"); //$NON-NLS-1$ - this.target = target; - this.validationStatus = validationStatus; - this.cachedValue = target.getValue(); - - target.addValueChangeListener(targetChangeListener); - target.addStaleListener(targetStaleListener); - validationStatus.addValueChangeListener(validationStatusChangeListener); - } - - private void makeStale() { - if (!stale) { - stale = true; - fireStale(); - } - } - - public boolean isStale() { - ObservableTracker.getterCalled(this); - return stale || target.isStale(); - } - - protected Object doGetValue() { - return cachedValue; - } - - private void internalSetValue(Object value, boolean updateTarget) { - Object oldValue = cachedValue; - cachedValue = value; - if (updateTarget) { - updatingTarget = true; - try { - target.setValue(value); - cachedValue = target.getValue(); - } finally { - updatingTarget = false; - } - } - stale = false; - if (!Util.equals(oldValue, cachedValue)) - fireValueChange(Diffs.createValueDiff(oldValue, cachedValue)); - } - - protected void doSetValue(Object value) { - internalSetValue(value, true); - } - - public Object getValueType() { - return target.getValueType(); - } - - public synchronized void dispose() { - target.removeValueChangeListener(targetChangeListener); - target.removeStaleListener(targetStaleListener); - validationStatus - .removeValueChangeListener(validationStatusChangeListener); - super.dispose(); - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/masterdetail/DetailObservableList.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/masterdetail/DetailObservableList.java deleted file mode 100755 index 1baec566..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/masterdetail/DetailObservableList.java +++ /dev/null @@ -1,175 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005-2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 147515 - * Matthew Hall - bug 221351 - *******************************************************************************/ -package org.eclipse.core.internal.databinding.observable.masterdetail; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IObserving; -import org.eclipse.core.databinding.observable.list.IListChangeListener; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.ListChangeEvent; -import org.eclipse.core.databinding.observable.list.ObservableList; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.observable.value.ValueChangeEvent; -import org.eclipse.core.runtime.Assert; - -/** - * @since 3.2 - * - */ - -public class DetailObservableList extends ObservableList implements IObserving { - - private boolean updating = false; - - private IListChangeListener innerChangeListener = new IListChangeListener() { - public void handleListChange(ListChangeEvent event) { - if (!updating) { - fireListChange(event.diff); - } - } - }; - - private Object currentOuterValue; - - private IObservableList innerObservableList; - - private IObservableFactory factory; - - private IObservableValue outerObservableValue; - - private Object detailType; - - /** - * @param factory - * @param outerObservableValue - * @param detailType - */ - public DetailObservableList(IObservableFactory factory, - IObservableValue outerObservableValue, Object detailType) { - super(outerObservableValue.getRealm(), Collections.EMPTY_LIST, detailType); - this.factory = factory; - this.outerObservableValue = outerObservableValue; - this.detailType = detailType; - updateInnerObservableList(outerObservableValue); - - outerObservableValue.addValueChangeListener(outerChangeListener); - } - - IValueChangeListener outerChangeListener = new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - List oldList = new ArrayList(wrappedList); - updateInnerObservableList(outerObservableValue); - fireListChange(Diffs.computeListDiff(oldList, wrappedList)); - } - }; - - private void updateInnerObservableList(IObservableValue outerObservableValue) { - if (innerObservableList != null) { - innerObservableList.removeListChangeListener(innerChangeListener); - innerObservableList.dispose(); - } - currentOuterValue = outerObservableValue.getValue(); - if (currentOuterValue == null) { - innerObservableList = null; - wrappedList = Collections.EMPTY_LIST; - } else { - this.innerObservableList = (IObservableList) factory - .createObservable(currentOuterValue); - wrappedList = innerObservableList; - - if (detailType != null) { - Object innerValueType = innerObservableList.getElementType(); - Assert.isTrue(getElementType().equals(innerValueType), - "Cannot change value type in a nested observable list"); //$NON-NLS-1$ - } - innerObservableList.addListChangeListener(innerChangeListener); - } - } - - public boolean add(Object o) { - return wrappedList.add(o); - } - - public void add(int index, Object element) { - wrappedList.add(index, element); - } - - public boolean remove(Object o) { - return wrappedList.remove(o); - } - - public Object set(int index, Object element) { - return wrappedList.set(index, element); - } - - public Object move(int oldIndex, int newIndex) { - if (innerObservableList != null) - return innerObservableList.move(oldIndex, newIndex); - return super.move(oldIndex, newIndex); - } - - public Object remove(int index) { - return wrappedList.remove(index); - } - - public boolean addAll(Collection c) { - return wrappedList.addAll(c); - } - - public boolean addAll(int index, Collection c) { - return wrappedList.addAll(index, c); - } - - public boolean removeAll(Collection c) { - return wrappedList.removeAll(c); - } - - public boolean retainAll(Collection c) { - return wrappedList.retainAll(c); - } - - public void clear() { - wrappedList.clear(); - } - - public void dispose() { - super.dispose(); - - if (outerObservableValue != null) { - outerObservableValue.removeValueChangeListener(outerChangeListener); - outerObservableValue.dispose(); - } - if (innerObservableList != null) { - innerObservableList.removeListChangeListener(innerChangeListener); - innerObservableList.dispose(); - } - currentOuterValue = null; - factory = null; - innerObservableList = null; - innerChangeListener = null; - } - - public Object getObserved() { - if (innerObservableList instanceof IObserving) { - return ((IObserving) innerObservableList).getObserved(); - } - return null; - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/masterdetail/DetailObservableMap.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/masterdetail/DetailObservableMap.java deleted file mode 100644 index a57148c9..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/masterdetail/DetailObservableMap.java +++ /dev/null @@ -1,126 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 221704) - * Matthew Hall - bug 223114 - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable.masterdetail; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.map.IMapChangeListener; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.map.MapChangeEvent; -import org.eclipse.core.databinding.observable.map.ObservableMap; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.observable.value.ValueChangeEvent; - -/** - * @since 1.1 - * - */ -public class DetailObservableMap extends ObservableMap { - private boolean updating = false; - - private IObservableValue master; - private IObservableFactory detailFactory; - - private IObservableMap detailMap; - - private IValueChangeListener masterChangeListener = new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - Map oldMap = new HashMap(wrappedMap); - updateDetailMap(); - fireMapChange(Diffs.computeMapDiff(oldMap, wrappedMap)); - } - }; - - private IMapChangeListener detailChangeListener = new IMapChangeListener() { - public void handleMapChange(MapChangeEvent event) { - if (!updating) { - fireMapChange(event.diff); - } - } - }; - - /** - * Constructs a new DetailObservableMap - * - * @param detailFactory - * observable factory that creates IObservableMap instances given - * the current value of master observable value - * @param master - * - */ - public DetailObservableMap(IObservableFactory detailFactory, - IObservableValue master) { - super(master.getRealm(), Collections.EMPTY_MAP); - this.master = master; - this.detailFactory = detailFactory; - - updateDetailMap(); - master.addValueChangeListener(masterChangeListener); - } - - private void updateDetailMap() { - Object masterValue = master.getValue(); - if (detailMap != null) { - detailMap.removeMapChangeListener(detailChangeListener); - detailMap.dispose(); - } - - if (masterValue == null) { - detailMap = null; - wrappedMap = Collections.EMPTY_MAP; - } else { - detailMap = (IObservableMap) detailFactory - .createObservable(masterValue); - wrappedMap = detailMap; - detailMap.addMapChangeListener(detailChangeListener); - } - } - - public Object put(Object key, Object value) { - return detailMap.put(key, value); - } - - public void putAll(Map map) { - detailMap.putAll(map); - } - - public Object remove(Object key) { - return detailMap.remove(key); - } - - public void clear() { - detailMap.clear(); - } - - public synchronized void dispose() { - if (master != null) { - master.removeValueChangeListener(masterChangeListener); - master = null; - masterChangeListener = null; - } - detailFactory = null; - if (detailMap != null) { - detailMap.removeMapChangeListener(detailChangeListener); - detailMap.dispose(); - detailMap = null; - } - detailChangeListener = null; - super.dispose(); - } - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/masterdetail/DetailObservableSet.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/masterdetail/DetailObservableSet.java deleted file mode 100755 index dc0fc461..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/masterdetail/DetailObservableSet.java +++ /dev/null @@ -1,158 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005-2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 221351 - *******************************************************************************/ -package org.eclipse.core.internal.databinding.observable.masterdetail; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IObserving; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.ISetChangeListener; -import org.eclipse.core.databinding.observable.set.ObservableSet; -import org.eclipse.core.databinding.observable.set.SetChangeEvent; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.observable.value.ValueChangeEvent; -import org.eclipse.core.runtime.Assert; - -/** - * @since 3.2 - * - */ -public class DetailObservableSet extends ObservableSet implements IObserving { - - private boolean updating = false; - - private ISetChangeListener innerChangeListener = new ISetChangeListener() { - public void handleSetChange(SetChangeEvent event) { - if (!updating) { - fireSetChange(event.diff); - } - } - }; - - private Object currentOuterValue; - - private IObservableSet innerObservableSet; - - private IObservableValue outerObservableValue; - - private IObservableFactory factory; - - /** - * @param factory - * @param outerObservableValue - * @param detailType - */ - public DetailObservableSet(IObservableFactory factory, - IObservableValue outerObservableValue, Object detailType) { - super(outerObservableValue.getRealm(), Collections.EMPTY_SET, - detailType); - this.factory = factory; - this.outerObservableValue = outerObservableValue; - updateInnerObservableSet(outerObservableValue); - - outerObservableValue.addValueChangeListener(outerChangeListener); - } - - IValueChangeListener outerChangeListener = new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - Set oldSet = new HashSet(wrappedSet); - updateInnerObservableSet(outerObservableValue); - fireSetChange(Diffs.computeSetDiff(oldSet, wrappedSet)); - } - }; - - private void updateInnerObservableSet(IObservableValue outerObservableValue) { - currentOuterValue = outerObservableValue.getValue(); - if (innerObservableSet != null) { - innerObservableSet.removeSetChangeListener(innerChangeListener); - innerObservableSet.dispose(); - } - if (currentOuterValue == null) { - innerObservableSet = null; - wrappedSet = Collections.EMPTY_SET; - } else { - this.innerObservableSet = (IObservableSet) factory - .createObservable(currentOuterValue); - wrappedSet = innerObservableSet; - - if (elementType != null) { - Object innerValueType = innerObservableSet.getElementType(); - - Assert.isTrue(elementType.equals(innerValueType), - "Cannot change value type in a nested observable set"); //$NON-NLS-1$ - } - - innerObservableSet.addSetChangeListener(innerChangeListener); - } - } - - public boolean add(Object o) { - getterCalled(); - return wrappedSet.add(o); - } - - public boolean remove(Object o) { - getterCalled(); - return wrappedSet.remove(o); - } - - public boolean addAll(Collection c) { - getterCalled(); - return wrappedSet.addAll(c); - } - - public boolean removeAll(Collection c) { - getterCalled(); - return wrappedSet.removeAll(c); - } - - public boolean retainAll(Collection c) { - getterCalled(); - return wrappedSet.retainAll(c); - } - - public void clear() { - getterCalled(); - wrappedSet.clear(); - } - - public void dispose() { - super.dispose(); - - if (outerObservableValue != null) { - outerObservableValue.removeValueChangeListener(outerChangeListener); - outerObservableValue.dispose(); - } - if (innerObservableSet != null) { - innerObservableSet.removeSetChangeListener(innerChangeListener); - innerObservableSet.dispose(); - } - currentOuterValue = null; - factory = null; - innerObservableSet = null; - innerChangeListener = null; - } - - public Object getObserved() { - if (innerObservableSet instanceof IObserving) { - return ((IObserving) innerObservableSet).getObserved(); - } - return null; - } - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/masterdetail/DetailObservableValue.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/masterdetail/DetailObservableValue.java deleted file mode 100755 index c1b1654d..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/masterdetail/DetailObservableValue.java +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - * Brad Reynolds - bug 147515 - *******************************************************************************/ -package org.eclipse.core.internal.databinding.observable.masterdetail; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IObserving; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.value.AbstractObservableValue; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.observable.value.ValueChangeEvent; -import org.eclipse.core.runtime.Assert; - -/** - * @since 1.0 - * - */ -public class DetailObservableValue extends AbstractObservableValue implements IObserving { - - private boolean updating = false; - - private IValueChangeListener innerChangeListener = new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - if (!updating) { - fireValueChange(event.diff); - } - } - }; - - private Object currentOuterValue; - - private IObservableValue innerObservableValue; - - private Object detailType; - - private IObservableValue outerObservableValue; - - private IObservableFactory factory; - - /** - * @param outerObservableValue - * @param factory - * @param detailType - */ - public DetailObservableValue(IObservableValue outerObservableValue, - IObservableFactory factory, Object detailType) { - super(outerObservableValue.getRealm()); - this.factory = factory; - this.detailType = detailType; - this.outerObservableValue = outerObservableValue; - updateInnerObservableValue(outerObservableValue); - - outerObservableValue.addValueChangeListener(outerChangeListener); - } - - IValueChangeListener outerChangeListener = new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - Object oldValue = doGetValue(); - updateInnerObservableValue(outerObservableValue); - fireValueChange(Diffs.createValueDiff(oldValue, doGetValue())); - } - }; - - private void updateInnerObservableValue( - IObservableValue outerObservableValue) { - currentOuterValue = outerObservableValue.getValue(); - if (innerObservableValue != null) { - innerObservableValue.removeValueChangeListener(innerChangeListener); - innerObservableValue.dispose(); - } - if (currentOuterValue == null) { - innerObservableValue = null; - } else { - this.innerObservableValue = (IObservableValue) factory - .createObservable(currentOuterValue); - Object innerValueType = innerObservableValue.getValueType(); - - if (detailType != null) { - Assert - .isTrue( - detailType.equals(innerValueType), - "Cannot change value type in a nested observable value, from " + innerValueType + " to " + detailType); //$NON-NLS-1$ //$NON-NLS-2$ - } - innerObservableValue.addValueChangeListener(innerChangeListener); - } - } - - public void doSetValue(Object value) { - if (innerObservableValue != null) - innerObservableValue.setValue(value); - } - - public Object doGetValue() { - return innerObservableValue == null ? null : innerObservableValue - .getValue(); - } - - public Object getValueType() { - return detailType; - } - - public void dispose() { - super.dispose(); - - if (outerObservableValue != null) { - outerObservableValue.removeValueChangeListener(outerChangeListener); - outerObservableValue.dispose(); - } - if (innerObservableValue != null) { - innerObservableValue.removeValueChangeListener(innerChangeListener); - innerObservableValue.dispose(); - } - currentOuterValue = null; - factory = null; - innerObservableValue = null; - innerChangeListener = null; - } - - public Object getObserved() { - if (innerObservableValue instanceof IObserving) { - return ((IObserving)innerObservableValue).getObserved(); - } - return null; - } - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/AbstractObservableTree.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/AbstractObservableTree.java deleted file mode 100644 index e1226c9d..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/AbstractObservableTree.java +++ /dev/null @@ -1,151 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164134 - *******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable.tree; - -import org.eclipse.core.databinding.observable.AbstractObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.util.Policy; -import org.eclipse.core.internal.databinding.BindingMessages; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.ListenerList; -import org.eclipse.core.runtime.Status; - -/** - * @since 3.3 - * - */ -public abstract class AbstractObservableTree extends AbstractObservable - implements IObservableTree { - - private boolean stale; - - private ListenerList treeListeners = new ListenerList(ListenerList.IDENTITY); - - /** - * @param realm - */ - public AbstractObservableTree(Realm realm) { - super(realm); - } - - public void addChild(TreePath parentPath, Object childElement) { - throw new UnsupportedOperationException(); - } - - public void addTreeChangeListener(ITreeChangeListener listener) { - treeListeners.add(listener); - } - - public int getChildCount(TreePath parentPath) { - return getChildren(parentPath).length; - } - - public boolean hasChildren(TreePath parentPath) { - return getChildCount(parentPath) > 0; - } - - public void insertChild(TreePath parentPath, int index, Object childElement) { - throw new UnsupportedOperationException(); - } - - public boolean isLazy() { - return false; - } - - public boolean isOrdered() { - return false; - } - - public void removeChild(TreePath parentPath, Object childElement) { - throw new UnsupportedOperationException(); - } - - public void removeChild(TreePath parentPath, int index) { - throw new UnsupportedOperationException(); - } - - public void removeTreeChangeListener(ITreeChangeListener listener) { - treeListeners.remove(listener); - } - - public void setChildCount(TreePath parentPath, int count) { - throw new UnsupportedOperationException(); - } - - public void setChildren(TreePath parentPath, Object[] children) { - throw new UnsupportedOperationException(); - } - - public void updateChildren(IChildrenUpdate update) { - TreePath parent = update.getParent(); - Object[] children = getChildren(parent); - for (int i = 0; i < update.getLength(); i++) { - int targetIndex = update.getOffset() + i; - if (targetIndex < children.length) { - update.setChild(children[targetIndex], targetIndex); - } else { - update - .setStatus(new Status( - IStatus.WARNING, - Policy.JFACE_DATABINDING, - IStatus.OK, - BindingMessages - .getString(BindingMessages.INDEX_OUT_OF_RANGE), - null)); - } - } - update.done(); - } - - public void updateChildrenCount(IChildrenCountUpdate update) { - TreePath[] parents = update.getParents(); - for (int i = 0; i < parents.length; i++) { - update.setChildCount(parents[i], getChildCount(parents[i])); - } - update.done(); - } - - public void updateHasChildren(IHasChildrenUpdate update) { - TreePath[] parents = update.getElements(); - for (int i = 0; i < parents.length; i++) { - update.setHasChilren(parents[i], hasChildren(parents[i])); - } - update.done(); - } - - public boolean isStale() { - return stale; - } - - /** - * @param stale - */ - public void setStale(boolean stale) { - this.stale = stale; - if (stale) { - fireStale(); - } - } - - protected void fireTreeChange(TreeDiff diff) { - // fire general change event first - fireChange(); - - Object[] listeners = treeListeners.getListeners(); - TreeChangeEvent event = new TreeChangeEvent(this, diff); - for (int i = 0; i < listeners.length; i++) { - ((ITreeChangeListener) listeners[i]).handleTreeChange(event); - } - } - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/IChildrenCountUpdate.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/IChildrenCountUpdate.java deleted file mode 100644 index 331176a9..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/IChildrenCountUpdate.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.core.internal.databinding.observable.tree; - -/** - * Request monitor used to collect the number of children for an element in a lazy - * observable tree. - * - * @since 3.3 - */ -public interface IChildrenCountUpdate extends IViewerUpdate { - - /** - * Returns the parent elements that children counts have been requested for - * as tree paths. An empty path identifies the root element. - * - * @return parent elements as tree paths - */ - public TreePath[] getParents(); - - /** - * Sets the number of children for the given parent. - * - * @param parentPath - * parent element or empty path for root element - * @param numChildren - * number of children - */ - public void setChildCount(TreePath parentPath, int numChildren); -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/IChildrenUpdate.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/IChildrenUpdate.java deleted file mode 100644 index 8d4b961e..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/IChildrenUpdate.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.core.internal.databinding.observable.tree; - -/** - * Context sensitive children update request for a parent and subrange of its - * children. - * - * @since 3.3 - */ -public interface IChildrenUpdate extends IViewerUpdate { - - /** - * Returns the parent element that children are being requested for - * as a tree path. An empty path identifies the root element. - * - * @return parent element as a tree path - */ - public TreePath getParent(); - - /** - * Returns the offset at which children have been requested for. This is - * the index of the first child being requested. - * - * @return offset at which children have been requested for - */ - public int getOffset(); - - /** - * Returns the number of children requested. - * - * @return number of children requested - */ - public int getLength(); - - /** - * Sets the child for this request's parent at the given offset. - * - * @param child child - * @param index child offset - * - * TODO: what to do with <code>null</code> - */ - public void setChild(Object child, int index); -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/IHasChildrenUpdate.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/IHasChildrenUpdate.java deleted file mode 100644 index f3eadd65..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/IHasChildrenUpdate.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.core.internal.databinding.observable.tree; - -/** - * Context sensitive update request for whether elements have children. - * - * @since 3.3 - */ -public interface IHasChildrenUpdate extends IViewerUpdate { - - /** - * The elements this request is for specified as tree paths. An empty path - * identifies the root element. - * - * @return elements as tree paths - */ - public TreePath[] getElements(); - - /** - * Sets whether the given element has children. - * - * @param element - * tree path to element, or empty for root element - * @param hasChildren - * whether it has children - */ - public void setHasChilren(TreePath element, boolean hasChildren); -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/IObservableTree.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/IObservableTree.java deleted file mode 100644 index a8774528..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/IObservableTree.java +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable.tree; - -import org.eclipse.core.databinding.observable.IObservable; - -/** - * - * A tree whose changes can be tracked by tree change listeners. If the tree is - * ordered ({@link #isOrdered()}), the order of children for a given tree path - * matters, and tree change notifications will always specify indices. If the - * tree is unordered, the children of a tree path are an unordered set and - * indices in change notifications are not specified. - * - * <p> - * This interface is not intended to be implemented by clients. Clients should - * instead subclass one of the framework classes that implement this interface. - * Note that direct implementers of this interface outside of the framework will - * be broken in future releases when methods are added to this interface. - * </p> - * - * @since 1.1 - */ -public interface IObservableTree extends IObservable { - - /** - * Element that can be returned from synchronous getters if this observable - * tree is lazy. - */ - public final static Object UNKNOWN_ELEMENT = new Object(); - - /** - * @param listener - */ - public void addTreeChangeListener(ITreeChangeListener listener); - - /** - * @param listener - */ - public void removeTreeChangeListener(ITreeChangeListener listener); - - /** - * Returns whether the order of children for a given parent is important. If - * this tree is ordered, tree change notifications will always specify - * indices. - * - * @return true if the order of children for a given parent is important - */ - public boolean isOrdered(); - - /** - * Returns whether this tree is optimized to fetch subsets of children - * lazily and possibly asynchronously. Implies {@link #isOrdered()}. - * - * @return true if this tree - */ - public boolean isLazy(); - - /** - * @param parentPath - * @return the children at the given parent path - */ - public Object[] getChildren(TreePath parentPath); - - /** - * @param parentPath - * @param children - */ - public void setChildren(TreePath parentPath, Object[] children); - - /** - * @param parentPath - * @param childElement - */ - public void addChild(TreePath parentPath, Object childElement); - - /** - * @param parentPath - * @param childElement - */ - public void removeChild(TreePath parentPath, Object childElement); - - /** - * @param parentPath - * @param index - * @param childElement - */ - public void insertChild(TreePath parentPath, int index, Object childElement); - - /** - * @param parentPath - * @param index - */ - public void removeChild(TreePath parentPath, int index); - - /** - * @param parentPath - * @return <code>true</code> if the element at the given path has children - */ - public boolean hasChildren(TreePath parentPath); - - /** - * @param parentPath - * @return the number of children of the element at the given path - */ - public int getChildCount(TreePath parentPath); - - /** - * @param parentPath - * @param count - */ - public void setChildCount(TreePath parentPath, int count); - - /** - * Updates the number of children for the given parent elements in the - * specified request. - * - * @param update specifies counts to update and stores result - */ - public void updateChildrenCount(IChildrenCountUpdate update); - - /** - * Updates children as requested by the update. - * - * @param update specifies children to update and stores result - */ - public void updateChildren(IChildrenUpdate update); - - /** - * Updates whether elements have children. - * - * @param update specifies elements to update and stores result - */ - public void updateHasChildren(IHasChildrenUpdate update); - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/IOrderedTreeProvider.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/IOrderedTreeProvider.java deleted file mode 100644 index f60d5611..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/IOrderedTreeProvider.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable.tree; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IObservableList; - -/** - * Objects that implement this interface are capable of describing a tree by - * returning the list of children of any given element in the tree. - * - * @since 3.3 - */ -public interface IOrderedTreeProvider { - /** - * Returns the children of the given element, or null if the element is a - * leaf node. The caller of this method is expected to dispose the result - * list when it is no longer needed. - * - * @param element - * the tree path of the element to query - * @return the children of the given element, or null if the element is a - * leaf node - */ - IObservableList createChildList(TreePath element); - - /** - * @return the realm shared by all child lists - */ - Realm getRealm(); -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/ITreeChangeListener.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/ITreeChangeListener.java deleted file mode 100644 index 8fe9f8f5..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/ITreeChangeListener.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable.tree; - -/** - * @since 3.3 - * - */ -public interface ITreeChangeListener { - /** - * @param event - */ - void handleTreeChange(TreeChangeEvent event); - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/IUnorderedTreeProvider.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/IUnorderedTreeProvider.java deleted file mode 100644 index 81941c80..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/IUnorderedTreeProvider.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable.tree; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.set.IObservableSet; - -/** - * @since 1.0 - * - */ -public interface IUnorderedTreeProvider { - /** - * @return the realm for the createChildSet method - */ - public Realm getRealm(); - - /** - * Returns the children of the given element, or null if the element is a leaf node. - * The caller of this method is expected to dispose the result set when it is no - * longer needed. - * - * @param element element to query - * @return the children of the given element, or null if the element is a leaf node - */ - IObservableSet createChildSet(Object element); -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/IViewerUpdate.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/IViewerUpdate.java deleted file mode 100644 index 26cadab4..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/IViewerUpdate.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.core.internal.databinding.observable.tree; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; - -/** - * A context sensitive viewer update request. - * - * @since 3.3 - */ -public interface IViewerUpdate extends IProgressMonitor { - - /** - * Sets the status of this request, possibly <code>null</code>. - * When a request fails, the status indicates why the request failed. - * A <code>null</code> status is considered to be successful. - * - * @param status request status - */ - public void setStatus(IStatus status); - - /** - * Returns the status of this request, or <code>null</code>. - * - * @return request status or <code>null</code> - */ - public IStatus getStatus(); - - /** - * Returns the model element corresponding to the given tree path. - * Returns the root element for the empty path. - * - * @param path viewer tree path - * @return corresponding model element - */ - public Object getElement(TreePath path); -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/TreeChangeEvent.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/TreeChangeEvent.java deleted file mode 100644 index b5051d5e..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/TreeChangeEvent.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable.tree; - -import java.util.EventObject; - -/** - * @since 3.3 - * - */ -public class TreeChangeEvent extends EventObject { - - /** - * - */ - private static final long serialVersionUID = -3198503763995528027L; - /** - * - */ - public TreeDiff diff; - - /** - * @param source - * @param diff - */ - public TreeChangeEvent(IObservableTree source, TreeDiff diff) { - super(source); - this.diff = diff; - } - - /** - * @return the observable tree from which this event originated - */ - public IObservableTree getObservable() { - return (IObservableTree) getSource(); - } - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/TreeDiff.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/TreeDiff.java deleted file mode 100644 index 7c419ea5..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/TreeDiff.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable.tree; - -/** - * Describes the difference between two trees as a tree of tree diff nodes. - * - * @since 1.1 - * - */ -public abstract class TreeDiff extends TreeDiffNode { - - /** - * Returns the tree path (possibly empty) of the parent, or - * <code>null</code> if the underlying tree is not lazy and never contains - * duplicate elements. - * - * @return the tree path (possibly empty) of the unchanged parent, or - * <code>null</code> - */ - public abstract TreePath getParentPath(); - - /** - * @param visitor - */ - public void accept(TreeDiffVisitor visitor) { - doAccept(visitor, getParentPath()); - } - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/TreeDiffNode.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/TreeDiffNode.java deleted file mode 100644 index a8b8b8d9..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/TreeDiffNode.java +++ /dev/null @@ -1,91 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable.tree; - -/** - * @since 1.1 - * - */ -public abstract class TreeDiffNode { - - /** - * - */ - public final static int NO_CHANGE = 0x00; - - /** - * - */ - public final static int ADDED = 0x01; - - /** - * - */ - public final static int REMOVED = 0x02; - - /** - * - */ - public final static int REPLACED = 0x03; - - /** - * - */ - public static final TreeDiffNode[] NO_CHILDREN = new TreeDiffNode[0]; - - /** - * - */ - public static final int INDEX_UNKNOWN = -1; - - /** - * @return the change type - */ - public abstract int getChangeType(); - - /** - * @return the element that was removed, or the replaced element - */ - public abstract Object getOldElement(); - - /** - * @return the element that was not changed, added, or the replacement - * element - */ - public abstract Object getNewElement(); - - /** - * @return the index at which the element was added, removed, or replaced - */ - public abstract int getIndex(); - - /** - * Returns the child tree diff objects that describe changes to children. If - * the change type is REMOVED, there will be no children. - * - * @return the nodes representing changes to children - */ - public abstract TreeDiffNode[] getChildren(); - - protected void doAccept(TreeDiffVisitor visitor, TreePath parentPath) { - TreePath currentPath = parentPath.createChildPath(getNewElement()); - boolean recurse = visitor.visit(this, currentPath); - if (recurse) { - TreeDiffNode[] children = getChildren(); - for (int i = 0; i < children.length; i++) { - TreeDiffNode child = children[i]; - child.doAccept(visitor, currentPath); - } - } - } - -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/TreeDiffVisitor.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/TreeDiffVisitor.java deleted file mode 100644 index 837464dc..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/TreeDiffVisitor.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable.tree; - -/** - * @since 3.3 - * - */ -public abstract class TreeDiffVisitor { - - /** - * Visits the given tree diff. - * - * @param diff - * the diff to visit - * @param currentPath - * the current path (the diff's element is the last segment of - * the path) - * - * @return <code>true</code> if the tree diff's children should be - * visited; <code>false</code> if they should be skipped. - */ - public abstract boolean visit(TreeDiffNode diff, TreePath currentPath); -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/TreePath.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/TreePath.java deleted file mode 100644 index 99e987c1..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/TreePath.java +++ /dev/null @@ -1,183 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 118516 - *******************************************************************************/ -package org.eclipse.core.internal.databinding.observable.tree; - -import org.eclipse.core.runtime.Assert; - -/** - * A tree path denotes a model element in a tree viewer. Tree path objects have - * value semantics. A model element is represented by a path of elements in the - * tree from the root element to the leaf element. - * <p> - * Clients may instantiate this class. Not intended to be subclassed. - * </p> - * - * @since 3.2 - */ -public final class TreePath { - - /** - * Constant for representing an empty tree path. - */ - public static final TreePath EMPTY = new TreePath(new Object[0]); - - private Object[] segments; - - private int hash; - - /** - * Constructs a path identifying a leaf node in a tree. - * - * @param segments - * path of elements to a leaf node in a tree, starting with the - * root element - */ - public TreePath(Object[] segments) { - Assert.isNotNull(segments, "Segments array cannot be null"); //$NON-NLS-1$ - this.segments = new Object[segments.length]; - for (int i = 0; i < segments.length; i++) { - Assert.isNotNull(segments[i], "Segments array cannot contain null"); //$NON-NLS-1$ - this.segments[i] = segments[i]; - } - } - - /** - * Returns the element at the specified index in this path. - * - * @param index - * index of element to return - * @return element at the specified index - */ - public Object getSegment(int index) { - return segments[index]; - } - - /** - * Returns the number of elements in this path. - * - * @return the number of elements in this path - */ - public int getSegmentCount() { - return segments.length; - } - - /** - * Returns the first element in this path. - * - * @return the first element in this path - */ - public Object getFirstSegment() { - if (segments.length == 0) { - return null; - } - return segments[0]; - } - - /** - * Returns the last element in this path. - * - * @return the last element in this path - */ - public Object getLastSegment() { - if (segments.length == 0) { - return null; - } - return segments[segments.length - 1]; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean equals(Object other) { - if (!(other instanceof TreePath)) { - return false; - } - TreePath otherPath = (TreePath) other; - if (segments.length != otherPath.segments.length) { - return false; - } - for (int i = 0; i < segments.length; i++) { - if (!segments[i].equals(otherPath.segments[i])) { - return false; - } - } - return true; - } - - public int hashCode() { - if (hash == 0) { - for (int i = 0; i < segments.length; i++) { - hash += segments[i].hashCode(); - } - } - return hash; - } - - /** - * Returns whether this path starts with the same segments as the given - * path, using the given comparer to compare segments. - * - * @param treePath - * path to compare to - * @return whether the given path is a prefix of this path, or the same as - * this path - */ - public boolean startsWith(TreePath treePath) { - int thisSegmentCount = getSegmentCount(); - int otherSegmentCount = treePath.getSegmentCount(); - if (otherSegmentCount == thisSegmentCount) { - return equals(treePath); - } - if (otherSegmentCount > thisSegmentCount) { - return false; - } - for (int i = 0; i < otherSegmentCount; i++) { - Object otherSegment = treePath.getSegment(i); - if (!otherSegment.equals(segments[i])) { - return false; - } - } - return true; - } - - /** - * Returns a copy of this tree path with one segment removed from the end, - * or <code>null</code> if this tree path has no segments. - * @return a tree path - */ - public TreePath getParentPath() { - int segmentCount = getSegmentCount(); - if (segmentCount <= 1) { - return null; - } - Object[] parentSegments = new Object[segmentCount - 1]; - System.arraycopy(segments, 0, parentSegments, 0, segmentCount - 1); - return new TreePath(parentSegments); - } - - /** - * Returns a copy of this tree path with the given segment added at the end. - * @param newSegment - * @return a tree path - */ - public TreePath createChildPath(Object newSegment) { - int segmentCount = getSegmentCount(); - Object[] childSegments = new Object[segmentCount + 1]; - if(segmentCount>0) { - System.arraycopy(segments, 0, childSegments, 0, segmentCount); - } - childSegments[segmentCount] = newSegment; - return new TreePath(childSegments); - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/package.html b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/package.html deleted file mode 100644 index d720e2b4..00000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/package.html +++ /dev/null @@ -1,16 +0,0 @@ -<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> - <meta name="Author" content="IBM"> - <meta name="GENERATOR" content="Mozilla/4.5 [en] (Win98; I) [Netscape]"> - <title>Package-level Javadoc</title> -</head> -<body> -To be written. -<h2> -Package Specification</h2> -<p> -This package provides classes that can be used to ...</p> -</body> -</html> diff --git a/bundles/org.eclipse.core.databinding/.classpath b/bundles/org.eclipse.core.databinding/.classpath deleted file mode 100644 index 6f3b481a..00000000 --- a/bundles/org.eclipse.core.databinding/.classpath +++ /dev/null @@ -1,7 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/CDC-1.1%Foundation-1.1"/> - <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> - <classpathentry kind="src" path="src"/> - <classpathentry kind="output" path="bin"/> -</classpath> diff --git a/bundles/org.eclipse.core.databinding/.cvsignore b/bundles/org.eclipse.core.databinding/.cvsignore deleted file mode 100644 index ba077a40..00000000 --- a/bundles/org.eclipse.core.databinding/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -bin diff --git a/bundles/org.eclipse.core.databinding/.project b/bundles/org.eclipse.core.databinding/.project deleted file mode 100644 index a52c8d98..00000000 --- a/bundles/org.eclipse.core.databinding/.project +++ /dev/null @@ -1,34 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<projectDescription> - <name>org.eclipse.core.databinding</name> - <comment></comment> - <projects> - </projects> - <buildSpec> - <buildCommand> - <name>org.eclipse.jdt.core.javabuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.ManifestBuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.SchemaBuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name> - <arguments> - </arguments> - </buildCommand> - </buildSpec> - <natures> - <nature>org.eclipse.pde.PluginNature</nature> - <nature>org.eclipse.jdt.core.javanature</nature> - <nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature> - </natures> -</projectDescription> diff --git a/bundles/org.eclipse.core.databinding/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.core.databinding/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index b9fdb95a..00000000 --- a/bundles/org.eclipse.core.databinding/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,353 +0,0 @@ -#Thu Apr 03 13:12:49 EDT 2008 -eclipse.preferences.version=1 -org.eclipse.jdt.core.builder.cleanOutputFolder=clean -org.eclipse.jdt.core.builder.duplicateResourceTask=warning -org.eclipse.jdt.core.builder.invalidClasspath=abort -org.eclipse.jdt.core.builder.recreateModifiedClassFileInOutputFolder=ignore -org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=*.launch -org.eclipse.jdt.core.circularClasspath=error -org.eclipse.jdt.core.classpath.exclusionPatterns=enabled -org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled -org.eclipse.jdt.core.codeComplete.argumentPrefixes= -org.eclipse.jdt.core.codeComplete.argumentSuffixes= -org.eclipse.jdt.core.codeComplete.fieldPrefixes= -org.eclipse.jdt.core.codeComplete.fieldSuffixes= -org.eclipse.jdt.core.codeComplete.localPrefixes= -org.eclipse.jdt.core.codeComplete.localSuffixes= -org.eclipse.jdt.core.codeComplete.staticFieldPrefixes= -org.eclipse.jdt.core.codeComplete.staticFieldSuffixes= -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.4 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.doc.comment.support=enabled -org.eclipse.jdt.core.compiler.maxProblemPerUnit=100 -org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.autoboxing=ignore -org.eclipse.jdt.core.compiler.problem.deprecation=warning -org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled -org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled -org.eclipse.jdt.core.compiler.problem.discouragedReference=error -org.eclipse.jdt.core.compiler.problem.emptyStatement=warning -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore -org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled -org.eclipse.jdt.core.compiler.problem.fieldHiding=warning -org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning -org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=error -org.eclipse.jdt.core.compiler.problem.forbiddenReference=error -org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=error -org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=error -org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore -org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=error -org.eclipse.jdt.core.compiler.problem.invalidJavadoc=error -org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled -org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled -org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled -org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=private -org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore -org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=error -org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore -org.eclipse.jdt.core.compiler.problem.missingJavadocComments=error -org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled -org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public -org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag -org.eclipse.jdt.core.compiler.problem.missingJavadocTags=error -org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled -org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=protected -org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore -org.eclipse.jdt.core.compiler.problem.missingSerialVersion=error -org.eclipse.jdt.core.compiler.problem.noEffectAssignment=error -org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=error -org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=error -org.eclipse.jdt.core.compiler.problem.nullReference=warning -org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=error -org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore -org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning -org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore -org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning -org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore -org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled -org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=error -org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled -org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore -org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning -org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning -org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore -org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning -org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning -org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning -org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=enabled -org.eclipse.jdt.core.compiler.problem.unusedImport=error -org.eclipse.jdt.core.compiler.problem.unusedLabel=error -org.eclipse.jdt.core.compiler.problem.unusedLocal=error -org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore -org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled -org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=enabled -org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=enabled -org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=error -org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning -org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -org.eclipse.jdt.core.compiler.source=1.3 -org.eclipse.jdt.core.formatter.align_type_members_on_columns=false -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16 -org.eclipse.jdt.core.formatter.alignment_for_assignment=0 -org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 -org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 -org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 -org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0 -org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 -org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 -org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16 -org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 -org.eclipse.jdt.core.formatter.blank_lines_after_imports=1 -org.eclipse.jdt.core.formatter.blank_lines_after_package=1 -org.eclipse.jdt.core.formatter.blank_lines_before_field=0 -org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0 -org.eclipse.jdt.core.formatter.blank_lines_before_imports=1 -org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1 -org.eclipse.jdt.core.formatter.blank_lines_before_method=1 -org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1 -org.eclipse.jdt.core.formatter.blank_lines_before_package=0 -org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1 -org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1 -org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line -org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false -org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false -org.eclipse.jdt.core.formatter.comment.format_block_comments=true -org.eclipse.jdt.core.formatter.comment.format_header=false -org.eclipse.jdt.core.formatter.comment.format_html=true -org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true -org.eclipse.jdt.core.formatter.comment.format_line_comments=true -org.eclipse.jdt.core.formatter.comment.format_source_code=true -org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true -org.eclipse.jdt.core.formatter.comment.indent_root_tags=true -org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert -org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert -org.eclipse.jdt.core.formatter.comment.line_length=80 -org.eclipse.jdt.core.formatter.compact_else_if=true -org.eclipse.jdt.core.formatter.continuation_indentation=2 -org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 -org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true -org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true -org.eclipse.jdt.core.formatter.indent_empty_lines=false -org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true -org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true -org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true -org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false -org.eclipse.jdt.core.formatter.indentation.size=4 -org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert -org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert -org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert -org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert -org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert -org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert -org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert -org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert -org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert -org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert -org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert -org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert -org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert -org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert -org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert -org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false -org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false -org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false -org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false -org.eclipse.jdt.core.formatter.lineSplit=80 -org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false -org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false -org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 -org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 -org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true -org.eclipse.jdt.core.formatter.tabulation.char=tab -org.eclipse.jdt.core.formatter.tabulation.size=4 -org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false -org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true -org.eclipse.jdt.core.incompatibleJDKLevel=ignore -org.eclipse.jdt.core.incompleteClasspath=error diff --git a/bundles/org.eclipse.core.databinding/.settings/org.eclipse.jdt.ui.prefs b/bundles/org.eclipse.core.databinding/.settings/org.eclipse.jdt.ui.prefs deleted file mode 100644 index 0f5114f4..00000000 --- a/bundles/org.eclipse.core.databinding/.settings/org.eclipse.jdt.ui.prefs +++ /dev/null @@ -1,116 +0,0 @@ -#Mon Dec 03 13:49:43 EST 2007 -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_serial_version_id=false -cleanup.always_use_blocks=true -cleanup.always_use_parentheses_in_expressions=false -cleanup.always_use_this_for_non_static_field_access=false -cleanup.always_use_this_for_non_static_method_access=false -cleanup.convert_to_enhanced_for_loop=false -cleanup.correct_indentation=false -cleanup.format_source_code=false -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_variable_declarations_final=false -cleanup.never_use_blocks=false -cleanup.never_use_parentheses_in_expressions=true -cleanup.organize_imports=false -cleanup.qualify_static_field_accesses_with_declaring_class=false -cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true -cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true -cleanup.qualify_static_member_accesses_with_declaring_class=true -cleanup.qualify_static_method_accesses_with_declaring_class=false -cleanup.remove_private_constructors=true -cleanup.remove_trailing_whitespaces=false -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=false -cleanup.use_blocks_only_for_return_and_throw=false -cleanup.use_parentheses_in_expressions=false -cleanup.use_this_for_non_static_field_access=false -cleanup.use_this_for_non_static_field_access_only_if_necessary=true -cleanup.use_this_for_non_static_method_access=false -cleanup.use_this_for_non_static_method_access_only_if_necessary=true -cleanup_profile=org.eclipse.jdt.ui.default.eclipse_clean_up_profile -cleanup_settings_version=2 -eclipse.preferences.version=1 -editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=false -formatter_profile=org.eclipse.jdt.ui.default.eclipse_profile -formatter_settings_version=11 -org.eclipse.jdt.ui.exception.name=e -org.eclipse.jdt.ui.gettersetter.use.is=true -org.eclipse.jdt.ui.ignorelowercasenames=true -org.eclipse.jdt.ui.importorder=java;javax;org;com; -org.eclipse.jdt.ui.javadoc=true -org.eclipse.jdt.ui.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"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\r\n * @return Returns the ${bare_field_name}.\r\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\r\n * @param ${param} The ${bare_field_name} to set.\r\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="true" 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) ${year} IBM Corporation 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 * IBM Corporation - initial API and implementation\r\n ******************************************************************************/\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 * @since 3.3\r\n *\r\n * ${tags}\r\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\r\n * \r\n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="true" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/* (non-Javadoc)\r\n * ${see_to_overridden}\r\n */</template><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\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\r\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\r\n${body_statement}</template><template autoinsert\="true" 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}\r\n// ${todo} Auto-generated constructor stub</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><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\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\r\n * ${tags}\r\n * ${see_to_target}\r\n */</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_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=false -sp_cleanup.format_source_code=false -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_variable_declarations_final=true -sp_cleanup.never_use_blocks=false -sp_cleanup.never_use_parentheses_in_expressions=true -sp_cleanup.on_save_use_additional_actions=false -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=false -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=false -sp_cleanup.remove_unused_imports=false -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=false -sp_cleanup.use_blocks_only_for_return_and_throw=false -sp_cleanup.use_parentheses_in_expressions=false -sp_cleanup.use_this_for_non_static_field_access=false -sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true -sp_cleanup.use_this_for_non_static_method_access=false -sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true diff --git a/bundles/org.eclipse.core.databinding/.settings/org.eclipse.pde.api.tools.prefs b/bundles/org.eclipse.core.databinding/.settings/org.eclipse.pde.api.tools.prefs deleted file mode 100644 index 60843cb3..00000000 --- a/bundles/org.eclipse.core.databinding/.settings/org.eclipse.pde.api.tools.prefs +++ /dev/null @@ -1,145 +0,0 @@ -#Wed Apr 02 17:10:39 EDT 2008 -ANNOTATION_ELEMENT_TYPE_ADDED_CLASS_BOUND=Error -ANNOTATION_ELEMENT_TYPE_ADDED_FIELD=Error -ANNOTATION_ELEMENT_TYPE_ADDED_INTERFACE_BOUND=Error -ANNOTATION_ELEMENT_TYPE_ADDED_INTERFACE_BOUNDS=Error -ANNOTATION_ELEMENT_TYPE_ADDED_METHOD=Error -ANNOTATION_ELEMENT_TYPE_ADDED_METHOD_WITHOUT_DEFAULT_VALUE=Error -ANNOTATION_ELEMENT_TYPE_ADDED_TYPE_MEMBER=Error -ANNOTATION_ELEMENT_TYPE_ADDED_TYPE_PARAMETER=Error -ANNOTATION_ELEMENT_TYPE_CHANGED_CLASS_BOUND=Error -ANNOTATION_ELEMENT_TYPE_CHANGED_INTERFACE_BOUND=Error -ANNOTATION_ELEMENT_TYPE_CHANGED_INTERFACE_BOUNDS=Error -ANNOTATION_ELEMENT_TYPE_CHANGED_RESTRICTIONS=Error -ANNOTATION_ELEMENT_TYPE_CHANGED_TO_CLASS=Error -ANNOTATION_ELEMENT_TYPE_CHANGED_TO_ENUM=Error -ANNOTATION_ELEMENT_TYPE_CHANGED_TO_INTERFACE=Error -ANNOTATION_ELEMENT_TYPE_REMOVED_CLASS_BOUND=Error -ANNOTATION_ELEMENT_TYPE_REMOVED_FIELD=Error -ANNOTATION_ELEMENT_TYPE_REMOVED_INTERFACE_BOUND=Error -ANNOTATION_ELEMENT_TYPE_REMOVED_METHOD_WITHOUT_DEFAULT_VALUE=Error -ANNOTATION_ELEMENT_TYPE_REMOVED_METHOD_WITH_DEFAULT_VALUE=Error -ANNOTATION_ELEMENT_TYPE_REMOVED_TYPE_MEMBER=Error -ANNOTATION_ELEMENT_TYPE_REMOVED_TYPE_PARAMETER=Error -ANNOTATION_ELEMENT_TYPE_REMOVED_TYPE_PARAMETERS=Error -API_COMPONENT_ELEMENT_TYPE_REMOVED_TYPE=Error -API_LEAK=Warning -API_PROFILE_ELEMENT_TYPE_REMOVED_API_COMPONENT=Error -CLASS_ELEMENT_TYPE_ADDED_CLASS_BOUND=Error -CLASS_ELEMENT_TYPE_ADDED_FIELD=Error -CLASS_ELEMENT_TYPE_ADDED_INTERFACE_BOUND=Error -CLASS_ELEMENT_TYPE_ADDED_INTERFACE_BOUNDS=Error -CLASS_ELEMENT_TYPE_ADDED_METHOD=Error -CLASS_ELEMENT_TYPE_ADDED_TYPE_PARAMETER=Error -CLASS_ELEMENT_TYPE_CHANGED_CLASS_BOUND=Error -CLASS_ELEMENT_TYPE_CHANGED_CONTRACTED_SUPERCLASS_SET=Error -CLASS_ELEMENT_TYPE_CHANGED_CONTRACTED_SUPERINTERFACES_SET=Error -CLASS_ELEMENT_TYPE_CHANGED_DECREASE_ACCESS=Error -CLASS_ELEMENT_TYPE_CHANGED_INTERFACE_BOUND=Error -CLASS_ELEMENT_TYPE_CHANGED_NON_ABSTRACT_TO_ABSTRACT=Error -CLASS_ELEMENT_TYPE_CHANGED_NON_FINAL_TO_FINAL=Error -CLASS_ELEMENT_TYPE_CHANGED_RESTRICTIONS=Error -CLASS_ELEMENT_TYPE_CHANGED_SUPERCLASS=Error -CLASS_ELEMENT_TYPE_CHANGED_TO_ANNOTATION=Error -CLASS_ELEMENT_TYPE_CHANGED_TO_ENUM=Error -CLASS_ELEMENT_TYPE_CHANGED_TO_INTERFACE=Error -CLASS_ELEMENT_TYPE_REMOVED_CLASS_BOUND=Error -CLASS_ELEMENT_TYPE_REMOVED_CONSTRUCTOR=Error -CLASS_ELEMENT_TYPE_REMOVED_FIELD=Error -CLASS_ELEMENT_TYPE_REMOVED_INTERFACE_BOUND=Error -CLASS_ELEMENT_TYPE_REMOVED_INTERFACE_BOUNDS=Error -CLASS_ELEMENT_TYPE_REMOVED_METHOD=Error -CLASS_ELEMENT_TYPE_REMOVED_TYPE_MEMBER=Error -CLASS_ELEMENT_TYPE_REMOVED_TYPE_PARAMETER=Error -CLASS_ELEMENT_TYPE_REMOVED_TYPE_PARAMETERS=Error -CONSTRUCTOR_ELEMENT_TYPE_ADDED_CLASS_BOUND=Error -CONSTRUCTOR_ELEMENT_TYPE_ADDED_INTERFACE_BOUND=Error -CONSTRUCTOR_ELEMENT_TYPE_ADDED_INTERFACE_BOUNDS=Error -CONSTRUCTOR_ELEMENT_TYPE_ADDED_TYPE_PARAMETER=Error -CONSTRUCTOR_ELEMENT_TYPE_CHANGED_CLASS_BOUND=Error -CONSTRUCTOR_ELEMENT_TYPE_CHANGED_DECREASE_ACCESS=Error -CONSTRUCTOR_ELEMENT_TYPE_CHANGED_INTERFACE_BOUND=Error -CONSTRUCTOR_ELEMENT_TYPE_CHANGED_NON_ABSTRACT_TO_ABSTRACT=Error -CONSTRUCTOR_ELEMENT_TYPE_CHANGED_NON_FINAL_TO_FINAL=Error -CONSTRUCTOR_ELEMENT_TYPE_CHANGED_NON_STATIC_TO_STATIC=Error -CONSTRUCTOR_ELEMENT_TYPE_CHANGED_STATIC_TO_NON_STATIC=Error -CONSTRUCTOR_ELEMENT_TYPE_CHANGED_TYPE_PARAMETER=Error -CONSTRUCTOR_ELEMENT_TYPE_CHANGED_VARARGS_TO_ARRAY=Error -CONSTRUCTOR_ELEMENT_TYPE_REMOVED_ANNOTATION_DEFAULT_VALUE=Error -CONSTRUCTOR_ELEMENT_TYPE_REMOVED_CLASS_BOUND=Error -CONSTRUCTOR_ELEMENT_TYPE_REMOVED_INTERFACE_BOUND=Error -CONSTRUCTOR_ELEMENT_TYPE_REMOVED_INTERFACE_BOUNDS=Error -CONSTRUCTOR_ELEMENT_TYPE_REMOVED_TYPE_PARAMETER=Error -CONSTRUCTOR_ELEMENT_TYPE_REMOVED_TYPE_PARAMETERS=Error -ENUM_ELEMENT_TYPE_ADDED_FIELD=Error -ENUM_ELEMENT_TYPE_ADDED_METHOD=Error -ENUM_ELEMENT_TYPE_CHANGED_CONTRACTED_SUPERINTERFACES_SET=Error -ENUM_ELEMENT_TYPE_CHANGED_RESTRICTIONS=Error -ENUM_ELEMENT_TYPE_CHANGED_TO_ANNOTATION=Error -ENUM_ELEMENT_TYPE_CHANGED_TO_CLASS=Error -ENUM_ELEMENT_TYPE_CHANGED_TO_INTERFACE=Error -ENUM_ELEMENT_TYPE_REMOVED_CONSTRUCTOR=Error -ENUM_ELEMENT_TYPE_REMOVED_ENUM_CONSTANT=Error -ENUM_ELEMENT_TYPE_REMOVED_FIELD=Error -ENUM_ELEMENT_TYPE_REMOVED_METHOD=Error -ENUM_ELEMENT_TYPE_REMOVED_TYPE_MEMBER=Error -FIELD_ELEMENT_TYPE_ADDED_VALUE=Error -FIELD_ELEMENT_TYPE_CHANGED_DECREASE_ACCESS=Error -FIELD_ELEMENT_TYPE_CHANGED_FINAL_TO_NON_FINAL_STATIC_CONSTANT=Ignore -FIELD_ELEMENT_TYPE_CHANGED_NON_FINAL_TO_FINAL=Error -FIELD_ELEMENT_TYPE_CHANGED_NON_STATIC_TO_STATIC=Error -FIELD_ELEMENT_TYPE_CHANGED_STATIC_TO_NON_STATIC=Error -FIELD_ELEMENT_TYPE_CHANGED_TYPE=Error -FIELD_ELEMENT_TYPE_CHANGED_VALUE=Error -FIELD_ELEMENT_TYPE_REMOVED_TYPE_ARGUMENTS=Error -FIELD_ELEMENT_TYPE_REMOVED_VALUE=Error -ILLEGAL_EXTEND=Warning -ILLEGAL_IMPLEMENT=Warning -ILLEGAL_INSTANTIATE=Warning -ILLEGAL_OVERRIDE=Warning -ILLEGAL_REFERENCE=Warning -INTERFACE_ELEMENT_TYPE_ADDED_CLASS_BOUND=Error -INTERFACE_ELEMENT_TYPE_ADDED_FIELD=Error -INTERFACE_ELEMENT_TYPE_ADDED_INTERFACE_BOUND=Error -INTERFACE_ELEMENT_TYPE_ADDED_INTERFACE_BOUNDS=Error -INTERFACE_ELEMENT_TYPE_ADDED_METHOD=Error -INTERFACE_ELEMENT_TYPE_ADDED_TYPE_MEMBER=Error -INTERFACE_ELEMENT_TYPE_ADDED_TYPE_PARAMETER=Error -INTERFACE_ELEMENT_TYPE_ADDED_TYPE_PARAMETERS=Error -INTERFACE_ELEMENT_TYPE_CHANGED_CLASS_BOUND=Error -INTERFACE_ELEMENT_TYPE_CHANGED_INTERFACE_BOUND=Error -INTERFACE_ELEMENT_TYPE_CHANGED_INTERFACE_BOUNDS=Error -INTERFACE_ELEMENT_TYPE_CHANGED_RESTRICTIONS=Error -INTERFACE_ELEMENT_TYPE_CHANGED_TO_ANNOTATION=Error -INTERFACE_ELEMENT_TYPE_CHANGED_TO_CLASS=Error -INTERFACE_ELEMENT_TYPE_CHANGED_TO_ENUM=Error -INTERFACE_ELEMENT_TYPE_REMOVED_CLASS_BOUND=Error -INTERFACE_ELEMENT_TYPE_REMOVED_FIELD=Error -INTERFACE_ELEMENT_TYPE_REMOVED_INTERFACE_BOUND=Error -INTERFACE_ELEMENT_TYPE_REMOVED_INTERFACE_BOUNDS=Error -INTERFACE_ELEMENT_TYPE_REMOVED_METHOD=Error -INTERFACE_ELEMENT_TYPE_REMOVED_TYPE_MEMBER=Error -METHOD_ELEMENT_TYPE_ADDED_CLASS_BOUND=Error -METHOD_ELEMENT_TYPE_ADDED_INTERFACE_BOUND=Error -METHOD_ELEMENT_TYPE_ADDED_INTERFACE_BOUNDS=Error -METHOD_ELEMENT_TYPE_ADDED_TYPE_PARAMETER=Error -METHOD_ELEMENT_TYPE_CHANGED_CLASS_BOUND=Error -METHOD_ELEMENT_TYPE_CHANGED_DECREASE_ACCESS=Error -METHOD_ELEMENT_TYPE_CHANGED_INTERFACE_BOUND=Error -METHOD_ELEMENT_TYPE_CHANGED_NON_ABSTRACT_TO_ABSTRACT=Error -METHOD_ELEMENT_TYPE_CHANGED_NON_FINAL_TO_FINAL=Error -METHOD_ELEMENT_TYPE_CHANGED_NON_STATIC_TO_STATIC=Error -METHOD_ELEMENT_TYPE_CHANGED_STATIC_TO_NON_STATIC=Error -METHOD_ELEMENT_TYPE_CHANGED_TYPE_PARAMETER=Error -METHOD_ELEMENT_TYPE_CHANGED_VARARGS_TO_ARRAY=Error -METHOD_ELEMENT_TYPE_REMOVED_ANNOTATION_DEFAULT_VALUE=Error -METHOD_ELEMENT_TYPE_REMOVED_CLASS_BOUND=Error -METHOD_ELEMENT_TYPE_REMOVED_INTERFACE_BOUND=Error -METHOD_ELEMENT_TYPE_REMOVED_INTERFACE_BOUNDS=Error -METHOD_ELEMENT_TYPE_REMOVED_TYPE_PARAMETER=Error -METHOD_ELEMENT_TYPE_REMOVED_TYPE_PARAMETERS=Error -eclipse.preferences.version=1 -incompatible_api_component_version=Error -invalid_since_tag_version=Error -malformed_since_tag=Error -missing_since_tag=Error diff --git a/bundles/org.eclipse.core.databinding/.settings/org.eclipse.pde.prefs b/bundles/org.eclipse.core.databinding/.settings/org.eclipse.pde.prefs deleted file mode 100644 index 4a56680a..00000000 --- a/bundles/org.eclipse.core.databinding/.settings/org.eclipse.pde.prefs +++ /dev/null @@ -1,18 +0,0 @@ -#Mon Dec 03 13:49:44 EST 2007 -compilers.incompatible-environment=1 -compilers.p.build=1 -compilers.p.deprecated=0 -compilers.p.illegal-att-value=0 -compilers.p.missing-bundle-classpath-entries=1 -compilers.p.missing-packages=2 -compilers.p.no-required-att=0 -compilers.p.not-externalized-att=0 -compilers.p.unknown-attribute=0 -compilers.p.unknown-class=0 -compilers.p.unknown-element=1 -compilers.p.unknown-resource=0 -compilers.p.unresolved-ex-points=0 -compilers.p.unresolved-import=0 -compilers.p.unused-element-or-attribute=1 -compilers.use-project=true -eclipse.preferences.version=1 diff --git a/bundles/org.eclipse.core.databinding/META-INF/MANIFEST.MF b/bundles/org.eclipse.core.databinding/META-INF/MANIFEST.MF deleted file mode 100644 index b5aaa189..00000000 --- a/bundles/org.eclipse.core.databinding/META-INF/MANIFEST.MF +++ /dev/null @@ -1,34 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: %pluginName -Bundle-SymbolicName: org.eclipse.core.databinding -Bundle-Version: 1.1.1.qualifier -Bundle-ClassPath: . -Bundle-Vendor: %providerName -Bundle-Localization: plugin -Export-Package: org.eclipse.core.databinding, - org.eclipse.core.databinding.conversion;x-internal:=false, - org.eclipse.core.databinding.observable, - org.eclipse.core.databinding.observable.list;x-internal:=false, - org.eclipse.core.databinding.observable.map, - org.eclipse.core.databinding.observable.masterdetail, - org.eclipse.core.databinding.observable.set;x-internal:=false, - org.eclipse.core.databinding.observable.value;x-internal:=false, - org.eclipse.core.databinding.util, - org.eclipse.core.databinding.validation;x-internal:=false, - org.eclipse.core.internal.databinding;x-friends:="org.eclipse.core.databinding.beans", - org.eclipse.core.internal.databinding.conversion;x-friends:="org.eclipse.jface.tests.databinding", - org.eclipse.core.internal.databinding.observable;x-internal:=true, - org.eclipse.core.internal.databinding.observable.masterdetail;x-friends:="org.eclipse.jface.tests.databinding", - org.eclipse.core.internal.databinding.observable.tree;x-friends:="org.eclipse.jface.databinding,org.eclipse.jface.tests.databinding", - org.eclipse.core.internal.databinding.validation;x-friends:="org.eclipse.jface.tests.databinding" -Require-Bundle: org.eclipse.equinox.common;bundle-version="[3.2.0,4.0.0)" -Import-Package-Comment: see http://wiki.eclipse.org/ -Import-Package: com.ibm.icu.text, - org.osgi.framework;version="[1.4.0,2.0.0)";resolution:=optional, - org.osgi.util.tracker;version="[1.3.3,2.0.0)";resolution:=optional, - org.eclipse.osgi.framework.log;version="[1.0.0,2.0.0)";resolution:=optional -Bundle-RequiredExecutionEnvironment: CDC-1.1/Foundation-1.1, - J2SE-1.4 -Bundle-Activator: org.eclipse.core.internal.databinding.Activator -Bundle-ActivationPolicy: lazy diff --git a/bundles/org.eclipse.core.databinding/about.html b/bundles/org.eclipse.core.databinding/about.html deleted file mode 100644 index 46023304..00000000 --- a/bundles/org.eclipse.core.databinding/about.html +++ /dev/null @@ -1,28 +0,0 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml"> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> -<title>About</title> -</head> -<body lang="EN-US"> -<h2>About This Content</h2> - -<p>June 2, 2006</p> -<h3>License</h3> - -<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise -indicated below, the Content is provided to you under the terms and conditions of the -Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available -at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>. -For purposes of the EPL, "Program" will mean the Content.</p> - -<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is -being redistributed by another party ("Redistributor") and different terms and conditions may -apply to your use of any object code in the Content. Check the Redistributor's license that was -provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise -indicated below, the terms and conditions of the EPL still apply to any source code in the Content -and such source code may be obtained at <a href="http://www.eclipse.org">http://www.eclipse.org</a>.</p> - -</body> -</html>
\ No newline at end of file diff --git a/bundles/org.eclipse.core.databinding/build.properties b/bundles/org.eclipse.core.databinding/build.properties deleted file mode 100644 index 67499e3d..00000000 --- a/bundles/org.eclipse.core.databinding/build.properties +++ /dev/null @@ -1,17 +0,0 @@ -############################################################################### -# Copyright (c) 2003, 2006 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -bin.includes = .,\ - META-INF/,\ - plugin.properties,\ - about.html -output.databinding.jar = bin/ -src.includes = about.html -source.. = src/ diff --git a/bundles/org.eclipse.core.databinding/plugin.properties b/bundles/org.eclipse.core.databinding/plugin.properties deleted file mode 100644 index e18f3957..00000000 --- a/bundles/org.eclipse.core.databinding/plugin.properties +++ /dev/null @@ -1,12 +0,0 @@ -############################################################################### -# Copyright (c) 2000, 2006 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -pluginName = JFace Data Binding -providerName = Eclipse.org diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/AggregateValidationStatus.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/AggregateValidationStatus.java deleted file mode 100644 index bbba98ed..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/AggregateValidationStatus.java +++ /dev/null @@ -1,250 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matt Carter - bug 182822 - * Boris Bokowski - bug 218269 - * Matthew Hall - bug 218269 - *******************************************************************************/ -package org.eclipse.core.databinding; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.ComputedValue; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.util.Policy; -import org.eclipse.core.internal.databinding.BindingMessages; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.core.runtime.Status; - -/** - * This class can be used to aggregate status values from a data binding context - * into a single status value. Instances of this class can be used as an - * observable value with a value type of {@link IStatus}, or the static methods - * can be called directly if an aggregated status result is only needed once. - * - * @since 1.0 - * - */ -public final class AggregateValidationStatus implements IObservableValue { - - private IObservableValue implementation; - - /** - * Constant denoting an aggregation strategy that merges multiple non-OK - * status objects in a {@link MultiStatus}. Returns an OK status result if - * all statuses from the given validation status providers are the an OK - * status. Returns a single status if there is only one non-OK status. - * - * @see #getStatusMerged(Collection) - */ - public static final int MERGED = 1; - - /** - * Constant denoting an aggregation strategy that always returns the most - * severe status from the given validation status providers. If there is - * more than one status at the same severity level, it picks the first one - * it encounters. - * - * @see #getStatusMaxSeverity(Collection) - */ - public static final int MAX_SEVERITY = 2; - - /** - * Creates a new aggregate validation status observable for the given data - * binding context. - * - * @param dbc - * a data binding context - * @param strategy - * a strategy constant, one of {@link #MERGED} or - * {@link #MAX_SEVERITY}. - * @since 1.1 - */ - public AggregateValidationStatus(DataBindingContext dbc, int strategy) { - this(dbc.getValidationRealm(), dbc.getValidationStatusProviders(), - strategy); - } - - /** - * @param validationStatusProviders - * an observable collection containing elements of type - * {@link ValidationStatusProvider} - * @param strategy - * a strategy constant, one of {@link #MERGED} or - * {@link #MAX_SEVERITY}. - * @see DataBindingContext#getValidationStatusProviders() - */ - public AggregateValidationStatus( - final IObservableCollection validationStatusProviders, int strategy) { - this(Realm.getDefault(), validationStatusProviders, strategy); - } - - /** - * @param realm - * Realm - * @param validationStatusProviders - * an observable collection containing elements of type - * {@link ValidationStatusProvider} - * @param strategy - * a strategy constant, one of {@link #MERGED} or - * {@link #MAX_SEVERITY}. - * @see DataBindingContext#getValidationStatusProviders() - * @since 1.1 - */ - public AggregateValidationStatus(final Realm realm, - final IObservableCollection validationStatusProviders, int strategy) { - if (strategy == MERGED) { - implementation = new ComputedValue(realm, IStatus.class) { - protected Object calculate() { - return getStatusMerged(validationStatusProviders); - } - }; - } else { - implementation = new ComputedValue(realm, IStatus.class) { - protected Object calculate() { - return getStatusMaxSeverity(validationStatusProviders); - } - }; - } - } - - /** - * @param listener - * @see org.eclipse.core.databinding.observable.IObservable#addChangeListener(org.eclipse.core.databinding.observable.IChangeListener) - */ - public void addChangeListener(IChangeListener listener) { - implementation.addChangeListener(listener); - } - - /** - * @param listener - * @see org.eclipse.core.databinding.observable.IObservable#addStaleListener(org.eclipse.core.databinding.observable.IStaleListener) - */ - public void addStaleListener(IStaleListener listener) { - implementation.addStaleListener(listener); - } - - /** - * @param listener - * @see org.eclipse.core.databinding.observable.value.IObservableValue#addValueChangeListener(org.eclipse.core.databinding.observable.value.IValueChangeListener) - */ - public void addValueChangeListener(IValueChangeListener listener) { - implementation.addValueChangeListener(listener); - } - - public void dispose() { - implementation.dispose(); - } - - public Realm getRealm() { - return implementation.getRealm(); - } - - public Object getValue() { - return implementation.getValue(); - } - - public Object getValueType() { - return implementation.getValueType(); - } - - public boolean isStale() { - return implementation.isStale(); - } - - public void removeChangeListener(IChangeListener listener) { - implementation.removeChangeListener(listener); - } - - public void removeStaleListener(IStaleListener listener) { - implementation.removeStaleListener(listener); - } - - public void removeValueChangeListener(IValueChangeListener listener) { - implementation.removeValueChangeListener(listener); - } - - public void setValue(Object value) { - implementation.setValue(value); - } - - /** - * Returns a status object that merges multiple non-OK status objects in a - * {@link MultiStatus}. Returns an OK status result if all statuses from - * the given validation status providers are the an OK status. Returns a - * single status if there is only one non-OK status. - * - * @param validationStatusProviders - * a collection of validation status providers - * @return a merged status - */ - public static IStatus getStatusMerged(Collection validationStatusProviders) { - List statuses = new ArrayList(); - for (Iterator it = validationStatusProviders.iterator(); it.hasNext();) { - ValidationStatusProvider validationStatusProvider = (ValidationStatusProvider) it - .next(); - IStatus status = (IStatus) validationStatusProvider - .getValidationStatus().getValue(); - if (!status.isOK()) { - statuses.add(status); - } - } - if (statuses.size() == 1) { - return (IStatus) statuses.get(0); - } - if (!statuses.isEmpty()) { - MultiStatus result = new MultiStatus(Policy.JFACE_DATABINDING, 0, - BindingMessages - .getString(BindingMessages.MULTIPLE_PROBLEMS), null); - for (Iterator it = statuses.iterator(); it.hasNext();) { - IStatus status = (IStatus) it.next(); - result.merge(status); - } - return result; - } - return Status.OK_STATUS; - } - - /** - * Returns a status that always returns the most severe status from the - * given validation status providers. If there is more than one status at - * the same severity level, it picks the first one it encounters. - * - * @param validationStatusProviders - * a collection of validation status providers - * @return a single status reflecting the most severe status from the given - * validation status providers - */ - public static IStatus getStatusMaxSeverity( - Collection validationStatusProviders) { - int maxSeverity = IStatus.OK; - IStatus maxStatus = Status.OK_STATUS; - for (Iterator it = validationStatusProviders.iterator(); it.hasNext();) { - ValidationStatusProvider validationStatusProvider = (ValidationStatusProvider) it - .next(); - IStatus status = (IStatus) validationStatusProvider - .getValidationStatus().getValue(); - if (status.getSeverity() > maxSeverity) { - maxSeverity = status.getSeverity(); - maxStatus = status; - } - } - return maxStatus; - } - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/Binding.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/Binding.java deleted file mode 100644 index a1939a4b..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/Binding.java +++ /dev/null @@ -1,163 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 159768 - * Boris Bokowski - bug 218269 - * Matthew Hall - bug 218269 - *******************************************************************************/ - -package org.eclipse.core.databinding; - -import java.util.Collections; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Observables; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.value.IObservableValue; - -/** - * This abstract class represents a binding between a model and a target. Newly - * created instances need to be added to a data binding context using - * {@link #init(DataBindingContext)}. - * - * @since 1.0 - */ -public abstract class Binding extends ValidationStatusProvider { - - protected DataBindingContext context; - private IObservable target; - private IObservable model; - - /** - * Creates a new binding. - * - * @param target target observable - * @param model model observable - */ - public Binding(IObservable target, IObservable model) { - this.target = target; - this.model = model; - } - - /** - * Initializes this binding with the given context and adds it to the list - * of bindings of the context. - * <p> - * Subclasses may extend, but must call the super implementation. - * </p> - * - * @param context - */ - public final void init(DataBindingContext context) { - this.context = context; - preInit(); - context.addBinding(this); - postInit(); - } - - /** - * Called by {@link #init(DataBindingContext)} after setting - * {@link #context} but before adding this binding to the context. - * Subclasses may use this method to perform initialization that could not - * be done in the constructor. Care should be taken not to cause any events - * while running this method. - */ - protected abstract void preInit(); - - /** - * Called by {@link #init(DataBindingContext)} after adding this binding to - * the context. Subclasses may use this method to perform initialization - * that may cause events to be fired, including BindingEvents that are - * forwarded to the data binding context. - */ - protected abstract void postInit(); - - /** - * @return an observable value containing the current validation status - */ - public abstract IObservableValue getValidationStatus(); - - /** - * Updates the model's state from the target's state at the next reasonable - * opportunity. There is no guarantee that the state will have been updated - * by the time this call returns. - */ - public abstract void updateTargetToModel(); - - /** - * Updates the target's state from the model's state at the next reasonable - * opportunity. There is no guarantee that the state will have been updated - * by the time this call returns. - */ - public abstract void updateModelToTarget(); - - /** - * Validates the target's state at the next reasonable - * opportunity. There is no guarantee that the validation status will have been updated - * by the time this call returns. - */ - public abstract void validateTargetToModel(); - - /** - * Validates the model's state at the next reasonable - * opportunity. There is no guarantee that the validation status will have been updated - * by the time this call returns. - */ - public abstract void validateModelToTarget(); - - /** - * Disposes of this Binding. Subclasses may extend, but must call super.dispose(). - */ - public void dispose() { - if (context != null) { - context.removeBinding(this); - } - context = null; - target = null; - model = null; - super.dispose(); - } - - /** - * @param context - */ - /* package */ void setDataBindingContext(DataBindingContext context) { - this.context = context; - } - - /** - * @return target observable - */ - public IObservable getTarget() { - return target; - } - - /** - * @since 1.1 - */ - public IObservableList getTargets() { - return Observables.staticObservableList(context.getValidationRealm(), - Collections.singletonList(target)); - } - - /** - * @return model observable - */ - public IObservable getModel() { - return model; - } - - /** - * @since 1.1 - */ - public IObservableList getModels() { - return Observables.staticObservableList(context.getValidationRealm(), - Collections.singletonList(model)); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/BindingException.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/BindingException.java deleted file mode 100644 index ebe86240..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/BindingException.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.core.databinding; - -import java.io.PrintStream; -import java.io.PrintWriter; - -/** - * An unchecked exception indicating a binding problem. - * - * @since 1.0 - */ -public class BindingException extends RuntimeException { - - /* - * Needed because all Throwables are Serializable. - */ - private static final long serialVersionUID = -4092828452936724217L; - private Throwable cause; - - /** - * Creates a new BindingException with the given message. - * - * @param message - */ - public BindingException(String message) { - super(message); - } - - /** - * Creates a new BindingException with the given message and cause. - * - * @param message - * @param cause - */ - public BindingException(String message, Throwable cause) { - super(message); - this.cause = cause; - } - - public void printStackTrace(PrintStream err) { - super.printStackTrace(err); - if (cause != null) { - err.println("caused by:"); //$NON-NLS-1$ - cause.printStackTrace(err); - } - } - - public void printStackTrace(PrintWriter err) { - super.printStackTrace(err); - if (cause != null) { - err.println("caused by:"); //$NON-NLS-1$ - cause.printStackTrace(err); - } - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/DataBindingContext.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/DataBindingContext.java deleted file mode 100644 index 08acd66a..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/DataBindingContext.java +++ /dev/null @@ -1,432 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005-2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 159539 - * Brad Reynolds - bug 140644 - * Brad Reynolds - bug 159940 - * Brad Reynolds - bug 116920, 159768 - * Matthew Hall - bugs 118516, 124684, 218269 - * Boris Bokowski - bug 218269 - *******************************************************************************/ -package org.eclipse.core.databinding; - -import java.util.Iterator; - -import org.eclipse.core.databinding.observable.Observables; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.internal.databinding.ValidationStatusMap; -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.IStatus; - -/** - * A DataBindingContext is the point of contact for the creation and management - * of {@link Binding bindings}, and aggregates validation statuses of its - * bindings, or more generally, its validation status providers. - * <p> - * A DataBindingContext provides the following abilities: - * <ul> - * <li>Ability to create bindings between - * {@link IObservableValue observable values}.</li> - * <li>Ability to create bindings between - * {@link IObservableList observable lists}.</li> - * <li>Access to the bindings created by the instance.</li> - * <li>Access to the list of validation status providers (this includes all - * bindings).</li> - * </ul> - * </p> - * <p> - * Multiple contexts can be used at any point in time. One strategy for the - * management of contexts is the aggregation of validation statuses. For example - * an <code>IWizardPage</code> could use a single context and the statuses - * could be aggregated to set the page status and fulfillment. Each page in the - * <code>IWizard</code> would have its own context instance. - * </p> - * - * @since 1.0 - */ -public class DataBindingContext { - private WritableList bindings; - private WritableList validationStatusProviders; - - /** - * Unmodifiable version of {@link #bindings} for public exposure. - */ - private IObservableList unmodifiableBindings; - /** - * Unmodifiable version of {@link #validationStatusProviders} for public - * exposure. - */ - private IObservableList unmodifiableStatusProviders; - - private IObservableMap validationStatusMap; - - private Realm validationRealm; - - /** - * Creates a data binding context, using the current default realm for the - * validation observables. - * - * @see Realm - */ - public DataBindingContext() { - this(Realm.getDefault()); - } - - /** - * Creates a data binding context using the given realm for the validation - * observables. - * - * @param validationRealm - * the realm to be used for the validation observables - * - * @see Realm - */ - public DataBindingContext(Realm validationRealm) { - Assert.isNotNull(validationRealm, "Validation realm cannot be null"); //$NON-NLS-1$ - this.validationRealm = validationRealm; - - bindings = new WritableList(validationRealm); - unmodifiableBindings = Observables.unmodifiableObservableList(bindings); - - validationStatusProviders = new WritableList(validationRealm); - unmodifiableStatusProviders = Observables - .unmodifiableObservableList(validationStatusProviders); - - validationStatusMap = new ValidationStatusMap(validationRealm, bindings); - } - - /** - * Creates a {@link Binding} to synchronize the values of two - * {@link IObservableValue observable values}. During synchronization - * validation and conversion can be employed to customize the process. For - * specifics on the customization of the process see - * {@link UpdateValueStrategy}. - * - * @param targetObservableValue - * target value, commonly a UI widget - * @param modelObservableValue - * model value - * @param targetToModel - * strategy to employ when the target is the source of the change - * and the model is the destination - * @param modelToTarget - * strategy to employ when the model is the source of the change - * and the target is the destination - * @return created binding - * - * @see UpdateValueStrategy - */ - public final Binding bindValue(IObservableValue targetObservableValue, - IObservableValue modelObservableValue, - UpdateValueStrategy targetToModel, UpdateValueStrategy modelToTarget) { - UpdateValueStrategy targetToModelStrategy = targetToModel != null ? targetToModel - : createTargetToModelUpdateValueStrategy(targetObservableValue, modelObservableValue); - UpdateValueStrategy modelToTargetStrategy = modelToTarget != null ? modelToTarget - : createModelToTargetUpdateValueStrategy(modelObservableValue, targetObservableValue); - targetToModelStrategy.fillDefaults(targetObservableValue, modelObservableValue); - modelToTargetStrategy.fillDefaults(modelObservableValue, targetObservableValue); - ValueBinding result = new ValueBinding(targetObservableValue, - modelObservableValue, targetToModelStrategy, - modelToTargetStrategy); - result.init(this); - return result; - } - - /** - * Returns an update value strategy to be used for copying values from the - * from value to the to value. Clients may override. - * - * @param fromValue - * @param toValue - * @return a update value strategy - */ - protected UpdateValueStrategy createModelToTargetUpdateValueStrategy( - IObservableValue fromValue, IObservableValue toValue) { - return new UpdateValueStrategy(); - } - - /** - * Returns an update value strategy to be used for copying values from the - * from value to the to value. Clients may override. - * - * @param fromValue - * @param toValue - * @return a update value strategy - */ - protected UpdateValueStrategy createTargetToModelUpdateValueStrategy( - IObservableValue fromValue, IObservableValue toValue) { - return new UpdateValueStrategy(); - } - - /** - * Creates a {@link Binding} to synchronize the values of two - * {@link IObservableList observable lists}. During synchronization - * validation and conversion can be employed to customize the process. For - * specifics on the customization of the process see - * {@link UpdateListStrategy}. - * - * @param targetObservableList - * target list, commonly a list representing a list in the UI - * @param modelObservableList - * model list - * @param targetToModel - * strategy to employ when the target is the source of the change - * and the model is the destination - * @param modelToTarget - * strategy to employ when the model is the source of the change - * and the target is the destination - * @return created binding - * - * @see UpdateListStrategy - */ - public final Binding bindList(IObservableList targetObservableList, - IObservableList modelObservableList, - UpdateListStrategy targetToModel, UpdateListStrategy modelToTarget) { - UpdateListStrategy targetToModelStrategy = targetToModel != null ? targetToModel - : createTargetToModelUpdateListStrategy(targetObservableList, - modelObservableList); - UpdateListStrategy modelToTargetStrategy = modelToTarget != null ? modelToTarget - : createModelToTargetUpdateListStrategy(modelObservableList, - targetObservableList); - targetToModelStrategy.fillDefaults(targetObservableList, - modelObservableList); - modelToTargetStrategy.fillDefaults(modelObservableList, - targetObservableList); - ListBinding result = new ListBinding(targetObservableList, - modelObservableList, targetToModelStrategy, - modelToTargetStrategy); - result.init(this); - return result; - } - - /** - * @param modelObservableList - * @param targetObservableList - * @return an update list strategy - */ - protected UpdateListStrategy createModelToTargetUpdateListStrategy( - IObservableList modelObservableList, - IObservableList targetObservableList) { - return new UpdateListStrategy(); - } - - /** - * @param targetObservableList - * @param modelObservableList - * @return an update list strategy - */ - protected UpdateListStrategy createTargetToModelUpdateListStrategy( - IObservableList targetObservableList, - IObservableList modelObservableList) { - return new UpdateListStrategy(); - } - - /** - * Creates a {@link Binding} to synchronize the values of two - * {@link IObservableSet observable sets}. During synchronization - * validation and conversion can be employed to customize the process. For - * specifics on the customization of the process see - * {@link UpdateSetStrategy}. - * - * @param targetObservableSet - * target set, commonly a set representing a set in the UI - * @param modelObservableSet - * model set - * @param targetToModel - * strategy to employ when the target is the source of the change - * and the model is the destination - * @param modelToTarget - * strategy to employ when the model is the source of the change - * and the target is the destination - * @return created binding - * @since 1.1 - */ - public final Binding bindSet(IObservableSet targetObservableSet, - IObservableSet modelObservableSet, UpdateSetStrategy targetToModel, - UpdateSetStrategy modelToTarget) { - if (targetToModel == null) - targetToModel = createTargetToModelUpdateSetStrategy( - targetObservableSet, modelObservableSet); - if (modelToTarget == null) - modelToTarget = createModelToTargetUpdateSetStrategy( - modelObservableSet, targetObservableSet); - targetToModel.fillDefaults(targetObservableSet, modelObservableSet); - modelToTarget.fillDefaults(modelObservableSet, targetObservableSet); - SetBinding result = new SetBinding(targetObservableSet, - modelObservableSet, targetToModel, modelToTarget); - result.init(this); - return result; - } - - /** - * @param targetObservableSet - * @param modelObservableSet - * @return a default set update strategy - * @since 1.1 - */ - protected UpdateSetStrategy createTargetToModelUpdateSetStrategy( - IObservableSet targetObservableSet, - IObservableSet modelObservableSet) { - return new UpdateSetStrategy(); - } - - /** - * @param modelObservableSet - * @param targetObservableSet - * @return a default set update strategy - * @since 1.1 - */ - protected UpdateSetStrategy createModelToTargetUpdateSetStrategy( - IObservableSet modelObservableSet, - IObservableSet targetObservableSet) { - return new UpdateSetStrategy(); - } - - /** - * Disposes of this data binding context and all bindings and validation - * status providers that were added to this context. - */ - public final void dispose() { - Binding[] bindingArray = (Binding[]) bindings.toArray(new Binding[bindings.size()]); - for (int i = 0; i < bindingArray.length; i++) { - bindingArray[i].dispose(); - } - ValidationStatusProvider[] statusProviderArray = (ValidationStatusProvider[]) validationStatusProviders - .toArray(new ValidationStatusProvider[validationStatusProviders - .size()]); - for (int i = 0; i < statusProviderArray.length; i++) { - if (!statusProviderArray[i].isDisposed()) - statusProviderArray[i].dispose(); - } - } - - /** - * Returns an unmodifiable observable list with elements of type - * {@link Binding}, ordered by time of addition. - * - * @return the observable list containing all bindings - */ - public final IObservableList getBindings() { - return unmodifiableBindings; - } - - /** - * Returns an unmodifiable observable list with elements of type - * {@link ValidationStatusProvider}, ordered by time of addition. - * - * @return the observable list containing all bindings - * @since 1.1 - */ - public final IObservableList getValidationStatusProviders() { - return unmodifiableStatusProviders; - } - - /** - * Returns an observable map from bindings (type: {@link Binding}) to - * statuses (type: {@link IStatus}). The keys of the map are the bindings - * returned by {@link #getBindings()}, and the values are the current - * validaion status objects for each binding. - * - * @return the observable map from bindings to status objects. - * - * @deprecated as of 1.1, please use {@link #getValidationStatusProviders()} - */ - public final IObservableMap getValidationStatusMap() { - return validationStatusMap; - } - - /** - * Adds the given binding to this data binding context. This will also add - * the given binding to the list of validation status providers. - * - * @param binding - * The binding to add. - * @see #addValidationStatusProvider(ValidationStatusProvider) - * @see #getValidationStatusProviders() - */ - public void addBinding(Binding binding) { - addValidationStatusProvider(binding); - bindings.add(binding); - } - - /** - * Adds the given validation status provider to this data binding context. - * - * @param validationStatusProvider - * The validation status provider to add. - * @since 1.1 - */ - public void addValidationStatusProvider( - ValidationStatusProvider validationStatusProvider) { - validationStatusProviders.add(validationStatusProvider); - } - - /** - * Updates all model observable objects to reflect the current state of the - * target observable objects. - * - */ - public final void updateModels() { - for (Iterator it = bindings.iterator(); it.hasNext();) { - Binding binding = (Binding) it.next(); - binding.updateTargetToModel(); - } - } - - /** - * Updates all target observable objects to reflect the current state of the - * model observable objects. - * - */ - public final void updateTargets() { - for (Iterator it = bindings.iterator(); it.hasNext();) { - Binding binding = (Binding) it.next(); - binding.updateModelToTarget(); - } - } - - /** - * Removes the given binding. - * - * @param binding - * @return <code>true</code> if was associated with the context, - * <code>false</code> if not - */ - public boolean removeBinding(Binding binding) { - return bindings.remove(binding) && removeValidationStatusProvider(binding); - } - - /** - * Removes the validation status provider. - * - * @param validationStatusProvider - * @return <code>true</code> if was associated with the context, - * <code>false</code> if not - * @since 1.1 - */ - public boolean removeValidationStatusProvider( - ValidationStatusProvider validationStatusProvider) { - return validationStatusProviders.remove(validationStatusProvider); - } - - /** - * Returns the validation realm. - * - * @return the realm for the validation observables - * @see Realm - */ - public final Realm getValidationRealm() { - return validationRealm; - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/ListBinding.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/ListBinding.java deleted file mode 100644 index 459c5248..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/ListBinding.java +++ /dev/null @@ -1,222 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.databinding; - -import java.util.Collections; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.list.IListChangeListener; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.ListChangeEvent; -import org.eclipse.core.databinding.observable.list.ListDiff; -import org.eclipse.core.databinding.observable.list.ListDiffEntry; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.internal.databinding.BindingStatus; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.core.runtime.Status; - -/** - * @since 1.0 - * - */ -public class ListBinding extends Binding { - - private UpdateListStrategy targetToModel; - private UpdateListStrategy modelToTarget; - private IObservableValue validationStatusObservable; - private boolean updatingTarget; - private boolean updatingModel; - - private IListChangeListener targetChangeListener = new IListChangeListener() { - public void handleListChange(ListChangeEvent event) { - if (!updatingTarget) { - doUpdate((IObservableList) getTarget(), - (IObservableList) getModel(), event.diff, - targetToModel, false, false); - } - } - }; - private IListChangeListener modelChangeListener = new IListChangeListener() { - public void handleListChange(ListChangeEvent event) { - if (!updatingModel) { - doUpdate((IObservableList) getModel(), - (IObservableList) getTarget(), event.diff, - modelToTarget, false, false); - } - } - }; - - /** - * @param target - * @param model - * @param modelToTargetStrategy - * @param targetToModelStrategy - */ - public ListBinding(IObservableList target, IObservableList model, - UpdateListStrategy targetToModelStrategy, - UpdateListStrategy modelToTargetStrategy) { - super(target, model); - this.targetToModel = targetToModelStrategy; - this.modelToTarget = modelToTargetStrategy; - if ((targetToModel.getUpdatePolicy() & UpdateValueStrategy.POLICY_UPDATE) != 0) { - target.addListChangeListener(targetChangeListener); - } else { - targetChangeListener = null; - } - if ((modelToTarget.getUpdatePolicy() & UpdateValueStrategy.POLICY_UPDATE) != 0) { - model.addListChangeListener(modelChangeListener); - } else { - modelChangeListener = null; - } - } - - public IObservableValue getValidationStatus() { - return validationStatusObservable; - } - - protected void preInit() { - validationStatusObservable = new WritableValue(context - .getValidationRealm(), Status.OK_STATUS, IStatus.class); - } - - protected void postInit() { - if (modelToTarget.getUpdatePolicy() == UpdateListStrategy.POLICY_UPDATE) { - updateModelToTarget(); - } - if (targetToModel.getUpdatePolicy() != UpdateListStrategy.POLICY_NEVER) { - validateTargetToModel(); - } - } - - public void updateModelToTarget() { - final IObservableList modelList = (IObservableList) getModel(); - modelList.getRealm().exec(new Runnable() { - public void run() { - ListDiff diff = Diffs.computeListDiff(Collections.EMPTY_LIST, - modelList); - doUpdate(modelList, (IObservableList) getTarget(), diff, - modelToTarget, true, true); - } - }); - } - - public void updateTargetToModel() { - final IObservableList targetList = (IObservableList) getTarget(); - targetList.getRealm().exec(new Runnable() { - public void run() { - ListDiff diff = Diffs.computeListDiff(Collections.EMPTY_LIST, - targetList); - doUpdate(targetList, (IObservableList) getModel(), diff, - targetToModel, true, true); - } - }); - } - - public void validateModelToTarget() { - // nothing for now - } - - public void validateTargetToModel() { - // nothing for now - } - - /* - * This method may be moved to UpdateListStrategy in the future if clients - * need more control over how the two lists are kept in sync. - */ - private void doUpdate(final IObservableList source, - final IObservableList destination, final ListDiff diff, - final UpdateListStrategy updateListStrategy, - final boolean explicit, final boolean clearDestination) { - final int policy = updateListStrategy.getUpdatePolicy(); - if (policy != UpdateListStrategy.POLICY_NEVER) { - if (policy != UpdateListStrategy.POLICY_ON_REQUEST || explicit) { - destination.getRealm().exec(new Runnable() { - public void run() { - if (destination == getTarget()) { - updatingTarget = true; - } else { - updatingModel = true; - } - MultiStatus multiStatus = BindingStatus.ok(); - - try { - if (clearDestination) { - destination.clear(); - } - ListDiffEntry[] diffEntries = diff.getDifferences(); - for (int i = 0; i < diffEntries.length; i++) { - ListDiffEntry listDiffEntry = diffEntries[i]; - if (listDiffEntry.isAddition()) { - IStatus setterStatus = updateListStrategy - .doAdd( - destination, - updateListStrategy - .convert(listDiffEntry - .getElement()), - listDiffEntry.getPosition()); - - mergeStatus(multiStatus, setterStatus); - // TODO - at this point, the two lists - // will be out of sync if an error occurred... - } else { - IStatus setterStatus = updateListStrategy - .doRemove(destination, - listDiffEntry.getPosition()); - - mergeStatus(multiStatus, setterStatus); - // TODO - at this point, the two lists - // will be out of sync if an error occurred... - } - } - } finally { - validationStatusObservable.setValue(multiStatus); - - if (destination == getTarget()) { - updatingTarget = false; - } else { - updatingModel = false; - } - } - } - }); - } - } - } - - /** - * Merges the provided <code>newStatus</code> into the - * <code>multiStatus</code>. - * - * @param multiStatus - * @param newStatus - */ - /* package */void mergeStatus(MultiStatus multiStatus, IStatus newStatus) { - if (!newStatus.isOK()) { - multiStatus.add(newStatus); - } - } - - public void dispose() { - if (targetChangeListener != null) { - ((IObservableList)getTarget()).removeListChangeListener(targetChangeListener); - targetChangeListener = null; - } - if (modelChangeListener != null) { - ((IObservableList)getModel()).removeListChangeListener(modelChangeListener); - modelChangeListener = null; - } - super.dispose(); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/ObservablesManager.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/ObservablesManager.java deleted file mode 100644 index 4efad459..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/ObservablesManager.java +++ /dev/null @@ -1,116 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Bob Smith - bug 198880 - *******************************************************************************/ - -package org.eclipse.core.databinding; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.internal.databinding.Pair; - -/** - * An observables manager can be used for lifecycle management of - * {@link IObservable} objects. - * - * @noextend This class is not intended to be subclassed by clients. - * - * @since 1.0 - * - */ -public class ObservablesManager { - - private Set managedObservables = new HashSet(); - private Set excludedObservables = new HashSet(); - private Map contexts = new HashMap(); - - /** - * Create a new observables manager. - */ - public ObservablesManager() { - } - - /** - * Adds the given observable to this manager. - * - * @param observable - * the observable - */ - public void addObservable(IObservable observable) { - managedObservables.add(observable); - } - - /** - * Adds the given observable to this manager's exclusion list. The given - * observable will not be disposed of by this manager. - * - * @param observable - * the observable - */ - public void excludeObservable(IObservable observable) { - excludedObservables.add(observable); - } - - /** - * Adds the given data binding context's target and/or model observables to - * this manager. - * - * @param context - * the data binding context - * @param trackTargets - * <code>true</code> if the target observables of the context - * should be managed - * @param trackModels - * <code>true</code> if the model observables of the context - * should be managed - */ - public void addObservablesFromContext(DataBindingContext context, - boolean trackTargets, boolean trackModels) { - if (trackTargets || trackModels) { - contexts.put(context, new Pair(new Boolean(trackTargets), - new Boolean(trackModels))); - } - } - - /** - * Disposes of this manager and all observables that it manages. - */ - public void dispose() { - Set observables = new HashSet(); - observables.addAll(managedObservables); - for (Iterator it = contexts.keySet().iterator(); it.hasNext();) { - DataBindingContext context = (DataBindingContext) it.next(); - Pair trackModelsOrTargets = (Pair) contexts.get(context); - boolean disposeTargets = ((Boolean) trackModelsOrTargets.a) - .booleanValue(); - boolean disposeModels = ((Boolean) trackModelsOrTargets.b) - .booleanValue(); - for (Iterator it2 = context.getBindings().iterator(); it2.hasNext();) { - Binding binding = (Binding) it2.next(); - if (disposeTargets) { - observables.add(binding.getTarget()); - } - if (disposeModels) { - observables.add(binding.getModel()); - } - } - } - observables.removeAll(excludedObservables); - for (Iterator it = observables.iterator(); it.hasNext();) { - IObservable observable = (IObservable) it.next(); - observable.dispose(); - } - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/SetBinding.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/SetBinding.java deleted file mode 100644 index 9e3d7471..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/SetBinding.java +++ /dev/null @@ -1,225 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 124684) - * IBM Corporation - through ListBinding.java - ******************************************************************************/ - -package org.eclipse.core.databinding; - -import java.util.Collections; -import java.util.Iterator; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.ISetChangeListener; -import org.eclipse.core.databinding.observable.set.SetChangeEvent; -import org.eclipse.core.databinding.observable.set.SetDiff; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.internal.databinding.BindingStatus; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.core.runtime.Status; - -/** - * @since 1.1 - * - */ -public class SetBinding extends Binding { - - private UpdateSetStrategy targetToModel; - private UpdateSetStrategy modelToTarget; - private IObservableValue validationStatusObservable; - private boolean updatingTarget; - private boolean updatingModel; - - private ISetChangeListener targetChangeListener = new ISetChangeListener() { - public void handleSetChange(SetChangeEvent event) { - if (!updatingTarget) { - doUpdate((IObservableSet) getTarget(), - (IObservableSet) getModel(), event.diff, targetToModel, - false, false); - } - } - }; - - private ISetChangeListener modelChangeListener = new ISetChangeListener() { - public void handleSetChange(SetChangeEvent event) { - if (!updatingModel) { - doUpdate((IObservableSet) getModel(), - (IObservableSet) getTarget(), event.diff, - modelToTarget, false, false); - } - } - }; - - /** - * @param target - * @param model - * @param modelToTargetStrategy - * @param targetToModelStrategy - */ - public SetBinding(IObservableSet target, IObservableSet model, - UpdateSetStrategy targetToModelStrategy, - UpdateSetStrategy modelToTargetStrategy) { - super(target, model); - this.targetToModel = targetToModelStrategy; - this.modelToTarget = modelToTargetStrategy; - if ((targetToModel.getUpdatePolicy() & UpdateSetStrategy.POLICY_UPDATE) != 0) { - target.addSetChangeListener(targetChangeListener); - } else { - targetChangeListener = null; - } - if ((modelToTarget.getUpdatePolicy() & UpdateSetStrategy.POLICY_UPDATE) != 0) { - model.addSetChangeListener(modelChangeListener); - } else { - modelChangeListener = null; - } - } - - public IObservableValue getValidationStatus() { - return validationStatusObservable; - } - - protected void preInit() { - validationStatusObservable = new WritableValue(context - .getValidationRealm(), Status.OK_STATUS, IStatus.class); - } - - protected void postInit() { - if (modelToTarget.getUpdatePolicy() == UpdateSetStrategy.POLICY_UPDATE) { - updateModelToTarget(); - } - if (targetToModel.getUpdatePolicy() != UpdateSetStrategy.POLICY_NEVER) { - validateTargetToModel(); - } - } - - public void updateModelToTarget() { - final IObservableSet modelSet = (IObservableSet) getModel(); - modelSet.getRealm().exec(new Runnable() { - public void run() { - SetDiff diff = Diffs.computeSetDiff(Collections.EMPTY_SET, - modelSet); - doUpdate(modelSet, (IObservableSet) getTarget(), diff, - modelToTarget, true, true); - } - }); - } - - public void updateTargetToModel() { - final IObservableSet targetSet = (IObservableSet) getTarget(); - targetSet.getRealm().exec(new Runnable() { - public void run() { - SetDiff diff = Diffs.computeSetDiff(Collections.EMPTY_SET, - targetSet); - doUpdate(targetSet, (IObservableSet) getModel(), diff, - targetToModel, true, true); - } - }); - } - - public void validateModelToTarget() { - // nothing for now - } - - public void validateTargetToModel() { - // nothing for now - } - - /* - * This method may be moved to UpdateSetStrategy in the future if clients - * need more control over how the two sets are kept in sync. - */ - private void doUpdate(final IObservableSet source, - final IObservableSet destination, final SetDiff diff, - final UpdateSetStrategy updateSetStrategy, final boolean explicit, - final boolean clearDestination) { - final int policy = updateSetStrategy.getUpdatePolicy(); - if (policy == UpdateSetStrategy.POLICY_NEVER) - return; - if (policy == UpdateSetStrategy.POLICY_ON_REQUEST && !explicit) - return; - destination.getRealm().exec(new Runnable() { - public void run() { - if (destination == getTarget()) { - updatingTarget = true; - } else { - updatingModel = true; - } - MultiStatus multiStatus = BindingStatus.ok(); - - try { - if (clearDestination) { - destination.clear(); - } - - for (Iterator iterator = diff.getRemovals().iterator(); iterator - .hasNext();) { - IStatus setterStatus = updateSetStrategy.doRemove( - destination, updateSetStrategy.convert(iterator - .next())); - - mergeStatus(multiStatus, setterStatus); - // TODO - at this point, the two sets - // will be out of sync if an error - // occurred... - } - - for (Iterator iterator = diff.getAdditions().iterator(); iterator - .hasNext();) { - IStatus setterStatus = updateSetStrategy.doAdd( - destination, updateSetStrategy.convert(iterator - .next())); - - mergeStatus(multiStatus, setterStatus); - // TODO - at this point, the two sets - // will be out of sync if an error - // occurred... - } - } finally { - validationStatusObservable.setValue(multiStatus); - - if (destination == getTarget()) { - updatingTarget = false; - } else { - updatingModel = false; - } - } - } - }); - } - - /** - * Merges the provided <code>newStatus</code> into the - * <code>multiStatus</code>. - * - * @param multiStatus - * @param newStatus - */ - /* package */void mergeStatus(MultiStatus multiStatus, IStatus newStatus) { - if (!newStatus.isOK()) { - multiStatus.add(newStatus); - } - } - - public void dispose() { - if (targetChangeListener != null) { - ((IObservableSet) getTarget()) - .removeSetChangeListener(targetChangeListener); - targetChangeListener = null; - } - if (modelChangeListener != null) { - ((IObservableSet) getModel()) - .removeSetChangeListener(modelChangeListener); - modelChangeListener = null; - } - super.dispose(); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateListStrategy.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateListStrategy.java deleted file mode 100644 index de8d9497..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateListStrategy.java +++ /dev/null @@ -1,232 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Tom Schindl<tom.schindl@bestsolution.at> - bugfix for 217940 - *******************************************************************************/ - -package org.eclipse.core.databinding; - -import org.eclipse.core.databinding.conversion.IConverter; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.validation.ValidationStatus; -import org.eclipse.core.internal.databinding.BindingMessages; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; - -/** - * Customizes a {@link Binding} between two - * {@link IObservableList observable lists}. The following behaviors can be - * customized via the strategy: - * <ul> - * <li>Conversion</li> - * <li>Automatic processing</li> - * </ul> - * <p> - * Conversion:<br/> When elements are added they can be - * {@link #convert(Object) converted} to the destination element type. - * </p> - * <p> - * Automatic processing:<br/> The processing to perform when the source - * observable changes. This behavior is configured via policies provided on - * construction of the strategy (e.g. {@link #POLICY_NEVER}, - * {@link #POLICY_ON_REQUEST}, {@link #POLICY_UPDATE}). - * </p> - * - * - * @see DataBindingContext#bindList(IObservableList, IObservableList, - * UpdateListStrategy, UpdateListStrategy) - * @see IConverter - * @since 1.0 - */ -public class UpdateListStrategy extends UpdateStrategy { - - /** - * Policy constant denoting that the source observable's state should not be - * tracked and that the destination observable's state should never be - * updated. - */ - public static int POLICY_NEVER = notInlined(1); - - /** - * Policy constant denoting that the source observable's state should not be - * tracked, but that conversion and updating the destination observable's - * state should be performed when explicitly requested. - */ - public static int POLICY_ON_REQUEST = notInlined(2); - - /** - * Policy constant denoting that the source observable's state should be - * tracked, and that conversion and updating the destination observable's - * state should be performed automatically on every change of the source - * observable state. - */ - public static int POLICY_UPDATE = notInlined(8); - - /** - * Helper method allowing API evolution of the above constant values. The - * compiler will not inline constant values into client code if values are - * "computed" using this helper. - * - * @param i - * an integer - * @return the same integer - */ - private static int notInlined(int i) { - return i; - } - - protected IConverter converter; - - private int updatePolicy; - - protected boolean provideDefaults; - - /** - * Creates a new update list strategy for automatically updating the - * destination observable list whenever the source observable list changes. - * A default converter will be provided. The defaults can be changed by - * calling one of the setter methods. - */ - public UpdateListStrategy() { - this(true, POLICY_UPDATE); - } - - /** - * Creates a new update list strategy with a configurable update policy. A - * default converter will be provided. The defaults can be changed by - * calling one of the setter methods. - * - * @param updatePolicy - * one of {@link #POLICY_NEVER}, {@link #POLICY_ON_REQUEST}, or - * {@link #POLICY_UPDATE} - */ - public UpdateListStrategy(int updatePolicy) { - this(true, updatePolicy); - } - - /** - * Creates a new update list strategy with a configurable update policy. A - * default converter will be provided if <code>provideDefaults</code> is - * <code>true</code>. The defaults can be changed by calling one of the - * setter methods. - * - * @param provideDefaults - * if <code>true</code>, default validators and a default - * converter will be provided based on the observable list's - * type. - * @param updatePolicy - * one of {@link #POLICY_NEVER}, {@link #POLICY_ON_REQUEST}, or - * {@link #POLICY_UPDATE} - */ - public UpdateListStrategy(boolean provideDefaults, int updatePolicy) { - this.provideDefaults = provideDefaults; - this.updatePolicy = updatePolicy; - } - - /** - * When an element is added to the destination converts the element from the - * source element type to the destination element type. - * <p> - * Default implementation will use the - * {@link #setConverter(IConverter) converter} if one exists. If no - * converter exists no conversion occurs. - * </p> - * - * @param element - * @return the converted element - */ - public Object convert(Object element) { - return converter == null ? element : converter.convert(element); - } - - /** - * - * @param source - * @param destination - */ - protected void fillDefaults(IObservableList source, - IObservableList destination) { - Object sourceType = source.getElementType(); - Object destinationType = destination.getElementType(); - if (provideDefaults && sourceType != null && destinationType != null) { - if (converter == null) { - setConverter(createConverter(sourceType, destinationType)); - } - } - if (converter != null) { - if (sourceType != null) { - checkAssignable(converter.getFromType(), sourceType, - "converter does not convert from type " + sourceType); //$NON-NLS-1$ - } - if (destinationType != null) { - checkAssignable(converter.getToType(), destinationType, - "converter does not convert to type " + destinationType); //$NON-NLS-1$ - } - } - } - - /** - * @return the update policy - */ - public int getUpdatePolicy() { - return updatePolicy; - } - - /** - * Sets the converter to be invoked when converting added elements from the - * source element type to the destination element type. - * - * @param converter - * @return the receiver, to enable method call chaining - */ - public UpdateListStrategy setConverter(IConverter converter) { - this.converter = converter; - return this; - } - - /** - * Adds the given element at the given index to the given observable list. - * Clients may extend but must call the super implementation. - * - * @param observableList - * @param element - * @param index - * @return a status - */ - protected IStatus doAdd(IObservableList observableList, Object element, - int index) { - try { - observableList.add(index, element); - } catch (Exception ex) { - return ValidationStatus.error(BindingMessages - .getString(BindingMessages.VALUEBINDING_ERROR_WHILE_SETTING_VALUE), - ex); - } - return Status.OK_STATUS; - } - - /** - * Removes the element at the given index from the given observable list. - * Clients may extend but must call the super implementation. - * - * @param observableList - * @param index - * @return a status - */ - protected IStatus doRemove(IObservableList observableList, int index) { - try { - observableList.remove(index); - } catch (Exception ex) { - return ValidationStatus.error(BindingMessages - .getString(BindingMessages.VALUEBINDING_ERROR_WHILE_SETTING_VALUE), - ex); - } - return Status.OK_STATUS; - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateSetStrategy.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateSetStrategy.java deleted file mode 100644 index 8867bbdf..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateSetStrategy.java +++ /dev/null @@ -1,230 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 124684) - * IBM Corporation - through UpdateListStrategy.java - ******************************************************************************/ - -package org.eclipse.core.databinding; - -import org.eclipse.core.databinding.conversion.IConverter; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.validation.ValidationStatus; -import org.eclipse.core.internal.databinding.BindingMessages; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; - -/** - * Customizes a {@link Binding} between two - * {@link IObservableSet observable sets}. The following behaviors can be - * customized via the strategy: - * <ul> - * <li>Conversion</li> - * <li>Automatic processing</li> - * </ul> - * <p> - * Conversion:<br/> When elements are added they can be - * {@link #convert(Object) converted} to the destination element type. - * </p> - * <p> - * Automatic processing:<br/> The processing to perform when the source - * observable changes. This behavior is configured via policies provided on - * construction of the strategy (e.g. {@link #POLICY_NEVER}, - * {@link #POLICY_ON_REQUEST}, {@link #POLICY_UPDATE}). - * </p> - * - * - * @see DataBindingContext#bindSet(IObservableSet, IObservableSet, - * UpdateSetStrategy, UpdateSetStrategy) - * @see IConverter - * @since 1.1 - */ -public class UpdateSetStrategy extends UpdateStrategy { - - /** - * Policy constant denoting that the source observable's state should not be - * tracked and that the destination observable's state should never be - * updated. - */ - public final static int POLICY_NEVER = notInlined(1); - - /** - * Policy constant denoting that the source observable's state should not be - * tracked, but that conversion and updating the destination observable's - * state should be performed when explicitly requested. - */ - public final static int POLICY_ON_REQUEST = notInlined(2); - - /** - * Policy constant denoting that the source observable's state should be - * tracked, and that conversion and updating the destination observable's - * state should be performed automatically on every change of the source - * observable state. - */ - public final static int POLICY_UPDATE = notInlined(8); - - /** - * Helper method allowing API evolution of the above constant values. The - * compiler will not inline constant values into client code if values are - * "computed" using this helper. - * - * @param i - * an integer - * @return the same integer - */ - private static int notInlined(int i) { - return i; - } - - protected IConverter converter; - - private int updatePolicy; - - protected boolean provideDefaults; - - /** - * Creates a new update list strategy for automatically updating the - * destination observable list whenever the source observable list changes. - * A default converter will be provided. The defaults can be changed by - * calling one of the setter methods. - */ - public UpdateSetStrategy() { - this(true, POLICY_UPDATE); - } - - /** - * Creates a new update list strategy with a configurable update policy. A - * default converter will be provided. The defaults can be changed by - * calling one of the setter methods. - * - * @param updatePolicy - * one of {@link #POLICY_NEVER}, {@link #POLICY_ON_REQUEST}, or - * {@link #POLICY_UPDATE} - */ - public UpdateSetStrategy(int updatePolicy) { - this(true, updatePolicy); - } - - /** - * Creates a new update list strategy with a configurable update policy. A - * default converter will be provided if <code>provideDefaults</code> is - * <code>true</code>. The defaults can be changed by calling one of the - * setter methods. - * - * @param provideDefaults - * if <code>true</code>, default validators and a default - * converter will be provided based on the observable list's - * type. - * @param updatePolicy - * one of {@link #POLICY_NEVER}, {@link #POLICY_ON_REQUEST}, or - * {@link #POLICY_UPDATE} - */ - public UpdateSetStrategy(boolean provideDefaults, int updatePolicy) { - this.provideDefaults = provideDefaults; - this.updatePolicy = updatePolicy; - } - - /** - * When an element is added to the destination converts the element from the - * source element type to the destination element type. - * <p> - * Default implementation will use the - * {@link #setConverter(IConverter) converter} if one exists. If no - * converter exists no conversion occurs. - * </p> - * - * @param element - * @return the converted element - */ - public Object convert(Object element) { - return converter == null ? element : converter.convert(element); - } - - /** - * - * @param source - * @param destination - */ - protected void fillDefaults(IObservableSet source, - IObservableSet destination) { - Object sourceType = source.getElementType(); - Object destinationType = destination.getElementType(); - if (provideDefaults && sourceType != null && destinationType != null) { - if (converter == null) { - setConverter(createConverter(sourceType, destinationType)); - } - } - if (converter != null) { - if (sourceType != null) { - checkAssignable(converter.getFromType(), sourceType, - "converter does not convert from type " + sourceType); //$NON-NLS-1$ - } - if (destinationType != null) { - checkAssignable(converter.getToType(), destinationType, - "converter does not convert to type " + destinationType); //$NON-NLS-1$ - } - } - } - - /** - * @return the update policy - */ - public int getUpdatePolicy() { - return updatePolicy; - } - - /** - * Sets the converter to be invoked when converting added elements from the - * source element type to the destination element type. - * - * @param converter - * @return the receiver, to enable method call chaining - */ - public UpdateSetStrategy setConverter(IConverter converter) { - this.converter = converter; - return this; - } - - /** - * Adds the given element at the given index to the given observable list. - * Clients may extend but must call the super implementation. - * - * @param observableSet - * @param element - * @return a status - */ - protected IStatus doAdd(IObservableSet observableSet, Object element) { - try { - observableSet.add(element); - } catch (Exception ex) { - return ValidationStatus.error(BindingMessages - .getString("ValueBinding_ErrorWhileSettingValue"), //$NON-NLS-1$ - ex); - } - return Status.OK_STATUS; - } - - /** - * Removes the element at the given index from the given observable list. - * Clients may extend but must call the super implementation. - * - * @param observableSet - * @param element - * @return a status - */ - protected IStatus doRemove(IObservableSet observableSet, Object element) { - try { - observableSet.remove(element); - } catch (Exception ex) { - return ValidationStatus.error(BindingMessages - .getString("ValueBinding_ErrorWhileSettingValue"), //$NON-NLS-1$ - ex); - } - return Status.OK_STATUS; - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateStrategy.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateStrategy.java deleted file mode 100644 index f8adb898..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateStrategy.java +++ /dev/null @@ -1,710 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matt Carter - Bug 180392 - * - Character support completed (bug 197679) - *******************************************************************************/ - -package org.eclipse.core.databinding; - -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.databinding.conversion.IConverter; -import org.eclipse.core.databinding.conversion.NumberToStringConverter; -import org.eclipse.core.databinding.conversion.StringToNumberConverter; -import org.eclipse.core.databinding.util.Policy; -import org.eclipse.core.internal.databinding.ClassLookupSupport; -import org.eclipse.core.internal.databinding.Pair; -import org.eclipse.core.internal.databinding.conversion.CharacterToStringConverter; -import org.eclipse.core.internal.databinding.conversion.IdentityConverter; -import org.eclipse.core.internal.databinding.conversion.IntegerToStringConverter; -import org.eclipse.core.internal.databinding.conversion.NumberToBigDecimalConverter; -import org.eclipse.core.internal.databinding.conversion.NumberToBigIntegerConverter; -import org.eclipse.core.internal.databinding.conversion.NumberToByteConverter; -import org.eclipse.core.internal.databinding.conversion.NumberToDoubleConverter; -import org.eclipse.core.internal.databinding.conversion.NumberToFloatConverter; -import org.eclipse.core.internal.databinding.conversion.NumberToIntegerConverter; -import org.eclipse.core.internal.databinding.conversion.NumberToLongConverter; -import org.eclipse.core.internal.databinding.conversion.NumberToShortConverter; -import org.eclipse.core.internal.databinding.conversion.ObjectToStringConverter; -import org.eclipse.core.internal.databinding.conversion.StringToByteConverter; -import org.eclipse.core.internal.databinding.conversion.StringToCharacterConverter; -import org.eclipse.core.internal.databinding.conversion.StringToShortConverter; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; - -import com.ibm.icu.text.NumberFormat; - -/** - * @since 1.0 - * - */ -/* package */class UpdateStrategy { - - private static final String BOOLEAN_TYPE = "java.lang.Boolean.TYPE"; //$NON-NLS-1$ - - private static final String SHORT_TYPE = "java.lang.Short.TYPE"; //$NON-NLS-1$ - - private static final String BYTE_TYPE = "java.lang.Byte.TYPE"; //$NON-NLS-1$ - - private static final String DOUBLE_TYPE = "java.lang.Double.TYPE"; //$NON-NLS-1$ - - private static final String FLOAT_TYPE = "java.lang.Float.TYPE"; //$NON-NLS-1$ - - private static final String INTEGER_TYPE = "java.lang.Integer.TYPE"; //$NON-NLS-1$ - - private static final String LONG_TYPE = "java.lang.Long.TYPE"; //$NON-NLS-1$ - - private static final String CHARACTER_TYPE = "java.lang.Character.TYPE"; //$NON-NLS-1$ - - private static Map converterMap; - - private static Class autoboxed(Class clazz) { - if (clazz == Float.TYPE) - return Float.class; - else if (clazz == Double.TYPE) - return Double.class; - else if (clazz == Short.TYPE) - return Short.class; - else if (clazz == Integer.TYPE) - return Integer.class; - else if (clazz == Long.TYPE) - return Long.class; - else if (clazz == Byte.TYPE) - return Byte.class; - else if (clazz == Boolean.TYPE) - return Boolean.class; - else if (clazz == Character.TYPE) - return Character.class; - return clazz; - } - - final protected void checkAssignable(Object toType, Object fromType, - String errorString) { - Boolean assignableFromModelToModelConverter = isAssignableFromTo( - fromType, toType); - if (assignableFromModelToModelConverter != null - && !assignableFromModelToModelConverter.booleanValue()) { - throw new BindingException(errorString - + " Expected: " + fromType + ", actual: " + toType); //$NON-NLS-1$//$NON-NLS-2$ - } - } - - /** - * Tries to create a converter that can convert from values of type - * fromType. Returns <code>null</code> if no converter could be created. - * Either toType or modelDescription can be <code>null</code>, but not - * both. - * - * @param fromType - * @param toType - * @return an IConverter, or <code>null</code> if unsuccessful - */ - protected IConverter createConverter(Object fromType, Object toType) { - if (!(fromType instanceof Class) || !(toType instanceof Class)) { - return new DefaultConverter(fromType, toType); - } - Class toClass = (Class) toType; - Class originalToClass = toClass; - if (toClass.isPrimitive()) { - toClass = autoboxed(toClass); - } - Class fromClass = (Class) fromType; - Class originalFromClass = fromClass; - if (fromClass.isPrimitive()) { - fromClass = autoboxed(fromClass); - } - if (!((Class) toType).isPrimitive() - && toClass.isAssignableFrom(fromClass)) { - return new IdentityConverter(originalFromClass, originalToClass); - } - if (((Class) fromType).isPrimitive() && ((Class) toType).isPrimitive() - && fromType.equals(toType)) { - return new IdentityConverter(originalFromClass, originalToClass); - } - Map converterMap = getConverterMap(); - Class[] supertypeHierarchyFlattened = ClassLookupSupport - .getTypeHierarchyFlattened(fromClass); - for (int i = 0; i < supertypeHierarchyFlattened.length; i++) { - Class currentFromClass = supertypeHierarchyFlattened[i]; - if (currentFromClass == toType) { - // converting to toType is just a widening - return new IdentityConverter(fromClass, toClass); - } - Pair key = new Pair(getKeyForClass(fromType, currentFromClass), - getKeyForClass(toType, toClass)); - Object converterOrClassname = converterMap.get(key); - if (converterOrClassname instanceof IConverter) { - return (IConverter) converterOrClassname; - } else if (converterOrClassname instanceof String) { - String classname = (String) converterOrClassname; - Class converterClass; - try { - converterClass = Class.forName(classname); - IConverter result = (IConverter) converterClass - .newInstance(); - converterMap.put(key, result); - return result; - } catch (Exception e) { - Policy - .getLog() - .log( - new Status( - IStatus.ERROR, - Policy.JFACE_DATABINDING, - 0, - "Error while instantiating default converter", e)); //$NON-NLS-1$ - } - } - } - // Since we found no converter yet, try a "downcast" converter; - // the IdentityConverter will automatically check the actual types at - // runtime. - if (fromClass.isAssignableFrom(toClass)) { - return new IdentityConverter(originalFromClass, originalToClass); - } - return new DefaultConverter(fromType, toType); - } - - private synchronized static Map getConverterMap() { - // using string-based lookup avoids loading of too many classes - if (converterMap == null) { - // NumberFormat to be shared across converters for the formatting of - // integer values - NumberFormat integerFormat = NumberFormat.getIntegerInstance(); - // NumberFormat to be shared across converters for formatting non - // integer values - NumberFormat numberFormat = NumberFormat.getNumberInstance(); - - converterMap = new HashMap(); - // Standard and Boxed Types - converterMap - .put( - new Pair("java.util.Date", "java.lang.String"), "org.eclipse.core.internal.databinding.conversion.DateToStringConverter"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - converterMap - .put( - new Pair("java.lang.String", "java.lang.Boolean"), "org.eclipse.core.internal.databinding.conversion.StringToBooleanConverter"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - converterMap - .put( - new Pair("java.lang.String", "java.lang.Byte"), StringToByteConverter.toByte(integerFormat, false)); //$NON-NLS-1$//$NON-NLS-2$ - converterMap - .put( - new Pair("java.lang.String", "java.util.Date"), "org.eclipse.core.internal.databinding.conversion.StringToDateConverter"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - converterMap - .put( - new Pair("java.lang.String", "java.lang.Short"), StringToShortConverter.toShort(integerFormat, false)); //$NON-NLS-1$//$NON-NLS-2$ - converterMap - .put( - new Pair("java.lang.String", "java.lang.Character"), StringToCharacterConverter.toCharacter(false)); //$NON-NLS-1$//$NON-NLS-2$ - converterMap - .put( - new Pair("java.lang.String", "java.lang.Integer"), StringToNumberConverter.toInteger(integerFormat, false)); //$NON-NLS-1$//$NON-NLS-2$ - converterMap - .put( - new Pair("java.lang.String", "java.lang.Double"), StringToNumberConverter.toDouble(numberFormat, false)); //$NON-NLS-1$//$NON-NLS-2$ - converterMap - .put( - new Pair("java.lang.String", "java.lang.Long"), StringToNumberConverter.toLong(integerFormat, false)); //$NON-NLS-1$//$NON-NLS-2$ - converterMap - .put( - new Pair("java.lang.String", "java.lang.Float"), StringToNumberConverter.toFloat(numberFormat, false)); //$NON-NLS-1$//$NON-NLS-2$ - converterMap - .put( - new Pair("java.lang.String", "java.math.BigInteger"), StringToNumberConverter.toBigInteger(integerFormat)); //$NON-NLS-1$//$NON-NLS-2$ - converterMap - .put( - new Pair("java.lang.Integer", "java.lang.String"), NumberToStringConverter.fromInteger(integerFormat, false)); //$NON-NLS-1$//$NON-NLS-2$ - converterMap - .put( - new Pair("java.lang.Long", "java.lang.String"), NumberToStringConverter.fromLong(integerFormat, false)); //$NON-NLS-1$//$NON-NLS-2$ - converterMap - .put( - new Pair("java.lang.Double", "java.lang.String"), NumberToStringConverter.fromDouble(numberFormat, false)); //$NON-NLS-1$//$NON-NLS-2$ - converterMap - .put( - new Pair("java.lang.Float", "java.lang.String"), NumberToStringConverter.fromFloat(numberFormat, false)); //$NON-NLS-1$//$NON-NLS-2$ - converterMap - .put( - new Pair("java.math.BigInteger", "java.lang.String"), NumberToStringConverter.fromBigInteger(integerFormat)); //$NON-NLS-1$//$NON-NLS-2$ - converterMap - .put( - new Pair("java.lang.Byte", "java.lang.String"), IntegerToStringConverter.fromByte(integerFormat, false)); //$NON-NLS-1$//$NON-NLS-2$ - converterMap - .put( - new Pair("java.lang.Short", "java.lang.String"), IntegerToStringConverter.fromShort(integerFormat, false)); //$NON-NLS-1$//$NON-NLS-2$ - converterMap - .put( - new Pair("java.lang.Character", "java.lang.String"), CharacterToStringConverter.fromCharacter(false)); //$NON-NLS-1$//$NON-NLS-2$ - - converterMap - .put( - new Pair("java.lang.Object", "java.lang.String"), "org.eclipse.core.internal.databinding.conversion.ObjectToStringConverter"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - - // Integer.TYPE - converterMap - .put( - new Pair("java.lang.String", INTEGER_TYPE), StringToNumberConverter.toInteger(integerFormat, true)); //$NON-NLS-1$ - converterMap - .put( - new Pair(INTEGER_TYPE, "java.lang.Integer"), new IdentityConverter(Integer.TYPE, Integer.class)); //$NON-NLS-1$ - converterMap - .put( - new Pair(INTEGER_TYPE, "java.lang.Object"), new IdentityConverter(Integer.TYPE, Object.class)); //$NON-NLS-1$ - converterMap - .put( - new Pair(INTEGER_TYPE, "java.lang.String"), NumberToStringConverter.fromInteger(integerFormat, true)); //$NON-NLS-1$ - - // Byte.TYPE - converterMap - .put( - new Pair("java.lang.String", BYTE_TYPE), StringToByteConverter.toByte(integerFormat, true)); //$NON-NLS-1$ - converterMap - .put( - new Pair(BYTE_TYPE, "java.lang.Byte"), new IdentityConverter(Byte.TYPE, Byte.class)); //$NON-NLS-1$ - converterMap - .put( - new Pair(BYTE_TYPE, "java.lang.String"), IntegerToStringConverter.fromByte(integerFormat, true)); //$NON-NLS-1$ - converterMap - .put( - new Pair(BYTE_TYPE, "java.lang.Object"), new IdentityConverter(Byte.TYPE, Object.class)); //$NON-NLS-1$ - - // Double.TYPE - converterMap - .put( - new Pair("java.lang.String", DOUBLE_TYPE), StringToNumberConverter.toDouble(numberFormat, true)); //$NON-NLS-1$ - converterMap - .put( - new Pair(DOUBLE_TYPE, "java.lang.String"), NumberToStringConverter.fromDouble(numberFormat, true)); //$NON-NLS-1$ - - converterMap - .put( - new Pair(DOUBLE_TYPE, "java.lang.Double"), new IdentityConverter(Double.TYPE, Double.class)); //$NON-NLS-1$ - converterMap - .put( - new Pair(DOUBLE_TYPE, "java.lang.Object"), new IdentityConverter(Double.TYPE, Object.class)); //$NON-NLS-1$ - - // Boolean.TYPE - converterMap - .put( - new Pair("java.lang.String", BOOLEAN_TYPE), "org.eclipse.core.internal.databinding.conversion.StringToBooleanPrimitiveConverter"); //$NON-NLS-1$ //$NON-NLS-2$ - converterMap - .put( - new Pair(BOOLEAN_TYPE, "java.lang.Boolean"), new IdentityConverter(Boolean.TYPE, Boolean.class)); //$NON-NLS-1$ - converterMap - .put( - new Pair(BOOLEAN_TYPE, "java.lang.String"), new ObjectToStringConverter(Boolean.TYPE)); //$NON-NLS-1$ - converterMap - .put( - new Pair(BOOLEAN_TYPE, "java.lang.Object"), new IdentityConverter(Boolean.TYPE, Object.class)); //$NON-NLS-1$ - - // Float.TYPE - converterMap - .put( - new Pair("java.lang.String", FLOAT_TYPE), StringToNumberConverter.toFloat(numberFormat, true)); //$NON-NLS-1$ - converterMap - .put( - new Pair(FLOAT_TYPE, "java.lang.String"), NumberToStringConverter.fromFloat(numberFormat, true)); //$NON-NLS-1$ - converterMap - .put( - new Pair(FLOAT_TYPE, "java.lang.Float"), new IdentityConverter(Float.TYPE, Float.class)); //$NON-NLS-1$ - converterMap - .put( - new Pair(FLOAT_TYPE, "java.lang.Object"), new IdentityConverter(Float.TYPE, Object.class)); //$NON-NLS-1$ - - // Short.TYPE - converterMap - .put( - new Pair("java.lang.String", SHORT_TYPE), StringToShortConverter.toShort(integerFormat, true)); //$NON-NLS-1$ - converterMap - .put( - new Pair(SHORT_TYPE, "java.lang.Short"), new IdentityConverter(Short.TYPE, Short.class)); //$NON-NLS-1$ - converterMap - .put( - new Pair(SHORT_TYPE, "java.lang.String"), IntegerToStringConverter.fromShort(integerFormat, true)); //$NON-NLS-1$ - converterMap - .put( - new Pair(SHORT_TYPE, "java.lang.Object"), new IdentityConverter(Short.TYPE, Object.class)); //$NON-NLS-1$ - - // Long.TYPE - converterMap - .put( - new Pair("java.lang.String", LONG_TYPE), StringToNumberConverter.toLong(integerFormat, true)); //$NON-NLS-1$ - converterMap - .put( - new Pair(LONG_TYPE, "java.lang.String"), NumberToStringConverter.fromLong(integerFormat, true)); //$NON-NLS-1$ - converterMap - .put( - new Pair(LONG_TYPE, "java.lang.Long"), new IdentityConverter(Long.TYPE, Long.class)); //$NON-NLS-1$ - converterMap - .put( - new Pair(LONG_TYPE, "java.lang.Object"), new IdentityConverter(Long.TYPE, Object.class)); //$NON-NLS-1$ - - // Character.TYPE - converterMap - .put( - new Pair("java.lang.String", CHARACTER_TYPE), StringToCharacterConverter.toCharacter(true)); //$NON-NLS-1$ - converterMap - .put( - new Pair(CHARACTER_TYPE, "java.lang.Character"), new IdentityConverter(Character.TYPE, Character.class)); //$NON-NLS-1$ - converterMap - .put( - new Pair(CHARACTER_TYPE, "java.lang.String"), CharacterToStringConverter.fromCharacter(true)); //$NON-NLS-1$ - converterMap - .put( - new Pair(CHARACTER_TYPE, "java.lang.Object"), new IdentityConverter(Character.TYPE, Object.class)); //$NON-NLS-1$ - - // Miscellaneous - converterMap - .put( - new Pair( - "org.eclipse.core.runtime.IStatus", "java.lang.String"), "org.eclipse.core.internal.databinding.conversion.StatusToStringConverter"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - - addNumberToByteConverters(converterMap, integerFormat, - integerClasses); - addNumberToByteConverters(converterMap, numberFormat, floatClasses); - - addNumberToShortConverters(converterMap, integerFormat, - integerClasses); - addNumberToShortConverters(converterMap, numberFormat, floatClasses); - - addNumberToIntegerConverters(converterMap, integerFormat, - integerClasses); - addNumberToIntegerConverters(converterMap, numberFormat, - floatClasses); - - addNumberToLongConverters(converterMap, integerFormat, - integerClasses); - addNumberToLongConverters(converterMap, numberFormat, floatClasses); - - addNumberToFloatConverters(converterMap, integerFormat, - integerClasses); - addNumberToFloatConverters(converterMap, numberFormat, floatClasses); - - addNumberToDoubleConverters(converterMap, integerFormat, - integerClasses); - addNumberToDoubleConverters(converterMap, numberFormat, - floatClasses); - - addNumberToBigIntegerConverters(converterMap, integerFormat, - integerClasses); - addNumberToBigIntegerConverters(converterMap, numberFormat, - floatClasses); - - addNumberToBigDecimalConverters(converterMap, integerFormat, - integerClasses); - addNumberToBigDecimalConverters(converterMap, numberFormat, - floatClasses); - } - - return converterMap; - } - - private static final Class[] integerClasses = new Class[] { Byte.TYPE, - Byte.class, Short.TYPE, Short.class, Integer.TYPE, Integer.class, - Long.TYPE, Long.class, BigInteger.class }; - - private static final Class[] floatClasses = new Class[] { Float.TYPE, - Float.class, Double.TYPE, Double.class, BigDecimal.class }; - - /** - * Registers converters to boxed and unboxed types from a list of from - * classes. - * - * @param map - * @param numberFormat - * @param fromTypes - */ - private static void addNumberToByteConverters(Map map, - NumberFormat numberFormat, Class[] fromTypes) { - - for (int i = 0; i < fromTypes.length; i++) { - Class fromType = fromTypes[i]; - if (!fromType.equals(Byte.class) && !fromType.equals(Byte.TYPE)) { - String fromName = (fromType.isPrimitive()) ? getKeyForClass( - fromType, null) : fromType.getName(); - - map - .put(new Pair(fromName, BYTE_TYPE), - new NumberToByteConverter(numberFormat, - fromType, true)); - map - .put(new Pair(fromName, Byte.class.getName()), - new NumberToByteConverter(numberFormat, - fromType, false)); - } - } - } - - /** - * Registers converters to boxed and unboxed types from a list of from - * classes. - * - * @param map - * @param numberFormat - * @param fromTypes - */ - private static void addNumberToShortConverters(Map map, - NumberFormat numberFormat, Class[] fromTypes) { - for (int i = 0; i < fromTypes.length; i++) { - Class fromType = fromTypes[i]; - if (!fromType.equals(Short.class) && !fromType.equals(Short.TYPE)) { - String fromName = (fromType.isPrimitive()) ? getKeyForClass( - fromType, null) : fromType.getName(); - - map - .put(new Pair(fromName, SHORT_TYPE), - new NumberToShortConverter(numberFormat, - fromType, true)); - map.put(new Pair(fromName, Short.class.getName()), - new NumberToShortConverter(numberFormat, fromType, - false)); - } - } - } - - /** - * Registers converters to boxed and unboxed types from a list of from - * classes. - * - * @param map - * @param numberFormat - * @param fromTypes - */ - private static void addNumberToIntegerConverters(Map map, - NumberFormat numberFormat, Class[] fromTypes) { - for (int i = 0; i < fromTypes.length; i++) { - Class fromType = fromTypes[i]; - if (!fromType.equals(Integer.class) - && !fromType.equals(Integer.TYPE)) { - String fromName = (fromType.isPrimitive()) ? getKeyForClass( - fromType, null) : fromType.getName(); - - map.put(new Pair(fromName, INTEGER_TYPE), - new NumberToIntegerConverter(numberFormat, fromType, - true)); - map.put(new Pair(fromName, Integer.class.getName()), - new NumberToIntegerConverter(numberFormat, fromType, - false)); - } - } - } - - /** - * Registers converters to boxed and unboxed types from a list of from - * classes. - * - * @param map - * @param numberFormat - * @param fromTypes - */ - private static void addNumberToLongConverters(Map map, - NumberFormat numberFormat, Class[] fromTypes) { - for (int i = 0; i < fromTypes.length; i++) { - Class fromType = fromTypes[i]; - if (!fromType.equals(Long.class) && !fromType.equals(Long.TYPE)) { - String fromName = (fromType.isPrimitive()) ? getKeyForClass( - fromType, null) : fromType.getName(); - - map - .put(new Pair(fromName, LONG_TYPE), - new NumberToLongConverter(numberFormat, - fromType, true)); - map - .put(new Pair(fromName, Long.class.getName()), - new NumberToLongConverter(numberFormat, - fromType, false)); - } - } - } - - /** - * Registers converters to boxed and unboxed types from a list of from - * classes. - * - * @param map - * @param numberFormat - * @param fromTypes - */ - private static void addNumberToFloatConverters(Map map, - NumberFormat numberFormat, Class[] fromTypes) { - for (int i = 0; i < fromTypes.length; i++) { - Class fromType = fromTypes[i]; - if (!fromType.equals(Float.class) && !fromType.equals(Float.TYPE)) { - String fromName = (fromType.isPrimitive()) ? getKeyForClass( - fromType, null) : fromType.getName(); - - map - .put(new Pair(fromName, FLOAT_TYPE), - new NumberToFloatConverter(numberFormat, - fromType, true)); - map.put(new Pair(fromName, Float.class.getName()), - new NumberToFloatConverter(numberFormat, fromType, - false)); - } - } - } - - /** - * Registers converters to boxed and unboxed types from a list of from - * classes. - * - * @param map - * @param numberFormat - * @param fromTypes - */ - private static void addNumberToDoubleConverters(Map map, - NumberFormat numberFormat, Class[] fromTypes) { - for (int i = 0; i < fromTypes.length; i++) { - Class fromType = fromTypes[i]; - if (!fromType.equals(Double.class) && !fromType.equals(Double.TYPE)) { - String fromName = (fromType.isPrimitive()) ? getKeyForClass( - fromType, null) : fromType.getName(); - - map.put(new Pair(fromName, DOUBLE_TYPE), - new NumberToDoubleConverter(numberFormat, fromType, - true)); - map.put(new Pair(fromName, Double.class.getName()), - new NumberToDoubleConverter(numberFormat, fromType, - false)); - } - } - } - - /** - * Registers converters to boxed and unboxed types from a list of from - * classes. - * - * @param map - * @param numberFormat - * @param fromTypes - */ - private static void addNumberToBigIntegerConverters(Map map, - NumberFormat numberFormat, Class[] fromTypes) { - for (int i = 0; i < fromTypes.length; i++) { - Class fromType = fromTypes[i]; - if (!fromType.equals(BigInteger.class)) { - String fromName = (fromType.isPrimitive()) ? getKeyForClass( - fromType, null) : fromType.getName(); - - map - .put(new Pair(fromName, BigInteger.class.getName()), - new NumberToBigIntegerConverter(numberFormat, - fromType)); - } - } - } - - /** - * Registers converters to boxed and unboxed types from a list of from - * classes. - * - * @param map - * @param numberFormat - * @param fromTypes - */ - private static void addNumberToBigDecimalConverters(Map map, - NumberFormat numberFormat, Class[] fromTypes) { - for (int i = 0; i < fromTypes.length; i++) { - Class fromType = fromTypes[i]; - if (!fromType.equals(BigDecimal.class)) { - String fromName = (fromType.isPrimitive()) ? getKeyForClass( - fromType, null) : fromType.getName(); - - map - .put(new Pair(fromName, BigDecimal.class.getName()), - new NumberToBigDecimalConverter(numberFormat, - fromType)); - } - } - } - - private static String getKeyForClass(Object originalValue, - Class filteredValue) { - if (originalValue instanceof Class) { - Class originalClass = (Class) originalValue; - if (originalClass.equals(Integer.TYPE)) { - return INTEGER_TYPE; - } else if (originalClass.equals(Byte.TYPE)) { - return BYTE_TYPE; - } else if (originalClass.equals(Boolean.TYPE)) { - return BOOLEAN_TYPE; - } else if (originalClass.equals(Double.TYPE)) { - return DOUBLE_TYPE; - } else if (originalClass.equals(Float.TYPE)) { - return FLOAT_TYPE; - } else if (originalClass.equals(Long.TYPE)) { - return LONG_TYPE; - } else if (originalClass.equals(Short.TYPE)) { - return SHORT_TYPE; - } - } - return filteredValue.getName(); - } - - /** - * Returns {@link Boolean#TRUE} if the from type is assignable to the to - * type, or {@link Boolean#FALSE} if it not, or <code>null</code> if - * unknown. - * - * @param fromType - * @param toType - * @return whether fromType is assignable to toType, or <code>null</code> - * if unknown - */ - protected Boolean isAssignableFromTo(Object fromType, Object toType) { - if (fromType instanceof Class && toType instanceof Class) { - Class toClass = (Class) toType; - if (toClass.isPrimitive()) { - toClass = autoboxed(toClass); - } - Class fromClass = (Class) fromType; - if (fromClass.isPrimitive()) { - fromClass = autoboxed(fromClass); - } - return toClass.isAssignableFrom(fromClass) ? Boolean.TRUE - : Boolean.FALSE; - } - return null; - } - - /* - * Default converter implementation, does not perform any conversion. - */ - protected static final class DefaultConverter implements IConverter { - - private final Object toType; - - private final Object fromType; - - /** - * @param fromType - * @param toType - */ - DefaultConverter(Object fromType, Object toType) { - this.toType = toType; - this.fromType = fromType; - } - - public Object convert(Object fromObject) { - return fromObject; - } - - public Object getFromType() { - return fromType; - } - - public Object getToType() { - return toType; - } - } - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateValueStrategy.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateValueStrategy.java deleted file mode 100644 index 22a7a350..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateValueStrategy.java +++ /dev/null @@ -1,580 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matt Carter - Character support completed (bug 197679) - * Tom Schindl<tom.schindl@bestsolution.at> - bugfix for 217940 - *******************************************************************************/ - -package org.eclipse.core.databinding; - -import java.util.Date; -import java.util.HashMap; - -import org.eclipse.core.databinding.conversion.IConverter; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.validation.IValidator; -import org.eclipse.core.databinding.validation.ValidationStatus; -import org.eclipse.core.internal.databinding.BindingMessages; -import org.eclipse.core.internal.databinding.Pair; -import org.eclipse.core.internal.databinding.conversion.NumberToBigDecimalConverter; -import org.eclipse.core.internal.databinding.conversion.NumberToBigIntegerConverter; -import org.eclipse.core.internal.databinding.conversion.NumberToByteConverter; -import org.eclipse.core.internal.databinding.conversion.NumberToDoubleConverter; -import org.eclipse.core.internal.databinding.conversion.NumberToFloatConverter; -import org.eclipse.core.internal.databinding.conversion.NumberToIntegerConverter; -import org.eclipse.core.internal.databinding.conversion.NumberToLongConverter; -import org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter; -import org.eclipse.core.internal.databinding.conversion.NumberToShortConverter; -import org.eclipse.core.internal.databinding.conversion.StringToCharacterConverter; -import org.eclipse.core.internal.databinding.conversion.StringToDateConverter; -import org.eclipse.core.internal.databinding.validation.NumberFormatConverter; -import org.eclipse.core.internal.databinding.validation.NumberToByteValidator; -import org.eclipse.core.internal.databinding.validation.NumberToDoubleValidator; -import org.eclipse.core.internal.databinding.validation.NumberToFloatValidator; -import org.eclipse.core.internal.databinding.validation.NumberToIntegerValidator; -import org.eclipse.core.internal.databinding.validation.NumberToLongValidator; -import org.eclipse.core.internal.databinding.validation.NumberToShortValidator; -import org.eclipse.core.internal.databinding.validation.NumberToUnboundedNumberValidator; -import org.eclipse.core.internal.databinding.validation.ObjectToPrimitiveValidator; -import org.eclipse.core.internal.databinding.validation.StringToByteValidator; -import org.eclipse.core.internal.databinding.validation.StringToCharacterValidator; -import org.eclipse.core.internal.databinding.validation.StringToDateValidator; -import org.eclipse.core.internal.databinding.validation.StringToDoubleValidator; -import org.eclipse.core.internal.databinding.validation.StringToFloatValidator; -import org.eclipse.core.internal.databinding.validation.StringToIntegerValidator; -import org.eclipse.core.internal.databinding.validation.StringToLongValidator; -import org.eclipse.core.internal.databinding.validation.StringToShortValidator; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; - -/** - * Customizes a {@link Binding} between two - * {@link IObservableValue observable values}. The following behaviors can be - * customized via the strategy: - * <ul> - * <li>Validation</li> - * <li>Conversion</li> - * <li>Automatic processing</li> - * </ul> - * <p> - * The update phases are: - * <ol> - * <li>Validate after get - {@link #validateAfterGet(Object)}</li> - * <li>Conversion - {@link #convert(Object)}</li> - * <li>Validate after conversion - {@link #validateAfterConvert(Object)}</li> - * <li>Validate before set - {@link #validateBeforeSet(Object)}</li> - * <li>Value set - {@link #doSet(IObservableValue, Object)}</li> - * </ol> - * </p> - * <p> - * Validation:<br/> {@link IValidator Validators} validate the value at - * multiple phases in the update process. Statuses returned from validators are - * aggregated into a <code>MultiStatus</code> until a status of - * <code>ERROR</code> or <code>CANCEL</code> is encountered. Either of these - * statuses will abort the update process. These statuses are available as the - * {@link Binding#getValidationStatus() binding validation status}. - * </p> - * <p> - * Conversion:<br/> A {@link IConverter converter} will convert the value from - * the type of the source observable into the type of the destination. The - * strategy has the ability to default converters for common scenarios. - * </p> - * <p> - * Automatic processing:<br/> The processing to perform when the source - * observable changes. This behavior is configured via policies provided on - * construction of the strategy (e.g. {@link #POLICY_NEVER}, - * {@link #POLICY_CONVERT}, {@link #POLICY_ON_REQUEST}, {@link #POLICY_UPDATE}). - * </p> - * - * @see DataBindingContext#bindValue(IObservableValue, IObservableValue, - * UpdateValueStrategy, UpdateValueStrategy) - * @see Binding#getValidationStatus() - * @see IValidator - * @see IConverter - * @since 1.0 - */ -public class UpdateValueStrategy extends UpdateStrategy { - - /** - * Policy constant denoting that the source observable's state should not be - * tracked and that the destination observable's value should never be - * updated. - */ - public static int POLICY_NEVER = notInlined(1); - - /** - * Policy constant denoting that the source observable's state should not be - * tracked, but that validation, conversion and updating the destination - * observable's value should be performed when explicitly requested. - */ - public static int POLICY_ON_REQUEST = notInlined(2); - - /** - * Policy constant denoting that the source observable's state should be - * tracked, including validating changes except for - * {@link #validateBeforeSet(Object)}, but that the destination - * observable's value should only be updated on request. - */ - public static int POLICY_CONVERT = notInlined(4); - - /** - * Policy constant denoting that the source observable's state should be - * tracked, and that validation, conversion and updating the destination - * observable's value should be performed automaticlly on every change of - * the source observable value. - */ - public static int POLICY_UPDATE = notInlined(8); - - /** - * Helper method allowing API evolution of the above constant values. The - * compiler will not inline constant values into client code if values are - * "computed" using this helper. - * - * @param i - * an integer - * @return the same integer - */ - private static int notInlined(int i) { - return i; - } - - protected IValidator afterGetValidator; - protected IValidator afterConvertValidator; - protected IValidator beforeSetValidator; - protected IConverter converter; - - private int updatePolicy; - - private static ValidatorRegistry validatorRegistry = new ValidatorRegistry(); - private static HashMap validatorsByConverter = new HashMap(); - - protected boolean provideDefaults; - - /** - * <code>true</code> if we defaulted the converter - */ - private boolean defaultedConverter = false; - - /** - * Creates a new update value strategy for automatically updating the - * destination observable value whenever the source observable value - * changes. Default validators and a default converter will be provided. The - * defaults can be changed by calling one of the setter methods. - */ - public UpdateValueStrategy() { - this(true, POLICY_UPDATE); - } - - /** - * Creates a new update value strategy with a configurable update policy. - * Default validators and a default converter will be provided. The defaults - * can be changed by calling one of the setter methods. - * - * @param updatePolicy - * one of {@link #POLICY_NEVER}, {@link #POLICY_ON_REQUEST}, - * {@link #POLICY_CONVERT}, or {@link #POLICY_UPDATE} - */ - public UpdateValueStrategy(int updatePolicy) { - this(true, updatePolicy); - } - - /** - * Creates a new update value strategy with a configurable update policy. - * Default validators and a default converter will be provided if - * <code>provideDefaults</code> is <code>true</code>. The defaults can - * be changed by calling one of the setter methods. - * - * @param provideDefaults - * if <code>true</code>, default validators and a default - * converter will be provided based on the observable value's - * type. - * @param updatePolicy - * one of {@link #POLICY_NEVER}, {@link #POLICY_ON_REQUEST}, - * {@link #POLICY_CONVERT}, or {@link #POLICY_UPDATE} - */ - public UpdateValueStrategy(boolean provideDefaults, int updatePolicy) { - this.provideDefaults = provideDefaults; - this.updatePolicy = updatePolicy; - } - - /** - * Converts the value from the source type to the destination type. - * <p> - * Default implementation will use the - * {@link #setConverter(IConverter) converter} if one exists. If no - * converter exists no conversion occurs. - * </p> - * - * @param value - * @return the converted value - */ - public Object convert(Object value) { - return converter == null ? value : converter.convert(value); - } - - /** - * Tries to create a validator that can validate values of type fromType. - * Returns <code>null</code> if no validator could be created. Either - * toType or modelDescription can be <code>null</code>, but not both. - * - * @param fromType - * @param toType - * @return an IValidator, or <code>null</code> if unsuccessful - */ - protected IValidator createValidator(Object fromType, Object toType) { - if (fromType == null || toType == null) { - return new IValidator() { - - public IStatus validate(Object value) { - return Status.OK_STATUS; - } - }; - } - - return findValidator(fromType, toType); - } - - /** - * Fills out default values based upon the provided <code>source</code> - * and <code>destination</code>. If the strategy is to default values it - * will attempt to default a converter. If the converter can be defaulted an - * attempt is made to default the - * {@link #validateAfterGet(Object) after get validator}. If a validator - * cannot be defaulted it will be <code>null</code>. - * - * @param source - * @param destination - */ - protected void fillDefaults(IObservableValue source, - IObservableValue destination) { - Object sourceType = source.getValueType(); - Object destinationType = destination.getValueType(); - if (provideDefaults && sourceType != null && destinationType != null) { - if (converter == null) { - IConverter converter = createConverter(sourceType, - destinationType); - defaultedConverter = (converter != null); - setConverter(converter); - } - - if (afterGetValidator == null) { - afterGetValidator = createValidator(sourceType, destinationType); - } - } - if (converter != null) { - if (sourceType != null) { - checkAssignable(converter.getFromType(), sourceType, - "converter does not convert from type " + sourceType); //$NON-NLS-1$ - } - if (destinationType != null) { - checkAssignable(converter.getToType(), destinationType, - "converter does not convert to type " + destinationType); //$NON-NLS-1$ - } - } - } - - private IValidator findValidator(Object fromType, Object toType) { - IValidator result = null; - - // We only default the validator if we defaulted the converter since the - // two are tightly coupled. - if (defaultedConverter) { - if (String.class.equals(fromType)) { - result = (IValidator) validatorsByConverter.get(converter); - - if (result == null) { - // TODO sring based lookup - if (Integer.class.equals(toType) - || Integer.TYPE.equals(toType)) { - result = new StringToIntegerValidator( - (NumberFormatConverter) converter); - } else if (Long.class.equals(toType) - || Long.TYPE.equals(toType)) { - result = new StringToLongValidator( - (NumberFormatConverter) converter); - } else if (Float.class.equals(toType) - || Float.TYPE.equals(toType)) { - result = new StringToFloatValidator( - (NumberFormatConverter) converter); - } else if (Double.class.equals(toType) - || Double.TYPE.equals(toType)) { - result = new StringToDoubleValidator( - (NumberFormatConverter) converter); - } else if (Byte.class.equals(toType) - || Byte.TYPE.equals(toType)) { - result = new StringToByteValidator( - (NumberFormatConverter) converter); - } else if (Short.class.equals(toType) - || Short.TYPE.equals(toType)) { - result = new StringToShortValidator( - (NumberFormatConverter) converter); - } else if (Character.class.equals(toType) - || Character.TYPE.equals(toType) - && converter instanceof StringToCharacterConverter) { - result = new StringToCharacterValidator( - (StringToCharacterConverter) converter); - } else if (Date.class.equals(toType) - && converter instanceof StringToDateConverter) { - result = new StringToDateValidator( - (StringToDateConverter) converter); - } - - if (result != null) { - validatorsByConverter.put(converter, result); - } - } - } else if (converter instanceof NumberToNumberConverter) { - result = (IValidator) validatorsByConverter.get(converter); - - if (result == null) { - if (converter instanceof NumberToByteConverter) { - result = new NumberToByteValidator( - (NumberToByteConverter) converter); - } else if (converter instanceof NumberToShortConverter) { - result = new NumberToShortValidator( - (NumberToShortConverter) converter); - } else if (converter instanceof NumberToIntegerConverter) { - result = new NumberToIntegerValidator( - (NumberToIntegerConverter) converter); - } else if (converter instanceof NumberToLongConverter) { - result = new NumberToLongValidator( - (NumberToLongConverter) converter); - } else if (converter instanceof NumberToFloatConverter) { - result = new NumberToFloatValidator( - (NumberToFloatConverter) converter); - } else if (converter instanceof NumberToDoubleConverter) { - result = new NumberToDoubleValidator( - (NumberToDoubleConverter) converter); - } else if (converter instanceof NumberToBigIntegerConverter - || converter instanceof NumberToBigDecimalConverter) { - result = new NumberToUnboundedNumberValidator( - (NumberToNumberConverter) converter); - } - } - } - - if (result == null) { - // TODO string based lookup - result = validatorRegistry.get(fromType, toType); - } - } - - return result; - } - - /** - * @return the update policy - */ - public int getUpdatePolicy() { - return updatePolicy; - } - - /** - * Sets the validator to be invoked after the source value is converted to - * the type of the destination observable. - * - * @param validator - * @return the receiver, to enable method call chaining - */ - public UpdateValueStrategy setAfterConvertValidator(IValidator validator) { - this.afterConvertValidator = validator; - return this; - } - - /** - * Sets the validator to be invoked after the source value is retrieved at - * the beginning of the synchronization process. - * - * @param validator - * @return the receiver, to enable method call chaining - */ - public UpdateValueStrategy setAfterGetValidator(IValidator validator) { - this.afterGetValidator = validator; - return this; - } - - /** - * Sets the validator to be invoked before the value is to be set on the - * destination at the end of the synchronization process. - * - * @param validator - * @return the receiver, to enable method call chaining - */ - public UpdateValueStrategy setBeforeSetValidator(IValidator validator) { - this.beforeSetValidator = validator; - return this; - } - - /** - * Sets the converter to be invoked when converting from the source type to - * the destination type. - * - * @param converter - * @return the receiver, to enable method call chaining - */ - public UpdateValueStrategy setConverter(IConverter converter) { - this.converter = converter; - return this; - } - - /** - * Validates the value after it is converted. - * <p> - * Default implementation will use the - * {@link #setAfterConvertValidator(IValidator) validator} if one exists. If - * one does not exist no validation will occur. - * </p> - * - * @param value - * @return an ok status - */ - public IStatus validateAfterConvert(Object value) { - return afterConvertValidator == null ? Status.OK_STATUS - : afterConvertValidator.validate(value); - } - - /** - * Validates the value after it is retrieved from the source. - * <p> - * Default implementation will use the - * {@link #setAfterGetValidator(IValidator) validator} if one exists. If one - * does not exist no validation will occur. - * </p> - * - * @param value - * @return an ok status - */ - public IStatus validateAfterGet(Object value) { - return afterGetValidator == null ? Status.OK_STATUS : afterGetValidator - .validate(value); - } - - /** - * Validates the value before it is set on the destination. - * <p> - * Default implementation will use the - * {@link #setBeforeSetValidator(IValidator) validator} if one exists. If - * one does not exist no validation will occur. - * </p> - * - * @param value - * @return an ok status - */ - public IStatus validateBeforeSet(Object value) { - return beforeSetValidator == null ? Status.OK_STATUS - : beforeSetValidator.validate(value); - } - - /** - * Sets the current value of the given observable to the given value. - * Clients may extend but must call the super implementation. - * - * @param observableValue - * @param value - * @return status - */ - protected IStatus doSet(IObservableValue observableValue, Object value) { - try { - observableValue.setValue(value); - } catch (Exception ex) { - return ValidationStatus.error(BindingMessages - .getString(BindingMessages.VALUEBINDING_ERROR_WHILE_SETTING_VALUE), - ex); - } - return Status.OK_STATUS; - } - - private static class ValidatorRegistry { - - private HashMap validators = new HashMap(); - - /** - * Adds the system-provided validators to the current validator - * registry. This is done automatically for the validator registry - * singleton. - */ - private ValidatorRegistry() { - // Standalone validators here... - associate(Integer.class, Integer.TYPE, - new ObjectToPrimitiveValidator(Integer.TYPE)); - associate(Byte.class, Byte.TYPE, new ObjectToPrimitiveValidator( - Byte.TYPE)); - associate(Short.class, Short.TYPE, new ObjectToPrimitiveValidator( - Short.TYPE)); - associate(Long.class, Long.TYPE, new ObjectToPrimitiveValidator( - Long.TYPE)); - associate(Float.class, Float.TYPE, new ObjectToPrimitiveValidator( - Float.TYPE)); - associate(Double.class, Double.TYPE, - new ObjectToPrimitiveValidator(Double.TYPE)); - associate(Boolean.class, Boolean.TYPE, - new ObjectToPrimitiveValidator(Boolean.TYPE)); - - associate(Object.class, Integer.TYPE, - new ObjectToPrimitiveValidator(Integer.TYPE)); - associate(Object.class, Byte.TYPE, new ObjectToPrimitiveValidator( - Byte.TYPE)); - associate(Object.class, Short.TYPE, new ObjectToPrimitiveValidator( - Short.TYPE)); - associate(Object.class, Long.TYPE, new ObjectToPrimitiveValidator( - Long.TYPE)); - associate(Object.class, Float.TYPE, new ObjectToPrimitiveValidator( - Float.TYPE)); - associate(Object.class, Double.TYPE, - new ObjectToPrimitiveValidator(Double.TYPE)); - associate(Object.class, Boolean.TYPE, - new ObjectToPrimitiveValidator(Boolean.TYPE)); - } - - /** - * Associate a particular validator that can validate the conversion - * (fromClass, toClass) - * - * @param fromClass - * The Class to convert from - * @param toClass - * The Class to convert to - * @param validator - * The IValidator - */ - private void associate(Object fromClass, Object toClass, - IValidator validator) { - validators.put(new Pair(fromClass, toClass), validator); - } - - /** - * Return an IValidator for a specific fromClass and toClass. - * - * @param fromClass - * The Class to convert from - * @param toClass - * The Class to convert to - * @return An appropriate IValidator - */ - private IValidator get(Object fromClass, Object toClass) { - IValidator result = (IValidator) validators.get(new Pair(fromClass, - toClass)); - if (result != null) - return result; - if (fromClass != null && toClass != null && fromClass == toClass) { - return new IValidator() { - public IStatus validate(Object value) { - return Status.OK_STATUS; - } - }; - } - return new IValidator() { - public IStatus validate(Object value) { - return Status.OK_STATUS; - } - }; - } - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/ValidationStatusProvider.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/ValidationStatusProvider.java deleted file mode 100644 index 14ad6c75..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/ValidationStatusProvider.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Boris Bokowski - initial API and implementation (bug 218269) - * Matthew Hall - bug 218269 - ******************************************************************************/ - -package org.eclipse.core.databinding; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.value.IObservableValue; - -/** - * A validation status provider tracks the state of zero or more target - * observables and zero or more model observables and produces a validation - * result. - * - * @since 1.1 - * - */ -public abstract class ValidationStatusProvider { - - protected boolean disposed = false; - - /** - * @return an observable value containing the current validation status - */ - public abstract IObservableValue getValidationStatus(); - - /** - * Returns the list of target observables (if any) that are being tracked by - * this validation status provider. - * - * @return an observable list of target {@link IObservable}s (may be empty) - */ - public abstract IObservableList getTargets(); - - /** - * Returns the model observables (if any) that are being tracked by this - * validation status provider. - * - * @return an observable list of model {@link IObservable}s (may be empty) - */ - public abstract IObservableList getModels(); - - /** - * Disposes of this ValidationStatusProvider. Subclasses may extend, but - * must call super.dispose(). - */ - public void dispose() { - disposed = true; - } - - /** - * @return true if the binding has been disposed. false otherwise. - */ - public boolean isDisposed() { - return disposed; - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/ValueBinding.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/ValueBinding.java deleted file mode 100644 index 8f33b87b..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/ValueBinding.java +++ /dev/null @@ -1,246 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 220700 - *******************************************************************************/ - -package org.eclipse.core.databinding; - -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.observable.value.ValueChangeEvent; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.databinding.util.Policy; -import org.eclipse.core.internal.databinding.BindingStatus; -import org.eclipse.core.internal.databinding.Util; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.core.runtime.Status; - -/** - * @since 1.0 - * - */ -class ValueBinding extends Binding { - private final UpdateValueStrategy targetToModel; - private final UpdateValueStrategy modelToTarget; - private WritableValue validationStatusObservable; - private IObservableValue target; - private IObservableValue model; - - private boolean updatingTarget; - private boolean updatingModel; - private IValueChangeListener targetChangeListener = new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - if (!updatingTarget && !Util.equals(event.diff.getOldValue(), event.diff.getNewValue())) { - doUpdate(target, model, targetToModel, false, false); - } - } - }; - private IValueChangeListener modelChangeListener = new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - if (!updatingModel && !Util.equals(event.diff.getOldValue(), event.diff.getNewValue())) { - doUpdate(model, target, modelToTarget, false, false); - } - } - }; - - /** - * @param targetObservableValue - * @param modelObservableValue - * @param targetToModel - * @param modelToTarget - */ - public ValueBinding(IObservableValue targetObservableValue, - IObservableValue modelObservableValue, - UpdateValueStrategy targetToModel, UpdateValueStrategy modelToTarget) { - super(targetObservableValue, modelObservableValue); - this.target = targetObservableValue; - this.model = modelObservableValue; - this.targetToModel = targetToModel; - this.modelToTarget = modelToTarget; - if ((targetToModel.getUpdatePolicy() & (UpdateValueStrategy.POLICY_CONVERT | UpdateValueStrategy.POLICY_UPDATE)) != 0) { - target.addValueChangeListener(targetChangeListener); - } else { - targetChangeListener = null; - } - if ((modelToTarget.getUpdatePolicy() & (UpdateValueStrategy.POLICY_CONVERT | UpdateValueStrategy.POLICY_UPDATE)) != 0) { - model.addValueChangeListener(modelChangeListener); - } else { - modelChangeListener = null; - } - } - - protected void preInit() { - validationStatusObservable = new WritableValue(context - .getValidationRealm(), Status.OK_STATUS, IStatus.class); - } - - protected void postInit() { - if (modelToTarget.getUpdatePolicy() == UpdateValueStrategy.POLICY_UPDATE) { - updateModelToTarget(); - } - if (targetToModel.getUpdatePolicy() != UpdateValueStrategy.POLICY_NEVER) { - validateTargetToModel(); - } - } - - public IObservableValue getValidationStatus() { - return validationStatusObservable; - } - - public void updateTargetToModel() { - doUpdate(target, model, targetToModel, true, false); - } - - public void updateModelToTarget() { - doUpdate(model, target, modelToTarget, true, false); - } - - /** - * Incorporates the provided <code>newStats</code> into the - * <code>multieStatus</code>. - * - * @param multiStatus - * @param newStatus - * @return <code>true</code> if the update should proceed - */ - /* package */boolean mergeStatus(MultiStatus multiStatus, IStatus newStatus) { - if (!newStatus.isOK()) { - multiStatus.add(newStatus); - return multiStatus.getSeverity() < IStatus.ERROR; - } - return true; - } - - /* - * This method may be moved to UpdateValueStrategy in the future if clients - * need more control over how the source value is copied to the destination - * observable. - */ - private void doUpdate(final IObservableValue source, - final IObservableValue destination, - final UpdateValueStrategy updateValueStrategy, - final boolean explicit, final boolean validateOnly) { - - final int policy = updateValueStrategy.getUpdatePolicy(); - if (policy == UpdateValueStrategy.POLICY_NEVER) - return; - if (policy == UpdateValueStrategy.POLICY_ON_REQUEST && !explicit) - return; - - source.getRealm().exec(new Runnable() { - public void run() { - boolean destinationRealmReached = false; - final MultiStatus multiStatus = BindingStatus.ok(); - try { - // Get value - Object value = source.getValue(); - - // Validate after get - IStatus status = updateValueStrategy - .validateAfterGet(value); - if (!mergeStatus(multiStatus, status)) - return; - - // Convert value - final Object convertedValue = updateValueStrategy - .convert(value); - - // Validate after convert - status = updateValueStrategy - .validateAfterConvert(convertedValue); - if (!mergeStatus(multiStatus, status)) - return; - if (policy == UpdateValueStrategy.POLICY_CONVERT - && !explicit) - return; - - // Validate before set - status = updateValueStrategy - .validateBeforeSet(convertedValue); - if (!mergeStatus(multiStatus, status)) - return; - if (validateOnly) - return; - - // Set value - destinationRealmReached = true; - destination.getRealm().exec(new Runnable() { - public void run() { - if (destination == target) { - updatingTarget = true; - } else { - updatingModel = true; - } - try { - IStatus setterStatus = updateValueStrategy - .doSet(destination, convertedValue); - - mergeStatus(multiStatus, setterStatus); - } finally { - if (destination == target) { - updatingTarget = false; - } else { - updatingModel = false; - } - setValidationStatus(multiStatus); - } - } - }); - } catch (Exception ex) { - // This check is necessary as in 3.2.2 Status - // doesn't accept a null message (bug 177264). - String message = (ex.getMessage() != null) ? ex - .getMessage() : ""; //$NON-NLS-1$ - - mergeStatus(multiStatus, new Status(IStatus.ERROR, - Policy.JFACE_DATABINDING, IStatus.ERROR, message, - ex)); - } finally { - if (!destinationRealmReached) { - setValidationStatus(multiStatus); - } - - } - } - }); - } - - public void validateModelToTarget() { - doUpdate(model, target, modelToTarget, true, true); - } - - public void validateTargetToModel() { - doUpdate(target, model, targetToModel, true, true); - } - - private void setValidationStatus(final IStatus status) { - validationStatusObservable.getRealm().exec(new Runnable() { - public void run() { - validationStatusObservable.setValue(status); - } - }); - } - - public void dispose() { - if (targetChangeListener != null) { - target.removeValueChangeListener(targetChangeListener); - targetChangeListener = null; - } - if (modelChangeListener != null) { - model.removeValueChangeListener(modelChangeListener); - modelChangeListener = null; - } - target = null; - model = null; - super.dispose(); - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/Converter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/Converter.java deleted file mode 100644 index 5a344e49..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/Converter.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.conversion; - - -/** - * Abstract base class for converters. - * - * @since 1.0 - * - */ -public abstract class Converter implements IConverter { - - private Object fromType; - private Object toType; - - /** - * @param fromType - * @param toType - */ - public Converter(Object fromType, Object toType) { - this.fromType = fromType; - this.toType = toType; - } - - public Object getFromType() { - return fromType; - } - - public Object getToType() { - return toType; - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/IConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/IConverter.java deleted file mode 100644 index ebd21ae0..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/IConverter.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.core.databinding.conversion; - -/** - * A one-way converter. - * - * @noextend This interface is not intended to be extended by clients. - * @noimplement This interface is not intended to be implemented by clients. - * Clients should subclass {@link Converter}. - * - * @since 1.0 - * - */ -public interface IConverter { - - /** - * Returns the type whose instances can be converted by this converter. The - * return type is Object rather than Class to optionally support richer type - * systems than the one provided by Java reflection. - * - * @return the type whose instances can be converted, or null if this - * converter is untyped - */ - public Object getFromType(); - - /** - * Returns the type to which this converter can convert. The return type is - * Object rather than Class to optionally support richer type systems than - * the one provided by Java reflection. - * - * @return the type to which this converter can convert, or null if this - * converter is untyped - */ - public Object getToType(); - - /** - * Returns the result of the conversion of the given object. - * - * @param fromObject - * the object to convert, of type {@link #getFromType()} - * @return the converted object, of type {@link #getToType()} - */ - public Object convert(Object fromObject); -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/NumberToStringConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/NumberToStringConverter.java deleted file mode 100644 index ee9a00b5..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/NumberToStringConverter.java +++ /dev/null @@ -1,189 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.databinding.conversion; - -import java.math.BigInteger; - -import com.ibm.icu.text.NumberFormat; - -/** - * Converts a Number to a String using <code>NumberFormat.format(...)</code>. - * This class is thread safe. - * - * @since 1.0 - */ -public class NumberToStringConverter extends Converter { - private final NumberFormat numberFormat; - private final Class fromType; - private boolean fromTypeIsLong; - private boolean fromTypeIsDecimalType; - private boolean fromTypeIsBigInteger; - - /** - * Constructs a new instance. - * <p> - * Private to restrict public instantiation. - * </p> - * - * @param numberFormat - * @param fromType - */ - private NumberToStringConverter(NumberFormat numberFormat, Class fromType) { - super(fromType, String.class); - - this.numberFormat = numberFormat; - this.fromType = fromType; - - if (Integer.class.equals(fromType) || Integer.TYPE.equals(fromType) - || Long.class.equals(fromType) || Long.TYPE.equals(fromType)) { - fromTypeIsLong = true; - } else if (Float.class.equals(fromType) || Float.TYPE.equals(fromType) - || Double.class.equals(fromType) - || Double.TYPE.equals(fromType)) { - fromTypeIsDecimalType = true; - } else if (BigInteger.class.equals(fromType)) { - fromTypeIsBigInteger = true; - } - } - - /** - * Converts the provided <code>fromObject</code> to a <code>String</code>. - * If the converter was constructed for an object type, non primitive, a - * <code>fromObject</code> of <code>null</code> will be converted to an - * empty string. - * - * @param fromObject - * value to convert. May be <code>null</code> if the converter - * was constructed for a non primitive type. - * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object) - */ - public Object convert(Object fromObject) { - // Null is allowed when the type is not primitve. - if (fromObject == null && !fromType.isPrimitive()) { - return ""; //$NON-NLS-1$ - } - - Number number = (Number) fromObject; - String result = null; - if (fromTypeIsLong) { - synchronized (numberFormat) { - result = numberFormat.format(number.longValue()); - } - } else if (fromTypeIsDecimalType) { - synchronized (numberFormat) { - result = numberFormat.format(number.doubleValue()); - } - } else if (fromTypeIsBigInteger) { - synchronized (numberFormat) { - result = numberFormat.format((BigInteger) number); - } - } - - return result; - } - - /** - * @param primitive - * <code>true</code> if the type is a double - * @return Double converter for the default locale - */ - public static NumberToStringConverter fromDouble(boolean primitive) { - return fromDouble(NumberFormat.getNumberInstance(), primitive); - } - - /** - * @param numberFormat - * @param primitive - * @return Double converter with the provided numberFormat - */ - public static NumberToStringConverter fromDouble(NumberFormat numberFormat, - boolean primitive) { - return new NumberToStringConverter(numberFormat, - (primitive) ? Double.TYPE : Double.class); - } - - /** - * @param primitive - * <code>true</code> if the type is a long - * @return Long converter for the default locale - */ - public static NumberToStringConverter fromLong(boolean primitive) { - return fromLong(NumberFormat.getIntegerInstance(), primitive); - } - - /** - * @param numberFormat - * @param primitive - * @return Long convert with the provided numberFormat - */ - public static NumberToStringConverter fromLong(NumberFormat numberFormat, - boolean primitive) { - return new NumberToStringConverter(numberFormat, - (primitive) ? Long.TYPE : Long.class); - } - - /** - * @param primitive - * <code>true</code> if the type is a float - * @return Float converter for the default locale - */ - public static NumberToStringConverter fromFloat(boolean primitive) { - return fromFloat(NumberFormat.getNumberInstance(), primitive); - } - - /** - * @param numberFormat - * @param primitive - * @return Float converter with the provided numberFormat - */ - public static NumberToStringConverter fromFloat(NumberFormat numberFormat, - boolean primitive) { - return new NumberToStringConverter(numberFormat, - (primitive) ? Float.TYPE : Float.class); - } - - /** - * @param primitive - * <code>true</code> if the type is a int - * @return Integer converter for the default locale - */ - public static NumberToStringConverter fromInteger(boolean primitive) { - return fromInteger(NumberFormat.getIntegerInstance(), primitive); - } - - /** - * @param numberFormat - * @param primitive - * @return Integer converter with the provided numberFormat - */ - public static NumberToStringConverter fromInteger( - NumberFormat numberFormat, boolean primitive) { - return new NumberToStringConverter(numberFormat, - (primitive) ? Integer.TYPE : Integer.class); - } - - /** - * @return BigInteger convert for the default locale - */ - public static NumberToStringConverter fromBigInteger() { - return fromBigInteger(NumberFormat.getIntegerInstance()); - } - - /** - * @param numberFormat - * @return BigInteger converter with the provided numberFormat - */ - public static NumberToStringConverter fromBigInteger( - NumberFormat numberFormat) { - return new NumberToStringConverter(numberFormat, BigInteger.class); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/StringToNumberConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/StringToNumberConverter.java deleted file mode 100644 index 104ec661..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/StringToNumberConverter.java +++ /dev/null @@ -1,255 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.databinding.conversion; - -import java.math.BigDecimal; -import java.math.BigInteger; - -import org.eclipse.core.internal.databinding.conversion.StringToNumberParser; -import org.eclipse.core.internal.databinding.conversion.StringToNumberParser.ParseResult; -import org.eclipse.core.internal.databinding.validation.NumberFormatConverter; - -import com.ibm.icu.text.NumberFormat; - -/** - * Converts a String to a Number using <code>NumberFormat.parse(...)</code>. - * This class is thread safe. - * - * @since 1.0 - */ -public class StringToNumberConverter extends NumberFormatConverter { - private Class toType; - /** - * NumberFormat instance to use for conversion. Access must be synchronized. - */ - private NumberFormat numberFormat; - - /** - * Minimum possible value for the type. Can be <code>null</code> as - * BigInteger doesn't have bounds. - */ - private final Number min; - /** - * Maximum possible value for the type. Can be <code>null</code> as - * BigInteger doesn't have bounds. - */ - private final Number max; - - /** - * The boxed type of the toType; - */ - private final Class boxedType; - - private static final Integer MIN_INTEGER = new Integer(Integer.MIN_VALUE); - private static final Integer MAX_INTEGER = new Integer(Integer.MAX_VALUE); - - private static final Double MIN_DOUBLE = new Double(-Double.MAX_VALUE); - private static final Double MAX_DOUBLE = new Double(Double.MAX_VALUE); - - private static final Long MIN_LONG = new Long(Long.MIN_VALUE); - private static final Long MAX_LONG = new Long(Long.MIN_VALUE); - - private static final Float MIN_FLOAT = new Float(-Float.MAX_VALUE); - private static final Float MAX_FLOAT = new Float(Float.MAX_VALUE); - - /** - * @param numberFormat - * @param toType - * @param min - * minimum possible value for the type, can be <code>null</code> - * as BigInteger doesn't have bounds - * @param max - * maximum possible value for the type, can be <code>null</code> - * as BigInteger doesn't have bounds - * @param boxedType - * a convenience that allows for the checking against one type - * rather than boxed and unboxed types - */ - private StringToNumberConverter(NumberFormat numberFormat, Class toType, - Number min, Number max, Class boxedType) { - super(String.class, toType, numberFormat); - - this.toType = toType; - this.numberFormat = numberFormat; - this.min = min; - this.max = max; - this.boxedType = boxedType; - } - - /** - * Converts the provided <code>fromObject</code> to the requested - * {@link #getToType() to type}. - * - * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object) - * @throws IllegalArgumentException - * if the value isn't in the format required by the NumberFormat - * or the value is out of range for the - * {@link #getToType() to type}. - * @throws IllegalArgumentException - * if conversion was not possible - */ - public Object convert(Object fromObject) { - ParseResult result = StringToNumberParser.parse(fromObject, - numberFormat, toType.isPrimitive()); - - if (result.getPosition() != null) { - // this shouldn't happen in the pipeline as validation should catch - // it but anyone can call convert so we should return a properly - // formatted message in an exception - throw new IllegalArgumentException(StringToNumberParser - .createParseErrorMessage((String) fromObject, result - .getPosition())); - } else if (result.getNumber() == null) { - // if an error didn't occur and the number is null then it's a boxed - // type and null should be returned - return null; - } - - /* - * Technically the checks for ranges aren't needed here because the - * validator should have validated this already but we shouldn't assume - * this has occurred. - */ - if (Integer.class.equals(boxedType)) { - if (StringToNumberParser.inIntegerRange(result.getNumber())) { - return new Integer(result.getNumber().intValue()); - } - } else if (Double.class.equals(boxedType)) { - if (StringToNumberParser.inDoubleRange(result.getNumber())) { - return new Double(result.getNumber().doubleValue()); - } - } else if (Long.class.equals(boxedType)) { - if (StringToNumberParser.inLongRange(result.getNumber())) { - return new Long(result.getNumber().longValue()); - } - } else if (Float.class.equals(boxedType)) { - if (StringToNumberParser.inFloatRange(result.getNumber())) { - return new Float(result.getNumber().floatValue()); - } - } else if (BigInteger.class.equals(boxedType)) { - return new BigDecimal(result.getNumber().doubleValue()) - .toBigInteger(); - } - - if (min != null && max != null) { - throw new IllegalArgumentException(StringToNumberParser - .createOutOfRangeMessage(min, max, numberFormat)); - } - - /* - * Fail safe. I don't think this could even be thrown but throwing the - * exception is better than returning null and hiding the error. - */ - throw new IllegalArgumentException( - "Could not convert [" + fromObject + "] to type [" + toType + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - - /** - * @param primitive - * <code>true</code> if the convert to type is an int - * @return to Integer converter for the default locale - */ - public static StringToNumberConverter toInteger(boolean primitive) { - return toInteger(NumberFormat.getIntegerInstance(), primitive); - } - - /** - * @param numberFormat - * @param primitive - * @return to Integer converter with the provided numberFormat - */ - public static StringToNumberConverter toInteger(NumberFormat numberFormat, - boolean primitive) { - return new StringToNumberConverter(numberFormat, - (primitive) ? Integer.TYPE : Integer.class, MIN_INTEGER, - MAX_INTEGER, Integer.class); - } - - /** - * @param primitive - * <code>true</code> if the convert to type is a double - * @return to Double converter for the default locale - */ - public static StringToNumberConverter toDouble(boolean primitive) { - return toDouble(NumberFormat.getNumberInstance(), primitive); - } - - /** - * @param numberFormat - * @param primitive - * @return to Double converter with the provided numberFormat - */ - public static StringToNumberConverter toDouble(NumberFormat numberFormat, - boolean primitive) { - return new StringToNumberConverter(numberFormat, - (primitive) ? Double.TYPE : Double.class, MIN_DOUBLE, - MAX_DOUBLE, Double.class); - } - - /** - * @param primitive - * <code>true</code> if the convert to type is a long - * @return to Long converter for the default locale - */ - public static StringToNumberConverter toLong(boolean primitive) { - return toLong(NumberFormat.getIntegerInstance(), primitive); - } - - /** - * @param numberFormat - * @param primitive - * @return to Long converter with the provided numberFormat - */ - public static StringToNumberConverter toLong(NumberFormat numberFormat, - boolean primitive) { - return new StringToNumberConverter(numberFormat, - (primitive) ? Long.TYPE : Long.class, MIN_LONG, MAX_LONG, - Long.class); - } - - /** - * @param primitive - * <code>true</code> if the convert to type is a float - * @return to Float converter for the default locale - */ - public static StringToNumberConverter toFloat(boolean primitive) { - return toFloat(NumberFormat.getNumberInstance(), primitive); - } - - /** - * @param numberFormat - * @param primitive - * @return to Float converter with the provided numberFormat - */ - public static StringToNumberConverter toFloat(NumberFormat numberFormat, - boolean primitive) { - return new StringToNumberConverter(numberFormat, - (primitive) ? Float.TYPE : Float.class, MIN_FLOAT, MAX_FLOAT, - Float.class); - } - - /** - * @return to BigInteger converter for the default locale - */ - public static StringToNumberConverter toBigInteger() { - return toBigInteger(NumberFormat.getIntegerInstance()); - } - - /** - * @param numberFormat - * @return to BigInteger converter with the provided numberFormat - */ - public static StringToNumberConverter toBigInteger(NumberFormat numberFormat) { - return new StringToNumberConverter(numberFormat, BigInteger.class, - null, null, BigInteger.class); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/package.html b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/package.html deleted file mode 100644 index 06a1b53e..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/package.html +++ /dev/null @@ -1,18 +0,0 @@ -<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> - <meta name="Author" content="IBM"> - <meta name="GENERATOR" content="Mozilla/4.5 [en] (Win98; I) [Netscape]"> - <title>Package-level Javadoc</title> -</head> -<body> -Provides interfaces and classes for data type conversion. -<h2> -Package Specification</h2> -<p> -This package provides the <tt>IConverter</tt> interface along with classes -that implement the interface to convert between common data types. -<p> -</body> -</html> diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/AbstractObservable.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/AbstractObservable.java deleted file mode 100644 index 90e9b587..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/AbstractObservable.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - * Matthew Hall - bug 118516 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.AssertionFailedException; - -/** - * @since 1.0 - */ -public abstract class AbstractObservable extends ChangeManager implements IObservable { - - /** - * @param realm - */ - public AbstractObservable(Realm realm) { - super(realm); - } - - public synchronized void addChangeListener(IChangeListener listener) { - addListener(ChangeEvent.TYPE, listener); - } - - public synchronized void removeChangeListener(IChangeListener listener) { - removeListener(ChangeEvent.TYPE, listener); - } - - public synchronized void addStaleListener(IStaleListener listener) { - addListener(StaleEvent.TYPE, listener); - } - - public synchronized void removeStaleListener(IStaleListener listener) { - removeListener(StaleEvent.TYPE, listener); - } - - protected void fireChange() { - checkRealm(); - fireEvent(new ChangeEvent(this)); - } - - protected void fireStale() { - checkRealm(); - fireEvent(new StaleEvent(this)); - } - - /** - * - */ - public synchronized void dispose() { - super.dispose(); - } - - /** - * Asserts that the realm is the current realm. - * - * @see Realm#isCurrent() - * @throws AssertionFailedException if the realm is not the current realm - */ - protected void checkRealm() { - Assert.isTrue(getRealm().isCurrent(), - "This operation must be run within the observable's realm"); //$NON-NLS-1$ - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/ChangeEvent.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/ChangeEvent.java deleted file mode 100644 index 60950cf2..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/ChangeEvent.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable; - -/** - * Generic change event denoting that the state of an {@link IObservable} object - * has changed. This event does not carry information about the kind of change - * that occurred. - * - * @since 1.0 - * - */ -public class ChangeEvent extends ObservableEvent { - - /** - * - */ - private static final long serialVersionUID = -3241193109844979384L; - static final Object TYPE = new Object(); - - /** - * Creates a new change event object. - * - * @param source - * the observable that changed state - */ - public ChangeEvent(IObservable source) { - super(source); - } - - protected void dispatch(IObservablesListener listener) { - ((IChangeListener) listener).handleChange(this); - } - - protected Object getListenerType() { - return TYPE; - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/ChangeManager.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/ChangeManager.java deleted file mode 100644 index bf2be9ad..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/ChangeManager.java +++ /dev/null @@ -1,162 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 118516 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.ListenerList; - -/** - * Listener management implementation. Exposed to subclasses in form of - * {@link AbstractObservable} and {@link ChangeSupport}. - * - * @since 1.0 - * - */ -/* package */ class ChangeManager { - - ListenerList[] listenerLists = null; - Object listenerTypes[] = null; - private Realm realm; - - /** - * @param realm - * - */ - /* package */ ChangeManager(Realm realm) { - Assert.isNotNull(realm, "Realm cannot be null"); //$NON-NLS-1$ - this.realm = realm; - } - - /** - * @param listenerType - * @param listener - */ - protected void addListener(Object listenerType, - IObservablesListener listener) { - int listenerTypeIndex = findListenerTypeIndex(listenerType); - if (listenerTypeIndex == -1) { - int length; - if (listenerTypes == null) { - length = 0; - listenerTypes = new Object[1]; - listenerLists = new ListenerList[1]; - } else { - length = listenerTypes.length; - System.arraycopy(listenerTypes, 0, - listenerTypes = new Object[length + 1], 0, length); - System - .arraycopy(listenerLists, 0, - listenerLists = new ListenerList[length + 1], - 0, length); - } - listenerTypes[length] = listenerType; - listenerLists[length] = new ListenerList(); - boolean hadListeners = hasListeners(); - listenerLists[length].add(listener); - if (!hadListeners) { - this.firstListenerAdded(); - } - return; - } - ListenerList listenerList = listenerLists[listenerTypeIndex]; - boolean hadListeners = true; - if (listenerList.size() == 0) { - hadListeners = hasListeners(); - } - listenerList.add(listener); - if (!hadListeners) { - firstListenerAdded(); - } - } - - /** - * @param listenerType - * @param listener - */ - protected void removeListener(Object listenerType, - IObservablesListener listener) { - int listenerTypeIndex = findListenerTypeIndex(listenerType); - if (listenerTypeIndex != -1) { - listenerLists[listenerTypeIndex].remove(listener); - if (listenerLists[listenerTypeIndex].size() == 0) { - if (!hasListeners()) { - this.lastListenerRemoved(); - } - } - } - } - - protected boolean hasListeners() { - if (listenerTypes == null) { - return false; - } - for (int i = 0; i < listenerTypes.length; i++) { - if (listenerLists[i].size() > 0) { - return true; - } - } - return false; - } - - private int findListenerTypeIndex(Object listenerType) { - if (listenerTypes != null) { - for (int i = 0; i < listenerTypes.length; i++) { - if (listenerTypes[i] == listenerType) { - return i; - } - } - } - return -1; - } - - protected void fireEvent(ObservableEvent event) { - Object listenerType = event.getListenerType(); - int listenerTypeIndex = findListenerTypeIndex(listenerType); - if (listenerTypeIndex != -1) { - Object[] listeners = listenerLists[listenerTypeIndex] - .getListeners(); - for (int i = 0; i < listeners.length; i++) { - event.dispatch((IObservablesListener) listeners[i]); - } - } - } - - /** - * - */ - protected void firstListenerAdded() { - } - - /** - * - */ - protected void lastListenerRemoved() { - } - - /** - * - */ - public void dispose() { - listenerLists = null; - listenerTypes = null; - realm = null; - } - - /** - * @return Returns the realm. - */ - public Realm getRealm() { - return realm; - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/ChangeSupport.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/ChangeSupport.java deleted file mode 100644 index e91daeb3..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/ChangeSupport.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable; - -/** - * @since 1.0 - * - */ -public abstract class ChangeSupport extends ChangeManager { - - /** - * @param realm - */ - public ChangeSupport(Realm realm) { - super(realm); - } - - public void addListener(Object listenerType, - IObservablesListener listener) { - super.addListener(listenerType, listener); - } - - public void removeListener(Object listenerType, - IObservablesListener listener) { - super.removeListener(listenerType, listener); - } - - public void fireEvent(ObservableEvent event) { - super.fireEvent(event); - } - - /** - * - */ - protected abstract void firstListenerAdded(); - - /** - * - */ - protected abstract void lastListenerRemoved(); - - /** - * @param listener - */ - public void addChangeListener(IChangeListener listener) { - addListener(ChangeEvent.TYPE, listener); - } - - /** - * @param listener - */ - public void removeChangeListener(IChangeListener listener) { - removeListener(ChangeEvent.TYPE, listener); - } - - /** - * @param listener - */ - public void addStaleListener(IStaleListener listener) { - addListener(StaleEvent.TYPE, listener); - } - - /** - * @param listener - */ - public void removeStaleListener(IStaleListener listener) { - removeListener(StaleEvent.TYPE, listener); - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/Diffs.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/Diffs.java deleted file mode 100644 index 9500537e..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/Diffs.java +++ /dev/null @@ -1,470 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 226216 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.Map.Entry; - -import org.eclipse.core.databinding.observable.list.ListDiff; -import org.eclipse.core.databinding.observable.list.ListDiffEntry; -import org.eclipse.core.databinding.observable.map.MapDiff; -import org.eclipse.core.databinding.observable.set.SetDiff; -import org.eclipse.core.databinding.observable.value.ValueDiff; -import org.eclipse.core.internal.databinding.Util; - -/** - * @since 1.0 - * - */ -public class Diffs { - - /** - * @param oldList - * @param newList - * @return the differences between oldList and newList - */ - public static ListDiff computeListDiff(List oldList, List newList) { - List diffEntries = new ArrayList(); - createListDiffs(new ArrayList(oldList), newList, diffEntries); - ListDiff listDiff = createListDiff((ListDiffEntry[]) diffEntries - .toArray(new ListDiffEntry[diffEntries.size()])); - return listDiff; - } - - /** - * adapted from EMF's ListDifferenceAnalyzer - */ - private static void createListDiffs(List oldList, List newList, - List listDiffs) { - int index = 0; - for (Iterator it = newList.iterator(); it.hasNext();) { - Object newValue = it.next(); - if (oldList.size() <= index) { - // append newValue to newList - listDiffs.add(createListDiffEntry(index, true, newValue)); - } else { - boolean done; - do { - done = true; - Object oldValue = oldList.get(index); - if (oldValue == null ? newValue != null : !oldValue.equals(newValue)) { - int oldIndexOfNewValue = listIndexOf(oldList, newValue, index); - if (oldIndexOfNewValue != -1) { - int newIndexOfOldValue = listIndexOf(newList, oldValue, index); - if (newIndexOfOldValue == -1) { - // removing oldValue from list[index] - listDiffs.add(createListDiffEntry(index, false, oldValue)); - oldList.remove(index); - done = false; - } else if (newIndexOfOldValue > oldIndexOfNewValue) { - // moving oldValue from list[index] to [newIndexOfOldValue] - if (oldList.size() <= newIndexOfOldValue) { - // The element cannot be moved to the correct index - // now, however later iterations will insert elements - // in front of it, eventually moving it into the - // correct spot. - newIndexOfOldValue = oldList.size() - 1; - } - listDiffs.add(createListDiffEntry(index, false, oldValue)); - oldList.remove(index); - listDiffs.add(createListDiffEntry(newIndexOfOldValue, true, oldValue)); - oldList.add(newIndexOfOldValue, oldValue); - done = false; - } else { - // move newValue from list[oldIndexOfNewValue] to [index] - listDiffs.add(createListDiffEntry(oldIndexOfNewValue, false, newValue)); - oldList.remove(oldIndexOfNewValue); - listDiffs.add(createListDiffEntry(index, true, newValue)); - oldList.add(index, newValue); - } - } else { - // add newValue at list[index] - oldList.add(index, newValue); - listDiffs.add(createListDiffEntry(index, true, newValue)); - } - } - } while (!done); - } - ++index; - } - for (int i = oldList.size(); i > index;) { - // remove excess trailing elements not present in newList - listDiffs.add(createListDiffEntry(--i, false, oldList.get(i))); - } - } - - /** - * @param list - * @param object - * @param index - * @return the index, or -1 if not found - */ - private static int listIndexOf(List list, Object object, int index) { - int size = list.size(); - for (int i=index; i<size;i++) { - Object candidate = list.get(i); - if (candidate==null ? object==null : candidate.equals(object)) { - return i; - } - } - return -1; - } - - /** - * Checks whether the two objects are <code>null</code> -- allowing for - * <code>null</code>. - * - * @param left - * The left object to compare; may be <code>null</code>. - * @param right - * The right object to compare; may be <code>null</code>. - * @return <code>true</code> if the two objects are equivalent; - * <code>false</code> otherwise. - */ - public static final boolean equals(final Object left, final Object right) { - return left == null ? right == null : ((right != null) && left - .equals(right)); - } - - /** - * @param oldSet - * @param newSet - * @return a set diff - */ - public static SetDiff computeSetDiff(Set oldSet, Set newSet) { - Set additions = new HashSet(newSet); - additions.removeAll(oldSet); - Set removals = new HashSet(oldSet); - removals.removeAll(newSet); - return createSetDiff(additions, removals); - } - - /** - * Computes the difference between two maps. - * - * @param oldMap - * @param newMap - * @return a map diff representing the changes needed to turn oldMap into - * newMap - */ - public static MapDiff computeMapDiff(Map oldMap, Map newMap) { - // starts out with all keys from the new map, we will remove keys from - // the old map as we go - final Set addedKeys = new HashSet(newMap.keySet()); - final Set removedKeys = new HashSet(); - final Set changedKeys = new HashSet(); - final Map oldValues = new HashMap(); - final Map newValues = new HashMap(); - for (Iterator it = oldMap.entrySet().iterator(); it.hasNext();) { - Map.Entry oldEntry = (Entry) it.next(); - Object oldKey = oldEntry.getKey(); - if (addedKeys.remove(oldKey)) { - // potentially changed key since it is in oldMap and newMap - Object oldValue = oldEntry.getValue(); - Object newValue = newMap.get(oldKey); - if (!Util.equals(oldValue, newValue)) { - changedKeys.add(oldKey); - oldValues.put(oldKey, oldValue); - newValues.put(oldKey, newValue); - } - } else { - removedKeys.add(oldKey); - oldValues.put(oldKey, oldEntry.getValue()); - } - } - for (Iterator it = addedKeys.iterator(); it.hasNext();) { - Object newKey = it.next(); - newValues.put(newKey, newMap.get(newKey)); - } - return new MapDiff() { - public Set getAddedKeys() { - return addedKeys; - } - - public Set getChangedKeys() { - return changedKeys; - } - - public Set getRemovedKeys() { - return removedKeys; - } - - public Object getNewValue(Object key) { - return newValues.get(key); - } - - public Object getOldValue(Object key) { - return oldValues.get(key); - } - }; - } - - /** - * @param oldValue - * @param newValue - * @return a value diff - */ - public static ValueDiff createValueDiff(final Object oldValue, - final Object newValue) { - return new ValueDiff() { - - public Object getOldValue() { - return oldValue; - } - - public Object getNewValue() { - return newValue; - } - }; - } - - /** - * @param additions - * @param removals - * @return a set diff - */ - public static SetDiff createSetDiff(Set additions, Set removals) { - final Set unmodifiableAdditions = Collections - .unmodifiableSet(additions); - final Set unmodifiableRemovals = Collections.unmodifiableSet(removals); - return new SetDiff() { - - public Set getAdditions() { - return unmodifiableAdditions; - } - - public Set getRemovals() { - return unmodifiableRemovals; - } - }; - } - - /** - * @param difference - * @return a list diff with one differing entry - */ - public static ListDiff createListDiff(ListDiffEntry difference) { - return createListDiff(new ListDiffEntry[] { difference }); - } - - /** - * @param difference1 - * @param difference2 - * @return a list diff with two differing entries - */ - public static ListDiff createListDiff(ListDiffEntry difference1, - ListDiffEntry difference2) { - return createListDiff(new ListDiffEntry[] { difference1, difference2 }); - } - - /** - * @param differences - * @return a list diff with the given entries - */ - public static ListDiff createListDiff(final ListDiffEntry[] differences) { - return new ListDiff() { - public ListDiffEntry[] getDifferences() { - return differences; - } - }; - } - - /** - * @param position - * @param isAddition - * @param element - * @return a list diff entry - */ - public static ListDiffEntry createListDiffEntry(final int position, - final boolean isAddition, final Object element) { - return new ListDiffEntry() { - - public int getPosition() { - return position; - } - - public boolean isAddition() { - return isAddition; - } - - public Object getElement() { - return element; - } - }; - } - - /** - * @param addedKey - * @param newValue - * @return a map diff - */ - public static MapDiff createMapDiffSingleAdd(final Object addedKey, - final Object newValue) { - return new MapDiff() { - - public Set getAddedKeys() { - return Collections.singleton(addedKey); - } - - public Set getChangedKeys() { - return Collections.EMPTY_SET; - } - - public Object getNewValue(Object key) { - return newValue; - } - - public Object getOldValue(Object key) { - return null; - } - - public Set getRemovedKeys() { - return Collections.EMPTY_SET; - } - }; - } - - /** - * @param existingKey - * @param oldValue - * @param newValue - * @return a map diff - */ - public static MapDiff createMapDiffSingleChange(final Object existingKey, - final Object oldValue, final Object newValue) { - return new MapDiff() { - - public Set getAddedKeys() { - return Collections.EMPTY_SET; - } - - public Set getChangedKeys() { - return Collections.singleton(existingKey); - } - - public Object getNewValue(Object key) { - return newValue; - } - - public Object getOldValue(Object key) { - return oldValue; - } - - public Set getRemovedKeys() { - return Collections.EMPTY_SET; - } - }; - } - - /** - * @param removedKey - * @param oldValue - * @return a map diff - */ - public static MapDiff createMapDiffSingleRemove(final Object removedKey, - final Object oldValue) { - return new MapDiff() { - - public Set getAddedKeys() { - return Collections.EMPTY_SET; - } - - public Set getChangedKeys() { - return Collections.EMPTY_SET; - } - - public Object getNewValue(Object key) { - return null; - } - - public Object getOldValue(Object key) { - return oldValue; - } - - public Set getRemovedKeys() { - return Collections.singleton(removedKey); - } - }; - } - - /** - * @param copyOfOldMap - * @return a map diff - */ - public static MapDiff createMapDiffRemoveAll(final Map copyOfOldMap) { - return new MapDiff() { - - public Set getAddedKeys() { - return Collections.EMPTY_SET; - } - - public Set getChangedKeys() { - return Collections.EMPTY_SET; - } - - public Object getNewValue(Object key) { - return null; - } - - public Object getOldValue(Object key) { - return copyOfOldMap.get(key); - } - - public Set getRemovedKeys() { - return copyOfOldMap.keySet(); - } - }; - } - - /** - * @param addedKeys - * @param removedKeys - * @param changedKeys - * @param oldValues - * @param newValues - * @return a map diff - */ - public static MapDiff createMapDiff(final Set addedKeys, - final Set removedKeys, final Set changedKeys, final Map oldValues, - final Map newValues) { - return new MapDiff() { - - public Set getAddedKeys() { - return addedKeys; - } - - public Set getChangedKeys() { - return changedKeys; - } - - public Object getNewValue(Object key) { - return newValues.get(key); - } - - public Object getOldValue(Object key) { - return oldValues.get(key); - } - - public Set getRemovedKeys() { - return removedKeys; - } - }; - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/IChangeListener.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/IChangeListener.java deleted file mode 100644 index d0a5cee9..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/IChangeListener.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable; - -import org.eclipse.core.databinding.observable.list.IListChangeListener; -import org.eclipse.core.databinding.observable.map.IMapChangeListener; -import org.eclipse.core.databinding.observable.set.ISetChangeListener; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; - -/** - * Listener for generic change events. Note that the change events do not carry - * information about the change, they only specify the affected observable. To - * listen for specific change events, use more specific change listeners. - * - * @see IValueChangeListener - * @see IListChangeListener - * @see ISetChangeListener - * @see IMapChangeListener - * - * @since 1.0 - */ -public interface IChangeListener extends IObservablesListener { - - /** - * Handle a generic change to the given observable. The given event object - * must only be used locally in this method because it may be reused for - * other change notifications. - * - * @param event - */ - public void handleChange(ChangeEvent event); - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/IObservable.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/IObservable.java deleted file mode 100644 index de8e8cde..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/IObservable.java +++ /dev/null @@ -1,109 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.core.databinding.observable; - -/** - * An object with state that allows to listen for state changes. - * - * <p> - * Implementations must not manage listeners themselves, listener management - * must be delegated to a private instance of type {@link ChangeSupport} if it - * is not inherited from {@link AbstractObservable}. - * </p> - * - * @noextend This interface is not intended to be extended by clients. - * @noimplement This interface is not intended to be implemented by clients. - * Clients should instead subclass one of the classes in the - * framework that implement this interface. Note that direct - * implementers of this interface outside of the framework will be - * broken in future releases when methods are added to this - * interface. - * - * @since 1.0 - * - */ -public interface IObservable { - - /** - * Returns the realm for this observable. Unless otherwise specified, - * getters and setters must be accessed from within this realm. Listeners - * will be within this realm when they receive events from this observable. - * <p> - * Because observables can only be accessed from within one realm, and they - * always fire events on that realm, their state can be observed in an - * incremental way. It is always safe to call getters of an observable from - * within a change listener attached to that observable. - * </p> - * - * @return the realm - */ - public Realm getRealm(); - - /** - * Adds the given change listener to the list of change listeners. Change - * listeners are notified about changes of the state of this observable in a - * generic way, without specifying the change that happened. To get the - * changed state, a change listener needs to query for the current state of - * this observable. - * - * @param listener - */ - public void addChangeListener(IChangeListener listener); - - /** - * Removes the given change listener from the list of change listeners. Has - * no effect if the given listener is not registered as a change listener. - * - * @param listener - */ - public void removeChangeListener(IChangeListener listener); - - /** - * Adds the given stale listener to the list of stale listeners. Stale - * listeners are notified when an observable object becomes stale, not when - * is becomes non-stale. - * - * @param listener - * - * @see #isStale() - */ - public void addStaleListener(IStaleListener listener); - - /** - * Removes the given stale listener from the list of stale listeners. Has no - * effect if the given listener is not registered as a stale listener. - * - * @param listener - */ - public void removeStaleListener(IStaleListener listener); - - /** - * Returns whether the state of this observable is stale and is expected to - * change soon. A non-stale observable that becomes stale will notify its - * stale listeners. A stale object that becomes non-stale does so by - * changing its state and notifying its change listeners, it does <b>not</b> - * notify its stale listeners about becoming non-stale. Clients that do not - * expect asynchronous changes may ignore staleness of observable objects. - * - * @return true if this observable's state is stale and will change soon. - * - * @TrackedGetter - implementers must call - * {@link ObservableTracker#getterCalled(IObservable)}. - */ - public boolean isStale(); - - /** - * Disposes of this observable object, removing all listeners registered - * with this object, and all listeners this object might have registered on - * other objects. - */ - public void dispose(); -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/IObservableCollection.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/IObservableCollection.java deleted file mode 100644 index 66e669af..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/IObservableCollection.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable; - -import java.util.Collection; - -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.set.IObservableSet; - -/** - * Interface for observable collections. Only general change listeners can be - * added to an observable collection. Listeners interested in incremental - * changes have to be added using more concrete subtypes such as - * {@link IObservableList} or {@link IObservableSet}. - * - * @noextend This interface is not intended to be extended by clients. - * @noimplement This interface is not intended to be implemented by clients. - * Clients should instead subclass one of the classes that - * implement this interface. Note that direct implementers of this - * interface outside of the framework will be broken in future - * releases when methods are added to this interface. - * </p> - * - * @since 1.0 - */ -public interface IObservableCollection extends IObservable, Collection { - - /** - * @return the element type of this observable value, or <code>null</code> - * if this observable collection is untyped. - */ - Object getElementType(); - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/IObservablesListener.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/IObservablesListener.java deleted file mode 100644 index bc0687c9..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/IObservablesListener.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable; - -/** - * Marker interface for all listener types in the observables framework. - * - * @noimplement This interface is not intended to be implemented by clients. - * - * @since 1.0 - */ -public interface IObservablesListener { - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/IObserving.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/IObserving.java deleted file mode 100644 index 1c9fc139..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/IObserving.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.databinding.observable; - -/** - * - * Mixin interface for IObservables that observe other objects. - * - * @since 1.0 - * - */ -public interface IObserving { - - /** - * Returns the observed object, or <code>null</code> if this observing - * object does not currently observe an object. - * - * @return the observed object, or <code>null</code> - */ - public Object getObserved(); - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/IStaleListener.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/IStaleListener.java deleted file mode 100644 index 57291983..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/IStaleListener.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable; - -/** - * Listener for staleness events. An observable object is stale if its state - * will change eventually. - * - * @since 1.0 - */ -public interface IStaleListener extends IObservablesListener { - - /** - * Handle the event that the given observable object is now stale. The given - * event object must only be used locally in this method because it may be - * reused for other change notifications. - * - * @param staleEvent - */ - public void handleStale(StaleEvent staleEvent); - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/ObservableEvent.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/ObservableEvent.java deleted file mode 100644 index 38a865c5..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/ObservableEvent.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable; - -import java.util.EventObject; - -/** - * Abstract event object for events fired by {@link IObservable} objects. All - * events fired by observables must be derived from this class so that the way - * of dispatching events can be improved in later versions of the framework. - * - * @since 1.0 - * - */ -public abstract class ObservableEvent extends EventObject { - - /** - * Creates a new observable event. - * - * @param source - */ - public ObservableEvent(IObservable source) { - super(source); - } - - /** - * - */ - private static final long serialVersionUID = 7693906965267871813L; - - /** - * Returns the observable that generated this event. - * - * @return the observable that generated this event - */ - public IObservable getObservable() { - return (IObservable) getSource(); - } - - /** - * Dispatch this event to the given listener. Subclasses must implement this - * method by calling the appropriate type-safe event handling method on the - * given listener according to the type of this event. - * - * @param listener - * the listener that should handle the event - */ - protected abstract void dispatch(IObservablesListener listener); - - /** - * Returns a unique object used for distinguishing this event type from - * others. - * - * @return a unique object representing the concrete type of this event. - */ - protected abstract Object getListenerType(); - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/ObservableTracker.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/ObservableTracker.java deleted file mode 100644 index 8e3fca96..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/ObservableTracker.java +++ /dev/null @@ -1,200 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - Fix NPE, more detailed assert messages (bug 210115) - *******************************************************************************/ -package org.eclipse.core.databinding.observable; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.internal.databinding.IdentityWrapper; -import org.eclipse.core.runtime.Assert; - -/** - * This class makes it possible to monitor whenever an IObservable is read from. - * This can be used to automatically attach and remove listeners. How to use it: - * - * <p> - * If you are implementing an IObservable, invoke getterCalled(this) whenever a - * getter is called - that is, whenever your observable is read from. You only - * need to do this once per method call. If one getter delegates to another, the - * outer getter doesn't need to call the method since the inner one will. - * </p> - * - * <p> - * If you want to determine what observables were used in a particular block of - * code, call runAndMonitor(Runnable). This will execute the given runnable and - * return the set of observables that were read from. - * </p> - * - * <p> - * This can be used to automatically attach listeners. For example, imagine you - * have a block of code that updates some widget by reading from a bunch of - * observables. Whenever one of those observables changes, you want to re-run - * the code and cause the widget to be refreshed. You could do this in the - * traditional manner by attaching one listener to each observable and - * re-running your widget update code whenever one of them changes, but this - * code is repetitive and requires updating the listener code whenever you - * refactor the widget updating code. - * </p> - * - * <p> - * Alternatively, you could use a utility class that runs the code in a - * runAndMonitor block and automatically attach listeners to any observable used - * in updating the widget. The advantage of the latter approach is that it, - * eliminates the code for attaching and detaching listeners and will always - * stay in synch with changes to the widget update logic. - * </p> - * - * @since 1.0 - */ -public class ObservableTracker { - - /** - * Threadlocal storage pointing to the current Set of IObservables, or null - * if none. Note that this is actually the top of a stack. Whenever a method - * changes the current value, it remembers the old value as a local variable - * and restores the old value when the method exits. - */ - private static ThreadLocal currentChangeListener = new ThreadLocal(); - - private static ThreadLocal currentStaleListener = new ThreadLocal(); - - private static ThreadLocal currentObservableSet = new ThreadLocal(); - - /** - * Invokes the given runnable, and returns the set of IObservables that were - * read by the runnable. If the runnable calls this method recursively, the - * result will not contain IObservables that were used within the inner - * runnable. - * - * @param runnable - * runnable to execute - * @param changeListener - * listener to register with all accessed observables - * @param staleListener - * listener to register with all accessed observables, or - * <code>null</code> if no stale listener is to be registered - * @return an array of unique observable objects - */ - public static IObservable[] runAndMonitor(Runnable runnable, - IChangeListener changeListener, IStaleListener staleListener) { - // Remember the previous value in the listener stack - Set lastObservableSet = (Set) currentObservableSet.get(); - IChangeListener lastChangeListener = (IChangeListener) currentChangeListener - .get(); - IStaleListener lastStaleListener = (IStaleListener) currentStaleListener - .get(); - - Set observableSet = new HashSet(); - // Push the new listeners to the top of the stack - currentObservableSet.set(observableSet); - currentChangeListener.set(changeListener); - currentStaleListener.set(staleListener); - try { - runnable.run(); - } finally { - // Pop the new listener off the top of the stack (by restoring the - // previous listener) - currentObservableSet.set(lastObservableSet); - currentChangeListener.set(lastChangeListener); - currentStaleListener.set(lastStaleListener); - } - - int i = 0; - IObservable[] result = new IObservable[observableSet.size()]; - for (Iterator it = observableSet.iterator(); it.hasNext();) { - IdentityWrapper wrapper = (IdentityWrapper) it.next(); - result[i++] = (IObservable) wrapper.unwrap(); - } - - return result; - } - - /** - * Runs the given runnable without tracking dependencies. - * @param runnable - * - * @since 1.1 - */ - public static void runAndIgnore(Runnable runnable) { - // Remember the previous value in the listener stack - Set lastObservableSet = (Set) currentObservableSet.get(); - IChangeListener lastChangeListener = (IChangeListener) currentChangeListener - .get(); - IStaleListener lastStaleListener = (IStaleListener) currentStaleListener - .get(); - currentObservableSet.set(null); - currentChangeListener.set(null); - currentStaleListener.set(null); - try { - runnable.run(); - } finally { - // Pop the new listener off the top of the stack (by restoring the - // previous listener) - currentObservableSet.set(lastObservableSet); - currentChangeListener.set(lastChangeListener); - currentStaleListener.set(lastStaleListener); - } - } - - /* - * Returns the same string as the default Object.toString() implementation. - * getterCalled() uses this method IObservable.toString() to avoid infinite - * recursion and stack overflow. - */ - private static String toString(IObservable observable) { - return observable.getClass().getName() + "@" //$NON-NLS-1$ - + Integer.toHexString(System.identityHashCode(observable)); - } - - /** - * Notifies the ObservableTracker that an observable was read from. The - * JavaDoc for methods that invoke this method should include the following - * tag: "@TrackedGetter This method will notify ObservableTracker that the - * receiver has been read from". This lets callers know that they can rely - * on automatic updates from the object without explicitly attaching a - * listener. - * - * @param observable - */ - public static void getterCalled(IObservable observable) { - Realm realm = observable.getRealm(); - if (realm == null) // observable.isDisposed() would be more appropriate if it existed - Assert.isTrue(false, "Getter called on disposed observable " //$NON-NLS-1$ - + toString(observable)); - if (!realm.isCurrent()) - Assert.isTrue(false, "Getter called outside realm of observable " //$NON-NLS-1$ - + toString(observable)); - - Set lastObservableSet = (Set) currentObservableSet.get(); - if (lastObservableSet == null) { - return; - } - IChangeListener lastChangeListener = (IChangeListener) currentChangeListener - .get(); - IStaleListener lastStaleListener = (IStaleListener) currentStaleListener - .get(); - - boolean added = false; - if (lastObservableSet != null) { - added = lastObservableSet.add(new IdentityWrapper(observable)); - } - - // If anyone is listening for observable usage... - if (added && lastChangeListener != null) { - observable.addChangeListener(lastChangeListener); - } - if (added && lastStaleListener != null) { - observable.addStaleListener(lastStaleListener); - } - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/Observables.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/Observables.java deleted file mode 100644 index f2720801..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/Observables.java +++ /dev/null @@ -1,514 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006-2008 Cerner Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Brad Reynolds - initial API and implementation - * Matt Carter - bug 212518 (constantObservableValue) - * Matthew Hall - bugs 208332, 212518, 219909, 184830 - * Marko Topolnik - bug 184830 - ******************************************************************************/ - -package org.eclipse.core.databinding.observable; - -import java.util.List; -import java.util.Set; - -import org.eclipse.core.databinding.observable.list.IListChangeListener; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.ObservableList; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.masterdetail.MasterDetailObservables; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.ISetChangeListener; -import org.eclipse.core.databinding.observable.set.ObservableSet; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.internal.databinding.observable.ConstantObservableValue; -import org.eclipse.core.internal.databinding.observable.EmptyObservableList; -import org.eclipse.core.internal.databinding.observable.EmptyObservableSet; -import org.eclipse.core.internal.databinding.observable.MapEntryObservableValue; -import org.eclipse.core.internal.databinding.observable.ProxyObservableList; -import org.eclipse.core.internal.databinding.observable.ProxyObservableSet; -import org.eclipse.core.internal.databinding.observable.StalenessObservableValue; -import org.eclipse.core.internal.databinding.observable.UnmodifiableObservableList; -import org.eclipse.core.internal.databinding.observable.UnmodifiableObservableSet; -import org.eclipse.core.internal.databinding.observable.UnmodifiableObservableValue; -import org.eclipse.core.runtime.Assert; - -/** - * Contains static methods to operate on or return - * {@link IObservable Observables}. - * - * @since 1.0 - */ -public class Observables { - /** - * Returns an unmodifiable observable value backed by the given observable - * value. - * - * @param value - * the value to wrap in an unmodifiable value - * @return an unmodifiable observable value backed by the given observable - * value - * @since 1.1 - */ - public static IObservableValue unmodifiableObservableValue( - IObservableValue value) { - Assert.isNotNull(value, "Argument 'value' cannot be null"); //$NON-NLS-1$ - return new UnmodifiableObservableValue(value); - } - - /** - * Returns an observable value with the given constant value. - * - * @param realm - * the observable's realm - * @param value - * the observable's constant value - * @param valueType - * the observable's value type - * @return an immutable observable value with the given constant value - * @since 1.1 - */ - public static IObservableValue constantObservableValue(Realm realm, - Object value, Object valueType) { - return new ConstantObservableValue(realm, value, valueType); - } - - /** - * Returns an observable value with the given constant value. - * - * @param realm - * the observable's realm - * @param value - * the observable's constant value - * @return an immutable observable value with the given constant value - * @since 1.1 - */ - public static IObservableValue constantObservableValue(Realm realm, - Object value) { - return constantObservableValue(realm, value, null); - } - - /** - * Returns an observable value with the given constant value. - * - * @param value - * the observable's constant value - * @param valueType - * the observable's value type - * @return an immutable observable value with the given constant value - * @since 1.1 - */ - public static IObservableValue constantObservableValue(Object value, - Object valueType) { - return constantObservableValue(Realm.getDefault(), value, valueType); - } - - /** - * Returns an observable value with the given constant value. - * - * @param value - * the observable's constant value - * @return an immutable observable value with the given constant value - * @since 1.1 - */ - public static IObservableValue constantObservableValue(Object value) { - return constantObservableValue(Realm.getDefault(), value, null); - } - - /** - * Returns an unmodifiable observable list backed by the given observable - * list. - * - * @param list - * the list to wrap in an unmodifiable list - * @return an unmodifiable observable list backed by the given observable - * list - */ - public static IObservableList unmodifiableObservableList( - IObservableList list) { - if (list == null) { - throw new IllegalArgumentException("List parameter cannot be null."); //$NON-NLS-1$ - } - - return new UnmodifiableObservableList(list); - } - - /** - * Returns an unmodifiable observable set backed by the given observable - * set. - * - * @param set - * the set to wrap in an unmodifiable set - * @return an unmodifiable observable set backed by the given observable set - * @since 1.1 - */ - public static IObservableSet unmodifiableObservableSet(IObservableSet set) { - if (set == null) { - throw new IllegalArgumentException("Set parameter cannot be null"); //$NON-NLS-1$ - } - - return new UnmodifiableObservableSet(set); - } - - /** - * Returns an empty observable list. The returned list continues to work - * after it has been disposed of and can be disposed of multiple times. - * - * @return an empty observable list. - */ - public static IObservableList emptyObservableList() { - return emptyObservableList(Realm.getDefault(), null); - } - - /** - * Returns an empty observable list of the given element type. The returned - * list continues to work after it has been disposed of and can be disposed - * of multiple times. - * - * @param elementType - * the element type of the returned list - * @return an empty observable list - * @since 1.1 - */ - public static IObservableList emptyObservableList(Object elementType) { - return emptyObservableList(Realm.getDefault(), elementType); - } - - /** - * Returns an empty observable list belonging to the given realm. The - * returned list continues to work after it has been disposed of and can be - * disposed of multiple times. - * - * @param realm - * the realm of the returned list - * @return an empty observable list. - */ - public static IObservableList emptyObservableList(Realm realm) { - return emptyObservableList(realm, null); - } - - /** - * Returns an empty observable list of the given element type and belonging - * to the given realm. The returned list continues to work after it has been - * disposed of and can be disposed of multiple times. - * - * @param realm - * the realm of the returned list - * @param elementType - * the element type of the returned list - * @return an empty observable list - * @since 1.1 - */ - public static IObservableList emptyObservableList(Realm realm, - Object elementType) { - return new EmptyObservableList(realm, elementType); - } - - /** - * Returns an empty observable set. The returned set continues to work after - * it has been disposed of and can be disposed of multiple times. - * - * @return an empty observable set. - */ - public static IObservableSet emptyObservableSet() { - return emptyObservableSet(Realm.getDefault(), null); - } - - /** - * Returns an empty observable set of the given element type. The returned - * set continues to work after it has been disposed of and can be disposed - * of multiple times. - * - * @param elementType - * the element type of the returned set - * @return an empty observable set - * @since 1.1 - */ - public static IObservableSet emptyObservableSet(Object elementType) { - return emptyObservableSet(Realm.getDefault(), elementType); - } - - /** - * Returns an empty observable set belonging to the given realm. The - * returned set continues to work after it has been disposed of and can be - * disposed of multiple times. - * - * @param realm - * the realm of the returned set - * @return an empty observable set. - */ - public static IObservableSet emptyObservableSet(Realm realm) { - return emptyObservableSet(realm, null); - } - - /** - * Returns an empty observable set of the given element type and belonging - * to the given realm. The returned set continues to work after it has been - * disposed of and can be disposed of multiple times. - * - * @param realm - * the realm of the returned set - * @param elementType - * the element type of the returned set - * @return an empty observable set - * @since 1.1 - */ - public static IObservableSet emptyObservableSet(Realm realm, - Object elementType) { - return new EmptyObservableSet(realm, elementType); - } - - /** - * Returns an observable set backed by the given set. - * - * @param set - * the set to wrap in an IObservableSet - * @return an observable set backed by the given set - */ - public static IObservableSet staticObservableSet(Set set) { - return staticObservableSet(Realm.getDefault(), set, Object.class); - } - - /** - * Returns an observable set of the given element type, backed by the given - * set. - * - * @param set - * the set to wrap in an IObservableSet - * @param elementType - * the element type of the returned set - * @return Returns an observable set backed by the given unchanging set - * @since 1.1 - */ - public static IObservableSet staticObservableSet(Set set, Object elementType) { - return staticObservableSet(Realm.getDefault(), set, elementType); - } - - /** - * Returns an observable set belonging to the given realm, backed by the - * given set. - * - * @param realm - * the realm of the returned set - * @param set - * the set to wrap in an IObservableSet - * @return an observable set backed by the given unchanging set - */ - public static IObservableSet staticObservableSet(Realm realm, Set set) { - return staticObservableSet(realm, set, Object.class); - } - - /** - * Returns an observable set of the given element type and belonging to the - * given realm, backed by the given set. - * - * @param realm - * the realm of the returned set - * @param set - * the set to wrap in an IObservableSet - * @param elementType - * the element type of the returned set - * @return an observable set backed by the given set - * @since 1.1 - */ - public static IObservableSet staticObservableSet(Realm realm, Set set, - Object elementType) { - return new ObservableSet(realm, set, elementType) { - public void addChangeListener(IChangeListener listener) { - } - - public void addStaleListener(IStaleListener listener) { - } - - public void addSetChangeListener(ISetChangeListener listener) { - } - }; - } - - /** - * Returns an observable set that contains the same elements as the given - * set, and fires the same events as the given set, but can be disposed of - * without disposing of the wrapped set. - * - * @param target - * the set to wrap - * @return a disposable proxy for the given observable set - */ - public static IObservableSet proxyObservableSet(IObservableSet target) { - return new ProxyObservableSet(target); - } - - /** - * Returns an observable list that contains the same elements as the given - * list, and fires the same events as the given list, but can be disposed of - * without disposing of the wrapped list. - * - * @param target - * the list to wrap - * @return a disposable proxy for the given observable list - * @since 1.1 - */ - public static IObservableList proxyObservableList(IObservableList target) { - return new ProxyObservableList(target); - } - - /** - * Returns an observable list backed by the given list. - * - * @param list - * the list to wrap in an IObservableList - * @return an observable list backed by the given unchanging list - */ - public static IObservableList staticObservableList(List list) { - return staticObservableList(Realm.getDefault(), list, Object.class); - } - - /** - * Returns an observable list of the given element type, backed by the given - * list. - * - * @param list - * the list to wrap in an IObservableList - * @param elementType - * the element type of the returned list - * @return an observable list backed by the given unchanging list - * @since 1.1 - */ - public static IObservableList staticObservableList(List list, - Object elementType) { - return staticObservableList(Realm.getDefault(), list, elementType); - } - - /** - * Returns an observable list belonging to the given realm, backed by the - * given list. - * - * @param realm - * the realm of the returned list - * @param list - * the list to wrap in an IObservableList - * @return an observable list backed by the given unchanging list - */ - public static IObservableList staticObservableList(Realm realm, List list) { - return staticObservableList(realm, list, Object.class); - } - - /** - * Returns an observable list of the given element type and belonging to the - * given realm, backed by the given list. - * - * @param realm - * the realm of the returned list - * @param list - * the list to wrap in an IObservableList - * @param elementType - * the element type of the returned list - * @return an observable list backed by the given unchanging list - * @since 1.1 - */ - public static IObservableList staticObservableList(Realm realm, List list, - Object elementType) { - return new ObservableList(realm, list, elementType) { - public void addChangeListener(IChangeListener listener) { - } - - public void addStaleListener(IStaleListener listener) { - } - - public void addListChangeListener(IListChangeListener listener) { - } - }; - } - - /** - * Returns an observable value of type <code>Boolean.TYPE</code> which - * tracks whether the given observable is stale. - * - * @param observable - * the observable to track - * @return an observable value which tracks whether the given observable is - * stale - * - * @since 1.1 - */ - public static IObservableValue observeStale(IObservable observable) { - return new StalenessObservableValue(observable); - } - - /** - * Returns an observable value that tracks changes to the value of an - * observable map's entry specified by its key. - * <p> - * The state where the key does not exist in the map is equivalent to the - * state where the key exists and its value is <code>null</code>. The - * transition between these two states is not considered a value change and - * no event is fired. - * - * @param map - * the observable map whose entry will be tracked. - * @param key - * the key identifying the map entry to track. - * @param valueType - * the type of the value. May be <code>null</code>, meaning - * the value is untyped. - * @return an observable value that tracks the value associated with the - * specified key in the given map - * @since 1.1 - */ - public static IObservableValue observeMapEntry(IObservableMap map, - Object key, Object valueType) { - return new MapEntryObservableValue(map, key, valueType); - } - - /** - * Returns a factory for creating obervable values tracking the value of the - * {@link IObservableMap observable map} entry identified by a particular - * key. - * - * @param map - * the observable map whose entry will be tracked. - * @param valueType - * the type of the value. May be <code>null</code>, meaning - * the value is untyped. - * @return a factory for creating observable values tracking the value of - * the observable map entry identified by a particular key object. - * @since 1.1 - */ - public static IObservableFactory mapEntryValueFactory( - final IObservableMap map, final Object valueType) { - return new IObservableFactory() { - public IObservable createObservable(Object key) { - return observeMapEntry(map, key, valueType); - } - }; - } - - /** - * Helper method for <code>MasterDetailObservables.detailValue(master, - * mapEntryValueFactory(map, valueType), valueType)</code>. - * - * @param map - * the observable map whose entry will be tracked. - * @param master - * the observable value that identifies which map entry to track. - * @param valueType - * the type of the value. May be <code>null</code>, meaning - * the value is untyped. - * @return an observable value tracking the current value of the specified - * key in the given map an observable value that tracks the current - * value of the named property for the current value of the master - * observable value - * @since 1.1 - */ - public static IObservableValue observeDetailMapEntry(IObservableMap map, - IObservableValue master, Object valueType) { - return MasterDetailObservables.detailValue(master, - mapEntryValueFactory(map, valueType), valueType); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/Realm.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/Realm.java deleted file mode 100644 index 27d08ff7..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/Realm.java +++ /dev/null @@ -1,293 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 168153 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable; - -import org.eclipse.core.databinding.Binding; -import org.eclipse.core.databinding.util.Policy; -import org.eclipse.core.internal.databinding.Queue; -import org.eclipse.core.runtime.ISafeRunnable; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.SafeRunner; -import org.eclipse.core.runtime.Status; - -/** - * A realm defines a context from which objects implementing {@link IObservable} - * must be accessed, and on which these objects will notify their listeners. To - * bridge between observables from different realms, subclasses of - * {@link Binding} can be used. - * <p> - * A block of code is said to be executing within a realm if calling - * {@link #isCurrent()} from that block returns true. Code reached by calling - * methods from that block will execute within the same realm, with the - * exception of methods on this class that can be used to execute code within a - * specific realm. Clients can use {@link #syncExec(Runnable)}, - * {@link #asyncExec(Runnable)}, or {@link #exec(Runnable)} to execute a - * runnable within this realm. Note that using {@link #syncExec(Runnable)} can - * lead to deadlocks and should be avoided if the current thread holds any - * locks. - * </p> - * <p> - * It is instructive to think about possible implementations of Realm: It can be - * based on executing on a designated thread such as a UI thread, or based on - * holding a lock. In the former case, calling syncExec on a realm that is not - * the current realm will execute the given runnable on a different thread (the - * designated thread). In the latter case, calling syncExec may execute the - * given runnable on the calling thread, but calling - * {@link #asyncExec(Runnable)} will execute the given runnable on a different - * thread. Therefore, no assumptions can be made about the thread that will - * execute arguments to {@link #asyncExec(Runnable)}, - * {@link #syncExec(Runnable)}, or {@link #exec(Runnable)}. - * </p> - * <p> - * It is possible that a block of code is executing within more than one realm. - * This can happen for implementations of Realm that are based on holding a lock - * but don't use a separate thread to run runnables given to - * {@link #syncExec(Runnable)}. Realm implementations of this kind should be - * appropriately documented because it increases the opportunity for deadlock. - * </p> - * <p> - * Some implementations of {@link IObservable} provide constructors which do not - * take a Realm argument and are specified to create the observable instance - * with the current default realm. The default realm can be set for the - * currently executing thread by using {@link #runWithDefault(Realm, Runnable)}. - * Note that the default realm does not have to be the current realm. - * </p> - * <p> - * Subclasses must override at least one of asyncExec()/syncExec(). For realms - * based on a designated thread, it may be easier to implement asyncExec and - * keep the default implementation of syncExec. For realms based on holding a - * lock, it may be easier to implement syncExec and keep the default - * implementation of asyncExec. - * </p> - * - * @since 1.0 - * - * @see IObservable - */ -public abstract class Realm { - - private static ThreadLocal defaultRealm = new ThreadLocal(); - - /** - * Returns the default realm for the calling thread, or <code>null</code> - * if no default realm has been set. - * - * @return the default realm, or <code>null</code> - */ - public static Realm getDefault() { - return (Realm) defaultRealm.get(); - } - - /** - * Sets the default realm for the calling thread, returning the current - * default thread. This method is inherently unsafe, it is recommended to - * use {@link #runWithDefault(Realm, Runnable)} instead. This method is - * exposed to subclasses to facilitate testing. - * - * @param realm - * the new default realm, or <code>null</code> - * @return the previous default realm, or <code>null</code> - */ - protected static Realm setDefault(Realm realm) { - Realm oldValue = getDefault(); - defaultRealm.set(realm); - return oldValue; - } - - /** - * @return true if the caller is executing in this realm. This method must - * not have side-effects (such as, for example, implicitly placing - * the caller in this realm). - */ - abstract public boolean isCurrent(); - - private Thread workerThread; - - Queue workQueue = new Queue(); - - /** - * Runs the given runnable. If an exception occurs within the runnable, it - * is logged and not re-thrown. If the runnable implements - * {@link ISafeRunnable}, the exception is passed to its - * <code>handleException<code> method. - * - * @param runnable - */ - protected static void safeRun(final Runnable runnable) { - ISafeRunnable safeRunnable; - if (runnable instanceof ISafeRunnable) { - safeRunnable = (ISafeRunnable) runnable; - } else { - safeRunnable = new ISafeRunnable() { - public void handleException(Throwable exception) { - Policy - .getLog() - .log( - new Status( - IStatus.ERROR, - Policy.JFACE_DATABINDING, - IStatus.OK, - "Unhandled exception: " + exception.getMessage(), exception)); //$NON-NLS-1$ - } - public void run() throws Exception { - runnable.run(); - } - }; - } - SafeRunner.run(safeRunnable); - } - - /** - * Causes the <code>run()</code> method of the runnable to be invoked from - * within this realm. If the caller is executing in this realm, the - * runnable's run method is invoked directly, otherwise it is run at the - * next reasonable opportunity using asyncExec. - * <p> - * If the given runnable is an instance of {@link ISafeRunnable}, its - * exception handler method will be called if any exceptions occur while - * running it. Otherwise, the exception will be logged. - * </p> - * - * @param runnable - */ - public void exec(Runnable runnable) { - if (isCurrent()) { - safeRun(runnable); - } else { - asyncExec(runnable); - } - } - - /** - * Causes the <code>run()</code> method of the runnable to be invoked from - * within this realm at the next reasonable opportunity. The caller of this - * method continues to run in parallel, and is not notified when the - * runnable has completed. - * <p> - * If the given runnable is an instance of {@link ISafeRunnable}, its - * exception handler method will be called if any exceptions occur while - * running it. Otherwise, the exception will be logged. - * </p> - * <p> - * Subclasses should use {@link #safeRun(Runnable)} to run the runnable. - * </p> - * - * @param runnable - */ - public void asyncExec(Runnable runnable) { - synchronized (workQueue) { - ensureWorkerThreadIsRunning(); - workQueue.enqueue(runnable); - workQueue.notifyAll(); - } - } - - /** - * - */ - private void ensureWorkerThreadIsRunning() { - if (workerThread == null) { - workerThread = new Thread() { - public void run() { - try { - while (true) { - Runnable work = null; - synchronized (workQueue) { - while (workQueue.isEmpty()) { - workQueue.wait(); - } - work = (Runnable) workQueue.dequeue(); - } - syncExec(work); - } - } catch (InterruptedException e) { - // exit - } - } - }; - workerThread.start(); - } - } - - /** - * Causes the <code>run()</code> method of the runnable to be invoked from - * within this realm at the next reasonable opportunity. This method is - * blocking the caller until the runnable completes. - * <p> - * If the given runnable is an instance of {@link ISafeRunnable}, its - * exception handler method will be called if any exceptions occur while - * running it. Otherwise, the exception will be logged. - * </p> - * <p> - * Subclasses should use {@link #safeRun(Runnable)} to run the runnable. - * </p> - * <p> - * Note: This class is not meant to be called by clients and therefore has - * only protected access. - * </p> - * - * @param runnable - */ - protected void syncExec(Runnable runnable) { - SyncRunnable syncRunnable = new SyncRunnable(runnable); - asyncExec(syncRunnable); - synchronized (syncRunnable) { - while (!syncRunnable.hasRun) { - try { - syncRunnable.wait(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - } - } - } - - static class SyncRunnable implements Runnable { - boolean hasRun = false; - - private Runnable runnable; - - SyncRunnable(Runnable runnable) { - this.runnable = runnable; - } - - public void run() { - try { - safeRun(runnable); - } finally { - synchronized (this) { - hasRun = true; - this.notifyAll(); - } - } - } - } - - /** - * Sets the provided <code>realm</code> as the default for the duration of - * {@link Runnable#run()} and resets the previous realm after completion. - * Note that this will not set the given realm as the current realm. - * - * @param realm - * @param runnable - */ - public static void runWithDefault(Realm realm, Runnable runnable) { - Realm oldRealm = Realm.getDefault(); - try { - defaultRealm.set(realm); - runnable.run(); - } finally { - defaultRealm.set(oldRealm); - } - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/StaleEvent.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/StaleEvent.java deleted file mode 100644 index 14e8c76b..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/StaleEvent.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable; - -/** - * Generic event denoting that the state of an {@link IObservable} object is - * about to change. Note that this event is only fired when an observable - * becomes stale, not when it becomes unstale; an observable that becomes - * unstale should always fire a change event. Staleness can be used (for - * example) to notify listeners when an observable has started a background - * thread for updating its state. Clients can safely ignore staleness. - * - * @see IObservable#isStale() - * - * @since 1.0 - * - */ -public class StaleEvent extends ObservableEvent { - - /** - * Creates a new stale event. - * - * @param source - * the source observable - */ - public StaleEvent(IObservable source) { - super(source); - } - - /** - * - */ - private static final long serialVersionUID = 3491012225431471077L; - - static final Object TYPE = new Object(); - - protected void dispatch(IObservablesListener listener) { - ((IStaleListener) listener).handleStale(this); - } - - protected Object getListenerType() { - return TYPE; - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/AbstractObservableList.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/AbstractObservableList.java deleted file mode 100644 index 658ff7f6..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/AbstractObservableList.java +++ /dev/null @@ -1,312 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - * Brad Reynolds - bug 167204 - * Matthew Hall - bug 118516 - * Matthew Hall - bug 208858 - * Matthew Hall - bug 208332 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.list; - -import java.util.AbstractList; -import java.util.Collection; -import java.util.Iterator; - -import org.eclipse.core.databinding.observable.ChangeEvent; -import org.eclipse.core.databinding.observable.ChangeSupport; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.AssertionFailedException; - -/** - * Subclasses should override at least get(int index) and size(). - * - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * - * @since 1.0 - * - */ -public abstract class AbstractObservableList extends AbstractList implements - IObservableList { - - private ChangeSupport changeSupport; - - /** - * @param realm - * - */ - public AbstractObservableList(Realm realm) { - Assert.isNotNull(realm, "Realm cannot be null"); //$NON-NLS-1$ - changeSupport = new ChangeSupport(realm){ - protected void firstListenerAdded() { - AbstractObservableList.this.firstListenerAdded(); - } - protected void lastListenerRemoved() { - AbstractObservableList.this.lastListenerRemoved(); - } - }; - } - - /** - * - */ - public AbstractObservableList() { - this(Realm.getDefault()); - } - - public boolean isStale() { - getterCalled(); - return false; - } - - public synchronized void addListChangeListener(IListChangeListener listener) { - changeSupport.addListener(ListChangeEvent.TYPE, listener); - } - - public synchronized void removeListChangeListener(IListChangeListener listener) { - changeSupport.removeListener(ListChangeEvent.TYPE, listener); - } - - protected void fireListChange(ListDiff diff) { - // fire general change event first - fireChange(); - changeSupport.fireEvent(new ListChangeEvent(this, diff)); - } - - public synchronized void addChangeListener(IChangeListener listener) { - changeSupport.addChangeListener(listener); - } - - public synchronized void removeChangeListener(IChangeListener listener) { - changeSupport.removeChangeListener(listener); - } - - public synchronized void addStaleListener(IStaleListener listener) { - changeSupport.addStaleListener(listener); - } - - public synchronized void removeStaleListener(IStaleListener listener) { - changeSupport.removeStaleListener(listener); - } - - /** - * Fires change event. Must be invoked from the current realm. - */ - protected void fireChange() { - checkRealm(); - changeSupport.fireEvent(new ChangeEvent(this)); - } - - /** - * Fires stale event. Must be invoked from the current realm. - */ - protected void fireStale() { - checkRealm(); - changeSupport.fireEvent(new StaleEvent(this)); - } - - /** - * - */ - protected void firstListenerAdded() { - } - - /** - * - */ - protected void lastListenerRemoved() { - } - - /** - * - */ - public synchronized void dispose() { - changeSupport = null; - lastListenerRemoved(); - } - - public final int size() { - getterCalled(); - return doGetSize(); - } - - /** - * @return the size - */ - protected abstract int doGetSize(); - - /** - * - */ - private void getterCalled() { - ObservableTracker.getterCalled(this); - } - - public boolean isEmpty() { - getterCalled(); - return super.isEmpty(); - } - - public boolean contains(Object o) { - getterCalled(); - return super.contains(o); - } - - public Iterator iterator() { - getterCalled(); - final Iterator wrappedIterator = super.iterator(); - return new Iterator() { - public void remove() { - wrappedIterator.remove(); - } - - public boolean hasNext() { - return wrappedIterator.hasNext(); - } - - public Object next() { - return wrappedIterator.next(); - } - }; - } - - public Object[] toArray() { - getterCalled(); - return super.toArray(); - } - - public Object[] toArray(Object a[]) { - getterCalled(); - return super.toArray(a); - } - - // Modification Operations - - public boolean add(Object o) { - getterCalled(); - return super.add(o); - } - - /** - * Moves the element located at <code>oldIndex</code> to - * <code>newIndex</code>. This method is equivalent to calling - * <code>add(newIndex, remove(oldIndex))</code>. - * <p> - * Subclasses should override this method to deliver list change - * notification for the remove and add operations in the same - * ListChangeEvent, as this allows {@link ListDiff#accept(ListDiffVisitor)} - * to recognize the operation as a move. - * - * @param oldIndex - * the element's position before the move. Must be within the - * range <code>0 <= oldIndex < size()</code>. - * @param newIndex - * the element's position after the move. Must be within the - * range <code>0 <= newIndex < size()</code>. - * @return the element that was moved. - * @throws IndexOutOfBoundsException - * if either argument is out of range (<code>0 <= index < size()</code>). - * @see ListDiffVisitor#handleMove(int, int, Object) - * @see ListDiff#accept(ListDiffVisitor) - * @since 1.1 - */ - public Object move(int oldIndex, int newIndex) { - checkRealm(); - int size = doGetSize(); - if (oldIndex < 0 || oldIndex >= size) - throw new IndexOutOfBoundsException( - "oldIndex: " + oldIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$ - if (newIndex < 0 || newIndex >= size) - throw new IndexOutOfBoundsException( - "newIndex: " + newIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$ - Object element = remove(oldIndex); - add(newIndex, element); - return element; - } - - public boolean remove(Object o) { - getterCalled(); - return super.remove(o); - } - - // Bulk Modification Operations - - public boolean containsAll(Collection c) { - getterCalled(); - return super.containsAll(c); - } - - public boolean addAll(Collection c) { - getterCalled(); - return super.addAll(c); - } - - public boolean addAll(int index, Collection c) { - getterCalled(); - return super.addAll(c); - } - - public boolean removeAll(Collection c) { - getterCalled(); - return super.removeAll(c); - } - - public boolean retainAll(Collection c) { - getterCalled(); - return super.retainAll(c); - } - - // Comparison and hashing - - public boolean equals(Object o) { - getterCalled(); - return super.equals(o); - } - - public int hashCode() { - getterCalled(); - return super.hashCode(); - } - - public int indexOf(Object o) { - getterCalled(); - return super.indexOf(o); - } - - public int lastIndexOf(Object o) { - getterCalled(); - return super.lastIndexOf(o); - } - - public Realm getRealm() { - return changeSupport.getRealm(); - } - - /** - * Asserts that the realm is the current realm. - * - * @see Realm#isCurrent() - * @throws AssertionFailedException - * if the realm is not the current realm - */ - protected void checkRealm() { - Assert.isTrue(getRealm().isCurrent(), - "This operation must be run within the observable's realm"); //$NON-NLS-1$ - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/ComputedList.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/ComputedList.java deleted file mode 100644 index e7f6b2b8..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/ComputedList.java +++ /dev/null @@ -1,290 +0,0 @@ -/************************************************************************************************************ - * Copyright (c) 2007 Matthew Hall 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: - * Matthew Hall - initial API and implementation - * IBM Corporation - initial API and implementation - * Brad Reynolds - initial API and implementation (through bug 116920 and bug 147515) - * Matthew Hall - bug 211786 - ***********************************************************************************************************/ -package org.eclipse.core.databinding.observable.list; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.eclipse.core.databinding.observable.ChangeEvent; -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.StaleEvent; - -/** - * A Lazily calculated list that automatically computes and registers listeners - * on its dependencies as long as all of its dependencies are IObservable - * objects - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * - * @since 1.1 - */ -public abstract class ComputedList extends AbstractObservableList { - private List cachedList = new ArrayList(); - - private boolean dirty = true; - private boolean stale = false; - - private IObservable[] dependencies = new IObservable[0]; - - /** - * Creates a computed list in the default realm and with an unknown (null) - * element type. - */ - public ComputedList() { - this(Realm.getDefault(), null); - } - - /** - * Creates a computed list in the default realm and with the given element - * type. - * - * @param elementType - * the element type, may be <code>null</code> to indicate - * unknown element type - */ - public ComputedList(Object elementType) { - this(Realm.getDefault(), elementType); - } - - /** - * Creates a computed list in given realm and with an unknown (null) element - * type. - * - * @param realm - * the realm - * - */ - public ComputedList(Realm realm) { - this(realm, null); - } - - /** - * Creates a computed list in the given realm and with the given element - * type. - * - * @param realm - * the realm - * @param elementType - * the element type, may be <code>null</code> to indicate - * unknown element type - */ - public ComputedList(Realm realm, Object elementType) { - super(realm); - this.elementType = elementType; - } - - /** - * Inner class that implements interfaces that we don't want to expose as - * public API. Each interface could have been implemented using a separate - * anonymous class, but we combine them here to reduce the memory overhead - * and number of classes. - * - * <p> - * The Runnable calls calculate and stores the result in cachedList. - * </p> - * - * <p> - * The IChangeListener stores each observable in the dependencies list. This - * is registered as the listener when calling ObservableTracker, to detect - * every observable that is used by computeValue. - * </p> - * - * <p> - * The IChangeListener is attached to every dependency. - * </p> - * - */ - private class PrivateInterface implements Runnable, IChangeListener, - IStaleListener { - public void run() { - cachedList = calculate(); - if (cachedList == null) - cachedList = Collections.EMPTY_LIST; - } - - public void handleStale(StaleEvent event) { - if (!dirty) - makeStale(); - } - - public void handleChange(ChangeEvent event) { - makeDirty(); - } - } - - private PrivateInterface privateInterface = new PrivateInterface(); - - private Object elementType; - - protected int doGetSize() { - return doGetList().size(); - } - - public Object get(int index) { - getterCalled(); - return doGetList().get(index); - } - - private final List getList() { - getterCalled(); - return doGetList(); - } - - final List doGetList() { - if (dirty) { - // This line will do the following: - // - Run the calculate method - // - While doing so, add any observable that is touched to the - // dependencies list - IObservable[] newDependencies = ObservableTracker.runAndMonitor( - privateInterface, privateInterface, null); - - // If any dependencies are stale, a stale event will be fired here - // even if we were already stale before recomputing. This is in case - // clients assume that a list change is indicative of non-staleness. - stale = false; - for (int i = 0; i < newDependencies.length; i++) { - if (newDependencies[i].isStale()) { - makeStale(); - break; - } - } - - if (!stale) { - for (int i = 0; i < newDependencies.length; i++) { - newDependencies[i].addStaleListener(privateInterface); - } - } - - dependencies = newDependencies; - - dirty = false; - } - - return cachedList; - } - - private void getterCalled() { - ObservableTracker.getterCalled(this); - } - - /** - * Subclasses must override this method to calculate the list contents. - * - * @return the object's list. - */ - protected abstract List calculate(); - - private void makeDirty() { - if (!dirty) { - dirty = true; - - makeStale(); - - stopListening(); - - // copy the old list - final List oldList = new ArrayList(cachedList); - // Fire the "dirty" event. This implementation recomputes the new - // list lazily. - fireListChange(new ListDiff() { - ListDiffEntry[] differences; - - public ListDiffEntry[] getDifferences() { - if (differences == null) - differences = Diffs.computeListDiff(oldList, getList()) - .getDifferences(); - return differences; - } - }); - } - } - - private void stopListening() { - if (dependencies != null) { - for (int i = 0; i < dependencies.length; i++) { - IObservable observable = dependencies[i]; - - observable.removeChangeListener(privateInterface); - observable.removeStaleListener(privateInterface); - } - dependencies = null; - } - } - - private void makeStale() { - if (!stale) { - stale = true; - fireStale(); - } - } - - public boolean isStale() { - // recalculate list if dirty, to ensure staleness is correct. - getList(); - return stale; - } - - public Object getElementType() { - return elementType; - } - - public synchronized void addChangeListener(IChangeListener listener) { - super.addChangeListener(listener); - // If somebody is listening, we need to make sure we attach our own - // listeners - computeListForListeners(); - } - - public synchronized void addListChangeListener(IListChangeListener listener) { - super.addListChangeListener(listener); - // If somebody is listening, we need to make sure we attach our own - // listeners - computeListForListeners(); - } - - private void computeListForListeners() { - // Some clients just add a listener and expect to get notified even if - // they never called getValue(), so we have to call getValue() ourselves - // here to be sure. Need to be careful about realms though, this method - // can be called outside of our realm. - // See also bug 198211. If a client calls this outside of our realm, - // they may receive change notifications before the runnable below has - // been executed. It is their job to figure out what to do with those - // notifications. - getRealm().exec(new Runnable() { - public void run() { - if (dependencies == null) { - // We are not currently listening. - // But someone is listening for changes. Call getValue() - // to make sure we start listening to the observables we - // depend on. - getList(); - } - } - }); - } - - public synchronized void dispose() { - stopListening(); - super.dispose(); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/IListChangeListener.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/IListChangeListener.java deleted file mode 100644 index 83727299..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/IListChangeListener.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.list; - -import org.eclipse.core.databinding.observable.IObservablesListener; - -/** - * Listener for changes to observable lists. - * - * @since 1.0 - */ -public interface IListChangeListener extends IObservablesListener { - - /** - * Handle a change to an observable list. The change is described by the - * diff object. The given event object must only be used locally in this - * method because it may be reused for other change notifications. The diff - * object referenced by the event is immutable and may be used non-locally. - * - * @param event - */ - void handleListChange(ListChangeEvent event); - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/IObservableList.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/IObservableList.java deleted file mode 100644 index 097d3678..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/IObservableList.java +++ /dev/null @@ -1,198 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 167204 - * Matthew Hall - bug 208858 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.list; - -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.eclipse.core.databinding.observable.IObservableCollection; - -/** - * A list whose changes can be tracked by list change listeners. - * - * @noextend This interface is not intended to be extended by clients. - * @noimplement This interface is not intended to be implemented by clients. - * Clients should instead subclass one of the framework classes - * that implement this interface. Note that direct implementers of - * this interface outside of the framework will be broken in future - * releases when methods are added to this interface. - * - * @see AbstractObservableList - * @see ObservableList - * - * @since 1.0 - */ -public interface IObservableList extends List, IObservableCollection { - - /** - * Adds the given list change listener to the list of list change listeners. - * @param listener - */ - public void addListChangeListener(IListChangeListener listener); - - /** - * Removes the given list change listener from the list of list change listeners. - * Has no effect if the given listener is not registered as a list change listener. - * - * @param listener - */ - public void removeListChangeListener(IListChangeListener listener); - - /** - * @TrackedGetter - */ - public int size(); - - /** - * @TrackedGetter - */ - public boolean isEmpty(); - - /** - * @TrackedGetter - */ - public boolean contains(Object o); - - /** - * @TrackedGetter - */ - public Iterator iterator(); - - /** - * @TrackedGetter - */ - public Object[] toArray(); - - /** - * @TrackedGetter - */ - public Object[] toArray(Object a[]); - - /** - * - */ - public boolean add(Object o); - - /** - * - */ - public boolean remove(Object o); - - /** - * @TrackedGetter - */ - public boolean containsAll(Collection c); - - /** - * - */ - public boolean addAll(Collection c); - - /** - * - */ - public boolean addAll(int index, Collection c); - - /** - * - */ - public boolean removeAll(Collection c); - - /** - * - */ - public boolean retainAll(Collection c); - - /** - * @TrackedGetter - */ - public boolean equals(Object o); - - /** - * @TrackedGetter - */ - public int hashCode(); - - /** - * @TrackedGetter - */ - public Object get(int index); - - /** - * - */ - public Object set(int index, Object element); - - /** - * Moves the element located at <code>oldIndex</code> to - * <code>newIndex</code>. This method is equivalent to calling - * <code>add(newIndex, remove(oldIndex))</code>. - * <p> - * Implementors should deliver list change notification for the remove and - * add operations in the same ListChangeEvent, as this allows - * {@link ListDiff#accept(ListDiffVisitor)} to recognize the operation as a - * move. - * - * @param oldIndex - * the element's position before the move. Must be within the - * range <code>0 <= oldIndex < size()</code>. - * @param newIndex - * the element's position after the move. Must be within the - * range <code>0 <= newIndex < size()</code>. - * @return the element that was moved. - * @throws IndexOutOfBoundsException - * if either argument is out of range (<code>0 <= index < size()</code>). - * @see ListDiffVisitor#handleMove(int, int, Object) - * @see ListDiff#accept(ListDiffVisitor) - * @since 1.1 - */ - public Object move(int oldIndex, int newIndex); - - /** - * - */ - public Object remove(int index); - - /** - * @TrackedGetter - */ - public int indexOf(Object o); - - /** - * @TrackedGetter - */ - public int lastIndexOf(Object o); - - /** - * @TrackedGetter - */ - public ListIterator listIterator(); - - /** - * @TrackedGetter - */ - public ListIterator listIterator(int index); - - /** - * @TrackedGetter - */ - public List subList(int fromIndex, int toIndex); - - /** - * @return the type of the elements or <code>null</code> if untyped - */ - Object getElementType(); -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/ListChangeEvent.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/ListChangeEvent.java deleted file mode 100644 index 1b2ce4d7..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/ListChangeEvent.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.list; - -import org.eclipse.core.databinding.observable.IObservablesListener; -import org.eclipse.core.databinding.observable.ObservableEvent; - -/** - * List change event describing an incremental change of an - * {@link IObservableList} object. - * - * @since 1.0 - */ -public class ListChangeEvent extends ObservableEvent { - - /** - * - */ - private static final long serialVersionUID = -9154315534258776672L; - - static final Object TYPE = new Object(); - - /** - * Description of the change to the source observable list. Listeners must - * not change this field. - */ - public ListDiff diff; - - /** - * Creates a new list change event. - * - * @param source - * the source observable list - * @param diff - * the list change - */ - public ListChangeEvent(IObservableList source, ListDiff diff) { - super(source); - this.diff = diff; - } - - /** - * Returns the observable list from which this event originated. - * - * @return the observable list from which this event originated - */ - public IObservableList getObservableList() { - return (IObservableList) getSource(); - } - - protected void dispatch(IObservablesListener listener) { - ((IListChangeListener) listener).handleListChange(this); - } - - protected Object getListenerType() { - return TYPE; - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/ListDiff.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/ListDiff.java deleted file mode 100644 index df98632d..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/ListDiff.java +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 208858 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.list; - -import org.eclipse.core.internal.databinding.Util; - -/** - * Object describing a diff between two lists. - * - * @since 1.0 - */ -public abstract class ListDiff { - - /** - * Returns a ListDiffEntry array representing the differences in the list, - * in the order they are to be processed. - * - * @return a ListDiffEntry array representing the differences in the list, - * in the order they are to be processed. - */ - public abstract ListDiffEntry[] getDifferences(); - - /** - * Traverses the {@link #getDifferences()} array, calling the appropriate - * method in <code>visitor</code> for each difference. - * <ol> - * <li>{@link ListDiffVisitor#handleReplace(int, Object, Object)} is called - * whenever a remove entry is immediately followed by an add entry which - * shares the same list index. - * <li>{@link ListDiffVisitor#handleMove(int, int, Object)} is called - * whenever a remove entry is immediately followed by an add entry with an - * equivalent element. - * <li>{@link ListDiffVisitor#handleRemove(int, Object)} is called whenever - * a remove entry does not match conditions 1 or 2. - * <li>{@link ListDiffVisitor#handleAdd(int, Object)} is called whenever an - * add entry does not match conditions in 1 or 2. - * </ol> - * - * @param visitor - * the visitor to receive callbacks. - * @see ListDiffVisitor - * @since 1.1 - */ - public void accept(ListDiffVisitor visitor) { - ListDiffEntry[] differences = getDifferences(); - for (int i = 0; i < differences.length; i++) { - ListDiffEntry entry = differences[i]; - int position = entry.getPosition(); - Object element = entry.getElement(); - boolean addition = entry.isAddition(); - - if (!addition && i + 1 < differences.length) { - ListDiffEntry entry2 = differences[i + 1]; - if (entry2.isAddition()) { - int position2 = entry2.getPosition(); - Object element2 = entry2.getElement(); - if (position == position2) { - visitor.handleReplace(position, element, element2); - i++; - continue; - } - if (Util.equals(element, element2)) { - visitor.handleMove(position, position2, element); - i++; - continue; - } - } - } - if (addition) - visitor.handleAdd(position, element); - else - visitor.handleRemove(position, element); - } - } - - /** - * @see java.lang.Object#toString() - */ - public String toString() { - ListDiffEntry[] differences = getDifferences(); - StringBuffer buffer = new StringBuffer(); - buffer.append(getClass().getName()); - - if (differences == null || differences.length == 0) { - buffer - .append("{}"); //$NON-NLS-1$ - } else { - buffer - .append("{"); //$NON-NLS-1$ - - for (int i = 0; i < differences.length; i++) { - if (i > 0) - buffer.append(", "); //$NON-NLS-1$ - - buffer - .append("difference[") //$NON-NLS-1$ - .append(i) - .append("] [") //$NON-NLS-1$ - .append(differences[i] != null ? differences[i].toString() : "null") //$NON-NLS-1$ - .append("]"); //$NON-NLS-1$ - } - buffer.append("}"); //$NON-NLS-1$ - } - - return buffer.toString(); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/ListDiffEntry.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/ListDiffEntry.java deleted file mode 100644 index da2e79ff..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/ListDiffEntry.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.databinding.observable.list; - -/** - * A single addition of an element to a list or removal of an element from a list. - * - * @since 1.0 - */ -public abstract class ListDiffEntry { - - /** - * @return the 0-based position of the addition or removal - */ - public abstract int getPosition(); - - /** - * @return true if this represents an addition, false if this represents a removal - */ - public abstract boolean isAddition(); - - /** - * @return the element that was added or removed - */ - public abstract Object getElement(); - - /** - * @see java.lang.Object#toString() - */ - public String toString() { - StringBuffer buffer = new StringBuffer(); - buffer - .append(this.getClass().getName()) - .append("{position [") //$NON-NLS-1$ - .append(getPosition()) - .append("], isAddition [") //$NON-NLS-1$ - .append(isAddition()) - .append("], element [") //$NON-NLS-1$ - .append(getElement() != null ? getElement().toString() : "null") //$NON-NLS-1$ - .append("]}"); //$NON-NLS-1$ - - return buffer.toString(); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/ListDiffVisitor.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/ListDiffVisitor.java deleted file mode 100644 index e2d13891..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/ListDiffVisitor.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 208858) - ******************************************************************************/ - -package org.eclipse.core.databinding.observable.list; - -import java.util.List; - -/** - * A visitor for processing differences in a ListDiff. - * - * @see ListDiff#accept(ListDiffVisitor) - * @since 1.1 - */ -public abstract class ListDiffVisitor { - /** - * Notifies the visitor that <code>element</code> was added to the list at - * position <code>index</code>. - * - * @param index - * the index where the element was added - * @param element - * the element that was added - */ - public abstract void handleAdd(int index, Object element); - - /** - * Notifies the visitor that <code>element</code> was removed from the - * list at position <code>index</code>. - * - * @param index - * the index where the element was removed - * @param element - * the element that was removed - */ - public abstract void handleRemove(int index, Object element); - - /** - * Notifies the visitor that <code>element</code> was moved in the list - * from position <code>oldIndex</code> to position <code>newIndex</code>. - * <p> - * The default implementation of this method calls - * {@link #handleRemove(int, Object)} with the old position, then - * {@link #handleAdd(int, Object)} with the new position. Clients which are - * interested in recognizing "moves" in a list (i.e. calls to - * {@link IObservableList#move(int, int)}) should override this method. - * - * @param oldIndex - * the index that the element was moved from. - * @param newIndex - * the index that the element was moved to. - * @param element - * the element that was moved - * @see IObservableList#move(int, int) - */ - public void handleMove(int oldIndex, int newIndex, Object element) { - handleRemove(oldIndex, element); - handleAdd(newIndex, element); - } - - /** - * Notifies the visitor that <code>oldElement</code>, located at position - * <code>index</code> in the list, was replaced by <code>newElement</code>. - * <p> - * The default implementation of this method calls - * {@link #handleRemove(int, Object)} with the old element, then - * {@link #handleAdd(int, Object)} with the new element. Clients which are - * interested in recognizing "replaces" in a list (i.e. calls to - * {@link List#set(int, Object)}) should override this method. - * - * @param index - * the index where the element was replaced. - * @param oldElement - * the element being replaced. - * @param newElement - * the element that replaced oldElement. - * @see List#set(int, Object) - */ - public void handleReplace(int index, Object oldElement, Object newElement) { - handleRemove(index, oldElement); - handleAdd(index, newElement); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/ObservableList.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/ObservableList.java deleted file mode 100644 index 7a7eeef3..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/ObservableList.java +++ /dev/null @@ -1,379 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bugs 164653, 167204 - * Matthew Hall - bugs 208858, 208332, 245183 - * Tom Schindl - bug 245183 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.list; - -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.eclipse.core.databinding.observable.AbstractObservable; -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.Realm; - -/** - * - * Abstract implementation of {@link IObservableList}, based on an underlying regular list. - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * @since 1.0 - * - */ -public abstract class ObservableList extends AbstractObservable implements - IObservableList { - - protected List wrappedList; - - /** - * Stale state of the list. Access must occur in the current realm. - */ - private boolean stale = false; - - private Object elementType; - - protected ObservableList(List wrappedList, Object elementType) { - this(Realm.getDefault(), wrappedList, elementType); - } - - protected ObservableList(Realm realm, List wrappedList, Object elementType) { - super(realm); - this.wrappedList = wrappedList; - this.elementType = elementType; - } - - public synchronized void addListChangeListener(IListChangeListener listener) { - addListener(ListChangeEvent.TYPE, listener); - } - - public synchronized void removeListChangeListener(IListChangeListener listener) { - removeListener(ListChangeEvent.TYPE, listener); - } - - protected void fireListChange(ListDiff diff) { - // fire general change event first - super.fireChange(); - fireEvent(new ListChangeEvent(this, diff)); - } - - public boolean contains(Object o) { - getterCalled(); - return wrappedList.contains(o); - } - - public boolean containsAll(Collection c) { - getterCalled(); - return wrappedList.containsAll(c); - } - - public boolean equals(Object o) { - getterCalled(); - - if (o == this) - return true; - if (o == null) - return false; - if (getClass() == o.getClass()) { - return wrappedList.equals(((ObservableList) o).wrappedList); - } - - return wrappedList.equals(o); - } - - public int hashCode() { - getterCalled(); - return wrappedList.hashCode(); - } - - public boolean isEmpty() { - getterCalled(); - return wrappedList.isEmpty(); - } - - public Iterator iterator() { - getterCalled(); - final Iterator wrappedIterator = wrappedList.iterator(); - return new Iterator() { - - public void remove() { - throw new UnsupportedOperationException(); - } - - public boolean hasNext() { - return wrappedIterator.hasNext(); - } - - public Object next() { - return wrappedIterator.next(); - } - }; - } - - public int size() { - getterCalled(); - return wrappedList.size(); - } - - public Object[] toArray() { - getterCalled(); - return wrappedList.toArray(); - } - - public Object[] toArray(Object[] a) { - getterCalled(); - return wrappedList.toArray(a); - } - - public String toString() { - getterCalled(); - return wrappedList.toString(); - } - - /** - * @TrackedGetter - */ - public Object get(int index) { - getterCalled(); - return wrappedList.get(index); - } - - /** - * @TrackedGetter - */ - public int indexOf(Object o) { - getterCalled(); - return wrappedList.indexOf(o); - } - - /** - * @TrackedGetter - */ - public int lastIndexOf(Object o) { - getterCalled(); - return wrappedList.lastIndexOf(o); - } - - // List Iterators - - /** - * @TrackedGetter - */ - public ListIterator listIterator() { - return listIterator(0); - } - - /** - * @TrackedGetter - */ - public ListIterator listIterator(int index) { - getterCalled(); - final ListIterator wrappedIterator = wrappedList.listIterator(index); - return new ListIterator() { - - public int nextIndex() { - return wrappedIterator.nextIndex(); - } - - public int previousIndex() { - return wrappedIterator.previousIndex(); - } - - public void remove() { - throw new UnsupportedOperationException(); - } - - public boolean hasNext() { - return wrappedIterator.hasNext(); - } - - public boolean hasPrevious() { - return wrappedIterator.hasPrevious(); - } - - public Object next() { - return wrappedIterator.next(); - } - - public Object previous() { - return wrappedIterator.previous(); - } - - public void add(Object o) { - throw new UnsupportedOperationException(); - } - - public void set(Object o) { - throw new UnsupportedOperationException(); - } - }; - } - - - public List subList(final int fromIndex, final int toIndex) { - getterCalled(); - if (fromIndex < 0 || fromIndex > toIndex || toIndex > size()) { - throw new IndexOutOfBoundsException(); - } - return new AbstractObservableList(getRealm()) { - - public Object getElementType() { - return ObservableList.this.getElementType(); - } - - public Object get(int location) { - return ObservableList.this.get(fromIndex + location); - } - - protected int doGetSize() { - return toIndex - fromIndex; - } - }; - } - - protected void getterCalled() { - ObservableTracker.getterCalled(this); - } - - public Object set(int index, Object element) { - throw new UnsupportedOperationException(); - } - - /** - * Moves the element located at <code>oldIndex</code> to - * <code>newIndex</code>. This method is equivalent to calling - * <code>add(newIndex, remove(oldIndex))</code>. - * <p> - * Subclasses should override this method to deliver list change - * notification for the remove and add operations in the same - * ListChangeEvent, as this allows {@link ListDiff#accept(ListDiffVisitor)} - * to recognize the operation as a move. - * - * @param oldIndex - * the element's position before the move. Must be within the - * range <code>0 <= oldIndex < size()</code>. - * @param newIndex - * the element's position after the move. Must be within the - * range <code>0 <= newIndex < size()</code>. - * @return the element that was moved. - * @throws IndexOutOfBoundsException - * if either argument is out of range (<code>0 <= index < size()</code>). - * @see ListDiffVisitor#handleMove(int, int, Object) - * @see ListDiff#accept(ListDiffVisitor) - * @since 1.1 - */ - public Object move(int oldIndex, int newIndex) { - checkRealm(); - int size = wrappedList.size(); - if (oldIndex < 0 || oldIndex >= size) - throw new IndexOutOfBoundsException( - "oldIndex: " + oldIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$ - if (newIndex < 0 || newIndex >= size) - throw new IndexOutOfBoundsException( - "newIndex: " + newIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$ - Object element = remove(oldIndex); - add(newIndex, element); - return element; - } - - public Object remove(int index) { - throw new UnsupportedOperationException(); - } - - public boolean add(Object o) { - throw new UnsupportedOperationException(); - } - - public void add(int index, Object element) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(int index, Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - throw new UnsupportedOperationException(); - } - - /** - * Returns the stale state. Must be invoked from the current realm. - * - * @return stale state - */ - public boolean isStale() { - getterCalled(); - return stale; - } - - /** - * Sets the stale state. Must be invoked from the current realm. - * - * @param stale - * The stale state to list. This will fire a stale event if the - * given boolean is true and this observable list was not already - * stale. - */ - public void setStale(boolean stale) { - checkRealm(); - - boolean wasStale = this.stale; - this.stale = stale; - if (!wasStale && stale) { - fireStale(); - } - } - - protected void fireChange() { - throw new RuntimeException("fireChange should not be called, use fireListChange() instead"); //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.jface.provisional.databinding.observable.AbstractObservable#dispose() - */ - public synchronized void dispose() { - super.dispose(); - } - - public Object getElementType() { - return elementType; - } - - protected void updateWrappedList(List newList) { - List oldList = wrappedList; - ListDiff listDiff = Diffs.computeListDiff(oldList, newList); - wrappedList = newList; - fireListChange(listDiff); - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/WritableList.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/WritableList.java deleted file mode 100644 index ca0c7503..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/WritableList.java +++ /dev/null @@ -1,239 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - * Brad Reynolds - bug 167204 - * Gautam Saggar - bug 169529 - * Brad Reynolds - bug 147515 - * Matthew Hall - bug 208858, 213145 - *******************************************************************************/ -package org.eclipse.core.databinding.observable.list; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; - -/** - * Mutable observable list backed by an ArrayList. - * - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * - * @since 1.0 - */ -public class WritableList extends ObservableList { - - /** - * Creates an empty writable list in the default realm with a - * <code>null</code> element type. - * - */ - public WritableList() { - this(Realm.getDefault()); - } - - /** - * Creates an empty writable list with a <code>null</code> element type. - * - * @param realm - */ - public WritableList(Realm realm) { - this(realm, new ArrayList(), null); - } - - /** - * Constructs a new instance with the default realm. - * - * @param toWrap - * @param elementType - * can be <code>null</code> - */ - public WritableList(List toWrap, Object elementType) { - this(Realm.getDefault(), toWrap, elementType); - } - - /** - * Creates a writable list containing elements of the given type, wrapping - * an existing client-supplied list. - * - * @param realm - * @param toWrap - * The java.utilList to wrap - * @param elementType - * can be <code>null</code> - */ - public WritableList(Realm realm, List toWrap, Object elementType) { - super(realm, toWrap, elementType); - } - - public Object set(int index, Object element) { - checkRealm(); - Object oldElement = wrappedList.set(index, element); - fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry(index, - false, oldElement), Diffs.createListDiffEntry(index, true, - element))); - return oldElement; - } - - /** - * @since 1.1 - */ - public Object move(int oldIndex, int newIndex) { - checkRealm(); - int size = wrappedList.size(); - if (oldIndex < 0 || oldIndex >= size) - throw new IndexOutOfBoundsException( - "oldIndex: " + oldIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$ - if (newIndex < 0 || newIndex >= size) - throw new IndexOutOfBoundsException( - "newIndex: " + newIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$ - if (oldIndex == newIndex) - return wrappedList.get(oldIndex); - Object element = wrappedList.remove(oldIndex); - wrappedList.add(newIndex, element); - fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry(oldIndex, - false, element), Diffs.createListDiffEntry(newIndex, true, - element))); - return element; - } - - public Object remove(int index) { - checkRealm(); - Object oldElement = wrappedList.remove(index); - fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry(index, - false, oldElement))); - return oldElement; - } - - public boolean add(Object element) { - checkRealm(); - boolean added = wrappedList.add(element); - if (added) { - fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry( - wrappedList.size() - 1, true, element))); - } - return added; - } - - public void add(int index, Object element) { - checkRealm(); - wrappedList.add(index, element); - fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry(index, - true, element))); - } - - public boolean addAll(Collection c) { - checkRealm(); - ListDiffEntry[] entries = new ListDiffEntry[c.size()]; - int i = 0; - int addIndex = wrappedList.size(); - for (Iterator it = c.iterator(); it.hasNext();) { - Object element = it.next(); - entries[i++] = Diffs.createListDiffEntry(addIndex++, true, element); - } - boolean added = wrappedList.addAll(c); - fireListChange(Diffs.createListDiff(entries)); - return added; - } - - public boolean addAll(int index, Collection c) { - checkRealm(); - ListDiffEntry[] entries = new ListDiffEntry[c.size()]; - int i = 0; - int addIndex = index; - for (Iterator it = c.iterator(); it.hasNext();) { - Object element = it.next(); - entries[i++] = Diffs.createListDiffEntry(addIndex++, true, element); - } - boolean added = wrappedList.addAll(index, c); - fireListChange(Diffs.createListDiff(entries)); - return added; - } - - public boolean remove(Object o) { - checkRealm(); - int index = wrappedList.indexOf(o); - if (index == -1) { - return false; - } - wrappedList.remove(index); - fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry(index, - false, o))); - return true; - } - - public boolean removeAll(Collection c) { - checkRealm(); - List entries = new ArrayList(); - for (Iterator it = c.iterator(); it.hasNext();) { - Object element = it.next(); - int removeIndex = wrappedList.indexOf(element); - if (removeIndex != -1) { - wrappedList.remove(removeIndex); - entries.add(Diffs.createListDiffEntry(removeIndex, false, - element)); - } - } - if (entries.size() > 0) - fireListChange(Diffs.createListDiff((ListDiffEntry[]) entries - .toArray(new ListDiffEntry[entries.size()]))); - return entries.size() > 0; - } - - public boolean retainAll(Collection c) { - checkRealm(); - List entries = new ArrayList(); - int removeIndex = 0; - for (Iterator it = wrappedList.iterator(); it.hasNext();) { - Object element = it.next(); - if (!c.contains(element)) { - entries.add(Diffs.createListDiffEntry(removeIndex, false, - element)); - it.remove(); - } else { - // only increment if we haven't removed the current element - removeIndex++; - } - } - if (entries.size() > 0) - fireListChange(Diffs.createListDiff((ListDiffEntry[]) entries - .toArray(new ListDiffEntry[entries.size()]))); - return entries.size() > 0; - } - - public void clear() { - checkRealm(); - List entries = new ArrayList(); - for (Iterator it = wrappedList.iterator(); it.hasNext();) { - Object element = it.next(); - // always report 0 as the remove index - entries.add(Diffs.createListDiffEntry(0, false, element)); - it.remove(); - } - fireListChange(Diffs.createListDiff((ListDiffEntry[]) entries - .toArray(new ListDiffEntry[entries.size()]))); - } - - /** - * @param elementType - * can be <code>null</code> - * @return new list with the default realm. - */ - public static WritableList withElementType(Object elementType) { - return new WritableList(Realm.getDefault(), new ArrayList(), - elementType); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/package.html b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/package.html deleted file mode 100644 index 2c2f1db6..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/package.html +++ /dev/null @@ -1,16 +0,0 @@ -<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> - <meta name="Author" content="IBM"> - <meta name="GENERATOR" content="Mozilla/4.5 [en] (Win98; I) [Netscape]"> - <title>Package-level Javadoc</title> -</head> -<body> -Provides classes for observing changes in lists. -<h2> -Package Specification</h2> -<p> -This package provides classes for observing changes in lists.</p> -</body> -</html> diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/AbstractObservableMap.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/AbstractObservableMap.java deleted file mode 100644 index e35f655f..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/AbstractObservableMap.java +++ /dev/null @@ -1,181 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - * Matthew Hall - bugs 118516, 240931 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.map; - -import java.util.AbstractMap; - -import org.eclipse.core.databinding.observable.ChangeEvent; -import org.eclipse.core.databinding.observable.ChangeSupport; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.AssertionFailedException; - -/** - * - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * @since 1.0 - */ -public abstract class AbstractObservableMap extends AbstractMap implements - IObservableMap { - - private ChangeSupport changeSupport; - - private boolean stale; - - /** - */ - public AbstractObservableMap() { - this(Realm.getDefault()); - } - - /** - * - */ - protected void lastListenerRemoved() { - } - - /** - * - */ - protected void firstListenerAdded() { - } - - /** - * @param realm - */ - public AbstractObservableMap(Realm realm) { - Assert.isNotNull(realm, "Realm cannot be null"); //$NON-NLS-1$ - changeSupport = new ChangeSupport(realm){ - protected void firstListenerAdded() { - AbstractObservableMap.this.firstListenerAdded(); - } - protected void lastListenerRemoved() { - AbstractObservableMap.this.lastListenerRemoved(); - } - }; - } - - public synchronized void addMapChangeListener(IMapChangeListener listener) { - if (changeSupport != null) { - changeSupport.addListener(MapChangeEvent.TYPE, listener); - } - } - - public synchronized void removeMapChangeListener(IMapChangeListener listener) { - if (changeSupport != null) { - changeSupport.removeListener(MapChangeEvent.TYPE, listener); - } - } - - public synchronized void addChangeListener(IChangeListener listener) { - if (changeSupport != null) { - changeSupport.addChangeListener(listener); - } - } - - public synchronized void addStaleListener(IStaleListener listener) { - if (changeSupport != null) { - changeSupport.addStaleListener(listener); - } - } - - public synchronized void dispose() { - if (changeSupport != null) { - changeSupport.dispose(); - changeSupport = null; - } - } - - public Realm getRealm() { - if (changeSupport != null) { - return changeSupport.getRealm(); - } - return null; - } - - public boolean isStale() { - checkRealm(); - return stale; - } - - public synchronized void removeChangeListener(IChangeListener listener) { - if (changeSupport != null) { - changeSupport.removeChangeListener(listener); - } - } - - public synchronized void removeStaleListener(IStaleListener listener) { - if (changeSupport != null) { - changeSupport.removeStaleListener(listener); - } - } - - /** - * Sets the stale state. Must be invoked from the current realm. - * - * @param stale - */ - public void setStale(boolean stale) { - checkRealm(); - this.stale = stale; - if (stale) { - fireStale(); - } - } - - /** - * Fires stale events. Must be invoked from current realm. - */ - protected void fireStale() { - checkRealm(); - changeSupport.fireEvent(new StaleEvent(this)); - } - - /** - * Fires change events. Must be invoked from current realm. - */ - protected void fireChange() { - checkRealm(); - changeSupport.fireEvent(new ChangeEvent(this)); - } - - /** - * Fires map change events. Must be invoked from current realm. - * - * @param diff - */ - protected void fireMapChange(MapDiff diff) { - checkRealm(); - changeSupport.fireEvent(new MapChangeEvent(this, diff)); - } - - /** - * Asserts that the realm is the current realm. - * - * @see Realm#isCurrent() - * @throws AssertionFailedException - * if the realm is not the current realm - */ - protected void checkRealm() { - Assert.isTrue(getRealm().isCurrent(), - "This operation must be run within the observable's realm"); //$NON-NLS-1$ - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/BidirectionalMap.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/BidirectionalMap.java deleted file mode 100644 index c83f6eef..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/BidirectionalMap.java +++ /dev/null @@ -1,104 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.core.databinding.observable.map; - -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.databinding.observable.Realm; - -/** - * - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * @since 1.0 - * - */ -public class BidirectionalMap extends ObservableMap { - - private Map valueToElements = new HashMap(); - - private IMapChangeListener mapListener = new IMapChangeListener() { - - public void handleMapChange(MapChangeEvent event) { - MapDiff diff = event.diff; - for (Iterator it = diff.getAddedKeys().iterator(); it.hasNext();) { - Object addedKey = it.next(); - addMapping(addedKey, diff.getNewValue(addedKey)); - } - for (Iterator it = diff.getChangedKeys().iterator(); it.hasNext();) { - Object changedKey = it.next(); - removeMapping(changedKey, diff.getOldValue(changedKey)); - addMapping(changedKey, diff.getNewValue(changedKey)); - } - for (Iterator it = diff.getRemovedKeys().iterator(); it.hasNext();) { - Object removedKey = it.next(); - removeMapping(removedKey, diff.getOldValue(removedKey)); - } - fireMapChange(diff); - } - }; - - /** - * @param wrappedMap - */ - public BidirectionalMap(IObservableMap wrappedMap) { - super(wrappedMap.getRealm(), wrappedMap); - wrappedMap.addMapChangeListener(mapListener); - for (Iterator it = wrappedMap.entrySet().iterator(); it.hasNext();) { - Map.Entry entry = (Entry) it.next(); - addMapping(entry.getKey(), entry.getValue()); - } - } - - /** - * @param key - * @param value - */ - private void addMapping(Object key, Object value) { - Object elementOrSet = valueToElements.get(value); - if (elementOrSet == null) { - valueToElements.put(value, key); - return; - } - if (!(elementOrSet instanceof Set)) { - elementOrSet = new HashSet(Collections.singleton(elementOrSet)); - valueToElements.put(value, elementOrSet); - } - Set set = (Set) elementOrSet; - set.add(key); - } - - /** - * @param functionValue - * @param element - */ - private void removeMapping(Object functionValue, Object element) { - Object elementOrSet = valueToElements.get(functionValue); - if (elementOrSet instanceof Set) { - Set set = (Set) elementOrSet; - set.remove(element); - if (set.size() == 0) { - valueToElements.remove(functionValue); - } - } else { - valueToElements.remove(functionValue); - } - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/CompositeMap.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/CompositeMap.java deleted file mode 100644 index 8f3bbb61..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/CompositeMap.java +++ /dev/null @@ -1,361 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.core.databinding.observable.map; - -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.set.WritableSet; -import org.eclipse.core.runtime.Assert; - -/** - * A read-only observable map formed by the composition of two observable maps. - * If map1 maps keys a:A to values b1:B, and map2 maps keys b2:B to values c:C, - * the composite map maps keys a:A to values c:C. For example, map1 could map - * Order objects to their corresponding Customer objects, and map2 could map - * Customer objects to their "last name" property of type String. The composite - * map of map1 and map2 would then map Order objects to their customers' last - * names. - * - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * - * @since 1.1 - * - */ -public class CompositeMap extends ObservableMap { - - private Map valueToElements = new HashMap(); - - // adds that need to go through the second map and thus will be picked up by - // secondMapListener. - private Set pendingAdds = new HashSet(); - - // Removes that need to go through the second map and thus will be picked up - // by - // secondMapListener. Maps from value being removed to key being removed. - private Map pendingRemoves = new HashMap(); - - // Changes that need to go through the second map and thus will be picked up - // by - // secondMapListener. Maps from old value to new value and new value to old - // value. - private Map pendingChanges = new HashMap(); - - private IMapChangeListener firstMapListener = new IMapChangeListener() { - - public void handleMapChange(MapChangeEvent event) { - MapDiff diff = event.diff; - Set rangeSetAdditions = new HashSet(); - Set rangeSetRemovals = new HashSet(); - final Set adds = new HashSet(); - final Set changes = new HashSet(); - final Set removes = new HashSet(); - final Map oldValues = new HashMap(); - - for (Iterator it = diff.getAddedKeys().iterator(); it.hasNext();) { - Object addedKey = it.next(); - Object newValue = diff.getNewValue(addedKey); - addMapping(addedKey, newValue); - if (!rangeSet.contains(newValue)) { - pendingAdds.add(newValue); - rangeSetAdditions.add(newValue); - } else { - adds.add(addedKey); - wrappedMap.put(addedKey, secondMap.get(newValue)); - } - } - for (Iterator it = diff.getChangedKeys().iterator(); it.hasNext();) { - Object changedKey = it.next(); - Object oldValue = diff.getOldValue(changedKey); - Object newValue = diff.getNewValue(changedKey); - boolean removed = removeMapping(changedKey, oldValue); - addMapping(changedKey, newValue); - boolean added = !rangeSet.contains(newValue); - if (removed) { - pendingRemoves.put(oldValue, changedKey); - rangeSetRemovals.add(oldValue); - } - if (added) { - pendingAdds.add(newValue); - rangeSetAdditions.add(newValue); - } - if (added || removed) { - pendingChanges.put(oldValue, newValue); - pendingChanges.put(newValue, oldValue); - } else { - changes.add(changedKey); - oldValues.put(changedKey, oldValue); - wrappedMap.put(changedKey, secondMap.get(newValue)); - } - } - for (Iterator it = diff.getRemovedKeys().iterator(); it.hasNext();) { - Object removedKey = it.next(); - Object oldValue = diff.getOldValue(removedKey); - if (removeMapping(removedKey, oldValue)) { - pendingRemoves.put(oldValue, removedKey); - rangeSetRemovals.add(oldValue); - } else { - removes.add(removedKey); - oldValues.put(removedKey, secondMap.get(oldValue)); - wrappedMap.remove(removedKey); - } - } - - if (adds.size() > 0 || removes.size() > 0 || changes.size() > 0) { - fireMapChange(new MapDiff() { - - public Set getAddedKeys() { - return adds; - } - - public Set getChangedKeys() { - return changes; - } - - public Object getNewValue(Object key) { - return wrappedMap.get(key); - } - - public Object getOldValue(Object key) { - return oldValues.get(key); - } - - public Set getRemovedKeys() { - return removes; - } - }); - } - - if (rangeSetAdditions.size() > 0 || rangeSetRemovals.size() > 0) { - rangeSet.addAndRemove(rangeSetAdditions, rangeSetRemovals); - } - } - }; - - private IMapChangeListener secondMapListener = new IMapChangeListener() { - - public void handleMapChange(MapChangeEvent event) { - MapDiff diff = event.diff; - final Set adds = new HashSet(); - final Set changes = new HashSet(); - final Set removes = new HashSet(); - final Map oldValues = new HashMap(); - final Map newValues = new HashMap(); - Set addedKeys = new HashSet(diff.getAddedKeys()); - Set removedKeys = new HashSet(diff.getRemovedKeys()); - - for (Iterator it = addedKeys.iterator(); it.hasNext();) { - Object addedKey = it.next(); - Set elements = getElementsForValue(addedKey); - Object newValue = diff.getNewValue(addedKey); - if (pendingChanges.containsKey(addedKey)) { - Object oldKey = pendingChanges.remove(addedKey); - Object oldValue; - if (removedKeys.remove(oldKey)) { - oldValue = diff.getOldValue(oldKey); - } else { - oldValue = secondMap.get(oldKey); - } - pendingChanges.remove(oldKey); - pendingAdds.remove(addedKey); - pendingRemoves.remove(oldKey); - for (Iterator it2 = elements.iterator(); it2.hasNext();) { - Object element = it2.next(); - changes.add(element); - oldValues.put(element, oldValue); - newValues.put(element, newValue); - wrappedMap.put(element, newValue); - } - } else if (pendingAdds.remove(addedKey)) { - for (Iterator it2 = elements.iterator(); it2.hasNext();) { - Object element = it2.next(); - adds.add(element); - newValues.put(element, newValue); - wrappedMap.put(element, newValue); - } - } else { - Assert.isTrue(false, "unexpected case"); //$NON-NLS-1$ - } - } - for (Iterator it = diff.getChangedKeys().iterator(); it.hasNext();) { - Object changedKey = it.next(); - Set elements = getElementsForValue(changedKey); - for (Iterator it2 = elements.iterator(); it2.hasNext();) { - Object element = it2.next(); - changes.add(element); - oldValues.put(element, diff.getOldValue(changedKey)); - Object newValue = diff.getNewValue(changedKey); - newValues.put(element, newValue); - wrappedMap.put(element, newValue); - } - } - for (Iterator it = removedKeys.iterator(); it.hasNext();) { - Object removedKey = it.next(); - Object element = pendingRemoves.remove(removedKey); - if (element != null) { - if (pendingChanges.containsKey(removedKey)) { - Object newKey = pendingChanges.remove(removedKey); - pendingChanges.remove(newKey); - pendingAdds.remove(newKey); - pendingRemoves.remove(removedKey); - changes.add(element); - oldValues.put(element, diff.getOldValue(removedKey)); - Object newValue = secondMap.get(newKey); - newValues.put(element, newValue); - wrappedMap.put(element, newValue); - } else { - removes.add(element); - Object oldValue = diff.getOldValue(removedKey); - oldValues.put(element, oldValue); - wrappedMap.remove(element); - } - } else { - Assert.isTrue(false, "unexpected case"); //$NON-NLS-1$ - } - } - - if (adds.size() > 0 || removes.size() > 0 || changes.size() > 0) { - fireMapChange(new MapDiff() { - - public Set getAddedKeys() { - return adds; - } - - public Set getChangedKeys() { - return changes; - } - - public Object getNewValue(Object key) { - return newValues.get(key); - } - - public Object getOldValue(Object key) { - return oldValues.get(key); - } - - public Set getRemovedKeys() { - return removes; - } - }); - } - } - }; - - private IObservableMap firstMap; - private IObservableMap secondMap; - - private static class WritableSetPlus extends WritableSet { - void addAndRemove(Set additions, Set removals) { - wrappedSet.removeAll(removals); - wrappedSet.addAll(additions); - fireSetChange(Diffs.createSetDiff(additions, removals)); - } - } - - private WritableSetPlus rangeSet = new WritableSetPlus(); - - /** - * Creates a new composite map. Because the key set of the second map is - * determined by the value set of the given observable map - * <code>firstMap</code>, it cannot be passed in as an argument. Instead, - * the second map will be created by calling - * <code>secondMapFactory.createObservable(valueSet())</code>. - * - * @param firstMap - * the first map - * @param secondMapFactory - * a factory that creates the second map when given an observable - * set representing the value set of <code>firstMap</code>. - */ - public CompositeMap(IObservableMap firstMap, - IObservableFactory secondMapFactory) { - super(firstMap.getRealm(), new HashMap()); - this.firstMap = firstMap; - firstMap.addMapChangeListener(firstMapListener); - for (Iterator it = firstMap.entrySet().iterator(); it.hasNext();) { - Map.Entry entry = (Entry) it.next(); - addMapping(entry.getKey(), entry.getValue()); - rangeSet.add(entry.getValue()); - } - this.secondMap = (IObservableMap) secondMapFactory - .createObservable(rangeSet); - secondMap.addMapChangeListener(secondMapListener); - for (Iterator it = firstMap.entrySet().iterator(); it.hasNext();) { - Map.Entry entry = (Entry) it.next(); - wrappedMap.put(entry.getKey(), secondMap.get(entry.getValue())); - } - } - - /** - * @param key - * @param value - */ - private void addMapping(Object key, Object value) { - Object elementOrSet = valueToElements.get(value); - if (elementOrSet == null) { - valueToElements.put(value, key); - return; - } - if (!(elementOrSet instanceof Set)) { - elementOrSet = new HashSet(Collections.singleton(elementOrSet)); - valueToElements.put(value, elementOrSet); - } - Set set = (Set) elementOrSet; - set.add(key); - } - - /** - * @param key - * @param value - */ - private boolean removeMapping(Object key, Object value) { - Object elementOrSet = valueToElements.get(value); - if (elementOrSet instanceof Set) { - Set set = (Set) elementOrSet; - set.remove(key); - if (set.size() == 0) { - valueToElements.remove(value); - return true; - } - return false; - } - valueToElements.remove(value); - return true; - } - - private Set getElementsForValue(Object value) { - Object elementOrSet = valueToElements.get(value); - if (elementOrSet instanceof Set) { - return (Set) elementOrSet; - } - return elementOrSet == null ? Collections.EMPTY_SET : Collections - .singleton(elementOrSet); - } - - public synchronized void dispose() { - super.dispose(); - firstMap.removeMapChangeListener(firstMapListener); - firstMap = null; - secondMap = null; - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/ComputedObservableMap.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/ComputedObservableMap.java deleted file mode 100644 index f7438926..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/ComputedObservableMap.java +++ /dev/null @@ -1,161 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.map; - -import java.util.AbstractSet; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.ISetChangeListener; -import org.eclipse.core.databinding.observable.set.SetChangeEvent; - -/** - * Maps objects to one of their attributes. Tracks changes to the underlying - * observable set of objects (keys), as well as changes to attribute values. - */ -public abstract class ComputedObservableMap extends AbstractObservableMap { - - private final IObservableSet keySet; - - private ISetChangeListener setChangeListener = new ISetChangeListener() { - public void handleSetChange(SetChangeEvent event) { - Set addedKeys = new HashSet(event.diff.getAdditions()); - Set removedKeys = new HashSet(event.diff.getRemovals()); - Map oldValues = new HashMap(); - Map newValues = new HashMap(); - for (Iterator it = removedKeys.iterator(); it.hasNext();) { - Object removedKey = it.next(); - Object oldValue = doGet(removedKey); - unhookListener(removedKey); - if (oldValue != null) { - oldValues.put(removedKey, oldValue); - } - } - for (Iterator it = addedKeys.iterator(); it.hasNext();) { - Object addedKey = it.next(); - hookListener(addedKey); - Object newValue = doGet(addedKey); - newValues.put(addedKey, newValue); - } - fireMapChange(Diffs.createMapDiff(addedKeys, removedKeys, - Collections.EMPTY_SET, oldValues, newValues)); - } - }; - - private Set entrySet = new EntrySet(); - - private class EntrySet extends AbstractSet { - - public Iterator iterator() { - final Iterator keyIterator = keySet.iterator(); - return new Iterator() { - - public boolean hasNext() { - return keyIterator.hasNext(); - } - - public Object next() { - final Object key = keyIterator.next(); - return new Map.Entry() { - - public Object getKey() { - return key; - } - - public Object getValue() { - return get(getKey()); - } - - public Object setValue(Object value) { - return put(getKey(), value); - } - }; - } - - public void remove() { - keyIterator.remove(); - } - }; - } - - public int size() { - return keySet.size(); - } - - } - - /** - * @param keySet - */ - public ComputedObservableMap(IObservableSet keySet) { - super(keySet.getRealm()); - this.keySet = keySet; - this.keySet.addSetChangeListener(setChangeListener); - } - - protected void init() { - for (Iterator it = this.keySet.iterator(); it.hasNext();) { - Object key = it.next(); - hookListener(key); - } - } - - protected final void fireSingleChange(Object key, Object oldValue, - Object newValue) { - fireMapChange(Diffs.createMapDiffSingleChange(key, oldValue, newValue)); - } - - public Set entrySet() { - return entrySet; - } - - public Set keySet() { - return keySet; - } - - final public Object get(Object key) { - return doGet(key); - } - - final public Object put(Object key, Object value) { - return doPut(key, value); - } - - /** - * @param removedKey - */ - protected abstract void unhookListener(Object removedKey); - - /** - * @param addedKey - */ - protected abstract void hookListener(Object addedKey); - - /** - * @param key - * @return the value for the given key - */ - protected abstract Object doGet(Object key); - - /** - * @param key - * @param value - * @return the old value for the given key - */ - protected abstract Object doPut(Object key, Object value); -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/IMapChangeListener.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/IMapChangeListener.java deleted file mode 100644 index 3bc829e9..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/IMapChangeListener.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.map; - -import org.eclipse.core.databinding.observable.IObservablesListener; - -/** - * Listener for changes to observable maps. - * - * @since 1.0 - * - */ -public interface IMapChangeListener extends IObservablesListener { - - /** - * Handle a change an observable map. The given event object must only be - * used locally in this method because it may be reused for other change - * notifications. The diff object referenced by the event is immutable and - * may be used non-locally. - * - * @param event - * the event - */ - void handleMapChange(MapChangeEvent event); - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/IObservableMap.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/IObservableMap.java deleted file mode 100644 index 78a0db0f..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/IObservableMap.java +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.map; - -import java.util.Collection; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.databinding.observable.IObservable; - -/** - * Observable Map. - * - * @noextend This interface is not intended to be extended by clients. - * @noimplement This interface is not intended to be implemented by clients. - * Clients should instead subclass one of the classes that - * implement this interface. Note that direct implementers of this - * interface outside of the framework will be broken in future - * releases when methods are added to this interface. - * - * @see AbstractObservableMap - * @see ObservableMap - * - * @since 1.1 - */ -public interface IObservableMap extends Map, IObservable { - - /** - * @param listener - */ - public void addMapChangeListener(IMapChangeListener listener); - - /** - * @param listener - */ - public void removeMapChangeListener(IMapChangeListener listener); - - /** - * @TrackedGetter - */ - public int size(); - - /** - * @TrackedGetter - */ - public boolean isEmpty(); - - /** - * @TrackedGetter - */ - public boolean containsKey(Object key); - - /** - * @TrackedGetter - */ - public boolean containsValue(Object value); - - /** - * @TrackedGetter - */ - public Object get(Object key); - - /** - * - */ - public Object put(Object key, Object value); - - /** - * - */ - public Object remove(Object key); - - /** - * @TrackedGetter - */ - public Set keySet(); - - /** - * @TrackedGetter - */ - public Collection values(); - - /** - * @TrackedGetter - */ - public Set entrySet(); - - /** - * @TrackedGetter - */ - public boolean equals(Object o); - - /** - * @TrackedGetter - */ - public int hashCode(); -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/MapChangeEvent.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/MapChangeEvent.java deleted file mode 100644 index 90bfef93..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/MapChangeEvent.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.databinding.observable.map; - -import org.eclipse.core.databinding.observable.IObservablesListener; -import org.eclipse.core.databinding.observable.ObservableEvent; - -/** - * Map change event describing an incremental change of an - * {@link IObservableMap} object. - * - * @since 1.0 - * - */ -public class MapChangeEvent extends ObservableEvent { - - /** - * - */ - private static final long serialVersionUID = -8092347212410548463L; - static final Object TYPE = new Object(); - - /** - * Description of the change to the source observable map. Listeners must - * not change this field. - */ - public MapDiff diff; - - /** - * Creates a new map change event - * - * @param source - * the source observable map - * @param diff - * the map change - */ - public MapChangeEvent(IObservableMap source, MapDiff diff) { - super(source); - this.diff = diff; - } - - /** - * Returns the observable map from which this event originated. - * - * @return the observable map from which this event originated - */ - public IObservableMap getObservableMap() { - return (IObservableMap) getSource(); - } - - protected void dispatch(IObservablesListener listener) { - ((IMapChangeListener) listener).handleMapChange(this); - } - - protected Object getListenerType() { - return TYPE; - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/MapDiff.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/MapDiff.java deleted file mode 100644 index f54c37cd..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/MapDiff.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.map; - -import java.util.Set; - -/** - * @since 1.1 - * - */ -public abstract class MapDiff { - - /** - * @return the set of keys which were added - */ - public abstract Set getAddedKeys(); - - /** - * @return the set of keys which were removed - */ - public abstract Set getRemovedKeys(); - - /** - * @return the set of keys for which the value has changed - */ - public abstract Set getChangedKeys(); - - /** - * Returns the old value for the given key, which must be an element of - * {@link #getRemovedKeys()} or {@link #getChangedKeys()}. - * - * @param key - * @return the old value for the given key. - */ - public abstract Object getOldValue(Object key); - - /** - * Returns the new value for the given key, which must be an element of - * {@link #getChangedKeys()} or {@link #getAddedKeys()}. - * - * @param key - * @return the new value for the given key. - */ - public abstract Object getNewValue(Object key); -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/ObservableMap.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/ObservableMap.java deleted file mode 100644 index b52b3f9c..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/ObservableMap.java +++ /dev/null @@ -1,182 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - * Matthew Hall - bug 245183 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.map; - -import java.util.Collection; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.databinding.observable.AbstractObservable; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.Realm; - -/** - * - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * @since 1.0 - */ -public class ObservableMap extends AbstractObservable implements IObservableMap { - - protected Map wrappedMap; - - private boolean stale = false; - - /** - * @param wrappedMap - */ - public ObservableMap(Map wrappedMap) { - this(Realm.getDefault(), wrappedMap); - } - - /** - * @param realm - * @param wrappedMap - */ - public ObservableMap(Realm realm, Map wrappedMap) { - super(realm); - this.wrappedMap = wrappedMap; - } - - public synchronized void addMapChangeListener(IMapChangeListener listener) { - addListener(MapChangeEvent.TYPE, listener); - } - - public synchronized void removeMapChangeListener(IMapChangeListener listener) { - removeListener(MapChangeEvent.TYPE, listener); - } - - protected void getterCalled() { - ObservableTracker.getterCalled(this); - } - - protected void fireMapChange(MapDiff diff) { - checkRealm(); - - // fire general change event first - super.fireChange(); - - fireEvent(new MapChangeEvent(this, diff)); - } - - public boolean containsKey(Object key) { - getterCalled(); - return wrappedMap.containsKey(key); - } - - public boolean containsValue(Object value) { - getterCalled(); - return wrappedMap.containsValue(value); - } - - public Set entrySet() { - getterCalled(); - return wrappedMap.entrySet(); - } - - public Object get(Object key) { - getterCalled(); - return wrappedMap.get(key); - } - - public boolean isEmpty() { - getterCalled(); - return wrappedMap.isEmpty(); - } - - public Set keySet() { - getterCalled(); - return wrappedMap.keySet(); - } - - public int size() { - getterCalled(); - return wrappedMap.size(); - } - - public Collection values() { - getterCalled(); - return wrappedMap.values(); - } - - /** - * Returns the stale state. Must be invoked from the current realm. - * - * @return stale state - */ - public boolean isStale() { - checkRealm(); - return stale; - } - - /** - * Sets the stale state. Must be invoked from the current realm. - * - * @param stale - * The stale state to set. This will fire a stale event if the - * given boolean is true and this observable set was not already - * stale. - */ - public void setStale(boolean stale) { - checkRealm(); - boolean wasStale = this.stale; - this.stale = stale; - if (!wasStale && stale) { - fireStale(); - } - } - - public Object put(Object key, Object value) { - throw new UnsupportedOperationException(); - } - - public Object remove(Object key) { - throw new UnsupportedOperationException(); - } - - public void clear() { - throw new UnsupportedOperationException(); - } - - public void putAll(Map arg0) { - throw new UnsupportedOperationException(); - } - - public synchronized void dispose() { - super.dispose(); - } - - public boolean equals(Object obj) { - getterCalled(); - - if (obj == this) - return true; - if (obj == null) - return false; - if (getClass() == obj.getClass()) { - return wrappedMap.equals(((ObservableMap) obj).wrappedMap); - } - - return wrappedMap.equals(obj); - } - - public int hashCode() { - getterCalled(); - - return wrappedMap.hashCode(); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/WritableMap.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/WritableMap.java deleted file mode 100644 index 4e534221..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/WritableMap.java +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006-2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - * Matthew Hall - bug 184830 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.map; - -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.internal.databinding.Util; - -/** - * - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * @since 1.0 - */ -public class WritableMap extends ObservableMap { - - /** - * Constructs a new WritableMap on the default realm. - */ - public WritableMap() { - this(Realm.getDefault()); - } - - /** - * Constructs a new WritableMap on the given realm. - * - * @param realm - * the realm - */ - public WritableMap(Realm realm) { - super(realm, new HashMap()); - } - - /** - * Associates the provided <code>value</code> with the <code>key</code>. Must be invoked from the current realm. - */ - public Object put(Object key, Object value) { - checkRealm(); - Object result = wrappedMap.put(key, value); - if (!Util.equals(result, value)) { - if (result==null) { - fireMapChange(Diffs.createMapDiffSingleAdd(key, value)); - } else { - fireMapChange(Diffs.createMapDiffSingleChange(key, result, - value)); - } - } - return result; - } - - /** - * Removes the value with the provide <code>key</code>. Must be invoked from the current realm. - */ - public Object remove(Object key) { - checkRealm(); - Object result = wrappedMap.remove(key); - if (result!=null) { - fireMapChange(Diffs.createMapDiffSingleRemove(key, result)); - } - return result; - } - - /** - * Clears the map. Must be invoked from the current realm. - */ - public void clear() { - checkRealm(); - if (!isEmpty()) { - Map copy = new HashMap(wrappedMap); - wrappedMap.clear(); - fireMapChange(Diffs.createMapDiffRemoveAll(copy)); - } - } - - /** - * Adds the provided <code>map</code>'s contents to this map. Must be invoked from the current realm. - */ - public void putAll(Map map) { - checkRealm(); - Set addedKeys = new HashSet(map.size()); - Map changes = new HashMap(map.size()); - for (Iterator it = map.entrySet().iterator(); it.hasNext();) { - Map.Entry entry = (Entry) it.next(); - Object previousValue = wrappedMap.put(entry.getKey(), entry.getValue()); - if (previousValue==null) { - addedKeys.add(entry.getKey()); - } else { - changes.put(entry.getKey(), previousValue); - } - } - if (!addedKeys.isEmpty() || !changes.isEmpty()) { - fireMapChange(Diffs.createMapDiff(addedKeys, Collections.EMPTY_SET, changes.keySet(), changes, wrappedMap)); - } - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/package.html b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/package.html deleted file mode 100644 index 22107ea3..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/package.html +++ /dev/null @@ -1,16 +0,0 @@ -<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> - <meta name="Author" content="IBM"> - <meta name="GENERATOR" content="Mozilla/4.5 [en] (Win98; I) [Netscape]"> - <title>Package-level Javadoc</title> -</head> -<body> -Provides classes that can be used to observe changes in maps. -<h2> -Package Specification</h2> -<p> -This package provides classes that can be used to observe changes in maps.</p> -</body> -</html> diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/masterdetail/IObservableFactory.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/masterdetail/IObservableFactory.java deleted file mode 100644 index e113f141..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/masterdetail/IObservableFactory.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.masterdetail; - -import org.eclipse.core.databinding.observable.IObservable; - -/** - * Generates an {@link IObservable} when passed a target instance. - * - * @since 1.0 - */ -public interface IObservableFactory { - - /** - * Creates an observable for the given target object. - * - * @param target - * @return the new observable - */ - public IObservable createObservable(Object target); - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/masterdetail/MasterDetailObservables.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/masterdetail/MasterDetailObservables.java deleted file mode 100644 index 77832e3f..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/masterdetail/MasterDetailObservables.java +++ /dev/null @@ -1,119 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 147515 - * Matthew Hall - bug 221704 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.masterdetail; - -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.internal.databinding.observable.masterdetail.DetailObservableList; -import org.eclipse.core.internal.databinding.observable.masterdetail.DetailObservableMap; -import org.eclipse.core.internal.databinding.observable.masterdetail.DetailObservableSet; -import org.eclipse.core.internal.databinding.observable.masterdetail.DetailObservableValue; - -/** - * Allows for the observation of an attribute, the detail, of an observable - * representing selection or another transient instance, the master. - * - * @since 1.0 - */ -public class MasterDetailObservables { - - /** - * Creates a detail observable value from a master observable value and a - * factory. This can be used to create observable values that represent a - * property of a selected object in a table. - * - * @param master - * the observable value to track - * @param detailFactory - * a factory for creating {@link IObservableValue} instances - * given a current value of the master - * @param detailType - * the value type of the detail observable value, typically of - * type java.lang.Class and can be <code>null</code> - * @return an observable value of the given value type that, for any current - * value of the given master value, behaves like the observable - * value created by the factory for that current value. - */ - public static IObservableValue detailValue(IObservableValue master, - IObservableFactory detailFactory, Object detailType) { - return new DetailObservableValue(master, detailFactory, detailType); - } - - /** - * Creates a detail observable list from a master observable value and a - * factory. This can be used to create observable lists that represent a - * list property of a selected object in a table. - * - * @param master - * the observable value to track - * @param detailFactory - * a factory for creating {@link IObservableList} instances given - * a current value of the master - * @param detailElementType - * the element type of the detail observable list, typically of - * type java.lang.Class and can be <code>null</code> - * @return an observable list with the given element type that, for any - * current value of the given master value, behaves like the - * observable list created by the factory for that current value. - */ - public static IObservableList detailList(IObservableValue master, - IObservableFactory detailFactory, Object detailElementType) { - return new DetailObservableList(detailFactory, master, - detailElementType); - } - - /** - * Creates a detail observable set from a master observable value and a - * factory. This can be used to create observable sets that represent a set - * property of a selected object in a table. - * - * @param master - * the observable value to track - * @param detailFactory - * a factory for creating {@link IObservableSet} instances given - * a current value of the master - * @param detailElementType - * the element type of the detail observable set, typically of - * type java.lang.Class and can be <code>null</code> - * @return an observable set with the given element type that, for any - * current value of the given master value, behaves like the - * observable set created by the factory for that current value. - */ - public static IObservableSet detailSet(IObservableValue master, - IObservableFactory detailFactory, Object detailElementType) { - return new DetailObservableSet(detailFactory, master, detailElementType); - } - - /** - * Creates a detail observable map from a master observable value and a - * factory. This can be used to create observable maps that represent a map - * property of a selected object in a table. - * - * @param master - * the observable value to track - * @param detailFactory - * a factory for createing {@link IObservableMap} instances given - * a current value of the master - * @return an observable map that, for any current value of the given master - * value, behaves like the observable map created by the factory for - * that current value. - * @since 1.1 - */ - public static IObservableMap detailMap(IObservableValue master, - IObservableFactory detailFactory) { - return new DetailObservableMap(detailFactory, master); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/masterdetail/package.html b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/masterdetail/package.html deleted file mode 100644 index 07b72e5b..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/masterdetail/package.html +++ /dev/null @@ -1,17 +0,0 @@ -<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> - <meta name="Author" content="IBM"> - <meta name="GENERATOR" content="Mozilla/4.5 [en] (Win98; I) [Netscape]"> - <title>Package-level Javadoc</title> -</head> -<body> -Provides classes that can be used to observe a detail of a master object. -<h2> -Package Specification</h2> -<p> -This package provides classes that can be used to observe a detail of a master object. -A common use case for master detail is observing the detail (e.g. name) of a master (e.g. selected Person) of a list of elements.</p> -</body> -</html> diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/package.html b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/package.html deleted file mode 100644 index 0739c1ca..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/package.html +++ /dev/null @@ -1,16 +0,0 @@ -<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> - <meta name="Author" content="IBM"> - <meta name="GENERATOR" content="Mozilla/4.5 [en] (Win98; I) [Netscape]"> - <title>Package-level Javadoc</title> -</head> -<body> -Provides the core APIs for observing changes in objects. -<h2> -Package Specification</h2> -<p> -This package provides the core APIs for observing changes in objects.</p> -</body> -</html> diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/AbstractObservableSet.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/AbstractObservableSet.java deleted file mode 100644 index 5c9d0b7f..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/AbstractObservableSet.java +++ /dev/null @@ -1,218 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 208332 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.set; - -import java.util.Collection; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.databinding.observable.AbstractObservable; -import org.eclipse.core.databinding.observable.ChangeSupport; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.Realm; - -/** - * - * Abstract implementation of {@link IObservableSet}. - * - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * - * @since 1.0 - */ -public abstract class AbstractObservableSet extends AbstractObservable implements - IObservableSet { - - private ChangeSupport changeSupport; - - private boolean stale = false; - - protected AbstractObservableSet() { - this(Realm.getDefault()); - } - - protected void firstListenerAdded() { - super.firstListenerAdded(); - } - - protected void lastListenerRemoved() { - super.lastListenerRemoved(); - } - - protected AbstractObservableSet(Realm realm) { - super(realm); - changeSupport = new ChangeSupport(realm){ - protected void firstListenerAdded() { - AbstractObservableSet.this.firstListenerAdded(); - } - protected void lastListenerRemoved() { - AbstractObservableSet.this.lastListenerRemoved(); - } - }; - } - - public synchronized void addSetChangeListener(ISetChangeListener listener) { - changeSupport.addListener(SetChangeEvent.TYPE, listener); - } - - public synchronized void removeSetChangeListener(ISetChangeListener listener) { - changeSupport.removeListener(SetChangeEvent.TYPE, listener); - } - - protected abstract Set getWrappedSet(); - - protected void fireSetChange(SetDiff diff) { - // fire general change event first - super.fireChange(); - - changeSupport.fireEvent(new SetChangeEvent(this, diff)); - } - - public boolean contains(Object o) { - getterCalled(); - return getWrappedSet().contains(o); - } - - public boolean containsAll(Collection c) { - getterCalled(); - return getWrappedSet().containsAll(c); - } - - public boolean equals(Object o) { - getterCalled(); - return getWrappedSet().equals(o); - } - - public int hashCode() { - getterCalled(); - return getWrappedSet().hashCode(); - } - - public boolean isEmpty() { - getterCalled(); - return getWrappedSet().isEmpty(); - } - - public Iterator iterator() { - getterCalled(); - final Iterator wrappedIterator = getWrappedSet().iterator(); - return new Iterator() { - - public void remove() { - throw new UnsupportedOperationException(); - } - - public boolean hasNext() { - ObservableTracker.getterCalled(AbstractObservableSet.this); - return wrappedIterator.hasNext(); - } - - public Object next() { - ObservableTracker.getterCalled(AbstractObservableSet.this); - return wrappedIterator.next(); - } - }; - } - - public int size() { - getterCalled(); - return getWrappedSet().size(); - } - - public Object[] toArray() { - getterCalled(); - return getWrappedSet().toArray(); - } - - public Object[] toArray(Object[] a) { - getterCalled(); - return getWrappedSet().toArray(a); - } - - public String toString() { - getterCalled(); - return getWrappedSet().toString(); - } - - protected void getterCalled() { - ObservableTracker.getterCalled(this); - } - - public boolean add(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - throw new UnsupportedOperationException(); - } - - /** - * @return Returns the stale state. - */ - public boolean isStale() { - getterCalled(); - return stale; - } - - /** - * @param stale - * The stale state to set. This will fire a stale event if the - * given boolean is true and this observable set was not already - * stale. - */ - public void setStale(boolean stale) { - checkRealm(); - boolean wasStale = this.stale; - this.stale = stale; - if (!wasStale && stale) { - fireStale(); - } - } - - - protected void fireChange() { - throw new RuntimeException("fireChange should not be called, use fireSetChange() instead"); //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.jface.provisional.databinding.observable.AbstractObservable#dispose() - */ - public synchronized void dispose() { - super.dispose(); - - if (changeSupport != null) { - changeSupport.dispose(); - changeSupport = null; - } - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/IObservableSet.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/IObservableSet.java deleted file mode 100644 index 0efecf66..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/IObservableSet.java +++ /dev/null @@ -1,129 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.set; - -import java.util.Collection; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.databinding.observable.IObservableCollection; - -/** - * A set whose changes can be tracked by set change listeners. - * - * @noextend This interface is not intended to be extended by clients. - * @noimplement This interface is not intended to be implemented by clients. - * Clients should instead subclass one of the classes that - * implement this interface. Note that direct implementers of this - * interface outside of the framework will be broken in future - * releases when methods are added to this interface. - * - * @see AbstractObservableSet - * @see ObservableSet - * - * @since 1.0 - * - */ -public interface IObservableSet extends Set, IObservableCollection { - - /** - * @param listener - */ - public void addSetChangeListener(ISetChangeListener listener); - - /** - * @param listener - */ - public void removeSetChangeListener(ISetChangeListener listener); - - /** - * @return the element type or <code>null</code> if untyped - */ - public Object getElementType(); - - /** - * @TrackedGetter - */ - int size(); - - /** - * @TrackedGetter - */ - boolean isEmpty(); - - /** - * @TrackedGetter - */ - boolean contains(Object o); - - /** - * @TrackedGetter - */ - Iterator iterator(); - - /** - * @TrackedGetter - */ - Object[] toArray(); - - /** - * @TrackedGetter - */ - Object[] toArray(Object a[]); - - // Modification Operations - - /** - * @TrackedGetter - */ - boolean add(Object o); - - /** - * @TrackedGetter - */ - boolean remove(Object o); - - // Bulk Operations - - /** - * @TrackedGetter - */ - boolean containsAll(Collection c); - - /** - * @TrackedGetter - */ - boolean addAll(Collection c); - - /** - * @TrackedGetter - */ - boolean retainAll(Collection c); - - /** - * @TrackedGetter - */ - boolean removeAll(Collection c); - - // Comparison and hashing - - /** - * @TrackedGetter - */ - boolean equals(Object o); - - /** - * @TrackedGetter - */ - int hashCode(); - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/ISetChangeListener.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/ISetChangeListener.java deleted file mode 100644 index 51c429a3..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/ISetChangeListener.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.set; - -import org.eclipse.core.databinding.observable.IObservablesListener; - -/** - * Listener for changes to observable sets. - * - * @since 1.0 - * - */ -public interface ISetChangeListener extends IObservablesListener { - - /** - * Handle a change to an observable set. The given event object must only be - * used locally in this method because it may be reused for other change - * notifications. The diff object referenced by the event is immutable and - * may be used non-locally. - * - * @param event - * the event - */ - void handleSetChange(SetChangeEvent event); - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/ListToSetAdapter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/ListToSetAdapter.java deleted file mode 100644 index e145fb3c..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/ListToSetAdapter.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.set; - -import java.util.HashSet; -import java.util.Set; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IListChangeListener; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.ListChangeEvent; -import org.eclipse.core.databinding.observable.list.ListDiffEntry; - -/** - * Observable set backed by an observable list. The wrapped list must not - * contain duplicate elements. - * - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * - * @since 1.0 - * - */ -public class ListToSetAdapter extends ObservableSet { - - private final IObservableList list; - - private IListChangeListener listener = new IListChangeListener() { - - public void handleListChange(ListChangeEvent event) { - Set added = new HashSet(); - Set removed = new HashSet(); - ListDiffEntry[] differences = event.diff.getDifferences(); - for (int i = 0; i < differences.length; i++) { - ListDiffEntry entry = differences[i]; - Object element = entry.getElement(); - if (entry.isAddition()) { - if (wrappedSet.add(element)) { - if (!removed.remove(element)) - added.add(element); - } - } else { - if (wrappedSet.remove(element)) { - removed.add(element); - added.remove(element); - } - } - } - fireSetChange(Diffs.createSetDiff(added, removed)); - } - }; - - /** - * @param list - */ - public ListToSetAdapter(IObservableList list) { - super(list.getRealm(), new HashSet(), list.getElementType()); - this.list = list; - wrappedSet.addAll(list); - this.list.addListChangeListener(listener); - } - - public synchronized void dispose() { - super.dispose(); - if (list != null && listener != null) { - list.removeListChangeListener(listener); - listener = null; - } - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/MappedSet.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/MappedSet.java deleted file mode 100644 index c51c0c5c..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/MappedSet.java +++ /dev/null @@ -1,157 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.set; - -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.map.IMapChangeListener; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.map.MapChangeEvent; -import org.eclipse.core.databinding.observable.map.MapDiff; - -/** - * - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * - * @since 1.0 - * - */ -public class MappedSet extends ObservableSet { - - private final IObservableMap wrappedMap; - - /* - * Map from values (range elements) to Integer ref counts - */ - private Map valueCounts = new HashMap(); - - private ISetChangeListener domainListener = new ISetChangeListener() { - public void handleSetChange(SetChangeEvent event) { - Set additions = new HashSet(); - for (Iterator it = event.diff.getAdditions().iterator(); it.hasNext();) { - Object added = it.next(); - Object mapValue = wrappedMap.get(added); - if (handleAddition(mapValue)) { - additions.add(mapValue); - } - } - Set removals = new HashSet(); - for (Iterator it = event.diff.getRemovals().iterator(); it.hasNext();) { - Object removed = it.next(); - Object mapValue = wrappedMap.get(removed); - if (handleRemoval(mapValue)) { - removals.add(mapValue); - } - } - fireSetChange(Diffs.createSetDiff(additions, removals)); - } - }; - - private IMapChangeListener mapChangeListener = new IMapChangeListener() { - public void handleMapChange(MapChangeEvent event) { - MapDiff diff = event.diff; - Set additions = new HashSet(); - Set removals = new HashSet(); - for (Iterator it = diff.getRemovedKeys().iterator(); it.hasNext();) { - Object key = it.next(); - Object oldValue = diff.getOldValue(key); - if (handleRemoval(oldValue)) { - removals.add(oldValue); - } - } - for (Iterator it = diff.getChangedKeys().iterator(); it.hasNext();) { - Object key = it.next(); - Object oldValue = diff.getOldValue(key); - Object newValue = diff.getNewValue(key); - if (handleRemoval(oldValue)) { - removals.add(oldValue); - } - if (handleAddition(newValue)) { - additions.add(newValue); - } - } - for (Iterator it = diff.getAddedKeys().iterator(); it.hasNext();) { - Object key = it.next(); - Object newValue = diff.getNewValue(key); - if (handleAddition(newValue)) { - additions.add(newValue); - } - } - fireSetChange(Diffs.createSetDiff(additions, removals)); - } - }; - - private IObservableSet input; - - /** - * @param input - * @param map - */ - public MappedSet(IObservableSet input, IObservableMap map) { - super(input.getRealm(), Collections.EMPTY_SET, Object.class); - setWrappedSet(valueCounts.keySet()); - this.wrappedMap = map; - this.input = input; - for (Iterator it = input.iterator(); it.hasNext();) { - Object element = it.next(); - Object functionValue = wrappedMap.get(element); - handleAddition(functionValue); - } - input.addSetChangeListener(domainListener); - map.addMapChangeListener(mapChangeListener); - } - - /** - * @param mapValue - * @return true if the given mapValue was an addition - */ - protected boolean handleAddition(Object mapValue) { - Integer count = (Integer) valueCounts.get(mapValue); - if (count == null) { - valueCounts.put(mapValue, new Integer(1)); - return true; - } - valueCounts.put(mapValue, new Integer(count.intValue() + 1)); - return false; - } - - /** - * @param mapValue - * @return true if the given mapValue has been removed - */ - protected boolean handleRemoval(Object mapValue) { - Integer count = (Integer) valueCounts.get(mapValue); - if (count.intValue() <= 1) { - valueCounts.remove(mapValue); - return true; - } - valueCounts.put(mapValue, new Integer(count.intValue() - 1)); - return false; - } - - public synchronized void dispose() { - wrappedMap.removeMapChangeListener(mapChangeListener); - input.removeSetChangeListener(domainListener); - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/ObservableSet.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/ObservableSet.java deleted file mode 100644 index 433a0f83..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/ObservableSet.java +++ /dev/null @@ -1,217 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bugs 208332, 245183 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.set; - -import java.util.Collection; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.databinding.observable.AbstractObservable; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.Realm; - -/** - * - * Abstract implementation of {@link IObservableSet}. - * - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * - * @since 1.0 - * - */ -public abstract class ObservableSet extends AbstractObservable implements - IObservableSet { - - protected Set wrappedSet; - - private boolean stale = false; - - protected Object elementType; - - protected ObservableSet(Set wrappedSet, Object elementType) { - this(Realm.getDefault(), wrappedSet, elementType); - } - - protected ObservableSet(Realm realm, Set wrappedSet, Object elementType) { - super(realm); - this.wrappedSet = wrappedSet; - this.elementType = elementType; - } - - public synchronized void addSetChangeListener(ISetChangeListener listener) { - addListener(SetChangeEvent.TYPE, listener); - } - - public synchronized void removeSetChangeListener(ISetChangeListener listener) { - removeListener(SetChangeEvent.TYPE, listener); - } - - protected void fireSetChange(SetDiff diff) { - // fire general change event first - super.fireChange(); - - fireEvent(new SetChangeEvent(this, diff)); - } - - public boolean contains(Object o) { - getterCalled(); - return wrappedSet.contains(o); - } - - public boolean containsAll(Collection c) { - getterCalled(); - return wrappedSet.containsAll(c); - } - - public boolean equals(Object o) { - getterCalled(); - - if (o == this) - return true; - if (o == null) - return false; - if (getClass() == o.getClass()) { - return wrappedSet.equals(((ObservableSet) o).wrappedSet); - } - - return wrappedSet.equals(o); - } - - public int hashCode() { - getterCalled(); - return wrappedSet.hashCode(); - } - - public boolean isEmpty() { - getterCalled(); - return wrappedSet.isEmpty(); - } - - public Iterator iterator() { - getterCalled(); - final Iterator wrappedIterator = wrappedSet.iterator(); - return new Iterator() { - - public void remove() { - throw new UnsupportedOperationException(); - } - - public boolean hasNext() { - ObservableTracker.getterCalled(ObservableSet.this); - return wrappedIterator.hasNext(); - } - - public Object next() { - ObservableTracker.getterCalled(ObservableSet.this); - return wrappedIterator.next(); - } - }; - } - - public int size() { - getterCalled(); - return wrappedSet.size(); - } - - public Object[] toArray() { - getterCalled(); - return wrappedSet.toArray(); - } - - public Object[] toArray(Object[] a) { - getterCalled(); - return wrappedSet.toArray(a); - } - - public String toString() { - getterCalled(); - return wrappedSet.toString(); - } - - protected void getterCalled() { - ObservableTracker.getterCalled(this); - } - - public boolean add(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - throw new UnsupportedOperationException(); - } - - /** - * @return Returns the stale state. - */ - public boolean isStale() { - getterCalled(); - return stale; - } - - /** - * @param stale - * The stale state to set. This will fire a stale event if the - * given boolean is true and this observable set was not already - * stale. - */ - public void setStale(boolean stale) { - checkRealm(); - boolean wasStale = this.stale; - this.stale = stale; - if (!wasStale && stale) { - fireStale(); - } - } - - /** - * @param wrappedSet The wrappedSet to set. - */ - protected void setWrappedSet(Set wrappedSet) { - this.wrappedSet = wrappedSet; - } - - protected void fireChange() { - throw new RuntimeException("fireChange should not be called, use fireSetChange() instead"); //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.jface.provisional.databinding.observable.AbstractObservable#dispose() - */ - public synchronized void dispose() { - super.dispose(); - } - - public Object getElementType() { - return elementType; - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/SetChangeEvent.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/SetChangeEvent.java deleted file mode 100644 index 4873885e..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/SetChangeEvent.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.databinding.observable.set; - -import org.eclipse.core.databinding.observable.IObservablesListener; -import org.eclipse.core.databinding.observable.ObservableEvent; - -/** - * List change event describing an incremental change of an - * {@link IObservableSet} object. - * - * @since 1.0 - * - */ -public class SetChangeEvent extends ObservableEvent { - - /** - * - */ - private static final long serialVersionUID = 7436547103857482256L; - static final Object TYPE = new Object(); - - /** - * Description of the change to the source observable set. Listeners must - * not change this field. - */ - public SetDiff diff; - - /** - * Creates a new set change event. - * - * @param source - * the source observable set - * @param diff - * the set change - */ - public SetChangeEvent(IObservableSet source, SetDiff diff) { - super(source); - this.diff = diff; - } - - /** - * Returns the observable set from which this event originated. - * - * @return the observable set from which this event originated - */ - public IObservableSet getObservableSet() { - return (IObservableSet) getSource(); - } - - protected void dispatch(IObservablesListener listener) { - ((ISetChangeListener) listener).handleSetChange(this); - } - - protected Object getListenerType() { - return TYPE; - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/SetDiff.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/SetDiff.java deleted file mode 100644 index d1a2f138..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/SetDiff.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.set; - -import java.util.Set; - -/** - * @since 1.0 - * - */ -public abstract class SetDiff { - - /** - * @return the set of added elements - */ - public abstract Set getAdditions(); - - /** - * @return the set of removed elements - */ - public abstract Set getRemovals(); - - /** - * @see java.lang.Object#toString() - */ - public String toString() { - StringBuffer buffer = new StringBuffer(); - buffer - .append(getClass().getName()) - .append("{additions [") //$NON-NLS-1$ - .append(getAdditions() != null ? getAdditions().toString() : "null") //$NON-NLS-1$ - .append("], removals [") //$NON-NLS-1$ - .append(getRemovals() != null ? getRemovals().toString() : "null") //$NON-NLS-1$ - .append("]}"); //$NON-NLS-1$ - - return buffer.toString(); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/UnionSet.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/UnionSet.java deleted file mode 100644 index 768c62d6..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/UnionSet.java +++ /dev/null @@ -1,210 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 208332 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.set; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.internal.databinding.observable.IStalenessConsumer; -import org.eclipse.core.internal.databinding.observable.StalenessTracker; - -/** - * Represents a set consisting of the union of elements from one or more other - * sets. This object does not need to be explicitly disposed. If nobody is - * listening to the UnionSet, the set will remove its listeners. - * - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * - * @since 1.0 - */ -public final class UnionSet extends ObservableSet { - - /** - * child sets - */ - private IObservableSet[] childSets; - - private boolean stale = false; - - /** - * Map of elements onto Integer reference counts. This map is constructed - * when the first listener is added to the union set. Null if nobody is - * listening to the UnionSet. - */ - private HashMap refCounts = null; - - private StalenessTracker stalenessTracker; - - /** - * @param childSets - */ - public UnionSet(IObservableSet[] childSets) { - super(childSets[0].getRealm(), null, childSets[0].getElementType()); - System.arraycopy(childSets, 0, this.childSets = new IObservableSet[childSets.length], 0, childSets.length); - this.stalenessTracker = new StalenessTracker(childSets, - stalenessConsumer); - } - - private ISetChangeListener childSetChangeListener = new ISetChangeListener() { - public void handleSetChange(SetChangeEvent event) { - processAddsAndRemoves(event.diff.getAdditions(), event.diff.getRemovals()); - } - }; - - private IStalenessConsumer stalenessConsumer = new IStalenessConsumer() { - public void setStale(boolean stale) { - boolean oldStale = UnionSet.this.stale; - UnionSet.this.stale = stale; - if (stale && !oldStale) { - fireStale(); - } - } - }; - - public boolean isStale() { - getterCalled(); - if (refCounts != null) { - return stale; - } - - for (int i = 0; i < childSets.length; i++) { - IObservableSet childSet = childSets[i]; - - if (childSet.isStale()) { - return true; - } - } - return false; - } - - private void processAddsAndRemoves(Set adds, Set removes) { - Set addsToFire = new HashSet(); - Set removesToFire = new HashSet(); - - for (Iterator iter = adds.iterator(); iter.hasNext();) { - Object added = iter.next(); - - Integer refCount = (Integer) refCounts.get(added); - if (refCount == null) { - refCounts.put(added, new Integer(1)); - addsToFire.add(added); - } else { - int refs = refCount.intValue(); - refCount = new Integer(refs + 1); - refCounts.put(added, refCount); - } - } - - for (Iterator iter = removes.iterator(); iter.hasNext();) { - Object removed = iter.next(); - - Integer refCount = (Integer) refCounts.get(removed); - if (refCount != null) { - int refs = refCount.intValue(); - if (refs <= 1) { - removesToFire.add(removed); - refCounts.remove(removed); - } else { - refCount = new Integer(refCount.intValue() - 1); - refCounts.put(removed, refCount); - } - } - } - - // just in case the removes overlapped with the adds - addsToFire.removeAll(removesToFire); - - if (addsToFire.size() > 0 || removesToFire.size() > 0) { - fireSetChange(Diffs.createSetDiff(addsToFire, removesToFire)); - } - } - - protected void firstListenerAdded() { - super.firstListenerAdded(); - - refCounts = new HashMap(); - for (int i = 0; i < childSets.length; i++) { - IObservableSet next = childSets[i]; - next.addSetChangeListener(childSetChangeListener); - incrementRefCounts(next); - } - stalenessTracker = new StalenessTracker(childSets, stalenessConsumer); - setWrappedSet(refCounts.keySet()); - } - - protected void lastListenerRemoved() { - super.lastListenerRemoved(); - - for (int i = 0; i < childSets.length; i++) { - IObservableSet next = childSets[i]; - - next.removeSetChangeListener(childSetChangeListener); - stalenessTracker.removeObservable(next); - } - refCounts = null; - stalenessTracker = null; - setWrappedSet(null); - } - - private ArrayList incrementRefCounts(Collection added) { - ArrayList adds = new ArrayList(); - - for (Iterator iter = added.iterator(); iter.hasNext();) { - Object next = iter.next(); - - Integer refCount = (Integer) refCounts.get(next); - if (refCount == null) { - adds.add(next); - refCount = new Integer(1); - refCounts.put(next, refCount); - } else { - refCount = new Integer(refCount.intValue() + 1); - refCounts.put(next, refCount); - } - } - return adds; - } - - protected void getterCalled() { - super.getterCalled(); - if (refCounts == null) { - // no listeners, recompute - setWrappedSet(computeElements()); - } - } - - private Set computeElements() { - // If there is no cached value, compute the union from scratch - if (refCounts == null) { - Set result = new HashSet(); - for (int i = 0; i < childSets.length; i++) { - result.addAll(childSets[i]); - } - return result; - } - - // Else there is a cached value. Return it. - return refCounts.keySet(); - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/WritableSet.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/WritableSet.java deleted file mode 100644 index 52ded9dd..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/WritableSet.java +++ /dev/null @@ -1,171 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006-2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 147515 - * Matthew Hall - bug 221351 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.set; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; - -/** - * Mutable (writable) implementation of {@link IObservableSet}. - * - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * - * @since 1.0 - */ -public class WritableSet extends ObservableSet { - - /** - * Constructs a new empty instance in the default realm with a - * <code>null</code> element type. - * - */ - public WritableSet() { - this(Realm.getDefault()); - } - - /** - * Constructs a new instance in the default realm containing the - * elements of the given collection. Changes to the given collection after - * calling this method do not affect the contents of the created WritableSet. - * - * @param c - * @param elementType - * can be <code>null</code> - */ - public WritableSet(Collection c, Object elementType) { - this(Realm.getDefault(), new HashSet(c), elementType); - } - - /** - * Constructs a new empty instance in the given realm and a - * <code>null</code> element type. - * - * @param realm - */ - public WritableSet(Realm realm) { - this(realm, new HashSet(), null); - } - - /** - * Constructs a new instance in the default realm with the given element - * type, containing the elements of the given collection. Changes to the - * given collection after calling this method do not affect the contents of - * the created WritableSet. - * - * @param realm - * @param c - * @param elementType - * can be <code>null</code> - */ - public WritableSet(Realm realm, Collection c, Object elementType) { - super(realm, new HashSet(c), elementType); - this.elementType = elementType; - } - - public boolean add(Object o) { - getterCalled(); - boolean added = wrappedSet.add(o); - if (added) { - fireSetChange(Diffs.createSetDiff(Collections.singleton(o), Collections.EMPTY_SET)); - } - return added; - } - - public boolean addAll(Collection c) { - getterCalled(); - Set additions = new HashSet(); - Iterator it = c.iterator(); - while (it.hasNext()) { - Object element = it.next(); - if (wrappedSet.add(element)) { - additions.add(element); - } - } - if (additions.size() > 0) { - fireSetChange(Diffs.createSetDiff(additions, Collections.EMPTY_SET)); - return true; - } - return false; - } - - public boolean remove(Object o) { - getterCalled(); - boolean removed = wrappedSet.remove(o); - if (removed) { - fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, Collections - .singleton(o))); - } - return removed; - } - - public boolean removeAll(Collection c) { - getterCalled(); - Set removes = new HashSet(); - Iterator it = c.iterator(); - while (it.hasNext()) { - Object element = it.next(); - if (wrappedSet.remove(element)) { - removes.add(element); - } - } - if (removes.size() > 0) { - fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, removes)); - return true; - } - return false; - } - - public boolean retainAll(Collection c) { - getterCalled(); - Set removes = new HashSet(); - Iterator it = wrappedSet.iterator(); - while (it.hasNext()) { - Object element = it.next(); - if (!c.contains(element)) { - it.remove(); - removes.add(element); - } - } - if (removes.size() > 0) { - fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, removes)); - return true; - } - return false; - } - - public void clear() { - getterCalled(); - Set removes = new HashSet(wrappedSet); - wrappedSet.clear(); - fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, removes)); - } - - /** - * @param elementType can be <code>null</code> - * @return new instance with the default realm - */ - public static WritableSet withElementType(Object elementType) { - return new WritableSet(Realm.getDefault(), new HashSet(), elementType); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/package.html b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/package.html deleted file mode 100644 index 5a57448a..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/package.html +++ /dev/null @@ -1,16 +0,0 @@ -<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> - <meta name="Author" content="IBM"> - <meta name="GENERATOR" content="Mozilla/4.5 [en] (Win98; I) [Netscape]"> - <title>Package-level Javadoc</title> -</head> -<body> -Provides classes that can be used to observe changes in sets. -<h2> -Package Specification</h2> -<p> -This package provides classes that can be used to observe changes in sets.</p> -</body> -</html> diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/AbstractObservableValue.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/AbstractObservableValue.java deleted file mode 100644 index 1c615894..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/AbstractObservableValue.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - * Matthew Hall - bug 208332 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.value; - -import org.eclipse.core.databinding.observable.AbstractObservable; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.Realm; - -/** - * - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * @since 1.0 - * - */ -abstract public class AbstractObservableValue extends AbstractObservable implements IObservableValue { - /** - * Constructs a new instance with the default realm. - */ - public AbstractObservableValue() { - this(Realm.getDefault()); - } - - /** - * @param realm - */ - public AbstractObservableValue(Realm realm) { - super(realm); - } - - public synchronized void addValueChangeListener(IValueChangeListener listener) { - addListener(ValueChangeEvent.TYPE, listener); - } - - public synchronized void removeValueChangeListener(IValueChangeListener listener) { - removeListener(ValueChangeEvent.TYPE, listener); - } - - final public void setValue(Object value) { - checkRealm(); - doSetValue(value); - } - - /** - * Template method for setting the value of the observable. By default the - * method throws an {@link UnsupportedOperationException}. - * - * @param value - */ - protected void doSetValue(Object value) { - throw new UnsupportedOperationException(); - } - - protected void fireValueChange(ValueDiff diff) { - // fire general change event first - super.fireChange(); - fireEvent(new ValueChangeEvent(this, diff)); - } - - public final Object getValue() { - getterCalled(); - return doGetValue(); - } - - abstract protected Object doGetValue(); - - public boolean isStale() { - getterCalled(); - return false; - } - - private void getterCalled() { - ObservableTracker.getterCalled(this); - } - - protected void fireChange() { - throw new RuntimeException( - "fireChange should not be called, use fireValueChange() instead"); //$NON-NLS-1$ - } - - public synchronized void dispose() { - super.dispose(); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/AbstractVetoableValue.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/AbstractVetoableValue.java deleted file mode 100644 index d3cff74b..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/AbstractVetoableValue.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - *******************************************************************************/ -package org.eclipse.core.databinding.observable.value; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.internal.databinding.Util; - -/** - * - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * @since 1.0 - * - */ -public abstract class AbstractVetoableValue extends AbstractObservableValue - implements IVetoableValue { - - /** - * Creates a new vetoable value. - */ - public AbstractVetoableValue() { - this(Realm.getDefault()); - } - - /** - * @param realm - */ - public AbstractVetoableValue(Realm realm) { - super(realm); - } - - final protected void doSetValue(Object value) { - Object currentValue = doGetValue(); - ValueDiff diff = Diffs.createValueDiff(currentValue, value); - boolean okToProceed = fireValueChanging(diff); - if (!okToProceed) { - throw new ChangeVetoException("Change not permitted"); //$NON-NLS-1$ - } - doSetApprovedValue(value); - - if (!Util.equals(diff.getOldValue(), diff.getNewValue())) { - fireValueChange(diff); - } - } - - /** - * Sets the value. Invoked after performing veto checks. Should not fire change events. - * - * @param value - */ - protected abstract void doSetApprovedValue(Object value); - - public synchronized void addValueChangingListener( - IValueChangingListener listener) { - addListener(ValueChangingEvent.TYPE, listener); - } - - public synchronized void removeValueChangingListener( - IValueChangingListener listener) { - removeListener(ValueChangingEvent.TYPE, listener); - } - - /** - * Notifies listeners about a pending change, and returns true if no - * listener vetoed the change. - * - * @param diff - * @return false if the change was vetoed, true otherwise - */ - protected boolean fireValueChanging(ValueDiff diff) { - checkRealm(); - - ValueChangingEvent event = new ValueChangingEvent(this, diff); - fireEvent(event); - return !event.veto; - } - - public synchronized void dispose() { - super.dispose(); - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/ChangeVetoException.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/ChangeVetoException.java deleted file mode 100644 index 3c9261ff..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/ChangeVetoException.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.core.databinding.observable.value; - -/** - * @since 1.0 - * - */ -public class ChangeVetoException extends RuntimeException { - - /** - * @param string - */ - public ChangeVetoException(String string) { - super(string); - } - - private static final long serialVersionUID = 1L; - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/ComputedValue.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/ComputedValue.java deleted file mode 100644 index 755063aa..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/ComputedValue.java +++ /dev/null @@ -1,261 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 116920 - * Brad Reynolds - bug 147515 - *******************************************************************************/ -package org.eclipse.core.databinding.observable.value; - -import org.eclipse.core.databinding.observable.ChangeEvent; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.StaleEvent; - -/** - * A Lazily calculated value that automatically computes and registers listeners - * on its dependencies as long as all of its dependencies are IObservable - * objects - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * - * @since 1.0 - */ -public abstract class ComputedValue extends AbstractObservableValue { - - private boolean dirty = true; - - private boolean stale = false; - - private Object cachedValue = null; - - /** - * Array of observables this computed value depends on. This field has a - * value of <code>null</code> if we are not currently listening. - */ - private IObservable[] dependencies = null; - - /** - * - */ - public ComputedValue() { - this(Realm.getDefault(), null); - } - - /** - * @param valueType - * can be <code>null</code> - */ - public ComputedValue(Object valueType) { - this(Realm.getDefault(), valueType); - } - - /** - * @param realm - * - */ - public ComputedValue(Realm realm) { - this(realm, null); - } - - /** - * @param realm - * @param valueType - */ - public ComputedValue(Realm realm, Object valueType) { - super(realm); - this.valueType = valueType; - } - - /** - * Inner class that implements interfaces that we don't want to expose as - * public API. Each interface could have been implemented using a separate - * anonymous class, but we combine them here to reduce the memory overhead - * and number of classes. - * - * <p> - * The Runnable calls computeValue and stores the result in cachedValue. - * </p> - * - * <p> - * The IChangeListener stores each observable in the dependencies list. This - * is registered as the listener when calling ObservableTracker, to detect - * every observable that is used by computeValue. - * </p> - * - * <p> - * The IChangeListener is attached to every dependency. - * </p> - * - */ - private class PrivateInterface implements Runnable, IChangeListener, - IStaleListener { - public void run() { - cachedValue = calculate(); - } - - public void handleStale(StaleEvent event) { - if (!dirty && !stale) { - stale = true; - fireStale(); - } - } - - public void handleChange(ChangeEvent event) { - makeDirty(); - } - } - - private PrivateInterface privateInterface = new PrivateInterface(); - - private Object valueType; - - protected final Object doGetValue() { - if (dirty) { - // This line will do the following: - // - Run the calculate method - // - While doing so, add any observable that is touched to the - // dependencies list - IObservable[] newDependencies = ObservableTracker.runAndMonitor( - privateInterface, privateInterface, null); - - stale = false; - for (int i = 0; i < newDependencies.length; i++) { - IObservable observable = newDependencies[i]; - // Add a change listener to the new dependency. - if (observable.isStale()) { - stale = true; - } else { - observable.addStaleListener(privateInterface); - } - } - - dependencies = newDependencies; - - dirty = false; - } - - return cachedValue; - } - - /** - * Subclasses must override this method to provide the object's value. - * - * @return the object's value - */ - protected abstract Object calculate(); - - protected final void makeDirty() { - if (!dirty) { - dirty = true; - - stopListening(); - - // copy the old value - final Object oldValue = cachedValue; - // Fire the "dirty" event. This implementation recomputes the new - // value lazily. - fireValueChange(new ValueDiff() { - - public Object getOldValue() { - return oldValue; - } - - public Object getNewValue() { - return getValue(); - } - }); - } - } - - /** - * - */ - private void stopListening() { - // Stop listening for dependency changes. - if (dependencies != null) { - for (int i = 0; i < dependencies.length; i++) { - IObservable observable = dependencies[i]; - - observable.removeChangeListener(privateInterface); - observable.removeStaleListener(privateInterface); - } - dependencies = null; - } - } - - public boolean isStale() { - // we need to recompute, otherwise staleness wouldn't mean anything - getValue(); - return stale; - } - - public Object getValueType() { - return valueType; - } - - // this method exists here so that we can call it from the runnable below. - /** - * @since 1.1 - */ - protected boolean hasListeners() { - return super.hasListeners(); - } - - public synchronized void addChangeListener(IChangeListener listener) { - super.addChangeListener(listener); - // If somebody is listening, we need to make sure we attach our own - // listeners - computeValueForListeners(); - } - - /** - * Some clients just add a listener and expect to get notified even if they - * never called getValue(), so we have to call getValue() ourselves here to - * be sure. Need to be careful about realms though, this method can be - * called outside of our realm. See also bug 198211. If a client calls this - * outside of our realm, they may receive change notifications before the - * runnable below has been executed. It is their job to figure out what to - * do with those notifications. - */ - private void computeValueForListeners() { - getRealm().exec(new Runnable() { - public void run() { - if (dependencies == null) { - // We are not currently listening. - if (hasListeners()) { - // But someone is listening for changes. Call getValue() - // to make sure we start listening to the observables we - // depend on. - getValue(); - } - } - } - }); - } - - public synchronized void addValueChangeListener( - IValueChangeListener listener) { - super.addValueChangeListener(listener); - // If somebody is listening, we need to make sure we attach our own - // listeners - computeValueForListeners(); - } - - public synchronized void dispose() { - super.dispose(); - stopListening(); - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/IObservableValue.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/IObservableValue.java deleted file mode 100644 index 630b1c47..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/IObservableValue.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.value; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; - -/** - * A value whose changes can be tracked by value change listeners. - * - * @noextend This interface is not intended to be extended by clients. - * @noimplement This interface is not intended to be implemented by clients. - * Clients should instead subclass one of the classes that - * implement this interface. Note that direct implementers of this - * interface outside of the framework will be broken in future - * releases when methods are added to this interface. - * - * @see AbstractObservableValue - * - * @since 1.0 - */ -public interface IObservableValue extends IObservable { - - /** - * The value type of this observable value, or <code>null</code> if this - * observable value is untyped. - * - * @return the value type, or <code>null</null> - */ - public Object getValueType(); - - /** - * Returns the value. Must be invoked in the {@link Realm} of the observable. - * - * @return the current value - * @TrackedGetter - */ - public Object getValue(); - - /** - * Sets the value. Must be invoked in the {@link Realm} of the observable. - * - * @param value - * the value to set - * @throws UnsupportedOperationException - * if this observable value cannot be set. - */ - public void setValue(Object value); - - /** - * - * @param listener - */ - public void addValueChangeListener(IValueChangeListener listener); - - /** - * @param listener - */ - public void removeValueChangeListener(IValueChangeListener listener); -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/IValueChangeListener.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/IValueChangeListener.java deleted file mode 100644 index 7af53822..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/IValueChangeListener.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.value; - -import org.eclipse.core.databinding.observable.IObservablesListener; - -/** - * Listener for changes to observable values. - * - * @since 1.0 - * - */ -public interface IValueChangeListener extends IObservablesListener { - - /** - * Handles a change to an observable value. The given event object must only - * be used locally in this method because it may be reused for other change - * notifications. The diff object referenced by the event is immutable and - * may be used non-locally. - * - * @param event - * the event - */ - void handleValueChange(ValueChangeEvent event); - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/IValueChangingListener.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/IValueChangingListener.java deleted file mode 100644 index ceb07b74..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/IValueChangingListener.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.core.databinding.observable.value; - -import org.eclipse.core.databinding.observable.IObservablesListener; - -/** - * Listener for pre-change events for observable values. - * - * @since 1.0 - * - */ -public interface IValueChangingListener extends IObservablesListener { - - /** - * This method is called when the value is about to change and provides an - * opportunity to veto the change. The given event object must only be used - * locally in this method because it may be reused for other change - * notifications. The diff object referenced by the event is immutable and - * may be used non-locally. - * - * @param event - */ - public void handleValueChanging(ValueChangingEvent event); - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/IVetoableValue.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/IVetoableValue.java deleted file mode 100644 index 1b795eda..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/IVetoableValue.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.core.databinding.observable.value; - -/** - * An observable value whose changes can be vetoed by listeners. - * - * @noextend This interface is not intended to be extended by clients. - * @noimplement This interface is not intended to be implemented by clients. - * Clients should instead subclass one of the classes that - * implement this interface. Note that direct implementers of this - * interface outside of the framework will be broken in future - * releases when methods are added to this interface. - * - * @since 1.0 - * - */ -public interface IVetoableValue extends IObservableValue { - - /** - * @param listener - */ - public void addValueChangingListener(IValueChangingListener listener); - - /** - * @param listener - */ - public void removeValueChangingListener(IValueChangingListener listener); - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/ValueChangeEvent.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/ValueChangeEvent.java deleted file mode 100644 index 3d4fba90..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/ValueChangeEvent.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.databinding.observable.value; - -import org.eclipse.core.databinding.observable.IObservablesListener; -import org.eclipse.core.databinding.observable.ObservableEvent; - -/** - * Value change event describing a change of an {@link IObservableValue} - * object's current value. - * - * @since 1.0 - * - */ -public class ValueChangeEvent extends ObservableEvent { - - /** - * - */ - private static final long serialVersionUID = 2305345286999701156L; - - static final Object TYPE = new Object(); - - /** - * Description of the change to the source observable value. Listeners must - * not change this field. - */ - public ValueDiff diff; - - /** - * Creates a new value change event. - * - * @param source - * the source observable value - * @param diff - * the value change - */ - public ValueChangeEvent(IObservableValue source, ValueDiff diff) { - super(source); - this.diff = diff; - } - - /** - * Returns the observable value from which this event originated. - * - * @return returns the observable value from which this event originated - */ - public IObservableValue getObservableValue() { - return (IObservableValue) source; - } - - protected void dispatch(IObservablesListener listener) { - ((IValueChangeListener) listener).handleValueChange(this); - } - - protected Object getListenerType() { - return TYPE; - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/ValueChangingEvent.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/ValueChangingEvent.java deleted file mode 100644 index f92cde7b..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/ValueChangingEvent.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.databinding.observable.value; - -import org.eclipse.core.databinding.observable.IObservablesListener; -import org.eclipse.core.databinding.observable.ObservableEvent; - -/** - * Value changing event describing a pending change of an - * {@link IObservableValue} object's current value. Listeners can veto the - * pending change by setting {@link #veto} to <code>true</code>. - * - * @since 1.0 - * - */ -public class ValueChangingEvent extends ObservableEvent { - - /** - * - */ - private static final long serialVersionUID = 2305345286999701156L; - - static final Object TYPE = new Object(); - - /** - * Description of the change to the source observable value. Listeners must - * not change this field. - */ - public ValueDiff diff; - - /** - * Flag for vetoing this change. Default value is <code>false</code>, can - * be set to <code>true</code> by listeners to veto this change. - */ - public boolean veto = false; - - /** - * Creates a new value changing event. - * - * @param source - * the source observable value - * @param diff - * the value change - */ - public ValueChangingEvent(IObservableValue source, ValueDiff diff) { - super(source); - this.diff = diff; - } - - /** - * @return the observable value from which this event originated - */ - public IObservableValue getObservableValue() { - return (IObservableValue) source; - } - - protected void dispatch(IObservablesListener listener) { - ((IValueChangingListener) listener).handleValueChanging(this); - } - - protected Object getListenerType() { - return TYPE; - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/ValueDiff.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/ValueDiff.java deleted file mode 100644 index 62a2f866..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/ValueDiff.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.value; - -import org.eclipse.core.databinding.observable.Diffs; - -/** - * @since 1.0 - * - */ -public abstract class ValueDiff { - /** - * Creates a value diff. - */ - public ValueDiff() { - } - - /** - * @return the old value - */ - public abstract Object getOldValue(); - - /** - * @return the new value - */ - public abstract Object getNewValue(); - - public boolean equals(Object obj) { - if (obj instanceof ValueDiff) { - ValueDiff val = (ValueDiff) obj; - - return Diffs.equals(val.getNewValue(), getNewValue()) - && Diffs.equals(val.getOldValue(), getOldValue()); - - } - return false; - } - - public int hashCode() { - final int prime = 31; - int result = 1; - Object nv = getNewValue(); - Object ov = getOldValue(); - result = prime * result + ((nv == null) ? 0 : nv.hashCode()); - result = prime * result + ((ov == null) ? 0 : ov.hashCode()); - return result; - } - - /** - * @see java.lang.Object#toString() - */ - public String toString() { - StringBuffer buffer = new StringBuffer(); - buffer - .append(getClass().getName()) - .append("{oldValue [") //$NON-NLS-1$ - .append(getOldValue() != null ? getOldValue().toString() : "null") //$NON-NLS-1$ - .append("], newValue [") //$NON-NLS-1$ - .append(getNewValue() != null ? getNewValue().toString() : "null") //$NON-NLS-1$ - .append("]}"); //$NON-NLS-1$ - - return buffer.toString(); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/WritableValue.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/WritableValue.java deleted file mode 100644 index 5d794f1a..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/WritableValue.java +++ /dev/null @@ -1,113 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 158687 - * Brad Reynolds - bug 164653, 147515 - *******************************************************************************/ - -package org.eclipse.core.databinding.observable.value; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; - -/** - * Mutable (writable) implementation of {@link IObservableValue} that will maintain a value and fire - * change events when the value changes. - * <p> - * This class is thread safe. All state accessing methods must be invoked from - * the {@link Realm#isCurrent() current realm}. Methods for adding and removing - * listeners may be invoked from any thread. - * </p> - * @since 1.0 - */ -public class WritableValue extends AbstractObservableValue { - - private final Object valueType; - - /** - * Constructs a new instance with the default realm, a <code>null</code> - * value type, and a <code>null</code> value. - */ - public WritableValue() { - this(null, null); - } - - /** - * Constructs a new instance with the default realm. - * - * @param initialValue - * can be <code>null</code> - * @param valueType - * can be <code>null</code> - */ - public WritableValue(Object initialValue, Object valueType) { - this(Realm.getDefault(), initialValue, valueType); - } - - /** - * Constructs a new instance with the provided <code>realm</code>, a - * <code>null</code> value type, and a <code>null</code> initial value. - * - * @param realm - */ - public WritableValue(Realm realm) { - this(realm, null, null); - } - - /** - * Constructs a new instance. - * - * @param realm - * @param initialValue - * can be <code>null</code> - * @param valueType - * can be <code>null</code> - */ - public WritableValue(Realm realm, Object initialValue, Object valueType) { - super(realm); - this.valueType = valueType; - this.value = initialValue; - } - - private Object value = null; - - public Object doGetValue() { - return value; - } - - /** - * @param value - * The value to set. - */ - public void doSetValue(Object value) { - boolean changed = false; - - if (this.value == null && value != null) { - changed = true; - } else if (this.value != null && !this.value.equals(value)) { - changed = true; - } - - if (changed) { - fireValueChange(Diffs.createValueDiff(this.value, this.value = value)); - } - } - - public Object getValueType() { - return valueType; - } - - /** - * @param elementType can be <code>null</code> - * @return new instance with the default realm and a value of <code>null</code> - */ - public static WritableValue withValueType(Object elementType) { - return new WritableValue(Realm.getDefault(), null, elementType); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/package.html b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/package.html deleted file mode 100644 index 4ce13df5..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/package.html +++ /dev/null @@ -1,16 +0,0 @@ -<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> - <meta name="Author" content="IBM"> - <meta name="GENERATOR" content="Mozilla/4.5 [en] (Win98; I) [Netscape]"> - <title>Package-level Javadoc</title> -</head> -<body> -Provides classes that can be used to observe changes in discrete values. -<h2> -Package Specification</h2> -<p> -This package provides classes that can be used to observe changes in discrete values.</p> -</body> -</html> diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/package.html b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/package.html deleted file mode 100644 index 9087bbfb..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/package.html +++ /dev/null @@ -1,42 +0,0 @@ -<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> - <meta name="Author" content="IBM"> - <meta name="GENERATOR" content="Mozilla/4.5 [en] (Win98; I) [Netscape]"> - <title>Package-level Javadoc</title> -</head> -<body> -Provides classes for binding observable objects, for example UI widgets and model objects. -<h2> -Package Specification</h2> -<p> -This package provides classes that can be used to synchronize state between pairs of -observable objects with optional data type conversion and validation. -<p> -A <tt>DataBindingContext</tt> is used to manage a list of <tt>Bindings</tt> -with their validation results. -</p> -<p> -Concrete subclasses of <tt>Binding</tt> synchronize state between two observables, -called the target observable and the model observable. Usually, the binding will -first copy the current state of the model observable to the target observable and -from then on track changes on both sides, reacting to changes on one side by -performing the corresponding change on the other side. -</p> -<p> -For each binding, two <tt>UpdateValueStrategy</tt> or <tt>UpdateListStrategy</tt> objects (one -for each direction) is used to control how the binding should synchronize, and can be used to -specify data type converters and validators. -</p> -<p> -<tt>AggregateValidationStatus</tt> allows clients to aggregate the current validation -statuses of a list of bindings, typically obtained from a data binding context. -</p> -<p> -For advanced validation, conversion, or similar requirements that affect the way -state is copied from one side to the other, subclasses of <tt>UpdateValueStrategy</tt> -or <tt>UpdateListStrategy</tt> can be created. -</p> -</body> -</html> diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/util/ILogger.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/util/ILogger.java deleted file mode 100644 index 652d7193..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/util/ILogger.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Chris Gross (schtoo@schtoo.com) - initial API and implementation - * (bug 49497 [RCP] JFace dependency on org.eclipse.core.runtime enlarges standalone JFace applications) - *******************************************************************************/ - -package org.eclipse.core.databinding.util; - -import org.eclipse.core.runtime.IStatus; - -/** - * A mechanism to log errors throughout JFace Data Binding. - * <p> - * Clients may provide their own implementation to change how errors are logged - * from within JFace Data Binding. - * </p> - * - * @see Policy#getLog() - * @see Policy#setLog(ILogger) - * @since 1.1 - */ -public interface ILogger { - - /** - * Logs the given status. - * - * @param status - * the status to log - */ - public void log(IStatus status); - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/util/Policy.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/util/Policy.java deleted file mode 100644 index 45467ba2..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/util/Policy.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Chris Gross (schtoo@schtoo.com) - support for ILogger added - * (bug 49497 [RCP] JFace dependency on org.eclipse.core.runtime enlarges standalone JFace applications) - * Brad Reynolds - bug 164653 - * Tom Schindl <tom.schindl@bestsolution.at> - bug 194587 - *******************************************************************************/ -package org.eclipse.core.databinding.util; - -import org.eclipse.core.runtime.IStatus; - -/** - * The Policy class handles settings for behaviour, debug flags and logging - * within JFace Data Binding. - * - * @since 1.1 - */ -public class Policy { - - /** - * Constant for the the default setting for debug options. - */ - public static final boolean DEFAULT = false; - - /** - * The unique identifier of the JFace plug-in. - */ - public static final String JFACE_DATABINDING = "org.eclipse.core.databinding";//$NON-NLS-1$ - - private static ILogger log; - - /** - * Returns the dummy log to use if none has been set - */ - private static ILogger getDummyLog() { - return new ILogger() { - public void log(IStatus status) { - System.err.println(status.getPlugin() + " - " + status.getCode() + " - " + status.getMessage()); //$NON-NLS-1$//$NON-NLS-2$ - if( status.getException() != null ) { - status.getException().printStackTrace(System.err); - } - } - }; - } - - /** - * Sets the logger used by JFace Data Binding to log errors. - * - * @param logger - * the logger to use, or <code>null</code> to use the default - * logger - */ - public static synchronized void setLog(ILogger logger) { - log = logger; - } - - /** - * Returns the logger used by JFace Data Binding to log errors. - * <p> - * The default logger prints the status to <code>System.err</code>. - * </p> - * - * @return the logger - */ - public static synchronized ILogger getLog() { - if (log == null) { - log = getDummyLog(); - } - return log; - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/util/package.html b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/util/package.html deleted file mode 100644 index 0b186a7b..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/util/package.html +++ /dev/null @@ -1,16 +0,0 @@ -<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> - <meta name="Author" content="IBM"> - <meta name="GENERATOR" content="Mozilla/4.5 [en] (Win98; I) [Netscape]"> - <title>Package-level Javadoc</title> -</head> -<body> -Provides general utilities for data binding. -<h2> -Package Specification</h2> -<p> -This package provides general utilities for data binding.</p> -</body> -</html> diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/IValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/IValidator.java deleted file mode 100644 index a9c4b8b1..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/IValidator.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.core.databinding.validation; - -import org.eclipse.core.runtime.IStatus; - -/** - * A validator. This validator is responsible for determining if a given value - * is valid. Validators can be used on target or model values. For example, a - * String2IntValidator would only accept source Strings that can successfully be - * converted to an integer value, and a PositiveIntegerValidator would only - * accept positive integers. - * - * @since 1.0 - * - */ -public interface IValidator { - - /** - * Determines if the given value is valid. - * - * @param value - * the value to validate - * @return a status object indicating whether the validation succeeded - * {@link IStatus#isOK()} or not. Never null. - */ - public IStatus validate(Object value); - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/MultiValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/MultiValidator.java deleted file mode 100644 index 91e24b58..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/MultiValidator.java +++ /dev/null @@ -1,397 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 218269) - * Boris Bokowski - bug 218269 - * Matthew Hall - bug 237884 - ******************************************************************************/ - -package org.eclipse.core.databinding.validation; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.core.databinding.ValidationStatusProvider; -import org.eclipse.core.databinding.observable.ChangeEvent; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.Observables; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IListChangeListener; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.ListChangeEvent; -import org.eclipse.core.databinding.observable.list.ListDiffVisitor; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.internal.databinding.observable.ValidatedObservableList; -import org.eclipse.core.internal.databinding.observable.ValidatedObservableMap; -import org.eclipse.core.internal.databinding.observable.ValidatedObservableSet; -import org.eclipse.core.internal.databinding.observable.ValidatedObservableValue; -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.IStatus; - -/** - * A validator for cross-constraints between observables. - * - * <p> - * Some practical examples of cross-constraints: - * <ul> - * <li>A start date cannot be later than an end date - * <li>A list of percentages should add up to 100% - * </ul> - * <p> - * Example: require two integer fields to contain either both even or both odd - * numbers. - * - * <pre> - * DataBindingContext dbc = new DataBindingContext(); - * - * IObservableValue target0 = SWTObservables.observeText(text0, SWT.Modify); - * IObservableValue target1 = SWTObservables.observeText(text1, SWT.Modify); - * - * // Binding in two stages (from target to middle, then from middle to model) - * // simplifies the validation logic. Using the middle observables saves - * // the trouble of converting the target values (Strings) to the model type - * // (integers) manually during validation. - * final IObservableValue middle0 = new WritableValue(null, Integer.TYPE); - * final IObservableValue middle1 = new WritableValue(null, Integer.TYPE); - * dbc.bind(target0, middle0, null, null); - * dbc.bind(target1, middle1, null, null); - * - * // Create the multi-validator - * MultiValidator validator = new MultiValidator() { - * protected IStatus validate() { - * // Calculate the validation status - * Integer value0 = (Integer) middle0.getValue(); - * Integer value1 = (Integer) middle1.getValue(); - * if (Math.abs(value0.intValue()) % 2 != Math.abs(value1.intValue()) % 2) - * return ValidationStatus - * .error("Values must be both even or both odd"); - * return ValidationStatus.ok(); - * } - * }; - * dbc.addValidationStatusProvider(validator); - * - * // Bind the middle observables to the model observables. - * IObservableValue model0 = new WritableValue(new Integer(2), Integer.TYPE); - * IObservableValue model1 = new WritableValue(new Integer(4), Integer.TYPE); - * dbc.bind(middle0, model0, null, null); - * dbc.bind(middle1, model1, null, null); - * </pre> - * - * <p> - * MultiValidator can also prevent invalid data from being copied to model. This - * is done by wrapping each target observable in a validated observable, and - * then binding the validated observable to the model. - * - * <pre> - * - * ... - * - * // Validated observables do not change value until the validator passes. - * IObservableValue validated0 = validator.observeValidatedValue(middle0); - * IObservableValue validated1 = validator.observeValidatedValue(middle1); - * IObservableValue model0 = new WritableValue(new Integer(2), Integer.TYPE); - * IObservableValue model1 = new WritableValue(new Integer(4), Integer.TYPE); - * // Bind to the validated value, not the middle/target - * dbc.bind(validated0, model0, null, null); - * dbc.bind(validated1, model1, null, null); - * </pre> - * - * Note: No guarantee is made as to the order of updates when multiple validated - * observables change value at once (i.e. multiple updates pending when the - * status becomes valid). Therefore the model may be in an invalid state after - * the first but before the last pending update. - * - * @since 1.1 - */ -public abstract class MultiValidator extends ValidationStatusProvider { - private Realm realm; - private IObservableValue validationStatus; - private IObservableValue unmodifiableValidationStatus; - private WritableList targets; - private IObservableList unmodifiableTargets; - private IObservableList models; - - IListChangeListener targetsListener = new IListChangeListener() { - public void handleListChange(ListChangeEvent event) { - event.diff.accept(new ListDiffVisitor() { - public void handleAdd(int index, Object element) { - ((IObservable) element) - .addChangeListener(dependencyListener); - } - - public void handleRemove(int index, Object element) { - ((IObservable) element) - .removeChangeListener(dependencyListener); - } - }); - } - }; - - private IChangeListener dependencyListener = new IChangeListener() { - public void handleChange(ChangeEvent event) { - revalidate(); - } - }; - - /** - * Constructs a MultiValidator on the default realm. - */ - public MultiValidator() { - this(Realm.getDefault()); - } - - /** - * Constructs a MultiValidator on the given realm. - * - * @param realm - * the realm on which validation takes place. - */ - public MultiValidator(Realm realm) { - Assert.isNotNull(realm, "Realm cannot be null"); //$NON-NLS-1$ - this.realm = realm; - - validationStatus = new WritableValue(realm, ValidationStatus.ok(), - IStatus.class); - - targets = new WritableList(realm, new ArrayList(), IObservable.class); - targets.addListChangeListener(targetsListener); - unmodifiableTargets = Observables.unmodifiableObservableList(targets); - - models = Observables.emptyObservableList(realm); - } - - private void checkObservable(IObservable target) { - Assert.isNotNull(target, "Target observable cannot be null"); //$NON-NLS-1$ - Assert - .isTrue(realm.equals(target.getRealm()), - "Target observable must be in the same realm as MultiValidator"); //$NON-NLS-1$ - } - - /** - * Returns an {@link IObservableValue} whose value is always the current - * validation status of this MultiValidator. The returned observable is in - * the same realm as this MultiValidator. - * - * @return an {@link IObservableValue} whose value is always the current - * validation status of this MultiValidator. - */ - public IObservableValue getValidationStatus() { - if (unmodifiableValidationStatus == null) { - revalidate(); - unmodifiableValidationStatus = Observables - .unmodifiableObservableValue(validationStatus); - } - return unmodifiableValidationStatus; - } - - private void revalidate() { - final IObservable[] dependencies = ObservableTracker.runAndMonitor( - new Runnable() { - public void run() { - try { - IStatus status = validate(); - if (status == null) - status = ValidationStatus.ok(); - validationStatus.setValue(status); - } catch (RuntimeException e) { - // Usually an NPE as dependencies are - // init'ed - validationStatus.setValue(ValidationStatus.error(e - .getMessage(), e)); - } - } - }, null, null); - ObservableTracker.runAndIgnore(new Runnable() { - public void run() { - List newTargets = new ArrayList(Arrays.asList(dependencies)); - targets.retainAll(newTargets); - newTargets.removeAll(targets); - - // Prevent dependency loop - newTargets.remove(validationStatus); - newTargets.remove(unmodifiableValidationStatus); - newTargets.remove(targets); - newTargets.remove(unmodifiableTargets); - newTargets.remove(models); - - targets.addAll(newTargets); - } - }); - } - - /** - * Return the current validation status. - * <p> - * Note: To ensure that the validation status is kept current, all - * dependencies used to calculate status should be accessed through - * {@link IObservable} instances. Each dependency observable must be in the - * same realm as the MultiValidator. - * - * @return the current validation status. - */ - protected abstract IStatus validate(); - - /** - * Returns a wrapper {@link IObservableValue} which stays in sync with the - * given target observable only when the validation status is valid. - * Statuses of {@link IStatus#OK OK}, {@link IStatus#INFO INFO} or - * {@link IStatus#WARNING WARNING} severity are considered valid. - * <p> - * The wrapper behaves as follows with respect to the validation status: - * <ul> - * <li>While valid, the wrapper stays in sync with its target observable. - * <li>While invalid, the wrapper's value is the target observable's last - * valid value. If the target changes value, a stale event is fired - * signaling that a change is pending. - * <li>When status changes from invalid to valid, the wrapper takes the - * value of the target observable, and synchronization resumes. - * </ul> - * - * @param target - * the target observable being wrapped. Must be in the same realm - * as the MultiValidator. - * @return an IObservableValue which stays in sync with the given target - * observable only with the validation status is valid. - */ - public IObservableValue observeValidatedValue(IObservableValue target) { - checkObservable(target); - return new ValidatedObservableValue(target, getValidationStatus()); - } - - /** - * Returns a wrapper {@link IObservableList} which stays in sync with the - * given target observable only when the validation status is valid. - * Statuses of {@link IStatus#OK OK}, {@link IStatus#INFO INFO} or - * {@link IStatus#WARNING WARNING} severity are considered valid. - * <p> - * The wrapper behaves as follows with respect to the validation status: - * <ul> - * <li>While valid, the wrapper stays in sync with its target observable. - * <li>While invalid, the wrapper's elements are the target observable's - * last valid elements. If the target changes elements, a stale event is - * fired signaling that a change is pending. - * <li>When status changes from invalid to valid, the wrapper takes the - * elements of the target observable, and synchronization resumes. - * </ul> - * - * @param target - * the target observable being wrapped. Must be in the same realm - * as the MultiValidator. - * @return an IObservableValue which stays in sync with the given target - * observable only with the validation status is valid. - */ - public IObservableList observeValidatedList(IObservableList target) { - checkObservable(target); - return new ValidatedObservableList(target, getValidationStatus()); - } - - /** - * Returns a wrapper {@link IObservableSet} which stays in sync with the - * given target observable only when the validation status is valid. - * Statuses of {@link IStatus#OK OK}, {@link IStatus#INFO INFO} or - * {@link IStatus#WARNING WARNING} severity are considered valid. - * <p> - * The wrapper behaves as follows with respect to the validation status: - * <ul> - * <li>While valid, the wrapper stays in sync with its target observable. - * <li>While invalid, the wrapper's elements are the target observable's - * last valid elements. If the target changes elements, a stale event is - * fired signaling that a change is pending. - * <li>When status changes from invalid to valid, the wrapper takes the - * elements of the target observable, and synchronization resumes. - * </ul> - * - * @param target - * the target observable being wrapped. Must be in the same realm - * as the MultiValidator. - * @return an IObservableValue which stays in sync with the given target - * observable only with the validation status is valid. - */ - public IObservableSet observeValidatedSet(IObservableSet target) { - checkObservable(target); - return new ValidatedObservableSet(target, getValidationStatus()); - } - - /** - * Returns a wrapper {@link IObservableMap} which stays in sync with the - * given target observable only when the validation status is valid. - * Statuses of {@link IStatus#OK OK}, {@link IStatus#INFO INFO} or - * {@link IStatus#WARNING WARNING} severity are considered valid. - * <p> - * The wrapper behaves as follows with respect to the validation status: - * <ul> - * <li>While valid, the wrapper stays in sync with its target observable. - * <li>While invalid, the wrapper's entries are the target observable's - * last valid entries. If the target changes entries, a stale event is fired - * signaling that a change is pending. - * <li>When status changes from invalid to valid, the wrapper takes the - * entries of the target observable, and synchronization resumes. - * </ul> - * - * @param target - * the target observable being wrapped. Must be in the same realm - * as the MultiValidator. - * @return an IObservableValue which stays in sync with the given target - * observable only with the validation status is valid. - */ - public IObservableMap observeValidatedMap(IObservableMap target) { - checkObservable(target); - return new ValidatedObservableMap(target, getValidationStatus()); - } - - public IObservableList getTargets() { - return unmodifiableTargets; - } - - public IObservableList getModels() { - return models; - } - - public void dispose() { - if (targets != null) { - targets.clear(); // Remove listeners from dependencies - } - - if (unmodifiableValidationStatus != null) { - unmodifiableValidationStatus.dispose(); - unmodifiableValidationStatus = null; - } - - if (validationStatus != null) { - validationStatus.dispose(); - validationStatus = null; - } - - if (unmodifiableTargets != null) { - unmodifiableTargets.dispose(); - unmodifiableTargets = null; - } - - if (targets != null) { - targets.dispose(); - targets = null; - } - - if (models != null) { - models.dispose(); - models = null; - } - - realm = null; - - super.dispose(); - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/ValidationStatus.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/ValidationStatus.java deleted file mode 100644 index d61cb196..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/ValidationStatus.java +++ /dev/null @@ -1,157 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164134 - *******************************************************************************/ -package org.eclipse.core.databinding.validation; - -import org.eclipse.core.databinding.util.Policy; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; - -/** - * Convenience class for creating status objects. - * - * @since 3.3 - * - */ -public class ValidationStatus extends Status { - - /** - * Creates a new validation status with the given severity, message, and - * exception. - * - * @param severity - * @param message - * @param exception - */ - private ValidationStatus(int severity, String message, Throwable exception) { - super(severity, Policy.JFACE_DATABINDING, IStatus.OK, message, exception); - } - - /** - * Creates a new validation status with the given severity and message. - * - * @param severity - * @param message - */ - private ValidationStatus(int severity, String message) { - super(severity, Policy.JFACE_DATABINDING,IStatus.OK, message, null); - } - - /** - * Creates a new validation error status with the given message. - * - * @param message - * @return a new error status with the given message - */ - public static IStatus error(String message) { - return new ValidationStatus(IStatus.ERROR, message); - } - - /** - * Creates a new validation cancel status with the given message. - * - * @param message - * @return a new cancel status with the given message - */ - public static IStatus cancel(String message) { - return new ValidationStatus(IStatus.CANCEL, message); - } - - /** - * Creates a new validation error status with the given message and - * exception. - * - * @param message - * @param exception - * @return a new error status with the given message and exception - */ - public static IStatus error(String message, Throwable exception) { - return new ValidationStatus(IStatus.ERROR, message, exception); - } - - /** - * Creates a new validation warning status with the given message. - * - * @param message - * @return a new warning status with the given message - */ - public static IStatus warning(String message) { - return new ValidationStatus(IStatus.WARNING, message); - } - - /** - * Creates a new validation info status with the given message. - * - * @param message - * @return a new info status with the given message - */ - public static IStatus info(String message) { - return new ValidationStatus(IStatus.INFO, message); - } - - /** - * Returns an OK status. - * - * @return an ok status - */ - public static IStatus ok() { - return Status.OK_STATUS; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ - public int hashCode() { - final int prime = 31; - int result = 1; - - String message = getMessage(); - int severity = getSeverity(); - Throwable throwable = getException(); - - result = prime * result + ((message == null) ? 0 : message.hashCode()); - result = prime * result + severity; - result = prime * result - + ((throwable == null) ? 0 : throwable.hashCode()); - return result; - } - - /** - * Equality is based upon instance equality rather than identity. - * - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - final ValidationStatus other = (ValidationStatus) obj; - - if (getSeverity() != other.getSeverity()) - return false; - if (getMessage() == null) { - if (other.getMessage() != null) - return false; - } else if (!getMessage().equals(other.getMessage())) - return false; - if (getException() == null) { - if (other.getException() != null) - return false; - } else if (!getException().equals(other.getException())) - return false; - return true; - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/package.html b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/package.html deleted file mode 100644 index 3d98b2e4..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/package.html +++ /dev/null @@ -1,16 +0,0 @@ -<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> - <meta name="Author" content="IBM"> - <meta name="GENERATOR" content="Mozilla/4.5 [en] (Win98; I) [Netscape]"> - <title>Package-level Javadoc</title> -</head> -<body> -Provides the core APIs for validation. -<h2> -Package Specification</h2> -<p> -This package provides the core APIs for validation.</p> -</body> -</html> diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/Activator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/Activator.java deleted file mode 100644 index 29db9100..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/Activator.java +++ /dev/null @@ -1,102 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Tom Schindl 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: - * Tom Schindl - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding; - -import java.util.ArrayList; - -import org.eclipse.core.databinding.util.ILogger; -import org.eclipse.core.databinding.util.Policy; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.osgi.framework.log.FrameworkLog; -import org.eclipse.osgi.framework.log.FrameworkLogEntry; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.util.tracker.ServiceTracker; - -/** - * @since 3.3 - * - */ -public class Activator implements BundleActivator { - /** - * The plug-in ID - */ - public static final String PLUGIN_ID = "org.eclipse.core.databinding"; //$NON-NLS-1$ - - private volatile static ServiceTracker _frameworkLogTracker; - - /** - * The constructor - */ - public Activator() { - } - - public void start(BundleContext context) throws Exception { - _frameworkLogTracker = new ServiceTracker(context, FrameworkLog.class.getName(), null); - _frameworkLogTracker.open(); - - Policy.setLog(new ILogger() { - - public void log(IStatus status) { - ServiceTracker frameworkLogTracker = _frameworkLogTracker; - FrameworkLog log = frameworkLogTracker == null ? null : (FrameworkLog) frameworkLogTracker.getService(); - if (log != null) { - log.log(createLogEntry(status)); - } else { - // fall back to System.err - System.err.println(status.getPlugin() + " - " + status.getCode() + " - " + status.getMessage()); //$NON-NLS-1$//$NON-NLS-2$ - if( status.getException() != null ) { - status.getException().printStackTrace(System.err); - } - } - } - - }); - } - - // Code copied from PlatformLogWriter.getLog(). Why is logging an IStatus so - // hard? - FrameworkLogEntry createLogEntry(IStatus status) { - Throwable t = status.getException(); - ArrayList childlist = new ArrayList(); - - int stackCode = t instanceof CoreException ? 1 : 0; - // ensure a substatus inside a CoreException is properly logged - if (stackCode == 1) { - IStatus coreStatus = ((CoreException) t).getStatus(); - if (coreStatus != null) { - childlist.add(createLogEntry(coreStatus)); - } - } - - if (status.isMultiStatus()) { - IStatus[] children = status.getChildren(); - for (int i = 0; i < children.length; i++) { - childlist.add(createLogEntry(children[i])); - } - } - - FrameworkLogEntry[] children = (FrameworkLogEntry[]) (childlist.size() == 0 ? null : childlist.toArray(new FrameworkLogEntry[childlist.size()])); - - return new FrameworkLogEntry(status.getPlugin(), status.getSeverity(), status.getCode(), status.getMessage(), stackCode, t, children); - } - - - public void stop(BundleContext context) throws Exception { - if (_frameworkLogTracker != null) { - _frameworkLogTracker.close(); - _frameworkLogTracker = null; - } - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/BindingMessages.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/BindingMessages.java deleted file mode 100644 index 3e93df2f..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/BindingMessages.java +++ /dev/null @@ -1,143 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Tom Schindl<tom.schindl@bestsolution.at> - bugfix for 217940 - *******************************************************************************/ -package org.eclipse.core.internal.databinding; - -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -import com.ibm.icu.text.MessageFormat; - -/** - * @since 1.0 - * - */ -public class BindingMessages { - - /** - * The Binding resource bundle; eagerly initialized. - */ - private static final ResourceBundle bundle = ResourceBundle - .getBundle("org.eclipse.core.internal.databinding.messages"); //$NON-NLS-1$ - - /** - * Key to be used for an index out of range message. - */ - public static final String INDEX_OUT_OF_RANGE = "IndexOutOfRange"; //$NON-NLS-1$ - - /** - * Key to be used for a "Multiple Problems." message. - */ - public static final String MULTIPLE_PROBLEMS = "MultipleProblems"; //$NON-NLS-1$ - - /** - * Key to be used for a "ValueBinding_ErrorWhileSettingValue" message - */ - public static final String VALUEBINDING_ERROR_WHILE_SETTING_VALUE = "ValueBinding_ErrorWhileSettingValue"; //$NON-NLS-1$ - - /** - * Key to be used for a "DateFormat_DateTime" message - */ - public static final String DATE_FORMAT_DATE_TIME = "DateFormat_DateTime"; //$NON-NLS-1$ - - /** - * Key to be used for a "DateFormat_Time" message - */ - public static final String DATEFORMAT_TIME = "DateFormat_Time"; //$NON-NLS-1$ - - /** - * Key to be used for a "ValueDelimiter" message - */ - public static final String VALUE_DELIMITER = "ValueDelimiter"; //$NON-NLS-1$ - - /** - * Key to be used for a "TrueStringValues" message - */ - public static final String TRUE_STRING_VALUES = "TrueStringValues"; //$NON-NLS-1$ - - /** - * Key to be used for a "FalseStringValues" message - */ - public static final String FALSE_STRING_VALUES = "FalseStringValues"; //$NON-NLS-1$ - - /** - * Key to be used for a "Validate_NumberOutOfRangeError" message - */ - public static final String VALIDATE_NUMBER_OUT_OF_RANGE_ERROR = "Validate_NumberOutOfRangeError"; //$NON-NLS-1$ - - /** - * Key to be used for a "Validate_NumberParseError" message - */ - public static final String VALIDATE_NUMBER_PARSE_ERROR = "Validate_NumberParseError"; //$NON-NLS-1$ - - /** - * Key to be used for a "Validate_ConversionToPrimitive" message - */ - public static final String VALIDATE_CONVERSION_TO_PRIMITIVE = "Validate_ConversionToPrimitive"; //$NON-NLS-1$ - - /** - * Key to be used for a "Validate_ConversionFromClassToPrimitive" message - */ - public static final String VALIDATE_CONVERSION_FROM_CLASS_TO_PRIMITIVE = "Validate_ConversionFromClassToPrimitive"; //$NON-NLS-1$ - - /** - * Key to be used for a "Validate_NoChangeAllowedHelp" message - */ - public static final String VALIDATE_NO_CHANGE_ALLOWED_HELP = "Validate_NoChangeAllowedHelp"; //$NON-NLS-1$ - - /** - * Key to be used for a "Validate_CharacterHelp" message - */ - public static final String VALIDATE_CHARACTER_HELP = "Validate_CharacterHelp"; //$NON-NLS-1$ - - /** - * Key to be used for a "Examples" message - */ - public static final String EXAMPLES = "Examples"; //$NON-NLS-1$ - - /** - * Key to be used for a "Validate_NumberParseErrorNoCharacter" message - */ - public static final String VALIDATE_NUMBER_PARSE_ERROR_NO_CHARACTER = "Validate_NumberParseErrorNoCharacter"; //$NON-NLS-1$ - - /** - * Returns the resource object with the given key in the resource bundle for - * JFace Data Binding. If there isn't any value under the given key, the key - * is returned. - * - * @param key - * the resource name - * @return the string - */ - public static String getString(String key) { - try { - return bundle.getString(key); - } catch (MissingResourceException e) { - return key; - } - } - - /** - * Returns a formatted string with the given key in the resource bundle for - * JFace Data Binding. - * - * @param key - * @param arguments - * @return formatted string, the key if the key is invalid - */ - public static String formatString(String key, Object[] arguments) { - try { - return MessageFormat.format(bundle.getString(key), arguments); - } catch (MissingResourceException e) { - return key; - } - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/BindingStatus.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/BindingStatus.java deleted file mode 100644 index 025b82c4..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/BindingStatus.java +++ /dev/null @@ -1,104 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding; - -import java.util.Arrays; - -import org.eclipse.core.databinding.util.Policy; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; - -/** - * A <code>MultiStatus</code> implementation that copies that state of the - * added status to this instance if it is >= the current severity. - * - * @since 1.0 - */ -public class BindingStatus extends MultiStatus { - /** - * Constructs a new instance. - * - * @param pluginId - * @param code - * @param message - * @param exception - */ - public BindingStatus(String pluginId, int code, String message, - Throwable exception) { - super(pluginId, code, message, exception); - } - - /** - * Adds the status to the multi status. The details of the status will be - * copied to the multi status if the severity is >= the current severity. - * - * @see org.eclipse.core.runtime.MultiStatus#add(org.eclipse.core.runtime.IStatus) - */ - public void add(IStatus status) { - if (status.getSeverity() >= getSeverity()) { - setMessage((status.getMessage() != null) ? status.getMessage() : ""); //$NON-NLS-1$ - setException(status.getException()); - setPlugin(status.getPlugin()); - setCode(status.getCode()); - } - - super.add(status); - } - - /** - * Instance initialized with the following values: - * <ul> - * <li>plugin = Policy.JFACE_DATABINDING</li> - * <li>severity = 0</li> - * <li>code = 0</li> - * <li>message = ""</li> - * <li>exception = null</li> - * </ul> - * - * @return status - */ - public static BindingStatus ok() { - return new BindingStatus(Policy.JFACE_DATABINDING, 0, "", null); //$NON-NLS-1$ - } - - private static int hashCode(Object[] array) { - final int prime = 31; - if (array == null) - return 0; - int result = 1; - for (int index = 0; index < array.length; index++) { - result = prime * result - + (array[index] == null ? 0 : array[index].hashCode()); - } - return result; - } - - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + BindingStatus.hashCode(getChildren()); - return result; - } - - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - final BindingStatus other = (BindingStatus) obj; - if (!Arrays.equals(getChildren(), other.getChildren())) - return false; - return true; - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ClassLookupSupport.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ClassLookupSupport.java deleted file mode 100644 index 7b3e04ae..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ClassLookupSupport.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -/** - * @since 1.0 - * - */ -public class ClassLookupSupport { - - /* - * code copied from AdapterManager.java - */ - private static HashMap classSearchOrderLookup; - - /** - * For a given class or interface, return an array containing the given type and all its direct and indirect supertypes. - * @param type - * @return an array containing the given type and all its direct and indirect supertypes - */ - public static Class[] getTypeHierarchyFlattened(Class type) { - List classes = null; - //cache reference to lookup to protect against concurrent flush - HashMap lookup = classSearchOrderLookup; - if (lookup != null) - classes = (List) lookup.get(type); - // compute class order only if it hasn't been cached before - if (classes == null) { - classes = new ArrayList(); - computeClassOrder(type, classes); - if (lookup == null) - classSearchOrderLookup = lookup = new HashMap(); - lookup.put(type, classes); - } - return (Class[]) classes.toArray(new Class[classes.size()]); - } - - /** - * Builds and returns a table of adapters for the given adaptable type. - * The table is keyed by adapter class name. The - * value is the <b>sole<b> factory that defines that adapter. Note that - * if multiple adapters technically define the same property, only the - * first found in the search order is considered. - * - * Note that it is important to maintain a consistent class and interface - * lookup order. See the class comment for more details. - */ - private static void computeClassOrder(Class adaptable, Collection classes) { - Class clazz = adaptable; - Set seen = new HashSet(4); - while (clazz != null) { - classes.add(clazz); - computeInterfaceOrder(clazz.getInterfaces(), classes, seen); - clazz = clazz.isInterface() ? Object.class : clazz.getSuperclass(); - } - } - - private static void computeInterfaceOrder(Class[] interfaces, Collection classes, Set seen) { - List newInterfaces = new ArrayList(interfaces.length); - for (int i = 0; i < interfaces.length; i++) { - Class interfac = interfaces[i]; - if (seen.add(interfac)) { - //note we cannot recurse here without changing the resulting interface order - classes.add(interfac); - newInterfaces.add(interfac); - } - } - for (Iterator it = newInterfaces.iterator(); it.hasNext();) - computeInterfaceOrder(((Class) it.next()).getInterfaces(), classes, seen); - } - - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/IdentityWrapper.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/IdentityWrapper.java deleted file mode 100644 index 978c9962..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/IdentityWrapper.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Daniel Kruegler - bug 137435 - ******************************************************************************/ - -package org.eclipse.core.internal.databinding; - -/** - * Used for wrapping objects that define their own implementations of equals() - * and hashCode() when putting them in sets or hashmaps to ensure identity - * comparison. - * - * @since 1.0 - * - */ -public class IdentityWrapper { - final Object o; - - /** - * @param o - */ - public IdentityWrapper(Object o) { - this.o = o; - } - - /** - * @return the unwrapped object - */ - public Object unwrap() { - return o; - } - - public boolean equals(Object obj) { - if (obj == null || obj.getClass() != IdentityWrapper.class) { - return false; - } - return o == ((IdentityWrapper) obj).o; - } - - public int hashCode() { - return System.identityHashCode(o); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/Pair.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/Pair.java deleted file mode 100644 index aebed881..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/Pair.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.core.internal.databinding; - -/** - * Class Pair. Represents a mathematical pair of objects (a, b). - * @since 1.0 - */ -public class Pair { - - /** - * a in the pair (a, b) - */ - public final Object a; - - /** - * b in the pair (a, b) - */ - public final Object b; - - /** - * Construct a Pair(a, b) - * - * @param a a in the pair (a, b) - * @param b b in the pair (a, b) - */ - public Pair(Object a, Object b) { - this.a = a; - this.b = b; - } - - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((a == null) ? 0 : a.hashCode()); - result = prime * result + ((b == null) ? 0 : b.hashCode()); - return result; - } - - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Pair other = (Pair) obj; - if (a == null) { - if (other.a != null) - return false; - } else if (!a.equals(other.a)) - return false; - if (b == null) { - if (other.b != null) - return false; - } else if (!b.equals(other.b)) - return false; - return true; - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/Queue.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/Queue.java deleted file mode 100644 index cb4a5070..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/Queue.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.core.internal.databinding; - -/** - * Created to avoid a dependency on java.util.LinkedList, see bug 205224. - * - * @since 1.1 - * - */ -public class Queue { - - static class Entry { - Object object; - - Entry(Object o) { - this.object = o; - } - - Entry next; - } - - Entry first; - Entry last; - - /** - * Adds the given object to the end of the queue. - * - * @param o - */ - public void enqueue(Object o) { - Entry oldLast = last; - last = new Entry(o); - if (oldLast != null) { - oldLast.next = last; - } else { - first = last; - } - } - - /** - * Returns the first object in the queue. The queue must not be empty. - * - * @return the first object - */ - public Object dequeue() { - Entry oldFirst = first; - if (oldFirst == null) { - throw new IllegalStateException(); - } - first = oldFirst.next; - if (first == null) { - last = null; - } - oldFirst.next = null; - return oldFirst.object; - } - - /** - * Returns <code>true</code> if the list is empty. - * - * @return <code>true</code> if the list is empty - */ - public boolean isEmpty() { - return first == null; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/RandomAccessListIterator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/RandomAccessListIterator.java deleted file mode 100644 index 8a560ad7..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/RandomAccessListIterator.java +++ /dev/null @@ -1,135 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 The Pampered Chef 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: - * The Pampered Chef - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding; - -import java.util.List; -import java.util.ListIterator; - -/** - * Class RandomAccessListIterator. A ListIterator implementation that also - * provides access to individual elements based on the element's index. - * - * @since 3.3 - */ -public class RandomAccessListIterator implements ListIterator { - private ListIterator delegate = null; - - /** - * @param iterator - */ - public RandomAccessListIterator(ListIterator iterator) { - this.delegate = iterator; - } - - /** - * @param list - */ - public RandomAccessListIterator(List list) { - if (list == null) { - throw new IllegalArgumentException("list is null"); //$NON-NLS-1$ - } - this.delegate = list.listIterator(); - } - - /* (non-Javadoc) - * @see java.util.ListIterator#add(java.lang.Object) - */ - public void add(Object arg0) { - delegate.add(arg0); - } - - /* (non-Javadoc) - * @see java.util.ListIterator#hasNext() - */ - public boolean hasNext() { - return delegate.hasNext(); - } - - /* (non-Javadoc) - * @see java.util.ListIterator#hasPrevious() - */ - public boolean hasPrevious() { - return delegate.hasPrevious(); - } - - /* (non-Javadoc) - * @see java.util.ListIterator#next() - */ - public Object next() { - return delegate.next(); - } - - /* (non-Javadoc) - * @see java.util.ListIterator#nextIndex() - */ - public int nextIndex() { - return delegate.nextIndex(); - } - - /* (non-Javadoc) - * @see java.util.ListIterator#previous() - */ - public Object previous() { - return delegate.previous(); - } - - /* (non-Javadoc) - * @see java.util.ListIterator#previousIndex() - */ - public int previousIndex() { - return delegate.previousIndex(); - } - - /* (non-Javadoc) - * @see java.util.ListIterator#remove() - */ - public void remove() { - delegate.remove(); - } - - /* (non-Javadoc) - * @see java.util.ListIterator#set(java.lang.Object) - */ - public void set(Object arg0) { - delegate.set(arg0); - } - - /** - * Return the element at the specified position by moving the iterator - * forward or backward in the list until it reaches the correct element. - * The iterator's position after returning the element will be one after - * the element returned. - * - * @param index The (0-based) index of the element to return. - * @return the Object at index - */ - public Object get(int index) { - if (delegate.nextIndex() == 0 && !delegate.hasNext()) { - throw new IndexOutOfBoundsException("Request for element from empty list"); //$NON-NLS-1$ - } - if (index < 0) { - throw new IndexOutOfBoundsException("Request for negative element index"); //$NON-NLS-1$ - } - - while (nextIndex() < index && hasNext()) { - next(); - } - while (previousIndex() > index-1) { - previous(); - } - if (!hasNext()) { - throw new IndexOutOfBoundsException("Request for element past end of list"); //$NON-NLS-1$ - } - return next(); - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/Util.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/Util.java deleted file mode 100644 index d0271773..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/Util.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding; - -/** - * @since 3.3 - * - */ -public class Util { - - /** - * Checks whether the two objects are <code>null</code> -- allowing for - * <code>null</code>. - * - * @param left - * The left object to compare; may be <code>null</code>. - * @param right - * The right object to compare; may be <code>null</code>. - * @return <code>true</code> if the two objects are equivalent; - * <code>false</code> otherwise. - */ - public static final boolean equals(final Object left, final Object right) { - return left == null ? right == null : ((right != null) && left - .equals(right)); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValidationStatusMap.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValidationStatusMap.java deleted file mode 100644 index 07efa93f..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValidationStatusMap.java +++ /dev/null @@ -1,159 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.internal.databinding; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.databinding.Binding; -import org.eclipse.core.databinding.observable.ChangeEvent; -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.core.databinding.observable.map.IMapChangeListener; -import org.eclipse.core.databinding.observable.map.MapDiff; -import org.eclipse.core.databinding.observable.map.ObservableMap; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.runtime.IStatus; - -/** - * @since 1.0 - * - */ -public class ValidationStatusMap extends ObservableMap { - - private boolean isDirty = true; - - private final WritableList bindings; - - private List dependencies = new ArrayList(); - - private IChangeListener markDirtyChangeListener = new IChangeListener() { - public void handleChange(ChangeEvent event) { - markDirty(); - } - }; - - /** - * @param realm - * @param bindings - */ - public ValidationStatusMap(Realm realm, WritableList bindings) { - super(realm, new HashMap()); - this.bindings = bindings; - bindings.addChangeListener(markDirtyChangeListener); - } - - protected void getterCalled() { - recompute(); - super.getterCalled(); - } - - private void markDirty() { - // since we are dirty, we don't need to listen anymore - removeElementChangeListener(); - final Map oldMap = wrappedMap; - // lazy computation of diff - MapDiff mapDiff = new MapDiff() { - private MapDiff cachedDiff = null; - - private void ensureCached() { - if (cachedDiff == null) { - recompute(); - cachedDiff = Diffs.computeMapDiff(oldMap, wrappedMap); - } - } - - public Set getAddedKeys() { - ensureCached(); - return cachedDiff.getAddedKeys(); - } - - public Set getChangedKeys() { - ensureCached(); - return cachedDiff.getChangedKeys(); - } - - public Object getNewValue(Object key) { - ensureCached(); - return cachedDiff.getNewValue(key); - } - - public Object getOldValue(Object key) { - ensureCached(); - return cachedDiff.getOldValue(key); - } - - public Set getRemovedKeys() { - ensureCached(); - return cachedDiff.getRemovedKeys(); - } - }; - wrappedMap = new HashMap(); - isDirty = true; - fireMapChange(mapDiff); - } - - private void recompute() { - if (isDirty) { - Map newContents = new HashMap(); - for (Iterator it = bindings.iterator(); it.hasNext();) { - Binding binding = (Binding) it.next(); - IObservableValue validationError = binding - .getValidationStatus(); - dependencies.add(validationError); - validationError.addChangeListener(markDirtyChangeListener); - IStatus validationStatusValue = (IStatus) validationError - .getValue(); - newContents.put(binding, validationStatusValue); - } - wrappedMap.putAll(newContents); - isDirty = false; - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.observable.list.ObservableList#dispose() - */ - public void dispose() { - bindings.removeChangeListener(markDirtyChangeListener); - removeElementChangeListener(); - super.dispose(); - } - - private void removeElementChangeListener() { - for (Iterator it = dependencies.iterator(); it.hasNext();) { - IObservableValue observableValue = (IObservableValue) it.next(); - observableValue.removeChangeListener(markDirtyChangeListener); - } - } - - public synchronized void addChangeListener(IChangeListener listener) { - // this ensures that the next change will be seen by the new listener. - recompute(); - super.addChangeListener(listener); - } - - public synchronized void addMapChangeListener(IMapChangeListener listener) { - // this ensures that the next change will be seen by the new listener. - recompute(); - super.addMapChangeListener(listener); - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/CharacterToStringConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/CharacterToStringConverter.java deleted file mode 100644 index e81091e5..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/CharacterToStringConverter.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Matt Carter 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: - * Matt Carter - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.conversion; - -import org.eclipse.core.databinding.conversion.Converter; - -/** - * Converts a character to a string. - */ -public class CharacterToStringConverter extends Converter { - private final boolean primitive; - - /** - * @param primitive - */ - private CharacterToStringConverter(boolean primitive) { - super(primitive ? Character.TYPE : Character.class, String.class); - this.primitive = primitive; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object) - */ - public Object convert(Object fromObject) { - // Null is allowed when the type is not primitive. - if (fromObject == null) { - if (primitive) - throw new IllegalArgumentException( - "'fromObject' is null. Cannot convert to primitive char."); //$NON-NLS-1$ - return ""; //$NON-NLS-1$ - } - - if (!(fromObject instanceof Character)) { - throw new IllegalArgumentException( - "'fromObject' is not of type [Character]."); //$NON-NLS-1$ - } - - return String.valueOf(((Character) fromObject).charValue()); - } - - /** - * @param primitive - * @return converter - */ - public static CharacterToStringConverter fromCharacter(boolean primitive) { - return new CharacterToStringConverter(primitive); - } - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/DateConversionSupport.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/DateConversionSupport.java deleted file mode 100755 index 0fd191f1..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/DateConversionSupport.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (C) 2005 db4objects Inc. http://www.db4o.com - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * db4objects - Initial API and implementation - * Tom Schindl<tom.schindl@bestsolution.at> - bugfix for 217940 - */ -package org.eclipse.core.internal.databinding.conversion; - -import java.text.ParsePosition; -import java.util.Date; - -import org.eclipse.core.internal.databinding.BindingMessages; - -import com.ibm.icu.text.DateFormat; -import com.ibm.icu.text.SimpleDateFormat; - -/** - * Base support for date/string conversion handling according to the default - * locale or in plain long milliseconds. - * <p> - * NOTE: parse(format(date)) will generally *not* be equal to date, since the - * string representation may not cover the sub-second range, time-only string - * representations will be counted from the beginning of the era, etc. - * </p> - */ -public abstract class DateConversionSupport { - private final static int DATE_FORMAT=DateFormat.SHORT; - private final static int DEFAULT_FORMATTER_INDEX=0; - - private final static int NUM_VIRTUAL_FORMATTERS=1; - - /** - * Alternative formatters for date, time and date/time. - * Raw milliseconds are covered as a special case. - */ - // TODO: These could be shared, but would have to be synchronized. - private DateFormat[] formatters = { - new SimpleDateFormat(BindingMessages.getString(BindingMessages.DATE_FORMAT_DATE_TIME)), - new SimpleDateFormat(BindingMessages.getString(BindingMessages.DATEFORMAT_TIME)), - DateFormat.getDateTimeInstance(DATE_FORMAT, DateFormat.SHORT), - DateFormat.getDateInstance(DATE_FORMAT), - DateFormat.getTimeInstance(DateFormat.SHORT), - DateFormat.getDateTimeInstance(DATE_FORMAT,DateFormat.MEDIUM), - DateFormat.getTimeInstance(DateFormat.MEDIUM) - }; - - /** - * Tries all available formatters to parse the given string according to the - * default locale or as a raw millisecond value and returns the result of the - * first successful run. - * - * @param str A string specifying a date according to the default locale or in raw milliseconds - * @return The parsed date, or null, if no available formatter could interpret the input string - */ - protected Date parse(String str) { - for (int formatterIdx = 0; formatterIdx < formatters.length; formatterIdx++) { - Date parsed=parse(str,formatterIdx); - if(parsed!=null) { - return parsed; - } - } - return null; - } - - protected Date parse(String str,int formatterIdx) { - if(formatterIdx>=0) { - ParsePosition pos=new ParsePosition(0); - if (str == null) { - return null; - } - Date date=formatters[formatterIdx].parse(str,pos); - if(pos.getErrorIndex()!=-1||pos.getIndex()!=str.length()) { - return null; - } - return date; - } - try { - long millisecs=Long.parseLong(str); - return new Date(millisecs); - } - catch(NumberFormatException exc) { - } - return null; - } - - /** - * Formats the given date with the default formatter according to the default locale. - * @param date a date - * @return a string representation of the given date according to the default locale - */ - protected String format(Date date) { - return format(date,DEFAULT_FORMATTER_INDEX); - } - - protected String format(Date date,int formatterIdx) { - if(formatterIdx>=0) { - return formatters[formatterIdx].format(date); - } - return String.valueOf(date.getTime()); - } - - protected int numFormatters() { - return formatters.length+NUM_VIRTUAL_FORMATTERS; - } - - /** - * Returns the date format for the provided <code>index</code>. - * <p> - * This is for testing purposes only and should not be a part of the API if - * this class was to be exposed. - * </p> - * - * @param index - * @return date format - */ - protected DateFormat getDateFormat(int index) { - if (index < 0 || index >= formatters.length) { - throw new IllegalArgumentException("'index' [" + index + "] is out of bounds."); //$NON-NLS-1$//$NON-NLS-2$ - } - - return formatters[index]; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/DateToStringConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/DateToStringConverter.java deleted file mode 100755 index 95a3e295..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/DateToStringConverter.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2005 db4objects Inc. http://www.db4o.com - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * db4objects - Initial API and implementation - */ -package org.eclipse.core.internal.databinding.conversion; - -import java.util.Date; - -import org.eclipse.core.databinding.conversion.IConverter; - - -/** - * Converts a Java.util.Date to a String using the current locale. Null date - * values are converted to an empty string. - * - * @since 1.0 - */ -public class DateToStringConverter extends DateConversionSupport implements IConverter { - public Object convert(Object source) { - if (source != null) - return format((Date)source); - return ""; //$NON-NLS-1$ - } - - public Object getFromType() { - return Date.class; - } - - public Object getToType() { - return String.class; - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/IdentityConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/IdentityConverter.java deleted file mode 100644 index 928aabab..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/IdentityConverter.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (C) 2005 db4objects Inc. http://www.db4o.com 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: - * db4objects - Initial API and implementation - * Matt Carter - Character support completed (bug 197679) - */ -package org.eclipse.core.internal.databinding.conversion; - -import org.eclipse.core.databinding.BindingException; -import org.eclipse.core.databinding.conversion.IConverter; - -/** - * TheIdentityConverter. Returns the source value (the identity function). - */ -public class IdentityConverter implements IConverter { - - private Class fromType; - - private Class toType; - - /** - * @param type - */ - public IdentityConverter(Class type) { - this.fromType = type; - this.toType = type; - } - - /** - * @param fromType - * @param toType - */ - public IdentityConverter(Class fromType, Class toType) { - this.fromType = fromType; - this.toType = toType; - } - - private Class[][] primitiveMap = new Class[][] { - { Integer.TYPE, Integer.class }, { Short.TYPE, Short.class }, - { Long.TYPE, Long.class }, { Double.TYPE, Double.class }, - { Byte.TYPE, Byte.class }, { Float.TYPE, Float.class }, - { Boolean.TYPE, Boolean.class }, - { Character.TYPE, Character.class } }; - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.binding.converter.IConverter#convert(java.lang.Object) - */ - public Object convert(Object source) { - if (toType.isPrimitive()) { - if (source == null) { - throw new BindingException("Cannot convert null to a primitive"); //$NON-NLS-1$ - } - } - if (source != null) { - Class sourceClass = source.getClass(); - if (toType.isPrimitive() || sourceClass.isPrimitive()) { - if (sourceClass.equals(toType) - || isPrimitiveTypeMatchedWithBoxed(sourceClass, toType)) { - return source; - } - throw new BindingException( - "Boxed and unboxed types do not match"); //$NON-NLS-1$ - } - if (!toType.isAssignableFrom(sourceClass)) { - throw new BindingException(sourceClass.getName() - + " is not assignable to " + toType.getName()); //$NON-NLS-1$ - } - } - return source; - } - - /** - * (Non-API) isPrimitiveTypeMatchedWithBoxed. - * - * @param sourceClass - * @param toClass - * @return true if sourceClass and toType are matched primitive/boxed types - */ - public boolean isPrimitiveTypeMatchedWithBoxed(Class sourceClass, - Class toClass) { - for (int i = 0; i < primitiveMap.length; i++) { - if (toClass.equals(primitiveMap[i][0]) - && sourceClass.equals(primitiveMap[i][1])) { - return true; - } - if (sourceClass.equals(primitiveMap[i][0]) - && toClass.equals(primitiveMap[i][1])) { - return true; - } - } - return false; - } - - public Object getFromType() { - return fromType; - } - - public Object getToType() { - return toType; - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/IntegerToStringConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/IntegerToStringConverter.java deleted file mode 100644 index c8b177c8..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/IntegerToStringConverter.java +++ /dev/null @@ -1,102 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.conversion; - -import org.eclipse.core.databinding.conversion.Converter; - -import com.ibm.icu.text.NumberFormat; - -/** - * Converts a value that is an integer, non decimal, to a String using a - * NumberFormat. - * <p> - * This class is a temporary as this ability exists in NumberToStringConverter - * except that short and byte are missing. - * </p> - * - * @since 1.0 - */ -public class IntegerToStringConverter extends Converter { - private final boolean primitive; - private final NumberFormat numberFormat; - private final Class boxedType; - - /** - * @param numberFormat - * @param fromType - * @param boxedType - */ - private IntegerToStringConverter(NumberFormat numberFormat, Class fromType, - Class boxedType) { - super(fromType, String.class); - this.primitive = fromType.isPrimitive(); - this.numberFormat = numberFormat; - this.boxedType = boxedType; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object) - */ - public Object convert(Object fromObject) { - // Null is allowed when the type is not primitve. - if (fromObject == null && !primitive) { - return ""; //$NON-NLS-1$ - } - - if (!boxedType.isInstance(fromObject)) { - throw new IllegalArgumentException( - "'fromObject' is not of type [" + boxedType + "]."); //$NON-NLS-1$//$NON-NLS-2$ - } - - return numberFormat.format(((Number) fromObject).longValue()); - } - - /** - * @param primitive - * @return converter - */ - public static IntegerToStringConverter fromShort(boolean primitive) { - return fromShort(NumberFormat.getIntegerInstance(), primitive); - } - - /** - * @param numberFormat - * @param primitive - * @return converter - */ - public static IntegerToStringConverter fromShort(NumberFormat numberFormat, - boolean primitive) { - return new IntegerToStringConverter(numberFormat, - primitive ? Short.TYPE : Short.class, Short.class); - } - - /** - * @param primitive - * @return converter - */ - public static IntegerToStringConverter fromByte(boolean primitive) { - return fromByte(NumberFormat.getIntegerInstance(), primitive); - } - - /** - * @param numberFormat - * @param primitive - * @return converter - */ - public static IntegerToStringConverter fromByte(NumberFormat numberFormat, - boolean primitive) { - return new IntegerToStringConverter(numberFormat, primitive ? Byte.TYPE - : Byte.class, Byte.class); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToBigDecimalConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToBigDecimalConverter.java deleted file mode 100644 index 2d3e38a0..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToBigDecimalConverter.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.conversion; - -import java.math.BigDecimal; -import java.math.BigInteger; - -import com.ibm.icu.text.NumberFormat; - -/** - * Converts from a Number to a BigDecimal. - * <p> - * Class is thread safe. - * </p> - * - * @since 1.0 - */ -public class NumberToBigDecimalConverter extends NumberToNumberConverter { - /** - * @param numberFormat - * @param fromType - */ - public NumberToBigDecimalConverter(NumberFormat numberFormat, Class fromType) { - super(numberFormat, fromType, BigDecimal.class); - } - - /* (non-Javadoc) - * @see org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter#doConvert(java.lang.Number) - */ - protected Number doConvert(Number number) { - if (number instanceof BigInteger) { - return new BigDecimal((BigInteger) number); - } - - return new BigDecimal(number.doubleValue()); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToBigIntegerConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToBigIntegerConverter.java deleted file mode 100644 index 23f4261a..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToBigIntegerConverter.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.conversion; - -import java.math.BigDecimal; -import java.math.BigInteger; - -import com.ibm.icu.text.NumberFormat; - -/** - * Converts from a Number to a BigInteger. - * <p> - * Class is thread safe. - * </p> - * - * @since 1.0 - */ -public class NumberToBigIntegerConverter extends NumberToNumberConverter { - /** - * @param numberFormat - * @param fromType - */ - public NumberToBigIntegerConverter(NumberFormat numberFormat, Class fromType) { - super(numberFormat, fromType, BigInteger.class); - } - - /* (non-Javadoc) - * @see org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter#doConvert(java.lang.Number) - */ - protected Number doConvert(Number number) { - return toBigDecimal(number).toBigInteger(); - } - - private static BigDecimal toBigDecimal(Number number) { - if (number instanceof BigDecimal) { - return (BigDecimal) number; - } - - return new BigDecimal(number.doubleValue()); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToByteConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToByteConverter.java deleted file mode 100644 index 88bf643a..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToByteConverter.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.conversion; - -import com.ibm.icu.text.NumberFormat; - -/** - * Converts from a Number to a Byte. - * <p> - * Class is thread safe. - * </p> - * - * @since 1.0 - */ -public class NumberToByteConverter extends NumberToNumberConverter { - /** - * @param numberFormat - * @param fromType - * @param primitive - */ - public NumberToByteConverter(NumberFormat numberFormat, Class fromType, - boolean primitive) { - super(numberFormat, fromType, (primitive) ? Byte.TYPE : Byte.class); - } - - /* (non-Javadoc) - * @see org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter#doConvert(java.lang.Number) - */ - protected Number doConvert(Number number) { - if (StringToNumberParser.inByteRange(number)) { - return new Byte(number.byteValue()); - } - - return null; - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToDoubleConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToDoubleConverter.java deleted file mode 100644 index 4e30390a..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToDoubleConverter.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.conversion; - -import com.ibm.icu.text.NumberFormat; - -/** - * Converts from a Number to a Double. - * <p> - * Class is thread safe. - * </p> - * - * @since 1.0 - */ -public class NumberToDoubleConverter extends NumberToNumberConverter { - - /** - * @param numberFormat - * @param fromType - * @param primitive - */ - public NumberToDoubleConverter(NumberFormat numberFormat, Class fromType, - boolean primitive) { - super(numberFormat, fromType, (primitive) ? Double.TYPE : Double.class); - } - - /* (non-Javadoc) - * @see org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter#doConvert(java.lang.Number) - */ - protected Number doConvert(Number number) { - if (StringToNumberParser.inDoubleRange(number)) { - return new Double(number.doubleValue()); - } - - return null; - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToFloatConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToFloatConverter.java deleted file mode 100644 index 64745a57..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToFloatConverter.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.conversion; - -import com.ibm.icu.text.NumberFormat; - -/** - * Converts from a Number to a Float. - * <p> - * Class is thread safe. - * </p> - * @since 1.0 - */ -public class NumberToFloatConverter extends NumberToNumberConverter { - /** - * @param numberFormat - * @param fromType - * @param primitive - */ - public NumberToFloatConverter(NumberFormat numberFormat, Class fromType, - boolean primitive) { - super(numberFormat, fromType, (primitive) ? Float.TYPE : Float.class); - } - - /* (non-Javadoc) - * @see org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter#doConvert(java.lang.Number) - */ - protected Number doConvert(Number number) { - if (StringToNumberParser.inFloatRange(number)) { - return new Float(number.floatValue()); - } - - return null; - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToIntegerConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToIntegerConverter.java deleted file mode 100644 index fdcf23aa..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToIntegerConverter.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.conversion; - -import org.eclipse.core.databinding.conversion.IConverter; - -import com.ibm.icu.text.NumberFormat; - -/** - * Converts from a Number to a Integer. - * <p> - * Class is thread safe. - * </p> - * @since 1.0 - */ -public class NumberToIntegerConverter extends NumberToNumberConverter implements - IConverter { - - /** - * @param numberFormat - * @param fromType - * @param primitive - */ - public NumberToIntegerConverter(NumberFormat numberFormat, - Class fromType, boolean primitive) { - super(numberFormat, fromType, (primitive) ? Integer.TYPE : Integer.class); - } - - /* (non-Javadoc) - * @see org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter#doConvert(java.lang.Number) - */ - protected Number doConvert(Number number) { - if (StringToNumberParser.inIntegerRange(number)) { - return new Integer(number.intValue()); - } - - return null; - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToLongConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToLongConverter.java deleted file mode 100644 index 6addb0e8..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToLongConverter.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.conversion; - -import com.ibm.icu.text.NumberFormat; - -/** - * Converts from a Number to a Long. - * <p> - * Class is thread safe. - * </p> - * @since 1.0 - */ -public class NumberToLongConverter extends NumberToNumberConverter { - /** - * @param numberFormat - * @param fromType - * @param primitive - */ - public NumberToLongConverter(NumberFormat numberFormat, Class fromType, - boolean primitive) { - super(numberFormat, fromType, (primitive) ? Long.TYPE : Long.class); - } - - /* (non-Javadoc) - * @see org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter#doConvert(java.lang.Number) - */ - protected Number doConvert(Number number) { - if (StringToNumberParser.inLongRange(number)) { - return new Long(number.longValue()); - } - - return null; - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToNumberConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToNumberConverter.java deleted file mode 100644 index 89f763bd..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToNumberConverter.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.conversion; - -import org.eclipse.core.databinding.conversion.Converter; - -import com.ibm.icu.text.NumberFormat; - -/** - * Base class for number to number converters. - * <p> - * This class is thread safe. - * </p> - * - * @since 1.0 - */ -public abstract class NumberToNumberConverter extends Converter { - private NumberFormat numberFormat; - - private boolean primitive; - - private String outOfRangeMessage; - - protected NumberToNumberConverter(NumberFormat numberFormat, - Class fromType, Class toType) { - super(fromType, toType); - this.numberFormat = numberFormat; - this.primitive = toType.isPrimitive(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object) - */ - public final Object convert(Object fromObject) { - if (fromObject == null) { - if (primitive) { - throw new IllegalArgumentException( - "Parameter 'fromObject' cannot be null."); //$NON-NLS-1$ - } - - return null; - } - - if (!(fromObject instanceof Number)) { - throw new IllegalArgumentException( - "Parameter 'fromObject' must be of type Number."); //$NON-NLS-1$ - } - - Number number = (Number) fromObject; - Number result = doConvert(number); - - if (result != null) { - return result; - } - - synchronized (this) { - if (outOfRangeMessage == null) { - outOfRangeMessage = StringToNumberParser - .createOutOfRangeMessage(new Short(Short.MIN_VALUE), - new Short(Short.MAX_VALUE), numberFormat); - } - - throw new IllegalArgumentException(outOfRangeMessage); - } - } - - /** - * Invoked when the number should converted. - * - * @param number - * @return number if conversion was successfule, <code>null</code> if the - * number was out of range - */ - protected abstract Number doConvert(Number number); - - /** - * NumberFormat being used by the converter. Access to the format must be - * synchronized on the number format instance. - * - * @return number format - */ - public NumberFormat getNumberFormat() { - return numberFormat; - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToShortConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToShortConverter.java deleted file mode 100644 index badb8c05..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToShortConverter.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.conversion; - -import com.ibm.icu.text.NumberFormat; - -/** - * Converts from a Number to a Short. - * <p> - * Class is thread safe. - * </p> - * @since 1.0 - */ -public class NumberToShortConverter extends NumberToNumberConverter { - /** - * @param numberFormat - * @param fromType - * @param primitive - */ - public NumberToShortConverter(NumberFormat numberFormat, Class fromType, - boolean primitive) { - - super(numberFormat, fromType, (primitive) ? Short.TYPE : Short.class); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter#doConvert(java.lang.Number) - */ - protected Number doConvert(Number number) { - if (StringToNumberParser.inShortRange(number)) { - return new Short(number.shortValue()); - } - - return null; - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/ObjectToStringConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/ObjectToStringConverter.java deleted file mode 100644 index 76b69d45..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/ObjectToStringConverter.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2005 db4objects Inc. http://www.db4o.com - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * db4objects - Initial API and implementation - */ -package org.eclipse.core.internal.databinding.conversion; - -import org.eclipse.core.databinding.conversion.IConverter; - -/** - * Converts any object to a string by calling its toString() method. - */ -public class ObjectToStringConverter implements IConverter { - private final Class fromClass; - - /** - * - */ - public ObjectToStringConverter() { - this(Object.class); - } - - /** - * @param fromClass - */ - public ObjectToStringConverter(Class fromClass) { - this.fromClass = fromClass; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.binding.converter.IConverter#convert(java.lang.Object) - */ - public Object convert(Object source) { - if (source == null) { - return ""; //$NON-NLS-1$ - } - return source.toString(); - } - - public Object getFromType() { - return fromClass; - } - - public Object getToType() { - return String.class; - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StatusToStringConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StatusToStringConverter.java deleted file mode 100644 index 72d77165..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StatusToStringConverter.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.conversion; - -import org.eclipse.core.databinding.conversion.Converter; -import org.eclipse.core.databinding.conversion.IConverter; -import org.eclipse.core.runtime.IStatus; - -/** - * Converts an IStatus into a String. The message of the status is the returned value. - * - * @since 1.0 - */ -public class StatusToStringConverter extends Converter implements IConverter { - /** - * Constructs a new instance. - */ - public StatusToStringConverter() { - super(IStatus.class, String.class); - } - - /* (non-Javadoc) - * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object) - */ - public Object convert(Object fromObject) { - if (fromObject == null) { - throw new IllegalArgumentException("Parameter 'fromObject' was null."); //$NON-NLS-1$ - } - - IStatus status = (IStatus) fromObject; - return status.getMessage(); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToBooleanConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToBooleanConverter.java deleted file mode 100755 index 7f67e768..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToBooleanConverter.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2005 db4objects Inc. http://www.db4o.com - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * db4objects - Initial API and implementation - */ -package org.eclipse.core.internal.databinding.conversion; - -/** - * StringToBooleanConverter. - */ -public class StringToBooleanConverter extends StringToBooleanPrimitiveConverter { - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.binding.converter.IConverter#convert(java.lang.Object) - */ - public Object convert(Object source) { - String sourceString = (String) source; - if ("".equals(sourceString.trim())) { //$NON-NLS-1$ - return null; - } - return super.convert(source); - } - - public Object getToType() { - return Boolean.class; - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToBooleanPrimitiveConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToBooleanPrimitiveConverter.java deleted file mode 100644 index f38300d3..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToBooleanPrimitiveConverter.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (C) 2005 db4objects Inc. http://www.db4o.com - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * db4objects - Initial API and implementation - * Tom Schindl<tom.schindl@bestsolution.at> - bugfix for 217940 - */ -package org.eclipse.core.internal.databinding.conversion; - -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; -import java.util.StringTokenizer; - -import org.eclipse.core.databinding.conversion.IConverter; -import org.eclipse.core.internal.databinding.BindingMessages; - -/** - * StringToBooleanPrimitiveConverter. - */ -public class StringToBooleanPrimitiveConverter implements IConverter { - private static final String[] trueValues; - - private static final String[] falseValues; - - static { - String delimiter = BindingMessages.getString(BindingMessages.VALUE_DELIMITER); - String values = BindingMessages.getString(BindingMessages.TRUE_STRING_VALUES); - trueValues = valuesToSortedArray(delimiter, values); - - values = BindingMessages.getString(BindingMessages.FALSE_STRING_VALUES); - falseValues = valuesToSortedArray(delimiter, values); - } - - /** - * Returns a sorted array with all values converted to upper case. - * - * @param delimiter - * @param values - * @return sorted array of values - */ - private static String[] valuesToSortedArray(String delimiter, String values) { - List list = new LinkedList(); - StringTokenizer tokenizer = new StringTokenizer(values, delimiter); - while (tokenizer.hasMoreTokens()) { - list.add(tokenizer.nextToken().toUpperCase()); - } - - String[] array = (String[]) list.toArray(new String[list.size()]); - Arrays.sort(array); - - return array; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.binding.converter.IConverter#convert(java.lang.Object) - */ - public Object convert(Object source) { - String s = (String) source; - s = s.toUpperCase(); - - if (Arrays.binarySearch(trueValues, s) > -1) { - return Boolean.TRUE; - } - - if (Arrays.binarySearch(falseValues, s) > -1) { - return Boolean.FALSE; - } - - throw new IllegalArgumentException(s + " is not a legal boolean value"); //$NON-NLS-1$ - } - - public Object getFromType() { - return String.class; - } - - public Object getToType() { - return Boolean.TYPE; - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToByteConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToByteConverter.java deleted file mode 100755 index eef131d2..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToByteConverter.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (C) 2005 db4objects Inc. http://www.db4o.com - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * db4objects - Initial API and implementation - */ -package org.eclipse.core.internal.databinding.conversion; - -import org.eclipse.core.internal.databinding.conversion.StringToNumberParser.ParseResult; -import org.eclipse.core.internal.databinding.validation.NumberFormatConverter; - -import com.ibm.icu.text.NumberFormat; - -/** - * @since 1.0 - */ -public class StringToByteConverter extends NumberFormatConverter { - private String outOfRangeMessage; - private NumberFormat numberFormat; - private boolean primitive; - - /** - * @param numberFormat - * @param toType - */ - private StringToByteConverter(NumberFormat numberFormat, Class toType) { - super(String.class, toType, numberFormat); - primitive = toType.isPrimitive(); - this.numberFormat = numberFormat; - } - - /** - * @param numberFormat - * @param primitive - * @return converter - */ - public static StringToByteConverter toByte(NumberFormat numberFormat, - boolean primitive) { - return new StringToByteConverter(numberFormat, (primitive) ? Byte.TYPE : Byte.class); - } - - /** - * @param primitive - * @return converter - */ - public static StringToByteConverter toByte(boolean primitive) { - return toByte(NumberFormat.getIntegerInstance(), primitive); - } - - /* (non-Javadoc) - * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object) - */ - public Object convert(Object fromObject) { - ParseResult result = StringToNumberParser.parse(fromObject, - numberFormat, primitive); - - if (result.getPosition() != null) { - // this shouldn't happen in the pipeline as validation should catch - // it but anyone can call convert so we should return a properly - // formatted message in an exception - throw new IllegalArgumentException(StringToNumberParser - .createParseErrorMessage((String) fromObject, result - .getPosition())); - } else if (result.getNumber() == null) { - // if an error didn't occur and the number is null then it's a boxed - // type and null should be returned - return null; - } - - if (StringToNumberParser.inByteRange(result.getNumber())) { - return new Byte(result.getNumber().byteValue()); - } - - synchronized (this) { - if (outOfRangeMessage == null) { - outOfRangeMessage = StringToNumberParser - .createOutOfRangeMessage(new Byte(Byte.MIN_VALUE), new Byte(Byte.MAX_VALUE), numberFormat); - } - - throw new IllegalArgumentException(outOfRangeMessage); - } - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToCharacterConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToCharacterConverter.java deleted file mode 100644 index ce71dc7a..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToCharacterConverter.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2005 db4objects Inc. http://www.db4o.com - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * db4objects - Initial API and implementation - * Matt Carter - Improved primitive conversion support (bug 197679) - */ -package org.eclipse.core.internal.databinding.conversion; - -import org.eclipse.core.databinding.conversion.IConverter; - -/** - * StringToCharacterConverter. - */ -public class StringToCharacterConverter implements IConverter { - - private final boolean primitiveTarget; - - /** - * - * @param primitiveTarget - */ - public StringToCharacterConverter(boolean primitiveTarget) { - this.primitiveTarget = primitiveTarget; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.binding.converter.IConverter#convert(java.lang.Object) - */ - public Object convert(Object source) { - if (source != null && !(source instanceof String)) - throw new IllegalArgumentException( - "String2Character: Expected type String, got type [" + source.getClass().getName() + "]"); //$NON-NLS-1$ //$NON-NLS-2$ - - String s = (String) source; - if (source == null || s.equals("")) { //$NON-NLS-1$ - if (primitiveTarget) - throw new IllegalArgumentException( - "String2Character: cannot convert null/empty string to character primitive"); //$NON-NLS-1$ - return null; - } - Character result; - - if (s.length() > 1) - throw new IllegalArgumentException( - "String2Character: string too long: " + s); //$NON-NLS-1$ - - try { - result = new Character(s.charAt(0)); - } catch (Exception e) { - throw new IllegalArgumentException( - "String2Character: " + e.getMessage() + ": " + s); //$NON-NLS-1$ //$NON-NLS-2$ - } - - return result; - } - - public Object getFromType() { - return String.class; - } - - public Object getToType() { - return primitiveTarget ? Character.TYPE : Character.class; - } - - /** - * @param primitive - * @return converter - */ - public static StringToCharacterConverter toCharacter(boolean primitive) { - return new StringToCharacterConverter(primitive); - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToDateConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToDateConverter.java deleted file mode 100644 index 47b55cee..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToDateConverter.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2005 db4objects Inc. http://www.db4o.com - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * db4objects - Initial API and implementation - */ -package org.eclipse.core.internal.databinding.conversion; - -import java.util.Date; - -import org.eclipse.core.databinding.conversion.IConverter; - - -/** - * Convert a String to a java.util.Date, respecting the current locale - * - * @since 1.0 - */ -public class StringToDateConverter extends DateConversionSupport implements IConverter { - public Object convert(Object source) { - return parse(source.toString()); - } - - public Object getFromType() { - return String.class; - } - - public Object getToType() { - return Date.class; - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToNumberParser.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToNumberParser.java deleted file mode 100644 index 3e7eafe9..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToNumberParser.java +++ /dev/null @@ -1,311 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.internal.databinding.conversion; - -import java.math.BigDecimal; -import java.math.BigInteger; -import java.text.ParsePosition; - -import org.eclipse.core.internal.databinding.BindingMessages; - -import com.ibm.icu.text.NumberFormat; - -/** - * Utility class for the parsing of strings to numbers. - * - * @since 1.0 - */ -public class StringToNumberParser { - private static final BigDecimal FLOAT_MAX_BIG_DECIMAL = new BigDecimal( - Float.MAX_VALUE); - private static final BigDecimal FLOAT_MIN_BIG_DECIMAL = new BigDecimal( - -Float.MAX_VALUE); - - private static final BigDecimal DOUBLE_MAX_BIG_DECIMAL = new BigDecimal( - Double.MAX_VALUE); - private static final BigDecimal DOUBLE_MIN_BIG_DECIMAL = new BigDecimal( - -Double.MAX_VALUE); - - /** - * @param value - * @param numberFormat - * @param primitive - * @return result - */ - public static ParseResult parse(Object value, NumberFormat numberFormat, - boolean primitive) { - if (!(value instanceof String)) { - throw new IllegalArgumentException( - "Value to convert is not a String"); //$NON-NLS-1$ - } - - String source = (String) value; - ParseResult result = new ParseResult(); - if (!primitive && source.trim().length() == 0) { - return result; - } - - synchronized (numberFormat) { - ParsePosition position = new ParsePosition(0); - Number parseResult = null; - parseResult = numberFormat.parse(source, position); - - if (position.getIndex() != source.length() - || position.getErrorIndex() > -1) { - - result.position = position; - } else { - result.number = parseResult; - } - } - - return result; - } - - /** - * The result of a parse operation. - * - * @since 1.0 - */ - public static class ParseResult { - /* package */Number number; - /* package */ParsePosition position; - - /** - * The number as a result of the conversion. <code>null</code> if the - * value could not be converted or if the type is not a primitive and - * the value was an empty string. - * - * @return number - */ - public Number getNumber() { - return number; - } - - /** - * ParsePosition if an error occurred while parsing. <code>null</code> - * if no error occurred. - * - * @return parse position - */ - public ParsePosition getPosition() { - return position; - } - } - - /** - * Formats an appropriate message for a parsing error. - * - * @param value - * @param position - * @return message - */ - public static String createParseErrorMessage(String value, - ParsePosition position) { - int errorIndex = (position.getErrorIndex() > -1) ? position - .getErrorIndex() : position.getIndex(); - - if (errorIndex < value.length()) { - return BindingMessages.formatString(BindingMessages.VALIDATE_NUMBER_PARSE_ERROR, - new Object[] { value, new Integer(errorIndex + 1), - new Character(value.charAt(errorIndex)) }); - } - return BindingMessages.formatString(BindingMessages.VALIDATE_NUMBER_PARSE_ERROR_NO_CHARACTER, - new Object[] { value, new Integer(errorIndex + 1) }); - } - - /** - * Formats an appropriate message for an out of range error. - * - * @param minValue - * @param maxValue - * @param numberFormat when accessed method synchronizes on instance - * @return message - */ - public static String createOutOfRangeMessage(Number minValue, - Number maxValue, NumberFormat numberFormat) { - String min = null; - String max = null; - - synchronized (numberFormat) { - min = numberFormat.format(minValue); - max = numberFormat.format(maxValue); - } - - return BindingMessages.formatString( - "Validate_NumberOutOfRangeError", new Object[] { min, max }); //$NON-NLS-1$ - } - - /** - * Returns <code>true</code> if the provided <code>number</code> is in - * the range of a integer. - * - * @param number - * @return <code>true</code> if a valid integer - * @throws IllegalArgumentException - * if the number type is unsupported - */ - public static boolean inIntegerRange(Number number) { - return checkInteger(number, 31); - } - - /** - * Validates the range of the provided <code>number</code>. - * - * @param number - * @param bitLength number of bits allowed to be in range - * @return <code>true</code> if in range - */ - private static boolean checkInteger(Number number, int bitLength) { - BigInteger bigInteger = null; - - if (number instanceof Integer || number instanceof Long) { - bigInteger = BigInteger.valueOf(number.longValue()); - } else if (number instanceof Float || number instanceof Double) { - double doubleValue = number.doubleValue(); - /* - * doubleValue == doubleValue is used to check for NaN because NaN != - * NaN. The only way to check for NaN is to compare that the value - * is equal to itself. - */ - if (doubleValue == doubleValue - && doubleValue != Double.NEGATIVE_INFINITY - && doubleValue != Double.POSITIVE_INFINITY) { - bigInteger = new BigDecimal(doubleValue).toBigInteger(); - } else { - return false; - } - } else if (number instanceof BigInteger) { - bigInteger = (BigInteger) number; - } else if (number instanceof BigDecimal) { - bigInteger = ((BigDecimal) number).toBigInteger(); - } else { - /* - * The else is necessary as the ICU4J plugin has it's own BigDecimal - * implementation which isn't part of the replacement plugin. So - * that this will work we fall back on the double value of the - * number. - */ - bigInteger = new BigDecimal(number.doubleValue()).toBigInteger(); - } - - if (bigInteger != null) { - return bigInteger.bitLength() <= bitLength; - } - - throw new IllegalArgumentException( - "Number of type [" + number.getClass().getName() + "] is not supported."); //$NON-NLS-1$ //$NON-NLS-2$ - } - - /** - * Returns <code>true</code> if the provided <code>number</code> is in - * the range of a long. - * - * @param number - * @return <code>true</code> if in range - * @throws IllegalArgumentException - * if the number type is unsupported - */ - public static boolean inLongRange(Number number) { - return checkInteger(number, 63); - } - - /** - * Returns <code>true</code> if the provided <code>number</code> is in - * the range of a float. - * - * @param number - * @return <code>true</code> if in range - * @throws IllegalArgumentException - * if the number type is unsupported - */ - public static boolean inFloatRange(Number number) { - return checkDecimal(number, FLOAT_MIN_BIG_DECIMAL, FLOAT_MAX_BIG_DECIMAL); - } - - private static boolean checkDecimal(Number number, BigDecimal min, BigDecimal max) { - BigDecimal bigDecimal = null; - if (number instanceof Integer || number instanceof Long) { - bigDecimal = new BigDecimal(number.doubleValue()); - } else if (number instanceof Float || number instanceof Double) { - double doubleValue = number.doubleValue(); - - /* - * doubleValue == doubleValue is used to check for NaN because NaN != - * NaN. The only way to check for NaN is to compare that the value - * is equal to itself. - */ - if (doubleValue == doubleValue - && doubleValue != Double.NEGATIVE_INFINITY - && doubleValue != Double.POSITIVE_INFINITY) { - bigDecimal = new BigDecimal(doubleValue); - } else { - return false; - } - } else if (number instanceof BigInteger) { - bigDecimal = new BigDecimal((BigInteger) number); - } else if (number instanceof BigDecimal) { - bigDecimal = (BigDecimal) number; - } else { - /* - * The else is necessary as the ICU4J plugin has it's own BigDecimal - * implementation which isn't part of the replacement plugin. So - * that this will work we fall back on the double value of the - * number. - */ - bigDecimal = new BigDecimal(number.doubleValue()); - } - - if (bigDecimal != null) { - return max.compareTo(bigDecimal) >= 0 - && min.compareTo(bigDecimal) <= 0; - } - - throw new IllegalArgumentException( - "Number of type [" + number.getClass().getName() + "] is not supported."); //$NON-NLS-1$ //$NON-NLS-2$ - } - - /** - * Returns <code>true</code> if the provided <code>number</code> is in - * the range of a double. - * - * @param number - * @return <code>true</code> if in range - * @throws IllegalArgumentException - * if the number type is unsupported - */ - public static boolean inDoubleRange(Number number) { - return checkDecimal(number, DOUBLE_MIN_BIG_DECIMAL, DOUBLE_MAX_BIG_DECIMAL); - } - - /** - * Returns <code>true</code> if the provided <code>number</code> is in - * the range of a short. - * - * @param number - * @return <code>true</code> if in range - */ - public static boolean inShortRange(Number number) { - return checkInteger(number, 15); - } - - /** - * Returns <code>true</code> if the provided <code>number</code> is in - * the range of a byte. - * - * @param number - * @return <code>true</code> if in range - */ - public static boolean inByteRange(Number number) { - return checkInteger(number, 7); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToShortConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToShortConverter.java deleted file mode 100755 index 3c05a5c7..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToShortConverter.java +++ /dev/null @@ -1,92 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.conversion; - -import org.eclipse.core.internal.databinding.conversion.StringToNumberParser.ParseResult; -import org.eclipse.core.internal.databinding.validation.NumberFormatConverter; - -import com.ibm.icu.text.NumberFormat; - -/** - * @since 1.0 - */ -public class StringToShortConverter extends NumberFormatConverter { - private final NumberFormat numberFormat; - private final boolean primitive; - - private String outOfRangeMessage; - - /** - * Constructs a new instance. - */ - private StringToShortConverter(NumberFormat numberFormat, Class toType) { - super(String.class, toType, numberFormat); - this.numberFormat = numberFormat; - primitive = toType.isPrimitive(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object) - */ - public Object convert(Object fromObject) { - ParseResult result = StringToNumberParser.parse(fromObject, - numberFormat, primitive); - - if (result.getPosition() != null) { - // this shouldn't happen in the pipeline as validation should catch - // it but anyone can call convert so we should return a properly - // formatted message in an exception - throw new IllegalArgumentException(StringToNumberParser - .createParseErrorMessage((String) fromObject, result - .getPosition())); - } else if (result.getNumber() == null) { - // if an error didn't occur and the number is null then it's a boxed - // type and null should be returned - return null; - } - - if (StringToNumberParser.inShortRange(result.getNumber())) { - return new Short(result.getNumber().shortValue()); - } - - synchronized (this) { - if (outOfRangeMessage == null) { - outOfRangeMessage = StringToNumberParser - .createOutOfRangeMessage(new Short(Short.MIN_VALUE), new Short(Short.MAX_VALUE), numberFormat); - } - - throw new IllegalArgumentException(outOfRangeMessage); - } - } - - /** - * @param primitive - * <code>true</code> if the convert to type is a short - * @return to Short converter for the default locale - */ - public static StringToShortConverter toShort(boolean primitive) { - return toShort(NumberFormat.getIntegerInstance(), primitive); - } - - /** - * @param numberFormat - * @param primitive - * @return to Short converter with the provided numberFormat - */ - public static StringToShortConverter toShort(NumberFormat numberFormat, - boolean primitive) { - return new StringToShortConverter(numberFormat, - (primitive) ? Short.TYPE : Short.class); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/messages.properties b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/messages.properties deleted file mode 100644 index 7540ebc7..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/messages.properties +++ /dev/null @@ -1,56 +0,0 @@ -############################################################################### -# Copyright (c) 2000, 2008 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -# NLS file for JFace Data Binding -############################################################################### -## Uneeded value -# -#Yes=Yes -#yes=yes -#No=No -#no=no -#True=True -#true=true -#False=False -#false=false -#and=and -#or=or -#Validate_BooleanHelp=Please type "Yes", "No", "True", or "False" -# -#Validate_RangeStart=Please enter a number between -#Validate_Like=Please enter a number like -# -############### - -IndexOutOfRange=Index out of Range. -MultipleProblems=Multiple Problems. - -ValueBinding_ErrorWhileSettingValue=An error occurred while setting the value. -DateFormat_DateTime=dd.MM.yyyy HH:mm:ss.SSS Z -DateFormat_Time=HH:mm:ss.SSS - -#ValueDelimiter should be used to separate multiple values that are stored in one key -ValueDelimiter=, - -#Values must be separated by ValueDelimiter -TrueStringValues=yes,true -FalseStringValues=no,false - -Validate_NumberOutOfRangeError=Please enter a value between [{0}] and [{1}] and with a similar format. -Validate_NumberParseError=Invalid character for value [{0}] at position [{1}] character [{2}]. -Validate_NumberParseErrorNoCharacter=Missing character for value [{0}] at position [{1}]. - -Validate_ConversionToPrimitive="Null object values can not be converted to primitives." -Validate_ConversionFromClassToPrimitive="Wrong object type to convert to primitive." - -Validate_NoChangeAllowedHelp=Changes are not allowed in this field -Validate_CharacterHelp=Please type a character - -Examples=Examples
\ No newline at end of file diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/ConstantObservableValue.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/ConstantObservableValue.java deleted file mode 100644 index f143efb5..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/ConstantObservableValue.java +++ /dev/null @@ -1,110 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007-2008 Matt Carter 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: - * Matt Carter - initial API and implementation (bug 212518) - * Matthew Hall - bug 212518 - *******************************************************************************/ -package org.eclipse.core.internal.databinding.observable; - -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.runtime.Assert; - -/** - * An immutable {@link IObservableValue}. - * - * @see WritableValue - */ -public class ConstantObservableValue implements IObservableValue { - final Realm realm; - final Object value; - final Object type; - - /** - * Construct a constant value of the given type, in the default realm. - * - * @param value - * immutable value - * @param type - * type - */ - public ConstantObservableValue(Object value, Object type) { - this(Realm.getDefault(), value, type); - } - - /** - * Construct a constant value of the given type, in the given realm. - * - * @param realm - * Realm - * @param value - * immutable value - * @param type - * type - */ - public ConstantObservableValue(Realm realm, Object value, Object type) { - Assert.isNotNull(realm, "Realm cannot be null"); //$NON-NLS-1$ - this.realm = realm; - this.value = value; - this.type = type; - } - - public Object getValueType() { - return type; - } - - public Object getValue() { - ObservableTracker.getterCalled(this); - return value; - } - - public void setValue(Object value) { - throw new UnsupportedOperationException(); - } - - public void addValueChangeListener(IValueChangeListener listener) { - // ignore - } - - public void removeValueChangeListener(IValueChangeListener listener) { - // ignore - } - - public void addChangeListener(IChangeListener listener) { - // ignore - } - - public void addStaleListener(IStaleListener listener) { - // ignore - } - - public void dispose() { - // nothing to dispose - } - - public Realm getRealm() { - return realm; - } - - public boolean isStale() { - return false; - } - - public void removeChangeListener(IChangeListener listener) { - // ignore - } - - public void removeStaleListener(IStaleListener listener) { - // ignore - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/EmptyObservableList.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/EmptyObservableList.java deleted file mode 100644 index 1b53b34b..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/EmptyObservableList.java +++ /dev/null @@ -1,224 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 208858 - * Matthew Hall - bug 208332 - *******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable; - -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IListChangeListener; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.runtime.Assert; - -/** - * Singleton empty list - */ -public class EmptyObservableList implements IObservableList { - - private static final List emptyList = Collections.EMPTY_LIST; - - private Realm realm; - private Object elementType; - - /** - * Creates an empty list. This list may be disposed multiple times - * without any side-effects. - * - * @param realm - * the realm of the constructed list - */ - public EmptyObservableList(Realm realm) { - this(realm, null); - } - - /** - * Creates an empty list. This list may be disposed multiple times - * without any side-effects. - * - * @param realm - * the realm of the constructed list - * @param elementType - * the element type of the constructed list - * @since 1.1 - */ - public EmptyObservableList(Realm realm, Object elementType) { - this.realm = realm; - this.elementType = elementType; - } - - public void addListChangeListener(IListChangeListener listener) { - // ignore - } - - public void removeListChangeListener(IListChangeListener listener) { - // ignore - } - - public Object getElementType() { - return elementType; - } - - public int size() { - checkRealm(); - return 0; - } - - void checkRealm() { - Assert.isTrue(realm.isCurrent(), - "Observable cannot be accessed outside its realm"); //$NON-NLS-1$ - } - - public boolean isEmpty() { - checkRealm(); - return true; - } - - public boolean contains(Object o) { - checkRealm(); - return false; - } - - public Iterator iterator() { - checkRealm(); - return emptyList.iterator(); - } - - public Object[] toArray() { - checkRealm(); - return emptyList.toArray(); - } - - public Object[] toArray(Object[] a) { - return emptyList.toArray(a); - } - - public boolean add(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean containsAll(Collection c) { - checkRealm(); - return c.isEmpty(); - } - - public boolean addAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - throw new UnsupportedOperationException(); - } - - public void addChangeListener(IChangeListener listener) { - } - - public void removeChangeListener(IChangeListener listener) { - } - - public void addStaleListener(IStaleListener listener) { - } - - public void removeStaleListener(IStaleListener listener) { - } - - public boolean isStale() { - checkRealm(); - return false; - } - - public void dispose() { - } - - public boolean addAll(int index, Collection c) { - throw new UnsupportedOperationException(); - } - - public Object get(int index) { - return emptyList.get(index); - } - - public int indexOf(Object o) { - return -1; - } - - public int lastIndexOf(Object o) { - return -1; - } - - public ListIterator listIterator() { - return emptyList.listIterator(); - } - - public ListIterator listIterator(int index) { - return emptyList.listIterator(index); - } - - public Object remove(int index) { - throw new UnsupportedOperationException(); - } - - public Object set(int index, Object element) { - throw new UnsupportedOperationException(); - } - - public Object move(int oldIndex, int newIndex) { - throw new UnsupportedOperationException(); - } - - public List subList(int fromIndex, int toIndex) { - return emptyList.subList(fromIndex, toIndex); - } - - public void add(int index, Object o) { - throw new UnsupportedOperationException(); - } - - public Realm getRealm() { - return realm; - } - - public boolean equals(Object obj) { - checkRealm(); - if (obj == this) - return true; - if (obj == null) - return false; - if (!(obj instanceof List)) - return false; - - return ((List) obj).isEmpty(); - } - - public int hashCode() { - checkRealm(); - return 1; - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/EmptyObservableSet.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/EmptyObservableSet.java deleted file mode 100644 index dab53c49..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/EmptyObservableSet.java +++ /dev/null @@ -1,176 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 208332 - *******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable; - -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.ISetChangeListener; -import org.eclipse.core.runtime.Assert; - -/** - * Singleton empty set - */ -public class EmptyObservableSet implements IObservableSet { - - private static final Set emptySet = Collections.EMPTY_SET; - - private Realm realm; - private Object elementType; - - /** - * Creates a singleton empty set. This set may be disposed multiple times - * without any side-effects. - * - * @param realm - * the realm of the constructed set - */ - public EmptyObservableSet(Realm realm) { - this(realm, null); - } - - /** - * Creates a singleton empty set. This set may be disposed multiple times - * without any side-effects. - * - * @param realm - * the realm of the constructed set - * @param elementType - * the element type of the constructed set - * @since 1.1 - */ - public EmptyObservableSet(Realm realm, Object elementType) { - this.realm = realm; - this.elementType = elementType; - } - - public void addSetChangeListener(ISetChangeListener listener) { - } - - public void removeSetChangeListener(ISetChangeListener listener) { - } - - public Object getElementType() { - return elementType; - } - - public int size() { - checkRealm(); - return 0; - } - - private void checkRealm() { - Assert.isTrue(realm.isCurrent(), - "Observable cannot be accessed outside its realm"); //$NON-NLS-1$ - } - - public boolean isEmpty() { - checkRealm(); - return true; - } - - public boolean contains(Object o) { - checkRealm(); - return false; - } - - public Iterator iterator() { - checkRealm(); - return emptySet.iterator(); - } - - public Object[] toArray() { - checkRealm(); - return emptySet.toArray(); - } - - public Object[] toArray(Object[] a) { - return emptySet.toArray(a); - } - - public boolean add(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean containsAll(Collection c) { - checkRealm(); - return c.isEmpty(); - } - - public boolean addAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - throw new UnsupportedOperationException(); - } - - public void addChangeListener(IChangeListener listener) { - } - - public void removeChangeListener(IChangeListener listener) { - } - - public void addStaleListener(IStaleListener listener) { - } - - public void removeStaleListener(IStaleListener listener) { - } - - public boolean isStale() { - checkRealm(); - return false; - } - - public void dispose() { - } - - public Realm getRealm() { - return realm; - } - - public boolean equals(Object obj) { - checkRealm(); - if (obj == this) - return true; - if (obj == null) - return false; - if (!(obj instanceof Set)) - return false; - - return ((Set) obj).isEmpty(); - } - - public int hashCode() { - checkRealm(); - return 0; - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/IStalenessConsumer.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/IStalenessConsumer.java deleted file mode 100644 index cfe5c612..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/IStalenessConsumer.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable; - -/** - * @since 1.0 - * - */ -public interface IStalenessConsumer { - /** - * @param stale - * - */ - public void setStale(boolean stale); -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/MapEntryObservableValue.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/MapEntryObservableValue.java deleted file mode 100644 index 3340eb6e..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/MapEntryObservableValue.java +++ /dev/null @@ -1,109 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Marko Topolnik 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: - * Marko Topolnik - initial API and implementation (bug 184830) - * Matthew Hall - bug 184830 - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.databinding.observable.map.IMapChangeListener; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.map.MapChangeEvent; -import org.eclipse.core.databinding.observable.value.AbstractObservableValue; -import org.eclipse.core.databinding.observable.value.IObservableValue; - -/** - * An {@link IObservableValue} that tracks the value of an entry in an - * {@link IObservableMap}, identified by the entry's key. - * - * @since 1.1 - */ -public class MapEntryObservableValue extends AbstractObservableValue { - private IObservableMap map; - private Object key; - private Object valueType; - - private IMapChangeListener changeListener = new IMapChangeListener() { - public void handleMapChange(final MapChangeEvent event) { - if (event.diff.getAddedKeys().contains(key)) { - final Object newValue = event.diff.getNewValue(key); - if (newValue != null) { - fireValueChange(Diffs.createValueDiff(null, newValue)); - } - } else if (event.diff.getChangedKeys().contains(key)) { - fireValueChange(Diffs.createValueDiff(event.diff - .getOldValue(key), event.diff.getNewValue(key))); - } else if (event.diff.getRemovedKeys().contains(key)) { - final Object oldValue = event.diff.getOldValue(key); - if (oldValue != null) { - fireValueChange(Diffs.createValueDiff(oldValue, null)); - } - } - } - }; - - private IStaleListener staleListener = new IStaleListener() { - public void handleStale(StaleEvent staleEvent) { - fireStale(); - } - }; - - /** - * Creates a map entry observable. - * - * @param map - * the observable map whose entry will be tracked - * @param key - * the key identifying the entry whose value will be tracked - * @param valueType - * the type of the value - */ - public MapEntryObservableValue(IObservableMap map, Object key, - Object valueType) { - super(map.getRealm()); - this.map = map; - this.key = key; - this.valueType = valueType; - - map.addMapChangeListener(changeListener); - map.addStaleListener(staleListener); - } - - public Object getValueType() { - return this.valueType; - } - - public boolean isStale() { - ObservableTracker.getterCalled(this); - return map.isStale(); - } - - public synchronized void dispose() { - if (map != null) { - map.removeMapChangeListener(changeListener); - map.removeStaleListener(staleListener); - map = null; - changeListener = null; - staleListener = null; - } - super.dispose(); - } - - protected Object doGetValue() { - return this.map.get(this.key); - } - - protected void doSetValue(Object value) { - this.map.put(this.key, value); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/ProxyObservableList.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/ProxyObservableList.java deleted file mode 100644 index 6d15f2c5..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/ProxyObservableList.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 208332) - * IBM Corporation - initial API and implementation - * (through ProxyObservableSet.java) - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable; - -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.databinding.observable.list.*; - -/** - * Wraps an observable list. This object acts like an exact copy of the original - * list, and tracks all the changes in the original. The only difference is that - * disposing the wrapper will not dispose the original. You can use this - * whenever you need to return an IObservableList from a method that expects the - * caller to dispose the list, but you have an IObservableList that you don't - * want disposed. - * - * @since 1.1 - */ -public class ProxyObservableList extends ObservableList { - private IListChangeListener listChangelistener = new IListChangeListener() { - public void handleListChange(ListChangeEvent event) { - fireListChange(event.diff); - } - }; - - private IStaleListener staleListener = new IStaleListener() { - public void handleStale(StaleEvent event) { - fireStale(); - } - }; - - private IObservableList wrappedList; - - /** - * Constructs a ProxyObservableList that tracks the state of the given list. - * - * @param wrappedList - * the list being wrapped - */ - public ProxyObservableList(IObservableList wrappedList) { - super(wrappedList.getRealm(), wrappedList, wrappedList.getElementType()); - this.wrappedList = wrappedList; - wrappedList.addListChangeListener(listChangelistener); - wrappedList.addStaleListener(staleListener); - } - - public boolean isStale() { - getterCalled(); - return wrappedList == null ? false : wrappedList.isStale(); - } - - public void dispose() { - if (wrappedList != null) { - wrappedList.removeListChangeListener(listChangelistener); - listChangelistener = null; - wrappedList.removeStaleListener(staleListener); - staleListener = null; - wrappedList = null; - } - super.dispose(); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/ProxyObservableSet.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/ProxyObservableSet.java deleted file mode 100644 index 55a0b24c..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/ProxyObservableSet.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 208332 - *******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable; - -import java.util.Collections; -import java.util.Set; - -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.databinding.observable.set.AbstractObservableSet; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.ISetChangeListener; -import org.eclipse.core.databinding.observable.set.SetChangeEvent; - -/** - * Wraps an observable set. This object acts like an exact copy of the original - * set, and tracks all the changes in the original. The only difference is that - * disposing the wrapper will not dispose the original. You can use this - * whenever you need to return an IObservableSet from a method that expects the - * caller to dispose the set, but you have an IObservableSet that you don't want - * disposed. - */ -public class ProxyObservableSet extends AbstractObservableSet { - private IObservableSet wrappedSet; - private Object elementType; - - private ISetChangeListener setChangeListener = new ISetChangeListener() { - public void handleSetChange(SetChangeEvent event) { - fireSetChange(event.diff); - } - }; - - private IStaleListener staleListener = new IStaleListener() { - public void handleStale(StaleEvent staleEvent) { - fireStale(); - } - }; - - /** - * Constructs a ProxyObservableSet that tracks the state of the given set. - * - * @param wrappedSet - * the set being wrapped - */ - public ProxyObservableSet(IObservableSet wrappedSet) { - super(wrappedSet.getRealm()); - this.wrappedSet = wrappedSet; - this.elementType = wrappedSet.getElementType(); - wrappedSet.addSetChangeListener(setChangeListener); - wrappedSet.addStaleListener(staleListener); - } - - protected Set getWrappedSet() { - return wrappedSet == null ? Collections.EMPTY_SET : wrappedSet; - } - - public Object getElementType() { - return elementType; - } - - public boolean isStale() { - getterCalled(); - return wrappedSet == null ? false : wrappedSet.isStale(); - } - - public void dispose() { - if (wrappedSet != null) { - wrappedSet.removeSetChangeListener(setChangeListener); - setChangeListener = null; - wrappedSet.removeStaleListener(staleListener); - staleListener = null; - wrappedSet = null; - } - elementType = null; - super.dispose(); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/StalenessObservableValue.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/StalenessObservableValue.java deleted file mode 100644 index 6a07fad3..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/StalenessObservableValue.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Boris Bokowski, IBM Corporation - initial API and implementation - * Matthew Hall - bug 212468 - *******************************************************************************/ -package org.eclipse.core.internal.databinding.observable; - -import org.eclipse.core.databinding.observable.ChangeEvent; -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.databinding.observable.value.AbstractObservableValue; - -/** - * An observable value that tracks the staleness of an {@link IObservable}. - * - * @since 1.1 - */ -public class StalenessObservableValue extends AbstractObservableValue { - - private class MyListener implements IChangeListener, IStaleListener { - public void handleChange(ChangeEvent event) { - if (stale && !event.getObservable().isStale()) { - stale = false; - fireValueChange(Diffs.createValueDiff(Boolean.TRUE, - Boolean.FALSE)); - } - } - - public void handleStale(StaleEvent staleEvent) { - if (!stale) { - stale = true; - fireValueChange(Diffs.createValueDiff(Boolean.FALSE, - Boolean.TRUE)); - } - } - } - - private IObservable tracked; - private boolean stale; - private MyListener listener = new MyListener(); - - /** - * Constructs a StalenessObservableValue that tracks the staleness of the - * given {@link IObservable}. - * - * @param observable - * the observable to track - */ - public StalenessObservableValue(IObservable observable) { - super(observable.getRealm()); - this.tracked = observable; - this.stale = observable.isStale(); - tracked.addChangeListener(listener); - tracked.addStaleListener(listener); - } - - protected Object doGetValue() { - return tracked.isStale() ? Boolean.TRUE : Boolean.FALSE; - } - - public Object getValueType() { - return Boolean.TYPE; - } - - public synchronized void dispose() { - if (tracked != null) { - tracked.removeChangeListener(listener); - tracked.removeStaleListener(listener); - tracked = null; - listener = null; - } - super.dispose(); - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/StalenessTracker.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/StalenessTracker.java deleted file mode 100644 index 6324325e..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/StalenessTracker.java +++ /dev/null @@ -1,127 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable; - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.databinding.observable.ChangeEvent; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.internal.databinding.IdentityWrapper; - -/** - * @since 1.0 - * - */ -public class StalenessTracker { - - private Map staleMap = new HashMap(); - - private int staleCount = 0; - - private final IStalenessConsumer stalenessConsumer; - - private class ChildListener implements IStaleListener, IChangeListener { - public void handleStale(StaleEvent event) { - processStalenessChange((IObservable) event.getSource(), true); - } - - public void handleChange(ChangeEvent event) { - processStalenessChange((IObservable) event.getSource(), true); - } - } - - private ChildListener childListener = new ChildListener(); - - /** - * @param observables - * @param stalenessConsumer - */ - public StalenessTracker(IObservable[] observables, - IStalenessConsumer stalenessConsumer) { - this.stalenessConsumer = stalenessConsumer; - for (int i = 0; i < observables.length; i++) { - IObservable observable = observables[i]; - doAddObservable(observable, false); - } - stalenessConsumer.setStale(staleCount > 0); - } - - /** - * @param child - * @param callback - */ - public void processStalenessChange(IObservable child, boolean callback) { - boolean oldStale = staleCount > 0; - IdentityWrapper wrappedChild = new IdentityWrapper(child); - boolean oldChildStale = getOldChildStale(wrappedChild); - boolean newChildStale = child.isStale(); - if (oldChildStale != newChildStale) { - if (oldChildStale) { - staleCount--; - } else { - staleCount++; - } - staleMap.put(wrappedChild, newChildStale ? Boolean.TRUE : Boolean.FALSE); - } - boolean newStale = staleCount > 0; - if (callback && (newStale != oldStale)) { - stalenessConsumer.setStale(newStale); - } - } - - /** - * @param wrappedChild - */ - private boolean getOldChildStale(IdentityWrapper wrappedChild) { - Object oldChildValue = staleMap.get(wrappedChild); - boolean oldChildStale = oldChildValue == null ? false - : ((Boolean) oldChildValue).booleanValue(); - return oldChildStale; - } - - /** - * @param observable - */ - public void addObservable(IObservable observable) { - doAddObservable(observable, true); - } - - private void doAddObservable(IObservable observable, boolean callback) { - processStalenessChange(observable, callback); - observable.addChangeListener(childListener); - observable.addStaleListener(childListener); - } - - /** - * @param observable - */ - public void removeObservable(IObservable observable) { - boolean oldStale = staleCount > 0; - IdentityWrapper wrappedChild = new IdentityWrapper(observable); - boolean oldChildStale = getOldChildStale(wrappedChild); - if (oldChildStale) { - staleCount--; - } - staleMap.remove(wrappedChild); - observable.removeChangeListener(childListener); - observable.removeStaleListener(childListener); - boolean newStale = staleCount > 0; - if (newStale != oldStale) { - stalenessConsumer.setStale(newStale); - } - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/UnmodifiableObservableList.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/UnmodifiableObservableList.java deleted file mode 100644 index 6f34e1eb..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/UnmodifiableObservableList.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006-2008 Cerner Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bug 208332 - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable; - -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.databinding.observable.list.IListChangeListener; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.ListChangeEvent; -import org.eclipse.core.databinding.observable.list.ObservableList; - -/** - * ObservableList implementation that prevents modification by consumers. Events - * in the originating wrapped list are propagated and thrown from this instance - * when appropriate. All mutators throw an UnsupportedOperationException. - * - * @since 1.0 - */ -/* - * Implementation makes the assumption that the superclass (ObservableList) is - * unmodifiable and that all modify methods throw an - * UnsupportedOperationException. - */ -public class UnmodifiableObservableList extends ObservableList { - /** - * List that is being made unmodifiable. - */ - private IObservableList wrappedList; - - private IListChangeListener listChangeListener = new IListChangeListener() { - public void handleListChange(ListChangeEvent event) { - // Fires a Change and then ListChange event. - fireListChange(event.diff); - } - }; - - private IStaleListener staleListener = new IStaleListener() { - public void handleStale(StaleEvent event) { - fireStale(); - } - }; - - /** - * @param wrappedList - */ - public UnmodifiableObservableList(IObservableList wrappedList) { - super(wrappedList.getRealm(), wrappedList, wrappedList.getElementType()); - this.wrappedList = wrappedList; - - wrappedList.addListChangeListener(listChangeListener); - - wrappedList.addStaleListener(staleListener); - } - - /** - * Because this instance is immutable staleness cannot be changed. - * - * @throws UnsupportedOperationException - * because this instance is unmodifiable. - */ - public void setStale(boolean stale) { - throw new UnsupportedOperationException(); - } - - public boolean isStale() { - getterCalled(); - return wrappedList == null ? false : wrappedList.isStale(); - } - - public synchronized void dispose() { - if (wrappedList != null) { - wrappedList.removeListChangeListener(listChangeListener); - wrappedList.removeStaleListener(staleListener); - wrappedList = null; - } - listChangeListener = null; - staleListener = null; - super.dispose(); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/UnmodifiableObservableSet.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/UnmodifiableObservableSet.java deleted file mode 100644 index ee38b252..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/UnmodifiableObservableSet.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 208332) - * Brad Reynolds - initial API and implementation - * (through UnmodifiableObservableList.java) - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable; - -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.databinding.observable.set.*; - -/** - * ObservableList implementation that prevents modification by consumers. Events - * in the originating wrapped list are propagated and thrown from this instance - * when appropriate. All mutators throw an UnsupportedOperationException. - * - * @since 1.1 - */ -public class UnmodifiableObservableSet extends ObservableSet { - private ISetChangeListener setChangeListener = new ISetChangeListener() { - public void handleSetChange(SetChangeEvent event) { - fireSetChange(event.diff); - } - }; - - private IStaleListener staleListener = new IStaleListener() { - public void handleStale(StaleEvent event) { - fireStale(); - } - }; - - private IObservableSet wrappedSet; - - /** - * @param wrappedSet - */ - public UnmodifiableObservableSet(IObservableSet wrappedSet) { - super(wrappedSet.getRealm(), wrappedSet, wrappedSet.getElementType()); - - this.wrappedSet = wrappedSet; - - wrappedSet.addSetChangeListener(setChangeListener); - wrappedSet.addStaleListener(staleListener); - } - - /** - * Because this instance is immutable staleness cannot be changed. - */ - public void setStale(boolean stale) { - throw new UnsupportedOperationException(); - } - - public boolean isStale() { - getterCalled(); - return wrappedSet == null ? false : wrappedSet.isStale(); - } - - public synchronized void dispose() { - if (wrappedSet != null) { - wrappedSet.removeSetChangeListener(setChangeListener); - wrappedSet.removeStaleListener(staleListener); - wrappedSet = null; - } - setChangeListener = null; - staleListener = null; - super.dispose(); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/UnmodifiableObservableValue.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/UnmodifiableObservableValue.java deleted file mode 100644 index e35712c3..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/UnmodifiableObservableValue.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 219909) - * Matthew Hall - bug 237884 - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable; - -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.databinding.observable.value.AbstractObservableValue; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.observable.value.ValueChangeEvent; - -/** - * An unmodifiable wrapper class for IObservableValue instances. - * @since 1.1 - */ -public class UnmodifiableObservableValue extends AbstractObservableValue { - private IObservableValue wrappedValue; - - /** - * Constructs an UnmodifiableObservableValue which wraps the given - * observable value - * - * @param wrappedValue - * the observable value to wrap in an unmodifiable instance. - */ - public UnmodifiableObservableValue(IObservableValue wrappedValue) { - super(wrappedValue.getRealm()); - - this.wrappedValue = wrappedValue; - wrappedValue.addValueChangeListener(new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - fireValueChange(event.diff); - } - }); - wrappedValue.addStaleListener(new IStaleListener() { - public void handleStale(StaleEvent staleEvent) { - fireStale(); - } - }); - } - - protected Object doGetValue() { - return wrappedValue.getValue(); - } - - public Object getValueType() { - return wrappedValue.getValueType(); - } - - public boolean isStale() { - return wrappedValue.isStale(); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/ValidatedObservableList.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/ValidatedObservableList.java deleted file mode 100644 index c1fa4612..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/ValidatedObservableList.java +++ /dev/null @@ -1,393 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 218269) - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.databinding.observable.list.IListChangeListener; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.ListChangeEvent; -import org.eclipse.core.databinding.observable.list.ListDiff; -import org.eclipse.core.databinding.observable.list.ListDiffEntry; -import org.eclipse.core.databinding.observable.list.ListDiffVisitor; -import org.eclipse.core.databinding.observable.list.ObservableList; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.observable.value.ValueChangeEvent; -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.IStatus; - -/** - * @since 3.3 - * - */ -public class ValidatedObservableList extends ObservableList { - private IObservableList target; - private IObservableValue validationStatus; - - // Only true when out of sync with target due to validation status - private boolean stale; - - // True when validaton status changes from invalid to valid. - private boolean computeNextDiff = false; - - private boolean updatingTarget = false; - - private IListChangeListener targetChangeListener = new IListChangeListener() { - public void handleListChange(ListChangeEvent event) { - if (updatingTarget) - return; - IStatus status = (IStatus) validationStatus.getValue(); - if (isValid(status)) { - if (stale) { - // this.stale means we are out of sync with target, - // so reset wrapped list to exactly mirror target - stale = false; - updateWrappedList(new ArrayList(target)); - } else { - ListDiff diff = event.diff; - if (computeNextDiff) { - diff = Diffs.computeListDiff(wrappedList, target); - computeNextDiff = false; - } - applyDiff(diff, wrappedList); - fireListChange(diff); - } - } else { - makeStale(); - } - } - }; - - private static boolean isValid(IStatus status) { - return status.isOK() || status.matches(IStatus.INFO | IStatus.WARNING); - } - - private IStaleListener targetStaleListener = new IStaleListener() { - public void handleStale(StaleEvent staleEvent) { - fireStale(); - } - }; - - private IValueChangeListener validationStatusChangeListener = new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - IStatus oldStatus = (IStatus) event.diff.getOldValue(); - IStatus newStatus = (IStatus) event.diff.getNewValue(); - if (stale && !isValid(oldStatus) && isValid(newStatus)) { - // this.stale means we are out of sync with target, - // reset wrapped list to exactly mirror target - stale = false; - updateWrappedList(new ArrayList(target)); - - // If the validation status becomes valid because of a change in - // target observable - computeNextDiff = true; - } - } - }; - - /** - * @param target - * @param validationStatus - */ - public ValidatedObservableList(final IObservableList target, - final IObservableValue validationStatus) { - super(target.getRealm(), new ArrayList(target), target.getElementType()); - Assert.isNotNull(validationStatus, - "Validation status observable cannot be null"); //$NON-NLS-1$ - Assert - .isTrue(target.getRealm().equals(validationStatus.getRealm()), - "Target and validation status observables must be on the same realm"); //$NON-NLS-1$ - this.target = target; - this.validationStatus = validationStatus; - target.addListChangeListener(targetChangeListener); - target.addStaleListener(targetStaleListener); - validationStatus.addValueChangeListener(validationStatusChangeListener); - } - - private void makeStale() { - if (!stale) { - stale = true; - fireStale(); - } - } - - private void updateTargetList(ListDiff diff) { - updatingTarget = true; - try { - if (stale) { - stale = false; - applyDiff(Diffs.computeListDiff(target, wrappedList), target); - } else { - applyDiff(diff, target); - } - } finally { - updatingTarget = false; - } - } - - private void applyDiff(ListDiff diff, final List list) { - diff.accept(new ListDiffVisitor() { - public void handleAdd(int index, Object element) { - list.add(index, element); - } - - public void handleRemove(int index, Object element) { - list.remove(index); - } - - public void handleReplace(int index, Object oldElement, - Object newElement) { - list.set(index, newElement); - } - }); - } - - public boolean isStale() { - ObservableTracker.getterCalled(this); - return stale || target.isStale(); - } - - public void add(int index, Object element) { - checkRealm(); - wrappedList.add(index, element); - ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry(index, - true, element)); - updateTargetList(diff); - fireListChange(diff); - } - - public boolean add(Object o) { - checkRealm(); - add(wrappedList.size(), o); - return true; - } - - public boolean addAll(Collection c) { - checkRealm(); - return addAll(wrappedList.size(), c); - } - - public boolean addAll(int index, Collection c) { - checkRealm(); - Object[] elements = c.toArray(); - ListDiffEntry[] entries = new ListDiffEntry[elements.length]; - for (int i = 0; i < elements.length; i++) { - wrappedList.add(index + i, elements[i]); - entries[i] = Diffs - .createListDiffEntry(index + i, true, elements[i]); - } - ListDiff diff = Diffs.createListDiff(entries); - updateTargetList(diff); - fireListChange(diff); - return true; - } - - public void clear() { - checkRealm(); - if (isEmpty()) - return; - ListDiff diff = Diffs.computeListDiff(wrappedList, - Collections.EMPTY_LIST); - wrappedList.clear(); - updateTargetList(diff); - fireListChange(diff); - } - - public Iterator iterator() { - getterCalled(); - final ListIterator wrappedIterator = wrappedList.listIterator(); - return new Iterator() { - Object last = null; - - public boolean hasNext() { - return wrappedIterator.hasNext(); - } - - public Object next() { - return last = wrappedIterator.next(); - } - - public void remove() { - int index = wrappedIterator.previousIndex(); - wrappedIterator.remove(); - ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry( - index, false, last)); - updateTargetList(diff); - fireListChange(diff); - } - }; - } - - public ListIterator listIterator() { - return listIterator(0); - } - - public ListIterator listIterator(int index) { - getterCalled(); - final ListIterator wrappedIterator = wrappedList.listIterator(index); - return new ListIterator() { - int lastIndex = -1; - Object last = null; - - public void add(Object o) { - wrappedIterator.add(o); - lastIndex = previousIndex(); - ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry( - lastIndex, true, o)); - updateTargetList(diff); - fireListChange(diff); - } - - public boolean hasNext() { - return wrappedIterator.hasNext(); - } - - public boolean hasPrevious() { - return wrappedIterator.hasPrevious(); - } - - public Object next() { - last = wrappedIterator.next(); - lastIndex = previousIndex(); - return last; - } - - public int nextIndex() { - return wrappedIterator.nextIndex(); - } - - public Object previous() { - last = wrappedIterator.previous(); - lastIndex = nextIndex(); - return last; - } - - public int previousIndex() { - return wrappedIterator.previousIndex(); - } - - public void remove() { - wrappedIterator.remove(); - ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry( - lastIndex, false, last)); - lastIndex = -1; - updateTargetList(diff); - fireListChange(diff); - } - - public void set(Object o) { - wrappedIterator.set(o); - ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry( - lastIndex, false, last), Diffs.createListDiffEntry( - lastIndex, true, o)); - last = o; - updateTargetList(diff); - fireListChange(diff); - } - }; - } - - public Object move(int oldIndex, int newIndex) { - checkRealm(); - int size = wrappedList.size(); - if (oldIndex >= size) - throw new IndexOutOfBoundsException( - "oldIndex: " + oldIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$ - if (newIndex >= size) - throw new IndexOutOfBoundsException( - "newIndex: " + newIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$ - if (oldIndex == newIndex) - return wrappedList.get(oldIndex); - Object element = wrappedList.remove(oldIndex); - wrappedList.add(newIndex, element); - ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry( - oldIndex, false, element), Diffs.createListDiffEntry(newIndex, - true, element)); - updateTargetList(diff); - fireListChange(diff); - return element; - } - - public Object remove(int index) { - checkRealm(); - Object element = wrappedList.remove(index); - ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry(index, - false, element)); - updateTargetList(diff); - fireListChange(diff); - return element; - } - - public boolean remove(Object o) { - checkRealm(); - int index = wrappedList.indexOf(o); - if (index == -1) - return false; - remove(index); - return true; - } - - public boolean removeAll(Collection c) { - checkRealm(); - List list = new ArrayList(wrappedList); - boolean changed = list.removeAll(c); - if (changed) { - ListDiff diff = Diffs.computeListDiff(wrappedList, list); - wrappedList = list; - updateTargetList(diff); - fireListChange(diff); - } - return changed; - } - - public boolean retainAll(Collection c) { - checkRealm(); - List list = new ArrayList(wrappedList); - boolean changed = list.retainAll(c); - if (changed) { - ListDiff diff = Diffs.computeListDiff(wrappedList, list); - wrappedList = list; - updateTargetList(diff); - fireListChange(diff); - } - return changed; - } - - public Object set(int index, Object element) { - checkRealm(); - Object oldElement = wrappedList.set(index, element); - ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry(index, - false, oldElement), Diffs.createListDiffEntry(index, true, - element)); - updateTargetList(diff); - fireListChange(diff); - return oldElement; - } - - public synchronized void dispose() { - target.removeListChangeListener(targetChangeListener); - target.removeStaleListener(targetStaleListener); - validationStatus - .removeValueChangeListener(validationStatusChangeListener); - super.dispose(); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/ValidatedObservableMap.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/ValidatedObservableMap.java deleted file mode 100644 index 1261f69c..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/ValidatedObservableMap.java +++ /dev/null @@ -1,228 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 218269) - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.databinding.observable.map.IMapChangeListener; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.map.MapChangeEvent; -import org.eclipse.core.databinding.observable.map.MapDiff; -import org.eclipse.core.databinding.observable.map.ObservableMap; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.observable.value.ValueChangeEvent; -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.IStatus; - -/** - * @since 3.3 - * - */ -public class ValidatedObservableMap extends ObservableMap { - private IObservableMap target; - private IObservableValue validationStatus; - - // Only true when out of sync with target due to validation status - private boolean stale; - - // True when validation status changes from invalid to valid. - private boolean computeNextDiff = false; - - private boolean updatingTarget = false; - - private IMapChangeListener targetChangeListener = new IMapChangeListener() { - public void handleMapChange(MapChangeEvent event) { - if (updatingTarget) - return; - IStatus status = (IStatus) validationStatus.getValue(); - if (isValid(status)) { - if (stale) { - // this.stale means we are out of sync with target, - // so reset wrapped list to exactly mirror target - stale = false; - updateWrappedMap(new HashMap(target)); - } else { - MapDiff diff = event.diff; - if (computeNextDiff) { - diff = Diffs.computeMapDiff(wrappedMap, target); - computeNextDiff = false; - } - applyDiff(diff, wrappedMap); - fireMapChange(diff); - } - } else { - makeStale(); - } - } - }; - - private IStaleListener targetStaleListener = new IStaleListener() { - public void handleStale(StaleEvent staleEvent) { - fireStale(); - } - }; - - private IValueChangeListener validationStatusChangeListener = new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - IStatus oldStatus = (IStatus) event.diff.getOldValue(); - IStatus newStatus = (IStatus) event.diff.getNewValue(); - if (stale && !isValid(oldStatus) && isValid(newStatus)) { - // this.stale means we are out of sync with target, - // reset wrapped map to exactly mirror target - stale = false; - updateWrappedMap(new HashMap(target)); - - // If the validation status becomes valid because of a change in - // target observable - computeNextDiff = true; - } - } - }; - - /** - * @param target - * @param validationStatus - */ - public ValidatedObservableMap(final IObservableMap target, - final IObservableValue validationStatus) { - super(target.getRealm(), new HashMap(target)); - Assert.isNotNull(validationStatus, - "Validation status observable cannot be null"); //$NON-NLS-1$ - Assert - .isTrue(target.getRealm().equals(validationStatus.getRealm()), - "Target and validation status observables must be on the same realm"); //$NON-NLS-1$ - this.target = target; - this.validationStatus = validationStatus; - target.addMapChangeListener(targetChangeListener); - target.addStaleListener(targetStaleListener); - validationStatus.addValueChangeListener(validationStatusChangeListener); - } - - private void updateWrappedMap(Map newMap) { - Map oldMap = wrappedMap; - MapDiff diff = Diffs.computeMapDiff(oldMap, newMap); - wrappedMap = newMap; - fireMapChange(diff); - } - - private static boolean isValid(IStatus status) { - return status.isOK() || status.matches(IStatus.INFO | IStatus.WARNING); - } - - private void applyDiff(MapDiff diff, Map map) { - for (Iterator iterator = diff.getRemovedKeys().iterator(); iterator - .hasNext();) - map.remove(iterator.next()); - for (Iterator iterator = diff.getChangedKeys().iterator(); iterator - .hasNext();) { - Object key = iterator.next(); - map.put(key, diff.getNewValue(key)); - } - for (Iterator iterator = diff.getAddedKeys().iterator(); iterator - .hasNext();) { - Object key = iterator.next(); - map.put(key, diff.getNewValue(key)); - } - } - - private void makeStale() { - if (!stale) { - stale = true; - fireStale(); - } - } - - private void updateTargetMap(MapDiff diff) { - updatingTarget = true; - try { - if (stale) { - stale = false; - applyDiff(Diffs.computeMapDiff(target, wrappedMap), target); - } else { - applyDiff(diff, target); - } - } finally { - updatingTarget = false; - } - } - - public boolean isStale() { - getterCalled(); - return stale || target.isStale(); - } - - public void clear() { - checkRealm(); - if (isEmpty()) - return; - MapDiff diff = Diffs.computeMapDiff(wrappedMap, Collections.EMPTY_MAP); - wrappedMap = new HashMap(); - updateTargetMap(diff); - fireMapChange(diff); - } - - public Object put(Object key, Object value) { - checkRealm(); - MapDiff diff; - Object oldValue; - if (wrappedMap.containsKey(key)) { - oldValue = wrappedMap.put(key, value); - if (wrappedMap.containsKey(key)) { // Changed - diff = Diffs.createMapDiffSingleChange(key, oldValue, value); - } else { // Removed - diff = Diffs.createMapDiffSingleRemove(key, oldValue); - } - } else { // Added - oldValue = wrappedMap.put(key, value); - diff = Diffs.createMapDiffSingleAdd(key, value); - } - updateTargetMap(diff); - fireMapChange(diff); - return oldValue; - } - - public void putAll(Map m) { - checkRealm(); - Map map = new HashMap(wrappedMap); - map.putAll(m); - MapDiff diff = Diffs.computeMapDiff(wrappedMap, map); - wrappedMap = map; - updateTargetMap(diff); - fireMapChange(diff); - } - - public Object remove(Object key) { - checkRealm(); - if (!wrappedMap.containsKey(key)) - return null; - Object oldValue = wrappedMap.remove(key); - MapDiff diff = Diffs.createMapDiffSingleRemove(key, oldValue); - updateTargetMap(diff); - fireMapChange(diff); - return oldValue; - } - - public synchronized void dispose() { - target.removeMapChangeListener(targetChangeListener); - target.removeStaleListener(targetStaleListener); - validationStatus - .removeValueChangeListener(validationStatusChangeListener); - super.dispose(); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/ValidatedObservableSet.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/ValidatedObservableSet.java deleted file mode 100644 index bb7c6e68..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/ValidatedObservableSet.java +++ /dev/null @@ -1,270 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 218269) - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.ISetChangeListener; -import org.eclipse.core.databinding.observable.set.ObservableSet; -import org.eclipse.core.databinding.observable.set.SetChangeEvent; -import org.eclipse.core.databinding.observable.set.SetDiff; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.observable.value.ValueChangeEvent; -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.IStatus; - -/** - * @since 3.3 - * - */ -public class ValidatedObservableSet extends ObservableSet { - private IObservableSet target; - private IObservableValue validationStatus; - - // Only true when out of sync with target due to validation status - private boolean stale; - - // True when validation status changes from invalid to valid. - private boolean computeNextDiff = false; - - private boolean updatingTarget = false; - - private ISetChangeListener targetChangeListener = new ISetChangeListener() { - public void handleSetChange(SetChangeEvent event) { - if (updatingTarget) - return; - IStatus status = (IStatus) validationStatus.getValue(); - if (isValid(status)) { - if (stale) { - // this.stale means we are out of sync with target, - // so reset wrapped list to exactly mirror target - stale = false; - updateWrappedSet(new HashSet(target)); - } else { - SetDiff diff = event.diff; - if (computeNextDiff) { - diff = Diffs.computeSetDiff(wrappedSet, target); - computeNextDiff = false; - } - applyDiff(diff, wrappedSet); - fireSetChange(diff); - } - } else { - makeStale(); - } - } - }; - - private IStaleListener targetStaleListener = new IStaleListener() { - public void handleStale(StaleEvent staleEvent) { - fireStale(); - } - }; - - private IValueChangeListener validationStatusChangeListener = new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - IStatus oldStatus = (IStatus) event.diff.getOldValue(); - IStatus newStatus = (IStatus) event.diff.getNewValue(); - if (stale && !isValid(oldStatus) && isValid(newStatus)) { - // this.stale means we are out of sync with target, - // reset wrapped set to exactly mirror target - stale = false; - updateWrappedSet(new HashSet(target)); - - // If the validation status becomes valid because of a change in - // target observable - computeNextDiff = true; - } - } - }; - - /** - * @param target - * @param validationStatus - */ - public ValidatedObservableSet(final IObservableSet target, - final IObservableValue validationStatus) { - super(target.getRealm(), new HashSet(target), target.getElementType()); - Assert.isNotNull(validationStatus, - "Validation status observable cannot be null"); //$NON-NLS-1$ - Assert - .isTrue(target.getRealm().equals(validationStatus.getRealm()), - "Target and validation status observables must be on the same realm"); //$NON-NLS-1$ - this.target = target; - this.validationStatus = validationStatus; - target.addSetChangeListener(targetChangeListener); - target.addStaleListener(targetStaleListener); - validationStatus.addValueChangeListener(validationStatusChangeListener); - } - - private void updateWrappedSet(Set newSet) { - Set oldSet = wrappedSet; - SetDiff diff = Diffs.computeSetDiff(oldSet, newSet); - wrappedSet = newSet; - fireSetChange(diff); - } - - private static boolean isValid(IStatus status) { - return status.isOK() || status.matches(IStatus.INFO | IStatus.WARNING); - } - - private void applyDiff(SetDiff diff, Set set) { - for (Iterator iterator = diff.getRemovals().iterator(); iterator - .hasNext();) { - set.remove(iterator.next()); - } - for (Iterator iterator = diff.getAdditions().iterator(); iterator - .hasNext();) { - set.add(iterator.next()); - } - } - - private void makeStale() { - if (!stale) { - stale = true; - fireStale(); - } - } - - private void updateTargetSet(SetDiff diff) { - updatingTarget = true; - try { - if (stale) { - stale = false; - applyDiff(Diffs.computeSetDiff(target, wrappedSet), target); - } else { - applyDiff(diff, target); - } - } finally { - updatingTarget = false; - } - } - - public boolean isStale() { - getterCalled(); - return stale || target.isStale(); - } - - public boolean add(Object o) { - getterCalled(); - boolean changed = wrappedSet.add(o); - if (changed) { - SetDiff diff = Diffs.createSetDiff(Collections.singleton(o), - Collections.EMPTY_SET); - updateTargetSet(diff); - fireSetChange(diff); - } - return changed; - } - - public boolean addAll(Collection c) { - getterCalled(); - HashSet set = new HashSet(wrappedSet); - boolean changed = set.addAll(c); - if (changed) { - SetDiff diff = Diffs.computeSetDiff(wrappedSet, set); - wrappedSet = set; - updateTargetSet(diff); - fireSetChange(diff); - } - return changed; - } - - public void clear() { - getterCalled(); - if (isEmpty()) - return; - SetDiff diff = Diffs.createSetDiff(Collections.EMPTY_SET, wrappedSet); - wrappedSet = new HashSet(); - updateTargetSet(diff); - fireSetChange(diff); - } - - public Iterator iterator() { - getterCalled(); - final Iterator wrappedIterator = wrappedSet.iterator(); - return new Iterator() { - Object last = null; - - public boolean hasNext() { - return wrappedIterator.hasNext(); - } - - public Object next() { - return last = wrappedIterator.next(); - } - - public void remove() { - wrappedIterator.remove(); - SetDiff diff = Diffs.createSetDiff(Collections.EMPTY_SET, - Collections.singleton(last)); - updateTargetSet(diff); - fireSetChange(diff); - } - }; - } - - public boolean remove(Object o) { - getterCalled(); - boolean changed = wrappedSet.remove(o); - if (changed) { - SetDiff diff = Diffs.createSetDiff(Collections.EMPTY_SET, - Collections.singleton(o)); - updateTargetSet(diff); - fireSetChange(diff); - } - return changed; - } - - public boolean removeAll(Collection c) { - getterCalled(); - Set set = new HashSet(wrappedSet); - boolean changed = set.removeAll(c); - if (changed) { - SetDiff diff = Diffs.computeSetDiff(wrappedSet, set); - wrappedSet = set; - updateTargetSet(diff); - fireSetChange(diff); - } - return changed; - } - - public boolean retainAll(Collection c) { - getterCalled(); - Set set = new HashSet(wrappedSet); - boolean changed = set.retainAll(c); - if (changed) { - SetDiff diff = Diffs.computeSetDiff(wrappedSet, set); - wrappedSet = set; - updateTargetSet(diff); - fireSetChange(diff); - } - return changed; - } - - public synchronized void dispose() { - target.removeSetChangeListener(targetChangeListener); - target.removeStaleListener(targetStaleListener); - validationStatus - .removeValueChangeListener(validationStatusChangeListener); - super.dispose(); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/ValidatedObservableValue.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/ValidatedObservableValue.java deleted file mode 100644 index 1164f539..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/ValidatedObservableValue.java +++ /dev/null @@ -1,170 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 218269) - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.databinding.observable.value.AbstractObservableValue; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.observable.value.IVetoableValue; -import org.eclipse.core.databinding.observable.value.ValueChangeEvent; -import org.eclipse.core.databinding.observable.value.ValueChangingEvent; -import org.eclipse.core.internal.databinding.Util; -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.IStatus; - -/** - * An {@link IObservableValue} wrapper that stays in sync with the target - * observable as long as a given validation status is valid. - * <ul> - * <li>While status is valid, ValidatedObservableValue stays in sync with its - * target. - * <li>When status becomes invalid, ValidatedObservableValue will retain the - * last valid value of its target. - * <li>While status is invalid, changes in the target observable cause - * ValidatedObservableValue to fire a stale event, to indicate that changes are - * pending. - * <li>When status becomes valid, pending value changes are performed (if any) - * and synchronization resumes. - * </ul> - * <p> - * Note: - * <ul> - * <li>By default, a status is valid if its - * {@link IStatus#getSeverity() severity} is {@link IStatus#OK OK}, - * {@link IStatus#INFO INFO}, or {@link IStatus#WARNING WARNING} - * <li>Calls to {@link #setValue(Object)} on the validated observable changes - * the value regardless of the validation status. - * <li>This class will not forward {@link ValueChangingEvent} events from a - * wrapped {@link IVetoableValue}. - * </ul> - * - * @since 1.2 - */ -public class ValidatedObservableValue extends AbstractObservableValue { - private IObservableValue target; - private IObservableValue validationStatus; - - private Object cachedValue; - private boolean stale; - private boolean updatingTarget = false; - - private IValueChangeListener targetChangeListener = new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - if (updatingTarget) - return; - IStatus status = (IStatus) validationStatus.getValue(); - if (isValid(status)) - internalSetValue(event.diff.getNewValue(), false); - else - makeStale(); - } - }; - - private static boolean isValid(IStatus status) { - return status.isOK() || status.matches(IStatus.INFO | IStatus.WARNING); - } - - private IStaleListener targetStaleListener = new IStaleListener() { - public void handleStale(StaleEvent staleEvent) { - fireStale(); - } - }; - - private IValueChangeListener validationStatusChangeListener = new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - IStatus oldStatus = (IStatus) event.diff.getOldValue(); - IStatus newStatus = (IStatus) event.diff.getNewValue(); - if (stale && !isValid(oldStatus) && isValid(newStatus)) { - internalSetValue(target.getValue(), false); - } - } - }; - - /** - * Constructs an observable value - * - * @param target - * the observable value to be wrapped - * @param validationStatus - * an observable value of type {@link IStatus}.class which - * contains the current validation status - */ - public ValidatedObservableValue(IObservableValue target, - IObservableValue validationStatus) { - super(target.getRealm()); - Assert.isNotNull(validationStatus, - "Validation status observable cannot be null"); //$NON-NLS-1$ - Assert - .isTrue(target.getRealm().equals(validationStatus.getRealm()), - "Target and validation status observables must be on the same realm"); //$NON-NLS-1$ - this.target = target; - this.validationStatus = validationStatus; - this.cachedValue = target.getValue(); - - target.addValueChangeListener(targetChangeListener); - target.addStaleListener(targetStaleListener); - validationStatus.addValueChangeListener(validationStatusChangeListener); - } - - private void makeStale() { - if (!stale) { - stale = true; - fireStale(); - } - } - - public boolean isStale() { - ObservableTracker.getterCalled(this); - return stale || target.isStale(); - } - - protected Object doGetValue() { - return cachedValue; - } - - private void internalSetValue(Object value, boolean updateTarget) { - Object oldValue = cachedValue; - cachedValue = value; - if (updateTarget) { - updatingTarget = true; - try { - target.setValue(value); - cachedValue = target.getValue(); - } finally { - updatingTarget = false; - } - } - stale = false; - if (!Util.equals(oldValue, cachedValue)) - fireValueChange(Diffs.createValueDiff(oldValue, cachedValue)); - } - - protected void doSetValue(Object value) { - internalSetValue(value, true); - } - - public Object getValueType() { - return target.getValueType(); - } - - public synchronized void dispose() { - target.removeValueChangeListener(targetChangeListener); - target.removeStaleListener(targetStaleListener); - validationStatus - .removeValueChangeListener(validationStatusChangeListener); - super.dispose(); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/masterdetail/DetailObservableList.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/masterdetail/DetailObservableList.java deleted file mode 100755 index 1baec566..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/masterdetail/DetailObservableList.java +++ /dev/null @@ -1,175 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005-2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 147515 - * Matthew Hall - bug 221351 - *******************************************************************************/ -package org.eclipse.core.internal.databinding.observable.masterdetail; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IObserving; -import org.eclipse.core.databinding.observable.list.IListChangeListener; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.ListChangeEvent; -import org.eclipse.core.databinding.observable.list.ObservableList; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.observable.value.ValueChangeEvent; -import org.eclipse.core.runtime.Assert; - -/** - * @since 3.2 - * - */ - -public class DetailObservableList extends ObservableList implements IObserving { - - private boolean updating = false; - - private IListChangeListener innerChangeListener = new IListChangeListener() { - public void handleListChange(ListChangeEvent event) { - if (!updating) { - fireListChange(event.diff); - } - } - }; - - private Object currentOuterValue; - - private IObservableList innerObservableList; - - private IObservableFactory factory; - - private IObservableValue outerObservableValue; - - private Object detailType; - - /** - * @param factory - * @param outerObservableValue - * @param detailType - */ - public DetailObservableList(IObservableFactory factory, - IObservableValue outerObservableValue, Object detailType) { - super(outerObservableValue.getRealm(), Collections.EMPTY_LIST, detailType); - this.factory = factory; - this.outerObservableValue = outerObservableValue; - this.detailType = detailType; - updateInnerObservableList(outerObservableValue); - - outerObservableValue.addValueChangeListener(outerChangeListener); - } - - IValueChangeListener outerChangeListener = new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - List oldList = new ArrayList(wrappedList); - updateInnerObservableList(outerObservableValue); - fireListChange(Diffs.computeListDiff(oldList, wrappedList)); - } - }; - - private void updateInnerObservableList(IObservableValue outerObservableValue) { - if (innerObservableList != null) { - innerObservableList.removeListChangeListener(innerChangeListener); - innerObservableList.dispose(); - } - currentOuterValue = outerObservableValue.getValue(); - if (currentOuterValue == null) { - innerObservableList = null; - wrappedList = Collections.EMPTY_LIST; - } else { - this.innerObservableList = (IObservableList) factory - .createObservable(currentOuterValue); - wrappedList = innerObservableList; - - if (detailType != null) { - Object innerValueType = innerObservableList.getElementType(); - Assert.isTrue(getElementType().equals(innerValueType), - "Cannot change value type in a nested observable list"); //$NON-NLS-1$ - } - innerObservableList.addListChangeListener(innerChangeListener); - } - } - - public boolean add(Object o) { - return wrappedList.add(o); - } - - public void add(int index, Object element) { - wrappedList.add(index, element); - } - - public boolean remove(Object o) { - return wrappedList.remove(o); - } - - public Object set(int index, Object element) { - return wrappedList.set(index, element); - } - - public Object move(int oldIndex, int newIndex) { - if (innerObservableList != null) - return innerObservableList.move(oldIndex, newIndex); - return super.move(oldIndex, newIndex); - } - - public Object remove(int index) { - return wrappedList.remove(index); - } - - public boolean addAll(Collection c) { - return wrappedList.addAll(c); - } - - public boolean addAll(int index, Collection c) { - return wrappedList.addAll(index, c); - } - - public boolean removeAll(Collection c) { - return wrappedList.removeAll(c); - } - - public boolean retainAll(Collection c) { - return wrappedList.retainAll(c); - } - - public void clear() { - wrappedList.clear(); - } - - public void dispose() { - super.dispose(); - - if (outerObservableValue != null) { - outerObservableValue.removeValueChangeListener(outerChangeListener); - outerObservableValue.dispose(); - } - if (innerObservableList != null) { - innerObservableList.removeListChangeListener(innerChangeListener); - innerObservableList.dispose(); - } - currentOuterValue = null; - factory = null; - innerObservableList = null; - innerChangeListener = null; - } - - public Object getObserved() { - if (innerObservableList instanceof IObserving) { - return ((IObserving) innerObservableList).getObserved(); - } - return null; - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/masterdetail/DetailObservableMap.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/masterdetail/DetailObservableMap.java deleted file mode 100644 index a57148c9..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/masterdetail/DetailObservableMap.java +++ /dev/null @@ -1,126 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 221704) - * Matthew Hall - bug 223114 - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable.masterdetail; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.map.IMapChangeListener; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.map.MapChangeEvent; -import org.eclipse.core.databinding.observable.map.ObservableMap; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.observable.value.ValueChangeEvent; - -/** - * @since 1.1 - * - */ -public class DetailObservableMap extends ObservableMap { - private boolean updating = false; - - private IObservableValue master; - private IObservableFactory detailFactory; - - private IObservableMap detailMap; - - private IValueChangeListener masterChangeListener = new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - Map oldMap = new HashMap(wrappedMap); - updateDetailMap(); - fireMapChange(Diffs.computeMapDiff(oldMap, wrappedMap)); - } - }; - - private IMapChangeListener detailChangeListener = new IMapChangeListener() { - public void handleMapChange(MapChangeEvent event) { - if (!updating) { - fireMapChange(event.diff); - } - } - }; - - /** - * Constructs a new DetailObservableMap - * - * @param detailFactory - * observable factory that creates IObservableMap instances given - * the current value of master observable value - * @param master - * - */ - public DetailObservableMap(IObservableFactory detailFactory, - IObservableValue master) { - super(master.getRealm(), Collections.EMPTY_MAP); - this.master = master; - this.detailFactory = detailFactory; - - updateDetailMap(); - master.addValueChangeListener(masterChangeListener); - } - - private void updateDetailMap() { - Object masterValue = master.getValue(); - if (detailMap != null) { - detailMap.removeMapChangeListener(detailChangeListener); - detailMap.dispose(); - } - - if (masterValue == null) { - detailMap = null; - wrappedMap = Collections.EMPTY_MAP; - } else { - detailMap = (IObservableMap) detailFactory - .createObservable(masterValue); - wrappedMap = detailMap; - detailMap.addMapChangeListener(detailChangeListener); - } - } - - public Object put(Object key, Object value) { - return detailMap.put(key, value); - } - - public void putAll(Map map) { - detailMap.putAll(map); - } - - public Object remove(Object key) { - return detailMap.remove(key); - } - - public void clear() { - detailMap.clear(); - } - - public synchronized void dispose() { - if (master != null) { - master.removeValueChangeListener(masterChangeListener); - master = null; - masterChangeListener = null; - } - detailFactory = null; - if (detailMap != null) { - detailMap.removeMapChangeListener(detailChangeListener); - detailMap.dispose(); - detailMap = null; - } - detailChangeListener = null; - super.dispose(); - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/masterdetail/DetailObservableSet.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/masterdetail/DetailObservableSet.java deleted file mode 100755 index dc0fc461..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/masterdetail/DetailObservableSet.java +++ /dev/null @@ -1,158 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005-2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 221351 - *******************************************************************************/ -package org.eclipse.core.internal.databinding.observable.masterdetail; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IObserving; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.ISetChangeListener; -import org.eclipse.core.databinding.observable.set.ObservableSet; -import org.eclipse.core.databinding.observable.set.SetChangeEvent; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.observable.value.ValueChangeEvent; -import org.eclipse.core.runtime.Assert; - -/** - * @since 3.2 - * - */ -public class DetailObservableSet extends ObservableSet implements IObserving { - - private boolean updating = false; - - private ISetChangeListener innerChangeListener = new ISetChangeListener() { - public void handleSetChange(SetChangeEvent event) { - if (!updating) { - fireSetChange(event.diff); - } - } - }; - - private Object currentOuterValue; - - private IObservableSet innerObservableSet; - - private IObservableValue outerObservableValue; - - private IObservableFactory factory; - - /** - * @param factory - * @param outerObservableValue - * @param detailType - */ - public DetailObservableSet(IObservableFactory factory, - IObservableValue outerObservableValue, Object detailType) { - super(outerObservableValue.getRealm(), Collections.EMPTY_SET, - detailType); - this.factory = factory; - this.outerObservableValue = outerObservableValue; - updateInnerObservableSet(outerObservableValue); - - outerObservableValue.addValueChangeListener(outerChangeListener); - } - - IValueChangeListener outerChangeListener = new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - Set oldSet = new HashSet(wrappedSet); - updateInnerObservableSet(outerObservableValue); - fireSetChange(Diffs.computeSetDiff(oldSet, wrappedSet)); - } - }; - - private void updateInnerObservableSet(IObservableValue outerObservableValue) { - currentOuterValue = outerObservableValue.getValue(); - if (innerObservableSet != null) { - innerObservableSet.removeSetChangeListener(innerChangeListener); - innerObservableSet.dispose(); - } - if (currentOuterValue == null) { - innerObservableSet = null; - wrappedSet = Collections.EMPTY_SET; - } else { - this.innerObservableSet = (IObservableSet) factory - .createObservable(currentOuterValue); - wrappedSet = innerObservableSet; - - if (elementType != null) { - Object innerValueType = innerObservableSet.getElementType(); - - Assert.isTrue(elementType.equals(innerValueType), - "Cannot change value type in a nested observable set"); //$NON-NLS-1$ - } - - innerObservableSet.addSetChangeListener(innerChangeListener); - } - } - - public boolean add(Object o) { - getterCalled(); - return wrappedSet.add(o); - } - - public boolean remove(Object o) { - getterCalled(); - return wrappedSet.remove(o); - } - - public boolean addAll(Collection c) { - getterCalled(); - return wrappedSet.addAll(c); - } - - public boolean removeAll(Collection c) { - getterCalled(); - return wrappedSet.removeAll(c); - } - - public boolean retainAll(Collection c) { - getterCalled(); - return wrappedSet.retainAll(c); - } - - public void clear() { - getterCalled(); - wrappedSet.clear(); - } - - public void dispose() { - super.dispose(); - - if (outerObservableValue != null) { - outerObservableValue.removeValueChangeListener(outerChangeListener); - outerObservableValue.dispose(); - } - if (innerObservableSet != null) { - innerObservableSet.removeSetChangeListener(innerChangeListener); - innerObservableSet.dispose(); - } - currentOuterValue = null; - factory = null; - innerObservableSet = null; - innerChangeListener = null; - } - - public Object getObserved() { - if (innerObservableSet instanceof IObserving) { - return ((IObserving) innerObservableSet).getObserved(); - } - return null; - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/masterdetail/DetailObservableValue.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/masterdetail/DetailObservableValue.java deleted file mode 100755 index c1b1654d..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/masterdetail/DetailObservableValue.java +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - * Brad Reynolds - bug 147515 - *******************************************************************************/ -package org.eclipse.core.internal.databinding.observable.masterdetail; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IObserving; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.value.AbstractObservableValue; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.observable.value.ValueChangeEvent; -import org.eclipse.core.runtime.Assert; - -/** - * @since 1.0 - * - */ -public class DetailObservableValue extends AbstractObservableValue implements IObserving { - - private boolean updating = false; - - private IValueChangeListener innerChangeListener = new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - if (!updating) { - fireValueChange(event.diff); - } - } - }; - - private Object currentOuterValue; - - private IObservableValue innerObservableValue; - - private Object detailType; - - private IObservableValue outerObservableValue; - - private IObservableFactory factory; - - /** - * @param outerObservableValue - * @param factory - * @param detailType - */ - public DetailObservableValue(IObservableValue outerObservableValue, - IObservableFactory factory, Object detailType) { - super(outerObservableValue.getRealm()); - this.factory = factory; - this.detailType = detailType; - this.outerObservableValue = outerObservableValue; - updateInnerObservableValue(outerObservableValue); - - outerObservableValue.addValueChangeListener(outerChangeListener); - } - - IValueChangeListener outerChangeListener = new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - Object oldValue = doGetValue(); - updateInnerObservableValue(outerObservableValue); - fireValueChange(Diffs.createValueDiff(oldValue, doGetValue())); - } - }; - - private void updateInnerObservableValue( - IObservableValue outerObservableValue) { - currentOuterValue = outerObservableValue.getValue(); - if (innerObservableValue != null) { - innerObservableValue.removeValueChangeListener(innerChangeListener); - innerObservableValue.dispose(); - } - if (currentOuterValue == null) { - innerObservableValue = null; - } else { - this.innerObservableValue = (IObservableValue) factory - .createObservable(currentOuterValue); - Object innerValueType = innerObservableValue.getValueType(); - - if (detailType != null) { - Assert - .isTrue( - detailType.equals(innerValueType), - "Cannot change value type in a nested observable value, from " + innerValueType + " to " + detailType); //$NON-NLS-1$ //$NON-NLS-2$ - } - innerObservableValue.addValueChangeListener(innerChangeListener); - } - } - - public void doSetValue(Object value) { - if (innerObservableValue != null) - innerObservableValue.setValue(value); - } - - public Object doGetValue() { - return innerObservableValue == null ? null : innerObservableValue - .getValue(); - } - - public Object getValueType() { - return detailType; - } - - public void dispose() { - super.dispose(); - - if (outerObservableValue != null) { - outerObservableValue.removeValueChangeListener(outerChangeListener); - outerObservableValue.dispose(); - } - if (innerObservableValue != null) { - innerObservableValue.removeValueChangeListener(innerChangeListener); - innerObservableValue.dispose(); - } - currentOuterValue = null; - factory = null; - innerObservableValue = null; - innerChangeListener = null; - } - - public Object getObserved() { - if (innerObservableValue instanceof IObserving) { - return ((IObserving)innerObservableValue).getObserved(); - } - return null; - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/AbstractObservableTree.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/AbstractObservableTree.java deleted file mode 100644 index e1226c9d..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/AbstractObservableTree.java +++ /dev/null @@ -1,151 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164134 - *******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable.tree; - -import org.eclipse.core.databinding.observable.AbstractObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.util.Policy; -import org.eclipse.core.internal.databinding.BindingMessages; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.ListenerList; -import org.eclipse.core.runtime.Status; - -/** - * @since 3.3 - * - */ -public abstract class AbstractObservableTree extends AbstractObservable - implements IObservableTree { - - private boolean stale; - - private ListenerList treeListeners = new ListenerList(ListenerList.IDENTITY); - - /** - * @param realm - */ - public AbstractObservableTree(Realm realm) { - super(realm); - } - - public void addChild(TreePath parentPath, Object childElement) { - throw new UnsupportedOperationException(); - } - - public void addTreeChangeListener(ITreeChangeListener listener) { - treeListeners.add(listener); - } - - public int getChildCount(TreePath parentPath) { - return getChildren(parentPath).length; - } - - public boolean hasChildren(TreePath parentPath) { - return getChildCount(parentPath) > 0; - } - - public void insertChild(TreePath parentPath, int index, Object childElement) { - throw new UnsupportedOperationException(); - } - - public boolean isLazy() { - return false; - } - - public boolean isOrdered() { - return false; - } - - public void removeChild(TreePath parentPath, Object childElement) { - throw new UnsupportedOperationException(); - } - - public void removeChild(TreePath parentPath, int index) { - throw new UnsupportedOperationException(); - } - - public void removeTreeChangeListener(ITreeChangeListener listener) { - treeListeners.remove(listener); - } - - public void setChildCount(TreePath parentPath, int count) { - throw new UnsupportedOperationException(); - } - - public void setChildren(TreePath parentPath, Object[] children) { - throw new UnsupportedOperationException(); - } - - public void updateChildren(IChildrenUpdate update) { - TreePath parent = update.getParent(); - Object[] children = getChildren(parent); - for (int i = 0; i < update.getLength(); i++) { - int targetIndex = update.getOffset() + i; - if (targetIndex < children.length) { - update.setChild(children[targetIndex], targetIndex); - } else { - update - .setStatus(new Status( - IStatus.WARNING, - Policy.JFACE_DATABINDING, - IStatus.OK, - BindingMessages - .getString(BindingMessages.INDEX_OUT_OF_RANGE), - null)); - } - } - update.done(); - } - - public void updateChildrenCount(IChildrenCountUpdate update) { - TreePath[] parents = update.getParents(); - for (int i = 0; i < parents.length; i++) { - update.setChildCount(parents[i], getChildCount(parents[i])); - } - update.done(); - } - - public void updateHasChildren(IHasChildrenUpdate update) { - TreePath[] parents = update.getElements(); - for (int i = 0; i < parents.length; i++) { - update.setHasChilren(parents[i], hasChildren(parents[i])); - } - update.done(); - } - - public boolean isStale() { - return stale; - } - - /** - * @param stale - */ - public void setStale(boolean stale) { - this.stale = stale; - if (stale) { - fireStale(); - } - } - - protected void fireTreeChange(TreeDiff diff) { - // fire general change event first - fireChange(); - - Object[] listeners = treeListeners.getListeners(); - TreeChangeEvent event = new TreeChangeEvent(this, diff); - for (int i = 0; i < listeners.length; i++) { - ((ITreeChangeListener) listeners[i]).handleTreeChange(event); - } - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/IChildrenCountUpdate.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/IChildrenCountUpdate.java deleted file mode 100644 index 331176a9..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/IChildrenCountUpdate.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.core.internal.databinding.observable.tree; - -/** - * Request monitor used to collect the number of children for an element in a lazy - * observable tree. - * - * @since 3.3 - */ -public interface IChildrenCountUpdate extends IViewerUpdate { - - /** - * Returns the parent elements that children counts have been requested for - * as tree paths. An empty path identifies the root element. - * - * @return parent elements as tree paths - */ - public TreePath[] getParents(); - - /** - * Sets the number of children for the given parent. - * - * @param parentPath - * parent element or empty path for root element - * @param numChildren - * number of children - */ - public void setChildCount(TreePath parentPath, int numChildren); -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/IChildrenUpdate.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/IChildrenUpdate.java deleted file mode 100644 index 8d4b961e..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/IChildrenUpdate.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.core.internal.databinding.observable.tree; - -/** - * Context sensitive children update request for a parent and subrange of its - * children. - * - * @since 3.3 - */ -public interface IChildrenUpdate extends IViewerUpdate { - - /** - * Returns the parent element that children are being requested for - * as a tree path. An empty path identifies the root element. - * - * @return parent element as a tree path - */ - public TreePath getParent(); - - /** - * Returns the offset at which children have been requested for. This is - * the index of the first child being requested. - * - * @return offset at which children have been requested for - */ - public int getOffset(); - - /** - * Returns the number of children requested. - * - * @return number of children requested - */ - public int getLength(); - - /** - * Sets the child for this request's parent at the given offset. - * - * @param child child - * @param index child offset - * - * TODO: what to do with <code>null</code> - */ - public void setChild(Object child, int index); -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/IHasChildrenUpdate.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/IHasChildrenUpdate.java deleted file mode 100644 index f3eadd65..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/IHasChildrenUpdate.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.core.internal.databinding.observable.tree; - -/** - * Context sensitive update request for whether elements have children. - * - * @since 3.3 - */ -public interface IHasChildrenUpdate extends IViewerUpdate { - - /** - * The elements this request is for specified as tree paths. An empty path - * identifies the root element. - * - * @return elements as tree paths - */ - public TreePath[] getElements(); - - /** - * Sets whether the given element has children. - * - * @param element - * tree path to element, or empty for root element - * @param hasChildren - * whether it has children - */ - public void setHasChilren(TreePath element, boolean hasChildren); -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/IObservableTree.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/IObservableTree.java deleted file mode 100644 index a8774528..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/IObservableTree.java +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable.tree; - -import org.eclipse.core.databinding.observable.IObservable; - -/** - * - * A tree whose changes can be tracked by tree change listeners. If the tree is - * ordered ({@link #isOrdered()}), the order of children for a given tree path - * matters, and tree change notifications will always specify indices. If the - * tree is unordered, the children of a tree path are an unordered set and - * indices in change notifications are not specified. - * - * <p> - * This interface is not intended to be implemented by clients. Clients should - * instead subclass one of the framework classes that implement this interface. - * Note that direct implementers of this interface outside of the framework will - * be broken in future releases when methods are added to this interface. - * </p> - * - * @since 1.1 - */ -public interface IObservableTree extends IObservable { - - /** - * Element that can be returned from synchronous getters if this observable - * tree is lazy. - */ - public final static Object UNKNOWN_ELEMENT = new Object(); - - /** - * @param listener - */ - public void addTreeChangeListener(ITreeChangeListener listener); - - /** - * @param listener - */ - public void removeTreeChangeListener(ITreeChangeListener listener); - - /** - * Returns whether the order of children for a given parent is important. If - * this tree is ordered, tree change notifications will always specify - * indices. - * - * @return true if the order of children for a given parent is important - */ - public boolean isOrdered(); - - /** - * Returns whether this tree is optimized to fetch subsets of children - * lazily and possibly asynchronously. Implies {@link #isOrdered()}. - * - * @return true if this tree - */ - public boolean isLazy(); - - /** - * @param parentPath - * @return the children at the given parent path - */ - public Object[] getChildren(TreePath parentPath); - - /** - * @param parentPath - * @param children - */ - public void setChildren(TreePath parentPath, Object[] children); - - /** - * @param parentPath - * @param childElement - */ - public void addChild(TreePath parentPath, Object childElement); - - /** - * @param parentPath - * @param childElement - */ - public void removeChild(TreePath parentPath, Object childElement); - - /** - * @param parentPath - * @param index - * @param childElement - */ - public void insertChild(TreePath parentPath, int index, Object childElement); - - /** - * @param parentPath - * @param index - */ - public void removeChild(TreePath parentPath, int index); - - /** - * @param parentPath - * @return <code>true</code> if the element at the given path has children - */ - public boolean hasChildren(TreePath parentPath); - - /** - * @param parentPath - * @return the number of children of the element at the given path - */ - public int getChildCount(TreePath parentPath); - - /** - * @param parentPath - * @param count - */ - public void setChildCount(TreePath parentPath, int count); - - /** - * Updates the number of children for the given parent elements in the - * specified request. - * - * @param update specifies counts to update and stores result - */ - public void updateChildrenCount(IChildrenCountUpdate update); - - /** - * Updates children as requested by the update. - * - * @param update specifies children to update and stores result - */ - public void updateChildren(IChildrenUpdate update); - - /** - * Updates whether elements have children. - * - * @param update specifies elements to update and stores result - */ - public void updateHasChildren(IHasChildrenUpdate update); - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/IOrderedTreeProvider.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/IOrderedTreeProvider.java deleted file mode 100644 index f60d5611..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/IOrderedTreeProvider.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable.tree; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IObservableList; - -/** - * Objects that implement this interface are capable of describing a tree by - * returning the list of children of any given element in the tree. - * - * @since 3.3 - */ -public interface IOrderedTreeProvider { - /** - * Returns the children of the given element, or null if the element is a - * leaf node. The caller of this method is expected to dispose the result - * list when it is no longer needed. - * - * @param element - * the tree path of the element to query - * @return the children of the given element, or null if the element is a - * leaf node - */ - IObservableList createChildList(TreePath element); - - /** - * @return the realm shared by all child lists - */ - Realm getRealm(); -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/ITreeChangeListener.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/ITreeChangeListener.java deleted file mode 100644 index 8fe9f8f5..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/ITreeChangeListener.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable.tree; - -/** - * @since 3.3 - * - */ -public interface ITreeChangeListener { - /** - * @param event - */ - void handleTreeChange(TreeChangeEvent event); - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/IUnorderedTreeProvider.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/IUnorderedTreeProvider.java deleted file mode 100644 index 81941c80..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/IUnorderedTreeProvider.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable.tree; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.set.IObservableSet; - -/** - * @since 1.0 - * - */ -public interface IUnorderedTreeProvider { - /** - * @return the realm for the createChildSet method - */ - public Realm getRealm(); - - /** - * Returns the children of the given element, or null if the element is a leaf node. - * The caller of this method is expected to dispose the result set when it is no - * longer needed. - * - * @param element element to query - * @return the children of the given element, or null if the element is a leaf node - */ - IObservableSet createChildSet(Object element); -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/IViewerUpdate.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/IViewerUpdate.java deleted file mode 100644 index 26cadab4..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/IViewerUpdate.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.core.internal.databinding.observable.tree; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; - -/** - * A context sensitive viewer update request. - * - * @since 3.3 - */ -public interface IViewerUpdate extends IProgressMonitor { - - /** - * Sets the status of this request, possibly <code>null</code>. - * When a request fails, the status indicates why the request failed. - * A <code>null</code> status is considered to be successful. - * - * @param status request status - */ - public void setStatus(IStatus status); - - /** - * Returns the status of this request, or <code>null</code>. - * - * @return request status or <code>null</code> - */ - public IStatus getStatus(); - - /** - * Returns the model element corresponding to the given tree path. - * Returns the root element for the empty path. - * - * @param path viewer tree path - * @return corresponding model element - */ - public Object getElement(TreePath path); -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/TreeChangeEvent.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/TreeChangeEvent.java deleted file mode 100644 index b5051d5e..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/TreeChangeEvent.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable.tree; - -import java.util.EventObject; - -/** - * @since 3.3 - * - */ -public class TreeChangeEvent extends EventObject { - - /** - * - */ - private static final long serialVersionUID = -3198503763995528027L; - /** - * - */ - public TreeDiff diff; - - /** - * @param source - * @param diff - */ - public TreeChangeEvent(IObservableTree source, TreeDiff diff) { - super(source); - this.diff = diff; - } - - /** - * @return the observable tree from which this event originated - */ - public IObservableTree getObservable() { - return (IObservableTree) getSource(); - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/TreeDiff.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/TreeDiff.java deleted file mode 100644 index 7c419ea5..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/TreeDiff.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable.tree; - -/** - * Describes the difference between two trees as a tree of tree diff nodes. - * - * @since 1.1 - * - */ -public abstract class TreeDiff extends TreeDiffNode { - - /** - * Returns the tree path (possibly empty) of the parent, or - * <code>null</code> if the underlying tree is not lazy and never contains - * duplicate elements. - * - * @return the tree path (possibly empty) of the unchanged parent, or - * <code>null</code> - */ - public abstract TreePath getParentPath(); - - /** - * @param visitor - */ - public void accept(TreeDiffVisitor visitor) { - doAccept(visitor, getParentPath()); - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/TreeDiffNode.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/TreeDiffNode.java deleted file mode 100644 index a8b8b8d9..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/TreeDiffNode.java +++ /dev/null @@ -1,91 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable.tree; - -/** - * @since 1.1 - * - */ -public abstract class TreeDiffNode { - - /** - * - */ - public final static int NO_CHANGE = 0x00; - - /** - * - */ - public final static int ADDED = 0x01; - - /** - * - */ - public final static int REMOVED = 0x02; - - /** - * - */ - public final static int REPLACED = 0x03; - - /** - * - */ - public static final TreeDiffNode[] NO_CHILDREN = new TreeDiffNode[0]; - - /** - * - */ - public static final int INDEX_UNKNOWN = -1; - - /** - * @return the change type - */ - public abstract int getChangeType(); - - /** - * @return the element that was removed, or the replaced element - */ - public abstract Object getOldElement(); - - /** - * @return the element that was not changed, added, or the replacement - * element - */ - public abstract Object getNewElement(); - - /** - * @return the index at which the element was added, removed, or replaced - */ - public abstract int getIndex(); - - /** - * Returns the child tree diff objects that describe changes to children. If - * the change type is REMOVED, there will be no children. - * - * @return the nodes representing changes to children - */ - public abstract TreeDiffNode[] getChildren(); - - protected void doAccept(TreeDiffVisitor visitor, TreePath parentPath) { - TreePath currentPath = parentPath.createChildPath(getNewElement()); - boolean recurse = visitor.visit(this, currentPath); - if (recurse) { - TreeDiffNode[] children = getChildren(); - for (int i = 0; i < children.length; i++) { - TreeDiffNode child = children[i]; - child.doAccept(visitor, currentPath); - } - } - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/TreeDiffVisitor.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/TreeDiffVisitor.java deleted file mode 100644 index 837464dc..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/TreeDiffVisitor.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable.tree; - -/** - * @since 3.3 - * - */ -public abstract class TreeDiffVisitor { - - /** - * Visits the given tree diff. - * - * @param diff - * the diff to visit - * @param currentPath - * the current path (the diff's element is the last segment of - * the path) - * - * @return <code>true</code> if the tree diff's children should be - * visited; <code>false</code> if they should be skipped. - */ - public abstract boolean visit(TreeDiffNode diff, TreePath currentPath); -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/TreePath.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/TreePath.java deleted file mode 100644 index 99e987c1..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/TreePath.java +++ /dev/null @@ -1,183 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 118516 - *******************************************************************************/ -package org.eclipse.core.internal.databinding.observable.tree; - -import org.eclipse.core.runtime.Assert; - -/** - * A tree path denotes a model element in a tree viewer. Tree path objects have - * value semantics. A model element is represented by a path of elements in the - * tree from the root element to the leaf element. - * <p> - * Clients may instantiate this class. Not intended to be subclassed. - * </p> - * - * @since 3.2 - */ -public final class TreePath { - - /** - * Constant for representing an empty tree path. - */ - public static final TreePath EMPTY = new TreePath(new Object[0]); - - private Object[] segments; - - private int hash; - - /** - * Constructs a path identifying a leaf node in a tree. - * - * @param segments - * path of elements to a leaf node in a tree, starting with the - * root element - */ - public TreePath(Object[] segments) { - Assert.isNotNull(segments, "Segments array cannot be null"); //$NON-NLS-1$ - this.segments = new Object[segments.length]; - for (int i = 0; i < segments.length; i++) { - Assert.isNotNull(segments[i], "Segments array cannot contain null"); //$NON-NLS-1$ - this.segments[i] = segments[i]; - } - } - - /** - * Returns the element at the specified index in this path. - * - * @param index - * index of element to return - * @return element at the specified index - */ - public Object getSegment(int index) { - return segments[index]; - } - - /** - * Returns the number of elements in this path. - * - * @return the number of elements in this path - */ - public int getSegmentCount() { - return segments.length; - } - - /** - * Returns the first element in this path. - * - * @return the first element in this path - */ - public Object getFirstSegment() { - if (segments.length == 0) { - return null; - } - return segments[0]; - } - - /** - * Returns the last element in this path. - * - * @return the last element in this path - */ - public Object getLastSegment() { - if (segments.length == 0) { - return null; - } - return segments[segments.length - 1]; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean equals(Object other) { - if (!(other instanceof TreePath)) { - return false; - } - TreePath otherPath = (TreePath) other; - if (segments.length != otherPath.segments.length) { - return false; - } - for (int i = 0; i < segments.length; i++) { - if (!segments[i].equals(otherPath.segments[i])) { - return false; - } - } - return true; - } - - public int hashCode() { - if (hash == 0) { - for (int i = 0; i < segments.length; i++) { - hash += segments[i].hashCode(); - } - } - return hash; - } - - /** - * Returns whether this path starts with the same segments as the given - * path, using the given comparer to compare segments. - * - * @param treePath - * path to compare to - * @return whether the given path is a prefix of this path, or the same as - * this path - */ - public boolean startsWith(TreePath treePath) { - int thisSegmentCount = getSegmentCount(); - int otherSegmentCount = treePath.getSegmentCount(); - if (otherSegmentCount == thisSegmentCount) { - return equals(treePath); - } - if (otherSegmentCount > thisSegmentCount) { - return false; - } - for (int i = 0; i < otherSegmentCount; i++) { - Object otherSegment = treePath.getSegment(i); - if (!otherSegment.equals(segments[i])) { - return false; - } - } - return true; - } - - /** - * Returns a copy of this tree path with one segment removed from the end, - * or <code>null</code> if this tree path has no segments. - * @return a tree path - */ - public TreePath getParentPath() { - int segmentCount = getSegmentCount(); - if (segmentCount <= 1) { - return null; - } - Object[] parentSegments = new Object[segmentCount - 1]; - System.arraycopy(segments, 0, parentSegments, 0, segmentCount - 1); - return new TreePath(parentSegments); - } - - /** - * Returns a copy of this tree path with the given segment added at the end. - * @param newSegment - * @return a tree path - */ - public TreePath createChildPath(Object newSegment) { - int segmentCount = getSegmentCount(); - Object[] childSegments = new Object[segmentCount + 1]; - if(segmentCount>0) { - System.arraycopy(segments, 0, childSegments, 0, segmentCount); - } - childSegments[segmentCount] = newSegment; - return new TreePath(childSegments); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/package.html b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/package.html deleted file mode 100644 index d720e2b4..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/tree/package.html +++ /dev/null @@ -1,16 +0,0 @@ -<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> - <meta name="Author" content="IBM"> - <meta name="GENERATOR" content="Mozilla/4.5 [en] (Win98; I) [Netscape]"> - <title>Package-level Javadoc</title> -</head> -<body> -To be written. -<h2> -Package Specification</h2> -<p> -This package provides classes that can be used to ...</p> -</body> -</html> diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/AbstractStringToNumberValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/AbstractStringToNumberValidator.java deleted file mode 100644 index 3cf8f0b2..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/AbstractStringToNumberValidator.java +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.validation; - -import org.eclipse.core.databinding.validation.IValidator; -import org.eclipse.core.databinding.validation.ValidationStatus; -import org.eclipse.core.internal.databinding.conversion.StringToNumberParser; -import org.eclipse.core.internal.databinding.conversion.StringToNumberParser.ParseResult; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; - -/** - * Validates a number that is to be converted by a {@link NumberFormatConverter}. - * Validation is comprised of parsing the String and range checks. - * - * @since 1.0 - */ -public abstract class AbstractStringToNumberValidator implements IValidator { - private final NumberFormatConverter converter; - private final boolean toPrimitive; - - private final Number min; - private final Number max; - - private String outOfRangeMessage; - - /** - * Constructs a new instance. - * - * @param converter converter and thus formatter to be used in validation - * @param min minimum value, used for reporting a range error to the user - * @param max maximum value, used for reporting a range error to the user - */ - protected AbstractStringToNumberValidator(NumberFormatConverter converter, - Number min, Number max) { - this.converter = converter; - this.min = min; - this.max = max; - - if (converter.getToType() instanceof Class) { - Class clazz = (Class) converter.getToType(); - toPrimitive = clazz.isPrimitive(); - } else { - toPrimitive = false; - } - } - - /** - * Validates the provided <code>value</code>. An error status is returned if: - * <ul> - * <li>The value cannot be parsed.</li> - * <li>The value is out of range.</li> - * </ul> - * - * @see org.eclipse.core.databinding.validation.IValidator#validate(java.lang.Object) - */ - public final IStatus validate(Object value) { - ParseResult result = StringToNumberParser.parse(value, converter - .getNumberFormat(), toPrimitive); - - if (result.getNumber() != null) { - if (!isInRange(result.getNumber())) { - if (outOfRangeMessage == null) { - outOfRangeMessage = StringToNumberParser - .createOutOfRangeMessage(min, max, converter - .getNumberFormat()); - } - - return ValidationStatus.error(outOfRangeMessage); - } - } else if (result.getPosition() != null) { - String parseErrorMessage = StringToNumberParser.createParseErrorMessage( - (String) value, result.getPosition()); - - return ValidationStatus.error(parseErrorMessage); - } - - return Status.OK_STATUS; - } - - /** - * Invoked by {@link #validate(Object)} when the range is to be validated. - * - * @param number - * @return <code>true</code> if in range - */ - protected abstract boolean isInRange(Number number); -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberFormatConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberFormatConverter.java deleted file mode 100644 index f8493298..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberFormatConverter.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.validation; - -import org.eclipse.core.databinding.conversion.Converter; - -import com.ibm.icu.text.NumberFormat; - -/** - * Converter that uses a number format for conversion. - * - * @since 1.0 - */ -public abstract class NumberFormatConverter extends Converter { - private final NumberFormat numberFormat; - - /** - * @param fromType - * @param toType - * @param numberFormat - */ - public NumberFormatConverter(Object fromType, Object toType, NumberFormat numberFormat) { - super(fromType, toType); - - this.numberFormat = numberFormat; - } - - /** - * @return number format - */ - /*package */ NumberFormat getNumberFormat() { - return numberFormat; - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberToByteValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberToByteValidator.java deleted file mode 100644 index cdb16f5f..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberToByteValidator.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.validation; - -import org.eclipse.core.internal.databinding.conversion.NumberToByteConverter; -import org.eclipse.core.internal.databinding.conversion.StringToNumberParser; - -/** - * Validates if a Number can fit in a Byte. - * <p> - * Class is thread safe. - * </p> - * - * @since 1.0 - */ -public class NumberToByteValidator extends NumberToNumberValidator { - private static final Byte MAX = new Byte(Byte.MAX_VALUE); - private static final Byte MIN = new Byte(Byte.MIN_VALUE); - - /** - * @param converter - */ - public NumberToByteValidator(NumberToByteConverter converter) { - super(converter, MIN, MAX); - } - - /* (non-Javadoc) - * @see org.eclipse.core.internal.databinding.validation.NumberToNumberValidator#inRange(java.lang.Number) - */ - protected boolean inRange(Number number) { - return StringToNumberParser.inByteRange(number); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberToDoubleValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberToDoubleValidator.java deleted file mode 100644 index 42065207..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberToDoubleValidator.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.validation; - -import org.eclipse.core.internal.databinding.conversion.NumberToDoubleConverter; -import org.eclipse.core.internal.databinding.conversion.StringToNumberParser; - -/** - * Validates if a Number can fit in a Double. - * <p> - * Class is thread safe. - * </p> - * @since 1.0 - */ -public class NumberToDoubleValidator extends NumberToNumberValidator { - private static final Double MIN = new Double(Double.MIN_VALUE); - private static final Double MAX = new Double(Double.MAX_VALUE); - - /** - * @param converter - */ - public NumberToDoubleValidator(NumberToDoubleConverter converter) { - super(converter, MIN, MAX); - } - - /* (non-Javadoc) - * @see org.eclipse.core.internal.databinding.validation.NumberToNumberValidator#inRange(java.lang.Number) - */ - protected boolean inRange(Number number) { - return StringToNumberParser.inDoubleRange(number); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberToFloatValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberToFloatValidator.java deleted file mode 100644 index 4fe3b8e9..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberToFloatValidator.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.validation; - -import org.eclipse.core.internal.databinding.conversion.NumberToFloatConverter; -import org.eclipse.core.internal.databinding.conversion.StringToNumberParser; - -/** - * Validates if a Number can fit in a Float. - * <p> - * Class is thread safe. - * </p> - * @since 1.0 - */ -public class NumberToFloatValidator extends NumberToNumberValidator { - private static final Float MIN = new Float(Float.MIN_VALUE); - private static final Float MAX = new Float(Float.MAX_VALUE); - - /** - * @param converter - */ - public NumberToFloatValidator(NumberToFloatConverter converter) { - super(converter, MIN, MAX); - } - - /* (non-Javadoc) - * @see org.eclipse.core.internal.databinding.validation.NumberToNumberValidator#inRange(java.lang.Number) - */ - protected boolean inRange(Number number) { - return StringToNumberParser.inFloatRange(number); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberToIntegerValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberToIntegerValidator.java deleted file mode 100644 index fe78bce6..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberToIntegerValidator.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.validation; - -import org.eclipse.core.internal.databinding.conversion.NumberToIntegerConverter; -import org.eclipse.core.internal.databinding.conversion.StringToNumberParser; - -/** - * Validates if a Number can fit in a Integer. - * <p> - * Class is thread safe. - * </p> - * @since 1.0 - */ -public class NumberToIntegerValidator extends NumberToNumberValidator { - private static final Integer MIN = new Integer(Integer.MIN_VALUE); - private static final Integer MAX = new Integer(Integer.MAX_VALUE); - - /** - * @param converter - */ - public NumberToIntegerValidator(NumberToIntegerConverter converter) { - super(converter, MIN, MAX); - } - - /* (non-Javadoc) - * @see org.eclipse.core.internal.databinding.validation.NumberToNumberValidator#inRange(java.lang.Number) - */ - protected boolean inRange(Number number) { - return StringToNumberParser.inIntegerRange(number); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberToLongValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberToLongValidator.java deleted file mode 100644 index 2c2fdb88..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberToLongValidator.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.validation; - -import org.eclipse.core.internal.databinding.conversion.NumberToLongConverter; -import org.eclipse.core.internal.databinding.conversion.StringToNumberParser; - -/** - * Validates if a Number can fit in a Long. - * <p> - * Class is thread safe. - * </p> - * @since 1.0 - */ -public class NumberToLongValidator extends NumberToNumberValidator { - private static final Long MIN = new Long(Long.MIN_VALUE); - private static final Long MAX = new Long(Long.MAX_VALUE); - - /** - * @param converter - */ - public NumberToLongValidator(NumberToLongConverter converter) { - super(converter, MIN, MAX); - } - - /* (non-Javadoc) - * @see org.eclipse.core.internal.databinding.validation.NumberToNumberValidator#inRange(java.lang.Number) - */ - protected boolean inRange(Number number) { - return StringToNumberParser.inLongRange(number); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberToNumberValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberToNumberValidator.java deleted file mode 100644 index 957e75b9..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberToNumberValidator.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.validation; - -import org.eclipse.core.databinding.validation.IValidator; -import org.eclipse.core.databinding.validation.ValidationStatus; -import org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter; -import org.eclipse.core.internal.databinding.conversion.StringToNumberParser; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; - -/** - * Base class for validators that validate if a Number can fit in another Number type. - * <p> - * Class is thread safe. - * </p> - * - * @since 1.0 - */ -public abstract class NumberToNumberValidator implements IValidator { - private final NumberToNumberConverter converter; - - private final Number min; - - private final Number max; - - private String outOfRangeMessage; - - private final boolean primitive; - - /** - * @param converter - * @param min - * can be <code>null</code> - * @param max - * can be <code>null</code> - */ - protected NumberToNumberValidator(NumberToNumberConverter converter, - Number min, Number max) { - this.converter = converter; - this.min = min; - this.max = max; - - primitive = ((Class) converter.getToType()).isPrimitive(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.validation.IValidator#validate(java.lang.Object) - */ - public final IStatus validate(Object value) { - if (value == null) { - if (primitive) { - throw new IllegalArgumentException( - "Parameter 'value' cannot be null."); //$NON-NLS-1$ - } - - return Status.OK_STATUS; - } - - if (!(value instanceof Number)) { - throw new IllegalArgumentException( - "Parameter 'value' is not of type Number."); //$NON-NLS-1$ - } - - Number number = (Number) value; - if (inRange(number)) { - return Status.OK_STATUS; - } - - synchronized (this) { - if (outOfRangeMessage == null && min != null && max != null) { - outOfRangeMessage = StringToNumberParser - .createOutOfRangeMessage(min, max, converter - .getNumberFormat()); - } - - return ValidationStatus.error(outOfRangeMessage); - } - } - - /** - * Invoked to determine if the value is in range. - * - * @param number - * @return <code>true</code> if in range - */ - protected abstract boolean inRange(Number number); -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberToShortValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberToShortValidator.java deleted file mode 100644 index c7fa8d85..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberToShortValidator.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.validation; - -import org.eclipse.core.internal.databinding.conversion.NumberToShortConverter; -import org.eclipse.core.internal.databinding.conversion.StringToNumberParser; - -/** - * Validates if a Number can fit in a Short. - * <p> - * Class is thread safe. - * </p> - * - * @since 1.0 - */ -public class NumberToShortValidator extends NumberToNumberValidator { - private static final Short MIN = new Short(Short.MIN_VALUE); - private static final Short MAX = new Short(Short.MAX_VALUE); - - /** - * @param converter - */ - public NumberToShortValidator(NumberToShortConverter converter) { - super(converter, MIN, MAX); - } - - /* (non-Javadoc) - * @see org.eclipse.core.internal.databinding.validation.NumberToNumberValidator#inRange(java.lang.Number) - */ - protected boolean inRange(Number number) { - return StringToNumberParser.inShortRange(number); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberToUnboundedNumberValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberToUnboundedNumberValidator.java deleted file mode 100644 index 7919c5a5..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberToUnboundedNumberValidator.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.validation; - -import org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter; - -/** - * Validates if a Number can fit in an unbounded number (e.g. BigInteger, BigDecimal, etc.). - * <p> - * Class is thread safe. - * </p> - * - * @since 1.0 - */ -public class NumberToUnboundedNumberValidator extends NumberToNumberValidator { - /** - * @param converter - */ - public NumberToUnboundedNumberValidator(NumberToNumberConverter converter) { - super(converter, null, null); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.internal.databinding.validation.NumberToNumberValidator#inRange(java.lang.Number) - */ - protected boolean inRange(Number number) { - return true; - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ObjectToPrimitiveValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ObjectToPrimitiveValidator.java deleted file mode 100755 index 67b46f98..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ObjectToPrimitiveValidator.java +++ /dev/null @@ -1,85 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Tom Schindl<tom.schindl@bestsolution.at> - bugfix for 217940 - *******************************************************************************/ - -package org.eclipse.core.internal.databinding.validation; - -import org.eclipse.core.databinding.validation.IValidator; -import org.eclipse.core.databinding.validation.ValidationStatus; -import org.eclipse.core.internal.databinding.BindingMessages; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; - -/** - * @since 3.2 - * - */ -public class ObjectToPrimitiveValidator implements IValidator { - - private Class toType; - - private Class[][] primitiveMap = new Class[][] { - { Integer.TYPE, Integer.class }, { Short.TYPE, Short.class }, - { Long.TYPE, Long.class }, { Double.TYPE, Double.class }, - { Byte.TYPE, Byte.class }, { Float.TYPE, Float.class }, - { Boolean.TYPE, Boolean.class }, - { Character.TYPE, Character.class } }; - - /** - * @param toType - */ - public ObjectToPrimitiveValidator(Class toType) { - this.toType = toType; - } - - protected Class getToType() { - return this.toType; - } - - public IStatus validate(Object value) { - return doValidate(value); - } - - private IStatus doValidate(Object value) { - if (value != null) { - if (!mapContainsValues(toType, value.getClass())) { - return ValidationStatus.error(getClassHint()); - } - return Status.OK_STATUS; - } - return ValidationStatus.error(getNullHint()); - } - - private boolean mapContainsValues(Class toType, Class fromType) { - for (int i = 0; i < primitiveMap.length; i++) { - if ((primitiveMap[i][0].equals(toType)) - && (primitiveMap[i][1].equals(fromType))) { - return true; - } - } - return false; - } - - /** - * @return a hint string - */ - public String getNullHint() { - return BindingMessages.getString(BindingMessages.VALIDATE_CONVERSION_TO_PRIMITIVE); - } - - /** - * @return a hint string - */ - public String getClassHint() { - return BindingMessages - .getString(BindingMessages.VALIDATE_CONVERSION_FROM_CLASS_TO_PRIMITIVE); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ReadOnlyValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ReadOnlyValidator.java deleted file mode 100755 index 8ebc6518..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ReadOnlyValidator.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2005, 2006 db4objects Inc. (http://www.db4o.com) 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: - * db4objects - Initial API and implementation - * Boris Bokowski (IBM Corporation) - bug 118429 - * Tom Schindl<tom.schindl@bestsolution.at> - bugfix for 217940 - */ -package org.eclipse.core.internal.databinding.validation; - -import org.eclipse.core.databinding.validation.IValidator; -import org.eclipse.core.databinding.validation.ValidationStatus; -import org.eclipse.core.internal.databinding.BindingMessages; -import org.eclipse.core.runtime.IStatus; - -/** - * ReadOnlyValidator. A validator that can be used as a partial validator for read-only fields. - */ -public class ReadOnlyValidator implements IValidator { - - private static ReadOnlyValidator singleton = null; - - /** - * Returns the ReadOnlyValidator - * - * @return the ReadOnlyValidator - */ - public static ReadOnlyValidator getDefault() { - if (singleton == null) { - singleton = new ReadOnlyValidator(); - } - return singleton; - } - - public IStatus validate(Object value) { - // No changes are allowed - return ValidationStatus.error(BindingMessages - .getString(BindingMessages.VALIDATE_NO_CHANGE_ALLOWED_HELP)); - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToByteValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToByteValidator.java deleted file mode 100644 index 2b7bdc4d..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToByteValidator.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.validation; - -import org.eclipse.core.internal.databinding.conversion.StringToNumberParser; - -/** - * @since 1.0 - */ -public class StringToByteValidator extends AbstractStringToNumberValidator { - private static final Byte MIN = new Byte(Byte.MIN_VALUE); - private static final Byte MAX = new Byte(Byte.MAX_VALUE); - - /** - * @param converter - */ - public StringToByteValidator(NumberFormatConverter converter) { - super(converter, MIN, MAX); - } - - /* (non-Javadoc) - * @see org.eclipse.core.internal.databinding.validation.AbstractStringToNumberValidator#isInRange(java.lang.Number) - */ - protected boolean isInRange(Number number) { - return StringToNumberParser.inByteRange(number); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToCharacterValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToCharacterValidator.java deleted file mode 100644 index fda38a96..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToCharacterValidator.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Matt Carter 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: - * Matt Carter - initial API and implementation - * Tom Schindl<tom.schindl@bestsolution.at> - bugfix for 217940 - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.validation; - -import org.eclipse.core.databinding.validation.IValidator; -import org.eclipse.core.databinding.validation.ValidationStatus; -import org.eclipse.core.internal.databinding.BindingMessages; -import org.eclipse.core.internal.databinding.conversion.StringToCharacterConverter; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; - -/** - * Validates a String to Character conversion. - */ -public class StringToCharacterValidator implements IValidator { - - private final StringToCharacterConverter converter; - - /** - * @param converter - */ - public StringToCharacterValidator(StringToCharacterConverter converter) { - this.converter = converter; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.validation.IValidator#validate(java.lang.Object) - */ - public IStatus validate(Object value) { - try { - converter.convert(value); - } catch (IllegalArgumentException e) { - // The StringToCharacterConverter throws an IllegalArgumentException - // if it cannot convert. - return ValidationStatus.error(BindingMessages - .getString(BindingMessages.VALIDATE_CHARACTER_HELP)); - } - return Status.OK_STATUS; - } - -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToDateValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToDateValidator.java deleted file mode 100644 index 9aaf642d..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToDateValidator.java +++ /dev/null @@ -1,108 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Tom Schindl<tom.schindl@bestsolution.at> - bugfix for 217940 - *******************************************************************************/ - -package org.eclipse.core.internal.databinding.validation; - -import java.util.Date; - -import org.eclipse.core.databinding.validation.IValidator; -import org.eclipse.core.databinding.validation.ValidationStatus; -import org.eclipse.core.internal.databinding.BindingMessages; -import org.eclipse.core.internal.databinding.conversion.DateConversionSupport; -import org.eclipse.core.internal.databinding.conversion.StringToDateConverter; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; - -/** - * @since 1.0 - */ -public class StringToDateValidator implements IValidator { - private final StringToDateConverter converter; - - /** - * @param converter - */ - public StringToDateValidator(StringToDateConverter converter) { - this.converter = converter; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.validation.IValidator#validate(java.lang.Object) - */ - public IStatus validate(Object value) { - if (value instanceof String && ((String)value).trim().length()==0) { - return Status.OK_STATUS; - } - Object convertedValue = converter.convert(value); - //The StringToDateConverter returns null if it can't parse the date. - if (convertedValue == null) { - return ValidationStatus.error(getErrorMessage()); - } - - return Status.OK_STATUS; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.internal.databinding.validation.WrappedConverterValidator#getErrorMessage() - */ - protected String getErrorMessage() { - Date sampleDate = new Date(); - - // FIXME We need to use the information from the - // converter, not use another instance of DateConversionSupport. - FormatUtil util = new FormatUtil(); - StringBuffer samples = new StringBuffer(); - for (int formatterIdx = 1; formatterIdx < util.numFormatters() - 2; formatterIdx++) { - samples.append('\''); - samples.append(util.format(sampleDate, formatterIdx)); - samples.append("', "); //$NON-NLS-1$ - } - samples.append('\''); - samples.append(util.format(sampleDate, 0)); - samples.append('\''); - return BindingMessages.getString(BindingMessages.EXAMPLES) + ": " + samples + ",..."; //$NON-NLS-1$//$NON-NLS-2$ - } - - private static class FormatUtil extends DateConversionSupport { - /* - * (non-Javadoc) - * - * @see org.eclipse.core.internal.databinding.conversion.DateConversionSupport#numFormatters() - */ - protected int numFormatters() { - return super.numFormatters(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.internal.databinding.conversion.DateConversionSupport#format(java.util.Date) - */ - protected String format(Date date) { - return super.format(date); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.internal.databinding.conversion.DateConversionSupport#format(java.util.Date, - * int) - */ - protected String format(Date date, int formatterIdx) { - return super.format(date, formatterIdx); - } - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToDoubleValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToDoubleValidator.java deleted file mode 100644 index 2e0d0fc9..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToDoubleValidator.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.validation; - -import org.eclipse.core.internal.databinding.conversion.StringToNumberParser; - -/** - * @since 1.0 - */ -public class StringToDoubleValidator extends AbstractStringToNumberValidator { - private static final Double MIN = new Double(-Double.MAX_VALUE); - private static final Double MAX = new Double(Double.MAX_VALUE); - - /** - * @param converter - */ - public StringToDoubleValidator(NumberFormatConverter converter) { - super(converter, MIN, MAX); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.internal.databinding.validation.AbstractStringToNumberValidator#inRange(java.lang.Number) - */ - protected boolean isInRange(Number number) { - return StringToNumberParser.inDoubleRange(number); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToFloatValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToFloatValidator.java deleted file mode 100644 index 6ce01e43..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToFloatValidator.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.validation; - -import org.eclipse.core.internal.databinding.conversion.StringToNumberParser; - -/** - * Validates that a string is of the appropriate format and is in the range of a - * float. - * - * @since 1.0 - */ -public class StringToFloatValidator extends AbstractStringToNumberValidator { - - private static final Float MIN = new Float(-Float.MAX_VALUE); - private static final Float MAX = new Float(Float.MAX_VALUE); - - /** - * @param converter - */ - public StringToFloatValidator(NumberFormatConverter converter) { - super(converter, MIN, MAX); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.internal.databinding.validation.AbstractStringToNumberValidator#inRange(java.lang.Number) - */ - protected boolean isInRange(Number number) { - return StringToNumberParser.inFloatRange(number); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToIntegerValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToIntegerValidator.java deleted file mode 100644 index 6b8fb242..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToIntegerValidator.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.validation; - -import org.eclipse.core.internal.databinding.conversion.StringToNumberParser; - - -/** - * Validates that a string is of the appropriate format and is in the range of - * an integer. - * - * @since 1.0 - */ -public class StringToIntegerValidator extends AbstractStringToNumberValidator { - private static final Integer MIN = new Integer(Integer.MIN_VALUE); - private static final Integer MAX = new Integer(Integer.MAX_VALUE); - - /** - * @param converter - */ - public StringToIntegerValidator(NumberFormatConverter converter) { - super(converter, MIN, MAX); - } - - /* (non-Javadoc) - * @see org.eclipse.core.internal.databinding.validation.AbstractStringToNumberValidator#inRange(java.lang.Number) - */ - protected boolean isInRange(Number number) { - return StringToNumberParser.inIntegerRange(number); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToLongValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToLongValidator.java deleted file mode 100644 index 10cd47f0..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToLongValidator.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.validation; - -import org.eclipse.core.internal.databinding.conversion.StringToNumberParser; - -/** - * Validates that a string is of the appropriate format and is in the range of - * an long. - * - * @since 1.0 - */ -public class StringToLongValidator extends AbstractStringToNumberValidator { - private static final Long MIN = new Long(Long.MIN_VALUE); - private static final Long MAX = new Long(Long.MAX_VALUE); - - /** - * @param converter - */ - public StringToLongValidator(NumberFormatConverter converter) { - super(converter, MIN, MAX); - } - - /* (non-Javadoc) - * @see org.eclipse.core.internal.databinding.validation.AbstractStringToNumberValidator#inRange(java.lang.Number) - */ - protected boolean isInRange(Number number) { - return StringToNumberParser.inLongRange(number); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToShortValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToShortValidator.java deleted file mode 100644 index eaf16b29..00000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToShortValidator.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.validation; - -import org.eclipse.core.internal.databinding.conversion.StringToNumberParser; - -/** - * @since 1.0 - */ -public class StringToShortValidator extends AbstractStringToNumberValidator { - private static final Short MIN = new Short(Short.MIN_VALUE); - private static final Short MAX = new Short(Short.MAX_VALUE); - - /** - * @param converter - */ - public StringToShortValidator(NumberFormatConverter converter) { - super(converter, MIN, MAX); - } - - /* (non-Javadoc) - * @see org.eclipse.core.internal.databinding.validation.AbstractStringToNumberValidator#inRange(java.lang.Number) - */ - protected boolean isInRange(Number number) { - return StringToNumberParser.inShortRange(number); - } -} diff --git a/bundles/org.eclipse.jface.databinding/.classpath b/bundles/org.eclipse.jface.databinding/.classpath deleted file mode 100644 index c2ce266a..00000000 --- a/bundles/org.eclipse.jface.databinding/.classpath +++ /dev/null @@ -1,7 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/CDC-1.0%Foundation-1.0"/> - <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> - <classpathentry kind="src" path="src"/> - <classpathentry kind="output" path="bin"/> -</classpath> diff --git a/bundles/org.eclipse.jface.databinding/.cvsignore b/bundles/org.eclipse.jface.databinding/.cvsignore deleted file mode 100644 index ba077a40..00000000 --- a/bundles/org.eclipse.jface.databinding/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -bin diff --git a/bundles/org.eclipse.jface.databinding/.project b/bundles/org.eclipse.jface.databinding/.project deleted file mode 100644 index c1c9d28c..00000000 --- a/bundles/org.eclipse.jface.databinding/.project +++ /dev/null @@ -1,34 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<projectDescription> - <name>org.eclipse.jface.databinding</name> - <comment></comment> - <projects> - </projects> - <buildSpec> - <buildCommand> - <name>org.eclipse.jdt.core.javabuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.ManifestBuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.SchemaBuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name> - <arguments> - </arguments> - </buildCommand> - </buildSpec> - <natures> - <nature>org.eclipse.pde.PluginNature</nature> - <nature>org.eclipse.jdt.core.javanature</nature> - <nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature> - </natures> -</projectDescription> diff --git a/bundles/org.eclipse.jface.databinding/.settings/.api_filters b/bundles/org.eclipse.jface.databinding/.settings/.api_filters deleted file mode 100644 index ff88e6ca..00000000 --- a/bundles/org.eclipse.jface.databinding/.settings/.api_filters +++ /dev/null @@ -1,91 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<component id="org.eclipse.jface.databinding" version="2"> - <resource path="src/org/eclipse/jface/internal/databinding/provisional/swt/WorkQueue.java" type="org.eclipse.jface.internal.databinding.provisional.swt.WorkQueue"> - <filter id="305365105"> - <message_arguments> - <message_argument value="org.eclipse.jface.internal.databinding.provisional.swt.WorkQueue"/> - <message_argument value="org.eclipse.jface.databinding_1.2.0"/> - </message_arguments> - </filter> - </resource> - <resource path="src/org/eclipse/jface/internal/databinding/provisional/swt/TableUpdater.java" type="org.eclipse.jface.internal.databinding.provisional.swt.TableUpdater"> - <filter id="305365105"> - <message_arguments> - <message_argument value="org.eclipse.jface.internal.databinding.provisional.swt.TableUpdater"/> - <message_argument value="org.eclipse.jface.databinding_1.2.0"/> - </message_arguments> - </filter> - </resource> - <resource path="src/org/eclipse/jface/internal/databinding/provisional/swt/MenuUpdater.java" type="org.eclipse.jface.internal.databinding.provisional.swt.MenuUpdater"> - <filter id="305365105"> - <message_arguments> - <message_argument value="org.eclipse.jface.internal.databinding.provisional.swt.MenuUpdater"/> - <message_argument value="org.eclipse.jface.databinding_1.2.0"/> - </message_arguments> - </filter> - </resource> - <resource path="src/org/eclipse/jface/internal/databinding/provisional/swt/AbstractSWTObservableValue.java" type="org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue"> - <filter id="305365105"> - <message_arguments> - <message_argument value="org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue"/> - <message_argument value="org.eclipse.jface.databinding_1.2.0"/> - </message_arguments> - </filter> - </resource> - <resource path="src/org/eclipse/jface/internal/databinding/provisional/viewers/UnorderedTreeContentProvider.java" type="org.eclipse.jface.internal.databinding.provisional.viewers.UnorderedTreeContentProvider"> - <filter id="305365105"> - <message_arguments> - <message_argument value="org.eclipse.jface.internal.databinding.provisional.viewers.UnorderedTreeContentProvider"/> - <message_argument value="org.eclipse.jface.databinding_1.2.0"/> - </message_arguments> - </filter> - </resource> - <resource path="src/org/eclipse/jface/internal/databinding/provisional/swt/ControlUpdater.java" type="org.eclipse.jface.internal.databinding.provisional.swt.ControlUpdater"> - <filter id="305365105"> - <message_arguments> - <message_argument value="org.eclipse.jface.internal.databinding.provisional.swt.ControlUpdater"/> - <message_argument value="org.eclipse.jface.databinding_1.2.0"/> - </message_arguments> - </filter> - </resource> - <resource path="src/org/eclipse/jface/internal/databinding/provisional/viewers/IParentProvider.java" type="org.eclipse.jface.internal.databinding.provisional.viewers.IParentProvider"> - <filter id="305365105"> - <message_arguments> - <message_argument value="org.eclipse.jface.internal.databinding.provisional.viewers.IParentProvider"/> - <message_argument value="org.eclipse.jface.databinding_1.2.0"/> - </message_arguments> - </filter> - </resource> - <resource path="src/org/eclipse/jface/internal/databinding/provisional/viewers/ViewerLabelProvider.java" type="org.eclipse.jface.internal.databinding.provisional.viewers.ViewerLabelProvider"> - <filter id="305365105"> - <message_arguments> - <message_argument value="org.eclipse.jface.internal.databinding.provisional.viewers.ViewerLabelProvider"/> - <message_argument value="org.eclipse.jface.databinding_1.2.0"/> - </message_arguments> - </filter> - </resource> - <resource path="src/org/eclipse/jface/internal/databinding/provisional/swt/SWTUtil.java" type="org.eclipse.jface.internal.databinding.provisional.swt.SWTUtil"> - <filter id="305365105"> - <message_arguments> - <message_argument value="org.eclipse.jface.internal.databinding.provisional.swt.SWTUtil"/> - <message_argument value="org.eclipse.jface.databinding_1.2.0"/> - </message_arguments> - </filter> - </resource> - <resource path="src/org/eclipse/jface/internal/databinding/provisional/swt/CompositeUpdater.java" type="org.eclipse.jface.internal.databinding.provisional.swt.CompositeUpdater"> - <filter id="305365105"> - <message_arguments> - <message_argument value="org.eclipse.jface.internal.databinding.provisional.swt.CompositeUpdater"/> - <message_argument value="org.eclipse.jface.databinding_1.2.0"/> - </message_arguments> - </filter> - </resource> - <resource path="src/org/eclipse/jface/internal/databinding/provisional/swt/AbstractSWTVetoableValue.java" type="org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTVetoableValue"> - <filter id="305365105"> - <message_arguments> - <message_argument value="org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTVetoableValue"/> - <message_argument value="org.eclipse.jface.databinding_1.2.0"/> - </message_arguments> - </filter> - </resource> -</component> diff --git a/bundles/org.eclipse.jface.databinding/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.jface.databinding/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 3328ba15..00000000 --- a/bundles/org.eclipse.jface.databinding/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,352 +0,0 @@ -#Thu Apr 03 13:12:14 EDT 2008 -eclipse.preferences.version=1 -org.eclipse.jdt.core.builder.cleanOutputFolder=clean -org.eclipse.jdt.core.builder.duplicateResourceTask=warning -org.eclipse.jdt.core.builder.invalidClasspath=abort -org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=*.launch -org.eclipse.jdt.core.circularClasspath=error -org.eclipse.jdt.core.classpath.exclusionPatterns=enabled -org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled -org.eclipse.jdt.core.codeComplete.argumentPrefixes= -org.eclipse.jdt.core.codeComplete.argumentSuffixes= -org.eclipse.jdt.core.codeComplete.fieldPrefixes= -org.eclipse.jdt.core.codeComplete.fieldSuffixes= -org.eclipse.jdt.core.codeComplete.localPrefixes= -org.eclipse.jdt.core.codeComplete.localSuffixes= -org.eclipse.jdt.core.codeComplete.staticFieldPrefixes= -org.eclipse.jdt.core.codeComplete.staticFieldSuffixes= -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.1 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.3 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.doc.comment.support=enabled -org.eclipse.jdt.core.compiler.maxProblemPerUnit=100 -org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.autoboxing=ignore -org.eclipse.jdt.core.compiler.problem.deprecation=warning -org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled -org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled -org.eclipse.jdt.core.compiler.problem.discouragedReference=error -org.eclipse.jdt.core.compiler.problem.emptyStatement=warning -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore -org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled -org.eclipse.jdt.core.compiler.problem.fieldHiding=warning -org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning -org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=error -org.eclipse.jdt.core.compiler.problem.forbiddenReference=error -org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=error -org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=error -org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore -org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=error -org.eclipse.jdt.core.compiler.problem.invalidJavadoc=error -org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled -org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled -org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled -org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=private -org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore -org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=error -org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore -org.eclipse.jdt.core.compiler.problem.missingJavadocComments=error -org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled -org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public -org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag -org.eclipse.jdt.core.compiler.problem.missingJavadocTags=error -org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled -org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=protected -org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore -org.eclipse.jdt.core.compiler.problem.missingSerialVersion=error -org.eclipse.jdt.core.compiler.problem.noEffectAssignment=error -org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=error -org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=error -org.eclipse.jdt.core.compiler.problem.nullReference=warning -org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=error -org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore -org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning -org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore -org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning -org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore -org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled -org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=error -org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled -org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore -org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning -org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning -org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore -org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning -org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning -org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning -org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=enabled -org.eclipse.jdt.core.compiler.problem.unusedImport=error -org.eclipse.jdt.core.compiler.problem.unusedLabel=error -org.eclipse.jdt.core.compiler.problem.unusedLocal=error -org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore -org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled -org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=enabled -org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=enabled -org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=error -org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning -org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -org.eclipse.jdt.core.compiler.source=1.3 -org.eclipse.jdt.core.formatter.align_type_members_on_columns=false -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16 -org.eclipse.jdt.core.formatter.alignment_for_assignment=0 -org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 -org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 -org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 -org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0 -org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 -org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 -org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16 -org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 -org.eclipse.jdt.core.formatter.blank_lines_after_imports=1 -org.eclipse.jdt.core.formatter.blank_lines_after_package=1 -org.eclipse.jdt.core.formatter.blank_lines_before_field=0 -org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0 -org.eclipse.jdt.core.formatter.blank_lines_before_imports=1 -org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1 -org.eclipse.jdt.core.formatter.blank_lines_before_method=1 -org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1 -org.eclipse.jdt.core.formatter.blank_lines_before_package=0 -org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1 -org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1 -org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line -org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false -org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false -org.eclipse.jdt.core.formatter.comment.format_block_comments=true -org.eclipse.jdt.core.formatter.comment.format_header=false -org.eclipse.jdt.core.formatter.comment.format_html=true -org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true -org.eclipse.jdt.core.formatter.comment.format_line_comments=true -org.eclipse.jdt.core.formatter.comment.format_source_code=true -org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true -org.eclipse.jdt.core.formatter.comment.indent_root_tags=true -org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert -org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert -org.eclipse.jdt.core.formatter.comment.line_length=80 -org.eclipse.jdt.core.formatter.compact_else_if=true -org.eclipse.jdt.core.formatter.continuation_indentation=2 -org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 -org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true -org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true -org.eclipse.jdt.core.formatter.indent_empty_lines=false -org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true -org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true -org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true -org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false -org.eclipse.jdt.core.formatter.indentation.size=4 -org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert -org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert -org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert -org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert -org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert -org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert -org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert -org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert -org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert -org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert -org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert -org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert -org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert -org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert -org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert -org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false -org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false -org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false -org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false -org.eclipse.jdt.core.formatter.lineSplit=80 -org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false -org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false -org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 -org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 -org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true -org.eclipse.jdt.core.formatter.tabulation.char=tab -org.eclipse.jdt.core.formatter.tabulation.size=4 -org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false -org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true -org.eclipse.jdt.core.incompatibleJDKLevel=ignore -org.eclipse.jdt.core.incompleteClasspath=error diff --git a/bundles/org.eclipse.jface.databinding/.settings/org.eclipse.jdt.ui.prefs b/bundles/org.eclipse.jface.databinding/.settings/org.eclipse.jdt.ui.prefs deleted file mode 100644 index ebd0fd0a..00000000 --- a/bundles/org.eclipse.jface.databinding/.settings/org.eclipse.jdt.ui.prefs +++ /dev/null @@ -1,116 +0,0 @@ -#Mon Dec 03 13:51:53 EST 2007 -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_serial_version_id=false -cleanup.always_use_blocks=true -cleanup.always_use_parentheses_in_expressions=false -cleanup.always_use_this_for_non_static_field_access=false -cleanup.always_use_this_for_non_static_method_access=false -cleanup.convert_to_enhanced_for_loop=false -cleanup.correct_indentation=false -cleanup.format_source_code=false -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_variable_declarations_final=false -cleanup.never_use_blocks=false -cleanup.never_use_parentheses_in_expressions=true -cleanup.organize_imports=false -cleanup.qualify_static_field_accesses_with_declaring_class=false -cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true -cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true -cleanup.qualify_static_member_accesses_with_declaring_class=true -cleanup.qualify_static_method_accesses_with_declaring_class=false -cleanup.remove_private_constructors=true -cleanup.remove_trailing_whitespaces=false -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=false -cleanup.use_blocks_only_for_return_and_throw=false -cleanup.use_parentheses_in_expressions=false -cleanup.use_this_for_non_static_field_access=false -cleanup.use_this_for_non_static_field_access_only_if_necessary=true -cleanup.use_this_for_non_static_method_access=false -cleanup.use_this_for_non_static_method_access_only_if_necessary=true -cleanup_profile=org.eclipse.jdt.ui.default.eclipse_clean_up_profile -cleanup_settings_version=2 -eclipse.preferences.version=1 -editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=false -formatter_profile=org.eclipse.jdt.ui.default.eclipse_profile -formatter_settings_version=11 -org.eclipse.jdt.ui.exception.name=e -org.eclipse.jdt.ui.gettersetter.use.is=true -org.eclipse.jdt.ui.ignorelowercasenames=true -org.eclipse.jdt.ui.importorder=java;javax;org;com; -org.eclipse.jdt.ui.javadoc=true -org.eclipse.jdt.ui.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"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\r\n * @return Returns the ${bare_field_name}.\r\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\r\n * @param ${param} The ${bare_field_name} to set.\r\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="true" 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) ${year} IBM Corporation 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 * IBM Corporation - initial API and implementation\r\n ******************************************************************************/\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 * @since 3.3\r\n *\r\n * ${tags}\r\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\r\n * \r\n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="true" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/* (non-Javadoc)\r\n * ${see_to_overridden}\r\n */</template><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\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\r\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\r\n${body_statement}</template><template autoinsert\="true" 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}\r\n// ${todo} Auto-generated constructor stub</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><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\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\r\n * ${tags}\r\n * ${see_to_target}\r\n */</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_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=false -sp_cleanup.format_source_code=false -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_variable_declarations_final=true -sp_cleanup.never_use_blocks=false -sp_cleanup.never_use_parentheses_in_expressions=true -sp_cleanup.on_save_use_additional_actions=false -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=false -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=false -sp_cleanup.remove_unused_imports=false -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=false -sp_cleanup.use_blocks_only_for_return_and_throw=false -sp_cleanup.use_parentheses_in_expressions=false -sp_cleanup.use_this_for_non_static_field_access=false -sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true -sp_cleanup.use_this_for_non_static_method_access=false -sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true diff --git a/bundles/org.eclipse.jface.databinding/.settings/org.eclipse.pde.prefs b/bundles/org.eclipse.jface.databinding/.settings/org.eclipse.pde.prefs deleted file mode 100644 index 2ad454b5..00000000 --- a/bundles/org.eclipse.jface.databinding/.settings/org.eclipse.pde.prefs +++ /dev/null @@ -1,18 +0,0 @@ -#Mon Dec 03 13:51:53 EST 2007 -compilers.incompatible-environment=1 -compilers.p.build=1 -compilers.p.deprecated=0 -compilers.p.illegal-att-value=0 -compilers.p.missing-bundle-classpath-entries=1 -compilers.p.missing-packages=2 -compilers.p.no-required-att=0 -compilers.p.not-externalized-att=0 -compilers.p.unknown-attribute=0 -compilers.p.unknown-class=0 -compilers.p.unknown-element=1 -compilers.p.unknown-resource=0 -compilers.p.unresolved-ex-points=0 -compilers.p.unresolved-import=0 -compilers.p.unused-element-or-attribute=1 -compilers.use-project=true -eclipse.preferences.version=1 diff --git a/bundles/org.eclipse.jface.databinding/META-INF/MANIFEST.MF b/bundles/org.eclipse.jface.databinding/META-INF/MANIFEST.MF deleted file mode 100644 index bc1534ab..00000000 --- a/bundles/org.eclipse.jface.databinding/META-INF/MANIFEST.MF +++ /dev/null @@ -1,22 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: %pluginName -Bundle-SymbolicName: org.eclipse.jface.databinding -Bundle-Version: 1.2.1.qualifier -Bundle-ClassPath: . -Bundle-Vendor: %providerName -Bundle-Localization: plugin -Export-Package: org.eclipse.jface.databinding.swt, - org.eclipse.jface.databinding.viewers, - org.eclipse.jface.databinding.wizard, - org.eclipse.jface.internal.databinding.provisional.swt;x-internal:=true, - org.eclipse.jface.internal.databinding.provisional.viewers;x-internal:=true, - org.eclipse.jface.internal.databinding.swt;x-internal:=true, - org.eclipse.jface.internal.databinding.viewers;x-internal:=true -Require-Bundle: org.eclipse.core.databinding;bundle-version="[1.0.0,2.0.0)", - org.eclipse.swt;bundle-version="[3.2.0,4.0.0)", - org.eclipse.jface;bundle-version="[3.2.0,4.0.0)", - org.eclipse.equinox.common;bundle-version="[3.2.0,4.0.0)" -Import-Package: com.ibm.icu.text -Bundle-RequiredExecutionEnvironment: CDC-1.0/Foundation-1.0, - J2SE-1.3 diff --git a/bundles/org.eclipse.jface.databinding/about.html b/bundles/org.eclipse.jface.databinding/about.html deleted file mode 100644 index 46023304..00000000 --- a/bundles/org.eclipse.jface.databinding/about.html +++ /dev/null @@ -1,28 +0,0 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml"> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> -<title>About</title> -</head> -<body lang="EN-US"> -<h2>About This Content</h2> - -<p>June 2, 2006</p> -<h3>License</h3> - -<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise -indicated below, the Content is provided to you under the terms and conditions of the -Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available -at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>. -For purposes of the EPL, "Program" will mean the Content.</p> - -<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is -being redistributed by another party ("Redistributor") and different terms and conditions may -apply to your use of any object code in the Content. Check the Redistributor's license that was -provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise -indicated below, the terms and conditions of the EPL still apply to any source code in the Content -and such source code may be obtained at <a href="http://www.eclipse.org">http://www.eclipse.org</a>.</p> - -</body> -</html>
\ No newline at end of file diff --git a/bundles/org.eclipse.jface.databinding/build.properties b/bundles/org.eclipse.jface.databinding/build.properties deleted file mode 100644 index 6f0a513e..00000000 --- a/bundles/org.eclipse.jface.databinding/build.properties +++ /dev/null @@ -1,17 +0,0 @@ -############################################################################### -# Copyright (c) 2006 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -bin.includes = .,\ - META-INF/,\ - plugin.properties,\ - about.html -output.databinding.jar = bin/ -src.includes = about.html -source.. = src/ diff --git a/bundles/org.eclipse.jface.databinding/plugin.properties b/bundles/org.eclipse.jface.databinding/plugin.properties deleted file mode 100644 index 2880743c..00000000 --- a/bundles/org.eclipse.jface.databinding/plugin.properties +++ /dev/null @@ -1,12 +0,0 @@ -############################################################################### -# Copyright (c) 2006 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -pluginName = JFace Data Binding for SWT and JFace -providerName = Eclipse.org diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/ISWTObservable.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/ISWTObservable.java deleted file mode 100644 index f3a74f85..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/ISWTObservable.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.databinding.swt; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.swt.widgets.Widget; - -/** - * {@link IObservable} observing an SWT widget. - * - * @since 1.1 - * - */ -public interface ISWTObservable extends IObservable { - - /** - * Returns the widget of this observable - * - * @return the widget - */ - public Widget getWidget(); - -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/ISWTObservableValue.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/ISWTObservableValue.java deleted file mode 100644 index d25ba3a1..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/ISWTObservableValue.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.databinding.swt; - -import org.eclipse.core.databinding.observable.value.IObservableValue; - -/** - * {@link IObservableValue} observing an SWT widget. - * - * @since 1.1 - * - */ -public interface ISWTObservableValue extends ISWTObservable, IObservableValue { - -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/SWTObservables.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/SWTObservables.java deleted file mode 100644 index 5efa5ca5..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/SWTObservables.java +++ /dev/null @@ -1,448 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matt Carter - bug 170668 - * Brad Reynolds - bug 170848 - * Matthew Hall - bug 180746, bug 207844 - * Michael Krauter, bug 180223 - *******************************************************************************/ -package org.eclipse.jface.databinding.swt; - -import java.util.ArrayList; -import java.util.Iterator; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.jface.internal.databinding.swt.ButtonObservableValue; -import org.eclipse.jface.internal.databinding.swt.CComboObservableList; -import org.eclipse.jface.internal.databinding.swt.CComboObservableValue; -import org.eclipse.jface.internal.databinding.swt.CComboSingleSelectionObservableValue; -import org.eclipse.jface.internal.databinding.swt.CLabelObservableValue; -import org.eclipse.jface.internal.databinding.swt.ComboObservableList; -import org.eclipse.jface.internal.databinding.swt.ComboObservableValue; -import org.eclipse.jface.internal.databinding.internal.swt.LinkObservableValue; -import org.eclipse.jface.internal.databinding.swt.ComboSingleSelectionObservableValue; -import org.eclipse.jface.internal.databinding.swt.ControlObservableValue; -import org.eclipse.jface.internal.databinding.swt.DelayedObservableValue; -import org.eclipse.jface.internal.databinding.swt.LabelObservableValue; -import org.eclipse.jface.internal.databinding.swt.ListObservableList; -import org.eclipse.jface.internal.databinding.swt.ListObservableValue; -import org.eclipse.jface.internal.databinding.swt.ListSingleSelectionObservableValue; -import org.eclipse.jface.internal.databinding.swt.SWTProperties; -import org.eclipse.jface.internal.databinding.swt.ScaleObservableValue; -import org.eclipse.jface.internal.databinding.swt.ShellObservableValue; -import org.eclipse.jface.internal.databinding.swt.SpinnerObservableValue; -import org.eclipse.jface.internal.databinding.swt.TableSingleSelectionObservableValue; -import org.eclipse.jface.internal.databinding.swt.TextEditableObservableValue; -import org.eclipse.jface.internal.databinding.swt.TextObservableValue; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.custom.CLabel; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Link; -import org.eclipse.swt.widgets.List; -import org.eclipse.swt.widgets.Scale; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Spinner; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.Text; - -/** - * A factory for creating observables for SWT widgets - * - * @since 1.1 - * - */ -public class SWTObservables { - - private static java.util.List realms = new ArrayList(); - - /** - * Returns the realm representing the UI thread for the given display. - * - * @param display - * @return the realm representing the UI thread for the given display - */ - public static Realm getRealm(final Display display) { - synchronized (realms) { - for (Iterator it = realms.iterator(); it.hasNext();) { - DisplayRealm displayRealm = (DisplayRealm) it.next(); - if (displayRealm.display == display) { - return displayRealm; - } - } - DisplayRealm result = new DisplayRealm(display); - realms.add(result); - return result; - } - } - - /** - * Returns an observable which delays notification of value change events - * from <code>observable</code> until <code>delay</code> milliseconds - * have passed since the last change event, or until a FocusOut event is - * received from the underlying widget (whichever happens earlier). This - * class helps to delay validation until the user stops typing. To notify - * about pending changes, the returned observable value will fire a stale - * event when the wrapped observable value fires a change event, but this - * change is being delayed. - * - * @param delay - * @param observable - * @return an observable which delays notification of value change events - * from <code>observable</code> until <code>delay</code> - * milliseconds have passed since the last change event. - * - * @since 1.2 - */ - public static ISWTObservableValue observeDelayedValue(int delay, ISWTObservableValue observable) { - return new DelayedObservableValue(delay, observable); - } - - /** - * @param control - * @return an observable value tracking the enabled state of the given - * control - */ - public static ISWTObservableValue observeEnabled(Control control) { - return new ControlObservableValue(control, SWTProperties.ENABLED); - } - - /** - * @param control - * @return an observable value tracking the visible state of the given - * control - */ - public static ISWTObservableValue observeVisible(Control control) { - return new ControlObservableValue(control, SWTProperties.VISIBLE); - } - - /** - * @param control - * @return an observable value tracking the tooltip text of the given - * control - */ - public static ISWTObservableValue observeTooltipText(Control control) { - return new ControlObservableValue(control, SWTProperties.TOOLTIP_TEXT); - } - - /** - * Returns an observable observing the selection attribute of the provided - * <code>control</code>. The supported types are: - * <ul> - * <li>org.eclipse.swt.widgets.Spinner</li> - * <li>org.eclipse.swt.widgets.Button</li> - * <li>org.eclipse.swt.widgets.Combo</li> - * <li>org.eclipse.swt.custom.CCombo</li> - * <li>org.eclipse.swt.widgets.List</li> - * <li>org.eclipse.swt.widgets.Scale</li> - * </ul> - * - * @param control - * @return observable value - * @throws IllegalArgumentException - * if <code>control</code> type is unsupported - */ - public static ISWTObservableValue observeSelection(Control control) { - if (control instanceof Spinner) { - return new SpinnerObservableValue((Spinner) control, - SWTProperties.SELECTION); - } else if (control instanceof Button) { - return new ButtonObservableValue((Button) control); - } else if (control instanceof Combo) { - return new ComboObservableValue((Combo) control, - SWTProperties.SELECTION); - } else if (control instanceof CCombo) { - return new CComboObservableValue((CCombo) control, - SWTProperties.SELECTION); - } else if (control instanceof List) { - return new ListObservableValue((List) control); - } else if (control instanceof Scale) { - return new ScaleObservableValue((Scale) control, - SWTProperties.SELECTION); - } - - throw new IllegalArgumentException( - "Widget [" + control.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ - } - - /** - * Returns an observable observing the minimum attribute of the provided - * <code>control</code>. The supported types are: - * <ul> - * <li>org.eclipse.swt.widgets.Spinner</li> - * <li>org.eclipse.swt.widgets.Scale</li> - * </ul> - * - * @param control - * @return observable value - * @throws IllegalArgumentException - * if <code>control</code> type is unsupported - */ - public static ISWTObservableValue observeMin(Control control) { - if (control instanceof Spinner) { - return new SpinnerObservableValue((Spinner) control, - SWTProperties.MIN); - } else if (control instanceof Scale) { - return new ScaleObservableValue((Scale) control, SWTProperties.MIN); - } - - throw new IllegalArgumentException( - "Widget [" + control.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ - } - - /** - * Returns an observable observing the maximum attribute of the provided - * <code>control</code>. The supported types are: - * <ul> - * <li>org.eclipse.swt.widgets.Spinner</li> - * <li>org.eclipse.swt.widgets.Scale</li> - * </ul> - * - * @param control - * @return observable value - * @throws IllegalArgumentException - * if <code>control</code> type is unsupported - */ - public static ISWTObservableValue observeMax(Control control) { - if (control instanceof Spinner) { - return new SpinnerObservableValue((Spinner) control, - SWTProperties.MAX); - } else if (control instanceof Scale) { - return new ScaleObservableValue((Scale) control, SWTProperties.MAX); - } - - throw new IllegalArgumentException( - "Widget [" + control.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ - } - - /** - * Returns an observable observing the text attribute of the provided - * <code>control</code>. The supported types are: - * <ul> - * <li>org.eclipse.swt.widgets.Text</li> - * </ul> - * - * <li>org.eclipse.swt.widgets.Label</li> - * @param control - * @param event event type to register for change events - * @return observable value - * @throws IllegalArgumentException - * if <code>control</code> type is unsupported - */ - public static ISWTObservableValue observeText(Control control, int event) { - if (control instanceof Text) { - return new TextObservableValue((Text) control, event); - } - - throw new IllegalArgumentException( - "Widget [" + control.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ - } - - /** - * Returns an observable observing the text attribute of the provided - * <code>control</code>. The supported types are: - * <ul> - * <li>org.eclipse.swt.widgets.Label</li> - * <li>org.eclipse.swt.widgets.Link (as of 1.2)</li> - * <li>org.eclipse.swt.custom.Label</li> - * <li>org.eclipse.swt.widgets.Combo</li> - * <li>org.eclipse.swt.custom.CCombo</li> - * <li>org.eclipse.swt.widgets.Shell</li> - * </ul> - * - * @param control - * @return observable value - * @throws IllegalArgumentException - * if <code>control</code> type is unsupported - */ - public static ISWTObservableValue observeText(Control control) { - if (control instanceof Label) { - return new LabelObservableValue((Label) control); - } else if (control instanceof Link) { - return new LinkObservableValue((Link) control); - } else if (control instanceof CLabel) { - return new CLabelObservableValue((CLabel) control); - } else if (control instanceof Combo) { - return new ComboObservableValue((Combo) control, SWTProperties.TEXT); - } else if (control instanceof CCombo) { - return new CComboObservableValue((CCombo) control, - SWTProperties.TEXT); - } else if (control instanceof Shell) { - return new ShellObservableValue((Shell) control); - } - - throw new IllegalArgumentException( - "Widget [" + control.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ - } - - /** - * Returns an observable observing the items attribute of the provided - * <code>control</code>. The supported types are: - * <ul> - * <li>org.eclipse.swt.widgets.Combo</li> - * <li>org.eclipse.swt.custom.CCombo</li> - * <li>org.eclipse.swt.widgets.List</li> - * </ul> - * - * @param control - * @return observable list - * @throws IllegalArgumentException - * if <code>control</code> type is unsupported - */ - public static IObservableList observeItems(Control control) { - if (control instanceof Combo) { - return new ComboObservableList((Combo) control); - } else if (control instanceof CCombo) { - return new CComboObservableList((CCombo) control); - } else if (control instanceof List) { - return new ListObservableList((List) control); - } - - throw new IllegalArgumentException( - "Widget [" + control.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ - } - - /** - * Returns an observable observing the single selection index attribute of - * the provided <code>control</code>. The supported types are: - * <ul> - * <li>org.eclipse.swt.widgets.Table</li> - * <li>org.eclipse.swt.widgets.Combo</li> - * <li>org.eclipse.swt.custom.CCombo</li> - * <li>org.eclipse.swt.widgets.List</li> - * </ul> - * - * @param control - * @return observable value - * @throws IllegalArgumentException - * if <code>control</code> type is unsupported - */ - public static ISWTObservableValue observeSingleSelectionIndex( - Control control) { - if (control instanceof Table) { - return new TableSingleSelectionObservableValue((Table) control); - } else if (control instanceof Combo) { - return new ComboSingleSelectionObservableValue((Combo) control); - } else if (control instanceof CCombo) { - return new CComboSingleSelectionObservableValue((CCombo) control); - } else if (control instanceof List) { - return new ListSingleSelectionObservableValue((List) control); - } - - throw new IllegalArgumentException( - "Widget [" + control.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ - } - - /** - * @param control - * @return an observable value tracking the foreground color of the given - * control - */ - public static ISWTObservableValue observeForeground(Control control) { - return new ControlObservableValue(control, SWTProperties.FOREGROUND); - } - - /** - * @param control - * @return an observable value tracking the background color of the given - * control - */ - public static ISWTObservableValue observeBackground(Control control) { - return new ControlObservableValue(control, SWTProperties.BACKGROUND); - } - - /** - * @param control - * @return an observable value tracking the font of the given control - */ - public static ISWTObservableValue observeFont(Control control) { - return new ControlObservableValue(control, SWTProperties.FONT); - } - - /** - * Returns an observable observing the editable attribute of - * the provided <code>control</code>. The supported types are: - * <ul> - * <li>org.eclipse.swt.widgets.Text</li> - * </ul> - * - * @param control - * @return observable value - * @throws IllegalArgumentException - * if <code>control</code> type is unsupported - */ - public static ISWTObservableValue observeEditable(Control control) { - if (control instanceof Text) { - return new TextEditableObservableValue((Text) control); - } - - throw new IllegalArgumentException( - "Widget [" + control.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ - } - - private static class DisplayRealm extends Realm { - private Display display; - - /** - * @param display - */ - private DisplayRealm(Display display) { - this.display = display; - } - - public boolean isCurrent() { - return Display.getCurrent() == display; - } - - public void asyncExec(final Runnable runnable) { - Runnable safeRunnable = new Runnable() { - public void run() { - safeRun(runnable); - } - }; - if (!display.isDisposed()) { - display.asyncExec(safeRunnable); - } - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ - public int hashCode() { - return (display == null) ? 0 : display.hashCode(); - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - final DisplayRealm other = (DisplayRealm) obj; - if (display == null) { - if (other.display != null) - return false; - } else if (!display.equals(other.display)) - return false; - return true; - } - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/package.html b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/package.html deleted file mode 100644 index 139ca4fc..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/package.html +++ /dev/null @@ -1,16 +0,0 @@ -<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> - <meta name="Author" content="IBM"> - <meta name="GENERATOR" content="Mozilla/4.5 [en] (Win98; I) [Netscape]"> - <title>Package-level Javadoc</title> -</head> -<body> -Provides classes that can be used to observe changes in SWT widgets. -<h2> -Package Specification</h2> -<p> -This package provides classes that can be used to observe changes in SWT widgets.</p> -</body> -</html> diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/IViewerObservable.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/IViewerObservable.java deleted file mode 100644 index 50703cd2..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/IViewerObservable.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.jface.databinding.viewers; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.jface.viewers.Viewer; - -/** - * {@link IObservable} observing a JFace Viewer. - * - * @since 1.2 - * - */ -public interface IViewerObservable extends IObservable { - /** - * Returns the underlying viewer for this observable. - * - * @return the viewer. - */ - public Viewer getViewer(); -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/IViewerObservableList.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/IViewerObservableList.java deleted file mode 100644 index 6b3ed4b6..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/IViewerObservableList.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.jface.databinding.viewers; - -import org.eclipse.core.databinding.observable.list.IObservableList; - -/** - * {@link IObservableList} observing a JFace Viewer. - * - * @since 1.2 - * - */ -public interface IViewerObservableList extends IObservableList, - IViewerObservable { -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/IViewerObservableSet.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/IViewerObservableSet.java deleted file mode 100644 index b8f98e66..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/IViewerObservableSet.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 124684) - ******************************************************************************/ - -package org.eclipse.jface.databinding.viewers; - -import org.eclipse.core.databinding.observable.set.IObservableSet; - -/** - * {@link IObservableSet} observing a JFace Viewer. - * - * @since 1.2 - * - */ -public interface IViewerObservableSet extends IObservableSet, IViewerObservable { -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/IViewerObservableValue.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/IViewerObservableValue.java deleted file mode 100644 index 6c145cf8..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/IViewerObservableValue.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.jface.databinding.viewers; - -import org.eclipse.core.databinding.observable.value.IObservableValue; - -/** - * {@link IObservableValue} observing a JFace Viewer. - * - * @since 1.2 - * - */ -public interface IViewerObservableValue extends IObservableValue, - IViewerObservable { -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ListeningLabelProvider.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ListeningLabelProvider.java deleted file mode 100644 index 5588a6f7..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ListeningLabelProvider.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.databinding.viewers; - -import java.util.Iterator; - -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.ISetChangeListener; -import org.eclipse.core.databinding.observable.set.SetChangeEvent; -import org.eclipse.jface.internal.databinding.provisional.viewers.ViewerLabelProvider; - -/** - * @since 1.1 - * - */ -public abstract class ListeningLabelProvider extends ViewerLabelProvider { - - private ISetChangeListener listener = new ISetChangeListener() { - public void handleSetChange(SetChangeEvent event) { - for (Iterator it = event.diff.getAdditions().iterator(); it.hasNext();) { - addListenerTo(it.next()); - } - for (Iterator it = event.diff.getRemovals().iterator(); it.hasNext();) { - removeListenerFrom(it.next()); - } - } - }; - - private IObservableSet items; - - /** - * @param itemsThatNeedLabels - */ - public ListeningLabelProvider(IObservableSet itemsThatNeedLabels) { - this.items = itemsThatNeedLabels; - items.addSetChangeListener(listener); - for (Iterator it = items.iterator(); it.hasNext();) { - addListenerTo(it.next()); - } - } - - /** - * @param next - */ - protected abstract void removeListenerFrom(Object next); - - /** - * @param next - */ - protected abstract void addListenerTo(Object next); - - public void dispose() { - for (Iterator iter = items.iterator(); iter.hasNext();) { - removeListenerFrom(iter.next()); - } - items.removeSetChangeListener(listener); - super.dispose(); - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ObservableListContentProvider.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ObservableListContentProvider.java deleted file mode 100644 index 2a5ec404..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ObservableListContentProvider.java +++ /dev/null @@ -1,133 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006-2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Tom Schindl<tom.schindl@bestsolution.at> - bugfix in: 214355 - * Matthew Hall - bugs 215531, 226765 - *******************************************************************************/ - -package org.eclipse.jface.databinding.viewers; - -import java.util.Set; - -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.list.IListChangeListener; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.ListChangeEvent; -import org.eclipse.core.databinding.observable.list.ListDiffVisitor; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.internal.databinding.viewers.ObservableCollectionContentProvider; -import org.eclipse.jface.internal.databinding.viewers.ViewerElementSet; -import org.eclipse.jface.viewers.AbstractListViewer; -import org.eclipse.jface.viewers.AbstractTableViewer; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.Viewer; - -/** - * A {@link IStructuredContentProvider content provider} for - * {@link AbstractTableViewer} or {@link AbstractListViewer} that provides - * elements of an {@link IObservableList} when set as the viewer's input. - * Objects of this class listen for changes to the observable list, and will - * insert and remove viewer elements to reflect observed changes. - * - * <p> - * This class is not intended to be subclassed by clients. - * - * @since 1.1 - */ -public class ObservableListContentProvider implements - IStructuredContentProvider { - private ObservableCollectionContentProvider impl; - - private static class Impl extends ObservableCollectionContentProvider - implements IListChangeListener { - protected void checkInput(Object input) { - Assert - .isTrue(input instanceof IObservableList, - "This content provider only works with input of type IObservableList"); //$NON-NLS-1$ - } - - protected void addCollectionChangeListener( - IObservableCollection collection) { - ((IObservableList) collection).addListChangeListener(this); - } - - protected void removeCollectionChangeListener( - IObservableCollection collection) { - ((IObservableList) collection).removeListChangeListener(this); - } - - public void handleListChange(ListChangeEvent event) { - if (isViewerDisposed()) - return; - final Set removals = ViewerElementSet.withComparer(comparer); - - event.diff.accept(new ListDiffVisitor() { - public void handleAdd(int index, Object element) { - knownElements.add(element); - viewerUpdater.insert(element, index); - } - - public void handleRemove(int index, Object element) { - viewerUpdater.remove(element, index); - removals.add(element); - } - - public void handleReplace(int index, Object oldElement, - Object newElement) { - knownElements.add(newElement); - viewerUpdater.replace(oldElement, newElement, index); - removals.add(oldElement); - } - - public void handleMove(int oldIndex, int newIndex, - Object element) { - viewerUpdater.move(element, oldIndex, newIndex); - } - }); - - // For each removed element, do not remove from known elements if - // the element is still present elsewhere in the list. - removals.removeAll(event.getObservableList()); - knownElements.removeAll(removals); - } - } - - /** - * Constructs an ObservableListContentProvider - */ - public ObservableListContentProvider() { - impl = new Impl(); - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - impl.inputChanged(viewer, oldInput, newInput); - } - - public Object[] getElements(Object inputElement) { - return impl.getElements(inputElement); - } - - public void dispose() { - impl.dispose(); - } - - /** - * Returns the set of elements known to this content provider. Label - * providers may track this set if they need to be notified about additions - * before the viewer sees the added element, and notified about removals - * after the element was removed from the viewer. This is intended for use - * by label providers, as it will always return the items that need labels. - * - * @return readableSet of items that will need labels - */ - public IObservableSet getKnownElements() { - return impl.getKnownElements(); - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ObservableListTreeContentProvider.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ObservableListTreeContentProvider.java deleted file mode 100644 index 71b2db74..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ObservableListTreeContentProvider.java +++ /dev/null @@ -1,186 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007-2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 207858) - * Matthew Hall - bug 226765 - *******************************************************************************/ - -package org.eclipse.jface.databinding.viewers; - -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.IObservablesListener; -import org.eclipse.core.databinding.observable.list.IListChangeListener; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.ListChangeEvent; -import org.eclipse.core.databinding.observable.list.ListDiffVisitor; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.jface.internal.databinding.viewers.ObservableCollectionTreeContentProvider; -import org.eclipse.jface.internal.databinding.viewers.ViewerElementSet; -import org.eclipse.jface.viewers.AbstractTreeViewer; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.Viewer; - -/** - * An {@link ITreeContentProvider} for use with an {@link AbstractTreeViewer}, - * which uses the provided {@link IObservableFactory list factory} to obtain the - * elements of a tree. Object of this class listen for changes to each - * {@link IObservableList} created by the factory, and will insert and remove - * viewer elements to reflect the observed changes. - * - * <p> - * This class is not intended to be subclassed by clients. - * - * @since 1.2 - */ -public class ObservableListTreeContentProvider implements ITreeContentProvider { - private final ObservableCollectionTreeContentProvider impl; - - private static class Impl extends ObservableCollectionTreeContentProvider { - public Impl(IObservableFactory listFactory, - TreeStructureAdvisor structureAdvisor) { - super(listFactory, structureAdvisor); - } - - private class ListChangeListener implements IListChangeListener { - final Object parentElement; - - public ListChangeListener(Object parentElement) { - this.parentElement = parentElement; - } - - public void handleListChange(ListChangeEvent event) { - if (isViewerDisposed()) - return; - - final Set removals = ViewerElementSet.withComparer(comparer); - event.diff.accept(new ListDiffVisitor() { - public void handleAdd(int index, Object child) { - // adds to known elements if new element - getOrCreateNode(child).addParent(parentElement); - - viewerUpdater.insert(parentElement, child, index); - } - - public void handleRemove(int index, Object child) { - viewerUpdater.remove(parentElement, child, index); - - removals.add(child); - } - - public void handleReplace(int index, Object oldChild, - Object newChild) { - getOrCreateNode(newChild).addParent(parentElement); - - viewerUpdater.replace(parentElement, oldChild, - newChild, index); - - removals.add(oldChild); - } - - public void handleMove(int oldIndex, int newIndex, - Object child) { - viewerUpdater.move(parentElement, child, oldIndex, - newIndex); - } - }); - - // For each removed element, do not remove node's parent if the - // element is still present elsewhere in the list. - removals.removeAll(event.getObservableList()); - for (Iterator iterator = removals.iterator(); iterator - .hasNext();) { - TreeNode node = getExistingNode(iterator.next()); - if (node != null) - // removes from known elements if last parent - node.removeParent(parentElement); - } - } - } - - protected IObservablesListener createCollectionChangeListener( - Object parentElement) { - return new ListChangeListener(parentElement); - } - - protected void addCollectionChangeListener( - IObservableCollection collection, IObservablesListener listener) { - IObservableList list = (IObservableList) collection; - IListChangeListener listListener = (IListChangeListener) listener; - list.addListChangeListener(listListener); - } - - protected void removeCollectionChangeListener( - IObservableCollection collection, IObservablesListener listener) { - IObservableList list = (IObservableList) collection; - IListChangeListener listListener = (IListChangeListener) listener; - list.removeListChangeListener(listListener); - } - } - - /** - * Constructs an ObservableListTreeContentProvider using the given list - * factory. - * - * @param listFactory - * observable factory that produces an IObservableList of - * children for a given parent element. Observable lists created - * by this factory must be on the realm of the current display. - * @param structureAdvisor - * an advisor that will be consulted from the implementations of - * the {@link #getParent(Object)} and - * {@link #hasChildren(Object)} methods, or <code>null</code> - * if no advisor is available. It is recommended that clients - * pass a non-null advisor if they can provide additional - * structural information about the tree. - */ - public ObservableListTreeContentProvider(IObservableFactory listFactory, - TreeStructureAdvisor structureAdvisor) { - impl = new Impl(listFactory, structureAdvisor); - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - impl.inputChanged(viewer, oldInput, newInput); - } - - public Object[] getElements(Object inputElement) { - return impl.getElements(inputElement); - } - - public boolean hasChildren(Object element) { - return impl.hasChildren(element); - } - - public Object[] getChildren(Object parentElement) { - return impl.getChildren(parentElement); - } - - public Object getParent(Object element) { - return impl.getParent(element); - } - - public void dispose() { - impl.dispose(); - } - - /** - * Returns the set of elements known to this content provider. Label - * providers may track this set if they need to be notified about additions - * before the viewer sees the added element, and notified about removals - * after the element was removed from the viewer. This is intended for use - * by label providers, as it will always return the items that need labels. - * - * @return readableSet of items that will need labels - */ - public IObservableSet getKnownElements() { - return impl.getKnownElements(); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ObservableMapLabelProvider.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ObservableMapLabelProvider.java deleted file mode 100644 index 5d9d434b..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ObservableMapLabelProvider.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164247 - * Brad Reynolds - bug 164134 - *******************************************************************************/ - -package org.eclipse.jface.databinding.viewers; - -import java.util.Set; - -import org.eclipse.core.databinding.observable.map.IMapChangeListener; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.map.MapChangeEvent; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.LabelProviderChangedEvent; -import org.eclipse.swt.graphics.Image; - -/** - * @since 1.1 - * - */ -public class ObservableMapLabelProvider extends LabelProvider - implements ILabelProvider, ITableLabelProvider { - - private final IObservableMap[] attributeMaps; - - private IMapChangeListener mapChangeListener = new IMapChangeListener() { - public void handleMapChange(MapChangeEvent event) { - Set affectedElements = event.diff.getChangedKeys(); - LabelProviderChangedEvent newEvent = new LabelProviderChangedEvent( - ObservableMapLabelProvider.this, affectedElements - .toArray()); - fireLabelProviderChanged(newEvent); - } - }; - - /** - * @param attributeMap - */ - public ObservableMapLabelProvider(IObservableMap attributeMap) { - this(new IObservableMap[] { attributeMap }); - } - - /** - * @param attributeMaps - */ - public ObservableMapLabelProvider(IObservableMap[] attributeMaps) { - System.arraycopy(attributeMaps, 0, this.attributeMaps = attributeMaps, 0, attributeMaps.length); - for (int i = 0; i < attributeMaps.length; i++) { - attributeMaps[i].addMapChangeListener(mapChangeListener); - } - } - - public void dispose() { - for (int i = 0; i < attributeMaps.length; i++) { - attributeMaps[i].removeMapChangeListener(mapChangeListener); - } - super.dispose(); - } - - public Image getImage(Object element) { - return null; - } - - public String getText(Object element) { - return getColumnText(element, 0); - } - - public Image getColumnImage(Object element, int columnIndex) { - return null; - } - - public String getColumnText(Object element, int columnIndex) { - if (columnIndex < attributeMaps.length) { - Object result = attributeMaps[columnIndex].get(element); - return result == null ? "" : result.toString(); //$NON-NLS-1$ - } - return null; - } - -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ObservableSetContentProvider.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ObservableSetContentProvider.java deleted file mode 100644 index 6526d7ba..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ObservableSetContentProvider.java +++ /dev/null @@ -1,106 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 116920 - * Matthew Hall - bugs 215531, 226765 - *******************************************************************************/ -package org.eclipse.jface.databinding.viewers; - -import java.util.Set; - -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.ISetChangeListener; -import org.eclipse.core.databinding.observable.set.SetChangeEvent; -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.internal.databinding.viewers.ObservableCollectionContentProvider; -import org.eclipse.jface.viewers.AbstractListViewer; -import org.eclipse.jface.viewers.AbstractTableViewer; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.Viewer; - -/** - * A {@link IStructuredContentProvider content provider} for - * {@link AbstractTableViewer} or {@link AbstractListViewer} that provides - * elements of an {@link IObservableSet} when set as the viewer's input. Objects - * of this class listen for changes to the observable set, and will insert and - * remove viewer elements to reflect observed changes. - * - * <p> - * This class is not intended to be subclassed by clients. - * - * @since 1.1 - */ -public class ObservableSetContentProvider implements IStructuredContentProvider { - private ObservableCollectionContentProvider impl; - - private static class Impl extends ObservableCollectionContentProvider - implements ISetChangeListener { - protected void checkInput(Object input) { - Assert - .isTrue(input instanceof IObservableSet, - "This content provider only works with input of type IObservableSet"); //$NON-NLS-1$ - } - - protected void addCollectionChangeListener( - IObservableCollection collection) { - ((IObservableSet) collection).addSetChangeListener(this); - } - - protected void removeCollectionChangeListener( - IObservableCollection collection) { - ((IObservableSet) collection).removeSetChangeListener(this); - } - - public void handleSetChange(SetChangeEvent event) { - if (isViewerDisposed()) - return; - - Set removals = event.diff.getRemovals(); - viewerUpdater.remove(removals.toArray()); - knownElements.removeAll(removals); - - Set additions = event.diff.getAdditions(); - knownElements.addAll(additions); - viewerUpdater.add(additions.toArray()); - } - } - - /** - * Constructs an ObservableSetContentProvider - */ - public ObservableSetContentProvider() { - impl = new Impl(); - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - impl.inputChanged(viewer, oldInput, newInput); - } - - public Object[] getElements(Object inputElement) { - return impl.getElements(inputElement); - } - - public void dispose() { - impl.dispose(); - } - - /** - * Returns the set of elements known to this content provider. Label - * providers may track this set if they need to be notified about additions - * before the viewer sees the added element, and notified about removals - * after the element was removed from the viewer. This is intended for use - * by label providers, as it will always return the items that need labels. - * - * @return unmodifiable set of items that will need labels - */ - public IObservableSet getKnownElements() { - return impl.getKnownElements(); - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ObservableSetTreeContentProvider.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ObservableSetTreeContentProvider.java deleted file mode 100644 index f3b8afa7..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ObservableSetTreeContentProvider.java +++ /dev/null @@ -1,162 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 207858) - * Matthew Hall - bug 226765 - *******************************************************************************/ - -package org.eclipse.jface.databinding.viewers; - -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.IObservablesListener; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.ISetChangeListener; -import org.eclipse.core.databinding.observable.set.SetChangeEvent; -import org.eclipse.jface.internal.databinding.viewers.ObservableCollectionTreeContentProvider; -import org.eclipse.jface.viewers.AbstractTreeViewer; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.Viewer; - -/** - * An {@link ITreeContentProvider} for use with an {@link AbstractTreeViewer}, - * which uses the provided {@link IObservableFactory set factory} to obtain the - * elements of a tree. Objects of this class listen for changes to each - * {@link IObservableSet} created by the factory, and will insert and remove - * viewer elements to reflect the observed changes. - * - * <p> - * This class is not intended to be subclassed by clients. - * - * @since 1.2 - */ -public class ObservableSetTreeContentProvider implements ITreeContentProvider { - private final ObservableCollectionTreeContentProvider impl; - - private static class Impl extends ObservableCollectionTreeContentProvider { - Impl(IObservableFactory setFactory, - TreeStructureAdvisor structureAdvisor) { - super(setFactory, structureAdvisor); - } - - private class SetChangeListener implements ISetChangeListener { - final Object parentElement; - - public SetChangeListener(Object parentElement) { - this.parentElement = parentElement; - } - - public void handleSetChange(SetChangeEvent event) { - if (isViewerDisposed()) - return; - - Set removals = event.diff.getRemovals(); - if (!removals.isEmpty()) { - viewerUpdater.remove(parentElement, removals.toArray()); - for (Iterator iterator = removals.iterator(); iterator - .hasNext();) { - Object child = iterator.next(); - TreeNode childNode = getExistingNode(child); - if (childNode != null) - childNode.removeParent(parentElement); - } - } - - Set additions = event.diff.getAdditions(); - if (!additions.isEmpty()) { - for (Iterator iterator = additions.iterator(); iterator - .hasNext();) { - Object child = iterator.next(); - getOrCreateNode(child).addParent(parentElement); - } - viewerUpdater.add(parentElement, additions.toArray()); - } - } - } - - protected IObservablesListener createCollectionChangeListener( - Object parentElement) { - return new SetChangeListener(parentElement); - } - - protected void addCollectionChangeListener( - IObservableCollection collection, IObservablesListener listener) { - IObservableSet set = (IObservableSet) collection; - ISetChangeListener setListener = (ISetChangeListener) listener; - set.addSetChangeListener(setListener); - } - - protected void removeCollectionChangeListener( - IObservableCollection collection, IObservablesListener listener) { - IObservableSet set = (IObservableSet) collection; - ISetChangeListener setListener = (ISetChangeListener) listener; - set.removeSetChangeListener(setListener); - } - } - - /** - * Constructs an ObservableListTreeContentProvider using the given list - * factory. - * - * @param setFactory - * observable factory that produces an IObservableSet of children - * for a given parent element. Observable sets created by this - * factory must be on the realm of the current display. - * @param structureAdvisor - * an advisor that will be consulted from the implementations of - * the {@link #getParent(Object)} and - * {@link #hasChildren(Object)} methods, or <code>null</code> - * if no advisor is available. It is recommended that clients - * pass a non-null advisor if they can provide additional - * structural information about the tree. - */ - public ObservableSetTreeContentProvider(IObservableFactory setFactory, - TreeStructureAdvisor structureAdvisor) { - impl = new Impl(setFactory, structureAdvisor); - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - impl.inputChanged(viewer, oldInput, newInput); - } - - public Object[] getElements(Object inputElement) { - return impl.getElements(inputElement); - } - - public boolean hasChildren(Object element) { - return impl.hasChildren(element); - } - - public Object[] getChildren(Object parentElement) { - return impl.getChildren(parentElement); - } - - public Object getParent(Object element) { - return impl.getParent(element); - } - - public void dispose() { - impl.dispose(); - } - - /** - * Returns the set of elements known to this content provider. Label - * providers may track this set if they need to be notified about additions - * before the viewer sees the added element, and notified about removals - * after the element was removed from the viewer. This is intended for use - * by label providers, as it will always return the items that need labels. - * - * @return readableSet of items that will need labels - */ - public IObservableSet getKnownElements() { - return impl.getKnownElements(); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ObservableValueEditingSupport.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ObservableValueEditingSupport.java deleted file mode 100644 index 3111c8d0..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ObservableValueEditingSupport.java +++ /dev/null @@ -1,220 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.databinding.viewers; - -import org.eclipse.core.databinding.Binding; -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.UpdateValueStrategy; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.ColumnViewer; -import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent; -import org.eclipse.jface.viewers.ColumnViewerEditorActivationListener; -import org.eclipse.jface.viewers.ColumnViewerEditorDeactivationEvent; -import org.eclipse.jface.viewers.EditingSupport; -import org.eclipse.jface.viewers.ViewerCell; - -/** - * {@link EditingSupport} using the JFace Data Binding concepts to handle the - * updating of an element from a {@link CellEditor}. - * - * @since 1.2 - */ -public abstract class ObservableValueEditingSupport extends EditingSupport { - /** - * Maintains references to the instances currently imployed while editing. - * Will be <code>null</code> when not editing. - */ - private EditingState editingState; - - private final ColumnViewerEditorActivationListenerHelper activationListener = new ColumnViewerEditorActivationListenerHelper(); - - private ColumnViewer viewer; - - private DataBindingContext dbc; - - /** - * Constructs a new instance with the provided <code>viewer</code> and - * <code>dbc</code>. - * - * @param viewer - * viewer to edit - * @param dbc - * dbc to create <code>Bindings</code> - */ - public ObservableValueEditingSupport(ColumnViewer viewer, - DataBindingContext dbc) { - super(viewer); - - if (dbc == null) { - throw new IllegalArgumentException("Parameter dbc was null."); //$NON-NLS-1$ - } - - this.viewer = viewer; - this.dbc = dbc; - } - - /** - * Default implementation always returns <code>true</code>. - * - * @see org.eclipse.jface.viewers.EditingSupport#canEdit(java.lang.Object) - */ - protected boolean canEdit(Object element) { - return true; - } - - /** - * Default implementation always returns <code>null</code> as this will be - * handled by the Binding. - * - * @see org.eclipse.jface.viewers.EditingSupport#getValue(java.lang.Object) - */ - protected Object getValue(Object element) { - // no op - return null; - } - - /** - * Default implementation does nothing as this will be handled by the - * Binding. - * - * @see org.eclipse.jface.viewers.EditingSupport#setValue(java.lang.Object, - * java.lang.Object) - */ - protected void setValue(Object element, Object value) { - // no op - } - - /** - * Creates a {@link Binding} between the editor and the element to be - * edited. Invokes {@link #doCreateCellEditorObservable(CellEditor)}, - * {@link #doCreateElementObservable(Object, ViewerCell)}, and then - * {@link #createBinding(IObservableValue, IObservableValue)}. - */ - final protected void initializeCellEditorValue(CellEditor cellEditor, - ViewerCell cell) { - IObservableValue target = doCreateCellEditorObservable(cellEditor); - Assert - .isNotNull(target, - "doCreateCellEditorObservable(...) did not return an observable"); //$NON-NLS-1$ - - IObservableValue model = doCreateElementObservable(cell.getElement(), - cell); - Assert.isNotNull(model, - "doCreateElementObservable(...) did not return an observable"); //$NON-NLS-1$ - - Binding binding = createBinding(target, model); - Assert - .isNotNull(binding, - "createBinding(...) did not return a binding"); //$NON-NLS-1$ - - editingState = new EditingState(binding, target, model); - - getViewer().getColumnViewerEditor().addEditorActivationListener( - activationListener); - } - - /** - * Creates the observable value for the CellEditor. - * - * @param cellEditor - * @return observable value - */ - protected abstract IObservableValue doCreateCellEditorObservable( - CellEditor cellEditor); - - /** - * Creates the observable value for the element. - * - * @param element - * @param cell - * @return observable value - */ - protected abstract IObservableValue doCreateElementObservable( - Object element, ViewerCell cell); - - /** - * Creates a new binding for the provided <code>target</code> and - * <code>model</code>. Default - * {@link UpdateValueStrategy value update strategies} are used with the - * target to model updating on {@link UpdateValueStrategy#POLICY_CONVERT}. - * - * @param target - * @param model - * @return binding - */ - protected Binding createBinding(IObservableValue target, - IObservableValue model) { - return dbc.bindValue(target, model, new UpdateValueStrategy( - UpdateValueStrategy.POLICY_CONVERT), null); - } - - /** - * Updates the model from the target. - */ - final protected void saveCellEditorValue(CellEditor cellEditor, - ViewerCell cell) { - editingState.binding.updateTargetToModel(); - } - - private class ColumnViewerEditorActivationListenerHelper extends - ColumnViewerEditorActivationListener { - - public void afterEditorActivated(ColumnViewerEditorActivationEvent event) { - // do nothing - } - - public void afterEditorDeactivated( - ColumnViewerEditorDeactivationEvent event) { - editingState.dispose(); - editingState = null; - - viewer.getColumnViewerEditor().removeEditorActivationListener(this); - } - - public void beforeEditorActivated( - ColumnViewerEditorActivationEvent event) { - // do nothing - } - - public void beforeEditorDeactivated( - ColumnViewerEditorDeactivationEvent event) { - // do nothing - } - } - - /** - * Maintains references to objects that only live for the length of the edit - * cycle. - */ - private static class EditingState { - IObservableValue target; - - IObservableValue model; - - Binding binding; - - EditingState(Binding binding, IObservableValue target, - IObservableValue model) { - this.binding = binding; - this.target = target; - this.model = model; - } - - void dispose() { - target.dispose(); - model.dispose(); - binding.dispose(); - } - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/TreeStructureAdvisor.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/TreeStructureAdvisor.java deleted file mode 100644 index ef569935..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/TreeStructureAdvisor.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ -package org.eclipse.jface.databinding.viewers; - -/** - * Instances of this class can be used to improve accuracy and performance of an - * {@link ObservableListTreeContentProvider} or an - * {@link ObservableSetTreeContentProvider}. This class is intended to be - * subclassed by clients. - * - * @since 1.2 - * - */ -public abstract class TreeStructureAdvisor { - - /** - * Returns the parent for the given element, or <code>null</code> - * indicating that the parent can't be computed. In this case the - * tree-structured viewer can't expand a given node correctly if requested. - * The default implementation returns null; clients should override. - * - * @param element - * the element - * @return the parent element, or <code>null</code> if it has none or if - * the parent cannot be computed - */ - public Object getParent(Object element) { - return null; - } - - /** - * Returns whether the given element has children, or <code>null</code> if - * the actual children collection should be consulted. The default - * implementation returns null; clients should override. - * <p> - * Intended as an optimization for when the viewer does not need the actual - * children. Clients may be able to implement this more efficiently than - * <code>getChildren</code>. - * </p> - * - * @param element - * the element - * @return <code>Boolean.TRUE</code> if the given element has children, - * <code>Boolean.FALSE</code> if it has no children, or - * <code>null</code> if the children collection should be - * consulted. - */ - public Boolean hasChildren(Object element) { - return null; - } - -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ViewersObservables.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ViewersObservables.java deleted file mode 100644 index 567b52ff..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ViewersObservables.java +++ /dev/null @@ -1,218 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 206839 - * Matthew Hall - bug 124684 - *******************************************************************************/ - -package org.eclipse.jface.databinding.viewers; - -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.internal.databinding.viewers.CheckableCheckedElementsObservableSet; -import org.eclipse.jface.internal.databinding.viewers.CheckboxViewerCheckedElementsObservableSet; -import org.eclipse.jface.internal.databinding.viewers.SelectionProviderMultipleSelectionObservableList; -import org.eclipse.jface.internal.databinding.viewers.SelectionProviderSingleSelectionObservableValue; -import org.eclipse.jface.internal.databinding.viewers.ViewerInputObservableValue; -import org.eclipse.jface.internal.databinding.viewers.ViewerMultipleSelectionObservableList; -import org.eclipse.jface.internal.databinding.viewers.ViewerSingleSelectionObservableValue; -import org.eclipse.jface.viewers.CheckboxTableViewer; -import org.eclipse.jface.viewers.CheckboxTreeViewer; -import org.eclipse.jface.viewers.ICheckable; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.widgets.Display; - -/** - * Factory methods for creating observables for JFace viewers - * - * @since 1.1 - */ -public class ViewersObservables { - - /** - * Returns an observable value that tracks the current selection of the - * given selection provider. If the selection provider provides selections - * of type {@link IStructuredSelection}, the observable value will be the - * first element of the structured selection as returned by - * {@link IStructuredSelection#getFirstElement()}. - * - * @param selectionProvider - * @return the observable value tracking the (single) selection of the given - * selection provider - */ - public static IObservableValue observeSingleSelection( - ISelectionProvider selectionProvider) { - if (selectionProvider instanceof Viewer) { - return observeSingleSelection((Viewer) selectionProvider); - } - return new SelectionProviderSingleSelectionObservableValue( - SWTObservables.getRealm(Display.getDefault()), - selectionProvider); - } - - /** - * Returns an observable list that tracks the current selection of the - * given selection provider. Assumes that the selection provider provides - * selections of type {@link IStructuredSelection}. Note that the - * observable list will not honor the full contract of - * <code>java.util.List</code> in that it may delete or reorder elements - * based on what the selection provider returns from - * {@link ISelectionProvider#getSelection()} after having called - * {@link ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection)} - * based on the requested change to the observable list. The affected - * methods are <code>add</code>, <code>addAll</code>, and - * <code>set</code>. - * - * @param selectionProvider - * @return the observable value tracking the (multi) selection of the given - * selection provider - * - * @since 1.2 - */ - public static IObservableList observeMultiSelection( - ISelectionProvider selectionProvider) { - if (selectionProvider instanceof Viewer) { - return observeMultiSelection((Viewer) selectionProvider); - } - return new SelectionProviderMultipleSelectionObservableList( - SWTObservables.getRealm(Display.getDefault()), - selectionProvider, Object.class); - } - - /** - * Returns an observable value that tracks the current selection of the - * given viewer. If the viewer provides selections of type - * {@link IStructuredSelection}, the observable value will be the first - * element of the structured selection as returned by - * {@link IStructuredSelection#getFirstElement()}. - * - * @param viewer - * the viewer - * @return the observable value tracking the (single) selection of the given - * viewer - * @since 1.2 - */ - public static IViewerObservableValue observeSingleSelection(Viewer viewer) { - return new ViewerSingleSelectionObservableValue( - SWTObservables.getRealm(Display.getDefault()), - viewer); - } - - /** - * Returns an observable list that tracks the current selection of the - * given viewer. Assumes that the viewer provides - * selections of type {@link IStructuredSelection}. Note that the - * observable list will not honor the full contract of - * <code>java.util.List</code> in that it may delete or reorder elements - * based on what the viewer returns from - * {@link ISelectionProvider#getSelection()} after having called - * {@link ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection)} - * based on the requested change to the observable list. The affected - * methods are <code>add</code>, <code>addAll</code>, and - * <code>set</code>. - * - * @param viewer - * @return the observable value tracking the (multi) selection of the given - * selection provider - * - * @since 1.2 - */ - public static IViewerObservableList observeMultiSelection( - Viewer viewer) { - return new ViewerMultipleSelectionObservableList( - SWTObservables.getRealm(Display.getDefault()), - viewer, Object.class); - } - - /** - * Returns an observable value that tracks the input of the given viewer. - * <p> - * The returned observer is blind to changes in the viewer's input unless - * its {@link IObservableValue#setValue(Object)} method is called directly. - * - * @param viewer - * the viewer to observe - * @return an observable value tracking the input of the given viewer - * @since 1.2 - */ - public static IObservableValue observeInput(Viewer viewer) { - return new ViewerInputObservableValue(SWTObservables.getRealm(viewer - .getControl().getDisplay()), viewer); - } - - /** - * Returns an observable set that tracks the checked elements of the given - * <code>ICheckable</code>. - * - * @param checkable - * {@link ICheckable} containing the checked elements to track - * @param elementType - * element type of the returned set - * @return an observable set tracking the checked elements of the given - * checkable. - * @since 1.2 - */ - public static IObservableSet observeCheckedElements(ICheckable checkable, - Object elementType) { - if (checkable instanceof CheckboxTableViewer) { - return observeCheckedElements((CheckboxTableViewer) checkable, - elementType); - } - if (checkable instanceof CheckboxTreeViewer) { - return observeCheckedElements((CheckboxTreeViewer) checkable, - elementType); - } - return new CheckableCheckedElementsObservableSet(SWTObservables - .getRealm(Display.getDefault()), checkable, elementType); - } - - /** - * Returns an observable set that tracks the checked elements of the given - * viewer. Assumes that the viewer implements {@link ICheckable}. - * - * @param viewer - * {@link CheckboxTableViewer} containing the checked elements to - * track. - * @param elementType - * element type of the returned set - * @return an observable set that tracks the checked elements of the given - * viewer. - * @since 1.2 - */ - public static IViewerObservableSet observeCheckedElements( - CheckboxTableViewer viewer, Object elementType) { - return new CheckboxViewerCheckedElementsObservableSet(SWTObservables - .getRealm(viewer.getControl().getDisplay()), viewer, - elementType); - } - - /** - * Returns an observable set that tracks the checked elements of the given - * viewer. Assumes that the viewer implements {@link ICheckable}. - * - * @param viewer - * {@link CheckboxTreeViewer} containing the checked elements to - * track. - * @param elementType - * element type of the returned set - * @return an observable set that tracks the checked elements of the given - * viewer. - * @since 1.2 - */ - public static IViewerObservableSet observeCheckedElements( - CheckboxTreeViewer viewer, Object elementType) { - return new CheckboxViewerCheckedElementsObservableSet(SWTObservables - .getRealm(viewer.getControl().getDisplay()), viewer, - elementType); - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/package.html b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/package.html deleted file mode 100644 index 2ebf7483..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/package.html +++ /dev/null @@ -1,16 +0,0 @@ -<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> - <meta name="Author" content="IBM"> - <meta name="GENERATOR" content="Mozilla/4.5 [en] (Win98; I) [Netscape]"> - <title>Package-level Javadoc</title> -</head> -<body> -Provides classes that can be used to observe the JFace Viewer framework. -<h2> -Package Specification</h2> -<p> -This package provides classes that can be used to observe the JFace Viewer framework.</p> -</body> -</html> diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/wizard/WizardPageSupport.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/wizard/WizardPageSupport.java deleted file mode 100644 index 5faf8ac6..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/wizard/WizardPageSupport.java +++ /dev/null @@ -1,300 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Boris Bokowski - bug 218269 - * Matthew Hall - bug 218269 - * Ashley Cambrell - bug 199179 - * Ovidio Mallo - bug 235195 - *******************************************************************************/ -package org.eclipse.jface.databinding.wizard; - -import java.util.Iterator; - -import org.eclipse.core.databinding.AggregateValidationStatus; -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.ValidationStatusProvider; -import org.eclipse.core.databinding.observable.ChangeEvent; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.list.IListChangeListener; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.ListChangeEvent; -import org.eclipse.core.databinding.observable.list.ListDiff; -import org.eclipse.core.databinding.observable.list.ListDiffEntry; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.observable.value.ValueChangeEvent; -import org.eclipse.core.databinding.util.Policy; -import org.eclipse.core.runtime.AssertionFailedException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.dialogs.IMessageProvider; -import org.eclipse.jface.wizard.WizardPage; - -/** - * Connects the validation result from the given data binding context to the - * given wizard page, updating the wizard page's completion state and its error - * message accordingly. - * - * @noextend This class is not intended to be subclassed by clients. - * - * @since 1.1 - */ -public class WizardPageSupport { - - private WizardPage wizardPage; - private DataBindingContext dbc; - private AggregateValidationStatus aggregateStatus; - private boolean uiChanged = false; - - /** - * Connect the validation result from the given data binding context to the - * given wizard page. Upon creation, the wizard page support will use the - * context's validation result to determine whether the page is complete. - * The page's error message will not be set at this time ensuring that the - * wizard page does not show an error right away. Upon any validation result - * change, {@link WizardPage#setPageComplete(boolean)} will be called - * reflecting the new validation result, and the wizard page's error message - * will be updated according to the current validation result. - * - * @param wizardPage - * @param dbc - * @return an instance of WizardPageSupport - */ - public static WizardPageSupport create(WizardPage wizardPage, - DataBindingContext dbc) { - return new WizardPageSupport(wizardPage, dbc); - } - - private WizardPageSupport(WizardPage wizardPage, DataBindingContext dbc) { - this.wizardPage = wizardPage; - this.dbc = dbc; - init(); - } - - private IChangeListener uiChangeListener = new IChangeListener() { - public void handleChange(ChangeEvent event) { - handleUIChanged(); - } - }; - private IListChangeListener validationStatusProvidersListener = new IListChangeListener() { - public void handleListChange(ListChangeEvent event) { - ListDiff diff = event.diff; - ListDiffEntry[] differences = diff.getDifferences(); - for (int i = 0; i < differences.length; i++) { - ListDiffEntry listDiffEntry = differences[i]; - ValidationStatusProvider validationStatusProvider = (ValidationStatusProvider) listDiffEntry - .getElement(); - IObservableList targets = validationStatusProvider.getTargets(); - if (listDiffEntry.isAddition()) { - targets - .addListChangeListener(validationStatusProviderTargetsListener); - for (Iterator it = targets.iterator(); it.hasNext();) { - ((IObservable) it.next()) - .addChangeListener(uiChangeListener); - } - } else { - targets - .removeListChangeListener(validationStatusProviderTargetsListener); - for (Iterator it = targets.iterator(); it.hasNext();) { - ((IObservable) it.next()) - .removeChangeListener(uiChangeListener); - } - } - } - } - }; - private IListChangeListener validationStatusProviderTargetsListener = new IListChangeListener() { - public void handleListChange(ListChangeEvent event) { - ListDiff diff = event.diff; - ListDiffEntry[] differences = diff.getDifferences(); - for (int i = 0; i < differences.length; i++) { - ListDiffEntry listDiffEntry = differences[i]; - IObservable target = (IObservable) listDiffEntry.getElement(); - if (listDiffEntry.isAddition()) { - target.addChangeListener(uiChangeListener); - } else { - target.removeChangeListener(uiChangeListener); - } - } - } - }; - private IStatus currentStatus; - - protected void init() { - aggregateStatus = new AggregateValidationStatus(dbc - .getValidationStatusProviders(), - AggregateValidationStatus.MAX_SEVERITY); - aggregateStatus.addValueChangeListener(new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - - currentStatus = (IStatus) event.diff.getNewValue(); - handleStatusChanged(); - } - }); - currentStatus = (IStatus) aggregateStatus.getValue(); - handleStatusChanged(); - dbc.getValidationStatusProviders().addListChangeListener( - validationStatusProvidersListener); - for (Iterator it = dbc.getValidationStatusProviders().iterator(); it - .hasNext();) { - ValidationStatusProvider validationStatusProvider = (ValidationStatusProvider) it - .next(); - IObservableList targets = validationStatusProvider.getTargets(); - targets - .addListChangeListener(validationStatusProviderTargetsListener); - for (Iterator iter = targets.iterator(); iter.hasNext();) { - ((IObservable) iter.next()).addChangeListener(uiChangeListener); - } - } - } - - protected void handleUIChanged() { - uiChanged = true; - if (currentStatus != null) { - handleStatusChanged(); - } - dbc.getValidationStatusProviders().removeListChangeListener( - validationStatusProvidersListener); - for (Iterator it = dbc.getValidationStatusProviders().iterator(); it - .hasNext();) { - ValidationStatusProvider validationStatusProvider = (ValidationStatusProvider) it - .next(); - IObservableList targets = validationStatusProvider.getTargets(); - targets - .removeListChangeListener(validationStatusProviderTargetsListener); - for (Iterator iter = targets.iterator(); iter.hasNext();) { - ((IObservable) iter.next()) - .removeChangeListener(uiChangeListener); - } - } - } - - protected void handleStatusChanged() { - if (currentStatus != null - && currentStatus.getSeverity() == IStatus.ERROR) { - wizardPage.setPageComplete(false); - wizardPage.setMessage(null); - wizardPage.setErrorMessage(uiChanged ? currentStatus.getMessage() - : null); - if (currentStatusHasException()) { - handleStatusException(); - } - } else if (currentStatus != null - && currentStatus.getSeverity() != IStatus.OK) { - int severity = currentStatus.getSeverity(); - wizardPage.setPageComplete((severity & IStatus.CANCEL) == 0); - int type; - switch (severity) { - case IStatus.OK: - type = IMessageProvider.NONE; - break; - case IStatus.CANCEL: - type = IMessageProvider.NONE; - break; - case IStatus.INFO: - type = IMessageProvider.INFORMATION; - break; - case IStatus.WARNING: - type = IMessageProvider.WARNING; - break; - case IStatus.ERROR: - type = IMessageProvider.ERROR; - break; - default: - throw new AssertionFailedException( - "incomplete switch statement"); //$NON-NLS-1$ - } - wizardPage.setErrorMessage(null); - wizardPage.setMessage(currentStatus.getMessage(), type); - } else { - wizardPage.setPageComplete(true); - wizardPage.setMessage(null); - wizardPage.setErrorMessage(null); - } - } - - private boolean currentStatusHasException() { - boolean hasException = false; - if (currentStatus.getException() != null) { - hasException = true; - } - if (currentStatus instanceof MultiStatus) { - MultiStatus multiStatus = (MultiStatus) currentStatus; - - for (int i = 0; i < multiStatus.getChildren().length; i++) { - IStatus status = multiStatus.getChildren()[i]; - if (status.getException() != null) { - hasException = true; - break; - } - } - } - return hasException; - } - - /** - * This is called when a Override to provide custom exception handling and - * reporting. - */ - protected void handleStatusException() { - if (currentStatus.getException() != null) { - logThrowable(currentStatus.getException()); - } else if (currentStatus instanceof MultiStatus) { - MultiStatus multiStatus = (MultiStatus) currentStatus; - for (int i = 0; i < multiStatus.getChildren().length; i++) { - IStatus status = multiStatus.getChildren()[i]; - if (status.getException() != null) { - logThrowable(status.getException()); - } - } - } - } - - private void logThrowable(Throwable throwable) { - Policy - .getLog() - .log( - new Status( - IStatus.ERROR, - Policy.JFACE_DATABINDING, - IStatus.OK, - "Unhandled exception: " + throwable.getMessage(), throwable)); //$NON-NLS-1$ - } - - /** - * Disposes of this wizard page support object, removing any listeners it - * may have attached. - */ - public void dispose() { - aggregateStatus.dispose(); - if (!uiChanged) { - for (Iterator it = dbc.getValidationStatusProviders().iterator(); it - .hasNext();) { - ValidationStatusProvider validationStatusProvider = (ValidationStatusProvider) it - .next(); - IObservableList targets = validationStatusProvider.getTargets(); - targets - .removeListChangeListener(validationStatusProviderTargetsListener); - for (Iterator iter = targets.iterator(); iter.hasNext();) { - ((IObservable) iter.next()) - .removeChangeListener(uiChangeListener); - } - } - dbc.getValidationStatusProviders().removeListChangeListener( - validationStatusProvidersListener); - } - aggregateStatus = null; - dbc = null; - uiChangeListener = null; - validationStatusProvidersListener = null; - validationStatusProviderTargetsListener = null; - wizardPage = null; - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/wizard/package.html b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/wizard/package.html deleted file mode 100755 index b0949811..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/wizard/package.html +++ /dev/null @@ -1,16 +0,0 @@ -<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> - <meta name="Author" content="IBM"> - <meta name="GENERATOR" content="Mozilla/4.5 [en] (Win98; I) [Netscape]"> - <title>Package-level Javadoc</title> -</head> -<body> -Provides classes that bridge between data binding and the JFace Wizard framework. -<h2> -Package Specification</h2> -<p> -This package provides classes that bridge between data binding and the JFace Wizard framework.</p> -</body> -</html> diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/internal/swt/LinkObservableValue.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/internal/swt/LinkObservableValue.java deleted file mode 100644 index fac53722..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/internal/swt/LinkObservableValue.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Michael Krauter, Catuno GmbH 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: - * Michael Krauter, Catuno GmbH - initial API and implementation (bug 180223) - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.internal.swt; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue; -import org.eclipse.swt.widgets.Link; - -/** - * @since 1.2 - * - */ -public class LinkObservableValue extends AbstractSWTObservableValue { - - private final Link link; - - /** - * @param link - */ - public LinkObservableValue(Link link) { - super(link); - this.link = link; - } - - public void doSetValue(final Object value) { - String oldValue = link.getText(); - link.setText(value == null ? "" : value.toString()); //$NON-NLS-1$ - fireValueChange(Diffs.createValueDiff(oldValue, link.getText())); - } - - public Object doGetValue() { - return link.getText(); - } - - public Object getValueType() { - return String.class; - } - -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/AbstractSWTObservableValue.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/AbstractSWTObservableValue.java deleted file mode 100644 index 3f667fd5..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/AbstractSWTObservableValue.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 The Pampered Chef, Inc. 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: - * The Pampered Chef, Inc. - initial API and implementation - ******************************************************************************/ - -package org.eclipse.jface.internal.databinding.provisional.swt; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.AbstractObservableValue; -import org.eclipse.jface.databinding.swt.ISWTObservableValue; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; -import org.eclipse.swt.widgets.Widget; - -/** - * NON-API - An abstract superclass for observable values that gurantees that the - * observable will be disposed when the control to which it is attached is - * disposed. - * - * @since 1.1 - */ -public abstract class AbstractSWTObservableValue extends AbstractObservableValue implements ISWTObservableValue { - - private final Widget widget; - - /** - * Standard constructor for an SWT ObservableValue. Makes sure that - * the observable gets disposed when the SWT widget is disposed. - * - * @param widget - */ - protected AbstractSWTObservableValue(Widget widget) { - this(SWTObservables.getRealm(widget.getDisplay()), widget); - } - - /** - * Constructor that allows for the setting of the realm. Makes sure that the - * observable gets disposed when the SWT widget is disposed. - * - * @param realm - * @param widget - * @since 1.2 - */ - protected AbstractSWTObservableValue(Realm realm, Widget widget) { - super(realm); - this.widget = widget; - widget.addDisposeListener(disposeListener); - } - - private DisposeListener disposeListener = new DisposeListener() { - public void widgetDisposed(DisposeEvent e) { - AbstractSWTObservableValue.this.dispose(); - } - }; - - /** - * @return Returns the widget. - */ - public Widget getWidget() { - return widget; - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/AbstractSWTVetoableValue.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/AbstractSWTVetoableValue.java deleted file mode 100644 index 7cf6954d..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/AbstractSWTVetoableValue.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 The Pampered Chef, Inc. 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: - * The Pampered Chef, Inc. - initial API and implementation - ******************************************************************************/ - -package org.eclipse.jface.internal.databinding.provisional.swt; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.AbstractVetoableValue; -import org.eclipse.jface.databinding.swt.ISWTObservableValue; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; -import org.eclipse.swt.widgets.Widget; - -/** - * NON-API - An abstract superclass for vetoable values that gurantees that the - * observable will be disposed when the control to which it is attached is - * disposed. - * - * @since 1.1 - */ -public abstract class AbstractSWTVetoableValue extends AbstractVetoableValue implements ISWTObservableValue { - - private final Widget widget; - - /** - * Standard constructor for an SWT VetoableValue. Makes sure that - * the observable gets disposed when the SWT widget is disposed. - * - * @param widget - */ - protected AbstractSWTVetoableValue(Widget widget) { - this(SWTObservables.getRealm(widget.getDisplay()), widget); - } - - /** - * Constructs a new instance for the provided <code>realm</code> and <code>widget</code>. - * - * @param realm - * @param widget - * @since 1.2 - */ - protected AbstractSWTVetoableValue(Realm realm, Widget widget) { - super(realm); - this.widget = widget; - if (widget == null) { - throw new IllegalArgumentException("The widget parameter is null."); //$NON-NLS-1$ - } - widget.addDisposeListener(disposeListener); - } - - private DisposeListener disposeListener = new DisposeListener() { - public void widgetDisposed(DisposeEvent e) { - AbstractSWTVetoableValue.this.dispose(); - } - }; - - /** - * @return Returns the widget. - */ - public Widget getWidget() { - return widget; - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/CompositeUpdater.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/CompositeUpdater.java deleted file mode 100644 index 2927e3d4..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/CompositeUpdater.java +++ /dev/null @@ -1,243 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Boris Bokowski, IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.provisional.swt; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.databinding.observable.ChangeEvent; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.list.IListChangeListener; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.ListChangeEvent; -import org.eclipse.core.databinding.observable.list.ListDiffEntry; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Widget; - -/** - * NON-API - This class can be used to update a composite with automatic dependency tracking. - * @since 1.1 - * - */ -public abstract class CompositeUpdater { - - private class UpdateRunnable implements Runnable, IChangeListener { - private Widget widget; - Object element; - - private boolean dirty = true; - - private IObservable[] dependencies = new IObservable[0]; - - UpdateRunnable(Widget widget, Object element) { - this.widget = widget; - this.element = element; - } - - // Runnable implementation. This method runs at most once per repaint - // whenever the - // value gets marked as dirty. - public void run() { - if (theComposite != null && !theComposite.isDisposed() - && widget != null && !widget.isDisposed()) { - updateIfNecessary(); - } - } - - private void updateIfNecessary() { - if (dirty) { - dependencies = ObservableTracker.runAndMonitor(new Runnable() { - public void run() { - updateWidget(widget, element); - } - }, this, null); - dirty = false; - } - } - - // IChangeListener implementation (listening to any dependency) - public void handleChange(ChangeEvent event) { - // Whenever this updator becomes dirty, schedule the run() method - makeDirty(); - } - - protected final void makeDirty() { - if (!dirty) { - dirty = true; - stopListening(); - if (!theComposite.isDisposed()) { - SWTUtil.runOnce(theComposite.getDisplay(), this); - } - } - } - - private void stopListening() { - // Stop listening for dependency changes - for (int i = 0; i < dependencies.length; i++) { - IObservable observable = dependencies[i]; - - observable.removeChangeListener(this); - } - } - } - - private class LayoutRunnable implements Runnable { - private boolean posted = false; - private Set controlsToLayout = new HashSet(); - void add(Control toLayout) { - controlsToLayout.add(toLayout); - if (!posted) { - posted = true; - theComposite.getDisplay().asyncExec(this); - } - } - public void run() { - posted = false; - theComposite.getShell().layout((Control[])controlsToLayout.toArray(new Control[controlsToLayout.size()])); - controlsToLayout.clear(); - } - } - - private LayoutRunnable layoutRunnable = new LayoutRunnable(); - - /** - * To be called from {@link #updateWidget(Widget, Object)} or {@link #createWidget(int)} - * if this updater's composite's layout may need to be updated. - * @param control - * @since 1.2 - */ - protected void requestLayout(Control control) { - layoutRunnable.add(control); - } - - private class PrivateInterface implements DisposeListener, - IListChangeListener { - - // DisposeListener implementation - public void widgetDisposed(DisposeEvent e) { - CompositeUpdater.this.dispose(); - } - - public void handleListChange(ListChangeEvent event) { - ListDiffEntry[] diffs = event.diff.getDifferences(); - for (int i = 0; i < diffs.length; i++) { - ListDiffEntry listDiffEntry = diffs[i]; - if (listDiffEntry.isAddition()) { - createChild(listDiffEntry.getElement(), listDiffEntry.getPosition()); - } else { - disposeWidget(listDiffEntry.getPosition()); - } - } - theComposite.layout(); - } - - } - - private PrivateInterface privateInterface = new PrivateInterface(); - - private Composite theComposite; - - private IObservableList model; - - /** - * Creates an updater for the given control and list. For each element of - * the list, a child widget of the composite will be created using - * {@link #createWidget(int)}. - * - * @param toUpdate - * composite to update - * @param model - * an observable list to track - */ - public CompositeUpdater(Composite toUpdate, IObservableList model) { - this.theComposite = toUpdate; - this.model = model; - - model.addListChangeListener(privateInterface); - theComposite.addDisposeListener(privateInterface); - ObservableTracker.runAndIgnore(new Runnable(){ - public void run() { - int index = 0; - for (Iterator it = CompositeUpdater.this.model.iterator(); it.hasNext();) { - Object element = it.next(); - createChild(element, index++); - } - } - }); - } - - /** - * @param position - * @since 1.2 - */ - protected void disposeWidget(int position) { - theComposite.getChildren()[position].dispose(); - } - - /** - * This is called automatically when the control is disposed. It may also be - * called explicitly to remove this updator from the control. Subclasses - * will normally extend this method to detach any listeners they attached in - * their constructor. - */ - public void dispose() { - theComposite.removeDisposeListener(privateInterface); - model.removeListChangeListener(privateInterface); - } - - /** - * Creates a new child widget for the target composite at the given index. - * - * <p> - * Subclasses should implement this method to provide the code that creates - * a child widget at a specific index. Note that - * {@link #updateWidget(Widget, Object)} will be called after this method - * returns. Only those properties of the widget that don't change over time - * should be set in this method. - * </p> - * - * @param index - * the at which to create the widget - * @return the widget - */ - protected abstract Widget createWidget(int index); - - /** - * Updates the given widget based on the element found in the model list. - * This method will be invoked once after the widget is created, and once - * before any repaint during which the control is visible and dirty. - * - * <p> - * Subclasses should implement this method to provide any code that changes - * the appearance of the widget. - * </p> - * - * @param widget - * the widget to update - * @param element - * the element associated with the widget - */ - protected abstract void updateWidget(Widget widget, Object element); - - void createChild(Object element, int index) { - Widget newChild = createWidget(index); - final UpdateRunnable updateRunnable = new UpdateRunnable(newChild, element); - newChild.setData(updateRunnable); - updateRunnable.updateIfNecessary(); - } - -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/ControlUpdater.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/ControlUpdater.java deleted file mode 100644 index ca819b74..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/ControlUpdater.java +++ /dev/null @@ -1,181 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.provisional.swt; - -import org.eclipse.core.databinding.observable.ChangeEvent; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; -import org.eclipse.swt.events.PaintEvent; -import org.eclipse.swt.events.PaintListener; -import org.eclipse.swt.widgets.Control; - -/** - * NON-API - A ControlUpdater updates an SWT control in response to changes in the model. - * By wrapping a block of code in a ControlUpdater, clients can rely on the fact - * that the block of code will be re-executed whenever anything changes in the - * model that might affect its behavior. - * - * <p> - * ControlUpdaters only execute when their controls are visible. If something changes - * in the model while the control is invisible, the updator is flagged as dirty and - * the updator stops listening to the model until the next time the control repaints. - * This saves CPU cycles by deferring UI updates to widgets that are currently invisible. - * </p> - * - * <p> - * Clients should subclass this when copying information from the model to - * a control. Typical usage: - * </p> - * - * <ul> - * <li>Override updateControl. It should do whatever is necessary to display - * the contents of the model in the control.</li> - * <li>In the constructor, attach listeners to the model. The listeners should - * call markDirty whenever anything changes in the model that affects - * updateControl. Note: this step can be omitted when calling any method - * tagged with "@TrackedGetter" since ControlUpdater will automatically attach - * a listener to any object if a "@TrackedGetter" method is called in - * updateControl.</li> - * <li>(optional)Extend dispose() to remove any listeners attached in the constructor</li> - * </ul> - * - * <p> - * Example: - * </p> - * - * <code> - * // Displays an observable value in a label and keeps the label in synch with changes - * // in the value. - * IReadableValue someValue = ... - * final Label myLabel = new Label(parent, SWT.NONE); - * new ControlUpdater(myLabel) { - * protected void updateControl() { - * myLabel.setText(someValue.getValue().toString); - * } - * } - * // myLabel will display the value of someValue the next time it repaints, and will automatically - * // be updated whenever someValue changes and the label is visible - * </code> - * - * @since 1.1 - */ -public abstract class ControlUpdater { - - private class PrivateInterface implements PaintListener, - DisposeListener, Runnable, IChangeListener { - - // PaintListener implementation - public void paintControl(PaintEvent e) { - updateIfNecessary(); - } - - // DisposeListener implementation - public void widgetDisposed(DisposeEvent e) { - ControlUpdater.this.dispose(); - } - - // Runnable implementation. This method runs at most once per repaint whenever the - // value gets marked as dirty. - public void run() { - if (theControl != null && !theControl.isDisposed() && theControl.isVisible()) { - updateIfNecessary(); - } - } - - // IChangeListener implementation (listening to the ComputedValue) - public void handleChange(ChangeEvent event) { - // Whenever this updator becomes dirty, schedule the run() method - makeDirty(); - } - - } - - private Runnable updateRunnable = new Runnable() { - public void run() { - updateControl(); - } - }; - - private PrivateInterface privateInterface = new PrivateInterface(); - private Control theControl; - private IObservable[] dependencies = new IObservable[0]; - private boolean dirty = false; - - /** - * Creates an updater for the given control. - * - * @param toUpdate control to update - */ - public ControlUpdater(Control toUpdate) { - theControl = toUpdate; - - theControl.addDisposeListener(privateInterface); - theControl.addPaintListener(privateInterface); - makeDirty(); - } - - private void updateIfNecessary() { - if (dirty) { - dependencies = ObservableTracker.runAndMonitor(updateRunnable, privateInterface, null); - dirty = false; - } - } - - /** - * This is called automatically when the control is disposed. It may also - * be called explicitly to remove this updator from the control. Subclasses - * will normally extend this method to detach any listeners they attached - * in their constructor. - */ - public void dispose() { - theControl.removeDisposeListener(privateInterface); - theControl.removePaintListener(privateInterface); - - stopListening(); - } - - private void stopListening() { - // Stop listening for dependency changes - for (int i = 0; i < dependencies.length; i++) { - IObservable observable = dependencies[i]; - - observable.removeChangeListener(privateInterface); - } - } - - /** - * Updates the control. This method will be invoked once after the - * updator is created, and once before any repaint during which the - * control is visible and dirty. - * - * <p> - * Subclasses should overload this method to provide any code that - * changes the appearance of the widget. - * </p> - */ - protected abstract void updateControl(); - - /** - * Marks this updator as dirty. Causes the updateControl method to - * be invoked before the next time the control is repainted. - */ - protected final void makeDirty() { - if (!dirty) { - dirty = true; - stopListening(); - SWTUtil.runOnce(theControl.getDisplay(), privateInterface); - } - } - -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/MenuUpdater.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/MenuUpdater.java deleted file mode 100644 index a40060df..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/MenuUpdater.java +++ /dev/null @@ -1,166 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.provisional.swt; - -import org.eclipse.core.databinding.observable.ChangeEvent; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; -import org.eclipse.swt.events.MenuEvent; -import org.eclipse.swt.events.MenuListener; -import org.eclipse.swt.widgets.Menu; - -/** - * NON-API - A MenuUpdater updates an SWT menu in response to changes in the model. By - * wrapping a block of code in a MenuUpdater, clients can rely on the fact that - * the block of code will be re-executed whenever anything changes in the model - * that might affect its behavior. - * - * <p> - * MenuUpdaters only execute once their menus are shown. If something changes in - * the model, the updater is flagged as dirty and it stops listening to the - * model until the next time the menu is shown. If the menu is visible while the - * model changes, it will be updated right away. - * </p> - * - * <p> - * Clients should subclass this when copying information from the model to a - * menu. Typical usage: - * </p> - * - * <ul> - * <li>Override updateMenu. It should do whatever is necessary to display the - * contents of the model in the menu.</li> - * <li>In the constructor, attach listeners to the model. The listeners should - * call markDirty whenever anything changes in the model that affects - * updateMenu. Note: this step can be omitted when calling any method tagged - * with "@TrackedGetter" since MenuUpdater will automatically attach a listener - * to any object if a "@TrackedGetter" method is called in updateMenu.</li> - * <li>(optional)Extend dispose() to remove any listeners attached in the - * constructor</li> - * </ul> - * - * @since 1.1 - */ -public abstract class MenuUpdater { - - private class PrivateInterface implements MenuListener, - DisposeListener, Runnable, IChangeListener { - - // DisposeListener implementation - public void widgetDisposed(DisposeEvent e) { - MenuUpdater.this.dispose(); - } - - // Runnable implementation. This method runs at most once per repaint whenever the - // value gets marked as dirty. - public void run() { - if (theMenu != null && !theMenu.isDisposed() && theMenu.isVisible()) { - updateIfNecessary(); - } - } - - // IChangeListener implementation (listening to the ComputedValue) - public void handleChange(ChangeEvent event) { - // Whenever this updator becomes dirty, schedule the run() method - makeDirty(); - } - - public void menuHidden(MenuEvent e) { - // do nothing - } - - public void menuShown(MenuEvent e) { - updateIfNecessary(); - } - - } - - private Runnable updateRunnable = new Runnable() { - public void run() { - updateMenu(); - } - }; - - private PrivateInterface privateInterface = new PrivateInterface(); - private Menu theMenu; - private IObservable[] dependencies = new IObservable[0]; - private boolean dirty = false; - - /** - * Creates an updator for the given menu. - * - * @param toUpdate menu to update - */ - public MenuUpdater(Menu toUpdate) { - theMenu = toUpdate; - - theMenu.addDisposeListener(privateInterface); - theMenu.addMenuListener(privateInterface); - makeDirty(); - } - - private void updateIfNecessary() { - if (dirty) { - dependencies = ObservableTracker.runAndMonitor(updateRunnable, privateInterface, null); - dirty = false; - } - } - - /** - * This is called automatically when the menu is disposed. It may also - * be called explicitly to remove this updator from the menu. Subclasses - * will normally extend this method to detach any listeners they attached - * in their constructor. - */ - public void dispose() { - theMenu.removeDisposeListener(privateInterface); - theMenu.removeMenuListener(privateInterface); - - stopListening(); - } - - private void stopListening() { - // Stop listening for dependency changes - for (int i = 0; i < dependencies.length; i++) { - IObservable observable = dependencies[i]; - - observable.removeChangeListener(privateInterface); - } - } - - /** - * Updates the menu. This method will be invoked once after the - * updater is created, and once for any SWT.Show event if this - * updater is marked as dirty at that time. - * - * <p> - * Subclasses should overload this method to provide any code that - * udates the menu. - * </p> - */ - protected abstract void updateMenu(); - - /** - * Marks this updator as dirty. Causes the updateControl method to - * be invoked before the next time the control is repainted. - */ - protected final void makeDirty() { - if (!dirty) { - dirty = true; - stopListening(); - SWTUtil.runOnce(theMenu.getDisplay(), privateInterface); - } - } - -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/SWTUtil.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/SWTUtil.java deleted file mode 100644 index 541711df..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/SWTUtil.java +++ /dev/null @@ -1,185 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.provisional.swt; - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.jface.util.SafeRunnable; -import org.eclipse.swt.graphics.RGB; -import org.eclipse.swt.widgets.Display; - -/** - * NON-API - Utility methods, mainly having to do with posting runnables to the UI thread - * in a particular way. - * @since 1.1 - * - */ -public class SWTUtil { - /** - * Stores a work queue for each display - */ - private static Map mapDisplayOntoWorkQueue = new HashMap(); - - private SWTUtil() { - } - - /** - * Runs the given runnable on the given display as soon as possible. If - * possible, the runnable will be executed before the next widget is - * repainted, but this behavior is not guaranteed. Use this method to - * schedule work will affect the way one or more widgets are drawn. - * - * <p> - * This is threadsafe. - * </p> - * - * @param d - * display - * @param r - * runnable to execute in the UI thread. - */ - public static void greedyExec(Display d, Runnable r) { - if (d.isDisposed()) { - return; - } - - // if (Display.getCurrent() == d) { - // r.run(); - // } else { - WorkQueue queue = getQueueFor(d); - queue.asyncExec(r); - // } - } - - /** - * Runs the given runnable on the given display as soon as possible. Unlike - * greedyExec, this has no effect if the given runnable has already been - * scheduled for execution. Use this method to schedule work that will - * affect the way one or more wigdets are drawn, but that should only happen - * once. - * - * <p> - * This is threadsafe. - * </p> - * - * @param d - * display - * @param r - * runnable to execute in the UI thread. Has no effect if the - * given runnable has already been scheduled but has not yet run. - */ - public static void runOnce(Display d, Runnable r) { - if (d.isDisposed()) { - return; - } - WorkQueue queue = getQueueFor(d); - queue.runOnce(r); - } - - /** - * Cancels a greedyExec or runOnce that was previously scheduled on the - * given display. Has no effect if the given runnable is not in the queue - * for the given display - * - * @param d - * target display - * @param r - * runnable to execute - */ - public static void cancelExec(Display d, Runnable r) { - if (d.isDisposed()) { - return; - } - WorkQueue queue = getQueueFor(d); - queue.cancelExec(r); - } - - /** - * Returns the work queue for the given display. Creates a work queue if - * none exists yet. - * - * @param d - * display to return queue for - * @return a work queue (never null) - */ - private static WorkQueue getQueueFor(final Display d) { - WorkQueue result; - synchronized (mapDisplayOntoWorkQueue) { - // Look for existing queue - result = (WorkQueue) mapDisplayOntoWorkQueue.get(d); - - if (result == null) { - // If none, create new queue - result = new WorkQueue(d); - final WorkQueue q = result; - mapDisplayOntoWorkQueue.put(d, result); - d.asyncExec(new Runnable() { - public void run() { - d.disposeExec(new Runnable() { - public void run() { - synchronized (mapDisplayOntoWorkQueue) { - q.cancelAll(); - mapDisplayOntoWorkQueue.remove(d); - } - } - }); - } - }); - } - return result; - } - } - - /** - * @param rgb1 - * @param rgb2 - * @param ratio - * @return the RGB object - */ - public static RGB mix(RGB rgb1, RGB rgb2, double ratio) { - return new RGB(interp(rgb1.red, rgb2.red, ratio), - interp(rgb1.green, rgb2.green, ratio), - interp(rgb1.blue, rgb2.blue, ratio)); - } - - private static int interp(int i1, int i2, double ratio) { - int result = (int)(i1 * ratio + i2 * (1.0d - ratio)); - if (result < 0) result = 0; - if (result > 255) result = 255; - return result; - } - - /** - * Logs an exception as though it was thrown by a SafeRunnable being run - * with the default ISafeRunnableRunner. Will not open modal dialogs or spin - * the event loop. - * - * @param t - * throwable to log - * @deprecated - * @noreference This method is not intended to be referenced by clients. It - * remains here for API backwards compatibility. - */ - public static void logException(final Exception t) { - SafeRunnable.run(new SafeRunnable() { - public void run() throws Exception { - throw t; - } - public void handleException(Throwable e) { - // IMPORTANT: Do not call the super implementation, since - // it opens a modal dialog, and may cause *syncExecs to run - // too early. - } - }); - } - -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/TableUpdater.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/TableUpdater.java deleted file mode 100644 index 8570a3cc..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/TableUpdater.java +++ /dev/null @@ -1,222 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.provisional.swt; - -import org.eclipse.core.databinding.observable.ChangeEvent; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.list.IListChangeListener; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.ListChangeEvent; -import org.eclipse.core.databinding.observable.list.ListDiffEntry; -import org.eclipse.core.runtime.Assert; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableItem; - -/** - * NON-API - This class can be used to update a table with automatic dependency - * tracking. - * - * @since 1.1 - * - * @noextend This class is not intended to be subclassed by clients. (We do - * encourage experimentation for non-production code and are - * interested in feedback though.) - * - */ -public abstract class TableUpdater { - - private class UpdateRunnable implements Runnable, IChangeListener, - DisposeListener { - private TableItem item; - - private boolean dirty = false; - - private IObservable[] dependencies = new IObservable[0]; - - private final Object element; - - UpdateRunnable(TableItem item, Object element) { - this.item = item; - this.element = element; - item.addDisposeListener(this); - } - - // Runnable implementation. This method runs at most once per repaint - // whenever the - // value gets marked as dirty. - public void run() { - if (table != null && !table.isDisposed() && item != null - && !item.isDisposed()) { - if (table.isVisible()) { - int tableHeight = table.getClientArea().height; - int numVisibleItems = tableHeight / table.getItemHeight(); - int indexOfItem = table.indexOf(item); - int topIndex = table.getTopIndex(); - if (indexOfItem >= topIndex - && indexOfItem <= topIndex + numVisibleItems) { - updateIfNecessary(indexOfItem); - return; - } - } - table.clear(table.indexOf(item)); - } - } - - private void updateIfNecessary(final int indexOfItem) { - if (dirty) { - dependencies = ObservableTracker.runAndMonitor(new Runnable() { - public void run() { - updateItem(indexOfItem, item, element); - } - }, this, null); - dirty = false; - } - } - - // IChangeListener implementation (listening to the ComputedValue) - public void handleChange(ChangeEvent event) { - // Whenever this updator becomes dirty, schedule the run() method - makeDirty(); - } - - protected final void makeDirty() { - if (!dirty) { - dirty = true; - stopListening(); - SWTUtil.runOnce(table.getDisplay(), this); - } - } - - private void stopListening() { - // Stop listening for dependency changes - for (int i = 0; i < dependencies.length; i++) { - IObservable observable = dependencies[i]; - - observable.removeChangeListener(this); - } - } - - // DisposeListener implementation - public void widgetDisposed(DisposeEvent e) { - stopListening(); - dependencies = null; - item = null; - } - } - - private class PrivateInterface implements Listener, DisposeListener { - - // Listener implementation - public void handleEvent(Event e) { - if (e.type == SWT.SetData) { - UpdateRunnable runnable = (UpdateRunnable) e.item.getData(); - if (runnable == null) { - runnable = new UpdateRunnable((TableItem) e.item, list.get(e.index)); - e.item.setData(runnable); - runnable.makeDirty(); - } else { - runnable.updateIfNecessary(e.index); - } - } - } - - // DisposeListener implementation - public void widgetDisposed(DisposeEvent e) { - TableUpdater.this.dispose(); - } - - } - - private PrivateInterface privateInterface = new PrivateInterface(); - - private Table table; - - private IListChangeListener listChangeListener = new IListChangeListener() { - public void handleListChange(ListChangeEvent event) { - ListDiffEntry[] differences = event.diff.getDifferences(); - for (int i = 0; i < differences.length; i++) { - ListDiffEntry entry = differences[i]; - if (entry.isAddition()) { - TableItem item = new TableItem(table, SWT.NONE, entry - .getPosition()); - UpdateRunnable updateRunnable = new UpdateRunnable(item, entry.getElement()); - item.setData(updateRunnable); - updateRunnable.makeDirty(); - } else { - table.getItem(entry.getPosition()).dispose(); - } - } - } - }; - - private IObservableList list; - - /** - * Creates an updator for the given control. - * - * @param table - * table to update - * @param list - * @since 1.2 - */ - public TableUpdater(Table table, IObservableList list) { - this.table = table; - this.list = list; - Assert.isLegal((table.getStyle() & SWT.VIRTUAL) != 0, - "TableUpdater requires virtual table"); //$NON-NLS-1$ - - table.setItemCount(list.size()); - list.addListChangeListener(listChangeListener); - - table.addDisposeListener(privateInterface); - table.addListener(SWT.SetData, privateInterface); - } - - /** - * This is called automatically when the control is disposed. It may also be - * called explicitly to remove this updator from the control. Subclasses - * will normally extend this method to detach any listeners they attached in - * their constructor. - */ - public void dispose() { - table.removeDisposeListener(privateInterface); - table.removeListener(SWT.SetData, privateInterface); - list.removeListChangeListener(listChangeListener); - table = null; - list = null; - } - - /** - * Updates the control. This method will be invoked once after the updator - * is created, and once before any repaint during which the control is - * visible and dirty. - * - * <p> - * Subclasses should overload this method to provide any code that changes - * the appearance of the widget. - * </p> - * - * @param index - * @param item - * the item to update - * @param element - * @since 1.2 - */ - protected abstract void updateItem(int index, TableItem item, Object element); - -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/WorkQueue.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/WorkQueue.java deleted file mode 100644 index 9668f025..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/WorkQueue.java +++ /dev/null @@ -1,149 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.provisional.swt; - -import java.util.HashSet; -import java.util.LinkedList; -import java.util.Set; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; - -/** - * NON-API - Helper class to manage a queue of runnables to be posted to the UI thread in a way - * that they are only run once. - * @since 1.1 - * - */ -public class WorkQueue { - - private boolean updateScheduled = false; - - private boolean paintListenerAttached = false; - - private LinkedList pendingWork = new LinkedList(); - - private Display d; - - private Set pendingWorkSet = new HashSet(); - - private Runnable updateJob = new Runnable() { - public void run() { - doUpdate(); - updateScheduled = false; - } - }; - - private Listener paintListener = new Listener() { - public void handleEvent(Event event) { - paintListenerAttached = false; - d.removeFilter(SWT.Paint, this); - doUpdate(); - } - }; - - /** - * @param targetDisplay - */ - public WorkQueue(Display targetDisplay) { - d = targetDisplay; - } - - private void doUpdate() { - for (;;) { - Runnable next; - synchronized (pendingWork) { - if (pendingWork.isEmpty()) { - break; - } - next = (Runnable) pendingWork.removeFirst(); - pendingWorkSet.remove(next); - } - - next.run(); - } - } - - /** - * Schedules some work to happen in the UI thread as soon as possible. If - * possible, the work will happen before the next control redraws. The given - * runnable will only be run once. Has no effect if this runnable has - * already been queued for execution. - * - * @param work - * runnable to execute - */ - public void runOnce(Runnable work) { - synchronized (pendingWork) { - if (pendingWorkSet.contains(work)) { - return; - } - - pendingWorkSet.add(work); - - asyncExec(work); - } - } - - /** - * Schedules some work to happen in the UI thread as soon as possible. If - * possible, the work will happen before the next control redraws. Unlike - * runOnce, calling asyncExec twice with the same runnable will cause that - * runnable to run twice. - * - * @param work - * runnable to execute - */ - public void asyncExec(Runnable work) { - synchronized (pendingWork) { - pendingWork.add(work); - if (!updateScheduled) { - updateScheduled = true; - d.asyncExec(updateJob); - } - - // If we're in the UI thread, add an event filter to ensure - // the work happens ASAP - if (Display.getCurrent() == d) { - if (!paintListenerAttached) { - paintListenerAttached = true; - d.addFilter(SWT.Paint, paintListener); - } - } - } - } - - /** - * Cancels a previously-scheduled runnable. Has no effect if the given - * runnable was not previously scheduled or has already executed. - * - * @param toCancel - * runnable to cancel - */ - public void cancelExec(Runnable toCancel) { - synchronized (pendingWork) { - pendingWork.remove(toCancel); - pendingWorkSet.remove(toCancel); - } - } - - /** - * Cancels all pending work. - */ - public void cancelAll() { - synchronized (pendingWork) { - pendingWork.clear(); - pendingWorkSet.clear(); - } - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/viewers/IParentProvider.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/viewers/IParentProvider.java deleted file mode 100644 index 433cea1e..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/viewers/IParentProvider.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Stefan Xenos, IBM - initial API and implementation - * Matthew Hall - bug 207858 - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.provisional.viewers; - -/** - * NON-API - Returns the parent of elements in a tree. - * - * @since 1.1 - */ -public interface IParentProvider { - - /** - * Returns the parent of the passed in child element, or null if unknown. - * - * @param child - * the child element - * @return the parent of the passed in child element, or null if unknown. - */ - public Object getParent(Object child); -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/viewers/TreeNode.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/viewers/TreeNode.java deleted file mode 100644 index 39ce1565..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/viewers/TreeNode.java +++ /dev/null @@ -1,339 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Stefan Xenos, IBM - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.provisional.viewers; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.Observables; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.ISetChangeListener; -import org.eclipse.core.databinding.observable.set.SetChangeEvent; -import org.eclipse.core.databinding.observable.set.SetDiff; -import org.eclipse.jface.databinding.viewers.ObservableListTreeContentProvider; -import org.eclipse.jface.databinding.viewers.ObservableSetTreeContentProvider; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.swt.widgets.Control; - -/** - * - * @since 1.0 - * @deprecated Use {@link ObservableSetTreeContentProvider} or - * {@link ObservableListTreeContentProvider} instead. - */ -/* package */ class TreeNode implements ISetChangeListener, IStaleListener { - private UnorderedTreeContentProvider contentProvider; - private Object element; - - // Stores the set of parents (null if there are less than 2) - private HashSet parents = null; - - // Stores one representative parent. If there is more than one parent, - // the complete set of parents can be found in the parents set. - Object parent; - - /** - * Set of child elements. - */ - private IObservableSet children; - - private boolean hasPendingNode = false; - private boolean isStale; - private boolean listeningToChildren = false; - private boolean prefetchEnqueued = false; - - /** - * @param element - * @param cp - */ - public TreeNode(Object element, UnorderedTreeContentProvider cp) { - this.element = element; - this.contentProvider = cp; - children = contentProvider.createChildSet(element); - if (children == null) { - children = Observables.emptyObservableSet(); - listeningToChildren = true; - } - hasPendingNode = children.isStale(); - } - - /** - * @param parent - */ - public void addParent(Object parent) { - if (this.parent == null) { - this.parent = parent; - } else { - if (parent.equals(this.parent)) { - return; - } - if (parents == null) { - parents = new HashSet(); - parents.add(this.parent); - } - parents.add(parent); - } - } - - /** - * @param parent - */ - public void removeParent(Object parent) { - if (this.parents != null) { - parents.remove(parent); - } - - if (parent == this.parent) { - if (parents == null || parents.isEmpty()) { - this.parent = null; - } else { - this.parent = parents.iterator().next(); - } - } - - if (this.parents != null && this.parents.size() <= 1) { - this.parents = null; - } - } - - /** - * Returns the set of children for this node. If new children are discovered later, they - * will be added directly to the viewer. - * - * @return TODO - */ - public Set getChildren() { - if (!listeningToChildren) { - listeningToChildren = true; - children.addSetChangeListener(this); - hasPendingNode = children.isEmpty() && children.isStale(); - children.addStaleListener(this); - updateStale(); - } - - // If the child set is stale and empty, show the "pending" node - if (hasPendingNode) { - Object pendingNode = contentProvider.getPendingNode(); - return Collections.singleton(pendingNode); - } - return children; - } - - /** - * @return TODO - */ - public IObservableSet getChildrenSet() { - return children; - } - - private void updateStale() { - boolean willBeStale = children.isStale(); - if (willBeStale != isStale) { - isStale = willBeStale; - - contentProvider.changeStale(isStale? 1 : -1); - } - } - - /** - * @return TODO - */ - public boolean isStale() { - return isStale; - } - - /** - * Returns true if the viewer should show a plus sign for expanding this - * node. - * - * @return TODO - */ - public boolean shouldShowPlus() { - if (children == null) { -// if (!hasPendingNode) { -// hasPendingNode = true; -// contentProvider.add(element, Collections.singleton(contentProvider.getPendingNode())); -// } - return true; - } - if (!listeningToChildren && !prefetchEnqueued) { - prefetchEnqueued = true; - contentProvider.enqueuePrefetch(this); - } - return !listeningToChildren || hasPendingNode || !children.isEmpty(); - } - - /** - * Disposes this node and removes all remaining children. - */ - public void dispose() { - if (children != null) { - if (listeningToChildren) { - contentProvider.remove(element, children, true); - children.removeSetChangeListener(this); - children.removeStaleListener(this); - } - children.dispose(); - children = null; - - if (listeningToChildren && isStale) { - contentProvider.changeStale(-1); - } - } - } - - /** - * @return TODO - */ - public boolean isDisposed() { - return children == null; - } - - /** - * Returns one representative parent, or null if this node is unparented. Use - * getParents() to get the complete set of known parents. - * - * @return TODO - */ - public Object getParent() { - return parent; - } - - /** - * - * @return the set of all known parents for this node - */ - public Set getParents() { - if (parents == null) { - if (parent == null) { - return Collections.EMPTY_SET; - } - return Collections.singleton(parent); - } - return parents; - } - - /** - * Called when the child set changes. Should not be called directly by the viewer. - */ - public void handleSetChange(SetChangeEvent event) { - SetDiff diff = event.diff; - TreeViewer viewer = this.contentProvider.getViewer(); - if (viewer != null) { - Control control = viewer.getControl(); - if (control != null) { - if (control.isDisposed()) { - // If the widgetry was disposed without notifying the content provider, then - // dispose the content provider now and stop processing events. - contentProvider.dispose(); - return; - } - } - } - - boolean shouldHavePendingNode = children.isEmpty() && children.isStale(); - - Set additions = diff.getAdditions(); - // Check if we should add the pending node - if (shouldHavePendingNode && !hasPendingNode) { - HashSet newAdditions = new HashSet(); - newAdditions.addAll(additions); - newAdditions.add(contentProvider.getPendingNode()); - additions = newAdditions; - hasPendingNode = true; - } - - Set removals = diff.getRemovals(); - // Check if we should remove the pending node - if (!shouldHavePendingNode && hasPendingNode) { - HashSet newRemovals = new HashSet(); - newRemovals.addAll(removals); - newRemovals.add(contentProvider.getPendingNode()); - removals = newRemovals; - hasPendingNode = false; - } - if (!additions.isEmpty()) { - contentProvider.add(element, additions); - } - if (!removals.isEmpty()) { - contentProvider.remove(element, removals, children.isEmpty() && !hasPendingNode); - } - - updateStale(); - } - - public void handleStale(StaleEvent staleEvent) { - TreeViewer viewer = this.contentProvider.getViewer(); - if (viewer != null) { - Control control = viewer.getControl(); - if (control != null) { - if (control.isDisposed()) { - // If the widgetry was disposed without notifying the content provider, then - // dispose the content provider now and stop processing events. - contentProvider.dispose(); - return; - } - } - } - - boolean shouldHavePendingNode = children.isEmpty() && children.isStale(); - - // Check if we should add the pending node - if (shouldHavePendingNode && !hasPendingNode) { - hasPendingNode = shouldHavePendingNode; - contentProvider.add(element, Collections.singleton(contentProvider.getPendingNode())); - } - - // Check if we should remove the pending node - if (!shouldHavePendingNode && hasPendingNode) { - hasPendingNode = shouldHavePendingNode; - contentProvider.remove(element, Collections.singleton(contentProvider.getPendingNode()), true); - } - - updateStale(); - } - - /** - * @return TODO - */ - public Object getElement() { - return element; - } - - /** - * - */ - public void prefetch() { - TreeViewer viewer = this.contentProvider.getViewer(); - if (viewer != null) { - Control control = viewer.getControl(); - if (control != null) { - if (control.isDisposed()) { - // If the widgetry has been disposed, then avoid sending anything - // to the viewer. - return; - } - } - } - - Set children = getChildren(); - if (!children.isEmpty()) { - contentProvider.add(element, children); - } else { - // We need to remove the + sign, and adding/removing elements won't do the trick - contentProvider.getViewer().refresh(element); - } - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/viewers/UnorderedTreeContentProvider.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/viewers/UnorderedTreeContentProvider.java deleted file mode 100644 index 627b60b1..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/viewers/UnorderedTreeContentProvider.java +++ /dev/null @@ -1,531 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Stefan Xenos, IBM - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.provisional.viewers; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.set.AbstractObservableSet; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.SetDiff; -import org.eclipse.core.internal.databinding.observable.tree.IUnorderedTreeProvider; -import org.eclipse.jface.databinding.viewers.ObservableListTreeContentProvider; -import org.eclipse.jface.databinding.viewers.ObservableSetTreeContentProvider; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.ITreePathContentProvider; -import org.eclipse.jface.viewers.ITreeViewerListener; -import org.eclipse.jface.viewers.TreeExpansionEvent; -import org.eclipse.jface.viewers.TreePath; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.jface.viewers.Viewer; - -/** - * NON-API - Generic tree content provider to be used with an AbstractTreeViewer based on a IUnorderedTreeProvider. - * @since 1.1 - * @deprecated Use {@link ObservableSetTreeContentProvider} or - * {@link ObservableListTreeContentProvider} instead. - */ -public class UnorderedTreeContentProvider implements ITreeContentProvider, ITreePathContentProvider { - - private HashMap mapElementToTreeNode = new HashMap(); - private LinkedList enqueuedPrefetches = new LinkedList(); - private IParentProvider rootParentProvider = null; - private boolean useTreePaths = false; - - class KnownElementsSet extends AbstractObservableSet { - - protected KnownElementsSet() { - super(); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.internal.databinding.provisional.observable.set.AbstractObservableSet#getWrappedSet() - */ - protected Set getWrappedSet() { - return mapElementToTreeNode.keySet(); - } - - void doFireDiff(Set added, Set removed) { - fireSetChange(Diffs.createSetDiff(added, removed)); - } - - public void fireSetChange(SetDiff diff) { - super.fireSetChange(diff); - } - - void doFireStale(boolean isStale) { - if (isStale) { - fireStale(); - } else { - fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, Collections.EMPTY_SET)); - } - } - - /* (non-Javadoc) - * @see org.eclipse.jface.internal.databinding.provisional.observable.set.IObservableSet#getElementType() - */ - public Object getElementType() { - return new Object(); - } - } - - KnownElementsSet elements = new KnownElementsSet(); - - private ITreeViewerListener expandListener = new ITreeViewerListener() { - public void treeCollapsed(TreeExpansionEvent event) { - } - - public void treeExpanded(TreeExpansionEvent event) { - } - }; - - private IUnorderedTreeProvider provider; - private Object pendingNode; - - private int avoidViewerUpdates; - - private TreeViewer treeViewer; - - private int staleCount = 0; - private boolean useRefresh; - private int maxPrefetches = 0; - - /** - * Constructs a content provider that will render the given tree in a TreeViewer. - * - * @param provider IObservableTree that provides the contents of the tree - * @param pendingNode element to insert whenever a node is being fetched in the background - * @param useRefresh true = notify the viewer of changes by calling refresh(...), false = - * notify the viewer of changes by calling add(...) and remove(...). Using false - * is more efficient, but may not work with TreeViewer subclasses. - */ - public UnorderedTreeContentProvider(IUnorderedTreeProvider provider, - Object pendingNode, boolean useRefresh) { - this.provider = provider; - this.pendingNode = pendingNode; - this.useRefresh = useRefresh; - } - - /** - * Sets whether this content provider should add/remove elements using - * TreePaths (true) or elements (false). - * - * <p></p> - * <p>When using elements:</p> - * - * <ul> - * <li>Cycles are permitted (elements can be their own ancestor)</li> - * <li>Addition, removal, and refresh are slightly faster</li> - * <li>It is not possible to have more than one content provider per tree</li> - * <li>The setRootPath(...) method is ignored</li> - * </ul> - * - * <p></p> - * <p>When using TreePaths:</p> - * - * <ul> - * <li>Cycles are not permitted (elements cannot be their own parent)</li> - * <li>Addition, removal, and refresh are slightly slower</li> - * <li>It is possible to use more than one content provider in the same tree</li> - * <li>The setRootPath(...) method can be used to direct the output to a particular - * subtree</li> - * </ul> - * - * @param usePaths - */ - public void useTreePaths(boolean usePaths) { - this.useTreePaths = usePaths; - } - - /** - * @param rootParentProvider - */ - public void setRootPath(IParentProvider rootParentProvider) { - this.rootParentProvider = rootParentProvider; - } - - /** - * @param maxPrefetches - */ - public void setMaxPrefetches(int maxPrefetches) { - this.maxPrefetches = maxPrefetches; - } - - /* package */ IObservableSet createChildSet(Object element) { - return provider.createChildSet(element); - } - - /* package */ void remove(Object element, Set removals, boolean lastElement) { - if (removals.isEmpty()) { - return; - } - if (avoidViewerUpdates == 0) { - if (lastElement || useRefresh) { - doRefresh(element); - } else { - if (useTreePaths) { - List toRemove = new ArrayList(); - TreePath[] parents = getParents(element); - for (int i = 0; i < parents.length; i++) { - TreePath parent = parents[i]; - - for (Iterator iter = removals.iterator(); iter.hasNext();) { - Object elementToRemove = iter.next(); - - toRemove.add(parent.createChildPath(element).createChildPath(elementToRemove)); - } - } - - treeViewer.remove(toRemove.toArray(new TreePath[toRemove.size()])); - } else { - treeViewer.remove(element, removals.toArray()); - } - } - for (Iterator iter = removals.iterator(); iter.hasNext();) { - Object next = iter.next(); - - TreeNode nextNode = (TreeNode)mapElementToTreeNode.get(next); - if (nextNode != null) { - nextNode.removeParent(element); - removeIfUnused(nextNode); - } - } - } - } - - /* package */ void add(Object element, Set additions) { - if (additions.isEmpty()) { - return; - } - if (avoidViewerUpdates == 0) { - // Handle new parents - addParent(element, additions); - if (useRefresh) { - doRefresh(element); - } else { - if (useTreePaths) { - TreePath[] parents = getParents(element); - for (int i = 0; i < parents.length; i++) { - TreePath parent = parents[i]; - - treeViewer.add(parent.createChildPath(element), additions.toArray()); - } - } else { - treeViewer.add(element, additions.toArray()); - } - } - } - } - - private void doRefresh(Object element) { - treeViewer.refresh(element); - } - - /** - * Ensures that the given set of children have the given parent as - * one of their parents. - * - * @param parent - * @param children - */ - private void addParent(Object parent, Set children) { - for (Iterator iter = children.iterator(); iter.hasNext();) { - Object next = iter.next(); - - TreeNode nextNode = getNode(next); - nextNode.addParent(parent); - } - } - - /** - * @return saouesnth - */ - public final Object getPendingNode() { - return pendingNode; - } - - /** - * @param parent - * @return aueosnht - */ - public IObservableSet getChildrenSet(Object parent) { - IObservableSet result = getNode(parent).getChildrenSet(); - - return result; - } - - public void dispose() { - if (treeViewer != null) { - try { - avoidViewerUpdates++; - enqueuedPrefetches.clear(); - Object[] keys = mapElementToTreeNode.keySet().toArray(); - - for (int i = 0; i < keys.length; i++) { - Object key = keys[i]; - - TreeNode result = (TreeNode)mapElementToTreeNode.get(key); - if (result != null) { - result.dispose(); - } - } - setViewer(null); - } finally { - avoidViewerUpdates--; - } - } - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - // This should only ever be called for a single viewer - setViewer(viewer); - - if (oldInput != null && newInput != null && oldInput.equals(newInput)) { - return; - } - - try { - avoidViewerUpdates++; - TreeNode oldNode = (TreeNode)mapElementToTreeNode.get(oldInput); - if (oldNode != null) { - removeIfUnused(oldNode); - } - } finally { - avoidViewerUpdates--; - } - } - - private void removeIfUnused(TreeNode toRemove) { - //TreeNode result = (TreeNode)mapElementToTreeNode.get(element); - Object element = toRemove.getElement(); - if (toRemove.getParent() == null) { - mapElementToTreeNode.remove(element); - elements.doFireDiff(Collections.EMPTY_SET, Collections.singleton(element)); - toRemove.dispose(); - } - } - - private void setViewer(Viewer viewer) { - if (viewer != null && !(viewer instanceof TreeViewer)) { - throw new IllegalArgumentException("This content provider can only be used with TreeViewers"); //$NON-NLS-1$ - } - TreeViewer newTreeViewer = (TreeViewer) viewer; - - if (newTreeViewer != treeViewer) { - if (treeViewer != null) { - treeViewer.removeTreeListener(expandListener); - } - - this.treeViewer = newTreeViewer; - if (newTreeViewer != null) { - newTreeViewer.addTreeListener(expandListener); - } - } - } - - public Object[] getChildren(Object parentElement) { - Set result = getNode(parentElement).getChildren(); - - addParent(parentElement, result); - - return result.toArray(); - } - - private TreeNode getNode(Object parentElement) { - TreeNode result = (TreeNode)mapElementToTreeNode.get(parentElement); - if (result == null) { - result = new TreeNode(parentElement, this); - mapElementToTreeNode.put(parentElement, result); - elements.fireSetChange(Diffs.createSetDiff(Collections.singleton(parentElement), - Collections.EMPTY_SET)); - } - return result; - } - - public Object getParent(Object element) { - Object result = getNode(element).getParent(); - if (result == null && rootParentProvider != null) { - result = rootParentProvider.getParent(element); - } - return result; - } - - public boolean hasChildren(Object element) { - return getNode(element).shouldShowPlus(); - } - - public Object[] getElements(Object inputElement) { - return getChildren(inputElement); - } - - /** - * @return aouesnth - */ - public IObservableSet getKnownElements() { - return elements; - } - - /* package */ void changeStale(int staleDelta) { - staleCount += staleDelta; - processPrefetches(); - elements.setStale(staleCount != 0); - } - - /** - * @return aoueesnth - */ - public TreeViewer getViewer() { - return treeViewer; - } - - /** - * @param element - * @return aoeusnth - */ - public boolean isDirty(Object element) { - return false; - } - - /* package */ void enqueuePrefetch(TreeNode node) { - if (maxPrefetches > 0 || maxPrefetches == -1) { - if (staleCount == 0) { - // Call node.getChildren()... this will cause us to start listening to the - // node and will trigger prefetching. Don't call prefetch since this method - // is intended to be called inside getters (which will simply return the - // fetched nodes) and prefetch() is intended to be called inside an asyncExec, - // which will notify the viewer directly of the newly discovered nodes. - node.getChildren(); - } else { - enqueuedPrefetches.add(node); - while (maxPrefetches >= 0 && enqueuedPrefetches.size() > maxPrefetches) { - enqueuedPrefetches.removeFirst(); - } - } - } - } - - private void processPrefetches() { - while (staleCount == 0 && !enqueuedPrefetches.isEmpty()) { - TreeNode next = (TreeNode)enqueuedPrefetches.removeLast(); - - // Note that we don't remove nodes from the prefetch queue when they are disposed, - // so we may encounter disposed nodes at this time. - if (!next.isDisposed()) { - next.prefetch(); - } - } - } - - public Object[] getChildren(TreePath parentPath) { - return getChildren(parentPath.getLastSegment()); - } - - public TreePath[] getParents(Object element) { - // Compute all paths that do not contain cycles - /** - * List of Lists - */ - List parentPaths = computeParents(element, new HashSet()); - - /** - * List of TreePath - */ - List result = new ArrayList(); - - for (Iterator iterator = parentPaths.iterator(); iterator.hasNext();) { - List nextPath = (List) iterator.next(); - - LinkedList resultPath = new LinkedList(); - resultPath.addAll(nextPath); - Object nextParent = resultPath.isEmpty() ? element : resultPath.getFirst(); - for(;nextParent != null;) { - if (rootParentProvider != null) { - nextParent = rootParentProvider.getParent(nextParent); - if (nextParent != null) { - resultPath.addFirst(nextParent); - } - } else { - nextParent = null; - } - } - - result.add(new TreePath(resultPath.toArray())); - } - - if (result.isEmpty() && rootParentProvider != null) { - Object nextParent = rootParentProvider.getParent(element); - if (nextParent != null) { - LinkedList resultPath = new LinkedList(); - while (nextParent != null) { - resultPath.addFirst(nextParent); - nextParent = rootParentProvider.getParent(nextParent); - } - - result.add(new TreePath(resultPath.toArray())); - } - - } - - return (TreePath[]) result.toArray(new TreePath[result.size()]); - } - - /** - * - * @param node - * @param toIgnore - * @return a list of Lists, indicating all known paths to the given node - */ - private List computeParents(Object node, HashSet toIgnore) { - List result = new ArrayList(); - boolean containedNode = toIgnore.add(node); - - TreeNode tn = getNode(node); - - HashSet parents = new HashSet(); - parents.addAll(tn.getParents()); - parents.removeAll(toIgnore); - if (parents.isEmpty()) { - ArrayList newPath = new ArrayList(); - result.add(newPath); - } else { - for (Iterator iterator = parents.iterator(); iterator.hasNext();) { - Object parent = iterator.next(); - - List parentPaths = computeParents(parent, toIgnore); - - for (Iterator iterator2 = parentPaths.iterator(); iterator2 - .hasNext();) { - List parentPath = (List) iterator2.next(); - - parentPath.add(parent); - result.add(parentPath); - } - } - } - - if (containedNode) { - toIgnore.remove(node); - } - return result; - } - - public boolean hasChildren(TreePath path) { - return hasChildren(path.getLastSegment()); - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/viewers/ViewerLabelProvider.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/viewers/ViewerLabelProvider.java deleted file mode 100644 index bfc1a563..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/viewers/ViewerLabelProvider.java +++ /dev/null @@ -1,91 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 223123 - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.provisional.viewers; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.eclipse.core.databinding.util.Policy; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ILabelProviderListener; -import org.eclipse.jface.viewers.IViewerLabelProvider; -import org.eclipse.jface.viewers.LabelProviderChangedEvent; -import org.eclipse.jface.viewers.ViewerLabel; -import org.eclipse.swt.graphics.Image; - -/** - * NON-API - Generic viewer label provider. - * @since 1.1 - * - */ -public class ViewerLabelProvider implements IViewerLabelProvider, - ILabelProvider { - - private List listeners = new ArrayList(); - - /** - * Subclasses should override this method. They should not call the base - * class implementation. - */ - public void updateLabel(ViewerLabel label, Object element) { - label.setText(element.toString()); - } - - protected final void fireChangeEvent(Collection changes) { - final LabelProviderChangedEvent event = new LabelProviderChangedEvent( - this, changes.toArray()); - ILabelProviderListener[] listenerArray = (ILabelProviderListener[]) listeners - .toArray(new ILabelProviderListener[listeners.size()]); - for (int i = 0; i < listenerArray.length; i++) { - ILabelProviderListener listener = listenerArray[i]; - try { - listener.labelProviderChanged(event); - } catch (Exception e) { - Policy.getLog().log( - new Status(IStatus.ERROR, Policy.JFACE_DATABINDING, e - .getLocalizedMessage(), e)); - } - } - } - - public final Image getImage(Object element) { - ViewerLabel label = new ViewerLabel("", null); //$NON-NLS-1$ - updateLabel(label, element); - return label.getImage(); - } - - public final String getText(Object element) { - ViewerLabel label = new ViewerLabel("", null); //$NON-NLS-1$ - updateLabel(label, element); - return label.getText(); - } - - public void addListener(ILabelProviderListener listener) { - listeners.add(listener); - } - - public void dispose() { - listeners.clear(); - } - - public final boolean isLabelProperty(Object element, String property) { - return true; - } - - public void removeListener(ILabelProviderListener listener) { - listeners.remove(listener); - } - -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ButtonObservableValue.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ButtonObservableValue.java deleted file mode 100644 index 5b2d789a..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ButtonObservableValue.java +++ /dev/null @@ -1,109 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - * Ashley Cambrell - bug 198904 - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.swt; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; - -/** - * @since 1.0 - * - */ -public class ButtonObservableValue extends AbstractSWTObservableValue { - - private final Button button; - - private boolean selectionValue; - - private Listener updateListener = new Listener() { - public void handleEvent(Event event) { - boolean oldSelectionValue = selectionValue; - selectionValue = button.getSelection(); - - notifyIfChanged(oldSelectionValue, selectionValue); - } - }; - - /** - * @param button - */ - public ButtonObservableValue(Button button) { - super(button); - this.button = button; - init(); - } - - /** - * @param realm - * @param button - */ - public ButtonObservableValue(Realm realm, Button button) { - super(realm, button); - this.button = button; - init(); - } - - private void init() { - button.addListener(SWT.Selection, updateListener); - button.addListener(SWT.DefaultSelection, updateListener); - } - - public void doSetValue(final Object value) { - boolean oldSelectionValue = selectionValue; - selectionValue = value == null ? false : ((Boolean) value) - .booleanValue(); - - button.setSelection(selectionValue); - notifyIfChanged(oldSelectionValue, selectionValue); - } - - public Object doGetValue() { - return button.getSelection() ? Boolean.TRUE : Boolean.FALSE; - } - - public Object getValueType() { - return Boolean.TYPE; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose() - */ - public synchronized void dispose() { - super.dispose(); - - if (!button.isDisposed()) { - button.removeListener(SWT.Selection, updateListener); - button.removeListener(SWT.DefaultSelection, updateListener); - } - } - - /** - * Notifies consumers with a value change event only if a change occurred. - * - * @param oldValue - * @param newValue - */ - private void notifyIfChanged(boolean oldValue, boolean newValue) { - if (oldValue != newValue) { - fireValueChange(Diffs.createValueDiff(oldValue ? Boolean.TRUE : Boolean.FALSE, - newValue ? Boolean.TRUE : Boolean.FALSE)); - } - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/CComboObservableList.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/CComboObservableList.java deleted file mode 100644 index b38baea7..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/CComboObservableList.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.swt; - -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.swt.custom.CCombo; - -/** - * @since 3.2 - * - */ -public class CComboObservableList extends SWTObservableList { - - private final CCombo ccombo; - - /** - * @param ccombo - */ - public CComboObservableList(CCombo ccombo) { - super(SWTObservables.getRealm(ccombo.getDisplay())); - this.ccombo = ccombo; - } - - protected int getItemCount() { - return ccombo.getItemCount(); - } - - protected void setItems(String[] newItems) { - ccombo.setItems(newItems); - } - - protected String[] getItems() { - return ccombo.getItems(); - } - - protected String getItem(int index) { - return ccombo.getItem(index); - } - - protected void setItem(int index, String string) { - ccombo.setItem(index, string); - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/CComboObservableValue.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/CComboObservableValue.java deleted file mode 100644 index 7edd1327..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/CComboObservableValue.java +++ /dev/null @@ -1,166 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - * Ashley Cambrell - bug 198904 - * Matthew Hall - bug 118516 - * Eric Rizzo - bug 134884 - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.swt; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; - -/** - * @since 3.2 - * - */ -public class CComboObservableValue extends AbstractSWTObservableValue { - - /** - * - */ - - private final CCombo ccombo; - - private final String attribute; - - private boolean updating = false; - - private String currentValue; - - private ModifyListener modifyListener; - - /** - * @param ccombo - * @param attribute - */ - public CComboObservableValue(CCombo ccombo, String attribute) { - super(ccombo); - this.ccombo = ccombo; - this.attribute = attribute; - init(); - } - - /** - * @param realm - * @param ccombo - * @param attribute - */ - public CComboObservableValue(Realm realm, CCombo ccombo, String attribute) { - super(realm, ccombo); - this.ccombo = ccombo; - this.attribute = attribute; - init(); - } - - private void init() { - if (attribute.equals(SWTProperties.SELECTION) - || attribute.equals(SWTProperties.TEXT)) { - this.currentValue = ccombo.getText(); - modifyListener = new ModifyListener() { - - public void modifyText(ModifyEvent e) { - if (!updating) { - String oldValue = currentValue; - currentValue = CComboObservableValue.this.ccombo - .getText(); - - notifyIfChanged(oldValue, currentValue); - } - } - }; - ccombo.addModifyListener(modifyListener); - } else - throw new IllegalArgumentException(); - } - - public void doSetValue(final Object value) { - String oldValue = ccombo.getText(); - try { - updating = true; - if (attribute.equals(SWTProperties.TEXT)) { - String stringValue = value != null ? value.toString() : ""; //$NON-NLS-1$ - ccombo.setText(stringValue); - } else if (attribute.equals(SWTProperties.SELECTION)) { - String items[] = ccombo.getItems(); - int index = -1; - if (value == null) { - ccombo.select(-1); - } else if (items != null) { - for (int i = 0; i < items.length; i++) { - if (value.equals(items[i])) { - index = i; - break; - } - } - if (index == -1) { - ccombo.setText((String) value); - } else { - ccombo.select(index); // -1 will not "unselect" - } - } - } - } finally { - updating = false; - currentValue = ccombo.getText(); - } - - notifyIfChanged(oldValue, currentValue); - } - - public Object doGetValue() { - if (attribute.equals(SWTProperties.TEXT)) - return ccombo.getText(); - - Assert.isTrue(attribute.equals(SWTProperties.SELECTION), - "unexpected attribute: " + attribute); //$NON-NLS-1$ - // The problem with a ccombo, is that it changes the text and - // fires before it update its selection index - return ccombo.getText(); - } - - public Object getValueType() { - Assert.isTrue(attribute.equals(SWTProperties.TEXT) - || attribute.equals(SWTProperties.SELECTION), - "unexpected attribute: " + attribute); //$NON-NLS-1$ - return String.class; - } - - /** - * @return attribute being observed - */ - public String getAttribute() { - return attribute; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose() - */ - public synchronized void dispose() { - super.dispose(); - - if (modifyListener != null && !ccombo.isDisposed()) { - ccombo.removeModifyListener(modifyListener); - } - } - - private void notifyIfChanged(String oldValue, String newValue) { - if (!oldValue.equals(newValue)) { - fireValueChange(Diffs.createValueDiff(oldValue, ccombo.getText())); - } - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/CComboSingleSelectionObservableValue.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/CComboSingleSelectionObservableValue.java deleted file mode 100644 index d10ad421..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/CComboSingleSelectionObservableValue.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - * Ashley Cambrell - bug 198904 - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.swt; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; - -/** - * @since 1.0 - * - */ -public class CComboSingleSelectionObservableValue extends - SingleSelectionObservableValue { - - private SelectionListener selectionListener; - - /** - * @param combo - */ - public CComboSingleSelectionObservableValue(CCombo combo) { - super(combo); - } - - /** - * @param realm - * @param combo - */ - public CComboSingleSelectionObservableValue(Realm realm, CCombo combo) { - super(realm, combo); - } - - private CCombo getCCombo() { - return (CCombo) getWidget(); - } - - protected void doAddSelectionListener(final Runnable runnable) { - selectionListener = new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - runnable.run(); - } - - public void widgetSelected(SelectionEvent e) { - runnable.run(); - } - }; - getCCombo().addSelectionListener(selectionListener); - } - - protected int doGetSelectionIndex() { - return getCCombo().getSelectionIndex(); - } - - protected void doSetSelectionIndex(int index) { - getCCombo().setText(getCCombo().getItem(index)); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose() - */ - public synchronized void dispose() { - super.dispose(); - if (selectionListener != null && !getCCombo().isDisposed()) { - getCCombo().removeSelectionListener(selectionListener); - } - - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/CLabelObservableValue.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/CLabelObservableValue.java deleted file mode 100644 index 106e07ae..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/CLabelObservableValue.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.swt; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue; -import org.eclipse.swt.custom.CLabel; - -/** - * @since 1.0 - * - */ -public class CLabelObservableValue extends AbstractSWTObservableValue { - - private final CLabel label; - - /** - * @param label - */ - public CLabelObservableValue(CLabel label) { - super(label); - this.label = label; - } - - /** - * @param realm - * @param label - */ - public CLabelObservableValue(Realm realm, CLabel label) { - super(realm, label); - this.label = label; - } - - public void doSetValue(final Object value) { - String oldValue = label.getText(); - String newValue = value == null ? "" : value.toString(); //$NON-NLS-1$ - label.setText(newValue); - - if (!newValue.equals(oldValue)) { - fireValueChange(Diffs.createValueDiff(oldValue, newValue)); - } - } - - public Object doGetValue() { - return label.getText(); - } - - public Object getValueType() { - return String.class; - } - -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ComboObservableList.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ComboObservableList.java deleted file mode 100644 index 8bccc48a..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ComboObservableList.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.swt; - -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.swt.widgets.Combo; - -/** - * @since 3.2 - * - */ -public class ComboObservableList extends SWTObservableList { - - private final Combo combo; - - /** - * @param combo - */ - public ComboObservableList(Combo combo) { - super(SWTObservables.getRealm(combo.getDisplay())); - this.combo = combo; - } - - protected int getItemCount() { - return combo.getItemCount(); - } - - protected void setItems(String[] newItems) { - combo.setItems(newItems); - } - - protected String[] getItems() { - return combo.getItems(); - } - - protected String getItem(int index) { - return combo.getItem(index); - } - - protected void setItem(int index, String string) { - combo.setItem(index, string); - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ComboObservableValue.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ComboObservableValue.java deleted file mode 100644 index 885501bd..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ComboObservableValue.java +++ /dev/null @@ -1,155 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - * Ashley Cambrell - bug 198904 - * Matthew Hall - bug 118516 - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.swt; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.widgets.Combo; - -/** - * @since 3.2 - * - */ -public class ComboObservableValue extends AbstractSWTObservableValue { - - private final Combo combo; - private final String attribute; - private boolean updating = false; - private String currentValue; - private ModifyListener modifyListener; - - /** - * @param combo - * @param attribute - */ - public ComboObservableValue(Combo combo, String attribute) { - super(combo); - this.combo = combo; - this.attribute = attribute; - init(); - } - - /** - * @param realm - * @param combo - * @param attribute - */ - public ComboObservableValue(Realm realm, Combo combo, String attribute) { - super(realm, combo); - this.combo = combo; - this.attribute = attribute; - init(); - } - - private void init() { - if (attribute.equals(SWTProperties.SELECTION) - || attribute.equals(SWTProperties.TEXT)) { - this.currentValue = combo.getText(); - modifyListener = new ModifyListener() { - - public void modifyText(ModifyEvent e) { - if (!updating) { - String oldValue = currentValue; - currentValue = ComboObservableValue.this.combo - .getText(); - - notifyIfChanged(oldValue, currentValue); - } - } - }; - combo.addModifyListener(modifyListener); - } else - throw new IllegalArgumentException(); - } - - public void doSetValue(final Object value) { - String oldValue = combo.getText(); - try { - updating = true; - if (attribute.equals(SWTProperties.TEXT)) { - String stringValue = value != null ? value.toString() : ""; //$NON-NLS-1$ - combo.setText(stringValue); - } else if (attribute.equals(SWTProperties.SELECTION)) { - String items[] = combo.getItems(); - int index = -1; - if (items != null && value != null) { - for (int i = 0; i < items.length; i++) { - if (value.equals(items[i])) { - index = i; - break; - } - } - if (index == -1) { - combo.setText((String) value); - } else { - combo.select(index); // -1 will not "unselect" - } - } - } - } finally { - updating = false; - currentValue = combo.getText(); - } - - notifyIfChanged(oldValue, currentValue); - } - - public Object doGetValue() { - if (attribute.equals(SWTProperties.TEXT)) - return combo.getText(); - - Assert.isTrue(attribute.equals(SWTProperties.SELECTION), - "unexpected attribute: " + attribute); //$NON-NLS-1$ - // The problem with a ccombo, is that it changes the text and - // fires before it update its selection index - return combo.getText(); - } - - public Object getValueType() { - Assert.isTrue(attribute.equals(SWTProperties.TEXT) - || attribute.equals(SWTProperties.SELECTION), - "unexpected attribute: " + attribute); //$NON-NLS-1$ - return String.class; - } - - /** - * @return attribute being observed - */ - public String getAttribute() { - return attribute; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose() - */ - public synchronized void dispose() { - super.dispose(); - - if (modifyListener != null && !combo.isDisposed()) { - combo.removeModifyListener(modifyListener); - } - } - - private void notifyIfChanged(String oldValue, String newValue) { - if (!oldValue.equals(newValue)) { - fireValueChange(Diffs.createValueDiff(oldValue, newValue)); - } - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ComboSingleSelectionObservableValue.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ComboSingleSelectionObservableValue.java deleted file mode 100644 index 922bfc2e..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ComboSingleSelectionObservableValue.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - * Ashley Cambrell - bugs 198903, 198904 - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.swt; - -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.widgets.Combo; - -/** - * @since 1.0 - * - */ -public class ComboSingleSelectionObservableValue extends - SingleSelectionObservableValue { - - private SelectionListener selectionListener; - - /** - * @param combo - */ - public ComboSingleSelectionObservableValue(Combo combo) { - super(combo); - } - - private Combo getCombo() { - return (Combo) getWidget(); - } - - protected void doAddSelectionListener(final Runnable runnable) { - selectionListener = new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - runnable.run(); - } - - public void widgetSelected(SelectionEvent e) { - runnable.run(); - } - }; - getCombo().addSelectionListener(selectionListener); - } - - protected int doGetSelectionIndex() { - return getCombo().getSelectionIndex(); - } - - protected void doSetSelectionIndex(int index) { - getCombo().select(index); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose() - */ - public synchronized void dispose() { - super.dispose(); - if (selectionListener != null && !getCombo().isDisposed()) { - getCombo().removeSelectionListener(selectionListener); - } - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ControlObservableValue.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ControlObservableValue.java deleted file mode 100644 index 11d6d4bc..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ControlObservableValue.java +++ /dev/null @@ -1,106 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - * Matt Carter - bug 170668 - * Brad Reynolds - bug 170848 - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.swt; - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.widgets.Control; - -/** - * @since 1.0 - * - */ -public class ControlObservableValue extends AbstractSWTObservableValue { - - private final Control control; - - private final String attribute; - - private Object valueType; - - private static final Map SUPPORTED_ATTRIBUTES = new HashMap(); - static { - SUPPORTED_ATTRIBUTES.put(SWTProperties.ENABLED, Boolean.TYPE); - SUPPORTED_ATTRIBUTES.put(SWTProperties.VISIBLE, Boolean.TYPE); - SUPPORTED_ATTRIBUTES.put(SWTProperties.TOOLTIP_TEXT, String.class); - SUPPORTED_ATTRIBUTES.put(SWTProperties.FOREGROUND, Color.class); - SUPPORTED_ATTRIBUTES.put(SWTProperties.BACKGROUND, Color.class); - SUPPORTED_ATTRIBUTES.put(SWTProperties.FONT, Font.class); - } - - /** - * @param control - * @param attribute - */ - public ControlObservableValue(Control control, String attribute) { - super(control); - this.control = control; - this.attribute = attribute; - if (SUPPORTED_ATTRIBUTES.keySet().contains(attribute)) { - this.valueType = SUPPORTED_ATTRIBUTES.get(attribute); - } else { - throw new IllegalArgumentException(); - } - } - - public void doSetValue(Object value) { - Object oldValue = doGetValue(); - if (attribute.equals(SWTProperties.ENABLED)) { - control.setEnabled(((Boolean) value).booleanValue()); - } else if (attribute.equals(SWTProperties.VISIBLE)) { - control.setVisible(((Boolean) value).booleanValue()); - } else if (attribute.equals(SWTProperties.TOOLTIP_TEXT)) { - control.setToolTipText((String) value); - } else if (attribute.equals(SWTProperties.FOREGROUND)) { - control.setForeground((Color) value); - } else if (attribute.equals(SWTProperties.BACKGROUND)) { - control.setBackground((Color) value); - } else if (attribute.equals(SWTProperties.FONT)) { - control.setFont((Font) value); - } - fireValueChange(Diffs.createValueDiff(oldValue, value)); - } - - public Object doGetValue() { - if (attribute.equals(SWTProperties.ENABLED)) { - return control.getEnabled() ? Boolean.TRUE : Boolean.FALSE; - } - if (attribute.equals(SWTProperties.VISIBLE)) { - return control.getVisible() ? Boolean.TRUE : Boolean.FALSE; - } - if (attribute.equals(SWTProperties.TOOLTIP_TEXT)) { - return control.getToolTipText(); - } - if (attribute.equals(SWTProperties.FOREGROUND)) { - return control.getForeground(); - } - if (attribute.equals(SWTProperties.BACKGROUND)) { - return control.getBackground(); - } - if (attribute.equals(SWTProperties.FONT)) { - return control.getFont(); - } - - return null; - } - - public Object getValueType() { - return valueType; - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/DelayedObservableValue.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/DelayedObservableValue.java deleted file mode 100644 index f328dc6b..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/DelayedObservableValue.java +++ /dev/null @@ -1,237 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 180746) - * Boris Bokowski, IBM - initial API and implementation - * Matthew Hall - bug 212223 - * Will Horn - bug 215297 - * Matthew Hall - bug 208332 - ******************************************************************************/ - -package org.eclipse.jface.internal.databinding.swt; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.observable.value.IVetoableValue; -import org.eclipse.core.databinding.observable.value.ValueChangeEvent; -import org.eclipse.core.databinding.observable.value.ValueChangingEvent; -import org.eclipse.core.databinding.observable.value.ValueDiff; -import org.eclipse.jface.databinding.swt.ISWTObservableValue; -import org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue; -import org.eclipse.jface.util.Util; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Widget; - -/** - * {@link IObservableValue} implementation that wraps any - * {@link ISWTObservableValue} and delays notification of value change events - * from the wrapped observable value until a certain time has passed since the - * last change event, or until a FocusOut event is received from the underlying - * widget (whichever happens earlier). This class helps to delay validation - * until the user stops typing. To notify about pending changes, a delayed - * observable value will fire a stale event when the wrapped observable value - * fires a change event, but this change is being delayed. - * - * Note that this class will not forward {@link ValueChangingEvent} events from - * a wrapped {@link IVetoableValue}. - * - * @since 1.2 - */ -public class DelayedObservableValue extends AbstractSWTObservableValue { - class ValueUpdater implements Runnable { - private final Object oldValue; - - boolean cancel = false; - boolean running = false; - - ValueUpdater(Object oldValue) { - this.oldValue = oldValue; - } - - void cancel() { - cancel = true; - } - - public void run() { - if (!cancel) - try { - running = true; - internalFireValueChange(oldValue); - } finally { - running = false; - } - } - } - - private IStaleListener staleListener = new IStaleListener() { - public void handleStale(StaleEvent staleEvent) { - if (!updating) - fireStale(); - } - }; - - private IValueChangeListener valueChangeListener = new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - if (!updating) - makeDirty(); - } - }; - - private Listener focusOutListener = new Listener() { - public void handleEvent(Event event) { - // Force update on focus out - if (dirty) - internalFireValueChange(cachedValue); - } - }; - - private final int delay; - private ISWTObservableValue observable; - private Control control; - - private boolean dirty = true; - private Object cachedValue = null; - - private boolean updating = false; - - private ValueUpdater updater = null; - - /** - * Constructs a new instance bound to the given - * <code>ISWTObservableValue</code> and configured to fire change events - * once there have been no value changes in the observable for - * <code>delay</code> milliseconds. - * - * @param delayMillis - * @param observable - * @throws IllegalArgumentException - * if <code>updateEventType</code> is an incorrect type. - */ - public DelayedObservableValue(int delayMillis, - ISWTObservableValue observable) { - super(observable.getRealm(), observable.getWidget()); - this.delay = delayMillis; - this.observable = observable; - - observable.addValueChangeListener(valueChangeListener); - observable.addStaleListener(staleListener); - Widget widget = observable.getWidget(); - if (widget instanceof Control) { - control = (Control) widget; - control.addListener(SWT.FocusOut, focusOutListener); - } - - cachedValue = doGetValue(); - } - - protected Object doGetValue() { - if (dirty) { - cachedValue = observable.getValue(); - dirty = false; - - if (updater != null && !updater.running) { - fireValueChange(Diffs.createValueDiff(updater.oldValue, - cachedValue)); - cancelScheduledUpdate(); - } - } - return cachedValue; - } - - protected void doSetValue(Object value) { - updating = true; - try { - // Principle of least surprise: setValue overrides any pending - // update from observable. - dirty = false; - cancelScheduledUpdate(); - - Object oldValue = cachedValue; - observable.setValue(value); - // Bug 215297 - target observable could veto or override value - // passed to setValue(). Make sure we cache whatever is set. - cachedValue = observable.getValue(); - - if (!Util.equals(oldValue, cachedValue)) - fireValueChange(Diffs.createValueDiff(oldValue, cachedValue)); - } finally { - updating = false; - } - } - - public boolean isStale() { - ObservableTracker.getterCalled(this); - return (dirty && updater != null) || observable.isStale(); - } - - /** - * Returns the type of the value from {@link #doGetValue()}, i.e. - * String.class - * - * @see org.eclipse.core.databinding.observable.value.IObservableValue#getValueType() - */ - public Object getValueType() { - return observable.getValueType(); - } - - public void dispose() { - cancelScheduledUpdate(); - if (observable != null) { - observable.dispose(); - observable.removeValueChangeListener(valueChangeListener); - observable.removeStaleListener(staleListener); - observable = null; - } - if (control != null) { - control.removeListener(SWT.FocusOut, focusOutListener); - control = null; - } - super.dispose(); - } - - private void makeDirty() { - if (!dirty) { - dirty = true; - fireStale(); - } - cancelScheduledUpdate(); // if any - scheduleUpdate(); - } - - private void cancelScheduledUpdate() { - if (updater != null) { - updater.cancel(); - updater = null; - } - } - - private void scheduleUpdate() { - updater = new ValueUpdater(cachedValue); - observable.getWidget().getDisplay().timerExec(delay, updater); - } - - private void internalFireValueChange(final Object oldValue) { - cancelScheduledUpdate(); - fireValueChange(new ValueDiff() { - public Object getOldValue() { - return oldValue; - } - - public Object getNewValue() { - return getValue(); - } - }); - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/LabelObservableValue.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/LabelObservableValue.java deleted file mode 100644 index 8dc7915a..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/LabelObservableValue.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.swt; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue; -import org.eclipse.swt.widgets.Label; - -/** - * @since 3.3 - * - */ -public class LabelObservableValue extends AbstractSWTObservableValue { - - private final Label label; - - /** - * @param label - */ - public LabelObservableValue(Label label) { - super(label); - this.label = label; - } - - /** - * @param realm - * @param label - */ - public LabelObservableValue(Realm realm, Label label) { - super(realm, label); - this.label = label; - } - - public void doSetValue(final Object value) { - String oldValue = label.getText(); - String newValue = value == null ? "" : value.toString(); //$NON-NLS-1$ - label.setText(newValue); - - if (!newValue.equals(oldValue)) { - fireValueChange(Diffs.createValueDiff(oldValue, newValue)); - } - } - - public Object doGetValue() { - return label.getText(); - } - - public Object getValueType() { - return String.class; - } - -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ListObservableList.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ListObservableList.java deleted file mode 100644 index c6537f7f..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ListObservableList.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.swt; - -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.swt.widgets.List; - -/** - * @since 3.2 - * - */ -public class ListObservableList extends SWTObservableList { - - private final List list; - - /** - * @param list - */ - public ListObservableList(List list) { - super(SWTObservables.getRealm(list.getDisplay())); - this.list = list; - } - - protected int getItemCount() { - return list.getItemCount(); - } - - protected void setItems(String[] newItems) { - list.setItems(newItems); - } - - protected String[] getItems() { - return list.getItems(); - } - - protected String getItem(int index) { - return list.getItem(index); - } - - protected void setItem(int index, String string) { - list.setItem(index, string); - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ListObservableValue.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ListObservableValue.java deleted file mode 100644 index 7a000042..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ListObservableValue.java +++ /dev/null @@ -1,109 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - * Ashley Cambrell - bug 198904 - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.swt; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.List; -import org.eclipse.swt.widgets.Listener; - -/** - * @since 3.2 - * - */ -public class ListObservableValue extends AbstractSWTObservableValue { - - private final List list; - - private boolean updating = false; - - private String currentValue; - - private Listener listener; - - /** - * @param list - */ - public ListObservableValue(List list) { - super(list); - this.list = list; - this.currentValue = (String) doGetValue(); - - if ((list.getStyle() & SWT.MULTI) > 0) - throw new IllegalArgumentException( - "SWT.SINGLE support only for a List selection"); //$NON-NLS-1$ - - listener = new Listener() { - - public void handleEvent(Event event) { - if (!updating) { - Object oldValue = currentValue; - currentValue = (String) doGetValue(); - fireValueChange(Diffs.createValueDiff(oldValue, - currentValue)); - } - } - - }; - list.addListener(SWT.Selection, listener); - } - - public void doSetValue(Object value) { - String oldValue = null; - if (list.getSelection() != null && list.getSelection().length > 0) - oldValue = list.getSelection()[0]; - try { - updating = true; - String items[] = list.getItems(); - int index = -1; - if (items != null && value != null) { - for (int i = 0; i < items.length; i++) { - if (value.equals(items[i])) { - index = i; - break; - } - } - list.select(index); // -1 will not "unselect" - } - currentValue = (String) value; - } finally { - updating = false; - } - fireValueChange(Diffs.createValueDiff(oldValue, value)); - } - - public Object doGetValue() { - int index = list.getSelectionIndex(); - if (index >= 0) - return list.getItem(index); - return null; - } - - public Object getValueType() { - return String.class; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose() - */ - public synchronized void dispose() { - super.dispose(); - if (listener != null && !list.isDisposed()) { - list.removeListener(SWT.Selection, listener); - } - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ListSingleSelectionObservableValue.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ListSingleSelectionObservableValue.java deleted file mode 100644 index 05332de8..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ListSingleSelectionObservableValue.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - * Ashley Cambrell - bug 198904 - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.swt; - -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.widgets.List; - -/** - * @since 1.0 - * - */ -public class ListSingleSelectionObservableValue extends - SingleSelectionObservableValue { - - private SelectionListener selectionListener; - - /** - * @param combo - */ - public ListSingleSelectionObservableValue(List combo) { - super(combo); - } - - private List getList() { - return (List) getWidget(); - } - - protected void doAddSelectionListener(final Runnable runnable) { - selectionListener = new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - runnable.run(); - } - - public void widgetSelected(SelectionEvent e) { - runnable.run(); - } - }; - getList().addSelectionListener(selectionListener); - } - - protected int doGetSelectionIndex() { - return getList().getSelectionIndex(); - } - - protected void doSetSelectionIndex(int index) { - getList().setSelection(index); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose() - */ - public synchronized void dispose() { - super.dispose(); - if (selectionListener != null && !getList().isDisposed()) { - getList().removeSelectionListener(selectionListener); - } - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/SWTObservableList.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/SWTObservableList.java deleted file mode 100644 index 499f74e4..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/SWTObservableList.java +++ /dev/null @@ -1,193 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 208858 - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.swt; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -import org.eclipse.core.databinding.BindingException; -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.AbstractObservableList; - -/** - * Abstract base class of CComboObservableList, ComboObservableList, and - * ListObservableList. - * - * @since 3.2 - * - */ -public abstract class SWTObservableList extends AbstractObservableList { - - /** - * - */ - public SWTObservableList() { - super(); - } - - /** - * @param realm - */ - public SWTObservableList(Realm realm) { - super(realm); - } - - public void add(int index, Object element) { - int size = doGetSize(); - if (index < 0 || index > size) - index = size; - String[] newItems = new String[size + 1]; - System.arraycopy(getItems(), 0, newItems, 0, index); - newItems[index] = (String) element; - System.arraycopy(getItems(), index, newItems, index + 1, size - index); - setItems(newItems); - fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry(index, - true, element))); - } - - public int doGetSize() { - return getItemCount(); - } - - public Object get(int index) { - getterCalled(); - return getItem(index); - } - - public Object getElementType() { - return String.class; - } - - /** - * @param index - * @return the item at the given index - */ - protected abstract String getItem(int index); - - /** - * @return the item count - */ - protected abstract int getItemCount(); - - /** - * @return the items - */ - protected abstract String[] getItems(); - - private void getterCalled() { - ObservableTracker.getterCalled(this); - } - - public Object remove(int index) { - getterCalled(); - int size = doGetSize(); - if (index < 0 || index > size - 1) - throw new BindingException( - "Request to remove an element out of the collection bounds"); //$NON-NLS-1$ - - String[] newItems = new String[size - 1]; - String oldElement = getItem(index); - if (newItems.length > 0) { - System.arraycopy(getItems(), 0, newItems, 0, index); - if (size - 1 > index) { - System.arraycopy(getItems(), index + 1, newItems, index, size - - index - 1); - } - } - setItems(newItems); - fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry(index, - false, oldElement))); - return oldElement; - } - - public Object set(int index, Object element) { - String oldElement = getItem(index); - setItem(index, (String) element); - fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry(index, - false, oldElement), Diffs.createListDiffEntry(index, true, - element))); - return oldElement; - } - - public Object move(int oldIndex, int newIndex) { - checkRealm(); - if (oldIndex == newIndex) - return get(oldIndex); - int size = doGetSize(); - if (oldIndex < 0 || oldIndex >= size) - throw new IndexOutOfBoundsException( - "oldIndex: " + oldIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$ - if (newIndex < 0 || newIndex >= size) - throw new IndexOutOfBoundsException( - "newIndex: " + newIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$ - - String[] items = getItems(); - String[] newItems = new String[size]; - String element = items[oldIndex]; - if (newItems.length > 0) { - System.arraycopy(items, 0, newItems, 0, size); - if (oldIndex < newIndex) { - System.arraycopy(items, oldIndex + 1, newItems, oldIndex, - newIndex - oldIndex); - } else { - System.arraycopy(items, newIndex, newItems, newIndex + 1, - oldIndex - newIndex); - } - newItems[newIndex] = element; - } - setItems(newItems); - fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry(oldIndex, - false, element), Diffs.createListDiffEntry(newIndex, true, - element))); - return element; - } - - public boolean removeAll(Collection c) { - checkRealm(); - List oldItems = Arrays.asList(getItems()); - List newItems = new ArrayList(oldItems); - boolean removedAll = newItems.removeAll(c); - if (removedAll) { - setItems((String[]) newItems.toArray(new String[newItems.size()])); - fireListChange(Diffs.computeListDiff(oldItems, newItems)); - } - return removedAll; - } - - public boolean retainAll(Collection c) { - checkRealm(); - List oldItems = Arrays.asList(getItems()); - List newItems = new ArrayList(oldItems); - boolean retainedAll = newItems.retainAll(c); - if (retainedAll) { - setItems((String[]) newItems.toArray(new String[newItems.size()])); - fireListChange(Diffs.computeListDiff(oldItems, newItems)); - } - return retainedAll; - } - - /** - * @param index - * @param string - */ - protected abstract void setItem(int index, String string); - - /** - * @param newItems - */ - protected abstract void setItems(String[] newItems); - -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/SWTProperties.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/SWTProperties.java deleted file mode 100644 index 5c0e8e25..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/SWTProperties.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matt Carter - bug 170668 - * Brad Reynolds - bug 170848 - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.swt; - -/** - * Constants used to describe properties of SWT controls. - * - * @since 1.0 - * - */ -public interface SWTProperties { - - /** - * Applies to Control - */ - public static final String ENABLED = "enabled"; //$NON-NLS-1$ - /** - * Applies to Control - */ - public static final String VISIBLE = "visible"; //$NON-NLS-1$ - /** - * Applies to Control - */ - public static final String TOOLTIP_TEXT = "tooltip"; //$NON-NLS-1$ - /** - * Applies to - */ - public static final String ITEMS = "items"; //$NON-NLS-1$ - /** - * Applies to Spinner - */ - public static final String MAX = "max"; //$NON-NLS-1$ - /** - * Applies to Spinner - */ - public static final String MIN = "min"; //$NON-NLS-1$ - /** - * Applies to Spinner, Button - */ - public static final String SELECTION = "selection"; //$NON-NLS-1$ - /** - * Applies to Spinner, Button - */ - public static final String SELECTION_INDEX = "index"; //$NON-NLS-1$ - /** - * Applies to Text, Label, Combo - */ - public static final String TEXT = "text"; //$NON-NLS-1$ - - /** - * Applies to Label, CLabel. - */ - public static final String IMAGE = "image"; //$NON-NLS-1$ - /** - * Applies to Control - */ - public static final String FOREGROUND = "foreground"; //$NON-NLS-1$ - /** - * Applies to Control - */ - public static final String BACKGROUND = "background"; //$NON-NLS-1$ - /** - * Applies to Control - */ - public static final String FONT = "font"; //$NON-NLS-1$ - -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ScaleObservableValue.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ScaleObservableValue.java deleted file mode 100644 index 8424662a..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ScaleObservableValue.java +++ /dev/null @@ -1,150 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Peter Centgraf - bug 175763 - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.swt; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.widgets.Scale; - -/** - * @since 1.0 - * - */ -public class ScaleObservableValue extends AbstractSWTObservableValue { - - private final Scale scale; - - private final String attribute; - - private boolean updating = false; - - private int currentSelection; - - private SelectionListener listener; - - /** - * @param scale - * @param attribute - */ - public ScaleObservableValue(Scale scale, String attribute) { - super(scale); - this.scale = scale; - this.attribute = attribute; - init(); - } - - /** - * @param realm - * @param scale - * @param attribute - */ - public ScaleObservableValue(Realm realm, Scale scale, String attribute) { - super(realm, scale); - this.scale = scale; - this.attribute = attribute; - init(); - } - - private void init() { - if (attribute.equals(SWTProperties.SELECTION)) { - currentSelection = scale.getSelection(); - scale.addSelectionListener(listener = new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - if (!updating) { - int newSelection = ScaleObservableValue.this.scale - .getSelection(); - notifyIfChanged(currentSelection, newSelection); - currentSelection = newSelection; - } - } - }); - } else if (!attribute.equals(SWTProperties.MIN) - && !attribute.equals(SWTProperties.MAX)) { - throw new IllegalArgumentException( - "Attribute name not valid: " + attribute); //$NON-NLS-1$ - } - } - - public void doSetValue(final Object value) { - int oldValue; - int newValue; - try { - updating = true; - newValue = ((Integer) value).intValue(); - if (attribute.equals(SWTProperties.SELECTION)) { - oldValue = scale.getSelection(); - scale.setSelection(newValue); - currentSelection = newValue; - } else if (attribute.equals(SWTProperties.MIN)) { - oldValue = scale.getMinimum(); - scale.setMinimum(newValue); - } else if (attribute.equals(SWTProperties.MAX)) { - oldValue = scale.getMaximum(); - scale.setMaximum(newValue); - } else { - Assert.isTrue(false, "invalid attribute name:" + attribute); //$NON-NLS-1$ - return; - } - - notifyIfChanged(oldValue, newValue); - } finally { - updating = false; - } - } - - public Object doGetValue() { - int value = 0; - if (attribute.equals(SWTProperties.SELECTION)) { - value = scale.getSelection(); - } else if (attribute.equals(SWTProperties.MIN)) { - value = scale.getMinimum(); - } else if (attribute.equals(SWTProperties.MAX)) { - value = scale.getMaximum(); - } - return new Integer(value); - } - - public Object getValueType() { - return Integer.TYPE; - } - - /** - * @return attribute being observed - */ - public String getAttribute() { - return attribute; - } - - /* (non-Javadoc) - * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose() - */ - public synchronized void dispose() { - super.dispose(); - - if (listener != null && !scale.isDisposed()) { - scale.removeSelectionListener(listener); - } - listener = null; - } - - private void notifyIfChanged(int oldValue, int newValue) { - if (oldValue != newValue) { - fireValueChange(Diffs.createValueDiff(new Integer(oldValue), - new Integer(newValue))); - } - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ShellObservableValue.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ShellObservableValue.java deleted file mode 100644 index a38091eb..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ShellObservableValue.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 207844) - * IBM Corporation - initial API and implementation - * Brad Reynolds - initial API and implementation - * Matthew Hall - bug 212235 - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.swt; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue; -import org.eclipse.swt.widgets.Shell; - -/** - * An {@link IObservableValue} that tracks the text of a Shell. - * - * @since 1.2 - */ -public class ShellObservableValue extends AbstractSWTObservableValue { - - private final Shell shell; - - /** - * Constructs a ShellObservableValue which tracks the text of the given - * Shell. - * - * @param shell - * the shell to track - */ - public ShellObservableValue(Shell shell) { - super(shell); - this.shell = shell; - } - - /** - * Constructs a ShellObservableValue belonging to the given realm, which - * tracks the text of the given shell. - * - * @param realm - * the realm of the constructed observable - * @param shell - * the shell to track - */ - public ShellObservableValue(Realm realm, Shell shell) { - super(realm, shell); - this.shell = shell; - } - - protected void doSetValue(final Object value) { - String oldValue = shell.getText(); - String newValue = value == null ? "" : value.toString(); //$NON-NLS-1$ - shell.setText(newValue); - - if (!newValue.equals(oldValue)) { - fireValueChange(Diffs.createValueDiff(oldValue, newValue)); - } - } - - protected Object doGetValue() { - return shell.getText(); - } - - public Object getValueType() { - return String.class; - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/SingleSelectionObservableValue.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/SingleSelectionObservableValue.java deleted file mode 100644 index 1f69137a..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/SingleSelectionObservableValue.java +++ /dev/null @@ -1,103 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.swt; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue; -import org.eclipse.swt.widgets.Control; - -/** - * @since 1.0 - * - */ -abstract public class SingleSelectionObservableValue extends - AbstractSWTObservableValue { - - private boolean updating = false; - - private int currentSelection; - - /** - * @param control - * the control - */ - public SingleSelectionObservableValue(Control control) { - super(control); - init(); - } - - /** - * @param realm - * @param control - */ - public SingleSelectionObservableValue(Realm realm, Control control) { - super(realm, control); - init(); - } - - private void init() { - currentSelection = doGetSelectionIndex(); - doAddSelectionListener(new Runnable(){ - public void run() { - if (!updating) { - int newSelection = doGetSelectionIndex(); - notifyIfChanged(currentSelection, newSelection); - currentSelection = newSelection; - } - } - }); - } - - /** - * @param runnable - */ - protected abstract void doAddSelectionListener(Runnable runnable); - - public void doSetValue(Object value) { - try { - updating = true; - int intValue = ((Integer) value).intValue(); - doSetSelectionIndex(intValue); - notifyIfChanged(currentSelection, intValue); - currentSelection = intValue; - } finally { - updating = false; - } - } - - /** - * @param intValue - * the selection index - */ - protected abstract void doSetSelectionIndex(int intValue); - - public Object doGetValue() { - return new Integer(doGetSelectionIndex()); - } - - /** - * @return the selection index - */ - protected abstract int doGetSelectionIndex(); - - public Object getValueType() { - return Integer.TYPE; - } - - private void notifyIfChanged(int oldValue, int newValue) { - if (oldValue != newValue) { - fireValueChange(Diffs.createValueDiff(new Integer( - oldValue), new Integer(newValue))); - } - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/SpinnerObservableValue.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/SpinnerObservableValue.java deleted file mode 100644 index 89c34b98..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/SpinnerObservableValue.java +++ /dev/null @@ -1,151 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - * Ashley Cambrell - bug 198904 - * Matthew Hall - bug 118516 - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.swt; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.widgets.Spinner; - -/** - * @since 1.0 - * - */ -public class SpinnerObservableValue extends AbstractSWTObservableValue { - - private final Spinner spinner; - - private final String attribute; - - private boolean updating = false; - - private int currentSelection; - - private ModifyListener modifyListener; - - /** - * @param spinner - * @param attribute - */ - public SpinnerObservableValue(Spinner spinner, String attribute) { - super(spinner); - this.spinner = spinner; - this.attribute = attribute; - init(); - } - - /** - * @param realm - * @param spinner - * @param attribute - */ - public SpinnerObservableValue(Realm realm, Spinner spinner, String attribute) { - super(realm, spinner); - this.spinner = spinner; - this.attribute = attribute; - init(); - } - - private void init() { - if (attribute.equals(SWTProperties.SELECTION)) { - currentSelection = spinner.getSelection(); - modifyListener = new ModifyListener() { - public void modifyText(ModifyEvent e) { - if (!updating) { - int newSelection = SpinnerObservableValue.this.spinner - .getSelection(); - notifyIfChanged(currentSelection, newSelection); - currentSelection = newSelection; - } - } - }; - spinner.addModifyListener(modifyListener); - } else if (!attribute.equals(SWTProperties.MIN) - && !attribute.equals(SWTProperties.MAX)) { - throw new IllegalArgumentException( - "Attribute name not valid: " + attribute); //$NON-NLS-1$ - } - } - - public void doSetValue(final Object value) { - int oldValue; - int newValue; - try { - updating = true; - newValue = ((Integer) value).intValue(); - if (attribute.equals(SWTProperties.SELECTION)) { - oldValue = spinner.getSelection(); - spinner.setSelection(newValue); - currentSelection = newValue; - } else if (attribute.equals(SWTProperties.MIN)) { - oldValue = spinner.getMinimum(); - spinner.setMinimum(newValue); - } else if (attribute.equals(SWTProperties.MAX)) { - oldValue = spinner.getMaximum(); - spinner.setMaximum(newValue); - } else { - Assert.isTrue(false, "invalid attribute name:" + attribute); //$NON-NLS-1$ - return; - } - notifyIfChanged(oldValue, newValue); - } finally { - updating = false; - } - } - - public Object doGetValue() { - int value = 0; - if (attribute.equals(SWTProperties.SELECTION)) { - value = spinner.getSelection(); - } else if (attribute.equals(SWTProperties.MIN)) { - value = spinner.getMinimum(); - } else if (attribute.equals(SWTProperties.MAX)) { - value = spinner.getMaximum(); - } - return new Integer(value); - } - - public Object getValueType() { - return Integer.TYPE; - } - - /** - * @return attribute being observed - */ - public String getAttribute() { - return attribute; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose() - */ - public synchronized void dispose() { - super.dispose(); - if (modifyListener != null && !spinner.isDisposed()) { - spinner.removeModifyListener(modifyListener); - } - } - - private void notifyIfChanged(int oldValue, int newValue) { - if (oldValue != newValue) { - fireValueChange(Diffs.createValueDiff(new Integer(oldValue), - new Integer(newValue))); - } - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/TableSingleSelectionObservableValue.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/TableSingleSelectionObservableValue.java deleted file mode 100644 index dd7d12c3..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/TableSingleSelectionObservableValue.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - * Ashley Cambrell - bug 198904 - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.swt; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.widgets.Table; - -/** - * @since 1.0 - * - */ -public class TableSingleSelectionObservableValue extends - SingleSelectionObservableValue { - - private SelectionListener selectionListener; - - /** - * @param table - */ - public TableSingleSelectionObservableValue(Table table) { - super(table); - } - - /** - * @param realm - * @param table - */ - public TableSingleSelectionObservableValue(Realm realm, Table table) { - super(realm, table); - } - - private Table getTable() { - return (Table) getWidget(); - } - - protected void doAddSelectionListener(final Runnable runnable) { - selectionListener = new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - runnable.run(); - } - - public void widgetSelected(SelectionEvent e) { - runnable.run(); - } - }; - getTable().addSelectionListener(selectionListener); - } - - protected int doGetSelectionIndex() { - return getTable().getSelectionIndex(); - } - - protected void doSetSelectionIndex(int index) { - getTable().setSelection(index); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose() - */ - public synchronized void dispose() { - super.dispose(); - if (selectionListener != null && !getTable().isDisposed()) { - getTable().removeSelectionListener(selectionListener); - } - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/TextEditableObservableValue.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/TextEditableObservableValue.java deleted file mode 100644 index 3457c0a4..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/TextEditableObservableValue.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.internal.databinding.swt; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue; -import org.eclipse.swt.widgets.Text; - -/** - * Observable value for the editable property of a Text. - * - * @since 1.1 - */ -public class TextEditableObservableValue extends AbstractSWTObservableValue { - private Text text; - - /** - * @param text - */ - public TextEditableObservableValue(Text text) { - super(text); - this.text = text; - } - - /** - * @param realm - * @param text - */ - public TextEditableObservableValue(Realm realm, Text text) { - super(realm, text); - this.text = text; - } - - /* (non-Javadoc) - * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#doGetValue() - */ - protected Object doGetValue() { - return (text.getEditable()) ? Boolean.TRUE : Boolean.FALSE; - } - - /* (non-Javadoc) - * @see org.eclipse.core.databinding.observable.value.IObservableValue#getValueType() - */ - public Object getValueType() { - return Boolean.TYPE; - } - - /* (non-Javadoc) - * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#doSetValue(java.lang.Object) - */ - protected void doSetValue(Object value) { - if (value == null) { - throw new IllegalArgumentException("Parameter value was null."); //$NON-NLS-1$ - } - - Boolean oldValue = new Boolean(text.getEditable()); - Boolean newValue = (Boolean) value; - - text.setEditable(newValue.booleanValue()); - - if (!oldValue.equals(newValue)) { - fireValueChange(Diffs.createValueDiff(oldValue, newValue)); - } - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/TextObservableValue.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/TextObservableValue.java deleted file mode 100644 index dcc516c6..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/TextObservableValue.java +++ /dev/null @@ -1,198 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds (bug 135446) - * Brad Reynolds - bug 164653 - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.swt; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTVetoableValue; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.VerifyEvent; -import org.eclipse.swt.events.VerifyListener; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Text; - -/** - * {@link IObservable} implementation that wraps a {@link Text} widget. The time - * at which listeners should be notified about changes to the text is specified - * on construction. - * - * <dl> - * <dt>Events:</dt> - * <dd> If the update event type (specified on construction) is - * <code>SWT.Modify</code> a value change event will be fired on every key - * stroke. If the update event type is <code>SWT.FocusOut</code> a value - * change event will be fired on focus out. When in either mode if the user is - * entering text and presses [Escape] the value will be reverted back to the - * last value set using doSetValue(). Regardless of the update event type a - * value changing event will fire on verify to enable vetoing of changes.</dd> - * </dl> - * - * @since 1.0 - */ -public class TextObservableValue extends AbstractSWTVetoableValue { - - /** - * {@link Text} widget that this is being observed. - */ - private final Text text; - - /** - * Flag to track when the model is updating the widget. When - * <code>true</code> the handlers for the SWT events should not process - * the event as this would cause an infinite loop. - */ - private boolean updating = false; - - /** - * SWT event that on firing this observable will fire change events to its - * listeners. - */ - private final int updateEventType; - - /** - * Valid types for the {@link #updateEventType}. - */ - private static final int[] validUpdateEventTypes = new int[] { SWT.Modify, - SWT.FocusOut, SWT.None }; - - /** - * Previous value of the Text. - */ - private String oldValue; - - private Listener updateListener = new Listener() { - public void handleEvent(Event event) { - if (!updating) { - String newValue = text.getText(); - - if (!newValue.equals(oldValue)) { - fireValueChange(Diffs.createValueDiff(oldValue, newValue)); - oldValue = newValue; - } - } - } - }; - - private VerifyListener verifyListener; - - /** - * Constructs a new instance bound to the given <code>text</code> widget - * and configured to fire change events to its listeners at the time of the - * <code>updateEventType</code>. - * - * @param text - * @param updateEventType - * SWT event constant as to what SWT event to update the model in - * response to. Appropriate values are: <code>SWT.Modify</code>, - * <code>SWT.FocusOut</code>, <code>SWT.None</code>. - * @throws IllegalArgumentException - * if <code>updateEventType</code> is an incorrect type. - */ - public TextObservableValue(final Text text, int updateEventType) { - this(SWTObservables.getRealm(text.getDisplay()), text, updateEventType); - } - - /** - * Constructs a new instance. - * - * @param realm can not be <code>null</code> - * @param text - * @param updateEventType - */ - public TextObservableValue(final Realm realm, Text text, int updateEventType) { - super(realm, text); - - boolean eventValid = false; - for (int i = 0; !eventValid && i < validUpdateEventTypes.length; i++) { - eventValid = (updateEventType == validUpdateEventTypes[i]); - } - if (!eventValid) { - throw new IllegalArgumentException( - "UpdateEventType [" + updateEventType + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ - } - this.text = text; - this.updateEventType = updateEventType; - if (updateEventType != SWT.None) { - text.addListener(updateEventType, updateListener); - } - - oldValue = text.getText(); - - verifyListener = new VerifyListener() { - public void verifyText(VerifyEvent e) { - if (!updating) { - String currentText = TextObservableValue.this.text - .getText(); - String newText = currentText.substring(0, e.start) + e.text - + currentText.substring(e.end); - if (!fireValueChanging(Diffs.createValueDiff(currentText, - newText))) { - e.doit = false; - } - } - } - }; - text.addVerifyListener(verifyListener); - } - - /** - * Sets the bound {@link Text Text's} text to the passed <code>value</code>. - * - * @param value - * new value, String expected - * @see org.eclipse.core.databinding.observable.value.AbstractVetoableValue#doSetApprovedValue(java.lang.Object) - * @throws ClassCastException - * if the value is anything other than a String - */ - protected void doSetApprovedValue(final Object value) { - try { - updating = true; - text.setText(value == null ? "" : value.toString()); //$NON-NLS-1$ - oldValue = text.getText(); - } finally { - updating = false; - } - } - - /** - * Returns the current value of the {@link Text}. - * - * @see org.eclipse.core.databinding.observable.value.AbstractVetoableValue#doGetValue() - */ - public Object doGetValue() { - return oldValue = text.getText(); - } - - /** - * Returns the type of the value from {@link #doGetValue()}, i.e. - * String.class - * - * @see org.eclipse.core.databinding.observable.value.IObservableValue#getValueType() - */ - public Object getValueType() { - return String.class; - } - - public void dispose() { - if (!text.isDisposed()) { - if (updateEventType != SWT.None) { - text.removeListener(updateEventType, updateListener); - } - text.removeVerifyListener(verifyListener); - } - super.dispose(); - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/CheckableCheckedElementsObservableSet.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/CheckableCheckedElementsObservableSet.java deleted file mode 100644 index da84d946..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/CheckableCheckedElementsObservableSet.java +++ /dev/null @@ -1,219 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 124684) - ******************************************************************************/ - -package org.eclipse.jface.internal.databinding.viewers; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.set.AbstractObservableSet; -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.viewers.CheckStateChangedEvent; -import org.eclipse.jface.viewers.ICheckStateListener; -import org.eclipse.jface.viewers.ICheckable; - -/** - * - * @since 1.2 - */ -public class CheckableCheckedElementsObservableSet extends - AbstractObservableSet { - private ICheckable checkable; - private Set wrappedSet; - private Object elementType; - private ICheckStateListener listener; - - /** - * Constructs a new instance on the given realm and checkable. - * - * @param realm - * the observable's realm - * @param checkable - * the ICheckable to track - * @param elementType - * type of elements in the set - */ - public CheckableCheckedElementsObservableSet(Realm realm, - ICheckable checkable, Object elementType) { - this(realm, checkable, elementType, new HashSet()); - } - - /** - * Constructs a new instance of the given realm, and checkable, - * - * @param realm - * the observable's realm - * @param checkable - * the ICheckable to track - * @param elementType - * type of elements in the set - * @param wrappedSet - * the set being wrapped - */ - public CheckableCheckedElementsObservableSet(Realm realm, - ICheckable checkable, Object elementType, final Set wrappedSet) { - super(realm); - Assert.isNotNull(checkable, "Checkable cannot be null"); //$NON-NLS-1$ - Assert.isNotNull(wrappedSet, "Wrapped set cannot be null"); //$NON-NLS-1$ - this.checkable = checkable; - this.wrappedSet = wrappedSet; - this.elementType = elementType; - - listener = new ICheckStateListener() { - public void checkStateChanged(CheckStateChangedEvent event) { - Object element = event.getElement(); - if (event.getChecked()) { - if (wrappedSet.add(element)) - fireSetChange(Diffs.createSetDiff(Collections - .singleton(element), Collections.EMPTY_SET)); - } else { - if (wrappedSet.remove(element)) - fireSetChange(Diffs.createSetDiff( - Collections.EMPTY_SET, Collections - .singleton(element))); - } - } - }; - checkable.addCheckStateListener(listener); - } - - protected Set getWrappedSet() { - return wrappedSet; - } - - Set createDiffSet() { - return new HashSet(); - } - - public Object getElementType() { - return elementType; - } - - public boolean add(Object o) { - getterCalled(); - boolean added = wrappedSet.add(o); - if (added) { - checkable.setChecked(o, true); - fireSetChange(Diffs.createSetDiff(Collections.singleton(o), - Collections.EMPTY_SET)); - } - return added; - } - - public boolean remove(Object o) { - getterCalled(); - boolean removed = wrappedSet.remove(o); - if (removed) { - checkable.setChecked(o, false); - fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, - Collections.singleton(o))); - } - return removed; - } - - public boolean addAll(Collection c) { - getterCalled(); - Set additions = createDiffSet(); - for (Iterator iterator = c.iterator(); iterator.hasNext();) { - Object element = iterator.next(); - if (wrappedSet.add(element)) { - checkable.setChecked(element, true); - additions.add(element); - } - } - boolean changed = !additions.isEmpty(); - if (changed) - fireSetChange(Diffs.createSetDiff(additions, Collections.EMPTY_SET)); - return changed; - } - - public boolean removeAll(Collection c) { - getterCalled(); - Set removals = createDiffSet(); - for (Iterator iterator = c.iterator(); iterator.hasNext();) { - Object element = iterator.next(); - if (wrappedSet.remove(element)) { - checkable.setChecked(element, false); - removals.add(element); - } - } - boolean changed = !removals.isEmpty(); - if (changed) - fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, removals)); - return changed; - } - - public boolean retainAll(Collection c) { - getterCalled(); - - // To ensure that elements are compared correctly, e.g. ViewerElementSet - Set toRetain = createDiffSet(); - toRetain.addAll(c); - - Set removals = createDiffSet(); - for (Iterator iterator = wrappedSet.iterator(); iterator.hasNext();) { - Object element = iterator.next(); - if (!toRetain.contains(element)) { - iterator.remove(); - checkable.setChecked(element, false); - removals.add(element); - } - } - boolean changed = !removals.isEmpty(); - if (changed) - fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, removals)); - return changed; - } - - public void clear() { - removeAll(wrappedSet); - } - - public Iterator iterator() { - getterCalled(); - final Iterator wrappedIterator = wrappedSet.iterator(); - return new Iterator() { - private Object last = null; - - public boolean hasNext() { - getterCalled(); - return wrappedIterator.hasNext(); - } - - public Object next() { - getterCalled(); - return last = wrappedIterator.next(); - } - - public void remove() { - getterCalled(); - wrappedIterator.remove(); - checkable.setChecked(last, false); - fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, - Collections.singleton(last))); - } - }; - } - - public synchronized void dispose() { - if (checkable != null) { - checkable.removeCheckStateListener(listener); - checkable = null; - listener = null; - } - super.dispose(); - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/CheckboxViewerCheckedElementsObservableSet.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/CheckboxViewerCheckedElementsObservableSet.java deleted file mode 100644 index eba454c3..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/CheckboxViewerCheckedElementsObservableSet.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 124684) - ******************************************************************************/ - -package org.eclipse.jface.internal.databinding.viewers; - -import java.util.Arrays; -import java.util.Set; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.jface.databinding.viewers.IViewerObservableSet; -import org.eclipse.jface.viewers.CheckboxTableViewer; -import org.eclipse.jface.viewers.CheckboxTreeViewer; -import org.eclipse.jface.viewers.StructuredViewer; -import org.eclipse.jface.viewers.Viewer; - -/** - * An observable set that tracks the checked elements in a CheckboxTableViewer - * or CheckboxTreeViewer - * - * @since 1.2 - */ -public class CheckboxViewerCheckedElementsObservableSet extends - CheckableCheckedElementsObservableSet implements IViewerObservableSet { - private StructuredViewer viewer; - - /** - * Constructs a new instance on the given realm and checkable. - * - * @param realm - * the observable's realm - * @param viewer - * the CheckboxTableViewer viewer to track. - * @param elementType - * type of elements in the set - */ - public CheckboxViewerCheckedElementsObservableSet(Realm realm, - CheckboxTableViewer viewer, Object elementType) { - super(realm, viewer, elementType, createElementSet(viewer)); - this.viewer = viewer; - } - - /** - * Constructs a new instance on the given realm and checkable. - * - * @param realm - * the observable's realm - * @param viewer - * the CheckboxTreeViewer viewer to track. - * @param elementType - * type of elements in the set - */ - public CheckboxViewerCheckedElementsObservableSet(Realm realm, - CheckboxTreeViewer viewer, Object elementType) { - super(realm, viewer, elementType, createElementSet(viewer)); - this.viewer = viewer; - } - - Set createDiffSet() { - return ViewerElementSet.withComparer(viewer.getComparer()); - } - - private static Set createElementSet(CheckboxTableViewer viewer) { - Set set = ViewerElementSet.withComparer(viewer.getComparer()); - set.addAll(Arrays.asList(viewer.getCheckedElements())); - return set; - } - - private static Set createElementSet(CheckboxTreeViewer viewer) { - Set set = ViewerElementSet.withComparer(viewer.getComparer()); - set.addAll(Arrays.asList(viewer.getCheckedElements())); - return set; - } - - public Viewer getViewer() { - return viewer; - } - - public synchronized void dispose() { - viewer = null; - super.dispose(); - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/LeafNodesSet.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/LeafNodesSet.java deleted file mode 100644 index 4b4b140f..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/LeafNodesSet.java +++ /dev/null @@ -1,260 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.viewers; - -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.databinding.observable.set.AbstractObservableSet; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.ISetChangeListener; -import org.eclipse.core.databinding.observable.set.SetChangeEvent; -import org.eclipse.core.databinding.observable.set.SetDiff; -import org.eclipse.core.internal.databinding.observable.tree.IUnorderedTreeProvider; -import org.eclipse.core.internal.databinding.observable.tree.TreePath; - -/** - * This set consists of all leaf nodes from the given tree (that is, all nodes - * for which ITreeProvider.createChildSet returns null). - */ -public class LeafNodesSet extends AbstractObservableSet { - - private HashSet leafNodes = new HashSet(); - - private HashMap mapElementsOntoNodeInfo = new HashMap(); - - private IUnorderedTreeProvider tree; - - private Object input; - - private int staleCount = 0; - - private class NodeInfo implements IStaleListener, ISetChangeListener { - // Number of times the element occurs in the tree - private int count; - - // Element - private TreePath treePath; - - // Children set (or null if this is a leaf node) - IObservableSet children; - - private boolean wasStale = false; - - /** - * @param treePath - */ - public NodeInfo(TreePath treePath) { - this.treePath = treePath; - children = tree.createChildSet(this.treePath); - if (children != null) { - children.addStaleListener(this); - children.addSetChangeListener(this); - } - count = 1; - } - - public void handleSetChange(SetChangeEvent event) { - processDiff(treePath, event.diff); - } - - public void handleStale(StaleEvent event) { - if (wasStale != children.isStale()) { - if (wasStale) { - staleCount--; - } else { - staleCount++; - } - wasStale = !wasStale; - } - setStale(staleCount > 0); - } - - /** - * - */ - public void dispose() { - if (children != null) { - children.dispose(); - children = null; - if (wasStale) { - staleCount--; - } - } - } - } - - /** - * Creates a set that will contain the leaf nodes from the given tree - * - * @param tree - * tree whose leaf nodes will be computed - */ - public LeafNodesSet(IUnorderedTreeProvider tree) { - this(null, tree); - } - - /** - * Creates a set that will contain the leaf nodes from the given tree, and - * sets the root of the tree to the given element. - * - * @param initialInput - * root of the tree - * @param tree - * tree whose leaf nodes will be computed - */ - public LeafNodesSet(Object initialInput, IUnorderedTreeProvider tree) { - super(tree.getRealm()); - this.tree = tree; - if (initialInput != null) { - setInput(initialInput); - } - } - - private void processDiff(TreePath treePath, SetDiff diff) { - Set removals = new HashSet(); - HashSet additions = new HashSet(); - - for (Iterator iter = diff.getRemovals().iterator(); iter.hasNext();) { - Object next = iter.next(); - - elementRemoved(treePath.createChildPath(next), removals); - } - - for (Iterator iter = diff.getAdditions().iterator(); iter.hasNext();) { - Object next = iter.next(); - - elementDiscovered(treePath.createChildPath(next), additions); - } - - HashSet newRemovals = new HashSet(); - newRemovals.addAll(removals); - newRemovals.removeAll(additions); - - HashSet newAdditions = new HashSet(); - newAdditions.addAll(additions); - newAdditions.removeAll(removals); - - leafNodes.addAll(newAdditions); - leafNodes.removeAll(newRemovals); - - if (!newAdditions.isEmpty() || !newRemovals.isEmpty()) { - setStale(staleCount > 0); - fireSetChange(Diffs.createSetDiff(newAdditions, newRemovals)); - } - } - - /** - * Sets the root of the tree to the given element. - * - * @param input - * new root of the tree - */ - public void setInput(Object input) { - Set removals = Collections.EMPTY_SET; - Set additions = Collections.EMPTY_SET; - if (this.input != null) { - removals = Collections.singleton(this.input); - } else if (input != null) { - additions = Collections.singleton(input); - } - this.input = input; - processDiff(TreePath.EMPTY, Diffs.createSetDiff(additions, removals)); - } - - /** - * Called when an element is removed from the tree. The given HashSet will - * be filled in with all removed leaf nodes. - * - * @param treePath - * @param removals - */ - private void elementRemoved(TreePath treePath, Set removals) { - NodeInfo newNode = (NodeInfo) mapElementsOntoNodeInfo.get(treePath); - - if (newNode != null) { - newNode = new NodeInfo(treePath); - newNode.count--; - if (newNode.count == 0) { - mapElementsOntoNodeInfo.remove(treePath); - if (newNode.children != null) { - for (Iterator iter = newNode.children.iterator(); iter - .hasNext();) { - Object next = iter.next(); - - elementRemoved(treePath.createChildPath(next), removals); - } - newNode.children.dispose(); - } else { - removals.add(treePath); - } - } - } - } - - /** - * Called when a new element is discovered in the tree. The given HashSet - * will be filled in with all newly discovered leaf nodes. - * - * @param treePath - * @param additions - */ - private void elementDiscovered(TreePath treePath, HashSet additions) { - NodeInfo newNode = (NodeInfo) mapElementsOntoNodeInfo.get(treePath); - - if (newNode == null) { - newNode = new NodeInfo(treePath); - mapElementsOntoNodeInfo.put(treePath, newNode); - if (newNode.children != null) { - for (Iterator iter = newNode.children.iterator(); iter - .hasNext();) { - Object next = iter.next(); - - elementDiscovered(treePath.createChildPath(next), additions); - } - } else { - additions.add(treePath); - } - } else { - // If this node was already known, increment the reference count. - newNode.count++; - } - } - - protected Set getWrappedSet() { - return leafNodes; - } - - public Object getElementType() { - return Object.class; - } - - public void dispose() { - for (Iterator iter = mapElementsOntoNodeInfo.values().iterator(); iter - .hasNext();) { - NodeInfo next = (NodeInfo) iter.next(); - - if (next.children != null) { - next.dispose(); - } - } - - mapElementsOntoNodeInfo.clear(); - leafNodes.clear(); - super.dispose(); - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ListViewerUpdater.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ListViewerUpdater.java deleted file mode 100644 index 015669d8..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ListViewerUpdater.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 215531) - * Matthew Hall - bug 226765 - ******************************************************************************/ - -package org.eclipse.jface.internal.databinding.viewers; - -import org.eclipse.jface.viewers.AbstractListViewer; - -/** - * NON-API - A {@link ViewerUpdater} that updates {@link AbstractListViewer} - * instances. - * - * @since 1.2 - */ -class ListViewerUpdater extends ViewerUpdater { - private AbstractListViewer viewer; - - ListViewerUpdater(AbstractListViewer viewer) { - super(viewer); - this.viewer = viewer; - } - - public void insert(Object element, int position) { - viewer.insert(element, position); - } - - public void remove(Object element, int position) { - viewer.remove(element); - } - - public void add(Object[] elements) { - viewer.add(elements); - } - - public void remove(Object[] elements) { - viewer.remove(elements); - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ObservableCollectionContentProvider.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ObservableCollectionContentProvider.java deleted file mode 100644 index 7daec159..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ObservableCollectionContentProvider.java +++ /dev/null @@ -1,206 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 215531) - * Matthew Hall - bug 226765 - ******************************************************************************/ - -package org.eclipse.jface.internal.databinding.viewers; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.Observables; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.masterdetail.MasterDetailObservables; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.viewers.AbstractListViewer; -import org.eclipse.jface.viewers.AbstractTableViewer; -import org.eclipse.jface.viewers.IElementComparer; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.StructuredViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.widgets.Display; - -/** - * NON-API - Abstract base class for content providers where the viewer input is - * expected to be an {@link IObservableCollection}. - * - * @since 1.2 - */ -public abstract class ObservableCollectionContentProvider implements - IStructuredContentProvider { - private IObservableValue viewerObservable; - - /** - * Element comparer used by the viewer (may be null). - */ - protected IElementComparer comparer; - - /** - * Interface for sending updates to the viewer. - */ - protected ViewerUpdater viewerUpdater; - - /** - * Observable set of all elements known to the content provider. Subclasses - * must add new elements to this set <b>before</b> adding them to the - * viewer, and must remove old elements from this set <b>after</b> removing - * them from the viewer. - */ - protected IObservableSet knownElements; - - private IObservableSet unmodifiableKnownElements; - private IObservableCollection observableCollection; - - /** - * Constructs an ObservableCollectionContentProvider - */ - protected ObservableCollectionContentProvider() { - final Realm realm = SWTObservables.getRealm(Display.getDefault()); - viewerObservable = new WritableValue(realm); - viewerUpdater = null; - - // Known elements is a detail set of viewerObservable, so that when we - // get the viewer instance we can swap in a set that uses its - // IElementComparer, if any. - IObservableFactory knownElementsFactory = new IObservableFactory() { - public IObservable createObservable(Object target) { - IElementComparer comparer = null; - if (target instanceof StructuredViewer) - comparer = ((StructuredViewer) target).getComparer(); - return ObservableViewerElementSet.withComparer(realm, null, - comparer); - } - }; - knownElements = MasterDetailObservables.detailSet(viewerObservable, - knownElementsFactory, null); - unmodifiableKnownElements = Observables - .unmodifiableObservableSet(knownElements); - - observableCollection = null; - } - - public Object[] getElements(Object inputElement) { - if (observableCollection == null) - return new Object[0]; - return observableCollection.toArray(); - } - - public void dispose() { - if (observableCollection != null) - removeCollectionChangeListener(observableCollection); - - if (viewerObservable != null) { - viewerObservable.setValue(null); - viewerObservable.dispose(); - viewerObservable = null; - } - viewerUpdater = null; - knownElements = null; - unmodifiableKnownElements = null; - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - setViewer(viewer); - setInput(newInput); - } - - private void setViewer(Viewer viewer) { - viewerUpdater = createViewerUpdater(viewer); - comparer = getElementComparer(viewer); - viewerObservable.setValue(viewer); // (clears knownElements) - } - - private static IElementComparer getElementComparer(Viewer viewer) { - if (viewer instanceof StructuredViewer) - return ((StructuredViewer) viewer).getComparer(); - return null; - } - - ViewerUpdater createViewerUpdater(Viewer viewer) { - if (viewer instanceof AbstractListViewer) - return new ListViewerUpdater((AbstractListViewer) viewer); - if (viewer instanceof AbstractTableViewer) - return new TableViewerUpdater((AbstractTableViewer) viewer); - throw new IllegalArgumentException( - "This content provider only works with AbstractTableViewer or AbstractListViewer"); //$NON-NLS-1$ - } - - void setInput(Object input) { - if (observableCollection != null) { - removeCollectionChangeListener(observableCollection); - observableCollection = null; - } - - if (input != null) { - checkInput(input); - Assert.isTrue(input instanceof IObservableCollection, - "Input must be an IObservableCollection"); //$NON-NLS-1$ - observableCollection = (IObservableCollection) input; - addCollectionChangeListener(observableCollection); - knownElements.addAll(observableCollection); - } - } - - /** - * Throws an exception if the input is not the correct type. - * - * @param input - * the input to check - */ - protected abstract void checkInput(Object input); - - /** - * Register for change event notification from the given collection. - * - * @param collection - * observable collection to listen to - */ - protected abstract void addCollectionChangeListener( - IObservableCollection collection); - - /** - * Deregisters from change events notification on the given collection. - * - * @param collection - * observable collection to stop listening to - */ - protected abstract void removeCollectionChangeListener( - IObservableCollection collection); - - /** - * Returns whether the viewer is disposed. Collection change listeners in - * subclasses should verify that the viewer is not disposed before sending - * any updates to the {@link ViewerUpdater viewer updater}. - * - * @return whether the viewer is disposed. - */ - protected final boolean isViewerDisposed() { - Viewer viewer = (Viewer) viewerObservable.getValue(); - return viewer == null || viewer.getControl() == null - || viewer.getControl().isDisposed(); - } - - /** - * Returns the set of elements known to this content provider. Label - * providers may track this set if they need to be notified about additions - * before the viewer sees the added element, and notified about removals - * after the element was removed from the viewer. This is intended for use - * by label providers, as it will always return the items that need labels. - * - * @return unmodifiable observable set of items that will need labels - */ - public IObservableSet getKnownElements() { - return unmodifiableKnownElements; - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ObservableCollectionTreeContentProvider.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ObservableCollectionTreeContentProvider.java deleted file mode 100644 index 37bb1c93..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ObservableCollectionTreeContentProvider.java +++ /dev/null @@ -1,398 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 207858) - * Matthew Hall - bugs 226765, 239015 - ******************************************************************************/ - -package org.eclipse.jface.internal.databinding.viewers; - -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.IObservablesListener; -import org.eclipse.core.databinding.observable.Observables; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.masterdetail.MasterDetailObservables; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.databinding.viewers.TreeStructureAdvisor; -import org.eclipse.jface.util.Util; -import org.eclipse.jface.viewers.AbstractTreeViewer; -import org.eclipse.jface.viewers.IElementComparer; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.StructuredViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.widgets.Display; - -/** - * NON-API - Abstract base class for {@link ITreeContentProvider}s which use an - * {@link IObservableFactory observable collection factory} to provide the - * elements of a tree. Each observable collection obtained from the factory is - * observed such that changes in the collection are reflected in the viewer. - * - * @since 1.2 - */ -public abstract class ObservableCollectionTreeContentProvider implements - ITreeContentProvider { - private Realm realm; - - private IObservableValue viewerObservable; - - /** - * Interfaces for sending updates to the viewer. - */ - protected TreeViewerUpdater viewerUpdater; - - /** - * Element comparer used by the viewer (may be null). - */ - protected IElementComparer comparer; - - private IObservableSet knownElements; - private IObservableSet unmodifiableKnownElements; - - private IObservableFactory /* <IObservableCollection> */collectionFactory; - - private Map /* <Object element, TreeNode node> */elementNodes; - - private TreeStructureAdvisor structureAdvisor; - - /** - * Constructs an ObservableCollectionTreeContentProvider using the given - * parent provider and collection factory. - * - * @param collectionFactory - * observable factory that produces an IObservableList of - * children for a given parent element. - * @param structureAdvisor - */ - protected ObservableCollectionTreeContentProvider( - IObservableFactory collectionFactory, - TreeStructureAdvisor structureAdvisor) { - this.structureAdvisor = structureAdvisor; - realm = SWTObservables.getRealm(Display.getDefault()); - viewerObservable = new WritableValue(realm); - viewerUpdater = null; - - // Known elements is a detail set of viewerObservable, so that when we - // get the viewer instance we can swap in a set that uses its - // IElementComparer, if any. - IObservableFactory knownElementsFactory = new IObservableFactory() { - public IObservable createObservable(Object target) { - return ObservableViewerElementSet.withComparer(realm, null, - getElementComparer((Viewer) target)); - } - }; - knownElements = MasterDetailObservables.detailSet(viewerObservable, - knownElementsFactory, null); - unmodifiableKnownElements = Observables - .unmodifiableObservableSet(knownElements); - - Assert - .isNotNull(collectionFactory, - "Collection factory cannot be null"); //$NON-NLS-1$ - this.collectionFactory = collectionFactory; - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - if (elementNodes != null && !elementNodes.isEmpty()) { - // Ensure we flush any observable collection listeners - TreeNode[] oldNodes = new TreeNode[elementNodes.size()]; - elementNodes.values().toArray(oldNodes); - for (int i = 0; i < oldNodes.length; i++) - oldNodes[i].dispose(); - elementNodes.clear(); - elementNodes = null; - } - - setViewer(viewer); - } - - private void setViewer(Viewer viewer) { - viewerUpdater = createViewerUpdater(viewer); - comparer = getElementComparer(viewer); - elementNodes = ViewerElementMap.withComparer(comparer); - viewerObservable.setValue(viewer); // (clears knownElements) - } - - private static IElementComparer getElementComparer(Viewer viewer) { - if (viewer instanceof StructuredViewer) - return ((StructuredViewer) viewer).getComparer(); - return null; - } - - private static TreeViewerUpdater createViewerUpdater(Viewer viewer) { - if (viewer instanceof AbstractTreeViewer) - return new TreeViewerUpdater((AbstractTreeViewer) viewer); - throw new IllegalArgumentException( - "This content provider only works with AbstractTreeViewer"); //$NON-NLS-1$ - } - - public Object getParent(Object element) { - if (structureAdvisor != null) { - Object parentFromAdvisor = structureAdvisor.getParent(element); - if (parentFromAdvisor != null) { - return parentFromAdvisor; - } - } - TreeNode node = getExistingNode(element); - if (node != null) - return node.getParent(); - return null; - } - - public Object[] getElements(Object input) { - return getChildren(input, true); - } - - public Object[] getChildren(Object element) { - return getChildren(element, false); - } - - private Object[] getChildren(Object element, boolean input) { - Object[] children = getOrCreateNode(element, input).getChildren(); - for (int i = 0; i < children.length; i++) - getOrCreateNode(children[i], false).addParent(element); - return children; - } - - public boolean hasChildren(Object element) { - if (structureAdvisor != null) { - Boolean hasChildren = structureAdvisor.hasChildren(element); - if (hasChildren != null) { - return hasChildren.booleanValue(); - } - } - return getOrCreateNode(element, false).hasChildren(); - } - - protected TreeNode getOrCreateNode(Object element) { - return getOrCreateNode(element, false); - } - - private TreeNode getOrCreateNode(Object element, boolean input) { - TreeNode node = getExistingNode(element); - if (node == null) { - node = new TreeNode(element); - elementNodes.put(element, node); - } - // In case the input element is also a visible node in the tree. - if (!input) - knownElements.add(element); - return node; - } - - protected TreeNode getExistingNode(Object element) { - TreeNode node = (TreeNode) elementNodes.get(element); - return node; - } - - protected boolean isViewerDisposed() { - Viewer viewer = (Viewer) viewerObservable.getValue(); - return viewer == null || viewer.getControl() == null - || viewer.getControl().isDisposed(); - } - - public void dispose() { - if (elementNodes != null) { - if (!elementNodes.isEmpty()) { - TreeNode[] nodes = new TreeNode[elementNodes.size()]; - elementNodes.values().toArray(nodes); - for (int i = 0; i < nodes.length; i++) { - nodes[i].dispose(); - } - elementNodes.clear(); - } - elementNodes = null; - } - if (viewerObservable != null) { - viewerObservable.setValue(null); - viewerObservable.dispose(); - viewerObservable = null; - } - viewerUpdater = null; - comparer = null; - knownElements = null; - unmodifiableKnownElements = null; - collectionFactory = null; - } - - /** - * Returns the set of elements known to this content provider. Label - * providers may track this set if they need to be notified about additions - * before the viewer sees the added element, and notified about removals - * after the element was removed from the viewer. This is intended for use - * by label providers, as it will always return the items that need labels. - * - * @return unmodifiable observable set of items that will need labels - */ - public IObservableSet getKnownElements() { - return unmodifiableKnownElements; - } - - /** - * Returns a listener which, when a collection change event is received, - * updates the tree viewer through the {@link #viewerUpdater} field, and - * maintains the adds and removes parents from the appropriate tree nodes. - * - * @param parentElement - * the element that is the parent element of all elements in the - * observable collection. - * @return a listener which updates the viewer when change events occur. - */ - protected abstract IObservablesListener createCollectionChangeListener( - Object parentElement); - - /** - * Registers the change listener to receive change events for the specified - * observable collection. - * - * @param collection - * the collection to observe for changes - * @param listener - * the listener that will receive collection change events. - */ - protected abstract void addCollectionChangeListener( - IObservableCollection collection, IObservablesListener listener); - - /** - * Unregisters the change listener from receving change events for the - * specified observable collection. - * - * @param collection - * the collection to stop observing. - * @param listener - * the listener to remove - */ - protected abstract void removeCollectionChangeListener( - IObservableCollection collection, IObservablesListener listener); - - protected final class TreeNode { - private Object element; - - private Object parent; - private Set parentSet; - - private IObservableCollection children; - - private IObservablesListener listener; - - TreeNode(Object element) { - Assert.isNotNull(element, "element cannot be null"); //$NON-NLS-1$ - this.element = element; - } - - Object getElement() { - return element; - } - - private boolean equal(Object left, Object right) { - if (comparer == null) - return Util.equals(left, right); - return comparer.equals(left, right); - } - - public void addParent(Object newParent) { - if (parent == null) { - parent = newParent; - } else if (!equal(parent, newParent)) { - if (parentSet == null) { - parentSet = ViewerElementSet.withComparer(comparer); - parentSet.add(parent); - } - parentSet.add(newParent); - } - } - - public void removeParent(Object oldParent) { - if (parentSet != null) - parentSet.remove(oldParent); - - if (equal(parent, oldParent)) { - if (parentSet == null || parentSet.isEmpty()) { - parent = null; - } else { - Iterator iterator = parentSet.iterator(); - parent = iterator.next(); - iterator.remove(); - } - } - - if (parentSet != null && parentSet.isEmpty()) - parentSet = null; - - if (parent == null) { - dispose(); - } - } - - private Object getParent() { - return parent; - } - - private void initChildren() { - if (children == null) { - children = (IObservableCollection) collectionFactory - .createObservable(element); - if (children == null) { - listener = null; - children = Observables.emptyObservableSet(realm); - } else { - Assert - .isTrue(Util.equals(realm, children.getRealm()), - "Children observable collection must be on the Display realm"); //$NON-NLS-1$ - listener = createCollectionChangeListener(element); - addCollectionChangeListener(children, listener); - } - } - } - - boolean hasChildren() { - initChildren(); - return !children.isEmpty(); - } - - Object[] getChildren() { - initChildren(); - return children.toArray(); - } - - private void dispose() { - if (element != null) { - elementNodes.remove(element); - knownElements.remove(element); - } - if (children != null) { - for (Iterator iterator = children.iterator(); iterator - .hasNext();) { - TreeNode child = getExistingNode(iterator.next()); - if (child != null) - child.removeParent(element); - } - if (listener != null) - removeCollectionChangeListener(children, listener); - children.dispose(); - children = null; - } - element = null; - parent = null; - if (parentSet != null) { - parentSet.clear(); - parentSet = null; - } - } - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ObservableViewerElementSet.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ObservableViewerElementSet.java deleted file mode 100644 index 2f8b1975..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ObservableViewerElementSet.java +++ /dev/null @@ -1,201 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 215531) - * Matthew Hall - bug 230267 - ******************************************************************************/ - -package org.eclipse.jface.internal.databinding.viewers; - -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.set.AbstractObservableSet; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.WritableSet; -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.viewers.IElementComparer; -import org.eclipse.jface.viewers.StructuredViewer; - -/** - * An {@link IObservableSet} of elements in a {@link StructuredViewer}. - * Elements of the set are compared using an {@link IElementComparer} instead of - * {@link #equals(Object)}. - * <p> - * This class is <i>not</i> a strict implementation the {@link IObservableSet} - * interface. It intentionally violates the {@link Set} contract, which requires - * the use of {@link #equals(Object)} when comparing elements. This class is - * designed for use with {@link StructuredViewer} which uses - * {@link IElementComparer} for element comparisons. - * - * - * @since 1.2 - */ -public class ObservableViewerElementSet extends AbstractObservableSet { - private Set wrappedSet; - private Object elementType; - private IElementComparer comparer; - - /** - * Constructs an ObservableViewerElementSet on the given {@link Realm} which - * uses the given {@link IElementComparer} to compare elements. - * - * @param realm - * the realm of the constructed set. - * @param elementType - * the element type of the constructed set. - * @param comparer - * the {@link IElementComparer} used to compare elements. - */ - public ObservableViewerElementSet(Realm realm, Object elementType, - IElementComparer comparer) { - super(realm); - - Assert.isNotNull(comparer); - this.wrappedSet = new ViewerElementSet(comparer); - this.elementType = elementType; - this.comparer = comparer; - } - - protected Set getWrappedSet() { - return wrappedSet; - } - - public Object getElementType() { - return elementType; - } - - public Iterator iterator() { - getterCalled(); - final Iterator wrappedIterator = wrappedSet.iterator(); - return new Iterator() { - Object last; - - public boolean hasNext() { - getterCalled(); - return wrappedIterator.hasNext(); - } - - public Object next() { - getterCalled(); - return last = wrappedIterator.next(); - } - - public void remove() { - getterCalled(); - wrappedIterator.remove(); - fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, - Collections.singleton(last))); - } - }; - } - - public boolean add(Object o) { - getterCalled(); - boolean changed = wrappedSet.add(o); - if (changed) - fireSetChange(Diffs.createSetDiff(Collections.singleton(o), - Collections.EMPTY_SET)); - return changed; - } - - public boolean addAll(Collection c) { - getterCalled(); - Set additions = new ViewerElementSet(comparer); - for (Iterator iterator = c.iterator(); iterator.hasNext();) { - Object element = iterator.next(); - if (wrappedSet.add(element)) - additions.add(element); - } - boolean changed = !additions.isEmpty(); - if (changed) - fireSetChange(Diffs.createSetDiff(additions, Collections.EMPTY_SET)); - return changed; - } - - public boolean remove(Object o) { - getterCalled(); - boolean changed = wrappedSet.remove(o); - if (changed) - fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, - Collections.singleton(o))); - return changed; - } - - public boolean removeAll(Collection c) { - getterCalled(); - Set removals = new ViewerElementSet(comparer); - for (Iterator iterator = c.iterator(); iterator.hasNext();) { - Object element = iterator.next(); - if (wrappedSet.remove(element)) - removals.add(element); - } - boolean changed = !removals.isEmpty(); - if (changed) - fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, removals)); - return changed; - } - - public boolean retainAll(Collection c) { - getterCalled(); - Set removals = new ViewerElementSet(comparer); - Object[] toRetain = c.toArray(); - outer: for (Iterator iterator = wrappedSet.iterator(); iterator - .hasNext();) { - Object element = iterator.next(); - // Cannot rely on c.contains(element) because we must compare - // elements using IElementComparer. - for (int i = 0; i < toRetain.length; i++) { - if (comparer.equals(element, toRetain[i])) - continue outer; - } - iterator.remove(); - removals.add(element); - } - boolean changed = !removals.isEmpty(); - if (changed) - fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, removals)); - return changed; - } - - public void clear() { - getterCalled(); - if (!wrappedSet.isEmpty()) { - Set removals = wrappedSet; - wrappedSet = new ViewerElementSet(comparer); - fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, removals)); - } - } - - /** - * Returns an {@link IObservableSet} for holding viewer elements, using the - * given {@link IElementComparer} for comparisons. - * - * @param realm - * the realm of the returned observable - * @param elementType - * the element type of the returned set - * @param comparer - * the element comparer to use in element comparisons (may be - * null). If null, the returned set will compare elements - * according to the standard contract for {@link Set} interface - * contract. - * @return a Set for holding viewer elements, using the given - * {@link IElementComparer} for comparisons. - */ - public static IObservableSet withComparer(Realm realm, Object elementType, - IElementComparer comparer) { - if (comparer == null) - return new WritableSet(realm, Collections.EMPTY_SET, elementType); - return new ObservableViewerElementSet(realm, elementType, comparer); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/SelectionProviderMultipleSelectionObservableList.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/SelectionProviderMultipleSelectionObservableList.java deleted file mode 100644 index d067ed97..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/SelectionProviderMultipleSelectionObservableList.java +++ /dev/null @@ -1,111 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Peter Centgraf 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: - * Peter Centgraf - initial API and implementation, bug 124683 - * Boris Bokowski, IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.internal.databinding.viewers; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.ListDiff; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; - -/** - * Observes multiple-selection of an {@link ISelectionProvider}. - * - * @since 1.2 - */ -public class SelectionProviderMultipleSelectionObservableList extends - WritableList { - - protected ISelectionProvider selectionProvider; - protected boolean handlingSelection; - protected boolean updating; - protected SelectionListener selectionListener = new SelectionListener(); - - class SelectionListener implements ISelectionChangedListener { - public void selectionChanged(SelectionChangedEvent event) { - if (updating) { - return; - } - handlingSelection = true; - try { - updateWrappedList(new ArrayList(getSelectionList(event.getSelection()))); - } finally { - handlingSelection = false; - } - } - } - - /** - * Create a new observable list based on the current selection of the given - * selection provider. Assumes that the selection provider provides - * structured selections. - * - * @param realm - * @param selectionProvider - * @param elementType - */ - public SelectionProviderMultipleSelectionObservableList(Realm realm, - ISelectionProvider selectionProvider, Object elementType) { - super(realm, new ArrayList(getSelectionList(selectionProvider)), elementType); - this.selectionProvider = selectionProvider; - selectionProvider.addSelectionChangedListener(selectionListener); - } - - protected void fireListChange(ListDiff diff) { - if (handlingSelection) { - super.fireListChange(diff); - } else { - // this is a bit of a hack - we are changing the diff to match the order - // of elements returned by the selection provider after we've set the - // selection. - updating = true; - try { - List oldList = getSelectionList(selectionProvider); - selectionProvider - .setSelection(new StructuredSelection(wrappedList)); - wrappedList = new ArrayList(getSelectionList(selectionProvider)); - super.fireListChange(Diffs.computeListDiff(oldList, wrappedList)); - } finally { - updating = false; - } - } - } - - protected static List getSelectionList(ISelectionProvider selectionProvider) { - if (selectionProvider == null) { - throw new IllegalArgumentException(); - } - return getSelectionList(selectionProvider.getSelection()); - } - - protected static List getSelectionList(ISelection sel) { - if (sel instanceof IStructuredSelection) { - return ((IStructuredSelection) sel).toList(); - } - return Collections.EMPTY_LIST; - } - - public synchronized void dispose() { - selectionProvider.removeSelectionChangedListener(selectionListener); - selectionProvider = null; - super.dispose(); - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/SelectionProviderSingleSelectionObservableValue.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/SelectionProviderSingleSelectionObservableValue.java deleted file mode 100644 index 4ecc6b5a..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/SelectionProviderSingleSelectionObservableValue.java +++ /dev/null @@ -1,147 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 137877 - * Brad Reynolds - bug 164653 - * Brad Reynolds - bug 147515 - * Ashley Cambrell - bug 198906 - *******************************************************************************/ - -package org.eclipse.jface.internal.databinding.viewers; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.AbstractObservableValue; -import org.eclipse.jface.util.Util; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; - -/** - * Observes single selection of an <code>ISelectionProvider</code>. - * - * @since 1.1 - */ -public class SelectionProviderSingleSelectionObservableValue extends - AbstractObservableValue { - - private final ISelectionProvider selectionProvider; - - private boolean updating = false; - - private Object currentSelection; - - private ISelectionChangedListener selectionChangedListener; - - /** - * Constructs a new instance associated with the provided - * <code>selectionProvider</code>. In order to initialize itself properly - * the constructor invokes {@link #doGetValue()}. This could be dangerous - * for subclasses, see {@link #doGetValue()} for an explanation. - * - * @param realm - * - * @param selectionProvider - * @see #doGetValue() - */ - public SelectionProviderSingleSelectionObservableValue(Realm realm, - ISelectionProvider selectionProvider) { - super(realm); - if (selectionProvider == null) { - throw new IllegalArgumentException( - "The 'selectionProvider' parameter is null."); //$NON-NLS-1$ - } - - this.selectionProvider = selectionProvider; - this.currentSelection = doGetValue(); - - selectionChangedListener = new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - if (!updating) { - Object oldSelection = currentSelection; - currentSelection = doGetValue(); - fireValueChange(Diffs.createValueDiff(oldSelection, - currentSelection)); - } - } - }; - selectionProvider.addSelectionChangedListener(selectionChangedListener); - } - - /** - * Sets the selection to the provided <code>value</code>. Value change - * events are fired after selection is set in the selection provider. - * - * @param value - * object to set as selected, <code>null</code> if wanting to - * remove selection - */ - public void doSetValue(final Object value) { - try { - updating = true; - - Object oldSelection = currentSelection; - selectionProvider - .setSelection(value == null ? StructuredSelection.EMPTY - : new StructuredSelection(value)); - currentSelection = doGetValue(); - if (!Util.equals(oldSelection, currentSelection)) { - fireValueChange(Diffs.createValueDiff(oldSelection, - currentSelection)); - } - } finally { - updating = false; - } - } - - /** - * Retrieves the current selection. - * <p> - * If a subclass overrides this method it must not depend upon the subclass - * to have been fully initialized before this method is invoked. - * <code>doGetValue()</code> is invoked by the - * {@link #SelectionProviderSingleSelectionObservableValue(Realm, ISelectionProvider) constructor} - * which means the subclass's constructor will not have fully executed - * before this method is invoked. - * </p> - * - * @return selection will be an instance of - * <code>IStructuredSelection</code> if a selection exists, - * <code>null</code> if no selection - * @see #SelectionProviderSingleSelectionObservableValue(Realm, - * ISelectionProvider) - */ - protected Object doGetValue() { - ISelection selection = selectionProvider.getSelection(); - if (selection instanceof IStructuredSelection) { - IStructuredSelection sel = (IStructuredSelection) selection; - return sel.getFirstElement(); - } - - return null; - } - - public Object getValueType() { - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose() - */ - public synchronized void dispose() { - selectionProvider - .removeSelectionChangedListener(selectionChangedListener); - super.dispose(); - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/TableViewerUpdater.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/TableViewerUpdater.java deleted file mode 100644 index ebc08f50..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/TableViewerUpdater.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 215531) - * Matthew Hall - bug 226765 - ******************************************************************************/ - -package org.eclipse.jface.internal.databinding.viewers; - -import org.eclipse.jface.viewers.AbstractTableViewer; - -/** - * NON-API - A {@link ViewerUpdater} that updates {@link AbstractTableViewer} - * instances. - * - * @since 1.2 - */ -class TableViewerUpdater extends ViewerUpdater { - private AbstractTableViewer viewer; - - TableViewerUpdater(AbstractTableViewer viewer) { - super(viewer); - this.viewer = viewer; - } - - public void insert(Object element, int position) { - viewer.insert(element, position); - } - - public void remove(Object element, int position) { - viewer.remove(element); - } - - public void replace(Object oldElement, Object newElement, int position) { - if (viewer.getComparator() == null && viewer.getFilters().length == 0) - viewer.replace(newElement, position); - else { - super.replace(oldElement, newElement, position); - } - } - - public void add(Object[] elements) { - viewer.add(elements); - } - - public void remove(Object[] elements) { - viewer.remove(elements); - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/TreeViewerUpdater.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/TreeViewerUpdater.java deleted file mode 100644 index f206fdf9..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/TreeViewerUpdater.java +++ /dev/null @@ -1,176 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 207858) - * Matthew Hall - bug 226765 - ******************************************************************************/ - -package org.eclipse.jface.internal.databinding.viewers; - -import org.eclipse.jface.util.Util; -import org.eclipse.jface.viewers.AbstractTreeViewer; -import org.eclipse.jface.viewers.IElementComparer; -import org.eclipse.jface.viewers.ITreeSelection; -import org.eclipse.jface.viewers.TreePath; -import org.eclipse.jface.viewers.TreeViewer; - -/** - * NON-API - An interface for sending updates to an {@link AbstractTreeViewer}. - * - * @since 1.2 - */ -public class TreeViewerUpdater { - private final AbstractTreeViewer viewer; - private final TreeViewer treeViewer; - - /** - * Constructs an ITreeViewerUpdater for updating the given viewer. - * - * @param viewer - * the viewer that will be updated - */ - public TreeViewerUpdater(AbstractTreeViewer viewer) { - this.viewer = viewer; - if (viewer instanceof TreeViewer) - treeViewer = (TreeViewer) viewer; - else - treeViewer = null; - } - - /** - * Insert the element into the viewer as a child of the specified parent - * element, at the specified position. - * - * @param parent - * the parent of the element being inserted - * @param element - * the element to insert - * @param position - * the position where the element is inserted - */ - public void insert(Object parent, Object element, int position) { - viewer.insert(parent, element, position); - } - - /** - * Replaces the specified element whenever it appears as a child of the - * specified parent element, at the given position with the new element. - * - * @param parent - * the parent of the element being replaced - * @param oldElement - * the element being replaced - * @param newElement - * the element that replaces <code>oldElement</code> - * @param position - * the position of the element being replaced. - */ - public void replace(Object parent, Object oldElement, Object newElement, - int position) { - if (treeViewer != null && viewer.getComparator() == null - && viewer.getFilters().length == 0) { - treeViewer.replace(parent, position, newElement); - } else { - remove(parent, oldElement, position); - insert(parent, newElement, position); - } - } - - /** - * Moves the specified element from the specified old position to the - * specified new position, whenever it appears as a child of the specified - * parent element. No action is taken if the viewer has a sorter or - * filter(s). - * - * @param parent - * the parent of the element being moved - * @param element - * the element being moved - * @param oldPosition - * the position of the element before it is moved - * @param newPosition - * the position of the element after it is moved - */ - public void move(Object parent, Object element, int oldPosition, - int newPosition) { - if (viewer.getComparator() == null && viewer.getFilters().length == 0) { - - ITreeSelection selection = (ITreeSelection) viewer.getSelection(); - - remove(parent, element, oldPosition); - insert(parent, element, newPosition); - - // Preserve selection - if (!selection.isEmpty()) { - // If the moved element is selected (or an ancestor of a - // selected element), restore the selection. - IElementComparer comparer = viewer.getComparer(); - TreePath[] paths = selection.getPaths(); - outer: for (int i = 0; i < paths.length; i++) { - TreePath path = paths[i]; - for (int j = 0; j < path.getSegmentCount(); j++) { - Object pathElement = path.getSegment(j); - if (comparer == null ? Util - .equals(element, pathElement) : comparer - .equals(element, pathElement)) { - viewer.setSelection(selection); - break outer; - } - } - } - } - } - } - - /** - * Removes the element from the from whenever it appears as a child of the - * specified parent element, at the specified position. - * - * @param parent - * the parent of the element being removed - * @param element - * the element to remove - * @param position - * the position where the element is located - */ - public void remove(Object parent, Object element, int position) { - if (treeViewer != null && viewer.getComparator() == null - && viewer.getFilters().length == 0) { - // Only TreeViewer has a remove-by-index method. - treeViewer.remove(parent, position); - } else { - viewer.remove(parent, new Object[] { element }); - } - } - - /** - * Add the elements into the viewer as children of the specified parent - * element. - * - * @param parent - * the parent of the element being inserted - * @param elements - * the elements to insert - */ - public void add(Object parent, Object[] elements) { - viewer.add(parent, elements); - } - - /** - * Remove the elements from the viewer wherever they appear as children of - * the specified parent element. - * - * @param parent - * the parent of the elements being removed - * @param elements - * the elements to remove - */ - public void remove(Object parent, Object[] elements) { - viewer.remove(parent, elements); - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ViewerElementMap.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ViewerElementMap.java deleted file mode 100644 index 6a8a03b6..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ViewerElementMap.java +++ /dev/null @@ -1,432 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 215531) - * Matthew Hall - bug 228125 - ******************************************************************************/ - -package org.eclipse.jface.internal.databinding.viewers; - -import java.lang.reflect.Array; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.util.Util; -import org.eclipse.jface.viewers.IElementComparer; -import org.eclipse.jface.viewers.StructuredViewer; - -/** - * A {@link Map} whose keys are elements in a {@link StructuredViewer}. The - * keys in the map are compared using an {@link IElementComparer} instead of - * {@link #equals(Object)}. - * <p> - * This class is <i>not</i> a strict implementation the {@link Map} interface. - * It intentionally violates the {@link Map} contract, which requires the use of - * {@link #equals(Object)} when comparing keys. This class is designed for use - * with {@link StructuredViewer} which uses {@link IElementComparer} for element - * comparisons. - * - * @since 1.2 - */ -public class ViewerElementMap implements Map { - private Map wrappedMap; - private IElementComparer comparer; - - /** - * Constructs a ViewerElementMap using the given {@link IElementComparer}. - * - * @param comparer - * the {@link IElementComparer} used for comparing keys. - */ - public ViewerElementMap(IElementComparer comparer) { - Assert.isNotNull(comparer); - this.wrappedMap = new HashMap(); - this.comparer = comparer; - } - - /** - * Constructs a ViewerElementMap containing all the entries in the specified - * map. - * - * @param map - * the map whose entries are to be added to this map. - * @param comparer - * the {@link IElementComparer} used for comparing keys. - */ - public ViewerElementMap(Map map, IElementComparer comparer) { - this(comparer); - Assert.isNotNull(map); - putAll(map); - } - - public void clear() { - wrappedMap.clear(); - } - - public boolean containsKey(Object key) { - return wrappedMap.containsKey(new ViewerElementWrapper(key, comparer)); - } - - public boolean containsValue(Object value) { - return wrappedMap.containsValue(value); - } - - public Set entrySet() { - final Set wrappedEntrySet = wrappedMap.entrySet(); - return new Set() { - public boolean add(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - wrappedEntrySet.clear(); - } - - public boolean contains(Object o) { - for (Iterator iterator = iterator(); iterator.hasNext();) - if (iterator.next().equals(o)) - return true; - return false; - } - - public boolean containsAll(Collection c) { - for (Iterator iterator = c.iterator(); iterator.hasNext();) - if (!contains(iterator.next())) - return false; - return true; - } - - public boolean isEmpty() { - return wrappedEntrySet.isEmpty(); - } - - public Iterator iterator() { - final Iterator wrappedIterator = wrappedEntrySet.iterator(); - return new Iterator() { - public boolean hasNext() { - return wrappedIterator.hasNext(); - } - - public Object next() { - final Map.Entry wrappedEntry = (Map.Entry) wrappedIterator - .next(); - return new Map.Entry() { - public Object getKey() { - return ((ViewerElementWrapper) wrappedEntry.getKey()) - .unwrap(); - } - - public Object getValue() { - return wrappedEntry.getValue(); - } - - public Object setValue(Object value) { - return wrappedEntry.setValue(value); - } - - public boolean equals(Object obj) { - if (obj == this) - return true; - if (obj == null || !(obj instanceof Map.Entry)) - return false; - Map.Entry that = (Map.Entry) obj; - return comparer.equals(this.getKey(), that - .getKey()) - && Util.equals(this.getValue(), that - .getValue()); - } - - public int hashCode() { - return wrappedEntry.hashCode(); - } - }; - } - - public void remove() { - wrappedIterator.remove(); - } - }; - } - - public boolean remove(Object o) { - final Map.Entry unwrappedEntry = (Map.Entry) o; - final ViewerElementWrapper wrappedKey = new ViewerElementWrapper( - unwrappedEntry.getKey(), comparer); - Map.Entry wrappedEntry = new Map.Entry() { - public Object getKey() { - return wrappedKey; - } - - public Object getValue() { - return unwrappedEntry.getValue(); - } - - public Object setValue(Object value) { - throw new UnsupportedOperationException(); - } - - public boolean equals(Object obj) { - if (obj == this) - return true; - if (obj == null || !(obj instanceof Map.Entry)) - return false; - Map.Entry that = (Map.Entry) obj; - return Util.equals(wrappedKey, that.getKey()) - && Util - .equals(this.getValue(), that - .getValue()); - } - - public int hashCode() { - return wrappedKey.hashCode() - ^ (getValue() == null ? 0 : getValue() - .hashCode()); - } - }; - return wrappedEntrySet.remove(wrappedEntry); - } - - public boolean removeAll(Collection c) { - boolean changed = false; - for (Iterator iterator = c.iterator(); iterator.hasNext();) - changed |= remove(iterator.next()); - return changed; - } - - public boolean retainAll(Collection c) { - boolean changed = false; - Object[] toRetain = c.toArray(); - outer: for (Iterator iterator = iterator(); iterator.hasNext();) { - Object entry = iterator.next(); - for (int i = 0; i < toRetain.length; i++) - if (entry.equals(toRetain[i])) - continue outer; - iterator.remove(); - changed = true; - } - return changed; - } - - public int size() { - return wrappedEntrySet.size(); - } - - public Object[] toArray() { - return toArray(new Object[size()]); - } - - public Object[] toArray(Object[] a) { - int size = size(); - if (a.length < size) { - a = (Object[]) Array.newInstance(a.getClass() - .getComponentType(), size); - } - int i = 0; - for (Iterator iterator = iterator(); iterator.hasNext();) { - a[i] = iterator.next(); - i++; - } - return a; - } - - public boolean equals(Object obj) { - if (obj == this) - return true; - if (obj == null || !(obj instanceof Set)) - return false; - Set that = (Set) obj; - return this.size() == that.size() && containsAll(that); - } - - public int hashCode() { - return wrappedEntrySet.hashCode(); - } - }; - } - - public Object get(Object key) { - return wrappedMap.get(new ViewerElementWrapper(key, comparer)); - } - - public boolean isEmpty() { - return wrappedMap.isEmpty(); - } - - public Set keySet() { - final Set wrappedKeySet = wrappedMap.keySet(); - return new Set() { - public boolean add(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - wrappedKeySet.clear(); - } - - public boolean contains(Object o) { - return wrappedKeySet.contains(new ViewerElementWrapper(o, comparer)); - } - - public boolean containsAll(Collection c) { - for (Iterator iterator = c.iterator(); iterator.hasNext();) - if (!wrappedKeySet.contains(new ViewerElementWrapper(iterator.next(), comparer))) - return false; - return true; - } - - public boolean isEmpty() { - return wrappedKeySet.isEmpty(); - } - - public Iterator iterator() { - final Iterator wrappedIterator = wrappedKeySet.iterator(); - return new Iterator() { - public boolean hasNext() { - return wrappedIterator.hasNext(); - } - - public Object next() { - return ((ViewerElementWrapper) wrappedIterator.next()).unwrap(); - } - - public void remove() { - wrappedIterator.remove(); - } - }; - } - - public boolean remove(Object o) { - return wrappedKeySet.remove(new ViewerElementWrapper(o, comparer)); - } - - public boolean removeAll(Collection c) { - boolean changed = false; - for (Iterator iterator = c.iterator(); iterator.hasNext();) - changed |= wrappedKeySet - .remove(new ViewerElementWrapper(iterator.next(), comparer)); - return changed; - } - - public boolean retainAll(Collection c) { - boolean changed = false; - Object[] toRetain = c.toArray(); - outer: for (Iterator iterator = iterator(); iterator.hasNext();) { - Object element = iterator.next(); - for (int i = 0; i < toRetain.length; i++) - if (comparer.equals(element, toRetain[i])) - continue outer; - // element not contained in collection, remove. - remove(element); - changed = true; - } - return changed; - } - - public int size() { - return wrappedKeySet.size(); - } - - public Object[] toArray() { - return toArray(new Object[wrappedKeySet.size()]); - } - - public Object[] toArray(Object[] a) { - int size = wrappedKeySet.size(); - ViewerElementWrapper[] wrappedArray = (ViewerElementWrapper[]) wrappedKeySet - .toArray(new ViewerElementWrapper[size]); - Object[] result = a; - if (a.length < size) { - result = (Object[]) Array.newInstance(a.getClass() - .getComponentType(), size); - } - for (int i = 0; i < size; i++) - result[i] = wrappedArray[i].unwrap(); - return result; - } - - public boolean equals(Object obj) { - if (obj == this) - return true; - if (obj == null || !(obj instanceof Set)) - return false; - Set that = (Set) obj; - return this.size() == that.size() && containsAll(that); - } - - public int hashCode() { - return wrappedKeySet.hashCode(); - } - }; - } - - public Object put(Object key, Object value) { - return wrappedMap.put(new ViewerElementWrapper(key, comparer), value); - } - - public void putAll(Map other) { - for (Iterator iterator = other.entrySet().iterator(); iterator - .hasNext();) { - Map.Entry entry = (Map.Entry) iterator.next(); - wrappedMap.put(new ViewerElementWrapper(entry.getKey(), comparer), entry.getValue()); - } - } - - public Object remove(Object key) { - return wrappedMap.remove(new ViewerElementWrapper(key, comparer)); - } - - public int size() { - return wrappedMap.size(); - } - - public Collection values() { - return wrappedMap.values(); - } - - public boolean equals(Object obj) { - if (obj == this) - return true; - if (obj == null || !(obj instanceof Map)) - return false; - Map that = (Map) obj; - return this.entrySet().equals(that.entrySet()); - } - - public int hashCode() { - return wrappedMap.hashCode(); - } - - /** - * Returns a Map for mapping viewer elements as keys to values, using the - * given {@link IElementComparer} for key comparisons. - * - * @param comparer - * the element comparer to use in key comparisons. If null, the - * returned map will compare keys according to the standard - * contract for {@link Map} interface contract. - * @return a Map for mapping viewer elements as keys to values, using the - * given {@link IElementComparer} for key comparisons. - */ - public static Map withComparer(IElementComparer comparer) { - if (comparer == null) - return new HashMap(); - return new ViewerElementMap(comparer); - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ViewerElementSet.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ViewerElementSet.java deleted file mode 100644 index b9a0b1e2..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ViewerElementSet.java +++ /dev/null @@ -1,203 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 215531) - * Matthew Hall - bug 124684 - ******************************************************************************/ - -package org.eclipse.jface.internal.databinding.viewers; - -import java.lang.reflect.Array; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.viewers.IElementComparer; -import org.eclipse.jface.viewers.StructuredViewer; - -/** - * A {@link Set} of elements in a {@link StructuredViewer}. Elements of the set - * are compared using an {@link IElementComparer} instead of - * {@link #equals(Object)}. - * <p> - * This class is <i>not</i> a strict implementation the {@link Set} interface. - * It intentionally violates the {@link Set} contract, which requires the use of - * {@link #equals(Object)} when comparing elements. This class is designed for - * use with {@link StructuredViewer} which uses {@link IElementComparer} for - * element comparisons. - * - * @since 1.2 - */ -public class ViewerElementSet implements Set { - private final Set wrappedSet; - private final IElementComparer comparer; - - /** - * Constructs a ViewerElementSet using the given {@link IElementComparer}. - * - * @param comparer - * the {@link IElementComparer} used for comparing elements. - */ - public ViewerElementSet(IElementComparer comparer) { - Assert.isNotNull(comparer); - this.wrappedSet = new HashSet(); - this.comparer = comparer; - } - - /** - * Constructs a ViewerElementSet containing all the elements in the - * specified collection. - * - * @param collection - * the collection whose elements are to be added to this set. - * @param comparer - * the {@link IElementComparer} used for comparing elements. - */ - public ViewerElementSet(Collection collection, IElementComparer comparer) { - this(comparer); - addAll(collection); - } - - public boolean add(Object o) { - return wrappedSet.add(new ViewerElementWrapper(o, comparer)); - } - - public boolean addAll(Collection c) { - boolean changed = false; - for (Iterator iterator = c.iterator(); iterator.hasNext();) - changed |= wrappedSet.add(new ViewerElementWrapper(iterator.next(), - comparer)); - return changed; - } - - public void clear() { - wrappedSet.clear(); - } - - public boolean contains(Object o) { - return wrappedSet.contains(new ViewerElementWrapper(o, comparer)); - } - - public boolean containsAll(Collection c) { - for (Iterator iterator = c.iterator(); iterator.hasNext();) - if (!wrappedSet.contains(new ViewerElementWrapper(iterator.next(), - comparer))) - return false; - return true; - } - - public boolean isEmpty() { - return wrappedSet.isEmpty(); - } - - public Iterator iterator() { - final Iterator wrappedIterator = wrappedSet.iterator(); - return new Iterator() { - public boolean hasNext() { - return wrappedIterator.hasNext(); - } - - public Object next() { - return ((ViewerElementWrapper) wrappedIterator.next()).unwrap(); - } - - public void remove() { - wrappedIterator.remove(); - } - }; - } - - public boolean remove(Object o) { - return wrappedSet.remove(new ViewerElementWrapper(o, comparer)); - } - - public boolean removeAll(Collection c) { - boolean changed = false; - for (Iterator iterator = c.iterator(); iterator.hasNext();) - changed |= remove(iterator.next()); - return changed; - } - - public boolean retainAll(Collection c) { - // Have to do this the slow way to ensure correct comparisons. i.e. - // cannot delegate to c.contains(it) since we can't be sure will - // compare elements the way we want. - boolean changed = false; - Object[] retainAll = c.toArray(); - outer: for (Iterator iterator = iterator(); iterator.hasNext();) { - Object element = iterator.next(); - for (int i = 0; i < retainAll.length; i++) { - if (comparer.equals(element, retainAll[i])) { - continue outer; - } - } - iterator.remove(); - changed = true; - } - return changed; - } - - public int size() { - return wrappedSet.size(); - } - - public Object[] toArray() { - return toArray(new Object[wrappedSet.size()]); - } - - public Object[] toArray(Object[] a) { - int size = wrappedSet.size(); - ViewerElementWrapper[] wrappedArray = (ViewerElementWrapper[]) wrappedSet - .toArray(new ViewerElementWrapper[size]); - Object[] result = a; - if (a.length < size) { - result = (Object[]) Array.newInstance(a.getClass() - .getComponentType(), size); - } - for (int i = 0; i < size; i++) - result[i] = wrappedArray[i].unwrap(); - return result; - } - - public boolean equals(Object obj) { - if (obj == this) - return true; - if (!(obj instanceof Set)) - return false; - Set that = (Set) obj; - return size() == that.size() && containsAll(that); - } - - public int hashCode() { - int hash = 0; - for (Iterator iterator = iterator(); iterator.hasNext();) { - Object element = iterator.next(); - hash += element == null ? 0 : element.hashCode(); - } - return hash; - } - - /** - * Returns a Set for holding viewer elements, using the given - * {@link IElementComparer} for comparisons. - * - * @param comparer - * the element comparer to use in element comparisons. If null, - * the returned set will compare elements according to the - * standard contract for {@link Set} interface contract. - * @return a Set for holding viewer elements, using the given - * {@link IElementComparer} for comparisons. - */ - public static Set withComparer(IElementComparer comparer) { - if (comparer == null) - return new HashSet(); - return new ViewerElementSet(comparer); - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ViewerElementWrapper.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ViewerElementWrapper.java deleted file mode 100644 index c2645aea..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ViewerElementWrapper.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 215531) - ******************************************************************************/ - -package org.eclipse.jface.internal.databinding.viewers; - -import org.eclipse.jface.viewers.IElementComparer; - -/** - * A wrapper class for viewer elements, which uses an {@link IElementComparer} - * for computing {@link Object#equals(Object) equality} and - * {@link Object#hashCode() hashes}. - * - * @since 1.2 - */ -public class ViewerElementWrapper { - private final Object element; - private final IElementComparer comparer; - - /** - * Constructs a ViewerElementWrapper wrapping the given element - * - * @param element - * the element being wrapped - * @param comparer - * the comparer to use for computing equality and hash codes. - */ - public ViewerElementWrapper(Object element, IElementComparer comparer) { - if (comparer == null) - throw new NullPointerException(); - this.element = element; - this.comparer = comparer; - } - - public boolean equals(Object obj) { - if (!(obj instanceof ViewerElementWrapper)) { - return false; - } - return comparer.equals(element, ((ViewerElementWrapper) obj).element); - } - - public int hashCode() { - return comparer.hashCode(element); - } - - Object unwrap() { - return element; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ViewerInputObservableValue.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ViewerInputObservableValue.java deleted file mode 100644 index 1a9ee02c..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ViewerInputObservableValue.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 206839) - *******************************************************************************/ - -package org.eclipse.jface.internal.databinding.viewers; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.AbstractObservableValue; -import org.eclipse.jface.util.Util; -import org.eclipse.jface.viewers.Viewer; - -/** - * Observes the input of a <code>Viewer</code>. - * <p> - * This observer is blind to changes in the viewer's input unless its - * {@link #setValue(Object)} method is called directly. - * - * @since 1.2 - */ -public class ViewerInputObservableValue extends AbstractObservableValue { - - private final Viewer viewer; - - /** - * Constructs a new instance associated with the provided <code>viewer</code>. - * - * @param realm - * @param viewer - */ - public ViewerInputObservableValue( Realm realm, Viewer viewer ) { - super( realm ); - if ( viewer == null ) { - throw new IllegalArgumentException( "The 'viewer' parameter is null." ); //$NON-NLS-1$ - } - - this.viewer = viewer; - } - - /** - * Sets the input to the provided <code>value</code>. Value change events are - * fired after input is set in the viewer. - * - * @param value object to set as input - */ - protected void doSetValue( final Object value ) { - Object oldValue = doGetValue(); - viewer.setInput( value ); - if ( !Util.equals( oldValue, value ) ) { - fireValueChange( Diffs.createValueDiff( oldValue, value ) ); - } - } - - /** - * Retrieves the current input. - * - * @return the current input - */ - protected Object doGetValue() { - return viewer.getInput(); - } - - public Object getValueType() { - return null; - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ViewerMultipleSelectionObservableList.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ViewerMultipleSelectionObservableList.java deleted file mode 100644 index 2dafff2c..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ViewerMultipleSelectionObservableList.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 137877 - * Brad Reynolds - bug 164653 - * Brad Reynolds - bug 147515 - * Ashley Cambrell - bug 198906 - *******************************************************************************/ - -package org.eclipse.jface.internal.databinding.viewers; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.jface.databinding.viewers.IViewerObservableList; -import org.eclipse.jface.viewers.Viewer; - -/** - * Observes single selection of a <code>Viewer</code>. - * - * @since 1.2 - */ -public class ViewerMultipleSelectionObservableList extends - SelectionProviderMultipleSelectionObservableList implements - IViewerObservableList { - - private Viewer viewer; - - /** - * @param realm - * @param viewer - * @param elementType - */ - public ViewerMultipleSelectionObservableList(Realm realm, Viewer viewer, - Object elementType) { - super(realm, viewer, elementType); - this.viewer = viewer; - } - - public Viewer getViewer() { - return viewer; - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ViewerSingleSelectionObservableValue.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ViewerSingleSelectionObservableValue.java deleted file mode 100644 index 648e369b..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ViewerSingleSelectionObservableValue.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 137877 - * Brad Reynolds - bug 164653 - * Brad Reynolds - bug 147515 - * Ashley Cambrell - bug 198906 - *******************************************************************************/ - -package org.eclipse.jface.internal.databinding.viewers; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.jface.databinding.viewers.IViewerObservableValue; -import org.eclipse.jface.viewers.Viewer; - -/** - * Observes single selection of a <code>Viewer</code>. - * - * @since 1.2 - */ -public class ViewerSingleSelectionObservableValue extends - SelectionProviderSingleSelectionObservableValue implements - IViewerObservableValue { - - private Viewer viewer; - - /** - * @param realm - * @param viewer - */ - public ViewerSingleSelectionObservableValue(Realm realm, Viewer viewer) { - super(realm, viewer); - this.viewer = viewer; - } - - public Viewer getViewer() { - return viewer; - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ViewerUpdater.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ViewerUpdater.java deleted file mode 100644 index 0977ae2e..00000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ViewerUpdater.java +++ /dev/null @@ -1,123 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 226765) - ******************************************************************************/ - -package org.eclipse.jface.internal.databinding.viewers; - -import org.eclipse.jface.util.Util; -import org.eclipse.jface.viewers.IElementComparer; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredViewer; - -/** - * NON-API - An interface for updating a viewer's elements. - * - * @since 1.2 - */ -public abstract class ViewerUpdater { - private final StructuredViewer viewer; - - /** - * Constructs a ViewerUpdater for updating the specified viewer. - * - * @param viewer - * the viewer which will be updated through this instance. - */ - protected ViewerUpdater(StructuredViewer viewer) { - this.viewer = viewer; - } - - /** - * Insert the element into the viewer at the specified position. - * - * @param element - * the element to add - * @param position - * the position of the element - */ - public abstract void insert(Object element, int position); - - /** - * Remove the element from the viewer - * - * @param element - * the element to remove - * @param position - * the position of the element - */ - public abstract void remove(Object element, int position); - - /** - * Replace the specified element at the given position with the new element. - * - * @param oldElement - * the element being replaced - * @param newElement - * the element that replaces <code>oldElement</code> - * @param position - * the position of the element being replaced. - */ - public void replace(Object oldElement, Object newElement, int position) { - remove(oldElement, position); - insert(newElement, position); - } - - /** - * Moves the specified element from the specified old position to the - * specified new position. No action is taken if the viewer has a sorter or - * filter(s). - * - * @param element - * the element being moved - * @param oldPosition - * the position of the element before it is moved - * @param newPosition - * the position of the element after it is moved - */ - public void move(Object element, int oldPosition, int newPosition) { - if (viewer.getComparator() == null && viewer.getFilters().length == 0) { - IStructuredSelection selection = (IStructuredSelection) viewer - .getSelection(); - - remove(element, oldPosition); - insert(element, newPosition); - - // Preserve selection - if (!selection.isEmpty()) { - IElementComparer comparer = viewer.getComparer(); - Object[] selectedElements = selection.toArray(); - for (int i = 0; i < selectedElements.length; i++) { - if (comparer == null ? Util.equals(element, - selectedElements[i]) : comparer.equals(element, - selectedElements[i])) { - viewer.setSelection(selection); - break; - } - } - } - } - } - - /** - * Adds the elements to the viewer. - * - * @param elements - * the elements to add - */ - public abstract void add(Object[] elements); - - /** - * Removes the elements from the viewer - * - * @param elements - * the elements to remove - */ - public abstract void remove(Object[] elements); -} diff --git a/examples/org.eclipse.jface.examples.databinding/.classpath b/examples/org.eclipse.jface.examples.databinding/.classpath deleted file mode 100644 index ce739334..00000000 --- a/examples/org.eclipse.jface.examples.databinding/.classpath +++ /dev/null @@ -1,7 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" path="src"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/> - <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> - <classpathentry kind="output" path="bin"/> -</classpath> diff --git a/examples/org.eclipse.jface.examples.databinding/.cvsignore b/examples/org.eclipse.jface.examples.databinding/.cvsignore deleted file mode 100644 index ba077a40..00000000 --- a/examples/org.eclipse.jface.examples.databinding/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -bin diff --git a/examples/org.eclipse.jface.examples.databinding/.project b/examples/org.eclipse.jface.examples.databinding/.project deleted file mode 100644 index 0ccc2284..00000000 --- a/examples/org.eclipse.jface.examples.databinding/.project +++ /dev/null @@ -1,30 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<projectDescription> - <name>org.eclipse.jface.examples.databinding</name> - <comment></comment> - <projects> - </projects> - <buildSpec> - <buildCommand> - <name>org.eclipse.jdt.core.javabuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.ManifestBuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.SchemaBuilder</name> - <arguments> - </arguments> - </buildCommand> - </buildSpec> - <natures> - <nature>org.eclipse.jem.workbench.JavaEMFNature</nature> - <nature>org.eclipse.pde.PluginNature</nature> - <nature>org.eclipse.jdt.core.javanature</nature> - <nature>org.eclipse.jem.beaninfo.BeanInfoNature</nature> - </natures> -</projectDescription> diff --git a/examples/org.eclipse.jface.examples.databinding/.settings/org.eclipse.jdt.core.prefs b/examples/org.eclipse.jface.examples.databinding/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 26cba416..00000000 --- a/examples/org.eclipse.jface.examples.databinding/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,357 +0,0 @@ -#Wed Apr 02 12:20:32 GMT-07:00 2008 -eclipse.preferences.version=1 -org.eclipse.jdt.core.builder.cleanOutputFolder=clean -org.eclipse.jdt.core.builder.duplicateResourceTask=warning -org.eclipse.jdt.core.builder.invalidClasspath=abort -org.eclipse.jdt.core.builder.recreateModifiedClassFileInOutputFolder=ignore -org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=*.launch -org.eclipse.jdt.core.circularClasspath=error -org.eclipse.jdt.core.classpath.exclusionPatterns=enabled -org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled -org.eclipse.jdt.core.codeComplete.argumentPrefixes= -org.eclipse.jdt.core.codeComplete.argumentSuffixes= -org.eclipse.jdt.core.codeComplete.fieldPrefixes= -org.eclipse.jdt.core.codeComplete.fieldSuffixes= -org.eclipse.jdt.core.codeComplete.localPrefixes= -org.eclipse.jdt.core.codeComplete.localSuffixes= -org.eclipse.jdt.core.codeComplete.staticFieldPrefixes= -org.eclipse.jdt.core.codeComplete.staticFieldSuffixes= -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.4 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.doc.comment.support=enabled -org.eclipse.jdt.core.compiler.maxProblemPerUnit=100 -org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.autoboxing=ignore -org.eclipse.jdt.core.compiler.problem.deprecation=ignore -org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled -org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled -org.eclipse.jdt.core.compiler.problem.discouragedReference=ignore -org.eclipse.jdt.core.compiler.problem.emptyStatement=warning -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore -org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled -org.eclipse.jdt.core.compiler.problem.fieldHiding=warning -org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning -org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=error -org.eclipse.jdt.core.compiler.problem.forbiddenReference=error -org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=error -org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=error -org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore -org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=error -org.eclipse.jdt.core.compiler.problem.invalidJavadoc=ignore -org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=disabled -org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled -org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled -org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=private -org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore -org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=error -org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore -org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore -org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled -org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public -org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag -org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore -org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled -org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=public -org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore -org.eclipse.jdt.core.compiler.problem.missingSerialVersion=error -org.eclipse.jdt.core.compiler.problem.noEffectAssignment=error -org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=error -org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore -org.eclipse.jdt.core.compiler.problem.nullReference=warning -org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=error -org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore -org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning -org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore -org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning -org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore -org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore -org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled -org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=error -org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled -org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore -org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning -org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning -org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore -org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning -org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning -org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning -org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore -org.eclipse.jdt.core.compiler.problem.unsafeTypeOperation=warning -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=enabled -org.eclipse.jdt.core.compiler.problem.unusedImport=error -org.eclipse.jdt.core.compiler.problem.unusedLabel=error -org.eclipse.jdt.core.compiler.problem.unusedLocal=error -org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore -org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled -org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=enabled -org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=enabled -org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=error -org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning -org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -org.eclipse.jdt.core.compiler.source=1.3 -org.eclipse.jdt.core.formatter.align_type_members_on_columns=false -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16 -org.eclipse.jdt.core.formatter.alignment_for_assignment=0 -org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 -org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 -org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 -org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0 -org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 -org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 -org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16 -org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 -org.eclipse.jdt.core.formatter.blank_lines_after_imports=1 -org.eclipse.jdt.core.formatter.blank_lines_after_package=1 -org.eclipse.jdt.core.formatter.blank_lines_before_field=0 -org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0 -org.eclipse.jdt.core.formatter.blank_lines_before_imports=1 -org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1 -org.eclipse.jdt.core.formatter.blank_lines_before_method=1 -org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1 -org.eclipse.jdt.core.formatter.blank_lines_before_package=0 -org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1 -org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1 -org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line -org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false -org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false -org.eclipse.jdt.core.formatter.comment.format_block_comments=true -org.eclipse.jdt.core.formatter.comment.format_header=false -org.eclipse.jdt.core.formatter.comment.format_html=true -org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true -org.eclipse.jdt.core.formatter.comment.format_line_comments=true -org.eclipse.jdt.core.formatter.comment.format_source_code=true -org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true -org.eclipse.jdt.core.formatter.comment.indent_root_tags=true -org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert -org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert -org.eclipse.jdt.core.formatter.comment.line_length=80 -org.eclipse.jdt.core.formatter.compact_else_if=true -org.eclipse.jdt.core.formatter.continuation_indentation=2 -org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 -org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true -org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true -org.eclipse.jdt.core.formatter.indent_empty_lines=false -org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true -org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true -org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true -org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false -org.eclipse.jdt.core.formatter.indentation.size=4 -org.eclipse.jdt.core.formatter.insert_new_line_after_annotation=insert -org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert -org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert -org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert -org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert -org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert -org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert -org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert -org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert -org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert -org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert -org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert -org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert -org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert -org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert -org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert -org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false -org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false -org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false -org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false -org.eclipse.jdt.core.formatter.lineSplit=80 -org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false -org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false -org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 -org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 -org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true -org.eclipse.jdt.core.formatter.tabulation.char=tab -org.eclipse.jdt.core.formatter.tabulation.size=4 -org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false -org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true -org.eclipse.jdt.core.incompatibleJDKLevel=ignore -org.eclipse.jdt.core.incompleteClasspath=error diff --git a/examples/org.eclipse.jface.examples.databinding/.settings/org.eclipse.jdt.ui.prefs b/examples/org.eclipse.jface.examples.databinding/.settings/org.eclipse.jdt.ui.prefs deleted file mode 100644 index 8079ff07..00000000 --- a/examples/org.eclipse.jface.examples.databinding/.settings/org.eclipse.jdt.ui.prefs +++ /dev/null @@ -1,116 +0,0 @@ -#Mon Dec 03 13:55:50 EST 2007 -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_serial_version_id=false -cleanup.always_use_blocks=true -cleanup.always_use_parentheses_in_expressions=false -cleanup.always_use_this_for_non_static_field_access=false -cleanup.always_use_this_for_non_static_method_access=false -cleanup.convert_to_enhanced_for_loop=false -cleanup.correct_indentation=false -cleanup.format_source_code=false -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_variable_declarations_final=false -cleanup.never_use_blocks=false -cleanup.never_use_parentheses_in_expressions=true -cleanup.organize_imports=false -cleanup.qualify_static_field_accesses_with_declaring_class=false -cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true -cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true -cleanup.qualify_static_member_accesses_with_declaring_class=true -cleanup.qualify_static_method_accesses_with_declaring_class=false -cleanup.remove_private_constructors=true -cleanup.remove_trailing_whitespaces=false -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=false -cleanup.use_blocks_only_for_return_and_throw=false -cleanup.use_parentheses_in_expressions=false -cleanup.use_this_for_non_static_field_access=false -cleanup.use_this_for_non_static_field_access_only_if_necessary=true -cleanup.use_this_for_non_static_method_access=false -cleanup.use_this_for_non_static_method_access_only_if_necessary=true -cleanup_profile=org.eclipse.jdt.ui.default.eclipse_clean_up_profile -cleanup_settings_version=2 -eclipse.preferences.version=1 -editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=false -formatter_profile=org.eclipse.jdt.ui.default.eclipse_profile -formatter_settings_version=11 -org.eclipse.jdt.ui.exception.name=e -org.eclipse.jdt.ui.gettersetter.use.is=true -org.eclipse.jdt.ui.ignorelowercasenames=true -org.eclipse.jdt.ui.importorder=java;javax;org;com; -org.eclipse.jdt.ui.javadoc=true -org.eclipse.jdt.ui.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"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\r\n * @return Returns the ${bare_field_name}.\r\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\r\n * @param ${param} The ${bare_field_name} to set.\r\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="true" 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) ${year} IBM Corporation 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 * IBM Corporation - initial API and implementation\r\n ******************************************************************************/\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 * @since 3.2\r\n *\r\n * ${tags}\r\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\r\n * \r\n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="true" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/* (non-Javadoc)\r\n * ${see_to_overridden}\r\n */</template><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\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\r\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\r\n${body_statement}</template><template autoinsert\="true" 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}\r\n// ${todo} Auto-generated constructor stub</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><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\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\r\n * ${tags}\r\n * ${see_to_target}\r\n */</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_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=false -sp_cleanup.format_source_code=false -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_variable_declarations_final=true -sp_cleanup.never_use_blocks=false -sp_cleanup.never_use_parentheses_in_expressions=true -sp_cleanup.on_save_use_additional_actions=false -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=false -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=false -sp_cleanup.remove_unused_imports=false -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=false -sp_cleanup.use_blocks_only_for_return_and_throw=false -sp_cleanup.use_parentheses_in_expressions=false -sp_cleanup.use_this_for_non_static_field_access=false -sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true -sp_cleanup.use_this_for_non_static_method_access=false -sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true diff --git a/examples/org.eclipse.jface.examples.databinding/.settings/org.eclipse.pde.prefs b/examples/org.eclipse.jface.examples.databinding/.settings/org.eclipse.pde.prefs deleted file mode 100644 index 122c936c..00000000 --- a/examples/org.eclipse.jface.examples.databinding/.settings/org.eclipse.pde.prefs +++ /dev/null @@ -1,18 +0,0 @@ -#Mon Dec 03 13:55:50 EST 2007 -compilers.incompatible-environment=1 -compilers.p.build=1 -compilers.p.deprecated=0 -compilers.p.illegal-att-value=0 -compilers.p.missing-bundle-classpath-entries=1 -compilers.p.missing-packages=2 -compilers.p.no-required-att=0 -compilers.p.not-externalized-att=0 -compilers.p.unknown-attribute=0 -compilers.p.unknown-class=1 -compilers.p.unknown-element=1 -compilers.p.unknown-resource=1 -compilers.p.unresolved-ex-points=0 -compilers.p.unresolved-import=0 -compilers.p.unused-element-or-attribute=1 -compilers.use-project=true -eclipse.preferences.version=1 diff --git a/examples/org.eclipse.jface.examples.databinding/META-INF/MANIFEST.MF b/examples/org.eclipse.jface.examples.databinding/META-INF/MANIFEST.MF deleted file mode 100644 index add7803f..00000000 --- a/examples/org.eclipse.jface.examples.databinding/META-INF/MANIFEST.MF +++ /dev/null @@ -1,20 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: %pluginName -Bundle-SymbolicName: org.eclipse.jface.examples.databinding -Bundle-Version: 1.0.100.qualifier -Bundle-ClassPath: . -Bundle-Vendor: %providerName -Bundle-Localization: plugin -Require-Bundle: org.eclipse.jface, - org.eclipse.core.databinding, - org.eclipse.core.runtime, - org.eclipse.core.databinding.beans, - org.eclipse.jface.databinding -Export-Package: org.eclipse.jface.examples.databinding;x-internal:=false, - org.eclipse.jface.examples.databinding.mask;x-internal:=false, - org.eclipse.jface.examples.databinding.mask.internal;x-internal:=true, - org.eclipse.jface.examples.databinding.model;x-internal:=false, - org.eclipse.jface.examples.databinding.radioGroup;x-internal:=false -Import-Package: com.ibm.icu.text -Bundle-RequiredExecutionEnvironment: J2SE-1.4 diff --git a/examples/org.eclipse.jface.examples.databinding/about.html b/examples/org.eclipse.jface.examples.databinding/about.html deleted file mode 100644 index 46023304..00000000 --- a/examples/org.eclipse.jface.examples.databinding/about.html +++ /dev/null @@ -1,28 +0,0 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml"> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> -<title>About</title> -</head> -<body lang="EN-US"> -<h2>About This Content</h2> - -<p>June 2, 2006</p> -<h3>License</h3> - -<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise -indicated below, the Content is provided to you under the terms and conditions of the -Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available -at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>. -For purposes of the EPL, "Program" will mean the Content.</p> - -<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is -being redistributed by another party ("Redistributor") and different terms and conditions may -apply to your use of any object code in the Content. Check the Redistributor's license that was -provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise -indicated below, the terms and conditions of the EPL still apply to any source code in the Content -and such source code may be obtained at <a href="http://www.eclipse.org">http://www.eclipse.org</a>.</p> - -</body> -</html>
\ No newline at end of file diff --git a/examples/org.eclipse.jface.examples.databinding/build.properties b/examples/org.eclipse.jface.examples.databinding/build.properties deleted file mode 100644 index 72c23de9..00000000 --- a/examples/org.eclipse.jface.examples.databinding/build.properties +++ /dev/null @@ -1,17 +0,0 @@ -############################################################################### -# Copyright (c) 2003, 2006 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -bin.includes = .,\ - META-INF/,\ - plugin.properties,\ - about.html -output.databindingexamples.jar = bin/ -src.includes = about.html -source.. = src/ diff --git a/examples/org.eclipse.jface.examples.databinding/plugin.properties b/examples/org.eclipse.jface.examples.databinding/plugin.properties deleted file mode 100644 index 759e715f..00000000 --- a/examples/org.eclipse.jface.examples.databinding/plugin.properties +++ /dev/null @@ -1,12 +0,0 @@ -############################################################################### -# Copyright (c) 2000, 2005 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -pluginName = JFace Data Binding Examples -providerName = Eclipse.org diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/ModelObject.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/ModelObject.java deleted file mode 100644 index 3e2acf33..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/ModelObject.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.examples.databinding; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.lang.reflect.Array; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class ModelObject { - private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( - this); - private String id; - - public void addPropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(listener); - } - - public void addPropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(propertyName, listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(listener); - } - - public void removePropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(propertyName, - listener); - } - - protected void firePropertyChange(String propertyName, Object oldValue, - Object newValue) { - propertyChangeSupport.firePropertyChange(propertyName, oldValue, - newValue); - } - - protected void firePropertyChange(String propertyName, int oldValue, - int newValue) { - propertyChangeSupport.firePropertyChange(propertyName, oldValue, - newValue); - } - - protected void firePropertyChange(String propertyName, boolean oldValue, - boolean newValue) { - propertyChangeSupport.firePropertyChange(propertyName, oldValue, - newValue); - } - - public void setId(String string) { - Object oldValue = id; - id = string; - firePropertyChange("id", oldValue, id); - } - - protected Object[] append(Object[] array, Object object) { - List newList = new ArrayList(Arrays.asList(array)); - newList.add(object); - return newList.toArray((Object[]) Array.newInstance(array.getClass() - .getComponentType(), newList.size())); - } - - protected Object[] remove(Object[] array, Object object) { - List newList = new ArrayList(Arrays.asList(array)); - newList.remove(object); - return newList.toArray((Object[]) Array.newInstance(array.getClass() - .getComponentType(), newList.size())); - } - -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/AsynchronousTestSet.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/AsynchronousTestSet.java deleted file mode 100644 index 96691159..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/AsynchronousTestSet.java +++ /dev/null @@ -1,163 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.examples.databinding.contentprovider.test; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Random; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.set.ObservableSet; -import org.eclipse.swt.widgets.Display; - -/** - * Test set that simulates asynchronously computed elements. The elements of the - * set are randomly generated Integers. Whenever the "recompute" method is - * called, the set will spin off a job that sleeps for a period of time and then - * randomly adds and removes elements from the set. - * - * <p> - * This simulates a set that wraps a database query or network communication. - * These would follow the same pattern (report the set as "stale", perform some - * slow operation, then make changes to the set). - * </p> - * - * @since 1.0 - */ -public class AsynchronousTestSet extends ObservableSet { - - private static Random randomNumberGenerator = new Random(); - - private Display display; - - private boolean stale = false; - - /** - * Average number of elements to add or remove - */ - private static final int AVERAGE_DELTA = 4; - - /** - * Average "computation" time -- time taken to do the simulated work (ms) - */ - private static final int AVERAGE_BUSY_TIME = 1000; - - /** - * List of all undisposed AsynchronousTestSet instances. Used for the - * recomputeAll method. - */ - private static List allSets = new ArrayList(); - - public AsynchronousTestSet() { - super(new HashSet(), Object.class); - display = Display.getCurrent(); - if (display == null) { - throw new IllegalStateException( - "This object can only be created in the UI thread"); //$NON-NLS-1$ - } - recompute(); - } - - protected void firstListenerAdded() { - super.firstListenerAdded(); - allSets.add(this); - } - - protected void lastListenerRemoved() { - allSets.remove(this); - super.lastListenerRemoved(); - } - - public static void recomputeAll() { - for (Iterator iter = allSets.iterator(); iter.hasNext();) { - AsynchronousTestSet next = (AsynchronousTestSet) iter.next(); - - next.recompute(); - } - } - - public void remove(Collection toRemove) { - HashSet removed = new HashSet(); - removed.addAll(toRemove); - removed.retainAll(wrappedSet); - - wrappedSet.removeAll(removed); - fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, removed)); - } - - public boolean isStale() { - return stale; - } - - public void recompute() { - if (!isStale()) { - setStale(true); - final int sleepTime = (int) (randomNumberGenerator.nextDouble() * (AVERAGE_BUSY_TIME * 2)); - Thread newThread = new Thread(new Runnable() { - public void run() { - - // Simulate work by sleeping - try { - Thread.sleep(sleepTime); - } catch (InterruptedException e) { - } - - // Add and remove some elements -- important: fire all - // events in the UI thread - display.asyncExec(new Runnable() { - public void run() { - final HashSet toAdd = new HashSet(); - final HashSet toRemove = new HashSet(); - - // Compute elements to add and remove (basically - // just fills the toAdd - // and toRemove sets with random elements) - int delta = (randomNumberGenerator - .nextInt(AVERAGE_DELTA * 4) - AVERAGE_DELTA * 2); - int extraAdds = randomNumberGenerator - .nextInt(AVERAGE_DELTA); - int addCount = delta + extraAdds; - int removeCount = -delta + extraAdds; - - if (addCount > 0) { - for (int i = 0; i < addCount; i++) { - toAdd.add(new Integer(randomNumberGenerator - .nextInt(20))); - } - } - - if (removeCount > 0) { - Iterator oldElements = wrappedSet.iterator(); - for (int i = 0; i < removeCount - && oldElements.hasNext(); i++) { - toRemove.add(oldElements.next()); - } - } - - toAdd.removeAll(wrappedSet); - wrappedSet.addAll(toAdd); - wrappedSet.removeAll(toRemove); - - setStale(false); - fireSetChange(Diffs.createSetDiff(toAdd, toRemove)); - } - }); - } - }); - - newThread.start(); - } - } -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/LabelProviderTest.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/LabelProviderTest.java deleted file mode 100644 index 736f7b55..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/LabelProviderTest.java +++ /dev/null @@ -1,211 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 116920 - *******************************************************************************/ - -package org.eclipse.jface.examples.databinding.contentprovider.test; - -import java.util.Collections; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.set.WritableSet; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.observable.value.ValueChangeEvent; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.databinding.viewers.ListeningLabelProvider; -import org.eclipse.jface.databinding.viewers.ObservableSetContentProvider; -import org.eclipse.jface.databinding.viewers.ViewersObservables; -import org.eclipse.jface.dialogs.InputDialog; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.jface.layout.LayoutConstants; -import org.eclipse.jface.viewers.ListViewer; -import org.eclipse.jface.viewers.ViewerLabel; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; - -/** - * Tests UpdatableTreeContentProvider and DirtyIndicationLabelProvider. Creates - * a tree containing three randomly-generated sets of integers, and one node - * that contains the union of the other sets. - * - * @since 1.0 - */ -public class LabelProviderTest { - - private Shell shell; - - private ListViewer list; - - private WritableSet setOfRenamables; - - private Button addButton; - - private Button removeButton; - - private Button renameButton; - - private SelectionListener buttonSelectionListener = new SelectionAdapter() { - /* - * (non-Javadoc) - * - * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) - */ - public void widgetSelected(SelectionEvent e) { - Button pressed = (Button) e.widget; - if (pressed == addButton) { - setOfRenamables.add(new RenamableItem()); - } else if (pressed == removeButton) { - setOfRenamables.remove(getCurrentSelection()); - } else if (pressed == renameButton) { - rename(getCurrentSelection()); - } - - super.widgetSelected(e); - } - }; - - private IObservableValue selectedRenamable; - - /** - * - */ - public LabelProviderTest() { - - // Create shell - shell = new Shell(Display.getCurrent()); - { // Initialize shell - setOfRenamables = new WritableSet(); - - list = new ListViewer(shell); - ObservableSetContentProvider contentProvider = new ObservableSetContentProvider(); - list.setContentProvider(contentProvider); - list.setLabelProvider(new ListeningLabelProvider(contentProvider - .getKnownElements()) { - RenamableItem.Listener listener = new RenamableItem.Listener() { - public void handleChanged(RenamableItem item) { - fireChangeEvent(Collections.singleton(item)); - } - }; - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.databinding.viewers.ViewerLabelProvider#updateLabel(org.eclipse.jface.viewers.ViewerLabel, - * java.lang.Object) - */ - public void updateLabel(ViewerLabel label, Object element) { - if (element instanceof RenamableItem) { - RenamableItem item = (RenamableItem) element; - - label.setText(item.getName()); - } - } - - protected void addListenerTo(Object next) { - RenamableItem item = (RenamableItem) next; - - item.addListener(listener); - } - - protected void removeListenerFrom(Object next) { - RenamableItem item = (RenamableItem) next; - - item.removeListener(listener); - } - }); - list.setInput(setOfRenamables); - - selectedRenamable = ViewersObservables.observeSingleSelection(list); - - Composite buttonBar = new Composite(shell, SWT.NONE); - { // Initialize buttonBar - addButton = new Button(buttonBar, SWT.PUSH); - addButton.setText("Add"); //$NON-NLS-1$ - addButton.addSelectionListener(buttonSelectionListener); - removeButton = new Button(buttonBar, SWT.PUSH); - removeButton.addSelectionListener(buttonSelectionListener); - removeButton.setText("Remove"); //$NON-NLS-1$ - renameButton = new Button(buttonBar, SWT.PUSH); - renameButton.addSelectionListener(buttonSelectionListener); - renameButton.setText("Rename"); //$NON-NLS-1$ - - selectedRenamable - .addValueChangeListener(new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - boolean shouldEnable = selectedRenamable - .getValue() != null; - removeButton.setEnabled(shouldEnable); - renameButton.setEnabled(shouldEnable); - } - }); - removeButton.setEnabled(false); - renameButton.setEnabled(false); - - GridLayoutFactory.fillDefaults().generateLayout(buttonBar); - } - - } - GridLayoutFactory.fillDefaults().numColumns(2).margins( - LayoutConstants.getMargins()).generateLayout(shell); - } - - /** - * @param currentSelection - */ - protected void rename(final RenamableItem currentSelection) { - InputDialog inputDialog = new InputDialog( - shell, - "Edit name", "Enter the new item name", currentSelection.getName(), null); //$NON-NLS-1$ //$NON-NLS-2$ - if (Window.OK == inputDialog.open()) { - currentSelection.setName(inputDialog.getValue()); - } - } - - /** - * @return - */ - protected RenamableItem getCurrentSelection() { - return (RenamableItem) selectedRenamable.getValue(); - } - - /** - * @param args - */ - public static void main(String[] args) { - final Display display = Display.getDefault(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - - public void run() { - LabelProviderTest test = new LabelProviderTest(); - Shell s = test.getShell(); - s.pack(); - s.setVisible(true); - - while (!s.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - } - }); - display.dispose(); - } - - private Shell getShell() { - return shell; - } -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/LabelProviderTest2.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/LabelProviderTest2.java deleted file mode 100644 index 3089982d..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/LabelProviderTest2.java +++ /dev/null @@ -1,210 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 116920 - *******************************************************************************/ - -package org.eclipse.jface.examples.databinding.contentprovider.test; - -import java.util.Collections; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.observable.value.ValueChangeEvent; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.databinding.viewers.ListeningLabelProvider; -import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; -import org.eclipse.jface.databinding.viewers.ViewersObservables; -import org.eclipse.jface.dialogs.InputDialog; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.jface.layout.LayoutConstants; -import org.eclipse.jface.viewers.ListViewer; -import org.eclipse.jface.viewers.ViewerLabel; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; - -/** - * Tests UpdatableTreeContentProvider and DirtyIndicationLabelProvider. Creates - * a tree containing three randomly-generated sets of integers, and one node - * that contains the union of the other sets. - * - * @since 1.0 - */ -public class LabelProviderTest2 { - - private Shell shell; - - private ListViewer list; - - private WritableList listOfRenamables; - - private Button addButton; - - private Button removeButton; - - private Button renameButton; - - private SelectionListener buttonSelectionListener = new SelectionAdapter() { - /* - * (non-Javadoc) - * - * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) - */ - public void widgetSelected(SelectionEvent e) { - Button pressed = (Button) e.widget; - if (pressed == addButton) { - listOfRenamables.add(new RenamableItem()); - } else if (pressed == removeButton) { - listOfRenamables.remove(getCurrentSelection()); - } else if (pressed == renameButton) { - rename(getCurrentSelection()); - } - - super.widgetSelected(e); - } - }; - - private IObservableValue selectedRenamable; - - /** - * - */ - public LabelProviderTest2() { - - // Create shell - shell = new Shell(Display.getCurrent()); - { // Initialize shell - listOfRenamables = new WritableList(); - - list = new ListViewer(shell); - ObservableListContentProvider contentProvider = new ObservableListContentProvider(); - list.setContentProvider(contentProvider); - list.setLabelProvider(new ListeningLabelProvider(contentProvider - .getKnownElements()) { - RenamableItem.Listener listener = new RenamableItem.Listener() { - public void handleChanged(RenamableItem item) { - fireChangeEvent(Collections.singleton(item)); - } - }; - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.databinding.viewers.ViewerLabelProvider#updateLabel(org.eclipse.jface.viewers.ViewerLabel, - * java.lang.Object) - */ - public void updateLabel(ViewerLabel label, Object element) { - if (element instanceof RenamableItem) { - RenamableItem item = (RenamableItem) element; - - label.setText(item.getName()); - } - } - - protected void addListenerTo(Object next) { - RenamableItem item = (RenamableItem) next; - - item.addListener(listener); - } - - protected void removeListenerFrom(Object next) { - RenamableItem item = (RenamableItem) next; - - item.removeListener(listener); - } - }); - list.setInput(listOfRenamables); - - selectedRenamable = ViewersObservables.observeSingleSelection(list); - - Composite buttonBar = new Composite(shell, SWT.NONE); - { // Initialize buttonBar - addButton = new Button(buttonBar, SWT.PUSH); - addButton.setText("Add"); //$NON-NLS-1$ - addButton.addSelectionListener(buttonSelectionListener); - removeButton = new Button(buttonBar, SWT.PUSH); - removeButton.addSelectionListener(buttonSelectionListener); - removeButton.setText("Remove"); //$NON-NLS-1$ - renameButton = new Button(buttonBar, SWT.PUSH); - renameButton.addSelectionListener(buttonSelectionListener); - renameButton.setText("Rename"); //$NON-NLS-1$ - - selectedRenamable - .addValueChangeListener(new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - boolean shouldEnable = selectedRenamable - .getValue() != null; - removeButton.setEnabled(shouldEnable); - renameButton.setEnabled(shouldEnable); - } - }); - removeButton.setEnabled(false); - renameButton.setEnabled(false); - - GridLayoutFactory.fillDefaults().generateLayout(buttonBar); - } - - } - GridLayoutFactory.fillDefaults().numColumns(2).margins( - LayoutConstants.getMargins()).generateLayout(shell); - } - - /** - * @param currentSelection - */ - protected void rename(final RenamableItem currentSelection) { - InputDialog inputDialog = new InputDialog( - shell, - "Edit name", "Enter the new item name", currentSelection.getName(), null); //$NON-NLS-1$ //$NON-NLS-2$ - if (Window.OK == inputDialog.open()) { - currentSelection.setName(inputDialog.getValue()); - } - } - - /** - * @return - */ - protected RenamableItem getCurrentSelection() { - return (RenamableItem) selectedRenamable.getValue(); - } - - /** - * @param args - */ - public static void main(String[] args) { - final Display display = Display.getDefault(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - LabelProviderTest2 test = new LabelProviderTest2(); - Shell s = test.getShell(); - s.pack(); - s.setVisible(true); - - while (!s.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - } - }); - display.dispose(); - } - - private Shell getShell() { - return shell; - } -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/RenamableItem.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/RenamableItem.java deleted file mode 100644 index 970b061e..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/RenamableItem.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.examples.databinding.contentprovider.test; - -import java.util.ArrayList; - -/** - * @since 1.0 - * - */ -public class RenamableItem { - - public static interface Listener { - public void handleChanged(RenamableItem item); - } - - private String name; - private ArrayList listeners = new ArrayList(); - - public RenamableItem() { - name = "RenamableItem"; //$NON-NLS-1$ - } - - public void addListener(Listener listener) { - listeners.add(listener); - } - - public void removeListener(Listener toRemove) { - listeners.remove(toRemove); - } - - public void setName(String newName) { - this.name = newName; - - Listener[] l = (Listener[]) listeners.toArray(new Listener[listeners.size()]); - for (int i = 0; i < l.length; i++) { - l[i].handleChanged(this); - } - } - - public String getName() { - return name; - } -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/SimpleNode.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/SimpleNode.java deleted file mode 100644 index 7d34d94b..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/SimpleNode.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.examples.databinding.contentprovider.test; - -import org.eclipse.core.databinding.observable.set.IObservableSet; - - -/** - * This object will be given randomly-generated children - * - * @since 1.0 - */ -public class SimpleNode { - private String nodeName; - private IObservableSet children; - - public SimpleNode(String nodeName, IObservableSet children) { - super(); - this.nodeName = nodeName; - this.children = children; - } - - public String getNodeName() { - return nodeName; - } - - public IObservableSet getChildren() { - return children; - } - -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/SomeMathFunction.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/SomeMathFunction.java deleted file mode 100644 index 88ec4540..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/SomeMathFunction.java +++ /dev/null @@ -1,124 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.examples.databinding.contentprovider.test; - -import java.util.Collections; -import java.util.Set; - -import org.eclipse.core.databinding.observable.map.ComputedObservableMap; -import org.eclipse.core.databinding.observable.map.MapDiff; -import org.eclipse.core.databinding.observable.set.IObservableSet; - -/** - * Simple function that performs one of three operations on Doubles: - * <ul> - * <li>Multiply by two</li> - * <li>Round to nearest integer</li> - * <li>Do nothing</li> - * </ul> - * - * @since 1.0 - */ -public class SomeMathFunction extends ComputedObservableMap { - - /** - * - */ - public static final int OP_IDENTITY = 0; - - /** - * - */ - public static final int OP_MULTIPLY = 1; - - /** - * - */ - public static final int OP_ROUND = 2; - - private int op = OP_ROUND; - - /** - * @param domain - */ - public SomeMathFunction(IObservableSet domain) { - super(domain); - init(); - } - - /** - * @param operation - */ - public void setOperation(final int operation) { - final int oldOp = this.op; - this.op = operation; - - // Fire a change event. Changing the operation is going to affect every - // answer returned by - // this function, so include every element in the function domain in the - // event. - // If this was a change that would only affect a subset of elements, we - // would include - // the subset of affected elements rather than using - // domain.toCollection() - fireMapChange(new MapDiff() { - - public Set getAddedKeys() { - return Collections.EMPTY_SET; - } - - public Set getChangedKeys() { - return keySet(); - } - - public Object getNewValue(Object key) { - return doComputeResult(key, operation); - } - - public Object getOldValue(Object key) { - return doComputeResult(key, oldOp); - } - - public Set getRemovedKeys() { - return Collections.EMPTY_SET; - } - }); - } - - private Object doComputeResult(Object element, int op) { - switch (op) { - case OP_IDENTITY: - return element; - case OP_MULTIPLY: - return new Double((((Double) element).doubleValue() * 2.0)); - case OP_ROUND: - return new Double(Math.floor((((Double) element).doubleValue()))); - } - return element; - } - - protected Object doGet(Object key) { - return doComputeResult(key, this.op); - } - - protected Object doPut(Object key, Object value) { - throw new UnsupportedOperationException(); - } - - protected void hookListener(Object addedKey) { - // ignore, no need to listen to immutable Double objects - } - - protected void unhookListener(Object removedKey) { - // ignore, no need to listen to immutable Double objects - } - -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/StructuredContentProviderTest.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/StructuredContentProviderTest.java deleted file mode 100644 index 20efc8eb..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/StructuredContentProviderTest.java +++ /dev/null @@ -1,396 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.examples.databinding.contentprovider.test; - -import java.util.Iterator; -import java.util.Random; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.set.MappedSet; -import org.eclipse.core.databinding.observable.set.WritableSet; -import org.eclipse.core.databinding.observable.value.ComputedValue; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.observable.value.ValueChangeEvent; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.databinding.viewers.ObservableSetContentProvider; -import org.eclipse.jface.databinding.viewers.ViewersObservables; -import org.eclipse.jface.internal.databinding.provisional.swt.ControlUpdater; -import org.eclipse.jface.internal.databinding.provisional.viewers.ViewerLabelProvider; -import org.eclipse.jface.viewers.ListViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; - -/** - * Tests UpdatableSetContentProvider, ComputableValue, ControlUpdator, - * UpdatableFunction, and ConvertingSet. - * - * <p> - * This test displays a dialog with user-editable list of Doubles. It allows the - * user to select a math function to apply to the set, and displays the result - * in a new list. A line of text along the bottom of the dialog displays the sum - * of the elements from the transformed set. Although this dialog is rather - * silly, it is a good example of a dialog where a lot of things can change from - * many directions. - * </p> - * - * <p> - * An UpdatableSetContentProvider is used to supply the contents each - * ListViewer. ControlUpdators - * - * </p> - * - * @since 1.0 - */ -public class StructuredContentProviderTest { - - private static Realm realm; - - /** - * Top-level shell for the dialog - */ - private Shell shell; - - /** - * Random number stream. Used for the "add" button. - */ - protected Random random = new Random(); - - // Data model //////////////////////////////////////////////////////// - - /** - * inputSet stores a set of Doubles. The user is allowed to add and remove - * Doubles from this set. - */ - private WritableSet inputSet; - - /** - * currentFunction is an Integer, set to one of the SomeMathFunction.OP_* - * constants. It identifies which function will be applied to inputSet. - */ - private WritableValue currentFunction; - - /** - * mathFunction is the transformation. It can multiply by 2, round down to - * the nearest integer, or do nothing (identity) - */ - private SomeMathFunction mathFunction; - - /** - * Set of Doubles. Holds the result of applying mathFunction to the - * inputSet. - */ - private MappedSet outputSet; - - /** - * A Double. Stores the sum of the Doubles in outputSet - */ - private IObservableValue sumOfOutputSet; - - /** - * Creates the test dialog as a top-level shell. - */ - public StructuredContentProviderTest() { - - // Initialize the data model - createDataModel(); - - shell = new Shell(Display.getCurrent(), SWT.SHELL_TRIM); - { // Initialize shell - final Label someDoubles = new Label(shell, SWT.NONE); - someDoubles.setText("A list of random Doubles"); //$NON-NLS-1$ - someDoubles.setLayoutData(new GridData( - GridData.HORIZONTAL_ALIGN_FILL - | GridData.VERTICAL_ALIGN_FILL)); - - Control addRemoveComposite = createInputControl(shell, inputSet); - - GridData addRemoveData = new GridData(GridData.FILL_BOTH); - addRemoveData.minimumHeight = 1; - addRemoveData.minimumWidth = 1; - - addRemoveComposite.setLayoutData(addRemoveData); - - Group operation = new Group(shell, SWT.NONE); - { // Initialize operation group - operation.setText("Select transformation"); //$NON-NLS-1$ - - createRadioButton(operation, currentFunction, "f(x) = x", //$NON-NLS-1$ - new Integer(SomeMathFunction.OP_IDENTITY)); - createRadioButton(operation, currentFunction, "f(x) = 2 * x", //$NON-NLS-1$ - new Integer(SomeMathFunction.OP_MULTIPLY)); - createRadioButton(operation, currentFunction, - "f(x) = floor(x)", new Integer( //$NON-NLS-1$ - SomeMathFunction.OP_ROUND)); - - GridLayout layout = new GridLayout(); - layout.numColumns = 1; - operation.setLayout(layout); - } - operation.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL - | GridData.VERTICAL_ALIGN_FILL)); - - Control outputControl = createOutputComposite(shell); - GridData outputData = new GridData(GridData.FILL_BOTH); - outputData.minimumHeight = 1; - outputData.minimumWidth = 1; - outputData.widthHint = 300; - outputData.heightHint = 150; - - outputControl.setLayoutData(outputData); - - final Label sumLabel = new Label(shell, SWT.NONE); - new ControlUpdater(sumLabel) { - protected void updateControl() { - double sum = ((Double) sumOfOutputSet.getValue()) - .doubleValue(); - int size = outputSet.size(); - - sumLabel.setText("The sum of the above " + size //$NON-NLS-1$ - + " doubles is " + sum); //$NON-NLS-1$ - } - }; - sumLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL - | GridData.VERTICAL_ALIGN_FILL)); - - GridLayout layout = new GridLayout(); - layout.numColumns = 1; - shell.setLayout(layout); - } - - } - - /** - * Create the updatables for this dialog - */ - private void createDataModel() { - // Initialize data model. We will create a user-editable set of Doubles. - // The user can run - // a transformation on this set and view the result in a list viewer. - - // inputSet will be a writable set of doubles. The user will add and - // remove entries from this set - // through the UI. - inputSet = new WritableSet(realm); - - // currentFunction holds the ID currently selected function to apply to - // elements in the inputSet. - // We will allow the user to change the current function through a set - // of radio buttons - currentFunction = new WritableValue(realm, new Integer( - SomeMathFunction.OP_MULTIPLY), null); - - // mathFunction implements the selected function - mathFunction = new SomeMathFunction(inputSet); - currentFunction.addValueChangeListener(new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - mathFunction - .setOperation(((Integer) currentFunction.getValue()) - .intValue()); - } - }); - mathFunction.setOperation(((Integer) currentFunction.getValue()) - .intValue()); - - // outputSet holds the result. It displays the result of applying the - // currently-selected - // function on all the elements in the input set. - outputSet = new MappedSet(inputSet, mathFunction); - - // sumOfOutputSet stores the current sum of the the Doubles in the - // output set - sumOfOutputSet = new ComputedValue(realm) { - protected Object calculate() { - double sum = 0.0; - for (Iterator iter = outputSet.iterator(); iter.hasNext();) { - Double next = (Double) iter.next(); - - sum += next.doubleValue(); - } - return new Double(sum); - } - }; - } - - /** - * Creates a radio button in the given parent composite. When selected, the - * button will change the given SettableValue to the given value. - * - * @param parent - * parent composite - * @param model - * SettableValue that will hold the value of the - * currently-selected radio button - * @param string - * text to appear in the radio button - * @param value - * value of this radio button (SettableValue will hold this value - * when the radio button is selected) - */ - private void createRadioButton(Composite parent, final WritableValue model, - String string, final Object value) { - final Button button = new Button(parent, SWT.RADIO); - button.setText(string); - button.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - model.setValue(value); - super.widgetSelected(e); - } - }); - new ControlUpdater(button) { - protected void updateControl() { - button.setSelection(model.getValue().equals(value)); - } - }; - button.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL - | GridData.VERTICAL_ALIGN_FILL)); - } - - private Control createOutputComposite(Composite parent) { - ListViewer listOfInts = new ListViewer(parent, SWT.BORDER - | SWT.V_SCROLL | SWT.H_SCROLL); - - listOfInts.setContentProvider(new ObservableSetContentProvider()); - listOfInts.setLabelProvider(new ViewerLabelProvider()); - listOfInts.setInput(outputSet); - return listOfInts.getControl(); - } - - /** - * Creates and returns a control that will allow the user to add and remove - * Doubles from the given input set. - * - * @param parent - * parent control - * @param inputSet - * input set - * @return a newly created SWT control that displays Doubles from the input - * set and allows the user to add and remove entries - */ - private Control createInputControl(Composite parent, - final WritableSet inputSet) { - Composite addRemoveComposite = new Composite(parent, SWT.NONE); - { // Initialize addRemoveComposite - ListViewer listOfInts = new ListViewer(addRemoveComposite, - SWT.BORDER); - - listOfInts.setContentProvider(new ObservableSetContentProvider()); - listOfInts.setLabelProvider(new ViewerLabelProvider()); - listOfInts.setInput(inputSet); - - final IObservableValue selectedInt = ViewersObservables.observeSingleSelection(listOfInts); - - GridData listData = new GridData(GridData.FILL_BOTH); - listData.minimumHeight = 1; - listData.minimumWidth = 1; - listData.widthHint = 150; - listData.heightHint = 150; - listOfInts.getControl().setLayoutData(listData); - - Composite buttonBar = new Composite(addRemoveComposite, SWT.NONE); - { // Initialize button bar - - Button add = new Button(buttonBar, SWT.PUSH); - add.setText("Add"); //$NON-NLS-1$ - add.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - inputSet.add(new Double(random.nextDouble() * 100.0)); - super.widgetSelected(e); - } - }); - add.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL - | GridData.VERTICAL_ALIGN_FILL)); - - final Button remove = new Button(buttonBar, SWT.PUSH); - remove.setText("Remove"); //$NON-NLS-1$ - // Enable the Remove button if and only if there is currently an - // element selected. - new ControlUpdater(remove) { - protected void updateControl() { - // This block demonstrates auto-listening. - // When updateControl is running, the framework - // remembers each - // updatable that gets touched. Since we're calling - // selectedInt.getValue() - // here, this updator will be flagged as dependant on - // selectedInt. This - // means that whenever selectedInt changes, this block - // of code will re-run - // itself. - - // The result is that the remove button will recompute - // its enablement - // whenever the selection in the listbox changes, and it - // was not necessary - // to attach any listeners. - remove.setEnabled(selectedInt.getValue() != null); - } - }; - - remove.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - inputSet.remove(selectedInt.getValue()); - super.widgetSelected(e); - } - }); - remove.setLayoutData(new GridData( - GridData.HORIZONTAL_ALIGN_FILL - | GridData.VERTICAL_ALIGN_FILL)); - - GridLayout buttonLayout = new GridLayout(); - buttonLayout.numColumns = 1; - buttonBar.setLayout(buttonLayout); - - } // End button bar - buttonBar.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL - | GridData.VERTICAL_ALIGN_BEGINNING)); - - GridLayout addRemoveLayout = new GridLayout(); - addRemoveLayout.numColumns = 2; - addRemoveComposite.setLayout(addRemoveLayout); - } - return addRemoveComposite; - } - - /** - * @param args - */ - public static void main(String[] args) { - Display display = Display.getDefault(); - realm = SWTObservables.getRealm(display); - StructuredContentProviderTest test = new StructuredContentProviderTest(); - Shell s = test.getShell(); - s.pack(); - s.setVisible(true); - - while (!s.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); - } - - private Shell getShell() { - return shell; - } - -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/TreeContentProviderTest.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/TreeContentProviderTest.java deleted file mode 100644 index 80193573..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/TreeContentProviderTest.java +++ /dev/null @@ -1,217 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.examples.databinding.contentprovider.test; - -import org.eclipse.core.databinding.observable.Observables; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.UnionSet; -import org.eclipse.core.databinding.observable.set.WritableSet; -import org.eclipse.core.internal.databinding.observable.tree.IUnorderedTreeProvider; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.internal.databinding.provisional.viewers.UnorderedTreeContentProvider; -import org.eclipse.jface.internal.databinding.provisional.viewers.ViewerLabelProvider; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.jface.layout.LayoutConstants; -import org.eclipse.jface.viewers.IViewerLabelProvider; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.jface.viewers.ViewerLabel; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; - -/** - * Tests UpdatableTreeContentProvider and DirtyIndicationLabelProvider. Creates - * a tree containing three randomly-generated sets of integers, and one node - * that contains the union of the other sets. - * - * @since 3.2 - */ -public class TreeContentProviderTest { - - private Shell shell; - private TreeViewer tree; - - // Three randomly-generated sets of doubles - private AsynchronousTestSet set1; - private AsynchronousTestSet set2; - private AsynchronousTestSet set3; - - // The union of the above three sets - private UnionSet union; - private Button randomize; - - public TreeContentProviderTest() { - - // Create the data model - set1 = new AsynchronousTestSet(); - set2 = new AsynchronousTestSet(); - set3 = new AsynchronousTestSet(); - - // A union of the above sets - union = new UnionSet(new IObservableSet[] { set1, set2, set3 }); - - // Create shell - shell = new Shell(Display.getCurrent()); - - createTree(); - - Composite buttonBar = new Composite(shell, SWT.NONE); - { - buttonBar.setLayout(new FillLayout(SWT.HORIZONTAL)); - randomize = new Button(buttonBar, SWT.PUSH); - randomize.setText("Randomize"); - randomize.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - AsynchronousTestSet.recomputeAll(); - super.widgetSelected(e); - } - }); - - GridLayoutFactory.fillDefaults().generateLayout(buttonBar); - } - - GridLayoutFactory.fillDefaults().margins(LayoutConstants.getMargins()) - .generateLayout(shell); - - shell.addDisposeListener(new DisposeListener() { - /* - * (non-Javadoc) - * - * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent) - */ - public void widgetDisposed(DisposeEvent e) { - dispose(); - } - }); - } - - /** - * - */ - protected void dispose() { - set1.dispose(); - set2.dispose(); - set3.dispose(); - union.dispose(); - } - - private void createTree() { - // Create the tree provider. This provides the structure of the tree. - // This tree will - // have an instance of RootNode as the root (which is really a - // placeholder), several - // SimpleNodes as top-level nodes, and sets of randomly generated - // Doubles below each - // SimpleNode. - IUnorderedTreeProvider treeProvider = new IUnorderedTreeProvider() { - public IObservableSet createChildSet(Object element) { - // If the parent is the root node, return the union of some - // randomly-generated - // nodes and some hardcoded nodes - if (element == tree.getInput()) { - // Set of hardcoded nodes - WritableSet topElements = new WritableSet(); - topElements.add(new SimpleNode("Random Set 1", set1)); - topElements.add(new SimpleNode("Random Set 2", set2)); - topElements.add(new SimpleNode("Random Set 3", set3)); - topElements.add(new SimpleNode("Union of the other sets", - union)); - return topElements; - } - - // If the parent is a RandomChildrenNode, return a - // randomly-generated - // set of Doubles for its children - if (element instanceof SimpleNode) { - // We return a new DelegatingObservableSet in order to - // prevent the - // original from being disposed. - return Observables - .proxyObservableSet(((SimpleNode) element) - .getChildren()); - } - - // Otherwise the node is a Double, which will have no children - return null; - } - - public Realm getRealm() { - // TODO Auto-generated method stub - return null; - } - }; - - // Label provider for the tree - IViewerLabelProvider labelProvider = new ViewerLabelProvider() { - public void updateLabel(ViewerLabel label, Object element) { - if (element instanceof SimpleNode) { - SimpleNode node = (SimpleNode) element; - - label.setText(node.getNodeName()); - } - - if (element instanceof Integer) { - Integer node = (Integer) element; - - label.setText("Integer " + node); - } - } - }; - - // Create tree viewer - tree = new TreeViewer(shell, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); - - // UpdatableTreeContentProvider converts an ITreeProvider into a - // standard JFace content provider - UnorderedTreeContentProvider contentProvider = new UnorderedTreeContentProvider( - treeProvider, "pending...", false); - - tree.setContentProvider(contentProvider); - tree.setLabelProvider(labelProvider); - - // For the ITreeProvider above, it doesn't matter what we select as the - // input. - tree.setInput(new Object()); - } - - /** - * @param args - */ - public static void main(String[] args) { - final Display display = Display.getDefault(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - TreeContentProviderTest test = new TreeContentProviderTest(); - Shell s = test.getShell(); - s.pack(); - s.setVisible(true); - - while (!s.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - } - }); - display.dispose(); - } - - private Shell getShell() { - return shell; - } -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/ducks/DuckType.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/ducks/DuckType.java deleted file mode 100644 index 031ac208..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/ducks/DuckType.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (C) 2005 db4objects Inc. http://www.db4o.com - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * db4objects - Initial API and implementation - */ -package org.eclipse.jface.examples.databinding.ducks; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; - -/** - * DuckType. Implements Duck Typing for Java. ("If it walks like a duck, - * quacks like a duck, it..."). Essentially allows programs to treat - * objects from separate hierarchies as if they were designed with common - * interfaces as long as they adhere to common naming conventions. - * <p> - * This version is the strict DuckType. All methods present in - * interfaceToImplement must be present on the target object. - * - * @author djo - */ -public class DuckType implements InvocationHandler { - - /** - * Interface DuckType#Wrapper. An interface for DuckType proxies that - * allows clients to access the proxied value. The value returned by - * calling DuckType#implement always implements this interface. - */ - public static interface Wrapper { - /** - * Method duckType_GetWrappedValue. Returns the proxied value. - * - * @return The proxied value. - */ - public Object duckType_GetWrappedValue(); - } - - /** - * Causes object to implement the interfaceToImplement and returns - * an instance of the object implementing interfaceToImplement even - * if interfaceToImplement was not declared in object.getClass()'s - * implements declaration.<p> - * - * This works as long as all methods declared in interfaceToImplement - * are present on object. - * - * @param interfaceToImplement The Java class of the interface to implement - * @param object The object to force to implement interfaceToImplement - * @return object, but now implementing interfaceToImplement - */ - public static Object implement(Class interfaceToImplement, Object object) { - return Proxy.newProxyInstance(interfaceToImplement.getClassLoader(), - new Class[] {interfaceToImplement, Wrapper.class}, new DuckType(object)); - } - - /** - * Indicates if object is a (DuckType) instace of intrface. That is, - * is every method in intrface present on object. - * - * @param intrface The interface to implement - * @param object The object to test - * @return true if every method in intrface is present on object. false otherwise - */ - public static boolean instanceOf(Class intrface, Object object) { - final Method[] methods = intrface.getMethods(); - Class candclass=object.getClass(); - for (int methodidx = 0; methodidx < methods.length; methodidx++) { - Method method=methods[methodidx]; - try { - candclass.getMethod(method.getName(), method.getParameterTypes()); - } catch (NoSuchMethodException e) { - return false; - } - } - return true; - } - - protected DuckType(Object object) { - this.object = object; - this.objectClass = object.getClass(); - } - - protected Object object; - protected Class objectClass; - - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - if (method.getName().equals("equals") && args != null && args.length == 1) { - return new Boolean(equals(args[0])); - } - if (method.getName().equals("hashCode") && args == null) { - return new Integer(hashCode()); - } - if (method.getName().equals("duckType_GetWrappedValue") && args == null) { - return object; - } - Method realMethod = objectClass.getMethod(method.getName(), method.getParameterTypes()); - if (!realMethod.isAccessible()) { - realMethod.setAccessible(true); - } - return realMethod.invoke(object, args); - } - - public boolean equals(Object obj) { - if (obj instanceof Wrapper) { - Wrapper proxy = (Wrapper) obj; - Object wrappedValue = proxy.duckType_GetWrappedValue(); - return wrappedValue.equals(object); - } - return obj == this || super.equals(obj) || object.equals(obj); - } - - public int hashCode() { - return object.hashCode(); - } -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/ducks/ReflectedMethod.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/ducks/ReflectedMethod.java deleted file mode 100644 index c3b78ea7..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/ducks/ReflectedMethod.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2005 db4objects Inc. http://www.db4o.com - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * db4objects - Initial API and implementation - */ -package org.eclipse.jface.examples.databinding.ducks; - -import java.lang.reflect.Method; - -/** - * ReflectedMethod. Encapsulates a method that may or may not exist on - * some receiver. Invocation policy is that if the method can be invoked, - * it is. On failure, returns null. - * - * @author djo - */ -public class ReflectedMethod { - - private Object subject; - private Method method; - - /** - * Constructor ReflectedMethod. Create a ReflectedMethod object. - * - * @param subject The object on which the method lives. - * @param methodName The name of the method. - * @param paramTypes The method's parameter types. - */ - public ReflectedMethod(Object subject, String methodName, Class[] paramTypes) { - this.subject = subject; - method = null; - try { - method = subject.getClass().getMethod(methodName, paramTypes); - } catch (Exception e) { - System.out.println(e); - } - } - - /** - * Method exists. Returns true if the underlying method exists, false - * otherwise. - * - * @return true if the underlying method exists, false otherwise. - */ - public boolean exists() { - return method != null; - } - - /** - * Method invoke. If possible, invoke the encapsulated method with the - * specified parameters. - * - * @param params An Object[] containing the parameters to pass. - * @return any return value or null if there was no return value or an - * error occured. - */ - public Object invoke(Object[] params) { - if (method == null) - return null; - try { - if (!method.isAccessible()) { - method.setAccessible(true); - } - return method.invoke(subject, params); - } catch (Exception e) { - return null; - } - } - - /** - * Method getType. Returns the return type of the method. - * - * @return The return type or null if none. - */ - public Class getType() { - return method.getReturnType(); - } -} - - diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/ducks/ReflectedProperty.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/ducks/ReflectedProperty.java deleted file mode 100644 index 3ec9a58c..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/ducks/ReflectedProperty.java +++ /dev/null @@ -1,104 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 The Pampered Chef 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: - * The Pampered Chef - initial API and implementation - ******************************************************************************/ - -package org.eclipse.jface.examples.databinding.ducks; - -/** - * Encapsulates a single JavaBeans-style property - * - * @since 3.3 - */ -public class ReflectedProperty { - private String propertyName; - private ReflectedMethod getter; - private ReflectedMethod setter; - - /** - * Construct a ReflectedProperty on some object, given the property name. - * - * @param object The object - * @param propertyName The property name - */ - public ReflectedProperty(Object object, String propertyName) { - this.propertyName = propertyName; - getter = new ReflectedMethod(object, makeGetterName(propertyName), new Class[] {}); - if (!getter.exists()) { - getter = new ReflectedMethod(object, makeBooleanGetterName(propertyName), new Class[] {}); - if (!getter.exists()) { - throw new IllegalArgumentException("Cannot find getter for " + propertyName); - } - } - setter = new ReflectedMethod(object, makeSetterName(propertyName), new Class[] {getter.getType()}); - } - - private String makeBooleanGetterName(String propertyName) { - return "is" + capitalize(propertyName); - } - - private String makeSetterName(String propertyName) { - return "set" + capitalize(propertyName); - } - - private String makeGetterName(String propertyName) { - return "get" + capitalize(propertyName); - } - - private String capitalize(String string) { - return string.substring(0, 1).toUpperCase() + string.substring(1); - } - - /** - * Return the property's type. This is the same as the type returned by - * the getter. - * - * @return The property's data type. - */ - public Class getType() { - return getter.getType(); - } - - /** - * Return the property's value. - * - * @return The value in the property. - */ - public Object get() { - return getter.invoke(new Object[] {}); - } - - /** - * Set the property's value. If the property is read-only, the request - * is ignored. - * - * @param newValue The value to set. - */ - public void set(Object newValue) { - setter.invoke(new Object[] {newValue}); - } - - /** - * Returns if the property is read-only. - * - * @return false if the property has a setter; true otherwise. - */ - public boolean isReadOnly() { - return !setter.exists(); - } - - /** - * Returns the property's name. - * - * @return The property name. - */ - public String getPropertyName() { - return propertyName; - } -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/ducks/RelaxedDuckType.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/ducks/RelaxedDuckType.java deleted file mode 100644 index fa433973..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/ducks/RelaxedDuckType.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2005 db4objects Inc. http://www.db4o.com - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * db4objects - Initial API and implementation - */ -package org.eclipse.jface.examples.databinding.ducks; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.util.HashMap; - -/** - * RelaxedDuckType. Implements Duck Typing for Java. ("If it walks like a duck, - * quacks like a duck, it..."). Essentially allows programs to treat - * objects from separate hierarchies as if they were designed with common - * interfaces as long as they adhere to common naming conventions. - * <p> - * This version is the relaxed DuckType. If a method in the interface is - * not present on the underlying object, the proxy simply returns null. - * - * @author djo - */ -public class RelaxedDuckType extends DuckType implements InvocationHandler { - - public static Object implement(Class interfaceToImplement, Object object) { - return Proxy.newProxyInstance(interfaceToImplement.getClassLoader(), - new Class[] {interfaceToImplement}, new RelaxedDuckType(object)); - } - - public static boolean includes(Object object, String method, Class[] args) { - try { - object.getClass().getMethod(method, args); - } catch (NoSuchMethodException e) { - return false; - } - return true; - } - - private static final HashMap NULL_VALUES = new HashMap(); { - NULL_VALUES.put(Boolean.TYPE, Boolean.FALSE); - NULL_VALUES.put(Integer.TYPE, new Integer(0)); - NULL_VALUES.put(Float.TYPE, new Float(0)); - NULL_VALUES.put(Long.TYPE, new Long(0)); - NULL_VALUES.put(Double.TYPE, new Double(0)); - NULL_VALUES.put(Character.TYPE, new Character(' ')); - } - - protected RelaxedDuckType(Object object) { - super(object); - } - - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - try { - Method realMethod = objectClass.getMethod(method.getName(), method.getParameterTypes()); - return realMethod.invoke(object, args); - } catch (NoSuchMethodException e) { - return NULL_VALUES.get(method.getReturnType()); - } catch (Throwable t) { - throw t; - } - } - -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/EditMask.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/EditMask.java deleted file mode 100644 index 484922e9..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/EditMask.java +++ /dev/null @@ -1,451 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 The Pampered Chef 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: - * The Pampered Chef - initial API and implementation - ******************************************************************************/ - -package org.eclipse.jface.examples.databinding.mask; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; - -import org.eclipse.jface.examples.databinding.mask.internal.EditMaskParser; -import org.eclipse.jface.examples.databinding.mask.internal.SWTUtil; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; -import org.eclipse.swt.events.FocusAdapter; -import org.eclipse.swt.events.FocusEvent; -import org.eclipse.swt.events.FocusListener; -import org.eclipse.swt.events.VerifyEvent; -import org.eclipse.swt.events.VerifyListener; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Text; - -/** - * Ensures text widget has the format specified by the edit mask. Edit masks - * are currently defined as follows: - * - * The following characters are reserved words that match specific kinds of - * characters: - * - * # - digits 0-9 - * A - uppercase A-Z - * a - upper or lowercase a-z, A-Z - * n - alphanumeric 0-9, a-z, A-Z - * - * All other characters are literals. The above characters may be turned into - * literals by preceeding them with a backslash. Use two backslashes to - * denote a backslash. - * - * Examples: - * - * (###) ###-#### U.S. phone number - * ###-##-#### U.S. Social Security number - * \\\### A literal backslash followed by a literal pound symbol followed by two digits - * - * Ideas for future expansion: - * - * Quantifiers as postfix modifiers to a token. ie: - * - * #{1, 2}/#{1,2}/#### MM/DD/YYYY date format allowing 1 or 2 digit month or day - * - * Literals may only be quantified as {0,1} which means that they only appear - * if placeholders on both sides of the literal have data. This will be used - * along with: - * - * Right-to-left support for numeric entry. When digits are being entered and - * a decimal point is present in the mask, digits to the left of the decimal - * are entered right-to-left but digits to the right of the decimal left-to-right. - * This might need to be a separate type of edit mask. (NumericMask, maybe?) - * - * Example: - * - * $#{0,3},{0,1}#{0,3}.#{0,2} ie: $123,456.12 or $12.12 or $1,234.12 or $123.12 - * - * - * Here's the basic idea of how the current implementation works (the actual - * implementation is slightly more abstracted and complicated than this): - * - * We always let the verify event pass if the user typed a new character or selected/deleted anything. - * During the verify event, we post an async runnable. - * Inside that async runnable, we: - * - Remember the selection position - * - getText(), then - * - Strip out all literal characters from text - * - Truncate the resulting string to raw length of edit mask without literals - * - Insert literal characters back in the correct positions - * - setText() the resulting string - * - reset the selection to the correct location - * - * @since 3.3 - */ -public class EditMask { - - public static final String FIELD_TEXT = "text"; - public static final String FIELD_RAW_TEXT = "rawText"; - public static final String FIELD_COMPLETE = "complete"; - protected Text text; - protected EditMaskParser editMaskParser; - private boolean fireChangeOnKeystroke = true; - private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); - - protected String oldValidRawText = ""; - protected String oldValidText = ""; - - /** - * Creates an instance that wraps around a text widget and manages its<br> - * formatting. - * - * @param text - * @param editMask - */ - public EditMask(Text text) { - this.text = text; - } - - /** - * @return the underlying Text control used by EditMask - */ - public Text getControl() { - return this.text; - } - - /** - * Set the edit mask string on the edit mask control. - * - * @param editMask The edit mask string - */ - public void setMask(String editMask) { - editMaskParser = new EditMaskParser(editMask); - text.addVerifyListener(verifyListener); - text.addFocusListener(focusListener); - text.addDisposeListener(disposeListener); - updateTextField.run(); - oldValidText = text.getText(); - oldValidRawText = editMaskParser.getRawResult(); - } - - /** - * @param string Sets the text string in the receiver - */ - public void setText(String string) { - String oldValue = text.getText(); - if (editMaskParser != null) { - editMaskParser.setInput(string); - String formattedResult = editMaskParser.getFormattedResult(); - text.setText(formattedResult); - firePropertyChange(FIELD_TEXT, oldValue, formattedResult); - } else { - text.setText(string); - firePropertyChange(FIELD_TEXT, oldValue, string); - } - oldValidText = text.getText(); - oldValidRawText = editMaskParser.getRawResult(); - } - - /** - * @return the actual (formatted) text - */ - public String getText() { - if (editMaskParser != null) { - return editMaskParser.getFormattedResult(); - } - return text.getText(); - } - - /** - * setRawText takes raw text as a parameter but formats it before - * setting the text in the Text control. - * - * @param string the raw (unformatted) text - */ - public void setRawText(String string) { - if (string == null) { - string = ""; - } - if (editMaskParser != null) { - String oldValue = editMaskParser.getRawResult(); - editMaskParser.setInput(string); - text.setText(editMaskParser.getFormattedResult()); - firePropertyChange(FIELD_RAW_TEXT, oldValue, string); - } else { - String oldValue = text.getText(); - text.setText(string); - firePropertyChange(FIELD_RAW_TEXT, oldValue, string); - } - oldValidText = text.getText(); - oldValidRawText = editMaskParser.getRawResult(); - } - - /** - * @return The input text with literals removed - */ - public String getRawText() { - if (editMaskParser != null) { - return editMaskParser.getRawResult(); - } - return text.getText(); - } - - /** - * @return true if the field is complete according to the mask; false otherwise - */ - public boolean isComplete() { - if (editMaskParser == null) { - return true; - } - return editMaskParser.isComplete(); - } - - /** - * Returns the placeholder character. The placeholder - * character must be a different character than any character that is - * allowed as input anywhere in the edit mask. For example, if the edit - * mask permits spaces to be used as input anywhere, the placeholder - * character must be something other than a space character. - * <p> - * The space character is the default placeholder character. - * - * @return the placeholder character - */ - public char getPlaceholder() { - if (editMaskParser == null) { - throw new IllegalArgumentException("Have to set an edit mask first"); - } - return editMaskParser.getPlaceholder(); - } - - /** - * Sets the placeholder character for the edit mask. The placeholder - * character must be a different character than any character that is - * allowed as input anywhere in the edit mask. For example, if the edit - * mask permits spaces to be used as input anywhere, the placeholder - * character must be something other than a space character. - * <p> - * The space character is the default placeholder character. - * - * @param placeholder The character to use as a placeholder - */ - public void setPlaceholder(char placeholder) { - if (editMaskParser == null) { - throw new IllegalArgumentException("Have to set an edit mask first"); - } - editMaskParser.setPlaceholder(placeholder); - updateTextField.run(); - oldValidText = text.getText(); - } - - /** - * Indicates if change notifications will be fired after every keystroke - * that affects the value of the rawText or only when the value is either - * complete or empty. - * - * @return true if every change (including changes from one invalid state to - * another) triggers a change event; false if only empty or valid - * values trigger a change event. Defaults to false. - */ - public boolean isFireChangeOnKeystroke() { - return fireChangeOnKeystroke; - } - - /** - * Sets if change notifications will be fired after every keystroke that - * affects the value of the rawText or only when the value is either - * complete or empty. - * - * @param fireChangeOnKeystroke - * true if every change (including changes from one invalid state - * to another) triggers a change event; false if only empty or - * valid values trigger a change event. Defaults to false. - */ - public void setFireChangeOnKeystroke(boolean fireChangeOnKeystroke) { - this.fireChangeOnKeystroke = fireChangeOnKeystroke; - } - - /** - * JavaBeans boilerplate code... - * - * @param listener - */ - public void addPropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(listener); - } - - /** - * JavaBeans boilerplate code... - * - * @param propertyName - * @param listener - */ - public void addPropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(propertyName, listener); - } - - /** - * JavaBeans boilerplate code... - * - * @param listener - */ - public void removePropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(listener); - } - - /** - * JavaBeans boilerplate code... - * - * @param propertyName - * @param listener - */ - public void removePropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(propertyName, - listener); - } - - private boolean isEitherValueNotNull(Object oldValue, Object newValue) { - return oldValue != null || newValue != null; - } - - private void firePropertyChange(String propertyName, Object oldValue, - Object newValue) { - if (isEitherValueNotNull(oldValue, newValue)) { - propertyChangeSupport.firePropertyChange(propertyName, - oldValue, newValue); - } - } - - protected boolean updating = false; - - protected int oldSelection = 0; - protected int selection = 0; - protected String oldRawText = ""; - protected boolean replacedSelectedText = false; - - private VerifyListener verifyListener = new VerifyListener() { - public void verifyText(VerifyEvent e) { - // If the edit mask is already full, don't let the user type - // any new characters - if (editMaskParser.isComplete() && // should eventually be .isFull() to account for optional characters - e.start == e.end && - e.text.length() > 0) - { - e.doit=false; - return; - } - - oldSelection = selection; - Point selectionRange = text.getSelection(); - selection = selectionRange.x; - - if (!updating) { - replacedSelectedText = false; - if (selectionRange.y - selectionRange.x > 0 && e.text.length() > 0) { - replacedSelectedText = true; - } - // If the machine is loaded down (ie: spyware, malware), we might - // get another keystroke before asyncExec can process, so we use - // greedyExec instead. - SWTUtil.greedyExec(Display.getCurrent(), updateTextField); -// Display.getCurrent().asyncExec(updateTextField); - } - } - }; - - private Runnable updateTextField = new Runnable() { - public void run() { - updating = true; - try { - if (!text.isDisposed()) { - Boolean oldIsComplete = new Boolean(editMaskParser.isComplete()); - - editMaskParser.setInput(text.getText()); - text.setText(editMaskParser.getFormattedResult()); - String newRawText = editMaskParser.getRawResult(); - - updateSelectionPosition(newRawText); - firePropertyChangeEvents(oldIsComplete, newRawText); - } - } finally { - updating = false; - } - } - - private void updateSelectionPosition(String newRawText) { - - // Adjust the selection - if (isInsertingNewCharacter(newRawText) || replacedSelectedText) { - // Find the position after where the new character was actually inserted - int selectionDelta = - editMaskParser.getNextInputPosition(oldSelection) - - oldSelection; - if (selectionDelta == 0) { - selectionDelta = editMaskParser.getNextInputPosition(selection) - - selection; - } - selection += selectionDelta; - } - - // Did we just type something that was accepted by the mask? - if (!newRawText.equals(oldRawText)) { // yep - - // If the user hits <end>, bounce them back to the end of their actual input - int firstIncompletePosition = editMaskParser.getFirstIncompleteInputPosition(); - if (firstIncompletePosition > 0 && selection > firstIncompletePosition) - selection = firstIncompletePosition; - text.setSelection(new Point(selection, selection)); - - } else { // nothing was accepted by the mask - - // Either we backspaced over a literal or we typed an illegal character - if (selection > oldSelection) { // typed an illegal character; backup - text.setSelection(new Point(selection-1, selection-1)); - } else { // backspaced over a literal; don't interfere with selection position - text.setSelection(new Point(selection, selection)); - } - } - oldRawText = newRawText; - } - - private boolean isInsertingNewCharacter(String newRawText) { - return newRawText.length() > oldRawText.length(); - } - - private void firePropertyChangeEvents(Boolean oldIsComplete, String newRawText) { - Boolean newIsComplete = new Boolean(editMaskParser.isComplete()); - if (!oldIsComplete.equals(newIsComplete)) { - firePropertyChange(FIELD_COMPLETE, oldIsComplete, newIsComplete); - } - if (!newRawText.equals(oldValidRawText)) { - if ( newIsComplete.booleanValue() || "".equals(newRawText) || fireChangeOnKeystroke) { - firePropertyChange(FIELD_RAW_TEXT, oldValidRawText, newRawText); - firePropertyChange(FIELD_TEXT, oldValidText, text.getText()); - oldValidText = text.getText(); - oldValidRawText = newRawText; - } - } - } - }; - - private FocusListener focusListener = new FocusAdapter() { - public void focusGained(FocusEvent e) { - selection = editMaskParser.getFirstIncompleteInputPosition(); - text.setSelection(selection, selection); - } - }; - - private DisposeListener disposeListener = new DisposeListener() { - public void widgetDisposed(DisposeEvent e) { - text.removeVerifyListener(verifyListener); - text.removeFocusListener(focusListener); - text.removeDisposeListener(disposeListener); - } - }; - -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/EditMaskParseException.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/EditMaskParseException.java deleted file mode 100644 index f2b6aece..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/EditMaskParseException.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 The Pampered Chef 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: - * The Pampered Chef - initial API and implementation - ******************************************************************************/ - -package org.eclipse.jface.examples.databinding.mask; - -/** - * Indicates a parse error while parsing an edit mask. - * - * @since 3.3 - */ -public class EditMaskParseException extends RuntimeException { - - private static final long serialVersionUID = 8142999683999681500L; - - /** - * Construct a MaskParseException - */ - public EditMaskParseException() { - super(); - } - - /** - * @param message - * @param cause - */ - public EditMaskParseException(String message, Throwable cause) { - super(message, cause); - } - - /** - * @param message - */ - public EditMaskParseException(String message) { - super(message); - } - - /** - * @param cause - */ - public EditMaskParseException(Throwable cause) { - super(cause); - } -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/EditMaskTest.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/EditMaskTest.java deleted file mode 100644 index 49c9c1c3..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/EditMaskTest.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.examples.databinding.mask; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.RowLayout; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -public class EditMaskTest { - - public static void main(String[] args) { - Display display = new Display(); - Shell shell = new Shell(display); - - Text text = new Text(shell, SWT.BORDER); - text.setText("XXXXXXXXXXXXX");// Put some X's in there to pad out the field's default size - - Text text2 = new Text(shell, SWT.BORDER); - text2.setText("630XXXXXXXXXX"); - - shell.setLayout(new RowLayout(SWT.VERTICAL)); - shell.setSize(800, 600); - - new EditMask(text).setMask("(###) ###-####"); - new EditMask(text2).setMask("(###) ###-####"); - - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - } - -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/internal/EditMaskLexerAndToken.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/internal/EditMaskLexerAndToken.java deleted file mode 100644 index d9c61b49..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/internal/EditMaskLexerAndToken.java +++ /dev/null @@ -1,189 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 The Pampered Chef 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: - * The Pampered Chef - initial API and implementation - ******************************************************************************/ - -package org.eclipse.jface.examples.databinding.mask.internal; - -import java.util.ArrayList; - -import org.eclipse.jface.examples.databinding.mask.EditMaskParseException; - -/** - * Lexical analyzer and token for an input mask. Since input masks have exactly - * one token type, we use the same class to be the recognizer and the token - * itself. - * - * @since 3.3 - */ -public class EditMaskLexerAndToken { - - /* - * First the literals that represent the types of characters - */ - private static ArrayList reservedWords = new ArrayList();{ - reservedWords.add("#"); - reservedWords.add("A"); - reservedWords.add("a"); - reservedWords.add("n"); - } - - /* - * ...and their corresponding regular expressions - */ - private static ArrayList inputRegexes = new ArrayList();{ - inputRegexes.add("^[0-9]$"); - inputRegexes.add("^[A-Z]$"); - inputRegexes.add("^[a-zA-Z]$"); - inputRegexes.add("^[0-9a-zA-Z]$"); - } - - private String charRegex = null; // A regex for matching input characters or null - private String literal = null; // The literal character if charRegex is null - private boolean readOnly; - private String input = null; // The user's input - - private boolean recognizeReservedWord(String inputMask, int position) { - String input = inputMask.substring(position, position+1); - for (int reservedWord = 0; reservedWord < reservedWords.size(); reservedWord++) { - if (input.equals(reservedWords.get(reservedWord))) { - charRegex = (String) inputRegexes.get(reservedWord); - literal = null; - input = null; - readOnly = false; - return true; - } - } - return false; - } - - private boolean recognizeBackslashLiteral(String inputMask, int position) throws EditMaskParseException { - String input = inputMask.substring(position, position+1); - if (input.equals("\\")) { - try { - input = inputMask.substring(position+1, position+2); - charRegex = null; - this.input = input; - literal = input; - readOnly = true; - return true; - } catch (Throwable t) { - throw new EditMaskParseException("Found a \\ without a character after it: " + inputMask); - } - } - return false; - } - - private boolean recognizeLiteral(String inputMask, int position) { - literal = inputMask.substring(position, position+1); - this.input = literal; - charRegex = null; - readOnly = true; - return true; - } - - /** - * Initializes itself based on characters in edit mask starting at position; - * returns number of chars consumed - * - * @param inputMask The entire edit mask - * @param position The position to begin parsing - * @return The number of characters consumed - * @throws EditMaskParseException If it encountered a syntax error during the parse - */ - public int initializeEditMask(String inputMask, int position) throws EditMaskParseException { - clear(); - if (recognizeReservedWord(inputMask, position)) { - return 1; - } - if (recognizeBackslashLiteral(inputMask, position)) { - return 2; - } - if (!recognizeLiteral(inputMask, position)) { - throw new EditMaskParseException("Should never see this error in this implementation!"); - } - readOnly = true; - return 1; - } - - /** - * ignores invalid input; stores valid input - * @param inputCharacter - * @return - */ - public boolean accept(String inputCharacter) { - if (readOnly) { - return false; - } - if (literal != null) { - return false; - } - if (!canAcceptMoreCharacters()) { - return false; - } - if (inputCharacter.matches(charRegex)) { - this.input = inputCharacter; - return true; - } - return false; - } - - /** - * @return Returns the characters it has accepted. In the current implementation, - * this is exactly one character. Once quantifiers are implemented, this could - * be many characters. If no characters have been accepted, returns null. - */ - public String getInput() { - return input; - } - - /** - * Clear any accepted input - */ - public void clear() { - if (!isReadOnly()) - input = null; - } - - /** - * @return true if it's a literal; false if it's a placeholder - */ - public boolean isReadOnly() { - return readOnly; - } - - /** - * @return true if it is a literal or if it has accepted the minimum - * required number of characters - */ - public boolean isComplete() { - if (input != null) { - return true; - } - return false; - } - - /** - * @return A position may be complete and yet able to accept more characters if - * the position includes optional characters via a quantifier of some type. - * Not implemented right now. - */ - public boolean canAcceptMoreCharacters() { - return !isComplete(); - } - - /** - * @return the minimum number of characters this RegexLexer must accept - * in order to be complete. Because we don't yet support quantifiers, this - * is currently always 1. - */ - public int getMinimumLength() { - return 1; - } -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/internal/EditMaskParser.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/internal/EditMaskParser.java deleted file mode 100644 index fc87f9e3..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/internal/EditMaskParser.java +++ /dev/null @@ -1,147 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 The Pampered Chef 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: - * The Pampered Chef - initial API and implementation - ******************************************************************************/ - -package org.eclipse.jface.examples.databinding.mask.internal; - -import java.util.LinkedList; - -import org.eclipse.jface.examples.databinding.mask.EditMaskParseException; - -/** - * @since 3.3 - */ -public class EditMaskParser { - private EditMaskLexerAndToken[] expectedTokens; - private char placeholder = ' '; - - /** - * @param editMask The complete edit mask - * @throws EditMaskParseException - */ - public EditMaskParser(String editMask) throws EditMaskParseException { - LinkedList tokens = new LinkedList(); - int position = 0; - while (position < editMask.length()) { - EditMaskLexerAndToken token = new EditMaskLexerAndToken(); - position += token.initializeEditMask(editMask, position); - tokens.add(token); - } - expectedTokens = (EditMaskLexerAndToken[]) tokens.toArray(new EditMaskLexerAndToken[tokens.size()]); - } - - /** - * @param input the user input which may or may not be in valid format - */ - public void setInput(String input) { - for (int i = 0; i < expectedTokens.length; i++) { - expectedTokens[i].clear(); - } - int tokenPosition = 0; - int inputPosition = 0; - while (inputPosition < input.length() && tokenPosition < expectedTokens.length) { - while (tokenPosition < expectedTokens.length && - (expectedTokens[tokenPosition].isComplete() || - expectedTokens[tokenPosition].isReadOnly())) - { - ++tokenPosition; - } - if (tokenPosition < expectedTokens.length) { - while (inputPosition < input.length() && !expectedTokens[tokenPosition].isComplete()) { - String inputChar = input.substring(inputPosition, inputPosition+1); - expectedTokens[tokenPosition].accept(inputChar); - ++inputPosition; - } - } - } - } - - /** - * @return the formatted version of the user input - */ - public String getFormattedResult() { - StringBuffer result = new StringBuffer(); - for (int i = 0; i < expectedTokens.length; i++) { - String outputChar = expectedTokens[i].getInput(); - if (outputChar == null) { - outputChar = "" + placeholder; - } - result.append(outputChar); - } - return result.toString(); - } - - /** - * @return the user input with all literals removed - */ - public String getRawResult() { - StringBuffer result = new StringBuffer(); - for (int i = 0; i < expectedTokens.length; i++) { - if (expectedTokens[i].isReadOnly()) { - continue; - } - String outputChar = expectedTokens[i].getInput(); - if (outputChar == null) { - outputChar = ""; - } - result.append(outputChar); - } - return result.toString(); - } - - /** - * @return true if the current input is a valid input - */ - public boolean isComplete() { - for (int i = 0; i < expectedTokens.length; i++) { - if (!expectedTokens[i].isComplete()) { - return false; - } - } - return true; - } - - /** - * @param startingAt The current index within the user input string - * @return The first non-read-only index greater than or equal to startingAt - */ - public int getNextInputPosition(int startingAt) { - while (startingAt < expectedTokens.length-1 && expectedTokens[startingAt].isReadOnly()) { - ++startingAt; - } - return startingAt; - } - - /** - * @return the first input position whose token is not marked as complete. Returns -1 if all are complete - */ - public int getFirstIncompleteInputPosition() { - for (int position = 0; position < expectedTokens.length; position++) { - if (!expectedTokens[position].isComplete()) { - return position; - } - } - return -1; - } - - /** - * @return Returns the placeholder. - */ - public char getPlaceholder() { - return placeholder; - } - - /** - * @param placeholder The placeholder to set. - */ - public void setPlaceholder(char placeholder) { - this.placeholder = placeholder; - } -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/internal/SWTUtil.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/internal/SWTUtil.java deleted file mode 100644 index 8bd2b2ad..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/internal/SWTUtil.java +++ /dev/null @@ -1,156 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.examples.databinding.mask.internal; - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.swt.graphics.RGB; -import org.eclipse.swt.widgets.Display; - -/** - * @since 1.0 - */ -public class SWTUtil { - /** - * Stores a work queue for each display - */ - private static Map mapDisplayOntoWorkQueue = new HashMap(); - - private SWTUtil() { - } - - /** - * Runs the given runnable on the given display as soon as possible. If - * possible, the runnable will be executed before the next widget is - * repainted, but this behavior is not guaranteed. Use this method to - * schedule work will affect the way one or more widgets are drawn. - * - * <p> - * This is threadsafe. - * </p> - * - * @param d - * display - * @param r - * runnable to execute in the UI thread. - */ - public static void greedyExec(Display d, Runnable r) { - if (d.isDisposed()) { - return; - } - - // if (Display.getCurrent() == d) { - // r.run(); - // } else { - WorkQueue queue = getQueueFor(d); - queue.asyncExec(r); - // } - } - - /** - * Runs the given runnable on the given display as soon as possible. Unlike - * greedyExec, this has no effect if the given runnable has already been - * scheduled for execution. Use this method to schedule work that will - * affect the way one or more wigdets are drawn, but that should only happen - * once. - * - * <p> - * This is threadsafe. - * </p> - * - * @param d - * display - * @param r - * runnable to execute in the UI thread. Has no effect if the - * given runnable has already been scheduled but has not yet run. - */ - public static void runOnce(Display d, Runnable r) { - if (d.isDisposed()) { - return; - } - WorkQueue queue = getQueueFor(d); - queue.runOnce(r); - } - - /** - * Cancels a greedyExec or runOnce that was previously scheduled on the - * given display. Has no effect if the given runnable is not in the queue - * for the given display - * - * @param d - * target display - * @param r - * runnable to execute - */ - public static void cancelExec(Display d, Runnable r) { - if (d.isDisposed()) { - return; - } - WorkQueue queue = getQueueFor(d); - queue.cancelExec(r); - } - - /** - * Returns the work queue for the given display. Creates a work queue if - * none exists yet. - * - * @param d - * display to return queue for - * @return a work queue (never null) - */ - private static WorkQueue getQueueFor(final Display d) { - WorkQueue result; - synchronized (mapDisplayOntoWorkQueue) { - // Look for existing queue - result = (WorkQueue) mapDisplayOntoWorkQueue.get(d); - - if (result == null) { - // If none, create new queue - result = new WorkQueue(d); - final WorkQueue q = result; - mapDisplayOntoWorkQueue.put(d, result); - d.asyncExec(new Runnable() { - public void run() { - d.disposeExec(new Runnable() { - public void run() { - synchronized (mapDisplayOntoWorkQueue) { - q.cancelAll(); - mapDisplayOntoWorkQueue.remove(d); - } - } - }); - } - }); - } - return result; - } - } - - /** - * @param rgb1 - * @param rgb2 - * @param ratio - * @return the RGB object - */ - public static RGB mix(RGB rgb1, RGB rgb2, double ratio) { - return new RGB(interp(rgb1.red, rgb2.red, ratio), - interp(rgb1.green, rgb2.green, ratio), - interp(rgb1.blue, rgb2.blue, ratio)); - } - - private static int interp(int i1, int i2, double ratio) { - int result = (int)(i1 * ratio + i2 * (1.0d - ratio)); - if (result < 0) result = 0; - if (result > 255) result = 255; - return result; - } -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/internal/WorkQueue.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/internal/WorkQueue.java deleted file mode 100644 index e5eeaea2..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/internal/WorkQueue.java +++ /dev/null @@ -1,148 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ -package org.eclipse.jface.examples.databinding.mask.internal; - -import java.util.HashSet; -import java.util.LinkedList; -import java.util.Set; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; - -/** - * @since 3.2 - * - */ -public class WorkQueue { - - private boolean updateScheduled = false; - - private boolean paintListenerAttached = false; - - private LinkedList pendingWork = new LinkedList(); - - private Display d; - - private Set pendingWorkSet = new HashSet(); - - private Runnable updateJob = new Runnable() { - public void run() { - doUpdate(); - updateScheduled = false; - } - }; - - private Listener paintListener = new Listener() { - public void handleEvent(Event event) { - paintListenerAttached = false; - d.removeFilter(SWT.Paint, this); - doUpdate(); - } - }; - - /** - * @param targetDisplay - */ - public WorkQueue(Display targetDisplay) { - d = targetDisplay; - } - - private void doUpdate() { - for (;;) { - Runnable next; - synchronized (pendingWork) { - if (pendingWork.isEmpty()) { - break; - } - next = (Runnable) pendingWork.removeFirst(); - pendingWorkSet.remove(next); - } - - next.run(); - } - - } - - /** - * Schedules some work to happen in the UI thread as soon as possible. If - * possible, the work will happen before the next control redraws. The given - * runnable will only be run once. Has no effect if this runnable has - * already been queued for execution. - * - * @param work - * runnable to execute - */ - public void runOnce(Runnable work) { - synchronized (pendingWork) { - if (pendingWorkSet.contains(work)) { - return; - } - - pendingWorkSet.add(work); - - asyncExec(work); - } - } - - /** - * Schedules some work to happen in the UI thread as soon as possible. If - * possible, the work will happen before the next control redraws. Unlike - * runOnce, calling asyncExec twice with the same runnable will cause that - * runnable to run twice. - * - * @param work - * runnable to execute - */ - public void asyncExec(Runnable work) { - synchronized (pendingWork) { - pendingWork.add(work); - if (!updateScheduled) { - updateScheduled = true; - d.asyncExec(updateJob); - } - - // If we're in the UI thread, add an event filter to ensure - // the work happens ASAP - if (Display.getCurrent() == d) { - if (!paintListenerAttached) { - paintListenerAttached = true; - d.addFilter(SWT.Paint, paintListener); - } - } - } - } - - /** - * Cancels a previously-scheduled runnable. Has no effect if the given - * runnable was not previously scheduled or has already executed. - * - * @param toCancel - * runnable to cancel - */ - public void cancelExec(Runnable toCancel) { - synchronized (pendingWork) { - pendingWork.remove(toCancel); - pendingWorkSet.remove(toCancel); - } - } - - /** - * Cancels all pending work. - */ - public void cancelAll() { - synchronized (pendingWork) { - pendingWork.clear(); - pendingWorkSet.clear(); - } - } -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Account.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Account.java deleted file mode 100644 index 7509d647..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Account.java +++ /dev/null @@ -1,85 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.examples.databinding.model; - -import java.util.Date; - -import org.eclipse.jface.examples.databinding.ModelObject; - -public class Account extends ModelObject { - - private String country; - private String firstName; - private String lastName; - private String state; - private String phone; - private Date expiryDate; - - public void setFirstName(String string) { - String oldValue = firstName; - firstName = string; - firePropertyChange("firstName", oldValue, string); - } - - public void setLastName(String string) { - String oldValue = lastName; - lastName = string; - firePropertyChange("lastName", oldValue, string); - } - - public void setState(String string) { - String oldValue = state; - state = string; - firePropertyChange("state", oldValue, string); - } - - public void setPhone(String string) { - String oldValue = phone; - phone = string; - firePropertyChange("phone", oldValue, phone); - } - - public void setCountry(String string) { - Object oldValue = country; - country = string; - firePropertyChange("country", oldValue, string); - } - - public String getCountry() { - return country; - } - - public String getFirstName() { - return firstName; - } - - public String getLastName() { - return lastName; - } - - public String getState() { - return state; - } - - public String getPhone() { - return phone; - } - - public Date getExpiryDate() { - return expiryDate; - } - - public void setExpiryDate(Date expiryDate) { - firePropertyChange("expiryDate", this.expiryDate, - this.expiryDate = expiryDate); - } - -}
\ No newline at end of file diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Adventure.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Adventure.java deleted file mode 100644 index d78eed03..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Adventure.java +++ /dev/null @@ -1,114 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.examples.databinding.model; - -import org.eclipse.core.databinding.validation.IValidator; -import org.eclipse.core.databinding.validation.ValidationStatus; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jface.examples.databinding.ModelObject; - -public class Adventure extends ModelObject { - - private boolean petsAllowed; - - private double price; - - private Lodging defaultLodging; - - private String name; - - private String description; - - private String location; - - private int maxNumberOfPeople; - - public String getName() { - return name; - } - - public void setName(String string) { - Object oldValue = name; - name = string; - firePropertyChange("name", oldValue, name); - } - - public int getMaxNumberOfPeople(){ - return maxNumberOfPeople; - } - - public void setMaxNumberOfPeople(int anInt) { - int oldValue = maxNumberOfPeople; - maxNumberOfPeople = anInt; - firePropertyChange("maxNumberOfPeople", oldValue, maxNumberOfPeople); - } - - public IValidator getMaxNumberOfPeopleDomainValidator() { - return new IValidator() { - public IStatus validate(Object value) { - int intValue = ((Integer)value).intValue(); - if (intValue < 1 || intValue > 20) { - return ValidationStatus - .error("Max number of people must be between 1 and 20 inclusive"); - } - return null; - } - }; - } - - public Lodging getDefaultLodging() { - return defaultLodging; - } - - public void setDefaultLodging(Lodging lodging) { - Object oldValue = defaultLodging; - defaultLodging = lodging; - firePropertyChange("defaultLodging", oldValue, defaultLodging); - } - - public void setPrice(double d) { - double oldValue = price; - price = d; - firePropertyChange("price", new Double(oldValue), new Double(price)); - } - - public double getPrice() { - return price; - } - - public void setPetsAllowed(boolean b) { - boolean oldValue = petsAllowed; - petsAllowed = b; - firePropertyChange("petsAllowed", new Boolean(oldValue), new Boolean( - petsAllowed)); - } - - public boolean isPetsAllowed() { - return petsAllowed; - } - - public void setDescription(String string) { - Object oldValue = description; - description = string; - firePropertyChange("description", oldValue, description); - } - - public void setLocation(String string) { - Object oldValue = location; - location = string; - firePropertyChange("location", oldValue, location); - } - - public String getDescription() { - return description; - } - -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/AdventureFactory.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/AdventureFactory.java deleted file mode 100644 index 2b95e139..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/AdventureFactory.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.examples.databinding.model; - -public class AdventureFactory { - - public Catalog createCatalog() { - return new Catalog(); - } - - public Category createCategory() { - return new Category(); - } - - public Adventure createAdventure() { - return new Adventure(); - } - - public Lodging createLodging() { - return new Lodging(); - } - - public Transportation createTransportation() { - return new Transportation(); - } - - public Account createAccount() { - return new Account(); - } - - public Cart createCart() { - return new Cart(); - } - -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/AggregateObservableValue.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/AggregateObservableValue.java deleted file mode 100644 index 0606d436..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/AggregateObservableValue.java +++ /dev/null @@ -1,102 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653 - *******************************************************************************/ -package org.eclipse.jface.examples.databinding.model; - -import java.util.StringTokenizer; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.value.AbstractObservableValue; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.observable.value.ValueChangeEvent; - -/** - * @since 3.2 - * - */ -public class AggregateObservableValue extends AbstractObservableValue { - - private IObservableValue[] observableValues; - - private String delimiter; - - private boolean updating = false; - - private String currentValue; - - private IValueChangeListener listener = new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - if (!updating) { - fireValueChange(Diffs.createValueDiff(currentValue, - doGetValue())); - } - } - }; - - /** - * @param observableValues - * @param delimiter - */ - public AggregateObservableValue(IObservableValue[] observableValues, - String delimiter) { - this.observableValues = observableValues; - this.delimiter = delimiter; - for (int i = 0; i < observableValues.length; i++) { - observableValues[i].addValueChangeListener(listener); - } - doGetValue(); - } - - public void doSetValue(Object value) { - Object oldValue = doGetValue(); - StringTokenizer tokenizer = new StringTokenizer((String) value, - delimiter); - try { - updating = true; - for (int i = 0; i < observableValues.length; i++) { - if (tokenizer.hasMoreElements()) { - observableValues[i].setValue(tokenizer.nextElement()); - } else { - observableValues[i].setValue(null); - } - } - } finally { - updating = false; - } - doGetValue(); - fireValueChange(Diffs.createValueDiff(oldValue, value)); - } - - public Object doGetValue() { - StringBuffer result = new StringBuffer(); - for (int i = 0; i < observableValues.length; i++) { - if (i > 0 & i < observableValues.length) { - result.append(delimiter); - } - result.append(observableValues[i].getValue()); - } - currentValue = result.toString(); - return currentValue; - } - - public Object getValueType() { - return String.class; - } - - public void dispose() { - for (int i = 0; i < observableValues.length; i++) { - observableValues[i].removeValueChangeListener(listener); - } - super.dispose(); - } - -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Cart.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Cart.java deleted file mode 100644 index b82f45eb..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Cart.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.examples.databinding.model; - -public class Cart { - - public void setAdventureDays(int i) { - // TODO Auto-generated method stub - - } - - public int getLodgingDays() { - // TODO Auto-generated method stub - return 0; - } - -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Catalog.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Catalog.java deleted file mode 100644 index edbae49e..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Catalog.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.examples.databinding.model; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.jface.examples.databinding.ModelObject; - -public class Catalog extends ModelObject { - - private Category[] categories = new Category[0]; - - private Lodging[] lodgings = new Lodging[0]; - - private Transportation[] transportations = new Transportation[0]; - - private Account[] accounts = new Account[0]; - - private List signons = new ArrayList(); - - public List getSignons(){ - return signons; - } - - public void addSignon(Signon aSignon){ - signons.add(aSignon); - firePropertyChange("signons",null,null); - } - - public void removeSignon(Signon aSignon){ - signons.remove(aSignon); - firePropertyChange("signons",null,null); - } - - public Category[] getCategories() { - return categories; - } - - public void addCategory(Category category) { - categories = (Category[]) append(categories, category); - firePropertyChange("categories", null, null); - } - - public void addLodging(Lodging lodging) { - lodgings = (Lodging[]) append(lodgings, lodging); - firePropertyChange("lodgings", null, null); - } - - public void addTransportation(Transportation transportation) { - transportations = (Transportation[]) append(transportations, transportation); - firePropertyChange("transportations", null, null); - } - - public void addAccount(Account account) { - accounts = (Account[]) append(accounts, account); - firePropertyChange("accounts", null, null); - } - - public Lodging[] getLodgings() { - return lodgings; - } - - public void removeLodging(Lodging lodging) { - lodgings = (Lodging[]) remove(lodgings, lodging); - firePropertyChange("lodgings", null, null); - } - - public void removeAccount(Account anAccount) { - accounts = (Account[]) remove(accounts, anAccount); - firePropertyChange("accounts", null, null); - } - - public Account[] getAccounts() { - return accounts; - } - - public Transportation[] getTransporations(){ - return transportations; - } - -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Category.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Category.java deleted file mode 100644 index 778a31c1..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Category.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.examples.databinding.model; - -import org.eclipse.jface.examples.databinding.ModelObject; - -public class Category extends ModelObject { - - private String name; - - private Adventure[] adventures = new Adventure[0]; - - public void setName(String string) { - Object oldValue = name; - name = string; - firePropertyChange("name", oldValue, name); - } - - public void addAdventure(Adventure adventure) { - adventures = (Adventure[]) append(adventures, adventure); - firePropertyChange("adventures", null, null); - } - - public Adventure[] getAdventures() { - return adventures; - } - - public String getName() { - return name; - } - -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Lodging.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Lodging.java deleted file mode 100644 index 0b9d081c..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Lodging.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.examples.databinding.model; - -import org.eclipse.jface.examples.databinding.ModelObject; - -public class Lodging extends ModelObject { - - private String name; - private String description; - - public String getDescription() { - return description; - } - - public void setDescription(String string) { - Object oldValue = description; - description = string; - firePropertyChange("description",oldValue,description); - } - - public void setName(String string) { - Object oldValue = name; - name = string; - firePropertyChange("name",oldValue,name); - } - - public String getName() { - return name; - } - -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/PriceModelObject.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/PriceModelObject.java deleted file mode 100644 index 35e3f5e8..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/PriceModelObject.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.examples.databinding.model; - -import org.eclipse.jface.examples.databinding.ModelObject; - - -public class PriceModelObject extends ModelObject { - - private double price; - - public double getDouble(){ - return price; - } - public void setPrice(double aPrice){ - int oldDollars = getDollars(); - int oldCents = getCents(); - double oldValue = price; - price = aPrice; - firePropertyChange("dollars",oldDollars,getDollars()); - firePropertyChange("cents",oldCents,getCents()); - firePropertyChange("price",new Double(oldValue), new Double(price)); - } - - public double getPrice(){ - return price; - } - - public int getCents(){ - return (int) (100*price - 100*Math.floor(price)); - } - - public void setCents(int cents){ - double oldPrice = getPrice(); - int oldCents = getCents(); - price = getDollars() + cents *.01; - firePropertyChange("cents",oldCents,getCents()); - firePropertyChange("price", new Double(oldPrice), new Double(price)); - } - - public int getDollars(){ - return new Double(price).intValue(); - } - - public void setDollars(int dollars){ - double oldPrice = getPrice(); - int oldDollars = getDollars(); - price = dollars + getCents() *.01; - firePropertyChange("dollars",oldDollars,getDollars()); - firePropertyChange("price", new Double(oldPrice), new Double(price)); - } - -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/SampleData.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/SampleData.java deleted file mode 100644 index f30a1592..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/SampleData.java +++ /dev/null @@ -1,172 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 116920 - *******************************************************************************/ -package org.eclipse.jface.examples.databinding.model; - - -public class SampleData { - - public static Category WINTER_CATEGORY; - - public static Category SUMMER_CATEGORY; - - public static Adventure BEACH_HOLIDAY; - - public static Adventure RAFTING_HOLIDAY; - - public static Adventure WINTER_HOLIDAY; - - public static Adventure ICE_FISHING; - - public static Lodging FIVE_STAR_HOTEL; - - public static Lodging YOUTH_HOSTEL; - - public static Lodging CAMP_GROUND; - - public static Catalog CATALOG_2005; - - public static Transportation GREYHOUND_BUS; - - public static Transportation EXECUTIVE_JET; - - public static Account PRESIDENT; - - public static Account DENTIST; - - public static Account SANTA_CLAUS; - - public static Cart CART; - - public static AdventureFactory FACTORY; - - // public static ITree CATALOG_TREE; - // - // public static ITree CATEGORY_TREE; - - public static Signon SIGNON_ADMINISTRATOR; - - public static Signon SIGNON_JOEBLOGGS; - - static { - initializeData(); - } - - public static void initializeData() { - - FACTORY = new AdventureFactory(); - - CATALOG_2005 = FACTORY.createCatalog(); - - // Categories - WINTER_CATEGORY = FACTORY.createCategory(); - WINTER_CATEGORY.setName("Freeze Adventures"); - WINTER_CATEGORY.setId("100"); - CATALOG_2005.addCategory(WINTER_CATEGORY); - - SUMMER_CATEGORY = FACTORY.createCategory(); - SUMMER_CATEGORY.setName("Hot Adventures"); - SUMMER_CATEGORY.setId("200"); - CATALOG_2005.addCategory(SUMMER_CATEGORY); - - // Adventures - WINTER_HOLIDAY = FACTORY.createAdventure(); - WINTER_HOLIDAY.setDescription("Winter holiday in France"); - WINTER_HOLIDAY.setName("Ski Alps"); - WINTER_HOLIDAY.setLocation("Chamonix"); - WINTER_HOLIDAY.setPrice(4000.52d); - WINTER_HOLIDAY.setId("150"); - WINTER_HOLIDAY.setMaxNumberOfPeople(3); - WINTER_CATEGORY.addAdventure(WINTER_HOLIDAY); - - ICE_FISHING = FACTORY.createAdventure(); - ICE_FISHING.setDescription("Ice Fishing in Helsinki"); - ICE_FISHING.setName("Ice Fishing"); - ICE_FISHING.setLocation("Finland"); - ICE_FISHING.setPrice(375.55d); - WINTER_CATEGORY.addAdventure(ICE_FISHING); - - BEACH_HOLIDAY = FACTORY.createAdventure(); - BEACH_HOLIDAY.setDescription("Beach holiday in Spain"); - BEACH_HOLIDAY.setName("Playa"); - BEACH_HOLIDAY.setLocation("Lloret de Mar"); - BEACH_HOLIDAY.setPrice(2000.52d); - BEACH_HOLIDAY.setId("250"); - SUMMER_CATEGORY.addAdventure(BEACH_HOLIDAY); - - RAFTING_HOLIDAY = FACTORY.createAdventure(); - RAFTING_HOLIDAY - .setDescription("White water rafting on the Ottawa river"); - RAFTING_HOLIDAY.setName("Whitewater"); - RAFTING_HOLIDAY.setLocation("Ottawa"); - RAFTING_HOLIDAY.setPrice(8000.52d); - RAFTING_HOLIDAY.setId("270"); - SUMMER_CATEGORY.addAdventure(RAFTING_HOLIDAY); - - // Lodgings - FIVE_STAR_HOTEL = FACTORY.createLodging(); - FIVE_STAR_HOTEL.setDescription("Deluxe palace"); - FIVE_STAR_HOTEL.setName("Flashy"); - YOUTH_HOSTEL = FACTORY.createLodging(); - YOUTH_HOSTEL.setDescription("Youth Hostel"); - YOUTH_HOSTEL.setName("Basic"); - CAMP_GROUND = FACTORY.createLodging(); - CAMP_GROUND.setDescription("Camp ground"); - CAMP_GROUND.setName("WetAndCold"); - CATALOG_2005.addLodging(FIVE_STAR_HOTEL); - CATALOG_2005.addLodging(YOUTH_HOSTEL); - CATALOG_2005.addLodging(CAMP_GROUND); - WINTER_HOLIDAY.setDefaultLodging(YOUTH_HOSTEL); - - // Transporation - GREYHOUND_BUS = FACTORY.createTransportation(); - GREYHOUND_BUS.setArrivalTime("14:30"); - GREYHOUND_BUS.setPrice(25.50); - CATALOG_2005.addTransportation(GREYHOUND_BUS); - EXECUTIVE_JET = FACTORY.createTransportation(); - EXECUTIVE_JET.setArrivalTime("11:10"); - EXECUTIVE_JET.setPrice(1500.99); - CATALOG_2005.addTransportation(EXECUTIVE_JET); - - // Accounts - PRESIDENT = FACTORY.createAccount(); - PRESIDENT.setFirstName("George"); - PRESIDENT.setLastName("Bush"); - PRESIDENT.setState("TX"); - PRESIDENT.setPhone("1112223333"); - PRESIDENT.setCountry("U.S.A"); - DENTIST = FACTORY.createAccount(); - DENTIST.setFirstName("Tooth"); - DENTIST.setLastName("Fairy"); - DENTIST.setState("CA"); - DENTIST.setPhone("4543219876"); - DENTIST.setCountry("PainLand"); - SANTA_CLAUS = FACTORY.createAccount(); - SANTA_CLAUS.setFirstName("Chris"); - SANTA_CLAUS.setLastName("Chringle"); - SANTA_CLAUS.setState("WI"); - SANTA_CLAUS.setPhone("8617429856"); - SANTA_CLAUS.setCountry("NorthPole"); - CATALOG_2005.addAccount(PRESIDENT); - CATALOG_2005.addAccount(DENTIST); - CATALOG_2005.addAccount(SANTA_CLAUS); - - // Signons - SIGNON_ADMINISTRATOR = new Signon("Administrator", "Foo123Bar"); - SIGNON_JOEBLOGGS = new Signon("JoeBloggs", "Harry5Potter"); - CATALOG_2005.addSignon(SIGNON_ADMINISTRATOR); - CATALOG_2005.addSignon(SIGNON_JOEBLOGGS); - - CART = FACTORY.createCart(); - - // initTrees(); - } -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Signon.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Signon.java deleted file mode 100644 index f6fae9f3..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Signon.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.examples.databinding.model; - -import org.eclipse.jface.examples.databinding.ModelObject; - -public class Signon extends ModelObject { - - String userId; - String password; - - public Signon(String aUserId, String aPassword) { - userId = aUserId; - password = aPassword; - } - public String getPassword() { - return password; - } - public void setPassword(String aPassword) { - String oldValue = password; - password = aPassword; - firePropertyChange("password",oldValue,password); - } - public String getUserId() { - return userId; - } - public void setUserId(String aUserId) { - String oldValue = userId; - userId = aUserId; - firePropertyChange("userId",oldValue,userId); - } - -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/SimpleCart.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/SimpleCart.java deleted file mode 100644 index 8fa45fa6..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/SimpleCart.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.examples.databinding.model; - -import org.eclipse.jface.examples.databinding.ModelObject; - -/** - * @since 3.2 - * - */ -public class SimpleCart extends ModelObject { - - private int numItems; - - public int getNumItems() { - return numItems; - } - - public void setNumItems(int numItems) { - firePropertyChange("numItems", this.numItems, this.numItems = numItems); - } - -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/SimpleModel.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/SimpleModel.java deleted file mode 100644 index cec1927d..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/SimpleModel.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2005 David Orme <djo@coconut-palm-software.com> - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * David Orme - Initial API and implementation - */ -package org.eclipse.jface.examples.databinding.model; - -import java.util.LinkedList; - - -public class SimpleModel { - public SimpleModel() { - // Add some sample data to our personList... - personList.add(new SimplePerson("John", "1234", "Wheaton", "IL")); - personList.add(new SimplePerson("Jane", "1234", "Glen Ellyn", "IL")); - personList.add(new SimplePerson("Frank", "1234", "Lombard", "IL")); - personList.add(new SimplePerson("Joe", "1234", "Elmhurst", "IL")); - personList.add(new SimplePerson("Chet", "1234", "Oak Lawn", "IL")); - personList.add(new SimplePerson("Wilbur", "1234", "Austin", "IL")); - personList.add(new SimplePerson("Elmo", "1234", "Chicago", "IL")); - } - - // Now a PersonList property... - - LinkedList personList = new LinkedList(); - - public LinkedList getPersonList() { - return personList; - } - -}
\ No newline at end of file diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/SimpleOrder.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/SimpleOrder.java deleted file mode 100644 index 7636a4c5..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/SimpleOrder.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * The Pampered Chef - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.examples.databinding.model; - -import java.util.Date; - -import org.eclipse.jface.examples.databinding.ModelObject; - -/** - * @since 1.0 - * - */ -public class SimpleOrder extends ModelObject { - - private int orderNumber; - private Date date; - - /** - * @return Returns the date. - */ - public Date getDate() { - return date; - } - - /** - * @param date The date to set. - */ - public void setDate(Date date) { - this.date = date; - } - - /** - * @return Returns the orderNumber. - */ - public int getOrderNumber() { - return orderNumber; - } - - /** - * @param orderNumber The orderNumber to set. - */ - public void setOrderNumber(int orderNumber) { - this.orderNumber = orderNumber; - } - - /** - * @param i - * @param date - */ - public SimpleOrder(int i, Date date) { - this.orderNumber = i; - this.date = date; - } - -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/SimplePerson.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/SimplePerson.java deleted file mode 100644 index 5bdddf5f..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/SimplePerson.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (C) 2005 David Orme <djo@coconut-palm-software.com> - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * David Orme - Initial API and implementation - * Brad Reynolds (bug 139407) - */ -package org.eclipse.jface.examples.databinding.model; - -import java.util.Date; -import java.util.LinkedList; -import java.util.List; - -import org.eclipse.jface.examples.databinding.ModelObject; - -public class SimplePerson extends ModelObject { - - private String name = ""; - private String address = ""; - private String city = ""; - private String state = ""; - private SimpleCart cart = new SimpleCart(); - - private List orders = new LinkedList(); - - public SimplePerson(String name, String address, String city, String state) { - this.name = name; - this.address = address; - this.city = city; - this.state = state; - - int numOrders = (int) (Math.random() * 5); - for (int i=0; i < numOrders; ++i) { - orders.add(new SimpleOrder(i, new Date())); - } - } - - public SimplePerson() {} - - /** - * @return Returns the address. - */ - public String getAddress() { - return address; - } - - /** - * @param address The address to set. - */ - public void setAddress(String address) { - String old = this.address; - this.address = address; - firePropertyChange("address", old, address); - } - - /** - * @return Returns the city. - */ - public String getCity() { - return city; - } - - /** - * @param city The city to set. - */ - public void setCity(String city) { - String old = this.city; - firePropertyChange("city", old, this.city = city); - } - - /** - * @return Returns the name. - */ - public String getName() { - return name; - } - - /** - * @param name The name to set. - */ - public void setName(String name) { - firePropertyChange("name", this.name, this.name = name); - } - - /** - * @return Returns the state. - */ - public String getState() { - return state; - } - - /** - * @param state The state to set. - */ - public void setState(String state) { - firePropertyChange("state", this.state, this.state = state); //$NON-NLS-1$ - } - - /** - * @return Returns the orders. - */ - public List getOrders() { - return orders; - } - - public SimpleCart getCart() { - return cart; - } - - public void setCart(SimpleCart cart) { - firePropertyChange("cart", this.cart, this.cart = cart); //$NON-NLS-1$ - } -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Transportation.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Transportation.java deleted file mode 100644 index 39fbc084..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Transportation.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.examples.databinding.model; - -import org.eclipse.jface.examples.databinding.ModelObject; - -public class Transportation extends ModelObject { - - private String arrivalTime; - private double price; - - public void setArrivalTime(String string) { - String oldValue = arrivalTime; - arrivalTime = string; - firePropertyChange("arrivaltime",oldValue,string); - } - - public String getArrivalTime(){ - return arrivalTime; - } - - public double getPrice() { - return price; - } - - public void setPrice(double aPrice) { - double oldPrice = price; - price = aPrice; - firePropertyChange("price",new Double(oldPrice),new Double(price)); - } - -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/nestedselection/TestMasterDetail.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/nestedselection/TestMasterDetail.java deleted file mode 100644 index 980c75a5..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/nestedselection/TestMasterDetail.java +++ /dev/null @@ -1,300 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 116920 - *******************************************************************************/ - -package org.eclipse.jface.examples.databinding.nestedselection; - -import org.eclipse.core.databinding.Binding; -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.UpdateValueStrategy; -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.conversion.IConverter; -import org.eclipse.core.databinding.observable.IObserving; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.validation.IValidator; -import org.eclipse.core.databinding.validation.ValidationStatus; -import org.eclipse.core.internal.databinding.conversion.ObjectToStringConverter; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; -import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; -import org.eclipse.jface.databinding.viewers.ViewersObservables; -import org.eclipse.jface.examples.databinding.model.SimpleModel; -import org.eclipse.jface.examples.databinding.model.SimpleOrder; -import org.eclipse.jface.examples.databinding.model.SimplePerson; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.swt.widgets.Text; - -/** - * @since 1.0 - * - */ -public class TestMasterDetail { - /** - * @since 3.2 - * - */ - private static final class CustomUpdateValueStrategy extends - UpdateValueStrategy { - protected IStatus doSet(IObservableValue observableValue, Object value) { - IStatus result = super.doSet(observableValue, value); - if (result.isOK()) { - Object changed = observableValue; - if (changed instanceof IObserving) { - changed = ((IObserving) changed).getObserved(); - } - System.out.println("changed: " + changed); - } - return result; - } - } - - /** - * @param args - */ - public static void main(String[] args) { - new TestMasterDetail().run(); - } - - private Shell shell = null; // @jve:decl-index=0:visual-constraint="10,10" - - private Table personsTable = null; - - private Label label1 = null; - - private Text name = null; - - private Label label2 = null; - - private Text address = null; - - private Label label3 = null; - - private Text city = null; - - private Label label4 = null; - - private Text state = null; - - private Table ordersTable = null; - - private Text validationStatus; - - /** - * This method initializes table - * - */ - private void createTable() { - GridData gridData = new org.eclipse.swt.layout.GridData(); - gridData.grabExcessHorizontalSpace = true; - gridData.verticalAlignment = org.eclipse.swt.layout.GridData.FILL; - gridData.horizontalSpan = 2; - gridData.grabExcessVerticalSpace = true; - gridData.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL; - personsTable = new Table(shell, SWT.FULL_SELECTION); - personsTable.setHeaderVisible(true); - personsTable.setLayoutData(gridData); - personsTable.setLinesVisible(true); - TableColumn tableColumn = new TableColumn(personsTable, SWT.NONE); - tableColumn.setWidth(60); - tableColumn.setText("Name"); - TableColumn tableColumn1 = new TableColumn(personsTable, SWT.NONE); - tableColumn1.setWidth(60); - tableColumn1.setText("State"); - } - - /** - * This method initializes table1 - * - */ - private void createTable1() { - GridData gridData5 = new org.eclipse.swt.layout.GridData(); - gridData5.horizontalSpan = 2; - gridData5.verticalAlignment = org.eclipse.swt.layout.GridData.FILL; - gridData5.grabExcessHorizontalSpace = true; - gridData5.grabExcessVerticalSpace = true; - gridData5.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL; - ordersTable = new Table(shell, SWT.FULL_SELECTION); - ordersTable.setHeaderVisible(true); - ordersTable.setLayoutData(gridData5); - ordersTable.setLinesVisible(true); - TableColumn tableColumn2 = new TableColumn(ordersTable, SWT.NONE); - tableColumn2.setWidth(60); - tableColumn2.setText("Order No"); - TableColumn tableColumn3 = new TableColumn(ordersTable, SWT.NONE); - tableColumn3.setWidth(60); - tableColumn3.setText("Date"); - } - - /** - * This method initializes sShell - */ - private void createShell() { - GridData gridData5 = new org.eclipse.swt.layout.GridData(); - gridData5.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL; - gridData5.verticalAlignment = org.eclipse.swt.layout.GridData.CENTER; - GridData gridData4 = new org.eclipse.swt.layout.GridData(); - gridData4.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL; - gridData4.verticalAlignment = org.eclipse.swt.layout.GridData.CENTER; - GridData gridData3 = new org.eclipse.swt.layout.GridData(); - gridData3.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL; - gridData3.verticalAlignment = org.eclipse.swt.layout.GridData.CENTER; - GridData gridData2 = new org.eclipse.swt.layout.GridData(); - gridData2.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL; - gridData2.verticalAlignment = org.eclipse.swt.layout.GridData.CENTER; - GridData gridData1 = new org.eclipse.swt.layout.GridData(); - gridData1.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL; - gridData1.verticalAlignment = org.eclipse.swt.layout.GridData.CENTER; - GridLayout gridLayout = new GridLayout(); - gridLayout.numColumns = 2; - shell = new Shell(); - shell.setText("Shell"); - createTable(); - shell.setLayout(gridLayout); - shell.setSize(new org.eclipse.swt.graphics.Point(495, 357)); - label1 = new Label(shell, SWT.NONE); - label1.setText("Name"); - name = new Text(shell, SWT.BORDER); - name.setLayoutData(gridData1); - label2 = new Label(shell, SWT.NONE); - label2.setText("Address"); - address = new Text(shell, SWT.BORDER); - address.setLayoutData(gridData2); - label3 = new Label(shell, SWT.NONE); - label3.setText("City"); - city = new Text(shell, SWT.BORDER); - city.setLayoutData(gridData4); - label4 = new Label(shell, SWT.NONE); - label4.setText("State"); - state = new Text(shell, SWT.BORDER); - state.setLayoutData(gridData3); - createTable1(); - validationStatus = new Text(shell, SWT.READ_ONLY | SWT.BORDER); - } - - private void run() { - final Display display = new Display(); - - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - createShell(); - bind(shell); - - shell.setSize(600, 600); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - } - }); - display.dispose(); - } - - SimpleModel model = new SimpleModel(); - - private void bind(Control parent) { - Realm realm = SWTObservables.getRealm(parent.getDisplay()); - - TableViewer peopleViewer = new TableViewer(personsTable); - ObservableListContentProvider peopleViewerContent = new ObservableListContentProvider(); - peopleViewer.setContentProvider(peopleViewerContent); - - IObservableMap[] attributeMaps = BeansObservables.observeMaps( - peopleViewerContent.getKnownElements(), SimplePerson.class, - new String[] { "name", "state" }); - peopleViewer.setLabelProvider(new ObservableMapLabelProvider( - attributeMaps)); - - peopleViewer.setInput(new WritableList(realm, model.getPersonList(), - SimpleModel.class)); - - IObservableValue selectedPerson = ViewersObservables - .observeSingleSelection(peopleViewer); - - DataBindingContext dbc = new DataBindingContext(realm) { - protected UpdateValueStrategy createTargetToModelUpdateValueStrategy( - IObservableValue fromValue, IObservableValue toValue) { - return new CustomUpdateValueStrategy(); - } - }; - IConverter upperCaseConverter = new IConverter() { - public Object convert(Object fromObject) { - return ((String) fromObject).toUpperCase(); - } - - public Object getFromType() { - return String.class; - } - - public Object getToType() { - return String.class; - } - }; - IValidator vowelValidator = new IValidator() { - public IStatus validate(Object value) { - String s = (String) value; - if (!s.matches("[aeiouAEIOU]*")) { - return ValidationStatus.error("only vowels allowed"); - } - return Status.OK_STATUS; - } - }; - Binding b = dbc.bindValue(SWTObservables.observeText(name, SWT.Modify), - BeansObservables.observeDetailValue(realm, selectedPerson, - "name", String.class), new CustomUpdateValueStrategy() - .setConverter(upperCaseConverter).setAfterGetValidator( - vowelValidator), null); - -// AggregateValidationStatus status = new AggregateValidationStatus(dbc -// .getBindings(), AggregateValidationStatus.MAX_SEVERITY); - dbc.bindValue(SWTObservables.observeText(validationStatus, SWT.NONE), - b.getValidationStatus(), null, new UpdateValueStrategy().setConverter(new ObjectToStringConverter())); - - dbc.bindValue(SWTObservables.observeText(address, SWT.Modify), - BeansObservables.observeDetailValue(realm, selectedPerson, - "address", String.class), null, null); - - dbc.bindValue(SWTObservables.observeText(city, SWT.Modify), - BeansObservables.observeDetailValue(realm, selectedPerson, - "city", String.class), null, null); - - dbc.bindValue(SWTObservables.observeText(state, SWT.Modify), - BeansObservables.observeDetailValue(realm, selectedPerson, - "state", String.class), null, null); - - TableViewer ordersViewer = new TableViewer(ordersTable); - ObservableListContentProvider ordersViewerContent = new ObservableListContentProvider(); - ordersViewer.setContentProvider(ordersViewerContent); - ordersViewer.setLabelProvider(new ObservableMapLabelProvider( - BeansObservables.observeMaps(ordersViewerContent - .getKnownElements(), SimpleOrder.class, new String[] { - "orderNumber", "date" }))); - - IObservableList orders = BeansObservables.observeDetailList(realm, - selectedPerson, "orders", SimpleOrder.class); - ordersViewer.setInput(orders); - } -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/radioGroup/RadioGroup.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/radioGroup/RadioGroup.java deleted file mode 100644 index 02e8f5db..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/radioGroup/RadioGroup.java +++ /dev/null @@ -1,559 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.examples.databinding.radioGroup; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import org.eclipse.jface.examples.databinding.ducks.DuckType; -import org.eclipse.swt.SWT; -import org.eclipse.swt.SWTException; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; - -/** - * This object decorates a bunch of SWT.RADIO buttons and provides saner - * selection semantics than you get by default with those radio buttons. - * <p> - * Its API is basically the same API as List, but with unnecessary methods - * removed. - */ -public class RadioGroup { - - private final IRadioButton[] buttons; - private final Object[] values; - IRadioButton oldSelection = null; - IRadioButton selectedButton = null; - IRadioButton potentialNewSelection = null; - - /** (Non-API) - * Interface IRadioButton. A duck interface that is used internally by RadioGroup - * and by RadioGroup's unit tests. - */ - public static interface IRadioButton { - void setData(String string, Object object); - void addSelectionListener(SelectionListener selectionListener); - void setSelection(boolean b); - boolean getSelection(); - boolean isFocusControl(); - String getText(); - void setText(String string); - void notifyListeners(int eventType, Event object); - } - - /** - * Constructs an instance of this widget given an array of Button objects to wrap. - * The Button objects must have been created with the SWT.RADIO style bit set, - * and they must all be in the same Composite. - * - * @param radioButtons Object[] an array of radio buttons to wrap. - * @param values Object[] an array of objects corresponding to the value of each radio button. - */ - public RadioGroup(Object[] radioButtons, Object[] values) { - IRadioButton[] buttons = new IRadioButton[radioButtons.length]; - if (buttons.length < 1) { - throw new IllegalArgumentException("A RadioGroup must manage at least one Button"); - } - for (int i = 0; i < buttons.length; i++) { - if (!DuckType.instanceOf(IRadioButton.class, radioButtons[i])) { - throw new IllegalArgumentException("A radio button was not passed"); - } - buttons[i] = (IRadioButton) DuckType.implement(IRadioButton.class, radioButtons[i]); - buttons[i].setData(Integer.toString(i), new Integer(i)); - buttons[i].addSelectionListener(selectionListener); - } - this.buttons = buttons; - this.values = values; - } - - /** - * Returns the object corresponding to the currently-selected radio button - * or null if no radio button is selected. - * - * @return the object corresponding to the currently-selected radio button - * or null if no radio button is selected. - */ - public Object getSelection() { - int selectionIndex = getSelectionIndex(); - if (selectionIndex < 0) - return ""; - return values[selectionIndex]; - } - - /** - * Sets the selected radio button to the radio button whose model object - * equals() the object specified by newSelection. If !newSelection.equals() - * any model object managed by this radio group, deselects all radio buttons. - * - * @param newSelection A model object corresponding to one of the model - * objects associated with one of the radio buttons. - */ - public void setSelection(Object newSelection) { - deselectAll(); - for (int i = 0; i < values.length; i++) { - if (values[i].equals(newSelection)) { - setSelection(i); - return; - } - } - } - - private SelectionListener selectionListener = new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - widgetSelected(e); - } - - public void widgetSelected(SelectionEvent e) { - potentialNewSelection = getButton(e); - if (! potentialNewSelection.getSelection()) { - return; - } - if (potentialNewSelection.equals(selectedButton)) { - return; - } - - if (fireWidgetChangeSelectionEvent(e)) { - oldSelection = selectedButton; - selectedButton = potentialNewSelection; - if (oldSelection == null) { - oldSelection = selectedButton; - } - - fireWidgetSelectedEvent(e); - } - } - - private IRadioButton getButton(SelectionEvent e) { - // If the actual IRadioButton is a test fixture, then the test fixture can't - // set e.widget, so the button object will be in e.data instead and a dummy - // Widget will be in e.widget. - if (e.data != null) { - return (IRadioButton) e.data; - } - return (IRadioButton) DuckType.implement(IRadioButton.class, e.widget); - } - }; - - private List widgetChangeListeners = new LinkedList(); - - protected boolean fireWidgetChangeSelectionEvent(SelectionEvent e) { - for (Iterator listenersIter = widgetChangeListeners.iterator(); listenersIter.hasNext();) { - VetoableSelectionListener listener = (VetoableSelectionListener) listenersIter.next(); - listener.canWidgetChangeSelection(e); - if (!e.doit) { - rollbackSelection(); - return false; - } - } - return true; - } - - private void rollbackSelection() { - Display.getCurrent().asyncExec(new Runnable() { - public void run() { - potentialNewSelection.setSelection(false); - selectedButton.setSelection(true); -// selectedButton.notifyListeners(SWT.Selection, null); - } - }); - } - - - /** - * Adds the listener to the collection of listeners who will - * be notified when the receiver's selection is about to change, by sending - * it one of the messages defined in the <code>VetoableSelectionListener</code> - * interface. - * <p> - * <code>widgetSelected</code> is called when the selection changes. - * <code>widgetDefaultSelected</code> is typically called when an item is double-clicked. - * </p> - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see VetoableSelectionListener - * @see #removeVetoableSelectionListener - * @see SelectionEvent - */ - public void addVetoableSelectionListener(VetoableSelectionListener listener) { - widgetChangeListeners.add(listener); - } - - /** - * Removes the listener from the collection of listeners who will - * be notified when the receiver's selection is about to change. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see VetoableSelectionListener - * @see #addVetoableSelectionListener - */ - public void removeVetoableSelectionListener(VetoableSelectionListener listener) { - widgetChangeListeners.remove(listener); - } - - - private List widgetSelectedListeners = new ArrayList(); - - protected void fireWidgetSelectedEvent(SelectionEvent e) { - for (Iterator listenersIter = widgetSelectedListeners.iterator(); listenersIter.hasNext();) { - SelectionListener listener = (SelectionListener) listenersIter.next(); - listener.widgetSelected(e); - } - } - - protected void fireWidgetDefaultSelectedEvent(SelectionEvent e) { - fireWidgetSelectedEvent(e); - } - - /** - * Adds the listener to the collection of listeners who will - * be notified when the receiver's selection changes, by sending - * it one of the messages defined in the <code>SelectionListener</code> - * interface. - * <p> - * <code>widgetSelected</code> is called when the selection changes. - * <code>widgetDefaultSelected</code> is typically called when an item is double-clicked. - * </p> - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #removeSelectionListener - * @see SelectionEvent - */ - public void addSelectionListener(SelectionListener listener) { - widgetSelectedListeners.add(listener); - } - - /** - * Removes the listener from the collection of listeners who will - * be notified when the receiver's selection changes. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #addSelectionListener - */ - public void removeSelectionListener(SelectionListener listener) { - widgetSelectedListeners.remove(listener); - } - - /** - * Deselects the item at the given zero-relative index in the receiver. - * If the item at the index was already deselected, it remains - * deselected. Indices that are out of range are ignored. - * - * @param index the index of the item to deselect - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ - public void deselect (int index) { - if (index < 0 || index >= buttons.length) - return; - buttons[index].setSelection(false); - } - - /** - * Deselects all selected items in the receiver. - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ - public void deselectAll () { - for (int i = 0; i < buttons.length; i++) - buttons[i].setSelection(false); - } - - /** - * Returns the zero-relative index of the item which currently - * has the focus in the receiver, or -1 if no item has focus. - * - * @return the index of the selected item - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ - public int getFocusIndex () { - for (int i = 0; i < buttons.length; i++) { - if (buttons[i].isFocusControl()) { - return i; - } - } - return -1; - } - - /** - * Returns the item at the given, zero-relative index in the - * receiver. Throws an exception if the index is out of range. - * - * @param index the index of the item to return - * @return the item at the given index - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * FIXME: tck - this should be renamed to getItemText() - */ - public String getItem (int index) { - if (index < 0 || index >= buttons.length) - SWT.error(SWT.ERROR_INVALID_RANGE, null, "getItem for a nonexistant item"); - return buttons[index].getText(); - } - - /** - * Returns the number of items contained in the receiver. - * - * @return the number of items - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ - public int getItemCount () { - return buttons.length; - } - - /** - * Returns a (possibly empty) array of <code>String</code>s which - * are the items in the receiver. - * <p> - * Note: This is not the actual structure used by the receiver - * to maintain its list of items, so modifying the array will - * not affect the receiver. - * </p> - * - * @return the items in the receiver's list - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ - public String [] getItems () { - List itemStrings = new ArrayList(); - for (int i = 0; i < buttons.length; i++) { - itemStrings.add(buttons[i].getText()); - } - return (String[]) itemStrings.toArray(new String[itemStrings.size()]); - } - - public Object[] getButtons() { - return buttons; - } - - /** - * Returns the zero-relative index of the item which is currently - * selected in the receiver, or -1 if no item is selected. - * - * @return the index of the selected item or -1 - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ - public int getSelectionIndex () { - for (int i = 0; i < buttons.length; i++) { - if (buttons[i].getSelection() == true) { - return i; - } - } - return -1; - } - - /** - * Gets the index of an item. - * <p> - * The list is searched starting at 0 until an - * item is found that is equal to the search item. - * If no item is found, -1 is returned. Indexing - * is zero based. - * - * @param string the search item - * @return the index of the item - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ - public int indexOf (String string) { - for (int i = 0; i < buttons.length; i++) { - if (buttons[i].getText().equals(string)) { - return i; - } - } - return -1; - } - - /** - * Searches the receiver's list starting at the given, - * zero-relative index until an item is found that is equal - * to the argument, and returns the index of that item. If - * no item is found or the starting index is out of range, - * returns -1. - * - * @param string the search item - * @param start the zero-relative index at which to start the search - * @return the index of the item - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ - public int indexOf (String string, int start) { - for (int i = start; i < buttons.length; i++) { - if (buttons[i].getText().equals(string)) { - return i; - } - } - return -1; - } - - /** - * Returns <code>true</code> if the item is selected, - * and <code>false</code> otherwise. Indices out of - * range are ignored. - * - * @param index the index of the item - * @return the visibility state of the item at the index - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ - public boolean isSelected (int index) { - return buttons[index].getSelection(); - } - - /** - * Selects the item at the given zero-relative index in the receiver's - * list. If the item at the index was already selected, it remains - * selected. Indices that are out of range are ignored. - * - * @param index the index of the item to select - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ - public void select (int index) { - if (index < 0 || index >= buttons.length) - return; - buttons[index].setSelection(true); - } - - /** - * Sets the text of the item in the receiver's list at the given - * zero-relative index to the string argument. This is equivalent - * to <code>remove</code>'ing the old item at the index, and then - * <code>add</code>'ing the new item at that index. - * - * @param index the index for the item - * @param string the new text for the item - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ - public void setItem (int index, String string) { - if (index < 0 || index >= buttons.length) - SWT.error(SWT.ERROR_INVALID_RANGE, null, "setItem for a nonexistant item"); - buttons[index].setText(string); - } - - /** - * Selects the item at the given zero-relative index in the receiver. - * If the item at the index was already selected, it remains selected. - * The current selection is first cleared, then the new item is selected. - * Indices that are out of range are ignored. - * - * @param index the index of the item to select - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * @see List#deselectAll() - * @see List#select(int) - */ - public void setSelection (int index) { - if (index < 0 || index > buttons.length - 1) { - return; - } - buttons[index].setSelection(true); - } - -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/radioGroup/VetoableSelectionListener.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/radioGroup/VetoableSelectionListener.java deleted file mode 100644 index 86f5d7b4..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/radioGroup/VetoableSelectionListener.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.examples.databinding.radioGroup; - -import org.eclipse.swt.events.SelectionEvent; - -/** - * Interface VetoableSelectionListener. An interface for SelectionListeners - * that permit the new selection to be vetoed before widgetSelected or - * widgetDefaultSelected is called. - */ -public interface VetoableSelectionListener { - /** - * Method widgetCanChangeSelection. Indicates that the selection is - * about to be changed. Setting e.doit to false will prevent the - * selection from changing. - * - * @param e The SelectionEvent that is being processed. - */ - public void canWidgetChangeSelection(SelectionEvent e); -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet000HelloWorld.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet000HelloWorld.java deleted file mode 100644 index 492dcdc0..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet000HelloWorld.java +++ /dev/null @@ -1,121 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 The Pampered Chef, Inc. 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: - * The Pampered Chef, Inc. - initial API and implementation - * Brad Reynolds - bug 116920 - ******************************************************************************/ - -package org.eclipse.jface.examples.databinding.snippets; - -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.RowLayout; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -/** - * Hello, databinding. Bind changes in a GUI to a Model object but don't worry - * about propogating changes from the Model to the GUI. - * <p> - * Illustrates the basic Model-ViewModel-Binding-View architecture typically - * used in data binding applications. - */ -public class Snippet000HelloWorld { - public static void main(String[] args) { - Display display = new Display(); - final ViewModel viewModel = new ViewModel(); - - Realm.runWithDefault(SWTObservables.getRealm(display), - new Runnable() { - public void run() { - final Shell shell = new View(viewModel).createShell(); - // The SWT event loop - Display display = Display.getCurrent(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - } - }); - // Print the results - System.out.println("person.getName() = " - + viewModel.getPerson().getName()); - } - - // The data model class. This is normally a persistent class of some sort. - // - // In this example, we only push changes from the GUI to the model, so we - // don't worry about implementing JavaBeans bound properties. If we need - // our GUI to automatically reflect changes in the Person object, the - // Person object would need to implement the JavaBeans property change - // listener methods. - static class Person { - // A property... - String name = "HelloWorld"; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - } - - // The View's model--the root of our Model graph for this particular GUI. - // - // Typically each View class has a corresponding ViewModel class. - // The ViewModel is responsible for getting the objects to edit from the - // DAO. Since this snippet doesn't have any persistent objects to - // retrieve, this ViewModel just instantiates a model object to edit. - static class ViewModel { - // The model to bind - private Person person = new Person(); - - public Person getPerson() { - return person; - } - } - - // The GUI view - static class View { - private ViewModel viewModel; - private Text name; - - public View(ViewModel viewModel) { - this.viewModel = viewModel; - } - - public Shell createShell() { - // Build a UI - Display display = Display.getDefault(); - Shell shell = new Shell(display); - shell.setLayout(new RowLayout(SWT.VERTICAL)); - name = new Text(shell, SWT.BORDER); - - // Bind it - DataBindingContext bindingContext = new DataBindingContext(); - Person person = viewModel.getPerson(); - - bindingContext.bindValue(SWTObservables.observeText(name, - SWT.Modify), BeansObservables.observeValue(person, "name"), - null, null); - - // Open and return the Shell - shell.pack(); - shell.open(); - return shell; - } - } - -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet001NestedSelectionWithCombo.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet001NestedSelectionWithCombo.java deleted file mode 100644 index c701255f..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet001NestedSelectionWithCombo.java +++ /dev/null @@ -1,215 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 The Pampered Chef, Inc. 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: - * The Pampered Chef, Inc. - initial API and implementation - * Brad Reynolds - bug 116920 - ******************************************************************************/ - -package org.eclipse.jface.examples.databinding.snippets; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.util.ArrayList; -import java.util.HashSet; - -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.Observables; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; -import org.eclipse.jface.databinding.viewers.ViewersObservables; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.jface.viewers.ArrayContentProvider; -import org.eclipse.jface.viewers.ComboViewer; -import org.eclipse.jface.viewers.ListViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.List; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -/** - * Demonstrates nested selection.<br> - * At the first level, user may select a person.<br> - * At the second level, user may select a city to associate with the selected<br> - * person or edit the person's name. - */ -public class Snippet001NestedSelectionWithCombo { - public static void main(String[] args) { - ViewModel viewModel = new ViewModel(); - Shell shell = new View(viewModel).createShell(); - - // The SWT event loop - Display display = Display.getCurrent(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - } - - // Minimal JavaBeans support - public static abstract class AbstractModelObject { - private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( - this); - - public void addPropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(listener); - } - - public void addPropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(propertyName, - listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(listener); - } - - public void removePropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(propertyName, - listener); - } - - protected void firePropertyChange(String propertyName, Object oldValue, - Object newValue) { - propertyChangeSupport.firePropertyChange(propertyName, oldValue, - newValue); - } - } - - // The data model class. This is normally a persistent class of some sort. - // - // This example implements full JavaBeans bound properties so that changes - // to instances of this class will automatically be propogated to the UI. - public static class Person extends AbstractModelObject { - // Constructor - public Person(String name, String city) { - this.name = name; - this.city = city; - } - - // Some JavaBean bound properties... - String name; - - String city; - - public String getName() { - return name; - } - - public void setName(String name) { - String oldValue = this.name; - this.name = name; - firePropertyChange("name", oldValue, name); - } - - public String getCity() { - return city; - } - - public void setCity(String city) { - String oldValue = this.city; - this.city = city; - firePropertyChange("city", oldValue, city); - } - } - - // The View's model--the root of our GUI's Model graph - // - // Typically each View class has a corresponding ViewModel class. - // The ViewModel is responsible for getting the objects to edit from the - // DAO. Since this snippet doesn't have any persistent objects to - // retrieve, this ViewModel just instantiates some objects to edit. - // - // This ViewModel also implements JavaBean bound properties. - static class ViewModel extends AbstractModelObject { - // The model to bind - private ArrayList people = new ArrayList(); - { - people.add(new Person("Wile E. Coyote", "Tucson")); - people.add(new Person("Road Runner", "Lost Horse")); - people.add(new Person("Bugs Bunny", "Forrest")); - } - - // Choice of cities for the Combo - private ArrayList cities = new ArrayList(); - { - cities.add("Tucson"); - cities.add("AcmeTown"); - cities.add("Lost Horse"); - cities.add("Forrest"); - cities.add("Lost Mine"); - } - - public ArrayList getPeople() { - return people; - } - - public ArrayList getCities() { - return cities; - } - } - - // The GUI view - static class View { - private ViewModel viewModel; - - public View(ViewModel viewModel) { - this.viewModel = viewModel; - } - - public Shell createShell() { - // Build a UI - Shell shell = new Shell(Display.getCurrent()); - Realm realm = SWTObservables.getRealm(shell.getDisplay()); - - List peopleList = new List(shell, SWT.BORDER); - Text name = new Text(shell, SWT.BORDER); - Combo city = new Combo(shell, SWT.BORDER | SWT.READ_ONLY); - - ListViewer peopleListViewer = new ListViewer(peopleList); - IObservableMap attributeMap = BeansObservables.observeMap( - Observables.staticObservableSet(realm, new HashSet( - viewModel.getPeople())), Person.class, "name"); - peopleListViewer.setLabelProvider(new ObservableMapLabelProvider( - attributeMap)); - peopleListViewer.setContentProvider(new ArrayContentProvider()); - peopleListViewer.setInput(viewModel.getPeople()); - - DataBindingContext dbc = new DataBindingContext(realm); - IObservableValue selectedPerson = ViewersObservables - .observeSingleSelection(peopleListViewer); - dbc.bindValue(SWTObservables.observeText(name, SWT.Modify), - BeansObservables.observeDetailValue(realm, selectedPerson, - "name", String.class), null, null); - - ComboViewer cityViewer = new ComboViewer(city); - cityViewer.setContentProvider(new ArrayContentProvider()); - cityViewer.setInput(viewModel.getCities()); - - IObservableValue citySelection = ViewersObservables - .observeSingleSelection(cityViewer); - dbc.bindValue(citySelection, BeansObservables.observeDetailValue( - realm, selectedPerson, "city", String.class), null, null); - - GridLayoutFactory.swtDefaults().applyTo(shell); - // Open and return the Shell - shell.pack(); - shell.open(); - return shell; - } - } - -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet002UpdateComboRetainSelection.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet002UpdateComboRetainSelection.java deleted file mode 100644 index 09882e74..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet002UpdateComboRetainSelection.java +++ /dev/null @@ -1,185 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 The Pampered Chef, Inc. 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: - * The Pampered Chef, Inc. - initial API and implementation - * Brad Reynolds - bug 116920 - ******************************************************************************/ - -package org.eclipse.jface.examples.databinding.snippets; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.masterdetail.MasterDetailObservables; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.RowLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; - -/** - * Shows how to bind a Combo so that when update its items, the selection is - * retained if at all possible. - * - * @since 3.2 - */ -public class Snippet002UpdateComboRetainSelection { - public static void main(String[] args) { - final Display display = new Display(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - ViewModel viewModel = new ViewModel(); - Shell shell = new View(viewModel).createShell(); - - // The SWT event loop - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - - // Print the results - System.out.println(viewModel.getText()); - } - }); - display.dispose(); - } - - // Minimal JavaBeans support - public static abstract class AbstractModelObject { - private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); - - public void addPropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(listener); - } - - public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(propertyName, listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(listener); - } - - public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(propertyName, listener); - } - - protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { - propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue); - } - } - - // The View's model--the root of our Model graph for this particular GUI. - public static class ViewModel extends AbstractModelObject { - private String text = "beef"; - - private List choices = new ArrayList(); - { - choices.add("pork"); - choices.add("beef"); - choices.add("poultry"); - choices.add("vegatables"); - } - - public List getChoices() { - return choices; - } - - public void setChoices(List choices) { - List old = this.choices; - this.choices = choices; - firePropertyChange("choices", old, choices); - } - - public String getText() { - return text; - } - - public void setText(String text) { - String oldValue = this.text; - this.text = text; - firePropertyChange("text", oldValue, text); - } - } - - // The GUI view - static class View { - private ViewModel viewModel; - /** - * used to make a new choices array unique - */ - static int count; - - public View(ViewModel viewModel) { - this.viewModel = viewModel; - } - - public Shell createShell() { - // Build a UI - Shell shell = new Shell(Display.getCurrent()); - shell.setLayout(new RowLayout(SWT.VERTICAL)); - - Combo combo = new Combo(shell, SWT.BORDER | SWT.READ_ONLY); - Button reset = new Button(shell, SWT.NULL); - reset.setText("reset collection"); - reset.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - List newList = new ArrayList(); - newList.add("Chocolate"); - newList.add("Vanilla"); - newList.add("Mango Parfait"); - newList.add("beef"); - newList.add("Cheesecake"); - newList.add(Integer.toString(++count)); - viewModel.setChoices(newList); - } - }); - - // Print value out first - System.out.println(viewModel.getText()); - - DataBindingContext dbc = new DataBindingContext(); - - IObservableList list = MasterDetailObservables.detailList(BeansObservables.observeValue(viewModel, "choices"), - getListDetailFactory(), - String.class); - dbc.bindList(SWTObservables.observeItems(combo), list, null, null); - dbc.bindValue(SWTObservables.observeText(combo), BeansObservables.observeValue(viewModel, "text"), null, null); - - // Open and return the Shell - shell.pack(); - shell.open(); - return shell; - } - } - - private static IObservableFactory getListDetailFactory() { - return new IObservableFactory() { - public IObservable createObservable(Object target) { - WritableList list = WritableList.withElementType(String.class); - list.addAll((Collection) target); - return list; - } - }; - } -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet003UpdateComboBindUsingViewer.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet003UpdateComboBindUsingViewer.java deleted file mode 100644 index dd616344..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet003UpdateComboBindUsingViewer.java +++ /dev/null @@ -1,191 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 The Pampered Chef, Inc. 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: - * The Pampered Chef, Inc. - initial API and implementation - * Brad Reynolds - bug 116920 - ******************************************************************************/ - -package org.eclipse.jface.examples.databinding.snippets; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.masterdetail.MasterDetailObservables; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; -import org.eclipse.jface.databinding.viewers.ViewersObservables; -import org.eclipse.jface.viewers.ComboViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.RowLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; - -/** - * Shows how to bind a Combo so that when update its items, the selection is - * retained if at all possible. - * - * @since 3.2 - */ -public class Snippet003UpdateComboBindUsingViewer { - public static void main(String[] args) { - final Display display = new Display(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - ViewModel viewModel = new ViewModel(); - Shell shell = new View(viewModel).createShell(); - - // The SWT event loop - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - // Print the results - System.out.println(viewModel.getText()); - } - }); - display.dispose(); - } - - // Minimal JavaBeans support - public static abstract class AbstractModelObject { - private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( - this); - - public void addPropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(listener); - } - - public void addPropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(propertyName, - listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(listener); - } - - public void removePropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(propertyName, - listener); - } - - protected void firePropertyChange(String propertyName, Object oldValue, - Object newValue) { - propertyChangeSupport.firePropertyChange(propertyName, oldValue, - newValue); - } - } - - // The View's model--the root of our Model graph for this particular GUI. - public static class ViewModel extends AbstractModelObject { - private String text = "beef"; - - private List choices = new ArrayList(); - { - choices.add("pork"); - choices.add("beef"); - choices.add("poultry"); - choices.add("vegatables"); - } - - public List getChoices() { - return choices; - } - - public void setChoices(List choices) { - this.choices = choices; - firePropertyChange("choices", null, null); - } - - public String getText() { - return text; - } - - public void setText(String text) { - String oldValue = this.text; - this.text = text; - firePropertyChange("text", oldValue, text); - } - } - - // The GUI view - static class View { - private ViewModel viewModel; - - public View(ViewModel viewModel) { - this.viewModel = viewModel; - } - - public Shell createShell() { - // Build a UI - Shell shell = new Shell(Display.getCurrent()); - shell.setLayout(new RowLayout(SWT.VERTICAL)); - - Combo combo = new Combo(shell, SWT.BORDER | SWT.READ_ONLY); - ComboViewer viewer = new ComboViewer(combo); - Button reset = new Button(shell, SWT.NULL); - reset.setText("reset collection"); - reset.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - List newList = new ArrayList(); - newList.add("Chocolate"); - newList.add("Vanilla"); - newList.add("Mango Parfait"); - newList.add("beef"); - newList.add("Cheesecake"); - viewModel.setChoices(newList); - } - }); - - // Print value out first - System.out.println(viewModel.getText()); - - DataBindingContext dbc = new DataBindingContext(); - IObservableList list = MasterDetailObservables.detailList( - BeansObservables.observeValue(viewModel, "choices"), - getListDetailFactory(), String.class); - viewer.setContentProvider(new ObservableListContentProvider()); - viewer.setInput(list); - - dbc.bindValue(ViewersObservables.observeSingleSelection(viewer), - BeansObservables.observeValue(viewModel, "text"), null, null); - - // Open and return the Shell - shell.pack(); - shell.open(); - return shell; - } - } - - private static IObservableFactory getListDetailFactory() { - return new IObservableFactory() { - public IObservable createObservable(Object target) { - WritableList list = WritableList.withElementType(String.class); - list.addAll((Collection) target); - return list; - } - }; - } -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet004DataBindingContextErrorLabel.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet004DataBindingContextErrorLabel.java deleted file mode 100644 index ac674aa5..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet004DataBindingContextErrorLabel.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Brad Reynolds - bug 116920, 159768 - ******************************************************************************/ - -package org.eclipse.jface.examples.databinding.snippets; - -import org.eclipse.core.databinding.AggregateValidationStatus; -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.UpdateValueStrategy; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.databinding.validation.IValidator; -import org.eclipse.core.databinding.validation.ValidationStatus; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -/** - * Snippet that displays how to bind the validation error of the - * {@link DataBindingContext} to a label. http://www.eclipse.org - * - * @since 3.2 - */ -public class Snippet004DataBindingContextErrorLabel { - public static void main(String[] args) { - final Display display = new Display(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - Shell shell = new Shell(display); - shell.setText("Data Binding Snippet 004"); - shell.setLayout(new GridLayout(2, false)); - - new Label(shell, SWT.NONE).setText("Enter '5' to be valid:"); - - Text text = new Text(shell, SWT.BORDER); - WritableValue value = WritableValue.withValueType(String.class); - new Label(shell, SWT.NONE).setText("Error:"); - - Label errorLabel = new Label(shell, SWT.BORDER); - errorLabel.setForeground(display.getSystemColor(SWT.COLOR_RED)); - GridDataFactory.swtDefaults().hint(200, SWT.DEFAULT).applyTo( - errorLabel); - - DataBindingContext dbc = new DataBindingContext(); - - // Bind the text to the value. - dbc.bindValue( - SWTObservables.observeText(text, SWT.Modify), - value, - new UpdateValueStrategy().setAfterConvertValidator(new FiveValidator()), - null); - - // Bind the error label to the validation error on the dbc. - dbc.bindValue(SWTObservables.observeText(errorLabel), - new AggregateValidationStatus(dbc.getBindings(), - AggregateValidationStatus.MAX_SEVERITY), null, - null); - - shell.pack(); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - } - }); - display.dispose(); - } - - /** - * Validator that returns validation errors for any value other than 5. - * - * @since 3.2 - */ - private static class FiveValidator implements IValidator { - public IStatus validate(Object value) { - return ("5".equals(value)) ? Status.OK_STATUS : ValidationStatus - .error("the value was '" + value + "', not '5'"); - } - } -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet005MenuUpdater.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet005MenuUpdater.java deleted file mode 100644 index f84b40c9..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet005MenuUpdater.java +++ /dev/null @@ -1,85 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 116920 - *******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; - -import java.util.Date; -import java.util.Iterator; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.internal.databinding.provisional.swt.MenuUpdater; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.MenuItem; -import org.eclipse.swt.widgets.Shell; - -/** - */ -public class Snippet005MenuUpdater { - public static void main(String[] args) { - final Display display = new Display(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - Shell shell = new Shell(display); - - final WritableList menuItemStrings = new WritableList(); - display.asyncExec(new Runnable() { - public void run() { - System.out.println("adding item"); - menuItemStrings.add(new Date().toString()); - display.timerExec(5000, this); - } - }); - - Menu bar = new Menu(shell, SWT.BAR); - shell.setMenuBar(bar); - MenuItem fileItem = new MenuItem(bar, SWT.CASCADE); - fileItem.setText("&Test Menu"); - final Menu submenu = new Menu(shell, SWT.DROP_DOWN); - fileItem.setMenu(submenu); - new MenuUpdater(submenu) { - protected void updateMenu() { - System.out.println("updating menu"); - MenuItem[] items = submenu.getItems(); - int itemIndex = 0; - for (Iterator it = menuItemStrings.iterator(); it - .hasNext();) { - MenuItem item; - if (itemIndex < items.length) { - item = items[itemIndex++]; - } else { - item = new MenuItem(submenu, SWT.NONE); - } - String string = (String) it.next(); - item.setText(string); - } - while (itemIndex < items.length) { - items[itemIndex++].dispose(); - } - } - }; - - shell.open(); - - // The SWT event loop - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - } - }); - display.dispose(); - } -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet006Spreadsheet.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet006Spreadsheet.java deleted file mode 100644 index 214b4f15..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet006Spreadsheet.java +++ /dev/null @@ -1,315 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 116920 - *******************************************************************************/ - -package org.eclipse.jface.examples.databinding.snippets; - -import java.text.NumberFormat; -import java.text.ParseException; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.core.databinding.observable.value.ComputedValue; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.internal.databinding.provisional.swt.TableUpdater; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.ControlEditor; -import org.eclipse.swt.custom.TableCursor; -import org.eclipse.swt.events.KeyAdapter; -import org.eclipse.swt.events.KeyEvent; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.swt.widgets.TableItem; -import org.eclipse.swt.widgets.Text; - -/** - * @since 1.1 - * - */ -public class Snippet006Spreadsheet { - - private static final int COUNTER_UPDATE_DELAY = 1000; - - private static final int NUM_COLUMNS = 6; - - private static final int NUM_ROWS = 16; - - /** - * 0 for no output, 1 for some, 2 for more - */ - private static int DEBUG_LEVEL = 0; - - /** - * If true, there will be a automatic counter at B1. - */ - private static boolean FUNKY_COUNTER = false; - - /** - * // * If true, all formulas (except for row 1 and column A) will be the - * sum of the values of their left and top neighbouring cells. - */ - private static boolean FUNKY_FORMULAS = true; - - static WritableValue[][] cellFormulas = new WritableValue[NUM_ROWS][NUM_COLUMNS]; - - static ComputedValue[][] cellValues = new ComputedValue[NUM_ROWS][NUM_COLUMNS]; - - static class ComputedCellValue extends ComputedValue { - private final IObservableValue cellFormula; - - private boolean calculating; - - ComputedCellValue(IObservableValue cellFormula) { - this.cellFormula = cellFormula; - } - - protected Object calculate() { - if (calculating) { - return "#cycle"; - } - try { - calculating = true; - return evaluate(cellFormula.getValue()); - } finally { - calculating = false; - } - } - - private Object evaluate(Object value) { - if (DEBUG_LEVEL >= 2) { - System.out.println("evaluating " + this + " ..."); - } - if (value == null) { - return ""; - } - try { - String s = (String) value; - if (!s.startsWith("=")) { - return s; - } - String addition = s.substring(1); - int indexOfPlus = addition.indexOf('+'); - String operand1 = addition.substring(0, indexOfPlus); - double value1 = eval(operand1); - String operand2 = addition.substring(indexOfPlus + 1); - double value2 = eval(operand2); - return NumberFormat.getNumberInstance().format(value1 + value2); - } catch (Exception ex) { - return ex.getMessage(); - } - } - - /** - * @param s - * @return - * @throws ParseException - */ - private double eval(String s) throws ParseException { - if (s.length() == 0) { - return 0; - } - char character = s.charAt(0); - if (Character.isLetter(character)) { - character = Character.toLowerCase(character); - // reference to other cell - int columnIndex = character - 'a'; - int rowIndex = 0; - rowIndex = NumberFormat.getNumberInstance().parse( - s.substring(1)).intValue() - 1; - String value = (String) cellValues[rowIndex][columnIndex] - .getValue(); - return value.length() == 0 ? 0 : NumberFormat - .getNumberInstance().parse(value).doubleValue(); - } - return NumberFormat.getNumberInstance().parse(s).doubleValue(); - } - } - - protected static int counter; - - public static void main(String[] args) { - - final Display display = new Display(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - Shell shell = new Shell(display); - shell.setText("Data Binding Snippet 006"); - - final Table table = new Table(shell, SWT.BORDER | SWT.MULTI - | SWT.FULL_SELECTION | SWT.VIRTUAL); - table.setLinesVisible(true); - table.setHeaderVisible(true); - - for (int i = 0; i < NUM_COLUMNS; i++) { - TableColumn tableColumn = new TableColumn(table, SWT.NONE); - tableColumn.setText(Character.toString((char) ('A' + i))); - tableColumn.setWidth(60); - } - WritableList list = new WritableList(); - for (int i = 0; i < NUM_ROWS; i++) { - list.add(new Object()); - for (int j = 0; j < NUM_COLUMNS; j++) { - cellFormulas[i][j] = new WritableValue(); - cellValues[i][j] = new ComputedCellValue( - cellFormulas[i][j]); - if (!FUNKY_FORMULAS || i == 0 || j == 0) { - cellFormulas[i][j].setValue(""); - } else { - cellFormulas[i][j].setValue("=" - + cellReference(i - 1, j) + "+" - + cellReference(i, j - 1)); - } - } - } - - new TableUpdater(table, list) { - protected void updateItem(int rowIndex, TableItem item, Object element) { - if (DEBUG_LEVEL >= 1) { - System.out.println("updating row " + rowIndex); - } - for (int j = 0; j < NUM_COLUMNS; j++) { - item.setText(j, (String) cellValues[rowIndex][j] - .getValue()); - } - } - }; - - if (FUNKY_COUNTER) { - // counter in A1 - display.asyncExec(new Runnable() { - public void run() { - cellFormulas[0][1].setValue("" + counter++); - display.timerExec(COUNTER_UPDATE_DELAY, this); - } - }); - } - - // create a TableCursor to navigate around the table - final TableCursor cursor = new TableCursor(table, SWT.NONE); - // create an editor to edit the cell when the user hits "ENTER" - // while over a cell in the table - final ControlEditor editor = new ControlEditor(cursor); - editor.grabHorizontal = true; - editor.grabVertical = true; - - cursor.addSelectionListener(new SelectionAdapter() { - // when the TableEditor is over a cell, select the - // corresponding row - // in - // the table - public void widgetSelected(SelectionEvent e) { - table.setSelection(new TableItem[] { cursor.getRow() }); - } - - // when the user hits "ENTER" in the TableCursor, pop up a - // text - // editor so that - // they can change the text of the cell - public void widgetDefaultSelected(SelectionEvent e) { - final Text text = new Text(cursor, SWT.NONE); - TableItem row = cursor.getRow(); - int rowIndex = table.indexOf(row); - int columnIndex = cursor.getColumn(); - text - .setText((String) cellFormulas[rowIndex][columnIndex] - .getValue()); - text.addKeyListener(new KeyAdapter() { - public void keyPressed(KeyEvent e) { - // close the text editor and copy the data over - // when the user hits "ENTER" - if (e.character == SWT.CR) { - TableItem row = cursor.getRow(); - int rowIndex = table.indexOf(row); - int columnIndex = cursor.getColumn(); - cellFormulas[rowIndex][columnIndex] - .setValue(text.getText()); - text.dispose(); - } - // close the text editor when the user hits - // "ESC" - if (e.character == SWT.ESC) { - text.dispose(); - } - } - }); - editor.setEditor(text); - text.setFocus(); - } - }); - // Hide the TableCursor when the user hits the "MOD1" or "MOD2" - // key. - // This alows the user to select multiple items in the table. - cursor.addKeyListener(new KeyAdapter() { - public void keyPressed(KeyEvent e) { - if (e.keyCode == SWT.MOD1 || e.keyCode == SWT.MOD2 - || (e.stateMask & SWT.MOD1) != 0 - || (e.stateMask & SWT.MOD2) != 0) { - cursor.setVisible(false); - } - } - }); - // Show the TableCursor when the user releases the "MOD2" or - // "MOD1" key. - // This signals the end of the multiple selection task. - table.addKeyListener(new KeyAdapter() { - public void keyReleased(KeyEvent e) { - if (e.keyCode == SWT.MOD1 - && (e.stateMask & SWT.MOD2) != 0) - return; - if (e.keyCode == SWT.MOD2 - && (e.stateMask & SWT.MOD1) != 0) - return; - if (e.keyCode != SWT.MOD1 - && (e.stateMask & SWT.MOD1) != 0) - return; - if (e.keyCode != SWT.MOD2 - && (e.stateMask & SWT.MOD2) != 0) - return; - - TableItem[] selection = table.getSelection(); - TableItem row = (selection.length == 0) ? table - .getItem(table.getTopIndex()) : selection[0]; - table.showItem(row); - cursor.setSelection(row, 0); - cursor.setVisible(true); - cursor.setFocus(); - } - }); - - GridLayoutFactory.fillDefaults().generateLayout(shell); - shell.setSize(400, 300); - shell.open(); - - // The SWT event loop - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - } - }); - display.dispose(); - } - - private static String cellReference(int rowIndex, int columnIndex) { - String cellReference = "" + ((char) ('A' + columnIndex)) - + (rowIndex + 1); - return cellReference; - } - -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet007ColorLabelProvider.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet007ColorLabelProvider.java deleted file mode 100644 index aac19d25..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet007ColorLabelProvider.java +++ /dev/null @@ -1,220 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * IBM Corporation - see bug 137934 - ******************************************************************************/ - -package org.eclipse.jface.examples.databinding.snippets; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.Observables; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; -import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ITableColorProvider; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; - -/** - * An example showing how to create a {@link ILabelProvider label provider} that - * to provide colors. - * - * @since 3.2 - */ -public class Snippet007ColorLabelProvider { - /** - * @param args - */ - public static void main(String[] args) { - final List persons = new ArrayList(); - persons.add(new Person("Fiona Apple", Person.FEMALE)); - persons.add(new Person("Elliot Smith", Person.MALE)); - persons.add(new Person("Diana Krall", Person.FEMALE)); - persons.add(new Person("David Gilmour", Person.MALE)); - - final Display display = new Display(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - Shell shell = new Shell(display); - shell.setText("Gender Bender"); - shell.setLayout(new GridLayout()); - - Table table = new Table(shell, SWT.SINGLE | SWT.H_SCROLL - | SWT.V_SCROLL | SWT.BORDER); - GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); - table.setLayoutData(gridData); - table.setHeaderVisible(true); - table.setLinesVisible(true); - TableColumn column = new TableColumn(table, SWT.NONE); - column.setText("No"); - column.setWidth(20); - column = new TableColumn(table, SWT.NONE); - column.setText("Name"); - column.setWidth(100); - final TableViewer viewer = new TableViewer(table); - - IObservableList observableList = Observables - .staticObservableList(persons); - ObservableListContentProvider contentProvider = new ObservableListContentProvider(); - - viewer.setContentProvider(contentProvider); - - // this does not have to correspond to the columns in the table, - // we just list all attributes that affect the table content. - IObservableMap[] attributes = BeansObservables.observeMaps( - contentProvider.getKnownElements(), Person.class, - new String[] { "name", "gender" }); - - class ColorLabelProvider extends ObservableMapLabelProvider - implements ITableColorProvider { - Color male = display.getSystemColor(SWT.COLOR_BLUE); - - Color female = new Color(display, 255, 192, 203); - - ColorLabelProvider(IObservableMap[] attributes) { - super(attributes); - } - - // to drive home the point that attributes does not have to - // match - // the columns - // in the table, we change the column text as follows: - public String getColumnText(Object element, int index) { - if (index == 0) { - return Integer - .toString(persons.indexOf(element) + 1); - } - return ((Person) element).getName(); - } - - public Color getBackground(Object element, int index) { - return null; - } - - public Color getForeground(Object element, int index) { - if (index == 0) - return null; - Person person = (Person) element; - return (person.getGender() == Person.MALE) ? male - : female; - } - - public void dispose() { - super.dispose(); - female.dispose(); - } - } - viewer.setLabelProvider(new ColorLabelProvider(attributes)); - - viewer.setInput(observableList); - - table.getColumn(0).pack(); - - Button button = new Button(shell, SWT.PUSH); - button.setText("Toggle Gender"); - button.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent arg0) { - StructuredSelection selection = (StructuredSelection) viewer - .getSelection(); - if (selection != null && !selection.isEmpty()) { - Person person = (Person) selection - .getFirstElement(); - person - .setGender((person.getGender() == Person.MALE) ? Person.FEMALE - : Person.MALE); - } - } - }); - - shell.setSize(300, 400); - shell.open(); - - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - } - }); - display.dispose(); - } - - private static class Person { - static final int MALE = 0; - - static final int FEMALE = 1; - - private String name; - - private int gender; - - private PropertyChangeSupport changeSupport = new PropertyChangeSupport( - this); - - Person(String name, int gender) { - this.name = name; - this.gender = gender; - } - - /** - * Returns the name. Method declared public to satisfy Java bean - * conventions - * - * @return the name - */ - public String getName() { - return name; - } - - /** - * @param listener - */ - public void addPropertyChangeListener(PropertyChangeListener listener) { - changeSupport.addPropertyChangeListener(listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - changeSupport.removePropertyChangeListener(listener); - } - - /** - * Returns the gender. Method declared public to satisfy Java bean - * conventions - * - * @return the gender - */ - public int getGender() { - return gender; - } - - void setGender(int gender) { - changeSupport.firePropertyChange("gender", this.gender, - this.gender = gender); - } - } -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet008ComputedValue.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet008ComputedValue.java deleted file mode 100644 index 38433d91..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet008ComputedValue.java +++ /dev/null @@ -1,168 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - ******************************************************************************/ - -package org.eclipse.jface.examples.databinding.snippets; - -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.UpdateValueStrategy; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.ComputedValue; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.FillLayout; -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; - -/** - * Snippet that demostrates a simple use case using ComputedValue to format a - * name as the user enters first and last name. - * - * @since 3.2 - */ -public class Snippet008ComputedValue { - /** - * @param args - */ - public static void main(String[] args) { - final Display display = new Display(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - - final UI ui = new UI(shell); - final Data data = new Data(); - - // Bind the UI to the Data. - DataBindingContext dbc = new DataBindingContext(); - dbc.bindValue(SWTObservables.observeText(ui.firstName, - SWT.Modify), data.firstName, null, null); - dbc.bindValue(SWTObservables.observeText(ui.lastName, - SWT.Modify), data.lastName, null, null); - - // Construct the formatted name observable. - FormattedName formattedName = new FormattedName(data.firstName, - data.lastName); - - // Bind the formatted name Text to the formatted name - // observable. - dbc.bindValue(SWTObservables.observeText(ui.formattedName, - SWT.None), formattedName, new UpdateValueStrategy(false, UpdateValueStrategy.POLICY_NEVER), null); - - shell.pack(); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - } - }); - display.dispose(); - } - - /** - * Creates the formatted name on change of the first or last name - * observables. - * <p> - * The key to understanding ComputedValue is understanding that it knows of - * the observables that are queried without being told. This is done with - * {@link ObservableTracker} voodoo. When calculate() is invoked - * <code>ObservableTracker</code> records the observables that are - * queried. It then exposes those observables and <code>ComputedValue</code> - * can listen to changes in those objects and react accordingly. - * </p> - * - * @since 3.2 - */ - static class FormattedName extends ComputedValue { - private IObservableValue firstName; - - private IObservableValue lastName; - - FormattedName(IObservableValue firstName, IObservableValue lastName) { - this.firstName = firstName; - this.lastName = lastName; - } - - protected Object calculate() { - String lastName = (String) this.lastName.getValue(); - String firstName = (String) this.firstName.getValue(); - lastName = (lastName != null && lastName.length() > 0) ? lastName - : "[Last Name]"; - firstName = (firstName != null && firstName.length() > 0) ? firstName - : "[First Name]"; - - StringBuffer buffer = new StringBuffer(); - buffer.append(lastName).append(", ").append(firstName); - - return buffer.toString(); - } - } - - static class Data { - final WritableValue firstName; - - final WritableValue lastName; - - Data() { - firstName = new WritableValue("", String.class); - lastName = new WritableValue("", String.class); - } - } - - /** - * Composite that creates the UI. - * - * @since 3.2 - */ - static class UI extends Composite { - final Text firstName; - - final Text lastName; - - final Text formattedName; - - UI(Composite parent) { - super(parent, SWT.NONE); - - GridLayoutFactory.swtDefaults().numColumns(2).applyTo(this); - - new Label(this, SWT.NONE).setText("First Name:"); - new Label(this, SWT.NONE).setText("Last Name"); - - GridDataFactory gdf = GridDataFactory.swtDefaults().align(SWT.FILL, - SWT.FILL).grab(true, false); - firstName = new Text(this, SWT.BORDER); - gdf.applyTo(firstName); - - lastName = new Text(this, SWT.BORDER); - gdf.applyTo(lastName); - - gdf = GridDataFactory.swtDefaults().span(2, 1).grab(true, false) - .align(SWT.FILL, SWT.BEGINNING); - Label label = new Label(this, SWT.NONE); - label.setText("Formatted Name:"); - gdf.applyTo(label); - - formattedName = new Text(this, SWT.BORDER); - formattedName.setEditable(false); - gdf.applyTo(formattedName); - } - } -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet009TableViewer.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet009TableViewer.java deleted file mode 100644 index a96d5ec5..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet009TableViewer.java +++ /dev/null @@ -1,180 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 The Pampered Chef, Inc. 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: - * Coconut Palm Software, Inc. - Initial API and implementation - ******************************************************************************/ - -package org.eclipse.jface.examples.databinding.snippets; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.util.LinkedList; -import java.util.List; - -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; -import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Table; - -/** - * Demonstrates binding a TableViewer to a collection. - */ -public class Snippet009TableViewer { - public static void main(String[] args) { - ViewModel viewModel = new ViewModel(); - Shell shell = new View(viewModel).createShell(); - - // The SWT event loop - Display display = Display.getCurrent(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - } - - // Minimal JavaBeans support - public static abstract class AbstractModelObject { - private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( - this); - - public void addPropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(listener); - } - - public void addPropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(propertyName, - listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(listener); - } - - public void removePropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(propertyName, - listener); - } - - protected void firePropertyChange(String propertyName, Object oldValue, - Object newValue) { - propertyChangeSupport.firePropertyChange(propertyName, oldValue, - newValue); - } - } - - // The data model class. This is normally a persistent class of some sort. - static class Person extends AbstractModelObject { - // A property... - String name = "John Smith"; - - public Person(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - public void setName(String name) { - String oldValue = this.name; - this.name = name; - firePropertyChange("name", oldValue, name); - } - } - - // The View's model--the root of our Model graph for this particular GUI. - // - // Typically each View class has a corresponding ViewModel class. - // The ViewModel is responsible for getting the objects to edit from the - // data access tier. Since this snippet doesn't have any persistent objects - // ro retrieve, this ViewModel just instantiates a model object to edit. - static class ViewModel { - // The model to bind - private List people = new LinkedList(); { - people.add(new Person("Steve Northover")); - people.add(new Person("Grant Gayed")); - people.add(new Person("Veronika Irvine")); - people.add(new Person("Mike Wilson")); - people.add(new Person("Christophe Cornu")); - people.add(new Person("Lynne Kues")); - people.add(new Person("Silenio Quarti")); - } - - public List getPeople() { - return people; - } - } - - // The GUI view - static class View { - private ViewModel viewModel; - private Table committers; - - public View(ViewModel viewModel) { - this.viewModel = viewModel; - } - - public Shell createShell() { - // Build a UI - Display display = Display.getDefault(); - Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - committers = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION); - committers.setLinesVisible(true); - - // Set up data binding. In an RCP application, the threading Realm - // will be set for you automatically by the Workbench. In an SWT - // application, you can do this once, wrpping your binding - // method call. - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - DataBindingContext bindingContext = new DataBindingContext(); - bindGUI(bindingContext); - } - }); - - // Open and return the Shell - shell.setSize(100, 300); - shell.open(); - return shell; - } - - protected void bindGUI(DataBindingContext bindingContext) { - // Since we're using a JFace Viewer, we do first wrap our Table... - TableViewer peopleViewer = new TableViewer(committers); - - // Create a standard content provider - ObservableListContentProvider peopleViewerContentProvider = - new ObservableListContentProvider(); - peopleViewer.setContentProvider(peopleViewerContentProvider); - - // And a standard label provider that maps columns - IObservableMap[] attributeMaps = BeansObservables.observeMaps( - peopleViewerContentProvider.getKnownElements(), Person.class, - new String[] { "name" }); - peopleViewer.setLabelProvider(new ObservableMapLabelProvider(attributeMaps)); - - // Now set the Viewer's input - peopleViewer.setInput(new WritableList(viewModel.getPeople(), Person.class)); - } - } - -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet010MasterDetail.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet010MasterDetail.java deleted file mode 100644 index b4cb4261..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet010MasterDetail.java +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - ******************************************************************************/ - -package org.eclipse.jface.examples.databinding.snippets; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; - -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.UpdateValueStrategy; -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.databinding.viewers.ViewersObservables; -import org.eclipse.jface.viewers.ArrayContentProvider; -import org.eclipse.jface.viewers.ListViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -/** - * Snippet that displays a simple master detail use case. A list of persons is - * displayed in a list and upon selection the name of the selected person will - * be displayed in a Text widget. - */ -public class Snippet010MasterDetail { - public static void main(String[] args) { - final Display display = new Display(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - Shell shell = new Shell(display); - shell.setLayout(new GridLayout()); - - Person[] persons = new Person[] { new Person("Me"), - new Person("Myself"), new Person("I") }; - - ListViewer viewer = new ListViewer(shell); - viewer.setContentProvider(new ArrayContentProvider()); - viewer.setInput(persons); - - Text name = new Text(shell, SWT.BORDER | SWT.READ_ONLY); - - // 1. Observe changes in selection. - IObservableValue selection = ViewersObservables - .observeSingleSelection(viewer); - - // 2. Observe the name property of the current selection. - IObservableValue detailObservable = BeansObservables - .observeDetailValue(Realm.getDefault(), selection, - "name", String.class); - - // 3. Bind the Text widget to the name detail (selection's - // name). - new DataBindingContext().bindValue(SWTObservables.observeText( - name, SWT.None), detailObservable, - new UpdateValueStrategy(false, - UpdateValueStrategy.POLICY_NEVER), null); - - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - } - }); - display.dispose(); - } - - public static class Person { - private String name; - private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this); - - Person(String name) { - this.name = name; - } - - public void addPropertyChangeListener(PropertyChangeListener listener) { - changeSupport.addPropertyChangeListener(listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - changeSupport.removePropertyChangeListener(listener); - } - - /** - * @return Returns the name. - */ - public String getName() { - return name; - } - - public String toString() { - return name; - } - } -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet011ValidateMultipleBindingsSnippet.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet011ValidateMultipleBindingsSnippet.java deleted file mode 100644 index 59ae4c20..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet011ValidateMultipleBindingsSnippet.java +++ /dev/null @@ -1,129 +0,0 @@ - /******************************************************************************* - * Copyright (c) 2007 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - ******************************************************************************/ - -package org.eclipse.jface.examples.databinding.snippets; - -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.UpdateValueStrategy; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.observable.value.ValueChangeEvent; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.databinding.validation.IValidator; -import org.eclipse.core.databinding.validation.ValidationStatus; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jface.databinding.swt.SWTObservables; -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.Shell; -import org.eclipse.swt.widgets.Text; - -/** - * Snippet that validates values across multiple bindings on change of each - * observable. If the values of the target observables are not equal the model - * is not updated. When the values are equal they will be written to sysout. - * - * @author Brad Reynolds - */ -public class Snippet011ValidateMultipleBindingsSnippet { - public static void main(String[] args) { - Realm.runWithDefault(SWTObservables.getRealm(Display.getDefault()), - new Runnable() { - public void run() { - Snippet011ValidateMultipleBindingsSnippet.run(); - } - }); - } - - private static void run() { - Shell shell = new Shell(); - - View view = new View(shell); - final Model model = new Model(); - - DataBindingContext dbc = new DataBindingContext(); - dbc.bindValue(SWTObservables.observeText(view.text1, SWT.Modify), - model.value1, new UpdateValueStrategy() - .setAfterConvertValidator(new CrossFieldValidator( - model.value2)), null); - dbc.bindValue(SWTObservables.observeText(view.text2, SWT.Modify), - model.value2, new UpdateValueStrategy() - .setAfterConvertValidator(new CrossFieldValidator( - model.value1)), null); - - // DEBUG - print to show value change - model.value1.addValueChangeListener(new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - System.out.println("Value 1: " + model.value1.getValue()); - } - }); - - // DEBUG - print to show value change - model.value2.addValueChangeListener(new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - System.out.println("Value 2: " + model.value2.getValue()); - } - }); - - shell.pack(); - shell.open(); - Display display = shell.getDisplay(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); - } - - /** - * @since 3.2 - * - */ - private static final class CrossFieldValidator implements IValidator { - /** - * - */ - private final IObservableValue other; - - /** - * @param model - */ - private CrossFieldValidator(IObservableValue other) { - this.other = other; - } - - public IStatus validate(Object value) { - if (!value.equals(other.getValue())) { - return ValidationStatus.ok(); - } - return ValidationStatus.error("values cannot be the same"); - } - } - - static class Model { - WritableValue value1 = new WritableValue(); - WritableValue value2 = new WritableValue(); - } - - static class View { - Text text1; - Text text2; - - View(Composite composite) { - composite.setLayout(new GridLayout(2, true)); - text1 = new Text(composite, SWT.BORDER); - text2 = new Text(composite, SWT.BORDER); - } - } -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet012CompositeUpdater.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet012CompositeUpdater.java deleted file mode 100644 index af9fee0c..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet012CompositeUpdater.java +++ /dev/null @@ -1,112 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.jface.examples.databinding.snippets; - -import java.util.Timer; -import java.util.TimerTask; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.internal.databinding.provisional.swt.CompositeUpdater; -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.widgets.Button; -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.Widget; - -/** - * @since 3.2 - * - */ -public class Snippet012CompositeUpdater { - - public static void main(String[] args) { - final Display display = new Display(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - Shell shell = new Shell(display); - - final WritableList list = new WritableList(); - - Button button = new Button(shell, SWT.PUSH); - button.setText("add"); - button.addSelectionListener(new SelectionAdapter() { - public void widgetSelected( - org.eclipse.swt.events.SelectionEvent e) { - list.add(0, new Counter()); - } - }); - - final Composite composite = new Composite(shell, SWT.None); - - new CompositeUpdater(composite, list) { - protected Widget createWidget(int index) { - Label label = new Label(composite, SWT.BORDER); - //requestLayout(label); - return label; - } - - protected void updateWidget(Widget widget, Object element) { - ((Label) widget).setText(((Counter) element).getValue() - + ""); - requestLayout((Label)widget); - } - }; - GridLayoutFactory.fillDefaults().numColumns(10).generateLayout(composite); - - GridDataFactory.fillDefaults().grab(true, true).applyTo( - composite); - - GridLayoutFactory.fillDefaults().generateLayout(shell); - shell.pack(); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - } - }); - display.dispose(); - } - - static Timer timer = new Timer(true); - - static class Counter extends WritableValue { - Counter() { - super(new Integer(0), Integer.class); - scheduleIncrementTask(); - } - - private void scheduleIncrementTask() { - timer.schedule(new TimerTask() { - public void run() { - // we have to get onto the realm (UI thread) to perform the - // increment - getRealm().asyncExec(new Runnable() { - public void run() { - Integer currentVal = (Integer) getValue(); - setValue(new Integer(currentVal.intValue() + 1)); - } - }); - scheduleIncrementTask(); - } - }, 1000); - } - } -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet013TableViewerEditing.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet013TableViewerEditing.java deleted file mode 100644 index b5cf3f4d..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet013TableViewerEditing.java +++ /dev/null @@ -1,247 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 The Pampered Chef, Inc. 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: - * The Pampered Chef, Inc. - initial API and implementation - * Tom Schindl - cell editing - ******************************************************************************/ - -package org.eclipse.jface.examples.databinding.snippets; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.util.LinkedList; -import java.util.List; - -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; -import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; -import org.eclipse.jface.databinding.viewers.ObservableValueEditingSupport; -import org.eclipse.jface.databinding.viewers.ViewersObservables; -import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.ColumnViewer; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.TableViewerColumn; -import org.eclipse.jface.viewers.TextCellEditor; -import org.eclipse.jface.viewers.ViewerCell; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.FillLayout; -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.Table; - -/** - * Demonstrates binding a TableViewer to a collection using the 3.3 Viewer APIs. - */ -public class Snippet013TableViewerEditing { - public static void main(String[] args) { - final Display display = new Display(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - ViewModel viewModel = new ViewModel(); - Shell shell = new View(viewModel).createShell(); - - // The SWT event loop - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - } - }); - } - - // Minimal JavaBeans support - public static abstract class AbstractModelObject { - private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( - this); - - public void addPropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(listener); - } - - public void addPropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(propertyName, - listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(listener); - } - - public void removePropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(propertyName, - listener); - } - - protected void firePropertyChange(String propertyName, Object oldValue, - Object newValue) { - propertyChangeSupport.firePropertyChange(propertyName, oldValue, - newValue); - } - } - - // The data model class. This is normally a persistent class of some sort. - static class Person extends AbstractModelObject { - // A property... - String name = "John Smith"; - - public Person(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - public void setName(String name) { - String oldValue = this.name; - this.name = name; - firePropertyChange("name", oldValue, name); - } - } - - // The View's model--the root of our Model graph for this particular GUI. - // - // Typically each View class has a corresponding ViewModel class. - // The ViewModel is responsible for getting the objects to edit from the - // data access tier. Since this snippet doesn't have any persistent objects - // ro retrieve, this ViewModel just instantiates a model object to edit. - static class ViewModel { - // The model to bind - private List people = new LinkedList(); - { - people.add(new Person("Steve Northover")); - people.add(new Person("Grant Gayed")); - people.add(new Person("Veronika Irvine")); - people.add(new Person("Mike Wilson")); - people.add(new Person("Christophe Cornu")); - people.add(new Person("Lynne Kues")); - people.add(new Person("Silenio Quarti")); - } - - public List getPeople() { - return people; - } - } - - /** - * Editing support that uses JFace Data Binding to control the editing - * lifecycle. The standard EditingSupport get/setValue(...) lifecycle is not - * used. - * - * @since 3.3 - */ - private static class InlineEditingSupport extends ObservableValueEditingSupport { - private CellEditor cellEditor; - - /** - * @param viewer - * @param dbc - */ - public InlineEditingSupport(ColumnViewer viewer, - DataBindingContext dbc) { - - super(viewer, dbc); - cellEditor = new TextCellEditor((Composite) viewer.getControl()); - } - - protected CellEditor getCellEditor(Object element) { - return cellEditor; - } - - protected IObservableValue doCreateCellEditorObservable( - CellEditor cellEditor) { - - return SWTObservables.observeText(cellEditor - .getControl(), SWT.Modify); - } - - protected IObservableValue doCreateElementObservable(Object element, - ViewerCell cell) { - return BeansObservables.observeValue(element, "name"); - } - } - - // The GUI view - static class View { - private ViewModel viewModel; - private Table committers; - private Label selectedCommitter; - - public View(ViewModel viewModel) { - this.viewModel = viewModel; - } - - public Shell createShell() { - // Build a UI - Display display = Display.getDefault(); - Shell shell = new Shell(display); - shell.setLayout(new FillLayout(SWT.VERTICAL)); - committers = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION); - committers.setLinesVisible(true); - - selectedCommitter = new Label(shell, SWT.NONE); - // Set up data binding. In an RCP application, the threading - // Realm - // will be set for you automatically by the Workbench. In an SWT - // application, you can do this once, wrpping your binding - // method call. - DataBindingContext bindingContext = new DataBindingContext(); - bindGUI(bindingContext); - - // Open and return the Shell - shell.setSize(100, 300); - shell.open(); - return shell; - } - - protected void bindGUI(DataBindingContext bindingContext) { - // Since we're using a JFace Viewer, we do first wrap our Table... - TableViewer peopleViewer = new TableViewer(committers); - TableViewerColumn column = new TableViewerColumn(peopleViewer, - SWT.NONE); - column.setEditingSupport(new InlineEditingSupport(peopleViewer, - bindingContext)); - column.getColumn().setWidth(100); - - // Create a standard content provider - ObservableListContentProvider peopleViewerContentProvider = new ObservableListContentProvider(); - peopleViewer.setContentProvider(peopleViewerContentProvider); - - // And a standard label provider that maps columns - IObservableMap[] attributeMaps = BeansObservables.observeMaps( - peopleViewerContentProvider.getKnownElements(), - Person.class, new String[] { "name" }); - peopleViewer.setLabelProvider(new ObservableMapLabelProvider( - attributeMaps)); - - // Now set the Viewer's input - peopleViewer.setInput(new WritableList(viewModel.getPeople(), - Person.class)); - - // bind selectedCommitter label to the name of the current selection - IObservableValue selection = ViewersObservables - .observeSingleSelection(peopleViewer); - bindingContext.bindValue(SWTObservables - .observeText(selectedCommitter), BeansObservables - .observeDetailValue(Realm.getDefault(), selection, "name", - String.class), null, null); - } - } - -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet014WizardDialog.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet014WizardDialog.java deleted file mode 100644 index 788a51d0..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet014WizardDialog.java +++ /dev/null @@ -1,162 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Boris Bokowski, IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.examples.databinding.snippets; - -import java.util.Date; - -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.UpdateValueStrategy; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.databinding.validation.IValidator; -import org.eclipse.core.databinding.validation.ValidationStatus; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.databinding.wizard.WizardPageSupport; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.wizard.IWizard; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; - -/** - * Creates and opens a wizard dialog with two simple wizard pages. - */ -public class Snippet014WizardDialog { - - static class FirstWizardPage extends WizardPage { - private final class SingleDigitValidator implements IValidator { - public IStatus validate(Object value) { - Integer i = (Integer) value; - if (i == null) { - return ValidationStatus - .info("Please enter a value."); - } - if (i.intValue() < 0 || i.intValue() > 9) { - return ValidationStatus - .error("Value must be between 0 and 9."); - } - return ValidationStatus.ok(); - } - } - - protected FirstWizardPage() { - super("First", "First Page", ImageDescriptor - .createFromImage(new Image(Display.getDefault(), 16, 16))); - } - - public void createControl(Composite parent) { - DataBindingContext dbc = new DataBindingContext(); - WizardPageSupport.create(this, dbc); - Composite composite = new Composite(parent, SWT.NONE); - Label label = new Label(composite, SWT.NONE); - label.setText("Enter a number between 0 and 9:"); - Text text = new Text(composite, SWT.BORDER); - - dbc.bindValue( - SWTObservables.observeText(text, SWT.Modify), - ((SampleWizard) getWizard()).getModel().intValue, - new UpdateValueStrategy().setAfterConvertValidator(new SingleDigitValidator()), - null); - - GridLayoutFactory.swtDefaults().numColumns(2).generateLayout( - composite); - setControl(composite); - } - } - - static class SecondWizardPage extends WizardPage { - protected SecondWizardPage() { - super("Second", "Second Page", ImageDescriptor - .createFromImage(new Image(Display.getDefault(), 16, 16))); - } - - public void createControl(Composite parent) { - DataBindingContext dbc = new DataBindingContext(); - WizardPageSupport.create(this, dbc); - Composite composite = new Composite(parent, SWT.NONE); - Label label = new Label(composite, SWT.NONE); - label.setText("Enter a date:"); - Text text = new Text(composite, SWT.BORDER); - - dbc.bindValue( - SWTObservables.observeText(text, SWT.Modify), - ((SampleWizard) getWizard()).getModel().dateValue, - null, - null); - - GridLayoutFactory.swtDefaults().numColumns(2).generateLayout( - composite); - setControl(composite); - } - } - - static class SampleWizardModel { - IObservableValue intValue = new WritableValue(null, Integer.class); - IObservableValue dateValue = new WritableValue(null, Date.class); - } - - static class SampleWizard extends Wizard { - - private SampleWizardModel model = new SampleWizardModel(); - - public void addPages() { - addPage(new FirstWizardPage()); - addPage(new SecondWizardPage()); - } - - public SampleWizardModel getModel() { - return model; - } - - public String getWindowTitle() { - return "Data Binding Snippet014"; - } - - public boolean performFinish() { - return true; - } - - } - - public static void main(String[] args) { - Display display = new Display(); - - // note that the "runWithDefault" will be done for you if you are using - // the - // Workbench as opposed to just JFace/SWT. - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - IWizard wizard = new SampleWizard(); - WizardDialog dialog = new WizardDialog(null, wizard); - dialog.open(); - // The SWT event loop - Display display = Display.getCurrent(); - while (dialog.getShell() != null - && !dialog.getShell().isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - } - }); - } - -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet015DelayTextModifyEvents.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet015DelayTextModifyEvents.java deleted file mode 100644 index eb132cf6..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet015DelayTextModifyEvents.java +++ /dev/null @@ -1,116 +0,0 @@ -/************************************************************************************************************ - * Copyright (c) 2007 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 180746) - * Boris Bokowski, IBM - initial API and implementation - ***********************************************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; - -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.observable.Observables; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.swt.ISWTObservableValue; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.internal.databinding.provisional.swt.ControlUpdater; -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.resource.FontDescriptor; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.jface.resource.LocalResourceManager; -import org.eclipse.jface.resource.ResourceManager; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Font; -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; - -public class Snippet015DelayTextModifyEvents { - - private static void createControls(Shell shell) { - final Label field1 = createLabel(shell, SWT.NONE, "Field 1 "); - - Text text1 = new Text(shell, SWT.BORDER); - GridDataFactory.fillDefaults().grab(true, false).hint(200, SWT.DEFAULT) - .applyTo(text1); - createLabel(shell, SWT.NONE, "200ms delay"); - - final Label field2 = createLabel(shell, SWT.NONE, "Field 2 "); - - Text text2 = new Text(shell, SWT.BORDER); - GridDataFactory.fillDefaults().grab(true, false).hint(200, SWT.DEFAULT) - .applyTo(text2); - - createLabel(shell, SWT.NONE, "1000ms delay"); - - final ISWTObservableValue delayed1 = SWTObservables.observeDelayedValue(200, - SWTObservables.observeText(text1, SWT.Modify)); - final ISWTObservableValue delayed2 = SWTObservables.observeDelayedValue(1000, - SWTObservables.observeText(text2, SWT.Modify)); - - // (In a real application,you would want to dispose the resource manager - // when you are done with it) - ResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources()); - final Font shellFont = shell.getFont(); - final Font italicFont = resourceManager.createFont(FontDescriptor.createFrom( - shellFont).setStyle(SWT.ITALIC)); - - final IObservableValue stale1 = Observables.observeStale(delayed1); - new ControlUpdater(field2) { - protected void updateControl() { - boolean stale = ((Boolean)stale1.getValue()).booleanValue(); - field2.setFont(stale ? italicFont : shellFont); - } - }; - - final IObservableValue stale2 = Observables.observeStale(delayed2); - new ControlUpdater(field1) { - protected void updateControl() { - boolean stale = ((Boolean)stale2.getValue()).booleanValue(); - field1.setFont(stale ? italicFont : shellFont); - } - }; - - String info = "Pending changes are applied immediately if the observed control loses focus"; - GridDataFactory.fillDefaults().span(3, 1).applyTo( - createLabel(shell, SWT.WRAP, info)); - - DataBindingContext dbc = new DataBindingContext(); - - dbc.bindValue(delayed1, delayed2, null, null); - } - - private static Label createLabel(Composite parent, int style, String text) { - Label label = new Label(parent, style); - label.setText(text); - return label; - } - - public static void main(String[] args) { - final Display display = new Display(); - - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - Shell shell = new Shell(); - shell.setLayout(new GridLayout(3, false)); - - createControls(shell); - - shell.pack(); - shell.open(); - while (!shell.isDisposed()) - if (!display.readAndDispatch()) - display.sleep(); - } - - }); - - display.dispose(); - } - -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet016TableUpdater.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet016TableUpdater.java deleted file mode 100644 index c0316fa5..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet016TableUpdater.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.jface.examples.databinding.snippets; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.internal.databinding.provisional.swt.TableUpdater; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableItem; - -/** - * @since 3.2 - * - */ -public class Snippet016TableUpdater { - public static void main(String[] args) { - final Display display = new Display(); - - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - final Shell shell = createShell(display); - GridLayoutFactory.fillDefaults().generateLayout(shell); - shell.open(); - // The SWT event loop - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - } - }); - } - - static class Stuff { - private WritableValue counter = new WritableValue(new Integer(1), Integer.class); - - public Stuff(final Display display) { - display.timerExec(1000, new Runnable() { - public void run() { - counter.setValue(new Integer(1 + ((Integer) counter - .getValue()).intValue())); - display.timerExec(1000, this); - } - }); - } - - public String toString() { - return counter.getValue().toString(); - } - } - - protected static Shell createShell(final Display display) { - Shell shell = new Shell(); - Table t = new Table(shell, SWT.VIRTUAL); - final WritableList list = new WritableList(); - new TableUpdater(t, list) { - - protected void updateItem(int index, TableItem item, Object element) { - item.setText(element.toString()); - } - }; - display.timerExec(2000, new Runnable() { - public void run() { - list.add(new Stuff(display)); - display.timerExec(2000, this); - } - }); - return shell; - } - -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet017TableViewerWithDerivedColumns.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet017TableViewerWithDerivedColumns.java deleted file mode 100644 index 7ac98aea..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet017TableViewerWithDerivedColumns.java +++ /dev/null @@ -1,317 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 The Pampered Chef, Inc. 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: - * Coconut Palm Software, Inc. - Initial API and implementation - ******************************************************************************/ - -package org.eclipse.jface.examples.databinding.snippets; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; - -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.core.databinding.observable.map.CompositeMap; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; -import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; -import org.eclipse.jface.databinding.viewers.ViewersObservables; -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.jface.viewers.ComboViewer; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerFilter; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.swt.widgets.Text; - -/** - * Demonstrates binding a TableViewer to a collection. - */ -public class Snippet017TableViewerWithDerivedColumns { - public static void main(String[] args) { - final Display display = new Display(); - - // Set up data binding. In an RCP application, the threading Realm - // will be set for you automatically by the Workbench. In an SWT - // application, you can do this once, wrapping your binding - // method call. - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - ViewModel viewModel = new ViewModel(); - Shell shell = new View(viewModel).createShell(); - - // The SWT event loop - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - } - }); - } - - // Minimal JavaBeans support - public static abstract class AbstractModelObject { - private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( - this); - - public void addPropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(listener); - } - - public void addPropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(propertyName, - listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(listener); - } - - public void removePropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(propertyName, - listener); - } - - protected void firePropertyChange(String propertyName, Object oldValue, - Object newValue) { - propertyChangeSupport.firePropertyChange(propertyName, oldValue, - newValue); - } - } - - private static Person UNKNOWN = new Person("unknown", null, null); - - // The data model class. This is normally a persistent class of some sort. - static class Person extends AbstractModelObject { - // A property... - String name = "Donald Duck"; - Person mother; - Person father; - - public Person(String name, Person mother, Person father) { - this.name = name; - this.mother = mother; - this.father = father; - } - - public String getName() { - return name; - } - - public void setName(String name) { - String oldValue = this.name; - this.name = name; - firePropertyChange("name", oldValue, name); - } - - public Person getMother() { - return mother; - } - - public void setMother(Person mother) { - firePropertyChange("mother", this.mother, this.mother = mother); - } - - public Person getFather() { - return father; - } - - public void setFather(Person father) { - firePropertyChange("father", this.father, this.father = father); - } - - public String toString() { - return name; - } - } - - // The View's model--the root of our Model graph for this particular GUI. - // - // Typically each View class has a corresponding ViewModel class. - // The ViewModel is responsible for getting the objects to edit from the - // data access tier. Since this snippet doesn't have any persistent objects - // ro retrieve, this ViewModel just instantiates a model object to edit. - static class ViewModel { - // The model to bind - private IObservableList people = new WritableList(); - { - Person fergus = new Person("Fergus McDuck", UNKNOWN, UNKNOWN); - Person downy = new Person("Downy O'Drake", UNKNOWN, UNKNOWN); - Person scrooge = new Person("Scrooge McDuck", downy, fergus); - Person hortense = new Person("Hortense McDuck", downy, fergus); - Person quackmore = new Person("Quackmore Duck", UNKNOWN, UNKNOWN); - Person della = new Person("Della Duck", hortense, quackmore); - Person donald = new Person("Donald Duck", hortense, quackmore); - donald.setFather(quackmore); - donald.setMother(hortense); - della.setFather(quackmore); - della.setMother(hortense); - hortense.setMother(downy); - hortense.setFather(fergus); - scrooge.setMother(downy); - scrooge.setFather(fergus); - people.add(UNKNOWN); - people.add(downy); - people.add(fergus); - people.add(scrooge); - people.add(quackmore); - people.add(hortense); - people.add(della); - people.add(donald); - } - - public IObservableList getPeople() { - return people; - } - } - - // The GUI view - static class View { - private ViewModel viewModel; - private Table duckFamily; - private Text nameText; - private Combo motherCombo; - private Combo fatherCombo; - - public View(ViewModel viewModel) { - this.viewModel = viewModel; - } - - public Shell createShell() { - // Build a UI - Display display = Display.getDefault(); - Shell shell = new Shell(display); - duckFamily = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION); - duckFamily.setHeaderVisible(true); - GridDataFactory.defaultsFor(duckFamily).span(2, 1).applyTo( - duckFamily); - createColumn("Name"); - createColumn("Mother"); - createColumn("Father"); - createColumn("Grandmother"); - duckFamily.setLinesVisible(true); - - new Label(shell, SWT.NONE).setText("Name:"); - nameText = new Text(shell, SWT.BORDER); - GridDataFactory.defaultsFor(nameText).grab(true, false).applyTo( - nameText); - - new Label(shell, SWT.NONE).setText("Mother:"); - motherCombo = new Combo(shell, SWT.READ_ONLY); - - new Label(shell, SWT.NONE).setText("Father:"); - fatherCombo = new Combo(shell, SWT.READ_ONLY); - - DataBindingContext bindingContext = new DataBindingContext(); - bindGUI(bindingContext); - - GridLayoutFactory.swtDefaults().numColumns(2).applyTo(shell); - // Open and return the Shell - shell.setSize(500, 300); - shell.open(); - return shell; - } - - private void createColumn(String string) { - final TableColumn column = new TableColumn(duckFamily, SWT.NONE); - column.setWidth(100); - column.setText(string); - } - - protected void bindGUI(DataBindingContext bindingContext) { - // Since we're using a JFace Viewer, we do first wrap our Table... - TableViewer peopleViewer = new TableViewer(duckFamily); - peopleViewer.addFilter(new ViewerFilter() { - public boolean select(Viewer viewer, Object parentElement, - Object element) { - return element != UNKNOWN; - } - }); - - // Create a standard content provider - ObservableListContentProvider peopleViewerContentProvider = new ObservableListContentProvider(); - peopleViewer.setContentProvider(peopleViewerContentProvider); - - // And a standard label provider that maps columns - IObservableMap nameMap = BeansObservables.observeMap( - peopleViewerContentProvider.getKnownElements(), - Person.class, "name"); - IObservableMap motherMap = BeansObservables.observeMap( - peopleViewerContentProvider.getKnownElements(), - Person.class, "mother"); - IObservableMap fatherMap = BeansObservables.observeMap( - peopleViewerContentProvider.getKnownElements(), - Person.class, "father"); - IObservableMap grandmotherMap = new CompositeMap(motherMap, - BeansObservables.setToMapFactory(Person.class, "mother")); - IObservableMap[] columnMaps = new IObservableMap[] { - nameMap, - new CompositeMap(motherMap, BeansObservables.setToMapFactory( - Person.class, "name")), - new CompositeMap(fatherMap, BeansObservables.setToMapFactory( - Person.class, "name")), - new CompositeMap(grandmotherMap, BeansObservables.setToMapFactory( - Person.class, "name")) }; - peopleViewer.setLabelProvider(new ObservableMapLabelProvider( - columnMaps)); - - // Now set the Viewer's input - peopleViewer.setInput(viewModel.getPeople()); - - IObservableValue selection = ViewersObservables - .observeSingleSelection(peopleViewer); - bindingContext - .bindValue( - SWTObservables.observeText(nameText, SWT.Modify), - BeansObservables.observeDetailValue(Realm - .getDefault(), selection, "name", - String.class), null, null); - - ComboViewer mothercomboViewer = new ComboViewer(motherCombo); - ObservableListContentProvider motherComboContentProvider = new ObservableListContentProvider(); - mothercomboViewer.setContentProvider(motherComboContentProvider); - mothercomboViewer.setLabelProvider(new ObservableMapLabelProvider( - BeansObservables.observeMap(motherComboContentProvider - .getKnownElements(), Person.class, "name"))); - mothercomboViewer.setInput(viewModel.getPeople()); - bindingContext.bindValue(ViewersObservables - .observeSingleSelection(mothercomboViewer), - BeansObservables.observeDetailValue(Realm.getDefault(), - selection, "mother", Person.class), null, null); - - ComboViewer fatherComboViewer = new ComboViewer(fatherCombo); - ObservableListContentProvider fatherComboContentProvider = new ObservableListContentProvider(); - fatherComboViewer - .setContentProvider(fatherComboContentProvider); - fatherComboViewer.setLabelProvider(new ObservableMapLabelProvider( - BeansObservables.observeMap(fatherComboContentProvider - .getKnownElements(), Person.class, "name"))); - fatherComboViewer.setInput(viewModel.getPeople()); - bindingContext.bindValue(ViewersObservables - .observeSingleSelection(fatherComboViewer), - BeansObservables.observeDetailValue(Realm.getDefault(), - selection, "father", Person.class), null, null); - } - } - -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet018CheckboxTableViewerCheckedSelection.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet018CheckboxTableViewerCheckedSelection.java deleted file mode 100644 index afdde9bf..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet018CheckboxTableViewerCheckedSelection.java +++ /dev/null @@ -1,371 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 124684) - ******************************************************************************/ - -package org.eclipse.jface.examples.databinding.snippets; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.value.ComputedValue; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; -import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; -import org.eclipse.jface.databinding.viewers.ViewersObservables; -import org.eclipse.jface.dialogs.IInputValidator; -import org.eclipse.jface.dialogs.InputDialog; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.jface.layout.TableColumnLayout; -import org.eclipse.jface.viewers.CheckboxTableViewer; -import org.eclipse.jface.viewers.ColumnWeightData; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.swt.widgets.Text; - -/** - * Snippet 018: Binding to the checked elements in a CheckboxTableViewer. - */ -public class Snippet018CheckboxTableViewerCheckedSelection { - public static void main(String[] args) { - // The SWT event loop - final Display display = Display.getDefault(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - ViewModel viewModel = createSampleModel(); - - Shell shell = new View(viewModel).createShell(); - shell.open(); - while (!shell.isDisposed()) - if (!display.readAndDispatch()) - display.sleep(); - } - }); - display.dispose(); - } - - private static ViewModel createSampleModel() { - ViewModel viewModel = new ViewModel(); - - Person stan = createPerson("Stan"); - Person kyle = createPerson("Kyle"); - Person eric = createPerson("Eric"); - Person kenny = createPerson("Kenny"); - Person wendy = createPerson("Wendy"); - Person butters = createPerson("Butters"); - - setFriends(stan, new Person[] { kyle, eric, kenny, wendy }); - setFriends(kyle, new Person[] { stan, eric, kenny }); - setFriends(eric, new Person[] { eric }); - setFriends(kenny, new Person[] { stan, kyle, eric }); - setFriends(wendy, new Person[] { stan }); - setFriends(butters, new Person[0]); - - Person[] people = new Person[] { stan, kyle, eric, kenny, wendy, - butters }; - viewModel.setPeople(Arrays.asList(people)); - return viewModel; - } - - private static Person createPerson(String name) { - Person person = new Person(); - person.setName(name); - return person; - } - - private static void setFriends(Person person, Person[] friends) { - person.setFriends(new HashSet(Arrays.asList(friends))); - } - - // Minimal JavaBeans support - public static abstract class AbstractModelObject { - private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( - this); - - public void addPropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(listener); - } - - public void addPropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(propertyName, - listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(listener); - } - - public void removePropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(propertyName, - listener); - } - - protected void firePropertyChange(String propertyName, Object oldValue, - Object newValue) { - propertyChangeSupport.firePropertyChange(propertyName, oldValue, - newValue); - } - } - - // The data model class. - static class Person extends AbstractModelObject { - private String name; - private Set friends = new HashSet(); - - public String getName() { - return name; - } - - public void setName(String name) { - firePropertyChange("name", this.name, this.name = name); - } - - public Set getFriends() { - return new HashSet(friends); - } - - public void setFriends(Set friends) { - firePropertyChange("friends", this.friends, - this.friends = new HashSet(friends)); - } - - public String toString() { - return name; - } - } - - // The View's model--the root of our Model graph for this particular GUI. - // - // Typically each View class has a corresponding ViewModel class. - // - // The ViewModel is responsible for getting the objects to edit from the - // data access tier. Since this snippet doesn't have any persistent objects - // to retrieve, this ViewModel just instantiates a model object to edit. - static class ViewModel extends AbstractModelObject { - private List people = new ArrayList(); - - public List getPeople() { - return new ArrayList(people); - } - - public void setPeople(List people) { - firePropertyChange("people", this.people, - this.people = new ArrayList(people)); - } - } - - // The GUI view - static class View { - private ViewModel viewModel; - - private Shell shell; - - private Button addPersonButton; - private Button removePersonButton; - private TableViewer peopleViewer; - private Text personName; - private CheckboxTableViewer friendsViewer; - - public View(ViewModel viewModel) { - this.viewModel = viewModel; - } - - public Shell createShell() { - // Build a UI - final Display display = Display.getCurrent(); - shell = new Shell(display); - - createUI(shell); - - // Bind UI - bindUI(); - - // Open and return the Shell - shell.setSize(shell.computeSize(400, SWT.DEFAULT)); - shell.open(); - return shell; - } - - private void createUI(Shell shell) { - shell.setText("Binding checked elements in CheckboxTableViewer"); - shell.setLayout(new GridLayout(2, false)); - - new Label(shell, SWT.NONE).setText("People"); - - Composite buttons = new Composite(shell, SWT.NONE); - GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo( - buttons); - GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(true) - .applyTo(buttons); - addPersonButton = new Button(buttons, SWT.PUSH); - addPersonButton.setText("Add"); - GridDataFactory.fillDefaults().applyTo(addPersonButton); - removePersonButton = new Button(buttons, SWT.PUSH); - removePersonButton.setText("Remove"); - GridDataFactory.fillDefaults().applyTo(removePersonButton); - - Composite peopleComposite = new Composite(shell, SWT.NONE); - GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo( - peopleComposite); - TableColumnLayout peopleColumnLayout = new TableColumnLayout(); - peopleComposite.setLayout(peopleColumnLayout); - - peopleViewer = new TableViewer(peopleComposite, SWT.SINGLE - | SWT.BORDER | SWT.FULL_SELECTION); - - Table peopleTable = peopleViewer.getTable(); - peopleTable.setHeaderVisible(true); - peopleTable.setLinesVisible(true); - - TableColumn nameColumn = new TableColumn(peopleTable, SWT.NONE); - nameColumn.setText("Name"); - peopleColumnLayout.setColumnData(nameColumn, - new ColumnWeightData(1)); - - TableColumn friendsColumn = new TableColumn(peopleTable, SWT.NONE); - friendsColumn.setText("Friends"); - peopleColumnLayout.setColumnData(friendsColumn, - new ColumnWeightData(3)); - - new Label(shell, SWT.NONE).setText("Name"); - - personName = new Text(shell, SWT.BORDER); - GridDataFactory.fillDefaults().grab(true, false) - .applyTo(personName); - - new Label(shell, SWT.NONE).setText("Friends"); - - Composite friendsComposite = new Composite(shell, SWT.NONE); - GridDataFactory.fillDefaults().grab(true, true).applyTo( - friendsComposite); - TableColumnLayout friendsColumnLayout = new TableColumnLayout(); - friendsComposite.setLayout(friendsColumnLayout); - - friendsViewer = CheckboxTableViewer.newCheckList(friendsComposite, - SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION); - - Table friendsTable = friendsViewer.getTable(); - friendsTable.setHeaderVisible(true); - friendsTable.setLinesVisible(true); - TableColumn friendNameColumn = new TableColumn(friendsTable, - SWT.NONE); - friendNameColumn.setText("Name"); - friendsColumnLayout.setColumnData(friendNameColumn, - new ColumnWeightData(1)); - - GridDataFactory.fillDefaults().grab(true, true).applyTo( - friendsViewer.getTable()); - } - - private void bindUI() { - DataBindingContext dbc = new DataBindingContext(); - - final IObservableList people = BeansObservables.observeList(Realm - .getDefault(), viewModel, "people"); - - addPersonButton.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event event) { - InputDialog dlg = new InputDialog(shell, "Add Person", - "Enter name:", "<Name>", new IInputValidator() { - public String isValid(String newText) { - if (newText == null - || newText.length() == 0) - return "Name cannot be empty"; - return null; - } - }); - if (dlg.open() == Window.OK) { - Person person = new Person(); - person.setName(dlg.getValue()); - people.add(person); - peopleViewer.setSelection(new StructuredSelection( - person)); - } - } - }); - - removePersonButton.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event event) { - IStructuredSelection selected = (IStructuredSelection) peopleViewer - .getSelection(); - if (selected.isEmpty()) - return; - Person person = (Person) selected.getFirstElement(); - if (MessageDialog.openConfirm(shell, "Remove person", - "Remove " + person.getName() + "?")) - people.remove(person); - } - }); - - ObservableListContentProvider peopleContentProvider = new ObservableListContentProvider(); - peopleViewer.setContentProvider(peopleContentProvider); - peopleViewer.setLabelProvider(new ObservableMapLabelProvider( - BeansObservables.observeMaps(peopleContentProvider - .getKnownElements(), Person.class, new String[] { - "name", "friends" }))); - peopleViewer.setInput(people); - - final IObservableValue selectedPerson = ViewersObservables - .observeSingleSelection(peopleViewer); - - IObservableValue personSelected = new ComputedValue(Boolean.TYPE) { - protected Object calculate() { - return Boolean.valueOf(selectedPerson.getValue() != null); - } - }; - dbc.bindValue(SWTObservables.observeEnabled(removePersonButton), - personSelected, null, null); - dbc.bindValue(SWTObservables.observeEnabled(friendsViewer - .getTable()), personSelected, null, null); - - dbc.bindValue(SWTObservables.observeText(personName, SWT.Modify), - BeansObservables.observeDetailValue(Realm.getDefault(), - selectedPerson, "name", String.class), null, null); - - ObservableListContentProvider friendsContentProvider = new ObservableListContentProvider(); - friendsViewer.setContentProvider(friendsContentProvider); - friendsViewer.setLabelProvider(new ObservableMapLabelProvider( - BeansObservables.observeMap(friendsContentProvider - .getKnownElements(), Person.class, "name"))); - friendsViewer.setInput(people); - - dbc.bindSet(ViewersObservables.observeCheckedElements( - friendsViewer, Person.class), BeansObservables - .observeDetailSet(Realm.getDefault(), selectedPerson, - "friends", Person.class), null, null); - } - } -}
\ No newline at end of file diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet019TreeViewerWithListFactory.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet019TreeViewerWithListFactory.java deleted file mode 100644 index a356793e..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet019TreeViewerWithListFactory.java +++ /dev/null @@ -1,333 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.ComputedValue; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.databinding.viewers.ObservableListTreeContentProvider; -import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; -import org.eclipse.jface.databinding.viewers.ViewersObservables; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.layout.RowLayout; -import org.eclipse.swt.widgets.Button; -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; -import org.eclipse.swt.widgets.Tree; -import org.eclipse.swt.widgets.TreeItem; - -public class Snippet019TreeViewerWithListFactory { - - private Button pasteButton; - private Button copyButton; - private Shell shell; - private Button addChildBeanButton; - private Button removeBeanButton; - private TreeViewer beanViewer; - private Tree tree; - private Text beanText; - private DataBindingContext m_bindingContext; - - private Bean input = createBean("input"); - private IObservableValue clipboard; - - /** - * Launch the application - * - * @param args - */ - public static void main(String[] args) { - Display display = Display.getDefault(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - try { - Snippet019TreeViewerWithListFactory window = new Snippet019TreeViewerWithListFactory(); - window.open(); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - - /** - * Open the window - */ - public void open() { - final Display display = Display.getDefault(); - createContents(); - shell.open(); - shell.layout(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - } - - /** - * Create contents of the window - */ - protected void createContents() { - shell = new Shell(); - final GridLayout gridLayout_1 = new GridLayout(); - gridLayout_1.numColumns = 2; - shell.setLayout(gridLayout_1); - shell.setSize(535, 397); - shell.setText("SWT Application"); - - final Composite group = new Composite(shell, SWT.NONE); - final RowLayout rowLayout = new RowLayout(); - rowLayout.marginTop = 0; - rowLayout.marginRight = 0; - rowLayout.marginLeft = 0; - rowLayout.marginBottom = 0; - rowLayout.pack = false; - group.setLayout(rowLayout); - group - .setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, - 2, 1)); - - final Button addRootButton = new Button(group, SWT.NONE); - addRootButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(final SelectionEvent e) { - List list = input.getList(); - Bean root = createBean("root"); - list.add(root); - input.setList(list); - - beanViewer.setSelection(new StructuredSelection(root)); - beanText.selectAll(); - beanText.setFocus(); - } - }); - addRootButton.setText("Add Root"); - - addChildBeanButton = new Button(group, SWT.NONE); - addChildBeanButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(final SelectionEvent e) { - Bean parent = getSelectedBean(); - List list = new ArrayList(parent.getList()); - Bean child = createBean("child"); - list.add(child); - parent.setList(list); - - beanViewer.setSelection(new StructuredSelection(child)); - beanText.selectAll(); - beanText.setFocus(); - } - }); - addChildBeanButton.setText("Add Child"); - - removeBeanButton = new Button(group, SWT.NONE); - removeBeanButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(final SelectionEvent e) { - TreeItem selectedItem = beanViewer.getTree().getSelection()[0]; - TreeItem parentItem = selectedItem.getParentItem(); - Bean parent; - int index; - if (parentItem == null) { - parent = input; - index = beanViewer.getTree().indexOf(selectedItem); - } else { - parent = (Bean) parentItem.getData(); - index = parentItem.indexOf(selectedItem); - } - - List list = new ArrayList(parent.getList()); - list.remove(index); - parent.setList(list); - } - }); - removeBeanButton.setText("Remove"); - - copyButton = new Button(group, SWT.NONE); - copyButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(final SelectionEvent e) { - clipboard.setValue(getSelectedBean()); - } - }); - copyButton.setText("Copy"); - - pasteButton = new Button(group, SWT.NONE); - pasteButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(final SelectionEvent e) { - Bean copy = (Bean) clipboard.getValue(); - if (copy == null) - return; - Bean parent = getSelectedBean(); - if (parent == null) - parent = input; - - List list = new ArrayList(parent.getList()); - list.add(copy); - parent.setList(list); - - beanViewer.setSelection(new StructuredSelection(copy)); - beanText.selectAll(); - beanText.setFocus(); - } - }); - pasteButton.setText("Paste"); - - final Button refreshButton = new Button(group, SWT.NONE); - refreshButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(final SelectionEvent e) { - beanViewer.refresh(); - } - }); - refreshButton.setText("Refresh"); - - beanViewer = new TreeViewer(shell, SWT.FULL_SELECTION | SWT.BORDER); - beanViewer.setUseHashlookup(true); - tree = beanViewer.getTree(); - tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); - - final Label itemNameLabel = new Label(shell, SWT.NONE); - itemNameLabel.setText("Item Name"); - - beanText = new Text(shell, SWT.BORDER); - final GridData gd_beanValue = new GridData(SWT.FILL, SWT.CENTER, true, - false); - beanText.setLayoutData(gd_beanValue); - m_bindingContext = initDataBindings(); - // - initExtraBindings(m_bindingContext); - } - - private static Bean createBean(String name) { - return new Bean(name); - } - - protected DataBindingContext initDataBindings() { - IObservableValue treeViewerSelectionObserveSelection = ViewersObservables - .observeSingleSelection(beanViewer); - IObservableValue textTextObserveWidget = SWTObservables.observeText( - beanText, SWT.Modify); - IObservableValue treeViewerValueObserveDetailValue = BeansObservables - .observeDetailValue(Realm.getDefault(), - treeViewerSelectionObserveSelection, "text", - java.lang.String.class); - // - // - DataBindingContext bindingContext = new DataBindingContext(); - // - bindingContext.bindValue(textTextObserveWidget, - treeViewerValueObserveDetailValue, null, null); - // - return bindingContext; - } - - private Bean getSelectedBean() { - IStructuredSelection selection = (IStructuredSelection) beanViewer - .getSelection(); - if (selection.isEmpty()) - return null; - return (Bean) selection.getFirstElement(); - } - - private void initExtraBindings(DataBindingContext dbc) { - final IObservableValue beanViewerSelection = ViewersObservables - .observeSingleSelection(beanViewer); - IObservableValue beanSelected = new ComputedValue(Boolean.TYPE) { - protected Object calculate() { - return Boolean.valueOf(beanViewerSelection.getValue() != null); - } - }; - dbc.bindValue(SWTObservables.observeEnabled(addChildBeanButton), - beanSelected, null, null); - dbc.bindValue(SWTObservables.observeEnabled(removeBeanButton), - beanSelected, null, null); - - clipboard = new WritableValue(); - dbc.bindValue(SWTObservables.observeEnabled(copyButton), beanSelected, - null, null); - dbc.bindValue(SWTObservables.observeEnabled(pasteButton), - new ComputedValue(Boolean.TYPE) { - protected Object calculate() { - return Boolean.valueOf(clipboard.getValue() != null); - } - }, null, null); - - ObservableListTreeContentProvider contentProvider = new ObservableListTreeContentProvider( - BeansObservables.listFactory(Realm.getDefault(), "list", - Bean.class), null); - beanViewer.setContentProvider(contentProvider); - beanViewer.setLabelProvider(new ObservableMapLabelProvider( - BeansObservables.observeMap(contentProvider.getKnownElements(), - Bean.class, "text"))); - beanViewer.setInput(input); - } - - static class Bean { - /* package */PropertyChangeSupport changeSupport = new PropertyChangeSupport( - this); - private String text; - private List list; - - public Bean(String text) { - this.text = text; - list = new ArrayList(); - } - - public void addPropertyChangeListener(PropertyChangeListener listener) { - changeSupport.addPropertyChangeListener(listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - changeSupport.removePropertyChangeListener(listener); - } - - public String getText() { - return text; - } - - public void setText(String value) { - changeSupport.firePropertyChange("text", this.text, - this.text = value); - } - - public List getList() { - if (list == null) - return null; - return new ArrayList(list); - } - - public void setList(List list) { - if (list != null) - list = new ArrayList(list); - changeSupport.firePropertyChange("list", this.list, - this.list = list); - } - - public boolean hasListeners(String propertyName) { - return changeSupport.hasListeners(propertyName); - } - } -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet020TreeViewerWithSetFactory.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet020TreeViewerWithSetFactory.java deleted file mode 100644 index 979412c2..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet020TreeViewerWithSetFactory.java +++ /dev/null @@ -1,330 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.examples.databinding.snippets; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.util.HashSet; -import java.util.Set; - -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.ComputedValue; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; -import org.eclipse.jface.databinding.viewers.ObservableSetTreeContentProvider; -import org.eclipse.jface.databinding.viewers.ViewersObservables; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.jface.viewers.ViewerComparator; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.layout.RowLayout; -import org.eclipse.swt.widgets.Button; -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; -import org.eclipse.swt.widgets.Tree; -import org.eclipse.swt.widgets.TreeItem; - -public class Snippet020TreeViewerWithSetFactory { - - private Button pasteButton; - private Button copyButton; - private Shell shell; - private Button addChildBeanButton; - private Button removeBeanButton; - private TreeViewer beanViewer; - private Tree tree; - private Text beanText; - private DataBindingContext m_bindingContext; - - private Bean input = createBean("input"); - private IObservableValue clipboard; - static int counter = 0; - - /** - * Launch the application - * - * @param args - */ - public static void main(String[] args) { - Display display = Display.getDefault(); - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - try { - Snippet020TreeViewerWithSetFactory window = new Snippet020TreeViewerWithSetFactory(); - window.open(); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - - /** - * Open the window - */ - public void open() { - final Display display = Display.getDefault(); - createContents(); - shell.open(); - shell.layout(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - } - - /** - * Create contents of the window - */ - protected void createContents() { - shell = new Shell(); - final GridLayout gridLayout_1 = new GridLayout(); - gridLayout_1.numColumns = 2; - shell.setLayout(gridLayout_1); - shell.setSize(535, 397); - shell.setText("SWT Application"); - - final Composite group = new Composite(shell, SWT.NONE); - final RowLayout rowLayout = new RowLayout(); - rowLayout.marginTop = 0; - rowLayout.marginRight = 0; - rowLayout.marginLeft = 0; - rowLayout.marginBottom = 0; - rowLayout.pack = false; - group.setLayout(rowLayout); - group - .setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, - 2, 1)); - - final Button addRootButton = new Button(group, SWT.NONE); - addRootButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(final SelectionEvent e) { - Set set = input.getSet(); - Bean root = createBean("root"); - set.add(root); - input.setSet(set); - - beanViewer.setSelection(new StructuredSelection(root)); - beanText.selectAll(); - beanText.setFocus(); - } - }); - addRootButton.setText("Add Root"); - - addChildBeanButton = new Button(group, SWT.NONE); - addChildBeanButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(final SelectionEvent e) { - Bean parent = getSelectedBean(); - Set set = new HashSet(parent.getSet()); - Bean child = createBean("child" + (counter++)); - set.add(child); - parent.setSet(set); - -// beanViewer.setSelection(new StructuredSelection(parent)); -// beanText.selectAll(); -// beanText.setFocus(); - } - }); - addChildBeanButton.setText("Add Child"); - - removeBeanButton = new Button(group, SWT.NONE); - removeBeanButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(final SelectionEvent e) { - TreeItem selectedItem = beanViewer.getTree().getSelection()[0]; - Bean bean = (Bean) selectedItem.getData(); - TreeItem parentItem = selectedItem.getParentItem(); - Bean parent; - if (parentItem == null) - parent = input; - else - parent = (Bean) parentItem.getData(); - - Set set = new HashSet(parent.getSet()); - set.remove(bean); - parent.setSet(set); - } - }); - removeBeanButton.setText("Remove"); - - copyButton = new Button(group, SWT.NONE); - copyButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(final SelectionEvent e) { - clipboard.setValue(getSelectedBean()); - } - }); - copyButton.setText("Copy"); - - pasteButton = new Button(group, SWT.NONE); - pasteButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(final SelectionEvent e) { - Bean copy = (Bean) clipboard.getValue(); - if (copy == null) - return; - Bean parent = getSelectedBean(); - if (parent == null) - parent = input; - - Set set = new HashSet(parent.getSet()); - set.add(copy); - parent.setSet(set); - - beanViewer.setSelection(new StructuredSelection(copy)); - beanText.selectAll(); - beanText.setFocus(); - } - }); - pasteButton.setText("Paste"); - - final Button refreshButton = new Button(group, SWT.NONE); - refreshButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(final SelectionEvent e) { - beanViewer.refresh(); - } - }); - refreshButton.setText("Refresh"); - - beanViewer = new TreeViewer(shell, SWT.FULL_SELECTION | SWT.BORDER); - beanViewer.setUseHashlookup(true); - beanViewer.setComparator(new ViewerComparator()); - tree = beanViewer.getTree(); - tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); - - final Label itemNameLabel = new Label(shell, SWT.NONE); - itemNameLabel.setText("Item Name"); - - beanText = new Text(shell, SWT.BORDER); - final GridData gd_beanValue = new GridData(SWT.FILL, SWT.CENTER, true, - false); - beanText.setLayoutData(gd_beanValue); - m_bindingContext = initDataBindings(); - // - initExtraBindings(m_bindingContext); - } - - private static Bean createBean(String name) { - return new Bean(name); - } - - protected DataBindingContext initDataBindings() { - IObservableValue treeViewerSelectionObserveSelection = ViewersObservables - .observeSingleSelection(beanViewer); - IObservableValue textTextObserveWidget = SWTObservables.observeText( - beanText, SWT.Modify); - IObservableValue treeViewerValueObserveDetailValue = BeansObservables - .observeDetailValue(Realm.getDefault(), - treeViewerSelectionObserveSelection, "text", - java.lang.String.class); - // - // - DataBindingContext bindingContext = new DataBindingContext(); - // - bindingContext.bindValue(textTextObserveWidget, - treeViewerValueObserveDetailValue, null, null); - // - return bindingContext; - } - - private Bean getSelectedBean() { - IStructuredSelection selection = (IStructuredSelection) beanViewer - .getSelection(); - if (selection.isEmpty()) - return null; - return (Bean) selection.getFirstElement(); - } - - private void initExtraBindings(DataBindingContext dbc) { - final IObservableValue beanViewerSelection = ViewersObservables - .observeSingleSelection(beanViewer); - IObservableValue beanSelected = new ComputedValue(Boolean.TYPE) { - protected Object calculate() { - return Boolean.valueOf(beanViewerSelection.getValue() != null); - } - }; - dbc.bindValue(SWTObservables.observeEnabled(addChildBeanButton), - beanSelected, null, null); - dbc.bindValue(SWTObservables.observeEnabled(removeBeanButton), - beanSelected, null, null); - - clipboard = new WritableValue(); - dbc.bindValue(SWTObservables.observeEnabled(copyButton), - beanSelected, null, null); - dbc.bindValue(SWTObservables.observeEnabled(pasteButton), new ComputedValue(Boolean.TYPE) { - protected Object calculate() { - return Boolean.valueOf(clipboard.getValue() != null); - } - }, null, null); - - ObservableSetTreeContentProvider contentProvider = new ObservableSetTreeContentProvider( - BeansObservables.setFactory(Realm.getDefault(), "set", - Bean.class), null); - beanViewer.setContentProvider(contentProvider); - beanViewer.setLabelProvider(new ObservableMapLabelProvider( - BeansObservables.observeMap(contentProvider.getKnownElements(), - Bean.class, "text"))); - beanViewer.setInput(input); - } - - static class Bean { - /* package */PropertyChangeSupport changeSupport = new PropertyChangeSupport( - this); - private String text; - private Set set; - - public Bean(String text) { - this.text = text; - set = new HashSet(); - } - - public void addPropertyChangeListener(PropertyChangeListener listener) { - changeSupport.addPropertyChangeListener(listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - changeSupport.removePropertyChangeListener(listener); - } - - public String getText() { - return text; - } - - public void setText(String value) { - changeSupport.firePropertyChange("text", this.text, this.text = value); - } - - public Set getSet() { - if (set == null) - return null; - return new HashSet(set); - } - - public void setSet(Set set) { - if (set != null) - set = new HashSet(set); - changeSupport.firePropertyChange("set", this.set, this.set = set); - } - - public boolean hasListeners(String propertyName) { - return changeSupport.hasListeners(propertyName); - } - } -}
\ No newline at end of file diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet021MultiFieldValidation.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet021MultiFieldValidation.java deleted file mode 100644 index cd86b040..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet021MultiFieldValidation.java +++ /dev/null @@ -1,357 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 218269) - ******************************************************************************/ - -package org.eclipse.jface.examples.databinding.snippets; - -import java.util.ArrayList; -import java.util.Iterator; - -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.databinding.validation.MultiValidator; -import org.eclipse.core.databinding.validation.ValidationStatus; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; -import org.eclipse.jface.databinding.wizard.WizardPageSupport; -import org.eclipse.jface.dialogs.IInputValidator; -import org.eclipse.jface.dialogs.InputDialog; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ListViewer; -import org.eclipse.jface.window.Window; -import org.eclipse.jface.wizard.IWizard; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.List; -import org.eclipse.swt.widgets.Text; - -/** - * @since 3.2 - * - */ -public class Snippet021MultiFieldValidation extends WizardPage { - - private List list_1; - private List list; - private Button addAddendButton; - private Button removeAddendButton; - private Text sumModelValue; - private Text field2ModelValue; - private Text field1ModelValue; - private Text sumTarget; - private Text field2Target; - private Text field1Target; - private ListViewer addendsTarget; - private ListViewer addendsModelValue; - - /** - * Create the wizard - */ - public Snippet021MultiFieldValidation() { - super("snippet021"); - setTitle("Snippet 021 - Multi-field Validators"); - setDescription("Enter values which satisfy the cross-field constraints"); - } - - /** - * Create contents of the wizard - * - * @param parent - */ - public void createControl(Composite parent) { - Composite container = new Composite(parent, SWT.NULL); - final GridLayout gridLayout = new GridLayout(); - gridLayout.numColumns = 2; - container.setLayout(gridLayout); - // - setControl(container); - - final Group bothEvenOrGroup = new Group(container, SWT.NONE); - bothEvenOrGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, - false)); - bothEvenOrGroup.setText("Numbers must be both even or both odd"); - final GridLayout gridLayout_1 = new GridLayout(); - gridLayout_1.numColumns = 3; - bothEvenOrGroup.setLayout(gridLayout_1); - new Label(bothEvenOrGroup, SWT.NONE); - - final Label targetLabel = new Label(bothEvenOrGroup, SWT.NONE); - targetLabel.setText("Target"); - - final Label modelLabel = new Label(bothEvenOrGroup, SWT.NONE); - modelLabel.setText("Model"); - - final Label field1Label = new Label(bothEvenOrGroup, SWT.NONE); - field1Label.setText("Field 1"); - - field1Target = new Text(bothEvenOrGroup, SWT.BORDER); - final GridData gd_field1Target = new GridData(SWT.FILL, SWT.CENTER, - true, false); - field1Target.setLayoutData(gd_field1Target); - - field1ModelValue = new Text(bothEvenOrGroup, SWT.READ_ONLY | SWT.BORDER); - final GridData gd_field1ModelValue = new GridData(SWT.FILL, SWT.CENTER, - true, false); - field1ModelValue.setLayoutData(gd_field1ModelValue); - - final Label field2Label = new Label(bothEvenOrGroup, SWT.NONE); - field2Label.setText("Field 2"); - - field2Target = new Text(bothEvenOrGroup, SWT.BORDER); - final GridData gd_field2Target = new GridData(SWT.FILL, SWT.CENTER, - true, false); - field2Target.setLayoutData(gd_field2Target); - - field2ModelValue = new Text(bothEvenOrGroup, SWT.READ_ONLY | SWT.BORDER); - final GridData gd_field2ModelValue = new GridData(SWT.FILL, SWT.CENTER, - true, false); - field2ModelValue.setLayoutData(gd_field2ModelValue); - - final Group sumOfAllGroup = new Group(container, SWT.NONE); - sumOfAllGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, - true)); - sumOfAllGroup.setText("Addends must add up to sum"); - final GridLayout gridLayout_2 = new GridLayout(); - gridLayout_2.numColumns = 3; - sumOfAllGroup.setLayout(gridLayout_2); - new Label(sumOfAllGroup, SWT.NONE); - - final Label targetLabel_1 = new Label(sumOfAllGroup, SWT.NONE); - targetLabel_1.setText("Target"); - - final Label modelLabel_1 = new Label(sumOfAllGroup, SWT.NONE); - modelLabel_1.setText("Model"); - - final Label expectedSumLabel = new Label(sumOfAllGroup, SWT.NONE); - expectedSumLabel.setText("Sum"); - - sumTarget = new Text(sumOfAllGroup, SWT.BORDER); - final GridData gd_sumTarget = new GridData(SWT.FILL, SWT.CENTER, true, - false); - sumTarget.setLayoutData(gd_sumTarget); - - sumModelValue = new Text(sumOfAllGroup, SWT.READ_ONLY | SWT.BORDER); - final GridData gd_sumModelValue = new GridData(SWT.FILL, SWT.CENTER, - true, false); - sumModelValue.setLayoutData(gd_sumModelValue); - - final Label addendsLabel = new Label(sumOfAllGroup, SWT.NONE); - addendsLabel.setText("Addends"); - - addendsTarget = new ListViewer(sumOfAllGroup, SWT.V_SCROLL | SWT.BORDER); - list_1 = addendsTarget.getList(); - list_1 - .setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, - 2)); - - addendsModelValue = new ListViewer(sumOfAllGroup, SWT.V_SCROLL - | SWT.BORDER); - list = addendsModelValue.getList(); - list.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 2)); - - final Composite composite = new Composite(sumOfAllGroup, SWT.NONE); - composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); - final GridLayout gridLayout_3 = new GridLayout(); - gridLayout_3.marginWidth = 0; - gridLayout_3.marginHeight = 0; - composite.setLayout(gridLayout_3); - - addAddendButton = new Button(composite, SWT.NONE); - addAddendButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, - false)); - addAddendButton.setText("Add"); - - removeAddendButton = new Button(composite, SWT.NONE); - removeAddendButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, - false, false)); - removeAddendButton.setText("Remove"); - - bindUI(); - } - - private void bindUI() { - DataBindingContext dbc = new DataBindingContext(); - - bindEvensAndOddsGroup(dbc); - bindSumAndAddendsGroup(dbc); - - WizardPageSupport.create(this, dbc); - } - - private void bindEvensAndOddsGroup(DataBindingContext dbc) { - IObservableValue targetField1 = SWTObservables.observeText( - field1Target, SWT.Modify); - final IObservableValue middleField1 = new WritableValue(null, - Integer.TYPE); - dbc.bindValue(targetField1, middleField1, null, null); - - IObservableValue targetField2 = SWTObservables.observeText( - field2Target, SWT.Modify); - final IObservableValue middleField2 = new WritableValue(null, - Integer.TYPE); - dbc.bindValue(targetField2, middleField2, null, null); - - MultiValidator validator = new MultiValidator() { - protected IStatus validate() { - Integer field1 = (Integer) middleField1.getValue(); - Integer field2 = (Integer) middleField2.getValue(); - if (Math.abs(field1.intValue()) % 2 != Math.abs(field2 - .intValue()) % 2) - return ValidationStatus - .error("Fields 1 and 2 must be both even or both odd"); - return null; - } - }; - dbc.addValidationStatusProvider(validator); - - IObservableValue modelField1 = new WritableValue(new Integer(1), - Integer.TYPE); - IObservableValue modelField2 = new WritableValue(new Integer(4), - Integer.TYPE); - dbc.bindValue(validator.observeValidatedValue(middleField1), - modelField1, null, null); - dbc.bindValue(validator.observeValidatedValue(middleField2), - modelField2, null, null); - - dbc.bindValue(SWTObservables.observeText(field1ModelValue, SWT.Modify), - modelField1, null, null); - dbc.bindValue(SWTObservables.observeText(field2ModelValue, SWT.Modify), - modelField2, null, null); - } - - private void bindSumAndAddendsGroup(DataBindingContext dbc) { - IObservableValue targetSum = SWTObservables.observeText(sumTarget, - SWT.Modify); - final IObservableValue middleSum = new WritableValue(null, Integer.TYPE); - dbc.bindValue(targetSum, middleSum, null, null); - - final IObservableList targetAddends = new WritableList(new ArrayList(), - Integer.TYPE); - addendsTarget.setContentProvider(new ObservableListContentProvider()); - addendsTarget.setInput(targetAddends); - - addAddendButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(final SelectionEvent e) { - InputDialog dialog = new InputDialog(getShell(), - "Input addend", "Enter an integer addend", "0", - new IInputValidator() { - public String isValid(String newText) { - try { - Integer.valueOf(newText); - return null; - } catch (NumberFormatException e) { - return "Enter a number between " - + Integer.MIN_VALUE + " and " - + Integer.MAX_VALUE; - } - } - }); - if (dialog.open() == Window.OK) { - targetAddends.add(Integer.valueOf(dialog.getValue())); - } - } - }); - - removeAddendButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - IStructuredSelection selection = (IStructuredSelection) addendsTarget - .getSelection(); - if (!selection.isEmpty()) - targetAddends.remove(selection.getFirstElement()); - } - }); - - IObservableValue modelSum = new WritableValue(new Integer(5), - Integer.TYPE); - dbc.bindValue(SWTObservables.observeText(sumModelValue, SWT.Modify), - modelSum, null, null); - - IObservableList modelAddends = new WritableList(new ArrayList(), - Integer.TYPE); - - MultiValidator validator = new MultiValidator() { - protected IStatus validate() { - Integer sum = (Integer) middleSum.getValue(); - int actualSum = 0; - for (Iterator iterator = targetAddends.iterator(); iterator - .hasNext();) { - actualSum += ((Integer) iterator.next()).intValue(); - } - if (sum.intValue() != actualSum) - return ValidationStatus.error("Sum of addends is " - + actualSum + ", expecting " + sum); - return ValidationStatus.ok(); - } - }; - dbc.addValidationStatusProvider(validator); - - addendsModelValue - .setContentProvider(new ObservableListContentProvider()); - addendsModelValue.setInput(modelAddends); - - dbc.bindValue(validator.observeValidatedValue(middleSum), modelSum, - null, null); - dbc.bindList(validator.observeValidatedList(targetAddends), - modelAddends, null, null); - } - - static class MultiFieldValidationWizard extends Wizard { - public void addPages() { - addPage(new Snippet021MultiFieldValidation()); - } - - public String getWindowTitle() { - return "Snippet 021 - Multi-field Validation"; - } - - public boolean performFinish() { - return true; - } - } - - public static void main(String[] args) { - Display display = new Display(); - - Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { - public void run() { - IWizard wizard = new MultiFieldValidationWizard(); - WizardDialog dialog = new WizardDialog(null, wizard); - dialog.open(); - - // The SWT event loop - Display display = Display.getCurrent(); - while (dialog.getShell() != null - && !dialog.getShell().isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - } - }); - - display.dispose(); - } -} diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet0xffffffff.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet0xffffffff.java deleted file mode 100644 index 8b441634..00000000 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet0xffffffff.java +++ /dev/null @@ -1,168 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 The Pampered Chef, Inc. 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: - * The Pampered Chef, Inc. - initial API and implementation - * Brad Reynolds - bug 116920 - ******************************************************************************/ - -package org.eclipse.jface.examples.databinding.snippets; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.layout.RowLayout; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -/** - * Snippet -1. - * - * Hello, no databinding. Bind changes in a GUI to a Model object but don't - * worry about propogating changes from the Model to the GUI -- using *manual* - * code. (0xffffffff is -1 in 32-bit two's complement binary arithmatic) - */ -public class Snippet0xffffffff { - public static void main(String[] args) { - ViewModel viewModel = new ViewModel(); - Shell shell = new View(viewModel).createShell(); - - // The SWT event loop - Display display = Display.getCurrent(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - - // Print the results - System.out.println("person.getName() = " - + viewModel.getPerson().getName()); - } - - // Minimal JavaBeans support - public static abstract class AbstractModelObject { - private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( - this); - - public void addPropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(listener); - } - - public void addPropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(propertyName, - listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(listener); - } - - public void removePropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(propertyName, - listener); - } - - protected void firePropertyChange(String propertyName, Object oldValue, - Object newValue) { - propertyChangeSupport.firePropertyChange(propertyName, oldValue, - newValue); - } - } - - // The data model class. This is normally a persistent class of some sort. - // - // In this example, we only push changes from the GUI to the model, so we - // don't worry about implementing JavaBeans bound properties. If we need - // our GUI to automatically reflect changes in the Person object, the - // Person object would need to implement the JavaBeans property change - // listener methods. - static class Person extends AbstractModelObject { - // A property... - String name = "John Smith"; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - } - - // The View's model--the root of our Model graph for this particular GUI. - // - // Typically each View class has a corresponding ViewModel class. - // - // The ViewModel is responsible for getting the objects to edit from the - // data access tier. Since this snippet doesn't have any persistent objects - // to - // retrieve, this ViewModel just instantiates a model object to edit. - static class ViewModel { - // The model to bind - private Person person = new Person(); - - public Person getPerson() { - return person; - } - } - - // The GUI view - static class View { - private ViewModel viewModel; - - public View(ViewModel viewModel) { - this.viewModel = viewModel; - } - - public Shell createShell() { - // Build a UI - final Display display = Display.getCurrent(); - Shell shell = new Shell(display); - shell.setLayout(new RowLayout(SWT.VERTICAL)); - - final Text name = new Text(shell, SWT.BORDER); - - // Bind it (manually) - name.setText(viewModel.getPerson().getName()); - name.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - final String text = name.getText(); - // validation - // conversion - viewModel.getPerson().setName(text); - } - }); - viewModel.person.addPropertyChangeListener("name", - new PropertyChangeListener() { - public void propertyChange(PropertyChangeEvent evt) { - display.asyncExec(new Runnable() { - public void run() { - final String newName = viewModel.person.getName(); - // conversion - name.setText(newName); - } - }); - } - }); - - // Open and return the Shell - shell.pack(); - shell.open(); - return shell; - } - } - -} diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/.classpath b/tests/org.eclipse.jface.tests.databinding.conformance/.classpath deleted file mode 100644 index ce739334..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/.classpath +++ /dev/null @@ -1,7 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" path="src"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/> - <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> - <classpathentry kind="output" path="bin"/> -</classpath> diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/.project b/tests/org.eclipse.jface.tests.databinding.conformance/.project deleted file mode 100644 index 3094c2c0..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/.project +++ /dev/null @@ -1,28 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<projectDescription> - <name>org.eclipse.jface.tests.databinding.conformance</name> - <comment></comment> - <projects> - </projects> - <buildSpec> - <buildCommand> - <name>org.eclipse.jdt.core.javabuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.ManifestBuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.SchemaBuilder</name> - <arguments> - </arguments> - </buildCommand> - </buildSpec> - <natures> - <nature>org.eclipse.pde.PluginNature</nature> - <nature>org.eclipse.jdt.core.javanature</nature> - </natures> -</projectDescription> diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/.settings/org.eclipse.jdt.core.prefs b/tests/org.eclipse.jface.tests.databinding.conformance/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 383af269..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,355 +0,0 @@ -#Mon Dec 03 13:56:42 EST 2007 -eclipse.preferences.version=1 -org.eclipse.jdt.core.builder.cleanOutputFolder=clean -org.eclipse.jdt.core.builder.duplicateResourceTask=warning -org.eclipse.jdt.core.builder.invalidClasspath=abort -org.eclipse.jdt.core.builder.recreateModifiedClassFileInOutputFolder=ignore -org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=*.launch -org.eclipse.jdt.core.circularClasspath=error -org.eclipse.jdt.core.classpath.exclusionPatterns=enabled -org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled -org.eclipse.jdt.core.codeComplete.argumentPrefixes= -org.eclipse.jdt.core.codeComplete.argumentSuffixes= -org.eclipse.jdt.core.codeComplete.fieldPrefixes= -org.eclipse.jdt.core.codeComplete.fieldSuffixes= -org.eclipse.jdt.core.codeComplete.localPrefixes= -org.eclipse.jdt.core.codeComplete.localSuffixes= -org.eclipse.jdt.core.codeComplete.staticFieldPrefixes= -org.eclipse.jdt.core.codeComplete.staticFieldSuffixes= -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.4 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.doc.comment.support=enabled -org.eclipse.jdt.core.compiler.maxProblemPerUnit=100 -org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.autoboxing=ignore -org.eclipse.jdt.core.compiler.problem.deprecation=warning -org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled -org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled -org.eclipse.jdt.core.compiler.problem.discouragedReference=ignore -org.eclipse.jdt.core.compiler.problem.emptyStatement=warning -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore -org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled -org.eclipse.jdt.core.compiler.problem.fieldHiding=warning -org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning -org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=error -org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=error -org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=error -org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore -org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=error -org.eclipse.jdt.core.compiler.problem.invalidJavadoc=ignore -org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=disabled -org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled -org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled -org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=private -org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore -org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=error -org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore -org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore -org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled -org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public -org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag -org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore -org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled -org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=public -org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore -org.eclipse.jdt.core.compiler.problem.missingSerialVersion=error -org.eclipse.jdt.core.compiler.problem.noEffectAssignment=error -org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=error -org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore -org.eclipse.jdt.core.compiler.problem.nullReference=warning -org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=error -org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore -org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning -org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore -org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning -org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore -org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled -org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=error -org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled -org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore -org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning -org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning -org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore -org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning -org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning -org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning -org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore -org.eclipse.jdt.core.compiler.problem.unsafeTypeOperation=warning -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=enabled -org.eclipse.jdt.core.compiler.problem.unusedImport=error -org.eclipse.jdt.core.compiler.problem.unusedLabel=error -org.eclipse.jdt.core.compiler.problem.unusedLocal=error -org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore -org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled -org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=enabled -org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=enabled -org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=error -org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning -org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -org.eclipse.jdt.core.compiler.source=1.3 -org.eclipse.jdt.core.formatter.align_type_members_on_columns=false -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16 -org.eclipse.jdt.core.formatter.alignment_for_assignment=0 -org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 -org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 -org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 -org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0 -org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 -org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 -org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16 -org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 -org.eclipse.jdt.core.formatter.blank_lines_after_imports=1 -org.eclipse.jdt.core.formatter.blank_lines_after_package=1 -org.eclipse.jdt.core.formatter.blank_lines_before_field=0 -org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0 -org.eclipse.jdt.core.formatter.blank_lines_before_imports=1 -org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1 -org.eclipse.jdt.core.formatter.blank_lines_before_method=1 -org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1 -org.eclipse.jdt.core.formatter.blank_lines_before_package=0 -org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1 -org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1 -org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line -org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false -org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false -org.eclipse.jdt.core.formatter.comment.format_block_comments=true -org.eclipse.jdt.core.formatter.comment.format_header=false -org.eclipse.jdt.core.formatter.comment.format_html=true -org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true -org.eclipse.jdt.core.formatter.comment.format_line_comments=true -org.eclipse.jdt.core.formatter.comment.format_source_code=true -org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true -org.eclipse.jdt.core.formatter.comment.indent_root_tags=true -org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert -org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert -org.eclipse.jdt.core.formatter.comment.line_length=80 -org.eclipse.jdt.core.formatter.compact_else_if=true -org.eclipse.jdt.core.formatter.continuation_indentation=2 -org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 -org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true -org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true -org.eclipse.jdt.core.formatter.indent_empty_lines=false -org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true -org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true -org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true -org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false -org.eclipse.jdt.core.formatter.indentation.size=4 -org.eclipse.jdt.core.formatter.insert_new_line_after_annotation=insert -org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert -org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert -org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert -org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert -org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert -org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert -org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert -org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert -org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert -org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert -org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert -org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert -org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert -org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert -org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert -org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false -org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false -org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false -org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false -org.eclipse.jdt.core.formatter.lineSplit=80 -org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false -org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false -org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 -org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 -org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true -org.eclipse.jdt.core.formatter.tabulation.char=tab -org.eclipse.jdt.core.formatter.tabulation.size=4 -org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false -org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true -org.eclipse.jdt.core.incompatibleJDKLevel=ignore -org.eclipse.jdt.core.incompleteClasspath=error diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/.settings/org.eclipse.jdt.ui.prefs b/tests/org.eclipse.jface.tests.databinding.conformance/.settings/org.eclipse.jdt.ui.prefs deleted file mode 100644 index 8ee15567..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/.settings/org.eclipse.jdt.ui.prefs +++ /dev/null @@ -1,116 +0,0 @@ -#Mon Dec 03 13:56:42 EST 2007 -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_serial_version_id=false -cleanup.always_use_blocks=true -cleanup.always_use_parentheses_in_expressions=false -cleanup.always_use_this_for_non_static_field_access=false -cleanup.always_use_this_for_non_static_method_access=false -cleanup.convert_to_enhanced_for_loop=false -cleanup.correct_indentation=false -cleanup.format_source_code=false -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_variable_declarations_final=false -cleanup.never_use_blocks=false -cleanup.never_use_parentheses_in_expressions=true -cleanup.organize_imports=false -cleanup.qualify_static_field_accesses_with_declaring_class=false -cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true -cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true -cleanup.qualify_static_member_accesses_with_declaring_class=true -cleanup.qualify_static_method_accesses_with_declaring_class=false -cleanup.remove_private_constructors=true -cleanup.remove_trailing_whitespaces=false -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=false -cleanup.use_blocks_only_for_return_and_throw=false -cleanup.use_parentheses_in_expressions=false -cleanup.use_this_for_non_static_field_access=false -cleanup.use_this_for_non_static_field_access_only_if_necessary=true -cleanup.use_this_for_non_static_method_access=false -cleanup.use_this_for_non_static_method_access_only_if_necessary=true -cleanup_profile=org.eclipse.jdt.ui.default.eclipse_clean_up_profile -cleanup_settings_version=2 -eclipse.preferences.version=1 -editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=false -formatter_profile=org.eclipse.jdt.ui.default.eclipse_profile -formatter_settings_version=11 -org.eclipse.jdt.ui.exception.name=e -org.eclipse.jdt.ui.gettersetter.use.is=true -org.eclipse.jdt.ui.ignorelowercasenames=true -org.eclipse.jdt.ui.importorder=java;javax;org;com; -org.eclipse.jdt.ui.javadoc=true -org.eclipse.jdt.ui.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"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\r\n * @return Returns the ${bare_field_name}.\r\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\r\n * @param ${param} The ${bare_field_name} to set.\r\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="true" 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) ${year} IBM Corporation 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 * IBM Corporation - initial API and implementation\r\n ******************************************************************************/\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 * @since 3.2\r\n *\r\n * ${tags}\r\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\r\n * \r\n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="true" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/* (non-Javadoc)\r\n * ${see_to_overridden}\r\n */</template><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\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\r\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\r\n${body_statement}</template><template autoinsert\="true" 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}\r\n// ${todo} Auto-generated constructor stub</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><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\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\r\n * ${tags}\r\n * ${see_to_target}\r\n */</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_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=false -sp_cleanup.format_source_code=false -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_variable_declarations_final=true -sp_cleanup.never_use_blocks=false -sp_cleanup.never_use_parentheses_in_expressions=true -sp_cleanup.on_save_use_additional_actions=false -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=false -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=false -sp_cleanup.remove_unused_imports=false -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=false -sp_cleanup.use_blocks_only_for_return_and_throw=false -sp_cleanup.use_parentheses_in_expressions=false -sp_cleanup.use_this_for_non_static_field_access=false -sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true -sp_cleanup.use_this_for_non_static_method_access=false -sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/.settings/org.eclipse.pde.prefs b/tests/org.eclipse.jface.tests.databinding.conformance/.settings/org.eclipse.pde.prefs deleted file mode 100644 index 12a7331d..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/.settings/org.eclipse.pde.prefs +++ /dev/null @@ -1,18 +0,0 @@ -#Mon Dec 03 13:56:42 EST 2007 -compilers.incompatible-environment=1 -compilers.p.build=1 -compilers.p.deprecated=0 -compilers.p.illegal-att-value=0 -compilers.p.missing-bundle-classpath-entries=1 -compilers.p.missing-packages=2 -compilers.p.no-required-att=0 -compilers.p.not-externalized-att=0 -compilers.p.unknown-attribute=0 -compilers.p.unknown-class=1 -compilers.p.unknown-element=1 -compilers.p.unknown-resource=1 -compilers.p.unresolved-ex-points=0 -compilers.p.unresolved-import=0 -compilers.p.unused-element-or-attribute=1 -compilers.use-project=true -eclipse.preferences.version=1 diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/META-INF/MANIFEST.MF b/tests/org.eclipse.jface.tests.databinding.conformance/META-INF/MANIFEST.MF deleted file mode 100644 index 64829477..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/META-INF/MANIFEST.MF +++ /dev/null @@ -1,24 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: %pluginName -Bundle-SymbolicName: org.eclipse.jface.tests.databinding.conformance -Bundle-Version: 1.0.0 -Require-Bundle: org.junit, - org.eclipse.core.databinding, - org.eclipse.jface.databinding, - org.eclipse.swt, - org.eclipse.core.runtime -Bundle-Vendor: %providerName -Bundle-RequiredExecutionEnvironment: J2SE-1.4 -Bundle-Localization: plugin -Export-Package: org.eclipse.jface.databinding.conformance;uses:="org.eclipse.core.databinding.observable,org.eclipse.jface.databinding.conformance.delegate,junit.framework", - org.eclipse.jface.databinding.conformance.delegate, - org.eclipse.jface.databinding.conformance.swt, - org.eclipse.jface.databinding.conformance.util; - uses:="org.eclipse.core.databinding.observable.map, - org.eclipse.jface.databinding.conformance.delegate, - org.eclipse.core.databinding.observable, - org.eclipse.core.databinding.observable.list, - org.eclipse.core.databinding.observable.value, - junit.framework, - org.eclipse.core.databinding.observable.set" diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/about.html b/tests/org.eclipse.jface.tests.databinding.conformance/about.html deleted file mode 100644 index d42b3ced..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/about.html +++ /dev/null @@ -1,28 +0,0 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml"> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> -<title>About</title> -</head> -<body lang="EN-US"> -<h2>About This Content</h2> - -<p>June 2, 2006</p> -<h3>License</h3> - -<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise -indicated below, the Content is provided to you under the terms and conditions of the -Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available -at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>. -For purposes of the EPL, "Program" will mean the Content.</p> - -<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is -being redistributed by another party ("Redistributor") and different terms and conditions may -apply to your use of any object code in the Content. Check the Redistributor's license that was -provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise -indicated below, the terms and conditions of the EPL still apply to any source code in the Content -and such source code may be obtained at <a href="http://www.eclipse.org">http://www.eclipse.org</a>.</p> - -</body> -</html> diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/build.properties b/tests/org.eclipse.jface.tests.databinding.conformance/build.properties deleted file mode 100644 index cc155527..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/build.properties +++ /dev/null @@ -1,17 +0,0 @@ -############################################################################### -# Copyright (c) 2007 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -bin.includes = .,\ - META-INF/,\ - plugin.properties,\ - about.html -output.databinding.jar = bin/ -src.includes = about.html -source.. = src/ diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/plugin.properties b/tests/org.eclipse.jface.tests.databinding.conformance/plugin.properties deleted file mode 100644 index 4e17d68d..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/plugin.properties +++ /dev/null @@ -1,12 +0,0 @@ -############################################################################### -# Copyright (c) 2007 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -pluginName = JFace Data Binding Conformance Tests -providerName = Eclipse.org diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/MutableObservableCollectionContractTest.java b/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/MutableObservableCollectionContractTest.java deleted file mode 100644 index ba34da54..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/MutableObservableCollectionContractTest.java +++ /dev/null @@ -1,387 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bugs 208858, 213145 - *******************************************************************************/ - -package org.eclipse.jface.databinding.conformance; - -import java.util.Arrays; -import java.util.Collections; - -import junit.framework.Test; - -import org.eclipse.core.databinding.observable.ChangeEvent; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.jface.databinding.conformance.delegate.IObservableCollectionContractDelegate; -import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker; -import org.eclipse.jface.databinding.conformance.util.CurrentRealm; -import org.eclipse.jface.databinding.conformance.util.RealmTester; -import org.eclipse.jface.databinding.conformance.util.SuiteBuilder; - -/** - * Mutability tests for IObservableCollection. - * <p> - * This class is experimental and can change at any time. It is recommended to - * not subclass or assume the test names will not change. The only API that is - * guaranteed to not change are the constructors. The tests will remain public - * and not final in order to allow for consumers to turn off a test if needed by - * subclassing. - * </p> - * - * @since 3.2 - */ -public class MutableObservableCollectionContractTest extends ObservableDelegateTest { - private IObservableCollectionContractDelegate delegate; - - private IObservableCollection collection; - - public MutableObservableCollectionContractTest( - IObservableCollectionContractDelegate delegate) { - super(delegate); - this.delegate = delegate; - } - - public MutableObservableCollectionContractTest(String name, - IObservableCollectionContractDelegate delegate) { - super(name, delegate); - this.delegate = delegate; - } - - protected void setUp() throws Exception { - super.setUp(); - - collection = (IObservableCollection) super.getObservable(); - } - - public void testAdd_ChangeEvent() throws Exception { - assertChangeEventFired(new Runnable() { - public void run() { - collection.add(delegate.createElement(collection)); - } - }, "Collection.add(Object)", collection); - } - - public void testAdd_RealmCheck() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - collection.add(delegate.createElement(collection)); - } - }, (CurrentRealm) collection.getRealm()); - } - - public void testAdd_ChangeEventFiredAfterElementIsAdded() throws Exception { - final Object element = delegate.createElement(collection); - - assertContainsDuringChangeEvent(new Runnable() { - public void run() { - collection.add(element); - } - }, "Collection.add(Object)", collection, element); - } - - public void testAddAll_ChangeEvent() throws Exception { - assertChangeEventFired(new Runnable() { - public void run() { - collection.addAll(Arrays.asList(new Object[] { delegate - .createElement(collection) })); - } - }, "Collection.addAll(Collection)", collection); - } - - public void testAddAll_RealmCheck() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - collection.addAll(Arrays.asList(new Object[] { delegate - .createElement(collection) })); - } - }, (CurrentRealm) collection.getRealm()); - } - - public void testAddAll_ChangeEventFiredAfterElementsAreAdded() - throws Exception { - final Object element = delegate.createElement(collection); - - assertContainsDuringChangeEvent(new Runnable() { - public void run() { - collection.addAll(Arrays.asList(new Object[] { element })); - } - }, "Collection.addAll(Collection)", collection, element); - } - - public void testRemove_ChangeEvent() throws Exception { - final Object element = delegate.createElement(collection); - collection.add(element); - - assertChangeEventFired(new Runnable() { - public void run() { - collection.remove(element); - } - }, "Collection.remove(Object)", collection); - } - - public void testRemove_RealmCheck() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - collection.remove(delegate.createElement(collection)); - } - }, (CurrentRealm) collection.getRealm()); - } - - public void testRemove_ChangeEventFiredAfterElementIsRemoved() - throws Exception { - final Object element = delegate.createElement(collection); - collection.add(element); - - assertDoesNotContainDuringChangeEvent(new Runnable() { - public void run() { - collection.remove(element); - } - }, "Collection.remove(Object)", collection, element); - } - - public void testRemoveAll_ChangeEvent() throws Exception { - final Object element = delegate.createElement(collection); - collection.add(element); - - assertChangeEventFired(new Runnable() { - public void run() { - collection.removeAll(Arrays.asList(new Object[] { element })); - } - }, "Collection.removeAll(Collection)", collection); - } - - public void testRemoveAll_RealmCheck() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - collection.removeAll(Arrays.asList(new Object[] { delegate.createElement(collection) })); - } - }, (CurrentRealm) collection.getRealm()); - } - - public void testRemoveAll_ChangeEventFiredAfterElementsAreRemoved() - throws Exception { - final Object element = delegate.createElement(collection); - collection.add(element); - - assertDoesNotContainDuringChangeEvent(new Runnable() { - public void run() { - collection.removeAll(Arrays.asList(new Object[] { element })); - } - }, "Collection.removeAll(Collection)", collection, element); - } - - public void testRemoveAll_NoChange() throws Exception { - ChangeEventTracker tracker = ChangeEventTracker.observe(collection); - collection.removeAll(Collections.EMPTY_LIST); - assertEquals( - "List.removeAll on an empty list should not fire a list change event", - 0, tracker.count); - } - - public void testRetainAll_ChangeEvent() throws Exception { - final Object element1 = delegate.createElement(collection); - collection.add(element1); - Object element2 = delegate.createElement(collection); - collection.add(element2); - - assertChangeEventFired(new Runnable() { - public void run() { - collection.retainAll(Arrays.asList(new Object[] { element1 })); - } - - }, "Collection.retainAll(Collection)", collection); - } - - public void testRetainAll_RealmCheck() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - collection.retainAll(Collections.EMPTY_LIST); - } - }, (CurrentRealm) collection.getRealm()); - } - - public void testRetainAll_ChangeEventFiredAfterElementsAreRetained() - throws Exception { - Object element1 = delegate.createElement(collection); - collection.add(element1); - Object element2 = delegate.createElement(collection); - collection.add(element2); - - // precondition - assertTrue(collection.contains(element1)); - assertTrue(collection.contains(element2)); - - ContainsListener listener1 = new ContainsListener(collection, element1) - .init(); - ContainsListener listener2 = new ContainsListener(collection, element2) - .init(); - - // set contains the the opposite of the expected outcome to ensure they - // get set - listener1.contains = false; - listener2.contains = true; - - collection.retainAll(Arrays.asList(new Object[] { element1 })); - assertTrue( - formatFail("When Collection.retainAll(...) fires the change event the element should have been retained in the Collection."), - listener1.contains); - assertFalse( - formatFail("When Collection.retainAll(...) fires the change event the element should have been removed from the Collection."), - listener2.contains); - } - - public void testRetainAll_NoChangeFiresNoChangeEvent() throws Exception { - ChangeEventTracker tracker = ChangeEventTracker.observe(collection); - collection.retainAll(Collections.EMPTY_LIST); - assertEquals("List.retainAll should not have fired a change event:", - 0, tracker.count); - } - - public void testClear_ChangeEvent() throws Exception { - collection.add(delegate.createElement(collection)); - - assertChangeEventFired(new Runnable() { - public void run() { - collection.clear(); - } - }, "List.clear()", collection); - } - - public void testClear_RealmCheck() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - collection.clear(); - } - }, (CurrentRealm) collection.getRealm()); - } - - public void testClear_ChangeEventFiredAfterElementIsRemoved() - throws Exception { - Object element = delegate.createElement(collection); - collection.add(element); - - assertDoesNotContainDuringChangeEvent(new Runnable() { - public void run() { - collection.clear(); - } - }, "List.clear()", collection, element); - } - - /** - * Asserts that a ChangeEvent is fired once when the provided - * <code>runnable</code> is invoked and the source is the provided - * <code>collection</code>. - * - * @param runnable - * @param methodName - * @param collection - */ - /* package */void assertChangeEventFired(Runnable runnable, - String methodName, IObservableCollection collection) { - - ChangeEventTracker listener = ChangeEventTracker.observe(collection); - runnable.run(); - - assertEquals(formatFail(methodName + " should fire one ChangeEvent."), 1, - listener.count); - assertEquals( - formatFail(methodName - + "'s change event observable should be the created Collection."), - collection, listener.event.getObservable()); - } - - /** - * Asserts that when the change event is fired for the action contained in - * the <code>runnable</code> the change will have been applied to the - * <code>collection</code>. - * - * @param runnable - * @param methodName - * @param collection - * @param elementNotContained - */ - /* package */void assertDoesNotContainDuringChangeEvent(Runnable runnable, - String methodName, IObservableCollection collection, - Object elementNotContained) { - - // precondition - assertTrue(collection.contains(elementNotContained)); - - ContainsListener listener = new ContainsListener(collection, - elementNotContained).init(); - listener.contains = true; - collection.remove(elementNotContained); - assertFalse( - formatFail(new StringBuffer("When ") - .append(methodName) - .append( - " fires a change event the element should have been removed from the Collection.") - .toString()), listener.contains); - } - - /** - * Asserts that when the change event is fired for the action contained in - * the <code>runnable</code> the change will have been applied to the - * <code>collection</code>. - * - * @param runnable - * @param methodName - * @param collection - * @param elementContained - */ - /* package */void assertContainsDuringChangeEvent(Runnable runnable, - String methodName, IObservableCollection collection, - Object elementContained) { - ContainsListener listener = new ContainsListener(collection, - elementContained).init(); - - // precondition - assertFalse(collection.contains(elementContained)); - runnable.run(); - - assertTrue( - formatFail(new StringBuffer("When ") - .append(methodName) - .append( - " fires a change event the element should have been added to the Collection.") - .toString()), listener.contains); - } - - /* package */static class ContainsListener implements IChangeListener { - boolean contains; - - final private Object element; - - final private IObservableCollection collection; - - ContainsListener(IObservableCollection collection, Object element) { - this.element = element; - this.collection = collection; - } - - ContainsListener init() { - collection.addChangeListener(this); - return this; - } - - public void handleChange(ChangeEvent event) { - contains = collection.contains(element); - } - } - - public static Test suite(IObservableCollectionContractDelegate delegate) { - return new SuiteBuilder().addObservableContractTest( - MutableObservableCollectionContractTest.class, delegate) - .addObservableContractTest( - ObservableCollectionContractTest.class, delegate) - .build(); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/MutableObservableListContractTest.java b/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/MutableObservableListContractTest.java deleted file mode 100644 index 57668750..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/MutableObservableListContractTest.java +++ /dev/null @@ -1,623 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007-2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bugs 208858, 221351, 213145, 244098 - ******************************************************************************/ - -package org.eclipse.jface.databinding.conformance; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import junit.framework.Assert; -import junit.framework.Test; - -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.ListDiffEntry; -import org.eclipse.jface.databinding.conformance.delegate.IObservableCollectionContractDelegate; -import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker; -import org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker; -import org.eclipse.jface.databinding.conformance.util.SuiteBuilder; - - -/** - * Mutability tests for IObservableList. - * - * <p> - * This class is experimental and can change at any time. It is recommended to - * not subclass or assume the test names will not change. The only API that is - * guaranteed to not change are the constructors. The tests will remain public - * and not final in order to allow for consumers to turn off a test if needed by - * subclassing. - * </p> - * - * @since 3.2 - */ -public class MutableObservableListContractTest extends - MutableObservableCollectionContractTest { - private IObservableCollectionContractDelegate delegate; - - private IObservableList list; - - /** - * @param delegate - */ - public MutableObservableListContractTest( - IObservableCollectionContractDelegate delegate) { - super(delegate); - this.delegate = delegate; - } - - public MutableObservableListContractTest(String testName, - IObservableCollectionContractDelegate delegate) { - super(testName, delegate); - this.delegate = delegate; - } - - protected void setUp() throws Exception { - super.setUp(); - list = (IObservableList) getObservable(); - } - - public void testAdd_ListChangeEvent() throws Exception { - assertListChangeEventFired(new Runnable() { - public void run() { - list.add(delegate.createElement(list)); - } - }, "List.add(Object)", list); - } - - public void testAdd_ListDiffEntry() throws Exception { - list.add(delegate.createElement(list)); - final Object element = delegate.createElement(list); - - assertAddDiffEntry(new Runnable() { - public void run() { - list.add(element); - } - }, "List.add(Object)", list, element, 1); - } - - public void testAddAtIndex_ChangeEvent() throws Exception { - assertChangeEventFired(new Runnable() { - public void run() { - list.add(0, delegate.createElement(list)); - } - }, "List.add(int, Object)", list); - } - - public void testAddAtIndex_ListChangeEvent() throws Exception { - assertListChangeEventFired(new Runnable() { - public void run() { - list.add(0, delegate.createElement(list)); - } - }, "List.add(int, Object)", list); - } - - public void testAddAtIndex_ChangeEventFiredAfterElementIsAdded() - throws Exception { - final Object element = delegate.createElement(list); - - assertContainsDuringChangeEvent(new Runnable() { - public void run() { - list.add(0, element); - } - }, "List.add(int, Collection)", list, element); - } - - public void testAddAtIndex_ListDiffEntry() throws Exception { - list.add(delegate.createElement(list)); - final Object element = delegate.createElement(list); - - assertAddDiffEntry(new Runnable() { - public void run() { - list.add(1, element); - } - }, "List.add(int, Object)", list, element, 1); - } - - public void testAddAll_ListChangeEvent() throws Exception { - assertListChangeEventFired(new Runnable() { - public void run() { - list.addAll(Arrays.asList(new Object[] { delegate - .createElement(list) })); - } - }, "List.addAll(Collection", list); - } - - public void testAddAll_ListDiffEntry() throws Exception { - final Object element = delegate.createElement(list); - - assertAddDiffEntry(new Runnable() { - public void run() { - list.addAll(Arrays.asList(new Object[] { element })); - } - }, "List.addAll(Collection)", list, element, 0); - } - - public void testAddAll_ListDiffEntry2() throws Exception { - list.add(delegate.createElement(list)); - final Object element = delegate.createElement(list); - - assertAddDiffEntry(new Runnable() { - public void run() { - list.addAll(Collections.singletonList(element)); - } - }, "List.addAll(Collection)", list, element, 1); - } - - public void testAddAllAtIndex_ChangeEvent() throws Exception { - assertChangeEventFired(new Runnable() { - public void run() { - list.addAll(0, Arrays.asList(new Object[] { delegate - .createElement(list) })); - } - }, "List.addAll(int, Collection)", list); - } - - public void testAddAllAtIndex_ListChangeEvent() throws Exception { - assertListChangeEventFired(new Runnable() { - public void run() { - list.addAll(0, Arrays.asList(new Object[] { delegate - .createElement(list) })); - } - }, "List.addAll(int, Collection)", list); - } - - public void testAddAllAtIndex_ChangeEventFiredAfterElementIsAdded() - throws Exception { - final Object element = delegate.createElement(list); - - assertContainsDuringChangeEvent(new Runnable() { - public void run() { - list.addAll(0, Arrays.asList(new Object[] { element })); - } - }, "List.addAll(int, Collection)", list, element); - } - - public void testAddAllAtIndex_ListDiffEntry() throws Exception { - list.add(delegate.createElement(list)); - final Object element = delegate.createElement(list); - - assertAddDiffEntry(new Runnable() { - public void run() { - list.addAll(1, Arrays.asList(new Object[] { element })); - } - }, "List.addAll(int, Collection)", list, element, 1); - } - - public void testSet_ChangeEvent() throws Exception { - list.add(delegate.createElement(list)); - - assertChangeEventFired(new Runnable() { - public void run() { - list.set(0, delegate.createElement(list)); - } - }, "List.set(int, Object)", list); - } - - public void testSet_ListChangeEvent() throws Exception { - list.add(delegate.createElement(list)); - - assertListChangeEventFired(new Runnable() { - public void run() { - list.set(0, delegate.createElement(list)); - } - }, "List.set(int, Object)", list); - } - - public void testSet_ChangeEventFiredAfterElementIsSet() throws Exception { - Object element1 = delegate.createElement(list); - list.add(element1); - final Object element2 = delegate.createElement(list); - - assertContainsDuringChangeEvent(new Runnable() { - public void run() { - list.set(0, element2); - } - }, "List.set(int, Object)", list, element2); - } - - public void testSet_ListDiffEntry() throws Exception { - list.add(delegate.createElement(list)); - Object oldElement = delegate.createElement(list); - list.add(oldElement); - - ListChangeEventTracker listener = ListChangeEventTracker.observe(list); - - Object newElement = delegate.createElement(list); - list.set(1, newElement); - - ListDiffEntry[] entries = listener.event.diff.getDifferences(); - assertEquals( - "List.set(int, Object) should result in 2 list diff entries.", - 2, entries.length); - - ListDiffEntry remove = entries[0]; - assertFalse(remove.isAddition()); - assertEquals( - "List.set(int, Object) removed element should be the old element.", - oldElement, remove.getElement()); - assertEquals( - "List.set(int, Object) removed index should be the index the new element was set at.", - 1, remove.getPosition()); - - ListDiffEntry add = entries[1]; - assertTrue(add.isAddition()); - assertEquals( - "List.set(int, Object) added element should be the set element.", - newElement, add.getElement()); - assertEquals( - "List.set(int, Object) add index should be the index the new element was set at.", - 1, add.getPosition()); - } - - public void testMove_ChangeEvent() throws Exception { - list.add(delegate.createElement(list)); - list.add(delegate.createElement(list)); - - assertChangeEventFired(new Runnable() { - public void run() { - list.move(0, 1); - } - }, "IObservableList.move(int, int)", list); - } - - public void testMove_NoChangeEventAtSameIndex() throws Exception { - Object element = delegate.createElement(list); - list.add(element); - - ListChangeEventTracker tracker = ListChangeEventTracker.observe(list); - - final Object movedElement = list.move(0, 0); - - assertEquals( - formatFail("IObservableList.move(int,int) should return the moved element"), - element, movedElement); - assertEquals( - formatFail("IObservableLIst.move(int,int) should not fire a change event" - + "when the old and new indices are the same"), 0, - tracker.count); - } - - public void testMove_ListChangeEvent() throws Exception { - final Object element = delegate.createElement(list); - list.add(element); - list.add(delegate.createElement(list)); - - assertListChangeEventFired(new Runnable() { - public void run() { - Object movedElement = list.move(0, 1); - assertEquals(element, movedElement); - } - }, "IObservableList.move(int, int)", list); - } - - public void testMove_ChangeEventFiredAfterElementIsMoved() throws Exception { - Object element0 = delegate.createElement(list); - Object element1 = delegate.createElement(list); - list.add(element0); - list.add(element1); - - assertSame(element0, list.get(0)); - assertSame(element1, list.get(1)); - - list.move(0, 1); - - assertSame(element1, list.get(0)); - assertSame(element0, list.get(1)); - } - - public void testMove_ListDiffEntry() { - Object element = delegate.createElement(list); - list.add(element); - list.add(delegate.createElement(list)); - - ListChangeEventTracker listener = ListChangeEventTracker.observe(list); - - list.move(0, 1); - - ListDiffEntry[] entries = listener.event.diff.getDifferences(); - assertEquals( - "List.set(int, Object) should result in 2 list diff entries.", - 2, entries.length); - - ListDiffEntry remove = entries[0]; - ListDiffEntry add = entries[1]; - assertFalse( - "IObservableList.move(int, int) removed element should be first in list diff", - remove.isAddition()); - assertTrue( - "IObservableList.move(int, int) added element should be second in list diff", - add.isAddition()); - - assertEquals( - "IObservableList.move(int, int) remove entry contains incorrect element", - element, remove.getElement()); - assertEquals( - "IObservableList.move(int, int) add entry contains incorrect element", - element, add.getElement()); - - assertEquals( - "IObservableList.move(int, int) remove entry should be the old element index", - 0, remove.getPosition()); - assertEquals( - "IObservableList.move(int, int) add entry should be the new element index", - 1, add.getPosition()); - } - - public void testRemove_ListChangeEvent() throws Exception { - final Object element = delegate.createElement(list); - list.add(element); - - assertListChangeEventFired(new Runnable() { - public void run() { - list.remove(element); - } - }, "List.remove(Object)", list); - } - - public void testRemove_ListDiffEntry() throws Exception { - list.add(delegate.createElement(list)); - final Object element = delegate.createElement(list); - list.add(element); - - assertRemoveDiffEntry(new Runnable() { - public void run() { - list.remove(element); - } - }, "List.remove(Object)", list, element, 1); - } - - public void testRemoveAtIndex_ChangeEvent() throws Exception { - list.add(delegate.createElement(list)); - - assertChangeEventFired(new Runnable() { - public void run() { - list.remove(0); - } - }, "List.remove(int)", list); - } - - public void testRemoveAtIndex_ListChangeEvent() throws Exception { - list.add(delegate.createElement(list)); - - assertListChangeEventFired(new Runnable() { - public void run() { - list.remove(0); - } - }, "List.remove(int)", list); - } - - public void testRemoveAtIndex_ChangeEventFiredAfterElementIsRemoved() - throws Exception { - final Object element = delegate.createElement(list); - list.add(element); - - assertDoesNotContainDuringChangeEvent(new Runnable() { - public void run() { - list.remove(0); - } - }, "List.remove(int)", list, element); - } - - public void testRemoveAtIndex_ListDiffEntry() throws Exception { - list.add(delegate.createElement(list)); - Object element = delegate.createElement(list); - list.add(element); - - assertRemoveDiffEntry(new Runnable() { - public void run() { - list.remove(1); - } - }, "List.remove(int)", list, element, 1); - } - - public void testRemoveAll_ListChangeEvent() throws Exception { - final Object element = delegate.createElement(list); - list.add(element); - - assertListChangeEventFired(new Runnable() { - public void run() { - list.removeAll(Arrays.asList(new Object[] { element })); - } - }, "List.removeAll(Collection)", list); - } - - public void testRemoveAll_ListDiffEntry() throws Exception { - final Object element = delegate.createElement(list); - list.add(element); - - assertRemoveDiffEntry(new Runnable() { - public void run() { - list.removeAll(Arrays.asList(new Object[] { element })); - } - }, "List.removeAll(Collection)", list, element, 0); - } - - public void testRemoveAll_ListDiffEntry2() throws Exception { - list.add(delegate.createElement(list)); - final Object element = delegate.createElement(list); - list.add(element); - - assertRemoveDiffEntry(new Runnable() { - public void run() { - list.removeAll(Arrays.asList(new Object[] { element })); - } - }, "List.removeAll(Collection)", list, element, 1); - } - - public void testRetainAll_ListChangeEvent() throws Exception { - final Object element1 = delegate.createElement(list); - list.add(element1); - list.add(delegate.createElement(list)); - - assertListChangeEventFired(new Runnable() { - public void run() { - list.retainAll(Arrays.asList(new Object[] { element1 })); - } - }, "List.retainAll(Collection", list); - } - - public void testRetainAll_ListDiffEntry() throws Exception { - final Object element1 = delegate.createElement(list); - list.add(element1); - Object element2 = delegate.createElement(list); - list.add(element2); - - assertRemoveDiffEntry(new Runnable() { - public void run() { - list.retainAll(Arrays.asList(new Object[] { element1 })); - } - }, "List.retainAll(Collection)", list, element2, 1); - } - - public void testClear_ListChangeEvent() throws Exception { - list.add(delegate.createElement(list)); - - assertListChangeEventFired(new Runnable() { - public void run() { - list.clear(); - } - }, "List.clear()", list); - } - - public void testClear_ListDiffEntry() throws Exception { - Object element = delegate.createElement(list); - list.add(element); - - assertRemoveDiffEntry(new Runnable() { - public void run() { - list.clear(); - } - }, "List.clear()", list, element, 0); - } - - public void testClear_ClearsList() { - Object element = delegate.createElement(list); - list.add(element); - Assert.assertEquals(Collections.singletonList(element), list); - list.clear(); - Assert.assertEquals(Collections.EMPTY_LIST, list); - } - - /** - * Asserts standard behaviors of firing list change events. - * <ul> - * <li>Event fires once.</li> - * <li>Source of the event is the provided <code>list</code>. - * <li>The list change event is fired after the change event.</li> - * </ul> - * - * @param runnable - * @param methodName - * @param list - */ - private void assertListChangeEventFired(Runnable runnable, - String methodName, IObservableList list) { - List queue = new ArrayList(); - ListChangeEventTracker listListener = new ListChangeEventTracker(queue); - ChangeEventTracker changeListener = new ChangeEventTracker(queue); - - list.addListChangeListener(listListener); - list.addChangeListener(changeListener); - - runnable.run(); - - assertEquals(formatFail(methodName + " should fire one ListChangeEvent."), 1, - listListener.count); - assertEquals(formatFail(methodName - + "'s change event observable should be the created List."), - list, listListener.event.getObservable()); - - assertEquals(formatFail("Two notifications should have been received."), 2, queue - .size()); - assertEquals("ChangeEvent of " + methodName - + " should have fired before the ListChangeEvent.", - changeListener, queue.get(0)); - assertEquals("ListChangeEvent of " + methodName - + " should have fired after the ChangeEvent.", listListener, - queue.get(1)); - } - - /** - * Asserts the list diff entry for a remove operation. - * - * @param runnable - * @param methodName - * @param list - * @param element - * @param index - */ - private void assertRemoveDiffEntry(Runnable runnable, String methodName, - IObservableList list, Object element, int index) { - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - runnable.run(); - - ListDiffEntry[] entries = listener.event.diff.getDifferences(); - assertEquals(methodName + " should result in one diff entry.", 1, - entries.length); - - ListDiffEntry entry = entries[0]; - assertFalse(methodName - + " should result in a diff entry that is an removal.", entry - .isAddition()); - assertEquals(methodName - + " remove diff entry should have removed the element.", - element, entry.getElement()); - assertEquals( - methodName - + " remove diff entry should have removed the element from the provided index.", - index, entry.getPosition()); - } - - /** - * Asserts the list diff entry for an add operation. - * - * @param runnable - * @param methodName - * @param list - * @param element - * @param index - */ - private void assertAddDiffEntry(Runnable runnable, String methodName, - IObservableList list, Object element, int index) { - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - runnable.run(); - - ListDiffEntry[] entries = listener.event.diff.getDifferences(); - assertEquals(methodName + " should result in one diff entry.", 1, - entries.length); - - ListDiffEntry entry = entries[0]; - assertTrue(methodName - + " should result in a diff entry that is an addition.", entry - .isAddition()); - assertEquals(methodName - + " add diff entry should have added the element.", element, - entry.getElement()); - assertEquals( - methodName - + "add diff entry should have added the element at the provided index.", - index, entry.getPosition()); - } - - public static Test suite(IObservableCollectionContractDelegate delegate) { - return new SuiteBuilder().addObservableContractTest( - MutableObservableListContractTest.class, delegate) - .addObservableContractTest(ObservableListContractTest.class, - delegate).build(); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/MutableObservableSetContractTest.java b/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/MutableObservableSetContractTest.java deleted file mode 100644 index 8ff8cdb7..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/MutableObservableSetContractTest.java +++ /dev/null @@ -1,333 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007-2008 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bugs 215531, 221351, 213145 - ******************************************************************************/ - -package org.eclipse.jface.databinding.conformance; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -import junit.framework.Test; - -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.jface.databinding.conformance.delegate.IObservableCollectionContractDelegate; -import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker; -import org.eclipse.jface.databinding.conformance.util.SetChangeEventTracker; -import org.eclipse.jface.databinding.conformance.util.SuiteBuilder; - -/** - */ -public class MutableObservableSetContractTest extends - MutableObservableCollectionContractTest { - private IObservableCollectionContractDelegate delegate; - - private IObservableSet set; - - public MutableObservableSetContractTest(String testName, - IObservableCollectionContractDelegate delegate) { - super(testName, delegate); - this.delegate = delegate; - } - - /** - * @param delegate - */ - public MutableObservableSetContractTest( - IObservableCollectionContractDelegate delegate) { - super(delegate); - } - - protected void setUp() throws Exception { - super.setUp(); - set = (IObservableSet) getObservable(); - } - - public void testAdd_SetChangeEvent() throws Exception { - assertSetChangeEventFired(new Runnable() { - public void run() { - set.add(delegate.createElement(set)); - } - }, "Set.add(Object)", set); - } - - public void testAdd_SetDiffEntry() throws Exception { - set.add(delegate.createElement(set)); - final Object element = delegate.createElement(set); - - assertAddDiffEntry(new Runnable() { - public void run() { - set.add(element); - } - }, "Set.add(Object)", set, element); - } - - public void testAdd_GetterCalled() throws Exception { - assertGetterCalled(new Runnable() { - public void run() { - set.add(delegate.createElement(set)); - } - }, "Set.add(Object)", set); - } - - public void testAddAll_SetChangeEvent() throws Exception { - assertSetChangeEventFired(new Runnable() { - public void run() { - set.addAll(Arrays.asList(new Object[] { delegate - .createElement(set) })); - } - }, "Set.addAll(Collection", set); - } - - public void testAddAll_SetDiffEntry() throws Exception { - final Object element = delegate.createElement(set); - - assertAddDiffEntry(new Runnable() { - public void run() { - set.addAll(Arrays.asList(new Object[] { element })); - } - }, "Set.addAll(Collection)", set, element); - } - - public void testAddAll_GetterCalled() throws Exception { - assertGetterCalled(new Runnable() { - public void run() { - set.addAll(Collections.singleton(delegate.createElement(set))); - } - }, "Set.addAll(Collection)", set); - } - - public void testRemove_SetChangeEvent() throws Exception { - final Object element = delegate.createElement(set); - set.add(element); - - assertSetChangeEventFired(new Runnable() { - public void run() { - set.remove(element); - } - }, "Set.remove(Object)", set); - } - - public void testRemove_SetDiffEntry() throws Exception { - set.add(delegate.createElement(set)); - final Object element = delegate.createElement(set); - set.add(element); - - assertRemoveDiffEntry(new Runnable() { - public void run() { - set.remove(element); - } - }, "Set.remove(Object)", set, element); - } - - public void testRemove_GetterCalled() throws Exception { - final Object element = delegate.createElement(set); - set.add(element); - assertGetterCalled(new Runnable() { - public void run() { - set.remove(element); - } - }, "Set.remove(Object)", set); - } - - public void testRemoveAll_SetChangeEvent() throws Exception { - final Object element = delegate.createElement(set); - set.add(element); - - assertSetChangeEventFired(new Runnable() { - public void run() { - set.removeAll(Arrays.asList(new Object[] { element })); - } - }, "Set.removeAll(Collection)", set); - } - - public void testRemoveAll_SetDiffEntry() throws Exception { - final Object element = delegate.createElement(set); - set.add(element); - - assertRemoveDiffEntry(new Runnable() { - public void run() { - set.removeAll(Arrays.asList(new Object[] { element })); - } - }, "Set.removeAll(Collection)", set, element); - } - - public void testRemoveAll_GetterCalled() throws Exception { - final Object element = delegate.createElement(set); - set.add(element); - assertGetterCalled(new Runnable() { - public void run() { - set.removeAll(Collections.singleton(element)); - } - }, "Set.removeAll(Collection)", set); - } - - public void testRetainAll_SetChangeEvent() throws Exception { - final Object element1 = delegate.createElement(set); - set.add(element1); - set.add(delegate.createElement(set)); - - assertSetChangeEventFired(new Runnable() { - public void run() { - set.retainAll(Arrays.asList(new Object[] { element1 })); - } - }, "Set.retainAll(Collection", set); - } - - public void testRetainAll_SetDiffEntry() throws Exception { - final Object element1 = delegate.createElement(set); - set.add(element1); - Object element2 = delegate.createElement(set); - set.add(element2); - - assertRemoveDiffEntry(new Runnable() { - public void run() { - set.retainAll(Arrays.asList(new Object[] { element1 })); - } - }, "Set.retainAll(Collection)", set, element2); - } - - public void testRetainAll_GetterCalled() throws Exception { - set.add(delegate.createElement(set)); - assertGetterCalled(new Runnable() { - public void run() { - set.retainAll(Collections.EMPTY_SET); - } - }, "Set.retainAll(Collection)", set); - } - - public void testClear_SetChangeEvent() throws Exception { - set.add(delegate.createElement(set)); - - assertSetChangeEventFired(new Runnable() { - public void run() { - set.clear(); - } - }, "Set.clear()", set); - } - - public void testClear_SetDiffEntry() throws Exception { - Object element = delegate.createElement(set); - set.add(element); - - assertRemoveDiffEntry(new Runnable() { - public void run() { - set.clear(); - } - }, "Set.clear()", set, element); - } - - public void testClear_GetterCalled() throws Exception { - set.add(delegate.createElement(set)); - assertGetterCalled(new Runnable() { - public void run() { - set.clear(); - } - }, "Set.clear()", set); - } - - /** - * Asserts standard behaviors of firing set change events. - * <ul> - * <li>Event fires once.</li> - * <li>Source of the event is the provided <code>set</code>. - * <li>The set change event is fired after the change event.</li> - * </ul> - * - * @param runnable - * @param methodName - * @param set - */ - private void assertSetChangeEventFired(Runnable runnable, - String methodName, IObservableSet set) { - List queue = new ArrayList(); - SetChangeEventTracker setListener = new SetChangeEventTracker(queue); - ChangeEventTracker changeListener = new ChangeEventTracker(queue); - - set.addSetChangeListener(setListener); - set.addChangeListener(changeListener); - - runnable.run(); - - assertEquals(formatFail(methodName + " should fire one SetChangeEvent."), 1, - setListener.count); - assertEquals(formatFail(methodName - + "'s change event observable should be the created Set."), set, - setListener.event.getObservable()); - - assertEquals(formatFail("Two notifications should have been received."), 2, queue - .size()); - assertEquals(formatFail("ChangeEvent of " + methodName - + " should have fired before the SetChangeEvent."), - changeListener, queue.get(0)); - assertEquals(formatFail("SetChangeEvent of " + methodName - + " should have fired after the ChangeEvent."), setListener, - queue.get(1)); - } - - /** - * Asserts the set diff entry for an add operation. - * - * @param runnable - * @param methodName - * @param set - * @param element - */ - private void assertAddDiffEntry(Runnable runnable, String methodName, - IObservableSet set, Object element) { - SetChangeEventTracker listener = new SetChangeEventTracker(); - set.addSetChangeListener(listener); - - runnable.run(); - - Set entries = listener.event.diff.getAdditions(); - assertEquals(formatFail(methodName + " should result in one diff entry."), 1, - entries.size()); - - assertTrue(formatFail(methodName - + " should result in a diff entry that is an addition."), - entries.contains(element)); - } - - /** - * Asserts the set diff entry for a remove operation. - * - * @param runnable - * @param methodName - * @param set - * @param element - */ - private void assertRemoveDiffEntry(Runnable runnable, String methodName, - IObservableSet set, Object element) { - SetChangeEventTracker listener = new SetChangeEventTracker(); - set.addSetChangeListener(listener); - - runnable.run(); - - Set entries = listener.event.diff.getRemovals(); - assertEquals(formatFail(methodName + " should result in one diff entry."), 1, - entries.size()); - - assertTrue(formatFail(methodName - + " should result in a diff entry that is a removal."), - entries.contains(element)); - } - - public static Test suite(IObservableCollectionContractDelegate delegate) { - return new SuiteBuilder().addObservableContractTest( - MutableObservableSetContractTest.class, delegate) - .addObservableContractTest( - ObservableCollectionContractTest.class, delegate) - .build(); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/MutableObservableValueContractTest.java b/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/MutableObservableValueContractTest.java deleted file mode 100644 index e03b0aae..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/MutableObservableValueContractTest.java +++ /dev/null @@ -1,115 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 213145 - *******************************************************************************/ - -package org.eclipse.jface.databinding.conformance; - -import junit.framework.Test; - -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.conformance.delegate.IObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker; -import org.eclipse.jface.databinding.conformance.util.CurrentRealm; -import org.eclipse.jface.databinding.conformance.util.RealmTester; -import org.eclipse.jface.databinding.conformance.util.SuiteBuilder; -import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; - -/** - * Mutability tests for IObservableValue. - * - * <p> - * This class is experimental and can change at any time. It is recommended to - * not subclass or assume the test names will not change. The only API that is - * guaranteed to not change are the constructors. The tests will remain public - * and not final in order to allow for consumers to turn off a test if needed by - * subclassing. - * </p> - * - * @since 3.2 - */ -public class MutableObservableValueContractTest extends - ObservableDelegateTest { - private IObservableValueContractDelegate delegate; - - private IObservableValue observable; - - /** - * @param delegate - */ - public MutableObservableValueContractTest( - IObservableValueContractDelegate delegate) { - this(null, delegate); - } - - public MutableObservableValueContractTest(String testName, - IObservableValueContractDelegate delegate) { - super(testName, delegate); - this.delegate = delegate; - } - - protected void setUp() throws Exception { - super.setUp(); - - this.observable = (IObservableValue) getObservable(); - } - - public void testSetValue_SetsValue() throws Exception { - Object value = delegate.createValue(observable); - - observable.setValue(value); - assertEquals(formatFail("IObservableValue.setValue(Object) should set the value of the observable."), value, observable.getValue()); - } - - public void testSetValue_ChangeEvent() throws Exception { - ChangeEventTracker listener = ChangeEventTracker.observe(observable); - - observable.setValue(delegate.createValue(observable)); - - assertEquals(formatFail("Change event listeners were not notified"), 1, listener.count); - assertEquals(formatFail("IObservableValue.setValue(Object) should fire one ChangeEvent."), 1, - listener.count); - assertEquals( - formatFail("IObservableValue.setValue(Object)'s change event observable should be the created observable."), - observable, listener.event.getObservable()); - } - - public void testSetValue_SameValue() throws Exception { - // invoke change to ensure observable has a value - delegate.change(observable); - - ValueChangeEventTracker valueChangeListener = ValueChangeEventTracker.observe(observable); - ChangeEventTracker changeListener = ChangeEventTracker.observe(observable); - Object value = observable.getValue(); - observable.setValue(value); - - assertEquals( - formatFail("IObservableValue.setValue() should not fire a value change event when the value has not change."), - 0, valueChangeListener.count); - assertEquals( - formatFail("IObservableValue.setValue() should not fire a change event when the value has not change."), - 0, changeListener.count); - } - - public void testSetValue_RealmChecks() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - observable.setValue(delegate.createValue(observable)); - } - }, (CurrentRealm) observable.getRealm()); - } - - public static Test suite(IObservableValueContractDelegate delegate) { - return new SuiteBuilder().addObservableContractTest( - MutableObservableValueContractTest.class, delegate) - .addObservableContractTest(ObservableValueContractTest.class, - delegate).build(); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/ObservableCollectionContractTest.java b/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/ObservableCollectionContractTest.java deleted file mode 100644 index 23985ac2..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/ObservableCollectionContractTest.java +++ /dev/null @@ -1,217 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 213145 - *******************************************************************************/ - -package org.eclipse.jface.databinding.conformance; - -import java.util.Arrays; - -import junit.framework.Test; - -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.jface.databinding.conformance.delegate.IObservableCollectionContractDelegate; -import org.eclipse.jface.databinding.conformance.util.CurrentRealm; -import org.eclipse.jface.databinding.conformance.util.RealmTester; -import org.eclipse.jface.databinding.conformance.util.SuiteBuilder; - -/** - * Tests for IObservableCollection that don't mutate the collection. - * <p> - * This class is experimental and can change at any time. It is recommended to - * not subclass or assume the test names will not change. The only API that is - * guaranteed to not change are the constructors. The tests will remain public - * and not final in order to allow for consumers to turn off a test if needed by - * subclassing. - * </p> - * - * @since 3.2 - */ -public class ObservableCollectionContractTest extends ObservableContractTest { - private IObservableCollectionContractDelegate delegate; - - private IObservableCollection collection; - - public ObservableCollectionContractTest( - IObservableCollectionContractDelegate delegate) { - super(delegate); - this.delegate = delegate; - } - - public ObservableCollectionContractTest(String testName, - IObservableCollectionContractDelegate delegate) { - super(testName, delegate); - this.delegate = delegate; - } - - protected void setUp() throws Exception { - super.setUp(); - - collection = (IObservableCollection) getObservable(); - } - - public void testIterator_GetterCalled() throws Exception { - assertGetterCalled(new Runnable() { - public void run() { - collection.iterator(); - } - }, "Collection.iterator()", collection); - } - - public void testIterator_RealmCheck() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - collection.iterator(); - } - }, (CurrentRealm) collection.getRealm()); - } - - public void testSize_GetterCalled() throws Exception { - assertGetterCalled(new Runnable() { - public void run() { - collection.size(); - } - }, "Collection.size()", collection); - } - - public void testSize_RealmCheck() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - collection.size(); - } - }, (CurrentRealm) collection.getRealm()); - } - - public void testIsEmpty_GetterCalled() throws Exception { - assertGetterCalled(new Runnable() { - public void run() { - collection.isEmpty(); - } - }, "Collection.isEmpty()", collection); - } - - public void testIsEmpty_RealmCheck() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - collection.isEmpty(); - } - }, (CurrentRealm) collection.getRealm()); - } - - public void testContains_GetterCalled() throws Exception { - assertGetterCalled(new Runnable() { - public void run() { - collection.contains(delegate.createElement(collection)); - } - }, "Collection.contains(...)", collection); - } - - public void testContains_RealmCheck() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - collection.contains(delegate.createElement(collection)); - } - }, (CurrentRealm) collection.getRealm()); - } - - public void testContainsAll_GetterCalled() throws Exception { - assertGetterCalled(new Runnable() { - public void run() { - collection.containsAll(Arrays.asList(new Object[] { delegate - .createElement(collection) })); - } - }, "Collection.containsAll(Collection)", collection); - } - - public void testContainsAll_RealmCheck() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - collection.containsAll(Arrays.asList(new Object[] { delegate - .createElement(collection) })); - } - }, (CurrentRealm) collection.getRealm()); - } - - public void testToArray_GetterCalled() throws Exception { - assertGetterCalled(new Runnable() { - public void run() { - collection.toArray(); - } - }, "Collection.toArray()", collection); - } - - public void testToArray_RealmCheck() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - collection.toArray(); - } - }, (CurrentRealm) collection.getRealm()); - } - - public void testToArrayWithObjectArray_GetterCalled() throws Exception { - assertGetterCalled(new Runnable() { - public void run() { - collection.toArray(new Object[collection.size()]); - } - }, "Collection.toArray(Object[])", collection); - } - - public void testToArrayWithObjectArray_RealmCheck() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - collection.toArray(new Object[collection.size()]); - } - }, (CurrentRealm) collection.getRealm()); - } - - public void testEquals_GetterCalled() throws Exception { - assertGetterCalled(new Runnable() { - public void run() { - collection.equals(collection); - } - }, "Collection.equals(Object)", collection); - } - - public void testEquals_RealmCheck() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - collection.equals(collection); - } - }, (CurrentRealm) collection.getRealm()); - } - - public void testHashCode_GetterCalled() throws Exception { - assertGetterCalled(new Runnable() { - public void run() { - collection.hashCode(); - } - }, "Collection.hashCode()", collection); - } - - public void testHashCode_RealmCheck() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - collection.hashCode(); - } - }, (CurrentRealm) collection.getRealm()); - } - - public void testGetElementType_ReturnsType() throws Exception { - assertEquals( - "Element type of the collection should be returned from IObservableCollection.getElementType()", - delegate.getElementType(collection), collection - .getElementType()); - } - - public static Test suite(IObservableCollectionContractDelegate delegate) { - return new SuiteBuilder().addObservableContractTest( - ObservableCollectionContractTest.class, delegate).build(); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/ObservableContractTest.java b/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/ObservableContractTest.java deleted file mode 100644 index ff013f5d..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/ObservableContractTest.java +++ /dev/null @@ -1,183 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007-2008 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bug 208322 - * Matthew Hall - bug 221351 - * Matthew Hall - bug 208858 - ******************************************************************************/ - -package org.eclipse.jface.databinding.conformance; - -import junit.framework.Test; - -import org.eclipse.core.databinding.observable.ChangeEvent; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.jface.databinding.conformance.delegate.IObservableContractDelegate; -import org.eclipse.jface.databinding.conformance.util.CurrentRealm; -import org.eclipse.jface.databinding.conformance.util.RealmTester; -import org.eclipse.jface.databinding.conformance.util.SuiteBuilder; - -/** - * Tests for IObservable that don't require mutating the observable. - * <p> - * This class is experimental and can change at any time. It is recommended to - * not subclass or assume the test names will not change. The only API that is - * guaranteed to not change are the constructors. The tests will remain public - * and not final in order to allow for consumers to turn off a test if needed by - * subclassing. - * </p> - * - * @since 3.2 - */ -public class ObservableContractTest extends ObservableDelegateTest { - private IObservable observable; - - private IObservableContractDelegate delegate; - - public ObservableContractTest(IObservableContractDelegate delegate) { - this(null, delegate); - } - - public ObservableContractTest(String testName, - IObservableContractDelegate delegate) { - super(testName, delegate); - - this.delegate = delegate; - } - - protected void setUp() throws Exception { - super.setUp(); - observable = getObservable(); - } - - public void testGetRealm_NotNull() throws Exception { - assertNotNull(formatFail("The observable's realm should not be null."), observable - .getRealm()); - } - - public void testChange_ChangeEvent() throws Exception { - ChangeListener listener = new ChangeListener(); - - observable.addChangeListener(listener); - delegate.change(observable); - - assertEquals( - formatFail("A change in the observable should notify change listeners."), - 1, listener.count); - } - - public void testChange_EventObservable() throws Exception { - ChangeListener listener = new ChangeListener(); - - observable.addChangeListener(listener); - delegate.change(observable); - - ChangeEvent event = listener.event; - assertNotNull(formatFail("change event was null"), event); - - assertSame( - formatFail("In the change event the source of the change should be the observable."), - observable, event.getObservable()); - } - - public void testChange_RealmCheck() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - delegate.change(observable); - } - }, (CurrentRealm) observable.getRealm()); - } - - public void testChange_ObservableRealmIsTheCurrentRealm() throws Exception { - ChangeListener listener = new ChangeListener(); - observable.addChangeListener(listener); - - delegate.change(observable); - assertTrue( - formatFail("On change the current realm should be the realm of the observable."), - listener.isCurrentRealm); - } - - public void testRemoveChangeListener_RemovesListener() throws Exception { - ChangeListener listener = new ChangeListener(); - - observable.addChangeListener(listener); - delegate.change(observable); - - // precondition check - assertEquals(formatFail("change did not notify listeners"), 1, listener.count); - - observable.removeChangeListener(listener); - delegate.change(observable); - - assertEquals( - formatFail("When a change listener is removed it should not still receive change events."), - 1, listener.count); - } - - public void testIsStale_NotStale() throws Exception { - delegate.setStale(observable, false); - assertFalse( - formatFail("When an observable is not stale isStale() should return false."), - observable.isStale()); - } - - public void testIsStale_RealmChecks() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - observable.isStale(); - } - }, (CurrentRealm) observable.getRealm()); - } - - public void testIsStale_GetterCalled() throws Exception { - assertGetterCalled(new Runnable() { - public void run() { - observable.isStale(); - } - }, "isStale", observable); - } - - public void testDispose_RemovesListeners() throws Exception { - ChangeListener disposedObservableListener = new ChangeListener(); - Realm realm = observable.getRealm(); - - observable.addChangeListener(disposedObservableListener); - observable.dispose(); - - //create a new observable to fire a change from - observable = delegate.createObservable(realm); - delegate.change(observable); - - assertEquals( - formatFail("After being disposed listeners should not receive change events."), - 0, disposedObservableListener.count); - } - - /* package */static class ChangeListener implements IChangeListener { - int count; - - ChangeEvent event; - - boolean isCurrentRealm; - - public void handleChange(ChangeEvent event) { - count++; - this.event = event; - this.isCurrentRealm = event.getObservable().getRealm().isCurrent(); - } - } - - public static Test suite(IObservableContractDelegate delegate) { - return new SuiteBuilder().addObservableContractTest( - ObservableContractTest.class, delegate).build(); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/ObservableDelegateTest.java b/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/ObservableDelegateTest.java deleted file mode 100644 index f7405398..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/ObservableDelegateTest.java +++ /dev/null @@ -1,135 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007-2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 221351 - ******************************************************************************/ - -package org.eclipse.jface.databinding.conformance; - -import junit.framework.TestCase; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.jface.databinding.conformance.delegate.IObservableContractDelegate; -import org.eclipse.jface.databinding.conformance.util.CurrentRealm; -import org.eclipse.jface.databinding.conformance.util.RealmTester; - -/** - * TestCase that provides the standard behavior expected for delegating test cases. - * - * @since 3.2 - */ -public class ObservableDelegateTest extends TestCase { - private IObservableContractDelegate delegate; - - private Realm previousRealm; - - private IObservable observable; - private String debugInfo; - - public ObservableDelegateTest(IObservableContractDelegate delegate) { - this(null, delegate); - } - - public ObservableDelegateTest(String testName, IObservableContractDelegate delegate) { - super(testName); - this.delegate = delegate; - } - - protected void setUp() throws Exception { - super.setUp(); - previousRealm = Realm.getDefault(); - - delegate.setUp(); - observable = doCreateObservable(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - - delegate.tearDown(); - observable.dispose(); - observable = null; - - RealmTester.setDefault(previousRealm); - - observable = null; - previousRealm = null; - } - - /** - * Creates a new observable with a default realm. Invoked from - * {@link #setUp()}. Override to customize the creation of observables - * (e.g. specifying a different Realm). - * - * @return observable - */ - protected IObservable doCreateObservable() { - return delegate.createObservable(new CurrentRealm(true)); - } - - /** - * Returns the created observable. The observable is created in - * {@link #setUp()}. If invoked before {@link #setUp()} will be - * <code>null</code>. - * - * @return observable - */ - protected IObservable getObservable() { - return observable; - } - - /** - * Returns the delegate in use. - * - * @return delegate - */ - protected IObservableContractDelegate getObservableContractDelegate() { - return delegate; - } - - protected String formatFail(String message) { - return message + getDebugString(); - } - - private String getDebugString() { - if (debugInfo == null) { - debugInfo = "(Test: " + this.getClass().getName() + ", Delegate: " + delegate.getClass().getName() + ")"; - } - - return debugInfo; - } - - /** - * Asserts that ObservableTracker.getterCalled(...) is invoked when the - * provided <code>runnable</code> is invoked. - * - * @param runnable - * @param methodName - * method name to display when displaying a message - * @param observable - * observable that should be collected by ObservableTracker - */ - protected void assertGetterCalled(Runnable runnable, String methodName, IObservable observable) { - IObservable[] observables = ObservableTracker.runAndMonitor(runnable, - null, null); - - int count = 0; - for (int i = 0; i < observables.length; i++) { - if (observables[i] == observable) { - count++; - } - } - - assertEquals(formatFail(methodName - + " should invoke ObservableTracker.getterCalled() once."), 1, - count); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/ObservableListContractTest.java b/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/ObservableListContractTest.java deleted file mode 100644 index a0e48c17..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/ObservableListContractTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 213145 - *******************************************************************************/ - -package org.eclipse.jface.databinding.conformance; - -import junit.framework.Test; - -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.jface.databinding.conformance.delegate.IObservableCollectionContractDelegate; -import org.eclipse.jface.databinding.conformance.util.CurrentRealm; -import org.eclipse.jface.databinding.conformance.util.SuiteBuilder; - -/** - * Tests for IObservableList that don't require mutating the collection. - * <p> - * This class is experimental and can change at any time. It is recommended to - * not subclass or assume the test names will not change. The only API that is - * guaranteed to not change are the constructors. The tests will remain public - * and not final in order to allow for consumers to turn off a test if needed by - * subclassing. - * </p> - * - * @since 3.2 - */ -public class ObservableListContractTest extends - ObservableCollectionContractTest { - private IObservableList list; - - private IObservableCollectionContractDelegate delegate; - - /** - * @param delegate - */ - public ObservableListContractTest( - IObservableCollectionContractDelegate delegate) { - super(delegate); - this.delegate = delegate; - } - - public ObservableListContractTest(String testName, - IObservableCollectionContractDelegate delegate) { - super(testName, delegate); - this.delegate = delegate; - } - - protected void setUp() throws Exception { - super.setUp(); - - list = (IObservableList) getObservable(); - } - - public void testListIterator_GetterCalled() throws Exception { - assertGetterCalled(new Runnable() { - public void run() { - list.listIterator(); - } - }, "List.listIterator()", list); - } - - public void testGet_GetterCalled() throws Exception { - list = (IObservableList) delegate.createObservableCollection(new CurrentRealm(true), 1); - assertGetterCalled(new Runnable() { - public void run() { - list.get(0); - } - }, "List.get(int)", list); - } - - public void testIndexOf_GetterCalled() throws Exception { - assertGetterCalled(new Runnable() { - public void run() { - list.indexOf(delegate.createElement(list)); - } - }, "List.indexOf(int)", list); - } - - public void testLastIndexOf_GetterCalled() throws Exception { - assertGetterCalled(new Runnable() { - public void run() { - list.lastIndexOf(delegate.createElement(list)); - } - }, "List.lastIndexOf(Object)", list); - } - - public void testListIteratorAtIndex_GetterCalled() throws Exception { - // Create a new list instead of adding an item because the list might - // not be mutable - list = (IObservableList) delegate.createObservableCollection(new CurrentRealm(true), 1); - assertGetterCalled(new Runnable() { - public void run() { - list.listIterator(0); - } - }, "List.listIterator(int)", list); - } - - public void testSubList_GetterCalled() throws Exception { - list = (IObservableList) delegate.createObservableCollection(new CurrentRealm(true), 1); - assertGetterCalled(new Runnable() { - public void run() { - list.subList(0, 1); - } - }, "List.subList(int, int)", list); - } - - public static Test suite(IObservableCollectionContractDelegate delegate) { - return new SuiteBuilder().addObservableContractTest( - ObservableListContractTest.class, delegate).build(); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/ObservableStaleContractTest.java b/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/ObservableStaleContractTest.java deleted file mode 100644 index 9c754aa2..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/ObservableStaleContractTest.java +++ /dev/null @@ -1,157 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bug 213145 - ******************************************************************************/ - -package org.eclipse.jface.databinding.conformance; - -import junit.framework.Test; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.jface.databinding.conformance.delegate.IObservableContractDelegate; -import org.eclipse.jface.databinding.conformance.util.SuiteBuilder; - -/** - * @since 3.3 - */ -public class ObservableStaleContractTest extends ObservableDelegateTest { - private IObservableContractDelegate delegate; - private IObservable observable; - - public ObservableStaleContractTest(IObservableContractDelegate delegate) { - this(null, delegate); - } - - public ObservableStaleContractTest(String testName, IObservableContractDelegate delegate) { - super(testName, delegate); - this.delegate = delegate; - } - - protected void setUp() throws Exception { - super.setUp(); - - observable = getObservable(); - } - - public void testIsStale_TrueWhenStale() throws Exception { - delegate.setStale(observable, true); - assertTrue(formatFail("When stale isStale() should return true."), observable.isStale()); - } - - public void testIsStale_FalseWhenNotStale() throws Exception { - delegate.setStale(observable, false); - assertFalse(formatFail("When not stale isStale() should return false."), observable.isStale()); - } - - public void testBecomingStaleFiresStaleEvent() throws Exception { - StaleListener listener = new StaleListener(); - - // precondition - ensureStale(observable, false); - - observable.addStaleListener(listener); - delegate.setStale(observable, true); - - assertEquals(formatFail("When becoming stale listeners should be notified."), 1, listener.count); - } - - public void testStaleEventObservable() throws Exception { - StaleListener listener = new StaleListener(); - - // precondition - ensureStale(observable, false); - - observable.addStaleListener(listener); - delegate.setStale(observable, true); - - StaleEvent event = listener.event; - assertNotNull(formatFail("stale event was null"), event); - assertEquals(formatFail("When notifying listeners of becoming stale the observable should be the source of the event."), observable, - event.getObservable()); - } - - public void testRemoveStaleListener_RemovesListener() throws Exception { - StaleListener listener = new StaleListener(); - - observable.addStaleListener(listener); - ensureStale(observable, false); - delegate.setStale(observable, true); - - // precondition check - assertEquals(formatFail("set stale did not notify listeners"), 1, listener.count); - - observable.removeStaleListener(listener); - ensureStale(observable, false); - delegate.setStale(observable, true); - - assertEquals(formatFail("Once removed stale listeners should not be notified of becoming stale."), 1, - listener.count); - } - - public void testStaleListenersAreNotNotifiedWhenObservableIsNoLongerStale() - throws Exception { - ensureStale(observable, true); - - StaleListener listener = new StaleListener(); - observable.addStaleListener(listener); - delegate.setStale(observable, false); - - assertEquals(formatFail("Stale listeners should not be notified when the stale state changes from true to false."), 0, - listener.count); - } - - public void testObservableRealmIsCurrentOnStale() throws Exception { - ensureStale(observable, false); - - StaleListener listener = new StaleListener(); - observable.addStaleListener(listener); - delegate.setStale(observable, true); - - assertTrue(formatFail("When notifying listeners of becoming stale the observable's realm should be the current realm."), - listener.isCurrentRealm); - } - - /** - * Ensures that stale is set to the provided state. Will throw an - * AssertionFailedError if setting of the state is unsuccessful. - * - * @param observable - * @param stale - */ - private void ensureStale(IObservable observable, boolean stale) { - if (observable.isStale() != stale) { - delegate.setStale(observable, stale); - } - - assertEquals(stale, observable.isStale()); - } - - /* package */static class StaleListener implements IStaleListener { - int count; - - StaleEvent event; - - boolean isCurrentRealm; - - public void handleStale(StaleEvent staleEvent) { - count++; - this.event = staleEvent; - this.isCurrentRealm = staleEvent.getObservable().getRealm() - .isCurrent(); - } - } - - public static Test suite(IObservableContractDelegate delegate) { - return new SuiteBuilder().addObservableContractTest( - ObservableStaleContractTest.class, delegate).build(); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/ObservableValueContractTest.java b/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/ObservableValueContractTest.java deleted file mode 100644 index 5ea30984..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/ObservableValueContractTest.java +++ /dev/null @@ -1,179 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bug 213145 - ******************************************************************************/ - -package org.eclipse.jface.databinding.conformance; - -import java.util.ArrayList; -import java.util.List; - -import junit.framework.Test; - -import org.eclipse.core.databinding.observable.ChangeEvent; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.observable.value.ValueChangeEvent; -import org.eclipse.jface.databinding.conformance.delegate.IObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.util.CurrentRealm; -import org.eclipse.jface.databinding.conformance.util.RealmTester; -import org.eclipse.jface.databinding.conformance.util.SuiteBuilder; -import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; - -/** - * @since 3.2 - */ -public class ObservableValueContractTest extends ObservableContractTest { - private IObservableValueContractDelegate delegate; - private IObservableValue observable; - - public ObservableValueContractTest(IObservableValueContractDelegate delegate) { - super(delegate); - this.delegate = delegate; - } - - /** - * @param testName - * @param delegate - */ - public ObservableValueContractTest(String testName, - IObservableValueContractDelegate delegate) { - super(testName, delegate); - this.delegate = delegate; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.databinding.conformance.ObservableContractTest#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - observable = (IObservableValue) getObservable(); - } - - public void testChange_ValueChangeEvent() throws Exception { - ValueChangeEventTracker listener = ValueChangeEventTracker.observe(observable); - - delegate.change(observable); - assertEquals(formatFail("On change value change listeners should be notified."), 1, - listener.count); - } - - public void testGetValueType_ExpectedType() throws Exception { - assertEquals(formatFail("Type of the value should be returned from getType()."), - delegate.getValueType(observable), observable.getValueType()); - } - - public void testChange_OrderOfNotifications() throws Exception { - final List listeners = new ArrayList(); - IChangeListener changeListener = new IChangeListener() { - public void handleChange(ChangeEvent event) { - listeners.add(this); - } - }; - - IValueChangeListener valueChangeListener = new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - listeners.add(this); - } - }; - - observable.addChangeListener(changeListener); - observable.addValueChangeListener(valueChangeListener); - - delegate.change(observable); - - assertTrue(formatFail("Change Listeners were not notified on change."), listeners.size() > 0); - - // not asserting the fact that both are notified as this is asserted in - // other tests - assertEquals( - formatFail("Change listeners should be notified before value change listeners."), - changeListener, listeners.get(0)); - assertEquals( - formatFail("Value change listeners should be notified after change listeners."), - valueChangeListener, listeners.get(1)); - } - - public void testChange_ValueChangeEventDiff() throws Exception { - ValueChangeEventTracker listener = ValueChangeEventTracker.observe(observable); - Object oldValue = observable.getValue(); - - delegate.change(observable); - - ValueChangeEvent event = listener.event; - - assertTrue(formatFail("Change Listeners were not notified on change."), listener.count > 0); - - assertEquals( - formatFail("When a value change event is fired the old value should be the previous value of the observable value."), - oldValue, event.diff.getOldValue()); - assertEquals( - formatFail("When a value change event is fired the new value should be the same as the current value of the observable value."), - observable.getValue(), event.diff.getNewValue()); - } - - public void testChange_ValueChangeEventFiredAfterValueIsSet() - throws Exception { - class ValueChangeListener implements IValueChangeListener { - Object value; - - public void handleValueChange(ValueChangeEvent event) { - this.value = event.getObservableValue().getValue(); - } - } - - ValueChangeListener listener = new ValueChangeListener(); - observable.addValueChangeListener(listener); - delegate.change(observable); - assertEquals( - formatFail("When a value change event is fired the new value should be applied before firing the change event."), - listener.value, observable.getValue()); - } - - public void testRemoveValueChangeListener_RemovesListener() throws Exception { - ValueChangeEventTracker listener = ValueChangeEventTracker.observe(observable); - delegate.change(observable); - - // precondition - assertEquals(formatFail("Value change listeners should be notified on change."), 1, - listener.count); - - observable.removeValueChangeListener(listener); - delegate.change(observable); - - assertEquals( - formatFail("Value change listeners should not be notified after they've been removed from the observable."), - 1, listener.count); - } - - public void testGetValue_GetterCalled() throws Exception { - assertGetterCalled(new Runnable() { - public void run() { - observable.getValue(); - } - }, formatFail("IObservableValue.getValue()"), observable); - } - - public void testGetValue_RealmCheck() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - observable.getValue(); - } - }, (CurrentRealm) observable.getRealm()); - } - - public static Test suite(IObservableValueContractDelegate delegate) { - return new SuiteBuilder().addObservableContractTest( - ObservableValueContractTest.class, delegate).build(); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/delegate/AbstractObservableCollectionContractDelegate.java b/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/delegate/AbstractObservableCollectionContractDelegate.java deleted file mode 100644 index 5455d7f8..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/delegate/AbstractObservableCollectionContractDelegate.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.jface.databinding.conformance.delegate; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.Realm; - -/** - * Abstract implementation of {@link IObservableCollectionContractDelegate}. - * - * @since 3.2 - */ -public abstract class AbstractObservableCollectionContractDelegate extends - AbstractObservableContractDelegate implements - IObservableCollectionContractDelegate { - - /** - * Invokes {@link IObservableCollectionContractDelegate#createObservableCollection(Realm, int)}. - * @param realm - * @return observable - */ - public final IObservable createObservable(Realm realm) { - return createObservableCollection(realm, 0); - } - - public Object createElement(IObservableCollection collection) { - //no op - return null; - } - - public Object getElementType(IObservableCollection collection) { - //no op - return null; - } -} diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/delegate/AbstractObservableContractDelegate.java b/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/delegate/AbstractObservableContractDelegate.java deleted file mode 100644 index 81467602..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/delegate/AbstractObservableContractDelegate.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - ******************************************************************************/ - -package org.eclipse.jface.databinding.conformance.delegate; - -import org.eclipse.core.databinding.observable.IObservable; - -/** - * Abstract implementation of {@link IObservableContractDelegate}. - * - * @since 1.1 - */ -public abstract class AbstractObservableContractDelegate implements - IObservableContractDelegate { - - public void setUp() { - // no op - } - - public void tearDown() { - // no op - } - - public void change(IObservable observable) { - // no op - } - - public void setStale(IObservable observable, boolean stale) { - // no op - } -} diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/delegate/AbstractObservableValueContractDelegate.java b/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/delegate/AbstractObservableValueContractDelegate.java deleted file mode 100644 index 6de2c2cd..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/delegate/AbstractObservableValueContractDelegate.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - ******************************************************************************/ - -package org.eclipse.jface.databinding.conformance.delegate; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; - -/** - * Abstract implementation of {@link IObservableValueContractDelegate}. - * - * @since 1.1 - */ -public abstract class AbstractObservableValueContractDelegate extends - AbstractObservableContractDelegate implements - IObservableValueContractDelegate { - - /** - * Invokes {@link #createObservableValue(Realm)}. - * @param realm - * @return observable - */ - public final IObservable createObservable(Realm realm) { - return createObservableValue(realm); - } - - /** - * Default implementation returns <code>null</code>. - * @param observable - * @return value type - */ - public Object getValueType(IObservableValue observable) { - // no op - return null; - } - - /** - * Default implementation returns <code>null</code>. - * @param observable - * @return value - */ - public Object createValue(IObservableValue observable) { - //no op - return null; - } -} diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/delegate/IObservableCollectionContractDelegate.java b/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/delegate/IObservableCollectionContractDelegate.java deleted file mode 100644 index 5fb412c2..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/delegate/IObservableCollectionContractDelegate.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.jface.databinding.conformance.delegate; - -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.Realm; - -/** - * Delegate interface for an IObservableCollection. - * - * <p> - * This interface is not intended to be implemented by clients. Clients should - * instead subclass one of the classes that implement this interface. Note that - * direct implementers of this interface outside of the framework will be broken - * in future releases when methods are added to this interface. - * </p> - * - * @since 1.1 - */ -public interface IObservableCollectionContractDelegate extends - IObservableContractDelegate { - /** - * Creates a new observable collection with the provided - * <code>elementCount</code>. - * - * @param realm realm of the collection - * @param elementCount - * number of elements to initialize the collection with - * - * @return new observable collection - */ - public IObservableCollection createObservableCollection(Realm realm, int elementCount); - - /** - * Creates a new element of the appropriate type for the provided - * <code>collection</code>. This element will be employed to assert the - * addition and removal of elements in the collection. - * - * @param collection - * @return valid element for the collection - */ - public Object createElement(IObservableCollection collection); - - /** - * Returns the expected type of the elements in the collection. - * - * @param collection - * @return element type - */ - public Object getElementType(IObservableCollection collection); -} diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/delegate/IObservableContractDelegate.java b/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/delegate/IObservableContractDelegate.java deleted file mode 100644 index bcd59bbf..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/delegate/IObservableContractDelegate.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - ******************************************************************************/ - -package org.eclipse.jface.databinding.conformance.delegate; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; - -/** - * Delegate interface for observables. - * - * <p> - * This interface is not intended to be implemented by clients. Clients should - * instead subclass one of the classes that implement this interface. Note that - * direct implementers of this interface outside of the framework will be broken - * in future releases when methods are added to this interface. - * </p> - * - * @since 1.1 - */ -public interface IObservableContractDelegate { - /** - * Notifies the delegate of the start of a test. - */ - public void setUp(); - - /** - * Notifies the delegate of the end of a test. - */ - public void tearDown(); - - /** - * Invokes an operation to set the stale state of the provided - * <code>observable</code>. - * - * @param observable - * @param stale - */ - public void setStale(IObservable observable, boolean stale); - - /** - * Creates a new observable. - * - * @param realm realm of the observable - * @return observable - */ - public IObservable createObservable(Realm realm); - - /** - * Invokes a change operation resulting in a change event being fired from - * the observable. The preferred approach is to change the observed object - * resulting in an observable event. There is no guaranteed as to the state - * of the observable when invoked. The observable could be disposed to - * assert the proper behavior of dispose. - * - * @param observable - */ - public void change(IObservable observable); -} diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/delegate/IObservableValueContractDelegate.java b/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/delegate/IObservableValueContractDelegate.java deleted file mode 100644 index 873b0050..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/delegate/IObservableValueContractDelegate.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - ******************************************************************************/ - -package org.eclipse.jface.databinding.conformance.delegate; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; - -/** - * Delegate interface for an observable value. - * - * <p> - * This interface is not intended to be implemented by clients. Clients should - * instead subclass one of the classes that implement this interface. Note that - * direct implementers of this interface outside of the framework will be broken - * in future releases when methods are added to this interface. - * </p> - * - * @since 1.1 - */ -public interface IObservableValueContractDelegate extends - IObservableContractDelegate { - - /** - * Creates a new observable value. - * - * @param realm - * realm of the observable - * @return observable value - */ - public IObservableValue createObservableValue(Realm realm); - - /** - * Returns the expected type of the observable. - * - * @param observable - * @return type - */ - public Object getValueType(IObservableValue observable); - - /** - * Returns a valid value that is not the current value of the observable. - * - * @param observable - * @return value - */ - public Object createValue(IObservableValue observable); -} diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/swt/SWTMutableObservableValueContractTest.java b/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/swt/SWTMutableObservableValueContractTest.java deleted file mode 100644 index b16fb6ef..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/swt/SWTMutableObservableValueContractTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 213145 - *******************************************************************************/ - -package org.eclipse.jface.databinding.conformance.swt; - -import junit.framework.Test; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.jface.databinding.conformance.MutableObservableValueContractTest; -import org.eclipse.jface.databinding.conformance.delegate.IObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.util.DelegatingRealm; -import org.eclipse.jface.databinding.conformance.util.SuiteBuilder; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.swt.widgets.Display; - -/** - * Mutability tests for IObservableValue for a SWT widget. - * - * <p> - * This class is experimental and can change at any time. It is recommended to - * not subclass or assume the test names will not change. The only API that is - * guaranteed to not change are the constructors. The tests will remain public - * and not final in order to allow for consumers to turn off a test if needed by - * subclassing. - * </p> - * - * @since 3.2 - */ -public class SWTMutableObservableValueContractTest extends - MutableObservableValueContractTest { - private IObservableValueContractDelegate delegate; - - public SWTMutableObservableValueContractTest( - IObservableValueContractDelegate delegate) { - this(null, delegate); - } - - /** - * @param testName - * @param delegate - */ - public SWTMutableObservableValueContractTest(String testName, - IObservableValueContractDelegate delegate) { - super(testName, delegate); - this.delegate = delegate; - } - - /** - * Creates a new observable passing the realm for the current display. - * @return observable - */ - protected IObservable doCreateObservable() { - Display display = Display.getCurrent(); - if (display == null) { - display = new Display(); - } - DelegatingRealm delegateRealm = new DelegatingRealm(SWTObservables - .getRealm(display)); - delegateRealm.setCurrent(true); - - return delegate.createObservable(delegateRealm); - } - - public static Test suite(IObservableValueContractDelegate delegate) { - return new SuiteBuilder().addObservableContractTest( - SWTMutableObservableValueContractTest.class, delegate) - .addObservableContractTest( - SWTObservableValueContractTest.class, delegate).build(); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/swt/SWTObservableValueContractTest.java b/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/swt/SWTObservableValueContractTest.java deleted file mode 100644 index ef216699..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/swt/SWTObservableValueContractTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 213145 - *******************************************************************************/ - -package org.eclipse.jface.databinding.conformance.swt; - -import junit.framework.Test; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.jface.databinding.conformance.ObservableValueContractTest; -import org.eclipse.jface.databinding.conformance.delegate.IObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.util.DelegatingRealm; -import org.eclipse.jface.databinding.conformance.util.SuiteBuilder; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.swt.widgets.Display; - -/** - * Tests for IObservableValue that don't mutate the value. - * <p> - * This class is experimental and can change at any time. It is recommended to - * not subclass or assume the test names will not change. The only API that is - * guaranteed to not change are the constructors. The tests will remain public - * and not final in order to allow for consumers to turn off a test if needed by - * subclassing. - * </p> - * - * @since 3.2 - */ -public class SWTObservableValueContractTest extends ObservableValueContractTest { - private IObservableValueContractDelegate delegate; - - /** - * @param delegate - */ - public SWTObservableValueContractTest( - IObservableValueContractDelegate delegate) { - this(null, delegate); - } - - public SWTObservableValueContractTest(String testName, - IObservableValueContractDelegate delegate) { - super(testName, delegate); - this.delegate = delegate; - } - - /** - * Creates a new observable passing the realm for the current display. - * @return observable - */ - protected IObservable doCreateObservable() { - Display display = Display.getCurrent(); - if (display == null) { - display = new Display(); - } - DelegatingRealm delegateRealm = new DelegatingRealm(SWTObservables - .getRealm(display)); - delegateRealm.setCurrent(true); - - return delegate.createObservable(delegateRealm); - } - - public static Test suite(IObservableValueContractDelegate delegate) { - return new SuiteBuilder().addObservableContractTest(SWTObservableValueContractTest.class, delegate).build(); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/util/ChangeEventTracker.java b/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/util/ChangeEventTracker.java deleted file mode 100644 index 1e38756f..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/util/ChangeEventTracker.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.databinding.conformance.util; - -import java.util.List; - -import org.eclipse.core.databinding.observable.ChangeEvent; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IObservable; - -/** - * Listener for tracking the firing of ChangeEvents. - */ -public class ChangeEventTracker implements IChangeListener { - public int count; - public ChangeEvent event; - - /** - * Queue that the listener will add itself too when it is notified of an - * event. Used to determine order of notifications of listeners. Can be null. - */ - public final List queue; - - public ChangeEventTracker() { - queue = null; - } - - public ChangeEventTracker(List notificationQueue) { - this.queue = notificationQueue; - } - - public void handleChange(ChangeEvent event) { - count++; - this.event = event; - if (queue != null) { - queue.add(this); - } - } - - /** - * Convenience method to register a new listener. - * - * @param observable - * @return tracker - */ - public static ChangeEventTracker observe(IObservable observable) { - ChangeEventTracker tracker = new ChangeEventTracker(); - observable.addChangeListener(tracker); - return tracker; - } -} diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/util/CurrentRealm.java b/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/util/CurrentRealm.java deleted file mode 100644 index 82e56fbe..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/util/CurrentRealm.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.databinding.conformance.util; - -import org.eclipse.core.databinding.observable.Realm; - -/** - * Allows for the toggling of the current status of the realm. The - * asyncExec(...) implementations do nothing. - * - * @since 3.2 - */ -public class CurrentRealm extends Realm { - private boolean current; - - public CurrentRealm() { - this(false); - } - - public CurrentRealm(boolean current) { - this.current = current; - } - - public boolean isCurrent() { - return current; - } - - public void setCurrent(boolean current) { - this.current = current; - } - - protected void syncExec(Runnable runnable) { - super.syncExec(runnable); - } - - public void asyncExec(Runnable runnable) { - throw new UnsupportedOperationException( - "CurrentRealm does not support asyncExec(Runnable)."); //$NON-NLS-1$ - } - - protected static Realm setDefault(Realm realm) { - return Realm.setDefault(realm); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/util/DelegatingRealm.java b/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/util/DelegatingRealm.java deleted file mode 100644 index 229d5fc5..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/util/DelegatingRealm.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.databinding.conformance.util; - -import org.eclipse.core.databinding.observable.Realm; - -/** - * Realm that will delegate to another for all operations except calls to - * {@link #isCurrent()}. The current status can be set by the consumer to - * enable testing of realm checks. - * - * @since 3.2 - */ -public class DelegatingRealm extends CurrentRealm { - private Realm realm; - - public DelegatingRealm(Realm realm) { - this.realm = realm; - } - - protected void syncExec(Runnable runnable) { - realm.exec(runnable); - } - - public void asyncExec(Runnable runnable) { - realm.asyncExec(runnable); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/util/ListChangeEventTracker.java b/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/util/ListChangeEventTracker.java deleted file mode 100644 index da2a2632..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/util/ListChangeEventTracker.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.databinding.conformance.util; - -import java.util.List; - -import org.eclipse.core.databinding.observable.list.IListChangeListener; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.ListChangeEvent; - -/** - * Listener for tracking the firing of ListChangeEvents. - */ -public class ListChangeEventTracker implements IListChangeListener { - public int count; - - public ListChangeEvent event; - - /** - * Queue that the listener will add itself too when it is notified of an - * event. Used to determine order of notifications of listeners. - */ - public final List listenerQueue; - - public ListChangeEventTracker() { - this(null); - } - - public ListChangeEventTracker(List listenerQueue) { - this.listenerQueue = listenerQueue; - } - - public void handleListChange(ListChangeEvent event) { - count++; - this.event = event; - if (listenerQueue != null) { - listenerQueue.add(this); - } - } - - /** - * Convenience method to register a new listener. - * - * @param observable - * @return tracker - */ - public static ListChangeEventTracker observe(IObservableList observable) { - ListChangeEventTracker tracker = new ListChangeEventTracker(); - observable.addListChangeListener(tracker); - return tracker; - } -} diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/util/MapChangeEventTracker.java b/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/util/MapChangeEventTracker.java deleted file mode 100644 index 52e87e92..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/util/MapChangeEventTracker.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.databinding.conformance.util; - -import java.util.List; - -import org.eclipse.core.databinding.observable.map.IMapChangeListener; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.map.MapChangeEvent; - -/** - * Listener for tracking the firing of ChangeEvents. - */ -public class MapChangeEventTracker implements IMapChangeListener { - public int count; - - public MapChangeEvent event; - - public List queue; - - public MapChangeEventTracker() { - this(null); - } - - public MapChangeEventTracker(List queue) { - this.queue = queue; - } - - public void handleMapChange(MapChangeEvent event) { - count++; - this.event = event; - - if (queue != null) { - queue.add(this); - } - } - - /** - * Convenience method to register a new listener. - * - * @param observable - * @return tracker - */ - public static MapChangeEventTracker observe(IObservableMap observable) { - MapChangeEventTracker tracker = new MapChangeEventTracker(); - observable.addMapChangeListener(tracker); - return tracker; - } -} diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/util/RealmTester.java b/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/util/RealmTester.java deleted file mode 100644 index bae6b173..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/util/RealmTester.java +++ /dev/null @@ -1,106 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - ******************************************************************************/ - -package org.eclipse.jface.databinding.conformance.util; - -import junit.framework.Assert; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.runtime.AssertionFailedException; - -/** - * Aids in the testing of Realms. - * - * @since 3.2 - */ -public class RealmTester { - - /** - * Sets the default realm without using Realm.runWithDefault() for testing - * purposes. - * - * @param realm - */ - public static void setDefault(Realm realm) { - CurrentRealm.setDefault(realm); - } - - /** - * Runs the provided <code>runnable</code> when the realm is both current - * and not current. It checks for AssertionFailedExceptions and if an - * exception occurs or doesn't occur as expected the test fails. The realm - * of an observable created before the method was invoked must be of type - * {@link CurrentRealm}. The default realm during the runnable invocation - * is set to an instance of {@link CurrentRealm} when the runnable is - * invoked. - * - * @param runnable - */ - public static void exerciseCurrent(Runnable runnable) { - CurrentRealm previousRealm = (CurrentRealm) Realm.getDefault(); - CurrentRealm realm = new CurrentRealm(); - setDefault(realm); - - try { - realm.setCurrent(true); - if (previousRealm != null) { - previousRealm.setCurrent(true); - } - - try { - runnable.run(); - } catch (AssertionFailedException e) { - Assert - .fail("Correct realm, exception should not have been thrown"); - } - - realm.setCurrent(false); - if (previousRealm != null) { - previousRealm.setCurrent(false); - } - - try { - runnable.run(); - Assert - .fail("Incorrect realm, exception should have been thrown"); - } catch (AssertionFailedException e) { - } - } finally { - setDefault(previousRealm); - } - } - - /** - * Runs the provided <code>runnable</code> when the realm is both current - * and not current. It checks for AssertionFailedExceptions and if an - * exception occurs or doesn't occur as expected the test fails. - * - * @param runnable - * @param realm - */ - public static void exerciseCurrent(Runnable runnable, CurrentRealm realm) { - realm.setCurrent(true); - - try { - runnable.run(); - } catch (AssertionFailedException e) { - Assert.fail("Correct realm, exception should not have been thrown"); - } - - realm.setCurrent(false); - - try { - runnable.run(); - Assert.fail("Incorrect realm, exception should have been thrown"); - } catch (AssertionFailedException e) { - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/util/SetChangeEventTracker.java b/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/util/SetChangeEventTracker.java deleted file mode 100644 index 9de2f887..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/util/SetChangeEventTracker.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.databinding.conformance.util; - -import java.util.List; - -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.ISetChangeListener; -import org.eclipse.core.databinding.observable.set.SetChangeEvent; - -public class SetChangeEventTracker implements ISetChangeListener { - public int count; - - public SetChangeEvent event; - - /** - * Queue that the listener will add itself too when it is notified of an - * event. Used to determine order of notifications of listeners. - */ - public final List listenerQueue; - - public SetChangeEventTracker() { - this(null); - } - - public SetChangeEventTracker(List notificationQueue) { - this.listenerQueue = notificationQueue; - } - - public void handleSetChange(SetChangeEvent event) { - count++; - this.event = event; - if (listenerQueue != null) { - listenerQueue.add(this); - } - } - - /** - * Convenience method to register a new listener. - * - * @param observable - * @return tracker - */ - public static SetChangeEventTracker observe(IObservableSet observable) { - SetChangeEventTracker tracker = new SetChangeEventTracker(); - observable.addSetChangeListener(tracker); - return tracker; - } -} diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/util/SuiteBuilder.java b/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/util/SuiteBuilder.java deleted file mode 100644 index cc50de5d..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/util/SuiteBuilder.java +++ /dev/null @@ -1,194 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bug 208322 - ******************************************************************************/ - -package org.eclipse.jface.databinding.conformance.util; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; -import java.util.Iterator; -import java.util.LinkedHashSet; - -import org.eclipse.jface.databinding.conformance.delegate.IObservableContractDelegate; - -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * Builds a test suite. - * - * @since 1.1 - */ -public class SuiteBuilder { - private LinkedHashSet content; - - public SuiteBuilder() { - content = new LinkedHashSet(); - } - - /** - * Adds all test methods from the provided <code>testCase</code> to the - * suite. - * - * @param testCase - * @return builder - */ - public SuiteBuilder addTests(Class testCase) { - content.add(testCase); - return this; - } - - /** - * Adds all test methods from the provided <code>testCase</code> with the - * provided <code>parameters</code>. A constructor must exist in the - * testCase that accepts a String as the first parameter followed by - * parameters matching the provided parameters. If an appropriate - * constructor is not found an exception will be thrown. - * - * @param testCase - * @param parameters - * @return builder - */ - public SuiteBuilder addParameterizedTests(Class testCase, - Object[] parameters) { - - Constructor constructor = findConstructor(testCase, parameters); - if (constructor == null) { - throw new IllegalArgumentException( - "The parameters provided don't match a constructor found in [" - + testCase.getName() + "]"); - } - - content.add(new ParameterizedTest(testCase, constructor, parameters)); - - return this; - } - - /** - * Convenience method for invoking - * {@link #addParameterizedTests(Class, Object[])} with a delegate. - * - * @param testCase - * @param delegate - * @return builder - */ - public SuiteBuilder addObservableContractTest(Class testCase, - IObservableContractDelegate delegate) { - - addParameterizedTests(testCase, new Object[] {delegate}); - return this; - } - - /** - * Builds a new TestSuite out of the tests. - * - * @return suite - */ - public TestSuite build() { - TestSuite suite = new TestSuite(); - - for (Iterator it = content.iterator(); it.hasNext();) { - Object o = it.next(); - if (o instanceof Class) { - suite.addTestSuite((Class) o); - } else if (o instanceof ParameterizedTest) { - ParameterizedTest test = (ParameterizedTest) o; - - // Outer test named for parameterized test class - TestSuite testClassSuite = new TestSuite(); - testClassSuite.setName(test.testClass.getName()); - - // Inner test named for parameter - TestSuite parameterSuite = new TestSuite(); - parameterSuite.setName(test.parameters[0].getClass().getName()); - testClassSuite.addTest(parameterSuite); - - Method[] methods = test.testClass.getMethods(); - for (int i = 0; i < methods.length; i++) { - String name = methods[i].getName(); - if (name.startsWith("test")) { - try { - parameterSuite.addTest((Test) test.constructor - .newInstance(toParamArray(name, - test.parameters))); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - } - - if (testClassSuite.countTestCases() > 0) - suite.addTest(testClassSuite); - } - } - - return suite; - } - - private Object[] toParamArray(String testName, Object[] parameters) { - Object[] result = new Object[parameters.length + 1]; - result[0] = testName; - System.arraycopy(parameters, 0, result, 1, parameters.length); - return result; - } - - /** - * Returns the constructor that has a String as the first parameters and - * then matches the type of the parameters. - * @param clazz - * @param parameters - * @return constructor - */ - private static Constructor findConstructor(Class clazz, Object[] parameters) { - Constructor[] constructors = clazz.getConstructors(); - int expectedParametersLength = parameters.length + 1; - - for (int i = 0; i < constructors.length; i++) { - Constructor constructor = constructors[i]; - Class[] types = constructor.getParameterTypes(); - - if (types.length != expectedParametersLength - || !String.class.equals(types[0])) { - continue; - } - - boolean skip = false; - for (int j = 1; j < types.length; j++) { - Class type = types[j]; - if (!type.isInstance(parameters[j - 1])) { - skip = true; - break; - } - } - - if (!skip) { - return constructor; - } - } - - return null; - } - - /* package */static class ParameterizedTest { - final Constructor constructor; - - final Object[] parameters; - - private Class testClass; - - ParameterizedTest(Class testClass, Constructor constructor, - Object[] parameterss) { - this.testClass = testClass; - this.constructor = constructor; - this.parameters = parameterss; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/util/ValueChangeEventTracker.java b/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/util/ValueChangeEventTracker.java deleted file mode 100644 index b54bd14c..00000000 --- a/tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/util/ValueChangeEventTracker.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.databinding.conformance.util; - -import java.util.List; - -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.observable.value.ValueChangeEvent; - -/** - * Listener for tracking the firing of ValueChangeEvents. - */ -public class ValueChangeEventTracker implements IValueChangeListener { - public int count; - - public ValueChangeEvent event; - - public final List queue; - - public ValueChangeEventTracker() { - this(null); - } - - public ValueChangeEventTracker(List queue) { - this.queue = queue; - } - - public void handleValueChange(ValueChangeEvent event) { - count++; - this.event = event; - - if (queue != null) { - queue.add(this); - } - } - - /** - * Convenience method to register a new listener. - * - * @param observable - * @return tracker - */ - public static ValueChangeEventTracker observe(IObservableValue observable) { - ValueChangeEventTracker tracker = new ValueChangeEventTracker(); - observable.addValueChangeListener(tracker); - return tracker; - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/.classpath b/tests/org.eclipse.jface.tests.databinding/.classpath deleted file mode 100644 index ce739334..00000000 --- a/tests/org.eclipse.jface.tests.databinding/.classpath +++ /dev/null @@ -1,7 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" path="src"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/> - <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> - <classpathentry kind="output" path="bin"/> -</classpath> diff --git a/tests/org.eclipse.jface.tests.databinding/.cvsignore b/tests/org.eclipse.jface.tests.databinding/.cvsignore deleted file mode 100644 index ba077a40..00000000 --- a/tests/org.eclipse.jface.tests.databinding/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -bin diff --git a/tests/org.eclipse.jface.tests.databinding/.project b/tests/org.eclipse.jface.tests.databinding/.project deleted file mode 100644 index 815de410..00000000 --- a/tests/org.eclipse.jface.tests.databinding/.project +++ /dev/null @@ -1,28 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<projectDescription> - <name>org.eclipse.jface.tests.databinding</name> - <comment></comment> - <projects> - </projects> - <buildSpec> - <buildCommand> - <name>org.eclipse.jdt.core.javabuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.ManifestBuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.SchemaBuilder</name> - <arguments> - </arguments> - </buildCommand> - </buildSpec> - <natures> - <nature>org.eclipse.pde.PluginNature</nature> - <nature>org.eclipse.jdt.core.javanature</nature> - </natures> -</projectDescription> diff --git a/tests/org.eclipse.jface.tests.databinding/.settings/org.eclipse.jdt.core.prefs b/tests/org.eclipse.jface.tests.databinding/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 9ad30f42..00000000 --- a/tests/org.eclipse.jface.tests.databinding/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,354 +0,0 @@ -#Fri Apr 04 13:14:00 GMT-07:00 2008 -eclipse.preferences.version=1 -org.eclipse.jdt.core.builder.cleanOutputFolder=clean -org.eclipse.jdt.core.builder.duplicateResourceTask=warning -org.eclipse.jdt.core.builder.invalidClasspath=abort -org.eclipse.jdt.core.builder.recreateModifiedClassFileInOutputFolder=ignore -org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=*.launch -org.eclipse.jdt.core.circularClasspath=error -org.eclipse.jdt.core.classpath.exclusionPatterns=enabled -org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled -org.eclipse.jdt.core.codeComplete.argumentPrefixes= -org.eclipse.jdt.core.codeComplete.argumentSuffixes= -org.eclipse.jdt.core.codeComplete.fieldPrefixes= -org.eclipse.jdt.core.codeComplete.fieldSuffixes= -org.eclipse.jdt.core.codeComplete.localPrefixes= -org.eclipse.jdt.core.codeComplete.localSuffixes= -org.eclipse.jdt.core.codeComplete.staticFieldPrefixes= -org.eclipse.jdt.core.codeComplete.staticFieldSuffixes= -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.4 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.doc.comment.support=enabled -org.eclipse.jdt.core.compiler.maxProblemPerUnit=100 -org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.autoboxing=ignore -org.eclipse.jdt.core.compiler.problem.deprecation=ignore -org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled -org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled -org.eclipse.jdt.core.compiler.problem.discouragedReference=ignore -org.eclipse.jdt.core.compiler.problem.emptyStatement=warning -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore -org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled -org.eclipse.jdt.core.compiler.problem.fieldHiding=warning -org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning -org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=error -org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=error -org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=error -org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore -org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=error -org.eclipse.jdt.core.compiler.problem.invalidJavadoc=ignore -org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=disabled -org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled -org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled -org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=private -org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore -org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=error -org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore -org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore -org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled -org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public -org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag -org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore -org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled -org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=public -org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore -org.eclipse.jdt.core.compiler.problem.missingSerialVersion=error -org.eclipse.jdt.core.compiler.problem.noEffectAssignment=error -org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=error -org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore -org.eclipse.jdt.core.compiler.problem.nullReference=warning -org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=error -org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore -org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning -org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore -org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning -org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore -org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore -org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled -org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=error -org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled -org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore -org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning -org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning -org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore -org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning -org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning -org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning -org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=enabled -org.eclipse.jdt.core.compiler.problem.unusedImport=error -org.eclipse.jdt.core.compiler.problem.unusedLabel=error -org.eclipse.jdt.core.compiler.problem.unusedLocal=error -org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore -org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled -org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=enabled -org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=enabled -org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=error -org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning -org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -org.eclipse.jdt.core.compiler.source=1.3 -org.eclipse.jdt.core.formatter.align_type_members_on_columns=false -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16 -org.eclipse.jdt.core.formatter.alignment_for_assignment=0 -org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 -org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 -org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 -org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0 -org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 -org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 -org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16 -org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 -org.eclipse.jdt.core.formatter.blank_lines_after_imports=1 -org.eclipse.jdt.core.formatter.blank_lines_after_package=1 -org.eclipse.jdt.core.formatter.blank_lines_before_field=0 -org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0 -org.eclipse.jdt.core.formatter.blank_lines_before_imports=1 -org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1 -org.eclipse.jdt.core.formatter.blank_lines_before_method=1 -org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1 -org.eclipse.jdt.core.formatter.blank_lines_before_package=0 -org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1 -org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1 -org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line -org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false -org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false -org.eclipse.jdt.core.formatter.comment.format_block_comments=true -org.eclipse.jdt.core.formatter.comment.format_header=false -org.eclipse.jdt.core.formatter.comment.format_html=true -org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true -org.eclipse.jdt.core.formatter.comment.format_line_comments=true -org.eclipse.jdt.core.formatter.comment.format_source_code=true -org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true -org.eclipse.jdt.core.formatter.comment.indent_root_tags=true -org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert -org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert -org.eclipse.jdt.core.formatter.comment.line_length=80 -org.eclipse.jdt.core.formatter.compact_else_if=true -org.eclipse.jdt.core.formatter.continuation_indentation=2 -org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 -org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true -org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true -org.eclipse.jdt.core.formatter.indent_empty_lines=false -org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true -org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true -org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true -org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false -org.eclipse.jdt.core.formatter.indentation.size=4 -org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert -org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert -org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert -org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert -org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert -org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert -org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert -org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert -org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert -org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert -org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert -org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert -org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert -org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert -org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert -org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false -org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false -org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false -org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false -org.eclipse.jdt.core.formatter.lineSplit=80 -org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false -org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false -org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 -org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 -org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true -org.eclipse.jdt.core.formatter.tabulation.char=tab -org.eclipse.jdt.core.formatter.tabulation.size=4 -org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false -org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true -org.eclipse.jdt.core.incompatibleJDKLevel=ignore -org.eclipse.jdt.core.incompleteClasspath=error diff --git a/tests/org.eclipse.jface.tests.databinding/.settings/org.eclipse.jdt.ui.prefs b/tests/org.eclipse.jface.tests.databinding/.settings/org.eclipse.jdt.ui.prefs deleted file mode 100644 index 8ee15567..00000000 --- a/tests/org.eclipse.jface.tests.databinding/.settings/org.eclipse.jdt.ui.prefs +++ /dev/null @@ -1,116 +0,0 @@ -#Mon Dec 03 13:56:42 EST 2007 -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_serial_version_id=false -cleanup.always_use_blocks=true -cleanup.always_use_parentheses_in_expressions=false -cleanup.always_use_this_for_non_static_field_access=false -cleanup.always_use_this_for_non_static_method_access=false -cleanup.convert_to_enhanced_for_loop=false -cleanup.correct_indentation=false -cleanup.format_source_code=false -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_variable_declarations_final=false -cleanup.never_use_blocks=false -cleanup.never_use_parentheses_in_expressions=true -cleanup.organize_imports=false -cleanup.qualify_static_field_accesses_with_declaring_class=false -cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true -cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true -cleanup.qualify_static_member_accesses_with_declaring_class=true -cleanup.qualify_static_method_accesses_with_declaring_class=false -cleanup.remove_private_constructors=true -cleanup.remove_trailing_whitespaces=false -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=false -cleanup.use_blocks_only_for_return_and_throw=false -cleanup.use_parentheses_in_expressions=false -cleanup.use_this_for_non_static_field_access=false -cleanup.use_this_for_non_static_field_access_only_if_necessary=true -cleanup.use_this_for_non_static_method_access=false -cleanup.use_this_for_non_static_method_access_only_if_necessary=true -cleanup_profile=org.eclipse.jdt.ui.default.eclipse_clean_up_profile -cleanup_settings_version=2 -eclipse.preferences.version=1 -editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=false -formatter_profile=org.eclipse.jdt.ui.default.eclipse_profile -formatter_settings_version=11 -org.eclipse.jdt.ui.exception.name=e -org.eclipse.jdt.ui.gettersetter.use.is=true -org.eclipse.jdt.ui.ignorelowercasenames=true -org.eclipse.jdt.ui.importorder=java;javax;org;com; -org.eclipse.jdt.ui.javadoc=true -org.eclipse.jdt.ui.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"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\r\n * @return Returns the ${bare_field_name}.\r\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\r\n * @param ${param} The ${bare_field_name} to set.\r\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="true" 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) ${year} IBM Corporation 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 * IBM Corporation - initial API and implementation\r\n ******************************************************************************/\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 * @since 3.2\r\n *\r\n * ${tags}\r\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\r\n * \r\n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="true" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/* (non-Javadoc)\r\n * ${see_to_overridden}\r\n */</template><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\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\r\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\r\n${body_statement}</template><template autoinsert\="true" 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}\r\n// ${todo} Auto-generated constructor stub</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><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\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\r\n * ${tags}\r\n * ${see_to_target}\r\n */</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_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=false -sp_cleanup.format_source_code=false -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_variable_declarations_final=true -sp_cleanup.never_use_blocks=false -sp_cleanup.never_use_parentheses_in_expressions=true -sp_cleanup.on_save_use_additional_actions=false -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=false -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=false -sp_cleanup.remove_unused_imports=false -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=false -sp_cleanup.use_blocks_only_for_return_and_throw=false -sp_cleanup.use_parentheses_in_expressions=false -sp_cleanup.use_this_for_non_static_field_access=false -sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true -sp_cleanup.use_this_for_non_static_method_access=false -sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true diff --git a/tests/org.eclipse.jface.tests.databinding/.settings/org.eclipse.pde.prefs b/tests/org.eclipse.jface.tests.databinding/.settings/org.eclipse.pde.prefs deleted file mode 100644 index 12a7331d..00000000 --- a/tests/org.eclipse.jface.tests.databinding/.settings/org.eclipse.pde.prefs +++ /dev/null @@ -1,18 +0,0 @@ -#Mon Dec 03 13:56:42 EST 2007 -compilers.incompatible-environment=1 -compilers.p.build=1 -compilers.p.deprecated=0 -compilers.p.illegal-att-value=0 -compilers.p.missing-bundle-classpath-entries=1 -compilers.p.missing-packages=2 -compilers.p.no-required-att=0 -compilers.p.not-externalized-att=0 -compilers.p.unknown-attribute=0 -compilers.p.unknown-class=1 -compilers.p.unknown-element=1 -compilers.p.unknown-resource=1 -compilers.p.unresolved-ex-points=0 -compilers.p.unresolved-import=0 -compilers.p.unused-element-or-attribute=1 -compilers.use-project=true -eclipse.preferences.version=1 diff --git a/tests/org.eclipse.jface.tests.databinding/JFace-Data Binding Test Suite.launch b/tests/org.eclipse.jface.tests.databinding/JFace-Data Binding Test Suite.launch deleted file mode 100644 index 5d1c7246..00000000 --- a/tests/org.eclipse.jface.tests.databinding/JFace-Data Binding Test Suite.launch +++ /dev/null @@ -1,37 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<launchConfiguration type="org.eclipse.pde.ui.JunitLaunchConfig"> -<stringAttribute key="application" value="org.eclipse.pde.junit.runtime.coretestapplication"/> -<booleanAttribute key="askclear" value="false"/> -<booleanAttribute key="automaticAdd" value="true"/> -<booleanAttribute key="automaticValidate" value="false"/> -<stringAttribute key="bootstrap" value=""/> -<stringAttribute key="checked" value="[NONE]"/> -<booleanAttribute key="clearConfig" value="true"/> -<booleanAttribute key="clearws" value="true"/> -<booleanAttribute key="clearwslog" value="false"/> -<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/pde-junit"/> -<booleanAttribute key="default" value="true"/> -<booleanAttribute key="includeOptional" value="true"/> -<stringAttribute key="location" value="${workspace_loc}/../junit-workspace"/> -<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> -<listEntry value="/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/BindingTestSuite.java"/> -</listAttribute> -<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> -<listEntry value="1"/> -</listAttribute> -<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/> -<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/> -<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/> -<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/> -<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit3"/> -<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.jface.tests.databinding.BindingTestSuite"/> -<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.jface.tests.databinding"/> -<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/> -<stringAttribute key="pde.version" value="3.3"/> -<stringAttribute key="product" value="org.eclipse.sdk.ide"/> -<stringAttribute key="templateConfig" value=""/> -<booleanAttribute key="tracing" value="false"/> -<booleanAttribute key="useDefaultConfig" value="true"/> -<booleanAttribute key="useDefaultConfigArea" value="false"/> -<booleanAttribute key="useProduct" value="false"/> -</launchConfiguration> diff --git a/tests/org.eclipse.jface.tests.databinding/META-INF/MANIFEST.MF b/tests/org.eclipse.jface.tests.databinding/META-INF/MANIFEST.MF deleted file mode 100644 index 16140984..00000000 --- a/tests/org.eclipse.jface.tests.databinding/META-INF/MANIFEST.MF +++ /dev/null @@ -1,19 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: %pluginName -Bundle-SymbolicName: org.eclipse.jface.tests.databinding -Bundle-Version: 1.0.101.qualifier -Bundle-ClassPath: jfacebindingtests.jar -Bundle-Vendor: %providerName -Bundle-Localization: plugin -Require-Bundle: org.eclipse.core.databinding, - org.junit, - org.eclipse.swt, - org.eclipse.jface, - org.eclipse.core.runtime, - org.eclipse.jface.examples.databinding, - org.eclipse.core.databinding.beans, - org.eclipse.jface.databinding, - org.eclipse.jface.tests.databinding.conformance -Import-Package: com.ibm.icu.text -Bundle-RequiredExecutionEnvironment: J2SE-1.4 diff --git a/tests/org.eclipse.jface.tests.databinding/about.html b/tests/org.eclipse.jface.tests.databinding/about.html deleted file mode 100644 index 46023304..00000000 --- a/tests/org.eclipse.jface.tests.databinding/about.html +++ /dev/null @@ -1,28 +0,0 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml"> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> -<title>About</title> -</head> -<body lang="EN-US"> -<h2>About This Content</h2> - -<p>June 2, 2006</p> -<h3>License</h3> - -<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise -indicated below, the Content is provided to you under the terms and conditions of the -Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available -at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>. -For purposes of the EPL, "Program" will mean the Content.</p> - -<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is -being redistributed by another party ("Redistributor") and different terms and conditions may -apply to your use of any object code in the Content. Check the Redistributor's license that was -provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise -indicated below, the terms and conditions of the EPL still apply to any source code in the Content -and such source code may be obtained at <a href="http://www.eclipse.org">http://www.eclipse.org</a>.</p> - -</body> -</html>
\ No newline at end of file diff --git a/tests/org.eclipse.jface.tests.databinding/build.properties b/tests/org.eclipse.jface.tests.databinding/build.properties deleted file mode 100644 index e671f5a5..00000000 --- a/tests/org.eclipse.jface.tests.databinding/build.properties +++ /dev/null @@ -1,20 +0,0 @@ -############################################################################### -# Copyright (c) 2005 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -source.jfacebindingtests.jar = src/ - -src.includes = about.html -output.jfacebindingtests.jar = bin/ -bin.includes = META-INF/,\ - about.html,\ - test.xml,\ - *.html,\ - jfacebindingtests.jar,\ - plugin.properties diff --git a/tests/org.eclipse.jface.tests.databinding/plugin.properties b/tests/org.eclipse.jface.tests.databinding/plugin.properties deleted file mode 100644 index 6f8acfcf..00000000 --- a/tests/org.eclipse.jface.tests.databinding/plugin.properties +++ /dev/null @@ -1,12 +0,0 @@ -############################################################################### -# Copyright (c) 2000, 2005 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -pluginName = JFace Data Binding Tests -providerName = Eclipse.org diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/AggregateValidationStatusTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/AggregateValidationStatusTest.java deleted file mode 100644 index 28d5b068..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/AggregateValidationStatusTest.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.databinding; - -import org.eclipse.core.databinding.AggregateValidationStatus; -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jface.tests.databinding.AbstractSWTTestCase; - -/** - * @since 1.1 - */ -public class AggregateValidationStatusTest extends AbstractSWTTestCase { - public void testAggregateValidationStatusValueType() throws Exception { - DataBindingContext dbc = new DataBindingContext(); - AggregateValidationStatus status = new AggregateValidationStatus(dbc - .getBindings(), AggregateValidationStatus.MAX_SEVERITY); - assertEquals(IStatus.class, status.getValueType()); - } - - public void testConstructor_DefaultRealm() throws Exception { - DataBindingContext dbc = new DataBindingContext(); - AggregateValidationStatus status = new AggregateValidationStatus(dbc - .getBindings(), AggregateValidationStatus.MAX_SEVERITY); - assertEquals(Realm.getDefault(), status.getRealm()); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/DatabindingContextTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/DatabindingContextTest.java deleted file mode 100755 index aa644370..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/DatabindingContextTest.java +++ /dev/null @@ -1,260 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 159539 - * Brad Reynolds - bug 140644 - * Brad Reynolds - bug 159940 - * Brad Reynolds - bug 116920, 159768 - * Matthew Hall - bug 213145 - *******************************************************************************/ -package org.eclipse.core.tests.databinding; - -import java.util.ArrayList; - -import org.eclipse.core.databinding.AggregateValidationStatus; -import org.eclipse.core.databinding.Binding; -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.UpdateListStrategy; -import org.eclipse.core.databinding.UpdateValueStrategy; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.databinding.validation.IValidator; -import org.eclipse.core.databinding.validation.ValidationStatus; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker; -import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -public class DatabindingContextTest extends AbstractDefaultRealmTestCase { - private DataBindingContext dbc; - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - - dbc = new DataBindingContext(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase#tearDown() - */ - protected void tearDown() throws Exception { - if (dbc != null) { - dbc.dispose(); - } - super.tearDown(); - } - - public void testDisposeBindings() throws Exception { - Binding binding = new BindingStub(); - binding.init(dbc); - - assertFalse(binding.isDisposed()); - dbc.dispose(); - assertTrue("binding should be diposed when dbc is disposed", binding - .isDisposed()); - } - - public void testBindValue() throws Exception { - IObservableValue target = WritableValue.withValueType(String.class); - IObservableValue model = WritableValue.withValueType(String.class); - - Binding binding = dbc.bindValue(target, model, null, null); - assertTrue("binding is of the incorrect type", - binding.getClass().getName().endsWith("ValueBinding")); - } - - public void testBindList() throws Exception { - IObservableList target = WritableList.withElementType(Object.class); - IObservableList model = WritableList.withElementType(Object.class); - - Binding binding = dbc.bindList(target, model, null, null); - assertTrue("binding is of the incorrect type", - binding.getClass().getName().endsWith("ListBinding")); - } - - /** - * Asserts that IStatus is populated and change events are fired when a - * Binding that is associated with a context is in error. - * - * @throws Exception - */ - public void testValidationError() throws Exception { - WritableValue targetObservable = WritableValue.withValueType(String.class); - WritableValue modelObservable = WritableValue.withValueType(String.class); - - final String errorMessage = "error"; - ValueChangeEventTracker errorCounter = new ValueChangeEventTracker(); - ChangeEventTracker errorsCounter = new ChangeEventTracker(); - - IObservableValue error = new AggregateValidationStatus(dbc - .getBindings(), AggregateValidationStatus.MAX_SEVERITY); - error.addValueChangeListener(errorCounter); - assertTrue(((IStatus) error.getValue()).isOK()); - - IObservableMap errors = dbc.getValidationStatusMap(); - errors.addChangeListener(errorsCounter); - assertEquals(0, errors.size()); - - IValidator validator = new IValidator() { - public IStatus validate(Object value) { - return ValidationStatus.error(errorMessage); - } - }; - - dbc - .bindValue(targetObservable, modelObservable, - new UpdateValueStrategy().setAfterGetValidator(validator), null); - - targetObservable.setValue(""); - assertFalse(((IStatus) error.getValue()).isOK()); - assertEquals(errorMessage, ((IStatus) error.getValue()).getMessage()); - assertEquals(1, errors.size()); - assertEquals(1, errorsCounter.count); - assertEquals(1, errorCounter.count); - error.dispose(); - } - - /** - * Asserts that then - * {@link DataBindingContext#bindValue(IObservableValue, IObservableValue, org.eclipse.jface.databinding.DefaultBindSpec, BindSpec)} - * if invoked the created binding is added to the internal list of bindings. - * - * @throws Exception - */ - public void testBindValueAddBinding() throws Exception { - WritableValue targetValue = WritableValue.withValueType(String.class); - WritableValue modelValue = WritableValue.withValueType(String.class); - - assertNotNull(dbc.getBindings()); - assertEquals(0, dbc.getBindings().size()); - - Binding binding = dbc.bindValue(targetValue, modelValue, null, null); - assertNotNull(binding); - assertNotNull(dbc.getBindings()); - assertEquals(1, dbc.getBindings().size()); - assertEquals(binding, dbc.getBindings().get(0)); - } - - /** - * Asserts that when - * {@link DataBindingContext#bindList(IObservableList, IObservableList, org.eclipse.jface.databinding.DefaultBindSpec, UpdateListStrategy)} - * is invoked the created binding is added to the intenal list of bindings. - * - * @throws Exception - */ - public void testBindListAddBinding() throws Exception { - WritableList targetList = new WritableList(new ArrayList(), - Object.class); - WritableList modelList = new WritableList(new ArrayList(), Object.class); - - assertNotNull(dbc.getBindings()); - assertEquals(0, dbc.getBindings().size()); - - Binding binding = dbc.bindList(targetList, modelList, null, null); - assertNotNull(binding); - assertNotNull(dbc.getBindings()); - assertEquals(1, dbc.getBindings().size()); - assertEquals(binding, dbc.getBindings().get(0)); - } - - public void testGetBindingsImmutability() throws Exception { - BindingStub binding = new BindingStub(); - binding.init(dbc); - - try { - dbc.getBindings().remove(0); - fail("exception should have been thrown"); - } catch (UnsupportedOperationException e) { - } - } - - public void testRemoveBinding() throws Exception { - BindingStub binding = new BindingStub(); - binding.init(dbc); - - assertTrue("context should contain the binding", dbc.getBindings() - .contains(binding)); - binding.dispose(); - assertFalse("binding should have been removed", dbc.getBindings() - .contains(binding)); - } - - /** - * Asserts that when a ValueBinding is created validation is ran to ensure - * that the validation status of the Binding reflects the validity of the - * value in the target. - * - * @throws Exception - */ - public void testValidateTargetAfterValueBindingCreation() throws Exception { - WritableValue target = new WritableValue("", String.class); - WritableValue model = new WritableValue("2", String.class); - class Validator implements IValidator { - public IStatus validate(Object value) { - return ValidationStatus.error("error"); - } - } - - Binding binding = dbc.bindValue(target, model, - new UpdateValueStrategy().setAfterConvertValidator(new Validator()), null); - - assertEquals(IStatus.ERROR, ((IStatus) binding.getValidationStatus() - .getValue()).getSeverity()); - } - - protected void assertNoErrorsFound() { - IStatus status = AggregateValidationStatus.getStatusMaxSeverity(dbc.getBindings()); - assertTrue("No errors should be found, but found " + status , status.isOK()); - } - - protected void assertErrorsFound() { - IStatus status = AggregateValidationStatus.getStatusMaxSeverity(dbc.getBindings()); - assertFalse("Errors should be found, but found none.", status.isOK()); - } - - private static class BindingStub extends Binding { - DataBindingContext context; - - public BindingStub() { - super(new WritableValue(), new WritableValue()); - } - - public IObservableValue getValidationStatus() { - return null; - } - - public void updateTargetToModel() { - } - - public void updateModelToTarget() { - } - - protected void postInit() { - } - - protected void preInit() { - } - - public void validateModelToTarget() { - } - - public void validateTargetToModel() { - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/ListBindingTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/ListBindingTest.java deleted file mode 100755 index cf97ec1d..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/ListBindingTest.java +++ /dev/null @@ -1,188 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 116920, 159768 - *******************************************************************************/ - -package org.eclipse.core.tests.databinding; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.core.databinding.Binding; -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.UpdateListStrategy; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.core.databinding.validation.ValidationStatus; -import org.eclipse.core.internal.databinding.BindingStatus; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -/** - * @since 1.1 - */ -public class ListBindingTest extends AbstractDefaultRealmTestCase { - private IObservableList target; - private IObservableList model; - private DataBindingContext dbc; - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - - target = new WritableList(new ArrayList(), String.class); - model = new WritableList(new ArrayList(), String.class); - dbc = new DataBindingContext(); - } - - public void testUpdateModelFromTarget() throws Exception { - Binding binding = dbc.bindList(target, model, - new UpdateListStrategy(UpdateListStrategy.POLICY_ON_REQUEST), - new UpdateListStrategy(UpdateListStrategy.POLICY_ON_REQUEST)); - - target.add("1"); - List targetCopy = new ArrayList(target.size()); - targetCopy.addAll(target); - - model.add("2"); - - assertFalse("target should not equal model", target.equals(model)); - binding.updateTargetToModel(); - assertEquals("target should not have changed", targetCopy, target); - assertEquals("target != model", target, model); - } - - public void testUpdateTargetFromModel() throws Exception { - Binding binding = dbc.bindList(target, model, - new UpdateListStrategy(UpdateListStrategy.POLICY_ON_REQUEST), - new UpdateListStrategy(UpdateListStrategy.POLICY_ON_REQUEST)); - - target.add("1"); - model.add("2"); - - List modelCopy = new ArrayList(model.size()); - modelCopy.addAll(model); - - assertFalse("model should not equal target", model.equals(target)); - binding.updateModelToTarget(); - - assertEquals("model should not have changed", modelCopy, model); - assertEquals("model != target", model, target); - } - - public void testGetTarget() throws Exception { - Binding binding = dbc.bindList(target, model, - null, - null); - assertEquals(target, binding.getTarget()); - } - - public void testGetModel() throws Exception { - Binding binding = dbc.bindList(target, model, - null, - null); - assertEquals(model, binding.getModel()); - } - - public void testStatusIsInstanceOfBindingStatus() throws Exception { - Binding binding = dbc.bindList(target, model, null, null); - assertTrue(binding.getValidationStatus().getValue() instanceof BindingStatus); - } - - public void testAddValidationStatusContainsMultipleStatuses() throws Exception { - UpdateListStrategy strategy = new UpdateListStrategy() { - protected IStatus doAdd(IObservableList observableList, - Object element, int index) { - super.doAdd(observableList, element, index); - - switch (index) { - case 0: - return ValidationStatus.error(""); - case 1: - return ValidationStatus.info(""); - } - - return null; - } - }; - - Binding binding = dbc.bindList(target, model, strategy, null); - target.addAll(Arrays.asList(new String[] {"1", "2"})); - - IStatus status = (IStatus) binding.getValidationStatus().getValue(); - assertEquals("maximum status", IStatus.ERROR, status.getSeverity()); - assertTrue("multi status", status.isMultiStatus()); - - IStatus[] children = status.getChildren(); - assertEquals("multi status children", 2, children.length); - assertEquals("first status severity", IStatus.ERROR, children[0].getSeverity()); - assertEquals("second status severity", IStatus.INFO, children[1].getSeverity()); - } - - public void testRemoveValidationStatusContainsMultipleStatuses() throws Exception { - List items = Arrays.asList(new String[] {"1", "2"}); - model.addAll(items); - - UpdateListStrategy strategy = new UpdateListStrategy() { - int count; - /* (non-Javadoc) - * @see org.eclipse.core.databinding.UpdateListStrategy#doRemove(org.eclipse.core.databinding.observable.list.IObservableList, int) - */ - protected IStatus doRemove(IObservableList observableList, int index) { - super.doRemove(observableList, index); - - switch (count++) { - case 0: - return ValidationStatus.error(""); - case 1: - return ValidationStatus.info(""); - } - - return null; - } - }; - - Binding binding = dbc.bindList(target, model, strategy, null); - target.removeAll(items); - - IStatus status = (IStatus) binding.getValidationStatus().getValue(); - assertEquals("maximum status", IStatus.ERROR, status.getSeverity()); - assertTrue("multi status", status.isMultiStatus()); - - IStatus[] children = status.getChildren(); - assertEquals("multi status children", 2, children.length); - assertEquals("first status severity", IStatus.ERROR, children[0].getSeverity()); - assertEquals("second status severity", IStatus.INFO, children[1].getSeverity()); - } - - public void testAddOKValidationStatus() throws Exception { - Binding binding = dbc.bindList(target, model, null, null); - target.add("1"); - - IStatus status = (IStatus) binding.getValidationStatus().getValue(); - assertTrue(status.isOK()); - assertEquals(0, status.getChildren().length); - } - - public void testRemoveOKValidationStatus() throws Exception { - model.add("1"); - Binding binding = dbc.bindList(target, model, null, null); - - target.remove("1"); - IStatus status = (IStatus) binding.getValidationStatus().getValue(); - assertTrue(status.isOK()); - assertEquals(0, status.getChildren().length); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/ObservablesManagerTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/ObservablesManagerTest.java deleted file mode 100644 index a89461bd..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/ObservablesManagerTest.java +++ /dev/null @@ -1,222 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Bob Smith 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: - * Bob Smith - initial API and implementation (bug 198880) - ******************************************************************************/ - -package org.eclipse.core.tests.databinding; - -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.ObservablesManager; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -/** - * @since 3.2 - * - */ -public class ObservablesManagerTest extends AbstractDefaultRealmTestCase { - private DataBindingContext dbc; - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - - dbc = new DataBindingContext(); - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase#tearDown() - */ - protected void tearDown() throws Exception { - if (dbc != null) { - dbc.dispose(); - } - super.tearDown(); - } - - public void testOnlyModelIsDisposed() throws Exception { - - FlagOnDisposeObservableValue targetOv = new FlagOnDisposeObservableValue(); - FlagOnDisposeObservableValue modelOv = new FlagOnDisposeObservableValue(); - dbc.bindValue(targetOv, modelOv, null, null); - - ObservablesManager observablesManager = new ObservablesManager(); - - observablesManager.addObservablesFromContext(dbc, false, true); - observablesManager.dispose(); - - assertFalse(targetOv.disposeCalled); - assertTrue(modelOv.disposeCalled); - } - - public void testOnlyTargetIsDisposed() throws Exception { - - FlagOnDisposeObservableValue targetOv = new FlagOnDisposeObservableValue(); - FlagOnDisposeObservableValue modelOv = new FlagOnDisposeObservableValue(); - dbc.bindValue(targetOv, modelOv, null, null); - - ObservablesManager observablesManager = new ObservablesManager(); - - observablesManager.addObservablesFromContext(dbc, true, false); - observablesManager.dispose(); - - assertTrue(targetOv.disposeCalled); - assertFalse(modelOv.disposeCalled); - } - - public void testTargetAndModelIsDisposed() throws Exception { - - FlagOnDisposeObservableValue targetOv = new FlagOnDisposeObservableValue(); - FlagOnDisposeObservableValue modelOv = new FlagOnDisposeObservableValue(); - dbc.bindValue(targetOv, modelOv, null, null); - - ObservablesManager observablesManager = new ObservablesManager(); - - observablesManager.addObservablesFromContext(dbc, true, true); - observablesManager.dispose(); - - assertTrue(targetOv.disposeCalled); - assertTrue(modelOv.disposeCalled); - } - - private static class FlagOnDisposeObservableValue implements - IObservableValue { - - private boolean disposeCalled = false; - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.observable.value.IObservableValue#addValueChangeListener(org.eclipse.core.databinding.observable.value.IValueChangeListener) - */ - public void addValueChangeListener(IValueChangeListener listener) { - // dummy - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.observable.value.IObservableValue#getValue() - */ - public Object getValue() { - // dummy - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.observable.value.IObservableValue#getValueType() - */ - public Object getValueType() { - // dummy - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.observable.value.IObservableValue#removeValueChangeListener(org.eclipse.core.databinding.observable.value.IValueChangeListener) - */ - public void removeValueChangeListener(IValueChangeListener listener) { - // dummy - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.observable.value.IObservableValue#setValue(java.lang.Object) - */ - public void setValue(Object value) { - // dummy - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.observable.IObservable#addChangeListener(org.eclipse.core.databinding.observable.IChangeListener) - */ - public void addChangeListener(IChangeListener listener) { - // dummy - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.observable.IObservable#addStaleListener(org.eclipse.core.databinding.observable.IStaleListener) - */ - public void addStaleListener(IStaleListener listener) { - // dummy - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.observable.IObservable#dispose() - */ - public void dispose() { - disposeCalled = true; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.observable.IObservable#getRealm() - */ - public Realm getRealm() { - return Realm.getDefault(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.observable.IObservable#isStale() - */ - public boolean isStale() { - // dummy - return false; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.observable.IObservable#removeChangeListener(org.eclipse.core.databinding.observable.IChangeListener) - */ - public void removeChangeListener(IChangeListener listener) { - // dummy - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.databinding.observable.IObservable#removeStaleListener(org.eclipse.core.databinding.observable.IStaleListener) - */ - public void removeStaleListener(IStaleListener listener) { - // dummy - - } - - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/UpdateStrategyTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/UpdateStrategyTest.java deleted file mode 100644 index 351f668d..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/UpdateStrategyTest.java +++ /dev/null @@ -1,315 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.databinding; - -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.Date; - -import org.eclipse.core.databinding.UpdateValueStrategy; -import org.eclipse.core.databinding.conversion.IConverter; -import org.eclipse.core.databinding.conversion.NumberToStringConverter; -import org.eclipse.core.databinding.conversion.StringToNumberConverter; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.internal.databinding.conversion.DateToStringConverter; -import org.eclipse.core.internal.databinding.conversion.IdentityConverter; -import org.eclipse.core.internal.databinding.conversion.IntegerToStringConverter; -import org.eclipse.core.internal.databinding.conversion.NumberToBigDecimalConverter; -import org.eclipse.core.internal.databinding.conversion.NumberToBigIntegerConverter; -import org.eclipse.core.internal.databinding.conversion.NumberToByteConverter; -import org.eclipse.core.internal.databinding.conversion.NumberToDoubleConverter; -import org.eclipse.core.internal.databinding.conversion.NumberToFloatConverter; -import org.eclipse.core.internal.databinding.conversion.NumberToIntegerConverter; -import org.eclipse.core.internal.databinding.conversion.NumberToLongConverter; -import org.eclipse.core.internal.databinding.conversion.NumberToShortConverter; -import org.eclipse.core.internal.databinding.conversion.StatusToStringConverter; -import org.eclipse.core.internal.databinding.conversion.StringToBooleanConverter; -import org.eclipse.core.internal.databinding.conversion.StringToBooleanPrimitiveConverter; -import org.eclipse.core.internal.databinding.conversion.StringToByteConverter; -import org.eclipse.core.internal.databinding.conversion.StringToCharacterConverter; -import org.eclipse.core.internal.databinding.conversion.StringToDateConverter; -import org.eclipse.core.internal.databinding.conversion.StringToShortConverter; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -/** - * @since 1.1 - */ -public class UpdateStrategyTest extends AbstractDefaultRealmTestCase { - public void testDefaultConverterForStringToInteger() throws Exception { - assertDefaultConverter(String.class, Integer.class, StringToNumberConverter.class); - } - - public void testDefaultConverterForStringToIntegerPrimitive() throws Exception { - assertDefaultConverter(String.class, Integer.TYPE, StringToNumberConverter.class); - } - - public void testDefaultConverterForStringToLong() throws Exception { - assertDefaultConverter(String.class, Long.class, StringToNumberConverter.class); - } - - public void testDefaultConverterForStringToLongPrimitive() throws Exception { - assertDefaultConverter(String.class, Long.TYPE, StringToNumberConverter.class); - } - - public void testDefaultConverterForStringToDouble() throws Exception { - assertDefaultConverter(String.class, Double.class, StringToNumberConverter.class); - } - - public void testDefaultConverterForStringToDoublePrimitive() throws Exception { - assertDefaultConverter(String.class, Double.TYPE, StringToNumberConverter.class); - } - - public void testDefaultConverterForStringToFloat() throws Exception { - assertDefaultConverter(String.class, Float.class, StringToNumberConverter.class); - } - - public void testDefaultConverterForStringToFloatPrimitive() throws Exception { - assertDefaultConverter(String.class, Float.TYPE, StringToNumberConverter.class); - } - - public void testDefaultConverterForStringToBigInteger() throws Exception { - assertDefaultConverter(String.class, BigInteger.class, StringToNumberConverter.class); - } - - public void testDefaultConverterForIntegerToString() throws Exception { - assertDefaultConverter(Integer.class, String.class, NumberToStringConverter.class); - } - - public void testDefaultConverterForIntegerPrimitiveToString() throws Exception { - assertDefaultConverter(Integer.TYPE, String.class, NumberToStringConverter.class); - } - - public void testDefaultConverterForLongToString() throws Exception { - assertDefaultConverter(Long.class, String.class, NumberToStringConverter.class); - } - - public void testDefaultConverterForLongPrimitiveToString() throws Exception { - assertDefaultConverter(Long.TYPE, String.class, NumberToStringConverter.class); - } - - public void testDefaultConverterForDoubleToString() throws Exception { - assertDefaultConverter(Double.class, String.class, NumberToStringConverter.class); - } - - public void testDefaultConverterForDoublePrimitiveToString() throws Exception { - assertDefaultConverter(Double.TYPE, String.class, NumberToStringConverter.class); - } - - public void testDefaultConverterForFloatToString() throws Exception { - assertDefaultConverter(Float.class, String.class, NumberToStringConverter.class); - } - - public void testDefaultConverterForFloatPrimitiveToString() throws Exception { - assertDefaultConverter(Float.TYPE, String.class, NumberToStringConverter.class); - } - - public void testDefaultConverterForBigIntegerToString() throws Exception { - assertDefaultConverter(BigInteger.class, String.class, NumberToStringConverter.class); - } - - public void testDefaultConverterForDateToString() throws Exception { - assertDefaultConverter(Date.class, String.class, DateToStringConverter.class); - } - - public void testDefaultConverterForStringToBoolean() throws Exception { - assertDefaultConverter(String.class, Boolean.class, StringToBooleanConverter.class); - } - - public void testDefaultConverterForStringToBooleanPrimitive() throws Exception { - assertDefaultConverter(String.class, Boolean.TYPE, StringToBooleanPrimitiveConverter.class); - } - - public void testDefaultConverterForStringToByte() throws Exception { - assertDefaultConverter(String.class, Byte.class, StringToByteConverter.class); - } - - public void testDefaultConverterForStringToBytePrimitive() throws Exception { - assertDefaultConverter(String.class, Byte.TYPE, StringToByteConverter.class); - } - - public void testDefaultConverterForStringToCharacter() throws Exception { - assertDefaultConverter(String.class, Character.class, StringToCharacterConverter.class); - } - - public void testDefaultConverterForStringToDate() throws Exception { - assertDefaultConverter(String.class, Date.class, StringToDateConverter.class); - } - - public void testDefaultConverterForStringToShort() throws Exception { - assertDefaultConverter(String.class, Short.class, StringToShortConverter.class); - } - - public void testDefaultConverterForStringToShortPrimitive() throws Exception { - assertDefaultConverter(String.class, Short.TYPE, StringToShortConverter.class); - } - - public void testDefaultConverterForByteToString() throws Exception { - assertDefaultConverter(Byte.class, String.class, IntegerToStringConverter.class); - } - - public void testDefaultConverterForBytePrimitiveToString() throws Exception { - assertDefaultConverter(Byte.TYPE, String.class, IntegerToStringConverter.class); - } - - public void testDefaultConverterForShortToString() throws Exception { - assertDefaultConverter(Short.class, String.class, IntegerToStringConverter.class); - } - - public void testDefaultConverterForShortPrimitiveToString() throws Exception { - assertDefaultConverter(Short.TYPE, String.class, IntegerToStringConverter.class); - } - - public void testDefaultConverterForStatusToString() throws Exception { - assertDefaultConverter(IStatus.class, String.class, StatusToStringConverter.class); - } - - - public void testDefaultConverterForNumberToByte() throws Exception { - assertFromNumberToNumberConverter(Byte.class, Byte.TYPE, - NumberToByteConverter.class); - } - - public void testDefaultConverterForNumberToShort() throws Exception { - assertFromNumberToNumberConverter(Short.class, Short.TYPE, - NumberToShortConverter.class); - } - - public void testDefaultConverterForNumberToShortPrimitive() - throws Exception { - assertFromNumberToNumberConverter(Short.TYPE, Short.class, - NumberToShortConverter.class); - } - - public void testDefaultConverterForNumberToInteger() throws Exception { - assertFromNumberToNumberConverter(Integer.class, Integer.TYPE, - NumberToIntegerConverter.class); - } - - public void testDefaultConverterForNumberToIntegerPrimitive() - throws Exception { - assertFromNumberToNumberConverter(Integer.TYPE, Integer.class, - NumberToIntegerConverter.class); - } - - public void testDefaultConverterForNumberToLong() throws Exception { - assertFromNumberToNumberConverter(Long.class, Long.TYPE, - NumberToLongConverter.class); - } - - public void testDefaultConverterForNumberToLongPrimitive() throws Exception { - assertFromNumberToNumberConverter(Long.TYPE, Long.class, - NumberToLongConverter.class); - } - - public void testDefaultConverterForNumberToFloat() throws Exception { - assertFromNumberToNumberConverter(Float.class, Float.TYPE, - NumberToFloatConverter.class); - } - - public void testDefaultConverterForNumberToFloatPrimitive() - throws Exception { - assertFromNumberToNumberConverter(Float.TYPE, Float.class, - NumberToFloatConverter.class); - } - - public void testDefaultConverterForNumberToDouble() throws Exception { - assertFromNumberToNumberConverter(Double.class, Double.TYPE, - NumberToDoubleConverter.class); - } - - public void testDefaultConverterForNumberToDoublePrimitive() - throws Exception { - assertFromNumberToNumberConverter(Double.TYPE, Double.class, - NumberToDoubleConverter.class); - } - - public void testDefaultConverterForNumberToBigInteger() throws Exception { - assertFromNumberToNumberConverter(BigInteger.class, null, - NumberToBigIntegerConverter.class); - } - - public void testDefaultConverterForNumberToBigDecimal() throws Exception { - assertFromNumberToNumberConverter(BigDecimal.class, null, - NumberToBigDecimalConverter.class); - } - - - private static Class[] primitiveNumberTypes = new Class[] { Byte.TYPE, - Short.TYPE, Integer.TYPE, Long.TYPE, Float.TYPE, Double.TYPE }; - - private static Class[] boxedNumberTypes = new Class[] { Byte.class, - Short.class, Integer.class, Long.class, Float.class, Double.class, - BigInteger.class, BigDecimal.class }; - - private void assertFromNumberToNumberConverter(Class toType, - Class toCounterPrimitiveType, Class converterType) { - - for (int i = 0; i < primitiveNumberTypes.length; i++) { - Class primitiveType = primitiveNumberTypes[i]; - - if (!primitiveType.equals(toType) - && !primitiveType.equals(toCounterPrimitiveType)) { - assertDefaultConverter(primitiveType, toType, converterType); - } else if (!primitiveType.equals(toType)) { - assertDefaultConverter(primitiveType, toType, - IdentityConverter.class); - } - } - - for (int i = 0; i < boxedNumberTypes.length; i++) { - Class boxedType = boxedNumberTypes[i]; - - if (!boxedType.equals(toType) - && !boxedType.equals(toCounterPrimitiveType)) { - assertDefaultConverter(boxedType, toType, converterType); - } else if (!boxedType.equals(toType)) { - assertDefaultConverter(boxedType, toType, - IdentityConverter.class); - } - } - } - - private void assertDefaultConverter(Class fromType, Class toType, Class converterType) { - WritableValue source = WritableValue.withValueType(fromType); - WritableValue destination = WritableValue.withValueType(toType); - - UpdateStrategyStub strategy = new UpdateStrategyStub(); - strategy.fillDefaults(source, destination); - - IConverter converter = strategy.converter; - assertNotNull("converter not null", converter); - assertEquals("fromType [" + fromType + "]" , fromType, converter.getFromType()); - assertEquals("toType [" + toType + "]", toType, converter.getToType()); - assertTrue("converter should be instanceof " + converterType - + " but was instanceof " + converter.getClass(), converterType - .isInstance(converter)); - } - - class UpdateStrategyStub extends UpdateValueStrategy { - IConverter converter; - - protected void fillDefaults(IObservableValue source, - IObservableValue destination) { - super.fillDefaults(source, destination); - } - - /* (non-Javadoc) - * @see org.eclipse.core.databinding.UpdateValueStrategy#setConverter(org.eclipse.core.databinding.conversion.IConverter) - */ - public UpdateValueStrategy setConverter(IConverter converter) { - this.converter = converter; - return super.setConverter(converter); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/UpdateValueStrategyTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/UpdateValueStrategyTest.java deleted file mode 100644 index 881b562f..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/UpdateValueStrategyTest.java +++ /dev/null @@ -1,170 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.databinding; - -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.Date; - -import org.eclipse.core.databinding.UpdateValueStrategy; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.databinding.validation.IValidator; -import org.eclipse.core.internal.databinding.validation.NumberToByteValidator; -import org.eclipse.core.internal.databinding.validation.NumberToDoubleValidator; -import org.eclipse.core.internal.databinding.validation.NumberToFloatValidator; -import org.eclipse.core.internal.databinding.validation.NumberToIntegerValidator; -import org.eclipse.core.internal.databinding.validation.NumberToLongValidator; -import org.eclipse.core.internal.databinding.validation.NumberToShortValidator; -import org.eclipse.core.internal.databinding.validation.NumberToUnboundedNumberValidator; -import org.eclipse.core.internal.databinding.validation.StringToByteValidator; -import org.eclipse.core.internal.databinding.validation.StringToDateValidator; -import org.eclipse.core.internal.databinding.validation.StringToDoubleValidator; -import org.eclipse.core.internal.databinding.validation.StringToFloatValidator; -import org.eclipse.core.internal.databinding.validation.StringToIntegerValidator; -import org.eclipse.core.internal.databinding.validation.StringToLongValidator; -import org.eclipse.core.internal.databinding.validation.StringToShortValidator; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -/** - * @since 1.1 - */ -public class UpdateValueStrategyTest extends AbstractDefaultRealmTestCase { - public void testDefaultValidatorForStringToInteger() throws Exception { - assertDefaultValidator(String.class, Integer.class, StringToIntegerValidator.class); - } - - public void testDefaultValidatorForStringToIntegerPrimitive() throws Exception { - assertDefaultValidator(String.class, Integer.TYPE, StringToIntegerValidator.class); - } - - public void testDefaultValidatorForStringToLong() throws Exception { - assertDefaultValidator(String.class, Long.class, StringToLongValidator.class); - } - - public void testDefaultValidatorForStringToLongPrimitive() throws Exception { - assertDefaultValidator(String.class, Long.TYPE, StringToLongValidator.class); - } - - public void testDefaultValidatorForStringToFloat() throws Exception { - assertDefaultValidator(String.class, Float.class, StringToFloatValidator.class); - } - - public void testDefaultValidatorForStringToFloatPrimitive() throws Exception { - assertDefaultValidator(String.class, Float.TYPE, StringToFloatValidator.class); - } - - public void testDefaultValidatorForStringToDouble() throws Exception { - assertDefaultValidator(String.class, Double.class, StringToDoubleValidator.class); - } - - public void testDefaultValidatorForStringToDoublePrimitive() throws Exception { - assertDefaultValidator(String.class, Double.TYPE, StringToDoubleValidator.class); - } - - public void testDefaultValidatorForStringToByte() throws Exception { - assertDefaultValidator(String.class, Byte.class, StringToByteValidator.class); - } - - public void testDefaultValidatorForStringToBytePrimitive() throws Exception { - assertDefaultValidator(String.class, Byte.TYPE, StringToByteValidator.class); - } - - public void testDefaultValidatorForStringToShort() throws Exception { - assertDefaultValidator(String.class, Short.class, StringToShortValidator.class); - } - - public void testDefaultValidatorForStringToShortPrimitive() throws Exception { - assertDefaultValidator(String.class, Short.TYPE, StringToShortValidator.class); - } - - public void testDefaultValidatorForStringToDate() throws Exception { - assertDefaultValidator(String.class, Date.class, StringToDateValidator.class); - } - - public void testDefaultValidatorForNumberToByte() throws Exception { - assertDefaultValidator(Integer.class, Byte.class, NumberToByteValidator.class); - } - - public void testDefaultValidatorForNumberToShort() throws Exception { - assertDefaultValidator(Integer.class, Short.class, NumberToShortValidator.class); - } - - public void testDefaultValidatorForNumberToInteger() throws Exception { - assertDefaultValidator(Short.class, Integer.class, NumberToIntegerValidator.class); - } - - public void testDefaultValidatorForNumberToLong() throws Exception { - assertDefaultValidator(Short.class, Long.class, NumberToLongValidator.class); - } - - public void testDefaultValidatorForNumberToFloat() throws Exception { - assertDefaultValidator(Short.class, Float.class, NumberToFloatValidator.class); - } - - public void testDefaultValidatorForNumberToDouble() throws Exception { - assertDefaultValidator(Short.class, Double.class, NumberToDoubleValidator.class); - } - - public void testDefaultValidatorForNumberToBigInteger() throws Exception { - assertDefaultValidator(Short.class, BigInteger.class, NumberToUnboundedNumberValidator.class); - } - - public void testDefaultValidatorForNumberToBigDecimal() throws Exception { - assertDefaultValidator(Short.class, BigDecimal.class, NumberToUnboundedNumberValidator.class); - } - - public void testCachesDefaultedValidators() throws Exception { - WritableValue source = WritableValue.withValueType(String.class); - WritableValue destination = WritableValue.withValueType(Integer.class); - - UpdateValueStrategyStub strategy = new UpdateValueStrategyStub(); - strategy.fillDefaults(source, destination); - - IValidator validator = strategy.validator; - assertNotNull(validator); - - strategy = new UpdateValueStrategyStub(); - strategy.fillDefaults(source, destination); - - assertSame(validator,strategy.validator); - } - - private void assertDefaultValidator(Class fromType, Class toType, Class validatorType) { - WritableValue source = WritableValue.withValueType(fromType); - WritableValue destination = WritableValue.withValueType(toType); - - UpdateValueStrategyStub strategy = new UpdateValueStrategyStub(); - strategy.fillDefaults(source, destination); - - IValidator validator = strategy.validator; - assertNotNull("validator not null", validator); - assertTrue("converter instanceof " + validatorType, validatorType.isInstance(validator)); - } - - class UpdateValueStrategyStub extends UpdateValueStrategy { - IValidator validator; - - protected void fillDefaults(IObservableValue source, - IObservableValue destination) { - super.fillDefaults(source, destination); - } - - /* (non-Javadoc) - * @see org.eclipse.core.databinding.UpdateValueStrategy#createValidator(java.lang.Object, java.lang.Object) - */ - protected IValidator createValidator(Object fromType, Object toType) { - validator = super.createValidator(fromType, toType); - return validator; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/ValueBindingTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/ValueBindingTest.java deleted file mode 100755 index 12d32cd8..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/ValueBindingTest.java +++ /dev/null @@ -1,279 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Brad Reynolds - bug 116920 - * Brad Reynolds - bug 164653, 159768 - ******************************************************************************/ - -package org.eclipse.core.tests.databinding; - -import org.eclipse.core.databinding.Binding; -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.UpdateValueStrategy; -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.value.AbstractObservableValue; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.ValueDiff; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.databinding.validation.IValidator; -import org.eclipse.core.databinding.validation.ValidationStatus; -import org.eclipse.core.internal.databinding.BindingStatus; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -/** - * @since 1.1 - */ -public class ValueBindingTest extends AbstractDefaultRealmTestCase { - private WritableValue target; - - private WritableValue model; - - private DataBindingContext dbc; - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - - target = WritableValue.withValueType(String.class); - model = WritableValue.withValueType(String.class); - dbc = new DataBindingContext(); - } - - /** - * Bug 152543. - * - * @throws Exception - */ - public void testNoUpdateTargetFromModel() throws Exception { - try { - new DataBindingContext().bindValue(new ObservableValueStub(), - new ObservableValueStub(), new UpdateValueStrategy( - UpdateValueStrategy.POLICY_NEVER), - new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER)); - } catch (Exception e) { - fail(e.getMessage()); - } - } - - public void testValuePropagation() throws Exception { - String initialValue = "value"; - model.setValue(initialValue); - - assertFalse(model.getValue().equals(target.getValue())); - dbc.bindValue(target, model, null, null); - - assertEquals(target.getValue(), model.getValue()); - } - - public void testGetTarget() throws Exception { - Binding binding = dbc.bindValue(target, model, null, null); - - assertEquals(target, binding.getTarget()); - } - - public void testGetModel() throws Exception { - Binding binding = dbc.bindValue(target, model, null, null); - - assertEquals(model, binding.getModel()); - } - - public void testOKStatusInValidationUpdatesModel() throws Exception { - Binding binding = dbc.bindValue(target, model, null, null); - - String value = "value"; - assertFalse(value.equals(model.getValue())); - target.setValue(value); - - assertEquals("value copied to model", value, model.getValue()); - assertTrue(((IStatus) binding.getValidationStatus().getValue()).isOK()); - } - - public void testWarningStatusInValidationUpdatesModel() throws Exception { - Binding binding = dbc.bindValue(target, model, - new UpdateValueStrategy() - .setAfterGetValidator(warningValidator()), null); - - String value = "value"; - assertFalse(value.equals(model.getValue())); - target.setValue(value); - - assertEquals("value copied to model", value, model.getValue()); - assertEquals("warning status", IStatus.WARNING, ((IStatus) binding - .getValidationStatus().getValue()).getSeverity()); - } - - public void testInfoStatusInValidationUpdatesModel() throws Exception { - Binding binding = dbc - .bindValue(target, model, new UpdateValueStrategy() - .setAfterGetValidator(infoValidator()), null); - - String value = "value"; - assertFalse(value.equals(model.getValue())); - target.setValue(value); - - assertEquals("value copied to model", value, model.getValue()); - assertEquals("info status", IStatus.INFO, ((IStatus) binding - .getValidationStatus().getValue()).getSeverity()); - } - - public void testErrorStatusInValidationDoesNotUpdateModel() - throws Exception { - Binding binding = dbc.bindValue(target, model, - new UpdateValueStrategy() - .setAfterGetValidator(errorValidator()), null); - - String value = "value"; - assertFalse(value.equals(model.getValue())); - target.setValue(value); - - assertFalse("value not copied to model", value.equals(model.getValue())); - assertEquals("error status", IStatus.ERROR, ((IStatus) binding - .getValidationStatus().getValue()).getSeverity()); - } - - public void testCancelStatusInValidationDoesNotUpdateModel() - throws Exception { - Binding binding = dbc.bindValue(target, model, - new UpdateValueStrategy() - .setAfterGetValidator(cancelValidator()), null); - - String value = "value"; - assertFalse(value.equals(model.getValue())); - target.setValue(value); - - assertFalse("value not copied to model", value.equals(model.getValue())); - assertEquals("cancel status", IStatus.CANCEL, ((IStatus) binding - .getValidationStatus().getValue()).getSeverity()); - } - - public void testStatusesFromEveryPhaseAreReturned() throws Exception { - UpdateValueStrategy strategy = new UpdateValueStrategy() { - protected IStatus doSet(IObservableValue observableValue, - Object value) { - super.doSet(observableValue, value); - return ValidationStatus.info(""); - } - }; - - strategy.setAfterGetValidator(warningValidator()); - strategy.setAfterConvertValidator(infoValidator()); - strategy.setBeforeSetValidator(warningValidator()); - - Binding binding = dbc.bindValue(target, model, strategy, null); - String value = "value"; - assertFalse(value.equals(model.getValue())); - - target.setValue(value); - assertEquals(value, model.getValue()); - IStatus status = (IStatus) binding.getValidationStatus().getValue(); - assertTrue(status.isMultiStatus()); - assertEquals("max status", IStatus.WARNING, status.getSeverity()); - - MultiStatus multiStatus = (MultiStatus) status; - assertEquals(4, multiStatus.getChildren().length); - IStatus[] children = multiStatus.getChildren(); - - assertEquals("after get severity", IStatus.WARNING, children[0] - .getSeverity()); - assertEquals("after convert severity", IStatus.INFO, children[1] - .getSeverity()); - assertEquals("before set severity", IStatus.WARNING, children[2] - .getSeverity()); - assertEquals("doSet severity", IStatus.INFO, children[3].getSeverity()); - } - - public void testStatusIsInstanceOfBindingStatus() throws Exception { - Binding binding = dbc.bindValue(target, model, null, null); - assertTrue(binding.getValidationStatus().getValue() instanceof BindingStatus); - } - - public void testDiffsAreCheckedForEqualityBeforeUpdate() throws Exception { - class WritableValueStub extends WritableValue { - public WritableValueStub() { - super("", String.class); - } - - protected void fireValueChange(ValueDiff diff) { - super.fireValueChange(diff); - } - } - - WritableValueStub target = new WritableValueStub(); - WritableValue model = WritableValue.withValueType(String.class); - - class Strategy extends UpdateValueStrategy { - int afterGetCount; - public IStatus validateAfterGet(Object value) { - afterGetCount++; - return super.validateAfterGet(value); - } - } - - Strategy strategy = new Strategy(); - dbc.bindValue(target, model, strategy, null); - int count = strategy.afterGetCount; - - target.fireValueChange(Diffs.createValueDiff("", "")); - assertEquals("update does not occur", count, strategy.afterGetCount); - } - - private IValidator warningValidator() { - return new IValidator() { - public IStatus validate(Object value) { - return ValidationStatus.warning(""); - } - }; - } - - private IValidator infoValidator() { - return new IValidator() { - public IStatus validate(Object value) { - return ValidationStatus.info(""); - } - }; - } - - private IValidator errorValidator() { - return new IValidator() { - public IStatus validate(Object value) { - return ValidationStatus.error(""); - } - }; - } - - private IValidator cancelValidator() { - return new IValidator() { - public IStatus validate(Object value) { - return ValidationStatus.cancel(""); - } - }; - } - - private static class ObservableValueStub extends AbstractObservableValue { - protected Object doGetValue() { - // do nothing - return null; - } - - public Object getValueType() { - // do nothing - return null; - } - - protected void doSetValue(Object value) { - - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/beans/BeansObservablesTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/beans/BeansObservablesTest.java deleted file mode 100644 index 4e1b652c..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/beans/BeansObservablesTest.java +++ /dev/null @@ -1,227 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006-2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164268, 171616 - * Mike Evans - bug 217558 - * Matthew Hall - bug 221351 - *******************************************************************************/ - -package org.eclipse.core.tests.databinding.beans; - -import java.util.Arrays; - -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.beans.IBeanObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.internal.databinding.beans.BeanObservableListDecorator; -import org.eclipse.core.internal.databinding.beans.BeanObservableSetDecorator; -import org.eclipse.core.internal.databinding.beans.BeanObservableValueDecorator; -import org.eclipse.core.tests.internal.databinding.beans.Bean; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -/** - * @since 3.2 - */ -public class BeansObservablesTest extends AbstractDefaultRealmTestCase { - Bean[] elements = null; - Bean model = null; - Class elementType = null; - - protected void setUp() throws Exception { - super.setUp(); - - elements = new Bean[] { new Bean("1"), new Bean("2"), new Bean("3") }; - model = new Bean(elements); - model.setList(Arrays.asList(elements)); - elementType = Bean.class; - } - - public void testObserveListArrayInferredElementType() throws Exception { - IObservableList list = BeansObservables.observeList(Realm.getDefault(), - model, "list", null); - assertEquals("element type", Object.class, list.getElementType()); - } - - public void testObserveListNonInferredElementType() throws Exception { - elementType = Object.class; - IObservableList list = BeansObservables.observeList(Realm.getDefault(), - model, "list", null); - assertEquals("element type", elementType, list.getElementType()); - } - - public void testListFactory() throws Exception { - IObservableFactory factory = BeansObservables.listFactory(Realm - .getDefault(), "list", elementType); - IObservableList list = (IObservableList) factory - .createObservable(model); - - assertTrue("elements of the list", Arrays.equals(elements, list - .toArray(new Bean[list.size()]))); - assertEquals("element type", elementType, list.getElementType()); - } - - public void testObserveDetailListElementType() throws Exception { - WritableValue parent = WritableValue.withValueType(Bean.class); - parent.setValue(model); - IObservableList list = BeansObservables.observeDetailList(Realm - .getDefault(), parent, "list", elementType); - - assertEquals("element type", elementType, list.getElementType()); - assertTrue("elements of list", Arrays.equals(elements, list - .toArray(new Bean[list.size()]))); - } - - public void testObserveDetailValueIBeanObservable() throws Exception { - WritableValue parent = WritableValue.withValueType(Bean.class); - parent.setValue(new Bean()); - - IObservableValue detailValue = BeansObservables.observeDetailValue( - Realm.getDefault(), parent, "value", String.class); - assertTrue(detailValue instanceof IBeanObservable); - - BeanObservableValueDecorator beanObservable = (BeanObservableValueDecorator) detailValue; - assertEquals("property descriptor", Bean.class.getMethod("getValue", - null), beanObservable.getPropertyDescriptor().getReadMethod()); - assertEquals("observed", parent.getValue(), beanObservable.getObserved()); - assertTrue("delegate", beanObservable.getDelegate().getClass() - .getName().endsWith("DetailObservableValue")); - } - - public void testObserveDetailValueNullOuterElementType() throws Exception { - WritableValue parent = new WritableValue(new Bean(), null); - - IObservableValue detailValue = BeansObservables.observeDetailValue( - Realm.getDefault(), parent, "value", String.class); - - assertNull("property descriptor", ((IBeanObservable) detailValue) - .getPropertyDescriptor()); - } - - public void testObservableDetailListIBeanObservable() throws Exception { - WritableValue parent = WritableValue.withValueType(Bean.class); - parent.setValue(new Bean()); - - IObservableList detailList = BeansObservables.observeDetailList(Realm - .getDefault(), parent, "list", Bean.class); - assertTrue("detail is not an IBeanObservable", - detailList instanceof IBeanObservable); - - BeanObservableListDecorator beanObservable = (BeanObservableListDecorator) detailList; - assertEquals("property descriptor", Bean.class.getMethod("getList", - null), beanObservable.getPropertyDescriptor().getReadMethod()); - assertEquals("observed", parent, beanObservable.getObserved()); - - // DetailObservableList is package level we can do a straight instanceof - // check - assertTrue("delegate is the observed", beanObservable.getDelegate() - .equals(detailList)); - } - - public void testObservableDetailListNullOuterElementType() throws Exception { - WritableValue parent = new WritableValue(new Bean(), null); - - IObservableList detailList = BeansObservables.observeDetailList(Realm - .getDefault(), parent, "list", Bean.class); - - assertNull("property descriptor", ((IBeanObservable) detailList) - .getPropertyDescriptor()); - } - - public void testObservableDetailSetIBeanObservable() throws Exception { - WritableValue parent = WritableValue.withValueType(Bean.class); - parent.setValue(new Bean()); - - IObservableSet detailSet = BeansObservables.observeDetailSet(Realm - .getDefault(), parent, "set", Bean.class); - assertTrue("detail is not an IBeanObservable", - detailSet instanceof IBeanObservable); - - BeanObservableSetDecorator beanObservable = (BeanObservableSetDecorator) detailSet; - assertEquals("property descriptor", Bean.class - .getMethod("getSet", null), beanObservable - .getPropertyDescriptor().getReadMethod()); - assertEquals("observed", parent, beanObservable.getObserved()); - - // DetailObservableSet is package level we can't do a straight - // instanceof check - assertTrue("delegate is the observed", beanObservable.getDelegate() - .equals(detailSet)); - } - - public void testObservableDetailSetNullOuterElementType() throws Exception { - WritableValue parent = new WritableValue(new Bean(), null); - - IObservableSet detailSet = BeansObservables.observeDetailSet(Realm - .getDefault(), parent, "set", Bean.class); - - assertNull("property descriptor", ((IBeanObservable) detailSet) - .getPropertyDescriptor()); - } - - public void testObserveSetElementType() throws Exception { - Bean bean = new Bean(); - IObservableSet observableSet = BeansObservables.observeSet(Realm - .getDefault(), bean, "set", Bean.class); - assertEquals(Bean.class, observableSet.getElementType()); - } - - public void testObserveSetNonInferredElementType() throws Exception { - Bean bean = new Bean(); - IObservableSet observableSet = BeansObservables.observeSet(Realm - .getDefault(), bean, "set"); - assertEquals(Object.class, observableSet.getElementType()); - } - /** - * Test for fix for Bug 217558 [DataBinding] Databinding - BeansObservables.observeList() - * - error when external code modifies observed list. - */ - public void testHandleExternalChangeToProperty() { - Bean targetBean = new Bean(); - IObservableList modelObservable = BeansObservables.observeList(Realm.getDefault(), - model, "array", elementType ); - IObservableList targetObservable = BeansObservables.observeList(Realm.getDefault(), - targetBean, "array", elementType ); - - DataBindingContext context = new DataBindingContext( Realm.getDefault() ); - try { - // bind two beans and check the binding works - context.bindList( - targetObservable, - modelObservable, - null, - null ); - assertTrue( Arrays.equals( elements, targetBean.getArray() ) ); - - // set source direct - target databinding still works... - Bean[] newElements = new Bean[] { new Bean("4"), new Bean("5"), new Bean("6") }; - model.setArray( newElements ); - assertTrue( Arrays.equals( newElements, targetBean.getArray() ) ); - - // ... but setting the model's list breaks databinding the other way... - - // ... so setting target direct breaks databinding without fix and - // the assert would fail - newElements = new Bean[] { new Bean("7"), new Bean("8"), new Bean("9") }; - targetBean.setArray( newElements ); - assertTrue( Arrays.equals( newElements, model.getArray() ) ); - } - finally { - // context only needed for this test so not put in setUp / tearDown - context.dispose(); - } - - } - -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/beans/PojoObservablesTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/beans/PojoObservablesTest.java deleted file mode 100644 index 720837c3..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/beans/PojoObservablesTest.java +++ /dev/null @@ -1,187 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.tests.databinding.beans; - -import org.eclipse.core.databinding.beans.PojoObservables; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.WritableSet; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.internal.databinding.beans.JavaBeanObservableList; -import org.eclipse.core.internal.databinding.beans.JavaBeanObservableMap; -import org.eclipse.core.internal.databinding.beans.JavaBeanObservableSet; -import org.eclipse.core.internal.databinding.beans.JavaBeanObservableValue; -import org.eclipse.core.tests.internal.databinding.beans.Bean; -import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker; -import org.eclipse.jface.databinding.conformance.util.CurrentRealm; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -/** - * @since 3.2 - */ -public class PojoObservablesTest extends AbstractDefaultRealmTestCase { - private Bean pojo; - private String propertyName; - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - - pojo = new Bean(); - propertyName = "value"; - } - - public void testObserveValue_ReturnsJavaBeanObservableValue() - throws Exception { - IObservableValue value = PojoObservables.observeValue(pojo, propertyName); - - assertNotNull(value); - assertTrue(value instanceof JavaBeanObservableValue); - } - - public void testObserveValue_DoesNotAttachListeners() throws Exception { - IObservableValue value = PojoObservables.observeValue(pojo, propertyName); - - ChangeEventTracker.observe(value); - assertFalse(pojo.hasListeners(propertyName)); - } - - public void testObservableValueWithRealm_ReturnsJavaBeanObservable() - throws Exception { - CurrentRealm realm = new CurrentRealm(true); - IObservableValue value = PojoObservables.observeValue(realm, pojo, - propertyName); - - assertNotNull(value); - assertTrue(value instanceof JavaBeanObservableValue); - } - - public void testObservableMap_ReturnsJavaBeanObservableMap() - throws Exception { - IObservableSet set = new WritableSet(); - set.add(new Bean()); - - IObservableMap map = PojoObservables.observeMap(set, Bean.class, - propertyName); - assertNotNull(map); - assertTrue(map instanceof JavaBeanObservableMap); - } - - public void testObservableMap_DoesNotAttachListeners() throws Exception { - IObservableSet set = new WritableSet(); - set.add(pojo); - - IObservableMap map = PojoObservables.observeMap(set, Bean.class, propertyName); - assertFalse(pojo.hasListeners(propertyName)); - ChangeEventTracker.observe(map); - assertFalse(pojo.hasListeners(propertyName)); - } - - public void testObserveMaps_ReturnsMaps() throws Exception { - IObservableSet set = new WritableSet(); - set.add(pojo); - - IObservableMap[] maps = PojoObservables.observeMaps(set, Bean.class, new String[] {"value", "class"}); - assertEquals(2, maps.length); - } - - public void testObserveListWithElementType_ReturnsJavaBeanObservableList() throws Exception { - IObservableList list = PojoObservables.observeList(Realm.getDefault(), pojo, "list", String.class); - assertTrue(list instanceof JavaBeanObservableList); - } - - public void testObserveListWithElementType_DoesNotAttachListeners() throws Exception { - IObservableList observable = PojoObservables.observeList(Realm.getDefault(), pojo, "list", String.class); - assertFalse(pojo.hasListeners("list")); - ChangeEventTracker.observe(observable); - assertFalse(pojo.hasListeners("list")); - } - - public void testObserveList_ReturnsJavaBeanObservableList() throws Exception { - IObservableList observable = PojoObservables.observeList(Realm.getDefault(), pojo, "list"); - assertTrue(observable instanceof JavaBeanObservableList); - } - - public void testObserveList_DoesNotAttachListeners() throws Exception { - IObservableList observable = PojoObservables.observeList(Realm.getDefault(), pojo, "list"); - assertFalse(pojo.hasListeners("list")); - ChangeEventTracker.observe(observable); - assertFalse(pojo.hasListeners("list")); - } - - public void testObserveSetWithElementType_ReturnsJavaBeanObservableList() throws Exception { - IObservableSet list = PojoObservables.observeSet(Realm.getDefault(), pojo, "set", String.class); - assertTrue(list instanceof JavaBeanObservableSet); - } - - public void testObserveSetWithElementType_DoesNotAttachListeners() throws Exception { - IObservableSet observable = PojoObservables.observeSet(Realm.getDefault(), pojo, "set", String.class); - assertFalse(pojo.hasListeners("set")); - ChangeEventTracker.observe(observable); - assertFalse(pojo.hasListeners("set")); - } - - public void testObserveSet_ReturnsJavaBeanObservableList() throws Exception { - IObservableSet list = PojoObservables.observeSet(Realm.getDefault(), pojo, "set"); - assertTrue(list instanceof JavaBeanObservableSet); - } - - public void testObserveSet_DoesNotAttachListeners() throws Exception { - IObservableSet observable = PojoObservables.observeSet(Realm.getDefault(), pojo, "set"); - assertFalse(pojo.hasListeners("set")); - ChangeEventTracker.observe(observable); - assertFalse(pojo.hasListeners("set")); - } - - public void testValueFactory_DoesNotAttachListeners() throws Exception { - IObservableFactory factory = PojoObservables.valueFactory(Realm.getDefault(), "value"); - IObservableValue observable = (IObservableValue) factory.createObservable(pojo); - - assertFalse(pojo.hasListeners("value")); - ChangeEventTracker.observe(observable); - assertFalse(pojo.hasListeners("value")); - } - - public void testListFactory_DoesNotAttachListeners() throws Exception { - IObservableFactory factory = PojoObservables.listFactory(Realm.getDefault(), "list", String.class); - IObservableList observable = (IObservableList) factory.createObservable(pojo); - - assertFalse(pojo.hasListeners("value")); - ChangeEventTracker.observe(observable); - assertFalse(pojo.hasListeners("value")); - } - - public void testSetFactory_DoesNotAttachListeners() throws Exception { - IObservableFactory factory = PojoObservables.setFactory(Realm.getDefault(), propertyName); - IObservableSet observable = (IObservableSet) factory.createObservable(pojo); - - assertFalse(pojo.hasListeners("set")); - ChangeEventTracker.observe(observable); - assertFalse(pojo.hasListeners("set")); - } - - public void testSetFactoryWithElementType_DoesNotAttachListeners() throws Exception { - IObservableFactory factory = PojoObservables.setFactory(Realm.getDefault(), propertyName, String.class); - IObservableSet observable = (IObservableSet) factory.createObservable(pojo); - - assertFalse(pojo.hasListeners("set")); - ChangeEventTracker.observe(observable); - assertFalse(pojo.hasListeners("set")); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/conversion/NumberToStringConverterTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/conversion/NumberToStringConverterTest.java deleted file mode 100644 index 4b2f4c3c..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/conversion/NumberToStringConverterTest.java +++ /dev/null @@ -1,121 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.databinding.conversion; - -import java.math.BigInteger; - -import junit.framework.TestCase; - -import org.eclipse.core.databinding.conversion.NumberToStringConverter; - -import com.ibm.icu.text.NumberFormat; - -/** - * @since 1.1 - */ -public class NumberToStringConverterTest extends TestCase { - private NumberFormat numberFormat; - private NumberFormat integerFormat; - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - - numberFormat = NumberFormat.getInstance(); - integerFormat = NumberFormat.getIntegerInstance(); - } - - public void testFromTypes() throws Exception { - assertEquals("Integer.class", Integer.class, NumberToStringConverter - .fromInteger(false).getFromType()); - assertEquals("Integer.TYPE", Integer.TYPE, NumberToStringConverter - .fromInteger(true).getFromType()); - assertEquals("Double.class", Double.class, NumberToStringConverter - .fromDouble(false).getFromType()); - assertEquals("Double.TYPE", Double.TYPE, NumberToStringConverter - .fromDouble(true).getFromType()); - assertEquals("Long.class", Long.class, NumberToStringConverter - .fromLong(false).getFromType()); - assertEquals("Long.TYPE", Long.TYPE, NumberToStringConverter.fromLong( - true).getFromType()); - assertEquals("Float.class", Float.class, NumberToStringConverter - .fromFloat(false).getFromType()); - assertEquals("Float.TYPE", Float.TYPE, NumberToStringConverter - .fromFloat(true).getFromType()); - assertEquals("BigInteger.class", BigInteger.class, - NumberToStringConverter.fromBigInteger().getFromType()); - } - - public void testToTypeIsStringClass() throws Exception { - assertEquals(String.class, NumberToStringConverter.fromInteger(false) - .getToType()); - } - - public void testConvertIntegerToString() throws Exception { - Integer input = new Integer(1000); - String expected = integerFormat.format(input.longValue()); - - NumberToStringConverter converter = NumberToStringConverter - .fromInteger(false); - String result = (String) converter.convert(input); - assertEquals(expected, result); - } - - public void testConvertDoubleToString() throws Exception { - Double input = new Double(1000.1d); - String expected = numberFormat.format(input.doubleValue()); - - NumberToStringConverter converter = NumberToStringConverter - .fromDouble(false); - String result = (String) converter.convert(input); - assertEquals(expected, result); - } - - public void testConvertFloatToString() throws Exception { - Float input = new Float(1000.1f); - String expected = numberFormat.format(input.floatValue()); - - NumberToStringConverter converter = NumberToStringConverter - .fromFloat(false); - String result = (String) converter.convert(input); - assertEquals(expected, result); - } - - public void testConvertLongToString() throws Exception { - Long input = new Long(1000l); - String expected = integerFormat.format(input.longValue()); - - NumberToStringConverter converter = NumberToStringConverter - .fromLong(false); - String result = (String) converter.convert(input); - assertEquals(expected, result); - } - - public void testConvertBigIntegerToString() throws Exception { - BigInteger input = BigInteger.valueOf(1000); - String expected = integerFormat.format(input); - - NumberToStringConverter converter = NumberToStringConverter.fromBigInteger(); - String result = (String) converter.convert(input); - assertEquals(expected, result); - } - - public void testNullSourceConvertsToEmptyString() throws Exception { - NumberToStringConverter converter = NumberToStringConverter - .fromInteger(false); - assertEquals("", converter.convert(null)); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/conversion/StringToNumberConverterTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/conversion/StringToNumberConverterTest.java deleted file mode 100644 index d171fa38..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/conversion/StringToNumberConverterTest.java +++ /dev/null @@ -1,189 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.databinding.conversion; - -import java.math.BigInteger; - -import junit.framework.TestCase; - -import org.eclipse.core.databinding.conversion.StringToNumberConverter; - -import com.ibm.icu.text.NumberFormat; - -/** - * @since 1.1 - */ -//TODO test for ICU4Js BigDecimal -public class StringToNumberConverterTest extends TestCase { - private NumberFormat numberFormat; - private NumberFormat numberIntegerFormat; - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - numberFormat = NumberFormat.getInstance(); - numberIntegerFormat = NumberFormat.getIntegerInstance(); - } - - public void testToTypes() throws Exception { - assertEquals("Integer.class", Integer.class, StringToNumberConverter.toInteger(false).getToType()); - assertEquals("Integer.TYPE", Integer.TYPE, StringToNumberConverter.toInteger(true).getToType()); - assertEquals("Double.class", Double.class, StringToNumberConverter.toDouble(false).getToType()); - assertEquals("Double.TYPE", Double.TYPE, StringToNumberConverter.toDouble(true).getToType()); - assertEquals("Long.class", Long.class, StringToNumberConverter.toLong(false).getToType()); - assertEquals("Long.TYPE", Long.TYPE, StringToNumberConverter.toLong(true).getToType()); - assertEquals("Float.class", Float.class, StringToNumberConverter.toFloat(false).getToType()); - assertEquals("Float.TYPE", Float.TYPE, StringToNumberConverter.toFloat(true).getToType()); - assertEquals("BigInteger.TYPE", BigInteger.class, StringToNumberConverter.toBigInteger().getToType()); - } - - public void testFromTypeIsString() throws Exception { - assertEquals(String.class, StringToNumberConverter.toInteger(false) - .getFromType()); - } - - public void testConvertsToBigInteger() throws Exception { - BigInteger input = BigInteger.valueOf(1000); - - StringToNumberConverter converter = StringToNumberConverter.toBigInteger(); - BigInteger result = (BigInteger) converter.convert(numberFormat.format(input)); - - assertEquals(input, result); - } - - public void testConvertsToInteger() throws Exception { - Integer input = new Integer(1000); - - StringToNumberConverter converter = StringToNumberConverter.toInteger(false); - Integer result = (Integer) converter.convert(numberIntegerFormat.format(input - .longValue())); - assertEquals(input, result); - } - - public void testConvertsToDouble() throws Exception { - Double input = new Double(1000); - - StringToNumberConverter converter = StringToNumberConverter.toDouble(false); - Double result = (Double) converter.convert(numberFormat.format(input - .doubleValue())); - - assertEquals(input, result); - } - - public void testConvertsToLong() throws Exception { - Long input = new Long(1000); - - StringToNumberConverter converter = StringToNumberConverter.toLong(false); - Long result = (Long) converter.convert(numberIntegerFormat.format(input - .longValue())); - - assertEquals(input, result); - } - - public void testConvertsToFloat() throws Exception { - Float input = new Float(1000); - - StringToNumberConverter converter = StringToNumberConverter.toFloat(false); - Float result = (Float) converter.convert(numberFormat.format(input - .floatValue())); - - assertEquals(input, result); - } - - public void testConvertedToIntegerPrimitive() throws Exception { - Integer input = new Integer(1000); - - StringToNumberConverter converter = StringToNumberConverter.toInteger(true); - Integer result = (Integer) converter.convert(numberIntegerFormat.format(input - .longValue())); - assertEquals(input, result); - } - - public void testConvertsToDoublePrimitive() throws Exception { - Double input = new Double(1000); - - StringToNumberConverter converter = StringToNumberConverter.toDouble(true); - Double result = (Double) converter.convert(numberFormat.format(input - .doubleValue())); - - assertEquals(input, result); - } - - public void testConvertsToLongPrimitive() throws Exception { - Long input = new Long(1000); - - StringToNumberConverter converter = StringToNumberConverter.toLong(true); - Long result = (Long) converter.convert(numberIntegerFormat.format(input - .longValue())); - - assertEquals(input, result); - } - - public void testConvertsToFloatPrimitive() throws Exception { - Float input = new Float(1000); - - StringToNumberConverter converter = StringToNumberConverter.toFloat(true); - Float result = (Float) converter.convert(numberFormat.format(input - .floatValue())); - - assertEquals(input, result); - } - - public void testReturnsNullBoxedTypeForEmptyString() throws Exception { - StringToNumberConverter converter = StringToNumberConverter.toInteger(false); - try { - assertNull(converter.convert("")); - } catch (Exception e) { - fail("exception should not have been thrown"); - } - } - - public void testThrowsIllegalArgumentExceptionIfAskedToConvertNonString() - throws Exception { - StringToNumberConverter converter = StringToNumberConverter.toInteger(false); - try { - converter.convert(new Integer(1)); - fail("exception should have been thrown"); - } catch (IllegalArgumentException e) { - } - } - - /** - * Asserts a use case where the integer starts with a valid value but ends - * in an unparsable format. - * - * @throws Exception - */ - public void testInvalidInteger() throws Exception { - StringToNumberConverter converter = StringToNumberConverter - .toInteger(false); - - try { - converter.convert("1 1 1"); - fail("exception should have been thrown"); - } catch (IllegalArgumentException e) { - } - } - - public void testThrowsIllegalArgumentExceptionIfNumberIsOutOfRange() throws Exception { - StringToNumberConverter converter = StringToNumberConverter.toInteger(false); - try { - converter.convert(numberFormat.format(Long.MAX_VALUE)); - fail("exception should have been thrown"); - } catch (IllegalArgumentException e) { - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/AbstractObservableTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/AbstractObservableTest.java deleted file mode 100755 index 322c03b8..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/AbstractObservableTest.java +++ /dev/null @@ -1,294 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Brad Reynolds. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Brad Reynolds - initial API and implementation - * Brad Reynolds - bug 116920 - * Matthew Hall - bugs 208332, 213145 - ******************************************************************************/ - -package org.eclipse.core.tests.databinding.observable; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.AbstractObservable; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.jface.databinding.conformance.ObservableContractTest; -import org.eclipse.jface.databinding.conformance.ObservableStaleContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableContractDelegate; -import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker; -import org.eclipse.jface.databinding.conformance.util.CurrentRealm; -import org.eclipse.jface.databinding.conformance.util.RealmTester; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -/** - * Tests for AbstractObservable. - * - * @since 1.1 - */ -public class AbstractObservableTest extends AbstractDefaultRealmTestCase { - private ObservableStub observable; - - protected void setUp() throws Exception { - super.setUp(); - observable = new ObservableStub(Realm.getDefault()); - } - - public void testStaleListener() throws Exception { - assertFalse(observable.hasListeners()); - - StaleListener listener1 = new StaleListener(); - - assertFalse(observable.firstListenerAdded); - observable.addStaleListener(listener1); - assertTrue(observable.firstListenerAdded); - observable.firstListenerAdded = false; // reset - - assertTrue(observable.hasListeners()); - assertEquals(0, listener1.count); - - observable.fireStale(); - - assertEquals(1, listener1.count); - assertSame(observable, listener1.source); - - // Add a second stale listener as 1 vs. 2 listener code is different. - StaleListener listener2 = new StaleListener(); - assertEquals(0, listener2.count); - observable.addStaleListener(listener2); - observable.fireStale(); - - assertEquals(2, listener1.count); - assertEquals(1, listener2.count); - - // Add a third stale listener as 2 vs. 3 or greater code is different. - StaleListener listener3 = new StaleListener(); - observable.addStaleListener(listener3); - assertEquals(0, listener3.count); - - observable.fireStale(); - - assertEquals(3, listener1.count); - assertEquals(2, listener2.count); - assertEquals(1, listener3.count); - - assertFalse(observable.lastListenerRemoved); - observable.removeStaleListener(listener1); - observable.removeStaleListener(listener2); - observable.removeStaleListener(listener3); - assertTrue(observable.lastListenerRemoved); - - assertFalse(observable.hasListeners()); - } - - public void testChangeListener() throws Exception { - assertFalse(observable.hasListeners()); - - ChangeEventTracker listener1 = new ChangeEventTracker(); - - assertFalse(observable.firstListenerAdded); - observable.addChangeListener(listener1); - assertTrue(observable.firstListenerAdded); - observable.firstListenerAdded = false; - - assertTrue(observable.hasListeners()); - assertEquals(0, listener1.count); - - observable.fireChange(); - - assertEquals(1, listener1.count); - assertSame(observable, listener1.event.getSource()); - - // Add a second listener as the 1 vs. 2 listener code is different. - ChangeEventTracker listener2 = new ChangeEventTracker(); - observable.addChangeListener(listener2); - assertEquals(0, listener2.count); - - observable.fireChange(); - assertEquals(2, listener1.count); - assertEquals(1, listener2.count); - - // Add a third listener as the 2 vs. 3 or greater code is different. - ChangeEventTracker listener3 = new ChangeEventTracker(); - observable.addChangeListener(listener3); - assertEquals(0, listener3.count); - - observable.fireChange(); - - assertEquals(3, listener1.count); - assertEquals(2, listener2.count); - assertEquals(1, listener3.count); - - assertFalse(observable.lastListenerRemoved); - observable.removeChangeListener(listener1); - observable.removeChangeListener(listener2); - observable.removeChangeListener(listener3); - assertTrue(observable.lastListenerRemoved); - - assertFalse(observable.hasListeners()); - } - - public void testHasListenersWithChangeAndStaleListeners() throws Exception { - ChangeEventTracker changeListener = new ChangeEventTracker(); - StaleListener staleListener = new StaleListener(); - - assertFalse(observable.hasListeners()); - assertFalse(observable.firstListenerAdded); - assertFalse(observable.lastListenerRemoved); - - observable.addChangeListener(changeListener); - assertTrue(observable.hasListeners()); - assertTrue(observable.firstListenerAdded); - assertFalse(observable.lastListenerRemoved); - - // reset - observable.firstListenerAdded = false; - observable.lastListenerRemoved = false; - - observable.addStaleListener(staleListener); - assertTrue(observable.hasListeners()); - assertFalse(observable.firstListenerAdded); - assertFalse(observable.lastListenerRemoved); - - observable.removeChangeListener(changeListener); - assertTrue(observable.hasListeners()); - assertFalse(observable.firstListenerAdded); - assertFalse(observable.lastListenerRemoved); - - observable.removeStaleListener(staleListener); - assertFalse(observable.hasListeners()); - assertFalse(observable.firstListenerAdded); - assertTrue(observable.lastListenerRemoved); - } - - public void testFireStaleRealmChecks() throws Exception { - RealmTester.setDefault(new CurrentRealm(true)); - - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - observable = new ObservableStub(); - observable.fireStale(); - } - }); - } - - public void testFireChangeRealmChecks() throws Exception { - RealmTester.setDefault(new CurrentRealm(true)); - - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - observable = new ObservableStub(); - observable.fireChange(); - } - }); - } - - private class StaleListener implements IStaleListener { - int count; - IObservable source; - - public void handleStale(StaleEvent event) { - count++; - this.source = event.getObservable(); - } - } - - public static Test suite() { - TestSuite suite = new TestSuite(AbstractObservableTest.class.getName()); - suite.addTestSuite(AbstractObservableTest.class); - Delegate delegate = new Delegate(); - suite.addTest(ObservableContractTest.suite(delegate)); - suite.addTest(ObservableStaleContractTest.suite(delegate)); - return suite; - } - - /* package */static class Delegate extends - AbstractObservableContractDelegate { - - public void change(IObservable observable) { - ((ObservableStub) observable).fireChange(); - } - - public void setStale(IObservable observable, boolean stale) { - ((ObservableStub) observable).setStale(stale); - } - - public IObservable createObservable(Realm realm) { - return new ObservableStub(realm); - } - } - - private static class ObservableStub extends AbstractObservable { - private boolean stale; - - public ObservableStub() { - this(Realm.getDefault()); - } - - /** - * @param realm - */ - public ObservableStub(Realm realm) { - super(realm); - } - - private boolean firstListenerAdded; - - private boolean lastListenerRemoved; - - protected Object doGetValue() { - return null; - } - - public Object getValueType() { - return null; - } - - protected void fireStale() { - super.fireStale(); - } - - protected void fireChange() { - super.fireChange(); - } - - public boolean isStale() { - getterCalled(); - return stale; - } - - private void getterCalled() { - ObservableTracker.getterCalled(this); - } - - public void setStale(boolean stale) { - boolean old = this.stale; - this.stale = stale; - - if (stale && !old) { - fireStale(); - } - } - - protected boolean hasListeners() { - return super.hasListeners(); - } - - protected void firstListenerAdded() { - firstListenerAdded = true; - } - - protected void lastListenerRemoved() { - lastListenerRemoved = true; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/DiffsTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/DiffsTest.java deleted file mode 100755 index 551acdd2..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/DiffsTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.tests.databinding.observable; - -import java.util.Set; - -import junit.framework.TestCase; - -import org.eclipse.core.databinding.observable.set.SetDiff; -import org.eclipse.core.databinding.observable.value.ValueDiff; - -/** - * @since 3.2 - * - */ -public class DiffsTest extends TestCase { - /** - * Asserts that the {@link SetDiff#toString()} implementation doesn't throw a NPE if any of its properties are <code>null</code>. - */ - public void test_SetDiff() { - SetDiff diff = new SetDiff() { - public Set getAdditions() { - return null; - } - - public Set getRemovals() { - return null; - } - }; - - try { - diff.toString(); - assertTrue(true); - } catch (NullPointerException e) { - fail("NPE was thrown."); - } - } - - /** - * Asserts that if the {@link ValueDiff#toString()} implementation doesn't throw a NPE if any of its properties are <code>null</code>. - * - */ - public void test_ValueDiff() { - ValueDiff diff = new ValueDiff() { - public Object getNewValue() { - return null; - } - - public Object getOldValue() { - return null; - } - }; - - try { - diff.toString(); - assertTrue(true); - } catch (NullPointerException e) { - fail("NPE was thrown."); - } - } - -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/Diffs_ListDiffTests.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/Diffs_ListDiffTests.java deleted file mode 100644 index 5cd9affb..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/Diffs_ListDiffTests.java +++ /dev/null @@ -1,282 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 226216 - *******************************************************************************/ - -package org.eclipse.core.tests.databinding.observable; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import junit.framework.TestCase; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.list.ListDiff; -import org.eclipse.core.databinding.observable.list.ListDiffEntry; -import org.eclipse.core.databinding.observable.list.ListDiffVisitor; - -/** - * @since 1.1 - */ -public class Diffs_ListDiffTests extends TestCase { - public void testListDiffEntryToStringDoesNotThrowNPEForNullListDiffEntry() { - ListDiffEntry entry = new ListDiffEntry() { - public Object getElement() { - return null; - } - - public int getPosition() { - return 0; - } - - public boolean isAddition() { - return false; - } - }; - - try { - entry.toString(); - assertTrue(true); - } catch (NullPointerException e) { - fail("NPE was thrown."); - } - } - - public void testListDiffToStringDoesNotThrowNPEForNullListDiff() { - ListDiff diff = new ListDiff() { - public ListDiffEntry[] getDifferences() { - return null; - } - }; - - try { - diff.toString(); - assertTrue(true); - } catch (NullPointerException e) { - fail("NPE was thrown."); - } - } - - public void testListDiffToStringDoesNotThrowNPEForNullListDiffEntry() { - ListDiff diff = new ListDiff() { - public ListDiffEntry[] getDifferences() { - return new ListDiffEntry[1]; - } - }; - - try { - diff.toString(); - assertTrue(true); - } catch (NullPointerException e) { - fail("NPE was thrown."); - } - } - - public void testDiffScenario1() throws Exception { - ListDiff diff = diff(null, null); - assertEquals(0, diff.getDifferences().length); - } - - private ListDiff diff(String[] oldArray, String[] newArray) { - List a = Arrays.asList((oldArray != null) ? oldArray : new String[] {}); - List b = Arrays.asList((newArray != null) ? newArray : new String[] {}); - - return Diffs.computeListDiff(a, b); - } - - public void testDiffScenario2() throws Exception { - ListDiff diff = diff(new String[] {"a"}, null); - assertEquals(1, diff.getDifferences().length); - assertEntry(diff.getDifferences()[0], false, 0, "a"); - } - - public void testDiffScenario3() throws Exception { - ListDiff diff = diff(null, new String[] {"a"}); - assertEquals(1, diff.getDifferences().length); - assertEntry(diff.getDifferences()[0], true, 0, "a"); - } - - public void testDiffScenario4() throws Exception { - ListDiff diff = diff(new String[] {"a"}, new String[] {"a"}); - - assertEquals(0, diff.getDifferences().length); - } - - public void testDiffScenario5() throws Exception { - ListDiff diff = diff(new String[] {"a"}, new String[] {"b"}); - assertEquals(2, diff.getDifferences().length); - - assertEntry(diff.getDifferences()[0], true, 0, "b"); - assertEntry(diff.getDifferences()[1], false, 1, "a"); - } - - public void testDiffScenario6() throws Exception { - ListDiff diff = diff(new String[] { "a" }, new String[] { "a", "b" }); - - assertEquals(1, diff.getDifferences().length); - assertEntry(diff.getDifferences()[0], true, 1, "b"); - } - - public void testDiffScenario7() throws Exception { - ListDiff diff = diff(new String[] { "a" }, new String[] { "b", "a" }); - - assertEquals(1, diff.getDifferences().length); - assertEntry(diff.getDifferences()[0], true, 0, "b"); - } - - public void testDiffScenario8() throws Exception { - ListDiff diff = diff(new String[] { "a" }, new String[] { "b", "b" }); - - assertEquals(3, diff.getDifferences().length); - assertEntry(diff.getDifferences()[0], true, 0, "b"); - assertEntry(diff.getDifferences()[1], true, 1, "b"); - assertEntry(diff.getDifferences()[2], false, 2, "a"); - } - - public void testDiffScenario9() throws Exception { - ListDiff diff = diff(new String[] { "a" }, new String[] { "a", "b", "c" }); - - assertEquals(2, diff.getDifferences().length); - assertEntry(diff.getDifferences()[0], true, 1, "b"); - assertEntry(diff.getDifferences()[1], true, 2, "c"); - } - - public void testDiffScenario10() throws Exception { - ListDiff diff = diff(new String[] { "b" }, new String[] { "a", "b", "c" }); - - assertEquals(2, diff.getDifferences().length); - assertEntry(diff.getDifferences()[0], true, 0, "a"); - assertEntry(diff.getDifferences()[1], true, 2, "c"); - } - - public void testDiffScenario11() throws Exception { - ListDiff diff = diff(new String[] { "c" }, new String[] { "a", "b", "c" }); - - assertEquals(2, diff.getDifferences().length); - assertEntry(diff.getDifferences()[0], true, 0, "a"); - assertEntry(diff.getDifferences()[1], true, 1, "b"); - } - - public void testDiffScenario12() throws Exception { - ListDiff diff = diff(new String[] { "a", "b", "c" }, new String[] { "a", "b", "c" }); - - assertEquals(0, diff.getDifferences().length); - } - - public void testDiffScenario13() throws Exception { - ListDiff diff = diff(new String[] { "a", "b", "c" }, new String[] { "b", "c" }); - - assertEquals(1, diff.getDifferences().length); - assertEntry(diff.getDifferences()[0], false, 0, "a"); - } - - public void testDiffScenarios14() throws Exception { - ListDiff diff = diff(new String[] { "a", "b", "c" }, new String[] { "a", "c" }); - - assertEquals(1, diff.getDifferences().length); - assertEntry(diff.getDifferences()[0], false, 1, "b"); - } - - public void testDiffScenarios15() throws Exception { - ListDiff diff = diff(new String[] { "a", "b", "c" }, new String[] { "a", "b" }); - - assertEquals(1, diff.getDifferences().length); - assertEntry(diff.getDifferences()[0], false, 2, "c"); - } - - public void testDiffScenarios16() throws Exception { - ListDiff diff = diff(new String[] { "a", "b", "c" }, new String[] { "c", "b", "a" }); - - assertEquals(4, diff.getDifferences().length); - assertEntry(diff.getDifferences()[0], false, 2, "c"); - assertEntry(diff.getDifferences()[1], true, 0, "c"); - assertEntry(diff.getDifferences()[2], false, 2, "b"); - assertEntry(diff.getDifferences()[3], true, 1, "b"); - } - - public void testDiffScenarios17() throws Exception { - ListDiff diff = diff(new String[] { "a", "b", "c" }, new String[] { "c", "b" }); - - assertEquals(3, diff.getDifferences().length); - assertEntry(diff.getDifferences()[0], false, 0, "a"); - assertEntry(diff.getDifferences()[1], false, 1, "c"); - assertEntry(diff.getDifferences()[2], true, 0, "c"); - } - - private static void assertEntry(ListDiffEntry entry, boolean addition, int position, String element) { - assertEquals("addition", addition, entry.isAddition()); - assertEquals("position", position, entry.getPosition()); - assertEquals("element", element, entry.getElement()); - } - - public void testComputeListDiff_SingleInsert() { - checkComputedListDiff(Arrays.asList(new Object[] { "a", "c" }), Arrays - .asList(new Object[] { "a", "b", "c" })); - } - - public void testComputeListDiff_SingleAppend() { - checkComputedListDiff(Arrays.asList(new Object[] { "a", "b" }), Arrays - .asList(new Object[] { "a", "b", "c" })); - } - - public void testComputeListDiff_SingleRemove() { - checkComputedListDiff(Arrays.asList(new Object[] { "a", "b", "c" }), - Arrays.asList(new Object[] { "a", "b" })); - checkComputedListDiff(Arrays.asList(new Object[] { "a", "b", "c" }), - Arrays.asList(new Object[] { "a", "c" })); - checkComputedListDiff(Arrays.asList(new Object[] { "a", "b", "c" }), - Arrays.asList(new Object[] { "b", "c" })); - } - - public void testComputeListDiff_MoveDown1() { - checkComputedListDiff(Arrays.asList(new Object[] { "a", "b" }), Arrays - .asList(new Object[] { "b", "a" })); - } - - public void testComputeListDiff_MoveDown2() { - checkComputedListDiff(Arrays.asList(new Object[] { "a", "b", "c" }), - Arrays.asList(new Object[] { "b", "c", "a" })); - } - - public void testComputeListDiff_MoveUp1() { - checkComputedListDiff(Arrays.asList(new Object[] { "a", "b" }), Arrays - .asList(new Object[] { "b", "a" })); - } - - public void testComputeListDiff_MoveUp2() { - checkComputedListDiff(Arrays.asList(new Object[] { "a", "b", "c" }), - Arrays.asList(new Object[] { "c", "a", "b" })); - } - - private static void checkComputedListDiff(List oldList, List newList) { - ListDiff diff = Diffs.computeListDiff(oldList, newList); - - final List list = new ArrayList(oldList); - diff.accept(new ListDiffVisitor() { - public void handleAdd(int index, Object element) { - list.add(index, element); - } - - public void handleRemove(int index, Object element) { - assertEquals(element, list.remove(index)); - } - - public void handleReplace(int index, Object oldElement, - Object newElement) { - assertEquals(oldElement, list.set(index, newElement)); - } - }); - - assertEquals( - "Applying diff to old list should make it equal to new list", - newList, list); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/LockRealm.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/LockRealm.java deleted file mode 100755 index 768fb335..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/LockRealm.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.tests.databinding.observable; - -import java.util.LinkedList; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.ILock; -import org.eclipse.core.runtime.jobs.Job; - -/** - * @since 3.2 - * - */ -public class LockRealm extends Realm { - - private LinkedList queue; - private ILock lock; - private Job job; - private boolean lockAcquired; - - public LockRealm() { - queue = new LinkedList(); - lock = Job.getJobManager().newLock(); - job = new Job("Lock Realm Job") { - protected IStatus run(IProgressMonitor monitor) { - for (Runnable runnable; (runnable = dequeue()) != null;) { - acquireLock(); - try { - safeRun(runnable); - } finally { - releaseLock(); - } - } - return Status.OK_STATUS; - } - }; - job.setSystem(true); - } - - protected void syncExec(Runnable runnable) { - acquireLock(); - try { - safeRun(runnable); - } finally { - releaseLock(); - } - } - - public void asyncExec(Runnable runnable) { - enqueue(runnable); - job.schedule(); - } - - /** - * @param runnable - */ - private void enqueue(Runnable runnable) { - synchronized (queue) { - queue.addLast(runnable); - } - } - - private Runnable dequeue() { - synchronized (queue) { - if (queue.isEmpty()) { - return null; - } - return (Runnable) queue.getFirst(); - } - } - - public boolean isCurrent() { - return lockAcquired; - } - - private void acquireLock() { - lock.acquire(); - lockAcquired = true; - } - - private void releaseLock() { - lockAcquired = false; - lock.release(); - } - -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/ObservableTrackerTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/ObservableTrackerTest.java deleted file mode 100644 index be13fa3d..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/ObservableTrackerTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 210115) - ******************************************************************************/ - -package org.eclipse.core.tests.databinding.observable; - -import org.eclipse.core.databinding.observable.*; -import org.eclipse.core.runtime.AssertionFailedException; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -public class ObservableTrackerTest extends AbstractDefaultRealmTestCase { - public void testGetterCalled_ObservableDisposed() throws Exception { - try { - IObservable observable = new ObservableStub(); - observable.dispose(); - - ObservableTracker.getterCalled(observable); - - fail("expected AssertionFailedException"); - } catch (AssertionFailedException expected) { - } - } - - public void testGetterCalled_ObservableRealmNotCurrent() throws Exception { - try { - IObservable observable = new ObservableStub(new NotCurrentRealm()); - - ObservableTracker.getterCalled(observable); - - fail("expected AssertionFailedException"); - } catch (AssertionFailedException expected) { - } - } - - public static class ObservableStub extends AbstractObservable { - public ObservableStub() { - this(Realm.getDefault()); - } - - public ObservableStub(Realm realm) { - super(realm); - } - - public boolean isStale() { - return false; - } - } - - public static class NotCurrentRealm extends Realm { - public boolean isCurrent() { - return false; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/ObservablesTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/ObservablesTest.java deleted file mode 100755 index 6c896db2..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/ObservablesTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Cerner Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Brad Reynolds - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.databinding.observable; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.databinding.observable.Observables; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.ObservableList; -import org.eclipse.core.internal.databinding.observable.UnmodifiableObservableList; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -public class ObservablesTest extends AbstractDefaultRealmTestCase { - public void testUnmodifableObservableListExceptions() throws Exception { - try { - Observables.unmodifiableObservableList(null); - fail("IllegalArgumentException should have been thrown."); - } catch (IllegalArgumentException e) { - } - } - - public void testUnmodifiableObservableList() throws Exception { - IObservableList unmodifiable = Observables.unmodifiableObservableList(new ObservableListStub(new ArrayList(0), String.class)); - assertTrue(unmodifiable instanceof UnmodifiableObservableList); - } - - private static class ObservableListStub extends ObservableList { - /** - * @param wrappedList - * @param elementType - */ - protected ObservableListStub(List wrappedList, Object elementType) { - super(wrappedList, elementType); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/RealmTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/RealmTest.java deleted file mode 100644 index ad8caf00..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/RealmTest.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.databinding.observable; - -import junit.framework.TestCase; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.jface.databinding.conformance.util.CurrentRealm; -import org.eclipse.jface.databinding.conformance.util.RealmTester; - -/** - * @since 3.2 - */ -public class RealmTest extends TestCase { - public void testSetDefaultWithRunnable() throws Exception { - Realm oldRealm = new CurrentRealm(true); - final Realm newRealm = new CurrentRealm(true); - - RealmTester.setDefault(oldRealm); - Realm.runWithDefault(newRealm, new Runnable() { - public void run() { - assertEquals("new realm should be default", newRealm, Realm.getDefault()); - } - }); - - assertEquals("old realm should have been restored", oldRealm, Realm.getDefault()); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/ThreadRealm.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/ThreadRealm.java deleted file mode 100755 index 7562a162..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/ThreadRealm.java +++ /dev/null @@ -1,129 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 118516 - *******************************************************************************/ -package org.eclipse.core.tests.databinding.observable; - -import java.util.LinkedList; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.runtime.Assert; - -/** - * {@link Realm} that enforces execution to be within a specific - * {@link Thread}. - * - * @since 3.2 - */ -public class ThreadRealm extends Realm { - private Thread thread; - - private final LinkedList queue = new LinkedList(); - - private volatile boolean block; - - /** - * Initializes the realm. - * - * @param thread - */ - public synchronized void init(Thread thread) { - if (thread == null) { - throw new IllegalArgumentException("Parameter thread was null."); //$NON-NLS-1$ - } - Assert.isTrue(this.thread == null, "Realm can only be initialized once."); - - this.thread = thread; - } - - /** - * @return <code>true</code> if the current thread is the thread for - * the realm - */ - public boolean isCurrent() { - return Thread.currentThread() == thread; - } - - /** - * @return thread, <code>null</code> if not - * {@link #init(Thread) initialized} - */ - public Thread getThread() { - return thread; - } - - /** - * Queues the provided <code>runnable</code>. - * - * @param runnable - */ - public void asyncExec(Runnable runnable) { - synchronized (queue) { - queue.add(runnable); - queue.notifyAll(); - } - } - - public boolean isBlocking() { - return block; - } - - /** - * Blocks the current thread invoking runnables. - */ - public void block() { - if (block) { - throw new IllegalStateException("Realm is already blocking."); - } - - if (Thread.currentThread() != thread) { - throw new IllegalStateException("The current thread is not the correct thread."); - } - - try { - block = true; - while (block) { - Runnable runnable = null; - synchronized (queue) { - while (queue.isEmpty()) { - queue.wait(); - } - - // Check the size in case the thread is being awoken by - // unblock(). - if (!queue.isEmpty()) { - runnable = (Runnable) queue.removeFirst(); - } - } - - if (runnable != null) { - safeRun(runnable); - runnable = null; - } - } - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } finally { - block = false; - } - } - - /** - * Unblocks the thread. - */ - public void unblock() { - block = false; - - // Awaken the thread if waiting. - synchronized (queue) { - queue.notifyAll(); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/list/AbstractObservableListTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/list/AbstractObservableListTest.java deleted file mode 100755 index 4aa00d59..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/list/AbstractObservableListTest.java +++ /dev/null @@ -1,210 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Brad Reynolds - bug 167204 - * Matthew Hall - bugs 208858, 213145 - ******************************************************************************/ - -package org.eclipse.core.tests.databinding.observable.list; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.AbstractObservableList; -import org.eclipse.core.databinding.observable.list.IListChangeListener; -import org.eclipse.core.databinding.observable.list.ListChangeEvent; -import org.eclipse.core.databinding.observable.list.ListDiff; -import org.eclipse.core.databinding.observable.list.ListDiffEntry; -import org.eclipse.jface.databinding.conformance.ObservableListContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; -import org.eclipse.jface.databinding.conformance.util.CurrentRealm; -import org.eclipse.jface.databinding.conformance.util.RealmTester; - -/** - * @since 3.2 - */ -public class AbstractObservableListTest extends TestCase { - private AbstractObservableListStub list; - - protected void setUp() throws Exception { - RealmTester.setDefault(new CurrentRealm(true)); - list = new AbstractObservableListStub(); - } - - protected void tearDown() throws Exception { - RealmTester.setDefault(null); - } - - public void testFireChangeRealmChecks() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - list.fireChange(); - } - }); - } - - public void testFireStaleRealmChecks() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - list.fireStale(); - } - }); - } - - public void testFireListChangeRealmChecks() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - list.fireListChange(null); - } - }); - } - - public void testMove_FiresListChanges() throws Exception { - list = new MutableObservableListStub(); - final Object element = new Object(); - list.add(element); - list.add(new Object()); - - final List diffEntries = new ArrayList(); - list.addListChangeListener(new IListChangeListener() { - public void handleListChange(ListChangeEvent event) { - diffEntries.addAll(Arrays.asList(event.diff.getDifferences())); - } - }); - - list.move(0, 1); - - assertEquals(2, diffEntries.size()); - - ListDiffEntry entry = (ListDiffEntry) diffEntries.get(0); - assertEquals(element, entry.getElement()); - assertEquals(false, entry.isAddition()); - assertEquals(0, entry.getPosition()); - - entry = (ListDiffEntry) diffEntries.get(1); - assertEquals(element, entry.getElement()); - assertEquals(true, entry.isAddition()); - assertEquals(1, entry.getPosition()); - } - - public void testMove_MovesElement() throws Exception { - list = new MutableObservableListStub(); - final Object element0 = new Object(); - final Object element1 = new Object(); - list.add(element0); - list.add(element1); - - list.move(0, 1); - - assertEquals(element1, list.get(0)); - assertEquals(element0, list.get(1)); - } - - public static Test suite() { - TestSuite suite = new TestSuite(AbstractObservableListTest.class.getName()); - suite.addTestSuite(AbstractObservableListTest.class); - suite.addTest(ObservableListContractTest.suite(new Delegate())); - return suite; - } - - /* package */static class Delegate extends - AbstractObservableCollectionContractDelegate { - - public IObservableCollection createObservableCollection(Realm realm, - final int itemCount) { - - String[] items = new String[itemCount]; - for (int i = 0; i < itemCount; i++) { - items[i] = String.valueOf(i); - } - - AbstractObservableListStub observable = new AbstractObservableListStub(realm, Arrays.asList(items)); - observable.elementType = String.class; - return observable; - } - - public Object getElementType(IObservableCollection collection) { - return String.class; - } - - public void change(IObservable observable) { - ((AbstractObservableListStub) observable).fireChange(); - } - } - - static class AbstractObservableListStub extends AbstractObservableList { - Object elementType; - - List wrappedList; - - public AbstractObservableListStub() { - super(); - wrappedList = new ArrayList(); - } - - public AbstractObservableListStub(Realm realm, List list) { - super(realm); - this.wrappedList = list; - } - - protected int doGetSize() { - return wrappedList.size(); - } - - public Object get(int index) { - ObservableTracker.getterCalled(this); - return wrappedList.get(index); - } - - public Object getElementType() { - return elementType; - } - - protected void fireChange() { - super.fireChange(); - } - - protected void fireStale() { - super.fireStale(); - } - - protected void fireListChange(ListDiff diff) { - super.fireListChange(diff); - } - } - - static class MutableObservableListStub extends AbstractObservableListStub { - // These methods are present so we can test AbstractObservableList.move() - - public void add(int index, Object element) { - checkRealm(); - wrappedList.add(index, element); - fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry( - index, true, element))); - } - - public Object remove(int index) { - checkRealm(); - Object element = wrappedList.remove(index); - fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry( - index, false, element))); - return element; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/list/ComputedListTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/list/ComputedListTest.java deleted file mode 100644 index 6b1aebed..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/list/ComputedListTest.java +++ /dev/null @@ -1,165 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 211786) - * Matthew Hall - bug 213145 - ******************************************************************************/ - -package org.eclipse.core.tests.databinding.observable.list; - -import java.util.ArrayList; -import java.util.List; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.AbstractObservable; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.databinding.observable.list.ComputedList; -import org.eclipse.jface.databinding.conformance.ObservableListContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; -import org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -public class ComputedListTest extends AbstractDefaultRealmTestCase { - ComputedListStub list; - - protected void setUp() throws Exception { - super.setUp(); - list = new ComputedListStub(); - list.size(); // Force list to compute - } - - public void testDependency_Staleness() { - assertFalse(list.isStale()); - list.dependency.fireStale(); - assertTrue(list.isStale()); - } - - public void testDependency_FiresListChange() { - assertEquals(list.nextComputation, list); - - Object element = new Object(); - list.nextComputation.add(element); - - list.dependency.fireChange(); - - List expectedList = new ArrayList(); - expectedList.add(element); - assertEquals(expectedList, list); - } - - public void testDependency_NoStaleEventIfAlreadyDirty() { - list.dependency.fireChange(); - list.addStaleListener(new IStaleListener() { - public void handleStale(StaleEvent staleEvent) { - fail("Should not fire stale when list is already dirty"); - } - }); - list.dependency.fireStale(); - } - - public void testDependency_ListChangeEventFiresOnlyWhenNotDirty() { - ListChangeEventTracker tracker = ListChangeEventTracker.observe(list); - - list.dependency.fireChange(); - assertEquals( - "ComputedList should fire list change event when its dependency changes", - 1, tracker.count); - - list.dependency.fireChange(); - assertEquals( - "ComputedList should not fire list change events when dirty", - 1, tracker.count); - - list.size(); // Force list to recompute. - list.dependency.fireChange(); - assertEquals( - "ComputedList should fire list change event when its dependency changes", - 2, tracker.count); - } - - static class ComputedListStub extends ComputedList { - List nextComputation = new ArrayList(); - ObservableStub dependency; - - ComputedListStub() { - this(Realm.getDefault()); - } - - ComputedListStub(Realm realm) { - super(realm); - dependency = new ObservableStub(realm); - } - - protected List calculate() { - ObservableTracker.getterCalled(dependency); - return new ArrayList(nextComputation); - } - } - - static class ObservableStub extends AbstractObservable { - public ObservableStub(Realm realm) { - super(realm); - } - - boolean stale; - - public boolean isStale() { - return stale; - } - - protected void fireStale() { - stale = true; - super.fireStale(); - } - - protected void fireChange() { - super.fireChange(); - } - } - - public static Test suite() { - TestSuite suite = new TestSuite(ComputedListTest.class.getName()); - suite.addTestSuite(ComputedListTest.class); - suite.addTest(ObservableListContractTest.suite(new Delegate())); - return suite; - } - - static class Delegate extends AbstractObservableCollectionContractDelegate { - public IObservableCollection createObservableCollection(Realm realm, - int elementCount) { - final ComputedListStub list = new ComputedListStub(realm); - for (int i = 0; i < elementCount; i++) - list.nextComputation.add(createElement(list)); - list.size(); // force list to compute - return list; - } - - public void change(IObservable observable) { - ComputedListStub list = (ComputedListStub) observable; - list.nextComputation.add(new Object()); - list.dependency.fireChange(); - } - - public void setStale(IObservable observable, boolean stale) { - if (stale) - ((ComputedListStub) observable).dependency.fireStale(); - else { - ComputedListStub computedList = (ComputedListStub) observable; - computedList.dependency.stale = false; - computedList.dependency.fireChange(); - } - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/list/ListDiffTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/list/ListDiffTest.java deleted file mode 100644 index 959d8281..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/list/ListDiffTest.java +++ /dev/null @@ -1,126 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 208858) - ******************************************************************************/ - -package org.eclipse.core.tests.databinding.observable.list; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.list.ListDiff; -import org.eclipse.core.databinding.observable.list.ListDiffEntry; -import org.eclipse.core.databinding.observable.list.ListDiffVisitor; - -import junit.framework.TestCase; - -/** - * Tests for ListDiff class - * - * @since 1.1 - */ -public class ListDiffTest extends TestCase { - ListDiffVisitorStub visitor; - - protected void setUp() throws Exception { - super.setUp(); - visitor = new ListDiffVisitorStub(); - } - - public void testAccept_Add() { - createListDiff(add(0, "element")).accept(visitor); - assertEquals("add(0,element)", visitor.log); - } - - public void testAccept_Remove() { - createListDiff(remove(0, "element")).accept(visitor); - assertEquals("remove(0,element)", visitor.log); - } - - public void testAccept_Move() { - createListDiff(remove(0, "element"), add(1, "element")).accept(visitor); - assertEquals("move(0,1,element)", visitor.log); - } - - public void testAccept_Replace() { - createListDiff(remove(0, "element0"), add(0, "element1")).accept( - visitor); - assertEquals("replace(0,element0,element1)", visitor.log); - } - - public void testAccept_AllPatterns() { - createListDiff(new ListDiffEntry[] { - // Replace - remove(0, "element0"), add(0, "element1"), - // Remove - remove(1, "element2"), - // Add - add(2, "element3"), - // Move - remove(3, "element4"), add(4, "element4") }).accept(visitor); - assertEquals( - "replace(0,element0,element1), remove(1,element2), add(2,element3), move(3,4,element4)", - visitor.log); - } - - public void testAccept_MoveDetectionUsesEqualityNotSameness() { - Object element0 = new String("element"); - Object element1 = new String("element"); - assertNotSame(element0, element1); - assertEquals(element0, element1); - - createListDiff(remove(0, element0), add(1, element1)).accept(visitor); - assertEquals("move(0,1,element)", visitor.log); - } - - private ListDiffEntry add(int index, Object element) { - return Diffs.createListDiffEntry(index, true, element); - } - - private ListDiffEntry remove(int index, Object element) { - return Diffs.createListDiffEntry(index, false, element); - } - - private ListDiff createListDiff(ListDiffEntry difference) { - return createListDiff(new ListDiffEntry[] { difference }); - } - - private ListDiff createListDiff(ListDiffEntry first, ListDiffEntry second) { - return createListDiff(new ListDiffEntry[] { first, second }); - } - - private ListDiff createListDiff(ListDiffEntry[] differences) { - return Diffs.createListDiff(differences); - } - - class ListDiffVisitorStub extends ListDiffVisitor { - String log = ""; - - public void handleAdd(int index, Object element) { - log("add(" + index + "," + element + ")"); - } - - public void handleRemove(int index, Object element) { - log("remove(" + index + "," + element + ")"); - } - - public void handleMove(int oldIndex, int newIndex, Object element) { - log("move(" + oldIndex + "," + newIndex + "," + element + ")"); - } - - public void handleReplace(int index, Object oldElement, - Object newElement) { - log("replace(" + index + "," + oldElement + "," + newElement + ")"); - } - - private void log(String message) { - if (log.length() > 0) - log += ", "; - log += message; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/list/ListDiffVisitorTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/list/ListDiffVisitorTest.java deleted file mode 100644 index 4ec92885..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/list/ListDiffVisitorTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 208858) - ******************************************************************************/ - -package org.eclipse.core.tests.databinding.observable.list; - -import org.eclipse.core.databinding.observable.list.ListDiffVisitor; - -import junit.framework.TestCase; - -/** - * Tests for ListDiffVisitor class - * - * @since 1.1 - */ -public class ListDiffVisitorTest extends TestCase { - ListDiffVisitorStub visitor; - - protected void setUp() throws Exception { - super.setUp(); - visitor = new ListDiffVisitorStub(); - } - - public void testHandleMove_DelegatesByDefault() { - visitor.handleMove(0, 1, "element"); - assertEquals( - "Default ListDiffVisitor.handleMove must delegate to handleRemove and handleAdd", - "remove(0,element), add(1,element)", visitor.log); - } - - public void testHandleReplace_DelegatesByDefault() { - visitor.handleReplace(2, "oldElement", "newElement"); - assertEquals( - "Default ListDiffVisitor.handleReplace must delegate to handleRemove and handleAdd", - "remove(2,oldElement), add(2,newElement)", visitor.log); - } - - static class ListDiffVisitorStub extends ListDiffVisitor { - String log = ""; - - private void log(String message) { - if (log.length() > 0) - log += ", "; - log += message; - } - - public void handleAdd(int index, Object element) { - log("add(" + index + "," + element + ")"); - } - - public void handleRemove(int index, Object element) { - log("remove(" + index + "," + element + ")"); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/list/ObservableListTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/list/ObservableListTest.java deleted file mode 100755 index 7d9dcde9..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/list/ObservableListTest.java +++ /dev/null @@ -1,216 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 167204 - * Matthew Hall - bugs 208858, 213145, 245183 - *******************************************************************************/ - -package org.eclipse.core.tests.databinding.observable.list; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IListChangeListener; -import org.eclipse.core.databinding.observable.list.ListChangeEvent; -import org.eclipse.core.databinding.observable.list.ListDiff; -import org.eclipse.core.databinding.observable.list.ListDiffEntry; -import org.eclipse.core.databinding.observable.list.ObservableList; -import org.eclipse.jface.databinding.conformance.ObservableListContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; -import org.eclipse.jface.databinding.conformance.util.CurrentRealm; -import org.eclipse.jface.databinding.conformance.util.RealmTester; - -/** - * @since 3.2 - */ -public class ObservableListTest extends TestCase { - private ObservableListStub list; - - protected void setUp() throws Exception { - RealmTester.setDefault(new CurrentRealm(true)); - - list = new ObservableListStub(new ArrayList(0), Object.class); - } - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#tearDown() - */ - protected void tearDown() throws Exception { - RealmTester.setDefault(null); - } - - public void testIsStaleRealmChecks() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - list.isStale(); - } - }); - } - - public void testSetStaleRealmChecks() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - list.setStale(false); - } - }); - } - - public void testMove_FiresListChanges() throws Exception { - list = new MutableObservableListStub(); - final Object element = new Object(); - list.add(0, element); - list.add(1, new Object()); - - final List diffEntries = new ArrayList(); - list.addListChangeListener(new IListChangeListener() { - public void handleListChange(ListChangeEvent event) { - diffEntries.addAll(Arrays.asList(event.diff.getDifferences())); - } - }); - - list.move(0, 1); - - assertEquals(2, diffEntries.size()); - - ListDiffEntry entry = (ListDiffEntry) diffEntries.get(0); - assertEquals(element, entry.getElement()); - assertEquals(false, entry.isAddition()); - assertEquals(0, entry.getPosition()); - - entry = (ListDiffEntry) diffEntries.get(1); - assertEquals(element, entry.getElement()); - assertEquals(true, entry.isAddition()); - assertEquals(1, entry.getPosition()); - } - - public void testMove_MovesElement() throws Exception { - list = new MutableObservableListStub(); - final Object element0 = new Object(); - final Object element1 = new Object(); - list.add(0, element0); - list.add(1, element1); - - list.move(0, 1); - - assertEquals(element1, list.get(0)); - assertEquals(element0, list.get(1)); - } - - public void testEquals_IdentityCheckShortcut() { - List wrappedList = new ArrayList() { - private static final long serialVersionUID = 1L; - - public boolean equals(Object o) { - fail("ObservableList.equals() should return true instead of delegating to wrappedList when this == obj"); - return false; - } - }; - list = new ObservableListStub(wrappedList, null); - assertTrue(list.equals(list)); - } - - public void testEquals_SameClassDelegatesToWrappedLists() { - List wrappedList = new ArrayList() { - private static final long serialVersionUID = 1L; - - public boolean equals(Object o) { - // The observable lists will only be equal if they delegate to - // wrappedList.equals(other.wrappedList) - return o == this; - } - }; - list = new ObservableListStub(wrappedList, null); - ObservableListStub otherList = new ObservableListStub(wrappedList, null); - assertTrue(list.equals(otherList)); - } - - public static Test suite() { - TestSuite suite = new TestSuite(ObservableListTest.class.getName()); - suite.addTestSuite(ObservableListTest.class); - suite.addTest(ObservableListContractTest.suite(new Delegate())); - return suite; - } - - /* package */ static class Delegate extends AbstractObservableCollectionContractDelegate { - public IObservableCollection createObservableCollection(Realm realm, final int elementCount) { - List wrappedList = new ArrayList(); - for (int i = 0; i < elementCount; i++) { - wrappedList.add(String.valueOf(i)); - } - - return new MutableObservableListStub(realm, wrappedList, String.class); - } - - public void change(IObservable observable) { - ObservableListStub list = (ObservableListStub) observable; - Object element = "element"; - list.wrappedList.add(element); - list.fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry(list.size(), true, element))); - } - - public Object getElementType(IObservableCollection collection) { - return String.class; - } - } - - /* package */static class ObservableListStub extends ObservableList { - List wrappedList; - ObservableListStub(Realm realm, List wrappedList, Object elementType) { - super(realm, wrappedList, elementType); - this.wrappedList = wrappedList; - } - - ObservableListStub(List wrappedList, Object elementType) { - super(wrappedList, elementType); - this.wrappedList = wrappedList; - } - - protected void fireListChange(ListDiff diff) { - super.fireListChange(diff); - } - } - - /* package */static class MutableObservableListStub extends - ObservableListStub { - MutableObservableListStub() { - this(Realm.getDefault(), new ArrayList(), null); - } - - MutableObservableListStub(Realm realm, List wrappedList, - Object elementType) { - super(realm, wrappedList, elementType); - } - - public void add(int index, Object element) { - checkRealm(); - wrappedList.add(index, element); - fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry( - index, true, element))); - } - - public Object remove(int index) { - checkRealm(); - Object element = wrappedList.remove(index); - fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry( - index, false, element))); - return element; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/list/WritableListTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/list/WritableListTest.java deleted file mode 100755 index 5a7d1581..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/list/WritableListTest.java +++ /dev/null @@ -1,195 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 164653, 147515 - * Matthew Hall - bug 213145 - *******************************************************************************/ - -package org.eclipse.core.tests.databinding.observable.list; - -import java.util.ArrayList; -import java.util.Collections; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.jface.databinding.conformance.MutableObservableListContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; -import org.eclipse.jface.databinding.conformance.util.CurrentRealm; -import org.eclipse.jface.databinding.conformance.util.RealmTester; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.swt.widgets.Display; - -/** - * @since 3.2 - */ -public class WritableListTest extends TestCase { - protected void tearDown() throws Exception { - RealmTester.setDefault(null); - } - - public void testSetRealmChecks() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - WritableList list = new WritableList(); - list.add(""); - list.set(0, ""); - } - }); - } - - public void testAddRealmChecks() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - WritableList list = new WritableList(); - list.add(""); - } - }); - } - - public void testAddByIndexRealmChecks() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - WritableList list = new WritableList(); - list.add(0, ""); - } - }); - } - - public void testAddAllRealmChecks() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - WritableList list = new WritableList(); - list.addAll(Collections.EMPTY_LIST); - } - }); - } - - public void testAddAllByIndexRealmChecks() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - WritableList list = new WritableList(); - list.addAll(0, Collections.EMPTY_LIST); - } - }); - } - - public void testRemoveRealmChecks() throws Exception { - RealmTester.setDefault(new CurrentRealm(true)); - final WritableList list = new WritableList(); - list.add(""); - list.add(""); - - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - list.remove(""); - } - }); - RealmTester.setDefault(null); - } - - public void testRemoveByIndexRealmChecks() throws Exception { - RealmTester.setDefault(new CurrentRealm(true)); - final WritableList list = new WritableList(); - list.add(""); - list.add(""); - - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - list.remove(list.size() - 1); - } - }); - - RealmTester.setDefault(null); - } - - public void testRemoveAllRealmChecks() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - WritableList list = new WritableList(); - list.removeAll(Collections.EMPTY_LIST); - } - }); - } - - public void testRetainAllRealmChecks() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - WritableList list = new WritableList(); - list.retainAll(Collections.EMPTY_LIST); - } - }); - } - - public void testClearRealmChecks() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - WritableList list = new WritableList(); - list.clear(); - } - }); - } - - public void testNullElementType() throws Exception { - RealmTester.setDefault(SWTObservables.getRealm(Display.getDefault())); - WritableList writableList = new WritableList(); - assertNull(writableList.getElementType()); - - writableList = new WritableList(Realm.getDefault()); - assertNull(writableList.getElementType()); - } - - public void testWithElementType() throws Exception { - RealmTester.setDefault(SWTObservables.getRealm(Display.getDefault())); - - Object elementType = String.class; - WritableList list = WritableList.withElementType(elementType); - assertNotNull(list); - assertEquals(Realm.getDefault(), list.getRealm()); - assertEquals(elementType, list.getElementType()); - } - - public static Test suite() { - TestSuite suite = new TestSuite(WritableListTest.class.getName()); - suite.addTestSuite(WritableListTest.class); - suite.addTest(MutableObservableListContractTest.suite(new Delegate())); - return suite; - } - - /* package */static class Delegate extends - AbstractObservableCollectionContractDelegate { - public Object createElement(IObservableCollection collection) { - return String.valueOf(collection.size() + 1); - } - - public Object getElementType(IObservableCollection collection) { - return String.class; - } - - public IObservableCollection createObservableCollection(Realm realm, - final int itemCount) { - WritableList observable = new WritableList(realm, new ArrayList(), String.class); - - for (int i = 0; i < itemCount; i++) { - observable.add(String.valueOf(i)); - } - - return observable; - } - - public void change(IObservable observable) { - ((WritableList) observable).add(""); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/map/AbstractObservableMapTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/map/AbstractObservableMapTest.java deleted file mode 100644 index a1839528..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/map/AbstractObservableMapTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.databinding.observable.map; - -import java.util.Set; - -import junit.framework.TestCase; - -import org.eclipse.core.databinding.observable.map.AbstractObservableMap; -import org.eclipse.core.databinding.observable.map.MapDiff; -import org.eclipse.jface.databinding.conformance.util.CurrentRealm; -import org.eclipse.jface.databinding.conformance.util.RealmTester; - -/** - * @since 3.2 - */ -public class AbstractObservableMapTest extends TestCase { - private AbstractObservableMapStub map; - - protected void setUp() throws Exception { - RealmTester.setDefault(new CurrentRealm(true)); - map = new AbstractObservableMapStub(); - } - - protected void tearDown() throws Exception { - RealmTester.setDefault(null); - } - - public void testIsStaleRealmChecks() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - map.isStale(); - } - }); - } - - public void testSetStaleRealmChecks() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - map.setStale(true); - } - }); - } - - public void testFireStaleRealmChecks() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - map.fireStale(); - } - }); - } - - public void testFireChangeRealmChecks() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - map.fireChange(); - } - }); - } - - public void testFireMapChangeRealmChecks() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - map.fireMapChange(null); - } - }); - } - - static class AbstractObservableMapStub extends AbstractObservableMap { - public Set entrySet() { - return null; - } - - protected void fireChange() { - super.fireChange(); - } - - protected void fireMapChange(MapDiff diff) { - super.fireMapChange(diff); - } - - protected void fireStale() { - super.fireStale(); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/map/CompositeMapTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/map/CompositeMapTest.java deleted file mode 100644 index 488d86c5..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/map/CompositeMapTest.java +++ /dev/null @@ -1,204 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.tests.databinding.observable.map; - -import java.util.Collections; - -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.map.CompositeMap; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.WritableSet; -import org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker; -import org.eclipse.jface.examples.databinding.model.SimpleCart; -import org.eclipse.jface.examples.databinding.model.SimplePerson; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -/** - * @since 3.2 - * - */ -public class CompositeMapTest extends AbstractDefaultRealmTestCase { - - private WritableSet persons; - private CompositeMap composedMap; - - protected void setUp() throws Exception { - super.setUp(); - persons = new WritableSet(); - IObservableMap first = BeansObservables.observeMap(persons, - SimplePerson.class, "cart"); - composedMap = new CompositeMap(first, new IObservableFactory() { - public IObservable createObservable(Object target) { - return BeansObservables.observeMap((IObservableSet) target, - SimpleCart.class, "numItems"); - } - }); - } - - public void testAddToFirstMap() { - MapChangeEventTracker tracker = new MapChangeEventTracker(); - composedMap.addMapChangeListener(tracker); - assertEquals(0, tracker.count); - SimplePerson newPerson = new SimplePerson("p1", "a1", "c1", "s1"); - newPerson.getCart().setNumItems(42); - persons.add(newPerson); - assertEquals(1, tracker.count); - assertEquals(0, tracker.event.diff.getRemovedKeys().size()); - assertEquals(0, tracker.event.diff.getChangedKeys().size()); - assertEquals(Collections.singleton(newPerson), tracker.event.diff - .getAddedKeys()); - assertEquals(new Integer(42), tracker.event.diff.getNewValue(newPerson)); - assertEquals(new Integer(42), composedMap.get(newPerson)); - } - - public void testAddSharedToFirstMap() { - SimplePerson person1 = new SimplePerson("p1", "a1", "c1", "s1"); - person1.getCart().setNumItems(42); - persons.add(person1); - MapChangeEventTracker tracker = new MapChangeEventTracker(); - composedMap.addMapChangeListener(tracker); - assertEquals(0, tracker.count); - SimplePerson person2 = new SimplePerson("p1", "a1", "c1", "s1"); - person2.setCart(person1.getCart()); - persons.add(person2); - assertEquals(1, tracker.count); - assertEquals(0, tracker.event.diff.getRemovedKeys().size()); - assertEquals(0, tracker.event.diff.getChangedKeys().size()); - assertEquals(Collections.singleton(person2), tracker.event.diff - .getAddedKeys()); - assertEquals(new Integer(42), tracker.event.diff.getNewValue(person2)); - assertEquals(new Integer(42), composedMap.get(person2)); - assertEquals(new Integer(42), composedMap.get(person1)); - } - - public void testRemoveFromFirstMap() { - MapChangeEventTracker tracker = new MapChangeEventTracker(); - SimplePerson newPerson = new SimplePerson("p1", "a1", "c1", "s1"); - newPerson.getCart().setNumItems(42); - persons.add(newPerson); - assertTrue("newPerson should be added", composedMap.containsKey(newPerson)); - composedMap.addMapChangeListener(tracker); - assertEquals(0, tracker.count); - persons.remove(newPerson); - assertEquals(1, tracker.count); - assertEquals(0, tracker.event.diff.getAddedKeys().size()); - assertEquals(0, tracker.event.diff.getChangedKeys().size()); - assertEquals(Collections.singleton(newPerson), tracker.event.diff - .getRemovedKeys()); - assertEquals(new Integer(42), tracker.event.diff.getOldValue(newPerson)); - assertFalse("newPerson should be removed", composedMap.containsKey(newPerson)); - } - - public void testRemoveSharedFromFirstMap() { - SimplePerson person1 = new SimplePerson("p1", "a1", "c1", "s1"); - person1.getCart().setNumItems(42); - persons.add(person1); - SimplePerson person2 = new SimplePerson("p1", "a1", "c1", "s1"); - person2.setCart(person1.getCart()); - persons.add(person2); - assertTrue("person2 should be added", composedMap.containsKey(person2)); - MapChangeEventTracker tracker = new MapChangeEventTracker(); - composedMap.addMapChangeListener(tracker); - assertEquals(0, tracker.count); - persons.remove(person2); - assertEquals(1, tracker.count); - assertEquals(0, tracker.event.diff.getAddedKeys().size()); - assertEquals(0, tracker.event.diff.getChangedKeys().size()); - assertEquals(Collections.singleton(person2), tracker.event.diff - .getRemovedKeys()); - assertEquals(new Integer(42), tracker.event.diff.getOldValue(person2)); - assertFalse("person2 should be removed", composedMap.containsKey(person2)); - assertEquals(new Integer(42), composedMap.get(person1)); - } - - public void testChangeInFirstMap() { - SimplePerson person1 = new SimplePerson("p1", "a1", "c1", "s1"); - person1.getCart().setNumItems(42); - persons.add(person1); - MapChangeEventTracker tracker = new MapChangeEventTracker(); - composedMap.addMapChangeListener(tracker); - assertEquals(0, tracker.count); - person1.setCart(new SimpleCart()); - assertEquals(1, tracker.count); - assertEquals(0, tracker.event.diff.getAddedKeys().size()); - assertEquals(0, tracker.event.diff.getRemovedKeys().size()); - assertEquals(Collections.singleton(person1), tracker.event.diff - .getChangedKeys()); - assertEquals(new Integer(42), tracker.event.diff.getOldValue(person1)); - assertEquals(new Integer(0), tracker.event.diff.getNewValue(person1)); - assertEquals(new Integer(0), composedMap.get(person1)); - } - - public void testChangeInFirstMapToShared() { - SimplePerson person0 = new SimplePerson("p0", "a0", "c0", "s0"); - person0.getCart().setNumItems(13); - persons.add(person0); - SimplePerson person1 = new SimplePerson("p1", "a1", "c1", "s1"); - person1.getCart().setNumItems(42); - persons.add(person1); - MapChangeEventTracker tracker = new MapChangeEventTracker(); - composedMap.addMapChangeListener(tracker); - assertEquals(0, tracker.count); - person1.setCart(person0.getCart()); - assertEquals(1, tracker.count); - assertEquals(0, tracker.event.diff.getAddedKeys().size()); - assertEquals(0, tracker.event.diff.getRemovedKeys().size()); - assertEquals(Collections.singleton(person1), tracker.event.diff - .getChangedKeys()); - assertEquals(new Integer(42), tracker.event.diff.getOldValue(person1)); - assertEquals(new Integer(13), tracker.event.diff.getNewValue(person1)); - assertEquals(new Integer(13), composedMap.get(person1)); - } - - public void testChangeInFirstMapFromShared() { - SimplePerson person0 = new SimplePerson("p0", "a0", "c0", "s0"); - person0.getCart().setNumItems(13); - persons.add(person0); - SimplePerson person1 = new SimplePerson("p1", "a1", "c1", "s1"); - person1.setCart(person0.getCart()); - persons.add(person1); - MapChangeEventTracker tracker = new MapChangeEventTracker(); - composedMap.addMapChangeListener(tracker); - assertEquals(0, tracker.count); - person1.setCart(new SimpleCart()); - assertEquals(1, tracker.count); - assertEquals(0, tracker.event.diff.getAddedKeys().size()); - assertEquals(0, tracker.event.diff.getRemovedKeys().size()); - assertEquals(Collections.singleton(person1), tracker.event.diff - .getChangedKeys()); - assertEquals(new Integer(13), tracker.event.diff.getOldValue(person1)); - assertEquals(new Integer(0), tracker.event.diff.getNewValue(person1)); - assertEquals(new Integer(0), composedMap.get(person1)); - } - - public void testChangeInSecondMap() { - SimplePerson person0 = new SimplePerson("p0", "a0", "c0", "s0"); - person0.getCart().setNumItems(13); - persons.add(person0); - MapChangeEventTracker tracker = new MapChangeEventTracker(); - composedMap.addMapChangeListener(tracker); - assertEquals(0, tracker.count); - person0.getCart().setNumItems(42); - assertEquals(1, tracker.count); - assertEquals(0, tracker.event.diff.getAddedKeys().size()); - assertEquals(0, tracker.event.diff.getRemovedKeys().size()); - assertEquals(Collections.singleton(person0), tracker.event.diff - .getChangedKeys()); - assertEquals(new Integer(13), tracker.event.diff.getOldValue(person0)); - assertEquals(new Integer(42), tracker.event.diff.getNewValue(person0)); - assertEquals(new Integer(42), composedMap.get(person0)); - } - -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/map/ObservableMapTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/map/ObservableMapTest.java deleted file mode 100644 index bff39abf..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/map/ObservableMapTest.java +++ /dev/null @@ -1,144 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 245183 - *******************************************************************************/ - -package org.eclipse.core.tests.databinding.observable.map; - -import java.util.HashMap; -import java.util.Map; - -import junit.framework.TestCase; - -import org.eclipse.core.databinding.observable.map.IMapChangeListener; -import org.eclipse.core.databinding.observable.map.MapChangeEvent; -import org.eclipse.core.databinding.observable.map.MapDiff; -import org.eclipse.core.databinding.observable.map.ObservableMap; -import org.eclipse.jface.databinding.conformance.util.CurrentRealm; -import org.eclipse.jface.databinding.conformance.util.RealmTester; - -/** - * @since 3.2 - * - */ -public class ObservableMapTest extends TestCase { - ObservableMapStub map; - - protected void setUp() throws Exception { - RealmTester.setDefault(new CurrentRealm(true)); - map = new ObservableMapStub(new HashMap()); - } - - protected void tearDown() throws Exception { - RealmTester.setDefault(null); - } - - public void testDisposeMapChangeListeners() throws Exception { - class MapChangeListener implements IMapChangeListener { - int count; - - public void handleMapChange(MapChangeEvent event) { - count++; - } - } - - MapChangeListener listener = new MapChangeListener(); - map.addMapChangeListener(listener); - - assertEquals(0, listener.count); - map.fireMapChange(null); - assertEquals(1, listener.count); - - map.dispose(); - try { - map.fireMapChange(null); - } catch (Exception e) { - // do nothing - } - - assertEquals("listener should not have been notified", 1, - listener.count); - } - - public void testIsStaleRealmChecks() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - map.isStale(); - } - }); - } - - public void testSetStaleRealmChecks() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - map.setStale(true); - } - }); - } - - public void testFireMapChangeRealmChecks() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - map.fireMapChange(null); - } - }); - } - - public void testEquals_SingleEntry() { - Map reference = new HashMap(); - Object key = new Object(); - Object value = new Object(); - reference.put(key, value); - - map = new ObservableMapStub(reference); - assertEquals(reference, map); - } - - public void testEquals_IdentityCheckShortcut() { - Map wrappedMap = new HashMap() { - private static final long serialVersionUID = 1L; - - public boolean equals(Object o) { - fail("ObservableMap.equals() should return true instead of delegating to wrappedMap when this == obj"); - return false; - } - }; - map = new ObservableMapStub(wrappedMap); - assertTrue(map.equals(map)); - } - - public void testEquals_SameClassDelegatesToWrappedMaps() { - Map wrappedMap = new HashMap() { - private static final long serialVersionUID = 1L; - - public boolean equals(Object o) { - // The observable maps will only be equal if they delegate to - // wrappedMap.equals(other.wrappedMap) - return o == this; - } - }; - map = new ObservableMapStub(wrappedMap); - ObservableMapStub otherMap = new ObservableMapStub(wrappedMap); - assertTrue(map.equals(otherMap)); - } - - static class ObservableMapStub extends ObservableMap { - /** - * @param wrappedMap - */ - public ObservableMapStub(Map wrappedMap) { - super(wrappedMap); - } - - protected void fireMapChange(MapDiff diff) { - super.fireMapChange(diff); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/map/WritableMapTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/map/WritableMapTest.java deleted file mode 100644 index d3a98705..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/map/WritableMapTest.java +++ /dev/null @@ -1,123 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006-2008 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bug 184830 - ******************************************************************************/ - -package org.eclipse.core.tests.databinding.observable.map; - -import java.util.Collections; -import java.util.Set; - -import junit.framework.TestCase; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.map.MapChangeEvent; -import org.eclipse.core.databinding.observable.map.WritableMap; -import org.eclipse.jface.databinding.conformance.util.CurrentRealm; -import org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker; -import org.eclipse.jface.databinding.conformance.util.RealmTester; - -/** - * @since 3.2 - * - */ -public class WritableMapTest extends TestCase { - protected void setUp() throws Exception { - RealmTester.setDefault(new CurrentRealm(true)); - } - - protected void tearDown() throws Exception { - RealmTester.setDefault(null); - } - - public void testPutRealmChecks() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - WritableMap map = new WritableMap(); - map.put("", ""); - } - }); - } - - public void testRemoveRealmChecks() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - WritableMap map = new WritableMap(); - CurrentRealm realm = (CurrentRealm) Realm.getDefault(); - boolean current = realm.isCurrent(); - realm.setCurrent(true); - map.put("", ""); - realm.setCurrent(current); - - map.remove(""); - } - }); - } - - public void testClearRealmChecks() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - WritableMap map = new WritableMap(); - map.clear(); - } - }); - } - - public void testPutAllRealmChecks() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - WritableMap map = new WritableMap(); - map.putAll(Collections.EMPTY_MAP); - } - }); - } - - public void testPutWithExistingKeyMapChangeEvent() throws Exception { - WritableMap map = new WritableMap(); - String key = "key"; - String value = "value"; - map.put(key, value); - - MapChangeEventTracker listener = new MapChangeEventTracker(); - map.addMapChangeListener(listener); - - assertEquals(0, listener.count); - - String newValue = "new value"; - map.put(key, newValue); - - assertEquals(1, listener.count); - MapChangeEvent event = listener.event; - - - Set changedKeys = event.diff.getChangedKeys(); - assertEquals(1, changedKeys.size()); - assertTrue(changedKeys.contains(key)); - assertEquals(value, event.diff.getOldValue(key)); - assertEquals(newValue, event.diff.getNewValue(key)); - } - - public void testPutSameValue_NoMapChangeEvent() { - WritableMap map = new WritableMap(); - Object key = new Object(); - Object value = "value"; - map.put(key, value); - - MapChangeEventTracker tracker = MapChangeEventTracker.observe(map); - - assertEquals(0, tracker.count); - - Object equalValue = new String("value"); - map.put(key, equalValue); - - assertEquals(0, tracker.count); - - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/set/AbstractObservableSetTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/set/AbstractObservableSetTest.java deleted file mode 100644 index 4992c1be..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/set/AbstractObservableSetTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bug 213145 - ******************************************************************************/ - -package org.eclipse.core.tests.databinding.observable.set; - -import java.util.HashSet; -import java.util.Set; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.set.AbstractObservableSet; -import org.eclipse.core.databinding.observable.set.SetDiff; -import org.eclipse.jface.databinding.conformance.ObservableCollectionContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; - -/** - */ -public class AbstractObservableSetTest extends TestCase { - public static Test suite() { - TestSuite suite = new TestSuite(AbstractObservableSetTest.class.getName()); - suite.addTest(ObservableCollectionContractTest.suite(new Delegate())); - return suite; - } - - private static class Delegate extends - AbstractObservableCollectionContractDelegate { - public void change(IObservable observable) { - ((AbstractObservableSetStub) observable).fireSetChange(Diffs.createSetDiff(new HashSet(), new HashSet())); - } - - public Object createElement(IObservableCollection collection) { - return Integer.toString(collection.size()); - } - - public Object getElementType(IObservableCollection collection) { - return String.class; - } - - public IObservableCollection createObservableCollection(Realm realm, - int elementCount) { - AbstractObservableSetStub set = new AbstractObservableSetStub(realm, String.class); - - for (int i = 0; i < elementCount; i++) { - set.getWrappedSet().add(Integer.toString(i)); - } - - return set; - } - } - - private static class AbstractObservableSetStub extends AbstractObservableSet { - private Object type; - private HashSet set; - - private AbstractObservableSetStub(Realm realm, Object type) { - super (realm); - set = new HashSet(); - this.type = type; - } - - protected Set getWrappedSet() { - return set; - } - - public Object getElementType() { - return type; - } - - protected void fireSetChange(SetDiff diff) { - super.fireSetChange(diff); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/set/ObservableSetTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/set/ObservableSetTest.java deleted file mode 100755 index 89ef2c9e..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/set/ObservableSetTest.java +++ /dev/null @@ -1,113 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bugs 213145, 245183 - ******************************************************************************/ - -package org.eclipse.core.tests.databinding.observable.set; - -import java.util.HashSet; -import java.util.Set; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.ObservableSet; -import org.eclipse.core.databinding.observable.set.SetDiff; -import org.eclipse.jface.databinding.conformance.ObservableCollectionContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -/** - * @since 1.1 - */ -public class ObservableSetTest extends AbstractDefaultRealmTestCase { - public void testEquals_IdentityCheckShortcut() { - Set wrappedSet = new HashSet() { - private static final long serialVersionUID = 1L; - - public boolean equals(Object o) { - fail("ObservableSet.equals() should return true instead of delegating to wrappedSet when this == obj"); - return false; - } - }; - Set set = new ObservableSetStub(Realm.getDefault(), wrappedSet, null); - assertTrue(set.equals(set)); - } - - public void testEquals_SameClassDelegatesToWrappedSets() { - Set wrappedSet = new HashSet() { - private static final long serialVersionUID = 1L; - - public boolean equals(Object o) { - // The observable sets will only be equal if they delegate to - // wrappedSet.equals(other.wrappedSet) - return o == this; - } - }; - Set set = new ObservableSetStub(Realm.getDefault(), wrappedSet, null); - Set otherSet = new ObservableSetStub(Realm.getDefault(), wrappedSet, - null); - assertTrue(set.equals(otherSet)); - } - - public static Test suite() { - TestSuite suite = new TestSuite(ObservableSetTest.class.getName()); - suite.addTestSuite(ObservableSetTest.class); - suite.addTest(ObservableCollectionContractTest.suite(new Delegate())); - return suite; - } - - private static class Delegate extends AbstractObservableCollectionContractDelegate { - private Delegate() { - } - - public void change(IObservable observable) { - ((ObservableSetStub) observable).fireSetChange(Diffs.createSetDiff(new HashSet(), new HashSet())); - } - - public Object createElement(IObservableCollection collection) { - return Integer.toString(collection.size()); - } - - public Object getElementType(IObservableCollection collection) { - return String.class; - } - - public IObservableCollection createObservableCollection(Realm realm, - int elementCount) { - IObservableSet set = new ObservableSetStub(realm, new HashSet(), String.class); - - for (int i = 0; i < elementCount; i++) { - set.add(Integer.toString(i)); - } - - return set; - } - } - - private static class ObservableSetStub extends ObservableSet { - /** - * @param wrappedSet - * @param elementType - */ - protected ObservableSetStub(Realm realm, Set wrappedSet, Object elementType) { - super(realm, wrappedSet, elementType); - } - - public void fireSetChange(SetDiff diff) { - super.fireSetChange(diff); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/set/UnionSetTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/set/UnionSetTest.java deleted file mode 100755 index ad699603..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/set/UnionSetTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bug 213145 - ******************************************************************************/ - -package org.eclipse.core.tests.databinding.observable.set; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.UnionSet; -import org.eclipse.core.databinding.observable.set.WritableSet; -import org.eclipse.jface.databinding.conformance.ObservableCollectionContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; - -/** - */ -public class UnionSetTest extends TestCase { - public static Test suite() { - TestSuite suite = new TestSuite(UnionSetTest.class.getName()); - suite.addTest(ObservableCollectionContractTest.suite(new Delegate())); - return suite; - } - - private static class Delegate extends - AbstractObservableCollectionContractDelegate { - private IObservableSet[] sets; - - private Delegate() { - } - - public void setUp() { - - super.setUp(); - } - - public void tearDown() { - sets = null; - - super.tearDown(); - } - - public void change(IObservable observable) { - sets[0].add(Integer.toString(sets[0].size())); - } - - public Object createElement(IObservableCollection collection) { - return Integer.toString(collection.size()); - } - - public IObservableCollection createObservableCollection(Realm realm, - int elementCount) { - sets = new IObservableSet[]{new WritableSet(realm), new WritableSet(realm)}; - - IObservableSet set = new UnionSet(sets); - - for (int i = 0; i < elementCount; i++) { - sets[0].add(Integer.toString(i)); - } - - return set; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/set/WritableSetTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/set/WritableSetTest.java deleted file mode 100644 index f23f3151..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/set/WritableSetTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007-2008 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bugs 221351, 213145 - ******************************************************************************/ -package org.eclipse.core.tests.databinding.observable.set; - -import java.util.Collections; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.WritableSet; -import org.eclipse.jface.databinding.conformance.MutableObservableSetContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -/** - */ -public class WritableSetTest extends AbstractDefaultRealmTestCase { - public void testWithElementType() throws Exception { - Object elementType = String.class; - WritableSet set = WritableSet.withElementType(elementType); - assertNotNull(set); - assertEquals(Realm.getDefault(), set.getRealm()); - assertEquals(elementType, set.getElementType()); - } - - public static Test suite() { - TestSuite suite = new TestSuite(WritableSetTest.class.getName()); - suite.addTestSuite(WritableSetTest.class); - suite.addTest(MutableObservableSetContractTest.suite(new Delegate())); - return suite; - } - - private static class Delegate extends - AbstractObservableCollectionContractDelegate { - private Delegate() { - super(); - } - - public void change(IObservable observable) { - IObservableSet set = (IObservableSet) observable; - set.add(createElement(set)); - } - - public Object createElement(IObservableCollection collection) { - return new Object(); - } - - public Object getElementType(IObservableCollection collection) { - return String.class; - } - - public IObservableCollection createObservableCollection(Realm realm, - int elementCount) { - IObservableSet set = new WritableSet(realm, Collections.EMPTY_SET, - String.class); - for (int i = 0; i < elementCount; i++) { - set.add(createElement(set)); - } - - return set; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/value/AbstractObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/value/AbstractObservableValueTest.java deleted file mode 100755 index 66fb3591..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/value/AbstractObservableValueTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.databinding.observable.value; - -import junit.framework.TestCase; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.AbstractObservableValue; -import org.eclipse.core.databinding.observable.value.ValueDiff; -import org.eclipse.jface.databinding.conformance.util.CurrentRealm; -import org.eclipse.jface.databinding.conformance.util.RealmTester; - -/** - * @since 3.2 - */ -public class AbstractObservableValueTest extends TestCase { - public void testSetValueRealmChecks() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - ObservableValueStub observable = new ObservableValueStub(); - try { - observable.setValue(null); - } catch (UnsupportedOperationException e) { - // do nothing - } - } - }); - } - - public void testSetValueInvokesDoSetValue() throws Exception { - class ValueStub extends ObservableValueStub { - int doSetValue; - - ValueStub(Realm realm) { - super(realm); - } - - protected void doSetValue(Object value) { - doSetValue++; - } - } - - Realm realm = new CurrentRealm(true); - ValueStub stub = new ValueStub(realm); - assertEquals(0, stub.doSetValue); - stub.setValue(new Object()); - assertEquals("doSetValue should have been invoked", 1, stub.doSetValue); - } - - public void testFireValueChangeRealmChecks() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - ObservableValueStub observable = new ObservableValueStub(); - observable.fireValueChange(null); - } - }); - } - - private static class ObservableValueStub extends AbstractObservableValue { - ObservableValueStub() { - super(Realm.getDefault()); - } - - private ObservableValueStub(Realm realm) { - super(realm); - } - - protected Object doGetValue() { - return null; - } - - public Object getValueType() { - return null; - } - - protected void fireValueChange(ValueDiff diff) { - super.fireValueChange(diff); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/value/AbstractVetoableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/value/AbstractVetoableValueTest.java deleted file mode 100755 index 2507db4f..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/value/AbstractVetoableValueTest.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.databinding.observable.value; - -import junit.framework.TestCase; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.AbstractVetoableValue; -import org.eclipse.core.databinding.observable.value.ValueDiff; -import org.eclipse.jface.databinding.conformance.util.CurrentRealm; -import org.eclipse.jface.databinding.conformance.util.RealmTester; - -/** - * @since 3.2 - */ -public class AbstractVetoableValueTest extends TestCase { - public void testSetValueInvokesDoSetApprovedValue() throws Exception { - class VetoableValue extends VetoableValueStub { - int count; - Object value; - - VetoableValue(Realm realm) { - super(realm); - } - - protected void doSetApprovedValue(Object value) { - count++; - this.value = value; - } - } - - Realm realm = new CurrentRealm(true); - VetoableValue vetoableValue = new VetoableValue(realm); - assertEquals(0, vetoableValue.count); - assertEquals(null, vetoableValue.value); - - Object value = new Object(); - vetoableValue.setValue(value); - assertEquals(1, vetoableValue.count); - assertEquals(value, vetoableValue.value); - } - - public void testFireValueChangeRealmChecks() throws Exception { - RealmTester.exerciseCurrent(new Runnable() { - public void run() { - VetoableValueStub observable = new VetoableValueStub(); - observable.fireValueChanging(null); - } - }); - } - - private static class VetoableValueStub extends AbstractVetoableValue { - VetoableValueStub() { - this(Realm.getDefault()); - } - - VetoableValueStub(Realm realm) { - super(realm); - } - - protected void doSetApprovedValue(Object value) { - } - - protected Object doGetValue() { - return null; - } - - - public Object getValueType() { - return null; - } - - protected boolean fireValueChanging(ValueDiff diff) { - return super.fireValueChanging(diff); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/value/ComputedValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/value/ComputedValueTest.java deleted file mode 100755 index 8d900117..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/value/ComputedValueTest.java +++ /dev/null @@ -1,134 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 116920 - * Brad Reynolds - bug 164653 - *******************************************************************************/ - -package org.eclipse.core.tests.databinding.observable.value; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.databinding.observable.value.ComputedValue; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -/** - * @since 1.0 - * - */ -public class ComputedValueTest extends AbstractDefaultRealmTestCase { - public void testValueType() throws Exception { - ComputedValue cv = new ComputedValue(Integer.TYPE) { - protected Object calculate() { - return new Integer(42); - } - }; - assertEquals("value type should be the type that was set", Integer.TYPE, cv.getValueType()); - - cv = new ComputedValue() { - protected Object calculate() { - // TODO Auto-generated method stub - return null; - } - }; - - assertNull(cv.getValueType()); - } - - public void test_getValue() throws Exception { - ComputedValue cv = new ComputedValue() { - protected Object calculate() { - return new Integer(42); - } - }; - assertEquals("Calculated value should be 42", new Integer(42), cv.getValue()); - } - - public void testDependencyValueChange() throws Exception { - final WritableValue value = new WritableValue(new Integer(42), Integer.TYPE); - - ComputedValue cv = new ComputedValue() { - protected Object calculate() { - return value.getValue(); - } - }; - - assertEquals("calculated value should have been that of the writable value", value.getValue(), cv.getValue()); - - value.setValue(new Integer(44)); - - assertEquals("calculated value should have been that of the writable value", value.getValue(), cv.getValue()); - } - - private static class WritableValueExt extends WritableValue { - public WritableValueExt(Object valueType, Object initialValue) { - super(initialValue, valueType); - } - - public boolean hasListeners() { - return super.hasListeners(); - } - } - - public void testHookAndUnhookDependantObservables() throws Exception { - final List values = new ArrayList(); - - ComputedValue cv = new ComputedValue() { - protected Object calculate() { - int sum = 0; - for (Iterator it = values.iterator(); it.hasNext();) { - WritableValue value = (WritableValue) it.next(); - sum += ((Integer) value.getValue()).intValue(); - - } - - return new Integer(sum); - } - }; - - WritableValueExt value1 = new WritableValueExt(Integer.TYPE, new Integer(1)); - WritableValueExt value2 = new WritableValueExt(Integer.TYPE, new Integer(1)); - values.add(value1); - values.add(value2); - - assertFalse(value1.hasListeners()); - assertFalse(value2.hasListeners()); - cv.getValue(); - assertTrue(value1.hasListeners()); - assertTrue(value2.hasListeners()); - - //force the computed value to be stale - value2.setValue(new Integer(2)); - //remove value2 from the values that are used to compute the value - values.remove(value2); - - //force the value to be computed - cv.getValue(); - assertEquals(new Integer(1), cv.getValue()); - assertTrue(value1.hasListeners()); - assertFalse("because value2 is not a part of the calculation the listeners should have been removed", value2.hasListeners()); - } - - public void testSetValueUnsupportedOperationException() throws Exception { - ComputedValue cv = new ComputedValue() { - protected Object calculate() { - return null; - } - }; - - try { - cv.setValue(new Object()); - fail("exception should have been thrown"); - } catch (UnsupportedOperationException e) { - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/value/WritableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/value/WritableValueTest.java deleted file mode 100755 index 8437e741..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/value/WritableValueTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Brad Reynolds - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Brad Reynolds - bug 158687 - * Brad Reynolds - bug 164653 - * Matthew Hall - bug 213145 - ******************************************************************************/ - -package org.eclipse.core.tests.databinding.observable.value; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.jface.databinding.conformance.MutableObservableValueContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.eclipse.swt.widgets.Display; - -/** - * @since 3.2 - */ -public class WritableValueTest extends AbstractDefaultRealmTestCase { - /** - * All constructors delegate to the 3 arg constructor. - * - * @throws Exception - */ - public void testConstructor() throws Exception { - WritableValue value = new WritableValue(SWTObservables.getRealm(Display - .getDefault())); - assertNull(value.getValue()); - assertNull(value.getValueType()); - } - - public void testWithValueType() throws Exception { - Object elementType = String.class; - WritableValue value = WritableValue.withValueType(elementType); - assertNotNull(value); - assertEquals(Realm.getDefault(), value.getRealm()); - assertEquals(elementType, value.getValueType()); - } - - public static Test suite() { - TestSuite suite = new TestSuite(WritableValueTest.class.getName()); - suite.addTestSuite(WritableValueTest.class); - suite.addTest(MutableObservableValueContractTest.suite(new Delegate())); - return suite; - } - - /* package */static class Delegate extends - AbstractObservableValueContractDelegate { - public IObservableValue createObservableValue(Realm realm) { - return new WritableValue(realm, "", String.class); - } - - public void change(IObservable observable) { - IObservableValue observableValue = (IObservableValue) observable; - observableValue.setValue(createValue(observableValue)); - } - - public Object getValueType(IObservableValue observable) { - return String.class; - } - - public Object createValue(IObservableValue observable) { - return observable.getValue() + "a"; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/validation/MultiValidatorTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/validation/MultiValidatorTest.java deleted file mode 100644 index be1e4aad..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/validation/MultiValidatorTest.java +++ /dev/null @@ -1,196 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 218269) - * Matthew Hall - bug 237884 - ******************************************************************************/ - -package org.eclipse.core.tests.databinding.validation; - -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.observable.ChangeEvent; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.ObservableTracker; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.databinding.validation.MultiValidator; -import org.eclipse.core.databinding.validation.ValidationStatus; -import org.eclipse.core.internal.databinding.observable.ValidatedObservableValue; -import org.eclipse.core.runtime.AssertionFailedException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jface.databinding.conformance.util.CurrentRealm; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -public class MultiValidatorTest extends AbstractDefaultRealmTestCase { - private WritableValue dependency; - private MultiValidator validator; - private IObservableValue validationStatus; - - protected void setUp() throws Exception { - super.setUp(); - dependency = new WritableValue(null, IStatus.class); - validator = new MultiValidator() { - protected IStatus validate() { - return (IStatus) dependency.getValue(); - } - }; - validationStatus = validator.getValidationStatus(); - } - - public void testConstructor_NullArgument() { - try { - new MultiValidator(null) { - protected IStatus validate() { - return null; - } - }; - fail("Expected AssertionFailedException"); - } catch (AssertionFailedException expected) { - } - } - - public void testGetValidationStatus_NullResultYieldsOKStatus() { - IStatus status = (IStatus) validationStatus.getValue(); - assertTrue(status.isOK()); // null -> OK - } - - public void testGetValidationStatus_ExceptionThrownYieldsErrorStatus() { - final RuntimeException e = new RuntimeException("message"); - validator = new MultiValidator() { - protected IStatus validate() { - throw e; - } - }; - assertEquals(ValidationStatus.error("message", e), validator - .getValidationStatus().getValue()); - } - - public void testGetValidationStatus_TracksWithDependency() { - IStatus newStatus = ValidationStatus.error("error"); - dependency.setValue(newStatus); - assertEquals(newStatus, validationStatus.getValue()); - } - - public void testInit_AddsValidationProducer() { - DataBindingContext dbc = new DataBindingContext(); - dbc.addValidationStatusProvider(validator); - assertTrue(dbc.getValidationStatusProviders().contains(validator)); - } - - public void testObserveValidatedValue_NullArgument() { - try { - validator.observeValidatedValue(null); - fail("Expected AssertionFailedException"); - } catch (AssertionFailedException expected) { - } - } - - public void testObserveValidatedValue_WrongRealm() { - Realm otherRealm = new CurrentRealm(true); - try { - validator.observeValidatedValue(new WritableValue(otherRealm)); - fail("Expected AssertionFailedException"); - } catch (AssertionFailedException expected) { - } - } - - public void testObserveValidatedValue_ReturnValue() { - WritableValue target = new WritableValue(); - ValidatedObservableValue validated = (ValidatedObservableValue) validator - .observeValidatedValue(target); - - target.setValue(new Object()); - assertEquals(target.getValue(), validated.getValue()); - - dependency.setValue(ValidationStatus.error("error")); - assertFalse(validated.isStale()); - - target.setValue(new Object()); - assertTrue(validated.isStale()); - assertFalse(target.getValue().equals(validated.getValue())); - - dependency.setValue(ValidationStatus.info("info")); // considered valid - assertEquals(target.getValue(), validated.getValue()); - assertFalse(validated.isStale()); - } - - public void testBug237884_DisposeCausesNPE() { - MultiValidator validator = new MultiValidator() { - protected IStatus validate() { - return ValidationStatus.ok(); - } - }; - try { - validator.dispose(); - } catch (NullPointerException e) { - fail("Bug 237884: MultiValidator.dispose() causes NPE"); - } - } - - public void testBug237884_MultipleDispose() { - validator.dispose(); - validator.dispose(); - } - - public void testBug237884_Comment3_ValidationStatusAsDependencyCausesStackOverflow() { - dependency = new WritableValue(new Object(), Object.class); - validator = new MultiValidator() { - private int counter; - - protected IStatus validate() { - ObservableTracker.getterCalled(dependency); - return ValidationStatus.info("info " + counter++); - } - }; - validationStatus = validator.getValidationStatus(); - - // bug behavior: the validation status listener causes the validation - // status observable to become a dependency of the validator. - validationStatus.addChangeListener(new IChangeListener() { - public void handleChange(ChangeEvent event) { - ObservableTracker.getterCalled(validationStatus); - } - }); - dependency.setValue(new Object()); - - // at this point, because the validation status observable is a - // dependency, changes to the validation status cause revalidation in an - // infinite recursion. - try { - dependency.setValue(new Object()); - } catch (StackOverflowError e) { - fail("Bug 237884: Accessing MultiValidator validation status from within listener " - + "causes infinite recursion"); - } - } - - public void testBug237884_ValidationStatusListenerCausesLoopingDependency() { - validationStatus.addChangeListener(new IChangeListener() { - public void handleChange(ChangeEvent event) { - ObservableTracker.getterCalled(validationStatus); - } - }); - assertFalse(validator.getTargets().contains(validationStatus)); - // trigger revalidation - dependency.setValue(ValidationStatus.info("info")); - assertFalse(validator.getTargets().contains(validationStatus)); - } - - public void testBug237884_ValidationStatusAccessDuringValidationCausesLoopingDependency() { - validator = new MultiValidator() { - protected IStatus validate() { - ObservableTracker.getterCalled(getValidationStatus()); - return (IStatus) dependency.getValue(); - } - }; - // trigger revalidation - dependency.setValue(ValidationStatus.info("info")); - assertFalse(validator.getTargets().contains(validationStatus)); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/validation/ValidationStatusTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/validation/ValidationStatusTest.java deleted file mode 100644 index b6f831e4..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/validation/ValidationStatusTest.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.databinding.validation; - -import junit.framework.TestCase; - -import org.eclipse.core.databinding.validation.ValidationStatus; -import org.eclipse.core.runtime.IStatus; - -/** - * @since 1.1 - */ -public class ValidationStatusTest extends TestCase { - public void testEqualsAndHashCode() throws Exception { - String message = "error"; - Exception e = new IllegalArgumentException(); - IStatus status1 = ValidationStatus.error(message, e); - IStatus status2 = ValidationStatus.error(message, e); - - assertEquals(status1, status2); - assertEquals(status1.hashCode(), status2.hashCode()); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/BindingMessagesTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/BindingMessagesTest.java deleted file mode 100644 index 5e6b5162..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/BindingMessagesTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.eclipse.core.tests.internal.databinding; -import junit.framework.TestCase; - -import org.eclipse.core.internal.databinding.BindingMessages; - -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -/** - * @since 3.2 - * - */ -public class BindingMessagesTest extends TestCase { - public void testFormatString() throws Exception { - String key = "Validate_NumberOutOfRangeError"; - String result = BindingMessages.formatString(key, new Object[] {"1", "2"}); - assertFalse("key should not be returned", key.equals(result)); - } - - public void testFormatStringForKeyNotFound() throws Exception { - String key = "key_that_does_not_exist"; - String result = BindingMessages.formatString(key, null); - assertTrue(key.equals(result)); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/BindingStatusTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/BindingStatusTest.java deleted file mode 100644 index 4e732048..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/BindingStatusTest.java +++ /dev/null @@ -1,123 +0,0 @@ -package org.eclipse.core.tests.internal.databinding; -import junit.framework.TestCase; - -import org.eclipse.core.databinding.util.Policy; -import org.eclipse.core.databinding.validation.ValidationStatus; -import org.eclipse.core.internal.databinding.BindingStatus; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; - -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -/** - * @since 1.1 - */ -public class BindingStatusTest extends TestCase { - private BindingStatus bindingStatus; - - /* (non-Javadoc) - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - - bindingStatus = BindingStatus.ok(); - } - - public void testMessageIsFromStatus() throws Exception { - String message = "error message"; - IStatus status = ValidationStatus.error(message); - - bindingStatus.add(status); - assertEquals(message, bindingStatus.getMessage()); - } - - public void testExceptionIsFromStatus() throws Exception { - IllegalArgumentException e = new IllegalArgumentException(); - Status status = new Status(0, Policy.JFACE_DATABINDING, 0, "", e); - - bindingStatus.add(status); - assertEquals(e, bindingStatus.getException()); - } - - public void testPluginIsFromStatus() throws Exception { - String plugin = "test"; - Status status = new Status(0, plugin, 0, "", null); - - bindingStatus.add(status); - assertEquals(plugin, bindingStatus.getPlugin()); - } - - public void testCodeIsFromStatus() throws Exception { - int code = 1; - Status status = new Status(0, Policy.JFACE_DATABINDING, code, "", null); - - bindingStatus.add(status); - assertEquals(code, status.getCode()); - } - - public void testSeverityIsFromStatus() throws Exception { - IStatus status = ValidationStatus.error(""); - - bindingStatus.add(status); - assertEquals(IStatus.ERROR, status.getSeverity()); - } - - public void testLowerSeverityDoesNotOverwriteGreaterSeverity() throws Exception { - String info = "info"; - String error = "error"; - - bindingStatus.add(ValidationStatus.error(error)); - assertEquals(IStatus.ERROR, bindingStatus.getSeverity()); - assertEquals(error, bindingStatus.getMessage()); - - bindingStatus.add(ValidationStatus.info(info)); - assertEquals(IStatus.ERROR, bindingStatus.getSeverity()); - assertEquals(error, bindingStatus.getMessage()); - - IStatus[] children = bindingStatus.getChildren(); - assertEquals(2, children.length); - assertEquals(IStatus.ERROR, children[0].getSeverity()); - assertEquals(IStatus.INFO, children[1].getSeverity()); - } - - public void testEqual() throws Exception { - BindingStatus status1 = BindingStatus.ok(); - BindingStatus status2 = BindingStatus.ok(); - - assertEquals(status1, status2); - } - - public void testNotEqual() throws Exception { - BindingStatus status1 = BindingStatus.ok(); - BindingStatus status2 = BindingStatus.ok(); - - status2.add(ValidationStatus.error("")); - assertFalse(status1.equals(status2)); - } - - public void testHashCode() throws Exception { - BindingStatus status1 = BindingStatus.ok(); - BindingStatus status2 = BindingStatus.ok(); - - assertEquals(status1.hashCode(), status2.hashCode()); - } - - public void testOkInitializesStatus() throws Exception { - BindingStatus status = BindingStatus.ok(); - assertEquals(Policy.JFACE_DATABINDING, status.getPlugin()); - assertEquals("", status.getMessage()); - assertEquals(0, status.getCode()); - assertEquals(0, status.getChildren().length); - assertNull(status.getException()); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/QueueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/QueueTest.java deleted file mode 100644 index 0541847b..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/QueueTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding; - -import org.eclipse.core.internal.databinding.Queue; - -import junit.framework.TestCase; - -/** - * @since 3.2 - * - */ -public class QueueTest extends TestCase { - - private Queue queue; - - protected void setUp() throws Exception { - this.queue = new Queue(); - } - - public void testIsEmpty() { - assertTrue(queue.isEmpty()); - queue.enqueue("foo"); - assertFalse(queue.isEmpty()); - queue.enqueue("bar"); - assertFalse(queue.isEmpty()); - queue.dequeue(); - assertFalse(queue.isEmpty()); - queue.dequeue(); - assertTrue(queue.isEmpty()); - } - - public void testEnqueueAndDequeue() { - try { - queue.dequeue(); - fail("expected IllegalStateException"); - } catch(IllegalStateException ex) { - // expected - } - queue.enqueue("foo"); - assertEquals("foo", queue.dequeue()); - try { - queue.dequeue(); - fail("expected IllegalStateException"); - } catch(IllegalStateException ex) { - // expected - } - queue.enqueue("foo"); - queue.enqueue("bar"); - queue.dequeue(); - queue.enqueue("bas"); - queue.enqueue("moo"); - assertEquals("bar", queue.dequeue()); - assertEquals("bas", queue.dequeue()); - assertEquals("moo", queue.dequeue()); - assertTrue(queue.isEmpty()); - } - -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/RandomAccessListIteratorTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/RandomAccessListIteratorTest.java deleted file mode 100755 index 20bcbdc3..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/RandomAccessListIteratorTest.java +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.core.tests.internal.databinding; - -import java.util.LinkedList; -import java.util.List; - -import junit.framework.TestCase; - -import org.eclipse.core.internal.databinding.RandomAccessListIterator; - -public class RandomAccessListIteratorTest extends TestCase { - - private List emptyList = new LinkedList(); - private RandomAccessListIterator rali0 = new RandomAccessListIterator(emptyList); - private List listWithOne; - private RandomAccessListIterator rali1; - private List list; - private RandomAccessListIterator raliN; - - protected void setUp() throws Exception { - listWithOne = new LinkedList(); - listWithOne.add("Uno"); - rali1 = new RandomAccessListIterator(listWithOne); - list = new LinkedList(); - list.add("One"); - list.add("Two"); - list.add("three"); - list.add("four"); - raliN = new RandomAccessListIterator(list); - } - - public void testGet_emptyList() { - try { - rali0.get(0); - fail("Should have thrown exception"); - } catch (IndexOutOfBoundsException e) { - // success - } - } - - public void testGet_withOne() { - try { - assertEquals("Uno", "Uno", rali1.get(0)); - - rali1.get(1); - fail("Should have thrown IndexOutOfBoundsException"); - } catch (Exception e) { - // success - } - } - - public void testGet_alreadyAtItem() { - assertEquals("one", "One", raliN.get(0)); - } - - public void testGet_moveForward() throws Exception { - assertEquals("three", "three", raliN.get(2)); - } - - public void testGet_moveBackward() throws Exception { - raliN.next(); - raliN.next(); - assertEquals("one", "One", raliN.get(0)); - } - - public void testGet_getLast() throws Exception { - assertEquals("four", "four", raliN.get(3)); - } - - public void testGet_indexTooHigh() throws Exception { - try { - raliN.get(4); - fail("Should have thrown exception"); - } catch (IndexOutOfBoundsException e) { - // success - } - } - - public void testGet_indexTooLow() throws Exception { - try { - raliN.get(-100); - fail("Should have thrown exception"); - } catch (IndexOutOfBoundsException e) { - // success - } - } - -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/Bean.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/Bean.java deleted file mode 100644 index 09224106..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/Bean.java +++ /dev/null @@ -1,111 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007-2008 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bugs 221351, 245183 - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.beans; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * Simple Java Bean for testing. - * - * @since 3.3 - */ -public class Bean { - /* package */PropertyChangeSupport changeSupport = new PropertyChangeSupport( - this); - private String value; - private Object[] array; - private List list; - private Set set; - private Map map; - - public Bean() { - } - - public Bean(String value) { - this.value = value; - } - - public Bean(Object[] array) { - this.array = array; - } - - public Bean(List list) { - this.list = list; - } - - public Bean(Set set) { - this.set = set; - } - - public Bean(Map map) { - this.map = map; - } - - public void addPropertyChangeListener(PropertyChangeListener listener) { - changeSupport.addPropertyChangeListener(listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - changeSupport.removePropertyChangeListener(listener); - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - changeSupport.firePropertyChange("value", this.value, - this.value = value); - } - - public Object[] getArray() { - return array; - } - - public void setArray(Object[] array) { - changeSupport.firePropertyChange("array", this.array, - this.array = array); - } - - public List getList() { - return list; - } - - public void setList(List list) { - changeSupport.firePropertyChange("list", this.list, this.list = list); - } - - public Set getSet() { - return set; - } - - public void setSet(Set set) { - changeSupport.firePropertyChange("set", this.set, this.set = set); - } - - public Map getMap() { - return map; - } - - public void setMap(Map map) { - changeSupport.firePropertyChange("map", this.map, this.map = map); - } - - public boolean hasListeners(String propertyName) { - return changeSupport.hasListeners(propertyName); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/BeanObservableListDecoratorTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/BeanObservableListDecoratorTest.java deleted file mode 100644 index c923d281..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/BeanObservableListDecoratorTest.java +++ /dev/null @@ -1,125 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bugs 208858, 213145, 245183 - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.beans; - -import java.beans.PropertyDescriptor; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.internal.databinding.beans.BeanObservableListDecorator; -import org.eclipse.core.internal.databinding.beans.JavaBeanObservableList; -import org.eclipse.jface.databinding.conformance.MutableObservableListContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.eclipse.swt.widgets.Display; - -/** - * @since 3.3 - */ -public class BeanObservableListDecoratorTest extends AbstractDefaultRealmTestCase { - private PropertyDescriptor propertyDescriptor; - private JavaBeanObservableList observableList; - private BeanObservableListDecorator decorator; - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - - Bean bean = new Bean(); - propertyDescriptor = new PropertyDescriptor( - "list", Bean.class,"getList","setList"); - observableList = new JavaBeanObservableList( - SWTObservables.getRealm(Display.getDefault()), bean, - propertyDescriptor, Bean.class); - decorator = new BeanObservableListDecorator(observableList, observableList, propertyDescriptor); - } - - public void testGetDelegate() throws Exception { - assertEquals(observableList, decorator.getDelegate()); - } - - public void testGetObserved() throws Exception { - assertEquals(observableList, decorator.getObserved()); - } - - public void testGetPropertyDescriptor() throws Exception { - assertEquals(propertyDescriptor, decorator.getPropertyDescriptor()); - } - - public void testEquals_IdentityCheckShortcut() { - IObservableList delegate = new WritableList() { - public boolean equals(Object obj) { - fail("ObservableList.equals() should return true instead of delegating to wrappedList when this == obj"); - return false; - } - }; - decorator = new BeanObservableListDecorator(delegate, - new WritableValue(new Bean(), Object.class), propertyDescriptor); - assertTrue(decorator.equals(decorator)); - } - - public void testEquals_SameClassDelegatesToDelegateObservables() { - IObservableList delegate = new WritableList() { - public boolean equals(Object o) { - return o == this; - } - }; - Bean bean = new Bean(); - decorator = new BeanObservableListDecorator(delegate, new WritableValue( - bean, Object.class), propertyDescriptor); - BeanObservableListDecorator otherDecorator = new BeanObservableListDecorator( - delegate, new WritableValue(bean, Object.class), - propertyDescriptor); - assertTrue(decorator.equals(otherDecorator)); - } - - public static Test suite() { - TestSuite suite = new TestSuite(BeanObservableListDecoratorTest.class.getName()); - suite.addTestSuite(BeanObservableListDecoratorTest.class); - suite.addTest(MutableObservableListContractTest.suite(new Delegate())); - return suite; - } - - static class Delegate extends AbstractObservableCollectionContractDelegate { - public IObservableCollection createObservableCollection(Realm realm, - int elementCount) { - final WritableList delegate = new WritableList(realm); - for (int i = 0; i < elementCount; i++) - delegate.add(createElement(delegate)); - return new BeanObservableListDecorator(delegate, null, null); - } - - private int counter; - - public Object createElement(IObservableCollection collection) { - return Integer.toString(counter++); - } - - public void change(IObservable observable) { - IObservableList list = (IObservableList) observable; - list.add(createElement(list)); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/BeanObservableMapDecoratorTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/BeanObservableMapDecoratorTest.java deleted file mode 100644 index 514c29a3..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/BeanObservableMapDecoratorTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 245183) - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.beans; - -import java.beans.PropertyDescriptor; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.map.WritableMap; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.internal.databinding.beans.BeanObservableMapDecorator; -import org.eclipse.core.internal.databinding.beans.JavaBeanPropertyObservableMap; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -/** - * @since 3.3 - */ -public class BeanObservableMapDecoratorTest extends - AbstractDefaultRealmTestCase { - private PropertyDescriptor propertyDescriptor; - private JavaBeanPropertyObservableMap observableMap; - private BeanObservableMapDecorator decorator; - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - - Bean bean = new Bean(); - propertyDescriptor = new PropertyDescriptor("map", Bean.class, - "getMap", "setMap"); - observableMap = new JavaBeanPropertyObservableMap(Realm.getDefault(), - bean, propertyDescriptor); - decorator = new BeanObservableMapDecorator(observableMap, - observableMap, propertyDescriptor); - } - - public void testGetDelegate() throws Exception { - assertEquals(observableMap, decorator.getDelegate()); - } - - public void testGetObserved() throws Exception { - assertEquals(observableMap, decorator.getObserved()); - } - - public void testGetPropertyDescriptor() throws Exception { - assertEquals(propertyDescriptor, decorator.getPropertyDescriptor()); - } - - public void testEquals_IdentityCheckShortcut() { - IObservableMap delegate = new WritableMap() { - public boolean equals(Object obj) { - fail("ObservableList.equals() should return true instead of delegating to wrappedList when this == obj"); - return false; - } - }; - decorator = new BeanObservableMapDecorator(delegate, new WritableValue( - new Bean(), Object.class), propertyDescriptor); - assertTrue(decorator.equals(decorator)); - } - - public void testEquals_SameClassDelegatesToDelegateObservables() { - IObservableMap delegate = new WritableMap() { - public boolean equals(Object o) { - return o == this; - } - }; - Bean bean = new Bean(); - decorator = new BeanObservableMapDecorator(delegate, bean, - propertyDescriptor); - BeanObservableMapDecorator otherDecorator = new BeanObservableMapDecorator( - delegate, bean, propertyDescriptor); - assertTrue(decorator.equals(otherDecorator)); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/BeanObservableSetDecoratorTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/BeanObservableSetDecoratorTest.java deleted file mode 100644 index 924b1395..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/BeanObservableSetDecoratorTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bug 245183 - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.beans; - -import java.beans.PropertyDescriptor; - -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.WritableSet; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.internal.databinding.beans.BeanObservableSetDecorator; -import org.eclipse.core.internal.databinding.beans.JavaBeanObservableSet; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.eclipse.swt.widgets.Display; - -/** - * @since 3.3 - */ -public class BeanObservableSetDecoratorTest extends AbstractDefaultRealmTestCase { - private PropertyDescriptor propertyDescriptor; - private JavaBeanObservableSet observableSet; - private BeanObservableSetDecorator decorator; - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - - Bean bean = new Bean(); - propertyDescriptor = new PropertyDescriptor("set", - Bean.class); - observableSet = new JavaBeanObservableSet( - SWTObservables.getRealm(Display.getDefault()), bean, - propertyDescriptor, String.class); - decorator = new BeanObservableSetDecorator( - observableSet, observableSet, propertyDescriptor); - } - - public void testGetDelegate() throws Exception { - assertEquals(observableSet, decorator.getDelegate()); - } - - public void testGetObserved() throws Exception { - assertEquals(observableSet, decorator.getObserved()); - } - - public void testGetPropertyDescriptor() throws Exception { - assertEquals(propertyDescriptor, decorator.getPropertyDescriptor()); - } - - public void testEquals_IdentityCheckShortcut() { - IObservableSet delegate = new WritableSet() { - public boolean equals(Object obj) { - fail("ObservableList.equals() should return true instead of delegating to wrappedList when this == obj"); - return false; - } - }; - decorator = new BeanObservableSetDecorator(delegate, new WritableValue( - new Bean(), Object.class), propertyDescriptor); - assertTrue(decorator.equals(decorator)); - } - - public void testEquals_SameClassDelegatesToDelegateObservables() { - IObservableSet delegate = new WritableSet() { - public boolean equals(Object o) { - return o == this; - } - }; - Bean bean = new Bean(); - decorator = new BeanObservableSetDecorator(delegate, bean, - propertyDescriptor); - BeanObservableSetDecorator otherDecorator = new BeanObservableSetDecorator( - delegate, bean, propertyDescriptor); - assertTrue(decorator.equals(otherDecorator)); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/BeanObservableValueDecoratorTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/BeanObservableValueDecoratorTest.java deleted file mode 100644 index 718688d0..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/BeanObservableValueDecoratorTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bug 245183 - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.beans; - -import java.beans.PropertyDescriptor; - -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.internal.databinding.beans.BeanObservableValueDecorator; -import org.eclipse.core.internal.databinding.beans.JavaBeanObservableValue; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.eclipse.swt.widgets.Display; - -/** - * @since 3.3 - */ -public class BeanObservableValueDecoratorTest extends AbstractDefaultRealmTestCase { - private Bean bean; - private JavaBeanObservableValue observableValue; - private BeanObservableValueDecorator decorator; - private PropertyDescriptor propertyDescriptor; - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - - bean = new Bean(); - propertyDescriptor = new PropertyDescriptor("value", - Bean.class); - observableValue = new JavaBeanObservableValue( - SWTObservables.getRealm(Display.getDefault()), bean, - propertyDescriptor); - decorator = new BeanObservableValueDecorator( - observableValue, new WritableValue(bean, Object.class), observableValue - .getPropertyDescriptor()); - } - - public void testGetDelegate() throws Exception { - assertEquals(observableValue, decorator.getDelegate()); - } - - public void testGetObserved() throws Exception { - assertEquals(bean, decorator.getObserved()); - } - - public void testGetPropertyDescriptor() throws Exception { - assertEquals(propertyDescriptor, decorator.getPropertyDescriptor()); - } - - public void testEquals_IdentityCheckShortcut() { - IObservableValue delegate = new WritableValue() { - public boolean equals(Object obj) { - fail("ObservableList.equals() should return true instead of delegating to wrappedList when this == obj"); - return false; - } - }; - decorator = new BeanObservableValueDecorator(delegate, new WritableValue(bean, Object.class), propertyDescriptor); - assertTrue(decorator.equals(decorator)); - } - - public void testEquals_SameClassDelegatesToDelegateObservables() { - IObservableValue delegate = new WritableValue() { - public boolean equals(Object o) { - return o == this; - } - }; - decorator = new BeanObservableValueDecorator(delegate, - new WritableValue(bean, Object.class), propertyDescriptor); - BeanObservableValueDecorator otherDecorator = new BeanObservableValueDecorator( - delegate, new WritableValue(bean, Object.class), - propertyDescriptor); - assertTrue(decorator.equals(otherDecorator)); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableArrayBasedListTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableArrayBasedListTest.java deleted file mode 100644 index c2d183f4..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableArrayBasedListTest.java +++ /dev/null @@ -1,530 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007-2008 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bugs 221351, 213145, 244098 - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.beans; - -import java.beans.IntrospectionException; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.beans.PropertyDescriptor; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.ListChangeEvent; -import org.eclipse.core.databinding.observable.list.ListDiffEntry; -import org.eclipse.core.internal.databinding.beans.JavaBeanObservableList; -import org.eclipse.jface.databinding.conformance.MutableObservableListContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; -import org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.eclipse.swt.widgets.Display; - -/** - * @since 1.1 - */ -public class JavaBeanObservableArrayBasedListTest extends - AbstractDefaultRealmTestCase { - private JavaBeanObservableList list; - - private PropertyDescriptor propertyDescriptor; - - private Bean bean; - - private String propertyName; - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - - propertyName = "array"; - propertyDescriptor = new PropertyDescriptor(propertyName, Bean.class); - bean = new Bean(new Object[0]); - - list = new JavaBeanObservableList(SWTObservables.getRealm(Display - .getDefault()), bean, propertyDescriptor, Bean.class); - } - - public void testGetObserved() throws Exception { - assertSame(bean, list.getObserved()); - } - - public void testGetPropertyDescriptor() throws Exception { - assertSame(propertyDescriptor, list.getPropertyDescriptor()); - } - - public void testRegistersListenerOnCreation() - throws Exception { - assertTrue(bean.changeSupport.hasListeners(propertyName)); - } - - public void testRemovesListenerOnDisposal() - throws Exception { - list.dispose(); - assertFalse(bean.changeSupport.hasListeners(propertyName)); - } - - public void testFiresListChangeEvents() throws Exception { - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - assertEquals(0, listener.count); - bean.setArray(new Bean[] { new Bean() }); - assertEquals(1, listener.count); - } - - public void testAddAddsElement() throws Exception { - int count = list.size(); - String element = "1"; - - assertEquals(0, count); - list.add(element); - assertEquals(count + 1, list.size()); - assertEquals(element, bean.getArray()[count]); - } - - public void testAddListChangeEvent() throws Exception { - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - assertEquals(0, listener.count); - String element = "1"; - - list.add(element); - - assertEquals(1, listener.count); - ListChangeEvent event = listener.event; - - assertEquals(list, event.getObservableList()); - assertEntry(event.diff.getDifferences()[0], true, 0, element); - } - - public void testAdd_FiresPropertyChangeEvent() throws Exception { - assertPropertyChangeEvent(bean, new Runnable() { - public void run() { - list.add("0"); - } - }); - } - - public void testAddWithIndex() throws Exception { - String element = "1"; - assertEquals(0, list.size()); - - list.add(0, element); - assertEquals(element, bean.getArray()[0]); - } - - public void testAddAtIndexListChangeEvent() throws Exception { - String element = "1"; - assertEquals(0, list.size()); - - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - list.add(0, element); - - ListChangeEvent event = listener.event; - assertEntry(event.diff.getDifferences()[0], true, 0, element); - } - - public void testAddAtIndexPropertyChangeEvent() throws Exception { - assertPropertyChangeEvent(bean, new Runnable() { - public void run() { - list.add(0, "0"); - } - }); - } - - public void testRemove() throws Exception { - String element = "1"; - list.add(element); - - assertEquals(1, bean.getArray().length); - list.remove(element); - assertEquals(0, bean.getArray().length); - } - - public void testRemoveListChangeEvent() throws Exception { - String element = "1"; - list.add(element); - - assertEquals(1, list.size()); - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - list.remove(element); - - assertEquals(1, listener.count); - ListChangeEvent event = listener.event; - assertEquals(list, event.getObservableList()); - assertEntry(event.diff.getDifferences()[0], false, 0, element); - } - - public void testRemovePropertyChangeEvent() throws Exception { - list.add("0"); - - assertPropertyChangeEvent(bean, new Runnable() { - public void run() { - list.remove("0"); - } - }); - } - - public void testRemoveAtIndex() throws Exception { - String element = "1"; - list.add(element); - - assertEquals(element, bean.getArray()[0]); - - list.remove(0); - assertEquals(0, bean.getArray().length); - } - - public void testRemoveAtIndexListChangeEvent() throws Exception { - String element = "1"; - list.add(element); - - assertEquals(1, list.size()); - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - list.remove(0); - - assertEquals(1, listener.count); - ListChangeEvent event = listener.event; - assertEquals(list, event.getObservableList()); - assertEntry(event.diff.getDifferences()[0], false, 0, element); - } - - public void testRemoveAtIndexPropertyChangeEvent() throws Exception { - list.add("0"); - assertPropertyChangeEvent(bean, new Runnable() { - public void run() { - list.remove(0); - } - }); - } - - public void testAddAll() throws Exception { - Collection elements = Arrays.asList(new String[] { "1", "2" }); - assertEquals(0, list.size()); - - list.addAll(elements); - - assertEquals(2, bean.getArray().length); - } - - public void testAddAllListChangEvent() throws Exception { - List elements = Arrays.asList(new String[] { "1", "2" }); - assertEquals(0, list.size()); - - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - assertEquals(0, listener.count); - - list.addAll(elements); - - assertEquals(1, listener.count); - ListChangeEvent event = listener.event; - assertEquals(list, event.getObservableList()); - - assertEntry(event.diff.getDifferences()[0], true, 0, elements.get(0)); - assertEntry(event.diff.getDifferences()[1], true, 1, elements.get(1)); - } - - public void testAddAllPropertyChangeEvent() throws Exception { - assertPropertyChangeEvent(bean, new Runnable() { - public void run() { - list.addAll(Arrays.asList(new String[] { "0", "1" })); - } - }); - } - - public void testAddAllAtIndex() throws Exception { - List elements = Arrays.asList(new String[] { "1", "2" }); - list.addAll(elements); - - assertEquals(2, list.size()); - - list.addAll(2, elements); - - assertEquals(4, bean.getArray().length); - assertEquals(elements.get(0), bean.getArray()[0]); - assertEquals(elements.get(1), bean.getArray()[1]); - } - - public void testAddAllAtIndexListChangeEvent() throws Exception { - List elements = Arrays.asList(new String[] { "1", "2" }); - list.addAll(elements); - - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - assertEquals(0, listener.count); - - list.addAll(2, elements); - - assertEquals(1, listener.count); - ListChangeEvent event = listener.event; - assertEquals(list, event.getObservableList()); - assertEntry(event.diff.getDifferences()[0], true, 2, elements.get(0)); - assertEntry(event.diff.getDifferences()[1], true, 3, elements.get(1)); - } - - public void testAddAllAtIndexPropertyChangeEvent() throws Exception { - assertPropertyChangeEvent(bean, new Runnable() { - public void run() { - list.addAll(0, Arrays.asList(new String[] { "1", "2" })); - } - }); - } - - public void testRemoveAll() throws Exception { - List elements = Arrays.asList(new String[] { "1", "2" }); - list.addAll(elements); - list.addAll(elements); - - assertEquals(4, bean.getArray().length); - list.removeAll(elements); - - assertEquals(2, bean.getArray().length); - assertEquals(elements.get(0), bean.getArray()[0]); - assertEquals(elements.get(1), bean.getArray()[1]); - } - - public void testRemoveAllListChangeEvent() throws Exception { - List elements = Arrays.asList(new String[] { "1", "2" }); - list.addAll(elements); - list.addAll(elements); - - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - assertEquals(0, listener.count); - list.removeAll(elements); - - ListChangeEvent event = listener.event; - assertEquals(list, event.getObservableList()); - assertEntry(event.diff.getDifferences()[0], false, 0, elements.get(0)); - assertEntry(event.diff.getDifferences()[1], false, 0, elements.get(1)); - } - - public void testRemoveAllPropertyChangeEvent() throws Exception { - list.add("0"); - assertPropertyChangeEvent(bean, new Runnable() { - public void run() { - list.removeAll(Arrays.asList(new String[] { "0" })); - } - }); - } - - public void testRetailAll() throws Exception { - List elements = Arrays.asList(new String[] { "0", "1", "2", "3" }); - list.addAll(elements); - - assertEquals(4, bean.getArray().length); - - list.retainAll(elements.subList(0, 2)); - assertEquals(2, bean.getArray().length); - - assertEquals(elements.get(0), bean.getArray()[0]); - assertEquals(elements.get(1), bean.getArray()[1]); - } - - public void testRetainAllListChangeEvent() throws Exception { - List elements = Arrays.asList(new String[] { "0", "1", "2", "3" }); - list.addAll(elements); - - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - assertEquals(0, listener.count); - list.retainAll(elements.subList(0, 2)); - - assertEquals(1, listener.count); - ListChangeEvent event = listener.event; - assertEquals(list, event.getObservableList()); - assertEntry(event.diff.getDifferences()[0], false, 2, elements.get(2)); - assertEntry(event.diff.getDifferences()[1], false, 2, elements.get(3)); - } - - public void testRetainAllPropertyChangeEvent() throws Exception { - list.addAll(Arrays.asList(new String[] { "0", "1" })); - - assertPropertyChangeEvent(bean, new Runnable() { - public void run() { - list.retainAll(Arrays.asList(new String[] { "0" })); - } - }); - } - - public void testSet() throws Exception { - String oldElement = "old"; - String newElement = "new"; - list.add(oldElement); - - assertEquals(oldElement, bean.getArray()[0]); - - list.set(0, newElement); - assertEquals(newElement, bean.getArray()[0]); - } - - public void testMove() throws Exception { - String element0 = "element0"; - String element1 = "element1"; - list.add(element0); - list.add(element1); - - assertEquals(2, bean.getArray().length); - assertEquals(element0, bean.getArray()[0]); - assertEquals(element1, bean.getArray()[1]); - - list.move(0, 1); - - assertEquals(2, bean.getArray().length); - assertEquals(element1, bean.getArray()[0]); - assertEquals(element0, bean.getArray()[1]); - } - - public void testSetListChangeEvent() throws Exception { - String oldElement = "old"; - String newElement = "new"; - list.add(oldElement); - - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - assertEquals(0, listener.count); - - list.set(0, newElement); - - assertEquals(1, listener.count); - ListChangeEvent event = listener.event; - assertEquals(list, event.getObservableList()); - assertEntry(event.diff.getDifferences()[0], false, 0, oldElement); - assertEntry(event.diff.getDifferences()[1], true, 0, newElement); - } - - public void testSetPropertyChangeEvent() throws Exception { - list.add("0"); - assertPropertyChangeEvent(bean, new Runnable() { - public void run() { - list.set(0, "1"); - } - }); - } - - public void testListChangeEventFiresWhenNewListIsSet() throws Exception { - Bean[] elements = new Bean[] { new Bean(), new Bean() }; - - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - assertEquals(0, listener.count); - bean.setArray(elements); - assertEquals(1, listener.count); - } - - private static void assertEntry(ListDiffEntry entry, boolean addition, - int position, Object element) { - assertEquals("addition", addition, entry.isAddition()); - assertEquals("position", position, entry.getPosition()); - assertEquals("element", element, entry.getElement()); - } - - private static void assertPropertyChangeEvent(Bean bean, Runnable runnable) { - PropertyChangeTracker listener = new PropertyChangeTracker(); - bean.addPropertyChangeListener(listener); - - Object[] old = bean.getArray(); - assertEquals(0, listener.count); - - runnable.run(); - - PropertyChangeEvent event = listener.evt; - assertEquals("event did not fire", 1, listener.count); - assertEquals("array", event.getPropertyName()); - assertTrue("old value", Arrays.equals(old, (Object[]) event.getOldValue())); - assertTrue("new value", Arrays.equals(bean.getArray(), (Object[]) event.getNewValue())); - assertFalse("lists are equal", Arrays.equals(bean.getArray(), old)); - } - - private static class PropertyChangeTracker implements - PropertyChangeListener { - int count; - - PropertyChangeEvent evt; - - /* - * (non-Javadoc) - * - * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) - */ - public void propertyChange(PropertyChangeEvent evt) { - count++; - this.evt = evt; - } - } - - public static Test suite() { - TestSuite suite = new TestSuite(JavaBeanObservableArrayBasedListTest.class.getName()); - suite.addTestSuite(JavaBeanObservableArrayBasedListTest.class); - suite.addTest(MutableObservableListContractTest.suite(new Delegate())); - return suite; - } - - static class Delegate extends AbstractObservableCollectionContractDelegate { - public IObservableCollection createObservableCollection(Realm realm, - int elementCount) { - String propertyName = "array"; - PropertyDescriptor propertyDescriptor; - try { - propertyDescriptor = new PropertyDescriptor(propertyName, - Bean.class); - } catch (IntrospectionException e) { - throw new RuntimeException(e); - } - Object bean = new Bean(new Object[0]); - - IObservableList list = new JavaBeanObservableList(realm, bean, - propertyDescriptor, String.class); - for (int i = 0; i < elementCount; i++) - list.add(createElement(list)); - return list; - } - - public Object createElement(IObservableCollection collection) { - return new Object(); - } - - public Object getElementType(IObservableCollection collection) { - return String.class; - } - - public void change(IObservable observable) { - IObservableList list = (IObservableList) observable; - list.add(createElement(list)); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableArrayBasedSetTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableArrayBasedSetTest.java deleted file mode 100644 index 8f897d4f..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableArrayBasedSetTest.java +++ /dev/null @@ -1,349 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 221351) - * Brad Reynolds - through JavaBeanObservableArrayBasedListTest.java - * Matthew Hall - bug 213145, 244098 - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.beans; - -import java.beans.IntrospectionException; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.beans.PropertyDescriptor; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.SetChangeEvent; -import org.eclipse.core.internal.databinding.beans.JavaBeanObservableSet; -import org.eclipse.jface.databinding.conformance.MutableObservableSetContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; -import org.eclipse.jface.databinding.conformance.util.SetChangeEventTracker; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.eclipse.swt.widgets.Display; - -/** - * @since 1.1 - */ -public class JavaBeanObservableArrayBasedSetTest extends - AbstractDefaultRealmTestCase { - private JavaBeanObservableSet set; - - private PropertyDescriptor propertyDescriptor; - - private Bean bean; - - private String propertyName; - - protected void setUp() throws Exception { - super.setUp(); - - propertyName = "array"; - propertyDescriptor = new PropertyDescriptor(propertyName, Bean.class); - bean = new Bean(new HashSet()); - - set = new JavaBeanObservableSet(SWTObservables.getRealm(Display - .getDefault()), bean, propertyDescriptor, String.class); - } - - public void testGetObserved() throws Exception { - assertEquals(bean, set.getObserved()); - } - - public void testGetPropertyDescriptor() throws Exception { - assertEquals(propertyDescriptor, set.getPropertyDescriptor()); - } - - public void testRegistersListenerOnCreation() throws Exception { - assertTrue(bean.changeSupport.hasListeners(propertyName)); - } - - public void testRemovesListenerOnDisposal() throws Exception { - set.dispose(); - assertFalse(bean.changeSupport.hasListeners(propertyName)); - } - - public void testSetBeanProperty_FiresSetChangeEvents() throws Exception { - SetChangeEventTracker listener = SetChangeEventTracker.observe(set); - - assertEquals(0, listener.count); - bean.setArray(new String[] { "element" }); - assertEquals(1, listener.count); - } - - public void testAdd_AddsElement() throws Exception { - assertEquals(0, set.size()); - - String element = "1"; - set.add(element); - - assertEquals(1, set.size()); - assertEquals(element, bean.getArray()[0]); - } - - public void testAdd_SetChangeEvent() throws Exception { - SetChangeEventTracker listener = SetChangeEventTracker.observe(set); - assertEquals(0, listener.count); - - String element = "1"; - set.add(element); - - assertEquals(1, listener.count); - SetChangeEvent event = listener.event; - - assertSame(set, event.getObservableSet()); - assertEquals(Collections.singleton(element), event.diff.getAdditions()); - assertEquals(Collections.EMPTY_SET, event.diff.getRemovals()); - } - - public void testAdd_FiresPropertyChangeEvent() throws Exception { - assertPropertyChangeEvent(bean, new Runnable() { - public void run() { - set.add("0"); - } - }); - } - - public void testRemove() throws Exception { - String element = "1"; - set.add(element); - - assertEquals(1, bean.getArray().length); - set.remove(element); - assertEquals(0, bean.getArray().length); - } - - public void testRemoveListChangeEvent() throws Exception { - String element = "1"; - set.add(element); - assertEquals(1, set.size()); - - SetChangeEventTracker listener = SetChangeEventTracker.observe(set); - assertEquals(0, listener.count); - - set.remove(element); - - assertEquals(1, listener.count); - SetChangeEvent event = listener.event; - assertEquals(set, event.getObservableSet()); - assertEquals(Collections.singleton(element), event.diff.getRemovals()); - assertEquals(Collections.EMPTY_SET, event.diff.getAdditions()); - } - - public void testRemovePropertyChangeEvent() throws Exception { - set.add("0"); - - assertPropertyChangeEvent(bean, new Runnable() { - public void run() { - set.remove("0"); - } - }); - } - - public void testAddAll() throws Exception { - Collection elements = Arrays.asList(new String[] { "1", "2" }); - assertEquals(0, set.size()); - - set.addAll(elements); - - assertEquals(2, bean.getArray().length); - } - - public void testAddAllListChangEvent() throws Exception { - Collection elements = Arrays.asList(new String[] { "1", "2" }); - assertEquals(0, set.size()); - - SetChangeEventTracker listener = SetChangeEventTracker.observe(set); - assertEquals(0, listener.count); - - set.addAll(elements); - - assertEquals(1, listener.count); - SetChangeEvent event = listener.event; - assertEquals(set, event.getObservableSet()); - - assertEquals(new HashSet(elements), event.diff.getAdditions()); - assertEquals(Collections.EMPTY_SET, event.diff.getRemovals()); - } - - public void testAddAllPropertyChangeEvent() throws Exception { - assertPropertyChangeEvent(bean, new Runnable() { - public void run() { - set.addAll(Arrays.asList(new String[] { "0", "1" })); - } - }); - } - - public void testRemoveAll() throws Exception { - Collection elements = Arrays.asList(new String[] { "1", "2" }); - set.addAll(elements); - - assertEquals(2, bean.getArray().length); - set.removeAll(elements); - - assertEquals(0, bean.getArray().length); - } - - public void testRemoveAllListChangeEvent() throws Exception { - Collection elements = Arrays.asList(new String[] { "1", "2" }); - set.addAll(elements); - - SetChangeEventTracker listener = SetChangeEventTracker.observe(set); - assertEquals(0, listener.count); - - set.removeAll(elements); - - SetChangeEvent event = listener.event; - assertEquals(set, event.getObservableSet()); - assertEquals(Collections.EMPTY_SET, event.diff.getAdditions()); - assertEquals(new HashSet(elements), event.diff.getRemovals()); - } - - public void testRemoveAllPropertyChangeEvent() throws Exception { - set.add("0"); - assertPropertyChangeEvent(bean, new Runnable() { - public void run() { - set.removeAll(Arrays.asList(new String[] { "0" })); - } - }); - } - - public void testRetailAll() throws Exception { - set.addAll(Arrays.asList(new String[] { "0", "1", "2", "3" })); - - assertEquals(4, bean.getArray().length); - - set.retainAll(Arrays.asList(new String[] { "0", "1" })); - assertEquals(2, bean.getArray().length); - - assertTrue(set.containsAll(Arrays.asList(new String[] { "1", "0" }))); - } - - public void testRetainAllListChangeEvent() throws Exception { - set.addAll(Arrays.asList(new String[] { "0", "1", "2", "3" })); - - SetChangeEventTracker listener = SetChangeEventTracker.observe(set); - - assertEquals(0, listener.count); - set.retainAll(Arrays.asList(new String[] { "0", "1" })); - - assertEquals(1, listener.count); - SetChangeEvent event = listener.event; - assertEquals(set, event.getObservableSet()); - assertEquals(Collections.EMPTY_SET, event.diff.getAdditions()); - assertEquals(new HashSet(Arrays.asList(new String[] { "2", "3" })), - event.diff.getRemovals()); - } - - public void testRetainAllPropertyChangeEvent() throws Exception { - set.addAll(Arrays.asList(new String[] { "0", "1" })); - - assertPropertyChangeEvent(bean, new Runnable() { - public void run() { - set.retainAll(Arrays.asList(new String[] { "0" })); - } - }); - } - - public void testListChangeEventFiresWhenNewListIsSet() throws Exception { - Bean[] elements = new Bean[] { new Bean(), new Bean() }; - - SetChangeEventTracker listener = SetChangeEventTracker.observe(set); - - assertEquals(0, listener.count); - bean.setArray(elements); - assertEquals(1, listener.count); - } - - private static void assertPropertyChangeEvent(Bean bean, Runnable runnable) { - PropertyChangeTracker listener = new PropertyChangeTracker(); - bean.addPropertyChangeListener(listener); - - Object[] old = bean.getArray(); - assertEquals(0, listener.count); - - runnable.run(); - - PropertyChangeEvent event = listener.evt; - assertEquals("event did not fire", 1, listener.count); - assertEquals("array", event.getPropertyName()); - assertTrue("old value", Arrays.equals(old, (Object[]) event - .getOldValue())); - assertTrue("new value", Arrays.equals(bean.getArray(), (Object[]) event.getNewValue())); - assertFalse("lists are equal", Arrays.equals(bean.getArray(), old)); - } - - private static class PropertyChangeTracker implements - PropertyChangeListener { - int count; - - PropertyChangeEvent evt; - - /* - * (non-Javadoc) - * - * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) - */ - public void propertyChange(PropertyChangeEvent evt) { - count++; - this.evt = evt; - } - } - - public static Test suite() { - TestSuite suite = new TestSuite(JavaBeanObservableArrayBasedSetTest.class.getName()); - suite.addTestSuite(JavaBeanObservableArrayBasedSetTest.class); - suite.addTest(MutableObservableSetContractTest.suite(new Delegate())); - return suite; - } - - static class Delegate extends AbstractObservableCollectionContractDelegate { - public IObservableCollection createObservableCollection(Realm realm, - int elementCount) { - String propertyName = "array"; - PropertyDescriptor propertyDescriptor; - try { - propertyDescriptor = new PropertyDescriptor(propertyName, - Bean.class); - } catch (IntrospectionException e) { - throw new RuntimeException(e); - } - Object bean = new Bean(new Object[0]); - - IObservableSet list = new JavaBeanObservableSet(realm, bean, - propertyDescriptor, String.class); - for (int i = 0; i < elementCount; i++) - list.add(createElement(list)); - return list; - } - - public Object createElement(IObservableCollection collection) { - return new Object().toString(); - } - - public Object getElementType(IObservableCollection collection) { - return String.class; - } - - public void change(IObservable observable) { - IObservableSet list = (IObservableSet) observable; - list.add(createElement(list)); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableListTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableListTest.java deleted file mode 100644 index e91cf7ef..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableListTest.java +++ /dev/null @@ -1,577 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007-2008 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bugs 221351, 213145, 244098, 240931 - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.beans; - -import java.beans.IntrospectionException; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.beans.PropertyDescriptor; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IListChangeListener; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.ListChangeEvent; -import org.eclipse.core.databinding.observable.list.ListDiffEntry; -import org.eclipse.core.internal.databinding.beans.JavaBeanObservableList; -import org.eclipse.jface.databinding.conformance.MutableObservableListContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; -import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker; -import org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.eclipse.swt.widgets.Display; - -/** - * @since 1.1 - */ -public class JavaBeanObservableListTest extends AbstractDefaultRealmTestCase { - private JavaBeanObservableList list; - - private PropertyDescriptor propertyDescriptor; - - private Bean bean; - - private String propertyName; - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - - propertyName = "list"; - propertyDescriptor = new PropertyDescriptor(propertyName, Bean.class); - bean = new Bean(new ArrayList()); - - list = new JavaBeanObservableList(SWTObservables.getRealm(Display - .getDefault()), bean, propertyDescriptor, String.class); - } - - public void testGetObserved() throws Exception { - assertEquals(bean, list.getObserved()); - } - - public void testGetPropertyDescriptor() throws Exception { - assertEquals(propertyDescriptor, list.getPropertyDescriptor()); - } - - public void testRegistersListenerOnCreation() throws Exception { - assertTrue(bean.changeSupport.hasListeners(propertyName)); - } - - public void testRemovesListenerOnDisposal() throws Exception { - list.dispose(); - assertFalse(bean.changeSupport.hasListeners(propertyName)); - } - - public void testFiresListChangeEvents() throws Exception { - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - assertEquals(0, listener.count); - bean.setList(Arrays.asList(new String[] { "value" })); - assertEquals(1, listener.count); - } - - public void testAddAddsElement() throws Exception { - int count = list.size(); - String element = "1"; - - assertEquals(0, count); - list.add(element); - assertEquals(count + 1, list.size()); - assertEquals(element, bean.getList().get(count)); - } - - public void testAddListChangeEvent() throws Exception { - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - assertEquals(0, listener.count); - String element = "1"; - - list.add(element); - - assertEquals(1, listener.count); - ListChangeEvent event = listener.event; - - assertEquals(list, event.getObservableList()); - assertEntry(event.diff.getDifferences()[0], true, 0, element); - } - - public void testAddFiresPropertyChangeEvent() throws Exception { - assertPropertyChangeEvent(bean, new Runnable() { - public void run() { - list.add("0"); - } - }); - } - - public void testAddAtIndex() throws Exception { - String element = "1"; - assertEquals(0, list.size()); - - list.add(0, element); - assertEquals(element, bean.getList().get(0)); - } - - public void testAddAtIndexListChangeEvent() throws Exception { - String element = "1"; - assertEquals(0, list.size()); - - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - list.add(0, element); - - ListChangeEvent event = listener.event; - assertEntry(event.diff.getDifferences()[0], true, 0, element); - } - - public void testAddAtIndexPropertyChangeEvent() throws Exception { - assertPropertyChangeEvent(bean, new Runnable() { - public void run() { - list.add(0, "0"); - } - }); - } - - public void testClear() throws Exception { - String element = "1"; - list.add(element); - - assertEquals(1, bean.getList().size()); - assertPropertyChangeEvent(bean, new Runnable(){ - public void run() { - list.clear(); - } - }); - assertEquals(0, bean.getList().size()); - } - - public void testRemove() throws Exception { - String element = "1"; - list.add(element); - - assertEquals(1, bean.getList().size()); - list.remove(element); - assertEquals(0, bean.getList().size()); - } - - public void testRemoveListChangeEvent() throws Exception { - String element = "1"; - list.add(element); - - assertEquals(1, list.size()); - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - list.remove(element); - - assertEquals(1, listener.count); - ListChangeEvent event = listener.event; - assertEquals(list, event.getObservableList()); - assertEntry(event.diff.getDifferences()[0], false, 0, element); - } - - public void testRemovePropertyChangeEvent() throws Exception { - list.add("0"); - - assertPropertyChangeEvent(bean, new Runnable() { - public void run() { - list.remove("0"); - } - }); - } - - public void testRemoveAtIndex() throws Exception { - String element = "1"; - list.add(element); - - assertEquals(element, bean.getList().get(0)); - - list.remove(0); - assertEquals(0, bean.getList().size()); - } - - public void testRemoveAtIndexListChangeEvent() throws Exception { - String element = "1"; - list.add(element); - - assertEquals(1, list.size()); - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - list.remove(0); - - assertEquals(1, listener.count); - ListChangeEvent event = listener.event; - assertEquals(list, event.getObservableList()); - assertEntry(event.diff.getDifferences()[0], false, 0, element); - } - - public void testRemoveAtIndexPropertyChangeEvent() throws Exception { - list.add("0"); - assertPropertyChangeEvent(bean, new Runnable() { - public void run() { - list.remove(0); - } - }); - } - - public void testAddAll() throws Exception { - Collection elements = Arrays.asList(new String[] { "1", "2" }); - assertEquals(0, list.size()); - - list.addAll(elements); - - assertEquals(2, bean.getList().size()); - } - - public void testAddAllListChangEvent() throws Exception { - List elements = Arrays.asList(new String[] { "1", "2" }); - assertEquals(0, list.size()); - - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - assertEquals(0, listener.count); - - list.addAll(elements); - - assertEquals(1, listener.count); - ListChangeEvent event = listener.event; - assertEquals(list, event.getObservableList()); - - assertEntry(event.diff.getDifferences()[0], true, 0, elements.get(0)); - assertEntry(event.diff.getDifferences()[1], true, 1, elements.get(1)); - } - - public void testAddAllPropertyChangeEvent() throws Exception { - assertPropertyChangeEvent(bean, new Runnable() { - public void run() { - list.addAll(Arrays.asList(new String[] {"0", "1"})); - } - }); - } - - public void testAddAllAtIndex() throws Exception { - List elements = Arrays.asList(new String[] { "1", "2" }); - list.addAll(elements); - - assertEquals(2, list.size()); - - list.addAll(2, elements); - - assertEquals(4, bean.getList().size()); - assertEquals(elements.get(0), bean.getList().get(0)); - assertEquals(elements.get(1), bean.getList().get(1)); - } - - public void testAddAllAtIndexListChangeEvent() throws Exception { - List elements = Arrays.asList(new String[] { "1", "2" }); - list.addAll(elements); - - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - assertEquals(0, listener.count); - - list.addAll(2, elements); - - assertEquals(1, listener.count); - ListChangeEvent event = listener.event; - assertEquals(list, event.getObservableList()); - assertEntry(event.diff.getDifferences()[0], true, 2, elements.get(0)); - assertEntry(event.diff.getDifferences()[1], true, 3, elements.get(1)); - } - - public void testAddAllAtIndexPropertyChangeEvent() throws Exception { - assertPropertyChangeEvent(bean, new Runnable() { - public void run() { - list.addAll(0, Arrays.asList(new String[] {"1", "2"})); - } - }); - } - - public void testRemoveAll() throws Exception { - List elements = Arrays.asList(new String[] { "1", "2" }); - list.addAll(elements); - list.addAll(elements); - - assertEquals(4, bean.getList().size()); - list.removeAll(elements); - - assertEquals(2, bean.getList().size()); - assertEquals(elements.get(0), bean.getList().get(0)); - assertEquals(elements.get(1), bean.getList().get(1)); - } - - public void testRemoveAllListChangeEvent() throws Exception { - List elements = Arrays.asList(new String[] { "1", "2" }); - list.addAll(elements); - list.addAll(elements); - - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - assertEquals(0, listener.count); - list.removeAll(elements); - - ListChangeEvent event = listener.event; - assertEquals(list, event.getObservableList()); - assertEntry(event.diff.getDifferences()[0], false, 0, elements.get(0)); - assertEntry(event.diff.getDifferences()[1], false, 0, elements.get(1)); - } - - public void testRemoveAllPropertyChangeEvent() throws Exception { - list.add("0"); - assertPropertyChangeEvent(bean, new Runnable() { - public void run() { - list.removeAll(Arrays.asList(new String[] {"0"})); - } - }); - } - - public void testRetailAll() throws Exception { - List elements = Arrays.asList(new String[] { "0", "1", "2", "3" }); - list.addAll(elements); - - assertEquals(4, bean.getList().size()); - - list.retainAll(elements.subList(0, 2)); - assertEquals(2, bean.getList().size()); - - assertEquals(elements.get(0), bean.getList().get(0)); - assertEquals(elements.get(1), bean.getList().get(1)); - } - - public void testRetainAllListChangeEvent() throws Exception { - List elements = Arrays.asList(new String[] { "0", "1", "2", "3" }); - list.addAll(elements); - - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - assertEquals(0, listener.count); - list.retainAll(elements.subList(0, 2)); - - assertEquals(1, listener.count); - ListChangeEvent event = listener.event; - assertEquals(list, event.getObservableList()); - assertEntry(event.diff.getDifferences()[0], false, 2, elements.get(2)); - assertEntry(event.diff.getDifferences()[1], false, 2, elements.get(3)); - } - - public void testRetainAllPropertyChangeEvent() throws Exception { - list.addAll(Arrays.asList(new String[] {"0", "1"})); - - assertPropertyChangeEvent(bean, new Runnable() { - public void run() { - list.retainAll(Arrays.asList(new String[] {"0"})); - } - }); - } - - public void testSet() throws Exception { - String oldElement = "old"; - String newElement = "new"; - list.add(oldElement); - - assertEquals(oldElement, bean.getList().get(0)); - - list.set(0, newElement); - assertEquals(newElement, bean.getList().get(0)); - } - - public void testMove() throws Exception { - String element0 = "element0"; - String element1 = "element1"; - list.add(element0); - list.add(element1); - - assertEquals(2, bean.getList().size()); - assertEquals(element0, bean.getList().get(0)); - assertEquals(element1, bean.getList().get(1)); - - list.move(0, 1); - - assertEquals(2, bean.getList().size()); - assertEquals(element1, bean.getList().get(0)); - assertEquals(element0, bean.getList().get(1)); - } - - public void testSetListChangeEvent() throws Exception { - String oldElement = "old"; - String newElement = "new"; - list.add(oldElement); - - ListChangeEventTracker listener = ListChangeEventTracker.observe(list); - assertEquals(0, listener.count); - - list.set(0, newElement); - - assertEquals(1, listener.count); - ListChangeEvent event = listener.event; - assertEquals(list, event.getObservableList()); - assertEntry(event.diff.getDifferences()[0], false, 0, oldElement); - assertEntry(event.diff.getDifferences()[1], true, 0, newElement); - } - - public void testSetPropertyChangeEvent() throws Exception { - list.add("0"); - assertPropertyChangeEvent(bean, new Runnable() { - public void run() { - list.set(0, "1"); - } - }); - } - - public void testListChangeEventFiresWhenNewListIsSet() throws Exception { - List elements = Arrays.asList(new String[] { "1", "2" }); - - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - assertEquals(0, listener.count); - bean.setList(elements); - assertEquals(1, listener.count); - } - - public void testConstructor_RegistersListener() throws Exception { - Bean bean = new Bean(); - new JavaBeanObservableList(Realm.getDefault(), bean, - new PropertyDescriptor("list", Bean.class), Bean.class); - - assertTrue(bean.hasListeners("list")); - } - - public void testConstructor_SkipsRegisterListener() throws Exception { - Bean bean = new Bean(); - JavaBeanObservableList observable = new JavaBeanObservableList(Realm - .getDefault(), bean, - new PropertyDescriptor("list", Bean.class), Bean.class, false); - - assertFalse(bean.hasListeners("list")); - ChangeEventTracker.observe(observable); - assertFalse(bean.hasListeners("list")); - } - - public void testFirstListenerAdded_AfterLastListenerRemoved() throws Exception { - IListChangeListener listener = new IListChangeListener() { - public void handleListChange(ListChangeEvent event) { - // noop - } - }; - list.addListChangeListener(listener); - list.removeListChangeListener(listener); - list.addListChangeListener(listener); - } - - public void testDispose_DoubleInvocation() throws Exception { - list.dispose(); - list.dispose(); - } - - private static void assertEntry(ListDiffEntry entry, boolean addition, - int position, Object element) { - assertEquals("addition", addition, entry.isAddition()); - assertEquals("position", position, entry.getPosition()); - assertEquals("element", element, entry.getElement()); - } - - private static void assertPropertyChangeEvent(Bean bean, Runnable runnable) { - PropertyChangeTracker listener = new PropertyChangeTracker(); - bean.addPropertyChangeListener(listener); - - List old = bean.getList(); - assertEquals(0, listener.count); - - runnable.run(); - - PropertyChangeEvent event = listener.evt; - assertEquals("event did not fire", 1, listener.count); - assertEquals("list", event.getPropertyName()); - assertEquals("old value", old, event.getOldValue()); - assertEquals("new value", bean.getList(), event.getNewValue()); - assertFalse("lists are equal", bean.getList().equals(old)); - } - - private static class PropertyChangeTracker implements - PropertyChangeListener { - int count; - - PropertyChangeEvent evt; - - /* - * (non-Javadoc) - * - * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) - */ - public void propertyChange(PropertyChangeEvent evt) { - count++; - this.evt = evt; - } - } - - public static Test suite() { - TestSuite suite = new TestSuite(JavaBeanObservableListTest.class.getName()); - suite.addTestSuite(JavaBeanObservableListTest.class); - suite.addTest(MutableObservableListContractTest.suite(new Delegate())); - return suite; - } - - static class Delegate extends AbstractObservableCollectionContractDelegate { - public IObservableCollection createObservableCollection(Realm realm, - int elementCount) { - String propertyName = "list"; - PropertyDescriptor propertyDescriptor; - try { - propertyDescriptor = new PropertyDescriptor(propertyName, - Bean.class); - } catch (IntrospectionException e) { - throw new RuntimeException(e); - } - Object bean = new Bean(new ArrayList()); - - IObservableList list = new JavaBeanObservableList(realm, bean, - propertyDescriptor, String.class); - for (int i = 0; i < elementCount; i++) - list.add(createElement(list)); - return list; - } - - public Object createElement(IObservableCollection collection) { - return new Object().toString(); - } - - public Object getElementType(IObservableCollection collection) { - return String.class; - } - - public void change(IObservable observable) { - IObservableList list = (IObservableList) observable; - list.add(createElement(list)); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableMapTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableMapTest.java deleted file mode 100644 index fbdc3a24..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableMapTest.java +++ /dev/null @@ -1,196 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bugs 213145, 240931 - *******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.beans; - -import java.beans.PropertyDescriptor; -import java.util.HashSet; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.map.IMapChangeListener; -import org.eclipse.core.databinding.observable.map.MapChangeEvent; -import org.eclipse.core.databinding.observable.map.MapDiff; -import org.eclipse.core.databinding.observable.set.WritableSet; -import org.eclipse.core.internal.databinding.beans.JavaBeanObservableMap; -import org.eclipse.core.tests.databinding.observable.ThreadRealm; -import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker; -import org.eclipse.jface.databinding.conformance.util.CurrentRealm; - -/** - * @since 3.2 - * - */ -public class JavaBeanObservableMapTest extends TestCase { - private Bean model1; - - private Bean model2; - - private WritableSet set; - - private PropertyDescriptor propertyDescriptor; - - private JavaBeanObservableMap map; - - protected void setUp() throws Exception { - ThreadRealm realm = new ThreadRealm(); - realm.init(Thread.currentThread()); - model1 = new Bean("1"); - model2 = new Bean("2"); - - set = new WritableSet(realm, new HashSet(), Bean.class); - set.add(model1); - set.add(model2); - - propertyDescriptor = new PropertyDescriptor("value", Bean.class); - map = new JavaBeanObservableMap(set, propertyDescriptor); - } - - public void testGetValue() throws Exception { - assertEquals( - "The 'value' from the map should be the value of the property of the model.", - model1.getValue(), map.get(model1)); - } - - public void testSetValueNotifications() throws Exception { - String oldValue = model1.getValue(); - String newValue = model1.getValue() + model1.getValue(); - MapChangeListener listener = new MapChangeListener(); - - map.addMapChangeListener(listener); - assertEquals(0, listener.count); - model1.setValue(newValue); - assertEquals(1, listener.count); - assertTrue(listener.diff.getChangedKeys().contains(model1)); - assertEquals(newValue, listener.diff.getNewValue(model1)); - assertEquals(oldValue, listener.diff.getOldValue(model1)); - assertFalse(listener.diff.getAddedKeys().contains(model1)); - assertFalse(listener.diff.getRemovedKeys().contains(model1)); - } - - public void testPutValue() throws Exception { - String oldValue = model1.getValue(); - String newValue = model1.getValue() + model1.getValue(); - MapChangeListener listener = new MapChangeListener(); - map.addMapChangeListener(listener); - - assertEquals(0, listener.count); - map.put(model1, newValue); - assertEquals(1, listener.count); - assertEquals(newValue, model1.getValue()); - assertEquals(oldValue, listener.diff.getOldValue(model1)); - assertEquals(newValue, listener.diff.getNewValue(model1)); - assertFalse(listener.diff.getAddedKeys().contains(model1)); - assertTrue(listener.diff.getChangedKeys().contains(model1)); - assertFalse(listener.diff.getRemovedKeys().contains(model1)); - } - - public void testAddKey() throws Exception { - MapChangeListener listener = new MapChangeListener(); - map.addMapChangeListener(listener); - - Bean model3 = new Bean("3"); - - assertEquals(0, listener.count); - set.add(model3); - assertEquals(1, listener.count); - assertTrue(listener.diff.getAddedKeys().contains(model3)); - assertEquals(model3.getValue(), map.get(model3)); - - String newValue = model3.getValue() + model3.getValue(); - model3.setValue(newValue); - assertEquals(2, listener.count); - assertEquals(3, map.size()); - } - - public void testRemoveKey() throws Exception { - MapChangeListener listener = new MapChangeListener(); - map.addMapChangeListener(listener); - - assertEquals(0, listener.count); - set.remove(model1); - assertEquals(1, listener.count); - assertFalse(listener.diff.getAddedKeys().contains(model1)); - assertFalse(listener.diff.getChangedKeys().contains(model1)); - assertTrue(listener.diff.getRemovedKeys().contains(model1)); - assertEquals(1, map.size()); - } - - public void testGetObserved() throws Exception { - assertEquals(set, map.getObserved()); - } - - public void testGetPropertyDescriptor() throws Exception { - assertEquals(propertyDescriptor, map.getPropertyDescriptor()); - } - - public void testConstructor_SkipRegisterListeners() throws Exception { - Realm realm = new CurrentRealm(true); - WritableSet set = new WritableSet(realm); - Bean bean = new Bean(); - set.add(bean); - - JavaBeanObservableMap observable = new JavaBeanObservableMap(set, new PropertyDescriptor("value", Bean.class), false); - ChangeEventTracker.observe(observable); - - assertFalse(bean.hasListeners("value")); - } - - public void testConstructor_RegistersListeners() throws Exception { - Realm realm = new CurrentRealm(true); - WritableSet set = new WritableSet(realm); - Bean bean = new Bean(); - set.add(bean); - - JavaBeanObservableMap observable = new JavaBeanObservableMap(set, new PropertyDescriptor("value", Bean.class)); - ChangeEventTracker.observe(observable); - - assertTrue(bean.hasListeners("value")); - } - - public void testFirstListenerAdded_AfterLastListenerRemoved() - throws Exception { - IMapChangeListener listener = new IMapChangeListener() { - public void handleMapChange(MapChangeEvent event) { - // noop - } - }; - map.addMapChangeListener(listener); - map.removeMapChangeListener(listener); - map.addMapChangeListener(listener); - } - - public void testDispose_DoubleInvocation() throws Exception { - map.dispose(); - map.dispose(); - } - - private static class MapChangeListener implements IMapChangeListener { - int count; - - MapDiff diff; - - public void handleMapChange(MapChangeEvent event) { - count++; - this.diff = event.diff; - } - } - - public static Test suite() { - TestSuite suite = new TestSuite(JavaBeanObservableMapTest.class.getName()); - suite.addTestSuite(JavaBeanObservableMapTest.class); - return suite; - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableSetTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableSetTest.java deleted file mode 100644 index 5bc4e44b..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableSetTest.java +++ /dev/null @@ -1,173 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007-2008 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bugs 221351, 213145, 244098, 240931 - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.beans; - -import java.beans.IntrospectionException; -import java.beans.PropertyDescriptor; -import java.util.Arrays; -import java.util.HashSet; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.ISetChangeListener; -import org.eclipse.core.databinding.observable.set.SetChangeEvent; -import org.eclipse.core.internal.databinding.beans.JavaBeanObservableSet; -import org.eclipse.jface.databinding.conformance.MutableObservableSetContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; -import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker; -import org.eclipse.jface.databinding.conformance.util.CurrentRealm; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.swt.widgets.Display; - -/** - * @since 3.3 - */ -public class JavaBeanObservableSetTest extends TestCase { - private JavaBeanObservableSet observableSet; - private Bean bean; - private PropertyDescriptor propertyDescriptor; - private String propertyName; - private SetChangeListener listener; - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - bean = new Bean(); - propertyName = "set"; - propertyDescriptor = new PropertyDescriptor(propertyName, Bean.class); - - observableSet = new JavaBeanObservableSet(SWTObservables - .getRealm(Display.getDefault()), bean, propertyDescriptor, - Bean.class); - listener = new SetChangeListener(); - } - - public void testGetObserved() throws Exception { - assertEquals(bean, observableSet.getObserved()); - } - - public void testGetPropertyDescriptor() throws Exception { - assertEquals(propertyDescriptor, observableSet.getPropertyDescriptor()); - } - - public void testGetElementType() throws Exception { - assertEquals(Bean.class, observableSet.getElementType()); - } - - public void testRegistersListenerOnCreation() throws Exception { - assertTrue(bean.changeSupport.hasListeners(propertyName)); - } - - public void testRemovesListenerOnDisposal() throws Exception { - observableSet.dispose(); - assertFalse(bean.changeSupport.hasListeners(propertyName)); - } - - public void testFiresChangeEvents() throws Exception { - observableSet.addSetChangeListener(listener); - assertEquals(0, listener.count); - bean.setSet(new HashSet(Arrays.asList(new String[] {"1"}))); - assertEquals(1, listener.count); - } - - public void testConstructor_RegisterListeners() throws Exception { - bean = new Bean(); - new JavaBeanObservableSet(new CurrentRealm(true), bean, - propertyDescriptor, Bean.class); - assertTrue(bean.hasListeners(propertyName)); - } - - public void testConstructor_SkipsRegisterListeners() throws Exception { - bean = new Bean(); - - observableSet = new JavaBeanObservableSet(new CurrentRealm(true), bean, - propertyDescriptor, Bean.class, false); - assertFalse(bean.hasListeners(propertyName)); - ChangeEventTracker.observe(observableSet); - assertFalse(bean.hasListeners(propertyName)); - } - - public void testFirstListenerAdded_AfterLastListenerRemoved() throws Exception { - ISetChangeListener listener = new ISetChangeListener() { - public void handleSetChange(SetChangeEvent event) { - // noop - } - }; - observableSet.addSetChangeListener(listener); - observableSet.removeSetChangeListener(listener); - observableSet.addSetChangeListener(listener); - } - - public void testDispose_DoubleInvocation() throws Exception { - observableSet.dispose(); - observableSet.dispose(); - } - - static class SetChangeListener implements ISetChangeListener { - int count; - public void handleSetChange(SetChangeEvent event) { - count++; - } - } - - public static Test suite() { - TestSuite suite = new TestSuite(JavaBeanObservableSetTest.class.getName()); - suite.addTestSuite(JavaBeanObservableSetTest.class); - suite.addTest(MutableObservableSetContractTest.suite(new Delegate())); - return suite; - } - - private static class Delegate extends - AbstractObservableCollectionContractDelegate { - public IObservableCollection createObservableCollection(Realm realm, - int elementCount) { - Bean bean = new Bean(); - String propertyName = "set"; - PropertyDescriptor propertyDescriptor; - try { - propertyDescriptor = new PropertyDescriptor(propertyName, - Bean.class); - } catch (IntrospectionException e) { - throw new RuntimeException(e); - } - - IObservableSet set = new JavaBeanObservableSet(realm, - bean, propertyDescriptor, String.class); - for (int i = 0; i < elementCount; i++) - set.add(createElement(set)); - return set; - } - - public Object createElement(IObservableCollection collection) { - return new Object(); - } - - public Object getElementType(IObservableCollection collection) { - return String.class; - } - - public void change(IObservable observable) { - IObservableSet set = (IObservableSet) observable; - set.add(createElement(set)); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableValueTest.java deleted file mode 100644 index 6765e7db..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableValueTest.java +++ /dev/null @@ -1,196 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Brad Reynolds - bug 171616 - * Katarzyna Marszalek - test case for bug 198519 - * Matthew Hall - bug 213145 - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.beans; - -import java.beans.IntrospectionException; -import java.beans.PropertyDescriptor; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.ChangeEvent; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.ComputedValue; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.internal.databinding.beans.JavaBeanObservableValue; -import org.eclipse.jface.databinding.conformance.MutableObservableValueContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker; -import org.eclipse.jface.examples.databinding.model.SimplePerson; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -/** - * @since 3.2 - */ -public class JavaBeanObservableValueTest extends AbstractDefaultRealmTestCase { - private Bean bean; - private JavaBeanObservableValue observableValue; - private PropertyDescriptor propertyDescriptor; - private String propertyName; - - /* (non-Javadoc) - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - - bean = new Bean(); - propertyName = "value"; - propertyDescriptor = new PropertyDescriptor(propertyName, Bean.class); - observableValue = new JavaBeanObservableValue(Realm.getDefault(), bean, propertyDescriptor); - } - - public void testGetObserved() throws Exception { - assertEquals(bean, observableValue.getObserved()); - } - - public void testGetPropertyDescriptor() throws Exception { - assertEquals(propertyDescriptor, observableValue.getPropertyDescriptor()); - } - - public void testSetValueThrowsExceptionThrownByBean() throws Exception { - ThrowsSetException temp = new ThrowsSetException(); - JavaBeanObservableValue observable = new JavaBeanObservableValue(Realm - .getDefault(), temp, - new PropertyDescriptor("value", ThrowsSetException.class)); - - try { - observable.setValue(""); - fail("exception should have been thrown"); - } catch (RuntimeException e) { - assertEquals(temp.thrownException, e.getCause()); - } - } - - public void testGetValueThrowsExceptionThrownByBean() throws Exception { - ThrowsGetException temp = new ThrowsGetException(); - JavaBeanObservableValue observable = new JavaBeanObservableValue(Realm - .getDefault(), temp, - new PropertyDescriptor("value", ThrowsGetException.class)); - - try { - observable.getValue(); - fail("exception should have been thrown"); - } catch (RuntimeException e) { - assertEquals(temp.thrownException, e.getCause()); - } - } - - public void testBug198519() { - final SimplePerson person = new SimplePerson(); - final ComputedValue cv = new ComputedValue() { - final IObservableValue name = BeansObservables.observeValue(person, "name"); //$NON-NLS-1$ - protected Object calculate() { - return Boolean.valueOf(name.getValue() != null); - } - }; - cv.addChangeListener(new IChangeListener() { - public void handleChange(ChangeEvent event) { - cv.getValue(); - } - }); - person.setName("foo"); - } - - public void testConstructor_RegistersListeners() throws Exception { - JavaBeanObservableValue observable = new JavaBeanObservableValue(Realm.getDefault(), bean, propertyDescriptor); - ChangeEventTracker.observe(observable); - - assertTrue(bean.hasListeners(propertyName)); - } - - public void testConstructor_SkipRegisterListeners() throws Exception { - JavaBeanObservableValue observable = new JavaBeanObservableValue(Realm.getDefault(), bean, propertyDescriptor, false); - ChangeEventTracker.observe(observable); - - assertFalse(bean.hasListeners(propertyName)); - } - - public static Test suite() { - TestSuite suite = new TestSuite(JavaBeanObservableValueTest.class.getName()); - suite.addTestSuite(JavaBeanObservableValueTest.class); - suite.addTest(MutableObservableValueContractTest.suite(new Delegate())); - return suite; - } - - /* package */ static class Delegate extends AbstractObservableValueContractDelegate { - private Bean bean; - - public void setUp() { - super.setUp(); - - bean = new Bean(""); - } - - public IObservableValue createObservableValue(Realm realm) { - try { - PropertyDescriptor propertyDescriptor = new PropertyDescriptor("value", Bean.class); - return new JavaBeanObservableValue(realm, bean, - propertyDescriptor); - } catch (IntrospectionException e) { - throw new RuntimeException(e); - } - } - - public void change(IObservable observable) { - IObservableValue observableValue = (IObservableValue) observable; - observableValue.setValue(createValue(observableValue)); - } - - public Object getValueType(IObservableValue observable) { - return String.class; - } - - public Object createValue(IObservableValue observable) { - return observable.getValue() + "a"; - } - } - - /** - * Throws an exception when the value is set. - * - * @since 3.2 - */ - /* package */class ThrowsSetException { - private String value; - - /* package */NullPointerException thrownException; - - public void setValue(String value) { - throw thrownException = new NullPointerException(); - } - - public String getValue() { - return value; - } - } - - /* package */class ThrowsGetException { - public String value; - - /* package */NullPointerException thrownException; - - public String getValue() { - throw thrownException = new NullPointerException(); - } - - public void setValue(String value) { - this.value = value; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanPropertyObservableMapTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanPropertyObservableMapTest.java deleted file mode 100644 index ddcfc9a0..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanPropertyObservableMapTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 240931) - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.beans; - -import java.beans.PropertyDescriptor; -import java.util.HashMap; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.map.IMapChangeListener; -import org.eclipse.core.databinding.observable.map.MapChangeEvent; -import org.eclipse.core.internal.databinding.beans.JavaBeanPropertyObservableMap; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -/** - * @since 3.2 - * - */ -public class JavaBeanPropertyObservableMapTest extends - AbstractDefaultRealmTestCase { - private JavaBeanPropertyObservableMap map; - - private PropertyDescriptor propertyDescriptor; - - private Bean bean; - - private String propertyName; - - protected void setUp() throws Exception { - super.setUp(); - - propertyName = "map"; - propertyDescriptor = new PropertyDescriptor(propertyName, Bean.class); - bean = new Bean(new HashMap()); - - map = new JavaBeanPropertyObservableMap(Realm.getDefault(), bean, - propertyDescriptor); - } - - public void testFirstListenerAdded_AfterLastListenerRemoved() - throws Exception { - IMapChangeListener listener = new IMapChangeListener() { - public void handleMapChange(MapChangeEvent event) { - // noop - } - }; - map.addMapChangeListener(listener); - map.removeMapChangeListener(listener); - map.addMapChangeListener(listener); - } - - public void testDispose_DoubleInvocation() throws Exception { - map.dispose(); - map.dispose(); - } - - public static Test suite() { - TestSuite suite = new TestSuite(JavaBeanPropertyObservableMapTest.class - .getName()); - suite.addTestSuite(JavaBeanPropertyObservableMapTest.class); - return suite; - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/ListenerSupportTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/ListenerSupportTest.java deleted file mode 100644 index b55271ae..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/ListenerSupportTest.java +++ /dev/null @@ -1,231 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.beans; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.util.Arrays; - -import org.eclipse.core.databinding.util.ILogger; -import org.eclipse.core.databinding.util.Policy; -import org.eclipse.core.internal.databinding.beans.ListenerSupport; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -/** - * @since 1.1 - */ -public class ListenerSupportTest extends AbstractDefaultRealmTestCase { - private PropertyChangeListenerStub listener; - private String propertyName; - - protected void setUp() throws Exception { - super.setUp(); - - listener = new PropertyChangeListenerStub(); - propertyName = "value"; - } - - public void testAddPropertyChangeListenerWithPropertyName() - throws Exception { - SpecificListenerBean bean = new SpecificListenerBean(); - - ListenerSupport support = new ListenerSupport(listener, propertyName); - assertFalse(bean.changeSupport.hasListeners(propertyName)); - assertNull(support.getHookedTargets()); - - support.hookListener(bean); - assertTrue("has listeners", bean.changeSupport.hasListeners(propertyName)); - assertTrue("hooked target", Arrays.asList(support.getHookedTargets()).contains(bean)); - } - - public void testAddPropertyChangeListenerWithoutPropertyName() - throws Exception { - GenericListenerBean bean = new GenericListenerBean(); - - ListenerSupport support = new ListenerSupport(listener, propertyName); - assertFalse(bean.changeSupport.hasListeners(propertyName)); - assertNull(support.getHookedTargets()); - - support.hookListener(bean); - assertTrue("has listeners", bean.changeSupport.hasListeners(propertyName)); - assertTrue("hooked target", Arrays.asList(support.getHookedTargets()).contains(bean)); - } - - public void testChangeListenerIsOnlyNotifiedWhenWatchedPropertyChanges() - throws Exception { - GenericListenerBean bean = new GenericListenerBean(); - ListenerSupport support = new ListenerSupport(listener, propertyName); - support.hookListener(bean); - - assertEquals(0, listener.count); - bean.setValue("1"); - assertEquals(1, listener.count); - assertEquals("value", listener.event.getPropertyName()); - - bean.setOther("2"); - assertEquals(1, listener.count); - } - - public void testLogStatusWhenAddPropertyChangeListenerMethodIsNotFound() - throws Exception { - class BeanStub { - } - - class Log implements ILogger { - int count; - IStatus status; - - public void log(IStatus status) { - count++; - this.status = status; - } - } - - Log log = new Log(); - Policy.setLog(log); - - ListenerSupport support = new ListenerSupport(listener, "value"); - BeanStub bean = new BeanStub(); - - assertEquals(0, log.count); - support.hookListener(bean); - assertEquals(1, log.count); - assertEquals(IStatus.WARNING, log.status.getSeverity()); - } - - public void testRemovePropertyChangeListenerWithPropertyName() - throws Exception { - SpecificListenerBean bean = new SpecificListenerBean(); - ListenerSupport support = new ListenerSupport(listener, propertyName); - support.hookListener(bean); - - assertTrue(bean.changeSupport.hasListeners(propertyName)); - assertTrue(Arrays.asList(support.getHookedTargets()).contains(bean)); - - support.unhookListener(bean); - assertFalse("has listeners", bean.changeSupport.hasListeners(propertyName)); - assertNull("unhooked target", support.getHookedTargets()); - } - - public void testRemovePropertyChangeListenerWithoutPropertyName() - throws Exception { - GenericListenerBean bean = new GenericListenerBean(); - ListenerSupport support = new ListenerSupport(listener, propertyName); - support.hookListener(bean); - - assertTrue(bean.changeSupport.hasListeners(propertyName)); - assertTrue(Arrays.asList(support.getHookedTargets()).contains(bean)); - - support.unhookListener(bean); - assertFalse("has listeners", bean.changeSupport.hasListeners(propertyName)); - assertNull("unhooked target", support.getHookedTargets()); - } - - public void testLogStatusWhenRemovePropertyChangeListenerMethodIsNotFound() - throws Exception { - class InvalidBean { - } - - class Log implements ILogger { - int count; - IStatus status; - - public void log(IStatus status) { - count++; - this.status = status; - } - } - - Log log = new Log(); - Policy.setLog(log); - - ListenerSupport support = new ListenerSupport(listener, "value"); - InvalidBean bean = new InvalidBean(); - - support.hookListener(bean); - log.count = 0; - log.status = null; - assertEquals(0, log.count); - support.unhookListener(bean); - assertEquals(1, log.count); - assertEquals(IStatus.WARNING, log.status.getSeverity()); - } - - static class GenericListenerBean { - private String other; - PropertyChangeSupport changeSupport = new PropertyChangeSupport(this); - private String value; - - public String getValue() { - return value; - } - - public void setValue(String value) { - changeSupport.firePropertyChange("value", this.value, - this.value = value); - } - - public String getOther() { - return other; - } - - public void setOther(String other) { - changeSupport.firePropertyChange("other", this.other, - this.other = other); - } - - public void addPropertyChangeListener(PropertyChangeListener listener) { - changeSupport.addPropertyChangeListener(listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - changeSupport.removePropertyChangeListener(listener); - } - } - - static class SpecificListenerBean { - PropertyChangeSupport changeSupport = new PropertyChangeSupport(this); - String propertyName; - String value; - - public void addPropertyChangeListener(String name, - PropertyChangeListener listener) { - this.propertyName = name; - changeSupport.addPropertyChangeListener(name, listener); - } - - public void removePropertyChangeListener(String name, - PropertyChangeListener listener) { - changeSupport.removePropertyChangeListener(name, listener); - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } - } - - static class PropertyChangeListenerStub implements PropertyChangeListener { - PropertyChangeEvent event; - int count; - - public void propertyChange(PropertyChangeEvent evt) { - count++; - this.event = evt; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/DateConversionSupportTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/DateConversionSupportTest.java deleted file mode 100644 index 5e66de40..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/DateConversionSupportTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.conversion; - -import junit.framework.TestCase; - -import org.eclipse.core.internal.databinding.BindingMessages; -import org.eclipse.core.internal.databinding.conversion.DateConversionSupport; - -import com.ibm.icu.text.DateFormat; -import com.ibm.icu.text.SimpleDateFormat; - -/** - * @since 1.1 - */ -public class DateConversionSupportTest extends TestCase { - public void testDatePatternIsExternalized() throws Exception { - StubConverter stub = new StubConverter(); - String key = "DateFormat_DateTime"; - String format = BindingMessages.getString(key); - - assertFalse("format is defined", key.equals(format)); - SimpleDateFormat dateFormat = (SimpleDateFormat) stub.getDateFormat(0); - assertEquals(format, dateFormat.toPattern()); - } - - public void testTimePatternIsExternalized() throws Exception { - StubConverter stub = new StubConverter(); - String key = "DateFormat_Time"; - String format = BindingMessages.getString(key); - - assertFalse("format is defined", key.equals(format)); - SimpleDateFormat dateFormat = (SimpleDateFormat) stub.getDateFormat(1); - assertEquals(format, dateFormat.toPattern()); - } - - static class StubConverter extends DateConversionSupport { - protected DateFormat getDateFormat(int index) { - return super.getDateFormat(index); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/IdentityConverterTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/IdentityConverterTest.java deleted file mode 100755 index 80761839..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/IdentityConverterTest.java +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 116920 - * Matt Carter - bug 197679 - *******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.conversion; - -import junit.framework.TestCase; - -import org.eclipse.core.databinding.BindingException; -import org.eclipse.core.internal.databinding.conversion.IdentityConverter; - -/** - * @since 3.2 - * - */ -public class IdentityConverterTest extends TestCase { - - private IdentityConverter c; - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - c = new IdentityConverter(Integer.TYPE, Integer.TYPE); - } - - public void testIsPrimitiveTypeMatchedWithBoxed() throws Exception { - assertTrue(c.isPrimitiveTypeMatchedWithBoxed(Integer.class, - Integer.TYPE)); - assertTrue(c.isPrimitiveTypeMatchedWithBoxed(Integer.TYPE, - Integer.class)); - - assertTrue(c.isPrimitiveTypeMatchedWithBoxed(Byte.class, Byte.TYPE)); - assertTrue(c.isPrimitiveTypeMatchedWithBoxed(Byte.TYPE, Byte.class)); - - assertTrue(c.isPrimitiveTypeMatchedWithBoxed(Short.class, Short.TYPE)); - assertTrue(c.isPrimitiveTypeMatchedWithBoxed(Short.TYPE, Short.class)); - - assertTrue(c.isPrimitiveTypeMatchedWithBoxed(Long.class, Long.TYPE)); - assertTrue(c.isPrimitiveTypeMatchedWithBoxed(Long.TYPE, Long.class)); - - assertTrue(c.isPrimitiveTypeMatchedWithBoxed(Float.class, Float.TYPE)); - assertTrue(c.isPrimitiveTypeMatchedWithBoxed(Float.TYPE, Float.class)); - - assertTrue(c.isPrimitiveTypeMatchedWithBoxed(Double.class, Double.TYPE)); - assertTrue(c.isPrimitiveTypeMatchedWithBoxed(Double.TYPE, Double.class)); - - assertTrue(c.isPrimitiveTypeMatchedWithBoxed(Boolean.class, - Boolean.TYPE)); - assertTrue(c.isPrimitiveTypeMatchedWithBoxed(Boolean.TYPE, - Boolean.class)); - - assertTrue(c.isPrimitiveTypeMatchedWithBoxed(Character.class, - Character.TYPE)); - assertTrue(c.isPrimitiveTypeMatchedWithBoxed(Character.TYPE, - Character.class)); - - assertFalse(c.isPrimitiveTypeMatchedWithBoxed(Boolean.class, - Integer.TYPE)); - } - - public void testConvert_NullToPrimitive() { - IdentityConverter p2b = new IdentityConverter(Float.TYPE, Float.TYPE); - try { - p2b.convert(null); - fail("Should have thrown an exception"); - } catch (BindingException b) { - // success - } - } - - public void testConvert_PrimitiveToBoxed() throws Exception { - IdentityConverter p2b = new IdentityConverter(Float.TYPE, Float.class); - assertEquals("4.2", new Float(4.2), p2b.convert(new Float(4.2))); - } - - public void testConvert_BoxedToPrimitive() throws Exception { - IdentityConverter p2b = new IdentityConverter(Float.class, Float.TYPE); - assertEquals("4.2", new Float(4.2), p2b.convert(new Float(4.2))); - } - - public void testConvert_PrimitiveToPrimitive() throws Exception { - IdentityConverter p2b = new IdentityConverter(Float.TYPE, Float.TYPE); - assertEquals("4.2", new Float(4.2), p2b.convert(new Float(4.2))); - } - - public void testConvert_BoxedToBoxed() throws Exception { - IdentityConverter p2b = new IdentityConverter(Float.class, Float.class); - assertEquals("4.2", new Float(4.2), p2b.convert(new Float(4.2))); - } - - public static class Person { - public String foo = "blah"; - } - - public static class Animal { - public String name = "fido"; - } - - public void test_Convert_ValidAssignment() throws Exception { - IdentityConverter pc = new IdentityConverter(Object.class, Person.class); - Person orig = new Person(); - Object person = pc.convert(orig); - assertTrue("Person class", person.getClass().equals(Person.class)); - assertTrue("Need correct Person", person.equals(orig)); - } - - public void test_Convert_ValidAssignment2() throws Exception { - IdentityConverter pc = new IdentityConverter(Person.class, Object.class); - Person orig = new Person(); - Object person = pc.convert(orig); - assertTrue("Person class", person.getClass().equals(Person.class)); - assertTrue("Need correct Person", person.equals(orig)); - } - - public void testConvert_InvalidAssignment() throws Exception { - IdentityConverter pc = new IdentityConverter(Object.class, Person.class); - try { - pc.convert(new Animal()); - fail("Should have gotten an exception"); - } catch (Exception e) { - // success - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/IntegerToStringConverterTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/IntegerToStringConverterTest.java deleted file mode 100644 index a86de2da..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/IntegerToStringConverterTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.conversion; - -import junit.framework.TestCase; - -import org.eclipse.core.internal.databinding.conversion.IntegerToStringConverter; - -import com.ibm.icu.text.NumberFormat; - -/** - * @since 1.1 - */ -public class IntegerToStringConverterTest extends TestCase { - private NumberFormat integerFormat; - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - - integerFormat = NumberFormat.getIntegerInstance(); - } - - public void testFromTypeShort() throws Exception { - assertEquals(Short.class, IntegerToStringConverter.fromShort(false) - .getFromType()); - assertEquals(Short.TYPE, IntegerToStringConverter.fromShort(true) - .getFromType()); - assertEquals(Byte.class, IntegerToStringConverter.fromByte(false) - .getFromType()); - assertEquals(Byte.TYPE, IntegerToStringConverter.fromByte(true) - .getFromType()); - } - - public void testToTypeIsStringClass() throws Exception { - assertEquals(String.class, IntegerToStringConverter.fromShort(false) - .getToType()); - } - - public void testConvertShortToString() throws Exception { - Short value = new Short((short) 1); - String expected = integerFormat.format(value); - - IntegerToStringConverter converter = IntegerToStringConverter - .fromShort(integerFormat, false); - String result = (String) converter.convert(value); - assertEquals(expected, result); - } - - public void testConvertByteToString() throws Exception { - Byte value = new Byte((byte) 1); - String expected = integerFormat.format(value); - - IntegerToStringConverter converter = IntegerToStringConverter.fromByte( - integerFormat, false); - String result = (String) converter.convert(value); - assertEquals(expected, result); - } - - public void testNullSourceConvertsToEmptyString() throws Exception { - IntegerToStringConverter converter = IntegerToStringConverter - .fromByte(false); - assertEquals("", converter.convert(null)); - } - - public void testIllegalArgumentExceptionIfSourceIsNotExpectedType() throws Exception { - IntegerToStringConverter converter = IntegerToStringConverter.fromByte(false); - try { - converter.convert(new Integer(1)); - fail("exception should have been thrown"); - } catch (IllegalArgumentException e) { - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/NumberToBigDecimalTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/NumberToBigDecimalTest.java deleted file mode 100644 index 9cdabd91..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/NumberToBigDecimalTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.conversion; - -import java.math.BigDecimal; - -import org.eclipse.core.databinding.conversion.IConverter; -import org.eclipse.core.internal.databinding.conversion.NumberToBigDecimalConverter; - -import com.ibm.icu.text.NumberFormat; - -/** - * @since 1.1 - */ -public class NumberToBigDecimalTest extends NumberToNumberTestHarness { - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.NumberToNumberTestHarness#doGetOutOfRangeNumber() - */ - protected Number doGetOutOfRangeNumber() { - return null; //does not exist - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.NumberToNumberTestHarness#doGetToBoxedTypeValidator(java.lang.Class) - */ - protected IConverter doGetToBoxedTypeValidator(Class fromType) { - return new NumberToBigDecimalConverter(NumberFormat.getInstance(), fromType); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.NumberToNumberTestHarness#doGetToPrimitiveValidator(java.lang.Class) - */ - protected IConverter doGetToPrimitiveValidator(Class fromType) { - return null; // does not exist - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.NumberToNumberTestHarness#doGetToType(boolean) - */ - protected Class doGetToType(boolean primitive) { - return (primitive) ? null : BigDecimal.class; - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/NumberToBigIntegerConverterTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/NumberToBigIntegerConverterTest.java deleted file mode 100644 index 2d41a6a8..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/NumberToBigIntegerConverterTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.conversion; - -import java.math.BigInteger; - -import org.eclipse.core.databinding.conversion.IConverter; -import org.eclipse.core.internal.databinding.conversion.NumberToBigIntegerConverter; - -import com.ibm.icu.text.NumberFormat; - -/** - * @since 1.1 - */ -public class NumberToBigIntegerConverterTest extends NumberToNumberTestHarness { - private NumberFormat numberFormat; - - /* (non-Javadoc) - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.NumberToNumberTestHarness#doGetOutOfRangeNumber() - */ - protected Number doGetOutOfRangeNumber() { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.NumberToNumberTestHarness#doGetToBoxedTypeValidator(java.lang.Class) - */ - protected IConverter doGetToBoxedTypeValidator(Class fromType) { - return new NumberToBigIntegerConverter(numberFormat, fromType); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.NumberToNumberTestHarness#doGetToPrimitiveValidator(java.lang.Class) - */ - protected IConverter doGetToPrimitiveValidator(Class fromType) { - return null; //no such thing - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.NumberToNumberTestHarness#doGetToType(boolean) - */ - protected Class doGetToType(boolean primitive) { - return (primitive) ? null : BigInteger.class; - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/NumberToByteConverterTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/NumberToByteConverterTest.java deleted file mode 100644 index 551b6844..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/NumberToByteConverterTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.conversion; - -import org.eclipse.core.databinding.conversion.IConverter; -import org.eclipse.core.internal.databinding.conversion.NumberToByteConverter; - -import com.ibm.icu.text.NumberFormat; - -/** - * @since 1.1 - */ -public class NumberToByteConverterTest extends NumberToNumberTestHarness { - private NumberFormat numberFormat; - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - - numberFormat = NumberFormat.getInstance(); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.NumberToNumberTestHarness#doGetOutOfRangeNumber() - */ - protected Number doGetOutOfRangeNumber() { - return new Integer(Byte.MAX_VALUE + 1); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.NumberToNumberTestHarness#doGetToBoxedTypeValidator(java.lang.Class) - */ - protected IConverter doGetToBoxedTypeValidator(Class fromType) { - return new NumberToByteConverter(numberFormat, fromType, false); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.NumberToNumberTestHarness#doGetToPrimitiveValidator(java.lang.Class) - */ - protected IConverter doGetToPrimitiveValidator(Class fromType) { - return new NumberToByteConverter(numberFormat, fromType, true); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.NumberToNumberTestHarness#doGetToType() - */ - protected Class doGetToType(boolean primitive) { - return (primitive) ? Byte.TYPE : Byte.class; - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/NumberToDoubleConverterTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/NumberToDoubleConverterTest.java deleted file mode 100644 index 2a5a4806..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/NumberToDoubleConverterTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.conversion; - -import java.math.BigDecimal; - -import org.eclipse.core.databinding.conversion.IConverter; -import org.eclipse.core.internal.databinding.conversion.NumberToDoubleConverter; - -import com.ibm.icu.text.NumberFormat; - -/** - * @since 1.1 - */ -public class NumberToDoubleConverterTest extends NumberToNumberTestHarness { - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.NumberToNumberTestHarness#doGetOutOfRangeNumber() - */ - protected Number doGetOutOfRangeNumber() { - return new BigDecimal(Double.MAX_VALUE).add(new BigDecimal(Double.MAX_VALUE)); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.NumberToNumberTestHarness#doGetToBoxedTypeValidator(java.lang.Class) - */ - protected IConverter doGetToBoxedTypeValidator(Class fromType) { - return new NumberToDoubleConverter(NumberFormat.getInstance(), fromType, false); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.NumberToNumberTestHarness#doGetToPrimitiveValidator(java.lang.Class) - */ - protected IConverter doGetToPrimitiveValidator(Class fromType) { - return new NumberToDoubleConverter(NumberFormat.getInstance(), fromType, true); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.NumberToNumberTestHarness#doGetToType(boolean) - */ - protected Class doGetToType(boolean primitive) { - return (primitive) ? Double.TYPE : Double.class; - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/NumberToFloatConverterTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/NumberToFloatConverterTest.java deleted file mode 100644 index 17752f6e..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/NumberToFloatConverterTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.conversion; - -import org.eclipse.core.databinding.conversion.IConverter; -import org.eclipse.core.internal.databinding.conversion.NumberToFloatConverter; - -import com.ibm.icu.text.NumberFormat; - -/** - * @since 1.1 - */ -public class NumberToFloatConverterTest extends NumberToNumberTestHarness { - private NumberFormat numberFormat; - - /* (non-Javadoc) - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - - numberFormat = NumberFormat.getInstance(); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.NumberToNumberTestHarness#doGetOutOfRangeNumber() - */ - protected Number doGetOutOfRangeNumber() { - return new Double(Double.MAX_VALUE); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.NumberToNumberTestHarness#doGetToBoxedTypeValidator(java.lang.Class) - */ - protected IConverter doGetToBoxedTypeValidator(Class fromType) { - return new NumberToFloatConverter(numberFormat, fromType, false); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.NumberToNumberTestHarness#doGetToPrimitiveValidator(java.lang.Class) - */ - protected IConverter doGetToPrimitiveValidator(Class fromType) { - return new NumberToFloatConverter(numberFormat, fromType, true); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.NumberToNumberTestHarness#doGetToType(boolean) - */ - protected Class doGetToType(boolean primitive) { - return (primitive) ? Float.TYPE : Float.class; - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/NumberToIntegerConverterTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/NumberToIntegerConverterTest.java deleted file mode 100644 index 07346772..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/NumberToIntegerConverterTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.conversion; - -import org.eclipse.core.databinding.conversion.IConverter; -import org.eclipse.core.internal.databinding.conversion.NumberToIntegerConverter; - -import com.ibm.icu.text.NumberFormat; - -/** - * @since 1.1 - */ -public class NumberToIntegerConverterTest extends NumberToNumberTestHarness { - private NumberFormat numberFormat; - - /* (non-Javadoc) - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - - numberFormat = NumberFormat.getInstance(); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.NumberToNumberTestHarness#doGetOutOfRangeNumber() - */ - protected Number doGetOutOfRangeNumber() { - return new Long((long) Integer.MAX_VALUE + 1); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.NumberToNumberTestHarness#doGetToBoxedTypeValidator(java.lang.Class) - */ - protected IConverter doGetToBoxedTypeValidator(Class fromType) { - return new NumberToIntegerConverter(numberFormat, fromType, false); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.NumberToNumberTestHarness#doGetToPrimitiveValidator(java.lang.Class) - */ - protected IConverter doGetToPrimitiveValidator(Class fromType) { - return new NumberToIntegerConverter(numberFormat, fromType, true); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.NumberToNumberTestHarness#doGetToType(boolean) - */ - protected Class doGetToType(boolean primitive) { - return (primitive) ? Integer.TYPE : Integer.class; - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/NumberToLongConverterTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/NumberToLongConverterTest.java deleted file mode 100644 index aff8120b..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/NumberToLongConverterTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.conversion; - -import org.eclipse.core.databinding.conversion.IConverter; -import org.eclipse.core.internal.databinding.conversion.NumberToLongConverter; - -import com.ibm.icu.text.NumberFormat; - -/** - * @since 1.1 - */ -public class NumberToLongConverterTest extends NumberToNumberTestHarness { - private NumberFormat numberFormat; - - /* (non-Javadoc) - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - - numberFormat = NumberFormat.getInstance(); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.NumberToNumberTestHarness#doGetOutOfRangeNumber() - */ - protected Number doGetOutOfRangeNumber() { - return new Double(Double.MAX_VALUE); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.NumberToNumberTestHarness#doGetToBoxedTypeValidator(java.lang.Class) - */ - protected IConverter doGetToBoxedTypeValidator(Class fromType) { - return new NumberToLongConverter(numberFormat, fromType, false); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.NumberToNumberTestHarness#doGetToPrimitiveValidator(java.lang.Class) - */ - protected IConverter doGetToPrimitiveValidator(Class fromType) { - return new NumberToLongConverter(numberFormat, fromType, true); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.NumberToNumberTestHarness#doGetToType(boolean) - */ - protected Class doGetToType(boolean primitive) { - return (primitive) ? Long.TYPE : Long.class; - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/NumberToNumberTestHarness.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/NumberToNumberTestHarness.java deleted file mode 100644 index d6373b35..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/NumberToNumberTestHarness.java +++ /dev/null @@ -1,131 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.conversion; - -import junit.framework.TestCase; - -import org.eclipse.core.databinding.conversion.IConverter; - -/** - * @since 1.1 - */ -public abstract class NumberToNumberTestHarness extends TestCase { - - /** - * Invoked when a to primitive validator is needed. - * - * @param fromType - * @return validator, <code>null</code> if the type does not have a primitive form - */ - protected abstract IConverter doGetToPrimitiveValidator(Class fromType); - - /** - * Invoked when a to boxed validator is needed. - * - * @param fromType - * @return - */ - protected abstract IConverter doGetToBoxedTypeValidator(Class fromType); - - /** - * Invoked when the type is needed. - * - * @param primitive - * @return type, <code>null</code> if the type does not have a primitive form - */ - protected abstract Class doGetToType(boolean primitive); - - /** - * Invoked when an out of range number is needed to use for conversion. - * - * @return out of range number of <code>null</code> if the type has no bounds - */ - protected abstract Number doGetOutOfRangeNumber(); - - public void testFromType() throws Exception { - Class from = Integer.class; - assertEquals(from, doGetToBoxedTypeValidator(from).getFromType()); - } - - public void testToTypeIsPrimitive() throws Exception { - Class toType = doGetToType(true); - - if (toType == null) { - //return if there is no primitive type - return; - } - assertEquals("to type was not of the correct type", toType, doGetToPrimitiveValidator(Integer.class) - .getToType()); - assertTrue("to type was not primitive", toType.isPrimitive()); - } - - public void testToTypeIsBoxedType() throws Exception { - Class toType = doGetToType(false); - assertEquals(toType, doGetToBoxedTypeValidator(Integer.class) - .getToType()); - assertFalse(toType.isPrimitive()); - } - - public void testValidConversion() throws Exception { - Integer value = new Integer(1); - Number result = (Number) doGetToBoxedTypeValidator(Integer.class) - .convert(value); - - assertNotNull("result was null", result); - - // regardless if the converter is for the primitive value the returned - // value will be the boxed type - assertEquals(doGetToType(false), result.getClass()); - assertEquals(value, new Integer(result.intValue())); - } - - public void testOutOfRangeConversion() throws Exception { - Number outOfRange = doGetOutOfRangeNumber(); - - if (outOfRange == null) { - //the number does not have bounds (e.g. BigInteger or BigDecimal) - return; - } - try { - doGetToBoxedTypeValidator(Integer.class).convert(outOfRange); - fail("exception should have been thrown"); - } catch (IllegalArgumentException e) { - } - } - - public void testConvertNullValueForPrimitiveThrowsIllegalArgumentException() - throws Exception { - if (doGetToType(true) == null) { - //return if primitive is not supported - - return; - } - - try { - doGetToPrimitiveValidator(Integer.class).convert(null); - fail("exception should have been thrown"); - } catch (IllegalArgumentException e) { - } - } - - public void testConvertNullValueForBoxedTypeReturnsNull() throws Exception { - assertNull(doGetToBoxedTypeValidator(Integer.class).convert(null)); - } - - public void testNonNumberThrowsIllegalArgumentException() throws Exception { - try { - doGetToBoxedTypeValidator(Integer.class).convert(""); - fail("exception should have been thrown"); - } catch (IllegalArgumentException e) { - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/NumberToShortConverterTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/NumberToShortConverterTest.java deleted file mode 100644 index 4c00cfc9..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/NumberToShortConverterTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.conversion; - -import org.eclipse.core.databinding.conversion.IConverter; -import org.eclipse.core.internal.databinding.conversion.NumberToShortConverter; - -import com.ibm.icu.text.NumberFormat; - -/** - * @since 1.1 - */ -public class NumberToShortConverterTest extends NumberToNumberTestHarness { - private NumberFormat numberFormat; - - /* (non-Javadoc) - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - - numberFormat = NumberFormat.getInstance(); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.NumberToNumberTestHarness#doGetOutOfRangeNumber() - */ - protected Number doGetOutOfRangeNumber() { - return new Integer(Short.MAX_VALUE + 1); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.NumberToNumberTestHarness#doGetToBoxedTypeValidator(java.lang.Class) - */ - protected IConverter doGetToBoxedTypeValidator(Class fromType) { - return new NumberToShortConverter(numberFormat, fromType, false); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.NumberToNumberTestHarness#doGetToPrimitiveValidator(java.lang.Class) - */ - protected IConverter doGetToPrimitiveValidator(Class fromType) { - return new NumberToShortConverter(numberFormat, fromType, true); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.NumberToNumberTestHarness#doGetToType(boolean) - */ - protected Class doGetToType(boolean primitive) { - return (primitive) ? Short.TYPE : Short.class; - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/ObjectToPrimitiveValidatorTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/ObjectToPrimitiveValidatorTest.java deleted file mode 100755 index 9fbfb831..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/ObjectToPrimitiveValidatorTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.conversion; - -import junit.framework.TestCase; - -import org.eclipse.core.internal.databinding.validation.ObjectToPrimitiveValidator; -import org.eclipse.core.runtime.IStatus; - -/** - * @since 3.2 - * - */ -public class ObjectToPrimitiveValidatorTest extends TestCase { - - private ObjectToPrimitiveValidator objectToPrimitiveValidator; - - protected void setUp() throws Exception { - this.objectToPrimitiveValidator = new ObjectToPrimitiveValidator( - Integer.TYPE); - } - - /** - * Test method for - * {@link org.eclipse.jface.internal.databinding.provisional.validation.ObjectToPrimitiveValidator#isValid(java.lang.Object)}. - */ - public void testIsValid() { - IStatus result = this.objectToPrimitiveValidator.validate(null); - assertEquals("The wrong validation error was found.", result - .getMessage(), this.objectToPrimitiveValidator.getNullHint()); - - result = this.objectToPrimitiveValidator.validate(new Integer(1)); - assertTrue("No validation error should be found.", result.isOK()); - - result = this.objectToPrimitiveValidator.validate(new Object()); - assertEquals("The wrong validation error was found.", result - .getMessage(), this.objectToPrimitiveValidator.getClassHint()); - } - -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StatusToStringConverterTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StatusToStringConverterTest.java deleted file mode 100644 index 51bb8729..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StatusToStringConverterTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.conversion; - -import junit.framework.TestCase; - -import org.eclipse.core.databinding.validation.ValidationStatus; -import org.eclipse.core.internal.databinding.conversion.StatusToStringConverter; -import org.eclipse.core.runtime.IStatus; - -/** - * @since 1.1 - */ -public class StatusToStringConverterTest extends TestCase { - private StatusToStringConverter converter; - - /* (non-Javadoc) - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - - converter = new StatusToStringConverter(); - } - - public void testConvertedValueIsMessageOfStatus() throws Exception { - String message = "this is my message"; - IStatus status = ValidationStatus.error(message); - assertEquals(message, converter.convert(status)); - } - - public void testFromTypeIsIStatus() throws Exception { - assertEquals(IStatus.class, converter.getFromType()); - } - - public void testToTypeIsString() throws Exception { - assertEquals(String.class, converter.getToType()); - } - - public void testIllegalArgumentExceptionIsThrownWithNullInput() throws Exception { - try { - converter.convert(null); - fail(); - } catch (IllegalArgumentException e) { - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToBooleanConverterTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToBooleanConverterTest.java deleted file mode 100644 index b1534ec6..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToBooleanConverterTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.conversion; - -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.StringTokenizer; - -import junit.framework.TestCase; -import junit.framework.TestResult; - -import org.eclipse.core.internal.databinding.BindingMessages; -import org.eclipse.core.internal.databinding.conversion.StringToBooleanConverter; - -/** - * @since 1.1 - */ -public class StringToBooleanConverterTest extends TestCase { - private StringToBooleanConverter converter; - - private List trueValues; - - private List falseValues; - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#run(junit.framework.TestResult) - */ - public void run(TestResult result) { - trueValues = Collections.unmodifiableList(toValues(BindingMessages - .getString("ValueDelimiter"), BindingMessages - .getString("TrueStringValues"))); - falseValues = Collections.unmodifiableList(toValues(BindingMessages - .getString("ValueDelimiter"), BindingMessages - .getString("FalseStringValues"))); - - super.run(result); - } - - private List toValues(String delimiter, String values) { - StringTokenizer tokenizer = new StringTokenizer(values, delimiter); - List result = new LinkedList(); - - while (tokenizer.hasMoreTokens()) { - result.add(tokenizer.nextToken()); - } - - return result; - } - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - - converter = new StringToBooleanConverter(); - assertTrue(trueValues.size() > 0); - assertTrue(falseValues.size() > 0); - } - - public void testConvertsToTrue() throws Exception { - Boolean result = (Boolean) converter.convert(trueValues.get(0)); - assertTrue(result.booleanValue()); - } - - public void testConvertsToFalse() throws Exception { - Boolean result = (Boolean) converter.convert(falseValues.get(0)); - assertFalse(result.booleanValue()); - } - - public void testUpperCaseStringConvertsToTrue() throws Exception { - Boolean result = (Boolean) converter.convert(((String) trueValues.get(0)) - .toUpperCase()); - assertTrue(result.booleanValue()); - } - - public void testUpperCaseStringConvertsToFalse() throws Exception { - Boolean result = (Boolean) converter.convert(((String) falseValues.get(0)) - .toUpperCase()); - assertFalse(result.booleanValue()); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToByteConverterTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToByteConverterTest.java deleted file mode 100644 index 1c614680..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToByteConverterTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.conversion; - -import junit.framework.TestCase; - -import org.eclipse.core.internal.databinding.conversion.StringToByteConverter; - -import com.ibm.icu.text.NumberFormat; - -/** - * @since 1.1 - */ -public class StringToByteConverterTest extends TestCase { - private NumberFormat numberFormat; - private StringToByteConverter converter; - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - numberFormat = NumberFormat.getIntegerInstance(); - converter = StringToByteConverter.toByte(numberFormat, false); - } - - public void testConvertsToByte() throws Exception { - Byte value = new Byte((byte) 1); - Byte result = (Byte) converter.convert(numberFormat.format(value)); - - assertEquals(value, result); - } - - public void testConvertsToBytePrimitive() throws Exception { - converter = StringToByteConverter.toByte(numberFormat, true); - Byte value = new Byte((byte) 1); - Byte result = (Byte) converter.convert(numberFormat.format(value)); - assertEquals(value, result); - } - - public void testFromTypeIsString() throws Exception { - assertEquals(String.class, converter.getFromType()); - } - - public void testToTypeIsShort() throws Exception { - assertEquals(Byte.class, converter.getToType()); - } - - public void testToTypeIsBytePrimitive() throws Exception { - converter = StringToByteConverter.toByte(true); - assertEquals(Byte.TYPE, converter.getToType()); - } - - public void testReturnsNullBoxedTypeForEmptyString() throws Exception { - assertNull(converter.convert("")); - } - - public void testThrowsIllegalArgumentExceptionIfAskedToConvertNonString() - throws Exception { - try { - converter.convert(new Integer(1)); - fail("exception should have been thrown"); - } catch (IllegalArgumentException e) { - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToCharacterConverterTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToCharacterConverterTest.java deleted file mode 100644 index 21250dfc..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToCharacterConverterTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * Copyright (c) Matt Carter 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: - * Matt Carter - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.conversion; - -import junit.framework.TestCase; - -import org.eclipse.core.internal.databinding.conversion.StringToCharacterConverter; - -/** - * @since 1.1 - */ -public class StringToCharacterConverterTest extends TestCase { - - private StringToCharacterConverter converter; - private StringToCharacterConverter primitiveConverter; - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - converter = StringToCharacterConverter.toCharacter(false); - primitiveConverter = StringToCharacterConverter.toCharacter(true); - } - - public void testConvertsToCharacter() throws Exception { - Character value = new Character('X'); - Character result = (Character) converter.convert(Character - .toString(value.charValue())); - - assertEquals(value, result); - } - - public void testConvertsToCharacterPrimitive() throws Exception { - Character value = new Character('Y'); - Character result = (Character) primitiveConverter.convert(String - .valueOf(value.charValue())); - assertEquals(value, result); - } - - public void testFromTypeIsString() throws Exception { - assertEquals(String.class, converter.getFromType()); - } - - public void testToTypeIsCharacter() throws Exception { - assertEquals(Character.class, converter.getToType()); - } - - public void testToTypeIsCharacterPrimitive() throws Exception { - assertEquals(Character.TYPE, primitiveConverter.getToType()); - } - - public void testReturnsNullBoxedTypeForEmptyString() throws Exception { - assertNull(converter.convert("")); - } - - public void testNullCharacterIsOK() throws Exception { - assertNull(converter.convert(null)); - } - - public void testNullCharacterIsNotOKForPrimitive() throws Exception { - try { - primitiveConverter.convert(null); - fail("exception should have been thrown"); - } catch (IllegalArgumentException e) { - } - } - - public void testThrowsIllegalArgumentExceptionIfAskedToConvertNonString() - throws Exception { - try { - converter.convert(new Integer(1)); - fail("exception should have been thrown"); - } catch (IllegalArgumentException e) { - } - } -}
\ No newline at end of file diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToNumberParserByteTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToNumberParserByteTest.java deleted file mode 100644 index dd8b65bb..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToNumberParserByteTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.conversion; - -import org.eclipse.core.internal.databinding.conversion.StringToNumberParser; - -/** - * @since 3.2 - * - */ -public class StringToNumberParserByteTest extends - StringToNumberParserTestHarness { - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.StringToNumberParserTestHarness#assertValid(java.lang.Number) - */ - protected boolean assertValid(Number number) { - return StringToNumberParser.inByteRange(number); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.StringToNumberParserTestHarness#getValidMax() - */ - protected Number getValidMax() { - return new Byte(Byte.MAX_VALUE); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.StringToNumberParserTestHarness#getValidMin() - */ - protected Number getValidMin() { - return new Byte(Byte.MIN_VALUE); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToNumberParserDoubleTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToNumberParserDoubleTest.java deleted file mode 100644 index 485d0592..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToNumberParserDoubleTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.conversion; - -import org.eclipse.core.internal.databinding.conversion.StringToNumberParser; - -/** - * @since 3.2 - * - */ -public class StringToNumberParserDoubleTest extends - StringToNumberParserTestHarness { - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.StringToNumberParserTestHarness#assertValid(java.lang.Number) - */ - protected boolean assertValid(Number number) { - return StringToNumberParser.inDoubleRange(number); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.StringToNumberParserTestHarness#getValidMax() - */ - protected Number getValidMax() { - return new Double(Double.MAX_VALUE); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.StringToNumberParserTestHarness#getValidMin() - */ - protected Number getValidMin() { - return new Double(-Double.MAX_VALUE); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToNumberParserFloatTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToNumberParserFloatTest.java deleted file mode 100644 index 8a286eb4..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToNumberParserFloatTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.conversion; - -import org.eclipse.core.internal.databinding.conversion.StringToNumberParser; - -/** - * @since 1.1 - * - */ -public class StringToNumberParserFloatTest extends - StringToNumberParserTestHarness { - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.StringToNumberParserTestHarness#assertValid(java.lang.Number) - */ - protected boolean assertValid(Number number) { - return StringToNumberParser.inFloatRange(number); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.StringToNumberParserTestHarness#getValidMax() - */ - protected Number getValidMax() { - return new Float(Float.MAX_VALUE); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.StringToNumberParserTestHarness#getValidMin() - */ - protected Number getValidMin() { - return new Float(-Float.MAX_VALUE); - } - -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToNumberParserIntegerTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToNumberParserIntegerTest.java deleted file mode 100644 index cd37511a..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToNumberParserIntegerTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.conversion; - -import org.eclipse.core.internal.databinding.conversion.StringToNumberParser; - -/** - * @since 1.1 - */ -public class StringToNumberParserIntegerTest extends - StringToNumberParserTestHarness { - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.StringToNumberParserTestHarness#assertValid(java.lang.Number) - */ - protected boolean assertValid(Number number) { - return StringToNumberParser.inIntegerRange(number); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.StringToNumberParserTestHarness#getValidMax() - */ - protected Number getValidMax() { - return new Integer(Integer.MAX_VALUE); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.StringToNumberParserTestHarness#getValidMin() - */ - protected Number getValidMin() { - return new Integer(Integer.MIN_VALUE); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToNumberParserLongTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToNumberParserLongTest.java deleted file mode 100644 index 3ecef0d6..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToNumberParserLongTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.conversion; - -import org.eclipse.core.internal.databinding.conversion.StringToNumberParser; - -/** - * @since 1.1 - * - */ -public class StringToNumberParserLongTest extends - StringToNumberParserTestHarness { - - protected boolean assertValid(Number number) { - return StringToNumberParser.inLongRange(number); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.StringToNumberParserTestHarness#getValidMax() - */ - protected Number getValidMax() { - return new Long(Long.MAX_VALUE); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.StringToNumberParserTestHarness#getValidMin() - */ - protected Number getValidMin() { - return new Long(Long.MIN_VALUE); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToNumberParserShortTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToNumberParserShortTest.java deleted file mode 100644 index cf0c0fa1..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToNumberParserShortTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.conversion; - -import org.eclipse.core.internal.databinding.conversion.StringToNumberParser; - - -/** - * @since 1.1 - */ -public class StringToNumberParserShortTest extends StringToNumberParserTestHarness { - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.StringToNumberParserTestHarness#assertValid(java.lang.Number) - */ - protected boolean assertValid(Number number) { - return StringToNumberParser.inShortRange(number); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.StringToNumberParserTestHarness#getValidMax() - */ - protected Number getValidMax() { - return new Short(Short.MAX_VALUE); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.conversion.StringToNumberParserTestHarness#getValidMin() - */ - protected Number getValidMin() { - return new Short(Short.MIN_VALUE); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToNumberParserTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToNumberParserTest.java deleted file mode 100644 index a1329a0d..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToNumberParserTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.conversion; - -import junit.framework.TestCase; - -import org.eclipse.core.internal.databinding.conversion.StringToNumberParser; -import org.eclipse.core.internal.databinding.conversion.StringToNumberParser.ParseResult; - -import com.ibm.icu.text.NumberFormat; - -/** - * @since 1.1 - */ -public class StringToNumberParserTest extends TestCase { - private NumberFormat integerFormat; - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - - integerFormat = NumberFormat.getIntegerInstance(); - } - - public void testParseNonStringThrowsIllegalArgumentException() - throws Exception { - try { - StringToNumberParser.parse(new Integer(0), integerFormat, false); - fail("exception should have been thrown"); - } catch (IllegalArgumentException e) { - } - } - - public void testEmptyStringReturnsNullIfNotPrimitive() throws Exception { - ParseResult result = StringToNumberParser.parse("", - integerFormat, false); - assertNull(result.getNumber()); - } - - public void testReturnsParsePositionWhenValueCannotBeParsed() - throws Exception { - ParseResult result = StringToNumberParser.parse("adsf", - integerFormat, false); - assertNotNull(result.getPosition()); - assertNull(result.getNumber()); - } - - public void testReturnsNumberWhenSuccessfullyParsed() throws Exception { - Integer number = new Integer(5); - ParseResult result = StringToNumberParser.parse(integerFormat - .format(number.longValue()), integerFormat, false); - assertNull(result.getPosition()); - assertEquals(number.intValue(), result.getNumber().intValue()); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToNumberParserTestHarness.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToNumberParserTestHarness.java deleted file mode 100644 index 476ba39c..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToNumberParserTestHarness.java +++ /dev/null @@ -1,215 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.conversion; - -import java.math.BigDecimal; -import java.math.BigInteger; - -import org.eclipse.core.internal.databinding.conversion.StringToNumberParser; - -import junit.framework.TestCase; - -/** - * @since 1.1 - */ -public abstract class StringToNumberParserTestHarness extends TestCase { - - protected abstract Number getValidMax(); - - protected abstract Number getValidMin(); - - protected abstract boolean assertValid(Number number); - - public void testRanges() throws Exception { - Number min = getValidMin(); - Number max = getValidMax(); - - double minDouble = min.doubleValue(); - double maxDouble = max.doubleValue(); - - //test bytes - assertTrue("valid byte", assertValid(new Byte((byte) 1))); - assertTrue("valid byte min", assertValid(new Byte(Byte.MIN_VALUE))); - assertTrue("valid byte max", assertValid(new Byte(Byte.MAX_VALUE))); - - // test shorts - assertTrue("valid short", assertValid(new Short((short) 1))); - boolean result = assertValid(new Short(Short.MIN_VALUE)); - if (minDouble > Short.MIN_VALUE) { - assertFalse("invalid short min", result); - } else { - assertTrue("valid short min", result); - } - - result = assertValid(new Short(Short.MAX_VALUE)); - if (maxDouble < Short.MAX_VALUE) { - assertFalse("invalid short max", result); - } else { - assertTrue("valid short max", result); - } - - // test integers - assertTrue("valid Integer", assertValid(new Integer(1))); - - result = assertValid(new Integer(Integer.MIN_VALUE)); - if (minDouble > Integer.MIN_VALUE) { - assertFalse("invalid Integer min", result); - } else { - assertTrue("valid integer min", result); - } - - result = assertValid(new Integer(Integer.MAX_VALUE)); - if (maxDouble < Integer.MAX_VALUE) { - assertFalse("valid Integer max", result); - } else { - assertTrue("valid integer max", result); - } - - // test longs - assertTrue("valid long", assertValid(new Long(1))); - result = assertValid(new Long(Long.MIN_VALUE)); - if (minDouble > Long.MIN_VALUE) { - assertFalse("invalid long min", result); - } else { - assertTrue("valid long min", result); - } - - result = assertValid(new Long(Long.MAX_VALUE)); - if (maxDouble < Long.MAX_VALUE) { - assertFalse("invalid long max", result); - } else { - assertTrue("valid long max", result); - } - - // test floats - assertTrue("valid float", assertValid(new Float(1))); - result = assertValid(new Float(-Float.MAX_VALUE)); - if (minDouble > -Float.MAX_VALUE) { - assertFalse("invalid float min", result); - } else { - assertTrue("valid float min", result); - } - - result = assertValid(new Float(Float.MAX_VALUE)); - if (maxDouble < Float.MAX_VALUE) { - assertFalse("invalid float max", result); - } else { - assertTrue("valid float max", result); - } - - assertFalse("invalid negative float infinity", assertValid(new Float( - Float.NEGATIVE_INFINITY))); - assertFalse("invalid positive float infinity", assertValid(new Float( - Float.POSITIVE_INFINITY))); - assertFalse("invalid float NaN", assertValid(new Float(Float.NaN))); - - // test doubles - assertTrue("valid double", assertValid(new Double(1))); - result = assertValid(new Double(-Double.MAX_VALUE)); - if (minDouble > -Double.MAX_VALUE) { - assertFalse("invalid double min", result); - } else { - assertTrue("valid double min", result); - } - - result = assertValid(new Double(Double.MAX_VALUE)); - if (maxDouble < Double.MAX_VALUE) { - assertFalse("invalid float max", result); - } else { - assertTrue("valid float max", result); - } - - assertFalse("invalid negative double infinity", assertValid(new Double( - Double.NEGATIVE_INFINITY))); - assertFalse("invalid positive double infinity", assertValid(new Double( - Double.POSITIVE_INFINITY))); - assertFalse("invalid double NaN", assertValid(new Double(Double.NaN))); - - // test BigIntegers - assertTrue("valid BigInteger", assertValid(BigInteger.valueOf(1))); - BigDecimal bigDecimalMin = new BigDecimal(min.doubleValue()); - bigDecimalMin = bigDecimalMin.subtract(new BigDecimal(1)); - assertFalse("invalid BigInteger min", assertValid(bigDecimalMin.toBigInteger())); - - BigDecimal bigDecimalMax = new BigDecimal(max.doubleValue()); - bigDecimalMax = bigDecimalMax.add(new BigDecimal(1)); - assertFalse("invalid BigInteger max", assertValid(bigDecimalMax.toBigInteger())); - - // test BigDecimals - assertTrue("valid BigDecimal", assertValid(new BigDecimal(1))); - assertFalse("invalid BigDecimal min", assertValid(bigDecimalMin)); - assertFalse("invalid BigDecimal max", assertValid(bigDecimalMax)); - - /** - * The ICU4J plugin's NumberFormat will return it's own BigDecimal - * implementation, com.ibm.icu.math.BigDecimal. The issue this causes is - * that we can't reference this class as it's not part of the - * replacement plugin. So in order to ensure that we handle Number's - * that are not part of the JDK stub a number implemenation and ensure - * that the double representation of this number is used. - * - * @throws Exception - */ - class MyNumber extends Number { - double value; - int count; - - MyNumber(double value) { - this.value = value; - } - - private static final long serialVersionUID = 1L; - - /* - * (non-Javadoc) - * - * @see java.lang.Number#doubleValue() - */ - public double doubleValue() { - count++; - return value; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Number#floatValue() - */ - public float floatValue() { - return 0; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Number#intValue() - */ - public int intValue() { - return 0; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Number#longValue() - */ - public long longValue() { - return 0; - } - } - - MyNumber number = new MyNumber(1); - assertEquals(0, number.count); - assertTrue(StringToNumberParser.inIntegerRange(number)); - assertTrue("double value retrieved", number.count > 0); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToShortConverterTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToShortConverterTest.java deleted file mode 100644 index b37fba1c..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/conversion/StringToShortConverterTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.conversion; - -import junit.framework.TestCase; - -import org.eclipse.core.internal.databinding.conversion.StringToShortConverter; - -import com.ibm.icu.text.NumberFormat; - -/** - * @since 1.1 - */ -public class StringToShortConverterTest extends TestCase { - private NumberFormat numberFormat; - private StringToShortConverter converter; - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - numberFormat = NumberFormat.getIntegerInstance(); - converter = StringToShortConverter.toShort(numberFormat, false); - } - - public void testConvertsToShort() throws Exception { - Short value = new Short((short) 1); - Short result = (Short) converter.convert(numberFormat.format(value)); - - assertEquals(value, result); - } - - public void testConvertsToShortPrimitive() throws Exception { - converter = StringToShortConverter.toShort(numberFormat, true); - Short value = new Short((short) 1); - Short result = (Short) converter.convert(numberFormat.format(value)); - assertEquals(value, result); - } - - public void testFromTypeIsString() throws Exception { - assertEquals(String.class, converter.getFromType()); - } - - public void testToTypeIsShort() throws Exception { - assertEquals(Short.class, converter.getToType()); - } - - public void testToTypeIsShortPrimitive() throws Exception { - converter = StringToShortConverter.toShort(true); - assertEquals(Short.TYPE, converter.getToType()); - } - - public void testReturnsNullBoxedTypeForEmptyString() throws Exception { - assertNull(converter.convert("")); - } - - public void testThrowsIllegalArgumentExceptionIfAskedToConvertNonString() - throws Exception { - try { - converter.convert(new Integer(1)); - fail("exception should have been thrown"); - } catch (IllegalArgumentException e) { - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/ConstantObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/ConstantObservableValueTest.java deleted file mode 100644 index 918d9901..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/ConstantObservableValueTest.java +++ /dev/null @@ -1,125 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007-2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 212518) - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.observable; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.internal.databinding.observable.ConstantObservableValue; -import org.eclipse.jface.databinding.conformance.ObservableValueContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.delegate.IObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.util.SuiteBuilder; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * Tests for ConstantObservableValue - * - * @since 1.1 - */ -public class ConstantObservableValueTest extends AbstractDefaultRealmTestCase { - public void testConstructor_NullRealm() { - try { - new ConstantObservableValue(null, null, null); - fail("Constructor should throw an exception when null realm is passed in"); - } catch (RuntimeException expected) { - } - } - - public static Test suite() { - TestSuite suite = new TestSuite("ConstantValueTest"); - suite.addTestSuite(ConstantObservableValueTest.class); - suite.addTest(UnchangeableObservableValueContractTest - .suite(new Delegate())); - return suite; - } - - private static class Delegate extends - AbstractObservableValueContractDelegate { - public IObservableValue createObservableValue(Realm realm) { - return new ConstantObservableValue(realm, new Object(), - Object.class); - } - - public Object getValueType(IObservableValue observable) { - return Object.class; - } - } - - /** - * Non-API--this class is public so that SuiteBuilder can access it. - */ - public static class UnchangeableObservableValueContractTest extends - ObservableValueContractTest { - public UnchangeableObservableValueContractTest(String name, - IObservableValueContractDelegate delegate) { - super(name, delegate); - } - - public void testChange_OrderOfNotifications() { - // disabled - } - - public void testChange_ValueChangeEvent() { - // disabled - } - - public void testChange_ValueChangeEventDiff() { - // disabled - } - - public void testChange_ValueChangeEventFiredAfterValueIsSet() { - // disabled - } - - public void testRemoveValueChangeListener_RemovesListener() - throws Exception { - // disabled - } - - public void testChange_ChangeEvent() { - // disabled - } - - public void testChange_EventObservable() { - // disabled - } - - public void testChange_ObservableRealmIsTheCurrentRealm() { - // disabled - } - - public void testChange_RealmCheck() { - // disabled - } - - public void testRemoveChangeListener_RemovesListener() { - // disabled - } - - public void testIsStale_RealmChecks() { - // disabled - } - - public void testIsStale_GetterCalled() throws Exception { - // disabled - } - - public static Test suite(IObservableValueContractDelegate delegate) { - return new SuiteBuilder().addObservableContractTest( - UnchangeableObservableValueContractTest.class, delegate) - .build(); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/EmptyObservableListTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/EmptyObservableListTest.java deleted file mode 100644 index 85482402..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/EmptyObservableListTest.java +++ /dev/null @@ -1,153 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 208332) - * Matthew Hall - bug 213145 - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.observable; - -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.internal.databinding.observable.EmptyObservableList; -import org.eclipse.jface.databinding.conformance.ObservableListContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; -import org.eclipse.jface.databinding.conformance.delegate.IObservableCollectionContractDelegate; -import org.eclipse.jface.databinding.conformance.util.SuiteBuilder; - -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * @since 3.2 - * - */ -public class EmptyObservableListTest { - public static Test suite() { - TestSuite suite = new TestSuite(EmptyObservableListTest.class.getName()); - suite.addTest(ImmutableObservableListContractTest.suite(new Delegate())); - return suite; - } - - public static class ImmutableObservableListContractTest extends - ObservableListContractTest { - public static Test suite(IObservableCollectionContractDelegate delegate) { - return new SuiteBuilder().addObservableContractTest( - ImmutableObservableListContractTest.class, delegate) - .build(); - } - - public ImmutableObservableListContractTest( - IObservableCollectionContractDelegate delegate) { - super(delegate); - } - - public ImmutableObservableListContractTest(String name, - IObservableCollectionContractDelegate delegate) { - super(name, delegate); - } - - public void testGet_GetterCalled() { - // disabled - } - - public void testSubList_GetterCalled() { - // disabled - } - - public void testChange_ChangeEvent() { - // disabled - } - - public void testChange_EventObservable() { - // disabled - } - - public void testChange_ObservableRealmIsTheCurrentRealm() { - // disabled - } - - public void testChange_RealmCheck() { - // disabled - } - - public void testRemoveChangeListener_RemovesListener() { - // disabled - } - - public void testIndexOf_GetterCalled() { - // disabled - } - - public void testLastIndexOf_GetterCalled() { - // disabled - } - - public void testListIterator_GetterCalled() { - // disabled - } - - public void testListIteratorAtIndex_GetterCalled() { - // disabled - } - - public void testContains_GetterCalled() { - // disabled - } - - public void testContainsAll_GetterCalled() { - // disabled - } - - public void testEquals_GetterCalled() { - // disabled - } - - public void testHashCode_GetterCalled() { - // disabled - } - - public void testIsEmpty_GetterCalled() { - // disabled - } - - public void testIterator_GetterCalled() { - // disabled - } - - public void testSize_GetterCalled() throws Exception { - // disabled - } - - public void testToArray_GetterCalled() throws Exception { - // disabled - } - - public void testToArrayWithObjectArray_GetterCalled() throws Exception { - // disabled - } - - public void testIsStale_GetterCalled() throws Exception { - // disabled - } - } - - private static class Delegate extends - AbstractObservableCollectionContractDelegate { - private Object elementType = new Object(); - - public IObservableCollection createObservableCollection(Realm realm, - int elementCount) { - return new EmptyObservableList(realm, elementType); - } - - public Object getElementType(IObservableCollection collection) { - return elementType; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/EmptyObservableSetTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/EmptyObservableSetTest.java deleted file mode 100644 index 2fa464e7..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/EmptyObservableSetTest.java +++ /dev/null @@ -1,128 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 208332) - * Matthew Hall - bug 213145 - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.observable; - -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.internal.databinding.observable.EmptyObservableSet; -import org.eclipse.jface.databinding.conformance.ObservableCollectionContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; -import org.eclipse.jface.databinding.conformance.delegate.IObservableCollectionContractDelegate; -import org.eclipse.jface.databinding.conformance.util.SuiteBuilder; - -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * @since 3.2 - * - */ -public class EmptyObservableSetTest { - public static Test suite() { - TestSuite suite = new TestSuite(EmptyObservableSetTest.class.getName()); - suite.addTest(ImmutableObservableSetContractTest.suite(new Delegate())); - return suite; - } - - public static class ImmutableObservableSetContractTest extends - ObservableCollectionContractTest { - public static Test suite(IObservableCollectionContractDelegate delegate) { - return new SuiteBuilder().addObservableContractTest( - ImmutableObservableSetContractTest.class, delegate).build(); - } - - public ImmutableObservableSetContractTest( - IObservableCollectionContractDelegate delegate) { - super(delegate); - } - - public ImmutableObservableSetContractTest(String name, - IObservableCollectionContractDelegate delegate) { - super(name, delegate); - } - - public void testChange_ChangeEvent() { - // disabled - } - - public void testChange_EventObservable() { - // disabled - } - - public void testChange_ObservableRealmIsTheCurrentRealm() { - // disabled - } - - public void testChange_RealmCheck() { - // disabled - } - - public void testRemoveChangeListener_RemovesListener() { - // disabled - } - - public void testContains_GetterCalled() { - // disabled - } - - public void testContainsAll_GetterCalled() { - // disabled - } - - public void testEquals_GetterCalled() { - // disabled - } - - public void testHashCode_GetterCalled() { - // disabled - } - - public void testIsEmpty_GetterCalled() { - // disabled - } - - public void testIterator_GetterCalled() { - // disabled - } - - public void testSize_GetterCalled() { - // disabled - } - - public void testToArray_GetterCalled() { - // disabled - } - - public void testToArrayWithObjectArray_GetterCalled() { - // disabled - } - - public void testIsStale_GetterCalled() throws Exception { - // disabled - } - } - - private static class Delegate extends - AbstractObservableCollectionContractDelegate { - private Object elementType = new Object(); - - public IObservableCollection createObservableCollection(Realm realm, - int elementCount) { - return new EmptyObservableSet(realm, elementType); - } - - public Object getElementType(IObservableCollection collection) { - return elementType; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/MapEntryObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/MapEntryObservableValueTest.java deleted file mode 100644 index d27e02a0..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/MapEntryObservableValueTest.java +++ /dev/null @@ -1,191 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007-2008 Marko Topolnik 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: - * Marko Topolnik - initial API and implementation (bug 184830) - * Matthew Hall - bugs 184830, 213145 - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.observable; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Observables; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.map.WritableMap; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.observable.value.ValueChangeEvent; -import org.eclipse.core.databinding.observable.value.ValueDiff; -import org.eclipse.core.internal.databinding.observable.MapEntryObservableValue; -import org.eclipse.jface.databinding.conformance.MutableObservableValueContractTest; -import org.eclipse.jface.databinding.conformance.ObservableStaleContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -/** - * @since 1.2 - */ -public class MapEntryObservableValueTest extends AbstractDefaultRealmTestCase - implements IValueChangeListener { - private static final String VALUE1 = "Value1"; - private static final String VALUE2 = "Value2"; - - private final Object key = "mapKey"; - private IObservableMap map; - private ValueDiff diff; - private MapEntryObservableValue observedValue; - - protected void setUp() throws Exception { - super.setUp(); - this.map = new WritableMap(); - this.observedValue = (MapEntryObservableValue) Observables - .observeMapEntry(this.map, this.key, String.class); - observedValue.addValueChangeListener(this); - } - - public void handleValueChange(ValueChangeEvent p_event) { - this.diff = p_event.diff; - } - - public void testNullValue() { - // test entry added with value null - this.map.put(this.key, null); - assertNull(this.diff); - assertNull(this.observedValue.getValue()); - // test value changed from null to null - this.map.put(this.key, null); - assertNull(this.diff); - assertNull(this.observedValue.getValue()); - // test null-valued entry removed - this.map.remove(this.key); - assertNull(this.diff); - assertNull(this.observedValue.getValue()); - } - - public void testNonNullValue() { - // test add non-null value - this.map.put(this.key, VALUE1); - assertNotNull(this.diff); - assertNull(this.diff.getOldValue()); - assertSame(VALUE1, this.diff.getNewValue()); - assertSame(VALUE1, this.observedValue.getValue()); - - // test change to another non-null value - this.diff = null; - this.map.put(this.key, VALUE2); - assertNotNull(this.diff); - assertSame(VALUE1, this.diff.getOldValue()); - assertSame(VALUE2, this.diff.getNewValue()); - assertSame(VALUE2, this.observedValue.getValue()); - } - - public void testTransitionBetweenNullAndNonNull() { - this.map.put(this.key, null); - - // test transition to non-null - this.diff = null; - this.map.put(this.key, VALUE1); - assertNotNull(this.diff); - assertNull(this.diff.getOldValue()); - assertSame(VALUE1, this.diff.getNewValue()); - - // test transition to null - this.diff = null; - this.map.put(this.key, null); - assertNotNull(this.diff); - assertSame(VALUE1, this.diff.getOldValue()); - assertNull(this.diff.getNewValue()); - } - - public void testRemoveKey() { - this.map.put(this.key, VALUE1); - - this.diff = null; - this.map.remove(this.key); - assertNotNull(this.diff); - assertSame(VALUE1, this.diff.getOldValue()); - assertNull(this.diff.getNewValue()); - } - - public void testGetAndSetValue() { - // test set null value - this.observedValue.setValue(null); - assertNull(this.observedValue.getValue()); - assertNull(this.diff); - - // test set non-null value - this.observedValue.setValue(VALUE1); - assertSame(VALUE1, this.observedValue.getValue()); - assertNotNull(this.diff); - assertNull(this.diff.getOldValue()); - assertSame(VALUE1, this.diff.getNewValue()); - - // test set another non-null value - this.diff = null; - this.observedValue.setValue(VALUE2); - assertSame(VALUE2, this.observedValue.getValue()); - assertNotNull(this.diff); - assertSame(VALUE1, this.diff.getOldValue()); - assertSame(VALUE2, this.diff.getNewValue()); - } - - public static Test suite() { - TestSuite suite = new TestSuite(MapEntryObservableValueTest.class.getName()); - suite.addTestSuite(MapEntryObservableValueTest.class); - suite.addTest(MutableObservableValueContractTest.suite(new Delegate())); - suite.addTest(ObservableStaleContractTest.suite(new Delegate())); - return suite; - } - - private static class Delegate extends - AbstractObservableValueContractDelegate { - private Object valueType = new Object(); - - public IObservableValue createObservableValue(Realm realm) { - WritableMap map = new WritableMap(realm); - Object key = new Object(); - map.put(key, new Object()); - return new MapEntryObservableValueStub(map, key, valueType); - } - - public Object createValue(IObservableValue observable) { - return new Object(); - } - - public Object getValueType(IObservableValue observable) { - return valueType; - } - - public void change(IObservable observable) { - MapEntryObservableValueStub mapEntryValue = (MapEntryObservableValueStub) observable; - mapEntryValue.map - .put(mapEntryValue.key, createValue(mapEntryValue)); - } - - public void setStale(IObservable observable, boolean stale) { - MapEntryObservableValueStub mapEntryValue = (MapEntryObservableValueStub) observable; - mapEntryValue.map.setStale(stale); - } - } - - private static class MapEntryObservableValueStub extends - MapEntryObservableValue { - WritableMap map; - Object key; - - MapEntryObservableValueStub(WritableMap map, Object key, - Object valueType) { - super(map, key, valueType); - this.map = map; - this.key = key; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/ProxyObservableListTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/ProxyObservableListTest.java deleted file mode 100644 index a1ceaa3a..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/ProxyObservableListTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 208332) - * Matthew Hall - bug 213145 - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.observable; - -import java.util.ArrayList; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.core.internal.databinding.observable.ProxyObservableList; -import org.eclipse.jface.databinding.conformance.ObservableListContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; - -/** - * @since 3.2 - * - */ -public class ProxyObservableListTest { - public static Test suite() { - TestSuite suite = new TestSuite(ProxyObservableListTest.class.getName()); - suite.addTest(ObservableListContractTest.suite(new Delegate())); - return suite; - } - - static class Delegate extends AbstractObservableCollectionContractDelegate { - private Object elementType = Object.class; - - public IObservableCollection createObservableCollection(Realm realm, - int elementCount) { - IObservableList wrappedList = new WritableList(realm, - new ArrayList(), elementType); - for (int i = 0; i < elementCount; i++) - wrappedList.add(new Object()); - return new ProxyObservableListStub(wrappedList); - } - - public Object createElement(IObservableCollection collection) { - return new Object(); - } - - public Object getElementType(IObservableCollection collection) { - return elementType; - } - - public void change(IObservable observable) { - ((ProxyObservableListStub) observable).wrappedList - .add(new Object()); - } - } - - static class ProxyObservableListStub extends ProxyObservableList { - IObservableList wrappedList; - - ProxyObservableListStub(IObservableList wrappedList) { - super(wrappedList); - this.wrappedList = wrappedList; - } - } -}
\ No newline at end of file diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/ProxyObservableSetTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/ProxyObservableSetTest.java deleted file mode 100644 index 1be56d23..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/ProxyObservableSetTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 208332) - * Matthew Hall - bug 213145 - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.observable; - -import java.util.Collections; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.WritableSet; -import org.eclipse.core.internal.databinding.observable.ProxyObservableSet; -import org.eclipse.jface.databinding.conformance.ObservableCollectionContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; - -/** - * @since 3.2 - * - */ -public class ProxyObservableSetTest { - public static Test suite() { - TestSuite suite = new TestSuite(ProxyObservableSetTest.class.getName()); - suite.addTest(ObservableCollectionContractTest.suite(new Delegate())); - return suite; - } - - static class Delegate extends AbstractObservableCollectionContractDelegate { - private Object elementType = Object.class; - - public IObservableCollection createObservableCollection(Realm realm, - int elementCount) { - IObservableSet wrappedSet = new WritableSet(realm, - Collections.EMPTY_SET, elementType); - for (int i = 0; i < elementCount; i++) - wrappedSet.add(createElement(wrappedSet)); - return new ProxyObservableSetStub(wrappedSet); - } - - public Object createElement(IObservableCollection collection) { - return new Object(); - } - - public Object getElementType(IObservableCollection collection) { - return elementType; - } - - public void change(IObservable observable) { - ProxyObservableSetStub set = (ProxyObservableSetStub) observable; - set.wrappedSet.add(createElement(set)); - } - } - - static class ProxyObservableSetStub extends ProxyObservableSet { - IObservableSet wrappedSet; - - ProxyObservableSetStub(IObservableSet wrappedSet) { - super(wrappedSet); - this.wrappedSet = wrappedSet; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/StalenessObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/StalenessObservableValueTest.java deleted file mode 100644 index 0d5a5f3b..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/StalenessObservableValueTest.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 212468) - * Matthew Hall - bug 213145 - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.observable; - -import org.eclipse.core.databinding.observable.AbstractObservable; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.internal.databinding.observable.StalenessObservableValue; -import org.eclipse.jface.databinding.conformance.ObservableValueContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -/** - * Tests for StalenessObservableValue - * - * @since 1.1 - */ -public class StalenessObservableValueTest extends TestCase { - public static Test suite() { - TestSuite suite = new TestSuite(StalenessObservableValueTest.class.getName()); - suite.addTest(ObservableValueContractTest.suite(new Delegate())); - return suite; - } - - static class ObservableStub extends AbstractObservable { - boolean stale; - - public ObservableStub(Realm realm) { - super(realm); - } - - public boolean isStale() { - return stale; - } - - public void setStale(boolean stale) { - if (this.stale == stale) - return; - - this.stale = stale; - if (stale) { - fireStale(); - } else { - fireChange(); - } - } - } - - static class StalenessObservableValueStub extends StalenessObservableValue { - ObservableStub target; - - StalenessObservableValueStub(ObservableStub target) { - super(target); - this.target = target; - } - } - - static class Delegate extends AbstractObservableValueContractDelegate { - public IObservableValue createObservableValue(Realm realm) { - return new StalenessObservableValueStub(new ObservableStub(realm)); - } - - public void change(IObservable observable) { - ObservableStub target = ((StalenessObservableValueStub) observable).target; - target.setStale(!target.isStale()); - } - - public Object getValueType(IObservableValue observable) { - return Boolean.TYPE; - } - } -}
\ No newline at end of file diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/UnmodifiableObservableListTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/UnmodifiableObservableListTest.java deleted file mode 100755 index 13e57031..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/UnmodifiableObservableListTest.java +++ /dev/null @@ -1,239 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Cerner Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bugs 208332, 213145 - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.observable; - -import java.util.ArrayList; -import java.util.List; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.ChangeEvent; -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.Observables; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.databinding.observable.list.IListChangeListener; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.ListChangeEvent; -import org.eclipse.core.databinding.observable.list.ListDiff; -import org.eclipse.core.databinding.observable.list.ListDiffEntry; -import org.eclipse.core.databinding.observable.list.ObservableList; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.core.internal.databinding.observable.UnmodifiableObservableList; -import org.eclipse.jface.databinding.conformance.ObservableListContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -public class UnmodifiableObservableListTest extends - AbstractDefaultRealmTestCase { - ObservableList unmodifiable; - ObservableList mutable; - - protected void setUp() throws Exception { - super.setUp(); - - List list = new ArrayList(); - list.add("1"); - list.add("2"); - - mutable = new MutableObservableList(list, String.class); - unmodifiable = (ObservableList) Observables - .unmodifiableObservableList(mutable); - } - - public void testFiresChangeEvents() throws Exception { - ChangeCounter mutableListener = new ChangeCounter(); - ChangeCounter unmodifiableListener = new ChangeCounter(); - - mutable.addChangeListener(mutableListener); - unmodifiable.addChangeListener(unmodifiableListener); - - assertEquals(0, mutableListener.count); - assertEquals(0, unmodifiableListener.count); - mutable.add("3"); - assertEquals(1, mutableListener.count); - assertEquals(1, unmodifiableListener.count); - } - - public void testFiresListChangeEvents() throws Exception { - ListChangeCounter mutableListener = new ListChangeCounter(); - ListChangeCounter unmodifiableListener = new ListChangeCounter(); - - mutable.addListChangeListener(mutableListener); - unmodifiable.addListChangeListener(unmodifiableListener); - - assertEquals(0, mutableListener.count); - assertEquals(0, unmodifiableListener.count); - - String element = "3"; - mutable.add(element); - assertEquals(1, mutableListener.count); - assertEquals(mutable, mutableListener.source); - assertEquals(1, mutableListener.diff.getDifferences().length); - - ListDiffEntry difference = mutableListener.diff.getDifferences()[0]; - assertEquals(element, difference.getElement()); - assertTrue(difference.isAddition()); - assertEquals(3, mutable.size()); - - assertEquals(1, unmodifiableListener.count); - assertEquals(unmodifiable, unmodifiableListener.source); - assertEquals(1, unmodifiableListener.diff.getDifferences().length); - - difference = unmodifiableListener.diff.getDifferences()[0]; - assertEquals(element, difference.getElement()); - assertTrue(difference.isAddition()); - assertEquals(3, unmodifiable.size()); - } - - public void testFiresStaleEvents() throws Exception { - StaleCounter mutableListener = new StaleCounter(); - StaleCounter unmodifiableListener = new StaleCounter(); - - mutable.addStaleListener(mutableListener); - unmodifiable.addStaleListener(unmodifiableListener); - - assertEquals(0, mutableListener.count); - assertEquals(0, unmodifiableListener.count); - mutable.setStale(true); - assertEquals(1, mutableListener.count); - assertEquals(mutable, mutableListener.source); - assertTrue(mutable.isStale()); - assertEquals(1, unmodifiableListener.count); - assertEquals(unmodifiable, unmodifiableListener.source); - assertTrue(unmodifiable.isStale()); - } - - public void testIsStale() throws Exception { - assertFalse(mutable.isStale()); - assertFalse(unmodifiable.isStale()); - mutable.setStale(true); - assertTrue(mutable.isStale()); - assertTrue(unmodifiable.isStale()); - } - - public void testSetStaleOnUnmodifiableList() throws Exception { - try { - unmodifiable.setStale(true); - fail("UnsupportedOperationException should have been thrown"); - } catch (UnsupportedOperationException e) { - } - } - - private static class StaleCounter implements IStaleListener { - int count; - IObservable source; - - public void handleStale(StaleEvent event) { - count++; - this.source = event.getObservable(); - } - } - - private static class ChangeCounter implements IChangeListener { - int count; - IObservable source; - - public void handleChange(ChangeEvent event) { - count++; - this.source = event.getObservable(); - } - } - - private static class ListChangeCounter implements IListChangeListener { - int count; - IObservableList source; - ListDiff diff; - - public void handleListChange(ListChangeEvent event) { - count++; - this.source = event.getObservableList(); - this.diff = event.diff; - } - } - - private static class MutableObservableList extends ObservableList { - /** - * @param wrappedList - * @param elementType - */ - public MutableObservableList(List wrappedList, Object elementType) { - super(wrappedList, elementType); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.internal.databinding.provisional.observable.list.ObservableList#add(java.lang.Object) - */ - public boolean add(Object o) { - boolean result = wrappedList.add(o); - fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry( - wrappedList.size() - 1, true, o))); - - return result; - } - } - - public static Test suite() { - TestSuite suite = new TestSuite(UnmodifiableObservableListTest.class.getName()); - suite.addTestSuite(UnmodifiableObservableListTest.class); - suite.addTest(ObservableListContractTest.suite(new Delegate())); - return suite; - } - - private static class Delegate extends - AbstractObservableCollectionContractDelegate { - private Object elementType = new Object(); - - public IObservableCollection createObservableCollection(Realm realm, - int elementCount) { - IObservableList backingList = new WritableList(realm, - new ArrayList(), elementType); - IObservableList result = new UnmodifiableObservableListStub( - backingList); - for (int i = 0; i < elementCount; i++) - backingList.add(createElement(result)); - return result; - } - - public Object createElement(IObservableCollection collection) { - return new Object(); - } - - public Object getElementType(IObservableCollection collection) { - return elementType; - } - - public void change(IObservable observable) { - UnmodifiableObservableListStub unmodifiableList = (UnmodifiableObservableListStub) observable; - IObservableList wrappedList = unmodifiableList.wrappedList; - wrappedList.add(createElement(unmodifiableList)); - } - } - - private static class UnmodifiableObservableListStub extends - UnmodifiableObservableList { - IObservableList wrappedList; - - UnmodifiableObservableListStub(IObservableList wrappedList) { - super(wrappedList); - this.wrappedList = wrappedList; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/UnmodifiableObservableSetTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/UnmodifiableObservableSetTest.java deleted file mode 100644 index 2ae7ef14..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/UnmodifiableObservableSetTest.java +++ /dev/null @@ -1,237 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Matthew 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: - * Brad Reynolds - initial API and implementation - * (through UnmodifiableObservableListTest.java) - * Matthew Hall - bugs 208332, 213145 - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.observable; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.ChangeEvent; -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.Observables; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.ISetChangeListener; -import org.eclipse.core.databinding.observable.set.ObservableSet; -import org.eclipse.core.databinding.observable.set.SetChangeEvent; -import org.eclipse.core.databinding.observable.set.SetDiff; -import org.eclipse.core.databinding.observable.set.WritableSet; -import org.eclipse.core.internal.databinding.observable.UnmodifiableObservableSet; -import org.eclipse.jface.databinding.conformance.ObservableCollectionContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -public class UnmodifiableObservableSetTest extends AbstractDefaultRealmTestCase { - UnmodifiableObservableSet unmodifiable; - MutableObservableSet mutable; - - protected void setUp() throws Exception { - super.setUp(); - - Set set = new HashSet(); - set.add("1"); - set.add("2"); - - mutable = new MutableObservableSet(set, String.class); - unmodifiable = (UnmodifiableObservableSet) Observables - .unmodifiableObservableSet(mutable); - } - - public void testFiresChangeEvents() throws Exception { - ChangeCounter mutableListener = new ChangeCounter(); - ChangeCounter unmodifiableListener = new ChangeCounter(); - - mutable.addChangeListener(mutableListener); - unmodifiable.addChangeListener(unmodifiableListener); - - assertEquals(0, mutableListener.count); - assertEquals(0, unmodifiableListener.count); - mutable.add("3"); - assertEquals(1, mutableListener.count); - assertEquals(1, unmodifiableListener.count); - } - - public void testFiresSetChangeEvents() throws Exception { - SetChangeCounter mutableListener = new SetChangeCounter(); - SetChangeCounter unmodifiableListener = new SetChangeCounter(); - - mutable.addSetChangeListener(mutableListener); - unmodifiable.addSetChangeListener(unmodifiableListener); - - assertEquals(0, mutableListener.count); - assertEquals(0, unmodifiableListener.count); - - String element = "3"; - mutable.add(element); - assertEquals(1, mutableListener.count); - assertEquals(mutable, mutableListener.source); - assertEquals(1, mutableListener.diff.getAdditions().size()); - - Object addition = mutableListener.diff.getAdditions().toArray()[0]; - assertEquals(element, addition); - assertEquals(3, mutable.size()); - - assertEquals(1, unmodifiableListener.count); - assertEquals(unmodifiable, unmodifiableListener.source); - assertEquals(1, unmodifiableListener.diff.getAdditions().size()); - - addition = unmodifiableListener.diff.getAdditions().toArray()[0]; - assertEquals(element, addition); - assertEquals(3, unmodifiable.size()); - } - - public void testFiresStaleEvents() throws Exception { - StaleCounter mutableListener = new StaleCounter(); - StaleCounter unmodifiableListener = new StaleCounter(); - - mutable.addStaleListener(mutableListener); - unmodifiable.addStaleListener(unmodifiableListener); - - assertEquals(0, mutableListener.count); - assertEquals(0, unmodifiableListener.count); - mutable.setStale(true); - assertEquals(1, mutableListener.count); - assertEquals(mutable, mutableListener.source); - assertTrue(mutable.isStale()); - assertEquals(1, unmodifiableListener.count); - assertEquals(unmodifiable, unmodifiableListener.source); - assertTrue(unmodifiable.isStale()); - } - - public void testIsStale() throws Exception { - assertFalse(mutable.isStale()); - assertFalse(unmodifiable.isStale()); - mutable.setStale(true); - assertTrue(mutable.isStale()); - assertTrue(unmodifiable.isStale()); - } - - public void testSetStaleOnUnmodifiableList() throws Exception { - try { - unmodifiable.setStale(true); - fail("UnsupportedOperationException should have been thrown"); - } catch (UnsupportedOperationException e) { - } - } - - private static class StaleCounter implements IStaleListener { - int count; - IObservable source; - - public void handleStale(StaleEvent event) { - count++; - this.source = event.getObservable(); - } - } - - private static class ChangeCounter implements IChangeListener { - int count; - IObservable source; - - public void handleChange(ChangeEvent event) { - count++; - this.source = event.getObservable(); - } - } - - private static class SetChangeCounter implements ISetChangeListener { - int count; - IObservableSet source; - SetDiff diff; - - public void handleSetChange(SetChangeEvent event) { - count++; - this.source = event.getObservableSet(); - this.diff = event.diff; - } - } - - private static class MutableObservableSet extends ObservableSet { - /** - * @param wrappedList - * @param elementType - */ - public MutableObservableSet(Set wrappedSet, Object elementType) { - super(wrappedSet, elementType); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.internal.databinding.provisional.observable.list.ObservableList#add(java.lang.Object) - */ - public boolean add(Object o) { - boolean result = wrappedSet.add(o); - if (result) - fireSetChange(Diffs.createSetDiff(Collections.singleton(o), - Collections.EMPTY_SET)); - return result; - } - } - - public static Test suite() { - TestSuite suite = new TestSuite(UnmodifiableObservableSetTest.class.getName()); - suite.addTestSuite(UnmodifiableObservableSetTest.class); - suite.addTest(ObservableCollectionContractTest.suite(new Delegate())); - return suite; - } - - private static class Delegate extends - AbstractObservableCollectionContractDelegate { - private Object elementType = new Object(); - - public IObservableCollection createObservableCollection(Realm realm, - int elementCount) { - IObservableSet backingList = new WritableSet(realm, new HashSet(), - elementType); - IObservableSet result = new UnmodifiableObservableSetStub( - backingList); - for (int i = 0; i < elementCount; i++) - backingList.add(createElement(result)); - return result; - } - - public Object createElement(IObservableCollection collection) { - return new Object(); - } - - public Object getElementType(IObservableCollection collection) { - return elementType; - } - - public void change(IObservable observable) { - UnmodifiableObservableSetStub unmodifiableList = (UnmodifiableObservableSetStub) observable; - IObservableSet wrappedList = unmodifiableList.wrappedSet; - wrappedList.add(createElement(unmodifiableList)); - } - } - - private static class UnmodifiableObservableSetStub extends - UnmodifiableObservableSet { - IObservableSet wrappedSet; - - UnmodifiableObservableSetStub(IObservableSet wrappedSet) { - super(wrappedSet); - this.wrappedSet = wrappedSet; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/UnmodifiableObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/UnmodifiableObservableValueTest.java deleted file mode 100644 index 630d4ced..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/UnmodifiableObservableValueTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 219909) - * Matthew Hall - bug 213145 - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.observable; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.internal.databinding.observable.UnmodifiableObservableValue; -import org.eclipse.jface.databinding.conformance.ObservableValueContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; - -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * @since 3.2 - * - */ -public class UnmodifiableObservableValueTest { - public static Test suite() { - TestSuite suite = new TestSuite(UnmodifiableObservableValueTest.class.getName()); - suite.addTest(ObservableValueContractTest.suite(new Delegate())); - return suite; - } - - private static class Delegate extends - AbstractObservableValueContractDelegate { - private Object valueType = new Object(); - - public IObservableValue createObservableValue(Realm realm) { - return new UnmodifiableObservableValueStub(new WritableValue(realm, - null, valueType)); - } - - public Object getValueType(IObservableValue observable) { - return valueType; - } - - public Object createValue(IObservableValue observable) { - return new Object(); - } - - public void change(IObservable observable) { - UnmodifiableObservableValueStub wrapper = (UnmodifiableObservableValueStub) observable; - wrapper.wrappedValue.setValue(createValue(wrapper)); - } - } - - private static class UnmodifiableObservableValueStub extends - UnmodifiableObservableValue { - IObservableValue wrappedValue; - - UnmodifiableObservableValueStub(IObservableValue wrappedValue) { - super(wrappedValue); - this.wrappedValue = wrappedValue; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/ValidatedObservableListTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/ValidatedObservableListTest.java deleted file mode 100644 index 21793a79..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/ValidatedObservableListTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 218269) - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.observable; - -import java.util.ArrayList; - -import junit.framework.Test; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.databinding.validation.ValidationStatus; -import org.eclipse.core.internal.databinding.observable.ValidatedObservableList; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jface.databinding.conformance.MutableObservableListContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -public class ValidatedObservableListTest extends AbstractDefaultRealmTestCase { - public static Test suite() { - return MutableObservableListContractTest.suite(new Delegate()); - } - - static class Delegate extends AbstractObservableCollectionContractDelegate { - private Object elementType = new Object(); - - public IObservableCollection createObservableCollection(Realm realm, - int elementCount) { - IObservableList target = new WritableList(realm, new ArrayList(), - elementType); - for (int i = 0; i < elementCount; i++) - target.add(createElement(target)); - IObservableValue validationStatus = new WritableValue(realm, - ValidationStatus.ok(), IStatus.class); - return new ValidatedObservableListStub(target, validationStatus); - } - - public Object createElement(IObservableCollection collection) { - return new Object(); - } - - public Object getElementType(IObservableCollection collection) { - return elementType; - } - - public void change(IObservable observable) { - ValidatedObservableListStub validated = (ValidatedObservableListStub) observable; - validated.target.add(createElement(validated)); - } - - public void setStale(IObservable observable, boolean stale) { - ValidatedObservableListStub validated = (ValidatedObservableListStub) observable; - if (stale) { - validated.validationStatus.setValue(ValidationStatus - .error("error")); - validated.target.add(createElement(validated)); - } else { - validated.validationStatus.setValue(ValidationStatus.ok()); - } - } - - } - - static class ValidatedObservableListStub extends ValidatedObservableList { - IObservableList target; - IObservableValue validationStatus; - - ValidatedObservableListStub(IObservableList target, - IObservableValue validationStatus) { - super(target, validationStatus); - this.target = target; - this.validationStatus = validationStatus; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/ValidatedObservableSetTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/ValidatedObservableSetTest.java deleted file mode 100644 index 0748e0ab..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/ValidatedObservableSetTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 218269) - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.observable; - -import java.util.Collections; - -import junit.framework.Test; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.WritableSet; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.databinding.validation.ValidationStatus; -import org.eclipse.core.internal.databinding.observable.ValidatedObservableSet; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jface.databinding.conformance.MutableObservableSetContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -public class ValidatedObservableSetTest extends AbstractDefaultRealmTestCase { - public static Test suite() { - return MutableObservableSetContractTest.suite(new Delegate()); - } - - static class Delegate extends AbstractObservableCollectionContractDelegate { - private Object elementType = new Object(); - - public IObservableCollection createObservableCollection(Realm realm, - int elementCount) { - IObservableSet target = new WritableSet(realm, - Collections.EMPTY_SET, elementType); - for (int i = 0; i < elementCount; i++) - target.add(createElement(target)); - IObservableValue validationStatus = new WritableValue(realm, - ValidationStatus.ok(), IStatus.class); - return new ValidatedObservableSetStub(target, validationStatus); - } - - public Object createElement(IObservableCollection collection) { - return new Object(); - } - - public Object getElementType(IObservableCollection collection) { - return elementType; - } - - public void change(IObservable observable) { - ValidatedObservableSetStub validated = (ValidatedObservableSetStub) observable; - validated.target.add(createElement(validated)); - } - - public void setStale(IObservable observable, boolean stale) { - ValidatedObservableSetStub validated = (ValidatedObservableSetStub) observable; - if (stale) { - validated.validationStatus.setValue(ValidationStatus - .error("error")); - validated.target.add(createElement(validated)); - } else { - validated.validationStatus.setValue(ValidationStatus.ok()); - } - } - - } - - static class ValidatedObservableSetStub extends ValidatedObservableSet { - IObservableSet target; - IObservableValue validationStatus; - - ValidatedObservableSetStub(IObservableSet target, - IObservableValue validationStatus) { - super(target, validationStatus); - this.target = target; - this.validationStatus = validationStatus; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/ValidatedObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/ValidatedObservableValueTest.java deleted file mode 100644 index fd2e0e4d..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/ValidatedObservableValueTest.java +++ /dev/null @@ -1,305 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 218269) - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.observable; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.AbstractObservableValue; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.databinding.validation.ValidationStatus; -import org.eclipse.core.internal.databinding.observable.ValidatedObservableValue; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jface.databinding.conformance.MutableObservableValueContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.util.CurrentRealm; -import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -/** - * @since 3.2 - * - */ -public class ValidatedObservableValueTest extends AbstractDefaultRealmTestCase { - private ValidatedObservableValue validated; - private ObservableValueStub target; - private IObservableValue validationStatus; - - private Object oldValue; - private Object newValue; - - protected void setUp() throws Exception { - super.setUp(); - oldValue = new Object(); - newValue = new Object(); - target = new ObservableValueStub(Realm.getDefault()); - target.setValue(oldValue); - validationStatus = new WritableValue(ValidationStatus.ok(), - IStatus.class); - validated = new ValidatedObservableValue(target, validationStatus); - } - - public void testConstructor_RequireObservablesOnSameRealm() { - CurrentRealm realm1 = new CurrentRealm(true); - CurrentRealm realm2 = new CurrentRealm(true); - target = new ObservableValueStub(realm1); - validationStatus = new WritableValue(realm2); - try { - new ValidatedObservableValue(target, validationStatus); - fail("Expected exception--target and validation status should have the same realm"); - } catch (RuntimeException expected) { - } - } - - public void testIsStale_WhenTargetIsStale() { - assertFalse(target.isStale()); - assertFalse(validated.isStale()); - - target.fireStale(); - - assertTrue(target.isStale()); - assertTrue(validated.isStale()); - } - - public void testIsStale_WhileChangesPending() { - assertFalse(target.isStale()); - assertFalse(validated.isStale()); - - validationStatus.setValue(ValidationStatus.error("error")); - - // The validated observable goes stale only when the target changes - // value but the validation status is not OK. - assertFalse(target.isStale()); - assertFalse(validated.isStale()); - - target.setValue(newValue); - - assertFalse(target.isStale()); - assertTrue(validated.isStale()); - - validationStatus.setValue(ValidationStatus.ok()); - - assertFalse(validated.isStale()); - } - - public void testGetValueType_SameAsTarget() { - assertEquals(target.getValueType(), validated.getValueType()); - } - - public void testGetValue_InitialValue() { - assertEquals(oldValue, target.getValue()); - assertEquals(oldValue, validated.getValue()); - } - - public void testGetValue_WhileChangesPending() { - assertEquals(oldValue, target.getValue()); - assertEquals(oldValue, validated.getValue()); - - validationStatus.setValue(ValidationStatus.error("error")); - - assertEquals(oldValue, target.getValue()); - assertEquals(oldValue, validated.getValue()); - - target.setValue(newValue); - - assertEquals(newValue, target.getValue()); - assertEquals(oldValue, validated.getValue()); - - validationStatus.setValue(ValidationStatus.ok()); - - assertEquals(newValue, validated.getValue()); - } - - public void testSetValue_PropagatesToTarget() { - validated.setValue(newValue); - - assertEquals(newValue, validated.getValue()); - assertEquals(newValue, target.getValue()); - } - - public void testSetValue_PropagatesToTargetWhileStatusNotOK() { - validationStatus.setValue(ValidationStatus.error("error")); - - validated.setValue(newValue); - - assertEquals(newValue, validated.getValue()); - assertEquals(newValue, target.getValue()); - assertFalse(validated.isStale()); - } - - public void testSetValue_CachesGetValueFromTarget() { - Object overrideValue = target.overrideValue = new Object(); - - assertEquals(oldValue, validated.getValue()); - assertEquals(oldValue, target.getValue()); - - validationStatus.setValue(ValidationStatus.error("error")); - - validated.setValue(newValue); - - assertEquals(overrideValue, target.getValue()); - assertEquals(overrideValue, validated.getValue()); - } - - public void testSetValue_SingleValueChangeEvent() { - ValueChangeEventTracker tracker = ValueChangeEventTracker - .observe(validated); - - validated.setValue(newValue); - assertEquals(1, tracker.count); - assertEquals(oldValue, tracker.event.diff.getOldValue()); - assertEquals(newValue, tracker.event.diff.getNewValue()); - } - - public void testSetValue_SingleValueChangeEventWhileInvalid() { - ValueChangeEventTracker tracker = ValueChangeEventTracker - .observe(validated); - - validationStatus.setValue(ValidationStatus.error("error")); - validated.setValue(newValue); - assertEquals(1, tracker.count); - assertEquals(oldValue, tracker.event.diff.getOldValue()); - assertEquals(newValue, tracker.event.diff.getNewValue()); - } - - public void testSetValue_FiresSingleValueChangeEventWithTargetOverride() { - ValueChangeEventTracker tracker = ValueChangeEventTracker - .observe(validated); - - Object overrideValue = new Object(); - target.overrideValue = overrideValue; - validated.setValue(newValue); - - assertEquals(1, tracker.count); - assertEquals(oldValue, tracker.event.diff.getOldValue()); - assertEquals(overrideValue, tracker.event.diff.getNewValue()); - } - - public void testSetValue_FiresValueChangeEvent() { - ValueChangeEventTracker targetTracker = ValueChangeEventTracker - .observe(target); - ValueChangeEventTracker validatedTracker = ValueChangeEventTracker - .observe(validated); - - validated.setValue(newValue); - - assertEquals(1, targetTracker.count); - assertEquals(oldValue, targetTracker.event.diff.getOldValue()); - assertEquals(newValue, targetTracker.event.diff.getNewValue()); - - assertEquals(1, validatedTracker.count); - assertEquals(oldValue, validatedTracker.event.diff.getOldValue()); - assertEquals(newValue, validatedTracker.event.diff.getNewValue()); - } - - public void testIsStale_MatchTargetStaleness() { - target.forceStale = true; - target.fireStale(); - - assertTrue(target.isStale()); - assertTrue(validated.isStale()); - - target.setValue(newValue); - - assertTrue(target.isStale()); - assertTrue(validated.isStale()); - } - - static class ObservableValueStub extends AbstractObservableValue { - private Object value; - private boolean stale; - private boolean forceStale; - - Object overrideValue; - - public ObservableValueStub(Realm realm) { - super(realm); - } - - protected Object doGetValue() { - return value; - } - - protected void doSetValue(Object value) { - Object oldValue = this.value; - if (overrideValue != null) - value = overrideValue; - this.value = value; - stale = forceStale; - fireValueChange(Diffs.createValueDiff(oldValue, value)); - } - - public Object getValueType() { - return Object.class; - } - - protected void fireStale() { - stale = true; - super.fireStale(); - } - - public boolean isStale() { - return stale; - } - } - - public static Test suite() { - TestSuite suite = new TestSuite(ValidatedObservableValueTest.class.getName()); - suite.addTestSuite(ValidatedObservableValueTest.class); - suite.addTest(MutableObservableValueContractTest.suite(new Delegate())); - return suite; - } - - static class Delegate extends AbstractObservableValueContractDelegate { - private Object valueType = new Object(); - - public IObservableValue createObservableValue(Realm realm) { - return new ValidatedObservableValueStub(realm, valueType); - } - - public Object createValue(IObservableValue observable) { - return new Object(); - } - - public Object getValueType(IObservableValue observable) { - return valueType; - } - - public void change(IObservable observable) { - ValidatedObservableValueStub validated = (ValidatedObservableValueStub) observable; - IObservableValue target = validated.target; - target.setValue(createValue(validated)); - } - } - - static class ValidatedObservableValueStub extends ValidatedObservableValue { - final IObservableValue target; - final IObservableValue validationStatus; - - ValidatedObservableValueStub(Realm realm, Object valueType) { - this(new WritableValue(realm, null, valueType), new WritableValue( - realm, ValidationStatus.ok(), IStatus.class)); - } - - private ValidatedObservableValueStub(IObservableValue target, - IObservableValue validationStatus) { - super(target, validationStatus); - this.target = target; - this.validationStatus = validationStatus; - } - } - -}
\ No newline at end of file diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/masterdetail/DetailObservableListTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/masterdetail/DetailObservableListTest.java deleted file mode 100644 index 264ba349..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/masterdetail/DetailObservableListTest.java +++ /dev/null @@ -1,158 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007-2008 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bugs 208858, 221351, 213145 - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.observable.masterdetail; - -import java.util.ArrayList; -import java.util.Arrays; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.internal.databinding.observable.masterdetail.DetailObservableList; -import org.eclipse.core.runtime.AssertionFailedException; -import org.eclipse.jface.databinding.conformance.MutableObservableListContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -/** - * @since 3.2 - */ -public class DetailObservableListTest extends AbstractDefaultRealmTestCase { - /** - * Asserts the use case of specifying null on construction for the detail - * type of the detail list. - * - * @throws Exception - */ - public void testElementTypeNull() throws Exception { - WritableValue observableValue = new WritableValue(new WritableList(new ArrayList(), Object.class), null); - - class Factory implements IObservableFactory { - Object type = Object.class; - - public IObservable createObservable(Object target) { - return new WritableList(new ArrayList(), type); - } - } - - Factory factory = new Factory(); - DetailObservableList detailObservable = new DetailObservableList( - factory, observableValue, null); - assertNull(detailObservable.getElementType()); - - //change the type returned from the factory - factory.type = String.class; - observableValue.setValue(new WritableList(new ArrayList(), String.class)); - assertNull("element type not null", detailObservable.getElementType()); - } - - /** - * Asserts that you can't change the type across multiple inner observables. - * - * @throws Exception - */ - public void testElementTypeNotNull() throws Exception { - WritableValue observableValue = new WritableValue(new WritableList(new ArrayList(), Object.class), - null); - - class Factory implements IObservableFactory { - Object type = Object.class; - - public IObservable createObservable(Object target) { - return new WritableList(new ArrayList(), type); - } - } - - Factory factory = new Factory(); - DetailObservableList detailObservable = new DetailObservableList(factory, - observableValue, Object.class); - assertEquals(factory.type, detailObservable.getElementType()); - - try { - factory.type = String.class; - observableValue.setValue(new WritableList(Arrays - .asList(new Object[] { new Object() }), String.class)); - fail("if an element type is set this cannot be changed"); - } catch (AssertionFailedException e) { - } - } - - public static Test suite() { - TestSuite suite = new TestSuite(DetailObservableListTest.class.getName()); - suite.addTestSuite(DetailObservableListTest.class); - suite.addTest(MutableObservableListContractTest.suite(new Delegate())); - return suite; - } - - static class Delegate extends AbstractObservableCollectionContractDelegate { - Object elementType = Object.class; - - public IObservableCollection createObservableCollection( - final Realm realm, final int elementCount) { - - IObservableValue master = new WritableValue(realm, new Integer( - elementCount), Integer.class); - IObservableFactory factory = new FactoryStub(realm, elementType); - return new DetailObservableListStub(factory, master, elementType); - } - - public Object createElement(IObservableCollection collection) { - return new Object(); - } - - public Object getElementType(IObservableCollection collection) { - return elementType; - } - - public void change(IObservable observable) { - final IObservableValue master = ((DetailObservableListStub)observable).master; - master.setValue(new Integer(((Integer)master.getValue()).intValue()+1)); - } - } - - static class FactoryStub implements IObservableFactory { - private Realm realm; - private Object elementType; - - FactoryStub(Realm realm, Object elementType) { - this.realm = realm; - this.elementType = elementType; - } - - Object type = Object.class; - - public IObservable createObservable(Object target) { - int elementCount = ((Integer) target).intValue(); - final ArrayList wrappedList = new ArrayList(); - for (int i = 0; i < elementCount; i++) - wrappedList.add(new Object()); - return new WritableList(realm, wrappedList, elementType); - } - } - - static class DetailObservableListStub extends DetailObservableList { - IObservableValue master; - DetailObservableListStub(IObservableFactory factory, - IObservableValue master, Object elementType) { - super(factory, master, elementType); - this.master = master; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/masterdetail/DetailObservableSetTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/masterdetail/DetailObservableSetTest.java deleted file mode 100644 index b4edbd42..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/masterdetail/DetailObservableSetTest.java +++ /dev/null @@ -1,170 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007-2008 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bugs 221351, 213145 - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.observable.masterdetail; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.set.WritableSet; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.internal.databinding.observable.masterdetail.DetailObservableSet; -import org.eclipse.core.runtime.AssertionFailedException; -import org.eclipse.jface.databinding.conformance.MutableObservableSetContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -/** - * @since 3.2 - * - */ -public class DetailObservableSetTest extends AbstractDefaultRealmTestCase { - /** - * Asserts the use case of specifying null on construction for the detail - * type of the detail set. - * - * @throws Exception - */ - public void testElementTypeNull() throws Exception { - WritableValue observableValue = new WritableValue(new WritableSet(new HashSet(), Object.class), - null); - - class Factory implements IObservableFactory { - Object type; - - public IObservable createObservable(Object target) { - return new WritableSet(new HashSet(), type); - } - } - - Factory factory = new Factory(); - DetailObservableSet detailObservable = new DetailObservableSet(factory, - observableValue, null); - assertNull(detailObservable.getElementType()); - - factory.type = Object.class; - observableValue.setValue(new WritableSet(Arrays - .asList(new Object[] { new Object() }), String.class)); - assertNull("element type not null", detailObservable.getElementType()); - - factory.type = String.class; - // set the value again to ensure that the observable doesn't update the - // element type with that of the new element type - observableValue.setValue(new WritableSet(Arrays - .asList(new String[] { "1" }), Object.class)); - assertNull("element type not null", detailObservable.getElementType()); - } - - /** - * Asserts that you can't change the type across multiple inner observables. - * - * @throws Exception - */ - public void testElementTypeNotNull() throws Exception { - WritableValue observableValue = new WritableValue(new WritableSet(new HashSet(), Object.class), - null); - - class Factory implements IObservableFactory { - Object type = Object.class; - - public IObservable createObservable(Object target) { - return new WritableSet(new HashSet(), type); - } - } - - Factory factory = new Factory(); - DetailObservableSet detailObservable = new DetailObservableSet(factory, - observableValue, Object.class); - assertEquals(factory.type, detailObservable.getElementType()); - - try { - factory.type = String.class; - observableValue.setValue(new WritableSet(Arrays - .asList(new Object[] { new Object() }), String.class)); - fail("if an element type is set this cannot be changed"); - } catch (AssertionFailedException e) { - } - } - - public static Test suite() { - TestSuite suite = new TestSuite(DetailObservableSetTest.class.getName()); - suite.addTestSuite(DetailObservableSetTest.class); - suite.addTest(MutableObservableSetContractTest.suite(new Delegate())); - return suite; - } - - static class Delegate extends AbstractObservableCollectionContractDelegate { - Object elementType = Object.class; - - public IObservableCollection createObservableCollection( - final Realm realm, final int elementCount) { - - IObservableValue master = new WritableValue(realm, new Integer( - elementCount), Integer.class); - IObservableFactory factory = new FactoryStub(realm, elementType); - return new DetailObservableSetStub(factory, master, elementType); - } - - public Object createElement(IObservableCollection collection) { - return new Object(); - } - - public Object getElementType(IObservableCollection collection) { - return elementType; - } - - public void change(IObservable observable) { - final IObservableValue master = ((DetailObservableSetStub) observable).master; - master.setValue(new Integer(((Integer) master.getValue()) - .intValue() + 1)); - } - } - - static class FactoryStub implements IObservableFactory { - private Realm realm; - private Object elementType; - - FactoryStub(Realm realm, Object elementType) { - this.realm = realm; - this.elementType = elementType; - } - - Object type = Object.class; - - public IObservable createObservable(Object target) { - int elementCount = ((Integer) target).intValue(); - final Set wrappedSet = new HashSet(); - for (int i = 0; i < elementCount; i++) - wrappedSet.add(new Object()); - return new WritableSet(realm, wrappedSet, elementType); - } - } - - static class DetailObservableSetStub extends DetailObservableSet { - IObservableValue master; - - DetailObservableSetStub(IObservableFactory factory, - IObservableValue master, Object elementType) { - super(factory, master, elementType); - this.master = master; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/masterdetail/DetailObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/masterdetail/DetailObservableValueTest.java deleted file mode 100755 index 35abc20d..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/masterdetail/DetailObservableValueTest.java +++ /dev/null @@ -1,157 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006-2008 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Brad Reynolds - bug 147515 - * Matthew Hall - bugs 221351, 213145 - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.observable.masterdetail; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.masterdetail.MasterDetailObservables; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.internal.databinding.observable.masterdetail.DetailObservableValue; -import org.eclipse.jface.databinding.conformance.MutableObservableValueContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.util.CurrentRealm; -import org.eclipse.jface.databinding.conformance.util.RealmTester; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -/** - * @since 3.2 - */ -public class DetailObservableValueTest extends AbstractDefaultRealmTestCase { - private WritableValue outerObservable; - - protected void setUp() throws Exception { - super.setUp(); - outerObservable = new WritableValue(); - } - - public void testSetValue() throws Exception { - WritableValueFactory factory = new WritableValueFactory(); - outerObservable.setValue(""); - - IObservableValue detailObservable = MasterDetailObservables - .detailValue(outerObservable, factory, null); - WritableValue innerObservable = factory.innerObservable; - Object value = new Object(); - - assertFalse(value.equals(innerObservable.getValue())); - detailObservable.setValue(value); - assertEquals("inner value", value, innerObservable.getValue()); - } - - public void testGetValueType() throws Exception { - DetailObservableValue detailObservable = new DetailObservableValue(outerObservable, null, String.class); - assertEquals(String.class, detailObservable.getValueType()); - } - - /** - * Asserts that when a null value type is set for the detail observable no - * type checking is performed and the value type is always <code>null</code>. - */ - public void testGetValueTypeNullValueType() throws Exception { - WritableValueFactory factory = new WritableValueFactory(); - DetailObservableValue detailObservable = new DetailObservableValue( - outerObservable, factory, null); - assertNull(detailObservable.getValueType()); - factory.type = String.class; - - // force the inner observable to be recreated - outerObservable.setValue("1"); - assertNull("value type should be ignored", detailObservable.getValueType()); - - factory.type = Object.class; - - // force the inner observable to be recreated - outerObservable.setValue("2"); - assertNull("value type should be ignored", detailObservable.getValueType()); - } - - /** - * Factory that creates WritableValues with the target as the value. - */ - static class WritableValueFactory implements IObservableFactory { - Realm realm; - WritableValue innerObservable; - Object type; - - public IObservable createObservable(Object target) { - return innerObservable = new WritableValue(realm == null ? Realm - .getDefault() : realm, target, type); - } - } - - public static Test suite() { - TestSuite suite = new TestSuite(DetailObservableValueTest.class.getName()); - suite.addTestSuite(DetailObservableValueTest.class); - suite.addTest(MutableObservableValueContractTest.suite(new Delegate())); - return suite; - } - - private static class DetailObservableValueStub extends - DetailObservableValue { - IObservableValue outerObservableValue; - - DetailObservableValueStub(IObservableValue outerObservableValue, - IObservableFactory valueFactory, Object detailType) { - super(outerObservableValue, valueFactory, detailType); - this.outerObservableValue = outerObservableValue; - } - } - - private static class Delegate extends - AbstractObservableValueContractDelegate { - private Object valueType; - private Realm previousRealm; - - public void setUp() { - super.setUp(); - valueType = new Object(); - previousRealm = Realm.getDefault(); - - RealmTester.setDefault(new CurrentRealm()); - } - - public void tearDown() { - RealmTester.setDefault(previousRealm); - super.tearDown(); - } - - public IObservableValue createObservableValue(Realm realm) { - WritableValueFactory valueFactory = new WritableValueFactory(); - valueFactory.realm = realm; - valueFactory.type = valueType; - WritableValue masterObservableValue = new WritableValue(realm, - new Object(), null); - return new DetailObservableValueStub(masterObservableValue, - valueFactory, valueType); - } - - public Object createValue(IObservableValue observable) { - return new Object(); - } - - public Object getValueType(IObservableValue observable) { - return valueType; - } - - public void change(IObservable observable) { - DetailObservableValueStub value = (DetailObservableValueStub) observable; - value.outerObservableValue.setValue(createValue(value)); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/AbstractStringToNumberValidatorTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/AbstractStringToNumberValidatorTest.java deleted file mode 100644 index cf58d351..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/AbstractStringToNumberValidatorTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.validation; - -import junit.framework.TestCase; - -import org.eclipse.core.databinding.conversion.StringToNumberConverter; -import org.eclipse.core.internal.databinding.validation.AbstractStringToNumberValidator; -import org.eclipse.core.internal.databinding.validation.NumberFormatConverter; -import org.eclipse.core.runtime.IStatus; - -/** - * Tests for AbstractStringToNumberValidator. Most tests should be included in - * StringToNumberValidatorTestHarness. This class is for the edge cases. - * - * @since 3.2 - */ -public class AbstractStringToNumberValidatorTest extends TestCase { - /** - * Test for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=194353. - * - * @throws Exception - */ - public void testErrorMessagesAreNotCached() throws Exception { - NumberFormatConverter c = StringToNumberConverter.toInteger(false); - ValidatorStub v = new ValidatorStub(c); - - IStatus status1 = v.validate("1a"); - assertEquals(IStatus.ERROR, status1.getSeverity()); - - IStatus status2 = v.validate("2b"); - assertEquals(IStatus.ERROR, status2.getSeverity()); - - assertFalse("messages should not be equal", status1.getMessage().equals(status2.getMessage())); - } - - static class ValidatorStub extends AbstractStringToNumberValidator { - ValidatorStub(NumberFormatConverter c) { - super(c, new Integer(Integer.MIN_VALUE), new Integer(Integer.MAX_VALUE)); - } - - protected boolean isInRange(Number number) { - return true; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/NumberToByteValidatorTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/NumberToByteValidatorTest.java deleted file mode 100644 index 88f27505..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/NumberToByteValidatorTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.validation; - -import org.eclipse.core.internal.databinding.conversion.NumberToByteConverter; -import org.eclipse.core.internal.databinding.validation.NumberToByteValidator; -import org.eclipse.core.internal.databinding.validation.NumberToNumberValidator; - -import com.ibm.icu.text.NumberFormat; - -/** - * @since 1.1 - */ -public class NumberToByteValidatorTest extends NumberToNumberValidatorTestHarness { - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.NumberToNumberValidatorTestHarness#doGetOutOfRangeNumber() - */ - protected Number doGetOutOfRangeNumber() { - return new Integer(Byte.MAX_VALUE + 1); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.NumberToNumberValidatorTestHarness#doGetToBoxedTypeValidator() - */ - protected NumberToNumberValidator doGetToBoxedTypeValidator(Class fromType) { - NumberToByteConverter converter = new NumberToByteConverter(NumberFormat.getInstance(), - fromType, false); - return new NumberToByteValidator(converter); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.NumberToNumberValidatorTestHarness#doGetToPrimitiveValidator() - */ - protected NumberToNumberValidator doGetToPrimitiveValidator(Class fromType) { - NumberToByteConverter converter = new NumberToByteConverter(NumberFormat.getInstance(), - fromType, true); - return new NumberToByteValidator(converter); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/NumberToDoubleValidatorTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/NumberToDoubleValidatorTest.java deleted file mode 100644 index 38c7a291..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/NumberToDoubleValidatorTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.validation; - -import java.math.BigDecimal; - -import org.eclipse.core.internal.databinding.conversion.NumberToDoubleConverter; -import org.eclipse.core.internal.databinding.validation.NumberToDoubleValidator; -import org.eclipse.core.internal.databinding.validation.NumberToNumberValidator; - -import com.ibm.icu.text.NumberFormat; - -/** - * @since 1.1 - */ -public class NumberToDoubleValidatorTest extends - NumberToNumberValidatorTestHarness { - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.NumberToNumberValidatorTestHarness#doGetOutOfRangeNumber() - */ - protected Number doGetOutOfRangeNumber() { - return new BigDecimal(Double.MAX_VALUE).add(new BigDecimal(Double.MAX_VALUE)); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.NumberToNumberValidatorTestHarness#doGetToBoxedTypeValidator(java.lang.Class) - */ - protected NumberToNumberValidator doGetToBoxedTypeValidator(Class fromType) { - NumberToDoubleConverter converter = new NumberToDoubleConverter(NumberFormat.getInstance(), fromType, false); - return new NumberToDoubleValidator(converter); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.NumberToNumberValidatorTestHarness#doGetToPrimitiveValidator(java.lang.Class) - */ - protected NumberToNumberValidator doGetToPrimitiveValidator(Class fromType) { - NumberToDoubleConverter converter = new NumberToDoubleConverter(NumberFormat.getInstance(), fromType, true); - return new NumberToDoubleValidator(converter); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/NumberToFloatValidatorTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/NumberToFloatValidatorTest.java deleted file mode 100644 index f2f8a588..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/NumberToFloatValidatorTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.validation; - -import org.eclipse.core.internal.databinding.conversion.NumberToFloatConverter; -import org.eclipse.core.internal.databinding.validation.NumberToFloatValidator; -import org.eclipse.core.internal.databinding.validation.NumberToNumberValidator; - -import com.ibm.icu.text.NumberFormat; - -/** - * @since 1.1 - */ -public class NumberToFloatValidatorTest extends - NumberToNumberValidatorTestHarness { - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.NumberToNumberValidatorTestHarness#doGetOutOfRangeNumber() - */ - protected Number doGetOutOfRangeNumber() { - return new Double(Double.MAX_VALUE); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.NumberToNumberValidatorTestHarness#doGetToBoxedTypeValidator(java.lang.Class) - */ - protected NumberToNumberValidator doGetToBoxedTypeValidator(Class fromType) { - NumberToFloatConverter converter = new NumberToFloatConverter(NumberFormat.getInstance(), fromType, false); - return new NumberToFloatValidator(converter); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.NumberToNumberValidatorTestHarness#doGetToPrimitiveValidator(java.lang.Class) - */ - protected NumberToNumberValidator doGetToPrimitiveValidator(Class fromType) { - NumberToFloatConverter converter = new NumberToFloatConverter(NumberFormat.getInstance(), fromType, true); - return new NumberToFloatValidator(converter); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/NumberToIntegerValidatorTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/NumberToIntegerValidatorTest.java deleted file mode 100644 index 37015a26..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/NumberToIntegerValidatorTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.validation; - -import org.eclipse.core.internal.databinding.conversion.NumberToIntegerConverter; -import org.eclipse.core.internal.databinding.validation.NumberToIntegerValidator; -import org.eclipse.core.internal.databinding.validation.NumberToNumberValidator; - -import com.ibm.icu.text.NumberFormat; - -/** - * @since 1.1 - */ -public class NumberToIntegerValidatorTest extends - NumberToNumberValidatorTestHarness { - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.NumberToNumberValidatorTestHarness#doGetOutOfRangeNumber() - */ - protected Number doGetOutOfRangeNumber() { - return new Long((long) Integer.MAX_VALUE + 1); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.NumberToNumberValidatorTestHarness#doGetToBoxedTypeValidator(java.lang.Class) - */ - protected NumberToNumberValidator doGetToBoxedTypeValidator(Class fromType) { - NumberToIntegerConverter converter = new NumberToIntegerConverter(NumberFormat.getInstance(), fromType, false); - return new NumberToIntegerValidator(converter); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.NumberToNumberValidatorTestHarness#doGetToPrimitiveValidator(java.lang.Class) - */ - protected NumberToNumberValidator doGetToPrimitiveValidator(Class fromType) { - NumberToIntegerConverter converter = new NumberToIntegerConverter(NumberFormat.getInstance(), fromType, true); - return new NumberToIntegerValidator(converter); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/NumberToLongValidatorTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/NumberToLongValidatorTest.java deleted file mode 100644 index 7821d758..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/NumberToLongValidatorTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.validation; - -import org.eclipse.core.internal.databinding.conversion.NumberToLongConverter; -import org.eclipse.core.internal.databinding.validation.NumberToLongValidator; -import org.eclipse.core.internal.databinding.validation.NumberToNumberValidator; - -import com.ibm.icu.text.NumberFormat; - -/** - * @since 1.1 - */ -public class NumberToLongValidatorTest extends - NumberToNumberValidatorTestHarness { - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.NumberToNumberValidatorTestHarness#doGetOutOfRangeNumber() - */ - protected Number doGetOutOfRangeNumber() { - return new Double(Double.MAX_VALUE); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.NumberToNumberValidatorTestHarness#doGetToBoxedTypeValidator(java.lang.Class) - */ - protected NumberToNumberValidator doGetToBoxedTypeValidator(Class fromType) { - NumberToLongConverter converter = new NumberToLongConverter(NumberFormat.getInstance(), fromType, false); - return new NumberToLongValidator(converter); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.NumberToNumberValidatorTestHarness#doGetToPrimitiveValidator(java.lang.Class) - */ - protected NumberToNumberValidator doGetToPrimitiveValidator(Class fromType) { - NumberToLongConverter converter = new NumberToLongConverter(NumberFormat.getInstance(), fromType, true); - return new NumberToLongValidator(converter); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/NumberToNumberValidatorTestHarness.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/NumberToNumberValidatorTestHarness.java deleted file mode 100644 index 817241c5..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/NumberToNumberValidatorTestHarness.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.validation; - -import junit.framework.TestCase; - -import org.eclipse.core.databinding.validation.IValidator; -import org.eclipse.core.internal.databinding.validation.NumberToNumberValidator; -import org.eclipse.core.runtime.IStatus; - -/** - * @since 1.1 - */ -public abstract class NumberToNumberValidatorTestHarness extends TestCase { - protected abstract NumberToNumberValidator doGetToPrimitiveValidator(Class fromType); - protected abstract NumberToNumberValidator doGetToBoxedTypeValidator(Class fromType); - protected abstract Number doGetOutOfRangeNumber(); - - public void testValidateNullForBoxedTypeIsOK() throws Exception { - IStatus status = doGetToBoxedTypeValidator(Integer.class).validate(null); - assertTrue(status.isOK()); - } - - public void testValidateNullForPrimitiveThrowsIllegalArgumentException() - throws Exception { - IValidator validator = doGetToPrimitiveValidator(Integer.class); - - if (validator == null) { - //return if a primitive validator does not exist (e.g. BigInteger, BigDecimal, etc.) - return; - } - - try { - doGetToPrimitiveValidator(Integer.class).validate(null); - - fail("exception should have been thrown"); - } catch (IllegalArgumentException e) { - } - } - - public void testValidReturnsOK() throws Exception { - assertTrue(doGetToBoxedTypeValidator(Integer.class).validate(new Integer(1)).isOK()); - } - - public void testOutOfRangeReturnsError() throws Exception { - Number number = doGetOutOfRangeNumber(); - - if (number == null) { - //return if there is no value out of range (e.g. BigInteger, BigDecimal, etc.) - return; - } - - IStatus status = doGetToBoxedTypeValidator(Integer.class).validate(number); - - assertEquals(IStatus.ERROR, status.getSeverity()); - assertTrue(status.getMessage() != null); - } - - public void testValidateIncorrectTypeThrowsIllegalArgumentException() throws Exception { - try { - doGetToBoxedTypeValidator(Integer.class).validate(""); - fail("exception should have been thrown"); - } catch (IllegalArgumentException e) { - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/NumberToShortValidatorTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/NumberToShortValidatorTest.java deleted file mode 100644 index df915931..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/NumberToShortValidatorTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.validation; - -import org.eclipse.core.internal.databinding.conversion.NumberToShortConverter; -import org.eclipse.core.internal.databinding.validation.NumberToNumberValidator; -import org.eclipse.core.internal.databinding.validation.NumberToShortValidator; - -import com.ibm.icu.text.NumberFormat; - -/** - * @since 1.1 - */ -public class NumberToShortValidatorTest extends NumberToNumberValidatorTestHarness { - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.NumberToNumberValidatorTestHarness#doGetOutOfRangeNumber() - */ - protected Number doGetOutOfRangeNumber() { - return new Integer(Short.MAX_VALUE + 1); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.NumberToNumberValidatorTestHarness#doGetToBoxedTypeValidator(java.lang.Class) - */ - protected NumberToNumberValidator doGetToBoxedTypeValidator(Class fromType) { - NumberToShortConverter converter = new NumberToShortConverter(NumberFormat.getInstance(), - Integer.class, false); - return new NumberToShortValidator(converter); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.NumberToNumberValidatorTestHarness#doGetToPrimitiveValidator(java.lang.Class) - */ - protected NumberToNumberValidator doGetToPrimitiveValidator(Class fromType) { - NumberToShortConverter converter = new NumberToShortConverter(NumberFormat.getInstance(), - Integer.class, true); - return new NumberToShortValidator(converter); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/NumberToUnboundedNumberValidatorTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/NumberToUnboundedNumberValidatorTest.java deleted file mode 100644 index da5fa743..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/NumberToUnboundedNumberValidatorTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.validation; - -import org.eclipse.core.internal.databinding.conversion.NumberToBigIntegerConverter; -import org.eclipse.core.internal.databinding.validation.NumberToNumberValidator; -import org.eclipse.core.internal.databinding.validation.NumberToUnboundedNumberValidator; - -import com.ibm.icu.text.NumberFormat; - -/** - * @since 1.1 - */ -public class NumberToUnboundedNumberValidatorTest extends - NumberToNumberValidatorTestHarness { - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.NumberToNumberValidatorTestHarness#doGetOutOfRangeNumber() - */ - protected Number doGetOutOfRangeNumber() { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.NumberToNumberValidatorTestHarness#doGetToBoxedTypeValidator(java.lang.Class) - */ - protected NumberToNumberValidator doGetToBoxedTypeValidator(Class fromType) { - NumberToBigIntegerConverter converter = new NumberToBigIntegerConverter(NumberFormat.getInstance(), fromType); - return new NumberToUnboundedNumberValidator(converter); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.NumberToNumberValidatorTestHarness#doGetToPrimitiveValidator(java.lang.Class) - */ - protected NumberToNumberValidator doGetToPrimitiveValidator(Class fromType) { - return null; // primitive BigInteger does not exist - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/StringToByteValidatorTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/StringToByteValidatorTest.java deleted file mode 100644 index 7e33bc2b..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/StringToByteValidatorTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.validation; - -import org.eclipse.core.databinding.validation.IValidator; -import org.eclipse.core.internal.databinding.conversion.StringToByteConverter; -import org.eclipse.core.internal.databinding.validation.StringToByteValidator; - -import com.ibm.icu.text.NumberFormat; - -/** - * @since 1.1 - */ -public class StringToByteValidatorTest extends - StringToNumberValidatorTestHarness { - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.StringToNumberValidatorTestHarness#getInRangeNumber() - */ - protected Number getInRangeNumber() { - return new Byte(Byte.MAX_VALUE); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.StringToNumberValidatorTestHarness#getInvalidString() - */ - protected String getInvalidString() { - return "1.1"; - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.StringToNumberValidatorTestHarness#getOutOfRangeNumber() - */ - protected Number getOutOfRangeNumber() { - return new Integer(Byte.MAX_VALUE + 1); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.StringToNumberValidatorTestHarness#setupNumberFormat() - */ - protected NumberFormat setupNumberFormat() { - return NumberFormat.getIntegerInstance(); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.StringToNumberValidatorTestHarness#setupValidator(com.ibm.icu.text.NumberFormat) - */ - protected IValidator setupValidator(NumberFormat numberFormat) { - StringToByteConverter converter = StringToByteConverter.toByte(numberFormat, false); - return new StringToByteValidator(converter); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/StringToCharacterValidatorTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/StringToCharacterValidatorTest.java deleted file mode 100644 index ca753fdf..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/StringToCharacterValidatorTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * Copyright (c) Matt Carter 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: - * Matt Carter - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.validation; - -import junit.framework.TestCase; - -import org.eclipse.core.internal.databinding.conversion.StringToCharacterConverter; -import org.eclipse.core.internal.databinding.validation.StringToCharacterValidator; - -/** - * @since 1.1 - */ -public class StringToCharacterValidatorTest extends TestCase { - - private StringToCharacterValidator validator; - private StringToCharacterValidator primitiveValidator; - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - StringToCharacterConverter converter = StringToCharacterConverter - .toCharacter(false); - StringToCharacterConverter primitiveConverter = StringToCharacterConverter - .toCharacter(true); - validator = new StringToCharacterValidator(converter); - primitiveValidator = new StringToCharacterValidator(primitiveConverter); - } - - public void testValidatesCharacter() throws Exception { - assertTrue(validator.validate("X").isOK()); - } - - public void testValidatesCharacterPrimitive() throws Exception { - assertTrue(primitiveValidator.validate("X").isOK()); - } - - public void testNullCharacterIsValid() throws Exception { - assertTrue(validator.validate(null).isOK()); - } - - public void testEmptyStringCharacterIsValid() throws Exception { - assertTrue(validator.validate("").isOK()); - } - - public void testNullCharacterIsInvalidForPrimitive() throws Exception { - assertFalse(primitiveValidator.validate(null).isOK()); - } - - public void testNonStringIsInvalid() throws Exception { - assertFalse(primitiveValidator.validate(new Integer(4)).isOK()); - } - - public void testLongerThanOneCharacterIsInvalid() throws Exception { - assertFalse(primitiveValidator.validate("XYZ").isOK()); - } - -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/StringToDoubleValidatorTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/StringToDoubleValidatorTest.java deleted file mode 100644 index 71d6f3ff..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/StringToDoubleValidatorTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.validation; - -import java.math.BigDecimal; - -import org.eclipse.core.databinding.conversion.StringToNumberConverter; -import org.eclipse.core.databinding.validation.IValidator; -import org.eclipse.core.internal.databinding.validation.StringToDoubleValidator; - -import com.ibm.icu.text.NumberFormat; - -/** - * @since 1.1 - */ -public class StringToDoubleValidatorTest extends - StringToNumberValidatorTestHarness { - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.StringToNumberValidatorTestHarness#getInRangeNumber() - */ - protected Number getInRangeNumber() { - return new Double(1); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.StringToNumberValidatorTestHarness#getInvalidString() - */ - protected String getInvalidString() { - return "1a"; - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.StringToNumberValidatorTestHarness#getOutOfRangeNumber() - */ - protected Number getOutOfRangeNumber() { - BigDecimal decimal = new BigDecimal(Double.MAX_VALUE); - return decimal.add(new BigDecimal(Double.MAX_VALUE)); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.StringToNumberValidatorTestHarness#setupNumberFormat() - */ - protected NumberFormat setupNumberFormat() { - return NumberFormat.getInstance(); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.StringToNumberValidatorTestHarness#setupValidator(com.ibm.icu.text.NumberFormat) - */ - protected IValidator setupValidator(NumberFormat numberFormat) { - StringToNumberConverter converter = StringToNumberConverter.toDouble(numberFormat, false); - return new StringToDoubleValidator(converter); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/StringToFloatValidatorTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/StringToFloatValidatorTest.java deleted file mode 100644 index d7ec0329..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/StringToFloatValidatorTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.validation; - -import org.eclipse.core.databinding.conversion.StringToNumberConverter; -import org.eclipse.core.databinding.validation.IValidator; -import org.eclipse.core.internal.databinding.validation.StringToFloatValidator; - -import com.ibm.icu.text.NumberFormat; - -/** - * @since 1.1 - */ -public class StringToFloatValidatorTest extends - StringToNumberValidatorTestHarness { - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.StringToNumberValidatorTestHarness#getInRangeNumber() - */ - protected Number getInRangeNumber() { - return new Float(1); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.StringToNumberValidatorTestHarness#getInvalidString() - */ - protected String getInvalidString() { - return "1a"; - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.StringToNumberValidatorTestHarness#getOutOfRangeNumber() - */ - protected Number getOutOfRangeNumber() { - return new Double(Double.MAX_VALUE); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.StringToNumberValidatorTestHarness#setupNumberFormat() - */ - protected NumberFormat setupNumberFormat() { - return NumberFormat.getInstance(); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.StringToNumberValidatorTestHarness#setupValidator(com.ibm.icu.text.NumberFormat) - */ - protected IValidator setupValidator(NumberFormat numberFormat) { - StringToNumberConverter converter = StringToNumberConverter.toFloat(numberFormat, false); - return new StringToFloatValidator(converter); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/StringToIntegerValidatorTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/StringToIntegerValidatorTest.java deleted file mode 100644 index d854d0b6..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/StringToIntegerValidatorTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.validation; - -import org.eclipse.core.databinding.conversion.StringToNumberConverter; -import org.eclipse.core.databinding.validation.IValidator; -import org.eclipse.core.internal.databinding.validation.StringToIntegerValidator; - -import com.ibm.icu.text.NumberFormat; - -/** - * @since 1.1 - */ -public class StringToIntegerValidatorTest extends - StringToNumberValidatorTestHarness { - /* - * (non-Javadoc) - * - * @see org.eclipse.core.tests.internal.databinding.validation.StringToNumberValidatorTestHarness#setupNumberFormat() - */ - protected NumberFormat setupNumberFormat() { - return NumberFormat.getIntegerInstance(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.tests.internal.databinding.validation.StringToNumberValidatorTestHarness#setupValidator(com.ibm.icu.text.NumberFormat) - */ - protected IValidator setupValidator(NumberFormat numberFormat) { - StringToNumberConverter converter = StringToNumberConverter.toInteger( - numberFormat, false); - return new StringToIntegerValidator(converter); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.tests.internal.databinding.validation.StringToNumberValidatorTestHarness#getInRangeNumber() - */ - protected Number getInRangeNumber() { - return new Integer(1); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.tests.internal.databinding.validation.StringToNumberValidatorTestHarness#getInvalidString() - */ - protected String getInvalidString() { - return "1.1"; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.tests.internal.databinding.validation.StringToNumberValidatorTestHarness#getOutOfRangeNumber() - */ - protected Number getOutOfRangeNumber() { - return new Double(Double.MAX_VALUE); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/StringToLongValidatorTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/StringToLongValidatorTest.java deleted file mode 100644 index 97f76474..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/StringToLongValidatorTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.validation; - -import org.eclipse.core.databinding.conversion.StringToNumberConverter; -import org.eclipse.core.databinding.validation.IValidator; -import org.eclipse.core.internal.databinding.validation.NumberFormatConverter; -import org.eclipse.core.internal.databinding.validation.StringToLongValidator; - -import com.ibm.icu.text.NumberFormat; - -/** - * @since 1.1 - */ -public class StringToLongValidatorTest extends StringToNumberValidatorTestHarness { - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.StringToNumberValidatorTestHarness#getInRangeNumber() - */ - protected Number getInRangeNumber() { - return new Long(1); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.StringToNumberValidatorTestHarness#getInvalidString() - */ - protected String getInvalidString() { - return "1.1"; - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.StringToNumberValidatorTestHarness#getOutOfRangeNumber() - */ - protected Number getOutOfRangeNumber() { - return new Double(Double.MAX_VALUE); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.StringToNumberValidatorTestHarness#setupNumberFormat() - */ - protected NumberFormat setupNumberFormat() { - return NumberFormat.getIntegerInstance(); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.StringToNumberValidatorTestHarness#setupValidator() - */ - protected IValidator setupValidator(NumberFormat numberFormat) { - NumberFormatConverter converter = StringToNumberConverter.toInteger(numberFormat, false); - return new StringToLongValidator(converter); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/StringToNumberValidatorTestHarness.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/StringToNumberValidatorTestHarness.java deleted file mode 100644 index 9e62ec32..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/StringToNumberValidatorTestHarness.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.validation; - -import junit.framework.TestCase; - -import org.eclipse.core.databinding.validation.IValidator; -import org.eclipse.core.runtime.IStatus; - -import com.ibm.icu.text.NumberFormat; - -/** - * A test harness for testing string to number validators. - * - * @since 1.1 - */ -public abstract class StringToNumberValidatorTestHarness extends TestCase { - private NumberFormat numberFormat; - private IValidator validator; - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - - numberFormat = setupNumberFormat(); - validator = setupValidator(numberFormat); - } - - /** - * Invoked during setup to instantiate the number format. - * - * @return number format - */ - protected abstract NumberFormat setupNumberFormat(); - - /** - * Invoked during setup to instantiate the validator. - * - * @param numberFormat - * @return validator - */ - protected abstract IValidator setupValidator(NumberFormat numberFormat); - - /** - * Returns a string value that will not parse. - * - * @return string - */ - protected abstract String getInvalidString(); - - /** - * Returns a number value that is out of range for the validator. - * - * @return number - */ - protected abstract Number getOutOfRangeNumber(); - - /** - * Returns a number that is in range for the validator. - * - * @return number - */ - protected abstract Number getInRangeNumber(); - - public void testInvalidValueReturnsError() throws Exception { - IStatus status = validator.validate(getInvalidString()); - assertEquals("error severify", IStatus.ERROR, status.getSeverity()); - assertNotNull("message not null", status.getMessage()); - } - - public void testOutOfRangeValueReturnsError() throws Exception { - String string = numberFormat.format(getOutOfRangeNumber()); - IStatus status = validator.validate(string); - assertEquals(IStatus.ERROR, status.getSeverity()); - assertNotNull(status.getMessage()); - } - - public void testValidateValidValue() throws Exception { - String string = numberFormat.format(getInRangeNumber()); - assertTrue(validator.validate(string).isOK()); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/StringToShortValidatorTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/StringToShortValidatorTest.java deleted file mode 100644 index 9de5b389..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/validation/StringToShortValidatorTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.validation; - -import org.eclipse.core.databinding.validation.IValidator; -import org.eclipse.core.internal.databinding.conversion.StringToShortConverter; -import org.eclipse.core.internal.databinding.validation.StringToShortValidator; - -import com.ibm.icu.text.NumberFormat; - -/** - * @since 1.1 - */ -public class StringToShortValidatorTest extends - StringToNumberValidatorTestHarness { - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.StringToNumberValidatorTestHarness#getInRangeNumber() - */ - protected Number getInRangeNumber() { - return new Short(Short.MAX_VALUE); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.StringToNumberValidatorTestHarness#getInvalidString() - */ - protected String getInvalidString() { - return "1.1"; - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.StringToNumberValidatorTestHarness#getOutOfRangeNumber() - */ - protected Number getOutOfRangeNumber() { - return new Integer(Short.MAX_VALUE + 1); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.StringToNumberValidatorTestHarness#setupNumberFormat() - */ - protected NumberFormat setupNumberFormat() { - return NumberFormat.getIntegerInstance(); - } - - /* (non-Javadoc) - * @see org.eclipse.core.tests.internal.databinding.validation.StringToNumberValidatorTestHarness#setupValidator(com.ibm.icu.text.NumberFormat) - */ - protected IValidator setupValidator(NumberFormat numberFormat) { - StringToShortConverter converter = StringToShortConverter.toShort(numberFormat, false); - return new StringToShortValidator(converter); - } - -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/AbstractDefaultRealmTestCase.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/AbstractDefaultRealmTestCase.java deleted file mode 100644 index c6fd4a9a..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/AbstractDefaultRealmTestCase.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - ******************************************************************************/ - -package org.eclipse.jface.tests.databinding; - -import junit.framework.TestCase; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.jface.databinding.conformance.util.RealmTester; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.swt.widgets.Display; - -/** - * Base class that sets the default realm to be the SWT realm. - * - * @since 3.3 - */ -public class AbstractDefaultRealmTestCase extends TestCase { - private Realm previousRealm; - - /** - * Sets the default realm to be the realm for the default display. - * - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - - previousRealm = Realm.getDefault(); - - Display display = Display.getCurrent() != null - && !Display.getCurrent().isDisposed() ? Display.getCurrent() - : Display.getDefault(); - RealmTester.setDefault(SWTObservables.getRealm(display)); - } - - /** - * Removes the default realm. - */ - protected void tearDown() throws Exception { - super.tearDown(); - - RealmTester.setDefault(previousRealm); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/AbstractSWTTestCase.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/AbstractSWTTestCase.java deleted file mode 100644 index 32f0cdb5..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/AbstractSWTTestCase.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Ashley Cambrell - bug 198904 - ******************************************************************************/ - -package org.eclipse.jface.tests.databinding; - -import org.eclipse.swt.widgets.Shell; - -/** - * Abstract test case that handles disposing of the Shell after each test. - * - * @since 1.1 - */ -public abstract class AbstractSWTTestCase extends AbstractDefaultRealmTestCase { - private Shell shell; - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase#tearDown() - */ - protected void tearDown() throws Exception { - super.tearDown(); - - if (shell != null && !shell.isDisposed()) { - shell.dispose(); - } - } - - /** - * Returns a Shell to be used in a test. - * - * @return shell - */ - protected Shell getShell() { - if (shell == null || shell.isDisposed()) { - shell = new Shell(); - } - - return shell; - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/BindingTestSetup.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/BindingTestSetup.java deleted file mode 100644 index 7ef5f670..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/BindingTestSetup.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.jface.tests.databinding; - -import java.util.Locale; - -import org.eclipse.core.databinding.util.ILogger; -import org.eclipse.core.databinding.util.Policy; -import org.eclipse.core.runtime.IStatus; - -import junit.extensions.TestSetup; -import junit.framework.Test; - -/** - * @since 3.2 - * - */ -public class BindingTestSetup extends TestSetup { - - private Locale oldLocale; - private ILogger oldLogger; - private org.eclipse.jface.util.ILogger oldJFaceLogger; - - public BindingTestSetup(Test test) { - super(test); - } - - protected void setUp() throws Exception { - super.setUp(); - oldLocale = Locale.getDefault(); - Locale.setDefault(Locale.US); - oldLogger = Policy.getLog(); - Policy.setLog(new ILogger() { - public void log(IStatus status) { - // we are not expecting anything in the log while we test. - if (status.getException() != null) { - throw new RuntimeException(status.getException()); - } - fail(); - } - }); - oldJFaceLogger = org.eclipse.jface.util.Policy.getLog(); - org.eclipse.jface.util.Policy.setLog(new org.eclipse.jface.util.ILogger(){ - public void log(IStatus status) { - // we are not expecting anything in the log while we test. - if (status.getException() != null) { - throw new RuntimeException(status.getException()); - } - fail(); - } - }); - } - - protected void tearDown() throws Exception { - Locale.setDefault(oldLocale); - Policy.setLog(oldLogger); - org.eclipse.jface.util.Policy.setLog(oldJFaceLogger); - super.tearDown(); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/BindingTestSuite.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/BindingTestSuite.java deleted file mode 100644 index 7efe7955..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/BindingTestSuite.java +++ /dev/null @@ -1,419 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005-2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bugs 137877, 152543, 152540, 116920, 164247, 164653, - * 159768, 170848, 147515 - * Bob Smith - bug 198880 - * Ashley Cambrell - bugs 198903, 198904 - * Matthew Hall - bugs 210115, 212468, 212223, 206839, 208858, 208322, - * 212518, 215531, 221351, 184830, 213145, 218269, 239015, - * 245183 - * Ovidio Mallo - bug 235195 - *******************************************************************************/ -package org.eclipse.jface.tests.databinding; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.eclipse.core.tests.databinding.AggregateValidationStatusTest; -import org.eclipse.core.tests.databinding.DatabindingContextTest; -import org.eclipse.core.tests.databinding.ListBindingTest; -import org.eclipse.core.tests.databinding.ObservablesManagerTest; -import org.eclipse.core.tests.databinding.UpdateStrategyTest; -import org.eclipse.core.tests.databinding.UpdateValueStrategyTest; -import org.eclipse.core.tests.databinding.ValueBindingTest; -import org.eclipse.core.tests.databinding.beans.BeansObservablesTest; -import org.eclipse.core.tests.databinding.beans.PojoObservablesTest; -import org.eclipse.core.tests.databinding.conversion.NumberToStringConverterTest; -import org.eclipse.core.tests.databinding.conversion.StringToNumberConverterTest; -import org.eclipse.core.tests.databinding.observable.AbstractObservableTest; -import org.eclipse.core.tests.databinding.observable.DiffsTest; -import org.eclipse.core.tests.databinding.observable.Diffs_ListDiffTests; -import org.eclipse.core.tests.databinding.observable.ObservableTrackerTest; -import org.eclipse.core.tests.databinding.observable.ObservablesTest; -import org.eclipse.core.tests.databinding.observable.RealmTest; -import org.eclipse.core.tests.databinding.observable.list.AbstractObservableListTest; -import org.eclipse.core.tests.databinding.observable.list.ComputedListTest; -import org.eclipse.core.tests.databinding.observable.list.ListDiffTest; -import org.eclipse.core.tests.databinding.observable.list.ListDiffVisitorTest; -import org.eclipse.core.tests.databinding.observable.list.ObservableListTest; -import org.eclipse.core.tests.databinding.observable.list.WritableListTest; -import org.eclipse.core.tests.databinding.observable.map.AbstractObservableMapTest; -import org.eclipse.core.tests.databinding.observable.map.CompositeMapTest; -import org.eclipse.core.tests.databinding.observable.map.ObservableMapTest; -import org.eclipse.core.tests.databinding.observable.map.WritableMapTest; -import org.eclipse.core.tests.databinding.observable.set.AbstractObservableSetTest; -import org.eclipse.core.tests.databinding.observable.set.ObservableSetTest; -import org.eclipse.core.tests.databinding.observable.set.UnionSetTest; -import org.eclipse.core.tests.databinding.observable.set.WritableSetTest; -import org.eclipse.core.tests.databinding.observable.value.AbstractObservableValueTest; -import org.eclipse.core.tests.databinding.observable.value.AbstractVetoableValueTest; -import org.eclipse.core.tests.databinding.observable.value.ComputedValueTest; -import org.eclipse.core.tests.databinding.observable.value.WritableValueTest; -import org.eclipse.core.tests.databinding.validation.MultiValidatorTest; -import org.eclipse.core.tests.databinding.validation.ValidationStatusTest; -import org.eclipse.core.tests.internal.databinding.BindingMessagesTest; -import org.eclipse.core.tests.internal.databinding.BindingStatusTest; -import org.eclipse.core.tests.internal.databinding.QueueTest; -import org.eclipse.core.tests.internal.databinding.RandomAccessListIteratorTest; -import org.eclipse.core.tests.internal.databinding.beans.BeanObservableListDecoratorTest; -import org.eclipse.core.tests.internal.databinding.beans.BeanObservableMapDecoratorTest; -import org.eclipse.core.tests.internal.databinding.beans.BeanObservableSetDecoratorTest; -import org.eclipse.core.tests.internal.databinding.beans.BeanObservableValueDecoratorTest; -import org.eclipse.core.tests.internal.databinding.beans.JavaBeanObservableArrayBasedListTest; -import org.eclipse.core.tests.internal.databinding.beans.JavaBeanObservableArrayBasedSetTest; -import org.eclipse.core.tests.internal.databinding.beans.JavaBeanObservableListTest; -import org.eclipse.core.tests.internal.databinding.beans.JavaBeanObservableMapTest; -import org.eclipse.core.tests.internal.databinding.beans.JavaBeanObservableSetTest; -import org.eclipse.core.tests.internal.databinding.beans.JavaBeanObservableValueTest; -import org.eclipse.core.tests.internal.databinding.beans.JavaBeanPropertyObservableMapTest; -import org.eclipse.core.tests.internal.databinding.beans.ListenerSupportTest; -import org.eclipse.core.tests.internal.databinding.conversion.DateConversionSupportTest; -import org.eclipse.core.tests.internal.databinding.conversion.IdentityConverterTest; -import org.eclipse.core.tests.internal.databinding.conversion.IntegerToStringConverterTest; -import org.eclipse.core.tests.internal.databinding.conversion.NumberToBigDecimalTest; -import org.eclipse.core.tests.internal.databinding.conversion.NumberToBigIntegerConverterTest; -import org.eclipse.core.tests.internal.databinding.conversion.NumberToByteConverterTest; -import org.eclipse.core.tests.internal.databinding.conversion.NumberToDoubleConverterTest; -import org.eclipse.core.tests.internal.databinding.conversion.NumberToFloatConverterTest; -import org.eclipse.core.tests.internal.databinding.conversion.NumberToIntegerConverterTest; -import org.eclipse.core.tests.internal.databinding.conversion.NumberToLongConverterTest; -import org.eclipse.core.tests.internal.databinding.conversion.NumberToShortConverterTest; -import org.eclipse.core.tests.internal.databinding.conversion.ObjectToPrimitiveValidatorTest; -import org.eclipse.core.tests.internal.databinding.conversion.StatusToStringConverterTest; -import org.eclipse.core.tests.internal.databinding.conversion.StringToBooleanConverterTest; -import org.eclipse.core.tests.internal.databinding.conversion.StringToByteConverterTest; -import org.eclipse.core.tests.internal.databinding.conversion.StringToCharacterConverterTest; -import org.eclipse.core.tests.internal.databinding.conversion.StringToNumberParserByteTest; -import org.eclipse.core.tests.internal.databinding.conversion.StringToNumberParserDoubleTest; -import org.eclipse.core.tests.internal.databinding.conversion.StringToNumberParserFloatTest; -import org.eclipse.core.tests.internal.databinding.conversion.StringToNumberParserIntegerTest; -import org.eclipse.core.tests.internal.databinding.conversion.StringToNumberParserLongTest; -import org.eclipse.core.tests.internal.databinding.conversion.StringToNumberParserShortTest; -import org.eclipse.core.tests.internal.databinding.conversion.StringToNumberParserTest; -import org.eclipse.core.tests.internal.databinding.conversion.StringToShortConverterTest; -import org.eclipse.core.tests.internal.databinding.observable.ConstantObservableValueTest; -import org.eclipse.core.tests.internal.databinding.observable.EmptyObservableListTest; -import org.eclipse.core.tests.internal.databinding.observable.EmptyObservableSetTest; -import org.eclipse.core.tests.internal.databinding.observable.MapEntryObservableValueTest; -import org.eclipse.core.tests.internal.databinding.observable.ProxyObservableListTest; -import org.eclipse.core.tests.internal.databinding.observable.ProxyObservableSetTest; -import org.eclipse.core.tests.internal.databinding.observable.StalenessObservableValueTest; -import org.eclipse.core.tests.internal.databinding.observable.UnmodifiableObservableListTest; -import org.eclipse.core.tests.internal.databinding.observable.UnmodifiableObservableSetTest; -import org.eclipse.core.tests.internal.databinding.observable.ValidatedObservableListTest; -import org.eclipse.core.tests.internal.databinding.observable.ValidatedObservableSetTest; -import org.eclipse.core.tests.internal.databinding.observable.ValidatedObservableValueTest; -import org.eclipse.core.tests.internal.databinding.observable.masterdetail.DetailObservableListTest; -import org.eclipse.core.tests.internal.databinding.observable.masterdetail.DetailObservableSetTest; -import org.eclipse.core.tests.internal.databinding.observable.masterdetail.DetailObservableValueTest; -import org.eclipse.core.tests.internal.databinding.validation.AbstractStringToNumberValidatorTest; -import org.eclipse.core.tests.internal.databinding.validation.NumberToByteValidatorTest; -import org.eclipse.core.tests.internal.databinding.validation.NumberToDoubleValidatorTest; -import org.eclipse.core.tests.internal.databinding.validation.NumberToFloatValidatorTest; -import org.eclipse.core.tests.internal.databinding.validation.NumberToIntegerValidatorTest; -import org.eclipse.core.tests.internal.databinding.validation.NumberToLongValidatorTest; -import org.eclipse.core.tests.internal.databinding.validation.NumberToShortValidatorTest; -import org.eclipse.core.tests.internal.databinding.validation.NumberToUnboundedNumberValidatorTest; -import org.eclipse.core.tests.internal.databinding.validation.StringToByteValidatorTest; -import org.eclipse.core.tests.internal.databinding.validation.StringToCharacterValidatorTest; -import org.eclipse.core.tests.internal.databinding.validation.StringToDoubleValidatorTest; -import org.eclipse.core.tests.internal.databinding.validation.StringToFloatValidatorTest; -import org.eclipse.core.tests.internal.databinding.validation.StringToIntegerValidatorTest; -import org.eclipse.core.tests.internal.databinding.validation.StringToLongValidatorTest; -import org.eclipse.core.tests.internal.databinding.validation.StringToShortValidatorTest; -import org.eclipse.jface.tests.databinding.scenarios.BindingScenariosTestSuite; -import org.eclipse.jface.tests.databinding.swt.SWTObservablesTest; -import org.eclipse.jface.tests.databinding.viewers.ObservableListTreeContentProviderTest; -import org.eclipse.jface.tests.databinding.viewers.ObservableMapLabelProviderTest; -import org.eclipse.jface.tests.databinding.viewers.ObservableSetContentProviderTest; -import org.eclipse.jface.tests.databinding.viewers.ObservableSetTreeContentProviderTest; -import org.eclipse.jface.tests.databinding.viewers.ViewersObservablesTest; -import org.eclipse.jface.tests.databinding.wizard.WizardPageSupportTest; -import org.eclipse.jface.tests.examples.databinding.mask.internal.EditMaskLexerAndTokenTest; -import org.eclipse.jface.tests.examples.databinding.mask.internal.EditMaskParserTest; -import org.eclipse.jface.tests.internal.databinding.swt.ButtonObservableValueTest; -import org.eclipse.jface.tests.internal.databinding.swt.CComboObservableValueSelectionTest; -import org.eclipse.jface.tests.internal.databinding.swt.CComboObservableValueTest; -import org.eclipse.jface.tests.internal.databinding.swt.CComboObservableValueTextTest; -import org.eclipse.jface.tests.internal.databinding.swt.CComboSingleSelectionObservableValueTest; -import org.eclipse.jface.tests.internal.databinding.swt.CLabelObservableValueTest; -import org.eclipse.jface.tests.internal.databinding.swt.ComboObservableValueSelectionTest; -import org.eclipse.jface.tests.internal.databinding.swt.ComboObservableValueTest; -import org.eclipse.jface.tests.internal.databinding.swt.ComboObservableValueTextTest; -import org.eclipse.jface.tests.internal.databinding.swt.ComboSingleSelectionObservableValueTest; -import org.eclipse.jface.tests.internal.databinding.swt.ControlObservableValueTest; -import org.eclipse.jface.tests.internal.databinding.swt.DelayedObservableValueTest; -import org.eclipse.jface.tests.internal.databinding.swt.LabelObservableValueTest; -import org.eclipse.jface.tests.internal.databinding.swt.ListSingleSelectionObservableValueTest; -import org.eclipse.jface.tests.internal.databinding.swt.SWTObservableListTest; -import org.eclipse.jface.tests.internal.databinding.swt.ScaleObservableValueMaxTest; -import org.eclipse.jface.tests.internal.databinding.swt.ScaleObservableValueMinTest; -import org.eclipse.jface.tests.internal.databinding.swt.ScaleObservableValueSelectionTest; -import org.eclipse.jface.tests.internal.databinding.swt.ShellObservableValueTest; -import org.eclipse.jface.tests.internal.databinding.swt.SpinnerObservableValueMaxTest; -import org.eclipse.jface.tests.internal.databinding.swt.SpinnerObservableValueMinTest; -import org.eclipse.jface.tests.internal.databinding.swt.SpinnerObservableValueSelectionTest; -import org.eclipse.jface.tests.internal.databinding.swt.SpinnerObservableValueTest; -import org.eclipse.jface.tests.internal.databinding.swt.TableObservableValueTest; -import org.eclipse.jface.tests.internal.databinding.swt.TableSingleSelectionObservableValueTest; -import org.eclipse.jface.tests.internal.databinding.swt.TextEditableObservableValueTest; -import org.eclipse.jface.tests.internal.databinding.swt.TextObservableValueFocusOutTest; -import org.eclipse.jface.tests.internal.databinding.swt.TextObservableValueModifyTest; -import org.eclipse.jface.tests.internal.databinding.swt.TextObservableValueTest; -import org.eclipse.jface.tests.internal.databinding.viewers.ObservableCollectionTreeContentProviderTest; -import org.eclipse.jface.tests.internal.databinding.viewers.ObservableViewerElementSetTest; -import org.eclipse.jface.tests.internal.databinding.viewers.SelectionProviderMultiSelectionObservableListTest; -import org.eclipse.jface.tests.internal.databinding.viewers.SelectionProviderSingleSelectionObservableValueTest; -import org.eclipse.jface.tests.internal.databinding.viewers.ViewerElementMapTest; -import org.eclipse.jface.tests.internal.databinding.viewers.ViewerElementSetTest; -import org.eclipse.jface.tests.internal.databinding.viewers.ViewerElementWrapperTest; -import org.eclipse.jface.tests.internal.databinding.viewers.ViewerInputObservableValueTest; - -public class BindingTestSuite extends TestSuite { - - public static void main(String[] args) { - junit.textui.TestRunner.run(suite()); - } - - public static Test suite() { - return new BindingTestSetup(new BindingTestSuite()); - } - - public BindingTestSuite() { - // org.eclipse.core.tests.databinding - addTestSuite(AggregateValidationStatusTest.class); - addTestSuite(DatabindingContextTest.class); - addTestSuite(ListBindingTest.class); - addTestSuite(UpdateStrategyTest.class); - addTestSuite(UpdateValueStrategyTest.class); - addTestSuite(ValueBindingTest.class); - addTestSuite(ObservablesManagerTest.class); - - // org.eclipse.core.tests.databinding.beans - addTestSuite(BeansObservablesTest.class); - addTestSuite(PojoObservablesTest.class); - - // org.eclipse.core.tests.databinding.conversion - addTestSuite(NumberToStringConverterTest.class); - addTestSuite(StringToNumberConverterTest.class); - - // org.eclipse.core.tests.databinding.observable - addTest(AbstractObservableTest.suite()); - addTestSuite(Diffs_ListDiffTests.class); - addTestSuite(DiffsTest.class); - addTestSuite(ObservablesTest.class); - addTestSuite(ObservableTrackerTest.class); - addTestSuite(RealmTest.class); - - // org.eclipse.core.tests.databinding.observable.list - addTest(AbstractObservableListTest.suite()); - addTest(ComputedListTest.suite()); - addTestSuite(ListDiffTest.class); - addTestSuite(ListDiffVisitorTest.class); - addTest(ObservableListTest.suite()); - addTest(WritableListTest.suite()); - - // org.eclipse.core.tests.databinding.observable.map - addTestSuite(AbstractObservableMapTest.class); - addTestSuite(ObservableMapTest.class); - addTestSuite(WritableMapTest.class); - addTestSuite(CompositeMapTest.class); - - // org.eclipse.core.tests.databinding.observable.set - addTest(AbstractObservableSetTest.suite()); - addTest(ObservableSetTest.suite()); - addTest(UnionSetTest.suite()); - addTest(WritableSetTest.suite()); - - //org.eclipse.core.tests.databinding.observable.value - addTestSuite(AbstractObservableValueTest.class); - addTestSuite(AbstractVetoableValueTest.class); - addTestSuite(ComputedValueTest.class); - addTest(WritableValueTest.suite()); - - //org.eclipse.core.tests.databinding.validation - addTestSuite(MultiValidatorTest.class); - addTestSuite(ValidationStatusTest.class); - - // org.eclipse.core.tests.internal.databinding - addTestSuite(BindingMessagesTest.class); - addTestSuite(BindingStatusTest.class); - addTestSuite(RandomAccessListIteratorTest.class); - addTestSuite(QueueTest.class); - - // org.eclipse.core.tests.internal.databinding.conversion - addTestSuite(DateConversionSupportTest.class); - addTestSuite(IdentityConverterTest.class); - addTestSuite(IntegerToStringConverterTest.class); - addTestSuite(NumberToBigDecimalTest.class); - addTestSuite(NumberToBigIntegerConverterTest.class); - addTestSuite(NumberToByteConverterTest.class); - addTestSuite(NumberToDoubleConverterTest.class); - addTestSuite(NumberToFloatConverterTest.class); - addTestSuite(NumberToIntegerConverterTest.class); - addTestSuite(NumberToLongConverterTest.class); - addTestSuite(NumberToShortConverterTest.class); - addTestSuite(ObjectToPrimitiveValidatorTest.class); - addTestSuite(StatusToStringConverterTest.class); - addTestSuite(StringToBooleanConverterTest.class); - addTestSuite(StringToByteConverterTest.class); - addTestSuite(StringToCharacterConverterTest.class); - addTestSuite(StringToNumberParserByteTest.class); - addTestSuite(StringToNumberParserDoubleTest.class); - addTestSuite(StringToNumberParserFloatTest.class); - addTestSuite(StringToNumberParserIntegerTest.class); - addTestSuite(StringToNumberParserLongTest.class); - addTestSuite(StringToNumberParserShortTest.class); - addTestSuite(StringToNumberParserTest.class); - addTestSuite(StringToShortConverterTest.class); - - //org.eclipse.core.tests.internal.databinding.internal.beans - addTest(BeanObservableListDecoratorTest.suite()); - addTestSuite(BeanObservableMapDecoratorTest.class); - addTestSuite(BeanObservableSetDecoratorTest.class); - addTestSuite(BeanObservableValueDecoratorTest.class); - addTest(JavaBeanObservableArrayBasedListTest.suite()); - addTest(JavaBeanObservableArrayBasedSetTest.suite()); - addTest(JavaBeanObservableListTest.suite()); - addTest(JavaBeanObservableMapTest.suite()); - addTest(JavaBeanPropertyObservableMapTest.suite()); - addTest(JavaBeanObservableSetTest.suite()); - addTest(JavaBeanObservableValueTest.suite()); - addTestSuite(ListenerSupportTest.class); - - //org.eclipse.core.tests.internal.databinding.observable - addTest(ConstantObservableValueTest.suite()); - addTest(EmptyObservableListTest.suite()); - addTest(EmptyObservableSetTest.suite()); - addTest(MapEntryObservableValueTest.suite()); - addTest(ProxyObservableListTest.suite()); - addTest(ProxyObservableSetTest.suite()); - addTest(StalenessObservableValueTest.suite()); - addTest(UnmodifiableObservableListTest.suite()); - addTest(UnmodifiableObservableSetTest.suite()); - addTest(ValidatedObservableValueTest.suite()); - addTest(ValidatedObservableListTest.suite()); - addTest(ValidatedObservableSetTest.suite()); -// addTest(ValidatedObservableMapTest.suite()); - - // org.eclipse.core.tests.internal.databinding.observable.masterdetail - addTest(DetailObservableListTest.suite()); - addTest(DetailObservableSetTest.suite()); - addTest(DetailObservableValueTest.suite()); - - // org.eclipse.core.tests.internal.databinding.validation - addTestSuite(AbstractStringToNumberValidatorTest.class); - addTestSuite(NumberToByteValidatorTest.class); - addTestSuite(NumberToDoubleValidatorTest.class); - addTestSuite(NumberToFloatValidatorTest.class); - addTestSuite(NumberToIntegerValidatorTest.class); - addTestSuite(NumberToLongValidatorTest.class); - addTestSuite(NumberToShortValidatorTest.class); - addTestSuite(NumberToUnboundedNumberValidatorTest.class); - addTestSuite(StringToByteValidatorTest.class); - addTestSuite(StringToCharacterValidatorTest.class); - addTestSuite(StringToDoubleValidatorTest.class); - addTestSuite(StringToFloatValidatorTest.class); - addTestSuite(StringToIntegerValidatorTest.class); - addTestSuite(StringToLongValidatorTest.class); - addTestSuite(StringToShortValidatorTest.class); - - // org.eclipse.jface.tests.databinding.scenarios - addTest(BindingScenariosTestSuite.suite()); - // The files in this package are in the above test suite - - //org.eclipse.jface.tests.databinding.swt - addTestSuite(SWTObservablesTest.class); - - // org.eclipse.jface.tests.databinding.viewers - addTestSuite(ObservableListTreeContentProviderTest.class); - addTestSuite(ObservableMapLabelProviderTest.class); - addTestSuite(ObservableSetContentProviderTest.class); - addTestSuite(ObservableSetTreeContentProviderTest.class); - addTestSuite(ViewersObservablesTest.class); - - // org.eclipse.jface.tests.databinding.wizard - addTestSuite(WizardPageSupportTest.class); - - //org.eclipse.jface.tests.example.databinding.mask.internal - addTestSuite(EditMaskLexerAndTokenTest.class); - addTestSuite(EditMaskParserTest.class); - - //org.eclipse.jface.tests.internal.databinding.internal.swt - addTest(ButtonObservableValueTest.suite()); - addTestSuite(CComboObservableValueTest.class); - addTest(CComboObservableValueSelectionTest.suite()); - addTest(CComboObservableValueTextTest.suite()); - addTestSuite(CComboSingleSelectionObservableValueTest.class); - addTest(CComboSingleSelectionObservableValueTest.suite()); - addTest(CLabelObservableValueTest.suite()); - addTestSuite(ComboObservableValueTest.class); - addTest(ComboObservableValueSelectionTest.suite()); - addTest(ComboObservableValueTextTest.suite()); - addTestSuite(ComboSingleSelectionObservableValueTest.class); - addTest(DelayedObservableValueTest.suite()); - - addTest(SWTObservableListTest.suite()); - - addTestSuite(ControlObservableValueTest.class); - addTest(LabelObservableValueTest.suite()); - addTestSuite(ListSingleSelectionObservableValueTest.class); - addTest(ScaleObservableValueMinTest.suite()); - addTest(ScaleObservableValueMaxTest.suite()); - addTest(ScaleObservableValueSelectionTest.suite()); - - addTest(ShellObservableValueTest.suite()); - - addTestSuite(SpinnerObservableValueTest.class); - addTest(SpinnerObservableValueMinTest.suite()); - addTest(SpinnerObservableValueMaxTest.suite()); - addTest(SpinnerObservableValueSelectionTest.suite()); - - addTestSuite(TableObservableValueTest.class); - addTest(TableSingleSelectionObservableValueTest.suite()); - addTest(TextEditableObservableValueTest.suite()); - addTest(TextObservableValueFocusOutTest.suite()); - addTest(TextObservableValueModifyTest.suite()); - addTestSuite(TextObservableValueTest.class); - - //org.eclipse.jface.tests.internal.databinding.internal.viewers - addTest(ObservableViewerElementSetTest.suite()); - addTestSuite(ObservableCollectionTreeContentProviderTest.class); - addTestSuite(SelectionProviderMultiSelectionObservableListTest.class); - addTestSuite(SelectionProviderSingleSelectionObservableValueTest.class); - addTestSuite(ViewerElementMapTest.class); - addTestSuite(ViewerElementSetTest.class); - addTestSuite(ViewerElementWrapperTest.class); - addTest(ViewerInputObservableValueTest.suite()); - } - - /** - * @param testCase - * TODO - * @return true if the given test is temporarily disabled - */ - public static boolean failingTestsDisabled(TestCase testCase) { - System.out.println("Ignoring disabled test: " - + testCase.getClass().getName() + "." + testCase.getName()); - return true; - } - - /** - * @param testSuite - * TODO - * @return true if the given test is temporarily disabled - */ - public static boolean failingTestsDisabled(TestSuite testSuite) { - System.out.println("Ignoring disabled test: " - + testSuite.getClass().getName() + "." + testSuite.getName()); - return true; - } -}
\ No newline at end of file diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/AutomationUtil.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/AutomationUtil.java deleted file mode 100644 index 9e881ae6..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/AutomationUtil.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.tests.databinding.scenarios; - -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; - -/** - * COPIED FROM org.eclipse.ui.tests - * <code>AutomationUtil</code> contains utility methods to mimic key events. - * Mouse event methods can be added if needed to complete this class. - */ - -public class AutomationUtil { - - /** - * Method to mimic a key code event on a display. - * - * @param display - * The display. - * @param eventType - * The event type. - * @param keyCode - * The key code. - */ - public static void performKeyCodeEvent(Display display, int eventType, - int keyCode) { - Event event = new Event(); - event.type = eventType; - event.keyCode = keyCode; - display.post(event); - } - - /** - * Method to mimic a character event on a display. - * - * @param display - * The display. - * @param eventType - * The event type. - * @param character - * The character to mimic. - */ - public static void performCharacterEvent(Display display, int eventType, - char character) { - Event event = new Event(); - event.type = eventType; - event.character = character; - display.post(event); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/BindingScenariosTestSuite.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/BindingScenariosTestSuite.java deleted file mode 100644 index 93fb3cb7..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/BindingScenariosTestSuite.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 116920 - *******************************************************************************/ -package org.eclipse.jface.tests.databinding.scenarios; - -import junit.extensions.TestSetup; -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; - -/** - * To run this test suite, right-click and select "Run As JUnit Plug-in Test". - * This will also start an Eclipse instance. To clean up the launch - * configuration, open up its "Main" tab and select "[No Application] - Headless - * Mode" as the application to run. You can also run this class as an SWT - * application. - */ -public class BindingScenariosTestSuite extends TestSuite { - - public static void main(String[] args) { - junit.textui.TestRunner.run(suite()); - } - - private static Display display; - - private static Shell shell; - - public static Test suite() { - return new TestSetup(new BindingScenariosTestSuite()) { - protected void setUp() throws Exception { - Display d = Display.getDefault(); - shell = new Shell(d, SWT.SHELL_TRIM); - shell.setLayout(new FillLayout()); - } - - protected void tearDown() throws Exception { - shell.close(); - shell.dispose(); - if (display != null) { - display.dispose(); - } - } - }; - } - - public BindingScenariosTestSuite() { - addTestSuite(ButtonControlScenario.class); - addTestSuite(ComboScenarios.class); - addTestSuite(ComboUpdatingTest.class); - addTestSuite(ComboViewerScenario.class); - addTestSuite(CustomConverterScenarios.class); - addTestSuite(CustomScenarios.class); - addTestSuite(ListViewerScenario.class); - addTestSuite(MasterDetailScenarios.class); - addTestSuite(NewTableScenarios.class); - addTestSuite(NPETestScenario.class); - addTestSuite(PropertyScenarios.class); - addTestSuite(SpinnerControlScenario.class); - addTestSuite(TableScenarios.class); - addTestSuite(TextControlScenario.class); - } - - public static Shell getShell() { - return shell; - } - -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/ButtonControlScenario.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/ButtonControlScenario.java deleted file mode 100644 index 5f1ac5ab..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/ButtonControlScenario.java +++ /dev/null @@ -1,118 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 116920 - *******************************************************************************/ -package org.eclipse.jface.tests.databinding.scenarios; - -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.examples.databinding.model.Adventure; -import org.eclipse.jface.examples.databinding.model.SampleData; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Button; - -/** - * To run the tests in this class, right-click and select "Run As JUnit Plug-in - * Test". This will also start an Eclipse instance. To clean up the launch - * configuration, open up its "Main" tab and select "[No Application] - Headless - * Mode" as the application to run. - */ - -public class ButtonControlScenario extends ScenariosTestCase { - - private Adventure adventure; - - private Button button; - - protected void setUp() throws Exception { - super.setUp(); - // do any setup work here - button = new Button(getComposite(), SWT.CHECK); - adventure = SampleData.WINTER_HOLIDAY; - } - - protected void tearDown() throws Exception { - button.dispose(); - super.tearDown(); - } - - public void testScenario01() { - // Bind the button's selection to the adventure "isPetsAllowed" - getDbc().bindValue(SWTObservables.observeSelection(button), - BeansObservables.observeValue(adventure, "petsAllowed"), - null, null); - - // Check the model and GUI are in the same state - assertEquals(button.getSelection(), adventure.isPetsAllowed()); - // Change the model and check the GUI is updated - boolean newBoolean = !adventure.isPetsAllowed(); - adventure.setPetsAllowed(newBoolean); - assertEquals(newBoolean, adventure.isPetsAllowed()); - assertEquals(button.getSelection(), newBoolean); - // Change the GUI and check the model - newBoolean = !newBoolean; - button.setSelection(newBoolean); - button.notifyListeners(SWT.Selection, null); - assertEquals(newBoolean, adventure.isPetsAllowed()); - newBoolean = !newBoolean; - final boolean finalNewBoolean = newBoolean; - adventure.setPetsAllowed(finalNewBoolean); - spinEventLoop(0); - assertEquals(newBoolean, button.getSelection()); - - } - - public void testScenario02() { - // Test with an SWT.Toggle button - button.dispose(); - button = new Button(getComposite(), SWT.TOGGLE); - // Bind the button's selection to the adventure "isPetsAllowed" - getDbc().bindValue(SWTObservables.observeSelection(button), - BeansObservables.observeValue(adventure, "petsAllowed"), - null, null); - - // Check the model and GUI are in the same state - assertEquals(button.getSelection(), adventure.isPetsAllowed()); - // Change the model and check the GUI is updated - boolean newBoolean = !adventure.isPetsAllowed(); - adventure.setPetsAllowed(newBoolean); - assertEquals(newBoolean, adventure.isPetsAllowed()); - assertEquals(button.getSelection(), newBoolean); - // Change the GUI and check the model - newBoolean = !newBoolean; - button.setSelection(newBoolean); - button.notifyListeners(SWT.Selection, null); - assertEquals(newBoolean, adventure.isPetsAllowed()); - } - - public void testScenario03() { - // Test with an SWT.Radio button - button.dispose(); - button = new Button(getComposite(), SWT.RADIO); - - // Bind the button's selection to the adventure "isPetsAllowed" - getDbc().bindValue(SWTObservables.observeSelection(button), - BeansObservables.observeValue(adventure, "petsAllowed"), - null, null); - - // Check the model and GUI are in the same state - assertEquals(button.getSelection(), adventure.isPetsAllowed()); - // Change the model and check the GUI is updated - boolean newBoolean = !adventure.isPetsAllowed(); - adventure.setPetsAllowed(newBoolean); - assertEquals(newBoolean, adventure.isPetsAllowed()); - assertEquals(button.getSelection(), newBoolean); - // Change the GUI and check the model - newBoolean = !newBoolean; - button.setSelection(newBoolean); - button.notifyListeners(SWT.Selection, null); - assertEquals(newBoolean, adventure.isPetsAllowed()); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/ComboScenarios.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/ComboScenarios.java deleted file mode 100644 index aefc9e25..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/ComboScenarios.java +++ /dev/null @@ -1,563 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 116920 - * Brad Reynolds - bug 160000 - *******************************************************************************/ -package org.eclipse.jface.tests.databinding.scenarios; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Locale; - -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; -import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; -import org.eclipse.jface.databinding.viewers.ViewersObservables; -import org.eclipse.jface.examples.databinding.model.Account; -import org.eclipse.jface.examples.databinding.model.Adventure; -import org.eclipse.jface.examples.databinding.model.Catalog; -import org.eclipse.jface.examples.databinding.model.Lodging; -import org.eclipse.jface.examples.databinding.model.SampleData; -import org.eclipse.jface.viewers.ComboViewer; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.widgets.Combo; - -public class ComboScenarios extends ScenariosTestCase { - - protected ComboViewer cviewer = null; - - protected Combo combo = null; - - protected Catalog catalog = null; - - ILabelProvider lodgingLabelProvider = new LabelProvider() { - public String getText(Object element) { - return ((Lodging) element).getName(); - } - }; - - ILabelProvider accountLabelProvider = new LabelProvider() { - public String getText(Object element) { - return ((Account) element).getCountry(); - } - }; - - protected void setUp() throws Exception { - super.setUp(); - getComposite().setLayout(new FillLayout()); - - combo = new Combo(getComposite(), SWT.READ_ONLY | SWT.DROP_DOWN); - cviewer = new ComboViewer(combo); - - catalog = SampleData.CATALOG_2005; // Lodging source - } - - protected void tearDown() throws Exception { - combo.dispose(); - combo = null; - cviewer = null; - super.tearDown(); - } - - protected Object getViewerSelection() { - return ((IStructuredSelection) cviewer.getSelection()) - .getFirstElement(); - } - - /** - * @return the ComboViewer's domain object list - */ - protected List getViewerContent(ComboViewer cviewer) { - Object[] elements = ((IStructuredContentProvider) cviewer - .getContentProvider()).getElements(null); - if (elements != null) - return Arrays.asList(elements); - return null; - } - - /** - * - * @return the combo's items (String[]), which is the same thing as the - * Viewer's labels - * - */ - protected List getComboContent() { - String[] elements = combo.getItems(); - if (elements != null) - return Arrays.asList(elements); - return null; - } - - protected List getColumn(Object[] list, String feature) { - List result = new ArrayList(); - if (list == null || list.length == 0) - return result; - String getterName = "get" - + feature.substring(0, 1).toUpperCase(Locale.ENGLISH) - + feature.substring(1); - try { - Method getter = list[0].getClass().getMethod(getterName, - new Class[0]); - try { - for (int i = 0; i < list.length; i++) { - result.add(getter.invoke(list[i], new Object[0])); - } - } catch (IllegalArgumentException e) { - } catch (IllegalAccessException e) { - } catch (InvocationTargetException e) { - } - } catch (SecurityException e) { - } catch (NoSuchMethodException e) { - } - return result; - } - - /** - * This test case deal with the 3rd scenario, using vanilla bindings: Ensure - * a valid content and selection are bounded correctly Bind a collection of - * Lodgings to a ComboViewer Bind the ComboViewer's selection to the - * defaultLodging of an Adventure - * - * This test does not deal with null values, empty content, changed content, - * property change of content elements, etc. - * - */ - public void test_ROCombo_Scenario03_vanilla() { - IObservableList lodgings = BeansObservables.observeList(Realm - .getDefault(), catalog, "lodgings"); - ObservableListContentProvider contentProvider = new ObservableListContentProvider(); - - IObservableMap[] attributeMaps = BeansObservables.observeMaps( - contentProvider.getKnownElements(), Lodging.class, - new String[] { "name" }); - - // Bind the ComboViewer's content to the available lodging - cviewer.setContentProvider(contentProvider); - cviewer.setLabelProvider(new ObservableMapLabelProvider(attributeMaps)); - cviewer.setInput(lodgings); - - Adventure skiAdventure = SampleData.WINTER_HOLIDAY; // selection will - - // Ensure that cv's content now has the catalog's lodgings - assertArrayEquals(catalog.getLodgings(), getViewerContent(cviewer) - .toArray()); - - // Ensure that the cv's labels are the same as the lodging descriptions - assertEquals(getColumn(catalog.getLodgings(), "name"), - getComboContent()); - - getDbc().bindValue(ViewersObservables.observeSingleSelection(cviewer), - BeansObservables.observeValue(skiAdventure, "defaultLodging"), - null, null); - - // Check to see that the initial selection is the currentDefault Lodging - assertEquals(getViewerSelection(), skiAdventure.getDefaultLodging()); - - // Change the selection of the ComboViewer to all possible lodgings, and - // verify that skiAdventure's default lodging was changed accordingly - for (int i = 0; i < catalog.getLodgings().length; i++) { - Object selection = catalog.getLodgings()[i]; - cviewer.setSelection(new StructuredSelection(selection)); - assertEquals(selection, skiAdventure.getDefaultLodging()); - assertEquals(getViewerSelection(), skiAdventure.getDefaultLodging()); - } - - } - - /** - * This test case deal with the 3rd scenario, and focuses on the collection - * binding to the combo. It will bind a collection, add/remove/change - * elements in the collection, and change element's properties to ensure - * that the combo's labels were updated appropriatly. - * - * it also induce null values in properties, and elments. - * - * This test does not deal with the combo's selection. - */ - public void test_ROCombo_Scenario03_collectionBindings() { - // column binding - // Bind the ComboViewer's content to the available lodging - IObservableList lodgings = BeansObservables.observeList(Realm - .getDefault(), catalog, "lodgings"); - ObservableListContentProvider contentProvider = new ObservableListContentProvider(); - - IObservableMap[] attributeMaps = BeansObservables.observeMaps( - contentProvider.getKnownElements(), Lodging.class, - new String[] { "name" }); - - cviewer.setContentProvider(contentProvider); - cviewer.setLabelProvider(new ObservableMapLabelProvider(attributeMaps)); - cviewer.setInput(lodgings); - - // Ensure that cv's content now has the catalog's lodgings - assertArrayEquals(catalog.getLodgings(), getViewerContent(cviewer) - .toArray()); - - // Ensure that the cv's labels are the same as the lodging descriptions - assertEquals(getColumn(catalog.getLodgings(), "name"), - getComboContent()); - - // Add a lodging in the middle (not supported by the model right now) - // Lodging lodging = SampleData.FACTORY.createLodging(); - // lodging.setName("Middle Lodging"); - // catalog.addLodging(lodging); - // assertEquals(getViewerContent(cviewer).get(2), lodging); - - // Add a lodging at the end - Lodging lodging = SampleData.FACTORY.createLodging(); - lodging.setName("End Lodging"); - catalog.addLodging(lodging); - int index = getComboContent().size() - 1; - assertEquals(getViewerContent(cviewer).get(index), lodging); - - // Delete the first Lodging - catalog.removeLodging(catalog.getLodgings()[0]); - // Ensure that the cv's labels are the same as the lodging descriptions - assertEquals(getColumn(catalog.getLodgings(), "name"), - getComboContent()); - - // Delete middle Lodging - catalog.removeLodging(catalog.getLodgings()[2]); - // Ensure that the cv's labels are the same as the lodging descriptions - assertEquals(getColumn(catalog.getLodgings(), "name"), - getComboContent()); - - // Change the names of all Lodging - for (int i = 0; i < catalog.getLodgings().length; i++) { - Lodging l = catalog.getLodgings()[i]; - l.setName("Changed: " + l.getName()); - } - spinEventLoop(0); // force Async. efforts - assertEquals(getColumn(catalog.getLodgings(), "name"), - getComboContent()); - - // Set to null value - Lodging l = catalog.getLodgings()[0]; - assertEquals(combo.getItem(0), l.getName()); - l.setName(null); - assertEquals("", combo.getItem(0)); - - // set to empty list - while (catalog.getLodgings().length > 0) { - catalog.removeLodging(catalog.getLodgings()[0]); - assertEquals(getColumn(catalog.getLodgings(), "name"), - getComboContent()); - } - } - - /** - * This scenario tests a simple SWT combo with a set item list where the - * selection is bouded to a String property - */ - // public void test_ROCombo_Scenario01() { - // - // // Read-Only Combo will not change its text property on a call to - // // setText() - // - // String[] items = new String[] { "FairyLand", "TuneLand", "NoWereLand", - // "TinkerLand", "DreamLand" }; - // combo.setItems(items); - // Account account = catalog.getAccounts()[0]; - // - // // simple Combo's selection bound to the Account's country property - // getDbc().bind(new Property(combo, SWTProperties.SELECTION), - // new Property(account, "country"), null); - // - // // Drive the combo selection - // int index = 3; - // combo.setText(items[index]); // this should drive the selection - // assertEquals(account.getCountry(), items[index]); - // - // // Set the country, and ensure selection is set property - // index = 1; - // account.setCountry(items[index]); - // assertEquals(index, combo.getSelectionIndex()); - // assertEquals(combo.getText(), items[index]); - // - // index = combo.getSelectionIndex(); - // String txt = combo.getText(); - // // Set the country to something that is not in the Combo's list - // account.setCountry("FooBar"); - // // Combo's selection will not Change - // assertEquals(combo.getSelectionIndex(), index); - // assertEquals(combo.getText(), txt); - // - // } - /** - * This scenario tests a simple SWT combo that is bound to a list of Country - * objects. The Country object's name property is listed in the Combo. - * - * The Combo's selection is bounded to the Country property of an Account. - */ - // public void test_ROCombo_Scenario02_SWTCombo() { - // - // // Create a list of Strings for the countries - // IObservableList list = new WritableList(); - // for (int i = 0; i < catalog.getAccounts().length; i++) - // list.add(catalog.getAccounts()[i].getCountry()); - // - // // Bind the combo's content to that of the String based list - // getDbc().bind(combo, list, null); - // assertEquals(Arrays.asList(combo.getItems()), list); - // - // Account account = catalog.getAccounts()[0]; - // - // // simple Combo's selection bound to the Account's country property - // getDbc().bind(new Property(combo, SWTProperties.SELECTION), - // new Property(account, "country"), null); - // - // // Drive the combo selection - // String selection = (String) list.get(2); - // combo.setText(selection); // this should drive the selection - // assertEquals(account.getCountry(), selection); - // - // } - /** - * This scenario tests a simple SWT combo that is bound to a list of Country - * objects. The Country object's name property is listed in the Combo. - * - * The Combo's selection is bounded to the Country property of an Account. - */ - // public void test_ROCombo_Scenario02_ComboViewer() { - // - // // Account label provider will fill the combo with the country - // cviewer.setLabelProvider(accountLabelProvider); - // // Bind the ComboViewer's content to the available accounts - // getDbc().bind( - // cviewer, - // new ListModelDescription(new Property(catalog, "accounts"), - // "country"), null); - // - // // Ensure that cv's content now has the catalog's accounts - // assertArrayEquals(catalog.getAccounts(), getViewerContent(cviewer) - // .toArray()); - // // Ensure that the cv's labels are the same as the account countries - // assertEquals(getColumn(catalog.getAccounts(), "country"), - // getComboContent()); - // - // Account account = SampleData.FACTORY.createAccount(); - // - // // Use the Viewers visual Combo (Strings) to set the account's country - // getDbc().bind(new Property(combo, SWTProperties.SELECTION), - // new Property(account, "country"), null); - // - // // Change the selection of the ComboViewer to all possible accounts, and - // // verify that the account's Country is being changed correctly. - // for (int i = 0; i < catalog.getAccounts().length; i++) { - // Account selection = catalog.getAccounts()[i]; - // cviewer.setSelection(new StructuredSelection(selection)); - // assertEquals(selection.getCountry(), account.getCountry()); - // } - // - // } - /** - * This test ensure that multiple combos can be bound to the same deomain - * model - */ - public void test_ROCombo_multipleBindings() { - Adventure skiAdventure = SampleData.WINTER_HOLIDAY; // for selection - - // Bind the ComboViewer's content to the available lodging - IObservableList lodgings = BeansObservables.observeList(Realm - .getDefault(), catalog, "lodgings"); - ObservableListContentProvider contentProvider = new ObservableListContentProvider(); - - IObservableMap[] attributeMaps = BeansObservables.observeMaps( - contentProvider.getKnownElements(), Lodging.class, - new String[] { "name" }); - - cviewer.setContentProvider(contentProvider); - cviewer.setLabelProvider(new ObservableMapLabelProvider(attributeMaps)); - cviewer.setInput(lodgings); - - // Ensure that cv's content now has the catalog's lodgings - assertArrayEquals(catalog.getLodgings(), getViewerContent(cviewer) - .toArray()); - - // Ensure that the cv's labels are the same as the lodging descriptions - assertEquals(getColumn(catalog.getLodgings(), "name"), - getComboContent()); - - ComboViewer otherViewer = new ComboViewer(getComposite(), SWT.NONE); - lodgings = BeansObservables.observeList(Realm.getDefault(), catalog, - "lodgings"); - contentProvider = new ObservableListContentProvider(); - - attributeMaps = BeansObservables.observeMaps(contentProvider - .getKnownElements(), Lodging.class, new String[] { "name" }); - - otherViewer.setContentProvider(contentProvider); - otherViewer.setLabelProvider(new ObservableMapLabelProvider( - attributeMaps)); - otherViewer.setInput(lodgings); - - // Ensure that cv's content now has the catalog's lodgings - assertArrayEquals(catalog.getLodgings(), getViewerContent(otherViewer) - .toArray()); - - // Bind both selections to the same thing - IObservableValue selection = ViewersObservables - .observeSingleSelection(cviewer); - getDbc().bindValue(selection, - BeansObservables.observeValue(skiAdventure, "defaultLodging"), - null, null); - - IObservableValue otherSelection = ViewersObservables - .observeSingleSelection(otherViewer); - getDbc().bindValue(otherSelection, - BeansObservables.observeValue(skiAdventure, "defaultLodging"), - null, null); - - Lodging lodging = catalog.getLodgings()[0]; - - // Ensure that setting the selection is driven forward to the other - // combo - cviewer.setSelection(new StructuredSelection(lodging)); - assertEquals(((IStructuredSelection) cviewer.getSelection()) - .getFirstElement(), ((IStructuredSelection) otherViewer - .getSelection()).getFirstElement()); - - // Change the list of one combo, and ensure it updates the other combo - catalog.removeLodging(lodging); - assertEquals(getViewerContent(cviewer), getViewerContent(otherViewer)); - - } - - /** - * This scenario tests a simple SWT CCombo that is bound to a list of - * Country objects. The Country object's name property is listed in the - * Combo. - * - * The Combo's selection is bounded to the Country property of an Account. - */ - public void test_ROCombo_SWTCCombo() { - - // Create a list of Strings for the countries - IObservableList list = new WritableList(); - for (int i = 0; i < catalog.getAccounts().length; i++) - list.add(catalog.getAccounts()[i].getCountry()); - - CCombo ccombo = new CCombo(getComposite(), SWT.READ_ONLY - | SWT.DROP_DOWN); - - // Bind the combo's content to that of the String based list - getDbc().bindList(SWTObservables.observeItems(ccombo), list, null, null); - assertEquals(Arrays.asList(ccombo.getItems()), list); - - Account account = catalog.getAccounts()[0]; - - // simple Combo's selection bound to the Account's country property - IObservableValue comboSelection = SWTObservables.observeSelection(ccombo); - getDbc().bindValue(comboSelection, - BeansObservables.observeValue(account, "country"), null, null); - - // Drive the combo selection - String selection = (String) list.get(2); - ccombo.setText(selection); // this should drive the selection - assertEquals(account.getCountry(), selection); - - } - - /** - * This scenario tests a simple SWT CCombo that is bound to a list of - * Country objects. The Country object's name property is listed in the - * Combo. - * - * The Combo's selection is bounded to the Country property of an Account. - */ - public void test_WCombo_SWTCCombo() { - - // Create a list of Strings for the countries - IObservableList list = new WritableList(); - for (int i = 0; i < catalog.getAccounts().length; i++) - list.add(catalog.getAccounts()[i].getCountry()); - - CCombo ccombo = new CCombo(getComposite(), SWT.READ_ONLY - | SWT.DROP_DOWN); - - // Bind the combo's content to that of the String based list - getDbc().bindList(SWTObservables.observeItems(ccombo), list, null, null); - assertEquals(Arrays.asList(ccombo.getItems()), list); - - Account account = catalog.getAccounts()[0]; - - // simple Combo's selection bound to the Account's country property - IObservableValue comboSelection = SWTObservables.observeSelection(ccombo); - getDbc().bindValue(comboSelection, - BeansObservables.observeValue(account, "country"), null, null); - - // Drive the combo selection - String selection = (String) list.get(2); - ccombo.setText(selection); // this should drive the selection - assertEquals(account.getCountry(), selection); - - selection = (String) list.get(1); - account.setCountry(selection); - assertEquals(selection, ccombo.getItem(ccombo.getSelectionIndex())); - assertEquals(selection, ccombo.getText()); - - selection = "country not in list"; - account.setCountry(selection); - assertEquals(-1, ccombo.getSelectionIndex()); - assertEquals(selection, ccombo.getText()); - } - - /** - * This scenario tests a simple SWT CCombo that is bound to a list of - * Country objects. The Country object's name property is listed in the - * Combo. - * - * The Combo's selection is bounded to the Country property of an Account. - */ - public void test_ROCombo_SWTList() { - - // Create a list of Strings for the countries - IObservableList list = new WritableList(); - for (int i = 0; i < catalog.getAccounts().length; i++) - list.add(catalog.getAccounts()[i].getCountry()); - - org.eclipse.swt.widgets.List swtlist = new org.eclipse.swt.widgets.List( - getComposite(), SWT.READ_ONLY | SWT.SINGLE); - - // Bind the combo's content to that of the String based list - getDbc().bindList(SWTObservables.observeItems(swtlist), list, null, null); - assertEquals(Arrays.asList(swtlist.getItems()), list); - - Account account = catalog.getAccounts()[0]; - - // simple Combo's selection bound to the Account's country property - IObservableValue listSelection = SWTObservables.observeSelection(swtlist); - getDbc().bindValue(listSelection, - BeansObservables.observeValue(account, "country"), null, null); - - String selection = (String) list.get(2); - swtlist.select(2); // this should drive the selection - swtlist.notifyListeners(SWT.Selection, null); // Force notification - assertEquals(account.getCountry(), selection); - - } - -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/ComboUpdatingTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/ComboUpdatingTest.java deleted file mode 100644 index 31c683b0..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/ComboUpdatingTest.java +++ /dev/null @@ -1,214 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 116920 - *******************************************************************************/ - -package org.eclipse.jface.tests.databinding.scenarios; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.tests.databinding.BindingTestSuite; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.widgets.Combo; - -/** - * @since 3.2 - */ -public class ComboUpdatingTest extends ScenariosTestCase { - - private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( - this); - - public void addPropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(listener); - } - - public void addPropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(propertyName, listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(listener); - } - - public void removePropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(propertyName, - listener); - } - - protected void firePropertyChange(String propertyName, Object oldValue, - Object newValue) { - propertyChangeSupport.firePropertyChange(propertyName, oldValue, - newValue); - } - - - private Combo comboEditable; - //private Combo comboReadOnly; - - private static final String PROP_TEXT = "text"; - private String text = "Hello, world"; - - public String getText() { - return text; - } - - public void setText(String text) { - this.text = text; - } - - private static final String PROP_CHOICES = "choices"; - private List choices = new ArrayList(); - { - choices.add("Banana"); - choices.add("Apple"); - choices.add("Mango"); - } - - public List getChoices() { - return choices; - } - - public void setChoices(List choices) { - this.choices = choices; - firePropertyChange(PROP_CHOICES, null, null); - } - - protected void setUp() throws Exception { - super.setUp(); - getComposite().setLayout(new FillLayout()); - comboEditable = new Combo(getComposite(), SWT.DROP_DOWN); -// comboReadOnly = new Combo(getComposite(), SWT.DROP_DOWN | SWT.READ_ONLY); - } - - //------------------------------------------------------------------------- - - private static final String NEXT = "Next"; - public void testBindText() throws Exception { - getDbc().bindValue(SWTObservables.observeText(comboEditable), BeansObservables.observeValue(this, "text"), null, null); - spinEventLoop(0); - assertEquals("Should find value of text", text, comboEditable.getText()); - comboEditable.setText(NEXT); - spinEventLoop(0); - assertEquals("Should find new value in text", NEXT, text); - } - - public void testBindItems_listHasSameItems_editable() throws Exception { - if (BindingTestSuite.failingTestsDisabled(this)) { - return; - } - text = "Apple"; - - getDbc().bindValue(SWTObservables.observeText(comboEditable), BeansObservables.observeValue(this, PROP_TEXT), null, null); - - spinEventLoop(0); - assertEquals("Should find value of text", text, comboEditable.getText()); - - IObservableList list = new WritableList(getChoices(), null); - getDbc().bindList(SWTObservables.observeItems(comboEditable), list, null, null); - - spinEventLoop(0); - int position = 0; - for (Iterator choicesIter = choices.iterator(); choicesIter.hasNext();) { - String element = (String) choicesIter.next(); - assertEquals(element, comboEditable.getItem(position)); - ++position; - } -// assertEquals("Should find value of text", "Apple", text); - assertEquals("Should find value of combo.getText()", "", comboEditable.getText()); - comboEditable.setText("Banana"); - spinEventLoop(0); - assertEquals("Should find value of text", "Banana", text); - } - -// public void testBindItems_listHasSameItems_readOnly() throws Exception { -// text = "Apple"; -// ComboObservableValue value = (ComboObservableValue) getDbc().createObservable(new Property(comboReadOnly, PROP_TEXT)); -// getDbc().bind(value.getItems(), new Property(this, PROP_CHOICES), null); -//// getDbc().bind(combo, new Property(this, PROP_CHOICES, String.class, Boolean.TRUE), null); -// spinEventLoop(0); -// assertEquals("Should find value of text", "Apple", text); -// getDbc().bind(value, new Property(this, PROP_TEXT), null); -// spinEventLoop(0); -// assertEquals("Should find value of text", "Apple", text); -// assertEquals("Should find value of combo.getText()", "Apple", comboReadOnly.getText()); -// int position = 0; -// for (Iterator choicesIter = choices.iterator(); choicesIter.hasNext();) { -// String element = (String) choicesIter.next(); -// assertEquals(element, comboReadOnly.getItem(position)); -// ++position; -// } -// assertEquals("Should find value of text", "Apple", text); -// assertEquals("Should find value of combo.getText()", "Apple", comboReadOnly.getText()); -// comboReadOnly.setText("Banana"); -// spinEventLoop(0); -// assertEquals("Should find value of text", "Banana", text); -// } - - public void testBindItems_listHasDifferentItems_editable() throws Exception { - if (BindingTestSuite.failingTestsDisabled(this)) { - return; - } - - getDbc().bindValue(SWTObservables.observeText(comboEditable), BeansObservables.observeValue(this, PROP_TEXT), null, null); - - spinEventLoop(0); - assertEquals("Should find value of text", text, comboEditable.getText()); - - IObservableList list = new WritableList(new ArrayList(), String.class); - list.addAll(getChoices()); - getDbc().bindList(SWTObservables.observeItems(comboEditable), list, null, null); - - spinEventLoop(0); - int position = 0; - for (Iterator choicesIter = choices.iterator(); choicesIter.hasNext();) { - String element = (String) choicesIter.next(); - assertEquals(element, comboEditable.getItem(position)); - ++position; - } -// assertEquals("Should find value of text", "Hello, world", text); - assertEquals("Should find value of combo.getText()", "", comboEditable.getText()); - comboEditable.setText("Banana"); - spinEventLoop(0); - assertEquals("Should find value of text", "Banana", text); - } - -// public void testBindItems_listHasDifferentItems_readOnly() throws Exception { -// ComboObservableValue value = (ComboObservableValue) getDbc().createObservable(new Property(comboReadOnly, PROP_TEXT)); -// getDbc().bind(value, new Property(this, PROP_TEXT), null); -// spinEventLoop(0); -// getDbc().bind(value.getItems(), new Property(this, PROP_CHOICES), null); -//// getDbc().bind(combo, new Property(this, PROP_CHOICES, String.class, Boolean.TRUE), null); -// spinEventLoop(0); -// int position = 0; -// for (Iterator choicesIter = choices.iterator(); choicesIter.hasNext();) { -// String element = (String) choicesIter.next(); -// assertEquals(element, comboReadOnly.getItem(position)); -// ++position; -// } -//// assertEquals("Should find value of text", "Hello, world", text); -// assertEquals("Should find value of combo.getText()", "", comboReadOnly.getText()); -// comboReadOnly.setText("Banana"); -// spinEventLoop(0); -// assertEquals("Should find value of text", "Banana", text); -// } - -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/ComboViewerScenario.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/ComboViewerScenario.java deleted file mode 100644 index 4cf8176c..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/ComboViewerScenario.java +++ /dev/null @@ -1,120 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 116920 - * Brad Reynolds - bug 160000 - *******************************************************************************/ -package org.eclipse.jface.tests.databinding.scenarios; - -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; -import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; -import org.eclipse.jface.databinding.viewers.ViewersObservables; -import org.eclipse.jface.examples.databinding.model.Adventure; -import org.eclipse.jface.examples.databinding.model.Catalog; -import org.eclipse.jface.examples.databinding.model.Lodging; -import org.eclipse.jface.examples.databinding.model.SampleData; -import org.eclipse.jface.viewers.ComboViewer; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Combo; - -/** - * To run the tests in this class, right-click and select "Run As JUnit Plug-in - * Test". This will also start an Eclipse instance. To clean up the launch - * configuration, open up its "Main" tab and select "[No Application] - Headless - * Mode" as the application to run. - */ - -public class ComboViewerScenario extends ScenariosTestCase { - - private Catalog catalog; - - private Combo combo; - - private ComboViewer comboViewer; - - protected void setUp() throws Exception { - super.setUp(); - // do any setup work here - combo = new Combo(getComposite(), SWT.READ_ONLY | SWT.DROP_DOWN); - comboViewer = new ComboViewer(combo); - catalog = SampleData.CATALOG_2005; // Lodging source - } - - protected void tearDown() throws Exception { - combo.dispose(); - combo = null; - comboViewer = null; - super.tearDown(); - } - - public void testScenario01() { - // Bind the catalog's lodgings to the combo - IObservableList lodgings = BeansObservables.observeList(realm, catalog, - "lodgings"); - ObservableListContentProvider contentProvider = new ObservableListContentProvider(); - - IObservableMap attributeMap = BeansObservables.observeMap( - contentProvider.getKnownElements(), Lodging.class, "name"); - comboViewer.setLabelProvider(new ObservableMapLabelProvider( - attributeMap)); - comboViewer.setContentProvider(contentProvider); - comboViewer.setInput(lodgings); - - // Verify that the combo's items are the lodgings - for (int i = 0; i < catalog.getLodgings().length; i++) { - assertEquals(catalog.getLodgings()[i], comboViewer.getElementAt(i)); - } - // Verify that the String being shown in the combo viewer is the - // "toString" of the combo viewer - String[] lodgingStrings = new String[catalog.getLodgings().length]; - for (int i = 0; i < catalog.getLodgings().length; i++) { - lodgingStrings[i] = catalog.getLodgings()[i].getName(); - } - assertArrayEquals(lodgingStrings, combo.getItems()); - - // Verify that the combo has no selected item - assertEquals(null, ((IStructuredSelection) comboViewer.getSelection()) - .getFirstElement()); - - // Now bind the selection of the combo to the "defaultLodging" property - // of an adventure - final Adventure adventure = SampleData.WINTER_HOLIDAY; - IObservableValue selection = ViewersObservables - .observeSingleSelection(comboViewer); - getDbc().bindValue(selection, - BeansObservables.observeValue(adventure, "defaultLodging"), - null, null); - - // Verify that the combo selection is the default lodging - assertEquals(((IStructuredSelection) comboViewer.getSelection()) - .getFirstElement(), adventure.getDefaultLodging()); - - // Change the model and verify that the combo selection changes - adventure.setDefaultLodging(SampleData.CAMP_GROUND); - assertEquals(adventure.getDefaultLodging(), SampleData.CAMP_GROUND); - assertEquals(((IStructuredSelection) comboViewer.getSelection()) - .getFirstElement(), adventure.getDefaultLodging()); - - // Change the combo selection and verify that the model changes - comboViewer.getCombo().select(3); - assertEquals(((IStructuredSelection) comboViewer.getSelection()) - .getFirstElement(), adventure.getDefaultLodging()); - - adventure.setDefaultLodging(SampleData.YOUTH_HOSTEL); - spinEventLoop(0); - assertEquals(((IStructuredSelection) comboViewer.getSelection()) - .getFirstElement(), adventure.getDefaultLodging()); - } - -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/CustomBeanModelType.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/CustomBeanModelType.java deleted file mode 100644 index f8af8534..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/CustomBeanModelType.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.jface.tests.databinding.scenarios; - -/** - * @since 3.2 - * - */ -public class CustomBeanModelType { - - private String propertyName; - - private Object object; - - private Class type; - - /** - * @param object - * @param propertyName - * @param type - */ - public CustomBeanModelType(Object object, String propertyName, Class type) { - this.object = object; - this.propertyName = propertyName; - this.type = type; - } - - /** - * @return - */ - public String getPropertyName() { - return propertyName; - } - - /** - * @return - */ - public Object getObject() { - return object; - } - - /** - * @return - */ - public Class getType() { - return type; - } - -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/CustomBeanUpdateValueStrategy.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/CustomBeanUpdateValueStrategy.java deleted file mode 100644 index e2447101..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/CustomBeanUpdateValueStrategy.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 116920, 159768 - *******************************************************************************/ -// TODO djo: copyright -package org.eclipse.jface.tests.databinding.scenarios; - -import java.lang.reflect.Method; - -import org.eclipse.core.databinding.UpdateValueStrategy; -import org.eclipse.core.databinding.conversion.IConverter; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.validation.IValidator; - -/** - * A BindSpec that will automatically grab validators from an object's - * properties, if a get<PropertyName>Validator method is defined. Makes it - * easy to associate validators with the properties that they are responsible - * for validating. - * - */ -public class CustomBeanUpdateValueStrategy extends UpdateValueStrategy { - - public IConverter createConverter(Object fromType, Object toType) { - if (fromType instanceof CustomBeanModelType) { - CustomBeanModelType customBeanModelType = (CustomBeanModelType) fromType; - fromType = customBeanModelType.getType(); - } - if (toType instanceof CustomBeanModelType) { - CustomBeanModelType customBeanModelType = (CustomBeanModelType) toType; - toType = customBeanModelType.getType(); - } - return super.createConverter(fromType, toType); - } - - protected void fillDefaults(IObservableValue source, - IObservableValue destination) { - if (destination.getValueType() instanceof CustomBeanModelType) { - if (beforeSetValidator==null) { - CustomBeanModelType property = (CustomBeanModelType) destination.getValueType(); - String propertyName = property.getPropertyName(); - String getValidatorMethodName = "get" + upperCaseFirstLetter(propertyName) + "Validator"; //$NON-NLS-1$ //$NON-NLS-2$ - - Class objectClass = property.getObject().getClass(); - - Method getValidator; - try { - getValidator = objectClass.getMethod(getValidatorMethodName, - new Class[] { Class.class }); - beforeSetValidator= (IValidator) getValidator.invoke(property - .getObject(), new Object[0]); - } catch (Exception e) { - // ignore - } - - } - } - super.fillDefaults(source, destination); - } - - private String upperCaseFirstLetter(String name) { - String result = name.substring(0, 1).toUpperCase() + name.substring(1); - return result; - } - - public Boolean isAssignableFromTo(Object fromType, Object toType) { - if (fromType instanceof CustomBeanModelType) { - fromType = ((CustomBeanModelType) fromType).getType(); - } - if (toType instanceof CustomBeanModelType) { - toType = ((CustomBeanModelType) toType).getType(); - } - return super.isAssignableFromTo(fromType, toType); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/CustomConverterScenarios.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/CustomConverterScenarios.java deleted file mode 100644 index d3507787..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/CustomConverterScenarios.java +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 116920 - *******************************************************************************/ -package org.eclipse.jface.tests.databinding.scenarios; - -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.examples.databinding.model.Adventure; -import org.eclipse.jface.examples.databinding.model.PriceModelObject; -import org.eclipse.jface.examples.databinding.model.SampleData; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Spinner; - -/** - * To run the tests in this class, right-click and select "Run As JUnit Plug-in - * Test". This will also start an Eclipse instance. To clean up the launch - * configuration, open up its "Main" tab and select "[No Application] - Headless - * Mode" as the application to run. - */ - -public class CustomConverterScenarios extends ScenariosTestCase { - - private Adventure skiTrip; - - protected void setUp() throws Exception { - super.setUp(); - skiTrip = SampleData.WINTER_HOLIDAY; - } - - protected void tearDown() throws Exception { - // do any teardown work here - super.tearDown(); - } - - public void testScenario01() { - DataBindingContext dbc = getDbc(); - Spinner spinner_dollars = new Spinner(getComposite(), SWT.NONE); - spinner_dollars.setMaximum(10000); - Spinner spinner_cents = new Spinner(getComposite(), SWT.NONE); - - // The price object is a double which contains both the dollars and - // cents - // To allow this to be worked on with two separate spinner controls - // (which get and set int values) - // an intermediate object is used - PriceModelObject priceModel = new PriceModelObject(); - - dbc.bindValue(BeansObservables.observeValue(priceModel, "price"), BeansObservables.observeValue(skiTrip, - "price"), null, null); - - dbc.bindValue(SWTObservables.observeSelection(spinner_dollars), - BeansObservables.observeValue(priceModel, "dollars"), - null, null); - - dbc.bindValue(SWTObservables.observeSelection(spinner_cents), - BeansObservables.observeValue(priceModel, "cents"), - null, null); - - // spinEventLoop(1); - // Make sure that the selection on the spinner_dollars matches the - // dollars of the price - assertEquals(spinner_dollars.getSelection(), new Double(skiTrip.getPrice()).intValue()); - // Make sure that the selection on the spinner_cents matches the dollars - // of the price - Double doublePrice = new Double(skiTrip.getPrice()); - double cents = 100 * doublePrice.doubleValue() - 100 * doublePrice.intValue(); - assertEquals(spinner_cents.getSelection(), (int) cents); - - // Change the selection on the spinner_dollars to be $50 and make sure - // the model is updated with the cents included - spinner_dollars.setSelection(50); - double expectedPrice = 50 + cents / 100; - assertEquals(expectedPrice, skiTrip.getPrice(), 0.01); - - // Change the selection on the spinner_cents to be 27 and make sure the - // model is updated with the dollars included - spinner_cents.setSelection(27); - assertEquals(50.27, skiTrip.getPrice(), 0.01); - - // Change the model to be $60.99 dollars and make sure the - // spinner_dollars is 60 and spinner_cents is 99 - skiTrip.setPrice(60.99); - assertEquals(60, spinner_dollars.getSelection()); - assertEquals(99, spinner_cents.getSelection()); - - } - -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/CustomScenarios.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/CustomScenarios.java deleted file mode 100644 index c6eb678c..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/CustomScenarios.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 116920 - *******************************************************************************/ -package org.eclipse.jface.tests.databinding.scenarios; - -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.examples.databinding.model.Adventure; -import org.eclipse.jface.examples.databinding.model.AggregateObservableValue; -import org.eclipse.jface.examples.databinding.model.SampleData; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Text; - -/** - * To run the tests in this class, right-click and select "Run As JUnit Plug-in - * Test". This will also start an Eclipse instance. To clean up the launch - * configuration, open up its "Main" tab and select "[No Application] - Headless - * Mode" as the application to run. - */ - -public class CustomScenarios extends ScenariosTestCase { - - protected void setUp() throws Exception { - super.setUp(); - // do any setup work here - } - - protected void tearDown() throws Exception { - // do any teardown work here - super.tearDown(); - } - - public void testScenario01() { - - // Binding the name property of an Adventure object to the contents of - // Text controls, no conversion, no validation. - - Adventure adventure = SampleData.WINTER_HOLIDAY; - Text text = new Text(getComposite(), SWT.BORDER); - - IObservableValue descriptionObservable = BeansObservables.observeValue(adventure, "description"); - IObservableValue nameObservable = BeansObservables.observeValue(adventure, "name"); - AggregateObservableValue customObservable_comma = new AggregateObservableValue(new IObservableValue[] { - descriptionObservable, nameObservable }, ","); - - getDbc().bindValue(SWTObservables.observeText(text, SWT.Modify), customObservable_comma, null, null); - // spinEventLoop(1); - // Make sure that the description on the model match the widget - assertEquals(adventure.getDescription() + "," + adventure.getName(), text.getText()); - - // Change the widget to newDescription,newName and ensure the model is - // updated - text.setText("newDescription,newName"); - assertEquals("newDescription", adventure.getDescription()); - assertEquals("newName", adventure.getName()); - - // Change the model to newDescription_0 and newName_0 and ensure the GUI - // is updated - adventure.setDescription("newDescription_0"); - adventure.setName("newName_0"); - assertEquals("newDescription_0,newName_0", text.getText()); - - // Change text to newDescription_1 with no comma and ensure the model is - // updated correctly with no name - text.setText("newDescription_1"); - assertEquals("newDescription_1", adventure.getDescription()); - assertEquals(null, adventure.getName()); - - // Change text to newName with a preceeding comma and ensure the model - // is updated correctly with no description - // TODO - Get this test working + Add the one where we have two - // aggregates and update one and - // check that the other is updated - currently this fails on the GUI - - // JRW - // text.setText(",newName_1"); - // assertEquals(null, adventure.getDescription()); - // assertEquals("newName_1", adventure.getName()); - - } - -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/LabelControlScenario.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/LabelControlScenario.java deleted file mode 100644 index ad234a6e..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/LabelControlScenario.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 116920 - *******************************************************************************/ -package org.eclipse.jface.tests.databinding.scenarios; - -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.examples.databinding.model.Adventure; -import org.eclipse.jface.examples.databinding.model.SampleData; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Label; - -/** - * To run the tests in this class, right-click and select "Run As JUnit Plug-in - * Test". This will also start an Eclipse instance. To clean up the launch - * configuration, open up its "Main" tab and select "[No Application] - Headless - * Mode" as the application to run. - */ - -public class LabelControlScenario extends ScenariosTestCase { - - private Adventure adventure; - - private Label label; - - protected void setUp() throws Exception { - super.setUp(); - // do any setup work here - label = new Label(getComposite(), SWT.NONE); - adventure = SampleData.WINTER_HOLIDAY; - } - - protected void tearDown() throws Exception { - // do any teardown work here - super.tearDown(); - label.dispose(); - label = null; - } - - public void testScenario01() { - // Bind the adventure "name" property to a label control - // Change the UI and verify the model and UI are the same value - // Change the model and verify the UI changes - getDbc().bindValue(SWTObservables.observeText(label), BeansObservables.observeValue(adventure, "name"), null, null); - - assertEquals(adventure.getName(), label.getText()); - adventure.setName("France"); - assertEquals("France", label.getText()); - adventure.setName("Climb Everest"); - spinEventLoop(0); - assertEquals("Climb Everest", label.getText()); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/ListViewerScenario.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/ListViewerScenario.java deleted file mode 100644 index 0fe7dda1..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/ListViewerScenario.java +++ /dev/null @@ -1,123 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 116920 - * Brad Reynolds - bug 160000 - *******************************************************************************/ -package org.eclipse.jface.tests.databinding.scenarios; - -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; -import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; -import org.eclipse.jface.databinding.viewers.ViewersObservables; -import org.eclipse.jface.examples.databinding.model.Adventure; -import org.eclipse.jface.examples.databinding.model.Catalog; -import org.eclipse.jface.examples.databinding.model.Lodging; -import org.eclipse.jface.examples.databinding.model.SampleData; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ListViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.List; - -/** - * To run the tests in this class, right-click and select "Run As JUnit Plug-in - * Test". This will also start an Eclipse instance. To clean up the launch - * configuration, open up its "Main" tab and select "[No Application] - Headless - * Mode" as the application to run. - */ - -public class ListViewerScenario extends ScenariosTestCase { - - private Catalog catalog; - - private List list; - - private ListViewer listViewer; - - protected void setUp() throws Exception { - super.setUp(); - // do any setup work here - list = new List(getComposite(), SWT.READ_ONLY | SWT.SINGLE); - listViewer = new ListViewer(list); - catalog = SampleData.CATALOG_2005; // Lodging source - } - - protected void tearDown() throws Exception { - list.dispose(); - list = null; - listViewer = null; - super.tearDown(); - } - - public void testScenario01() { - // Bind the catalog's lodgings to the combo - IObservableList lodgings = BeansObservables.observeList(Realm - .getDefault(), catalog, "lodgings"); - ObservableListContentProvider contentProvider = new ObservableListContentProvider(); - - IObservableMap[] attributeMaps = BeansObservables.observeMaps( - contentProvider.getKnownElements(), Lodging.class, - new String[] { "name" }); - listViewer.setContentProvider(contentProvider); - listViewer.setLabelProvider(new ObservableMapLabelProvider( - attributeMaps)); - listViewer.setInput(lodgings); - - // Verify that the combo's items are the lodgings - for (int i = 0; i < catalog.getLodgings().length; i++) { - assertEquals(catalog.getLodgings()[i], listViewer.getElementAt(i)); - } - // Verify that the String being shown in the list viewer is the - // "toString" of the combo viewer - String[] lodgingStrings = new String[catalog.getLodgings().length]; - for (int i = 0; i < catalog.getLodgings().length; i++) { - lodgingStrings[i] = catalog.getLodgings()[i].getName(); - } - assertArrayEquals(lodgingStrings, list.getItems()); - - // Verify that the list has no selected item - assertEquals(null, ((IStructuredSelection) listViewer.getSelection()) - .getFirstElement()); - - // Now bind the selection of the combo to the "defaultLodging" property - // of an adventure - final Adventure adventure = SampleData.WINTER_HOLIDAY; - - IObservableValue selection = ViewersObservables - .observeSingleSelection(listViewer); - getDbc().bindValue(selection, - BeansObservables.observeValue(adventure, "defaultLodging"), - null, null); - - // Verify that the list selection is the default lodging - assertEquals(((IStructuredSelection) listViewer.getSelection()) - .getFirstElement(), adventure.getDefaultLodging()); - - // Change the model and verify that the list selection changes - adventure.setDefaultLodging(SampleData.CAMP_GROUND); - assertEquals(adventure.getDefaultLodging(), SampleData.CAMP_GROUND); - assertEquals(((IStructuredSelection) listViewer.getSelection()) - .getFirstElement(), adventure.getDefaultLodging()); - - // Change the list selection and verify that the model changes - listViewer.getList().select(3); - assertEquals(((IStructuredSelection) listViewer.getSelection()) - .getFirstElement(), adventure.getDefaultLodging()); - - adventure.setDefaultLodging(SampleData.YOUTH_HOSTEL); - spinEventLoop(0); - assertEquals(((IStructuredSelection) listViewer.getSelection()) - .getFirstElement(), adventure.getDefaultLodging()); - - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/MasterDetailScenarios.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/MasterDetailScenarios.java deleted file mode 100644 index d8b8b767..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/MasterDetailScenarios.java +++ /dev/null @@ -1,371 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 160000 - *******************************************************************************/ -package org.eclipse.jface.tests.databinding.scenarios; - -import java.util.Arrays; -import java.util.List; - -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.masterdetail.MasterDetailObservables; -import org.eclipse.core.databinding.observable.value.ComputedValue; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; -import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; -import org.eclipse.jface.databinding.viewers.ViewersObservables; -import org.eclipse.jface.examples.databinding.model.Adventure; -import org.eclipse.jface.examples.databinding.model.Catalog; -import org.eclipse.jface.examples.databinding.model.Category; -import org.eclipse.jface.examples.databinding.model.Lodging; -import org.eclipse.jface.examples.databinding.model.SampleData; -import org.eclipse.jface.viewers.ContentViewer; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ListViewer; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Text; - -/** - * To run the tests in this class, right-click and select "Run As JUnit Plug-in - * Test". This will also start an Eclipse instance. To clean up the launch - * configuration, open up its "Main" tab and select "[No Application] - Headless - * Mode" as the application to run. - */ - -public class MasterDetailScenarios extends ScenariosTestCase { - - protected Object getViewerSelection(ContentViewer contentViewer) { - return ((IStructuredSelection) contentViewer.getSelection()) - .getFirstElement(); - } - - /** - * @return the ComboViewer's domain object list - */ - protected List getViewerContent(ContentViewer contentViewer) { - Object[] elements = ((IStructuredContentProvider) contentViewer - .getContentProvider()).getElements(null); - if (elements != null) - return Arrays.asList(elements); - return null; - } - - public void testScenario01() { - // Displaying the catalog's list of Lodging objects in a list viewer, - // using their names. The name of the currently selected Lodging can - // be edited in a text widget. There is always a selected Lodging - // object. - ListViewer listViewer = new ListViewer(getComposite(), SWT.BORDER); - Realm realm = SWTObservables.getRealm(listViewer.getControl() - .getDisplay()); - listViewer.getList().setLayoutData( - new GridData(SWT.FILL, SWT.FILL, false, false)); - Catalog catalog = SampleData.CATALOG_2005; - - IObservableList lodgings = BeansObservables.observeList(realm, catalog, - "lodgings"); - ObservableListContentProvider contentProvider = new ObservableListContentProvider(); - IObservableMap[] attributeMaps = BeansObservables.observeMaps( - contentProvider.getKnownElements(), Lodging.class, - new String[] { "name" }); - listViewer.setContentProvider(contentProvider); - listViewer.setLabelProvider(new ObservableMapLabelProvider( - attributeMaps)); - listViewer.setInput(lodgings); - - assertArrayEquals(catalog.getLodgings(), getViewerContent(listViewer) - .toArray()); - - IObservableValue selectedLodging = ViewersObservables - .observeSingleSelection(listViewer); - - selectedLodging.setValue(SampleData.CAMP_GROUND); - - assertEquals(SampleData.CAMP_GROUND, getViewerSelection(listViewer)); - Text txtName = new Text(getComposite(), SWT.BORDER); - - getDbc().bindValue( - SWTObservables.observeText(txtName, SWT.Modify), - BeansObservables.observeDetailValue(realm, selectedLodging, - "name", String.class), null, null); - - assertEquals(txtName.getText(), SampleData.CAMP_GROUND.getName()); - enterText(txtName, "foobar"); - assertEquals("foobar", SampleData.CAMP_GROUND.getName()); - listViewer.setSelection(new StructuredSelection( - SampleData.FIVE_STAR_HOTEL)); - assertEquals(SampleData.FIVE_STAR_HOTEL, selectedLodging.getValue()); - assertEquals(SampleData.FIVE_STAR_HOTEL.getName(), txtName.getText()); - SampleData.FIVE_STAR_HOTEL.setName("barfoo"); - assertEquals("barfoo", txtName.getText()); - - // Now make sure that the event listeners get removed on dispose() - // Values should no longer be updated - selectedLodging.dispose(); - - // selectedLodging.setValue(SampleData.CAMP_GROUND); - // assertNotSame(SampleData.CAMP_GROUND, - // getViewerSelection(listViewer)); - // assertNotSame(txtName.getText(), SampleData.CAMP_GROUND.getName()); - // enterText(txtName, "foobar"); - // assertNotSame("foobar", SampleData.CAMP_GROUND.getName()); - // listViewer.setSelection(new StructuredSelection( - // SampleData.FIVE_STAR_HOTEL)); - // assertNotSame(SampleData.FIVE_STAR_HOTEL, - // selectedLodging.getValue()); - // assertNotSame(SampleData.FIVE_STAR_HOTEL.getName(), - // txtName.getText()); - // SampleData.FIVE_STAR_HOTEL.setName("barfoo"); - // assertNotSame("barfoo", txtName.getText()); - } - - public void testScenario02() { - // Selecting from the list of lodgings for an adventure and editing the - // properties of the selected lodging in text widgets. If no lodging is - // selected the input controls for name and adventure are disabled. - // There are two buttons "Add" and "Remove"; clicking on "Add" creates a - // new lodging and selects it so it can be edited, clicking on "Remove" - // removes the currently selected lodging from the list. - final ListViewer listViewer = new ListViewer(getComposite(), SWT.BORDER); - listViewer.getList().setLayoutData( - new GridData(SWT.FILL, SWT.FILL, false, false)); - final Catalog catalog = SampleData.CATALOG_2005; - - IObservableList lodgings = BeansObservables.observeList(realm, catalog, - "lodgings"); - ObservableListContentProvider contentProvider = new ObservableListContentProvider(); - IObservableMap[] attributeMaps = BeansObservables.observeMaps( - contentProvider.getKnownElements(), Lodging.class, - new String[] { "name" }); - listViewer.setContentProvider(contentProvider); - listViewer.setLabelProvider(new ObservableMapLabelProvider( - attributeMaps)); - listViewer.setInput(lodgings); - - assertArrayEquals(catalog.getLodgings(), getViewerContent(listViewer) - .toArray()); - - final IObservableValue selectedLodgingObservable = ViewersObservables - .observeSingleSelection(listViewer); - - selectedLodgingObservable.setValue(null); - assertTrue(listViewer.getSelection().isEmpty()); - - ComputedValue selectionExistsObservable = new ComputedValue( - boolean.class) { - protected Object calculate() { - return new Boolean(selectedLodgingObservable.getValue() != null); - } - }; - - assertFalse(((Boolean) selectionExistsObservable.getValue()) - .booleanValue()); - - final Text txtName = new Text(getComposite(), SWT.BORDER); - - getDbc().bindValue(SWTObservables.observeEnabled(txtName), - selectionExistsObservable, null, null); - getDbc().bindValue( - SWTObservables.observeText(txtName, SWT.Modify), - BeansObservables.observeDetailValue(realm, - selectedLodgingObservable, "name", String.class), null, null); - - assertEquals(txtName.getText(), ""); - assertFalse(txtName.getEnabled()); - - final Text txtDescription = new Text(getComposite(), SWT.BORDER); - - getDbc().bindValue(SWTObservables.observeEnabled(txtDescription), - selectionExistsObservable, null, null); - getDbc().bindValue( - SWTObservables.observeText(txtDescription, SWT.Modify), - MasterDetailObservables.detailValue( - selectedLodgingObservable, BeansObservables - .valueFactory(realm, "description"), - String.class), null, null); - - assertEquals(txtDescription.getText(), ""); - assertFalse(txtDescription.getEnabled()); - - Button addButton = new Button(getComposite(), SWT.PUSH); - addButton.addSelectionListener(new SelectionListener() { - public void widgetSelected(SelectionEvent e) { - Lodging selectedLodging = (Lodging) selectedLodgingObservable - .getValue(); - int insertionIndex = 0; - if (selectedLodging != null) { - insertionIndex = Arrays.asList(catalog.getLodgings()) - .indexOf(selectedLodging); - assertTrue(insertionIndex >= 0); - } - Lodging newLodging = SampleData.FACTORY.createLodging(); - int itemCount = listViewer.getList().getItemCount(); - newLodging.setName("new lodging name " + itemCount); - newLodging.setDescription("new lodging description " - + itemCount); - catalog.addLodging(newLodging); - assertEquals(itemCount + 1, listViewer.getList().getItemCount()); - listViewer.setSelection(new StructuredSelection(newLodging)); - assertSame(newLodging, selectedLodgingObservable.getValue()); - assertTrue(txtName.getEnabled()); - assertTrue(txtDescription.getEnabled()); - assertEquals(newLodging.getName(), txtName.getText()); - assertEquals(newLodging.getDescription(), txtDescription - .getText()); - } - - public void widgetDefaultSelected(SelectionEvent e) { - widgetSelected(e); - } - }); - - Button removeButton = new Button(getComposite(), SWT.PUSH); - removeButton.addSelectionListener(new SelectionListener() { - public void widgetSelected(SelectionEvent e) { - Lodging selectedLodging = (Lodging) selectedLodgingObservable - .getValue(); - assertNotNull(selectedLodging); - int deletionIndex = Arrays.asList(catalog.getLodgings()) - .indexOf(selectedLodging); - assertTrue(deletionIndex >= 0); - int itemCount = listViewer.getList().getItemCount(); - catalog.removeLodging(selectedLodging); - assertEquals(itemCount - 1, listViewer.getList().getItemCount()); - assertNull(selectedLodgingObservable.getValue()); - } - - public void widgetDefaultSelected(SelectionEvent e) { - widgetSelected(e); - } - }); - - pushButtonWithEvents(addButton); - pushButtonWithEvents(removeButton); - pushButtonWithEvents(addButton); - pushButtonWithEvents(addButton); - pushButtonWithEvents(removeButton); - } - - public void testScenario03() { - // List adventures and for the selected adventure allow its default - // lodging�s name and description to be changed in text controls. If - // there is no selected adventure or the default lodging is null the - // text controls are disabled. This is a nested property. The default - // lodging can be changed elsewhere, and the list - final Catalog catalog = SampleData.CATALOG_2005; - - final ListViewer categoryListViewer = new ListViewer(getComposite(), - SWT.BORDER); - categoryListViewer.getList().setLayoutData( - new GridData(SWT.FILL, SWT.FILL, false, false)); - - IObservableList categories = BeansObservables.observeList(realm, - catalog, "categories"); - ObservableListContentProvider contentProvider = new ObservableListContentProvider(); - IObservableMap[] attributeMaps = BeansObservables.observeMaps( - contentProvider.getKnownElements(), Category.class, - new String[] { "name" }); - categoryListViewer.setContentProvider(contentProvider); - categoryListViewer.setLabelProvider(new ObservableMapLabelProvider( - attributeMaps)); - categoryListViewer.setInput(categories); - - assertArrayEquals(catalog.getCategories(), getViewerContent( - categoryListViewer).toArray()); - - final IObservableValue selectedCategoryObservable = ViewersObservables - .observeSingleSelection(categoryListViewer); - - final ListViewer adventureListViewer = new ListViewer(getComposite(), - SWT.BORDER); - adventureListViewer.getList().setLayoutData( - new GridData(SWT.FILL, SWT.FILL, false, false)); - - IObservableList adventures = BeansObservables.observeDetailList(realm, - selectedCategoryObservable, "adventures", Adventure.class); - contentProvider = new ObservableListContentProvider(); - attributeMaps = BeansObservables.observeMaps(contentProvider - .getKnownElements(), Adventure.class, new String[] { "name" }); - adventureListViewer.setContentProvider(contentProvider); - adventureListViewer.setLabelProvider(new ObservableMapLabelProvider( - attributeMaps)); - adventureListViewer.setInput(adventures); - - ComputedValue categorySelectionExistsObservable = new ComputedValue() { - protected Object calculate() { - return new Boolean( - selectedCategoryObservable.getValue() != null); - } - }; - - getDbc().bindValue( - SWTObservables.observeEnabled(adventureListViewer.getList()), - categorySelectionExistsObservable, null, null); - - final IObservableValue selectedAdventureObservable = ViewersObservables - .observeSingleSelection(adventureListViewer); - - ComputedValue adventureSelectionExistsObservable = new ComputedValue() { - protected Object calculate() { - return new Boolean( - selectedAdventureObservable.getValue() != null); - } - }; - - final Text txtName = new Text(getComposite(), SWT.BORDER); - - getDbc().bindValue(SWTObservables.observeEnabled(txtName), - adventureSelectionExistsObservable, null, null); - getDbc().bindValue( - SWTObservables.observeText(txtName, SWT.Modify), - BeansObservables.observeDetailValue(realm, - selectedAdventureObservable, "name", String.class), - null, null); - - assertEquals(txtName.getText(), ""); - assertFalse(txtName.getEnabled()); - - final Text txtDescription = new Text(getComposite(), SWT.BORDER); - - getDbc().bindValue(SWTObservables.observeEnabled(txtDescription), - adventureSelectionExistsObservable, null, null); - getDbc().bindValue( - SWTObservables.observeText(txtDescription, SWT.Modify), - BeansObservables.observeDetailValue(realm, - selectedAdventureObservable, "description", - String.class), null, null); - - assertFalse(adventureListViewer.getList().isEnabled()); - categoryListViewer.setSelection(new StructuredSelection( - SampleData.SUMMER_CATEGORY)); - assertTrue(adventureListViewer.getList().isEnabled()); - assertFalse(txtName.getEnabled()); - adventureListViewer.setSelection(new StructuredSelection( - SampleData.RAFTING_HOLIDAY)); - assertEquals(Boolean.TRUE, adventureSelectionExistsObservable - .getValue()); - assertTrue(txtName.getEnabled()); - assertEquals(SampleData.RAFTING_HOLIDAY.getName(), txtName.getText()); - categoryListViewer.setSelection(new StructuredSelection( - SampleData.WINTER_CATEGORY)); - assertTrue(adventureListViewer.getList().isEnabled()); - assertFalse(txtName.getEnabled()); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/NPETestScenario.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/NPETestScenario.java deleted file mode 100644 index b7e4aed3..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/NPETestScenario.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 116920 - *******************************************************************************/ - -package org.eclipse.jface.tests.databinding.scenarios; - -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Text; - -/** - * @since 3.2 - * - */ -public class NPETestScenario extends ScenariosTestCase { - private Text text; - - Person person; - - protected void setUp() throws Exception { - super.setUp(); - person = new Person(); - text = new Text(getComposite(), SWT.BORDER); - } - - /** - * Asserts the ability to have an initial value of <code>null</code> on - * the model and to update the value by changing the value of the view. - */ - public void test_InitialNullValue() { - Person person = new Person(); - assertNull(person.getName()); - - System.out.println("Expecting message about not being able to attach a listener"); - getDbc().bindValue(SWTObservables.observeText(text, SWT.Modify), - BeansObservables.observeValue(person, "name"), - null, null); - - text.setText("Brad"); - text.notifyListeners(SWT.FocusOut, null); - assertEquals("Brad", person.getName()); - } - - private static class Person { - private String name; - - /** - * @return Returns the name. - */ - public String getName() { - return name; - } - - /** - * @param name - * The name to set. - */ - public void setName(String name) { - this.name = name; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/NewTableScenarios.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/NewTableScenarios.java deleted file mode 100644 index 6a323258..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/NewTableScenarios.java +++ /dev/null @@ -1,443 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.tests.databinding.scenarios; - -import org.eclipse.jface.examples.databinding.model.Catalog; -import org.eclipse.jface.examples.databinding.model.Category; -import org.eclipse.jface.examples.databinding.model.SampleData; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.widgets.TableColumn; - -/** - * To run the tests in this class, right-click and select "Run As JUnit Plug-in - * Test". This will also start an Eclipse instance. To clean up the launch - * configuration, open up its "Main" tab and select "[No Application] - Headless - * Mode" as the application to run. - */ - -public class NewTableScenarios extends ScenariosTestCase { - - private TableViewer tableViewer; - - Catalog catalog; - - Category category; - - private TableColumn firstNameColumn; - - private TableColumn lastNameColumn; - - private TableColumn stateColumn; - - Image[] images; - - private TableColumn fancyColumn; - - protected void setUp() throws Exception { - super.setUp(); - getComposite().setLayout(new FillLayout()); - tableViewer = new TableViewer(getComposite()); - tableViewer.getTable().setLinesVisible(true); - tableViewer.getTable().setHeaderVisible(true); - firstNameColumn = new TableColumn(tableViewer.getTable(), SWT.NONE); - firstNameColumn.setWidth(50); - lastNameColumn = new TableColumn(tableViewer.getTable(), SWT.NONE); - lastNameColumn.setWidth(50); - stateColumn = new TableColumn(tableViewer.getTable(), SWT.NONE); - stateColumn.setWidth(50); - fancyColumn = new TableColumn(tableViewer.getTable(), SWT.NONE); - fancyColumn.setWidth(250); - - catalog = SampleData.CATALOG_2005; // Lodging source - category = SampleData.WINTER_CATEGORY; - - images = new Image[] { - getShell().getDisplay().getSystemImage(SWT.ICON_ERROR), - getShell().getDisplay().getSystemImage(SWT.ICON_WARNING), - getShell().getDisplay().getSystemImage(SWT.ICON_INFORMATION), }; - } - - protected void tearDown() throws Exception { - // do any teardown work here - super.tearDown(); - tableViewer.getTable().dispose(); - tableViewer = null; - firstNameColumn = null; - lastNameColumn = null; - stateColumn = null; - } - - String getValue(String text) { - if (text == null) - return ""; - return text; - } - - public void testScenario01() { -// // Factory for directly creating IObservables for beans -// JavaBeans javaBeans = new JavaBeans(); -// -// // Wrap the TableViewer in an IObservableCollectionWithLabels -// IObservableCollectionWithLabels accountTable = new TableViewerObservableTable( -// tableViewer); -// -// // Create a readable set to track the catalog's accounts -// IReadableSet accountSet = javaBeans.createReadableSet(catalog, -// new PropertyDescriptor("accounts", Catalog.class, "getAccounts", null), -// Account.class); -// -// // Create an observable cell provider to track the given accounts' properties. -// IObservableCellProvider accountCellProvider = javaBeans.createObservableCellProvider( -// accountSet, new String[] { "firstName", "lastName", "state" }); -// -// // bind -// getDbc().bind(accountTable, accountCellProvider, null); -// -// // uncomment next line to see result interactively -// // interact(); -// -// // Verify the data in the table columns matches the accounts -// Account[] accounts = catalog.getAccounts(); -// for (int i = 0; i < accounts.length; i++) { -// Account account = accounts[i]; -// String col_0 = ((ITableLabelProvider) tableViewer -// .getLabelProvider()).getColumnText(account, 0); -// assertEquals(getValue(account.getFirstName()), col_0); -// String col_1 = ((ITableLabelProvider) tableViewer -// .getLabelProvider()).getColumnText(account, 1); -// assertEquals(getValue(account.getLastName()), col_1); -// String col_2 = ((ITableLabelProvider) tableViewer -// .getLabelProvider()).getColumnText(account, 2); -// assertEquals(getValue(account.getState()), col_2); -// -// } - } - - public void testScenario02() throws SecurityException, - IllegalArgumentException { -// // Show that a TableViewer with three columns can be used to update -// // columns -// Account[] accounts = catalog.getAccounts(); -// -// TableViewerDescription tableViewerDescription = new TableViewerDescription( -// tableViewer); -// tableViewerDescription.addEditableColumn("firstName"); -// tableViewerDescription.addEditableColumn("lastName", null, null, -// new PhoneConverter()); -// tableViewerDescription.addEditableColumn("state", null, null, -// new StateConverter()); -// getDbc().bind(tableViewerDescription, -// new Property(catalog, "accounts"), null); -// -// Account account = accounts[0]; -// // Select the first item in the table -// tableViewer.editElement(account, 0); -// // Set the text property of the cell editor which is now active over the -// // "firstName" column -// CellEditor[] cellEditors = tableViewer.getCellEditors(); -// TextCellEditor firstNameEditor = (TextCellEditor) cellEditors[0]; -// // Change the firstName and test it goes to the model -// enterText((Text) firstNameEditor.getControl(), "Bill"); -// // Check whether the model has changed -// assertEquals("Bill", account.getFirstName()); - } - - public void testScenario04() { -// // Show that when an item is added to a collection the table gets an -// // extra item -// Account[] accounts = catalog.getAccounts(); -// -// TableViewerDescription tableViewerDescription = new TableViewerDescription( -// tableViewer); -// tableViewerDescription.addColumn("firstName"); -// tableViewerDescription.addColumn("lastName"); -// tableViewerDescription.addColumn("state"); -// tableViewerDescription.addColumn(null, new IConverter() { -// -// public Class getModelType() { -// return Account.class; -// } -// -// public Class getTargetType() { -// return ViewerLabel.class; -// } -// -// public Object convertTargetToModel(Object targetObject) { -// return null; -// } -// -// public Object convertModelToTarget(Object modelObject) { -// Account account = (Account) modelObject; -// return new ViewerLabel(account.toString(), images[new Random() -// .nextInt(images.length)]); -// } -// }); -// getDbc().bind(tableViewerDescription, -// new Property(catalog, "accounts"), null); -// -// // interact(); -// -// // Verify the number of accounts matches the number of items in the -// // table -// assertEquals(tableViewer.getTable().getItemCount(), accounts.length); -// // Add a new account and verify that the number of items in the table -// // increases -// Account newAccount = new Account(); -// newAccount.setFirstName("Finbar"); -// newAccount.setLastName("McGoo"); -// newAccount.setLastName("NC"); -// catalog.addAccount(newAccount); -// // The number of items should have gone up by one -// assertEquals(tableViewer.getTable().getItemCount(), accounts.length + 1); -// // The number of items should still match the number of accounts (i.e. -// // test the model) -// assertEquals(tableViewer.getTable().getItemCount(), catalog -// .getAccounts().length); -// // Remove the account that was just added -// catalog.removeAccount(newAccount); -// // The number of items should match the original -// assertEquals(tableViewer.getTable().getItemCount(), accounts.length); -// // The number of items should still match the number of accounts (i.e. -// // test the model is reset) -// assertEquals(tableViewer.getTable().getItemCount(), catalog -// .getAccounts().length); -// -// // Test adding and removing to the model on a non UI thread -// int numberOfAccounts = catalog.getAccounts().length; -// final Account barney = new Account(); -// barney.setFirstName("Barney"); -// barney.setLastName("Smith"); -// barney.setLastName("CA"); -// invokeNonUI(new Runnable() { -// public void run() { -// catalog.addAccount(barney); -// } -// }); -// spinEventLoop(0); -// // The number of items should have gone up by one -// assertEquals(tableViewer.getTable().getItemCount(), -// numberOfAccounts + 1); -// -// invokeNonUI(new Runnable() { -// public void run() { -// catalog.removeAccount(barney); -// } -// }); -// spinEventLoop(0); -// // The number of items should have reverted to the original number -// // before barney was added and removed -// assertEquals(tableViewer.getTable().getItemCount(), numberOfAccounts); -// - } - - public void testScenario03() { -// // Show that converters work for table columns -// Account[] accounts = catalog.getAccounts(); -// -// TableViewerDescription tableViewerDescription = new TableViewerDescription( -// tableViewer); -// tableViewerDescription.addEditableColumn("lastName"); -// tableViewerDescription.addEditableColumn("phone", null, null, -// new PhoneConverter()); -// tableViewerDescription.addEditableColumn("state", null, null, -// new StateConverter()); -// getDbc().bind(tableViewerDescription, -// new Property(catalog, "accounts"), null); -// -// // Verify that the data in the the table columns matches the expected -// // What we are looking for is that the phone numbers are converterted to -// // nnn-nnn-nnnn and that -// // the state letters are converted to state names -// // Verify the data in the table columns matches the accounts -// PhoneConverter phoneConverter = new PhoneConverter(); -// StateConverter stateConverter = new StateConverter(); -// for (int i = 0; i < accounts.length; i++) { -// Account account = catalog.getAccounts()[i]; -// // Check the phone number -// String col_phone = ((ITableLabelProvider) tableViewer -// .getLabelProvider()).getColumnText(account, 1); -// assertEquals(getValue((String) phoneConverter -// .convertModelToTarget(account.getPhone())), col_phone); -// String col_state = ((ITableLabelProvider) tableViewer -// .getLabelProvider()).getColumnText(account, 2); -// assertEquals(getValue((String) stateConverter -// .convertModelToTarget(account.getState())), col_state); -// } - } - - public void testScenario05() { -// // Show that when the model changes then the UI refreshes to reflect -// // this -// -// TableViewerDescription tableViewerDescription = new TableViewerDescription( -// tableViewer); -// tableViewerDescription.addColumn("lastName"); -// tableViewerDescription.addColumn("phone", new PhoneConverter()); -// tableViewerDescription.addColumn("state", new StateConverter()); -// getDbc().bind(tableViewerDescription, -// new Property(catalog, "accounts"), null); -// -// final Account account = catalog.getAccounts()[0]; -// String lastName = tableViewer.getTable().getItem(0).getText(0); -// // Check the firstName in the TableItem is the same as the model -// assertEquals(lastName, account.getLastName()); -// // Now change the model and check again -// account.setLastName("Gershwin"); -// lastName = tableViewer.getTable().getItem(0).getText(0); -// assertEquals(lastName, account.getLastName()); -// -// // Test the model update on a non UI thread -// invokeNonUI(new Runnable() { -// public void run() { -// account.setLastName("Mozart"); -// } -// }); -// spinEventLoop(0); -// lastName = tableViewer.getTable().getItem(0).getText(0); -// assertEquals(lastName, account.getLastName()); -// - } - - public void testScenario06() { -// // Check that explicit type means that defaulting of converters works -// TableViewerDescription tableViewerDescription = new TableViewerDescription( -// tableViewer); -// tableViewerDescription.addEditableColumn("price"); -// tableViewerDescription.getColumn(0).setPropertyType(Double.TYPE); -// getDbc().bind(tableViewerDescription, -// new Property(catalog, "transporations"), null); -// Transportation transporation = catalog.getTransporations()[0]; -// tableViewer.editElement(transporation, 0); -// // Set the text property of the cell editor which is now active over the -// // "firstName" column -// CellEditor[] cellEditors = tableViewer.getCellEditors(); -// TextCellEditor priceEditor = (TextCellEditor) cellEditors[0]; -// // Change the firstName and test it goes to the model -// enterText((Text) priceEditor.getControl(), "123.45"); -// // Verify the model is updated -// assertEquals(transporation.getPrice(), 123.45, 0); - - } - - public void testScenario07() { -// // Verify that even when a column's property type is not set, that it is -// // worked out lazily from the target type -// TableViewerDescription tableViewerDescription = new TableViewerDescription( -// tableViewer); -// tableViewerDescription.addEditableColumn("price"); -// // The column's type is not set to be Double.TYPE. This will be inferred -// // once the first Transportation object is set -// // into the ObservableCollection -// getDbc().bind(tableViewerDescription, -// new Property(catalog, "transporations"), null); -// Transportation transporation = catalog.getTransporations()[0]; -// tableViewer.editElement(transporation, 0); -// // Set the text property of the cell editor which is now active over the -// // "firstName" column -// CellEditor[] cellEditors = tableViewer.getCellEditors(); -// TextCellEditor priceEditor = (TextCellEditor) cellEditors[0]; -// // Change the firstName and test it goes to the model -// enterText((Text) priceEditor.getControl(), "123.45"); -// // Verify the model is updated -// assertEquals(transporation.getPrice(), 123.45, 0); -// - } - - public void testScenario08_00() { -// // Verify that binding to a Collection property (rather than an array) -// // works when specifying data type -// TableViewerDescription tableViewerDescription = new TableViewerDescription( -// tableViewer); -// tableViewerDescription.addEditableColumn("userId"); -// tableViewerDescription.addEditableColumn("password"); -// getDbc().bind(tableViewerDescription, -// new Property(catalog, "signons", Signon.class, null), null); -// Signon firstSignon = (Signon) catalog.getSignons().get(0); -// // Verify the UI matches the model -// TableItem firstTableItem = tableViewer.getTable().getItem(0); -// assertEquals(firstTableItem.getText(1), firstSignon.getPassword()); -// // Change the model and ensure the UI refreshes -// firstSignon.setPassword("Eclipse123Rocks"); -// assertEquals("Eclipse123Rocks", firstSignon.getPassword()); -// assertEquals(firstTableItem.getText(1), firstSignon.getPassword()); -// // Change the GUI and ensure the model refreshes -// tableViewer.editElement(firstSignon, 1); -// CellEditor[] cellEditors = tableViewer.getCellEditors(); -// TextCellEditor passwordEditor = (TextCellEditor) cellEditors[1]; -// enterText((Text) passwordEditor.getControl(), "Cricket11Players"); -// assertEquals("Cricket11Players", firstSignon.getPassword()); -// - } - - public void testScenario08_01() { -// // Verify that binding to a Collection property (rather than an array) -// // works without specifying data type -// TableViewerDescription tableViewerDescription = new TableViewerDescription( -// tableViewer); -// tableViewerDescription.addEditableColumn("userId"); -// tableViewerDescription.addEditableColumn("password"); -// getDbc().bind(tableViewerDescription, new Property(catalog, "signons"), -// null); -// Signon firstSignon = (Signon) catalog.getSignons().get(0); -// // Verify the UI matches the model -// TableItem firstTableItem = tableViewer.getTable().getItem(0); -// assertEquals(firstTableItem.getText(1), firstSignon.getPassword()); -// // Change the model and ensure the UI refreshes -// firstSignon.setPassword("Eclipse123Rocks"); -// assertEquals("Eclipse123Rocks", firstSignon.getPassword()); -// assertEquals(firstTableItem.getText(1), firstSignon.getPassword()); -// // Change the GUI and ensure the model refreshes -// tableViewer.editElement(firstSignon, 1); -// CellEditor[] cellEditors = tableViewer.getCellEditors(); -// TextCellEditor passwordEditor = (TextCellEditor) cellEditors[1]; -// enterText((Text) passwordEditor.getControl(), "Cricket11Players"); -// assertEquals("Cricket11Players", firstSignon.getPassword()); -// - } - - public void testScenario09() { -// // Verify that nested properties work. Catalog has adventures. Adventure -// // has defaultLodging. Loding has name. -// TableViewerDescription tableViewerDescription = new TableViewerDescription( -// tableViewer); -// tableViewerDescription.addColumn("name"); -// tableViewerDescription.addColumn("defaultLodging.name"); -// getDbc().bind(tableViewerDescription, -// new Property(category, "adventures"), null); - } - /** - * public void testScenario10(){ // Verify that for TIME_EARLY updating - * occurs on a per key basic for a TextCellEditor // Show that converters - * work for table columns Account[] accounts = catalog.getAccounts(); - * Account firstAccount = accounts[0]; - * SampleData.getSWTObservableFactory().setUpdateTime(DataBindingContext.TIME_EARLY); - * TableViewerDescription tableViewerDescription = new - * TableViewerDescription(tableViewer); - * tableViewerDescription.addEditableColumn("lastName"); - * tableViewerDescription.addColumn("lastName"); - * getDbc().bind(tableViewerDescription,new Property(catalog, "accounts"), - * null); // Verify that the first account is shown in the first row with - * the last name correctly - * assertEquals(tableViewer.getTable().getItem(0).getData(),firstAccount); - * assertEquals(tableViewer.getTable().getItem(0).getText(0),firstAccount.getLastName()); - * assertEquals(tableViewer.getTable().getItem(0).getText(1),firstAccount.getLastName()); // - * Create a cell editor over the first column - * tableViewer.editElement(firstAccount, 0); // Set the text property of the - * cell editor which is now active over the "firstName" column CellEditor[] - * cellEditors = tableViewer.getCellEditors(); TextCellEditor - * lastNameCellEditor = (TextCellEditor) cellEditors[0]; - * ((Text)lastNameCellEditor.getControl()).setText("E"); // Verify that the - * key press goes to the model assertEquals(firstAccount.getLastName(),"E"); } - */ -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/PropertyScenarios.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/PropertyScenarios.java deleted file mode 100644 index 719ceed4..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/PropertyScenarios.java +++ /dev/null @@ -1,579 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 116920, 159768 - *******************************************************************************/ -package org.eclipse.jface.tests.databinding.scenarios; - -import java.text.ParseException; -import java.util.Date; -import java.util.Locale; - -import org.eclipse.core.databinding.AggregateValidationStatus; -import org.eclipse.core.databinding.Binding; -import org.eclipse.core.databinding.UpdateValueStrategy; -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.conversion.Converter; -import org.eclipse.core.databinding.conversion.IConverter; -import org.eclipse.core.databinding.conversion.NumberToStringConverter; -import org.eclipse.core.databinding.conversion.StringToNumberConverter; -import org.eclipse.core.databinding.observable.ChangeEvent; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.validation.IValidator; -import org.eclipse.core.databinding.validation.ValidationStatus; -import org.eclipse.core.internal.databinding.conversion.IdentityConverter; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.examples.databinding.model.Account; -import org.eclipse.jface.examples.databinding.model.Adventure; -import org.eclipse.jface.examples.databinding.model.Cart; -import org.eclipse.jface.examples.databinding.model.SampleData; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.FocusEvent; -import org.eclipse.swt.events.FocusListener; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Spinner; -import org.eclipse.swt.widgets.Text; - -import com.ibm.icu.text.NumberFormat; - -/** - * To run the tests in this class, right-click and select "Run As JUnit Plug-in - * Test". This will also start an Eclipse instance. To clean up the launch - * configuration, open up its "Main" tab and select "[No Application] - Headless - * Mode" as the application to run. - */ - -public class PropertyScenarios extends ScenariosTestCase { - - private Adventure adventure; - - protected void setUp() throws Exception { - super.setUp(); - // do any setup work here - adventure = SampleData.WINTER_HOLIDAY; - } - - protected void tearDown() throws Exception { - // do any teardown work here - super.tearDown(); - } - - public void testEnterText() { - // just to make sure enterText() generates a FocusOut event. - Text text = new Text(getComposite(), SWT.BORDER); - final boolean[] focusLostHolder = { false }; - text.addFocusListener(new FocusListener() { - - public void focusGained(FocusEvent e) { - // only interested in focus lost events - } - - public void focusLost(FocusEvent e) { - focusLostHolder[0] = true; - } - }); - enterText(text, "hallo"); - assertTrue(focusLostHolder[0]); - } - - public void testScenario01() { - Text text = new Text(getComposite(), SWT.BORDER); - getDbc().bindValue(SWTObservables.observeText(text, SWT.Modify), - BeansObservables.observeValue(adventure, "name"), - null, null); - - // getDbc().bind(text, new Property(adventure, "name"), null); - // uncomment the following line to see what's happening - // spinEventLoop(1); - assertEquals(adventure.getName(), text.getText()); - enterText(text, "foobar"); - // uncomment the following line to see what's happening - // spinEventLoop(1); - assertEquals("foobar", adventure.getName()); - adventure.setName("barfoo"); - // uncomment the following line to see what's happening - // spinEventLoop(1); - assertEquals("barfoo", text.getText()); - } - - public void testScenario02() { - // Binding the name property of an Adventure object to the contents of - // Text controls, no conversion, no validation. The Text widget editable - // is set to false.by the developer (can not change the name) - Text text = new Text(getComposite(), SWT.READ_ONLY); - - getDbc().bindValue(SWTObservables.observeText(text, SWT.None), - BeansObservables.observeValue(adventure, "name"), - null, null); - assertEquals(adventure.getName(), text.getText()); - } - - public void testScenario03() { - // Binding of a read-only property of an Adventure object to the - // contents of Text controls, no conversion, no validation. Text control - // is not editable as a side effect of binding to a read-only property.. - Cart cart = SampleData.CART; - cart.setAdventureDays(42); - // bind to the lodgingDays feature, which is read-only and always one - // less than the number of adventure days. - Text text = new Text(getComposite(), SWT.BORDER); - - System.out.println("Expecting message about not being able to attach a listener"); - getDbc().bindValue(SWTObservables.observeText(text, SWT.Modify), - BeansObservables.observeValue(cart, "lodgingDays"), - null, null); - - assertEquals(new Integer(cart.getLodgingDays()).toString(), text.getText()); - } - - public void testScenario04() { - // Binding a nested property of an Adventure object to the content of a - // Text control, no conversion, no validation. - Text text = new Text(getComposite(), SWT.BORDER); - // TODO Scenario needs to be more specific - I'm binding to the default - // lodging's description of an adventure. What do we expect to happen - // when the default lodging changes? If we expect no change, then this - // scenario does not introduce anything new. If we expect the binding to - // be to the new default lodging's description, shouldn't we move this - // scenario to the master/detail section? I'm assuming the latter for - // now. - - IObservableValue defaultLodging =BeansObservables.observeDetailValue(realm, BeansObservables.observeValue(adventure, - "defaultLodging"), "description", String.class); - - getDbc().bindValue(SWTObservables.observeText(text, SWT.Modify), defaultLodging, null, null); - - // test changing the description - assertEquals(adventure.getDefaultLodging().getDescription(), text.getText()); - enterText(text, "foobar"); - assertEquals("foobar", adventure.getDefaultLodging().getDescription()); - adventure.getDefaultLodging().setDescription("barfoo"); - assertEquals(adventure.getDefaultLodging().getDescription(), text.getText()); - - // test changing the default lodging - adventure.setDefaultLodging(SampleData.CAMP_GROUND); - assertEquals(adventure.getDefaultLodging().getDescription(), text.getText()); - adventure.getDefaultLodging().setDescription("barfo"); - assertEquals(adventure.getDefaultLodging().getDescription(), text.getText()); - - adventure.setDefaultLodging(null); - assertEquals("", text.getText()); - - adventure.setDefaultLodging(SampleData.FIVE_STAR_HOTEL); - assertEquals(adventure.getDefaultLodging().getDescription(), text.getText()); - adventure.getDefaultLodging().setDescription("barf"); - assertEquals(adventure.getDefaultLodging().getDescription(), text.getText()); - - } - - public void testScenario05() { - // Binding the name property of an Adventure object to the contents of - // Text controls where conversion occurs � the model data is held all - // in - // uppercase and displayed in lowercase with the first letter - // capitalized. - Text text = new Text(getComposite(), SWT.BORDER); - adventure.setName("UPPERCASE"); - - IConverter converter1 = new IConverter() { - public Object getFromType() { - return String.class; - } - - public Object getToType() { - return String.class; - } - - public Object convert(Object toObject) { - String modelValue = (String) toObject; - if (modelValue == null || modelValue.equals("")) { - return modelValue; - } - String firstChar = modelValue.substring(0, 1); - String remainingChars = modelValue.substring(1); - return firstChar.toUpperCase() + remainingChars.toLowerCase(); - } - }; - IConverter converter2 = new IConverter() { - public Object getFromType() { - return String.class; - } - - public Object getToType() { - return String.class; - } - - public Object convert(Object fromObject) { - return ((String) fromObject).toUpperCase(); - } - }; - - getDbc().bindValue(SWTObservables.observeText(text, SWT.Modify), - BeansObservables.observeValue(adventure, "name"), - new UpdateValueStrategy().setConverter(converter2), new UpdateValueStrategy().setConverter(converter1)); - - // spinEventLoop(1); - assertEquals("Uppercase", text.getText()); - enterText(text, "lowercase"); - // spinEventLoop(1); - // TODO If we wanted to "canonicalize" the value in the text field, how - // could we do that? - assertEquals("LOWERCASE", adventure.getName()); - } - - public void testScenario06() { - // Binding the name property of an Adventure object to the contents of - // Text controls where validation occurs and the name cannot be longer - // than 15 characters and cannot contain spaces - Text text = new Text(getComposite(), SWT.BORDER); - final String noSpacesMessage = "Name must not contain spaces."; - final String max15CharactersMessage = "Maximum length for name is 15 characters."; - adventure.setName("ValidValue"); - - IValidator validator = new IValidator() { - public IStatus validate(Object value) { - String stringValue = (String) value; - if (stringValue.length() > 15) { - return ValidationStatus.error(max15CharactersMessage); - } else if (stringValue.indexOf(' ') != -1) { - return ValidationStatus.cancel(noSpacesMessage); - } else { - return Status.OK_STATUS; - } - } - }; - -// BindSpec bindSpec = new DefaultBindSpec().setModelToTargetConverter(new IdentityConverter(String.class)) -// .setTargetToModelConverter(new IdentityConverter(String.class)) -// .addTargetValidator(BindingEvent.PIPELINE_VALUE_CHANGING, validator); - - Binding binding = getDbc().bindValue( - SWTObservables.observeText(text, SWT.Modify), - BeansObservables.observeValue(adventure, "name"), - new UpdateValueStrategy().setConverter(new IdentityConverter( - String.class)).setAfterGetValidator(validator), - new UpdateValueStrategy().setConverter(new IdentityConverter( - String.class))); - - // no validation message - assertTrue(((IStatus)binding.getValidationStatus().getValue()).isOK()); - enterText(text, "Invalid Value"); - assertEquals(noSpacesMessage, ((IStatus) binding.getValidationStatus().getValue()).getMessage()); - assertEquals("ValidValue", adventure.getName()); - text.setText("InvalidValueBecauseTooLong"); - assertEquals(max15CharactersMessage, - ((IStatus) binding.getValidationStatus().getValue()).getMessage()); - assertEquals("ValidValue", adventure.getName()); - enterText(text, "anothervalid"); - assertTrue(((IStatus)binding.getValidationStatus().getValue()).isOK()); - assertEquals("anothervalid", adventure.getName()); - } - - public void testScenario07() { - // Binding the price property of an Adventure to a Text control. Price - // is a double and Text accepts String so conversion will have to occur. - // Validation ensure that the value is positive - Text text = new Text(getComposite(), SWT.BORDER); - adventure.setPrice(5.0); - final String cannotBeNegativeMessage = "Price cannot be negative."; - final String mustBeCurrencyMessage = "Price must be a currency."; - - IValidator validator = new IValidator() { - public IStatus validate(Object value) { - String stringValue = (String) value; - try { - double doubleValue = new Double(stringValue).doubleValue(); - if (doubleValue < 0.0) { - return ValidationStatus.error(cannotBeNegativeMessage); - } - return Status.OK_STATUS; - } catch (NumberFormatException ex) { - return ValidationStatus.error(mustBeCurrencyMessage); - } - } - }; - - //Create a number formatter that will display one decimal position. - NumberFormat numberFormat = NumberFormat.getInstance(); - numberFormat.setMinimumFractionDigits(1); - - IConverter targetToModelConverter = StringToNumberConverter.toDouble( - numberFormat, true); - IConverter modelToTargetConverter = NumberToStringConverter.fromDouble( - numberFormat, true); - - getDbc().bindValue( - SWTObservables.observeText(text, SWT.Modify), - BeansObservables.observeValue(adventure, "price"), - new UpdateValueStrategy().setAfterGetValidator(validator) - .setConverter(targetToModelConverter), - new UpdateValueStrategy().setConverter(modelToTargetConverter)); - - String expected = numberFormat.format(adventure.getPrice()); - assertEquals(expected, text.getText()); - assertTrue(AggregateValidationStatus.getStatusMaxSeverity(getDbc().getBindings()).isOK()); - - String toEnter = numberFormat.format(0.65); - enterText(text, toEnter); - assertTrue(AggregateValidationStatus.getStatusMaxSeverity(getDbc().getBindings()).isOK()); - assertEquals(0.65, adventure.getPrice(), 0.0001); - - adventure.setPrice(42.24); - expected = numberFormat.format(adventure.getPrice()); - assertEquals(expected, text.getText()); - assertTrue(AggregateValidationStatus.getStatusMaxSeverity(getDbc().getBindings()).isOK()); - - enterText(text, "jygt"); - assertEquals(mustBeCurrencyMessage, AggregateValidationStatus.getStatusMaxSeverity(getDbc().getBindings()).getMessage()); - - toEnter = numberFormat.format(-23.9); - enterText(text, toEnter); - assertEquals(cannotBeNegativeMessage, AggregateValidationStatus.getStatusMaxSeverity(getDbc().getBindings()).getMessage()); - assertEquals(42.24, adventure.getPrice(), 0.0001); - - adventure.setPrice(0.0); - assertTrue(AggregateValidationStatus.getStatusMaxSeverity(getDbc().getBindings()).isOK()); - } - - public void testScenario08() { - // Binding the price property of an Adventure to a Text control but with - // custom conversion � the double will be validated to only have two - // decimal places and displayed with a leading currency symbol, and can - // be entered with or without the currency symbol. - Text text = new Text(getComposite(), SWT.BORDER); - adventure.setPrice(5.0); - final String cannotBeNegativeMessage = "Price cannot be negative."; - final String mustBeCurrencyMessage = "Price must be a currency."; - final NumberFormat currencyFormat = NumberFormat.getCurrencyInstance(Locale.CANADA); - - IConverter toCurrency = new Converter(double.class, String.class) { - public Object convert(Object toObject) { - return currencyFormat.format(((Double) toObject).doubleValue()); - } - }; - - IConverter toDouble = new Converter(String.class, double.class) { - public Object convert(Object fromObject) { - try { - return new Double(currencyFormat.parse((String) fromObject).doubleValue()); - } catch (ParseException e) { - // TODO throw something like - // IllegalConversionException? - return new Double(0); - } - } - }; - - IValidator validator = new IValidator() { - public IStatus validate(Object value) { - String stringValue = (String) value; - try { - double doubleValue = currencyFormat.parse(stringValue).doubleValue(); - if (doubleValue < 0.0) { - return ValidationStatus.error(cannotBeNegativeMessage); - } - return Status.OK_STATUS; - } catch (ParseException e) { - return ValidationStatus.error(mustBeCurrencyMessage); - } - } - }; - - getDbc().bindValue(SWTObservables.observeText(text, SWT.Modify), - BeansObservables.observeValue(adventure, "price"), -new UpdateValueStrategy().setConverter(toDouble).setAfterGetValidator(validator),new UpdateValueStrategy().setConverter(toCurrency)); - - String expected = currencyFormat.format(5); - assertEquals(expected, text.getText()); - assertTrue(AggregateValidationStatus.getStatusMaxSeverity(getDbc().getBindings()).isOK()); - - String toEnter = currencyFormat.format(0.65); - enterText(text, toEnter); - assertTrue(AggregateValidationStatus.getStatusMaxSeverity(getDbc().getBindings()).isOK()); - assertEquals(0.65, adventure.getPrice(), 0.0001); - - adventure.setPrice(42.24); - expected = currencyFormat.format(adventure.getPrice()); - assertEquals(expected, text.getText()); - - assertTrue(AggregateValidationStatus.getStatusMaxSeverity(getDbc().getBindings()).isOK()); - enterText(text, "jygt"); - assertEquals(mustBeCurrencyMessage, AggregateValidationStatus.getStatusMaxSeverity(getDbc().getBindings()).getMessage()); - - toEnter = currencyFormat.format(-23.9); - enterText(text, toEnter); - - assertEquals(cannotBeNegativeMessage, AggregateValidationStatus.getStatusMaxSeverity(getDbc().getBindings()).getMessage()); - assertEquals(42.24, adventure.getPrice(), 0.0001); - adventure.setPrice(0.0); - assertTrue(AggregateValidationStatus.getStatusMaxSeverity(getDbc().getBindings()).isOK()); - } - - public void testScenario09() { - // Binding a boolean property to a CheckBox. Adventure will have a - // Boolean property �petsAllowed� - Button checkbox = new Button(getComposite(), SWT.CHECK); - // checkbox.setText("Pets allowed"); - // checkbox.setLayoutData(new GridData(SWT.LEFT,SWT.TOP, false,false)); - adventure.setPetsAllowed(true); - - getDbc().bindValue(SWTObservables.observeSelection(checkbox), - BeansObservables.observeValue(adventure, "petsAllowed"), - null, null); - - assertEquals(true, checkbox.getSelection()); - setButtonSelectionWithEvents(checkbox, false); - assertEquals(false, adventure.isPetsAllowed()); - adventure.setPetsAllowed(true); - assertEquals(true, checkbox.getSelection()); - } - - public void testScenario10() { - // Binding a Transportation departure time to a Text control that - // formats and validates the time to and from a String. There are - // property bindings that bind elements of the GUI to elements to GUI - // and also elements of the domain to elements of the domain - // TODO fail("not implemented"); - } - - public void testScenario11() { - // Binding the max value of a spinner to another spinner. - Spinner spinner1 = new Spinner(getComposite(), SWT.NONE); - spinner1.setSelection(10); - spinner1.setMinimum(1); - spinner1.setMaximum(100); - Spinner spinner2 = new Spinner(getComposite(), SWT.NONE); - spinner2.setMaximum(1); - - getDbc().bindValue(SWTObservables.observeSelection(spinner1), SWTObservables.observeMax(spinner2), null, null); - - assertEquals(1, spinner1.getSelection()); - spinner1.setSelection(10); - spinner1.notifyListeners(SWT.Modify, new Event()); - assertEquals(10, spinner2.getMaximum()); - } - - public void testScenario12() { - // Binding the enabled state of several Text controls to a check box. - // There will be two check boxes, so as each is enabled/disabled the - // other one follows as do the states of the Text controls. - Button checkbox1 = new Button(getComposite(), SWT.CHECK); - checkbox1.setSelection(false); - Button checkbox2 = new Button(getComposite(), SWT.CHECK); - checkbox2.setSelection(false); - Text text1 = new Text(getComposite(), SWT.NONE); - Text text2 = new Text(getComposite(), SWT.NONE); - - IObservableValue checkbox1Selected = SWTObservables.observeSelection(checkbox1); - IObservableValue checkbox2Selected = SWTObservables.observeSelection(checkbox2); - - // bind the two checkboxes so that if one is checked, the other is not - // and vice versa. - Converter negatingConverter = new Converter(boolean.class, boolean.class) { - private Boolean negated(Boolean booleanObject) { - return new Boolean(!booleanObject.booleanValue()); - } - - public Object convert(Object targetObject) { - return negated((Boolean) targetObject); - } - }; - - getDbc().bindValue(checkbox1Selected, - checkbox2Selected,new UpdateValueStrategy().setConverter(negatingConverter), - new UpdateValueStrategy().setConverter(negatingConverter)); - - // bind the enabled state of the two text widgets to one of the - // checkboxes each. - - getDbc().bindValue(SWTObservables.observeEnabled(text1), checkbox1Selected, null, null); - getDbc().bindValue(SWTObservables.observeEnabled(text2), checkbox2Selected, null, null); - - assertEquals(true, text1.getEnabled()); - assertEquals(false, text2.getEnabled()); - assertEquals(true, checkbox1.getSelection()); - setButtonSelectionWithEvents(checkbox1, false); - assertEquals(false, text1.getEnabled()); - assertEquals(true, text2.getEnabled()); - assertEquals(true, checkbox2.getSelection()); - setButtonSelectionWithEvents(checkbox2, false); - assertEquals(true, text1.getEnabled()); - assertEquals(false, text2.getEnabled()); - assertEquals(true, checkbox1.getSelection()); - } - - public void testScenario13() { - Text text = new Text(getComposite(), SWT.BORDER); - - getDbc().bindValue(SWTObservables.observeText(text, SWT.FocusOut), BeansObservables.observeValue(adventure, "name"), null, null); - - // uncomment the following line to see what's happening - // happening - // spinEventLoop(1); - String adventureName = adventure.getName(); - assertEquals(adventureName, text.getText()); - enterText(text, "foobar"); - // uncomment the following line to see what's happening - // spinEventLoop(1); - assertEquals("foobar", adventure.getName()); - adventure.setName("barfoo"); - // uncomment the following line to see what's happening - // spinEventLoop(1); - assertEquals("barfoo", text.getText()); - } - - public void testScenario14() { - Text t1 = new Text(getComposite(), SWT.BORDER); - Text t2 = new Text(getComposite(), SWT.BORDER); - - getDbc().bindValue(SWTObservables.observeText(t1, SWT.Modify), BeansObservables.observeValue(adventure, "name"), null, null); - getDbc().bindValue(SWTObservables.observeText(t2, SWT.Modify), BeansObservables.observeValue(adventure, "name"), null, null); - - final int[] counter = { 0 }; - - IObservableValue uv = BeansObservables.observeValue(adventure, "name"); - - uv.addChangeListener(new IChangeListener() { - public void handleChange(ChangeEvent event) { - // Count how many times adventure has changed - counter[0]++; - } - }); - - String name = adventure.getName() + "Foo"; - enterText(t1, name); - assertEquals(name, adventure.getName()); - assertEquals(name, t2.getText()); - assertTrue(counter[0] == 1); - - name = name + "Bar"; - uv.setValue(name); - assertEquals(t1.getText(), adventure.getName()); - assertEquals(2, counter[0]); - - } - - public void testScenario15() { - Text text = new Text(getComposite(), SWT.NONE); - Account account = new Account(); - account.setExpiryDate(new Date()); - - Binding b = getDbc().bindValue(SWTObservables.observeText(text, SWT.Modify), BeansObservables.observeValue(account, "expiryDate"), null, null); - Text errorText = new Text(getComposite(), SWT.NONE); - - getDbc().bindValue(SWTObservables.observeText(errorText, SWT.Modify), b.getValidationStatus(), new UpdateValueStrategy(false, UpdateValueStrategy.POLICY_NEVER), null); - assertTrue(((IStatus)b.getValidationStatus().getValue()).isOK()); - enterText(text, "foo"); - assertFalse(((IStatus)b.getValidationStatus().getValue()).isOK()); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/ScenariosTestCase.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/ScenariosTestCase.java deleted file mode 100644 index b55c59bc..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/ScenariosTestCase.java +++ /dev/null @@ -1,147 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 116920 - *******************************************************************************/ -package org.eclipse.jface.tests.databinding.scenarios; - -import java.util.Arrays; - -import junit.framework.TestCase; - -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.jface.databinding.conformance.util.RealmTester; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.examples.databinding.model.SampleData; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -/** - * Abstract base class of the JFace binding scenario test classes. - */ -abstract public class ScenariosTestCase extends TestCase { - - private Composite composite; - private DataBindingContext dbc; - protected Display display; - private boolean disposeDisplay = false; - protected Shell shell; - protected Text dummyText; - protected Realm realm; - - protected Composite getComposite() { - return composite; - } - - protected DataBindingContext getDbc() { - return dbc; - } - - public Shell getShell() { - if (shell != null) { - return shell; - } - Shell result = BindingScenariosTestSuite.getShell(); - if (result == null) { - display = Display.getDefault(); - if (Display.getDefault() == null) { - display = new Display(); - disposeDisplay = true; - } - shell = new Shell(display, SWT.SHELL_TRIM); - shell.setLayout(new FillLayout()); - result = shell; - } - result.setText(getName()); // In the case that the shell() becomes - // visible. - return result; - } - - protected void spinEventLoop(int secondsToWaitWithNoEvents) { - if (!composite.isVisible() && secondsToWaitWithNoEvents > 0) { - composite.getShell().open(); - } - while (composite.getDisplay().readAndDispatch()) { - // do nothing, just process events - } - try { - Thread.sleep(secondsToWaitWithNoEvents * 1000); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - } - - protected void interact() { - if (!getShell().isVisible()) { - getShell().open(); - } - while (!getShell().isDisposed()) { - if (!getShell().getDisplay().readAndDispatch()) { - getShell().getDisplay().sleep(); - } - } - } - - protected void setButtonSelectionWithEvents(Button button, boolean value) { - if (button.getSelection() == value) { - return; - } - button.setSelection(value); - pushButtonWithEvents(button); - } - - protected void pushButtonWithEvents(Button button) { - button.notifyListeners(SWT.Selection, null); - } - - protected void setUp() throws Exception { - realm = SWTObservables.getRealm(Display.getDefault()); - RealmTester.setDefault(realm); - - composite = new Composite(getShell(), SWT.NONE); - composite.setLayout(new FillLayout()); - SampleData.initializeData(); // test may manipulate the data... let - // all start from fresh - dbc = new DataBindingContext(); - dummyText = new Text(getComposite(), SWT.NONE); - dummyText.setText("dummy"); - } - - protected void tearDown() throws Exception { - realm = null; - getShell().setVisible(false); // same Shell may be reUsed across tests - composite.dispose(); - composite = null; - if (shell != null) { - shell.close(); - shell.dispose(); - } else - dbc.dispose(); - if (display != null && disposeDisplay) { - display.dispose(); - } - } - - protected void enterText(Text text, String string) { - text.notifyListeners(SWT.FocusIn, null); - text.setText(string); - text.notifyListeners(SWT.FocusOut, null); - } - - protected void assertArrayEquals(Object[] expected, Object[] actual) { - assertEquals(Arrays.asList(expected), Arrays.asList(actual)); - } - -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/SpinnerControlScenario.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/SpinnerControlScenario.java deleted file mode 100644 index b1d2ad2f..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/SpinnerControlScenario.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 116920 - *******************************************************************************/ -package org.eclipse.jface.tests.databinding.scenarios; - -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.examples.databinding.model.Adventure; -import org.eclipse.jface.examples.databinding.model.SampleData; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Spinner; - -/** - * To run the tests in this class, right-click and select "Run As JUnit Plug-in - * Test". This will also start an Eclipse instance. To clean up the launch - * configuration, open up its "Main" tab and select "[No Application] - Headless - * Mode" as the application to run. - */ - -public class SpinnerControlScenario extends ScenariosTestCase { - - private Adventure adventure; - - protected void setUp() throws Exception { - super.setUp(); - // do any setup work here - adventure = SampleData.WINTER_HOLIDAY; - } - - protected void tearDown() throws Exception { - // do any teardown work here - super.tearDown(); - } - - public void testScenario01() { - // Bind the adventure "maxNumberOfPeople" property to a spinner - // Change the UI and verify the model changes - // Change the model and verify the UI changes - Spinner spinner = new Spinner(getComposite(), SWT.BORDER); - getDbc().bindValue(SWTObservables.observeSelection(spinner), - BeansObservables.observeValue(adventure, "maxNumberOfPeople"), - null, null); - - assertEquals(adventure.getMaxNumberOfPeople(), spinner.getSelection()); - // Verify the model is updated when the GUI is changed - spinner.setSelection(5); - assertEquals(5, adventure.getMaxNumberOfPeople()); - // Verify the GUI is updated when the model changes - adventure.setMaxNumberOfPeople(7); - assertEquals(7, spinner.getSelection()); - adventure.setMaxNumberOfPeople(11); - spinEventLoop(0); - assertEquals(11, spinner.getSelection()); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/TableScenarios.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/TableScenarios.java deleted file mode 100644 index 70c38acb..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/TableScenarios.java +++ /dev/null @@ -1,451 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 116920 - * Brad Reynolds - bug 160000 - *******************************************************************************/ -package org.eclipse.jface.tests.databinding.scenarios; - -import java.util.ArrayList; -import java.util.Arrays; - -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; -import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; -import org.eclipse.jface.examples.databinding.model.Account; -import org.eclipse.jface.examples.databinding.model.Catalog; -import org.eclipse.jface.examples.databinding.model.Category; -import org.eclipse.jface.examples.databinding.model.SampleData; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.swt.widgets.TableItem; - -/** - * To run the tests in this class, right-click and select "Run As JUnit Plug-in - * Test". This will also start an Eclipse instance. To clean up the launch - * configuration, open up its "Main" tab and select "[No Application] - Headless - * Mode" as the application to run. - */ - -public class TableScenarios extends ScenariosTestCase { - - private TableViewer tableViewer; - - private Catalog catalog; - - Category category; - - private TableColumn firstNameColumn; - - private TableColumn lastNameColumn; - - private TableColumn stateColumn; - - Image[] images; - - private TableColumn fancyColumn; - - protected void setUp() throws Exception { - super.setUp(); - getComposite().setLayout(new FillLayout()); - tableViewer = new TableViewer(getComposite()); - tableViewer.getTable().setLinesVisible(true); - tableViewer.getTable().setHeaderVisible(true); - firstNameColumn = new TableColumn(tableViewer.getTable(), SWT.NONE); - firstNameColumn.setWidth(50); - lastNameColumn = new TableColumn(tableViewer.getTable(), SWT.NONE); - lastNameColumn.setWidth(50); - stateColumn = new TableColumn(tableViewer.getTable(), SWT.NONE); - stateColumn.setWidth(50); - fancyColumn = new TableColumn(tableViewer.getTable(), SWT.NONE); - fancyColumn.setWidth(250); - - catalog = SampleData.CATALOG_2005; // Lodging source - category = SampleData.WINTER_CATEGORY; - - images = new Image[] { - getShell().getDisplay().getSystemImage(SWT.ICON_ERROR), - getShell().getDisplay().getSystemImage(SWT.ICON_WARNING), - getShell().getDisplay().getSystemImage(SWT.ICON_INFORMATION), }; - } - - protected void tearDown() throws Exception { - // do any teardown work here - super.tearDown(); - tableViewer.getTable().dispose(); - tableViewer = null; - firstNameColumn = null; - lastNameColumn = null; - stateColumn = null; - } - - public void testScenario01() { - // Show that a TableViewer with three columns renders the accounts - Account[] accounts = catalog.getAccounts(); - - IObservableList list = new WritableList(new ArrayList(), Account.class); - list.addAll(Arrays.asList(accounts)); - - ObservableListContentProvider contentProvider = new ObservableListContentProvider(); - IObservableMap[] attributeMaps = BeansObservables.observeMaps( - contentProvider.getKnownElements(), Account.class, - new String[] { "firstName", "lastName", "state" }); - - tableViewer.setContentProvider(contentProvider); - tableViewer.setLabelProvider(new ObservableMapLabelProvider( - attributeMaps)); - tableViewer.setInput(list); - - Table table = tableViewer.getTable(); - - // Verify the data in the table columns matches the accounts - for (int i = 0; i < accounts.length; i++) { - Account account = catalog.getAccounts()[i]; - TableItem item = table.getItem(i); - - assertEquals(account.getFirstName(), item.getText(0)); - assertEquals(account.getLastName(), item.getText(1)); - assertEquals(account.getState(), item.getText(2)); - } - } - - public void testScenario02() throws SecurityException, - IllegalArgumentException { - // Show that a TableViewer with three columns can be used to update - // columns - // Account[] accounts = catalog.getAccounts(); - // - // TableModelDescription tableModelDescription = new - // TableModelDescription(new Property(catalog, "accounts"), new - // String[]{"firstName","lastName","state"}); - // // tableViewerDescription.addEditableColumn("firstName"); - // // tableViewerDescription.addEditableColumn("lastName", null, null, - // new PhoneConverter()); - // // tableViewerDescription.addEditableColumn("state", null, null, new - // StateConverter()); - // getDbc().bind(tableViewer, - // tableModelDescription, null); - // - // Account account = accounts[0]; - // // Select the first item in the table - // tableViewer.editElement(account, 0); - // // Set the text property of the cell editor which is now active over - // the "firstName" column - // CellEditor[] cellEditors = tableViewer.getCellEditors(); - // TextCellEditor firstNameEditor = (TextCellEditor) cellEditors[0]; - // // Change the firstName and test it goes to the model - // enterText((Text) firstNameEditor.getControl(), "Bill"); - // // Check whether the model has changed - // assertEquals("Bill",account.getFirstName()); - } - - public void testScenario04() { - // // Show that when an item is added to a collection the table gets an - // extra item - // Account[] accounts = catalog.getAccounts(); - // - // TableViewerDescription tableViewerDescription = new - // TableViewerDescription( - // tableViewer); - // tableViewerDescription.addColumn("firstName"); - // tableViewerDescription.addColumn("lastName"); - // tableViewerDescription.addColumn("state"); - // tableViewerDescription.addColumn(null,new IConverter(){ - // - // public Class getModelType() { - // return Account.class; - // } - // - // public Class getTargetType() { - // return ViewerLabel.class; - // } - // - // public Object convertTargetToModel(Object targetObject) { - // return null; - // } - // - // public Object convertModelToTarget(Object modelObject) { - // Account account = (Account) modelObject; - // return new ViewerLabel(account.toString(), images[new - // Random().nextInt(images.length)]); - // }}); - // getDbc().bind(tableViewerDescription, - // new Property(catalog, "accounts"), null); - // - // //interact(); - // - // // Verify the number of accounts matches the number of items in the - // table - // assertEquals(tableViewer.getTable().getItemCount(),accounts.length); - // // Add a new account and verify that the number of items in the table - // increases - // Account newAccount = new Account(); - // newAccount.setFirstName("Finbar"); - // newAccount.setLastName("McGoo"); - // newAccount.setLastName("NC"); - // catalog.addAccount(newAccount); - // // The number of items should have gone up by one - // assertEquals(tableViewer.getTable().getItemCount(),accounts.length + - // 1); - // // The number of items should still match the number of accounts - // (i.e. test the model) - // assertEquals(tableViewer.getTable().getItemCount(),catalog.getAccounts().length); - // // Remove the account that was just added - // catalog.removeAccount(newAccount); - // // The number of items should match the original - // assertEquals(tableViewer.getTable().getItemCount(),accounts.length); - // // The number of items should still match the number of accounts - // (i.e. test the model is reset) - // assertEquals(tableViewer.getTable().getItemCount(),catalog.getAccounts().length); - // - // // Test adding and removing to the model on a non UI thread - // int numberOfAccounts = catalog.getAccounts().length; - // final Account barney = new Account(); - // barney.setFirstName("Barney"); - // barney.setLastName("Smith"); - // barney.setLastName("CA"); - // invokeNonUI(new Runnable(){ - // public void run(){ - // catalog.addAccount(barney); - // } - // }); - // spinEventLoop(0); - // // The number of items should have gone up by one - // assertEquals(tableViewer.getTable().getItemCount(),numberOfAccounts + - // 1); - // - // invokeNonUI(new Runnable(){ - // public void run(){ - // catalog.removeAccount(barney); - // } - // }); - // spinEventLoop(0); - // // The number of items should have reverted to the original number - // before barney was added and removed - // assertEquals(tableViewer.getTable().getItemCount(),numberOfAccounts); - // - } - - public void testScenario03() { - // // Show that converters work for table columns - // Account[] accounts = catalog.getAccounts(); - // - // TableViewerDescription tableViewerDescription = new - // TableViewerDescription( - // tableViewer); - // tableViewerDescription.addEditableColumn("lastName"); - // tableViewerDescription.addEditableColumn("phone", null, null , - // new PhoneConverter()); - // tableViewerDescription.addEditableColumn("state", null, null , - // new StateConverter()); - // getDbc().bind(tableViewerDescription, - // new Property(catalog, "accounts"), null); - // - // // Verify that the data in the the table columns matches the expected - // // What we are looking for is that the phone numbers are converterted - // to - // // nnn-nnn-nnnn and that - // // the state letters are converted to state names - // // Verify the data in the table columns matches the accounts - // PhoneConverter phoneConverter = new PhoneConverter(); - // StateConverter stateConverter = new StateConverter(); - // for (int i = 0; i < accounts.length; i++) { - // Account account = catalog.getAccounts()[i]; - // // Check the phone number - // String col_phone = ((ITableLabelProvider) tableViewer - // .getLabelProvider()).getColumnText(account, 1); - // assertEquals(getValue((String)phoneConverter - // .convertModelToTarget(account.getPhone())), col_phone); - // String col_state = ((ITableLabelProvider) tableViewer - // .getLabelProvider()).getColumnText(account, 2); - // assertEquals(getValue((String)stateConverter - // .convertModelToTarget(account.getState())), col_state); - // } - } - - public void testScenario05() { - // // Show that when the model changes then the UI refreshes to reflect - // this - // - // TableViewerDescription tableViewerDescription = new - // TableViewerDescription( - // tableViewer); - // tableViewerDescription.addColumn("lastName"); - // tableViewerDescription.addColumn("phone", - // new PhoneConverter()); - // tableViewerDescription.addColumn("state", - // new StateConverter()); - // getDbc().bind(tableViewerDescription, - // new Property(catalog, "accounts"), null); - // - // final Account account = catalog.getAccounts()[0]; - // String lastName = tableViewer.getTable().getItem(0).getText(0); - // // Check the firstName in the TableItem is the same as the model - // assertEquals(lastName,account.getLastName()); - // // Now change the model and check again - // account.setLastName("Gershwin"); - // lastName = tableViewer.getTable().getItem(0).getText(0); - // assertEquals(lastName,account.getLastName()); - // - // // Test the model update on a non UI thread - // invokeNonUI(new Runnable(){ - // public void run(){ - // account.setLastName("Mozart"); - // } - // }); - // spinEventLoop(0); - // lastName = tableViewer.getTable().getItem(0).getText(0); - // assertEquals(lastName,account.getLastName()); - // - } - - public void testScenario06() { - // // Check that explicit type means that defaulting of converters works - // TableViewerDescription tableViewerDescription = new - // TableViewerDescription( - // tableViewer); - // tableViewerDescription.addEditableColumn("price"); - // tableViewerDescription.getColumn(0).setPropertyType(Double.TYPE); - // getDbc().bind(tableViewerDescription, - // new Property(catalog, "transporations"), null); - // Transportation transporation = catalog.getTransporations()[0]; - // tableViewer.editElement(transporation, 0); - // // Set the text property of the cell editor which is now active over - // the "firstName" column - // CellEditor[] cellEditors = tableViewer.getCellEditors(); - // TextCellEditor priceEditor = (TextCellEditor) cellEditors[0]; - // // Change the firstName and test it goes to the model - // enterText((Text) priceEditor.getControl(), "123.45"); - // // Verify the model is updated - // assertEquals(transporation.getPrice(),123.45,0); - - } - - public void testScenario07() { - // // Verify that even when a column's property type is not set, that it - // is worked out lazily from the target type - // TableViewerDescription tableViewerDescription = new - // TableViewerDescription( - // tableViewer); - // tableViewerDescription.addEditableColumn("price"); - // // The column's type is not set to be Double.TYPE. This will be - // inferred once the first Transportation object is set - // // into the ObservableCollection - // getDbc().bind(tableViewerDescription, - // new Property(catalog, "transporations"), null); - // Transportation transporation = catalog.getTransporations()[0]; - // tableViewer.editElement(transporation, 0); - // // Set the text property of the cell editor which is now active over - // the "firstName" column - // CellEditor[] cellEditors = tableViewer.getCellEditors(); - // TextCellEditor priceEditor = (TextCellEditor) cellEditors[0]; - // // Change the firstName and test it goes to the model - // enterText((Text) priceEditor.getControl(), "123.45"); - // // Verify the model is updated - // assertEquals(transporation.getPrice(),123.45,0); - // - } - - public void testScenario08_00() { - // // Verify that binding to a Collection property (rather than an - // array) works when specifying data type - // TableViewerDescription tableViewerDescription = new - // TableViewerDescription( - // tableViewer); - // tableViewerDescription.addEditableColumn("userId"); - // tableViewerDescription.addEditableColumn("password"); - // getDbc().bind(tableViewerDescription, - // new Property(catalog, "signons", Signon.class, null), null); - // Signon firstSignon = (Signon) catalog.getSignons().get(0); - // // Verify the UI matches the model - // TableItem firstTableItem = tableViewer.getTable().getItem(0); - // assertEquals(firstTableItem.getText(1),firstSignon.getPassword()); - // // Change the model and ensure the UI refreshes - // firstSignon.setPassword("Eclipse123Rocks"); - // assertEquals("Eclipse123Rocks",firstSignon.getPassword()); - // assertEquals(firstTableItem.getText(1),firstSignon.getPassword()); - // // Change the GUI and ensure the model refreshes - // tableViewer.editElement(firstSignon, 1); - // CellEditor[] cellEditors = tableViewer.getCellEditors(); - // TextCellEditor passwordEditor = (TextCellEditor) cellEditors[1]; - // enterText((Text) passwordEditor.getControl(), "Cricket11Players"); - // assertEquals("Cricket11Players",firstSignon.getPassword()); - // - } - - public void testScenario08_01() { - // // Verify that binding to a Collection property (rather than an - // array) works without specifying data type - // TableViewerDescription tableViewerDescription = new - // TableViewerDescription( - // tableViewer); - // tableViewerDescription.addEditableColumn("userId"); - // tableViewerDescription.addEditableColumn("password"); - // getDbc().bind(tableViewerDescription, - // new Property(catalog, "signons"), null); - // Signon firstSignon = (Signon) catalog.getSignons().get(0); - // // Verify the UI matches the model - // TableItem firstTableItem = tableViewer.getTable().getItem(0); - // assertEquals(firstTableItem.getText(1),firstSignon.getPassword()); - // // Change the model and ensure the UI refreshes - // firstSignon.setPassword("Eclipse123Rocks"); - // assertEquals("Eclipse123Rocks",firstSignon.getPassword()); - // assertEquals(firstTableItem.getText(1),firstSignon.getPassword()); - // // Change the GUI and ensure the model refreshes - // tableViewer.editElement(firstSignon, 1); - // CellEditor[] cellEditors = tableViewer.getCellEditors(); - // TextCellEditor passwordEditor = (TextCellEditor) cellEditors[1]; - // enterText((Text) passwordEditor.getControl(), "Cricket11Players"); - // assertEquals("Cricket11Players",firstSignon.getPassword()); - // - } - - public void testScenario09() { - // // Verify that nested properties work. Catalog has adventures. - // Adventure has defaultLodging. Loding has name. - // TableViewerDescription tableViewerDescription = new - // TableViewerDescription(tableViewer); - // tableViewerDescription.addColumn("name"); - // tableViewerDescription.addColumn("defaultLodging.name"); - // getDbc().bind(tableViewerDescription,new Property(category, - // "adventures"),null); - // - } - /** - * public void testScenario10(){ // Verify that for TIME_EARLY updating - * occurs on a per key basic for a TextCellEditor // Show that converters - * work for table columns Account[] accounts = catalog.getAccounts(); - * Account firstAccount = accounts[0]; - * SampleData.getSWTObservableFactory().setUpdateTime(DataBindingContext.TIME_EARLY); - * TableViewerDescription tableViewerDescription = new - * TableViewerDescription(tableViewer); - * tableViewerDescription.addEditableColumn("lastName"); - * tableViewerDescription.addColumn("lastName"); - * getDbc().bind(tableViewerDescription,new Property(catalog, "accounts"), - * null); // Verify that the first account is shown in the first row with - * the last name correctly - * assertEquals(tableViewer.getTable().getItem(0).getData(),firstAccount); - * assertEquals(tableViewer.getTable().getItem(0).getText(0),firstAccount.getLastName()); - * assertEquals(tableViewer.getTable().getItem(0).getText(1),firstAccount.getLastName()); // - * Create a cell editor over the first column - * tableViewer.editElement(firstAccount, 0); // Set the text property of the - * cell editor which is now active over the "firstName" column CellEditor[] - * cellEditors = tableViewer.getCellEditors(); TextCellEditor - * lastNameCellEditor = (TextCellEditor) cellEditors[0]; - * ((Text)lastNameCellEditor.getControl()).setText("E"); // Verify that the - * key press goes to the model assertEquals(firstAccount.getLastName(),"E"); } - */ -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/TextControlScenario.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/TextControlScenario.java deleted file mode 100644 index 500b09bf..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/TextControlScenario.java +++ /dev/null @@ -1,310 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 116920 - *******************************************************************************/ -package org.eclipse.jface.tests.databinding.scenarios; - -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.examples.databinding.model.Account; -import org.eclipse.jface.examples.databinding.model.Adventure; -import org.eclipse.jface.examples.databinding.model.SampleData; -import org.eclipse.jface.examples.databinding.model.Transportation; -import org.eclipse.jface.tests.databinding.BindingTestSuite; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; - -import com.ibm.icu.text.NumberFormat; - -/** - * To run the tests in this class, right-click and select "Run As JUnit Plug-in - * Test". This will also start an Eclipse instance. To clean up the launch - * configuration, open up its "Main" tab and select "[No Application] - Headless - * Mode" as the application to run. - */ - -public class TextControlScenario extends ScenariosTestCase { - - private Text text; - - private Adventure adventure; - - private Transportation transportation; - - Account account; - - protected void setUp() throws Exception { - super.setUp(); - // do any setup work here - adventure = SampleData.WINTER_HOLIDAY; - transportation = SampleData.EXECUTIVE_JET; - account = SampleData.PRESIDENT; - text = new Text(getComposite(), SWT.BORDER); - } - - protected void tearDown() throws Exception { - text.dispose(); - text = null; - super.tearDown(); - } - - public void testScenario01() { - // Bind the adventure "name" property to a text field - // Change the UI and verify the model changes - // Change the model and verify the UI changes - getDbc().bindValue(SWTObservables.observeText(text, SWT.Modify), - BeansObservables.observeValue(adventure, "name"), - null, null); - - assertEquals(adventure.getName(), text.getText()); - text.setText("England"); - text.notifyListeners(SWT.FocusOut, null); - assertEquals("England", adventure.getName()); - adventure.setName("France"); - assertEquals("France", text.getText()); - adventure.setName("Germany"); - spinEventLoop(0); - assertEquals("Germany", text.getText()); - } - - public void testScenario02() { - - // Bind the transportation "price" property to a text field - // This is a Double.TYPE so we check that conversion and validation - // occurs - // Change the UI and verify the model changes - // Change the model and verify the UI changes - getDbc().bindValue(SWTObservables.observeText(text, SWT.Modify), - BeansObservables.observeValue(transportation, "price"), - null, null); - - NumberFormat numberFormat = NumberFormat.getInstance(); - - assertEquals(numberFormat.format(transportation.getPrice()), text.getText()); - text.setText("9876.54"); - text.notifyListeners(SWT.FocusOut, null); - assertEquals(9876.54, transportation.getPrice(), 0); - - transportation.setPrice(1234.56); - assertEquals(numberFormat.format(transportation.getPrice()), text.getText()); - } - -// public void testScenario03() { -// // Show that the Escape key can be pressed in the middle of editing and -// // the value will revert -// // the updatePolicy for this test is TIME_LATE so it occurs when focus -// // is lost from the Text control -// getDbc().bindValue(SWTObservables.observeText(text, SWT.FocusOut), -// BeansObservables.observeValue(adventure, "name"), -// null, null); -// -// String currentText = text.getText(); -// text.setText("Switzerland"); -// // We do not notify FocusOut -// // Verify that the model hasn't changed -// assertEquals(currentText, adventure.getName()); -// Event event = new Event(); -// event.character = SWT.ESC; -// event.keyCode = 27; -// text.notifyListeners(SWT.KeyDown, event); -// // Verify that the text has reverted -// assertEquals(currentText, text.getText()); -// // And that the model didn't change -// assertEquals(adventure.getName(), currentText); -// // Now change the GUI and commit this change -// currentText = "Austria"; -// text.setText(currentText); -// text.notifyListeners(SWT.FocusOut, null); -// assertEquals(text.getText(), adventure.getName()); -// // Now change the text again and press escape a second time -// text.setText("Turkey"); -// // Send escape -// text.notifyListeners(SWT.KeyDown, event); -// // Verify it has reverted to "Austria" and not any other value, i.e. the -// // last value it displayed -// assertEquals(currentText, text.getText()); -// -// } - -// public void testScenario04() { -// // Show that the Escape key can be pressed in the middle of editing and -// // the value will revert -// // the updatePolicy for this test is TIME_EARLY so it occurs when each -// // keystroke occurs -// getDbc().bindValue(SWTObservables.observeText(text, SWT.Modify), -// BeansObservables.observeValue(adventure, "name"), -// null, null); -// -// String originalName = adventure.getName(); -// // Change the text field character by character and ensure that the -// // model changes -// String newName = "Switzerland"; -// for (int i = 0; i < newName.length(); i++) { -// text.setText(newName.substring(0, i + 1)); -// // Verify the model has changed -// assertEquals(newName.substring(0, i + 1), adventure.getName()); -// } -// -// // Now send an escape key and verify that the model reverts -// Event event = new Event(); -// event.character = SWT.ESC; -// event.keyCode = 27; -// text.notifyListeners(SWT.KeyDown, event); -// assertEquals(adventure.getName(), originalName); -// -// // Now send "Austria" key by key -// newName = "Austria"; -// for (int i = 0; i < newName.length(); i++) { -// text.setText(newName.substring(0, i + 1)); -// // Verify the model has changed -// assertEquals(newName.substring(0, i + 1), adventure.getName()); -// } -// // Send a focus lost event to commit the change -// text.notifyListeners(SWT.FocusOut, null); -// // Send an escape key -// text.notifyListeners(SWT.KeyDown, event); -// // Verify that the model has changed and has not reverted -// assertEquals(newName, adventure.getName()); -// } - - /** - * public void testScenario05(){ // Show that nesting of properties works. - * Adventure has defaultLodging and Lodging has name getDbc().bind(text,new - * Property(adventure,"defaultLodging.name"),null); // Verify the GUI is - * showing the model value - * assertEquals(text.getText(),adventure.getDefaultLodging().getName()); } - */ - public void testScenario06() { - // // Show that partial validation works for TIME_EARLY - // // We are using TIME_EARLY to verify that invalid states are not sent - // to the model - // getSWTObservableFactory().setUpdateTime(DataBindingContext.TIME_EARLY); - // getDbc().bind(text, new Property(account, "phone"), new BindSpec(new - // PhoneConverter(),new PhoneValidator())); - // // Verify we have no error message for partial validation or full - // validation yet - // assertTrue(((String)getDbc().getPartialValidationMessage().getValue()).length() - // == 0); - // assertTrue(((String)getDbc().getValidationMessage().getValue()).length() - // == 0); - // // Update some of the phone number - // String originalPhoneNumber = account.getPhone(); - // text.setText("999"); - // // Verify that the phone number is partially invalid and there is no - // validation message - // assertTrue(((String)getDbc().getPartialValidationMessage().getValue()).length() - // > 0); - // assertTrue(((String)getDbc().getValidationMessage().getValue()).length() - // == 0); - // // And that the model has not changed - // assertEquals(account.getPhone(),originalPhoneNumber); - // // Verify that fixing the phone removes the error and the model is - // updated too - // text.setText("999-888-7777"); - // assertTrue(((String)getDbc().getPartialValidationMessage().getValue()).length() - // == 0); - // assertEquals(account.getPhone(),"9998887777"); - } - - public void testScenario07() { - // // Show that partial validation works for TIME_LATE - // getSWTObservableFactory().setUpdateTime(DataBindingContext.TIME_LATE); - // getDbc().bind(text, new Property(account, "phone"), new BindSpec(new - // PhoneConverter(),new PhoneValidator())); - // // Update some of the phone number - // String originalPhoneNumber = account.getPhone(); - // text.setText("222"); - // // Verify that we have no completion validation message and a partial - // one - // assertTrue(((String)getDbc().getPartialValidationMessage().getValue()).length() - // > 0); - // assertTrue(((String)getDbc().getValidationMessage().getValue()).length() - // == 0); - // // Fix the error - // text.setText("222-333-4444"); - // // Verify that the errors are both fixed - // assertTrue(((String)getDbc().getPartialValidationMessage().getValue()).length() - // == 0); - // assertTrue(((String)getDbc().getValidationMessage().getValue()).length() - // == 0); - // // The model should not be changed - // assertEquals(originalPhoneNumber,account.getPhone()); - // // Lose focus and verify that the complete validation message is - // fixed - // text.notifyListeners(SWT.FocusOut,null); - // assertTrue(((String)getDbc().getValidationMessage().getValue()).length() - // == 0); - // // The model should be changed - // assertEquals("2223334444",account.getPhone()); - } - - public void testScenario08() { - - if (BindingTestSuite.failingTestsDisabled(this)) { - return; - } - - // Show that the CustomBeanBindSupportFactory will automatically pick up - // the - // validator on the MaxNumberOfPeople property - - DataBindingContext dbc = getDbc(); - - dbc.bindValue(SWTObservables.observeText(text, SWT.Modify), - BeansObservables.observeValue(adventure, "maxNumberOfPeople"), - new CustomBeanUpdateValueStrategy(), null); - - // make sure we can set a value inside the validator's range - text.setText("4"); - assertEquals(4, adventure.getMaxNumberOfPeople()); - // Now try to set a value outside the validator's range - text.setText("999"); - assertEquals(4, adventure.getMaxNumberOfPeople()); - dbc.dispose(); - } - - public void testScenario09() { - // Verify direct binding between a Text and Label following bugzilla - // 118696 - Label label = new Label(getComposite(), SWT.NONE); - getDbc().bindValue(SWTObservables.observeText(text, SWT.FocusOut), SWTObservables.observeText(label), null, null); - - // Change the text - text.setText("Frog"); - // Verify the label does not change - assertTrue(label.getText().length() == 0); - // Lose focus from the text field - text.notifyListeners(SWT.FocusOut, null); - assertEquals(label.getText(), "Frog"); - - } - - public void testScenario10() { - // Verify direct binding between a Text and Label following bugzilla - // 118696 with TIME_EARLY - Label label = new Label(getComposite(), SWT.NONE); - getDbc().bindValue(SWTObservables.observeText(text, SWT.Modify), SWTObservables.observeText(label), null, null); - - // Change the text - String newTextValue = "Frog"; - for (int i = 0; i < newTextValue.length(); i++) { - text.setText(newTextValue.substring(0, i + 1)); - // Verify the label has changed key by key - assertEquals(text.getText(), label.getText()); - } - // Lose focus - text.notifyListeners(SWT.FocusOut, null); - // Verify the text and label are the same following a lose focus - assertEquals(text.getText(), label.getText()); - } - -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/smoketest/swt.xswt b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/smoketest/swt.xswt deleted file mode 100644 index 0097d63e..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/smoketest/swt.xswt +++ /dev/null @@ -1,301 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?>
-<xswt xmlns:x="http://sweet_swt.sf.net/xswt">
- <import xmlns="http://sweet_swt.sf.net/xswt">
- <package name="java.lang"/>
- <package name="org.eclipse.swt.widgets"/>
- <package name="org.eclipse.swt.custom"/>
- <package name="org.eclipse.swt.layout"/>
- </import>
-
- <!-- An XSWT example that uses nearly every SWT control and uses the new
- syntax wherever possible.
-
- Get XSWT at:
-
- http://xswt.sourceforge.net/updates
-
- then choose Window | Show View | Other... | XSWT Views | XSWT Preview -->
-
- <layout x:class="gridLayout"/>
-
- <label text="SWT Controls:"/>
- <tabFolder>
- <layoutData x:class="gridData" grabExcessHorizontalSpace="true" grabExcessVerticalSpace="true" horizontalAlignment="GridData.FILL" verticalAlignment="GridData.FILL"/>
-
- <composite x:id="Text">
- <layoutData x:class="gridData" grabExcessHorizontalSpace="true" horizontalAlignment="GridData.FILL"/>
- <layout x:class="gridLayout" numColumns="2"/>
-
- <composite x:style="BORDER">
- <layoutData x:class="gridData" grabExcessHorizontalSpace="true" verticalAlignment="GridData.FILL" horizontalAlignment="GridData.FILL"/>
- <layout x:class="gridLayout" numColumns="2"/>
-
- <label text="Integer:"/><text x:style="BORDER" x:id="intText" text="1"/>
- <label text="Float:"/><text x:style="BORDER" x:id="floatText" text="1.0"/>
- <label text="String:"/><text x:style="BORDER" x:id="stringText" text="The quick brown fox jumped over the lazy dog."/>
- <label text="RegexValidated String:"/><text x:style="BORDER" x:id="regexStringText" text="The quick brown fox jumped over the lazy dog."/>
- <label text="Masked String:"/><text x:style="BORDER" x:id="maskedStringText" background="208 128 128"/>
- </composite>
- <slider x:style="VERTICAL" x:id="buttonScroller">
- <layoutData x:class="gridData" verticalAlignment="GridData.FILL"/>
- </slider>
- </composite>
- <tabItem text="Text" control="Text"/>
-
- <composite x:id="Labels">
- <layoutData x:class="gridData" grabExcessHorizontalSpace="true" horizontalAlignment="GridData.FILL"/>
- <layout x:class="gridLayout" numColumns="2"/>
-
- <composite x:style="BORDER">
- <layoutData x:class="gridData" grabExcessHorizontalSpace="true" verticalAlignment="GridData.FILL" horizontalAlignment="GridData.FILL"/>
- <layout x:class="gridLayout" numColumns="1"/>
-
- <label text="Label with text"/>
- <label text="Label with image"/>
- <label text="Label with text and image"/>
- <label x:style="SEPARATOR | HORIZONTAL"><layoutData x:class="gridData" grabExcessHorizontalSpace="true" horizontalAlignment="GridData.FILL"/></label>
- <cLabel text="CLabel with text"/>
- <cLabel text="CLabel with image"/>
- <cLabel text="CLabel with text and image"/>
- </composite>
- <slider x:style="VERTICAL" x:id="textScroller"/>
- </composite>
- <tabItem text="Label / CLabel" control="Labels"/>
-
- <composite x:id="Button">
- <layoutData x:class="gridData" grabExcessHorizontalSpace="true" horizontalAlignment="GridData.FILL"/>
- <layout x:class="gridLayout" numColumns="2"/>
-
- <composite x:style="BORDER">
- <layoutData x:class="gridData" grabExcessHorizontalSpace="true" verticalAlignment="GridData.FILL" horizontalAlignment="GridData.FILL"/>
- <layout x:class="gridLayout" numColumns="2"/>
-
- <label text="Push:"/><button x:id="pushButton" text="PushButton"/>
- <label text="Arrow:"/><button x:id="arrowButton" x:style="ARROW" text="ArrowButton"/>
- <label text="Toggle:"/><button x:id="toggleButton" x:style="TOGGLE" text="ToggleButton"/>
- <label text="Check:"/><button x:style="CHECK" x:id="checkButton" text="CheckBox"/>
- <label text="Radio Group 1:"/>
- <composite x:style="BORDER" x:id="radioGroup1">
- <layoutData x:class="gridData" horizontalAlignment="GridData.FILL"/>
- <layout x:class="gridLayout" numColumns="1"/>
-
- <button x:style="RADIO" x:id="radioButton0.1" text="Radio"/>
- <button x:style="RADIO" x:id="radioButton0.2" text="Radio2" selection="true"/>
- <button x:style="RADIO" x:id="radioButton0.3" text="Radio3"/>
- </composite>
- <label text="Radio Group 2:"/>
- <composite x:style="BORDER" x:id="radioGroup2">
- <layoutData x:class="gridData" horizontalAlignment="GridData.FILL"/>
- <layout x:class="gridLayout" numColumns="1"/>
-
- <button x:style="RADIO" x:id="radioButton1.1" text="Radio"/>
- <button x:style="RADIO" x:id="radioButton1.2" text="Radio2"/>
- <button x:style="RADIO" x:id="radioButton1.3" text="Radio3"/>
- </composite>
- </composite>
- <slider x:style="VERTICAL" x:id="1buttonScroller">
- <layoutData x:class="gridData" verticalAlignment="GridData.FILL"/>
- </slider>
- </composite>
- <tabItem text="Button" control="Button"/>
-
- <composite x:id="List">
- <layoutData x:class="gridData" grabExcessHorizontalSpace="true" horizontalAlignment="GridData.FILL"/>
- <layout x:class="gridLayout" numColumns="1"/>
-
- <composite>
- <layoutData x:class="gridData" grabExcessHorizontalSpace="true" horizontalAlignment="GridData.FILL" grabExcessVerticalSpace="true" verticalAlignment="GridData.FILL"/>
- <layout x:class="fillLayout" type="VERTICAL"/>
-
- <list x:style="BORDER | V_SCROLL | MULTI"/>
- <list x:style="BORDER | V_SCROLL"/>
- </composite>
- </composite>
- <tabItem text="List" control="List"/>
-
- <composite x:id="Combos">
- <layoutData x:class="gridData" grabExcessHorizontalSpace="true" horizontalAlignment="GridData.FILL"/>
- <layout x:class="gridLayout" numColumns="2"/>
-
- <composite x:style="BORDER">
- <layoutData x:class="gridData" grabExcessHorizontalSpace="true" verticalAlignment="GridData.FILL" horizontalAlignment="GridData.FILL"/>
- <layout x:class="gridLayout" numColumns="1"/>
-
- <combo>
- <add x:p0="item1"/>
- <add x:p0="item2"/>
- <add x:p0="item3"/>
- </combo>
- <combo x:style="SIMPLE">
- <add x:p0="item1"/>
- <add x:p0="item2"/>
- <add x:p0="item3"/>
- </combo>
- <combo x:style="READ_ONLY">
- <add x:p0="item1"/>
- <add x:p0="item2"/>
- <add x:p0="item3"/>
- </combo>
- <label x:style="SEPARATOR | HORIZONTAL"><layoutData x:class="gridData" grabExcessHorizontalSpace="true" horizontalAlignment="GridData.FILL"/></label>
- <cCombo>
- <add x:p0="item1"/>
- <add x:p0="item2"/>
- <add x:p0="item3"/>
- </cCombo>
- <cCombo x:style="READ_ONLY" background="255 255 255">
- <add x:p0="item1"/>
- <add x:p0="item2"/>
- <add x:p0="item3"/>
- </cCombo>
- </composite>
- <slider x:style="VERTICAL" x:id="2buttonScroller">
- <layoutData x:class="gridData" verticalAlignment="GridData.FILL"/>
- </slider>
- </composite>
- <tabItem text="Combo / CCombo" control="Combos"/>
-
- <composite x:id="Table">
- <layoutData x:class="gridData" grabExcessHorizontalSpace="true" horizontalAlignment="GridData.FILL"/>
- <layout x:class="gridLayout" numColumns="1"/>
-
- <composite x:style="BORDER">
- <layoutData x:class="gridData" grabExcessHorizontalSpace="true" grabExcessVerticalSpace="true" horizontalAlignment="GridData.FILL" verticalAlignment="GridData.FILL"/>
- <layout x:class="gridLayout" numColumns="2"/>
-
- <table x:style="BORDER" linesVisible="true" headerVisible="true">
- <layoutData x:class="gridData" grabExcessHorizontalSpace="true" grabExcessVerticalSpace="true" horizontalAlignment="GridData.FILL" verticalAlignment="GridData.FILL"/>
-
- <tableColumn width="50" text="Done"/>
- <tableColumn width="200" text="Description"/>
- <tableColumn width="60" text="Planned"/>
- <tableColumn width="60" text="Revised"/>
- <tableColumn width="60" text="Actual"/>
- <!--<tableItem/>-->
- </table>
- </composite>
- </composite>
- <tabItem text="Table" control="Table"/>
-
- <composite x:id="Tree">
- <layoutData x:class="gridData" grabExcessHorizontalSpace="true" horizontalAlignment="GridData.FILL"/>
- <layout x:class="gridLayout" numColumns="1"/>
-
- <composite x:style="BORDER">
- <layoutData x:class="gridData" grabExcessHorizontalSpace="true" grabExcessVerticalSpace="true" horizontalAlignment="GridData.FILL" verticalAlignment="GridData.FILL"/>
- <layout x:class="gridLayout" numColumns="2"/>
-
- <tree x:style="BORDER">
- <layoutData x:class="gridData" grabExcessHorizontalSpace="true" grabExcessVerticalSpace="true" horizontalAlignment="GridData.FILL" verticalAlignment="GridData.FILL"/>
-
- <treeItem text="item">
- <x:children>
- <treeItem text="item"/>
- <treeItem text="item"/>
- <treeItem text="item">
- <x:children>
- <treeItem text="item"/>
- <treeItem text="item"/>
- <treeItem text="item"/>
- <treeItem text="item"/>
- <treeItem text="item"/>
- </x:children>
- </treeItem>
- <treeItem text="item"/>
- </x:children>
- </treeItem>
- <treeItem text="item with Image (or at least needs one)">
- <x:children>
- <treeItem text="item"/>
- <treeItem text="item"/>
- </x:children>
- </treeItem>
- <treeItem text="Another item">
- <x:children>
- <treeItem text="item"/>
- <treeItem text="item"/>
- <treeItem text="item"/>
- <treeItem text="item"/>
- <treeItem text="item"/>
- </x:children>
- </treeItem>
- </tree>
- </composite>
- </composite>
- <tabItem text="Tree" control="Tree"/>
-
- <composite x:id="TableTree">
- <layoutData x:class="gridData" grabExcessHorizontalSpace="true" horizontalAlignment="GridData.FILL"/>
- <layout x:class="gridLayout" numColumns="1"/>
-
- <composite x:style="BORDER">
- <layoutData x:class="gridData" grabExcessHorizontalSpace="true" grabExcessVerticalSpace="true" horizontalAlignment="GridData.FILL" verticalAlignment="GridData.FILL"/>
- <layout x:class="gridLayout" numColumns="2"/>
-
- <tableTree x:style="BORDER">
- <layoutData x:class="gridData" grabExcessHorizontalSpace="true" grabExcessVerticalSpace="true" horizontalAlignment="GridData.FILL" verticalAlignment="GridData.FILL"/>
-
- <tableTreeItem text="item">
- <x:children>
- <tableTreeItem text="subitem"/>
- <tableTreeItem text="subitem"/>
- </x:children>
- </tableTreeItem>
- <tableTreeItem text="item">
- <x:children>
- <tableTreeItem text="subitem"/>
- <tableTreeItem text="subitem"/>
- <tableTreeItem text="subitem"/>
- <tableTreeItem text="subitem"/>
- <tableTreeItem text="subitem"/>
- </x:children>
- </tableTreeItem>
- <tableTreeItem text="item">
- <x:children>
- <tableTreeItem text="item">
- <x:children>
- <tableTreeItem text="subitem"/>
- </x:children>
- </tableTreeItem>
- <tableTreeItem text="item">
- <x:children>
- <tableTreeItem text="subitem"/>
- <tableTreeItem text="subitem"/>
- <tableTreeItem text="subitem"/>
- <tableTreeItem text="subitem"/>
- <tableTreeItem text="subitem"/>
- </x:children>
- </tableTreeItem>
- <tableTreeItem text="item">
- <x:children>
- <tableTreeItem text="subitem"/>
- <tableTreeItem text="subitem"/>
- <tableTreeItem text="subitem"/>
- </x:children>
- </tableTreeItem>
- </x:children>
- </tableTreeItem>
- </tableTree>
- </composite>
- </composite>
- <tabItem text="TableTree" control="TableTree"/>
-
- <composite x:id="Progress">
- <layoutData x:class="gridData" grabExcessHorizontalSpace="true" horizontalAlignment="GridData.FILL"/>
- <layout x:class="gridLayout" numColumns="2"/>
-
- <composite x:style="BORDER">
- <layoutData x:class="gridData" grabExcessHorizontalSpace="true" verticalAlignment="GridData.FILL" horizontalAlignment="GridData.FILL"/>
- <layout x:class="gridLayout" numColumns="1"/>
-
- <progressBar x:style="INDETERMINATE"/>
- <progressBar x:style="INDETERMINATE | SMOOTH"/>
- <progressBar x:style="SMOOTH" minimum="0" maximum="100" selection="40"/>
- <progressBar minimum="0" maximum="100" selection="60"/>
- </composite>
- <slider x:style="VERTICAL" x:id="3textScroller"/>
- </composite>
- <tabItem text="ProgressBar" control="Progress"/>
-
- </tabFolder>
-</xswt>
-
diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/swt/SWTObservablesTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/swt/SWTObservablesTest.java deleted file mode 100644 index eab532fb..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/swt/SWTObservablesTest.java +++ /dev/null @@ -1,335 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - ******************************************************************************/ - -package org.eclipse.jface.tests.databinding.swt; - -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.jface.databinding.conformance.util.RealmTester; -import org.eclipse.jface.databinding.swt.ISWTObservableValue; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.internal.databinding.swt.ButtonObservableValue; -import org.eclipse.jface.internal.databinding.swt.CComboObservableList; -import org.eclipse.jface.internal.databinding.swt.CComboObservableValue; -import org.eclipse.jface.internal.databinding.swt.CLabelObservableValue; -import org.eclipse.jface.internal.databinding.swt.ComboObservableList; -import org.eclipse.jface.internal.databinding.swt.ComboObservableValue; -import org.eclipse.jface.internal.databinding.swt.LabelObservableValue; -import org.eclipse.jface.internal.databinding.swt.ListObservableList; -import org.eclipse.jface.internal.databinding.swt.ListObservableValue; -import org.eclipse.jface.internal.databinding.swt.SWTProperties; -import org.eclipse.jface.internal.databinding.swt.ScaleObservableValue; -import org.eclipse.jface.internal.databinding.swt.SpinnerObservableValue; -import org.eclipse.jface.internal.databinding.swt.TableSingleSelectionObservableValue; -import org.eclipse.jface.internal.databinding.swt.TextEditableObservableValue; -import org.eclipse.jface.internal.databinding.swt.TextObservableValue; -import org.eclipse.jface.tests.databinding.AbstractSWTTestCase; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.custom.CLabel; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.List; -import org.eclipse.swt.widgets.Scale; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Spinner; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.Text; -import org.eclipse.swt.widgets.Tree; - -/** - * @since 1.1 - */ -public class SWTObservablesTest extends AbstractSWTTestCase { - private Shell shell; - - protected void setUp() throws Exception { - super.setUp(); - - shell = getShell(); - RealmTester.setDefault(SWTObservables.getRealm(shell.getDisplay())); - } - - protected void tearDown() throws Exception { - super.tearDown(); - - RealmTester.setDefault(null); - } - - public void testObserveForeground() throws Exception { - ISWTObservableValue value = SWTObservables.observeForeground(shell); - assertNotNull(value); - assertEquals(Color.class, value.getValueType()); - } - - public void testObserveBackground() throws Exception { - ISWTObservableValue value = SWTObservables.observeBackground(shell); - assertNotNull(value); - assertEquals(Color.class, value.getValueType()); - } - - public void testObserveFont() throws Exception { - ISWTObservableValue value = SWTObservables.observeFont(shell); - assertNotNull(value); - assertEquals(Font.class, value.getValueType()); - } - - public void testObserveSelectionOfSpinner() throws Exception { - Spinner spinner = new Spinner(shell, SWT.NONE); - ISWTObservableValue value = SWTObservables.observeSelection(spinner); - assertNotNull(value); - assertTrue(value instanceof SpinnerObservableValue); - - SpinnerObservableValue spinnerObservable = (SpinnerObservableValue) value; - assertEquals(SWTProperties.SELECTION, spinnerObservable.getAttribute()); - } - - public void testObserveSelectionOfButton() throws Exception { - Button button = new Button(shell, SWT.PUSH); - ISWTObservableValue value = SWTObservables.observeSelection(button); - assertNotNull(value); - assertTrue(value instanceof ButtonObservableValue); - } - - public void testObserveSelectionOfCombo() throws Exception { - Combo combo = new Combo(shell, SWT.NONE); - ISWTObservableValue value = SWTObservables.observeSelection(combo); - assertNotNull(value); - assertTrue(value instanceof ComboObservableValue); - - ComboObservableValue comboObservable = (ComboObservableValue) value; - assertEquals(SWTProperties.SELECTION, comboObservable.getAttribute()); - } - - public void testObserveSelectionOfCCombo() throws Exception { - CCombo combo = new CCombo(shell, SWT.NONE); - ISWTObservableValue value = SWTObservables.observeSelection(combo); - assertNotNull(value); - assertTrue(value instanceof CComboObservableValue); - - CComboObservableValue ccomboObservable = (CComboObservableValue) value; - assertEquals(SWTProperties.SELECTION, ccomboObservable.getAttribute()); - } - - public void testObserveSelectionOfList() throws Exception { - List list = new List(shell, SWT.NONE); - ISWTObservableValue value = SWTObservables.observeSelection(list); - assertNotNull(value); - assertTrue(value instanceof ListObservableValue); - } - - public void testObserveSelectionOfScale() throws Exception { - Scale scale = new Scale(shell, SWT.NONE); - ISWTObservableValue value = SWTObservables.observeSelection(scale); - assertNotNull(value); - assertTrue(value instanceof ScaleObservableValue); - - ScaleObservableValue scaleObservable = (ScaleObservableValue) value; - assertEquals(SWTProperties.SELECTION, scaleObservable.getAttribute()); - } - - public void testObserveSelectionOfUnsupportedControl() throws Exception { - try { - Text text = new Text(shell, SWT.NONE); - SWTObservables.observeSelection(text); - fail("Exception should have been thrown"); - } catch (IllegalArgumentException e) { - } - } - - public void testObserveTextOfText() throws Exception { - Text text = new Text(shell, SWT.NONE); - assertFalse(text.isListening(SWT.FocusOut)); - - ISWTObservableValue value = SWTObservables.observeText(text, - SWT.FocusOut); - assertNotNull(value); - assertTrue(value instanceof TextObservableValue); - assertTrue(text.isListening(SWT.FocusOut)); - } - - public void testObserveTextWithEventOfUnsupportedControl() throws Exception { - Label label = new Label(shell, SWT.NONE); - try { - SWTObservables.observeText(label, SWT.FocusOut); - fail("Exception should have been thrown"); - } catch (Exception e) { - } - } - - public void testObserveTextOfLabel() throws Exception { - Label label = new Label(shell, SWT.NONE); - ISWTObservableValue value = SWTObservables.observeText(label); - assertNotNull(label); - assertTrue(value instanceof LabelObservableValue); - } - - public void testObserveTextOfCLabel() throws Exception { - CLabel label = new CLabel(shell, SWT.NONE); - ISWTObservableValue value = SWTObservables.observeText(label); - assertNotNull(label); - assertTrue(value instanceof CLabelObservableValue); - } - - public void testObserveTextOfCombo() throws Exception { - Combo combo = new Combo(shell, SWT.NONE); - ISWTObservableValue value = SWTObservables.observeText(combo); - assertNotNull(value); - assertTrue(value instanceof ComboObservableValue); - - ComboObservableValue comboObservable = (ComboObservableValue) value; - assertEquals(SWTProperties.TEXT, comboObservable.getAttribute()); - } - - public void testObserveTextOfCCombo() throws Exception { - CCombo combo = new CCombo(shell, SWT.NONE); - ISWTObservableValue value = SWTObservables.observeText(combo); - assertNotNull(value); - assertTrue(value instanceof CComboObservableValue); - - CComboObservableValue ccomboObservable = (CComboObservableValue) value; - assertEquals(SWTProperties.TEXT, ccomboObservable.getAttribute()); - } - - public void testObserveTextOfUnsupportedControl() throws Exception { - Table table = new Table(shell, SWT.NONE); - try { - SWTObservables.observeText(table); - fail("Exception should have been thrown"); - } catch (IllegalArgumentException e) { - } - } - - public void testObserveItemsOfCombo() throws Exception { - Combo combo = new Combo(shell, SWT.NONE); - IObservableList list = SWTObservables.observeItems(combo); - assertNotNull(list); - assertTrue(list instanceof ComboObservableList); - } - - public void testObserveItemsOfCCombo() throws Exception { - CCombo ccombo = new CCombo(shell, SWT.NONE); - IObservableList list = SWTObservables.observeItems(ccombo); - assertNotNull(list); - assertTrue(list instanceof CComboObservableList); - } - - public void testObserveItemsOfList() throws Exception { - List list = new List(shell, SWT.NONE); - IObservableList observableList = SWTObservables.observeItems(list); - assertNotNull(observableList); - assertTrue(observableList instanceof ListObservableList); - } - - public void testObserveItemsOfUnsupportedControl() throws Exception { - Table table = new Table(shell, SWT.NONE); - try { - SWTObservables.observeItems(table); - fail("Exception should have been thrown"); - } catch (IllegalArgumentException e) { - } - } - - public void testObserveSingleSelectionIndexOfTable() throws Exception { - Table table = new Table(shell, SWT.NONE); - ISWTObservableValue value = SWTObservables - .observeSingleSelectionIndex(table); - assertNotNull(value); - assertTrue(value instanceof TableSingleSelectionObservableValue); - } - - public void testObserveSingleSelectionIndexOfUnsupportedControl() - throws Exception { - Tree tree = new Tree(shell, SWT.NONE); - try { - SWTObservables.observeSingleSelectionIndex(tree); - fail("Exception should have been thrown"); - } catch (IllegalArgumentException e) { - - } - } - - public void testObserveMinOfSpinner() throws Exception { - Spinner spinner = new Spinner(shell, SWT.NONE); - ISWTObservableValue value = SWTObservables.observeMin(spinner); - assertNotNull(value); - assertTrue(value instanceof SpinnerObservableValue); - - SpinnerObservableValue spinnerObservable = (SpinnerObservableValue) value; - assertEquals(SWTProperties.MIN, spinnerObservable.getAttribute()); - } - - public void testObserveMinOfScale() throws Exception { - Scale scale = new Scale(shell, SWT.NONE); - ISWTObservableValue value = SWTObservables.observeMin(scale); - assertNotNull(value); - assertTrue(value instanceof ScaleObservableValue); - - ScaleObservableValue scaleObservable = (ScaleObservableValue) value; - assertEquals(SWTProperties.MIN, scaleObservable.getAttribute()); - } - - public void testObserveMinOfUnsupportedControl() throws Exception { - Text text = new Text(shell, SWT.NONE); - try { - SWTObservables.observeMin(text); - fail("Exception should have been thrown"); - } catch (IllegalArgumentException e) { - } - } - - public void testObserveMaxOfSpinner() throws Exception { - Spinner spinner = new Spinner(shell, SWT.NONE); - ISWTObservableValue value = SWTObservables.observeMax(spinner); - assertNotNull(value); - assertTrue(value instanceof SpinnerObservableValue); - - SpinnerObservableValue spinnerObservable = (SpinnerObservableValue) value; - assertEquals(SWTProperties.MAX, spinnerObservable.getAttribute()); - } - - public void testObserveMaxOfScale() throws Exception { - Scale scale = new Scale(shell, SWT.NONE); - ISWTObservableValue value = SWTObservables.observeMax(scale); - assertNotNull(value); - assertTrue(value instanceof ScaleObservableValue); - - ScaleObservableValue scaleObservable = (ScaleObservableValue) value; - assertEquals(SWTProperties.MAX, scaleObservable.getAttribute()); - } - - public void testObserveMaxOfUnsupportedControl() throws Exception { - Text text = new Text(shell, SWT.NONE); - try { - SWTObservables.observeMax(text); - fail("Exception should have been thrown"); - } catch (IllegalArgumentException e) { - } - } - - public void testObserveEditableOfText() throws Exception { - Text text = new Text(shell, SWT.NONE); - ISWTObservableValue value = SWTObservables.observeEditable(text); - assertNotNull(value); - assertTrue(value instanceof TextEditableObservableValue); - } - - public void testObserveEditableOfUnsupportedControl() throws Exception { - Label label = new Label(shell, SWT.NONE); - try { - SWTObservables.observeEditable(label); - fail("Exception should have been thrown"); - } catch (IllegalArgumentException e) { - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/viewers/ObservableListContentProviderTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/viewers/ObservableListContentProviderTest.java deleted file mode 100644 index 9154e716..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/viewers/ObservableListContentProviderTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 215531) - ******************************************************************************/ -package org.eclipse.jface.tests.databinding.viewers; - -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Shell; - -public class ObservableListContentProviderTest extends - AbstractDefaultRealmTestCase { - private Shell shell; - private TableViewer viewer; - private ObservableListContentProvider contentProvider; - private IObservableList input; - - protected void setUp() throws Exception { - super.setUp(); - shell = new Shell(); - viewer = new TableViewer(shell, SWT.NONE); - - contentProvider = new ObservableListContentProvider(); - viewer.setContentProvider(contentProvider); - - input = new WritableList(); - viewer.setInput(input); - } - - protected void tearDown() throws Exception { - shell.dispose(); - viewer = null; - input = null; - super.tearDown(); - } - - public void testViewerUpdate_RemoveElementAfterMutation() { - Mutable element = new Mutable(1); - input.add(element); - - assertEquals(1, viewer.getTable().getItemCount()); - - element.id++; - input.remove(element); - - assertEquals(0, viewer.getTable().getItemCount()); - } - - static class Mutable { - public int id; - - public Mutable(int id) { - this.id = id; - } - - public boolean equals(Object obj) { - if (obj == this) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Mutable that = (Mutable) obj; - return this.id == that.id; - } - - public int hashCode() { - return id; - } - } -}
\ No newline at end of file diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/viewers/ObservableListTreeContentProviderTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/viewers/ObservableListTreeContentProviderTest.java deleted file mode 100644 index 3d2bb244..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/viewers/ObservableListTreeContentProviderTest.java +++ /dev/null @@ -1,138 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007-2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 207858) - *******************************************************************************/ - -package org.eclipse.jface.tests.databinding.viewers; - -import java.util.Arrays; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.runtime.AssertionFailedException; -import org.eclipse.jface.databinding.viewers.ObservableListTreeContentProvider; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Tree; - -public class ObservableListTreeContentProviderTest extends - AbstractDefaultRealmTestCase { - private Shell shell; - private TreeViewer viewer; - private Tree tree; - private ObservableListTreeContentProvider contentProvider; - private Object input; - - protected void setUp() throws Exception { - super.setUp(); - shell = new Shell(); - tree = new Tree(shell, SWT.NONE); - viewer = new TreeViewer(tree); - input = new Object(); - } - - protected void tearDown() throws Exception { - shell.dispose(); - tree = null; - viewer = null; - input = null; - super.tearDown(); - } - - private void initContentProvider(IObservableFactory listFactory) { - contentProvider = new ObservableListTreeContentProvider(listFactory, null); - viewer.setContentProvider(contentProvider); - viewer.setInput(input); - } - - public void testConstructor_NullArgumentThrowsException() { - try { - initContentProvider(null); - fail("Constructor should have thrown AssertionFailedException"); - } catch (AssertionFailedException expected) { - } - } - - public void testGetElements_ChangesFollowObservedList() { - final IObservableList elements = new WritableList(); - final Object input = new Object(); - initContentProvider(new IObservableFactory() { - public IObservable createObservable(Object target) { - return target == input ? elements : null; - } - }); - - assertTrue(Arrays.equals(new Object[0], contentProvider - .getElements("unknown input"))); - - Object element0 = new Object(); - elements.add(element0); - - assertTrue(Arrays.equals(new Object[] { element0 }, contentProvider - .getElements(input))); - - Object element1 = new Object(); - elements.add(element1); - - assertTrue(Arrays.equals(new Object[] { element0, element1 }, - contentProvider.getElements(input))); - } - - public void testViewerUpdate_RemoveElementAfterMutation() { - final IObservableList children = new WritableList(); - initContentProvider(new IObservableFactory() { - public IObservable createObservable(Object target) { - return target == input ? children : null; - } - }); - - Mutable element = new Mutable(); - children.add(element); - assertEquals(1, tree.getItemCount()); - - element.mutate(); - children.remove(element); - assertEquals(0, tree.getItemCount()); - } - - static class Mutable { - private int id; - - public Mutable() { - this(0); - } - - public Mutable(int id) { - this.id = id; - } - - public void mutate() { - id++; - } - - public boolean equals(Object obj) { - if (obj == this) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Mutable that = (Mutable) obj; - return this.id == that.id; - } - - public int hashCode() { - return id; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/viewers/ObservableMapLabelProviderTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/viewers/ObservableMapLabelProviderTest.java deleted file mode 100644 index cffed54f..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/viewers/ObservableMapLabelProviderTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Brad Reynolds - bug 164247 - ******************************************************************************/ - -package org.eclipse.jface.tests.databinding.viewers; - -import java.util.HashSet; - -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.set.WritableSet; -import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; -import org.eclipse.jface.examples.databinding.ModelObject; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -/** - * @since 1.1 - */ -public class ObservableMapLabelProviderTest extends AbstractDefaultRealmTestCase { - - public void testGetColumnText() throws Exception { - WritableSet set = new WritableSet(new HashSet(), Item.class); - Item item = new Item(); - String value = "value"; - item.setValue(value); - set.add(item); - - ObservableMapLabelProvider labelProvider = new ObservableMapLabelProvider(BeansObservables.observeMap(set, Item.class, "value")); - assertEquals(item.getValue(), labelProvider.getColumnText(item, 0)); - } - - public void testGetColumnTextNullValue() throws Exception { - WritableSet set = new WritableSet(new HashSet(), Item.class); - Item item = new Item(); - set.add(item); - - ObservableMapLabelProvider labelProvider = new ObservableMapLabelProvider(BeansObservables.observeMap(set, Item.class, "value")); - assertNull(item.getValue()); - assertEquals("", labelProvider.getColumnText(item, 0)); - } - - private static class Item extends ModelObject { - private String value; - - public String getValue() { - return value; - } - - public void setValue(String value) { - String old = this.value; - - firePropertyChange("value", old, this.value = value); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/viewers/ObservableSetContentProviderTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/viewers/ObservableSetContentProviderTest.java deleted file mode 100644 index 2d02ff5e..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/viewers/ObservableSetContentProviderTest.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Boris Bokowski, IBM - bug 209484 - ******************************************************************************/ - -package org.eclipse.jface.tests.databinding.viewers; - -import java.util.Arrays; - -import org.eclipse.core.databinding.observable.set.WritableSet; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.databinding.viewers.ObservableSetContentProvider; -import org.eclipse.jface.tests.databinding.AbstractSWTTestCase; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.swt.widgets.Display; - -/** - * @since 3.3 - * - */ -public class ObservableSetContentProviderTest extends AbstractSWTTestCase { - public void testKnownElementsRealm() throws Exception { - ObservableSetContentProvider contentProvider = new ObservableSetContentProvider(); - assertSame("realm for the known elements should be the SWT realm", - SWTObservables.getRealm(Display.getDefault()), contentProvider - .getKnownElements().getRealm()); - } - - public void testKnownElementsAfterSetInput() { - ObservableSetContentProvider contentProvider = new ObservableSetContentProvider(); - TableViewer tableViewer = new TableViewer(getShell()); - tableViewer.setContentProvider(contentProvider); - assertEquals(0, contentProvider.getKnownElements().size()); - WritableSet input = new WritableSet(Arrays.asList(new String[] {"one","two","three"}), String.class); - tableViewer.setInput(input); - assertEquals(3, contentProvider.getKnownElements().size()); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/viewers/ObservableSetTreeContentProviderTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/viewers/ObservableSetTreeContentProviderTest.java deleted file mode 100644 index 1d5fc470..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/viewers/ObservableSetTreeContentProviderTest.java +++ /dev/null @@ -1,156 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007-2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 207858) - *******************************************************************************/ - -package org.eclipse.jface.tests.databinding.viewers; - -import java.util.Arrays; -import java.util.List; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.WritableSet; -import org.eclipse.core.runtime.AssertionFailedException; -import org.eclipse.jface.databinding.viewers.ObservableSetTreeContentProvider; -import org.eclipse.jface.internal.databinding.viewers.ObservableViewerElementSet; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.eclipse.jface.viewers.IElementComparer; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Tree; - -public class ObservableSetTreeContentProviderTest extends - AbstractDefaultRealmTestCase { - private Shell shell; - private TreeViewer viewer; - private Tree tree; - private ObservableSetTreeContentProvider contentProvider; - private Object input; - - protected void setUp() throws Exception { - super.setUp(); - shell = new Shell(); - tree = new Tree(shell, SWT.NONE); - viewer = new TreeViewer(tree); - input = new Object(); - } - - protected void tearDown() throws Exception { - shell.dispose(); - tree = null; - viewer = null; - input = null; - super.tearDown(); - } - - private void initContentProvider(IObservableFactory listFactory) { - contentProvider = new ObservableSetTreeContentProvider(listFactory, null); - viewer.setContentProvider(contentProvider); - viewer.setInput(input); - } - - public void testConstructor_NullArgumentThrowsException() { - try { - initContentProvider(null); - fail("Constructor should have thrown AssertionFailedException"); - } catch (AssertionFailedException expected) { - } - } - - public void testGetElements_ChangesFollowObservedList() { - final IObservableSet elements = new WritableSet(); - final Object input = new Object(); - initContentProvider(new IObservableFactory() { - public IObservable createObservable(Object target) { - return target == input ? elements : null; - } - }); - - assertTrue(Arrays.equals(new Object[0], contentProvider - .getElements("unknown input"))); - - Object element0 = new Object(); - elements.add(element0); - - assertTrue(Arrays.equals(new Object[] { element0 }, contentProvider - .getElements(input))); - - Object element1 = new Object(); - elements.add(element1); - - List elementList = Arrays.asList(contentProvider.getElements(input)); - assertEquals(2, elementList.size()); - assertTrue(elementList.containsAll(Arrays.asList(new Object[] { - element0, element1 }))); - } - - public void testViewerUpdate_RemoveElementAfterMutation() { - IElementComparer comparer = new IElementComparer() { - public boolean equals(Object a, Object b) { - return a == b; - } - - public int hashCode(Object element) { - return System.identityHashCode(element); - } - }; - viewer.setComparer(comparer); - - final IObservableSet children = ObservableViewerElementSet - .withComparer(Realm.getDefault(), null, comparer); - initContentProvider(new IObservableFactory() { - public IObservable createObservable(Object target) { - return target == input ? children : null; - } - }); - - Mutable element = new Mutable(); - children.add(element); - assertEquals(1, tree.getItemCount()); - - element.mutate(); - assertTrue(children.remove(element)); - assertEquals(0, tree.getItemCount()); - } - - static class Mutable { - private int id; - - public Mutable() { - this(0); - } - - public Mutable(int id) { - this.id = id; - } - - public void mutate() { - id++; - } - - public boolean equals(Object obj) { - if (obj == this) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Mutable that = (Mutable) obj; - return this.id == that.id; - } - - public int hashCode() { - return id; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/viewers/ObservableValueEditingSupportTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/viewers/ObservableValueEditingSupportTest.java deleted file mode 100644 index a0f2856e..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/viewers/ObservableValueEditingSupportTest.java +++ /dev/null @@ -1,302 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.tests.databinding.viewers; - -import org.eclipse.core.databinding.Binding; -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.IChangeListener; -import org.eclipse.core.databinding.observable.IStaleListener; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.tests.internal.databinding.beans.Bean; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; -import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; -import org.eclipse.jface.databinding.viewers.ObservableValueEditingSupport; -import org.eclipse.jface.tests.databinding.AbstractSWTTestCase; -import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.ColumnViewer; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.TableViewerColumn; -import org.eclipse.jface.viewers.TextCellEditor; -import org.eclipse.jface.viewers.ViewerCell; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -public class ObservableValueEditingSupportTest extends AbstractSWTTestCase { - private Shell shell; - - private ObservableValueEditingSupportStub editingSupport; - - private DataBindingContext dbc; - - private TableViewer viewer; - - private Bean bean; - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.tests.databinding.AbstractSWTTestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - - shell = getShell(); - dbc = new DataBindingContext(); - - viewer = new TableViewer(shell); - TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE); - - // Create a standard content provider - ObservableListContentProvider peopleViewerContentProvider = new ObservableListContentProvider(); - viewer.setContentProvider(peopleViewerContentProvider); - - // And a standard label provider that maps columns - IObservableMap[] attributeMaps = BeansObservables.observeMaps( - peopleViewerContentProvider.getKnownElements(), Bean.class, - new String[] { "value" }); - viewer.setLabelProvider(new ObservableMapLabelProvider(attributeMaps)); - - editingSupport = new ObservableValueEditingSupportStub(viewer, dbc); - column.setEditingSupport(editingSupport); - - WritableList input = WritableList.withElementType(String.class); - bean = new Bean(); - bean.setValue("value"); - input.add(bean); - viewer.setInput(input); - } - - public void testInitializeCellEditorValue_OrderOfOperations() - throws Exception { - assertEquals("precondition", 0, editingSupport.events.length()); - - viewer.editElement(bean, 0); - assertEquals( - "createCellEditorObservable createElementObservable createBinding", - editingSupport.events.toString()); - } - - public void testSaveCellEditorValue_UpdatesModel() throws Exception { - Text text = new Text(shell, SWT.NONE); - shell.open(); - - String newValue = bean.getValue() + "a"; - - viewer.editElement(bean, 0); - editingSupport.editor.setValue(newValue); - - // force the focus to leave the editor updating the value - text.setFocus(); - - assertEquals(newValue, bean.getValue()); - } - - public void testDisposesBinding() throws Exception { - Text text = new Text(shell, SWT.NONE); - shell.open(); - - viewer.editElement(bean, 0); - assertFalse("precondition", editingSupport.binding.isDisposed()); - - text.setFocus(); - assertTrue(editingSupport.binding.isDisposed()); - } - - public void testDisposesTargetObservable() throws Exception { - Text text = new Text(shell, SWT.NONE); - shell.open(); - - viewer.editElement(bean, 0); - assertEquals("precondition", 0, editingSupport.target.disposed); - - text.setFocus(); - assertEquals(1, editingSupport.target.disposed); - } - - public void testDisposesModelObservable() throws Exception { - Text text = new Text(shell, SWT.NONE); - shell.open(); - - viewer.editElement(bean, 0); - assertEquals("precondition", 0, editingSupport.model.disposed); - - text.setFocus(); - assertEquals(1, editingSupport.model.disposed); - } - - public void testCanEdit_DefaultIsTrue() throws Exception { - assertTrue(editingSupport.canEdit(bean)); - } - - private static class ObservableValueEditingSupportStub extends - ObservableValueEditingSupport { - StringBuffer events = new StringBuffer(); - - TextCellEditor editor; - - Binding binding; - - ObservableValueDecorator target; - - ObservableValueDecorator model; - - /** - * @param viewer - * @param dbc - */ - public ObservableValueEditingSupportStub(ColumnViewer viewer, - DataBindingContext dbc) { - super(viewer, dbc); - editor = new TextCellEditor((Composite) viewer.getControl()); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.databinding.viewers.ObservableValueEditingSupport#canEdit(java.lang.Object) - */ - protected boolean canEdit(Object element) { - return super.canEdit(element); - } - - public CellEditor getCellEditor() { - return editor; - } - - private void event(String event) { - if (events.length() > 0) { - events.append(" "); - } - - events.append(event); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.databinding.viewers.ObservableValueEditingSupport#createCellEditorObservable(org.eclipse.jface.viewers.CellEditor) - */ - protected IObservableValue doCreateCellEditorObservable( - CellEditor cellEditor) { - event("createCellEditorObservable"); - - return target = new ObservableValueDecorator(SWTObservables - .observeText(cellEditor.getControl(), SWT.NONE)); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.databinding.viewers.ObservableValueEditingSupport#createElementObservable(java.lang.Object, - * org.eclipse.jface.viewers.ViewerCell) - */ - protected IObservableValue doCreateElementObservable(Object element, - ViewerCell cell) { - event("createElementObservable"); - return model = new ObservableValueDecorator(BeansObservables - .observeValue(element, "value")); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.databinding.viewers.ObservableValueEditingSupport#createBinding(org.eclipse.core.databinding.observable.value.IObservableValue, - * org.eclipse.core.databinding.observable.value.IObservableValue) - */ - protected Binding createBinding(IObservableValue target, - IObservableValue model) { - event("createBinding"); - - return binding = super.createBinding(target, model); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.viewers.EditingSupport#getCellEditor(java.lang.Object) - */ - protected CellEditor getCellEditor(Object element) { - return editor; - } - } - - /** - * Decorator that will allow for tracking calls to dispose(). We really need - * an isDisposed() method on IObservable... - */ - private static class ObservableValueDecorator implements IObservableValue { - int disposed; - - IObservableValue delegate; - - ObservableValueDecorator(IObservableValue delegate) { - this.delegate = delegate; - } - - public synchronized void dispose() { - disposed++; - delegate.dispose(); - } - - public void addChangeListener(IChangeListener listener) { - delegate.addChangeListener(listener); - } - - public void addStaleListener(IStaleListener listener) { - delegate.addStaleListener(listener); - } - - public void addValueChangeListener(IValueChangeListener listener) { - delegate.addValueChangeListener(listener); - } - - public Realm getRealm() { - return delegate.getRealm(); - } - - public Object getValue() { - return delegate.getValue(); - } - - public Object getValueType() { - return delegate.getValueType(); - } - - public boolean isStale() { - return delegate.isStale(); - } - - public void removeChangeListener(IChangeListener listener) { - delegate.removeChangeListener(listener); - } - - public void removeStaleListener(IStaleListener listener) { - delegate.removeStaleListener(listener); - } - - public void removeValueChangeListener(IValueChangeListener listener) { - delegate.removeValueChangeListener(listener); - } - - public void setValue(Object value) { - delegate.setValue(value); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/viewers/ViewersObservablesTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/viewers/ViewersObservablesTest.java deleted file mode 100644 index 56d24ef3..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/viewers/ViewersObservablesTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 206839) - ******************************************************************************/ - -package org.eclipse.jface.tests.databinding.viewers; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.databinding.viewers.ViewersObservables; -import org.eclipse.jface.internal.databinding.viewers.ViewerInputObservableValue; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; - -/** - * Tests for ViewersObservables - * - * @since 1.2 - */ -public class ViewersObservablesTest extends AbstractDefaultRealmTestCase { - TableViewer viewer; - Realm realm; - - protected void setUp() throws Exception { - super.setUp(); - realm = SWTObservables.getRealm(Display.getCurrent()); - Shell shell = new Shell(); - viewer = new TableViewer(shell, SWT.NONE); - } - - protected void tearDown() throws Exception { - Shell shell = viewer.getTable().getShell(); - if (!shell.isDisposed()) - shell.dispose(); - shell = null; - realm = null; - super.tearDown(); - } - - public void testObserveInput_InstanceOfViewerInputObservableValue() { - IObservableValue observable = ViewersObservables.observeInput(viewer); - assertTrue(observable instanceof ViewerInputObservableValue); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/wizard/WizardPageSupportTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/wizard/WizardPageSupportTest.java deleted file mode 100644 index b83c232f..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/wizard/WizardPageSupportTest.java +++ /dev/null @@ -1,104 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Ovidio Mallo 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: - * Ovidio Mallo - initial API and implementation (bug 235195) - ******************************************************************************/ - -package org.eclipse.jface.tests.databinding.wizard; - -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.ValidationStatusProvider; -import org.eclipse.core.databinding.observable.Observables; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.databinding.validation.ValidationStatus; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jface.databinding.wizard.WizardPageSupport; -import org.eclipse.jface.tests.databinding.AbstractSWTTestCase; -import org.eclipse.jface.wizard.IWizardPage; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.widgets.Composite; - -/** - * @since 1.2 - */ -public class WizardPageSupportTest extends AbstractSWTTestCase { - - /** - * Bug 235195. - */ - public void testPageComplete() { - IWizardPage page = new WizardPage("Page") { - public void createControl(Composite parent) { - setControl(parent); - - IObservableValue validation = new WritableValue( - ValidationStatus.ok(), IStatus.class); - - DataBindingContext dbc = new DataBindingContext(); - ValidationProvider validationProvider = new ValidationProvider( - validation); - dbc.addValidationStatusProvider(validationProvider); - - WizardPageSupport.create(this, dbc); - - assertTrue(isPageComplete()); - - validation.setValue(ValidationStatus.info("INFO")); - assertTrue(isPageComplete()); - - validation.setValue(ValidationStatus.warning("WARNING")); - assertTrue(isPageComplete()); - - validation.setValue(ValidationStatus.error("ERROR")); - assertFalse(isPageComplete()); - - validation.setValue(ValidationStatus.cancel("CANCEL")); - assertFalse(isPageComplete()); - } - }; - - loadWizardPage(page); - } - - private void loadWizardPage(IWizardPage page) { - Wizard wizard = new Wizard() { - public boolean performFinish() { - return true; - } - }; - wizard.addPage(page); - - WizardDialog dialog = new WizardDialog(getShell(), wizard); - dialog.create(); - } - - private class ValidationProvider extends ValidationStatusProvider { - - private final IObservableValue validation; - - public ValidationProvider(IObservableValue validation) { - this.validation = validation; - } - - public IObservableValue getValidationStatus() { - return validation; - } - - public IObservableList getTargets() { - return Observables.emptyObservableList(); - } - - public IObservableList getModels() { - return Observables.emptyObservableList(); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/examples/databinding/mask/internal/EditMaskLexerAndTokenTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/examples/databinding/mask/internal/EditMaskLexerAndTokenTest.java deleted file mode 100755 index 040ae6c8..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/examples/databinding/mask/internal/EditMaskLexerAndTokenTest.java +++ /dev/null @@ -1,108 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.tests.examples.databinding.mask.internal; - -import junit.framework.TestCase; - -import org.eclipse.jface.examples.databinding.mask.internal.EditMaskLexerAndToken; - -public class EditMaskLexerAndTokenTest extends TestCase { - - private EditMaskLexerAndToken token; - - protected void setUp() throws Exception { - token = new EditMaskLexerAndToken(); - } - - public void testInitWithNumeric() throws Exception { - token.initializeEditMask("#", 0); - assertTrue("Should accept a digit", token.accept("0")); - token.clear(); - assertTrue("Should accept a digit", token.accept("1")); - token.clear(); - assertTrue("Should accept a digit", token.accept("2")); - token.clear(); - assertTrue("Should accept a digit", token.accept("3")); - token.clear(); - assertTrue("Should accept a digit", token.accept("4")); - token.clear(); - assertTrue("Should accept a digit", token.accept("5")); - token.clear(); - assertTrue("Should accept a digit", token.accept("6")); - token.clear(); - assertTrue("Should accept a digit", token.accept("7")); - token.clear(); - assertTrue("Should accept a digit", token.accept("8")); - token.clear(); - assertTrue("Should accept a digit", token.accept("9")); - token.clear(); - assertFalse("Should not accept an alpha", token.accept("A")); - token.clear(); - assertFalse("Should not accept an alpha", token.accept("z")); - assertFalse("Placeholders are not read-only", token.isReadOnly()); - } - - public void testInitWithLiteral() throws Exception { - token.initializeEditMask("(", 0); - assertEquals("Literals automatically set their input", "(", token.getInput()); - assertFalse("Literals don't accept anything", token.accept("(")); - assertTrue("literals are read-only", token.isReadOnly()); - assertTrue("Literals are complete", token.isComplete()); - assertFalse("Literals cannot accept characters", token.canAcceptMoreCharacters()); - } - - public void testInitWithBackslashLiteral() throws Exception { - token.initializeEditMask("\\#", 0); - assertEquals("Should get backslash literal", "#", token.getInput()); - } - - public void testAcceptWithValidInputAndEmpty() throws Exception { - token.initializeEditMask("#", 0); - assertTrue("Should accept a 0", token.accept("0")); - } - - public void testAcceptWhenParserCannotAcceptMoreCharacters() throws Exception { - token.initializeEditMask("#", 0); - assertTrue("Should accept a 0", token.accept("0")); - assertFalse("Should not accept a 0 -- input full", token.accept("0")); - } - - public void testGetInput() throws Exception { - token.initializeEditMask("#", 0); - assertTrue("Should accept a #", token.accept("0")); - assertEquals(token.getInput(), "0"); - } - - public void testClear_withNonLiteral() throws Exception { - token.initializeEditMask("#", 0); - assertTrue("Should accept a 0", token.accept("0")); - assertNotNull("Input should not be null", token.getInput()); - token.clear(); - assertNull("Input should be null after clear", token.getInput()); - } - - public void testClear_withLiteral() throws Exception { - token.initializeEditMask("(", 0); - assertNotNull("Input should not be null", token.getInput()); - token.clear(); - assertNotNull("Input should still not be null after clear of read-only literal", token.getInput()); - } - - public void testIsComplete_withNonLiteral() throws Exception { - token.initializeEditMask("#", 0); - assertFalse("should not be complete", token.isComplete()); - token.accept("1"); - assertTrue("should be complete", token.isComplete()); - token.clear(); - assertFalse("should not be complete", token.isComplete()); - } - -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/examples/databinding/mask/internal/EditMaskParserTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/examples/databinding/mask/internal/EditMaskParserTest.java deleted file mode 100755 index 8a2ceb45..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/examples/databinding/mask/internal/EditMaskParserTest.java +++ /dev/null @@ -1,105 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.tests.examples.databinding.mask.internal; - -import junit.framework.TestCase; - -import org.eclipse.jface.examples.databinding.mask.EditMaskParseException; -import org.eclipse.jface.examples.databinding.mask.internal.EditMaskParser; - -/** - * @since 3.2 - * - */ -public class EditMaskParserTest extends TestCase { - - private EditMaskParser parser; - - /* (non-Javadoc) - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - parser = new EditMaskParser("(###) ###-####"); - } - - /** - * Test method for {@link org.eclipse.jface.examples.databinding.mask.internal.EditMaskParser#EditMaskParser(java.lang.String)}. - */ - public void testEditMaskParser_validMask() { - new EditMaskParser("(###) ###-####"); - } - - /** - * Test method for {@link org.eclipse.jface.examples.databinding.mask.internal.EditMaskParser#EditMaskParser(java.lang.String)}. - */ - public void testEditMaskParser_invalidMask() { - try { - new EditMaskParser("(###) ###-####\\"); - fail("Should have thrown exception"); - } catch (EditMaskParseException e) { - // success - } - } - - /** - * Test method for {@link org.eclipse.jface.examples.databinding.mask.internal.EditMaskParser#setInput(java.lang.String)}. - */ - public void testSetInput() { - parser.setInput("63a0) 5*55-1\\212abc9"); - assertEquals("Unformatted input", "6305551212", parser.getRawResult()); - assertEquals("Formatted input", "(630) 555-1212", parser.getFormattedResult()); - } - - /** - * Test method for {@link org.eclipse.jface.examples.databinding.mask.internal.EditMaskParser#setInput(java.lang.String)}. - */ - public void testSetInput_incomplete() { - parser.setInput("6a0) 5*5-1\\12"); - assertEquals("Unformatted input", "6055112", parser.getRawResult()); - assertEquals("Formatted input", "(605) 511-2 ", parser.getFormattedResult()); - } - - /** - * Test method for {@link org.eclipse.jface.examples.databinding.mask.internal.EditMaskParser#isComplete()}. - */ - public void testIsComplete() { - parser.setInput("63a0) 5*55-1\\212"); - assertTrue("complete", parser.isComplete()); - parser.setInput("6a0) 5*5-1\\12"); - assertFalse("incomplete", parser.isComplete()); - } - - public void testSetPlaceholder() throws Exception { - parser.setInput("6a0) 5*5-1\\12"); - assertEquals("Formatted input", "(605) 511-2 ", parser.getFormattedResult()); - parser.setPlaceholder('_'); - assertEquals("Formatted input", "(605) 511-2___", parser.getFormattedResult()); - } - - /** - * Test method for {@link org.eclipse.jface.examples.databinding.mask.internal.EditMaskParser#getNextInputPosition(int)}. - */ - public void testGetNextInputPosition() { - assertEquals("Skip leading (", 1, parser.getNextInputPosition(0)); - assertEquals("Position 1 is good", 1, parser.getNextInputPosition(1)); - assertEquals("Skip )<space>", 6, parser.getNextInputPosition(4)); - } - - public void testGetFirstIncompleteInputPosition() throws Exception { - assertEquals("1st position incomplete", 1, parser.getFirstIncompleteInputPosition()); - parser.setInput("6a0) 5*5-1\\12"); - assertEquals("11th position incomplete", 11, parser.getFirstIncompleteInputPosition()); - parser.setInput("63a0) 5*55-1\\212"); - assertEquals("all complete", -1, parser.getFirstIncompleteInputPosition()); - } -} - diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/examples/model/PersonTests.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/examples/model/PersonTests.java deleted file mode 100644 index 1c9b9c1a..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/examples/model/PersonTests.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Brad Reynolds. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Brad Reynolds - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jface.tests.examples.model; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; - -import junit.framework.TestCase; - -import org.eclipse.jface.examples.databinding.model.SimplePerson; - -/** - * @since 3.2 - * - */ -public class PersonTests extends TestCase { - public void testSetName() { - SimplePerson person = new SimplePerson(); - Listener listener = new Listener(); - - person.addPropertyChangeListener(listener); - assertEquals(0, listener.count); - assertNull(listener.lastEvent); - person.setState("new state"); //$NON-NLS-1$ - - assertEquals(1, listener.count); - assertNotNull(listener.lastEvent); - assertEquals("state", listener.lastEvent.getPropertyName()); //$NON-NLS-1$ - assertEquals("", listener.lastEvent.getOldValue()); - assertEquals("new state", listener.lastEvent.getNewValue()); //$NON-NLS-1$ - assertEquals("new state", person.getState()); - } - - private class Listener implements PropertyChangeListener { - private int count; - private PropertyChangeEvent lastEvent; - - public void propertyChange(PropertyChangeEvent evt) { - count++; - this.lastEvent = evt; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ButtonObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ButtonObservableValueTest.java deleted file mode 100644 index 9b84d925..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ButtonObservableValueTest.java +++ /dev/null @@ -1,153 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Ashley Cambrell - bug 198904 - * Matthew Hall - bug 213145 - ******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest; -import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; -import org.eclipse.jface.internal.databinding.swt.ButtonObservableValue; -import org.eclipse.jface.tests.databinding.AbstractSWTTestCase; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Shell; - -/** - * @since 3.2 - */ -public class ButtonObservableValueTest extends AbstractSWTTestCase { - private Button button; - private ButtonObservableValue observableValue; - private ValueChangeEventTracker listener; - - /* (non-Javadoc) - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - - Shell shell = getShell(); - button = new Button(shell, SWT.CHECK); - observableValue = new ButtonObservableValue( - button); - listener = new ValueChangeEventTracker(); - } - - public void testSelection_ChangeNotifiesObservable() throws Exception { - observableValue.addValueChangeListener(listener); - button.setSelection(true); - - // precondition - assertEquals(0, listener.count); - button.notifyListeners(SWT.Selection, null); - - assertEquals("Selection event should notify observable.", 1, - listener.count); - } - - public void testSelection_NoChange() throws Exception { - button.setSelection(true); - button.notifyListeners(SWT.Selection, null); - observableValue.addValueChangeListener(listener); - - //precondition - assertEquals(0, listener.count); - - button.notifyListeners(SWT.Selection, null); - assertEquals("Value did not change. Listeners should not have been notified.", 0, listener.count); - } - - public void testSetValue_NullConvertedToFalse() { - button.setSelection(true); - assertEquals(Boolean.TRUE, observableValue.getValue()); - - observableValue.setValue(null); - assertEquals(Boolean.FALSE, observableValue.getValue()); - } - - public void testDispose() throws Exception { - ValueChangeEventTracker testCounterValueChangeListener = new ValueChangeEventTracker(); - observableValue.addValueChangeListener(testCounterValueChangeListener); - - assertEquals(Boolean.FALSE, observableValue.getValue()); - assertFalse(button.getSelection()); - - button.setSelection(true); - button.notifyListeners(SWT.Selection, null); - - assertEquals(1, testCounterValueChangeListener.count); - assertEquals(Boolean.TRUE, observableValue.getValue()); - assertTrue(button.getSelection()); - - observableValue.dispose(); - - button.setSelection(false); - button.notifyListeners(SWT.Selection, null); - - assertEquals(1, testCounterValueChangeListener.count); - } - - public static Test suite() { - TestSuite suite = new TestSuite(ButtonObservableValueTest.class.getName()); - suite.addTestSuite(ButtonObservableValueTest.class); - suite.addTest(SWTMutableObservableValueContractTest.suite(new Delegate())); - return suite; - } - - /* package */static class Delegate extends - AbstractObservableValueContractDelegate { - Shell shell; - - Button button; - - public void setUp() { - super.setUp(); - - shell = new Shell(); - button = new Button(shell, SWT.CHECK); - } - - public void tearDown() { - super.tearDown(); - - shell.dispose(); - } - - public IObservableValue createObservableValue(Realm realm) { - return new ButtonObservableValue(realm, button); - } - - public Object getValueType(IObservableValue observable) { - return Boolean.TYPE; - } - - public void change(IObservable observable) { - button.setSelection(changeValue(button)); - button.notifyListeners(SWT.Selection, null); - } - - public Object createValue(IObservableValue observable) { - return Boolean.valueOf(changeValue(button)); - } - - private boolean changeValue(Button button) { - return !button.getSelection(); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/CComboObservableValueSelectionTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/CComboObservableValueSelectionTest.java deleted file mode 100644 index dc48c2aa..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/CComboObservableValueSelectionTest.java +++ /dev/null @@ -1,120 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 213145 - *******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest; -import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; -import org.eclipse.jface.databinding.swt.ISWTObservable; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.internal.databinding.swt.CComboObservableValue; -import org.eclipse.jface.internal.databinding.swt.SWTProperties; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; - -/** - * @since 3.2 - */ -public class CComboObservableValueSelectionTest extends TestCase { - private Delegate delegate; - - private CCombo combo; - - protected void setUp() throws Exception { - super.setUp(); - - delegate = new Delegate(); - delegate.setUp(); - combo = delegate.combo; - } - - protected void tearDown() throws Exception { - super.tearDown(); - - delegate.tearDown(); - } - - public void testSelection_NotifiesObservable() throws Exception { - IObservableValue observable = (IObservableValue) delegate - .createObservable(SWTObservables.getRealm(Display.getDefault())); - - ValueChangeEventTracker listener = ValueChangeEventTracker.observe(observable); - combo.select(0); - - assertEquals("Observable was not notified.", 1, listener.count); - } - - public static Test suite() { - TestSuite suite = new TestSuite(CComboObservableValueSelectionTest.class.getName()); - suite.addTestSuite(CComboObservableValueSelectionTest.class); - suite.addTest(SWTMutableObservableValueContractTest.suite(new Delegate())); - return suite; - } - - /* package */static class Delegate extends - AbstractObservableValueContractDelegate { - private Shell shell; - - /* package */CCombo combo; - - public void setUp() { - shell = new Shell(); - combo = new CCombo(shell, SWT.NONE); - combo.add("a"); - combo.add("b"); - } - - public void tearDown() { - shell.dispose(); - } - - public IObservableValue createObservableValue(Realm realm) { - return new CComboObservableValue(realm, combo, - SWTProperties.SELECTION); - } - - public void change(IObservable observable) { - int index = combo - .indexOf((String) createValue((IObservableValue) observable)); - - combo.select(index); - } - - public Object getValueType(IObservableValue observable) { - return String.class; - } - - public Object createValue(IObservableValue observable) { - CCombo combo = ((CCombo) ((ISWTObservable) observable).getWidget()); - switch (combo.getSelectionIndex()) { - case -1: - // fall thru - case 1: - return combo.getItem(0); - case 0: - return combo.getItem(1); - default: - throw new RuntimeException("Unexpected selection."); - } - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/CComboObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/CComboObservableValueTest.java deleted file mode 100644 index e89fe421..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/CComboObservableValueTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Ashley Cambrell - bug 198904 - * Eric Rizzo - bug 134884 - ******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; -import org.eclipse.jface.internal.databinding.swt.CComboObservableValue; -import org.eclipse.jface.internal.databinding.swt.SWTProperties; -import org.eclipse.jface.tests.databinding.AbstractSWTTestCase; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; - -/** - * @since 3.2 - */ -public class CComboObservableValueTest extends AbstractSWTTestCase { - public void testDispose() throws Exception { - CCombo combo = new CCombo(getShell(), SWT.NONE); - CComboObservableValue observableValue = new CComboObservableValue( - combo, SWTProperties.TEXT); - - ValueChangeEventTracker testCounterValueChangeListener = new ValueChangeEventTracker(); - observableValue.addValueChangeListener(testCounterValueChangeListener); - - assertEquals("", combo.getText()); - assertEquals("", observableValue.getValue()); - - String expected1 = "Test123"; - combo.setText(expected1); - - assertEquals(1, testCounterValueChangeListener.count); - assertEquals(expected1, combo.getText()); - assertEquals(expected1, observableValue.getValue()); - - observableValue.dispose(); - - String expected2 = "NewValue123"; - combo.setText(expected2); - - assertEquals(1, testCounterValueChangeListener.count); - assertEquals(expected2, combo.getText()); - } - - public void testSetValueWithNull() { - testSetValueWithNull(SWTProperties.TEXT); - testSetValueWithNull(SWTProperties.SELECTION); - } - - protected void testSetValueWithNull(String observableMode) { - CCombo combo = new CCombo(getShell(), SWT.NONE); - combo.setItems(new String[] {"one", "two", "three"}); - CComboObservableValue observable = new CComboObservableValue( - combo, observableMode); - - observable.doSetValue("two"); - assertEquals("two", combo.getText()); - assertEquals(1, combo.getSelectionIndex()); - - observable.doSetValue(null); - assertEquals("", combo.getText()); - assertEquals(-1, combo.getSelectionIndex()); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/CComboObservableValueTextTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/CComboObservableValueTextTest.java deleted file mode 100644 index 246879fd..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/CComboObservableValueTextTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bug 213145 - ******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest; -import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; -import org.eclipse.jface.databinding.swt.ISWTObservable; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.internal.databinding.swt.CComboObservableValue; -import org.eclipse.jface.internal.databinding.swt.SWTProperties; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; - -/** - * @since 3.2 - */ -public class CComboObservableValueTextTest extends TestCase { - private Delegate delegate; - - private CCombo combo; - - protected void setUp() throws Exception { - super.setUp(); - - delegate = new Delegate(); - delegate.setUp(); - combo = delegate.combo; - } - - protected void tearDown() throws Exception { - super.tearDown(); - - delegate.tearDown(); - } - - public void testModify_NotifiesObservable() throws Exception { - IObservableValue observable = delegate - .createObservableValue(SWTObservables.getRealm(Display - .getDefault())); - ValueChangeEventTracker listener = ValueChangeEventTracker - .observe(observable); - - combo.setText((String) delegate.createValue(observable)); - - assertEquals("Observable was not notified.", 1, listener.count); - } - - public static Test suite() { - TestSuite suite = new TestSuite(CComboObservableValueTextTest.class.getName()); - suite.addTestSuite(CComboObservableValueTextTest.class); - suite.addTest(SWTMutableObservableValueContractTest.suite(new Delegate())); - return suite; - } - - /* package */static class Delegate extends - AbstractObservableValueContractDelegate { - /* package */CCombo combo; - - private Shell shell; - - public void setUp() { - shell = new Shell(); - combo = new CCombo(shell, SWT.NONE); - } - - public void tearDown() { - shell.dispose(); - } - - public IObservableValue createObservableValue(Realm realm) { - return new CComboObservableValue(realm, combo, SWTProperties.TEXT); - } - - public void change(IObservable observable) { - CCombo combo = (CCombo) ((ISWTObservable) observable).getWidget(); - combo.setText(combo.getText() + "a"); - } - - public Object getValueType(IObservableValue observable) { - return String.class; - } - - public Object createValue(IObservableValue observable) { - return observable.getValue() + "a"; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/CComboSingleSelectionObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/CComboSingleSelectionObservableValueTest.java deleted file mode 100644 index 36d0bc75..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/CComboSingleSelectionObservableValueTest.java +++ /dev/null @@ -1,103 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Ashley Cambrell - bug 198903 - * Matthew Hall - bug 213145 - ******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest; -import org.eclipse.jface.databinding.swt.ISWTObservable; -import org.eclipse.jface.internal.databinding.swt.CComboSingleSelectionObservableValue; -import org.eclipse.jface.tests.databinding.AbstractSWTTestCase; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.widgets.Shell; - -/** - * @since 3.2 - */ -public class CComboSingleSelectionObservableValueTest extends AbstractSWTTestCase { - public void testSetValue() throws Exception { - CCombo combo = new CCombo(getShell(), SWT.NONE); - CComboSingleSelectionObservableValue observableValue = new CComboSingleSelectionObservableValue( - combo); - combo.add("Item1"); - combo.add("Item2"); - - assertEquals(-1, combo.getSelectionIndex()); - assertEquals(-1, ((Integer) observableValue.getValue()).intValue()); - - Integer value = new Integer(1); - observableValue.setValue(value); - assertEquals("combo selection index", value.intValue(), combo - .getSelectionIndex()); - assertEquals("observable value", value, observableValue.getValue()); - - assertEquals("Item2", combo.getText()); - } - - public static Test suite() { - TestSuite suite = new TestSuite(CComboSingleSelectionObservableValueTest.class.getName()); - suite.addTestSuite(CComboSingleSelectionObservableValueTest.class); - suite.addTest(SWTMutableObservableValueContractTest.suite(new Delegate())); - return suite; - } - - /* package */static class Delegate extends - AbstractObservableValueContractDelegate { - private CCombo combo; - private Shell shell; - - public void setUp() { - shell = new Shell(); - combo = new CCombo(shell, SWT.NONE); - combo.add("0"); - combo.add("1"); - } - - public void tearDown() { - shell.dispose(); - } - - public IObservableValue createObservableValue(Realm realm) { - return new CComboSingleSelectionObservableValue(realm, combo); - } - - public void change(IObservable observable) { - int index = _createValue((IObservableValue) observable); - combo.select(index); - combo.notifyListeners(SWT.Selection, null); - } - - public Object getValueType(IObservableValue observable) { - return Integer.TYPE; - } - - public Object createValue(IObservableValue observable) { - return new Integer(_createValue(observable)); - } - - private int _createValue(IObservableValue observable) { - CCombo combo = ((CCombo) ((ISWTObservable) observable).getWidget()); - int value = Math.max(0, combo.getSelectionIndex()); - - //returns either 0 or 1 depending upon current value - return Math.abs(value - 1); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/CLabelObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/CLabelObservableValueTest.java deleted file mode 100644 index abdf4e44..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/CLabelObservableValueTest.java +++ /dev/null @@ -1,106 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bug 213145 - ******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.internal.databinding.swt.CLabelObservableValue; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CLabel; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; - -/** - * @since 3.2 - * - */ -public class CLabelObservableValueTest extends TestCase { - private Delegate delegate; - private IObservableValue observable; - private CLabel label; - - protected void setUp() throws Exception { - super.setUp(); - - delegate = new Delegate(); - delegate.setUp(); - label = delegate.label; - observable = delegate.createObservableValue(SWTObservables.getRealm(Display.getDefault())); - } - - protected void tearDown() throws Exception { - super.tearDown(); - - delegate.tearDown(); - observable.dispose(); - } - - public void testSetValue() throws Exception { - //preconditions - assertEquals(null, label.getText()); - assertEquals(null, observable.getValue()); - - String value = "value"; - observable.setValue(value); - assertEquals("label text", value, label.getText()); - assertEquals("observable value", value, observable.getValue()); - } - - public static Test suite() { - TestSuite suite = new TestSuite(CLabelObservableValueTest.class.getName()); - suite.addTestSuite(CLabelObservableValueTest.class); - suite.addTest(SWTMutableObservableValueContractTest.suite(new Delegate())); - return suite; - } - - /* package */static class Delegate extends - AbstractObservableValueContractDelegate { - private Shell shell; - - CLabel label; - - public void setUp() { - shell = new Shell(); - label = new CLabel(shell, SWT.NONE); - } - - public void tearDown() { - shell.dispose(); - } - - public IObservableValue createObservableValue(Realm realm) { - return new CLabelObservableValue(realm, label); - } - - public void change(IObservable observable) { - IObservableValue value = (IObservableValue) observable; - value.setValue(value.getValue() + "a"); - } - - public Object getValueType(IObservableValue observable) { - return String.class; - } - - public Object createValue(IObservableValue observable) { - return observable.getValue() + "a"; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ComboObservableValueSelectionTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ComboObservableValueSelectionTest.java deleted file mode 100644 index 48d431d2..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ComboObservableValueSelectionTest.java +++ /dev/null @@ -1,124 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 213145 - *******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest; -import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; -import org.eclipse.jface.databinding.swt.ISWTObservable; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.internal.databinding.swt.ComboObservableValue; -import org.eclipse.jface.internal.databinding.swt.SWTProperties; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; - -/** - * @since 3.2 - * - */ -public class ComboObservableValueSelectionTest extends TestCase { - private Delegate delegate; - - private Combo combo; - - protected void setUp() throws Exception { - super.setUp(); - - delegate = new Delegate(); - delegate.setUp(); - combo = delegate.combo; - } - - protected void tearDown() throws Exception { - super.tearDown(); - - delegate.tearDown(); - } - - public void testSelection_NotifiesObservable() throws Exception { - IObservableValue observable = (IObservableValue) delegate - .createObservable(SWTObservables.getRealm(Display.getDefault())); - - ValueChangeEventTracker listener = ValueChangeEventTracker - .observe(observable); - combo.select(0); - combo.notifyListeners(SWT.Selection, null); - - assertEquals("Observable was not notified.", 1, listener.count); - } - - public static Test suite() { - TestSuite suite = new TestSuite(ComboObservableValueSelectionTest.class.toString()); - suite.addTestSuite(ComboObservableValueSelectionTest.class); - suite.addTest(SWTMutableObservableValueContractTest.suite(new Delegate())); - return suite; - } - - /* package */static class Delegate extends - AbstractObservableValueContractDelegate { - private Shell shell; - - /* package */Combo combo; - - public void setUp() { - shell = new Shell(); - combo = new Combo(shell, SWT.NONE); - combo.add("a"); - combo.add("b"); - } - - public void tearDown() { - shell.dispose(); - } - - public IObservableValue createObservableValue(Realm realm) { - return new ComboObservableValue(realm, combo, - SWTProperties.SELECTION); - } - - public void change(IObservable observable) { - int index = combo - .indexOf((String) createValue((IObservableValue) observable)); - - combo.select(index); - combo.notifyListeners(SWT.Selection, null); - } - - public Object getValueType(IObservableValue observable) { - return String.class; - } - - public Object createValue(IObservableValue observable) { - Combo combo = ((Combo) ((ISWTObservable) observable).getWidget()); - switch (combo.getSelectionIndex()) { - case -1: - // fall thru - case 1: - return combo.getItem(0); - case 0: - return combo.getItem(1); - default: - throw new RuntimeException("Unexpected selection."); - } - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ComboObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ComboObservableValueTest.java deleted file mode 100644 index 0423bb21..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ComboObservableValueTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Ashley Cambrell - bug 198904 - ******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; -import org.eclipse.jface.internal.databinding.swt.ComboObservableValue; -import org.eclipse.jface.internal.databinding.swt.SWTProperties; -import org.eclipse.jface.tests.databinding.AbstractSWTTestCase; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Combo; - -/** - * @since 3.2 - * @no - */ -public class ComboObservableValueTest extends AbstractSWTTestCase { - public void testDispose() throws Exception { - Combo combo = new Combo(getShell(), SWT.NONE); - ComboObservableValue observableValue = new ComboObservableValue(combo, - SWTProperties.TEXT); - ValueChangeEventTracker testCounterValueChangeListener = new ValueChangeEventTracker(); - observableValue.addValueChangeListener(testCounterValueChangeListener); - - assertEquals("", combo.getText()); - assertEquals("", observableValue.getValue()); - - String expected1 = "Test123"; - combo.setText(expected1); - - assertEquals(1, testCounterValueChangeListener.count); - assertEquals(expected1, combo.getText()); - assertEquals(expected1, observableValue.getValue()); - - observableValue.dispose(); - - String expected2 = "NewValue123"; - combo.setText(expected2); - - assertEquals(1, testCounterValueChangeListener.count); - assertEquals(expected2, combo.getText()); - } - - public void testSetValueWithNull() { - testSetValueWithNull(SWTProperties.TEXT); - testSetValueWithNull(SWTProperties.SELECTION); - } - - protected void testSetValueWithNull(String observableMode) { - Combo combo = new Combo(getShell(), SWT.NONE); - combo.setItems(new String[] {"one", "two", "three"}); - ComboObservableValue observable = new ComboObservableValue( - combo, observableMode); - - observable.doSetValue("two"); - assertEquals("two", combo.getText()); - if (observableMode.equals(SWTProperties.SELECTION)) { - assertEquals("expect selection at index 1 in mode " + observableMode, 1, combo.getSelectionIndex()); - } - - if (observableMode.equals(SWTProperties.TEXT)) { - observable.doSetValue(null); - assertEquals("expect empty text in mode " + observableMode, "", combo.getText()); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ComboObservableValueTextTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ComboObservableValueTextTest.java deleted file mode 100644 index 5b737717..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ComboObservableValueTextTest.java +++ /dev/null @@ -1,108 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bug 213145 - ******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest; -import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; -import org.eclipse.jface.databinding.swt.ISWTObservable; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.internal.databinding.swt.ComboObservableValue; -import org.eclipse.jface.internal.databinding.swt.SWTProperties; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; - -/** - * @since 3.2 - * - */ -public class ComboObservableValueTextTest extends TestCase { - private Delegate delegate; - - private Combo combo; - - protected void setUp() throws Exception { - super.setUp(); - - delegate = new Delegate(); - delegate.setUp(); - combo = delegate.combo; - } - - protected void tearDown() throws Exception { - super.tearDown(); - - delegate.tearDown(); - } - - public void testModify_NotifiesObservable() throws Exception { - IObservableValue observable = delegate - .createObservableValue(SWTObservables.getRealm(Display - .getDefault())); - ValueChangeEventTracker listener = ValueChangeEventTracker - .observe(observable); - - combo.setText((String) delegate.createValue(observable)); - - assertEquals("Observable was not notified.", 1, listener.count); - } - - public static Test suite() { - TestSuite suite = new TestSuite(ComboObservableValueTextTest.class.toString()); - suite.addTestSuite(ComboObservableValueTextTest.class); - suite.addTest(SWTMutableObservableValueContractTest.suite(new Delegate())); - return suite; - } - - /* package */static class Delegate extends - AbstractObservableValueContractDelegate { - /* package */Combo combo; - - private Shell shell; - - public void setUp() { - shell = new Shell(); - combo = new Combo(shell, SWT.NONE); - } - - public void tearDown() { - shell.dispose(); - } - - public IObservableValue createObservableValue(Realm realm) { - return new ComboObservableValue(realm, combo, SWTProperties.TEXT); - } - - public void change(IObservable observable) { - Combo combo = (Combo) ((ISWTObservable) observable).getWidget(); - combo.setText(combo.getText() + "a"); - } - - public Object getValueType(IObservableValue observable) { - return String.class; - } - - public Object createValue(IObservableValue observable) { - return observable.getValue() + "a"; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ComboSingleSelectionObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ComboSingleSelectionObservableValueTest.java deleted file mode 100644 index b8b31545..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ComboSingleSelectionObservableValueTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Ashley Cambrell 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: - * Ashley Cambrell - initial API and implementation (bug 198903) - ******************************************************************************/ -package org.eclipse.jface.tests.internal.databinding.swt; - -import org.eclipse.jface.internal.databinding.swt.ComboSingleSelectionObservableValue; -import org.eclipse.jface.tests.databinding.AbstractSWTTestCase; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Combo; - -/** - * @since 3.2 - * - */ -public class ComboSingleSelectionObservableValueTest extends - AbstractSWTTestCase { - public void testSetValue() throws Exception { - Combo combo = new Combo(getShell(), SWT.NONE); - ComboSingleSelectionObservableValue observableValue = new ComboSingleSelectionObservableValue( - combo); - combo.add("Item1"); - combo.add("Item2"); - - assertEquals(-1, combo.getSelectionIndex()); - assertEquals(-1, ((Integer) observableValue.getValue()).intValue()); - - Integer value = new Integer(1); - observableValue.setValue(value); - assertEquals("combo selection index", value.intValue(), combo - .getSelectionIndex()); - assertEquals("observable value", value, observableValue.getValue()); - - assertEquals("Item2", combo.getText()); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ControlObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ControlObservableValueTest.java deleted file mode 100644 index 9e9db620..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ControlObservableValueTest.java +++ /dev/null @@ -1,192 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Brad Reynolds - bug 170848 - ******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import org.eclipse.jface.internal.databinding.swt.ControlObservableValue; -import org.eclipse.jface.internal.databinding.swt.SWTProperties; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.widgets.Shell; - -/** - * @since 3.2 - * - */ -public class ControlObservableValueTest extends AbstractDefaultRealmTestCase { - private Shell shell; - - protected void setUp() throws Exception { - super.setUp(); - - shell = new Shell(); - } - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#tearDown() - */ - protected void tearDown() throws Exception { - if (shell != null && !shell.isDisposed()) { - shell.dispose(); - shell = null; - } - } - - public void testSetValueEnabled() throws Exception { - ControlObservableValue observableValue = new ControlObservableValue( - shell, SWTProperties.ENABLED); - Boolean value = Boolean.FALSE; - observableValue.setValue(value); - assertFalse(shell.isEnabled()); - } - - public void testGetValueEnabled() throws Exception { - ControlObservableValue value = new ControlObservableValue(shell, - SWTProperties.ENABLED); - shell.setEnabled(false); - assertEquals(Boolean.FALSE, value.getValue()); - } - - public void testGetValueTypeEnabled() throws Exception { - ControlObservableValue value = new ControlObservableValue(shell, - SWTProperties.ENABLED); - assertEquals(boolean.class, value.getValueType()); - } - - public void testSetValueVisible() throws Exception { - ControlObservableValue value = new ControlObservableValue(shell, - SWTProperties.VISIBLE); - value.setValue(Boolean.FALSE); - assertFalse(shell.isVisible()); - } - - public void testGetValueVisible() throws Exception { - ControlObservableValue value = new ControlObservableValue(shell, - SWTProperties.VISIBLE); - shell.setVisible(false); - assertEquals(Boolean.FALSE, value.getValue()); - } - - public void testGetValueTypeVisible() throws Exception { - ControlObservableValue value = new ControlObservableValue(shell, - SWTProperties.VISIBLE); - assertEquals(Boolean.TYPE, value.getValueType()); - } - - public void testSetValueForeground() throws Exception { - ControlObservableValue value = new ControlObservableValue(shell, - SWTProperties.FOREGROUND); - - Color color = shell.getDisplay().getSystemColor(SWT.COLOR_BLACK); - - value.setValue(color); - assertEquals(color, shell.getForeground()); - } - - public void testGetValueForeground() throws Exception { - ControlObservableValue value = new ControlObservableValue(shell, - SWTProperties.FOREGROUND); - - Color color = shell.getDisplay().getSystemColor(SWT.COLOR_BLACK); - shell.setForeground(color); - assertEquals(color, value.getValue()); - } - - public void testGetValueTypeForgroundColor() throws Exception { - ControlObservableValue value = new ControlObservableValue(shell, - SWTProperties.FOREGROUND); - assertEquals(Color.class, value.getValueType()); - } - - public void testGetValueBackground() throws Exception { - ControlObservableValue value = new ControlObservableValue(shell, - SWTProperties.BACKGROUND); - - Color color = shell.getDisplay().getSystemColor(SWT.COLOR_BLACK); - shell.setBackground(color); - assertEquals(color, value.getValue()); - } - - public void testSetValueBackground() throws Exception { - ControlObservableValue value = new ControlObservableValue(shell, - SWTProperties.BACKGROUND); - - Color color = shell.getDisplay().getSystemColor(SWT.COLOR_BLACK); - - value.setValue(color); - assertEquals(color, shell.getBackground()); - } - - public void testGetValueTypeBackgroundColor() throws Exception { - ControlObservableValue value = new ControlObservableValue(shell, - SWTProperties.BACKGROUND); - assertEquals(Color.class, value.getValueType()); - } - - public void testGetValueTypeTooltip() throws Exception { - ControlObservableValue value = new ControlObservableValue(shell, - SWTProperties.TOOLTIP_TEXT); - assertEquals(String.class, value.getValueType()); - } - - public void testSetValueFont() throws Exception { - ControlObservableValue value = new ControlObservableValue(shell, - SWTProperties.FONT); - - Font font = JFaceResources.getDialogFont(); - - value.setValue(font); - assertEquals(font, shell.getFont()); - } - - public void testGetValueFont() throws Exception { - ControlObservableValue value = new ControlObservableValue(shell, - SWTProperties.FONT); - - Font font = JFaceResources.getDialogFont(); - shell.setFont(font); - assertEquals(font, value.getValue()); - } - - public void testGetValueTypeFont() throws Exception { - ControlObservableValue value = new ControlObservableValue(shell, - SWTProperties.FONT); - assertEquals(Font.class, value.getValueType()); - } - - public void testSetValueTooltipText() throws Exception { - ControlObservableValue value = new ControlObservableValue(shell, - SWTProperties.TOOLTIP_TEXT); - String text = "text"; - value.setValue(text); - assertEquals(text, shell.getToolTipText()); - } - - public void testGetValueTooltipText() throws Exception { - ControlObservableValue value = new ControlObservableValue(shell, - SWTProperties.TOOLTIP_TEXT); - String text = "text"; - shell.setToolTipText(text); - assertEquals(text, value.getValue()); - } - - public void testGetValueTypeTooltipText() throws Exception { - ControlObservableValue value = new ControlObservableValue(shell, - SWTProperties.TOOLTIP_TEXT); - assertEquals(String.class, value.getValueType()); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/DelayedObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/DelayedObservableValueTest.java deleted file mode 100644 index 1cc02430..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/DelayedObservableValueTest.java +++ /dev/null @@ -1,272 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 212223) - * Matthew Hall - bug 213145 - ******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest; -import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue; -import org.eclipse.jface.internal.databinding.swt.DelayedObservableValue; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Widget; - -/** - * Tests for DelayedObservableValue - * - * @since 1.2 - */ -public class DelayedObservableValueTest extends AbstractDefaultRealmTestCase { - private Display display; - private Shell shell; - private Object oldValue; - private Object newValue; - private SWTObservableValueStub target; - private DelayedObservableValue delayed; - - protected void setUp() throws Exception { - super.setUp(); - display = Display.getCurrent(); - shell = new Shell(display); - target = new SWTObservableValueStub(SWTObservables.getRealm(display), - shell); - oldValue = new Object(); - newValue = new Object(); - target.setValue(oldValue); - delayed = new DelayedObservableValue(1, target); - } - - protected void tearDown() throws Exception { - target.dispose(); - target = null; - shell.dispose(); - shell = null; - display = null; - super.tearDown(); - } - - public void testIsStale_WhenTargetIsStale() { - assertFalse(target.isStale()); - assertFalse(delayed.isStale()); - - target.fireStale(); - - assertTrue(target.isStale()); - assertTrue(delayed.isStale()); - } - - public void testIsStale_DuringDelay() { - assertFalse(target.isStale()); - assertFalse(delayed.isStale()); - - target.setValue(newValue); - - assertFalse(target.isStale()); - assertTrue(delayed.isStale()); - } - - public void testGetValueType_SameAsTarget() { - assertEquals(target.getValueType(), delayed.getValueType()); - } - - public void testGetValue_FiresPendingValueChange() { - assertFiresPendingValueChange(new Runnable() { - public void run() { - final Object value = delayed.getValue(); - assertEquals(newValue, value); - } - }); - } - - public void testFocusOut_FiresPendingValueChange() { - assertFiresPendingValueChange(new Runnable() { - public void run() { - // simulate focus-out event - shell.notifyListeners(SWT.FocusOut, new Event()); - } - }); - } - - public void testSetValue_PropagatesToTarget() { - assertEquals(oldValue, delayed.getValue()); - assertEquals(oldValue, target.getValue()); - - delayed.setValue(newValue); - - assertEquals(newValue, target.getValue()); - assertEquals(newValue, delayed.getValue()); - } - - public void testSetValue_CachesGetValueFromTarget() { - Object overrideValue = target.overrideValue = new Object(); - - assertEquals(oldValue, delayed.getValue()); - assertEquals(oldValue, target.getValue()); - - delayed.setValue(newValue); - - assertEquals(overrideValue, target.getValue()); - assertEquals(overrideValue, delayed.getValue()); - } - - public void testSetValue_FiresValueChangeEvent() { - ValueChangeEventTracker targetTracker = ValueChangeEventTracker - .observe(target); - ValueChangeEventTracker delayedTracker = ValueChangeEventTracker - .observe(delayed); - - delayed.setValue(newValue); - - assertEquals(1, targetTracker.count); - assertEquals(oldValue, targetTracker.event.diff.getOldValue()); - assertEquals(newValue, targetTracker.event.diff.getNewValue()); - - assertEquals(1, delayedTracker.count); - assertEquals(oldValue, delayedTracker.event.diff.getOldValue()); - assertEquals(newValue, delayedTracker.event.diff.getNewValue()); - } - - public void testWait_FiresPendingValueChange() { - assertFiresPendingValueChange(new Runnable() { - public void run() { - // Give plenty of time for display to run timer task - long timeout = time() + 5000; - do { - sleep(10); - processDisplayEvents(); - } while (delayed.isStale() && time() < timeout); - } - - private void sleep(int delay) { - try { - Thread.sleep(delay); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } - - private void processDisplayEvents() { - while (display.readAndDispatch()) { - } - } - - private long time() { - return System.currentTimeMillis(); - } - }); - } - - private void assertFiresPendingValueChange(Runnable runnable) { - ValueChangeEventTracker tracker = ValueChangeEventTracker - .observe(delayed); - - target.setValue(newValue); - assertTrue(delayed.isStale()); - assertEquals(0, tracker.count); - - runnable.run(); - - assertFalse(delayed.isStale()); - assertEquals(1, tracker.count); - assertEquals(oldValue, tracker.event.diff.getOldValue()); - assertEquals(newValue, tracker.event.diff.getNewValue()); - } - - static class SWTObservableValueStub extends AbstractSWTObservableValue { - private Object value; - private boolean stale; - - Object overrideValue; - - public SWTObservableValueStub(Realm realm, Widget widget) { - super(realm, widget); - } - - protected Object doGetValue() { - return value; - } - - protected void doSetValue(Object value) { - Object oldValue = this.value; - if (overrideValue != null) - value = overrideValue; - this.value = value; - stale = false; - fireValueChange(Diffs.createValueDiff(oldValue, value)); - } - - public Object getValueType() { - return Object.class; - } - - protected void fireStale() { - stale = true; - super.fireStale(); - } - - public boolean isStale() { - return stale; - } - } - - public static Test suite() { - TestSuite suite = new TestSuite(DelayedObservableValueTest.class.getName()); - suite.addTestSuite(DelayedObservableValueTest.class); - suite.addTest(SWTMutableObservableValueContractTest.suite(new Delegate())); - return suite; - } - - static class Delegate extends AbstractObservableValueContractDelegate { - Shell shell; - - public void setUp() { - super.setUp(); - shell = new Shell(); - } - - public void tearDown() { - shell.dispose(); - shell = null; - super.tearDown(); - } - - public IObservableValue createObservableValue(Realm realm) { - return new DelayedObservableValue(0, new SWTObservableValueStub( - realm, shell)); - } - - public Object getValueType(IObservableValue observable) { - return Object.class; - } - - public void change(IObservable observable) { - IObservableValue observableValue = (IObservableValue) observable; - observableValue.setValue(createValue(observableValue)); - } - - public Object createValue(IObservableValue observable) { - return new Object(); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/LabelObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/LabelObservableValueTest.java deleted file mode 100644 index 55abc7ed..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/LabelObservableValueTest.java +++ /dev/null @@ -1,109 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bug 213145 - ******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.conformance.ObservableDelegateTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.internal.databinding.swt.LabelObservableValue; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; - -/** - * @since 3.2 - */ -public class LabelObservableValueTest extends ObservableDelegateTest { - private Delegate delegate; - private IObservableValue observable; - private Label label; - - public LabelObservableValueTest() { - this(null); - } - - public LabelObservableValueTest(String testName) { - super(testName, new Delegate()); - } - - protected void setUp() throws Exception { - super.setUp(); - - delegate = (Delegate) getObservableContractDelegate(); - observable = (IObservableValue) getObservable(); - label = delegate.label; - } - - protected IObservable doCreateObservable() { - return getObservableContractDelegate().createObservable(SWTObservables.getRealm(Display.getDefault())); - } - - public void testSetValue() throws Exception { - //preconditions - assertEquals("", label.getText()); - assertEquals("", observable.getValue()); - - String value = "value"; - observable.setValue(value); - assertEquals("label text", value, label.getText()); - assertEquals("observable value", value, observable.getValue()); - } - - public static Test suite() { - TestSuite suite = new TestSuite(LabelObservableValueTest.class.toString()); - suite.addTestSuite(LabelObservableValueTest.class); - suite.addTest(SWTMutableObservableValueContractTest.suite(new Delegate())); - return suite; - } - - /* package */static class Delegate extends - AbstractObservableValueContractDelegate { - private Shell shell; - - Label label; - - public void setUp() { - shell = new Shell(); - label = new Label(shell, SWT.NONE); - } - - public void tearDown() { - shell.dispose(); - } - - public IObservableValue createObservableValue(Realm realm) { - return new LabelObservableValue(realm, label); - } - - public void change(IObservable observable) { - IObservableValue value = (IObservableValue) observable; - value.setValue(value.getValue() + "a"); - } - - public Object getValueType(IObservableValue observable) { - return String.class; - } - - public Object createValue(IObservableValue observable) { - return observable.getValue() + "a"; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ListSingleSelectionObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ListSingleSelectionObservableValueTest.java deleted file mode 100644 index 0bc7315e..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ListSingleSelectionObservableValueTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Ashley Cambrell 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: - * Ashley Cambrell - initial API and implementation - ******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import org.eclipse.jface.internal.databinding.swt.ListSingleSelectionObservableValue; -import org.eclipse.jface.tests.databinding.AbstractSWTTestCase; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.List; - -/** - * @since 3.2 - * - */ -public class ListSingleSelectionObservableValueTest extends AbstractSWTTestCase { - public void testSetValue() throws Exception { - List list = new List(getShell(), SWT.NONE); - ListSingleSelectionObservableValue observableValue = new ListSingleSelectionObservableValue( - list); - list.add("Item1"); - - assertEquals(-1, list.getSelectionIndex()); - assertEquals(-1, ((Integer) observableValue.getValue()).intValue()); - - Integer value = new Integer(0); - observableValue.setValue(value); - assertEquals("list selection index", value.intValue(), list - .getSelectionIndex()); - assertEquals("observable value", value, observableValue.getValue()); - } - - public void testDispose() throws Exception { - List list = new List(getShell(), SWT.NONE); - ListSingleSelectionObservableValue observableValue = new ListSingleSelectionObservableValue( - list); - list.add("Item1"); - list.add("Item2"); - - assertEquals(-1, list.getSelectionIndex()); - assertEquals(-1, ((Integer) observableValue.getValue()).intValue()); - - list.select(0); - list.notifyListeners(SWT.Selection, null); - assertEquals(0, list.getSelectionIndex()); - assertEquals(new Integer(0), observableValue.getValue()); - - observableValue.dispose(); - - list.select(1); - list.notifyListeners(SWT.Selection, null); - assertEquals(1, list.getSelectionIndex()); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/SWTObservableListTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/SWTObservableListTest.java deleted file mode 100644 index fe9ee8f2..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/SWTObservableListTest.java +++ /dev/null @@ -1,115 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 208858) - * Matthew Hall - bug 213145 - ******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.jface.databinding.conformance.MutableObservableListContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; -import org.eclipse.jface.internal.databinding.swt.SWTObservableList; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; - -/** - * @since 3.3 - */ -public class SWTObservableListTest extends AbstractDefaultRealmTestCase { - SWTObservableListStub list; - - protected void setUp() throws Exception { - super.setUp(); - list = new SWTObservableListStub(Realm.getDefault(), 0); - } - - public void testMove_ForwardAndBackward() { - String element0 = "element0"; - String element1 = "element1"; - - list.add(element0); - list.add(element1); - - // move forward - assertEquals(element0, list.move(0, 1)); - assertEquals(element1, list.move(0, 1)); - - // move backward - assertEquals(element1, list.move(1, 0)); - assertEquals(element0, list.move(1, 0)); - } - - public static Test suite() { - TestSuite suite = new TestSuite(SWTObservableListTest.class.toString()); - suite.addTestSuite(SWTObservableListTest.class); - suite.addTest(MutableObservableListContractTest.suite(new Delegate())); - return suite; - } - - static class Delegate extends AbstractObservableCollectionContractDelegate { - public IObservableCollection createObservableCollection(Realm realm, - int elementCount) { - return new SWTObservableListStub(realm, elementCount); - } - - private int counter; - - public Object createElement(IObservableCollection collection) { - return "Item" + counter++; - } - - public Object getElementType(IObservableCollection collection) { - return String.class; - } - - public void change(IObservable observable) { - ((SWTObservableListStub) observable).fireChange(); - } - } - - static class SWTObservableListStub extends SWTObservableList { - String[] items; - - public SWTObservableListStub(Realm realm, int elementCount) { - super(realm); - items = new String[elementCount]; - for (int i = 0; i < items.length; i++) - items[i] = Integer.toString(i); - } - - protected String getItem(int index) { - return items[index]; - } - - protected int getItemCount() { - return items.length; - } - - protected String[] getItems() { - return items; - } - - protected void setItem(int index, String string) { - items[index] = string; - } - - protected void setItems(String[] newItems) { - items = newItems; - } - - protected void fireChange() { - super.fireChange(); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ScaleObservableValueMaxTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ScaleObservableValueMaxTest.java deleted file mode 100644 index d598dcfe..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ScaleObservableValueMaxTest.java +++ /dev/null @@ -1,119 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 213145 - *******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.conformance.ObservableDelegateTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.internal.databinding.swt.SWTProperties; -import org.eclipse.jface.internal.databinding.swt.ScaleObservableValue; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Scale; -import org.eclipse.swt.widgets.Shell; - -/** - * @since 3.2 - */ -public class ScaleObservableValueMaxTest extends ObservableDelegateTest { - private Delegate delegate; - - private Scale scale; - - private IObservableValue observable; - - public ScaleObservableValueMaxTest() { - this(null); - } - - public ScaleObservableValueMaxTest(String testName) { - super(testName, new Delegate()); - } - - protected void setUp() throws Exception { - super.setUp(); - - delegate = (Delegate) getObservableContractDelegate(); - observable = (IObservableValue) getObservable(); - scale = delegate.scale; - } - - protected IObservable doCreateObservable() { - return getObservableContractDelegate().createObservable( - SWTObservables.getRealm(Display.getDefault())); - } - - public void testGetValue() throws Exception { - int max = 100; - scale.setMaximum(max); - assertEquals(new Integer(max), observable.getValue()); - } - - public void testSetValue() throws Exception { - int max = 100; - observable.setValue(new Integer(max)); - assertEquals(max, scale.getMaximum()); - } - - public static Test suite() { - TestSuite suite = new TestSuite(ScaleObservableValueMaxTest.class.toString()); - suite.addTestSuite(ScaleObservableValueMaxTest.class); - suite.addTest(SWTMutableObservableValueContractTest.suite(new Delegate())); - return suite; - } - - /* package */static class Delegate extends - AbstractObservableValueContractDelegate { - private Shell shell; - - Scale scale; - - public void setUp() { - shell = new Shell(); - scale = new Scale(shell, SWT.NONE); - scale.setMaximum(1000); - } - - public void tearDown() { - shell.dispose(); - } - - public IObservableValue createObservableValue(Realm realm) { - return new ScaleObservableValue(realm, scale, SWTProperties.MAX); - } - - public void change(IObservable observable) { - IObservableValue observableValue = (IObservableValue) observable; - observableValue.setValue(createValue(observableValue)); - } - - public Object getValueType(IObservableValue observable) { - return Integer.TYPE; - } - - public Object createValue(IObservableValue observable) { - return createIntegerValue(observable); - } - - private Integer createIntegerValue(IObservableValue observable) { - return new Integer(((Integer) observable.getValue()).intValue() + 1); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ScaleObservableValueMinTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ScaleObservableValueMinTest.java deleted file mode 100644 index f3f56dd8..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ScaleObservableValueMinTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 213145 - *******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.conformance.ObservableDelegateTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.internal.databinding.swt.SWTProperties; -import org.eclipse.jface.internal.databinding.swt.ScaleObservableValue; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Scale; -import org.eclipse.swt.widgets.Shell; - -/** - * @since 3.2 - */ -public class ScaleObservableValueMinTest extends ObservableDelegateTest { - private Delegate delegate; - - private Scale scale; - - private IObservableValue observable; - - public ScaleObservableValueMinTest() { - this(null); - } - - public ScaleObservableValueMinTest(String testName) { - super(testName, new Delegate()); - } - - protected void setUp() throws Exception { - super.setUp(); - - delegate = (Delegate) getObservableContractDelegate(); - observable = (IObservableValue) getObservable(); - scale = delegate.scale; - } - - protected IObservable doCreateObservable() { - return getObservableContractDelegate().createObservable(SWTObservables.getRealm(Display.getDefault())); - } - - public void testGetValue() throws Exception { - int min = 100; - scale.setMinimum(min); - assertEquals(new Integer(min), observable.getValue()); - } - - public void testSetValue() throws Exception { - int min = 100; - observable.setValue(new Integer(min)); - assertEquals(min, scale.getMinimum()); - } - - public static Test suite() { - TestSuite suite = new TestSuite(ScaleObservableValueMinTest.class.toString()); - suite.addTestSuite(ScaleObservableValueMinTest.class); - suite.addTest(SWTMutableObservableValueContractTest.suite(new Delegate())); - return suite; - } - - /* package */static class Delegate extends - AbstractObservableValueContractDelegate { - private Shell shell; - - Scale scale; - - public void setUp() { - shell = new Shell(); - scale = new Scale(shell, SWT.NONE); - scale.setMaximum(1000); - } - - public void tearDown() { - shell.dispose(); - } - - public IObservableValue createObservableValue(Realm realm) { - return new ScaleObservableValue(realm, scale, SWTProperties.MIN); - } - - public void change(IObservable observable) { - IObservableValue observableValue = (IObservableValue) observable; - observableValue.setValue(createValue(observableValue)); - } - - public Object getValueType(IObservableValue observable) { - return Integer.TYPE; - } - - public Object createValue(IObservableValue observable) { - return createIntegerValue(observable); - } - - private Integer createIntegerValue(IObservableValue observable) { - return new Integer(((Integer) observable.getValue()).intValue() + 1); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ScaleObservableValueSelectionTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ScaleObservableValueSelectionTest.java deleted file mode 100644 index 8043b022..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ScaleObservableValueSelectionTest.java +++ /dev/null @@ -1,122 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 213145 - *******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.conformance.ObservableDelegateTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.internal.databinding.swt.SWTProperties; -import org.eclipse.jface.internal.databinding.swt.ScaleObservableValue; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Scale; -import org.eclipse.swt.widgets.Shell; - -/** - * @since 3.2 - */ -public class ScaleObservableValueSelectionTest extends ObservableDelegateTest { - private Delegate delegate; - - private Scale scale; - - private IObservableValue observable; - - public ScaleObservableValueSelectionTest() { - this(null); - } - - public ScaleObservableValueSelectionTest(String testName) { - super(testName, new Delegate()); - } - - protected void setUp() throws Exception { - super.setUp(); - - delegate = (Delegate) getObservableContractDelegate(); - observable = (IObservableValue) getObservable(); - scale = delegate.scale; - } - - protected IObservable doCreateObservable() { - return getObservableContractDelegate().createObservable(SWTObservables.getRealm(Display.getDefault())); - } - - public void testGetValue() throws Exception { - int value = 100; - scale.setSelection(value); - assertEquals(new Integer(value), observable.getValue()); - } - - public void testSetValue() throws Exception { - int value = 100; - observable.setValue(new Integer(value)); - assertEquals(value, scale.getSelection()); - } - - public static Test suite() { - TestSuite suite = new TestSuite(ScaleObservableValueSelectionTest.class - .toString()); - suite.addTestSuite(ScaleObservableValueSelectionTest.class); - suite.addTest(SWTMutableObservableValueContractTest - .suite(new Delegate())); - return suite; - } - - /* package */static class Delegate extends - AbstractObservableValueContractDelegate { - private Shell shell; - - Scale scale; - - public void setUp() { - shell = new Shell(); - scale = new Scale(shell, SWT.NONE); - scale.setMaximum(1000); - } - - public void tearDown() { - shell.dispose(); - } - - public IObservableValue createObservableValue(Realm realm) { - return new ScaleObservableValue(realm, scale, SWTProperties.SELECTION); - } - - public void change(IObservable observable) { - scale - .setSelection(createIntegerValue( - (IObservableValue) observable).intValue()); - scale.notifyListeners(SWT.Selection, null); - } - - public Object getValueType(IObservableValue observable) { - return Integer.TYPE; - } - - public Object createValue(IObservableValue observable) { - return createIntegerValue(observable); - } - - private Integer createIntegerValue(IObservableValue observable) { - return new Integer(((Integer) observable.getValue()).intValue() + 1); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ShellObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ShellObservableValueTest.java deleted file mode 100644 index 41d5330e..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ShellObservableValueTest.java +++ /dev/null @@ -1,130 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 212235) - * Matthew Hall - bug 213145 - ******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest; -import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; -import org.eclipse.jface.internal.databinding.swt.ShellObservableValue; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.eclipse.swt.widgets.Shell; - -/** - * Tests for ShellObservableValue - * - * @since 1.2 - */ -public class ShellObservableValueTest extends AbstractDefaultRealmTestCase { - String oldValue; - String newValue; - Shell shell; - ShellObservableValue observable; - ValueChangeEventTracker tracker; - - protected void setUp() throws Exception { - super.setUp(); - shell = new Shell(); - observable = new ShellObservableValue(shell); - oldValue = "old"; - newValue = "new"; - shell.setText(oldValue); - tracker = ValueChangeEventTracker.observe(observable); - } - - public void tearDown() throws Exception { - observable.dispose(); - observable = null; - shell.dispose(); - shell = null; - super.tearDown(); - } - - public void testGetValueType() { - assertEquals(String.class, observable.getValueType()); - } - - public void testSetValue_FiresValueChangeEvent() { - observable.setValue(newValue); - - assertEquals(1, tracker.count); - assertEquals(oldValue, tracker.event.diff.getOldValue()); - assertEquals(newValue, tracker.event.diff.getNewValue()); - } - - public void testSetValue_NullConvertedToEmptyString() { - observable.setValue(null); - - assertEquals("", observable.getValue()); - assertEquals("", shell.getText()); - } - - public void testShellSetText_GetValueReturnsSame() { - assertEquals(oldValue, observable.getValue()); - - shell.setText(newValue); - - assertEquals(newValue, observable.getValue()); - } - - public void testShellSetText_NoValueChangeEvent() { - shell.setText(newValue); - assertEquals(0, tracker.count); - } - - public static Test suite() { - TestSuite suite = new TestSuite(ShellObservableValueTest.class.toString()); - suite.addTestSuite(ShellObservableValueTest.class); - suite.addTest(SWTMutableObservableValueContractTest.suite(new Delegate())); - return suite; - } - - static class Delegate extends AbstractObservableValueContractDelegate { - Shell shell; - - public void setUp() { - super.setUp(); - shell = new Shell(); - } - - public void tearDown() { - shell.dispose(); - shell = null; - super.tearDown(); - } - - public IObservableValue createObservableValue(Realm realm) { - return new ShellObservableValue(realm, shell); - } - - public Object getValueType(IObservableValue observable) { - return String.class; - } - - public void change(IObservable observable) { - IObservableValue observableValue = (IObservableValue) observable; - observableValue.setValue(createValue(observableValue)); - } - - int counter; - - public Object createValue(IObservableValue observable) { - return Integer.toString(counter++); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/SpinnerObservableValueMaxTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/SpinnerObservableValueMaxTest.java deleted file mode 100644 index 52806b75..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/SpinnerObservableValueMaxTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 213145 - *******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.conformance.ObservableDelegateTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.internal.databinding.swt.SWTProperties; -import org.eclipse.jface.internal.databinding.swt.SpinnerObservableValue; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Spinner; - -/** - * @since 3.2 - */ -public class SpinnerObservableValueMaxTest extends ObservableDelegateTest { - private Delegate delegate; - - private Spinner spinner; - - private IObservableValue observable; - - public SpinnerObservableValueMaxTest() { - this(null); - } - - public SpinnerObservableValueMaxTest(String testName) { - super(testName, new Delegate()); - } - - protected void setUp() throws Exception { - super.setUp(); - - delegate = (Delegate) getObservableContractDelegate(); - observable = (IObservableValue) getObservable(); - spinner = delegate.spinner; - } - - protected IObservable doCreateObservable() { - return getObservableContractDelegate().createObservable(SWTObservables.getRealm(Display.getDefault())); - } - - public void testGetValue() throws Exception { - int max = 100; - spinner.setMaximum(max); - assertEquals(new Integer(max), observable.getValue()); - } - - public void testSetValue() throws Exception { - int max = 100; - observable.setValue(new Integer(max)); - assertEquals(max, spinner.getMaximum()); - } - - public static Test suite() { - TestSuite suite = new TestSuite(SpinnerObservableValueMaxTest.class.toString()); - suite.addTestSuite(SpinnerObservableValueMaxTest.class); - suite.addTest(SWTMutableObservableValueContractTest.suite(new Delegate())); - return suite; - } - - /* package */static class Delegate extends - AbstractObservableValueContractDelegate { - private Shell shell; - - Spinner spinner; - - public void setUp() { - shell = new Shell(); - spinner = new Spinner(shell, SWT.NONE); - spinner.setMaximum(1000); - } - - public void tearDown() { - shell.dispose(); - } - - public IObservableValue createObservableValue(Realm realm) { - return new SpinnerObservableValue(realm, spinner, SWTProperties.MAX); - } - - public void change(IObservable observable) { - IObservableValue observableValue = (IObservableValue) observable; - observableValue.setValue(createValue(observableValue)); - } - - public Object getValueType(IObservableValue observable) { - return Integer.TYPE; - } - - public Object createValue(IObservableValue observable) { - return createIntegerValue(observable); - } - - private Integer createIntegerValue(IObservableValue observable) { - return new Integer(((Integer) observable.getValue()).intValue() + 1); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/SpinnerObservableValueMinTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/SpinnerObservableValueMinTest.java deleted file mode 100644 index c208bea5..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/SpinnerObservableValueMinTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 213145 - *******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.conformance.ObservableDelegateTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.internal.databinding.swt.SWTProperties; -import org.eclipse.jface.internal.databinding.swt.SpinnerObservableValue; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Spinner; - -/** - * @since 3.2 - */ -public class SpinnerObservableValueMinTest extends ObservableDelegateTest { - private Delegate delegate; - - private Spinner spinner; - - private IObservableValue observable; - - public SpinnerObservableValueMinTest() { - this(null); - } - - public SpinnerObservableValueMinTest(String testName) { - super(testName, new Delegate()); - } - - protected void setUp() throws Exception { - super.setUp(); - - delegate = (Delegate) getObservableContractDelegate(); - observable = (IObservableValue) getObservable(); - spinner = delegate.spinner; - } - - protected IObservable doCreateObservable() { - return getObservableContractDelegate().createObservable(SWTObservables.getRealm(Display.getDefault())); - } - - public void testGetValue() throws Exception { - int min = 100; - spinner.setMinimum(min); - assertEquals(new Integer(min), observable.getValue()); - } - - public void testSetValue() throws Exception { - int min = 100; - observable.setValue(new Integer(min)); - assertEquals(min, spinner.getMinimum()); - } - - public static Test suite() { - TestSuite suite = new TestSuite(SpinnerObservableValueMinTest.class.toString()); - suite.addTestSuite(SpinnerObservableValueMinTest.class); - suite.addTest(SWTMutableObservableValueContractTest.suite(new Delegate())); - return suite; - } - - /* package */static class Delegate extends - AbstractObservableValueContractDelegate { - private Shell shell; - - Spinner spinner; - - public void setUp() { - shell = new Shell(); - spinner = new Spinner(shell, SWT.NONE); - spinner.setMaximum(1000); - } - - public void tearDown() { - shell.dispose(); - } - - public IObservableValue createObservableValue(Realm realm) { - return new SpinnerObservableValue(realm, spinner, SWTProperties.MIN); - } - - public void change(IObservable observable) { - IObservableValue observableValue = (IObservableValue) observable; - observableValue.setValue(createValue(observableValue)); - } - - public Object getValueType(IObservableValue observable) { - return Integer.TYPE; - } - - public Object createValue(IObservableValue observable) { - return createIntegerValue(observable); - } - - private Integer createIntegerValue(IObservableValue observable) { - return new Integer(((Integer) observable.getValue()).intValue() + 1); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/SpinnerObservableValueSelectionTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/SpinnerObservableValueSelectionTest.java deleted file mode 100644 index 066344cf..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/SpinnerObservableValueSelectionTest.java +++ /dev/null @@ -1,120 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 213145 - *******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.conformance.ObservableDelegateTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.internal.databinding.swt.SWTProperties; -import org.eclipse.jface.internal.databinding.swt.SpinnerObservableValue; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Spinner; - -/** - * @since 3.2 - */ -public class SpinnerObservableValueSelectionTest extends ObservableDelegateTest { - private Delegate delegate; - - private Spinner spinner; - - private IObservableValue observable; - - public SpinnerObservableValueSelectionTest() { - this(null); - } - - public SpinnerObservableValueSelectionTest(String testName) { - super(testName, new Delegate()); - } - - protected void setUp() throws Exception { - super.setUp(); - - delegate = (Delegate) getObservableContractDelegate(); - observable = (IObservableValue) getObservable(); - spinner = delegate.spinner; - } - - protected IObservable doCreateObservable() { - return getObservableContractDelegate().createObservable(SWTObservables.getRealm(Display.getDefault())); - } - - public void testGetValue() throws Exception { - int value = 100; - spinner.setSelection(value); - assertEquals(new Integer(value), observable.getValue()); - } - - public void testSetValue() throws Exception { - int value = 100; - observable.setValue(new Integer(value)); - assertEquals(value, spinner.getSelection()); - } - - public static Test suite() { - TestSuite suite = new TestSuite(SpinnerObservableValueSelectionTest.class.toString()); - suite.addTestSuite(SpinnerObservableValueSelectionTest.class); - suite.addTest(SWTMutableObservableValueContractTest.suite(new Delegate())); - return suite; - } - - /* package */static class Delegate extends - AbstractObservableValueContractDelegate { - private Shell shell; - - Spinner spinner; - - public void setUp() { - shell = new Shell(); - spinner = new Spinner(shell, SWT.NONE); - spinner.setMaximum(1000); - } - - public void tearDown() { - shell.dispose(); - } - - public IObservableValue createObservableValue(Realm realm) { - return new SpinnerObservableValue(realm, spinner, SWTProperties.SELECTION); - } - - public void change(IObservable observable) { - spinner - .setSelection(createIntegerValue( - (IObservableValue) observable).intValue()); - spinner.notifyListeners(SWT.Selection, null); - } - - public Object getValueType(IObservableValue observable) { - return Integer.TYPE; - } - - public Object createValue(IObservableValue observable) { - return createIntegerValue(observable); - } - - private Integer createIntegerValue(IObservableValue observable) { - return new Integer(((Integer) observable.getValue()).intValue() + 1); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/SpinnerObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/SpinnerObservableValueTest.java deleted file mode 100644 index 481c74b0..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/SpinnerObservableValueTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Ashley Cambrell - bug 198904 - ******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; -import org.eclipse.jface.internal.databinding.swt.SWTProperties; -import org.eclipse.jface.internal.databinding.swt.SpinnerObservableValue; -import org.eclipse.jface.tests.databinding.AbstractSWTTestCase; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Spinner; - -/** - * @since 3.2 - * - */ -public class SpinnerObservableValueTest extends AbstractSWTTestCase { - public void testDispose() throws Exception { - Spinner spinner = new Spinner(getShell(), SWT.NONE); - SpinnerObservableValue observableValue = new SpinnerObservableValue( - spinner, SWTProperties.SELECTION); - ValueChangeEventTracker testCounterValueChangeListener = new ValueChangeEventTracker(); - observableValue.addValueChangeListener(testCounterValueChangeListener); - - assertEquals(0, spinner.getSelection()); - assertEquals(0, ((Integer) observableValue.getValue()).intValue()); - - Integer expected1 = new Integer(1); - spinner.setSelection(expected1.intValue()); - -// assertEquals(1, testCounterValueChangeListener.counter); - assertEquals(expected1.intValue(), spinner.getSelection()); - assertEquals(expected1, observableValue.getValue()); - - observableValue.dispose(); - - Integer expected2 = new Integer(2); - spinner.setSelection(expected2.intValue()); - -// assertEquals(1, testCounterValueChangeListener.counter); - assertEquals(expected2.intValue(), spinner.getSelection()); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/TableObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/TableObservableValueTest.java deleted file mode 100644 index 25302da5..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/TableObservableValueTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Ashley Cambrell - bug 198904 - ******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import org.eclipse.jface.internal.databinding.swt.TableSingleSelectionObservableValue; -import org.eclipse.jface.tests.databinding.AbstractSWTTestCase; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableItem; - -/** - * @since 3.2 - */ -public class TableObservableValueTest extends AbstractSWTTestCase { - public void testDispose() throws Exception { - Table table = new Table(getShell(), SWT.NONE); - TableSingleSelectionObservableValue observableValue = new TableSingleSelectionObservableValue( - table); - - TableItem item1 = new TableItem(table, SWT.NONE); - item1.setText("Item1"); - TableItem item2 = new TableItem(table, SWT.NONE); - item2.setText("Item2"); - - assertEquals(-1, table.getSelectionIndex()); - assertEquals(-1, ((Integer) observableValue.getValue()).intValue()); - - table.select(0); - table.notifyListeners(SWT.Selection, null); - - assertEquals(0, table.getSelectionIndex()); - assertEquals(new Integer(0), observableValue.getValue()); - - observableValue.dispose(); - - table.select(1); - table.notifyListeners(SWT.Selection, null); - assertEquals(1, table.getSelectionIndex()); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/TableSingleSelectionObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/TableSingleSelectionObservableValueTest.java deleted file mode 100644 index f475a6b7..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/TableSingleSelectionObservableValueTest.java +++ /dev/null @@ -1,140 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 Brad Reynolds 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: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bugs 118516, 213145 - ******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.databinding.conformance.ObservableDelegateTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.internal.databinding.swt.TableSingleSelectionObservableValue; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableItem; - -/** - * @since 3.2 - */ -public class TableSingleSelectionObservableValueTest extends ObservableDelegateTest { - private Delegate delegate; - private IObservableValue observable; - private Table table; - - public TableSingleSelectionObservableValueTest() { - this(null); - } - - public TableSingleSelectionObservableValueTest(String testName) { - super(testName, new Delegate()); - } - - protected void setUp() throws Exception { - super.setUp(); - - observable = (IObservableValue) getObservable(); - delegate = (Delegate) getObservableContractDelegate(); - table = delegate.table; - } - - protected IObservable doCreateObservable() { - Delegate delegate = (Delegate) getObservableContractDelegate(); - return delegate.createObservableValue(SWTObservables.getRealm(Display.getDefault())); - } - - public void testSetValue() throws Exception { - //preconditions - assertEquals(-1, table.getSelectionIndex()); - assertEquals(-1, ((Integer) observable.getValue()).intValue()); - - Integer value = new Integer(0); - observable.setValue(value); - assertEquals("table selection index", value.intValue(), table - .getSelectionIndex()); - assertEquals("observable value", value, observable.getValue()); - } - - public void testGetValue() throws Exception { - int value = 1; - table.setSelection(value); - - assertEquals("table selection index", value, table.getSelectionIndex()); - assertEquals("observable value", new Integer(value), observable.getValue()); - } - - public static Test suite() { - TestSuite suite = new TestSuite(TableSingleSelectionObservableValueTest.class.toString()); - suite.addTestSuite(TableSingleSelectionObservableValueTest.class); - suite.addTest(SWTMutableObservableValueContractTest.suite(new Delegate())); - return suite; - } - - /* package */static class Delegate extends - AbstractObservableValueContractDelegate { - private Shell shell; - - Table table; - - public void setUp() { - shell = new Shell(); - table = new Table(shell, SWT.NONE); - new TableItem(table, SWT.NONE).setText("0"); - new TableItem(table, SWT.NONE).setText("1"); - } - - public void tearDown() { - shell.dispose(); - } - - public IObservableValue createObservableValue(Realm realm) { - return new TableSingleSelectionObservableValue(realm, table); - } - - public Object getValueType(IObservableValue observable) { - return Integer.TYPE; - } - - public void change(IObservable observable) { - int index = createIntegerValue((IObservableValue) observable) - .intValue(); - table.select(index); - - table.notifyListeners(SWT.Selection, null); - } - - public Object createValue(IObservableValue observable) { - return createIntegerValue(observable); - } - - private Integer createIntegerValue(IObservableValue observable) { - int value = ((Integer) observable.getValue()).intValue(); - switch (value) { - case -1: - case 1: - return new Integer(0); - case 0: - return new Integer(1); - } - - Assert.isTrue(false); - return null; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/TestCounterValueChangeListener.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/TestCounterValueChangeListener.java deleted file mode 100644 index 8e1ca78d..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/TestCounterValueChangeListener.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Ashley Cambrell 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: - * Ashley Cambrell - initial API and implementation - ******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import org.eclipse.core.databinding.observable.value.IValueChangeListener; -import org.eclipse.core.databinding.observable.value.ValueChangeEvent; - -class TestCounterValueChangeListener implements - IValueChangeListener { - public int counter = 0; - - public void handleValueChange(ValueChangeEvent event) { - ++counter; - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/TextEditableObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/TextEditableObservableValueTest.java deleted file mode 100644 index 8d1b09ec..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/TextEditableObservableValueTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 213145 - *******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.conformance.ObservableDelegateTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest; -import org.eclipse.jface.internal.databinding.swt.TextEditableObservableValue; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -/** - * @since 1.1 - */ -public class TextEditableObservableValueTest extends - ObservableDelegateTest { - - private Delegate delegate; - private Text text; - private IObservableValue observable; - - public TextEditableObservableValueTest() { - this(null); - } - - public TextEditableObservableValueTest(String testName) { - super(testName, new Delegate()); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.conformance.databinding.ObservableDelegateTest#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - - delegate = (Delegate) getObservableContractDelegate(); - observable = (IObservableValue) getObservable(); - text = delegate.text; - } - - protected IObservable doCreateObservable() { - return super.doCreateObservable(); - } - - public void testGetValue() throws Exception { - text.setEditable(false); - assertEquals(Boolean.valueOf(text.getEditable()), observable.getValue()); - - text.setEditable(true); - assertEquals(Boolean.valueOf(text.getEditable()), observable.getValue()); - } - - public void testSetValue() throws Exception { - text.setEditable(false); - observable.setValue(Boolean.TRUE); - assertEquals(Boolean.TRUE, Boolean.valueOf(text.getEditable())); - - observable.setValue(Boolean.FALSE); - assertEquals(Boolean.FALSE, Boolean.valueOf(text.getEditable())); - } - - public static Test suite() { - TestSuite suite = new TestSuite(TextEditableObservableValueTest.class.toString()); - suite.addTestSuite(TextEditableObservableValueTest.class); - suite.addTest(SWTMutableObservableValueContractTest.suite(new Delegate())); - return suite; - } - - /*package*/ static class Delegate extends AbstractObservableValueContractDelegate { - private Shell shell; - Text text; - - public void setUp() { - shell = new Shell(); - text = new Text(shell, SWT.NONE); - } - - public void tearDown() { - shell.dispose(); - } - - public IObservableValue createObservableValue(Realm realm) { - return new TextEditableObservableValue(realm, text); - } - - public Object getValueType(IObservableValue observable) { - return Boolean.TYPE; - } - - public void change(IObservable observable) { - IObservableValue observableValue = (IObservableValue) observable; - observableValue.setValue(createValue(observableValue)); - } - - public Object createValue(IObservableValue observable) { - return (Boolean.TRUE.equals(observable.getValue()) ? Boolean.FALSE: Boolean.TRUE); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/TextObservableValueFocusOutTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/TextObservableValueFocusOutTest.java deleted file mode 100644 index 95041603..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/TextObservableValueFocusOutTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 213145 - *******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest; -import org.eclipse.jface.internal.databinding.swt.TextObservableValue; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -/** - * Tests for the FocusOut version of TextObservableValue. - */ -public class TextObservableValueFocusOutTest extends TestCase { - public static Test suite() { - TestSuite suite = new TestSuite(TextObservableValueFocusOutTest.class.toString()); - suite.addTest(SWTMutableObservableValueContractTest.suite(new Delegate())); - return suite; - } - - /* package */static class Delegate extends - AbstractObservableValueContractDelegate { - private Shell shell; - - private Text text; - - public void setUp() { - shell = new Shell(); - text = new Text(shell, SWT.NONE); - } - - public void tearDown() { - shell.dispose(); - } - - public IObservableValue createObservableValue(Realm realm) { - return new TextObservableValue(realm, text, SWT.FocusOut); - } - - public Object getValueType(IObservableValue observable) { - return String.class; - } - - public void change(IObservable observable) { - text.setFocus(); - - IObservableValue observableValue = (IObservableValue) observable; - text.setText((String) createValue(observableValue)); - - text.notifyListeners(SWT.FocusOut, null); - } - - public Object createValue(IObservableValue observable) { - String value = (String) observable.getValue(); - return value + "a"; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/TextObservableValueModifyTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/TextObservableValueModifyTest.java deleted file mode 100644 index 98677546..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/TextObservableValueModifyTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bug 213145 - *******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest; -import org.eclipse.jface.internal.databinding.swt.TextObservableValue; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -/** - * @since 3.2 - */ -public class TextObservableValueModifyTest extends TestCase { - public static Test suite() { - TestSuite suite = new TestSuite(TextObservableValueModifyTest.class.toString()); - suite.addTest(SWTMutableObservableValueContractTest.suite(new Delegate())); - return suite; - } - - /* package */static class Delegate extends - AbstractObservableValueContractDelegate { - private Shell shell; - - private Text text; - - public void setUp() { - shell = new Shell(); - text = new Text(shell, SWT.NONE); - } - - public void tearDown() { - shell.dispose(); - } - - public IObservableValue createObservableValue(Realm realm) { - return new TextObservableValue(realm, text, SWT.Modify); - } - - public Object getValueType(IObservableValue observable) { - return String.class; - } - - public void change(IObservable observable) { - text.setFocus(); - - IObservableValue observableValue = (IObservableValue) observable; - text.setText((String) createValue(observableValue)); - } - - public Object createValue(IObservableValue observable) { - String value = (String) observable.getValue(); - return value + "a"; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/TextObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/TextObservableValueTest.java deleted file mode 100644 index 5e96a3da..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/TextObservableValueTest.java +++ /dev/null @@ -1,108 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bug 116920 - * Brad Reynolds - bug 164653 - * Ashley Cambrell - bug 198904 - *******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; -import org.eclipse.jface.internal.databinding.swt.TextObservableValue; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -/** - * Tests to assert the inputs of the TextObservableValue constructor. - * - * @since 3.2 - */ -public class TextObservableValueTest extends AbstractDefaultRealmTestCase { - private Text text; - private ValueChangeEventTracker listener; - - protected void setUp() throws Exception { - super.setUp(); - - Shell shell = new Shell(); - text = new Text(shell, SWT.NONE); - - listener = new ValueChangeEventTracker(); - } - - /** - * Asserts that only valid SWT event types are accepted on construction of - * TextObservableValue. - */ - public void testConstructorUpdateEventTypes() { - try { - new TextObservableValue(text, SWT.NONE); - new TextObservableValue(text, SWT.FocusOut); - new TextObservableValue(text, SWT.Modify); - assertTrue(true); - } catch (IllegalArgumentException e) { - fail(); - } - - try { - new TextObservableValue(text, SWT.Verify); - fail(); - } catch (IllegalArgumentException e) { - assertTrue(true); - } - } - - /** - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=171132 - * - * @throws Exception - */ - public void testGetValueBeforeFocusOutChangeEventsFire() throws Exception { - TextObservableValue observableValue = new TextObservableValue(text, SWT.FocusOut); - observableValue.addValueChangeListener(listener); - - String a = "a"; - String b = "b"; - - text.setText(a); - assertEquals(a, observableValue.getValue()); //fetch the value updating the buffered value - - text.setText(b); - text.notifyListeners(SWT.FocusOut, null); - - assertEquals(1, listener.count); - assertEquals(a, listener.event.diff.getOldValue()); - assertEquals(b, listener.event.diff.getNewValue()); - } - - public void testDispose() throws Exception { - TextObservableValue observableValue = new TextObservableValue(text, - SWT.Modify); - ValueChangeEventTracker testCounterValueChangeListener = new ValueChangeEventTracker(); - observableValue.addValueChangeListener(testCounterValueChangeListener); - - String expected1 = "Test123"; - text.setText(expected1); - - assertEquals(1, testCounterValueChangeListener.count); - assertEquals(expected1, text.getText()); - assertEquals(expected1, observableValue.getValue()); - - observableValue.dispose(); - - String expected2 = "NewValue123"; - text.setText(expected2); - - assertEquals(1, testCounterValueChangeListener.count); - assertEquals(expected2, text.getText()); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/ObservableCollectionTreeContentProviderTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/ObservableCollectionTreeContentProviderTest.java deleted file mode 100644 index 65096288..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/ObservableCollectionTreeContentProviderTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 239015) - ******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.viewers; - -import java.util.Arrays; -import java.util.HashSet; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.jface.databinding.viewers.ObservableListTreeContentProvider; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.swt.widgets.Shell; - -/** - * @since 3.2 - * - */ -public class ObservableCollectionTreeContentProviderTest extends - AbstractDefaultRealmTestCase { - private Shell shell; - private TreeViewer viewer; - ObservableListTreeContentProvider contentProvider; - - protected void setUp() throws Exception { - super.setUp(); - shell = new Shell(); - viewer = new TreeViewer(shell); - } - - protected void tearDown() throws Exception { - shell.dispose(); - shell = null; - viewer = null; - super.tearDown(); - } - - private void createContentProvider(IObservableFactory factory) { - contentProvider = new ObservableListTreeContentProvider( - factory, null); - viewer.setContentProvider(contentProvider); - } - - public void testGetKnownElements_ExcludesInput() { - final Object input = new Object(); - Object[] rootElements = new Object[] { "one", "two", "three" }; - final IObservableList rootElementList = new WritableList(Arrays - .asList(rootElements), null); - createContentProvider(new IObservableFactory() { - public IObservable createObservable(Object target) { - if (target == input) - return rootElementList; - return null; - } - }); - viewer.setInput(input); - contentProvider.getElements(input); - - IObservableSet knownElements = contentProvider.getKnownElements(); - assertFalse(knownElements.contains(input)); - assertEquals(new HashSet(Arrays.asList(rootElements)), knownElements); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/ObservableViewerElementSetTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/ObservableViewerElementSetTest.java deleted file mode 100644 index ad54db7c..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/ObservableViewerElementSetTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 215531) - * Matthew Hall - bug 213145 - ******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.viewers; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.jface.databinding.conformance.MutableObservableSetContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; -import org.eclipse.jface.internal.databinding.viewers.ObservableViewerElementSet; -import org.eclipse.jface.viewers.IElementComparer; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class ObservableViewerElementSetTest extends TestCase { - public static Test suite() { - TestSuite suite = new TestSuite(ObservableViewerElementSetTest.class.getName()); - suite.addTest(MutableObservableSetContractTest.suite(new Delegate())); - return suite; - } - - private static class Delegate extends - AbstractObservableCollectionContractDelegate { - - public IObservableCollection createObservableCollection(Realm realm, - int elementCount) { - ObservableViewerElementSet set = new ObservableViewerElementSet(realm, - Object.class, new IdentityElementComparer()); - for (int i = 0; i < elementCount; i++) - set.add(createElement(set)); - return set; - } - - public Object createElement(IObservableCollection collection) { - return new Object(); - } - - public void change(IObservable observable) { - IObservableSet set = (IObservableSet) observable; - set.add(createElement(set)); - } - - public Object getElementType(IObservableCollection collection) { - return Object.class; - } - } - - private static class IdentityElementComparer implements IElementComparer { - public boolean equals(Object a, Object b) { - return a == b; - } - - public int hashCode(Object element) { - return System.identityHashCode(element); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/SelectionProviderMultiSelectionObservableListTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/SelectionProviderMultiSelectionObservableListTest.java deleted file mode 100644 index 0bbf6bf2..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/SelectionProviderMultiSelectionObservableListTest.java +++ /dev/null @@ -1,170 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Brad Reynolds. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Brad Reynolds - initial API and implementation - * Brad Reynolds - bug 116920 - *******************************************************************************/ -package org.eclipse.jface.tests.internal.databinding.viewers; - -import junit.framework.TestCase; - -import org.eclipse.core.databinding.observable.list.ListDiffEntry; -import org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.internal.databinding.viewers.SelectionProviderMultipleSelectionObservableList; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; - -/** - * Tests for SelectionProviderMultiSelectionObservableList. - * - * @since 1.2 - */ -public class SelectionProviderMultiSelectionObservableListTest extends TestCase { - private ISelectionProvider selectionProvider; - - private TableViewer viewer; - - private static String[] model = new String[] { "0", "1", "2", "3" }; - - protected void setUp() throws Exception { - Shell shell = new Shell(); - viewer = new TableViewer(shell, SWT.MULTI); - viewer.setContentProvider(new ContentProvider()); - viewer.setInput(model); - selectionProvider = viewer; - } - - protected void tearDown() throws Exception { - Shell shell = viewer.getTable().getShell(); - if (!shell.isDisposed()) - shell.dispose(); - } - - public void testConstructorIllegalArgumentException() { - try { - new SelectionProviderMultipleSelectionObservableList(SWTObservables - .getRealm(Display.getDefault()), null, Object.class); - fail(); - } catch (IllegalArgumentException e) { - } - } - - /** - * Asserts that when a selection is set on the viewer: - * <ul> - * <li>the selection is available in the observable</li> - * <li>Value change events are fired with appropriate diff values</li> - * </ul> - */ - public void testAddRemove() { - SelectionProviderMultipleSelectionObservableList observable = new SelectionProviderMultipleSelectionObservableList( - SWTObservables.getRealm(Display.getDefault()), - selectionProvider, Object.class); - ListChangeEventTracker listener = new ListChangeEventTracker(); - observable.addListChangeListener(listener); - assertEquals(0, observable.size()); - - selectionProvider.setSelection(new StructuredSelection(model[0])); - assertEquals(1, listener.count); - assertEquals(1, listener.event.diff.getDifferences().length); - assertDiffEntry(listener.event.diff.getDifferences()[0], 0, model[0], true); - assertEquals(observable, listener.event.getObservableList()); - assertEquals(1, observable.size()); - assertEquals(model[0], observable.get(0)); - - selectionProvider.setSelection(new StructuredSelection(model[1])); - assertEquals(2, listener.count); - assertEquals(2, listener.event.diff.getDifferences().length); - assertDiffEntry(listener.event.diff.getDifferences()[0], 0, model[1], true); - assertDiffEntry(listener.event.diff.getDifferences()[1], 1, model[0], false); - assertEquals(observable, listener.event.getObservableList()); - assertEquals(1, observable.size()); - assertEquals(model[1], observable.get(0)); - - selectionProvider.setSelection(new StructuredSelection(new Object[]{model[2],model[3]})); - assertEquals(3, listener.count); - assertEquals(3, listener.event.diff.getDifferences().length); - assertDiffEntry(listener.event.diff.getDifferences()[0], 0, model[2], true); - assertDiffEntry(listener.event.diff.getDifferences()[1], 1, model[3], true); - assertDiffEntry(listener.event.diff.getDifferences()[2], 2, model[1], false); - assertEquals(observable, listener.event.getObservableList()); - assertEquals(2, observable.size()); - assertEquals(model[2], observable.get(0)); - assertEquals(model[3], observable.get(1)); - - selectionProvider.setSelection(StructuredSelection.EMPTY); - assertEquals(4, listener.count); - assertEquals(2, listener.event.diff.getDifferences().length); - assertDiffEntry(listener.event.diff.getDifferences()[0], 1, model[3], false); - assertDiffEntry(listener.event.diff.getDifferences()[1], 0, model[2], false); - assertEquals(observable, listener.event.getObservableList()); - assertEquals(0, observable.size()); - - observable.add(model[1]); - assertEquals(5, listener.count); - assertEquals(1, listener.event.diff.getDifferences().length); - assertDiffEntry(listener.event.diff.getDifferences()[0], 0, model[1], true); - assertEquals(observable, listener.event.getObservableList()); - assertEquals(1, ((IStructuredSelection)viewer.getSelection()).size()); - - observable.add(0, model[2]); - assertEquals(6, listener.count); - assertEquals(1, listener.event.diff.getDifferences().length); - // This is a bit surprising (we added at index 0 but the event says index 1). - // It is to the fact that the observable list tracks the underlying selection - // provider's notion of which element is at which index. - assertDiffEntry(listener.event.diff.getDifferences()[0], 1, model[2], true); - assertEquals(observable, listener.event.getObservableList()); - assertEquals(2, ((IStructuredSelection)viewer.getSelection()).size()); - - observable.clear(); - assertEquals(7, listener.count); - assertEquals(2, listener.event.diff.getDifferences().length); - assertDiffEntry(listener.event.diff.getDifferences()[0], 1, model[2], false); - assertDiffEntry(listener.event.diff.getDifferences()[1], 0, model[1], false); - assertEquals(observable, listener.event.getObservableList()); - assertEquals(0, ((IStructuredSelection)viewer.getSelection()).size()); -} - - /** - * @param diffEntry - * @param position - * @param element - * @param isAddition - */ - private void assertDiffEntry(ListDiffEntry diffEntry, int position, - String element, boolean isAddition) { - assertEquals(isAddition, diffEntry.isAddition()); - assertEquals(position, diffEntry.getPosition()); - assertEquals(element, diffEntry.getElement()); - } - - private class ContentProvider implements IStructuredContentProvider { - public void dispose() { - // TODO Auto-generated method stub - - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - // TODO Auto-generated method stub - - } - - public Object[] getElements(Object inputElement) { - return (String[]) inputElement; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/SelectionProviderSingleSelectionObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/SelectionProviderSingleSelectionObservableValueTest.java deleted file mode 100644 index a5abde82..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/SelectionProviderSingleSelectionObservableValueTest.java +++ /dev/null @@ -1,147 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Brad Reynolds. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Brad Reynolds - initial API and implementation - * Brad Reynolds - bug 116920 - * Ashley Cambrell - bug 198906 - *******************************************************************************/ -package org.eclipse.jface.tests.internal.databinding.viewers; - -import junit.framework.TestCase; - -import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.internal.databinding.viewers.SelectionProviderSingleSelectionObservableValue; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; - -/** - * Tests for SelectionProviderSingleSelectionObservableValue. - * - * @since 1.1 - */ -public class SelectionProviderSingleSelectionObservableValueTest extends - TestCase { - private ISelectionProvider selectionProvider; - - private TableViewer viewer; - - private static String[] model = new String[] { "0", "1" }; - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - Shell shell = new Shell(); - viewer = new TableViewer(shell, SWT.NONE); - viewer.setContentProvider(new ContentProvider()); - viewer.setInput(model); - selectionProvider = viewer; - } - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#tearDown() - */ - protected void tearDown() throws Exception { - Shell shell = viewer.getTable().getShell(); - if (!shell.isDisposed()) - shell.dispose(); - } - - public void testConstructorIllegalArgumentException() { - try { - new SelectionProviderSingleSelectionObservableValue(SWTObservables - .getRealm(Display.getDefault()), null); - fail(); - } catch (IllegalArgumentException e) { - } - } - - /** - * Asserts that when a selection is set on the viewer: - * <ul> - * <li>the selection is available in the observable</li> - * <li>Value change events are fired with appropriate diff values</li> - * </ul> - */ - public void testGetSetValue() { - SelectionProviderSingleSelectionObservableValue observable = new SelectionProviderSingleSelectionObservableValue( - SWTObservables.getRealm(Display.getDefault()), - selectionProvider); - ValueChangeEventTracker listener = new ValueChangeEventTracker(); - observable.addValueChangeListener(listener); - assertNull(observable.getValue()); - - selectionProvider.setSelection(new StructuredSelection(model[0])); - assertEquals(1, listener.count); - assertNull(listener.event.diff.getOldValue()); - assertEquals(model[0], listener.event.diff.getNewValue()); - assertEquals(observable, listener.event.getObservableValue()); - assertEquals(model[0], observable.getValue()); - - selectionProvider.setSelection(new StructuredSelection(model[1])); - assertEquals(2, listener.count); - assertEquals(model[0], listener.event.diff.getOldValue()); - assertEquals(model[1], listener.event.diff.getNewValue()); - assertEquals(observable, listener.event.getObservableValue()); - assertEquals(model[1], observable.getValue()); - - selectionProvider.setSelection(StructuredSelection.EMPTY); - assertEquals(3, listener.count); - assertEquals(model[1], listener.event.diff.getOldValue()); - assertNull(listener.event.diff.getNewValue()); - assertEquals(observable, listener.event.getObservableValue()); - assertEquals(null, observable.getValue()); - } - - public void testDispose() throws Exception { - SelectionProviderSingleSelectionObservableValue observable = new SelectionProviderSingleSelectionObservableValue( - SWTObservables.getRealm(Display.getDefault()), - selectionProvider); - ValueChangeEventTracker listener = new ValueChangeEventTracker(); - observable.addValueChangeListener(listener); - - selectionProvider.setSelection(new StructuredSelection(model[0])); - assertEquals(1, listener.count); - assertNull(listener.event.diff.getOldValue()); - assertEquals(model[0], listener.event.diff.getNewValue()); - assertEquals(observable, listener.event.getObservableValue()); - assertEquals(model[0], observable.getValue()); - - observable.dispose(); - selectionProvider.setSelection(new StructuredSelection(model[1])); - assertEquals(1, listener.count); - } - - private class ContentProvider implements IStructuredContentProvider { - public void dispose() { - // TODO Auto-generated method stub - - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - // TODO Auto-generated method stub - - } - - public Object[] getElements(Object inputElement) { - return (String[]) inputElement; - } - } - -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/ViewerElementMapTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/ViewerElementMapTest.java deleted file mode 100644 index 1aece17c..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/ViewerElementMapTest.java +++ /dev/null @@ -1,535 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 215531) - * Matthew Hall - bug 228125 - ******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.viewers; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.eclipse.jface.internal.databinding.viewers.ViewerElementMap; -import org.eclipse.jface.viewers.IElementComparer; - -import junit.framework.TestCase; - -/** - * @since 1.2 - */ -public class ViewerElementMapTest extends TestCase { - IdentityElementComparer comparer; - ViewerElementMap map; - - Object key; - Object value; - - protected void setUp() throws Exception { - super.setUp(); - comparer = new IdentityElementComparer(); - map = new ViewerElementMap(comparer); - key = new Object(); - value = new Object(); - } - - public void testConstructor_NullComparer() { - try { - new ViewerElementMap(null); - fail("Constructor should throw exception when null comparer passed in"); - } catch (RuntimeException expected) { - } - } - - public void testConstructorWithCollection_NullCollection() { - try { - new ViewerElementMap(null, new IdentityElementComparer()); - fail("Constructor should throw exception when null collection passed in"); - } catch (RuntimeException expected) { - } - } - - public void testConstructorWithCollection_ContainsAllEntries() { - Map toCopy = new HashMap(); - toCopy.put(new Object(), new Object()); - map = new ViewerElementMap(toCopy, new IdentityElementComparer()); - assertEquals(toCopy, map); - } - - public void testIsEmpty() { - assertTrue(map.isEmpty()); - map.put(key, value); - assertFalse(map.isEmpty()); - } - - public void testSize() { - assertEquals(0, map.size()); - map.put(key, value); - assertEquals(1, map.size()); - } - - public void testClear() { - map.put(key, value); - assertFalse(map.isEmpty()); - map.clear(); - assertTrue(map.isEmpty()); - } - - public void testGet() { - assertNull(map.get(key)); - map.put(key, value); - assertEquals(value, map.get(key)); - } - - public void testContainsKey() { - String key1 = new String("key"); - String key2 = new String("key"); // equal but distinct instances - assertFalse(map.containsKey(key1)); - map.put(key1, value); - assertTrue(map.containsKey(key1)); - assertFalse(map.containsKey(key2)); - } - - public void testContainsValue() { - assertFalse(map.containsValue(value)); - map.put(key, value); - assertTrue(map.containsValue(value)); - } - - public void testPutAll() { - Map other = new HashMap(); - other.put(key, value); - - assertTrue(map.isEmpty()); - map.putAll(other); - assertEquals(1, map.size()); - assertTrue(map.containsKey(key)); - assertEquals(value, map.get(key)); - } - - public void testRemove() { - map.put(key, value); - assertTrue(map.containsKey(key)); - map.remove(key); - assertFalse(map.containsKey(key)); - } - - public void testValues() { - Collection values = map.values(); - assertTrue(values.isEmpty()); - - map.put(key, value); - - assertEquals(1, values.size()); - assertEquals(value, values.iterator().next()); - - map.remove(key); - assertTrue(map.values().isEmpty()); - } - - public void testKeySet() { - Set keySet = map.keySet(); - assertTrue(keySet.isEmpty()); - - map.put(key, value); - assertEquals(1, keySet.size()); - assertTrue(keySet.contains(key)); - - map.remove(key); - assertTrue(keySet.isEmpty()); - } - - public void testKeySet_Add() { - try { - map.keySet().add(key); - fail("Expected UnsupportedOperationException"); - } catch (UnsupportedOperationException expected) { - } - } - - public void testKeySet_AddAll() { - try { - map.keySet().addAll(Collections.singleton(key)); - fail("Expected UnsupportedOperationException"); - } catch (UnsupportedOperationException expected) { - } - } - - public void testKeySet_Clear() { - map.put(key, value); - Set keySet = map.keySet(); - assertTrue(keySet.contains(key)); - keySet.clear(); - assertTrue(keySet.isEmpty()); - assertTrue(map.isEmpty()); - } - - public void testKeySet_Contains() { - Set keySet = map.keySet(); - assertFalse(keySet.contains(key)); - map.put(key, value); - assertTrue(keySet.contains(key)); - } - - public void testKeySet_ContainsAll() { - Set keySet = map.keySet(); - assertFalse(keySet.containsAll(Collections.singleton(key))); - map.put(key, value); - assertTrue(keySet.containsAll(Collections.singleton(key))); - } - - public void testKeySet_IsEmpty() { - Set keySet = map.keySet(); - assertTrue(keySet.isEmpty()); - map.put(key, value); - assertFalse(keySet.isEmpty()); - } - - public void testKeySet_Iterator() { - map.put(key, value); - Iterator iterator = map.keySet().iterator(); - assertTrue(iterator.hasNext()); - assertEquals(key, iterator.next()); - - assertEquals(1, map.size()); - iterator.remove(); - assertTrue(map.isEmpty()); - - assertFalse(iterator.hasNext()); - } - - public void testKeySet_Remove() { - map.put(key, value); - assertEquals(1, map.size()); - map.keySet().remove(key); - assertTrue(map.isEmpty()); - } - - public void testKeySet_RemoveAll() { - map.put(key, value); - Set keySet = map.keySet(); - assertFalse(keySet.removeAll(Collections.EMPTY_SET)); - assertEquals(1, map.size()); - assertTrue(keySet.removeAll(Collections.singleton(key))); - assertTrue(map.isEmpty()); - } - - public void testKeySet_RetainAll() { - map.put(key, value); - Set keySet = map.keySet(); - assertFalse(keySet.retainAll(Collections.singleton(key))); - assertEquals(1, map.size()); - assertTrue(keySet.retainAll(Collections.EMPTY_SET)); - assertTrue(map.isEmpty()); - } - - public void testKeySet_Size() { - Set keySet = map.keySet(); - assertEquals(0, keySet.size()); - map.put(key, value); - assertEquals(1, keySet.size()); - map.clear(); - assertEquals(0, keySet.size()); - } - - public void testKeySet_ToArray() { - Set keySet = map.keySet(); - map.put(key, value); - Object[] array = keySet.toArray(); - assertEquals(1, array.length); - assertSame(key, array[0]); - } - - public void testKeySet_ToArrayWithObjectArray() { - key = new String("key"); - map.put(key, value); - String[] array = (String[]) map.keySet().toArray(new String[0]); - assertEquals(1, array.length); - assertSame(key, array[0]); - } - - public void testKeySet_Equals() { - Set keySet = map.keySet(); - assertFalse(keySet.equals(null)); - assertTrue(keySet.equals(keySet)); - - assertTrue(keySet.equals(Collections.EMPTY_SET)); - map.put(key, value); - assertTrue(keySet.equals(Collections.singleton(key))); - } - - public void testKeySet_HashCode() { - Set keySet = map.keySet(); - assertEquals(0, keySet.hashCode()); - map.put(key, value); - int hash = comparer.hashCode(key); - assertEquals(hash, keySet.hashCode()); - } - - public void testEntrySet() { - Set entrySet = map.entrySet(); - assertTrue(entrySet.isEmpty()); - - map.put(key, value); - assertEquals(1, entrySet.size()); - Map.Entry entry = (Map.Entry) entrySet.iterator().next(); - assertEquals(key, entry.getKey()); - assertEquals(value, entry.getValue()); - - map.remove(key); - assertTrue(entrySet.isEmpty()); - } - - public void testEntrySet_Add() { - try { - map.entrySet().add(key); - fail("Expected UnsupportedOperationException"); - } catch (UnsupportedOperationException expected) { - } - } - - public void testEntrySet_AddAll() { - try { - map.entrySet().addAll(Collections.EMPTY_SET); - fail("Expected UnsupportedOperationException"); - } catch (UnsupportedOperationException expected) { - } - } - - public void testEntrySet_Clear() { - map.put(key, value); - assertEquals(1, map.size()); - map.entrySet().clear(); - assertTrue(map.isEmpty()); - } - - public void testEntrySet_Contains() { - map.put(key, value); - Set entrySet = map.entrySet(); - assertTrue(entrySet.contains(new MapEntryStub(key, value))); - map.remove(key); - assertFalse(entrySet.contains(new MapEntryStub(key, value))); - } - - public void testEntrySet_ContainsAll() { - Set entrySet = map.entrySet(); - assertFalse(entrySet.containsAll(Collections - .singleton(new MapEntryStub(key, value)))); - assertTrue(entrySet.containsAll(Collections.EMPTY_SET)); - - map.put(key, value); - assertTrue(entrySet.containsAll(Collections.singleton(new MapEntryStub( - key, value)))); - } - - public void testEntrySet_IsEmpty() { - Set entrySet = map.entrySet(); - assertTrue(entrySet.isEmpty()); - map.put(key, value); - assertFalse(entrySet.isEmpty()); - } - - public void testEntrySet_Iterator() { - map.put(key, value); - Iterator iterator = map.entrySet().iterator(); - assertTrue(iterator.hasNext()); - Map.Entry entry = (Map.Entry) iterator.next(); - assertTrue(entry.equals(new MapEntryStub(key, value))); - - assertEquals(1, map.size()); - iterator.remove(); - assertTrue(map.isEmpty()); - assertFalse(iterator.hasNext()); - } - - public void testEntrySet_Remove() { - map.put(key, value); - assertEquals(1, map.size()); - - assertTrue(map.entrySet().remove(new MapEntryStub(key, value))); - assertTrue(map.isEmpty()); - } - - public void testEntrySet_RemoveAll() { - Set entrySet = map.entrySet(); - assertFalse(entrySet.removeAll(Collections.EMPTY_SET)); - - map.put(key, value); - assertEquals(1, map.size()); - assertTrue(entrySet.removeAll(Collections.singleton(new MapEntryStub( - key, value)))); - assertTrue(map.isEmpty()); - } - - public void testEntrySet_RetainAll() { - Set entrySet = map.entrySet(); - assertFalse(entrySet.retainAll(Collections.EMPTY_SET)); - - map.put(key, value); - assertEquals(1, map.size()); - assertFalse(entrySet.retainAll(Collections.singleton(new MapEntryStub( - key, value)))); - assertEquals(1, map.size()); - assertTrue(entrySet.retainAll(Collections.EMPTY_SET)); - assertTrue(map.isEmpty()); - } - - public void testEntrySet_Size() { - Set entrySet = map.entrySet(); - assertEquals(0, entrySet.size()); - map.put(key, value); - assertEquals(1, entrySet.size()); - } - - public void testEntrySet_ToArray() { - Set entrySet = map.entrySet(); - assertEquals(0, entrySet.toArray().length); - - map.put(key, value); - Object[] array = entrySet.toArray(); - assertEquals(1, array.length); - assertTrue(array[0].equals(new MapEntryStub(key, value))); - } - - public void testEntrySet_ToArrayWithObjectArray() { - Set entrySet = map.entrySet(); - assertEquals(0, entrySet.toArray(new Object[0]).length); - - map.put(key, value); - Map.Entry[] array = (Map.Entry[]) entrySet.toArray(new Map.Entry[0]); - assertEquals(1, array.length); - assertTrue(array[0].equals(new MapEntryStub(key, value))); - } - - public void testEntrySet_Equals() { - Set entrySet = map.entrySet(); - assertFalse(entrySet.equals(null)); - assertTrue(entrySet.equals(entrySet)); - - assertTrue(entrySet.equals(Collections.EMPTY_SET)); - assertFalse(entrySet.equals(Collections.singleton(new MapEntryStub(key, - value)))); - - map.put(key, value); - assertFalse(entrySet.equals(Collections.EMPTY_SET)); - assertTrue(entrySet.equals(Collections.singleton(new MapEntryStub(key, - value)))); - } - - public void testEntrySet_HashCode() { - // hash formula mandated by Map contract - Set entrySet = map.entrySet(); - assertEquals(0, entrySet.hashCode()); - - map.put(key, value); - int hash = comparer.hashCode(key) ^ value.hashCode(); - assertEquals(hash, entrySet.hashCode()); - } - - public void testEntrySet_Entry_SetValue() { - map.put(key, value); - - Map.Entry entry = (Map.Entry) map.entrySet().iterator().next(); - - Object newValue = new Object(); - Object oldValue = entry.setValue(newValue); - assertEquals(value, oldValue); - assertEquals(newValue, entry.getValue()); - assertEquals(newValue, map.get(key)); - } - - public void testEntrySet_Entry_Equals() { - map.put(key, value); - - Map.Entry entry = (Map.Entry) map.entrySet().iterator().next(); - assertFalse(entry.equals(null)); - assertTrue(entry.equals(entry)); - assertTrue(entry.equals(new MapEntryStub(key, value))); - } - - public void testEntrySet_Entry_HashCode() { - map.put(key, value); - - // hash computed as required by Map contract - int hash = comparer.hashCode(key) ^ value.hashCode(); - assertEquals(hash, map.entrySet().iterator().next().hashCode()); - } - - public void testEquals() { - assertFalse(map.equals(null)); - assertTrue(map.equals(map)); - - Map other = new HashMap(); - other.put(key, value); - - assertTrue(map.equals(Collections.EMPTY_MAP)); - assertFalse(map.equals(other)); - - map.put(key, value); - - assertFalse(map.equals(Collections.EMPTY_MAP)); - assertTrue(map.equals(other)); - } - - public void testHashCode() { - assertEquals(0, map.hashCode()); - - map.put(key, value); - int hash = comparer.hashCode(key) ^ value.hashCode(); - assertEquals(hash, map.hashCode()); - } - - public void testWithComparer() { - assertFalse(ViewerElementMap.withComparer(null) instanceof ViewerElementMap); - assertTrue(ViewerElementMap.withComparer(comparer) instanceof ViewerElementMap); - } - - static class IdentityElementComparer implements IElementComparer { - public boolean equals(Object a, Object b) { - return a == b; - } - - public int hashCode(Object element) { - return System.identityHashCode(element); - } - } - - static class MapEntryStub implements Map.Entry { - private final Object key; - private final Object value; - - public MapEntryStub(Object key, Object value) { - this.key = key; - this.value = value; - } - - public Object getKey() { - return key; - } - - public Object getValue() { - return value; - } - - public Object setValue(Object value) { - throw new UnsupportedOperationException(); - } - - public boolean equals(Object obj) { - throw new UnsupportedOperationException(); - } - - public int hashCode() { - throw new UnsupportedOperationException(); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/ViewerElementSetTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/ViewerElementSetTest.java deleted file mode 100644 index 4d4a55b8..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/ViewerElementSetTest.java +++ /dev/null @@ -1,238 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 215531) - ******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.viewers; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; - -import org.eclipse.jface.internal.databinding.viewers.ViewerElementSet; -import org.eclipse.jface.viewers.IElementComparer; - -import junit.framework.TestCase; - -/** - * @since 1.2 - */ -public class ViewerElementSetTest extends TestCase { - IdentityElementComparer comparer; - ViewerElementSet set; - - protected void setUp() throws Exception { - super.setUp(); - comparer = new IdentityElementComparer(); - set = new ViewerElementSet(comparer); - } - - public void testConstructor_NullComparer() { - try { - new ViewerElementSet(null); - fail("Constructor should throw exception when null comparer passed in"); - } catch (RuntimeException expected) { - } - } - - public void testConstructorWithCollection_NullCollection() { - try { - new ViewerElementSet(null, new IdentityElementComparer()); - fail("Constructor should throw exception when null collection passed in"); - } catch (RuntimeException expected) {} - } - - public void testConstructorWithCollection_AddsAllElements() { - Collection toCopy = Collections.singleton(new Object()); - set = new ViewerElementSet(toCopy, new IdentityElementComparer()); - assertTrue(set.containsAll(toCopy)); - } - - public void testAdd_ContainsHonorsComparer() { - Object o1 = new String("string"); - Object o2 = new String("string"); // distinct instances - assertTrue(o1.equals(o2)); - assertNotSame(o1, o2); - - assertTrue(set.add(o1)); - - assertTrue(set.contains(o1)); - assertFalse(set.contains(o2)); - } - - public void testAdd_FilterDuplicateElements() { - Object o = new Object(); - - assertTrue(set.add(o)); - assertFalse(set.add(o)); // no change--element already in set - - assertEquals(1, set.size()); - assertTrue(set.contains(o)); - } - - public void testAddAll_ContainsAllHonorsComparer() { - String o1 = new String("o1"); - String o2 = new String("o2"); - Collection items = Arrays.asList(new Object[] { o1, o2 }); - assertTrue(set.addAll(items)); - - assertTrue(set.containsAll(items)); - assertFalse(set.containsAll(Collections.singleton(new String("o1")))); - assertFalse(set.containsAll(Collections.singleton(new String("o2")))); - } - - public void testAddAll_FiltersDuplicateElements() { - Object o = new Object(); - set.add(o); - - assertFalse(set.addAll(Collections.singleton(o))); - } - - public void testClear() { - set.add(new Object()); - assertEquals(1, set.size()); - - set.clear(); - assertEquals(0, set.size()); - } - - public void testIsEmpty() { - assertTrue(set.isEmpty()); - set.add(new Object()); - assertFalse(set.isEmpty()); - } - - public void testIterator() { - Object o = new Object(); - set.add(o); - - Iterator iterator = set.iterator(); - assertTrue(iterator.hasNext()); - assertSame(o, iterator.next()); - - assertTrue(set.contains(o)); - iterator.remove(); - assertFalse(set.contains(o)); - - assertFalse(iterator.hasNext()); - } - - public void testRemove() { - Object o = new Object(); - assertFalse(set.remove(o)); - - assertTrue(set.add(o)); - assertTrue(set.contains(o)); - assertTrue(set.remove(o)); - - assertFalse(set.contains(o)); - } - - public void testRemoveAll() { - assertFalse(set.removeAll(Collections.EMPTY_SET)); - - Object o1 = new Object(); - Object o2 = new Object(); - set.addAll(Arrays.asList(new Object[] { o1, o2 })); - - assertTrue(set.removeAll(Collections.singleton(o1))); - assertFalse(set.contains(o1)); - assertFalse(set.removeAll(Collections.singleton(o1))); - - assertTrue(set.removeAll(Arrays.asList(new Object[] { o2, "some", - "other", "objects" }))); - assertFalse(set.contains(o2)); - } - - public void testRetainAll() { - Object o1 = new Object(); - Object o2 = new Object(); - set.add(o1); - set.add(o2); - - assertFalse(set.retainAll(Arrays.asList(new Object[] { o1, o2 }))); // no - // change - - assertTrue(set.contains(o2)); - assertTrue(set.retainAll(Collections.singleton(o1))); - assertFalse(set.contains(o2)); - - assertTrue(set.contains(o1)); - assertTrue(set.retainAll(Collections.EMPTY_SET)); - assertFalse(set.contains(o1)); - } - - public void testSize() { - assertEquals(0, set.size()); - - Object o = new Object(); - set.add(o); - assertEquals(1, set.size()); - - set.remove(o); - assertEquals(0, set.size()); - } - - public void testToArray() { - assertEquals(0, set.toArray().length); - - Object o = new Object(); - set.add(o); - assertTrue(Arrays.equals(new Object[] { o }, set.toArray())); - } - - public void testToArrayWithObjectArray() { - Object o = new String("unique"); - set.add(o); - - String[] array = (String[]) set.toArray(new String[0]); - assertEquals(1, array.length); - assertSame(o, array[0]); - } - - public void testEquals() { - assertTrue(set.equals(set)); - assertFalse(set.equals(null)); - assertFalse(set.equals(new Object())); - - assertTrue(set.equals(Collections.EMPTY_SET)); - - Object o = new String("string"); - Object distinct = new String("string"); - set.add(o); - assertTrue(set.equals(Collections.singleton(o))); - assertFalse(set.equals(Collections.singleton(distinct))); - } - - public void testHashCode() { - // Hash code implementation is mandated - assertEquals(0, set.hashCode()); - - Object o = new Object(); - set.add(o); - int hash = comparer.hashCode(o); - assertEquals(hash, set.hashCode()); - - Object o2 = new Object(); - set.add(o2); - hash += comparer.hashCode(o2); - assertEquals(hash, set.hashCode()); - } - - static class IdentityElementComparer implements IElementComparer { - public boolean equals(Object a, Object b) { - return a == b; - } - - public int hashCode(Object element) { - return System.identityHashCode(element); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/ViewerElementWrapperTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/ViewerElementWrapperTest.java deleted file mode 100644 index f85d811f..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/ViewerElementWrapperTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.viewers; - -import org.eclipse.jface.internal.databinding.viewers.ViewerElementWrapper; -import org.eclipse.jface.viewers.IElementComparer; - -import junit.framework.TestCase; - -/** - * @since 3.2 - * - */ -public class ViewerElementWrapperTest extends TestCase { - private ViewerElementWrapper wrapper; - private Object element; - private IElementComparer comparer; - - protected void setUp() throws Exception { - super.setUp(); - element = new ElementStub(0); - comparer = new IdentityElementComparer(); - wrapper = new ViewerElementWrapper(element, comparer); - } - - public void testConstructor_NullComparer() { - try { - new ViewerElementWrapper(element, null); - fail("Expected NullPointerException"); - } catch (NullPointerException expected) { - } - } - - public void testEquals() { - assertFalse(wrapper.equals(null)); - assertTrue(wrapper.equals(wrapper)); - assertTrue(wrapper.equals(new ViewerElementWrapper(element, comparer))); - } - - public void testHashCode() { - int hash = 0; - element = new ElementStub(hash); - wrapper = new ViewerElementWrapper(element, comparer); - assertEquals(System.identityHashCode(element), wrapper.hashCode()); - assertEquals(hash, element.hashCode()); - } - - static class ElementStub { - private final int hash; - - public ElementStub(int hash) { - this.hash = hash; - } - - public boolean equals(Object obj) { - if (obj == this) - return true; - if (obj == null) - return false; - if (obj.getClass() != getClass()) - return false; - ElementStub that = (ElementStub) obj; - return this.hash == that.hash; - } - - public int hashCode() { - return hash; - } - } - - static class IdentityElementComparer implements IElementComparer { - public boolean equals(Object a, Object b) { - return a == b; - } - - public int hashCode(Object element) { - return System.identityHashCode(element); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/ViewerInputObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/ViewerInputObservableValueTest.java deleted file mode 100644 index 6161721a..00000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/ViewerInputObservableValueTest.java +++ /dev/null @@ -1,184 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Matthew Hall 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: - * Matthew Hall - initial API and implementation (bug 206839) - * Matthew Hall - bug 213145 - *******************************************************************************/ -package org.eclipse.jface.tests.internal.databinding.viewers; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.ValueChangeEvent; -import org.eclipse.jface.databinding.conformance.MutableObservableValueContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; -import org.eclipse.jface.internal.databinding.viewers.ViewerInputObservableValue; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Shell; - -/** - * Tests for ViewerInputObservableValue. - * - * @since 1.2 - */ -public class ViewerInputObservableValueTest extends - AbstractDefaultRealmTestCase { - private TableViewer viewer; - private static String[] model = new String[] { "0", "1" }; - - protected void setUp() throws Exception { - super.setUp(); - Shell shell = new Shell(); - viewer = new TableViewer(shell, SWT.NONE); - viewer.setContentProvider(new ContentProvider()); - } - - protected void tearDown() throws Exception { - Shell shell = viewer.getTable().getShell(); - if (!shell.isDisposed()) - shell.dispose(); - super.tearDown(); - } - - public void testConstructor_IllegalArgumentException() { - try { - new ViewerInputObservableValue(Realm.getDefault(), null); - fail("Expected IllegalArgumentException for null argument"); - } catch (IllegalArgumentException expected) { - } - } - - public void testSetInputOnViewer_FiresNoChangeEvents() { - IObservableValue observable = new ViewerInputObservableValue(Realm - .getDefault(), viewer); - ValueChangeEventTracker listener = ValueChangeEventTracker.observe(observable); - - assertNull(viewer.getInput()); - assertEquals(0, listener.count); - - viewer.setInput(model); - - assertEquals(model, observable.getValue()); - assertEquals(0, listener.count); - - viewer.setInput(null); - - assertEquals(null, observable.getValue()); - assertEquals(0, listener.count); - } - - public void testGetSetValue_FiresChangeEvents() { - IObservableValue observable = new ViewerInputObservableValue(Realm - .getDefault(), viewer); - ValueChangeEventTracker listener = new ValueChangeEventTracker(); - observable.addValueChangeListener(listener); - - assertNull(observable.getValue()); - assertEquals(0, listener.count); - - observable.setValue(model); - - assertEquals(model, observable.getValue()); - assertEquals(1, listener.count); - assertValueChangeEventEquals(observable, null, model, listener.event); - - observable.setValue(null); - - assertNull(observable.getValue()); - assertEquals(2, listener.count); - assertValueChangeEventEquals(observable, model, null, listener.event); - } - - public void testGetValueType_AlwaysNull() throws Exception { - IObservableValue observable = new ViewerInputObservableValue(Realm - .getDefault(), viewer); - assertEquals(null, observable.getValueType()); - } - - public void testDispose() throws Exception { - IObservableValue observable = new ViewerInputObservableValue(Realm - .getDefault(), viewer); - observable.dispose(); - assertNull(observable.getRealm()); - try { - observable.setValue(model); - fail("Expected NullPointerException"); - } catch (NullPointerException expected) { - } - } - - private void assertValueChangeEventEquals( - IObservableValue expectedObservable, Object expectedOldValue, - Object expectedNewValue, ValueChangeEvent event) { - assertSame(expectedObservable, event.getObservableValue()); - assertEquals(expectedOldValue, event.diff.getOldValue()); - assertEquals(expectedNewValue, event.diff.getNewValue()); - } - - static class ContentProvider implements IStructuredContentProvider { - public void dispose() { - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - - public Object[] getElements(Object inputElement) { - return (String[]) inputElement; - } - } - - public static Test suite() { - TestSuite suite = new TestSuite(ViewerInputObservableValueTest.class.getName()); - suite.addTestSuite(ViewerInputObservableValueTest.class); - suite.addTest(MutableObservableValueContractTest.suite(new Delegate())); - return suite; - } - - static class Delegate extends AbstractObservableValueContractDelegate { - TableViewer viewer; - - public void setUp() { - super.setUp(); - Shell shell = new Shell(); - viewer = new TableViewer(shell, SWT.NONE); - viewer.setContentProvider(new ContentProvider()); - } - - public void tearDown() { - Shell shell = viewer.getTable().getShell(); - if (!shell.isDisposed()) - shell.dispose(); - super.tearDown(); - } - - public IObservableValue createObservableValue(Realm realm) { - return new ViewerInputObservableValue(realm, viewer); - } - - public void change(IObservable observable) { - IObservableValue value = (IObservableValue)observable; - value.setValue(createValue(value)); - } - - public Object createValue(IObservableValue observable) { - return new String[] { "one", "two" }; - } - - public Object getValueType(IObservableValue observable) { - return null; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/test.xml b/tests/org.eclipse.jface.tests.databinding/test.xml deleted file mode 100644 index 73284d59..00000000 --- a/tests/org.eclipse.jface.tests.databinding/test.xml +++ /dev/null @@ -1,50 +0,0 @@ -<?xml version="1.0"?> - -<project name="testsuite" default="run" basedir="."> - <!-- The property ${eclipse-home} should be passed into this script --> - <!-- Set a meaningful default value for when it is not. --> - <property name="eclipse-home" value="${basedir}\..\.."/> - - <!-- sets the properties eclipse-home, and library-file --> - <property name="plugin-name" value="org.eclipse.jface.tests.databinding"/> - <property name="library-file" - value="${eclipse-home}/plugins/org.eclipse.test/library.xml"/> - - <!-- This target holds all initialization code that needs to be done for --> - <!-- all tests that are to be run. Initialization for individual tests --> - <!-- should be done within the body of the suite target. --> - <target name="init"> - <tstamp/> - <delete> - <fileset dir="${eclipse-home}" includes="org*.xml"/> - </delete> - </target> - - <!-- This target defines the tests that need to be run. --> - <target name="suite"> - <property name="sniff-folder" - value="${eclipse-home}/databinding_sniff_folder"/> - <delete dir="${sniff-folder}" quiet="true"/> - <ant target="core-test" antfile="${library-file}" dir="${eclipse-home}"> - <property name="data-dir" value="${sniff-folder}"/> - <property name="plugin-name" value="${plugin-name}"/> - <property name="classname" - value="org.eclipse.jface.tests.databinding.BindingTestSuite"/> - </ant> - </target> - - <!-- This target holds code to cleanup the testing environment after --> - <!-- after all of the tests have been run. You can use this target to --> - <!-- delete temporary files that have been created. --> - <target name="cleanup"> - </target> - - <!-- This target runs the test suite. Any actions that need to happen --> - <!-- after all the tests have been run should go here. --> - <target name="run" depends="init,suite,cleanup"> - <ant target="collect" antfile="${library-file}" dir="${eclipse-home}"> - <property name="includes" value="org*.xml"/> - <property name="output-file" value="${plugin-name}.xml"/> - </ant> - </target> -</project> |