diff options
Diffstat (limited to 'bundles/org.eclipse.wst.xml.ui')
301 files changed, 0 insertions, 43672 deletions
diff --git a/bundles/org.eclipse.wst.xml.ui/.classpath b/bundles/org.eclipse.wst.xml.ui/.classpath deleted file mode 100644 index 9d03c22865..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/.classpath +++ /dev/null @@ -1,66 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" path="src" /> - <classpathentry kind="src" path="src-validation" /> - <classpathentry kind="src" path="src-multipage" /> - <classpathentry kind="src" path="src-wizards" /> - <classpathentry kind="src" path="src-catalog" /> - <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"> - <accessrules> - <accessrule kind="accessible" - pattern="org/eclipse/wst/validation/internal/core/ValidationException" /> - <accessrule kind="accessible" - pattern="org/eclipse/wst/validation/internal/operations/LocalizedMessage/" /> - <accessrule kind="accessible" - pattern="org/eclipse/wst/validation/internal/provisional/core/IMessage" /> - <accessrule kind="accessible" - pattern="org/eclipse/wst/validation/internal/core/Message" /> - <accessrule kind="accessible" - pattern="org/eclipse/wst/validation/internal/provisional/core/IReporter" /> - <accessrule kind="accessible" - pattern="org/eclipse/wst/validation/internal/provisional/core/IValidationContext" /> - <accessrule kind="accessible" - pattern="org/eclipse/wst/validation/internal/provisional/core/IValidator" /> - <accessrule kind="accessible" - pattern="org/eclipse/wst/common/ui/internal/dnd/DefaultDragAndDropCommand" /> - <accessrule kind="accessible" - pattern="org/eclipse/wst/common/ui/internal/dialogs/SelectSingleFileDialog" /> - <accessrule kind="accessible" - pattern="org/eclipse/wst/validation/internal/core/IMessageAccess" /> - <accessrule kind="accessible" - pattern="org/eclipse/wst/validation/internal/provisional/core/IProjectValidationContext" /> - <accessrule kind="accessible" - pattern="org/eclipse/wst/validation/internal/provisional/core/IValidatorJob" /> - <accessrule kind="accessible" - pattern="org/eclipse/wst/common/ui/internal/viewers/SelectSingleFileView" /> - <accessrule kind="accessible" - pattern="org/eclipse/wst/common/ui/internal/dnd/DragAndDropCommand" /> - <accessrule kind="accessible" - pattern="org/eclipse/wst/common/ui/internal/dnd/DragAndDropManager" /> - <accessrule kind="accessible" - pattern="org/eclipse/wst/common/ui/internal/dnd/ObjectTransfer" /> - <accessrule kind="accessible" - pattern="org/eclipse/wst/common/ui/internal/dnd/ViewerDragAdapter" /> - <accessrule kind="accessible" - pattern="org/eclipse/wst/common/ui/internal/dnd/ViewerDropAdapter" /> - <accessrule kind="accessible" - pattern="org/eclipse/wst/validation/internal/ConfigurationManager" /> - <accessrule kind="accessible" - pattern="org/eclipse/wst/validation/internal/ProjectConfiguration" /> - <accessrule kind="accessible" - pattern="org/eclipse/wst/validation/internal/ValidationRegistryReader" /> - <accessrule kind="accessible" - pattern="org/eclipse/wst/validation/internal/ValidatorMetaData" /> - <accessrule kind="accessible" - pattern="org/eclipse/wst/validation/internal/provisional/ValidationFactory" /> - <accessrule kind="accessible" - pattern="org/eclipse/wst/common/ui/internal/viewers/*" /> - <accessrule kind="accessible" - pattern="org/eclipse/wst/validation/internal/ValidationConfiguration" /> - </accessrules> - </classpathentry> - <classpathentry kind="output" path="bin" /> -</classpath> diff --git a/bundles/org.eclipse.wst.xml.ui/.cvsignore b/bundles/org.eclipse.wst.xml.ui/.cvsignore deleted file mode 100644 index 701c285abb..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/.cvsignore +++ /dev/null @@ -1,10 +0,0 @@ -bin -temp.folder -build.xml -xmleditor.jar -org.eclipse.wst.xml.ui_1.0.0.jar -org.eclipse.wst.xml.ui_1.0.0.zip -xmleditorsrc.zip -@dot -src.zip -javaCompiler...args diff --git a/bundles/org.eclipse.wst.xml.ui/.options b/bundles/org.eclipse.wst.xml.ui/.options deleted file mode 100644 index 5acae8fda4..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/.options +++ /dev/null @@ -1 +0,0 @@ -org.eclipse.wst.xml.ui/projectionperf=false diff --git a/bundles/org.eclipse.wst.xml.ui/.project b/bundles/org.eclipse.wst.xml.ui/.project deleted file mode 100644 index 50dc4a8398..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/.project +++ /dev/null @@ -1,27 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<projectDescription> - <name>org.eclipse.wst.xml.ui</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/bundles/org.eclipse.wst.xml.ui/.settings/org.eclipse.core.resources.prefs b/bundles/org.eclipse.wst.xml.ui/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index afa5c91352..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,3 +0,0 @@ -#Tue Apr 04 03:36:32 EDT 2006 -eclipse.preferences.version=1 -encoding/<project>=ISO-8859-1 diff --git a/bundles/org.eclipse.wst.xml.ui/.settings/org.eclipse.core.runtime.prefs b/bundles/org.eclipse.wst.xml.ui/.settings/org.eclipse.core.runtime.prefs deleted file mode 100644 index 7ec5750225..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/.settings/org.eclipse.core.runtime.prefs +++ /dev/null @@ -1,3 +0,0 @@ -#Mon Apr 17 01:48:39 EDT 2006 -eclipse.preferences.version=1 -line.separator=\r\n diff --git a/bundles/org.eclipse.wst.xml.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.wst.xml.ui/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index a512da061c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,79 +0,0 @@ -#Sat Mar 24 02:59:49 EDT 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=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.compiler.codegen.inlineJsrBytecode=disabled
-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=warning
-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=enabled
-org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
-org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
-org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
-org.eclipse.jdt.core.compiler.problem.finalParameterBound=ignore
-org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=error
-org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
-org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
-org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
-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.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=enabled
-org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public
-org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore
-org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=enabled
-org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=private
-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=warning
-org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
-org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
-org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=error
-org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=enabled
-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=ignore
-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=ignore
-org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=error
-org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
-org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
-org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
-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.unusedParameterWhenImplementingAbstract=disabled
-org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
-org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=error
-org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
-org.eclipse.jdt.core.compiler.source=1.3
-org.eclipse.jdt.core.incompatibleJDKLevel=ignore
-org.eclipse.jdt.core.incompleteClasspath=error
diff --git a/bundles/org.eclipse.wst.xml.ui/.settings/org.eclipse.jdt.ui.prefs b/bundles/org.eclipse.wst.xml.ui/.settings/org.eclipse.jdt.ui.prefs deleted file mode 100644 index 0ece7b5d75..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/.settings/org.eclipse.jdt.ui.prefs +++ /dev/null @@ -1,51 +0,0 @@ -#Wed Nov 22 23:23:01 EST 2006 -cleanup.add_default_serial_version_id=true -cleanup.add_generated_serial_version_id=false -cleanup.add_missing_annotations=false -cleanup.add_missing_deprecated_annotations=true -cleanup.add_missing_nls_tags=false -cleanup.add_missing_override_annotations=true -cleanup.add_serial_version_id=true -cleanup.always_use_blocks=true -cleanup.always_use_parentheses_in_expressions=true -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.format_comment=true -cleanup.format_javadoc=true -cleanup.format_multi_line_comment=true -cleanup.format_single_line_comment=true -cleanup.format_source_code=true -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=false -cleanup.organize_imports=true -cleanup.qualify_static_field_accesses_with_declaring_class=false -cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true -cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true -cleanup.qualify_static_member_accesses_with_declaring_class=true -cleanup.qualify_static_method_accesses_with_declaring_class=false -cleanup.remove_private_constructors=true -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=true -cleanup.remove_unused_private_methods=true -cleanup.remove_unused_private_types=true -cleanup.use_blocks=true -cleanup.use_blocks_only_for_return_and_throw=false -cleanup.use_parentheses_in_expressions=true -cleanup.use_this_for_non_static_field_access=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=_SSE Team Styles -cleanup_settings_version=2 -eclipse.preferences.version=1 -internal.default.compliance=default -org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8"?>\r\n<templates/> diff --git a/bundles/org.eclipse.wst.xml.ui/.settings/org.eclipse.ltk.core.refactoring.prefs b/bundles/org.eclipse.wst.xml.ui/.settings/org.eclipse.ltk.core.refactoring.prefs deleted file mode 100644 index c59368c5e1..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/.settings/org.eclipse.ltk.core.refactoring.prefs +++ /dev/null @@ -1,3 +0,0 @@ -#Tue Apr 04 03:36:32 EDT 2006 -eclipse.preferences.version=1 -org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false diff --git a/bundles/org.eclipse.wst.xml.ui/.settings/org.eclipse.pde.prefs b/bundles/org.eclipse.wst.xml.ui/.settings/org.eclipse.pde.prefs deleted file mode 100644 index de4a8be5f8..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/.settings/org.eclipse.pde.prefs +++ /dev/null @@ -1,25 +0,0 @@ -#Wed Jun 04 20:07:47 EDT 2008 -compilers.f.unresolved-features=1 -compilers.f.unresolved-plugins=1 -compilers.incompatible-environment=0 -compilers.p.build=0 -compilers.p.deprecated=1 -compilers.p.discouraged-class=1 -compilers.p.illegal-att-value=0 -compilers.p.internal=1 -compilers.p.missing-packages=1 -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=0 -compilers.p.unknown-identifier=0 -compilers.p.unknown-resource=0 -compilers.p.unresolved-ex-points=0 -compilers.p.unresolved-import=0 -compilers.p.unused-element-or-attribute=0 -compilers.s.create-docs=false -compilers.s.doc-folder=doc -compilers.s.open-tags=1 -compilers.use-project=true -eclipse.preferences.version=1 diff --git a/bundles/org.eclipse.wst.xml.ui/META-INF/MANIFEST.MF b/bundles/org.eclipse.wst.xml.ui/META-INF/MANIFEST.MF deleted file mode 100644 index 0172a152b1..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/META-INF/MANIFEST.MF +++ /dev/null @@ -1,61 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: %pluginName -Bundle-SymbolicName: org.eclipse.wst.xml.ui; singleton:=true -Bundle-Version: 1.1.0.qualifier -Bundle-Activator: org.eclipse.wst.xml.ui.internal.XMLUIPlugin -Bundle-Vendor: %providerName -Bundle-Localization: plugin -Export-Package: org.eclipse.wst.xml.ui, - org.eclipse.wst.xml.ui.internal;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.internal.actions;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.internal.autoedit;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.internal.catalog;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.internal.catalog.icons.etool50;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.internal.catalog.icons.obj16;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.internal.catalog.icons.ovr16;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.internal.contentassist;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.internal.contentoutline;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.internal.correction;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.internal.dialogs;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.internal.dnd;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.internal.doubleclick;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.internal.editor;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.internal.handlers;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.internal.hyperlink;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.internal.nsedit;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.internal.preferences;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.internal.projection;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.internal.properties;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.internal.provisional;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.internal.registry;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.internal.search;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.internal.selection;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.internal.style;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.internal.tabletree;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.internal.taginfo;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.internal.templates;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.internal.text;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.internal.util;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.internal.validation;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.internal.validation.core.errorinfo;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.internal.wizards;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", - org.eclipse.wst.xml.ui.views.contentoutline, - org.eclipse.wst.xml.ui.views.properties -Require-Bundle: org.eclipse.ui.ide;bundle-version="[3.4.0,4.0.0)", - org.eclipse.ui.views;bundle-version="[3.3.0,4.0.0)", - org.eclipse.jface.text;bundle-version="[3.4.0,4.0.0)", - org.eclipse.ui.workbench.texteditor;bundle-version="[3.4.0,4.0.0)", - org.eclipse.wst.sse.ui;bundle-version="[1.1.0,1.2.0)", - org.eclipse.wst.sse.core;bundle-version="[1.1.300,1.2.0)", - org.eclipse.ui;bundle-version="[3.4.0,4.0.0)", - org.eclipse.core.resources;bundle-version="[3.4.0,4.0.0)", - org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)", - org.eclipse.wst.common.uriresolver;bundle-version="[1.1.301,1.2.0)", - org.eclipse.wst.xml.core;bundle-version="[1.1.300,1.2.0)", - org.eclipse.wst.common.ui;bundle-version="[1.1.301,1.2.0)", - org.eclipse.wst.validation;bundle-version="[1.2.0,1.3.0)", - com.ibm.icu;bundle-version="[3.8.1,4.0.0)", - org.eclipse.core.expressions;bundle-version="[3.3.0,4.0.0)" -Bundle-ActivationPolicy: lazy; exclude:="org.eclipse.wst.xml.ui.internal.validation.core.errorinfo" -Bundle-RequiredExecutionEnvironment: J2SE-1.4 diff --git a/bundles/org.eclipse.wst.xml.ui/about.html b/bundles/org.eclipse.wst.xml.ui/about.html deleted file mode 100644 index 2199df3f05..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/about.html +++ /dev/null @@ -1,34 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"> -<HTML> - -<head> -<title>About</title> -<meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1"> -</head> - -<BODY lang="EN-US"> - -<H3>About This Content</H3> - -<P>June, 2008</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/org/documents/epl-v10.php">http://www.eclipse.org/org/documents/epl-v10.php</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/bundles/org.eclipse.wst.xml.ui/build.properties b/bundles/org.eclipse.wst.xml.ui/build.properties deleted file mode 100644 index cae15eb007..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/build.properties +++ /dev/null @@ -1,30 +0,0 @@ -############################################################################### -# Copyright (c) 2001, 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 -# Jens Lukowski/Innoopract - initial renaming/restructuring -# -############################################################################### -bin.includes = plugin.xml,\ - icons/,\ - plugin.properties,\ - templates/,\ - examples/,\ - META-INF/,\ - .,\ - .options,\ - about.html -bin.excludes = bin/**,\ - @dot/**,\ - temp.folder/** -source.. = src/,\ - src-multipage/,\ - src-wizards/,\ - src-catalog/,\ - src-validation -src.includes = build.properties diff --git a/bundles/org.eclipse.wst.xml.ui/examples/EditingAndValidatingXML.zip b/bundles/org.eclipse.wst.xml.ui/examples/EditingAndValidatingXML.zip Binary files differdeleted file mode 100644 index 62577670ee..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/examples/EditingAndValidatingXML.zip +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/XMLFile.gif b/bundles/org.eclipse.wst.xml.ui/icons/XMLFile.gif Binary files differdeleted file mode 100644 index 14eb1be095..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/XMLFile.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/dtool16/collapse.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/dtool16/collapse.gif Binary files differdeleted file mode 100644 index ce74721ea2..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/dtool16/collapse.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/dtool16/collapse_all.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/dtool16/collapse_all.gif Binary files differdeleted file mode 100644 index 7dc0de5130..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/dtool16/collapse_all.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/dtool16/constrainoff.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/dtool16/constrainoff.gif Binary files differdeleted file mode 100644 index 4bdceb84e9..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/dtool16/constrainoff.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/dtool16/constrainon.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/dtool16/constrainon.gif Binary files differdeleted file mode 100644 index e823d572a3..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/dtool16/constrainon.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/dtool16/expand.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/dtool16/expand.gif Binary files differdeleted file mode 100644 index bc37b7a4e5..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/dtool16/expand.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/dtool16/expand_all.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/dtool16/expand_all.gif Binary files differdeleted file mode 100644 index 492c14f6e1..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/dtool16/expand_all.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/dtool16/new_xml.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/dtool16/new_xml.gif Binary files differdeleted file mode 100644 index e1cfdf7eb3..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/dtool16/new_xml.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/dtool16/rldgrmr.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/dtool16/rldgrmr.gif Binary files differdeleted file mode 100644 index 49325dd8ea..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/dtool16/rldgrmr.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/dtool16/validate.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/dtool16/validate.gif Binary files differdeleted file mode 100644 index 561d1463ef..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/dtool16/validate.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/etool16/collapse.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/etool16/collapse.gif Binary files differdeleted file mode 100644 index b75bc19602..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/etool16/collapse.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/etool16/collapse_all.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/etool16/collapse_all.gif Binary files differdeleted file mode 100644 index a2d80a9044..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/etool16/collapse_all.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/etool16/constrainoff.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/etool16/constrainoff.gif Binary files differdeleted file mode 100644 index c1ab04c81c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/etool16/constrainoff.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/etool16/constrainon.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/etool16/constrainon.gif Binary files differdeleted file mode 100644 index 082f9c0ae8..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/etool16/constrainon.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/etool16/expand.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/etool16/expand.gif Binary files differdeleted file mode 100644 index b2f45306c9..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/etool16/expand.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/etool16/expand_all.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/etool16/expand_all.gif Binary files differdeleted file mode 100644 index 0205b29176..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/etool16/expand_all.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/etool16/new_xml.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/etool16/new_xml.gif Binary files differdeleted file mode 100644 index 9dfb62d35b..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/etool16/new_xml.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/etool16/rldgrmr.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/etool16/rldgrmr.gif Binary files differdeleted file mode 100644 index 049cac696c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/etool16/rldgrmr.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/etool16/validate.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/etool16/validate.gif Binary files differdeleted file mode 100644 index 2b347ac458..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/etool16/validate.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/XSDFile.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/XSDFile.gif Binary files differdeleted file mode 100644 index cc0eeb7196..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/XSDFile.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/add_correction.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/add_correction.gif Binary files differdeleted file mode 100644 index 252d7ebcb8..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/add_correction.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/att_req_obj.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/att_req_obj.gif Binary files differdeleted file mode 100644 index a8c66d5016..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/att_req_obj.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/attribute_obj.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/attribute_obj.gif Binary files differdeleted file mode 100644 index 79d49d037b..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/attribute_obj.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/cdatasection.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/cdatasection.gif Binary files differdeleted file mode 100644 index 6b0872c909..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/cdatasection.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/choice.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/choice.gif Binary files differdeleted file mode 100644 index d13ba2e5b0..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/choice.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/comment_obj.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/comment_obj.gif Binary files differdeleted file mode 100644 index 28c2ccb1e7..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/comment_obj.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/correction_change.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/correction_change.gif Binary files differdeleted file mode 100644 index af83c528dd..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/correction_change.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/doctype.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/doctype.gif Binary files differdeleted file mode 100644 index 3300f82862..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/doctype.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/dtdfile.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/dtdfile.gif Binary files differdeleted file mode 100644 index 3c0acadd2d..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/dtdfile.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/element_obj.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/element_obj.gif Binary files differdeleted file mode 100644 index 3567815907..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/element_obj.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/entity.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/entity.gif Binary files differdeleted file mode 100644 index 61fd3d4caa..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/entity.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/entity_reference.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/entity_reference.gif Binary files differdeleted file mode 100644 index 3af9149125..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/entity_reference.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/enum.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/enum.gif Binary files differdeleted file mode 100644 index 5c0a48115b..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/enum.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/error-overlay.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/error-overlay.gif Binary files differdeleted file mode 100644 index 119dcccd5a..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/error-overlay.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/localvariable_obj.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/localvariable_obj.gif Binary files differdeleted file mode 100644 index 3244b26ef4..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/localvariable_obj.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/notation.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/notation.gif Binary files differdeleted file mode 100644 index 57ad089a69..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/notation.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/occurone_obj.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/occurone_obj.gif Binary files differdeleted file mode 100644 index 7bb65c9d51..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/occurone_obj.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/proinst_obj.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/proinst_obj.gif Binary files differdeleted file mode 100644 index 74436d8d3c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/proinst_obj.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/sort.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/sort.gif Binary files differdeleted file mode 100644 index 23c5d0b11c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/sort.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/tag-generic.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/tag-generic.gif Binary files differdeleted file mode 100644 index 65f516e80a..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/tag-generic.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/tag-macro.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/tag-macro.gif Binary files differdeleted file mode 100644 index 5d1f81b6d4..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/tag-macro.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/tag_generic_deemphasized_obj.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/tag_generic_deemphasized_obj.gif Binary files differdeleted file mode 100644 index cacb4058a7..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/tag_generic_deemphasized_obj.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/tag_generic_emphasized_obj.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/tag_generic_emphasized_obj.gif Binary files differdeleted file mode 100644 index 45c1db4c08..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/tag_generic_emphasized_obj.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/text.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/text.gif Binary files differdeleted file mode 100644 index efa7a38014..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/text.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/txtext.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/txtext.gif Binary files differdeleted file mode 100644 index b226e41c52..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/txtext.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/warning_obj.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/warning_obj.gif Binary files differdeleted file mode 100644 index 1e5f5eb367..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/warning_obj.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/ovr16/error_ovr.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/ovr16/error_ovr.gif Binary files differdeleted file mode 100644 index 119dcccd5a..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/ovr16/error_ovr.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/ovr16/stale_error_ovr.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/ovr16/stale_error_ovr.gif Binary files differdeleted file mode 100644 index 5b0471b5eb..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/ovr16/stale_error_ovr.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/ovr16/warn_ovr.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/ovr16/warn_ovr.gif Binary files differdeleted file mode 100644 index c350704fa1..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/ovr16/warn_ovr.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/view16/attibute.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/view16/attibute.gif Binary files differdeleted file mode 100644 index 79d49d037b..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/view16/attibute.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/wizban/generatexml_wiz.png b/bundles/org.eclipse.wst.xml.ui/icons/full/wizban/generatexml_wiz.png Binary files differdeleted file mode 100644 index b17e48a94b..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/full/wizban/generatexml_wiz.png +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/newSampleProject_wiz.gif b/bundles/org.eclipse.wst.xml.ui/icons/newSampleProject_wiz.gif Binary files differdeleted file mode 100644 index dc96b10c97..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/newSampleProject_wiz.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/newSampleProject_wizbanner.png b/bundles/org.eclipse.wst.xml.ui/icons/newSampleProject_wizbanner.png Binary files differdeleted file mode 100644 index be7147416b..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/newSampleProject_wizbanner.png +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/sourceEditor.gif b/bundles/org.eclipse.wst.xml.ui/icons/sourceEditor.gif Binary files differdeleted file mode 100644 index 75ebdb8586..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/sourceEditor.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/icons/xmldoc.gif b/bundles/org.eclipse.wst.xml.ui/icons/xmldoc.gif Binary files differdeleted file mode 100644 index 14eb1be095..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/xmldoc.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/plugin.properties b/bundles/org.eclipse.wst.xml.ui/plugin.properties deleted file mode 100644 index e900acf59a..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/plugin.properties +++ /dev/null @@ -1,139 +0,0 @@ -############################################################################### -# Copyright (c) 2001, 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 -# Jens Lukowski/Innoopract - initial renaming/restructuring -# David Carver / STAR Standards - added XML Catalog Import/Export Wizard -# bug 192568 -# David Carver / STAR Standards - bug 212330 - migrate to org.eclipse.ui.menus -############################################################################### -providerName=Eclipse.org -pluginName=XML UI Plugin -XML.name=XML -XML_Files.name=XML Files -XML_Source.name=Editor -XML_Templates.name=Templates -XML_Styles.name=Styles -XML_Syntax_Coloring=Syntax Coloring -XML_Typing=Typing -XML_Editor.name=XML Editor -############################################################################### -_UI_WIZARD_NEW_XML=XML -_UI_WIZARD_XML_CATEGORY=XML -genMenuLabel=&Generate -_UI_ACTION_CREATE_XML=&XML File... -_UI_CREATE_NEW_XML_FILE=Create a new XML file -_UI_WIZARD_IMPORT_EXPORT_XMLCATALOG=XML Catalog -_UI_IMPORT_XML_CATALOG_FILE=Import an existing XML Catalog. -_UI_EXPORT_XML_CATALOG_FILE=Export an XML Catalog. -XMLExample.name=Editing and validating XML files -XMLExampleProjectCreationWizard.description=Create a project containing XML sample files -XMLExampleProjectCreationWizard.projectname=XMLExamples -XMLExampleProjectCreationWizard.pagetitle=XML sample files for editing and validating -XMLExampleProjectCreationWizard.pagedescription=Create a project containing XML sample files. -XMLExampleProjectCreationWizard.label=&Project Name: -############################################################################### -All_XML_context_type_Extension_Element.name=All XML -XML_New_context_type_Extension_Element.name=New XML -XML_Tag_context_type_Extension_Element.name=XML Tag -XML_Attribute_context_type_Extension_Element.name=XML Attribute -XML_Attribute_value_context_type_Extension_Element.name=XML Attribute value -############################################################################### -AddTask.label=Add &Task... -AddTask.tooltip=Add Task... -AddBookmark.label=Add Boo&kmark... -AddBookmark.tooltip=Add Bookmark... -SelectRuler.label=Select Ruler -############################################################################### -XML_Catalog_File_Type_Extension_Point.name=XML Catalog file type extension point -_UI_PREF_XML_CATALOG=XML Catalog -_UI_PREF_DTD_FILES=DTD Files -_UI_PREF_XSD_FILES=XSD Files -_UI_PREF_TAGLIB_DEF_FILES=Taglib Definition Files -############################################################################### -_UI_XML_VALIDATOR = XML Validator -_UI_REF_FILE_SHOW_DETAILS = Show Details... -_UI_MENU_VALIDATE_XML = Validate XML File -## -CleanupDocument_label=Cleanup Document... -CleanupDocument_tooltip=Cleanup Document -ToggleComment_label=Toggle Comment -ToggleComment_tooltip=Toggle Comment -AddBlockComment_label=Add Block Comment -AddBlockComment_tooltip=Add Block Comment -RemoveBlockComment_label=Remove Block Comment -RemoveBlockComment_tooltip=Remove Block Comment -FindOccurrences_label=Occurrences in File -## -preferenceKeywords.files=editor xml creating saving files suffix specified encoding iana -preferenceKeywords.source=editor xml source formatting line width split multiple attributes new clear blank indent tabs spaces size content assist automatically suggestions prompt characters inserted strategy lax strict grammar constraints inferred absence dtd schema -preferenceKeywords.templates=editor xml templates snippet macros -preferenceKeywords.styles=editor xml style customize syntax highlighting type text content foreground background bold color -preferenceKeywords.xmlcatalog=xml catalog entries -preferenceKeywords.severities=xml grammar errors warnings ignore options severity severities suppress project specific projectspecific - -## -XML_Source_target_name=XML Source -XML_hyperlink=Tags And Attributes -## -DesignMenu_name=&Design -ReloadDependencies_name=Reload Dependencies -ReloadDependencies_description=Reload Dependencies -ReloadDependencies_mnemonic=R -Constraints_name=Turn off Grammar Constraints -Constraints_description=Turn off grammar Constraints -Constraints_mnemonic=T -ExpandAll_name=Expand All -CollapseAll_name=Collapse All -ActionDefinition.nextSibling.name=Next Sibling -ActionDefinition.nextSibling.description=Go to Next Sibling -ActionDefinition.previousSibling.name=Previous Sibling -ActionDefinition.previousSibling.description=Go to Previous Sibling -ActionDefinition.gotoMatchingTag.name=Matching Tag -ActionDefinition.gotoMatchingTag.description=Go to Matching Tag -MatchingTagPreference.label=Matching Tags - -scope.structured.text.editor.xml.name=Editing XML Source -scope.structured.text.editor.xml.description=Editing XML Source -scope.structured.text.editor.xml.navigation.name=XML Source Navigation -scope.structured.text.editor.xml.navigation.description=XML Source Navigation -scope.structured.text.editor.xml.cleanup.name=XML Source Cleanup -scope.structured.text.editor.xml.cleanup.description=XML Source Cleanup -scope.structured.text.editor.xml.comments.name=XML Source Comments -scope.structured.text.editor.xml.comments.description=XML Source Comments -scope.structured.text.editor.xml.selection.name=XML Source Selection -scope.structured.text.editor.xml.selection.description=XML Source Selection -scope.structured.text.editor.xml.dependencies.name=XML Source Dependencies -scope.structured.text.editor.xml.dependencies.description=XML Source Dependencies -scope.structured.text.editor.xml.grammar.name=XML Source Grammar -scope.structured.text.editor.xml.grammar.description=XML Source Grammar -scope.structured.text.editor.xml.expand.name=XML Source Expand/Collapse -scope.structured.text.editor.xml.expand.description=XML Source Expand/Collapse -scope.structured.text.editor.xml.occurrences.name=XML Source Occurrences -scope.structured.text.editor.xml.occurrences.description=XML Source Occurrences - -Colors.tagAttributeName=Tag Attribute Name -Colors.tagAttributeValue=Tag Attribute Value -Colors.commentBorder=Comment Border -Colors.commentText=Comment Text -Colors.declBorder=Declaration Border -Colors.doctypeName=Doctype Name -Colors.doctypeExternalPubref=Doctype External Public Reference -Colors.doctypeExternalId=Doctype External Id -Colors.doctypeExtrenalSysref=Doctype External System Reference -Colors.tagBorder=Tag Border -Colors.tagName=Tag Name -Colors.piBorder=Processing Instruction Border -Colors.cdataBorder=CDATA Border -Colors.cdataText=CDATA Text -Colors.entityReference=Entity Reference - -# Menu contributions -command.toggle.comment.mnemonic=T -command.add.block.comment.mnemonic=A -command.remove.block.comment.mnemonic=R
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.xml.ui/plugin.xml b/bundles/org.eclipse.wst.xml.ui/plugin.xml deleted file mode 100644 index c8a3d522bd..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/plugin.xml +++ /dev/null @@ -1,1567 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<?eclipse version="3.3"?> -<plugin> - - <extension-point id="catalogFileType" name="%XML_Catalog_File_Type_Extension_Point.name" schema="schema/catalogFileType.exsd"/> - - <extension point="org.eclipse.wst.xml.ui.catalogFileType"> - <fileType - extensions="dtd, ent, mod" - description="%_UI_PREF_DTD_FILES" - id="org.eclipse.wst.xml.core.ui.catalogFileType.dtd"> - </fileType> - <fileType - extensions="xsd" - description="%_UI_PREF_XSD_FILES" - id="org.eclipse.wst.xml.core.ui.catalogFileType.xsd"> - </fileType> - <fileType - extensions="tld" - description="%_UI_PREF_TAGLIB_DEF_FILES" - id="org.eclipse.wst.xml.core.ui.catalogFileType.tld"> - </fileType> - </extension> - - <!--The org.eclipse.wst.xml.core.xmlsource content type is only for - handling some special cases of ill-formed xml in a reasonable - manner, and should not be emulated by clients. The two content - types are often used interchangeably by the XML component, but - please use org.eclipse.core.runtime.xml instead. --> - <extension point="org.eclipse.wst.sse.ui.editorConfiguration"> - <sourceViewerConfiguration - class="org.eclipse.wst.xml.ui.StructuredTextViewerConfigurationXML" - target="org.eclipse.core.runtime.xml, org.eclipse.wst.xml.core.xmlsource" /> - <contentOutlineConfiguration - class="org.eclipse.wst.xml.ui.views.contentoutline.XMLContentOutlineConfiguration" - target="org.eclipse.core.runtime.xml, org.eclipse.wst.xml.core.xmlsource" /> - <propertySheetConfiguration - class="org.eclipse.wst.xml.ui.views.properties.XMLPropertySheetConfiguration" - target="org.eclipse.core.runtime.xml, org.eclipse.wst.xml.core.xmlsource" /> - <documentationTextHover - class="org.eclipse.wst.xml.ui.internal.taginfo.XMLTagInfoHoverProcessor" - target="org.eclipse.wst.xml.XML_DEFAULT"> - </documentationTextHover> - <doubleClickStrategy - class="org.eclipse.wst.xml.ui.internal.doubleclick.XMLDoubleClickStrategy" - target="org.eclipse.wst.xml.XML_DEFAULT"> - </doubleClickStrategy> - <provisionalConfiguration - type="sourceeditingtexttools" - class="org.eclipse.wst.xml.ui.internal.provisional.XMLSourceEditingTextTools" - target="org.eclipse.core.runtime.xml, org.eclipse.wst.xml.core.xmlsource" /> - <provisionalConfiguration - type="characterpairmatcher" - class="org.eclipse.wst.xml.ui.internal.text.XMLDocumentRegionEdgeMatcher" - target="org.eclipse.core.runtime.xml, org.eclipse.wst.xml.core.xmlsource" /> - <provisionalConfiguration - type="structuredtextfoldingprovider" - class="org.eclipse.wst.xml.ui.internal.projection.StructuredTextFoldingProviderXML" - target="org.eclipse.core.runtime.xml, org.eclipse.wst.xml.core.xmlsource" /> - <provisionalConfiguration - type="org.eclipse.jface.text.quickassist.IQuickAssistProcessor" - class="org.eclipse.wst.xml.ui.internal.correction.XMLQuickAssistProcessor" - target="org.eclipse.wst.xml.XML_DEFAULT" /> - <provisionalConfiguration - type="autoeditstrategy" - class="org.eclipse.wst.xml.ui.internal.autoedit.StructuredAutoEditStrategyXML" - target="org.eclipse.wst.xml.XML_DEFAULT" /> - <provisionalDefinition - type="preferencepages" - value="org.eclipse.wst.xml.ui.preferences.xml.xml, org.eclipse.wst.sse.ui.preferences.xml.source, org.eclipse.wst.sse.ui.preferences.xml.templates, org.eclipse.wst.sse.ui.preferences.xml.colors" - target="org.eclipse.core.runtime.xml, org.eclipse.wst.xml.core.xmlsource" /> - <provisionalDefinition - type="spellingregions" - value="XML_COMMENT_TEXT, XML_CONTENT, XML_DEFAULT" - target="org.eclipse.core.runtime.xml, org.eclipse.wst.xml.core.xmlsource" /> - <provisionalDefinition - type="activecontexts" - value="org.eclipse.core.runtime.xml, org.eclipse.wst.xml.navigation, org.eclipse.wst.xml.cleanup, org.eclipse.wst.xml.comments, org.eclipse.wst.xml.selection, org.eclipse.wst.xml.dependencies, org.eclipse.wst.xml.grammar, org.eclipse.wst.xml.expand, org.eclipse.wst.xml.occurrences" - target="org.eclipse.core.runtime.xml" /> - </extension> - - <extension point="org.eclipse.ui.contexts"> - <context - name="%scope.structured.text.editor.xml.name" - parentId="org.eclipse.wst.sse.ui.structuredTextEditorScope" - description="%scope.structured.text.editor.xml.description" - id="org.eclipse.core.runtime.xml"> - </context> - <context - name="%scope.structured.text.editor.xml.navigation.name" - parentId="org.eclipse.wst.sse.ui.structuredTextEditorScope" - description="%scope.structured.text.editor.xml.navigation.description" - id="org.eclipse.wst.xml.navigation"> - </context> - <context - name="%scope.structured.text.editor.xml.cleanup.name" - parentId="org.eclipse.wst.sse.ui.structuredTextEditorScope" - description="%scope.structured.text.editor.xml.cleanup.description" - id="org.eclipse.wst.xml.cleanup"> - </context> - <context - name="%scope.structured.text.editor.xml.comments.name" - parentId="org.eclipse.wst.sse.ui.structuredTextEditorScope" - description="%scope.structured.text.editor.xml.comments.description" - id="org.eclipse.wst.xml.comments"> - </context> - <context - name="%scope.structured.text.editor.xml.selection.name" - parentId="org.eclipse.wst.sse.ui.structuredTextEditorScope" - description="%scope.structured.text.editor.xml.selection.description" - id="org.eclipse.wst.xml.selection"> - </context> - <context - name="%scope.structured.text.editor.xml.dependencies.name" - parentId="org.eclipse.wst.sse.ui.structuredTextEditorScope" - description="%scope.structured.text.editor.xml.dependencies.description" - id="org.eclipse.wst.xml.dependencies"> - </context> - <context - name="%scope.structured.text.editor.xml.grammar.name" - parentId="org.eclipse.wst.sse.ui.structuredTextEditorScope" - description="%scope.structured.text.editor.xml.grammar.description" - id="org.eclipse.wst.xml.grammar"> - </context> - <context - name="%scope.structured.text.editor.xml.expand.name" - parentId="org.eclipse.wst.sse.ui.structuredTextEditorScope" - description="%scope.structured.text.editor.xml.expand.description" - id="org.eclipse.wst.xml.expand"> - </context> - <context - name="%scope.structured.text.editor.xml.occurrences.name" - parentId="org.eclipse.wst.sse.ui.structuredTextEditorScope" - description="%scope.structured.text.editor.xml.occurrences.description" - id="org.eclipse.wst.xml.occurrences"> - </context> - </extension> - - <extension - point="org.eclipse.core.filebuffers.annotationModelCreation"> - <factory - contentTypeId="org.eclipse.core.runtime.xml" - class="org.eclipse.wst.sse.ui.internal.StructuredResourceMarkerAnnotationModelFactory" /> - <factory - contentTypeId="org.eclipse.wst.xml.core.xmlsource" - class="org.eclipse.wst.sse.ui.internal.StructuredResourceMarkerAnnotationModelFactory" /> - </extension> - <extension - point="org.eclipse.wst.sse.ui.adapterFactoryDescription"> - <adapterFactoryDescription - class="org.eclipse.wst.xml.ui.internal.registry.AdapterFactoryProviderForXML"> - <contentType id="org.eclipse.core.runtime.xml" /> - <contentType id="org.eclipse.wst.xml.core.xmlsource" /> - </adapterFactoryDescription> - </extension> - <extension point="org.eclipse.ui.preferencePages"> - <!-- The "top-level" XML category --> - <page - name="%XML.name" - class="org.eclipse.wst.xml.ui.internal.preferences.EmptyFilePreferencePage" - id="org.eclipse.wst.xml.ui.preferences.xml"> - </page> - <!-- The "lower level" XML Files category/page --> - <page - name="%XML_Files.name" - category="org.eclipse.wst.xml.ui.preferences.xml" - class="org.eclipse.wst.xml.ui.internal.preferences.XMLFilesPreferencePage" - id="org.eclipse.wst.xml.ui.preferences.xml.xml"> - <keywordReference id="org.eclipse.wst.xml.ui.files"/> - <keywordReference id="org.eclipse.wst.xml.ui.severities"/> - </page> - <!-- XML PREFERENCE PAGES --> - <page - name="%XML_Source.name" - category="org.eclipse.wst.xml.ui.preferences.xml.xml" - class="org.eclipse.wst.xml.ui.internal.preferences.XMLSourcePreferencePage" - id="org.eclipse.wst.sse.ui.preferences.xml.source"> - <keywordReference id="org.eclipse.wst.xml.ui.source"/> - </page> - <page - name="%XML_Templates.name" - category="org.eclipse.wst.sse.ui.preferences.xml.source" - class="org.eclipse.wst.xml.ui.internal.preferences.XMLTemplatePreferencePage" - id="org.eclipse.wst.sse.ui.preferences.xml.templates"> - <keywordReference id="org.eclipse.wst.xml.ui.templates"/> - </page> - <page - name="%XML_Syntax_Coloring" - category="org.eclipse.wst.sse.ui.preferences.xml.source" - class="org.eclipse.wst.xml.ui.internal.preferences.XMLSyntaxColoringPage" - id="org.eclipse.wst.sse.ui.preferences.xml.colors"> - <keywordReference id="org.eclipse.wst.xml.ui.styles"/> - </page> - <page - name="%_UI_PREF_XML_CATALOG" - category="org.eclipse.wst.xml.ui.preferences.xml" - class="org.eclipse.wst.xml.ui.internal.catalog.XMLCatalogPreferencePage" - id="org.eclipse.wst.xml.core.ui.XMLCatalogPreferencePage"> - <keywordReference id="org.eclipse.wst.xml.ui.xmlcatalog"/> - </page> - <page - name="%XML_Typing" - category="org.eclipse.wst.sse.ui.preferences.xml.source" - class="org.eclipse.wst.xml.ui.internal.preferences.XMLTypingPreferencePage" - id="org.eclipse.wst.sse.ui.preferences.xml.typing"> - </page> - </extension> - - <!-- Keywords for preference and properties pages --> - <extension point="org.eclipse.ui.keywords"> - <keyword - label="%preferenceKeywords.files" - id="org.eclipse.wst.xml.ui.files"/> - <keyword - label="%preferenceKeywords.source" - id="org.eclipse.wst.xml.ui.source"/> - <keyword - label="%preferenceKeywords.templates" - id="org.eclipse.wst.xml.ui.templates"/> - <keyword - label="%preferenceKeywords.styles" - id="org.eclipse.wst.xml.ui.styles"/> - <keyword - label="%preferenceKeywords.xmlcatalog" - id="org.eclipse.wst.xml.ui.xmlcatalog"/> - <keyword - label="%preferenceKeywords.severities" - id="org.eclipse.wst.xml.ui.severities"/> - </extension> - - <!-- Editor actionsets --> - <extension point="org.eclipse.ui.actionSetPartAssociations"> - <actionSetPartAssociation - targetID="org.eclipse.ui.edit.text.actionSet.annotationNavigation"> - <part id="org.eclipse.core.runtime.xml.source"></part> - <part id="org.eclipse.core.runtime.xml.source2"></part> - </actionSetPartAssociation> - <actionSetPartAssociation - targetID="org.eclipse.ui.NavigateActionSet"> - <part id="org.eclipse.core.runtime.xml.source"></part> - <part id="org.eclipse.core.runtime.xml.source2"></part> - </actionSetPartAssociation> - </extension> - - <!-- Templates --> - <extension point="org.eclipse.ui.editors.templates"> - <contextType - name="%All_XML_context_type_Extension_Element.name" - class="org.eclipse.wst.xml.ui.internal.templates.TemplateContextTypeXML" - id="xml_all"> - </contextType> - <contextType - name="%XML_New_context_type_Extension_Element.name" - class="org.eclipse.wst.xml.ui.internal.templates.TemplateContextTypeXML" - id="xml_new"> - </contextType> - <contextType - name="%XML_Tag_context_type_Extension_Element.name" - class="org.eclipse.wst.xml.ui.internal.templates.TemplateContextTypeXML" - id="xml_tag"> - </contextType> - <contextType - name="%XML_Attribute_context_type_Extension_Element.name" - class="org.eclipse.wst.xml.ui.internal.templates.TemplateContextTypeXML" - id="xml_attribute"> - </contextType> - <contextType - name="%XML_Attribute_value_context_type_Extension_Element.name" - class="org.eclipse.wst.xml.ui.internal.templates.TemplateContextTypeXML" - id="xml_attribute_value"> - </contextType> - <include - file="templates/xmldefault-templates.xml" - translations="$nl$/templates/xmldefault-templates.properties"> - </include> - </extension> - - <extension point="org.eclipse.ui.editors"> - <editor - name="%XML_Editor.name" - icon="$nl$/icons/xmldoc.gif" - contributorClass="org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorActionBarContributor" - class="org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart" - symbolicFontName="org.eclipse.wst.sse.ui.textfont" - id="org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart"> - <contentTypeBinding - contentTypeId="org.eclipse.core.runtime.xml" /> - <contentTypeBinding - contentTypeId="org.eclipse.wst.xml.core.xmlsource" /> - - </editor> - </extension> - - <!-- Editor actionsets --> - <extension point="org.eclipse.ui.actionSetPartAssociations"> - <actionSetPartAssociation - targetID="org.eclipse.ui.edit.text.actionSet.annotationNavigation"> - <part - id="org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart"> - </part> - </actionSetPartAssociation> - <actionSetPartAssociation - targetID="org.eclipse.ui.NavigateActionSet"> - <part - id="org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart"> - </part> - </actionSetPartAssociation> - </extension> - - - - <!-- ================================================== --> - <!-- Contribute a 'New Wizard' for XML files --> - <!-- ================================================== --> - <extension point="org.eclipse.ui.newWizards"> - <category - name="%_UI_WIZARD_XML_CATEGORY" - id="org.eclipse.wst.XMLCategory"> - </category> - <wizard - name="%_UI_WIZARD_NEW_XML" - icon="$nl$/icons/XMLFile.gif" - category="org.eclipse.wst.XMLCategory" - class="org.eclipse.wst.xml.ui.internal.wizards.NewXMLWizard" - id="org.eclipse.wst.xml.ui.internal.wizards.NewXMLWizard"> - <description>%_UI_CREATE_NEW_XML_FILE</description> - <selection class="org.eclipse.core.resources.IResource"> - </selection> - </wizard> - </extension> - - <!-- =============================================================================== --> - <!-- Allow the 'New XML' wizard to be accessed via the 'Generate' menu on a XSD file --> - <!-- =============================================================================== --> -<!-- - <extension point="org.eclipse.ui.popupMenus"> - <objectContribution - objectClass="org.eclipse.core.resources.IFile" - nameFilter="*.xsd" - id="org.eclipse.wst.xmlwizard.createXMLFromXSD"> - <menu - label="%genMenuLabel" - path="additions" - id="generateXMLArtifacts"> - <separator name="xml" /> - </menu> - <action - label="%_UI_ACTION_CREATE_XML" - class="org.eclipse.wst.xml.ui.internal.wizards.XMLImportActionDelegate" - menubarPath="generateXMLArtifacts/xml" - enablesFor="1" - id="org.eclipse.wst.xmlwizard.createXMLFromXSDAction"> - </action> - </objectContribution> - </extension> ---> - - <!-- =============================================================================== --> - <!-- Allow the 'New XML' wizard to be accessed via the 'Generate' menu on a DTD file --> - <!-- =============================================================================== --> -<!-- - <extension point="org.eclipse.ui.popupMenus"> - <objectContribution - objectClass="org.eclipse.core.resources.IFile" - nameFilter="*.dtd" - id="org.eclipse.wst.xmlwizard.createXMLFromDTD"> - <menu - label="%genMenuLabel" - path="additions" - id="generateXMLArtifacts"> - <separator name="xml" /> - </menu> - <action - label="%_UI_ACTION_CREATE_XML" - class="org.eclipse.wst.xml.ui.internal.wizards.XMLImportActionDelegate" - menubarPath="generateXMLArtifacts/xml" - enablesFor="1" - id="org.eclipse.wst.xmlwizard.createXMLFromDTDAction"> - </action> - </objectContribution> - </extension> ---> - - <!-- =============================================================================== --> - <!-- Contribute a New->Example... entry for Editing and Validating XML files --> - <!-- =============================================================================== --> - - <!-- define the XMLSamples project wizard --> - <extension point="org.eclipse.ui.newWizards"> - <category - name="%_UI_WIZARD_NEW_XML" - parentCategory="org.eclipse.ui.Examples" - id="org.eclipse.wst.xml.examples"> - </category> - <wizard - name="%XMLExample.name" - class="org.eclipse.wst.xml.ui.internal.wizards.ExampleProjectCreationWizard" - category="org.eclipse.ui.Examples/org.eclipse.wst.xml.examples" - id="org.eclipse.wst.xml.ui.XMLExampleProjectCreationWizard" - project="true" - icon="$nl$/icons/newSampleProject_wiz.gif"> - <description> - %XMLExampleProjectCreationWizard.description - </description> - </wizard> - </extension> - - <!-- configure the XMLSamples project wizard --> - <extension - point="org.eclipse.wst.common.ui.exampleProjectCreationWizard" - id="XMLExampleProjectCreationWizardExtension"> - <wizard - id="org.eclipse.wst.xml.ui.XMLExampleProjectCreationWizard" - banner="icons/newSampleProject_wizbanner.png"> - <projectsetup - pagetitle="%XMLExampleProjectCreationWizard.pagetitle" - name="%XMLExampleProjectCreationWizard.projectname" - label="%XMLExampleProjectCreationWizard.label" - pagedescription="%XMLExampleProjectCreationWizard.pagedescription" - open="readme.html"> - <import - dest="" - src="examples/EditingAndValidatingXML.zip" /> - </projectsetup> - </wizard> - </extension> - - <!-- initialize xml ui preferences --> - <extension point="org.eclipse.core.runtime.preferences"> - <initializer - class="org.eclipse.wst.xml.ui.internal.preferences.XMLUIPreferenceInitializer" /> - </extension> - - <extension point="org.eclipse.wst.sse.ui.sourcevalidation"> - <validator - scope="total" - class="org.eclipse.wst.xml.ui.internal.validation.DelegatingSourceValidatorForXML" - id="org.eclipse.wst.xml.ui.internal.validation.DelegatingSourceValidatorForXML"> - <contentTypeIdentifier id="org.eclipse.core.runtime.xml"> - <partitionType id="org.eclipse.wst.xml.XML_DEFAULT"/> - <partitionType id="org.eclipse.wst.sse.ST_DEFAULT"/> - </contentTypeIdentifier> - <contentTypeIdentifier id="org.eclipse.wst.xml.core.xmlsource"> - <partitionType id="org.eclipse.wst.xml.XML_DEFAULT"/> - <partitionType id="org.eclipse.wst.sse.ST_DEFAULT"/> - </contentTypeIdentifier> - </validator> - </extension> - - <extension point="org.eclipse.wst.sse.ui.sourcevalidation"> - <validator - scope="partial" - class="org.eclipse.wst.xml.ui.internal.validation.MarkupValidator" - id="org.eclipse.wst.xml.ui.internal.validation.markupvalidator"> - <contentTypeIdentifier id="org.eclipse.core.runtime.xml"> - <partitionType id="org.eclipse.wst.sse.ST_DEFAULT"/> - <partitionType id="org.eclipse.wst.xml.XML_DEFAULT"/> - </contentTypeIdentifier> - <contentTypeIdentifier id="org.eclipse.wst.xml.core.xmlsource"> - <partitionType id="org.eclipse.wst.xml.XML_DEFAULT"/> - <partitionType id="org.eclipse.wst.sse.ST_DEFAULT"/> - </contentTypeIdentifier> - </validator> - </extension> - - <extension point="org.eclipse.ui.editors.annotationTypes"> - <type name="org.eclipse.wst.xml.ui.matching.tag"/> - </extension> - <extension point="org.eclipse.ui.editors.markerAnnotationSpecification"> - <specification - includeOnPreferencePage="true" - colorPreferenceValue="212,212,212" - annotationType="org.eclipse.wst.xml.ui.matching.tag" - colorPreferenceKey="matchingTagIndicationColor" - presentationLayer="4" - label="%MatchingTagPreference.label" - icon="icons/full/obj16/tag-generic.gif" - textPreferenceValue="false" - textPreferenceKey="matchingTagIndication" - highlightPreferenceKey="matchingTagHighlight" - highlightPreferenceValue="true" - verticalRulerPreferenceKey="matchingTagVerticalRuler" - verticalRulerPreferenceValue="false" - overviewRulerPreferenceKey="matchingTagIndicationInOverviewRuler" - overviewRulerPreferenceValue="true" - textStylePreferenceKey="matchingTagTextStyle" - textStylePreferenceValue="NONE"> - </specification> - </extension> - - <!--======================================================================================--> - <!-- Document provider for ExternalFileEditorInput --> - <!--======================================================================================--> - <extension point="org.eclipse.ui.editors.documentProviders"> - <provider - inputTypes="org.eclipse.wst.xml.ui.internal.hyperlink.ExternalFileEditorInput" - class="org.eclipse.ui.editors.text.TextFileDocumentProvider" - id="org.eclipse.wst.xml.ui.internal.ExternalFileDocumentProvider"> - </provider> - </extension> - - <!-- To Do: migrate this to the org.eclipse.ui.menus popup: format --> - <extension point="org.eclipse.ui.popupMenus"> - <viewerContribution - targetID="org.eclipse.core.runtime.xml.source.RulerContext" - id="org.eclipse.ui.texteditor.ruler.context.actions"> - <action - label="%AddTask.label" - helpContextId="org.eclipse.ui.AddTask_action_context" - class="org.eclipse.ui.texteditor.TaskRulerAction" - tooltip="%AddTask.tooltip" - menubarPath="additions" - id="org.eclipse.ui.texteditor.TaskRulerAction"> - </action> - <action - label="%AddBookmark.label" - helpContextId="org.eclipse.ui.bookmark_action_context" - class="org.eclipse.ui.texteditor.BookmarkRulerAction" - tooltip="%AddBookmark.tooltip" - menubarPath="additions" - id="org.eclipse.ui.texteditor.BookmarkRulerAction"> - </action> - </viewerContribution> - </extension> - - <!--======================================================================================--> - <!-- Pop-up menu and associated command/handler for nested validation messages. --> - <!--======================================================================================--> - - <extension point="org.eclipse.ui.menus"> - <menuContribution locationURI="popup:org.eclipse.ui.ide.MarkersView"> - <command commandId="org.eclipse.wst.xml.ui.referencedFileErrors"> - <visibleWhen checkEnabled="false"> - <reference definitionId="org.eclipse.wst.xml.ui.referencedFileErrors" /> - </visibleWhen> - </command> - </menuContribution> - </extension> - - <extension point="org.eclipse.ui.commands"> - <command - description="%_UI_REF_FILE_SHOW_DETAILS" - id="org.eclipse.wst.xml.ui.referencedFileErrors" - name="%_UI_REF_FILE_SHOW_DETAILS" /> - </extension> - - <extension point="org.eclipse.ui.handlers"> - <handler - class="org.eclipse.wst.xml.ui.internal.validation.core.errorinfo.ReferencedFileErrorsHandler" - commandId="org.eclipse.wst.xml.ui.referencedFileErrors"> - <enabledWhen> - <reference definitionId="org.eclipse.wst.xml.ui.referencedFileErrors" /> - </enabledWhen> - </handler> - </extension> - - <extension point="org.eclipse.core.expressions.propertyTesters"> - <propertyTester - class="org.eclipse.wst.xml.ui.internal.validation.core.errorinfo.GroupNamePropertyTester" - id="org.eclipse.wst.xml.ui.markerGroupNamePropertyTester" - namespace="org.eclipse.wst.xml.ui" - properties="groupNamePrefix" - type="org.eclipse.core.resources.IMarker"> - </propertyTester> - </extension> - - <extension point="org.eclipse.core.expressions.definitions"> - <definition id="org.eclipse.wst.xml.ui.referencedFileErrors"> - <and> - <count value="1" /> - <with variable="selection"> - <iterate operator="or"> - <adapt type="org.eclipse.core.resources.IMarker"> - <test property="org.eclipse.wst.xml.ui.groupNamePrefix" value="referencedFileError" forcePluginActivation="true" /> - </adapt> - </iterate> - </with> - </and> - </definition> - </extension> - -<!-- - <extension point="org.eclipse.ui.editorActions"> - <editorContribution - id="org.eclipse.core.runtime.xml.source.editorActions" - targetID="org.eclipse.core.runtime.xml.source"> - <action - id="CleanupDocument" - label="%CleanupDocument_label" - definitionId="org.eclipse.wst.sse.ui.cleanup.document" - tooltip="%CleanupDocument_tooltip" - class="org.eclipse.wst.xml.ui.internal.actions.CleanupActionXMLDelegate" - actionID="CleanupDocument"> - </action> - <action - id="ToggleComment" - label="%ToggleComment_label" - definitionId="org.eclipse.wst.sse.ui.toggle.comment" - tooltip="%ToggleComment_tooltip" - class="org.eclipse.wst.xml.ui.internal.actions.ToggleCommentActionXMLDelegate" - actionID="ToggleComment"> - </action> - <action - id="AddBlockComment" - label="%AddBlockComment_label" - definitionId="org.eclipse.wst.sse.ui.add.block.comment" - tooltip="%AddBlockComment_tooltip" - class="org.eclipse.wst.xml.ui.internal.actions.AddBlockCommentActionXMLDelegate" - actionID="AddBlockComment"> - </action> - <action - id="RemoveBlockComment" - label="%RemoveBlockComment_label" - definitionId="org.eclipse.wst.sse.ui.remove.block.comment" - tooltip="%RemoveBlockComment_tooltip" - class="org.eclipse.wst.xml.ui.internal.actions.RemoveBlockCommentActionXMLDelegate" - actionID="RemoveBlockComment"> - </action> - <action - id="FindOccurrences" - label="%FindOccurrences_label" - definitionId="org.eclipse.wst.sse.ui.search.find.occurrences" - class="org.eclipse.wst.xml.ui.internal.search.XMLFindOccurrencesActionDelegate" - actionID="FindOccurrences"> - </action> - <action - id="StructureSelectEnclosing" - label="%StructureSelectEnclosing_label" - definitionId="org.eclipse.wst.sse.ui.structure.select.enclosing" - tooltip="%StructureSelectEnclosing_tooltip" - class="org.eclipse.wst.xml.ui.internal.selection.StructuredSelectEnclosingXMLActionDelegate" - actionID="StructureSelectEnclosing"> - </action> - <action - id="StructureSelectNext" - label="%StructureSelectNext_label" - definitionId="org.eclipse.wst.sse.ui.structure.select.next" - tooltip="%StructureSelectNext_tooltip" - class="org.eclipse.wst.xml.ui.internal.selection.StructuredSelectNextXMLActionDelegate" - actionID="StructureSelectNext"> - </action> - <action - id="StructureSelectPrevious" - label="%StructureSelectPrevious_label" - definitionId="org.eclipse.wst.sse.ui.structure.select.previous" - tooltip="%StructureSelectPrevious_tooltip" - class="org.eclipse.wst.xml.ui.internal.selection.StructuredSelectPreviousXMLActionDelegate" - actionID="StructureSelectPrevious"> - </action> - <action - id="StructureSelectHistory" - label="%StructureSelectHistory_label" - definitionId="org.eclipse.wst.sse.ui.structure.select.last" - tooltip="%StructureSelectHistory_tooltip" - class="org.eclipse.wst.sse.ui.internal.selection.StructuredSelectHistoryActionDelegate" - actionID="StructureSelectHistory"> - </action> - </editorContribution> - <editorContribution - targetID="org.eclipse.core.runtime.xml.source" - id="org.eclipse.core.runtime.xml.source.ruler.actions"> - <action - label="%AddBookmark.label" - helpContextId="org.eclipse.ui.bookmark_action_context" - class="org.eclipse.ui.texteditor.BookmarkRulerAction" - actionID="RulerDoubleClick" - id="org.eclipse.ui.texteditor.BookmarkRulerAction"/> - <action - label="%SelectRuler.label" - class="org.eclipse.ui.texteditor.SelectRulerAction" - actionID="RulerClick" - id="org.eclipse.ui.texteditor.SelectRulerAction"/> - </editorContribution> - </extension> ---> - - <extension - point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectorTargets"> - <target - id="org.eclipse.core.runtime.xml" - name="%XML_Source_target_name"> - </target> - </extension> - <extension - point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectors"> - <hyperlinkDetector - class="org.eclipse.wst.xml.ui.internal.hyperlink.XMLHyperlinkDetector" - id="org.eclipse.wst.xml.ui.internal.hyperlink.XMLHyperlinkDetector" - name="%XML_hyperlink" - targetId="org.eclipse.core.runtime.xml"> - </hyperlinkDetector> - </extension> - <extension - point="org.eclipse.ui.importWizards"> - <category - id="org.eclipse.wst.XMLCategory" - name="%_UI_WIZARD_NEW_XML"> - </category> - <wizard - category="org.eclipse.wst.XMLCategory" - class="org.eclipse.wst.xml.ui.internal.wizards.ImportXMLCatalogWizard" - icon="icons/xmldoc.gif" - id="org.eclipse.wst.xml.ui.internal.wizards.ImportXMLCatalogWizard" - name="%_UI_WIZARD_IMPORT_EXPORT_XMLCATALOG"> - <description> - %_UI_IMPORT_XML_CATALOG_FILE - </description> - </wizard> - </extension> - <extension - point="org.eclipse.ui.exportWizards"> - <category - id="org.eclipse.wst.XMLCategory" - name="%_UI_WIZARD_NEW_XML"> - </category> - <wizard - category="org.eclipse.wst.XMLCategory" - class="org.eclipse.wst.xml.ui.internal.wizards.ExportXMLCatalogWizard" - icon="icons/xmldoc.gif" - id="org.eclipse.wst.xml.ui.internal.wizards.ExportXMLCatalogWizard" - name="%_UI_WIZARD_IMPORT_EXPORT_XMLCATALOG"> - <description> - %_UI_EXPORT_XML_CATALOG_FILE - </description> - </wizard> - </extension> - - <extension point="org.eclipse.ui.commands"> - <!-- Navigate commands --> - <command - name="%ActionDefinition.nextSibling.name" - description="%ActionDefinition.nextSibling.description" - categoryId="org.eclipse.ui.category.edit" - id="org.eclipse.wst.xml.ui.nextSibling"> - </command> - <command - name="%ActionDefinition.previousSibling.name" - description="%ActionDefinition.previousSibling.description" - categoryId="org.eclipse.ui.category.edit" - id="org.eclipse.wst.xml.ui.previousSibling"> - </command> - <command - name="%ActionDefinition.gotoMatchingTag.name" - description="%ActionDefinition.gotoMatchingTag.description" - categoryId="org.eclipse.ui.category.edit" - id="org.eclipse.wst.xml.ui.gotoMatchingTag"> - </command> - </extension> - - <extension point="org.eclipse.ui.bindings"> - <!-- win32: M1=CTRL, M2=SHIFT, M3=ALT, M4=- - carbon: M1=COMMAND, M2=SHIFT, M3=ALT, M4=CTRL - gtk: ? - --> - <!-- Navigate commands --> - <key - sequence="M1+M2+ARROW_UP" - contextId="org.eclipse.wst.sse.ui.structuredTextEditorScope" - commandId="org.eclipse.wst.xml.ui.previousSibling" - schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/> - <key - platform="carbon" - sequence="CTRL+SHIFT+ARROW_UP" - contextId="org.eclipse.wst.sse.ui.structuredTextEditorScope" - commandId="org.eclipse.wst.xml.ui.previousSibling" - schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/> - <key - sequence="M1+M2+ARROW_DOWN" - contextId="org.eclipse.wst.sse.ui.structuredTextEditorScope" - commandId="org.eclipse.wst.xml.ui.nextSibling" - schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/> - <key - platform="carbon" - sequence="CTRL+SHIFT+ARROW_DOWN" - contextId="org.eclipse.wst.sse.ui.structuredTextEditorScope" - commandId="org.eclipse.wst.xml.ui.nextSibling" - schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/> - <key - sequence="M1+M2+>" - contextId="org.eclipse.wst.sse.ui.structuredTextEditorScope" - commandId="org.eclipse.wst.xml.ui.gotoMatchingTag" - schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/> - <key - platform="carbon" - sequence="CTRL+SHIFT+." - contextId="org.eclipse.wst.sse.ui.structuredTextEditorScope" - commandId="org.eclipse.wst.xml.ui.gotoMatchingTag" - schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/> - - </extension> - -<!-- - This section contains the new org.eclipse.ui.menus extions points and command handler - definitions. - --> - - <extension point="org.eclipse.ui.menus"> - <!-- Unable to contribute to Search menu at the moment due to bug 213385 --> -<!-- - <menuContribution locationURI="menu:org.eclipse.search.menu"> ---> - <menuContribution locationURI="menu:goTo?after=matchingEnd"> -<!-- - <command commandId="org.eclipse.wst.xml.ui.gotoMatchingTag" id="GoToMatchingTag" label="%GoToMatchingTag_label" style="push"> - <visibleWhen checkEnabled="false"> - <reference definitionId="org.eclipse.wst.sse.ui.sseActiveContext.definition"></reference> - </visibleWhen> - </command> ---> - <separator name="goToSiblingsBegin" visible="true"></separator> - <command commandId="org.eclipse.wst.xml.ui.nextSibling" id="GoToNextSibling" label="%ActionDefinition.nextSibling.name" style="push"> - <visibleWhen checkEnabled="false"> - <reference definitionId="org.eclipse.wst.xml.ui.navigation"></reference> - </visibleWhen> - </command> - <command commandId="org.eclipse.wst.xml.ui.previousSibling" id="GoToPreviousSibling" label="%ActionDefinition.previousSibling.name" style="push"> - <visibleWhen checkEnabled="false"> - <reference definitionId="org.eclipse.wst.xml.ui.navigation"></reference> - </visibleWhen> - </command> - <separator name="goToSiblingsEnd" visible="false"></separator> - </menuContribution> - <menuContribution - locationURI="menu:org.eclipse.ui.main.menu?before=window"> - <menu - id="org.eclipse.wst.xml.ui.designMenuId" - label="%DesignMenu_name"> - <separator - name="designStart"> - </separator> - <command - commandId="org.eclipse.wst.xml.ui.disable.grammar.constraints" - icon="icons/full/etool16/constrainon.gif" - id="ToggleGrammarConstraints" - mnemonic="%Constraints_mnemonic" - style="push"> - <visibleWhen checkEnabled="false"> - <and> - <reference definitionId="org.eclipse.wst.xml.ui.grammar"/> - <not> - <reference definitionId="org.eclipse.wst.sse.ui.sseActiveContext.definition"/> - </not> - </and> - </visibleWhen> - </command> - <command - commandId="org.eclipse.wst.xml.ui.reload.dependecies" - icon="icons/full/etool16/rldgrmr.gif" - id="ReloadDependencies" - mnemonic="%ReloadDependencies_mnemonic" - style="push"> - <visibleWhen checkEnabled="false"> - <and> - <reference definitionId="org.eclipse.wst.xml.ui.dependencies"/> - <not> - <reference definitionId="org.eclipse.wst.sse.ui.sseActiveContext.definition"/> - </not> - </and> - </visibleWhen> - </command> - <separator - name="expand" - visible="true"> - </separator> - - <command - commandId="sed.tabletree.expandAll" - icon="icons/full/etool16/expand_all.gif" - id="ExpandAll" - style="push"> - <visibleWhen checkEnabled="false"> - <and> - <reference definitionId="org.eclipse.wst.xml.ui.expand"/> - <not> - <reference definitionId="org.eclipse.wst.sse.ui.sseActiveContext.definition"/> - </not> - </and> - </visibleWhen> - </command> - <command - commandId="sed.tabletree.collapseAll" - icon="icons/full/etool16/collapse_all.gif" - id="CollapseAll" - style="push"> - <visibleWhen checkEnabled="false"> - <and> - <reference definitionId="org.eclipse.wst.xml.ui.expand"/> - <not> - <reference definitionId="org.eclipse.wst.sse.ui.sseActiveContext.definition"/> - </not> - </and> - </visibleWhen> - </command> - - <separator - name="additions" - visible="true"> - </separator> - <separator - name="designEnd" - visible="false"> - </separator> - </menu> - </menuContribution> - <menuContribution locationURI="menu:edit?after=additions"> - <command commandId="org.eclipse.ui.edit.text.contentAssist.proposals" id="XMLContentAssist" style="push"> - <visibleWhen checkEnabled="false"> - <reference definitionId="org.eclipse.wst.xml.ui.xmlSourceContributions.definition"></reference> - </visibleWhen> - </command> - </menuContribution> - <menuContribution - locationURI="popup:org.eclipse.ui.popup.any?after=additions"> - <menu - id="generateMenuId" - label="%genMenuLabel"> - <command - commandId="org.eclipse.wst.sse.ui.generate.xml" - id="GenerateXML" - style="push"> - <visibleWhen checkEnabled="false"> - <or> - <iterate ifEmpty="false"> - <adapt - type="org.eclipse.core.resources.IFile"> - <test - property="org.eclipse.wst.sse.core.resources.contentTypeId" - value="org.eclipse.wst.xsd.core.xsdsource"> - </test> - </adapt> - </iterate> - <iterate ifEmpty="false"> - <adapt - type="org.eclipse.core.resources.IFile"> - <test - property="org.eclipse.wst.sse.core.resources.contentTypeId" - value="org.eclipse.wst.dtd.core.dtdsource"> - </test> - </adapt> - </iterate> - </or> - </visibleWhen> - </command> - </menu> - </menuContribution> - - <menuContribution - locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions"> - <toolbar - id="org.eclipse.wst.xml.ui.design.DesignToolBar"> - <separator - name="sed.tabletree.separator.1" - visible="true"> - </separator> - <command - commandId="org.eclipse.wst.xml.ui.disable.grammar.constraints" - icon="icons/full/etool16/constrainon.gif" - id="ToggleGrammarConstraints" - style="push" - tooltip="%Constraints_name"> - <visibleWhen - checkEnabled="false"> - <reference - definitionId="org.eclipse.wst.xml.ui.grammar"> - </reference> - </visibleWhen> - </command> - <command - commandId="org.eclipse.wst.xml.ui.reload.dependecies" - icon="icons/full/etool16/rldgrmr.gif" - id="ReloadDependencies" - style="push"> - <visibleWhen - checkEnabled="false"> - <reference - definitionId="org.eclipse.wst.xml.ui.dependencies"> - </reference> - </visibleWhen> - </command> - <separator - name="sed.tabletree.separator.2" - visible="true"> - </separator> - <command - commandId="sed.tabletree.expandAll" - icon="icons/full/etool16/expand_all.gif" - id="ExpandAll" - style="push"> - <visibleWhen - checkEnabled="false"> - <reference - definitionId="org.eclipse.wst.xml.ui.expand"> - </reference> - </visibleWhen> - </command> - <command - commandId="sed.tabletree.collapseAll" - icon="icons/full/etool16/collapse_all.gif" - id="CollapseAll" - style="push"> - <visibleWhen - checkEnabled="false"> - <reference - definitionId="org.eclipse.wst.xml.ui.expand"> - </reference> - </visibleWhen> - </command> - </toolbar> - </menuContribution> - - <menuContribution locationURI="menu:sourceMenuId?after=sourceBegin"> - <command commandId="org.eclipse.wst.sse.ui.toggle.comment" - id="ToggleComment" - mnemonic="%command.toggle.comment.mnemonic" - style="push"> - <visibleWhen checkEnabled="false"> - <reference definitionId="org.eclipse.wst.xml.ui.comments"/> - </visibleWhen> - </command> - <command commandId="org.eclipse.wst.sse.ui.add.block.comment" - id="AddBlockComment" - mnemonic="%command.add.block.comment.mnemonic" - style="push"> - <visibleWhen checkEnabled="false"> - <reference definitionId="org.eclipse.wst.xml.ui.comments"/> - </visibleWhen> - </command> - <command commandId="org.eclipse.wst.sse.ui.remove.block.comment" - id="RemoveBlockComment" - mnemonic="%command.remove.block.comment.mnemonic" - style="push"> - <visibleWhen checkEnabled="false"> - <reference definitionId="org.eclipse.wst.xml.ui.comments"/> - </visibleWhen> - </command> - </menuContribution> - - <menuContribution - locationURI="popup:sourcePopupMenuId?after=sourceBegin"> - <command commandId="org.eclipse.wst.sse.ui.toggle.comment" id="ToggleComment" style="push"> - <visibleWhen checkEnabled="false"> - <reference definitionId="org.eclipse.wst.xml.ui.comments"></reference> - </visibleWhen> - </command> - <command commandId="org.eclipse.wst.sse.ui.add.block.comment" id="AddBlockComment" style="push"> - <visibleWhen checkEnabled="false"> - <reference definitionId="org.eclipse.wst.xml.ui.comments"></reference> - </visibleWhen> - </command> - <command commandId="org.eclipse.wst.sse.ui.remove.block.comment" id="RemoveBlockComment" style="push"> - <visibleWhen checkEnabled="false"> - <reference definitionId="org.eclipse.wst.xml.ui.comments"></reference> - </visibleWhen> - </command> - <separator name="format" visible="true"></separator> - </menuContribution> - </extension> - - <extension point="org.eclipse.core.expressions.definitions"> - <definition id="org.eclipse.wst.xml.ui.xmlSourceContributions.definition"> - <with variable="activeContexts"> - <iterate operator="or"> - <equals value="org.eclipse.core.runtime.xml"/> - </iterate> - </with> - </definition> - </extension> - - <extension point="org.eclipse.core.expressions.definitions"> - <definition id="org.eclipse.wst.xml.ui.core"> - <with variable="activeContexts"> - <iterate operator="or"> - <equals value="org.eclipse.core.runtime.xml"/> - </iterate> - </with> - </definition> - </extension> - - <extension point="org.eclipse.core.expressions.definitions"> - <definition id="org.eclipse.wst.xml.ui.occurrences"> - <with variable="activeContexts"> - <iterate operator="or"> - <equals value="org.eclipse.wst.xml.occurrences"/> - </iterate> - </with> - </definition> - </extension> - - <extension point="org.eclipse.core.expressions.definitions"> - <definition id="org.eclipse.wst.xml.ui.comments"> - <with variable="activeContexts"> - <iterate operator="or"> - <equals value="org.eclipse.wst.xml.comments"/> - </iterate> - </with> - </definition> - </extension> - - <extension point="org.eclipse.core.expressions.definitions"> - <definition id="org.eclipse.wst.xml.ui.cleanup"> - <with variable="activeContexts"> - <iterate operator="or"> - <equals value="org.eclipse.wst.xml.cleanup"/> - </iterate> - </with> - </definition> - </extension> - - <extension point="org.eclipse.core.expressions.definitions"> - <definition id="org.eclipse.wst.xml.ui.navigation"> - <with variable="activeContexts"> - <iterate operator="or"> - <equals value="org.eclipse.wst.xml.navigation"/> - </iterate> - </with> - </definition> - </extension> - - <extension point="org.eclipse.core.expressions.definitions"> - <definition id="org.eclipse.wst.xml.ui.selection"> - <with variable="activeContexts"> - <iterate operator="or"> - <equals value="org.eclipse.wst.xml.selection"/> - </iterate> - </with> - </definition> - </extension> - - <extension point="org.eclipse.core.expressions.definitions"> - <definition id="org.eclipse.wst.xml.ui.dependencies"> - <or> - <with variable="activeEditorId"> - <equals value="org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart"></equals> - </with> - <with variable="activeContexts"> - <iterate operator="or"> - <equals value="org.eclipse.wst.xml.dependencies"/> - </iterate> - </with> - </or> - </definition> - </extension> - - <extension point="org.eclipse.core.expressions.definitions"> - <definition id="org.eclipse.wst.xml.ui.grammar"> - <or> - <with variable="activeEditorId"> - <equals value="org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart"></equals> - </with> - <with variable="activeContexts"> - <iterate operator="or"> - <equals value="org.eclipse.wst.xml.grammar"/> - </iterate> - </with> - </or> - </definition> - </extension> - - <extension point="org.eclipse.core.expressions.definitions"> - <definition id="org.eclipse.wst.xml.ui.expand"> - <or> - <with variable="activeEditorId"> - <equals value="org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart"></equals> - </with> - <with variable="activeContexts"> - <iterate operator="or"> - <equals value="org.eclipse.wst.xml.expand"/> - </iterate> - </with> - </or> - </definition> - </extension> - - <extension - point="org.eclipse.ui.handlers"> - <handler - class="org.eclipse.wst.xml.ui.internal.handlers.CleanupdocumentHandler" - commandId="org.eclipse.wst.sse.ui.cleanup.document"> - <activeWhen> - <reference definitionId="org.eclipse.wst.xml.ui.cleanup"/> - </activeWhen> - <enabledWhen> - <reference definitionId="org.eclipse.wst.xml.ui.cleanup"/> - </enabledWhen> - </handler> - <handler - class="org.eclipse.wst.xml.ui.internal.handlers.ToggleCommentHandler" - commandId="org.eclipse.wst.sse.ui.toggle.comment"> - <activeWhen> - <reference definitionId="org.eclipse.wst.xml.ui.comments"/> - </activeWhen> - <enabledWhen> - <reference definitionId="org.eclipse.wst.xml.ui.comments"/> - </enabledWhen> - </handler> - <handler - class="org.eclipse.wst.xml.ui.internal.handlers.AddBlockCommentHandler" - commandId="org.eclipse.wst.sse.ui.add.block.comment"> - <activeWhen> - <reference definitionId="org.eclipse.wst.xml.ui.comments"/> - </activeWhen> - <enabledWhen> - <reference definitionId="org.eclipse.wst.xml.ui.comments"/> - </enabledWhen> - </handler> - <handler - class="org.eclipse.wst.xml.ui.internal.handlers.RemoveBlockCommentHandler" - commandId="org.eclipse.wst.sse.ui.remove.block.comment"> - <activeWhen> - <reference definitionId="org.eclipse.wst.xml.ui.comments"/> - </activeWhen> - <enabledWhen> - <reference definitionId="org.eclipse.wst.xml.ui.comments"/> - </enabledWhen> - </handler> - <handler - class="org.eclipse.wst.xml.ui.internal.handlers.StructuredSelectEnclosingXMLHandler" - commandId="org.eclipse.wst.sse.ui.structure.select.enclosing"> - <activeWhen> - <reference definitionId="org.eclipse.wst.xml.ui.selection"/> - </activeWhen> - <enabledWhen> - <reference definitionId="org.eclipse.wst.xml.ui.selection"/> - </enabledWhen> - </handler> - <handler - class="org.eclipse.wst.xml.ui.internal.handlers.StructuredSelectNextXMLHandler" - commandId="org.eclipse.wst.sse.ui.structure.select.next"> - <activeWhen> - <reference definitionId="org.eclipse.wst.xml.ui.selection"/> - </activeWhen> - <enabledWhen> - <reference definitionId="org.eclipse.wst.xml.ui.selection"/> - </enabledWhen> - </handler> - <handler - class="org.eclipse.wst.xml.ui.internal.handlers.StructuredSelectPreviousXMLHandler" - commandId="org.eclipse.wst.sse.ui.structure.select.previous"> - <activeWhen> - <reference definitionId="org.eclipse.wst.xml.ui.selection"/> - </activeWhen> - <enabledWhen> - <reference definitionId="org.eclipse.wst.xml.ui.selection"/> - </enabledWhen> - </handler> - <handler - class="org.eclipse.wst.sse.ui.internal.handlers.StructuredSelectHistoryHandler" - commandId="org.eclipse.wst.sse.ui.structure.select.last"> - <activeWhen> - <reference definitionId="org.eclipse.wst.xml.ui.selection"/> - </activeWhen> - <enabledWhen> - <reference definitionId="org.eclipse.wst.xml.ui.selection"/> - </enabledWhen> - </handler> - <handler - class="org.eclipse.wst.xml.ui.internal.handlers.XMLFindOccurencesHandler" - commandId="org.eclipse.wst.sse.ui.search.find.occurrences"> - <activeWhen> - <reference definitionId="org.eclipse.wst.xml.ui.occurrences"/> - </activeWhen> - <enabledWhen> - <reference definitionId="org.eclipse.wst.xml.ui.occurrences"/> - </enabledWhen> - </handler> -<!-- - <handler - class="org.eclipse.wst.xml.ui.internal.handlers.GoToMatchingTagHandler" - commandId="org.eclipse.wst.xml.ui.gotoMatchingTag"> - <activeWhen> - <reference definitionId="org.eclipse.wst.xml.ui.navigation"/> - </activeWhen> - <enabledWhen> - <reference definitionId="org.eclipse.wst.xml.ui.navigation"/> - </enabledWhen> - </handler> ---> - <handler - class="org.eclipse.wst.xml.ui.internal.handlers.NextSiblingNavigationHandler" - commandId="org.eclipse.wst.xml.ui.nextSibling"> - <activeWhen> - <reference definitionId="org.eclipse.wst.xml.ui.navigation"/> - </activeWhen> - <enabledWhen> - <reference definitionId="org.eclipse.wst.xml.ui.navigation"/> - </enabledWhen> - </handler> - <handler - class="org.eclipse.wst.xml.ui.internal.handlers.PreviousSiblingNavigationHandler" - commandId="org.eclipse.wst.xml.ui.previousSibling"> - <activeWhen> - <reference definitionId="org.eclipse.wst.xml.ui.navigation"/> - </activeWhen> - <enabledWhen> - <reference definitionId="org.eclipse.wst.xml.ui.navigation"/> - </enabledWhen> - </handler> - <handler - class="org.eclipse.wst.xml.ui.internal.handlers.ReloadDependenciesHandler" - commandId="org.eclipse.wst.xml.ui.reload.dependecies"> - <activeWhen> - <reference definitionId="org.eclipse.wst.xml.ui.dependencies"/> - </activeWhen> - <enabledWhen> - <reference definitionId="org.eclipse.wst.xml.ui.dependencies"/> - </enabledWhen> - </handler> - <handler - class="org.eclipse.wst.xml.ui.internal.handlers.ToggleEditModeHandler" - commandId="org.eclipse.wst.xml.ui.disable.grammar.constraints"> - <activeWhen> - <reference definitionId="org.eclipse.wst.xml.ui.grammar"/> - </activeWhen> - <enabledWhen> - <reference definitionId="org.eclipse.wst.xml.ui.grammar"/> - </enabledWhen> - </handler> - <handler - class="org.eclipse.wst.xml.ui.internal.wizards.NewXMLHandler" - commandId="org.eclipse.wst.sse.ui.generate.xml"> - </handler> - <handler - class="org.eclipse.wst.xml.ui.internal.handlers.ExpandAllHandler" - commandId="sed.tabletree.expandAll"> - <activeWhen> - <not> - <with variable="activeContexts"> - <iterate operator="or"> - <equals value="org.eclipse.wst.sse.ui.structuredTextEditorScope"/> - </iterate> - </with> - </not> - </activeWhen> - </handler> - <handler - class="org.eclipse.wst.xml.ui.internal.handlers.CollapseAllHandler" - commandId="sed.tabletree.collapseAll"> - <activeWhen> - <not> - <with variable="activeContexts"> - <iterate operator="or"> - <equals value="org.eclipse.wst.sse.ui.structuredTextEditorScope"/> - </iterate> - </with> - </not> - </activeWhen> - </handler> - </extension> - - <extension - point="org.eclipse.ui.commands"> - <command - id="org.eclipse.wst.sse.ui.generate.xml" - name="%_UI_ACTION_CREATE_XML"> - </command> - <command - description="%ReloadDependencies_description" - id="org.eclipse.wst.xml.ui.reload.dependecies" - name="%ReloadDependencies_name"> - </command> - <command - description="%Constraints_description" - id="org.eclipse.wst.xml.ui.disable.grammar.constraints" - name="%Constraints_name"> - </command> - <command - id="sed.tabletree.expandAll" - name="%ExpandAll_name"> - </command> - <command - id="sed.tabletree.collapseAll" - name="%CollapseAll_name"> - </command> - </extension> - - <!-- Define theme --> - <extension - point="org.eclipse.ui.themes"> - <theme - id="org.eclipse.ui.ide.systemDefault"> - <colorOverride - id="tagAttributeName" - value="COLOR_LIST_FOREGROUND"> - </colorOverride> - <colorOverride - id="tagAttributeValue" - value="COLOR_LIST_FOREGROUND"> - </colorOverride> - <colorOverride - id="commentBorder" - value="COLOR_LIST_SELECTION"> - </colorOverride> - <colorOverride - id="commentText" - value="COLOR_LIST_SELECTION"> - </colorOverride> - <colorOverride - id="declBoder" - value="COLOR_LIST_FOREGROUND"> - </colorOverride> - <colorOverride - id="doctypeName" - value="COLOR_LIST_FOREGROUND"> - </colorOverride> - <colorOverride - id="doctypeExternalPubref" - value="COLOR_LIST_FOREGROUND"> - </colorOverride> - <colorOverride - id="doctypeExternalId" - value="COLOR_WIDGET_NORMAL_SHADOW"> - </colorOverride> - <colorOverride - id="doctypeExtrenalSysref" - value="COLOR_LIST_FOREGROUND"> - </colorOverride> - <colorOverride - id="tagBorder" - value="COLOR_LIST_FOREGROUND"> - </colorOverride> - <colorOverride - id="tagName" - value="COLOR_LIST_FOREGROUND"> - </colorOverride> - <colorOverride - id="piBorder" - value="COLOR_LIST_FOREGROUND"> - </colorOverride> - <colorOverride - id="cdataBorder" - value="COLOR_LIST_FOREGROUND"> - </colorOverride> - <colorOverride - id="cdataText" - value="COLOR_LIST_FOREGROUND"> - </colorOverride> - <colorOverride - id="entityReference" - value="COLOR_LIST_FOREGROUND"> - </colorOverride> - </theme> - <colorDefinition - id="tagAttributeName" - isEditable="false" - label="%Colors.tagAttributeName" - value="127, 0, 127"> - </colorDefinition> - <colorDefinition - id="tagAttributeValue" - isEditable="false" - label="%Colors.tagAttributeValue" - value="42, 0, 255"> - </colorDefinition> - <colorDefinition - id="commentBorder" - isEditable="false" - label="%Colors.commentBorder" - value="63, 95, 191"> - </colorDefinition> - <colorDefinition - id="commentText" - isEditable="false" - label="%Colors.commentText" - value="63, 95, 191"> - </colorDefinition> - <colorDefinition - id="declBoder" - isEditable="false" - label="%Colors.declBorder" - value="0, 128, 128"> - </colorDefinition> - <colorDefinition - id="doctypeName" - isEditable="false" - label="%Colors.doctypeName" - value="0, 128, 128"> - </colorDefinition> - <colorDefinition - id="doctypeExternalPubref" - isEditable="false" - label="%Colors.doctypeExternalPubref" - value="0, 128, 128"> - </colorDefinition> - <colorDefinition - id="doctypeExternalId" - isEditable="false" - label="%Colors.doctypeExternalId" - value="128, 128, 128"> - </colorDefinition> - <colorDefinition - id="doctypeExtrenalSysref" - isEditable="false" - label="%Colors.doctypeExtrenalSysref" - value="63, 127, 95"> - </colorDefinition> - <colorDefinition - id="tagBorder" - isEditable="false" - label="%Colors.tagBorder" - value="0, 128, 128"> - </colorDefinition> - <colorDefinition - id="tagName" - isEditable="false" - label="%Colors.tagName" - value="63, 127, 127"> - </colorDefinition> - <colorDefinition - id="piBorder" - isEditable="false" - label="%Colors.piBorder" - value="0, 128, 128"> - </colorDefinition> - <colorDefinition - id="cdataBorder" - isEditable="false" - label="%Colors.cdataBorder" - value="0, 128, 128"> - </colorDefinition> - <colorDefinition - id="cdataText" - isEditable="false" - label="%Colors.cdataText" - value="0, 0, 0"> - </colorDefinition> - <colorDefinition - id="entityReference" - isEditable="false" - label="%Colors.entityReference" - value="42, 0, 255"> - </colorDefinition> - </extension> - - <!-- Enable the FormatHandler for XML Content Type --> - <extension point="org.eclipse.ui.handlers"> - <handler - class="org.eclipse.wst.sse.ui.internal.handlers.FormatHandler" - commandId="org.eclipse.wst.sse.ui.format"> - <activeWhen> - <reference definitionId="org.eclipse.wst.xml.ui.xmlContentType.definition"></reference> - </activeWhen> - <enabledWhen> - <reference definitionId="org.eclipse.wst.xml.ui.xmlContentType.definition"></reference> - </enabledWhen> - </handler> - </extension> - - <!-- Set up a definition for XML Content Types --> - <extension point="org.eclipse.core.expressions.definitions"> - <definition id="org.eclipse.wst.xml.ui.xmlContentType.definition"> - <or> - <iterate ifEmpty="false"> - <adapt type="org.eclipse.core.resources.IFile"> - <test property="org.eclipse.wst.sse.core.resources.contentTypeId" - value="org.eclipse.wst.xml.core.xmlsource"/> - </adapt> - </iterate> - <iterate ifEmpty="false"> - <adapt type="org.eclipse.core.resources.IFile"> - <test property="org.eclipse.wst.sse.core.resources.contentTypeId" - value="org.eclipse.core.runtime.xml"/> - </adapt> - </iterate> - </or> - </definition> - </extension> -</plugin> diff --git a/bundles/org.eclipse.wst.xml.ui/schema/catalogFileType.exsd b/bundles/org.eclipse.wst.xml.ui/schema/catalogFileType.exsd deleted file mode 100644 index 3629659d4d..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/schema/catalogFileType.exsd +++ /dev/null @@ -1,120 +0,0 @@ -<?xml version='1.0' encoding='UTF-8'?> -<!-- Schema file written by PDE --> -<schema targetNamespace="org.eclipse.wst.xml.ui"> -<annotation> - <appInfo> - <meta.schema plugin="org.eclipse.wst.xml.ui" id="catalogFileType" name="XML Catalog file type extension point"/> - </appInfo> - <documentation> - <b>This extension point is internal and should not be used by any other plugins.</b> - </documentation> - </annotation> - - <element name="extension"> - <complexType> - <sequence> - <element ref="fileType" minOccurs="1" maxOccurs="unbounded"/> - </sequence> - <attribute name="point" type="string" use="required"> - <annotation> - <documentation> - - </documentation> - </annotation> - </attribute> - <attribute name="id" type="string"> - <annotation> - <documentation> - - </documentation> - </annotation> - </attribute> - <attribute name="name" type="string"> - <annotation> - <documentation> - - </documentation> - <appInfo> - <meta.attribute translatable="true"/> - </appInfo> - </annotation> - </attribute> - </complexType> - </element> - - <element name="fileType"> - <complexType> - <attribute name="extensions" type="string" use="required"> - <annotation> - <documentation> - - </documentation> - </annotation> - </attribute> - <attribute name="description" type="string" use="required"> - <annotation> - <documentation> - - </documentation> - </annotation> - </attribute> - <attribute name="id" type="string" use="required"> - <annotation> - <documentation> - - </documentation> - </annotation> - </attribute> - </complexType> - </element> - - <annotation> - <appInfo> - <meta.section type="since"/> - </appInfo> - <documentation> - <b>This extension point is internal and should not be used by any other plugins.</b> - </documentation> - </annotation> - - <annotation> - <appInfo> - <meta.section type="examples"/> - </appInfo> - <documentation> - - </documentation> - </annotation> - - <annotation> - <appInfo> - <meta.section type="apiInfo"/> - </appInfo> - <documentation> - - </documentation> - </annotation> - - <annotation> - <appInfo> - <meta.section type="implementation"/> - </appInfo> - <documentation> - - </documentation> - </annotation> - - <annotation> - <appInfo> - <meta.section type="copyright"/> - </appInfo> - <documentation> - Copyright (c) 2000, 2005 IBM Corporation and others.<br> -All rights reserved. This program and the accompanying materials are made -available under the terms of the Eclipse Public License v1.0 which accompanies -this distribution, and is available at <a -href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a> - </documentation> - </annotation> - -</schema> diff --git a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/AdvancedOptionsDialog.java b/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/AdvancedOptionsDialog.java deleted file mode 100644 index ac1dec6230..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/AdvancedOptionsDialog.java +++ /dev/null @@ -1,229 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.catalog; - -import java.io.ByteArrayInputStream; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.window.Window; -import org.eclipse.osgi.util.NLS; -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.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.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.dialogs.SaveAsDialog; -import org.eclipse.wst.common.ui.internal.dialogs.SelectSingleFileDialog; -import org.eclipse.wst.xml.core.internal.catalog.CatalogSet; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; - -public class AdvancedOptionsDialog extends Dialog { - protected ICatalog workingUserCatalog; - - public AdvancedOptionsDialog(Shell parentShell, ICatalog workingUserCatalog) { - super(parentShell); - setShellStyle(getShellStyle() | SWT.RESIZE); - this.workingUserCatalog = workingUserCatalog; - } - - - protected void createButtonsForButtonBar(Composite parent) { - createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); - } - - - protected Control createDialogArea(Composite parent) { - Composite dialogArea = (Composite) super.createDialogArea(parent); - // WorkbenchHelp.setHelp(dialogArea, new - // ControlContextComputer(dialogArea, - // XMLBuilderContextIds.XMLP_PROJECT_DIALOG)); - - Composite composite = new Composite(dialogArea, SWT.NONE); - composite.setLayout(new GridLayout()); - composite.setLayoutData(new GridData(GridData.FILL_BOTH)); - - Label label = new Label(composite, SWT.NONE); - label.setText(XMLCatalogMessages.UI_LABEL_DIALOG_DESCRIPTION); - - Composite buttonComposite = new Composite(composite, SWT.NONE); - GridLayout gridLayout = new GridLayout(); - gridLayout.numColumns = 3; - buttonComposite.setLayout(gridLayout); - buttonComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - Composite placeHolder = new Composite(buttonComposite, SWT.NONE); - placeHolder.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - Composite buttonGroup = new Composite(buttonComposite, SWT.NONE); - gridLayout = new GridLayout(); - gridLayout.numColumns = 2; - gridLayout.makeColumnsEqualWidth = true; - buttonGroup.setLayout(gridLayout); - buttonGroup.setLayoutData(createGridData()); - - Button importButton = new Button(buttonGroup, SWT.PUSH | SWT.CENTER); - importButton.setText(" " + XMLCatalogMessages.UI_BUTTON_IMPORT + " "); //$NON-NLS-1$ //$NON-NLS-2$ - - Button exportButton = new Button(buttonGroup, SWT.PUSH | SWT.CENTER); - exportButton.setText(" " + XMLCatalogMessages.UI_BUTTON_EXPORT + " "); //$NON-NLS-1$ //$NON-NLS-2$ - - placeHolder = new Composite(buttonComposite, SWT.NONE); - placeHolder.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - // add importButton listener - SelectionListener importButtonSelectionListener = new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - invokeImportDialog(); - } - }; - importButton.addSelectionListener(importButtonSelectionListener); - - // add exportButton listener - SelectionListener exportButtonSelectionListener = new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - invokeExportDialog(); - } - }; - exportButton.addSelectionListener(exportButtonSelectionListener); - - return dialogArea; - } - - protected GridData createGridData() { - GridData gd = new GridData(GridData.CENTER); - gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_CENTER; - gd.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER; - return gd; - } - - - protected void invokeImportDialog() { - SelectSingleFileDialog dialog = new SelectSingleFileDialog(getShell(), null, true); - String[] extensions = {".xmlcatalog", ".xml"}; //$NON-NLS-1$ //$NON-NLS-2$ - dialog.addFilterExtensions(extensions); - dialog.create(); - dialog.getShell().setText(XMLCatalogMessages.UI_LABEL_IMPORT_DIALOG_TITLE); - dialog.setTitle(XMLCatalogMessages.UI_LABEL_IMPORT_DIALOG_HEADING); - dialog.setMessage(XMLCatalogMessages.UI_LABEL_IMPORT_DIALOG_MESSAGE); - dialog.setBlockOnOpen(true); - int rc = dialog.open(); - if (rc == Window.OK) { - IFile file = dialog.getFile(); - if (file != null) { - String fileName = file.getLocation().toFile().toURI().toString(); - try { - CatalogSet tempResourceSet = new CatalogSet(); - ICatalog newCatalog = tempResourceSet.lookupOrCreateCatalog("temp", fileName); //$NON-NLS-1$ - workingUserCatalog.addEntriesFromCatalog(newCatalog); - } - catch (Exception e) { - // TODO... give error message - } - } - close(); - } - } - - - protected void invokeExportDialog() { - IPath originalFilePath = null; - IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); - if (projects.length > 0) { - originalFilePath = projects[0].getFullPath().append(".xmlcatalog"); //$NON-NLS-1$ - } - - SaveAsDialog dialog = new SaveAsDialog(getShell()); - if (originalFilePath != null) { - IFile originalFile = ResourcesPlugin.getWorkspace().getRoot().getFile(originalFilePath); - dialog.setOriginalFile(originalFile); - } - dialog.create(); - - dialog.getShell().setText(XMLCatalogMessages.UI_LABEL_EXPORT_DIALOG_TITLE); - dialog.setTitle(XMLCatalogMessages.UI_LABEL_EXPORT_DIALOG_HEADING); - dialog.setMessage(XMLCatalogMessages.UI_LABEL_EXPORT_DIALOG_MESSAGE); - - dialog.setBlockOnOpen(true); - int rc = dialog.open(); - if (rc == Window.OK) { - IPath path = dialog.getResult(); - if (path != null) { - IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); - String fileName = file.getLocation().toFile().toURI().toString(); - - // here we save the catalog entries to the selected file - try { - createFileIfRequired(file); - workingUserCatalog.setLocation(fileName); - workingUserCatalog.save(); - } - catch (Exception ex) { - try { - String title = XMLCatalogMessages.UI_LABEL_CATALOG_SAVE_ERROR; - String briefMessage = XMLCatalogMessages.UI_LABEL_CATALOG_COULD_NOT_BE_SAVED; - String reason = file.isReadOnly() ? NLS.bind(XMLCatalogMessages.UI_LABEL_FILE_IS_READ_ONLY, fileName) : NLS.bind(XMLCatalogMessages.ERROR_SAVING_FILE, fileName); - String details = NLS.bind(XMLCatalogMessages.ERROR_SAVING_FILE, fileName); - - ErrorDialog.openError(Display.getCurrent().getActiveShell(), title, briefMessage, createStatus(reason, details)); - } - catch (Exception ex2) { - } - } - close(); - } - } - } - - // TODO... This was copied from WindowUtility. Is there an easier way to - // create a status object? - // If not, we should open an eclipse bug or add a similar utility to - // baseExtensionsUI. - // - private static IStatus createStatus(String reason, String msg) { - String pluginId = XMLUIPlugin.getDefault().getBundle().getSymbolicName(); - MultiStatus multiStatus = new MultiStatus(pluginId, 0, reason, null); - Status status = new Status(IStatus.ERROR, pluginId, 0, msg, null); - multiStatus.add(status); - return multiStatus; - } - - - protected void createFileIfRequired(IFile file) { - try { - if ((file != null) && !file.exists()) { - ByteArrayInputStream inputStream = new ByteArrayInputStream(new byte[0]); - file.create(inputStream, true, null); - // createEmptyXMLCatalog(file); - } - } - catch (Exception e) { - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/CatalogFileTypeRegistryReader.java b/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/CatalogFileTypeRegistryReader.java deleted file mode 100644 index 6165312083..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/CatalogFileTypeRegistryReader.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.wst.xml.ui.internal.catalog; - -import java.util.Collection; -import java.util.HashMap; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.IExtensionRegistry; -import org.eclipse.core.runtime.Platform; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; - -public class CatalogFileTypeRegistryReader { - private static CatalogFileTypeRegistryReader _instance; - - static final String ATT_DESCRIPTION = "description"; //$NON-NLS-1$ - - static final String ATT_EXTENSIONS = "extensions"; //$NON-NLS-1$ - - static final String ATT_ICON = "icon"; //$NON-NLS-1$ - - static final String ATT_ID = "id"; //$NON-NLS-1$ - - static final String EXTENSION_POINT_ID = "catalogFileType"; //$NON-NLS-1$ - - static final String TAG_NAME = "fileType"; //$NON-NLS-1$ - - private static CatalogFileTypeRegistryReader getInstance() { - if (_instance == null) { - _instance = new CatalogFileTypeRegistryReader(); - } - return _instance; - } - - public static Collection getXMLCatalogFileTypes() { - return getInstance().hashMap.values(); - } - - private HashMap hashMap; - - public CatalogFileTypeRegistryReader() { - this.hashMap = new HashMap(); - readRegistry(); - } - - private void readElement(IConfigurationElement element) { - if (element.getName().equals(TAG_NAME)) { - String id = element.getAttribute(ATT_ID); - if (id != null) { - XMLCatalogFileType fileType = (XMLCatalogFileType) hashMap.get(id); - if (fileType == null) { - fileType = new XMLCatalogFileType(); - hashMap.put(id, fileType); - } - - if (fileType.description == null) { - String description = element.getAttribute(ATT_DESCRIPTION); - fileType.description = description; - } - - fileType.addExtensions(element.getAttribute(ATT_EXTENSIONS)); - } - } - } - - private void readRegistry() { - readRegistry(EXTENSION_POINT_ID); - } - - private void readRegistry(String extensionPointId) { - IExtensionRegistry pluginRegistry = Platform.getExtensionRegistry(); - IExtensionPoint point = pluginRegistry.getExtensionPoint(XMLUIPlugin.ID, extensionPointId); - if (point != null) { - IConfigurationElement[] elements = point.getConfigurationElements(); - for (int i = 0; i < elements.length; i++) { - readElement(elements[i]); - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/EditCatalogEntryDialog.java b/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/EditCatalogEntryDialog.java deleted file mode 100644 index 302c29b6c6..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/EditCatalogEntryDialog.java +++ /dev/null @@ -1,1053 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.catalog; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.resources.IFile; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.layout.FormAttachment; -import org.eclipse.swt.layout.FormData; -import org.eclipse.swt.layout.FormLayout; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.FileDialog; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.MenuItem; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; -import org.eclipse.swt.widgets.ToolBar; -import org.eclipse.swt.widgets.ToolItem; -import org.eclipse.swt.widgets.Widget; -import org.eclipse.ui.part.PageBook; -import org.eclipse.wst.common.ui.internal.dialogs.SelectSingleFileDialog; -import org.eclipse.wst.common.uriresolver.internal.URI; -import org.eclipse.wst.common.uriresolver.internal.util.URIHelper; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogElement; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry; -import org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog; - -public class EditCatalogEntryDialog extends Dialog { - protected static Image borwseImage = ImageFactory.INSTANCE.getImage("icons/obj16/file_expand.gif"); //$NON-NLS-1$ - protected static Image catalogEntryToolBarImage = ImageFactory.INSTANCE.getImage("icons/etool50/catalogEntry.gif"); //$NON-NLS-1$ - protected static Image nextCatalogToolBarImage = ImageFactory.INSTANCE.getImage("icons/etool50/nextCatalog.gif"); //$NON-NLS-1$ - - protected class CatalogEntryPage extends CatalogElementPage { - - protected Button browseButton; - - protected ICatalogEntry catalogEntry; - - protected Button checkboxButton; - - protected Label errorMessageLabel; - - protected Text keyField; - - protected Combo keyTypeCombo; - - protected Text resourceLocationField; - - protected Combo resourceTypeCombo; - - protected Text webAddressField; - - protected String key; - - protected int type; - - protected void computeErrorMessage() { - errorMessage = null; - warningMessage = null; - - if (errorMessage == null) { - String fileName = resourceLocationField.getText(); - if (fileName.trim().length() > 0) { - if ((fileName.indexOf("..") != -1) || (fileName.indexOf("./") != -1) || (fileName.indexOf("/.") != -1) || (fileName.indexOf(".\\") != -1) || (fileName.indexOf("\\.") != -1)) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ - errorMessage = XMLCatalogMessages.UI_WARNING_URI_MUST_NOT_HAVE_DOTS; - } - - String uri = fileName; - if (!URIHelper.hasProtocol(uri)) { - URIHelper.isAbsolute(uri); - uri = (URIHelper.isAbsolute(uri)) ? URIHelper.prependFileProtocol(uri) : URIHelper.prependPlatformResourceProtocol(uri); - } - - if ((errorMessage == null) && !URIHelper.isReadableURI(uri, false)) { - errorMessage = XMLCatalogMessages.UI_WARNING_URI_NOT_FOUND_COLON + fileName; - } - } - else { - // this an error that is not actaully - // reported ... OK is just disabled - errorMessage = ""; //$NON-NLS-1$ - } - - // Make sure the key is a fully qualified URI in the cases - // where the key type is "System ID" or "Schema location" - if ((keyField.getText().length() > 0) && (getKeyType() == ICatalogEntry.ENTRY_TYPE_SYSTEM)) { - URI uri = URI.createURI(keyField.getText()); - if (uri.scheme() == null) { - warningMessage = XMLCatalogMessages.UI_WARNING_SHOULD_BE_FULLY_QUALIFIED_URI; - } - } - } - - if ((errorMessage == null) && checkboxButton.getSelection() && (webAddressField.getText().trim().length() == 0)) { - // this an error that is not actaully - // reported ... OK is just disabled - errorMessage = ""; //$NON-NLS-1$ - } - - if ((errorMessage == null) && (keyField.getText().trim().length() == 0)) { - // this an error that is not actaully - // reported ... OK is just disabled - errorMessage = ""; //$NON-NLS-1$ - } - } - - protected Control createCatalogEntryPanel(Composite parent) { - - ModifyListener modifyListener = new ModifyListener() { - public void modifyText(ModifyEvent e) { - if (e.widget == resourceLocationField) { - if (keyField.getText().length() == 0) { - String uri = resourceLocationField.getText(); - if (uri.endsWith("xsd") && !URIHelper.hasProtocol(uri)) { //$NON-NLS-1$ - uri = URIHelper.isAbsolute(uri) ? URIHelper.prependFileProtocol(uri) : URIHelper.prependPlatformResourceProtocol(uri); - String namespaceURI = XMLQuickScan.getTargetNamespaceURIForSchema(uri); - if (namespaceURI != null) { - keyField.setText(namespaceURI); - } - } - } - } - updateWidgets(e.widget); - } - }; - - - Composite composite = new Composite(parent, SWT.NONE); - GridData gd = new GridData(GridData.FILL_BOTH); - composite.setLayoutData(gd); - - GridLayout layout = new GridLayout(); - composite.setLayout(layout); - - Composite group = new Composite(composite, SWT.NONE); - gd = new GridData(GridData.FILL_HORIZONTAL); - group.setLayoutData(gd); - - layout = new GridLayout(3, false); - group.setLayout(layout); - - Label resourceLocationLabel = new Label(group, SWT.NONE); - resourceLocationLabel.setText(XMLCatalogMessages.UI_LABEL_LOCATION_COLON); - - resourceLocationField = new Text(group, SWT.SINGLE | SWT.BORDER); - gd = new GridData(); - gd.horizontalAlignment = SWT.FILL; - gd.grabExcessHorizontalSpace = true; - resourceLocationField.setLayoutData(gd); - - resourceLocationField.setText(getDisplayValue(URIUtils.convertURIToLocation(getEntry().getURI()))); - - // WorkbenchHelp.setHelp(resourceLocationField, - // XMLBuilderContextIds.XMLP_ENTRY_URI); - resourceLocationField.addModifyListener(modifyListener); - - - browseButton = createBrowseButton(group); - // WorkbenchHelp.setHelp(browseButton, - // XMLBuilderContextIds.XMLP_ENTRY_BROWSE); - browseButton.addSelectionListener(new DropDownSelectionListener(resourceLocationField)); - - // Key Type - // - Label keyTypeLabel = new Label(group, SWT.NONE); - keyTypeLabel.setText(XMLCatalogMessages.UI_KEY_TYPE_COLON); - - keyTypeCombo = new Combo(group, SWT.NONE); - gd = new GridData(); - gd.horizontalAlignment = SWT.FILL; - gd.grabExcessHorizontalSpace = true; - keyTypeCombo.setLayoutData(gd); - updateKeyTypeCombo(getEntry().getEntryType()); - keyTypeCombo.addModifyListener(modifyListener); - // WorkbenchHelp.setHelp(keyTypeCombo, - // XMLBuilderContextIds.XMLP_ENTRY_KEY_TYPE); - - // a placeholder to fill the 3rd column - Button placeHolder = new Button(group, SWT.NONE); - placeHolder.setVisible(false); - - // Key - // - Label keyValueLabel = new Label(group, SWT.NONE); - keyValueLabel.setText(XMLCatalogMessages.UI_LABEL_KEY_COLON); - keyField = new Text(group, SWT.SINGLE | SWT.BORDER); - // WorkbenchHelp.setHelp(keyField, - // XMLBuilderContextIds.XMLP_ENTRY_KEY); - keyField.setLayoutData(gd); - keyField.setText(getDisplayValue(getEntry().getKey())); - keyField.addModifyListener(modifyListener); - - Composite group2 = new Composite(composite, SWT.NONE); - gd = new GridData(GridData.FILL_HORIZONTAL); - group2.setLayoutData(gd); - - layout = new GridLayout(); - group2.setLayout(layout); - - // checkbox -- note parent is dialogArea - // - checkboxButton = new Button(group2, SWT.CHECK); - // WorkbenchHelp.setHelp(checkboxButton, - // XMLBuilderContextIds.XMLP_ENTRY_SPECIFY_ALTERNATIVE); - checkboxButton.setText(XMLCatalogMessages.UI_LABEL_SPECIFY_ALTERNATIVE_WEB_URL); - checkboxButton.setLayoutData(new GridData()); - checkboxButton.setSelection(getEntry().getAttributeValue(ICatalogEntry.ATTR_WEB_URL) != null); - SelectionListener buttonListener = new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent event) { - // no impl - } - - public void widgetSelected(SelectionEvent event) { - if (event.widget == checkboxButton) { - updateWidgets(checkboxButton); - } - } - }; - checkboxButton.addSelectionListener(buttonListener); - - // Web Address field - // - - ModifyListener webAddressFieldListener = new ModifyListener() { - public void modifyText(ModifyEvent e) { - computeErrorMessage(); - updateErrorMessageLabel(errorMessageLabel); - updateOKButtonState(); - } - }; - - webAddressField = new Text(group2, SWT.SINGLE | SWT.BORDER); - // WorkbenchHelp.setHelp(webAddressField, - // XMLBuilderContextIds.XMLP_ENTRY_WEB_ADDRESS); - webAddressField.setLayoutData(gd); - webAddressField.setText(getDisplayValue(getEntry().getAttributeValue(ICatalogEntry.ATTR_WEB_URL))); - webAddressField.setEnabled(false); - webAddressField.addModifyListener(webAddressFieldListener); - - - errorMessageLabel = new Label(group2, SWT.NONE); - errorMessageLabel.setForeground(color); - errorMessageLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - updateWidgets(null); - - key = getEntry().getKey(); - type = getEntry().getEntryType(); - - return composite; - } - - public Control createControl(Composite parent) { - - fControl = createCatalogEntryPanel(parent); - - return fControl; - } - - - public ICatalogElement getData() { - return getEntry(); - } - - protected ICatalogEntry getEntry() { - if (catalogEntry == null) { - if ((fCatalogElement != null) && (fCatalogElement.getType() == ICatalogElement.TYPE_ENTRY)) { - catalogEntry = (ICatalogEntry) fCatalogElement; - } - else { - if (catalog != null) { - catalogEntry = (ICatalogEntry) catalog.createCatalogElement(ICatalogElement.TYPE_ENTRY); - } - } - } - return catalogEntry; - } - - protected int getKeyType() { - switch (keyTypeCombo.getSelectionIndex()) { - case 0 : - if ("schema".equals(keyTypeCombo.getData("keyType"))) { //$NON-NLS-1$ //$NON-NLS-2$ - return ICatalogEntry.ENTRY_TYPE_URI; // xsd - // namespace - // is URI type - // key - } - return ICatalogEntry.ENTRY_TYPE_PUBLIC; - case 1 : - return ICatalogEntry.ENTRY_TYPE_SYSTEM; - case 2 : - return ICatalogEntry.ENTRY_TYPE_URI; - default : - return ICatalogEntry.ENTRY_TYPE_PUBLIC; - } - } - - public void saveData() { - if (validateData()) { - getEntry().setURI(URIUtils.convertLocationToURI(resourceLocationField.getText())); - getEntry().setKey(keyField.getText()); - getEntry().setEntryType(getKeyType()); - getEntry().setAttributeValue(ICatalogEntry.ATTR_WEB_URL, checkboxButton.getSelection() ? webAddressField.getText() : null); - dataSaved = true; - } - else { - errorMessage = XMLCatalogMessages.UI_WARNING_DUPLICATE_ENTRY; - errorMessageLabel.setText(errorMessage); - updateOKButtonState(); - dataSaved = false; - } - } - - /** - * Validates that the data entered does not conflict with an existing entry in either catalog. - * @return True if validated, false otherwise. - */ - protected boolean validateData() { - - String result = null; - if (key == null || !key.equals(keyField.getText()) || type != getKeyType()) - { - // get system catalog - ICatalog systemCatalog = null; - ICatalog defaultCatalog = XMLCorePlugin.getDefault().getDefaultXMLCatalog(); - INextCatalog[] nextCatalogs = defaultCatalog.getNextCatalogs(); - for (int i = 0; i < nextCatalogs.length; i++) { - INextCatalog catalog = nextCatalogs[i]; - ICatalog referencedCatalog = catalog.getReferencedCatalog(); - if (referencedCatalog != null) { - if (XMLCorePlugin.SYSTEM_CATALOG_ID.equals(referencedCatalog.getId())) { - systemCatalog = referencedCatalog; - } - } - } - - try { - switch( getKeyType() ) - { - case ICatalogEntry.ENTRY_TYPE_PUBLIC: - result = catalog.resolvePublic(keyField.getText(), null); - if (result == null) { - result = systemCatalog.resolvePublic(keyField.getText(), null); - } - break; - case ICatalogEntry.ENTRY_TYPE_SYSTEM: - result = catalog.resolveSystem(keyField.getText()); - if (result == null) { - result = systemCatalog.resolveSystem(keyField.getText()); - } - break; - case ICatalogEntry.ENTRY_TYPE_URI: - result = catalog.resolveURI(keyField.getText()); - if (result == null) { - result = systemCatalog.resolveURI(keyField.getText()); - } - break; - } - } - catch (Exception e) { - } - } - - return (result == null); - } - - protected void updateKeyTypeCombo(int type) { - keyTypeCombo.removeAll(); - for (Iterator i = CatalogFileTypeRegistryReader.getXMLCatalogFileTypes().iterator(); i.hasNext();) { - XMLCatalogFileType theFileType = (XMLCatalogFileType) i.next(); - if (theFileType.extensions != null) { - for (Iterator j = theFileType.extensions.iterator(); j.hasNext();) { - String extension = (String) j.next(); - if (resourceLocationField.getText().endsWith(extension)) { - if (theFileType.description.equals("XSD Files")) { //$NON-NLS-1$ - keyTypeCombo.add(XMLCatalogMessages.UI_KEY_TYPE_DESCRIPTION_XSD_PUBLIC); - keyTypeCombo.add(XMLCatalogMessages.UI_KEY_TYPE_DESCRIPTION_XSD_SYSTEM); - keyTypeCombo.setData("keyType", "schema"); //$NON-NLS-1$ //$NON-NLS-2$ - } - else if (theFileType.description.equals("DTD Files")) { //$NON-NLS-1$ - keyTypeCombo.add(XMLCatalogMessages.UI_KEY_TYPE_DESCRIPTION_DTD_PUBLIC); - keyTypeCombo.add(XMLCatalogMessages.UI_KEY_TYPE_DESCRIPTION_DTD_SYSTEM); - keyTypeCombo.add(XMLCatalogMessages.UI_KEY_TYPE_DESCRIPTION_URI); - } - else { - keyTypeCombo.add(XMLCatalogMessages.UI_KEY_TYPE_DESCRIPTION_URI); - } - } - - } - - } - } - if (keyTypeCombo.getItemCount() == 0) { - keyTypeCombo.add(XMLCatalogMessages.UI_KEY_TYPE_DESCRIPTION_DTD_PUBLIC); - keyTypeCombo.add(XMLCatalogMessages.UI_KEY_TYPE_DESCRIPTION_DTD_SYSTEM); - keyTypeCombo.add(XMLCatalogMessages.UI_KEY_TYPE_DESCRIPTION_URI); - } - - switch (type) { - case ICatalogEntry.ENTRY_TYPE_PUBLIC : - keyTypeCombo.select(0); - break; - case ICatalogEntry.ENTRY_TYPE_SYSTEM : - keyTypeCombo.select(1); - break; - case ICatalogEntry.ENTRY_TYPE_URI : // handle XML Schema, - // where namespace name is - // mapped to URI situation - if ("schema".equals(keyTypeCombo.getData("keyType"))) { //$NON-NLS-1$ //$NON-NLS-2$ - keyTypeCombo.select(0); // namespace name as URI key - // type - } - else { - keyTypeCombo.select(2); // URI key type - } - break; - default : - if (keyTypeCombo.getItemCount() > 0) { - keyTypeCombo.select(0); - } - break; - } - - } - - protected void updateWebAddressWidgets(int keyType) { - boolean isPublicKeyType = (keyType == ICatalogEntry.ENTRY_TYPE_PUBLIC); - checkboxButton.setEnabled(isPublicKeyType); - webAddressField.setEnabled(isPublicKeyType && checkboxButton.getSelection()); - } - - protected void updateWidgets(Widget widget) { - if (widget != keyTypeCombo) { - updateKeyTypeCombo(getKeyType()); - } - updateWebAddressWidgets(getKeyType()); - computeErrorMessage(); - updateErrorMessageLabel(errorMessageLabel); - updateOKButtonState(); - } - - } - - protected abstract class CatalogElementPage { - - Control fControl; - - public CatalogElementPage() { - super(); - - } - - public abstract Control createControl(Composite parent); - - public Control getControl() { - return fControl; - } - - public abstract ICatalogElement getData(); - - public abstract void saveData(); - } - - protected class FilterableSelectSingleFileDialog extends SelectSingleFileDialog implements SelectionListener { - protected Combo filterControl; - - public FilterableSelectSingleFileDialog(Shell parentShell) { - super(parentShell, null, true); - setFilters(null); - } - - public void createAndOpen() { - this.create(); - setBlockOnOpen(true); - getShell().setText(XMLCatalogMessages.UI_LABEL_FILE_SELECTION); - this.setTitle(XMLCatalogMessages.UI_LABEL_SELECT_FILE); - this.setMessage(XMLCatalogMessages.UI_LABEL_CHOOSE_FILE_TO_ADD_TO_CATALOG); - open(); - } - - public void createFilterControl(Composite composite) { - Label label = new Label(composite, SWT.NONE); - label.setText(XMLCatalogMessages.UI_LABEL_SELECT_FILE_FILTER_CONTROL); - - filterControl = new Combo(composite, SWT.NONE); - GridData gd = new GridData(GridData.FILL_HORIZONTAL); - filterControl.setLayoutData(gd); - - filterControl.setText(XMLCatalogMessages.UI_TEXT_SELECT_FILE_FILTER_CONTROL); - filterControl.add(XMLCatalogMessages.UI_TEXT_SELECT_FILE_FILTER_CONTROL); - - for (Iterator i = CatalogFileTypeRegistryReader.getXMLCatalogFileTypes().iterator(); i.hasNext();) { - XMLCatalogFileType fileType = (XMLCatalogFileType) i.next(); - if (fileType.description != null) { - filterControl.add(fileType.description); - } - } - - filterControl.addSelectionListener(this); - } - - protected void setFilters(XMLCatalogFileType fileType) { - if (fileType == null) { - // compute all the supported file extensions - List list = new ArrayList(); - for (Iterator i = CatalogFileTypeRegistryReader.getXMLCatalogFileTypes().iterator(); i.hasNext();) { - XMLCatalogFileType theFileType = (XMLCatalogFileType) i.next(); - if (theFileType.extensions != null) { - list.addAll(theFileType.extensions); - } - } - // Any files are now supported with Resource URI - // selectSingleFileView.setFilterExtensions(createStringArray(list)); - } - else { - if (fileType.extensions != null) { - selectSingleFileView.setFilterExtensions(createStringArray(fileType.extensions)); - } - } - } - - public void widgetDefaultSelected(SelectionEvent e) { - // do nothing - } - - public void widgetSelected(SelectionEvent e) { - String text = filterControl.getText(); - XMLCatalogFileType fileType = getMatchingFileType(text); - setFilters(fileType); - } - } - - protected class NextCatalogPage extends CatalogElementPage { - protected Button browseButton; - - protected Text catalogLocationField; - - protected INextCatalog nextCatalog; - - protected Label errorMessageLabel; - - protected void computeErrorMessage() { - errorMessage = null; - - if (errorMessage == null) { - String fileName = catalogLocationField.getText(); - if (fileName.trim().length() > 0) { - if ((fileName.indexOf("..") != -1) || (fileName.indexOf("./") != -1) || (fileName.indexOf("/.") != -1) || (fileName.indexOf(".\\") != -1) || (fileName.indexOf("\\.") != -1)) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ - errorMessage = XMLCatalogMessages.UI_WARNING_URI_MUST_NOT_HAVE_DOTS; - } - - String uri = fileName; - if (!URIHelper.hasProtocol(uri)) { - uri = URIHelper.isAbsolute(uri) ? URIHelper.prependFileProtocol(uri) : URIHelper.prependPlatformResourceProtocol(uri); - } - - if ((errorMessage == null) && !URIHelper.isReadableURI(uri, false)) { - errorMessage = XMLCatalogMessages.UI_WARNING_URI_NOT_FOUND_COLON + fileName; - } - } - else { - // this an error that is not actually - // reported ... OK is just disabled - errorMessage = ""; //$NON-NLS-1$ - } - } - - } - - public Control createControl(Composite parent) { - fControl = createNextCatalogPanel(parent); - return fControl; - } - - protected Control createNextCatalogPanel(Composite parent) { - ModifyListener modifyListener = new ModifyListener() { - public void modifyText(ModifyEvent e) { - updateWidgets(e.widget); - } - }; - - Composite composite = new Composite(parent, SWT.NONE); - GridData gd = new GridData(GridData.FILL_BOTH); - composite.setLayoutData(gd); - - GridLayout layout = new GridLayout(); - composite.setLayout(layout); - - Composite group = new Composite(composite, SWT.NONE); - gd = new GridData(GridData.FILL_HORIZONTAL); - group.setLayoutData(gd); - - layout = new GridLayout(2, false); - group.setLayout(layout); - - Label resourceLocationLabel = new Label(group, SWT.NONE); - resourceLocationLabel.setText(XMLCatalogMessages.UI_LABEL_CATALOG_URI_COLON); - - // filler - new Label(group, SWT.NONE); - - catalogLocationField = new Text(group, SWT.SINGLE | SWT.BORDER); - catalogLocationField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - catalogLocationField.setText(URIUtils.convertURIToLocation(getDisplayValue(getNextCatalog().getCatalogLocation()))); - // WorkbenchHelp.setHelp(resourceLocationField, - // XMLBuilderContextIds.XMLP_ENTRY_URI); - catalogLocationField.addModifyListener(modifyListener); - - browseButton = createBrowseButton(group); - browseButton.addSelectionListener(new DropDownSelectionListener(catalogLocationField)); - - errorMessageLabel = new Label(group, SWT.NONE); - errorMessageLabel.setForeground(color); - errorMessageLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - updateWidgets(null); - return composite; - } - - public ICatalogElement getData() { - return getNextCatalog(); - } - - protected INextCatalog getNextCatalog() { - if (nextCatalog == null) { - if ((fCatalogElement != null) && (fCatalogElement.getType() == ICatalogElement.TYPE_NEXT_CATALOG)) { - nextCatalog = (INextCatalog) fCatalogElement; - } - else { - if (catalog != null) { - nextCatalog = (INextCatalog) catalog.createCatalogElement(ICatalogElement.TYPE_NEXT_CATALOG); - } - } - } - return nextCatalog; - } - - public void saveData() { - getNextCatalog().setCatalogLocation(URIUtils.convertLocationToURI(catalogLocationField.getText())); - dataSaved = true; - } - - protected void updateWidgets(Widget widget) { - computeErrorMessage(); - updateErrorMessageLabel(errorMessageLabel); - updateOKButtonState(); - } - } - - protected class ToolBarItemSelectionChangeListener implements SelectionListener { - public void widgetDefaultSelected(SelectionEvent e) { - // TODO Auto-generated method stub - - } - - public void widgetSelected(SelectionEvent e) { - Object selection = e.getSource(); - if (selection instanceof ToolItem) { - if (!showPage((CatalogElementPage) ((ToolItem) selection).getData())) { - // Page flipping wasn't successful - // handleError(); - } - } - } - - } - - public static String[] createStringArray(List list) { - String[] stringArray = new String[list.size()]; - for (int i = 0; i < stringArray.length; i++) { - stringArray[i] = (String) list.get(i); - } - return stringArray; - } - - public static String removeLeadingSlash(String uri) { - // remove leading slash from the value to avoid the whole leading - // slash - // ambiguity problem - // - if (uri != null) { - while (uri.startsWith("/") || uri.startsWith("\\")) { //$NON-NLS-1$ //$NON-NLS-2$ - uri = uri.substring(1); - } - } - return uri; - } - - protected ICatalog catalog; - - protected ICatalogElement fCatalogElement; - - protected String errorMessage; - - protected String warningMessage; - - protected Button okButton; - - protected PageBook pageContainer; - - protected CatalogElementPage selectedPage; - - // protected TreeViewer treeViewer; - - protected ToolBar toolBar; - - protected Color color; - protected boolean dataSaved; - - public EditCatalogEntryDialog(Shell parentShell, ICatalog aCatalog) { - super(parentShell); - setShellStyle(getShellStyle() | SWT.RESIZE); - this.catalog = aCatalog; - } - - public EditCatalogEntryDialog(Shell parentShell, ICatalogElement catalogElement, ICatalog aCatalog) { - this(parentShell, aCatalog); - this.fCatalogElement = catalogElement; - // TODO EB: fix his - // entry.setURI(URIHelper.removePlatformResourceProtocol(entry.getURI())); - } - - protected void buttonPressed(int buttonId) { - if (buttonId == IDialogConstants.OK_ID) { - selectedPage.saveData(); - if (!dataSaved) { - // do not exit edit dialog - return; - } - } - super.buttonPressed(buttonId); - } - - - - protected void createButtonsForButtonBar(Composite parent) { - okButton = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); - okButton.setEnabled(false); - createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); - updateOKButtonState(); - } - - protected void createCatalogEntryButton() { - CatalogElementPage page = new CatalogEntryPage(); - page.createControl(pageContainer); - ToolItem toolItem = new ToolItem(toolBar, SWT.PUSH); - toolItem.setImage(catalogEntryToolBarImage); - toolItem.setText(XMLCatalogMessages.EditCatalogEntryDialog_catalogEntryLabel); - toolItem.setData(page); - toolItem.addSelectionListener(new ToolBarItemSelectionChangeListener()); - } - - protected Control createDialogArea(Composite parent) { - Composite dialogAreaComposite = (Composite) super.createDialogArea(parent); - color = new Color(dialogAreaComposite.getDisplay(), 200, 0, 0); - GridLayout layout = new GridLayout(); - layout.marginHeight = 0; - layout.marginWidth = 0; - dialogAreaComposite.setLayout(layout); - GridData gd = new GridData(GridData.FILL_BOTH); - gd.widthHint = 500; - gd.heightHint = 250; - dialogAreaComposite.setLayoutData(gd); - createMainComponent(dialogAreaComposite); - return this.dialogArea; - } - - public boolean close() { - if (color != null) { - color.dispose(); - } - return super.close(); - } - - protected Composite createMainComponent(Composite composite) { - if (fCatalogElement != null) // "edit" action - { - Composite composite1 = new Composite(composite, SWT.NONE); - GridData data = new GridData(GridData.FILL_BOTH); - composite1.setLayoutData(data); - GridLayout layout = new GridLayout(); - composite1.setLayout(layout); - - pageContainer = new PageBook(composite1, SWT.NONE); - pageContainer.setLayoutData(new GridData(GridData.FILL_BOTH)); - - if (fCatalogElement.getType() == ICatalogElement.TYPE_ENTRY) { - CatalogElementPage entryPage = new CatalogEntryPage(); - entryPage.createControl(pageContainer); - showPage(entryPage); - } - else if (fCatalogElement.getType() == ICatalogElement.TYPE_NEXT_CATALOG) { - CatalogElementPage nextCatalogPage = new NextCatalogPage(); - nextCatalogPage.createControl(pageContainer); - showPage(nextCatalogPage); - } - - return composite1; - } - return createMainComponentWithToolbar(composite); - - } - - protected Composite createMainComponentWithToolbar(Composite composite) { - - FormLayout formLayout = new FormLayout(); - formLayout.marginHeight = 5; - formLayout.marginWidth = 5; - composite.setLayout(formLayout); - - Label label = new Label(composite, SWT.NONE); - FormData data = new FormData(); - data.top = new FormAttachment(0, 0); - data.left = new FormAttachment(0, 0); - data.right = new FormAttachment(100, 0); - label.setLayoutData(data); - - toolBar = new ToolBar(composite, SWT.BORDER | SWT.FLAT | SWT.VERTICAL); - - data = new FormData(); - data.top = new FormAttachment(label, 0); - data.left = new FormAttachment(0, 0); - data.bottom = new FormAttachment(100, 0); - // data.height = 250; - // data.width = 50; - toolBar.setLayoutData(data); - - Composite composite1 = new Composite(composite, SWT.BORDER); - data = new FormData(); - data.top = new FormAttachment(label, 0); - data.left = new FormAttachment(toolBar, 0, SWT.DEFAULT); - data.right = new FormAttachment(100, 0); - data.bottom = new FormAttachment(100, 0); - composite1.setLayoutData(data); - GridLayout layout = new GridLayout(); - layout.marginHeight = 0; - layout.marginWidth = 0; - composite1.setLayout(layout); - - // createPageBookPanel(composite1); - pageContainer = new PageBook(composite1, SWT.NONE); - pageContainer.setLayoutData(new GridData(GridData.FILL_BOTH)); - - // add pages for each type of catalog element - createCatalogEntryButton(); - createNextCatalogButton(); - if (toolBar.getItemCount() > 0) { - ToolItem item = toolBar.getItem(0); - showPage((CatalogElementPage) (item.getData())); - } - return composite1; - } - - protected void createNextCatalogButton() { - CatalogElementPage page = new NextCatalogPage(); - page.createControl(pageContainer); - ToolItem toolItem = new ToolItem(toolBar, SWT.PUSH); - toolItem.setImage(nextCatalogToolBarImage); - toolItem.setText(XMLCatalogMessages.EditCatalogEntryDialog_nextCatalogLabel); - toolItem.setData(page); - toolItem.addSelectionListener(new ToolBarItemSelectionChangeListener()); - - } - - protected ICatalogElement getCatalogElement() { - return fCatalogElement; - } - - protected String getDisplayValue(String string) { - return string != null ? string : ""; //$NON-NLS-1$ - } - - protected XMLCatalogFileType getMatchingFileType(String description) { - XMLCatalogFileType fileType = null; - for (Iterator i = CatalogFileTypeRegistryReader.getXMLCatalogFileTypes().iterator(); i.hasNext();) { - XMLCatalogFileType theFileType = (XMLCatalogFileType) i.next(); - if ((theFileType.description != null) && theFileType.description.equals(description)) { - fileType = theFileType; - } - } - return fileType; - } - - protected boolean showPage(CatalogElementPage page) { - if (pageContainer.isDisposed()) { - return false; - } - selectedPage = page; - pageContainer.setVisible(true); - pageContainer.showPage(selectedPage.getControl()); - fCatalogElement = selectedPage.getData(); - return true; - } - - protected void updateErrorMessageLabel(Label errorMessageLabel) { - if (errorMessage != null) { - errorMessageLabel.setText(errorMessage); - } - else if (warningMessage != null) { - errorMessageLabel.setText(warningMessage); - } - else { - errorMessageLabel.setText(""); - } - } - - protected void updateOKButtonState() { - if (okButton != null) { - okButton.setEnabled(errorMessage == null); - } - } - - protected Button createBrowseButton(Composite composite) { - Button browseButton = new Button(composite, SWT.FLAT); - // browseButton.setText(XMLCatalogMessages. - // UI_BUTTON_BROWSE")); - browseButton.setImage(borwseImage); - Rectangle r = borwseImage.getBounds(); - GridData gd = new GridData(); - int IMAGE_WIDTH_MARGIN = 6; - int IMAGE_HEIGHT_MARGIN = 6; - gd.heightHint = r.height + IMAGE_HEIGHT_MARGIN; - gd.widthHint = r.width + IMAGE_WIDTH_MARGIN; - browseButton.setLayoutData(gd); - - return browseButton; - - } - - class DropDownSelectionListener extends SelectionAdapter { - private Menu menu = null; - private Control control; - - public DropDownSelectionListener(Control aControl) { - super(); - this.control = aControl; - } - - public void widgetSelected(SelectionEvent event) { - // Create the menu if it has not already been created - if (menu == null) { - // Lazy create the menu. - menu = new Menu(getShell()); - MenuItem menuItem = new MenuItem(menu, SWT.NONE); - menuItem.setText(XMLCatalogMessages.UI_BUTTON_MENU_BROWSE_WORKSPACE); - /* - * Add a menu selection listener so that the menu is hidden - * when the user selects an item from the drop down menu. - */ - menuItem.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - setMenuVisible(false); - invokeWorkspaceFileSelectionDialog(); - } - }); - - menuItem = new MenuItem(menu, SWT.NONE); - menuItem.setText(XMLCatalogMessages.UI_BUTTON_MENU_BROWSE_FILE_SYSTEM); - /* - * Add a menu selection listener so that the menu is hidden - * when the user selects an item from the drop down menu. - */ - menuItem.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - setMenuVisible(false); - invokeFileSelectionDialog(); - } - }); - - } - - // Position the menu below and vertically aligned with the the - // drop down tool button. - Button button = (Button) event.widget; - - // set location - Point ptBrowse = button.getLocation(); - Rectangle rcBrowse = button.getBounds(); - ptBrowse.y += rcBrowse.height; - ptBrowse = button.getParent().toDisplay(ptBrowse); - menu.setLocation(ptBrowse.x, ptBrowse.y); - - setMenuVisible(true); - - } - - void setMenuVisible(boolean visible) { - menu.setVisible(visible); - // this.visible = visible; - } - - void invokeWorkspaceFileSelectionDialog() { - FilterableSelectSingleFileDialog dialog = new FilterableSelectSingleFileDialog(getShell()); - dialog.createAndOpen(); - - IFile file = dialog.getFile(); - if (file != null) { - // remove leading slash from the value to avoid the - // whole leading slash ambiguity problem - // - String uri = file.getFullPath().toString(); - while (uri.startsWith("/") || uri.startsWith("\\")) { //$NON-NLS-1$ //$NON-NLS-2$ - uri = uri.substring(1); - } - if (control instanceof Text) { - ((Text) control).setText(uri); - } - - } - } - - void invokeFileSelectionDialog() { - FileDialog dialog = new FileDialog(getShell(), SWT.SINGLE); - String file = dialog.open(); - if ((control instanceof Text) && (file != null)) { - ((Text) control).setText(file); - } - } - } - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/ElementNodePage.java b/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/ElementNodePage.java deleted file mode 100644 index 0ec61e6234..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/ElementNodePage.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.catalog; - -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogElement; - - -public abstract class ElementNodePage { - - Control fControl; - - public ElementNodePage() { - super(); - - } - - public abstract Control createControl(Composite parent); - - public Control getControl() { - return fControl; - } - - public abstract void saveData(); - - public abstract ICatalogElement getData(); -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/ImageFactory.java b/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/ImageFactory.java deleted file mode 100644 index 3938a7efb1..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/ImageFactory.java +++ /dev/null @@ -1,201 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.catalog; - -import java.util.Hashtable; - -import org.eclipse.jface.resource.CompositeImageDescriptor; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.resource.ImageRegistry; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.ImageData; -import org.eclipse.swt.graphics.Point; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; - -public class ImageFactory { - public static final int TOP_LEFT = 1; - public static final int TOP_RIGHT = 2; - public static final int BOTTOM_LEFT = 3; - public static final int BOTTOM_RIGHT = 4; - - protected static final int[][] OVERLAY_COORDINATE = {{0, 0}, {0, 2}, {2, 0}, {2, 2}}; - - protected static ImageFactory INSTANCE = new ImageFactory(); - - protected Hashtable compositeImageTable = new Hashtable(); - - public ImageFactory() { - super(); - } - - public Image getImage(String iconName) { - ImageRegistry imageRegistry = XMLUIPlugin.getDefault().getImageRegistry(); - - if (imageRegistry.get(iconName) != null) { - return imageRegistry.get(iconName); - } - else { - imageRegistry.put(iconName, ImageDescriptor.createFromFile(getClass(), iconName)); - return imageRegistry.get(iconName); - } - } - - public Image createCompositeImage(Image base, Image overlay, int overlayPosition) { - String key = base + "*" + overlay + "*" + overlayPosition; //$NON-NLS-1$ //$NON-NLS-2$ - Image result = (Image) compositeImageTable.get(key); - if (result == null) { - ImageDescriptor overlays[][] = new ImageDescriptor[3][3]; - int[] coord = OVERLAY_COORDINATE[overlayPosition]; - overlays[coord[1]][coord[0]] = new ImageBasedImageDescriptor(overlay); - OverlayIcon icon = new OverlayIcon(new ImageBasedImageDescriptor(base), overlays, new Point(16, 16)); - result = icon.createImage(); - compositeImageTable.put(key, result); - } - return result; - } - - - public static ImageDescriptor createImageDescriptorWrapper(Image image) { - return new ImageBasedImageDescriptor(image); - } - - /** - * An OverlayIcon consists of a main icon and several adornments. - */ - class OverlayIcon extends CompositeImageDescriptor { - - static final int DEFAULT_WIDTH = 22; - - static final int DEFAULT_HEIGHT = 16; - - private Point fSize = null; - - private ImageDescriptor fBase; - - private ImageDescriptor fOverlays[][]; - - public OverlayIcon(ImageDescriptor base, ImageDescriptor[][] overlays, Point size) { - fBase = base; - fOverlays = overlays; - fSize = size; - } - - protected void drawBottomLeft(ImageDescriptor[] overlays) { - if (overlays == null) { - return; - } - int length = overlays.length; - int x = 0; - for (int i = 0; i < 3; i++) { - if ((i < length) && (overlays[i] != null)) { - ImageData id = overlays[i].getImageData(); - drawImage(id, x, getSize().y - id.height); - x += id.width; - } - } - } - - protected void drawBottomRight(ImageDescriptor[] overlays) { - if (overlays == null) { - return; - } - int length = overlays.length; - int x = getSize().x; - for (int i = 2; i >= 0; i--) { - if ((i < length) && (overlays[i] != null)) { - ImageData id = overlays[i].getImageData(); - x -= id.width; - drawImage(id, x, getSize().y - id.height); - } - } - } - - /** - * @see CompositeImageDescriptor#drawCompositeImage(int, int) - */ - protected void drawCompositeImage(int width, int height) { - ImageData bg; - if ((fBase == null) || ((bg = fBase.getImageData()) == null)) { - bg = DEFAULT_IMAGE_DATA; - } - drawImage(bg, 0, 0); - - if (fOverlays != null) { - if (fOverlays.length > 0) { - drawTopRight(fOverlays[0]); - } - - if (fOverlays.length > 1) { - drawBottomRight(fOverlays[1]); - } - - if (fOverlays.length > 2) { - drawBottomLeft(fOverlays[2]); - } - - if (fOverlays.length > 3) { - drawTopLeft(fOverlays[3]); - } - } - } - - protected void drawTopLeft(ImageDescriptor[] overlays) { - if (overlays == null) { - return; - } - int length = overlays.length; - int x = 0; - for (int i = 0; i < 3; i++) { - if ((i < length) && (overlays[i] != null)) { - ImageData id = overlays[i].getImageData(); - drawImage(id, x, 0); - x += id.width; - } - } - } - - protected void drawTopRight(ImageDescriptor[] overlays) { - if (overlays == null) { - return; - } - int length = overlays.length; - int x = getSize().x; - for (int i = 2; i >= 0; i--) { - if ((i < length) && (overlays[i] != null)) { - ImageData id = overlays[i].getImageData(); - x -= id.width; - drawImage(id, x, 0); - } - } - } - - /** - * @see CompositeImageDescriptor#getSize() - */ - protected Point getSize() { - return fSize; - } - } - - static class ImageBasedImageDescriptor extends ImageDescriptor { - protected Image image; - - public ImageBasedImageDescriptor(Image image) { - this.image = image; - } - - public ImageData getImageData() { - return image.getImageData(); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/URIUtils.java b/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/URIUtils.java deleted file mode 100644 index ea0c2bc802..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/URIUtils.java +++ /dev/null @@ -1,54 +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.wst.xml.ui.internal.catalog; - -import org.eclipse.wst.common.uriresolver.internal.util.URIHelper; - -public class URIUtils { - - private static final String PROTOCOL_PATTERN = ":"; - private static final String FILE_PROTOCOL = "file:"; - private static final String PLATFORM_RESOURCE_PROTOCOL = "platform:/resource/"; - private static final String LOCAL_FILE_PROTOCOL_FORWARD_SLASH = "\\\\\\"; - private static final String LOCAL_FILE_PROTOCOL_BACK_SLASH = "///"; - private static final char PATH_SEPARATOR_FORWARD_SLASH = '/'; - private static final char PATH_SEPARATOR_BACK_SLASH = '\\'; - - public static String convertURIToLocation(String uri) { - String location = uri; - if (uri != null) { - if (uri.startsWith(FILE_PROTOCOL)) { - location = org.eclipse.wst.common.uriresolver.internal.URI.createURI(uri).toFileString(); - if (location != null && (location.startsWith(LOCAL_FILE_PROTOCOL_BACK_SLASH) - || location.startsWith(LOCAL_FILE_PROTOCOL_FORWARD_SLASH))) { - location = location.substring(LOCAL_FILE_PROTOCOL_BACK_SLASH.length()); - } - } else if (uri.startsWith(PLATFORM_RESOURCE_PROTOCOL)) { - location = uri.substring(PLATFORM_RESOURCE_PROTOCOL.length()); - } - } - return location; - } - - public static String convertLocationToURI(String location) { - String uri = location; - if (!URIHelper.hasProtocol(location)) { - uri = URIHelper.isAbsolute(location)? org.eclipse.wst.common.uriresolver.internal.URI.createFileURI(location).toString() - : URIHelper.prependPlatformResourceProtocol(location); - } - if (uri.startsWith(FILE_PROTOCOL) && uri.indexOf(PROTOCOL_PATTERN, FILE_PROTOCOL.length()) != -1) { - uri = URIHelper.ensureFileURIProtocolFormat(uri); - } - uri = uri.replace(PATH_SEPARATOR_BACK_SLASH, PATH_SEPARATOR_FORWARD_SLASH); - return uri; - } - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/XMLCatalogEntriesView.java b/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/XMLCatalogEntriesView.java deleted file mode 100644 index 92f8bb5170..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/XMLCatalogEntriesView.java +++ /dev/null @@ -1,304 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.catalog; - -import java.util.Iterator; - -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.Viewer; -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.graphics.Point; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.wst.xml.core.internal.catalog.Catalog; -import org.eclipse.wst.xml.core.internal.catalog.CatalogElement; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogElement; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; - - - -public class XMLCatalogEntriesView extends Composite { - protected Button newButton; - protected Button editButton; - protected Button deleteButton; - protected XMLCatalogTreeViewer tableViewer; - protected ICatalog workingUserCatalog; - protected ICatalog systemCatalog; - - // protected boolean isPageEnabled = true; - - public XMLCatalogEntriesView(Composite parent, ICatalog workingUserCatalog, ICatalog systemCatalog) { - super(parent, SWT.NONE); - this.workingUserCatalog = workingUserCatalog; - this.systemCatalog = systemCatalog; - - GridLayout gridLayout = new GridLayout(); - gridLayout.numColumns = 2; - this.setLayout(gridLayout); - - tableViewer = createTableViewer(this); - tableViewer.setInput("dummy"); //$NON-NLS-1$ - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=202692 - // specifically set size of tree before expanding it - Point initialSize = tableViewer.getTree().computeSize(SWT.DEFAULT, SWT.DEFAULT); - GridData gridData = new GridData(GridData.FILL_BOTH); - gridData.widthHint = initialSize.x; - gridData.heightHint = initialSize.y; - tableViewer.getControl().setLayoutData(gridData); - - tableViewer.expandToLevel(2); - tableViewer.reveal(XMLCatalogTreeViewer.USER_SPECIFIED_ENTRIES_OBJECT); - - ISelectionChangedListener listener = new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - updateWidgetEnabledState(); - } - }; - tableViewer.addSelectionChangedListener(listener); - - createButtons(this); - } - - public static String removeLeadingSlash(String uri) { - // remove leading slash from the value to avoid the whole leading - // slash ambiguity problem - // - if (uri != null) { - while (uri.startsWith("/") || uri.startsWith("\\")) //$NON-NLS-1$ //$NON-NLS-2$ - { - uri = uri.substring(1); - } - } - return uri; - } - - protected XMLCatalogTreeViewer createTableViewer(Composite parent) { - String headings[] = new String[2]; - headings[0] = XMLCatalogMessages.UI_LABEL_KEY; - headings[1] = XMLCatalogMessages.UI_LABEL_URI; - - XMLCatalogTreeViewer theTableViewer = new XMLCatalogTreeViewer(parent, workingUserCatalog, systemCatalog); - return theTableViewer; - } - - protected void createButtons(Composite parent) { - Composite composite = new Composite(parent, SWT.NONE); - GridData gd = new GridData(); - gd.verticalAlignment = GridData.BEGINNING; - composite.setLayoutData(gd); - GridLayout gridLayout = new GridLayout(); - gridLayout.marginHeight = 0; - gridLayout.marginWidth = 0; - gridLayout.marginLeft = 3; - composite.setLayout(gridLayout); - - SelectionListener selectionListener = new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - if (e.widget == newButton) { - performNew(); - } - else if (e.widget == editButton) { - performEdit(); - } - else if (e.widget == deleteButton) { - performDelete(); - } - } - }; - - // add the "New..." button - // - gd = new GridData(); - gd.horizontalAlignment = GridData.FILL; - gd.grabExcessHorizontalSpace = true; - - newButton = new Button(composite, SWT.NONE); - newButton.setText(XMLCatalogMessages.UI_BUTTON_NEW); - // WorkbenchHelp.setHelp(newButton, - // XMLBuilderContextIds.XMLP_MAPPING_NEW); - newButton.setLayoutData(gd); - newButton.addSelectionListener(selectionListener); - - // add the "Edit..." button - // - gd = new GridData(); - gd.horizontalAlignment = GridData.FILL; - gd.grabExcessHorizontalSpace = true; - editButton = new Button(composite, SWT.NONE); - editButton.setText(XMLCatalogMessages.UI_BUTTON_EDIT); - // WorkbenchHelp.setHelp(editButton, - // XMLBuilderContextIds.XMLP_MAPPING_EDIT); - editButton.setLayoutData(gd); - editButton.addSelectionListener(selectionListener); - - // add the "Delete" button - // - gd = new GridData(); - gd.horizontalAlignment = GridData.FILL; - gd.grabExcessHorizontalSpace = true; - deleteButton = new Button(composite, SWT.NONE); - deleteButton.setText(XMLCatalogMessages.UI_BUTTON_REMOVE); - // WorkbenchHelp.setHelp(deleteButton, - // XMLBuilderContextIds.XMLP_MAPPING_DELETE); - deleteButton.setLayoutData(gd); - deleteButton.addSelectionListener(selectionListener); - - gd = new GridData(); - gd.horizontalAlignment = GridData.FILL; - gd.grabExcessHorizontalSpace = true; - gd.horizontalSpan = 4; - - Button hiddenButton = new Button(composite, SWT.NONE); - hiddenButton.setLayoutData(gd); - hiddenButton.setVisible(false); - hiddenButton.setEnabled(false); - - // a cruddy hack so that the PreferenceDialog doesn't close every time - // we press 'enter' - // - getShell().setDefaultButton(hiddenButton); - updateWidgetEnabledState(); - } - - public void refresh() { - tableViewer.refresh();// XMLCatalogTreeViewer.USER_SPECIFIED_ENTRIES_OBJECT); - } - - protected EditCatalogEntryDialog invokeDialog(String title, ICatalogElement entry, ICatalog catalog) { - Shell shell = XMLUIPlugin.getInstance().getWorkbench().getActiveWorkbenchWindow().getShell(); - EditCatalogEntryDialog dialog = entry != null ? new EditCatalogEntryDialog(shell, entry, catalog) : new EditCatalogEntryDialog(shell, catalog); - dialog.create(); - dialog.getShell().setText(title); - dialog.setBlockOnOpen(true); - dialog.open(); - return dialog; - } - - protected EditCatalogEntryDialog invokeDialog(String title, ICatalog catalog) { - return invokeDialog(title, null, catalog); - } - - - protected void performNew() { - - // ICatalogEntry newEntry = - // (ICatalogEntry)workingUserCatalog.createCatalogElement(ICatalogElement.TYPE_ENTRY); - EditCatalogEntryDialog dialog = invokeDialog(XMLCatalogMessages.UI_LABEL_NEW_DIALOG_TITLE, workingUserCatalog); - ICatalogElement element = dialog.getCatalogElement(); - if (dialog.getReturnCode() == Window.OK) { - workingUserCatalog.addCatalogElement(element); - tableViewer.setSelection(new StructuredSelection(element), true); - tableViewer.refresh(); - } - } - - protected void performEdit() { - ISelection selection = tableViewer.getSelection(); - Object selectedObject = (selection instanceof IStructuredSelection) ? ((IStructuredSelection) selection).getFirstElement() : null; - - if (selectedObject instanceof ICatalogElement) { - ICatalogElement oldEntry = (ICatalogElement) selectedObject; - ICatalogElement newEntry = (ICatalogElement) ((CatalogElement) oldEntry).clone(); - - EditCatalogEntryDialog dialog = invokeDialog(XMLCatalogMessages.UI_LABEL_EDIT_DIALOG_TITLE, newEntry, workingUserCatalog); - if (dialog.getReturnCode() == Window.OK) { - // delete the old value if the 'mapFrom' has changed - // - workingUserCatalog.removeCatalogElement(oldEntry); - - // update the new mapping - // - workingUserCatalog.addCatalogElement(newEntry); - tableViewer.setSelection(new StructuredSelection(newEntry)); - } - } - } - - protected void performDelete() { - ISelection selection = tableViewer.getSelection(); - if(selection instanceof IStructuredSelection) { - IStructuredSelection structuredSelection = (IStructuredSelection)selection; - Iterator iterator = structuredSelection.iterator(); - while(iterator.hasNext()) { - Object selectedObject = iterator.next(); - if (selectedObject instanceof ICatalogElement) { - ICatalogElement catalogElement = (ICatalogElement) selectedObject; - workingUserCatalog.removeCatalogElement(catalogElement); - } - } - } - } - - protected void updateWidgetEnabledState() { - boolean isEditable = false; - ISelection selection = tableViewer.getSelection(); - boolean multipleSelection = false; - if(selection instanceof IStructuredSelection) { - IStructuredSelection structuredSelection = (IStructuredSelection)selection; - if(structuredSelection.size() > 1) { - multipleSelection = true; - } - Object selectedObject = structuredSelection.getFirstElement(); - if (selectedObject instanceof ICatalogElement) { - ICatalogElement[] elements = ((Catalog) workingUserCatalog).getCatalogElements(); - // dw List entriesList = new ArrayList(elements.length); - for (int i = 0; i < elements.length; i++) { - ICatalogElement element = elements[i]; - isEditable = selectedObject.equals(element); - if (isEditable) { - break; - } - } - } - } - - // if (isPageEnabled) - { - editButton.setEnabled(isEditable & !multipleSelection); - deleteButton.setEnabled(isEditable); - } - } - - /* - * public void setPageEnabled(boolean enabled) { isPageEnabled = enabled; - * - * tableViewer.getControl().setEnabled(isPageEnabled); - * - * newButton.setEnabled(isPageEnabled); - * editButton.setEnabled(isPageEnabled); - * deleteButton.setEnabled(isPageEnabled); } - */ - public void updatePage() { - refresh(); - updateWidgetEnabledState(); - } - - public Viewer getViewer() { - return tableViewer; - } - - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/XMLCatalogEntryDetailsView.java b/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/XMLCatalogEntryDetailsView.java deleted file mode 100644 index fe97a1ca37..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/XMLCatalogEntryDetailsView.java +++ /dev/null @@ -1,115 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.catalog; - - -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.ScrollBar; -import org.eclipse.swt.widgets.Text; -import org.eclipse.wst.common.uriresolver.internal.util.URIHelper; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry; -import org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog; - - - -public class XMLCatalogEntryDetailsView { - protected Text detailsText; - protected ScrollBar verticalScroll, horizontalScroll; - - public XMLCatalogEntryDetailsView(Composite parent) { - Color color = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND); - - detailsText = new Text(parent, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); - - GridData data = new GridData(GridData.FILL_BOTH); - data.heightHint = 85; - detailsText.setLayoutData(data); - - verticalScroll = detailsText.getVerticalBar(); - // verticalScroll.setVisible(false); - horizontalScroll = detailsText.getHorizontalBar(); - detailsText.setEditable(false); - detailsText.setBackground(color); - } - - public void setCatalogElement(ICatalogEntry entry) { - if (entry == null) { - detailsText.setText(""); //$NON-NLS-1$ - return; - } - - String value = getDisplayValue(entry != null ? entry.getURI() : ""); //$NON-NLS-1$ - String line1 = XMLCatalogMessages.UI_LABEL_DETAILS_URI_COLON + "\t\t" + value; //$NON-NLS-1$ - - String line0; - if (value.startsWith("jar:file:")) { - String jarFile = URIUtils.convertURIToLocation(URIHelper.ensureURIProtocolFormat(value.substring("jar:".length(), value.indexOf('!')))); - String internalFile = URIUtils.convertURIToLocation(URIHelper.ensureURIProtocolFormat("file://" + value.substring(value.indexOf('!') + 1))); - line0 = XMLCatalogMessages.UI_LABEL_DETAILS_URI_LOCATION + "\t" + internalFile + " " + XMLCatalogMessages.UI_LABEL_DETAILS_IN_JAR_FILE + " " + jarFile; - } - else { - value = URIUtils.convertURIToLocation(value); - line0 = XMLCatalogMessages.UI_LABEL_DETAILS_URI_LOCATION + "\t" + value; //$NON-NLS-1$ - - } - - value = entry != null ? getKeyTypeValue(entry) : ""; //$NON-NLS-1$ - String line2 = XMLCatalogMessages.UI_KEY_TYPE_DETAILS_COLON + "\t" + value; //$NON-NLS-1$ - - value = getDisplayValue(entry != null ? entry.getKey() : ""); //$NON-NLS-1$ - String line3 = XMLCatalogMessages.UI_LABEL_DETAILS_KEY_COLON + "\t\t" + value; //$NON-NLS-1$ - - String entireString = "\n" + line0 + "\n" + line1 + "\n" + line2 + "\n" + line3; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - detailsText.setText(entireString); - } - - public void setCatalogElement(INextCatalog nextCatalog) { - String value = getDisplayValue(nextCatalog != null ? nextCatalog.getCatalogLocation() : ""); //$NON-NLS-1$ - String line1 = XMLCatalogMessages.UI_LABEL_DETAILS_URI_COLON + "\t\t" + value; //$NON-NLS-1$ - - String line0 = XMLCatalogMessages.UI_LABEL_DETAILS_URI_LOCATION + "\t" + URIUtils.convertURIToLocation(value); - - String entireString = "\n" + line0 + "\n" + line1; //$NON-NLS-1$ - detailsText.setText(entireString); - } - - protected String getDisplayValue(String string) { - return string != null ? string : ""; //$NON-NLS-1$ - } - - protected String getKeyTypeValue(ICatalogEntry entry) { - String result = null; - if ((entry.getURI() != null) && entry.getURI().endsWith("xsd")) //$NON-NLS-1$ - { - result = (entry.getEntryType() == ICatalogEntry.ENTRY_TYPE_URI) ? XMLCatalogMessages.UI_KEY_TYPE_DESCRIPTION_XSD_PUBLIC : XMLCatalogMessages.UI_KEY_TYPE_DESCRIPTION_XSD_SYSTEM; - } - else { - switch (entry.getEntryType()) { - case ICatalogEntry.ENTRY_TYPE_PUBLIC : - result = XMLCatalogMessages.UI_KEY_TYPE_DESCRIPTION_DTD_PUBLIC; - break; - case ICatalogEntry.ENTRY_TYPE_SYSTEM : - result = XMLCatalogMessages.UI_KEY_TYPE_DESCRIPTION_DTD_SYSTEM; - break; - default : - result = XMLCatalogMessages.UI_KEY_TYPE_DESCRIPTION_URI; - break; - } - - } - return result; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/XMLCatalogFileType.java b/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/XMLCatalogFileType.java deleted file mode 100644 index aadb767038..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/XMLCatalogFileType.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.catalog; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import com.ibm.icu.util.StringTokenizer; - -import org.eclipse.swt.graphics.Image; - - -public class XMLCatalogFileType { - public String description; - public List extensions = new ArrayList(); - public String iconFileName; - public Image icon; - - public void addExtensions(String contributedExtensions) { - List list = parseExtensions(contributedExtensions); - for (Iterator i = list.iterator(); i.hasNext();) { - String extension = (String) i.next(); - if (!extensions.contains(extension)) { - extensions.add(extension); - } - } - } - - protected List parseExtensions(String string) { - List list = new ArrayList(); - for (StringTokenizer st = new StringTokenizer(string, ", "); st.hasMoreTokens();) //$NON-NLS-1$ - { - String token = st.nextToken(); - if (token != null) { - list.add(token); - } - } - return list; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/XMLCatalogMessages.java b/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/XMLCatalogMessages.java deleted file mode 100644 index 177c196ff8..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/XMLCatalogMessages.java +++ /dev/null @@ -1,137 +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 - Initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.catalog; - -import org.eclipse.osgi.util.NLS; - -/** - * Strings used by XML Editor - * - * @plannedfor 1.0 - */ -public class XMLCatalogMessages extends NLS { - private static final String BUNDLE_NAME = "org.eclipse.wst.xml.ui.internal.catalog.XMLCatalogResources";//$NON-NLS-1$ - - public static String UI_WIZARD_SCHEMA_AND_NAME_SPACE_INFO; - public static String UI_LABEL_NAME_SPACE_PREFIX; - public static String UI_LABEL_NAME_SPACE_URI; - public static String UI_LABEL_XSD_LOCATION; - public static String UI_LABEL_DOCTYPE_INFORMATION; - public static String UI_LABEL_SYSTEM_ID; - public static String UI_LABEL_PUBLIC_ID; - public static String UI_LABEL_SELECT_FILE; - public static String UI_LABEL_KEY; - public static String UI_LABEL_KEY_COLON; - public static String UI_LABEL_DETAILS_KEY_COLON; - public static String UI_LABEL_DETAILS_IN_JAR_FILE; - public static String UI_LABEL_URI; - public static String UI_LABEL_LOCATION_COLON; - public static String UI_LABEL_CATALOG_URI_COLON; - public static String UI_LABEL_DETAILS_URI_COLON; - public static String UI_LABEL_DETAILS_URI_LOCATION; - public static String UI_KEY_TYPE_COLON; - public static String UI_KEY_TYPE_DETAILS_COLON; - public static String UI_KEY_TYPE_DESCRIPTION_XSD_PUBLIC; - public static String UI_KEY_TYPE_DESCRIPTION_XSD_SYSTEM; - public static String UI_KEY_TYPE_DESCRIPTION_DTD_PUBLIC; - public static String UI_KEY_TYPE_DESCRIPTION_DTD_SYSTEM; - public static String UI_KEY_TYPE_DESCRIPTION_URI; - public static String UI_LABEL_SPECIFY_ALTERNATIVE_WEB_URL; - public static String UI_WARNING_URI_MUST_NOT_HAVE_DOTS; - public static String UI_LABEL_FILE_SELECTION; - public static String UI_LABEL_CHOOSE_FILE_TO_ADD_TO_CATALOG; - - - public static String UI_WARNING_URI_NOT_FOUND_COLON; - public static String UI_WARNING_URI_NOT_FOUND_LONG; - public static String UI_WARNING_INVALID_FILE; - public static String UI_WARNING_INVALID_FILE_LONG; - public static String UI_WARNING_NO_ELEMENT; - public static String UI_WARNING_NO_ELEMENT_DTD_LONG; - public static String UI_WARNING_NO_ELEMENT_XSD_LONG; - public static String UI_WARNING_SHOULD_BE_FULLY_QUALIFIED_URI; - public static String UI_WARNING_DUPLICATE_ENTRY; - - - // NewModelWizard - public static String UI_INVALID_GRAMMAR_ERROR; - public static String UI_BUTTON_BROWSE; - - // XMLCatalogIdMappingPage - public static String UI_LABEL_MAP_TO; - public static String UI_LABEL_MAP_FROM; - public static String UI_BUTTON_NEW; - public static String UI_BUTTON_EDIT; - public static String UI_BUTTON_DELETE; - public static String UI_BUTTON_REMOVE; - public static String UI_LABEL_NEW_DIALOG_TITLE; - public static String UI_LABEL_EDIT_DIALOG_TITLE; - - - // XMLCatalogPreferencePage - public static String UI_LABEL_USER_ENTRIES; - public static String UI_LABEL_USER_ENTRIES_TOOL_TIP; - public static String UI_LABEL_SYSTEM_ENTRIES; - public static String UI_LABEL_SYSTEM_ENTRIES_TOOL_TIP; - public static String UI_BUTTON_CHANGE; - public static String UI_LABEL_SELECT_PROJECT; - public static String UI_LABEL_SPECIFY_PROJECT_DESCRIPTION; - public static String UI_WARNING_NO_PROJECTS_CREATED; - public static String UI_WARNING_PROJECT_NOT_SPECIFIED; - public static String UI_WARNING_PROJECT_DOES_NOT_EXIST; - public static String UI_LABEL_PROJECT_TO_USE; - public static String UI_LABEL_CATALOG_SAVE_ERROR; - public static String UI_LABEL_CATALOG_COULD_NOT_BE_SAVED; - public static String UI_LABEL_ADVANCED; - public static String UI_LABEL_ADVANCED_XML_CATALOG_PREFS; - public static String UI_LABEL_SPECIFY_PERSISTENCE_FILE; - public static String UI_LABEL_SAVE_CATALOG_DIALOG_TITLE; - public static String UI_LABEL_SAVE_CATALOG_DIALOG_DESC; - public static String UI_LABEL_BROWSE_CATALOG_FILE_TITLE; - public static String UI_LABEL_BROWSE_CATALOG_FILE_DESC; - public static String UI_LABEL_DETAILS; - public static String UI_LABEL_USER_SPECIFIED_ENTRIES; - public static String UI_LABEL_PLUGIN_SPECIFIED_ENTRIES; - public static String UI_LABEL_PLATFORM_RESOURCE; - public static String UI_LABEL_FILE_SYSTEM_RESOURCE; - // AdvancedOptionsDialog - public static String UI_BUTTON_IMPORT; - public static String UI_BUTTON_EXPORT; - - public static String UI_LABEL_IMPORT_DIALOG_TITLE; - public static String UI_LABEL_IMPORT_DIALOG_HEADING; - public static String UI_LABEL_IMPORT_DIALOG_MESSAGE; - - public static String UI_LABEL_EXPORT_DIALOG_TITLE; - public static String UI_LABEL_EXPORT_DIALOG_HEADING; - public static String UI_LABEL_EXPORT_DIALOG_MESSAGE; - public static String ERROR_SAVING_FILE; - public static String UI_LABEL_FILE_IS_READ_ONLY; - public static String UI_LABEL_DIALOG_DESCRIPTION; - - public static String EditCatalogEntryDialog_catalogEntryLabel; - public static String EditCatalogEntryDialog_nextCatalogLabel; - public static String UI_BUTTON_MENU_BROWSE_WORKSPACE; - public static String UI_BUTTON_MENU_BROWSE_FILE_SYSTEM; - public static String UI_LABEL_SELECT_FILE_FILTER_CONTROL; - public static String UI_TEXT_SELECT_FILE_FILTER_CONTROL; - - - - static { - // load message values from bundle file - NLS.initializeMessages(BUNDLE_NAME, XMLCatalogMessages.class); - } - - private XMLCatalogMessages() { - // cannot create new instance - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/XMLCatalogPreferencePage.java b/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/XMLCatalogPreferencePage.java deleted file mode 100644 index 7316e0195a..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/XMLCatalogPreferencePage.java +++ /dev/null @@ -1,242 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * David Carver/STAR Standard - d_a_carver@yahoo.com - bug 192568 - * Removed Advanced button - Functionality is now in the - * Import/Export XML Catalog Wizards. - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.catalog; - -import org.eclipse.jface.preference.PreferencePage; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; -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.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.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPreferencePage; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.eclipse.wst.xml.core.internal.catalog.CatalogSet; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEvent; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogListener; -import org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog; - -public class XMLCatalogPreferencePage extends PreferencePage implements IWorkbenchPreferencePage, ICatalogListener { - - protected XMLCatalogEntriesView catalogEntriesView; - - protected ICatalog workingUserCatalog; - - protected ICatalog systemCatalog; - - protected ICatalog userCatalog; - - protected ICatalog defaultCatalog; - - protected Button advancedButton; - - public XMLCatalogPreferencePage() { - defaultCatalog = XMLCorePlugin.getDefault().getDefaultXMLCatalog(); - INextCatalog[] nextCatalogs = defaultCatalog.getNextCatalogs(); - for (int i = 0; i < nextCatalogs.length; i++) { - INextCatalog catalog = nextCatalogs[i]; - ICatalog referencedCatalog = catalog.getReferencedCatalog(); - if (referencedCatalog != null) { - if (XMLCorePlugin.SYSTEM_CATALOG_ID.equals(referencedCatalog.getId())) { - systemCatalog = referencedCatalog; - } - else if (XMLCorePlugin.USER_CATALOG_ID.equals(referencedCatalog.getId())) { - userCatalog = referencedCatalog; - } - } - } - } - - public void dispose() { - super.dispose(); - workingUserCatalog.removeListener(this); - } - - /** - * Refresh the view in responce to an event sent by the Catalog - */ - public void catalogChanged(ICatalogEvent event) { - catalogEntriesView.updatePage(); - } - - /** - * Creates preference page controls on demand. - * - * @param parent - * the parent for the preference page - */ - protected Control createContents(Composite parent) { - // we create a working copy of the 'User Settings' for the Catalog - // that we can modify - CatalogSet tempCatalogSet = new CatalogSet(); - workingUserCatalog = tempCatalogSet.lookupOrCreateCatalog("working", ""); //$NON-NLS-1$ //$NON-NLS-2$ - - // TODO: add entries from the nested catalogs as well - workingUserCatalog.addEntriesFromCatalog(userCatalog); - workingUserCatalog.addListener(this); - noDefaultAndApplyButton(); - Composite composite = new Composite(parent, SWT.NULL); - // WorkbenchHelp.setHelp(composite, new - // ControlContextComputer(composite, - // XMLBuilderContextIds.XMLP_CATALOG_PAGE)); - composite.setLayout(new GridLayout()); - composite.setLayoutData(new GridData(GridData.FILL_BOTH)); - createCatalogEntriesView(composite); - createCatalogDetailsView(composite); - //createAdvancedButton(composite); - // catalogEntriesView.updatePage(); - applyDialogFont(composite); - - return composite; - } - - /** - * @deprecated - * @param composite - */ - protected void createAdvancedButton(Composite composite) { - Composite panel = new Composite(composite, SWT.NONE); - GridLayout gridLayout = new GridLayout(); - gridLayout.numColumns = 3; - panel.setLayout(gridLayout); - panel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - // TODO... is there a better way to expand the page width? - // This invisible label is created to force the width of the page to - // be - // wide enough to show - // the rather long uri and key fields of a catalog entry. - Label widthFudger = new Label(panel, SWT.NONE); - String widthFudgerString = ""; //$NON-NLS-1$ - for (int i = 0; i < 55; i++) { - widthFudgerString += "x"; //$NON-NLS-1$ - } - widthFudger.setText(widthFudgerString); - widthFudger.setVisible(false); - Composite placeHolder = new Composite(panel, SWT.NONE); - placeHolder.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - advancedButton = new Button(panel, SWT.NONE); - advancedButton.setText(XMLCatalogMessages.UI_LABEL_ADVANCED); - SelectionListener selectionListener = new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - AdvancedOptionsDialog dialog = new AdvancedOptionsDialog(getShell(), workingUserCatalog); - dialog.create(); - dialog.getShell().setText(XMLCatalogMessages.UI_LABEL_ADVANCED_XML_CATALOG_PREFS); - dialog.setBlockOnOpen(true); - dialog.open(); - } - }; - advancedButton.addSelectionListener(selectionListener); - } - - public boolean isSameFileName(String a, String b) { - boolean result = false; - if ((a == null) && (b == null)) { - result = true; - } - else if ((a != null) && (b != null)) { - result = a.equals(b); - } - return result; - } - - protected void createCatalogEntriesView(Composite parent) { - Group group = new Group(parent, SWT.NONE); - group.setLayout(new GridLayout()); - group.setLayoutData(new GridData(GridData.FILL_BOTH)); - group.setText(XMLCatalogMessages.UI_LABEL_USER_ENTRIES); - group.setToolTipText(XMLCatalogMessages.UI_LABEL_USER_ENTRIES_TOOL_TIP); - // WorkbenchHelp.setHelp(userEntriesGroup, new - // ControlContextComputer(userEntriesGroup, - // XMLBuilderContextIds.XMLP_CATALOG_USER_GROUP)); - catalogEntriesView = new XMLCatalogEntriesView(group, workingUserCatalog, systemCatalog); - catalogEntriesView.setLayoutData(new GridData(GridData.FILL_BOTH)); - } - - protected void createCatalogDetailsView(Composite parent) { - Group detailsGroup = new Group(parent, SWT.NONE); - detailsGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - detailsGroup.setLayout(new GridLayout()); - detailsGroup.setText(XMLCatalogMessages.UI_LABEL_DETAILS); - final XMLCatalogEntryDetailsView detailsView = new XMLCatalogEntryDetailsView(detailsGroup); - ISelectionChangedListener listener = new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - ISelection selection = event.getSelection(); - Object selectedObject = (selection instanceof IStructuredSelection) && ((IStructuredSelection) selection).size() == 1 ? ((IStructuredSelection) selection).getFirstElement() : null; - if (selectedObject instanceof ICatalogEntry) { - ICatalogEntry entry = (ICatalogEntry) selectedObject; - detailsView.setCatalogElement(entry); - } - else if (selectedObject instanceof INextCatalog) { - INextCatalog entry = (INextCatalog) selectedObject; - detailsView.setCatalogElement(entry); - } - else { - detailsView.setCatalogElement((ICatalogEntry) null); - } - - } - }; - catalogEntriesView.getViewer().addSelectionChangedListener(listener); - } - - /** - * Do anything necessary because the OK button has been pressed. - * - * @return whether it is okay to close the preference page - */ - public boolean performOk() { - return storeValues(); - } - - /** - * @see IWorkbenchPreferencePage - */ - public void init(IWorkbench workbench) { - } - - /** - * Stores the values of the controls back to the preference store. - */ - private boolean storeValues() { - // dw Object fileObject = null; - try { - // update the userCatalog so that its the same as the working - // catalog - userCatalog.clear(); - // TODO add entries from the nested catalogs? - userCatalog.addEntriesFromCatalog(workingUserCatalog); - // now save the userCatalog - userCatalog.save(); - } - catch (Exception e) { - } - return true; - } - - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/XMLCatalogResources.properties b/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/XMLCatalogResources.properties deleted file mode 100644 index 0910d6c3d5..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/XMLCatalogResources.properties +++ /dev/null @@ -1,115 +0,0 @@ -############################################################################### -# Copyright (c) 2004, 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 -# David Carver/STAR Standard, d_a_carver@yahoo.com, bug 192568 -# - Fixed grammar in XML Catalog Import dialog. -############################################################################### -UI_WIZARD_SCHEMA_AND_NAME_SPACE_INFO = Schema and Namespace Information -UI_LABEL_NAME_SPACE_PREFIX = Namespace prefix: -UI_LABEL_NAME_SPACE_URI = Namespace URI: -UI_LABEL_XSD_LOCATION = Schema location: -UI_LABEL_DOCTYPE_INFORMATION = Document type information -UI_LABEL_SYSTEM_ID = &System ID: -UI_LABEL_PUBLIC_ID = &Public ID: -UI_LABEL_SELECT_FILE = Select File -UI_LABEL_KEY = Key -UI_LABEL_KEY_COLON = &Key: -UI_LABEL_DETAILS_KEY_COLON = Key: -UI_LABEL_DETAILS_IN_JAR_FILE = in jar file -UI_LABEL_URI = URI -UI_LABEL_LOCATION_COLON = &Location: -UI_LABEL_CATALOG_URI_COLON = Location of another XML Catalog file: -UI_LABEL_DETAILS_URI_COLON = URI: -UI_KEY_TYPE_COLON = Key &Type: -UI_KEY_TYPE_DETAILS_COLON = Key Type: -UI_LABEL_DETAILS_URI_LOCATION = Location: -UI_KEY_TYPE_DESCRIPTION_XSD_PUBLIC = Namespace Name -UI_KEY_TYPE_DESCRIPTION_XSD_SYSTEM = Schema Location -UI_KEY_TYPE_DESCRIPTION_DTD_PUBLIC = Public ID -UI_KEY_TYPE_DESCRIPTION_DTD_SYSTEM = System ID -UI_KEY_TYPE_DESCRIPTION_URI = URI -UI_LABEL_SPECIFY_ALTERNATIVE_WEB_URL = Specify &alternative web address -UI_WARNING_URI_MUST_NOT_HAVE_DOTS = URI must not included '.' or '..' -UI_LABEL_PLATFORM_RESOURCE = Workspace -UI_LABEL_FILE_SYSTEM_RESOURCE = File System - -UI_WARNING_URI_NOT_FOUND_COLON = The specified resource can't be located : -UI_WARNING_SHOULD_BE_FULLY_QUALIFIED_URI = Warning: the key value should be a fully qualified URI -UI_WARNING_URI_NOT_FOUND_LONG = The specified file cannot be found. It may have been moved to a different location. If the file is located remotely, a network connection cannot be established to the remote location. -UI_WARNING_INVALID_FILE = The specified file is invalid. -UI_WARNING_INVALID_FILE_LONG = The specified file is invalid. A proper XML file cannot be generated from it. Open the DTD or XML schema file, edit it as necessary, validate it and try again. -UI_WARNING_NO_ELEMENT = The specified file must contain at least one element declaration. -UI_WARNING_NO_ELEMENT_DTD_LONG = The specified file must contain at least one element declaration that can be used as the root element in the generated XML file. -UI_WARNING_NO_ELEMENT_XSD_LONG = The specified file must contain at least one global element declaration that can be used as the root element in the generated XML file. -UI_WARNING_DUPLICATE_ENTRY = The specified entry is invalid. An existing entry has the same key and key type. - - -!NewModelWizard -UI_INVALID_GRAMMAR_ERROR = Invalid Grammar -UI_BUTTON_BROWSE = &Browse... - -!XMLCatalogIdMappingPage -UI_LABEL_MAP_TO = Map to: -UI_LABEL_MAP_FROM = Map from: -UI_BUTTON_NEW = &Add... -UI_BUTTON_EDIT = &Edit... -UI_BUTTON_DELETE = &Delete -UI_BUTTON_REMOVE = &Remove -UI_LABEL_NEW_DIALOG_TITLE = Add XML Catalog Entry -UI_LABEL_EDIT_DIALOG_TITLE = Edit XML Catalog Entry - - -!XMLCatalogPreferencePage -UI_LABEL_USER_ENTRIES = XML Catalog Entries -UI_LABEL_USER_ENTRIES_TOOL_TIP = XML Catalog entries that have been specified by the user -UI_LABEL_SYSTEM_ENTRIES = Plug-in specified entries -UI_LABEL_SYSTEM_ENTRIES_TOOL_TIP = XML Catalog entries that have been specified by a plug-in -UI_BUTTON_CHANGE = Change... -UI_LABEL_SELECT_PROJECT = Select Project -UI_LABEL_SPECIFY_PROJECT_DESCRIPTION = Specify the project to persist the XML Catalog information -UI_WARNING_NO_PROJECTS_CREATED = No projects have been created yet. -UI_WARNING_PROJECT_NOT_SPECIFIED = A project name has not been specified. -UI_WARNING_PROJECT_DOES_NOT_EXIST = The specified project does not exist. -UI_LABEL_PROJECT_TO_USE = Project to use to persist XML Catalog User Entries: -UI_LABEL_CATALOG_SAVE_ERROR = XML Catalog Save Error -UI_LABEL_CATALOG_COULD_NOT_BE_SAVED = The XML Catalog entry could not be saved. -UI_LABEL_ADVANCED = &Advanced... -UI_LABEL_ADVANCED_XML_CATALOG_PREFS = Advanced XML Catalog Preferences -UI_LABEL_SPECIFY_PERSISTENCE_FILE = &Specify a file to use to persist the XML Catalog information. -UI_LABEL_SAVE_CATALOG_DIALOG_TITLE = Save Changes -UI_LABEL_SAVE_CATALOG_DIALOG_DESC = You have made unsaved changes to the current XML Catalog settings. Do you wish to save your changes before loading the new XML Catalog settings? -UI_LABEL_BROWSE_CATALOG_FILE_TITLE = Select Folder -UI_LABEL_BROWSE_CATALOG_FILE_DESC = Select the folder that contains the '.xmlcatalog' file. -UI_LABEL_DETAILS = Details -UI_LABEL_USER_SPECIFIED_ENTRIES = User Specified Entries -UI_LABEL_PLUGIN_SPECIFIED_ENTRIES = Plugin Specified Entries -UI_LABEL_FILE_SELECTION = File Selection -UI_LABEL_CHOOSE_FILE_TO_ADD_TO_CATALOG = Choose a file to add to the XML Catalog - -!AdvancedOptionsDialog -UI_LABEL_DIALOG_DESCRIPTION = Use the buttons below to import or export XML Catalog settings. -UI_BUTTON_IMPORT = Import... -UI_BUTTON_EXPORT = Export... - -UI_LABEL_IMPORT_DIALOG_TITLE = Import XML Catalog Settings -UI_LABEL_IMPORT_DIALOG_HEADING = Specify XML Catalog File -UI_LABEL_IMPORT_DIALOG_MESSAGE = Specify the file that will be used to load the XML Catalog Settings - -UI_LABEL_EXPORT_DIALOG_TITLE = Export XML Catalog Settings -UI_LABEL_EXPORT_DIALOG_HEADING = Specify XML Catalog File -UI_LABEL_EXPORT_DIALOG_MESSAGE = Specify the file that will used to save the XML Catalog Setting -ERROR_SAVING_FILE = Error saving file %1 -UI_LABEL_FILE_IS_READ_ONLY = File %1 is read only - -EditCatalogEntryDialog_catalogEntryLabel=Catalog Entry -EditCatalogEntryDialog_nextCatalogLabel=Next Catalog -UI_BUTTON_MENU_BROWSE_WORKSPACE=Workspace... -UI_BUTTON_MENU_BROWSE_FILE_SYSTEM=File System... -UI_LABEL_SELECT_FILE_FILTER_CONTROL=Files of type: -UI_TEXT_SELECT_FILE_FILTER_CONTROL=All Supported Files diff --git a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/XMLCatalogTreeViewer.java b/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/XMLCatalogTreeViewer.java deleted file mode 100644 index 30d49598e6..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/XMLCatalogTreeViewer.java +++ /dev/null @@ -1,260 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.catalog; - -import com.ibm.icu.text.Collator; -import java.util.Arrays; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerFilter; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.IEditorRegistry; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.common.uriresolver.internal.util.URIHelper; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogElement; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry; -import org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog; - - -public class XMLCatalogTreeViewer extends TreeViewer { - protected static Image xmlCatalogImage = ImageFactory.INSTANCE.getImage("icons/obj16/xmlcatalog_obj.gif"); //$NON-NLS-1$ - protected static Image errorImage = ImageFactory.INSTANCE.getImage("icons/ovr16/error-overlay.gif"); //$NON-NLS-1$ - protected static Image entryImage = ImageFactory.INSTANCE.getImage("icons/obj16/entry_obj.png"); //$NON-NLS-1$ - protected static Image nextCatalogImage = ImageFactory.INSTANCE.getImage("icons/obj16/nextCatalog_obj.gif"); //$NON-NLS-1$ - - protected static String ERROR_STATE_KEY = "errorstatekey"; //$NON-NLS-1$ - - protected ICatalog fWorkingUserCatalog; - protected ICatalog fSystemCatalog; - - public static String USER_SPECIFIED_ENTRIES_OBJECT = XMLCatalogMessages.UI_LABEL_USER_SPECIFIED_ENTRIES; - public static String PLUGIN_SPECIFIED_ENTRIES_OBJECT = XMLCatalogMessages.UI_LABEL_PLUGIN_SPECIFIED_ENTRIES; - - public XMLCatalogTreeViewer(Composite parent, ICatalog workingUserCatalog, ICatalog systemCatalog) { - super(parent, SWT.MULTI | SWT.BORDER); - this.fWorkingUserCatalog = workingUserCatalog; - this.fSystemCatalog = systemCatalog; - - setContentProvider(new CatalogEntryContentProvider()); - setLabelProvider(new CatalogEntryLabelProvider()); - } - - public void setFilterExtensions(String[] extensions) { - resetFilters(); - addFilter(new XMLCatalogTableViewerFilter(extensions)); - } - - public class CatalogEntryLabelProvider extends LabelProvider { - protected HashMap imageTable = new HashMap(); - - public String getText(Object object) { - String result = null; - if (object instanceof ICatalogEntry) { - ICatalogEntry catalogEntry = (ICatalogEntry) object; - result = catalogEntry.getKey(); - // result = URIHelper.removePlatformResourceProtocol(result); - } - else if (object instanceof INextCatalog) { - INextCatalog nextCatalog = (INextCatalog) object; - // result = nextCatalog.getCatalogLocation(); - result = URIUtils.convertURIToLocation(nextCatalog.getCatalogLocation()); - if (nextCatalog.getCatalogLocation().startsWith("file:")) { - result += " (" + XMLCatalogMessages.UI_LABEL_FILE_SYSTEM_RESOURCE + ")"; - } - else if (nextCatalog.getCatalogLocation().startsWith("platform:")) { - result += " (" + XMLCatalogMessages.UI_LABEL_PLATFORM_RESOURCE + ")"; - } - } - return result != null ? result : object.toString(); - } - - public Image getImage(Object object) { - Image result = null; - Image base = null; - if (object instanceof String) { - result = xmlCatalogImage; - } - else if (object instanceof ICatalogEntry) { - ICatalogEntry catalogEntry = (ICatalogEntry) object; - String uri = catalogEntry.getURI(); - IEditorRegistry er = PlatformUI.getWorkbench().getEditorRegistry(); - ImageDescriptor imageDescriptor = er.getImageDescriptor(uri); - Image image = (Image) imageTable.get(imageDescriptor); - if (image == null) { - image = imageDescriptor.createImage(); - imageTable.put(imageDescriptor, image); - } - base = image; - - if (base != null) { - if (URIHelper.isReadableURI(uri, true)) { - result = base; - } - else { - result = ImageFactory.INSTANCE.createCompositeImage(base, errorImage, ImageFactory.BOTTOM_LEFT); - } - } - } - else if (object instanceof INextCatalog) { - // TODO: add image to the imageTable and add error overlay if - // next catalog URI is not readable - result = nextCatalogImage; - } - return result; - } - - public void dispose() { - super.dispose(); - for (Iterator it = imageTable.values().iterator(); it.hasNext();) { - ((Image) it.next()).dispose(); - } - } - } - - - public class CatalogEntryContentProvider implements ITreeContentProvider { - protected Object[] roots; - - public CatalogEntryContentProvider() { - roots = new Object[2]; - roots[0] = USER_SPECIFIED_ENTRIES_OBJECT; - roots[1] = PLUGIN_SPECIFIED_ENTRIES_OBJECT; - } - - public boolean isRoot(Object object) { - return (object instanceof String) || (object instanceof INextCatalog); - } - - public Object[] getElements(Object element) { - return roots; - } - - public Object[] getChildren(Object parentElement) { - Object[] result = new Object[0]; - if (parentElement == roots[0]) { - result = getChildrenHelper(fWorkingUserCatalog); - } - else if (parentElement == roots[1]) { - result = getChildrenHelper(fSystemCatalog); - } - else if (parentElement instanceof INextCatalog) { - ICatalog nextCatalog = ((INextCatalog) parentElement).getReferencedCatalog(); - result = getChildrenHelper(nextCatalog); - } - return result; - } - - protected Object[] getChildrenHelper(ICatalog catalog) { - // TODO add entries from the nested catalogs - - ICatalogEntry[] entries = catalog.getCatalogEntries(); - if (entries.length > 0) { - Comparator comparator = new Comparator() { - public int compare(Object o1, Object o2) { - int result = 0; - if ((o1 instanceof ICatalogEntry) && (o2 instanceof ICatalogEntry)) { - ICatalogEntry entry1 = (ICatalogEntry) o1; - ICatalogEntry entry2 = (ICatalogEntry) o2; - result = Collator.getInstance().compare(entry1.getKey(), entry2.getKey()); - } - return result; - } - }; - Arrays.sort(entries, comparator); - } - Vector result = new Vector(); - result.addAll(Arrays.asList(entries)); - INextCatalog[] nextCatalogs = catalog.getNextCatalogs(); - List nextCatalogsList = Arrays.asList(nextCatalogs); - result.addAll(nextCatalogsList); - - return result.toArray(new ICatalogElement[result.size()]); - } - - public Object getParent(Object element) { - return (element instanceof String) ? null : USER_SPECIFIED_ENTRIES_OBJECT; - } - - public boolean hasChildren(Object element) { - return isRoot(element) ? getChildren(element).length > 0 : false; - } - - public void dispose() { - // nothing to dispose - } - - public void inputChanged(Viewer viewer, Object old, Object newobj) { - // ISSUE: seems we should do something here - } - - public boolean isDeleted(Object object) { - return false; - } - } - - - public void menuAboutToShow(IMenuManager menuManager) { - Action action = new Action("hello") { //$NON-NLS-1$ - public void run() { - System.out.println("run!"); //$NON-NLS-1$ - } - }; - menuManager.add(action); - } - - - class XMLCatalogTableViewerFilter extends ViewerFilter { - protected String[] extensions; - - public XMLCatalogTableViewerFilter(String[] extensions1) { - this.extensions = extensions1; - } - - public boolean isFilterProperty(Object element, Object property) { - return false; - } - - public boolean select(Viewer viewer, Object parent, Object element) { - boolean result = false; - if (element instanceof ICatalogEntry) { - ICatalogEntry catalogEntry = (ICatalogEntry) element; - for (int i = 0; i < extensions.length; i++) { - if (catalogEntry.getURI().endsWith(extensions[i])) { - result = true; - break; - } - } - } - else if (element.equals(XMLCatalogTreeViewer.PLUGIN_SPECIFIED_ENTRIES_OBJECT) || element.equals(XMLCatalogTreeViewer.USER_SPECIFIED_ENTRIES_OBJECT)) { - return true; - } - return result; - } - } - - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/XMLQuickScan.java b/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/XMLQuickScan.java deleted file mode 100644 index 723539d86c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/XMLQuickScan.java +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.catalog; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; - -import org.eclipse.wst.xml.ui.internal.Logger; -import org.xml.sax.Attributes; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.DefaultHandler; - -/** - * - */ -public class XMLQuickScan { - public static String getTargetNamespaceURIForSchema(String uri) { - String result = null; - try { - URL url = new URL(uri); - InputStream inputStream = url.openStream(); - result = XMLQuickScan.getTargetNamespaceURIForSchema(inputStream); - } - catch (Exception e) { - } - return result; - } - - public static String getTargetNamespaceURIForSchema(InputStream input) { - TargetNamespaceURIContentHandler handler = new TargetNamespaceURIContentHandler(); - ClassLoader prevClassLoader = Thread.currentThread().getContextClassLoader(); - try { - Thread.currentThread().setContextClassLoader(XMLQuickScan.class.getClassLoader()); - SAXParserFactory factory = SAXParserFactory.newInstance(); - factory.setNamespaceAware(true); - SAXParser parser = factory.newSAXParser(); - parser.parse(new InputSource(input), handler); - } - catch (StopParseException e) { - // this is a normal exception to stop parsing early, - // when info is found, so we can safely ignore - } - catch (ParserConfigurationException e) { - Logger.logException(e); - } - catch (SAXException e) { - Logger.logException(e); - } - catch (IOException e) { - Logger.logException(e); - } - finally { - Thread.currentThread().setContextClassLoader(prevClassLoader); - } - return handler.targetNamespaceURI; - } - - /** - * This is a special exception that is used to stop parsing when required - * information is found. - */ - static class StopParseException extends org.xml.sax.SAXException { - static final long serialVersionUID = 1L; - - /** - * Constructor StopParseException. - */ - StopParseException() { - super("targetnamespace found, no need to continue the parse"); - } - } - - static class TargetNamespaceURIContentHandler extends DefaultHandler { - public String targetNamespaceURI; - - public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { - if (localName.equals("schema")) //$NON-NLS-1$ - { - int nAttributes = attributes.getLength(); - for (int i = 0; i < nAttributes; i++) { - if (attributes.getLocalName(i).equals("targetNamespace")) //$NON-NLS-1$ - { - targetNamespaceURI = attributes.getValue(i); - break; - } - } - } - throw new StopParseException(); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/icons/etool50/catalogEntry.gif b/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/icons/etool50/catalogEntry.gif Binary files differdeleted file mode 100644 index d65b280297..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/icons/etool50/catalogEntry.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/icons/etool50/nextCatalog.gif b/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/icons/etool50/nextCatalog.gif Binary files differdeleted file mode 100644 index 3a934b907c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/icons/etool50/nextCatalog.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/icons/obj16/entry_obj.png b/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/icons/obj16/entry_obj.png Binary files differdeleted file mode 100644 index be7147416b..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/icons/obj16/entry_obj.png +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/icons/obj16/file_expand.gif b/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/icons/obj16/file_expand.gif Binary files differdeleted file mode 100644 index 85f9baaf44..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/icons/obj16/file_expand.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/icons/obj16/file_obj.gif b/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/icons/obj16/file_obj.gif Binary files differdeleted file mode 100644 index 061161ae1c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/icons/obj16/file_obj.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/icons/obj16/nextCatalog_obj.gif b/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/icons/obj16/nextCatalog_obj.gif Binary files differdeleted file mode 100644 index d4bfe79eb9..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/icons/obj16/nextCatalog_obj.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/icons/obj16/xmlcatalog_obj.gif b/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/icons/obj16/xmlcatalog_obj.gif Binary files differdeleted file mode 100644 index a61441f2a8..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/icons/obj16/xmlcatalog_obj.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/icons/ovr16/error-overlay.gif b/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/icons/ovr16/error-overlay.gif Binary files differdeleted file mode 100644 index 119dcccd5a..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-catalog/org/eclipse/wst/xml/ui/internal/catalog/icons/ovr16/error-overlay.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/DOMPropertyDescriptorFactory.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/DOMPropertyDescriptorFactory.java deleted file mode 100644 index 5bebb72cca..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/DOMPropertyDescriptorFactory.java +++ /dev/null @@ -1,135 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 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.wst.xml.ui.internal.tabletree; - -import org.eclipse.ui.views.properties.IPropertyDescriptor; -import org.eclipse.ui.views.properties.TextPropertyDescriptor; -import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.ui.internal.properties.EnumeratedStringPropertyDescriptor; -import org.w3c.dom.Attr; -import org.w3c.dom.CDATASection; -import org.w3c.dom.Comment; -import org.w3c.dom.DocumentType; -import org.w3c.dom.Element; -import org.w3c.dom.EntityReference; -import org.w3c.dom.Node; -import org.w3c.dom.ProcessingInstruction; -import org.w3c.dom.Text; - - -public class DOMPropertyDescriptorFactory { - - protected static final String HACK = "hack"; //$NON-NLS-1$ - - public DOMPropertyDescriptorFactory() { - } - - public IPropertyDescriptor createAttributePropertyDescriptor(Attr attr) { - IPropertyDescriptor result = null; - - String attributeName = attr.getName(); - - ModelQuery mq = ModelQueryUtil.getModelQuery(attr.getOwnerDocument()); - - if (mq != null) { - CMAttributeDeclaration ad = mq.getCMAttributeDeclaration(attr); - if (ad != null) { - String[] valuesArray = mq.getPossibleDataTypeValues(attr.getOwnerElement(), ad); - if ((valuesArray != null) && (valuesArray.length > 0)) { - result = new EnumeratedStringPropertyDescriptor(attributeName, attributeName, valuesArray); - } - } - } - - if (result == null) { - result = createDefaultPropertyDescriptor(attributeName); - } - return result; - } - - public IPropertyDescriptor createCDATASectionPropertyDescriptor(CDATASection cdataSection) { - return createDefaultPropertyDescriptor(HACK); - } - - public IPropertyDescriptor createCommentPropertyDescriptor(Comment comment) { - return createDefaultPropertyDescriptor(HACK); - } - - protected IPropertyDescriptor createDefaultPropertyDescriptor(String attributeName) { - TextPropertyDescriptor descriptor = new TextPropertyDescriptor(attributeName, attributeName); - return descriptor; - } - - public IPropertyDescriptor createDocumentTypePropertyDescriptor(DocumentType documentType) { - return null; // new TextPropertyDescriptor(HACK, HACK); - } - - public IPropertyDescriptor createElementPropertyDescriptor(Element element) { - return createDefaultPropertyDescriptor(HACK); - } - - public IPropertyDescriptor createEntityReferencePropertyDescriptor(EntityReference entityReference) { - return createDefaultPropertyDescriptor(HACK); - } - - public IPropertyDescriptor createProcessingInstructionPropertyDescriptor(ProcessingInstruction pi) { - return createDefaultPropertyDescriptor(HACK); - } - - public IPropertyDescriptor createPropertyDescriptor(Object object) { - IPropertyDescriptor result = null; - if (object instanceof Node) { - Node node = (Node) object; - int nodeType = node.getNodeType(); - switch (nodeType) { - case Node.ATTRIBUTE_NODE : { - result = createAttributePropertyDescriptor((Attr) node); - break; - } - case Node.CDATA_SECTION_NODE : { - result = createCDATASectionPropertyDescriptor((CDATASection) node); - break; - } - case Node.COMMENT_NODE : { - result = createCommentPropertyDescriptor((Comment) node); - break; - } - case Node.DOCUMENT_TYPE_NODE : { - result = createDocumentTypePropertyDescriptor((DocumentType) node); - break; - } - case Node.ELEMENT_NODE : { - result = createElementPropertyDescriptor((Element) node); - break; - } - case Node.ENTITY_REFERENCE_NODE : { - result = createEntityReferencePropertyDescriptor((EntityReference) node); - break; - } - case Node.PROCESSING_INSTRUCTION_NODE : { - result = createProcessingInstructionPropertyDescriptor((ProcessingInstruction) node); - break; - } - case Node.TEXT_NODE : { - result = createTextPropertyDescriptor((Text) node); - break; - } - } - } - return result; - } - - public IPropertyDescriptor createTextPropertyDescriptor(Text text) { - return createDefaultPropertyDescriptor(HACK); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/IDesignViewer.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/IDesignViewer.java deleted file mode 100644 index f1be97fd80..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/IDesignViewer.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 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.wst.xml.ui.internal.tabletree; - -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.swt.widgets.Control; - -public interface IDesignViewer { - public Control getControl(); - - String getTitle(); - - void setDocument(IDocument document); - - ISelectionProvider getSelectionProvider(); -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/IDesignViewerActionBarContributor.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/IDesignViewerActionBarContributor.java deleted file mode 100644 index 411a3f9178..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/IDesignViewerActionBarContributor.java +++ /dev/null @@ -1,21 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 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.wst.xml.ui.internal.tabletree; - - - -import org.eclipse.ui.IActionBars; -import org.eclipse.wst.sse.ui.internal.ISourceViewerActionBarContributor; - - -public interface IDesignViewerActionBarContributor extends ISourceViewerActionBarContributor { - public void initViewerSpecificContributions(IActionBars bars); -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/SourceEditorActionBarContributor.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/SourceEditorActionBarContributor.java deleted file mode 100644 index 5e9ffccd60..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/SourceEditorActionBarContributor.java +++ /dev/null @@ -1,228 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 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.wst.xml.ui.internal.tabletree; - -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.IStatusLineManager; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IEditorActionBarContributor; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.part.MultiPageEditorActionBarContributor; -import org.eclipse.ui.part.MultiPageEditorPart; -import org.eclipse.wst.sse.ui.StructuredTextEditor; -import org.eclipse.wst.sse.ui.internal.ExtendedEditorActionBuilder; -import org.eclipse.wst.sse.ui.internal.IExtendedContributor; -import org.eclipse.wst.sse.ui.internal.ISourceViewerActionBarContributor; - - -public class SourceEditorActionBarContributor extends MultiPageEditorActionBarContributor implements IExtendedContributor { - - protected IEditorActionBarContributor designViewerActionBarContributor = null; - protected IEditorActionBarContributor sourceViewerActionContributor = null; - protected MultiPageEditorPart multiPageEditor = null; - - // EditorExtension - private static final String EDITOR_ID = "org.eclipse.wst.xml.ui.XMLMultiPageEditorPart"; //$NON-NLS-1$ - private IExtendedContributor extendedContributor; - - public SourceEditorActionBarContributor() { - super(); - - sourceViewerActionContributor = new SourcePageActionContributor(); - - // Read action extensions. - ExtendedEditorActionBuilder builder = new ExtendedEditorActionBuilder(); - extendedContributor = builder.readActionExtensions(EDITOR_ID); - } - - public void init(IActionBars actionBars) { - super.init(actionBars); - - if (actionBars != null) { - initDesignViewerActionBarContributor(actionBars); - initSourceViewerActionContributor(actionBars); - } - } - - protected void initDesignViewerActionBarContributor(IActionBars actionBars) { - if (designViewerActionBarContributor != null) { - designViewerActionBarContributor.init(actionBars, getPage()); - } - } - - protected void initSourceViewerActionContributor(IActionBars actionBars) { - if (sourceViewerActionContributor != null) { - sourceViewerActionContributor.init(actionBars, getPage()); - } - } - - public void dispose() { - super.dispose(); - - if (designViewerActionBarContributor != null) { - designViewerActionBarContributor.dispose(); - } - - if (sourceViewerActionContributor != null) { - sourceViewerActionContributor.dispose(); - } - - if (extendedContributor != null) { - extendedContributor.dispose(); - } - } - - /** - * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToMenu(IMenuManager) - */ - public final void contributeToMenu(IMenuManager menu) { - super.contributeToMenu(menu); - - //addToMenu(menu); - - if (extendedContributor != null) { - extendedContributor.contributeToMenu(menu); - } - } - - protected void addToMenu(IMenuManager menu) { - } - - /** - * @see IExtendedContributor#contributeToPopupMenu(IMenuManager) - */ - public final void contributeToPopupMenu(IMenuManager menu) { - - addToPopupMenu(menu); - - if (extendedContributor != null) { - extendedContributor.contributeToPopupMenu(menu); - } - } - - protected void addToPopupMenu(IMenuManager menu) { - } - - /** - * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToToolBar(IToolBarManager) - */ - public final void contributeToToolBar(IToolBarManager toolBarManager) { - super.contributeToToolBar(toolBarManager); - - addToToolBar(toolBarManager); - - if (extendedContributor != null) { - extendedContributor.contributeToToolBar(toolBarManager); - } - } - - protected void addToToolBar(IToolBarManager toolBarManager) { - } - - /** - * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToStatusLine(IStatusLineManager) - */ - public final void contributeToStatusLine(IStatusLineManager manager) { - super.contributeToStatusLine(manager); - - addToStatusLine(manager); - - if (extendedContributor != null) { - extendedContributor.contributeToStatusLine(manager); - } - } - - protected void addToStatusLine(IStatusLineManager manager) { - } - - /** - * @see IExtendedContributor#updateToolbarActions() - */ - public void updateToolbarActions() { - if (extendedContributor != null) { - extendedContributor.updateToolbarActions(); - } - } - - public void setActiveEditor(IEditorPart targetEditor) { - // save multiPageEditor before calling - // super.setActiveEditor(targetEditor) - // super.setActiveEditor will call setActivePage(IEditorPart - // activeEditor) - // multiPageEditor is needed in setActivePage(IEditorPart - // activeEditor) - if (targetEditor instanceof MultiPageEditorPart) { - multiPageEditor = (MultiPageEditorPart) targetEditor; - } - - super.setActiveEditor(targetEditor); - - updateToolbarActions(); - - if (extendedContributor != null) { - extendedContributor.setActiveEditor(targetEditor); - } - } - - public void setActivePage(IEditorPart activeEditor) { - // This contributor is designed for StructuredTextMultiPageEditorPart. - // To safe-guard this from problems caused by unexpected usage by - // other editors, the following - // check is added. - if (multiPageEditor != null) { - if ((activeEditor != null) && (activeEditor instanceof StructuredTextEditor)) { - activateSourcePage(activeEditor); - } - else { - activateDesignPage(activeEditor); - } - } - - updateToolbarActions(); - - IActionBars actionBars = getActionBars(); - if (actionBars != null) { - // update menu bar and tool bar - actionBars.updateActionBars(); - } - } - - protected void activateDesignPage(IEditorPart activeEditor) { - if ((designViewerActionBarContributor != null) && (designViewerActionBarContributor instanceof IDesignViewerActionBarContributor)) { - designViewerActionBarContributor.setActiveEditor(multiPageEditor); - } - - if ((sourceViewerActionContributor != null) && (sourceViewerActionContributor instanceof ISourceViewerActionBarContributor)) { - // if design page is not really an IEditorPart, activeEditor == - // null, so pass in multiPageEditor instead (d282414) - if (activeEditor == null) { - sourceViewerActionContributor.setActiveEditor(multiPageEditor); - } - else { - sourceViewerActionContributor.setActiveEditor(activeEditor); - } - ((ISourceViewerActionBarContributor) sourceViewerActionContributor).setViewerSpecificContributionsEnabled(false); - } - } - - protected void activateSourcePage(IEditorPart activeEditor) { - if ((designViewerActionBarContributor != null) && (designViewerActionBarContributor instanceof IDesignViewerActionBarContributor)) { - designViewerActionBarContributor.setActiveEditor(multiPageEditor); - } - - if ((sourceViewerActionContributor != null) && (sourceViewerActionContributor instanceof ISourceViewerActionBarContributor)) { - sourceViewerActionContributor.setActiveEditor(activeEditor); - ((ISourceViewerActionBarContributor) sourceViewerActionContributor).setViewerSpecificContributionsEnabled(true); - } - } - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/SourcePageActionContributor.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/SourcePageActionContributor.java deleted file mode 100644 index bd1e251276..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/SourcePageActionContributor.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 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.wst.xml.ui.internal.tabletree; - - - -import org.eclipse.ui.IActionBars; -import org.eclipse.wst.xml.ui.internal.actions.ActionContributorXML; - - -/** - * SourcePageActionContributor - * - * This class is for multi page editor's source page contributor. - * - * Use XMLEditorActionContributor for single page editor. - */ -public class SourcePageActionContributor extends ActionContributorXML { - - private IActionBars fBars; - - /** - * This method calls: - * <ul> - * <li><code>contributeToMenu</code> with <code>bars</code>' menu - * manager</li> - * <li><code>contributeToToolBar</code> with <code>bars</code>' tool - * bar manager</li> - * <li><code>contributeToStatusLine</code> with <code>bars</code>' - * status line manager</li> - * </ul> - * The given action bars are also remembered and made accessible via - * <code>getActionBars</code>. - * - * @param bars - * the action bars - * - */ - public void init(IActionBars bars) { - fBars = bars; - contributeToMenu(bars.getMenuManager()); - contributeToToolBar(bars.getToolBarManager()); - contributeToStatusLine(bars.getStatusLineManager()); - } - - /** - * Returns this contributor's action bars. - * - * @return the action bars - */ - public IActionBars getActionBars() { - return fBars; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/TreeContentHelper.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/TreeContentHelper.java deleted file mode 100644 index 11a4dd61df..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/TreeContentHelper.java +++ /dev/null @@ -1,459 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004-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.wst.xml.ui.internal.tabletree; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMWriter; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.w3c.dom.Attr; -import org.w3c.dom.CharacterData; -import org.w3c.dom.DOMException; -import org.w3c.dom.Document; -import org.w3c.dom.DocumentType; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.ProcessingInstruction; -import org.w3c.dom.Text; - - -/** - * This performs the work of taking a DOM tree and converting it to a - * displayable 'UI' tree. - * - * For example : - white space text nodes are ommited from the 'UI' tree - - * adjacent Text and EntityReference nodes are combined into a single 'UI' - * node - Elements with 'text only' children are diplayed without children - * - */ -public class TreeContentHelper { - - public static final int HIDE_WHITE_SPACE_TEXT_NODES = 8; - public static final int COMBINE_ADJACENT_TEXT_AND_ENTITY_REFERENCES = 16; - public static final int HIDE_ELEMENT_CHILD_TEXT_NODES = 32; - - protected int style = HIDE_WHITE_SPACE_TEXT_NODES | COMBINE_ADJACENT_TEXT_AND_ENTITY_REFERENCES | HIDE_ELEMENT_CHILD_TEXT_NODES; - - /** - * - */ - public boolean hasStyleFlag(int flag) { - return (style & flag) != 0; - } - - /** - * - */ - public Object[] getChildren(Object element) { - Object[] result = null; - - if (element instanceof Node) { - Node node = (Node) element; - List list = new ArrayList(); - boolean textContentOnly = true; - - NamedNodeMap map = node.getAttributes(); - if (map != null) { - int length = map.getLength(); - for (int i = 0; i < length; i++) { - list.add(map.item(i)); - textContentOnly = false; - } - } - - Node prevIncludedNode = null; - for (Node childNode = node.getFirstChild(); childNode != null; childNode = childNode.getNextSibling()) { - int childNodeType = childNode.getNodeType(); - boolean includeNode = true; - - if (includeNode && hasStyleFlag(HIDE_WHITE_SPACE_TEXT_NODES)) { - if (isIgnorableText(childNode)) { - // filter out the ignorable text node - includeNode = false; - } - } - - if (includeNode && hasStyleFlag(COMBINE_ADJACENT_TEXT_AND_ENTITY_REFERENCES)) { - if (isTextOrEntityReferenceNode(childNode) && (prevIncludedNode != null) && isTextOrEntityReferenceNode(prevIncludedNode)) { - // we only show the first of a list of adjacent text - // or entity reference node in the tree - // so we filter out this subsequent one - includeNode = false; - } - } - - if (hasStyleFlag(HIDE_ELEMENT_CHILD_TEXT_NODES)) { - if ((childNodeType != Node.TEXT_NODE) && (childNodeType != Node.ENTITY_REFERENCE_NODE)) { - textContentOnly = false; - } - } - - if (includeNode) { - list.add(childNode); - prevIncludedNode = childNode; - } - } - - if (hasStyleFlag(HIDE_ELEMENT_CHILD_TEXT_NODES) && textContentOnly) { - result = new Object[0]; - } - else { - result = list.toArray(); - } - } - return result; - } - - /** - * - */ - protected boolean isTextOrEntityReferenceNode(Node node) { - return (node.getNodeType() == Node.TEXT_NODE) || (node.getNodeType() == Node.ENTITY_REFERENCE_NODE); - } - - /** - * - */ - public boolean isIgnorableText(Node node) { - boolean result = false; - if (node.getNodeType() == Node.TEXT_NODE) { - String data = ((Text) node).getData(); - result = ((data == null) || (data.trim().length() == 0)); - } - return result; - } - - /** - * - */ - public boolean isCombinedTextNode(Node node) { - boolean result = false; - if (node.getNodeType() == Node.TEXT_NODE) { - Node nextNode = node.getNextSibling(); - if (nextNode != null) { - if (nextNode.getNodeType() == Node.ENTITY_REFERENCE_NODE) { - result = true; - } - } - } - else if (node.getNodeType() == Node.ENTITY_REFERENCE_NODE) { - result = true; - } - return result; - } - - /** - * - */ - public List getCombinedTextNodeList(Node theNode) { - List list = new Vector(); - boolean prevIsEntity = false; - for (Node node = theNode; node != null; node = node.getNextSibling()) { - int nodeType = node.getNodeType(); - if (nodeType == Node.ENTITY_REFERENCE_NODE) { - prevIsEntity = true; - list.add(node); - } - else if ((nodeType == Node.TEXT_NODE) && (prevIsEntity || (node == theNode))) { - prevIsEntity = false; - list.add(node); - } - else { - break; - } - } - return list; - } - - public String getElementTextValue(Element element) { - List list = _getElementTextContent(element); - return list != null ? getValueForTextContent(list) : null; - } - - public void setElementTextValue(Element element, String value) { - setElementNodeValue(element, value); - } - - private List _getElementTextContent(Element element) { - List result = null; - - for (Node node = element.getFirstChild(); node != null; node = node.getNextSibling()) { - if ((node.getNodeType() == Node.TEXT_NODE) || (node.getNodeType() == Node.ENTITY_REFERENCE_NODE)) { - if (result == null) { - result = new Vector(); - } - result.add(node); - } - else { - result = null; - break; - } - } - return result; - } - - /** - * If the element is has 'text only' content this method will return the - * list of elements that compose the text only content - */ - public List getElementTextContent(Element element) { - List result = null; - if (!element.hasAttributes()) { - result = _getElementTextContent(element); - } - return result; - } - - - /** - * - */ - public String getNodeValue(Node node) { - String result = null; - int nodeType = node.getNodeType(); - switch (nodeType) { - case Node.ATTRIBUTE_NODE : { - result = ((Attr) node).getValue(); - break; - } - case Node.CDATA_SECTION_NODE : - // drop thru - case Node.COMMENT_NODE : { - result = ((CharacterData) node).getData(); - break; - } - case Node.DOCUMENT_TYPE_NODE : { - result = getDocumentTypeValue((DocumentType) node); - break; - } - case Node.ELEMENT_NODE : { - result = getElementNodeValue((Element) node); - break; - } - case Node.ENTITY_REFERENCE_NODE : - // drop thru - case Node.TEXT_NODE : { - result = getTextNodeValue(node); - break; - } - case Node.PROCESSING_INSTRUCTION_NODE : { - result = ((ProcessingInstruction) node).getData(); - break; - } - } - return result; - } - - /** - * - */ - public void setNodeValue(Node node, String value) { - int nodeType = node.getNodeType(); - try { - switch (nodeType) { - case Node.ATTRIBUTE_NODE : { - ((Attr) node).setValue(value); - break; - } - case Node.CDATA_SECTION_NODE : - // drop thru - case Node.COMMENT_NODE : { - ((CharacterData) node).setData(value); - break; - } - case Node.ELEMENT_NODE : { - setElementNodeValue((Element) node, value); - break; - } - case Node.ENTITY_REFERENCE_NODE : - // drop thru - case Node.TEXT_NODE : { - setTextNodeValue(node, value); - break; - } - case Node.PROCESSING_INSTRUCTION_NODE : { - ((ProcessingInstruction) node).setData(value); - break; - } - } - } - catch (DOMException e) { - Display d = getDisplay(); - if (d != null) { - d.beep(); - } - } - } - - private Display getDisplay() { - - return PlatformUI.getWorkbench().getDisplay(); - } - - - /** - * - */ - protected String getDocumentTypeValue(DocumentType documentType) { - return DOMWriter.getDocumentTypeData(documentType); - } - - /** - * - */ - protected String getElementNodeValue(Element element) { - String result = null; - List list = getElementTextContent(element); - if (list != null) { - result = getValueForTextContent(list); - } - return result; - } - - /** - * - */ - protected void setElementNodeValue(Element element, String value) { - List list = getElementTextContent(element); - if (list != null) { - setValueForTextContent(list, value); - } - else { - Document document = element.getOwnerDocument(); - Text text = document.createTextNode(value); - element.appendChild(text); - } - } - - /** - * - */ - protected String getTextNodeValue(Node node) { - String result = null; - List list = null; - if (isCombinedTextNode(node)) { - list = getCombinedTextNodeList(node); - } - else { - list = new Vector(); - list.add(node); - } - result = getValueForTextContent(list); - return result; - } - - /** - * - */ - protected void setTextNodeValue(Node node, String value) { - List list = null; - if (isCombinedTextNode(node)) { - list = getCombinedTextNodeList(node); - } - else { - list = new Vector(); - list.add(node); - } - setValueForTextContent(list, value); - } - - public Text getEffectiveTextNodeForCombinedNodeList(List list) { - Text result = null; - for (Iterator i = list.iterator(); i.hasNext();) { - Node node = (Node) i.next(); - if (node.getNodeType() == Node.TEXT_NODE) { - result = (Text) node; - break; - } - } - return result; - } - - /** - * - */ - protected String getValueForTextContent(List list) { - String result = null; - if (list.size() > 0) { - IDOMNode first = (IDOMNode) list.get(0); - IDOMNode last = (IDOMNode) list.get(list.size() - 1); - IDOMModel model = first.getModel(); - int start = first.getStartOffset(); - int end = last.getEndOffset(); - try { - result = model.getStructuredDocument().get(start, end - start); - } - catch (Exception e) { - } - } - - // we trim the content so that it looks nice when viewed - // we need to be carfull to preserve the 'trimmed' text when the value - // is set (see setValueForTextContent) - if (result != null) { - result = result.trim(); - } - return result; - } - - /** - * - */ - protected void setValueForTextContent(List list, String value) { - // String oldValue = getValueForTextContent(); - // we worry about preserving trimmed text - if (list.size() > 0) { - IDOMNode first = (IDOMNode) list.get(0); - IDOMNode last = (IDOMNode) list.get(list.size() - 1); - int start = first.getStartOffset(); - int end = last.getEndOffset(); - first.getModel().getStructuredDocument().replaceText(this, start, end - start, value); - } - } - - /** - * - */ - public boolean isEditable(Node node) { - int nodeType = node.getNodeType(); - boolean result = false; - switch (nodeType) { - case Node.ATTRIBUTE_NODE : - // drop thru - case Node.CDATA_SECTION_NODE : - // drop thru - case Node.COMMENT_NODE : - // drop thru - case Node.ENTITY_REFERENCE_NODE : - // drop thru - case Node.TEXT_NODE : - // drop thru - case Node.PROCESSING_INSTRUCTION_NODE : { - result = true; - break; - } - case Node.ELEMENT_NODE : { - result = (getElementTextContent((Element) node) != null) || (node.getChildNodes().getLength() == 0); - break; - } - } - return result; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/TreeExtension.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/TreeExtension.java deleted file mode 100644 index c9832cc8ef..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/TreeExtension.java +++ /dev/null @@ -1,557 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 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.wst.xml.ui.internal.tabletree; - -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - -import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.ICellEditorListener; -import org.eclipse.jface.viewers.ICellModifier; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.FocusEvent; -import org.eclipse.swt.events.FocusListener; -import org.eclipse.swt.events.KeyAdapter; -import org.eclipse.swt.events.KeyEvent; -import org.eclipse.swt.events.KeyListener; -import org.eclipse.swt.events.MouseAdapter; -import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.events.MouseMoveListener; -import org.eclipse.swt.events.PaintEvent; -import org.eclipse.swt.events.PaintListener; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Cursor; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.ScrollBar; -import org.eclipse.swt.widgets.Text; -import org.eclipse.swt.widgets.Tree; -import org.eclipse.swt.widgets.TreeItem; -import org.eclipse.ui.PlatformUI; - - -public class TreeExtension implements PaintListener { - - protected Tree fTree; - protected EditManager editManager; - protected String[] fColumnProperties; - protected ICellModifier cellModifier; - protected int columnPosition = 300; - protected int columnHitWidth = 5; - protected Color tableLineColor; - protected int controlWidth; - protected DelayedDrawTimer delayedDrawTimer; - private boolean fisUnsupportedInput = false; - - public TreeExtension(Tree tree) { - this.fTree = tree; - InternalMouseListener listener = new InternalMouseListener(); - tree.addMouseMoveListener(listener); - tree.addMouseListener(listener); - tree.addPaintListener(this); - editManager = new EditManager(tree); - delayedDrawTimer = new DelayedDrawTimer(tree); - - tableLineColor = tree.getDisplay().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW); - } - - public void dispose() { - tableLineColor.dispose(); - } - - public void setCellModifier(ICellModifier modifier) { - cellModifier = modifier; - } - - public void resetCachedData() { - // todo: sure seems we should reset something? - } - - public ICellModifier getCellModifier() { - return cellModifier; - } - - public List getItemList() { - List list = new Vector(); - getItemListHelper(fTree.getItems(), list); - return list; - } - - protected void getItemListHelper(TreeItem[] items, List list) { - for (int i = 0; i < items.length; i++) { - TreeItem item = items[i]; - list.add(item); - getItemListHelper(item.getItems(), list); - } - } - - protected TreeItem getTreeItemOnRow(int px, int py) { - TreeItem result = null; - List list = getItemList(); - for (Iterator i = list.iterator(); i.hasNext();) { - TreeItem item = (TreeItem) i.next(); - Rectangle r = item.getBounds(); - if ((r != null) && (px >= r.x) && (py >= r.y) && (py <= r.y + r.height)) { - result = item; - } - } - return result; - } - - protected class InternalMouseListener extends MouseAdapter implements MouseMoveListener { - protected int columnDragged = -1; - protected boolean isDown = false; - protected int prevX = -1; - protected Cursor cursor = null; - - public void mouseMove(MouseEvent e) { - if ((e.x > columnPosition - columnHitWidth) && (e.x < columnPosition + columnHitWidth)) { - if (cursor == null) { - cursor = new Cursor(fTree.getDisplay(), SWT.CURSOR_SIZEWE); - fTree.setCursor(cursor); - } - } - else { - if (cursor != null) { - fTree.setCursor(null); - cursor.dispose(); - cursor = null; - } - } - - if (columnDragged != -1) { - // using the delay timer will make redraws less flickery - if (e.x > 20) { - columnPosition = e.x; - delayedDrawTimer.reset(20); - } - } - } - - public void mouseDown(MouseEvent e) { - // here we handle the column resizing by detect if the user has - // click on a column separator - // - columnDragged = -1; - editManager.deactivateCellEditor(); - - if ((e.x > columnPosition - columnHitWidth) && (e.x < columnPosition + columnHitWidth)) { - columnDragged = 0; - } - - // here we handle selecting tree items when any thing on the 'row' - // is clicked - // - TreeItem item = fTree.getItem(new Point(e.x, e.y)); - if (item == null) { - item = getTreeItemOnRow(e.x, e.y); - if (item != null) { - TreeItem[] items = new TreeItem[1]; - items[0] = item; - fTree.setSelection(items); - } - } - } - - public void mouseUp(MouseEvent e) { - columnDragged = -1; - } - } - - public String[] getColumnProperties() { - return fColumnProperties; - } - - public void setColumnProperties(String[] columnProperties) { - this.fColumnProperties = columnProperties; - } - - public void paintControl(PaintEvent event) { - GC gc = event.gc; - Rectangle treeBounds = fTree.getBounds(); - - controlWidth = treeBounds.width; - Color bg = fTree.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND); - Color bg2 = fTree.getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION); - - gc.setBackground(bg2); - - // // This next part causes problems on LINUX, so let's not do it - // there - // if (B2BHacks.IS_UNIX == false) { - // TreeItem[] selectedItems = tree.getSelection(); - // if (selectedItems.length > 0) { - // for (int i = 0; i < selectedItems.length; i++) { - // TreeItem item = selectedItems[i]; - // Rectangle bounds = item.getBounds(); - // if (bounds != null) { - // gc.fillRectangle(bounds.x + bounds.width, bounds.y, controlWidth, - // bounds.height); - // } - // } - // } - // } - // - if (!fisUnsupportedInput) { - TreeItem[] items = fTree.getItems(); - if (items.length > 0) { - gc.setForeground(tableLineColor); - gc.setBackground(bg); - - gc.fillRectangle(columnPosition, treeBounds.x, treeBounds.width, treeBounds.height); - - Rectangle itemBounds = items[0].getBounds(); - int height = computeTreeItemHeight(); - - if (itemBounds != null) { - /* - * Bounds will be for the first item, which will either be - * visible at the top of the Tree, or scrolled off with - * negative values - */ - int startY = itemBounds.y; - - /* Only draw lines within the Tree boundaries */ - for (int i = startY; i < treeBounds.height; i += height) { - if (i >= treeBounds.y) { - gc.drawLine(0, i, treeBounds.width, i); - } - } - } - gc.drawLine(columnPosition, 0, columnPosition, treeBounds.height); - paintItems(gc, items, treeBounds); - - } - else { - addEmptyTreeMessage(gc); - } - } - else { - addUnableToPopulateTreeMessage(gc); - } - } - - protected int computeTreeItemHeight() { - int result = -1; - - /* - * On GTK tree.getItemHeight() seems to lie to us. It reports that the - * tree item occupies a few pixles less vertical space than it should - * (possibly because of the image height vs. the text height?). This - * foils our code that draws the 'row' lines since we assume that - * lines should be drawn at 'itemHeight' increments. Don't trust - * getItemHeight() to compute the increment... instead compute the - * value based on distance between two TreeItems, and then use the - * larger value. - * - * This strategy only works on trees where the items are of even - * height, however bug - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=117201 indicates that - * this is no longer promised, at least on win32 and likely on other - * platforms soon. - */ - if (fTree.getItemCount() > 0) { - TreeItem[] items = fTree.getItems(); - Rectangle itemBounds = items[0].getBounds(); - - if (items[0].getExpanded()) { - TreeItem[] children = items[0].getItems(); - if (children.length > 0) { - result = children[0].getBounds().y - itemBounds.y; - } - } - else if (items.length > 1) { - result = items[1].getBounds().y - itemBounds.y; - } - } - - result = Math.max(fTree.getItemHeight(), result); - return result; - } - - protected void addEmptyTreeMessage(GC gc) { - // nothing to add here - } - - private void addUnableToPopulateTreeMessage(GC gc) { - // here we print a message when the document cannot be displayed just - // to give the - // user a visual cue - // so that they know how to proceed to edit the blank view - gc.setForeground(fTree.getDisplay().getSystemColor(SWT.COLOR_BLACK)); - gc.setBackground(fTree.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); - gc.drawString(XMLEditorMessages.TreeExtension_0, 10, 10); - } - - void setIsUnsupportedInput(boolean isUnsupported) { - fisUnsupportedInput = isUnsupported; - } - - public void paintItems(GC gc, TreeItem[] items, Rectangle treeBounds) { - if (items != null) { - for (int i = 0; i < items.length; i++) { - TreeItem item = items[i]; - if (item != null) { - Rectangle bounds = item.getBounds(); - if (bounds != null) { - if (treeBounds.intersects(bounds)) { - paintItem(gc, item, bounds); - } - } - - // defect 241039 - // - if (item.getExpanded()) { - paintItems(gc, item.getItems(), treeBounds); - } - } - } - } - } - - protected void paintItem(GC gc, TreeItem item, Rectangle bounds) { - // nothing to paint - } - - public interface ICellEditorProvider { - CellEditor getCellEditor(Object o, int col); - } - - /** - * This class is used to improve drawing during a column resize. - */ - public class DelayedDrawTimer implements Runnable { - protected Control control; - - public DelayedDrawTimer(Control control1) { - this.control = control1; - } - - public void reset(int milliseconds) { - getDisplay().timerExec(milliseconds, this); - } - - public void run() { - control.redraw(); - } - } - - Display getDisplay() { - - return PlatformUI.getWorkbench().getDisplay(); - } - - /** - * EditManager - */ - public class EditManager { - protected Tree fTree1; - protected Control cellEditorHolder; - protected CellEditorState cellEditorState; - - public EditManager(Tree tree) { - this.fTree1 = tree; - this.cellEditorHolder = new Composite(tree, SWT.NONE); - - final Tree theTree = tree; - - MouseAdapter theMouseAdapter = new MouseAdapter() { - public void mouseDown(MouseEvent e) { - deactivateCellEditor(); - - if (e.x > columnPosition + columnHitWidth) { - TreeItem[] items = theTree.getSelection(); - // No edit if more than one row is selected. - if (items.length == 1) { - Rectangle bounds = items[0].getBounds(); - if ((bounds != null) && (e.y >= bounds.y) && (e.y <= bounds.y + bounds.height)) { - int columnToEdit = 1; - activateCellEditor(items[0], columnToEdit); - } - } - } - } - }; - - SelectionListener selectionListener = new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - applyCellEditorValue(); - } - - public void widgetSelected(SelectionEvent e) { - applyCellEditorValue(); - } - }; - - KeyListener keyListener = new KeyAdapter() { - public void keyPressed(KeyEvent e) { - if (e.character == SWT.CR) { - deactivateCellEditor(); - TreeItem[] items = theTree.getSelection(); - if (items.length == 1) { - activateCellEditor(items[0], 1); - } - } - } - }; - - tree.addMouseListener(theMouseAdapter); - tree.addKeyListener(keyListener); - ScrollBar hBar = tree.getHorizontalBar(); - if (hBar != null) { - hBar.addSelectionListener(selectionListener); - } - ScrollBar vBar = tree.getVerticalBar(); - if (vBar != null) { - vBar.addSelectionListener(selectionListener); - } - } - - public boolean isCellEditorActive() { - return cellEditorState != null; - } - - public void applyCellEditorValue() { - if ((cellEditorState != null) && (cellModifier != null)) { - TreeItem treeItem = cellEditorState.fTreeItem; - - // The area below the cell editor needs to be explicity - // repainted on Linux - // - // Rectangle r = B2BHacks.IS_UNIX ? treeItem.getBounds() : - // null; - - Object value = cellEditorState.fCellEditor.getValue(); - String property = cellEditorState.fProperty; - - deactivateCellEditor(); - - cellModifier.modify(treeItem, property, value); - - // if (r != null) { - // tree.redraw(r.x, r.y, tree.getBounds().width, r.height, - // false); - // } - } - } - - public void deactivateCellEditor() { - // Clean up any previous editor control - if (cellEditorState != null) { - cellEditorState.deactivate(); - cellEditorState = null; - } - } - - public void activateCellEditor(TreeItem treeItem, int column) { - if (cellModifier instanceof ICellEditorProvider) { - ICellEditorProvider cellEditorProvider = (ICellEditorProvider) cellModifier; - Object data = treeItem.getData(); - if (fColumnProperties.length > column) { - String property = fColumnProperties[column]; - if (cellModifier.canModify(data, property)) { - CellEditor newCellEditor = cellEditorProvider.getCellEditor(data, column); - if (newCellEditor != null) { - // The control that will be the editor must be a - // child of the columnPosition - Control control = newCellEditor.getControl(); - if (control != null) { - cellEditorState = new CellEditorState(newCellEditor, control, treeItem, column, property); - cellEditorState.activate(); - } - } - } - } - } - } - - /** - * this class holds the state that is need on a per cell editor - * invocation basis - */ - public class CellEditorState implements ICellEditorListener, FocusListener { - public CellEditor fCellEditor; - public Control fControl; - public TreeItem fTreeItem; - public int fColumnNumber; - public String fProperty; - - public CellEditorState(CellEditor cellEditor, Control control, TreeItem treeItem, int columnNumber, String property) { - this.fCellEditor = cellEditor; - this.fControl = control; - this.fTreeItem = treeItem; - this.fColumnNumber = columnNumber; - this.fProperty = property; - } - - public void activate() { - Object element = fTreeItem.getData(); - String value = cellModifier.getValue(element, fProperty).toString(); - if (fControl instanceof Text) { - Text text = (Text) fControl; - int requiredSize = value.length() + 100; - if (text.getTextLimit() < requiredSize) { - text.setTextLimit(requiredSize); - } - } - Rectangle r = fTreeItem.getBounds(); - if (r != null) { - fControl.setBounds(columnPosition + 5, r.y + 1, fTree1.getClientArea().width - (columnPosition + 5), r.height - 1); - fControl.setVisible(true); - fCellEditor.setValue(value); - fCellEditor.addListener(this); - fCellEditor.setFocus(); - fControl.addFocusListener(this); - } - } - - public void deactivate() { - fCellEditor.removeListener(this); - fControl.removeFocusListener(this); - fCellEditor.deactivate(); - fTree1.forceFocus(); - } - - // ICellEditorListener methods - // - public void applyEditorValue() { - applyCellEditorValue(); - } - - public void cancelEditor() { - deactivateCellEditor(); - } - - public void editorValueChanged(boolean oldValidState, boolean newValidState) { - // nothing, for now - } - - // FocusListener methods - // - public void focusGained(FocusEvent e) { - // do nothing - } - - public void focusLost(FocusEvent e) { - applyCellEditorValue(); - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/ViewerExpandCollapseAction.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/ViewerExpandCollapseAction.java deleted file mode 100644 index 02fd23cb5f..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/ViewerExpandCollapseAction.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 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.wst.xml.ui.internal.tabletree; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.AbstractTreeViewer; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; - -public class ViewerExpandCollapseAction extends Action { - - protected boolean isExpandAction; - protected AbstractTreeViewer viewer = null; - - public ViewerExpandCollapseAction(boolean isExpandAction) { - this.isExpandAction = isExpandAction; - if (isExpandAction) { - ImageDescriptor e_imageDescriptor = XMLEditorPluginImageHelper.getInstance().getImageDescriptor(XMLEditorPluginImages.IMG_ETOOL_EXPANDALL); - ImageDescriptor d_imageDescriptor = XMLEditorPluginImageHelper.getInstance().getImageDescriptor(XMLEditorPluginImages.IMG_DTOOL_EXPANDALL); - - setImageDescriptor(e_imageDescriptor); - setDisabledImageDescriptor(d_imageDescriptor); - setToolTipText(XMLUIMessages._UI_INFO_EXPAND_ALL); - } - else { - ImageDescriptor e_imageDescriptor = XMLEditorPluginImageHelper.getInstance().getImageDescriptor(XMLEditorPluginImages.IMG_ETOOL_COLLAPSEALL); - ImageDescriptor d_imageDescriptor = XMLEditorPluginImageHelper.getInstance().getImageDescriptor(XMLEditorPluginImages.IMG_DTOOL_COLLAPSEALL); - - setImageDescriptor(e_imageDescriptor); - setDisabledImageDescriptor(d_imageDescriptor); - setToolTipText(XMLUIMessages._UI_INFO_COLLAPSE_ALL); - } - } - - public void setViewer(AbstractTreeViewer viewer) { - this.viewer = viewer; - } - - public void run() { - if (viewer != null) { - // temporarily set the visibility to false - // this has a HUGE performance benefit - boolean isVisible = viewer.getControl().getVisible(); - viewer.getControl().setVisible(false); - - if (isExpandAction) { - viewer.expandAll(); - } - else { - viewer.collapseAll(); - } - - // restore the previous visibility state - // - viewer.getControl().setVisible(isVisible); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLEditorActionDefinitionIds.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLEditorActionDefinitionIds.java deleted file mode 100644 index 1d380cfb8b..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLEditorActionDefinitionIds.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 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.wst.xml.ui.internal.tabletree; - - - -/** - * Defines the definitions ids for the XML editor actions. - * - * @deprecated Use org.eclipse.wst.sse.ui.edit.util.ActionDefinitionIds - * instead - */ -public interface XMLEditorActionDefinitionIds { - public final static String CLEANUP_DOCUMENT = "org.eclipse.wst.sse.ui.edit.ui.cleanup.document";//$NON-NLS-1$ - public final static String FORMAT_DOCUMENT = "org.eclipse.wst.sse.ui.edit.ui.format.document";//$NON-NLS-1$ - public final static String FORMAT_ACTIVE_ELEMENTS = "org.eclipse.wst.sse.ui.edit.ui.format.active.elements";//$NON-NLS-1$ - public final static String OPEN_FILE = "org.eclipse.wst.sse.ui.edit.ui.open.file.from.source";//$NON-NLS-1$ - // public final static String INFORMATION = - // "org.eclipse.wst.sse.ui.edit.ui.show.tooltip.information";//$NON-NLS-1$ - public final static String INFORMATION = "org.eclipse.jdt.ui.edit.text.java.show.javadoc";//$NON-NLS-1$ - public final static String ADD_BREAKPOINTS = "org.eclipse.wst.sse.ui.edit.ui.add.breakpoints";//$NON-NLS-1$ - public final static String MANAGE_BREAKPOINTS = "org.eclipse.wst.sse.ui.edit.ui.manage.breakpoints";//$NON-NLS-1$ - public final static String ENABLE_BREAKPOINTS = "org.eclipse.wst.sse.ui.edit.ui.enable.breakpoints";//$NON-NLS-1$ - public final static String DISABLE_BREAKPOINTS = "org.eclipse.wst.sse.ui.edit.ui.disable.breakpoints";//$NON-NLS-1$ -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLEditorMessages.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLEditorMessages.java deleted file mode 100644 index c0471bf318..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLEditorMessages.java +++ /dev/null @@ -1,51 +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 - Initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.tabletree; - -import org.eclipse.osgi.util.NLS; - -/** - * Strings used by XML Editor - * - * @plannedfor 1.0 - */ -public class XMLEditorMessages extends NLS { - private static final String BUNDLE_NAME = "org.eclipse.wst.xml.ui.internal.tabletree.XMLEditorResources";//$NON-NLS-1$ - - public static String XMLTableTreeViewer_0; - public static String XMLMultiPageEditorPart_0; - public static String XMLTreeExtension_0; - public static String XMLTreeExtension_1; - public static String XMLTreeExtension_3; - public static String XMLTreeExtension_4; - public static String XMLTableTreeActionBarContributor_0; - public static String XMLTableTreeActionBarContributor_1; - public static String XMLTableTreeActionBarContributor_2; - public static String XMLTableTreeActionBarContributor_3; - public static String XMLTableTreeActionBarContributor_4; - public static String XMLTableTreeActionBarContributor_5; - public static String XMLTableTreeActionBarContributor_6; - public static String XMLTableTreeActionBarContributor_7; - public static String XMLTableTreeActionBarContributor_8; - public static String An_error_has_occurred_when1_ERROR_; - public static String Resource__does_not_exist; - public static String Editor_could_not_be_open; - public static String TreeExtension_0; - - static { - // load message values from bundle file - NLS.initializeMessages(BUNDLE_NAME, XMLEditorMessages.class); - } - - private XMLEditorMessages() { - // cannot create new instance - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLEditorPluginHOLD_OLD.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLEditorPluginHOLD_OLD.java deleted file mode 100644 index fd3acc0163..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLEditorPluginHOLD_OLD.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 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.wst.xml.ui.internal.tabletree; - - - -import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.eclipse.wst.sse.ui.internal.provisional.registry.AdapterFactoryRegistry; -import org.eclipse.wst.sse.ui.internal.provisional.registry.AdapterFactoryRegistryImpl; - -/** - * @deprecated This plugin has combined with the org.eclipse.wst.xml.ui - * plugin. Use XMLUIPlugin instead. - */ -public class XMLEditorPluginHOLD_OLD extends AbstractUIPlugin { - - public final static String PLUGIN_ID = "org.eclipse.wst.xml.ui.internal.XMLEditorPluginHOLD_OLD"; //$NON-NLS-1$ - protected static XMLEditorPluginHOLD_OLD instance = null; - - /** - * XMLUIPlugin constructor comment. - */ - public XMLEditorPluginHOLD_OLD() { - super(); - instance = this; - - // reference the preference store so - // initializeDefaultPreferences(IPreferenceStore preferenceStore) is - // called - getPreferenceStore(); - } - - public static XMLEditorPluginHOLD_OLD getDefault() { - return instance; - } - - public synchronized static XMLEditorPluginHOLD_OLD getInstance() { - return instance; - } - - public AdapterFactoryRegistry getAdapterFactoryRegistry() { - return AdapterFactoryRegistryImpl.getInstance(); - - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLEditorPluginImageHelper.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLEditorPluginImageHelper.java deleted file mode 100644 index b0d11df890..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLEditorPluginImageHelper.java +++ /dev/null @@ -1,157 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 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.wst.xml.ui.internal.tabletree; - -import java.util.HashMap; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.resource.ImageRegistry; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.swt.graphics.Image; -import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; - -/** - * Helper class to handle images provided by this plug-in. - * - * NOTE: For internal use only. For images used externally, please use the - * Shared***ImageHelper class instead. - * - * @author amywu - */ -public class XMLEditorPluginImageHelper { - private final String PLUGINID = XMLUIPlugin.ID; - private static XMLEditorPluginImageHelper instance = null; - - // save a descriptor for each image - private HashMap fImageDescRegistry = null; - - /** - * Gets the instance. - * - * @return Returns a XMLEditorPluginImageHelper - */ - public synchronized static XMLEditorPluginImageHelper getInstance() { - if (instance == null) { - instance = new XMLEditorPluginImageHelper(); - } - return instance; - } - - /** - * Retrieves the image associated with resource from the image registry. - * If the image cannot be retrieved, attempt to find and load the image at - * the location specified in resource. - * - * @param resource - * the image to retrieve - * @return Image the image associated with resource or null if one could - * not be found - */ - public Image getImage(String resource) { - Image image = getImageRegistry().get(resource); - if (image == null) { - // create an image - image = createImage(resource); - } - return image; - } - - /** - * Retrieves the image descriptor associated with resource from the image - * descriptor registry. If the image descriptor cannot be retrieved, - * attempt to find and load the image descriptor at the location specified - * in resource. - * - * @param resource - * the image descriptor to retrieve - * @return ImageDescriptor the image descriptor assocated with resource or - * the default "missing" image descriptor if one could not be - * found - */ - public ImageDescriptor getImageDescriptor(String resource) { - ImageDescriptor imageDescriptor = null; - Object o = getImageDescriptorRegistry().get(resource); - if (o == null) { - // create a descriptor - imageDescriptor = createImageDescriptor(resource); - } - else { - imageDescriptor = (ImageDescriptor) o; - } - return imageDescriptor; - } - - /** - * Returns the image descriptor registry for this plugin. - * - * @return HashMap - image descriptor registry for this plugin - */ - private HashMap getImageDescriptorRegistry() { - if (fImageDescRegistry == null) { - fImageDescRegistry = new HashMap(); - } - return fImageDescRegistry; - } - - /** - * Returns the image registry for this plugin. - * - * @return ImageRegistry - image registry for this plugin - */ - private ImageRegistry getImageRegistry() { - return JFaceResources.getImageRegistry(); - } - - /** - * Creates an image from the given resource and adds the image to the - * image registry. - * - * @param resource - * @return Image - */ - private Image createImage(String resource) { - ImageDescriptor desc = getImageDescriptor(resource); - Image image = null; - - if (desc != null) { - image = desc.createImage(); - // dont add the missing image descriptor image to the image - // registry - if (!desc.equals(ImageDescriptor.getMissingImageDescriptor())) { - getImageRegistry().put(resource, image); - } - } - return image; - } - - /** - * Creates an image descriptor from the given imageFilePath and adds the - * image descriptor to the image descriptor registry. If an image - * descriptor could not be created, the default "missing" image descriptor - * is returned but not added to the image descriptor registry. - * - * @param imageFilePath - * @return ImageDescriptor image descriptor for imageFilePath or default - * "missing" image descriptor if resource could not be found - */ - private ImageDescriptor createImageDescriptor(String imageFilePath) { - ImageDescriptor imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(PLUGINID, imageFilePath); - if (imageDescriptor != null) { - getImageDescriptorRegistry().put(imageFilePath, imageDescriptor); - } - else { - imageDescriptor = ImageDescriptor.getMissingImageDescriptor(); - } - - return imageDescriptor; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLEditorPluginImages.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLEditorPluginImages.java deleted file mode 100644 index a35f00f4cc..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLEditorPluginImages.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 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.wst.xml.ui.internal.tabletree; - -/** - * Bundle of most images used by the XML Editor plug-in. - */ -public class XMLEditorPluginImages { - public static final String IMG_DTOOL_COLLAPSE = "icons/full/dtool16/collapse.gif"; //$NON-NLS-1$ - public static final String IMG_ETOOL_COLLAPSE = "icons/full/etool16/collapse.gif"; //$NON-NLS-1$ - public static final String IMG_DTOOL_COLLAPSEALL = "icons/full/dtool16/collapse_all.gif"; //$NON-NLS-1$ - public static final String IMG_ETOOL_COLLAPSEALL = "icons/full/etool16/collapse_all.gif"; //$NON-NLS-1$ - public static final String IMG_DTOOL_EXPAND = "icons/full/dtool16/expand.gif"; //$NON-NLS-1$ - public static final String IMG_ETOOL_EXPAND = "icons/full/etool16/expand.gif"; //$NON-NLS-1$ - public static final String IMG_DTOOL_EXPANDALL = "icons/full/dtool16/expand_all.gif"; //$NON-NLS-1$ - public static final String IMG_ETOOL_EXPANDALL = "icons/full/etool16/expand_all.gif"; //$NON-NLS-1$ - public static final String IMG_DTOOL_NEW_XML = "icons/full/dtool16/new_xml.gif"; //$NON-NLS-1$ - public static final String IMG_ETOOL_NEW_XML = "icons/full/etool16/new_xml.gif"; //$NON-NLS-1$ -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLEditorResources.properties b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLEditorResources.properties deleted file mode 100644 index 2fc1735baf..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLEditorResources.properties +++ /dev/null @@ -1,30 +0,0 @@ -############################################################################### -# Copyright (c) 2004, 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 -############################################################################### -XMLTableTreeViewer_0=Design -XMLMultiPageEditorPart_0=Source -XMLTreeExtension_0=Structure -XMLTreeExtension_1=Value -XMLTreeExtension_3=The document is empty. -XMLTreeExtension_4=Right mouse click here to insert content. -XMLTableTreeActionBarContributor_0=&XML -XMLTableTreeActionBarContributor_1=&Expand All -XMLTableTreeActionBarContributor_2=&Collapse All -XMLTableTreeActionBarContributor_3=Turn Grammar Constraints Off -XMLTableTreeActionBarContributor_4=&Turn Grammar Constraints Off -XMLTableTreeActionBarContributor_5=Turn Grammar Constraints On -XMLTableTreeActionBarContributor_6=&Turn Grammar Constraints On -XMLTableTreeActionBarContributor_7=Reload Dependencies -XMLTableTreeActionBarContributor_8=&Reload Dependencies -## -An_error_has_occurred_when1_ERROR_=An error has occurred when initializing the input for the the editor's source page. -Resource__does_not_exist=Resource {0} does not exist. -Editor_could_not_be_open=Editor could not be open on {0} -TreeExtension_0=Cannot display document contents. diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLMultiPageEditorActionBarContributor.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLMultiPageEditorActionBarContributor.java deleted file mode 100644 index 7d4ee4b629..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLMultiPageEditorActionBarContributor.java +++ /dev/null @@ -1,93 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 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.wst.xml.ui.internal.tabletree; - - - -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IEditorPart; -import org.eclipse.wst.sse.ui.internal.ISourceViewerActionBarContributor; - - -public class XMLMultiPageEditorActionBarContributor extends SourceEditorActionBarContributor { - - private boolean needsMultiInit = true; - - public XMLMultiPageEditorActionBarContributor() { - super(); - } - - protected void initDesignViewerActionBarContributor(IActionBars actionBars) { - super.initDesignViewerActionBarContributor(actionBars); - - if (designViewerActionBarContributor != null) { - if (designViewerActionBarContributor instanceof IDesignViewerActionBarContributor) { - ((IDesignViewerActionBarContributor) designViewerActionBarContributor).initViewerSpecificContributions(actionBars); - } - } - } - - protected void activateDesignPage(IEditorPart activeEditor) { - if ((sourceViewerActionContributor != null) && (sourceViewerActionContributor instanceof ISourceViewerActionBarContributor)) { - // if design page is not really an IEditorPart, activeEditor == - // null, so pass in multiPageEditor instead (d282414) - if (activeEditor == null) { - sourceViewerActionContributor.setActiveEditor(multiPageEditor); - } - else { - sourceViewerActionContributor.setActiveEditor(activeEditor); - } - ((ISourceViewerActionBarContributor) sourceViewerActionContributor).setViewerSpecificContributionsEnabled(false); - } - - if ((designViewerActionBarContributor != null) && (designViewerActionBarContributor instanceof IDesignViewerActionBarContributor)) { - designViewerActionBarContributor.setActiveEditor(multiPageEditor); - ((IDesignViewerActionBarContributor) designViewerActionBarContributor).setViewerSpecificContributionsEnabled(true); - } - } - - protected void activateSourcePage(IEditorPart activeEditor) { - if ((designViewerActionBarContributor != null) && (designViewerActionBarContributor instanceof IDesignViewerActionBarContributor)) { - designViewerActionBarContributor.setActiveEditor(multiPageEditor); - ((IDesignViewerActionBarContributor) designViewerActionBarContributor).setViewerSpecificContributionsEnabled(false); - } - - if ((sourceViewerActionContributor != null) && (sourceViewerActionContributor instanceof ISourceViewerActionBarContributor)) { - sourceViewerActionContributor.setActiveEditor(activeEditor); - ((ISourceViewerActionBarContributor) sourceViewerActionContributor).setViewerSpecificContributionsEnabled(true); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.part.EditorActionBarContributor#init(org.eclipse.ui.IActionBars) - */ - public void init(IActionBars actionBars) { - super.init(actionBars); - needsMultiInit = true; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.IEditorActionBarContributor#setActiveEditor(org.eclipse.ui.IEditorPart) - */ - public void setActiveEditor(IEditorPart targetEditor) { - if (needsMultiInit) { - designViewerActionBarContributor = new XMLTableTreeActionBarContributor(); - initDesignViewerActionBarContributor(getActionBars()); - needsMultiInit = false; - } - super.setActiveEditor(targetEditor); - } - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLMultiPageEditorPart.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLMultiPageEditorPart.java deleted file mode 100644 index 0cb4194e7f..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLMultiPageEditorPart.java +++ /dev/null @@ -1,938 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2004, 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.wst.xml.ui.internal.tabletree; - -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExecutableExtension; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.action.IStatusLineManager; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextInputListener; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.IPostSelectionProvider; -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.swt.SWT; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.ui.IEditorActionBarContributor; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IEditorSite; -import org.eclipse.ui.IPartListener; -import org.eclipse.ui.IPartService; -import org.eclipse.ui.IPropertyListener; -import org.eclipse.ui.IWindowListener; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.ide.IDE; -import org.eclipse.ui.ide.IGotoMarker; -import org.eclipse.ui.part.MultiPageEditorActionBarContributor; -import org.eclipse.ui.part.MultiPageEditorPart; -import org.eclipse.ui.part.MultiPageEditorSite; -import org.eclipse.ui.part.MultiPageSelectionProvider; -import org.eclipse.ui.progress.UIJob; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.sse.ui.StructuredTextEditor; -import org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapter; -import org.eclipse.wst.xml.core.internal.provisional.IXMLPreferenceNames; -import org.eclipse.wst.xml.core.internal.provisional.contenttype.ContentTypeIdForXML; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.internal.contentoutline.JFaceNodeLabelProvider; -import org.w3c.dom.Attr; -import org.w3c.dom.Node; - -public class XMLMultiPageEditorPart extends MultiPageEditorPart { - - /** - * Internal part activation listener, copied from AbstractTextEditor - */ - class ActivationListener implements IPartListener, IWindowListener { - - /** Cache of the active workbench part. */ - private IWorkbenchPart fActivePart; - /** Indicates whether activation handling is currently be done. */ - private boolean fIsHandlingActivation = false; - /** - * The part service. - * - * @since 3.1 - */ - private IPartService fPartService; - - /** - * Creates this activation listener. - * - * @param partService - * the part service on which to add the part listener - * @since 3.1 - */ - public ActivationListener(IPartService partService) { - fPartService = partService; - fPartService.addPartListener(this); - PlatformUI.getWorkbench().addWindowListener(this); - } - - /** - * Disposes this activation listener. - * - * @since 3.1 - */ - public void dispose() { - fPartService.removePartListener(this); - PlatformUI.getWorkbench().removeWindowListener(this); - fPartService = null; - } - - /* - * @see IPartListener#partActivated(org.eclipse.ui.IWorkbenchPart) - */ - public void partActivated(IWorkbenchPart part) { - fActivePart = part; - handleActivation(); - } - - /* - * @see IPartListener#partBroughtToTop(org.eclipse.ui.IWorkbenchPart) - */ - public void partBroughtToTop(IWorkbenchPart part) { - // do nothing - } - - /* - * @see IPartListener#partClosed(org.eclipse.ui.IWorkbenchPart) - */ - public void partClosed(IWorkbenchPart part) { - // do nothing - } - - /* - * @see IPartListener#partDeactivated(org.eclipse.ui.IWorkbenchPart) - */ - public void partDeactivated(IWorkbenchPart part) { - fActivePart = null; - } - - /* - * @see IPartListener#partOpened(org.eclipse.ui.IWorkbenchPart) - */ - public void partOpened(IWorkbenchPart part) { - // do nothing - } - - /** - * Handles the activation triggering a element state check in the - * editor. - */ - void handleActivation() { - if (fIsHandlingActivation || (getTextEditor() == null)) { - return; - } - - if (fActivePart == XMLMultiPageEditorPart.this) { - fIsHandlingActivation = true; - try { - getTextEditor().safelySanityCheckState(getEditorInput()); - } - finally { - fIsHandlingActivation = false; - } - } - } - - /* - * @see org.eclipse.ui.IWindowListener#windowActivated(org.eclipse.ui.IWorkbenchWindow) - * @since 3.1 - */ - public void windowActivated(IWorkbenchWindow window) { - if (window == getEditorSite().getWorkbenchWindow()) { - /* - * Workaround for problem described in - * http://dev.eclipse.org/bugs/show_bug.cgi?id=11731 Will be - * removed when SWT has solved the problem. - */ - window.getShell().getDisplay().asyncExec(new Runnable() { - public void run() { - handleActivation(); - } - }); - } - } - - /* - * @see org.eclipse.ui.IWindowListener#windowDeactivated(org.eclipse.ui.IWorkbenchWindow) - * @since 3.1 - */ - public void windowDeactivated(IWorkbenchWindow window) { - // do nothing - } - - /* - * @see org.eclipse.ui.IWindowListener#windowClosed(org.eclipse.ui.IWorkbenchWindow) - * @since 3.1 - */ - public void windowClosed(IWorkbenchWindow window) { - // do nothing - } - - /* - * @see org.eclipse.ui.IWindowListener#windowOpened(org.eclipse.ui.IWorkbenchWindow) - * @since 3.1 - */ - public void windowOpened(IWorkbenchWindow window) { - // do nothing - } - } - - /** - * Listens for selection from the source page, applying it to the design - * viewer. - */ - private class TextEditorPostSelectionAdapter extends UIJob implements ISelectionChangedListener { - boolean forcePostSelection = false; - ISelection selection = null; - - public TextEditorPostSelectionAdapter() { - super(getTitle()); - setUser(true); - } - - public IStatus runInUIThread(IProgressMonitor monitor) { - if (selection != null) { - fDesignViewer.getSelectionProvider().setSelection(selection); - } - return Status.OK_STATUS; - } - - public void selectionChanged(SelectionChangedEvent event) { - if ((fDesignViewer != null) && ((getActivePage() != fDesignPageIndex) || !XMLMultiPageEditorPart.this.equals(getSite().getPage().getActivePart()))) { - if (forcePostSelection) { - selection = event.getSelection(); - schedule(200); - } - else { - fDesignViewer.getSelectionProvider().setSelection(event.getSelection()); - } - } - } - } - - private class PageInitializationData { - IConfigurationElement fElement; - String fPropertyName; - Object fData; - - PageInitializationData(IConfigurationElement cfig, String propertyName, Object data) { - super(); - fElement = cfig; - fPropertyName = propertyName; - fData = data; - } - void sendInitializationData(IExecutableExtension executableExtension) { - try { - executableExtension.setInitializationData(fElement, fPropertyName, fData); - } catch (CoreException e) { - Logger.logException(e); - } - } - } - - /** - * Internal IPropertyListener - */ - class PropertyListener implements IPropertyListener { - public void propertyChanged(Object source, int propId) { - switch (propId) { - // had to implement input changed "listener" so that - // StructuredTextEditor could tell it containing editor that - // the input has change, when a 'resource moved' event is - // found. - case IEditorPart.PROP_INPUT : { - if (source == getTextEditor() && fDesignViewer instanceof XMLTableTreeViewer) { - IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(getDocument()); - try { - if (model instanceof IDOMModel) { - IDOMDocument modelDocument = ((IDOMModel)model).getDocument(); - Object designInput = ((XMLTableTreeViewer)fDesignViewer).getInput(); - if (modelDocument != designInput) - setInput(getTextEditor().getEditorInput()); - } - } finally { - if (model != null) - model.releaseFromRead(); - } - } - } - case IEditorPart.PROP_DIRTY : { - if (source == getTextEditor()) { - if (getTextEditor().getEditorInput() != getEditorInput()) { - setInput(getTextEditor().getEditorInput()); - /* - * title should always change when input changes. - * create runnable for following post call - */ - Runnable runnable = new Runnable() { - public void run() { - _firePropertyChange(IWorkbenchPart.PROP_TITLE); - } - }; - /* - * Update is just to post things on the display - * queue (thread). We have to do this to get the - * dirty property to get updated after other - * things on the queue are executed. - */ - ((Control) getTextEditor().getAdapter(Control.class)).getDisplay().asyncExec(runnable); - } - } - break; - } - case IWorkbenchPart.PROP_TITLE : { - // update the input if the title is changed - if (source == getTextEditor()) { - if (getTextEditor().getEditorInput() != getEditorInput()) { - setInput(getTextEditor().getEditorInput()); - } - } - break; - } - default : { - // propagate changes. Is this needed? Answer: Yes. - if (source == getTextEditor()) { - _firePropertyChange(propId); - } - break; - } - } - - } - } - - class TextInputListener implements ITextInputListener { - public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) { - // do nothing - } - - public void inputDocumentChanged(IDocument oldInput, IDocument newInput) { - if ((fDesignViewer != null) && (newInput != null)) { - fDesignViewer.setDocument(newInput); - } - } - } - - class StatusLineLabelProvider extends JFaceNodeLabelProvider { - public StatusLineLabelProvider() { - } - - public String getText(Object element) { - if (element == null) - return null; - - Node node = (Node) element; - if (node.getNodeType() == Node.ATTRIBUTE_NODE) { - return getText(((Attr) node).getOwnerElement()); - } - - StringBuffer s = new StringBuffer(); - if (node.getNodeType() != Node.DOCUMENT_NODE) { - while (node != null && node instanceof INodeNotifier) { - INodeNotifier notifier = (INodeNotifier) node; - if (node.getNodeType() != Node.DOCUMENT_NODE) { - IJFaceNodeAdapter adapter = (IJFaceNodeAdapter) notifier.getAdapterFor(IJFaceNodeAdapter.class); - if (adapter != null) { - s.insert(0, adapter.getLabelText(node)); - } - } - node = node.getParentNode(); - if (node != null && node.getNodeType() != Node.DOCUMENT_NODE) - s.insert(0, IPath.SEPARATOR); - } - } - return s.toString(); - } - - public Image getImage(Object element) { - if (element == null) - return null; - - Node node = (Node) element; - if (node.getNodeType() == Node.ATTRIBUTE_NODE) { - return getImage(((Attr) node).getOwnerElement()); - } - return super.getImage(element); - } - } - - /** The design page index. */ - private int fDesignPageIndex; - - /** The design viewer */ - IDesignViewer fDesignViewer; - - private ActivationListener fActivationListener; - - IPropertyListener fPropertyListener = null; - - /** The source page index. */ - int fSourcePageIndex; - - /** The text editor. */ - private StructuredTextEditor fTextEditor; - - private TextEditorPostSelectionAdapter fTextEditorSelectionListener; - - private ILabelProvider fStatusLineLabelProvider; - - private PageInitializationData fPageInitializer; - - /** - * StructuredTextMultiPageEditorPart constructor comment. - */ - public XMLMultiPageEditorPart() { - super(); - fStatusLineLabelProvider = new StatusLineLabelProvider(); - } - - /* - * This method is just to make firePropertyChanged accessible from some - * (anonomous) inner classes. - */ - void _firePropertyChange(int property) { - super.firePropertyChange(property); - } - - /** - * Adds the source page of the multi-page editor. - */ - private void addSourcePage() throws PartInitException { - fSourcePageIndex = addPage(fTextEditor, getEditorInput()); - setPageText(fSourcePageIndex, XMLEditorMessages.XMLMultiPageEditorPart_0); - - firePropertyChange(PROP_TITLE); - - // Changes to the Text Viewer's document instance should also - // force an - // input refresh - fTextEditor.getTextViewer().addTextInputListener(new TextInputListener()); - } - - /** - * Connects the design viewer with the viewer selection manager. Should be - * done after createSourcePage() is done because we need to get the - * ViewerSelectionManager from the TextEditor. setModel is also done here - * because getModel() needs to reference the TextEditor. - */ - private void connectDesignPage() { - if (fDesignViewer != null) { - fDesignViewer.setDocument(getDocument()); - } - - /* - * Connect selection from the Design page to the selection provider - * for the XMLMultiPageEditorPart so that selection changes in the - * Design page will propogate across the workbench - */ - if (fDesignViewer.getSelectionProvider() instanceof IPostSelectionProvider) { - ((IPostSelectionProvider) fDesignViewer.getSelectionProvider()).addPostSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - ((MultiPageSelectionProvider) getSite().getSelectionProvider()).firePostSelectionChanged(event); - } - }); - } - fDesignViewer.getSelectionProvider().addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - ((MultiPageSelectionProvider) getSite().getSelectionProvider()).fireSelectionChanged(event); - } - }); - - /* - * Connect selection from the Design page to the selection provider of - * the Source page so that selection in the Design page will drive - * selection in the Source page. Prefer post selection. - */ - if (fDesignViewer.getSelectionProvider() instanceof IPostSelectionProvider) { - ((IPostSelectionProvider) fDesignViewer.getSelectionProvider()).addPostSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(final SelectionChangedEvent event) { - /* - * Only force selection update if source page is not - * active - */ - if (getActivePage() != fSourcePageIndex) { - getTextEditor().getSelectionProvider().setSelection(event.getSelection()); - } - } - }); - } - else { - fDesignViewer.getSelectionProvider().addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - /* - * Only force selection update if source page is not - * active - */ - if (getActivePage() != fSourcePageIndex) { - getTextEditor().getSelectionProvider().setSelection(event.getSelection()); - } - /* Bug 210481 - Removed call to updateStatusLine because this is already - * handled by the selection in the source page */ - } - }); - } - - /* - * Handle double-click in the Design page by selecting the - * corresponding amount of text in the Source page. - */ - fDesignViewer.getControl().addListener(SWT.MouseDoubleClick, new Listener() { - public void handleEvent(Event event) { - ISelection selection = fDesignViewer.getSelectionProvider().getSelection(); - int start = -1; - int length = -1; - if (selection instanceof IStructuredSelection) { - /* - * selection goes from the start of the first object to - * the end of the last - */ - IStructuredSelection structuredSelection = (IStructuredSelection) selection; - Object o = structuredSelection.getFirstElement(); - Object o2 = null; - if (structuredSelection.size() > 1) { - o2 = structuredSelection.toArray()[structuredSelection.size() - 1]; - } - else { - o2 = o; - } - if (o instanceof IndexedRegion) { - start = ((IndexedRegion) o).getStartOffset(); - length = ((IndexedRegion) o2).getEndOffset() - start; - } - else if (o2 instanceof ITextRegion) { - start = ((ITextRegion) o).getStart(); - length = ((ITextRegion) o2).getEnd() - start; - } - } - else if (selection instanceof ITextSelection) { - start = ((ITextSelection) selection).getOffset(); - length = ((ITextSelection) selection).getLength(); - } - if ((start > -1) && (length > -1)) { - getTextEditor().selectAndReveal(start, length); - } - } - }); - - /* - * Connect selection from the Source page to the selection provider of - * the Design page so that selection in the Source page will drive - * selection in the Design page. Prefer post selection. - */ - ISelectionProvider provider = getTextEditor().getSelectionProvider(); - if (fTextEditorSelectionListener == null) { - fTextEditorSelectionListener = new TextEditorPostSelectionAdapter(); - } - if (provider instanceof IPostSelectionProvider) { - fTextEditorSelectionListener.forcePostSelection = false; - ((IPostSelectionProvider) provider).addPostSelectionChangedListener(fTextEditorSelectionListener); - } - else { - fTextEditorSelectionListener.forcePostSelection = true; - provider.addSelectionChangedListener(fTextEditorSelectionListener); - } - } - - /** - * Create and Add the Design Page using a registered factory - * - */ - private void createAndAddDesignPage() { - IDesignViewer designViewer = createDesignPage(); - - fDesignViewer = designViewer; - // note: By adding the design page as a Control instead of an - // IEditorPart, page switches will indicate - // a "null" active editor when the design page is made active - fDesignPageIndex = addPage(designViewer.getControl()); - setPageText(fDesignPageIndex, designViewer.getTitle()); - } - - protected IDesignViewer createDesignPage() { - XMLTableTreeViewer tableTreeViewer = new XMLTableTreeViewer(getContainer()); - // Set the default infopop for XML design viewer. - XMLUIPlugin.getInstance().getWorkbench().getHelpSystem().setHelp(tableTreeViewer.getControl(), XMLTableTreeHelpContextIds.XML_DESIGN_VIEW_HELPID); - return tableTreeViewer; - } - - /** - * Creates the pages of this multi-page editor. - * <p> - * Subclasses of <code>MultiPageEditor</code> must implement this - * method. - * </p> - */ - protected void createPages() { - try { - // source page MUST be created before design page, now - createSourcePage(); - - createAndAddDesignPage(); - addSourcePage(); - connectDesignPage(); - - // set the active editor in the action bar contributor first - // before setactivepage calls action bar contributor's - // setactivepage (bug141013 - remove when bug151488 is fixed) - IEditorActionBarContributor contributor = getEditorSite().getActionBarContributor(); - if (contributor instanceof MultiPageEditorActionBarContributor) { - ((MultiPageEditorActionBarContributor) contributor).setActiveEditor(this); - } - - int activePageIndex = getPreferenceStore().getInt(IXMLPreferenceNames.LAST_ACTIVE_PAGE); - if ((activePageIndex >= 0) && (activePageIndex < getPageCount())) { - setActivePage(activePageIndex); - } - else { - setActivePage(fSourcePageIndex); - } - } - catch (PartInitException e) { - Logger.logException(e); - throw new RuntimeException(e); - } - } - - /** - * @see org.eclipse.ui.part.MultiPageEditorPart#createSite(org.eclipse.ui.IEditorPart) - */ - protected IEditorSite createSite(IEditorPart editor) { - IEditorSite site = null; - if (editor == fTextEditor) { - site = new MultiPageEditorSite(this, editor) { - /** - * @see org.eclipse.ui.part.MultiPageEditorSite#getActionBarContributor() - */ - public IEditorActionBarContributor getActionBarContributor() { - IEditorActionBarContributor contributor = super.getActionBarContributor(); - IEditorActionBarContributor multiContributor = XMLMultiPageEditorPart.this.getEditorSite().getActionBarContributor(); - if (multiContributor instanceof XMLMultiPageEditorActionBarContributor) { - contributor = ((XMLMultiPageEditorActionBarContributor) multiContributor).sourceViewerActionContributor; - } - return contributor; - } - - public String getId() { - // sets this id so nested editor is considered xml source - // page - return ContentTypeIdForXML.ContentTypeID_XML + ".source"; //$NON-NLS-1$; - } - }; - } - else { - site = super.createSite(editor); - } - return site; - } - - /** - * Creates the source page of the multi-page editor. - */ - protected void createSourcePage() throws PartInitException { - fTextEditor = createTextEditor(); - fTextEditor.setEditorPart(this); - - /* - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=134301 - XML editor - * does not remember font settings - * - * @see - * org.eclipse.ui.texteditor.AbstractTextEditor#getSymbolicFontName() - */ - fPageInitializer.sendInitializationData(fTextEditor); - - if (fPropertyListener == null) { - fPropertyListener = new PropertyListener(); - } - fTextEditor.addPropertyListener(fPropertyListener); - } - - /** - * Method createTextEditor. - * - * @return StructuredTextEditor - */ - private StructuredTextEditor createTextEditor() { - return new StructuredTextEditor(); - } - - private void disconnectDesignPage() { - if (fDesignViewer != null) { - fDesignViewer.setDocument(null); - } - } - - public void dispose() { - Logger.trace("Source Editor", "XMLMultiPageEditorPart::dispose entry"); //$NON-NLS-1$ //$NON-NLS-2$ - - disconnectDesignPage(); - - if (fActivationListener != null) { - fActivationListener.dispose(); - fActivationListener = null; - } - - if ((fTextEditor != null) && (fPropertyListener != null)) { - fTextEditor.removePropertyListener(fPropertyListener); - } - - // moved to last when added window ... seems like - // we'd be in danger of losing some data, like site, - // or something. - super.dispose(); - - Logger.trace("Source Editor", "StructuredTextMultiPageEditorPart::dispose exit"); //$NON-NLS-1$ //$NON-NLS-2$ - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor) - */ - public void doSave(IProgressMonitor monitor) { - fTextEditor.doSave(monitor); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.ISaveablePart#doSaveAs() - */ - public void doSaveAs() { - fTextEditor.doSaveAs(); - /* - * Update the design viewer since the editor input would have changed - * to the new file. - */ - if (fDesignViewer != null) { - fDesignViewer.setDocument(getDocument()); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) - */ - public Object getAdapter(Class key) { - Object result = null; - - // we extend superclass, not override it, so allow it first - // chance to satisfy request. - result = super.getAdapter(key); - - if (result == null) { - if (key == IDesignViewer.class) { - result = fDesignViewer; - - } - else if (key.equals(IGotoMarker.class)) { - result = new IGotoMarker() { - public void gotoMarker(IMarker marker) { - XMLMultiPageEditorPart.this.gotoMarker(marker); - } - }; - } - else { - /* - * DMW: I'm bullet-proofing this because its been reported (on - * very early versions) a null pointer sometimes happens here - * on startup, when an editor has been left open when - * workbench shutdown. - */ - if (fTextEditor != null) { - result = fTextEditor.getAdapter(key); - } - } - } - return result; - } - - private IDocument getDocument() { - IDocument document = null; - if (fTextEditor != null) { - document = fTextEditor.getDocumentProvider().getDocument(fTextEditor.getEditorInput()); - } - return document; - } - - private IPreferenceStore getPreferenceStore() { - return XMLUIPlugin.getDefault().getPreferenceStore(); - } - - StructuredTextEditor getTextEditor() { - return fTextEditor; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.IWorkbenchPart#getTitle() - */ - public String getTitle() { - String title = null; - if (getTextEditor() == null) { - if (getEditorInput() != null) { - title = getEditorInput().getName(); - } - } - else { - title = getTextEditor().getTitle(); - } - if (title == null) { - title = getPartName(); - } - return title; - } - - void gotoMarker(IMarker marker) { - setActivePage(fSourcePageIndex); - IDE.gotoMarker(fTextEditor, marker); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.IEditorPart#init(org.eclipse.ui.IEditorSite, - * org.eclipse.ui.IEditorInput) - */ - public void init(IEditorSite site, IEditorInput input) throws PartInitException { - try { - super.init(site, input); - // we want to listen for our own activation - fActivationListener = new ActivationListener(site.getWorkbenchWindow().getPartService()); - } - catch (Exception e) { - Logger.logException("exception initializing " + getClass().getName(), e); //$NON-NLS-1$ - } - setPartName(input.getName()); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.ISaveablePart#isSaveAsAllowed() - */ - public boolean isSaveAsAllowed() { - return (fTextEditor != null) && fTextEditor.isSaveAsAllowed(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.ISaveablePart#isSaveOnCloseNeeded() - */ - public boolean isSaveOnCloseNeeded() { - // overriding super class since it does a lowly isDirty! - if (fTextEditor != null) { - return fTextEditor.isSaveOnCloseNeeded(); - } - return isDirty(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.part.MultiPageEditorPart#pageChange(int) - */ - protected void pageChange(int newPageIndex) { - super.pageChange(newPageIndex); - saveLastActivePageIndex(newPageIndex); - - if (newPageIndex == fDesignPageIndex) { - // design page isn't an IEditorPart, therefore we have to send - // selection changes ourselves - ISelectionProvider selectionProvider = fDesignViewer.getSelectionProvider(); - if (selectionProvider != null) { - SelectionChangedEvent event = new SelectionChangedEvent(selectionProvider, selectionProvider.getSelection()); - ((MultiPageSelectionProvider) getSite().getSelectionProvider()).fireSelectionChanged(event); - ((MultiPageSelectionProvider) getSite().getSelectionProvider()).firePostSelectionChanged(event); - } - } - } - - private void saveLastActivePageIndex(int newPageIndex) { - // save the last active page index to preference manager - getPreferenceStore().setValue(IXMLPreferenceNames.LAST_ACTIVE_PAGE, newPageIndex); - } - - public void setInitializationData(IConfigurationElement cfig, String propertyName, Object data) { - super.setInitializationData(cfig, propertyName, data); - fPageInitializer = new PageInitializationData(cfig, propertyName, data); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.part.EditorPart#setInput(org.eclipse.ui.IEditorInput) - */ - protected void setInput(IEditorInput input) { - /* - * If driven from the Source page, it's "model" may not be up to date - * with (or even exist for) the input just yet. Later notification - * from the TextViewer could set us straight, although it's not - * guaranteed to happen after the model has been created. - */ - super.setInput(input); - if (fDesignViewer != null) { - fDesignViewer.setDocument(getDocument()); - } - setPartName(input.getName()); - } - - void updateStatusLine(ISelection selection) { - IStatusLineManager statusLineManager = getEditorSite().getActionBars().getStatusLineManager(); - if (fStatusLineLabelProvider != null && statusLineManager != null) { - String text = null; - Image image = null; - if (selection instanceof IStructuredSelection && !selection.isEmpty()) { - Object firstElement = ((IStructuredSelection) selection).getFirstElement(); - if (firstElement != null) { - text = fStatusLineLabelProvider.getText(firstElement); - image = fStatusLineLabelProvider.getImage((firstElement)); - } - } - if (image == null) { - statusLineManager.setMessage(text); - } - else { - statusLineManager.setMessage(image, text); - } - } - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeActionBarContributor.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeActionBarContributor.java deleted file mode 100644 index 9da1fef334..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeActionBarContributor.java +++ /dev/null @@ -1,319 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 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 - * David Carver - bug 212330 - migrate to org.eclipse.ui.menus extension point - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.tabletree; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IContributionManager; -import org.eclipse.jface.action.IMenuManager; -//import org.eclipse.jface.action.IToolBarManager; -//import org.eclipse.jface.action.MenuManager; -//import org.eclipse.jface.action.Separator; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IEditorSite; -//import org.eclipse.ui.IWorkbenchActionConstants; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchPartSite; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.ui.texteditor.ITextEditorActionConstants; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.ui.StructuredTextEditor; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl.CMDocumentLoader; -import org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl.InferredGrammarBuildingCMDocumentLoader; -import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; -import org.eclipse.wst.xml.ui.internal.util.SharedXMLEditorPluginImageHelper; -import org.w3c.dom.Document; - -/** - * - */ -public class XMLTableTreeActionBarContributor implements IDesignViewerActionBarContributor { - - protected IEditorPart editorPart; - protected final static String DESIGN_VIEWER_SEPARATOR_1_ID = "sed.tabletree.separator.1"; //$NON-NLS-1$ - protected final static String DESIGN_VIEWER_SEPARATOR_2_ID = "sed.tabletree.separator.2"; //$NON-NLS-1$ - protected final static String VALIDATE_XML_ID = "sed.tabletree.validateXML"; //$NON-NLS-1$ - protected final static String RELOAD_GRAMMAR_ID = "sed.tabletree.reloadGrammar"; //$NON-NLS-1$ - protected final static String TOGGLE_EDIT_MODE_ID = "sed.tabletree.toggleEditMode"; //$NON-NLS-1$ - protected final static String EXPAND_ALL_ID = "sed.tabletree.expandAll"; //$NON-NLS-1$ - protected final static String COLLAPSE_ALL_ID = "sed.tabletree.collapseAll"; //$NON-NLS-1$ - - protected ToggleEditModeAction toggleAction; - protected ReloadGrammarAction reloadGrammarAction; - // protected ValidateXMLAction validateXMLAction; - protected ViewerExpandCollapseAction expandAction; - protected ViewerExpandCollapseAction collapseAction; - protected ViewerExpandCollapseAction xmlMenuExpandAction; - protected ViewerExpandCollapseAction xmlMenuCollapseAction; - - public XMLTableTreeActionBarContributor() { - } - - protected void removeContributions(IContributionManager manager) { -/* try { - doRemove(manager, DESIGN_VIEWER_SEPARATOR_1_ID); - doRemove(manager, DESIGN_VIEWER_SEPARATOR_2_ID); - doRemove(manager, VALIDATE_XML_ID); - doRemove(manager, RELOAD_GRAMMAR_ID); - doRemove(manager, TOGGLE_EDIT_MODE_ID); - doRemove(manager, EXPAND_ALL_ID); - doRemove(manager, COLLAPSE_ALL_ID); - } - catch (Exception e) { - } -*/ - } - - protected void doRemove(IContributionManager manager, String id) { -/* try { - if (manager.find(id) != null) { - manager.remove(id); - } - } - catch (Exception e) { - } -*/ } - - public void init(IActionBars bars, IWorkbenchPage page) { - init(bars); - } - - public void init(IActionBars bars) { -// IToolBarManager tbm = bars.getToolBarManager(); - -/* IMenuManager xmlMenu = bars.getMenuManager().findMenuUsingPath("org.eclipse.core.runtime.xml.design.xmlmenu"); //$NON-NLS-1$ - - if (xmlMenu == null) { - xmlMenu = new MenuManager(XMLEditorMessages.XMLTableTreeActionBarContributor_0, "org.eclipse.core.runtime.xml.design.xmlmenu"); //$NON-NLS-1$ - // For RCP usage - if (bars.getMenuManager().find(IWorkbenchActionConstants.M_WINDOW) != null) { - bars.getMenuManager().insertBefore(IWorkbenchActionConstants.M_WINDOW, xmlMenu); - } - } - else { - removeContributions(xmlMenu); - } - - tbm.add(new Separator("DESIGN_VIEWER_SEPARATOR_1_ID")); //$NON-NLS-1$ -*/ - // ToggleEditModeAction - // -/* toggleAction = new ToggleEditModeAction(); - toggleAction.setId(TOGGLE_EDIT_MODE_ID); - xmlMenu.add(toggleAction); - tbm.add(toggleAction); -*/ - // ReloadGrammarAction - // -/* reloadGrammarAction = new ReloadGrammarAction(); - reloadGrammarAction.setId(RELOAD_GRAMMAR_ID); - tbm.add(reloadGrammarAction); - xmlMenu.add(reloadGrammarAction); - - xmlMenu.add(new Separator()); -*/ - // ExpandCollapseAction - // -/* xmlMenuExpandAction = new ViewerExpandCollapseAction(true); - xmlMenuExpandAction.setId(EXPAND_ALL_ID); - xmlMenuExpandAction.setText(XMLEditorMessages.XMLTableTreeActionBarContributor_1); - xmlMenu.add(xmlMenuExpandAction); - - xmlMenuCollapseAction = new ViewerExpandCollapseAction(false); - xmlMenuCollapseAction.setId(COLLAPSE_ALL_ID); - xmlMenuCollapseAction.setId(EXPAND_ALL_ID); - xmlMenuCollapseAction.setText(XMLEditorMessages.XMLTableTreeActionBarContributor_2); - xmlMenu.add(xmlMenuCollapseAction); -*/ - } - - protected void addActionWithId(IMenuManager menuManager, Action action, String id) { - action.setId(id); - menuManager.add(action); - } - - public void initViewerSpecificContributions(IActionBars bars) { -/* IToolBarManager tbm = bars.getToolBarManager(); - tbm.add(new Separator(DESIGN_VIEWER_SEPARATOR_2_ID)); - - expandAction = new ViewerExpandCollapseAction(true); - expandAction.setId(EXPAND_ALL_ID); - tbm.add(expandAction); - - collapseAction = new ViewerExpandCollapseAction(false); - collapseAction.setId(COLLAPSE_ALL_ID); - tbm.add(collapseAction); -*/ - } - - public void setViewerSpecificContributionsEnabled(boolean enabled) { -/* if (expandAction != null) { - expandAction.setEnabled(enabled); - xmlMenuExpandAction.setEnabled(enabled); - } - - if (collapseAction != null) { - collapseAction.setEnabled(enabled); - xmlMenuCollapseAction.setEnabled(enabled); - } -*/ - } - - public void setActiveEditor(IEditorPart targetEditor) { - editorPart = targetEditor; - -// IStructuredModel model = getModelForEditorPart(targetEditor); -/* reloadGrammarAction.setModel(model); - toggleAction.setModelQuery(ModelQueryUtil.getModelQuery(model)); - - XMLTableTreeViewer tableTreeViewer = getTableTreeViewerForEditorPart(editorPart); - if (tableTreeViewer != null) { - expandAction.setViewer(tableTreeViewer); - collapseAction.setViewer(tableTreeViewer); - - xmlMenuExpandAction.setViewer(tableTreeViewer); - xmlMenuCollapseAction.setViewer(tableTreeViewer); - } -*/ - if (editorPart instanceof XMLMultiPageEditorPart) { - IWorkbenchPartSite site = editorPart.getSite(); - if (site instanceof IEditorSite) { - ITextEditor textEditor = ((XMLMultiPageEditorPart) editorPart).getTextEditor(); - IActionBars actionBars = ((IEditorSite) site).getActionBars(); - actionBars.setGlobalActionHandler(ITextEditorActionConstants.UNDO, getAction(textEditor, ITextEditorActionConstants.UNDO)); - actionBars.setGlobalActionHandler(ITextEditorActionConstants.REDO, getAction(textEditor, ITextEditorActionConstants.REDO)); - } - } - - // TODO... uncomment this and investigate NPE - // - // add the cut/copy/paste for text fields - // ActionHandlerPlugin.connectPart(editorPart); - } - - protected final IAction getAction(ITextEditor editor, String actionId) { - return (editor == null ? null : editor.getAction(actionId)); - } - - protected IStructuredModel getModelForEditorPart(IEditorPart targetEditor) { - IStructuredModel result = null; - if (editorPart instanceof XMLMultiPageEditorPart) { - StructuredTextEditor textEditor = ((XMLMultiPageEditorPart) targetEditor).getTextEditor(); - result = (textEditor != null) ? textEditor.getModel() : null; - } - return result; - } - - protected XMLTableTreeViewer getTableTreeViewerForEditorPart(IEditorPart targetEditor) { - XMLTableTreeViewer result = null; - Object object = targetEditor.getAdapter(IDesignViewer.class); - if (object instanceof XMLTableTreeViewer) { - result = (XMLTableTreeViewer) object; - } - return result; - } - - /** - * - */ - public class ToggleEditModeAction extends Action { - protected ImageDescriptor onImage = SharedXMLEditorPluginImageHelper.getImageDescriptor(SharedXMLEditorPluginImageHelper.IMG_ETOOL_CONSTRAINON); - protected ImageDescriptor offImage = SharedXMLEditorPluginImageHelper.getImageDescriptor(SharedXMLEditorPluginImageHelper.IMG_ETOOL_CONSTRAINOFF); - protected ModelQuery modelQuery; - - public ToggleEditModeAction() { - setAppearanceForEditMode(ModelQuery.EDIT_MODE_CONSTRAINED_STRICT); - } - - public void run() { - if (modelQuery != null) { - int newState = getNextState(modelQuery.getEditMode()); - modelQuery.setEditMode(newState); - setAppearanceForEditMode(newState); - } - } - - public void setModelQuery(ModelQuery newModelQuery) { - modelQuery = newModelQuery; - if (modelQuery != null) { - setAppearanceForEditMode(modelQuery.getEditMode()); - } - } - - public void setAppearanceForEditMode(int editMode) { - if (editMode == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) { - setToolTipText(XMLEditorMessages.XMLTableTreeActionBarContributor_3); - setText(XMLEditorMessages.XMLTableTreeActionBarContributor_4); - setImageDescriptor(onImage); - } - else { - setToolTipText(XMLEditorMessages.XMLTableTreeActionBarContributor_5); - setText(XMLEditorMessages.XMLTableTreeActionBarContributor_6); - setImageDescriptor(offImage); - } - } - - public int getNextState(int editMode) { - int result = -1; - if (editMode == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) { - result = ModelQuery.EDIT_MODE_UNCONSTRAINED; - } - else { - result = ModelQuery.EDIT_MODE_CONSTRAINED_STRICT; - } - return result; - } - } - - /** - * - */ - public class ReloadGrammarAction extends Action { - protected IStructuredModel model; - - public ReloadGrammarAction() { - setDisabledImageDescriptor(SharedXMLEditorPluginImageHelper.getImageDescriptor(SharedXMLEditorPluginImageHelper.IMG_DTOOL_RLDGRMR)); - setImageDescriptor(SharedXMLEditorPluginImageHelper.getImageDescriptor(SharedXMLEditorPluginImageHelper.IMG_ETOOL_RLDGRMR)); - setToolTipText(XMLEditorMessages.XMLTableTreeActionBarContributor_7); - setText(XMLEditorMessages.XMLTableTreeActionBarContributor_8); - } - - public void setModel(IStructuredModel newModel) { - this.model = newModel; - } - - public void run() { - if (model != null) { - ModelQuery modelQuery = ModelQueryUtil.getModelQuery(model); - Document document = ((IDOMModel) model).getDocument(); - if ((modelQuery != null) && (modelQuery.getCMDocumentManager() != null)) { - modelQuery.getCMDocumentManager().getCMDocumentCache().clear(); - // TODO... need to figure out how to access the - // DOMObserver via ModelQuery - // ...why? - CMDocumentLoader loader = new InferredGrammarBuildingCMDocumentLoader(document, modelQuery); - loader.loadCMDocuments(); - } - } - } - } - - /** - * @see org.eclipse.ui.IEditorActionBarContributor#dispose() - */ - public void dispose() { - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeContentProvider.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeContentProvider.java deleted file mode 100644 index c713320815..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeContentProvider.java +++ /dev/null @@ -1,320 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 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.wst.xml.ui.internal.tabletree; - -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ILabelProviderListener; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.StructuredViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.graphics.Image; -import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; -import org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapter; -import org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapterFactory; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManagerListener; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.contentmodel.util.CMDocumentCache; -import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.util.SharedXMLEditorPluginImageHelper; -import org.w3c.dom.Attr; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.ProcessingInstruction; -import org.w3c.dom.Text; - - -public class XMLTableTreeContentProvider implements ITreeContentProvider, ITableLabelProvider, ILabelProvider, CMDocumentManagerListener { - - protected CMDocumentManager documentManager; - - StructuredViewer fViewer = null; - - private TreeContentHelper treeContentHelper = new TreeContentHelper(); - - public XMLTableTreeContentProvider() { - super(); - } - - // - // ILabelProvider stuff - // - public void addListener(ILabelProviderListener listener) { - // since we always return 'false' for "isLabelProperty", - // not need to listen. Maybe that should change some day? - } - - // CMDocumentManagerListener - // - public void cacheCleared(CMDocumentCache cache) { - doDelayedRefreshForViewers(); - } - - public void cacheUpdated(CMDocumentCache cache, final String uri, int oldStatus, int newStatus, CMDocument cmDocument) { - if ((newStatus == CMDocumentCache.STATUS_LOADED) || (newStatus == CMDocumentCache.STATUS_ERROR)) { - doDelayedRefreshForViewers(); - } - } - - public void dispose() { - } - - private void doDelayedRefreshForViewers() { - if ((fViewer != null) && !fViewer.getControl().isDisposed()) { - fViewer.getControl().getDisplay().asyncExec(new Runnable() { - public void run() { - if ((fViewer != null) && !fViewer.getControl().isDisposed()) { - fViewer.refresh(true); - } - } - }); - } - } - - public Object[] getChildren(Object element) { - if (element instanceof INodeNotifier) { - ((INodeNotifier) element).getAdapterFor(IJFaceNodeAdapter.class); - } - return treeContentHelper.getChildren(element); - } - - public Image getColumnImage(Object object, int columnIndex) { - return (columnIndex == 0) ? getImage(object) : null; - } - - // - // ITableLabelProvider stuff - // - public String getColumnText(Object object, int column) { - String result = null; - if (column == 0) { - result = getText(object); - } - else if ((column == 1) && (object instanceof Node)) { - result = treeContentHelper.getNodeValue((Node) object); - } - return result != null ? result : ""; //$NON-NLS-1$ - } - - public Object[] getElements(Object element) { - return getChildren(element); - } - - public Image getImage(Object object) { - if (object instanceof INodeNotifier) { - ((INodeNotifier) object).getAdapterFor(IJFaceNodeAdapter.class); - } - - Image image = null; - if (object instanceof Node) { - Node node = (Node) object; - switch (node.getNodeType()) { - case Node.ATTRIBUTE_NODE : { - image = SharedXMLEditorPluginImageHelper.getImage(SharedXMLEditorPluginImageHelper.IMG_OBJ_ATTRIBUTE); - break; - } - case Node.CDATA_SECTION_NODE : { - image = SharedXMLEditorPluginImageHelper.getImage(SharedXMLEditorPluginImageHelper.IMG_OBJ_CDATASECTION); - break; - } - case Node.COMMENT_NODE : { - image = SharedXMLEditorPluginImageHelper.getImage(SharedXMLEditorPluginImageHelper.IMG_OBJ_COMMENT); - break; - } - case Node.DOCUMENT_TYPE_NODE : { - image = SharedXMLEditorPluginImageHelper.getImage(SharedXMLEditorPluginImageHelper.IMG_OBJ_DOCTYPE); - break; - } - case Node.ELEMENT_NODE : { - image = SharedXMLEditorPluginImageHelper.getImage(SharedXMLEditorPluginImageHelper.IMG_OBJ_ELEMENT); - break; - } - case Node.PROCESSING_INSTRUCTION_NODE : { - image = SharedXMLEditorPluginImageHelper.getImage(SharedXMLEditorPluginImageHelper.IMG_OBJ_PROCESSINGINSTRUCTION); - break; - } - case Node.TEXT_NODE : { - image = SharedXMLEditorPluginImageHelper.getImage(SharedXMLEditorPluginImageHelper.IMG_OBJ_TXTEXT); - break; - } - case Node.ENTITY_REFERENCE_NODE : { - image = SharedXMLEditorPluginImageHelper.getImage(SharedXMLEditorPluginImageHelper.IMG_OBJ_ENTITY_REFERENCE); - break; - } - } - - // if (image != null) { - // Image markerOverlayImage = - // overlayIconManager.getOverlayImageForObject(node); - // if (markerOverlayImage != null) { - // image = imageFactory.createCompositeImage(image, - // markerOverlayImage, ImageFactory.BOTTOM_LEFT); - // } - // } - } - return image; - } - - public Object getParent(Object o) { - if (o instanceof INodeNotifier) { - ((INodeNotifier) o).getAdapterFor(IJFaceNodeAdapter.class); - } - - Object result = null; - if (o instanceof Node) { - Node node = (Node) o; - if (node.getNodeType() == Node.ATTRIBUTE_NODE) { - result = ((Attr) node).getOwnerElement(); - } - else { - result = node.getParentNode(); - } - } - return result; - } - - public Element getRootElement(Document document) { - Element rootElement = null; - - for (Node childNode = document.getFirstChild(); childNode != null; childNode = childNode.getNextSibling()) { - if (childNode.getNodeType() == Node.ELEMENT_NODE) { - rootElement = (Element) childNode; - break; - } - } - return rootElement; - } - - public String getText(Object object) { - if (object instanceof INodeNotifier) { - ((INodeNotifier) object).getAdapterFor(IJFaceNodeAdapter.class); - } - - String result = null; - if (object instanceof Node) { - Node node = (Node) object; - switch (node.getNodeType()) { - case Node.ATTRIBUTE_NODE : { - result = node.getNodeName(); - break; - } - case Node.DOCUMENT_TYPE_NODE : { - result = "DOCTYPE"; //$NON-NLS-1$ - break; - } - case Node.ELEMENT_NODE : { - result = node.getNodeName(); - break; - } - case Node.PROCESSING_INSTRUCTION_NODE : { - result = ((ProcessingInstruction) node).getTarget(); - break; - } - } - } - return result != null ? result : ""; //$NON-NLS-1$ - } - - public boolean hasChildren(Object element) { - return getChildren(element).length > 0; - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - // remove our listeners to the old state - if (oldInput != null) { - Document domDoc = (Document) oldInput; - ModelQuery mq = ModelQueryUtil.getModelQuery(domDoc); - if (mq != null) { - documentManager = mq.getCMDocumentManager(); - if (documentManager != null) { - documentManager.removeListener(this); - } - } - } - - if ((oldInput != null) && (oldInput instanceof IDOMNode)) { - IJFaceNodeAdapterFactory factory = (IJFaceNodeAdapterFactory) ((IDOMNode) oldInput).getModel().getFactoryRegistry().getFactoryFor(IJFaceNodeAdapter.class); - if (factory != null) { - factory.removeListener(viewer); - } - } - - if (viewer instanceof StructuredViewer) { - fViewer = null; - } - else { - fViewer = (StructuredViewer) viewer; - } - - if ((newInput != null) && (newInput instanceof IDOMNode)) { - IJFaceNodeAdapterFactory factory = (IJFaceNodeAdapterFactory) ((IDOMNode) newInput).getModel().getFactoryRegistry().getFactoryFor(IJFaceNodeAdapter.class); - if (factory != null) { - factory.addListener(viewer); - } - } - - if (newInput != null) { - Document domDoc = (Document) newInput; - ModelQuery mq = ModelQueryUtil.getModelQuery(domDoc); - - if (mq != null) { - documentManager = mq.getCMDocumentManager(); - if (documentManager != null) { - documentManager.setPropertyEnabled(CMDocumentManager.PROPERTY_ASYNC_LOAD, true); - documentManager.addListener(this); - } - } - } - } - - public boolean isDeleted(Object element) { - return element != null; - } - - // the following methods handle filtering aspects of the viewer - // - // - public boolean isIgnorableText(Node node) { - boolean result = false; - try { - if (node.getNodeType() == Node.TEXT_NODE) { - String data = ((Text) node).getData(); - result = ((data == null) || (data.trim().length() == 0)); - } - } - catch (Exception e) { - Logger.logException(e); - } - return result; - } - - public boolean isLabelProperty(Object object, String property) { - return false; - } - - public void propertyChanged(CMDocumentManager cmDocumentManager, String propertyName) { - if (cmDocumentManager.getPropertyEnabled(CMDocumentManager.PROPERTY_AUTO_LOAD)) { - doDelayedRefreshForViewers(); - } - } - - public void removeListener(ILabelProviderListener listener) { - // since we always return 'false' for "isLabelProperty", - // not need to listen. Maybe that should change some day? - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeHelpContextIds.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeHelpContextIds.java deleted file mode 100644 index 60bc4df222..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeHelpContextIds.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 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.wst.xml.ui.internal.tabletree; - -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; - - - -/** - * Help context ids for the TableTree view. - * <p> - * This interface contains constants only; it is not intended to be - * implemented or extended. - * </p> - * - */ -public interface XMLTableTreeHelpContextIds { - // org.eclipse.wst.xml.ui. - public static final String PREFIX = XMLUIPlugin.ID + "."; //$NON-NLS-1$ - - // XML Design View - public static final String XML_DESIGN_VIEW_HELPID = PREFIX + "xmlm3000"; //$NON-NLS-1$ -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreePropertyDescriptorFactory.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreePropertyDescriptorFactory.java deleted file mode 100644 index b929b4cf32..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreePropertyDescriptorFactory.java +++ /dev/null @@ -1,118 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 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.wst.xml.ui.internal.tabletree; - -import java.util.List; - -import org.eclipse.ui.views.properties.IPropertyDescriptor; -import org.eclipse.ui.views.properties.TextPropertyDescriptor; -import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.ui.internal.properties.EnumeratedStringPropertyDescriptor; -import org.w3c.dom.Attr; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.Text; - - -public class XMLTableTreePropertyDescriptorFactory extends DOMPropertyDescriptorFactory { - - protected TreeContentHelper treeContentHelper = new TreeContentHelper(); - - public XMLTableTreePropertyDescriptorFactory() { - super(); - } - - protected IPropertyDescriptor createPropertyDescriptorHelper(String name, Element element, CMNode cmNode) { - IPropertyDescriptor result = null; - - ModelQuery mq = ModelQueryUtil.getModelQuery(element.getOwnerDocument()); - String[] valuesArray = null; - if (mq != null) { - valuesArray = mq.getPossibleDataTypeValues(element, cmNode); - } - if ((valuesArray != null) && (valuesArray.length > 0)) { - result = new EnumeratedStringPropertyDescriptor(name, name, valuesArray); - } - else { - result = createDefaultPropertyDescriptor(name); - } - - return result; - } - - public IPropertyDescriptor createTextPropertyDescriptor(Text text) { - IPropertyDescriptor result = null; - Node parentNode = text.getParentNode(); - if ((parentNode != null) && (parentNode.getNodeType() == Node.ELEMENT_NODE)) { - Element parentElement = (Element) parentNode; - ModelQuery mq = ModelQueryUtil.getModelQuery(text.getOwnerDocument()); - CMElementDeclaration ed = null; - if (mq != null) { - ed = mq.getCMElementDeclaration(parentElement); - } - if (ed != null) { - result = createPropertyDescriptorHelper(HACK, parentElement, ed); - } - else { - result = createDefaultPropertyDescriptor(parentElement.getNodeName()); - } - } - - if (result == null) { - result = new TextPropertyDescriptor(HACK, HACK); - } - - return result; - } - - public IPropertyDescriptor createAttributePropertyDescriptor(Attr attr) { - IPropertyDescriptor result = null; - - String attributeName = attr.getName(); - ModelQuery mq = ModelQueryUtil.getModelQuery(attr.getOwnerDocument()); - - CMAttributeDeclaration ad = null; - if (mq != null) { - ad = mq.getCMAttributeDeclaration(attr); - } - if (ad != null) { - result = createPropertyDescriptorHelper(attributeName, attr.getOwnerElement(), ad); - } - - if (result == null) { - result = new TextPropertyDescriptor(attributeName, attributeName); - } - - return result; - } - - public IPropertyDescriptor createElementPropertyDescriptor(Element element) { - IPropertyDescriptor result = null; - List list = treeContentHelper.getElementTextContent(element); - if (list != null) { - Text text = treeContentHelper.getEffectiveTextNodeForCombinedNodeList(list); - if (text != null) { - result = createTextPropertyDescriptor(text); - } - } - - if (result == null) { - result = new TextPropertyDescriptor(HACK, HACK); - } - return result; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeViewer.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeViewer.java deleted file mode 100644 index 331f2d6b4c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeViewer.java +++ /dev/null @@ -1,334 +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 - ****************************************************************************/ -package org.eclipse.wst.xml.ui.internal.tabletree; - -import org.eclipse.jface.action.IMenuListener; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.util.LocalSelectionTransfer; -import org.eclipse.jface.util.SafeRunnable; -import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.IPostSelectionProvider; -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.StructuredSelection; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.dnd.DND; -import org.eclipse.swt.dnd.DragSource; -import org.eclipse.swt.dnd.DragSourceEvent; -import org.eclipse.swt.dnd.DragSourceListener; -import org.eclipse.swt.dnd.DropTarget; -import org.eclipse.swt.dnd.DropTargetEvent; -import org.eclipse.swt.dnd.DropTargetListener; -import org.eclipse.swt.dnd.Transfer; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.TableItem; -import org.eclipse.swt.widgets.TreeItem; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; -import org.eclipse.wst.xml.ui.internal.actions.NodeAction; -import org.eclipse.wst.xml.ui.internal.contentoutline.XMLNodeActionManager; -import org.eclipse.wst.xml.ui.internal.dnd.DragNodeCommand; -import org.w3c.dom.Document; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; - -public class XMLTableTreeViewer extends TreeViewer implements IDesignViewer { - - class NodeActionMenuListener implements IMenuListener { - public void menuAboutToShow(IMenuManager menuManager) { - // used to disable NodeSelection listening while running - // NodeAction - XMLNodeActionManager nodeActionManager = new XMLNodeActionManager(((IDOMDocument) getInput()).getModel(), XMLTableTreeViewer.this) { - public void beginNodeAction(NodeAction action) { - super.beginNodeAction(action); - } - - public void endNodeAction(NodeAction action) { - super.endNodeAction(action); - } - }; - nodeActionManager.fillContextMenu(menuManager, getSelection()); - } - } - - private class SelectionProvider implements IPostSelectionProvider { - - public void addPostSelectionChangedListener(ISelectionChangedListener listener) { - XMLTableTreeViewer.this.addPostSelectionChangedListener(listener); - } - - public void removePostSelectionChangedListener(ISelectionChangedListener listener) { - XMLTableTreeViewer.this.removePostSelectionChangedListener(listener); - } - - public void addSelectionChangedListener(ISelectionChangedListener listener) { - XMLTableTreeViewer.this.addSelectionChangedListener(listener); - } - - public ISelection getSelection() { - return XMLTableTreeViewer.this.getSelection(); - } - - public void removeSelectionChangedListener(ISelectionChangedListener listener) { - XMLTableTreeViewer.this.removeSelectionChangedListener(listener); - } - - public void setSelection(ISelection selection) { - boolean selectionSet = false; - if (!selection.isEmpty() && selection instanceof IStructuredSelection) { - IStructuredSelection structuredSelection = (IStructuredSelection) selection; - if (selection instanceof ITextSelection) { - ITextSelection textSelection = (ITextSelection) selection; - - if (structuredSelection.size() == 1) { - if (structuredSelection.getFirstElement() instanceof IDOMNode) { - IDOMNode domNode = (IDOMNode) structuredSelection.getFirstElement(); - IStructuredDocumentRegion startStructuredDocumentRegion = domNode.getStartStructuredDocumentRegion(); - if (startStructuredDocumentRegion != null) { - ITextRegion matchingRegion = startStructuredDocumentRegion.getRegionAtCharacterOffset(textSelection.getOffset()); - int allowedIterations = 40; - while (matchingRegion != null && !matchingRegion.getType().equals(DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) && allowedIterations > 0) { - matchingRegion = startStructuredDocumentRegion.getRegionAtCharacterOffset(startStructuredDocumentRegion.getStartOffset(matchingRegion) - 1); - allowedIterations--; - } - if (matchingRegion != null && matchingRegion.getType().equals(DOMRegionContext.XML_TAG_ATTRIBUTE_NAME)) { - String attrName = startStructuredDocumentRegion.getText(matchingRegion); - NamedNodeMap attributes = domNode.getAttributes(); - if (attributes != null && attrName.length() > 0) { - Node attr = attributes.getNamedItem(attrName); - if (attr != null) { - selectionSet = true; - XMLTableTreeViewer.this.setSelection(new StructuredSelection(attr)); - } - } - } - } - } - } - } - } - if (!selectionSet) { - XMLTableTreeViewer.this.setSelection(selection); - } - } - } - - protected CellEditor cellEditor; - - protected XMLTreeExtension treeExtension; - - private ISelectionProvider fSelectionProvider = new SelectionProvider(); - - public XMLTableTreeViewer(Composite parent) { - super(parent, SWT.FULL_SELECTION | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); - - // set up providers - this.treeExtension = new XMLTreeExtension(getTree()); - - XMLTableTreeContentProvider provider = new XMLTableTreeContentProvider(); - setContentProvider(provider); - setLabelProvider(provider); - - createContextMenu(); - - DragSource dragSource = new DragSource(getControl(), DND.DROP_COPY | DND.DROP_MOVE); - dragSource.addDragListener(createDragSourceListener()); - dragSource.setTransfer(new Transfer[] {LocalSelectionTransfer.getTransfer()}); - DropTarget dropTarget = new DropTarget(getControl(), DND.DROP_COPY | DND.DROP_MOVE); - dropTarget.addDropListener(createDropTargetListener()); - dropTarget.setTransfer(new Transfer[] {LocalSelectionTransfer.getTransfer()}); - } - - /** - * This creates a context menu for the viewer and adds a listener as well - * registering the menu for extension. - */ - protected void createContextMenu() { - MenuManager contextMenu = new MenuManager("#PopUp"); //$NON-NLS-1$ - contextMenu.add(new Separator("additions")); //$NON-NLS-1$ - contextMenu.setRemoveAllWhenShown(true); - contextMenu.addMenuListener(new NodeActionMenuListener()); - Menu menu = contextMenu.createContextMenu(getControl()); - getControl().setMenu(menu); - } - - private DragSourceListener createDragSourceListener() { - return new DragSourceListener() { - public void dragFinished(DragSourceEvent event) { - LocalSelectionTransfer.getTransfer().setSelection(null); - } - - public void dragSetData(DragSourceEvent event) { - } - - public void dragStart(DragSourceEvent event) { - LocalSelectionTransfer.getTransfer().setSelection(getSelection()); - } - }; - } - - private DropTargetListener createDropTargetListener() { - return new DropTargetListener() { - public void dragEnter(DropTargetEvent event) { - } - - public void dragLeave(DropTargetEvent event) { - } - - public void dragOperationChanged(DropTargetEvent event) { - } - - public void drop(DropTargetEvent event) { - if (event.operations != DND.DROP_NONE && LocalSelectionTransfer.getTransfer().getSelection() instanceof IStructuredSelection) { - dragOver(event); - IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection(); - if (selection != null && !selection.isEmpty() && event.item != null && event.item.getData() != null) { - /* - * the command uses these numbers instead of the - * feedback constants (even though it converts in - * the other direction as well) - */ - float feedbackFloat = getHeightInItem(event); - - final DragNodeCommand command = new DragNodeCommand(event.item.getData(), feedbackFloat, event.operations, event.detail, selection.toList(), XMLTableTreeViewer.this); - if (command != null && command.canExecute()) { - SafeRunnable.run(new SafeRunnable() { - public void run() throws Exception { - command.execute(); - } - }); - } - } - } - } - - public void dropAccept(DropTargetEvent event) { - } - - public void dragOver(DropTargetEvent event) { - event.feedback = DND.FEEDBACK_SELECT; - float feedbackFloat = getHeightInItem(event); - if (feedbackFloat > 0.75) { - event.feedback = DND.FEEDBACK_INSERT_AFTER; - } - else if (feedbackFloat < 0.25) { - event.feedback = DND.FEEDBACK_INSERT_BEFORE; - } - event.feedback |= DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL; - } - - private float getHeightInItem(DropTargetEvent event) { - if(event.item == null) return .5f; - if (event.item instanceof TreeItem) { - TreeItem treeItem = (TreeItem) event.item; - Control control = treeItem.getParent(); - Point point = control.toControl(new Point(event.x, event.y)); - Rectangle bounds = treeItem.getBounds(); - return (float) (point.y - bounds.y) / (float) bounds.height; - } - else if (event.item instanceof TableItem) { - TableItem tableItem = (TableItem) event.item; - Control control = tableItem.getParent(); - Point point = control.toControl(new Point(event.x, event.y)); - Rectangle bounds = tableItem.getBounds(0); - return (float) (point.y - bounds.y) / (float) bounds.height; - } - else { - return 0.0F; - } - } - }; - } - - protected void doRefresh(Object o, boolean fromDelayed) { - treeExtension.resetCachedData(); - super.refresh(o); - } - - public ISelectionProvider getSelectionProvider() { - return fSelectionProvider; - } - - public String getTitle() { - return XMLEditorMessages.XMLTableTreeViewer_0; - } - - protected void handleDispose(DisposeEvent event) { - super.handleDispose(event); - treeExtension.dispose(); - setDocument(null); - } - - public void refresh() { - treeExtension.resetCachedData(); - super.refresh(); - } - - public void refresh(Object o) { - treeExtension.resetCachedData(); - super.refresh(o); - } - - public void refresh(boolean updateLabels) { - treeExtension.resetCachedData(); - super.refresh(updateLabels); - getControl().redraw(); - } - - public void refresh(Object element, boolean updateLabels) { - treeExtension.resetCachedData(); - super.refresh(element, updateLabels); - getControl().redraw(); - } - - public void setDocument(IDocument document) { - /* - * let the text editor to be the one that manages the model's lifetime - */ - IStructuredModel model = null; - try { - model = StructuredModelManager.getModelManager().getExistingModelForRead(document); - - if ((model != null) && (model instanceof IDOMModel)) { - Document domDoc = null; - domDoc = ((IDOMModel) model).getDocument(); - setInput(domDoc); - treeExtension.setIsUnsupportedInput(false); - } - else { - treeExtension.setIsUnsupportedInput(true); - } - } - finally { - if (model != null) { - model.releaseFromRead(); - } - } - - } - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTreeExtension.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTreeExtension.java deleted file mode 100644 index dfcfc5a13a..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTreeExtension.java +++ /dev/null @@ -1,170 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 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.wst.xml.ui.internal.tabletree; - -import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.ICellModifier; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Item; -import org.eclipse.swt.widgets.Tree; -import org.eclipse.swt.widgets.TreeItem; -import org.eclipse.ui.views.properties.IPropertyDescriptor; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.contentmodel.util.CMDescriptionBuilder; -import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -public class XMLTreeExtension extends TreeExtension { - - public final static String STRUCTURE_PROPERTY = XMLEditorMessages.XMLTreeExtension_0; - public final static String VALUE_PROPERTY = XMLEditorMessages.XMLTreeExtension_1; - - protected Composite control; - protected MyCellModifier modifier; - protected XMLTableTreePropertyDescriptorFactory propertyDescriptorFactory; - protected CMDescriptionBuilder decriptionBuilder = new CMDescriptionBuilder(); - protected TreeContentHelper treeContentHelper = new TreeContentHelper(); - - protected Color f1, f2, b1, b2; - protected boolean cachedDataIsValid = true; - - public XMLTreeExtension(Tree tree) { - super(tree); - control = tree; - modifier = new MyCellModifier(); - setCellModifier(modifier); - String[] properties = {STRUCTURE_PROPERTY, VALUE_PROPERTY}; - setColumnProperties(properties); - - /* https://bugs.eclipse.org/bugs/show_bug.cgi?id=185851 - Used to be hardcoded as COLOR_BLACK */ - f1 = tree.getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND); - Color background = tree.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND); - - int r = Math.abs(background.getRed() - 125); - int g = Math.abs(background.getGreen() - 85); - int b = Math.abs(background.getBlue() - 105); - - f2 = new Color(tree.getDisplay(), r, g, b); - b1 = tree.getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION); - b2 = background; - - propertyDescriptorFactory = new XMLTableTreePropertyDescriptorFactory(); - } - - public void dispose() { - super.dispose(); - f2.dispose(); - } - - public void resetCachedData() { - cachedDataIsValid = false; - } - - public void paintItems(GC gc, TreeItem[] items, Rectangle treeBounds) { - super.paintItems(gc, items, treeBounds); - cachedDataIsValid = true; - } - - protected Object[] computeTreeExtensionData(Object object) { - Color color = f1; - String string = ""; //$NON-NLS-1$ - if (string.length() == 0) { - string = (String) modifier.getValue(object, VALUE_PROPERTY); - color = f1; - } - if ((string.length() == 0) && (object instanceof Element)) { - string = getElementValueHelper((Element) object); - color = f2; - } - Object[] data = new Object[2]; - data[0] = string; - data[1] = color; - return data; - } - - protected void paintItem(GC gc, TreeItem item, Rectangle bounds) { - super.paintItem(gc, item, bounds); - Object[] data = computeTreeExtensionData(item.getData()); - if ((data != null) && (data.length == 2)) { - gc.setClipping(columnPosition, bounds.y + 1, controlWidth, bounds.height); - gc.setForeground((Color) data[1]); - gc.drawString((String) data[0], columnPosition + 5, bounds.y + 1); - gc.setClipping((Rectangle) null); - } - } - - protected void addEmptyTreeMessage(GC gc) { - // here we print a message when the document is empty just to give the - // user a visual cue - // so that they know how to proceed to edit the blank view - gc.setForeground(fTree.getDisplay().getSystemColor(SWT.COLOR_BLACK)); - gc.setBackground(fTree.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); - gc.drawString(XMLEditorMessages.XMLTreeExtension_3, 10, 10); - gc.drawString(XMLEditorMessages.XMLTreeExtension_4, 10, 10 + gc.getFontMetrics().getHeight()); - } - - public String getElementValueHelper(Element element) { - String result = null; - - ModelQuery mq = ModelQueryUtil.getModelQuery(element.getOwnerDocument()); - if ((result == null) && (mq != null)) { - CMElementDeclaration ed = mq.getCMElementDeclaration(element); - if ((ed != null) && !Boolean.TRUE.equals(ed.getProperty("isInferred"))) { //$NON-NLS-1$ - result = decriptionBuilder.buildDescription(ed); - } - } - return result != null ? result : ""; //$NON-NLS-1$ - } - - /** - * - */ - public class MyCellModifier implements ICellModifier, TreeExtension.ICellEditorProvider { - public boolean canModify(Object element, String property) { - boolean result = false; - if (element instanceof Node) { - Node node = (Node) element; - result = (property == VALUE_PROPERTY) && treeContentHelper.isEditable(node); - } - return result; - } - - public Object getValue(Object object, String property) { - String result = null; - if (object instanceof Node) { - result = treeContentHelper.getNodeValue((Node) object); - } - return (result != null) ? result : ""; //$NON-NLS-1$ - } - - public void modify(Object element, String property, Object value) { - // enableNodeSelectionListener(false); - Item item = (Item) element; - String oldValue = treeContentHelper.getNodeValue((Node) item.getData()); - String newValue = value.toString(); - if ((newValue != null) && !newValue.equals(oldValue)) { - treeContentHelper.setNodeValue((Node) item.getData(), value.toString()); - } - // enableNodeSelectionListener(true); - } - - public CellEditor getCellEditor(Object o, int col) { - IPropertyDescriptor pd = propertyDescriptorFactory.createPropertyDescriptor(o); - return pd != null ? pd.createPropertyEditor(control) : null; - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-validation/org/eclipse/wst/xml/ui/internal/validation/XMLValidationUIMessages.java b/bundles/org.eclipse.wst.xml.ui/src-validation/org/eclipse/wst/xml/ui/internal/validation/XMLValidationUIMessages.java deleted file mode 100644 index ff3bea2100..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-validation/org/eclipse/wst/xml/ui/internal/validation/XMLValidationUIMessages.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.wst.xml.ui.internal.validation; - -import org.eclipse.osgi.util.NLS; - -/** - * Strings used by XML Validation - */ -public class XMLValidationUIMessages extends NLS { - private static final String BUNDLE_NAME = "org.eclipse.wst.xml.ui.internal.validation.xmlvalidation"; //$NON-NLS-1$ - - private XMLValidationUIMessages() { - // cannot create new instance - } - - static { - // initialize resource bundle - NLS.initializeMessages(BUNDLE_NAME, XMLValidationUIMessages.class); - } - public static String _UI_REF_FILE_ERROR_DESCRIPTION; - public static String _UI_REF_FILE_ERROR_MESSAGE; - public static String _UI_REF_FILE_ERROR_DETAILS; - public static String _UI_DETAILS_INFORMATION_UNAVAILABLE; - public static String _UI_DETAILS_INFO_REVALIDATE_TO_REGENERATE; - public static String _UI_SAVE_DIRTY_FILE_MESSAGE; - public static String _UI_SAVE_DIRTY_FILE_TITLE; - public static String TaskListTableViewer_0; - public static String TaskListTableViewer_1; - public static String TaskListTableViewer_2; - public static String TaskListTableViewer_3; -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-validation/org/eclipse/wst/xml/ui/internal/validation/core/errorinfo/GroupNamePropertyTester.java b/bundles/org.eclipse.wst.xml.ui/src-validation/org/eclipse/wst/xml/ui/internal/validation/core/errorinfo/GroupNamePropertyTester.java deleted file mode 100644 index 7c3e9bc485..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-validation/org/eclipse/wst/xml/ui/internal/validation/core/errorinfo/GroupNamePropertyTester.java +++ /dev/null @@ -1,52 +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.wst.xml.ui.internal.validation.core.errorinfo; - - -import org.eclipse.core.expressions.PropertyTester; -import org.eclipse.core.resources.IMarker; - - -/** - * Custom property tester used to determine if the groupName attribute is - * present on a marker and that its value starts with a given expected value. - */ -public class GroupNamePropertyTester extends PropertyTester -{ - /** - * The group name prefix property name. - */ - private static final String GROUP_NAME_PREFIX = "groupNamePrefix"; //$NON-NLS-1$ - - /** - * The group name marker attribute. - */ - private static final String GROUP_NAME = "groupName"; //$NON-NLS-1$ - - public boolean test(Object receiver, String property, Object[] args, Object expectedValue) - { - if (GROUP_NAME_PREFIX.equals(property)) - { - if (receiver instanceof IMarker) - { - IMarker marker = (IMarker)receiver; - - String groupName = marker.getAttribute(GROUP_NAME, null); - - boolean testValue = groupName != null && expectedValue instanceof String && groupName.startsWith((String)expectedValue); - return testValue; - } - } - - return false; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-validation/org/eclipse/wst/xml/ui/internal/validation/core/errorinfo/ReferencedFileErrorDialog.java b/bundles/org.eclipse.wst.xml.ui/src-validation/org/eclipse/wst/xml/ui/internal/validation/core/errorinfo/ReferencedFileErrorDialog.java deleted file mode 100644 index 4cc9f29d4a..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-validation/org/eclipse/wst/xml/ui/internal/validation/core/errorinfo/ReferencedFileErrorDialog.java +++ /dev/null @@ -1,254 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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.wst.xml.ui.internal.validation.core.errorinfo; - -import java.util.List; -import com.ibm.icu.util.StringTokenizer; - -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StyleRange; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.events.MouseMoveListener; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; -import org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage; -import org.eclipse.wst.xml.ui.internal.validation.XMLValidationUIMessages; - - -public class ReferencedFileErrorDialog extends Dialog { - protected TaskListTableViewer tableViewer; - protected List errorList; - protected String markedUpDetailsMessage; - protected String contextFile; - protected String referencedFile; - protected StyledText styledText; - protected Text fullFileNameField; - - public ReferencedFileErrorDialog(Shell parentShell, List errorList, String contextFile, String referencedFile) { - super(parentShell); - - int styleBits = getShellStyle() | SWT.RESIZE; - styleBits &= ~SWT.APPLICATION_MODAL; - - setShellStyle(styleBits); - this.errorList = errorList; - - this.referencedFile = referencedFile; - this.contextFile = contextFile; - this.markedUpDetailsMessage = getMarkedUpDetailsMessage(); - } - - public int createAndOpen() { - create(); - getShell().setText(XMLValidationUIMessages._UI_REF_FILE_ERROR_DETAILS); - - setBlockOnOpen(false); - return open(); - } - - - protected Control createButtonBar(Composite parent) { - Composite composite = new Composite(parent, SWT.NONE); - composite.setLayout(new GridLayout(2, false)); - composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - fullFileNameField = new Text(composite, SWT.NONE); - fullFileNameField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - fullFileNameField.setBackground(parent.getBackground()); - fullFileNameField.setEditable(false); - - super.createButtonBar(composite); - - return composite; - } - - protected Control createDialogArea(Composite parent) { - Composite dialogArea = (Composite) super.createDialogArea(parent); - dialogArea.setLayout(new GridLayout()); - - Composite c = new Composite(dialogArea, SWT.NONE); - c.setLayout(new GridLayout()); - c.setLayoutData(createGridData(true, -1, 200)); - - styledText = new StyledText(c, SWT.MULTI | SWT.WRAP); - styledText.setBackground(c.getBackground()); - setStyledText(styledText, markedUpDetailsMessage); - styledText.setEditable(false); - styledText.setLayoutData(createGridData(false, 650, -1)); - - MouseListener mouseListener = new MouseListener(); - styledText.addMouseMoveListener(mouseListener); - - tableViewer = new TaskListTableViewer(c, 10); - tableViewer.setInput(errorList); - tableViewer.addSelectionChangedListener(new InternalSelectionListener()); - tableViewer.getControl().setLayoutData(createGridData(true, 700, -1)); - return dialogArea; - } - - String getFullURI(int offset) { - String uri = ""; //$NON-NLS-1$ - int index = getIndex(offset); - if (index != -1) { - if ((index == 0) || (index == 2) || (index == 3)) { - uri = referencedFile; - } - else { - uri = contextFile; - } - } - return uri; - } - - private int getIndex(int offset) { - int result = -1; - StyleRange[] range = styledText.getStyleRanges(); - for (int i = 0; i < range.length; i++) { - int l = range[i].start; - int r = l + range[i].length; - if ((l <= offset) && (r >= offset)) { - result = i; - break; - } - } - return result; - } - - class MouseListener implements MouseMoveListener { - public void mouseMove(MouseEvent event) { - String toolTipText = ""; //$NON-NLS-1$ - try { - - int offset = styledText.getOffsetAtLocation(new Point(event.x, event.y)); - toolTipText = getFullURI(offset); - - } - catch (Exception e) { - // Do nothing. - } - styledText.setToolTipText(toolTipText); - if ((toolTipText != null) && (toolTipText.length() > 0)) { - fullFileNameField.setText(toolTipText); - } - } - } - - private String getMarkedUpDetailsMessage() { - String detailsMessage = ""; //$NON-NLS-1$ - // TODO... need to move '_UI_REF_FILE_ERROR_DESCRIPTION' to this - // plugin's properties file - // - String string = XMLValidationUIMessages._UI_REF_FILE_ERROR_DESCRIPTION; - // TODO... need to edit the properties file to remove "'" characters - // from the string - // I'm using these characters to markup the bold font. It's safer if I - // add these programtically. - // - string = removePattern(string, "'"); //$NON-NLS-1$ - - String c = "'" + getLastSegment(contextFile) + "'"; //$NON-NLS-1$ //$NON-NLS-2$ - String r = "'" + getLastSegment(referencedFile) + "'"; //$NON-NLS-1$ //$NON-NLS-2$ - - detailsMessage = NLS.bind(string, new Object[]{r, c, r, c}); - return detailsMessage; - } - - private String removePattern(String string, String pattern) { - while (true) { - int index = string.indexOf(pattern); - if (index != -1) { - string = string.substring(0, index) + string.substring(index + pattern.length()); - } - else { - break; - } - } - return string; - } - - private void setStyledText(StyledText styledText, String text) { - String visibleMessage = ""; //$NON-NLS-1$ - for (StringTokenizer st = new StringTokenizer(markedUpDetailsMessage, "'", false); st.hasMoreTokens();) //$NON-NLS-1$ - { - String token = st.nextToken(); - visibleMessage += token; - } - - styledText.setText(visibleMessage); - // dw Font font = styledText.getFont(); - - boolean inQuote = false; - int position = 0; - for (StringTokenizer st = new StringTokenizer(markedUpDetailsMessage, "'", true); st.hasMoreTokens();) //$NON-NLS-1$ - { - String token = st.nextToken(); - - if (token.equals("'")) //$NON-NLS-1$ - { - inQuote = !inQuote; - } - else { - if (inQuote) { - try { - - StyleRange style = new StyleRange(position, token.length(), styledText.getForeground(), styledText.getBackground(), SWT.BOLD); - styledText.setStyleRange(style); - } - catch (Exception e) { - e.printStackTrace(); - } - } - position = position + token.length(); - } - } - } - - private static GridData createGridData(boolean fillBoth, int w, int h) { - GridData gd = new GridData(fillBoth ? GridData.FILL_BOTH : GridData.FILL_HORIZONTAL); - gd.widthHint = w; - gd.heightHint = h; - return gd; - } - - private static String getLastSegment(String uri) { - String result = uri; - int index = Math.max(uri.lastIndexOf("/"), uri.lastIndexOf("\\")); //$NON-NLS-1$ //$NON-NLS-2$ - if (index != -1) { - result = uri.substring(index + 1); - } - return result; - } - - protected class InternalSelectionListener implements ISelectionChangedListener { - public void selectionChanged(SelectionChangedEvent event) { - ISelection selection = event.getSelection(); - if (selection instanceof StructuredSelection) { - ValidationMessage validationMessage = (ValidationMessage) ((StructuredSelection) selection).getFirstElement(); - if (validationMessage != null) { - String uristring = validationMessage.getUri(); - ReferencedFileErrorUtility.openEditorAndGotoError(uristring, validationMessage.getLineNumber(), validationMessage.getColumnNumber()); - } - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-validation/org/eclipse/wst/xml/ui/internal/validation/core/errorinfo/ReferencedFileErrorUtility.java b/bundles/org.eclipse.wst.xml.ui/src-validation/org/eclipse/wst/xml/ui/internal/validation/core/errorinfo/ReferencedFileErrorUtility.java deleted file mode 100644 index 378ee89867..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-validation/org/eclipse/wst/xml/ui/internal/validation/core/errorinfo/ReferencedFileErrorUtility.java +++ /dev/null @@ -1,118 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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.wst.xml.ui.internal.validation.core.errorinfo; - -import java.net.URL; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IEditorDescriptor; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IEditorRegistry; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.editors.text.TextEditor; -import org.eclipse.ui.part.FileEditorInput; -import org.eclipse.ui.texteditor.IDocumentProvider; -import org.eclipse.wst.xml.core.internal.validation.core.logging.LoggerFactory; - - -public class ReferencedFileErrorUtility { - public static void openEditorAndGotoError(String uristring, final int line, final int column) { - if (uristring != null) { - try { - URL uri = new URL(uristring); - if (uri != null) { - if ("file".equals(uri.getProtocol())) //$NON-NLS-1$ - { - String pathString = uri.getPath(); - IPath path = new Path(pathString); - String device = path.getDevice(); - if ((device != null) && device.startsWith("/")) //$NON-NLS-1$ - { - path = path.setDevice(device.substring(1)); - } - final IFile iFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path); - if ((iFile != null) && iFile.exists()) { - // Open the editor for this file. - final IWorkbench workbench = PlatformUI.getWorkbench(); - final IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow(); - - Display.getDefault().asyncExec(new Runnable() { - public void run() { - try { - IContentType contentType = iFile.getContentDescription().getContentType(); - IEditorRegistry editorRegistry = workbench.getEditorRegistry(); - String fileName = iFile.getName(); - IEditorDescriptor descriptor = editorRegistry.getDefaultEditor(fileName, contentType); - String editorId; - if (descriptor != null) { - editorId = descriptor.getId(); - } - else { - descriptor = editorRegistry.getDefaultEditor(fileName + ".txt"); //$NON-NLS-1$ - editorId = descriptor.getId(); - } - - if (editorId != null) - { - FileEditorInput editorInput = new FileEditorInput(iFile); - IWorkbenchPage activePage = workbenchWindow.getActivePage(); - activePage.openEditor(editorInput, editorId); - } - } - catch (Exception ex) { - LoggerFactory.getLoggerInstance().logError("Exception encountered when attempting to open file: " + iFile + "\n\n", ex); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - }); - - Runnable runnable = new Runnable() { - public void run() { - IEditorPart editorPart = workbenchWindow.getActivePage().getActiveEditor(); - gotoError(editorPart, line, column); - } - }; - Display.getCurrent().asyncExec(runnable); - } - } - } - } - catch (Exception e) { - // Do nothing. - } - } - } - - static void gotoError(IEditorPart editorPart, int line, int column) { - if (editorPart != null) { - TextEditor textEditor = (TextEditor) editorPart.getAdapter(TextEditor.class); - if (textEditor != null) { - try { - IDocumentProvider dp = textEditor.getDocumentProvider(); - IDocument document = (dp != null) ? dp.getDocument(textEditor.getEditorInput()) : null; - textEditor.selectAndReveal(document.getLineOffset(line - 1) + column - 1, 0); - } - catch (BadLocationException x) { - // marker refers to invalid text position -> do nothing - } - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-validation/org/eclipse/wst/xml/ui/internal/validation/core/errorinfo/ReferencedFileErrorsHandler.java b/bundles/org.eclipse.wst.xml.ui/src-validation/org/eclipse/wst/xml/ui/internal/validation/core/errorinfo/ReferencedFileErrorsHandler.java deleted file mode 100644 index 3db624374e..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-validation/org/eclipse/wst/xml/ui/internal/validation/core/errorinfo/ReferencedFileErrorsHandler.java +++ /dev/null @@ -1,108 +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.wst.xml.ui.internal.validation.core.errorinfo; - - -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.handlers.HandlerUtil; -import org.eclipse.ui.views.markers.MarkerViewHandler; -import org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage; -import org.eclipse.wst.xml.ui.internal.validation.XMLValidationUIMessages; - - -/** - * Handler for the referenced file errors command. This class replaces the old - * ReferencedFileErrorActionDelegate. - */ -public class ReferencedFileErrorsHandler extends MarkerViewHandler -{ - public Object execute(ExecutionEvent event) throws ExecutionException - { - final IMarker[] selectedMarkers = getSelectedMarkers(event); - - IMarker selectedMarker = selectedMarkers[0]; - - if (selectedMarker != null) - { - try - { - - IResource resource = selectedMarker.getResource(); - Map map = (Map)resource.getSessionProperty(ValidationMessage.ERROR_MESSAGE_MAP_QUALIFIED_NAME); - if (map == null) - { - String infoUnavailable = XMLValidationUIMessages._UI_DETAILS_INFORMATION_UNAVAILABLE; - String revalidateToRegenerateErrors = XMLValidationUIMessages._UI_DETAILS_INFO_REVALIDATE_TO_REGENERATE; - MessageDialog.openInformation(Display.getCurrent().getActiveShell(), infoUnavailable, revalidateToRegenerateErrors); - } - else - { - String uri = null; - - String groupName = (String)selectedMarker.getAttribute("groupName"); //$NON-NLS-1$ - if (groupName.startsWith("referencedFileError")) //$NON-NLS-1$ - { - int index1 = groupName.indexOf("("); //$NON-NLS-1$ - int index2 = groupName.lastIndexOf(")"); //$NON-NLS-1$ - if ((index1 != -1) && (index2 > index1)) - { - uri = groupName.substring(index1 + 1, index2); - } - } - - if (uri != null) - { - List list = Collections.EMPTY_LIST; - - ValidationMessage message = (ValidationMessage)map.get(uri); - if (message != null) - { - list = message.getNestedMessages(); - } - - IPath resourceLocation = resource.getLocation(); - - if (resourceLocation != null) - { - String validatedFileURI = resourceLocation.toOSString(); - validatedFileURI = "file:/" + validatedFileURI; //$NON-NLS-1$ - - ReferencedFileErrorDialog dialog = new ReferencedFileErrorDialog( - HandlerUtil.getActiveShell(event), - list, - validatedFileURI, - uri); - dialog.createAndOpen(); - } - } - } - } - catch (CoreException e) - { - // Do nothing. - } - } - - return this; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.xml.ui/src-validation/org/eclipse/wst/xml/ui/internal/validation/core/errorinfo/TaskListTableViewer.java b/bundles/org.eclipse.wst.xml.ui/src-validation/org/eclipse/wst/xml/ui/internal/validation/core/errorinfo/TaskListTableViewer.java deleted file mode 100644 index 433edf7601..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-validation/org/eclipse/wst/xml/ui/internal/validation/core/errorinfo/TaskListTableViewer.java +++ /dev/null @@ -1,159 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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.wst.xml.ui.internal.validation.core.errorinfo; - -import java.util.List; - -import org.eclipse.jface.viewers.ColumnWeightData; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.TableLayout; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.ui.ISharedImages; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.internal.validation.XMLValidationUIMessages; - - - -public class TaskListTableViewer extends TableViewer { - protected static final int COLUMN_ICON = 0; - protected static final int COLUMN_DESCRIPTION = 1; - protected static final int COLUMN_RESOURCE = 3; - protected static final int COLUMN_LOCATION = 2; - - protected static final String LABEL_ICON = ""; //$NON-NLS-1$ - protected static final String LABEL_DESCRIPTION = XMLValidationUIMessages.TaskListTableViewer_0; - protected static final String LABEL_RESOURCE = XMLValidationUIMessages.TaskListTableViewer_1; - protected static final String LABEL_LOCATION = XMLValidationUIMessages.TaskListTableViewer_2; - - protected int visibleRows = -1; - - protected int getColumnWidth(int column) { - int result = 0; - switch (column) { - case COLUMN_ICON : { - result = 1; - break; - } - case COLUMN_DESCRIPTION : { - result = 20; - break; - } - case COLUMN_RESOURCE : { - result = 3; - break; - } - case COLUMN_LOCATION : { - result = 3; - break; - } - } - return result; - } - - public TaskListTableViewer(Composite parent, int visibleRows) { - this(parent, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER, visibleRows); - } - - public TaskListTableViewer(Composite parent, int style, int visibleRows) { - super(new Table(parent, style)); - getTable().setLinesVisible(true); - - Provider provider = new Provider(); - setContentProvider(provider); - setLabelProvider(provider); - - String[] columnPropertiesArray = {LABEL_ICON, LABEL_DESCRIPTION, LABEL_LOCATION}; - setColumnProperties(columnPropertiesArray); - - Table table = getTable(); - table.setHeaderVisible(true); - table.setLayoutData(new GridData(GridData.FILL_BOTH)); - - TableLayout layout = new TableLayout(); - - for (int i = 0; i < columnPropertiesArray.length; i++) { - TableColumn column = new TableColumn(table, i); - column.setText(columnPropertiesArray[i]); - column.setAlignment(SWT.LEFT); - layout.addColumnData(new ColumnWeightData(getColumnWidth(i), true)); - } - - table.setLayout(layout); - - this.visibleRows = visibleRows; - } - - /** - * NamespaceInfoTableLabelProvider - */ - protected class Provider extends LabelProvider implements ITableLabelProvider, IStructuredContentProvider { - Viewer viewer; - Image errorImage; - Image warnImage; - - public Provider() { - errorImage = XMLUIPlugin.getInstance().getImage(ISharedImages.IMG_OBJS_ERROR_TSK); - - warnImage = XMLUIPlugin.getInstance().getImage(ISharedImages.IMG_OBJS_WARN_TSK); - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - this.viewer = viewer; - } - - public Object[] getElements(Object inputElement) { - List list = (List) viewer.getInput(); - return list != null ? list.toArray() : null; - } - - public Image getColumnImage(Object object, int columnIndex) { - ValidationMessage validationMessage = (ValidationMessage) object; - Image result = null; - if (columnIndex == 0) { - int severity = validationMessage.getSeverity(); - if ((severity == IMessage.HIGH_SEVERITY) || (severity == IMessage.NORMAL_SEVERITY)) { - result = errorImage; - } - else { - result = warnImage; - } - } - return result; - } - - public String getColumnText(Object object, int column) { - ValidationMessage errorMessage = (ValidationMessage) object; - String result = ""; //$NON-NLS-1$ - switch (column) { - case COLUMN_DESCRIPTION : { - result = errorMessage.getMessage(); - break; - } - case COLUMN_LOCATION : { - result = XMLValidationUIMessages.TaskListTableViewer_3 + errorMessage.getLineNumber(); - break; - } - } - return result; - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-validation/org/eclipse/wst/xml/ui/internal/validation/xmlvalidation.properties b/bundles/org.eclipse.wst.xml.ui/src-validation/org/eclipse/wst/xml/ui/internal/validation/xmlvalidation.properties deleted file mode 100644 index c35c84947b..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-validation/org/eclipse/wst/xml/ui/internal/validation/xmlvalidation.properties +++ /dev/null @@ -1,29 +0,0 @@ -############################################################################### -# Copyright (c) 2001, 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 -############################################################################### -### Constants for strings - -# -# Referenced File Dialog Related Message -# -_UI_REF_FILE_ERROR_DESCRIPTION = The errors below were detected when validating the file "{0}" via the file "{1}". In most cases these errors can be detected by validating "{2}" directly. However it is possible that errors will only occur when {2} is validated in the context of {3}. -_UI_REF_FILE_ERROR_MESSAGE = Referenced file contains errors ({0}). For more information, right click on the message and select "Show Details..." -_UI_REF_FILE_ERROR_DETAILS = Referenced File Error Details - -_UI_DETAILS_INFORMATION_UNAVAILABLE = Details Information Unavailable -_UI_DETAILS_INFO_REVALIDATE_TO_REGENERATE = Details information currently unavailable. Please revalidate the file to regenerate the error details. - -# -# Dirty File Dialog Related Messages -# -TaskListTableViewer_0=Description -TaskListTableViewer_1=Resource -TaskListTableViewer_2=Location -TaskListTableViewer_3=line diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ExampleProjectCreationOperation.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ExampleProjectCreationOperation.java deleted file mode 100644 index cd809c778a..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ExampleProjectCreationOperation.java +++ /dev/null @@ -1,206 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.wizards; - -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.net.URL; -import java.util.zip.ZipFile; - -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectDescription; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.ui.dialogs.IOverwriteQuery; -import org.eclipse.ui.wizards.datatransfer.ImportOperation; -import org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.osgi.framework.Bundle; - -public class ExampleProjectCreationOperation implements IRunnableWithProgress { - - private IResource elementToOpen; - - private IOverwriteQuery overwriteQuery; - - private ExampleProjectCreationWizardPage[] pages; - - /** - * Constructor for ExampleProjectCreationOperation - */ - public ExampleProjectCreationOperation(ExampleProjectCreationWizardPage[] myPages, IOverwriteQuery myOverwriteQuery) { - elementToOpen = null; - pages = myPages; - overwriteQuery = myOverwriteQuery; - } - - private IProject configNewProject(IWorkspaceRoot root, String name, String[] natureIds, IProject[] referencedProjects, IProgressMonitor monitor) throws InvocationTargetException { - try { - IProject project = root.getProject(name); - if (!project.exists()) { - project.create(null); - } - if (!project.isOpen()) { - project.open(null); - } - IProjectDescription desc = project.getDescription(); - desc.setLocation(null); - desc.setNatureIds(natureIds); - desc.setReferencedProjects(referencedProjects); - - project.setDescription(desc, new SubProgressMonitor(monitor, 1)); - - return project; - } - catch (CoreException e) { - throw new InvocationTargetException(e); - } - } - - private void createProject(IWorkspaceRoot root, ExampleProjectCreationWizardPage page, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - IConfigurationElement desc = page.getConfigurationElement(); - - IConfigurationElement[] imports = desc.getChildren("import"); //$NON-NLS-1$ - IConfigurationElement[] natures = desc.getChildren("nature"); //$NON-NLS-1$ - IConfigurationElement[] references = desc.getChildren("references"); //$NON-NLS-1$ - int nImports = (imports == null) ? 0 : imports.length; - int nNatures = (natures == null) ? 0 : natures.length; - int nReferences = (references == null) ? 0 : references.length; - - monitor.beginTask(XMLWizardsMessages.ExampleProjectCreationOperation_op_desc_proj, nImports + 1); - - String name = page.getProjectName(); - - String[] natureIds = new String[nNatures]; - for (int i = 0; i < nNatures; i++) { - natureIds[i] = natures[i].getAttribute("id"); //$NON-NLS-1$ - } - IProject[] referencedProjects = new IProject[nReferences]; - for (int i = 0; i < nReferences; i++) { - referencedProjects[i] = root.getProject(references[i].getAttribute("id")); //$NON-NLS-1$ - } - - IProject proj = configNewProject(root, name, natureIds, referencedProjects, monitor); - - for (int i = 0; i < nImports; i++) { - doImports(proj, imports[i], new SubProgressMonitor(monitor, 1)); - } - - String open = desc.getAttribute("open"); //$NON-NLS-1$ - if ((open != null) && (open.length() > 0)) { - IResource fileToOpen = proj.findMember(new Path(open)); - if (fileToOpen != null) { - elementToOpen = fileToOpen; - } - } - - } - - private void doImports(IProject project, IConfigurationElement curr, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - try { - IPath destPath; - String name = curr.getAttribute("dest"); //$NON-NLS-1$ - if ((name == null) || (name.length() == 0)) { - destPath = project.getFullPath(); - } - else { - IFolder folder = project.getFolder(name); - if (!folder.exists()) { - folder.create(true, true, null); - } - destPath = folder.getFullPath(); - } - String importPath = curr.getAttribute("src"); //$NON-NLS-1$ - if (importPath == null) { - importPath = ""; //$NON-NLS-1$ - Logger.log(Logger.ERROR, "projectsetup descriptor: import missing"); //$NON-NLS-1$ - return; - } - - ZipFile zipFile = getZipFileFromPluginDir(importPath, getContributingPlugin(curr)); - importFilesFromZip(zipFile, destPath, new SubProgressMonitor(monitor, 1)); - } - catch (CoreException e) { - throw new InvocationTargetException(e); - } - } - - private String getContributingPlugin(IConfigurationElement configurationElement) { - Object parent = configurationElement; - while (parent != null) { - if (parent instanceof IExtension) { - return ((IExtension) parent).getNamespace(); - } - parent = ((IConfigurationElement) parent).getParent(); - } - return null; - } - - public IResource getElementToOpen() { - return elementToOpen; - } - - private ZipFile getZipFileFromPluginDir(String pluginRelativePath, String symbolicName) throws CoreException { - try { - Bundle bundle = Platform.getBundle(symbolicName); - URL starterURL = new URL(bundle.getEntry("/"), pluginRelativePath); //$NON-NLS-1$ - return new ZipFile(Platform.asLocalURL(starterURL).getFile()); - } - catch (IOException e) { - String message = pluginRelativePath + ": " + e.getMessage(); //$NON-NLS-1$ - Status status = new Status(IStatus.ERROR, XMLUIPlugin.ID, IStatus.ERROR, message, e); - throw new CoreException(status); - } - } - - private void importFilesFromZip(ZipFile srcZipFile, IPath destPath, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - ZipFileStructureProvider structureProvider = new ZipFileStructureProvider(srcZipFile); - ImportOperation op = new ImportOperation(destPath, structureProvider.getRoot(), structureProvider, overwriteQuery); - op.run(monitor); - } - - /* - * @see IRunnableWithProgress#run(IProgressMonitor) - */ - public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - if (monitor == null) { - monitor = new NullProgressMonitor(); - } - try { - monitor.beginTask(XMLWizardsMessages.ExampleProjectCreationOperation_op_desc, pages.length); - IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); - - for (int i = 0; i < pages.length; i++) { - createProject(root, pages[i], new SubProgressMonitor(monitor, 1)); - } - } - finally { - monitor.done(); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ExampleProjectCreationWizard.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ExampleProjectCreationWizard.java deleted file mode 100644 index d968c92071..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ExampleProjectCreationWizard.java +++ /dev/null @@ -1,232 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.wizards; - -import java.lang.reflect.InvocationTargetException; -import java.net.URL; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExecutableExtension; -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.IExtensionRegistry; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.INewWizard; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation; -import org.eclipse.ui.dialogs.IOverwriteQuery; -import org.eclipse.ui.ide.IDE; -import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard; -import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; - -public class ExampleProjectCreationWizard extends Wizard implements INewWizard, IExecutableExtension { - - private class ImportOverwriteQuery implements IOverwriteQuery { - - private int openDialog(final String file) { - final int[] result = {IDialogConstants.CANCEL_ID}; - getShell().getDisplay().syncExec(new Runnable() { - public void run() { - String title = XMLWizardsMessages.ExampleProjectCreationWizard_overwritequery_title; - String msg = NLS.bind(XMLWizardsMessages.ExampleProjectCreationWizard_overwritequery_message, file); - String[] options = {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.CANCEL_LABEL}; - MessageDialog dialog = new MessageDialog(getShell(), title, null, msg, MessageDialog.QUESTION, options, 0); - result[0] = dialog.open(); - } - }); - return result[0]; - } - - public String queryOverwrite(String file) { - String[] returnCodes = {YES, NO, ALL, CANCEL}; - int returnVal = openDialog(file); - return returnVal < 0 ? CANCEL : returnCodes[returnVal]; - } - } - - private IConfigurationElement wizardConfigElement; - private IConfigurationElement exampleConfigElement; - - private String EXAMPLE_WIZARD_XP_ID = "org.eclipse.wst.common.ui.exampleProjectCreationWizard"; //$NON-NLS-1$ - - private ExampleProjectCreationWizardPage[] pages; - - private final String WEB_BROWSER_ID = "org.eclipse.ui.browser.editor"; //$NON-NLS-1$ - - public ExampleProjectCreationWizard() { - super(); - setDialogSettings(XMLUIPlugin.getDefault().getDialogSettings()); - setWindowTitle(XMLWizardsMessages.ExampleProjectCreationWizard_title); - setNeedsProgressMonitor(true); - } - - /* - * @see Wizard#addPages - */ - public void addPages() { - super.addPages(); - - if (exampleConfigElement == null) { - return; - } - IConfigurationElement[] children = exampleConfigElement.getChildren("projectsetup"); //$NON-NLS-1$ - if ((children == null) || (children.length == 0)) { - Logger.log(Logger.ERROR, "descriptor must contain one ore more projectsetup tags"); //$NON-NLS-1$ - return; - } - - pages = new ExampleProjectCreationWizardPage[children.length]; - - for (int i = 0; i < children.length; i++) { - pages[i] = new ExampleProjectCreationWizardPage(i, children[i]); - addPage(pages[i]); - } - } - - public void init(IWorkbench workbench, IStructuredSelection currentSelection) { - if (exampleConfigElement != null) { - String banner = exampleConfigElement.getAttribute("banner"); //$NON-NLS-1$ - if (banner != null) { - URL imageURL = Platform.find(Platform.getBundle(exampleConfigElement.getDeclaringExtension().getNamespace()), new Path(banner)); - ImageDescriptor desc = ImageDescriptor.createFromURL(imageURL); - setDefaultPageImageDescriptor(desc); - } - } - } - - protected IConfigurationElement[] getExtendedConfigurationElements() { - IExtensionRegistry registry = Platform.getExtensionRegistry(); - IExtensionPoint exampleWizardXP = registry.getExtensionPoint(EXAMPLE_WIZARD_XP_ID); - if (exampleWizardXP == null) { - return new IConfigurationElement[0]; - } - IExtension extension = exampleWizardXP.getExtension(getWizardExtensionId()); - if (extension != null) { - return extension.getConfigurationElements(); - } - IConfigurationElement[] exampleWizardCEs = exampleWizardXP.getConfigurationElements(); - return exampleWizardCEs; - } - - private void handleException(Throwable target) { - String title = XMLWizardsMessages.ExampleProjectCreationWizard_op_error_title; - String message = XMLWizardsMessages.ExampleProjectCreationWizard_op_error_message; - if (target instanceof CoreException) { - IStatus status = ((CoreException) target).getStatus(); - ErrorDialog.openError(getShell(), title, message, status); - Logger.logException(status.getMessage(), status.getException()); - } - else { - MessageDialog.openError(getShell(), title, target.getMessage()); - Logger.logException(target); - } - } - - private void openResource(final IResource resource) { - if (resource.getType() != IResource.FILE) { - return; - } - IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - if (window == null) { - return; - } - final IWorkbenchPage activePage = window.getActivePage(); - if (activePage != null) { - final Display display = getShell().getDisplay(); - display.asyncExec(new Runnable() { - public void run() { - try { - IDE.openEditor(activePage, (IFile) resource, WEB_BROWSER_ID, true); - } - catch (PartInitException e) { - Logger.logException(e); - } - } - }); - BasicNewResourceWizard.selectAndReveal(resource, activePage.getWorkbenchWindow()); - } - } - - /* - * @see Wizard#performFinish - */ - public boolean performFinish() { - ExampleProjectCreationOperation runnable = new ExampleProjectCreationOperation(pages, new ImportOverwriteQuery()); - - IRunnableWithProgress op = new WorkspaceModifyDelegatingOperation(runnable); - try { - getContainer().run(false, true, op); - } - catch (InvocationTargetException e) { - handleException(e.getTargetException()); - return false; - } - catch (InterruptedException e) { - return false; - } - BasicNewProjectResourceWizard.updatePerspective(wizardConfigElement); - IResource res = runnable.getElementToOpen(); - if (res != null) { - openResource(res); - } - return true; - } - - /** - * Stores the configuration element for the wizard. The config element - * will be used in <code>performFinish</code> to set the result - * perspective. - */ - public void setInitializationData(IConfigurationElement cfig, String propertyName, Object data) { - wizardConfigElement = cfig; - String title = wizardConfigElement.getAttribute("name"); //$NON-NLS-1$ - if (title != null) { - setWindowTitle(title); - } - String wizardId = getWizardExtensionId(); - IConfigurationElement[] exampleWizardCEs = getExtendedConfigurationElements(); - for (int i = 0; i < exampleWizardCEs.length; i++) { - IConfigurationElement element = exampleWizardCEs[i]; - String extWizardId = element.getAttribute("id"); //$NON-NLS-1$ - if ((wizardId != null) && (extWizardId != null) && wizardId.equals(extWizardId)) { - exampleConfigElement = element; - } - } - // initializeDefaultPageImageDescriptor(); - } - - public String getWizardExtensionId() { - return wizardConfigElement.getAttribute("id"); //$NON-NLS-1$ - } - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ExampleProjectCreationWizardPage.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ExampleProjectCreationWizardPage.java deleted file mode 100644 index 3f13b33942..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ExampleProjectCreationWizardPage.java +++ /dev/null @@ -1,111 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ - -package org.eclipse.wst.xml.ui.internal.wizards; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.jface.wizard.IWizard; -import org.eclipse.jface.wizard.IWizardPage; -import org.eclipse.ui.dialogs.WizardNewProjectCreationPage; - -public class ExampleProjectCreationWizardPage extends WizardNewProjectCreationPage { - - private IConfigurationElement configurationElement; - - public ExampleProjectCreationWizardPage(int pageNumber, IConfigurationElement elem) { - - super("page" + pageNumber); //$NON-NLS-1$ - configurationElement = elem; - - String name = getAttribute(elem, "name"); //$NON-NLS-1$ - setInitialProjectName(calculateInitialProjectName(name)); - - setDescription(getAttribute(configurationElement, "pagedescription")); //$NON-NLS-1$ - setTitle(getAttribute(configurationElement, "pagetitle")); //$NON-NLS-1$ - - } - - /* - * Set the default project name that is to appear on the initialPage page - * of this wizard. - */ - protected String calculateInitialProjectName(String projectName) { - IProject projectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); - if (!projectHandle.exists()) { - return projectName; - } - // Change the name until it doesn't exists. Try 9 times and then - // give up. - for (int i = 1; i < 10; i++) { - projectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName + i); - if (!projectHandle.exists()) { - return projectName + i; - } - } - return projectName + "9"; //$NON-NLS-1$ - - } - - private String getAttribute(IConfigurationElement elem, String tag) { - String res = elem.getAttribute(tag); - if (res == null) { - return '!' + tag + '!'; - } - return res; - } - - - - /** - * Returns the configuration element of this page. - * - * @return Returns a IConfigurationElement - */ - public IConfigurationElement getConfigurationElement() { - return configurationElement; - } - - /** - * @see org.eclipse.ui.dialogs.WizardNewProjectCreationPage#validatePage() - */ - protected boolean validatePage() { - if (!super.validatePage()) { - return false; - } - - String projectName = getProjectName(); - if (projectName == null) { - return false; - } - - IWizard wizard = getWizard(); - if (wizard instanceof ExampleProjectCreationWizard) { - IWizardPage[] pages = wizard.getPages(); - for (int i = 0; i < pages.length; i++) { - if ((pages[i] != this) && (pages[i] instanceof ExampleProjectCreationWizardPage)) { - if (projectName.equals(((ExampleProjectCreationWizardPage) pages[i]).getProjectName())) { - setErrorMessage(XMLWizardsMessages.ExampleProjectCreationWizardPage_error_alreadyexists); - return false; - } - } - } - } - - return true; - } - - - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ExportXMLCatalogWizard.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ExportXMLCatalogWizard.java deleted file mode 100644 index 478d459796..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ExportXMLCatalogWizard.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Standards for Technology in Automotive Retail (STAR) and - * others. All rights reserved. This program and the accompanying materials - * are made available under the terms 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 Carver/STAR - dcarver@starstandard.org/d_a_carver@yahoo.com - bug 192568 - * Initial API - This implements the functionality of the - * old Export Dialog for the XML Catalog. - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.wizards; - -import java.io.File; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IExportWizard; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.dialogs.WizardNewFileCreationPage; -import org.eclipse.ui.wizards.newresource.BasicNewFileResourceWizard; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.eclipse.wst.xml.core.internal.catalog.CatalogSet; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog; -import org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages; - -public class ExportXMLCatalogWizard extends BasicNewFileResourceWizard implements IExportWizard { - - protected WizardNewFileCreationPage exportPage = null; - protected ICatalog workingUserCatalog = null; - protected ICatalog userCatalog = null; - - public ExportXMLCatalogWizard() { - setWindowTitle(XMLWizardsMessages._UI_DIALOG_XMLCATALOG_EXPORT_TITLE); - ImageDescriptor descriptor = XMLEditorPluginImageHelper.getInstance().getImageDescriptor(XMLEditorPluginImages.IMG_WIZBAN_GENERATEXML); - setDefaultPageImageDescriptor(descriptor); - ICatalog defaultCatalog = XMLCorePlugin.getDefault().getDefaultXMLCatalog(); - INextCatalog[] nextCatalogs = defaultCatalog.getNextCatalogs(); - for (int i = 0; i < nextCatalogs.length; i++) { - INextCatalog catalog = nextCatalogs[i]; - ICatalog referencedCatalog = catalog.getReferencedCatalog(); - if (referencedCatalog != null) { - if (XMLCorePlugin.USER_CATALOG_ID.equals(referencedCatalog.getId())) { - userCatalog = referencedCatalog; - } - } - } - CatalogSet tempCatalogSet = new CatalogSet(); - workingUserCatalog = tempCatalogSet.lookupOrCreateCatalog("working", ""); //$NON-NLS-1$ //$NON-NLS-2$ - workingUserCatalog.addEntriesFromCatalog(userCatalog); - - } - - public boolean performFinish() { - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - IWorkspaceRoot workspaceRoot = workspace.getRoot(); - String workspacePath = workspaceRoot.getLocation().toOSString(); - String fullPath = workspacePath + exportPage.getContainerFullPath().toOSString(); - String requiredString=fullPath + File.separator + exportPage.getFileName(); - try { - IFile file = exportPage.createNewFile(); - workingUserCatalog.setLocation(requiredString); - workingUserCatalog.save(); - file.refreshLocal(IResource.DEPTH_ZERO, null); - } catch (Exception ex) { - return false; - } - return true; - } - - public void addPages() { - exportPage = new WizardNewFileCreationPage("XML Catalog Export", getSelection()); - exportPage.setTitle(XMLWizardsMessages._UI_DIALOG_XMLCATALOG_EXPORT_TITLE); - exportPage.setDescription(XMLWizardsMessages._UI_DIALOG_XMLCATALOG_EXPORT_DESCRIPTION); - exportPage.setFileExtension("xml"); //$NON-NLS-1$ - - addPage(exportPage); - } - - public void init(IWorkbench workbench, IStructuredSelection currentSelection) { - super.init(workbench, currentSelection); - setWindowTitle(XMLWizardsMessages._UI_DIALOG_XMLCATALOG_EXPORT_TITLE); - ImageDescriptor descriptor = XMLEditorPluginImageHelper.getInstance().getImageDescriptor(XMLEditorPluginImages.IMG_WIZBAN_GENERATEXML); - setDefaultPageImageDescriptor(descriptor); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/IXMLWizardHelpContextIds.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/IXMLWizardHelpContextIds.java deleted file mode 100644 index e342efae4f..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/IXMLWizardHelpContextIds.java +++ /dev/null @@ -1,48 +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.wst.xml.ui.internal.wizards; - -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; - -/** - * Help context ids for the xml wizard. - * <p> - * This interface contains constants only; it is not intended to be - * implemented. - * </p> - */ -interface IXMLWizardHelpContextIds { - // org.eclipse.wst.xml.ui. - public static final String PREFIX = XMLUIPlugin.ID + "."; //$NON-NLS-1$ - // Create XML file from a DTD file radio - public static final String XML_NEWWIZARD_CREATEXML1_HELPID = PREFIX + "xmlc0101"; //$NON-NLS-1$ - // Create XML file from an XML schema file radio button - public static final String XML_NEWWIZARD_CREATEXML2_HELPID = PREFIX + "xmlc0102"; //$NON-NLS-1$ - // Create XML file from scratch radio button - public static final String XML_NEWWIZARD_CREATEXML3_HELPID = PREFIX + "xmlc0103"; //$NON-NLS-1$ - // Select Source file page - public static final String XML_NEWWIZARD_SELECTSOURCE_HELPID = PREFIX + "xmlc0500"; //$NON-NLS-1$ - // Root element for both DTD and XML schema - public static final String XML_NEWWIZARD_SELECTROOTELEMENT_HELPID = PREFIX + "xmlc0410"; //$NON-NLS-1$ - // Create Optional Attributes - public static final String XML_NEWWIZARD_SELECTROOTELEMENT1_HELPID = PREFIX + "xmlc0441"; //$NON-NLS-1$ - // Create Optional Elements - public static final String XML_NEWWIZARD_SELECTROOTELEMENT2_HELPID = PREFIX + "xmlc0442"; //$NON-NLS-1$ - // Create first choice of required choice - public static final String XML_NEWWIZARD_SELECTROOTELEMENT3_HELPID = PREFIX + "xmlc0443"; //$NON-NLS-1$ - // Fill elements and attribute with data - public static final String XML_NEWWIZARD_SELECTROOTELEMENT4_HELPID = PREFIX + "xmlc0444"; //$NON-NLS-1$ - // System ID for DTD - public static final String XML_NEWWIZARD_SELECTROOTELEMENT5_HELPID = PREFIX + "xmlc0210"; //$NON-NLS-1$ - // Public ID for DTD - public static final String XML_NEWWIZARD_SELECTROOTELEMENT6_HELPID = PREFIX + "xmlc0220"; //$NON-NLS-1$ -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ImportXMLCatalogPage.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ImportXMLCatalogPage.java deleted file mode 100644 index 38e3447da2..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ImportXMLCatalogPage.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Standards for Technology in Automotive Retail (STAR) and - * others. All rights reserved. This program and the accompanying materials - * are made available under the terms 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 Carver/STAR - dcarver@starstandard.org/d_a_carver@yahoo.com - bug 192568 - * Initial API - This implements the functionality of the - * old Import Dialog for the XML Catalog. - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.wizards; - -import org.eclipse.core.resources.IFile; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.wst.common.ui.internal.viewers.SelectSingleFileView; - -public class ImportXMLCatalogPage extends WizardPage { - - protected SelectSingleFileView selectSingleFileView; - protected IStructuredSelection selection; - - - public ImportXMLCatalogPage() { - super(XMLWizardsMessages._UI_DIALOG_XMLCATALOG_IMPORT_TITLE); - setTitle(XMLWizardsMessages._UI_DIALOG_XMLCATALOG_IMPORT_TITLE); - selection = new StructuredSelection(); - selectSingleFileView = new SelectSingleFileView(selection, false) { - public void createFilterControl(Composite composite) { - ImportXMLCatalogPage.this.createFilterControl(composite); - } - }; - - } - - public void createControl(Composite parent) { - Composite composite = new Composite(parent, SWT.NULL); - composite.setLayout(new GridLayout()); - GridData gd = new GridData(GridData.FILL_BOTH); - gd.widthHint = 350; - gd.heightHint = 350; - composite.setLayoutData(gd); - String[] extensions = { ".xmlcatalog", ".xml" }; //$NON-NLS-1$ //$NON-NLS-2$ - selectSingleFileView.addFilterExtensions(extensions); - selectSingleFileView.createControl(composite); - selectSingleFileView.setVisibleHelper(true); - selectSingleFileView.addSelectionChangedTreeListener(new ISelectionChangedListener(){ - public void selectionChanged(SelectionChangedEvent event) { - ImportXMLCatalogPage.this.setPageComplete(selectSingleFileView.getFile() != null); - } - }); - setControl(composite); - } - - public void createFilterControl(Composite composite) { - } - - public IFile getFile() { - return selectSingleFileView.getFile(); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ImportXMLCatalogWizard.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ImportXMLCatalogWizard.java deleted file mode 100644 index f1200a2478..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ImportXMLCatalogWizard.java +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Standards for Technology in Automotive Retail (STAR) and - * others. All rights reserved. This program and the accompanying materials - * are made available under the terms 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 Carver/STAR - dcarver@starstandard.org/d_a_carver@yahoo.com - bug 192568 - * Initial API - This implements the functionality of the - * old Import Dialog for the XML Catalog. - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.wizards; - -import org.eclipse.core.resources.IFile; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.ui.IImportWizard; -import org.eclipse.ui.IWorkbench; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.eclipse.wst.xml.core.internal.catalog.CatalogSet; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog; -import org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog; -import org.eclipse.wst.xml.ui.internal.catalog.XMLCatalogMessages; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages; - -public class ImportXMLCatalogWizard extends Wizard implements IImportWizard { - - protected ImportXMLCatalogPage importPage = null; - protected ICatalog workingUserCatalog = null; - protected ICatalog userCatalog = null; - - public ImportXMLCatalogWizard() { - setWindowTitle(XMLWizardsMessages._UI_DIALOG_XMLCATALOG_IMPORT_TITLE); - ImageDescriptor descriptor = XMLEditorPluginImageHelper.getInstance().getImageDescriptor(XMLEditorPluginImages.IMG_WIZBAN_GENERATEXML); - setDefaultPageImageDescriptor(descriptor); - ICatalog defaultCatalog = XMLCorePlugin.getDefault().getDefaultXMLCatalog(); - INextCatalog[] nextCatalogs = defaultCatalog.getNextCatalogs(); - for (int i = 0; i < nextCatalogs.length; i++) { - INextCatalog catalog = nextCatalogs[i]; - ICatalog referencedCatalog = catalog.getReferencedCatalog(); - if (referencedCatalog != null) { - if (XMLCorePlugin.USER_CATALOG_ID.equals(referencedCatalog.getId())) { - userCatalog = referencedCatalog; - } - } - } - - CatalogSet tempCatalogSet = new CatalogSet(); - workingUserCatalog = tempCatalogSet.lookupOrCreateCatalog("working", ""); //$NON-NLS-1$ //$NON-NLS-2$ - workingUserCatalog.addEntriesFromCatalog(userCatalog); - } - - public boolean canFinish() { - return importPage.isPageComplete(); - } - - public boolean performFinish() { - IFile file = importPage.getFile(); - if (file != null) { - String fileName = file.getLocation().toFile().toURI().toString(); - try { - CatalogSet tempResourceSet = new CatalogSet(); - ICatalog newCatalog = tempResourceSet.lookupOrCreateCatalog("temp", fileName); //$NON-NLS-1$ - - workingUserCatalog.addEntriesFromCatalog(newCatalog); - userCatalog.clear(); - userCatalog.addEntriesFromCatalog(workingUserCatalog); - userCatalog.save(); - } - catch (Exception e) { - return false; - } - } - - return true; - } - - public void init(IWorkbench workbench, IStructuredSelection selection) { - // TODO Auto-generated method stub - - } - - public void addPages() { - importPage = new ImportXMLCatalogPage(); - importPage.setTitle(XMLCatalogMessages.UI_LABEL_IMPORT_DIALOG_HEADING); - importPage.setDescription(XMLWizardsMessages._UI_DIALOG_XMLCATALOG_IMPORT_DESCRIPTION); - importPage.setMessage(XMLCatalogMessages.UI_LABEL_IMPORT_DIALOG_MESSAGE); - addPage(importPage); - importPage.setPageComplete(false); - } -} - - diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NamespaceInfoContentBuilder.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NamespaceInfoContentBuilder.java deleted file mode 100644 index 09eed81a69..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NamespaceInfoContentBuilder.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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.wst.xml.ui.internal.wizards; - -import java.util.Hashtable; -import java.util.List; -import java.util.Vector; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMAnyElement; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.util.ContentBuilder; -import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo; - -public class NamespaceInfoContentBuilder extends ContentBuilder { - protected int count = 1; - public List list = new Vector(); - protected Hashtable table = new Hashtable(); - - public NamespaceInfoContentBuilder() { - super(); - } - - public void visitCMElementDeclaration(CMElementDeclaration ed) { - if (ed.getProperty("http://org.eclipse.wst/cm/properties/definitionInfo") != null) //$NON-NLS-1$ - { - super.visitCMElementDeclaration(ed); - } - } - - protected void createAnyElementNode(CMAnyElement anyElement) { - String uri = anyElement.getNamespaceURI(); - if ((uri != null) && !uri.startsWith("##")) //$NON-NLS-1$ - { - if (table.get(uri) == null) { - NamespaceInfo info = new NamespaceInfo(); - info.uri = uri; - info.prefix = "p" + count++; //$NON-NLS-1$ - table.put(uri, info); - list.add(info); - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewModelWizard.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewModelWizard.java deleted file mode 100644 index 9cfcd23801..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewModelWizard.java +++ /dev/null @@ -1,325 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * David Schneider, david.schneider@unisys.com - [142500] WTP properties pages fonts don't follow Eclipse preferences - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.wizards; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.FileDialog; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.INewWizard; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.dialogs.WizardNewFileCreationPage; -import org.eclipse.wst.xml.core.internal.provisional.contenttype.ContentTypeIdForXML; - -public class NewModelWizard extends Wizard implements INewWizard { - - protected IStructuredSelection fSelection; - protected IWorkbench fWorkbench; - protected String fCurrentDirectory; - - public NewModelWizard() { - super(); - } - - public void init(IWorkbench workbench, IStructuredSelection selection) { - this.fWorkbench = workbench; - this.fSelection = selection; - } - - public boolean performFinish() { - boolean result = true; - WizardPage currentPage = (WizardPage) getContainer().getCurrentPage(); - if (currentPage != null) { - result = currentPage.isPageComplete(); - } - return result; - } - - /** - * showFileDialog - */ - public FileDialog showFileDialog(Shell shell, String defaultDirectory, String defaultFile, String[] filterExtensions) { - FileDialog fileDialog = new FileDialog(shell, SWT.OPEN); - - // Get the last visit directory if we haven't defined a particular one - // here. - if ((defaultDirectory == null) || (defaultDirectory.length() == 0)) { - // defaultDirectory = - // Locate.instance(this).getLastSelectedDirectory(getResourcePath()); - } - - if ((defaultDirectory != null) && (defaultDirectory.length() != 0)) { - fileDialog.setFilterPath(defaultDirectory); - } - - fileDialog.setFileName(defaultFile); - fileDialog.setFilterExtensions(filterExtensions); - - fileDialog.open(); - - return fileDialog; - } - - - public void setCurrentDirectory(String currentDirectory1) { - this.fCurrentDirectory = currentDirectory1; - } - - - public void createWorkbenchResource(IContainer container, String fileName) { - IPath path = container.getFullPath(); - path = path.append(fileName); - IFile file = container.getWorkspace().getRoot().getFile(path); - if (!file.exists()) { - try { - file.create(null, true, null); - } - catch (CoreException e) { - // XMLBuilderPlugin.getPlugin().getMsgLogger().write("Encountered - // exception creating file: " + e.getMessage()); - } - } - } - - /** - * StartPage - */ - public class StartPage extends WizardPage implements Listener { - protected int selectedButton; - protected String[] radioButtonLabel; - protected Button[] radioButton; - - public StartPage(String pageName, String[] radioButtonLabel) { - super(pageName); - this.radioButtonLabel = radioButtonLabel; - radioButton = new Button[radioButtonLabel.length]; - } - - public Button getRadioButtonAtIndex(int i) { - Button result = null; - if ((i >= 0) && (i < radioButton.length)) { - result = radioButton[i]; - } - return result; - } - - public int getSelectedRadioButtonIndex() { - int result = -1; - for (int i = 0; i < radioButton.length; i++) { - if (radioButton[i].getSelection()) { - result = i; - } - } - return result; - } - - public void createControl(Composite parent) { - Composite base = new Composite(parent, SWT.NONE); - base.setLayout(new GridLayout()); - - // radio buttons' container - Composite radioButtonsGroup = new Composite(base, SWT.NONE); - GridLayout layout = new GridLayout(); - layout.numColumns = 1; - layout.makeColumnsEqualWidth = true; - layout.marginWidth = 0; - - radioButtonsGroup.setLayout(layout); - GridData gd = new GridData(GridData.FILL_BOTH); - gd.heightHint = 300; - gd.widthHint = 400; - radioButtonsGroup.setLayoutData(gd); - - for (int i = 0; i < radioButtonLabel.length; i++) { - radioButton[i] = new Button(radioButtonsGroup, SWT.RADIO); - radioButton[i].setText(radioButtonLabel[i]); - radioButton[i].setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - // radioButton[i].addListener(SWT.Modify, this); - } - setControl(base); - setPageComplete(isPageComplete()); - Dialog.applyDialogFont(parent); - } - - public void handleEvent(Event event) { - if (event.type == SWT.Modify) { - setPageComplete(isPageComplete()); - } - } - } - - - /** - * NewFilePage - */ - public class NewFilePage extends WizardNewFileCreationPage { - public String defaultName = "NewFile"; //$NON-NLS-1$ - public String defaultFileExtension = ".txt"; //$NON-NLS-1$ - public String[] filterExtensions = {"*.txt"}; //$NON-NLS-1$ - private List fValidExtensions = null; - - public NewFilePage(IStructuredSelection selection) { - super("", selection); //$NON-NLS-1$ - } - - protected String computeDefaultFileName() { - int count = 0; - String fileName = defaultName + defaultFileExtension; - IPath containerFullPath = getContainerFullPath(); - if (containerFullPath != null) { - while (true) { - IPath path = containerFullPath.append(fileName); - if (ResourcesPlugin.getWorkspace().getRoot().exists(path)) { - count++; - fileName = defaultName + count + defaultFileExtension; - } - else { - break; - } - } - } - return fileName; - } - - // returns true if file of specified name exists in any case for - // selected container - protected String existsFileAnyCase(String fileName) { - if ((getContainerFullPath() != null) && (getContainerFullPath().isEmpty() == false) && (fileName.compareTo("") != 0)) //$NON-NLS-1$ - { - // look through all resources at the specified container - - // compare in upper case - IResource parent = ResourcesPlugin.getWorkspace().getRoot().findMember(getContainerFullPath()); - if (parent instanceof IContainer) { - IContainer container = (IContainer) parent; - try { - IResource[] members = container.members(); - String enteredFileUpper = fileName.toUpperCase(); - for (int i = 0; i < members.length; i++) { - String resourceUpperName = members[i].getName().toUpperCase(); - if (resourceUpperName.equals(enteredFileUpper)) { - return members[i].getName(); - } - } - } - catch (CoreException e) { - } - } - } - return null; - } - - - protected boolean validatePage() { - String fullFileName = getFileName(); - if (!extensionValidForContentType(fullFileName)) { - setErrorMessage(NLS.bind(XMLWizardsMessages._ERROR_BAD_FILENAME_EXTENSION, getValidExtensions().toString())); - return false; - } - // no fileExtension, let's check for this file with default file - // extension - fullFileName += defaultFileExtension; - if ((getContainerFullPath() != null) && (getContainerFullPath().isEmpty() == false) && (getFileName().compareTo("") != 0)) //$NON-NLS-1$ - { - Path fullPath = new Path(getContainerFullPath().toString() + '/' + fullFileName); - IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(fullPath); - if (resource != null) { - setErrorMessage(XMLWizardsMessages._ERROR_FILE_ALREADY_EXISTS); - return false; - } - } - - // check for file should be case insensitive - String sameName = existsFileAnyCase(fullFileName); - if (sameName != null) { - // ISSUE: is qualitifedFileName not needed, or is it supposed - // to be used in error message? - // String qualifiedFileName = - // getContainerFullPath().toString() + '/' + fullFileName; - setErrorMessage(XMLWizardsMessages._ERROR_FILE_ALREADY_EXISTS + " " + sameName); //$NON-NLS-1$ - return false; - } - - return super.validatePage(); - } - - public void createControl(Composite parent) { - // inherit default container and name specification widgets - super.createControl(parent); - this.setFileName(computeDefaultFileName()); - setPageComplete(validatePage()); - } - - /** - * Get list of valid extensions for XML Content type - * - * @return List - */ - List getValidExtensions() { - if (fValidExtensions == null) { - IContentType type = Platform.getContentTypeManager().getContentType(ContentTypeIdForXML.ContentTypeID_XML); - fValidExtensions = new ArrayList(Arrays.asList(type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC))); - } - return fValidExtensions; - } - - /** - * Verifies if fileName is valid name for content type. Takes base - * content type into consideration. - * - * @param fileName - * @return true if extension is valid for this content type - */ - boolean extensionValidForContentType(String fileName) { - boolean valid = false; - - IContentType type = Platform.getContentTypeManager().getContentType(ContentTypeIdForXML.ContentTypeID_XML); - // there is currently an extension - if (fileName.lastIndexOf('.') != -1) { - // check what content types are associated with current - // extension - IContentType[] types = Platform.getContentTypeManager().findContentTypesFor(fileName); - int i = 0; - while ((i < types.length) && !valid) { - valid = types[i].isKindOf(type); - ++i; - } - } - else { - valid = true; // no extension so valid - } - return valid; - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLGenerator.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLGenerator.java deleted file mode 100644 index 406a4063d9..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLGenerator.java +++ /dev/null @@ -1,412 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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.wst.xml.ui.internal.wizards; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - -import javax.xml.parsers.DocumentBuilderFactory; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.ProjectScope; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Preferences; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.core.runtime.preferences.IScopeContext; -import org.eclipse.core.runtime.preferences.InstanceScope; -import org.eclipse.jface.util.Assert; -import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver; -import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolverPlugin; -import org.eclipse.wst.common.uriresolver.internal.util.URIHelper; -import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames; -import org.eclipse.wst.sse.core.utils.StringUtils; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.xml.core.internal.contentmodel.ContentModelManager; -import org.eclipse.wst.xml.core.internal.contentmodel.util.ContentBuilder; -import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMContentBuilderImpl; -import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMWriter; -import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -public class NewXMLGenerator { - - protected String grammarURI; - protected CMDocument cmDocument; - protected int buildPolicy; - protected String rootElementName; - - protected ICatalogEntry xmlCatalogEntry; - - // info for dtd - protected String publicId; - protected String systemId; - protected String defaultSystemId; - - // info for xsd - public List namespaceInfoList; - - public NewXMLGenerator() { - super(); - } - - public NewXMLGenerator(String grammarURI, CMDocument cmDocument) { - this.grammarURI = grammarURI; - this.cmDocument = cmDocument; - } - - - public static CMDocument createCMDocument(String uri, String[] errorInfo) { - String title = null; - String message = null; - List errorList = new Vector(); - CMDocument cmDocument = null; - - if (URIHelper.isReadableURI(uri, true)) { - // (cs) assume the uri has been provided in a normalized form - cmDocument = ContentModelManager.getInstance().createCMDocument(uri, null); - - if (uri.endsWith(".dtd")) { //$NON-NLS-1$ - if (errorList.size() > 0) { - title = XMLWizardsMessages._UI_INVALID_GRAMMAR_ERROR; - message = XMLWizardsMessages._UI_LABEL_ERROR_DTD_INVALID_INFO; - } - } - else // ".xsd" - { - // To be consistent with the schema editor validation - XMLSchemaValidationChecker validator = new XMLSchemaValidationChecker(); - if (!validator.isValid(uri)) { - title = XMLWizardsMessages._UI_INVALID_GRAMMAR_ERROR; - message = XMLWizardsMessages._UI_LABEL_ERROR_SCHEMA_INVALID_INFO; - } - else if (cmDocument != null) { - int globalElementCount = cmDocument.getElements().getLength(); - if (globalElementCount == 0) { - title = XMLWizardsMessages._UI_WARNING_TITLE_NO_ROOT_ELEMENTS; - message = XMLWizardsMessages._UI_WARNING_MSG_NO_ROOT_ELEMENTS; - } - } - } - } - else { - title = XMLWizardsMessages._UI_WARNING_TITLE_NO_ROOT_ELEMENTS; - message = XMLWizardsMessages._UI_WARNING_URI_NOT_FOUND_COLON + " " + uri; //$NON-NLS-1$ - } - errorInfo[0] = title; - errorInfo[1] = message; - - return cmDocument; - } - - private String applyLineDelimiter(IFile file, String text) { - String lineDelimiter = Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, System.getProperty("line.separator"), new IScopeContext[] {new ProjectScope(file.getProject()), new InstanceScope() });//$NON-NLS-1$ - String convertedText = StringUtils.replace(text, "\r\n", "\n"); - convertedText = StringUtils.replace(convertedText, "\r", "\n"); - convertedText = StringUtils.replace(convertedText, "\n", lineDelimiter); - return convertedText; - } - - /** - * @deprecated use createTemplateXMLDocument(IFile, String) instead - */ - public void createEmptyXMLDocument(IFile newFile) throws Exception { - String charSet = getUserPreferredCharset(); - String contents = "<?xml version=\"1.0\" encoding=\"" + charSet + "\"?>"; //$NON-NLS-1$ //$NON-NLS-2$ - createTemplateXMLDocument(newFile, contents); - } - - void createTemplateXMLDocument(IFile newFile, String contents) throws Exception { - if (contents != null) { - String charSet = getUserPreferredCharset(); - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - - PrintWriter writer = new PrintWriter(new OutputStreamWriter(outputStream, charSet)); - contents = applyLineDelimiter(newFile, contents); - writer.println(contents); - writer.flush(); - outputStream.close(); - - ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); - newFile.setContents(inputStream, true, true, null); - inputStream.close(); - } - } - - private String getUserPreferredCharset() { - Preferences preference = XMLCorePlugin.getDefault().getPluginPreferences(); - String charSet = preference.getString(CommonEncodingPreferenceNames.OUTPUT_CODESET); - return charSet; - } - - public void createXMLDocument(String xmlFileName) throws Exception { - IContentType contentType = Platform.getContentTypeManager().findContentTypeFor(xmlFileName); - String charset = null; - if (contentType != null) { - charset = contentType.getDefaultCharset(); - } - ByteArrayOutputStream outputStream = createXMLDocument(xmlFileName, charset); - - File file = new File(xmlFileName); - FileOutputStream fos = new FileOutputStream(file); - outputStream.writeTo(fos); - fos.close(); - } - - - public void createXMLDocument(IFile newFile, String xmlFileName) throws Exception { - String charset = newFile.getCharset(); - ByteArrayOutputStream outputStream = createXMLDocument(xmlFileName, charset); - - String contents = outputStream.toString(charset); - contents = applyLineDelimiter(newFile, contents); - - ByteArrayInputStream inputStream = new ByteArrayInputStream(contents.getBytes(charset)); - newFile.setContents(inputStream, true, true, null); - inputStream.close(); - } - - - public ByteArrayOutputStream createXMLDocument(String xmlFileName, String charset) throws Exception { - if (charset == null) { - charset = getUserPreferredCharset(); - if (charset == null) { - charset = "UTF-8"; //$NON-NLS-1$ - } - } - CMDocument cmDocument = getCMDocument(); - - Assert.isNotNull(cmDocument); - Assert.isNotNull(getRootElementName()); - - // create the xml model - CMNamedNodeMap nameNodeMap = cmDocument.getElements(); - CMElementDeclaration cmElementDeclaration = (CMElementDeclaration) nameNodeMap.getNamedItem(getRootElementName()); - - Document xmlDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); - DOMContentBuilderImpl contentBuilder = new DOMContentBuilderImpl(xmlDocument); - - // this 'uglyTempHack' flag is required in order to supress the - // creation a default encoding - // we'll handle this later in the domWriter.print() method used below - // - contentBuilder.supressCreationOfDoctypeAndXMLDeclaration = true; - contentBuilder.setBuildPolicy(buildPolicy); - contentBuilder.setExternalCMDocumentSupport(new MyExternalCMDocumentSupport(namespaceInfoList, xmlFileName)); - contentBuilder.createDefaultRootContent(cmDocument, cmElementDeclaration, namespaceInfoList); - - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, charset); - - DOMWriter domWriter = new DOMWriter(outputStreamWriter); - - // TODO... instead of relying on file extensions, we need to keep - // track of the grammar type - // better yet we should reate an SSE document so that we can format it - // nicely before saving - // then we won't need the DOMWriter at all - // - domWriter.print(xmlDocument, charset, cmDocument.getNodeName(), getNonWhitespaceString(getPublicId()), getNonWhitespaceString(getSystemId())); - outputStream.flush(); - outputStream.close(); - - return outputStream; - } - - - public void createNamespaceInfoList() { - List result = new Vector(); - if (cmDocument != null) { - result = (List) cmDocument.getProperty("http://org.eclipse.wst/cm/properties/completeNamespaceInfo"); //$NON-NLS-1$ - if (result != null) { - int size = result.size(); - for (int i = 0; i < size; i++) { - NamespaceInfo info = (NamespaceInfo) result.get(i); - if (i == 0) { - String locationInfo = null; - if (xmlCatalogEntry != null) { - if (xmlCatalogEntry.getEntryType() == ICatalogEntry.ENTRY_TYPE_PUBLIC) { - locationInfo = xmlCatalogEntry.getAttributeValue(ICatalogEntry.ATTR_WEB_URL); - } - else { - locationInfo = xmlCatalogEntry.getKey(); - } - } - if (locationInfo == null) { - locationInfo = defaultSystemId; - } - info.locationHint = locationInfo; - info.setProperty("locationHint-readOnly", "true"); //$NON-NLS-1$ //$NON-NLS-2$ - info.setProperty("uri-readOnly", "true"); //$NON-NLS-1$ //$NON-NLS-2$ - info.setProperty("unremovable", "true"); //$NON-NLS-1$ //$NON-NLS-2$ - } else { - info.locationHint = null; - } - } - } - - NamespaceInfoContentBuilder builder = new NamespaceInfoContentBuilder(); - builder.setBuildPolicy(ContentBuilder.BUILD_ONLY_REQUIRED_CONTENT); - builder.visitCMNode(cmDocument); - result.addAll(builder.list); - } - namespaceInfoList = result; - } - - - public boolean isMissingNamespaceLocation() { - boolean result = false; - for (Iterator i = namespaceInfoList.iterator(); i.hasNext();) { - NamespaceInfo info = (NamespaceInfo) i.next(); - if (info.locationHint == null) { - result = true; - break; - } - } - return result; - } - - - public String[] getNamespaceInfoErrors() { - String[] errorList = null; - -// No warnings should be given when namespaces entries have missing location hints -// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=105128 -// if ((namespaceInfoList != null) && isMissingNamespaceLocation()) { -// String title = XMLWizardsMessages._UI_LABEL_NO_LOCATION_HINT; -// String message = XMLWizardsMessages._UI_WARNING_MSG_NO_LOCATION_HINT_1 + " " + XMLWizardsMessages._UI_WARNING_MSG_NO_LOCATION_HINT_2 + "\n\n" + XMLWizardsMessages._UI_WARNING_MSG_NO_LOCATION_HINT_3; //$NON-NLS-1$ //$NON-NLS-2$ -// -// errorList = new String[2]; -// errorList[0] = title; -// errorList[1] = message; -// } - return errorList; - } - - - public void setXMLCatalogEntry(ICatalogEntry catalogEntry) { - xmlCatalogEntry = catalogEntry; - } - - public ICatalogEntry getXMLCatalogEntry() { - return xmlCatalogEntry; - } - - - public void setBuildPolicy(int policy) { - buildPolicy = policy; - } - - - public void setDefaultSystemId(String sysId) { - defaultSystemId = sysId; - } - - public String getDefaultSystemId() { - return defaultSystemId; - } - - public void setSystemId(String sysId) { - systemId = sysId; - } - - public String getSystemId() { - return systemId; - } - - public void setPublicId(String pubId) { - publicId = pubId; - } - - public String getPublicId() { - return publicId; - } - - public void setGrammarURI(String gramURI) { - grammarURI = gramURI; - } - - public String getGrammarURI() { - return grammarURI; - } - - public void setCMDocument(CMDocument cmDoc) { - cmDocument = cmDoc; - } - - public CMDocument getCMDocument() { - return cmDocument; - } - - public void setRootElementName(String rootName) { - rootElementName = rootName; - } - - public String getRootElementName() { - return rootElementName; - } - - - protected class MyExternalCMDocumentSupport implements DOMContentBuilderImpl.ExternalCMDocumentSupport { - protected List namespaceInfoList1; - protected URIResolver idResolver; - protected String resourceLocation; - - protected MyExternalCMDocumentSupport(List namespaceInfoListParam, String resourceLocation) { - this.namespaceInfoList1 = namespaceInfoListParam; - this.resourceLocation = resourceLocation; - idResolver = URIResolverPlugin.createResolver(); - } - - public CMDocument getCMDocument(Element element, String namespaceURI) { - CMDocument result = null; - if ((namespaceURI != null) && (namespaceURI.trim().length() > 0)) { - String locationHint = null; - for (Iterator i = namespaceInfoList1.iterator(); i.hasNext();) { - NamespaceInfo info = (NamespaceInfo) i.next(); - if (namespaceURI.equals(info.uri)) { - locationHint = info.locationHint; - break; - } - } - if (locationHint != null) { - grammarURI = idResolver.resolve(resourceLocation, locationHint, locationHint); - result = ContentModelManager.getInstance().createCMDocument(getGrammarURI(), null); - } - } - else { - result = cmDocument; - } - return result; - } - } - - public static String getNonWhitespaceString(String string) { - String result = null; - if (string != null) { - if (string.trim().length() > 0) { - result = string; - } - } - return result; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLHandler.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLHandler.java deleted file mode 100644 index 38c2669350..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLHandler.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Standards for Technology in Automotive Retail and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms 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 Carver - initial API and implementation, bug 212330 - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.wizards; - -import java.util.Iterator; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.commands.IHandler; -import org.eclipse.core.resources.IFile; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.handlers.HandlerUtil; - -public class NewXMLHandler extends AbstractHandler implements IHandler { - - /** - * - */ - public NewXMLHandler() { - super(); - } - - /* (non-Javadoc) - * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) - */ - public Object execute(ExecutionEvent event) throws ExecutionException { - IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event); - ISelection selection = workbenchWindow.getSelectionService().getSelection(); - Object selectedObject = getSelection(selection); - - if ((selectedObject instanceof IFile) && (selection instanceof IStructuredSelection)) { - IFile file = (IFile) selectedObject; - IStructuredSelection structuredSelection = (IStructuredSelection) selection; - try { - NewXMLWizard.showDialog(workbenchWindow.getShell(), file, structuredSelection); - } - catch (Exception e) { - // XMLCorePlugin.getDefault().getLog().log(); - } - } - return null; - } - - public static Object getSelection(ISelection selection) { - if (selection == null) { - return null; - } - - Object result = null; - if (selection instanceof IStructuredSelection) { - IStructuredSelection es = (IStructuredSelection) selection; - Iterator i = es.iterator(); - if (i.hasNext()) { - result = i.next(); - } - } - return result; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLTemplatesWizardPage.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLTemplatesWizardPage.java deleted file mode 100644 index 929a01f762..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLTemplatesWizardPage.java +++ /dev/null @@ -1,508 +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.wst.xml.ui.internal.wizards; - -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.preference.PreferenceDialog; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.jface.text.Document; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.jface.text.source.SourceViewer; -import org.eclipse.jface.text.source.SourceViewerConfiguration; -import org.eclipse.jface.text.templates.DocumentTemplateContext; -import org.eclipse.jface.text.templates.Template; -import org.eclipse.jface.text.templates.TemplateBuffer; -import org.eclipse.jface.text.templates.TemplateContext; -import org.eclipse.jface.text.templates.TemplateContextType; -import org.eclipse.jface.text.templates.persistence.TemplateStore; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TableLayout; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerSorter; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ControlAdapter; -import org.eclipse.swt.events.ControlEvent; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Link; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.PreferencesUtil; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration; -import org.eclipse.wst.sse.ui.internal.StructuredTextViewer; -import org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider; -import org.eclipse.wst.xml.core.internal.provisional.contenttype.ContentTypeIdForXML; -import org.eclipse.wst.xml.ui.StructuredTextViewerConfigurationXML; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.internal.editor.IHelpContextIds; -import org.eclipse.wst.xml.ui.internal.preferences.XMLUIPreferenceNames; -import org.eclipse.wst.xml.ui.internal.templates.TemplateContextTypeIdsXML; - -/** - * Templates page in new file wizard. Allows users to select a new file - * template to be applied in new file. - * - */ -public class NewXMLTemplatesWizardPage extends WizardPage { - - /** - * Content provider for templates - */ - private class TemplateContentProvider implements IStructuredContentProvider { - /** The template store. */ - private TemplateStore fStore; - - /* - * @see IContentProvider#dispose() - */ - public void dispose() { - fStore = null; - } - - /* - * @see IStructuredContentProvider#getElements(Object) - */ - public Object[] getElements(Object input) { - return fStore.getTemplates(TemplateContextTypeIdsXML.NEW); - } - - /* - * @see IContentProvider#inputChanged(Viewer, Object, Object) - */ - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - fStore = (TemplateStore) newInput; - } - } - - /** - * Label provider for templates. - */ - private class TemplateLabelProvider extends LabelProvider implements ITableLabelProvider { - - /* - * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, - * int) - */ - public Image getColumnImage(Object element, int columnIndex) { - return null; - } - - /* - * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, - * int) - */ - public String getColumnText(Object element, int columnIndex) { - Template template = (Template) element; - - switch (columnIndex) { - case 0 : - return template.getName(); - case 1 : - return template.getDescription(); - default : - return ""; //$NON-NLS-1$ - } - } - } - - /** Last selected template name */ - private String fLastSelectedTemplateName; - /** The viewer displays the pattern of selected template. */ - private SourceViewer fPatternViewer; - /** The table presenting the templates. */ - private TableViewer fTableViewer; - /** Template store used by this wizard page */ - private TemplateStore fTemplateStore; - /** Checkbox for using templates. */ - private Button fUseTemplateButton; - - public NewXMLTemplatesWizardPage() { - super("NewXMLTemplatesWizardPage", XMLWizardsMessages.NewXMLTemplatesWizardPage_0, null); //$NON-NLS-1$ - setDescription(XMLWizardsMessages.NewXMLTemplatesWizardPage_1); - } - - /** - * Correctly resizes the table so no phantom columns appear - * - * @param parent - * the parent control - * @param buttons - * the buttons - * @param table - * the table - * @param column1 - * the first column - * @param column2 - * the second column - * @param column3 - * the third column - */ - private void configureTableResizing(final Composite parent, final Table table, final TableColumn column1, final TableColumn column2) { - parent.addControlListener(new ControlAdapter() { - public void controlResized(ControlEvent e) { - Rectangle area = parent.getClientArea(); - Point preferredSize = table.computeSize(SWT.DEFAULT, SWT.DEFAULT); - int width = area.width - 2 * table.getBorderWidth(); - if (preferredSize.y > area.height) { - // Subtract the scrollbar width from the total column - // width - // if a vertical scrollbar will be required - Point vBarSize = table.getVerticalBar().getSize(); - width -= vBarSize.x; - } - - Point oldSize = table.getSize(); - if (oldSize.x > width) { - // table is getting smaller so make the columns - // smaller first and then resize the table to - // match the client area width - column1.setWidth(width / 2); - column2.setWidth(width / 2); - table.setSize(width, area.height); - } - else { - // table is getting bigger so make the table - // bigger first and then make the columns wider - // to match the client area width - table.setSize(width, area.height); - column1.setWidth(width / 2); - column2.setWidth(width / 2); - } - } - }); - } - - public void createControl(Composite ancestor) { - Composite parent = new Composite(ancestor, SWT.NONE); - GridLayout layout = new GridLayout(); - layout.numColumns = 2; - parent.setLayout(layout); - - // create checkbox for user to use XML Template - fUseTemplateButton = new Button(parent, SWT.CHECK); - fUseTemplateButton.setText(XMLWizardsMessages.NewXMLTemplatesWizardPage_4); - GridData data = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1); - fUseTemplateButton.setLayoutData(data); - fUseTemplateButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - enableTemplates(); - } - }); - - // create composite for Templates table - Composite innerParent = new Composite(parent, SWT.NONE); - GridLayout innerLayout = new GridLayout(); - innerLayout.numColumns = 2; - innerLayout.marginHeight = 0; - innerLayout.marginWidth = 0; - innerParent.setLayout(innerLayout); - GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1); - innerParent.setLayoutData(gd); - - // Create linked text to just to templates preference page - Link link = new Link(innerParent, SWT.NONE); - link.setText(XMLWizardsMessages.NewXMLTemplatesWizardPage_6); - data = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1); - link.setLayoutData(data); - link.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - linkClicked(); - } - }); - - // create table that displays templates - Table table = new Table(innerParent, SWT.BORDER | SWT.FULL_SELECTION); - - data = new GridData(GridData.FILL_BOTH); - data.widthHint = convertWidthInCharsToPixels(2); - data.heightHint = convertHeightInCharsToPixels(10); - data.horizontalSpan = 2; - table.setLayoutData(data); - table.setHeaderVisible(true); - table.setLinesVisible(true); - TableLayout tableLayout = new TableLayout(); - table.setLayout(tableLayout); - - TableColumn column1 = new TableColumn(table, SWT.NONE); - column1.setText(XMLWizardsMessages.NewXMLTemplatesWizardPage_2); - - TableColumn column2 = new TableColumn(table, SWT.NONE); - column2.setText(XMLWizardsMessages.NewXMLTemplatesWizardPage_3); - - fTableViewer = new TableViewer(table); - fTableViewer.setLabelProvider(new TemplateLabelProvider()); - fTableViewer.setContentProvider(new TemplateContentProvider()); - - fTableViewer.setSorter(new ViewerSorter() { - public int compare(Viewer viewer, Object object1, Object object2) { - if ((object1 instanceof Template) && (object2 instanceof Template)) { - Template left = (Template) object1; - Template right = (Template) object2; - int result = left.getName().compareToIgnoreCase(right.getName()); - if (result != 0) { - return result; - } - return left.getDescription().compareToIgnoreCase(right.getDescription()); - } - return super.compare(viewer, object1, object2); - } - - public boolean isSorterProperty(Object element, String property) { - return true; - } - }); - - fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent e) { - updateViewerInput(); - } - }); - - // create viewer that displays currently selected template's contents - fPatternViewer = doCreateViewer(parent); - - fTemplateStore = XMLUIPlugin.getDefault().getTemplateStore(); - fTableViewer.setInput(fTemplateStore); - - configureTableResizing(innerParent, table, column1, column2); - loadLastSavedPreferences(); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IHelpContextIds.XML_NEWWIZARD_TEMPLATE_HELPID); - Dialog.applyDialogFont(parent); - setControl(parent); - } - - /** - * Creates, configures and returns a source viewer to present the template - * pattern on the preference page. Clients may override to provide a - * custom source viewer featuring e.g. syntax coloring. - * - * @param parent - * the parent control - * @return a configured source viewer - */ - private SourceViewer createViewer(Composite parent) { - SourceViewerConfiguration sourceViewerConfiguration = new StructuredTextViewerConfiguration() { - StructuredTextViewerConfiguration baseConfiguration = new StructuredTextViewerConfigurationXML(); - - public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { - return baseConfiguration.getConfiguredContentTypes(sourceViewer); - } - - public LineStyleProvider[] getLineStyleProviders(ISourceViewer sourceViewer, String partitionType) { - return baseConfiguration.getLineStyleProviders(sourceViewer, partitionType); - } - }; - SourceViewer viewer = new StructuredTextViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); - ((StructuredTextViewer) viewer).getTextWidget().setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont")); //$NON-NLS-1$ - IStructuredModel scratchModel = StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(ContentTypeIdForXML.ContentTypeID_XML); - IDocument document = scratchModel.getStructuredDocument(); - viewer.configure(sourceViewerConfiguration); - viewer.setDocument(document); - return viewer; - } - - private SourceViewer doCreateViewer(Composite parent) { - Label label = new Label(parent, SWT.NONE); - label.setText(XMLWizardsMessages.NewXMLTemplatesWizardPage_5); - GridData data = new GridData(); - data.horizontalSpan = 2; - label.setLayoutData(data); - - SourceViewer viewer = createViewer(parent); - viewer.setEditable(false); - - Control control = viewer.getControl(); - data = new GridData(GridData.FILL_BOTH); - data.horizontalSpan = 2; - data.heightHint = convertHeightInCharsToPixels(5); - control.setLayoutData(data); - - return viewer; - } - - /** - * Enable/disable controls in page based on fUseTemplateButton's current - * state. - */ - void enableTemplates() { - boolean enabled = fUseTemplateButton.getSelection(); - - if (!enabled) { - // save last selected template - Template template = getSelectedTemplate(); - if (template != null) { - fLastSelectedTemplateName = template.getName(); - } - else { - fLastSelectedTemplateName = ""; //$NON-NLS-1$ - } - - fTableViewer.setSelection(null); - } - else { - setSelectedTemplate(fLastSelectedTemplateName); - } - - fTableViewer.getControl().setEnabled(enabled); - fPatternViewer.getControl().setEnabled(enabled); - } - - /** - * Return the template preference page id - * - * @return - */ - private String getPreferencePageId() { - return "org.eclipse.wst.sse.ui.preferences.xml.templates"; //$NON-NLS-1$ - } - - /** - * Get the currently selected template. - * - * @return - */ - private Template getSelectedTemplate() { - Template template = null; - IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection(); - - if (selection.size() == 1) { - template = (Template) selection.getFirstElement(); - } - return template; - } - - /** - * Returns template string to insert. - * - * @return String to insert or null if none is to be inserted - */ - String getTemplateString() { - String templateString = null; - - Template template = getSelectedTemplate(); - if (template != null) { - TemplateContextType contextType = XMLUIPlugin.getDefault().getTemplateContextRegistry().getContextType(TemplateContextTypeIdsXML.NEW); - IDocument document = new Document(); - TemplateContext context = new DocumentTemplateContext(contextType, document, 0, 0); - try { - TemplateBuffer buffer = context.evaluate(template); - templateString = buffer.getString(); - } - catch (Exception e) { - Logger.log(Logger.WARNING_DEBUG, "Could not create template for new xml", e); //$NON-NLS-1$ - } - } - - return templateString; - } - - void linkClicked() { - String pageId = getPreferencePageId(); - PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(getShell(), pageId, new String[]{pageId}, null); - dialog.open(); - fTableViewer.refresh(); - } - - /** - * Load the last template name used in New XML File wizard. - */ - private void loadLastSavedPreferences() { - String templateName = XMLUIPlugin.getDefault().getPreferenceStore().getString(XMLUIPreferenceNames.NEW_FILE_TEMPLATE_NAME); - if ((templateName == null) || (templateName.length() == 0)) { - fLastSelectedTemplateName = ""; //$NON-NLS-1$ - fUseTemplateButton.setSelection(false); - } - else { - fLastSelectedTemplateName = templateName; - fUseTemplateButton.setSelection(true); - } - enableTemplates(); - } - - /** - * Save template name used for next call to New XML File wizard. - */ - void saveLastSavedPreferences() { - String templateName = ""; //$NON-NLS-1$ - - Template template = getSelectedTemplate(); - if (template != null) { - templateName = template.getName(); - } - - XMLUIPlugin.getDefault().getPreferenceStore().setValue(XMLUIPreferenceNames.NEW_FILE_TEMPLATE_NAME, templateName); - XMLUIPlugin.getDefault().savePluginPreferences(); - } - - /** - * Select a template in the table viewer given the template name. If - * template name cannot be found or templateName is null, just select - * first item in table. If no items in table select nothing. - * - * @param templateName - */ - private void setSelectedTemplate(String templateName) { - Object template = null; - - if ((templateName != null) && (templateName.length() > 0)) { - // pick the last used template - template = fTemplateStore.findTemplate(templateName, TemplateContextTypeIdsXML.NEW); - } - - // no record of last used template so just pick first element - if (template == null) { - // just pick first element - template = fTableViewer.getElementAt(0); - } - - if (template != null) { - IStructuredSelection selection = new StructuredSelection(template); - fTableViewer.setSelection(selection, true); - } - } - - /** - * Updates the pattern viewer. - */ - void updateViewerInput() { - Template template = getSelectedTemplate(); - if (template != null) { - fPatternViewer.getDocument().set(template.getPattern()); - } - else { - fPatternViewer.getDocument().set(""); //$NON-NLS-1$ - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLWizard.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLWizard.java deleted file mode 100644 index da1f814d3b..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLWizard.java +++ /dev/null @@ -1,879 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * David Schneider, david.schneider@unisys.com - [142500] WTP properties pages fonts don't follow Eclipse preferences - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.wizards; - -import java.util.Arrays; -import java.util.List; -import java.util.Vector; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Preferences; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.util.Assert; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.wizard.IWizardPage; -import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -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.Shell; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.IEditorDescriptor; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.part.FileEditorInput; -import org.eclipse.ui.part.PageBook; -import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard; -import org.eclipse.wst.common.uriresolver.internal.util.URIHelper; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMContentBuilder; -import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo; -import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.dialogs.NamespaceInfoErrorHelper; -import org.eclipse.wst.xml.ui.internal.dialogs.SelectFileOrXMLCatalogIdPanel; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages; -import org.eclipse.wst.xml.ui.internal.nsedit.CommonEditNamespacesDialog; - -import com.ibm.icu.text.Collator; - -public class NewXMLWizard extends NewModelWizard { - protected static final int CREATE_FROM_DTD = 0; - protected static final int CREATE_FROM_XSD = 1; - protected static final int CREATE_FROM_SCRATCH = 2; - - protected static final String[] createFromRadioButtonLabel = {XMLWizardsMessages._UI_RADIO_XML_FROM_DTD, XMLWizardsMessages._UI_RADIO_XML_FROM_SCHEMA, XMLWizardsMessages._UI_RADIO_XML_FROM_SCRATCH}; - - protected static final String[] filePageFilterExtensions = {".xml"}; //$NON-NLS-1$ - protected static final String[] browseXSDFilterExtensions = {".xsd"}; //$NON-NLS-1$ - protected static final String[] browseDTDFilterExtensions = {".dtd"}; //$NON-NLS-1$ - - protected NewFilePage newFilePage; - /** - * @deprecated clients should not be allowed to change start page - */ - protected StartPage startPage; - private StartPage fCreateXMLFromWizardPage; - protected SelectGrammarFilePage selectGrammarFilePage; - protected SelectRootElementPage selectRootElementPage; - - protected String cmDocumentErrorMessage; - - protected NewXMLGenerator generator; - private NewXMLTemplatesWizardPage fNewXMLTemplatesWizardPage; - - - public NewXMLWizard() { - setWindowTitle(XMLWizardsMessages._UI_WIZARD_CREATE_NEW_TITLE); - ImageDescriptor descriptor = XMLEditorPluginImageHelper.getInstance().getImageDescriptor(XMLEditorPluginImages.IMG_WIZBAN_GENERATEXML); - setDefaultPageImageDescriptor(descriptor); - generator = new NewXMLGenerator(); - } - - - public NewXMLWizard(IFile file, CMDocument cmDocument) { - this(); - - generator.setGrammarURI(URIHelper.getPlatformURI(file)); - generator.setCMDocument(cmDocument); - } - - - public static void showDialog(Shell shell, IFile file, IStructuredSelection structuredSelection) { - String[] errorInfo = new String[2]; - // (cs) the URI argument to createCMDocument needs to be a fully - // qualified URI - // - CMDocument cmDocument = NewXMLGenerator.createCMDocument(URIHelper.getPlatformURI(file), errorInfo); - if (errorInfo[0] == null) { - NewXMLWizard wizard = new NewXMLWizard(file, cmDocument); - wizard.init(PlatformUI.getWorkbench(), structuredSelection); - wizard.setNeedsProgressMonitor(true); - WizardDialog dialog = new WizardDialog(shell, wizard); - dialog.create(); - dialog.getShell().setText(XMLWizardsMessages._UI_DIALOG_NEW_TITLE); - dialog.setBlockOnOpen(true); - dialog.open(); - } - else { - MessageDialog.openInformation(shell, errorInfo[0], errorInfo[1]); - } - } - - public void addPages() { - String grammarURI = generator.getGrammarURI(); - - // new file page - newFilePage = new NewFilePage(fSelection); - newFilePage.setTitle(XMLWizardsMessages._UI_WIZARD_CREATE_XML_FILE_HEADING); - newFilePage.setDescription(XMLWizardsMessages._UI_WIZARD_CREATE_XML_FILE_EXPL); - newFilePage.defaultName = (grammarURI != null) ? URIHelper.removeFileExtension(URIHelper.getLastSegment(grammarURI)) : "NewFile"; //$NON-NLS-1$ - Preferences preference = XMLCorePlugin.getDefault().getPluginPreferences(); - String ext = preference.getString(XMLCorePreferenceNames.DEFAULT_EXTENSION); - newFilePage.defaultFileExtension = "." + ext; //$NON-NLS-1$ - newFilePage.filterExtensions = filePageFilterExtensions; - addPage(newFilePage); - - if (grammarURI == null) { - // create xml from page - fCreateXMLFromWizardPage = new StartPage("StartPage", createFromRadioButtonLabel) //$NON-NLS-1$ - { - public void createControl(Composite parent) { - super.createControl(parent); - } - - public void setVisible(boolean visible) { - super.setVisible(visible); - getRadioButtonAtIndex(getCreateMode()).setSelection(true); - getRadioButtonAtIndex(getCreateMode()).setFocus(); - - // Set the help context for each button - PlatformUI.getWorkbench().getHelpSystem().setHelp(fCreateXMLFromWizardPage.getRadioButtonAtIndex(0), IXMLWizardHelpContextIds.XML_NEWWIZARD_CREATEXML1_HELPID); - PlatformUI.getWorkbench().getHelpSystem().setHelp(fCreateXMLFromWizardPage.getRadioButtonAtIndex(1), IXMLWizardHelpContextIds.XML_NEWWIZARD_CREATEXML2_HELPID); - PlatformUI.getWorkbench().getHelpSystem().setHelp(fCreateXMLFromWizardPage.getRadioButtonAtIndex(2), IXMLWizardHelpContextIds.XML_NEWWIZARD_CREATEXML3_HELPID); - } - }; - - - fCreateXMLFromWizardPage.setTitle(XMLWizardsMessages._UI_WIZARD_CREATE_XML_HEADING); - fCreateXMLFromWizardPage.setDescription(XMLWizardsMessages._UI_WIZARD_CREATE_XML_EXPL); - addPage(fCreateXMLFromWizardPage); - } - - // selectGrammarFilePage - selectGrammarFilePage = new SelectGrammarFilePage(); - addPage(selectGrammarFilePage); - - // select root element page - selectRootElementPage = new SelectRootElementPage(); - selectRootElementPage.setTitle(XMLWizardsMessages._UI_WIZARD_SELECT_ROOT_HEADING); - selectRootElementPage.setDescription(XMLWizardsMessages._UI_WIZARD_SELECT_ROOT_EXPL); - addPage(selectRootElementPage); - - // from "scratch" - fNewXMLTemplatesWizardPage = new NewXMLTemplatesWizardPage(); - addPage(fNewXMLTemplatesWizardPage); - } - - - public IWizardPage getStartingPage() { - WizardPage result = null; - if (startPage != null) { - result = startPage; - } - else { - result = newFilePage; - } - return result; - } - - - public int getCreateMode() { - String grammarURI = generator.getGrammarURI(); - - int result = CREATE_FROM_SCRATCH; - if (grammarURI != null) { - if (grammarURI.endsWith(".dtd")) //$NON-NLS-1$ - { - result = CREATE_FROM_DTD; - } - else if (grammarURI.endsWith(".xsd")) //$NON-NLS-1$ - { - result = CREATE_FROM_XSD; - } - } - else if (fCreateXMLFromWizardPage != null) { - int selectedIndex = fCreateXMLFromWizardPage.getSelectedRadioButtonIndex(); - if (selectedIndex != -1) { - result = selectedIndex; - } - } - return result; - } - - - public IWizardPage getNextPage(IWizardPage currentPage) { - WizardPage nextPage = null; - if (currentPage == startPage) { - nextPage = newFilePage; - } - else if (currentPage == newFilePage) { - if (generator.getGrammarURI() == null) - nextPage = fCreateXMLFromWizardPage; - else - nextPage = selectRootElementPage; - } - else if (currentPage == fCreateXMLFromWizardPage) { - if (getCreateMode() == CREATE_FROM_SCRATCH) { - nextPage = fNewXMLTemplatesWizardPage; - } - else if (generator.getGrammarURI() == null) { - nextPage = selectGrammarFilePage; - } - else { - nextPage = selectRootElementPage; - } - } - else if (currentPage == selectGrammarFilePage) { - nextPage = selectRootElementPage; - } - return nextPage; - } - - - public boolean canFinish() { - boolean result = false; - - IWizardPage currentPage = getContainer().getCurrentPage(); - // can finish on: new file page, create from & template page if creating from scratch, select root element page - if ((currentPage == newFilePage && generator.getGrammarURI() == null) || (fCreateXMLFromWizardPage != null && fCreateXMLFromWizardPage.getSelectedRadioButtonIndex() == CREATE_FROM_SCRATCH) || (currentPage == selectRootElementPage)) { - result = currentPage.isPageComplete(); - } - return result; - } - - - public boolean performFinish() { - boolean result = super.performFinish(); - // save user options for next use - fNewXMLTemplatesWizardPage.saveLastSavedPreferences(); - - String fileName = null; - try { - - String[] namespaceErrors = generator.getNamespaceInfoErrors(); - if (namespaceErrors != null) { - String title = namespaceErrors[0]; - String message = namespaceErrors[1]; - result = MessageDialog.openQuestion(getShell(), title, message); - } - - if (result) { - fileName = newFilePage.getFileName(); - if ((new Path(fileName)).getFileExtension() == null) { - newFilePage.setFileName(fileName.concat(newFilePage.defaultFileExtension)); - } - - IFile newFile = newFilePage.createNewFile(); - String xmlFileName = newFile.getLocation().toOSString(); - - if (getContainer().getCurrentPage() == selectRootElementPage) { - - generator.createXMLDocument(newFile, xmlFileName); - } - else { - // put template contents into file - String templateString = fNewXMLTemplatesWizardPage.getTemplateString(); - generator.createTemplateXMLDocument(newFile, templateString); - } - - newFile.refreshLocal(IResource.DEPTH_ONE, null); - - IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - BasicNewResourceWizard.selectAndReveal(newFile, workbenchWindow); - openEditor(newFile); - } - } - catch (Exception e) { - Logger.logException("Exception completing New XML wizard " + fileName, e); //$NON-NLS-1$ - } - return result; - } - - public void openEditor(IFile file) { - // Open editor on new file. - String editorId = null; - try { - IEditorDescriptor editor = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getLocation().toOSString(), file.getContentDescription().getContentType()); - if (editor != null) { - editorId = editor.getId(); - } - } - catch (CoreException e1) { - // editor id could not be retrieved, so we can not open editor - return; - } - IWorkbenchWindow dw = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - try { - if (dw != null) { - IWorkbenchPage page = dw.getActivePage(); - if (page != null) { - page.openEditor(new FileEditorInput(file), editorId, true); - } - } - } - catch (PartInitException e) { - // editor can not open for some reason - return; - } - - } - - - protected String getDefaultSystemId() { - String relativePath = "platform:/resource/" + newFilePage.getContainerFullPath().toString() + "/dummy"; //$NON-NLS-1$ //$NON-NLS-2$ - return URIHelper.getRelativeURI(generator.getGrammarURI(), relativePath); - } - - - /** - * SelectGrammarFilePage - */ - class SelectGrammarFilePage extends WizardPage { - protected SelectFileOrXMLCatalogIdPanel panel; - - SelectGrammarFilePage() { - super("SelectGrammarFilePage"); //$NON-NLS-1$ - } - - public void createControl(Composite parent) { - Composite composite = new Composite(parent, SWT.NONE); - PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IXMLWizardHelpContextIds.XML_NEWWIZARD_SELECTSOURCE_HELPID); - composite.setLayout(new GridLayout()); - composite.setLayoutData(new GridData(GridData.FILL_BOTH)); - setControl(composite); - - panel = new SelectFileOrXMLCatalogIdPanel(composite); - panel.setLayoutData(new GridData(GridData.FILL_BOTH)); - - SelectFileOrXMLCatalogIdPanel.Listener listener = new SelectFileOrXMLCatalogIdPanel.Listener() { - public void completionStateChanged() { - updateErrorMessage(); - } - }; - panel.setListener(listener); - Dialog.applyDialogFont(parent); - } - - public void setVisible(boolean visible) { - super.setVisible(visible); - if (visible) { - if (getCreateMode() == CREATE_FROM_DTD) { - setTitle(XMLWizardsMessages._UI_WIZARD_SELECT_DTD_FILE_TITLE); - setDescription(XMLWizardsMessages._UI_WIZARD_SELECT_DTD_FILE_DESC); - panel.setFilterExtensions(browseDTDFilterExtensions); - } - else { - setTitle(XMLWizardsMessages._UI_WIZARD_SELECT_XSD_FILE_TITLE); - setDescription(XMLWizardsMessages._UI_WIZARD_SELECT_XSD_FILE_DESC); - panel.setFilterExtensions(browseXSDFilterExtensions); - } - generator.setGrammarURI(null); - generator.setCMDocument(null); - cmDocumentErrorMessage = null; - } - panel.setVisibleHelper(visible); - } - - public String getURI() { - String uri = panel.getXMLCatalogURI(); - if (uri == null) { - IFile file = panel.getFile(); - if (file != null) { - uri = URIHelper.getPlatformURI(file); - } - } - return uri; - } - - public boolean isPageComplete() { - return (getURI() != null) && (getErrorMessage() == null); - } - - public String getXMLCatalogId() { - return panel.getXMLCatalogId(); - } - - public ICatalogEntry getXMLCatalogEntry() { - return panel.getXMLCatalogEntry(); - } - - public String computeErrorMessage() { - String errorMessage = null; - String uri = getURI(); - if (uri != null) { - if (!URIHelper.isReadableURI(uri, false)) { - errorMessage = XMLWizardsMessages._UI_LABEL_ERROR_CATALOG_ENTRY_INVALID; - } - } - return errorMessage; - } - - - public void updateErrorMessage() { - String errorMessage = computeErrorMessage(); - setErrorMessage(errorMessage); - setPageComplete(isPageComplete()); - } - } - - - /** - * SelectRootElementPage - */ - class SelectRootElementPage extends WizardPage implements SelectionListener { - protected Combo combo; - protected Button[] radioButton; - protected PageBook pageBook; - protected XSDOptionsPanel xsdOptionsPanel; - protected DTDOptionsPanel dtdOptionsPanel; - - - SelectRootElementPage() { - super("SelectRootElementPage"); //$NON-NLS-1$ - } - - public void createControl(Composite parent) { - // container group - Composite containerGroup = new Composite(parent, SWT.NONE); - PlatformUI.getWorkbench().getHelpSystem().setHelp(containerGroup, IXMLWizardHelpContextIds.XML_NEWWIZARD_SELECTROOTELEMENT_HELPID); - containerGroup.setLayout(new GridLayout()); - containerGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - setControl(containerGroup); - - // select root element - Label containerLabel = new Label(containerGroup, SWT.NONE); - containerLabel.setText(XMLWizardsMessages._UI_LABEL_ROOT_ELEMENT); - combo = new Combo(containerGroup, SWT.DROP_DOWN | SWT.READ_ONLY); - combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - combo.addSelectionListener(this); - - // Options - { - Group group = new Group(containerGroup, SWT.NONE); - group.setText(XMLWizardsMessages._UI_WIZARD_CONTENT_OPTIONS); - - GridLayout layout = new GridLayout(); - layout.numColumns = 1; - layout.makeColumnsEqualWidth = true; - layout.marginWidth = 0; - group.setLayout(layout); - group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - radioButton = new Button[4]; - - radioButton[0] = new Button(group, SWT.CHECK); - radioButton[0].setText(XMLWizardsMessages._UI_WIZARD_CREATE_OPTIONAL_ATTRIBUTES); - radioButton[0].setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - radioButton[0].setSelection(false); - PlatformUI.getWorkbench().getHelpSystem().setHelp(radioButton[0], IXMLWizardHelpContextIds.XML_NEWWIZARD_SELECTROOTELEMENT1_HELPID); - - radioButton[1] = new Button(group, SWT.CHECK); - radioButton[1].setText(XMLWizardsMessages._UI_WIZARD_CREATE_OPTIONAL_ELEMENTS); - radioButton[1].setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - radioButton[1].setSelection(false); - PlatformUI.getWorkbench().getHelpSystem().setHelp(radioButton[1], IXMLWizardHelpContextIds.XML_NEWWIZARD_SELECTROOTELEMENT2_HELPID); - - radioButton[2] = new Button(group, SWT.CHECK); - radioButton[2].setText(XMLWizardsMessages._UI_WIZARD_CREATE_FIRST_CHOICE); - radioButton[2].setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - radioButton[2].setSelection(true); - PlatformUI.getWorkbench().getHelpSystem().setHelp(radioButton[2], IXMLWizardHelpContextIds.XML_NEWWIZARD_SELECTROOTELEMENT3_HELPID); - - radioButton[3] = new Button(group, SWT.CHECK); - radioButton[3].setText(XMLWizardsMessages._UI_WIZARD_FILL_ELEMENTS_AND_ATTRIBUTES); - radioButton[3].setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - radioButton[3].setSelection(true); - PlatformUI.getWorkbench().getHelpSystem().setHelp(radioButton[3], IXMLWizardHelpContextIds.XML_NEWWIZARD_SELECTROOTELEMENT4_HELPID); - /* - * radioButton = new Button[2]; - * - * radioButton[0] = new Button(group, SWT.RADIO); - * radioButton[0].setText(XMLWizardsMessages.getString("_UI_WIZARD_CREATE_REQUIRED")); - * radioButton[0].setLayoutData(new - * GridData(GridData.FILL_HORIZONTAL)); - * radioButton[0].setSelection(true); - * WorkbenchHelp.setHelp(radioButton[0], - * XMLBuilderContextIds.XMLC_CREATE_REQUIRED_ONLY); - * - * radioButton[1] = new Button(group, SWT.RADIO); - * radioButton[1].setText(XMLWizardsMessages.getString("_UI_WIZARD_CREATE_OPTIONAL")); - * radioButton[1].setLayoutData(new - * GridData(GridData.FILL_HORIZONTAL)); - * WorkbenchHelp.setHelp(radioButton[1], - * XMLBuilderContextIds.XMLC_CREATE_REQUIRED_AND_OPTION); - */ - } - - // add the grammar specific generation options - // - { - pageBook = new PageBook(containerGroup, SWT.NONE); - pageBook.setLayoutData(new GridData(GridData.FILL_BOTH)); - xsdOptionsPanel = new XSDOptionsPanel(this, pageBook); - dtdOptionsPanel = new DTDOptionsPanel(this, pageBook); - pageBook.showPage(xsdOptionsPanel); - } - } - - public void widgetSelected(SelectionEvent event) { - int index = combo.getSelectionIndex(); - String rootElementName = (index != -1) ? combo.getItem(index) : null; - generator.setRootElementName(rootElementName); - } - - public void widgetDefaultSelected(SelectionEvent event) { - // do nothing - } - - public void setVisible(boolean visible) { - super.setVisible(visible); - - if (visible) { - try { - if (generator.getGrammarURI() == null) { - generator.setGrammarURI(selectGrammarFilePage.getURI()); - generator.setXMLCatalogEntry(selectGrammarFilePage.getXMLCatalogEntry()); - } - Assert.isNotNull(generator.getGrammarURI()); - - if (generator.getCMDocument() == null) { - final String[] errorInfo = new String[2]; - final CMDocument[] cmdocs = new CMDocument[1]; - Runnable r = new Runnable() { - public void run() { - cmdocs[0] = NewXMLGenerator.createCMDocument(generator.getGrammarURI(), errorInfo); - } - }; - org.eclipse.swt.custom.BusyIndicator.showWhile(Display.getCurrent(), r); - - generator.setCMDocument(cmdocs[0]); - cmDocumentErrorMessage = errorInfo[1]; - } - - combo.removeAll(); - if ((generator.getCMDocument() != null) && (cmDocumentErrorMessage == null)) { - CMNamedNodeMap nameNodeMap = generator.getCMDocument().getElements(); - Vector nameNodeVector = new Vector(); - - for (int i = 0; i < nameNodeMap.getLength(); i++) { - CMElementDeclaration cmElementDeclaration = (CMElementDeclaration) nameNodeMap.item(i); - Object value = cmElementDeclaration.getProperty("Abstract"); //$NON-NLS-1$ - if (value != Boolean.TRUE) { - nameNodeVector.add(cmElementDeclaration.getElementName()); - } - } - - Object[] nameNodeArray = nameNodeVector.toArray(); - if (nameNodeArray.length > 0) { - Arrays.sort(nameNodeArray, Collator.getInstance()); - } - - String defaultRootName = (String) (generator.getCMDocument()).getProperty("http://org.eclipse.wst/cm/properties/defaultRootName"); //$NON-NLS-1$ - int defaultRootIndex = -1; - for (int i = 0; i < nameNodeArray.length; i++) { - String elementName = (String) nameNodeArray[i]; - - combo.add(elementName); - if ((defaultRootName != null) && defaultRootName.equals(elementName)) { - defaultRootIndex = i; - } - } - - if (nameNodeArray.length > 0) { - defaultRootIndex = defaultRootIndex != -1 ? defaultRootIndex : 0; - combo.select(defaultRootIndex); - generator.setRootElementName(combo.getItem(defaultRootIndex)); - } - } - - if (generator.getGrammarURI().endsWith("xsd")) //$NON-NLS-1$ - { - pageBook.showPage(xsdOptionsPanel); - generator.setDefaultSystemId(getDefaultSystemId()); - generator.createNamespaceInfoList(); - - // Provide default namespace prefix if none - for (int i = 0; i < generator.namespaceInfoList.size(); i++) { - NamespaceInfo nsinfo = (NamespaceInfo) generator.namespaceInfoList.get(i); - if (((nsinfo.prefix == null) || (nsinfo.prefix.trim().length() == 0)) && ((nsinfo.uri != null) && (nsinfo.uri.trim().length() != 0))) { - nsinfo.prefix = getDefaultPrefix(generator.namespaceInfoList); - } - } - xsdOptionsPanel.setNamespaceInfoList(generator.namespaceInfoList); - } - else if (generator.getGrammarURI().endsWith("dtd")) //$NON-NLS-1$ - { - pageBook.showPage(dtdOptionsPanel); - dtdOptionsPanel.update(); - } - } - catch (Exception e) { - // XMLBuilderPlugin.getPlugin().getMsgLogger().writeCurrentThread(); - } - - /* - * String errorMessage = computeErrorMessage(); if - * (errorMessage == null) super.setVisible(visible); - */ - - updateErrorMessage(); - } - } - - private String getDefaultPrefix(List nsInfoList) { - String defaultPrefix = "p"; //$NON-NLS-1$ - if (nsInfoList == null) { - return defaultPrefix; - } - - Vector v = new Vector(); - for (int i = 0; i < nsInfoList.size(); i++) { - NamespaceInfo nsinfo = (NamespaceInfo) nsInfoList.get(i); - if (nsinfo.prefix != null) { - v.addElement(nsinfo.prefix); - } - } - - if (v.contains(defaultPrefix)) { - String s = defaultPrefix; - for (int j = 0; v.contains(s); j++) { - s = defaultPrefix + Integer.toString(j); - } - return s; - } - return defaultPrefix; - } - - public boolean isPageComplete() { - boolean complete = ((generator.getRootElementName() != null) && (generator.getRootElementName().length() > 0)) && (getErrorMessage() == null); - - if (complete) { - /* - * int buildPolicy = radioButton[0].getSelection() ? - * DOMContentBuilder.BUILD_ONLY_REQUIRED_CONTENT : - * DOMContentBuilder.BUILD_ALL_CONTENT; - */ - int buildPolicy = 0; - if (radioButton[0].getSelection()) { - buildPolicy = buildPolicy | DOMContentBuilder.BUILD_OPTIONAL_ATTRIBUTES; - } - if (radioButton[1].getSelection()) { - buildPolicy = buildPolicy | DOMContentBuilder.BUILD_OPTIONAL_ELEMENTS; - } - if (radioButton[2].getSelection()) { - buildPolicy = buildPolicy | DOMContentBuilder.BUILD_FIRST_CHOICE | DOMContentBuilder.BUILD_FIRST_SUBSTITUTION; - } - if (radioButton[3].getSelection()) { - buildPolicy = buildPolicy | DOMContentBuilder.BUILD_TEXT_NODES; - } - - generator.setBuildPolicy(buildPolicy); - } - - return complete; - } - - public String computeErrorMessage() { - String errorMessage = null; - - if (cmDocumentErrorMessage != null) { - errorMessage = cmDocumentErrorMessage; - } - else if ((generator.getRootElementName() == null) || (generator.getRootElementName().length() == 0)) { - errorMessage = XMLWizardsMessages._ERROR_ROOT_ELEMENT_MUST_BE_SPECIFIED; - } - - return errorMessage; - } - - - public void updateErrorMessage() { - String errorMessage = computeErrorMessage(); - if (errorMessage == null) { - if (xsdOptionsPanel.isVisible()) { - - errorMessage = xsdOptionsPanel.computeErrorMessage(); - } - else if (dtdOptionsPanel.isVisible()) { - errorMessage = dtdOptionsPanel.computeErrorMessage(); - } - } - setErrorMessage(errorMessage); - setPageComplete(isPageComplete()); - } - } - - // //////////////End SelectRootElementPage - - - - public static GridLayout createOptionsPanelLayout() { - GridLayout gridLayout = new GridLayout(); - gridLayout.marginWidth = 0; - gridLayout.horizontalSpacing = 0; - return gridLayout; - } - - - - /** - * - */ - class XSDOptionsPanel extends Composite { - protected String errorMessage = null; - protected SelectRootElementPage parentPage; - protected CommonEditNamespacesDialog editNamespaces; - private IPath currentPath = null; - - public XSDOptionsPanel(SelectRootElementPage parentPage, Composite parent) { - super(parent, SWT.NONE); - this.parentPage = parentPage; - - setLayout(createOptionsPanelLayout()); - setLayoutData(new GridData(GridData.FILL_BOTH)); - } - - private CommonEditNamespacesDialog getEditNamespaces() { - if (editNamespaces == null) { - Composite co = new Composite(this, SWT.NONE); - co.setLayout(new GridLayout()); - String tableTitle = XMLWizardsMessages._UI_LABEL_NAMESPACE_INFORMATION; - editNamespaces = new CommonEditNamespacesDialog(co, null, tableTitle, true, true); - this.layout(); - } - return editNamespaces; - } - - public void setNamespaceInfoList(List list) { - CommonEditNamespacesDialog editDialog = getEditNamespaces(); - - if (newFilePage != null) { - IPath newPath = newFilePage.getContainerFullPath(); - if (newPath != null) { - if (!newPath.equals(currentPath)) { - String resourceURI = "platform:/resource" + newPath.toString() + "/dummy"; //$NON-NLS-1$ //$NON-NLS-2$ - String resolvedPath = URIHelper.normalize(resourceURI, null, null); - resolvedPath = URIHelper.removeProtocol(resolvedPath); - - currentPath = new Path(resolvedPath); - editDialog.setResourcePath(currentPath); - } - } - } - editDialog.setNamespaceInfoList(list); - editDialog.updateErrorMessage(list); - } - - public void updateErrorMessage(List namespaceInfoList) { - NamespaceInfoErrorHelper helper = new NamespaceInfoErrorHelper(); - errorMessage = helper.computeErrorMessage(namespaceInfoList, null); - parentPage.updateErrorMessage(); - } - - - public String computeErrorMessage() { - return errorMessage; - } - } - - - /** - * - */ - public class DTDOptionsPanel extends Composite implements ModifyListener { - protected Group group; - protected Text systemIdField; - protected Text publicIdField; - protected SelectRootElementPage parentPage; - - public DTDOptionsPanel(SelectRootElementPage parentPage, Composite parent) { - super(parent, SWT.NONE); - this.parentPage = parentPage; - setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - setLayout(createOptionsPanelLayout()); - Group group = new Group(this, SWT.NONE); - group.setText(XMLWizardsMessages._UI_LABEL_DOCTYPE_INFORMATION); - - GridLayout layout = new GridLayout(); - layout.numColumns = 2; - group.setLayout(layout); - group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - Label publicIdLabel = new Label(group, SWT.NONE); - publicIdLabel.setText(XMLWizardsMessages._UI_LABEL_PUBLIC_ID); - publicIdField = new Text(group, SWT.SINGLE | SWT.BORDER); - publicIdField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - publicIdField.addModifyListener(this); - PlatformUI.getWorkbench().getHelpSystem().setHelp(publicIdField, IXMLWizardHelpContextIds.XML_NEWWIZARD_SELECTROOTELEMENT5_HELPID); - - Label systemIdLabel = new Label(group, SWT.NONE); - systemIdLabel.setText(XMLWizardsMessages._UI_LABEL_SYSTEM_ID); - systemIdField = new Text(group, SWT.SINGLE | SWT.BORDER); - systemIdField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - systemIdField.addModifyListener(this); - PlatformUI.getWorkbench().getHelpSystem().setHelp(systemIdField, IXMLWizardHelpContextIds.XML_NEWWIZARD_SELECTROOTELEMENT6_HELPID); - } - - public void update() { - String thePublicId = null; - String theSystemId = null; - ICatalogEntry xmlCatalogEntry = generator.getXMLCatalogEntry(); - - if (xmlCatalogEntry != null) { - if (xmlCatalogEntry.getEntryType() == ICatalogEntry.ENTRY_TYPE_PUBLIC) { - thePublicId = xmlCatalogEntry.getKey(); - theSystemId = xmlCatalogEntry.getAttributeValue(ICatalogEntry.ATTR_WEB_URL); - if (theSystemId == null) { - theSystemId = generator.getGrammarURI().startsWith("http:") ? generator.getGrammarURI() : URIHelper.getLastSegment(generator.getGrammarURI()); //$NON-NLS-1$ - } - } - else { - theSystemId = xmlCatalogEntry.getKey(); - } - } - else { - theSystemId = getDefaultSystemId(); - } - - publicIdField.setText(thePublicId != null ? thePublicId : ""); //$NON-NLS-1$ - systemIdField.setText(theSystemId != null ? theSystemId : ""); //$NON-NLS-1$ - } - - public void modifyText(ModifyEvent e) { - generator.setSystemId(systemIdField.getText()); - generator.setPublicId(publicIdField.getText()); - parentPage.updateErrorMessage(); - } - - public String computeErrorMessage() { - return null; - } - } - - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/XMLImportActionDelegate.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/XMLImportActionDelegate.java deleted file mode 100644 index 4b923c48ff..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/XMLImportActionDelegate.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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.wst.xml.ui.internal.wizards; - -import java.util.Iterator; -import org.eclipse.core.resources.IFile; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IActionDelegate; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; - -// TODO cs... rename this class NewXMLActionDelegate -// we need to re-add pre-validation using the validation framework API's -// since we also need to add validation to the 'New XML' case, this -// prevalidation -// function should really go into the NewWizard somewhere -// -public class XMLImportActionDelegate implements IActionDelegate { - /** - * Checks the current selection and runs the separate browser to show the - * content of the Readme file. This code shows how to launch separate - * browsers that are not VA/Base desktop parts. - * - * @param action - * the action that was performed - */ - public void run(IAction action) { - IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - ISelection selection = workbenchWindow.getSelectionService().getSelection(); - Object selectedObject = getSelection(selection); - - if ((selectedObject instanceof IFile) && (selection instanceof IStructuredSelection)) { - IFile file = (IFile) selectedObject; - IStructuredSelection structuredSelection = (IStructuredSelection) selection; - try { - NewXMLWizard.showDialog(workbenchWindow.getShell(), file, structuredSelection); - } - catch (Exception e) { - // XMLCorePlugin.getDefault().getLog().log(); - } - } - } - - /** - * unused - */ - public void selectionChanged(IAction action, ISelection selection) { - // unused - } - - // scammed from WindowUtility - // - public static Object getSelection(ISelection selection) { - if (selection == null) { - return null; - } // end of if () - - Object result = null; - if (selection instanceof IStructuredSelection) { - IStructuredSelection es = (IStructuredSelection) selection; - Iterator i = es.iterator(); - if (i.hasNext()) { - result = i.next(); - } - } - return result; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/XMLSchemaValidationChecker.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/XMLSchemaValidationChecker.java deleted file mode 100644 index e56a3d33ea..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/XMLSchemaValidationChecker.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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.wst.xml.ui.internal.wizards; - -import org.eclipse.core.resources.IFile; -import org.eclipse.wst.common.uriresolver.internal.util.URIHelper; -import org.xml.sax.ErrorHandler; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; - -public class XMLSchemaValidationChecker { - public boolean isValid(IFile ifile) { - String xsdFileName = ifile.getLocation().toString(); - return isValid(xsdFileName); - } - - /** - * Should this be implemented as a Validator and simply called as such - * with a reporter that only checks the results for severity = error? Or - * should the Xerces requirement be broken using a plug-in extension? - */ - - public boolean isValid(String xsdFileName) { - // DOMASBuilderImpl builder = new DOMASBuilderImpl(); - // DOMErrorHandler errorHandler = new DOMErrorHandler(); - // builder.setErrorHandler(errorHandler); - try { - // String uri = - URIHelper.getURIForFilePath(xsdFileName); - // ASModel model = builder.parseASURI(uri); - // if (errorHandler.hasError()) - // return false; - } - catch (Exception e) // invalid schema - { - return false; - } - - return true; - } - - // inner class - class DOMErrorHandler implements ErrorHandler { - private boolean hasError = false; - - public boolean hasError() { - return hasError; - } - - public void error(SAXParseException err) { - hasError = true; - } - - public void fatalError(SAXParseException exception) throws SAXException { - hasError = true; - } - - public void warning(SAXParseException exception) throws SAXException { - // not an error - } - } // end DOMErrorHandlerImpl - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/XMLWizard.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/XMLWizard.java deleted file mode 100644 index ffea5d4624..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/XMLWizard.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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.wst.xml.ui.internal.wizards; - -import java.net.MalformedURLException; -import java.net.URL; - -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.resource.ImageDescriptor; - -public class XMLWizard { - protected static XMLWizard instance = new XMLWizard(); - - public synchronized static XMLWizard getInstance() { - return instance; - } - - public XMLWizard() { - instance = this; - - } - - public ImageDescriptor getImageDescriptor(String name) { - try { - URL url = new URL(Platform.getBundle("org.eclipse.wst.xml.ui").getEntry("/"), name); //$NON-NLS-1$ //$NON-NLS-2$ - return ImageDescriptor.createFromURL(url); - } - catch (MalformedURLException e) { - return ImageDescriptor.getMissingImageDescriptor(); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/XMLWizardsMessages.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/XMLWizardsMessages.java deleted file mode 100644 index a1e01bbfcc..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/XMLWizardsMessages.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 - Initial API and implementation - * David Carver/STAR Standard - d_a_carver@yahoo.com - bug 192568 - **********************************************************************/ -package org.eclipse.wst.xml.ui.internal.wizards; - -import org.eclipse.osgi.util.NLS; - -/** - * Strings used by XML Wizards - * - * @plannedfor 1.0 - */ -public class XMLWizardsMessages extends NLS { - private static final String BUNDLE_NAME = "org.eclipse.wst.xml.ui.internal.wizards.wizardResource";//$NON-NLS-1$ - - public static String _UI_DIALOG_NEW_TITLE; - public static String _UI_DIALOG_TITLE_INVALID_GRAMMAR; - public static String _UI_DIALOG_MESSAGE_INVALID_GRAMMAR; - public static String _UI_WIZARD_CREATE_NEW_TITLE; - public static String _UI_RADIO_XML_FROM_DTD; - public static String _UI_RADIO_XML_FROM_SCHEMA; - public static String _UI_RADIO_XML_FROM_SCRATCH; - public static String _UI_WIZARD_CREATE_XML_HEADING; - public static String _UI_WIZARD_CREATE_XML_EXPL; - public static String _UI_WIZARD_CREATE_XML_FILE_HEADING; - public static String _UI_WIZARD_CREATE_XML_FILE_EXPL; - public static String _UI_WIZARD_SELECT_DTD_FILE_DESC; - public static String _UI_WIZARD_SELECT_DTD_FILE_TITLE; - public static String _UI_WIZARD_SELECT_XSD_FILE_DESC; - public static String _UI_WIZARD_SELECT_XSD_FILE_TITLE; - public static String _UI_WIZARD_SELECT_ROOT_HEADING; - public static String _UI_WIZARD_SELECT_ROOT_EXPL; - public static String _UI_LABEL_ROOT_ELEMENT; - public static String _UI_WARNING_TITLE_NO_ROOT_ELEMENTS; - public static String _UI_WARNING_MSG_NO_ROOT_ELEMENTS; - public static String _UI_LABEL_NO_LOCATION_HINT; - public static String _UI_WARNING_MSG_NO_LOCATION_HINT_1; - public static String _UI_WARNING_MSG_NO_LOCATION_HINT_2; - public static String _UI_WARNING_MSG_NO_LOCATION_HINT_3; - public static String _UI_WIZARD_CONTENT_OPTIONS; - public static String _UI_WIZARD_CREATE_REQUIRED;// commented out - public static String _UI_WIZARD_CREATE_OPTIONAL;// commented out - public static String _UI_WIZARD_CREATE_OPTIONAL_ATTRIBUTES; - public static String _UI_WIZARD_CREATE_OPTIONAL_ELEMENTS; - public static String _UI_WIZARD_CREATE_FIRST_CHOICE; - public static String _UI_WIZARD_FILL_ELEMENTS_AND_ATTRIBUTES; - public static String _UI_LABEL_DOCTYPE_INFORMATION; - public static String _UI_LABEL_SYSTEM_ID; - public static String _UI_LABEL_PUBLIC_ID; - public static String _UI_WARNING_URI_NOT_FOUND_COLON; - public static String _UI_INVALID_GRAMMAR_ERROR; - public static String _ERROR_BAD_FILENAME_EXTENSION; - public static String _ERROR_FILE_ALREADY_EXISTS; - public static String _ERROR_ROOT_ELEMENT_MUST_BE_SPECIFIED; - public static String _UI_LABEL_ERROR_SCHEMA_INVALID_INFO; - public static String _UI_LABEL_ERROR_DTD_INVALID_INFO; - public static String _UI_LABEL_ERROR_CATALOG_ENTRY_INVALID; - public static String _UI_LABEL_NAMESPACE_INFORMATION; - public static String Validation_Plugins_Unavailable; - public static String Validation_cannot_be_performed; - public static String ExampleProjectCreationOperation_op_desc; - public static String ExampleProjectCreationOperation_op_desc_proj; - public static String ExampleProjectCreationWizard_title; - public static String ExampleProjectCreationWizard_op_error_title; - public static String ExampleProjectCreationWizard_op_error_message; - public static String ExampleProjectCreationWizard_overwritequery_title; - public static String ExampleProjectCreationWizard_overwritequery_message; - public static String ExampleProjectCreationWizardPage_error_alreadyexists; - - public static String NewXMLTemplatesWizardPage_0; - public static String NewXMLTemplatesWizardPage_1; - public static String NewXMLTemplatesWizardPage_2; - public static String NewXMLTemplatesWizardPage_3; - public static String NewXMLTemplatesWizardPage_4; - public static String NewXMLTemplatesWizardPage_5; - public static String NewXMLTemplatesWizardPage_6; - - public static String _UI_DIALOG_XMLCATALOG_IMPORT_TITLE; - public static String _UI_DIALOG_XMLCATALOG_EXPORT_TITLE; - public static String _UI_DIALOG_XMLCATALOG_EXPORT_DESCRIPTION; - public static String _UI_DIALOG_XMLCATALOG_IMPORT_DESCRIPTION; - static { - // load message values from bundle file - NLS.initializeMessages(BUNDLE_NAME, XMLWizardsMessages.class); - } - - private XMLWizardsMessages() { - // cannot create new instance - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/wizardResource.properties b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/wizardResource.properties deleted file mode 100644 index 0bd7bacc11..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/wizardResource.properties +++ /dev/null @@ -1,99 +0,0 @@ -############################################################################### -# Copyright (c) 2001, 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 -# David Carver/STAR Standard - d_a_carver@yahoo.com - bug 192568 -############################################################################### -! Properties file for component: XML Tools - New XML Wizard -! Packaged for translation in: xml.zip - -!XMLImportActionDelegate -_UI_DIALOG_NEW_TITLE = New XML File -_UI_DIALOG_TITLE_INVALID_GRAMMAR = Invalid Grammar -_UI_DIALOG_MESSAGE_INVALID_GRAMMAR = The grammar file contains errors. If you proceed, an incorrect result file will be generated. Do you want to continue? - -!NewXMLBWizard -_UI_WIZARD_CREATE_NEW_TITLE = New XML File -_UI_RADIO_XML_FROM_DTD = Create XML file from a &DTD file -_UI_RADIO_XML_FROM_SCHEMA = Create XML file from an &XML schema file -_UI_RADIO_XML_FROM_SCRATCH = Create XML file from an XML &template -_UI_WIZARD_CREATE_XML_HEADING = Create XML File From -_UI_WIZARD_CREATE_XML_EXPL = Select how you would like to create your XML file. -_UI_WIZARD_CREATE_XML_FILE_HEADING = XML File -_UI_WIZARD_CREATE_XML_FILE_EXPL = Create a new XML file. -_UI_WIZARD_SELECT_DTD_FILE_DESC = Select the DTD file to create the XML file. -_UI_WIZARD_SELECT_DTD_FILE_TITLE = Select DTD File -_UI_WIZARD_SELECT_XSD_FILE_DESC = Select the schema file to create the XML file. -_UI_WIZARD_SELECT_XSD_FILE_TITLE = Select XML Schema File -_UI_WIZARD_SELECT_ROOT_HEADING = Select Root Element -_UI_WIZARD_SELECT_ROOT_EXPL = Select the root element of the XML file. -_UI_LABEL_ROOT_ELEMENT = Root element: -_UI_WARNING_TITLE_NO_ROOT_ELEMENTS = No Root Elements -_UI_WARNING_MSG_NO_ROOT_ELEMENTS = No root element exists since the schema provided has no global elements. -_UI_LABEL_NO_LOCATION_HINT = Unspecified Namespace Location -_UI_WARNING_MSG_NO_LOCATION_HINT_1 = You have not specified a location hint for one or more namespace entries. -_UI_WARNING_MSG_NO_LOCATION_HINT_2 = Elements from these namespaces will not be generated. This may lead to an invalid generated document. -_UI_WARNING_MSG_NO_LOCATION_HINT_3 = Click Yes to continue, Click No to go back and specify the location hints. -_UI_WIZARD_CONTENT_OPTIONS = Content options - -_UI_WIZARD_CREATE_REQUIRED = &Create required content only -_UI_WIZARD_CREATE_OPTIONAL = Create required and &optional content - -_UI_WIZARD_CREATE_OPTIONAL_ATTRIBUTES = Create optional &attributes -_UI_WIZARD_CREATE_OPTIONAL_ELEMENTS = Create optional e&lements -_UI_WIZARD_CREATE_FIRST_CHOICE = Create first choice of required &choice -_UI_WIZARD_FILL_ELEMENTS_AND_ATTRIBUTES = Fill elements and attributes with &data - -_UI_LABEL_DOCTYPE_INFORMATION = Document type information -_UI_LABEL_SYSTEM_ID = &System ID: -_UI_LABEL_PUBLIC_ID = &Public ID: - -_UI_WARNING_URI_NOT_FOUND_COLON = The specified resource cannot be located : - -!NewModelWizard -_UI_INVALID_GRAMMAR_ERROR = Invalid Grammar - -!NewModelWizard -_ERROR_BAD_FILENAME_EXTENSION = The file name must end in one of the following extensions {0}. -_ERROR_FILE_ALREADY_EXISTS = The same file already exists. -_ERROR_ROOT_ELEMENT_MUST_BE_SPECIFIED = A root element must be specified. -_UI_LABEL_ERROR_SCHEMA_INVALID_INFO = The schema file contains errors. Open it in the XML schema editor for details. -_UI_LABEL_ERROR_DTD_INVALID_INFO = The DTD file contains errors. Open it in the DTD editor for details. - -_UI_LABEL_ERROR_CATALOG_ENTRY_INVALID = The selected catalog entry specifies a URI that can not be located. - -_UI_LABEL_NAMESPACE_INFORMATION=Namespace Information - -Validation_Plugins_Unavailable=Validation Plugins Unavailable -Validation_cannot_be_performed=Validation cannot be performed because the validation plugins were disabled or not found. The generated file may be invalid. Do you wish to continue? - -!ImportXMLCatalogWizard -_UI_DIALOG_XMLCATALOG_IMPORT_TITLE = Import XML Catalog -_UI_DIALOG_XMLCATALOG_IMPORT_DESCRIPTION = Import all entries from an existing XML Catalog into the User Catalog. - -!ExportXMLCatalogWizard -_UI_DIALOG_XMLCATALOG_EXPORT_TITLE = Export Existing XML Catalog -_UI_DIALOG_XMLCATALOG_EXPORT_DESCRIPTION = Export all existing User Catalog entries. -# -# ExampleProject -ExampleProjectCreationOperation_op_desc=Creating example projects... -ExampleProjectCreationOperation_op_desc_proj=Configuring project... -ExampleProjectCreationWizard_title=New Example Project -ExampleProjectCreationWizard_op_error_title=Project Creation Failed -ExampleProjectCreationWizard_op_error_message=Project could not be created. -ExampleProjectCreationWizard_overwritequery_title=Overwrite -ExampleProjectCreationWizard_overwritequery_message=Do you want to overwrite {0}? -ExampleProjectCreationWizardPage_error_alreadyexists=Project already exists. - -NewXMLTemplatesWizardPage_0=Select XML Template -NewXMLTemplatesWizardPage_1=Select a template as initial content in the XML page. -NewXMLTemplatesWizardPage_2=Name -NewXMLTemplatesWizardPage_3=Description -NewXMLTemplatesWizardPage_4=Use XML Template -NewXMLTemplatesWizardPage_5=Preview: -NewXMLTemplatesWizardPage_6=Templates are 'New XML' templates found in the <a>XML Templates</a> preference page. diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/StructuredTextViewerConfigurationXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/StructuredTextViewerConfigurationXML.java deleted file mode 100644 index b3dd5a7c07..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/StructuredTextViewerConfigurationXML.java +++ /dev/null @@ -1,224 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Vector; - -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Preferences; -import org.eclipse.jface.text.IAutoEditStrategy; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.text.formatter.IContentFormatter; -import org.eclipse.jface.text.formatter.MultiPassContentFormatter; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.wst.sse.core.text.IStructuredPartitions; -import org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration; -import org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames; -import org.eclipse.wst.xml.core.internal.provisional.contenttype.ContentTypeIdForXML; -import org.eclipse.wst.xml.core.internal.text.rules.StructuredTextPartitionerForXML; -import org.eclipse.wst.xml.core.text.IXMLPartitions; -import org.eclipse.wst.xml.ui.internal.XMLFormattingStrategy; -import org.eclipse.wst.xml.ui.internal.autoedit.AutoEditStrategyForTabs; -import org.eclipse.wst.xml.ui.internal.contentassist.NoRegionContentAssistProcessor; -import org.eclipse.wst.xml.ui.internal.contentassist.XMLContentAssistProcessor; -import org.eclipse.wst.xml.ui.internal.contentoutline.JFaceNodeLabelProvider; -import org.eclipse.wst.xml.ui.internal.style.LineStyleProviderForXML; -import org.w3c.dom.Node; - -/** - * Configuration for a source viewer which shows XML content. - * <p> - * Clients can subclass and override just those methods which must be specific - * to their needs. - * </p> - * - * @see org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration - * @since 1.0 - */ -public class StructuredTextViewerConfigurationXML extends StructuredTextViewerConfiguration { - /* - * One instance per configuration because not sourceviewer-specific and - * it's a String array - */ - private String[] fConfiguredContentTypes; - /* - * One instance per configuration - */ - private LineStyleProvider fLineStyleProviderForXML; - private ILabelProvider fStatusLineLabelProvider; - - /** - * Create new instance of StructuredTextViewerConfigurationXML - */ - public StructuredTextViewerConfigurationXML() { - // Must have empty constructor to createExecutableExtension - super(); - } - - public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) { - List allStrategies = new ArrayList(0); - - IAutoEditStrategy[] superStrategies = super.getAutoEditStrategies(sourceViewer, contentType); - for (int i = 0; i < superStrategies.length; i++) { - allStrategies.add(superStrategies[i]); - } - - // be sure this is last, so it can modify any results form previous - // commands that might on on same partiion type. - // add auto edit strategy that handles when tab key is pressed - allStrategies.add(new AutoEditStrategyForTabs()); - - return (IAutoEditStrategy[]) allStrategies.toArray(new IAutoEditStrategy[allStrategies.size()]); - } - - public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { - - if (fConfiguredContentTypes == null) { - String[] xmlTypes = StructuredTextPartitionerForXML.getConfiguredContentTypes(); - fConfiguredContentTypes = new String[xmlTypes.length + 2]; - fConfiguredContentTypes[0] = IStructuredPartitions.DEFAULT_PARTITION; - fConfiguredContentTypes[1] = IStructuredPartitions.UNKNOWN_PARTITION; - int index = 0; - System.arraycopy(xmlTypes, 0, fConfiguredContentTypes, index += 2, xmlTypes.length); - } - return fConfiguredContentTypes; - } - - protected IContentAssistProcessor[] getContentAssistProcessors(ISourceViewer sourceViewer, String partitionType) { - IContentAssistProcessor[] processors = null; - - if ((partitionType == IStructuredPartitions.DEFAULT_PARTITION) || (partitionType == IXMLPartitions.XML_DEFAULT)) { - processors = new IContentAssistProcessor[]{new XMLContentAssistProcessor()}; - } - else if (partitionType == IStructuredPartitions.UNKNOWN_PARTITION) { - processors = new IContentAssistProcessor[]{new NoRegionContentAssistProcessor()}; - } - - return processors; - } - - public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) { - IContentFormatter formatter = super.getContentFormatter(sourceViewer); - // super was unable to create a formatter, probably because - // sourceViewer does not have document set yet, so just create a - // generic one - if (!(formatter instanceof MultiPassContentFormatter)) - formatter = new MultiPassContentFormatter(getConfiguredDocumentPartitioning(sourceViewer), IXMLPartitions.XML_DEFAULT); - ((MultiPassContentFormatter) formatter).setMasterStrategy(new XMLFormattingStrategy()); -// ((MultiPassContentFormatter) formatter).setMasterStrategy(new StructuredFormattingStrategy(new FormatProcessorXML())); - - return formatter; - } - - public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) { - Vector vector = new Vector(); - - // prefix[0] is either '\t' or ' ' x tabWidth, depending on preference - Preferences preferences = XMLCorePlugin.getDefault().getPluginPreferences(); - int indentationWidth = preferences.getInt(XMLCorePreferenceNames.INDENTATION_SIZE); - String indentCharPref = preferences.getString(XMLCorePreferenceNames.INDENTATION_CHAR); - boolean useSpaces = XMLCorePreferenceNames.SPACE.equals(indentCharPref); - - for (int i = 0; i <= indentationWidth; i++) { - StringBuffer prefix = new StringBuffer(); - boolean appendTab = false; - - if (useSpaces) { - for (int j = 0; j + i < indentationWidth; j++) { - prefix.append(' '); - } - - if (i != 0) { - appendTab = true; - } - } - else { - for (int j = 0; j < i; j++) { - prefix.append(' '); - } - - if (i != indentationWidth) { - appendTab = true; - } - } - - if (appendTab) { - prefix.append('\t'); - vector.add(prefix.toString()); - // remove the tab so that indentation - tab is also an indent - // prefix - prefix.deleteCharAt(prefix.length() - 1); - } - vector.add(prefix.toString()); - } - - vector.add(""); //$NON-NLS-1$ - - return (String[]) vector.toArray(new String[vector.size()]); - } - - public LineStyleProvider[] getLineStyleProviders(ISourceViewer sourceViewer, String partitionType) { - LineStyleProvider[] providers = null; - - if ((partitionType == IXMLPartitions.XML_DEFAULT) || (partitionType == IXMLPartitions.XML_CDATA) || (partitionType == IXMLPartitions.XML_COMMENT) || (partitionType == IXMLPartitions.XML_DECLARATION) || (partitionType == IXMLPartitions.XML_PI)) { - providers = new LineStyleProvider[]{getLineStyleProviderForXML()}; - } - - return providers; - } - - private LineStyleProvider getLineStyleProviderForXML() { - if (fLineStyleProviderForXML == null) { - fLineStyleProviderForXML = new LineStyleProviderForXML(); - } - return fLineStyleProviderForXML; - } - - public ILabelProvider getStatusLineLabelProvider(ISourceViewer sourceViewer) { - if (fStatusLineLabelProvider == null) { - fStatusLineLabelProvider = new JFaceNodeLabelProvider() { - public String getText(Object element) { - if (element == null) - return null; - - StringBuffer s = new StringBuffer(); - Node node = (Node) element; - while (node != null) { - if (node.getNodeType() != Node.DOCUMENT_NODE) { - s.insert(0, super.getText(node)); - } - node = node.getParentNode(); - if (node != null && node.getNodeType() != Node.DOCUMENT_NODE) { - s.insert(0, IPath.SEPARATOR); - } - } - return s.toString(); - } - - }; - } - return fStatusLineLabelProvider; - } - - protected Map getHyperlinkDetectorTargets(ISourceViewer sourceViewer) { - Map targets = super.getHyperlinkDetectorTargets(sourceViewer); - targets.put(ContentTypeIdForXML.ContentTypeID_XML, null); - return targets; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/DOMObserver.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/DOMObserver.java deleted file mode 100644 index 4976050264..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/DOMObserver.java +++ /dev/null @@ -1,192 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal; - - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter; -import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.ui.internal.SSEUIMessages; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl.CMDocumentLoader; -import org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl.InferredGrammarBuildingCMDocumentLoader; -import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -/** - * This class is used to observe changes in the DOM and perform - * occasional'scans' to deduce information. We use a delay timer mechanism to - * ensure scans are made every couple of seconds to avoid performance - * problems. Currently this class is used to keep track of referenced grammar - * uri's within the document ensure that they are loaded by the - * CMDocumentManager. We might want to generalize this class to perform other - * suplimental information gathering that is suitable for 'time delayed' - * computation (error hints etc.). - */ -// TODO: Where should this class go? -public class DOMObserver { - - - // An abstract adapter that ensures that the children of a new Node are - // also adapted - // - abstract class DocumentAdapter implements INodeAdapter { - public DocumentAdapter() { - } - - public void connect(Document document) { - ((INodeNotifier) document).addAdapter(this); - adapt(document.getDocumentElement()); - } - - public void dicconnect(Document document) { - ((INodeNotifier) document).removeAdapter(this); - } - - public void adapt(Element element) { - if (element != null) { - if (((INodeNotifier) element).getExistingAdapter(this) == null) { - ((INodeNotifier) element).addAdapter(this); - - for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) { - if (child.getNodeType() == Node.ELEMENT_NODE) { - adapt((Element) child); - } - } - } - } - } - - public boolean isAdapterForType(Object type) { - return type == this; - } - - abstract public void notifyChanged(INodeNotifier notifier, int eventType, Object feature, Object oldValue, Object newValue, int index); - } - - /** - * This class listens to the changes in the CMDocument and triggers a - * CMDocument load - */ - class MyDocumentAdapter extends DocumentAdapter { - - public void notifyChanged(INodeNotifier notifier, int eventType, Object feature, Object oldValue, Object newValue, int index) { - switch (eventType) { - case INodeNotifier.ADD : { - if (newValue instanceof Element) { - // System.out.println("ADD (to " + - // ((Node)notifier).getNodeName() + ") " + - // ((Element)newValue).getNodeName() + " old " + - // oldValue); - adapt((Element) newValue); - } - break; - } - // case INodeNotifier.REMOVE: - case INodeNotifier.CHANGE : - case INodeNotifier.STRUCTURE_CHANGED : - case INodeNotifier.CONTENT_CHANGED : { - Node node = (Node) notifier; - if (node.getNodeType() == Node.ELEMENT_NODE) { - switch (eventType) { - case INodeNotifier.CHANGE : - case INodeNotifier.STRUCTURE_CHANGED : { - // structure change - invokeDelayedCMDocumentLoad(); - break; - } - case INodeNotifier.CONTENT_CHANGED : { - // some content changed - break; - } - } - } - else if (node.getNodeType() == Node.DOCUMENT_NODE) { - invokeDelayedCMDocumentLoad(); - } - break; - } - } - } - } - - /** - * Intentionally left visible to the user - */ - class TimerJob extends Job { - public TimerJob() { - super(SSEUIMessages.LoadingReferencedGrammars); - } - - public IStatus run(IProgressMonitor monitor) { - monitor.beginTask("", IProgressMonitor.UNKNOWN); //$NON-NLS-1$ - Thread.currentThread().setPriority(Thread.MIN_PRIORITY); - invokeCMDocumentLoad(); - monitor.done(); - return Status.OK_STATUS; - } - } - - private Job timer = new TimerJob(); - protected Document fDocument; - protected boolean isGrammarInferenceEnabled; - - public DOMObserver(IStructuredModel model) { - fDocument = (model instanceof IDOMModel) ? ((IDOMModel) model).getDocument() : null; - - if (fDocument != null) { - // here we create and init an adapter that will listen to - // changes to the document and contained elements - MyDocumentAdapter adapter = new MyDocumentAdapter(); - adapter.connect(fDocument); - - ModelQuery modelQuery = ModelQueryUtil.getModelQuery(fDocument); - if ((modelQuery != null) && (modelQuery.getCMDocumentManager() != null)) { - CMDocumentManager cmDocumentManager = modelQuery.getCMDocumentManager(); - cmDocumentManager.setPropertyEnabled(CMDocumentManager.PROPERTY_AUTO_LOAD, false); - } - } - } - - public void init() { - // CS: we seem to expose an XSD initialization problem when we do this - // immediately - // very nasty... I need to revist this problem with Ed Merks - // - timer.schedule(); - } - - public void invokeCMDocumentLoad() { - ModelQuery modelQuery = ModelQueryUtil.getModelQuery(fDocument); - if ((modelQuery != null) && (modelQuery.getCMDocumentManager() != null)) { - CMDocumentLoader loader = isGrammarInferenceEnabled ? new InferredGrammarBuildingCMDocumentLoader(fDocument, modelQuery) : new CMDocumentLoader(fDocument, modelQuery); - loader.loadCMDocuments(); - } - } - - public void invokeDelayedCMDocumentLoad() { - timer.schedule(2000); - } - - public void setGrammarInferenceEnabled(boolean isEnabled) { - isGrammarInferenceEnabled = isEnabled; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/Logger.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/Logger.java deleted file mode 100644 index b98e7ab1d2..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/Logger.java +++ /dev/null @@ -1,163 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal; - - - -import com.ibm.icu.util.StringTokenizer; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; -import org.osgi.framework.Bundle; - -/** - * Small convenience class to log messages to plugin's log file and also, if - * desired, the console. This class should only be used by classes in this - * plugin. Other plugins should make their own copy, with appropriate ID. - */ -public class Logger { - private static final String PLUGIN_ID = "org.eclipse.wst.xml.ui"; //$NON-NLS-1$ - - public static final int ERROR = IStatus.ERROR; // 4 - public static final int ERROR_DEBUG = 200 + ERROR; - public static final int INFO = IStatus.INFO; // 1 - public static final int INFO_DEBUG = 200 + INFO; - - public static final int OK = IStatus.OK; // 0 - - public static final int OK_DEBUG = 200 + OK; - - private static final String TRACEFILTER_LOCATION = "/debug/tracefilter"; //$NON-NLS-1$ - public static final int WARNING = IStatus.WARNING; // 2 - public static final int WARNING_DEBUG = 200 + WARNING; - - /** - * Adds message to log. - * - * @param level - * severity level of the message (OK, INFO, WARNING, ERROR, - * OK_DEBUG, INFO_DEBUG, WARNING_DEBUG, ERROR_DEBUG) - * @param message - * text to add to the log - * @param exception - * exception thrown - */ - protected static void _log(int level, String message, Throwable exception) { - if ((level == OK_DEBUG) || (level == INFO_DEBUG) || (level == WARNING_DEBUG) || (level == ERROR_DEBUG)) { - if (!isDebugging()) { - return; - } - } - - int severity = IStatus.OK; - switch (level) { - case INFO_DEBUG : - case INFO : - severity = IStatus.INFO; - break; - case WARNING_DEBUG : - case WARNING : - severity = IStatus.WARNING; - break; - case ERROR_DEBUG : - case ERROR : - severity = IStatus.ERROR; - } - message = (message != null) ? message : "null"; //$NON-NLS-1$ - Status statusObj = new Status(severity, PLUGIN_ID, severity, message, exception); - Bundle bundle = Platform.getBundle(PLUGIN_ID); - if (bundle != null) { - Platform.getLog(bundle).log(statusObj); - } - } - - /** - * Prints message to log if category matches /debug/tracefilter option. - * - * @param message - * text to print - * @param category - * category of the message, to be compared with - * /debug/tracefilter - */ - protected static void _trace(String category, String message, Throwable exception) { - if (isTracing(category)) { - message = (message != null) ? message : "null"; //$NON-NLS-1$ - Status statusObj = new Status(IStatus.OK, PLUGIN_ID, IStatus.OK, message, exception); - Bundle bundle = Platform.getBundle(PLUGIN_ID); - if (bundle != null) { - Platform.getLog(bundle).log(statusObj); - } - } - } - - /** - * @return true if the platform is debugging - */ - public static boolean isDebugging() { - return Platform.inDebugMode(); - } - - /** - * Determines if currently tracing a category - * - * @param category - * @return true if tracing category, false otherwise - */ - public static boolean isTracing(String category) { - if (!isDebugging()) { - return false; - } - - String traceFilter = Platform.getDebugOption(PLUGIN_ID + TRACEFILTER_LOCATION); - if (traceFilter != null) { - StringTokenizer tokenizer = new StringTokenizer(traceFilter, ","); //$NON-NLS-1$ - while (tokenizer.hasMoreTokens()) { - String cat = tokenizer.nextToken().trim(); - if (category.equals(cat)) { - return true; - } - } - } - return false; - } - - public static void log(int level, String message) { - _log(level, message, null); - } - - public static void log(int level, String message, Throwable exception) { - _log(level, message, exception); - } - - public static void logException(String message, Throwable exception) { - _log(ERROR, message, exception); - } - - public static void logException(Throwable exception) { - _log(ERROR, exception.getMessage(), exception); - } - - public static void trace(String category, String message) { - _trace(category, message, null); - } - - public static void traceException(String category, String message, Throwable exception) { - _trace(category, message, exception); - } - - public static void traceException(String category, Throwable exception) { - _trace(category, exception.getMessage(), exception); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLFormattingStrategy.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLFormattingStrategy.java deleted file mode 100644 index 39432efc78..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLFormattingStrategy.java +++ /dev/null @@ -1,105 +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.wst.xml.ui.internal; - -import java.util.LinkedList; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.TypedPosition; -import org.eclipse.jface.text.formatter.ContextBasedFormattingStrategy; -import org.eclipse.jface.text.formatter.FormattingContextProperties; -import org.eclipse.jface.text.formatter.IFormattingContext; -import org.eclipse.jface.text.formatter.IFormattingStrategyExtension; -import org.eclipse.text.edits.TextEdit; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; -import org.eclipse.wst.sse.ui.internal.Logger; -import org.eclipse.wst.xml.core.internal.formatter.DefaultXMLPartitionFormatter; - -public class XMLFormattingStrategy extends ContextBasedFormattingStrategy implements IFormattingStrategyExtension { - - /** Documents to be formatted by this strategy */ - private final LinkedList fDocuments = new LinkedList(); - /** Partitions to be formatted by this strategy */ - private final LinkedList fPartitions = new LinkedList(); - private IRegion fRegion; - private DefaultXMLPartitionFormatter formatter = new DefaultXMLPartitionFormatter(); - - /** - * @param formatProcessor - */ - public XMLFormattingStrategy() { - super(); - } - - /* - * @see org.eclipse.jface.text.formatter.ContextBasedFormattingStrategy#format() - */ - public void format() { - super.format(); - - final IDocument document = (IDocument) fDocuments.removeFirst(); - final TypedPosition partition = (TypedPosition) fPartitions.removeFirst(); - - if (document != null && partition != null && fRegion != null) { - try { - if (document instanceof IStructuredDocument) { - IStructuredModel model = StructuredModelManager.getModelManager().getModelForEdit((IStructuredDocument) document); - if (model != null) { - try { - TextEdit edit = formatter.format(model, fRegion.getOffset(), fRegion.getLength()); - if (edit != null) { - try { - model.aboutToChangeModel(); - edit.apply(document); - } - finally { - model.changedModel(); - } - } - } - finally { - model.releaseFromEdit(); - } - } - } - } - catch (BadLocationException e) { - // log for now, unless we find reason not to - Logger.log(Logger.INFO, e.getMessage()); - } - } - } - - /* - * @see org.eclipse.jface.text.formatter.ContextBasedFormattingStrategy#formatterStarts(org.eclipse.jface.text.formatter.IFormattingContext) - */ - public void formatterStarts(final IFormattingContext context) { - super.formatterStarts(context); - - fPartitions.addLast(context.getProperty(FormattingContextProperties.CONTEXT_PARTITION)); - fDocuments.addLast(context.getProperty(FormattingContextProperties.CONTEXT_MEDIUM)); - fRegion = (IRegion) context.getProperty(FormattingContextProperties.CONTEXT_REGION); - } - - /* - * @see org.eclipse.jface.text.formatter.ContextBasedFormattingStrategy#formatterStops() - */ - public void formatterStops() { - super.formatterStops(); - - fPartitions.clear(); - fDocuments.clear(); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java deleted file mode 100644 index 3150a14bfc..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java +++ /dev/null @@ -1,326 +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 - Initial API and implementation - * Benjamin Muskalla, b.muskalla@gmx.net - [158660] character entities should have their own syntax highlighting preference - * David Carver - STAR - [205989] - [validation] validate XML after XInclude resolution - **********************************************************************/ -package org.eclipse.wst.xml.ui.internal; - -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -import org.eclipse.osgi.util.NLS; - -/** - * Strings used by XML UI - * - * @plannedfor 1.0 - */ -public class XMLUIMessages extends NLS { - private static final String BUNDLE_NAME = "org.eclipse.wst.xml.ui.internal.XMLUIPluginResources";//$NON-NLS-1$ - private static ResourceBundle fResourceBundle; - - public static String Sample_XML_doc; - public static String Comment_Delimiters_UI_; - public static String Comment_Content_UI_; - public static String Tag_Delimiters_UI_; - public static String Tag_Names_UI_; - public static String Attribute_Names_UI_; - public static String Attribute_Values_UI_; - public static String Declaration_Delimiters_UI_; - public static String Content_UI_; - public static String CDATA_Delimiters_UI_; - public static String CDATA_Content_UI_; - public static String Processing_Instruction_Del_UI_; - public static String Processing_Instruction_Con_UI__UI_; - public static String DOCTYPE_Name_UI_; - public static String DOCTYPE_SYSTEM_PUBLIC_Keyw_UI_; - public static String DOCTYPE_Public_Reference_UI_; - public static String DOCTYPE_System_Reference_UI_; - public static String Entity_Reference_UI_; - public static String DELETE; - public static String ADD_PROCESSING_INSTRUCTION; - public static String _UI_MENU_ADD_AFTER; - public static String _UI_MENU_ADD_ATTRIBUTE; - public static String _UI_MENU_ADD_BEFORE; - public static String _UI_MENU_ADD_CHILD; - public static String _UI_MENU_REMOVE; - public static String _UI_MENU_REPLACE_WITH; - public static String _UI_MENU_EDIT_DOCTYPE; - public static String _UI_LABEL_UNDO_REPLACE_DESCRIPTION; - public static String _UI_LABEL_EDIT_DOCTYPE; - public static String _UI_INFO_EXPAND_ALL; - public static String _UI_INFO_COLLAPSE_ALL; - public static String _UI_MENU_ADD_DTD_INFORMATION; - public static String _UI_MENU_ADD_SCHEMA_INFORMATION; - public static String _UI_MENU_EDIT_PROCESSING_INSTRUCTION; - public static String _UI_MENU_EDIT_NAMESPACES; - public static String _UI_MENU_ADD_DTD_INFORMATION_TITLE; - public static String _UI_MENU_EDIT_PROCESSING_INSTRUCTION_TITLE; - public static String _UI_MENU_EDIT_SCHEMA_INFORMATION_TITLE; - public static String _UI_MENU_NEW_ATTRIBUTE; - public static String _UI_MENU_NEW_ATTRIBUTE_TITLE; - public static String _UI_MENU_EDIT_ATTRIBUTE; - public static String _UI_MENU_EDIT_ATTRIBUTE_TITLE; - public static String _UI_MENU_NEW_ELEMENT; - public static String _UI_MENU_NEW_ELEMENT_TITLE; - public static String _UI_MENU_RENAME; - public static String _UI_MENU_RENAME_TITLE; - public static String _UI_LABEL_ELEMENT_NAME; - public static String _UI_MENU_ADD_COMMENT; - public static String _UI_MENU_ADD_PROCESSING_INSTRUCTION; - public static String _UI_MENU_ADD_CDATA_SECTION; - public static String _UI_MENU_ADD_PCDATA; - public static String _UI_MENU_COMMENT; - public static String _UI_MENU_PROCESSING_INSTRUCTION; - public static String _UI_MENU_CDATA_SECTION; - public static String _UI_MENU_PCDATA; - public static String _UI_MENU_ADD; - public static String _UI_COMMENT_VALUE; - public static String _UI_PI_TARGET_VALUE; - public static String _UI_PI_DATA_VALUE; - public static String _UI_LABEL_ROOT_ELEMENT_VALUE; - public static String _UI_LABEL_TARGET_COLON; - public static String _UI_LABEL_DATA_COLON; - public static String _UI_LABEL_ROOT_ELEMENT_NAME_COLON; - public static String _UI_LABEL_PUBLIC_ID_COLON; - public static String _UI_LABEL_SYSTEM_ID_COLON; - public static String _UI_LABEL_BROWSE; - public static String _UI_LABEL_SELECT_XML_CATALOG_ENTRY; - public static String _UI_LABEL_SPECIFY_SYSTEM_ID; - public static String _UI_LABEL_SELECT_FILE; - public static String _UI_LABEL_KEY; - public static String _UI_LABEL_URI; - public static String _UI_LABEL_XML_CATALOG_COLON; - public static String _UI_LABEL_NAMESPACE_NAME; - public static String _UI_LABEL_LOCATION_HINT; - public static String _UI_LABEL_PREFIX; - public static String _UI_LABEL_NAMESPACE_NAME_COLON; - public static String _UI_LABEL_LOCATION_HINT_COLON; - public static String _UI_LABEL_PREFIX_COLON; - public static String _UI_NO_NAMESPACE_NAME; - public static String _UI_NO_PREFIX; - public static String _UI_LABEL_XML_SCHEMA_INFORMATION; - public static String _UI_LABEL_NAME_COLON; - public static String _UI_LABEL_VALUE_COLON; - public static String _UI_BUTTON_DELETE; - public static String _UI_BUTTON_NEW; - public static String _UI_BUTTON_EDIT; - public static String _UI_LABEL_NEW_NAMESPACE_INFORMATION; - public static String _UI_RADIO_BUTTON_SELECT_FROM_WORKSPACE; - public static String _UI_RADIO_BUTTON_SELECT_FROM_CATALOG; - public static String _UI_WARNING_MORE_THAN_ONE_NS_WITH_NAME; - public static String _UI_WARNING_MORE_THAN_ONE_NS_WITHOUT_NAME; - public static String _UI_WARNING_MORE_THAN_ONE_NS_WITHOUT_PREFIX; - public static String _UI_WARNING_MORE_THAN_ONE_NS_WITH_PREFIX; - public static String _UI_WARNING_SCHEMA_CAN_NOT_BE_LOCATED; - public static String _UI_WARNING_LOCATION_HINT_NOT_SPECIFIED; - public static String _UI_WARNING_NAMESPACE_NAME_NOT_SPECIFIED; - public static String _UI_WARNING_PREFIX_NOT_SPECIFIED; - public static String _UI_WARNING_ROOT_ELEMENT_MUST_BE_SPECIFIED; - public static String _UI_WARNING_SYSTEM_ID_MUST_BE_SPECIFIED; - public static String _UI_INVALID_NAME; - public static String _UI_ENTER_REQ_PREFIX_AND_NAMESPACE; - public static String _UI_SELECT_REGISTERED_NAMESPACES; - public static String _UI_SPECIFY_NEW_NAMESPACE; - public static String _UI_SELECT_NAMESPACE_TO_ADD; - public static String _UI_ADD_NAMESPACE_DECLARATIONS; - public static String _UI_NAMESPACE_DECLARATIONS; - public static String _UI_TARGET_NAMESPACE; - public static String _ERROR_XML_ATTRIBUTE_ALREADY_EXISTS; - public static String error_message_goes_here; - public static String SurroundWithNewElementQuickAssistProposal_0; - public static String SurroundWithNewElementQuickAssistProposal_1; - public static String RenameInFileQuickAssistProposal_0; - public static String RenameInFileQuickAssistProposal_1; - public static String InsertRequiredAttrsQuickAssistProposal_0; - public static String InsertRequiredAttrsQuickAssistProposal_1; - public static String EncodingSettings_0; - public static String EncodingSettings_1; - public static String DragNodeCommand_0; - public static String DragNodeCommand_1; - public static String CommonEditNamespacesDialog_0; - public static String JFaceNodeAdapter_1; - public static String QuickFixProcessorXML_0; - public static String QuickFixProcessorXML_1; - public static String QuickFixProcessorXML_2; - public static String QuickFixProcessorXML_3; - public static String QuickFixProcessorXML_4; - public static String QuickFixProcessorXML_5; - public static String QuickFixProcessorXML_6; - public static String QuickFixProcessorXML_7; - public static String QuickFixProcessorXML_8; - public static String QuickFixProcessorXML_9; - public static String QuickFixProcessorXML_10; - public static String QuickFixProcessorXML_11; - public static String QuickFixProcessorXML_12; - public static String QuickFixProcessorXML_13; - public static String QuickFixProcessorXML_14; - public static String QuickFixProcessorXML_15; - public static String XMLPropertySourceAdapter_0; - public static String WorkbenchDefaultEncodingSettings_0; - public static String refreshoutline_0; - public static String Creating_files_encoding; - public static String End_tag_has_attributes; - public static String Attribute__is_missing_a_value; - public static String Attribute__has_no_value; - public static String Missing_end_tag_; - public static String Missing_start_tag_; - public static String ReconcileStepForMarkup_0; - public static String ReconcileStepForMarkup_1; - public static String ReconcileStepForMarkup_2; - public static String ReconcileStepForMarkup_3; - public static String ReconcileStepForMarkup_4; - public static String ReconcileStepForMarkup_5; - public static String ReconcileStepForMarkup_6; - public static String End_with_; - public static String SEVERE_internal_error_occu_UI_; - public static String No_known_attribute__UI_; - public static String Content_Assist_not_availab_UI_; - public static String Element__is_unknown; - public static String Comment__; - public static String Close_with__; - public static String End_with__; - public static String Close_with___; - public static String Close_with____; - public static String _Has_no_available_child; - public static String No_known_child_tag; - public static String __Has_no_known_child; - public static String No_known_child_tag_names; - public static String The_document_element__; - public static String No_definition_for_in; - public static String No_definition_for; - public static String No_content_model_for; - public static String No_content_model_found_UI_; - public static String Cleanup_UI_; - public static String Compress_empty_element_tags_UI_; - public static String Insert_required_attributes_UI_; - public static String Insert_missing_tags_UI_; - public static String Quote_attribute_values_UI_; - public static String Format_source_UI_; - public static String Convert_EOL_codes_UI_; - public static String EOL_Windows_UI; - public static String EOL_Unix_UI; - public static String EOL_Mac_UI; - public static String Creating_files; - public static String Encoding_desc; - public static String Encoding; - public static String Creating_or_saving_files; - public static String End_of_line_code_desc; - public static String End_of_line_code; - public static String EOL_Windows; - public static String EOL_Unix; - public static String EOL_Mac; - public static String EOL_NoTranslation; - public static String XMLFilesPreferencePage_ExtensionLabel; - public static String XMLFilesPreferencePage_ExtensionError; - public static String Content_assist_UI_; - public static String Automatically_make_suggest_UI_; - public static String Prompt_when_these_characte_UI_; - public static String Formatting_UI_; - public static String Line_width__UI_; - public static String Split_multiple_attributes; - public static String Align_final_bracket; - public static String Preserve_PCDATA_Content; - public static String Space_before_empty_close_tag; - public static String Indent_using_tabs; - public static String Indent_using_spaces; - public static String Indentation_size; - public static String Indentation_size_tip; - public static String Clear_all_blank_lines_UI_; - public static String Grammar_Constraints; - public static String Use_inferred_grammar_in_absence_of; - public static String Suggestion_Strategy; - public static String Suggestion_Strategy_Lax; - public static String Suggestion_Strategy_Strict; - public static String Element____1; - public static String Content_Model____2; - public static String Attribute____3; - public static String Data_Type____4; - public static String Enumerated_Values____5; - public static String SourceMenu_label; - public static String Comment_label; // Resource bundle - public static String Comment_tooltip; // Resource bundle - public static String Comment_description; // Resource bundle - public static String Uncomment_label; // Resource bundle - public static String Uncomment_tooltip; // Resource bundle - public static String Uncomment_description; // Resource bundle - public static String ToggleComment_label; // Resource bundle - public static String ToggleComment_tooltip; // Resource bundle - public static String ToggleComment_description; // Resource bundle - public static String AddBlockComment_label; // Resource bundle - public static String AddBlockComment_tooltip; // Resource bundle - public static String AddBlockComment_description; // Resource bundle - public static String RemoveBlockComment_label; // Resource bundle - public static String RemoveBlockComment_tooltip; // Resource bundle - public static String RemoveBlockComment_description; // Resource bundle - public static String CleanupDocument_label; // Resource bundle - public static String CleanupDocument_tooltip; // Resource bundle - public static String CleanupDocument_description; // Resource bundle - public static String FindOccurrences_label; // Resource bundle - public static String OpenFileFromSource_label; // Resource bundle - public static String OpenFileFromSource_tooltip; // Resource bundle - public static String OpenFileFromSource_description; // Resource bundle - public static String XMLContentOutlineConfiguration_0; - public static String XMLTyping_Auto_Complete; - public static String XMLTyping_Auto_Remove; - public static String XMLTyping_Complete_Comments; - public static String XMLTyping_Complete_End_Tags; - public static String XMLTyping_Remove_End_Tags; - public static String StructureSelectEnclosing_label; - public static String StructureSelectEnclosing_tooltip; - public static String StructureSelectEnclosing_description; - public static String StructureSelectNext_label; - public static String StructureSelectNext_tooltip; - public static String StructureSelectNext_description; - public static String StructureSelectPrevious_label; - public static String StructureSelectPrevious_tooltip; - public static String StructureSelectPrevious_description; - public static String MESSAGE_XML_VALIDATION_MESSAGE_UI_; - public static String Indicate_no_grammar_specified; - public static String Indicate_no_grammar_specified_severities; - public static String Validating_files; - public static String SyntaxColoringPage_0; - public static String SyntaxColoringPage_2; - public static String SyntaxColoringPage_3; - public static String SyntaxColoringPage_4; - public static String SyntaxColoringPage_5; - public static String SyntaxColoringPage_6; - public static String EmptyFilePreferencePage_0; - public static String _UI_STRUCTURED_TEXT_EDITOR_PREFS_LINK; - public static String gotoMatchingTag_label; - public static String gotoMatchingTag_description; - public static String nextSibling_label; - public static String nextSibling_description; - public static String previousSibling_label; - public static String previousSibling_description; - public static String Use_XInclude; - public static String Open; - public static String _UI_BUTTON_SORT; - - static { - // load message values from bundle file - NLS.initializeMessages(BUNDLE_NAME, XMLUIMessages.class); - } - - private XMLUIMessages() { - // cannot create new instance - } - - public static ResourceBundle getResourceBundle() { - try { - if (fResourceBundle == null) { - fResourceBundle = ResourceBundle.getBundle(BUNDLE_NAME); - } - } - catch (MissingResourceException x) { - fResourceBundle = null; - } - return fResourceBundle; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPlugin.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPlugin.java deleted file mode 100644 index fe8f1715b6..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPlugin.java +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal; - -import java.io.IOException; - -import org.eclipse.jface.text.templates.ContextTypeRegistry; -import org.eclipse.jface.text.templates.persistence.TemplateStore; -import org.eclipse.swt.graphics.Image; -import org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry; -import org.eclipse.ui.editors.text.templates.ContributionTemplateStore; -import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.eclipse.wst.sse.ui.internal.provisional.registry.AdapterFactoryRegistry; -import org.eclipse.wst.sse.ui.internal.provisional.registry.AdapterFactoryRegistryImpl; -import org.eclipse.wst.xml.ui.internal.preferences.XMLUIPreferenceNames; -import org.eclipse.wst.xml.ui.internal.templates.TemplateContextTypeIdsXML; - -/** - * The main plugin class to be used in the desktop. - */ -public class XMLUIPlugin extends AbstractUIPlugin { - public final static String ID = "org.eclipse.wst.xml.ui"; //$NON-NLS-1$ - - protected static XMLUIPlugin instance = null; - - public static XMLUIPlugin getDefault() { - return instance; - } - - public synchronized static XMLUIPlugin getInstance() { - return instance; - } - - /** - * The template context type registry for the xml editor. - */ - private ContextTypeRegistry fContextTypeRegistry; - - /** - * The template store for the xml editor. - * - */ - private TemplateStore fTemplateStore; - - public XMLUIPlugin() { - super(); - instance = this; - } - - public AdapterFactoryRegistry getAdapterFactoryRegistry() { - return AdapterFactoryRegistryImpl.getInstance(); - - } - - /** - * Returns the template store for the xml editor templates. - * - * @return the template store for the xml editor templates - */ - public TemplateStore getTemplateStore() { - if (fTemplateStore == null) { - fTemplateStore = new ContributionTemplateStore(getTemplateContextRegistry(), getPreferenceStore(), XMLUIPreferenceNames.TEMPLATES_KEY); - - try { - fTemplateStore.load(); - } - catch (IOException e) { - Logger.logException(e); - } - } - return fTemplateStore; - } - - /** - * Returns the template context type registry for the xml plugin. - * - * @return the template context type registry for the xml plugin - */ - public ContextTypeRegistry getTemplateContextRegistry() { - if (fContextTypeRegistry == null) { - ContributionContextTypeRegistry registry = new ContributionContextTypeRegistry(); - registry.addContextType(TemplateContextTypeIdsXML.ALL); - registry.addContextType(TemplateContextTypeIdsXML.NEW); - registry.addContextType(TemplateContextTypeIdsXML.TAG); - registry.addContextType(TemplateContextTypeIdsXML.ATTRIBUTE); - registry.addContextType(TemplateContextTypeIdsXML.ATTRIBUTE_VALUE); - - fContextTypeRegistry = registry; - } - - return fContextTypeRegistry; - } - - /** - * Get an image from the registry. - * - * *This method is used by the referencingfile dialog and should be - * removed when the dialog is moved to anothercomponent. - * - * @param imageName - * The name of the image. - * @return The image registered for the given name. - */ - public Image getImage(String imageName) { - return getWorkbench().getSharedImages().getImage(imageName); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties deleted file mode 100644 index f950a50e97..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties +++ /dev/null @@ -1,333 +0,0 @@ -############################################################################### -# Copyright (c) 2001, 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 -# Jens Lukowski/Innoopract - initial renaming/restructuring -# Benjamin Muskalla, b.muskalla@gmx.net - [158660] character entities should have their own syntax highlighting preference -# David Carver - STAR - [205989] - [validation] validate XML after XInclude resolution -############################################################################### -## The following line is a sample XML document. Please translate only the following parts: -## begin color definitions -## Normal text content. -Sample_XML_doc=<?xml version=\"1.0\"?>\n<?customProcessingInstruction\n\tXML processor specific\n\tcontent ?>\n<!DOCTYPE colors\n\tPUBLIC \"//IBM/XML/COLORS/\" \"colors.dtd\">\n<colors>\n\t<!-- begin color definitions -->\n\t<color name=\"plaintext\" foreground=\"#000000\"\n\t\tbackground=\"#D4D0C8\" />\n\t<color name=\"bold\" foreground=\"#000000\"\n\t\tbackground=\"#B3ACA0\" />\n\t<![CDATA[<123456789>]]>\n\tNormal text content.\n\t===>look at me!<===\n\t<color name=\"inverse\" foreground=\"#F0F0F0\"\n\t\tbackground=\"#D4D0C8\" />\n\n</colors>\n -Comment_Delimiters_UI_=Comment Delimiters -Comment_Content_UI_=Comment Content -Tag_Delimiters_UI_=Tag Delimiters -Tag_Names_UI_=Tag Names -Attribute_Names_UI_=Attribute Names -Attribute_Values_UI_=Attribute Values -Declaration_Delimiters_UI_=Declaration Delimiters -Content_UI_=Content -Entity_Reference_UI_=Entity References -## on the following 2 lines, do not translate CDATA -CDATA_Delimiters_UI_=CDATA Delimiters -CDATA_Content_UI_=CDATA Content -Processing_Instruction_Del_UI_=Processing Instruction Delimiters -Processing_Instruction_Con_UI__UI_=Processing Instruction Content -## on the following line solely translate: Name -DOCTYPE_Name_UI_=DOCTYPE Name -## on the following line solely translate: Keyword -DOCTYPE_SYSTEM_PUBLIC_Keyw_UI_=DOCTYPE SYSTEM/PUBLIC Keyword -## on the following line solely translate: Public Reference -DOCTYPE_Public_Reference_UI_=DOCTYPE Public Reference -## on the following line solely translate: System Reference -DOCTYPE_System_Reference_UI_=DOCTYPE System Reference -# XML Common UI -# Constants for strings - -DELETE=Remove -ADD_PROCESSING_INSTRUCTION=Add Processing Instruction - -_UI_MENU_ADD_AFTER=Add &After -_UI_MENU_ADD_ATTRIBUTE=Add A&ttribute -_UI_MENU_ADD_BEFORE=Add &Before -_UI_MENU_ADD_CHILD=Add &Child -_UI_MENU_REMOVE=Re&move -_UI_MENU_REPLACE_WITH=Re&place With -_UI_MENU_EDIT_DOCTYPE=Edit DOCTYPE... -_UI_LABEL_UNDO_REPLACE_DESCRIPTION=Replace -_UI_LABEL_EDIT_DOCTYPE=Edit DOCTYPE -_UI_INFO_EXPAND_ALL=Expand All -_UI_INFO_COLLAPSE_ALL=Collapse All - -_UI_MENU_ADD_DTD_INFORMATION=Add DTD Information... -_UI_MENU_ADD_SCHEMA_INFORMATION=Add Schema Information... -_UI_MENU_EDIT_PROCESSING_INSTRUCTION=Edit Process&ing Instruction... -_UI_MENU_EDIT_NAMESPACES=Edit &Namespaces... - -_UI_MENU_ADD_DTD_INFORMATION_TITLE=Add DTD Information -_UI_MENU_EDIT_PROCESSING_INSTRUCTION_TITLE=Edit Processing Instruction -_UI_MENU_EDIT_SCHEMA_INFORMATION_TITLE=Edit Schema Information - -_UI_MENU_NEW_ATTRIBUTE=&New Attribute... -_UI_MENU_NEW_ATTRIBUTE_TITLE=New Attribute -_UI_MENU_EDIT_ATTRIBUTE=Edit Attribute... -_UI_MENU_EDIT_ATTRIBUTE_TITLE=Edit Attribute -_UI_MENU_NEW_ELEMENT=New &Element... -_UI_MENU_NEW_ELEMENT_TITLE=New Element -_UI_MENU_RENAME=R&ename -_UI_MENU_RENAME_TITLE=Rename -_UI_LABEL_ELEMENT_NAME=Element name: - -_UI_MENU_ADD_COMMENT=Add Comment -_UI_MENU_ADD_PROCESSING_INSTRUCTION=Add Processing Instruction -_UI_MENU_ADD_CDATA_SECTION=Add CDATA Section -_UI_MENU_ADD_PCDATA=Add #PCDATA; - -_UI_MENU_COMMENT=C&omment -_UI_MENU_PROCESSING_INSTRUCTION=P&rocessing Instruction -_UI_MENU_CDATA_SECTION=CDATA Section -_UI_MENU_PCDATA=#PC&DATA; - -_UI_MENU_ADD=Add - -_UI_COMMENT_VALUE=comment -_UI_PI_TARGET_VALUE=target -_UI_PI_DATA_VALUE=data -_UI_LABEL_ROOT_ELEMENT_VALUE=RootElement - -_UI_LABEL_TARGET_COLON=Target: -_UI_LABEL_DATA_COLON=Data: -_UI_LABEL_ROOT_ELEMENT_NAME_COLON=Root element name: -_UI_LABEL_PUBLIC_ID_COLON=Public ID: -_UI_LABEL_SYSTEM_ID_COLON=System ID: -_UI_LABEL_BROWSE=Browse... -_UI_LABEL_SELECT_XML_CATALOG_ENTRY=Select XML Catalog Entry -_UI_LABEL_SPECIFY_SYSTEM_ID=Specify System ID -_UI_LABEL_SELECT_FILE=Select File - -_UI_LABEL_KEY=Key -_UI_LABEL_URI=URI: -_UI_LABEL_XML_CATALOG_COLON=XML Catalog -_UI_LABEL_NAMESPACE_NAME=Namespace Name -_UI_LABEL_LOCATION_HINT=Location Hint -_UI_LABEL_PREFIX=Prefix -_UI_LABEL_NAMESPACE_NAME_COLON=Namespace Name: -_UI_LABEL_LOCATION_HINT_COLON=Location Hint: -_UI_LABEL_PREFIX_COLON=Prefix: -_UI_NO_NAMESPACE_NAME=<no namespace name> -_UI_NO_PREFIX=<no prefix> - -_UI_LABEL_XML_SCHEMA_INFORMATION=XML Schema Information - -_UI_LABEL_NAME_COLON=Name: -_UI_LABEL_VALUE_COLON=Value: - -_UI_BUTTON_DELETE=Delete -_UI_BUTTON_NEW=New... -_UI_BUTTON_EDIT=Edit... - -_UI_LABEL_NEW_NAMESPACE_INFORMATION=New Namespace Information - -# SelectFileOrXMLCatalogIdPanel.java - -_UI_RADIO_BUTTON_SELECT_FROM_WORKSPACE=Select file from Workspace -_UI_RADIO_BUTTON_SELECT_FROM_CATALOG=Select XML Catalog entry - -_UI_WARNING_MORE_THAN_ONE_NS_WITH_NAME=More than one namespace has been specified with the namespace name : -_UI_WARNING_MORE_THAN_ONE_NS_WITHOUT_NAME=More than one schema has been specified without a namespace name -_UI_WARNING_MORE_THAN_ONE_NS_WITHOUT_PREFIX=More than one namespace has been specificed without a prefix -_UI_WARNING_MORE_THAN_ONE_NS_WITH_PREFIX=More than one namespace has been specified with the prefix : -_UI_WARNING_SCHEMA_CAN_NOT_BE_LOCATED=The specified schema can not be located : -_UI_WARNING_LOCATION_HINT_NOT_SPECIFIED=A location hint has not been specified for the namespace with name -_UI_WARNING_NAMESPACE_NAME_NOT_SPECIFIED=A name must be specified for the namespace with prefix : -_UI_WARNING_PREFIX_NOT_SPECIFIED=A prefix must be specified for the namespace named : -_UI_WARNING_ROOT_ELEMENT_MUST_BE_SPECIFIED=A root element name must be specified. -_UI_WARNING_SYSTEM_ID_MUST_BE_SPECIFIED=A system ID must be specified. - -_UI_INVALID_NAME=Invalid name - -# String used for editing namespaces (org.eclipse.wst.xml.ui.nsedit) -_UI_ENTER_REQ_PREFIX_AND_NAMESPACE=Enter the required prefix and namespace URI for the namespace declaration. -_UI_SELECT_REGISTERED_NAMESPACES=Select From Registered Namespaces -_UI_SPECIFY_NEW_NAMESPACE=Specify New Namespace -_UI_SELECT_NAMESPACE_TO_ADD=Select the namespace declarations to add. -_UI_ADD_NAMESPACE_DECLARATIONS=Add Namespace Declarations -_UI_NAMESPACE_DECLARATIONS=Namespace Declarations -_UI_TARGET_NAMESPACE=Target Namespace - -_ERROR_XML_ATTRIBUTE_ALREADY_EXISTS=The element already has an attribute with this name. - -# -error_message_goes_here=error message goes here -SurroundWithNewElementQuickAssistProposal_0=Surround with new element -SurroundWithNewElementQuickAssistProposal_1=Surround with new element -RenameInFileQuickAssistProposal_0=Link all references for a rename in file (does not change references in other files) -RenameInFileQuickAssistProposal_1=Rename in file -InsertRequiredAttrsQuickAssistProposal_0=Insert required attributes -InsertRequiredAttrsQuickAssistProposal_1=Insert required attributes -EncodingSettings_0=IANA: -EncodingSettings_1=Encoding: -DragNodeCommand_0=Move -DragNodeCommand_1=Copy -CommonEditNamespacesDialog_0=Add... -JFaceNodeAdapter_1=Refresh Property Sheet -QuickFixProcessorXML_0=Remove empty tag -QuickFixProcessorXML_1=Change to empty-element tag -QuickFixProcessorXML_2=Remove this tag -QuickFixProcessorXML_3=Insert end tag before first child element -QuickFixProcessorXML_4=Insert end tag at end of element -QuickFixProcessorXML_5=Remove attributes in end tag -QuickFixProcessorXML_6=Insert default attribute value -QuickFixProcessorXML_7=Remove this attribute -QuickFixProcessorXML_8=Remove spaces before tag name -QuickFixProcessorXML_9=Remove spaces before processing instruction -QuickFixProcessorXML_10=Remove namespace in processing instruction -QuickFixProcessorXML_11=Remove this element -QuickFixProcessorXML_12=Remove this attribute value -QuickFixProcessorXML_13=Insert required attribute -QuickFixProcessorXML_14=Quote attribute value -QuickFixProcessorXML_15=Insert closing bracket -XMLPropertySourceAdapter_0=Attributes - -WorkbenchDefaultEncodingSettings_0=Use workspace encoding -refreshoutline_0=Refreshing Outline -Creating_files_encoding=Creating files encoding preference -# ReconcileStepForMarkup -End_tag_has_attributes=End tag has attributes -Attribute__is_missing_a_value=Attribute \"{0}\" is missing a value -Attribute__has_no_value=Attribute \"{0}\" has no value -Missing_start_tag_=Missing start tag \"{0}\" -Missing_end_tag_=Missing end tag \"{0}\" -ReconcileStepForMarkup_0=Missing closing quote -ReconcileStepForMarkup_1=Missing quotes for attribute value -ReconcileStepForMarkup_2=A tagname cannot start with a space -ReconcileStepForMarkup_3=Empty tags are not allowed -ReconcileStepForMarkup_4=Namespaces are not allowed in a Processing Instruction target -ReconcileStepForMarkup_5=Spaces are not allowed before a Processing Instruction -ReconcileStepForMarkup_6=Tag missing closing bracket '>' -# Content Assist -End_with_=End with {0}> -SEVERE_internal_error_occu_UI_=SEVERE internal error occurred -No_known_attribute__UI_=No known attribute -Content_Assist_not_availab_UI_=Content Assist not available at the current location -Element__is_unknown=Element <{0}> is unknown. -Comment__=comment {0} -Close_with__=Close with {0} -End_with__=End with \"</{0}>\" -Close_with___=Close with \"{0}\" -Close_with____=Close with \"></{0}>\" -_Has_no_available_child={0} has no available child tags. -No_known_child_tag=No known child tag names of <{0}> begin with \"{1}\". -__Has_no_known_child=<{0}> has no known child tags. -No_known_child_tag_names=No known child tag names of <{0}> begin with \"{1}\" -The_document_element__=The document element <{0}> is already present. -No_definition_for_in=No definition was found for element <{0}> in {1} -No_definition_for=No definition was found for element <{0}> -No_content_model_for=No content model found for {0}. -No_content_model_found_UI_=No content model found -## The following strings are for the XML Cleanup dialog -Cleanup_UI_=Cleanup -Compress_empty_element_tags_UI_=&Compress empty element tags -Insert_required_attributes_UI_=Insert &required attributes -Insert_missing_tags_UI_=&Insert missing tags -Quote_attribute_values_UI_=&Quote attribute values -Format_source_UI_=&Format source -Convert_EOL_codes_UI_=Convert line &delimiters to -EOL_Windows_UI=&Windows -EOL_Unix_UI=U&NIX -EOL_Mac_UI=&Mac -## XML Files preference page -Creating_files=Creating files -Encoding_desc=The following encoding will apply: -Encoding=En&coding: -Creating_or_saving_files=Creating or saving files -End_of_line_code_desc=The following line delimiter will apply: -End_of_line_code=&Line delimiter: -EOL_Windows=Windows -EOL_Unix=UNIX -EOL_Mac=Mac -EOL_NoTranslation=No translation -Validating_files=Validating files -Indicate_no_grammar_specified=Indicate when no grammar is specified: -Indicate_no_grammar_specified_severities=Error,Warning,Ignore -XMLFilesPreferencePage_ExtensionLabel=Add this suffix (if not specified): -XMLFilesPreferencePage_ExtensionError=Suffix must be one of the following {0}. -## XML Source preference page -Content_assist_UI_=Content assist -Automatically_make_suggest_UI_=Automatically ma&ke suggestions -Prompt_when_these_characte_UI_=P&rompt when these characters are inserted: -Formatting_UI_=Formatting -Line_width__UI_=Line &width: -Split_multiple_attributes=Split &multiple attributes each on a new line -Align_final_bracket=&Align final bracket in multi-line element tags -Preserve_PCDATA_Content=&Preserve whitespace in tags with PCDATA content -Space_before_empty_close_tag=Ins&ert whitespace before closing empty end-tags -Indent_using_tabs=&Indent using tabs -Indent_using_spaces=I&ndent using spaces -Indentation_size=In&dentation size: -Indentation_size_tip=Indentation size -Clear_all_blank_lines_UI_=Clear all &blank lines -Grammar_Constraints=Grammar Constraints -Use_inferred_grammar_in_absence_of=&Use inferred grammar in absence of DTD/Schema -Suggestion_Strategy=&Suggestion strategy: -Suggestion_Strategy_Lax=Lax -Suggestion_Strategy_Strict=Strict -## tag info -Element____1=Element : -Content_Model____2=Content Model : -Attribute____3=Attribute : -Data_Type____4=Data Type : -Enumerated_Values____5=Enumerated Values : -## copied from sse.ui -SourceMenu_label=&Source -Comment_label=Co&mment -Comment_tooltip=Comment -Comment_description=Comment -Uncomment_label=&Uncomment -Uncomment_tooltip=Uncomment -Uncomment_description=Uncomment -ToggleComment_label=Toggle Comment -ToggleComment_tooltip=Toggle Comment -ToggleComment_description=Toggle Comment -AddBlockComment_label=Add Block Comment -AddBlockComment_tooltip=Add Block Comment -AddBlockComment_description=Add Block Comment -RemoveBlockComment_label=Remove Block Comment -RemoveBlockComment_tooltip=Remove Block Comment -RemoveBlockComment_description=Remove Block Comment -CleanupDocument_label=Cleanup Document... -CleanupDocument_tooltip=Cleanup Document -CleanupDocument_description=Cleanup Document -FindOccurrences_label=Occurrences in File -OpenFileFromSource_label=Op&en Selection -OpenFileFromSource_tooltip=Open an editor on the selected link -OpenFileFromSource_description=Open an editor on the selected link -XMLContentOutlineConfiguration_0=Show Attributes -XMLTyping_Auto_Complete=Automatically close -XMLTyping_Auto_Remove=Automatically remove -XMLTyping_Complete_Comments=&Comments -XMLTyping_Complete_End_Tags=&End tags -XMLTyping_Remove_End_Tags=E&nd tags when creating empty self-closing tags -StructureSelectEnclosing_label=Enclosing Element -StructureSelectEnclosing_tooltip=Expand selection to include enclosing element -StructureSelectEnclosing_description=Expand selection to include enclosing element -StructureSelectNext_label=Next Element -StructureSelectNext_tooltip=Expand selection to include next sibling -StructureSelectNext_description=Expand selection to include next sibling -StructureSelectPrevious_label=Previous Element -StructureSelectPrevious_tooltip=Expand selection to include previous sibling -StructureSelectPrevious_description=Expand selection to include previous sibling -MESSAGE_XML_VALIDATION_MESSAGE_UI_=XML Validator validating {0} -SyntaxColoringPage_0=Syntax Element: -SyntaxColoringPage_2=Enable -SyntaxColoringPage_3=&Bold -SyntaxColoringPage_4=&Italic -SyntaxColoringPage_5=&Strike-through -SyntaxColoringPage_6=&Underline -EmptyFilePreferencePage_0=Expand the tree to edit preferences for a specific feature. -_UI_STRUCTURED_TEXT_EDITOR_PREFS_LINK=XML editing preferences. Note that some preferences may be set on the <a>{0}</a> preference page. -Use_XInclude=Process XML Inclusions -nextSibling_label=Next Sibling -nextSibling_description=Go to Next Sibling -previousSibling_label=Previous Sibling -previousSibling_description=Go to Previous Sibling -gotoMatchingTag_label=Matching Tag -gotoMatchingTag_description=Go To Matching Tag -Open=Open '{0}' -_UI_BUTTON_SORT=Sort diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/AbstractCommentActionXMLDelegate.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/AbstractCommentActionXMLDelegate.java deleted file mode 100644 index e00b29d7eb..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/AbstractCommentActionXMLDelegate.java +++ /dev/null @@ -1,117 +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.wst.xml.ui.internal.actions; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.text.TextSelection; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.swt.widgets.Event; -import org.eclipse.ui.IActionDelegate2; -import org.eclipse.ui.IEditorActionDelegate; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IViewActionDelegate; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.wst.xml.ui.internal.Logger; - -/** - * Abstract comment action delegate for XML editors - */ -abstract public class AbstractCommentActionXMLDelegate implements IEditorActionDelegate, IActionDelegate2, IViewActionDelegate { - static final String CLOSE_COMMENT = "-->"; //$NON-NLS-1$ - static final String OPEN_COMMENT = "<!--"; //$NON-NLS-1$ - - IEditorPart fEditor; - - public void setActiveEditor(IAction action, IEditorPart targetEditor) { - fEditor = targetEditor; - } - - public void dispose() { - // nulling out just in case - fEditor = null; - } - - public void runWithEvent(IAction action, Event event) { - run(action); - } - - public void run(IAction action) { - if (fEditor instanceof ITextEditor) { - ITextEditor textEditor = (ITextEditor) fEditor; - IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()); - if (document != null) { - // get current text selection - ITextSelection textSelection = getCurrentSelection(); - if (textSelection.isEmpty()) { - return; - } - - processAction(document, textSelection); - } - } - } - - public void init(IViewPart view) { - // do nothing - } - - public void selectionChanged(IAction action, ISelection selection) { - // do nothing - } - - private ITextSelection getCurrentSelection() { - if (fEditor instanceof ITextEditor) { - ISelectionProvider provider = ((ITextEditor) fEditor).getSelectionProvider(); - if (provider != null) { - ISelection selection = provider.getSelection(); - if (selection instanceof ITextSelection) { - return (ITextSelection) selection; - } - } - } - return TextSelection.emptySelection(); - } - - abstract void processAction(IDocument document, ITextSelection textSelection); - - void removeOpenCloseComments(IDocument document, int offset, int length) { - try { - int adjusted_length = length; - - // remove open comments - String string = document.get(offset, length); - int index = string.lastIndexOf(OPEN_COMMENT); - while (index != -1) { - document.replace(offset + index, OPEN_COMMENT.length(), ""); //$NON-NLS-1$ - index = string.lastIndexOf(OPEN_COMMENT, index - 1); - adjusted_length -= OPEN_COMMENT.length(); - } - - // remove close comments - string = document.get(offset, adjusted_length); - index = string.lastIndexOf(CLOSE_COMMENT); - while (index != -1) { - document.replace(offset + index, CLOSE_COMMENT.length(), ""); //$NON-NLS-1$ - index = string.lastIndexOf(CLOSE_COMMENT, index - 1); - } - } - catch (BadLocationException e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/AbstractNodeActionManager.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/AbstractNodeActionManager.java deleted file mode 100644 index 028d579f80..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/AbstractNodeActionManager.java +++ /dev/null @@ -1,684 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.actions; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.contentmodel.util.CMDescriptionBuilder; -import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMContentBuilder; -import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMContentBuilderImpl; -import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMNamespaceHelper; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.internal.editor.CMImageUtil; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages; -import org.w3c.dom.Attr; -import org.w3c.dom.Document; -import org.w3c.dom.DocumentType; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.w3c.dom.ProcessingInstruction; - -public abstract class AbstractNodeActionManager extends BaseNodeActionManager { - - - /** - * AddNodeAction - */ - public class AddNodeAction extends NodeAction { - protected CMNode cmnode; - protected String description; - protected int index; - protected int nodeType; - protected Node parent; - protected String undoDescription; - - - public AddNodeAction(CMNode cmnode, Node parent, int index) { - this.cmnode = cmnode; - this.parent = parent; - this.index = index; - - String text = getLabel(parent, cmnode); - setText(text); - description = text; - undoDescription = XMLUIMessages._UI_MENU_ADD + " " + text; //$NON-NLS-1$ - ImageDescriptor descriptor = CMImageUtil.getImageDescriptor(cmnode); - if (descriptor == null) { - descriptor = imageDescriptorCache.getImageDescriptor(cmnode); - } - setImageDescriptor(descriptor); - } - - - public AddNodeAction(int nodeType, Node parent, int index) { - this.nodeType = nodeType; - this.index = index; - this.parent = parent; - - switch (nodeType) { - case Node.COMMENT_NODE : { - description = XMLUIMessages._UI_MENU_COMMENT; - undoDescription = XMLUIMessages._UI_MENU_ADD_COMMENT; - break; - } - case Node.PROCESSING_INSTRUCTION_NODE : { - description = XMLUIMessages._UI_MENU_PROCESSING_INSTRUCTION; - undoDescription = XMLUIMessages._UI_MENU_ADD_PROCESSING_INSTRUCTION; - break; - } - case Node.CDATA_SECTION_NODE : { - description = XMLUIMessages._UI_MENU_CDATA_SECTION; - undoDescription = XMLUIMessages._UI_MENU_ADD_CDATA_SECTION; - break; - } - case Node.TEXT_NODE : { - description = XMLUIMessages._UI_MENU_PCDATA; - undoDescription = XMLUIMessages._UI_MENU_ADD_PCDATA; - break; - } - } - setText(description); - setImageDescriptor(imageDescriptorCache.getImageDescriptor(new Integer(nodeType))); - } - - - protected void addNodeForCMNode() { - if (parent != null) { - insert(parent, cmnode, index); - } - } - - - protected void addNodeForNodeType() { - Document document = parent.getNodeType() == Node.DOCUMENT_NODE ? (Document) parent : parent.getOwnerDocument(); - Node newChildNode = null; - boolean format = true; - switch (nodeType) { - case Node.COMMENT_NODE : { - newChildNode = document.createComment(XMLUIMessages._UI_COMMENT_VALUE); - break; - } - case Node.PROCESSING_INSTRUCTION_NODE : { - newChildNode = document.createProcessingInstruction(XMLUIMessages._UI_PI_TARGET_VALUE, XMLUIMessages._UI_PI_DATA_VALUE); - break; - } - case Node.CDATA_SECTION_NODE : { - newChildNode = document.createCDATASection(""); //$NON-NLS-1$ - break; - } - case Node.TEXT_NODE : { - format = false; - newChildNode = document.createTextNode(parent.getNodeName()); - break; - } - } - - if (newChildNode != null) { - List list = new Vector(1); - list.add(newChildNode); - insertNodesAtIndex(parent, list, index, format); - } - } - - - public String getUndoDescription() { - return undoDescription; - } - - - public void run() { - beginNodeAction(this); - if (cmnode != null) { - addNodeForCMNode(); - } - else { - addNodeForNodeType(); - } - endNodeAction(this); - } - } - - - /** - * DeleteAction - */ - public class DeleteAction extends NodeAction { - protected List list; - - public DeleteAction(List list) { - setText(XMLUIMessages._UI_MENU_REMOVE); - this.list = list; - } - - public DeleteAction(Node node) { - setText(XMLUIMessages._UI_MENU_REMOVE); - list = new Vector(); - list.add(node); - } - - public String getUndoDescription() { - return XMLUIMessages.DELETE; - } - - public void run() { - beginNodeAction(this); - - for (Iterator i = list.iterator(); i.hasNext();) { - Node node = (Node) i.next(); - if (node.getNodeType() == Node.ATTRIBUTE_NODE) { - Attr attr = (Attr) node; - attr.getOwnerElement().removeAttributeNode(attr); - } - else { - Node parent = node.getParentNode(); - if (parent != null) { - Node previousSibling = node.getPreviousSibling(); - if ((previousSibling != null) && isWhitespaceTextNode(previousSibling)) { - parent.removeChild(previousSibling); - } - parent.removeChild(node); - } - } - } - - endNodeAction(this); - } - } - - - class ImageDescriptorCache { - protected ImageDescriptor attributeImage = XMLEditorPluginImageHelper.getInstance().getImageDescriptor(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE); - protected ImageDescriptor attributeReqImage = XMLEditorPluginImageHelper.getInstance().getImageDescriptor(XMLEditorPluginImages.IMG_OBJ_ATT_REQ_OBJ); - protected ImageDescriptor cdataSectionImage = XMLEditorPluginImageHelper.getInstance().getImageDescriptor(XMLEditorPluginImages.IMG_OBJ_CDATASECTION); - protected ImageDescriptor commentImage = XMLEditorPluginImageHelper.getInstance().getImageDescriptor(XMLEditorPluginImages.IMG_OBJ_COMMENT); - protected ImageDescriptor elementImage = XMLEditorPluginImageHelper.getInstance().getImageDescriptor(XMLEditorPluginImages.IMG_OBJ_ELEMENT); - protected ImageDescriptor piImage = XMLEditorPluginImageHelper.getInstance().getImageDescriptor(XMLEditorPluginImages.IMG_OBJ_PROCESSINGINSTRUCTION); - protected ImageDescriptor textImage = XMLEditorPluginImageHelper.getInstance().getImageDescriptor(XMLEditorPluginImages.IMG_OBJ_TXTEXT); - - public ImageDescriptor getImageDescriptor(Object object) { - ImageDescriptor result = null; - if (object instanceof CMNode) { - CMNode cmnode = (CMNode) object; - switch (cmnode.getNodeType()) { - case CMNode.ATTRIBUTE_DECLARATION : { - result = CMImageUtil.getImageDescriptor(cmnode); - if (result == null) { - if (((CMAttributeDeclaration) cmnode).getUsage() == CMAttributeDeclaration.REQUIRED) { - result = attributeReqImage; - } - else { - result = attributeImage; - } - } - break; - } - case CMNode.DATA_TYPE : { - result = textImage; - break; - } - case CMNode.ELEMENT_DECLARATION : { - result = CMImageUtil.getImageDescriptor(cmnode); - if (result == null) { - result = elementImage; - } - break; - } - case CMNode.GROUP : { - result = elementImage; - break; - } - } - } - else if (object instanceof Integer) { - Integer integer = (Integer) object; - switch (integer.intValue()) { - case Node.COMMENT_NODE : { - result = commentImage; - break; - } - case Node.PROCESSING_INSTRUCTION_NODE : { - result = piImage; - break; - } - case Node.CDATA_SECTION_NODE : { - result = cdataSectionImage; - break; - } - case Node.TEXT_NODE : { - result = textImage; - break; - } - } - } - return result; - } - } - - // TODO... remove this class. I'm pretty sure it is no longer used by - // anyone. - /** - * @depracated - */ - public class InsertAction extends NodeAction { - protected String description; - protected int index; - protected int nodeType; - protected Node parent; - - public InsertAction(int nodeType, Node parent, int index) { - this.nodeType = nodeType; - this.index = index; - this.parent = parent; - switch (nodeType) { - case Node.COMMENT_NODE : { - description = XMLUIMessages._UI_MENU_COMMENT; - break; - } - case Node.PROCESSING_INSTRUCTION_NODE : { - description = XMLUIMessages._UI_MENU_PROCESSING_INSTRUCTION; - break; - } - case Node.CDATA_SECTION_NODE : { - description = XMLUIMessages._UI_MENU_CDATA_SECTION; - break; - } - case Node.TEXT_NODE : { - description = XMLUIMessages._UI_MENU_PCDATA; - break; - } - } - setText(description); - setImageDescriptor(imageDescriptorCache.getImageDescriptor(new Integer(nodeType))); - } - - public InsertAction(int nodeType, Node parent, int index, String title) { - this.nodeType = nodeType; - this.index = index; - this.parent = parent; - description = title; - setText(description); - setImageDescriptor(imageDescriptorCache.getImageDescriptor(new Integer(nodeType))); - } - - public String getUndoDescription() { - return XMLUIMessages._UI_MENU_ADD + " " + description; //$NON-NLS-1$ - } - - public void run() { - beginNodeAction(this); - - Document document = parent.getNodeType() == Node.DOCUMENT_NODE ? (Document) parent : parent.getOwnerDocument(); - Node newChildNode = null; - boolean format = true; - switch (nodeType) { - case Node.COMMENT_NODE : { - newChildNode = document.createComment(XMLUIMessages._UI_COMMENT_VALUE); - break; - } - case Node.PROCESSING_INSTRUCTION_NODE : { - newChildNode = document.createProcessingInstruction(XMLUIMessages._UI_PI_TARGET_VALUE, XMLUIMessages._UI_PI_DATA_VALUE); - break; - } - case Node.CDATA_SECTION_NODE : { - newChildNode = document.createCDATASection(""); //$NON-NLS-1$ - break; - } - case Node.TEXT_NODE : { - format = false; - newChildNode = document.createTextNode(parent.getNodeName()); - break; - } - } - - if (newChildNode != null) { - List list = new Vector(1); - list.add(newChildNode); - insertNodesAtIndex(parent, list, index, format); - } - - endNodeAction(this); - } - } - - - /** - * ReplaceNodeAction - */ - public class ReplaceNodeAction extends NodeAction { - protected CMNode cmnode; - protected String description; - protected int endIndex; - protected Node parent; - protected int startIndex; - - - public ReplaceNodeAction(Node parent, CMNode cmnode, int startIndex, int endIndex) { - this.parent = parent; - this.cmnode = cmnode; - this.startIndex = startIndex; - this.endIndex = endIndex; - - setText(getLabel(parent, cmnode)); - setImageDescriptor(imageDescriptorCache.getImageDescriptor(cmnode)); - } - - public String getUndoDescription() { - String result = XMLUIMessages._UI_LABEL_UNDO_REPLACE_DESCRIPTION; - result += " " + getLabel(parent, cmnode); //$NON-NLS-1$ - return result; - } - - public void run() { - beginNodeAction(this); - - if ((parent != null) && (cmnode != null)) { - remove(parent, startIndex, endIndex); - insert(parent, cmnode, startIndex); - } - endNodeAction(this); - } - } - - protected ImageDescriptorCache imageDescriptorCache = new ImageDescriptorCache(); - protected Viewer fViewer; - - public AbstractNodeActionManager(IStructuredModel model, ModelQuery modelQuery, Viewer viewer) { - super(model, modelQuery); - this.fViewer = viewer; - } - - - public void beginNodeAction(NodeAction action) { - fModel.beginRecording(action, action.getUndoDescription()); - } - - - protected Action createAddAttributeAction(Element parent, CMAttributeDeclaration ad) { - Action action = null; - if (ad == null) { - action = new EditAttributeAction(this, parent, null, XMLUIMessages._UI_MENU_NEW_ATTRIBUTE, XMLUIMessages._UI_MENU_NEW_ATTRIBUTE_TITLE); - } - else { - action = new AddNodeAction(ad, parent, -1); - } - return action; - } - - - protected Action createAddCDataSectionAction(Node parent, int index) { - return new AddNodeAction(Node.CDATA_SECTION_NODE, parent, index); - } - - - protected Action createAddCommentAction(Node parent, int index) { - return new AddNodeAction(Node.COMMENT_NODE, parent, index); - } - - - protected Action createAddDoctypeAction(Document document, int index) { - return new EditDoctypeAction(fModel, document, fModel.getBaseLocation(), XMLUIMessages._UI_MENU_ADD_DTD_INFORMATION); - } - - - protected Action createAddElementAction(Node parent, CMElementDeclaration ed, int index) { - Action action = null; - if (ed == null) { - action = new EditElementAction(this, parent, index, XMLUIMessages._UI_MENU_NEW_ELEMENT, XMLUIMessages._UI_MENU_NEW_ELEMENT_TITLE); - } - else { - action = new AddNodeAction(ed, parent, index); - } - return action; - } - - - protected Action createAddPCDataAction(Node parent, CMDataType dataType, int index) { - Action action = null; - if (dataType == null) { - action = new AddNodeAction(Node.TEXT_NODE, parent, index); - } - else { - action = new AddNodeAction(dataType, parent, index); - } - return action; - } - - - protected Action createAddProcessingInstructionAction(Node parent, int index) { - Node refChild = getRefChildNodeAtIndex(parent, index); - Action action = new EditProcessingInstructionAction(this, parent, refChild, XMLUIMessages._UI_MENU_ADD_PROCESSING_INSTRUCTION, XMLUIMessages.ADD_PROCESSING_INSTRUCTION); - action.setImageDescriptor(imageDescriptorCache.getImageDescriptor(new Integer(Node.PROCESSING_INSTRUCTION_NODE))); - return action; - } - - - protected Action createAddSchemaInfoAction(Element element) { - return new EditSchemaInfoAction(this, element.getOwnerDocument(), fModel.getBaseLocation(), XMLUIMessages._UI_MENU_ADD_SCHEMA_INFORMATION); - } - - - protected Action createDeleteAction(List selection) { - DeleteAction deleteAction = new DeleteAction(selection); - deleteAction.setEnabled(selection.size() > 0); - return deleteAction; - } - - - public DOMContentBuilder createDOMContentBuilder(Document document) { - DOMContentBuilderImpl builder = new DOMContentBuilderImpl(document); - return builder; - } - - - protected Action createEditAttributeAction(Attr attr, CMAttributeDeclaration ad) { - return new EditAttributeAction(this, attr.getOwnerElement(), attr, XMLUIMessages._UI_MENU_EDIT_ATTRIBUTE, XMLUIMessages._UI_MENU_EDIT_ATTRIBUTE_TITLE); - } - - - protected Action createEditDoctypeAction(DocumentType doctype) { - return new EditDoctypeAction(fModel, doctype, fModel.getBaseLocation(), XMLUIMessages._UI_MENU_EDIT_DOCTYPE); - } - - - protected Action createEditProcessingInstructionAction(ProcessingInstruction pi) { - return new EditProcessingInstructionAction(this, pi, XMLUIMessages._UI_MENU_EDIT_PROCESSING_INSTRUCTION, XMLUIMessages._UI_MENU_EDIT_PROCESSING_INSTRUCTION_TITLE); - } - - - protected Action createEditSchemaInfoAction(Element element) { - return new EditSchemaInfoAction(this, element.getOwnerDocument(), fModel.getBaseLocation(), XMLUIMessages._UI_MENU_EDIT_NAMESPACES); - } - - - protected Action createRenameAction(Node node) { - Action result = null; - if (node instanceof Element) { - result = new EditElementAction(this, (Element) node, XMLUIMessages._UI_MENU_RENAME, XMLUIMessages._UI_MENU_RENAME_TITLE); - } - return result; - } - - - protected Action createReplaceAction(Node parent, CMNode cmnode, int startIndex, int endIndex) { - return new ReplaceNodeAction(parent, cmnode, startIndex, endIndex); - } - - public void endNodeAction(NodeAction action) { - fModel.endRecording(action); - } - - - - public void fillContextMenu(IMenuManager menuManager, ISelection selection) { - try { - List selectionList = new ArrayList(); - if (selection instanceof IStructuredSelection) { - IStructuredSelection es = (IStructuredSelection) selection; - for (Iterator i = es.iterator(); i.hasNext();) { - selectionList.add(i.next()); - } - } - - contributeActions(menuManager, selectionList); - } - catch (Exception e) { - e.printStackTrace(); - } - } - - /** - * - */ - public String getLabel(Node parent, CMNode cmnode) { - String result = "?" + cmnode + "?"; //$NON-NLS-1$ //$NON-NLS-2$ - if (cmnode != null) { - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=155800 - result = cmnode.getNodeName(); - if(result == null) { - result = (String) cmnode.getProperty("description"); //$NON-NLS-1$ - } - if (result == null || result.length() == 0) { - if (cmnode.getNodeType() == CMNode.GROUP) { - CMDescriptionBuilder descriptionBuilder = new CMDescriptionBuilder(); - result = descriptionBuilder.buildDescription(cmnode); - } - else { - result = DOMNamespaceHelper.computeName(cmnode, parent, null); - } - } - } - return result; - } - - - public IStructuredModel getModel() { - return fModel; - } - - - public Shell getWorkbenchWindowShell() { - return XMLUIPlugin.getInstance().getWorkbench().getActiveWorkbenchWindow().getShell(); - } - - - public void insert(Node parent, CMNode cmnode, int index) { - Document document = parent.getNodeType() == Node.DOCUMENT_NODE ? (Document) parent : parent.getOwnerDocument(); - DOMContentBuilder builder = createDOMContentBuilder(document); - builder.setBuildPolicy(DOMContentBuilder.BUILD_ONLY_REQUIRED_CONTENT); - builder.build(parent, cmnode); - insertNodesAtIndex(parent, builder.getResult(), index); - } - - - public void insertNodesAtIndex(Node parent, List list, int index) { - insertNodesAtIndex(parent, list, index, true); - } - - - public void insertNodesAtIndex(Node parent, List list, int index, boolean format) { - NodeList nodeList = parent.getChildNodes(); - if (index == -1) { - index = nodeList.getLength(); - } - Node refChild = (index < nodeList.getLength()) ? nodeList.item(index) : null; - - // here we consider the case where the previous node is a 'white - // space' Text node - // we should really do the insert before this node - // - int prevIndex = index - 1; - Node prevChild = (prevIndex < nodeList.getLength()) ? nodeList.item(prevIndex) : null; - if (isWhitespaceTextNode(prevChild)) { - refChild = prevChild; - } - - for (Iterator i = list.iterator(); i.hasNext();) { - Node newNode = (Node) i.next(); - - if (newNode.getNodeType() == Node.ATTRIBUTE_NODE) { - Element parentElement = (Element) parent; - parentElement.setAttributeNode((Attr) newNode); - } - else { - parent.insertBefore(newNode, refChild); - } - } - - boolean formatDeep = false; - for (Iterator i = list.iterator(); i.hasNext();) { - Node newNode = (Node) i.next(); - if (newNode.getNodeType() == Node.ELEMENT_NODE) { - formatDeep = true; - } - - if (format) { - reformat(newNode, formatDeep); - } - } - - setViewerSelection(list); - } - - - /** - * This method is abstract since currently, the sed editor is required to - * perform formating and we don't want to create a dependency on the sed - * editor. - */ - public abstract void reformat(Node parent, boolean deep); - - - public void remove(Node parent, int startIndex, int endIndex) { - NodeList nodeList = parent.getChildNodes(); - for (int i = endIndex; i >= startIndex; i--) { - Node node = nodeList.item(i); - if (node != null) { - parent.removeChild(node); - } - } - } - - - public void setViewerSelection(List list) { - if (fViewer != null) { - fViewer.setSelection(new StructuredSelection(list), true); - } - } - - - public void setViewerSelection(Node node) { - if (fViewer != null) { - fViewer.setSelection(new StructuredSelection(node), true); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/ActionContributorXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/ActionContributorXML.java deleted file mode 100644 index c4f8285df7..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/ActionContributorXML.java +++ /dev/null @@ -1,224 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.actions; - -import java.util.ResourceBundle; - -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.IStatusLineManager; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchActionConstants; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; -import org.eclipse.ui.texteditor.RetargetTextEditorAction; -import org.eclipse.wst.sse.ui.internal.actions.ActionContributor; -import org.eclipse.wst.sse.ui.internal.actions.ActionDefinitionIds; -import org.eclipse.wst.sse.ui.internal.actions.StructuredTextEditorActionConstants; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; - -/** - * XMLEditorActionContributor - * - * This class should not be used inside multi page editor's - * ActionBarContributor, since cascaded init() call from the - * ActionBarContributor will causes exception and it leads to lose whole - * toolbars. - * - * Instead, use SourcePageActionContributor for source page contributor of - * multi page editor. - * - * Note that this class is still valid for single page editor. - */ -public class ActionContributorXML extends ActionContributor { - private static final String[] EDITOR_IDS = {"org.eclipse.core.runtime.xml.source", "org.eclipse.core.runtime.xml.source2", "org.eclipse.wst.sse.ui.StructuredTextEditor"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - private static final String GO_TO_MATCHING_TAG_ID = "org.eclipse.wst.xml.ui.gotoMatchingTag"; //$NON-NLS-1$ - - protected RetargetTextEditorAction fCleanupDocument = null; - protected RetargetTextEditorAction fComment = null; - protected RetargetTextEditorAction fContentAssist = null; - protected RetargetTextEditorAction fFindOccurrences = null; - protected RetargetTextEditorAction fFormatActiveElements = null; - protected RetargetTextEditorAction fFormatDocument = null; - protected RetargetTextEditorAction fOpenFileAction = null; // open file - - protected RetargetTextEditorAction fUncomment = null; - private GoToMatchingTagAction fGoToMatchingTagAction; - - public ActionContributorXML() { - super(); - - ResourceBundle resourceBundle = XMLUIMessages.getResourceBundle(); - - fContentAssist = new RetargetTextEditorAction(resourceBundle, ""); //$NON-NLS-1$ - fContentAssist.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); - - // source commands - fCleanupDocument = new RetargetTextEditorAction(resourceBundle, ""); //$NON-NLS-1$ - fCleanupDocument.setActionDefinitionId(ActionDefinitionIds.CLEANUP_DOCUMENT); - - fFormatDocument = new RetargetTextEditorAction(resourceBundle, ""); //$NON-NLS-1$ - fFormatDocument.setActionDefinitionId(ActionDefinitionIds.FORMAT_DOCUMENT); - - fFormatActiveElements = new RetargetTextEditorAction(resourceBundle, ""); //$NON-NLS-1$ - fFormatActiveElements.setActionDefinitionId(ActionDefinitionIds.FORMAT_ACTIVE_ELEMENTS); - - // navigate commands - fOpenFileAction = new RetargetTextEditorAction(resourceBundle, ""); //$NON-NLS-1$ - fOpenFileAction.setActionDefinitionId(ActionDefinitionIds.OPEN_FILE); - - fFindOccurrences = new RetargetTextEditorAction(resourceBundle, ""); //$NON-NLS-1$ - fFindOccurrences.setActionDefinitionId(ActionDefinitionIds.FIND_OCCURRENCES); - - fGoToMatchingTagAction = new GoToMatchingTagAction(resourceBundle, "gotoMatchingTag_", null); //$NON-NLS-1$ - fGoToMatchingTagAction.setActionDefinitionId(GO_TO_MATCHING_TAG_ID); - fGoToMatchingTagAction.setId(GO_TO_MATCHING_TAG_ID); - } - - /** - * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToMenu(IMenuManager) - */ - public void contributeToMenu(IMenuManager menu) { - // navigate commands - IMenuManager navigateMenu = menu.findMenuUsingPath(IWorkbenchActionConstants.M_NAVIGATE); - if (navigateMenu != null) { - navigateMenu.appendToGroup(IWorkbenchActionConstants.OPEN_EXT, fCommandsSeparator); - navigateMenu.appendToGroup(IWorkbenchActionConstants.OPEN_EXT, fOpenFileAction); - - IMenuManager gotoGroup = navigateMenu.findMenuUsingPath(IWorkbenchActionConstants.GO_TO); - if (gotoGroup != null) { - gotoGroup.appendToGroup("matchingBegin", fGoToMatchingTagAction); //$NON-NLS-1$ - } - } - super.contributeToMenu(menu); - } - - protected void addToMenu(IMenuManager menu) { -/* - // edit commands - IMenuManager editMenu = menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT); - if (editMenu != null) { - editMenu.add(fCommandsSeparator); - editMenu.add(fToggleInsertModeAction); - editMenu.add(fCommandsSeparator); - editMenu.add(fExpandSelectionToMenu); - editMenu.add(fCommandsSeparator); - editMenu.add(fContentAssist); - editMenu.add(fMenuAdditionsGroupMarker); - } - - // source commands - String sourceMenuLabel = XMLUIMessages.SourceMenu_label; - String sourceMenuId = "sourceMenuId"; //$NON-NLS-1$ - IMenuManager sourceMenu = new MenuManager(sourceMenuLabel, sourceMenuId); - menu.insertAfter(IWorkbenchActionConstants.M_EDIT, sourceMenu); - if (sourceMenu != null) { - sourceMenu.add(fCommandsSeparator); - sourceMenu.add(fToggleComment); - sourceMenu.add(fAddBlockComment); - sourceMenu.add(fRemoveBlockComment); - sourceMenu.add(fShiftRight); - sourceMenu.add(fShiftLeft); - sourceMenu.add(fCleanupDocument); - sourceMenu.add(fFormatDocument); - sourceMenu.add(fFormatActiveElements); - sourceMenu.add(fCommandsSeparator); - sourceMenu.add(fFindOccurrences); - } - - // navigate commands - IMenuManager navigateMenu = menu.findMenuUsingPath(IWorkbenchActionConstants.M_NAVIGATE); - if (navigateMenu != null) { - navigateMenu.appendToGroup(IWorkbenchActionConstants.OPEN_EXT, fCommandsSeparator); - navigateMenu.appendToGroup(IWorkbenchActionConstants.OPEN_EXT, fOpenFileAction); - - IMenuManager gotoGroup = navigateMenu.findMenuUsingPath(IWorkbenchActionConstants.GO_TO); - if (gotoGroup != null) { - gotoGroup.add(fGotoMatchingBracketAction); - gotoGroup.add(fGoToMatchingTagAction); - gotoGroup.add(new Separator()); - } - } -*/ - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.edit.util.ActionContributor#getExtensionIDs() - */ - protected String[] getExtensionIDs() { - return EDITOR_IDS; - } - - /** - * @see org.eclipse.ui.IEditorActionBarContributor#setActiveEditor(IEditorPart) - */ - public void setActiveEditor(IEditorPart activeEditor) { - if (getActiveEditorPart() == activeEditor) { - return; - } - super.setActiveEditor(activeEditor); - - IActionBars actionBars = getActionBars(); - if (actionBars != null) { - IStatusLineManager statusLineManager = actionBars.getStatusLineManager(); - if (statusLineManager != null) { - statusLineManager.setMessage(null); - statusLineManager.setErrorMessage(null); - } - } - - ITextEditor textEditor = getTextEditor(activeEditor); - - fContentAssist.setAction(getAction(textEditor, StructuredTextEditorActionConstants.ACTION_NAME_CONTENTASSIST_PROPOSALS)); - - fCleanupDocument.setAction(getAction(textEditor, StructuredTextEditorActionConstants.ACTION_NAME_CLEANUP_DOCUMENT)); - fFormatDocument.setAction(getAction(textEditor, StructuredTextEditorActionConstants.ACTION_NAME_FORMAT_DOCUMENT)); - fFormatActiveElements.setAction(getAction(textEditor, StructuredTextEditorActionConstants.ACTION_NAME_FORMAT_ACTIVE_ELEMENTS)); - fCleanupDocument.setEnabled((textEditor != null) && textEditor.isEditable()); - fFormatDocument.setEnabled((textEditor != null) && textEditor.isEditable()); - fFormatActiveElements.setEnabled((textEditor != null) && textEditor.isEditable()); - - fOpenFileAction.setAction(getAction(textEditor, StructuredTextEditorActionConstants.ACTION_NAME_OPEN_FILE)); - - fFindOccurrences.setAction(getAction(textEditor, StructuredTextEditorActionConstants.ACTION_NAME_FIND_OCCURRENCES)); - - fGoToMatchingTagAction.setEditor(textEditor); - if (textEditor != null) { - textEditor.setAction(GO_TO_MATCHING_TAG_ID, fGoToMatchingTagAction); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.ISourceViewerActionBarContributor#setViewerSpecificContributionsEnabled(boolean) - */ - public void setViewerSpecificContributionsEnabled(boolean enabled) { - super.setViewerSpecificContributionsEnabled(enabled); - - fContentAssist.setEnabled(enabled); - // cleanup and format document actions do not rely on source viewer - // being enabled - // fCleanupDocument.setEnabled(enabled); - // fFormatDocument.setEnabled(enabled); - - fFormatActiveElements.setEnabled(enabled); - fOpenFileAction.setEnabled(enabled); - fFindOccurrences.setEnabled(enabled); - - fGoToMatchingTagAction.setEnabled(enabled); - fGotoMatchingBracketAction.setEnabled(enabled); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/AddBlockCommentActionXMLDelegate.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/AddBlockCommentActionXMLDelegate.java deleted file mode 100644 index a038376bea..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/AddBlockCommentActionXMLDelegate.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.wst.xml.ui.internal.actions; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.xml.core.internal.document.CommentImpl; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; - -/** - * Add block comment action delegate for XML editor - */ -public class AddBlockCommentActionXMLDelegate extends AbstractCommentActionXMLDelegate { - - public void init(IAction action) { - if (action != null) { - action.setText(XMLUIMessages.AddBlockComment_label); - action.setToolTipText(XMLUIMessages.AddBlockComment_tooltip); - action.setDescription(XMLUIMessages.AddBlockComment_description); - } - } - - void processAction(IDocument document, ITextSelection textSelection) { - IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForEdit(document); - if (model != null) { - try { - IndexedRegion selectionStartIndexedRegion = model.getIndexedRegion(textSelection.getOffset()); - IndexedRegion selectionEndIndexedRegion = model.getIndexedRegion(textSelection.getOffset() + textSelection.getLength()); - - if (selectionStartIndexedRegion == null) { - return; - } - if ((selectionEndIndexedRegion == null) && (textSelection.getLength() > 0)) { - selectionEndIndexedRegion = model.getIndexedRegion(textSelection.getOffset() + textSelection.getLength() - 1); - } - if (selectionEndIndexedRegion == null) { - return; - } - - int openCommentOffset = selectionStartIndexedRegion.getStartOffset(); - int closeCommentOffset = selectionEndIndexedRegion.getEndOffset() + OPEN_COMMENT.length(); - - - if ((textSelection.getLength() == 0) && (selectionStartIndexedRegion instanceof CommentImpl)) { - return; - } - - model.beginRecording(this, XMLUIMessages.AddBlockComment_tooltip); - model.aboutToChangeModel(); - - try { - document.replace(openCommentOffset, 0, OPEN_COMMENT); - document.replace(closeCommentOffset, 0, CLOSE_COMMENT); - removeOpenCloseComments(document, openCommentOffset + OPEN_COMMENT.length(), closeCommentOffset - openCommentOffset - CLOSE_COMMENT.length()); - } - catch (BadLocationException e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - finally { - model.changedModel(); - model.endRecording(this); - } - } - finally { - model.releaseFromEdit(); - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/BaseNodeActionManager.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/BaseNodeActionManager.java deleted file mode 100644 index 4629a23803..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/BaseNodeActionManager.java +++ /dev/null @@ -1,519 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.actions; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.w3c.dom.Attr; -import org.w3c.dom.Document; -import org.w3c.dom.DocumentType; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.w3c.dom.ProcessingInstruction; - -public abstract class BaseNodeActionManager { - - - /** - * MyMenuManager - */ - public static class MyMenuManager extends MenuManager { - protected String title; - - public MyMenuManager(String s) { - super(s); - title = s; - } - - public boolean isEnabled() { - return !isEmpty(); - } - - public String toString() { - return title; - } - } - - public static DocumentType getDoctype(Node node) { - Document document = (node.getNodeType() == Node.DOCUMENT_NODE) ? (Document) node : node.getOwnerDocument(); - return document.getDoctype(); - } - - protected MenuBuilder menuBuilder = new MenuBuilder(); - protected IStructuredModel fModel; - protected ModelQuery modelQuery; - - protected BaseNodeActionManager(IStructuredModel model, ModelQuery modelQuery) { - this.fModel = model; - this.modelQuery = modelQuery; - } - - - protected void addActionHelper(IMenuManager menu, List modelQueryActionList) { - List actionList = new Vector(); - for (Iterator i = modelQueryActionList.iterator(); i.hasNext();) { - ModelQueryAction action = (ModelQueryAction) i.next(); - if (action.getCMNode() != null) { - int cmNodeType = action.getCMNode().getNodeType(); - if (action.getKind() == ModelQueryAction.INSERT) { - switch (cmNodeType) { - case CMNode.ATTRIBUTE_DECLARATION : { - actionList.add(createAddAttributeAction((Element) action.getParent(), (CMAttributeDeclaration) action.getCMNode())); - break; - } - case CMNode.ELEMENT_DECLARATION : { - actionList.add(createAddElementAction(action.getParent(), (CMElementDeclaration) action.getCMNode(), action.getStartIndex())); - break; - } - } - } - else if (action.getKind() == ModelQueryAction.REPLACE) { - if ((action.getParent() != null) && (action.getCMNode() != null)) { - actionList.add(createReplaceAction(action.getParent(), action.getCMNode(), action.getStartIndex(), action.getEndIndex())); - } - } - } - } - menuBuilder.populateMenu(menu, actionList, false); - } - - protected void contributeAction(IMenuManager menu, Action action) { - if (action != null) { - menu.add(action); - } - } - - - public void contributeActions(IMenuManager menu, List selection) { - int editMode = modelQuery.getEditMode(); - int ic = ModelQuery.INCLUDE_CHILD_NODES; - int vc = (editMode == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) ? ModelQuery.VALIDITY_STRICT : ModelQuery.VALIDITY_NONE; - - List implicitlySelectedNodeList = null; - - if (selection.size() > 0) { - implicitlySelectedNodeList = getSelectedNodes(selection, true); - - // contribute delete actions - contributeDeleteActions(menu, implicitlySelectedNodeList, ic, vc); - } - - if (selection.size() == 1) { - Node node = (Node) selection.get(0); - - // contribute edit actions - contributeEditActions(menu, node); - - // contribute add child actions - contributeAddChildActions(menu, node, ic, vc); - - // contribute add before actions - contributeAddSiblingActions(menu, node, ic, vc); - } - - if (selection.size() > 0) { - // contribute replace actions - contributeReplaceActions(menu, implicitlySelectedNodeList, ic, vc); - } - - if (selection.size() == 0) { - Document document = ((IDOMModel) fModel).getDocument(); - contributeAddDocumentChildActions(menu, document, ic, vc); - contributeEditGrammarInformationActions(menu, document); - } - } - - - protected void contributeAddChildActions(IMenuManager menu, Node node, int ic, int vc) { - int nodeType = node.getNodeType(); - - if (nodeType == Node.ELEMENT_NODE) { - // 'Add Child...' and 'Add Attribute...' actions - // - Element element = (Element) node; - - IMenuManager addAttributeMenu = new MyMenuManager(XMLUIMessages._UI_MENU_ADD_ATTRIBUTE); - IMenuManager addChildMenu = new MyMenuManager(XMLUIMessages._UI_MENU_ADD_CHILD); - menu.add(addAttributeMenu); - menu.add(addChildMenu); - - CMElementDeclaration ed = modelQuery.getCMElementDeclaration(element); - if (ed != null) { - // add insert attribute actions - // - List modelQueryActionList = new ArrayList(); - modelQuery.getInsertActions(element, ed, -1, ModelQuery.INCLUDE_ATTRIBUTES, vc, modelQueryActionList); - addActionHelper(addAttributeMenu, modelQueryActionList); - - // add insert child node actions - // - modelQueryActionList = new ArrayList(); - modelQuery.getInsertActions(element, ed, -1, ic, vc, modelQueryActionList); - addActionHelper(addChildMenu, modelQueryActionList); - } - - // add PI and COMMENT - contributePIAndCommentActions(addChildMenu, element, ed, -1); - - // add PCDATA, CDATA_SECTION - contributeTextNodeActions(addChildMenu, element, ed, -1); - - // add NEW ELEMENT - contributeUnconstrainedAddElementAction(addChildMenu, element, ed, -1); - - // add ATTRIBUTE - contributeUnconstrainedAttributeActions(addAttributeMenu, element, ed); - } - } - - - protected void contributeAddDocumentChildActions(IMenuManager menu, Document document, int ic, int vc) { - IMenuManager addChildMenu = new MyMenuManager(XMLUIMessages._UI_MENU_ADD_CHILD); - menu.add(addChildMenu); - - // add PI and COMMENT - contributePIAndCommentActions(addChildMenu, document, -1); - - // add NEW ELEMENT - contributeUnconstrainedAddElementAction(addChildMenu, document, -1); - } - - - protected void contributeAddSiblingActions(IMenuManager menu, Node node, int ic, int vc) { - IMenuManager addBeforeMenu = new MyMenuManager(XMLUIMessages._UI_MENU_ADD_BEFORE); - IMenuManager addAfterMenu = new MyMenuManager(XMLUIMessages._UI_MENU_ADD_AFTER); - menu.add(addBeforeMenu); - menu.add(addAfterMenu); - - Node parentNode = node.getParentNode(); - if (parentNode != null) { - int index = getIndex(parentNode, node); - if (parentNode.getNodeType() == Node.ELEMENT_NODE) { - Element parentElement = (Element) parentNode; - CMElementDeclaration parentED = modelQuery.getCMElementDeclaration(parentElement); - if (parentED != null) { - // 'Add Before...' and 'Add After...' actions - // - List modelQueryActionList = new ArrayList(); - modelQuery.getInsertActions(parentElement, parentED, index, ic, vc, modelQueryActionList); - addActionHelper(addBeforeMenu, modelQueryActionList); - - modelQueryActionList = new ArrayList(); - modelQuery.getInsertActions(parentElement, parentED, index + 1, ic, vc, modelQueryActionList); - addActionHelper(addAfterMenu, modelQueryActionList); - } - - // add COMMENT and PI before and after - contributePIAndCommentActions(addBeforeMenu, parentElement, parentED, index); - contributePIAndCommentActions(addAfterMenu, parentElement, parentED, index + 1); - - // add PCDATA, CDATA_SECTION before and after - contributeTextNodeActions(addBeforeMenu, parentElement, parentED, index); - contributeTextNodeActions(addAfterMenu, parentElement, parentED, index + 1); - - // add NEW ELEMENT before and after - contributeUnconstrainedAddElementAction(addBeforeMenu, parentElement, parentED, index); - contributeUnconstrainedAddElementAction(addAfterMenu, parentElement, parentED, index + 1); - } - else if (parentNode.getNodeType() == Node.DOCUMENT_NODE) { - Document document = (Document) parentNode; - CMDocument cmDocument = modelQuery.getCorrespondingCMDocument(parentNode); - if (cmDocument != null) { - // add possible root element insertions - // - List modelQueryActionList = new ArrayList(); - modelQuery.getInsertActions(document, cmDocument, index, ic, vc, modelQueryActionList); - addActionHelper(addAfterMenu, modelQueryActionList); - - modelQueryActionList = new ArrayList(); - modelQuery.getInsertActions(document, cmDocument, index + 1, ic, vc, modelQueryActionList); - addActionHelper(addAfterMenu, modelQueryActionList); - } - - // add COMMENT and PI before and after - contributePIAndCommentActions(addBeforeMenu, document, index); - contributePIAndCommentActions(addAfterMenu, document, index + 1); - - // add ELEMENT before and after - contributeUnconstrainedAddElementAction(addBeforeMenu, document, index); - contributeUnconstrainedAddElementAction(addAfterMenu, document, index + 1); - } - } - } - - protected void contributeDeleteActions(IMenuManager menu, List list, int ic, int vc) { - boolean canRemove = modelQuery.canRemove(list, vc); - - - // a delete action with an empty list will produce a disabled menu - // item - // - List resultList = canRemove ? list : Collections.EMPTY_LIST; - contributeAction(menu, createDeleteAction(resultList)); - } - - - protected void contributeEditActions(IMenuManager menu, Node node) { - contributeEditGrammarInformationActions(menu, node); - - if (node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) { - contributeAction(menu, createEditProcessingInstructionAction((ProcessingInstruction) node)); - } - else if (node.getNodeType() == Node.ATTRIBUTE_NODE) { - contributeAction(menu, createEditAttributeAction((Attr) node, null)); - } - } - - - protected void contributeEditGrammarInformationActions(IMenuManager menu, Node node) { - Document document = node.getNodeType() == Node.DOCUMENT_NODE ? (Document) node : node.getOwnerDocument(); - - DocumentType doctype = getDoctype(node); - if (doctype == null) { - contributeAction(menu, createAddDoctypeAction(document, -1)); - } - - if (node.getNodeType() == Node.DOCUMENT_TYPE_NODE) { - contributeAction(menu, createEditDoctypeAction((DocumentType) node)); - } - - if ((doctype == null) && (getRootElement(document) != null)) { - contributeAction(menu, createEditSchemaInfoAction(getRootElement(document))); - } - } - - protected void contributePIAndCommentActions(IMenuManager menu, Document document, int index) { - // test to make sure that the index isn't before the XML declaration - // - contributeAction(menu, createAddCommentAction(document, index)); - contributeAction(menu, createAddProcessingInstructionAction(document, index)); - } - - - protected void contributePIAndCommentActions(IMenuManager menu, Element parentElement, CMElementDeclaration parentEd, int index) { - if ((parentEd == null) || isCommentAllowed(parentEd)) { - contributeAction(menu, createAddCommentAction(parentElement, index)); - contributeAction(menu, createAddProcessingInstructionAction(parentElement, index)); - } - } - - - protected void contributeReplaceActions(IMenuManager menu, List selectedNodeList, int ic, int vc) { - // 'Replace With...' actions - // - IMenuManager replaceWithMenu = new MyMenuManager(XMLUIMessages._UI_MENU_REPLACE_WITH); - menu.add(replaceWithMenu); - - if ((modelQuery.getEditMode() == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) && (selectedNodeList.size() > 0)) { - Node node = (Node) selectedNodeList.get(0); - Node parentNode = node.getParentNode(); - if ((parentNode != null) && (parentNode.getNodeType() == Node.ELEMENT_NODE)) { - Element parentElement = (Element) parentNode; - CMElementDeclaration parentED = modelQuery.getCMElementDeclaration(parentElement); - if (parentED != null) { - List replaceActionList = new Vector(); - modelQuery.getReplaceActions(parentElement, parentED, selectedNodeList, ic, vc, replaceActionList); - addActionHelper(replaceWithMenu, replaceActionList); - } - } - } - } - - protected void contributeTextNodeActions(IMenuManager menu, Element parentElement, CMElementDeclaration parentEd, int index) { - if ((parentEd == null) || isTextAllowed(parentEd)) { - CMDataType dataType = parentEd != null ? parentEd.getDataType() : null; - contributeAction(menu, createAddPCDataAction(parentElement, dataType, index)); - contributeAction(menu, createAddCDataSectionAction(parentElement, index)); - } - } - - - protected void contributeUnconstrainedAddElementAction(IMenuManager menu, Document document, int index) { - if (isUnconstrainedActionAllowed()) { - if (getRootElement(document) == null) { - int xmlDeclarationIndex = -1; - int doctypeIndex = -1; - NodeList nodeList = document.getChildNodes(); - int nodeListLength = nodeList.getLength(); - for (int i = 0; i < nodeListLength; i++) { - Node node = nodeList.item(i); - int nodeType = node.getNodeType(); - if (nodeType == Node.DOCUMENT_TYPE_NODE) { - doctypeIndex = i; - break; - } - else if (nodeType == Node.PROCESSING_INSTRUCTION_NODE) { - ProcessingInstruction pi = (ProcessingInstruction) node; - if (pi.getTarget().equalsIgnoreCase("xml") && (xmlDeclarationIndex == -1)) { //$NON-NLS-1$ - xmlDeclarationIndex = i; - } - } - } - - if (((xmlDeclarationIndex == -1) || (index > xmlDeclarationIndex)) && ((doctypeIndex == -1) || (index > doctypeIndex))) { - contributeAction(menu, createAddElementAction(document, null, index)); - } - } - } - } - - - protected void contributeUnconstrainedAddElementAction(IMenuManager menu, Element parentElement, CMElementDeclaration parentEd, int index) { - if (isUnconstrainedActionAllowed()) { - if ((parentEd == null) || (parentEd.getProperty("isInferred") == Boolean.TRUE) || ((modelQuery.getEditMode() != ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) && isElementAllowed(parentEd))) { //$NON-NLS-1$ - contributeAction(menu, createAddElementAction(parentElement, null, index)); - } - } - } - - - protected void contributeUnconstrainedAttributeActions(IMenuManager menu, Element parentElement, CMElementDeclaration parentEd) { - if (isUnconstrainedActionAllowed()) { - if ((parentEd == null) || (parentEd.getProperty("isInferred") == Boolean.TRUE) || (modelQuery.getEditMode() != ModelQuery.EDIT_MODE_CONSTRAINED_STRICT)) { //$NON-NLS-1$ - contributeAction(menu, createAddAttributeAction(parentElement, null)); - } - } - } - - abstract protected Action createAddAttributeAction(Element parent, CMAttributeDeclaration ad); - - abstract protected Action createAddCDataSectionAction(Node parent, int index); - - abstract protected Action createAddCommentAction(Node parent, int index); - - abstract protected Action createAddDoctypeAction(Document parent, int index); - - abstract protected Action createAddElementAction(Node parent, CMElementDeclaration ed, int index); - - abstract protected Action createAddPCDataAction(Node parent, CMDataType dataType, int index); - - abstract protected Action createAddProcessingInstructionAction(Node parent, int index); - - abstract protected Action createAddSchemaInfoAction(Element element); - - abstract protected Action createDeleteAction(List selection); - - abstract protected Action createEditAttributeAction(Attr attribute, CMAttributeDeclaration ad); - - abstract protected Action createEditDoctypeAction(DocumentType doctype); - - abstract protected Action createEditProcessingInstructionAction(ProcessingInstruction pi); - - abstract protected Action createEditSchemaInfoAction(Element element); - - abstract protected Action createRenameAction(Node node); - - abstract protected Action createReplaceAction(Node parent, CMNode cmnode, int startIndex, int endIndex); - - - public int getIndex(Node parentNode, Node child) { - NodeList nodeList = parentNode.getChildNodes(); - int index = -1; - int size = nodeList.getLength(); - for (int i = 0; i < size; i++) { - if (nodeList.item(i) == child) { - index = i; - break; - } - } - return index; - } - - - public Node getRefChildNodeAtIndex(Node parent, int index) { - NodeList nodeList = parent.getChildNodes(); - Node refChild = ((index >= 0) && (index < nodeList.getLength())) ? nodeList.item(index) : null; - return refChild; - } - - - protected Element getRootElement(Document document) { - Element result = null; - NodeList nodeList = document.getChildNodes(); - int nodeListLength = nodeList.getLength(); - for (int i = 0; i < nodeListLength; i++) { - Node node = nodeList.item(i); - if (node.getNodeType() == Node.ELEMENT_NODE) { - result = (Element) node; - break; - } - } - return result; - } - - - protected List getSelectedNodes(List list, boolean includeTextNodes) { - List result = new ArrayList(0); - for (Iterator i = list.iterator(); i.hasNext();) { - Object object = i.next(); - if (object instanceof Node) { - Node node = (Node) object; - if (node.getNodeType() == Node.TEXT_NODE) { - if (includeTextNodes) { - result.add(object); - } - } - else { - result.add(node); - } - } - } - return result; - } - - - protected boolean isCommentAllowed(CMElementDeclaration parentEd) { - int contentType = parentEd.getContentType(); - return (contentType == CMElementDeclaration.ELEMENT) || (contentType == CMElementDeclaration.MIXED) || (contentType == CMElementDeclaration.PCDATA) || (contentType == CMElementDeclaration.ANY); - } - - - protected boolean isElementAllowed(CMElementDeclaration parentEd) { - int contentType = parentEd.getContentType(); - return (contentType == CMElementDeclaration.ELEMENT) || (contentType == CMElementDeclaration.MIXED) || (contentType == CMElementDeclaration.ANY); - } - - - protected boolean isTextAllowed(CMElementDeclaration parentEd) { - int contentType = parentEd.getContentType(); - return (contentType == CMElementDeclaration.MIXED) || (contentType == CMElementDeclaration.PCDATA) || (contentType == CMElementDeclaration.ANY); - } - - - protected boolean isUnconstrainedActionAllowed() { - return true; - } - - - protected boolean isWhitespaceTextNode(Node node) { - return (node != null) && (node.getNodeType() == Node.TEXT_NODE) && (node.getNodeValue().trim().length() == 0); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/CleanupActionXMLDelegate.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/CleanupActionXMLDelegate.java deleted file mode 100644 index d91a815d7b..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/CleanupActionXMLDelegate.java +++ /dev/null @@ -1,139 +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.wst.xml.ui.internal.actions; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.widgets.Event; -import org.eclipse.ui.IActionDelegate2; -import org.eclipse.ui.IEditorActionDelegate; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IViewActionDelegate; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupProcessor; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.ui.internal.SSEUIMessages; -import org.eclipse.wst.xml.core.internal.cleanup.CleanupProcessorXML; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; - -/** - * Cleanup action delegate for CSS editor - */ -public class CleanupActionXMLDelegate implements IEditorActionDelegate, IActionDelegate2, IViewActionDelegate { - private IEditorPart fEditor; - private IStructuredCleanupProcessor fCleanupProcessor; - - public void setActiveEditor(IAction action, IEditorPart targetEditor) { - fEditor = targetEditor; - } - - public void dispose() { - // nulling out just in case - fEditor = null; - fCleanupProcessor = null; - } - - public void init(IAction action) { - if (action != null) { - action.setText(XMLUIMessages.CleanupDocument_label); - action.setToolTipText(XMLUIMessages.CleanupDocument_tooltip); - action.setDescription(XMLUIMessages.CleanupDocument_description); - } - } - - public void runWithEvent(IAction action, Event event) { - run(action); - } - - public void init(IViewPart view) { - // do nothing - } - - public void run(IAction action) { - if (fEditor instanceof ITextEditor) { - final ITextEditor editor = (ITextEditor) fEditor; - Dialog cleanupDialog = new CleanupDialogXML(editor.getSite().getShell()); - if (cleanupDialog.open() == Window.OK) { - // setup runnable - Runnable runnable = new Runnable() { - public void run() { - IStructuredCleanupProcessor cleanupProcessor = getCleanupProcessor(); - if (cleanupProcessor != null) { - IStructuredModel model = null; - try { - model = StructuredModelManager.getModelManager().getExistingModelForEdit(editor.getDocumentProvider().getDocument(editor.getEditorInput())); - if (model != null) { - cleanupProcessor.cleanupModel(model); - } - } - finally { - if (model != null) { - model.releaseFromEdit(); - } - } - } - } - }; - - // TODO: make independent of 'model'. - IStructuredModel model = null; - try { - model = StructuredModelManager.getModelManager().getExistingModelForEdit(editor.getDocumentProvider().getDocument(editor.getEditorInput())); - if (model != null) { - // begin recording - ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection(); - model.beginRecording(this, SSEUIMessages.Cleanup_Document_UI_, SSEUIMessages.Cleanup_Document_UI_, selection.getOffset(), selection.getLength()); - - // tell the model that we are about to make a big - // model change - model.aboutToChangeModel(); - - // run - BusyIndicator.showWhile(fEditor.getEditorSite().getWorkbenchWindow().getShell().getDisplay(), runnable); - } - } - finally { - if (model != null) { - // tell the model that we are done with the big - // model - // change - model.changedModel(); - - // end recording - ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection(); - model.endRecording(this, selection.getOffset(), selection.getLength()); - model.releaseFromEdit(); - } - } - } - } - } - - public void selectionChanged(IAction action, ISelection selection) { - // do nothing - } - - IStructuredCleanupProcessor getCleanupProcessor() { - if (fCleanupProcessor == null) { - fCleanupProcessor = new CleanupProcessorXML(); - } - - return fCleanupProcessor; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/CleanupDialogXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/CleanupDialogXML.java deleted file mode 100644 index 97b718a81e..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/CleanupDialogXML.java +++ /dev/null @@ -1,204 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.actions; - -import org.eclipse.core.runtime.Preferences; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -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.Shell; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.editor.IHelpContextIds; - -public class CleanupDialogXML extends Dialog implements SelectionListener { - protected Button fCheckBoxCompressEmptyElementTags; - protected Button fCheckBoxConvertEOLCodes; - protected Button fCheckBoxFormatSource; - protected Button fCheckBoxInsertMissingTags; - protected Button fCheckBoxInsertRequiredAttrs; - protected Button fCheckBoxQuoteAttrValues; - protected IStructuredModel fModel = null; - protected Preferences fPreferences = null; - protected Button fRadioButtonAttrNameCaseAsis; - protected Button fRadioButtonAttrNameCaseLower; - protected Button fRadioButtonAttrNameCaseUpper; - protected Button fRadioButtonConvertEOLMac; - protected Button fRadioButtonConvertEOLUnix; - protected Button fRadioButtonConvertEOLWindows; - - protected Button fRadioButtonTagNameCaseAsis; - protected Button fRadioButtonTagNameCaseLower; - protected Button fRadioButtonTagNameCaseUpper; - - public CleanupDialogXML(Shell shell) { - - super(shell); - } - - public Control createDialogArea(Composite parent) { - - getShell().setText(XMLUIMessages.Cleanup_UI_); - Composite composite = new Composite(parent, SWT.NULL); - createDialogAreaInComposite(composite); - initializeOptions(); - return composite; - } - - protected void createDialogAreaInComposite(Composite composite) { - - PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.CLEANUP_XML_HELPID); // use - // XML - // specific - // help - - GridLayout layout = new GridLayout(); - layout.numColumns = 1; - layout.makeColumnsEqualWidth = true; - composite.setLayout(layout); - - // Compress empty element tags - fCheckBoxCompressEmptyElementTags = new Button(composite, SWT.CHECK); - fCheckBoxCompressEmptyElementTags.setText(XMLUIMessages.Compress_empty_element_tags_UI_); - fCheckBoxCompressEmptyElementTags.addSelectionListener(this); - - // Insert missing required attrs - fCheckBoxInsertRequiredAttrs = new Button(composite, SWT.CHECK); - fCheckBoxInsertRequiredAttrs.setText(XMLUIMessages.Insert_required_attributes_UI_); - fCheckBoxInsertRequiredAttrs.addSelectionListener(this); - - // Insert missing begin/end tags - fCheckBoxInsertMissingTags = new Button(composite, SWT.CHECK); - fCheckBoxInsertMissingTags.setText(XMLUIMessages.Insert_missing_tags_UI_); - fCheckBoxInsertMissingTags.addSelectionListener(this); - - // Quote attribute values - fCheckBoxQuoteAttrValues = new Button(composite, SWT.CHECK); - fCheckBoxQuoteAttrValues.setText(XMLUIMessages.Quote_attribute_values_UI_); - fCheckBoxQuoteAttrValues.addSelectionListener(this); - - // Format source - fCheckBoxFormatSource = new Button(composite, SWT.CHECK); - fCheckBoxFormatSource.setText(XMLUIMessages.Format_source_UI_); - fCheckBoxFormatSource.addSelectionListener(this); - - // Convert EOL code - fCheckBoxConvertEOLCodes = new Button(composite, SWT.CHECK); - fCheckBoxConvertEOLCodes.setText(XMLUIMessages.Convert_EOL_codes_UI_); - fCheckBoxConvertEOLCodes.addSelectionListener(this); - Composite EOLCodes = new Composite(composite, SWT.NULL); - GridLayout hLayout = new GridLayout(); - hLayout.numColumns = 3; - EOLCodes.setLayout(hLayout); - fRadioButtonConvertEOLWindows = new Button(EOLCodes, SWT.RADIO); - fRadioButtonConvertEOLWindows.setText(XMLUIMessages.EOL_Windows_UI); - fRadioButtonConvertEOLWindows.addSelectionListener(this); - fRadioButtonConvertEOLUnix = new Button(EOLCodes, SWT.RADIO); - fRadioButtonConvertEOLUnix.setText(XMLUIMessages.EOL_Unix_UI); - fRadioButtonConvertEOLUnix.addSelectionListener(this); - fRadioButtonConvertEOLMac = new Button(EOLCodes, SWT.RADIO); - fRadioButtonConvertEOLMac.setText(XMLUIMessages.EOL_Mac_UI); - fRadioButtonConvertEOLMac.addSelectionListener(this); - } - - protected void enableEOLCodeRadios(boolean enable) { - - if ((fRadioButtonConvertEOLWindows != null) && (fRadioButtonConvertEOLUnix != null) && (fRadioButtonConvertEOLMac != null)) { - fRadioButtonConvertEOLWindows.setEnabled(enable); - fRadioButtonConvertEOLUnix.setEnabled(enable); - fRadioButtonConvertEOLMac.setEnabled(enable); - if (!fRadioButtonConvertEOLWindows.getSelection() && !fRadioButtonConvertEOLUnix.getSelection() && !fRadioButtonConvertEOLMac.getSelection()) { - fRadioButtonConvertEOLWindows.setSelection(true); - } - } - } - - protected Preferences getModelPreferences() { - return XMLCorePlugin.getDefault().getPluginPreferences(); - } - - protected void initializeOptions() { - - fCheckBoxCompressEmptyElementTags.setSelection(getModelPreferences().getBoolean(XMLCorePreferenceNames.COMPRESS_EMPTY_ELEMENT_TAGS)); - fCheckBoxInsertRequiredAttrs.setSelection(getModelPreferences().getBoolean(XMLCorePreferenceNames.INSERT_REQUIRED_ATTRS)); - fCheckBoxInsertMissingTags.setSelection(getModelPreferences().getBoolean(XMLCorePreferenceNames.INSERT_MISSING_TAGS)); - fCheckBoxQuoteAttrValues.setSelection(getModelPreferences().getBoolean(XMLCorePreferenceNames.QUOTE_ATTR_VALUES)); - fCheckBoxFormatSource.setSelection(getModelPreferences().getBoolean(XMLCorePreferenceNames.FORMAT_SOURCE)); - fCheckBoxConvertEOLCodes.setSelection(getModelPreferences().getBoolean(XMLCorePreferenceNames.CONVERT_EOL_CODES)); - String EOLCode = getModelPreferences().getString(XMLCorePreferenceNames.CLEANUP_EOL_CODE); - if (EOLCode.compareTo(CommonEncodingPreferenceNames.LF) == 0) { - fRadioButtonConvertEOLUnix.setSelection(true); - } - else if (EOLCode.compareTo(CommonEncodingPreferenceNames.CR) == 0) { - fRadioButtonConvertEOLMac.setSelection(true); - } - else { - fRadioButtonConvertEOLWindows.setSelection(true); - } - enableEOLCodeRadios(fCheckBoxConvertEOLCodes.getSelection()); - } - - protected void okPressed() { - - storeOptions(); - super.okPressed(); - } - - public void setModel(IStructuredModel model) { - - fModel = model; - } - - protected void storeOptions() { - - getModelPreferences().setValue(XMLCorePreferenceNames.COMPRESS_EMPTY_ELEMENT_TAGS, fCheckBoxCompressEmptyElementTags.getSelection()); - getModelPreferences().setValue(XMLCorePreferenceNames.INSERT_REQUIRED_ATTRS, fCheckBoxInsertRequiredAttrs.getSelection()); - getModelPreferences().setValue(XMLCorePreferenceNames.INSERT_MISSING_TAGS, fCheckBoxInsertMissingTags.getSelection()); - getModelPreferences().setValue(XMLCorePreferenceNames.QUOTE_ATTR_VALUES, fCheckBoxQuoteAttrValues.getSelection()); - getModelPreferences().setValue(XMLCorePreferenceNames.FORMAT_SOURCE, fCheckBoxFormatSource.getSelection()); - getModelPreferences().setValue(XMLCorePreferenceNames.CONVERT_EOL_CODES, fCheckBoxConvertEOLCodes.getSelection()); - if (fRadioButtonConvertEOLUnix.getSelection()) { - getModelPreferences().setValue(XMLCorePreferenceNames.CLEANUP_EOL_CODE, CommonEncodingPreferenceNames.LF); - } - else if (fRadioButtonConvertEOLMac.getSelection()) { - getModelPreferences().setValue(XMLCorePreferenceNames.CLEANUP_EOL_CODE, CommonEncodingPreferenceNames.CR); - } - else { - getModelPreferences().setValue(XMLCorePreferenceNames.CLEANUP_EOL_CODE, CommonEncodingPreferenceNames.CRLF); - } - // explicitly save plugin preferences so values are stored - XMLCorePlugin.getDefault().savePluginPreferences(); - } - - public void widgetDefaultSelected(SelectionEvent e) { - - widgetSelected(e); - } - - public void widgetSelected(SelectionEvent e) { - - getButton(OK).setEnabled(((fRadioButtonTagNameCaseLower != null) && (fRadioButtonTagNameCaseLower.getSelection() || fRadioButtonTagNameCaseUpper.getSelection())) || ((fRadioButtonAttrNameCaseLower != null) && (fRadioButtonAttrNameCaseLower.getSelection() || fRadioButtonAttrNameCaseUpper.getSelection())) || fCheckBoxInsertMissingTags.getSelection() || fCheckBoxQuoteAttrValues.getSelection() || fCheckBoxFormatSource.getSelection() || fCheckBoxConvertEOLCodes.getSelection() || ((fRadioButtonConvertEOLUnix != null) && (fRadioButtonConvertEOLUnix.getSelection() || fRadioButtonConvertEOLMac.getSelection() || fRadioButtonConvertEOLWindows.getSelection()))); - if (e.widget == fCheckBoxConvertEOLCodes) { - enableEOLCodeRadios(fCheckBoxConvertEOLCodes.getSelection()); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditAttributeAction.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditAttributeAction.java deleted file mode 100644 index 3da8aa7b48..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditAttributeAction.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.actions; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.internal.dialogs.EditAttributeDialog; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages; -import org.w3c.dom.Attr; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -public class EditAttributeAction extends NodeAction { - protected static ImageDescriptor imageDescriptor; - - public static ImageDescriptor createImageDescriptor() { - if (imageDescriptor == null) { - imageDescriptor = XMLEditorPluginImageHelper.getInstance().getImageDescriptor(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE); - } - return imageDescriptor; - } - - protected Attr attr; - protected AbstractNodeActionManager manager; - protected Element ownerElement; - protected String title; - - public EditAttributeAction(AbstractNodeActionManager manager, Element ownerElement, Attr attr, String actionLabel, String title) { - this.manager = manager; - this.ownerElement = ownerElement; - this.attr = attr; - this.title = title; - setText(actionLabel); - // assume if attr is null then this is an 'Add' that requires action - // an icons... otherwise this is an edit - if (attr == null) { - setImageDescriptor(createImageDescriptor()); - } - } - - public String getUndoDescription() { - return title; - } - - public void run() { - manager.beginNodeAction(this); - Shell shell = XMLUIPlugin.getInstance().getWorkbench().getActiveWorkbenchWindow().getShell(); - EditAttributeDialog dialog = new EditAttributeDialog(shell, ownerElement, attr); - dialog.create(); - dialog.getShell().setText(title); - dialog.setBlockOnOpen(true); - dialog.open(); - - if (dialog.getReturnCode() == Window.OK) { - if (attr != null) { - ownerElement.removeAttributeNode(attr); - } - Document document = ownerElement.getOwnerDocument(); - Attr newAttribute = document.createAttribute(dialog.getAttributeName()); - newAttribute.setValue(dialog.getAttributeValue()); - ownerElement.setAttributeNode(newAttribute); - manager.setViewerSelection(newAttribute); - } - manager.endNodeAction(this); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditDoctypeAction.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditDoctypeAction.java deleted file mode 100644 index 6330044396..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditDoctypeAction.java +++ /dev/null @@ -1,191 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.actions; - -import org.eclipse.core.runtime.Path; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.xml.core.internal.document.DocumentImpl; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocumentType; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.dialogs.EditDoctypeDialog; -import org.w3c.dom.Document; -import org.w3c.dom.DocumentType; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -/** - * EditDoctypeAction - */ -public class EditDoctypeAction extends Action { - protected DocumentType doctype; - protected Document document; - protected IStructuredModel model; - protected String resourceLocation; - protected String title; - - /** - * This constructor is used to create a new doctype. - */ - public EditDoctypeAction(IStructuredModel model, Document document, String resourceLocation, String title) { - setText(title); - this.model = model; - this.document = document; - this.resourceLocation = resourceLocation; - this.title = title; - } - - /** - * This constructor is used to edit an exisitng doctype. - */ - public EditDoctypeAction(IStructuredModel model, DocumentType doctype, String resourceLocation, String title) { - setText(title); - this.model = model; - this.doctype = doctype; - this.resourceLocation = resourceLocation; - this.title = title; - } - - - protected DocumentType createDoctype(EditDoctypeDialog dialog, Document document) { - DocumentType result = null; - if (document instanceof DocumentImpl) { - IDOMDocument documentImpl = (IDOMDocument) document; - IDOMDocumentType doctypeImpl = (IDOMDocumentType) documentImpl.createDoctype(dialog.getName()); - doctypeImpl.setPublicId(dialog.getPublicId()); - doctypeImpl.setSystemId(dialog.getSystemId()); - result = doctypeImpl; - } - return result; - } - - private Display getDisplay() { - - return PlatformUI.getWorkbench().getDisplay(); - } - - - protected String getRootElementName(Document document) { - Element rootElement = null; - NodeList nodeList = document.getChildNodes(); - int nodeListLength = nodeList.getLength(); - for (int i = 0; i < nodeListLength; i++) { - Node childNode = nodeList.item(i); - if (childNode.getNodeType() == Node.ELEMENT_NODE) { - rootElement = (Element) childNode; - break; - } - } - return rootElement != null ? rootElement.getNodeName() : XMLUIMessages._UI_LABEL_ROOT_ELEMENT_VALUE; - } - - public String getUndoDescription() { - return title; - } - - - protected void insertDoctype(DocumentType doctype, Document document) { - Node refChild = null; - NodeList nodeList = document.getChildNodes(); - int nodeListLength = nodeList.getLength(); - for (int i = 0; i < nodeListLength; i++) { - Node childNode = nodeList.item(i); - if ((childNode.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) || (childNode.getNodeType() == Node.COMMENT_NODE)) { - // continue on to the nextNode - } - else { - refChild = childNode; - break; - } - } - - document.insertBefore(doctype, refChild); - // manager.reformat(doctype, false); - } - - public void run() { - model.beginRecording(this, getUndoDescription()); - // Shell shell = - // XMLCommonUIPlugin.getInstance().getWorkbench().getActiveWorkbenchWindow().getShell(); - Shell shell = getDisplay().getActiveShell(); - EditDoctypeDialog dialog = showEditDoctypeDialog(shell); - - if (dialog.getReturnCode() == Window.OK) { - if (doctype != null) { - updateDoctype(dialog, doctype); - } - else if (document != null) { - DocumentType doctype = createDoctype(dialog, document); - if (doctype != null) { - insertDoctype(doctype, document); - } - } - } - model.endRecording(this); - } - - protected EditDoctypeDialog showEditDoctypeDialog(Shell shell) { - EditDoctypeDialog dialog = null; - - if (doctype != null) { - dialog = new EditDoctypeDialog(shell, doctype); - if (title == null) { - title = XMLUIMessages._UI_LABEL_EDIT_DOCTYPE; - } - } - else if (document != null) { - String rootElementName = getRootElementName(document); - dialog = new EditDoctypeDialog(shell, rootElementName, "", rootElementName + ".dtd"); //$NON-NLS-1$ //$NON-NLS-2$ - if (title == null) { - title = XMLUIMessages._UI_MENU_ADD_DTD_INFORMATION_TITLE; - } - } - - dialog.setComputeSystemId((doctype == null) || (doctype.getSystemId() == null) || (doctype.getSystemId().trim().length() == 0)); - - dialog.setErrorChecking(false);// !model.getType().equals(IStructuredModel.HTML)); - dialog.create(); - dialog.getShell().setText(title); - dialog.setBlockOnOpen(true); - dialog.setResourceLocation(new Path(resourceLocation)); - dialog.open(); - - return dialog; - } - - - protected void updateDoctype(EditDoctypeDialog dialog, DocumentType doctype) { - if (doctype instanceof IDOMDocumentType) { - IDOMDocumentType doctypeImpl = (IDOMDocumentType) doctype; - if (doctypeImpl.getName().equals(dialog.getName())) { - doctypeImpl.setPublicId(dialog.getPublicId()); - doctypeImpl.setSystemId(dialog.getSystemId()); - } - else { - // we need to create a new one and remove the old - // - Document document = doctype.getOwnerDocument(); - DocumentType newDoctype = createDoctype(dialog, document); - document.insertBefore(newDoctype, doctype); - document.removeChild(doctype); - // manager.reformat(newDoctype, false); - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditElementAction.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditElementAction.java deleted file mode 100644 index b94426844c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditElementAction.java +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.actions; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.internal.dialogs.EditElementDialog; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -public class EditElementAction extends NodeAction { - - protected static ImageDescriptor imageDescriptor; - - public static ImageDescriptor createImageDescriptor() { - if (imageDescriptor == null) { - imageDescriptor = XMLEditorPluginImageHelper.getInstance().getImageDescriptor(XMLEditorPluginImages.IMG_OBJ_ELEMENT); - } - return imageDescriptor; - } - - protected Element element; - protected int insertionIndex = -1; - protected AbstractNodeActionManager manager; - protected Node parent; - protected String title; - - public EditElementAction(AbstractNodeActionManager manager, Element element, String actionLabel, String dialogTitle) { - this(manager, element.getParentNode(), -1, element, actionLabel, dialogTitle); - } - - protected EditElementAction(AbstractNodeActionManager manager, Node parent, int index, Element element, String actionLabel, String title) { - this.manager = manager; - this.parent = parent; - this.insertionIndex = index; - this.element = element; - this.title = title; - setText(actionLabel); - if (element == null) { - setImageDescriptor(createImageDescriptor()); - } - } - - public EditElementAction(AbstractNodeActionManager manager, Node parent, int index, String actionLabel, String title) { - this(manager, parent, index, null, actionLabel, title); - } - - public String getUndoDescription() { - return title; - } - - public void run() { - manager.beginNodeAction(this); - Shell shell = XMLUIPlugin.getInstance().getWorkbench().getActiveWorkbenchWindow().getShell(); - EditElementDialog dialog = new EditElementDialog(shell, element); - dialog.create(); - dialog.getShell().setText(title); - dialog.setBlockOnOpen(true); - dialog.open(); - - if (dialog.getReturnCode() == Window.OK) { - Document document = parent.getNodeType() == Node.DOCUMENT_NODE ? (Document) parent : parent.getOwnerDocument(); - if (element != null) { - // here we need to do a rename... which seems to be quite hard - // to do :-( - if (element instanceof IDOMElement) { - IDOMElement elementImpl = (IDOMElement) element; - IDOMModel model = elementImpl.getModel(); - String oldName = elementImpl.getNodeName(); - String newName = dialog.getElementName(); - setStructuredDocumentRegionElementName(model, elementImpl.getStartStructuredDocumentRegion(), oldName, newName); - setStructuredDocumentRegionElementName(model, elementImpl.getEndStructuredDocumentRegion(), oldName, newName); - } - } - else { - Element newElement = document.createElement(dialog.getElementName()); - NodeList nodeList = parent.getChildNodes(); - int nodeListLength = nodeList.getLength(); - Node refChild = (insertionIndex < nodeListLength) && (insertionIndex >= 0) ? nodeList.item(insertionIndex) : null; - parent.insertBefore(newElement, refChild); - manager.reformat(newElement, false); - manager.setViewerSelection(newElement); - } - } - manager.endNodeAction(this); - } - - protected void setStructuredDocumentRegionElementName(IDOMModel model, IStructuredDocumentRegion flatNode, String oldName, String newName) { - if (flatNode != null) { - String string = flatNode.getText(); - int index = string.indexOf(oldName); - if (index != -1) { - index += flatNode.getStart(); - model.getStructuredDocument().replaceText(this, index, oldName.length(), newName); - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditProcessingInstructionAction.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditProcessingInstructionAction.java deleted file mode 100644 index 9dec301c01..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditProcessingInstructionAction.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.actions; - -import org.eclipse.jface.window.Window; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.internal.dialogs.EditProcessingInstructionDialog; -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.w3c.dom.ProcessingInstruction; - -/** - * EditProcessingInstructionAction - */ -public class EditProcessingInstructionAction extends NodeAction { - protected Node childRef; - protected AbstractNodeActionManager manager; - protected Node parent; - protected ProcessingInstruction pi; - protected String title; - - /** - * This constructor is used to add a new ProcessingInstruction - */ - public EditProcessingInstructionAction(AbstractNodeActionManager manager, Node parent, Node childRef, String actionLabel, String title) { - setText(actionLabel); - this.manager = manager; - this.parent = parent; - this.childRef = childRef; - this.title = title; - } - - /** - * This constructor is used to edit a ProcessingInstruction - */ - public EditProcessingInstructionAction(AbstractNodeActionManager manager, ProcessingInstruction pi, String actionLabel, String title) { - setText(actionLabel); - this.manager = manager; - this.pi = pi; - this.parent = pi.getParentNode(); - this.title = title; - } - - public String getUndoDescription() { - return title; - } - - public void run() { - manager.beginNodeAction(this); - Shell shell = XMLUIPlugin.getInstance().getWorkbench().getActiveWorkbenchWindow().getShell(); - - EditProcessingInstructionDialog dialog = null; - if (pi != null) { - dialog = new EditProcessingInstructionDialog(shell, pi); - } - else { - dialog = new EditProcessingInstructionDialog(shell, XMLUIMessages._UI_PI_TARGET_VALUE, XMLUIMessages._UI_PI_DATA_VALUE); - } - - dialog.create(); - dialog.getShell().setText(title); - dialog.setBlockOnOpen(true); - dialog.open(); - - if (dialog.getReturnCode() == Window.OK) { - if (pi != null) { - childRef = pi; - } - - Document document = parent.getNodeType() == Node.DOCUMENT_NODE ? (Document) parent : parent.getOwnerDocument(); - Node newNode = document.createProcessingInstruction(dialog.getTarget(), dialog.getData()); - parent.insertBefore(newNode, childRef); - - if (pi != null) { - parent.removeChild(pi); - } - - manager.reformat(newNode, false); - manager.setViewerSelection(newNode); - } - manager.endNodeAction(this); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditSchemaInfoAction.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditSchemaInfoAction.java deleted file mode 100644 index 699492cd1a..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/EditSchemaInfoAction.java +++ /dev/null @@ -1,166 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.actions; - -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.runtime.Path; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMNamespaceInfoManager; -import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.internal.dialogs.EditSchemaInfoDialog; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -/** - * EditDoctypeAction - */ -public class EditSchemaInfoAction extends NodeAction { - protected AbstractNodeActionManager manager; - protected DOMNamespaceInfoManager namespaceInfoManager = new DOMNamespaceInfoManager(); - protected Node node; - protected String resourceLocation; - protected String title; - - public EditSchemaInfoAction(AbstractNodeActionManager manager, Node node, String resourceLocation, String title) { - this.manager = manager; - this.node = node; - setText(title); - this.resourceLocation = resourceLocation; - this.title = title; - } - - protected Map createPrefixMapping(List oldList, List newList) { - Map map = new Hashtable(); - - Hashtable oldURIToPrefixTable = new Hashtable(); - for (Iterator i = oldList.iterator(); i.hasNext();) { - NamespaceInfo oldInfo = (NamespaceInfo) i.next(); - oldURIToPrefixTable.put(oldInfo.uri, oldInfo); - } - - for (Iterator i = newList.iterator(); i.hasNext();) { - NamespaceInfo newInfo = (NamespaceInfo) i.next(); - NamespaceInfo oldInfo = (NamespaceInfo) oldURIToPrefixTable.get(newInfo.uri != null ? newInfo.uri : ""); //$NON-NLS-1$ - - - // if oldInfo is non null ... there's a matching URI in the old - // set - // we can use its prefix to detemine out mapping - // - // if oldInfo is null ... we use the 'oldCopy' we stashed away - // assuming that the user changed the URI and the prefix - if (oldInfo == null) { - oldInfo = (NamespaceInfo) newInfo.getProperty("oldCopy"); //$NON-NLS-1$ - } - - if (oldInfo != null) { - String newPrefix = newInfo.prefix != null ? newInfo.prefix : ""; //$NON-NLS-1$ - String oldPrefix = oldInfo.prefix != null ? oldInfo.prefix : ""; //$NON-NLS-1$ - if (!oldPrefix.equals(newPrefix)) { - map.put(oldPrefix, newPrefix); - } - } - } - return map; - } - - public Element getElement(Node node) { - Element result = null; - if (node.getNodeType() == Node.ELEMENT_NODE) { - result = (Element) node; - } - else if (node.getNodeType() == Node.DOCUMENT_NODE) { - result = getRootElement((Document) node); - } - return result; - } - - - public Element getRootElement(Document document) { - Element rootElement = null; - NodeList nodeList = document.getChildNodes(); - int nodeListLength = nodeList.getLength(); - for (int i = 0; i < nodeListLength; i++) { - Node childNode = nodeList.item(i); - if (childNode.getNodeType() == Node.ELEMENT_NODE) { - rootElement = (Element) childNode; - break; - } - } - return rootElement; - } - - public String getUndoDescription() { - return title; - } - - public void run() { - manager.beginNodeAction(this); - - // todo... change constructor to take an element - Element element = getElement(node); - if (element != null) { - Shell shell = XMLUIPlugin.getInstance().getWorkbench().getActiveWorkbenchWindow().getShell(); - EditSchemaInfoDialog dialog = new EditSchemaInfoDialog(shell, new Path(resourceLocation)); - - List namespaceInfoList = namespaceInfoManager.getNamespaceInfoList(element); - List oldNamespaceInfoList = NamespaceInfo.cloneNamespaceInfoList(namespaceInfoList); - - // here we store a copy of the old info for each NamespaceInfo - // this info will be used in createPrefixMapping() to figure out - // how to update the document - // in response to these changes - for (Iterator i = namespaceInfoList.iterator(); i.hasNext();) { - NamespaceInfo info = (NamespaceInfo) i.next(); - NamespaceInfo oldCopy = new NamespaceInfo(info); - info.setProperty("oldCopy", oldCopy); //$NON-NLS-1$ - } - - dialog.setNamespaceInfoList(namespaceInfoList); - dialog.create(); - // dialog.getShell().setSize(500, 300); - dialog.getShell().setText(XMLUIMessages._UI_MENU_EDIT_SCHEMA_INFORMATION_TITLE); - dialog.setBlockOnOpen(true); - dialog.open(); - - if (dialog.getReturnCode() == Window.OK) { - List newInfoList = dialog.getNamespaceInfoList(); - namespaceInfoManager.removeNamespaceInfo(element); - namespaceInfoManager.addNamespaceInfo(element, newInfoList, true); - - // see if we need to rename any prefixes - Map prefixMapping = createPrefixMapping(oldNamespaceInfoList, namespaceInfoList); - if (prefixMapping.size() > 0) { - try { - manager.getModel().aboutToChangeModel(); - ReplacePrefixAction replacePrefixAction = new ReplacePrefixAction(manager, element, prefixMapping); - replacePrefixAction.run(); - } - finally { - manager.getModel().changedModel(); - } - } - } - } - manager.endNodeAction(this); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/GoToMatchingTagAction.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/GoToMatchingTagAction.java deleted file mode 100644 index 823cd5964a..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/GoToMatchingTagAction.java +++ /dev/null @@ -1,299 +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.wst.xml.ui.internal.actions; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.ResourceBundle; - -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.text.Position; -import org.eclipse.jface.text.TextSelection; -import org.eclipse.jface.text.source.Annotation; -import org.eclipse.jface.text.source.IAnnotationModel; -import org.eclipse.jface.text.source.IAnnotationModelExtension; -import org.eclipse.jface.viewers.IPostSelectionProvider; -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.swt.widgets.Event; -import org.eclipse.ui.texteditor.IDocumentProvider; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.ui.texteditor.TextEditorAction; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.w3c.dom.Attr; -import org.w3c.dom.Node; - -/** - * Moves the cursor to the end tag if it is in a start tag, and vice versa. - * Also updates the matching tag annotation in the active editor. - * - * @author nitin - * - */ -class GoToMatchingTagAction extends TextEditorAction { - - private class UpdateListener implements ISelectionChangedListener { - public void selectionChanged(SelectionChangedEvent event) { - updateFor(event.getSelection()); - } - } - - private static final String ANNOTATION_TYPE = "org.eclipse.wst.xml.ui.matching.tag"; //$NON-NLS-1$ - private ISelectionChangedListener fUpdateListener = null; - static final boolean DEBUG = false; - - /** - * @param bundle - * @param prefix - * @param editor - * @param style - */ - GoToMatchingTagAction(ResourceBundle bundle, String prefix, ITextEditor editor) { - super(bundle, prefix, editor); - fUpdateListener = new UpdateListener(); - } - - void removeAnnotation(boolean allMatching) { - ITextEditor textEditor = getTextEditor(); - if (textEditor == null) { - if (DEBUG) { - System.out.println("no editor"); //$NON-NLS-1$ - } - return; - } - IDocumentProvider documentProvider = textEditor.getDocumentProvider(); - if (documentProvider == null) { - if (DEBUG) { - System.out.println("no document provider"); //$NON-NLS-1$ - } - return; - } - IAnnotationModel annotationModel = documentProvider.getAnnotationModel(textEditor.getEditorInput()); - if (annotationModel == null) { - if (DEBUG) { - System.out.println("no annotation model"); //$NON-NLS-1$ - } - return; - } - - Iterator annotationIterator = annotationModel.getAnnotationIterator(); - List oldAnnotations = new ArrayList(); - while (annotationIterator.hasNext()) { - Annotation annotation = (Annotation) annotationIterator.next(); - if (ANNOTATION_TYPE.equals(annotation.getType())) { - annotation.markDeleted(true); - /** - * Sometimes it is supported, sometime's it is not. Confusing. - */ - try { - annotationIterator.remove(); - } - catch (UnsupportedOperationException e) { - oldAnnotations.add(annotation); - } - if (DEBUG) { - System.out.println("removed " + annotation); //$NON-NLS-1$ - } - if (!allMatching) - break; - } - } - if (!oldAnnotations.isEmpty()) { - int size = oldAnnotations.size(); - for (int i = 0; i < size; i++) { - annotationModel.removeAnnotation((Annotation) oldAnnotations.get(i)); - } - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.Action#runWithEvent(org.eclipse.swt.widgets.Event) - */ - public void runWithEvent(Event event) { - super.runWithEvent(event); - if (getTextEditor() == null) - return; - - ISelection selection = getTextEditor().getSelectionProvider().getSelection(); - if (!selection.isEmpty() && selection instanceof IStructuredSelection && selection instanceof ITextSelection) { - Object o = ((IStructuredSelection) selection).getFirstElement(); - if (o instanceof IDOMNode) { - int offset = ((ITextSelection) selection).getOffset(); - IStructuredDocumentRegion matchRegion = null; - if (((Node) o).getNodeType() == Node.ATTRIBUTE_NODE) { - o = ((Attr) o).getOwnerElement(); - } - - int targetOffset = -1; - if (o instanceof IDOMNode) { - IDOMNode node = (IDOMNode) o; - IStructuredDocumentRegion startStructuredDocumentRegion = node.getStartStructuredDocumentRegion(); - if (startStructuredDocumentRegion != null && startStructuredDocumentRegion.containsOffset(offset)) { - matchRegion = ((IDOMNode) o).getEndStructuredDocumentRegion(); - if (matchRegion != null) - targetOffset = matchRegion.getStartOffset() + 2; - } - else { - IStructuredDocumentRegion endStructuredDocumentRegion = node.getEndStructuredDocumentRegion(); - if (endStructuredDocumentRegion != null && endStructuredDocumentRegion.containsOffset(offset)) { - matchRegion = ((IDOMNode) o).getStartStructuredDocumentRegion(); - if (matchRegion != null) - targetOffset = matchRegion.getStartOffset() + 1; - } - } - } - - if (targetOffset >= 0) { - getTextEditor().getSelectionProvider().setSelection(new TextSelection(targetOffset, 0)); - } - } - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.texteditor.TextEditorAction#setEditor(org.eclipse.ui.texteditor.ITextEditor) - */ - public void setEditor(ITextEditor editor) { - ITextEditor textEditor = getTextEditor(); - if (textEditor != null) { - removeAnnotation(true); - - ISelectionProvider selectionProvider = textEditor.getSelectionProvider(); - if (selectionProvider instanceof IPostSelectionProvider) { - ((IPostSelectionProvider) selectionProvider).removePostSelectionChangedListener(fUpdateListener); - } - } - super.setEditor(editor); - if (editor != null) { - ISelectionProvider selectionProvider = editor.getSelectionProvider(); - if (selectionProvider instanceof IPostSelectionProvider) { - ((IPostSelectionProvider) selectionProvider).addPostSelectionChangedListener(fUpdateListener); - } - - updateFor(selectionProvider.getSelection()); - } - } - - public void update() { - setEnabled(true); - - } - - void updateFor(ISelection selection) { - ITextEditor textEditor = getTextEditor(); - if (textEditor == null) { - if (DEBUG) { - System.out.println("no editor"); //$NON-NLS-1$ - } - return; - } - IDocumentProvider documentProvider = textEditor.getDocumentProvider(); - if (documentProvider == null) { - if (DEBUG) { - System.out.println("no document provider"); //$NON-NLS-1$ - } - return; - } - IAnnotationModel annotationModel = documentProvider.getAnnotationModel(textEditor.getEditorInput()); - if (annotationModel == null || !(annotationModel instanceof IAnnotationModelExtension)) { - if (DEBUG) { - System.out.println("no annotation model"); //$NON-NLS-1$ - } - return; - } - - List oldAnnotations = new ArrayList(2); - Iterator annotationIterator = annotationModel.getAnnotationIterator(); - while (annotationIterator.hasNext()) { - Annotation annotation = (Annotation) annotationIterator.next(); - if (ANNOTATION_TYPE.equals(annotation.getType())) { - annotation.markDeleted(true); - if (DEBUG) { - System.out.println("removing " + annotation); //$NON-NLS-1$ - } - oldAnnotations.add(annotation); - } - } - - Map newAnnotations = new HashMap(); - if (!selection.isEmpty() && selection instanceof IStructuredSelection && selection instanceof ITextSelection) { - Object o = ((IStructuredSelection) selection).getFirstElement(); - if (o instanceof IDOMNode) { - int offset = ((ITextSelection) selection).getOffset(); - IStructuredDocumentRegion matchRegion = null; - if (((Node) o).getNodeType() == Node.ATTRIBUTE_NODE) { - o = ((Attr) o).getOwnerElement(); - } - - Position pStart = null; - Position pEnd = null; - if (o instanceof IDOMNode) { - IDOMNode node = (IDOMNode) o; - IStructuredDocumentRegion startStructuredDocumentRegion = node.getStartStructuredDocumentRegion(); - if (startStructuredDocumentRegion != null && startStructuredDocumentRegion.containsOffset(offset)) { - if (startStructuredDocumentRegion.getNumberOfRegions() > 1) { - ITextRegion nameRegion = startStructuredDocumentRegion.getRegions().get(1); - pStart = new Position(startStructuredDocumentRegion.getStartOffset(nameRegion), nameRegion.getTextLength()); - } - matchRegion = ((IDOMNode) o).getEndStructuredDocumentRegion(); - if (matchRegion != null && matchRegion.getNumberOfRegions() > 1) { - ITextRegion nameRegion = matchRegion.getRegions().get(1); - pEnd = new Position(matchRegion.getStartOffset(nameRegion), nameRegion.getTextLength()); - } - } - else { - IStructuredDocumentRegion endStructuredDocumentRegion = node.getEndStructuredDocumentRegion(); - if (endStructuredDocumentRegion != null && endStructuredDocumentRegion.containsOffset(offset)) { - if (endStructuredDocumentRegion.getNumberOfRegions() > 1) { - ITextRegion nameRegion = endStructuredDocumentRegion.getRegions().get(1); - pEnd = new Position(endStructuredDocumentRegion.getStartOffset(nameRegion), nameRegion.getTextLength()); - } - matchRegion = ((IDOMNode) o).getStartStructuredDocumentRegion(); - if (matchRegion != null && matchRegion.getNumberOfRegions() > 1) { - ITextRegion nameRegion = matchRegion.getRegions().get(1); - pStart = new Position(matchRegion.getStartOffset(nameRegion), nameRegion.getTextLength()); - } - } - } - } - if (pStart != null && pEnd != null) { - Annotation annotation = new Annotation(false); - annotation.setType(ANNOTATION_TYPE); - newAnnotations.put(annotation, pStart); - if (DEBUG) { - System.out.println("adding " + annotation); //$NON-NLS-1$ - } - - annotation = new Annotation(false); - annotation.setType(ANNOTATION_TYPE); - newAnnotations.put(annotation, pEnd); - if (DEBUG) { - System.out.println("adding " + annotation); //$NON-NLS-1$ - } - } - } - } - ((IAnnotationModelExtension) annotationModel).replaceAnnotations((Annotation[]) oldAnnotations.toArray(new Annotation[oldAnnotations.size()]), newAnnotations); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/MenuBuilder.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/MenuBuilder.java deleted file mode 100644 index 78f3ceb017..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/MenuBuilder.java +++ /dev/null @@ -1,146 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ - - -package org.eclipse.wst.xml.ui.internal.actions; - -import com.ibm.icu.text.Collator; -import java.util.Arrays; -import java.util.Comparator; -import java.util.List; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.MenuManager; - - -public class MenuBuilder { - - - protected Comparator comparator = new Comparator() { - - public int compare(Object o1, Object o2) { - return Collator.getInstance().compare(getSortKey(o1), getSortKey(o2)); - } - - protected String getSortKey(Object o) { - String result = ""; //$NON-NLS-1$ - if (o instanceof IAction) { - IAction action = (IAction) o; - result = action.getText(); - } - // else if (o instanceof MenuData) - // { - // result = "z" + ((MenuData)o).name; - // } - return result; - } - }; - - - protected void createAlphebeticalGrouping(IMenuManager menu, List actionList) { - Object[] array = actionList.toArray(); - if (array.length > 0) { - Arrays.sort(array, comparator); - } - - int groupSize = 15; - int minGroupSize = 5; - int numberOfGroups = (array.length / groupSize) + ((array.length % groupSize > minGroupSize) ? 1 : 0); - - for (int i = 0; i < numberOfGroups; i++) { - boolean isLastGroup = (i == (numberOfGroups - 1)); - int firstIndex = i * groupSize; - int lastIndex = isLastGroup ? array.length - 1 : i * groupSize + groupSize - 1; - Action firstAction = (Action) array[firstIndex]; - Action lastAction = (Action) array[lastIndex]; - MenuManager submenu = new MenuManager(firstAction.getText() + " - " + lastAction.getText()); //$NON-NLS-1$ - menu.add(submenu); - for (int j = firstIndex; j <= lastIndex; j++) { - submenu.add((Action) array[j]); - } - } - } - - - public void populateMenu(IMenuManager menu, List actionList, boolean createTiered) { - // sort the actions - if (actionList.size() < 25) { - Object[] array = actionList.toArray(); - if (array.length > 0) { - Arrays.sort(array, comparator); - } - for (int i = 0; i < array.length; i++) { - menu.add((Action) array[i]); - } - } - else { - createAlphebeticalGrouping(menu, actionList); - } - } - - /* - * protected void createPropertyGrouping(IMenuManager menu, List - * actionList) { MenuDataTable menuDataTable = new MenuDataTable(); - * - * for (Iterator i = actionList.iterator(); i.hasNext(); ) { String - * groupName = null; Action action = (Action)i.next(); if (action - * instanceof NodeAction) { groupName = - * ((NodeAction)action).getGroupName(); } if (groupName == null) { - * groupName = ""; } MenuData menuData = - * menuDataTable.lookupOrCreate(groupName, ""); - * menuData.childList.add(action); } populateMenu(menu, - * menuDataTable.getRoot()); } - * - * - * protected void populateMenu(MenuManager menuManager, MenuData menuData) { - * for (Iterator i = menuData.childList.iterator(); i.hasNext(); ) { - * Object o = i.next(); if (o instanceof Action) { - * menuManager.add((Action)o); } else if (o instanceof MenuData) { - * MenuData childMenuData = (MenuData)o; MenuManager childMenuManager = - * new MenuManager(childMenuData.name); menuManager.add(childMenuManager); - * populateMenu(childMenuManager, childMenuData); } } } - * - * - * public MenuDataTable { protected Hashtable table = new Hashtable(); - * protected MenuData root; - * - * public MenuDataTable() { root = lookupOrCreateMenuData(null, null); } - * - * protected MenuData lookupMenuData(String name) { String key = name != - * null ? name : ""; return (MenuData)menuDataTable.get(key); } - * - * protected MenuData lookupOrCreateMenuData(String name, String - * parentName) { String key = name != null ? name : ""; MenuData menuData = - * (MenuData)menuDataTable.get(key); if (menuData == null) { menuData = - * new MenuData(name, parentName); menuDataTable.put(key, menuData); } - * return menuData; } - * - * public MenuData getRoot() { return root; } } - * - * - * protected class MenuData { public String name; public String - * parentName; public List childList = new Vector(); - * - * MenuData(String name, String parentName) { this.name = name; - * this.parentName = parentName; } - * - * protected void sort() { Object[] array = childList.toArray(); if - * (array.length > 0 ) { Arrays.sort(array, comparator); } childList = - * Arrays.asList(array); - * - * for (Iterator i = childList.iterator(); i.hasNext(); ) { Object o = - * i.next(); if (o instanceof MenuData) { ((MenuData)o).sort(); } } } } - */ -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/NodeAction.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/NodeAction.java deleted file mode 100644 index 0974e8f603..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/NodeAction.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ - - -package org.eclipse.wst.xml.ui.internal.actions; - -import org.eclipse.jface.action.Action; - -public abstract class NodeAction extends Action { - - public String getSortKey() { - return null; - } - - public abstract String getUndoDescription(); -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/RemoveBlockCommentActionXMLDelegate.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/RemoveBlockCommentActionXMLDelegate.java deleted file mode 100644 index 473e5f257f..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/RemoveBlockCommentActionXMLDelegate.java +++ /dev/null @@ -1,87 +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.wst.xml.ui.internal.actions; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.xml.core.internal.document.CommentImpl; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; - -/** - * Remove block comment action delegate for XML editor - */ -public class RemoveBlockCommentActionXMLDelegate extends AbstractCommentActionXMLDelegate { - - void processAction(IDocument document, ITextSelection textSelection) { - IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForEdit(document); - if (model != null) { - try { - IndexedRegion selectionStartIndexedRegion = model.getIndexedRegion(textSelection.getOffset()); - IndexedRegion selectionEndIndexedRegion = model.getIndexedRegion(textSelection.getOffset() + textSelection.getLength()); - - if ((selectionStartIndexedRegion == null) || (selectionEndIndexedRegion == null)) { - return; - } - - int openCommentOffset = selectionStartIndexedRegion.getStartOffset(); - int closeCommentOffset = selectionEndIndexedRegion.getEndOffset() - OPEN_COMMENT.length() - CLOSE_COMMENT.length(); - - model.beginRecording(this, XMLUIMessages.RemoveBlockComment_tooltip); - model.aboutToChangeModel(); - - try { - if (textSelection.getLength() == 0) { - if (selectionStartIndexedRegion instanceof CommentImpl) { - document.replace(openCommentOffset, OPEN_COMMENT.length(), ""); //$NON-NLS-1$ - document.replace(closeCommentOffset, CLOSE_COMMENT.length(), ""); //$NON-NLS-1$ - } - } - else { - if (selectionStartIndexedRegion instanceof CommentImpl) { - document.replace(openCommentOffset, OPEN_COMMENT.length(), ""); //$NON-NLS-1$ - } - - if (selectionEndIndexedRegion instanceof CommentImpl) { - document.replace(closeCommentOffset, CLOSE_COMMENT.length(), ""); //$NON-NLS-1$ - } - } - removeOpenCloseComments(document, openCommentOffset + OPEN_COMMENT.length(), closeCommentOffset - openCommentOffset - CLOSE_COMMENT.length()); - } - catch (BadLocationException e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - finally { - model.changedModel(); - model.endRecording(this); - } - } - finally { - model.releaseFromEdit(); - } - } - } - - public void init(IAction action) { - if (action != null) { - action.setText(XMLUIMessages.RemoveBlockComment_label); - action.setToolTipText(XMLUIMessages.RemoveBlockComment_tooltip); - action.setDescription(XMLUIMessages.RemoveBlockComment_description); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/ReplacePrefixAction.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/ReplacePrefixAction.java deleted file mode 100644 index e5719a989d..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/ReplacePrefixAction.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.actions; - -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Vector; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMVisitor; -import org.w3c.dom.Attr; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - - - -public class ReplacePrefixAction extends NodeAction { - - class NodeCollectingDOMVisitor extends DOMVisitor { - public List list = new Vector(); - - protected boolean isPrefixChangedNeeded(Node node) { - String key = node.getPrefix() != null ? node.getPrefix() : ""; //$NON-NLS-1$ - return prefixMapping.get(key) != null; - } - - public void visitAttr(Attr attr) { - /* - * if (isPrefixChangedNeeded(element)) { list.add(attr); } - */ - } - - protected void visitElement(Element element) { - super.visitElement(element); - if (isPrefixChangedNeeded(element)) { - list.add(element); - } - } - } - - protected static ImageDescriptor imageDescriptor; - protected Element element; - protected AbstractNodeActionManager manager; - protected Map prefixMapping; - - public ReplacePrefixAction(AbstractNodeActionManager manager, Element element, Map prefixMapping) { - this.manager = manager; - this.element = element; - this.prefixMapping = prefixMapping; - } - - public String getUndoDescription() { - return ""; //$NON-NLS-1$ - } - - public void run() { - NodeCollectingDOMVisitor visitor = new NodeCollectingDOMVisitor(); - visitor.visitNode(element); - for (Iterator i = visitor.list.iterator(); i.hasNext();) { - Node node = (Node) i.next(); - String key = node.getPrefix() != null ? node.getPrefix() : ""; //$NON-NLS-1$ - String newPrefix = (String) prefixMapping.get(key); - if (newPrefix != null) { - node.setPrefix(newPrefix); - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/SiblingNavigationAction.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/SiblingNavigationAction.java deleted file mode 100644 index a08b44f60e..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/SiblingNavigationAction.java +++ /dev/null @@ -1,110 +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.wst.xml.ui.internal.actions; - -import java.util.ResourceBundle; - -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.swt.widgets.Event; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.ui.texteditor.TextEditorAction; -import org.w3c.dom.Attr; -import org.w3c.dom.Node; - -/** - * Provides navigation to next/previous DOM sibling Nodes - * - * @author nitin - * - */ -class SiblingNavigationAction extends TextEditorAction { - - private boolean fForward; - - /** - * @param bundle - * @param prefix - * @param editor - */ - SiblingNavigationAction(ResourceBundle bundle, String prefix, ITextEditor editor, boolean forward) { - super(bundle, prefix, editor); - fForward = forward; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.Action#runWithEvent(org.eclipse.swt.widgets.Event) - */ - public void runWithEvent(Event event) { - super.runWithEvent(event); - if (getTextEditor() == null) - return; - - ISelection selection = getTextEditor().getSelectionProvider().getSelection(); - if (!selection.isEmpty() && selection instanceof IStructuredSelection) { - Object o = ((IStructuredSelection) selection).getFirstElement(); - if (o instanceof Node) { - Node sibling = null; - - if (((Node) o).getNodeType() == Node.ATTRIBUTE_NODE) { - o = ((Attr) o).getOwnerElement(); - } - if (fForward) { - sibling = ((Node) o).getNextSibling(); - while (sibling != null && sibling.getNodeType() == Node.TEXT_NODE && sibling.getNodeValue().trim().length() == 0) { - sibling = sibling.getNextSibling(); - } - if (sibling == null) { - sibling = ((Node) o).getParentNode().getFirstChild(); - while (sibling != null && sibling.getNodeType() == Node.TEXT_NODE && sibling.getNodeValue().trim().length() == 0) { - sibling = sibling.getNextSibling(); - } - } - } - else { - sibling = ((Node) o).getPreviousSibling(); - while (sibling != null && sibling.getNodeType() == Node.TEXT_NODE && sibling.getNodeValue().trim().length() == 0) { - sibling = sibling.getPreviousSibling(); - } - if (sibling == null) { - sibling = ((Node) o).getParentNode().getLastChild(); - while (sibling != null && sibling.getNodeType() == Node.TEXT_NODE && sibling.getNodeValue().trim().length() == 0) { - sibling = sibling.getPreviousSibling(); - } - } - } - - // The only child is a Text Node, go to the parent Node - if (((Node) o).getNodeType() == Node.TEXT_NODE && o.equals(sibling)) { - sibling = ((Node) o).getParentNode(); - } - - - if (sibling != null) { - getTextEditor().getSelectionProvider().setSelection(new StructuredSelection(sibling)); - } - } - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.texteditor.TextEditorAction#update() - */ - public void update() { - - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/ToggleCommentActionXMLDelegate.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/ToggleCommentActionXMLDelegate.java deleted file mode 100644 index 09d81d1840..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/ToggleCommentActionXMLDelegate.java +++ /dev/null @@ -1,174 +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.wst.xml.ui.internal.actions; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.text.Position; -import org.eclipse.jface.text.TextSelection; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; - -/** - * Toggle comment action delegate for XML editor - */ -public class ToggleCommentActionXMLDelegate extends AbstractCommentActionXMLDelegate { - public void init(IAction action) { - if (action != null) { - action.setText(XMLUIMessages.ToggleComment_label); - action.setToolTipText(XMLUIMessages.ToggleComment_tooltip); - action.setDescription(XMLUIMessages.ToggleComment_description); - } - } - - void processAction(IDocument document, ITextSelection textSelection) { - // get text selection lines info - int selectionStartLine = textSelection.getStartLine(); - int selectionEndLine = textSelection.getEndLine(); - try { - int selectionEndLineOffset = document.getLineOffset(selectionEndLine); - int selectionEndOffset = textSelection.getOffset() + textSelection.getLength(); - - // adjust selection end line - if ((selectionEndLine > selectionStartLine) && (selectionEndLineOffset == selectionEndOffset)) { - selectionEndLine--; - } - - } - catch (BadLocationException e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - - // save the selection position since it will be changing - Position selectionPosition = null; - boolean updateStartOffset = false; - try { - selectionPosition = new Position(textSelection.getOffset(), textSelection.getLength()); - document.addPosition(selectionPosition); - - // extra check if commenting from beginning of line - int selectionStartLineOffset = document.getLineOffset(selectionStartLine); - if ((textSelection.getLength() > 0) && (selectionStartLineOffset == textSelection.getOffset()) && !isCommentLine(document, selectionStartLine)) { - updateStartOffset = true; - } - } - catch (BadLocationException e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - - processAction(document, selectionStartLine, selectionEndLine); - - updateCurrentSelection(selectionPosition, document, updateStartOffset); - } - - private void processAction(IDocument document, int selectionStartLine, int selectionEndLine) { - IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForEdit(document); - if (model != null) { - try { - model.beginRecording(this, XMLUIMessages.ToggleComment_tooltip); - model.aboutToChangeModel(); - - for (int i = selectionStartLine; i <= selectionEndLine; i++) { - try { - if (document.getLineLength(i) > 0) { - if (isCommentLine(document, i)) { - int lineOffset = document.getLineOffset(i); - IRegion region = document.getLineInformation(i); - String string = document.get(region.getOffset(), region.getLength()); - int openCommentOffset = lineOffset + string.indexOf(OPEN_COMMENT); - int closeCommentOffset = lineOffset + string.indexOf(CLOSE_COMMENT) - OPEN_COMMENT.length(); - uncomment(document, openCommentOffset, closeCommentOffset); - } - else { - int openCommentOffset = document.getLineOffset(i); - int lineDelimiterLength = document.getLineDelimiter(i) == null ? 0 : document.getLineDelimiter(i).length(); - int closeCommentOffset = openCommentOffset + document.getLineLength(i) - lineDelimiterLength + OPEN_COMMENT.length(); - comment(document, openCommentOffset, closeCommentOffset); - } - } - } - catch (BadLocationException e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - } - } - finally { - model.changedModel(); - model.endRecording(this); - model.releaseFromEdit(); - } - } - } - - private boolean isCommentLine(IDocument document, int line) { - boolean isComment = false; - - try { - IRegion region = document.getLineInformation(line); - String string = document.get(region.getOffset(), region.getLength()).trim(); - isComment = (string.length() >= OPEN_COMMENT.length() + CLOSE_COMMENT.length()) && string.startsWith(OPEN_COMMENT) && string.endsWith(CLOSE_COMMENT); - } - catch (BadLocationException e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - return isComment; - } - - private void comment(IDocument document, int openCommentOffset, int closeCommentOffset) { - try { - document.replace(openCommentOffset, 0, OPEN_COMMENT); - document.replace(closeCommentOffset, 0, CLOSE_COMMENT); - removeOpenCloseComments(document, openCommentOffset + OPEN_COMMENT.length(), closeCommentOffset - openCommentOffset - CLOSE_COMMENT.length()); - } - catch (BadLocationException e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - } - - private void uncomment(IDocument document, int openCommentOffset, int closeCommentOffset) { - try { - document.replace(openCommentOffset, OPEN_COMMENT.length(), ""); //$NON-NLS-1$ - document.replace(closeCommentOffset, CLOSE_COMMENT.length(), ""); //$NON-NLS-1$ - } - catch (BadLocationException e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - } - - private void updateCurrentSelection(Position selectionPosition, IDocument document, boolean updateStartOffset) { - if (fEditor instanceof ITextEditor) { - // update the selection if text selection changed - if (selectionPosition != null) { - ITextSelection selection = null; - if (updateStartOffset) { - selection = new TextSelection(document, selectionPosition.getOffset() - OPEN_COMMENT.length(), selectionPosition.getLength() + OPEN_COMMENT.length()); - } - else { - selection = new TextSelection(document, selectionPosition.getOffset(), selectionPosition.getLength()); - } - ISelectionProvider provider = ((ITextEditor) fEditor).getSelectionProvider(); - if (provider != null) { - provider.setSelection(selection); - } - document.removePosition(selectionPosition); - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/autoedit/AutoEditStrategyForTabs.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/autoedit/AutoEditStrategyForTabs.java deleted file mode 100644 index 1b416ccc2c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/autoedit/AutoEditStrategyForTabs.java +++ /dev/null @@ -1,200 +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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.autoedit; - -import org.eclipse.core.runtime.Preferences; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.ConfigurableLineTracker; -import org.eclipse.jface.text.DocumentCommand; -import org.eclipse.jface.text.IAutoEditStrategy; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ILineTracker; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.TextUtilities; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.ui.texteditor.ITextEditorExtension3; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames; -import org.eclipse.wst.xml.ui.internal.Logger; - -/** - * AutoEditStrategy to handle characters inserted when Tab key is pressed - */ -public class AutoEditStrategyForTabs implements IAutoEditStrategy { - private final String TAB_CHARACTER = "\t"; //$NON-NLS-1$ - - public void customizeDocumentCommand(IDocument document, DocumentCommand command) { - // if not in smart insert mode just ignore - if (!isSmartInsertMode()) { - return; - } - - // spaces for tab character - if ((command.length == 0) && (command.text != null) && (command.text.length() > 0) && (command.text.indexOf(TAB_CHARACTER) != -1)) { - smartInsertForTab(command, document); - } - } - - /** - * Insert spaces for tabs - * - * @param command - */ - private void smartInsertForTab(DocumentCommand command, IDocument document) { - // tab key was pressed. now check preferences to see if need to insert - // spaces instead of tab - int indentationWidth = getIndentationWidth(); - if (indentationWidth > -1) { - String originalText = command.text; - StringBuffer newText = new StringBuffer(originalText); - - // determine where in line this command begins - int lineOffset = -1; - try { - IRegion lineInfo = document.getLineInformationOfOffset(command.offset); - lineOffset = command.offset - lineInfo.getOffset(); - } - catch (BadLocationException e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - - ILineTracker lineTracker = getLineTracker(document, originalText); - - int startIndex = 0; - int index = newText.indexOf(TAB_CHARACTER); - while (index != -1) { - String indent = getIndentString(indentationWidth, lineOffset, lineTracker, index); - - // replace \t character with spaces - newText.replace(index, index + 1, indent); - if (lineTracker != null) { - try { - lineTracker.replace(index, 1, indent); - } - catch (BadLocationException e) { - // if something goes wrong with replacing text, just - // reset to current string - lineTracker.set(newText.toString()); - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - } - - startIndex = index + indent.length(); - index = newText.indexOf(TAB_CHARACTER, startIndex); - } - command.text = newText.toString(); - } - } - - /** - * Calculate number of spaces for next tab stop - */ - private String getIndentString(int indentationWidth, int lineOffset, ILineTracker lineTracker, int index) { - int indentSize = indentationWidth; - int offsetInLine = -1; - if (lineTracker != null) { - try { - IRegion lineInfo = lineTracker.getLineInformationOfOffset(index); - if ((lineInfo.getOffset() == 0) && (lineOffset > -1)) { - offsetInLine = lineOffset + index; - } - else { - offsetInLine = index - lineInfo.getOffset(); - } - } - catch (BadLocationException e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - } - else { - if (lineOffset > -1) { - offsetInLine = lineOffset + index; - } - } - if ((offsetInLine > -1) && (indentationWidth > 0)) { - int remainder = offsetInLine % indentationWidth; - indentSize = indentationWidth - remainder; - } - - StringBuffer indent = new StringBuffer(); - for (int i = 0; i < indentSize; i++) { - indent.append(' '); - } - return indent.toString(); - } - - /** - * Set up a line tracker for text within command if text is multi-line - */ - private ILineTracker getLineTracker(IDocument document, String originalText) { - ConfigurableLineTracker lineTracker = null; - int[] delims = TextUtilities.indexOf(document.getLegalLineDelimiters(), originalText, 0); - if ((delims[0] != -1) || (delims[1] != -1)) { - lineTracker = new ConfigurableLineTracker(document.getLegalLineDelimiters()); - lineTracker.set(originalText); - } - return lineTracker; - } - - /** - * Return true if active editor is in smart insert mode, false otherwise - * - * @return boolean - */ - private boolean isSmartInsertMode() { - boolean isSmartInsertMode = false; - - ITextEditor textEditor = null; - IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - if (window != null) { - IWorkbenchPage page = window.getActivePage(); - if (page != null) { - IEditorPart editor = page.getActiveEditor(); - if (editor != null) { - if (editor instanceof ITextEditor) { - textEditor = (ITextEditor) editor; - } - else { - textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class); - } - } - } - } - - // check if smart insert mode - if ((textEditor instanceof ITextEditorExtension3) && (((ITextEditorExtension3) textEditor).getInsertMode() == ITextEditorExtension3.SMART_INSERT)) { - isSmartInsertMode = true; - } - return isSmartInsertMode; - } - - /** - * Returns indentation width if using spaces for indentation, -1 otherwise - * - * @return int - */ - private int getIndentationWidth() { - int width = -1; - - Preferences preferences = XMLCorePlugin.getDefault().getPluginPreferences(); - if (XMLCorePreferenceNames.SPACE.equals(preferences.getString(XMLCorePreferenceNames.INDENTATION_CHAR))) { - width = preferences.getInt(XMLCorePreferenceNames.INDENTATION_SIZE); - } - - return width; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/autoedit/StructuredAutoEditStrategyXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/autoedit/StructuredAutoEditStrategyXML.java deleted file mode 100644 index df619e79f0..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/autoedit/StructuredAutoEditStrategyXML.java +++ /dev/null @@ -1,180 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.autoedit; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.DocumentCommand; -import org.eclipse.jface.text.IAutoEditStrategy; -import org.eclipse.jface.text.IDocument; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.ui.texteditor.ITextEditorExtension3; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.internal.preferences.XMLUIPreferenceNames; -import org.w3c.dom.Node; - -/** - * Automatically inserts closing comment tag or end tag when appropriate. - */ -public class StructuredAutoEditStrategyXML implements IAutoEditStrategy { - /* - * NOTE: copies of this class exists in - * org.eclipse.wst.xml.ui.internal.autoedit - * org.eclipse.wst.html.ui.internal.autoedit - */ - public void customizeDocumentCommand(IDocument document, DocumentCommand command) { - Object textEditor = getActiveTextEditor(); - if (!((textEditor instanceof ITextEditorExtension3) && (((ITextEditorExtension3) textEditor).getInsertMode() == ITextEditorExtension3.SMART_INSERT))) { - return; - } - - IStructuredModel model = null; - try { - model = StructuredModelManager.getModelManager().getExistingModelForRead(document); - if (model != null) { - if (command.text != null) { - smartInsertForComment(command, document, model); - smartInsertForEndTag(command, document, model); - smartRemoveEndTag(command, document, model); - } - } - } - finally { - if (model != null) { - model.releaseFromRead(); - } - } - } - - private boolean isPreferenceEnabled(String key) { - return (key != null && XMLUIPlugin.getDefault().getPreferenceStore().getBoolean(key)); - } - - private boolean isCommentNode(IDOMNode node) { - return ((node != null) && (node instanceof IDOMElement) && ((IDOMElement) node).isCommentTag()); - } - - private boolean isDocumentNode(IDOMNode node) { - return ((node != null) && (node.getNodeType() == Node.DOCUMENT_NODE)); - } - - /** - * Attempts to clean up an end-tag if a start-tag is converted into an empty-element - * tag (e.g., <node />) and the original element was empty. - * - * @param command the document command describing the change - * @param document the document that will be changed - * @param model the model based on the document - */ - private void smartRemoveEndTag(DocumentCommand command, IDocument document, IStructuredModel model) { - try { - // An opening tag is now a self-terminated end-tag - if ("/".equals(command.text) && ">".equals(document.get(command.offset, 1)) && isPreferenceEnabled(XMLUIPreferenceNames.TYPING_REMOVE_END_TAGS)) { //$NON-NLS-1$ //$NON-NLS-2$ - IDOMNode node = (IDOMNode) model.getIndexedRegion(command.offset); - if (node != null && !node.hasChildNodes()) { - IStructuredDocumentRegion region = node.getEndStructuredDocumentRegion(); - - if (region != null && region.isEnded()) - document.replace(region.getStartOffset(), region.getLength(), ""); //$NON-NLS-1$ - } - } - } - catch (BadLocationException e) { - Logger.logException(e); - } - } - - private void smartInsertForComment(DocumentCommand command, IDocument document, IStructuredModel model) { - try { - if (command.text.equals("-") && (document.getLength() >= 3) && document.get(command.offset - 3, 3).equals("<!-") && isPreferenceEnabled(XMLUIPreferenceNames.TYPING_COMPLETE_COMMENTS)) { //$NON-NLS-1$ //$NON-NLS-2$ - command.text += " -->"; //$NON-NLS-1$ - command.shiftsCaret = false; - command.caretOffset = command.offset + 2; - command.doit = false; - } - } - catch (BadLocationException e) { - Logger.logException(e); - } - - } - - private void smartInsertForEndTag(DocumentCommand command, IDocument document, IStructuredModel model) { - try { - if (command.text.equals("/") && (document.getLength() >= 1) && document.get(command.offset - 1, 1).equals("<") && isPreferenceEnabled(XMLUIPreferenceNames.TYPING_COMPLETE_END_TAGS)) { //$NON-NLS-1$ //$NON-NLS-2$ - IDOMNode parentNode = (IDOMNode) ((IDOMNode) model.getIndexedRegion(command.offset - 1)).getParentNode(); - if (isCommentNode(parentNode)) { - // loop and find non comment node parent - while ((parentNode != null) && isCommentNode(parentNode)) { - parentNode = (IDOMNode) parentNode.getParentNode(); - } - } - - if (!isDocumentNode(parentNode)) { - // only add end tag if one does not already exist or if - // add '/' does not create one already - IStructuredDocumentRegion endTagStructuredDocumentRegion = parentNode.getEndStructuredDocumentRegion(); - if (endTagStructuredDocumentRegion == null) { - StringBuffer toAdd = new StringBuffer(parentNode.getNodeName()); - if (toAdd.length() > 0) { - toAdd.append(">"); //$NON-NLS-1$ - String suffix = toAdd.toString(); - if ((document.getLength() < command.offset + suffix.length()) || (!suffix.equals(document.get(command.offset, suffix.length())))) { - command.text += suffix; - } - } - } - } - } - } - catch (BadLocationException e) { - Logger.logException(e); - } - } - - /** - * Return the active text editor if possible, otherwise the active editor - * part. - * - * @return Object - */ - private Object getActiveTextEditor() { - IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - if (window != null) { - IWorkbenchPage page = window.getActivePage(); - if (page != null) { - IEditorPart editor = page.getActiveEditor(); - if (editor != null) { - if (editor instanceof ITextEditor) { - return editor; - } - ITextEditor textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class); - if (textEditor != null) { - return textEditor; - } - return editor; - } - } - } - return null; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AbstractContentAssistProcessor.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AbstractContentAssistProcessor.java deleted file mode 100644 index 5d44aee5f0..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AbstractContentAssistProcessor.java +++ /dev/null @@ -1,2482 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.contentassist; - -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Properties; -import java.util.Vector; - -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.text.contentassist.IContextInformation; -import org.eclipse.jface.text.contentassist.IContextInformationValidator; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.graphics.Image; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.encoding.ContentTypeEncodingPreferences; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList; -import org.eclipse.wst.sse.core.internal.util.Debug; -import org.eclipse.wst.sse.ui.internal.IReleasable; -import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils; -import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal; -import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMContent; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMEntityDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMGroup; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList; -import org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction; -import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMNamespaceHelper; -import org.eclipse.wst.xml.core.internal.document.AttrImpl; -import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.core.internal.provisional.contenttype.ContentTypeIdForXML; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.internal.editor.CMImageUtil; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages; -import org.eclipse.wst.xml.ui.internal.preferences.XMLUIPreferenceNames; -import org.eclipse.wst.xml.ui.internal.taginfo.MarkupTagInfoProvider; -import org.w3c.dom.Attr; -import org.w3c.dom.Document; -import org.w3c.dom.DocumentType; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -abstract public class AbstractContentAssistProcessor implements IContentAssistProcessor, IReleasable { - /** - * ISSUE: this is a bit of hidden JSP knowledge that was implemented this - * way for expedency. Should be evolved in future to depend on - * "nestedContext". - */ - private class DOMJSPRegionContextsPrivateCopy { - private static final String JSP_CLOSE = "JSP_CLOSE"; //$NON-NLS-1$ - private static final String JSP_COMMENT_CLOSE = "JSP_COMMENT_CLOSE"; //$NON-NLS-1$ - - private static final String JSP_COMMENT_OPEN = "JSP_COMMENT_OPEN"; //$NON-NLS-1$ - private static final String JSP_DECLARATION_OPEN = "JSP_DECLARATION_OPEN"; //$NON-NLS-1$ - private static final String JSP_DIRECTIVE_CLOSE = "JSP_DIRECTIVE_CLOSE"; //$NON-NLS-1$ - private static final String JSP_DIRECTIVE_NAME = "JSP_DIRECTIVE_NAME"; //$NON-NLS-1$ - - private static final String JSP_DIRECTIVE_OPEN = "JSP_DIRECTIVE_OPEN"; //$NON-NLS-1$ - private static final String JSP_EXPRESSION_OPEN = "JSP_EXPRESSION_OPEN"; //$NON-NLS-1$ - - private static final String JSP_ROOT_TAG_NAME = "JSP_ROOT_TAG_NAME"; //$NON-NLS-1$ - - private static final String JSP_SCRIPTLET_OPEN = "JSP_SCRIPTLET_OPEN"; //$NON-NLS-1$ - - } - - protected static final String INTERNALERROR = XMLUIMessages.SEVERE_internal_error_occu_UI_; - protected static final String UNKNOWN_ATTR = XMLUIMessages.No_known_attribute__UI_; - protected static final String UNKNOWN_CONTEXT = XMLUIMessages.Content_Assist_not_availab_UI_; - protected char completionProposalAutoActivationCharacters[] = null; - protected char contextInformationAutoActivationCharacters[] = null; - private AttributeContextInformationProvider fAttributeInfoProvider = null; - private AttributeContextInformationPresenter fContextInformationPresenter = null; - - protected String fErrorMessage = null; - protected XMLContentModelGenerator fGenerator; - // protected IResource resource = null; - protected MarkupTagInfoProvider fInfoProvider = null; - protected ITextViewer fTextViewer = null; - - private final boolean showValues = true; - - public AbstractContentAssistProcessor() { - init(); - } - - protected void addAttributeNameProposals(ContentAssistRequest contentAssistRequest) { - IDOMNode node = (IDOMNode) contentAssistRequest.getNode(); - IStructuredDocumentRegion sdRegion = contentAssistRequest.getDocumentRegion(); - // retrieve the list of attributes - CMElementDeclaration elementDecl = getCMElementDeclaration(node); - if (elementDecl != null) { - CMNamedNodeMap attributes = elementDecl.getAttributes(); - - CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(attributes); - if (node.getNodeType() == Node.ELEMENT_NODE) { - List nodes = ModelQueryUtil.getModelQuery(node.getOwnerDocument()).getAvailableContent((Element) node, elementDecl, ModelQuery.INCLUDE_ATTRIBUTES); - for (int k = 0; k < nodes.size(); k++) { - CMNode cmnode = (CMNode) nodes.get(k); - if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) { - allAttributes.put(cmnode); - } - } - } - attributes = allAttributes; - - String matchString = contentAssistRequest.getMatchString(); - - // check whether an attribute really exists for the replacement - // offsets AND if it possesses a value - boolean attrAtLocationHasValue = false; - NamedNodeMap attrs = node.getAttributes(); - for (int i = 0; i < attrs.getLength(); i++) { - AttrImpl existingAttr = (AttrImpl) attrs.item(i); - ITextRegion name = existingAttr.getNameRegion(); - - if ((sdRegion.getStartOffset(name) <= contentAssistRequest.getReplacementBeginPosition()) && (sdRegion.getStartOffset(name) + name.getLength() >= contentAssistRequest.getReplacementBeginPosition() + contentAssistRequest.getReplacementLength()) && (existingAttr.getValueRegion() != null)) { - attrAtLocationHasValue = true; - break; - } - } - - // only add proposals for the attributes whose names begin with - // the matchstring - if (attributes != null) { - for (int i = 0; i < attributes.getLength(); i++) { - CMAttributeDeclaration attrDecl = (CMAttributeDeclaration) attributes.item(i); - - int isRequired = 0; - if (attrDecl.getUsage() == CMAttributeDeclaration.REQUIRED) { - isRequired = XMLRelevanceConstants.R_REQUIRED; - } - - boolean showAttribute = true; - showAttribute = showAttribute && beginsWith(getRequiredName(node, attrDecl), matchString.trim()); - AttrImpl attr = (AttrImpl) node.getAttributes().getNamedItem(getRequiredName(node, attrDecl)); - ITextRegion nameRegion = attr != null ? attr.getNameRegion() : null; - // nameRegion.getEndOffset() + 1 is required to allow for - // matches against the full name of an existing Attr - showAttribute = showAttribute && ((attr == null) || ((nameRegion != null) && (sdRegion.getStartOffset(nameRegion) <= contentAssistRequest.getReplacementBeginPosition()) && (sdRegion.getStartOffset(nameRegion) + nameRegion.getLength() >= contentAssistRequest.getReplacementBeginPosition() + contentAssistRequest.getReplacementLength()))); - if (showAttribute) { - Image attrImage = CMImageUtil.getImage(attrDecl); - if (attrImage == null) { - if (isRequired > 0) { - attrImage = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATT_REQ_OBJ); - } - else { - attrImage = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE); - } - } - - String proposedText = null; - String proposedInfo = getAdditionalInfo(elementDecl, attrDecl); - CustomCompletionProposal proposal = null; - // attribute is at this location and already exists - if (attrAtLocationHasValue) { - // only propose the name - proposedText = getRequiredName(node, attrDecl); - proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), proposedText.length(), attrImage, proposedText, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_NAME + isRequired, true); - } - // no attribute exists or is elsewhere, generate - // minimally - else { - Attr existingAttrNode = (Attr) node.getAttributes().getNamedItem(getRequiredName(node, attrDecl)); - String value = null; - if (existingAttrNode != null) { - value = existingAttrNode.getNodeValue(); - } - if ((value != null) && (value.length() > 0)) { - proposedText = getRequiredName(node, attrDecl); - } - else { - proposedText = getRequiredText(node, attrDecl); - } - proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), attrDecl.getNodeName().length() + 2, attrImage, - // if the value isn't empty (no empty set of - // quotes), show it - // BUG 203494, content strings may have "", but not be empty - // An empty string is when there's no content between double quotes - // and there is no single quote that may be encasing a double quote - (showValues && (proposedText.lastIndexOf('\"') - proposedText.indexOf('\"') == 1 && proposedText.indexOf('\'') == -1)) ? getRequiredName(node, attrDecl) : proposedText, - null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_NAME + isRequired); - } - contentAssistRequest.addProposal(proposal); - } - } - } - } - else { - setErrorMessage(NLS.bind(XMLUIMessages.Element__is_unknown, (new Object[]{node.getNodeName()}))); - } - } - - protected void addAttributeValueProposals(ContentAssistRequest contentAssistRequest) { - - IDOMNode node = (IDOMNode) contentAssistRequest.getNode(); - - // Find the attribute region and name for which this position should - // have a value proposed - IStructuredDocumentRegion open = node.getFirstStructuredDocumentRegion(); - ITextRegionList openRegions = open.getRegions(); - int i = openRegions.indexOf(contentAssistRequest.getRegion()); - if (i < 0) { - return; - } - ITextRegion nameRegion = null; - while (i >= 0) { - nameRegion = openRegions.get(i--); - if (nameRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) { - break; - } - } - - // the name region is REQUIRED to do anything useful - if (nameRegion != null) { - // Retrieve the declaration - CMElementDeclaration elementDecl = getCMElementDeclaration(node); - - // String attributeName = nameRegion.getText(); - String attributeName = open.getText(nameRegion); - - CMAttributeDeclaration attrDecl = null; - - // No CMElementDeclaration means no attribute metadata, but - // retrieve the - // declaration for the attribute otherwise - if (elementDecl != null) { - CMNamedNodeMap attributes = elementDecl.getAttributes(); - - CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(attributes) { - private Map caseInsensitive; - - private Map getCaseInsensitiveMap() { - if(caseInsensitive == null) - caseInsensitive = new HashMap(); - return caseInsensitive; - } - - public CMNode getNamedItem(String name) { - CMNode node = super.getNamedItem(name); - if (node == null) { - node = (CMNode) getCaseInsensitiveMap().get(name.toLowerCase(Locale.US)); - } - return node; - } - - public void put(CMNode cmNode) { - super.put(cmNode); - getCaseInsensitiveMap().put(cmNode.getNodeName().toLowerCase(Locale.US), cmNode); - } - }; - if (node.getNodeType() == Node.ELEMENT_NODE) { - List nodes = ModelQueryUtil.getModelQuery(node.getOwnerDocument()).getAvailableContent((Element) node, elementDecl, ModelQuery.INCLUDE_ATTRIBUTES); - for (int k = 0; k < nodes.size(); k++) { - CMNode cmnode = (CMNode) nodes.get(k); - if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) { - allAttributes.put(cmnode); - } - } - } - attributes = allAttributes; - - String noprefixName = DOMNamespaceHelper.getUnprefixedName(attributeName); - if (attributes != null) { - attrDecl = (CMAttributeDeclaration) attributes.getNamedItem(noprefixName); - if (attrDecl == null) { - attrDecl = (CMAttributeDeclaration) attributes.getNamedItem(attributeName); - } - } - if (attrDecl == null) { - setErrorMessage(UNKNOWN_ATTR, attributeName); - } - } - - String currentValue = node.getAttributes().getNamedItem(attributeName).getNodeValue(); - String proposedInfo = null; - Image image = CMImageUtil.getImage(attrDecl); - if (image == null) { - if ((attrDecl != null) && (attrDecl.getUsage() == CMAttributeDeclaration.REQUIRED)) { - image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATT_REQ_OBJ); - } - else { - image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE); - } - } - - if ((attrDecl != null) && (attrDecl.getAttrType() != null)) { - // attribute is known, prompt with values from the declaration - proposedInfo = getAdditionalInfo(elementDecl, attrDecl); - List possibleValues = getPossibleDataTypeValues(node, attrDecl); - if (possibleValues.size() > 0) { - // ENUMERATED VALUES - String matchString = contentAssistRequest.getMatchString(); - if (matchString == null) { - matchString = ""; //$NON-NLS-1$ - } - if ((matchString.length() > 0) && (matchString.startsWith("\"") || matchString.startsWith("'"))) { - matchString = matchString.substring(1); - } - boolean currentValid = false; - - // d210858, if the region's a container, don't suggest the - // enumerated values as they probably won't help - boolean existingComplicatedValue = (contentAssistRequest.getRegion() != null) && (contentAssistRequest.getRegion() instanceof ITextRegionContainer); - if (!existingComplicatedValue) { - for (Iterator j = possibleValues.iterator(); j.hasNext();) { - String possibleValue = (String) j.next(); - currentValid = currentValid || possibleValue.equals(currentValue); - if ((matchString.length() == 0) || possibleValue.startsWith(matchString)) { - - String rString = "\"" + possibleValue + "\""; //$NON-NLS-2$//$NON-NLS-1$ - int rOffset = contentAssistRequest.getReplacementBeginPosition(); - int rLength = contentAssistRequest.getReplacementLength(); - int cursorAfter = possibleValue.length() + 1; - String displayString = "\"" + possibleValue + "\""; //$NON-NLS-2$//$NON-NLS-1$ - - CustomCompletionProposal proposal = new CustomCompletionProposal(rString, rOffset, rLength, cursorAfter, image, displayString, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE); - contentAssistRequest.addProposal(proposal); - } - } - } - } - else if (((attrDecl.getUsage() == CMAttributeDeclaration.FIXED) || (attrDecl.getAttrType().getImpliedValueKind() == CMDataType.IMPLIED_VALUE_FIXED)) && (attrDecl.getAttrType().getImpliedValue() != null)) { - // FIXED values - String value = attrDecl.getAttrType().getImpliedValue(); - if ((value != null) && (value.length() > 0)) { - String rValue = "\"" + value + "\"";//$NON-NLS-2$//$NON-NLS-1$ - CustomCompletionProposal proposal = new CustomCompletionProposal(rValue, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), rValue.length() + 1, image, rValue, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE); - contentAssistRequest.addProposal(proposal); - if ((currentValue.length() > 0) && !value.equals(currentValue)) { - rValue = "\"" + currentValue + "\""; //$NON-NLS-2$//$NON-NLS-1$ - proposal = new CustomCompletionProposal(rValue, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), rValue.length() + 1, image, rValue, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE); - contentAssistRequest.addProposal(proposal); - } - } - } - } - else { - // unknown attribute, so supply nice empty values - proposedInfo = getAdditionalInfo(null, elementDecl); - CustomCompletionProposal proposal = null; - if ((currentValue != null) && (currentValue.length() > 0)) { - String rValue = "\"" + currentValue + "\""; //$NON-NLS-2$//$NON-NLS-1$ - proposal = new CustomCompletionProposal(rValue, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), 1, image, rValue, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE); - contentAssistRequest.addProposal(proposal); - } - } - } - else { - setErrorMessage(UNKNOWN_CONTEXT); - } - } - - protected void addCommentProposal(ContentAssistRequest contentAssistRequest) { - contentAssistRequest.addProposal(new CustomCompletionProposal("<!-- -->", //$NON-NLS-1$ - contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), 5, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_COMMENT), NLS.bind(XMLUIMessages.Comment__, (new Object[]{" <!-- -->"})), //$NON-NLS-1$ - null, null, XMLRelevanceConstants.R_COMMENT)); - } - - /** - * Add all of the element declarations int the CMContent object into one - * big list. - */ - protected void addContent(List contentList, CMContent content) { - if (content == null) { - return; - } - if (content instanceof CMGroup) { - CMNodeList children = ((CMGroup) content).getChildNodes(); - if (children == null) { - return; - } - for (int i = 0; i < children.getLength(); i++) { - CMNode child = children.item(i); - if (child.getNodeType() == CMNode.ELEMENT_DECLARATION) { - contentList.add(child); - } - else { - if (child.getNodeType() == CMNode.GROUP) { - addContent(contentList, (CMContent) child); - } - else { - throw new IllegalArgumentException("Unknown content child: " + child); //$NON-NLS-1$ - } - } - } - } - else { - contentList.add(content); - } - } - - protected void addDocTypeProposal(ContentAssistRequest contentAssistRequest) { - // if a DocumentElement exists, use that for the root Element name - String rootname = "unspecified"; //$NON-NLS-1$ - if (contentAssistRequest.getNode().getOwnerDocument().getDocumentElement() != null) { - rootname = contentAssistRequest.getNode().getOwnerDocument().getDocumentElement().getNodeName(); - } - - String proposedText = "<!DOCTYPE " + rootname + " PUBLIC \"//UNKNOWN/\" \"unknown.dtd\">"; //$NON-NLS-1$ //$NON-NLS-2$ - ICompletionProposal proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), 10, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_DOCTYPE), "<!DOCTYPE ... >", //$NON-NLS-1$ - null, null, XMLRelevanceConstants.R_DOCTYPE); - // TODO provide special documentation on doc type - contentAssistRequest.addProposal(proposal); - } - - /** - * Add the proposals for a completely empty document - */ - protected void addEmptyDocumentProposals(ContentAssistRequest contentAssistRequest) { - // nothing - } - - /** - * Add the proposals for the name in an end tag - */ - protected void addEndTagNameProposals(ContentAssistRequest contentAssistRequest) { - - if (contentAssistRequest.getStartOffset() + contentAssistRequest.getRegion().getTextLength() < contentAssistRequest.getReplacementBeginPosition()) { - CustomCompletionProposal proposal = new CustomCompletionProposal(">", //$NON-NLS-1$ - contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), 1, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC), NLS.bind(XMLUIMessages.Close_with__, (new Object[]{" '>'"})), //$NON-NLS-1$ - null, null, XMLRelevanceConstants.R_END_TAG_NAME); - contentAssistRequest.addProposal(proposal); - } - else { - IDOMNode node = (IDOMNode) contentAssistRequest.getNode(); - ModelQuery modelQuery = ModelQueryUtil.getModelQuery(node.getOwnerDocument()); - Node aNode = contentAssistRequest.getNode(); - String matchString = contentAssistRequest.getMatchString(); - if (matchString.startsWith("</")) { - matchString = matchString.substring(2); - } - while (aNode != null) { - if (aNode.getNodeType() == Node.ELEMENT_NODE) { - if (aNode.getNodeName().startsWith(matchString)) { - IDOMNode aXMLNode = (IDOMNode) aNode; - CMElementDeclaration ed = modelQuery.getCMElementDeclaration((Element) aNode); - if ((aXMLNode.getEndStructuredDocumentRegion() == null) && ((ed == null) || (ed.getContentType() != CMElementDeclaration.EMPTY))) { - String proposedText = aNode.getNodeName(); - String proposedInfo = (ed != null) ? getAdditionalInfo(null, ed) : null; - if ((node.getNodeType() == Node.TEXT_NODE) && !contentAssistRequest.getDocumentRegion().isEnded()) { - proposedText += ">"; //$NON-NLS-1$ - } - CustomCompletionProposal proposal = null; - // double check to see if the region acted upon is - // a tag name; replace it if so - Image image = CMImageUtil.getImage(ed); - if (image == null) { - image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC); - } - if (contentAssistRequest.getRegion().getType() == DOMRegionContext.XML_TAG_NAME) { - proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getStartOffset(), contentAssistRequest.getRegion().getTextLength(), proposedText.length(), image, proposedText, null, proposedInfo, XMLRelevanceConstants.R_END_TAG_NAME); - } - else { - proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), proposedText.length(), image, NLS.bind(XMLUIMessages.Close_with__, (new Object[]{"'" + proposedText + "'"})), //$NON-NLS-1$ //$NON-NLS-2$ - null, proposedInfo, XMLRelevanceConstants.R_END_TAG_NAME); - } - contentAssistRequest.addProposal(proposal); - } - } - } - aNode = aNode.getParentNode(); - } - } - } - - /** - * Prompt for end tags to a non-empty Node that hasn't ended Handles these - * cases: <br> - * <tagOpen>| <br> - * <tagOpen>< |<br> - * <tagOpen></ | - * - * @param contentAssistRequest - */ - protected void addEndTagProposals(ContentAssistRequest contentAssistRequest) { - IDOMNode node = (IDOMNode) contentAssistRequest.getParent(); - - if (isCommentNode(node)) { - // loop and find non comment node parent - while ((node != null) && isCommentNode(node)) { - node = (IDOMNode) node.getParentNode(); - } - } - - // node is already closed - if (node.isClosed()) { - // loop and find non comment unclose node parent - while ((node != null) && node.isClosed()) { - node = (IDOMNode) node.getParentNode(); - } - } - // there were no unclosed tags - if (node == null) { - return; - } - - // data to create a CustomCompletionProposal - String replaceText = node.getNodeName() + ">"; //$NON-NLS-1$ - int replaceBegin = contentAssistRequest.getReplacementBeginPosition(); - int replaceLength = contentAssistRequest.getReplacementLength(); - int cursorOffset = node.getNodeName().length() + 1; - String displayString = ""; //$NON-NLS-1$ - String proposedInfo = ""; //$NON-NLS-1$ - Image image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC); - - setErrorMessage(null); - boolean addProposal = false; - - if (node.getNodeType() == Node.ELEMENT_NODE) { - // //////////////////////////////////////////////////////////////////////////////////// - IStructuredDocument sDoc = (IStructuredDocument) fTextViewer.getDocument(); - IStructuredDocumentRegion xmlEndTagOpen = sDoc.getRegionAtCharacterOffset(contentAssistRequest.getReplacementBeginPosition()); - // skip backward to "<", "</", or the (unclosed) start tag, null - // if not found - String type = ""; //$NON-NLS-1$ - while ((xmlEndTagOpen != null) && ((type = xmlEndTagOpen.getType()) != DOMRegionContext.XML_END_TAG_OPEN) && (type != DOMRegionContext.XML_TAG_CLOSE) && !needsEndTag(xmlEndTagOpen) && (type != DOMRegionContext.XML_TAG_OPEN)) { - xmlEndTagOpen = xmlEndTagOpen.getPrevious(); - } - - if (xmlEndTagOpen == null) { - return; - } - - node = (IDOMNode) node.getModel().getIndexedRegion(xmlEndTagOpen.getStartOffset()); - node = (IDOMNode) node.getParentNode(); - - if (isStartTag(xmlEndTagOpen)) { - // this is the case for a start tag w/out end tag - // eg: - // <p> - // <% String test = "test"; %> - // | - if (needsEndTag(xmlEndTagOpen)) { - String tagName = getTagName(xmlEndTagOpen); - xmlEndTagOpen.getTextEndOffset(); - replaceLength = 0; - replaceText = "</" + tagName + ">"; //$NON-NLS-1$ //$NON-NLS-2$ $NON-NLS-2$ - // replaceText = "</" + node.getNodeName() + ">"; - // //$NON-NLS-1$ $NON-NLS-2$ - cursorOffset = tagName.length() + 3; - displayString = NLS.bind(XMLUIMessages.End_with__, (new Object[]{tagName})); - addProposal = true; - } - } - else if (type == DOMRegionContext.XML_END_TAG_OPEN) { - // this is the case for: <tag> </ | - // possibly <tag> </ |<anotherTag> - // should only be replacing white space... - replaceLength = (replaceBegin > xmlEndTagOpen.getTextEndOffset()) ? replaceBegin - xmlEndTagOpen.getTextEndOffset() : 0; - replaceText = node.getNodeName() + ">"; //$NON-NLS-1$ - cursorOffset = replaceText.length(); - replaceBegin = xmlEndTagOpen.getTextEndOffset(); - displayString = NLS.bind(XMLUIMessages.End_with_, (new Object[]{node.getNodeName()})); - addProposal = true; - } - else if (type == DOMRegionContext.XML_TAG_OPEN) { - // this is the case for: <tag> < | - replaceText = "/" + node.getNodeName() + ">"; //$NON-NLS-1$ //$NON-NLS-2$ $NON-NLS-2$ - cursorOffset = replaceText.length(); - // replaceText = "/" + node.getNodeName() + ">"; //$NON-NLS-1$ - // $NON-NLS-2$ - // should only be replacing white space... - replaceLength = (replaceBegin > xmlEndTagOpen.getTextEndOffset()) ? replaceBegin - xmlEndTagOpen.getTextEndOffset() : 0; - replaceBegin = xmlEndTagOpen.getTextEndOffset(); - displayString = NLS.bind(XMLUIMessages.End_with_, (new Object[]{"/" + node.getNodeName()})); //$NON-NLS-1$ - addProposal = true; - } - } - // //////////////////////////////////////////////////////////////////////////////////// - // sometimes the node is not null, but - // getNodeValue() is null, put in a null check - else if ((node.getNodeValue() != null) && (node.getNodeValue().indexOf("</") != -1)) { //$NON-NLS-1$ - // the case where "</" is started, but the nodes comes in as a - // text node (instead of element) - // like this: <tag> </| - Node parent = node.getParentNode(); - if ((parent != null) && (parent.getNodeType() != Node.DOCUMENT_NODE)) { - replaceText = parent.getNodeName() + ">"; //$NON-NLS-1$ - cursorOffset = replaceText.length(); - displayString = NLS.bind(XMLUIMessages.End_with__, (new Object[]{parent.getNodeName()})); - setErrorMessage(null); - addProposal = true; - } - } - // //////////////////////////////////////////////////////////////////////////////////// - else if (node.getNodeType() == Node.DOCUMENT_NODE) { - setErrorMessage(UNKNOWN_CONTEXT); - } - if (addProposal == true) { - CustomCompletionProposal proposal = new CustomCompletionProposal(replaceText, replaceBegin, replaceLength, cursorOffset, image, displayString, null, proposedInfo, XMLRelevanceConstants.R_END_TAG); - contentAssistRequest.addProposal(proposal); - } - } - - protected void addEntityProposals(ContentAssistRequest contentAssistRequest, int documentPosition, ITextRegion completionRegion, IDOMNode treeNode) { - ICompletionProposal[] eps = computeEntityReferenceProposals(documentPosition, completionRegion, treeNode); - for (int i = 0; (eps != null) && (i < eps.length); i++) { - contentAssistRequest.addProposal(eps[i]); - } - } - - protected void addEntityProposals(Vector proposals, Properties map, String key, int nodeOffset, IStructuredDocumentRegion sdRegion, ITextRegion completionRegion) { - if (map == null) { - return; - } - String entityName = ""; //$NON-NLS-1$ - String entityValue = ""; //$NON-NLS-1$ - Image entityIcon = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ENTITY_REFERENCE); - String replacementText = ""; //$NON-NLS-1$ - String displayString = ""; //$NON-NLS-1$ - Enumeration keys = map.keys(); - - while ((keys != null) && keys.hasMoreElements()) { - entityName = (String) keys.nextElement(); - entityValue = map.getProperty(entityName); - // filter based on partial entity string... - if (entityName.toLowerCase().startsWith(key.toLowerCase()) || key.trim().equals("")) //$NON-NLS-1$ - { - // figure out selection...if text is selected, add it to - // selection length - int selectionLength = nodeOffset; - if (fTextViewer != null) { - selectionLength += fTextViewer.getSelectedRange().y; - } - // create a new proposal for entity string... - replacementText = "&" + entityName + ";"; //$NON-NLS-1$ //$NON-NLS-2$ - displayString = "&" + entityName + "; (" + entityValue + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - ICompletionProposal cp = new CustomCompletionProposal(replacementText, sdRegion.getStartOffset(completionRegion), selectionLength, replacementText.length(), entityIcon, displayString, null, null, XMLRelevanceConstants.R_ENTITY); - if (cp != null) { - proposals.add(cp); - } - } - } - } - - protected void addPCDATAProposal(String nodeName, ContentAssistRequest contentAssistRequest) { - CustomCompletionProposal proposal = new CustomCompletionProposal("<![CDATA[]]>", //$NON-NLS-1$ - contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), 9, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_CDATASECTION), "CDATA Section", //$NON-NLS-1$ - null, null, XMLRelevanceConstants.R_CDATA); - contentAssistRequest.addProposal(proposal); - - proposal = new CustomCompletionProposal(nodeName, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), nodeName.length(), XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TXTEXT), "#PCDATA", //$NON-NLS-1$ - null, null, XMLRelevanceConstants.R_CDATA); - contentAssistRequest.addProposal(proposal); - } - - protected void addStartDocumentProposals(ContentAssistRequest contentAssistRequest) { - Node aNode = contentAssistRequest.getNode(); - boolean xmlpiFound = false; - Document owningDocument = aNode.getOwnerDocument(); - // ==> // int xmlpiNodePosition = -1; - - // make sure xmlpi is root element - // don't want doctype proposal if XMLPI isn't first element... - Node first = owningDocument.getFirstChild(); - boolean xmlpiIsFirstElement = ((first != null) && (first.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE)); - boolean insertDoctype = xmlpiIsFirstElement; - - for (Node child = owningDocument.getFirstChild(); child != null; child = child.getNextSibling()) { - boolean xmlpi = ((child.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) && child.getNodeName().equals("xml")); //$NON-NLS-1$ - xmlpiFound = xmlpiFound || xmlpi; - if (xmlpiFound) { - if (child instanceof IDOMNode) { - // ==> // int xmlpiNodePosition = - // ((XMLNode)child).getEndOffset(); - } - // skip white space and text - while (((child = child.getNextSibling()) != null) && (child.getNodeType() == Node.TEXT_NODE)) { - // just skipping - } - // check if theres a node inbetween XMLPI and cursor position - if ((child != null) && (child instanceof IDOMNode)) { - if ((contentAssistRequest.getReplacementBeginPosition() >= ((IDOMNode) child).getEndOffset()) || !xmlpiIsFirstElement) { - insertDoctype = false; - } - } - break; - } - } - - if (xmlpiFound && (owningDocument.getDoctype() == null) && isCursorAfterXMLPI(contentAssistRequest) && insertDoctype) { - addDocTypeProposal(contentAssistRequest); - } - } - - /** - * Close an unclosed start tag - */ - protected void addTagCloseProposals(ContentAssistRequest contentAssistRequest) { - IDOMNode node = (IDOMNode) contentAssistRequest.getParent(); - if (node.getNodeType() == Node.ELEMENT_NODE) { - - CMElementDeclaration elementDecl = getCMElementDeclaration(node); - String proposedInfo = (elementDecl != null) ? getAdditionalInfo(null, elementDecl) : null; - int contentType = (elementDecl != null) ? elementDecl.getContentType() : CMElementDeclaration.ANY; - // if it's XML and content doesn't HAVE to be element, add "/>" - // proposal. - boolean endWithSlashBracket = (getXML(node) && (contentType != CMElementDeclaration.ELEMENT)); - - Image image = CMImageUtil.getImage(elementDecl); - if (image == null) { - image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC); - } - - // is the start tag ended properly? - if ((contentAssistRequest.getDocumentRegion() == node.getFirstStructuredDocumentRegion()) && !(node.getFirstStructuredDocumentRegion()).isEnded()) { - setErrorMessage(null); - // Is this supposed to be an empty tag? Note that if we can't - // tell, we assume it's not. - if ((elementDecl != null) && (elementDecl.getContentType() == CMElementDeclaration.EMPTY)) { - // prompt with a self-closing end character if needed - CustomCompletionProposal proposal = new CustomCompletionProposal(getContentGenerator().getStartTagClose(node, elementDecl), contentAssistRequest.getReplacementBeginPosition(), - // this is one of the few times to ignore the length -- - // always insert - // contentAssistRequest.getReplacementLength(), - 0, getContentGenerator().getStartTagClose(node, elementDecl).length(), image, NLS.bind(XMLUIMessages.Close_with___, (new Object[]{getContentGenerator().getStartTagClose(node, elementDecl)})), null, proposedInfo, XMLRelevanceConstants.R_CLOSE_TAG); - contentAssistRequest.addProposal(proposal); - } - else { - // prompt with a close for the start tag - CustomCompletionProposal proposal = new CustomCompletionProposal(">", //$NON-NLS-1$ - contentAssistRequest.getReplacementBeginPosition(), - // this is one of the few times to ignore the - // length -- always insert - // contentAssistRequest.getReplacementLength(), - 0, 1, image, NLS.bind(XMLUIMessages.Close_with__, (new Object[]{" '>'"})), //$NON-NLS-1$ - null, proposedInfo, XMLRelevanceConstants.R_CLOSE_TAG); - contentAssistRequest.addProposal(proposal); - - // prompt with the closer for the start tag and an end tag - // if one is not present - if (node.getEndStructuredDocumentRegion() == null) { - // make sure tag name is actually what it thinks it - // is...(eg. <%@ vs. <jsp:directive) - IStructuredDocumentRegion sdr = contentAssistRequest.getDocumentRegion(); - String openingTagText = (sdr != null) ? sdr.getFullText() : ""; //$NON-NLS-1$ - if ((openingTagText != null) && (openingTagText.indexOf(node.getNodeName()) != -1)) { - proposal = new CustomCompletionProposal("></" + node.getNodeName() + ">", //$NON-NLS-2$//$NON-NLS-1$ - contentAssistRequest.getReplacementBeginPosition(), - // this is one of the few times to - // ignore the length -- always insert - // contentAssistRequest.getReplacementLength(), - 0, 1, image, NLS.bind(XMLUIMessages.Close_with____, (new Object[]{node.getNodeName()})), null, proposedInfo, XMLRelevanceConstants.R_CLOSE_TAG); - contentAssistRequest.addProposal(proposal); - } - } - // prompt with slash bracket "/>" incase if it's a self - // ending tag - if (endWithSlashBracket) { - proposal = new CustomCompletionProposal("/>", //$NON-NLS-1$ - contentAssistRequest.getReplacementBeginPosition(), - // this is one of the few times to ignore - // the length -- always insert - // contentAssistRequest.getReplacementLength(), - 0, 2, image, NLS.bind(XMLUIMessages.Close_with__, (new Object[]{" \"/>\""})), //$NON-NLS-1$ - null, proposedInfo, XMLRelevanceConstants.R_CLOSE_TAG + 1); // +1 - // to - // bring - // to - // top - // of - // list - contentAssistRequest.addProposal(proposal); - } - } - } - else if ((contentAssistRequest.getDocumentRegion() == node.getLastStructuredDocumentRegion()) && !node.getLastStructuredDocumentRegion().isEnded()) { - setErrorMessage(null); - // prompt with a closing end character for the end tag - CustomCompletionProposal proposal = new CustomCompletionProposal(">", //$NON-NLS-1$ - contentAssistRequest.getReplacementBeginPosition(), - // this is one of the few times to ignore the - // length -- always insert - // contentAssistRequest.getReplacementLength(), - 0, 1, image, NLS.bind(XMLUIMessages.Close_with__, (new Object[]{" '>'"})), //$NON-NLS-1$ - null, proposedInfo, XMLRelevanceConstants.R_CLOSE_TAG); - contentAssistRequest.addProposal(proposal); - } - } - else if (node.getNodeType() == Node.DOCUMENT_NODE) { - setErrorMessage(UNKNOWN_CONTEXT); - } - } - - protected void addTagInsertionProposals(ContentAssistRequest contentAssistRequest, int childPosition) { - List cmnodes = null; - Node parent = contentAssistRequest.getParent(); - String error = null; - - // (nsd) This is only valid at the document element level - // only valid if it's XML (check added 2/17/2004) - if ((parent != null) && (parent.getNodeType() == Node.DOCUMENT_NODE) && ((IDOMDocument) parent).isXMLType() && !isCursorAfterXMLPI(contentAssistRequest)) { - return; - } - // only want proposals if cursor is after doctype... - if (!isCursorAfterDoctype(contentAssistRequest)) { - return; - } - - // fix for meta-info comment nodes.. they currently "hide" other - // proposals because the don't - // have a content model (so can't propose any children..) - if ((parent != null) && (parent instanceof IDOMNode) && isCommentNode((IDOMNode) parent)) { - // loop and find non comment node? - while ((parent != null) && isCommentNode((IDOMNode) parent)) { - parent = parent.getParentNode(); - } - } - - if (parent.getNodeType() == Node.ELEMENT_NODE) { - CMElementDeclaration parentDecl = getCMElementDeclaration(parent); - if (parentDecl != null) { - // XSD-specific ability - no filtering - CMDataType childType = parentDecl.getDataType(); - if (childType != null) { - String[] childStrings = childType.getEnumeratedValues(); - if (childStrings != null) { - // the content string is the sole valid child...so - // replace the rest - int begin = contentAssistRequest.getReplacementBeginPosition(); - int length = contentAssistRequest.getReplacementLength(); - if (parent instanceof IDOMNode) { - if (((IDOMNode) parent).getLastStructuredDocumentRegion() != ((IDOMNode) parent).getFirstStructuredDocumentRegion()) { - begin = ((IDOMNode) parent).getFirstStructuredDocumentRegion().getEndOffset(); - length = ((IDOMNode) parent).getLastStructuredDocumentRegion().getStartOffset() - begin; - } - } - String proposedInfo = getAdditionalInfo(parentDecl, childType); - for (int i = 0; i < childStrings.length; i++) { - CustomCompletionProposal textProposal = new CustomCompletionProposal(childStrings[i], begin, length, childStrings[i].length(), XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ENUM), childStrings[i], null, proposedInfo, XMLRelevanceConstants.R_TAG_INSERTION); - contentAssistRequest.addProposal(textProposal); - } - } - } - } - if ((parentDecl != null) && (parentDecl.getContentType() == CMElementDeclaration.PCDATA)) { - addPCDATAProposal(parentDecl.getNodeName(), contentAssistRequest); - } - else { - // retrieve the list of all possible children within this - // parent context - cmnodes = getAvailableChildElementDeclarations((Element) parent, childPosition, ModelQueryAction.INSERT); - - // retrieve the list of the possible children within this - // parent context and at this index - List strictCMNodeSuggestions = null; - if (XMLUIPreferenceNames.SUGGESTION_STRATEGY_VALUE_STRICT.equals(XMLUIPlugin.getInstance().getPreferenceStore().getString(XMLUIPreferenceNames.SUGGESTION_STRATEGY))) { - strictCMNodeSuggestions = getValidChildElementDeclarations((Element) parent, childPosition, ModelQueryAction.INSERT); - } - Iterator nodeIterator = cmnodes.iterator(); - if (!nodeIterator.hasNext()) { - if (getCMElementDeclaration(parent) != null) { - error = NLS.bind(XMLUIMessages._Has_no_available_child, (new Object[]{parent.getNodeName()})); - } - else { - error = NLS.bind(XMLUIMessages.Element__is_unknown, (new Object[]{parent.getNodeName()})); - } - } - String matchString = contentAssistRequest.getMatchString(); - // chop off any leading <'s and whitespace from the - // matchstring - while ((matchString.length() > 0) && (Character.isWhitespace(matchString.charAt(0)) || beginsWith(matchString, "<"))) { - //$NON-NLS-1$ - matchString = matchString.substring(1); - } - while (nodeIterator.hasNext()) { - Object o = nodeIterator.next(); - if (o instanceof CMElementDeclaration) { - CMElementDeclaration elementDecl = (CMElementDeclaration) o; - // only add proposals for the child element's that - // begin with the matchstring - String tagname = getRequiredName(parent, elementDecl); - boolean isStrictCMNodeSuggestion = strictCMNodeSuggestions != null ? strictCMNodeSuggestions.contains(elementDecl) : false; - - Image image = CMImageUtil.getImage(elementDecl); - - if (image == null) { - if (strictCMNodeSuggestions != null) { - image = isStrictCMNodeSuggestion ? XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC_EMPHASIZED) : XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC_DEEMPHASIZED); - } - else { - image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC); - } - - } - - // int markupAdjustment = - // getContentGenerator().getMinimalStartTagLength(parent, - // elementDecl); - if (beginsWith(tagname, matchString)) { - String proposedText = getRequiredText(parent, elementDecl); - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=89811 - // place cursor in first empty quotes - int markupAdjustment = getCursorPositionForProposedText(proposedText); - - String proposedInfo = getAdditionalInfo(parentDecl, elementDecl); - int relevance = isStrictCMNodeSuggestion ? XMLRelevanceConstants.R_STRICTLY_VALID_TAG_INSERTION : XMLRelevanceConstants.R_TAG_INSERTION; - CustomCompletionProposal proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), markupAdjustment, image, tagname, null, proposedInfo, relevance); - contentAssistRequest.addProposal(proposal); - } - } - } - if (contentAssistRequest.getProposals().size() == 0) { - if (error != null) { - setErrorMessage(error); - } - else if ((contentAssistRequest.getMatchString() != null) && (contentAssistRequest.getMatchString().length() > 0)) { - setErrorMessage(NLS.bind(XMLUIMessages.No_known_child_tag, (new Object[]{parent.getNodeName(), contentAssistRequest.getMatchString()}))); - //$NON-NLS-1$ = "No known child tag names of <{0}> begin with \"{1}\"." - } - else { - setErrorMessage(NLS.bind(XMLUIMessages.__Has_no_known_child, (new Object[]{parent.getNodeName()}))); - } - } - } - } - else if (parent.getNodeType() == Node.DOCUMENT_NODE) { - // Can only prompt with elements if the cursor position is past - // the XML processing - // instruction and DOCTYPE declaration - boolean xmlpiFound = false; - boolean doctypeFound = false; - int minimumOffset = -1; - - for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) { - - boolean xmlpi = ((child.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) && child.getNodeName().equals("xml")); //$NON-NLS-1$ - boolean doctype = child.getNodeType() == Node.DOCUMENT_TYPE_NODE; - if (xmlpi || (doctype && (minimumOffset < 0))) { - minimumOffset = ((IDOMNode) child).getFirstStructuredDocumentRegion().getStartOffset() + ((IDOMNode) child).getFirstStructuredDocumentRegion().getTextLength(); - } - xmlpiFound = xmlpiFound || xmlpi; - doctypeFound = doctypeFound || doctype; - } - - if (contentAssistRequest.getReplacementBeginPosition() >= minimumOffset) { - List childDecls = getAvailableRootChildren((Document) parent, childPosition); - for (int i = 0; i < childDecls.size(); i++) { - CMElementDeclaration ed = (CMElementDeclaration) childDecls.get(i); - if (ed != null) { - Image image = CMImageUtil.getImage(ed); - if (image == null) { - image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC); - } - String proposedText = getRequiredText(parent, ed); - String tagname = getRequiredName(parent, ed); - // account for the < and > - int markupAdjustment = getContentGenerator().getMinimalStartTagLength(parent, ed); - String proposedInfo = getAdditionalInfo(null, ed); - CustomCompletionProposal proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), markupAdjustment, image, tagname, null, proposedInfo, XMLRelevanceConstants.R_TAG_INSERTION); - contentAssistRequest.addProposal(proposal); - } - } - } - } - } - - protected void addTagNameProposals(ContentAssistRequest contentAssistRequest, int childPosition) { - List cmnodes = null; - Node parent = contentAssistRequest.getParent(); - IDOMNode node = (IDOMNode) contentAssistRequest.getNode(); - String error = null; - String matchString = contentAssistRequest.getMatchString(); - if (parent.getNodeType() == Node.ELEMENT_NODE) { - // retrieve the list of children - // validActions = getAvailableChildrenAtIndex((Element) parent, - // childPosition); - cmnodes = getAvailableChildElementDeclarations((Element) parent, childPosition, ModelQueryAction.INSERT); - Iterator nodeIterator = cmnodes.iterator(); - // chop off any leading <'s and whitespace from the matchstring - while ((matchString.length() > 0) && (Character.isWhitespace(matchString.charAt(0)) || beginsWith(matchString, "<"))) { - //$NON-NLS-1$ - matchString = matchString.substring(1); - } - if (!nodeIterator.hasNext()) { - error = NLS.bind(XMLUIMessages.__Has_no_known_child, (new Object[]{parent.getNodeName()})); - } - while (nodeIterator.hasNext()) { - CMNode elementDecl = (CMNode) nodeIterator.next(); - if (elementDecl != null) { - // only add proposals for the child element's that begin - // with the matchstring - String proposedText = null; - int cursorAdjustment = 0; - - // do a check to see if partial attributes of partial tag - // names are in list - if (((node != null) && (node.getAttributes() != null) && (node.getAttributes().getLength() > 0) && attributeInList(node, parent, elementDecl)) || ((node.getNodeType() != Node.TEXT_NODE) && node.getFirstStructuredDocumentRegion().isEnded())) { - - proposedText = getRequiredName(parent, elementDecl); - cursorAdjustment = proposedText.length(); - } - else { - proposedText = getRequiredName(parent, elementDecl); - cursorAdjustment = proposedText.length(); - if (elementDecl instanceof CMElementDeclaration) { - CMElementDeclaration ed = (CMElementDeclaration) elementDecl; - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=89811 - StringBuffer sb = new StringBuffer(); - getContentGenerator().generateTag(parent, ed, sb); - // since it's a name proposal, assume '<' is - // already there - // only return the rest of the tag - proposedText = sb.toString().substring(1); - cursorAdjustment = getCursorPositionForProposedText(proposedText); - - // cursorAdjustment = proposedText.length() + - // 1; - // proposedText += "></" + - // getRequiredName(parent, elementDecl) + ">"; - // //$NON-NLS-2$//$NON-NLS-1$ - } - } - if (beginsWith(proposedText, matchString)) { - Image image = CMImageUtil.getImage(elementDecl); - if (image == null) { - image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC); - } - String proposedInfo = getAdditionalInfo(getCMElementDeclaration(parent), elementDecl); - CustomCompletionProposal proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), cursorAdjustment, image, getRequiredName(parent, elementDecl), null, proposedInfo, XMLRelevanceConstants.R_TAG_NAME); - contentAssistRequest.addProposal(proposal); - } - } - } - if (contentAssistRequest.getProposals().size() == 0) { - if (error != null) { - setErrorMessage(error); - } - else if ((contentAssistRequest.getMatchString() != null) && (contentAssistRequest.getMatchString().length() > 0)) { - setErrorMessage(NLS.bind(XMLUIMessages.No_known_child_tag_names, (new Object[]{parent.getNodeName(), contentAssistRequest.getMatchString()}))); - //$NON-NLS-1$ = "No known child tag names of <{0}> begin with \"{1}\"" - } - else { - setErrorMessage(NLS.bind(XMLUIMessages.__Has_no_known_child, (new Object[]{parent.getNodeName()}))); - } - } - } - else if (parent.getNodeType() == Node.DOCUMENT_NODE) { - List childElements = getAvailableRootChildren((Document) parent, childPosition); - for (int i = 0; i < childElements.size(); i++) { - CMNode ed = (CMNode) childElements.get(i); - if (ed == null) { - continue; - } - String proposedText = null; - int cursorAdjustment = 0; - if (ed instanceof CMElementDeclaration) { - // proposedText = getRequiredName(parent, ed); - StringBuffer sb = new StringBuffer(); - getContentGenerator().generateTag(parent, (CMElementDeclaration) ed, sb); - // tag starts w/ '<', but we want to compare to name - proposedText = sb.toString().substring(1); - - if (!beginsWith(proposedText, matchString)) { - continue; - } - - cursorAdjustment = getCursorPositionForProposedText(proposedText); - - String proposedInfo = getAdditionalInfo(null, ed); - Image image = CMImageUtil.getImage(ed); - if (image == null) { - image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC); - } - CustomCompletionProposal proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), cursorAdjustment, image, getRequiredName(parent, ed), null, proposedInfo, XMLRelevanceConstants.R_TAG_NAME); - contentAssistRequest.addProposal(proposal); - } - } - } - } - - /** - * this is the position the cursor should be in after the proposal is - * applied - * - * @param proposedText - * @return the position the cursor should be in after the proposal is - * applied - */ - private int getCursorPositionForProposedText(String proposedText) { - int cursorAdjustment; - cursorAdjustment = proposedText.indexOf("\"\"") + 1; //$NON-NLS-1$ - // otherwise, after the first tag - if (cursorAdjustment == 0) { - cursorAdjustment = proposedText.indexOf('>') + 1; - } - if (cursorAdjustment == 0) { - cursorAdjustment = proposedText.length() + 1; - } - - return cursorAdjustment; - } - - /** - * @deprecated XML proposal is added via xml declaration template instead - */ - protected void addXMLProposal(ContentAssistRequest contentAssistRequest) { - String proposedText = "<?xml version=\"1.0\" encoding=\"" + ContentTypeEncodingPreferences.getUserPreferredCharsetName(ContentTypeIdForXML.ContentTypeID_XML) + "\"?>"; //$NON-NLS-2$//$NON-NLS-1$ - ICompletionProposal proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), proposedText.length(), XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_PROCESSINGINSTRUCTION), proposedText, null, null, XMLRelevanceConstants.R_XML_DECLARATION); - // TODO add special XML proposal info - contentAssistRequest.addProposal(proposal); - } - - /** - * This method determines if any of the attributes in the proposed XMLNode - * node, are possible values of attributes from possible Elements at this - * point in the document according to the Content Model. - * - * @param node - * the element with attributes that you would like to test if - * are possible for possible Elements at this point - * @param cmnode - * possible element at this point in the document (depending on - * what 'node' is) true if any attributes of 'node' match any - * possible attributes from 'cmnodes' list. - */ - protected boolean attributeInList(IDOMNode node, Node parent, CMNode cmnode) { - if ((node == null) || (parent == null) || (cmnode == null)) { - return false; - } - String elementMatchString = node.getNodeName(); - String cmnodeName = getRequiredName(parent, cmnode);// cmnode.getNodeName(); - if (node instanceof Element) { - NamedNodeMap map = ((Element) node).getAttributes(); - String attrMatchString = ""; //$NON-NLS-1$ - CMNamedNodeMap cmattrMap = null; - // iterate attribute possibilities for partially started node - for (int i = 0; (map != null) && (i < map.getLength()); i++) { - attrMatchString = map.item(i).getNodeName(); - // filter on whatever user typed for element name already - if (beginsWith(cmnodeName, elementMatchString)) { - if (cmnode.getNodeType() == CMNode.ELEMENT_DECLARATION) { - cmattrMap = ((CMElementDeclaration) cmnode).getAttributes(); - - CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(cmattrMap); - List nodes = ModelQueryUtil.getModelQuery(node.getOwnerDocument()).getAvailableContent((Element) node, (CMElementDeclaration) cmnode, ModelQuery.INCLUDE_ATTRIBUTES); - for (int k = 0; k < nodes.size(); k++) { - CMNode adnode = (CMNode) nodes.get(k); - if (adnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) { - allAttributes.put(adnode); - } - } - cmattrMap = allAttributes; - - // iterate possible attributes from a cmnode in - // proposal list - for (int k = 0; (cmattrMap != null) && (k < cmattrMap.getLength()); k++) { - // check if name matches - if (cmattrMap.item(k).getNodeName().equals(attrMatchString)) { - return true; - } - } - } - } - } - } - return false; - } - - protected boolean beginsWith(String aString, String prefix) { - if ((aString == null) || (prefix == null)) { - return true; - } - // (pa) matching independent of case to be consistant with Java - // editor CA - return aString.toLowerCase().startsWith(prefix.toLowerCase()); - } - - protected ContentAssistRequest computeAttributeProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) { - ContentAssistRequest contentAssistRequest = null; - IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition); - if (documentPosition < sdRegion.getStartOffset(completionRegion)) { - // setup to insert new attributes - contentAssistRequest = newContentAssistRequest(nodeAtOffset, node, sdRegion, completionRegion, documentPosition, 0, matchString); - } - else { - // Setup to replace an existing attribute name - contentAssistRequest = newContentAssistRequest(nodeAtOffset, node, sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion), completionRegion.getTextLength(), matchString); - } - addAttributeNameProposals(contentAssistRequest); - contentAssistRequest.setReplacementBeginPosition(documentPosition); - contentAssistRequest.setReplacementLength(0); - if ((node.getFirstStructuredDocumentRegion() != null) && (!node.getFirstStructuredDocumentRegion().isEnded())) { - addTagCloseProposals(contentAssistRequest); - } - return contentAssistRequest; - } - - protected ContentAssistRequest computeAttributeValueProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) { - ContentAssistRequest contentAssistRequest = null; - IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition); - if ((documentPosition > sdRegion.getStartOffset(completionRegion) + completionRegion.getTextLength()) && (sdRegion.getStartOffset(completionRegion) + completionRegion.getTextLength() != sdRegion.getStartOffset(completionRegion) + completionRegion.getLength())) { - // setup to add a new attribute at the documentPosition - IDOMNode actualNode = (IDOMNode) node.getModel().getIndexedRegion(sdRegion.getStartOffset(completionRegion)); - contentAssistRequest = newContentAssistRequest(actualNode, actualNode, sdRegion, completionRegion, documentPosition, 0, matchString); - addAttributeNameProposals(contentAssistRequest); - if ((actualNode.getFirstStructuredDocumentRegion() != null) && !actualNode.getFirstStructuredDocumentRegion().isEnded()) { - addTagCloseProposals(contentAssistRequest); - } - } - else { - // setup to replace the existing value - if (!nodeAtOffset.getFirstStructuredDocumentRegion().isEnded() && (documentPosition < sdRegion.getStartOffset(completionRegion))) { - // if the IStructuredDocumentRegion isn't closed and the - // cursor is in front of the value, add - contentAssistRequest = newContentAssistRequest(nodeAtOffset, node, sdRegion, completionRegion, documentPosition, 0, matchString); - addAttributeNameProposals(contentAssistRequest); - } - else { - contentAssistRequest = newContentAssistRequest(nodeAtOffset, node, sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion), completionRegion.getTextLength(), matchString); - addAttributeValueProposals(contentAssistRequest); - } - } - return contentAssistRequest; - } - - protected ContentAssistRequest computeCompletionProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode treeNode, IDOMNode xmlnode) { - ContentAssistRequest contentAssistRequest = null; - String regionType = completionRegion.getType(); - IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition); - - // Handle the most common and best supported cases - if ((xmlnode.getNodeType() == Node.ELEMENT_NODE) || (xmlnode.getNodeType() == Node.DOCUMENT_NODE)) { - if (regionType == DOMRegionContext.XML_TAG_OPEN) { - contentAssistRequest = computeTagOpenProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode); - } - else if (regionType == DOMRegionContext.XML_TAG_NAME) { - contentAssistRequest = computeTagNameProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode); - } - else if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) { - contentAssistRequest = computeAttributeProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode); - } - else if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) { - contentAssistRequest = computeEqualsProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode); - } - else if ((regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) && (documentPosition == sdRegion.getTextEndOffset()) && (sdRegion.getText(completionRegion).endsWith("\"") || sdRegion.getText(completionRegion).endsWith("\'"))) //$NON-NLS-1$ //$NON-NLS-2$ - { - // this is for when the cursor is at the end of the closing - // quote for an attribute.. - IDOMNode actualNode = (IDOMNode) xmlnode.getModel().getIndexedRegion(sdRegion.getStartOffset(completionRegion)); - contentAssistRequest = newContentAssistRequest(actualNode, actualNode, sdRegion, completionRegion, documentPosition, 0, matchString); - addTagCloseProposals(contentAssistRequest); - } - else if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) { - contentAssistRequest = computeAttributeValueProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode); - } - else if ((regionType == DOMRegionContext.XML_TAG_CLOSE) || (regionType == DOMRegionContext.XML_EMPTY_TAG_CLOSE) || (regionType.equals(DOMJSPRegionContextsPrivateCopy.JSP_DIRECTIVE_CLOSE))) { - contentAssistRequest = computeTagCloseProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode); - } - else if (regionType == DOMRegionContext.XML_END_TAG_OPEN) { - contentAssistRequest = computeEndTagOpenProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode); - } - else if ((regionType == DOMRegionContext.XML_CONTENT) || (regionType == DOMRegionContext.XML_CHAR_REFERENCE) || (regionType == DOMRegionContext.XML_ENTITY_REFERENCE) || (regionType == DOMRegionContext.XML_PE_REFERENCE)) { - contentAssistRequest = computeContentProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode); - } - - // These ITextRegion types begin DOM Elements as well and although - // internally harder to assist, - // text insertions directly before them can be made - else if ((documentPosition == sdRegion.getStartOffset(completionRegion)) && (regionType.equals(DOMJSPRegionContextsPrivateCopy.JSP_COMMENT_OPEN) || regionType.equals(DOMJSPRegionContextsPrivateCopy.JSP_DECLARATION_OPEN) || regionType.equals(DOMJSPRegionContextsPrivateCopy.JSP_DIRECTIVE_OPEN) || regionType.equals(DOMJSPRegionContextsPrivateCopy.JSP_EXPRESSION_OPEN) || regionType.equals(DOMJSPRegionContextsPrivateCopy.JSP_SCRIPTLET_OPEN) || (regionType == DOMRegionContext.XML_DECLARATION_OPEN) || (regionType == DOMRegionContext.XML_PI_OPEN) || (regionType == DOMRegionContext.XML_COMMENT_OPEN) || (regionType == DOMRegionContext.XML_CDATA_OPEN))) { - contentAssistRequest = newContentAssistRequest(treeNode, xmlnode.getParentNode(), sdRegion, completionRegion, documentPosition, 0, matchString); - addTagInsertionProposals(contentAssistRequest, getElementPositionForModelQuery(treeNode)); - addStartDocumentProposals(contentAssistRequest); - } - } - // Not a Document or Element? (odd cases go here for now) - else if (isCloseRegion(completionRegion)) { - contentAssistRequest = newContentAssistRequest(treeNode, xmlnode.getParentNode(), sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion) + completionRegion.getLength(), 0, matchString); - addStartDocumentProposals(contentAssistRequest); - if (documentPosition >= sdRegion.getTextEndOffset(completionRegion)) { - addTagInsertionProposals(contentAssistRequest, getElementPositionForModelQuery(treeNode) + 1); - } - } - else if ((documentPosition == sdRegion.getStartOffset(completionRegion)) && (regionType.equals(DOMJSPRegionContextsPrivateCopy.JSP_COMMENT_OPEN) || regionType.equals(DOMJSPRegionContextsPrivateCopy.JSP_DECLARATION_OPEN) || regionType.equals(DOMJSPRegionContextsPrivateCopy.JSP_DIRECTIVE_OPEN) || regionType.equals(DOMJSPRegionContextsPrivateCopy.JSP_EXPRESSION_OPEN) || regionType.equals(DOMJSPRegionContextsPrivateCopy.JSP_SCRIPTLET_OPEN) || (regionType == DOMRegionContext.XML_DECLARATION_OPEN) || (regionType == DOMRegionContext.XML_PI_OPEN) || (regionType == DOMRegionContext.XML_COMMENT_OPEN) || (regionType == DOMRegionContext.XML_CDATA_OPEN))) { - contentAssistRequest = newContentAssistRequest(treeNode, xmlnode.getParentNode(), sdRegion, completionRegion, documentPosition, 0, matchString); - addTagInsertionProposals(contentAssistRequest, getElementPositionForModelQuery(treeNode)); - addStartDocumentProposals(contentAssistRequest); - } - return contentAssistRequest; - } - - /** - * CONTENT ASSIST STARTS HERE - * - * Return a list of proposed code completions based on the specified - * location within the document that corresponds to the current cursor - * position within the text-editor control. - * - * @param textViewer - * @param documentPosition - - * the cursor location within the document - * - * an array of ICompletionProposals - */ - public ICompletionProposal[] computeCompletionProposals(ITextViewer textViewer, int documentPosition) { - - setErrorMessage(null); - - fTextViewer = textViewer; - - IndexedRegion treeNode = ContentAssistUtils.getNodeAt(textViewer, documentPosition); - - Node node = (Node) treeNode; - while ((node != null) && (node.getNodeType() == Node.TEXT_NODE) && (node.getParentNode() != null)) { - node = node.getParentNode(); - } - IDOMNode xmlnode = (IDOMNode) node; - - ContentAssistRequest contentAssistRequest = null; - - IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition); - ITextRegion completionRegion = getCompletionRegion(documentPosition, node); - - String matchString = getMatchString(sdRegion, completionRegion, documentPosition); - - // Handle empty Documents - if (completionRegion == null) { - if (((treeNode == null) || (((Node) treeNode).getNodeType() == Node.DOCUMENT_NODE)) && (completionRegion == null) && ((xmlnode == null) || (xmlnode.getChildNodes() == null) || (xmlnode.getChildNodes().getLength() == 0))) { - IStructuredModel sModel = StructuredModelManager.getModelManager().getExistingModelForRead(textViewer.getDocument()); - try { - if (sModel != null) { - IDOMDocument docNode = ((IDOMModel) sModel).getDocument(); - contentAssistRequest = newContentAssistRequest(docNode, docNode, sdRegion, completionRegion, documentPosition, 0, null); - addEmptyDocumentProposals(contentAssistRequest); - } - } - finally { - if (sModel != null) { - sModel.releaseFromRead(); - } - } - if (contentAssistRequest == null) { - Logger.logException(new IllegalStateException("problem getting model")); //$NON-NLS-1$ - return new ICompletionProposal[0]; - } - return contentAssistRequest.getCompletionProposals(); - } - // MASSIVE ERROR CONDITION - Logger.logException(new IllegalStateException("completion region was null")); //$NON-NLS-1$ - setErrorMessage(INTERNALERROR); - contentAssistRequest = newContentAssistRequest((Node) treeNode, node.getParentNode(), sdRegion, completionRegion, documentPosition, 0, ""); //$NON-NLS-1$ - return contentAssistRequest.getCompletionProposals(); - } - - - // catch documents where no region can be determined - if ((xmlnode.getNodeType() == Node.DOCUMENT_NODE) && ((completionRegion == null) || (xmlnode.getChildNodes() == null) || (xmlnode.getChildNodes().getLength() == 0))) { - contentAssistRequest = computeStartDocumentProposals(documentPosition, matchString, completionRegion, (IDOMNode) treeNode, xmlnode); - return contentAssistRequest.getCompletionProposals(); - } - - // compute normal proposals - contentAssistRequest = computeCompletionProposals(documentPosition, matchString, completionRegion, (IDOMNode) treeNode, xmlnode); - if (contentAssistRequest == null) { - contentAssistRequest = newContentAssistRequest((Node) treeNode, node.getParentNode(), sdRegion, completionRegion, documentPosition, 0, ""); //$NON-NLS-1$ - if (Debug.displayWarnings) { - System.out.println(UNKNOWN_CONTEXT + " " + completionRegion.getType() + "@" + documentPosition); //$NON-NLS-2$//$NON-NLS-1$ - } - setErrorMessage(UNKNOWN_CONTEXT); - } - - /* - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=123892 - * Only set this error message if nothing else was already set - **/ - if (contentAssistRequest.getProposals().size() == 0 && getErrorMessage() == null) { - setErrorMessage(UNKNOWN_CONTEXT); - } - - return contentAssistRequest.getCompletionProposals(); - } - - protected ContentAssistRequest computeContentProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) { - ContentAssistRequest contentAssistRequest = null; - - // setup to add children at the content node's position - contentAssistRequest = newContentAssistRequest(nodeAtOffset, node, getStructuredDocumentRegion(documentPosition), completionRegion, documentPosition, 0, matchString); - if ((node != null) && (node.getNodeType() == Node.DOCUMENT_NODE) && (((Document) node).getDoctype() == null)) { - addStartDocumentProposals(contentAssistRequest); - } - addTagInsertionProposals(contentAssistRequest, getElementPositionForModelQuery(nodeAtOffset)); - if (node.getNodeType() != Node.DOCUMENT_NODE) { - addEndTagProposals(contentAssistRequest); - } - // entities? - addEntityProposals(contentAssistRequest, documentPosition, completionRegion, node); - // addEntityProposals(contentAssistRequest); - return contentAssistRequest; - } - - /** - * Returns information about possible contexts based on the specified - * location within the document that corresponds to the current cursor - * position within the text viewer. - * - * @param viewer - * the viewer whose document is used to compute the possible - * contexts an array of context information objects or - * <code>null</code> if no context could be found - */ - public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) { - if (fAttributeInfoProvider == null) { - fAttributeInfoProvider = new AttributeContextInformationProvider((IStructuredDocument) viewer.getDocument(), (AttributeContextInformationPresenter) getContextInformationValidator()); - } - return fAttributeInfoProvider.getAttributeInformation(documentOffset); - } - - protected ContentAssistRequest computeEndTagOpenProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) { - ContentAssistRequest contentAssistRequest = null; - IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition); - int completionRegionStart = sdRegion.getStartOffset(completionRegion); - int completionRegionLength = completionRegion.getLength(); - IStructuredDocumentRegion sdRegionAtCompletionOffset = node.getStructuredDocument().getRegionAtCharacterOffset(completionRegionStart + completionRegionLength); - ITextRegion regionAtEndOfCompletion = sdRegionAtCompletionOffset.getRegionAtCharacterOffset(completionRegionStart + completionRegionLength); - - if ((documentPosition != completionRegionStart) && (regionAtEndOfCompletion != null) && (regionAtEndOfCompletion.getType() == DOMRegionContext.XML_TAG_NAME)) { - ITextRegion nameRegion = regionAtEndOfCompletion; - contentAssistRequest = newContentAssistRequest(nodeAtOffset, nodeAtOffset.getParentNode(), sdRegion, completionRegion, sdRegion.getStartOffset(nameRegion), nameRegion.getTextLength(), matchString); - } - else { - if (nodeAtOffset.getFirstStructuredDocumentRegion() == sdRegion) { - // abnormal case, this unmatched end tag will be a sibling - contentAssistRequest = newContentAssistRequest(nodeAtOffset, nodeAtOffset.getParentNode(), sdRegion, completionRegion, documentPosition, 0, matchString); - } - else { - // normal case, this end tag is the parent - contentAssistRequest = newContentAssistRequest(nodeAtOffset, nodeAtOffset, sdRegion, completionRegion, documentPosition, 0, matchString); - } - } - // if (documentPosition >= sdRegion.getStartOffset(completionRegion) + - // completionRegion.getTextLength()) - addEndTagProposals(contentAssistRequest); - // else - if (completionRegionStart == documentPosition) { - // positioned at start of end tag - addTagInsertionProposals(contentAssistRequest, node.getChildNodes().getLength()); - } - return contentAssistRequest; - } - - /** - * return all possible EntityReferenceProposals (according to current - * position in doc) - */ - protected ICompletionProposal[] computeEntityReferenceProposals(int documentPosition, ITextRegion completionRegion, IDOMNode treeNode) { - // only handle XML content for now - Vector proposals = new Vector(); // ICompletionProposals - IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition); - if ((completionRegion != null) && (completionRegion.getType() == DOMRegionContext.XML_CONTENT)) { - int nodeOffset = documentPosition - sdRegion.getStartOffset(completionRegion); - String regionText = sdRegion.getFullText(completionRegion); - - // if directly to the right of a &, region will be null, need to - // move to - // the previous region...there might be a better way to do this - if ((regionText != null) && regionText.trim().equals("") && (documentPosition > 0)) { //$NON-NLS-1$ - IStructuredDocumentRegion prev = treeNode.getStructuredDocument().getRegionAtCharacterOffset(documentPosition - 1); - if ((prev != null) && prev.getText().equals("&")) { //$NON-NLS-1$ - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=206680 - // examine previous region - sdRegion = prev; - completionRegion = prev.getLastRegion(); - regionText = prev.getFullText(); - nodeOffset = 1; - } - } - - // string must start w/ & - if ((regionText != null) && regionText.startsWith("&")) { //$NON-NLS-1$ - String key = (nodeOffset > 0) ? regionText.substring(1, nodeOffset) : ""; //$NON-NLS-1$ - - // get entity proposals, passing in the appropriate start - // string - ModelQuery mq = ModelQueryUtil.getModelQuery(((Node) treeNode).getOwnerDocument()); - if (mq != null) { - CMDocument xmlDoc = mq.getCorrespondingCMDocument(treeNode); - CMNamedNodeMap cmmap = null; - Properties entities = null; - if (xmlDoc != null) { - cmmap = xmlDoc.getEntities(); - } - if (cmmap != null) { - entities = mapToProperties(cmmap); - } - else // 224787 in absence of content model, just use - // minimal 5 entities - { - entities = new Properties(); - entities.put("quot", "\""); //$NON-NLS-1$ //$NON-NLS-2$ - entities.put("apos", "'"); //$NON-NLS-1$ //$NON-NLS-2$ - entities.put("amp", "&"); //$NON-NLS-1$ //$NON-NLS-2$ - entities.put("lt", "<"); //$NON-NLS-1$ //$NON-NLS-2$ - entities.put("gt", ">"); //$NON-NLS-1$ //$NON-NLS-2$ - entities.put("nbsp", " "); //$NON-NLS-1$ //$NON-NLS-2$ - } - addEntityProposals(proposals, entities, key, nodeOffset, sdRegion, completionRegion); - } - } - } - return (ICompletionProposal[]) ((proposals.size() > 0) ? proposals.toArray(new ICompletionProposal[proposals.size()]) : null); - } - - protected ContentAssistRequest computeEqualsProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) { - ContentAssistRequest contentAssistRequest = null; - IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition); - ITextRegion valueRegion = node.getStartStructuredDocumentRegion().getRegionAtCharacterOffset(sdRegion.getStartOffset(completionRegion) + completionRegion.getLength()); - if ((valueRegion != null) && (valueRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) && (sdRegion.getStartOffset(valueRegion) <= documentPosition)) { - // replace the adjacent attribute value - contentAssistRequest = newContentAssistRequest(nodeAtOffset, node, sdRegion, valueRegion, sdRegion.getStartOffset(valueRegion), valueRegion.getTextLength(), matchString); - } - else { - // append an attribute value after the '=' - contentAssistRequest = newContentAssistRequest(nodeAtOffset, node, sdRegion, completionRegion, documentPosition, 0, matchString); - } - addAttributeValueProposals(contentAssistRequest); - return contentAssistRequest; - } - - protected ContentAssistRequest computeStartDocumentProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) { - // setup for a non-empty document, but one that hasn't been formally - // started - ContentAssistRequest contentAssistRequest = null; - contentAssistRequest = newContentAssistRequest(nodeAtOffset, node, getStructuredDocumentRegion(documentPosition), completionRegion, documentPosition, 0, matchString); - addStartDocumentProposals(contentAssistRequest); - return contentAssistRequest; - } - - protected ContentAssistRequest computeTagCloseProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) { - ContentAssistRequest contentAssistRequest = null; - IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition); - - if ((node.getNodeType() == Node.DOCUMENT_NODE) || (documentPosition >= sdRegion.getEndOffset())) { - // this is a content request as the documentPosition is AFTER the - // end of the closing region - if ((node == nodeAtOffset) && (node.getParentNode() != null)) { - node = (IDOMNode) node.getParentNode(); - } - contentAssistRequest = newContentAssistRequest(nodeAtOffset, node, sdRegion, completionRegion, documentPosition, 0, matchString); - addTagInsertionProposals(contentAssistRequest, getElementPositionForModelQuery(nodeAtOffset)); - if ((node.getNodeType() != Node.DOCUMENT_NODE) && (node.getEndStructuredDocumentRegion() == null)) { - addEndTagProposals(contentAssistRequest); - } - } - else { - // at the start of the tag's close or within it - ITextRegion closeRegion = sdRegion.getLastRegion(); - boolean insideTag = !sdRegion.isEnded() || (documentPosition <= sdRegion.getStartOffset(closeRegion)); - if (insideTag) { - // this is a request for completions within a tag - contentAssistRequest = newContentAssistRequest(nodeAtOffset, node, sdRegion, completionRegion, documentPosition, 0, matchString); - if ((node.getNodeType() != Node.DOCUMENT_NODE) && (node.getEndStructuredDocumentRegion() != null)) { - addTagCloseProposals(contentAssistRequest); - } - if (sdRegion == nodeAtOffset.getFirstStructuredDocumentRegion()) { - contentAssistRequest.setReplacementBeginPosition(documentPosition); - contentAssistRequest.setReplacementLength(0); - addAttributeNameProposals(contentAssistRequest); - } - } - } - return contentAssistRequest; - } - - protected ContentAssistRequest computeTagNameProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) { - ContentAssistRequest contentAssistRequest = null; - IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition); - - if (sdRegion != nodeAtOffset.getFirstStructuredDocumentRegion()) { - // completing the *first* tag in "<tagname1 |<tagname2" - IDOMNode actualNode = (IDOMNode) node.getModel().getIndexedRegion(sdRegion.getStartOffset(completionRegion)); - if (actualNode != null) { - if (actualNode.getFirstStructuredDocumentRegion() == sdRegion) { - // start tag - if (documentPosition > sdRegion.getStartOffset(completionRegion) + completionRegion.getLength()) { - // it's attributes - contentAssistRequest = newContentAssistRequest(actualNode, actualNode, sdRegion, completionRegion, documentPosition - matchString.length(), matchString.length(), matchString); - if (node.getStructuredDocument().getRegionAtCharacterOffset(sdRegion.getStartOffset(completionRegion) - 1).getRegionAtCharacterOffset(sdRegion.getStartOffset(completionRegion) - 1).getType() == DOMRegionContext.XML_TAG_OPEN) { - addAttributeNameProposals(contentAssistRequest); - } - addTagCloseProposals(contentAssistRequest); - } - else { - // it's name - contentAssistRequest = newContentAssistRequest(actualNode, actualNode.getParentNode(), sdRegion, completionRegion, documentPosition - matchString.length(), matchString.length(), matchString); - addTagNameProposals(contentAssistRequest, getElementPositionForModelQuery(actualNode)); - } - } - else { - if (documentPosition >= sdRegion.getStartOffset(completionRegion) + completionRegion.getLength()) { - // insert name - contentAssistRequest = newContentAssistRequest(actualNode, actualNode.getParentNode(), sdRegion, completionRegion, documentPosition, 0, matchString); - } - else { - // replace name - contentAssistRequest = newContentAssistRequest(actualNode, actualNode.getParentNode(), sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion), completionRegion.getTextLength(), matchString); - } - addEndTagNameProposals(contentAssistRequest); - } - } - } - else { - if (documentPosition > sdRegion.getStartOffset(completionRegion) + completionRegion.getTextLength()) { - // unclosed tag with only a name; should prompt for attributes - // and a close instead - contentAssistRequest = newContentAssistRequest(nodeAtOffset, node, sdRegion, completionRegion, documentPosition - matchString.length(), matchString.length(), matchString); - addAttributeNameProposals(contentAssistRequest); - addTagCloseProposals(contentAssistRequest); - } - else { - if (sdRegion.getRegions().get(0).getType() != DOMRegionContext.XML_END_TAG_OPEN) { - int replaceLength = documentPosition - sdRegion.getStartOffset(completionRegion); - contentAssistRequest = newContentAssistRequest(node, node.getParentNode(), sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion), replaceLength, matchString); - addTagNameProposals(contentAssistRequest, getElementPositionForModelQuery(nodeAtOffset)); - } - else { - IDOMNode actualNode = (IDOMNode) node.getModel().getIndexedRegion(documentPosition); - if (actualNode != null) { - if (documentPosition >= sdRegion.getStartOffset(completionRegion) + completionRegion.getTextLength()) { - contentAssistRequest = newContentAssistRequest(actualNode, actualNode.getParentNode(), sdRegion, completionRegion, documentPosition, 0, matchString); - } - else { - contentAssistRequest = newContentAssistRequest(actualNode, actualNode.getParentNode(), sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion), completionRegion.getTextLength(), matchString); - } - addEndTagNameProposals(contentAssistRequest); - } - } - } - } - return contentAssistRequest; - } - - protected ContentAssistRequest computeTagOpenProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) { - ContentAssistRequest contentAssistRequest = null; - IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition); - if (sdRegion != nodeAtOffset.getFirstStructuredDocumentRegion()) { - // completing the *first* XML_TAG_OPEN in "<<tagname" - IDOMNode actualNode = (IDOMNode) node.getModel().getIndexedRegion(sdRegion.getStartOffset(completionRegion)); - if (actualNode != null) { - contentAssistRequest = newContentAssistRequest(actualNode, actualNode.getParentNode(), sdRegion, completionRegion, documentPosition, 0, matchString); - addTagNameProposals(contentAssistRequest, getElementPositionForModelQuery(actualNode)); - addEndTagProposals(contentAssistRequest); // (pa) 220850 - } - } - else { - if (documentPosition == sdRegion.getStartOffset(completionRegion)) { - if (node.getNodeType() == Node.ELEMENT_NODE) { - // at the start of an existing tag, right before the '<' - contentAssistRequest = newContentAssistRequest(nodeAtOffset, node.getParentNode(), sdRegion, completionRegion, documentPosition, 0, matchString); - addTagInsertionProposals(contentAssistRequest, getElementPositionForModelQuery(nodeAtOffset)); - addEndTagProposals(contentAssistRequest); - } - else if (node.getNodeType() == Node.DOCUMENT_NODE) { - // at the opening of the VERY first tag with a '<' - contentAssistRequest = newContentAssistRequest(nodeAtOffset, node.getParentNode(), sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion), completionRegion.getTextLength(), matchString); - addStartDocumentProposals(contentAssistRequest); - } - } - else { - // within the white space - ITextRegion name = getNameRegion(node.getStartStructuredDocumentRegion()); - // (pa) ITextRegion refactor - // if (name != null && name.containsOffset(documentPosition)) - // { - if ((name != null) && ((sdRegion.getStartOffset(name) <= documentPosition) && (sdRegion.getEndOffset(name) >= documentPosition))) { - // replace the existing name - contentAssistRequest = newContentAssistRequest(node, node.getParentNode(), sdRegion, completionRegion, sdRegion.getStartOffset(name), name.getTextLength(), matchString); - } - else { - // insert a valid new name, or possibly an end tag - contentAssistRequest = newContentAssistRequest(nodeAtOffset, ((Node) nodeAtOffset).getParentNode(), sdRegion, completionRegion, documentPosition, 0, matchString); - addEndTagProposals(contentAssistRequest); - contentAssistRequest.setReplacementBeginPosition(documentPosition); - contentAssistRequest.setReplacementLength(0); - } - addTagNameProposals(contentAssistRequest, getElementPositionForModelQuery(nodeAtOffset)); - } - } - return contentAssistRequest; - } - - /** - * Retreives cmnode's documentation to display in the completion - * proposal's additional info. If no documentation exists for cmnode, try - * displaying parentOrOwner's documentation - * - * String any documentation information to display for cmnode. - * <code>null</code> if there is nothing to display. - */ - protected String getAdditionalInfo(CMNode parentOrOwner, CMNode cmnode) { - String addlInfo = null; - - if (cmnode == null) { - if (Debug.displayWarnings) { - new IllegalArgumentException("Null declaration!").printStackTrace(); //$NON-NLS-1$ - } - return null; - } - - addlInfo = getInfoProvider().getInfo(cmnode); - if ((addlInfo == null) && (parentOrOwner != null)) { - addlInfo = getInfoProvider().getInfo(parentOrOwner); - } - return addlInfo; - } - - // returns a list of ModelQueryActions - protected List getAvailableChildrenAtIndex(Element parent, int index, int validityChecking) { - List list = new ArrayList(); - CMElementDeclaration parentDecl = getCMElementDeclaration(parent); - if (parentDecl != null) { - ModelQuery modelQuery = ModelQueryUtil.getModelQuery(parent.getOwnerDocument()); - // taken from ActionManagers - // int editMode = modelQuery.getEditMode(); - int editMode = ModelQuery.EDIT_MODE_UNCONSTRAINED; - int ic = (editMode == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) ? ModelQuery.INCLUDE_CHILD_NODES | ModelQuery.INCLUDE_SEQUENCE_GROUPS : ModelQuery.INCLUDE_CHILD_NODES; - modelQuery.getInsertActions(parent, parentDecl, index, ic, validityChecking, list); - } - return list; - } - - // returns a list of CMElementDeclarations - protected List getAvailableRootChildren(Document document, int childIndex) { - List list = null; - - // extract the valid 'root' node name from the DocumentType Node - DocumentType docType = document.getDoctype(); - String rootName = null; - if (docType != null) { - rootName = docType.getNodeName(); - } - if (rootName == null) { - return new ArrayList(0); - } - - for (Node child = document.getFirstChild(); child != null; child = child.getNextSibling()) { - // make sure the "root" Element isn't already present - // is it required to be an Element? - if ((child.getNodeType() == Node.ELEMENT_NODE) && stringsEqual(child.getNodeName(), rootName)) { - // if the node is missing either the start or end tag, don't - // count it as present - if ((child instanceof IDOMNode) && ((((IDOMNode) child).getStartStructuredDocumentRegion() == null) || (((IDOMNode) child).getEndStructuredDocumentRegion() == null))) { - continue; - } - if (Debug.displayInfo) { - System.out.println(rootName + " already present!"); //$NON-NLS-1$ - } - setErrorMessage(NLS.bind(XMLUIMessages.The_document_element__, (new Object[]{rootName}))); - return new ArrayList(0); - } - } - - list = new ArrayList(1); - ModelQuery modelQuery = ModelQueryUtil.getModelQuery(document); - if (modelQuery != null) { - CMDocument cmdoc = modelQuery.getCorrespondingCMDocument(document); - if (cmdoc != null) { - if (rootName != null) { - CMElementDeclaration rootDecl = (CMElementDeclaration) cmdoc.getElements().getNamedItem(rootName); - if (rootDecl != null) { - list.add(rootDecl); - } - else { - // supply the given document name anyway, even if it - // is an error - list.add(new SimpleCMElementDeclaration(rootName)); - if (Debug.displayInfo || Debug.displayWarnings) { - System.out.println("No definition found for " + rootName + " in " + docType.getPublicId() + "/" + docType.getSystemId()); //$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$ - } - String location = "" + (docType.getPublicId() != null ? docType.getPublicId() + "/" : "") + (docType.getSystemId() != null ? docType.getSystemId() : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - //$NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$ - //$NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$ - if (location.length() > 0) { - setErrorMessage(NLS.bind(XMLUIMessages.No_definition_for_in, (new Object[]{rootName, location}))); - } - else { - setErrorMessage(NLS.bind(XMLUIMessages.No_definition_for, (new Object[]{rootName}))); - } - } - } - } - else { - if (Debug.displayInfo || Debug.displayWarnings) { - System.out.println("No content model found."); //$NON-NLS-1$ - } - //$NON-NLS-1$ - //$NON-NLS-1$ - String location = "" + (docType.getPublicId() != null ? docType.getPublicId() + "/" : "") + (docType.getSystemId() != null ? docType.getSystemId() : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - //$NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$ - //$NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$ - if (location.length() > 0) { - setErrorMessage(NLS.bind(XMLUIMessages.No_content_model_for, (new Object[]{location}))); - } - else { - setErrorMessage(XMLUIMessages.No_content_model_found_UI_); - } - } - } - - return list; - } - - protected CMElementDeclaration getCMElementDeclaration(Node node) { - CMElementDeclaration result = null; - if (node.getNodeType() == Node.ELEMENT_NODE) { - ModelQuery modelQuery = ModelQueryUtil.getModelQuery(node.getOwnerDocument()); - if (modelQuery != null) { - result = modelQuery.getCMElementDeclaration((Element) node); - } - } - return result; - } - - /** - * Returns the characters which when entered by the user should - * automatically trigger the presentation of possible completions. - * - * the auto activation characters for completion proposal or - * <code>null</code> if no auto activation is desired - */ - public char[] getCompletionProposalAutoActivationCharacters() { - return completionProposalAutoActivationCharacters; - } - - protected ITextRegion getCompletionRegion(int offset, IStructuredDocumentRegion sdRegion) { - ITextRegion region = sdRegion.getRegionAtCharacterOffset(offset); - if (region == null) { - return null; - } - - if (sdRegion.getStartOffset(region) == offset) { - // The offset is at the beginning of the region - if ((sdRegion.getStartOffset(region) == sdRegion.getStartOffset()) && (sdRegion.getPrevious() != null) && (!sdRegion.getPrevious().isEnded())) { - // Is the region also the start of the node? If so, the - // previous IStructuredDocumentRegion is - // where to look for a useful region. - region = sdRegion.getPrevious().getRegionAtCharacterOffset(offset - 1); - } - else { - // Is there no separating whitespace from the previous region? - // If not, - // then that region is the important one - ITextRegion previousRegion = sdRegion.getRegionAtCharacterOffset(offset - 1); - if ((previousRegion != null) && (previousRegion != region) && (previousRegion.getTextLength() == previousRegion.getLength())) { - region = previousRegion; - } - } - } - else { - // The offset is NOT at the beginning of the region - if (offset > sdRegion.getStartOffset(region) + region.getTextLength()) { - // Is the offset within the whitespace after the text in this - // region? - // If so, use the next region - ITextRegion nextRegion = sdRegion.getRegionAtCharacterOffset(sdRegion.getStartOffset(region) + region.getLength()); - if (nextRegion != null) { - region = nextRegion; - } - } - else { - // Is the offset within the important text for this region? - // If so, then we've already got the right one. - } - } - - // valid WHITE_SPACE region handler (#179924) - if ((region != null) && (region.getType() == DOMRegionContext.WHITE_SPACE)) { - ITextRegion previousRegion = sdRegion.getRegionAtCharacterOffset(sdRegion.getStartOffset(region) - 1); - if (previousRegion != null) { - region = previousRegion; - } - } - - return region; - } - - /** - * Return the region whose content's require completion. This is something - * of a misnomer as sometimes the user wants to be prompted for contents - * of a non-existant ITextRegion, such as for enumerated attribute values - * following an '=' sign. - */ - protected ITextRegion getCompletionRegion(int documentPosition, Node domnode) { - if (domnode == null) { - return null; - } - - ITextRegion region = null; - int offset = documentPosition; - IStructuredDocumentRegion flatNode = null; - IDOMNode node = (IDOMNode) domnode; - - if (node.getNodeType() == Node.DOCUMENT_NODE) { - if (node.getStructuredDocument().getLength() == 0) { - return null; - } - ITextRegion result = node.getStructuredDocument().getRegionAtCharacterOffset(offset).getRegionAtCharacterOffset(offset); - while (result == null) { - offset--; - result = node.getStructuredDocument().getRegionAtCharacterOffset(offset).getRegionAtCharacterOffset(offset); - } - return result; - } - - IStructuredDocumentRegion startTag = node.getStartStructuredDocumentRegion(); - IStructuredDocumentRegion endTag = node.getEndStructuredDocumentRegion(); - - // Determine if the offset is within the start - // IStructuredDocumentRegion, end IStructuredDocumentRegion, or - // somewhere within the Node's XML content. - if ((startTag != null) && (startTag.getStartOffset() <= offset) && (offset < startTag.getStartOffset() + startTag.getLength())) { - flatNode = startTag; - } - else if ((endTag != null) && (endTag.getStartOffset() <= offset) && (offset < endTag.getStartOffset() + endTag.getLength())) { - flatNode = endTag; - } - - if (flatNode != null) { - // the offset is definitely within the start or end tag, continue - // on and find the region - region = getCompletionRegion(offset, flatNode); - } - else { - // the docPosition is neither within the start nor the end, so it - // must be content - flatNode = node.getStructuredDocument().getRegionAtCharacterOffset(offset); - // (pa) ITextRegion refactor - // if (flatNode.contains(documentPosition)) { - if ((flatNode.getStartOffset() <= documentPosition) && (flatNode.getEndOffset() >= documentPosition)) { - // we're interesting in completing/extending the previous - // IStructuredDocumentRegion if the current - // IStructuredDocumentRegion isn't plain content or if it's - // preceded by an orphan '<' - if ((offset == flatNode.getStartOffset()) && (flatNode.getPrevious() != null) && (((flatNode.getRegionAtCharacterOffset(documentPosition) != null) && (flatNode.getRegionAtCharacterOffset(documentPosition).getType() != DOMRegionContext.XML_CONTENT)) || (flatNode.getPrevious().getLastRegion().getType() == DOMRegionContext.XML_TAG_OPEN) || (flatNode.getPrevious().getLastRegion().getType() == DOMRegionContext.XML_END_TAG_OPEN))) { - // Is the region also the start of the node? If so, the - // previous IStructuredDocumentRegion is - // where to look for a useful region. - region = flatNode.getPrevious().getLastRegion(); - } - else if (flatNode.getEndOffset() == documentPosition) { - region = flatNode.getLastRegion(); - } - else { - region = flatNode.getFirstRegion(); - } - } - else { - // catch end of document positions where the docPosition isn't - // in a IStructuredDocumentRegion - region = flatNode.getLastRegion(); - } - } - - return region; - } - - /** - * Provided by default. Subclasses may override with their own - * implementations. - * - * @see AbstractContentAssistProcessor#getContentGenerator() - */ - public XMLContentModelGenerator getContentGenerator() { - if (fGenerator == null) { - fGenerator = new XMLContentModelGenerator(); - } - return fGenerator; - } - - /** - * Returns the characters which when entered by the user should - * automatically trigger the presentation of context information. - * - * the auto activation characters for presenting context information or - * <code>null</code> if no auto activation is desired - */ - public char[] getContextInformationAutoActivationCharacters() { - return contextInformationAutoActivationCharacters; - } - - /** - * Returns a validator used to determine when displayed context - * information should be dismissed. May only return <code>null</code> if - * the processor is incapable of computing context information. - * - * a context information validator, or <code>null</code> if the - * processor is incapable of computing context information - */ - public IContextInformationValidator getContextInformationValidator() { - if (fContextInformationPresenter == null) { - fContextInformationPresenter = new AttributeContextInformationPresenter(); - } - return fContextInformationPresenter; - } - - protected int getElementPosition(Node child) { - Node parent = child.getParentNode(); - if (parent == null) { - return 0; - } - - NodeList children = parent.getChildNodes(); - if (children == null) { - return 0; - } - int count = 0; - - for (int i = 0; i < children.getLength(); i++) { - if (children.item(i) == child) { - return count; - } - else { - // if (children.item(i).getNodeType() == Node.ELEMENT_NODE) - count++; - } - } - return 0; - } - - private int getElementPositionForModelQuery(Node child) { - return getElementPosition(child); - // return -1; - } - - /** - * Return the reason why computeProposals was not able to find any - * completions. - * - * an error message or null if no error occurred - */ - public String getErrorMessage() { - return fErrorMessage; - } - - /** - * @param iResource - */ - // public void initialize(IResource iResource) { - // this.resource = iResource; - // } - /** - * Gets the infoProvider. - * - * fInfoProvider and if fInfoProvider was <code>null</code> create a new - * instance - */ - public MarkupTagInfoProvider getInfoProvider() { - if (fInfoProvider == null) { - fInfoProvider = new MarkupTagInfoProvider(); - } - return fInfoProvider; - } - - protected String getMatchString(IStructuredDocumentRegion parent, ITextRegion aRegion, int offset) { - if ((aRegion == null) || isCloseRegion(aRegion)) { - return ""; //$NON-NLS-1$ - } - String matchString = null; - String regionType = aRegion.getType(); - if ((regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) || (regionType == DOMRegionContext.XML_TAG_OPEN) || (offset > parent.getStartOffset(aRegion) + aRegion.getTextLength())) { - matchString = ""; //$NON-NLS-1$ - } - else if (regionType == DOMRegionContext.XML_CONTENT) { - matchString = ""; //$NON-NLS-1$ - } - else { - if ((parent.getText(aRegion).length() > 0) && (parent.getStartOffset(aRegion) < offset)) { - matchString = parent.getText(aRegion).substring(0, offset - parent.getStartOffset(aRegion)); - } - else { - matchString = ""; //$NON-NLS-1$ - } - } - return matchString; - } - - protected ITextRegion getNameRegion(IStructuredDocumentRegion flatNode) { - if (flatNode == null) { - return null; - } - Iterator regionList = flatNode.getRegions().iterator(); - while (regionList.hasNext()) { - ITextRegion region = (ITextRegion) regionList.next(); - if (isNameRegion(region)) { - return region; - } - } - return null; - } - - /** - * Retrieves all of the possible valid values for this attribute - * declaration - */ - protected List getPossibleDataTypeValues(Node node, CMAttributeDeclaration ad) { - List list = null; - if (node.getNodeType() == Node.ELEMENT_NODE) { - Element element = (Element) node; - String[] dataTypeValues = null; - // The ModelQuery may not be available if the corresponding - // adapter - // is absent - ModelQuery modelQuery = ModelQueryUtil.getModelQuery(element.getOwnerDocument()); - if (modelQuery != null) { - dataTypeValues = modelQuery.getPossibleDataTypeValues(element, ad); - } - else { - if (ad.getAttrType() != null) { - dataTypeValues = ad.getAttrType().getEnumeratedValues(); - } - } - if (dataTypeValues != null) { - list = new ArrayList(dataTypeValues.length); - for (int i = 0; i < dataTypeValues.length; i++) { - list.add(dataTypeValues[i]); - } - } - } - if (list == null) { - list = new ArrayList(0); - } - return list; - } - - protected String getRequiredName(Node parentOrOwner, CMNode cmnode) { - if ((cmnode == null) || (parentOrOwner == null)) { - if (Debug.displayWarnings) { - new IllegalArgumentException("Null declaration!").printStackTrace(); //$NON-NLS-1$ - } - return ""; //$NON-NLS-1$ - } - return getContentGenerator().getRequiredName(parentOrOwner, cmnode); - } - - protected String getRequiredText(Node parentOrOwner, CMAttributeDeclaration attrDecl) { - if (attrDecl == null) { - if (Debug.displayWarnings) { - new IllegalArgumentException("Null attribute declaration!").printStackTrace(); //$NON-NLS-1$ - } - return ""; //$NON-NLS-1$ - } - StringBuffer buff = new StringBuffer(); - getContentGenerator().generateRequiredAttribute(parentOrOwner, attrDecl, buff); - return buff.toString(); - } - - protected String getRequiredText(Node parentOrOwner, CMElementDeclaration elementDecl) { - if (elementDecl == null) { - if (Debug.displayWarnings) { - new IllegalArgumentException("Null attribute declaration!").printStackTrace(); //$NON-NLS-1$ - } - return ""; //$NON-NLS-1$ - } - StringBuffer buff = new StringBuffer(); - getContentGenerator().generateTag(parentOrOwner, elementDecl, buff); - return buff.toString(); - } - - /** - * StructuredTextViewer must be set before using this. - */ - public IStructuredDocumentRegion getStructuredDocumentRegion(int pos) { - // (pa) ITextRegion refactor defect 245190 - // return - // (IStructuredDocumentRegion)ContentAssistUtils.getNodeAt((StructuredTextViewer)fTextViewer, - // pos); - return ContentAssistUtils.getStructuredDocumentRegion(fTextViewer, pos); - } - - private String getTagName(IStructuredDocumentRegion sdRegion) { - ITextRegionList regions = sdRegion.getRegions(); - ITextRegion region = null; - String name = ""; //$NON-NLS-1$ - for (int i = 0; i < regions.size(); i++) { - region = regions.get(i); - if (region.getType() == DOMRegionContext.XML_TAG_NAME) { - name = sdRegion.getText(region); - break; - } - } - return name; - } - - // returns a list of CMNodes that are available within this parent context - // Given the grammar shown below and a snippet of XML code (where the '|' - // indicated the cursor position) - // the list would return all of the element declarations that are - // potential child elements of Foo. - // - // grammar : Foo -> (A, B, C) - // snippet : <Foo><A>| - // result : {A, B, C} - // - // TODO cs... do we need to pass in the 'kindOfAction'? Seems to me we - // could assume it's always an insert. - protected List getAvailableChildElementDeclarations(Element parent, int childPosition, int kindOfAction) { - List modelQueryActions = getAvailableChildrenAtIndex(parent, childPosition, ModelQuery.VALIDITY_NONE); - Iterator iterator = modelQueryActions.iterator(); - List cmnodes = new Vector(); - while (iterator.hasNext()) { - ModelQueryAction action = (ModelQueryAction) iterator.next(); - if ((childPosition < 0) || (((action.getStartIndex() <= childPosition) && (childPosition <= action.getEndIndex())) && (action.getKind() == kindOfAction))) { - CMNode actionCMNode = action.getCMNode(); - if ((actionCMNode != null) && !cmnodes.contains(actionCMNode)) { - cmnodes.add(actionCMNode); - } - } - } - return cmnodes; - } - - // returns a list of CMNodes that can be validly inserted at this - // childPosition - // Given the grammar shown below and a snippet of XML code (where the '|' - // indicated the cursor position) - // the list would return only the element declarations can be inserted - // while maintaing validity of the content. - // - // grammar : Foo -> (A, B, C) - // snippet : <Foo><A>| - // result : {B} - // - protected List getValidChildElementDeclarations(Element parent, int childPosition, int kindOfAction) { - List modelQueryActions = getAvailableChildrenAtIndex(parent, childPosition, ModelQuery.VALIDITY_STRICT); - Iterator iterator = modelQueryActions.iterator(); - List cmnodes = new Vector(); - while (iterator.hasNext()) { - ModelQueryAction action = (ModelQueryAction) iterator.next(); - if ((childPosition < 0) || (((action.getStartIndex() <= childPosition) && (childPosition <= action.getEndIndex())) && (action.getKind() == kindOfAction))) { - CMNode actionCMNode = action.getCMNode(); - if ((actionCMNode != null) && !cmnodes.contains(actionCMNode)) { - cmnodes.add(actionCMNode); - } - } - } - return cmnodes; - } - - /** - * Similar to the call in HTMLContentAssistProcessor. Pass in a node, it - * tells you if the document is XML type. - * - * @param node - * - */ - protected boolean getXML(Node node) { - if (node == null) { - return false; - } - - Document doc = null; - doc = (node.getNodeType() != Node.DOCUMENT_NODE) ? node.getOwnerDocument() : ((Document) node); - - return (doc instanceof IDOMDocument) && ((IDOMDocument) doc).isXMLType(); - } - - // Initialize local settings - protected void init() { - // implement in subclasses - } - - protected boolean isCloseRegion(ITextRegion region) { - String type = region.getType(); - return ((type == DOMRegionContext.XML_PI_CLOSE) || (type == DOMRegionContext.XML_TAG_CLOSE) || (type == DOMRegionContext.XML_EMPTY_TAG_CLOSE) || (type == DOMRegionContext.XML_CDATA_CLOSE) || (type == DOMRegionContext.XML_COMMENT_CLOSE) || (type == DOMRegionContext.XML_ATTLIST_DECL_CLOSE) || (type == DOMRegionContext.XML_ELEMENT_DECL_CLOSE) || (type == DOMRegionContext.XML_DOCTYPE_DECLARATION_CLOSE) || (type == DOMJSPRegionContextsPrivateCopy.JSP_CLOSE) || (type == DOMJSPRegionContextsPrivateCopy.JSP_COMMENT_CLOSE) || (type.equals(DOMJSPRegionContextsPrivateCopy.JSP_DIRECTIVE_CLOSE)) || (type == DOMRegionContext.XML_DECLARATION_CLOSE)); - } - - /* - * This is to determine if a tag is a special meta-info comment tag that - * shows up as an ELEMENT - */ - private boolean isCommentNode(IDOMNode node) { - return ((node != null) && (node instanceof IDOMElement) && ((IDOMElement) node).isCommentTag()); - } - - /** - * Checks if cursor position is after doctype tag... - * - * @param car - * - */ - protected boolean isCursorAfterDoctype(ContentAssistRequest car) { - Node aNode = car.getNode(); - Document parent = aNode.getOwnerDocument(); - int xmldoctypeNodePosition = -1; - boolean isAfterDoctype = true; - - if (parent == null) { - return true; // blank document case - } - - for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) { - if (child instanceof IDOMNode) { - if (child.getNodeType() == Node.DOCUMENT_TYPE_NODE) { - xmldoctypeNodePosition = ((IDOMNode) child).getEndOffset(); - isAfterDoctype = (car.getReplacementBeginPosition() >= xmldoctypeNodePosition); - break; - } - } - } - return isAfterDoctype; - } - - /** - * This method can check if the cursor is after the XMLPI - * - * @param car - * - */ - protected boolean isCursorAfterXMLPI(ContentAssistRequest car) { - Node aNode = car.getNode(); - boolean xmlpiFound = false; - Document parent = aNode.getOwnerDocument(); - int xmlpiNodePosition = -1; - boolean isAfterXMLPI = false; - - if (parent == null) { - return true; // blank document case - } - - for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) { - boolean xmlpi = ((child.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) && child.getNodeName().equals("xml")); //$NON-NLS-1$ - xmlpiFound = xmlpiFound || xmlpi; - if (xmlpiFound) { - if (child instanceof IDOMNode) { - xmlpiNodePosition = ((IDOMNode) child).getEndOffset(); - isAfterXMLPI = (car.getReplacementBeginPosition() >= xmlpiNodePosition); - } - break; - } - } - return isAfterXMLPI; - } - - protected boolean isNameRegion(ITextRegion region) { - String type = region.getType(); - return ((type == DOMRegionContext.XML_TAG_NAME) || (type == DOMJSPRegionContextsPrivateCopy.JSP_DIRECTIVE_NAME) || (type == DOMRegionContext.XML_ELEMENT_DECL_NAME) || (type == DOMRegionContext.XML_DOCTYPE_NAME) || (type == DOMRegionContext.XML_ATTLIST_DECL_NAME) || (type == DOMJSPRegionContextsPrivateCopy.JSP_ROOT_TAG_NAME) || type.equals(DOMJSPRegionContextsPrivateCopy.JSP_DIRECTIVE_NAME)); - } - - protected boolean isQuote(String string) { - String trimmed = string.trim(); - if (trimmed.length() > 0) { - return (trimmed.charAt(0) == '\'') || (trimmed.charAt(0) == '"'); - } - return false; - } - - private boolean isSelfClosed(IStructuredDocumentRegion startTag) { - ITextRegionList regions = startTag.getRegions(); - return regions.get(regions.size() - 1).getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE; - } - - private boolean isStartTag(IStructuredDocumentRegion sdRegion) { - boolean result = false; - if (sdRegion.getRegions().size() > 0) { - ITextRegion r = sdRegion.getRegions().get(0); - result = (r.getType() == DOMRegionContext.XML_TAG_OPEN) && sdRegion.isEnded(); - } - return result; - } - - protected Properties mapToProperties(CMNamedNodeMap map) { - Properties p = new Properties(); - for (int i = 0; i < map.getLength(); i++) { - CMEntityDeclaration decl = (CMEntityDeclaration) map.item(i); - p.put(decl.getName(), decl.getValue()); - } - return p; - } - - /** - * Gets the corresponding XMLNode, and checks if it's closed. - * - * @param startTag - * - */ - private boolean needsEndTag(IStructuredDocumentRegion startTag) { - boolean result = false; - IStructuredModel sModel = StructuredModelManager.getModelManager().getExistingModelForRead(fTextViewer.getDocument()); - try { - if (sModel != null) { - IDOMNode xmlNode = (IDOMNode) sModel.getIndexedRegion(startTag.getStart()); - if (!isStartTag(startTag)) { - result = false; - } - else if (isSelfClosed(startTag)) { - result = false; - } - else if (!xmlNode.isContainer()) { - result = false; - } - else { - result = xmlNode.getEndStructuredDocumentRegion() == null; - } - } - } - finally { - if (sModel != null) { - sModel.releaseFromRead(); - } - } - return result; - } - - protected ContentAssistRequest newContentAssistRequest(Node node, Node possibleParent, IStructuredDocumentRegion documentRegion, ITextRegion completionRegion, int begin, int length, String filter) { - return new ContentAssistRequest(node, possibleParent, documentRegion, completionRegion, begin, length, filter); - } - - public void release() { - fGenerator = null; - } - - /** - * Set the reason why computeProposals was not able to find any - * completions. - */ - public void setErrorMessage(String errorMessage) { - fErrorMessage = errorMessage; - } - - /** - * Set the reason why computeProposals was not able to find any - * completions. - */ - protected void setErrorMessage(String errorMessage, String append) { - setErrorMessage(errorMessage + append); - } - - /** - * Set the reason why computeProposals was not able to find any - * completions. - */ - protected void setErrorMessage(String errorMessage, String prepend, String append) { - setErrorMessage(prepend + errorMessage + append); - } - - protected boolean stringsEqual(String a, String b) { - // (pa) 221190 matching independent of case to be consistant with Java - // editor CA - return a.equalsIgnoreCase(b); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AbstractContentModelGenerator.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AbstractContentModelGenerator.java deleted file mode 100644 index 7884482852..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AbstractContentModelGenerator.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.contentassist; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMNamespaceHelper; -import org.w3c.dom.Node; - - -public abstract class AbstractContentModelGenerator { - - public static boolean generateChildren = false; - - public AbstractContentModelGenerator() { - super(); - } - - public abstract void generateAttribute(CMAttributeDeclaration attrDecl, StringBuffer buffer); - - protected void generateAttributes(CMElementDeclaration elementDecl, StringBuffer buffer) { - CMNamedNodeMap attributes = elementDecl.getAttributes(); - if (attributes == null) { - return; - } - for (int i = 0; i < attributes.getLength(); i++) { - generateAttribute((CMAttributeDeclaration) attributes.item(i), buffer); - } - return; - } - - protected abstract void generateEndTag(String tagName, Node parentNode, CMElementDeclaration elementDecl, StringBuffer buffer); - - public void generateRequiredChildren(Node parentNode, CMElementDeclaration elementDecl, StringBuffer buffer) { - if (generateChildren) { - } - return; - } - - protected abstract void generateStartTag(String tagName, Node parentNode, CMElementDeclaration elementDecl, StringBuffer buffer); - - public void generateTag(Node parent, CMElementDeclaration elementDecl, StringBuffer buffer) { - if ((elementDecl == null) || (buffer == null)) { - return; - } - - String tagName = getRequiredName(parent, elementDecl); - - generateStartTag(tagName, parent, elementDecl, buffer); - generateRequiredChildren(parent, elementDecl, buffer); - generateEndTag(tagName, parent, elementDecl, buffer); - return; - } - - public abstract int getMinimalStartTagLength(Node node, CMElementDeclaration elementDecl); - - public String getRequiredName(Node ownerNode, CMNode cmnode) { - if (ownerNode != null) { - return DOMNamespaceHelper.computeName(cmnode, ownerNode, null); - } - return cmnode.getNodeName(); - } - - public abstract String getStartTagClose(Node parentNode, CMElementDeclaration elementDecl); - - protected boolean requiresAttributes(CMElementDeclaration ed) { - CMNamedNodeMap attributes = ed.getAttributes(); - if (attributes == null) { - return false; - } - for (int i = 0; i < attributes.getLength(); i++) { - if (((CMAttributeDeclaration) attributes.item(i)).getUsage() == CMAttributeDeclaration.REQUIRED) { - return true; - } - } - return false; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AttributeContextInformation.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AttributeContextInformation.java deleted file mode 100644 index 66e514ae24..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AttributeContextInformation.java +++ /dev/null @@ -1,115 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.contentassist; - -import java.util.HashMap; - -import org.eclipse.jface.text.contentassist.IContextInformation; -import org.eclipse.jface.text.contentassist.IContextInformationExtension; -import org.eclipse.swt.graphics.Image; -import org.eclipse.wst.sse.ui.internal.util.Assert; - - -/** - * Implementation of IContextInformation. Adds knowledge about the information - * display string such as required attributes for this context. - * - * @author pavery - */ -public class AttributeContextInformation implements IContextInformation, IContextInformationExtension { - private HashMap fAttr2RangeMap; - /** The name of the context */ - private String fContextDisplayString; - /** The image to be displayed */ - private Image fImage; - /** The information to be displayed */ - private String fInformationDisplayString; - private int fPosition = -1; - - /** - * Creates a new context information with an image. - * - * @param image - * the image to display when presenting the context information - * @param contextDisplayString - * the string to be used when presenting the context - * @param informationDisplayString - * the string to be displayed when presenting the context - * information, may not be <code>null</code> - */ - public AttributeContextInformation(Image image, String contextDisplayString, String informationDisplayString, HashMap attr2RangeMap) { - Assert.isNotNull(informationDisplayString, "illegal argument: informationDisplayString can not be null"); //$NON-NLS-1$ - - fImage = image; - fContextDisplayString = contextDisplayString; - fInformationDisplayString = informationDisplayString; - fAttr2RangeMap = attr2RangeMap; - } - - /** - * Creates a new context information without an image. - * - * @param contextDisplayString - * the string to be used when presenting the context - * @param informationDisplayString - * the string to be displayed when presenting the context - * information - */ - public AttributeContextInformation(String contextDisplayString, String informationDisplayString, HashMap attr2RangeMap) { - this(null, contextDisplayString, informationDisplayString, attr2RangeMap); - } - - /** - * Maps (String -> Position). The attribute name to the Text position. - * - * - */ - public HashMap getAttr2RangeMap() { - return fAttr2RangeMap; - } - - /** - * @see org.eclipse.jface.text.contentassist.IContextInformation#getContextDisplayString() - */ - public String getContextDisplayString() { - if (fContextDisplayString != null) { - return fContextDisplayString; - } - return fInformationDisplayString; - } - - /** - * @see org.eclipse.jface.text.contentassist.IContextInformationExtension#getContextInformationPosition() - */ - public int getContextInformationPosition() { - return fPosition; - } - - /** - * @see org.eclipse.jface.text.contentassist.IContextInformation#getImage() - */ - public Image getImage() { - return fImage; - } - - /** - * @see org.eclipse.jface.text.contentassist.IContextInformation#getInformationDisplayString() - */ - public String getInformationDisplayString() { - return fInformationDisplayString; - } - - public void setContextInformationPosition(int position) { - fPosition = position; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AttributeContextInformationPresenter.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AttributeContextInformationPresenter.java deleted file mode 100644 index acd660bb20..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AttributeContextInformationPresenter.java +++ /dev/null @@ -1,122 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.contentassist; - -import java.util.HashMap; - -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.Position; -import org.eclipse.jface.text.TextPresentation; -import org.eclipse.jface.text.contentassist.IContextInformation; -import org.eclipse.jface.text.contentassist.IContextInformationPresenter; -import org.eclipse.jface.text.contentassist.IContextInformationValidator; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StyleRange; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; - - -/** - * Responsible for the presentation of the context info popup. This includes - * text style, and when the window should close. - * - * @author pavery - */ -public class AttributeContextInformationPresenter implements IContextInformationPresenter, IContextInformationValidator { - private int fDocumentPosition = -1; - - private IContextInformation fInfo = null; - private ContextInfoModelUtil fModelUtil = null; - private ITextViewer fViewer = null; - - public AttributeContextInformationPresenter() { - super(); - } - - /** - * @see org.eclipse.jface.text.contentassist.IContextInformationValidator#install(org.eclipse.jface.text.contentassist.IContextInformation, - * org.eclipse.jface.text.ITextViewer, int) - */ - public void install(IContextInformation info, ITextViewer viewer, int documentPosition) { - fInfo = info; - fViewer = viewer; - fDocumentPosition = documentPosition; - fModelUtil = new ContextInfoModelUtil((IStructuredDocument) fViewer.getDocument()); - } - - /** - * @see org.eclipse.jface.text.contentassist.IContextInformationValidator#isContextInformationValid(int) - */ - public boolean isContextInformationValid(int documentPosition) { - // determine whether or not this context info should still be - // showing... - // if cursor still within the element it's valid... - boolean result = false; - if (fModelUtil != null) { - IStructuredDocumentRegion startRegion = fModelUtil.getXMLNode(fDocumentPosition).getStartStructuredDocumentRegion(); - int start = startRegion.getStartOffset(); - int end = startRegion.getEndOffset(); - result = (documentPosition < end) && (documentPosition > start + 1); - } - return result; - } - - /** - * @see org.eclipse.jface.text.contentassist.IContextInformationPresenter#updatePresentation(int, - * org.eclipse.jface.text.TextPresentation) - */ - public boolean updatePresentation(int documentPosition, TextPresentation presentation) { - presentation.clear(); - - if (!(fInfo instanceof AttributeContextInformation)) { - return false; - } - - // iterate existing attributes from current node - IDOMNode xmlNode = fModelUtil.getXMLNode(documentPosition); - IStructuredDocumentRegion sdRegion = xmlNode.getFirstStructuredDocumentRegion(); - ITextRegionList regions = sdRegion.getRegions(); - ITextRegion r = null; - String attrName = ""; //$NON-NLS-1$ - Object temp = null; - Position p = null; - HashMap map = ((AttributeContextInformation) fInfo).getAttr2RangeMap(); - - // so we can add ranges in order - StyleRange[] sorted = new StyleRange[fInfo.getInformationDisplayString().length()]; - for (int i = 0; i < regions.size(); i++) { - r = regions.get(i); - if (r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) { - attrName = sdRegion.getText(r); - temp = map.get(attrName); - if (temp != null) { - p = (Position) temp; - sorted[p.offset] = new StyleRange(p.offset, p.length, null, null, SWT.BOLD); - } - } - } - // style ranges need to be added in order - StyleRange sr = null; - for (int i = 0; i < sorted.length; i++) { - sr = sorted[i]; - if (sr != null) { - presentation.addStyleRange(sr); - } - } - return true; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AttributeContextInformationProvider.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AttributeContextInformationProvider.java deleted file mode 100644 index f0e90522c8..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AttributeContextInformationProvider.java +++ /dev/null @@ -1,231 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.contentassist; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; - -import org.eclipse.jface.text.Position; -import org.eclipse.jface.text.contentassist.ContextInformation; -import org.eclipse.jface.text.contentassist.IContextInformation; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList; -import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMContent; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMGroup; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList; -import org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - - -/** - * Calculates attribute context information based on a StructuedDocument and - * document position. - * - * @author pavery - */ -class AttributeContextInformationProvider { - private final IContextInformation[] EMPTY_CONTEXT_INFO = new IContextInformation[0]; - private Comparator fComparator; - - private IStructuredDocument fDocument = null; - private ContextInfoModelUtil fModelUtil = null; - - public AttributeContextInformationProvider(IStructuredDocument doc, AttributeContextInformationPresenter presenter) { - fDocument = doc; - fModelUtil = new ContextInfoModelUtil(fDocument); - } - - /** - * @param sdRegion - * - */ - private boolean canProposeInfo(IStructuredDocumentRegion sdRegion) { - if ((sdRegion != null) && isEndTag(sdRegion)) { - return false; - } - else { - return true; - } - } - - public IContextInformation[] getAttributeInformation(int offset) { - /* - * need to take care of special cases w/ ambiguous regions <tag>| - * </tag> also end tags.. - */ - IContextInformation[] results = EMPTY_CONTEXT_INFO; - - IStructuredDocumentRegion sdRegion = fModelUtil.getDocument().getRegionAtCharacterOffset(offset); - if (!canProposeInfo(sdRegion)) { - return EMPTY_CONTEXT_INFO; - } - - IDOMNode node = fModelUtil.getXMLNode(offset); - if (node != null) { - switch (node.getNodeType()) { - case Node.ELEMENT_NODE : - results = getInfoForElement(node); - break; - // future... - // case Node.TEXT_NODE : - // results = getInfoForText(node); - // break; - } - } - return results; - } - - /** - * Returns a comparator that compares CMAttributeDeclaration names. - * - * the comparator - */ - private Comparator getCMAttributeComparator() { - if (fComparator == null) { - fComparator = new Comparator() { - public int compare(Object o1, Object o2) { - return ((CMAttributeDeclaration) o1).getAttrName().compareTo(((CMAttributeDeclaration) o2).getAttrName()); - } - }; - } - return fComparator; - } - - /** - * @param node - * - */ - private IContextInformation[] getInfoForElement(IDOMNode node) { - IContextInformation[] results = EMPTY_CONTEXT_INFO; - CMElementDeclaration decl = fModelUtil.getModelQuery().getCMElementDeclaration((Element) node); - if (decl != null) { - CMNamedNodeMap attributes = decl.getAttributes(); - - CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(attributes); - List nodes = ModelQueryUtil.getModelQuery(node.getOwnerDocument()).getAvailableContent((Element) node, decl, ModelQuery.INCLUDE_ATTRIBUTES); - for (int k = 0; k < nodes.size(); k++) { - CMNode cmnode = (CMNode) nodes.get(k); - if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) { - allAttributes.put(cmnode); - } - } - attributes = allAttributes; - - String attrContextString = node.getNodeName(); - StringBuffer attrInfo = new StringBuffer(" "); //$NON-NLS-1$ - String name = ""; //$NON-NLS-1$ - HashMap attrPosMap = new HashMap(); - int pos = 0; - int length = 0; - int numPerLine = 8; - - CMAttributeDeclaration[] sortedAttrs = getSortedAttributes(attributes); - - for (int i = 0; i < sortedAttrs.length; i++) { - name = sortedAttrs[i].getAttrName(); - length = name.length(); - pos = attrInfo.length(); - - attrInfo.append(name); - - if (sortedAttrs[i].getUsage() == CMAttributeDeclaration.REQUIRED) { - attrInfo.append("*"); //$NON-NLS-1$ - length++; - } - if (i < attributes.getLength() - 1) { - attrInfo.append(" "); //$NON-NLS-1$ - if ((i != 0) && (i % numPerLine == 0)) { - attrInfo.append("\n "); //$NON-NLS-1$ - } - } - attrPosMap.put(name, new Position(pos, length)); - } - if (!attrInfo.toString().trim().equals("")) { - return new IContextInformation[]{new AttributeContextInformation(attrContextString, attrInfo.toString(), attrPosMap)}; - } - } - return results; - } - - /** - * @param node - * - */ - IContextInformation[] getInfoForText(IDOMNode node) { - Node parent = node.getParentNode(); - String contextString = node.getNodeName(); - StringBuffer info = new StringBuffer(" "); //$NON-NLS-1$ - if ((parent != null) && (parent.getNodeType() == Node.ELEMENT_NODE)) { - CMElementDeclaration decl = fModelUtil.getModelQuery().getCMElementDeclaration((Element) parent); - CMContent content = decl.getContent(); - if (content instanceof CMGroup) { - CMGroup cmGroup = (CMGroup) content; - CMNodeList children = cmGroup.getChildNodes(); - CMNode cmNode = null; - for (int i = 0; i < children.getLength(); i++) { - cmNode = children.item(i); - contextString = cmNode.getNodeName(); - if (contextString != null) { - info.append("<" + cmNode.getNodeName() + ">"); //$NON-NLS-1$ //$NON-NLS-2$ - if (i < children.getLength() - 1) { - info.append(" "); //$NON-NLS-1$ - } - } - } - } - } - if (!info.toString().trim().equals("")) { - return new IContextInformation[]{new ContextInformation(contextString, info.toString())}; - } - else { - return EMPTY_CONTEXT_INFO; - } - } - - /** - * Returns sorted array of CMAttributeDeclarations. - * - * @param attributes - * - */ - private CMAttributeDeclaration[] getSortedAttributes(CMNamedNodeMap attributes) { - List sorted = new ArrayList(); - for (int i = 0; i < attributes.getLength(); i++) { - sorted.add(attributes.item(i)); - } - Collections.sort(sorted, getCMAttributeComparator()); - return (CMAttributeDeclaration[]) sorted.toArray(new CMAttributeDeclaration[sorted.size()]); - } - - /** - * @param sdRegion - * - */ - private boolean isEndTag(IStructuredDocumentRegion sdRegion) { - ITextRegionList regions = sdRegion.getRegions(); - return regions.get(0).getType() == DOMRegionContext.XML_END_TAG_OPEN; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/ContentAssistRequest.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/ContentAssistRequest.java deleted file mode 100644 index 6a1d3af534..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/ContentAssistRequest.java +++ /dev/null @@ -1,260 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.contentassist; - - - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection; -import org.eclipse.wst.sse.core.utils.StringUtils; -import org.w3c.dom.Node; - - -public class ContentAssistRequest { - protected IStructuredDocumentRegion documentRegion = null; - protected List macros = new ArrayList(); - protected String matchString; - protected Node node = null; - protected Node parent = null; - protected List proposals = new ArrayList(); - protected ITextRegion region = null; - protected int replacementBeginPosition; - protected int replacementLength; - - // private Boolean separate = null; // (pa) not used - // private Boolean sort = null; // (pa) not used - /** - * XMLContentAssistRequest constructor comment. - */ - public ContentAssistRequest(Node node, Node parent, IStructuredDocumentRegion documentRegion, ITextRegion completionRegion, int begin, int length, String filter) { - super(); - setNode(node); - setParent(parent); - setDocumentRegion(documentRegion); - setRegion(completionRegion); - setMatchString(filter); - setReplacementBeginPosition(begin); - setReplacementLength(length); - } - - public void addMacro(ICompletionProposal newProposal) { - macros.add(newProposal); - } - - public void addProposal(ICompletionProposal newProposal) { - proposals.add(newProposal); - } - - public ICompletionProposal[] getCompletionProposals() { - ICompletionProposal results[] = null; - if ((getProposals().size() > 0) || (getMacros().size() > 0)) { - List allProposals = new ArrayList(); - if (!shouldSeparate()) { - allProposals.addAll(getProposals()); - // should be empty, as all macros should have gone into the - // proposal list - allProposals.addAll(getMacros()); - allProposals = sortProposals(allProposals); - } - else { - allProposals.addAll(sortProposals(getProposals())); - allProposals.addAll(sortProposals(getMacros())); - } - - results = new ICompletionProposal[allProposals.size()]; - for (int i = 0; i < allProposals.size(); i++) { - results[i] = (ICompletionProposal) allProposals.get(i); - } - } - return results; - } - - - public IStructuredDocumentRegion getDocumentRegion() { - return documentRegion; - } - - /** - * - * @return java.util.List - */ - public java.util.List getMacros() { - return macros; - } - - /** - * - * @return java.lang.String - */ - public java.lang.String getMatchString() { - return matchString; - } - - /** - * - * @return org.w3c.dom.Node - */ - public org.w3c.dom.Node getNode() { - return node; - } - - /** - * - * @return org.w3c.dom.Node - */ - public org.w3c.dom.Node getParent() { - return parent; - } - - /** - * - * @return java.util.List - */ - public java.util.List getProposals() { - return proposals; - } - - public ITextRegion getRegion() { - return region; - } - - /** - * - * @return int - */ - public int getReplacementBeginPosition() { - return replacementBeginPosition; - } - - /** - * @return int - */ - public int getReplacementLength() { - return replacementLength; - } - - public int getStartOffset() { - if ((getDocumentRegion() != null) && (getRegion() != null)) { - return ((ITextRegionCollection) getDocumentRegion()).getStartOffset(getRegion()); - } - return -1; - } - - public String getText() { - if ((getDocumentRegion() != null) && (getRegion() != null)) { - return ((ITextRegionCollection) getDocumentRegion()).getText(getRegion()); - } - return ""; //$NON-NLS-1$ - } - - public int getTextEndOffset() { - if ((getDocumentRegion() != null) && (getRegion() != null)) { - return ((ITextRegionCollection) getDocumentRegion()).getTextEndOffset(getRegion()); - } - return -1; - } - - /** - * @param region - */ - public void setDocumentRegion(IStructuredDocumentRegion region) { - documentRegion = region; - } - - /** - * - * @param newMatchString - * java.lang.String - */ - public void setMatchString(java.lang.String newMatchString) { - matchString = newMatchString; - } - - /** - * - * @param newNode - * org.w3c.dom.Node - */ - public void setNode(org.w3c.dom.Node newNode) { - node = newNode; - } - - /** - * - * @param newParent - * org.w3c.dom.Node - */ - public void setParent(org.w3c.dom.Node newParent) { - parent = newParent; - } - - /** - * - * @param newRegion - */ - public void setRegion(ITextRegion newRegion) { - region = newRegion; - } - - /** - * - * @param newReplacementBeginPosition - * int - */ - public void setReplacementBeginPosition(int newReplacementBeginPosition) { - replacementBeginPosition = newReplacementBeginPosition; - } - - - public void setReplacementLength(int newReplacementLength) { - replacementLength = newReplacementLength; - } - - public boolean shouldSeparate() { - /* - * if (separate == null) { PreferenceManager manager = - * getPreferenceManager(); if(manager == null) { separate = - * Boolean.FALSE; } else { Element caSettings = - * manager.getElement(PreferenceNames.CONTENT_ASSIST); separate = new - * Boolean(caSettings.getAttribute(PreferenceNames.SEPARATE).equals(PreferenceNames.TRUE)); } } - * return separate.booleanValue(); - */ - return false; - } - - protected List sortProposals(List proposalsIn) { - Collections.sort(proposalsIn, new ProposalComparator()); - return proposalsIn; - - } - - /** - * - * @return java.lang.String - */ - public java.lang.String toString() { - return "Node: " + getNode() //$NON-NLS-1$ - + "\nParent: " + getParent() //$NON-NLS-1$ - + "\nStructuredDocumentRegion: " + StringUtils.escape(getDocumentRegion().toString()) //$NON-NLS-1$ - + "\nRegion: " + getRegion() //$NON-NLS-1$ - + "\nMatch string: '" + StringUtils.escape(getMatchString()) + "'" //$NON-NLS-2$//$NON-NLS-1$ - + "\nOffsets: [" + getReplacementBeginPosition() + "-" + (getReplacementBeginPosition() + getReplacementLength()) + "]\n"; //$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$ - } - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/ContextInfoModelUtil.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/ContextInfoModelUtil.java deleted file mode 100644 index a48e75337b..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/ContextInfoModelUtil.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.contentassist; - -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; - - -/** - * @author pavery - */ -public class ContextInfoModelUtil { - IStructuredDocument fDocument = null; - - ContextInfoModelUtil(IStructuredDocument doc) { - fDocument = doc; - } - - public IStructuredDocument getDocument() { - return fDocument; - } - - public ModelQuery getModelQuery() { - ModelQuery mq = null; - - IStructuredModel xmlModel = null; - try { - xmlModel = StructuredModelManager.getModelManager().getExistingModelForRead(getDocument()); - mq = ModelQueryUtil.getModelQuery(xmlModel); - } - finally { - if (xmlModel != null) { - xmlModel.releaseFromRead(); - } - } - return mq; - } - - public IDOMNode getXMLNode(int offset) { - IStructuredModel xmlModel = null; - IDOMNode xmlNode = null; - try { - xmlModel = StructuredModelManager.getModelManager().getExistingModelForRead(getDocument()); - xmlNode = (IDOMNode) xmlModel.getIndexedRegion(offset); - } - finally { - if (xmlModel != null) - xmlModel.releaseFromRead(); - } - return xmlNode; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/CustomTemplateProposal.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/CustomTemplateProposal.java deleted file mode 100644 index f19dd90858..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/CustomTemplateProposal.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.wst.xml.ui.internal.contentassist; - -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.templates.Template; -import org.eclipse.jface.text.templates.TemplateContext; -import org.eclipse.jface.text.templates.TemplateProposal; -import org.eclipse.swt.graphics.Image; -import org.eclipse.wst.sse.core.utils.StringUtils; -import org.eclipse.wst.sse.ui.internal.contentassist.IRelevanceCompletionProposal; - -/** - * Purpose of this class is to make the additional proposal info into content - * fit for an HTML viewer (by escaping characters) - */ -class CustomTemplateProposal extends TemplateProposal implements IRelevanceCompletionProposal { - // copies of this class exist in: - // org.eclipse.jst.jsp.ui.internal.contentassist - // org.eclipse.wst.html.ui.internal.contentassist - // org.eclipse.wst.xml.ui.internal.contentassist - - public CustomTemplateProposal(Template template, TemplateContext context, IRegion region, Image image, int relevance) { - super(template, context, region, image, relevance); - } - - public String getAdditionalProposalInfo() { - String additionalInfo = super.getAdditionalProposalInfo(); - return StringUtils.convertToHTMLContent(additionalInfo); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/NoRegionContentAssistProcessor.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/NoRegionContentAssistProcessor.java deleted file mode 100644 index 57744f39bd..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/NoRegionContentAssistProcessor.java +++ /dev/null @@ -1,274 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.contentassist; - - - -import java.util.HashMap; -import java.util.Iterator; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.ITypedRegion; -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.text.contentassist.IContextInformation; -import org.eclipse.jface.text.contentassist.IContextInformationValidator; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.ui.internal.IReleasable; -import org.eclipse.wst.sse.ui.internal.StructuredTextViewer; -import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils; -import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; -import org.eclipse.wst.xml.core.text.IXMLPartitions; - - -/** - * ContentAssistProcessor to handle special cases in content assist where the - * partitioner cannot determine a partition type at the current cursor - * position (usually at EOF). - * - * @author pavery - */ -public class NoRegionContentAssistProcessor implements IContentAssistProcessor, IReleasable { - - private static final boolean DEBUG = false; - protected char completionProposalAutoActivationCharacters[] = null; - protected char contextInformationAutoActivationCharacters[] = null; - - private final ICompletionProposal[] EMPTY_PROPOSAL_SET = new ICompletionProposal[0]; - protected String fErrorMessage = null; - private HashMap fNameToProcessorMap = null; - private HashMap fPartitionToProcessorMap = null; - - public NoRegionContentAssistProcessor() { - super(); - } - - protected void addPartitionProcessor(String key, IContentAssistProcessor processor) { - addProcessor(getPartitionToProcessorMap(), key, processor); - } - - protected void addNameProcessor(String key, IContentAssistProcessor processor) { - addProcessor(getNameToProcessorMap(), key, processor); - } - - protected IContentAssistProcessor getPartitionProcessor(String key) { - return (IContentAssistProcessor) getPartitionToProcessorMap().get(key); - } - - /** - * Ensures release if it's a duplicate partition type. - * - * @param map - * @param key - * @param processor - */ - private void addProcessor(HashMap map, String key, IContentAssistProcessor processor) { - Object o = map.remove(key); - if (o != null) { - if (o instanceof IReleasable) { - ((IReleasable) o).release(); - } - } - map.put(key, processor); - } - - /** - * Figures out what the correct ICompletionProposalProcessor is and - * computesCompletionProposals on that. - * - * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer, - * int) - */ - public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) { - IContentAssistProcessor p = null; - ICompletionProposal[] results = EMPTY_PROPOSAL_SET; - - p = guessContentAssistProcessor(viewer, documentOffset); - if (p != null) { - results = p.computeCompletionProposals(viewer, documentOffset); - } - - return (results != null) ? results : EMPTY_PROPOSAL_SET; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeContextInformation(org.eclipse.jface.text.ITextViewer, - * int) - */ - public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) { - // get context info from processor that we end up using... - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getCompletionProposalAutoActivationCharacters() - */ - public char[] getCompletionProposalAutoActivationCharacters() { - return completionProposalAutoActivationCharacters; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationAutoActivationCharacters() - */ - public char[] getContextInformationAutoActivationCharacters() { - return contextInformationAutoActivationCharacters; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationValidator() - */ - public IContextInformationValidator getContextInformationValidator() { - // return the validator for the content assist processor that we - // used... - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getErrorMessage() - */ - public String getErrorMessage() { - return fErrorMessage; - } - - private HashMap getNameToProcessorMap() { - if (fNameToProcessorMap == null) { - fNameToProcessorMap = new HashMap(); - initNameToProcessorMap(); - } - return fNameToProcessorMap; - } - - private HashMap getPartitionToProcessorMap() { - if (fPartitionToProcessorMap == null) { - fPartitionToProcessorMap = new HashMap(); - initPartitionToProcessorMap(); - } - return fPartitionToProcessorMap; - } - - /** - * Gives you the document partition type (String) for the given - * StructuredTextViewer and documentPosition. - * - * @param viewer - * @param documentPosition - * @return String - */ - protected String getPartitionType(StructuredTextViewer viewer, int documentPosition) { - IDocument document = viewer.getDocument(); - String partitionType = null; - ITypedRegion partition = null; - try { - partition = document.getPartition(documentPosition); - partitionType = partition.getType(); - } - catch (BadLocationException e) { - partitionType = null; - } - return partitionType; - } - - /** - * Guesses a ContentAssistProcessor based on the TextViewer and - * documentOffset. - * - * @param viewer - * @param documentOffset - */ - protected IContentAssistProcessor guessContentAssistProcessor(ITextViewer viewer, int documentOffset) { - // mapping logic here... - // look @ previous region - // look @ previous doc partition type - // look @ page language - IContentAssistProcessor p = null; - IStructuredDocumentRegion sdRegion = ContentAssistUtils.getStructuredDocumentRegion(viewer, documentOffset); - if (sdRegion != null) { - String currentRegionType = sdRegion.getType(); - // System.out.println("current region type is >> " + - // currentRegionType); - if (currentRegionType == DOMRegionContext.UNDEFINED) { - IStructuredDocumentRegion sdPrev = sdRegion.getPrevious(); - if (sdPrev != null) { - if (DEBUG) { - String prevRegionType = sdPrev.getType(); - System.out.println("previous region type is >> " + prevRegionType); //$NON-NLS-1$ - } - } - } - } - // working w/ viewer & document partition - if ((p == null) && (viewer.getDocument().getLength() > 0)) { - String prevPartitionType = getPartitionType((StructuredTextViewer) viewer, documentOffset - 1); - // System.out.println("previous partition type is > " + - // prevPartitionType); - p = (IContentAssistProcessor) getPartitionToProcessorMap().get(prevPartitionType); - } - return p; - } - - /** - * Inits map for extra ContentAssistProcessors (useBean, get/setProperty) - */ - protected void initNameToProcessorMap() { - // nothing to do in this case - } - - /** - * Adds all relevent ContentAssistProcessors to the partition to processor - * map (just XML here) - */ - protected void initPartitionToProcessorMap() { - XMLContentAssistProcessor xmlProcessor = new XMLContentAssistProcessor(); - addProcessor(getPartitionToProcessorMap(), IXMLPartitions.XML_DEFAULT, xmlProcessor); - } - - public void release() { - releasePartitionToProcessorMap(); - releaseNameToProcessorMap(); - } - - protected void releaseMap(HashMap map) { - if ((map != null) && !map.isEmpty()) { - Iterator it = map.keySet().iterator(); - Object key = null; - while (it.hasNext()) { - key = it.next(); - if (map.get(key) instanceof IReleasable) { - ((IReleasable) map.get(key)).release(); - } - } - map.clear(); - map = null; - } - } - - protected void releaseNameToProcessorMap() { - releaseMap(fNameToProcessorMap); - } - - protected void releasePartitionToProcessorMap() { - releaseMap(fPartitionToProcessorMap); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/NonValidatingModelQueryAction.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/NonValidatingModelQueryAction.java deleted file mode 100644 index 24a397dcf6..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/NonValidatingModelQueryAction.java +++ /dev/null @@ -1,159 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.contentassist; - - - -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; - -public class NonValidatingModelQueryAction implements org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction { - - protected CMNode cmnode = null; - protected int endIndex = 0; - protected int kind = INSERT; - protected int startIndex = 0; - protected Object userData = null; - - /** - * NonValidatingModelQueryAction constructor comment. - */ - protected NonValidatingModelQueryAction() { - super(); - } - - /** - * NonValidatingModelQueryAction constructor comment. - */ - public NonValidatingModelQueryAction(CMNode newChild, int newKind, int newStart, int newEnd, Object newUserData) { - super(); - cmnode = newChild; - kind = newKind; - startIndex = newStart; - endIndex = newEnd; - userData = newUserData; - } - - /** - * getCMNode method comment. - */ - public org.eclipse.wst.xml.core.internal.contentmodel.CMNode getCMNode() { - return cmnode; - } - - /** - * - * @return int - */ - public int getEndIndex() { - return endIndex; - } - - /** - * - * @return int - */ - public int getKind() { - return kind; - } - - /** - * getParent method comment. - */ - public org.w3c.dom.Node getParent() { - return null; - } - - /** - * - * @return int - */ - public int getStartIndex() { - return startIndex; - } - - /** - * getUserData method comment. - */ - public Object getUserData() { - return null; - } - - /** - * performAction method comment. - */ - public void performAction() { - } - - /** - * setCMNode method comment. - */ - protected void setCMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode newNode) { - cmnode = newNode; - } - - /** - * - * @param newEndIndex - * int - */ - protected void setEndIndex(int newEndIndex) { - endIndex = newEndIndex; - } - - /** - * - * @param newKind - * int - */ - protected void setKind(int newKind) { - kind = newKind; - } - - /** - * - * @param newStartIndex - * int - */ - protected void setStartIndex(int newStartIndex) { - startIndex = newStartIndex; - } - - /** - * setUserData method comment. - */ - public void setUserData(Object object) { - } - - /** - * - * @return java.lang.String - */ - public String toString() { - String actionName = null; - switch (kind) { - case INSERT : - actionName = "INSERT";//$NON-NLS-1$ - break; - case REMOVE : - actionName = "REMOVE";//$NON-NLS-1$ - break; - case REPLACE : - actionName = "REPLACE";//$NON-NLS-1$ - break; - default : - actionName = "UNKNOWN ACTION ";//$NON-NLS-1$ - } - String nodeName = (cmnode != null) ? getCMNode().getNodeName() : "(unknown)";//$NON-NLS-1$ - return actionName + "=" + nodeName + "(" + startIndex + "..." + endIndex + ")";//$NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$ - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/ProposalComparator.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/ProposalComparator.java deleted file mode 100644 index ee6e8e8a66..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/ProposalComparator.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.contentassist; - - - -import java.util.Comparator; - -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.wst.sse.ui.internal.contentassist.IRelevanceCompletionProposal; - - -public class ProposalComparator implements Comparator { - - - public int compare(Object o1, Object o2) { - int relevance = 0; - if ((o1 instanceof IRelevanceCompletionProposal) && (o2 instanceof IRelevanceCompletionProposal)) { - // sort based on relevance - IRelevanceCompletionProposal cp1 = (IRelevanceCompletionProposal) o1; - IRelevanceCompletionProposal cp2 = (IRelevanceCompletionProposal) o2; - - relevance = cp2.getRelevance() - cp1.getRelevance(); - - // if same relevance, secondary sort (lexigraphically) - if ((relevance == 0) && (o1 instanceof ICompletionProposal) && (o2 instanceof ICompletionProposal)) { - String displayString1 = ((ICompletionProposal) o1).getDisplayString(); - String displayString2 = ((ICompletionProposal) o2).getDisplayString(); - if ((displayString1 != null) && (displayString2 != null)) { - // relevance = displayString1.compareTo(displayString2); - // // this didn't mix caps w/ lowercase - relevance = com.ibm.icu.text.Collator.getInstance().compare(displayString1, displayString2); - } - } - } - // otherwise if it's not ISEDRelevanceCompletionProposal, don't sort - return relevance; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/ReplaceNameTemplateContext.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/ReplaceNameTemplateContext.java deleted file mode 100644 index c371494694..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/ReplaceNameTemplateContext.java +++ /dev/null @@ -1,104 +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.wst.xml.ui.internal.contentassist; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.Position; -import org.eclipse.jface.text.templates.DocumentTemplateContext; -import org.eclipse.jface.text.templates.Template; -import org.eclipse.jface.text.templates.TemplateBuffer; -import org.eclipse.jface.text.templates.TemplateContextType; -import org.eclipse.jface.text.templates.TemplateException; - -/** - * Just like DocumentTemplateContext except if an insert offset is passed in, - * during evaluation, the "prefix" before the template will be checked to see - * if it matches the template name. If so, overwrite the template name. - * Otherwise, just insert the template at the insert offset location (by not - * overwriting the prefix text) - */ -public class ReplaceNameTemplateContext extends DocumentTemplateContext { - private int fInsertOffset = -1; - - /** - * Creates a document template context. - * - * @param type - * the context type - * @param document - * the document this context applies to - * @param offset - * the offset of the document region - * @param length - * the length of the document region - */ - public ReplaceNameTemplateContext(TemplateContextType type, IDocument document, int offset, int length) { - this(type, document, new Position(offset, length)); - } - - /** - * Creates a document template context. The supplied <code>Position</code> - * will be queried to compute the <code>getStart</code> and - * <code>getEnd</code> methods, which will therefore answer updated - * position data if it is registered with the document. - * - * @param type - * the context type - * @param document - * the document this context applies to - * @param position - * the position describing the area of the document which forms - * the template context - * @since 3.1 - */ - public ReplaceNameTemplateContext(TemplateContextType type, IDocument document, Position position) { - super(type, document, position); - } - - /** - * Creates a document template context. - * - * @param type - * the context type - * @param document - * the document this context applies to - * @param offset - * the offset of the document region - * @param length - * the length of the document region - * @param insertOffset - * the offset of the document region where insert was - * originally requested - */ - public ReplaceNameTemplateContext(TemplateContextType type, IDocument document, int offset, int length, int insertOffset) { - this(type, document, new Position(offset, length)); - fInsertOffset = insertOffset; - } - - /* - * @see org.eclipse.jface.text.templates.TemplateContext#evaluate(org.eclipse.jface.text.templates.Template) - */ - public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException { - TemplateBuffer buffer = super.evaluate(template); - if (buffer != null) { - if ((fInsertOffset > -1) && (fInsertOffset > getStart())) { - String prefix = getDocument().get(getStart(), fInsertOffset - getStart()); - if (!template.getName().startsWith(prefix)) { - // generate a new buffer that actually contains the - // text that was going to be overwritten - buffer = new TemplateBuffer(prefix + buffer.getString(), buffer.getVariables()); - } - } - } - return buffer; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/SimpleCMElementDeclaration.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/SimpleCMElementDeclaration.java deleted file mode 100644 index 41a607aa0e..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/SimpleCMElementDeclaration.java +++ /dev/null @@ -1,170 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.contentassist; - - - -public class SimpleCMElementDeclaration implements org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration { - - String fNodeName; - - /** - * SimpleCMELementDeclaration constructor comment. - */ - public SimpleCMElementDeclaration() { - super(); - } - - public SimpleCMElementDeclaration(String nodeName) { - super(); - setNodeName(nodeName); - } - - /** - * getAttributes method - * - * @return CMNamedNodeMap - * - * Returns CMNamedNodeMap of AttributeDeclaration - */ - public org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap getAttributes() { - return null; - } - - /** - * getCMContent method - * - * @return CMContent - * - * Returns the root node of this element's content model. This can be an - * CMElementDeclaration or a CMGroup - */ - public org.eclipse.wst.xml.core.internal.contentmodel.CMContent getContent() { - return null; - } - - /** - * getContentType method - * - * @return int - * - * Returns one of : ANY, EMPTY, ELEMENT, MIXED, PCDATA, CDATA. - */ - public int getContentType() { - return 0; - } - - /** - * getDataType method - * - * @return java.lang.String - */ - public org.eclipse.wst.xml.core.internal.contentmodel.CMDataType getDataType() { - return null; - } - - /** - * getElementName method - * - * @return java.lang.String - */ - public String getElementName() { - return null; - } - - /** - * getLocalElements method - * - * @return CMNamedNodeMap - * - * Returns a list of locally defined elements. - */ - public org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap getLocalElements() { - return null; - } - - /** - * getMaxOccur method - * - * @return int - * - * If -1, it's UNBOUNDED. - */ - public int getMaxOccur() { - return 0; - } - - /** - * getMinOccur method - * - * @return int - * - * If 0, it's OPTIONAL. If 1, it's REQUIRED. - */ - public int getMinOccur() { - return 0; - } - - /** - * - * @return java.lang.String - */ - public java.lang.String getNodeName() { - return fNodeName; - } - - /** - * getNodeType method - * - * @return int - * - * Returns one of : - * - */ - public int getNodeType() { - return 0; - } - - /** - * getProperty method - * - * @return java.lang.Object - * - * Returns the object property desciped by the propertyName - * - */ - public Object getProperty(String propertyName) { - return null; - } - - /** - * - * @param newNodeName - * java.lang.String - */ - public void setNodeName(java.lang.String newNodeName) { - fNodeName = newNodeName; - } - - /** - * supports method - * - * @return boolean - * - * Returns true if the CMNode supports a specified property - * - */ - public boolean supports(String propertyName) { - return false; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/SourceEditorImageHelper.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/SourceEditorImageHelper.java deleted file mode 100644 index fe16777023..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/SourceEditorImageHelper.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.contentassist; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.swt.graphics.Image; -import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; - - -/** - * @deprecated use internal XMLEditorPluginImageHelper or external - * SharedXMLEditorPluginImageHelper instead - */ -public class SourceEditorImageHelper { - - public SourceEditorImageHelper() { - super(); - } - - public Image createImage(String resource) { - ImageDescriptor desc = AbstractUIPlugin.imageDescriptorFromPlugin(XMLUIPlugin.ID, resource); - Image image = desc.createImage(); - JFaceResources.getImageRegistry().put(resource, image); - return image; - } - - public Image getImage(String resource) { - Image image = JFaceResources.getImageRegistry().get(resource); - if (image == null) { - image = createImage(resource); - } - return image; - } - - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLContentAssistProcessor.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLContentAssistProcessor.java deleted file mode 100644 index 252c04c5fb..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLContentAssistProcessor.java +++ /dev/null @@ -1,166 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.contentassist; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.IResource; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.jface.util.IPropertyChangeListener; -import org.eclipse.jface.util.PropertyChangeEvent; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.internal.preferences.XMLUIPreferenceNames; -import org.eclipse.wst.xml.ui.internal.templates.TemplateContextTypeIdsXML; - -public class XMLContentAssistProcessor extends AbstractContentAssistProcessor implements IPropertyChangeListener { - - protected IPreferenceStore fPreferenceStore = null; - protected IResource fResource = null; - private XMLTemplateCompletionProcessor fTemplateProcessor = null; - private List fTemplateContexts = new ArrayList(); - - public XMLContentAssistProcessor() { - super(); - } - - protected void addAttributeNameProposals(ContentAssistRequest contentAssistRequest) { - addTemplates(contentAssistRequest, TemplateContextTypeIdsXML.ATTRIBUTE); - super.addAttributeNameProposals(contentAssistRequest); - } - - protected void addAttributeValueProposals(ContentAssistRequest contentAssistRequest) { - addTemplates(contentAssistRequest, TemplateContextTypeIdsXML.ATTRIBUTE_VALUE); - super.addAttributeValueProposals(contentAssistRequest); - } - - protected void addEmptyDocumentProposals(ContentAssistRequest contentAssistRequest) { - addTemplates(contentAssistRequest, TemplateContextTypeIdsXML.NEW); - super.addEmptyDocumentProposals(contentAssistRequest); - } - - protected void addTagInsertionProposals(ContentAssistRequest contentAssistRequest, int childPosition) { - addTemplates(contentAssistRequest, TemplateContextTypeIdsXML.TAG); - super.addTagInsertionProposals(contentAssistRequest, childPosition); - } - - /** - * Adds templates to the list of proposals - * - * @param contentAssistRequest - * @param context - */ - private void addTemplates(ContentAssistRequest contentAssistRequest, String context) { - addTemplates(contentAssistRequest, context, contentAssistRequest.getReplacementBeginPosition()); - } - - /** - * Adds templates to the list of proposals - * - * @param contentAssistRequest - * @param context - * @param startOffset - */ - private void addTemplates(ContentAssistRequest contentAssistRequest, String context, int startOffset) { - if (contentAssistRequest == null) { - return; - } - - // if already adding template proposals for a certain context type, do - // not add again - if (!fTemplateContexts.contains(context)) { - fTemplateContexts.add(context); - boolean useProposalList = !contentAssistRequest.shouldSeparate(); - - if (getTemplateCompletionProcessor() != null) { - getTemplateCompletionProcessor().setContextType(context); - ICompletionProposal[] proposals = getTemplateCompletionProcessor().computeCompletionProposals(fTextViewer, startOffset); - for (int i = 0; i < proposals.length; ++i) { - if (useProposalList) { - contentAssistRequest.addProposal(proposals[i]); - } - else { - contentAssistRequest.addMacro(proposals[i]); - } - } - } - } - } - - protected ContentAssistRequest computeCompletionProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode treeNode, IDOMNode xmlnode) { - ContentAssistRequest request = super.computeCompletionProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode); - // bug115927 use original document position for all/any region - // templates - addTemplates(request, TemplateContextTypeIdsXML.ALL, documentPosition); - return request; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.xml.ui.contentassist.AbstractContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer, - * int) - */ - public ICompletionProposal[] computeCompletionProposals(ITextViewer textViewer, int documentPosition) { - fTemplateContexts.clear(); - return super.computeCompletionProposals(textViewer, documentPosition); - } - - protected IPreferenceStore getPreferenceStore() { - if (fPreferenceStore == null) { - fPreferenceStore = XMLUIPlugin.getDefault().getPreferenceStore(); - } - return fPreferenceStore; - } - - private XMLTemplateCompletionProcessor getTemplateCompletionProcessor() { - if (fTemplateProcessor == null) { - fTemplateProcessor = new XMLTemplateCompletionProcessor(); - } - return fTemplateProcessor; - } - - protected void init() { - getPreferenceStore().addPropertyChangeListener(this); - reinit(); - } - - public void propertyChange(PropertyChangeEvent event) { - String property = event.getProperty(); - - if ((property.compareTo(XMLUIPreferenceNames.AUTO_PROPOSE) == 0) || (property.compareTo(XMLUIPreferenceNames.AUTO_PROPOSE_CODE) == 0)) { - reinit(); - } - } - - protected void reinit() { - String key = XMLUIPreferenceNames.AUTO_PROPOSE; - boolean doAuto = getPreferenceStore().getBoolean(key); - if (doAuto) { - key = XMLUIPreferenceNames.AUTO_PROPOSE_CODE; - completionProposalAutoActivationCharacters = getPreferenceStore().getString(key).toCharArray(); - } - else { - completionProposalAutoActivationCharacters = null; - } - } - - public void release() { - super.release(); - getPreferenceStore().removePropertyChangeListener(this); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLContentAssistUtilities.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLContentAssistUtilities.java deleted file mode 100644 index 4aa4b346c8..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLContentAssistUtilities.java +++ /dev/null @@ -1,516 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.contentassist; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.osgi.util.NLS; -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer; -import org.eclipse.wst.sse.core.internal.util.ScriptLanguageKeys; -import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils; -import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper; -import org.w3c.dom.Document; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; - -/** - * @author pavery - */ -public class XMLContentAssistUtilities extends ContentAssistUtils { - - /** - * ISSUE: this is a bit of hidden JSP knowledge that was implemented this - * way for expedency. Should be evolved in future to depend on - * "nestedContext". - */ - private class DOMJSPRegionContextsPrivateCopy { - private static final String JSP_CLOSE = "JSP_CLOSE"; //$NON-NLS-1$ - private static final String JSP_DECLARATION_OPEN = "JSP_DECLARATION_OPEN"; //$NON-NLS-1$ - private static final String JSP_SCRIPTLET_OPEN = "JSP_SCRIPTLET_OPEN"; //$NON-NLS-1$ - private static final String JSP_EXPRESSION_OPEN = "JSP_EXPRESSION_OPEN"; //$NON-NLS-1$ - - } - - - public static final String CONTENT = "Content"; //$NON-NLS-1$ - public static final String CONTENT_SCRIPT_TYPE = "Content-Script-Type"; //$NON-NLS-1$ - public static final String HEAD = "HEAD"; //$NON-NLS-1$ - public static final String HTML = "HTML"; //$NON-NLS-1$ - public static final String HTTP_EQUIV = "HTTP-EQUIV"; //$NON-NLS-1$ - public static final String META = "META"; //$NON-NLS-1$ - - /** - * A convenience method for getting the closing proposal given the - * contents (IndexedRegion) of a tag that is started, but possibly not - * ended - * - * @param viewer - * the text viewer - * @param documentPosition - * the cursor position in the viewer - * @param indexedNode - * the contents of the tag that is started but possibly not - * ended - * @param parentTagName - * the tag on which you are checkin for an ending tag - * @param imagePath - * content assist image relative path - * @return ICompletionProposal - */ - public static ICompletionProposal computeJSPEndTagProposal(ITextViewer viewer, int documentPosition, IndexedRegion indexedNode, String parentTagName, String imagePath) { - ICompletionProposal p = null; - - // check if tag is closed - boolean hasEndTag = true; - boolean isJSPTag = false; - IDOMNode xnode = null; - String tagName = ""; //$NON-NLS-1$ - if (indexedNode instanceof IDOMNode) { - xnode = ((IDOMNode) indexedNode); - // it's ended already... - if (xnode.getEndStructuredDocumentRegion() != null) { - return null; - } - IDOMNode openNode = null; - if (!xnode.getNodeName().equalsIgnoreCase(parentTagName)) { - openNode = (IDOMNode) xnode.getParentNode(); - } - if (openNode != null) { - if (openNode instanceof IDOMElement) { - isJSPTag = ((IDOMElement) openNode).isJSPTag(); - } - tagName = openNode.getNodeName(); - hasEndTag = (openNode.getEndStructuredDocumentRegion() != null); - } - } - - // it's closed, don't add close tag proposal - if (!hasEndTag && !isJSPTag) { - - // create appropriate close tag text - String proposedText = "</" + tagName; //$NON-NLS-1$ - String viewerText = viewer.getTextWidget().getText(); - if ((viewerText.length() >= documentPosition) && (viewerText.length() >= 2) && (documentPosition >= 2)) { - String last2chars = viewerText.substring(documentPosition - 2, documentPosition); - if (last2chars.endsWith("</")) { - proposedText = tagName; - } - else if (last2chars.endsWith("<")) { - proposedText = "/" + tagName; //$NON-NLS-1$ - } - } - - // create proposal - p = new CustomCompletionProposal(proposedText + ">", //$NON-NLS-1$ - documentPosition, 0, proposedText.length() + 1, XMLEditorPluginImageHelper.getInstance().getImage(imagePath), NLS.bind(XMLUIMessages.End_with_, (new Object[]{proposedText})), null, null, XMLRelevanceConstants.R_END_TAG); - } - else if (!hasEndTag && isJSPTag) { - - // create appropriate close tag text - String proposedText = "%"; //$NON-NLS-1$ - String viewerText = viewer.getTextWidget().getText(); - - // TODO (pa) make it smarter to add "%>" or just ">" if % is - // already there... - if ((viewerText.length() >= documentPosition) && (viewerText.length() >= 2)) { - String last2chars = viewerText.substring(documentPosition - 2, documentPosition); - String lastchar = viewerText.substring(documentPosition - 1, documentPosition); - if (lastchar.equals("%")) //$NON-NLS-1$ - { - if (last2chars.endsWith("<%")) { - proposedText = "%"; //$NON-NLS-1$ - } - else { - proposedText = ""; //$NON-NLS-1$ - } - } - } - - // create proposal - p = new CustomCompletionProposal(proposedText + ">", //$NON-NLS-1$ - documentPosition, 0, proposedText.length() + 1, XMLEditorPluginImageHelper.getInstance().getImage(imagePath), NLS.bind(XMLUIMessages.End_with_, (new Object[]{proposedText})), null, null, XMLRelevanceConstants.R_END_TAG); - } - - return p; - } - - - /** - * A convenience method for getting the closing proposal given the - * contents (IndexedRegion) of a tag that is started, but possibly not - * ended - * - * @param viewer - * the text viewer - * @param documentPosition - * the cursor position in the viewer - * @param indexedNode - * the contents of the tag that is started but possibly not - * ended - * @param parentTagName - * the tag on which you are checkin for an ending tag - * @param imagePath - * content assist relative image path - * @return ICompletionProposal - */ - public static ICompletionProposal computeXMLEndTagProposal(ITextViewer viewer, int documentPosition, IndexedRegion indexedNode, String parentTagName, String imagePath) { - ICompletionProposal p = null; - - // check if tag is closed - boolean hasEndTag = true; - IDOMNode xnode = null; - String tagName = ""; //$NON-NLS-1$ - if (indexedNode instanceof IDOMNode) { - xnode = ((IDOMNode) indexedNode); - // it's ended already... - if (xnode.getEndStructuredDocumentRegion() != null) { - return null; - } - IDOMNode styleNode = null; - if (!xnode.getNodeName().equalsIgnoreCase(parentTagName)) { - styleNode = (IDOMNode) xnode.getParentNode(); - } - if (styleNode != null) { - tagName = styleNode.getNodeName(); - hasEndTag = (styleNode.getEndStructuredDocumentRegion() != null); - } - } - - // it's closed, don't add close tag proposal - if (!hasEndTag) { - - // create appropriate close tag text - String proposedText = "</" + tagName; //$NON-NLS-1$ - String viewerText = viewer.getTextWidget().getText(); - if ((viewerText.length() >= documentPosition) && (viewerText.length() >= 2) && (documentPosition >= 2)) { - String last2chars = viewerText.substring(documentPosition - 2, documentPosition); - if (last2chars.endsWith("</")) { - proposedText = tagName; - } - else if (last2chars.endsWith("<")) { - proposedText = "/" + tagName; //$NON-NLS-1$ - } - } - - // create proposal - p = new CustomCompletionProposal(proposedText + ">", //$NON-NLS-1$ - documentPosition, 0, proposedText.length() + 1, XMLEditorPluginImageHelper.getInstance().getImage(imagePath), NLS.bind(XMLUIMessages.End_with_, (new Object[]{proposedText})), null, null, XMLRelevanceConstants.R_END_TAG); - } - return p; - } - - private static String getMetaScriptType(Document doc) { - // Can not just do a Document.getElementsByTagName(String) as this - // needs - // to be relatively fast. - List metas = new ArrayList(); - // check for META tags under the Document - Node html = null; - Node head = null; - Node child = null; - // ---------------------------------------------------------------------- - // (pa) 20021217 - // cmvc defect 235554 - // performance enhancement: using child.getNextSibling() rather than - // nodeList(item) for O(n) vs. O(n*n) - // ---------------------------------------------------------------------- - - for (child = doc.getFirstChild(); child != null; child = child.getNextSibling()) { - if (child.getNodeType() != Node.ELEMENT_NODE) { - continue; - } - if (child.getNodeName().equalsIgnoreCase(META)) { - metas.add(child); - } - else if (child.getNodeName().equalsIgnoreCase(HTML)) { - html = child; - } - } - // NodeList children = doc.getChildNodes(); - // for(int i = 0; i < children.getLength(); i++) { - // child = children.item(i); - // if(child.getNodeType() != Node.ELEMENT_NODE) - // continue; - // if(child.getNodeName().equalsIgnoreCase(META)) - // metas.add(child); - // else if(child.getNodeName().equalsIgnoreCase(HTML)) - // html = child; - // } - - // check for META tags under HEAD - if (html != null) { - for (child = html.getFirstChild(); (child != null) && (head == null); child = child.getNextSibling()) { - if (child.getNodeType() != Node.ELEMENT_NODE) { - continue; - } - if (child.getNodeName().equalsIgnoreCase(HEAD)) { - head = child; - } - } - // children = html.getChildNodes(); - // for(int i = 0; i < children.getLength() && head == null; i++) { - // child = children.item(i); - // if(child.getNodeType() != Node.ELEMENT_NODE) - // continue; - // if(child.getNodeName().equalsIgnoreCase(HEAD)) - // head = child; - // } - } - - if (head != null) { - for (head.getFirstChild(); child != null; child = child.getNextSibling()) { - if (child.getNodeType() != Node.ELEMENT_NODE) { - continue; - } - if (child.getNodeName().equalsIgnoreCase(META)) { - metas.add(child); - } - } - // children = head.getChildNodes(); - // for(int i = 0 ; i < children.getLength(); i++) { - // child = children.item(i); - // if(child.getNodeType() != Node.ELEMENT_NODE) - // continue; - // if(child.getNodeName().equalsIgnoreCase(META)) - // metas.add(child); - // } - } - - return getMetaScriptType(metas); - } - - private static String getMetaScriptType(List metaNodeList) { - Node meta = null; - NamedNodeMap attributes = null; - boolean httpEquiv = false; - String contentScriptType = null; - - for (int i = metaNodeList.size() - 1; i >= 0; i--) { - meta = (Node) metaNodeList.get(i); - attributes = meta.getAttributes(); - httpEquiv = false; - contentScriptType = null; - for (int j = 0; j < attributes.getLength(); j++) { - if (attributes.item(j).getNodeName().equalsIgnoreCase(HTTP_EQUIV)) { - httpEquiv = attributes.item(j).getNodeValue().equalsIgnoreCase(CONTENT_SCRIPT_TYPE); - } - else if (attributes.item(j).getNodeName().equalsIgnoreCase(CONTENT)) { - contentScriptType = attributes.item(j).getNodeValue(); - } - } - if (httpEquiv && (contentScriptType != null)) { - return contentScriptType; - } - } - return null; - } - - /** - * Returns the scripting language the scriptNode is in Currently returns - * javascript unless some unknown type or language is specified. Then the - * unknown type/language is returned - * - * @param scriptNode - */ - public static String getScriptLanguage(Node scriptNode) { - Node attr = null; - - boolean specified = false; - // try to find a scripting adapter for 'type' - if ((scriptNode == null) || (scriptNode.getAttributes() == null)) { - return null; - } - - attr = scriptNode.getAttributes().getNamedItem("type");//$NON-NLS-1$ - if (attr != null) { - specified = true; - String type = attr.getNodeValue(); - return lookupScriptType(type); - } - // now try to find a scripting adapter for 'language' (deprecated by - // HTML specifications) - attr = scriptNode.getAttributes().getNamedItem("language");//$NON-NLS-1$ - if (attr != null) { - specified = true; - String language = attr.getNodeValue(); - return lookupScriptLanguage(language); - } - // check if one is specified by a META tag at the root level or inside - // of HEAD - String type = null; - if (!specified) { - type = getMetaScriptType(scriptNode.getOwnerDocument()); - } - if (type != null) { - specified = true; - return lookupScriptType(type); - } - // return default - if (!specified) { - return ScriptLanguageKeys.JAVASCRIPT; - } - return null; - } - - /** - * Tells you if the flatnode is the %> delimiter - * - * ISSUE: this is a bit of hidden JSP knowledge that was implemented this - * way for expedency. Should be evolved in future to depend on - * "nestedContext". - */ - public static boolean isJSPCloseDelimiter(IStructuredDocumentRegion fn) { - if (fn == null) { - return false; - } - return isJSPCloseDelimiter(fn.getType()); - } - - /** - * ISSUE: this is a bit of hidden JSP knowledge that was implemented this - * way for expedency. Should be evolved in future to depend on - * "nestedContext". - */ - public static boolean isJSPCloseDelimiter(String type) { - if (type == null) { - return false; - } - return (type.equals(DOMJSPRegionContextsPrivateCopy.JSP_CLOSE) || type.equals(DOMRegionContext.XML_TAG_CLOSE)); - } - - /** - * Tells you if the flatnode is the JSP region <%%>, <%=%>, <%!%> - * - * ISSUE: this is a bit of hidden JSP knowledge that was implemented this - * way for expedency. Should be evolved in future to depend on - * "nestedContext". - */ - public static boolean isJSPDelimiter(IStructuredDocumentRegion fn) { - boolean isDelimiter = false; - String type = fn.getType(); - if (type != null) { - isDelimiter = isJSPDelimiter(type); - } - return isDelimiter; - } - - /** - * ISSUE: this is a bit of hidden JSP knowledge that was implemented this - * way for expedency. Should be evolved in future to depend on - * "nestedContext". - */ - public static boolean isJSPDelimiter(String type) { - if (type == null) { - return false; - } - return (isJSPOpenDelimiter(type) || isJSPCloseDelimiter(type)); - } - - /** - * Tells you if the flatnode is <%, <%=, or <%! ISSUE: this is a bit of - * hidden JSP knowledge that was implemented this way for expedency. - * Should be evolved in future to depend on "nestedContext". - */ - public static boolean isJSPOpenDelimiter(IStructuredDocumentRegion fn) { - if (fn == null) { - return false; - } - return isJSPOpenDelimiter(fn.getType()); - } - - /** - * ISSUE: this is a bit of hidden JSP knowledge that was implemented this - * way for expedency. Should be evolved in future to depend on - * "nestedContext". - */ - public static boolean isJSPOpenDelimiter(String type) { - if (type == null) { - return false; - } - return (type.equals(DOMJSPRegionContextsPrivateCopy.JSP_SCRIPTLET_OPEN) || type.equals(DOMJSPRegionContextsPrivateCopy.JSP_DECLARATION_OPEN) || type.equals(DOMJSPRegionContextsPrivateCopy.JSP_EXPRESSION_OPEN)); - } - - /** - * Tells you if the flatnode is the <jsp:scriptlet>, <jsp:expression>, or - * <jsp:declaration>tag - * - * ISSUE: this is a bit of hidden JSP knowledge that was implemented this - * way for expedency. Should be evolved in future to depend on - * "nestedContext". - */ - public static boolean isXMLJSPDelimiter(IStructuredDocumentRegion fn) { - boolean isDelimiter = false; - if ((fn != null) && (fn instanceof ITextRegionContainer)) { - Object[] regions = ((ITextRegionContainer) fn).getRegions().toArray(); - ITextRegion temp = null; - String regionText = ""; //$NON-NLS-1$ - for (int i = 0; i < regions.length; i++) { - temp = (ITextRegion) regions[i]; - if (temp.getType() == DOMRegionContext.XML_TAG_NAME) { - regionText = fn.getText(temp); - if (regionText.equalsIgnoreCase("jsp:scriptlet") || regionText.equalsIgnoreCase("jsp:expression") || regionText.equalsIgnoreCase("jsp:declaration")) { - isDelimiter = true; - } - } - } - } - return isDelimiter; - } - - /** - * Returns "javascript" if language attribute is some form of javascript, - * "java" if language attribute is some form of java. Otherwise, just - * returns type. - * - * @param language - */ - public static String lookupScriptLanguage(String language) { - for (int i = 0; i < ScriptLanguageKeys.JAVASCRIPT_LANGUAGE_KEYS.length; i++) { - if (ScriptLanguageKeys.JAVASCRIPT_LANGUAGE_KEYS[i].equalsIgnoreCase(language)) { - return ScriptLanguageKeys.JAVASCRIPT; - } - } - for (int i = 0; i < ScriptLanguageKeys.JAVA_LANGUAGE_KEYS.length; i++) { - if (ScriptLanguageKeys.JAVA_LANGUAGE_KEYS[i].equalsIgnoreCase(language)) { - return ScriptLanguageKeys.JAVA; - } - } - return language; - } - - /** - * Returns "javascript" if type (used in <script type="xxx"> is actually - * javascript type. Otherwise, just returns type - * - * @param type - */ - public static String lookupScriptType(String type) { - for (int i = 0; i < ScriptLanguageKeys.JAVASCRIPT_MIME_TYPE_KEYS.length; i++) { - if (ScriptLanguageKeys.JAVASCRIPT_MIME_TYPE_KEYS[i].equalsIgnoreCase(type)) { - return ScriptLanguageKeys.JAVASCRIPT; - } - } - return type; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLContentModelGenerator.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLContentModelGenerator.java deleted file mode 100644 index 2896432813..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLContentModelGenerator.java +++ /dev/null @@ -1,154 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.contentassist; - - - -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.w3c.dom.Node; - - -public class XMLContentModelGenerator extends AbstractContentModelGenerator { - - /** - * ISSUE: this is a bit of hidden JSP knowledge that was implemented this - * way for expedency. Should be evolved in future to depend on - * "nestedContext". - */ - private class DOMJSPRegionContextsPrivateCopy { - private static final String JSP_DIRECTIVE_OPEN = "JSP_DIRECTIVE_OPEN"; //$NON-NLS-1$ - } - - /** - * XMLContentModelGenerator constructor comment. - */ - public XMLContentModelGenerator() { - super(); - } - - public void generateAttribute(CMAttributeDeclaration attrDecl, StringBuffer buffer) { - if ((attrDecl == null) || (buffer == null)) { - return; - } - int usage = attrDecl.getUsage(); - if (usage == CMAttributeDeclaration.REQUIRED) { - buffer.append(" "); //$NON-NLS-1$ - generateRequiredAttribute(null, attrDecl, buffer); // todo pass - // ownerNode as - // 1st param - } - return; - } - - protected void generateEndTag(String tagName, Node parentNode, CMElementDeclaration elementDecl, StringBuffer buffer) { - if (elementDecl == null) { - return; - } - if (elementDecl.getContentType() != CMElementDeclaration.EMPTY) { - buffer.append("</" + tagName + ">");//$NON-NLS-2$//$NON-NLS-1$ - } - return; - } - - public void generateRequiredAttribute(Node ownerNode, CMAttributeDeclaration attrDecl, StringBuffer buffer) { - if ((attrDecl == null) || (buffer == null)) { - return; - } - - // attribute name - String attributeName = getRequiredName(ownerNode, attrDecl); - CMDataType attrType = attrDecl.getAttrType(); - String defaultValue = null; - // = sign - buffer.append(attributeName + "="); //$NON-NLS-1$ - // attribute value - if (attrType != null) { - // insert any value that is implied - if ((attrType.getImpliedValueKind() != CMDataType.IMPLIED_VALUE_NONE) && (attrType.getImpliedValue() != null)) { - defaultValue = attrType.getImpliedValue(); - } - // otherwise, if an enumerated list of values exists, use the - // first value - else if ((attrType.getEnumeratedValues() != null) && (attrType.getEnumeratedValues().length > 0)) { - defaultValue = attrType.getEnumeratedValues()[0]; - } - } - - char attrQuote = '\"'; - // Found a double quote, wrap the attribute in single quotes - if(defaultValue != null && defaultValue.indexOf(attrQuote) >= 0) { - attrQuote = '\''; - } - - buffer.append(attrQuote); - buffer.append(((defaultValue != null) ? defaultValue : "")); //$NON-NLS-1$ - buffer.append(attrQuote); - return; - } - - protected void generateStartTag(String tagName, Node parentNode, CMElementDeclaration elementDecl, StringBuffer buffer) { - if ((elementDecl == null) || (buffer == null)) { - return; - } - buffer.append("<" + tagName);//$NON-NLS-1$ - generateAttributes(elementDecl, buffer); - buffer.append(getStartTagClose(parentNode, elementDecl)); - return; - } - - public int getMinimalStartTagLength(Node node, CMElementDeclaration elementDecl) { - if (elementDecl == null) { - return 0; - } - if (requiresAttributes(elementDecl)) { - return getRequiredName(node, elementDecl).length() + 2; // < + - // name + - // space - } - else { - return 1 + getRequiredName(node, elementDecl).length() + getStartTagClose(node, elementDecl).length(); // < + - // name - // + - // appropriate - // close - } - } - - protected String getOtherClose(Node notATagNode) { - if (notATagNode instanceof IDOMNode) { - IStructuredDocumentRegion node = ((IDOMNode) notATagNode).getStartStructuredDocumentRegion(); - if ((node != null) && (node.getNumberOfRegions() > 1) && node.getRegions().get(0).getType().equals(DOMJSPRegionContextsPrivateCopy.JSP_DIRECTIVE_OPEN)) { - return "%>"; //$NON-NLS-1$ - } - } - return null; - } - - public String getStartTagClose(Node parentNode, CMElementDeclaration elementDecl) { - String other = getOtherClose(parentNode); - if (other != null) { - return other; - } - if (elementDecl == null) { - return ">";//$NON-NLS-1$ - } - if (elementDecl.getContentType() == CMElementDeclaration.EMPTY) { - return "/>"; //$NON-NLS-1$ - } - return ">"; //$NON-NLS-1$ - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLRelevanceConstants.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLRelevanceConstants.java deleted file mode 100644 index 4a99070ae6..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLRelevanceConstants.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.contentassist; - -import org.eclipse.wst.sse.ui.internal.contentassist.IRelevanceConstants; - - - -/** - * some relevance constants for content assist higher relevance means it shows - * up higher on the list - */ -public interface XMLRelevanceConstants extends IRelevanceConstants { - - int R_CDATA = 400; - int R_CLOSE_TAG = 1500; - - int R_COMMENT = 100; - - // moved this above macros - int R_DOCTYPE = 600; - int R_END_TAG = 1400; - int R_END_TAG_NAME = 1100; - int R_ENTITY = 1000; - int R_JSP = 500; - - int R_JSP_ATTRIBUTE_VALUE = 700; - - // (pa) make these the same relevance so proposals are same order for V501 - int R_MACRO = 500; - - // add this onto "required" attrs, elements, etc to bubble them up on - // sorting... - // CMVC 246618 - int R_REQUIRED = 10; - int R_TAG_INSERTION = 500; - int R_STRICTLY_VALID_TAG_INSERTION = 600; - int R_TAG_NAME = 1200; - int R_XML_ATTRIBUTE_NAME = 900; - int R_XML_ATTRIBUTE_VALUE = 800; - int R_XML_DECLARATION = 1300; -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLTemplateCompletionProcessor.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLTemplateCompletionProcessor.java deleted file mode 100644 index 29f9ad2f46..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLTemplateCompletionProcessor.java +++ /dev/null @@ -1,172 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.contentassist; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.Region; -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.jface.text.templates.ContextTypeRegistry; -import org.eclipse.jface.text.templates.Template; -import org.eclipse.jface.text.templates.TemplateCompletionProcessor; -import org.eclipse.jface.text.templates.TemplateContext; -import org.eclipse.jface.text.templates.TemplateContextType; -import org.eclipse.jface.text.templates.TemplateException; -import org.eclipse.jface.text.templates.TemplateProposal; -import org.eclipse.jface.text.templates.persistence.TemplateStore; -import org.eclipse.swt.graphics.Image; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages; - - -/** - * Completion processor for XML Templates. Most of the work is already done by - * the XML Content Assist processor, so by the time the - * XMLTemplateCompletionProcessor is asked for content assist proposals, the - * XML content assist processor has already set the context type for - * templates. - */ -class XMLTemplateCompletionProcessor extends TemplateCompletionProcessor { - private static final class ProposalComparator implements Comparator { - public int compare(Object o1, Object o2) { - return ((TemplateProposal) o2).getRelevance() - ((TemplateProposal) o1).getRelevance(); - } - } - - private static final Comparator fgProposalComparator = new ProposalComparator(); - private String fContextTypeId = null; - - /* - * Copied from super class except instead of calling createContext(viewer, - * region) call createContext(viewer, region, offset) instead - */ - public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) { - - ITextSelection selection = (ITextSelection) viewer.getSelectionProvider().getSelection(); - - // adjust offset to end of normalized selection - if (selection.getOffset() == offset) { - offset = selection.getOffset() + selection.getLength(); - } - - String prefix = extractPrefix(viewer, offset); - Region region = new Region(offset - prefix.length(), prefix.length()); - TemplateContext context = createContext(viewer, region, offset); - if (context == null) { - return new ICompletionProposal[0]; - } - - // name of the selection variables {line, word}_selection - context.setVariable("selection", selection.getText()); //$NON-NLS-1$ - - Template[] templates = getTemplates(context.getContextType().getId()); - - List matches = new ArrayList(); - for (int i = 0; i < templates.length; i++) { - Template template = templates[i]; - try { - context.getContextType().validate(template.getPattern()); - } - catch (TemplateException e) { - continue; - } - if (template.matches(prefix, context.getContextType().getId())) { - matches.add(createProposal(template, context, (IRegion) region, getRelevance(template, prefix))); - } - } - - Collections.sort(matches, fgProposalComparator); - - return (ICompletionProposal[]) matches.toArray(new ICompletionProposal[matches.size()]); - } - - /** - * Creates a concrete template context for the given region in the - * document. This involves finding out which context type is valid at the - * given location, and then creating a context of this type. The default - * implementation returns a <code>SmartReplaceTemplateContext</code> for - * the context type at the given location. This takes the offset at which - * content assist was invoked into consideration. - * - * @param viewer - * the viewer for which the context is created - * @param region - * the region into <code>document</code> for which the - * context is created - * @param offset - * the original offset where content assist was invoked - * @return a template context that can handle template insertion at the - * given location, or <code>null</code> - */ - private TemplateContext createContext(ITextViewer viewer, IRegion region, int offset) { - // pretty much same code as super.createContext except create - // SmartReplaceTemplateContext - TemplateContextType contextType = getContextType(viewer, region); - if (contextType != null) { - IDocument document = viewer.getDocument(); - return new ReplaceNameTemplateContext(contextType, document, region.getOffset(), region.getLength(), offset); - } - return null; - } - - protected ICompletionProposal createProposal(Template template, TemplateContext context, IRegion region, int relevance) { - return new CustomTemplateProposal(template, context, region, getImage(template), relevance); - } - - protected TemplateContextType getContextType(ITextViewer viewer, IRegion region) { - TemplateContextType type = null; - - ContextTypeRegistry registry = getTemplateContextRegistry(); - if (registry != null) { - type = registry.getContextType(fContextTypeId); - } - - return type; - } - - protected Image getImage(Template template) { - // just return the same image for now - return XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_MACRO); - } - - private ContextTypeRegistry getTemplateContextRegistry() { - return XMLUIPlugin.getDefault().getTemplateContextRegistry(); - } - - protected Template[] getTemplates(String contextTypeId) { - Template templates[] = null; - - TemplateStore store = getTemplateStore(); - if (store != null) { - templates = store.getTemplates(contextTypeId); - } - - return templates; - } - - private TemplateStore getTemplateStore() { - return XMLUIPlugin.getDefault().getTemplateStore(); - } - - void setContextType(String contextTypeId) { - fContextTypeId = contextTypeId; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/JFaceNodeAdapter.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/JFaceNodeAdapter.java deleted file mode 100644 index 321c4477a1..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/JFaceNodeAdapter.java +++ /dev/null @@ -1,261 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.contentoutline; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; - -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.resource.ImageRegistry; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.jface.viewers.StructuredViewer; -import org.eclipse.swt.graphics.Image; -import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; -import org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapter; -import org.eclipse.wst.xml.ui.internal.editor.CMImageUtil; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages; -import org.w3c.dom.Node; - -/** - * Adapts a DOM node to a JFace viewer. - */ -public class JFaceNodeAdapter implements IJFaceNodeAdapter { - - final static Class ADAPTER_KEY = IJFaceNodeAdapter.class; - - /** - * debug .option - */ - private static final boolean DEBUG = getDebugValue(); - - private static boolean getDebugValue() { - String value = Platform.getDebugOption("org.eclipse.wst.sse.ui/debug/outline"); //$NON-NLS-1$ - boolean result = (value != null) && value.equalsIgnoreCase("true"); //$NON-NLS-1$ - return result; - } - - JFaceNodeAdapterFactory fAdapterFactory; - private RefreshStructureJob fRefreshJob = null; - - public JFaceNodeAdapter(JFaceNodeAdapterFactory adapterFactory) { - super(); - this.fAdapterFactory = adapterFactory; - } - - protected Image createImage(Object object) { - Image image = null; - Node node = (Node) object; - switch (node.getNodeType()) { - case Node.ELEMENT_NODE : { - image = createXMLImageDescriptor(XMLEditorPluginImages.IMG_OBJ_ELEMENT); - break; - } - case Node.ATTRIBUTE_NODE : { - image = createXMLImageDescriptor(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE); - break; - } - case Node.TEXT_NODE : { // actually, TEXT should never be seen in - // the tree - image = createXMLImageDescriptor(XMLEditorPluginImages.IMG_OBJ_TXTEXT); - break; - } - case Node.CDATA_SECTION_NODE : { - image = createXMLImageDescriptor(XMLEditorPluginImages.IMG_OBJ_CDATASECTION); - break; - } - case Node.ENTITY_REFERENCE_NODE : - case Node.ENTITY_NODE : { - image = createXMLImageDescriptor(XMLEditorPluginImages.IMG_OBJ_ENTITY); - break; - } - case Node.PROCESSING_INSTRUCTION_NODE : { - image = createXMLImageDescriptor(XMLEditorPluginImages.IMG_OBJ_PROCESSINGINSTRUCTION); - break; - } - case Node.COMMENT_NODE : { - image = createXMLImageDescriptor(XMLEditorPluginImages.IMG_OBJ_COMMENT); - break; - } - case Node.DOCUMENT_TYPE_NODE : { - image = createXMLImageDescriptor(XMLEditorPluginImages.IMG_OBJ_DOCTYPE); - break; - } - case Node.NOTATION_NODE : { - image = createXMLImageDescriptor(XMLEditorPluginImages.IMG_OBJ_NOTATION); - break; - } - default : { - image = createXMLImageDescriptor(XMLEditorPluginImages.IMG_OBJ_ELEMENT); - break; - } - } - return image; - } - - protected Image createXMLImageDescriptor(String imageResourceName) { - return XMLEditorPluginImageHelper.getInstance().getImage(imageResourceName); - } - - public Object[] getChildren(Object object) { - - // (pa) 20021217 - // cmvc defect 235554 - // performance enhancement: using child.getNextSibling() rather than - // nodeList(item) for O(n) vs. O(n*n) - // - ArrayList v = new ArrayList(); - if (object instanceof Node) { - Node node = (Node) object; - for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { - Node n = child; - if (n.getNodeType() != Node.TEXT_NODE) { - v.add(n); - } - } - } - return v.toArray(); - } - - /** - * Returns an enumeration with the elements belonging to the passed - * element. These are the top level items in a list, tree, table, etc... - */ - public Object[] getElements(Object node) { - return getChildren(node); - } - - /** - * Fetches the label image specific to this object instance. - */ - public Image getLabelImage(Object node) { - Image image = null; - if (node instanceof Node) { - image = CMImageUtil.getImage(CMImageUtil.getDeclaration((Node) node)); - if ((image == null) && (JFaceResources.getImageRegistry() != null)) { - ImageRegistry imageRegistry = JFaceResources.getImageRegistry(); - String nodeName = getNodeName(node); - image = imageRegistry.get(nodeName); - if (image == null) { - image = createImage(node); - if (image != null) { - imageRegistry.put(nodeName, image); - } - } - } - } - return image; - } - - /** - * Fetches the label text specific to this object instance. - */ - public String getLabelText(Object node) { - return getNodeName(node); - } - - private String getNodeName(Object object) { - StringBuffer nodeName = new StringBuffer(); - if (object instanceof Node) { - Node node = (Node) object; - nodeName.append(node.getNodeName()); - - if (node.getNodeType() == Node.DOCUMENT_TYPE_NODE) { - nodeName.insert(0, "DOCTYPE:"); //$NON-NLS-1$ - } - - } - return nodeName.toString(); - } - - - public Object getParent(Object object) { - if (object instanceof Node) { - Node node = (Node) object; - return node.getParentNode(); - } - return null; - } - - private synchronized RefreshStructureJob getRefreshJob() { - if (fRefreshJob == null) { - fRefreshJob = new RefreshStructureJob(); - } - return fRefreshJob; - } - - - public boolean hasChildren(Object object) { - // (pa) 20021217 - // cmvc defect 235554 > use child.getNextSibling() instead of - // nodeList(item) for O(n) vs. O(n*n) - Node node = (Node) object; - for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { - if (child.getNodeType() != Node.TEXT_NODE) { - return true; - } - } - return false; - } - - /** - * Allowing the INodeAdapter to compare itself against the type allows it - * to return true in more than one case. - */ - public boolean isAdapterForType(Object type) { - if (type == null) { - return false; - } - return type.equals(ADAPTER_KEY); - } - - /** - * Called by the object being adapter (the notifier) when something has - * changed. - */ - public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) { - // future_TODO: the 'uijobs' used in this method were added to solve - // threading problems when the dom - // is updated in the background while the editor is open. They may be - // a bit overkill and not that useful. - // (That is, may be be worthy of job manager management). If they are - // found to be important enough to leave in, - // there's probably some optimization that can be done. - if (notifier instanceof Node) { - Collection listeners = fAdapterFactory.getListeners(); - Iterator iterator = listeners.iterator(); - - while (iterator.hasNext()) { - Object listener = iterator.next(); - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=90637 - // if (notifier instanceof Node && (listener instanceof - // StructuredViewer) && (eventType == - // INodeNotifier.STRUCTURE_CHANGED || (eventType == - // INodeNotifier.CHANGE && changedFeature == null))) { - if ((listener instanceof StructuredViewer) && ((eventType == INodeNotifier.STRUCTURE_CHANGED) || (eventType == INodeNotifier.CONTENT_CHANGED) || (eventType == INodeNotifier.CHANGE))) { - if (DEBUG) { - System.out.println("JFaceNodeAdapter notified on event type > " + eventType); //$NON-NLS-1$ - } - - // refresh on structural and "unknown" changes - StructuredViewer structuredViewer = (StructuredViewer) listener; - // https://w3.opensource.ibm.com/bugzilla/show_bug.cgi?id=5230 - if (structuredViewer.getControl() != null) { - getRefreshJob().refresh(structuredViewer, (Node) notifier); - } - } - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/JFaceNodeAdapterFactory.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/JFaceNodeAdapterFactory.java deleted file mode 100644 index 7977ca5e87..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/JFaceNodeAdapterFactory.java +++ /dev/null @@ -1,173 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.contentoutline; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.jface.viewers.StructuredViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.widgets.Control; -import org.eclipse.ui.progress.UIJob; -import org.eclipse.wst.sse.core.internal.provisional.AbstractAdapterFactory; -import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter; -import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory; -import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; -import org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapter; -import org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapterFactory; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManagerListener; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.contentmodel.util.CMDocumentCache; -import org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; - - -/** - * An adapter factory to create JFaceNodeAdapters. Use this adapter factory - * with a JFaceAdapterContentProvider to display DOM nodes in a tree. - */ -public class JFaceNodeAdapterFactory extends AbstractAdapterFactory implements IJFaceNodeAdapterFactory { - public class CMDocumentManagerListenerImpl implements CMDocumentManagerListener { - private static final int UPDATE_DELAY = 200; - - public void cacheCleared(CMDocumentCache cache) { - // nothing to do - } - - public void cacheUpdated(CMDocumentCache cache, final String uri, int oldStatus, int newStatus, CMDocument cmDocument) { - if ((newStatus == CMDocumentCache.STATUS_LOADED) || (newStatus == CMDocumentCache.STATUS_ERROR)) { - refreshViewers(); - } - } - - public void propertyChanged(CMDocumentManager cmDocumentManager, String propertyName) { - if (cmDocumentManager.getPropertyEnabled(CMDocumentManager.PROPERTY_AUTO_LOAD)) { - refreshViewers(); - } - } - - private void refreshViewers() { - Object[] listeners = getListeners().toArray(); - for (int i = 0; i < listeners.length; i++) { - if (listeners[i] instanceof StructuredViewer) { - final StructuredViewer viewer = (StructuredViewer) listeners[i]; - Job refresh = new UIJob(XMLUIMessages.refreshoutline_0) { - public IStatus runInUIThread(IProgressMonitor monitor) { - Control refreshControl = viewer.getControl(); - if ((refreshControl != null) && !refreshControl.isDisposed()) { - viewer.refresh(true); - } - return Status.OK_STATUS; - } - }; - refresh.setSystem(true); - refresh.setPriority(Job.SHORT); - refresh.schedule(UPDATE_DELAY); - } - else if (listeners[i] instanceof Viewer) { - final Viewer viewer = (Viewer) listeners[i]; - Job refresh = new UIJob(XMLUIMessages.refreshoutline_0) { - public IStatus runInUIThread(IProgressMonitor monitor) { - Control refreshControl = viewer.getControl(); - if ((refreshControl != null) && !refreshControl.isDisposed()) { - viewer.refresh(); - } - return Status.OK_STATUS; - } - }; - refresh.setSystem(true); - refresh.setPriority(Job.SHORT); - refresh.schedule(UPDATE_DELAY); - } - } - } - } - - private CMDocumentManager cmDocumentManager; - private CMDocumentManagerListenerImpl fCMDocumentManagerListener = null; - /** - * This keeps track of all the listeners. - */ - private Set fListeners = new HashSet(); - - protected INodeAdapter singletonAdapter; - - public JFaceNodeAdapterFactory() { - this(IJFaceNodeAdapter.class, true); - } - - public JFaceNodeAdapterFactory(Object adapterKey, boolean registerAdapters) { - super(adapterKey, registerAdapters); - } - - public synchronized void addListener(Object listener) { - fListeners.add(listener); - } - - public INodeAdapterFactory copy() { - return new JFaceNodeAdapterFactory(getAdapterKey(), isShouldRegisterAdapter()); - } - - /** - * Create a new JFace adapter for the DOM node passed in - */ - protected INodeAdapter createAdapter(INodeNotifier node) { - if (singletonAdapter == null) { - // create the JFaceNodeAdapter - singletonAdapter = new JFaceNodeAdapter(this); - initAdapter(singletonAdapter, node); - } - return singletonAdapter; - } - - - /** - * returns "copy" so no one can modify our list. It is a shallow copy. - */ - public synchronized Collection getListeners() { - return new ArrayList(fListeners); - } - - protected void initAdapter(INodeAdapter adapter, INodeNotifier node) { - // register for CMDocumentManager events - ModelQueryAdapter mqadapter = (ModelQueryAdapter) node.getAdapterFor(ModelQueryAdapter.class); - if (mqadapter != null) { - ModelQuery mquery = mqadapter.getModelQuery(); - if ((mquery != null) && (mquery.getCMDocumentManager() != null)) { - cmDocumentManager = mquery.getCMDocumentManager(); - fCMDocumentManagerListener = new CMDocumentManagerListenerImpl(); - cmDocumentManager.addListener(fCMDocumentManagerListener); - } - } - } - - public void release() { - // deregister from CMDocumentManager events - if ((cmDocumentManager != null) && (fCMDocumentManagerListener != null)) { - cmDocumentManager.removeListener(fCMDocumentManagerListener); - } - fListeners.clear(); - } - - public synchronized void removeListener(Object listener) { - fListeners.remove(listener); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/JFaceNodeContentProvider.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/JFaceNodeContentProvider.java deleted file mode 100644 index f3c5452f80..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/JFaceNodeContentProvider.java +++ /dev/null @@ -1,120 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.contentoutline; - -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter; -import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapter; -import org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapterFactory; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; - - -/** - * An ITreeContentProvider for a TreeViewers used to display DOM nodes. This - * content provider takes an adapter factory to create JFace adapters for the - * nodes in the tree. - */ -public class JFaceNodeContentProvider implements ITreeContentProvider { - - public JFaceNodeContentProvider() { - super(); - } - - /** - * The visual part that is using this content provider is about to be - * disposed. Deallocate all allocated SWT resources. - */ - public void dispose() { - } - - /** - * Returns the JFace adapter for the specified object. - * - * @param adaptable - * java.lang.Object The object to get the adapter for - */ - protected IJFaceNodeAdapter getAdapter(Object adaptable) { - if (adaptable instanceof INodeNotifier) { - INodeAdapter adapter = ((INodeNotifier) adaptable).getAdapterFor(IJFaceNodeAdapter.class); - if (adapter instanceof IJFaceNodeAdapter) { - return (IJFaceNodeAdapter) adapter; - } - } - return null; - } - - public Object[] getChildren(Object object) { - IJFaceNodeAdapter adapter = getAdapter(object); - - if (adapter != null) { - return adapter.getChildren(object); - } - - return new Object[0]; - } - - public Object[] getElements(Object object) { - // The root is usually an instance of an XMLStructuredModel in - // which case we want to extract the document. - Object topNode = object; - if (object instanceof IDOMModel) { - topNode = ((IDOMModel) object).getDocument(); - } - - IJFaceNodeAdapter adapter = getAdapter(topNode); - - if (adapter != null) { - return adapter.getElements(topNode); - } - - return new Object[0]; - } - - public Object getParent(Object object) { - IJFaceNodeAdapter adapter = getAdapter(object); - - if (adapter != null) { - return adapter.getParent(object); - } - - return null; - } - - public boolean hasChildren(Object object) { - IJFaceNodeAdapter adapter = getAdapter(object); - - if (adapter != null) { - return adapter.hasChildren(object); - } - - return false; - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - if ((oldInput != null) && (oldInput instanceof IStructuredModel)) { - IJFaceNodeAdapterFactory factory = (IJFaceNodeAdapterFactory) ((IStructuredModel) oldInput).getFactoryRegistry().getFactoryFor(IJFaceNodeAdapter.class); - if (factory != null) { - factory.removeListener(viewer); - } - } - if ((newInput != null) && (newInput instanceof IStructuredModel)) { - IJFaceNodeAdapterFactory factory = (IJFaceNodeAdapterFactory) ((IStructuredModel) newInput).getFactoryRegistry().getFactoryFor(IJFaceNodeAdapter.class); - if (factory != null) { - factory.addListener(viewer); - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/JFaceNodeLabelProvider.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/JFaceNodeLabelProvider.java deleted file mode 100644 index 6168ddebcf..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/JFaceNodeLabelProvider.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.contentoutline; - -import org.eclipse.jface.viewers.ColumnLabelProvider; -import org.eclipse.swt.graphics.Image; -import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter; -import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; -import org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapter; - -/** - * A (column) label provider backed by JFaceNodeAdapters. - */ -public class JFaceNodeLabelProvider extends ColumnLabelProvider { - /** - * JFaceNodeLabelProvider constructor comment. - */ - public JFaceNodeLabelProvider() { - super(); - } - - /** - * Returns the JFace adapter for the specified object. - * - * @param adaptable - * java.lang.Object The object to get the adapter for - */ - protected IJFaceNodeAdapter getAdapter(Object adaptable) { - if (adaptable instanceof INodeNotifier) { - INodeAdapter adapter = ((INodeNotifier) adaptable).getAdapterFor(IJFaceNodeAdapter.class); - if (adapter instanceof IJFaceNodeAdapter) { - return (IJFaceNodeAdapter) adapter; - } - } - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object) - */ - public Image getImage(Object element) { - IJFaceNodeAdapter adapter = getAdapter(element); - if (adapter != null) - return adapter.getLabelImage(element); - return super.getImage(element); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object) - */ - public String getText(Object element) { - IJFaceNodeAdapter adapter = getAdapter(element); - if (adapter != null) - return adapter.getLabelText(element); - return super.getText(element); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, - * java.lang.String) - */ - public boolean isLabelProperty(Object element, String property) { - return false; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/RefreshStructureJob.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/RefreshStructureJob.java deleted file mode 100644 index a58c09ba26..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/RefreshStructureJob.java +++ /dev/null @@ -1,359 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.contentoutline; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.jface.viewers.StructuredViewer; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.w3c.dom.Document; -import org.w3c.dom.Node; - -/** - * This job holds a queue of updates (affected nodes) for multiple structured - * viewers. When a new request comes in, the current run is cancelled, the new - * request is added to the queue, then the job is re-scheduled. Support for - * multiple structured viewers is required because refresh updates are usually - * triggered by model changes, and the model may be visible in more than one - * viewer. - * - * @author pavery - */ -class RefreshStructureJob extends Job { - - /** debug flag */ - static final boolean DEBUG; - private static final long UPDATE_DELAY = 300; - static { - String value = Platform.getDebugOption("org.eclipse.wst.sse.ui/debug/refreshStructure"); //$NON-NLS-1$ - DEBUG = (value != null) && value.equalsIgnoreCase("true"); //$NON-NLS-1$ - } - /** List of refresh requests (Nodes) */ - private final List fRefreshes; - /** List of update requests (Nodes) */ - private final List fUpdates; - /** List of update requests (Nodes) */ - private final List fUpdateProperties; - /** the structured viewers */ - Set fRefreshViewers = new HashSet(3); - Set fUpdateViewers = new HashSet(3); - - public RefreshStructureJob() { - super(XMLUIMessages.refreshoutline_0); - setPriority(Job.LONG); - setSystem(true); - fRefreshes = new ArrayList(5); - fUpdates = new ArrayList(5); - fUpdateProperties = new ArrayList(5); - } - - private synchronized void addUpdateRequest(Node newNodeRequest, String[] updateProperties) { - /* - * If we get to here, either from existing request list being zero - * length, or no exisitng requests "matched" new request, then add the - * new request. - */ - fUpdates.add(newNodeRequest); - fUpdateProperties.add(updateProperties); - } - - private synchronized void addUpdateViewer(StructuredViewer viewer) { - fUpdateViewers.add(viewer); - } - - private synchronized void addRefreshRequest(Node newNodeRequest) { - /* - * note: the caller must NOT pass in null node request (which, since - * private method, we do not need to gaurd against here, as long as we - * gaurd against it in calling method. - */ - int size = fRefreshes.size(); - for (int i = 0; i < size; i++) { - Node existingNodeRequest = (Node) fRefreshes.get(i); - /* - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=157427 If we - * already have a request which equals the new request, discard - * the new request - */ - if (existingNodeRequest.equals(newNodeRequest)) { - return; - } - /* - * If we already have a request which contains the new request, - * discard the new request - */ - if (contains(existingNodeRequest, newNodeRequest)) { - return; - } - /* - * If new request contains any existing requests, replace it with - * new request. ISSUE: technically, we should replace ALL - * contained, existing requests (such as if many siblings already - * que'd up when their common parent is then requested, but, I'm - * not sure if that occurs much, in practice, or if there's an - * algorithm to quickly find them all. Actually, I guess we could - * just go through the _rest_ of the list (i+1 to size) and remove - * any that are contained by new request ... in future :) . - */ - if (contains(newNodeRequest, existingNodeRequest)) { - fRefreshes.set(i, newNodeRequest); - return; - } - } - /* - * If we get to here, either from existing request list being zero - * length, or no exisitng requests "matched" new request, then add the - * new request. - */ - fRefreshes.add(newNodeRequest); - } - - private synchronized void addRefreshViewer(StructuredViewer viewer) { - fRefreshViewers.add(viewer); - } - - /** - * Simple hierarchical containment relationship. Note, this method returns - * "false" if the two nodes are equal! - * - * @param root - * @param possible - * @return if the root is parent of possible, return true, otherwise - * return false - */ - private boolean contains(Node root, Node possible) { - if (DEBUG) { - System.out.println("=============================================================================================================="); //$NON-NLS-1$ - System.out.println("recursive call w/ root: " + root.getNodeName() + " and possible: " + possible); //$NON-NLS-1$ //$NON-NLS-2$ - System.out.println("--------------------------------------------------------------------------------------------------------------"); //$NON-NLS-1$ - } - - // the following checks are important - // #document node will break the algorithm otherwise - - // can't contain the child if it's null - if (root == null) { - if (DEBUG) { - System.out.println("returning false: root is null"); //$NON-NLS-1$ - } - return false; - } - // nothing can be parent of Document node - if (possible instanceof Document) { - if (DEBUG) { - System.out.println("returning false: possible is Document node"); //$NON-NLS-1$ - } - return false; - } - // document contains everything - if (root instanceof Document) { - if (DEBUG) { - System.out.println("returning true: root is Document node"); //$NON-NLS-1$ - } - return true; - } - - // check parentage - Node current = possible; - // loop parents - while ((current != null) && (current.getNodeType() != Node.DOCUMENT_NODE)) { - // found it - if (root.equals(current)) { - if (DEBUG) { - System.out.println(" !!! found: " + possible.getNodeName() + " in subelement of: " + root.getNodeName()); //$NON-NLS-1$ //$NON-NLS-2$ - } - return true; - } - current = current.getParentNode(); - } - // never found it - return false; - } - - /** - * Refresh must be on UI thread because it's on a SWT widget. - * - * @param node - */ - private void doRefresh(final Node node, final StructuredViewer[] viewers) { - final Display display = PlatformUI.getWorkbench().getDisplay(); - display.asyncExec(new Runnable() { - public void run() { - if (DEBUG) { - System.out.println("refresh on: [" + node.getNodeName() + "]"); //$NON-NLS-1$ //$NON-NLS-2$ - } - - for (int i = 0; i < viewers.length; i++) { - if (!viewers[i].getControl().isDisposed()) { - if (node.getNodeType() == Node.DOCUMENT_NODE) { - viewers[i].refresh(true); - } - else { - viewers[i].refresh(node, true); - } - } - else { - if (DEBUG) { - System.out.println(" !!! skipped refreshing disposed viewer: " + viewers[i]); //$NON-NLS-1$ - } - } - } - } - }); - } - - /** - * Update must be on UI thread because it's on a SWT widget. - * - * @param node - */ - private void doUpdate(final StructuredViewer[] viewers, final Node node, final String[] properties) { - final Display display = PlatformUI.getWorkbench().getDisplay(); - display.asyncExec(new Runnable() { - public void run() { - if (DEBUG) { - System.out.println("refresh on: [" + node.getNodeName() + "]"); //$NON-NLS-1$ //$NON-NLS-2$ - } - - for (int i = 0; i < viewers.length; i++) { - if (!viewers[i].getControl().isDisposed()) { - viewers[i].update(node, properties); - } - else { - if (DEBUG) { - System.out.println(" !!! skipped refreshing disposed viewer: " + viewers[i]); //$NON-NLS-1$ - } - } - } - } - }); - } - - /** - * This method also synchronized because it accesses the fRefreshes queue - * and fRefreshViewers list - * - * @return an array containing and array of the currently requested Nodes - * to refresh and the viewers in which to refresh them - */ - private synchronized Object[] getRefreshRequests() { - Node[] toRefresh = (Node[]) fRefreshes.toArray(new Node[fRefreshes.size()]); - fRefreshes.clear(); - - StructuredViewer[] viewers = (StructuredViewer[]) fRefreshViewers.toArray(new StructuredViewer[fRefreshViewers.size()]); - fRefreshViewers.clear(); - - return new Object[]{toRefresh, viewers}; - } - - /** - * This method also synchronized because it accesses the fUpdates queue - * and fUpdateViewers list - * - * @return an array containing and array of the currently requested Nodes - * to refresh and the viewers in which to refresh them - */ - private synchronized Object[] getUpdateRequests() { - Node[] toUpdate = (Node[]) fUpdates.toArray(new Node[fUpdates.size()]); - fUpdates.clear(); - - StructuredViewer[] viewers = (StructuredViewer[]) fUpdateViewers.toArray(new StructuredViewer[fUpdateViewers.size()]); - fUpdateViewers.clear(); - - String[][] properties = (String[][]) fUpdateProperties.toArray(new String[fUpdateProperties.size()][]); - fUpdateProperties.clear(); - - return new Object[]{toUpdate, viewers, properties}; - } - - /** - * Invoke a refresh on the viewer on the given node. - * - * @param node - */ - public void refresh(StructuredViewer viewer, Node node) { - if (node == null) { - return; - } - - addRefreshViewer(viewer); - addRefreshRequest(node); - schedule(UPDATE_DELAY); - } - - /** - * Invoke a refresh on the viewer on the given node. - * - * @param node - */ - public void update(StructuredViewer viewer, Node node, String[] properties) { - if (node == null) { - return; - } - - addUpdateViewer(viewer); - addUpdateRequest(node, properties); - schedule(UPDATE_DELAY); - } - - protected IStatus run(IProgressMonitor monitor) { - IStatus status = Status.OK_STATUS; - try { - performUpdates(); - - performRefreshes(monitor); - } - finally { - monitor.done(); - } - return status; - } - - private void performRefreshes(IProgressMonitor monitor) { - // Retrieve BOTH viewers and Nodes on one block - Object[] requests = getRefreshRequests(); - Node[] nodes = (Node[]) requests[0]; - StructuredViewer[] viewers = (StructuredViewer[]) requests[1]; - - for (int i = 0; i < nodes.length; i++) { - if (monitor.isCanceled()) { - throw new OperationCanceledException(); - } - doRefresh(nodes[i], viewers); - } - } - - private void performUpdates() { - // Retrieve BOTH viewers and Nodes on one block - Object[] requests = getUpdateRequests(); - Node[] nodes = (Node[]) requests[0]; - StructuredViewer[] viewers = (StructuredViewer[]) requests[1]; - String[][] properties = (String[][]) requests[2]; - - for (int i = 0; i < nodes.length; i++) { - doUpdate(viewers, nodes[i], properties[i]); - } - } - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/XMLNodeActionManager.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/XMLNodeActionManager.java deleted file mode 100644 index f858071966..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/XMLNodeActionManager.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.contentoutline; - -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML; -import org.eclipse.wst.xml.ui.internal.actions.AbstractNodeActionManager; -import org.w3c.dom.Node; - - -public class XMLNodeActionManager extends AbstractNodeActionManager { - public XMLNodeActionManager(IStructuredModel model, Viewer viewer) { - super(model, ModelQueryUtil.getModelQuery(model), viewer); - } - - public void reformat(Node newElement, boolean deep) { - try { - // tell the model that we are about to make a big model change - fModel.aboutToChangeModel(); - - // format selected node - IStructuredFormatProcessor formatProcessor = new FormatProcessorXML(); - formatProcessor.formatNode(newElement); - } - finally { - // tell the model that we are done with the big model change - fModel.changedModel(); - } - } - - public void setModel(IStructuredModel newModel) { - fModel = newModel; - setModelQuery(ModelQueryUtil.getModelQuery(newModel)); - } - - protected void setModelQuery(ModelQuery newModelQuery) { - modelQuery = newModelQuery; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/CorrectionAssistantProviderXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/CorrectionAssistantProviderXML.java deleted file mode 100644 index 2c11048950..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/CorrectionAssistantProviderXML.java +++ /dev/null @@ -1,51 +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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.correction; - -import org.eclipse.jface.text.contentassist.ContentAssistant; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.text.contentassist.IContentAssistant; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.wst.sse.ui.internal.correction.CorrectionAssistantProvider; -import org.eclipse.wst.xml.core.text.IXMLPartitions; - -/** - * Correction assistant for XML - * - * @deprecated since 2.0 RC0 Use - * org.eclipse.jface.text.quickassist.IQuickAssistProcessor; - */ -public class CorrectionAssistantProviderXML extends CorrectionAssistantProvider { - - public IContentAssistant getCorrectionAssistant(ISourceViewer sourceViewer) { - IContentAssistant ca = null; - - if (sourceViewer != null) { - ContentAssistant assistant = new ContentAssistant(); - - if (sourceViewer != null) { - IContentAssistProcessor correctionProcessor = new CorrectionProcessorXML(sourceViewer); - assistant.setContentAssistProcessor(correctionProcessor, IXMLPartitions.XML_DEFAULT); - assistant.setContentAssistProcessor(correctionProcessor, IXMLPartitions.XML_CDATA); - assistant.setContentAssistProcessor(correctionProcessor, IXMLPartitions.XML_COMMENT); - assistant.setContentAssistProcessor(correctionProcessor, IXMLPartitions.XML_DECLARATION); - assistant.setContentAssistProcessor(correctionProcessor, IXMLPartitions.XML_PI); - assistant.setContentAssistProcessor(correctionProcessor, IXMLPartitions.DTD_SUBSET); - } - ca = assistant; - } - - return ca; - } - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/CorrectionProcessorXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/CorrectionProcessorXML.java deleted file mode 100644 index 97e73e73f0..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/CorrectionProcessorXML.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.correction; - -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.wst.sse.ui.internal.correction.IQuickAssistProcessor; -import org.eclipse.wst.sse.ui.internal.correction.IQuickFixProcessor; -import org.eclipse.wst.sse.ui.internal.correction.StructuredCorrectionProcessor; - -/** - * @deprecated since 2.0 RC0 Use - * org.eclipse.jface.text.quickassist.IQuickAssistProcessor; - */ -public class CorrectionProcessorXML extends StructuredCorrectionProcessor { - protected IQuickAssistProcessor fQuickAssistProcessor; - protected IQuickFixProcessor fQuickFixProcessor; - - public CorrectionProcessorXML(ISourceViewer sourceViewer) { - super(sourceViewer); - } - - protected IQuickAssistProcessor getQuickAssistProcessor() { - if (fQuickAssistProcessor == null) { - fQuickAssistProcessor = new QuickAssistProcessorXML(); - } - - return fQuickAssistProcessor; - } - - protected IQuickFixProcessor getQuickFixProcessor() { - if (fQuickFixProcessor == null) { - fQuickFixProcessor = new QuickFixProcessorXML(); - } - - return fQuickFixProcessor; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/InsertRequiredAttrsQuickAssistProposal.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/InsertRequiredAttrsQuickAssistProposal.java deleted file mode 100644 index 74947edfd4..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/InsertRequiredAttrsQuickAssistProposal.java +++ /dev/null @@ -1,180 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.correction; - -import java.util.List; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.DocumentEvent; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.jface.text.contentassist.ICompletionProposalExtension2; -import org.eclipse.jface.text.contentassist.IContextInformation; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -import org.eclipse.text.edits.InsertEdit; -import org.eclipse.text.edits.MultiTextEdit; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils; -import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages; - -public class InsertRequiredAttrsQuickAssistProposal implements ICompletionProposal, ICompletionProposalExtension2 { - private final List fRequiredAttrs; - - /** - * @param requiredAttrs - */ - public InsertRequiredAttrsQuickAssistProposal(List requiredAttrs) { - fRequiredAttrs = requiredAttrs; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposal#apply(org.eclipse.jface.text.IDocument) - */ - public void apply(IDocument document) { - // not implemented? - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#apply(org.eclipse.jface.text.ITextViewer, - * char, int, int) - */ - public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) { - IDOMNode node = (IDOMNode) ContentAssistUtils.getNodeAt(viewer, offset); - IStructuredDocumentRegion startStructuredDocumentRegion = node.getStartStructuredDocumentRegion(); - int index = startStructuredDocumentRegion.getEndOffset(); - ITextRegion lastRegion = startStructuredDocumentRegion.getLastRegion(); - if (lastRegion.getType() == DOMRegionContext.XML_TAG_CLOSE) { - index--; - lastRegion = startStructuredDocumentRegion.getRegionAtCharacterOffset(index - 1); - } - else if (lastRegion.getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE) { - index = index - 2; - lastRegion = startStructuredDocumentRegion.getRegionAtCharacterOffset(index - 1); - } - MultiTextEdit multiTextEdit = new MultiTextEdit(); - try { - for (int i = 0; i < fRequiredAttrs.size(); i++) { - CMAttributeDeclaration attrDecl = (CMAttributeDeclaration) fRequiredAttrs.get(i); - String requiredAttributeName = attrDecl.getAttrName(); - String defaultValue = attrDecl.getDefaultValue(); - if (defaultValue == null) { - defaultValue = ""; //$NON-NLS-1$ - } - String nameAndDefaultValue = " "; //$NON-NLS-1$ - if ((i == 0) && (lastRegion.getLength() > lastRegion.getTextLength())) { - nameAndDefaultValue = ""; //$NON-NLS-1$ - } - nameAndDefaultValue += requiredAttributeName + "=\"" + defaultValue + "\""; //$NON-NLS-1$//$NON-NLS-2$ - multiTextEdit.addChild(new InsertEdit(index, nameAndDefaultValue)); - // BUG3381: MultiTextEdit applies all child TextEdit's basing - // on offsets - // in the document before the first TextEdit, not after each - // child TextEdit. Therefore, do not need to advance the - // index. - // index += nameAndDefaultValue.length(); - } - multiTextEdit.apply(viewer.getDocument()); - } - catch (BadLocationException e) { - // log, for now, unless we find there's reasons why we get some - // here. - Logger.log(Logger.INFO, e.getMessage()); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getAdditionalProposalInfo() - */ - public String getAdditionalProposalInfo() { - return XMLUIMessages.InsertRequiredAttrsQuickAssistProposal_0; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getContextInformation() - */ - public IContextInformation getContextInformation() { - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getDisplayString() - */ - public String getDisplayString() { - return XMLUIMessages.InsertRequiredAttrsQuickAssistProposal_1; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getImage() - */ - public Image getImage() { - // return JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_LOCAL); - return XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ADD_CORRECTION); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getSelection(org.eclipse.jface.text.IDocument) - */ - public Point getSelection(IDocument document) { - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#selected(org.eclipse.jface.text.ITextViewer, - * boolean) - */ - public void selected(ITextViewer viewer, boolean smartToggle) { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#unselected(org.eclipse.jface.text.ITextViewer) - */ - public void unselected(ITextViewer viewer) { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#validate(org.eclipse.jface.text.IDocument, - * int, org.eclipse.jface.text.DocumentEvent) - */ - public boolean validate(IDocument document, int offset, DocumentEvent event) { - return false; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/ProblemIDsXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/ProblemIDsXML.java deleted file mode 100644 index 18fae109eb..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/ProblemIDsXML.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.correction; - -public interface ProblemIDsXML { - int AttrsInEndTag = 3; - int AttrValueNotQuoted = 13; - int EmptyTag = 1; - int InvalidAttrValue = 11; - int MissingAttrValue = 4; - int MissingClosingBracket = 14; - int MissingEndTag = 2; - int MissingRequiredAttr = 12; - int MissingStartTag = 15; - int NamespaceInPI = 8; - int NoAttrValue = 5; - int SpacesBeforePI = 7; - int SpacesBeforeTagName = 6; - int Unclassified = 0; - int UnknownAttr = 10; - int UnknownElement = 9; -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/QuickAssistProcessorXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/QuickAssistProcessorXML.java deleted file mode 100644 index 328db8d7cd..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/QuickAssistProcessorXML.java +++ /dev/null @@ -1,192 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.correction; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.sse.ui.internal.StructuredTextViewer; -import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils; -import org.eclipse.wst.sse.ui.internal.correction.IQuickAssistProcessor; -import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; - -/** - * @deprecated since 2.0 RC0 Use - * org.eclipse.jface.text.quickassist.IQuickAssistProcessor; - */ -public class QuickAssistProcessorXML implements IQuickAssistProcessor { - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.correction.IQuickAssistProcessor#canAssist(org.eclipse.wst.sse.core.text.IStructuredDocument, - * int) - */ - public boolean canAssist(StructuredTextViewer viewer, int offset) { - return true; - } - - /** - * @param proposals - * @param viewer - * @param offset - */ - protected void getInsertRequiredAttrs(ArrayList proposals, StructuredTextViewer viewer, int offset) { - IDOMNode node = (IDOMNode) ContentAssistUtils.getNodeAt(viewer, offset); - if ((node != null) && (node.getNodeType() == Node.ELEMENT_NODE)) { - IStructuredDocumentRegion startStructuredDocumentRegion = node.getStartStructuredDocumentRegion(); - if ((startStructuredDocumentRegion != null) && startStructuredDocumentRegion.containsOffset(offset)) { - IDOMNode cursorNode = (IDOMNode) ContentAssistUtils.getNodeAt(viewer, offset); - List requiredAttrs = getRequiredAttrs(cursorNode); - if (requiredAttrs.size() > 0) { - NamedNodeMap currentAttrs = node.getAttributes(); - List insertAttrs = new ArrayList(); - if (currentAttrs.getLength() == 0) { - insertAttrs.addAll(requiredAttrs); - } - else { - for (int i = 0; i < requiredAttrs.size(); i++) { - String requiredAttrName = ((CMAttributeDeclaration) requiredAttrs.get(i)).getAttrName(); - boolean found = false; - for (int j = 0; j < currentAttrs.getLength(); j++) { - String currentAttrName = currentAttrs.item(j).getNodeName(); - if (requiredAttrName.compareToIgnoreCase(currentAttrName) == 0) { - found = true; - break; - } - } - if (!found) { - insertAttrs.add(requiredAttrs.get(i)); - } - } - } - if (insertAttrs.size() > 0) { - proposals.add(new InsertRequiredAttrsQuickAssistProposal(insertAttrs)); - } - } - } - } - } - - /** - * @param proposals - * @param viewer - * @param offset - */ - protected void getLocalRenameQuickAssistProposal(ArrayList proposals, StructuredTextViewer viewer, int offset) { - IDOMNode node = (IDOMNode) ContentAssistUtils.getNodeAt(viewer, offset); - IStructuredDocumentRegion startStructuredDocumentRegion = node == null ? null : node.getStartStructuredDocumentRegion(); - IStructuredDocumentRegion endStructuredDocumentRegion = node == null ? null : node.getEndStructuredDocumentRegion(); - - ITextRegion region = null; - int regionTextEndOffset = 0; - if ((startStructuredDocumentRegion != null) && startStructuredDocumentRegion.containsOffset(offset)) { - region = startStructuredDocumentRegion.getRegionAtCharacterOffset(offset); - regionTextEndOffset = startStructuredDocumentRegion.getTextEndOffset(region); - } - else if ((endStructuredDocumentRegion != null) && endStructuredDocumentRegion.containsOffset(offset)) { - region = endStructuredDocumentRegion.getRegionAtCharacterOffset(offset); - regionTextEndOffset = endStructuredDocumentRegion.getTextEndOffset(region); - } - - if ((region != null) && ((region.getType() == DOMRegionContext.XML_TAG_NAME) || (region.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME)) && (offset <= regionTextEndOffset)) { - proposals.add(new RenameInFileQuickAssistProposal()); - } - } - - protected ModelQuery getModelQuery(Node node) { - if (node.getNodeType() == Node.DOCUMENT_NODE) { - return ModelQueryUtil.getModelQuery((Document) node); - } - else { - return ModelQueryUtil.getModelQuery(node.getOwnerDocument()); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.correction.IQuickAssistProcessor#getProposals(org.eclipse.wst.sse.core.text.IStructuredDocument, - * int) - */ - public ICompletionProposal[] getProposals(StructuredTextViewer viewer, int offset) throws CoreException { - ArrayList proposals = new ArrayList(); - - getLocalRenameQuickAssistProposal(proposals, viewer, offset); - getSurroundWithNewElementQuickAssistProposal(proposals, viewer, offset); - getInsertRequiredAttrs(proposals, viewer, offset); - - return (ICompletionProposal[]) proposals.toArray(new ICompletionProposal[proposals.size()]); - } - - protected List getRequiredAttrs(Node node) { - List result = new ArrayList(); - - ModelQuery modelQuery = getModelQuery(node); - if (modelQuery != null) { - CMElementDeclaration elementDecl = modelQuery.getCMElementDeclaration((Element) node); - if (elementDecl != null) { - CMNamedNodeMap attrMap = elementDecl.getAttributes(); - - CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(attrMap); - List nodes = ModelQueryUtil.getModelQuery(node.getOwnerDocument()).getAvailableContent((Element)node, elementDecl, ModelQuery.INCLUDE_ATTRIBUTES); - for (int k = 0; k < nodes.size(); k++) { - CMNode cmnode = (CMNode) nodes.get(k); - if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) { - allAttributes.put(cmnode); - } - } - attrMap = allAttributes; - - Iterator it = attrMap.iterator(); - CMAttributeDeclaration attr = null; - while (it.hasNext()) { - attr = (CMAttributeDeclaration) it.next(); - if (attr.getUsage() == CMAttributeDeclaration.REQUIRED) { - result.add(attr); - } - } - } - } - - return result; - } - - /** - * @param proposals - * @param viewer - * @param offset - */ - protected void getSurroundWithNewElementQuickAssistProposal(ArrayList proposals, StructuredTextViewer viewer, int offset) { - IDOMNode node = (IDOMNode) ContentAssistUtils.getNodeAt(viewer, offset); - if (node != null) { - proposals.add(new SurroundWithNewElementQuickAssistProposal()); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/QuickFixProcessorXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/QuickFixProcessorXML.java deleted file mode 100644 index 28eaea1de6..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/QuickFixProcessorXML.java +++ /dev/null @@ -1,151 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.correction; - -import java.util.ArrayList; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jface.text.contentassist.CompletionProposal; -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.jface.text.source.Annotation; -import org.eclipse.swt.graphics.Image; -import org.eclipse.wst.sse.ui.internal.correction.IQuickFixProcessor; -import org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages; - -/** - * @deprecated since 2.0 RC0 Use - * org.eclipse.jface.text.quickassist.IQuickAssistProcessor; - */ -public class QuickFixProcessorXML implements IQuickFixProcessor { - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.correction.IQuickFixProcessor#canFix(int) - */ - public boolean canFix(Annotation annotation) { - boolean result = false; - - if (annotation instanceof TemporaryAnnotation) { - TemporaryAnnotation tempAnnotation = (TemporaryAnnotation) annotation; - int problemID = tempAnnotation.getProblemID(); - switch (problemID) { - case ProblemIDsXML.EmptyTag : - case ProblemIDsXML.MissingEndTag : - case ProblemIDsXML.AttrsInEndTag : - case ProblemIDsXML.MissingAttrValue : - case ProblemIDsXML.NoAttrValue : - case ProblemIDsXML.SpacesBeforeTagName : - case ProblemIDsXML.SpacesBeforePI : - case ProblemIDsXML.NamespaceInPI : - case ProblemIDsXML.UnknownElement : - case ProblemIDsXML.UnknownAttr : - case ProblemIDsXML.InvalidAttrValue : - case ProblemIDsXML.MissingRequiredAttr : - case ProblemIDsXML.AttrValueNotQuoted : - case ProblemIDsXML.MissingClosingBracket : - result = true; - } - } - - return result; - } - - public Image getImage() { - // return - // JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); - return XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_CORRECTION_CHANGE); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.correction.IQuickFixProcessor#getProposals(org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation) - */ - public ICompletionProposal[] getProposals(Annotation annotation) throws CoreException { - ArrayList proposals = new ArrayList(); - - if (annotation instanceof TemporaryAnnotation) { - TemporaryAnnotation tempAnnotation = (TemporaryAnnotation) annotation; - int problemID = tempAnnotation.getProblemID(); - switch (problemID) { - case ProblemIDsXML.EmptyTag : - proposals.add(new CompletionProposal("", tempAnnotation.getPosition().getOffset(), tempAnnotation.getPosition().getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_0, null, "")); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case ProblemIDsXML.MissingEndTag : - String tagName = (String) ((Object[]) tempAnnotation.getAdditionalFixInfo())[0]; - String tagClose = (String) ((Object[]) tempAnnotation.getAdditionalFixInfo())[1]; - int tagCloseOffset = ((Integer) ((Object[]) tempAnnotation.getAdditionalFixInfo())[2]).intValue(); - int startTagEndOffset = ((Integer) ((Object[]) tempAnnotation.getAdditionalFixInfo())[3]).intValue(); - int firstChildStartOffset = ((Integer) ((Object[]) tempAnnotation.getAdditionalFixInfo())[4]).intValue(); - int endOffset = ((Integer) ((Object[]) tempAnnotation.getAdditionalFixInfo())[5]).intValue(); - proposals.add(new CompletionProposal(tagClose, tagCloseOffset, 0, 0, getImage(), XMLUIMessages.QuickFixProcessorXML_1, null, "")); //$NON-NLS-1$ - proposals.add(new CompletionProposal("", tempAnnotation.getPosition().getOffset(), startTagEndOffset - tempAnnotation.getPosition().getOffset(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_2, null, "")); //$NON-NLS-1$ //$NON-NLS-2$ - proposals.add(new CompletionProposal("</" + tagName + ">", firstChildStartOffset, 0, 0, getImage(), XMLUIMessages.QuickFixProcessorXML_3, null, "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - proposals.add(new CompletionProposal("</" + tagName + ">", endOffset, 0, 0, getImage(), XMLUIMessages.QuickFixProcessorXML_4, null, "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - break; - case ProblemIDsXML.AttrsInEndTag : - proposals.add(new CompletionProposal("", tempAnnotation.getPosition().getOffset(), tempAnnotation.getPosition().getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_5, null, "")); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case ProblemIDsXML.MissingAttrValue : - String defaultAttrValue = (String) ((Object[]) tempAnnotation.getAdditionalFixInfo())[0]; - int insertOffset = ((Integer) ((Object[]) tempAnnotation.getAdditionalFixInfo())[1]).intValue(); - proposals.add(new CompletionProposal("\"" + defaultAttrValue + "\"", tempAnnotation.getPosition().getOffset() + tempAnnotation.getPosition().getLength() + insertOffset, 0, defaultAttrValue.length() + 2, getImage(), XMLUIMessages.QuickFixProcessorXML_6, null, "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - proposals.add(new CompletionProposal("", tempAnnotation.getPosition().getOffset(), tempAnnotation.getPosition().getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_7, null, "")); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case ProblemIDsXML.NoAttrValue : - defaultAttrValue = (String) tempAnnotation.getAdditionalFixInfo(); - proposals.add(new CompletionProposal("=\"" + defaultAttrValue + "\"", tempAnnotation.getPosition().getOffset() + tempAnnotation.getPosition().getLength(), 0, defaultAttrValue.length() + 3, getImage(), XMLUIMessages.QuickFixProcessorXML_6, null, "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - proposals.add(new CompletionProposal("", tempAnnotation.getPosition().getOffset(), tempAnnotation.getPosition().getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_7, null, "")); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case ProblemIDsXML.SpacesBeforeTagName : - proposals.add(new CompletionProposal("", tempAnnotation.getPosition().getOffset(), tempAnnotation.getPosition().getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_8, null, "")); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case ProblemIDsXML.SpacesBeforePI : - proposals.add(new CompletionProposal("", tempAnnotation.getPosition().getOffset(), tempAnnotation.getPosition().getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_9, null, "")); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case ProblemIDsXML.NamespaceInPI : - proposals.add(new CompletionProposal("", tempAnnotation.getPosition().getOffset(), tempAnnotation.getPosition().getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_10, null, "")); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case ProblemIDsXML.UnknownElement : - proposals.add(new RemoveUnknownElementQuickFixProposal(tempAnnotation.getAdditionalFixInfo(), getImage(), XMLUIMessages.QuickFixProcessorXML_11)); - proposals.add(new RenameInFileQuickAssistProposal()); - break; - case ProblemIDsXML.UnknownAttr : - proposals.add(new CompletionProposal("", tempAnnotation.getPosition().getOffset(), tempAnnotation.getPosition().getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_7, null, "")); //$NON-NLS-1$ //$NON-NLS-2$ - proposals.add(new RenameInFileQuickAssistProposal()); - break; - case ProblemIDsXML.InvalidAttrValue : - proposals.add(new CompletionProposal("", tempAnnotation.getPosition().getOffset(), tempAnnotation.getPosition().getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_12, null, "")); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case ProblemIDsXML.MissingRequiredAttr : - String requiredAttr = (String) ((Object[]) tempAnnotation.getAdditionalFixInfo())[0]; - insertOffset = ((Integer) ((Object[]) tempAnnotation.getAdditionalFixInfo())[1]).intValue(); - proposals.add(new CompletionProposal(requiredAttr, tempAnnotation.getPosition().getOffset() + insertOffset, 0, requiredAttr.length(), getImage(), XMLUIMessages.QuickFixProcessorXML_13, null, "")); //$NON-NLS-1$ - break; - case ProblemIDsXML.AttrValueNotQuoted : - String attrValue = (String) tempAnnotation.getAdditionalFixInfo(); - proposals.add(new CompletionProposal("\"" + attrValue + "\"", tempAnnotation.getPosition().getOffset(), tempAnnotation.getPosition().getLength(), attrValue.length() + 2, getImage(), XMLUIMessages.QuickFixProcessorXML_14, null, "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - break; - case ProblemIDsXML.MissingClosingBracket : - proposals.add(new CompletionProposal(">", tempAnnotation.getPosition().getOffset() + tempAnnotation.getPosition().getLength(), 0, 1, getImage(), XMLUIMessages.QuickFixProcessorXML_15, null, "")); //$NON-NLS-1$ //$NON-NLS-2$ - break; - } - } - - return (ICompletionProposal[]) proposals.toArray(new ICompletionProposal[proposals.size()]); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/RemoveUnknownElementQuickFixProposal.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/RemoveUnknownElementQuickFixProposal.java deleted file mode 100644 index b87a2c9a78..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/RemoveUnknownElementQuickFixProposal.java +++ /dev/null @@ -1,162 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.correction; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.DocumentEvent; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.jface.text.contentassist.ICompletionProposalExtension2; -import org.eclipse.jface.text.contentassist.IContextInformation; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -import org.eclipse.text.edits.DeleteEdit; -import org.eclipse.text.edits.MalformedTreeException; -import org.eclipse.text.edits.MultiTextEdit; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; - -public class RemoveUnknownElementQuickFixProposal implements ICompletionProposal, ICompletionProposalExtension2 { - private Object fAdditionalFixInfo = null; - private String fDisplayString; - private Image fImage; - private Point fSelection; // initialized by apply() - - public RemoveUnknownElementQuickFixProposal(Object additionalFixInfo, Image image, String displayString) { - fAdditionalFixInfo = additionalFixInfo; - fImage = image; - fDisplayString = displayString; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposal#apply(org.eclipse.jface.text.IDocument) - */ - public void apply(IDocument document) { - // not implemented? - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#apply(org.eclipse.jface.text.ITextViewer, - * char, int, int) - */ - public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) { - int startTagOffset = ((Integer) ((Object[]) fAdditionalFixInfo)[0]).intValue(); - int startTagLength = ((Integer) ((Object[]) fAdditionalFixInfo)[1]).intValue(); - int endTagOffset = ((Integer) ((Object[]) fAdditionalFixInfo)[2]).intValue(); - int endTagLength = ((Integer) ((Object[]) fAdditionalFixInfo)[3]).intValue(); - - MultiTextEdit multiTextEdit = new MultiTextEdit(); - if (endTagOffset != -1) { - multiTextEdit.addChild(new DeleteEdit(endTagOffset, endTagLength)); - fSelection = new Point(endTagOffset, 0); - } - if (startTagOffset != -1) { - multiTextEdit.addChild(new DeleteEdit(startTagOffset, startTagLength)); - fSelection = new Point(startTagOffset, 0); - } - - try { - multiTextEdit.apply(viewer.getDocument()); - } - catch (MalformedTreeException e) { - // log for now, unless find reasons not to. - Logger.log(Logger.INFO, e.getMessage()); - } - catch (BadLocationException e) { - // log for now, unless find reasons not to. - Logger.log(Logger.INFO, e.getMessage()); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getAdditionalProposalInfo() - */ - public String getAdditionalProposalInfo() { - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getContextInformation() - */ - public IContextInformation getContextInformation() { - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getDisplayString() - */ - public String getDisplayString() { - if (fDisplayString == null) { - fDisplayString = XMLUIMessages.QuickFixProcessorXML_11; - } - - return fDisplayString; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getImage() - */ - public Image getImage() { - return fImage; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getSelection(org.eclipse.jface.text.IDocument) - */ - public Point getSelection(IDocument document) { - return fSelection; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#selected(org.eclipse.jface.text.ITextViewer, - * boolean) - */ - public void selected(ITextViewer viewer, boolean smartToggle) { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#unselected(org.eclipse.jface.text.ITextViewer) - */ - public void unselected(ITextViewer viewer) { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#validate(org.eclipse.jface.text.IDocument, - * int, org.eclipse.jface.text.DocumentEvent) - */ - public boolean validate(IDocument document, int offset, DocumentEvent event) { - return false; - } - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/RenameInFileQuickAssistProposal.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/RenameInFileQuickAssistProposal.java deleted file mode 100644 index ac95b3178c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/RenameInFileQuickAssistProposal.java +++ /dev/null @@ -1,188 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.correction; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.DocumentEvent; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.jface.text.contentassist.ICompletionProposalExtension2; -import org.eclipse.jface.text.contentassist.IContextInformation; -import org.eclipse.jface.text.link.LinkedModeModel; -import org.eclipse.jface.text.link.LinkedModeUI; -import org.eclipse.jface.text.link.LinkedPosition; -import org.eclipse.jface.text.link.LinkedPositionGroup; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -import org.eclipse.ui.texteditor.link.EditorLinkedModeUI; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.sse.ui.internal.StructuredTextViewer; -import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages; - -public class RenameInFileQuickAssistProposal implements ICompletionProposal, ICompletionProposalExtension2 { - protected IRegion fSelectedRegion; // initialized by apply() - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposal#apply(org.eclipse.jface.text.IDocument) - */ - public void apply(IDocument document) { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#apply(org.eclipse.jface.text.ITextViewer, - * char, int, int) - */ - public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) { - IDocument document = viewer.getDocument(); - LinkedPositionGroup group = new LinkedPositionGroup(); - try { - if (viewer instanceof StructuredTextViewer) { - IDOMNode node = (IDOMNode) ContentAssistUtils.getNodeAt(viewer, offset); - IStructuredDocumentRegion startStructuredDocumentRegion = node.getStartStructuredDocumentRegion(); - ITextRegion region = (startStructuredDocumentRegion == null) ? null : startStructuredDocumentRegion.getRegionAtCharacterOffset(offset); - if (region != null) { - group.addPosition(new LinkedPosition(document, startStructuredDocumentRegion.getStartOffset() + region.getStart(), region.getTextLength(), 0)); - - if ((region.getType() == DOMRegionContext.XML_TAG_NAME) && (node.getEndStructuredDocumentRegion() != null)) { - region = node.getEndStructuredDocumentRegion().getRegions().get(1); - if (region != null) { - group.addPosition(new LinkedPosition(document, node.getEndStructuredDocumentRegion().getStartOffset() + region.getStart(), region.getTextLength(), 1)); - } - } - } - else { - IStructuredDocumentRegion endStructuredDocumentRegion = node.getEndStructuredDocumentRegion(); - region = (endStructuredDocumentRegion == null) ? null : endStructuredDocumentRegion.getRegionAtCharacterOffset(offset); - if (region != null) { - if ((region.getType() == DOMRegionContext.XML_TAG_NAME) && (node.getStartStructuredDocumentRegion() != null)) { - ITextRegion startTagNameRegion = node.getStartStructuredDocumentRegion().getRegions().get(1); - if (region != null) { - group.addPosition(new LinkedPosition(document, node.getStartStructuredDocumentRegion().getStartOffset() + startTagNameRegion.getStart(), startTagNameRegion.getTextLength(), 0)); - group.addPosition(new LinkedPosition(document, endStructuredDocumentRegion.getStartOffset() + region.getStart(), region.getTextLength(), 1)); - } - } - else { - group.addPosition(new LinkedPosition(document, endStructuredDocumentRegion.getStartOffset() + region.getStart(), region.getTextLength(), 0)); - } - } - } - - // TODO CompletionProposalPopup#insertProposal() calls - // IRewriteTarget.beginCompoundChange() - // which disables redraw in ITextViewer. Workaround for now. - ((StructuredTextViewer) viewer).setRedraw(true); - } - - LinkedModeModel linkedModeModel = new LinkedModeModel(); - linkedModeModel.addGroup(group); - linkedModeModel.forceInstall(); - - LinkedModeUI ui = new EditorLinkedModeUI(linkedModeModel, viewer); - ui.setExitPosition(viewer, offset, 0, LinkedPositionGroup.NO_STOP); - ui.enter(); - - fSelectedRegion = ui.getSelectedRegion(); - } - catch (BadLocationException e) { - // log for now, unless find reason not to - Logger.log(Logger.INFO, e.getMessage()); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getAdditionalProposalInfo() - */ - public String getAdditionalProposalInfo() { - return XMLUIMessages.RenameInFileQuickAssistProposal_0; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getContextInformation() - */ - public IContextInformation getContextInformation() { - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getDisplayString() - */ - public String getDisplayString() { - return XMLUIMessages.RenameInFileQuickAssistProposal_1; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getImage() - */ - public Image getImage() { - // return JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_LOCAL); - return XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_LOCAL_VARIABLE); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getSelection(org.eclipse.jface.text.IDocument) - */ - public Point getSelection(IDocument document) { - return new Point(fSelectedRegion.getOffset(), fSelectedRegion.getLength()); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#selected(org.eclipse.jface.text.ITextViewer, - * boolean) - */ - public void selected(ITextViewer viewer, boolean smartToggle) { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#unselected(org.eclipse.jface.text.ITextViewer) - */ - public void unselected(ITextViewer viewer) { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#validate(org.eclipse.jface.text.IDocument, - * int, org.eclipse.jface.text.DocumentEvent) - */ - public boolean validate(IDocument document, int offset, DocumentEvent event) { - return false; - } - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/SurroundWithNewElementQuickAssistProposal.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/SurroundWithNewElementQuickAssistProposal.java deleted file mode 100644 index 7baffc845a..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/SurroundWithNewElementQuickAssistProposal.java +++ /dev/null @@ -1,111 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.correction; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.swt.graphics.Image; -import org.eclipse.text.edits.InsertEdit; -import org.eclipse.text.edits.MalformedTreeException; -import org.eclipse.text.edits.MultiTextEdit; -import org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor; -import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages; -import org.w3c.dom.Node; - -public class SurroundWithNewElementQuickAssistProposal extends RenameInFileQuickAssistProposal { - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#apply(org.eclipse.jface.text.ITextViewer, - * char, int, int) - */ - public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) { - try { - int startTagOffset = offset; - int endTagOffset = offset + viewer.getSelectedRange().y; - - // surround the node if no selection - if (startTagOffset == endTagOffset) { - IDOMNode cursorNode = (IDOMNode) ContentAssistUtils.getNodeAt(viewer, offset); - // use parent node if text node is empty - if ((cursorNode.getNodeType() == Node.TEXT_NODE) && (cursorNode.getNodeValue().trim().length() == 0)) { - cursorNode = (IDOMNode) cursorNode.getParentNode(); - } - - startTagOffset = cursorNode.getStartOffset(); - endTagOffset = cursorNode.getEndOffset(); - } - - // insert new element - MultiTextEdit multiTextEdit = new MultiTextEdit(); - // element tag name cannot be DBCS, do not translate "<element>" - // and "</element>" - multiTextEdit.addChild(new InsertEdit(startTagOffset, "<element>")); //$NON-NLS-1$ - multiTextEdit.addChild(new InsertEdit(endTagOffset, "</element>")); //$NON-NLS-1$ - multiTextEdit.apply(viewer.getDocument()); - - // get new element node - IDOMNode newElementNode = (IDOMNode) ContentAssistUtils.getNodeAt(viewer, startTagOffset); - - // format new element - IStructuredFormatProcessor formatProcessor = new FormatProcessorXML(); - formatProcessor.formatNode(newElementNode); - - // rename new element - super.apply(viewer, trigger, stateMask, newElementNode.getStartOffset() + 1); - } - catch (MalformedTreeException e) { - // log for now, unless find reason not to - Logger.log(Logger.INFO, e.getMessage()); - } - catch (BadLocationException e) { - // log for now, unless find reason not to - Logger.log(Logger.INFO, e.getMessage()); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getAdditionalProposalInfo() - */ - public String getAdditionalProposalInfo() { - return XMLUIMessages.SurroundWithNewElementQuickAssistProposal_0; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getDisplayString() - */ - public String getDisplayString() { - return XMLUIMessages.SurroundWithNewElementQuickAssistProposal_1; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getImage() - */ - public Image getImage() { - // return JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_LOCAL); - return XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ADD_CORRECTION); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/XMLQuickAssistProcessor.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/XMLQuickAssistProcessor.java deleted file mode 100644 index 4649e948af..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/XMLQuickAssistProcessor.java +++ /dev/null @@ -1,212 +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.wst.xml.ui.internal.correction; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext; -import org.eclipse.jface.text.quickassist.IQuickAssistProcessor; -import org.eclipse.jface.text.source.Annotation; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; - -public class XMLQuickAssistProcessor implements IQuickAssistProcessor { - - public boolean canAssist(IQuickAssistInvocationContext invocationContext) { - return true; - } - - public boolean canFix(Annotation annotation) { - return false; - } - - public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) { - List proposals = new ArrayList(); - - getLocalRenameQuickAssistProposal(proposals, invocationContext.getSourceViewer(), invocationContext.getOffset()); - getSurroundWithNewElementQuickAssistProposal(proposals, invocationContext.getSourceViewer(), invocationContext.getOffset()); - getInsertRequiredAttrs(proposals, invocationContext.getSourceViewer(), invocationContext.getOffset()); - - return (ICompletionProposal[]) proposals.toArray(new ICompletionProposal[proposals.size()]); - } - - public String getErrorMessage() { - return null; - } - - private void getInsertRequiredAttrs(List proposals, ISourceViewer viewer, int offset) { - IDOMNode node = (IDOMNode) getNodeAt(viewer, offset); - if ((node != null) && (node.getNodeType() == Node.ELEMENT_NODE)) { - IStructuredDocumentRegion startStructuredDocumentRegion = node.getStartStructuredDocumentRegion(); - if ((startStructuredDocumentRegion != null) && startStructuredDocumentRegion.containsOffset(offset)) { - IDOMNode cursorNode = (IDOMNode) getNodeAt(viewer, offset); - List requiredAttrs = getRequiredAttrs(cursorNode); - if (requiredAttrs.size() > 0) { - NamedNodeMap currentAttrs = node.getAttributes(); - List insertAttrs = new ArrayList(); - if (currentAttrs.getLength() == 0) { - insertAttrs.addAll(requiredAttrs); - } - else { - for (int i = 0; i < requiredAttrs.size(); i++) { - String requiredAttrName = ((CMAttributeDeclaration) requiredAttrs.get(i)).getAttrName(); - boolean found = false; - for (int j = 0; j < currentAttrs.getLength(); j++) { - String currentAttrName = currentAttrs.item(j).getNodeName(); - if (requiredAttrName.compareToIgnoreCase(currentAttrName) == 0) { - found = true; - break; - } - } - if (!found) { - insertAttrs.add(requiredAttrs.get(i)); - } - } - } - if (insertAttrs.size() > 0) { - proposals.add(new InsertRequiredAttrsQuickAssistProposal(insertAttrs)); - } - } - } - } - } - - private void getLocalRenameQuickAssistProposal(List proposals, ISourceViewer viewer, int offset) { - IDOMNode node = (IDOMNode) getNodeAt(viewer, offset); - IStructuredDocumentRegion startStructuredDocumentRegion = node == null ? null : node.getStartStructuredDocumentRegion(); - IStructuredDocumentRegion endStructuredDocumentRegion = node == null ? null : node.getEndStructuredDocumentRegion(); - - ITextRegion region = null; - int regionTextEndOffset = 0; - if ((startStructuredDocumentRegion != null) && startStructuredDocumentRegion.containsOffset(offset)) { - region = startStructuredDocumentRegion.getRegionAtCharacterOffset(offset); - regionTextEndOffset = startStructuredDocumentRegion.getTextEndOffset(region); - } - else if ((endStructuredDocumentRegion != null) && endStructuredDocumentRegion.containsOffset(offset)) { - region = endStructuredDocumentRegion.getRegionAtCharacterOffset(offset); - regionTextEndOffset = endStructuredDocumentRegion.getTextEndOffset(region); - } - - if ((region != null) && ((region.getType() == DOMRegionContext.XML_TAG_NAME) || (region.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME)) && (offset <= regionTextEndOffset)) { - proposals.add(new RenameInFileQuickAssistProposal()); - } - } - - private ModelQuery getModelQuery(Node node) { - if (node.getNodeType() == Node.DOCUMENT_NODE) { - return ModelQueryUtil.getModelQuery((Document) node); - } - else { - return ModelQueryUtil.getModelQuery(node.getOwnerDocument()); - } - } - - private List getRequiredAttrs(Node node) { - List result = new ArrayList(); - - ModelQuery modelQuery = getModelQuery(node); - if (modelQuery != null) { - CMElementDeclaration elementDecl = modelQuery.getCMElementDeclaration((Element) node); - if (elementDecl != null) { - CMNamedNodeMap attrMap = elementDecl.getAttributes(); - - CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(attrMap); - List nodes = ModelQueryUtil.getModelQuery(node.getOwnerDocument()).getAvailableContent((Element) node, elementDecl, ModelQuery.INCLUDE_ATTRIBUTES); - for (int k = 0; k < nodes.size(); k++) { - CMNode cmnode = (CMNode) nodes.get(k); - if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) { - allAttributes.put(cmnode); - } - } - attrMap = allAttributes; - - Iterator it = attrMap.iterator(); - CMAttributeDeclaration attr = null; - while (it.hasNext()) { - attr = (CMAttributeDeclaration) it.next(); - if (attr.getUsage() == CMAttributeDeclaration.REQUIRED) { - result.add(attr); - } - } - } - } - - return result; - } - - private void getSurroundWithNewElementQuickAssistProposal(List proposals, ISourceViewer viewer, int offset) { - IDOMNode node = (IDOMNode) getNodeAt(viewer, offset); - if (node != null) { - proposals.add(new SurroundWithNewElementQuickAssistProposal()); - } - } - - /** - * Returns the closest IndexedRegion for the offset and viewer allowing - * for differences between viewer offsets and model positions. note: this - * method returns an IndexedRegion for read only - * - * @param viewer - * the viewer whose document is used to compute the proposals - * @param documentOffset - * an offset within the document for which completions should - * be computed - * @return an IndexedRegion - */ - private IndexedRegion getNodeAt(ITextViewer viewer, int documentOffset) { - // copied from ContentAssistUtils.getNodeAt() - if (viewer == null) - return null; - - IndexedRegion node = null; - IModelManager mm = StructuredModelManager.getModelManager(); - IStructuredModel model = null; - if (mm != null) - model = mm.getExistingModelForRead(viewer.getDocument()); - try { - if (model != null) { - int lastOffset = documentOffset; - node = model.getIndexedRegion(documentOffset); - while (node == null && lastOffset >= 0) { - lastOffset--; - node = model.getIndexedRegion(lastOffset); - } - } - } - finally { - if (model != null) - model.releaseFromRead(); - } - return node; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/EditAttributeDialog.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/EditAttributeDialog.java deleted file mode 100644 index e95af8078c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/EditAttributeDialog.java +++ /dev/null @@ -1,172 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.dialogs; - -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -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.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.util.XMLCommonUIContextIds; -import org.w3c.dom.Attr; -import org.w3c.dom.Element; - -public class EditAttributeDialog extends Dialog implements ModifyListener { - protected Attr attribute; - protected String attributeName; - protected Text attributeNameField; - protected String attributeValue; - protected Text attributeValueField; - protected Label errorMessageLabel; - protected Button okButton; - protected Element ownerElement; - - public EditAttributeDialog(Shell parentShell, Element ownerElement, Attr attribute) { - super(parentShell); - setShellStyle(getShellStyle() | SWT.RESIZE); - this.ownerElement = ownerElement; - this.attribute = attribute; - } - - protected void buttonPressed(int buttonId) { - if (buttonId == IDialogConstants.OK_ID) { - attributeName = getModelValue(attributeNameField.getText()); - attributeValue = attributeValueField.getText(); - } - super.buttonPressed(buttonId); - } - - protected void createButtonsForButtonBar(Composite parent) { - okButton = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); - createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); - } - - protected Control createContents(Composite parent) { - Control control = super.createContents(parent); - attributeNameField.forceFocus(); - attributeNameField.selectAll(); - updateErrorMessage(); - return control; - } - - - protected Control createDialogArea(Composite parent) { - Composite dialogArea = (Composite) super.createDialogArea(parent); - PlatformUI.getWorkbench().getHelpSystem().setHelp(dialogArea, XMLCommonUIContextIds.XCUI_ATTRIBUTE_DIALOG); - - Composite composite = new Composite(dialogArea, SWT.NONE); - GridLayout layout = new GridLayout(); - layout.numColumns = 2; - layout.marginWidth = 0; - composite.setLayout(layout); - - // - // Style convenience constants - composite.setLayoutData(new GridData(GridData.FILL_BOTH)); - - Label attributeNameLabel = new Label(composite, SWT.NONE); - attributeNameLabel.setText(XMLUIMessages._UI_LABEL_NAME_COLON); - - attributeNameField = new Text(composite, SWT.SINGLE | SWT.BORDER); - GridData gd = new GridData(GridData.FILL_HORIZONTAL); - gd.widthHint = 300; - attributeNameField.setLayoutData(gd); - attributeNameField.setText(getDisplayValue(attribute != null ? attribute.getName() : "")); //$NON-NLS-1$ - attributeNameField.addModifyListener(this); - - Label attributeValueLabel = new Label(composite, SWT.NONE); - attributeValueLabel.setText(XMLUIMessages._UI_LABEL_VALUE_COLON); - - String value = attribute != null ? attribute.getValue() : ""; //$NON-NLS-1$ - int style = SWT.SINGLE | SWT.BORDER; - if (value.indexOf("\n") != -1) { //$NON-NLS-1$ - style = SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL; - } - - attributeValueField = new Text(composite, style); - gd = new GridData(GridData.FILL_HORIZONTAL); - gd.widthHint = 300; - attributeValueField.setLayoutData(gd); - attributeValueField.setText(getDisplayValue(attribute != null ? attribute.getValue() : "")); //$NON-NLS-1$ - - // error message - errorMessageLabel = new Label(composite, SWT.WRAP); - errorMessageLabel.setText(XMLUIMessages.error_message_goes_here); - gd = new GridData(GridData.FILL_HORIZONTAL); - gd.widthHint = 200; - gd.heightHint = Math.max(30, errorMessageLabel.computeSize(0, 0, false).y * 2); - gd.horizontalSpan = 2; - errorMessageLabel.setLayoutData(gd); - Color color = new Color(errorMessageLabel.getDisplay(), 200, 0, 0); - errorMessageLabel.setForeground(color); - - return dialogArea; - } - - public String getAttributeName() { - return attributeName; - } - - public String getAttributeValue() { - return attributeValue; - } - - protected String getDisplayValue(String string) { - return string != null ? string : ""; //$NON-NLS-1$ - } - - protected String getModelValue(String string) { - String result = null; - if ((string != null) && (string.trim().length() > 0)) { - result = string; - } - return result; - } - - public void modifyText(ModifyEvent e) { - updateErrorMessage(); - } - - protected void updateErrorMessage() { - String errorMessage = null; - String name = attributeNameField.getText().trim(); - if (name.length() > 0) { - Attr matchingAttribute = ownerElement.getAttributeNode(name); - if ((matchingAttribute != null) && (matchingAttribute != attribute)) { - errorMessage = XMLUIMessages._ERROR_XML_ATTRIBUTE_ALREADY_EXISTS; - } - else { - // TODO get checkName from Model - // errorMessage = ValidateHelper.checkXMLName(name); - } - } - else { - errorMessage = ""; //$NON-NLS-1$ - } - - errorMessageLabel.setText(errorMessage != null ? errorMessage : ""); //$NON-NLS-1$ - errorMessageLabel.getParent().layout(); - okButton.setEnabled(errorMessage == null); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/EditDoctypeDialog.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/EditDoctypeDialog.java deleted file mode 100644 index 6e071ba91e..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/EditDoctypeDialog.java +++ /dev/null @@ -1,235 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * David Schneider, david.schneider@unisys.com - [142500] WTP properties pages fonts don't follow Eclipse preferences - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.dialogs; - -import org.eclipse.core.runtime.IPath; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -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.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.util.XMLCommonUIContextIds; -import org.w3c.dom.DocumentType; - -public class EditDoctypeDialog extends Dialog { - protected boolean computeSystemId; - protected String[] doctypeData; - protected boolean errorChecking; - protected Label errorMessageLabel; - protected Button okButton; - protected Button publicIdBrowseButton; - protected Text publicIdField; - protected IPath resourceLocation; - protected Text rootElementNameField; - protected Button systemIdBrowseButton; - protected Text systemIdField; - - public EditDoctypeDialog(Shell parentShell, DocumentType doctype) { - this(parentShell, doctype.getName(), doctype.getPublicId(), doctype.getSystemId()); - } - - public EditDoctypeDialog(Shell parentShell, String name, String publicId, String systemId) { - super(parentShell); - setShellStyle(getShellStyle() | SWT.RESIZE); - doctypeData = new String[3]; - doctypeData[0] = name; - doctypeData[1] = publicId; - doctypeData[2] = systemId; - } - - protected void buttonPressed(int buttonId) { - doctypeData[0] = getModelValue(rootElementNameField.getText()); - doctypeData[1] = getModelValue(publicIdField.getText()); - doctypeData[2] = getModelValue(systemIdField.getText()); - super.buttonPressed(buttonId); - } - - protected void createButtonsForButtonBar(Composite parent) { - okButton = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); - createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); - } - - - protected Control createContents(Composite parent) { - Control control = super.createContents(parent); - updateErrorMessage(); - return control; - } - - protected Control createDialogArea(Composite parent) { - Composite dialogControl = (Composite) super.createDialogArea(parent); - PlatformUI.getWorkbench().getHelpSystem().setHelp(dialogControl, XMLCommonUIContextIds.XCUI_DOCTYPE_DIALOG); - - Composite composite = new Composite(dialogControl, SWT.NONE); - GridLayout layout = new GridLayout(); - layout.numColumns = 3; - layout.marginWidth = 0; - composite.setLayout(layout); - composite.setLayoutData(new GridData(GridData.FILL_BOTH)); - - - ModifyListener modifyListener = new ModifyListener() { - public void modifyText(ModifyEvent e) { - if (e.widget == systemIdField) { - computeSystemId = false; - } - updateErrorMessage(); - } - }; - - // row 1 - // - Label rootElementNameLabel = new Label(composite, SWT.NONE); - rootElementNameLabel.setText(XMLUIMessages._UI_LABEL_ROOT_ELEMENT_NAME_COLON); - - rootElementNameField = new Text(composite, SWT.SINGLE | SWT.BORDER); - PlatformUI.getWorkbench().getHelpSystem().setHelp(rootElementNameField, XMLCommonUIContextIds.XCUI_DOCTYPE_ROOT); - GridData gd = new GridData(GridData.FILL_HORIZONTAL); - gd.widthHint = 200; - rootElementNameField.setLayoutData(gd); - rootElementNameField.setText(getDisplayValue(doctypeData[0])); - rootElementNameField.addModifyListener(modifyListener); - - Label placeHolder = new Label(composite, SWT.NONE); - placeHolder.setLayoutData(new GridData()); - - // row 2 - // - Label publicIdLabel = new Label(composite, SWT.NONE); - publicIdLabel.setText(XMLUIMessages._UI_LABEL_PUBLIC_ID_COLON); - - publicIdField = new Text(composite, SWT.SINGLE | SWT.BORDER); - PlatformUI.getWorkbench().getHelpSystem().setHelp(publicIdField, XMLCommonUIContextIds.XCUI_DOCTYPE_PUBLIC); - publicIdField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - publicIdField.setText(getDisplayValue(doctypeData[1])); - - SelectionListener selectionListener = new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - EditEntityHelper helper = new EditEntityHelper(); - if (e.widget == publicIdBrowseButton) { - helper.performBrowseForPublicId(getShell(), publicIdField, computeSystemId ? systemIdField : null); - } - else if (e.widget == systemIdBrowseButton) { - helper.performBrowseForSystemId(getShell(), systemIdField, resourceLocation); - } - } - }; - - publicIdBrowseButton = new Button(composite, SWT.NONE); - publicIdBrowseButton.setText(XMLUIMessages._UI_LABEL_BROWSE); - publicIdBrowseButton.addSelectionListener(selectionListener); - - // row 3 - Label systemIdLabel = new Label(composite, SWT.NONE); - systemIdLabel.setText(XMLUIMessages._UI_LABEL_SYSTEM_ID_COLON); - - systemIdField = new Text(composite, SWT.SINGLE | SWT.BORDER); - PlatformUI.getWorkbench().getHelpSystem().setHelp(systemIdField, XMLCommonUIContextIds.XCUI_DOCTYPE_SYSTEM); - systemIdField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - systemIdField.setText(getDisplayValue(doctypeData[2])); - systemIdField.addModifyListener(modifyListener); - - - systemIdBrowseButton = new Button(composite, SWT.NONE); - systemIdBrowseButton.setText(XMLUIMessages._UI_LABEL_BROWSE); - systemIdBrowseButton.addSelectionListener(selectionListener); - - // error message - errorMessageLabel = new Label(dialogControl, SWT.NONE); - errorMessageLabel.setText(""); //$NON-NLS-1$ - errorMessageLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - Color color = new Color(errorMessageLabel.getDisplay(), 200, 0, 0); - errorMessageLabel.setForeground(color); - - Dialog.applyDialogFont(parent); - return dialogControl; - } - - - protected Label createMessageArea(Composite composite) { - Label label = new Label(composite, SWT.NONE); - // label.setText(message); - return label; - } - - - protected String getDisplayValue(String string) { - return string != null ? string : ""; //$NON-NLS-1$ - } - - public boolean getErrorChecking() { - return errorChecking; - } - - - protected String getModelValue(String string) { - String result = null; - if ((string != null) && (string.trim().length() > 0)) { - result = string; - } - return result; - } - - public String getName() { - return doctypeData[0]; - } - - public String getPublicId() { - return doctypeData[1]; - } - - public String getSystemId() { - return doctypeData[2]; - } - - public void setComputeSystemId(boolean computeSystemId) { - this.computeSystemId = computeSystemId; - } - - public void setErrorChecking(boolean errorChecking) { - this.errorChecking = errorChecking; - } - - public void setResourceLocation(IPath path) { - resourceLocation = path; - } - - public void updateErrorMessage() { - if (errorChecking) { - String errorMessage = null; - if (getModelValue(systemIdField.getText()) == null) { - errorMessage = XMLUIMessages._UI_WARNING_SYSTEM_ID_MUST_BE_SPECIFIED; - } - else if (getModelValue(rootElementNameField.getText()) == null) { - errorMessage = XMLUIMessages._UI_WARNING_ROOT_ELEMENT_MUST_BE_SPECIFIED; - } - - errorMessageLabel.setText(errorMessage != null ? errorMessage : ""); //$NON-NLS-1$ - okButton.setEnabled(errorMessage == null); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/EditElementDialog.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/EditElementDialog.java deleted file mode 100644 index adad3814f2..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/EditElementDialog.java +++ /dev/null @@ -1,141 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.dialogs; - -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -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.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.xml.core.internal.provisional.NameValidator; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.util.XMLCommonUIContextIds; -import org.w3c.dom.Element; - -public class EditElementDialog extends Dialog implements ModifyListener { - protected Element element; - protected String elementName; - protected Text elementNameField; - protected Label errorMessageLabel; - protected Button okButton; - - public EditElementDialog(Shell parentShell, Element element) { - super(parentShell); - setShellStyle(getShellStyle() | SWT.RESIZE); - this.element = element; - } - - protected void buttonPressed(int buttonId) { - if (buttonId == IDialogConstants.OK_ID) { - elementName = getModelValue(elementNameField.getText()); - } - super.buttonPressed(buttonId); - } - - - protected void createButtonsForButtonBar(Composite parent) { - okButton = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); - createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); - } - - protected Control createContents(Composite parent) { - Control control = super.createContents(parent); - elementNameField.forceFocus(); - elementNameField.selectAll(); - updateErrorMessage(); - return control; - } - - - protected Control createDialogArea(Composite parent) { - Composite dialogArea = (Composite) super.createDialogArea(parent); - PlatformUI.getWorkbench().getHelpSystem().setHelp(dialogArea, XMLCommonUIContextIds.XCUI_ELEMENT_DIALOG); - - Composite composite = new Composite(dialogArea, SWT.NONE); - GridLayout layout = new GridLayout(); - layout.numColumns = 2; - layout.marginWidth = 0; - composite.setLayout(layout); - composite.setLayoutData(new GridData(GridData.FILL_BOTH)); - - Label elementNameLabel = new Label(composite, SWT.NONE); - elementNameLabel.setText(XMLUIMessages._UI_LABEL_ELEMENT_NAME); - - elementNameField = new Text(composite, SWT.SINGLE | SWT.BORDER); - GridData gd = new GridData(GridData.FILL_HORIZONTAL); - gd.widthHint = 200; - elementNameField.setLayoutData(gd); - elementNameField.setText(getDisplayValue(element != null ? element.getNodeName() : "")); //$NON-NLS-1$ - elementNameField.addModifyListener(this); - - // error message - errorMessageLabel = new Label(composite, SWT.NONE); - errorMessageLabel.setText(XMLUIMessages.error_message_goes_here); - gd = new GridData(GridData.FILL_HORIZONTAL); - gd.horizontalSpan = 2; - errorMessageLabel.setLayoutData(gd); - Color color = new Color(errorMessageLabel.getDisplay(), 200, 0, 0); - errorMessageLabel.setForeground(color); - - return dialogArea; - } - - protected String getDisplayValue(String string) { - return string != null ? string : ""; //$NON-NLS-1$ - } - - public String getElementName() { - return elementName; - } - - protected String getModelValue(String string) { - String result = null; - if ((string != null) && (string.trim().length() > 0)) { - result = string; - } - return result; - } - - public void modifyText(ModifyEvent e) { - updateErrorMessage(); - } - - protected void updateErrorMessage() { - String errorMessage = null; - String name = elementNameField.getText(); - // String name = elementNameField.getText().trim(); - if (name.length() > 0) { - // TODO use checkName from model level - // errorMessage = ValidateHelper.checkXMLName(name); - if (!NameValidator.isValid(name)) { - errorMessage = XMLUIMessages._UI_INVALID_NAME; - } - } - else { - errorMessage = ""; //$NON-NLS-1$ - } - - errorMessageLabel.setText(errorMessage != null ? errorMessage : ""); //$NON-NLS-1$ - okButton.setEnabled(errorMessage == null); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/EditEntityHelper.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/EditEntityHelper.java deleted file mode 100644 index 25eb64dc55..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/EditEntityHelper.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.dialogs; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.IPath; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; -import org.eclipse.wst.common.uriresolver.internal.util.URIHelper; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; - -public class EditEntityHelper { - - public void performBrowseForPublicId(Shell parentShell, Text publicIdField) { - performBrowseForPublicId(parentShell, publicIdField, null); - } - - public void performBrowseForPublicId(Shell parentShell, Text publicIdField, Text systemIdField) { - String[] extensions = {"dtd", "txt"}; //$NON-NLS-1$ //$NON-NLS-2$ - SelectXMLCatalogIdDialog dialog = new SelectXMLCatalogIdDialog(parentShell, extensions); - dialog.create(); - dialog.getShell().setText(XMLUIMessages._UI_LABEL_SELECT_XML_CATALOG_ENTRY); - dialog.setBlockOnOpen(true); - dialog.open(); - if (dialog.getReturnCode() == Window.OK) { - String id = dialog.getId(); - if (id != null) { - publicIdField.setText(id); - if ((systemIdField != null) && (dialog.getSystemId() != null)) { - systemIdField.setText(dialog.getSystemId()); - } - } - } - } - - public void performBrowseForSystemId(Shell parentShell, Text systemIdField, IPath resourceLocation) { - String[] extensions = {"dtd"}; //$NON-NLS-1$ - SelectFileOrXMLCatalogIdDialog dialog = new SelectFileOrXMLCatalogIdDialog(parentShell, extensions, ICatalogEntry.ENTRY_TYPE_SYSTEM); - dialog.create(); - dialog.getShell().setText(XMLUIMessages._UI_LABEL_SPECIFY_SYSTEM_ID); - dialog.setBlockOnOpen(true); - dialog.open(); - if (dialog.getReturnCode() == Window.OK) { - String id = dialog.getId(); - IFile file = dialog.getFile(); - if (id != null) { - systemIdField.setText(id); - } - else if (file != null) { - String uri = null; - if (resourceLocation != null) { - uri = URIHelper.getRelativeURI(file.getLocation(), resourceLocation); - } - else { - uri = file.getLocation().toOSString(); - } - systemIdField.setText(uri); - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/EditNamespaceInfoDialog.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/EditNamespaceInfoDialog.java deleted file mode 100644 index 844ac60e03..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/EditNamespaceInfoDialog.java +++ /dev/null @@ -1,274 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.dialogs; - -import java.util.List; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IPath; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -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.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver; -import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolverPlugin; -import org.eclipse.wst.common.uriresolver.internal.util.URIHelper; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.ContentModelManager; -import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.util.XMLCommonUIContextIds; - -public class EditNamespaceInfoDialog extends Dialog { - - public static EditNamespaceInfoDialog invokeDialog(Shell shell, String title, NamespaceInfo info, IPath resourceLocation) { - EditNamespaceInfoDialog dialog = new EditNamespaceInfoDialog(shell, info); - dialog.create(); - dialog.getShell().setText(title); - dialog.setBlockOnOpen(true); - dialog.setResourceLocation(resourceLocation); - dialog.open(); - return dialog; - } - - protected Button browseButton; - protected String errorMessage; - - protected Label errorMessageLabel; - protected NamespaceInfo fInfo; - protected Text locationHintField; - - protected Button okButton; - protected Text prefixField; - protected IPath resourceLocation; - protected Text uriField; - - public EditNamespaceInfoDialog(Shell parentShell, NamespaceInfo info) { - super(parentShell); - setShellStyle(getShellStyle() | SWT.RESIZE); - this.fInfo = info; - } - - protected void buttonPressed(int buttonId) { - if (buttonId == IDialogConstants.OK_ID) { - fInfo.uri = uriField.getText(); - fInfo.prefix = prefixField.getText(); - fInfo.locationHint = locationHintField.getText(); - } - super.buttonPressed(buttonId); - } - - protected void computeErrorMessage() { - errorMessage = null; - } - - protected void createButtonsForButtonBar(Composite parent) { - okButton = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); - okButton.setEnabled(false); - createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); - updateWidgets(); - } - - protected Control createDialogArea(Composite parent) { - Composite dialogsubArea = (Composite) super.createDialogArea(parent); - PlatformUI.getWorkbench().getHelpSystem().setHelp(dialogsubArea, XMLCommonUIContextIds.XCUI_NAMESPACE_DIALOG); - - Composite composite = new Composite(dialogsubArea, SWT.NONE); - GridLayout layout = new GridLayout(); - layout.numColumns = 3; - layout.marginWidth = 0; - composite.setLayout(layout); - - GridData gd = new GridData(GridData.FILL_HORIZONTAL); - gd.widthHint = 350; - composite.setLayoutData(gd); - - ModifyListener modifyListener = new ModifyListener() { - public void modifyText(ModifyEvent e) { - updateWidgets(); - } - }; - - - // row 1 - // - Label uriLabel = new Label(composite, SWT.NONE); - uriLabel.setText(XMLUIMessages._UI_LABEL_NAMESPACE_NAME_COLON); - - uriField = new Text(composite, SWT.SINGLE | SWT.BORDER); - gd = new GridData(GridData.FILL_HORIZONTAL); - gd.grabExcessHorizontalSpace = true; - uriField.setLayoutData(gd); - uriField.setText(getDisplayValue(fInfo.uri)); - uriField.addModifyListener(modifyListener); - uriField.setEnabled(fInfo.getProperty("uri-readOnly") == null); //$NON-NLS-1$ - - // never read - Label placeHolder1 = new Label(composite, SWT.NONE); - placeHolder1.setText(""); //$NON-NLS-1$ - - // row 2 - // - Label prefixLabel = new Label(composite, SWT.NONE); - prefixLabel.setText(XMLUIMessages._UI_LABEL_PREFIX_COLON); - - prefixField = new Text(composite, SWT.SINGLE | SWT.BORDER); - gd = new GridData(GridData.FILL_HORIZONTAL); - gd.grabExcessHorizontalSpace = true; - prefixField.setLayoutData(gd); - prefixField.setText(getDisplayValue(fInfo.prefix)); - prefixField.addModifyListener(modifyListener); - prefixField.setEnabled(fInfo.getProperty("prefix-readOnly") == null); //$NON-NLS-1$ - - // never read - Label placeHolder2 = new Label(composite, SWT.NONE); - placeHolder2.setText(""); //$NON-NLS-1$ - - // row 3 - // - Label locationHintLabel = new Label(composite, SWT.NONE); - locationHintLabel.setText(XMLUIMessages._UI_LABEL_LOCATION_HINT_COLON); - - locationHintField = new Text(composite, SWT.SINGLE | SWT.BORDER); - gd = new GridData(GridData.FILL_HORIZONTAL); - gd.grabExcessHorizontalSpace = true; - locationHintField.setLayoutData(gd); - locationHintField.setText(getDisplayValue(fInfo.locationHint)); - locationHintField.addModifyListener(modifyListener); - locationHintField.setEnabled(fInfo.getProperty("locationHint-readOnly") == null); //$NON-NLS-1$ - - SelectionListener selectionListener = new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - performBrowse(); - } - }; - - browseButton = new Button(composite, SWT.NONE); - browseButton.setText(XMLUIMessages._UI_LABEL_BROWSE); - browseButton.addSelectionListener(selectionListener); - browseButton.setEnabled(locationHintField.getEnabled()); - - // error message - errorMessageLabel = new Label(dialogsubArea, SWT.NONE); - errorMessageLabel.setText(XMLUIMessages.error_message_goes_here); - errorMessageLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - Color color = new Color(errorMessageLabel.getDisplay(), 200, 0, 0); - errorMessageLabel.setForeground(color); - - return dialogsubArea; - } - - protected String getDisplayValue(String string) { - return string != null ? string : ""; //$NON-NLS-1$ - } - - protected void performBrowse() { - String[] extensions = {".xsd"}; //$NON-NLS-1$ - SelectFileOrXMLCatalogIdDialog dialog = new SelectFileOrXMLCatalogIdDialog(getShell(), extensions); - dialog.create(); - dialog.getShell().setText(XMLUIMessages._UI_LABEL_SELECT_FILE); - dialog.setBlockOnOpen(true); - dialog.open(); - - if (dialog.getReturnCode() == Window.OK) { - String grammarURI = null; - IFile file = dialog.getFile(); - String id = dialog.getId(); - if (file != null) { - String uri = null; - if (resourceLocation != null) { - IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(resourceLocation); - if (resource != null) { - IPath location = resource.getLocation(); - if (location != null) { - uri = URIHelper.getRelativeURI(file.getLocation(), location); - } - } - else { - uri = URIHelper.getRelativeURI(file.getLocation(), resourceLocation); - } - grammarURI = file.getLocation().toOSString(); - } - else { - uri = file.getLocation().toOSString(); - grammarURI = uri; - } - locationHintField.setText(uri); - } - else if (id != null) { - locationHintField.setText(id); - URIResolver resolver = URIResolverPlugin.createResolver(); - grammarURI = resolver.resolve(null, id, id); - } - - - CMDocument document = ContentModelManager.getInstance().createCMDocument(URIHelper.getURIForFilePath(grammarURI), "xsd"); //$NON-NLS-1$ - if(document != null) { - List namespaceInfoList = (List) document.getProperty("http://org.eclipse.wst/cm/properties/namespaceInfo"); //$NON-NLS-1$ - if(namespaceInfoList != null) { - NamespaceInfo info = (NamespaceInfo) namespaceInfoList.get(0); - if(info != null) { - if ((uriField.getText().trim().length() == 0) && (info.uri != null)) { - uriField.setText(info.uri); - } - if ((prefixField.getText().trim().length() == 0) && (info.prefix != null)) { - prefixField.setText(info.prefix); - } - } - } - } - } - } - - public void setResourceLocation(IPath path) { - resourceLocation = path; - } - - protected void updateErrorMessageLabel() { - errorMessageLabel.setText(errorMessage != null ? errorMessage : ""); //$NON-NLS-1$ - } - - protected void updateOKButtonState() { - if (okButton != null) { - if ((uriField.getText().trim().length() == 0) && (prefixField.getText().trim().length() == 0) && (locationHintField.getText().trim().length() == 0)) { - okButton.setEnabled(false); - } - else { - okButton.setEnabled(errorMessage == null); - } - } - } - - protected void updateWidgets() { - computeErrorMessage(); - updateErrorMessageLabel(); - updateOKButtonState(); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/EditProcessingInstructionDialog.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/EditProcessingInstructionDialog.java deleted file mode 100644 index 6742855d8c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/EditProcessingInstructionDialog.java +++ /dev/null @@ -1,116 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.dialogs; - -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.util.XMLCommonUIContextIds; -import org.w3c.dom.ProcessingInstruction; - -public class EditProcessingInstructionDialog extends Dialog { - protected String data; - protected Text dataField; - protected String target; - protected Text targetField; - - public EditProcessingInstructionDialog(Shell parentShell, ProcessingInstruction pi) { - this(parentShell, pi.getTarget(), pi.getData()); - } - - public EditProcessingInstructionDialog(Shell parentShell, String target, String data) { - super(parentShell); - setShellStyle(getShellStyle() | SWT.RESIZE); - this.target = target; - this.data = data; - } - - protected void buttonPressed(int buttonId) { - target = getModelValue(targetField.getText()); - data = getModelValue(dataField.getText()); - super.buttonPressed(buttonId); - } - - protected void createButtonsForButtonBar(Composite parent) { - createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); - createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); - } - - protected Control createDialogArea(Composite parent) { - Composite dialogArea1 = (Composite) super.createDialogArea(parent); - PlatformUI.getWorkbench().getHelpSystem().setHelp(dialogArea1, XMLCommonUIContextIds.XCUI_PROCESSING_DIALOG); - - Composite composite = new Composite(dialogArea1, SWT.NONE); - GridLayout layout = new GridLayout(); - layout.numColumns = 2; - layout.marginWidth = 0; - composite.setLayout(layout); - composite.setLayoutData(new GridData(GridData.FILL_BOTH)); - - - GridData gd = new GridData(GridData.FILL_HORIZONTAL); - gd.widthHint = 250; - - Label targetLabel = new Label(composite, SWT.NONE); - targetLabel.setText(XMLUIMessages._UI_LABEL_TARGET_COLON); - - targetField = new Text(composite, SWT.SINGLE | SWT.BORDER); - targetField.setLayoutData(gd); - targetField.setText(getDisplayValue(target)); - - Label dataLabel = new Label(composite, SWT.NONE); - dataLabel.setText(XMLUIMessages._UI_LABEL_DATA_COLON); - - dataField = new Text(composite, SWT.SINGLE | SWT.BORDER); - dataField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - dataField.setText(getDisplayValue(data)); - - return dialogArea1; - } - - protected Label createMessageArea(Composite composite) { - Label label = new Label(composite, SWT.NONE); - // label.setText(message); - return label; - } - - public String getData() { - return data; - } - - protected String getDisplayValue(String string) { - return string != null ? string : ""; //$NON-NLS-1$ - } - - protected String getModelValue(String string) { - String result = null; - if ((string != null) && (string.trim().length() > 0)) { - result = string; - } - return result; - } - - - public String getTarget() { - return target; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/EditSchemaInfoDialog.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/EditSchemaInfoDialog.java deleted file mode 100644 index d4458097d8..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/EditSchemaInfoDialog.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.dialogs; - -import java.util.List; - -import org.eclipse.core.runtime.IPath; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.nsedit.CommonEditNamespacesDialog; -import org.eclipse.wst.xml.ui.internal.util.XMLCommonUIContextIds; - -public class EditSchemaInfoDialog extends Dialog implements UpdateListener { - // protected NamespaceInfoTable namespaceInfoTable; - protected Label errorMessageLabel; - protected List namespaceInfoList; - protected IPath resourceLocation; - - public EditSchemaInfoDialog(Shell parentShell, IPath resourceLocation) { - super(parentShell); - setShellStyle(getShellStyle() | SWT.RESIZE); - this.resourceLocation = resourceLocation; - } - - protected void createButtonsForButtonBar(Composite parent) { - createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); - createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); - } - - protected Control createDialogArea(Composite parent) { - Composite dialogArea = (Composite) super.createDialogArea(parent); - PlatformUI.getWorkbench().getHelpSystem().setHelp(dialogArea, XMLCommonUIContextIds.XCUI_SCHEMA_INFO_DIALOG); - - CommonEditNamespacesDialog editNamespacesControl = new CommonEditNamespacesDialog(dialogArea, resourceLocation, XMLUIMessages._UI_NAMESPACE_DECLARATIONS, false, true); - editNamespacesControl.setNamespaceInfoList(namespaceInfoList); - - editNamespacesControl.updateErrorMessage(namespaceInfoList); - - return dialogArea; - } - - protected Control getDialogArea(Composite parent) { - return super.createDialogArea(parent); - } - - public List getNamespaceInfoList() { - return namespaceInfoList; - } - - public void setNamespaceInfoList(List list) { - namespaceInfoList = list; - } - - public void updateErrorMessage(List namespaceInfoList) { - NamespaceInfoErrorHelper helper = new NamespaceInfoErrorHelper(); - String errorMessage = helper.computeErrorMessage(namespaceInfoList, null); - errorMessageLabel.setText(errorMessage != null ? errorMessage : ""); //$NON-NLS-1$ - } - - public void updateOccured(Object object, Object arg) { - updateErrorMessage((List) arg); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/NamespaceInfoErrorHelper.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/NamespaceInfoErrorHelper.java deleted file mode 100644 index 540df93305..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/NamespaceInfoErrorHelper.java +++ /dev/null @@ -1,104 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.dialogs; - -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver; -import org.eclipse.wst.common.uriresolver.internal.util.URIHelper; -import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMNamespaceInfoManager; -import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; - -public class NamespaceInfoErrorHelper { - - protected List errorList; - - public NamespaceInfoErrorHelper() { - } - - public String computeErrorMessage(List namespaceInfoList, URIResolver idResolver) { - String result = null; - Hashtable prefixTable = new Hashtable(); - Hashtable uriTable = new Hashtable(); - for (Iterator iterator = namespaceInfoList.iterator(); iterator.hasNext();) { - NamespaceInfo nsInfo = (NamespaceInfo) iterator.next(); - nsInfo.normalize(); - - String urikey = nsInfo.uri != null ? nsInfo.uri : ""; //$NON-NLS-1$ - NamespaceInfo nsInfo2 = null; - if ((nsInfo2 = (NamespaceInfo) uriTable.get(urikey)) != null) { - if ((nsInfo.uri != null) && nsInfo.uri.equals(nsInfo2.uri)) { - result = XMLUIMessages._UI_WARNING_MORE_THAN_ONE_NS_WITH_NAME + "'" + nsInfo.uri + "'"; //$NON-NLS-1$ //$NON-NLS-2$ - } - else { - result = XMLUIMessages._UI_WARNING_MORE_THAN_ONE_NS_WITHOUT_NAME; - } - break; - } - else { - uriTable.put(urikey, nsInfo); - } - - if (nsInfo.uri != null) { - String key = nsInfo.prefix != null ? nsInfo.prefix : ""; //$NON-NLS-1$ - if (prefixTable.get(key) != null) { - if (nsInfo.prefix != null) { - result = XMLUIMessages._UI_WARNING_MORE_THAN_ONE_NS_WITH_PREFIX + "'" + nsInfo.prefix + "'"; //$NON-NLS-1$ //$NON-NLS-2$ - break; - } - else { - result = XMLUIMessages._UI_WARNING_MORE_THAN_ONE_NS_WITHOUT_PREFIX; - break; - } - } - else { - prefixTable.put(key, nsInfo); - } - - if ((nsInfo.locationHint != null) && (idResolver != null)) { - String grammarURI = idResolver.resolve(null, nsInfo.locationHint, nsInfo.locationHint); - if (!URIHelper.isReadableURI(grammarURI, false)) { - result = XMLUIMessages._UI_WARNING_SCHEMA_CAN_NOT_BE_LOCATED + " '" + nsInfo.locationHint + "'"; //$NON-NLS-1$ //$NON-NLS-2$ - break; - } - } - if ((idResolver != null) && (nsInfo.locationHint == null) && !nsInfo.uri.equals(DOMNamespaceInfoManager.XSI_URI)) { - result = XMLUIMessages._UI_WARNING_LOCATION_HINT_NOT_SPECIFIED + " '" + nsInfo.uri + "'"; //$NON-NLS-1$ //$NON-NLS-2$ - break; - } - } - else { - if (nsInfo.prefix != null) { - result = XMLUIMessages._UI_WARNING_NAMESPACE_NAME_NOT_SPECIFIED + " '" + nsInfo.prefix + "'"; //$NON-NLS-1$ //$NON-NLS-2$ - break; - } - } - } - // additional tests - if (result == null) { - for (Iterator iterator = namespaceInfoList.iterator(); iterator.hasNext();) { - NamespaceInfo nsInfo = (NamespaceInfo) iterator.next(); - nsInfo.normalize(); - if ((nsInfo.uri != null) && nsInfo.isPrefixRequired && (nsInfo.prefix == null)) { - result = XMLUIMessages._UI_WARNING_PREFIX_NOT_SPECIFIED + " '" + nsInfo.uri + "'"; //$NON-NLS-1$ //$NON-NLS-2$ - break; - } - } - } - - return result; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/NamespaceInfoTable.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/NamespaceInfoTable.java deleted file mode 100644 index 8a438dce85..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/NamespaceInfoTable.java +++ /dev/null @@ -1,398 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.dialogs; - -import java.util.List; -import java.util.Vector; - -import org.eclipse.core.runtime.IPath; -import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.ColumnWeightData; -import org.eclipse.jface.viewers.ILabelProviderListener; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TableLayout; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.TextCellEditor; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.MouseAdapter; -import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; -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.wst.xml.core.internal.contentmodel.util.NamespaceInfo; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; - -public class NamespaceInfoTable extends Composite { - - /** - * NamespaceInfoTableLabelProvider - */ - protected class NamespaceInfoTableLabelProvider implements ITableLabelProvider, IStructuredContentProvider { - - public void addListener(ILabelProviderListener listener) { - } - - public void dispose() { - } - - public Image getColumnImage(Object object, int columnIndex) { - return null; - } - - public String getColumnText(Object object, int column) { - NamespaceInfo info = (NamespaceInfo) object; - String result = null; - switch (column) { - case 0 : { - result = info.uri; - break; - } - case 1 : { - result = info.prefix; - break; - } - case 2 : { - result = info.locationHint; - break; - } - } - result = result != null ? result : ""; //$NON-NLS-1$ - if (result.equals("")) { //$NON-NLS-1$ - switch (column) { - case 0 : { - result = XMLUIMessages._UI_NO_NAMESPACE_NAME; - break; - } - case 1 : { - result = XMLUIMessages._UI_NO_PREFIX; - break; - } - } - } - return result; - } - - String getDefaultPrefix() { - String defaultPrefix = "p"; //$NON-NLS-1$ - if (namespaceInfoList == null) { - return defaultPrefix; - } - Vector v = new Vector(); - for (int i = 0; i < namespaceInfoList.size(); i++) { - NamespaceInfo nsinfo = (NamespaceInfo) namespaceInfoList.get(i); - if (nsinfo.prefix != null) { - v.addElement(nsinfo.prefix); - } - } - if (v.contains(defaultPrefix)) { - String s = defaultPrefix; - for (int j = 0; v.contains(s); j++) { - s = defaultPrefix + Integer.toString(j); - } - return s; - } - else { - return defaultPrefix; - } - } - - public Object[] getElements(Object inputElement) { - return namespaceInfoList.toArray(); - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - - public boolean isDeleted(Object element) { - return false; - } - - public boolean isLabelProperty(Object object, Object property) { - return false; - } - - public boolean isLabelProperty(Object element, String property) { - return false; - } - - public void removeListener(ILabelProviderListener listener) { - } - } - - protected static final String LOCATION_HINT = XMLUIMessages._UI_LABEL_LOCATION_HINT; - protected static final String NAMESPACE_URI = XMLUIMessages._UI_LABEL_NAMESPACE_NAME; - protected static final String PREFIX = XMLUIMessages._UI_LABEL_PREFIX; - protected Button deleteButton; - protected boolean dummyRowsRemoved = false; - protected Button editButton; - protected List namespaceInfoList = new Vector(); - protected Button newButton; - protected NamespaceInfoTableLabelProvider provider; - protected IPath resourceLocation; - protected TableViewer tableViewer; - protected UpdateListener updateListener; - protected int visibleRows = -1; - - public NamespaceInfoTable(Composite parent) { - this(parent, -1, -1, -1); - } - - public NamespaceInfoTable(Composite parent, int visibleRows) { - this(parent, -1, -1, visibleRows); - } - - public NamespaceInfoTable(Composite parent, int widthHint, int heightHint) { - this(parent, widthHint, heightHint, -1); - } - - public NamespaceInfoTable(Composite parent, int widthHint, int heightHint, int visibleRows) { - super(parent, SWT.NONE); - setLayout(createGridLayout()); - setLayoutData(new GridData(GridData.FILL_BOTH)); - Group namespaceInfoGroup = new Group(this, SWT.NONE); - namespaceInfoGroup.setText(XMLUIMessages._UI_LABEL_XML_SCHEMA_INFORMATION); - namespaceInfoGroup.setLayout(new GridLayout()); - GridData gd = new GridData(GridData.FILL_BOTH); - if (widthHint != -1) { - gd.widthHint = widthHint; - } - if (heightHint != -1) { - gd.heightHint = heightHint; - } - namespaceInfoGroup.setLayoutData(gd); - // WorkbenchHelp.setHelp(namespaceInfoGroup, new - // ControlContextComputer(namespaceInfoGroup, - // XMLBuilderContextIds.XMLC_NAMESPACE_GROUP)); - String[] titleArray = {NAMESPACE_URI, PREFIX, LOCATION_HINT}; - tableViewer = new TableViewer(namespaceInfoGroup, SWT.FULL_SELECTION); - provider = new NamespaceInfoTableLabelProvider(); - tableViewer.setContentProvider(provider); - tableViewer.setLabelProvider(provider); - tableViewer.setColumnProperties(titleArray); - Table table = tableViewer.getTable(); - table.setHeaderVisible(true); - table.setLayoutData(new GridData(GridData.FILL_BOTH)); - int[] widthArray = {50, 20, 30}; - TableLayout layout = new TableLayout(); - for (int i = 0; i < titleArray.length; i++) { - TableColumn column = new TableColumn(table, i); - column.setText(titleArray[i]); - column.setAlignment(SWT.LEFT); - layout.addColumnData(new ColumnWeightData(widthArray[i], true)); - } - this.visibleRows = visibleRows; - for (int i = 0; i < visibleRows; i++) { - TableItem item = new TableItem(table, SWT.NONE); - item.setText("#######"); //$NON-NLS-1$ - } - table.setLayout(layout); - CellEditor[] cellEditors = new CellEditor[titleArray.length]; - cellEditors[1] = new TextCellEditor(table); - cellEditors[2] = new TextCellEditor(table); - tableViewer.setCellEditors(cellEditors); - MouseAdapter mouseAdapter = new MouseAdapter() { - public void mouseDoubleClick(MouseEvent e) { - if (tableViewer.getTable().getItem(new Point(e.x, e.y)) != null) { - performEdit(); - } - } - }; - table.addMouseListener(mouseAdapter); - createButtons(namespaceInfoGroup); - ISelectionChangedListener selectionChangedListener = new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - updateButtonEnabledState(); - } - }; - tableViewer.addSelectionChangedListener(selectionChangedListener); - } - - protected void createButtons(Composite parent) { - Composite composite = new Composite(parent, SWT.NONE); - composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - GridLayout gridLayout = new GridLayout(); - gridLayout.numColumns = 2; - gridLayout.marginHeight = 0; - gridLayout.marginWidth = 0; - composite.setLayout(gridLayout); - Button hiddenButton = new Button(composite, SWT.NONE); - hiddenButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - hiddenButton.setVisible(false); - hiddenButton.setEnabled(false); - SelectionListener selectionListener = new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - if (e.widget == newButton) { - performNew(); - } - else if (e.widget == editButton) { - performEdit(); - } - else if (e.widget == deleteButton) { - performDelete(); - } - } - }; - // create a composite to hold the three buttons - Composite buttonComposite = new Composite(composite, SWT.NONE); - buttonComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - GridLayout buttonGridLayout = new GridLayout(); - buttonGridLayout.numColumns = 3; - buttonGridLayout.makeColumnsEqualWidth = true; - buttonComposite.setLayout(buttonGridLayout); - // add the New button - // - newButton = new Button(buttonComposite, SWT.NONE); - newButton.setText(XMLUIMessages._UI_BUTTON_NEW); - newButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - newButton.addSelectionListener(selectionListener); - // add the Edit button - // - editButton = new Button(buttonComposite, SWT.NONE); - editButton.setText(XMLUIMessages._UI_BUTTON_EDIT); - editButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - editButton.addSelectionListener(selectionListener); - // add the Delete button - // - deleteButton = new Button(buttonComposite, SWT.NONE); - deleteButton.setText(XMLUIMessages._UI_BUTTON_DELETE); - deleteButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - deleteButton.addSelectionListener(selectionListener); - } - - public GridLayout createGridLayout() { - GridLayout gridLayout = new GridLayout(); - gridLayout.marginWidth = 0; - gridLayout.horizontalSpacing = 0; - return gridLayout; - } - - public List getNamespaceInfoList() { - return namespaceInfoList; - } - - protected NamespaceInfo getTargetNamespaceInfo() { - return ((namespaceInfoList != null) && (namespaceInfoList.size() > 0)) ? (NamespaceInfo) namespaceInfoList.get(0) : null; - } - - protected EditNamespaceInfoDialog invokeDialog(String title, NamespaceInfo info) { - Shell shell = XMLUIPlugin.getInstance().getWorkbench().getActiveWorkbenchWindow().getShell(); - EditNamespaceInfoDialog dialog = new EditNamespaceInfoDialog(shell, info); - dialog.create(); - dialog.getShell().setText(title); - dialog.setBlockOnOpen(true); - dialog.setResourceLocation(resourceLocation); - dialog.open(); - return dialog; - } - - protected void performDelayedUpdate() { - Runnable delayedUpdate = new Runnable() { - public void run() { - update(); - } - }; - getDisplay().asyncExec(delayedUpdate); - if (updateListener != null) { - updateListener.updateOccured(this, namespaceInfoList); - } - } - - public void performDelete() { - ISelection selection = tableViewer.getSelection(); - Object selectedObject = (selection instanceof IStructuredSelection) ? ((IStructuredSelection) selection).getFirstElement() : null; - if (selectedObject != null) { - namespaceInfoList.remove(selectedObject); - performDelayedUpdate(); - } - } - - public void performEdit() { - ISelection selection = tableViewer.getSelection(); - Object selectedObject = (selection instanceof IStructuredSelection) ? ((IStructuredSelection) selection).getFirstElement() : null; - if (selectedObject instanceof NamespaceInfo) { - invokeDialog(XMLUIMessages._UI_LABEL_NEW_NAMESPACE_INFORMATION, (NamespaceInfo) selectedObject); - performDelayedUpdate(); - } - } - - public void performNew() { - NamespaceInfo info = new NamespaceInfo(); - EditNamespaceInfoDialog dialog = invokeDialog(XMLUIMessages._UI_LABEL_NEW_NAMESPACE_INFORMATION, info); - if (dialog.getReturnCode() == Window.OK) { - namespaceInfoList.add(info); - performDelayedUpdate(); - } - } - - public void setNamespaceInfoList(List namespaceInfoList) { - this.namespaceInfoList = namespaceInfoList; - update(); - } - - public void setResourceLocation(IPath resourceLocation) { - this.resourceLocation = resourceLocation; - } - - public void setUpdateListener(UpdateListener updateListener) { - this.updateListener = updateListener; - } - - public void update() { - updateHelper(namespaceInfoList); - } - - public void updateButtonEnabledState() { - ISelection selection = tableViewer.getSelection(); - Object selectedObject = (selection instanceof IStructuredSelection) ? ((IStructuredSelection) selection).getFirstElement() : null; - NamespaceInfo info = (NamespaceInfo) selectedObject; - editButton.setEnabled(info != null); - deleteButton.setEnabled((info != null) && (info.getProperty("unremovable") == null)); //$NON-NLS-1$ - } - - public void updateHelper(List namespaceInfoList) { - if ((visibleRows != -1) && !dummyRowsRemoved) { - dummyRowsRemoved = true; - tableViewer.getTable().removeAll(); - } - ISelection selection = tableViewer.getSelection(); - tableViewer.setInput(namespaceInfoList); - if (selection.isEmpty()) { - if (namespaceInfoList.size() > 0) { - tableViewer.setSelection(new StructuredSelection(namespaceInfoList.get(0))); - } - } - else { - tableViewer.setSelection(selection); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/SelectFileOrXMLCatalogIdDialog.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/SelectFileOrXMLCatalogIdDialog.java deleted file mode 100644 index d36cf7bc65..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/SelectFileOrXMLCatalogIdDialog.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.dialogs; - -import org.eclipse.core.resources.IFile; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Shell; - - -public class SelectFileOrXMLCatalogIdDialog extends Dialog { - protected int catalogEntryType; - protected String[] extensions; - protected IFile file; - protected String id; - protected Button okButton; - protected SelectFileOrXMLCatalogIdPanel panel; - - public SelectFileOrXMLCatalogIdDialog(Shell parentShell, String[] extensions) { - this(parentShell, extensions, 0); - } - - public SelectFileOrXMLCatalogIdDialog(Shell parentShell, String[] extensions, int catalogEntryType) { - super(parentShell); - setShellStyle(getShellStyle() | SWT.RESIZE); - this.extensions = extensions; - this.catalogEntryType = catalogEntryType; - } - - - protected void buttonPressed(int buttonId) { - if (buttonId == IDialogConstants.OK_ID) { - file = panel.getFile(); - id = panel.getXMLCatalogId(); - } - super.buttonPressed(buttonId); - } - - protected void createButtonsForButtonBar(Composite parent) { - okButton = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); - okButton.setEnabled(false); - createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); - } - - protected Control createDialogArea(Composite parent) { - Composite dialogArea = (Composite) super.createDialogArea(parent); - - panel = new SelectFileOrXMLCatalogIdPanel(dialogArea); - panel.setCatalogEntryType(catalogEntryType); - panel.setFilterExtensions(extensions); - panel.setVisibleHelper(true); - SelectFileOrXMLCatalogIdPanel.Listener listener = new SelectFileOrXMLCatalogIdPanel.Listener() { - public void completionStateChanged() { - updateButtonState(); - } - }; - panel.setListener(listener); - - return dialogArea; - } - - public IFile getFile() { - return file; - } - - public String getId() { - return id; - } - - protected void updateButtonState() { - okButton.setEnabled((panel.getFile() != null) || (panel.getXMLCatalogId() != null)); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/SelectFileOrXMLCatalogIdPanel.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/SelectFileOrXMLCatalogIdPanel.java deleted file mode 100644 index 2987b045ca..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/SelectFileOrXMLCatalogIdPanel.java +++ /dev/null @@ -1,184 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * David Schneider, david.schneider@unisys.com - [142500] WTP properties pages fonts don't follow Eclipse preferences - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.dialogs; - -import org.eclipse.core.resources.IFile; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.SelectionChangedEvent; -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.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.ui.part.PageBook; -import org.eclipse.wst.common.ui.internal.viewers.SelectSingleFileView; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; - - -public class SelectFileOrXMLCatalogIdPanel extends Composite implements SelectionListener { - - /** - * TODO: Change the name of this interface; "Listener" is used by SWT. - */ - public interface Listener { - void completionStateChanged(); - } - - protected class MySelectSingleFileView extends SelectSingleFileView implements SelectSingleFileView.Listener { - protected Control control; - - public MySelectSingleFileView(Composite parent) { - super(null, true); - // String[] ext = {".dtd"}; - // addFilterExtensions(ext); - control = createControl(parent); - control.setLayoutData(new GridData(GridData.FILL_BOTH)); - MySelectSingleFileView.this.setListener(this); - } - - public Control getControl() { - return control; - } - - public void setControlComplete(boolean isComplete) { - updateCompletionStateChange(); - } - - public void setVisibleHelper(boolean isVisible) { - super.setVisibleHelper(isVisible); - } - } - - protected Listener listener; - protected PageBook pageBook; - - protected Button[] radioButton; - protected MySelectSingleFileView selectSingleFileView; - protected SelectXMLCatalogIdPanel selectXMLCatalogIdPanel; - - public SelectFileOrXMLCatalogIdPanel(Composite parent) { - super(parent, SWT.NONE); - - // container group - setLayout(new GridLayout()); - GridData gd = new GridData(GridData.FILL_BOTH); - gd.heightHint = 400; - gd.widthHint = 400; - setLayoutData(gd); - - radioButton = new Button[2]; - radioButton[0] = new Button(this, SWT.RADIO); - radioButton[0].setText(XMLUIMessages._UI_RADIO_BUTTON_SELECT_FROM_WORKSPACE); - radioButton[0].setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - radioButton[0].setSelection(true); - radioButton[0].addSelectionListener(this); - - radioButton[1] = new Button(this, SWT.RADIO); - radioButton[1].setText(XMLUIMessages._UI_RADIO_BUTTON_SELECT_FROM_CATALOG); - radioButton[1].setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - radioButton[1].addSelectionListener(this); - - pageBook = new PageBook(this, SWT.NONE); - pageBook.setLayoutData(new GridData(GridData.FILL_BOTH)); - - selectSingleFileView = new MySelectSingleFileView(pageBook); - - ICatalog xmlCatalog = XMLCorePlugin.getDefault().getDefaultXMLCatalog(); - selectXMLCatalogIdPanel = new SelectXMLCatalogIdPanel(pageBook, xmlCatalog); - selectXMLCatalogIdPanel.getTableViewer().addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - updateCompletionStateChange(); - } - }); - Dialog.applyDialogFont(parent); - pageBook.showPage(selectSingleFileView.getControl()); - - } - - public IFile getFile() { - IFile result = null; - if (radioButton[0].getSelection()) { - result = selectSingleFileView.getFile(); - } - return result; - } - - public ICatalogEntry getXMLCatalogEntry() { - ICatalogEntry result = null; - if (radioButton[1].getSelection()) { - result = selectXMLCatalogIdPanel.getXMLCatalogEntry(); - } - return result; - } - - public String getXMLCatalogId() { - String result = null; - if (radioButton[1].getSelection()) { - result = selectXMLCatalogIdPanel.getId(); - } - return result; - } - - public String getXMLCatalogURI() { - String result = null; - if (radioButton[1].getSelection()) { - result = selectXMLCatalogIdPanel.getURI(); - } - return result; - } - - public void setCatalogEntryType(int catalogEntryType) { - selectXMLCatalogIdPanel.setCatalogEntryType(catalogEntryType); - } - - public void setFilterExtensions(String[] filterExtensions) { - selectSingleFileView.resetFilters(); - selectSingleFileView.addFilterExtensions(filterExtensions); - - selectXMLCatalogIdPanel.getTableViewer().setFilterExtensions(filterExtensions); - } - - public void setListener(Listener listener) { - this.listener = listener; - } - - public void setVisibleHelper(boolean isVisible) { - selectSingleFileView.setVisibleHelper(isVisible); - } - - public void updateCompletionStateChange() { - if (listener != null) { - listener.completionStateChanged(); - } - } - - public void widgetDefaultSelected(SelectionEvent e) { - } - - public void widgetSelected(SelectionEvent e) { - if (e.widget == radioButton[0]) { - pageBook.showPage(selectSingleFileView.getControl()); - } - else { - pageBook.showPage(selectXMLCatalogIdPanel); - } - updateCompletionStateChange(); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/SelectXMLCatalogIdDialog.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/SelectXMLCatalogIdDialog.java deleted file mode 100644 index 624c96a89c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/SelectXMLCatalogIdDialog.java +++ /dev/null @@ -1,111 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ - - -package org.eclipse.wst.xml.ui.internal.dialogs; - -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry; -import org.eclipse.wst.xml.ui.internal.util.XMLCommonUIContextIds; - - - -public class SelectXMLCatalogIdDialog extends Dialog { - protected String[] extensions; - protected Button okButton; - protected SelectXMLCatalogIdPanel panel; - protected String publicId; - protected String systemId; - - public SelectXMLCatalogIdDialog(Shell parentShell, String[] extensions) { - super(parentShell); - setShellStyle(getShellStyle() | SWT.RESIZE); - this.extensions = extensions; - } - - - protected void buttonPressed(int buttonId) { - if (buttonId == IDialogConstants.OK_ID) { - ISelection selection = panel.getTableViewer().getSelection(); - Object selectedObject = (selection instanceof IStructuredSelection) ? ((IStructuredSelection) selection).getFirstElement() : null; - - if (selectedObject instanceof ICatalogEntry) { - ICatalogEntry mappingInfo = (ICatalogEntry) selectedObject; - publicId = mappingInfo.getKey(); - systemId = computeDefaultSystemId(mappingInfo); - } - } - super.buttonPressed(buttonId); - } - - protected String computeDefaultSystemId(ICatalogEntry mappingInfo) { - String result = mappingInfo.getAttributeValue(ICatalogEntry.ATTR_WEB_URL); - if ((result == null) && (mappingInfo.getURI() != null)) { - int index = mappingInfo.getURI().lastIndexOf("/"); //$NON-NLS-1$ - String lastSegment = index != -1 ? mappingInfo.getURI().substring(index + 1) : mappingInfo.getURI(); - result = lastSegment; - } - return result; - } - - protected void createButtonsForButtonBar(Composite parent) { - okButton = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); - okButton.setEnabled(false); - createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); - } - - protected Control createDialogArea(Composite parent) { - Composite dialogArea = (Composite) super.createDialogArea(parent); - PlatformUI.getWorkbench().getHelpSystem().setHelp(dialogArea, XMLCommonUIContextIds.XCUI_CATALOG_DIALOG); - - ICatalog xmlCatalog = XMLCorePlugin.getDefault().getDefaultXMLCatalog(); - panel = new SelectXMLCatalogIdPanel(dialogArea, xmlCatalog); - - ISelectionChangedListener listener = new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - updateButtonState(); - } - }; - panel.getTableViewer().setFilterExtensions(extensions); - panel.getTableViewer().addSelectionChangedListener(listener); - return dialogArea; - } - - - - public String getId() { - return publicId; - } - - public String getSystemId() { - return systemId; - } - - protected void updateButtonState() { - ISelection selection = panel.getTableViewer().getSelection(); - okButton.setEnabled(!selection.isEmpty()); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/SelectXMLCatalogIdPanel.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/SelectXMLCatalogIdPanel.java deleted file mode 100644 index 01a9e8b399..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/SelectXMLCatalogIdPanel.java +++ /dev/null @@ -1,147 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.dialogs; - -import java.util.Collection; -import java.util.List; -import java.util.Vector; - -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry; -import org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; - - -public class SelectXMLCatalogIdPanel extends Composite { - protected int catalogEntryType; - protected boolean doTableSizeHack = false; - - protected XMLCatalogTableViewer tableViewer; - protected ICatalog fXmlCatalog; - - public SelectXMLCatalogIdPanel(Composite parent, ICatalog xmlCatalog) { - super(parent, SWT.NONE); - this.fXmlCatalog = xmlCatalog; - - GridLayout gridLayout = new GridLayout(); - this.setLayout(gridLayout); - GridData gd = new GridData(GridData.FILL_HORIZONTAL); - gd.heightHint = 200; - gd.widthHint = 700; - this.setLayoutData(gd); - - Label label = new Label(this, SWT.NONE); - label.setText(XMLUIMessages._UI_LABEL_XML_CATALOG_COLON); - - tableViewer = createTableViewer(this); - tableViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH)); - tableViewer.setInput("dummy"); //$NON-NLS-1$ - } - - protected XMLCatalogTableViewer createTableViewer(Composite parent) { - String headings[] = new String[2]; - headings[0] = XMLUIMessages._UI_LABEL_KEY; - headings[1] = XMLUIMessages._UI_LABEL_URI; - - XMLCatalogTableViewer theTableViewer = new XMLCatalogTableViewer(parent, headings) { - - protected void addXMLCatalogEntries(List list, ICatalogEntry[] entries) { - for (int i = 0; i < entries.length; i++) { - ICatalogEntry entry = entries[i]; - if (catalogEntryType == 0) { - list.add(entry); - } - else if (catalogEntryType == entry.getEntryType()) { - list.add(entry); - } - } - } - - public Collection getXMLCatalogEntries() { - List result = null; - - if ((fXmlCatalog == null) || doTableSizeHack) { - // this lets us create a table with an initial height of - // 10 rows - // otherwise we get stuck with 0 row heigh table... that's - // too small - doTableSizeHack = false; - result = new Vector(); - for (int i = 0; i < 6; i++) { - result.add(""); //$NON-NLS-1$ - } - } - else { - result = new Vector(); - INextCatalog[] nextCatalogs = fXmlCatalog.getNextCatalogs(); - for (int i = 0; i < nextCatalogs.length; i++) { - INextCatalog catalog = nextCatalogs[i]; - ICatalog referencedCatalog = catalog.getReferencedCatalog(); - if (referencedCatalog != null) { - if (XMLCorePlugin.SYSTEM_CATALOG_ID.equals(referencedCatalog.getId())) { - ICatalog systemCatalog = referencedCatalog; - addXMLCatalogEntries(result, systemCatalog.getCatalogEntries()); - - } - else if (XMLCorePlugin.USER_CATALOG_ID.equals(referencedCatalog.getId())) { - ICatalog userCatalog = referencedCatalog; - addXMLCatalogEntries(result, userCatalog.getCatalogEntries()); - - } - } - } - } - return result; - } - }; - return theTableViewer; - } - - - public String getId() { - ICatalogEntry entry = getXMLCatalogEntry(); - return entry != null ? entry.getKey() : null; - } - - public XMLCatalogTableViewer getTableViewer() { - return tableViewer; - } - - public String getURI() { - ICatalogEntry entry = getXMLCatalogEntry(); - return entry != null ? entry.getURI() : null; - } - - public ICatalogEntry getXMLCatalogEntry() { - ICatalogEntry result = null; - ISelection selection = tableViewer.getSelection(); - Object selectedObject = (selection instanceof IStructuredSelection) ? ((IStructuredSelection) selection).getFirstElement() : null; - if (selectedObject instanceof ICatalogEntry) { - result = (ICatalogEntry) selectedObject; - } - return result; - } - - public void setCatalogEntryType(int catalogEntryType) { - this.catalogEntryType = catalogEntryType; - tableViewer.refresh(); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/UpdateListener.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/UpdateListener.java deleted file mode 100644 index 607270ad1f..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/UpdateListener.java +++ /dev/null @@ -1,20 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ - - -package org.eclipse.wst.xml.ui.internal.dialogs; - -public interface UpdateListener { - - public void updateOccured(Object object, Object arg); -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/XMLCatalogTableViewer.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/XMLCatalogTableViewer.java deleted file mode 100644 index ada87596e1..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/XMLCatalogTableViewer.java +++ /dev/null @@ -1,201 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ - - -package org.eclipse.wst.xml.ui.internal.dialogs; - -import com.ibm.icu.text.Collator; -import java.util.Arrays; -import java.util.Collection; -import java.util.Comparator; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.viewers.ColumnWeightData; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.TableLayout; -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.graphics.Image; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.wst.common.uriresolver.internal.util.URIHelper; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages; - - -public class XMLCatalogTableViewer extends TableViewer { - - - public class CatalogEntryContentProvider implements IStructuredContentProvider { - - public void dispose() { - } - - public Object[] getElements(Object element) { - Object[] array = getXMLCatalogEntries().toArray(); - Comparator comparator = new Comparator() { - public int compare(Object o1, Object o2) { - int result = 0; - if ((o1 instanceof ICatalogEntry) && (o2 instanceof ICatalogEntry)) { - ICatalogEntry mappingInfo1 = (ICatalogEntry) o1; - ICatalogEntry mappingInfo2 = (ICatalogEntry) o2; - result = Collator.getInstance().compare(mappingInfo1.getKey(), mappingInfo2.getKey()); - } - return result; - } - }; - Arrays.sort(array, comparator); - return array; - } - - public void inputChanged(Viewer viewer, Object old, Object newobj) { - } - - public boolean isDeleted(Object object) { - return false; - } - } - - public class CatalogEntryLabelProvider extends LabelProvider implements ITableLabelProvider { - - public Image getColumnImage(Object object, int columnIndex) { - Image result = null; - if (columnIndex == 0) { - Image base = null; - if (object instanceof ICatalogEntry) { - ICatalogEntry catalogEntry = (ICatalogEntry) object; - String uri = catalogEntry.getURI(); - if (uri.endsWith("dtd")) { //$NON-NLS-1$ - base = dtdFileImage; - } - else if (uri.endsWith("xsd")) { //$NON-NLS-1$ - base = xsdFileImage; - } - else { - base = unknownFileImage; - } - - if (base != null) { - if (URIHelper.isReadableURI(uri, false)) { - result = base; - } - else { - // TODO... SSE port - result = base;// imageFactory.createCompositeImage(base, - // errorImage, - // ImageFactory.BOTTOM_LEFT); - } - } - } - } - return result; - } - - public String getColumnText(Object object, int columnIndex) { - String result = null; - if (object instanceof ICatalogEntry) { - ICatalogEntry catalogEntry = (ICatalogEntry) object; - result = columnIndex == 0 ? catalogEntry.getKey() : catalogEntry.getURI(); - result = URIHelper.removePlatformResourceProtocol(result); - } - return result != null ? result : ""; //$NON-NLS-1$ - } - } - - - class XMLCatalogTableViewerFilter extends ViewerFilter { - protected String[] extensions; - - public XMLCatalogTableViewerFilter(String[] extensions) { - this.extensions = extensions; - } - - public boolean isFilterProperty(Object element, Object property) { - return false; - } - - public boolean select(Viewer viewer, Object parent, Object element) { - boolean result = false; - if (element instanceof ICatalogEntry) { - ICatalogEntry catalogEntry = (ICatalogEntry) element; - for (int i = 0; i < extensions.length; i++) { - if (catalogEntry.getURI().endsWith(extensions[i])) { - result = true; - break; - } - } - } - return result; - } - } - - protected static Image dtdFileImage = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_DTDFILE); - - protected static String ERROR_STATE_KEY = "errorstatekey"; //$NON-NLS-1$ - protected static Image errorImage = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OVR_ERROR); - - protected static Image unknownFileImage = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TXTEXT); - protected static Image xsdFileImage = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_XSDFILE); - - // protected ImageFactory imageFactory = new ImageFactory(); - - public XMLCatalogTableViewer(Composite parent, String[] columnProperties) { - super(parent, SWT.FULL_SELECTION); - - Table table = getTable(); - table.setLinesVisible(true); - table.setHeaderVisible(true); - table.setLinesVisible(true); - - TableLayout layout = new TableLayout(); - for (int i = 0; i < columnProperties.length; i++) { - TableColumn column = new TableColumn(table, i); - column.setText(columnProperties[i]); - column.setAlignment(SWT.LEFT); - layout.addColumnData(new ColumnWeightData(50, true)); - } - table.setLayout(layout); - table.setLinesVisible(false); - - setColumnProperties(columnProperties); - - setContentProvider(new CatalogEntryContentProvider()); - setLabelProvider(new CatalogEntryLabelProvider()); - } - - public Collection getXMLCatalogEntries() { - return null; - } - - - public void menuAboutToShow(IMenuManager menuManager) { - Action action = new Action("hello") { //$NON-NLS-1$ - public void run() { - System.out.println("run!"); //$NON-NLS-1$ - } - }; - menuManager.add(action); - } - - public void setFilterExtensions(String[] extensions) { - resetFilters(); - addFilter(new XMLCatalogTableViewerFilter(extensions)); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dnd/DragNodeCommand.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dnd/DragNodeCommand.java deleted file mode 100644 index 3f5c66fab0..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dnd/DragNodeCommand.java +++ /dev/null @@ -1,287 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.dnd; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.swt.dnd.DND; -import org.eclipse.wst.common.ui.internal.dnd.DefaultDragAndDropCommand; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.w3c.dom.Attr; -import org.w3c.dom.DOMException; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -public class DragNodeCommand extends DefaultDragAndDropCommand { - private List fSelections; - private TreeViewer fTreeViewer; - - public DragNodeCommand(Object target, float location, int operations, int operation, Collection sources, TreeViewer treeViewer) { - super(target, location, operations, operation, sources); - fTreeViewer = treeViewer; - fSelections = new ArrayList(); - } - - private void beginModelChange(Node node, boolean batchUpdate) { - IStructuredModel structuredModel = getStructuredModel(node); - if (structuredModel != null) { - String undoDesc = new String(); - if (getOperation() == DND.DROP_MOVE) { - undoDesc = XMLUIMessages.DragNodeCommand_0; - } - else if (getOperation() == DND.DROP_COPY) { - undoDesc = XMLUIMessages.DragNodeCommand_1; - } - - structuredModel.beginRecording(this, undoDesc); - if (batchUpdate) { - // structuredModel.aboutToChangeModel(); - } - } - } - - public boolean canExecute() { - return executeHelper(true); - } - - private boolean doModify(Node source, Node parentNode, Node refChild, boolean testOnly) { - boolean result = false; - if (source.getNodeType() == Node.ATTRIBUTE_NODE) { - Attr sourceAttribute = (Attr) source; - Element sourceAttributeOwnerElement = sourceAttribute.getOwnerElement(); - if ((parentNode.getNodeType() == Node.ELEMENT_NODE) && (sourceAttributeOwnerElement != parentNode)) { - result = true; - if (!testOnly) { - try { - if (getOperation() == DND.DROP_MOVE) { - Element targetElement = (Element) parentNode; - sourceAttributeOwnerElement.removeAttributeNode(sourceAttribute); - targetElement.getAttributes().setNamedItem(sourceAttribute); - fSelections.add(sourceAttribute); - } - else if (getOperation() == DND.DROP_COPY) { - Attr cloneAttribute = (Attr) sourceAttribute.cloneNode(false); - Element targetElement = (Element) parentNode; - targetElement.getAttributes().setNamedItem(cloneAttribute); - fSelections.add(cloneAttribute); - } - } - catch (Exception e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - } - } - } - else { - if (((parentNode.getNodeType() == Node.ELEMENT_NODE) || (parentNode.getNodeType() == Node.DOCUMENT_NODE)) && !(refChild instanceof Attr)) { - result = true; - - if (!testOnly) { - try { - if (isAncestor(source, parentNode)) { - // System.out.println("can not perform this drag drop - // operation.... todo... pop up dialog"); - } - else { - // defect 221055 this test is required or else the - // node will - // be removed from the tree and the insert will fail - if (source != refChild) { - if (getOperation() == DND.DROP_MOVE) { - Node oldParent = source.getParentNode(); - Node oldSibling = source.getNextSibling(); - oldParent.removeChild(source); - try { - parentNode.insertBefore(source, refChild); - } catch (DOMException e) { - // bug151692 - if unable to move node to new location, reinsert back to old location - oldParent.insertBefore(source, oldSibling); - } - fSelections.add(source); - } - else if (getOperation() == DND.DROP_COPY) { - Node nodeClone = source.cloneNode(true); - parentNode.insertBefore(nodeClone, refChild); - fSelections.add(nodeClone); - } - } - } - } - catch (Exception e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - } - } - } - return result; - } - - private void endModelChange(Node node, boolean batchUpdate) { - IStructuredModel structuredModel = getStructuredModel(node); - if (structuredModel != null) { - structuredModel.endRecording(this); - if (batchUpdate) { - // structuredModel.changedModel(); - } - } - } - - public void execute() { - executeHelper(false); - - // Make our selection if the treeViewer != null - if (fTreeViewer != null) { - StructuredSelection structuredSelection = new StructuredSelection(fSelections); - fTreeViewer.setSelection(structuredSelection); - } - } - - private boolean executeHelper(boolean testOnly) { - boolean result = true; - if (target instanceof Node) { - Node targetNode = (Node) target; - Node parentNode = getParentForDropPosition(targetNode); - Node refChild = getRefChild(targetNode); - - Vector sourcesList = new Vector(); - sourcesList.addAll(sources); - - removeMemberDescendants(sourcesList); - boolean performBatchUpdate = sourcesList.size() > 5; - - if (!testOnly) { - beginModelChange(targetNode, performBatchUpdate); - } - for (Iterator i = sourcesList.iterator(); i.hasNext();) { - Object source = i.next(); - if (source instanceof Node) { - if (!((refChild == null) && (targetNode instanceof Attr))) { - result = doModify((Node) source, parentNode, refChild, testOnly); - } - else { - result = false; - } - if (!result) { - break; - } - } - } - if (!testOnly) { - endModelChange(targetNode, performBatchUpdate); - } - } - else { - result = false; - } - return result; - } - - - public int getFeedback() { - int result = DND.FEEDBACK_SELECT; - if (location > 0.75) { - result = DND.FEEDBACK_INSERT_AFTER; - } - else if (location < 0.25) { - result = DND.FEEDBACK_INSERT_BEFORE; - } - return result; - } - - private Node getParentForDropPosition(Node node) { - Node result = null; - - int feedback = getFeedback(); - if (feedback == DND.FEEDBACK_SELECT) { - result = node; - } - else { - result = getParentOrOwner(node); - } - return result; - } - - - private Node getParentOrOwner(Node node) { - return (node.getNodeType() == Node.ATTRIBUTE_NODE) ? ((Attr) node).getOwnerElement() : node.getParentNode(); - } - - - private Node getRefChild(Node node) { - Node result = null; - - int feedback = getFeedback(); - - if (feedback == DND.FEEDBACK_INSERT_BEFORE) { - result = node; - } - else if (feedback == DND.FEEDBACK_INSERT_AFTER) { - result = node.getNextSibling(); - } - return result; - } - - private IStructuredModel getStructuredModel(Node node) { - IStructuredModel result = null; - if (node instanceof IDOMNode) { - result = ((IDOMNode) node).getModel(); - } - return result; - } - - // returns true if a is an ancestore of b - // - private boolean isAncestor(Node a, Node b) { - boolean result = false; - for (Node parent = b; parent != null; parent = parent.getParentNode()) { - if (parent == a) { - result = true; - break; - } - } - return result; - } - - - /** - * This method removes members of the list that have ancestors that are - * also members of the list. - */ - private void removeMemberDescendants(List list) { - Hashtable table = new Hashtable(); - for (Iterator i = list.iterator(); i.hasNext();) { - Object node = i.next(); - table.put(node, node); - } - - for (int i = list.size() - 1; i >= 0; i--) { - Node node = (Node) list.get(i); - for (Node parent = getParentOrOwner(node); parent != null; parent = getParentOrOwner(parent)) { - if (table.get(parent) != null) { - list.remove(i); - break; - } - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dnd/XMLDragAndDropManager.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dnd/XMLDragAndDropManager.java deleted file mode 100644 index 48097a81eb..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dnd/XMLDragAndDropManager.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ - - -package org.eclipse.wst.xml.ui.internal.dnd; - -import java.util.Collection; - -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.swt.dnd.DND; -import org.eclipse.swt.dnd.Transfer; -import org.eclipse.wst.common.ui.internal.dnd.DragAndDropCommand; -import org.eclipse.wst.common.ui.internal.dnd.DragAndDropManager; -import org.eclipse.wst.common.ui.internal.dnd.ObjectTransfer; -import org.eclipse.wst.common.ui.internal.dnd.ViewerDragAdapter; -import org.eclipse.wst.common.ui.internal.dnd.ViewerDropAdapter; -import org.w3c.dom.Node; - -public class XMLDragAndDropManager implements DragAndDropManager { - private TreeViewer fViewer; - - public static void addDragAndDropSupport(TreeViewer viewer) { - int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK; - Transfer[] transfers = new Transfer[]{ObjectTransfer.getInstance()}; - viewer.addDragSupport(dndOperations, transfers, new ViewerDragAdapter(viewer)); - viewer.addDropSupport(dndOperations, transfers, new ViewerDropAdapter(viewer, new XMLDragAndDropManager(viewer))); - } - - public XMLDragAndDropManager() { - super(); - } - - public XMLDragAndDropManager(TreeViewer viewer) { - fViewer = viewer; - } - - public DragAndDropCommand createCommand(Object target, float location, int operations, int operation, Collection source) { - DragAndDropCommand result = null; - if (target instanceof Node) { - result = new DragNodeCommand(target, location, operations, operation, source, fViewer); - } - return result; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/doubleclick/XMLDoubleClickStrategy.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/doubleclick/XMLDoubleClickStrategy.java deleted file mode 100644 index b23097ecf2..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/doubleclick/XMLDoubleClickStrategy.java +++ /dev/null @@ -1,327 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.doubleclick; - -import org.eclipse.jface.text.DefaultTextDoubleClickStrategy; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.swt.graphics.Point; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.sse.ui.internal.StructuredTextViewer; -import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; -import org.w3c.dom.Node; - - -public class XMLDoubleClickStrategy extends DefaultTextDoubleClickStrategy { - protected static final char DOUBLE_QUOTE = '\"'; - protected static final char SINGLE_QUOTE = '\''; - protected static final char SPACE = ' '; - protected int fCaretPosition = -1; - protected int fDoubleClickCount = 0; - protected Node fNode = null; - protected IStructuredDocumentRegion fStructuredDocumentRegion = null; - protected String fStructuredDocumentRegionText = ""; //$NON-NLS-1$ - protected IStructuredModel fStructuredModel = null; - protected StructuredTextViewer fStructuredTextViewer; - protected ITextRegion fTextRegion = null; - - public void doubleClicked(ITextViewer textViewer) { - if (textViewer instanceof StructuredTextViewer) { - fStructuredTextViewer = (StructuredTextViewer) textViewer; - try { - fStructuredModel = StructuredModelManager.getModelManager().getExistingModelForRead(fStructuredTextViewer.getDocument()); - - if (fStructuredModel != null) { - int caretPosition = textViewer.getSelectedRange().x; - if (caretPosition < 0) { - return; - } - - fNode = (Node) fStructuredModel.getIndexedRegion(caretPosition); - if (fNode == null) { - return; - } - - updateDoubleClickCount(caretPosition); - updateStructuredDocumentRegion(); - updateTextRegion(); - - if (fNode.getNodeType() == Node.TEXT_NODE) { - processTextDoubleClicked(); - } - else { - processElementDoubleClicked(); - } - } - } - finally { - if (fStructuredModel != null) { - fStructuredModel.releaseFromRead(); - } - } - } - } - - protected Point getWord(String string, int cursor) { - if (string == null) { - return null; - } - - int wordStart = 0; - int wordEnd = string.length(); - - wordStart = string.lastIndexOf(SPACE, cursor - 1); - int temp = string.lastIndexOf(SINGLE_QUOTE, cursor - 1); - wordStart = Math.max(wordStart, temp); - temp = string.lastIndexOf(DOUBLE_QUOTE, cursor - 1); - wordStart = Math.max(wordStart, temp); - if (wordStart == -1) { - wordStart = cursor; - } - else { - wordStart++; - } - - wordEnd = string.indexOf(SPACE, cursor); - if (wordEnd == -1) { - wordEnd = string.length(); - } - temp = string.indexOf(SINGLE_QUOTE, cursor); - if (temp == -1) { - temp = string.length(); - } - wordEnd = Math.min(wordEnd, temp); - temp = string.indexOf(DOUBLE_QUOTE, cursor); - if (temp == -1) { - temp = string.length(); - } - wordEnd = Math.min(wordEnd, temp); - if (wordEnd == string.length()) { - wordEnd = cursor; - } - - if ((wordStart == wordEnd) && !isQuoted(string)) { - wordStart = 0; - wordEnd = string.length(); - } - - return new Point(wordStart, wordEnd); - } - - protected boolean isQuoted(String string) { - if ((string == null) || (string.length() < 2)) { - return false; - } - - int lastIndex = string.length() - 1; - char firstChar = string.charAt(0); - char lastChar = string.charAt(lastIndex); - - return (((firstChar == SINGLE_QUOTE) && (lastChar == SINGLE_QUOTE)) || ((firstChar == DOUBLE_QUOTE) && (lastChar == DOUBLE_QUOTE))); - } - - protected void processElementAttrEqualsDoubleClicked2Times() { - int prevRegionOffset = fStructuredDocumentRegion.getStartOffset(fTextRegion) - 1; - ITextRegion prevRegion = fStructuredDocumentRegion.getRegionAtCharacterOffset(prevRegionOffset); - int nextRegionOffset = fStructuredDocumentRegion.getEndOffset(fTextRegion); - ITextRegion nextRegion = fStructuredDocumentRegion.getRegionAtCharacterOffset(nextRegionOffset); - - if ((prevRegion != null) && (prevRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) && (nextRegion != null) && (nextRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE)) { - fStructuredTextViewer.setSelectedRange(fStructuredDocumentRegion.getStartOffset(prevRegion), nextRegion.getTextEnd() - prevRegion.getStart()); - } - } - - protected void processElementAttrNameDoubleClicked2Times() { - int nextRegionOffset = fStructuredDocumentRegion.getEndOffset(fTextRegion); - ITextRegion nextRegion = fStructuredDocumentRegion.getRegionAtCharacterOffset(nextRegionOffset); - - if (nextRegion != null) { - nextRegionOffset = fStructuredDocumentRegion.getEndOffset(nextRegion); - nextRegion = fStructuredDocumentRegion.getRegionAtCharacterOffset(nextRegionOffset); - if ((nextRegion != null) && (nextRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE)) { - fStructuredTextViewer.setSelectedRange(fStructuredDocumentRegion.getStartOffset(fTextRegion), nextRegion.getTextEnd() - fTextRegion.getStart()); - } - else { - // attribute has no value - fStructuredTextViewer.setSelectedRange(fStructuredDocumentRegion.getStart(), fStructuredDocumentRegion.getLength()); - fDoubleClickCount = 0; - } - } - } - - protected void processElementAttrValueDoubleClicked() { - String regionText = fStructuredDocumentRegion.getText(fTextRegion); - - if (fDoubleClickCount == 1) { - Point word = getWord(regionText, fCaretPosition - fStructuredDocumentRegion.getStartOffset(fTextRegion)); - if (word.x == word.y) { // no word found; select whole region - fStructuredTextViewer.setSelectedRange(fStructuredDocumentRegion.getStartOffset(fTextRegion), regionText.length()); - fDoubleClickCount++; - } - else { - fStructuredTextViewer.setSelectedRange(fStructuredDocumentRegion.getStartOffset(fTextRegion) + word.x, word.y - word.x); - } - } - else if (fDoubleClickCount == 2) { - if (isQuoted(regionText)) { - // ==> // Point word = getWord(regionText, fCaretPosition - - // fStructuredDocumentRegion.getStartOffset(fTextRegion)); - fStructuredTextViewer.setSelectedRange(fStructuredDocumentRegion.getStartOffset(fTextRegion), regionText.length()); - } - else { - processElementAttrValueDoubleClicked2Times(); - } - } - else if (fDoubleClickCount == 3) { - if (isQuoted(regionText)) { - processElementAttrValueDoubleClicked2Times(); - } - else { - fStructuredTextViewer.setSelectedRange(fStructuredDocumentRegion.getStart(), fStructuredDocumentRegion.getLength()); - fDoubleClickCount = 0; - } - } - else { // fDoubleClickCount == 4 - fStructuredTextViewer.setSelectedRange(fStructuredDocumentRegion.getStart(), fStructuredDocumentRegion.getLength()); - fDoubleClickCount = 0; - } - } - - protected void processElementAttrValueDoubleClicked2Times() { - int prevRegionOffset = fStructuredDocumentRegion.getStartOffset(fTextRegion) - 1; - ITextRegion prevRegion = fStructuredDocumentRegion.getRegionAtCharacterOffset(prevRegionOffset); - - if (prevRegion != null) { - prevRegionOffset = fStructuredDocumentRegion.getStartOffset(prevRegion) - 1; - prevRegion = fStructuredDocumentRegion.getRegionAtCharacterOffset(prevRegionOffset); - if ((prevRegion != null) && (prevRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME)) { - fStructuredTextViewer.setSelectedRange(fStructuredDocumentRegion.getStartOffset(prevRegion), fTextRegion.getTextEnd() - prevRegion.getStart()); - } - } - } - - protected void processElementDoubleClicked() { - if (fTextRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) { - processElementAttrValueDoubleClicked(); // special handling for - } - else { - if (fDoubleClickCount == 1) { - fStructuredTextViewer.setSelectedRange(fStructuredDocumentRegion.getStart() + fTextRegion.getStart(), fTextRegion.getTextLength()); - } - else if (fDoubleClickCount == 2) { - if (fTextRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) { - processElementAttrNameDoubleClicked2Times(); - } - else if (fTextRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) { - processElementAttrEqualsDoubleClicked2Times(); - } - else { - fStructuredTextViewer.setSelectedRange(fStructuredDocumentRegion.getStart(), fStructuredDocumentRegion.getLength()); - fDoubleClickCount = 0; - } - } - else { // fDoubleClickCount == 3 - fStructuredTextViewer.setSelectedRange(fStructuredDocumentRegion.getStart(), fStructuredDocumentRegion.getLength()); - fDoubleClickCount = 0; - } - } - } - - protected void processTextDoubleClicked() { - if (fDoubleClickCount == 1) { - super.doubleClicked(fStructuredTextViewer); - - Point selectedRange = fStructuredTextViewer.getSelectedRange(); - if ((selectedRange.x == fStructuredDocumentRegion.getStartOffset(fTextRegion)) && (selectedRange.y == fTextRegion.getTextLength())) { - // only one word in region, skip one level of double click - // selection - fDoubleClickCount++; - } - } - else if (fDoubleClickCount == 2) { - if (fTextRegion.getType() == DOMRegionContext.UNDEFINED) { - fStructuredTextViewer.setSelectedRange(fStructuredDocumentRegion.getStart(), fStructuredDocumentRegion.getLength()); - fDoubleClickCount = 0; - } - else { - if (isQuoted(fStructuredDocumentRegion.getFullText(fTextRegion))) { - fStructuredTextViewer.setSelectedRange(fStructuredDocumentRegion.getStartOffset(fTextRegion) + 1, fTextRegion.getTextLength() - 2); - } - else { - fStructuredTextViewer.setSelectedRange(fStructuredDocumentRegion.getStartOffset(fTextRegion), fTextRegion.getTextLength()); - } - } - } - else { - if ((fDoubleClickCount == 3) && isQuoted(fStructuredDocumentRegion.getFullText(fTextRegion))) { - fStructuredTextViewer.setSelectedRange(fStructuredDocumentRegion.getStartOffset(fTextRegion), fTextRegion.getTextLength()); - } - else { - if ((fDoubleClickCount == 3) && isQuoted(fStructuredDocumentRegionText)) { - fStructuredTextViewer.setSelectedRange(fStructuredDocumentRegion.getStart() + 1, fStructuredDocumentRegion.getLength() - 2); - } - else { - fStructuredTextViewer.setSelectedRange(fStructuredDocumentRegion.getStart(), fStructuredDocumentRegion.getLength()); - fDoubleClickCount = 0; - } - } - } - } - - public void setModel(IStructuredModel structuredModel) { - fStructuredModel = structuredModel; - } - - protected void updateDoubleClickCount(int caretPosition) { - if (fCaretPosition == caretPosition) { - if (fStructuredDocumentRegion != null) { - fDoubleClickCount++; - } - else { - fDoubleClickCount = 1; - } - } - else { - fCaretPosition = caretPosition; - fDoubleClickCount = 1; - } - } - - protected void updateStructuredDocumentRegion() { - fStructuredDocumentRegion = fStructuredModel.getStructuredDocument().getRegionAtCharacterOffset(fCaretPosition); - if (fStructuredDocumentRegion != null) { - fStructuredDocumentRegionText = fStructuredDocumentRegion.getText(); - } - else { - fStructuredDocumentRegionText = ""; //$NON-NLS-1$ - } - } - - protected void updateTextRegion() { - if (fStructuredDocumentRegion != null) { - fTextRegion = fStructuredDocumentRegion.getRegionAtCharacterOffset(fCaretPosition); - // if fTextRegion is null, it means we are at just past the last - // fStructuredDocumentRegion, - // at the very end of the document, so we'll use the last text - // region in the document - if (fTextRegion == null) { - fTextRegion = fStructuredDocumentRegion.getRegionAtCharacterOffset(fCaretPosition - 1); - } - } - else { - fTextRegion = null; - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/editor/CMImageUtil.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/editor/CMImageUtil.java deleted file mode 100644 index 64320ec782..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/editor/CMImageUtil.java +++ /dev/null @@ -1,115 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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.wst.xml.ui.internal.editor; - -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.swt.SWTException; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.ImageData; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.w3c.dom.Attr; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -/** - * @author nsd - */ -public class CMImageUtil { - - public static String SMALL_ICON_URL = "small-icon"; //$NON-NLS-1$ - - public static CMNode getDeclaration(Node node) { - CMNode decl = null; - ModelQuery mq = null; - switch (node.getNodeType()) { - case Node.ATTRIBUTE_NODE : { - mq = ModelQueryUtil.getModelQuery(((Attr) node).getOwnerDocument()); - decl = mq.getCMAttributeDeclaration((Attr) node); - } - break; - case Node.ELEMENT_NODE : { - mq = ModelQueryUtil.getModelQuery(node.getOwnerDocument()); - decl = mq.getCMElementDeclaration((Element) node); - } - break; - } - return decl; - } - - public static Image getImage(CMNode cmnode) { - if (cmnode == null) { - return null; - } - Image image = null; - ImageDescriptor descriptor = getImageDescriptor(cmnode); - if (descriptor != null) { - image = descriptor.createImage(false); - } - return image; - } - - public static ImageDescriptor getImageDescriptor(CMNode cmnode) { - if (cmnode == null) { - return null; - } - // cache CM-specified images with the XML UI plugin - String imageURLString = (String) cmnode.getProperty(SMALL_ICON_URL); - ImageDescriptor descriptor = null; - if ((imageURLString != null) && (imageURLString.length() > 0)) { - descriptor = XMLUIPlugin.getInstance().getImageRegistry().getDescriptor(imageURLString); - if (descriptor == null) { - try { - URL imageURL = new URL(imageURLString); - URLConnection connection = imageURL.openConnection(); - connection.setUseCaches(false); - InputStream inputStream = connection.getInputStream(); - try { - ImageData data = new ImageData(inputStream); - descriptor = ImageDescriptor.createFromImageData(data); - XMLUIPlugin.getInstance().getImageRegistry().put(imageURLString, descriptor); - } - catch (SWTException e) { - /* - * There was a problem loading image from stream - * (corrupt, missing, etc.) - */ - if (inputStream != null) - inputStream.close(); - } - } - catch (MalformedURLException e) { - descriptor = null; - } - catch (IOException e) { - descriptor = null; - } - } - } - return descriptor; - } - - /** - * - */ - private CMImageUtil() { - super(); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/editor/IHelpContextIds.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/editor/IHelpContextIds.java deleted file mode 100644 index d64004f6d7..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/editor/IHelpContextIds.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.editor; - -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; - -/** - * Help context ids for the XML Source Editor. - * <p> - * This interface contains constants only; it is not intended to be - * implemented. - * </p> - * - */ -public interface IHelpContextIds { - // org.eclipse.wst.xml.ui. - public static final String PREFIX = XMLUIPlugin.ID + "."; //$NON-NLS-1$ - - // figured out on the fly - // // XML Source page editor - // public static final String XML_SOURCEVIEW_HELPID = - // ContentTypeIdForXML.ContentTypeID_XML +"_source_HelpId"; //$NON-NLS-1$ - - // XML Files Preference page - public static final String XML_PREFWEBX_FILES_HELPID = PREFIX + "webx0060"; //$NON-NLS-1$ - // XML Source Preference page - public static final String XML_PREFWEBX_SOURCE_HELPID = PREFIX + "webx0061"; //$NON-NLS-1$ - // XML Styles Preference page - public static final String XML_PREFWEBX_STYLES_HELPID = PREFIX + "webx0062"; //$NON-NLS-1$ - // XML Templates Preference page - public static final String XML_PREFWEBX_TEMPLATES_HELPID = PREFIX + "webx0063"; //$NON-NLS-1$ - - // XML Cleanup dialog - public static final String CLEANUP_XML_HELPID = PREFIX + "xmlm1200"; //$NON-NLS-1$ - - // XML New File Wizard - Template Page - public static final String XML_NEWWIZARD_TEMPLATE_HELPID = PREFIX + "xmlw0010"; //$NON-NLS-1$ -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/editor/XMLEditorPluginImageHelper.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/editor/XMLEditorPluginImageHelper.java deleted file mode 100644 index 429b6b7d17..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/editor/XMLEditorPluginImageHelper.java +++ /dev/null @@ -1,160 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.editor; - -import java.util.HashMap; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.resource.ImageRegistry; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.swt.graphics.Image; -import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; - - -/** - * Helper class to handle images provided by this plug-in. - * - * NOTE: For internal use only. For images used externally, please use the - * Shared***ImageHelper class instead. - * - * @author amywu - */ -public class XMLEditorPluginImageHelper { - private static XMLEditorPluginImageHelper instance = null; - - /** - * Gets the instance. - * - * @return Returns a XMLEditorPluginImageHelper - */ - public synchronized static XMLEditorPluginImageHelper getInstance() { - if (instance == null) { - instance = new XMLEditorPluginImageHelper(); - } - return instance; - } - - // save a descriptor for each image - private HashMap fImageDescRegistry = null; - private final String PLUGINID = XMLUIPlugin.ID; - - /** - * Creates an image from the given resource and adds the image to the - * image registry. - * - * @param resource - * @return Image - */ - private Image createImage(String resource) { - ImageDescriptor desc = getImageDescriptor(resource); - Image image = null; - - if (desc != null) { - image = desc.createImage(); - // dont add the missing image descriptor image to the image - // registry - if (!desc.equals(ImageDescriptor.getMissingImageDescriptor())) { - getImageRegistry().put(resource, image); - } - } - return image; - } - - /** - * Creates an image descriptor from the given imageFilePath and adds the - * image descriptor to the image descriptor registry. If an image - * descriptor could not be created, the default "missing" image descriptor - * is returned but not added to the image descriptor registry. - * - * @param imageFilePath - * @return ImageDescriptor image descriptor for imageFilePath or default - * "missing" image descriptor if resource could not be found - */ - private ImageDescriptor createImageDescriptor(String imageFilePath) { - ImageDescriptor imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(PLUGINID, imageFilePath); - if (imageDescriptor != null) { - getImageDescriptorRegistry().put(imageFilePath, imageDescriptor); - } - else { - imageDescriptor = ImageDescriptor.getMissingImageDescriptor(); - } - - return imageDescriptor; - } - - /** - * Retrieves the image associated with resource from the image registry. - * If the image cannot be retrieved, attempt to find and load the image at - * the location specified in resource. - * - * @param resource - * the image to retrieve - * @return Image the image associated with resource or null if one could - * not be found - */ - public Image getImage(String resource) { - Image image = getImageRegistry().get(resource); - if (image == null) { - // create an image - image = createImage(resource); - } - return image; - } - - /** - * Retrieves the image descriptor associated with resource from the image - * descriptor registry. If the image descriptor cannot be retrieved, - * attempt to find and load the image descriptor at the location specified - * in resource. - * - * @param resource - * the image descriptor to retrieve - * @return ImageDescriptor the image descriptor assocated with resource or - * the default "missing" image descriptor if one could not be - * found - */ - public ImageDescriptor getImageDescriptor(String resource) { - ImageDescriptor imageDescriptor = null; - Object o = getImageDescriptorRegistry().get(resource); - if (o == null) { - // create a descriptor - imageDescriptor = createImageDescriptor(resource); - } - else { - imageDescriptor = (ImageDescriptor) o; - } - return imageDescriptor; - } - - /** - * Returns the image descriptor registry for this plugin. - * - * @return HashMap - image descriptor registry for this plugin - */ - private HashMap getImageDescriptorRegistry() { - if (fImageDescRegistry == null) { - fImageDescRegistry = new HashMap(); - } - return fImageDescRegistry; - } - - /** - * Returns the image registry for this plugin. - * - * @return ImageRegistry - image registry for this plugin - */ - private ImageRegistry getImageRegistry() { - return JFaceResources.getImageRegistry(); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/editor/XMLEditorPluginImages.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/editor/XMLEditorPluginImages.java deleted file mode 100644 index a13408d8e5..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/editor/XMLEditorPluginImages.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.editor; - -/** - * Bundle of most images used by the XML Source Editor plug-in. - */ -public class XMLEditorPluginImages { - - public static final String IMG_DTOOL_CONSTRAINOFF = "icons/full/dtool16/constrainoff.gif"; //$NON-NLS-1$ - public static final String IMG_DTOOL_CONSTRAINON = "icons/full/dtool16/constrainon.gif"; //$NON-NLS-1$ - public static final String IMG_DTOOL_RLDGRMR = "icons/full/dtool16/rldgrmr.gif"; //$NON-NLS-1$ - public static final String IMG_DTOOL_VALIDATE = "icons/full/dtool16/validate.gif"; //$NON-NLS-1$ - public static final String IMG_ETOOL_CONSTRAINOFF = "icons/full/etool16/constrainoff.gif"; //$NON-NLS-1$ - public static final String IMG_ETOOL_CONSTRAINON = "icons/full/etool16/constrainon.gif"; //$NON-NLS-1$ - public static final String IMG_ETOOL_RLDGRMR = "icons/full/etool16/rldgrmr.gif"; //$NON-NLS-1$ - public static final String IMG_ETOOL_VALIDATE = "icons/full/etool16/validate.gif"; //$NON-NLS-1$ - public static final String IMG_OBJ_ADD_CORRECTION = "icons/full/obj16/add_correction.gif"; //$NON-NLS-1$ - public static final String IMG_OBJ_ATT_REQ_OBJ = "icons/full/obj16/att_req_obj.gif"; //$NON-NLS-1$ - - public static final String IMG_OBJ_ATTRIBUTE = "icons/full/obj16/attribute_obj.gif"; //$NON-NLS-1$ - public static final String IMG_OBJ_CDATASECTION = "icons/full/obj16/cdatasection.gif"; //$NON-NLS-1$ - public static final String IMG_OBJ_COMMENT = "icons/full/obj16/comment_obj.gif"; //$NON-NLS-1$ - public static final String IMG_OBJ_CORRECTION_CHANGE = "icons/full/obj16/correction_change.gif"; //$NON-NLS-1$ - public static final String IMG_OBJ_DOCTYPE = "icons/full/obj16/doctype.gif"; //$NON-NLS-1$ - public static final String IMG_OBJ_DTDFILE = "icons/full/obj16/dtdfile.gif"; //$NON-NLS-1$ - public static final String IMG_OBJ_ELEMENT = "icons/full/obj16/element_obj.gif"; //$NON-NLS-1$ - public static final String IMG_OBJ_ENTITY = "icons/full/obj16/entity.gif"; //$NON-NLS-1$ - public static final String IMG_OBJ_ENTITY_REFERENCE = "icons/full/obj16/entity_reference.gif"; //$NON-NLS-1$ - public static final String IMG_OBJ_ENUM = "icons/full/obj16/enum.gif"; //$NON-NLS-1$ - public static final String IMG_OBJ_LOCAL_VARIABLE = "icons/full/obj16/localvariable_obj.gif"; //$NON-NLS-1$ - public static final String IMG_OBJ_NOTATION = "icons/full/obj16/notation.gif"; //$NON-NLS-1$ - public static final String IMG_OBJ_PROCESSINGINSTRUCTION = "icons/full/obj16/proinst_obj.gif"; //$NON-NLS-1$ - public static final String IMG_OBJ_SORT = "icons/full/obj16/sort.gif"; //$NON-NLS-1$ - public static final String IMG_OBJ_TAG_GENERIC = "icons/full/obj16/tag-generic.gif"; //$NON-NLS-1$ - public static final String IMG_OBJ_TAG_GENERIC_DEEMPHASIZED = "icons/full/obj16/tag_generic_deemphasized_obj.gif"; //$NON-NLS-1$ - public static final String IMG_OBJ_TAG_GENERIC_EMPHASIZED = "icons/full/obj16/tag_generic_emphasized_obj.gif"; //$NON-NLS-1$ - public static final String IMG_OBJ_TAG_MACRO = "icons/full/obj16/tag-macro.gif"; //$NON-NLS-1$ - public static final String IMG_OBJ_TXTEXT = "icons/full/obj16/text.gif"; //$NON-NLS-1$ - public static final String IMG_OBJ_WARNING_OBJ = "icons/full/obj16/warning_obj.gif"; //$NON-NLS-1$ - public static final String IMG_OBJ_XSDFILE = "icons/full/obj16/XSDFile.gif"; //$NON-NLS-1$ - - public static final String IMG_OVR_ERROR = "icons/full/ovr16/error_ovr.gif"; //$NON-NLS-1$ - public static final String IMG_OVR_STALE_ERROR = "icons/full/ovr16/stale_error_ovr.gif"; //$NON-NLS-1$ - public static final String IMG_OVR_WARN = "icons/full/ovr16/warn_ovr.gif"; //$NON-NLS-1$ - - public static final String IMG_WIZBAN_GENERATEXML = "icons/full/wizban/generatexml_wiz.png"; //$NON-NLS-1$ -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/AbstractSiblingNavigationHandler.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/AbstractSiblingNavigationHandler.java deleted file mode 100644 index 4e0565bbf2..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/AbstractSiblingNavigationHandler.java +++ /dev/null @@ -1,92 +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.wst.xml.ui.internal.handlers; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.handlers.HandlerUtil; -import org.eclipse.ui.texteditor.ITextEditor; -import org.w3c.dom.Attr; -import org.w3c.dom.Node; - -/** - * Provides navigation to next/previous DOM sibling Nodes - */ -abstract public class AbstractSiblingNavigationHandler extends AbstractHandler { - - public Object execute(ExecutionEvent event) throws ExecutionException { - IEditorPart editor = HandlerUtil.getActiveEditor(event); - ITextEditor textEditor = null; - if (editor instanceof ITextEditor) - textEditor = (ITextEditor) editor; - else { - Object o = editor.getAdapter(ITextEditor.class); - if (o != null) - textEditor = (ITextEditor) o; - } - if (textEditor != null) { - - ISelection selection = textEditor.getSelectionProvider().getSelection(); - if (!selection.isEmpty() && selection instanceof IStructuredSelection) { - Object o = ((IStructuredSelection) selection).getFirstElement(); - if (o instanceof Node) { - Node sibling = null; - - if (((Node) o).getNodeType() == Node.ATTRIBUTE_NODE) { - o = ((Attr) o).getOwnerElement(); - } - if (moveForward()) { - sibling = ((Node) o).getNextSibling(); - while (sibling != null && sibling.getNodeType() == Node.TEXT_NODE && sibling.getNodeValue().trim().length() == 0) { - sibling = sibling.getNextSibling(); - } - if (sibling == null) { - sibling = ((Node) o).getParentNode().getFirstChild(); - while (sibling != null && sibling.getNodeType() == Node.TEXT_NODE && sibling.getNodeValue().trim().length() == 0) { - sibling = sibling.getNextSibling(); - } - } - } - else { - sibling = ((Node) o).getPreviousSibling(); - while (sibling != null && sibling.getNodeType() == Node.TEXT_NODE && sibling.getNodeValue().trim().length() == 0) { - sibling = sibling.getPreviousSibling(); - } - if (sibling == null) { - sibling = ((Node) o).getParentNode().getLastChild(); - while (sibling != null && sibling.getNodeType() == Node.TEXT_NODE && sibling.getNodeValue().trim().length() == 0) { - sibling = sibling.getPreviousSibling(); - } - } - } - - // The only child is a Text Node, go to the parent Node - if (((Node) o).getNodeType() == Node.TEXT_NODE && o.equals(sibling)) { - sibling = ((Node) o).getParentNode(); - } - - - if (sibling != null) { - textEditor.getSelectionProvider().setSelection(new StructuredSelection(sibling)); - } - } - } - } - return null; - } - - abstract protected boolean moveForward(); -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/AddBlockCommentHandler.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/AddBlockCommentHandler.java deleted file mode 100644 index 475f37a1f8..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/AddBlockCommentHandler.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Standards for Technology in Automotive Retail and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms 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 Carver - initial API and implementation, bug 212330 - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.handlers; - -import org.eclipse.core.commands.IHandler; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.xml.core.internal.document.CommentImpl; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; - -public class AddBlockCommentHandler extends CommentHandler implements IHandler { - - public AddBlockCommentHandler() { - super(); - } - - void processAction(ITextEditor textEditor, IDocument document, ITextSelection textSelection) { - IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForEdit(document); - if (model != null) { - try { - IndexedRegion selectionStartIndexedRegion = model.getIndexedRegion(textSelection.getOffset()); - IndexedRegion selectionEndIndexedRegion = model.getIndexedRegion(textSelection.getOffset() + textSelection.getLength()); - - if (selectionStartIndexedRegion == null) { - return; - } - if ((selectionEndIndexedRegion == null) && (textSelection.getLength() > 0)) { - selectionEndIndexedRegion = model.getIndexedRegion(textSelection.getOffset() + textSelection.getLength() - 1); - } - if (selectionEndIndexedRegion == null) { - return; - } - - int openCommentOffset = selectionStartIndexedRegion.getStartOffset(); - int closeCommentOffset = selectionEndIndexedRegion.getEndOffset() + OPEN_COMMENT.length(); - - if ((textSelection.getLength() == 0) && (selectionStartIndexedRegion instanceof CommentImpl)) { - return; - } - - model.beginRecording(this, XMLUIMessages.AddBlockComment_tooltip); - model.aboutToChangeModel(); - - try { - document.replace(openCommentOffset, 0, OPEN_COMMENT); - document.replace(closeCommentOffset, 0, CLOSE_COMMENT); - super.removeOpenCloseComments(document, openCommentOffset + OPEN_COMMENT.length(), closeCommentOffset - openCommentOffset - CLOSE_COMMENT.length()); - } - catch (BadLocationException e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - finally { - model.changedModel(); - model.endRecording(this); - } - } - finally { - model.releaseFromEdit(); - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/CleanupdocumentHandler.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/CleanupdocumentHandler.java deleted file mode 100644 index 0d46a0e6d9..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/CleanupdocumentHandler.java +++ /dev/null @@ -1,119 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Standards for Technology in Automotive Retail and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms 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 Carver - initial API and implementation - bug 212330 - - * Based off CleanupActionXMLDelegate - *******************************************************************************/ - -package org.eclipse.wst.xml.ui.internal.handlers; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.commands.IHandler; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.handlers.HandlerUtil; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupProcessor; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.ui.internal.SSEUIMessages; -import org.eclipse.wst.xml.core.internal.cleanup.CleanupProcessorXML; -import org.eclipse.wst.xml.ui.internal.actions.CleanupDialogXML; - -public class CleanupdocumentHandler extends AbstractHandler implements IHandler { - private IStructuredCleanupProcessor fCleanupProcessor; - - public void dispose() { - // nulling out just in case - fCleanupProcessor = null; - } - - public Object execute(ExecutionEvent event) throws ExecutionException { - IEditorPart editor = HandlerUtil.getActiveEditor(event); - ITextEditor textEditor = null; - if (editor instanceof ITextEditor) - textEditor = (ITextEditor) editor; - else { - Object o = editor.getAdapter(ITextEditor.class); - if (o != null) - textEditor = (ITextEditor) o; - } - if (textEditor != null) { - final ITextEditor finalTextEditor = textEditor; - Dialog cleanupDialog = new CleanupDialogXML(editor.getSite().getShell()); - if (cleanupDialog.open() == Window.OK) { - // setup runnable - Runnable runnable = new Runnable() { - public void run() { - IStructuredCleanupProcessor cleanupProcessor = getCleanupProcessor(); - if (cleanupProcessor != null) { - IStructuredModel model = null; - try { - model = StructuredModelManager.getModelManager().getExistingModelForEdit(finalTextEditor.getDocumentProvider().getDocument(finalTextEditor.getEditorInput())); - if (model != null) { - cleanupProcessor.cleanupModel(model); - } - } - finally { - if (model != null) { - model.releaseFromEdit(); - } - } - } - } - }; - - // TODO: make independent of 'model'. - IStructuredModel model = null; - try { - model = StructuredModelManager.getModelManager().getExistingModelForEdit(textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput())); - if (model != null) { - // begin recording - ITextSelection selection = (ITextSelection) textEditor.getSelectionProvider().getSelection(); - model.beginRecording(this, SSEUIMessages.Cleanup_Document_UI_, SSEUIMessages.Cleanup_Document_UI_, selection.getOffset(), selection.getLength()); - - // tell the model that we are about to make a big - // model change - model.aboutToChangeModel(); - - // run - BusyIndicator.showWhile(textEditor.getEditorSite().getWorkbenchWindow().getShell().getDisplay(), runnable); - } - } - finally { - if (model != null) { - // tell the model that we are done with the big - // model - // change - model.changedModel(); - - // end recording - ITextSelection selection = (ITextSelection) textEditor.getSelectionProvider().getSelection(); - model.endRecording(this, selection.getOffset(), selection.getLength()); - model.releaseFromEdit(); - } - } - } - } - - return null; - } - - IStructuredCleanupProcessor getCleanupProcessor() { - if (fCleanupProcessor == null) { - fCleanupProcessor = new CleanupProcessorXML(); - } - - return fCleanupProcessor; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/CollapseAllHandler.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/CollapseAllHandler.java deleted file mode 100644 index 60c644be2e..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/CollapseAllHandler.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Standards for Technology in Automotive Retail and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms 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 Carver - initial API and implementation, bug 212330 - * - *******************************************************************************/ - -package org.eclipse.wst.xml.ui.internal.handlers; - -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.commands.IHandler; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.handlers.HandlerUtil; - -public class CollapseAllHandler extends ExpandCollapseAllHandler implements IHandler { - - /** - * - */ - public CollapseAllHandler() { - super(); - } - - /* (non-Javadoc) - * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) - */ - public Object execute(ExecutionEvent event) throws ExecutionException { - IEditorPart editorPart = HandlerUtil.getActiveEditor(event); - - viewer = getTableTreeViewerForEditorPart(editorPart); - - if (viewer != null) { - // temporarily set the visibility to false - // this has a HUGE performance benefit - boolean isVisible = viewer.getControl().getVisible(); - viewer.getControl().setVisible(false); - viewer.collapseAll(); - - // restore the previous visibility state - // - viewer.getControl().setVisible(isVisible); - } - - return null; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/CommentHandler.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/CommentHandler.java deleted file mode 100644 index 6188db2ca6..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/CommentHandler.java +++ /dev/null @@ -1,103 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Standards for Technology in Automotive Retail and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms 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 Carver - initial API and implementation, bug 212330 - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.handlers; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.commands.IHandler; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.text.TextSelection; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.handlers.HandlerUtil; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.wst.xml.ui.internal.Logger; - -public class CommentHandler extends AbstractHandler implements IHandler { - static final String CLOSE_COMMENT = "-->"; //$NON-NLS-1$ - static final String OPEN_COMMENT = "<!--"; //$NON-NLS-1$ - - public CommentHandler() { - super(); - } - - public Object execute(ExecutionEvent event) throws ExecutionException { - IEditorPart editor = HandlerUtil.getActiveEditor(event); - ITextEditor textEditor = null; - if (editor instanceof ITextEditor) - textEditor = (ITextEditor) editor; - else { - Object o = editor.getAdapter(ITextEditor.class); - if (o != null) - textEditor = (ITextEditor) o; - } - if (textEditor != null) { - IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()); - if (document != null) { - // get current text selection - ITextSelection textSelection = getCurrentSelection(textEditor); - if (textSelection.isEmpty()) { - return null; - } - - processAction(textEditor, document, textSelection); - } - } - - return null; - } - - protected ITextSelection getCurrentSelection(ITextEditor textEditor) { - ISelectionProvider provider = textEditor.getSelectionProvider(); - if (provider != null) { - ISelection selection = provider.getSelection(); - if (selection instanceof ITextSelection) { - return (ITextSelection) selection; - } - } - return TextSelection.emptySelection(); - } - - void processAction(ITextEditor textEditor, IDocument document, ITextSelection textSelection) { - // Implementations to over ride. - } - - protected void removeOpenCloseComments(IDocument document, int offset, int length) { - try { - int adjusted_length = length; - - // remove open comments - String string = document.get(offset, length); - int index = string.lastIndexOf(OPEN_COMMENT); - while (index != -1) { - document.replace(offset + index, OPEN_COMMENT.length(), ""); //$NON-NLS-1$ - index = string.lastIndexOf(OPEN_COMMENT, index - 1); - adjusted_length -= OPEN_COMMENT.length(); - } - - // remove close comments - string = document.get(offset, adjusted_length); - index = string.lastIndexOf(CLOSE_COMMENT); - while (index != -1) { - document.replace(offset + index, CLOSE_COMMENT.length(), ""); //$NON-NLS-1$ - index = string.lastIndexOf(CLOSE_COMMENT, index - 1); - } - } - catch (BadLocationException e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/ExpandAllHandler.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/ExpandAllHandler.java deleted file mode 100644 index 9091399bbc..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/ExpandAllHandler.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Standards for Technology in Automotive Retail and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms 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 Carver - initial API and implementation, bug 212330 - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.handlers; - -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.handlers.HandlerUtil; -import org.eclipse.wst.xml.ui.internal.tabletree.XMLTableTreeViewer; - -public class ExpandAllHandler extends ExpandCollapseAllHandler { - - protected XMLTableTreeViewer viewer = null; - - /** - * - */ - public ExpandAllHandler() { - super(); - } - - /* (non-Javadoc) - * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) - */ - public Object execute(ExecutionEvent event) throws ExecutionException { - - IEditorPart editorPart = HandlerUtil.getActiveEditor(event); - - viewer = getTableTreeViewerForEditorPart(editorPart); - - if (viewer != null) { - // temporarily set the visibility to false - // this has a HUGE performance benefit - boolean isVisible = viewer.getControl().getVisible(); - viewer.getControl().setVisible(false); - viewer.expandAll(); - - // restore the previous visibility state - // - viewer.getControl().setVisible(isVisible); - } - - return null; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/ExpandCollapseAllHandler.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/ExpandCollapseAllHandler.java deleted file mode 100644 index 52d40f4d5d..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/ExpandCollapseAllHandler.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Standards for Technology in Automotive Retail and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms 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 Carver - initial API and implementation, bug 212330 - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.handlers; - -import java.util.Map; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.commands.IElementUpdater; -import org.eclipse.ui.menus.UIElement; -import org.eclipse.wst.xml.ui.internal.tabletree.IDesignViewer; -import org.eclipse.wst.xml.ui.internal.tabletree.XMLTableTreeViewer; - -public class ExpandCollapseAllHandler extends AbstractHandler implements IElementUpdater { - - protected XMLTableTreeViewer viewer = null; - - /** - * Command handler for handling Expand and Collapse for Tree Viewer - */ - public ExpandCollapseAllHandler() { - super(); - } - - /* (non-Javadoc) - * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) - */ - public Object execute(ExecutionEvent event) throws ExecutionException { - // Implementors to put their code here. - - return null; - } - - protected XMLTableTreeViewer getTableTreeViewerForEditorPart(IEditorPart targetEditor) { - XMLTableTreeViewer result = null; - Object object = targetEditor.getAdapter(IDesignViewer.class); - if (object instanceof XMLTableTreeViewer) { - result = (XMLTableTreeViewer) object; - } - return result; - } - - public void updateElement(UIElement element, Map parameters) { - // TODO Auto-generated method stub - - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/NextSiblingNavigationHandler.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/NextSiblingNavigationHandler.java deleted file mode 100644 index c25951cc89..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/NextSiblingNavigationHandler.java +++ /dev/null @@ -1,19 +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.wst.xml.ui.internal.handlers; - -public class NextSiblingNavigationHandler extends AbstractSiblingNavigationHandler { - - protected boolean moveForward() { - return true; - } - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/PreviousSiblingNavigationHandler.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/PreviousSiblingNavigationHandler.java deleted file mode 100644 index 3442a8b523..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/PreviousSiblingNavigationHandler.java +++ /dev/null @@ -1,19 +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.wst.xml.ui.internal.handlers; - -public class PreviousSiblingNavigationHandler extends AbstractSiblingNavigationHandler { - - protected boolean moveForward() { - return false; - } - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/ReloadDependenciesHandler.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/ReloadDependenciesHandler.java deleted file mode 100644 index c371a18e21..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/ReloadDependenciesHandler.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Standards for Technology in Automotive Retail and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms 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 Carver - initial API and implementation, bug 212330 - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.handlers; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.commands.IHandler; -import org.eclipse.jface.text.IDocument; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.handlers.HandlerUtil; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl.CMDocumentLoader; -import org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl.InferredGrammarBuildingCMDocumentLoader; -import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; -import org.w3c.dom.Document; - -public class ReloadDependenciesHandler extends AbstractHandler implements IHandler { - protected IStructuredModel model; - - /** - * - */ - public ReloadDependenciesHandler() { - // TODO Auto-generated constructor stub - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) - */ - public Object execute(ExecutionEvent event) throws ExecutionException { - IEditorPart editor = HandlerUtil.getActiveEditor(event); - ITextEditor textEditor = null; - if (editor instanceof ITextEditor) - textEditor = (ITextEditor) editor; - else { - Object o = editor.getAdapter(ITextEditor.class); - if (o != null) - textEditor = (ITextEditor) o; - } - if (textEditor != null) { - IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()); - IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(document); - if (model != null) { - ModelQuery modelQuery = null; - try { - modelQuery = ModelQueryUtil.getModelQuery(model); - } - finally { - model.releaseFromRead(); - } - Document domDocument = ((IDOMModel) model).getDocument(); - if ((modelQuery != null) && (modelQuery.getCMDocumentManager() != null)) { - modelQuery.getCMDocumentManager().getCMDocumentCache().clear(); - // TODO... need to figure out how to access the - // DOMObserver via ModelQuery - // ...why? - CMDocumentLoader loader = new InferredGrammarBuildingCMDocumentLoader(domDocument, modelQuery); - loader.loadCMDocuments(); - } - } - } - return null; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/RemoveBlockCommentHandler.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/RemoveBlockCommentHandler.java deleted file mode 100644 index b4080bf944..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/RemoveBlockCommentHandler.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Standards for Technology in Automotive Retail and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms 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 Carver - initial API and implementation, bug 212330 - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.handlers; - -import org.eclipse.core.commands.IHandler; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.xml.core.internal.document.CommentImpl; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; - -/** - * @author dcarver - * - */ -public class RemoveBlockCommentHandler extends CommentHandler implements IHandler { - - public RemoveBlockCommentHandler() { - super(); - } - - void processAction(ITextEditor textEditor, IDocument document, ITextSelection textSelection) { - IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForEdit(document); - if (model != null) { - try { - IndexedRegion selectionStartIndexedRegion = model.getIndexedRegion(textSelection.getOffset()); - IndexedRegion selectionEndIndexedRegion = model.getIndexedRegion(textSelection.getOffset() + textSelection.getLength()); - - if ((selectionStartIndexedRegion == null) || (selectionEndIndexedRegion == null)) { - return; - } - - int openCommentOffset = selectionStartIndexedRegion.getStartOffset(); - int closeCommentOffset = selectionEndIndexedRegion.getEndOffset() - OPEN_COMMENT.length() - CLOSE_COMMENT.length(); - - model.beginRecording(this, XMLUIMessages.RemoveBlockComment_tooltip); - model.aboutToChangeModel(); - - try { - if (textSelection.getLength() == 0) { - if (selectionStartIndexedRegion instanceof CommentImpl) { - document.replace(openCommentOffset, OPEN_COMMENT.length(), ""); //$NON-NLS-1$ - document.replace(closeCommentOffset, CLOSE_COMMENT.length(), ""); //$NON-NLS-1$ - } - } - else { - if (selectionStartIndexedRegion instanceof CommentImpl) { - document.replace(openCommentOffset, OPEN_COMMENT.length(), ""); //$NON-NLS-1$ - } - - if (selectionEndIndexedRegion instanceof CommentImpl) { - document.replace(closeCommentOffset, CLOSE_COMMENT.length(), ""); //$NON-NLS-1$ - } - } - removeOpenCloseComments(document, openCommentOffset + OPEN_COMMENT.length(), closeCommentOffset - openCommentOffset - CLOSE_COMMENT.length()); - } - catch (BadLocationException e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - finally { - model.changedModel(); - model.endRecording(this); - } - } - finally { - model.releaseFromEdit(); - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/StructuredSelectEnclosingXMLHandler.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/StructuredSelectEnclosingXMLHandler.java deleted file mode 100644 index f043b6e1b6..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/StructuredSelectEnclosingXMLHandler.java +++ /dev/null @@ -1,59 +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.wst.xml.ui.internal.handlers; - -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.text.Region; -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.sse.ui.internal.handlers.AbstractStructuredSelectHandler; -import org.w3c.dom.Node; - -public class StructuredSelectEnclosingXMLHandler extends AbstractStructuredSelectHandler { - protected IndexedRegion getCursorIndexedRegion(IDocument document, ITextSelection textSelection) { - IndexedRegion indexedRegion = null; - - indexedRegion = getIndexedRegion(document, textSelection.getOffset()); - - return indexedRegion; - } - - protected Region getNewSelectionRegion(IndexedRegion indexedRegion, ITextSelection textSelection) { - Region newRegion = null; - if (indexedRegion instanceof Node) { - Node cursorNode = (Node) indexedRegion; - - // use parent node for empty text node - if ((cursorNode.getNodeType() == Node.TEXT_NODE) && (cursorNode.getNodeValue().trim().length() == 0)) { - cursorNode = cursorNode.getParentNode(); - - if (cursorNode instanceof IndexedRegion) { - indexedRegion = (IndexedRegion) cursorNode; - } - } - - Region cursorNodeRegion = new Region(indexedRegion.getStartOffset(), indexedRegion.getEndOffset() - indexedRegion.getStartOffset()); - - if ((cursorNodeRegion.getOffset() >= textSelection.getOffset()) && (cursorNodeRegion.getOffset() <= textSelection.getOffset() + textSelection.getLength()) && (cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() >= textSelection.getOffset()) && (cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() <= textSelection.getOffset() + textSelection.getLength())) { - Node newNode = cursorNode.getParentNode(); - - if (newNode instanceof IndexedRegion) { - IndexedRegion newIndexedRegion = (IndexedRegion) newNode; - newRegion = new Region(newIndexedRegion.getStartOffset(), newIndexedRegion.getEndOffset() - newIndexedRegion.getStartOffset()); - } - } - else { - newRegion = cursorNodeRegion; - } - } - return newRegion; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/StructuredSelectNextXMLHandler.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/StructuredSelectNextXMLHandler.java deleted file mode 100644 index 366789fc29..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/StructuredSelectNextXMLHandler.java +++ /dev/null @@ -1,97 +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.wst.xml.ui.internal.handlers; - -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.text.Region; -import org.eclipse.jface.text.TextSelection; -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.sse.ui.internal.handlers.AbstractStructuredSelectHandler; -import org.w3c.dom.Node; - -public class StructuredSelectNextXMLHandler extends AbstractStructuredSelectHandler { - - protected IndexedRegion getCursorIndexedRegion(IDocument document, ITextSelection textSelection) { - int offset = textSelection.getOffset() + textSelection.getLength() - 1; - if (offset < 0) { - offset = 0; - } - - IndexedRegion indexedRegion = null; - - indexedRegion = getIndexedRegion(document, offset); - - return indexedRegion; - } - - protected Region getNewSelectionRegion(IndexedRegion indexedRegion, ITextSelection textSelection) { - Region newRegion = null; - if (indexedRegion instanceof Node) { - Node cursorNode = (Node) indexedRegion; - - // use parent node for empty text node - if ((cursorNode.getNodeType() == Node.TEXT_NODE) && (cursorNode.getNodeValue().trim().length() == 0)) { - cursorNode = cursorNode.getParentNode(); - - if (cursorNode instanceof IndexedRegion) { - indexedRegion = (IndexedRegion) cursorNode; - } - } - - Region cursorNodeRegion = new Region(indexedRegion.getStartOffset(), indexedRegion.getEndOffset() - indexedRegion.getStartOffset()); - int currentOffset = textSelection.getOffset(); - int currentEndOffset = currentOffset + textSelection.getLength(); - if ((cursorNodeRegion.getOffset() >= currentOffset) && (cursorNodeRegion.getOffset() <= currentEndOffset) && (cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() >= currentOffset) && (cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() <= currentEndOffset)) { - newRegion = getNewSelectionRegion2(indexedRegion, textSelection); - } - else { - newRegion = cursorNodeRegion; - } - } - return newRegion; - } - - /** - * This method was separated out from getNewSelectionRegion2 because the - * code in here is allowed to be called recursively. - * - * @param indexedRegion - * @param textSelection - * @return new region to select or null if none - */ - private Region getNewSelectionRegion2(IndexedRegion indexedRegion, ITextSelection textSelection) { - Region newRegion = null; - if (indexedRegion instanceof Node) { - Node node = (Node) indexedRegion; - Node newNode = node.getNextSibling(); - if (newNode == null) { - newNode = node.getParentNode(); - - if (newNode instanceof IndexedRegion) { - IndexedRegion newIndexedRegion = (IndexedRegion) newNode; - newRegion = new Region(newIndexedRegion.getStartOffset(), newIndexedRegion.getEndOffset() - newIndexedRegion.getStartOffset()); - } - } - else { - if (newNode instanceof IndexedRegion) { - IndexedRegion newIndexedRegion = (IndexedRegion) newNode; - newRegion = new Region(textSelection.getOffset(), newIndexedRegion.getEndOffset() - textSelection.getOffset()); - - if (newNode.getNodeType() == Node.TEXT_NODE) { - newRegion = getNewSelectionRegion2(newIndexedRegion, new TextSelection(newRegion.getOffset(), newRegion.getLength())); - } - } - } - } - return newRegion; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/StructuredSelectPreviousXMLHandler.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/StructuredSelectPreviousXMLHandler.java deleted file mode 100644 index ab57447cee..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/StructuredSelectPreviousXMLHandler.java +++ /dev/null @@ -1,75 +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.wst.xml.ui.internal.handlers; - -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.text.Region; -import org.eclipse.jface.text.TextSelection; -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.sse.ui.internal.handlers.AbstractStructuredSelectHandler; -import org.w3c.dom.Node; - -public class StructuredSelectPreviousXMLHandler extends AbstractStructuredSelectHandler { - - protected IndexedRegion getCursorIndexedRegion(IDocument document, ITextSelection textSelection) { - IndexedRegion indexedRegion = null; - - indexedRegion = getIndexedRegion(document, textSelection.getOffset()); - - return indexedRegion; - } - - protected Region getNewSelectionRegion(IndexedRegion indexedRegion, ITextSelection textSelection) { - Region newRegion = null; - if (indexedRegion instanceof Node) { - Node cursorNode = (Node) indexedRegion; - - // use parent node for empty text node - if ((cursorNode.getNodeType() == Node.TEXT_NODE) && (cursorNode.getNodeValue().trim().length() == 0)) { - cursorNode = cursorNode.getParentNode(); - - if (cursorNode instanceof IndexedRegion) { - indexedRegion = (IndexedRegion) cursorNode; - } - } - - Region cursorNodeRegion = new Region(indexedRegion.getStartOffset(), indexedRegion.getEndOffset() - indexedRegion.getStartOffset()); - - if ((cursorNodeRegion.getOffset() >= textSelection.getOffset()) && (cursorNodeRegion.getOffset() <= textSelection.getOffset() + textSelection.getLength()) && (cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() >= textSelection.getOffset()) && (cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() <= textSelection.getOffset() + textSelection.getLength())) { - Node newNode = cursorNode.getPreviousSibling(); - if (newNode == null) { - newNode = cursorNode.getParentNode(); - - if (newNode instanceof IndexedRegion) { - IndexedRegion newIndexedRegion = (IndexedRegion) newNode; - newRegion = new Region(newIndexedRegion.getStartOffset(), newIndexedRegion.getEndOffset() - newIndexedRegion.getStartOffset()); - } - } - else { - if (newNode instanceof IndexedRegion) { - IndexedRegion newIndexedRegion = (IndexedRegion) newNode; - newRegion = new Region(newIndexedRegion.getStartOffset(), textSelection.getOffset() + textSelection.getLength() - newIndexedRegion.getStartOffset()); - - if (newNode.getNodeType() == Node.TEXT_NODE) { - newRegion = getNewSelectionRegion(newIndexedRegion, new TextSelection(newRegion.getOffset(), newRegion.getLength())); - } - } - } - - } - else { - newRegion = cursorNodeRegion; - } - } - return newRegion; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/ToggleCommentHandler.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/ToggleCommentHandler.java deleted file mode 100644 index 174f680bbb..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/ToggleCommentHandler.java +++ /dev/null @@ -1,193 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Standards for Technology in Automotive Retail and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms 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 Carver - initial API and implementation, bug 212330 - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.handlers; - -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.commands.IHandler; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.text.Position; -import org.eclipse.jface.text.TextSelection; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.handlers.HandlerUtil; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; - -public class ToggleCommentHandler extends CommentHandler implements IHandler { - public ToggleCommentHandler() { - super(); - } - - public Object execute(ExecutionEvent event) throws ExecutionException { - IEditorPart editor = HandlerUtil.getActiveEditor(event); - ITextEditor textEditor = null; - if (editor instanceof ITextEditor) - textEditor = (ITextEditor) editor; - else { - Object o = editor.getAdapter(ITextEditor.class); - if (o != null) - textEditor = (ITextEditor) o; - } - if (textEditor != null) { - IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()); - if (document != null) { - // get current text selection - ITextSelection textSelection = getCurrentSelection(textEditor); - if (textSelection.isEmpty()) { - return null; - } - - processAction(textEditor, document, textSelection); - } - } - return null; - } - - void processAction(ITextEditor textEditor, IDocument document, ITextSelection textSelection) { - // get text selection lines info - int selectionStartLine = textSelection.getStartLine(); - int selectionEndLine = textSelection.getEndLine(); - try { - int selectionEndLineOffset = document.getLineOffset(selectionEndLine); - int selectionEndOffset = textSelection.getOffset() + textSelection.getLength(); - - // adjust selection end line - if ((selectionEndLine > selectionStartLine) && (selectionEndLineOffset == selectionEndOffset)) { - selectionEndLine--; - } - - } - catch (BadLocationException e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - - // save the selection position since it will be changing - Position selectionPosition = null; - boolean updateStartOffset = false; - try { - selectionPosition = new Position(textSelection.getOffset(), textSelection.getLength()); - document.addPosition(selectionPosition); - - // extra check if commenting from beginning of line - int selectionStartLineOffset = document.getLineOffset(selectionStartLine); - if ((textSelection.getLength() > 0) && (selectionStartLineOffset == textSelection.getOffset()) && !isCommentLine(document, selectionStartLine)) { - updateStartOffset = true; - } - } - catch (BadLocationException e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - - processAction(document, selectionStartLine, selectionEndLine); - - updateCurrentSelection(textEditor, selectionPosition, document, updateStartOffset); - } - - private void processAction(IDocument document, int selectionStartLine, int selectionEndLine) { - IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForEdit(document); - if (model != null) { - try { - model.beginRecording(this, XMLUIMessages.ToggleComment_tooltip); - model.aboutToChangeModel(); - - for (int i = selectionStartLine; i <= selectionEndLine; i++) { - try { - if (document.getLineLength(i) > 0) { - if (isCommentLine(document, i)) { - int lineOffset = document.getLineOffset(i); - IRegion region = document.getLineInformation(i); - String string = document.get(region.getOffset(), region.getLength()); - int openCommentOffset = lineOffset + string.indexOf(OPEN_COMMENT); - int closeCommentOffset = lineOffset + string.indexOf(CLOSE_COMMENT) - OPEN_COMMENT.length(); - uncomment(document, openCommentOffset, closeCommentOffset); - } - else { - int openCommentOffset = document.getLineOffset(i); - int lineDelimiterLength = document.getLineDelimiter(i) == null ? 0 : document.getLineDelimiter(i).length(); - int closeCommentOffset = openCommentOffset + document.getLineLength(i) - lineDelimiterLength + OPEN_COMMENT.length(); - comment(document, openCommentOffset, closeCommentOffset); - } - } - } - catch (BadLocationException e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - } - } - finally { - model.changedModel(); - model.endRecording(this); - model.releaseFromEdit(); - } - } - } - - private boolean isCommentLine(IDocument document, int line) { - boolean isComment = false; - - try { - IRegion region = document.getLineInformation(line); - String string = document.get(region.getOffset(), region.getLength()).trim(); - isComment = (string.length() >= OPEN_COMMENT.length() + CLOSE_COMMENT.length()) && string.startsWith(OPEN_COMMENT) && string.endsWith(CLOSE_COMMENT); - } - catch (BadLocationException e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - return isComment; - } - - private void comment(IDocument document, int openCommentOffset, int closeCommentOffset) { - try { - document.replace(openCommentOffset, 0, OPEN_COMMENT); - document.replace(closeCommentOffset, 0, CLOSE_COMMENT); - removeOpenCloseComments(document, openCommentOffset + OPEN_COMMENT.length(), closeCommentOffset - openCommentOffset - CLOSE_COMMENT.length()); - } - catch (BadLocationException e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - } - - private void uncomment(IDocument document, int openCommentOffset, int closeCommentOffset) { - try { - document.replace(openCommentOffset, OPEN_COMMENT.length(), ""); //$NON-NLS-1$ - document.replace(closeCommentOffset, CLOSE_COMMENT.length(), ""); //$NON-NLS-1$ - } - catch (BadLocationException e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - } - - private void updateCurrentSelection(ITextEditor textEditor, Position selectionPosition, IDocument document, boolean updateStartOffset) { - // update the selection if text selection changed - if (selectionPosition != null) { - ITextSelection selection = null; - if (updateStartOffset) { - selection = new TextSelection(document, selectionPosition.getOffset() - OPEN_COMMENT.length(), selectionPosition.getLength() + OPEN_COMMENT.length()); - } - else { - selection = new TextSelection(document, selectionPosition.getOffset(), selectionPosition.getLength()); - } - ISelectionProvider provider = textEditor.getSelectionProvider(); - if (provider != null) { - provider.setSelection(selection); - } - document.removePosition(selectionPosition); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/ToggleEditModeHandler.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/ToggleEditModeHandler.java deleted file mode 100644 index 85e4f594c2..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/ToggleEditModeHandler.java +++ /dev/null @@ -1,137 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Standards for Technology in Automotive Retail and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms 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 Carver - initial API and implementation, bug 212330 - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.handlers; - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.text.IDocument; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.commands.ICommandService; -import org.eclipse.ui.commands.IElementUpdater; -import org.eclipse.ui.handlers.HandlerUtil; -import org.eclipse.ui.menus.UIElement; -import org.eclipse.ui.services.IServiceScopes; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.internal.tabletree.XMLEditorMessages; -import org.eclipse.wst.xml.ui.internal.util.SharedXMLEditorPluginImageHelper; - -public class ToggleEditModeHandler extends AbstractHandler implements IElementUpdater { - protected ImageDescriptor onImage = SharedXMLEditorPluginImageHelper.getImageDescriptor(SharedXMLEditorPluginImageHelper.IMG_ETOOL_CONSTRAINON); - protected ImageDescriptor offImage = SharedXMLEditorPluginImageHelper.getImageDescriptor(SharedXMLEditorPluginImageHelper.IMG_ETOOL_CONSTRAINOFF); - protected ModelQuery modelQuery; - - public ToggleEditModeHandler() { - super(); - } - - public Object execute(ExecutionEvent event) throws ExecutionException { - IEditorPart editor = HandlerUtil.getActiveEditor(event); - ITextEditor textEditor = null; - if (editor instanceof ITextEditor) - textEditor = (ITextEditor) editor; - else { - Object o = editor.getAdapter(ITextEditor.class); - if (o != null) - textEditor = (ITextEditor) o; - } - if (textEditor != null) { - IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()); - IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(document); - if (model != null) { - try { - modelQuery = ModelQueryUtil.getModelQuery(model); - } - finally { - model.releaseFromRead(); - } - if (modelQuery != null) { - int newState = getNextState(modelQuery.getEditMode()); - modelQuery.setEditMode(newState); - - // Force a Refresh on this command so that the image can - // be - // updated. - ICommandService commandService = (ICommandService) HandlerUtil.getActiveWorkbenchWindow(event).getService(ICommandService.class); - Map filter = new HashMap(); - filter.put(IServiceScopes.WINDOW_SCOPE, HandlerUtil.getActiveWorkbenchWindow(event)); - commandService.refreshElements(event.getCommand().getId(), filter); - } - } - } - - return null; - } - - public int getNextState(int editMode) { - int result = -1; - if (editMode == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) { - result = ModelQuery.EDIT_MODE_UNCONSTRAINED; - } - else { - result = ModelQuery.EDIT_MODE_CONSTRAINED_STRICT; - } - return result; - } - - - // Handlers that need to interact with the ui that the command came from - // need to use implement this method. - public void updateElement(UIElement element, Map parameters) { - IEditorPart editor = XMLUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); - ITextEditor textEditor = null; - if (editor instanceof ITextEditor) - textEditor = (ITextEditor) editor; - else { - Object o = editor.getAdapter(ITextEditor.class); - if (o != null) - textEditor = (ITextEditor) o; - } - if (textEditor != null) { - IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()); - IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(document); - if (model != null) { - try { - modelQuery = ModelQueryUtil.getModelQuery(model); - } - finally { - model.releaseFromRead(); - } - if (modelQuery != null) { - setAppearanceForEditMode(modelQuery.getEditMode(), element); - } - } - } - } - - public void setAppearanceForEditMode(int editMode, UIElement element) { - if (editMode == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) { - element.setTooltip(XMLEditorMessages.XMLTableTreeActionBarContributor_3); - element.setText(XMLEditorMessages.XMLTableTreeActionBarContributor_3); - element.setIcon(onImage); - } - else { - element.setTooltip(XMLEditorMessages.XMLTableTreeActionBarContributor_5); - element.setText(XMLEditorMessages.XMLTableTreeActionBarContributor_5); - element.setIcon(offImage); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/XMLFindOccurencesHandler.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/XMLFindOccurencesHandler.java deleted file mode 100644 index 56c28bdea5..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/handlers/XMLFindOccurencesHandler.java +++ /dev/null @@ -1,137 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Standards for Technology in Automotive Retail and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms 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 Carver - initial API and implementation - bug 212330 - - * Based off CleanupActionXMLDelegate - *******************************************************************************/ - -package org.eclipse.wst.xml.ui.internal.handlers; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.commands.IHandler; -import org.eclipse.core.resources.IFile; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.text.ITypedRegion; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IFileEditorInput; -import org.eclipse.ui.handlers.HandlerUtil; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.wst.sse.ui.internal.SSEUIMessages; -import org.eclipse.wst.sse.ui.internal.search.FindOccurrencesProcessor; -import org.eclipse.wst.sse.ui.internal.util.PlatformStatusLineUtil; -import org.eclipse.wst.xml.ui.internal.search.XMLFindOccurrencesProcessor; - -public class XMLFindOccurencesHandler extends AbstractHandler implements IHandler { - private List fProcessors; - - public void dispose() { - } - - public Object execute(ExecutionEvent event) throws ExecutionException { - IEditorPart editor = HandlerUtil.getActiveEditor(event); - ITextEditor textEditor = null; - boolean okay = false; - - if (editor instanceof ITextEditor) - textEditor = (ITextEditor) editor; - else { - Object o = editor.getAdapter(ITextEditor.class); - if (o != null) - textEditor = (ITextEditor) o; - } - - if (textEditor != null) { - IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()); - if (document != null) { - ITextSelection textSelection = getTextSelection(textEditor); - FindOccurrencesProcessor findOccurrenceProcessor = getProcessorForCurrentSelection(document, textSelection); - if (findOccurrenceProcessor != null) { - if (textEditor.getEditorInput() instanceof IFileEditorInput) { - IFile file = ((IFileEditorInput) textEditor.getEditorInput()).getFile(); - okay = findOccurrenceProcessor.findOccurrences(document, textSelection, file); - } - } - } - } - if (okay) { - // clear status message - PlatformStatusLineUtil.clearStatusLine(); - } - else { - String errorMessage = SSEUIMessages.FindOccurrencesActionProvider_0; //$NON-NLS-1$ - PlatformStatusLineUtil.displayErrorMessage(errorMessage); - PlatformStatusLineUtil.addOneTimeClearListener(); - } - - return null; - } - - /** - * Get the appropriate find occurrences processor - * - * @param document - - * assumes not null - * @param textSelection - * @return FindOccurrencesProcessor - */ - private FindOccurrencesProcessor getProcessorForCurrentSelection(IDocument document, ITextSelection textSelection) { - // check if we have an action that's enabled on the current partition - ITypedRegion tr = getPartition(document, textSelection); - String partition = tr != null ? tr.getType() : ""; //$NON-NLS-1$ - - Iterator it = getProcessors().iterator(); - FindOccurrencesProcessor action = null; - while (it.hasNext()) { - action = (FindOccurrencesProcessor) it.next(); - // we just choose the first action that can handle the partition - if (action.enabledForParitition(partition)) - return action; - } - return null; - } - - private ITypedRegion getPartition(IDocument document, ITextSelection textSelection) { - ITypedRegion region = null; - if (textSelection != null) { - try { - region = document.getPartition(textSelection.getOffset()); - } - catch (BadLocationException e) { - region = null; - } - } - return region; - } - - private ITextSelection getTextSelection(ITextEditor textEditor) { - ITextSelection textSelection = null; - ISelection selection = textEditor.getSelectionProvider().getSelection(); - if (selection instanceof ITextSelection && !selection.isEmpty()) { - textSelection = (ITextSelection) selection; - } - return textSelection; - } - - protected List getProcessors() { - if (fProcessors == null) { - fProcessors = new ArrayList(); - XMLFindOccurrencesProcessor htmlProcessor = new XMLFindOccurrencesProcessor(); - fProcessors.add(htmlProcessor); - } - return fProcessors; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/hyperlink/CatalogEntryHyperlink.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/hyperlink/CatalogEntryHyperlink.java deleted file mode 100644 index 346f10aa65..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/hyperlink/CatalogEntryHyperlink.java +++ /dev/null @@ -1,101 +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.wst.xml.ui.internal.hyperlink; - -import java.io.File; - -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.hyperlink.IHyperlink; -import org.eclipse.jface.text.hyperlink.URLHyperlink; -import org.eclipse.osgi.util.NLS; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; - -class CatalogEntryHyperlink implements IHyperlink { - - private IRegion fHyperlinkRegion = null; - private ICatalogEntry fEntry = null; - - /** - * @param hyperlinkRegion - * @param entry - */ - CatalogEntryHyperlink(IRegion hyperlinkRegion, ICatalogEntry entry) { - super(); - fHyperlinkRegion = hyperlinkRegion; - fEntry = entry; - } - - /** - * @return - */ - private IHyperlink getHyperlink() { - if (fEntry.getURI().startsWith("file:")) { //$NON-NLS-1$ - return new ExternalFileHyperlink(fHyperlinkRegion, new File(fEntry.getURI().substring(5))); - } - else if (fEntry.getURI().startsWith("platform:/resource/")) { //$NON-NLS-1$ - IPath path = new Path(fEntry.getURI().substring(20)); - if (path.segmentCount() > 1) - return new WorkspaceFileHyperlink(fHyperlinkRegion, ResourcesPlugin.getWorkspace().getRoot().getFile(path)); - } - else { - return new URLHyperlink(fHyperlinkRegion, fEntry.getURI()); - } - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.hyperlink.IHyperlink#getHyperlinkRegion() - */ - public IRegion getHyperlinkRegion() { - return fHyperlinkRegion; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.hyperlink.IHyperlink#getHyperlinkText() - */ - public String getHyperlinkText() { - IHyperlink link = getHyperlink(); - if (link != null) - return link.getHyperlinkText(); - return NLS.bind(XMLUIMessages.Open, fEntry.getKey()); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.hyperlink.IHyperlink#getTypeLabel() - */ - public String getTypeLabel() { - IHyperlink link = getHyperlink(); - if (link != null) - return link.getTypeLabel(); - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.hyperlink.IHyperlink#open() - */ - public void open() { - IHyperlink link = getHyperlink(); - if (link != null) - link.open(); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/hyperlink/ExternalFileEditorInput.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/hyperlink/ExternalFileEditorInput.java deleted file mode 100644 index 86e85d05a2..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/hyperlink/ExternalFileEditorInput.java +++ /dev/null @@ -1,171 +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.wst.xml.ui.internal.hyperlink; - -import java.io.File; - -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IPathEditorInput; -import org.eclipse.ui.IPersistableElement; -import org.eclipse.ui.editors.text.ILocationProvider; -import org.eclipse.ui.model.IWorkbenchAdapter; - -/** - * EditorInput for external files. Copied from - * org.eclipse.ui.internal.editors.text.JavaFileEditorInput - */ -class ExternalFileEditorInput implements IEditorInput, ILocationProvider { - // copies of this class exist in: - // org.eclipse.wst.xml.ui.internal.hyperlink - // org.eclipse.wst.html.ui.internal.hyperlink - // org.eclipse.jst.jsp.ui.internal.hyperlink - - /** - * The workbench adapter which simply provides the label. - */ - private class WorkbenchAdapter implements IWorkbenchAdapter { - /* - * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang.Object) - */ - public Object[] getChildren(Object o) { - return null; - } - - /* - * @see org.eclipse.ui.model.IWorkbenchAdapter#getImageDescriptor(java.lang.Object) - */ - public ImageDescriptor getImageDescriptor(Object object) { - return null; - } - - /* - * @see org.eclipse.ui.model.IWorkbenchAdapter#getLabel(java.lang.Object) - */ - public String getLabel(Object o) { - return ((ExternalFileEditorInput) o).getName(); - } - - /* - * @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(java.lang.Object) - */ - public Object getParent(Object o) { - return null; - } - } - - private File fFile; - private WorkbenchAdapter fWorkbenchAdapter = new WorkbenchAdapter(); - - public ExternalFileEditorInput(File file) { - super(); - fFile = file; - fWorkbenchAdapter = new WorkbenchAdapter(); - } - - /* - * @see org.eclipse.ui.IEditorInput#exists() - */ - public boolean exists() { - return fFile.exists(); - } - - /* - * @see org.eclipse.ui.IEditorInput#getImageDescriptor() - */ - public ImageDescriptor getImageDescriptor() { - return null; - } - - /* - * @see org.eclipse.ui.IEditorInput#getName() - */ - public String getName() { - return fFile.getName(); - } - - /* - * @see org.eclipse.ui.IEditorInput#getPersistable() - */ - public IPersistableElement getPersistable() { - return null; - } - - /* - * @see org.eclipse.ui.IEditorInput#getToolTipText() - */ - public String getToolTipText() { - return fFile.getAbsolutePath(); - } - - /* - * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) - */ - public Object getAdapter(Class adapter) { - if (ILocationProvider.class.equals(adapter)) { - return this; - } - if (IWorkbenchAdapter.class.equals(adapter)) { - return fWorkbenchAdapter; - } - return Platform.getAdapterManager().getAdapter(this, adapter); - } - - /* - * @see org.eclipse.ui.editors.text.ILocationProvider#getPath(java.lang.Object) - */ - public IPath getPath(Object element) { - if (element instanceof ExternalFileEditorInput) { - ExternalFileEditorInput input = (ExternalFileEditorInput) element; - return Path.fromOSString(input.fFile.getAbsolutePath()); - } - return null; - } - - /* - * @see org.eclipse.ui.IPathEditorInput#getPath() - * @since 3.1 - */ - public IPath getPath() { - return Path.fromOSString(fFile.getAbsolutePath()); - } - - /* - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean equals(Object o) { - if (o == this) { - return true; - } - - if (o instanceof ExternalFileEditorInput) { - ExternalFileEditorInput input = (ExternalFileEditorInput) o; - return fFile.equals(input.fFile); - } - - if (o instanceof IPathEditorInput) { - IPathEditorInput input = (IPathEditorInput) o; - return getPath().equals(input.getPath()); - } - - return false; - } - - /* - * @see java.lang.Object#hashCode() - */ - public int hashCode() { - return fFile.hashCode(); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/hyperlink/ExternalFileHyperlink.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/hyperlink/ExternalFileHyperlink.java deleted file mode 100644 index e935fc3ec6..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/hyperlink/ExternalFileHyperlink.java +++ /dev/null @@ -1,76 +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.wst.xml.ui.internal.hyperlink; - -import java.io.File; - -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.hyperlink.IHyperlink; -import org.eclipse.osgi.util.NLS; -import org.eclipse.ui.IEditorDescriptor; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.ide.IDE; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; - -/** - * Hyperlink for external files. - */ -class ExternalFileHyperlink implements IHyperlink { - // copies of this class exist in: - // org.eclipse.wst.xml.ui.internal.hyperlink - // org.eclipse.wst.html.ui.internal.hyperlink - // org.eclipse.jst.jsp.ui.internal.hyperlink - - private IRegion fHyperlinkRegion; - private File fHyperlinkFile; - - public ExternalFileHyperlink(IRegion region, File file) { - fHyperlinkFile = file; - fHyperlinkRegion = region; - } - - public IRegion getHyperlinkRegion() { - return fHyperlinkRegion; - } - - public String getTypeLabel() { - return null; - } - - public String getHyperlinkText() { - String path = fHyperlinkFile.getPath(); - if (path.length() > 55) { - path = path.substring(0, 25) + "..." + path.substring(path.length() - 25, path.length()); - } - return NLS.bind(XMLUIMessages.Open, path); - } - - public void open() { - if (fHyperlinkFile != null) { - IEditorInput input = new ExternalFileEditorInput(fHyperlinkFile); - IEditorDescriptor descriptor; - try { - descriptor = IDE.getEditorDescriptor(input.getName(), true); - if (descriptor != null) { - IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); - IDE.openEditor(page, input, descriptor.getId(), true); - } - } - catch (PartInitException e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/hyperlink/WorkspaceFileHyperlink.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/hyperlink/WorkspaceFileHyperlink.java deleted file mode 100644 index bcd210b4bb..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/hyperlink/WorkspaceFileHyperlink.java +++ /dev/null @@ -1,89 +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.wst.xml.ui.internal.hyperlink; - -import org.eclipse.core.resources.IFile; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.hyperlink.IHyperlink; -import org.eclipse.osgi.util.NLS; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.ide.IDE; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; - -/** - * Hyperlink for files within the workspace. (As long as there is an IFile, - * this can be used) Opens the default editor for the file. - */ -class WorkspaceFileHyperlink implements IHyperlink { - // copies of this class exist in: - // org.eclipse.wst.xml.ui.internal.hyperlink - // org.eclipse.wst.html.ui.internal.hyperlink - // org.eclipse.jst.jsp.ui.internal.hyperlink - - private IRegion fRegion; - private IFile fFile; - private IRegion fHighlightRange; - - public WorkspaceFileHyperlink(IRegion region, IFile file) { - fRegion = region; - fFile = file; - } - - public WorkspaceFileHyperlink(IRegion region, IFile file, IRegion range) { - fRegion = region; - fFile = file; - fHighlightRange = range; - } - - public IRegion getHyperlinkRegion() { - return fRegion; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.hyperlink.IHyperlink#getTypeLabel() - */ - public String getTypeLabel() { - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.hyperlink.IHyperlink#getHyperlinkText() - */ - public String getHyperlinkText() { - return NLS.bind(XMLUIMessages.Open, fFile.getName()); - } - - public void open() { - if ((fFile != null) && fFile.exists()) { - try { - IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); - IEditorPart editor = IDE.openEditor(page, fFile, true); - // highlight range in editor if possible - if ((fHighlightRange != null) && (editor instanceof ITextEditor)) { - ((ITextEditor) editor).setHighlightRange(fHighlightRange.getOffset(), fHighlightRange.getLength(), true); - } - } - catch (PartInitException pie) { - Logger.log(Logger.WARNING_DEBUG, pie.getMessage(), pie); - } - } - } - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/hyperlink/XMLHyperlinkDetector.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/hyperlink/XMLHyperlinkDetector.java deleted file mode 100644 index 09abdc3985..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/hyperlink/XMLHyperlinkDetector.java +++ /dev/null @@ -1,569 +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.wst.xml.ui.internal.hyperlink; - -import java.io.File; -import java.net.URI; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.Region; -import org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector; -import org.eclipse.jface.text.hyperlink.IHyperlink; -import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolverPlugin; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.sse.core.utils.StringUtils; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry; -import org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog; -import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMNamespaceHelper; -import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.w3c.dom.Attr; -import org.w3c.dom.DocumentType; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; - -import com.ibm.icu.util.StringTokenizer; - -/** - * Detects hyperlinks in XML tags. Includes detection in DOCTYPE and attribute - * values. Resolves references to schemas, dtds, etc using the Common URI - * Resolver. - * - */ -public class XMLHyperlinkDetector extends AbstractHyperlinkDetector { - private final String NO_NAMESPACE_SCHEMA_LOCATION = "noNamespaceSchemaLocation"; //$NON-NLS-1$ - private final String SCHEMA_LOCATION = "schemaLocation"; //$NON-NLS-1$ - private final String XMLNS = "xmlns"; //$NON-NLS-1$ - private final String XSI_NAMESPACE_URI = "http://www.w3.org/2001/XMLSchema-instance"; //$NON-NLS-1$ - - /** - * Create the appropriate hyperlink - * - * @param uriString - * @param hyperlinkRegion - * @return IHyperlink - */ - private IHyperlink createHyperlink(String uriString, IRegion hyperlinkRegion, IDocument document, Node node) { - IHyperlink link = null; - - ICatalogEntry entry = getCatalogEntry(uriString); - if (entry != null) { - link = new CatalogEntryHyperlink(hyperlinkRegion, entry); - } - else { - // try to locate the file in the workspace - File systemFile = getFileFromUriString(uriString); - if (systemFile != null) { - String systemPath = systemFile.getPath(); - IFile file = getFile(systemPath); - if (file != null) { - // this is a WorkspaceFileHyperlink since file exists in - // workspace - link = new WorkspaceFileHyperlink(hyperlinkRegion, file); - } - else { - // this is an ExternalFileHyperlink since file does not - // exist in workspace - link = new ExternalFileHyperlink(hyperlinkRegion, systemFile); - } - } - } - return link; - } - - public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) { - // for now, only capable of creating 1 hyperlink - List hyperlinks = new ArrayList(0); - - if ((region != null) && (textViewer != null)) { - IDocument document = textViewer.getDocument(); - Node currentNode = getCurrentNode(document, region.getOffset()); - if (currentNode != null) { - String uriString = null; - if (currentNode.getNodeType() == Node.DOCUMENT_TYPE_NODE) { - // doctype nodes - uriString = getURIString(currentNode, document); - } - else if (currentNode.getNodeType() == Node.ELEMENT_NODE) { - // element nodes - Attr currentAttr = getCurrentAttrNode(currentNode, region.getOffset()); - if (currentAttr != null) { - // try to find link for current attribute - // resolve attribute value - uriString = getURIString(currentAttr, document); - // verify validity of uri string - if ((uriString == null) || !isValidURI(uriString)) { - // reset current attribute - currentAttr = null; - } - } - if (currentAttr == null) { - // try to find a linkable attribute within element - currentAttr = getLinkableAttr((Element) currentNode); - if (currentAttr != null) { - uriString = getURIString(currentAttr, document); - } - } - currentNode = currentAttr; - } - // try to create hyperlink from information gathered - if ((uriString != null) && (currentNode != null) && isValidURI(uriString)) { - IRegion hyperlinkRegion = getHyperlinkRegion(currentNode); - IHyperlink hyperlink = createHyperlink(uriString, hyperlinkRegion, document, currentNode); - if (hyperlink != null) { - hyperlinks.add(hyperlink); - } - } - } - } - if (hyperlinks.size() == 0) { - return null; - } - return (IHyperlink[]) hyperlinks.toArray(new IHyperlink[0]); - } - - /** - * Get the base location from the current model (local file system) - */ - private String getBaseLocation(IDocument document) { - String result = null; - - // get the base location from the current model - IStructuredModel sModel = null; - try { - sModel = StructuredModelManager.getModelManager().getExistingModelForRead(document); - if (sModel != null) { - result = sModel.getBaseLocation(); - - IPath path = new Path(result); - if (path.segmentCount() > 1) { - IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); - if (file.exists()) { - String baseLocation = null; - if (file.getLocation() != null) { - baseLocation = file.getLocation().toString(); - } - if (baseLocation == null && file.getLocationURI() != null) { - baseLocation = file.getLocationURI().toString(); - } - if (baseLocation == null) { - baseLocation = file.getFullPath().toString(); - } - result = baseLocation; - } - } - } - } - finally { - if (sModel != null) { - sModel.releaseFromRead(); - } - } - return result; - } - - /** - * Get the CMElementDeclaration for an element - * - * @param element - * @return CMElementDeclaration - */ - private CMElementDeclaration getCMElementDeclaration(Element element) { - CMElementDeclaration ed = null; - - ModelQuery mq = ModelQueryUtil.getModelQuery(element.getOwnerDocument()); - if (mq != null) { - ed = mq.getCMElementDeclaration(element); - } - return ed; - } - - /** - * Returns the attribute node within node at offset - * - * @param node - * @param offset - * @return Attr - */ - private Attr getCurrentAttrNode(Node node, int offset) { - if ((node instanceof IndexedRegion) && ((IndexedRegion) node).contains(offset) && (node.hasAttributes())) { - NamedNodeMap attrs = node.getAttributes(); - // go through each attribute in node and if attribute contains - // offset, return that attribute - for (int i = 0; i < attrs.getLength(); ++i) { - // assumption that if parent node is of type IndexedRegion, - // then its attributes will also be of type IndexedRegion - IndexedRegion attRegion = (IndexedRegion) attrs.item(i); - if (attRegion.contains(offset)) { - return (Attr) attrs.item(i); - } - } - } - return null; - } - - /** - * Returns the node the cursor is currently on in the document. null if no - * node is selected - * - * @param offset - * @return Node either element, doctype, text, or null - */ - private Node getCurrentNode(IDocument document, int offset) { - // get the current node at the offset (returns either: element, - // doctype, text) - IndexedRegion inode = null; - IStructuredModel sModel = null; - try { - sModel = StructuredModelManager.getModelManager().getExistingModelForRead(document); - if (sModel != null) { - inode = sModel.getIndexedRegion(offset); - if (inode == null) { - inode = sModel.getIndexedRegion(offset - 1); - } - } - } - finally { - if (sModel != null) { - sModel.releaseFromRead(); - } - } - - if (inode instanceof Node) { - return (Node) inode; - } - return null; - } - - /** - * Returns an IFile from the given uri if possible, null if cannot find - * file from uri. - * - * @param fileString - * file system path - * @return returns IFile if fileString exists in the workspace - */ - private IFile getFile(String fileString) { - IFile file = null; - - if (fileString != null) { - Path filePath = new Path(fileString); - if (filePath.segmentCount() > 1 && ResourcesPlugin.getWorkspace().getRoot().getFile(filePath).exists()) { - return ResourcesPlugin.getWorkspace().getRoot().getFile(filePath); - } - IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(filePath); - for (int i = 0; (i < files.length) && (file == null); i++) { - if (files[i].exists()) { - file = files[i]; - } - } - } - - return file; - } - - /** - * Create a file from the given uri string - * - * @param uriString - - * assumes uriString is not http:// - * @return File created from uriString if possible, null otherwise - */ - private File getFileFromUriString(String uriString) { - File file = null; - try { - // first just try to create a file directly from uriString as - // default in case create file from uri does not work - file = new File(uriString); - - // try to create file from uri - URI uri = new URI(uriString); - file = new File(uri); - } - catch (Exception e) { - // if exception is thrown while trying to create File just ignore - // and file will be null - } - return file; - } - - private IRegion getHyperlinkRegion(Node node) { - IRegion hyperRegion = null; - - if (node != null) { - short nodeType = node.getNodeType(); - if (nodeType == Node.DOCUMENT_TYPE_NODE) { - // handle doc type node - IDOMNode docNode = (IDOMNode) node; - hyperRegion = new Region(docNode.getStartOffset(), docNode.getEndOffset() - docNode.getStartOffset()); - } - else if (nodeType == Node.ATTRIBUTE_NODE) { - // handle attribute nodes - IDOMAttr att = (IDOMAttr) node; - // do not include quotes in attribute value region - int regOffset = att.getValueRegionStartOffset(); - ITextRegion valueRegion = att.getValueRegion(); - if (valueRegion != null) { - int regLength = valueRegion.getTextLength(); - String attValue = att.getValueRegionText(); - if (StringUtils.isQuoted(attValue)) { - ++regOffset; - regLength = regLength - 2; - } - hyperRegion = new Region(regOffset, regLength); - } - } - } - return hyperRegion; - } - - /** - * Attempts to find an attribute within element that is openable. - * - * @param element - - * cannot be null - * @return Attr attribute that can be used for open on, null if no - * attribute could be found - */ - private Attr getLinkableAttr(Element element) { - CMElementDeclaration ed = getCMElementDeclaration(element); - // get the list of attributes for this node - NamedNodeMap attrs = element.getAttributes(); - for (int i = 0; i < attrs.getLength(); ++i) { - // check if this attribute is "openOn-able" - Attr att = (Attr) attrs.item(i); - if (isLinkableAttr(att, ed)) { - return att; - } - } - return null; - } - - /** - * Find the location hint for the given namespaceURI if it exists - * - * @param elementNode - - * cannot be null - * @param namespaceURI - - * cannot be null - * @return location hint (systemId) if it was found, null otherwise - */ - private String getLocationHint(Element elementNode, String namespaceURI) { - Attr schemaLocNode = elementNode.getAttributeNodeNS(XSI_NAMESPACE_URI, SCHEMA_LOCATION); - if (schemaLocNode != null) { - StringTokenizer st = new StringTokenizer(schemaLocNode.getValue()); - while (st.hasMoreTokens()) { - String publicId = st.hasMoreTokens() ? st.nextToken() : null; - String systemId = st.hasMoreTokens() ? st.nextToken() : null; - // found location hint - if (namespaceURI.equalsIgnoreCase(publicId)) { - return systemId; - } - } - } - return null; - } - - /** - * Returns the URI string - * - * @param node - - * assumes not null - */ - private String getURIString(Node node, IDocument document) { - String resolvedURI = null; - // need the base location, publicId, and systemId for URIResolver - String baseLoc = null; - String publicId = null; - String systemId = null; - - short nodeType = node.getNodeType(); - // handle doc type node - if (nodeType == Node.DOCUMENT_TYPE_NODE) { - baseLoc = getBaseLocation(document); - publicId = ((DocumentType) node).getPublicId(); - systemId = ((DocumentType) node).getSystemId(); - } - else if (nodeType == Node.ATTRIBUTE_NODE) { - // handle attribute node - Attr attrNode = (Attr) node; - String attrName = attrNode.getName(); - String attrValue = attrNode.getValue(); - attrValue = StringUtils.strip(attrValue); - if ((attrValue != null) && (attrValue.length() > 0)) { - baseLoc = getBaseLocation(document); - - // handle schemaLocation attribute - String prefix = DOMNamespaceHelper.getPrefix(attrName); - String unprefixedName = DOMNamespaceHelper.getUnprefixedName(attrName); - if ((XMLNS.equals(prefix)) || (XMLNS.equals(unprefixedName))) { - publicId = attrValue; - systemId = getLocationHint(attrNode.getOwnerElement(), publicId); - if (systemId == null) { - systemId = attrValue; - } - } - else if ((XSI_NAMESPACE_URI.equals(DOMNamespaceHelper.getNamespaceURI(attrNode))) && (SCHEMA_LOCATION.equals(unprefixedName))) { - // for now just use the first pair - // need to look into being more precise - StringTokenizer st = new StringTokenizer(attrValue); - publicId = st.hasMoreTokens() ? st.nextToken() : null; - systemId = st.hasMoreTokens() ? st.nextToken() : null; - // else check if xmlns publicId = value - } - else { - systemId = attrValue; - } - } - } - - resolvedURI = resolveURI(baseLoc, publicId, systemId); - return resolvedURI; - } - - /** - * Checks to see if the given attribute is openable. Attribute is openable - * if it is a namespace declaration attribute or if the attribute value is - * of type URI. - * - * @param attr - * cannot be null - * @param cmElement - * CMElementDeclaration associated with the attribute (can be - * null) - * @return true if this attribute is "openOn-able" false otherwise - */ - private boolean isLinkableAttr(Attr attr, CMElementDeclaration cmElement) { - String attrName = attr.getName(); - String prefix = DOMNamespaceHelper.getPrefix(attrName); - String unprefixedName = DOMNamespaceHelper.getUnprefixedName(attrName); - // determine if attribute is namespace declaration - if ((XMLNS.equals(prefix)) || (XMLNS.equals(unprefixedName))) { - return true; - } - - // determine if attribute contains schema location - if ((XSI_NAMESPACE_URI.equals(DOMNamespaceHelper.getNamespaceURI(attr))) && ((SCHEMA_LOCATION.equals(unprefixedName)) || (NO_NAMESPACE_SCHEMA_LOCATION.equals(unprefixedName)))) { - return true; - } - - // determine if attribute value is of type URI - if (cmElement != null) { - CMNamedNodeMap attrDecls = cmElement.getAttributes(); - CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(attrDecls); - List nodes = ModelQueryUtil.getModelQuery(attr.getOwnerDocument()).getAvailableContent(attr.getOwnerElement(), cmElement, ModelQuery.INCLUDE_ATTRIBUTES); - for (int k = 0; k < nodes.size(); k++) { - CMNode cmnode = (CMNode) nodes.get(k); - if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) { - allAttributes.put(cmnode); - } - } - attrDecls = allAttributes; - - CMAttributeDeclaration attrDecl = (CMAttributeDeclaration) attrDecls.getNamedItem(attrName); - if ((attrDecl != null) && (attrDecl.getAttrType() != null) && (CMDataType.URI.equals(attrDecl.getAttrType().getDataTypeName()))) { - return true; - } - } - return false; - } - - /** - * Checks whether the given uriString is really pointing to a file - * - * @param uriString - * @return boolean - */ - private boolean isValidURI(String uriString) { - boolean isValid = false; - - if (getCatalogEntry(uriString) != null) { - isValid = true; - } - else { - File file = getFileFromUriString(uriString); - if (file != null) { - isValid = file.isFile(); - } - if(!isValid) { - } - - } - return isValid; - } - - /** - * @param uriString - * @return - */ - private ICatalogEntry getCatalogEntry(String uriString) { - ICatalog defaultCatalog = XMLCorePlugin.getDefault().getDefaultXMLCatalog(); - if (defaultCatalog != null) { - // Process default catalog - ICatalogEntry[] entries = defaultCatalog.getCatalogEntries(); - for (int entry = 0; entry < entries.length; entry++) { - if (uriString.equals(entries[entry].getKey())||uriString.equals(entries[entry].getURI())) { - return entries[entry]; - } - } - - // Process declared OASIS nextCatalogs catalog - INextCatalog[] nextCatalogs = defaultCatalog.getNextCatalogs(); - for (int nextCatalog = 0; nextCatalog < nextCatalogs.length; nextCatalog++) { - ICatalog catalog = nextCatalogs[nextCatalog].getReferencedCatalog(); - ICatalogEntry[] entries2 = catalog.getCatalogEntries(); - for (int entry = 0; entry < entries2.length; entry++) { - if (uriString.equals(entries2[entry].getKey())||uriString.equals(entries2[entry].getURI())) - return entries2[entry]; - } - } - } - return null; - } - - /** - * Resolves the given URI information - * - * @param baseLocation - * @param publicId - * @param systemId - * @return String resolved uri. - */ - private String resolveURI(String baseLocation, String publicId, String systemId) { - // dont resolve if there's nothing to resolve - if ((baseLocation == null) && (publicId == null) && (systemId == null)) { - return null; - } - return URIResolverPlugin.createResolver().resolve(baseLocation, publicId, systemId); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/nsedit/CommonAddNamespacesControl.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/nsedit/CommonAddNamespacesControl.java deleted file mode 100644 index 2782c4778c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/nsedit/CommonAddNamespacesControl.java +++ /dev/null @@ -1,281 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.nsedit; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IPath; -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.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.TableItem; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.part.PageBook; -import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolverPlugin; -import org.eclipse.wst.common.uriresolver.internal.util.URIHelper; -import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.dialogs.SelectFileOrXMLCatalogIdDialog; - -public class CommonAddNamespacesControl extends Composite implements SelectionListener { - - class EditNamespaceControl extends Composite { - protected Button browseButton; - Text locationHintField; - Text prefixField; - Text uriField; - - // protected NamespaceInfo info; - - public EditNamespaceControl(Composite parent) { - super(parent, SWT.NONE); // BORDER); - setLayout(new GridLayout()); - setLayoutData(new GridData(GridData.FILL_BOTH)); - - Label label = new Label(this, SWT.NONE); - label.setText(XMLUIMessages._UI_ENTER_REQ_PREFIX_AND_NAMESPACE); - - Composite composite = new Composite(this, SWT.NONE); - GridLayout layout = new GridLayout(); - layout.numColumns = 3; - layout.marginWidth = 0; - layout.verticalSpacing = 1; - composite.setLayout(layout); - - GridData gd = new GridData(GridData.FILL_HORIZONTAL); - gd.widthHint = 350; - composite.setLayoutData(gd); - - // row 1 - // - Label prefixLabel = new Label(composite, SWT.NONE); - prefixLabel.setText(XMLUIMessages._UI_LABEL_PREFIX_COLON); - - prefixField = new Text(composite, SWT.SINGLE | SWT.BORDER); - prefixField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - // prefixField.setText(getDisplayValue(info.prefix)); - // prefixField.addModifyListener(modifyListener); - // prefixField.setEnabled(info.getProperty("prefix-readOnly") == - // null); - new Label(composite, SWT.NONE); - - // row 2 - // - Label uriLabel = new Label(composite, SWT.NONE); - uriLabel.setText(XMLUIMessages._UI_LABEL_NAMESPACE_NAME_COLON); - - uriField = new Text(composite, SWT.SINGLE | SWT.BORDER); - uriField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - // uriField.setText(getDisplayValue(info.uri)); - // uriField.addModifyListener(modifyListener); - // uriField.setEnabled(info.getProperty("uri-readOnly") == null); - - new Label(composite, SWT.NONE); - - // row 3 - // - Label locationHintLabel = new Label(composite, SWT.NONE); - locationHintLabel.setText(XMLUIMessages._UI_LABEL_LOCATION_HINT_COLON); - - locationHintField = new Text(composite, SWT.SINGLE | SWT.BORDER); - locationHintField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - // locationHintField.setText(getDisplayValue(info.locationHint)); - // locationHintField.addModifyListener(modifyListener); - // locationHintField.setEnabled(info.getProperty("locationHint-readOnly") - // == null); - - SelectionListener selectionListener = new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - performBrowse(); - } - }; - - browseButton = new Button(composite, SWT.NONE); - browseButton.setText(XMLUIMessages._UI_LABEL_BROWSE); - browseButton.addSelectionListener(selectionListener); - browseButton.setEnabled(locationHintField.getEnabled()); - } - - protected void performBrowse() { - String[] extensions = {".xsd"}; //$NON-NLS-1$ - SelectFileOrXMLCatalogIdDialog dialog = new SelectFileOrXMLCatalogIdDialog(getShell(), extensions); - dialog.create(); - dialog.getShell().setText(XMLUIMessages._UI_LABEL_SELECT_FILE); - dialog.setBlockOnOpen(true); - dialog.open(); - - if (dialog.getReturnCode() == Window.OK) { - // String grammarURI = null; - IFile file = dialog.getFile(); - String id = dialog.getId(); - if (file != null) { - String uri = null; - if (resourceLocation != null) { - IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(resourceLocation); - if (resource != null) { - IPath location = resource.getLocation(); - if (location != null) { - uri = URIHelper.getRelativeURI(file.getLocation(), location); - } - } - else { - uri = URIHelper.getRelativeURI(file.getLocation(), resourceLocation); - } - // grammarURI = file.getLocation().toOSString(); - } - else { - uri = file.getLocation().toOSString(); - // grammarURI = uri; - } - locationHintField.setText(uri); - } - else if (id != null) { - locationHintField.setText(id); - // URIResolver resolver = - URIResolverPlugin.createResolver(); - // grammarURI = resolver.resolve(null, id, id); - } - - try { - // TODO CMDocument document = - // CMDocumentBuilderRegistry.getInstance().buildCMDocument(grammarURI); - // List namespaceInfoList = - // (List)document.getProperty("http://org.eclipse.wst/cm/properties/namespaceInfo"); - // NamespaceInfo info = - // (NamespaceInfo)namespaceInfoList.get(0); - // if (uriField.getText().trim().length() == 0 && info.uri - // != null) - // { - // uriField.setText(info.uri); - // } - // if (prefixField.getText().trim().length() == 0 && - // info.prefix != null) - // { - // prefixField.setText(info.prefix); - // } - } - catch (Exception e) { - } - } - } - } - - protected Button deleteButton; - protected Button editButton; - protected EditNamespaceControl editNamespaceControl; - protected int heightHint = 250; - protected List namespaceInfoList = new ArrayList(); - protected Button newButton; - protected PageBook pageBook; - protected Button radio1; - protected Button radio2; - protected IPath resourceLocation; - protected Composite tableSection; - protected CommonNamespaceInfoTable tableViewer; - protected int widthHint = 500; - - - public CommonAddNamespacesControl(Composite parent, int style, IPath resourceLocation) { - super(parent, style); - this.resourceLocation = resourceLocation; - GridData gd = new GridData(GridData.FILL_BOTH); - if (widthHint != -1) { - gd.widthHint = widthHint; - } - if (heightHint != -1) { - gd.heightHint = heightHint; - } - setLayoutData(gd); - setLayout(new GridLayout()); - - radio1 = new Button(this, SWT.RADIO); - radio1.setText(XMLUIMessages._UI_SELECT_REGISTERED_NAMESPACES); - radio1.addSelectionListener(this); - - radio2 = new Button(this, SWT.RADIO); - radio2.setText(XMLUIMessages._UI_SPECIFY_NEW_NAMESPACE); - radio2.addSelectionListener(this); - - Label separator = new Label(this, SWT.SEPARATOR | SWT.HORIZONTAL); - separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - // Group namespaceInfoGroup = new Group(this, SWT.NONE); - // namespaceInfoGroup.setText("Namespace Declarations"); - // //XMLCommonUIPlugin.getInstance().getString("_UI_LABEL_XML_SCHEMA_INFORMATION")); - // namespaceInfoGroup.setLayout(new GridLayout(2, false)); - // namespaceInfoGroup.setLayoutData(new GridData(GridData.FILL_BOTH)); - pageBook = new PageBook(this, SWT.NONE); - pageBook.setLayoutData(new GridData(GridData.FILL_BOTH)); - - tableSection = new Composite(pageBook, SWT.NONE); - tableSection.setLayout(new GridLayout()); - Label label = new Label(tableSection, SWT.NONE); - label.setText(XMLUIMessages._UI_SELECT_NAMESPACE_TO_ADD); - - tableViewer = new CommonNamespaceInfoTable(tableSection, SWT.CHECK, 6); - editNamespaceControl = new EditNamespaceControl(pageBook); - pageBook.showPage(tableSection); - - tableViewer.setInput(namespaceInfoList); - } - - - - public List getNamespaceInfoList() { - List list = new ArrayList(); - if (radio1.getSelection()) { - TableItem[] items = tableViewer.getTable().getItems(); - for (int i = 0; i < items.length; i++) { - TableItem item = items[i]; - if (item.getChecked()) { - list.add(item.getData()); - } - } - } - else { - NamespaceInfo info = new NamespaceInfo(); - info.prefix = editNamespaceControl.prefixField.getText(); - info.uri = editNamespaceControl.uriField.getText(); - info.locationHint = editNamespaceControl.locationHintField.getText(); - list.add(info); - } - return list; - } - - public void setNamespaceInfoList(List list) { - namespaceInfoList = list; - tableViewer.setInput(namespaceInfoList); - } - - public void widgetDefaultSelected(SelectionEvent e) { - } - - public void widgetSelected(SelectionEvent e) { - if (e.widget == radio1) { - pageBook.showPage(tableSection); - } - else if (e.widget == radio2) { - pageBook.showPage(editNamespaceControl); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/nsedit/CommonAddNamespacesDialog.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/nsedit/CommonAddNamespacesDialog.java deleted file mode 100644 index 269113fea8..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/nsedit/CommonAddNamespacesDialog.java +++ /dev/null @@ -1,205 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.nsedit; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.runtime.IPath; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry; -import org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog; -import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo; - - - -public class CommonAddNamespacesDialog extends Dialog { - protected CommonAddNamespacesControl addNamespacesControl; - protected List existingNamespaces; - protected List namespaceInfoList; - protected Button okButton; - protected HashMap preferredPrefixTable = new HashMap(); - protected IPath resourceLocation; - protected String title; - - public CommonAddNamespacesDialog(Shell parentShell, String title, IPath resourceLocation, List existingNamespaces) { - super(parentShell); - this.resourceLocation = resourceLocation; - setShellStyle(getShellStyle() | SWT.RESIZE); - this.title = title; - this.existingNamespaces = existingNamespaces; - preferredPrefixTable.put("http://schemas.xmlsoap.org/wsdl/", "wsdl"); //$NON-NLS-1$ //$NON-NLS-2$ - preferredPrefixTable.put("http://schemas.xmlsoap.org/wsdl/soap/", "soap"); //$NON-NLS-1$ //$NON-NLS-2$ - preferredPrefixTable.put("http://schemas.xmlsoap.org/wsdl/http/", "http"); //$NON-NLS-1$ //$NON-NLS-2$ - preferredPrefixTable.put("http://schemas.xmlsoap.org/wsdl/mime/", "mime"); //$NON-NLS-1$ //$NON-NLS-2$ - preferredPrefixTable.put("http://schemas.xmlsoap.org/soap/encoding/", "soapenc"); //$NON-NLS-1$ //$NON-NLS-2$ - preferredPrefixTable.put("http://schemas.xmlsoap.org/soap/envelope/", "soapenv"); //$NON-NLS-1$ //$NON-NLS-2$ - preferredPrefixTable.put("http://www.w3.org/2001/XMLSchema-instance", "xsi"); //$NON-NLS-1$ //$NON-NLS-2$ - preferredPrefixTable.put("http://www.w3.org/2001/XMLSchema", "xsd"); //$NON-NLS-1$ //$NON-NLS-2$ - } - - protected void addBuiltInNamespaces(List list) { - String xsiNamespace = "http://www.w3.org/2001/XMLSchema-instance"; //$NON-NLS-1$ - String xsdNamespace = "http://www.w3.org/2001/XMLSchema"; //$NON-NLS-1$ - if (!isAlreadyDeclared(xsiNamespace)) { - list.add(new NamespaceInfo("http://www.w3.org/2001/XMLSchema-instance", "xsi", null)); //$NON-NLS-1$ //$NON-NLS-2$ - } - if (!isAlreadyDeclared(xsdNamespace)) { - list.add(new NamespaceInfo("http://www.w3.org/2001/XMLSchema", "xsd", null)); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - protected void addCatalogMapToList(ICatalog catalog, List list) { - ICatalogEntry[] entries = catalog.getCatalogEntries(); - for (int i = 0; i < entries.length; i++) { - ICatalogEntry entry = entries[i]; - if ((entry.getEntryType() == ICatalogEntry.ENTRY_TYPE_PUBLIC) && entry.getURI().endsWith(".xsd")) { //$NON-NLS-1$ - if (!isAlreadyDeclared(entry.getKey())) { - NamespaceInfo namespaceInfo = new NamespaceInfo(entry.getKey(), "xx", null); //$NON-NLS-1$ - list.add(namespaceInfo); - } - } - } - } - - protected void buttonPressed(int buttonId) { - if (buttonId == IDialogConstants.OK_ID) { - namespaceInfoList = addNamespacesControl.getNamespaceInfoList(); - } - super.buttonPressed(buttonId); - } - - public void computeAddablePrefixes(List addableList, List exisitingList) { - HashMap map = new HashMap(); - for (Iterator i = exisitingList.iterator(); i.hasNext();) { - NamespaceInfo info = (NamespaceInfo) i.next(); - if (info.prefix != null) { - map.put(info.prefix, info); - } - } - for (Iterator i = addableList.iterator(); i.hasNext();) { - NamespaceInfo info = (NamespaceInfo) i.next(); - if (info.uri != null) { - String prefix = (String) preferredPrefixTable.get(info.uri); - info.prefix = getUniquePrefix(map, prefix, info.uri); - map.put(info.prefix, info); - } - } - } - - public int createAndOpen() { - create(); - getShell().setText(title); - Rectangle r = getShell().getBounds(); - getShell().setBounds(r.x + 80, r.y + 80, r.width, r.height); - setBlockOnOpen(true); - return open(); - } - - protected void createButtonsForButtonBar(Composite parent) { - okButton = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); - createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); - } - - protected Control createContents(Composite parent) { - Control control = super.createContents(parent); - return control; - } - - - - protected Control createDialogArea(Composite parent) { - Composite dialogArea = (Composite) super.createDialogArea(parent); - addNamespacesControl = new CommonAddNamespacesControl(dialogArea, SWT.NONE, resourceLocation); - List list = new ArrayList(); - - addBuiltInNamespaces(list); - ICatalog defaultCatalog = XMLCorePlugin.getDefault().getDefaultXMLCatalog(); - INextCatalog[] nextCatalogs = defaultCatalog.getNextCatalogs(); - for (int i = 0; i < nextCatalogs.length; i++) { - INextCatalog catalog = nextCatalogs[i]; - ICatalog referencedCatalog = catalog.getReferencedCatalog(); - if (referencedCatalog != null) { - if (XMLCorePlugin.USER_CATALOG_ID.equals(referencedCatalog.getId())) { - ICatalog userCatalog = referencedCatalog; - addCatalogMapToList(userCatalog, list); - - } - else if (XMLCorePlugin.SYSTEM_CATALOG_ID.equals(referencedCatalog.getId())) { - ICatalog systemCatalog = referencedCatalog; - addCatalogMapToList(systemCatalog, list); - } - } - } - - computeAddablePrefixes(list, existingNamespaces); - - addNamespacesControl.setNamespaceInfoList(list); - return dialogArea; - } - - public List getNamespaceInfoList() { - return namespaceInfoList; - } - - protected String getPreferredPrefix(String namespaceURI) { - return (String) preferredPrefixTable.get(namespaceURI); - } - - private String getUniquePrefix(HashMap prefixMap, String prefix, String uri) { - if (prefix == null) { - int lastIndex = uri.lastIndexOf('/'); - if (lastIndex == uri.length() - 1) { - uri = uri.substring(0, lastIndex); - lastIndex = uri.lastIndexOf('/'); - } - prefix = uri.substring(lastIndex + 1); - if ((prefix.length() > 20) || (prefix.indexOf(':') != -1)) { - prefix = null; - } - } - if (prefix == null) { - prefix = "p"; //$NON-NLS-1$ - } - if (prefixMap.get(prefix) != null) { - String base = prefix; - for (int count = 0; prefixMap.get(prefix) != null; count++) { - prefix = base + count; - } - } - return prefix; - } - - protected boolean isAlreadyDeclared(String namespaceURI) { - boolean result = false; - for (Iterator i = existingNamespaces.iterator(); i.hasNext();) { - NamespaceInfo namespaceInfo = (NamespaceInfo) i.next(); - if (namespaceURI.equals(namespaceInfo.uri)) { - result = true; - break; - } - } - return result; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/nsedit/CommonEditNamespacesDialog.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/nsedit/CommonEditNamespacesDialog.java deleted file mode 100644 index 3a358cd03f..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/nsedit/CommonEditNamespacesDialog.java +++ /dev/null @@ -1,327 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.nsedit; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.runtime.IPath; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; -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.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.Composite; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.internal.dialogs.EditNamespaceInfoDialog; -import org.eclipse.wst.xml.ui.internal.dialogs.NamespaceInfoErrorHelper; - -public class CommonEditNamespacesDialog { - protected Composite commonComposite; - protected Button deleteButton; - protected Button editButton; - - protected Label errorMessageLabel; - protected int heightHint = 250; - protected List namespaceInfoList = new ArrayList(); - - protected Button newButton; - protected IPath resourceLocation; - - private boolean showLocationText = false; - protected String tableLabel = ""; //$NON-NLS-1$ - protected CommonNamespaceInfoTable tableViewer; - - protected Composite topComposite; - protected boolean useGroup; - protected int widthHint = 500; - - public CommonEditNamespacesDialog(Composite parent, IPath resourceLocation, String stringTableLabel) { - this(parent, resourceLocation, stringTableLabel, false, false); - } - - public CommonEditNamespacesDialog(Composite parent, IPath resourceLocation, String stringTableLabel, boolean useGroup, boolean showLocText) { - this.resourceLocation = resourceLocation; - tableLabel = stringTableLabel; - this.useGroup = useGroup; - showLocationText = showLocText; - - GridData gd = new GridData(GridData.FILL_BOTH); - if (widthHint != -1) { - gd.widthHint = widthHint; - } - if (heightHint != -1) { - gd.heightHint = heightHint; - } - - // Set GridData and GridLayout for the parent Composite - parent.setLayoutData(gd); - parent.setLayout(new GridLayout()); - - // Create the top Composite - topComposite = new Composite(parent, SWT.NONE); - GridData topData = new GridData(GridData.FILL_HORIZONTAL); - topData.heightHint = 0; - topComposite.setLayoutData(topData); - topComposite.setLayout(new GridLayout()); - - // Create the 'common'/middle Composite - if (useGroup) { - commonComposite = new Group(parent, SWT.NONE); - } - else { - commonComposite = new Composite(parent, SWT.NONE); - } - commonComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); - commonComposite.setLayout(new GridLayout(3, false)); - - // Add the error Message Label - errorMessageLabel = new Label(parent, SWT.NONE); - errorMessageLabel.setLayoutData(createHorizontalFill()); - Color color = new Color(errorMessageLabel.getDisplay(), 200, 0, 0); - errorMessageLabel.setForeground(color); - - createControlArea(); - } - - - protected void createButtons(Composite parent) { - Composite composite = new Composite(parent, SWT.NONE); - composite.setLayoutData(new GridData(GridData.FILL_VERTICAL)); - GridLayout gridLayout = new GridLayout(); - gridLayout.numColumns = 1; - gridLayout.marginHeight = 0; - gridLayout.marginWidth = 0; - composite.setLayout(gridLayout); - - SelectionListener selectionListener = new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - if (e.widget == newButton) { - performNew(); - } - else if (e.widget == editButton) { - performEdit(); - } - else if (e.widget == deleteButton) { - performDelete(); - } - } - }; - - // create a composite to hold the three buttons - Composite buttonComposite = new Composite(composite, SWT.NONE); - buttonComposite.setLayoutData(createHorizontalFill()); - GridLayout buttonGridLayout = new GridLayout(); - // buttonGridLayout.numColumns = 3; - // buttonGridLayout.makeColumnsEqualWidth = true; - buttonComposite.setLayout(buttonGridLayout); - - // add the New button - // - newButton = new Button(buttonComposite, SWT.NONE); - // newButton.setText(" " + - // XMLCommonUIPlugin.getInstance().getString("_UI_BUTTON_NEW") + " "); - newButton.setText(" " + XMLUIMessages.CommonEditNamespacesDialog_0 + " "); //$NON-NLS-1$ //$NON-NLS-2$ - newButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // ViewUtility.createHorizontalFill()); - newButton.addSelectionListener(selectionListener); - - // add the Edit button - // - // gd = new GridData(); - // gd.horizontalAlignment = gd.FILL; - // gd.grabExcessHorizontalSpace = true; - - editButton = new Button(buttonComposite, SWT.NONE); - editButton.setText(XMLUIMessages._UI_BUTTON_EDIT); - editButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // ViewUtility.createHorizontalFill()); - editButton.addSelectionListener(selectionListener); - - // add the Delete button - // - // gd = new GridData(); - // gd.horizontalAlignment = gd.FILL; - // gd.grabExcessHorizontalSpace = true; - - deleteButton = new Button(buttonComposite, SWT.NONE); - deleteButton.setText(XMLUIMessages._UI_BUTTON_DELETE); - deleteButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // ViewUtility.createHorizontalFill()); - deleteButton.addSelectionListener(selectionListener); - } - - private void createControlArea() { - if (useGroup) { - ((Group) commonComposite).setText(tableLabel); - } - else { - Label label = new Label(commonComposite, SWT.NONE); - label.setText(tableLabel); - label.setLayoutData(createGridData(false, 3)); - } - - tableViewer = new CommonNamespaceInfoTable(commonComposite, 6, showLocationText); - tableViewer.getControl().setLayoutData(createGridData(true, 2)); - createButtons(commonComposite); - - tableViewer.setInput(namespaceInfoList); - updateButtonEnabledState(); - ISelectionChangedListener selectionChangedListener = new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - updateButtonEnabledState(); - } - }; - tableViewer.addSelectionChangedListener(selectionChangedListener); - } - - protected GridData createGridData(boolean both, int span) { - GridData gd = new GridData(both ? GridData.FILL_BOTH : GridData.FILL_HORIZONTAL); - gd.horizontalSpan = 2; - return gd; - } - - private GridData createHorizontalFill() { - GridData gd = new GridData(); - gd.horizontalAlignment = GridData.FILL; - gd.grabExcessHorizontalSpace = true; - return gd; - } - - - - public NamespaceInfo getNamespaceInfo(String namespace) { - NamespaceInfo result = null; - for (Iterator i = namespaceInfoList.iterator(); i.hasNext();) { - NamespaceInfo info = (NamespaceInfo) i.next(); - if ((info.uri != null) && info.uri.equals(namespace)) { - result = info; - break; - } - } - return result; - } - - protected Object getSelection(ISelection selection) { - if (selection == null) { - return null; - } // end of if () - - Object result = null; - if (selection instanceof IStructuredSelection) { - IStructuredSelection es = (IStructuredSelection) selection; - Iterator i = es.iterator(); - if (i.hasNext()) { - result = i.next(); - } - } - return result; - } - - /* - * Use the returned Composite to add content above the 'common contents'. - * Note: The GridData for the returned Composite has a heightHint = 0. - * This means when using the returned Composite, the GridData must be - * reset, else the Composite and it's contents will not appear. - */ - protected Composite getTopComposite() { - return topComposite; - } - - protected EditNamespaceInfoDialog invokeDialog(String title, NamespaceInfo info) { - Shell shell = XMLUIPlugin.getInstance().getWorkbench().getActiveWorkbenchWindow().getShell(); - EditNamespaceInfoDialog dialog = new EditNamespaceInfoDialog(shell, info); - dialog.create(); - dialog.getShell().setText(title); - dialog.setBlockOnOpen(true); - dialog.setResourceLocation(resourceLocation); - dialog.open(); - return dialog; - } - - protected void performDelayedUpdate() { - tableViewer.refresh(); - /* - * Runnable delayedUpdate = new Runnable() { public void run() { - * tableViewer.refresh(); } }; - * Display.getCurrent().asyncExec(delayedUpdate); - */ - // if (updateListener != null) - // { - // updateListener.updateOccured(this, namespaceInfoList); - // } - } - - public void performDelete() { - ISelection selection = tableViewer.getSelection(); - if (selection instanceof IStructuredSelection) { - IStructuredSelection structuredSelection = (IStructuredSelection) selection; - namespaceInfoList.removeAll(structuredSelection.toList()); - updateErrorMessage(namespaceInfoList); - performDelayedUpdate(); - } - } - - public void performEdit() { - Object selection = getSelection(tableViewer.getSelection()); - if (selection != null) { - invokeDialog(XMLUIMessages._UI_LABEL_NEW_NAMESPACE_INFORMATION, (NamespaceInfo) selection); - updateErrorMessage(namespaceInfoList); - performDelayedUpdate(); - } - } - - public void performNew() { - Shell shell = XMLUIPlugin.getInstance().getWorkbench().getActiveWorkbenchWindow().getShell(); - CommonAddNamespacesDialog dialog = new CommonAddNamespacesDialog(shell, XMLUIMessages._UI_ADD_NAMESPACE_DECLARATIONS, resourceLocation, namespaceInfoList); - dialog.createAndOpen(); - if (dialog.getReturnCode() == Window.OK) { - namespaceInfoList.addAll(dialog.getNamespaceInfoList()); - updateErrorMessage(namespaceInfoList); - performDelayedUpdate(); - } - } - - public void setNamespaceInfoList(List list) { - namespaceInfoList = list; - tableViewer.setInput(namespaceInfoList); - } - - public void updateButtonEnabledState() { - Object selection = getSelection(tableViewer.getSelection()); - NamespaceInfo info = (NamespaceInfo) selection; - editButton.setEnabled(info != null); - deleteButton.setEnabled((info != null) && (info.getProperty("unremovable") == null)); //$NON-NLS-1$ - } - - public void updateErrorMessage(List namespaceInfoList) { - NamespaceInfoErrorHelper helper = new NamespaceInfoErrorHelper(); - String errorMessage = helper.computeErrorMessage(namespaceInfoList, null); - errorMessageLabel.setText(errorMessage != null ? errorMessage : ""); //$NON-NLS-1$ - } - - public void setResourcePath(IPath path) { - resourceLocation = path; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/nsedit/CommonEditNamespacesTargetFieldDialog.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/nsedit/CommonEditNamespacesTargetFieldDialog.java deleted file mode 100644 index 1f6d85ae0a..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/nsedit/CommonEditNamespacesTargetFieldDialog.java +++ /dev/null @@ -1,104 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.nsedit; - -import org.eclipse.core.runtime.IPath; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; -import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; - -/* - * This class is an extension of CommonEditNamespacesDialog. This class adds - * the target namespaces dialog field. - */ -public class CommonEditNamespacesTargetFieldDialog extends CommonEditNamespacesDialog { - - class TargetNamespaceModifyListener implements ModifyListener { - public void modifyText(ModifyEvent e) { - String oldTargetNamespace = targetNamespace; - targetNamespace = targetNamespaceField.getText(); - updateTargetNamespaceAndNamespaceInfo(oldTargetNamespace, targetNamespace); - } - } - - protected String targetNamespace; - protected Text targetNamespaceField; - - public CommonEditNamespacesTargetFieldDialog(Composite parent, IPath resourceLocation1) { - super(parent, resourceLocation1, XMLUIMessages._UI_NAMESPACE_DECLARATIONS); - - Composite targetComp = getTopComposite(); - targetComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - GridData gd = new GridData(GridData.FILL_BOTH); - Label targetNamespaceLabel = new Label(targetComp, SWT.NONE); - targetNamespaceLabel.setLayoutData(gd); - targetNamespaceLabel.setText(XMLUIMessages._UI_TARGET_NAMESPACE); - - targetNamespaceField = new Text(targetComp, SWT.BORDER); - targetNamespaceField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - targetNamespaceField.addModifyListener(new TargetNamespaceModifyListener()); - - // createControlArea(); - } - - public String getTargetNamespace() { - return targetNamespace; - } - - public void performEdit() { - Object selection = getSelection(tableViewer.getSelection()); - if (selection != null) { - boolean editTargetNamespace = false; - NamespaceInfo nsInfo = (NamespaceInfo) selection; - if (getTargetNamespace().equals(nsInfo.uri)) { - editTargetNamespace = true; - } - - invokeDialog(XMLUIMessages._UI_LABEL_NEW_NAMESPACE_INFORMATION, nsInfo); - updateErrorMessage(namespaceInfoList); - performDelayedUpdate(); - - if (editTargetNamespace) { - targetNamespaceField.setText(nsInfo.uri); - } - } - } - - public void setTargetNamespace(String theTargetNamespace) { - targetNamespace = theTargetNamespace != null ? theTargetNamespace : ""; //$NON-NLS-1$ - targetNamespaceField.setText(targetNamespace); - // updateTargetNamespaceAndNamespaceInfo(targetNamespace); - } - - void updateTargetNamespaceAndNamespaceInfo(String oldTargetNamespace, String newTargetNamespace) { - NamespaceInfo info = getNamespaceInfo(newTargetNamespace); - if (info == null) { - info = getNamespaceInfo(oldTargetNamespace); - if (info == null) { - info = new NamespaceInfo(newTargetNamespace, "tns", null); //$NON-NLS-1$ - namespaceInfoList.add(info); - } - else { - info.uri = targetNamespace; - } - } - tableViewer.refresh(); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/nsedit/CommonNamespaceInfoTable.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/nsedit/CommonNamespaceInfoTable.java deleted file mode 100644 index 44162e45ff..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/nsedit/CommonNamespaceInfoTable.java +++ /dev/null @@ -1,346 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.nsedit; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.jface.viewers.ColumnWeightData; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.TableLayout; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.MouseAdapter; -import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.swt.widgets.TableItem; -import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; - -public class CommonNamespaceInfoTable extends TableViewer { - - /** - * NamespaceInfoTableLabelProvider - */ - protected class Provider extends LabelProvider implements ITableLabelProvider, IStructuredContentProvider { - Viewer viewer; - - public Image getColumnImage(Object object, int columnIndex) { - Image result = null; - int columnCode = getColumnCode(columnIndex); - if (columnCode == COLUMN_LOCATION_HINT) { - NamespaceInfo info = (NamespaceInfo) object; - if ((info.locationHint == null) || info.locationHint.trim().equals("")) { //$NON-NLS-1$ - // Comment this out until we solve the alignment/(space - // for image being allocated - // to prefix column) ...... - // result = - // XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_WARNING_OBJ); - } - } - - return result; - } - - public String getColumnText(Object object, int column) { - NamespaceInfo info = (NamespaceInfo) object; - String result = null; - int columnCode = getColumnCode(column); - switch (columnCode) { - case COLUMN_PREFIX : { - result = info.prefix; - break; - } - case COLUMN_NAMESPACE_URI : { - result = info.uri; - break; - } - case COLUMN_CHECKBOX : { - result = ""; // info.locationHint; //$NON-NLS-1$ - break; - } - case COLUMN_LOCATION_HINT : { - result = info.locationHint; - break; - } - } - result = result != null ? result : ""; //$NON-NLS-1$ - if (result.equals("")) { //$NON-NLS-1$ - switch (columnCode) { - case COLUMN_PREFIX : { - result = XMLUIMessages._UI_NO_PREFIX; - break; - } - case COLUMN_NAMESPACE_URI : { - result = XMLUIMessages._UI_NO_NAMESPACE_NAME; - break; - } - } - } - return result; - } - - public Object[] getElements(Object inputElement) { - List list = (List) viewer.getInput(); - return list != null ? list.toArray() : null; - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - this.viewer = viewer; - } - } - - class TableItemChecker extends MouseAdapter { - public void mouseDown(MouseEvent e) { - TableItem item = getTable().getItem(new Point(e.x, e.y)); - if (item != null) { - Object obj = item.getData(); - if (obj != null) { - NamespaceInfo info = (NamespaceInfo) obj; - TableColumn col = getTable().getColumn(0); - if (e.x < col.getWidth()) // if the point falls within - // the - // Select column then perform - // check/uncheck - { - String currentState = (String) info.getProperty("checked"); //$NON-NLS-1$ - System.out.println("currentState" + currentState); //$NON-NLS-1$ - if ((currentState == null) || currentState.equals("false")) //$NON-NLS-1$ - { - info.setProperty("checked", "true"); //$NON-NLS-1$ //$NON-NLS-2$ - } - else { - info.setProperty("checked", "false"); //$NON-NLS-1$ //$NON-NLS-2$ - } - refresh(); - } - } - } - } - } - - protected static final int COLUMN_CHECKBOX = 1; - protected static final int COLUMN_LOCATION_HINT = 4; - protected static final int COLUMN_NAMESPACE_URI = 2; - protected static final int COLUMN_PREFIX = 3; - - protected static final String LABEL_CHECKBOX = ""; //$NON-NLS-1$ - protected static final String LABEL_LOCATION_HINT = XMLUIMessages._UI_LABEL_LOCATION_HINT; - protected static final String LABEL_NAMESPACE_URI = XMLUIMessages._UI_LABEL_NAMESPACE_NAME; - protected static final String LABEL_PREFIX = XMLUIMessages._UI_LABEL_PREFIX; - protected List checkedList = new ArrayList(); - - // protected List namespaceInfoList = new ArrayList(); - protected int[] columnIndexMap; - protected boolean showCheckBoxes = true; - private boolean showLocationText = false; - - private Table table; - protected int visibleRows = -1; - - public CommonNamespaceInfoTable(Composite parent, int visibleRows) { - this(parent, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER, visibleRows, false); - } - - // protected CellEditor getCellEditor(int column) - // { - // return (column == COLUMN_CHECKBOX) ? checkBoxCellEditor : - // textCellEditor; - // } - - public CommonNamespaceInfoTable(Composite parent, int visibleRows, boolean showLocationText) { - this(parent, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER, visibleRows, showLocationText); - } - - public CommonNamespaceInfoTable(Composite parent, int style, int visibleRows) { - this(parent, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER | style, visibleRows, false); - } - - public CommonNamespaceInfoTable(Composite parent, int style, int visibleRows, boolean showLocationText) { - super(new Table(parent, style)); - getTable().setLinesVisible(true); - this.showCheckBoxes = (style & SWT.CHECK) != 0; - columnIndexMap = createColumnIndexMap(); - this.showLocationText = showLocationText; - - Provider provider = new Provider(); - setContentProvider(provider); - setLabelProvider(provider); - - String[] columnPropertiesArray = createColumnPropertiesArray(); - setColumnProperties(columnPropertiesArray); - - table = getTable(); - table.setHeaderVisible(true); - table.setLayoutData(new GridData(GridData.FILL_BOTH)); - - TableLayout layout = new TableLayout(); - - for (int i = 0; i < columnPropertiesArray.length; i++) { - TableColumn column = new TableColumn(table, i); - if ((columnPropertiesArray[i]).equals(LABEL_LOCATION_HINT)) { - if (showLocationText) { - column.setText(columnPropertiesArray[i]); - } - else { - // Comment this out until we solve the alignment/(space - // for image being allocated - // to prefix column) ...... - // column.setImage(XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TXTEXT)); - } - } - else { - column.setText(columnPropertiesArray[i]); - } - column.setAlignment(SWT.LEFT); - layout.addColumnData(new ColumnWeightData(getColumnWidth(i), true)); - } - table.setLayout(layout); - - this.visibleRows = visibleRows; - // for (int i = 0; i < visibleRows; i++) - // { - // TableItem item = new TableItem(table, SWT.NONE); - // item.setText("#######"); - // } - // checkBoxCellEditor = new NamespaceInfoCheckboxCellEditor(table); - // textCellEditor = new TextCellEditor(table); - - /* - * CellEditor[] cellEditors = new - * CellEditor[columnPropertiesArray.length]; for (int i = 0; i < - * columnPropertiesArray.length; i++) { cellEditors[i] = - * getCellEditor(i); } setCellEditors(cellEditors); - */ - // if (showCheckBoxes) - // { - // getTable().addMouseListener(new TableItemChecker()); - // } - } - - // protected CellEditor checkBoxCellEditor; - // protected CellEditor textCellEditor; - - protected int[] createColumnIndexMap() { - int[] result = new int[showCheckBoxes ? 4 : 3]; - int i = 0; - if (showCheckBoxes) { - result[i++] = COLUMN_CHECKBOX; - } - result[i++] = COLUMN_PREFIX; - result[i++] = COLUMN_NAMESPACE_URI; - if (!showCheckBoxes) { - result[i++] = COLUMN_LOCATION_HINT; - } - return result; - } - - protected String[] createColumnPropertiesArray() { - String[] result = new String[3]; - int i = 0; - if (showCheckBoxes) { - result[i++] = LABEL_CHECKBOX; - } - result[i++] = LABEL_PREFIX; - result[i++] = LABEL_NAMESPACE_URI; - if (!showCheckBoxes) { - result[i++] = LABEL_LOCATION_HINT; - } - return result; - } - - protected int getColumnCode(int column) { - int result = 0; - if (column < columnIndexMap.length) { - result = columnIndexMap[column]; - } - return result; - } - - protected int getColumnWidth(int column) { - int result = 0; - switch (getColumnCode(column)) { - case COLUMN_PREFIX : { - result = 5; - break; - } - case COLUMN_NAMESPACE_URI : { - // Size columns differently when location hint text label is - // displayed - if (showLocationText) { - result = 10; - } - else { - result = 20; - } - break; - } - case COLUMN_CHECKBOX : { - result = 1; // info.locationHint; - break; - } - case COLUMN_LOCATION_HINT : { - // Size columns differently when location hint text label is - // displayed - if (showLocationText) { - result = 10; - } - else { - result = 2; - } - break; - } - } - return result; - } - /* - * protected class NamespaceInfoCellModifier implements ICellModifier { - * public NamespaceInfoCellModifier() { } - * - * public boolean canModify(Object element, String property) { if - * (property.equals(LABEL_CHECKBOX)) { return true; } else if - * (property.equals(LABEL_PREFIX)) { return true; } return false; } - * - * public Object getValue(Object element, String property) { int column = - * 0; if (property.equals(LABEL_CHECKBOX)) { column = 0; } else if - * (property.equals(LABEL_PREFIX)) { column = 1; } else if - * (property.equals(LABEL_NAMESPACE_URI)) { column = 2; } - * - * //if (element instanceof TableElement) //{ // return - * provider.getColumnText(element, column); //} //else //{ // return null; // } - * return "hello"; } - * - * public void modify(Object element, String property, Object value) { } } - * - * protected class NamespaceInfoCheckboxCellEditor extends - * CheckboxCellEditor implements MouseListener { public - * NamespaceInfoCheckboxCellEditor(Composite parent) { super(parent); } - * - * protected void doSetValue(Object value) { } - * - * public void activate() { super.activate(); deactivate(); - * Display.getCurrent().getFocusControl().redraw(); } - * - * public void mouseDown(MouseEvent e) { if (getTable().getItem(new - * Point(e.x, e.y)) != null) { } } public void mouseDoubleClick(MouseEvent - * e) { } public void mouseUp(MouseEvent e) { } } - */ -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/EmptyFilePreferencePage.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/EmptyFilePreferencePage.java deleted file mode 100644 index 9870632ea9..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/EmptyFilePreferencePage.java +++ /dev/null @@ -1,100 +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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.preferences; - -import org.eclipse.jface.preference.PreferencePage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.ScrolledComposite; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPreferencePage; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; - -public class EmptyFilePreferencePage extends PreferencePage implements IWorkbenchPreferencePage { - - private Composite createComposite(Composite parent, int numColumns) { - noDefaultAndApplyButton(); - - Composite composite = new Composite(parent, SWT.NULL); - - // GridLayout - GridLayout layout = new GridLayout(); - layout.numColumns = numColumns; - composite.setLayout(layout); - - // GridData - GridData data = new GridData(GridData.FILL); - data.horizontalIndent = 0; - data.verticalAlignment = GridData.FILL; - data.horizontalAlignment = GridData.FILL; - composite.setLayoutData(data); - - return composite; - } - - protected Control createContents(Composite parent) { - Composite composite = createScrolledComposite(parent); - - String description = XMLUIMessages.EmptyFilePreferencePage_0; - Text text = new Text(composite, SWT.READ_ONLY); - // some themes on GTK have different background colors for Text and Labels - text.setBackground(composite.getBackground()); - text.setText(description); - - setSize(composite); - return composite; - } - - private Composite createScrolledComposite(Composite parent) { - // create scrollbars for this parent when needed - final ScrolledComposite sc1 = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL); - sc1.setLayoutData(new GridData(GridData.FILL_BOTH)); - Composite composite = createComposite(sc1, 1); - sc1.setContent(composite); - - // not calling setSize for composite will result in a blank composite, - // so calling it here initially - // setSize actually needs to be called after all controls are created, - // so scrolledComposite - // has correct minSize - setSize(composite); - return composite; - } - - public void init(IWorkbench workbench) { - } - - private void setSize(Composite composite) { - if (composite != null) { - // Note: The font is set here in anticipation that the class inheriting - // this base class may add widgets to the dialog. setSize - // is assumed to be called just before we go live. - applyDialogFont(composite); - Point minSize = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT); - composite.setSize(minSize); - // set scrollbar composite's min size so page is expandable but - // has scrollbars when needed - if (composite.getParent() instanceof ScrolledComposite) { - ScrolledComposite sc1 = (ScrolledComposite) composite.getParent(); - sc1.setMinSize(minSize); - sc1.setExpandHorizontal(true); - sc1.setExpandVertical(true); - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/EncodingSettings.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/EncodingSettings.java deleted file mode 100644 index e2bbd570e4..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/EncodingSettings.java +++ /dev/null @@ -1,359 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.preferences; - -import java.util.Vector; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; -import org.eclipse.wst.sse.core.internal.encoding.CommonCharsetNames; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; - -/** - * EncodingSettings is a composite that can be used to display the set of - * encoding values that are available to the user. The list of encoding values - * is based off the SupportedJavaEncoding class. As the user selects an - * encoding from the combo box, the readonly field below it changes to show - * the IANA tag for that particular encoding description. The labels for the - * widgets are configurable and the initial value to display to the user can - * be set using the setIANATag(). The currently selected entry's IANA tag can - * be retrieved with getIANATag(). Entries displayed to the user can be added - * and removed. - */ -public class EncodingSettings extends Composite { - - private class ComboListener implements ModifyListener { - public void modifyText(ModifyEvent e) { - int i = encodingCombo.getSelectionIndex(); - if ((i >= 0) && (i < ianaVector.size())) { - ianaText.setText((String) (ianaVector.elementAt(encodingCombo.getSelectionIndex()))); - } - } - } - - private static String ENCODING_LABEL = XMLUIMessages.EncodingSettings_1; - - private static String IANA_LABEL = XMLUIMessages.EncodingSettings_0; - - private ModifyListener comboListener = new ComboListener(); - protected Combo encodingCombo; - protected Label encodingLabel, ianaLabel; - protected Text ianaText; - protected Vector ianaVector; - - /** - * Method EncodingSettings. - * - * @param parent - */ - public EncodingSettings(Composite parent) { - super(parent, SWT.NONE); - init(IANA_LABEL, ENCODING_LABEL); - } - - /** - * Method EncodingSettings. - * - * @param parent - * @param encodingLabel - - * text label to use beside the locale sensitive description of - * the currently selected encoding - */ - public EncodingSettings(Composite parent, String encodingLabel) { - super(parent, SWT.NONE); - init(IANA_LABEL, encodingLabel); - } - - /** - * Method EncodingSettings. - * - * @param parent - * @param ianaLabel = - * text label to use beside the display only IANA field - * @param encodingLabel - - * text label to use beside the locale sensitive description of - * the currently selected encoding - */ - public EncodingSettings(Composite parent, String ianaLabel, String encodingLabel) { - super(parent, SWT.NONE); - init(ianaLabel, encodingLabel); - } - - /** - * Method addEntry. Add an entry to the end of the Encoding Combobox - * - * @param description - - * encoding description to display - * @param ianaTag - - * IANA tag for the description - */ - public void addEntry(String description, String ianaTag) { - encodingCombo.add(description); - ianaVector.add(ianaTag); - } - - /** - * Method addEntry. Add an entry to the Encoding Combobox at index index - * - * @param description - - * encoding description to display - * @param ianaTag - - * IANA tag for the description - * @param index - - * index into the combo to add to - */ - public void addEntry(String description, String ianaTag, int index) { - if (index == ianaVector.size()) { - // just add to the end - addEntry(description, ianaTag); - return; - } - - if ((0 <= index) && (index < ianaVector.size())) { - encodingCombo.add(description, index); - ianaVector.add(index, ianaTag); - } - } - - protected Combo createComboBox(Composite parent, boolean isReadOnly) { - int style = isReadOnly == true ? SWT.READ_ONLY : SWT.DROP_DOWN; - - Combo combo = new Combo(parent, style); - - GridData data = new GridData(); - data.horizontalAlignment = GridData.FILL; - data.grabExcessHorizontalSpace = true; - combo.setLayoutData(data); - return combo; - } - - /** - * Helper method for creating labels. - */ - protected Label createLabel(Composite parent, String text) { - Label label = new Label(parent, SWT.LEFT); - label.setText(text); - - GridData data = new GridData(); - data.horizontalAlignment = GridData.FILL; - label.setLayoutData(data); - return label; - } - - protected Text createTextField(Composite parent, int width) { - Text text = new Text(parent, SWT.SINGLE | SWT.READ_ONLY); - - GridData data = new GridData(); - data.horizontalAlignment = GridData.FILL; - data.grabExcessHorizontalSpace = true; - data.widthHint = width; - text.setLayoutData(data); - - return text; - } - - /** - * @see org.eclipse.swt.widgets.Widget#dispose() - */ - public void dispose() { - encodingCombo.removeModifyListener(comboListener); - super.dispose(); - } - - private void fillCombo() { - try { - String[] ianaTags = CommonCharsetNames.getCommonCharsetNames(); - int totalNum = ianaTags.length; - for (int i = 0; i < totalNum; i++) { - String iana = ianaTags[i]; - String enc = CommonCharsetNames.getDisplayString(iana); - - if (enc != null) { - encodingCombo.add(enc); - } - else { - Logger.log(Logger.WARNING, "CommonCharsetNames.getDisplayString(" + iana + ") returned null"); //$NON-NLS-1$ //$NON-NLS-2$ - encodingCombo.add(iana); - } - ianaVector.add(iana); - } - } - catch (Exception e) { - // e.printStackTrace(); - // MessageDialog.openError(getShell(), "Resource exception", - // "Unable to obtain encoding strings. Check resource file"); - // XMLEncodingPlugin.getPlugin().getMsgLogger().write(e.toString()); - // XMLEncodingPlugin.getPlugin().getMsgLogger().writeCurrentThread(); - Logger.log(Logger.ERROR, "Exception", e); //$NON-NLS-1$ - } - } - - /** - * <code>getEncoding</code> Get the descriptive encoding name that was - * selected. - * - * @return a <code>String</code> value - */ - public String getEncoding() { - return encodingCombo.getText(); - } - - /** - * Method getEncodingCombo. Returns the combo used to display the encoding - * descriptions. - * - * @return Combo - */ - public Combo getEncodingCombo() { - return encodingCombo; - } - - /** - * <code>getIANATag</code> Get the IANA tag equivalent of the selected - * descriptive encoding name - * - * @return a <code>String</code> value - */ - public String getIANATag() { - int i = encodingCombo.getSelectionIndex(); - if (i >= 0) { - return (String) (ianaVector.elementAt(i)); - } - return ""; //$NON-NLS-1$ - } - - protected void init(String ianaLabelStr, String encodingLabelStr) { - GridLayout layout = new GridLayout(); - layout.numColumns = 2; - setLayout(layout); - GridData data = new GridData(); - data.verticalAlignment = GridData.FILL; - data.horizontalAlignment = GridData.FILL; - data.grabExcessHorizontalSpace = true; - setLayoutData(data); - - encodingLabel = createLabel(this, encodingLabelStr); - encodingCombo = createComboBox(this, true); - ianaLabel = createLabel(this, ianaLabelStr); - ianaText = createTextField(this, 20); - ianaVector = new Vector(); - - fillCombo(); - resetToDefaultEncoding(); - encodingCombo.addModifyListener(comboListener); - } - - /** - * <code>isEncodingInList</code> Checks whether the encoding name is in - * the combo - * - * @param enc - * a <code>string</code> value. The encoding name. - * @return a <code>boolean</code> value. TRUE if encoding is in list. - * FALSE if encoding is not in list. - */ - public boolean isEncodingInList(String enc) { - int i = encodingCombo.indexOf(enc); - if (i >= 0) { - return true; - } - return false; - } - - /** - * <code>isIANATagInList</code> Checks whether the IANA tag is in the - * combo - * - * @param ianaTag - * a <code>string</code> value. The IANA tag. - * @return a <code>boolean</code> value. TRUE if tag is in list. FALSE - * if tag is not in list. - */ - public boolean isIANATagInList(String ianaTag) { - int i = ianaVector.indexOf(ianaTag); - if (i >= 0) { - return true; - } - return false; - } - - /** - * Method removeEntry. Removes both the description and the IANA tag at - * the specified index - * - * @param index - */ - public void removeEntry(int index) { - if ((0 <= index) && (index < ianaVector.size())) { - encodingCombo.remove(index); - ianaVector.remove(index); - } - } - - /** - * Method resetToDefaultEncoding. Reset the control to the default - * encoding. Currently UTF-8 - */ - public void resetToDefaultEncoding() { - String defaultIANATag = "UTF-8"; //$NON-NLS-1$ - ianaText.setText(defaultIANATag); - setIANATag(defaultIANATag); - } - - /** - * Method setEnabled. Enable/disable the EncodingSettings composite. - * - * @param enabled - */ - public void setEnabled(boolean enabled) { - encodingCombo.setEnabled(enabled); - encodingLabel.setEnabled(enabled); - ianaLabel.setEnabled(enabled); - ianaText.setEnabled(enabled); - } - - /** - * <code>setEncoding</code> Set the selection in the combo to the - * descriptive encoding name. - * - * @param enc - * a <code>string</code> value. Note this is not the IANA - * tag. - */ - public void setEncoding(String enc) { - encodingCombo.setText(enc); - encodingCombo.select(encodingCombo.indexOf(enc)); - } - - /** - * <code>setIANATag</code> Set the IANA tag for the combo - * - * @param ianaTag - * a <code>string</code> value. The IANA tag. - */ - public void setIANATag(String ianaTag) { - int i = ianaVector.indexOf(ianaTag); - if (i >= 0) { - encodingCombo.select(i); - } - } - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/WorkbenchDefaultEncodingSettings.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/WorkbenchDefaultEncodingSettings.java deleted file mode 100644 index e7930edb9e..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/WorkbenchDefaultEncodingSettings.java +++ /dev/null @@ -1,141 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.preferences; - -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.wst.sse.core.internal.encoding.CommonCharsetNames; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; - -/** - * WorkbenchDefaultEncodingSettings is an extension of EncodingSettings. This - * composite contains EncodingSettings for users to select the encoding they - * desire as well as a checkbox for users to select to use the default - * workbench encoding instead. - * - * @see org.eclipse.wst.xml.ui.internal.preferences.EncodingSettings - */ -public class WorkbenchDefaultEncodingSettings extends Composite { - - private final static int INDENT = 15; - private static final String WORKBENCH_DEFAULT = ""; //$NON-NLS-1$ - private EncodingSettings fEncodingSettings; - private String fNonDefaultIANA = null; - private Button fUseDefaultButton; - - public WorkbenchDefaultEncodingSettings(Composite parent) { - super(parent, SWT.NONE); - createControls(); - } - - private void createControls() { - GridLayout layout = new GridLayout(); - layout.numColumns = 1; - layout.marginWidth = 0; - setLayout(layout); - GridData data = new GridData(); - data.verticalAlignment = GridData.FILL; - data.horizontalAlignment = GridData.FILL; - data.grabExcessHorizontalSpace = true; - setLayoutData(data); - - Composite defaultEncodingComposite = new Composite(this, SWT.NONE); - layout = new GridLayout(); - layout.marginWidth = 0; - layout.marginHeight = 0; - data = new GridData(GridData.FILL_BOTH); - defaultEncodingComposite.setLayout(layout); - defaultEncodingComposite.setLayoutData(data); - - fUseDefaultButton = new Button(defaultEncodingComposite, SWT.CHECK); - fUseDefaultButton.setText(XMLUIMessages.WorkbenchDefaultEncodingSettings_0); - - fUseDefaultButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - handleUseDefaultButtonSelected(); - } - }); - - fEncodingSettings = new EncodingSettings(this); - ((GridLayout) fEncodingSettings.getLayout()).marginWidth = 0; - ((GridData) fEncodingSettings.getLayoutData()).horizontalIndent = INDENT; - - } - - private Combo getEncodingCombo() { - return fEncodingSettings.getEncodingCombo(); - } - - /** - * <code>getIANATag</code> Get the IANA tag equivalent of the selected - * descriptive encoding name. Returns empty string if using workbench - * encoding. - * - * @return a <code>String</code> value - */ - public String getIANATag() { - if (!isDefault()) { - return fEncodingSettings.getIANATag(); - } - return WORKBENCH_DEFAULT; - } - - private String getWorkbenchEncoding() { - return ResourcesPlugin.getEncoding(); - } - - void handleUseDefaultButtonSelected() { - if (fUseDefaultButton.getSelection()) { - fNonDefaultIANA = fEncodingSettings.getIANATag(); - String workbenchValue = getWorkbenchEncoding(); - workbenchValue = CommonCharsetNames.getIanaPreferredCharsetName(workbenchValue); - fEncodingSettings.setIANATag(workbenchValue); - } - else if (fNonDefaultIANA != null) { - fEncodingSettings.setIANATag(fNonDefaultIANA); - } - getEncodingCombo().setEnabled(!fUseDefaultButton.getSelection()); - fEncodingSettings.setEnabled(!fUseDefaultButton.getSelection()); - } - - private boolean isDefault() { - return fUseDefaultButton.getSelection(); - } - - /** - * <code>setEncoding</code> Set the selection in the combo to the - * descriptive encoding name. Selects use workbench encoding if ianaTag is - * null or empty string. - * - */ - public void setIANATag(String ianaTag) { - if ((ianaTag == null) || ianaTag.equals(WORKBENCH_DEFAULT)) { - fUseDefaultButton.setSelection(true); - handleUseDefaultButtonSelected(); - } - else { - fUseDefaultButton.setSelection(false); - handleUseDefaultButtonSelected(); - if (!isDefault()) { - fEncodingSettings.setIANATag(ianaTag); - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLColorPage.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLColorPage.java deleted file mode 100644 index 4f29d750f1..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLColorPage.java +++ /dev/null @@ -1,288 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * Benjamin Muskalla, b.muskalla@gmx.net - [158660] character entities should have their own syntax highlighting preference - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.preferences; - -import java.util.ArrayList; -import java.util.Dictionary; -import java.util.Hashtable; -import java.util.Iterator; - -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IModelManager; -import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; -import org.eclipse.wst.sse.ui.internal.preferences.OverlayPreferenceStore; -import org.eclipse.wst.sse.ui.internal.preferences.OverlayPreferenceStore.OverlayKey; -import org.eclipse.wst.sse.ui.internal.preferences.ui.AbstractColorPage; -import org.eclipse.wst.sse.ui.internal.preferences.ui.StyledTextColorPicker; -import org.eclipse.wst.xml.core.internal.provisional.contenttype.ContentTypeIdForXML; -import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.internal.editor.IHelpContextIds; -import org.eclipse.wst.xml.ui.internal.style.IStyleConstantsXML; - -/** - * @deprecated - */ -public class XMLColorPage extends AbstractColorPage { - - protected Control createContents(Composite parent) { - Composite pageComponent = createComposite(parent, 1); - ((GridData) pageComponent.getLayoutData()).horizontalAlignment = GridData.HORIZONTAL_ALIGN_FILL; - - super.createContents(pageComponent); - PlatformUI.getWorkbench().getHelpSystem().setHelp(pageComponent, IHelpContextIds.XML_PREFWEBX_STYLES_HELPID); - return pageComponent; - } - - /** - * Set up all the style preference keys in the overlay store - */ - protected OverlayKey[] createOverlayStoreKeys() { - ArrayList overlayKeys = new ArrayList(); - - ArrayList styleList = new ArrayList(); - initStyleList(styleList); - Iterator i = styleList.iterator(); - while (i.hasNext()) { - overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, (String) i.next())); - } - - OverlayPreferenceStore.OverlayKey[] keys = new OverlayPreferenceStore.OverlayKey[overlayKeys.size()]; - overlayKeys.toArray(keys); - return keys; - } - - protected IPreferenceStore doGetPreferenceStore() { - return XMLUIPlugin.getDefault().getPreferenceStore(); - } - - public String getSampleText() { - return XMLUIMessages.Sample_XML_doc; // = "<?xml - // version=\"1.0\"?>\n<?customProcessingInstruction\n\tXML - // processor - // specific\n\tcontent - // ?>\n<!DOCTYPE - // colors\n\tPUBLIC - // \"//IBM/XML/COLORS/\" - // \"colors.dtd\">\n<colors>\n\t<!-- - // begin color definitions - // -->\n\t<color - // name=\"plaintext\" - // foreground=\"#000000\"\n\t\tbackground=\"#D4D0C8\"/>\n\t<color - // name=\"bold\" - // foreground=\"#000000\"\n\t\tbackground=\"#B3ACA0\">\n\t<![CDATA[<123456789>]]>\n\tNormal - // text content.\n\t<color - // name=\"inverse\" - // foreground=\"#F0F0F0\"\n\t\tbackground=\"#D4D0C8\"/>\n\n</colors>\n"; - } - - protected void initCommonContextStyleMap(Dictionary contextStyleMap) { - - contextStyleMap.put(DOMRegionContext.XML_COMMENT_OPEN, IStyleConstantsXML.COMMENT_BORDER); - contextStyleMap.put(DOMRegionContext.XML_COMMENT_TEXT, IStyleConstantsXML.COMMENT_TEXT); - contextStyleMap.put(DOMRegionContext.XML_COMMENT_CLOSE, IStyleConstantsXML.COMMENT_BORDER); - - contextStyleMap.put(DOMRegionContext.XML_TAG_OPEN, IStyleConstantsXML.TAG_BORDER); - contextStyleMap.put(DOMRegionContext.XML_END_TAG_OPEN, IStyleConstantsXML.TAG_BORDER); - contextStyleMap.put(DOMRegionContext.XML_TAG_NAME, IStyleConstantsXML.TAG_NAME); - contextStyleMap.put(DOMRegionContext.XML_TAG_ATTRIBUTE_NAME, IStyleConstantsXML.TAG_ATTRIBUTE_NAME); - contextStyleMap.put(DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE, IStyleConstantsXML.TAG_ATTRIBUTE_VALUE); - contextStyleMap.put(DOMRegionContext.XML_TAG_CLOSE, IStyleConstantsXML.TAG_BORDER); - contextStyleMap.put(DOMRegionContext.XML_EMPTY_TAG_CLOSE, IStyleConstantsXML.TAG_BORDER); - - contextStyleMap.put(DOMRegionContext.XML_DECLARATION_OPEN, IStyleConstantsXML.DECL_BORDER); - contextStyleMap.put(DOMRegionContext.XML_DECLARATION_CLOSE, IStyleConstantsXML.DECL_BORDER); - contextStyleMap.put(DOMRegionContext.XML_ELEMENT_DECLARATION, IStyleConstantsXML.DECL_BORDER); - contextStyleMap.put(DOMRegionContext.XML_ELEMENT_DECL_CLOSE, IStyleConstantsXML.DECL_BORDER); - - contextStyleMap.put(DOMRegionContext.XML_CHAR_REFERENCE, IStyleConstantsXML.ENTITY_REFERENCE); - contextStyleMap.put(DOMRegionContext.XML_ENTITY_REFERENCE, IStyleConstantsXML.ENTITY_REFERENCE); - contextStyleMap.put(DOMRegionContext.XML_PE_REFERENCE, IStyleConstantsXML.ENTITY_REFERENCE); - - contextStyleMap.put(DOMRegionContext.XML_CONTENT, IStyleConstantsXML.XML_CONTENT); - } - - protected void initCommonDescriptions(Dictionary descriptions) { - - // create descriptions for hilighting types - descriptions.put(IStyleConstantsXML.COMMENT_BORDER, XMLUIMessages.Comment_Delimiters_UI_); // = - // "Comment - // Delimiters" - descriptions.put(IStyleConstantsXML.COMMENT_TEXT, XMLUIMessages.Comment_Content_UI_); // = - // "Comment - // Content" - descriptions.put(IStyleConstantsXML.TAG_BORDER, XMLUIMessages.Tag_Delimiters_UI_); // = - // "Tag - // Delimiters" - descriptions.put(IStyleConstantsXML.TAG_NAME, XMLUIMessages.Tag_Names_UI_); // = - // "Tag - // Names" - descriptions.put(IStyleConstantsXML.TAG_ATTRIBUTE_NAME, XMLUIMessages.Attribute_Names_UI_); // = - // "Attribute - // Names" - descriptions.put(IStyleConstantsXML.TAG_ATTRIBUTE_VALUE, XMLUIMessages.Attribute_Values_UI_); // = - // "Attribute - // Values" - descriptions.put(IStyleConstantsXML.DECL_BORDER, XMLUIMessages.Declaration_Delimiters_UI_); // = - // "Declaration - // Delimiters" - descriptions.put(IStyleConstantsXML.XML_CONTENT, XMLUIMessages.Content_UI_); // = - // "Content" - descriptions.put(IStyleConstantsXML.ENTITY_REFERENCE, XMLUIMessages.Entity_Reference_UI_); //$NON-NLS-1$ = "Entity References" - } - - protected void initCommonStyleList(ArrayList list) { - - // list.add(IStyleConstantsXML.CDATA_BORDER); - // list.add(IStyleConstantsXML.CDATA_TEXT); - // list.add(IStyleConstantsXML.PI_BORDER); - // list.add(IStyleConstantsXML.PI_CONTENT); - - list.add(IStyleConstantsXML.TAG_BORDER); - list.add(IStyleConstantsXML.TAG_NAME); - list.add(IStyleConstantsXML.TAG_ATTRIBUTE_NAME); - list.add(IStyleConstantsXML.TAG_ATTRIBUTE_VALUE); - list.add(IStyleConstantsXML.COMMENT_BORDER); - list.add(IStyleConstantsXML.COMMENT_TEXT); - list.add(IStyleConstantsXML.DECL_BORDER); - list.add(IStyleConstantsXML.XML_CONTENT); - list.add(IStyleConstantsXML.ENTITY_REFERENCE); - } - - protected void initContextStyleMap(Dictionary contextStyleMap) { - - initCommonContextStyleMap(contextStyleMap); - initDocTypeContextStyleMap(contextStyleMap); - contextStyleMap.put(DOMRegionContext.XML_CDATA_OPEN, IStyleConstantsXML.CDATA_BORDER); - contextStyleMap.put(DOMRegionContext.XML_CDATA_TEXT, IStyleConstantsXML.CDATA_TEXT); - contextStyleMap.put(DOMRegionContext.XML_CDATA_CLOSE, IStyleConstantsXML.CDATA_BORDER); - - contextStyleMap.put(DOMRegionContext.XML_PI_OPEN, IStyleConstantsXML.PI_BORDER); - contextStyleMap.put(DOMRegionContext.XML_PI_CONTENT, IStyleConstantsXML.PI_CONTENT); - contextStyleMap.put(DOMRegionContext.XML_PI_CLOSE, IStyleConstantsXML.PI_BORDER); - - } - - protected void initDescriptions(Dictionary descriptions) { - - initCommonDescriptions(descriptions); - initDocTypeDescriptions(descriptions); - descriptions.put(IStyleConstantsXML.CDATA_BORDER, XMLUIMessages.CDATA_Delimiters_UI_); // = - // "CDATA - // Delimiters" - descriptions.put(IStyleConstantsXML.CDATA_TEXT, XMLUIMessages.CDATA_Content_UI_); // = - // "CDATA - // Content" - descriptions.put(IStyleConstantsXML.PI_BORDER, XMLUIMessages.Processing_Instruction_Del_UI_); // = - // "Processing - // Instruction - // Delimiters" - descriptions.put(IStyleConstantsXML.PI_CONTENT, XMLUIMessages.Processing_Instruction_Con_UI__UI_); // = - // "Processing - // Instruction - // Content" - } - - protected void initDocTypeContextStyleMap(Dictionary contextStyleMap) { - - contextStyleMap.put(DOMRegionContext.XML_ELEMENT_DECL_NAME, IStyleConstantsXML.DOCTYPE_NAME); - contextStyleMap.put(DOMRegionContext.XML_DOCTYPE_DECLARATION, IStyleConstantsXML.TAG_NAME); - contextStyleMap.put(DOMRegionContext.XML_DOCTYPE_DECLARATION_CLOSE, IStyleConstantsXML.DECL_BORDER); - - contextStyleMap.put(DOMRegionContext.XML_DOCTYPE_NAME, IStyleConstantsXML.DOCTYPE_NAME); - contextStyleMap.put(DOMRegionContext.XML_DOCTYPE_EXTERNAL_ID_PUBLIC, IStyleConstantsXML.DOCTYPE_EXTERNAL_ID); - contextStyleMap.put(DOMRegionContext.XML_DOCTYPE_EXTERNAL_ID_PUBREF, IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_PUBREF); - contextStyleMap.put(DOMRegionContext.XML_DOCTYPE_EXTERNAL_ID_SYSTEM, IStyleConstantsXML.DOCTYPE_EXTERNAL_ID); - contextStyleMap.put(DOMRegionContext.XML_DOCTYPE_EXTERNAL_ID_SYSREF, IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_SYSREF); - } - - protected void initDocTypeDescriptions(Dictionary descriptions) { - - // create descriptions for hilighting types for DOCTYPE related items - descriptions.put(IStyleConstantsXML.DOCTYPE_NAME, XMLUIMessages.DOCTYPE_Name_UI_); // = - // "DOCTYPE - // Name" - descriptions.put(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID, XMLUIMessages.DOCTYPE_SYSTEM_PUBLIC_Keyw_UI_); // = - // "DOCTYPE - // SYSTEM/PUBLIC - // Keyword" - descriptions.put(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_PUBREF, XMLUIMessages.DOCTYPE_Public_Reference_UI_); // = - // "DOCTYPE - // Public - // Reference" - descriptions.put(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_SYSREF, XMLUIMessages.DOCTYPE_System_Reference_UI_); // = - // "DOCTYPE - // System - // Reference" - } - - protected void initDocTypeStyleList(ArrayList list) { - - list.add(IStyleConstantsXML.DOCTYPE_NAME); - list.add(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID); - list.add(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_PUBREF); - list.add(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_SYSREF); - } - - protected void initStyleList(ArrayList list) { - initCommonStyleList(list); - initDocTypeStyleList(list); - list.add(IStyleConstantsXML.CDATA_BORDER); - list.add(IStyleConstantsXML.CDATA_TEXT); - list.add(IStyleConstantsXML.PI_BORDER); - list.add(IStyleConstantsXML.PI_CONTENT); - } - - public boolean performOk() { - // required since the superclass *removes* existing preferences before - // saving its own - super.performOk(); - - SSEUIPlugin.getDefault().savePluginPreferences(); - return true; - } - - protected void setupPicker(StyledTextColorPicker picker) { - IModelManager mmanager = StructuredModelManager.getModelManager(); - picker.setParser(mmanager.createStructuredDocumentFor(ContentTypeIdForXML.ContentTypeID_XML).getParser()); - - Dictionary descriptions = new Hashtable(); - initDescriptions(descriptions); - - Dictionary contextStyleMap = new Hashtable(); - initContextStyleMap(contextStyleMap); - - ArrayList styleList = new ArrayList(); - initStyleList(styleList); - - picker.setContextStyleMap(contextStyleMap); - picker.setDescriptions(descriptions); - picker.setStyleList(styleList); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.preferences.ui.AbstractColorPage#savePreferences() - */ - protected void savePreferences() { - XMLUIPlugin.getDefault().savePluginPreferences(); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLFilesPreferencePage.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLFilesPreferencePage.java deleted file mode 100644 index 0f3cc0e8a6..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLFilesPreferencePage.java +++ /dev/null @@ -1,259 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * David Carver - STAR - [205989] - [validation] validate XML after XInclude resolution - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.preferences; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Preferences; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames; -import org.eclipse.wst.sse.core.utils.StringUtils; -import org.eclipse.wst.sse.ui.internal.preferences.ui.AbstractPreferencePage; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames; -import org.eclipse.wst.xml.core.internal.provisional.contenttype.ContentTypeIdForXML; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.editor.IHelpContextIds; - -public class XMLFilesPreferencePage extends AbstractPreferencePage { - protected EncodingSettings fEncodingSettings = null; - - private Combo fDefaultSuffix = null; - private List fValidExtensions = null; - private Combo fIndicateNoGrammar = null; - private Button fUseXinclude = null; - - /** - * @param parent - * @return - */ - private Combo createCombo(Composite parent, String[] items) { - Combo combo = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY); - combo.setItems(items); - - //GridData - GridData data = new GridData(SWT.FILL, SWT.CENTER, true, true); - combo.setLayoutData(data); - - return combo; - } - - protected Control createContents(Composite parent) { - Composite composite = (Composite) super.createContents(parent); - PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.XML_PREFWEBX_FILES_HELPID); - createContentsForCreatingGroup(composite); - createContentsForValidatingGroup(composite); - - setSize(composite); - loadPreferences(); - - return composite; - } - - protected void createContentsForCreatingGroup(Composite parent) { - Group creatingGroup = createGroup(parent, 2); - creatingGroup.setText(XMLUIMessages.Creating_files); - - // Default extension for New file Wizard - createLabel(creatingGroup, XMLUIMessages.XMLFilesPreferencePage_ExtensionLabel); - fDefaultSuffix = createDropDownBox(creatingGroup); - String[] validExtensions = (String[]) getValidExtensions().toArray(new String[0]); - Arrays.sort(validExtensions); - fDefaultSuffix.setItems(validExtensions); - fDefaultSuffix.addSelectionListener(this); - - Label label = createLabel(creatingGroup, XMLUIMessages.Encoding_desc); - ((GridData) label.getLayoutData()).horizontalSpan = 2; - fEncodingSettings = new EncodingSettings(creatingGroup, XMLUIMessages.Encoding); - ((GridData) fEncodingSettings.getLayoutData()).horizontalSpan = 2; - } - - protected void createContentsForValidatingGroup(Composite parent) { - Group validatingGroup = createGroup(parent, 2); - ((GridLayout) validatingGroup.getLayout()).makeColumnsEqualWidth = false; - validatingGroup.setText(XMLUIMessages.Validating_files); - - if (fIndicateNoGrammar == null) { - createLabel(validatingGroup, XMLUIMessages.Indicate_no_grammar_specified); - fIndicateNoGrammar = createCombo(validatingGroup, StringUtils.unpack(XMLUIMessages.Indicate_no_grammar_specified_severities)); - } - if (fUseXinclude == null) { - fUseXinclude = createCheckBox(validatingGroup, XMLUIMessages.Use_XInclude); - } - - new Label(validatingGroup, SWT.NONE).setLayoutData(new GridData()); - } - - public void dispose() { - fDefaultSuffix.removeModifyListener(this); - super.dispose(); - } - - protected void doSavePreferenceStore() { - XMLCorePlugin.getDefault().savePluginPreferences(); // model - } - - /** - * Get content type associated with this new file wizard - * - * @return IContentType - */ - protected IContentType getContentType() { - return Platform.getContentTypeManager().getContentType(ContentTypeIdForXML.ContentTypeID_XML); - } - - /** - * Get list of valid extensions - * - * @return List - */ - private List getValidExtensions() { - if (fValidExtensions == null) { - IContentType type = getContentType(); - fValidExtensions = new ArrayList(Arrays.asList(type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC))); - } - return fValidExtensions; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.preferences.ui.AbstractPreferencePage#getModelPreferences() - */ - protected Preferences getModelPreferences() { - return XMLCorePlugin.getDefault().getPluginPreferences(); - } - - protected void initializeValues() { - initializeValuesForCreatingGroup(); - initializeValuesForValidatingGroup(); - } - - protected void initializeValuesForCreatingGroup() { - String suffix = getModelPreferences().getString(XMLCorePreferenceNames.DEFAULT_EXTENSION); - fDefaultSuffix.setText(suffix); - - String encoding = getModelPreferences().getString(CommonEncodingPreferenceNames.OUTPUT_CODESET); - - fEncodingSettings.setIANATag(encoding); - } - - protected void initializeValuesForValidatingGroup() { - int indicateNoGrammarButtonSelected = getModelPreferences().getInt(XMLCorePreferenceNames.INDICATE_NO_GRAMMAR); - boolean useXIncludeButtonSelected = getModelPreferences().getBoolean(XMLCorePreferenceNames.USE_XINCLUDE); - - if (fIndicateNoGrammar != null) { - fIndicateNoGrammar.select(2 - indicateNoGrammarButtonSelected); - fIndicateNoGrammar.setText(StringUtils.unpack(XMLUIMessages.Indicate_no_grammar_specified_severities)[2-indicateNoGrammarButtonSelected]); - } - if (fUseXinclude != null) { - fUseXinclude.setSelection(useXIncludeButtonSelected); - } - } - - protected void performDefaults() { - performDefaultsForCreatingGroup(); - performDefaultsForValidatingGroup(); - - super.performDefaults(); - } - - protected void performDefaultsForCreatingGroup() { - String suffix = getModelPreferences().getDefaultString(XMLCorePreferenceNames.DEFAULT_EXTENSION); - fDefaultSuffix.setText(suffix); - - String encoding = getModelPreferences().getDefaultString(CommonEncodingPreferenceNames.OUTPUT_CODESET); - - fEncodingSettings.setIANATag(encoding); - // fEncodingSettings.resetToDefaultEncoding(); - } - - protected void performDefaultsForValidatingGroup() { - int indicateNoGrammarButtonSelected = getModelPreferences().getDefaultInt(XMLCorePreferenceNames.INDICATE_NO_GRAMMAR); - boolean useXIncludeButtonSelected = getModelPreferences().getDefaultBoolean(XMLCorePreferenceNames.USE_XINCLUDE); - - if (fIndicateNoGrammar != null) { - fIndicateNoGrammar.setSelection(new Point(indicateNoGrammarButtonSelected, 2 - indicateNoGrammarButtonSelected)); - fIndicateNoGrammar.setText(StringUtils.unpack(XMLUIMessages.Indicate_no_grammar_specified_severities)[indicateNoGrammarButtonSelected]); - } - if (fUseXinclude != null) { - fUseXinclude.setSelection(useXIncludeButtonSelected); - } - } - - public boolean performOk() { - boolean result = super.performOk(); - - doSavePreferenceStore(); - - return result; - } - - protected void storeValues() { - storeValuesForCreatingGroup(); - storeValuesForValidatingGroup(); - } - - protected void storeValuesForCreatingGroup() { - String suffix = fDefaultSuffix.getText(); - getModelPreferences().setValue(XMLCorePreferenceNames.DEFAULT_EXTENSION, suffix); - - getModelPreferences().setValue(CommonEncodingPreferenceNames.OUTPUT_CODESET, fEncodingSettings.getIANATag()); - } - - protected void storeValuesForValidatingGroup() { - if (fIndicateNoGrammar != null) { - int warnNoGrammarButtonSelected = 2 - fIndicateNoGrammar.getSelectionIndex(); - getModelPreferences().setValue(XMLCorePreferenceNames.INDICATE_NO_GRAMMAR, warnNoGrammarButtonSelected); - } - if (fUseXinclude != null) { - boolean useXIncludeButtonSelected = fUseXinclude.getSelection(); - getModelPreferences().setValue(XMLCorePreferenceNames.USE_XINCLUDE, useXIncludeButtonSelected); - } - } - - protected void validateValues() { - boolean isValid = false; - Iterator i = getValidExtensions().iterator(); - while (i.hasNext() && !isValid) { - String extension = (String) i.next(); - isValid = extension.equalsIgnoreCase(fDefaultSuffix.getText()); - } - - if (!isValid) { - setErrorMessage(NLS.bind(XMLUIMessages.XMLFilesPreferencePage_ExtensionError, getValidExtensions().toString())); - setValid(false); - } - else { - setErrorMessage(null); - setValid(true); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLSourcePreferencePage.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLSourcePreferencePage.java deleted file mode 100644 index db5131029c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLSourcePreferencePage.java +++ /dev/null @@ -1,387 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.preferences; - -import java.util.Vector; - -import org.eclipse.core.runtime.Preferences; -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Spinner; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.IWorkbenchPreferencePage; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.PreferenceLinkArea; -import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer; -import org.eclipse.wst.sse.ui.internal.preferences.ui.AbstractPreferencePage; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.internal.editor.IHelpContextIds; - -public class XMLSourcePreferencePage extends AbstractPreferencePage implements ModifyListener, SelectionListener, IWorkbenchPreferencePage { - private final int MIN_INDENTATION_SIZE = 0; - private final int MAX_INDENTATION_SIZE = 16; - - // Content Assist - protected Button fAutoPropose; - protected Label fAutoProposeLabel; - protected Text fAutoProposeText; - private Combo fSuggestionStrategyCombo; - private Vector fSuggestionStrategies = null; - protected Button fClearAllBlankLines; - - // Formatting - protected Label fLineWidthLabel; - protected Text fLineWidthText; - protected Button fSplitMultiAttrs; - private Button fIndentUsingTabs; - private Button fIndentUsingSpaces; - private Spinner fIndentationSize; - private Button fPreservePCDATAContent; - private Button fAlignEndBracket; - // BUG195264 - Support for removing/adding a space before empty close tags - private Button fSpaceBeforeEmptyCloseTag; - - // grammar constraints - protected Button fUseInferredGrammar; - - protected Control createContents(Composite parent) { - final Composite composite = super.createComposite(parent, 1); - PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.XML_PREFWEBX_SOURCE_HELPID); - - new PreferenceLinkArea(composite, SWT.WRAP | SWT.MULTI, "org.eclipse.wst.sse.ui.preferences.editor", XMLUIMessages._UI_STRUCTURED_TEXT_EDITOR_PREFS_LINK,//$NON-NLS-1$ - (IWorkbenchPreferenceContainer) getContainer(), null).getControl().setLayoutData(GridDataFactory.fillDefaults().hint(150, SWT.DEFAULT).create()); - new Label(composite, SWT.NONE).setLayoutData(GridDataFactory.swtDefaults().create()); - - createContentsForFormattingGroup(composite); - createContentsForContentAssistGroup(composite); - createContentsForGrammarConstraintsGroup(composite); - setSize(composite); - loadPreferences(); - - return composite; - } - - protected void createContentsForContentAssistGroup(Composite parent) { - Group contentAssistGroup = createGroup(parent, 2); - contentAssistGroup.setText(XMLUIMessages.Content_assist_UI_); - - fAutoPropose = createCheckBox(contentAssistGroup, XMLUIMessages.Automatically_make_suggest_UI_); - ((GridData) fAutoPropose.getLayoutData()).horizontalSpan = 2; - fAutoPropose.addSelectionListener(this); - - fAutoProposeLabel = createLabel(contentAssistGroup, XMLUIMessages.Prompt_when_these_characte_UI_); - fAutoProposeText = createTextField(contentAssistGroup); - - createLabel(contentAssistGroup, XMLUIMessages.Suggestion_Strategy); - fSuggestionStrategyCombo = new Combo(contentAssistGroup, SWT.READ_ONLY); - fSuggestionStrategies = new Vector(); - fSuggestionStrategyCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - fSuggestionStrategyCombo.add(XMLUIMessages.Suggestion_Strategy_Lax); - fSuggestionStrategies.add(XMLUIPreferenceNames.SUGGESTION_STRATEGY_VALUE_LAX); - fSuggestionStrategyCombo.add(XMLUIMessages.Suggestion_Strategy_Strict); - fSuggestionStrategies.add(XMLUIPreferenceNames.SUGGESTION_STRATEGY_VALUE_STRICT); - } - - protected void createContentsForFormattingGroup(Composite parent) { - Group formattingGroup = createGroup(parent, 2); - formattingGroup.setText(XMLUIMessages.Formatting_UI_); - - fLineWidthLabel = createLabel(formattingGroup, XMLUIMessages.Line_width__UI_); - fLineWidthText = new Text(formattingGroup, SWT.SINGLE | SWT.BORDER); - GridData gData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.BEGINNING); - gData.widthHint = 25; - fLineWidthText.setLayoutData(gData); - fLineWidthText.addModifyListener(this); - - fSplitMultiAttrs = createCheckBox(formattingGroup, XMLUIMessages.Split_multiple_attributes); - ((GridData) fSplitMultiAttrs.getLayoutData()).horizontalSpan = 2; - fAlignEndBracket = createCheckBox(formattingGroup, XMLUIMessages.Align_final_bracket); - ((GridData) fAlignEndBracket.getLayoutData()).horizontalSpan = 2; - fPreservePCDATAContent = createCheckBox(formattingGroup, XMLUIMessages.Preserve_PCDATA_Content); - ((GridData) fPreservePCDATAContent.getLayoutData()).horizontalSpan = 2; - fClearAllBlankLines = createCheckBox(formattingGroup, XMLUIMessages.Clear_all_blank_lines_UI_); - ((GridData) fClearAllBlankLines.getLayoutData()).horizontalSpan = 2; - fSpaceBeforeEmptyCloseTag = createCheckBox(formattingGroup, XMLUIMessages.Space_before_empty_close_tag); - ((GridData) fSpaceBeforeEmptyCloseTag.getLayoutData()).horizontalSpan = 2; - - fIndentUsingTabs = createRadioButton(formattingGroup, XMLUIMessages.Indent_using_tabs); - ((GridData) fIndentUsingTabs.getLayoutData()).horizontalSpan = 2; - - fIndentUsingSpaces = createRadioButton(formattingGroup, XMLUIMessages.Indent_using_spaces); - ((GridData) fIndentUsingSpaces.getLayoutData()).horizontalSpan = 2; - - createLabel(formattingGroup, XMLUIMessages.Indentation_size); - fIndentationSize = new Spinner(formattingGroup, SWT.READ_ONLY | SWT.BORDER); - GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); - fIndentationSize.setLayoutData(gd); - fIndentationSize.setToolTipText(XMLUIMessages.Indentation_size_tip); - fIndentationSize.setMinimum(MIN_INDENTATION_SIZE); - fIndentationSize.setMaximum(MAX_INDENTATION_SIZE); - fIndentationSize.setIncrement(1); - fIndentationSize.setPageIncrement(4); - fIndentationSize.addModifyListener(this); - } - - protected void createContentsForGrammarConstraintsGroup(Composite parent) { - Group grammarConstraintsGroup = createGroup(parent, 1); - grammarConstraintsGroup.setText(XMLUIMessages.Grammar_Constraints); - grammarConstraintsGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); - - fUseInferredGrammar = createCheckBox(grammarConstraintsGroup, XMLUIMessages.Use_inferred_grammar_in_absence_of); - } - - protected IPreferenceStore doGetPreferenceStore() { - return XMLUIPlugin.getDefault().getPreferenceStore(); - } - - protected void doSavePreferenceStore() { - XMLUIPlugin.getDefault().savePluginPreferences(); // editor - XMLCorePlugin.getDefault().savePluginPreferences(); // model - } - - protected void enableValues() { - if (fAutoPropose != null) { - if (fAutoPropose.getSelection()) { - fAutoProposeLabel.setEnabled(true); - fAutoProposeText.setEnabled(true); - } - else { - fAutoProposeLabel.setEnabled(false); - fAutoProposeText.setEnabled(false); - } - } - } - - protected Preferences getModelPreferences() { - return XMLCorePlugin.getDefault().getPluginPreferences(); - } - - /** - * Return the currently selected suggestion strategy preference - * - * @return a suggestion strategy constant from XMLUIPreferenceNames - */ - private String getCurrentSuggestionStrategy() { - int i = fSuggestionStrategyCombo.getSelectionIndex(); - if (i >= 0) { - return (String) (fSuggestionStrategies.elementAt(i)); - } - return ""; //$NON-NLS-1$ - } - - protected void initializeValues() { - initializeValuesForFormattingGroup(); - initializeValuesForContentAssistGroup(); - initializeValuesForGrammarConstraintsGroup(); - } - - protected void initializeValuesForContentAssistGroup() { - // Content Assist - fAutoPropose.setSelection(getPreferenceStore().getBoolean(XMLUIPreferenceNames.AUTO_PROPOSE)); - fAutoProposeText.setText(getPreferenceStore().getString(XMLUIPreferenceNames.AUTO_PROPOSE_CODE)); - String suggestionStrategy = getPreferenceStore().getString(XMLUIPreferenceNames.SUGGESTION_STRATEGY); - if (suggestionStrategy.length() > 0) { - setCurrentSuggestionStrategy(suggestionStrategy); - } - else { - setCurrentSuggestionStrategy(XMLUIPreferenceNames.SUGGESTION_STRATEGY_VALUE_LAX); - } - } - - protected void initializeValuesForFormattingGroup() { - // Formatting - fLineWidthText.setText(getModelPreferences().getString(XMLCorePreferenceNames.LINE_WIDTH)); - fSplitMultiAttrs.setSelection(getModelPreferences().getBoolean(XMLCorePreferenceNames.SPLIT_MULTI_ATTRS)); - fAlignEndBracket.setSelection(getModelPreferences().getBoolean(XMLCorePreferenceNames.ALIGN_END_BRACKET)); - fClearAllBlankLines.setSelection(getModelPreferences().getBoolean(XMLCorePreferenceNames.CLEAR_ALL_BLANK_LINES)); - fPreservePCDATAContent.setSelection(getModelPreferences().getBoolean(XMLCorePreferenceNames.PRESERVE_CDATACONTENT)); - fSpaceBeforeEmptyCloseTag.setSelection(getModelPreferences().getBoolean(XMLCorePreferenceNames.SPACE_BEFORE_EMPTY_CLOSE_TAG)); - - if (XMLCorePreferenceNames.TAB.equals(getModelPreferences().getString(XMLCorePreferenceNames.INDENTATION_CHAR))) { - fIndentUsingTabs.setSelection(true); - fIndentUsingSpaces.setSelection(false); - } - else { - fIndentUsingSpaces.setSelection(true); - fIndentUsingTabs.setSelection(false); - } - - fIndentationSize.setSelection(getModelPreferences().getInt(XMLCorePreferenceNames.INDENTATION_SIZE)); - } - - protected void initializeValuesForGrammarConstraintsGroup() { - fUseInferredGrammar.setSelection(getPreferenceStore().getBoolean(XMLUIPreferenceNames.USE_INFERRED_GRAMMAR)); - } - - protected void performDefaults() { - performDefaultsForFormattingGroup(); - performDefaultsForContentAssistGroup(); - performDefaultsForGrammarConstraintsGroup(); - - validateValues(); - enableValues(); - - super.performDefaults(); - } - - protected void performDefaultsForContentAssistGroup() { - // Content Assist - fAutoPropose.setSelection(getPreferenceStore().getDefaultBoolean(XMLUIPreferenceNames.AUTO_PROPOSE)); - fAutoProposeText.setText(getPreferenceStore().getDefaultString(XMLUIPreferenceNames.AUTO_PROPOSE_CODE)); - String suggestionStrategy = getPreferenceStore().getDefaultString(XMLUIPreferenceNames.SUGGESTION_STRATEGY); - if (suggestionStrategy.length() > 0) { - setCurrentSuggestionStrategy(suggestionStrategy); - } - else { - setCurrentSuggestionStrategy(XMLUIPreferenceNames.SUGGESTION_STRATEGY_VALUE_LAX); - } - } - - protected void performDefaultsForFormattingGroup() { - // Formatting - fLineWidthText.setText(getModelPreferences().getDefaultString(XMLCorePreferenceNames.LINE_WIDTH)); - fSplitMultiAttrs.setSelection(getModelPreferences().getDefaultBoolean(XMLCorePreferenceNames.SPLIT_MULTI_ATTRS)); - fAlignEndBracket.setSelection(getModelPreferences().getDefaultBoolean(XMLCorePreferenceNames.ALIGN_END_BRACKET)); - fClearAllBlankLines.setSelection(getModelPreferences().getDefaultBoolean(XMLCorePreferenceNames.CLEAR_ALL_BLANK_LINES)); - fPreservePCDATAContent.setSelection(getModelPreferences().getDefaultBoolean(XMLCorePreferenceNames.PRESERVE_CDATACONTENT)); - // BUG195264 - Support for removing/adding a space before empty close tags - fSpaceBeforeEmptyCloseTag.setSelection(getModelPreferences().getDefaultBoolean(XMLCorePreferenceNames.SPACE_BEFORE_EMPTY_CLOSE_TAG)); - - if (XMLCorePreferenceNames.TAB.equals(getModelPreferences().getDefaultString(XMLCorePreferenceNames.INDENTATION_CHAR))) { - fIndentUsingTabs.setSelection(true); - fIndentUsingSpaces.setSelection(false); - } - else { - fIndentUsingSpaces.setSelection(true); - fIndentUsingTabs.setSelection(false); - } - fIndentationSize.setSelection(getModelPreferences().getDefaultInt(XMLCorePreferenceNames.INDENTATION_SIZE)); - } - - protected void performDefaultsForGrammarConstraintsGroup() { - fUseInferredGrammar.setSelection(getPreferenceStore().getDefaultBoolean(XMLUIPreferenceNames.USE_INFERRED_GRAMMAR)); - } - - public boolean performOk() { - boolean result = super.performOk(); - - doSavePreferenceStore(); - - return result; - } - - /** - * Set a suggestion strategy in suggestion strategy combo box - * - * @param strategy - */ - private void setCurrentSuggestionStrategy(String strategy) { - // Clear the current selection. - fSuggestionStrategyCombo.clearSelection(); - fSuggestionStrategyCombo.deselectAll(); - - int i = fSuggestionStrategies.indexOf(strategy); - if (i >= 0) { - fSuggestionStrategyCombo.select(i); - } - } - - protected void storeValues() { - storeValuesForFormattingGroup(); - storeValuesForContentAssistGroup(); - storeValuesForGrammarConstraintsGroup(); - } - - protected void storeValuesForContentAssistGroup() { - // Content Assist - getPreferenceStore().setValue(XMLUIPreferenceNames.AUTO_PROPOSE, fAutoPropose.getSelection()); - getPreferenceStore().setValue(XMLUIPreferenceNames.AUTO_PROPOSE_CODE, fAutoProposeText.getText()); - getPreferenceStore().setValue(XMLUIPreferenceNames.SUGGESTION_STRATEGY, getCurrentSuggestionStrategy()); - } - - protected void storeValuesForFormattingGroup() { - // Formatting - getModelPreferences().setValue(XMLCorePreferenceNames.LINE_WIDTH, fLineWidthText.getText()); - getModelPreferences().setValue(XMLCorePreferenceNames.SPLIT_MULTI_ATTRS, fSplitMultiAttrs.getSelection()); - getModelPreferences().setValue(XMLCorePreferenceNames.ALIGN_END_BRACKET, fAlignEndBracket.getSelection()); - getModelPreferences().setValue(XMLCorePreferenceNames.CLEAR_ALL_BLANK_LINES, fClearAllBlankLines.getSelection()); - getModelPreferences().setValue(XMLCorePreferenceNames.PRESERVE_CDATACONTENT, fPreservePCDATAContent.getSelection()); - // BUG195264 - Support for removing/adding a space before empty close tags - getModelPreferences().setValue(XMLCorePreferenceNames.SPACE_BEFORE_EMPTY_CLOSE_TAG, fSpaceBeforeEmptyCloseTag.getSelection()); - - if (fIndentUsingTabs.getSelection()) { - getModelPreferences().setValue(XMLCorePreferenceNames.INDENTATION_CHAR, XMLCorePreferenceNames.TAB); - } - else { - getModelPreferences().setValue(XMLCorePreferenceNames.INDENTATION_CHAR, XMLCorePreferenceNames.SPACE); - } - getModelPreferences().setValue(XMLCorePreferenceNames.INDENTATION_SIZE, fIndentationSize.getSelection()); - } - - protected void storeValuesForGrammarConstraintsGroup() { - getPreferenceStore().setValue(XMLUIPreferenceNames.USE_INFERRED_GRAMMAR, fUseInferredGrammar.getSelection()); - } - - protected void validateValues() { - boolean isError = false; - String widthText = null; - - if (fLineWidthText != null) { - try { - widthText = fLineWidthText.getText(); - int formattingLineWidth = Integer.parseInt(widthText); - if ((formattingLineWidth < WIDTH_VALIDATION_LOWER_LIMIT) || (formattingLineWidth > WIDTH_VALIDATION_UPPER_LIMIT)) { - throw new NumberFormatException(); - } - } - catch (NumberFormatException nfexc) { - setInvalidInputMessage(widthText); - setValid(false); - isError = true; - } - } - - int indentSize = 0; - if (fIndentationSize != null) { - try { - indentSize = fIndentationSize.getSelection(); - if ((indentSize < MIN_INDENTATION_SIZE) || (indentSize > MAX_INDENTATION_SIZE)) { - throw new NumberFormatException(); - } - } - catch (NumberFormatException nfexc) { - setInvalidInputMessage(Integer.toString(indentSize)); - setValid(false); - isError = true; - } - } - - if (!isError) { - setErrorMessage(null); - setValid(true); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLSyntaxColoringPage.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLSyntaxColoringPage.java deleted file mode 100644 index 644fef27db..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLSyntaxColoringPage.java +++ /dev/null @@ -1,870 +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.wst.xml.ui.internal.preferences; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.jface.preference.ColorSelector; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.preference.PreferencePage; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.jface.text.TextAttribute; -import org.eclipse.jface.text.source.SourceViewer; -import org.eclipse.jface.util.IPropertyChangeListener; -import org.eclipse.jface.util.PropertyChangeEvent; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.ListViewer; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.StructuredViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerComparator; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.ACC; -import org.eclipse.swt.accessibility.AccessibleAdapter; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.custom.SashForm; -import org.eclipse.swt.custom.StyleRange; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.events.KeyEvent; -import org.eclipse.swt.events.KeyListener; -import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.events.MouseListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.events.TraverseEvent; -import org.eclipse.swt.events.TraverseListener; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.RGB; -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.Label; -import org.eclipse.swt.widgets.Link; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPreferencePage; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.PreferencesUtil; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList; -import org.eclipse.wst.sse.ui.internal.SSEUIMessages; -import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; -import org.eclipse.wst.sse.ui.internal.preferences.OverlayPreferenceStore; -import org.eclipse.wst.sse.ui.internal.preferences.OverlayPreferenceStore.OverlayKey; -import org.eclipse.wst.sse.ui.internal.preferences.ui.ColorHelper; -import org.eclipse.wst.sse.ui.internal.util.EditorUtility; -import org.eclipse.wst.xml.core.internal.provisional.contenttype.ContentTypeIdForXML; -import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.internal.editor.IHelpContextIds; -import org.eclipse.wst.xml.ui.internal.style.IStyleConstantsXML; - -import com.ibm.icu.text.Collator; - -/** - * A preference page to configure our XML syntax color. It resembles the JDT - * and CDT pages far more than our original color page while retaining the - * extra "click-to-find" functionality. - */ -public final class XMLSyntaxColoringPage extends PreferencePage implements IWorkbenchPreferencePage { - - private Button fBold; - private Label fForegroundLabel; - private Label fBackgroundLabel; - private Button fClearStyle; - private Map fContextToStyleMap; - private Color fDefaultForeground = null; - private Color fDefaultBackground = null; - private IStructuredDocument fDocument; - private ColorSelector fForegroundColorEditor; - private ColorSelector fBackgroundColorEditor; - private Button fItalic; - private OverlayPreferenceStore fOverlayStore; - private Button fStrike; - private Collection fStylePreferenceKeys; - private StructuredViewer fStylesViewer = null; - private Map fStyleToDescriptionMap; - private StyledText fText; - private Button fUnderline; - - // activate controls based on the given local color type - private void activate(String namedStyle) { - Color foreground = fDefaultForeground; - Color background = fDefaultBackground; - if (namedStyle == null) { - fClearStyle.setEnabled(false); - fBold.setEnabled(false); - fItalic.setEnabled(false); - fStrike.setEnabled(false); - fUnderline.setEnabled(false); - fForegroundLabel.setEnabled(false); - fBackgroundLabel.setEnabled(false); - fForegroundColorEditor.setEnabled(false); - fBackgroundColorEditor.setEnabled(false); - fBold.setSelection(false); - fItalic.setSelection(false); - fStrike.setSelection(false); - fUnderline.setSelection(false); - } - else { - TextAttribute attribute = getAttributeFor(namedStyle); - fClearStyle.setEnabled(true); - fBold.setEnabled(true); - fItalic.setEnabled(true); - fStrike.setEnabled(true); - fUnderline.setEnabled(true); - fForegroundLabel.setEnabled(true); - fBackgroundLabel.setEnabled(true); - fForegroundColorEditor.setEnabled(true); - fBackgroundColorEditor.setEnabled(true); - fBold.setSelection((attribute.getStyle() & SWT.BOLD) != 0); - fItalic.setSelection((attribute.getStyle() & SWT.ITALIC) != 0); - fStrike.setSelection((attribute.getStyle() & TextAttribute.STRIKETHROUGH) != 0); - fUnderline.setSelection((attribute.getStyle() & TextAttribute.UNDERLINE) != 0); - if (attribute.getForeground() != null) { - foreground = attribute.getForeground(); - } - if (attribute.getBackground() != null) { - background = attribute.getBackground(); - } - } - - fForegroundColorEditor.setColorValue(foreground.getRGB()); - fBackgroundColorEditor.setColorValue(background.getRGB()); - } - - /** - * Color the text in the sample area according to the current preferences - */ - void applyStyles() { - if (fText == null || fText.isDisposed()) - return; - IStructuredDocumentRegion documentRegion = fDocument.getFirstStructuredDocumentRegion(); - while (documentRegion != null) { - ITextRegionList regions = documentRegion.getRegions(); - for (int i = 0; i < regions.size(); i++) { - ITextRegion currentRegion = regions.get(i); - // lookup the local coloring type and apply it - String namedStyle = (String) fContextToStyleMap.get(currentRegion.getType()); - if (namedStyle == null) - continue; - TextAttribute attribute = getAttributeFor(namedStyle); - if (attribute == null) - continue; - StyleRange style = new StyleRange(documentRegion.getStartOffset(currentRegion), currentRegion.getTextLength(), attribute.getForeground(), attribute.getBackground(), attribute.getStyle()); - style.strikeout = (attribute.getStyle() & TextAttribute.STRIKETHROUGH) != 0; - style.underline = (attribute.getStyle() & TextAttribute.UNDERLINE) != 0; - fText.setStyleRange(style); - } - documentRegion = documentRegion.getNext(); - } - } - - Button createCheckbox(Composite parent, String label) { - Button button = new Button(parent, SWT.CHECK); - button.setText(label); - button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); - return button; - } - - /** - * Creates composite control and sets the default layout data. - */ - private Composite createComposite(Composite parent, int numColumns) { - Composite composite = new Composite(parent, SWT.NULL); - - // GridLayout - GridLayout layout = new GridLayout(); - layout.numColumns = numColumns; - layout.makeColumnsEqualWidth = false; - layout.marginHeight = 0; - layout.marginWidth = 0; - composite.setLayout(layout); - - // GridData - GridData data = new GridData(SWT.FILL, SWT.FILL, true, false); - composite.setLayoutData(data); - return composite; - } - - protected Control createContents(final Composite parent) { - initializeDialogUnits(parent); - - fDefaultForeground = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND); - fDefaultBackground = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND); - Composite pageComponent = createComposite(parent, 2); - PlatformUI.getWorkbench().getHelpSystem().setHelp(pageComponent, IHelpContextIds.XML_PREFWEBX_STYLES_HELPID); - - Link link = new Link(pageComponent, SWT.WRAP); - link.setText(SSEUIMessages.SyntaxColoring_Link); - link.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - PreferencesUtil.createPreferenceDialogOn(parent.getShell(), e.text, null, null); - } - }); - - GridData linkData= new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1); - linkData.widthHint= 150; // only expand further if anyone else requires it - link.setLayoutData(linkData); - - new Label(pageComponent, SWT.NONE).setLayoutData(new GridData()); - new Label(pageComponent, SWT.NONE).setLayoutData(new GridData()); - - SashForm editor = new SashForm(pageComponent, SWT.VERTICAL); - GridData gridData2 = new GridData(SWT.FILL, SWT.FILL, true, true); - gridData2.horizontalSpan = 2; - editor.setLayoutData(gridData2); - SashForm top = new SashForm(editor, SWT.HORIZONTAL); - Composite styleEditor = createComposite(top, 1); - ((GridLayout) styleEditor.getLayout()).marginRight = 5; - ((GridLayout) styleEditor.getLayout()).marginLeft = 0; - createLabel(styleEditor, XMLUIMessages.SyntaxColoringPage_0); - fStylesViewer = createStylesViewer(styleEditor); - GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); - gridData.horizontalIndent = 0; - Iterator iterator = fStyleToDescriptionMap.values().iterator(); - while (iterator.hasNext()) { - gridData.widthHint = Math.max(gridData.widthHint, convertWidthInCharsToPixels(iterator.next().toString().length())); - } - gridData.heightHint = convertHeightInCharsToPixels(5); - fStylesViewer.getControl().setLayoutData(gridData); - - Composite editingComposite = createComposite(top, 1); - ((GridLayout) styleEditor.getLayout()).marginLeft = 5; - createLabel(editingComposite, ""); //$NON-NLS-1$ - Button enabler = createCheckbox(editingComposite, XMLUIMessages.SyntaxColoringPage_2); - enabler.setEnabled(false); - enabler.setSelection(true); - Composite editControls = createComposite(editingComposite, 2); - ((GridLayout) editControls.getLayout()).marginLeft = 20; - - fForegroundLabel = createLabel(editControls, SSEUIMessages.Foreground_UI_); - ((GridData) fForegroundLabel.getLayoutData()).verticalAlignment = SWT.CENTER; - fForegroundLabel.setEnabled(false); - - fForegroundColorEditor = new ColorSelector(editControls); - Button fForegroundColor = fForegroundColorEditor.getButton(); - GridData gd = new GridData(SWT.BEGINNING, SWT.FILL, false, false); - fForegroundColor.setLayoutData(gd); - fForegroundColorEditor.setEnabled(false); - - fBackgroundLabel = createLabel(editControls, SSEUIMessages.Background_UI_); - ((GridData) fBackgroundLabel.getLayoutData()).verticalAlignment = SWT.CENTER; - fBackgroundLabel.setEnabled(false); - - fBackgroundColorEditor = new ColorSelector(editControls); - Button fBackgroundColor = fBackgroundColorEditor.getButton(); - gd = new GridData(SWT.BEGINNING, SWT.FILL, false, false); - fBackgroundColor.setLayoutData(gd); - fBackgroundColorEditor.setEnabled(false); - - fBold = createCheckbox(editControls, XMLUIMessages.SyntaxColoringPage_3); - fBold.setEnabled(false); - ((GridData) fBold.getLayoutData()).horizontalSpan = 2; - fItalic = createCheckbox(editControls, XMLUIMessages.SyntaxColoringPage_4); - fItalic.setEnabled(false); - ((GridData) fItalic.getLayoutData()).horizontalSpan = 2; - fStrike = createCheckbox(editControls, XMLUIMessages.SyntaxColoringPage_5); - fStrike.setEnabled(false); - ((GridData) fStrike.getLayoutData()).horizontalSpan = 2; - fUnderline = createCheckbox(editControls, XMLUIMessages.SyntaxColoringPage_6); - fUnderline.setEnabled(false); - ((GridData) fUnderline.getLayoutData()).horizontalSpan = 2; - fClearStyle = new Button(editingComposite, SWT.PUSH); - fClearStyle.setText(SSEUIMessages.Restore_Default_UI_); //$NON-NLS-1$ = "Restore Default" - fClearStyle.setLayoutData(new GridData(SWT.BEGINNING)); - ((GridData) fClearStyle.getLayoutData()).horizontalIndent = 20; - fClearStyle.setEnabled(false); - - Composite sampleArea = createComposite(editor, 1); - - ((GridLayout) sampleArea.getLayout()).marginLeft = 5; - ((GridLayout) sampleArea.getLayout()).marginTop = 5; - createLabel(sampleArea, SSEUIMessages.Sample_text__UI_); //$NON-NLS-1$ = "&Sample text:" - SourceViewer viewer = new SourceViewer(sampleArea, null, SWT.BORDER | SWT.LEFT_TO_RIGHT | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.READ_ONLY); - fText = viewer.getTextWidget(); - GridData gridData3 = new GridData(SWT.FILL, SWT.FILL, true, true); - gridData3.widthHint = convertWidthInCharsToPixels(20); - gridData3.heightHint = convertHeightInCharsToPixels(5); - gridData3.horizontalSpan = 2; - fText.setLayoutData(gridData3); - fText.setEditable(false); - fText.setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont")); //$NON-NLS-1$ - fText.addKeyListener(getTextKeyListener()); - fText.addSelectionListener(getTextSelectionListener()); - fText.addMouseListener(getTextMouseListener()); - fText.addTraverseListener(getTraverseListener()); - setAccessible(fText, SSEUIMessages.Sample_text__UI_); - fDocument = StructuredModelManager.getModelManager().createStructuredDocumentFor(ContentTypeIdForXML.ContentTypeID_XML); - fDocument.set(getExampleText()); - viewer.setDocument(fDocument); - - top.setWeights(new int[]{1, 1}); - editor.setWeights(new int[]{1, 1}); - PlatformUI.getWorkbench().getHelpSystem().setHelp(pageComponent, IHelpContextIds.XML_PREFWEBX_STYLES_HELPID); - - fStylesViewer.setInput(getStylePreferenceKeys()); - - applyStyles(); - - fStylesViewer.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - if (!event.getSelection().isEmpty()) { - Object o = ((IStructuredSelection) event.getSelection()).getFirstElement(); - String namedStyle = o.toString(); - activate(namedStyle); - if (namedStyle == null) - return; - } - } - }); - - fForegroundColorEditor.addListener(new IPropertyChangeListener() { - public void propertyChange(PropertyChangeEvent event) { - if (event.getProperty().equals(ColorSelector.PROP_COLORCHANGE)) { - Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement(); - String namedStyle = o.toString(); - String prefString = getOverlayStore().getString(namedStyle); - String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString); - if (stylePrefs != null) { - String oldValue = stylePrefs[0]; - // open color dialog to get new color - String newValue = ColorHelper.toRGBString(fForegroundColorEditor.getColorValue()); - - if (!newValue.equals(oldValue)) { - stylePrefs[0] = newValue; - String newPrefString = ColorHelper.packStylePreferences(stylePrefs); - getOverlayStore().setValue(namedStyle, newPrefString); - applyStyles(); - fText.redraw(); - } - } - } - } - }); - - fBackgroundColorEditor.addListener(new IPropertyChangeListener() { - public void propertyChange(PropertyChangeEvent event) { - if (event.getProperty().equals(ColorSelector.PROP_COLORCHANGE)) { - Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement(); - String namedStyle = o.toString(); - String prefString = getOverlayStore().getString(namedStyle); - String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString); - if (stylePrefs != null) { - String oldValue = stylePrefs[1]; - // open color dialog to get new color - String newValue = ColorHelper.toRGBString(fBackgroundColorEditor.getColorValue()); - - if (!newValue.equals(oldValue)) { - stylePrefs[1] = newValue; - String newPrefString = ColorHelper.packStylePreferences(stylePrefs); - getOverlayStore().setValue(namedStyle, newPrefString); - applyStyles(); - fText.redraw(); - activate(namedStyle); - } - } - } - } - }); - - fBold.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - super.widgetSelected(e); - // get current (newly old) style - Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement(); - String namedStyle = o.toString(); - String prefString = getOverlayStore().getString(namedStyle); - String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString); - if (stylePrefs != null) { - String oldValue = stylePrefs[2]; - String newValue = String.valueOf(fBold.getSelection()); - if (!newValue.equals(oldValue)) { - stylePrefs[2] = newValue; - String newPrefString = ColorHelper.packStylePreferences(stylePrefs); - getOverlayStore().setValue(namedStyle, newPrefString); - applyStyles(); - fText.redraw(); - } - } - } - }); - - fItalic.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - super.widgetSelected(e); - // get current (newly old) style - Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement(); - String namedStyle = o.toString(); - String prefString = getOverlayStore().getString(namedStyle); - String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString); - if (stylePrefs != null) { - String oldValue = stylePrefs[3]; - String newValue = String.valueOf(fItalic.getSelection()); - if (!newValue.equals(oldValue)) { - stylePrefs[3] = newValue; - String newPrefString = ColorHelper.packStylePreferences(stylePrefs); - getOverlayStore().setValue(namedStyle, newPrefString); - applyStyles(); - fText.redraw(); - } - } - } - }); - - fStrike.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - super.widgetSelected(e); - // get current (newly old) style - Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement(); - String namedStyle = o.toString(); - String prefString = getOverlayStore().getString(namedStyle); - String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString); - if (stylePrefs != null) { - String oldValue = stylePrefs[4]; - String newValue = String.valueOf(fStrike.getSelection()); - if (!newValue.equals(oldValue)) { - stylePrefs[4] = newValue; - String newPrefString = ColorHelper.packStylePreferences(stylePrefs); - getOverlayStore().setValue(namedStyle, newPrefString); - applyStyles(); - fText.redraw(); - } - } - } - }); - - fUnderline.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - super.widgetSelected(e); - // get current (newly old) style - Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement(); - String namedStyle = o.toString(); - String prefString = getOverlayStore().getString(namedStyle); - String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString); - if (stylePrefs != null) { - String oldValue = stylePrefs[5]; - String newValue = String.valueOf(fUnderline.getSelection()); - if (!newValue.equals(oldValue)) { - stylePrefs[5] = newValue; - String newPrefString = ColorHelper.packStylePreferences(stylePrefs); - getOverlayStore().setValue(namedStyle, newPrefString); - applyStyles(); - fText.redraw(); - } - } - } - }); - - fClearStyle.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - if (fStylesViewer.getSelection().isEmpty()) - return; - String namedStyle = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement().toString(); - getOverlayStore().setToDefault(namedStyle); - applyStyles(); - fText.redraw(); - activate(namedStyle); - } - }); - - return pageComponent; - } - - private Label createLabel(Composite parent, String text) { - Label label = new Label(parent, SWT.WRAP); - label.setText(text); - GridData data = new GridData(SWT.FILL, SWT.FILL, false, false); - label.setLayoutData(data); - label.setBackground(parent.getBackground()); - return label; - } - - // protected Label createDescriptionLabel(Composite parent) { - // return null; - // } - - /** - * Set up all the style preference keys in the overlay store - */ - private OverlayKey[] createOverlayStoreKeys() { - List overlayKeys = new ArrayList(); - - Iterator i = getStylePreferenceKeys().iterator(); - while (i.hasNext()) { - overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, (String) i.next())); - } - - OverlayPreferenceStore.OverlayKey[] keys = new OverlayPreferenceStore.OverlayKey[overlayKeys.size()]; - overlayKeys.toArray(keys); - return keys; - } - - /** - * Creates the List viewer where we see the various syntax element display - * names--would it ever be a Tree like JDT's? - * - * @param parent - * @return - */ - private StructuredViewer createStylesViewer(Composite parent) { - StructuredViewer stylesViewer = new ListViewer(parent, SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER); - stylesViewer.setComparator(new ViewerComparator(Collator.getInstance())); - stylesViewer.setLabelProvider(new LabelProvider() { - public String getText(Object element) { - Object description = fStyleToDescriptionMap.get(element); - if (description != null) - return description.toString(); - return super.getText(element); - } - }); - stylesViewer.setContentProvider(new ITreeContentProvider() { - public void dispose() { - } - - public Object[] getChildren(Object parentElement) { - return getStylePreferenceKeys().toArray(); - } - - public Object[] getElements(Object inputElement) { - return getChildren(inputElement); - } - - public Object getParent(Object element) { - return getStylePreferenceKeys(); - } - - public boolean hasChildren(Object element) { - return false; - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - }); - return stylesViewer; - } - - public void dispose() { - if (fOverlayStore != null) { - fOverlayStore.stop(); - } - super.dispose(); - } - - protected IPreferenceStore doGetPreferenceStore() { - return XMLUIPlugin.getDefault().getPreferenceStore(); - } - - private TextAttribute getAttributeFor(String namedStyle) { - TextAttribute ta = new TextAttribute(fDefaultForeground, fDefaultBackground, SWT.NORMAL); - - if (namedStyle != null && fOverlayStore != null) { - // note: "namedStyle" *is* the preference key - String prefString = getOverlayStore().getString(namedStyle); - String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString); - if (stylePrefs != null) { - RGB foreground = ColorHelper.toRGB(stylePrefs[0]); - RGB background = ColorHelper.toRGB(stylePrefs[1]); - - int fontModifier = SWT.NORMAL; - - if (stylePrefs.length > 2) { - boolean on = Boolean.valueOf(stylePrefs[2]).booleanValue(); - if (on) - fontModifier = fontModifier | SWT.BOLD; - } - if (stylePrefs.length > 3) { - boolean on = Boolean.valueOf(stylePrefs[3]).booleanValue(); - if (on) - fontModifier = fontModifier | SWT.ITALIC; - } - if (stylePrefs.length > 4) { - boolean on = Boolean.valueOf(stylePrefs[4]).booleanValue(); - if (on) - fontModifier = fontModifier | TextAttribute.STRIKETHROUGH; - } - if (stylePrefs.length > 5) { - boolean on = Boolean.valueOf(stylePrefs[5]).booleanValue(); - if (on) - fontModifier = fontModifier | TextAttribute.UNDERLINE; - } - - ta = new TextAttribute((foreground != null) ? EditorUtility.getColor(foreground) : null, (background != null) ? EditorUtility.getColor(background) : null, fontModifier); - } - } - return ta; - } - - private String getExampleText() { - return XMLUIMessages.Sample_XML_doc; - } - - private String getNamedStyleAtOffset(int offset) { - // ensure the offset is clean - if (offset >= fDocument.getLength()) - return getNamedStyleAtOffset(fDocument.getLength() - 1); - else if (offset < 0) - return getNamedStyleAtOffset(0); - IStructuredDocumentRegion documentRegion = fDocument.getFirstStructuredDocumentRegion(); - while (documentRegion != null && !documentRegion.containsOffset(offset)) { - documentRegion = documentRegion.getNext(); - } - if (documentRegion != null) { - // find the ITextRegion's Context at this offset - ITextRegion interest = documentRegion.getRegionAtCharacterOffset(offset); - if (interest == null) - return null; - if (offset > documentRegion.getTextEndOffset(interest)) - return null; - String regionContext = interest.getType(); - if (regionContext == null) - return null; - // find the named style (internal/selectable name) for that - // context - String namedStyle = (String) fContextToStyleMap.get(regionContext); - if (namedStyle != null) { - return namedStyle; - } - } - return null; - } - - private OverlayPreferenceStore getOverlayStore() { - return fOverlayStore; - } - - private Collection getStylePreferenceKeys() { - if (fStylePreferenceKeys == null) { - List styles = new ArrayList(); - styles.add(IStyleConstantsXML.DOCTYPE_NAME); - styles.add(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID); - styles.add(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_PUBREF); - styles.add(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_SYSREF); - styles.add(IStyleConstantsXML.CDATA_BORDER); - styles.add(IStyleConstantsXML.CDATA_TEXT); - styles.add(IStyleConstantsXML.PI_BORDER); - styles.add(IStyleConstantsXML.PI_CONTENT); - styles.add(IStyleConstantsXML.TAG_BORDER); - styles.add(IStyleConstantsXML.TAG_NAME); - styles.add(IStyleConstantsXML.TAG_ATTRIBUTE_NAME); - styles.add(IStyleConstantsXML.TAG_ATTRIBUTE_VALUE); - styles.add(IStyleConstantsXML.COMMENT_BORDER); - styles.add(IStyleConstantsXML.COMMENT_TEXT); - styles.add(IStyleConstantsXML.DECL_BORDER); - styles.add(IStyleConstantsXML.XML_CONTENT); - styles.add(IStyleConstantsXML.ENTITY_REFERENCE); - fStylePreferenceKeys = styles; - } - return fStylePreferenceKeys; - } - - private KeyListener getTextKeyListener() { - return new KeyListener() { - public void keyPressed(KeyEvent e) { - if (e.widget instanceof StyledText) { - int x = ((StyledText) e.widget).getCaretOffset(); - selectColorAtOffset(x); - } - } - - public void keyReleased(KeyEvent e) { - if (e.widget instanceof StyledText) { - int x = ((StyledText) e.widget).getCaretOffset(); - selectColorAtOffset(x); - } - } - }; - } - - private MouseListener getTextMouseListener() { - return new MouseListener() { - public void mouseDoubleClick(MouseEvent e) { - } - - public void mouseDown(MouseEvent e) { - } - - public void mouseUp(MouseEvent e) { - if (e.widget instanceof StyledText) { - int x = ((StyledText) e.widget).getCaretOffset(); - selectColorAtOffset(x); - } - } - }; - } - - private SelectionListener getTextSelectionListener() { - return new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - selectColorAtOffset(e.x); - if (e.widget instanceof StyledText) { - ((StyledText) e.widget).setSelection(e.x); - } - } - - public void widgetSelected(SelectionEvent e) { - selectColorAtOffset(e.x); - if (e.widget instanceof StyledText) { - ((StyledText) e.widget).setSelection(e.x); - } - } - }; - } - - private TraverseListener getTraverseListener() { - return new TraverseListener() { - /** - * @see org.eclipse.swt.events.TraverseListener#keyTraversed(TraverseEvent) - */ - public void keyTraversed(TraverseEvent e) { - if (e.widget instanceof StyledText) { - if ((e.detail == SWT.TRAVERSE_TAB_NEXT) || (e.detail == SWT.TRAVERSE_TAB_PREVIOUS)) - e.doit = true; - } - } - }; - } - - public void init(IWorkbench workbench) { - setDescription(SSEUIMessages.SyntaxColoring_Description); - - fStyleToDescriptionMap = new HashMap(); - fContextToStyleMap = new HashMap(); - - initStyleToDescriptionMap(); - initRegionContextToStyleMap(); - - fOverlayStore = new OverlayPreferenceStore(getPreferenceStore(), createOverlayStoreKeys()); - fOverlayStore.load(); - fOverlayStore.start(); - } - - private void initRegionContextToStyleMap() { - fContextToStyleMap.put(DOMRegionContext.XML_COMMENT_OPEN, IStyleConstantsXML.COMMENT_BORDER); - fContextToStyleMap.put(DOMRegionContext.XML_COMMENT_TEXT, IStyleConstantsXML.COMMENT_TEXT); - fContextToStyleMap.put(DOMRegionContext.XML_COMMENT_CLOSE, IStyleConstantsXML.COMMENT_BORDER); - - fContextToStyleMap.put(DOMRegionContext.XML_TAG_OPEN, IStyleConstantsXML.TAG_BORDER); - fContextToStyleMap.put(DOMRegionContext.XML_END_TAG_OPEN, IStyleConstantsXML.TAG_BORDER); - fContextToStyleMap.put(DOMRegionContext.XML_TAG_NAME, IStyleConstantsXML.TAG_NAME); - fContextToStyleMap.put(DOMRegionContext.XML_TAG_ATTRIBUTE_NAME, IStyleConstantsXML.TAG_ATTRIBUTE_NAME); - fContextToStyleMap.put(DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE, IStyleConstantsXML.TAG_ATTRIBUTE_VALUE); - fContextToStyleMap.put(DOMRegionContext.XML_TAG_CLOSE, IStyleConstantsXML.TAG_BORDER); - fContextToStyleMap.put(DOMRegionContext.XML_EMPTY_TAG_CLOSE, IStyleConstantsXML.TAG_BORDER); - - fContextToStyleMap.put(DOMRegionContext.XML_DECLARATION_OPEN, IStyleConstantsXML.DECL_BORDER); - fContextToStyleMap.put(DOMRegionContext.XML_DECLARATION_CLOSE, IStyleConstantsXML.DECL_BORDER); - fContextToStyleMap.put(DOMRegionContext.XML_ELEMENT_DECLARATION, IStyleConstantsXML.DECL_BORDER); - fContextToStyleMap.put(DOMRegionContext.XML_ELEMENT_DECL_CLOSE, IStyleConstantsXML.DECL_BORDER); - - fContextToStyleMap.put(DOMRegionContext.XML_CONTENT, IStyleConstantsXML.XML_CONTENT); - fContextToStyleMap.put(DOMRegionContext.XML_CDATA_OPEN, IStyleConstantsXML.CDATA_BORDER); - fContextToStyleMap.put(DOMRegionContext.XML_CDATA_TEXT, IStyleConstantsXML.CDATA_TEXT); - fContextToStyleMap.put(DOMRegionContext.XML_CDATA_CLOSE, IStyleConstantsXML.CDATA_BORDER); - - fContextToStyleMap.put(DOMRegionContext.XML_PI_OPEN, IStyleConstantsXML.PI_BORDER); - fContextToStyleMap.put(DOMRegionContext.XML_PI_CONTENT, IStyleConstantsXML.PI_CONTENT); - fContextToStyleMap.put(DOMRegionContext.XML_PI_CLOSE, IStyleConstantsXML.PI_BORDER); - fContextToStyleMap.put(DOMRegionContext.XML_ELEMENT_DECL_NAME, IStyleConstantsXML.DOCTYPE_NAME); - fContextToStyleMap.put(DOMRegionContext.XML_DOCTYPE_DECLARATION, IStyleConstantsXML.TAG_NAME); - fContextToStyleMap.put(DOMRegionContext.XML_DOCTYPE_DECLARATION_CLOSE, IStyleConstantsXML.DECL_BORDER); - - fContextToStyleMap.put(DOMRegionContext.XML_DOCTYPE_NAME, IStyleConstantsXML.DOCTYPE_NAME); - fContextToStyleMap.put(DOMRegionContext.XML_DOCTYPE_EXTERNAL_ID_PUBLIC, IStyleConstantsXML.DOCTYPE_EXTERNAL_ID); - fContextToStyleMap.put(DOMRegionContext.XML_DOCTYPE_EXTERNAL_ID_PUBREF, IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_PUBREF); - fContextToStyleMap.put(DOMRegionContext.XML_DOCTYPE_EXTERNAL_ID_SYSTEM, IStyleConstantsXML.DOCTYPE_EXTERNAL_ID); - fContextToStyleMap.put(DOMRegionContext.XML_DOCTYPE_EXTERNAL_ID_SYSREF, IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_SYSREF); - - fContextToStyleMap.put(DOMRegionContext.XML_CHAR_REFERENCE, IStyleConstantsXML.ENTITY_REFERENCE); - fContextToStyleMap.put(DOMRegionContext.XML_ENTITY_REFERENCE, IStyleConstantsXML.ENTITY_REFERENCE); - fContextToStyleMap.put(DOMRegionContext.XML_PE_REFERENCE, IStyleConstantsXML.ENTITY_REFERENCE); - } - - private void initStyleToDescriptionMap() { - fStyleToDescriptionMap.put(IStyleConstantsXML.CDATA_BORDER, XMLUIMessages.CDATA_Delimiters_UI_); - fStyleToDescriptionMap.put(IStyleConstantsXML.CDATA_TEXT, XMLUIMessages.CDATA_Content_UI_); - fStyleToDescriptionMap.put(IStyleConstantsXML.PI_BORDER, XMLUIMessages.Processing_Instruction_Del_UI_); - fStyleToDescriptionMap.put(IStyleConstantsXML.PI_CONTENT, XMLUIMessages.Processing_Instruction_Con_UI__UI_); - fStyleToDescriptionMap.put(IStyleConstantsXML.COMMENT_BORDER, XMLUIMessages.Comment_Delimiters_UI_); - fStyleToDescriptionMap.put(IStyleConstantsXML.COMMENT_TEXT, XMLUIMessages.Comment_Content_UI_); - fStyleToDescriptionMap.put(IStyleConstantsXML.TAG_BORDER, XMLUIMessages.Tag_Delimiters_UI_); - fStyleToDescriptionMap.put(IStyleConstantsXML.TAG_NAME, XMLUIMessages.Tag_Names_UI_); - fStyleToDescriptionMap.put(IStyleConstantsXML.TAG_ATTRIBUTE_NAME, XMLUIMessages.Attribute_Names_UI_); - fStyleToDescriptionMap.put(IStyleConstantsXML.TAG_ATTRIBUTE_VALUE, XMLUIMessages.Attribute_Values_UI_); - fStyleToDescriptionMap.put(IStyleConstantsXML.DECL_BORDER, XMLUIMessages.Declaration_Delimiters_UI_); - fStyleToDescriptionMap.put(IStyleConstantsXML.XML_CONTENT, XMLUIMessages.Content_UI_); - fStyleToDescriptionMap.put(IStyleConstantsXML.DOCTYPE_NAME, XMLUIMessages.DOCTYPE_Name_UI_); - fStyleToDescriptionMap.put(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID, XMLUIMessages.DOCTYPE_SYSTEM_PUBLIC_Keyw_UI_); - fStyleToDescriptionMap.put(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_PUBREF, XMLUIMessages.DOCTYPE_Public_Reference_UI_); - fStyleToDescriptionMap.put(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_SYSREF, XMLUIMessages.DOCTYPE_System_Reference_UI_); - fStyleToDescriptionMap.put(IStyleConstantsXML.ENTITY_REFERENCE, XMLUIMessages.Entity_Reference_UI_); - } - - protected void performDefaults() { - super.performDefaults(); - getOverlayStore().loadDefaults(); - applyStyles(); - fStylesViewer.setSelection(StructuredSelection.EMPTY); - activate(null); - fText.redraw(); - } - - public boolean performOk() { - getOverlayStore().propagate(); - - XMLUIPlugin.getDefault().savePluginPreferences(); - SSEUIPlugin.getDefault().savePluginPreferences(); - return true; - } - - private void selectColorAtOffset(int offset) { - String namedStyle = getNamedStyleAtOffset(offset); - if (namedStyle != null) { - fStylesViewer.setSelection(new StructuredSelection(namedStyle)); - fStylesViewer.reveal(namedStyle); - } - else { - fStylesViewer.setSelection(StructuredSelection.EMPTY); - } - activate(namedStyle); - } - - /** - * Specifically set the reporting name of a control for accessibility - */ - private void setAccessible(Control control, String name) { - if (control == null) - return; - final String n = name; - control.getAccessible().addAccessibleListener(new AccessibleAdapter() { - public void getName(AccessibleEvent e) { - if (e.childID == ACC.CHILDID_SELF) - e.result = n; - } - }); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLTemplatePreferencePage.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLTemplatePreferencePage.java deleted file mode 100644 index 810b5997e3..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLTemplatePreferencePage.java +++ /dev/null @@ -1,169 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.preferences; - -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.contentassist.ContentAssistant; -import org.eclipse.jface.text.contentassist.IContentAssistant; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.jface.text.source.SourceViewer; -import org.eclipse.jface.text.source.SourceViewerConfiguration; -import org.eclipse.jface.text.templates.ContextTypeRegistry; -import org.eclipse.jface.text.templates.Template; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.texteditor.templates.TemplatePreferencePage; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration; -import org.eclipse.wst.sse.ui.internal.StructuredTextViewer; -import org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider; -import org.eclipse.wst.xml.core.internal.provisional.contenttype.ContentTypeIdForXML; -import org.eclipse.wst.xml.ui.StructuredTextViewerConfigurationXML; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.internal.editor.IHelpContextIds; - - -/** - * Preference page for XML templates - */ -public class XMLTemplatePreferencePage extends TemplatePreferencePage { - - class XMLEditTemplateDialog extends EditTemplateDialog { - public XMLEditTemplateDialog(Shell parent, Template template, boolean edit, boolean isNameModifiable, ContextTypeRegistry registry) { - super(parent, template, edit, isNameModifiable, registry); - } - - protected SourceViewer createViewer(Composite parent) { - SourceViewerConfiguration sourceViewerConfiguration = new StructuredTextViewerConfiguration() { - StructuredTextViewerConfiguration baseConfiguration = new StructuredTextViewerConfigurationXML(); - - public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { - return baseConfiguration.getConfiguredContentTypes(sourceViewer); - } - - public LineStyleProvider[] getLineStyleProviders(ISourceViewer sourceViewer, String partitionType) { - return baseConfiguration.getLineStyleProviders(sourceViewer, partitionType); - } - - public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) { - ContentAssistant assistant = new ContentAssistant(); - assistant.enableAutoActivation(true); - assistant.enableAutoInsert(true); - assistant.setContentAssistProcessor(getTemplateProcessor(), IDocument.DEFAULT_CONTENT_TYPE); - return assistant; - } - }; - return doCreateViewer(parent, sourceViewerConfiguration); - } - } - - public XMLTemplatePreferencePage() { - XMLUIPlugin xmlEditorPlugin = XMLUIPlugin.getDefault(); - - setPreferenceStore(xmlEditorPlugin.getPreferenceStore()); - setTemplateStore(xmlEditorPlugin.getTemplateStore()); - setContextTypeRegistry(xmlEditorPlugin.getTemplateContextRegistry()); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite) - */ - protected Control createContents(Composite ancestor) { - Control c = super.createContents(ancestor); - PlatformUI.getWorkbench().getHelpSystem().setHelp(c, IHelpContextIds.XML_PREFWEBX_TEMPLATES_HELPID); - return c; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.texteditor.templates.TemplatePreferencePage#createViewer(org.eclipse.swt.widgets.Composite) - */ - protected SourceViewer createViewer(Composite parent) { - SourceViewerConfiguration sourceViewerConfiguration = new StructuredTextViewerConfiguration() { - StructuredTextViewerConfiguration baseConfiguration = new StructuredTextViewerConfigurationXML(); - - public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { - return baseConfiguration.getConfiguredContentTypes(sourceViewer); - } - - public LineStyleProvider[] getLineStyleProviders(ISourceViewer sourceViewer, String partitionType) { - return baseConfiguration.getLineStyleProviders(sourceViewer, partitionType); - } - }; - return doCreateViewer(parent, sourceViewerConfiguration); - } - - SourceViewer doCreateViewer(Composite parent, SourceViewerConfiguration viewerConfiguration) { - SourceViewer viewer = null; - String contentTypeID = ContentTypeIdForXML.ContentTypeID_XML; - viewer = new StructuredTextViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); - ((StructuredTextViewer) viewer).getTextWidget().setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont")); //$NON-NLS-1$ - IStructuredModel scratchModel = StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(contentTypeID); - IDocument document = scratchModel.getStructuredDocument(); - viewer.configure(viewerConfiguration); - viewer.setDocument(document); - return viewer; - } - - /** - * Creates the edit dialog. Subclasses may override this method to provide - * a custom dialog. - * - * @param template - * the template being edited - * @param edit - * whether the dialog should be editable - * @param isNameModifiable - * whether the template name may be modified - * @return the created or modified template, or <code>null</code> if the - * edition failed - * @since 3.1 - */ - protected Template editTemplate(Template template, boolean edit, boolean isNameModifiable) { - EditTemplateDialog dialog = new XMLEditTemplateDialog(getShell(), template, edit, isNameModifiable, getContextTypeRegistry()); - if (dialog.open() == Window.OK) { - return dialog.getTemplate(); - } - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.texteditor.templates.TemplatePreferencePage#isShowFormatterSetting() - */ - protected boolean isShowFormatterSetting() { - // template formatting has not been implemented - return false; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.preference.IPreferencePage#performOk() - */ - public boolean performOk() { - boolean ok = super.performOk(); - XMLUIPlugin.getDefault().savePluginPreferences(); - return ok; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLTypingPreferencePage.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLTypingPreferencePage.java deleted file mode 100644 index a30a7dd7e8..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLTypingPreferencePage.java +++ /dev/null @@ -1,106 +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.wst.xml.ui.internal.preferences; - -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Group; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.sse.ui.internal.preferences.ui.AbstractPreferencePage; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.internal.editor.IHelpContextIds; - -public class XMLTypingPreferencePage extends AbstractPreferencePage { - - private Button fCloseComment; - private Button fCloseEndTag; - private Button fRemoveEndTag; - - protected Control createContents(Composite parent) { - Composite composite = super.createComposite(parent, 1); - PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.XML_PREFWEBX_FILES_HELPID); - - createAutoComplete(composite); - createAutoRemove(composite); - - setSize(composite); - loadPreferences(); - - return composite; - } - - private void createAutoComplete(Composite parent) { - Group group = createGroup(parent, 2); - - group.setText(XMLUIMessages.XMLTyping_Auto_Complete); - - fCloseComment = createCheckBox(group, XMLUIMessages.XMLTyping_Complete_Comments); - ((GridData) fCloseComment.getLayoutData()).horizontalSpan = 2; - - fCloseEndTag = createCheckBox(group, XMLUIMessages.XMLTyping_Complete_End_Tags); - ((GridData) fCloseEndTag.getLayoutData()).horizontalSpan = 2; - - } - - private void createAutoRemove(Composite parent) { - Group group = createGroup(parent, 2); - - group.setText(XMLUIMessages.XMLTyping_Auto_Remove); - - fRemoveEndTag = createCheckBox(group, XMLUIMessages.XMLTyping_Remove_End_Tags); - ((GridData) fRemoveEndTag.getLayoutData()).horizontalSpan = 2; - } - - public boolean performOk() { - boolean result = super.performOk(); - - XMLUIPlugin.getDefault().savePluginPreferences(); - - return result; - } - - protected void initializeValues() { - initCheckbox(fCloseComment, XMLUIPreferenceNames.TYPING_COMPLETE_COMMENTS); - initCheckbox(fCloseEndTag, XMLUIPreferenceNames.TYPING_COMPLETE_END_TAGS); - initCheckbox(fRemoveEndTag, XMLUIPreferenceNames.TYPING_REMOVE_END_TAGS); - } - - protected void performDefaults() { - defaultCheckbox(fCloseComment, XMLUIPreferenceNames.TYPING_COMPLETE_COMMENTS); - defaultCheckbox(fCloseEndTag, XMLUIPreferenceNames.TYPING_COMPLETE_END_TAGS); - defaultCheckbox(fRemoveEndTag, XMLUIPreferenceNames.TYPING_REMOVE_END_TAGS); - } - - private void initCheckbox(Button box, String key) { - if(box != null && key != null) - box.setSelection(getPreferenceStore().getBoolean(key)); - } - - private void defaultCheckbox(Button box, String key) { - if(box != null && key != null) - box.setSelection(getPreferenceStore().getDefaultBoolean(key)); - } - - protected void storeValues() { - getPreferenceStore().setValue(XMLUIPreferenceNames.TYPING_COMPLETE_COMMENTS, (fCloseComment != null) ? fCloseComment.getSelection() : false); - getPreferenceStore().setValue(XMLUIPreferenceNames.TYPING_COMPLETE_END_TAGS, (fCloseEndTag != null) ? fCloseEndTag.getSelection() : false); - getPreferenceStore().setValue(XMLUIPreferenceNames.TYPING_REMOVE_END_TAGS, (fRemoveEndTag != null) ? fRemoveEndTag.getSelection() : false); - } - - protected IPreferenceStore doGetPreferenceStore() { - return XMLUIPlugin.getDefault().getPreferenceStore(); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLUIPreferenceInitializer.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLUIPreferenceInitializer.java deleted file mode 100644 index 8d294b1fc1..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLUIPreferenceInitializer.java +++ /dev/null @@ -1,137 +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 - * Benjamin Muskalla, b.muskalla@gmx.net - [158660] character entities should have their own syntax highlighting preference - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.preferences; - -import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.resource.ColorRegistry; -import org.eclipse.jface.text.templates.Template; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.sse.ui.internal.preferences.ui.ColorHelper; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.internal.style.IStyleConstantsXML; - -/** - * Sets default values for XML UI preferences - */ -public class XMLUIPreferenceInitializer extends AbstractPreferenceInitializer { - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences() - */ - public void initializeDefaultPreferences() { - IPreferenceStore store = XMLUIPlugin.getDefault().getPreferenceStore(); - ColorRegistry registry = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry(); - - store.setDefault(XMLUIPreferenceNames.AUTO_PROPOSE, true); - store.setDefault(XMLUIPreferenceNames.AUTO_PROPOSE_CODE, "<=:"); //$NON-NLS-1$ - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=140946 - store.setDefault(XMLUIPreferenceNames.SUGGESTION_STRATEGY, XMLUIPreferenceNames.SUGGESTION_STRATEGY_VALUE_STRICT); - store.setDefault(XMLUIPreferenceNames.USE_INFERRED_GRAMMAR, true); - - // XML Style Preferences - String NOBACKGROUNDBOLD = " | null | false"; //$NON-NLS-1$ - String JUSTITALIC = " | null | false | true"; //$NON-NLS-1$ - String styleValue = ColorHelper.findRGBString(registry, IStyleConstantsXML.TAG_ATTRIBUTE_NAME, 127, 0, 127) + NOBACKGROUNDBOLD; - store.setDefault(IStyleConstantsXML.TAG_ATTRIBUTE_NAME, styleValue); - - styleValue = ColorHelper.findRGBString(registry, IStyleConstantsXML.TAG_ATTRIBUTE_VALUE, 42, 0, 255) + JUSTITALIC; - store.setDefault(IStyleConstantsXML.TAG_ATTRIBUTE_VALUE, styleValue); - - styleValue = "null" + NOBACKGROUNDBOLD; //$NON-NLS-1$ - store.setDefault(IStyleConstantsXML.TAG_ATTRIBUTE_EQUALS, styleValue); // specified - // value - // is - // black; - // leaving - // as - // widget - // default - - styleValue = ColorHelper.findRGBString(registry, IStyleConstantsXML.COMMENT_BORDER, 63, 95, 191) + NOBACKGROUNDBOLD; - store.setDefault(IStyleConstantsXML.COMMENT_BORDER, styleValue); - styleValue = ColorHelper.findRGBString(registry, IStyleConstantsXML.COMMENT_TEXT, 63, 95, 191) + NOBACKGROUNDBOLD; - store.setDefault(IStyleConstantsXML.COMMENT_TEXT, styleValue); - - styleValue = ColorHelper.findRGBString(registry, IStyleConstantsXML.DECL_BORDER, 0, 128, 128) + NOBACKGROUNDBOLD; - store.setDefault(IStyleConstantsXML.DECL_BORDER, styleValue); - - styleValue = ColorHelper.findRGBString(registry, IStyleConstantsXML.DOCTYPE_NAME, 0, 0, 128) + NOBACKGROUNDBOLD; - store.setDefault(IStyleConstantsXML.DOCTYPE_NAME, styleValue); - styleValue = ColorHelper.findRGBString(registry, IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_PUBREF, 0, 0, 128) + NOBACKGROUNDBOLD; - store.setDefault(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_PUBREF, styleValue); - - styleValue = ColorHelper.findRGBString(registry, IStyleConstantsXML.DOCTYPE_EXTERNAL_ID, 128, 128, 128) + NOBACKGROUNDBOLD; - store.setDefault(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID, styleValue); - - styleValue = ColorHelper.findRGBString(registry, IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_SYSREF, 63, 127, 95) + NOBACKGROUNDBOLD; - store.setDefault(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_SYSREF, styleValue); - - styleValue = "null" + NOBACKGROUNDBOLD; //$NON-NLS-1$ - store.setDefault(IStyleConstantsXML.XML_CONTENT, styleValue); // specified - // value - // is - // black; - // leaving - // as - // widget - // default - - styleValue = ColorHelper.findRGBString(registry, IStyleConstantsXML.TAG_BORDER, 0, 128, 128) + NOBACKGROUNDBOLD; - store.setDefault(IStyleConstantsXML.TAG_BORDER, styleValue); - - styleValue = ColorHelper.findRGBString(registry, IStyleConstantsXML.TAG_NAME, 63, 127, 127) + NOBACKGROUNDBOLD; - store.setDefault(IStyleConstantsXML.TAG_NAME, styleValue); - - styleValue = ColorHelper.findRGBString(registry, IStyleConstantsXML.PI_BORDER, 0, 128, 128) + NOBACKGROUNDBOLD; - store.setDefault(IStyleConstantsXML.PI_BORDER, styleValue); - - styleValue = "null" + NOBACKGROUNDBOLD; //$NON-NLS-1$ - store.setDefault(IStyleConstantsXML.PI_CONTENT, styleValue); // specified - // value - // is - // black; - // leaving - // as - // widget - // default - - styleValue = ColorHelper.findRGBString(registry, IStyleConstantsXML.CDATA_BORDER, 0, 128, 128) + NOBACKGROUNDBOLD; - store.setDefault(IStyleConstantsXML.CDATA_BORDER, styleValue); - - styleValue = ColorHelper.findRGBString(registry, IStyleConstantsXML.CDATA_TEXT, 0, 0, 0) + NOBACKGROUNDBOLD; - store.setDefault(IStyleConstantsXML.CDATA_TEXT, styleValue); - - styleValue = ColorHelper.findRGBString(registry, IStyleConstantsXML.ENTITY_REFERENCE, 42, 0, 255) + NOBACKGROUNDBOLD; - store.setDefault(IStyleConstantsXML.ENTITY_REFERENCE, styleValue); - - // set default new xml file template to use in new file wizard - /* - * Need to find template name that goes with default template id (name - * may change for differnt language) - */ - String templateName = ""; //$NON-NLS-1$ - Template template = XMLUIPlugin.getDefault().getTemplateStore().findTemplateById("org.eclipse.wst.xml.ui.internal.templates.xmldeclaration"); //$NON-NLS-1$ - if (template != null) - templateName = template.getName(); - store.setDefault(XMLUIPreferenceNames.NEW_FILE_TEMPLATE_NAME, templateName); - - // Defaults for the Typing preference page - store.setDefault(XMLUIPreferenceNames.TYPING_COMPLETE_COMMENTS, true); - store.setDefault(XMLUIPreferenceNames.TYPING_COMPLETE_END_TAGS, true); - store.setDefault(XMLUIPreferenceNames.TYPING_REMOVE_END_TAGS, true); - } - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLUIPreferenceNames.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLUIPreferenceNames.java deleted file mode 100644 index 771ff17966..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLUIPreferenceNames.java +++ /dev/null @@ -1,137 +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.wst.xml.ui.internal.preferences; - -/** - * Preference keys for XML UI - */ -public class XMLUIPreferenceNames { - - public final static String SUGGESTION_STRATEGY_VALUE_LAX = "Lax"; //$NON-NLS-1$ - public final static String SUGGESTION_STRATEGY_VALUE_STRICT = "Strict"; //$NON-NLS-1$ - /** - * A named preference that controls if code assist gets auto activated. - * <p> - * Value is of type <code>Boolean</code>. - * </p> - */ - public static final String AUTO_PROPOSE = getAutoProposeKey(); - - private static String getAutoProposeKey() { - return "autoPropose";//$NON-NLS-1$ - } - - /** - * A named preference that holds the characters that auto activate code - * assist. - * <p> - * Value is of type <code>String</code>. All characters that trigger - * auto code assist. - * </p> - */ - public static final String AUTO_PROPOSE_CODE = getAutoProposeCodeKey(); - - private static String getAutoProposeCodeKey() { - return "autoProposeCode";//$NON-NLS-1$ - } - - /** - * The key to store customized templates. - * <p> - * Value is of type <code>String</code>. - * </p> - */ - public static final String TEMPLATES_KEY = getTemplatesKey(); - - private static String getTemplatesKey() { - return "org.eclipse.wst.sse.ui.custom_templates"; //$NON-NLS-1$ - } - - /** - * A named preference that controls whether or grammar should be inferred - * or not. - * <p> - * Value is of type <code>Boolean</code>. - * </p> - */ - public static final String USE_INFERRED_GRAMMAR = getUseInferredGrammarKey(); - - public static class OUTLINE_BEHAVIOR { - public static final String ELEMENT_NODE = "outline-behavior.element-node"; //$NON-NLS-1$ - public static final String ATTRIBUTE_NODE = "outline-behavior.attribute-node"; //$NON-NLS-1$ - public static final String TEXT_NODE = "outline-behavior.text-node"; //$NON-NLS-1$ - public static final String CDATA_SECTION_NODE = "outline-behavior.cdata-section-node"; //$NON-NLS-1$ - public static final String ENTITY_REFERENCE_NODE = "outline-behavior.entity-reference-node"; //$NON-NLS-1$ - public static final String ENTITY_NODE = "outline-behavior.entity-node"; //$NON-NLS-1$ - public static final String PROCESSING_INSTRUCTION_NODE = "outline-behavior.instruction-node"; //$NON-NLS-1$ - public static final String COMMENT_NODE = "outline-behavior.comment-node"; //$NON-NLS-1$ - public static final String DOCUMENT_NODE = "outline-behavior.document-node"; //$NON-NLS-1$ - public static final String DOCUMENT_TYPE_NODE = "outline-behavior.document-type-node"; //$NON-NLS-1$ - public static final String DOCUMENT_FRAGMENT_NODE = "outline-behavior.document-fragment-node"; //$NON-NLS-1$ - public static final String NOTATION_NODE = "outline-behavior.notation-node"; //$NON-NLS-1$ - } - - private static String getUseInferredGrammarKey() { - return "useInferredGrammar"; //$NON-NLS-1$ - } - - /** - * A named preference that holds the characters that auto activate code - * assist. - * <p> - * Value is of type <code>String</code>. All characters that trigger - * auto code assist. - * </p> - */ - public static final String SUGGESTION_STRATEGY = getSuggestionStrategeyKey(); - - private static String getSuggestionStrategeyKey() { - return "suggestionStrategy";//$NON-NLS-1$ - } - - /** - * The key to store the last template name used in new DTD file wizard. - * Template name is stored instead of template id because user-created - * templates do not have template ids. - * <p> - * Value is of type <code>String</code>. - * </p> - */ - public static final String NEW_FILE_TEMPLATE_NAME = "newFileTemplateName"; //$NON-NLS-1$ - - /** - * The key to store the option for auto-completing comments while - * typing. - * <p> - * Value is of type <code>boolean</code>. - * </p> - */ - public static final String TYPING_COMPLETE_COMMENTS = "completeComments"; //$NON-NLS-1$ - - /** - * The key to store the option for auto-completing end-tags after entering - * <code></</code> - * <p> - * Value is of type <code>boolean</code>. - * </p> - */ - public static final String TYPING_COMPLETE_END_TAGS = "completeEndTags"; //$NON-NLS-1$ - - /** - * The key to store the option for removing an end-tag if the start tag is - * converted to an empty-tag. - * <p> - * Value is of type <code>boolean</code>. - * </p> - */ - public static final String TYPING_REMOVE_END_TAGS = "removeEndTags"; //$NON-NLS-1$ -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/projection/ProjectionAnnotationModelChanges.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/projection/ProjectionAnnotationModelChanges.java deleted file mode 100644 index 7d415f9558..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/projection/ProjectionAnnotationModelChanges.java +++ /dev/null @@ -1,54 +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.wst.xml.ui.internal.projection; - -import java.util.Map; - -import org.eclipse.jface.text.source.Annotation; -import org.w3c.dom.Node; - -/** - * Contains a set of projection model additions/deletions/modifications - */ -class ProjectionAnnotationModelChanges { - // copies of this class located in: - // org.eclipse.wst.xml.ui.internal.projection - // org.eclipse.wst.css.ui.internal.projection - // org.eclipse.wst.html.ui.internal.projection - // org.eclipse.jst.jsp.ui.internal.projection - private Node fNode; - private Annotation[] fDeletions; - private Map fAdditions; - private Annotation[] fModifications; - - public ProjectionAnnotationModelChanges(Node node, Annotation[] deletions, Map additions, Annotation[] modifications) { - fNode = node; - fDeletions = deletions; - fAdditions = additions; - fModifications = modifications; - } - - public Map getAdditions() { - return fAdditions; - } - - public Annotation[] getDeletions() { - return fDeletions; - } - - public Annotation[] getModifications() { - return fModifications; - } - - public Node getNode() { - return fNode; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/projection/ProjectionModelNodeAdapterFactoryXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/projection/ProjectionModelNodeAdapterFactoryXML.java deleted file mode 100644 index 8202f4f33b..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/projection/ProjectionModelNodeAdapterFactoryXML.java +++ /dev/null @@ -1,157 +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.wst.xml.ui.internal.projection; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.eclipse.jface.text.source.Annotation; -import org.eclipse.jface.text.source.projection.ProjectionViewer; -import org.eclipse.wst.sse.core.internal.provisional.AbstractAdapterFactory; -import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter; -import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; -import org.w3c.dom.Node; - -public class ProjectionModelNodeAdapterFactoryXML extends AbstractAdapterFactory { - /** - * List of projection viewers currently associated with this projection - * model node adapter factory. - */ - private HashMap fProjectionViewers; - - public ProjectionModelNodeAdapterFactoryXML() { - super(ProjectionModelNodeAdapterXML.class, true); - } - - protected INodeAdapter createAdapter(INodeNotifier target) { - ProjectionModelNodeAdapterXML adapter = null; - - // create adapter for every element tag - if ((isActive()) && (target instanceof Node) && (((Node) target).getNodeType() == Node.ELEMENT_NODE)) { - adapter = new ProjectionModelNodeAdapterXML(this); - adapter.updateAdapter((Node) target); - } - - return adapter; - } - - /** - * Return true if this factory is currently actively managing projection - * - * @return - */ - boolean isActive() { - return ((fProjectionViewers != null) && !fProjectionViewers.isEmpty()); - } - - /** - * Updates projection annotation model if document is not in flux. - * Otherwise, queues up the changes to be applied when document is ready. - * - * @param node - * @param deletions - * @param additions - * @param modifications - */ - void queueAnnotationModelChanges(Node node, Annotation[] deletions, Map additions, Annotation[] modifications) { - queueAnnotationModelChanges(node, deletions, additions, modifications, null); - } - - /** - * Updates projection annotation model for a specific projection viewer if - * document is not in flux. Otherwise, queues up the changes to be applied - * when document is ready. - * - * @param node - * @param deletions - * @param additions - * @param modifications - * @param viewer - */ - void queueAnnotationModelChanges(Node node, Annotation[] deletions, Map additions, Annotation[] modifications, ProjectionViewer viewer) { - // create a change object for latest change and add to queue - ProjectionAnnotationModelChanges newChange = new ProjectionAnnotationModelChanges(node, deletions, additions, modifications); - if (fProjectionViewers != null) { - if (viewer != null) { - ProjectionViewerInformation info = (ProjectionViewerInformation) fProjectionViewers.get(viewer); - if (info != null) { - info.queueAnnotationModelChanges(newChange); - } - } - else { - Iterator infos = fProjectionViewers.values().iterator(); - while (infos.hasNext()) { - ProjectionViewerInformation info = (ProjectionViewerInformation) infos.next(); - info.queueAnnotationModelChanges(newChange); - } - } - } - } - - public void release() { - // go through every projectionviewer and call - // removeProjectionViewer(viewer); - if (fProjectionViewers != null) { - Iterator infos = fProjectionViewers.values().iterator(); - while (infos.hasNext()) { - ProjectionViewerInformation info = (ProjectionViewerInformation) infos.next(); - info.dispose(); - infos.remove(); - } - fProjectionViewers = null; - } - super.release(); - } - - /** - * Adds viewer to list of projection viewers this factory is associated - * with - * - * @param viewer - - * assumes viewer's document and projection annotation model - * are not null - */ - void addProjectionViewer(ProjectionViewer viewer) { - // remove old entry if it exists - removeProjectionViewer(viewer); - - if (fProjectionViewers == null) { - fProjectionViewers = new HashMap(); - } - - // create new object containing projection viewer and its info - ProjectionViewerInformation info = new ProjectionViewerInformation(viewer); - fProjectionViewers.put(viewer, info); - info.initialize(); - } - - /** - * Removes the given viewer from the list of projection viewers this - * factor is associated with - * - * @param viewer - */ - void removeProjectionViewer(ProjectionViewer viewer) { - if (fProjectionViewers != null) { - // remove entry from list of viewers - ProjectionViewerInformation info = (ProjectionViewerInformation) fProjectionViewers.remove(viewer); - if (info != null) { - info.dispose(); - } - // if removing last projection viewer, clear out everything - if (fProjectionViewers.isEmpty()) { - fProjectionViewers = null; - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/projection/ProjectionModelNodeAdapterXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/projection/ProjectionModelNodeAdapterXML.java deleted file mode 100644 index fde379a392..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/projection/ProjectionModelNodeAdapterXML.java +++ /dev/null @@ -1,298 +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.wst.xml.ui.internal.projection; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.text.Position; -import org.eclipse.jface.text.source.projection.ProjectionAnnotation; -import org.eclipse.jface.text.source.projection.ProjectionViewer; -import org.eclipse.swt.graphics.FontMetrics; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.widgets.Canvas; -import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter; -import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.w3c.dom.Node; - -/** - * Updates projection annotation model with projection annotations for this - * adapter node's children - */ -public class ProjectionModelNodeAdapterXML implements INodeAdapter { - private final static boolean debugProjectionPerf = "true".equalsIgnoreCase(Platform.getDebugOption("org.eclipse.wst.xml.ui/projectionperf")); //$NON-NLS-1$ //$NON-NLS-2$ - - private class TagProjectionAnnotation extends ProjectionAnnotation { - private boolean fIsVisible = false; /* workaround for BUG85874 */ - private Node fNode; - - public TagProjectionAnnotation(Node node, boolean isCollapsed) { - super(isCollapsed); - fNode = node; - } - - public Node getNode() { - return fNode; - } - - public void setNode(Node node) { - fNode = node; - } - - /** - * Does not paint hidden annotations. Annotations are hidden when they - * only span one line. - * - * @see ProjectionAnnotation#paint(org.eclipse.swt.graphics.GC, - * org.eclipse.swt.widgets.Canvas, - * org.eclipse.swt.graphics.Rectangle) - */ - public void paint(GC gc, Canvas canvas, Rectangle rectangle) { - /* workaround for BUG85874 */ - /* - * only need to check annotations that are expanded because hidden - * annotations should never have been given the chance to - * collapse. - */ - if (!isCollapsed()) { - // working with rectangle, so line height - FontMetrics metrics = gc.getFontMetrics(); - if (metrics != null) { - // do not draw annotations that only span one line and - // mark them as not visible - if ((rectangle.height / metrics.getHeight()) <= 1) { - fIsVisible = false; - return; - } - } - } - fIsVisible = true; - super.paint(gc, canvas, rectangle); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.source.projection.ProjectionAnnotation#markCollapsed() - */ - public void markCollapsed() { - /* workaround for BUG85874 */ - // do not mark collapsed if annotation is not visible - if (fIsVisible) { - super.markCollapsed(); - } - } - } - - ProjectionModelNodeAdapterFactoryXML fAdapterFactory; - private Map fTagAnnotations = new HashMap(); - - public ProjectionModelNodeAdapterXML(ProjectionModelNodeAdapterFactoryXML factory) { - fAdapterFactory = factory; - } - - /** - * Create a projection position from the given node. Able to get - * projection position if node isNodeProjectable. - * - * @param node - * @return null if no projection position possible, a Position otherwise - */ - private Position createProjectionPosition(Node node) { - Position pos = null; - if (isNodeProjectable(node) && (node instanceof IndexedRegion)) { - // IDocument document = - // fAdapterFactory.getProjectionViewer().getDocument(); - // if (document != null) { - IndexedRegion inode = (IndexedRegion) node; - int start = inode.getStartOffset(); - int end = inode.getEndOffset(); - if ((start >= 0) && (start < end)) { - // region-based - // extra line when collapsed, but no region increase when add - // newline - pos = new Position(start, end - start); - // try { - // // line-based - // // extra line when collapsed, but no region increase when - // add newline - // IRegion startLineRegion = - // document.getLineInformationOfOffset(start); - // IRegion endLineRegion = - // document.getLineInformationOfOffset(end); - // int startOffset = startLineRegion.getOffset(); - // int endOffset = endLineRegion.getOffset() + - // endLineRegion.getLength(); - // if (endOffset > startOffset) { - // pos = new Position(startOffset, endOffset - startOffset); - // } - - // // line-based - // // no extra line when collapsed, but region increase when - // add newline - // int startLine = document.getLineOfOffset(start); - // int endLine = document.getLineOfOffset(end); - // if (endLine + 1 < document.getNumberOfLines()) { - // int offset = document.getLineOffset(startLine); - // int endOffset = document.getLineOffset(endLine + 1); - // pos = new Position(offset, endOffset - offset); - // } - // } - // catch (BadLocationException x) { - // Logger.log(Logger.WARNING_DEBUG, null, x); - // } - } - // } - } - return pos; - } - - /** - * Find TagProjectionAnnotation for node in the current list of projection - * annotations for this adapter - * - * @param node - * @return TagProjectionAnnotation - */ - private TagProjectionAnnotation getExistingAnnotation(Node node) { - TagProjectionAnnotation anno = null; - - if ((node != null) && (!fTagAnnotations.isEmpty())) { - Iterator it = fTagAnnotations.keySet().iterator(); - while (it.hasNext() && (anno == null)) { - TagProjectionAnnotation a = (TagProjectionAnnotation) it.next(); - Node n = a.getNode(); - if (node.equals(n)) { - anno = a; - } - } - } - return anno; - } - - public boolean isAdapterForType(Object type) { - return type == ProjectionModelNodeAdapterXML.class; - } - - /** - * Returns true if node is a node type able to fold - * - * @param node - * @return boolean true if node is projectable, false otherwise - */ - private boolean isNodeProjectable(Node node) { - if (node.getNodeType() == Node.ELEMENT_NODE) { - return true; - } - return false; - } - - public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) { - // check if folding is even enabled, if not, just ignore notifyChanged - // events - if (!fAdapterFactory.isActive()) { - return; - } - - if ((eventType == INodeNotifier.STRUCTURE_CHANGED) && (notifier instanceof Node)) { - updateAdapter((Node) notifier); - } - } - - /** - * Update the projection annotation of all the nodes that are children of - * node - * - * @param node - */ - void updateAdapter(Node node) { - updateAdapter(node, null); - } - - /** - * Update the projection annotation of all the nodes that are children of - * node and adds all projection annotations to viewer (for newly added - * viewers) - * - * @param node - * @param viewer - */ - void updateAdapter(Node node, ProjectionViewer viewer) { - long start = System.currentTimeMillis(); - - Map additions = new HashMap(); - Map projectionAnnotations = new HashMap(); - - // go through immediate child nodes and figure out projection - // model annotations - if (node != null) { - Node childNode = node.getFirstChild(); - while (childNode != null) { - Position newPos = createProjectionPosition(childNode); - if (newPos != null) { - TagProjectionAnnotation newAnnotation = new TagProjectionAnnotation(childNode, false); - TagProjectionAnnotation existing = getExistingAnnotation(childNode); - if (existing == null) { - // add to map containing all annotations for this - // adapter - projectionAnnotations.put(newAnnotation, newPos); - // add to map containing annotations to add - additions.put(newAnnotation, newPos); - } - else { - // add to map containing all annotations for this - // adapter - projectionAnnotations.put(existing, newPos); - // remove from map containing annotations to delete - fTagAnnotations.remove(existing); - } - } - childNode = childNode.getNextSibling(); - } - - // in the end, want to delete anything leftover in old list, add - // everything in additions, and update everything in - // projectionAnnotations - ProjectionAnnotation[] oldList = null; - if (!fTagAnnotations.isEmpty()) { - oldList = (ProjectionAnnotation[]) fTagAnnotations.keySet().toArray(new ProjectionAnnotation[0]); - } - ProjectionAnnotation[] modifyList = null; - if (!projectionAnnotations.isEmpty()) { - modifyList = (ProjectionAnnotation[]) projectionAnnotations.keySet().toArray(new ProjectionAnnotation[0]); - } - - // specifically add all annotations to viewer - if ((viewer != null) && !projectionAnnotations.isEmpty()) { - fAdapterFactory.queueAnnotationModelChanges(node, null, projectionAnnotations, null, viewer); - } - - // only update when there is something to update - if (((oldList != null) && (oldList.length > 0)) || (!additions.isEmpty()) || ((modifyList != null) && (modifyList.length > 0))) { - fAdapterFactory.queueAnnotationModelChanges(node, oldList, additions, modifyList); - } - } - - // save new list of annotations - fTagAnnotations = projectionAnnotations; - - if (debugProjectionPerf) { - long end = System.currentTimeMillis(); - String nodeName = node != null ? node.getNodeName() : "null"; //$NON-NLS-1$ - System.out.println("ProjectionModelNodeAdapterXML.updateAdapter (" + nodeName + "):" + (end - start)); //$NON-NLS-1$ //$NON-NLS-2$ - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/projection/ProjectionViewerInformation.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/projection/ProjectionViewerInformation.java deleted file mode 100644 index 1dccff6c2a..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/projection/ProjectionViewerInformation.java +++ /dev/null @@ -1,197 +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.wst.xml.ui.internal.projection; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.jface.text.DocumentEvent; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IDocumentExtension; -import org.eclipse.jface.text.IDocumentListener; -import org.eclipse.jface.text.source.projection.ProjectionAnnotationModel; -import org.eclipse.jface.text.source.projection.ProjectionViewer; -import org.eclipse.wst.xml.ui.internal.Logger; - -/** - * Contains information about a projection viewer and also manages updating - * the viewer's projection annotation model - */ -class ProjectionViewerInformation { - // copies of this class located in: - // org.eclipse.wst.xml.ui.internal.projection - // org.eclipse.wst.css.ui.internal.projection - // org.eclipse.wst.html.ui.internal.projection - // org.eclipse.jst.jsp.ui.internal.projection - - /** - * Listens to document to be aware of when to update the projection - * annotation model. - */ - private class DocumentListener implements IDocumentListener { - private ProjectionViewerInformation fInfo; - - public DocumentListener(ProjectionViewerInformation info) { - fInfo = info; - } - - public void documentAboutToBeChanged(DocumentEvent event) { - IDocument document = event.getDocument(); - if (fInfo.getDocument() == document) { - fInfo.setIsDocumentChanging(true); - } - } - - public void documentChanged(DocumentEvent event) { - // register a post notification replace so that projection - // annotation model will be updated after all documentChanged - // listeners have been notified - IDocument document = event.getDocument(); - if ((document instanceof IDocumentExtension) && (fInfo.getDocument() == document)) { - if (fInfo.hasChangesQueued()) { - ((IDocumentExtension) document).registerPostNotificationReplace(this, new PostDocumentChangedListener(fInfo)); - } - } - } - } - - /** - * Essentially a post document changed listener because it is called after - * documentchanged has been fired. - */ - private class PostDocumentChangedListener implements IDocumentExtension.IReplace { - private ProjectionViewerInformation fInfo; - - public PostDocumentChangedListener(ProjectionViewerInformation info) { - fInfo = info; - } - - public void perform(IDocument document, IDocumentListener owner) { - fInfo.applyAnnotationModelChanges(); - fInfo.setIsDocumentChanging(false); - } - } - - /** - * Projection annotation model current associated with this projection - * viewer - */ - private ProjectionAnnotationModel fProjectionAnnotationModel; - /** - * Document currently associated with this projection viewer - */ - private IDocument fDocument; - /** - * Listener to fProjectionViewer's document - */ - private IDocumentListener fDocumentListener; - /** - * Indicates whether or not document is in the middle of changing - */ - private boolean fIsDocumentChanging = false; - /** - * List of projection annotation model changes that need to be applied - */ - private List fQueuedAnnotationChanges; - - public ProjectionViewerInformation(ProjectionViewer viewer) { - fDocument = viewer.getDocument(); - fProjectionAnnotationModel = viewer.getProjectionAnnotationModel(); - } - - IDocument getDocument() { - return fDocument; - } - - private List getQueuedAnnotationChanges() { - if (fQueuedAnnotationChanges == null) { - fQueuedAnnotationChanges = new ArrayList(); - } - return fQueuedAnnotationChanges; - } - - void setIsDocumentChanging(boolean changing) { - fIsDocumentChanging = changing; - } - - private boolean isDocumentChanging() { - return fIsDocumentChanging; - } - - /** - * Applies the pending projection annotation model changes to the - * projection annotation model. - */ - void applyAnnotationModelChanges() { - List queuedChanges = getQueuedAnnotationChanges(); - // go through all the pending annotation changes and apply - // them to - // the projection annotation model - while (!queuedChanges.isEmpty()) { - ProjectionAnnotationModelChanges changes = (ProjectionAnnotationModelChanges) queuedChanges.remove(0); - try { - fProjectionAnnotationModel.modifyAnnotations(changes.getDeletions(), changes.getAdditions(), changes.getModifications()); - } - catch (Exception e) { - // if anything goes wrong, log it be continue - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - } - } - - /** - * Returns true if there are annotation changes queued up, false otherwise - * - * @return boolean - */ - boolean hasChangesQueued() { - return !getQueuedAnnotationChanges().isEmpty(); - } - - /** - * Updates projection annotation model if document is not in flux. - * Otherwise, queues up the changes to be applied when document is ready. - */ - public void queueAnnotationModelChanges(ProjectionAnnotationModelChanges newChange) { - /* - * future_TODO: maybe improve by checking if annotation projection - * model change already exists for node. if so, throw out old change. - */ - getQueuedAnnotationChanges().add(newChange); - - // if document isn't changing, go ahead and apply it - if (!isDocumentChanging()) { - applyAnnotationModelChanges(); - } - } - - public void initialize() { - // add document listener - if (fDocumentListener == null) { - fDocumentListener = new DocumentListener(this); - } - getDocument().addDocumentListener(fDocumentListener); - } - - public void dispose() { - // remove document listener - if (fDocumentListener != null) { - getDocument().removeDocumentListener(fDocumentListener); - } - - // clear out list of queued changes since it may no longer - // be accurate - if (fQueuedAnnotationChanges != null) { - fQueuedAnnotationChanges.clear(); - fQueuedAnnotationChanges = null; - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/projection/StructuredTextFoldingProviderXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/projection/StructuredTextFoldingProviderXML.java deleted file mode 100644 index b7047bbc85..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/projection/StructuredTextFoldingProviderXML.java +++ /dev/null @@ -1,350 +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.wst.xml.ui.internal.projection; - -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextInputListener; -import org.eclipse.jface.text.source.projection.IProjectionListener; -import org.eclipse.jface.text.source.projection.ProjectionViewer; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.PropagatingAdapter; -import org.eclipse.wst.sse.core.internal.model.FactoryRegistry; -import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter; -import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.sse.ui.internal.projection.IStructuredTextFoldingProvider; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; -import org.w3c.dom.Document; -import org.w3c.dom.Node; - -/** - * Updates the projection model of a structured model for XML. - */ -public class StructuredTextFoldingProviderXML implements IStructuredTextFoldingProvider, IProjectionListener, ITextInputListener { - private final static boolean debugProjectionPerf = "true".equalsIgnoreCase(Platform.getDebugOption("org.eclipse.wst.xml.ui/projectionperf")); //$NON-NLS-1$ //$NON-NLS-2$ - - private IDocument fDocument; - private ProjectionViewer fViewer; - private boolean fProjectionNeedsToBeEnabled = false; - /** - * Maximum number of child nodes to add adapters to (limit for performance - * sake) - */ - private final int MAX_CHILDREN = 10; - /** - * Maximum number of sibling nodes to add adapters to (limit for - * performance sake) - */ - private final int MAX_SIBLINGS = 1000; - - /** - * Adds an adapter to node and its children - * - * @param node - * @param childLevel - */ - private void addAdapterToNodeAndChildren(Node node, int childLevel) { - // stop adding initial adapters MAX_CHILDREN levels deep for - // performance sake - if ((node instanceof INodeNotifier) && (childLevel < MAX_CHILDREN)) { - INodeNotifier notifier = (INodeNotifier) node; - - // try and get the adapter for the current node and update the - // adapter with projection information - ProjectionModelNodeAdapterXML adapter = (ProjectionModelNodeAdapterXML) notifier.getExistingAdapter(ProjectionModelNodeAdapterXML.class); - if (adapter != null) { - adapter.updateAdapter(node, fViewer); - } - else { - // just call getadapter so the adapter is created and - // automatically initialized - notifier.getAdapterFor(ProjectionModelNodeAdapterXML.class); - } - int siblingLevel = 0; - Node nextChild = node.getFirstChild(); - while ((nextChild != null) && (siblingLevel < MAX_SIBLINGS)) { - Node childNode = nextChild; - nextChild = childNode.getNextSibling(); - - addAdapterToNodeAndChildren(childNode, childLevel + 1); - } - } - } - - /** - * Goes through every node and adds an adapter onto each for tracking - * purposes - */ - private void addAllAdapters() { - long start = System.currentTimeMillis(); - - if (fDocument != null) { - IStructuredModel sModel = null; - try { - sModel = StructuredModelManager.getModelManager().getExistingModelForRead(fDocument); - if (sModel != null) { - int startOffset = 0; - IndexedRegion startNode = sModel.getIndexedRegion(startOffset); - if (startNode instanceof Node) { - int siblingLevel = 0; - Node nextSibling = (Node) startNode; - while ((nextSibling != null) && (siblingLevel < MAX_SIBLINGS)) { - Node currentNode = nextSibling; - nextSibling = currentNode.getNextSibling(); - - addAdapterToNodeAndChildren(currentNode, 0); - ++siblingLevel; - } - } - } - } - finally { - if (sModel != null) { - sModel.releaseFromRead(); - } - } - } - if (debugProjectionPerf) { - long end = System.currentTimeMillis(); - System.out.println("StructuredTextFoldingProviderXML.addAllAdapters: " + (end - start)); //$NON-NLS-1$ - } - } - - /** - * Get the ProjectionModelNodeAdapterFactoryXML to use with this provider. - * - * @return ProjectionModelNodeAdapterFactoryXML - */ - private ProjectionModelNodeAdapterFactoryXML getAdapterFactory(boolean createIfNeeded) { - long start = System.currentTimeMillis(); - - ProjectionModelNodeAdapterFactoryXML factory = null; - if (fDocument != null) { - IStructuredModel sModel = null; - try { - sModel = StructuredModelManager.getModelManager().getExistingModelForRead(fDocument); - if (sModel != null) { - FactoryRegistry factoryRegistry = sModel.getFactoryRegistry(); - - // getting the projectionmodelnodeadapter for the first - // time - // so do some initializing - if (!factoryRegistry.contains(ProjectionModelNodeAdapterXML.class) && createIfNeeded) { - ProjectionModelNodeAdapterFactoryXML newFactory = new ProjectionModelNodeAdapterFactoryXML(); - - // add factory to factory registry - factoryRegistry.addFactory(newFactory); - - // add factory to propogating adapter - IDOMModel domModel = (IDOMModel) sModel; - Document document = domModel.getDocument(); - PropagatingAdapter propagatingAdapter = (PropagatingAdapter) ((INodeNotifier) document).getAdapterFor(PropagatingAdapter.class); - if (propagatingAdapter != null) { - propagatingAdapter.addAdaptOnCreateFactory(newFactory); - } - } - - // try and get the factory - factory = (ProjectionModelNodeAdapterFactoryXML) factoryRegistry.getFactoryFor(ProjectionModelNodeAdapterXML.class); - } - } - finally { - if (sModel != null) { - sModel.releaseFromRead(); - } - } - } - - if (debugProjectionPerf) { - long end = System.currentTimeMillis(); - System.out.println("StructuredTextFoldingProviderXML.getAdapterFactory: " + (end - start)); //$NON-NLS-1$ - } - return factory; - } - - /** - * Initialize this provider with the correct document. Assumes projection - * is enabled. (otherwise, only install would have been called) - */ - public void initialize() { - if (!isInstalled()) { - return; - } - - long start = System.currentTimeMillis(); - // clear out old info - projectionDisabled(); - - fDocument = fViewer.getDocument(); - - // set projection viewer on new document's adapter factory - if (fViewer.getProjectionAnnotationModel() != null) { - ProjectionModelNodeAdapterFactoryXML factory = getAdapterFactory(true); - if (factory != null) { - factory.addProjectionViewer(fViewer); - } - try { - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=198304 - // disable redraw while adding all adapters - fViewer.setRedraw(false); - addAllAdapters(); - } - finally { - fViewer.setRedraw(true); - } - } - fProjectionNeedsToBeEnabled = false; - - if (debugProjectionPerf) { - long end = System.currentTimeMillis(); - System.out.println("StructuredTextFoldingProviderXML.initialize: " + (end - start)); //$NON-NLS-1$ - } - } - - /** - * Associate a ProjectionViewer with this IStructuredTextFoldingProvider - * - * @param viewer - - * assumes not null - */ - public void install(ProjectionViewer viewer) { - // uninstall before trying to install new viewer - if (isInstalled()) { - uninstall(); - } - fViewer = viewer; - fViewer.addProjectionListener(this); - fViewer.addTextInputListener(this); - } - - private boolean isInstalled() { - return fViewer != null; - } - - public void projectionDisabled() { - ProjectionModelNodeAdapterFactoryXML factory = getAdapterFactory(false); - if (factory != null) { - factory.removeProjectionViewer(fViewer); - } - - // clear out all annotations - if (fViewer.getProjectionAnnotationModel() != null) { - fViewer.getProjectionAnnotationModel().removeAllAnnotations(); - } - - removeAllAdapters(); - - fDocument = null; - fProjectionNeedsToBeEnabled = false; - } - - public void projectionEnabled() { - initialize(); - } - - /** - * Removes an adapter from node and its children - * - * @param node - * @param level - */ - private void removeAdapterFromNodeAndChildren(Node node, int level) { - if (node instanceof INodeNotifier) { - INodeNotifier notifier = (INodeNotifier) node; - - // try and get the adapter for the current node and remove it - INodeAdapter adapter = notifier.getExistingAdapter(ProjectionModelNodeAdapterXML.class); - if (adapter != null) { - notifier.removeAdapter(adapter); - } - - Node nextChild = node.getFirstChild(); - while (nextChild != null) { - Node childNode = nextChild; - nextChild = childNode.getNextSibling(); - - removeAdapterFromNodeAndChildren(childNode, level + 1); - } - } - } - - /** - * Goes through every node and removes adapter from each for cleanup - * purposes - */ - private void removeAllAdapters() { - long start = System.currentTimeMillis(); - - if (fDocument != null) { - IStructuredModel sModel = null; - try { - sModel = StructuredModelManager.getModelManager().getExistingModelForRead(fDocument); - if (sModel != null) { - int startOffset = 0; - IndexedRegion startNode = sModel.getIndexedRegion(startOffset); - if (startNode instanceof Node) { - Node nextSibling = (Node) startNode; - while (nextSibling != null) { - Node currentNode = nextSibling; - nextSibling = currentNode.getNextSibling(); - - removeAdapterFromNodeAndChildren(currentNode, 0); - } - } - } - } - finally { - if (sModel != null) { - sModel.releaseFromRead(); - } - } - } - - if (debugProjectionPerf) { - long end = System.currentTimeMillis(); - System.out.println("StructuredTextFoldingProviderXML.removeAllAdapters: " + (end - start)); //$NON-NLS-1$ - } - } - - public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) { - // if folding is enabled and new document is going to be a totally - // different document, disable projection - if ((fDocument != null) && (fDocument != newInput)) { - // disable projection and disconnect everything - projectionDisabled(); - fProjectionNeedsToBeEnabled = true; - } - } - - public void inputDocumentChanged(IDocument oldInput, IDocument newInput) { - // if projection was previously enabled before input document changed - // and new document is different than old document - if (fProjectionNeedsToBeEnabled && (fDocument == null) && (newInput != null)) { - projectionEnabled(); - fProjectionNeedsToBeEnabled = false; - } - } - - /** - * Disconnect this IStructuredTextFoldingProvider from projection viewer - */ - public void uninstall() { - if (isInstalled()) { - projectionDisabled(); - - fViewer.removeProjectionListener(this); - fViewer.removeTextInputListener(this); - fViewer = null; - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/properties/EnumeratedStringPropertyDescriptor.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/properties/EnumeratedStringPropertyDescriptor.java deleted file mode 100644 index a4bd9f6fcb..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/properties/EnumeratedStringPropertyDescriptor.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.properties; - - - -import java.util.Arrays; - -import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.views.properties.PropertyDescriptor; - -/** - * This class should be used for properties which require a combo box cell - * editor and whose values consist of a list of enumerated strings. - */ -public class EnumeratedStringPropertyDescriptor extends PropertyDescriptor { - protected StringComboBoxCellEditor fEditor; - protected Composite fParent; - - /** - * The enumerated possible values for the described property - */ - protected String fValues[] = null; - - public EnumeratedStringPropertyDescriptor(Object id, String newDisplayName, String[] valuesArray) { - super(id, newDisplayName); - setDescription((String) id); - fValues = valuesArray; - } - - /** - * Creates and returns a new cell editor for editing this property. - * Returns <code>null</code> if the property is not editable. - * - * @param parent - * the parent widget for the cell editor - * @return the cell editor for this property, or <code>null</code> if - * this property cannot be edited - */ - public CellEditor createPropertyEditor(Composite parent) { - // Check to see if we already have a Cell Editor with a valid Control - // under the given parent. - // If any of that's not true, create and return a new Cell Editor - if ((fEditor == null) || (fEditor.getControl() == null) || fEditor.getControl().isDisposed() || (parent != fParent)) { - fEditor = new StringComboBoxCellEditor(parent, fValues); - } - fParent = parent; - return fEditor; - } - - public void updateValues(String newValues[]) { - if (Arrays.equals(fValues, newValues)) { - return; - } - fValues = newValues; - if (fEditor != null) { - fEditor.setItems(newValues); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/properties/StringComboBoxCellEditor.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/properties/StringComboBoxCellEditor.java deleted file mode 100644 index a6536be42a..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/properties/StringComboBoxCellEditor.java +++ /dev/null @@ -1,119 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.properties; - - - -import org.eclipse.jface.viewers.ComboBoxCellEditor; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.wst.sse.ui.internal.Logger; - - -/** - * An extended ComboBoxCellEditor that selects and returns Strings - */ - -public class StringComboBoxCellEditor extends ComboBoxCellEditor { - private boolean fSettingValue = false; - - /** - * - */ - public StringComboBoxCellEditor() { - super(); - } - - /** - * @param parent - * @param items - */ - public StringComboBoxCellEditor(Composite parent, String[] items) { - super(parent, items); - } - - /** - * @param parent - * @param items - * @param style - */ - public StringComboBoxCellEditor(Composite parent, String[] items, int style) { - super(parent, items, style); - } - - protected Object doGetValue() { - // otherwise limits to set of valid values - Object index = super.doGetValue(); - int selection = -1; - if (index instanceof Integer) { - selection = ((Integer) index).intValue(); - } - if (selection >= 0) { - return getItems()[selection]; - } - else if (getControl() instanceof CCombo) { - // retrieve the actual text as the list of valid items doesn't - // contain the value - return ((CCombo) getControl()).getText(); - } - return null; - } - - protected void doSetValue(Object value) { - if (fSettingValue) { - return; - } - fSettingValue = true; - if (value instanceof Integer) { - super.doSetValue(value); - } - else { - String stringValue = value.toString(); - int selection = -1; - for (int i = 0; i < getItems().length; i++) { - if (getItems()[i].equals(stringValue)) { - selection = i; - } - } - if (selection >= 0) { - super.doSetValue(new Integer(selection)); - } - else { - super.doSetValue(new Integer(-1)); - if ((getControl() instanceof CCombo) && !stringValue.equals(((CCombo) getControl()).getText())) { - // update the Text widget - ((CCombo) getControl()).setText(stringValue); - } - } - } - fSettingValue = false; - } - - public void setItems(String[] newItems) { - if ((getControl() == null) || getControl().isDisposed()) { - Logger.log(Logger.ERROR, "Attempted to update item list for disposed cell editor"); //$NON-NLS-1$ - return; - } - - // keep selection if possible - Object previousSelectedValue = getValue(); - super.setItems(newItems); - if ((previousSelectedValue != null) && (getControl() instanceof CCombo)) { - for (int i = 0; i < newItems.length; i++) { - if (newItems[i].equals(previousSelectedValue)) { - setValue(previousSelectedValue); - } - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/properties/XMLPropertySource.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/properties/XMLPropertySource.java deleted file mode 100644 index 93ba73cb34..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/properties/XMLPropertySource.java +++ /dev/null @@ -1,839 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.properties; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Stack; - -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.views.properties.IPropertyDescriptor; -import org.eclipse.ui.views.properties.IPropertySheetEntry; -import org.eclipse.ui.views.properties.IPropertySource; -import org.eclipse.ui.views.properties.IPropertySource2; -import org.eclipse.ui.views.properties.TextPropertyDescriptor; -import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; -import org.eclipse.wst.sse.ui.views.properties.IPropertySourceExtension; -import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMNamespaceHelper; -import org.eclipse.wst.xml.core.internal.document.DocumentTypeAdapter; -import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.w3c.dom.Attr; -import org.w3c.dom.DOMException; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; - -/** - * An IPropertySource implementation for a JFace viewer used to display - * properties of DOM nodes. - */ -public class XMLPropertySource implements IPropertySource, IPropertySourceExtension, IPropertySource2 { - protected final static String CATEGORY_ATTRIBUTES = XMLUIMessages.XMLPropertySourceAdapter_0; - - private static final boolean fSetExpertFilter = false; - - /** - * derive categories from CMDataTypes; disabled until display strings can - * be planned - */ - private final static boolean fShouldDeriveCategories = false; - - private final static boolean fSortEnumeratedValues = true; - - /** - * Note: we want the default fCaseSensitive to be true, but, to avoid - * meaningless double initialization, we leave default here, and set in - * constructor only. - */ - private boolean fCaseSensitive; - private IPropertyDescriptor[] fDescriptors = null; - private Node fNode = null; - - private Stack fValuesBeingSet = new Stack(); - - public XMLPropertySource(INodeNotifier target) { - super(); - fNode = initNode(target); - fCaseSensitive = initCaseSensitive(fNode); - - } - - /** seperate method just to isolate error processing */ - private Node initNode(INodeNotifier target) { - Node node = null; - if (target instanceof Node) { - node = (Node) target; - } - else { - throw new IllegalArgumentException("XMLPropertySource is only for Nodes"); //$NON-NLS-1$ - } - return node; - } - - private boolean initCaseSensitive(Node node) { - // almost all tags are case senstive, except that old HTML - boolean caseSensitive = true; - DocumentTypeAdapter adapter = null; - if (node instanceof IDOMNode) { - adapter = getDocTypeFromDOMNode(node); - } - if (adapter != null) { - caseSensitive = (adapter.getTagNameCase() == DocumentTypeAdapter.STRICT_CASE); - } - return caseSensitive; - } - - /** - * by "internal spec" the DOCTYPE adapter is only available from Document - * Node - * - * @return {@link DocumentTypeAdapter} - */ - private DocumentTypeAdapter getDocTypeFromDOMNode(Node node) { - DocumentTypeAdapter adapter = null; - Document ownerDocument = node.getOwnerDocument(); - if (ownerDocument == null) { - // if ownerDocument is null, then fNode must be the Document Node - // [old, old comment] - // hmmmm, guess not. See - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=130233 - // guess this is used for many INodeNotifiers, not just XML. - // (and DTD's use IDOMNode? ... that doesn't sound quite right - // ... but, maybe a separate issue). - if (node instanceof Document) { - ownerDocument = (Document) node; - } - } - if (ownerDocument != null) { - adapter = (DocumentTypeAdapter) ((INodeNotifier) ownerDocument).getAdapterFor(DocumentTypeAdapter.class); - } - - return adapter; - } - - private String[] _getValidFixedStrings(CMAttributeDeclaration attrDecl, CMDataType helper) { - String attributeName = DOMNamespaceHelper.computeName(attrDecl, fNode, null); - List values = new ArrayList(1); - String impliedValue = helper.getImpliedValue(); - if (impliedValue != null) { - values.add(impliedValue); - } - boolean checkIfCurrentValueIsIncluded = ((fNode.getAttributes() != null) && (fNode.getAttributes().getNamedItem(attributeName) != null) && (fNode.getAttributes().getNamedItem(attributeName).getNodeValue() != null)); - if (checkIfCurrentValueIsIncluded) { - String currentValue = null; - currentValue = fNode.getAttributes().getNamedItem(attributeName).getNodeValue(); - if (!currentValue.equals(impliedValue)) { - values.add(currentValue); - } - } - String[] validStrings = new String[values.size()]; - validStrings = (String[]) values.toArray(validStrings); - return validStrings; - } - - private String[] _getValidStrings(CMAttributeDeclaration attrDecl, CMDataType valuesHelper) { - String attributeName = DOMNamespaceHelper.computeName(attrDecl, fNode, null); - List values = new ArrayList(1); - boolean currentValueKnown = false; - boolean checkIfCurrentValueIsKnown = ((fNode.getAttributes() != null) && (fNode.getAttributes().getNamedItem(attributeName) != null) && (fNode.getAttributes().getNamedItem(attributeName).getNodeValue() != null)); - String currentValue = null; - if (checkIfCurrentValueIsKnown) { - currentValue = fNode.getAttributes().getNamedItem(attributeName).getNodeValue(); - } - - if ((valuesHelper.getImpliedValueKind() == CMDataType.IMPLIED_VALUE_FIXED) && (valuesHelper.getImpliedValue() != null)) { - // FIXED value - currentValueKnown = (currentValue != null) && valuesHelper.getImpliedValue().equals(currentValue); - values.add(valuesHelper.getImpliedValue()); - } - else { - // ENUMERATED values - String[] valueStrings = null; - // valueStrings = valuesHelper.getEnumeratedValues(); - ModelQuery modelQuery = ModelQueryUtil.getModelQuery(fNode.getOwnerDocument()); - if ((modelQuery != null) && (fNode.getNodeType() == Node.ELEMENT_NODE)) { - valueStrings = modelQuery.getPossibleDataTypeValues((Element) fNode, attrDecl); - } - else { - valueStrings = attrDecl.getAttrType().getEnumeratedValues(); - } - if (valueStrings != null) { - for (int i = 0; i < valueStrings.length; i++) { - if (checkIfCurrentValueIsKnown && valueStrings[i].equals(currentValue)) { - currentValueKnown = true; - } - values.add(valueStrings[i]); - } - } - } - if ((valuesHelper.getImpliedValueKind() != CMDataType.IMPLIED_VALUE_NONE) && (valuesHelper.getImpliedValue() != null)) { - if (!values.contains(valuesHelper.getImpliedValue())) { - values.add(valuesHelper.getImpliedValue()); - } - } - - if (checkIfCurrentValueIsKnown && !currentValueKnown && (currentValue != null) && (currentValue.length() > 0)) { - values.add(currentValue); - } - String[] validStrings = new String[values.size()]; - validStrings = (String[]) values.toArray(validStrings); - return validStrings; - } - - private IPropertyDescriptor createDefaultPropertyDescriptor(String attributeName) { - return createDefaultPropertyDescriptor(attributeName, false); - } - - private IPropertyDescriptor createDefaultPropertyDescriptor(String attributeName, boolean hideOnFilter) { - // The descriptor class used here is also used in - // updatePropertyDescriptors() - TextPropertyDescriptor descriptor = new TextPropertyDescriptor(attributeName, attributeName); - descriptor.setCategory(getCategory(null)); - descriptor.setDescription(attributeName); - if (hideOnFilter && fSetExpertFilter) { - descriptor.setFilterFlags(new String[]{IPropertySheetEntry.FILTER_ID_EXPERT}); - } - return descriptor; - } - - /** - * Creates a property descriptor for an attribute with ENUMERATED values - - * if the value does not exist, an editable combo box is returned - if the - * value exists but is not one in the enumerated list of value, a combo - * box featuring the current and correct values is returned - if the value - * exists and it is a valid value, a combo box featuring the correct - * values with the current one visible is returned - */ - private IPropertyDescriptor createEnumeratedPropertyDescriptor(CMAttributeDeclaration attrDecl, CMDataType valuesHelper) { - // the displayName MUST be set - String attrName = DOMNamespaceHelper.computeName(attrDecl, fNode, null); - EnumeratedStringPropertyDescriptor descriptor = new EnumeratedStringPropertyDescriptor(attrName, attrName, _getValidStrings(attrDecl, valuesHelper)); - descriptor.setCategory(getCategory(attrDecl)); - descriptor.setDescription(attrName); - if ((attrDecl.getUsage() != CMAttributeDeclaration.REQUIRED) && fSetExpertFilter) { - descriptor.setFilterFlags(new String[]{IPropertySheetEntry.FILTER_ID_EXPERT}); - } - return descriptor; - } - - /** - * Creates a property descriptor for an attribute with a FIXED value - if - * the value does not exist, an editable combo box is returned - if the - * value exists but is not the fixed/default value, a combo box featuring - * the current and correct value is returned - if the value exists and it - * is the fixed/default value, no cell editor is provided "locking" the - * value in - */ - private IPropertyDescriptor createFixedPropertyDescriptor(CMAttributeDeclaration attrDecl, CMDataType helper) { - // the displayName MUST be set - String attrName = DOMNamespaceHelper.computeName(attrDecl, fNode, null); - EnumeratedStringPropertyDescriptor descriptor = new EnumeratedStringPropertyDescriptor(attrName, attrName, _getValidFixedStrings(attrDecl, helper)); - descriptor.setCategory(getCategory(attrDecl)); - descriptor.setDescription(DOMNamespaceHelper.computeName(attrDecl, fNode, null)); - return descriptor; - } - - protected IPropertyDescriptor createPropertyDescriptor(CMAttributeDeclaration attrDecl) { - IPropertyDescriptor descriptor = null; - CMDataType attrType = attrDecl.getAttrType(); - - if (attrType != null) { - // handle declarations that provide FIXED/ENUMERATED values - if ((attrType.getEnumeratedValues() != null) && (attrType.getEnumeratedValues().length > 0)) { - descriptor = createEnumeratedPropertyDescriptor(attrDecl, attrType); - } - else if (((attrDecl.getUsage() == CMAttributeDeclaration.FIXED) || (attrType.getImpliedValueKind() == CMDataType.IMPLIED_VALUE_FIXED)) && (attrType.getImpliedValue() != null)) { - descriptor = createFixedPropertyDescriptor(attrDecl, attrType); - } - else { - // plain text - descriptor = createTextPropertyDescriptor(attrDecl); - } - } - else { - // no extra information given - descriptor = createTextPropertyDescriptor(attrDecl); - } - return descriptor; - } - - /** - * Returns the current collection of property descriptors. - * - * @return all valid descriptors. - */ - private IPropertyDescriptor[] createPropertyDescriptors() { - CMNamedNodeMap attrMap = null; - CMElementDeclaration ed = getDeclaration(); - if (ed != null) { - CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(); - List nodes = ModelQueryUtil.getModelQuery(fNode.getOwnerDocument()).getAvailableContent((Element) fNode, ed, ModelQuery.INCLUDE_ATTRIBUTES); - for (int k = 0; k < nodes.size(); k++) { - CMNode cmnode = (CMNode) nodes.get(k); - if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) { - allAttributes.put(cmnode); - } - } - attrMap = allAttributes; - } - - List descriptorList = new ArrayList(); - List names = new ArrayList(); - IPropertyDescriptor descriptor; - - CMAttributeDeclaration attrDecl = null; - - // add descriptors for existing attributes - NamedNodeMap attributes = fNode.getAttributes(); - if (attributes != null) { - for (int i = 0; i < attributes.getLength(); i++) { - Attr attr = (Attr) attributes.item(i); - // if metainfo is present for this attribute, use the - // CMAttributeDeclaration to derive a descriptor - if (attrMap != null) { - String attrName = attr.getName(); - if (fCaseSensitive) { - attrDecl = (CMAttributeDeclaration) attrMap.getNamedItem(attrName); - } - else { - attrDecl = null; - for (int j = 0; j < attrMap.getLength(); j++) { - if (!fCaseSensitive && attrMap.item(j).getNodeName().equalsIgnoreCase(attrName)) { - attrDecl = (CMAttributeDeclaration) attrMap.item(j); - break; - } - } - } - } - // be consistent: if there's metainfo, use *that* as the - // descriptor ID - descriptor = null; - if (attrDecl != null) { - String attrName = DOMNamespaceHelper.computeName(attrDecl, fNode, null); - if (!names.contains(attrName)) { - descriptor = createPropertyDescriptor(attrDecl); - if (descriptor != null) - names.add(attrName); - } - } - else { - if (!names.contains(attr.getName())) { - descriptor = createDefaultPropertyDescriptor(attr.getName()); - if (descriptor != null) - names.add(attr.getName()); - } - } - if (descriptor != null) { - descriptorList.add(descriptor); - } - } - } - - // add descriptors from the metainfo that are not yet listed - if (attrMap != null) { - for (int i = 0; i < attrMap.getLength(); i++) { - attrDecl = (CMAttributeDeclaration) attrMap.item(i); - String attrName = DOMNamespaceHelper.computeName(attrDecl, fNode, null); - if (!names.contains(attrName)) { - IPropertyDescriptor holdDescriptor = createPropertyDescriptor(attrDecl); - if (holdDescriptor != null) { - names.add(attrName); - descriptorList.add(holdDescriptor); - } - } - } - } - - // add MQE-based descriptors - if (ed != null && fNode.getNodeType() == Node.ELEMENT_NODE) { - List nodes = ModelQueryUtil.getModelQuery(fNode.getOwnerDocument()).getAvailableContent((Element) fNode, ed, ModelQuery.INCLUDE_ATTRIBUTES); - for (int i = 0; i < nodes.size(); i++) { - CMNode node = (CMNode) nodes.get(i); - if (node.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) { - attrDecl = (CMAttributeDeclaration) node; - String attrName = DOMNamespaceHelper.computeName(attrDecl, fNode, null); - if (!names.contains(attrName)) { - IPropertyDescriptor holdDescriptor = createPropertyDescriptor(attrDecl); - if (holdDescriptor != null) { - names.add(attrName); - descriptorList.add(holdDescriptor); - } - } - } - } - } - - - IPropertyDescriptor[] descriptors = new IPropertyDescriptor[descriptorList.size()]; - for (int i = 0; i < descriptors.length; i++) { - descriptors[i] = (IPropertyDescriptor) descriptorList.get(i); - } - return descriptors; - } - - private IPropertyDescriptor createTextPropertyDescriptor(CMAttributeDeclaration attrDecl) { - String attrName = DOMNamespaceHelper.computeName(attrDecl, fNode, null); - TextPropertyDescriptor descriptor = new TextPropertyDescriptor(attrName, attrName); - descriptor.setCategory(getCategory(attrDecl)); - descriptor.setDescription(attrName); - if ((attrDecl.getUsage() != CMAttributeDeclaration.REQUIRED) && fSetExpertFilter) { - descriptor.setFilterFlags(new String[]{IPropertySheetEntry.FILTER_ID_EXPERT}); - } - return descriptor; - } - - private String getCategory(CMAttributeDeclaration attrDecl) { - if (attrDecl != null) { - if (attrDecl.supports("category")) { //$NON-NLS-1$ - return (String) attrDecl.getProperty("category"); //$NON-NLS-1$ - } - if (fShouldDeriveCategories && (attrDecl.getAttrType() != null) && (attrDecl.getAttrType().getNodeName() != null) && (attrDecl.getAttrType().getNodeName().length() > 0)) { - return attrDecl.getAttrType().getDataTypeName(); - } - } - return CATEGORY_ATTRIBUTES; - } - - private CMElementDeclaration getDeclaration() { - if ((fNode == null) || (fNode.getNodeType() != Node.ELEMENT_NODE)) { - return null; - } - ModelQuery modelQuery = ModelQueryUtil.getModelQuery(fNode.getOwnerDocument()); - if (modelQuery != null) { - return modelQuery.getCMElementDeclaration((Element) fNode); - } - return null; - } - - private Display getDisplay() { - - return PlatformUI.getWorkbench().getDisplay(); - } - - /** - * Returns a value for this Node that can be editted in a property sheet. - * - * @return a value that can be editted - */ - public Object getEditableValue() { - return null; - } - - /** - * Returns the current collection of property descriptors. - * - * @return all valid descriptors. - */ - public final IPropertyDescriptor[] getPropertyDescriptors() { - if ((fDescriptors == null) || (fDescriptors.length == 0)) { - fDescriptors = createPropertyDescriptors(); - } - else { - updatePropertyDescriptors(); - } - return fDescriptors; - } - - /** - * Returns the current value for the named property. - * - */ - public Object getPropertyValue(Object nameObject) { - String name = nameObject.toString(); - String returnedValue = null; - NamedNodeMap attrMap = fNode.getAttributes(); - if (attrMap != null) { - Node attribute = attrMap.getNamedItem(name); - if (attribute != null) { - if (attribute instanceof IDOMNode) { - returnedValue = ((IDOMNode) attribute).getValueSource(); - } - else { - returnedValue = attribute.getNodeValue(); - } - } - } - if (returnedValue == null) { - returnedValue = ""; //$NON-NLS-1$ - } - return returnedValue; - } - - private String[] getValidValues(CMAttributeDeclaration attrDecl) { - if (attrDecl == null) { - return new String[0]; - } - - String[] validValues = null; - CMDataType attrType = attrDecl.getAttrType(); - if (attrType != null) { - validValues = _getValidStrings(attrDecl, attrType); - if (fSortEnumeratedValues) { - Arrays.sort(validValues); - } - } - if (validValues == null) { - validValues = new String[0]; - } - return validValues; - } - - public boolean isPropertyRemovable(Object id) { - return true; - } - - public boolean isPropertyResettable(Object id) { - boolean resettable = false; - String property = id.toString(); - CMNamedNodeMap attrDecls = null; - - CMElementDeclaration ed = getDeclaration(); - if (ed != null) { - attrDecls = ed.getAttributes(); - CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(attrDecls); - List nodes = ModelQueryUtil.getModelQuery(fNode.getOwnerDocument()).getAvailableContent((Element) fNode, ed, ModelQuery.INCLUDE_ATTRIBUTES); - for (int k = 0; k < nodes.size(); k++) { - CMNode cmnode = (CMNode) nodes.get(k); - if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) { - allAttributes.put(cmnode); - } - } - attrDecls = allAttributes; - } - - if (attrDecls != null) { - CMAttributeDeclaration attrDecl = (CMAttributeDeclaration) attrDecls.getNamedItem(property); - if (attrDecl != null) { - if (attrDecl.getAttrType() != null) { - CMDataType helper = attrDecl.getAttrType(); - if ((helper.getImpliedValueKind() != CMDataType.IMPLIED_VALUE_NONE) && (helper.getImpliedValue() != null)) { - resettable = true; - } - } - } - } - return resettable; - } - - /** - * Returns whether the property value has changed from the default. - * - * @return <code>true</code> if the value of the specified property has - * changed from its original default value; <code>false</code> - * otherwise. - */ - public boolean isPropertySet(Object propertyObject) { - String property = propertyObject.toString(); - - NamedNodeMap attrMap = fNode.getAttributes(); - if (attrMap != null) { - return attrMap.getNamedItem(property) != null; - } - return false; - } - - /** - * Remove the given attribute from the Node - * - * @param propertyObject - */ - public void removeProperty(Object propertyObject) { - NamedNodeMap attrMap = fNode.getAttributes(); - if (attrMap != null) { - Node attribute = attrMap.getNamedItem(propertyObject.toString()); - if (attribute != null) { - try { - attrMap.removeNamedItem(propertyObject.toString()); - } - catch (DOMException e) { - if (e.code != DOMException.INVALID_MODIFICATION_ERR) { - Logger.logException(e); - } - } - } - } - } - - /** - * Resets the specified property's value to its default value. - * - */ - public void resetPropertyValue(Object propertyObject) { - String property = propertyObject.toString(); - CMNamedNodeMap attrDecls = null; - - CMElementDeclaration ed = getDeclaration(); - if (ed != null) { - attrDecls = ed.getAttributes(); - CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(attrDecls); - List nodes = ModelQueryUtil.getModelQuery(fNode.getOwnerDocument()).getAvailableContent((Element) fNode, ed, ModelQuery.INCLUDE_ATTRIBUTES); - for (int k = 0; k < nodes.size(); k++) { - CMNode cmnode = (CMNode) nodes.get(k); - if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) { - allAttributes.put(cmnode); - } - } - attrDecls = allAttributes; - } - - NamedNodeMap attrMap = fNode.getAttributes(); - if (attrDecls != null) { - CMAttributeDeclaration attrDecl = (CMAttributeDeclaration) attrDecls.getNamedItem(property); - String defValue = null; - if (attrDecl != null) { - if (attrDecl.getAttrType() != null) { - CMDataType helper = attrDecl.getAttrType(); - if ((helper.getImpliedValueKind() != CMDataType.IMPLIED_VALUE_NONE) && (helper.getImpliedValue() != null)) { - defValue = helper.getImpliedValue(); - } - } - } - if ((defValue != null) && (defValue.length() > 0)) { - ((Attr) attrMap.getNamedItem(property)).setValue(defValue); - } - else { - attrMap.removeNamedItem(property); - } - } - else { - attrMap.removeNamedItem(property); - } - } - - /** - * Sets the named property to the given value. - * - */ - public void setPropertyValue(Object nameObject, Object value) { - // Avoid cycling - can happen if a closing cell editor causes a - // refresh - // on the PropertySheet page and the setInput again asks the editor to - // close; besides, why apply the same value twice? - if (!fValuesBeingSet.isEmpty() && (fValuesBeingSet.peek() == nameObject)) { - return; - } - fValuesBeingSet.push(nameObject); - String name = nameObject.toString(); - String valueString = null; - if (value != null) { - valueString = value.toString(); - } - NamedNodeMap attrMap = fNode.getAttributes(); - try { - if (attrMap != null) { - Attr attr = (Attr) attrMap.getNamedItem(name); - if (attr != null) { - // EXISTING VALUE - // potential out of control loop if updating the value - // triggers a viewer update, forcing the - // active cell editor to save its value and causing the - // loop to continue - if ((attr.getValue() == null) || !attr.getValue().equals(valueString)) { - if (attr instanceof IDOMNode) { - ((IDOMNode) attr).setValueSource(valueString); - } - else { - attr.setValue(valueString); - } - } - } - else { - // NEW(?) value - if (value != null) { // never create an empty attribute - Attr newAttr = fNode.getOwnerDocument().createAttribute(name); - if (newAttr instanceof IDOMNode) { - ((IDOMNode) newAttr).setValueSource(valueString); - } - else { - newAttr.setValue(valueString); - } - attrMap.setNamedItem(newAttr); - } - } - } - else { - if (fNode instanceof Element) { - ((Element) fNode).setAttribute(name, valueString); - } - } - } - catch (DOMException e) { - Display d = getDisplay(); - if (d != null) { - d.beep(); - } - } - fValuesBeingSet.pop(); - } - - protected void updatePropertyDescriptors() { - if ((fDescriptors == null) || (fDescriptors.length == 0)) { - // Nothing to update - return; - } - - // List of all names encountered in the tag and defined by the element - List declaredNames = new ArrayList(); - // New descriptor list that will become fDescriptors after all - // processing is done - List descriptors = new ArrayList(); - // Names of the descriptors in the above List - List descriptorNames = new ArrayList(); - - // Update any descriptors derived from the metainfo - CMElementDeclaration ed = getDeclaration(); - CMNamedNodeMap attrMap = null; - if (ed != null) { - attrMap = ed.getAttributes(); - CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(attrMap); - List nodes = ModelQueryUtil.getModelQuery(fNode.getOwnerDocument()).getAvailableContent((Element) fNode, ed, ModelQuery.INCLUDE_ATTRIBUTES); - for (int k = 0; k < nodes.size(); k++) { - CMNode cmnode = (CMNode) nodes.get(k); - if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) { - allAttributes.put(cmnode); - } - } - attrMap = allAttributes; - } - // Update exiting descriptors; not added to the final list here - if (attrMap != null) { - // Update existing descriptor types based on metainfo - CMAttributeDeclaration attrDecl = null; - for (int i = 0; i < attrMap.getLength(); i++) { - attrDecl = (CMAttributeDeclaration) attrMap.item(i); - String attrName = DOMNamespaceHelper.computeName(attrDecl, fNode, null); - if (!declaredNames.contains(attrName)) { - declaredNames.add(attrName); - } - for (int j = 0; j < fDescriptors.length; j++) { - boolean sameName = (fCaseSensitive && fDescriptors[j].getId().equals(attrDecl.getNodeName())) || (!fCaseSensitive && attrDecl.getNodeName().equals(fDescriptors[j].getId().toString())); - if (sameName) { - String[] validValues = getValidValues(attrDecl); - // Update the descriptor for this - // CMAttributeDeclaration (only enumerated values get - // updated for now) - if (fDescriptors[j] instanceof EnumeratedStringPropertyDescriptor) { - ((EnumeratedStringPropertyDescriptor) fDescriptors[j]).updateValues(validValues); - } - // Replace with better descriptor - else if ((validValues != null) && (validValues.length > 0)) { - fDescriptors[j] = createPropertyDescriptor(attrDecl); - } - } - } - } - } - else { - // Update existing descriptors based on not having any metainfo - for (int j = 0; j < fDescriptors.length; j++) { - // Replace with basic descriptor - if (!(fDescriptors[j] instanceof TextPropertyDescriptor)) { - fDescriptors[j] = createDefaultPropertyDescriptor((String) fDescriptors[j].getId()); - } - } - } - - NamedNodeMap attributes = fNode.getAttributes(); - - // Remove descriptors for attributes that aren't present AND aren't - // known through metainfo, - // do this by only reusing existing descriptors for attributes that - // are present or declared - for (int i = 0; i < fDescriptors.length; i++) { - if (fDescriptors[i] != null) { - String descriptorName = fDescriptors[i].getId().toString(); - if ((declaredNames.contains(descriptorName) || (attributes.getNamedItem(descriptorName) != null)) && !descriptorNames.contains(descriptorName)) { - descriptorNames.add(descriptorName); - descriptors.add(fDescriptors[i]); - } - } - } - - // Add descriptors for declared attributes that don't already have one - if (attrMap != null) { - // Update existing descriptor types based on metainfo - CMAttributeDeclaration attrDecl = null; - for (int i = 0; i < attrMap.getLength(); i++) { - attrDecl = (CMAttributeDeclaration) attrMap.item(i); - String attrName = DOMNamespaceHelper.computeName(attrDecl, fNode, null); - if (fCaseSensitive) { - if (!descriptorNames.contains(attrName)) { - IPropertyDescriptor descriptor = createPropertyDescriptor(attrDecl); - if (descriptor != null) { - descriptorNames.add(attrName); - descriptors.add(descriptor); - } - } - } - else { - boolean exists = false; - for (int j = 0; j < descriptorNames.size(); j++) { - exists = (descriptorNames.get(j).toString().equalsIgnoreCase(attrName)) || exists; - } - if (!exists) { - descriptorNames.add(attrName); - IPropertyDescriptor descriptor = createPropertyDescriptor(attrDecl); - if (descriptor != null) { - descriptorNames.add(attrName); - descriptors.add(descriptor); - } - } - } - } - } - - // Add descriptors for existing attributes that don't already have one - if (attributes != null) { - for (int i = 0; i < attributes.getLength(); i++) { - Attr attr = (Attr) attributes.item(i); - String attrName = attr.getName(); - if (fCaseSensitive) { - if (!descriptorNames.contains(attrName)) { - descriptorNames.add(attrName); - descriptors.add(createDefaultPropertyDescriptor(attrName)); - } - } - else { - boolean exists = false; - for (int j = 0; j < descriptorNames.size(); j++) { - exists = (descriptorNames.get(j).toString().equalsIgnoreCase(attrName)) || exists; - } - if (!exists) { - descriptorNames.add(attrName); - descriptors.add(createDefaultPropertyDescriptor(attrName)); - } - } - } - } - - // Update fDescriptors - IPropertyDescriptor[] newDescriptors = new IPropertyDescriptor[descriptors.size()]; - for (int i = 0; i < newDescriptors.length; i++) { - newDescriptors[i] = (IPropertyDescriptor) descriptors.get(i); - } - fDescriptors = newDescriptors; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/provisional/IDOMSourceEditingTextTools.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/provisional/IDOMSourceEditingTextTools.java deleted file mode 100644 index a018b08f09..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/provisional/IDOMSourceEditingTextTools.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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.wst.xml.ui.internal.provisional; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.wst.sse.ui.internal.provisional.extensions.ISourceEditingTextTools; -import org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.NodeLocation; -import org.w3c.dom.Document; -import org.w3c.dom.Node; - -public interface IDOMSourceEditingTextTools extends ISourceEditingTextTools { - /** - * Returns a W3C DOM document - * - * @return Document object or <code>null</code> if corresponding - * document does not exist - */ - Document getDOMDocument(); - - /** - * Returns the W3C DOM Node at the given offset - * - * @param offset - * the offset within the IDocument - * @return a Node at that location, if one is present - * - * @throws BadLocationException - * for invalid offsets - */ - Node getNode(int offset) throws BadLocationException; - - /** - * Returns a NodeLocation object describing the position information of - * the Node's start and end tags. - * - * @param node - * @return The NodeLocation for this Node, null for unsupported Node - * instances. - */ - NodeLocation getNodeLocation(Node node); - - /** - * Returns the current server-side page language for the Document of the - * given Node. - * - * @return The server-side page language for this nodem null for Nodes - * within unsupported Documents. - */ - String getPageLanguage(Node node); - - /** - * Returns start offset of given Node. - * - * @param node - * w3c <code>Node</code> object to check - * @return the start offset or -1 for unsupported Nodes - */ - int getStartOffset(Node node); -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/provisional/XMLSourceEditingTextTools.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/provisional/XMLSourceEditingTextTools.java deleted file mode 100644 index 63a337edd1..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/provisional/XMLSourceEditingTextTools.java +++ /dev/null @@ -1,182 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.provisional; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.ui.IEditorPart; -import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter; -import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.ui.StructuredTextEditor; -import org.eclipse.wst.sse.ui.internal.StructuredTextViewer; -import org.eclipse.wst.sse.ui.internal.provisional.extensions.ISourceEditingTextTools; -import org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.NodeLocation; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMText; -import org.w3c.dom.Document; -import org.w3c.dom.Node; - -/** - * Implements ISourceEditingTextTools interface - */ -public class XMLSourceEditingTextTools implements IDOMSourceEditingTextTools, INodeAdapter { - - protected class NodeLocationImpl implements NodeLocation { - private IDOMNode node; - - public NodeLocationImpl(IDOMNode xmlnode) { - super(); - node = xmlnode; - } - - public int getEndTagEndOffset() { - if (node.getEndStructuredDocumentRegion() != null) { - return node.getEndStructuredDocumentRegion().getEndOffset(); - } - return -1; - } - - public int getEndTagStartOffset() { - if (node.getEndStructuredDocumentRegion() != null) { - return node.getEndStructuredDocumentRegion().getStartOffset(); - } - return -1; - } - - public int getStartTagEndOffset() { - if (node.getStartStructuredDocumentRegion() != null) { - return node.getStartStructuredDocumentRegion().getEndOffset(); - } - return -1; - } - - public int getStartTagStartOffset() { - if (node.getStartStructuredDocumentRegion() != null) { - return node.getStartStructuredDocumentRegion().getStartOffset(); - } - return -1; - } - } - - StructuredTextEditor fTextEditor = null; - - public int getCaretOffset() { - StructuredTextViewer stv = fTextEditor.getTextViewer(); - if ((stv != null) && (stv.getTextWidget() != null) && !stv.getTextWidget().isDisposed()) { - return stv.widgetOffset2ModelOffset(stv.getTextWidget().getCaretOffset()); - } - return 0; - } - - public IDocument getDocument() { - return fTextEditor.getDocumentProvider().getDocument(fTextEditor.getEditorInput()); - } - - public Document getDOMDocument() { - return (Document) fTextEditor.getModel().getAdapter(Document.class); - } - - /* - * If similar function is needed, composite it around the text editor's - * instance. Removed also because it returns an alread-released model - * - * public Document getDOMDocument(IMarker marker) { if (marker == null) - * return null; - * - * IResource res = marker.getResource(); if (res == null || !(res - * instanceof IFile)) return null; - * - * IModelManager mm = StructuredModelManager.getModelManager(); - * IStructuredModel model = null; try { model = - * mm.getExistingModelForRead((IFile) res); if (model == null || !(model - * instanceof IDOMModel)) return null; - * - * return ((IDOMModel) model).getDocument(); } finally { if (model != - * null) model.releaseFromRead(); } } - */ - - public IEditorPart getEditorPart() { - return fTextEditor.getEditorPart(); - } - - public Node getNode(int offset) throws BadLocationException { - Node node = null; - if ((0 <= offset) && (offset <= getDocument().getLength())) { - node = (Node) fTextEditor.getModel().getIndexedRegion(offset); - } - else { - throw new BadLocationException(); - } - return node; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.extensions.SourceEditingTextTools#getNodeLocation(org.w3c.dom.Node) - */ - public NodeLocation getNodeLocation(Node node) { - if ((node.getNodeType() == Node.ELEMENT_NODE) && (node instanceof IDOMNode)) { - return new NodeLocationImpl((IDOMNode) node); - } - return null; - } - - public String getPageLanguage(Node node) { - return ""; //$NON-NLS-1$ - } - - public ITextSelection getSelection() { - return (ITextSelection) fTextEditor.getSelectionProvider().getSelection(); - } - - /** - * IExtendedMarkupEditor method - */ - // public List getSelectedNodes() { - // ViewerSelectionManager vsm = getViewerSelectionManager(); - // return (vsm != null) ? vsm.getSelectedNodes() : null; - // } - public int getStartOffset(Node node) { - if ((node == null) || !(node instanceof IDOMText)) { - return -1; - } - - IStructuredDocumentRegion fnode = ((IDOMText) node).getFirstStructuredDocumentRegion(); - return fnode.getStartOffset(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.core.core.INodeAdapter#isAdapterForType(java.lang.Object) - */ - public boolean isAdapterForType(Object type) { - return ISourceEditingTextTools.class.equals(type); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.core.core.INodeAdapter#notifyChanged(org.eclipse.wst.sse.core.core.INodeNotifier, - * int, java.lang.Object, java.lang.Object, java.lang.Object, int) - */ - public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) { - } - - public void setTextEditor(StructuredTextEditor editor) { - fTextEditor = editor; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/registry/AdapterFactoryProviderForXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/registry/AdapterFactoryProviderForXML.java deleted file mode 100644 index 3794a1782e..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/registry/AdapterFactoryProviderForXML.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.registry; - -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.wst.sse.core.internal.ltk.modelhandler.IDocumentTypeHandler; -import org.eclipse.wst.sse.core.internal.model.FactoryRegistry; -import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.core.internal.util.Assert; -import org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapter; -import org.eclipse.wst.sse.ui.internal.provisional.registry.AdapterFactoryProvider; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.modelhandler.ModelHandlerForXML; -import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.ui.internal.DOMObserver; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.internal.contentoutline.JFaceNodeAdapterFactory; -import org.eclipse.wst.xml.ui.internal.preferences.XMLUIPreferenceNames; - -/** - * - */ -public class AdapterFactoryProviderForXML implements AdapterFactoryProvider { - - /* - * @see AdapterFactoryProvider#addAdapterFactories(IStructuredModel) - */ - public void addAdapterFactories(IStructuredModel structuredModel) { - - // add the normal content based factories to model's registry - addContentBasedFactories(structuredModel); - } - - protected void addContentBasedFactories(IStructuredModel structuredModel) { - FactoryRegistry factoryRegistry = structuredModel.getFactoryRegistry(); - Assert.isNotNull(factoryRegistry, "Program Error: client caller must ensure model has factory registry"); //$NON-NLS-1$ - INodeAdapterFactory factory = null; - - factory = factoryRegistry.getFactoryFor(IJFaceNodeAdapter.class); - if (factory == null) { - factory = new JFaceNodeAdapterFactory(); - factoryRegistry.addFactory(factory); - } - - // cs... added for inferred grammar support - // - if (structuredModel != null) { - ModelQuery modelQuery = ModelQueryUtil.getModelQuery(structuredModel); - if (modelQuery != null) { - CMDocumentManager documentManager = modelQuery.getCMDocumentManager(); - if (documentManager != null) { - IPreferenceStore store = XMLUIPlugin.getDefault().getPreferenceStore(); - boolean useInferredGrammar = (store != null) ? store.getBoolean(XMLUIPreferenceNames.USE_INFERRED_GRAMMAR) : true; - - documentManager.setPropertyEnabled(CMDocumentManager.PROPERTY_ASYNC_LOAD, true); - documentManager.setPropertyEnabled(CMDocumentManager.PROPERTY_AUTO_LOAD, false); - documentManager.setPropertyEnabled(CMDocumentManager.PROPERTY_USE_CACHED_RESOLVED_URI, true); - DOMObserver domObserver = new DOMObserver(structuredModel); - domObserver.setGrammarInferenceEnabled(useInferredGrammar); - domObserver.init(); - } - } - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.internal.provisional.registry.AdapterFactoryProvider#isFor(org.eclipse.wst.sse.core.internal.ltk.modelhandler.IDocumentTypeHandler) - */ - public boolean isFor(IDocumentTypeHandler contentTypeDescription) { - return (contentTypeDescription instanceof ModelHandlerForXML); - } - - public void reinitializeFactories(IStructuredModel structuredModel) { - // nothing to do, since no embedded type - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/search/XMLFindOccurrencesActionDelegate.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/search/XMLFindOccurrencesActionDelegate.java deleted file mode 100644 index 84f2ec934e..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/search/XMLFindOccurrencesActionDelegate.java +++ /dev/null @@ -1,34 +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.wst.xml.ui.internal.search; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.wst.sse.ui.internal.search.FindOccurrencesActionDelegate; - -/** - * Sets up FindOccurrencesActionDelegate for xml find occurrences processors - */ -public class XMLFindOccurrencesActionDelegate extends FindOccurrencesActionDelegate { - private List fProcessors; - - protected List getProcessors() { - if (fProcessors == null) { - fProcessors = new ArrayList(); - XMLFindOccurrencesProcessor htmlProcessor = new XMLFindOccurrencesProcessor(); - fProcessors.add(htmlProcessor); - } - return fProcessors; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/search/XMLFindOccurrencesProcessor.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/search/XMLFindOccurrencesProcessor.java deleted file mode 100644 index 6b12fec560..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/search/XMLFindOccurrencesProcessor.java +++ /dev/null @@ -1,31 +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.wst.xml.ui.internal.search; - -import org.eclipse.wst.sse.ui.internal.search.FindOccurrencesProcessor; -import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; -import org.eclipse.wst.xml.core.text.IXMLPartitions; - -/** - * Configures a FindOccurrencesProcessor with XML partitions and regions - */ -public class XMLFindOccurrencesProcessor extends FindOccurrencesProcessor { - - protected String[] getPartitionTypes() { - return new String[]{IXMLPartitions.XML_DEFAULT}; - } - - protected String[] getRegionTypes() { - return new String[]{DOMRegionContext.XML_TAG_NAME, DOMRegionContext.XML_TAG_ATTRIBUTE_NAME, DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE}; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/selection/StructuredSelectEnclosingXMLActionDelegate.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/selection/StructuredSelectEnclosingXMLActionDelegate.java deleted file mode 100644 index 258be52d4f..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/selection/StructuredSelectEnclosingXMLActionDelegate.java +++ /dev/null @@ -1,72 +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.wst.xml.ui.internal.selection; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.text.Region; -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.sse.ui.internal.selection.StructuredSelectActionDelegate; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.w3c.dom.Node; - -public class StructuredSelectEnclosingXMLActionDelegate extends StructuredSelectActionDelegate { - - protected IndexedRegion getCursorIndexedRegion(IDocument document, ITextSelection textSelection) { - IndexedRegion indexedRegion = null; - - indexedRegion = getIndexedRegion(document, textSelection.getOffset()); - - return indexedRegion; - } - - protected Region getNewSelectionRegion(IndexedRegion indexedRegion, ITextSelection textSelection) { - Region newRegion = null; - if (indexedRegion instanceof Node) { - Node cursorNode = (Node) indexedRegion; - - // use parent node for empty text node - if ((cursorNode.getNodeType() == Node.TEXT_NODE) && (cursorNode.getNodeValue().trim().length() == 0)) { - cursorNode = cursorNode.getParentNode(); - - if (cursorNode instanceof IndexedRegion) { - indexedRegion = (IndexedRegion) cursorNode; - } - } - - Region cursorNodeRegion = new Region(indexedRegion.getStartOffset(), indexedRegion.getEndOffset() - indexedRegion.getStartOffset()); - - if ((cursorNodeRegion.getOffset() >= textSelection.getOffset()) && (cursorNodeRegion.getOffset() <= textSelection.getOffset() + textSelection.getLength()) && (cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() >= textSelection.getOffset()) && (cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() <= textSelection.getOffset() + textSelection.getLength())) { - Node newNode = cursorNode.getParentNode(); - - if (newNode instanceof IndexedRegion) { - IndexedRegion newIndexedRegion = (IndexedRegion) newNode; - newRegion = new Region(newIndexedRegion.getStartOffset(), newIndexedRegion.getEndOffset() - newIndexedRegion.getStartOffset()); - } - } - else { - newRegion = cursorNodeRegion; - } - } - return newRegion; - } - - public void init(IAction action) { - if (action != null) { - action.setText(XMLUIMessages.StructureSelectEnclosing_label); - action.setToolTipText(XMLUIMessages.StructureSelectEnclosing_tooltip); - action.setDescription(XMLUIMessages.StructureSelectEnclosing_description); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/selection/StructuredSelectNextXMLActionDelegate.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/selection/StructuredSelectNextXMLActionDelegate.java deleted file mode 100644 index f5088c3122..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/selection/StructuredSelectNextXMLActionDelegate.java +++ /dev/null @@ -1,109 +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.wst.xml.ui.internal.selection; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.text.Region; -import org.eclipse.jface.text.TextSelection; -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.sse.ui.internal.selection.StructuredSelectActionDelegate; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.w3c.dom.Node; - -public class StructuredSelectNextXMLActionDelegate extends StructuredSelectActionDelegate { - - protected IndexedRegion getCursorIndexedRegion(IDocument document, ITextSelection textSelection) { - int offset = textSelection.getOffset() + textSelection.getLength() - 1; - if (offset < 0) { - offset = 0; - } - - IndexedRegion indexedRegion = null; - - indexedRegion = getIndexedRegion(document, offset); - - return indexedRegion; - } - - protected Region getNewSelectionRegion(IndexedRegion indexedRegion, ITextSelection textSelection) { - Region newRegion = null; - if (indexedRegion instanceof Node) { - Node cursorNode = (Node) indexedRegion; - - // use parent node for empty text node - if ((cursorNode.getNodeType() == Node.TEXT_NODE) && (cursorNode.getNodeValue().trim().length() == 0)) { - cursorNode = cursorNode.getParentNode(); - - if (cursorNode instanceof IndexedRegion) { - indexedRegion = (IndexedRegion) cursorNode; - } - } - - Region cursorNodeRegion = new Region(indexedRegion.getStartOffset(), indexedRegion.getEndOffset() - indexedRegion.getStartOffset()); - int currentOffset = textSelection.getOffset(); - int currentEndOffset = currentOffset + textSelection.getLength(); - if ((cursorNodeRegion.getOffset() >= currentOffset) && (cursorNodeRegion.getOffset() <= currentEndOffset) && (cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() >= currentOffset) && (cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() <= currentEndOffset)) { - newRegion = getNewSelectionRegion2(indexedRegion, textSelection); - } - else { - newRegion = cursorNodeRegion; - } - } - return newRegion; - } - - public void init(IAction action) { - if (action != null) { - action.setText(XMLUIMessages.StructureSelectNext_label); - action.setToolTipText(XMLUIMessages.StructureSelectNext_tooltip); - action.setDescription(XMLUIMessages.StructureSelectNext_description); - } - } - - /** - * This method was separated out from getNewSelectionRegion2 because the - * code in here is allowed to be called recursively. - * - * @param indexedRegion - * @param textSelection - * @return new region to select or null if none - */ - private Region getNewSelectionRegion2(IndexedRegion indexedRegion, ITextSelection textSelection) { - Region newRegion = null; - if (indexedRegion instanceof Node) { - Node node = (Node) indexedRegion; - Node newNode = node.getNextSibling(); - if (newNode == null) { - newNode = node.getParentNode(); - - if (newNode instanceof IndexedRegion) { - IndexedRegion newIndexedRegion = (IndexedRegion) newNode; - newRegion = new Region(newIndexedRegion.getStartOffset(), newIndexedRegion.getEndOffset() - newIndexedRegion.getStartOffset()); - } - } - else { - if (newNode instanceof IndexedRegion) { - IndexedRegion newIndexedRegion = (IndexedRegion) newNode; - newRegion = new Region(textSelection.getOffset(), newIndexedRegion.getEndOffset() - textSelection.getOffset()); - - if (newNode.getNodeType() == Node.TEXT_NODE) { - newRegion = getNewSelectionRegion2(newIndexedRegion, new TextSelection(newRegion.getOffset(), newRegion.getLength())); - } - } - } - } - return newRegion; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/selection/StructuredSelectPreviousXMLActionDelegate.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/selection/StructuredSelectPreviousXMLActionDelegate.java deleted file mode 100644 index 8939c32b4d..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/selection/StructuredSelectPreviousXMLActionDelegate.java +++ /dev/null @@ -1,88 +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.wst.xml.ui.internal.selection; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.text.Region; -import org.eclipse.jface.text.TextSelection; -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.sse.ui.internal.selection.StructuredSelectActionDelegate; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.w3c.dom.Node; - -public class StructuredSelectPreviousXMLActionDelegate extends StructuredSelectActionDelegate { - - protected IndexedRegion getCursorIndexedRegion(IDocument document, ITextSelection textSelection) { - IndexedRegion indexedRegion = null; - - indexedRegion = getIndexedRegion(document, textSelection.getOffset()); - - return indexedRegion; - } - - protected Region getNewSelectionRegion(IndexedRegion indexedRegion, ITextSelection textSelection) { - Region newRegion = null; - if (indexedRegion instanceof Node) { - Node cursorNode = (Node) indexedRegion; - - // use parent node for empty text node - if ((cursorNode.getNodeType() == Node.TEXT_NODE) && (cursorNode.getNodeValue().trim().length() == 0)) { - cursorNode = cursorNode.getParentNode(); - - if (cursorNode instanceof IndexedRegion) { - indexedRegion = (IndexedRegion) cursorNode; - } - } - - Region cursorNodeRegion = new Region(indexedRegion.getStartOffset(), indexedRegion.getEndOffset() - indexedRegion.getStartOffset()); - - if ((cursorNodeRegion.getOffset() >= textSelection.getOffset()) && (cursorNodeRegion.getOffset() <= textSelection.getOffset() + textSelection.getLength()) && (cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() >= textSelection.getOffset()) && (cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() <= textSelection.getOffset() + textSelection.getLength())) { - Node newNode = cursorNode.getPreviousSibling(); - if (newNode == null) { - newNode = cursorNode.getParentNode(); - - if (newNode instanceof IndexedRegion) { - IndexedRegion newIndexedRegion = (IndexedRegion) newNode; - newRegion = new Region(newIndexedRegion.getStartOffset(), newIndexedRegion.getEndOffset() - newIndexedRegion.getStartOffset()); - } - } - else { - if (newNode instanceof IndexedRegion) { - IndexedRegion newIndexedRegion = (IndexedRegion) newNode; - newRegion = new Region(newIndexedRegion.getStartOffset(), textSelection.getOffset() + textSelection.getLength() - newIndexedRegion.getStartOffset()); - - if (newNode.getNodeType() == Node.TEXT_NODE) { - newRegion = getNewSelectionRegion(newIndexedRegion, new TextSelection(newRegion.getOffset(), newRegion.getLength())); - } - } - } - - } - else { - newRegion = cursorNodeRegion; - } - } - return newRegion; - } - - public void init(IAction action) { - if (action != null) { - action.setText(XMLUIMessages.StructureSelectPrevious_label); - action.setToolTipText(XMLUIMessages.StructureSelectPrevious_tooltip); - action.setDescription(XMLUIMessages.StructureSelectPrevious_description); - } - } - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/style/IStyleConstantsXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/style/IStyleConstantsXML.java deleted file mode 100644 index 79055b6c95..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/style/IStyleConstantsXML.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * Benjamin Muskalla, b.muskalla@gmx.net - [158660] character entities should have their own syntax highlighting preference - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.style; - -/** - * Contains the symbolic name of styles used by LineStyleProvider, - * ColorManager, and any others who may be interested - */ -public interface IStyleConstantsXML { - public static final String BACKGROUND = "background"; //$NON-NLS-1$ - public static final String CDATA_BORDER = "cdataBorder";//$NON-NLS-1$ - public static final String CDATA_TEXT = "cdataText";//$NON-NLS-1$ - public static final String COMMENT_BORDER = "commentBorder";//$NON-NLS-1$ - public static final String COMMENT_TEXT = "commentText";//$NON-NLS-1$ - public static final String DECL_BORDER = "declBoder";//$NON-NLS-1$ - public static final String DOCTYPE_EXTERNAL_ID = "doctypeExternalId";//$NON-NLS-1$ - public static final String DOCTYPE_EXTERNAL_ID_PUBREF = "doctypeExternalPubref";//$NON-NLS-1$ - public static final String DOCTYPE_EXTERNAL_ID_SYSREF = "doctypeExtrenalSysref";//$NON-NLS-1$ - public static final String DOCTYPE_NAME = "doctypeName";//$NON-NLS-1$ - - public static final String FOREGROUND = "foreground"; //$NON-NLS-1$ - public static final String PI_BORDER = "piBorder";//$NON-NLS-1$ - public static final String PI_CONTENT = "piContent";//$NON-NLS-1$ - - public static final String TAG_ATTRIBUTE_EQUALS = "tagAttributeEquals"; //$NON-NLS-1$ - public static final String TAG_ATTRIBUTE_NAME = "tagAttributeName";//$NON-NLS-1$ - public static final String TAG_ATTRIBUTE_VALUE = "tagAttributeValue";//$NON-NLS-1$ - public static final String TAG_BORDER = "tagBorder";//$NON-NLS-1$ - public static final String TAG_NAME = "tagName";//$NON-NLS-1$ - public static final String XML_CONTENT = "xmlContent";//$NON-NLS-1$ - public static final String ENTITY_REFERENCE = "entityReference";//$NON-NLS-1$ -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/style/LineStyleProviderForXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/style/LineStyleProviderForXML.java deleted file mode 100644 index 2584548982..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/style/LineStyleProviderForXML.java +++ /dev/null @@ -1,209 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * Benjamin Muskalla, b.muskalla@gmx.net - [158660] character entities should have their own syntax highlighting preference - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.style; - -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.text.TextAttribute; -import org.eclipse.jface.util.PropertyChangeEvent; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.sse.ui.internal.provisional.style.AbstractLineStyleProvider; -import org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider; -import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; - -public class LineStyleProviderForXML extends AbstractLineStyleProvider implements LineStyleProvider { - public LineStyleProviderForXML() { - super(); - } - - protected TextAttribute getAttributeFor(ITextRegion region) { - /** - * a method to centralize all the "format rules" for regions - * specifically associated for how to "open" the region. - */ - // not sure why this is coming through null, but just to catch it - if (region == null) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.CDATA_TEXT); - } - String type = region.getType(); - if ((type == DOMRegionContext.XML_CONTENT) || (type == DOMRegionContext.XML_DOCTYPE_INTERNAL_SUBSET)) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.XML_CONTENT); - } - else if ((type == DOMRegionContext.XML_TAG_OPEN) || (type == DOMRegionContext.XML_END_TAG_OPEN) || (type == DOMRegionContext.XML_TAG_CLOSE) || (type == DOMRegionContext.XML_EMPTY_TAG_CLOSE)) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.TAG_BORDER); - } - else if ((type == DOMRegionContext.XML_CDATA_OPEN) || (type == DOMRegionContext.XML_CDATA_CLOSE)) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.CDATA_BORDER); - } - else if (type == DOMRegionContext.XML_CDATA_TEXT) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.CDATA_TEXT); - } - else if (type == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.TAG_ATTRIBUTE_NAME); - } - else if (type == DOMRegionContext.XML_DOCTYPE_DECLARATION) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.TAG_NAME); - } - else if (type == DOMRegionContext.XML_TAG_NAME) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.TAG_NAME); - } - else if ((type == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE)) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.TAG_ATTRIBUTE_VALUE); - } - else if (type == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.TAG_ATTRIBUTE_EQUALS); - } - else if ((type == DOMRegionContext.XML_COMMENT_OPEN) || (type == DOMRegionContext.XML_COMMENT_CLOSE)) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.COMMENT_BORDER); - } - else if (type == DOMRegionContext.XML_COMMENT_TEXT) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.COMMENT_TEXT); - } - else if (type == DOMRegionContext.XML_DOCTYPE_NAME) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.DOCTYPE_NAME); - } - else if ((type == DOMRegionContext.XML_CHAR_REFERENCE) || (type == DOMRegionContext.XML_ENTITY_REFERENCE) || (type == DOMRegionContext.XML_PE_REFERENCE)) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.ENTITY_REFERENCE); - } - else if (type == DOMRegionContext.XML_PI_CONTENT) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.PI_CONTENT); - } - else if ((type == DOMRegionContext.XML_PI_OPEN) || (type == DOMRegionContext.XML_PI_CLOSE)) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.PI_BORDER); - } - else if ((type == DOMRegionContext.XML_DECLARATION_OPEN) || (type == DOMRegionContext.XML_DECLARATION_CLOSE)) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.DECL_BORDER); - } - else if (type == DOMRegionContext.XML_DOCTYPE_EXTERNAL_ID_SYSREF) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_SYSREF); - } - else if (type == DOMRegionContext.XML_DOCTYPE_EXTERNAL_ID_PUBREF) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_PUBREF); - } - else if ((type == DOMRegionContext.XML_DOCTYPE_EXTERNAL_ID_PUBLIC) || (type == DOMRegionContext.XML_DOCTYPE_EXTERNAL_ID_SYSTEM)) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID); - } - else if (type == DOMRegionContext.UNDEFINED) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.CDATA_TEXT); - } - else if (type == DOMRegionContext.WHITE_SPACE) { - // white space is normall not on its own ... but when it is, we'll - // treat as content - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.XML_CONTENT); - } - else { - // default, return null to signal "not handled" - // in which case, other factories should be tried - return null; - } - } - - protected IPreferenceStore getColorPreferences() { - return XMLUIPlugin.getDefault().getPreferenceStore(); - } - - protected void handlePropertyChange(PropertyChangeEvent event) { - String styleKey = null; - - if (event != null) { - String prefKey = event.getProperty(); - // check if preference changed is a style preference - if (IStyleConstantsXML.TAG_NAME.equals(prefKey)) { - styleKey = IStyleConstantsXML.TAG_NAME; - } - else if (IStyleConstantsXML.TAG_BORDER.equals(prefKey)) { - styleKey = IStyleConstantsXML.TAG_BORDER; - } - else if (IStyleConstantsXML.TAG_ATTRIBUTE_NAME.equals(prefKey)) { - styleKey = IStyleConstantsXML.TAG_ATTRIBUTE_NAME; - } - else if (IStyleConstantsXML.TAG_ATTRIBUTE_VALUE.equals(prefKey)) { - styleKey = IStyleConstantsXML.TAG_ATTRIBUTE_VALUE; - } - else if (IStyleConstantsXML.TAG_ATTRIBUTE_EQUALS.equals(prefKey)) { - styleKey = IStyleConstantsXML.TAG_ATTRIBUTE_EQUALS; - } - else if (IStyleConstantsXML.COMMENT_BORDER.equals(prefKey)) { - styleKey = IStyleConstantsXML.COMMENT_BORDER; - } - else if (IStyleConstantsXML.COMMENT_TEXT.equals(prefKey)) { - styleKey = IStyleConstantsXML.COMMENT_TEXT; - } - else if (IStyleConstantsXML.ENTITY_REFERENCE.equals(prefKey)) { - styleKey = IStyleConstantsXML.ENTITY_REFERENCE; - } - else if (IStyleConstantsXML.CDATA_BORDER.equals(prefKey)) { - styleKey = IStyleConstantsXML.CDATA_BORDER; - } - else if (IStyleConstantsXML.CDATA_TEXT.equals(prefKey)) { - styleKey = IStyleConstantsXML.CDATA_TEXT; - } - else if (IStyleConstantsXML.DECL_BORDER.equals(prefKey)) { - styleKey = IStyleConstantsXML.DECL_BORDER; - } - else if (IStyleConstantsXML.DOCTYPE_EXTERNAL_ID.equals(prefKey)) { - styleKey = IStyleConstantsXML.DOCTYPE_EXTERNAL_ID; - } - else if (IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_PUBREF.equals(prefKey)) { - styleKey = IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_PUBREF; - } - else if (IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_SYSREF.equals(prefKey)) { - styleKey = IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_SYSREF; - } - else if (IStyleConstantsXML.DOCTYPE_NAME.equals(prefKey)) { - styleKey = IStyleConstantsXML.DOCTYPE_NAME; - } - else if (IStyleConstantsXML.PI_CONTENT.equals(prefKey)) { - styleKey = IStyleConstantsXML.PI_CONTENT; - } - else if (IStyleConstantsXML.PI_BORDER.equals(prefKey)) { - styleKey = IStyleConstantsXML.PI_BORDER; - } - else if (IStyleConstantsXML.XML_CONTENT.equals(prefKey)) { - styleKey = IStyleConstantsXML.XML_CONTENT; - } - } - - if (styleKey != null) { - // overwrite style preference with new value - addTextAttribute(styleKey); - super.handlePropertyChange(event); - } - } - - /** - * Loads text attributes into map. Make sure map is cleared before calling - * this. - */ - protected void loadColors() { - addTextAttribute(IStyleConstantsXML.TAG_NAME); - addTextAttribute(IStyleConstantsXML.TAG_BORDER); - addTextAttribute(IStyleConstantsXML.TAG_ATTRIBUTE_NAME); - addTextAttribute(IStyleConstantsXML.TAG_ATTRIBUTE_VALUE); - addTextAttribute(IStyleConstantsXML.TAG_ATTRIBUTE_EQUALS); - addTextAttribute(IStyleConstantsXML.COMMENT_BORDER); - addTextAttribute(IStyleConstantsXML.COMMENT_TEXT); - addTextAttribute(IStyleConstantsXML.CDATA_BORDER); - addTextAttribute(IStyleConstantsXML.CDATA_TEXT); - addTextAttribute(IStyleConstantsXML.DECL_BORDER); - addTextAttribute(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID); - addTextAttribute(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_PUBREF); - addTextAttribute(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_SYSREF); - addTextAttribute(IStyleConstantsXML.DOCTYPE_NAME); - addTextAttribute(IStyleConstantsXML.PI_CONTENT); - addTextAttribute(IStyleConstantsXML.PI_BORDER); - addTextAttribute(IStyleConstantsXML.XML_CONTENT); - addTextAttribute(IStyleConstantsXML.ENTITY_REFERENCE); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/taginfo/MarkupTagInfoProvider.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/taginfo/MarkupTagInfoProvider.java deleted file mode 100644 index 47513eff5b..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/taginfo/MarkupTagInfoProvider.java +++ /dev/null @@ -1,178 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.taginfo; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocumentation; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList; -import org.eclipse.wst.xml.core.internal.contentmodel.util.CMDescriptionBuilder; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; - -/** - * Provides basic tag information such as element/attribute name, data type, - * and tag info/documentation for CMNodes. Uses HTML to enhance presentation. - */ -public class MarkupTagInfoProvider { - protected final static String BOLD_END = "</b>"; //$NON-NLS-1$ - protected final static String BOLD_START = "<b>"; //$NON-NLS-1$ - protected final static String HEADING_END = "</h5>"; //$NON-NLS-1$ - protected final static String HEADING_START = "<h5>"; //$NON-NLS-1$ - protected final static String LIST_BEGIN = "<ul>"; //$NON-NLS-1$ - protected final static String LIST_ELEMENT = "<li>"; //$NON-NLS-1$ - protected final static String NEW_LINE = "<dl>"; //$NON-NLS-1$ - protected final static String PARAGRAPH_END = "</p>"; //$NON-NLS-1$ - protected final static String PARAGRAPH_START = "<p>"; //$NON-NLS-1$ - protected final static String SPACE = " "; //$NON-NLS-1$ - - /** - * Returns basic tag information for display given a CMNode - * - * @return String - */ - public String getInfo(CMNode node) { - if (node == null) { - return null; - } - StringBuffer sb = new StringBuffer(); - // we assume that if there is tagInfo present, only display tagInfo - printTagInfo(sb, node); - - // no tagInfo present, so try to display tag description - if (sb.length() == 0) { - printDescription(sb, node); - } - - // no tag description present either, so display default info - if (sb.length() == 0) { - printDefaultInfo(node, sb); - } - - return sb.toString(); - } - - /** - * Adds dataType's data type information, including enumerated type values - * to string buffer, sb - * - */ - protected void printDataTypeInfo(StringBuffer sb, CMDataType dataType) { - String dataTypeName = dataType.getNodeName(); - if ((dataTypeName != null) && (dataTypeName.length() > 0)) { - sb.append(PARAGRAPH_START + BOLD_START + XMLUIMessages.Data_Type____4 + SPACE + BOLD_END); - sb.append(dataTypeName); - sb.append(PARAGRAPH_END); - } - String[] enumeratedValue = dataType.getEnumeratedValues(); - if ((enumeratedValue != null) && (enumeratedValue.length > 0)) { - sb.append(PARAGRAPH_START + BOLD_START + XMLUIMessages.Enumerated_Values____5 + SPACE + BOLD_END); - sb.append(LIST_BEGIN); - for (int i = 0; i < enumeratedValue.length; i++) { - sb.append(LIST_ELEMENT + enumeratedValue[i]); - } - sb.append(PARAGRAPH_END); - } - } - - /** - * Adds the default info (element name, content model, data type) of - * CMNode to the string buffer, sb - * - */ - protected void printDefaultInfo(CMNode node, StringBuffer sb) { - { - - if (node.getNodeType() == CMNode.ELEMENT_DECLARATION) { - CMElementDeclaration ed = (CMElementDeclaration) node; - sb.append(PARAGRAPH_START + BOLD_START + XMLUIMessages.Element____1 + SPACE + BOLD_END); - sb.append(node.getNodeName()); - sb.append(PARAGRAPH_END); - printDocumentation(sb, node); - if (ed.getContentType() == CMElementDeclaration.PCDATA) { - CMDataType dataType = ed.getDataType(); - if (dataType != null) { - printDataTypeInfo(sb, dataType); - } - } - else { - CMDescriptionBuilder builder = new CMDescriptionBuilder(); - String description = builder.buildDescription(node); - if ((description != null) && (description.length() > 0)) { - sb.append(PARAGRAPH_START + BOLD_START + XMLUIMessages.Content_Model____2 + SPACE + BOLD_END); - sb.append(description + PARAGRAPH_END); - } - } - } - else if (node.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) { - CMAttributeDeclaration ad = (CMAttributeDeclaration) node; - sb.append(PARAGRAPH_START + BOLD_START + XMLUIMessages.Attribute____3 + SPACE + BOLD_END); - sb.append(node.getNodeName()); - sb.append(PARAGRAPH_END); - printDocumentation(sb, node); - CMDataType dataType = ad.getAttrType(); - if (dataType != null) { - printDataTypeInfo(sb, dataType); - } - } - else if (node.getNodeType() == CMNode.DATA_TYPE) { - sb.append(PARAGRAPH_START + BOLD_START + XMLUIMessages.Data_Type____4 + SPACE + BOLD_END); - sb.append(node.getNodeName()); - sb.append(PARAGRAPH_END); - printDocumentation(sb, node); - } - } - } - - /** - * Adds the description property of the CMNode to the string buffer, sb - * - */ - protected void printDescription(StringBuffer sb, CMNode node) { - String tagInfo = (String) node.getProperty("description"); //$NON-NLS-1$ - if (tagInfo != null) { - sb.append(PARAGRAPH_START + tagInfo.trim() + PARAGRAPH_END); - } - } - - /** - * Adds the tag documentation property of the CMNode to the string buffer, - * sb - * - */ - protected void printDocumentation(StringBuffer sb, CMNode node) { - CMNodeList nodeList = (CMNodeList) node.getProperty("documentation"); //$NON-NLS-1$ - if ((nodeList != null) && (nodeList.getLength() > 0)) { - for (int i = 0; i < nodeList.getLength(); i++) { - CMDocumentation documentation = (CMDocumentation) nodeList.item(i); - String doc = documentation.getValue(); - if (doc != null) { - sb.append(PARAGRAPH_START + doc.trim() + PARAGRAPH_END); - } - } - sb.append(NEW_LINE); - } - } - - /** - * Adds the tag info property of the CMNode to the string buffer, sb - * - */ - protected void printTagInfo(StringBuffer sb, CMNode node) { - String tagInfo = (String) node.getProperty("tagInfo"); //$NON-NLS-1$ - if (tagInfo != null) { - sb.append(PARAGRAPH_START + tagInfo.trim() + PARAGRAPH_END); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/taginfo/XMLInformationProvider.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/taginfo/XMLInformationProvider.java deleted file mode 100644 index fe76a69dab..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/taginfo/XMLInformationProvider.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.taginfo; - - - -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITextHover; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.information.IInformationProvider; -import org.eclipse.jface.text.information.IInformationProviderExtension; -import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; - -/** - * Provides context information for XML tags (Shows tooltip description) - * - * @deprecated StructuredTextViewerConfiguration creates the appropriate - * information provider - */ -public class XMLInformationProvider implements IInformationProvider, IInformationProviderExtension { - - private ITextHover fTextHover = null; - - public XMLInformationProvider() { - fTextHover = SSEUIPlugin.getDefault().getTextHoverManager().createBestMatchHover(new XMLTagInfoHoverProcessor()); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.information.IInformationProvider#getInformation(org.eclipse.jface.text.ITextViewer, - * org.eclipse.jface.text.IRegion) - */ - public String getInformation(ITextViewer textViewer, IRegion subject) { - return (String) getInformation2(textViewer, subject); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.information.IInformationProviderExtension#getInformation2(org.eclipse.jface.text.ITextViewer, - * org.eclipse.jface.text.IRegion) - */ - public Object getInformation2(ITextViewer textViewer, IRegion subject) { - return fTextHover.getHoverInfo(textViewer, subject); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.information.IInformationProvider#getSubject(org.eclipse.jface.text.ITextViewer, - * int) - */ - public IRegion getSubject(ITextViewer textViewer, int offset) { - return fTextHover.getHoverRegion(textViewer, offset); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/taginfo/XMLTagInfoHoverProcessor.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/taginfo/XMLTagInfoHoverProcessor.java deleted file mode 100644 index 47276fc757..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/taginfo/XMLTagInfoHoverProcessor.java +++ /dev/null @@ -1,362 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.taginfo; - - - -import java.util.List; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.Region; -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList; -import org.eclipse.wst.sse.core.internal.util.Debug; -import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils; -import org.eclipse.wst.sse.ui.internal.taginfo.AbstractHoverProcessor; -import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMNamespaceHelper; -import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - - -/** - * Provides hover help documentation for xml tags - * - * @see org.eclipse.jface.text.ITextHover - */ -public class XMLTagInfoHoverProcessor extends AbstractHoverProcessor { - protected MarkupTagInfoProvider fInfoProvider = null; - - /** - * Constructor for XMLTextHoverProcessor. - */ - public XMLTagInfoHoverProcessor() { - // nothing - } - - /** - * Retreives documentation to display in the hover help popup. - * - * @return String any documentation information to display - * <code>null</code> if there is nothing to display. - * - */ - protected String computeHoverHelp(ITextViewer textViewer, int documentPosition) { - String result = null; - - IndexedRegion treeNode = ContentAssistUtils.getNodeAt(textViewer, documentPosition); - if (treeNode == null) { - return null; - } - Node node = (Node) treeNode; - - while ((node != null) && (node.getNodeType() == Node.TEXT_NODE) && (node.getParentNode() != null)) { - node = node.getParentNode(); - } - IDOMNode parentNode = (IDOMNode) node; - - IStructuredDocumentRegion flatNode = ((IStructuredDocument) textViewer.getDocument()).getRegionAtCharacterOffset(documentPosition); - if (flatNode != null) { - ITextRegion region = flatNode.getRegionAtCharacterOffset(documentPosition); - if (region != null) { - result = computeRegionHelp(treeNode, parentNode, flatNode, region); - } - } - - return result; - } - - /** - * Computes the hoverhelp based on region - * - * @return String hoverhelp - */ - protected String computeRegionHelp(IndexedRegion treeNode, IDOMNode parentNode, IStructuredDocumentRegion flatNode, ITextRegion region) { - String result = null; - if (region == null) { - return null; - } - String regionType = region.getType(); - if (regionType == DOMRegionContext.XML_TAG_NAME) { - result = computeTagNameHelp((IDOMNode) treeNode, parentNode, flatNode, region); - } - else if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) { - result = computeTagAttNameHelp((IDOMNode) treeNode, parentNode, flatNode, region); - } - else if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) { - result = computeTagAttValueHelp((IDOMNode) treeNode, parentNode, flatNode, region); - } - return result; - } - - /** - * Computes the hover help for the attribute name - */ - protected String computeTagAttNameHelp(IDOMNode xmlnode, IDOMNode parentNode, IStructuredDocumentRegion flatNode, ITextRegion region) { - CMElementDeclaration elementDecl = getCMElementDeclaration(xmlnode); - String attName = flatNode.getText(region); - CMAttributeDeclaration attDecl = getCMAttributeDeclaration(xmlnode, elementDecl, attName); - return getAdditionalInfo(elementDecl, attDecl); - } - - /** - * Computes the hover help for the attribute value (this is the same as - * the attribute name's help) - */ - protected String computeTagAttValueHelp(IDOMNode xmlnode, IDOMNode parentNode, IStructuredDocumentRegion flatNode, ITextRegion region) { - CMElementDeclaration elementDecl = getCMElementDeclaration(xmlnode); - ITextRegion attrNameRegion = getAttrNameRegion(xmlnode, region); - - String attName = flatNode.getText(attrNameRegion); - CMAttributeDeclaration attDecl = getCMAttributeDeclaration(xmlnode, elementDecl, attName); - return getAdditionalInfo(elementDecl, attDecl); - } - - /** - * Computes the hover help for the tag name - */ - protected String computeTagNameHelp(IDOMNode xmlnode, IDOMNode parentNode, IStructuredDocumentRegion flatNode, ITextRegion region) { - CMElementDeclaration elementDecl = getCMElementDeclaration(xmlnode); - CMElementDeclaration pelementDecl = getCMElementDeclaration(parentNode); - return getAdditionalInfo(pelementDecl, elementDecl); - } - - /** - * Retreives cmnode's documentation to display in the hover help popup. If - * no documentation exists for cmnode, try displaying parentOrOwner's - * documentation - * - * @return String any documentation information to display for cmnode. - * <code>null</code> if there is nothing to display. - */ - protected String getAdditionalInfo(CMNode parentOrOwner, CMNode cmnode) { - String addlInfo = null; - - if (cmnode == null) { - if (Debug.displayWarnings) { - new IllegalArgumentException("Null declaration!").printStackTrace(); //$NON-NLS-1$ - } - return null; - } - - addlInfo = getInfoProvider().getInfo(cmnode); - if ((addlInfo == null) && (parentOrOwner != null)) { - addlInfo = getInfoProvider().getInfo(parentOrOwner); - } - return addlInfo; - } - - /** - * Find the region of the attribute name for the given attribute value - * region - * - */ - protected ITextRegion getAttrNameRegion(IDOMNode node, ITextRegion region) { - // Find the attribute name for which this position should have a value - IStructuredDocumentRegion open = node.getFirstStructuredDocumentRegion(); - ITextRegionList openRegions = open.getRegions(); - int i = openRegions.indexOf(region); - if (i < 0) { - return null; - } - ITextRegion nameRegion = null; - while (i >= 0) { - nameRegion = openRegions.get(i--); - if (nameRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) { - break; - } - } - return nameRegion; - } - - /** - * Retreives CMAttributeDeclaration indicated by attribute name within - * elementDecl - */ - protected CMAttributeDeclaration getCMAttributeDeclaration(IDOMNode node, CMElementDeclaration elementDecl, String attName) { - CMAttributeDeclaration attrDecl = null; - - if (elementDecl != null) { - CMNamedNodeMap attributes = elementDecl.getAttributes(); - - CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(attributes); - List nodes = ModelQueryUtil.getModelQuery(node.getOwnerDocument()).getAvailableContent((Element) node, elementDecl, ModelQuery.INCLUDE_ATTRIBUTES); - for (int k = 0; k < nodes.size(); k++) { - CMNode cmnode = (CMNode) nodes.get(k); - if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) { - allAttributes.put(cmnode); - } - } - attributes = allAttributes; - - String noprefixName = DOMNamespaceHelper.getUnprefixedName(attName); - if (attributes != null) { - attrDecl = (CMAttributeDeclaration) attributes.getNamedItem(noprefixName); - if (attrDecl == null) { - attrDecl = (CMAttributeDeclaration) attributes.getNamedItem(attName); - } - } - } - return attrDecl; - } - - /** - * Retreives CMElementDeclaration for given node - * - * @return CMElementDeclaration - CMElementDeclaration of node or - * <code>null</code> if not possible - */ - protected CMElementDeclaration getCMElementDeclaration(Node node) { - CMElementDeclaration result = null; - if (node.getNodeType() == Node.ELEMENT_NODE) { - ModelQuery modelQuery = ModelQueryUtil.getModelQuery(node.getOwnerDocument()); - if (modelQuery != null) { - result = modelQuery.getCMElementDeclaration((Element) node); - } - } - return result; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.ITextHover#getHoverInfo(org.eclipse.jface.text.ITextViewer, - * org.eclipse.jface.text.IRegion) - */ - public String getHoverInfo(ITextViewer viewer, IRegion hoverRegion) { - if ((hoverRegion == null) || (viewer == null) || (viewer.getDocument() == null)) { - return null; - } - - String displayText = null; - int documentOffset = hoverRegion.getOffset(); - displayText = computeHoverHelp(viewer, documentOffset); - - return displayText; - } - - /** - * Returns the region to hover the text over based on the offset. - * - * @param textViewer - * @param offset - * - * @return IRegion region to hover over if offset is within tag name, - * attribute name, or attribute value and if offset is not over - * invalid whitespace. otherwise, returns <code>null</code> - * - * @see org.eclipse.jface.text.ITextHover#getHoverRegion(ITextViewer, int) - */ - public IRegion getHoverRegion(ITextViewer textViewer, int offset) { - if ((textViewer == null) || (textViewer.getDocument() == null)) { - return null; - } - - IStructuredDocumentRegion flatNode = ((IStructuredDocument) textViewer.getDocument()).getRegionAtCharacterOffset(offset); - ITextRegion region = null; - - if (flatNode != null) { - region = flatNode.getRegionAtCharacterOffset(offset); - } - - if (region != null) { - // only supply hoverhelp for tag name, attribute name, or - // attribute value - String regionType = region.getType(); - if ((regionType == DOMRegionContext.XML_TAG_NAME) || (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) || (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE)) { - try { - // check if we are at whitespace before or after line - IRegion line = textViewer.getDocument().getLineInformationOfOffset(offset); - if ((offset > (line.getOffset())) && (offset < (line.getOffset() + line.getLength()))) { - // check if we are in region's trailing whitespace - // (whitespace after relevant info) - if (offset < flatNode.getTextEndOffset(region)) { - return new Region(flatNode.getStartOffset(region), region.getTextLength()); - } - } - } - catch (BadLocationException e) { - Logger.logException(e); - } - } - } - return null; - } - - /** - * @deprecated if enabled flag is false, dont call getHoverRegion in the - * first place if true, use getHoverRegion(ITextViewer, int) - */ - public IRegion getHoverRegion(ITextViewer textViewer, int offset, boolean enabled) { - if ((!enabled) || (textViewer == null) || (textViewer.getDocument() == null)) { - return null; - } - - IStructuredDocumentRegion flatNode = ((IStructuredDocument) textViewer.getDocument()).getRegionAtCharacterOffset(offset); - ITextRegion region = null; - - if (flatNode != null) { - region = flatNode.getRegionAtCharacterOffset(offset); - } - - if (region != null) { - // only supply hoverhelp for tag name, attribute name, or - // attribute value - String regionType = region.getType(); - if ((regionType == DOMRegionContext.XML_TAG_NAME) || (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) || (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE)) { - try { - // check if we are at whitespace before or after line - IRegion line = textViewer.getDocument().getLineInformationOfOffset(offset); - if ((offset > (line.getOffset())) && (offset < (line.getOffset() + line.getLength()))) { - // check if we are in region's trailing whitespace - // (whitespace after relevant info) - if (offset < flatNode.getTextEndOffset(region)) { - return new Region(flatNode.getStartOffset(region), region.getTextLength()); - } - } - } - catch (BadLocationException e) { - Logger.logException(e); - } - } - } - return null; - } - - /** - * Gets the infoProvider. - * - * @return Returns fInfoProvider and if fInfoProvider was - * <code>null</code> set fInfoProvider to DefaultInfoProvider - */ - public MarkupTagInfoProvider getInfoProvider() { - if (fInfoProvider == null) { - fInfoProvider = new MarkupTagInfoProvider(); - } - return fInfoProvider; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/templates/EncodingTemplateVariableResolverXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/templates/EncodingTemplateVariableResolverXML.java deleted file mode 100644 index 079b04270c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/templates/EncodingTemplateVariableResolverXML.java +++ /dev/null @@ -1,38 +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.wst.xml.ui.internal.templates; - -import org.eclipse.jface.text.templates.SimpleTemplateVariableResolver; -import org.eclipse.jface.text.templates.TemplateContext; -import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; - - -public class EncodingTemplateVariableResolverXML extends SimpleTemplateVariableResolver { - private static final String ENCODING_TYPE = getEncodingType(); - - private static String getEncodingType() { - return "encoding"; //$NON-NLS-1$ - } - - /** - * Creates a new encoding variable - */ - public EncodingTemplateVariableResolverXML() { - super(ENCODING_TYPE, XMLUIMessages.Creating_files_encoding); - } - - protected String resolve(TemplateContext context) { - return XMLCorePlugin.getDefault().getPluginPreferences().getString(CommonEncodingPreferenceNames.OUTPUT_CODESET); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/templates/TemplateContextTypeIdsXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/templates/TemplateContextTypeIdsXML.java deleted file mode 100644 index f7993e295c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/templates/TemplateContextTypeIdsXML.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.templates; - -public class TemplateContextTypeIdsXML { - - public static final String ALL = getAll(); - - public static final String ATTRIBUTE = getAttribute(); - - public static final String ATTRIBUTE_VALUE = getAttributeValue(); - - public static final String NEW = getNew(); - - public static final String TAG = getTag(); - - private static String getAll() { - return getPrefix() + "_all"; //$NON-NLS-1$ - } - - private static String getAttribute() { - return getPrefix() + "_attribute"; //$NON-NLS-1$ - } - - private static String getAttributeValue() { - return getPrefix() + "_attribute_value"; //$NON-NLS-1$ - } - - private static String getNew() { - return getPrefix() + "_new"; //$NON-NLS-1$ - } - - private static String getPrefix() { - return "xml"; //$NON-NLS-1$ - } - - private static String getTag() { - return getPrefix() + "_tag"; //$NON-NLS-1$ - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/templates/TemplateContextTypeXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/templates/TemplateContextTypeXML.java deleted file mode 100644 index 43ccf20924..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/templates/TemplateContextTypeXML.java +++ /dev/null @@ -1,35 +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.wst.xml.ui.internal.templates; - -import org.eclipse.jface.text.templates.GlobalTemplateVariables; -import org.eclipse.jface.text.templates.TemplateContextType; - -/** - * Base class for XML template context types. Templates of this context type - * apply to any place within XML content type. - */ -public class TemplateContextTypeXML extends TemplateContextType { - - public TemplateContextTypeXML() { - super(); - addResolver(new GlobalTemplateVariables.Cursor()); - addResolver(new GlobalTemplateVariables.Date()); - addResolver(new GlobalTemplateVariables.Dollar()); - addResolver(new GlobalTemplateVariables.LineSelection()); - addResolver(new GlobalTemplateVariables.Time()); - addResolver(new GlobalTemplateVariables.User()); - addResolver(new GlobalTemplateVariables.WordSelection()); - addResolver(new GlobalTemplateVariables.Year()); - addResolver(new EncodingTemplateVariableResolverXML()); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/text/XMLDocumentRegionEdgeMatcher.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/text/XMLDocumentRegionEdgeMatcher.java deleted file mode 100644 index b29fd9b47b..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/text/XMLDocumentRegionEdgeMatcher.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.text; - -import org.eclipse.jface.text.source.DefaultCharacterPairMatcher; -import org.eclipse.wst.sse.ui.internal.text.DocumentRegionEdgeMatcher; -import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; - - -public class XMLDocumentRegionEdgeMatcher extends DocumentRegionEdgeMatcher { - - private static final char[] PAIRS = {'{', '}', '(', ')', '[', ']','"','"','\'','\''}; - - public XMLDocumentRegionEdgeMatcher() { - super(new String[]{DOMRegionContext.XML_TAG_NAME, DOMRegionContext.XML_COMMENT_TEXT, DOMRegionContext.XML_CDATA_TEXT, DOMRegionContext.XML_PI_OPEN, DOMRegionContext.XML_PI_CONTENT}, new DefaultCharacterPairMatcher(PAIRS)); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/util/SharedXMLEditorPluginImageHelper.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/util/SharedXMLEditorPluginImageHelper.java deleted file mode 100644 index 9981244de5..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/util/SharedXMLEditorPluginImageHelper.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.util; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.swt.graphics.Image; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages; - - -public class SharedXMLEditorPluginImageHelper { - public static final String IMG_DTOOL_CONSTRAINOFF = XMLEditorPluginImages.IMG_DTOOL_CONSTRAINOFF; - public static final String IMG_DTOOL_CONSTRAINON = XMLEditorPluginImages.IMG_DTOOL_CONSTRAINON; - public static final String IMG_DTOOL_RLDGRMR = XMLEditorPluginImages.IMG_DTOOL_RLDGRMR; - public static final String IMG_DTOOL_VALIDATE = XMLEditorPluginImages.IMG_DTOOL_VALIDATE; - public static final String IMG_ETOOL_CONSTRAINOFF = XMLEditorPluginImages.IMG_ETOOL_CONSTRAINOFF; - public static final String IMG_ETOOL_CONSTRAINON = XMLEditorPluginImages.IMG_ETOOL_CONSTRAINON; - public static final String IMG_ETOOL_RLDGRMR = XMLEditorPluginImages.IMG_ETOOL_RLDGRMR; - public static final String IMG_ETOOL_VALIDATE = XMLEditorPluginImages.IMG_ETOOL_VALIDATE; - public static final String IMG_OBJ_ATTRIBUTE = XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE; - public static final String IMG_OBJ_CDATASECTION = XMLEditorPluginImages.IMG_OBJ_CDATASECTION; - public static final String IMG_OBJ_COMMENT = XMLEditorPluginImages.IMG_OBJ_COMMENT; - public static final String IMG_OBJ_DOCTYPE = XMLEditorPluginImages.IMG_OBJ_DOCTYPE; - public static final String IMG_OBJ_ELEMENT = XMLEditorPluginImages.IMG_OBJ_ELEMENT; - public static final String IMG_OBJ_ENTITY = XMLEditorPluginImages.IMG_OBJ_ENTITY; - public static final String IMG_OBJ_ENTITY_REFERENCE = XMLEditorPluginImages.IMG_OBJ_ENTITY_REFERENCE; - public static final String IMG_OBJ_NOTATION = XMLEditorPluginImages.IMG_OBJ_NOTATION; - public static final String IMG_OBJ_PROCESSINGINSTRUCTION = XMLEditorPluginImages.IMG_OBJ_PROCESSINGINSTRUCTION; - public static final String IMG_OBJ_TAG_GENERIC = XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC; - public static final String IMG_OBJ_TAG_MACRO = XMLEditorPluginImages.IMG_OBJ_TAG_MACRO; - public static final String IMG_OBJ_TXTEXT = XMLEditorPluginImages.IMG_OBJ_TXTEXT; - - /** - * Retrieves the specified image from the xml source editor plugin's image - * registry. Note: The returned <code>Image</code> is managed by the - * workbench; clients must <b>not </b> dispose of the returned image. - * - * @param symbolicName - * the symbolic name of the image; there are constants declared - * in this class for build-in images that come with the xml - * source editor - * @return the image, or <code>null</code> if not found - */ - public static Image getImage(String symbolicName) { - return XMLEditorPluginImageHelper.getInstance().getImage(symbolicName); - } - - /** - * Retrieves the image descriptor for specified image from the xml source - * editor plugin's image registry. Unlike <code>Image</code>s, image - * descriptors themselves do not need to be disposed. - * - * @param symbolicName - * the symbolic name of the image; there are constants declared - * in this interface for build-in images that come with the xml - * source editor - * @return the image descriptor, or <code>null</code> if not found - */ - public static ImageDescriptor getImageDescriptor(String symbolicName) { - return XMLEditorPluginImageHelper.getInstance().getImageDescriptor(symbolicName); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/util/XMLCommonResources.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/util/XMLCommonResources.java deleted file mode 100644 index a3ba0bba36..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/util/XMLCommonResources.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.util; - -import java.text.MessageFormat; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; - -/** - * @deprecated use XMLUIPlugin.getResourceString() instead - */ -/** - * This class exists temporarily until the properties files can be - * re-organized and the various resource references can be updated - */ -public class XMLCommonResources { - protected static XMLCommonResources instance; - - public synchronized static XMLCommonResources getInstance() { - if (instance == null) { - instance = new XMLCommonResources(XMLUIPlugin.getDefault()); - } - return instance; - } - - private XMLUIPlugin editorPlugin; - - private ResourceBundle resourceBundle; - - public XMLCommonResources(XMLUIPlugin editorPlugin) { - instance = this; - this.editorPlugin = editorPlugin; - try { - resourceBundle = ResourceBundle.getBundle("org.eclipse.wst.xml.ui.internal.XMLUIPluginResources"); //$NON-NLS-1$ - } - catch (MissingResourceException exception) { - // TODO... log an error message - // B2BUtilPlugin.getPlugin().getMsgLogger().write(B2BUtilPlugin.getGUIString("_WARN_PLUGIN_PROPERTIES_MISSING") - // + descriptor.getLabel()); - resourceBundle = null; - } - } - - ImageDescriptor _getImageDescriptor(String iconName) { - return AbstractUIPlugin.imageDescriptorFromPlugin(XMLUIPlugin.ID, iconName); - } - - - public ResourceBundle getResourceBundle() { - return resourceBundle; - } - - /** - * This gets the string resource. - */ - public String getString(String key) { - return getResourceBundle().getString(key); - } - - /** - * This gets the string resource and does one substitution. - */ - public String getString(String key, Object s1) { - return MessageFormat.format(getString(key), new Object[]{s1}); - } - - /** - * This gets the string resource and does two substitutions. - */ - public String getString(String key, Object s1, Object s2) { - return MessageFormat.format(getString(key), new Object[]{s1, s2}); - } - - public IWorkbench getWorkbench() { - return editorPlugin.getWorkbench(); - } - /* - * public ImageFactory getImageFactory() { return imageFactory; } - */ -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/util/XMLCommonUIContextIds.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/util/XMLCommonUIContextIds.java deleted file mode 100644 index 763d502b7f..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/util/XMLCommonUIContextIds.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ - - -package org.eclipse.wst.xml.ui.internal.util; - -/** - * Context help id constants. - */ -public interface XMLCommonUIContextIds { - public static final String PLUGIN_NAME = "org.eclipse.wst.xml.ui"; //$NON-NLS-1$ - - /* CONTEXT_ID xcui0500 for Edit Attribute Instruction Dialog */ - public static final String XCUI_ATTRIBUTE_DIALOG = PLUGIN_NAME + ".xcui0500"; //$NON-NLS-1$ - - /* CONTEXT_ID xcui0400 for Select XML Catalog ID Dialog */ - public static final String XCUI_CATALOG_DIALOG = PLUGIN_NAME + ".xcui0400"; //$NON-NLS-1$ - - /* CONTEXT_IDs for XML Common UI use xcuixxx context IDs */ - - /* CONTEXT_ID xcui0010 for Edit Doctype Dialog */ - public static final String XCUI_DOCTYPE_DIALOG = PLUGIN_NAME + ".xcui0010"; //$NON-NLS-1$ - /* CONTEXT_ID xcui0030 for Public ID Text Edit */ - public static final String XCUI_DOCTYPE_PUBLIC = PLUGIN_NAME + ".xcui0030"; //$NON-NLS-1$ - /* CONTEXT_ID xcui0020 for Root Element Name Text Edit */ - public static final String XCUI_DOCTYPE_ROOT = PLUGIN_NAME + ".xcui0020"; //$NON-NLS-1$ - /* CONTEXT_ID xcui0040 for System ID Text Edit */ - public static final String XCUI_DOCTYPE_SYSTEM = PLUGIN_NAME + ".xcui0050"; //$NON-NLS-1$ - - /* CONTEXT_ID xcui0300 for Edit Element Instruction Dialog */ - public static final String XCUI_ELEMENT_DIALOG = PLUGIN_NAME + ".xcui0600"; //$NON-NLS-1$ - - /* CONTEXT_ID xcui0200 for Edit Namespace Dialog */ - public static final String XCUI_NAMESPACE_DIALOG = PLUGIN_NAME + ".xcui0200"; //$NON-NLS-1$ - - /* CONTEXT_ID xcui0300 for Edit Processing Instruction Dialog */ - public static final String XCUI_PROCESSING_DIALOG = PLUGIN_NAME + ".xcui0300"; //$NON-NLS-1$ - - /* CONTEXT_ID xcui0100 for Edit Schema Information Dialog */ - public static final String XCUI_SCHEMA_INFO_DIALOG = PLUGIN_NAME + ".xcui0100"; //$NON-NLS-1$ -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/validation/DelegatingSourceValidator.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/validation/DelegatingSourceValidator.java deleted file mode 100644 index 3973babd6f..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/validation/DelegatingSourceValidator.java +++ /dev/null @@ -1,602 +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.wst.xml.ui.internal.validation; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.Path; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.validation.internal.core.IMessageAccess; -import org.eclipse.wst.validation.internal.core.ValidationException; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IProjectValidationContext; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; -import org.eclipse.wst.validation.internal.provisional.core.IValidationContext; -import org.eclipse.wst.validation.internal.provisional.core.IValidator; -import org.eclipse.wst.validation.internal.provisional.core.IValidatorJob; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMText; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -/** - * A DelegatingReconcileValidator calls its delegate validator to get a list - * of validation error IMessages. Using information in this IMessage the - * DelegatingReconcileValidator updates the IMessage with an offset and length - * to give a good range to be "squiggled" and adds the messages to the - * IReporter - * - * @author Mark Hutchinson - * - */ -public abstract class DelegatingSourceValidator implements IValidator { - // the selection strategies: - protected static final String ALL_ATTRIBUTES = "ALL_ATTRIBUTES"; //$NON-NLS-1$ - protected static final String ATTRIBUTE_NAME = "ATTRIBUTE_NAME"; //$NON-NLS-1$ - protected static final String ATTRIBUTE_VALUE = "ATTRIBUTE_VALUE"; //$NON-NLS-1$ - protected static final String START_TAG = "START_TAG"; //$NON-NLS-1$ - protected static final String TEXT = "TEXT"; //$NON-NLS-1$ - protected static final String FIRST_NON_WHITESPACE_TEXT = "FIRST_NON_WHITESPACE_TEXT"; //$NON-NLS-1$ - protected static final String TEXT_ENTITY_REFERENCE = "TEXT_ENTITY_REFERENCE"; //$NON-NLS-1$ - protected static final String VALUE_OF_ATTRIBUTE_WITH_GIVEN_VALUE = "VALUE_OF_ATTRIBUTE_WITH_GIVEN_VALUE"; //$NON-NLS-1$ - protected static final String END_TAG = "END_TAG"; //$NON-NLS-1$ - - /** - * This constant specifies the attribute name that specifies the side of - * the 'start tag' that the validator has used to report an error. A - * validator may choose to report a message at the left (the start of the - * start tag)or at the right (the end of the start tag). When this - * attribute is not specified error ERROR_SIDE_LEFT is the default. - */ - protected static final String ERROR_SIDE = "ERROR_SIDE"; //$NON-NLS-1$ - - /** - * When the ERROR_SIDE attribute specifies the ERROR_SIDE_LEFT value it is - * assumed that the message specifies a location to the left of the start - * tag - */ - protected static final String ERROR_SIDE_LEFT = "ERROR_SIDE_LEFT"; //$NON-NLS-1$ - - /** - * When the ERROR_SIDE attribute specifies the ERROR_SIDE_RIGHT value it - * is assumed that the message specifies a location to the right of the - * start tag - */ - protected static final String ERROR_SIDE_RIGHT = "ERROR_SIDE_RIGHT"; //$NON-NLS-1$ - - protected static final String COLUMN_NUMBER_ATTRIBUTE = "columnNumber"; //$NON-NLS-1$ - protected static final String SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE = "squiggleSelectionStrategy"; //$NON-NLS-1$ - protected static final String SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE = "squiggleNameOrValue"; //$NON-NLS-1$ - - public DelegatingSourceValidator() { - super(); // constructor - } - - public void cleanup(IReporter arg0) { // don't need to implement - } - - // My Implementation of IHelper - class MyHelper implements IProjectValidationContext { - InputStream inputStream; - - IFile file; - - public MyHelper(InputStream inputStream, IFile file) { - this.inputStream = inputStream; - this.file = file; - } - - public int getBuildKind() { - return 0; - } - - public Object loadModel(String symbolicName, Object[] parms) { - if (symbolicName.equals("getFile")) { //$NON-NLS-1$ - return file; - } - return null; - } - - public Object loadModel(String symbolicName) { - if (symbolicName.equals("inputStream")) { //$NON-NLS-1$ - return inputStream; - } - return null; - } - - public String[] getURIs() { - if (file != null) { - return new String[]{file.getFullPath().toString()}; - } - return new String[0]; - } - - public IProject getProject() { - if (file != null) { - return file.getProject(); - } - return null; - } - } - - // My Implementation of IReporter - class MyReporter implements IReporter { - List list = new ArrayList(); - - public MyReporter() { - super(); - } - - public void addMessage(IValidator origin, IMessage message) { - list.add(message); - } - - public void displaySubtask(IValidator validator, IMessage message) { - /* do not need to implement */ - } - - public IMessageAccess getMessageAccess() { - return null; - } - - public boolean isCancelled() { - return false; - } - - public void removeAllMessages(IValidator origin, Object object) { // do - /* do not need to implement */ - } - - public void removeAllMessages(IValidator origin) { - /* do not need to implement */ - } - - public void removeMessageSubset(IValidator validator, Object obj, String groupName) {// do - /* do not need to implement */ - } - - public List getMessages() { - return list; - } - } - - protected abstract IValidator getDelegateValidator(); - - /** - * Calls a delegate validator getting and updates it's list of - * ValidationMessages with a good squiggle offset and length. - * - * @param helper - * loads an object. - * @param reporter - * Is an instance of an IReporter interface, which is used for - * interaction with the user. - */ - public void validate(IValidationContext helper, IReporter reporter) throws ValidationException { - String[] delta = helper.getURIs(); - if (delta.length > 0) { - // get the file, model and document: - IFile file = getFile(delta[0]); - IDOMModel xmlModel = getModelForResource(file); - try { - IDOMDocument document = xmlModel.getDocument(); - - // store the text in a byte array; make a full copy to ease - // any threading problems - byte[] byteArray; - try { - byteArray = xmlModel.getStructuredDocument().get().getBytes("UTF-8"); - } - catch (UnsupportedEncodingException e) { - // Not likely to happen - byteArray = xmlModel.getStructuredDocument().get().getBytes(); - } - - if (isDelegateValidatorEnabled(file)) { - IValidator validator = getDelegateValidator(); - if (validator != null) { - // Validate the file: - IValidationContext vHelper = new MyHelper(new ByteArrayInputStream(byteArray), file); - MyReporter vReporter = new MyReporter(); - if (validator instanceof IValidatorJob) { - ((IValidatorJob) validator).validateInJob(vHelper, vReporter); - } - else { - validator.validate(vHelper, vReporter); - } - List messages = vReporter.list; - - // set the offset and length - updateValidationMessages(messages, document, reporter); - } - } - } - - - finally { - if (xmlModel != null) { - xmlModel.releaseFromRead(); - } - } - } - } - - /** - * iterates through the messages and calculates a "better" offset and - * length - * - * @param messages - - * a List of IMessages - * @param document - - * the document - * @param reporter - - * the reporter the messages are to be added to - */ - protected void updateValidationMessages(List messages, IDOMDocument document, IReporter reporter) { - for (int i = 0; i < messages.size(); i++) { - IMessage message = (IMessage) messages.get(i); - try { - if (message.getAttribute(COLUMN_NUMBER_ATTRIBUTE) != null) { - int column = ((Integer) message.getAttribute(COLUMN_NUMBER_ATTRIBUTE)).intValue(); - String selectionStrategy = (String) message.getAttribute(SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE); - String nameOrValue = (String) message.getAttribute(SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE); - - // convert the line and Column numbers to an offset: - int start = document.getStructuredDocument().getLineOffset(message.getLineNumber() - 1) + column - 1; - - // calculate the "better" start and end offset: - int[] result = computeStartAndEndLocation(start, selectionStrategy, getErrorSide(message), nameOrValue, document); - if (result != null) { - message.setOffset(result[0]); - message.setLength(result[1] - result[0]); - reporter.addMessage(this, message); - } - } - } - catch (BadLocationException e) { // this exception should not - // occur - it is thrown if - // trying to convert an - // invalid line number to and - // offset - } - - } - } - - /** - * @param delta - * the IFileDelta containing the file name to get - * @return the IFile - */ - public IFile getFile(String delta) { - IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(delta)); - if (file != null && file.exists()) - return file; - return null; - } - - /** - * - * @param file - * the file to get the model for - * @return the file's XMLModel - */ - protected IDOMModel getModelForResource(IFile file) { - IStructuredModel model = null; - IModelManager manager = StructuredModelManager.getModelManager(); - - try { - model = manager.getModelForRead(file); - // TODO.. HTML validator tries again to get a model a 2nd way - } - catch (Exception e) { - // e.printStackTrace(); - } - - return model instanceof IDOMModel ? (IDOMModel) model : null; - } - - /** - * @deprecated use computeStartEndLocation(int startOffset, String - * errorMessage, String selectionStrategy, boolean leftError, - * String nameOrValue, IDOMDocument document) { - * - */ - protected int[] computeStartEndLocation(int startOffset, String errorMessage, String selectionStrategy, String nameOrValue, IDOMDocument document) { - return computeStartAndEndLocation(startOffset, selectionStrategy, ERROR_SIDE_RIGHT, nameOrValue, document); - } - - /** - * Calculates the "better" offsets. - * - * @param startOffset - - * the offset given by Xerces - * @param errorMessage - - * the Xerces error Message - * @param selectionStrategy - - * the selectionStrategy - * @param document - - * the document - * @return int[] - position 0 has the start offset of the squiggle range, - * position 1 has the endOffset - */ - /* - * The way the offsets is calculated is: - find the indexed region - * (element) closest to the given offset - if we are between two elements, - * choosing left or right element will depend on parameter 'errorSide' - - * based on the selectionStrategy choose the underlining strategy (eg - * START_TAG means underline the start tag of that element) - use - * information from nameOrValue and the DOM to get better offsets - * - */ - protected int[] computeStartAndEndLocation(int startOffset, String selectionStrategy, String errorSide, String nameOrValue, IDOMDocument document) { - try { - int startEndPositions[] = new int[2]; - - IndexedRegion region = document.getModel().getIndexedRegion(startOffset); - IndexedRegion prevRegion = document.getModel().getIndexedRegion(startOffset - 1); - - if (prevRegion != region) { - // if between two regions we use the 'errorSide' to understand - // which - // element is applicable. if we know the error has been - // reported to the - // right of the tag, then we can assume we need to step back - // to the previous - // region to land at the 'correct location. Otherwise assume - // we're - // exactly where we need to be. - if (ERROR_SIDE_LEFT.equals(errorSide)) { - region = prevRegion; - } - } - - // initialize start and end positions to be the start positions - // this means if the - // special case is not taken care of below the start and end - // offset are set to be - // the start of the region where the error was - if (region != null) { - startEndPositions[0] = region.getStartOffset(); - startEndPositions[1] = startEndPositions[0]; - } - else { // this will message will not get added to the IReporter - // since the length is 0 - startEndPositions[0] = 0; - startEndPositions[1] = 0; - } - if (region instanceof Node) { - Node node = (Node) region; - - if (START_TAG.equals(selectionStrategy)) {// then we want to - // underline the opening tag - if (node.getNodeType() == Node.ELEMENT_NODE) { - IDOMElement element = (IDOMElement) node; - startEndPositions[0] = element.getStartOffset() + 1; - startEndPositions[1] = startEndPositions[0] + element.getTagName().length(); - } - } - else if (END_TAG.equals(selectionStrategy)) {// then we want to - // underline the end tag - if (node.getNodeType() == Node.ELEMENT_NODE) { - IDOMElement element = (IDOMElement) node; - startEndPositions[0] = element.getEndStartOffset(); - startEndPositions[1] = element.getEndOffset(); - } - } - else if (ATTRIBUTE_NAME.equals(selectionStrategy)) { // in - // underline the attribute's name - if (node.getNodeType() == Node.ELEMENT_NODE) { - IDOMElement element = (IDOMElement) node; - IDOMNode attributeNode = (IDOMNode) (element.getAttributeNode(nameOrValue)); - if (attributeNode != null) { - startEndPositions[0] = attributeNode.getStartOffset(); - startEndPositions[1] = attributeNode.getStartOffset() + nameOrValue.length(); - } - } - } - else if (ATTRIBUTE_VALUE.equals(selectionStrategy)) { - // underline the attribute's value - if (node.getNodeType() == Node.ELEMENT_NODE) { - IDOMElement element = (IDOMElement) node; - IDOMAttr attributeNode = (IDOMAttr) (element.getAttributeNode(nameOrValue)); - if (attributeNode != null) { - startEndPositions[0] = attributeNode.getValueRegionStartOffset(); - startEndPositions[1] = startEndPositions[0] + attributeNode.getValueRegionText().length(); - } - } - } - else if (ALL_ATTRIBUTES.equals(selectionStrategy)) { - // underline all attributes - if (node.getNodeType() == Node.ELEMENT_NODE) { - IDOMElement element = (IDOMElement) node; - NamedNodeMap attributes = element.getAttributes(); - if (attributes != null) { - IDOMNode first = (IDOMNode) attributes.item(0); - IDOMNode last = (IDOMNode) attributes.item(attributes.getLength() - 1); - if ((first != null) && (last != null)) { - startEndPositions[0] = first.getStartOffset(); - startEndPositions[1] = last.getEndOffset(); - } - } - } - } - else if (TEXT.equals(selectionStrategy)) { - // underline the text between the tags - if (node.getNodeType() == Node.TEXT_NODE) { - IDOMText textNode = (IDOMText) node; - int start = textNode.getStartOffset(); - String value = textNode.getNodeValue(); - int index = 0; - char curChar = value.charAt(index); - // here we are finding start offset by skipping over - // whitespace: - while ((curChar == '\n') || (curChar == '\t') || (curChar == '\r') || (curChar == ' ')) { - curChar = value.charAt(index); - index++; - } - if (index > 0) { - index--; - - } - start = start + index; - startEndPositions[0] = start + index; - startEndPositions[1] = start + value.trim().length(); - } - else if (node.getNodeType() == Node.ELEMENT_NODE) { - IDOMElement element = (IDOMElement) node; - Node child = element.getFirstChild(); - if (child instanceof IDOMNode) { - IDOMNode xmlChild = ((IDOMNode) child); - startEndPositions[0] = xmlChild.getStartOffset(); - startEndPositions[1] = xmlChild.getEndOffset(); - } - } - } - else if (FIRST_NON_WHITESPACE_TEXT.equals(selectionStrategy)) { - // search through all child nodes and return range of - // first non-whitespace - // text node - if (node.getNodeType() == Node.ELEMENT_NODE) { - NodeList nodes = node.getChildNodes(); - for (int i = 0; i < nodes.getLength(); i++) { - Node currentNode = nodes.item(i); - if (currentNode.getNodeType() == Node.TEXT_NODE) { - // TODO (Trung) I don't think we should call - // getNodeValue(), trim(), length() - // repeatedly. - // This is inefficient, to improve use local - // variables to store values. - IDOMText textNode = (IDOMText) currentNode; - if (textNode.getNodeValue().trim().length() > 0) { - String value = textNode.getNodeValue(); - int index = 0; - int start = textNode.getStartOffset(); - char curChar = value.charAt(index); - // here we are finding start offset by - // skipping over whitespace: - while ((curChar == '\n') || (curChar == '\t') || (curChar == '\r') || (curChar == ' ')) { - curChar = value.charAt(index); - index++; - } - if (index > 0) { - index--; - - } - start = start + index; - startEndPositions[0] = start; - startEndPositions[1] = start + value.trim().length(); - break; - } - } - - } - } - } - - else if (TEXT_ENTITY_REFERENCE.equals(selectionStrategy)) { - if (node.getNodeType() == Node.ENTITY_REFERENCE_NODE) { - startEndPositions[0] = region.getStartOffset(); - startEndPositions[1] = region.getEndOffset(); - } - else if (node.getNodeType() == Node.ELEMENT_NODE) { - /* - * In this case the undeclared entity might be in one - * of the attribute values. Search through the - * attributes to find the range of the undeclared - * entity. - */ - String entity = "&" + nameOrValue + ";"; //$NON-NLS-1$ //$NON-NLS-2$ - NamedNodeMap attributes = node.getAttributes(); - for (int i = 0; i < attributes.getLength(); i++) { - IDOMAttr attr = (IDOMAttr) attributes.item(i); - String nodeValue = attr.getNodeValue(); - int index = nodeValue.indexOf(entity); - if (index != -1) { - startEndPositions[0] = attr.getValueRegionStartOffset() + index + 1; - startEndPositions[1] = startEndPositions[0] + entity.length(); - } - } - } - - } - else if (VALUE_OF_ATTRIBUTE_WITH_GIVEN_VALUE.equals(selectionStrategy)) { - // TODO (Trung) do we really need this strategy ? - // If we know the name of the name of the attribute, we - // can retrieve its value. - // Hence, we can incoperate this strategy with - // ATTRIBUTE_VALUE ? - if (node.getNodeType() == Node.ELEMENT_NODE) { - // here we will search through all attributes for the - // one with the - // with the value we want: - // TODO (Trung) I see a potential problem here. - // What happens when there is another attribute having - // the same value - // with this attribute's buggy value ? - // Need to solve when time permits. - NamedNodeMap attributes = node.getAttributes(); - for (int i = 0; i < attributes.getLength(); i++) { - IDOMAttr attr = (IDOMAttr) attributes.item(i); - String nodeValue = attr.getNodeValue().trim(); - if (nodeValue.equals(nameOrValue)) { - startEndPositions[0] = attr.getValueRegionStartOffset() + 1; - startEndPositions[1] = startEndPositions[0] + nodeValue.length(); - break; - } - } - } - } - } - return startEndPositions; - } - // catch (Exception e) { // e.printStackTrace(); - // } - finally { - } - // return null; - } - - /** - * Returns true if delegate validator is enabled based on Validation - * preferences - * - * @param file - * @return false if delegate validator is not enabled based on Validatoin - * preferences, true otherwise - */ - protected boolean isDelegateValidatorEnabled(IFile file) { - return true; - } - - protected String getErrorSide(IMessage message) { - // note that if the ERROR_SIDE is unspecified we return the default - // value ERROR_SIDE_LEFT - Object value = message.getAttribute(ERROR_SIDE); - return ERROR_SIDE_RIGHT.equals(value) ? ERROR_SIDE_RIGHT : ERROR_SIDE_LEFT; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/validation/DelegatingSourceValidatorForXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/validation/DelegatingSourceValidatorForXML.java deleted file mode 100644 index 414a85b8ac..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/validation/DelegatingSourceValidatorForXML.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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.wst.xml.ui.internal.validation; - -import org.eclipse.core.resources.IFile; -import org.eclipse.wst.validation.ValidationFramework; -import org.eclipse.wst.validation.Validator; -import org.eclipse.wst.validation.internal.provisional.core.IValidator; - -/** - * This performs as you type validation for XML files - */ -public class DelegatingSourceValidatorForXML extends DelegatingSourceValidator -{ - private final static String Id = "org.eclipse.wst.xml.core.xml"; //$NON-NLS-1$ - - private Validator _validator; - - public DelegatingSourceValidatorForXML() - { - } - - private Validator getValidator() - { - if (_validator == null) - _validator = ValidationFramework.getDefault().getValidator(Id); - return _validator; - } - - protected IValidator getDelegateValidator() - { - Validator v = getValidator(); - if (v == null) - return null; - return v.asIValidator(); - } - - protected boolean isDelegateValidatorEnabled(IFile file) - { - Validator v = getValidator(); - if (v == null) - return false; - if (!v.shouldValidate(file, false, false)) - return false; - return v.isBuildValidation() || v.isManualValidation(); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/validation/MarkupQuickAssistProcessor.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/validation/MarkupQuickAssistProcessor.java deleted file mode 100644 index c8c876c130..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/validation/MarkupQuickAssistProcessor.java +++ /dev/null @@ -1,147 +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.wst.xml.ui.internal.validation; - -import java.util.ArrayList; - -import org.eclipse.jface.text.contentassist.CompletionProposal; -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext; -import org.eclipse.jface.text.quickassist.IQuickAssistProcessor; -import org.eclipse.jface.text.source.Annotation; -import org.eclipse.swt.graphics.Image; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.correction.ProblemIDsXML; -import org.eclipse.wst.xml.ui.internal.correction.RemoveUnknownElementQuickFixProposal; -import org.eclipse.wst.xml.ui.internal.correction.RenameInFileQuickAssistProposal; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages; - -/** - * Quick assist processor for problems found by the markup validator - */ -class MarkupQuickAssistProcessor implements IQuickAssistProcessor { - private int fProblemId; - private Object fAdditionalFixInfo = null; - - public boolean canAssist(IQuickAssistInvocationContext invocationContext) { - return false; - } - - public boolean canFix(Annotation annotation) { - boolean result = false; - - switch (fProblemId) { - case ProblemIDsXML.EmptyTag : - case ProblemIDsXML.MissingEndTag : - case ProblemIDsXML.AttrsInEndTag : - case ProblemIDsXML.MissingAttrValue : - case ProblemIDsXML.NoAttrValue : - case ProblemIDsXML.SpacesBeforeTagName : - case ProblemIDsXML.SpacesBeforePI : - case ProblemIDsXML.NamespaceInPI : - case ProblemIDsXML.UnknownElement : - case ProblemIDsXML.UnknownAttr : - case ProblemIDsXML.InvalidAttrValue : - case ProblemIDsXML.MissingRequiredAttr : - case ProblemIDsXML.AttrValueNotQuoted : - case ProblemIDsXML.MissingClosingBracket : - result = true; - } - - return result; - } - - public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) { - ArrayList proposals = new ArrayList(); - - switch (fProblemId) { - case ProblemIDsXML.EmptyTag : - proposals.add(new CompletionProposal("", invocationContext.getOffset(), invocationContext.getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_0, null, "")); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case ProblemIDsXML.MissingEndTag : - String tagName = (String) ((Object[]) fAdditionalFixInfo)[0]; - String tagClose = (String) ((Object[]) fAdditionalFixInfo)[1]; - int tagCloseOffset = ((Integer) ((Object[]) fAdditionalFixInfo)[2]).intValue(); - int startTagEndOffset = ((Integer) ((Object[]) fAdditionalFixInfo)[3]).intValue(); - int firstChildStartOffset = ((Integer) ((Object[]) fAdditionalFixInfo)[4]).intValue(); - int endOffset = ((Integer) ((Object[]) fAdditionalFixInfo)[5]).intValue(); - proposals.add(new CompletionProposal(tagClose, tagCloseOffset, 0, 0, getImage(), XMLUIMessages.QuickFixProcessorXML_1, null, "")); //$NON-NLS-1$ - proposals.add(new CompletionProposal("", invocationContext.getOffset(), startTagEndOffset - invocationContext.getOffset(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_2, null, "")); //$NON-NLS-1$ //$NON-NLS-2$ - proposals.add(new CompletionProposal("</" + tagName + ">", firstChildStartOffset, 0, 0, getImage(), XMLUIMessages.QuickFixProcessorXML_3, null, "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - proposals.add(new CompletionProposal("</" + tagName + ">", endOffset, 0, 0, getImage(), XMLUIMessages.QuickFixProcessorXML_4, null, "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - break; - case ProblemIDsXML.AttrsInEndTag : - proposals.add(new CompletionProposal("", invocationContext.getOffset(), invocationContext.getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_5, null, "")); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case ProblemIDsXML.MissingAttrValue : - String defaultAttrValue = (String) ((Object[]) fAdditionalFixInfo)[0]; - int insertOffset = ((Integer) ((Object[]) fAdditionalFixInfo)[1]).intValue(); - proposals.add(new CompletionProposal("\"" + defaultAttrValue + "\"", invocationContext.getOffset() + invocationContext.getLength() + insertOffset, 0, defaultAttrValue.length() + 2, getImage(), XMLUIMessages.QuickFixProcessorXML_6, null, "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - proposals.add(new CompletionProposal("", invocationContext.getOffset(), invocationContext.getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_7, null, "")); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case ProblemIDsXML.NoAttrValue : - defaultAttrValue = (String) fAdditionalFixInfo; - proposals.add(new CompletionProposal("=\"" + defaultAttrValue + "\"", invocationContext.getOffset() + invocationContext.getLength(), 0, defaultAttrValue.length() + 3, getImage(), XMLUIMessages.QuickFixProcessorXML_6, null, "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - proposals.add(new CompletionProposal("", invocationContext.getOffset(), invocationContext.getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_7, null, "")); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case ProblemIDsXML.SpacesBeforeTagName : - proposals.add(new CompletionProposal("", invocationContext.getOffset(), invocationContext.getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_8, null, "")); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case ProblemIDsXML.SpacesBeforePI : - proposals.add(new CompletionProposal("", invocationContext.getOffset(), invocationContext.getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_9, null, "")); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case ProblemIDsXML.NamespaceInPI : - proposals.add(new CompletionProposal("", invocationContext.getOffset(), invocationContext.getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_10, null, "")); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case ProblemIDsXML.UnknownElement : - proposals.add(new RemoveUnknownElementQuickFixProposal(fAdditionalFixInfo, getImage(), XMLUIMessages.QuickFixProcessorXML_11)); - proposals.add(new RenameInFileQuickAssistProposal()); - break; - case ProblemIDsXML.UnknownAttr : - proposals.add(new CompletionProposal("", invocationContext.getOffset(), invocationContext.getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_7, null, "")); //$NON-NLS-1$ //$NON-NLS-2$ - proposals.add(new RenameInFileQuickAssistProposal()); - break; - case ProblemIDsXML.InvalidAttrValue : - proposals.add(new CompletionProposal("", invocationContext.getOffset(), invocationContext.getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_12, null, "")); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case ProblemIDsXML.MissingRequiredAttr : - String requiredAttr = (String) ((Object[]) fAdditionalFixInfo)[0]; - insertOffset = ((Integer) ((Object[]) fAdditionalFixInfo)[1]).intValue(); - proposals.add(new CompletionProposal(requiredAttr, invocationContext.getOffset() + insertOffset, 0, requiredAttr.length(), getImage(), XMLUIMessages.QuickFixProcessorXML_13, null, "")); //$NON-NLS-1$ - break; - case ProblemIDsXML.AttrValueNotQuoted : - String attrValue = (String) fAdditionalFixInfo; - proposals.add(new CompletionProposal("\"" + attrValue + "\"", invocationContext.getOffset(), invocationContext.getLength(), attrValue.length() + 2, getImage(), XMLUIMessages.QuickFixProcessorXML_14, null, "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - break; - case ProblemIDsXML.MissingClosingBracket : - proposals.add(new CompletionProposal(">", invocationContext.getOffset() + invocationContext.getLength(), 0, 1, getImage(), XMLUIMessages.QuickFixProcessorXML_15, null, "")); //$NON-NLS-1$ //$NON-NLS-2$ - break; - } - return (ICompletionProposal[]) proposals.toArray(new ICompletionProposal[proposals.size()]); - } - - public String getErrorMessage() { - return null; - } - - private Image getImage() { - return XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_CORRECTION_CHANGE); - } - - public void setProblemId(int problemId) { - fProblemId = problemId; - } - - public void setAdditionalFixInfo(Object fixInfo) { - fAdditionalFixInfo = fixInfo; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/validation/MarkupValidator.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/validation/MarkupValidator.java deleted file mode 100644 index 8f23c7ff0b..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/validation/MarkupValidator.java +++ /dev/null @@ -1,1037 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.validation; - -import java.util.Locale; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceProxy; -import org.eclipse.core.resources.IResourceProxyVisitor; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.content.IContentDescription; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.quickassist.IQuickAssistProcessor; -import org.eclipse.osgi.util.NLS; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList; -import org.eclipse.wst.sse.core.utils.StringUtils; -import org.eclipse.wst.sse.ui.internal.reconcile.AbstractStructuredTextReconcilingStrategy; -import org.eclipse.wst.sse.ui.internal.reconcile.ReconcileAnnotationKey; -import org.eclipse.wst.sse.ui.internal.reconcile.validator.AnnotationInfo; -import org.eclipse.wst.sse.ui.internal.reconcile.validator.ISourceValidator; -import org.eclipse.wst.sse.ui.internal.reconcile.validator.IncrementalReporter; -import org.eclipse.wst.validation.AbstractValidator; -import org.eclipse.wst.validation.ValidationResult; -import org.eclipse.wst.validation.ValidationState; -import org.eclipse.wst.validation.internal.core.Message; -import org.eclipse.wst.validation.internal.core.ValidationException; -import org.eclipse.wst.validation.internal.operations.IWorkbenchContext; -import org.eclipse.wst.validation.internal.operations.LocalizedMessage; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; -import org.eclipse.wst.validation.internal.provisional.core.IValidationContext; -import org.eclipse.wst.validation.internal.provisional.core.IValidator; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.correction.ProblemIDsXML; -import org.w3c.dom.Node; - -/** - * Basic XML syntax checking step. - */ -public class MarkupValidator extends AbstractValidator implements IValidator, ISourceValidator { - private String DQUOTE = "\""; //$NON-NLS-1$ - private String SQUOTE = "'"; //$NON-NLS-1$ - private final String QUICKASSISTPROCESSOR = IQuickAssistProcessor.class.getName(); - - private IDocument fDocument; - - private IContentType fRootContentType = null; - - private int SEVERITY_ATTRIBUTE_HAS_NO_VALUE = IMessage.HIGH_SEVERITY; - private int SEVERITY_END_TAG_WITH_ATTRIBUTES = IMessage.HIGH_SEVERITY; - private int SEVERITY_INVALID_WHITESPACE_BEFORE_TAGNAME = IMessage.HIGH_SEVERITY; - private int SEVERITY_MISSING_CLOSING_BRACKET = IMessage.HIGH_SEVERITY; - private int SEVERITY_MISSING_CLOSING_QUOTE = IMessage.HIGH_SEVERITY; - private int SEVERITY_MISSING_END_TAG = IMessage.HIGH_SEVERITY; - private int SEVERITY_MISSING_START_TAG = IMessage.HIGH_SEVERITY; - private int SEVERITY_MISSING_QUOTES = IMessage.HIGH_SEVERITY; - private int SEVERITY_NAMESPACE_IN_PI_TARGET = IMessage.HIGH_SEVERITY; - private int SEVERITY_TAG_NAME_MISSING = IMessage.HIGH_SEVERITY; - private int SEVERITY_WHITESPACE_AT_START = IMessage.HIGH_SEVERITY; - - private void addAttributeError(String messageText, String attributeValueText, int start, int length, int problemId, IStructuredDocumentRegion sdRegion, IReporter reporter, int messageSeverity) { - - if (sdRegion.isDeleted()) { - return; - } - - int lineNo = getLineNumber(start); - LocalizedMessage message = new LocalizedMessage(messageSeverity, messageText); - message.setOffset(start); - message.setLength(length); - message.setLineNo(lineNo); - - - if (reporter instanceof IncrementalReporter) { - MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor(); - processor.setProblemId(problemId); - processor.setAdditionalFixInfo(attributeValueText); - message.setAttribute(QUICKASSISTPROCESSOR, processor); - AnnotationInfo info = new AnnotationInfo(message); - ((IncrementalReporter) reporter).addAnnotationInfo(this, info); - } - else { - reporter.addMessage(this, message); - } - } - - private void checkAttributesInEndTag(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) { - - if (structuredDocumentRegion.isDeleted()) { - return; - } - - ITextRegionList textRegions = structuredDocumentRegion.getRegions(); - int errorCount = 0; - int start = structuredDocumentRegion.getEndOffset(); - int end = structuredDocumentRegion.getEndOffset(); - for (int i = 0; (i < textRegions.size()) && (errorCount < AbstractStructuredTextReconcilingStrategy.ELEMENT_ERROR_LIMIT) && !structuredDocumentRegion.isDeleted(); i++) { - ITextRegion textRegion = textRegions.get(i); - if ((textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) || (textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) || (textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE)) { - if (start > structuredDocumentRegion.getStartOffset(textRegion)) { - start = structuredDocumentRegion.getStartOffset(textRegion); - } - end = structuredDocumentRegion.getEndOffset(textRegion); - errorCount++; - } - } - // create one error for all attributes in the end tag - if (errorCount > 0) { - // Position p = new Position(start, end - start); - String messageText = XMLUIMessages.End_tag_has_attributes; - LocalizedMessage message = new LocalizedMessage(SEVERITY_END_TAG_WITH_ATTRIBUTES, messageText); - message.setOffset(start); - message.setLength(end - start); - message.setLineNo(getLineNumber(start)); - - if (reporter instanceof IncrementalReporter) { - MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor(); - processor.setProblemId(ProblemIDsXML.AttrsInEndTag); - message.setAttribute(QUICKASSISTPROCESSOR, processor); - - AnnotationInfo info = new AnnotationInfo(message); - ((IncrementalReporter) reporter).addAnnotationInfo(this, info); - } - else { - reporter.addMessage(this, message); - } - } - } - - - private void checkClosingBracket(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) { - - if (structuredDocumentRegion.isDeleted()) { - return; - } - - ITextRegionList regions = structuredDocumentRegion.getRegions(); - ITextRegion r = null; - boolean closed = false; - for (int i = 0; (i < regions.size()) && !structuredDocumentRegion.isDeleted(); i++) { - r = regions.get(i); - if ((r.getType() == DOMRegionContext.XML_TAG_CLOSE) || (r.getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE)) { - closed = true; - } - } - if (!closed) { - - String messageText = XMLUIMessages.ReconcileStepForMarkup_6; - - int start = structuredDocumentRegion.getStartOffset(); - int length = structuredDocumentRegion.getText().trim().length(); - int lineNo = getLineNumber(start); - - LocalizedMessage message = new LocalizedMessage(SEVERITY_MISSING_CLOSING_BRACKET , messageText); - message.setOffset(start); - message.setLength(length); - message.setLineNo(lineNo); - - if (reporter instanceof IncrementalReporter) { - MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor(); - processor.setProblemId(ProblemIDsXML.MissingClosingBracket); - message.setAttribute(QUICKASSISTPROCESSOR, processor); - - AnnotationInfo info = new AnnotationInfo(message); - ((IncrementalReporter) reporter).addAnnotationInfo(this, info); - } - else { - reporter.addMessage(this, message); - } - } - } - - private void checkEmptyTag(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) { - - if (structuredDocumentRegion.isDeleted()) { - return; - } - - // navigate to name - ITextRegionList regions = structuredDocumentRegion.getRegions(); - if (regions.size() == 2) { - // missing name region - if ((regions.get(0).getType() == DOMRegionContext.XML_TAG_OPEN) && (regions.get(1).getType() == DOMRegionContext.XML_TAG_CLOSE)) { - String messageText = XMLUIMessages.ReconcileStepForMarkup_3; - int start = structuredDocumentRegion.getStartOffset(); - int length = structuredDocumentRegion.getLength(); - int lineNo = getLineNumber(start); - - LocalizedMessage message = new LocalizedMessage(SEVERITY_TAG_NAME_MISSING , messageText); - message.setOffset(start); - message.setLength(length); - message.setLineNo(lineNo); - - if (reporter instanceof IncrementalReporter) { - MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor(); - processor.setProblemId(ProblemIDsXML.EmptyTag); - message.setAttribute(QUICKASSISTPROCESSOR, processor); - - AnnotationInfo info = new AnnotationInfo(message); - ((IncrementalReporter) reporter).addAnnotationInfo(this, info); - } - else { - reporter.addMessage(this, message); - } - } - } - } - - private int getLineNumber(int start) { - int lineNo = -1; - try { - lineNo = getDocument().getLineOfOffset(start) + 1; - } - catch (BadLocationException e) { - Logger.logException(e); - } - return lineNo; - } - - private void checkForAttributeValue(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) { - if (structuredDocumentRegion.isDeleted()) { - return; - } - - // check for attributes without a value - // track the attribute/equals/value sequence using a state of 0, 1 ,2 - // representing the name, =, and value, respectively - int attrState = 0; - ITextRegionList textRegions = structuredDocumentRegion.getRegions(); - // ReconcileAnnotationKey key = createKey(structuredDocumentRegion, - // getScope()); - - int errorCount = 0; - for (int i = 0; (i < textRegions.size()) && (errorCount < AbstractStructuredTextReconcilingStrategy.ELEMENT_ERROR_LIMIT); i++) { - ITextRegion textRegion = textRegions.get(i); - if ((textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) || isTagCloseTextRegion(textRegion)) { - // dangling name and '=' - if ((attrState == 2) && (i >= 2)) { - // create annotation - ITextRegion nameRegion = textRegions.get(i - 2); - if (!(nameRegion instanceof ITextRegionContainer)) { - Object[] args = {structuredDocumentRegion.getText(nameRegion)}; - String messageText = NLS.bind(XMLUIMessages.Attribute__is_missing_a_value, args); - - int start = structuredDocumentRegion.getStartOffset(nameRegion); - int end = structuredDocumentRegion.getEndOffset(); - int lineNo = getLineNumber(start); - int textLength = structuredDocumentRegion.getText(nameRegion).trim().length(); - - LocalizedMessage message = new LocalizedMessage(SEVERITY_ATTRIBUTE_HAS_NO_VALUE , messageText); - message.setOffset(start); - message.setLength(textLength); - message.setLineNo(lineNo); - - // quick fix info - ITextRegion equalsRegion = textRegions.get(i - 2 + 1); - int insertOffset = structuredDocumentRegion.getTextEndOffset(equalsRegion) - end; - Object[] additionalFixInfo = {structuredDocumentRegion.getText(nameRegion), new Integer(insertOffset)}; - - if (reporter instanceof IncrementalReporter) { - MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor(); - processor.setProblemId(ProblemIDsXML.MissingAttrValue); - processor.setAdditionalFixInfo(additionalFixInfo); - message.setAttribute(QUICKASSISTPROCESSOR, processor); - - AnnotationInfo info = new AnnotationInfo(message); - ((IncrementalReporter) reporter).addAnnotationInfo(this, info); - } - else { - reporter.addMessage(this, message); - } - errorCount++; - } - } - // name but no '=' (XML only) - else if ((attrState == 1) && (i >= 1)) { - // create annotation - ITextRegion previousRegion = textRegions.get(i - 1); - if (!(previousRegion instanceof ITextRegionContainer)) { - Object[] args = {structuredDocumentRegion.getText(previousRegion)}; - String messageText = NLS.bind(XMLUIMessages.Attribute__has_no_value, args); - int start = structuredDocumentRegion.getStartOffset(previousRegion); - int textLength = structuredDocumentRegion.getText(previousRegion).trim().length(); - int lineNo = getLineNumber(start); - - LocalizedMessage message = new LocalizedMessage(SEVERITY_ATTRIBUTE_HAS_NO_VALUE, messageText); - message.setOffset(start); - message.setLength(textLength); - message.setLineNo(lineNo); - - if (reporter instanceof IncrementalReporter) { - MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor(); - processor.setProblemId(ProblemIDsXML.NoAttrValue); - processor.setAdditionalFixInfo(structuredDocumentRegion.getText(previousRegion)); - message.setAttribute(QUICKASSISTPROCESSOR, processor); - - AnnotationInfo info = new AnnotationInfo(message); - ((IncrementalReporter) reporter).addAnnotationInfo(this, info); - } - else { - reporter.addMessage(this, message); - } - - errorCount++; - } - } - attrState = 1; - } - else if (textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) { - attrState = 2; - } - else if (textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) { - attrState = 0; - } - } - - } - - private void checkForSpaceBeforeName(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) { - - if (structuredDocumentRegion.isDeleted()) { - return; - } - - String sdRegionText = structuredDocumentRegion.getFullText(); - if (sdRegionText.startsWith(" ")) { //$NON-NLS-1$ - IStructuredDocumentRegion prev = structuredDocumentRegion.getPrevious(); - if (prev != null) { - // this is possibly the case of "< tag" - if ((prev.getRegions().size() == 1) && isStartTag(prev)) { - // add the error for preceding space in tag name - String messageText = XMLUIMessages.ReconcileStepForMarkup_2; - int start = structuredDocumentRegion.getStartOffset(); - // find length of whitespace - int length = sdRegionText.trim().equals("") ? sdRegionText.length() : sdRegionText.indexOf(sdRegionText.trim()); //$NON-NLS-1$ - - LocalizedMessage message = new LocalizedMessage(SEVERITY_INVALID_WHITESPACE_BEFORE_TAGNAME , messageText); - message.setOffset(start); - message.setLength(length); - message.setLineNo(getLineNumber(start)); - - if (reporter instanceof IncrementalReporter) { - MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor(); - processor.setProblemId(ProblemIDsXML.SpacesBeforeTagName); - message.setAttribute(QUICKASSISTPROCESSOR, processor); - - AnnotationInfo info = new AnnotationInfo(message); - ((IncrementalReporter) reporter).addAnnotationInfo(this, info); - } - else { - reporter.addMessage(this, message); - } - } - } - } - } - - private void checkNoNamespaceInPI(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) { - - if (structuredDocumentRegion.isDeleted()) { - return; - } - - // navigate to name - ITextRegionList regions = structuredDocumentRegion.getRegions(); - ITextRegion r = null; - int errorCount = 0; - for (int i = 0; (i < regions.size()) && (errorCount < AbstractStructuredTextReconcilingStrategy.ELEMENT_ERROR_LIMIT) && !structuredDocumentRegion.isDeleted(); i++) { - r = regions.get(i); - if (r.getType() == DOMRegionContext.XML_TAG_NAME) { - String piText = structuredDocumentRegion.getText(r); - int index = piText.indexOf(":"); //$NON-NLS-1$ - if (index != -1) { - String messageText = XMLUIMessages.ReconcileStepForMarkup_4; - int start = structuredDocumentRegion.getStartOffset(r) + index; - int length = piText.trim().length() - index; - - LocalizedMessage message = new LocalizedMessage(SEVERITY_NAMESPACE_IN_PI_TARGET , messageText); - message.setOffset(start); - message.setLength(length); - message.setLineNo(getLineNumber(start)); - - if (reporter instanceof IncrementalReporter) { - MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor(); - processor.setProblemId(ProblemIDsXML.NamespaceInPI); - message.setAttribute(QUICKASSISTPROCESSOR, processor); - - AnnotationInfo info = new AnnotationInfo(message); - ((IncrementalReporter) reporter).addAnnotationInfo(this, info); - } - else { - reporter.addMessage(this, message); - } - - errorCount++; - } - } - } - } - - private void checkQuotesForAttributeValues(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) { - ITextRegionList regions = structuredDocumentRegion.getRegions(); - ITextRegion r = null; - String attrValueText = ""; //$NON-NLS-1$ - int errorCount = 0; - for (int i = 0; (i < regions.size()) && (errorCount < AbstractStructuredTextReconcilingStrategy.ELEMENT_ERROR_LIMIT); i++) { - r = regions.get(i); - if (r.getType() != DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) { - continue; - } - - attrValueText = structuredDocumentRegion.getText(r); - // attribute value includes quotes in the string - // split up attribute value on quotes - /* - * WORKAROUND till - * http://dev.icu-project.org/cgi-bin/icu-bugs/incoming?findid=5207 - * is fixed. (Also see BUG143628) - */ - - java.util.StringTokenizer st = new java.util.StringTokenizer(attrValueText, "\"'", true); //$NON-NLS-1$ - int size = st.countTokens(); - // get the pieces of the attribute value - String one = "", two = ""; //$NON-NLS-1$ //$NON-NLS-2$ - if (size > 0) { - one = st.nextToken(); - } - if (size > 1) { - two = st.nextToken(); - } - if (size > 2) { - // should be handled by parsing... - // as in we can't have an attribute value like: <element - // attr="a"b"c"/> - // and <element attr='a"b"c' /> is legal - continue; - } - - - if (size == 1) { - if (one.equals(DQUOTE) || one.equals(SQUOTE)) { - // missing closing quote - String message = XMLUIMessages.ReconcileStepForMarkup_0; - addAttributeError(message, attrValueText, structuredDocumentRegion.getStartOffset(r), attrValueText.trim().length(), ProblemIDsXML.Unclassified, structuredDocumentRegion, reporter, SEVERITY_MISSING_CLOSING_QUOTE); - errorCount++; - } - else { - // missing both - String message = XMLUIMessages.ReconcileStepForMarkup_1; - addAttributeError(message, attrValueText, structuredDocumentRegion.getStartOffset(r), attrValueText.trim().length(), ProblemIDsXML.AttrValueNotQuoted, structuredDocumentRegion, reporter, SEVERITY_MISSING_QUOTES); - errorCount++; - } - } - else if (size == 2) { - if ((one.equals(SQUOTE) && !two.equals(SQUOTE)) || (one.equals(DQUOTE) && !two.equals(DQUOTE))) { - // missing closing quote - String message = XMLUIMessages.ReconcileStepForMarkup_0; - addAttributeError(message, attrValueText, structuredDocumentRegion.getStartOffset(r), attrValueText.trim().length(), ProblemIDsXML.Unclassified, structuredDocumentRegion, reporter, SEVERITY_MISSING_CLOSING_QUOTE); - errorCount++; - } - } - } - // end of region for loop - } - - private void checkStartEndTagPairs(IStructuredDocumentRegion sdRegion, IReporter reporter) { - - if (sdRegion.isDeleted()) { - return; - } - - // check start/end tag pairs - IDOMNode xmlNode = getXMLNode(sdRegion); - - if (xmlNode == null) { - return; - } - - boolean selfClosed = false; - String tagName = null; - - /** - * For tags that aren't meant to be EMPTY, make sure it's empty or has an end tag - */ - if (xmlNode.isContainer()) { - IStructuredDocumentRegion endRegion = xmlNode.getEndStructuredDocumentRegion(); - if (endRegion == null) { - IStructuredDocumentRegion startRegion = xmlNode.getStartStructuredDocumentRegion(); - if (startRegion != null && !startRegion.isDeleted() && DOMRegionContext.XML_TAG_OPEN.equals(startRegion.getFirstRegion().getType())) { - // analyze the tag (check self closing) - ITextRegionList regions = startRegion.getRegions(); - ITextRegion r = null; - int start = sdRegion.getStart(); - int length = sdRegion.getTextLength(); - for (int i = 0; i < regions.size(); i++) { - r = regions.get(i); - if (r.getType() == DOMRegionContext.XML_TAG_NAME) { - tagName = sdRegion.getText(r); - start = sdRegion.getStartOffset(r); - length = r.getTextLength(); - } - else if (r.getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE) { - selfClosed = true; - } - } - - - if (!selfClosed && (tagName != null)) { - Object[] args = {tagName}; - String messageText = NLS.bind(XMLUIMessages.Missing_end_tag_, args); - - int lineNumber = getLineNumber(start); - - IMessage message = new LocalizedMessage(SEVERITY_MISSING_END_TAG , messageText); - message.setOffset(start); - message.setLength(length); - message.setLineNo(lineNumber); - - if (reporter instanceof IncrementalReporter) { - Object[] additionalFixInfo = getStartEndFixInfo(xmlNode, tagName, r); - - MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor(); - processor.setProblemId(ProblemIDsXML.MissingEndTag); - processor.setAdditionalFixInfo(additionalFixInfo); - message.setAttribute(QUICKASSISTPROCESSOR, processor); - - AnnotationInfo info = new AnnotationInfo(message); - - ((IncrementalReporter) reporter).addAnnotationInfo(this, info); - } - else { - reporter.addMessage(this, message); - } - } - } - } - else { - IStructuredDocumentRegion startRegion = xmlNode.getStartStructuredDocumentRegion(); - if (startRegion == null || startRegion.isDeleted()) { - // analyze the tag (check self closing) - ITextRegionList regions = endRegion.getRegions(); - ITextRegion r = null; - int start = sdRegion.getStart(); - int length = sdRegion.getTextLength(); - for (int i = 0; i < regions.size(); i++) { - r = regions.get(i); - if (r.getType() == DOMRegionContext.XML_TAG_NAME) { - tagName = sdRegion.getText(r); - start = sdRegion.getStartOffset(r); - length = r.getTextLength(); - } - } - - if (tagName != null) { - Object[] args = {tagName}; - String messageText = NLS.bind(XMLUIMessages.Missing_start_tag_, args); - - int lineNumber = getLineNumber(start); - - IMessage message = new LocalizedMessage(SEVERITY_MISSING_START_TAG, messageText); - message.setOffset(start); - message.setLength(length); - message.setLineNo(lineNumber); - - if (reporter instanceof IncrementalReporter) { - Object[] additionalFixInfo = getStartEndFixInfo(xmlNode, tagName, r); - - MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor(); - processor.setProblemId(ProblemIDsXML.MissingStartTag); - processor.setAdditionalFixInfo(additionalFixInfo); - message.setAttribute(QUICKASSISTPROCESSOR, processor); - - AnnotationInfo info = new AnnotationInfo(message); - - ((IncrementalReporter) reporter).addAnnotationInfo(this, info); - } - else { - reporter.addMessage(this, message); - } - } - } - } - - } - /* - * Check for an end tag that has no start tag - */ - else { - IStructuredDocumentRegion startRegion = xmlNode.getStartStructuredDocumentRegion(); - if (startRegion == null) { - IStructuredDocumentRegion endRegion = xmlNode.getEndStructuredDocumentRegion(); - if (!endRegion.isDeleted()) { - // get name - ITextRegionList regions = endRegion.getRegions(); - ITextRegion r = null; - for (int i = 0; i < regions.size(); i++) { - r = regions.get(i); - if (r.getType() == DOMRegionContext.XML_TAG_NAME) { - tagName = sdRegion.getText(r); - } - } - - if (!selfClosed && (tagName != null)) { - String messageText = StringUtils.unpack(XMLUIMessages.Indicate_no_grammar_specified_severities)[0]; - - int start = sdRegion.getStart(); - int lineNumber = getLineNumber(start); - - // SEVERITY_STRUCTURE == IMessage.HIGH_SEVERITY - IMessage message = new LocalizedMessage(IMessage.HIGH_SEVERITY, messageText); - message.setOffset(start); - message.setLength(sdRegion.getTextLength()); - message.setLineNo(lineNumber); - - reporter.addMessage(this, message); - } - } - } - } - } - - private Object[] getStartEndFixInfo(IDOMNode xmlNode, String tagName, ITextRegion r) { - // quick fix info - String tagClose = "/>"; //$NON-NLS-1$ - int tagCloseOffset = xmlNode.getFirstStructuredDocumentRegion().getEndOffset(); - if ((r != null) && (r.getType() == DOMRegionContext.XML_TAG_CLOSE)) { - tagClose = "/"; //$NON-NLS-1$ - tagCloseOffset--; - } - IDOMNode firstChild = (IDOMNode) xmlNode.getFirstChild(); - while ((firstChild != null) && (firstChild.getNodeType() == Node.TEXT_NODE)) { - firstChild = (IDOMNode) firstChild.getNextSibling(); - } - int endOffset = xmlNode.getEndOffset(); - int firstChildStartOffset = firstChild == null ? endOffset : firstChild.getStartOffset(); - Object[] additionalFixInfo = {tagName, tagClose, new Integer(tagCloseOffset), new Integer(xmlNode.getFirstStructuredDocumentRegion().getEndOffset()), // startTagEndOffset - new Integer(firstChildStartOffset), // firstChildStartOffset - new Integer(endOffset)}; // endOffset - return additionalFixInfo; - } - - private void checkStartingSpaceForPI(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) { - - if (structuredDocumentRegion.isDeleted()) { - return; - } - - IStructuredDocumentRegion prev = structuredDocumentRegion.getPrevious(); - if ((prev != null) && prev.getStartOffset() == 0) { - if (prev.getType() == DOMRegionContext.XML_CONTENT) { - String messageText = XMLUIMessages.ReconcileStepForMarkup_5; - int start = prev.getStartOffset(); - int length = prev.getLength(); - - LocalizedMessage message = new LocalizedMessage(SEVERITY_WHITESPACE_AT_START , messageText); - message.setOffset(start); - message.setLength(length); - message.setLineNo(getLineNumber(start)); - - if (reporter instanceof IncrementalReporter) { - MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor(); - processor.setProblemId(ProblemIDsXML.SpacesBeforePI); - message.setAttribute(QUICKASSISTPROCESSOR, processor); - - AnnotationInfo info = new AnnotationInfo(message); - ((IncrementalReporter) reporter).addAnnotationInfo(this, info); - } - else { - reporter.addMessage(this, message); - } - // Position p = new Position(start, length); - // - // ReconcileAnnotationKey key = - // createKey(structuredDocumentRegion, getScope()); - // TemporaryAnnotation annotation = new TemporaryAnnotation(p, - // SEVERITY_SYNTAX_ERROR, message, key, - // ProblemIDsXML.SpacesBeforePI); - // results.add(annotation); - } - } - } - - public int getScope() { - return ReconcileAnnotationKey.PARTIAL; - } - - private IDOMNode getXMLNode(IStructuredDocumentRegion sdRegion) { - - if (sdRegion == null) { - return null; - } - - IStructuredModel xModel = null; - IDOMNode xmlNode = null; - // get/release models should always be in a try/finally block - try { - xModel = StructuredModelManager.getModelManager().getExistingModelForRead(getDocument()); - // xModel is sometime null, when closing editor, for example - if (xModel != null) { - xmlNode = (IDOMNode) xModel.getIndexedRegion(sdRegion.getStart()); - } - } - finally { - if (xModel != null) { - xModel.releaseFromRead(); - } - } - return xmlNode; - } - - /** - * Determines whether the IStructuredDocumentRegion is a XML "end tag" - * since they're not allowed to have attribute ITextRegions - * - * @param structuredDocumentRegion - */ - private boolean isEndTag(IStructuredDocumentRegion structuredDocumentRegion) { - if ((structuredDocumentRegion == null) || structuredDocumentRegion.isDeleted()) { - return false; - } - return structuredDocumentRegion.getFirstRegion().getType() == DOMRegionContext.XML_END_TAG_OPEN; - } - - /** - * Determines if the IStructuredDocumentRegion is an XML Processing - * Instruction - * - * @param structuredDocumentRegion - * - */ - private boolean isPI(IStructuredDocumentRegion structuredDocumentRegion) { - if ((structuredDocumentRegion == null) || structuredDocumentRegion.isDeleted()) { - return false; - } - return structuredDocumentRegion.getFirstRegion().getType() == DOMRegionContext.XML_PI_OPEN; - } - - /** - * Determines whether the IStructuredDocumentRegion is a XML "start tag" - * since they need to be checked for proper XML attribute region sequences - * - * @param structuredDocumentRegion - * - */ - private boolean isStartTag(IStructuredDocumentRegion structuredDocumentRegion) { - if ((structuredDocumentRegion == null) || structuredDocumentRegion.isDeleted()) { - return false; - } - return structuredDocumentRegion.getFirstRegion().getType() == DOMRegionContext.XML_TAG_OPEN; - } - - // Because we check the "proper" closing separately from attribute - // sequencing, we need to know what's - // an appropriate close. - private boolean isTagCloseTextRegion(ITextRegion textRegion) { - return (textRegion.getType() == DOMRegionContext.XML_TAG_CLOSE) || (textRegion.getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE); - } - - /** - * Determines if the IStructuredDocumentRegion is XML Content - * - * @param structuredDocumentRegion - * - */ - private boolean isXMLContent(IStructuredDocumentRegion structuredDocumentRegion) { - if ((structuredDocumentRegion == null) || structuredDocumentRegion.isDeleted()) { - return false; - } - return structuredDocumentRegion.getFirstRegion().getType() == DOMRegionContext.XML_CONTENT; - } - - private void setDocument(IDocument doc) { - fDocument = doc; - } - - private IDocument getDocument() { - return fDocument; - } - - public void connect(IDocument document) { - setDocument(document); - } - - public void disconnect(IDocument document) { - setDocument(null); - } - - public void validate(IRegion dirtyRegion, IValidationContext helper, IReporter reporter) { - if (getDocument() == null) { - return; - } - if (!(reporter instanceof IncrementalReporter)) { - return; - } - if (!(getDocument() instanceof IStructuredDocument)) { - return; - } - - // remove old messages - reporter.removeAllMessages(this); - - IStructuredDocumentRegion[] regions = ((IStructuredDocument) fDocument).getStructuredDocumentRegions(dirtyRegion.getOffset(), dirtyRegion.getLength()); - for (int i = 0; i < regions.length; i++) { - validate(regions[i], reporter); - } - } - - public void validate(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) { - - if (structuredDocumentRegion == null) { - return; - } - - if (isStartTag(structuredDocumentRegion)) { - // check for attributes without a value - checkForAttributeValue(structuredDocumentRegion, reporter); - // check if started tag is ended - checkStartEndTagPairs(structuredDocumentRegion, reporter); - // check empty tag <> - checkEmptyTag(structuredDocumentRegion, reporter); - // check that each attribute has quotes - checkQuotesForAttributeValues(structuredDocumentRegion, reporter); - // check that the closing '>' is there - checkClosingBracket(structuredDocumentRegion, reporter); - } - else if (isEndTag(structuredDocumentRegion)) { - // check if ending tag was started - checkStartEndTagPairs(structuredDocumentRegion, reporter); - // check for attributes in an end tag - checkAttributesInEndTag(structuredDocumentRegion, reporter); - // check that the closing '>' is there - checkClosingBracket(structuredDocumentRegion, reporter); - } - else if (isPI(structuredDocumentRegion)) { - // check validity of processing instruction - checkStartingSpaceForPI(structuredDocumentRegion, reporter); - checkNoNamespaceInPI(structuredDocumentRegion, reporter); - } - else if (isXMLContent(structuredDocumentRegion)) { - checkForSpaceBeforeName(structuredDocumentRegion, reporter); - } - else if (isXMLDoctypeDeclaration(structuredDocumentRegion)) { - checkDocumentTypeReferences(structuredDocumentRegion, reporter); - } - } - - /** - * @param structuredDocumentRegion - * @param reporter - */ - private void checkDocumentTypeReferences(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) { - } - - /** - * @param structuredDocumentRegion - * @return - */ - private boolean isXMLDoctypeDeclaration(IStructuredDocumentRegion structuredDocumentRegion) { - if ((structuredDocumentRegion == null) || structuredDocumentRegion.isDeleted()) { - return false; - } - return structuredDocumentRegion.getFirstRegion().getType() == DOMRegionContext.XML_DECLARATION_OPEN && structuredDocumentRegion.getType().equals(DOMRegionContext.XML_DOCTYPE_DECLARATION); - } - - public void cleanup(IReporter reporter) { - fDocument = null; - } - - public void validate(IValidationContext helper, IReporter reporter) throws ValidationException { - String[] uris = helper.getURIs(); - IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); - if (uris.length > 0) { - IFile currentFile = null; - - for (int i = 0; i < uris.length && !reporter.isCancelled(); i++) { - // might be called with just project path? - IPath path = new Path(uris[i]); - if (path.segmentCount() > 1) { - currentFile = wsRoot.getFile(path); - if (shouldValidate(currentFile, true)) { - validateV1File(currentFile, reporter); - } - } - else if (uris.length == 1) { - validateV1Project(helper, reporter); - } - } - } - else - validateV1Project(helper, reporter); - } - - private boolean shouldValidate(IResourceProxy proxy) { - if(proxy.getType() == IResource.FILE) { - String name = proxy.getName(); - if(name.toLowerCase(Locale.US).endsWith(".xml")) { - return true; - } - } - return shouldValidate(proxy.requestResource(), false); - } - - private boolean shouldValidate(IResource file, boolean checkExtension) { - if (file == null || !file.exists() || file.getType() != IResource.FILE) - return false; - if (checkExtension) { - String extension = file.getFileExtension(); - if (extension != null && "xml".endsWith(extension.toLowerCase(Locale.US))) - return true; - } - - IContentDescription contentDescription = null; - try { - contentDescription = ((IFile) file).getContentDescription(); - if (contentDescription != null) { - IContentType contentType = contentDescription.getContentType(); - return contentDescription != null && contentType.isKindOf(getXMLContentType()); - } - } - catch (CoreException e) { - Logger.logException(e); - } - return false; - } - - /** - * @param helper - * @param reporter - */ - private void validateV1Project(IValidationContext helper, final IReporter reporter) { - // if uris[] length 0 -> validate() gets called for each project - if (helper instanceof IWorkbenchContext) { - IProject project = ((IWorkbenchContext) helper).getProject(); - IResourceProxyVisitor visitor = new IResourceProxyVisitor() { - public boolean visit(IResourceProxy proxy) throws CoreException { - if (shouldValidate(proxy)) { - validateV1File((IFile) proxy.requestResource(), reporter); - } - return true; - } - }; - try { - // collect all jsp files for the project - project.accept(visitor, IResource.DEPTH_INFINITE); - } - catch (CoreException e) { - Logger.logException(e); - } - } - } - - - /** - * @param currentFile - * @param reporter - */ - private void validateV1File(IFile currentFile, IReporter reporter) { - Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, currentFile.getFullPath().toString().substring(1)); - reporter.displaySubtask(MarkupValidator.this, message); - - IStructuredModel model = null; - try { - model = StructuredModelManager.getModelManager().getModelForRead(currentFile); - IStructuredDocument document = null; - if (model != null) { - document = model.getStructuredDocument(); - connect(document); - IStructuredDocumentRegion validationRegion = document.getFirstStructuredDocumentRegion(); - while (validationRegion != null) { - validate(validationRegion, reporter); - validationRegion = validationRegion.getNext(); - } - disconnect(document); - } - } - catch (Exception e) { - Logger.logException(e); - } - finally { - if (model != null) { - model.releaseFromRead(); - } - } - } - - /** - * @return - */ - private IContentType getXMLContentType() { - if (fRootContentType == null) { - fRootContentType = Platform.getContentTypeManager().getContentType("org.eclipse.core.runtime.xml"); - } - return fRootContentType; - } - - /* (non-Javadoc) - * @see org.eclipse.wst.validation.AbstractValidator#validate(org.eclipse.core.resources.IResource, int, org.eclipse.wst.validation.ValidationState, org.eclipse.core.runtime.IProgressMonitor) - */ - public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) { - if (resource.getType() != IResource.FILE) - return null; - ValidationResult result = new ValidationResult(); - IReporter reporter = result.getReporter(monitor); - validateV1File((IFile) resource, reporter); - return result; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/contentoutline/AbstractXMLContentOutlineConfiguration.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/contentoutline/AbstractXMLContentOutlineConfiguration.java deleted file mode 100644 index c5362745af..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/contentoutline/AbstractXMLContentOutlineConfiguration.java +++ /dev/null @@ -1,338 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.views.contentoutline; - -import org.eclipse.core.runtime.IPath; -import org.eclipse.jface.action.IMenuListener; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.util.LocalSelectionTransfer; -import org.eclipse.jface.util.SafeRunnable; -import org.eclipse.jface.util.TransferDragSourceListener; -import org.eclipse.jface.util.TransferDropTargetListener; -import org.eclipse.jface.viewers.IContentProvider; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.swt.dnd.DND; -import org.eclipse.swt.dnd.DragSourceEvent; -import org.eclipse.swt.dnd.DropTargetEvent; -import org.eclipse.swt.dnd.Transfer; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.TableItem; -import org.eclipse.swt.widgets.TreeItem; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.ui.internal.IReleasable; -import org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.internal.contentoutline.JFaceNodeContentProvider; -import org.eclipse.wst.xml.ui.internal.contentoutline.JFaceNodeLabelProvider; -import org.eclipse.wst.xml.ui.internal.contentoutline.XMLNodeActionManager; -import org.eclipse.wst.xml.ui.internal.dnd.DragNodeCommand; -import org.w3c.dom.Node; - -/** - * Basic Outline Configuration for generic XML support. Expects that the viewer's - * input will be the DOM Model, and provides basic label and content providers. - * - * @see org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration - * @since 3.1 - */ -public abstract class AbstractXMLContentOutlineConfiguration extends ContentOutlineConfiguration { - private class ActionManagerMenuListener implements IMenuListener, IReleasable { - private XMLNodeActionManager fActionManager; - private TreeViewer fTreeViewer; - - public ActionManagerMenuListener(TreeViewer viewer) { - fTreeViewer = viewer; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.action.IMenuListener#menuAboutToShow(org.eclipse.jface.action.IMenuManager) - */ - public void menuAboutToShow(IMenuManager manager) { - if (fActionManager == null) { - fActionManager = createNodeActionManager(fTreeViewer); - } - if (fActionManager != null) { - fActionManager.fillContextMenu(manager, fTreeViewer.getSelection()); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.internal.IReleasable#release() - */ - public void release() { - fTreeViewer = null; - if (fActionManager != null) { - fActionManager.setModel(null); - } - } - } - - private static class StatusLineLabelProvider extends JFaceNodeLabelProvider { - TreeViewer treeViewer = null; - - public StatusLineLabelProvider(TreeViewer viewer) { - treeViewer = viewer; - } - - public String getText(Object element) { - if (element == null) - return null; - - if (!(element instanceof Node)) { - return super.getText(element); - } - - StringBuffer s = new StringBuffer(); - Node node = (Node) element; - while (node != null) { - if (node.getNodeType() != Node.DOCUMENT_NODE) { - s.insert(0, super.getText(node)); - } - node = node.getParentNode(); - if (node != null && node.getNodeType() != Node.DOCUMENT_NODE) { - s.insert(0, IPath.SEPARATOR); - } - } - return s.toString(); - } - } - - private IContentProvider fContentProvider = null; - - private ActionManagerMenuListener fContextMenuFiller = null; - - private ILabelProvider fLabelProvider = null; - - boolean fShowAttributes = false; - - private ILabelProvider fSimpleLabelProvider; - private TransferDragSourceListener[] fTransferDragSourceListeners; - - private TransferDropTargetListener[] fTransferDropTargetListeners; - - /** - * Create new instance of XMLContentOutlineConfiguration - */ - public AbstractXMLContentOutlineConfiguration() { - // Must have empty constructor to createExecutableExtension - super(); - } - - /** - * Returns the NodeActionManager to use for the given treeViewer. - * <p> - * Not API. May be removed in the future. - * </p> - * - * @param treeViewer - * the TreeViewer associated with this configuration - * @return a node action manager for use with this tree viewer - */ - protected XMLNodeActionManager createNodeActionManager(TreeViewer treeViewer) { - return new XMLNodeActionManager((IStructuredModel) treeViewer.getInput(), treeViewer); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration#getContentProvider(org.eclipse.jface.viewers.TreeViewer) - */ - public IContentProvider getContentProvider(TreeViewer viewer) { - if (fContentProvider == null) { - fContentProvider = new JFaceNodeContentProvider(); - } - return fContentProvider; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration#getLabelProvider(org.eclipse.jface.viewers.TreeViewer) - */ - public ILabelProvider getLabelProvider(TreeViewer viewer) { - if (fLabelProvider == null) { - fLabelProvider = new JFaceNodeLabelProvider(); - } - return fLabelProvider; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration#getMenuListener(org.eclipse.jface.viewers.TreeViewer) - */ - public IMenuListener getMenuListener(TreeViewer viewer) { - if (fContextMenuFiller == null) { - fContextMenuFiller = new ActionManagerMenuListener(viewer); - } - return fContextMenuFiller; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration#getPreferenceStore() - */ - protected IPreferenceStore getPreferenceStore() { - return XMLUIPlugin.getDefault().getPreferenceStore(); - } - - public ILabelProvider getStatusLineLabelProvider(TreeViewer treeViewer) { - if (fSimpleLabelProvider == null) { - fSimpleLabelProvider = new StatusLineLabelProvider(treeViewer); - } - return fSimpleLabelProvider; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration#getTransferDragSourceListeners(org.eclipse.jface.viewers.TreeViewer) - */ - public TransferDragSourceListener[] getTransferDragSourceListeners(final TreeViewer treeViewer) { - if (fTransferDragSourceListeners == null) { - fTransferDragSourceListeners = new TransferDragSourceListener[]{new TransferDragSourceListener() { - - public void dragFinished(DragSourceEvent event) { - LocalSelectionTransfer.getTransfer().setSelection(null); - } - - public void dragSetData(DragSourceEvent event) { - } - - public void dragStart(DragSourceEvent event) { - LocalSelectionTransfer.getTransfer().setSelection(treeViewer.getSelection()); - } - - public Transfer getTransfer() { - return LocalSelectionTransfer.getTransfer(); - } - }}; - } - - return fTransferDragSourceListeners; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration#getTransferDropTargetListeners(org.eclipse.jface.viewers.TreeViewer) - */ - public TransferDropTargetListener[] getTransferDropTargetListeners(final TreeViewer treeViewer) { - if (fTransferDropTargetListeners == null) { - fTransferDropTargetListeners = new TransferDropTargetListener[]{new TransferDropTargetListener() { - public void dragEnter(DropTargetEvent event) { - } - - public void dragLeave(DropTargetEvent event) { - } - - public void dragOperationChanged(DropTargetEvent event) { - } - - public void dragOver(DropTargetEvent event) { - event.feedback = DND.FEEDBACK_SELECT; - float feedbackFloat = getHeightInItem(event); - if (feedbackFloat > 0.75) { - event.feedback = DND.FEEDBACK_INSERT_AFTER; - } - else if (feedbackFloat < 0.25) { - event.feedback = DND.FEEDBACK_INSERT_BEFORE; - } - event.feedback |= DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL; - } - - public void drop(DropTargetEvent event) { - if (event.operations != DND.DROP_NONE && LocalSelectionTransfer.getTransfer().getSelection() != null && !LocalSelectionTransfer.getTransfer().getSelection().isEmpty()) { - IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection(); - if (selection != null && !selection.isEmpty() && event.item != null && event.item.getData() != null) { - /* - * the command uses these numbers instead of the - * feedback constants (even though it converts in - * the other direction as well) - */ - float feedbackFloat = getHeightInItem(event); - - final DragNodeCommand command = new DragNodeCommand(event.item.getData(), feedbackFloat, event.operations, event.detail, selection.toList(), treeViewer); - if (command != null && command.canExecute()) { - SafeRunnable.run(new SafeRunnable() { - public void run() throws Exception { - command.execute(); - } - }); - } - } - } - } - - public void dropAccept(DropTargetEvent event) { - } - - private float getHeightInItem(DropTargetEvent event) { - if (event.item == null) - return .5f; - if (event.item instanceof TreeItem) { - TreeItem treeItem = (TreeItem) event.item; - Control control = treeItem.getParent(); - Point point = control.toControl(new Point(event.x, event.y)); - Rectangle bounds = treeItem.getBounds(); - return (float) (point.y - bounds.y) / (float) bounds.height; - } - else if (event.item instanceof TableItem) { - TableItem tableItem = (TableItem) event.item; - Control control = tableItem.getParent(); - Point point = control.toControl(new Point(event.x, event.y)); - Rectangle bounds = tableItem.getBounds(0); - return (float) (point.y - bounds.y) / (float) bounds.height; - } - else { - return 0.0F; - } - } - - public Transfer getTransfer() { - return LocalSelectionTransfer.getTransfer(); - } - - public boolean isEnabled(DropTargetEvent event) { - return getTransfer().isSupportedType(event.currentDataType); - } - }}; - } - return fTransferDropTargetListeners; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration#unconfigure(org.eclipse.jface.viewers.TreeViewer) - */ - public void unconfigure(TreeViewer viewer) { - super.unconfigure(viewer); - fTransferDragSourceListeners = null; - fTransferDropTargetListeners = null; - if (fContextMenuFiller != null) { - fContextMenuFiller.release(); - fContextMenuFiller = null; - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/contentoutline/XMLContentOutlineConfiguration.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/contentoutline/XMLContentOutlineConfiguration.java deleted file mode 100644 index ec3f156834..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/contentoutline/XMLContentOutlineConfiguration.java +++ /dev/null @@ -1,411 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.views.contentoutline; - -import java.util.List; - -import org.eclipse.jface.action.IContributionItem; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.viewers.IContentProvider; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.wst.sse.core.utils.StringUtils; -import org.eclipse.wst.sse.ui.internal.contentoutline.PropertyChangeUpdateAction; -import org.eclipse.wst.sse.ui.internal.contentoutline.PropertyChangeUpdateActionContributionItem; -import org.eclipse.wst.sse.ui.internal.editor.EditorPluginImageHelper; -import org.eclipse.wst.sse.ui.internal.editor.EditorPluginImages; -import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.contentoutline.JFaceNodeContentProvider; -import org.eclipse.wst.xml.ui.internal.contentoutline.JFaceNodeLabelProvider; -import org.eclipse.wst.xml.ui.internal.preferences.XMLUIPreferenceNames; -import org.w3c.dom.Attr; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; - -/** - * More advanced Outline Configuration for XML support. Expects that the viewer's - * input will be the DOM Model. - * - * @see AbstractXMLContentOutlineConfiguration - * @since 1.0 - */ -public class XMLContentOutlineConfiguration extends AbstractXMLContentOutlineConfiguration { - static final String ATTR_NAME = "name"; - static final String ATTR_ID = "id"; - - private class AttributeShowingLabelProvider extends JFaceNodeLabelProvider { - public boolean isLabelProperty(Object element, String property) { - return true; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object) - */ - public String getText(Object o) { - StringBuffer text = null; - if (o instanceof Node) { - Node node = (Node) o; - if ((node.getNodeType() == Node.ELEMENT_NODE) && fShowAttributes) { - text = new StringBuffer(super.getText(o)); - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=88444 - if (node.hasAttributes()) { - Element element = (Element) node; - NamedNodeMap attributes = element.getAttributes(); - Node idTypedAttribute = null; - Node requiredAttribute = null; - boolean hasId = false; - boolean hasName = false; - Node shownAttribute = null; - - // try to get content model element - // declaration - CMElementDeclaration elementDecl = null; - ModelQuery mq = ModelQueryUtil.getModelQuery(element.getOwnerDocument()); - if (mq != null) { - elementDecl = mq.getCMElementDeclaration(element); - } - // find an attribute of type (or just named) - // ID - if (elementDecl != null) { - int i = 0; - while ((i < attributes.getLength()) && (idTypedAttribute == null)) { - Node attr = attributes.item(i); - String attrName = attr.getNodeName(); - CMNamedNodeMap attributeDeclarationMap = elementDecl.getAttributes(); - - CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(attributeDeclarationMap); - List nodes = ModelQueryUtil.getModelQuery(node.getOwnerDocument()).getAvailableContent(element, elementDecl, ModelQuery.INCLUDE_ATTRIBUTES); - for (int k = 0; k < nodes.size(); k++) { - CMNode cmnode = (CMNode) nodes.get(k); - if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) { - allAttributes.put(cmnode); - } - } - attributeDeclarationMap = allAttributes; - - CMAttributeDeclaration attrDecl = (CMAttributeDeclaration) attributeDeclarationMap.getNamedItem(attrName); - if (attrDecl != null) { - if ((attrDecl.getAttrType() != null) && (CMDataType.ID.equals(attrDecl.getAttrType().getDataTypeName()))) { - idTypedAttribute = attr; - } - else if ((attrDecl.getUsage() == CMAttributeDeclaration.REQUIRED) && (requiredAttribute == null)) { - // as a backup, keep tabs on - // any required - // attributes - requiredAttribute = attr; - } - else { - hasId = hasId || attrName.equals(ATTR_ID); - hasName = hasName || attrName.equals(ATTR_NAME); - } - } - ++i; - } - } - - /* - * If no suitable attribute was found, try using a - * required attribute, if none, then prefer "id" or - * "name", otherwise just use first attribute - */ - if (idTypedAttribute != null) { - shownAttribute = idTypedAttribute; - } - else if (requiredAttribute != null) { - shownAttribute = requiredAttribute; - } - else if (hasId) { - shownAttribute = attributes.getNamedItem(ATTR_ID); - } - else if (hasName) { - shownAttribute = attributes.getNamedItem(ATTR_NAME); - } - if (shownAttribute == null) { - shownAttribute = attributes.item(0); - } - - // display the attribute and value (without quotes) - String attributeName = shownAttribute.getNodeName(); - if ((attributeName != null) && (attributeName.length() > 0)) { - text.append(" "); //$NON-NLS-1$ - text.append(attributeName); - String attributeValue = shownAttribute.getNodeValue(); - if ((attributeValue != null) && (attributeValue.length() > 0)) { - text.append("="); //$NON-NLS-1$ - text.append(StringUtils.strip(attributeValue)); - } - } - } - } - else { - text = new StringBuffer(super.getText(o)); - } - } - else { - return super.toString(); - } - return text.toString(); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.CellLabelProvider#getToolTipText(java.lang.Object) - */ - public String getToolTipText(Object element) { - if (element instanceof Node) { - switch (((Node) element).getNodeType()) { - case Node.COMMENT_NODE : - case Node.CDATA_SECTION_NODE : - case Node.PROCESSING_INSTRUCTION_NODE : - case Node.TEXT_NODE : { - String nodeValue = ((Node) element).getNodeValue().trim(); - return prepareText(nodeValue); - } - case Node.ELEMENT_NODE : { - // show the preceding comment's tooltip information - Node previous = ((Node) element).getPreviousSibling(); - if (previous != null && previous.getNodeType() == Node.TEXT_NODE) - previous = previous.getPreviousSibling(); - if (previous != null && previous.getNodeType() == Node.COMMENT_NODE) - return getToolTipText(previous); - } - } - } - return super.getToolTipText(element); - } - - /** - * Remove leading indentation from each line in the give string. - * @param text - * @return - */ - private String prepareText(String text) { - StringBuffer nodeText = new StringBuffer(); - for (int i = 0; i < text.length(); i++) { - char c = text.charAt(i); - if (c != '\r' && c != '\n') { - nodeText.append(c); - } - else if (c == '\r' || c == '\n') { - nodeText.append('\n'); - while (Character.isWhitespace(c) && i < text.length()) { - i++; - c = text.charAt(i); - } - nodeText.append(c); - } - } - return nodeText.toString(); - } - } - - /** - * Toggle action for whether or not to display element's first attribute - */ - private class ToggleShowAttributeAction extends PropertyChangeUpdateAction { - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=88444 - private TreeViewer fTreeViewer; - - public ToggleShowAttributeAction(IPreferenceStore store, String preference, TreeViewer treeViewer) { - super(XMLUIMessages.XMLContentOutlineConfiguration_0, store, preference, true); - setToolTipText(getText()); - // images needed - // setDisabledImageDescriptor(SYNCED_D); - // (nsd) temporarily re-use Properties view image - setImageDescriptor(EditorPluginImageHelper.getInstance().getImageDescriptor(EditorPluginImages.IMG_OBJ_PROP_PS)); - fTreeViewer = treeViewer; - update(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.texteditor.IUpdate#update() - */ - public void update() { - super.update(); - fShowAttributes = isChecked(); - - // notify the configuration of the change - enableShowAttributes(fShowAttributes, fTreeViewer); - - // refresh the outline view - fTreeViewer.refresh(true); - } - } - - private ILabelProvider fAttributeShowingLabelProvider; - private IContentProvider fContentProvider = null; - - boolean fShowAttributes = false; - - /* - * Preference key for Show Attributes - */ - private final String OUTLINE_SHOW_ATTRIBUTE_PREF = "outline-show-attribute"; //$NON-NLS-1$ - - /** - * Create new instance of XMLContentOutlineConfiguration - */ - public XMLContentOutlineConfiguration() { - // Must have empty constructor to createExecutableExtension - super(); - - /** - * Set up our preference store here. This is done so that subclasses - * aren't required to set their own values, although if they have, - * those will be used instead. - */ - IPreferenceStore store = getPreferenceStore(); - if (store.getDefaultString(XMLUIPreferenceNames.OUTLINE_BEHAVIOR.DOCUMENT_NODE).length() == 0) - store.setDefault(XMLUIPreferenceNames.OUTLINE_BEHAVIOR.DOCUMENT_NODE, "1, true"); - if (store.getDefaultString(XMLUIPreferenceNames.OUTLINE_BEHAVIOR.PROCESSING_INSTRUCTION_NODE).length() == 0) - store.setDefault(XMLUIPreferenceNames.OUTLINE_BEHAVIOR.PROCESSING_INSTRUCTION_NODE, "2, true"); - if (store.getDefaultString(XMLUIPreferenceNames.OUTLINE_BEHAVIOR.DOCUMENT_TYPE_NODE).length() == 0) - store.setDefault(XMLUIPreferenceNames.OUTLINE_BEHAVIOR.DOCUMENT_TYPE_NODE, "3, true"); - if (store.getDefaultString(XMLUIPreferenceNames.OUTLINE_BEHAVIOR.DOCUMENT_FRAGMENT_NODE).length() == 0) - store.setDefault(XMLUIPreferenceNames.OUTLINE_BEHAVIOR.DOCUMENT_FRAGMENT_NODE, "4, true"); - if (store.getDefaultString(XMLUIPreferenceNames.OUTLINE_BEHAVIOR.COMMENT_NODE).length() == 0) - store.setDefault(XMLUIPreferenceNames.OUTLINE_BEHAVIOR.COMMENT_NODE, "5, true"); - if (store.getDefaultString(XMLUIPreferenceNames.OUTLINE_BEHAVIOR.ATTRIBUTE_NODE).length() == 0) - store.setDefault(XMLUIPreferenceNames.OUTLINE_BEHAVIOR.ATTRIBUTE_NODE, "6, false"); - if (store.getDefaultString(XMLUIPreferenceNames.OUTLINE_BEHAVIOR.ELEMENT_NODE).length() == 0) - store.setDefault(XMLUIPreferenceNames.OUTLINE_BEHAVIOR.ELEMENT_NODE, "7, true"); - if (store.getDefaultString(XMLUIPreferenceNames.OUTLINE_BEHAVIOR.ENTITY_REFERENCE_NODE).length() == 0) - store.setDefault(XMLUIPreferenceNames.OUTLINE_BEHAVIOR.ENTITY_REFERENCE_NODE, "8, true"); - if (store.getDefaultString(XMLUIPreferenceNames.OUTLINE_BEHAVIOR.CDATA_SECTION_NODE).length() == 0) - store.setDefault(XMLUIPreferenceNames.OUTLINE_BEHAVIOR.CDATA_SECTION_NODE, "9, true"); - if (store.getDefaultString(XMLUIPreferenceNames.OUTLINE_BEHAVIOR.ENTITY_NODE).length() == 0) - store.setDefault(XMLUIPreferenceNames.OUTLINE_BEHAVIOR.ENTITY_NODE, "10, true"); - if (store.getDefaultString(XMLUIPreferenceNames.OUTLINE_BEHAVIOR.NOTATION_NODE).length() == 0) - store.setDefault(XMLUIPreferenceNames.OUTLINE_BEHAVIOR.NOTATION_NODE, "11, true"); - if (store.getDefaultString(XMLUIPreferenceNames.OUTLINE_BEHAVIOR.TEXT_NODE).length() == 0) - store.setDefault(XMLUIPreferenceNames.OUTLINE_BEHAVIOR.TEXT_NODE, "12, false"); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration#createMenuContributions(org.eclipse.jface.viewers.TreeViewer) - */ - protected IContributionItem[] createMenuContributions(TreeViewer viewer) { - IContributionItem[] items; - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=88444 - IContributionItem showAttributeItem = new PropertyChangeUpdateActionContributionItem(new ToggleShowAttributeAction(getPreferenceStore(), OUTLINE_SHOW_ATTRIBUTE_PREF, viewer)); - - items = super.createMenuContributions(viewer); - if (items == null) { - items = new IContributionItem[]{showAttributeItem}; - } - else { - IContributionItem[] combinedItems = new IContributionItem[items.length + 1]; - System.arraycopy(items, 0, combinedItems, 0, items.length); - combinedItems[items.length] = showAttributeItem; - items = combinedItems; - } - return items; - } - - /** - * Notifies this configuration that the flag that indicates whether or not - * to show attribute values in the tree viewer has changed. The tree - * viewer is automatically refreshed afterwards to update the labels. - * - * Clients should not call this method, but rather should react to it. - * - * @param showAttributes - * flag indicating whether or not to show attribute values in - * the tree viewer - * @param treeViewer - * the TreeViewer associated with this configuration - */ - protected void enableShowAttributes(boolean showAttributes, TreeViewer treeViewer) { - // nothing by default - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration#getContentProvider(org.eclipse.jface.viewers.TreeViewer) - */ - public IContentProvider getContentProvider(TreeViewer viewer) { - if (fContentProvider == null) { - fContentProvider = new JFaceNodeContentProvider(); - } - return fContentProvider; - } - - private Object getFilteredNode(Object object) { - if (object instanceof Node) { - Node node = (Node) object; - short nodeType = node.getNodeType(); - // replace attribute node in selection with its parent - if (nodeType == Node.ATTRIBUTE_NODE) { - node = ((Attr) node).getOwnerElement(); - } - // anything else not visible, replace with parent node - else if (nodeType == Node.TEXT_NODE) { - node = node.getParentNode(); - } - return node; - } - return object; - } - - private Object[] getFilteredNodes(Object[] filteredNodes) { - for (int i = 0; i < filteredNodes.length; i++) { - filteredNodes[i] = getFilteredNode(filteredNodes[i]); - } - return filteredNodes; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration#getLabelProvider(org.eclipse.jface.viewers.TreeViewer) - */ - public ILabelProvider getLabelProvider(TreeViewer viewer) { - if (fAttributeShowingLabelProvider == null) { - fAttributeShowingLabelProvider = new AttributeShowingLabelProvider(); - } - return fAttributeShowingLabelProvider; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration#getSelection(org.eclipse.jface.viewers.TreeViewer, - * org.eclipse.jface.viewers.ISelection) - */ - public ISelection getSelection(TreeViewer viewer, ISelection selection) { - ISelection filteredSelection = selection; - if (selection instanceof IStructuredSelection) { - Object[] filteredNodes = getFilteredNodes(((IStructuredSelection) selection).toArray()); - filteredSelection = new StructuredSelection(filteredNodes); - } - return filteredSelection; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/properties/XMLPropertySheetConfiguration.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/properties/XMLPropertySheetConfiguration.java deleted file mode 100644 index aba549d855..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/properties/XMLPropertySheetConfiguration.java +++ /dev/null @@ -1,259 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.views.properties; - -import java.util.HashSet; -import java.util.Set; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.progress.UIJob; -import org.eclipse.ui.views.properties.IPropertySheetPage; -import org.eclipse.ui.views.properties.IPropertySource; -import org.eclipse.ui.views.properties.IPropertySourceProvider; -import org.eclipse.ui.views.properties.PropertySheetPage; -import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter; -import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; -import org.eclipse.wst.sse.ui.views.properties.PropertySheetConfiguration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManagerListener; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.contentmodel.util.CMDocumentCache; -import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.properties.XMLPropertySource; -import org.w3c.dom.Attr; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -/** - * Configuration for property sheet page which shows XML content. - * - * @see org.eclipse.wst.sse.ui.views.properties.PropertySheetConfiguration - * @since 1.0 - */ -public class XMLPropertySheetConfiguration extends PropertySheetConfiguration { - private class CMDocumentManagerListenerImpl implements CMDocumentManagerListener { - public void cacheCleared(CMDocumentCache cache) { - // nothing to do - } - - public void cacheUpdated(CMDocumentCache cache, final String uri, int oldStatus, int newStatus, CMDocument cmDocument) { - if ((newStatus == CMDocumentCache.STATUS_LOADED) || (newStatus == CMDocumentCache.STATUS_ERROR)) { - refreshPages(); - } - } - - public void propertyChanged(CMDocumentManager cmDocumentManager, String propertyName) { - if (cmDocumentManager.getPropertyEnabled(CMDocumentManager.PROPERTY_AUTO_LOAD)) { - refreshPages(); - } - } - - private void refreshPages() { - getPropertiesRefreshJob().addPropertySheetPage(fPropertySheetPage); - getPropertiesRefreshJob().schedule(PropertiesRefreshJob.UPDATE_DELAY); - } - } - - private class PropertiesRefreshJob extends UIJob { - public static final int UPDATE_DELAY = 200; - - private Set propertySheetPages = null; - - public PropertiesRefreshJob() { - super(XMLUIMessages.JFaceNodeAdapter_1); - setSystem(true); - setPriority(Job.SHORT); - propertySheetPages = new HashSet(1); - } - - void addPropertySheetPage(IPropertySheetPage page) { - if (page != null) { - propertySheetPages.add(page); - schedule(UPDATE_DELAY); - } - } - - public IStatus runInUIThread(IProgressMonitor monitor) { - Object[] pages = propertySheetPages.toArray(); - propertySheetPages.clear(); - - for (int i = 0; i < pages.length; i++) { - PropertySheetPage page = (PropertySheetPage) pages[i]; - if ((page != null) && (page.getControl() != null) && !page.getControl().isDisposed()) { - page.refresh(); - } - } - - return Status.OK_STATUS; - } - } - - private class XMLPropertySheetRefreshAdapter implements INodeAdapter { - public boolean isAdapterForType(Object type) { - return false; - } - - public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) { - if (fPropertySheetPage != null) { - getPropertiesRefreshJob().addPropertySheetPage(fPropertySheetPage); - } - } - } - - private class XMLPropertySourceProvider implements IPropertySourceProvider { - private IPropertySource fPropertySource = null; - private INodeNotifier fSource = null; - - public IPropertySource getPropertySource(Object object) { - if ((fSource != null) && object.equals(fSource)) { - return fPropertySource; - } - - if (object instanceof IDOMNode) { - fSource = (INodeNotifier) object; - fPropertySource = (IPropertySource) fSource.getAdapterFor(IPropertySource.class); - if (fPropertySource == null) { - fPropertySource = new XMLPropertySource((INodeNotifier) object); - } - } - else { - fSource = null; - fPropertySource = null; - } - return fPropertySource; - } - } - - private CMDocumentManagerListenerImpl fCMDocumentManagerListener = new CMDocumentManagerListenerImpl(); - private PropertiesRefreshJob fPropertiesRefreshJob = null; - IPropertySheetPage fPropertySheetPage = null; - private IPropertySourceProvider fPropertySourceProvider = null; - private INodeAdapter fRefreshAdapter = new XMLPropertySheetRefreshAdapter(); - private CMDocumentManager[] fSelectedCMDocumentManagers = new CMDocumentManager[0]; - private INodeNotifier[] fSelectedNotifiers = new INodeNotifier[0]; - - - /** - * Create new instance of XMLPropertySheetConfiguration - */ - public XMLPropertySheetConfiguration() { - // Must have empty constructor to createExecutableExtension - super(); - } - - public ISelection getInputSelection(IWorkbenchPart selectingPart, ISelection selection) { - if (fSelectedNotifiers != null) { - for (int i = 0; i < fSelectedNotifiers.length; i++) { - fSelectedNotifiers[i].removeAdapter(fRefreshAdapter); - } - fSelectedNotifiers = null; - } - for (int i = 0; i < fSelectedCMDocumentManagers.length; i++) { - fSelectedCMDocumentManagers[i].removeListener(fCMDocumentManagerListener); - } - - ISelection preferredSelection = selection; - if (selection instanceof IStructuredSelection) { - IStructuredSelection structuredSel = (IStructuredSelection) selection; - - /* - * On Attr nodes, select the owner Element. On Text nodes, select - * the parent Element. - */ - Object[] selectedObjects = new Object[structuredSel.size()]; - System.arraycopy(structuredSel.toArray(), 0, selectedObjects, 0, selectedObjects.length); - for (int i = 0; i < selectedObjects.length; i++) { - Object inode = selectedObjects[i]; - if (inode instanceof Node) { - Node node = (Node) inode; - // replace Attribute Node with its owner - Node parentNode = node.getParentNode(); - if (node.getNodeType() == Node.ATTRIBUTE_NODE) { - Element ownerElement = ((Attr) node).getOwnerElement(); - selectedObjects[i] = ownerElement; - } - // replace Text Node with its parent - else if (((node.getNodeType() == Node.TEXT_NODE) || (node.getNodeType() == Node.CDATA_SECTION_NODE)) && (parentNode != null)) { - selectedObjects[i] = parentNode; - } - } - } - - if (selectedObjects.length > 0) { - Set managers = new HashSet(1); - Set selectedNotifiers = new HashSet(1); - - for (int i = 0; i < selectedObjects.length; i++) { - if (selectedObjects[i] instanceof Node) { - ModelQuery query = ModelQueryUtil.getModelQuery(((Node) selectedObjects[i]).getOwnerDocument()); - if (query != null) { - CMDocumentManager mgr = query.getCMDocumentManager(); - if (mgr != null) { - managers.add(mgr); - mgr.addListener(fCMDocumentManagerListener); - } - } - } - /* - * Add UI refresh adapters and remember notifiers for - * later removal - */ - if (selectedObjects[i] instanceof INodeNotifier) { - selectedNotifiers.add(selectedObjects[i]); - ((INodeNotifier) selectedObjects[i]).addAdapter(fRefreshAdapter); - } - } - fSelectedCMDocumentManagers = (CMDocumentManager[]) managers.toArray(new CMDocumentManager[managers.size()]); - fSelectedNotifiers = (INodeNotifier[]) selectedNotifiers.toArray(new INodeNotifier[selectedNotifiers.size()]); - } - - - preferredSelection = new StructuredSelection(selectedObjects); - } - return preferredSelection; - } - - PropertiesRefreshJob getPropertiesRefreshJob() { - if (fPropertiesRefreshJob == null) { - fPropertiesRefreshJob = new PropertiesRefreshJob(); - } - return fPropertiesRefreshJob; - } - - public IPropertySourceProvider getPropertySourceProvider(IPropertySheetPage page) { - if (fPropertySourceProvider == null) { - fPropertySheetPage = page; - fPropertySourceProvider = new XMLPropertySourceProvider(); - } - return fPropertySourceProvider; - } - - - public void unconfigure() { - super.unconfigure(); - for (int i = 0; i < fSelectedCMDocumentManagers.length; i++) { - fSelectedCMDocumentManagers[i].removeListener(fCMDocumentManagerListener); - } - fPropertySheetPage = null; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates.properties b/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates.properties deleted file mode 100644 index 8b5177a589..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates.properties +++ /dev/null @@ -1,26 +0,0 @@ -############################################################################### -# Copyright (c) 2001, 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 -# Jens Lukowski/Innoopract - initial renaming/restructuring -# -############################################################################### -Templates.comment.name=comment -Templates.comment.desc=xml comment -Templates.xmldeclaration.name=xml declaration -Templates.xmldeclaration.desc=xml declaration -Templates.xslpi.name=XSL processing instruction -Templates.xslpi.desc=XSL processing instruction -Templates.xsinsp.name=xsinsp -Templates.xsinsp.desc=XML Schema name space -Templates.schemaLoc.name=schemaLoc -Templates.schemaLoc.desc=XML Schema location attribute -Templates.noschemaLoc.name=noschemaLoc -Templates.noschemaLoc.desc=No Namespace Schema Location -Templates.defaultnsp.name=default namespace -Templates.defaultnsp.desc=Default Namespace Attribute diff --git a/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates.xml b/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates.xml deleted file mode 100644 index 7730cb2923..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates.xml +++ /dev/null @@ -1,24 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- -/******************************************************************************* - * Copyright (c) 2004, 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 - * David Carver - added templates for xsi namespace, schemaLocation, and - default namespace - *******************************************************************************/ - --> -<templates> - <template name="%Templates.xmldeclaration.name" description="%Templates.xmldeclaration.desc" id="org.eclipse.wst.xml.ui.internal.templates.xmldeclaration" context="xml_new" enabled="true"><?xml version="1.0" encoding="${encoding}"?></template> - <template name="%Templates.comment.name" description="%Templates.comment.desc" id="org.eclipse.wst.xml.ui.internal.templates.comment" context="xml_tag" enabled="true"><!-- ${cursor} --></template> - <template name="%Templates.xslpi.name" description="%Templates.xslpi.desc" id="org.eclipse.wst.xml.ui.internal.templates.xslpi" context="xml_tag" enabled="true"><?xml-stylesheet type="text/xsl" href="${cursor}"?></template> - <template name="%Templates.xsinsp.name" description="%Templates.xsinsp.desc" id="org.eclipse.wst.xml.ui.internal.templates.xsinsp" context="xml_attribute" enabled="true">xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"</template> - <template name="%Templates.schemaLoc.name" description="%Templates.schemaLoc.desc" id="org.eclipse.wst.xml.ui.internal.templates.schemaLoc" context="xml_attribute" enabled="true">xsi:schemaLocation="{namespace} {location}"</template> - <template name="%Templates.noschemaLoc.name" description="%Templates.noschemaLoc.desc" id="org.eclipse.wst.xml.ui.internal.templates.noschemaLoc" context="xml_attribute" enabled="true">xsi:schemaLocation="{namespace} {location}"</template> - <template name="%Templates.defaultnsp.name" description="%Templates.defaultnsp.desc" id="org.eclipse.wst.xml.ui.internal.templates.defaultnsp" context="xml_attribute" enabled="true">xmlns="default namespace"</template> -</templates> |