diff options
Diffstat (limited to 'bundles/org.eclipse.wst.xml.ui')
233 files changed, 0 insertions, 28698 deletions
diff --git a/bundles/org.eclipse.wst.xml.ui/.classpath b/bundles/org.eclipse.wst.xml.ui/.classpath deleted file mode 100644 index f1479352f5..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/.classpath +++ /dev/null @@ -1,9 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" path="src/"/> - <classpathentry kind="src" path="src-multipage/"/> - <classpathentry kind="src" path="src-wizards/"/> - <classpathentry excluding="org/eclipse/**/internal/**" kind="con" path="org.eclipse.pde.core.requiredPlugins"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> - <classpathentry kind="output" path="bin"/> -</classpath> diff --git a/bundles/org.eclipse.wst.xml.ui/.compatibility b/bundles/org.eclipse.wst.xml.ui/.compatibility deleted file mode 100644 index 2e4834a775..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/.compatibility +++ /dev/null @@ -1,2 +0,0 @@ -#Wed Mar 24 13:53:52 EST 2004
-.project=6269
diff --git a/bundles/org.eclipse.wst.xml.ui/.cvsignore b/bundles/org.eclipse.wst.xml.ui/.cvsignore deleted file mode 100644 index 03491a0452..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/.cvsignore +++ /dev/null @@ -1,7 +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 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.jdt.core.prefs b/bundles/org.eclipse.wst.xml.ui/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 7ec3436c18..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,69 +0,0 @@ -#Tue Nov 30 00:31:11 EST 2004
-org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled
-org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
-org.eclipse.jdt.core.compiler.debug.lineNumber=generate
-org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=warning
-org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
-org.eclipse.jdt.core.compiler.problem.unsafeTypeOperation=warning
-org.eclipse.jdt.core.compiler.problem.forbiddenReference=ignore
-org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=enabled
-org.eclipse.jdt.core.compiler.problem.unusedImport=error
-org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
-org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=error
-org.eclipse.jdt.core.builder.invalidClasspath=abort
-org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=*.launch
-org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
-org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=warning
-org.eclipse.jdt.core.compiler.debug.localVariable=generate
-org.eclipse.jdt.core.compiler.problem.deprecation=warning
-org.eclipse.jdt.core.compiler.source=1.3
-org.eclipse.jdt.core.compiler.problem.finalParameterBound=ignore
-org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
-org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore
-org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning
-org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
-org.eclipse.jdt.core.compiler.compliance=1.4
-org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
-org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
-org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
-org.eclipse.jdt.core.builder.cleanOutputFolder=clean
-org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
-org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
-org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=error
-org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
-org.eclipse.jdt.core.compiler.problem.fieldHiding=warning
-org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning
-org.eclipse.jdt.core.classpath.exclusionPatterns=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
-org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=error
-org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
-org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public
-org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=private
-org.eclipse.jdt.core.compiler.problem.localVariableHiding=warning
-org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
-org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled
-org.eclipse.jdt.core.incompatibleJDKLevel=ignore
-eclipse.preferences.version=1
-org.eclipse.jdt.core.circularClasspath=error
-org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=enabled
-org.eclipse.jdt.core.compiler.maxProblemPerUnit=100
-org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=warning
-org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore
-org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=private
-org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled
-org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
-org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
-org.eclipse.jdt.core.compiler.debug.sourceFile=generate
-org.eclipse.jdt.core.compiler.doc.comment.support=enabled
-org.eclipse.jdt.core.compiler.problem.noEffectAssignment=error
-org.eclipse.jdt.core.incompleteClasspath=error
-org.eclipse.jdt.core.compiler.problem.invalidJavadoc=error
-org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=enabled
-org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
-org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
-org.eclipse.jdt.core.builder.duplicateResourceTask=warning
-org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
diff --git a/bundles/org.eclipse.wst.xml.ui/README.txt b/bundles/org.eclipse.wst.xml.ui/README.txt deleted file mode 100644 index d5cec2457c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/README.txt +++ /dev/null @@ -1 +0,0 @@ -The XML specific implementation of the sse editor.
\ No newline at end of file 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 65bae85a75..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/build.properties +++ /dev/null @@ -1,29 +0,0 @@ -############################################################################### -# Copyright (c) 2001, 2004 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.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,\ - xml.jar,\ - icons/,\ - plugin.properties,\ - templates/,\ - xmleditor.jar,\ - examples/ -source.xmleditor.jar = src/,\ - src-multipage/,\ - src-wizards/ -src.includes = plugin.xml,\ - plugin.properties,\ - icons/,\ - templates/,\ - examples/ -output.xmleditor.jar = bin/ -jars.compile.order = xmleditor.jar 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 28f4ee0f26..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/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/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/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.gif b/bundles/org.eclipse.wst.xml.ui/icons/newSampleProject_wizbanner.gif Binary files differdeleted file mode 100644 index 9a0ff302dc..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/icons/newSampleProject_wizbanner.gif +++ /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 a033705ba2..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/plugin.properties +++ /dev/null @@ -1,59 +0,0 @@ -############################################################################### -# Copyright (c) 2001, 2004 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.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 -# -############################################################################### -providerName=Eclipse.org -pluginName=SSE XML Source Editor -nlFeatureName=SSE XML Source Editor NL Support -XML_Source_Page_Editor.name=XML Source Page Editor -XML_Files.name=XML Files -XML_Source.name=XML Source -XML_Templates.name=XML Templates -XML_Styles.name=XML Styles -XML_Editor.name=XML Editor -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 -############################################################################### -_UI_WIZARD_NEW_XML=XML -genMenuLabel=&Generate -_UI_ACTION_CREATE_XML=&XML File... -_UI_CREATE_NEW_XML_FILE=Create a new XML file. -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 context type -XML_Tag_context_type_Extension_Element.name=XML Tag context type -XML_Attribute_context_type_Extension_Element.name=XML Attribute context type -XML_Attribute_value_context_type_Extension_Element.name=XML Attribute value context type -############################################################################### -# The following property keys maybe unused. Commented out on 12/7/2004. Uncomment if needed. -#XMLExampleProjectCreationWizard.name=XML Examples -#XMLExampleProjectCreationWizard.description=Create a project containing XML sample files -#XML_Annotations.name=XML Annotations -#XML_Extension_Element.name=XML - 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 092f1dd60c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/plugin.xml +++ /dev/null @@ -1,346 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<?eclipse version="3.0"?> -<plugin - id="org.eclipse.wst.xml.ui" - name="%pluginName" - version="1.0.0" - provider-name="%providerName" - class="org.eclipse.wst.xml.ui.internal.XMLUIPlugin"> - - <runtime> - <library name="xmleditor.jar"> - <export name="*"/> - </library> - </runtime> - <requires> - <import plugin="org.eclipse.ui.ide"/> - <import plugin="org.eclipse.ui.views"/> - <import plugin="org.eclipse.jface.text"/> - <import plugin="org.eclipse.ui.workbench.texteditor"/> - <import plugin="org.eclipse.ui.editors"/> - <import plugin="org.eclipse.wst.sse.ui"/> - <import plugin="org.eclipse.wst.dtd.ui"/> - <import plugin="org.eclipse.wst.sse.core"/> - <import plugin="org.eclipse.ui"/> - <import plugin="org.eclipse.wst.common.contentmodel"/> - <import plugin="org.eclipse.core.resources"/> - <import plugin="org.eclipse.core.runtime"/> - <import plugin="org.eclipse.wst.common.encoding"/> - <import plugin="org.eclipse.wst.xml.uriresolver.ui"/> - <import plugin="org.eclipse.wst.common.uriresolver"/> - <import plugin="org.eclipse.wst.xml.uriresolver"/> - <import plugin="org.eclipse.wst.xml.core"/> - <import plugin="org.eclipse.wst.common.ui"/> - </requires> - - - <extension - point="org.eclipse.ui.editors"> - <editor - name="%XML_Source_Page_Editor.name" - icon="icons/sourceEditor.gif" - extensions="tld, nst, xmi, dadx, wsdl, xsl" - contributorClass="org.eclipse.wst.xml.ui.actions.ActionContributorXML" - class="org.eclipse.wst.xml.ui.StructuredTextEditorXML" - symbolicFontName="org.eclipse.wst.sse.ui.textfont" - id="org.eclipse.wst.xml.ui.StructuredTextEditorXML2"> - </editor> - <!-- Separate editor definition for xml source page to mark it as the default editor --> - <editor - name="%XML_Source_Page_Editor.name" - icon="icons/sourceEditor.gif" - extensions="xml" - default="true" - contributorClass="org.eclipse.wst.xml.ui.actions.ActionContributorXML" - class="org.eclipse.wst.xml.ui.StructuredTextEditorXML" - symbolicFontName="org.eclipse.wst.sse.ui.textfont" - id="org.eclipse.wst.xml.ui.StructuredTextEditorXML"> - </editor> - </extension> - <extension - point="org.eclipse.wst.sse.ui.extendedconfiguration"> - <textviewerconfiguration - class="org.eclipse.wst.xml.ui.StructuredTextViewerConfigurationXML" - target="org.eclipse.wst.xml.core.xmlsource"> - </textviewerconfiguration> - <contentoutlineconfiguration - class="org.eclipse.wst.xml.ui.views.contentoutline.XMLContentOutlineConfiguration" - target="org.eclipse.wst.xml.core.xmlsource"> - </contentoutlineconfiguration> - <propertysheetconfiguration - class="org.eclipse.wst.xml.ui.views.properties.XMLPropertySheetConfiguration" - target="org.eclipse.wst.xml.core.xmlsource"> - </propertysheetconfiguration> - <spellchecktarget - class="org.eclipse.wst.xml.ui.XMLSpellCheckTarget" - target="org.eclipse.wst.xml.core.xmlsource"> - </spellchecktarget> - <sourceeditingtexttools - class="org.eclipse.wst.xml.ui.extensions.XMLSourceEditingTextTools" - target="org.eclipse.wst.xml.core.xmlsource"> - </sourceeditingtexttools> - <characterpairmatcher - class="org.eclipse.wst.xml.ui.text.XMLDocumentRegionEdgeMatcher" - target="org.eclipse.wst.xml.core.xmlsource"> - </characterpairmatcher> - <preferencepages - preferenceids="org.eclipse.wst.sse.ui.preferences/org.eclipse.wst.sse.ui.preferences.xml" - target="org.eclipse.wst.xml.core.xmlsource"> - </preferencepages> - </extension> - <extension - point="org.eclipse.core.filebuffers.annotationModelCreation"> - <factory - contentTypeId="org.eclipse.wst.xml.core.xmlsource" - class="org.eclipse.wst.sse.ui.StructuredResourceMarkerAnnotationModelFactory"/> - </extension> - <extension - point="org.eclipse.wst.sse.ui.adapterFactoryDescription"> - <adapterFactoryDescription - class="org.eclipse.wst.xml.ui.registry.AdapterFactoryProviderForXML"> - <contentType id="org.eclipse.wst.xml.core.xmlsource"/> - </adapterFactoryDescription> - </extension> - <extension - point="org.eclipse.wst.sse.ui.embeddedAdapterFactoryProvider"> - <embeddedAdapterFactoryProvider - class="org.eclipse.wst.xml.ui.registry.AdapterFactoryProviderForEmbeddedXML"> - </embeddedAdapterFactoryProvider> - </extension> - <extension - point="org.eclipse.ui.preferencePages"> -<!-- XML PREFERENCE PAGES --> - <page - name="%XML_Files.name" - category="org.eclipse.wst.sse.ui.preferences" - class="org.eclipse.wst.xml.ui.preferences.XMLFilesPreferencePage" - id="org.eclipse.wst.sse.ui.preferences.xml"> - </page> - <page - name="%XML_Source.name" - category="org.eclipse.wst.sse.ui.preferences.xml" - class="org.eclipse.wst.xml.ui.preferences.XMLSourcePreferencePage" - id="org.eclipse.wst.sse.ui.preferences.xml.source"> - </page> - <page - name="%XML_Templates.name" - category="org.eclipse.wst.sse.ui.preferences.xml" - class="org.eclipse.wst.xml.ui.preferences.XMLTemplatePreferencePage" - id="org.eclipse.wst.sse.ui.preferences.xml.templates"> - </page> - <page - name="%XML_Styles.name" - category="org.eclipse.wst.sse.ui.preferences.xml" - class="org.eclipse.wst.xml.ui.preferences.XMLColorPage" - id="org.eclipse.wst.sse.ui.preferences.xml.colors"> - </page> - </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.StructuredTextEditorXML"> - </part> - <part - id="org.eclipse.wst.xml.ui.StructuredTextEditorXML2"> - </part> - </actionSetPartAssociation> - <actionSetPartAssociation - targetID="org.eclipse.ui.NavigateActionSet"> - <part - id="org.eclipse.wst.xml.ui.StructuredTextEditorXML"> - </part> - <part - id="org.eclipse.wst.xml.ui.StructuredTextEditorXML2"> - </part> - </actionSetPartAssociation> - </extension> - -<!-- add a default open on action for xml content type --> - <extension - point="org.eclipse.wst.sse.ui.openon"> - <openon - class="org.eclipse.wst.xml.ui.openon.DefaultOpenOnXML" - id="org.eclipse.wst.xml.ui.openon.DefaultOpenOnXML"> - <contenttypeidentifier - id="org.eclipse.wst.xml.core.xmlsource"> - </contenttypeidentifier> - </openon> - </extension> -<!-- Templates --> - <extension - point="org.eclipse.ui.editors.templates"> - <contextType - name="%All_XML_context_type_Extension_Element.name" - class="org.eclipse.wst.xml.ui.templates.TemplateContextTypeXML" - id="xml_all"> - </contextType> - <contextType - name="%XML_Tag_context_type_Extension_Element.name" - class="org.eclipse.wst.xml.ui.templates.TemplateContextTypeXMLTag" - id="xml_tag"> - </contextType> - <contextType - name="%XML_Attribute_context_type_Extension_Element.name" - class="org.eclipse.wst.xml.ui.templates.TemplateContextTypeXMLAttribute" - id="xml_attribute"> - </contextType> - <contextType - name="%XML_Attribute_value_context_type_Extension_Element.name" - class="org.eclipse.wst.xml.ui.templates.TemplateContextTypeXMLAttributeValue" - id="xml_attribute_value"> - </contextType> - <include - file="templates/xmldefault-templates.xml" - translations="templates/xmldefault-templates.properties"> - </include> - </extension> - - - - - - <extension - point="org.eclipse.ui.editors"> - <editor - name="%XML_Editor.name" - icon="icons/xmldoc.gif" - extensions="xml, tld, nst, xmi" - contributorClass="org.eclipse.wst.xml.internal.ui.XMLMultiPageEditorActionBarContributor" - class="org.eclipse.wst.xml.internal.ui.XMLMultiPageEditorPart" - id="org.eclipse.wst.xml.internal.ui.XMLMultiPageEditorPart"> - </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.internal.ui.XMLMultiPageEditorPart"> - </part> - </actionSetPartAssociation> - <actionSetPartAssociation - targetID="org.eclipse.ui.NavigateActionSet"> - <part - id="org.eclipse.wst.xml.internal.ui.XMLMultiPageEditorPart"> - </part> - </actionSetPartAssociation> - </extension> - - - -<!-- ================================================== --> -<!-- Contribute a 'New Wizard' for XML files --> -<!-- ================================================== --> - <extension - point="org.eclipse.ui.newWizards"> - <category - name="%_UI_WIZARD_NEW_XML" - id="org.eclipse.wst.XMLCategory"> - </category> - <wizard - name="%_UI_WIZARD_NEW_XML" - icon="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"> - <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.common.ui.wizards.ExampleProjectCreationWizard" - category="org.eclipse.ui.Examples/org.eclipse.wst.xml.examples" - id="org.eclipse.wst.xml.ui.XMLExampleProjectCreationWizard" - project="true" - icon="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.gif"> - <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> - -</plugin> diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/IDesignViewer.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/IDesignViewer.java deleted file mode 100644 index 493b8fddcf..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/IDesignViewer.java +++ /dev/null @@ -1,26 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2004 IBM Corporation and others. All rights reserved. This - * program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies 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.internal.ui; - - - -import org.eclipse.swt.widgets.Control; -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.sse.ui.ViewerSelectionManager; - - -public interface IDesignViewer { - public Control getControl(); - - String getTitle(); - - void setModel(IStructuredModel model); - - void setViewerSelectionManager(ViewerSelectionManager viewerSelectionManager); -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/IDesignViewerActionBarContributor.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/IDesignViewerActionBarContributor.java deleted file mode 100644 index ac191b354b..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/IDesignViewerActionBarContributor.java +++ /dev/null @@ -1,19 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2004 IBM Corporation and others. All rights reserved. This - * program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies 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.internal.ui; - - - -import org.eclipse.ui.IActionBars; -import org.eclipse.wst.sse.ui.ISourceViewerActionBarContributor; - - -public interface IDesignViewerActionBarContributor extends ISourceViewerActionBarContributor { - public void initViewerSpecificContributions(IActionBars bars); -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/SourceEditorActionBarContributor.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/SourceEditorActionBarContributor.java deleted file mode 100644 index 593de45f43..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/SourceEditorActionBarContributor.java +++ /dev/null @@ -1,210 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2004 IBM Corporation and others. All rights reserved. This - * program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies 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.internal.ui; - -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.wst.sse.ui.ISourceViewerActionBarContributor; -import org.eclipse.wst.sse.ui.StructuredTextEditor; -import org.eclipse.wst.sse.ui.extension.ExtendedEditorActionBuilder; -import org.eclipse.wst.sse.ui.extension.IExtendedContributor; - - -public class SourceEditorActionBarContributor extends MultiPageEditorActionBarContributor implements IExtendedContributor { - - protected IEditorActionBarContributor designViewerActionBarContributor = null; - protected IEditorActionBarContributor sourceViewerActionContributor = null; - protected XMLMultiPageEditorPart 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 XMLMultiPageEditorPart) - multiPageEditor = (XMLMultiPageEditorPart) 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); - } - } - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/SourcePageActionContributor.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/SourcePageActionContributor.java deleted file mode 100644 index 949a1557e0..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/SourcePageActionContributor.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies 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.internal.ui; - - - -import org.eclipse.ui.IActionBars; -import org.eclipse.wst.xml.ui.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; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/XMLEditorActionDefinitionIds.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/XMLEditorActionDefinitionIds.java deleted file mode 100644 index a05192e606..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/XMLEditorActionDefinitionIds.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies 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.internal.ui; - - - -/** - * 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$ -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/XMLEditorPluginHOLD_OLD.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/XMLEditorPluginHOLD_OLD.java deleted file mode 100644 index aaa46edae5..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/XMLEditorPluginHOLD_OLD.java +++ /dev/null @@ -1,126 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2004 IBM Corporation and others. All rights reserved. This - * program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies 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.internal.ui; - - - -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.preference.PreferenceConverter; -import org.eclipse.swt.graphics.RGB; -import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants; -import org.eclipse.wst.sse.ui.preferences.CommonEditorPreferenceNames; -import org.eclipse.wst.sse.ui.registry.AdapterFactoryRegistry; -import org.eclipse.wst.sse.ui.registry.AdapterFactoryRegistryImpl; -import org.eclipse.wst.sse.ui.registry.embedded.EmbeddedAdapterFactoryRegistryImpl; -import org.eclipse.wst.xml.core.XMLPreferenceNames; - -/** - * @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(); - - } - - public AdapterFactoryRegistry getEmbeddedAdapterFactoryRegistry() { - return EmbeddedAdapterFactoryRegistryImpl.getInstance(); - - } - - /** - * Creates XML Preference store and initializes its default values - */ - protected void initializeDefaultPreferences(IPreferenceStore preferenceStore) { - preferenceStore.setDefault(XMLPreferenceNames.LAST_ACTIVE_PAGE, 0); - - // editor prefs - preferenceStore.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER, false); - preferenceStore.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_OVERVIEW_RULER, true); - preferenceStore.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE, false); - - preferenceStore.setDefault(CommonEditorPreferenceNames.CONTENT_ASSIST_SUPPORTED, false); - preferenceStore.setDefault(CommonEditorPreferenceNames.AUTO_PROPOSE, true); - preferenceStore.setDefault(CommonEditorPreferenceNames.AUTO_PROPOSE_CODE, CommonEditorPreferenceNames.LT); - - preferenceStore.setDefault(CommonEditorPreferenceNames.MATCHING_BRACKETS, true); - PreferenceConverter.setDefault(preferenceStore, CommonEditorPreferenceNames.MATCHING_BRACKETS_COLOR, new RGB(192, 192, 192)); - - preferenceStore.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE, true); - PreferenceConverter.setDefault(preferenceStore, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE_COLOR, new RGB(225, 235, 224)); - - preferenceStore.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN, true); - PreferenceConverter.setDefault(preferenceStore, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLOR, new RGB(176, 180, 185)); - - preferenceStore.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN, 80); - - preferenceStore.setDefault(CommonEditorPreferenceNames.EDITOR_USE_INFERRED_GRAMMAR, true); - - initializeDefaultAnnotationPrefs(preferenceStore); - } - - /* - * Using this method for all content types initialize methods since - * they're all the same (for now) @param preferenceStore - */ - private void initializeDefaultAnnotationPrefs(IPreferenceStore preferenceStore) { - - preferenceStore.setDefault(CommonEditorPreferenceNames.ERROR_INDICATION, true); - PreferenceConverter.setDefault(preferenceStore, CommonEditorPreferenceNames.ERROR_INDICATION_COLOR, new RGB(255, 0, 128)); - - preferenceStore.setDefault(CommonEditorPreferenceNames.WARNING_INDICATION, true); - PreferenceConverter.setDefault(preferenceStore, CommonEditorPreferenceNames.WARNING_INDICATION_COLOR, new RGB(244, 200, 45)); - - preferenceStore.setDefault(CommonEditorPreferenceNames.TASK_INDICATION, false); - PreferenceConverter.setDefault(preferenceStore, CommonEditorPreferenceNames.TASK_INDICATION_COLOR, new RGB(0, 128, 255)); - - preferenceStore.setDefault(CommonEditorPreferenceNames.BOOKMARK_INDICATION, false); - PreferenceConverter.setDefault(preferenceStore, CommonEditorPreferenceNames.BOOKMARK_INDICATION_COLOR, new RGB(34, 164, 99)); - - preferenceStore.setDefault(CommonEditorPreferenceNames.SEARCH_RESULT_INDICATION, true); - PreferenceConverter.setDefault(preferenceStore, CommonEditorPreferenceNames.SEARCH_RESULT_INDICATION_COLOR, new RGB(192, 192, 192)); - - preferenceStore.setDefault(CommonEditorPreferenceNames.UNKNOWN_INDICATION, false); - PreferenceConverter.setDefault(preferenceStore, CommonEditorPreferenceNames.UNKNOWN_INDICATION_COLOR, new RGB(0, 0, 0)); - - preferenceStore.setDefault(CommonEditorPreferenceNames.ERROR_INDICATION_IN_OVERVIEW_RULER, true); - preferenceStore.setDefault(CommonEditorPreferenceNames.WARNING_INDICATION_IN_OVERVIEW_RULER, true); - preferenceStore.setDefault(CommonEditorPreferenceNames.TASK_INDICATION_IN_OVERVIEW_RULER, true); - preferenceStore.setDefault(CommonEditorPreferenceNames.BOOKMARK_INDICATION_IN_OVERVIEW_RULER, true); - preferenceStore.setDefault(CommonEditorPreferenceNames.SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER, true); - preferenceStore.setDefault(CommonEditorPreferenceNames.UNKNOWN_INDICATION_IN_OVERVIEW_RULER, false); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/XMLEditorPluginImageHelper.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/XMLEditorPluginImageHelper.java deleted file mode 100644 index fa3e6d2844..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/XMLEditorPluginImageHelper.java +++ /dev/null @@ -1,152 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies 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.internal.ui; - -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; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/XMLEditorPluginImages.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/XMLEditorPluginImages.java deleted file mode 100644 index b1ee193ec4..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/XMLEditorPluginImages.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies 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.internal.ui; - -/** - * 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$ -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/XMLEditorResourceHandler.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/XMLEditorResourceHandler.java deleted file mode 100644 index 1c5ae81ec9..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/XMLEditorResourceHandler.java +++ /dev/null @@ -1,65 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2004 IBM Corporation and others. All rights reserved. This - * program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies 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.internal.ui; - -import java.text.MessageFormat; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -public class XMLEditorResourceHandler { - //Resource bundle. - private static ResourceBundle resourceBundle; - private static final String KEY_PREFIX = "%"; //$NON-NLS-1$ - private static final String KEY_DOUBLE_PREFIX = "%%"; //$NON-NLS-1$ - - /** - * Returns the string from the plugin's resource bundle, - * or 'key' if not found. - */ - public static String getResourceString(String value) { - String s = value.trim(); - if (!s.startsWith(KEY_PREFIX, 0)) - return s; - if (s.startsWith(KEY_DOUBLE_PREFIX, 0)) - return s.substring(1); - - int ix = s.indexOf(' '); - String key = ix == -1 ? s : s.substring(0, ix); - - ResourceBundle bundle = getResourceBundle(); - try { - return (bundle != null) ? bundle.getString(key.substring(1)) : key; - } catch (MissingResourceException e) { - return key; - } - } - - public static String getResourceString(String key, Object[] args) { - - try { - return MessageFormat.format(getResourceString(key), args); - } catch (IllegalArgumentException e) { - return getResourceString(key); - } - - } - - /** - * Returns the plugin's resource bundle, - */ - public static ResourceBundle getResourceBundle() { - try { - if (resourceBundle == null) - resourceBundle = ResourceBundle.getBundle("org.eclipse.wst.xml.internal.ui.XMLEditorResources"); - } catch (MissingResourceException x) { - resourceBundle = null; - } - return resourceBundle; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/XMLEditorResources.properties b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/XMLEditorResources.properties deleted file mode 100644 index 6fcd774694..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/XMLEditorResources.properties +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################### -# Copyright (c) 2004 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.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 diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/XMLMultiPageEditorActionBarContributor.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/XMLMultiPageEditorActionBarContributor.java deleted file mode 100644 index 8eb0240f9c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/XMLMultiPageEditorActionBarContributor.java +++ /dev/null @@ -1,89 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2004 IBM Corporation and others. All rights reserved. This - * program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies 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.internal.ui; - - - -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IEditorPart; -import org.eclipse.wst.sse.ui.ISourceViewerActionBarContributor; -import org.eclipse.wst.xml.ui.internal.tabletree.XMLTableTreeActionBarContributor; - - -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); - } - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/XMLMultiPageEditorPart.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/XMLMultiPageEditorPart.java deleted file mode 100644 index 9021fe5831..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/internal/ui/XMLMultiPageEditorPart.java +++ /dev/null @@ -1,771 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2004 IBM Corporation and others. All rights reserved. This - * program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies 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.internal.ui; - -import java.io.IOException; -import java.io.InputStream; -import java.util.List; - -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceStatus; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextInputListener; -import org.eclipse.swt.events.ShellAdapter; -import org.eclipse.swt.events.ShellEvent; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IEditorActionBarContributor; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IEditorSite; -import org.eclipse.ui.IFileEditorInput; -import org.eclipse.ui.IPartListener; -import org.eclipse.ui.IPropertyListener; -import org.eclipse.ui.IStorageEditorInput; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.help.WorkbenchHelp; -import org.eclipse.ui.ide.IGotoMarker; -import org.eclipse.ui.part.MultiPageEditorPart; -import org.eclipse.ui.part.MultiPageEditorSite; -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.sse.core.exceptions.SourceEditingRuntimeException; -import org.eclipse.wst.sse.ui.StructuredTextEditor; -import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; -import org.eclipse.wst.xml.core.XMLPreferenceNames; -import org.eclipse.wst.xml.ui.StructuredTextEditorXML; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.internal.tabletree.XMLTableTreeHelpContextIds; -import org.eclipse.wst.xml.ui.internal.tabletree.XMLTableTreeViewer; -import org.w3c.dom.Document; -import org.w3c.dom.Node; - -public class XMLMultiPageEditorPart extends MultiPageEditorPart implements IPropertyListener { - - /** - * Internal part activation listener - */ - class PartListener extends ShellAdapter implements IPartListener { - private IWorkbenchPart fActivePart; - private boolean fIsHandlingActivation = false; - - private void handleActivation() { - - if (fIsHandlingActivation) - return; - - if (fActivePart == XMLMultiPageEditorPart.this) { - fIsHandlingActivation = true; - try { - safelySanityCheckState(); - } finally { - fIsHandlingActivation = false; - } - } - } - - /** - * @see IPartListener#partActivated(IWorkbenchPart) - */ - public void partActivated(IWorkbenchPart part) { - fActivePart = part; - handleActivation(); - } - - /** - * @see IPartListener#partBroughtToTop(IWorkbenchPart) - */ - public void partBroughtToTop(IWorkbenchPart part) { - } - - /** - * @see IPartListener#partClosed(IWorkbenchPart) - */ - public void partClosed(IWorkbenchPart part) { - } - - /** - * @see IPartListener#partDeactivated(IWorkbenchPart) - */ - public void partDeactivated(IWorkbenchPart part) { - fActivePart = null; - } - - /** - * @see IPartListener#partOpened(IWorkbenchPart) - */ - public void partOpened(IWorkbenchPart part) { - } - - /* - * @see ShellListener#shellActivated(ShellEvent) - */ - public void shellActivated(ShellEvent e) { - handleActivation(); - } - } - - class TextInputListener implements ITextInputListener { - public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) { - } - - public void inputDocumentChanged(IDocument oldInput, IDocument newInput) { - if (fDesignViewer != null && newInput != null) - fDesignViewer.setModel(getModel()); - } - } - - /** The design page index. */ - private int fDesignPageIndex; - - /** The design viewer */ - private IDesignViewer fDesignViewer; - - /** The source page index. */ - private int fSourcePageIndex; - /** The text editor. */ - private StructuredTextEditor fTextEditor; - - private PartListener partListener; - - /** - * StructuredTextMultiPageEditorPart constructor comment. - */ - public XMLMultiPageEditorPart() { - super(); - } - - /* - * This method is just to make firePropertyChanged accessbible from some - * (anonomous) inner classes. - */ - protected void _firePropertyChange(int property) { - super.firePropertyChange(property); - } - - /** - * Adds the source page of the multi-page editor. - */ - protected void addSourcePage() throws PartInitException { - try { - fSourcePageIndex = addPage(fTextEditor, getEditorInput()); - setPageText(fSourcePageIndex, XMLEditorResourceHandler.getResourceString("%XMLMultiPageEditorPart.0")); //$NON-NLS-1$ - // the update's critical, to get viewer selection manager and - // highlighting to work - fTextEditor.update(); - - firePropertyChange(PROP_TITLE); - - // Changes to the Text Viewer's document instance should also - // force an - // input refresh - fTextEditor.getTextViewer().addTextInputListener(new TextInputListener()); - } catch (PartInitException exception) { - // dispose editor - dispose(); - Logger.logException(exception); - throw new SourceEditingRuntimeException(exception, SSEUIPlugin.getResourceString("%An_error_has_occurred_when1_ERROR_")); //$NON-NLS-1$ - } - } - - /** - * 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. - */ - protected void connectDesignPage() { - if (fDesignViewer != null) { - fDesignViewer.setViewerSelectionManager(fTextEditor.getViewerSelectionManager()); - fDesignViewer.setModel(getModel()); - } - } - - /** - * Create and Add the Design Page using a registered factory - * - */ - protected void createAndAddDesignPage() { - XMLTableTreeViewer tableTreeViewer = new XMLTableTreeViewer(getContainer()); - // Set the default infopop for XML design viewer. - WorkbenchHelp.setHelp(tableTreeViewer.getControl(), XMLTableTreeHelpContextIds.XML_DESIGN_VIEW_HELPID); - - fDesignViewer = tableTreeViewer; - // 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(tableTreeViewer.getControl()); - setPageText(fDesignPageIndex, tableTreeViewer.getTitle()); - } - - /** - * 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(); - - setActivePage(); - - // future_TODO: add a catch block here for any exception the - // design - // page throws and convert it into a more informative message. - } 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; - } - }; - } 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); - - // Set the SourceViewerConfiguration now so the text editor won't use - // the default configuration first - // and switch to the StructuredTextViewerConfiguration later. - // DMW removed setSourceViewerConfiguration 3/26/2003 since added - // createPartControl to our text editor. - // fTextEditor.setSourceViewerConfiguration(); - fTextEditor.addPropertyListener(this); - } - - /** - * Method createTextEditor. - * - * @return StructuredTextEditor - */ - protected StructuredTextEditor createTextEditor() { - return new StructuredTextEditorXML(); - } - - protected void disconnectDesignPage() { - if (fDesignViewer != null) { - fDesignViewer.setModel(null); - fDesignViewer.setViewerSelectionManager(null); - } - } - - public void dispose() { - Logger.trace("Source Editor", "StructuredTextMultiPageEditorPart::dispose entry"); //$NON-NLS-1$ //$NON-NLS-2$ - - disconnectDesignPage(); - - IWorkbenchWindow window = getSite().getWorkbenchWindow(); - window.getPartService().removePartListener(partListener); - window.getShell().removeShellListener(partListener); - - getSite().getPage().removePartListener(partListener); - if (fTextEditor != null) { - fTextEditor.removePropertyListener(this); - } - - // 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) Saves the contents of this editor. <p> Subclasses must - * override this method to implement the open-save-close lifecycle for an - * editor. For greater details, see <code> IEditorPart </code></p> - * - * @see IEditorPart - */ - public void doSave(IProgressMonitor monitor) { - fTextEditor.doSave(monitor); - // // this is a temporary way to force validation. - // // when the validator is a workbench builder, the following lines - // can be removed - // if (fDesignViewer != null) - // fDesignViewer.saveOccurred(); - - } - - /* - * (non-Javadoc) Saves the contents of this editor to another object. <p> - * Subclasses must override this method to implement the open-save-close - * lifecycle for an editor. For greater details, see <code> IEditorPart - * </code></p> - * - * @see IEditorPart - */ - public void doSaveAs() { - fTextEditor.doSaveAs(); - // 253619 - // following used to be executed here, but is - // now called "back" from text editor (since - // mulitiple paths to the performSaveAs in StructuredTextEditor. - //doSaveAsForStructuredTextMulitPagePart(); - } - - private void editorInputIsAcceptable(IEditorInput input) throws PartInitException { - if (input instanceof IFileEditorInput) { - // verify that it can be opened - CoreException[] coreExceptionArray = new CoreException[1]; - if (fileDoesNotExist((IFileEditorInput) input, coreExceptionArray)) { - CoreException coreException = coreExceptionArray[0]; - if (coreException.getStatus().getCode() == IResourceStatus.FAILED_READ_LOCAL) { - // I'm assuming this is always 'does not exist' - // we'll refresh local go mimic behavior of default - // editor, where the - // troublesome file is refreshed (and will cause it to - // 'disappear' from Navigator. - try { - ((IFileEditorInput) input).getFile().refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor()); - } catch (CoreException ce) { - // very unlikely - Logger.logException(ce); - } - throw new PartInitException(SSEUIPlugin.getResourceString("%23concat_EXC_", (new Object[]{input.getName()}))); //$NON-NLS-1$ - //$NON-NLS-1$ = "Resource {0} does not exist." - } else { - throw new PartInitException(SSEUIPlugin.getResourceString("%32concat_EXC_", (new Object[]{input.getName()}))); //$NON-NLS-1$ - //$NON-NLS-1$ = "Editor could not be open on {0}" - } - } - } else if (input instanceof IStorageEditorInput) { - InputStream contents = null; - try { - contents = ((IStorageEditorInput) input).getStorage().getContents(); - } catch (CoreException noStorageExc) { - } - if (contents == null) { - throw new PartInitException(SSEUIPlugin.getResourceString("%32concat_EXC_", (new Object[]{input.getName()}))); //$NON-NLS-1$ - } else { - try { - contents.close(); - } catch (IOException e) { - } - } - } - } - - // void doSaveAsForStructuredTextMulitPagePart() { - // setPageText(getActivePage(), fTextEditor.getTitle()); - // setInput(fTextEditor.getEditorInput()); - // if (fDesignViewer != null) { - // //fDesignViewer.setEditorInput(fTextEditor.getEditorInput()); - // fDesignViewer.setModel(getModel()); - // fDesignViewer.saveAsOccurred(); - // } - // // even though we've set title etc., several times already! - // // only now is all prepared for it. - // firePropertyChange(IWorkbenchPart.PROP_TITLE); - // firePropertyChange(PROP_DIRTY); - // } - /* - * (non-Javadoc) Initializes the editor part with a site and input. <p> - * Subclasses of <code> EditorPart </code> must implement this method. - * Within the implementation subclasses should verify that the input type - * is acceptable and then save the site and input. Here is sample code: - * </p><pre> if (!(input instanceof IFileEditorInput)) throw new - * PartInitException("Invalid Input: Must be IFileEditorInput"); - * setSite(site); setInput(editorInput); </pre> - */ - protected boolean fileDoesNotExist(IFileEditorInput input, Throwable[] coreException) { - boolean result = false; - InputStream inStream = null; - if ((!(input.exists())) || (!(input.getFile().exists()))) { - result = true; - } else { - try { - inStream = input.getFile().getContents(true); - } catch (CoreException e) { - // very likely to be file not found - result = true; - coreException[0] = e; - } finally { - if (input != null) { - try { - if (inStream != null) { - inStream.close(); - } - } catch (IOException e) { - Logger.logException(e); - } - } - } - } - return result; - } - - public Object getAdapter(Class key) { - Object result = null; - if (key == IDesignViewer.class) { - result = fDesignViewer; - } else { - // DMW: I'm bullet-proofing this because - // its been reported (on 4.03 version) 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; - } - - /** - * IExtendedMarkupEditor method - */ - public Node getCaretNode() { - if (getTextEditor() == null) - return null; - - return getTextEditor().getCaretNode(); - } - - /** - * IExtendedSimpleEditor method - */ - public int getCaretPosition() { - if (getTextEditor() == null) - return -1; - - return getTextEditor().getCaretPosition(); - } - - /** - * IExtendedSimpleEditor method - */ - public IDocument getDocument() { - if (getTextEditor() == null) - return null; - - return getTextEditor().getDocument(); - } - - /** - * IExtendedMarkupEditor method - */ - public Document getDOMDocument() { - if (getTextEditor() == null) - return null; - - return getTextEditor().getDOMDocument(); - } - - /** - * IExtendedSimpleEditor method - */ - public IEditorPart getEditorPart() { - return this; - } - - protected IStructuredModel getModel() { - IStructuredModel model = null; - if (fTextEditor != null) - model = fTextEditor.getModel(); - return model; - } - - protected IPreferenceStore getPreferenceStore() { - return XMLUIPlugin.getDefault().getPreferenceStore(); - } - - /** - * IExtendedMarkupEditor method - */ - public List getSelectedNodes() { - if (getTextEditor() == null) - return null; - return getTextEditor().getSelectedNodes(); - } - - /** - * IExtendedSimpleEditor method - */ - public Point getSelectionRange() { - if (getTextEditor() == null) - return new Point(-1, -1); - - return getTextEditor().getSelectionRange(); - } - - public StructuredTextEditor getTextEditor() { - return fTextEditor; - } - - /* - * (non-Javadoc) Method declared on IWorkbenchPart. - */ - 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; - } - - /* - * (non-Javadoc) Sets the cursor and selection state for this editor to - * the passage defined by the given marker. <p> Subclasses may override. - * For greater details, see <code> IEditorPart </code></p> - * - * @see IEditorPart - */ - public void gotoMarker(IMarker marker) { - // (pa) 20020217 this was null when opening an editor that was - // already open - if (fTextEditor != null) { - IGotoMarker markerGotoer = (IGotoMarker) fTextEditor.getAdapter(IGotoMarker.class); - markerGotoer.gotoMarker(marker); - } - } - - public void init(IEditorSite site, IEditorInput input) throws PartInitException { - editorInputIsAcceptable(input); - try { - super.init(site, input); - if (partListener == null) { - partListener = new PartListener(); - } - //getSite().getPage().addPartListener(partListner); - // we want to listen for our own activation - IWorkbenchWindow window = getSite().getWorkbenchWindow(); - window.getPartService().addPartListener(partListener); - window.getShell().addShellListener(partListener); - } catch (Exception e) { - if (e instanceof SourceEditingRuntimeException) { - Throwable t = ((SourceEditingRuntimeException) e).getOriginalException(); - if (t instanceof IOException) { - System.out.println(t); - // file not found - } - } - } - setPartName(input.getName()); - } - - /* - * (non-Javadoc) Returns whether the "save as" operation is supported by - * this editor. <p> Subclasses must override this method to implement the - * open-save-close lifecycle for an editor. For greater details, see - * <code> IEditorPart </code></p> - * - * @see IEditorPart - */ - public boolean isSaveAsAllowed() { - return fTextEditor != null && fTextEditor.isSaveAsAllowed(); - } - - /* - * (non-Javadoc) Returns whether the contents of this editor should be - * saved when the editor is closed. <p> This method returns <code> true - * </code> if and only if the editor is dirty ( <code> isDirty </code> ). - * </p> - */ - public boolean isSaveOnCloseNeeded() { - // overriding super class since it does a lowly isDirty! - if (fTextEditor != null) - return fTextEditor.isSaveOnCloseNeeded(); - return isDirty(); - } - - /** - * Notifies this multi-page editor that the page with the given id has - * been activated. This method is called when the user selects a different - * tab. - * - * @param newPageIndex - * the index of the activated page - */ - protected void pageChange(int newPageIndex) { - super.pageChange(newPageIndex); - - saveLastActivePageIndex(newPageIndex); - } - - /** - * Posts the update code "behind" the running operation. - */ - protected void postOnDisplayQue(Runnable runnable) { - IWorkbench workbench = PlatformUI.getWorkbench(); - IWorkbenchWindow[] windows = workbench.getWorkbenchWindows(); - if (windows != null && windows.length > 0) { - Display display = windows[0].getShell().getDisplay(); - display.asyncExec(runnable); - } else - runnable.run(); - } - - /** - * Indicates that a property has changed. - * - * @param source - * the object whose property has changed - * @param propId - * the id of the property which has changed; property ids are - * generally defined as constants on the source class - */ - public void propertyChanged(Object source, int propId) { - switch (propId) { - // had to implement input changed "listener" so that - // strucutedText could tell it containing editor that - // the input has change, when a 'resource moved' event is - // found. - case IEditorPart.PROP_INPUT : - case IEditorPart.PROP_DIRTY : { - if (source == fTextEditor) { - if (fTextEditor.getEditorInput() != getEditorInput()) { - setInput(fTextEditor.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. - postOnDisplayQue(runnable); - } - } - break; - } - case IWorkbenchPart.PROP_TITLE : { - // update the input if the title is changed - if (source == fTextEditor) { - if (fTextEditor.getEditorInput() != getEditorInput()) { - setInput(fTextEditor.getEditorInput()); - } - } - break; - } - default : { - // propagate changes. Is this needed? Answer: Yes. - if (source == fTextEditor) { - firePropertyChange(propId); - } - break; - } - } - - } - - protected void safelySanityCheckState() { - // If we're called before editor is created, simply ignore since we - // delegate this function to our embedded TextEditor - if (getTextEditor() == null) - return; - - getTextEditor().safelySanityCheckState(getEditorInput()); - - } - - protected void saveLastActivePageIndex(int newPageIndex) { - // save the last active page index to preference manager - getPreferenceStore().setValue(XMLPreferenceNames.LAST_ACTIVE_PAGE, newPageIndex); - } - - /** - * Sets the currently active page. - */ - protected void setActivePage() { - // retrieve the last active page index from preference manager - int activePageIndex = getPreferenceStore().getInt(XMLPreferenceNames.LAST_ACTIVE_PAGE); - - // We check this range since someone could hand edit the XML - // preference file to an invalid value ... which I know from - // experience :( ... if they do, we'll reset to default and continue - // rather than throw an assertion error in the setActivePage(int) - // method. - if (activePageIndex < 0 || activePageIndex >= getPageCount()) { - activePageIndex = fDesignPageIndex; - } - setActivePage(activePageIndex); - } - - /* - * (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 the input just yet. We'll rely on later notification from the - // TextViewer to set us straight - super.setInput(input); - if (fDesignViewer != null) - fDesignViewer.setModel(getModel()); - setPartName(input.getName()); - } - - /** - * IExtendedMarkupEditor method - */ - public IStatus validateEdit(Shell context) { - if (getTextEditor() == null) - return new Status(IStatus.ERROR, XMLUIPlugin.ID, IStatus.INFO, "", null); //$NON-NLS-1$ - - return getTextEditor().validateEdit(context); - } - -}
\ No newline at end of file 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 9bf75fb53a..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/DOMPropertyDescriptorFactory.java +++ /dev/null @@ -1,136 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2004 IBM Corporation and others. All rights reserved. This - * program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies 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.common.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.common.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.sse.ui.views.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$ - private ModelQuery fModelQuery = null; - - public DOMPropertyDescriptorFactory(ModelQuery modelQuery) { - fModelQuery = modelQuery; - } - - public IPropertyDescriptor createAttributePropertyDescriptor(Attr attr) { - IPropertyDescriptor result = null; - - String attributeName = attr.getName(); - - CMAttributeDeclaration ad = fModelQuery.getCMAttributeDeclaration(attr); - if (ad != null) { - String[] valuesArray = fModelQuery.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); - } - - - public ModelQuery getModelQuery() { - return fModelQuery; - } - -}
\ No newline at end of file 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 d042bc2a8c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/TreeContentHelper.java +++ /dev/null @@ -1,431 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies 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.common.contentmodel.util.DOMWriter; -import org.eclipse.wst.xml.core.document.XMLModel; -import org.eclipse.wst.xml.core.document.XMLNode; -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; - } - - /** - * 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()) { - 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; - } - - /** - * - */ - 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) { - XMLNode first = (XMLNode) list.get(0); - XMLNode last = (XMLNode) list.get(list.size() - 1); - XMLModel 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) { - XMLNode first = (XMLNode) list.get(0); - XMLNode last = (XMLNode) 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 2800ef55b5..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/TreeExtension.java +++ /dev/null @@ -1,512 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2004 IBM Corporation and others. All rights reserved. This - * program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies 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 tree; - protected EditManager editManager; - protected String[] columnProperties; - protected ICellModifier cellModifier; - protected int columnPosition = 300; - protected int columnHitWidth = 5; - protected Color tableLineColor; - protected int controlWidth; - protected DelayedDrawTimer delayedDrawTimer; - - public TreeExtension(Tree tree) { - this.tree = 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() { - } - - public ICellModifier getCellModifier() { - return cellModifier; - } - - public List getItemList() { - List list = new Vector(); - getItemListHelper(tree.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(tree.getDisplay(), SWT.CURSOR_SIZEWE); - tree.setCursor(cursor); - } - } else { - if (cursor != null) { - tree.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 = tree.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; - tree.setSelection(items); - } - } - } - - public void mouseUp(MouseEvent e) { - columnDragged = -1; - } - } - - public String[] getColumnProperties() { - return columnProperties; - } - - public void setColumnProperties(String[] columnProperties) { - this.columnProperties = columnProperties; - } - - public void paintControl(PaintEvent event) { - GC gc = event.gc; - Rectangle treeBounds = tree.getBounds(); - - controlWidth = treeBounds.width; - Color bg = tree.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND); - Color bg2 = tree.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); - // } - // } - // } - // } - // - TreeItem[] items = tree.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) { - int startY = itemBounds.y < treeBounds.y ? itemBounds.y : treeBounds.y + ((treeBounds.y - itemBounds.y) % height); - - 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); - } else { - addEmptyTreeMessage(gc); - } - - paintItems(gc, items, treeBounds); - } - - 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. This which foils our code that draw - // the 'row' lines since we assume that - // lines should be drawn at 'itemHeight' increments. In the case of - // LINUX we don't trust getItemHeight() - // to compute the increment... instead we compute the value based on - // distance between two TreeItems. - // if (B2BHacks.IS_UNIX) { - // TreeItem[] items = tree.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 = result != -1 ? result : tree.getItemHeight(); - return result; - } - - protected void addEmptyTreeMessage(GC gc) { - } - - 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) { - } - - 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 control) { - this.control = control; - } - - public void reset(int milliseconds) { - getDisplay().timerExec(milliseconds, this); - } - - public void run() { - control.redraw(); - } - } - - private Display getDisplay() { - - return PlatformUI.getWorkbench().getDisplay(); - } - - /** - * EditManager - */ - public class EditManager { - protected Tree tree; - protected Control cellEditorHolder; - protected CellEditorState cellEditorState; - - public EditManager(Tree tree) { - this.tree = 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.treeItem; - - // The area below the cell editor needs to be explicity - // repainted on Linux - // - // Rectangle r = B2BHacks.IS_UNIX ? treeItem.getBounds() : - // null; - - Object value = cellEditorState.cellEditor.getValue(); - String property = cellEditorState.property; - - 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 (columnProperties.length > column) { - String property = columnProperties[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 cellEditor; - public Control control; - public TreeItem treeItem; - public int columnNumber; - public String property; - - public CellEditorState(CellEditor cellEditor, Control control, TreeItem treeItem, int columnNumber, String property) { - this.cellEditor = cellEditor; - this.control = control; - this.treeItem = treeItem; - this.columnNumber = columnNumber; - this.property = property; - } - - public void activate() { - Object element = treeItem.getData(); - String value = cellModifier.getValue(element, property).toString(); - if (control instanceof Text) { - Text text = (Text) control; - int requiredSize = value.length() + 100; - if (text.getTextLimit() < requiredSize) { - text.setTextLimit(requiredSize); - } - } - Rectangle r = treeItem.getBounds(); - if (r != null) { - control.setBounds(columnPosition + 5, r.y + 1, tree.getClientArea().width - (columnPosition + 5), r.height - 1); - control.setVisible(true); - cellEditor.setValue(value); - cellEditor.addListener(this); - cellEditor.setFocus(); - control.addFocusListener(this); - } - } - - public void deactivate() { - cellEditor.removeListener(this); - control.removeFocusListener(this); - cellEditor.deactivate(); - tree.forceFocus(); - } - - // ICellEditorListener methods - // - public void applyEditorValue() { - applyCellEditorValue(); - } - - public void cancelEditor() { - deactivateCellEditor(); - } - - public void editorValueChanged(boolean oldValidState, boolean newValidState) { - } - - // FocusListener methods - // - public void focusGained(FocusEvent e) { - } - - public void focusLost(FocusEvent e) { - applyCellEditorValue(); - } - } - } -}
\ No newline at end of file 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 9d37f78fc8..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/ViewerExpandCollapseAction.java +++ /dev/null @@ -1,65 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2004 IBM Corporation and others. All rights reserved. This - * program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies 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.internal.ui.XMLEditorPluginImageHelper; -import org.eclipse.wst.xml.internal.ui.XMLEditorPluginImages; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; - -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(XMLUIPlugin.getResourceString("%_UI_INFO_EXPAND_ALL")); //$NON-NLS-1$ - } 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(XMLUIPlugin.getResourceString("%_UI_INFO_COLLAPSE_ALL")); //$NON-NLS-1$ - } - } - - 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/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 252d0b00a1..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeActionBarContributor.java +++ /dev/null @@ -1,323 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies 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.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.common.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.common.contentmodel.modelqueryimpl.CMDocumentLoader; -import org.eclipse.wst.common.contentmodel.modelqueryimpl.InferredGrammarBuildingCMDocumentLoader; -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.sse.ui.StructuredTextEditor; -import org.eclipse.wst.xml.core.document.XMLModel; -import org.eclipse.wst.xml.core.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.internal.ui.IDesignViewer; -import org.eclipse.wst.xml.internal.ui.IDesignViewerActionBarContributor; -import org.eclipse.wst.xml.internal.ui.XMLEditorResourceHandler; -import org.eclipse.wst.xml.internal.ui.XMLMultiPageEditorPart; -import org.eclipse.wst.xml.ui.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("com.ibm.etools.sed.editor.xmlmenu"); //$NON-NLS-1$ - - if (xmlMenu == null) { - xmlMenu = new MenuManager(XMLEditorResourceHandler.getResourceString("%XMLTableTreeActionBarContributor.0"), "com.ibm.etools.sed.editor.xmlmenu"); //$NON-NLS-1$ //$NON-NLS-2$ - bars.getMenuManager().insertBefore(IWorkbenchActionConstants.M_WINDOW, xmlMenu); - } else { - removeContributions(xmlMenu); - } - - tbm.add(new Separator("DESIGN_VIEWER_SEPARATOR_1_ID")); //$NON-NLS-1$ - - // ValidateXMLAction - // - // ugly hack ... we don't contribute the generic XML validator if we - // already - // have a DAD validator contribution (in the case of the DAD editor). - // This hack will be removed when defect 212448 is fixed. - // - // if (tbm.find("validate.dad.validateDAD") == null) { - // validateXMLAction = new ValidateXMLAction(); - // tbm.add(validateXMLAction); - // xmlMenu.add(validateXMLAction); - // } - - // 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(XMLEditorResourceHandler.getResourceString("%XMLTableTreeActionBarContributor.1")); //$NON-NLS-1$ - xmlMenu.add(xmlMenuExpandAction); - - xmlMenuCollapseAction = new ViewerExpandCollapseAction(false); - xmlMenuCollapseAction.setId(COLLAPSE_ALL_ID); - xmlMenuCollapseAction.setId(EXPAND_ALL_ID); - xmlMenuCollapseAction.setText(XMLEditorResourceHandler.getResourceString("%XMLTableTreeActionBarContributor.2")); //$NON-NLS-1$ - 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(XMLEditorResourceHandler.getResourceString("%XMLTableTreeActionBarContributor.3")); //$NON-NLS-1$ - setText(XMLEditorResourceHandler.getResourceString("%XMLTableTreeActionBarContributor.4")); //$NON-NLS-1$ - setImageDescriptor(onImage); - } else { - setToolTipText(XMLEditorResourceHandler.getResourceString("%XMLTableTreeActionBarContributor.5")); //$NON-NLS-1$ - setText(XMLEditorResourceHandler.getResourceString("%XMLTableTreeActionBarContributor.6")); //$NON-NLS-1$ - 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(XMLEditorResourceHandler.getResourceString("%XMLTableTreeActionBarContributor.7")); //$NON-NLS-1$ - setText(XMLEditorResourceHandler.getResourceString("%XMLTableTreeActionBarContributor.8")); //$NON-NLS-1$ - } - - public void setModel(IStructuredModel newModel) { - this.model = newModel; - } - - public void run() { - if (model != null) { - ModelQuery modelQuery = ModelQueryUtil.getModelQuery(model); - Document document = ((XMLModel) 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() { - } -}
\ No newline at end of file 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 4603efa862..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeContentProvider.java +++ /dev/null @@ -1,367 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2004 IBM Corporation and others. All rights reserved. This - * program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies 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.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.swt.widgets.Control; -import org.eclipse.wst.common.contentmodel.CMDocument; -import org.eclipse.wst.common.contentmodel.modelquery.CMDocumentManager; -import org.eclipse.wst.common.contentmodel.modelquery.CMDocumentManagerListener; -import org.eclipse.wst.common.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.common.contentmodel.util.CMDocumentCache; -import org.eclipse.wst.sse.core.AbstractAdapterFactory; -import org.eclipse.wst.sse.core.INodeAdapter; -import org.eclipse.wst.sse.core.INodeNotifier; -import org.eclipse.wst.xml.core.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.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 ViewerNotifyingAdapterFactory viewerNotifyingAdapterFactory = new ViewerNotifyingAdapterFactory(); - protected XMLTableTreePropertyDescriptorFactory propertyDescriptorFactory; - // protected ImageFactory imageFactory = - // XMLCommonUIPlugin.getInstance().getImageFactory(); - protected List viewerList = new Vector(); - protected TreeContentHelper treeContentHelper = new TreeContentHelper(); - - protected CMDocumentManager documentManager; - - public XMLTableTreeContentProvider() { - } - - public void getDecendantList(Object element, List list) { - Object[] children = getChildren(element); - if (children != null) { - for (int i = 0; i < children.length; i++) { - Object child = children[i]; - list.add(child); - getDecendantList(child, list); - } - } - } - - public void addViewer(Viewer viewer) { - viewerList.add(viewer); - } - - public Object[] getChildren(Object element) { - viewerNotifyingAdapterFactory.doAdapt(element); - return treeContentHelper.getChildren(element); - } - - public Object getParent(Object o) { - 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 boolean hasChildren(Object element) { - viewerNotifyingAdapterFactory.doAdapt(element); - return getChildren(element).length > 0; - } - - public Object[] getElements(Object element) { - viewerNotifyingAdapterFactory.doAdapt(element); - return getChildren(element); - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - // remove our listeners to the old state - if (oldInput != null) { - propertyDescriptorFactory = null; - Document domDoc = (Document) oldInput; - ModelQuery mq = ModelQueryUtil.getModelQuery(domDoc); - if (mq != null) { - documentManager = mq.getCMDocumentManager(); - if (documentManager != null) { - documentManager.removeListener(this); - } - } - } - - if (newInput != null) { - Document domDoc = (Document) newInput; - ModelQuery mq = ModelQueryUtil.getModelQuery(domDoc); - - if (mq != null) { - propertyDescriptorFactory = new XMLTableTreePropertyDescriptorFactory(mq); - documentManager = mq.getCMDocumentManager(); - if (documentManager != null) { - documentManager.setPropertyEnabled(CMDocumentManager.PROPERTY_ASYNC_LOAD, true); - documentManager.addListener(this); - } - } - } - } - - public boolean isDeleted(Object element) { - return element != null; - } - - // - // ILabelProvider stuff - // - public void addListener(ILabelProviderListener listener) { - } - - public void dispose() { - viewerList = new Vector(); - } - - 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 Image getImage(Object object) { - viewerNotifyingAdapterFactory.doAdapt(object); - 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 = 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 String getText(Object object) { - viewerNotifyingAdapterFactory.doAdapt(object); - 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$ - } - - // - // ITableLabelProvider stuff - // - public String getColumnText(Object object, int column) { - viewerNotifyingAdapterFactory.doAdapt(object); - 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 Image getColumnImage(Object object, int columnIndex) { - viewerNotifyingAdapterFactory.doAdapt(object); - return (columnIndex == 0) ? getImage(object) : null; - } - - public boolean isLabelProperty(Object object, String property) { - return false; - } - - public void removeListener(ILabelProviderListener listener) { - } - - // There is only 1 adapter associated with this factory. This single - // adapter gets added - // to the adapter lists of many nodes. - public class ViewerNotifyingAdapterFactory extends AbstractAdapterFactory { - protected ViewerNotifyingAdapter viewerNotifyingAdapter = new ViewerNotifyingAdapter(); - - protected INodeAdapter createAdapter(INodeNotifier target) { - return viewerNotifyingAdapter; - } - - protected ViewerNotifyingAdapter doAdapt(Object object) { - ViewerNotifyingAdapter result = null; - if (object instanceof INodeNotifier) { - result = (ViewerNotifyingAdapter) adapt((INodeNotifier) object); - } - return result; - } - } - - public class ViewerNotifyingAdapter implements INodeAdapter { - public boolean isAdapterForType(Object type) { - return type.equals(viewerNotifyingAdapterFactory); - } - - public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) { - switch (eventType) { - //case INodeNotifier.ADD: // ignore - //case INodeNotifier.REMOVE: // ignore - case INodeNotifier.CHANGE : - case INodeNotifier.STRUCTURE_CHANGED : - case INodeNotifier.CONTENT_CHANGED : { - Node node = (Node) notifier; - if (node.getNodeType() == Node.ELEMENT_NODE || node.getNodeType() == Node.DOCUMENT_NODE) { - for (Iterator i = viewerList.iterator(); i.hasNext();) { - Viewer viewer = (Viewer) i.next(); - - if (viewer instanceof StructuredViewer) { - ((StructuredViewer) viewer).refresh(node); - } else { - // todo... consider doing a time delayed - // refresh here!! - viewer.refresh(); - } - } - } - break; - } - } - } - } - - // 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 static Text getHiddenChildTextNode(Node node) { - return null; - } - - // 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 propertyChanged(CMDocumentManager cmDocumentManager, String propertyName) { - if (cmDocumentManager.getPropertyEnabled(CMDocumentManager.PROPERTY_AUTO_LOAD)) { - doDelayedRefreshForViewers(); - } - } - - protected void doDelayedRefreshForViewers() { - List list = new Vector(); - list.addAll(viewerList); - - for (Iterator i = list.iterator(); i.hasNext();) { - final Viewer viewer = (Viewer) i.next(); - Control control = viewer.getControl(); - Runnable runnable = new Runnable() { - public void run() { - viewer.refresh(); - } - }; - // we need to ensure that this is run via 'asyncExec' since these - // notifications can come from a non-ui thread - control.getDisplay().asyncExec(runnable); - } - } -}
\ No newline at end of file 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 7f2730e9d0..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeHelpContextIds.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies 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; - - - -/** - * 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 { - - public static final String PREFIX = "com.ibm.etools.sed.tabletree."; //$NON-NLS-1$ - - // XML Design View - public static final String XML_DESIGN_VIEW_HELPID = PREFIX + "xmlm3000"; //$NON-NLS-1$ -}
\ No newline at end of file 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 65fe7554f7..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreePropertyDescriptorFactory.java +++ /dev/null @@ -1,97 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2004 IBM Corporation and others. All rights reserved. This - * program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies 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.common.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.common.contentmodel.CMElementDeclaration; -import org.eclipse.wst.common.contentmodel.CMNode; -import org.eclipse.wst.common.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.sse.ui.views.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(ModelQuery modelQuery) { - super(modelQuery); - } - - protected IPropertyDescriptor createPropertyDescriptorHelper(String name, Element element, CMNode cmNode) { - IPropertyDescriptor result = null; - - String[] valuesArray = getModelQuery().getPossibleDataTypeValues(element, cmNode); - if (valuesArray != null && valuesArray.length > 0) { - result = new EnumeratedStringPropertyDescriptor(name, name, valuesArray); - } - - 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; - CMElementDeclaration ed = getModelQuery().getCMElementDeclaration(parentElement); - if (ed != null) { - result = createPropertyDescriptorHelper(HACK, parentElement, ed); - } - } - - if (result == null) { - result = new TextPropertyDescriptor(HACK, HACK); - } - - return result; - } - - public IPropertyDescriptor createAttributePropertyDescriptor(Attr attr) { - IPropertyDescriptor result = null; - - String attributeName = attr.getName(); - - CMAttributeDeclaration ad = getModelQuery().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; - } -}
\ No newline at end of file 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 34bb4e7af7..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeViewer.java +++ /dev/null @@ -1,331 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2004 IBM Corporation and others. All rights reserved. This - * program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies 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.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.viewers.CellEditor; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.common.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.sse.core.IModelStateListener; -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.sse.ui.ViewerSelectionManager; -import org.eclipse.wst.sse.ui.view.events.INodeSelectionListener; -import org.eclipse.wst.sse.ui.view.events.NodeSelectionChangedEvent; -import org.eclipse.wst.xml.core.document.XMLModel; -import org.eclipse.wst.xml.core.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.internal.ui.IDesignViewer; -import org.eclipse.wst.xml.internal.ui.XMLEditorResourceHandler; -import org.eclipse.wst.xml.ui.actions.NodeAction; -import org.eclipse.wst.xml.ui.dnd.XMLDragAndDropManager; -import org.eclipse.wst.xml.ui.views.contentoutline.XMLNodeActionManager; -import org.w3c.dom.Document; - -public class XMLTableTreeViewer extends TreeViewer implements IDesignViewer { - - /** - * This class is used to improve source editing performance by coalescing - * multiple notifications for an element change into a single refresh - */ - class DelayedRefreshTimer implements Runnable { - private final int delta = 2000; - protected Object objectPendingRefresh; - protected ISelection pendingSelection; - protected Object prevObject; - protected XMLTableTreeViewer viewer; - - public DelayedRefreshTimer(XMLTableTreeViewer viewer) { - this.viewer = viewer; - } - - public boolean isRefreshPending() { - return objectPendingRefresh != null; - } - - public void refresh(Object object) { - if (prevObject == object) { - objectPendingRefresh = object; - getDisplay().timerExec(delta, this); - } else { - if (objectPendingRefresh != null) { - viewer.doRefresh(objectPendingRefresh, false); - objectPendingRefresh = null; - } - viewer.doRefresh(object, false); - } - prevObject = object; - } - - private Display getDisplay() { - - return PlatformUI.getWorkbench().getDisplay(); - } - - public void run() { - // defect 239677 ensure that the viewer's control is not disposed - // - if (objectPendingRefresh != null && !viewer.getTree().isDisposed()) { - viewer.doRefresh(objectPendingRefresh, true); - if (pendingSelection != null) { - // see fireSelectionChanged comment about jumping cursor - // problem - // - viewer.setSelection(pendingSelection, true); - pendingSelection = null; - } - objectPendingRefresh = null; - prevObject = null; - } - } - - public void setSelection(ISelection selection) { - pendingSelection = selection; - } - } - - class DelayingNodeSelectionListener implements INodeSelectionListener { - public void nodeSelectionChanged(NodeSelectionChangedEvent event) { - // if (isNodeSelectionListenerEnabled && - // !event.getSource().equals(this)) { - if (!event.getSource().equals(XMLTableTreeViewer.this)) { - List selectedNodes = event.getSelectedNodes(); - ISelection selection = new StructuredSelection(selectedNodes); - - // for performance purposes avoid large multi-selections - // - if (selectedNodes.size() < 100) { - if (timer.isRefreshPending()) { - timer.setSelection(selection); - } else { - setSelection(selection, true); - } - } - } - } - } - - class InternalModelStateListener implements IModelStateListener { - - public void modelAboutToBeChanged(IStructuredModel model) { - ignoreRefresh = true; - } - - public void modelChanged(IStructuredModel model) { - ignoreRefresh = false; - refresh(); - } - - public void modelDirtyStateChanged(IStructuredModel model, boolean isDirty) { - } - - public void modelResourceDeleted(IStructuredModel model) { - } - - public void modelResourceMoved(IStructuredModel originalmodel, IStructuredModel movedmodel) { - } - } - - class NodeActionMenuListener implements IMenuListener { - public void menuAboutToShow(IMenuManager menuManager) { - // used to disable NodeSelection listening while running - // NodeAction - XMLNodeActionManager nodeActionManager = new XMLNodeActionManager(fModel, XMLTableTreeViewer.this) { - public void beginNodeAction(NodeAction action) { - super.beginNodeAction(action); - } - - public void endNodeAction(NodeAction action) { - super.endNodeAction(action); - } - }; - nodeActionManager.fillContextMenu(menuManager, getSelection()); - } - } - - protected CellEditor cellEditor; - - int count = 0; - - protected IModelStateListener fInternalModelStateListener = new InternalModelStateListener(); - protected IStructuredModel fModel = null; - protected INodeSelectionListener fNodeSelectionListener; - - protected ViewerSelectionManager fViewerSelectionManager; - - protected boolean ignoreRefresh; - - protected DelayedRefreshTimer timer; - protected XMLTreeExtension treeExtension; - - 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(); - provider.addViewer(this); - setContentProvider(provider); - setLabelProvider(provider); - - createContextMenu(); - - XMLDragAndDropManager.addDragAndDropSupport(this); - timer = new DelayedRefreshTimer(this); - } - - /** - * 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); - } - - protected void doRefresh(Object o, boolean fromDelayed) { - treeExtension.resetCachedData(); - super.refresh(o); - } - - protected void fireSelectionChanged(SelectionChangedEvent event) { - if (!getTree().isDisposed() && !getTree().isFocusControl()) { - // defect 246094 - // Various jumping cursor problems are caused when a selection - // 'delayed' selection occurs. - // These delayed selections are caused two ways: - // - // - when DelayedRefreshTimer calls doRefresh() ... the - // 'preserveSelection' causes selection to occur - // - when DelayedRefreshTimer performs a 'pending' selection - // - // Since we only want to update the selectionManager on an explict - // user action - // (and not some selection that is merely a resonse to the - // selection manager) - // we ensure that the tree has focus control before firing events - // to the selectionManager. - // - removeSelectionChangedListener(fViewerSelectionManager); - super.fireSelectionChanged(event); - addSelectionChangedListener(fViewerSelectionManager); - } else { - super.fireSelectionChanged(event); - } - } - - - public INodeSelectionListener getNodeSelectionListener() { - if (fNodeSelectionListener == null) - fNodeSelectionListener = new DelayingNodeSelectionListener(); - return fNodeSelectionListener; - } - - public String getTitle() { - return XMLEditorResourceHandler.getResourceString("%XMLTableTreeViewer.0"); //$NON-NLS-1$ - } - - protected void handleDispose(DisposeEvent event) { - super.handleDispose(event); - treeExtension.dispose(); - setModel(null); - setViewerSelectionManager(null); - - // if (fViewerSelectionManager != null) { - // fViewerSelectionManager.removeNodeSelectionListener(getNodeSelectionListener()); - // } - // - // fOverlayIconManager.setResource(null); - // super.handleDispose(event); - // - // if (fModel != null) - // fModel.removeModelStateListener(fInternalModelStateListener); - } - - public void refresh() { - if (!ignoreRefresh && !getControl().isDisposed()) { - treeExtension.resetCachedData(); - super.refresh(); - - // if (B2BHacks.IS_UNIX) { - // this is required to fix defect 193792 - // this fixes the problem where the 'paintHandler'drawn portions - // of tree weren't repainted properly - // - getTree().redraw(0, 0, getTree().getBounds().width, getTree().getBounds().height, false); - getTree().update(); - // } - } - } - - public void refresh(Object o) { - if (!ignoreRefresh && !getControl().isDisposed() && timer != null) { - if (getTree().isVisible()) { - doRefresh(o, false); - } else { - timer.refresh(o); - } - } - } - - public void setModel(IStructuredModel model) { - // remove - if (fModel != null) { - fModel.removeModelStateListener(fInternalModelStateListener); - } - - fModel = model; - Document domDoc = null; - - if (fModel != null && fModel instanceof XMLModel) { - model.addModelStateListener(fInternalModelStateListener); - ModelQuery mq = ModelQueryUtil.getModelQuery(model); - treeExtension.setModelQuery(mq); - domDoc = ((XMLModel) fModel).getDocument(); - setInput(domDoc); - } - } - - // the following methods implement the IDesignViewer interface - // - getControl() is implemented via AdvancedTableTreeViewer - // - public void setViewerSelectionManager(ViewerSelectionManager viewerSelectionManager) { - // disconnect from old one - if (fViewerSelectionManager != null) { - fViewerSelectionManager.removeNodeSelectionListener(getNodeSelectionListener()); - removeSelectionChangedListener(fViewerSelectionManager); - } - - fViewerSelectionManager = viewerSelectionManager; - - // connect to new one - if (fViewerSelectionManager != null) { - fViewerSelectionManager.addNodeSelectionListener(getNodeSelectionListener()); - addSelectionChangedListener(fViewerSelectionManager); - } - } - -}
\ 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 44a0373dfc..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTreeExtension.java +++ /dev/null @@ -1,179 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2004 IBM Corporation and others. All rights reserved. This - * program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies 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.common.contentmodel.CMElementDeclaration; -import org.eclipse.wst.common.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.common.contentmodel.util.CMDescriptionBuilder; -import org.eclipse.wst.xml.internal.ui.XMLEditorResourceHandler; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -public class XMLTreeExtension extends TreeExtension { - - public final static String STRUCTURE_PROPERTY = XMLEditorResourceHandler.getResourceString("%XMLTreeExtension.0"); //$NON-NLS-1$ - public final static String VALUE_PROPERTY = XMLEditorResourceHandler.getResourceString("%XMLTreeExtension.1"); //$NON-NLS-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; - private ModelQuery fModelQuery; - - public XMLTreeExtension(Tree tree) { - super(tree); - control = tree; - modifier = new MyCellModifier(); - setCellModifier(modifier); - String[] properties = {STRUCTURE_PROPERTY, VALUE_PROPERTY}; - setColumnProperties(properties); - - f1 = tree.getDisplay().getSystemColor(SWT.COLOR_BLACK); - 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; - } - - 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(tree.getDisplay().getSystemColor(SWT.COLOR_BLACK)); - gc.setBackground(tree.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); - gc.drawString(XMLEditorResourceHandler.getResourceString("%XMLTreeExtension.3"), 10, 10); //$NON-NLS-1$ - gc.drawString(XMLEditorResourceHandler.getResourceString("%XMLTreeExtension.4"), 10, 10 + gc.getFontMetrics().getHeight()); //$NON-NLS-1$ - } - - public String getElementValueHelper(Element element) { - String result = null; - - if (result == null && getModelQuery() != null) { - CMElementDeclaration ed = getModelQuery().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; - } - } - - - public ModelQuery getModelQuery() { - return fModelQuery; - } - - /** - * @param query - */ - public void setModelQuery(ModelQuery query) { - fModelQuery = query; - propertyDescriptorFactory = new XMLTableTreePropertyDescriptorFactory(query); - } - -}
\ No newline at end of file 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 9cf981165d..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NamespaceInfoContentBuilder.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies 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.common.contentmodel.CMAnyElement; -import org.eclipse.wst.common.contentmodel.CMElementDeclaration; -import org.eclipse.wst.common.contentmodel.util.ContentBuilder; -import org.eclipse.wst.common.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) - { - super.visitCMElementDeclaration(ed); - } - } - - protected void createAnyElementNode(CMAnyElement anyElement) - { - String uri = anyElement.getNamespaceURI(); - if (uri != null && !uri.startsWith("##")) - { - if (table.get(uri) == null) - { - NamespaceInfo info = new NamespaceInfo(); - info.uri = uri; - info.prefix = "p" + count++; - 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 e3a929b44b..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewModelWizard.java +++ /dev/null @@ -1,326 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies 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.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.jface.viewers.IStructuredSelection; -import org.eclipse.jface.wizard.Wizard; -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.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.IEditorDescriptor; -import org.eclipse.ui.IEditorRegistry; -import org.eclipse.ui.INewWizard; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.WizardNewFileCreationPage; - -public class NewModelWizard extends Wizard implements INewWizard -{ - - protected IStructuredSelection selection; - protected IWorkbench workbench; - protected String currentDirectory; - - public NewModelWizard() - { - } - - public void init(IWorkbench workbench, IStructuredSelection selection) - { - this.workbench = workbench; - this.selection = 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 currentDirectory) - { - this.currentDirectory = currentDirectory; - } - - - 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); - //TODO... setHelp - //WorkbenchHelp.setHelp(base, XMLBuilderContextIds.XMLC_CREATE_PAGE); - 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); - //TODO... set help - //WorkbenchHelp.setHelp(radioButtonsGroup, XMLBuilderContextIds.XMLC_RADIO_GROUP); - - 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)); - //TODO... set help - //WorkbenchHelp.setHelp(radioButton[i], new ControlContextComputer(radioButton[i], XMLBuilderContextIds.XMLC_RADIO_BUTTON)); - //radioButton[i].addListener(SWT.Modify, this); - } - setControl(base); - setPageComplete(isPageComplete()); - } - - public void handleEvent(Event event) - { - if (event.type == SWT.Modify) - { - setPageComplete(isPageComplete()); - } - } - } - - - /** - * NewFilePage - */ - public class NewFilePage extends WizardNewFileCreationPage - { - public String defaultName = "NewFile"; - public String defaultFileExtension = ".txt"; - public String[] filterExtensions = { "*.txt"}; - - public NewFilePage(IStructuredSelection selection) - { - super("", selection); - } - - 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)) - { - //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(); - String fileExtension = (new Path(fullFileName)).getFileExtension(); - if (fileExtension != null) - { - IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry(); - IEditorDescriptor defaultEditorDescriptor = editorRegistry.getDefaultEditor(); - IEditorDescriptor[] descriptors = editorRegistry.getEditors(getFileName()); - if (descriptors.length == 0) - { - setErrorMessage(XMLWizard.getString("_ERROR_BAD_FILENAME_EXTENSION")); - return false; - } - } - else - { - // no fileExtension, let's check for this file with an .xml extension - fullFileName += ".xml"; - if ( (getContainerFullPath() != null) && (getContainerFullPath().isEmpty() == false) - && (getFileName().compareTo("") != 0)) - { - Path fullPath = new Path(getContainerFullPath().toString() + '/' + fullFileName); - IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(fullPath); - if (resource != null) - { - setErrorMessage(XMLWizard.getString("_ERROR_FILE_ALREADY_EXISTS")); - return false; - } - } - } - - // check for file should be case insensitive - String sameName = existsFileAnyCase(fullFileName); - if (sameName != null) - { - String qualifiedFileName = getContainerFullPath().toString() + '/' + fullFileName; - setErrorMessage(XMLWizard.getString("_ERROR_FILE_ALREADY_EXISTS") + " " + sameName); - 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()); - } - } -} - 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 6ad0dd44d2..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLGenerator.java +++ /dev/null @@ -1,423 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies 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.runtime.Preferences; -import org.eclipse.jface.util.Assert; -import org.eclipse.wst.common.contentmodel.CMDocument; -import org.eclipse.wst.common.contentmodel.CMElementDeclaration; -import org.eclipse.wst.common.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.common.contentmodel.CMPlugin; -import org.eclipse.wst.common.contentmodel.util.ContentBuilder; -import org.eclipse.wst.common.contentmodel.util.DOMContentBuilderImpl; -import org.eclipse.wst.common.contentmodel.util.DOMWriter; -import org.eclipse.wst.common.contentmodel.util.NamespaceInfo; -import org.eclipse.wst.sse.core.preferences.CommonModelPreferenceNames; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.eclipse.wst.xml.uriresolver.XMLCatalog; -import org.eclipse.wst.xml.uriresolver.XMLCatalogEntry; -import org.eclipse.wst.xml.uriresolver.XMLCatalogPlugin; -import org.eclipse.wst.xml.uriresolver.util.IdResolver; -import org.eclipse.wst.xml.uriresolver.util.IdResolverImpl; -import org.eclipse.wst.xml.uriresolver.util.URIHelper; -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 XMLCatalogEntry xmlCatalogEntry; - - // info for dtd - protected String publicId; - protected String systemId; - protected String defaultSystemId; - - // info for xsd - public List namespaceInfoList; - - public NewXMLGenerator() - { - } - - 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)) - { - uri = URIHelper.normalize(uri, null, null); - cmDocument = CMPlugin.getInstance().createCMDocument(uri, null); - - if (uri.endsWith(".dtd")) - { - if (errorList.size() > 0) - { - title = XMLWizard.getString("_UI_INVALID_GRAMMAR_ERROR"); - message = XMLWizard.getString("_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 = XMLWizard.getString("_UI_INVALID_GRAMMAR_ERROR"); - message = XMLWizard.getString("_UI_LABEL_ERROR_SCHEMA_INVALID_INFO"); - } - else if (cmDocument != null) - { - int globalElementCount = cmDocument.getElements().getLength(); - if (globalElementCount == 0) - { - title = XMLWizard.getString("_UI_WARNING_TITLE_NO_ROOT_ELEMENTS"); - message=XMLWizard.getString("_UI_WARNING_MSG_NO_ROOT_ELEMENTS"); - } - } - } - } - else - { - title = XMLWizard.getString("_UI_WARNING_TITLE_NO_ROOT_ELEMENTS"); - message = - XMLWizard.getString("_UI_WARNING_URI_NOT_FOUND_COLON") - + " " - + uri; - } - errorInfo[0] = title; - errorInfo[1] = message; - - return cmDocument; - } - - - public void createEmptyXMLDocument(IFile newFile) throws Exception - { - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - Preferences preference = XMLCorePlugin.getDefault().getPluginPreferences(); - String charSet = preference.getString(CommonModelPreferenceNames.OUTPUT_CODESET); - - PrintWriter writer = new PrintWriter(new OutputStreamWriter(outputStream, charSet)); - writer.println("<?xml version=\"1.0\" encoding=\"" + charSet + "\"?>"); - writer.flush(); - outputStream.close(); - - ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); - newFile.setContents(inputStream, true, true, null); - inputStream.close(); - } - - public void createXMLDocument(String xmlFileName) throws Exception - { - ByteArrayOutputStream outputStream = createXMLDocument(xmlFileName, false); - - File file = new File(xmlFileName); - FileOutputStream fos = new FileOutputStream(file); - outputStream.writeTo(fos); - fos.close(); - } - - - public void createXMLDocument(IFile newFile, String xmlFileName) throws Exception - { - ByteArrayOutputStream outputStream = createXMLDocument(xmlFileName, false); - - ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); - newFile.setContents(inputStream, true, true, null); - inputStream.close(); - } - - - public ByteArrayOutputStream createXMLDocument(String xmlFileName, boolean junk) throws Exception - { - 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); - - contentBuilder.setBuildPolicy(buildPolicy); - contentBuilder.setExternalCMDocumentSupport(new MyExternalCMDocumentSupport(namespaceInfoList, xmlFileName)); - contentBuilder.uglyTempHack = true; // todo... this line should be removed when 169191 is fixed - contentBuilder.createDefaultRootContent(cmDocument, cmElementDeclaration, namespaceInfoList); - - String[] encodingInfo = (String[])cmDocument.getProperty("encodingInfo"); - if (encodingInfo == null) - { - encodingInfo = new String[2]; - } - - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - OutputStreamWriter outputStreamWriter = encodingInfo[0] != null ? - new OutputStreamWriter(outputStream, encodingInfo[1]) : - new OutputStreamWriter(outputStream); - - DOMWriter domWriter = new DOMWriter(outputStreamWriter); - domWriter.print(xmlDocument, encodingInfo[1], cmDocument.getNodeName(), getNonWhitespaceString(getPublicId()), getNonWhitespaceString(getSystemId())); // todo... replace with domWriter.print(xmlDocument); when 169191 is fixed - outputStream.flush(); - outputStream.close(); - - return outputStream; - } - - - public void createNamespaceInfoList() - { - List result = new Vector(); - XMLCatalog xmlCatalog = XMLCatalogPlugin.getInstance().getDefaultXMLCatalog(); - if (cmDocument != null) - { - result = (List)cmDocument.getProperty("http://org.eclipse.wst/cm/properties/namespaceInfo"); - 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.getType() == XMLCatalogEntry.PUBLIC) - { - locationInfo = xmlCatalogEntry.getWebAddress(); - } - else - { - locationInfo = xmlCatalogEntry.getKey(); - } - } - if (locationInfo == null) - { - locationInfo = defaultSystemId; - } - info.locationHint = locationInfo; - info.setProperty("locationHint-readOnly", "true"); - } - info.setProperty("uri-readOnly", "true"); - info.setProperty("unremovable", "true"); - } - } - - 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; - - if (namespaceInfoList != null && isMissingNamespaceLocation()) - { - String title = XMLWizard.getString("_UI_LABEL_NO_LOCATION_HINT"); - String message = XMLWizard.getString("_UI_WARNING_MSG_NO_LOCATION_HINT_1") + " " + - XMLWizard.getString("_UI_WARNING_MSG_NO_LOCATION_HINT_2") + "\n\n" + - XMLWizard.getString("_UI_WARNING_MSG_NO_LOCATION_HINT_3"); - - errorList = new String[2]; - errorList[0] = title; - errorList[1] = message; - } - - return errorList; - } - - - public void setXMLCatalogEntry(XMLCatalogEntry catalogEntry) - { - xmlCatalogEntry = catalogEntry; - } - - public XMLCatalogEntry 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 namespaceInfoList; - protected IdResolver idResolver; - - protected MyExternalCMDocumentSupport(List namespaceInfoList, String resourceLocation) - { - this.namespaceInfoList = namespaceInfoList; - idResolver = new IdResolverImpl(resourceLocation); - } - - public CMDocument getCMDocument(Element element, String namespaceURI) - { - CMDocument result = null; - if (namespaceURI != null && namespaceURI.trim().length() > 0) - { - String locationHint = null; - for (Iterator i = namespaceInfoList.iterator(); i.hasNext(); ) - { - NamespaceInfo info = (NamespaceInfo)i.next(); - if (namespaceURI.equals(info.uri)) - { - locationHint = info.locationHint; - break; - } - } - if (locationHint != null) - { - grammarURI = idResolver.resolveId(locationHint, locationHint); - result = CMPlugin.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/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 073e495fa5..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLWizard.java +++ /dev/null @@ -1,937 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies 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.text.Collator; -import java.util.Arrays; -import java.util.List; -import java.util.Vector; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.Path; -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.contentmodel.CMDocument; -import org.eclipse.wst.common.contentmodel.CMElementDeclaration; -import org.eclipse.wst.common.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.common.contentmodel.util.DOMContentBuilder; -import org.eclipse.wst.common.contentmodel.util.NamespaceInfo; -import org.eclipse.wst.xml.ui.dialogs.NamespaceInfoErrorHelper; -import org.eclipse.wst.xml.ui.dialogs.SelectFileOrXMLCatalogIdPanel; -import org.eclipse.wst.xml.ui.dialogs.UpdateListener; -import org.eclipse.wst.xml.ui.nsedit.CommonEditNamespacesDialog; -import org.eclipse.wst.xml.uriresolver.XMLCatalogEntry; -import org.eclipse.wst.xml.uriresolver.util.URIHelper; - -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 - = {XMLWizard.getString("_UI_RADIO_XML_FROM_DTD"), - XMLWizard.getString("_UI_RADIO_XML_FROM_SCHEMA"), - XMLWizard.getString("_UI_RADIO_XML_FROM_SCRATCH")}; - - protected static final String[] filePageFilterExtensions = {".xml"}; - protected static final String[] browseXSDFilterExtensions = {".xsd"}; - protected static final String[] browseDTDFilterExtensions = {".dtd"}; - - protected NewFilePage newFilePage; - protected StartPage startPage; - protected SelectGrammarFilePage selectGrammarFilePage; - protected SelectRootElementPage selectRootElementPage; - - protected String cmDocumentErrorMessage; - - protected NewXMLGenerator generator; - - - public NewXMLWizard() - { - setWindowTitle(XMLWizard.getString("_UI_WIZARD_CREATE_XML_HEADING")); - setDefaultPageImageDescriptor(ImageDescriptor.createFromFile(XMLWizard.class,"icons/generatexml_wiz.gif")); - 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) - { - List errorList = new Vector(); - String[] errorInfo = new String[2]; - CMDocument cmDocument = NewXMLGenerator.createCMDocument(file.getLocation().toOSString(), 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(XMLWizard.getString("_UI_DIALOG_NEW_TITLE")); - dialog.setBlockOnOpen(true); - dialog.open(); - } - else - { - MessageDialog.openInformation(shell, errorInfo[0], errorInfo[1]); - } - } - - - public void addPages() - { - String grammarURI = generator.getGrammarURI(); - - if (grammarURI == null) - { - // start page - startPage = new StartPage("StartPage", createFromRadioButtonLabel) - { - 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 - //WorkbenchHelp.setHelp(startPage.getRadioButtonAtIndex(0), XMLBuilderContextIds.XMLC_FROM_DTD_RADIO); - //WorkbenchHelp.setHelp(startPage.getRadioButtonAtIndex(1), XMLBuilderContextIds.XMLC_XML_SCHEMA_RADIO); - //WorkbenchHelp.setHelp(startPage.getRadioButtonAtIndex(2), XMLBuilderContextIds.XMLC_SCRATCH_RADIO); - } - }; - - - startPage.setTitle(XMLWizard.getString("_UI_WIZARD_CREATE_XML_HEADING")); - startPage.setDescription(XMLWizard.getString("_UI_WIZARD_CREATE_XML_EXPL")); - addPage(startPage); - } - - // new file page - newFilePage = new NewFilePage(selection); - newFilePage.setTitle(XMLWizard.getString("_UI_WIZARD_CREATE_XML_FILE_HEADING")); - newFilePage.setDescription(XMLWizard.getString("_UI_WIZARD_CREATE_XML_FILE_EXPL")); - newFilePage.defaultName = (grammarURI != null) ? URIHelper.removeFileExtension(URIHelper.getLastSegment(grammarURI)) : "NewFile"; - newFilePage.defaultFileExtension = ".xml"; - newFilePage.filterExtensions = filePageFilterExtensions; - addPage(newFilePage); - - // selectGrammarFilePage - selectGrammarFilePage = new SelectGrammarFilePage(); - addPage(selectGrammarFilePage); - - // select root element page - selectRootElementPage = new SelectRootElementPage(); - selectRootElementPage.setTitle(XMLWizard.getString("_UI_WIZARD_SELECT_ROOT_HEADING")); - selectRootElementPage.setDescription(XMLWizard.getString("_UI_WIZARD_SELECT_ROOT_EXPL")); - addPage(selectRootElementPage); - } - - - 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")) - { - result = CREATE_FROM_DTD; - } - else if (grammarURI.endsWith(".xsd")) - { - result = CREATE_FROM_XSD; - } - } - else if (startPage != null) - { - int selectedIndex = startPage.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 (getCreateMode() == CREATE_FROM_SCRATCH) - { - nextPage = null; - } - 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(); - - if ((startPage != null && startPage.getSelectedRadioButtonIndex() == CREATE_FROM_SCRATCH && currentPage == newFilePage) || - (currentPage == selectRootElementPage)) - { - result = currentPage.isPageComplete(); - } - return result; - } - - - public boolean performFinish() - { - boolean result = true; - super.performFinish(); - try - { - - String[] namespaceErrors = generator.getNamespaceInfoErrors(); - if (namespaceErrors != null) - { - String title = namespaceErrors[0]; - String message = namespaceErrors[1]; - result = MessageDialog.openQuestion(getShell(), title, message); - } - - if (result) - { - String fileName = newFilePage.getFileName(); - if ((new Path(fileName)).getFileExtension() == null) - { - newFilePage.setFileName(fileName.concat(".xml")); - } - - IFile newFile = newFilePage.createNewFile(); - String xmlFileName = newFile.getLocation().toOSString(); - - if (getContainer().getCurrentPage() == selectRootElementPage) - { - - generator.createXMLDocument(newFile, xmlFileName); - } - else - { - generator.createEmptyXMLDocument(newFile); - } - - newFile.refreshLocal(1, null); - - IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - BasicNewResourceWizard.selectAndReveal(newFile, workbenchWindow); - openEditor(newFile); - } - } - catch (Exception e) - { - //e.printStackTrace(); - } - return result; - } - - public void openEditor(IFile file) - { - // Open editor on new file. - String editorId = null; - IEditorDescriptor editor = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getLocation().toOSString()); - if(editor != null){ - editorId = editor.getId(); - } - 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) { - } - } - - - protected String getDefaultSystemId() - { - String relativePath = "platform:/resource/" + newFilePage.getContainerFullPath().toString() + "/dummy"; - return URIHelper.getRelativeURI(generator.getGrammarURI(), relativePath); - } - - - /** - * SelectGrammarFilePage - */ - class SelectGrammarFilePage extends WizardPage - { - protected SelectFileOrXMLCatalogIdPanel panel; - - SelectGrammarFilePage() - { - super("SelectGrammarFilePage"); - } - - public void createControl(Composite parent) - { - Composite composite = new Composite(parent, SWT.NONE); - //WorkbenchHelp.setHelp(composite, XMLBuilderContextIds.XMLC_GRAMMAR_PAGE); - 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); - } - - public void setVisible(boolean visible) - { - super.setVisible(visible); - if (visible) - { - if (getCreateMode() == CREATE_FROM_DTD) - { - setTitle(XMLWizard.getString("_UI_WIZARD_SELECT_DTD_FILE_TITLE")); - setDescription(XMLWizard.getString("_UI_WIZARD_SELECT_DTD_FILE_DESC")); - panel.setFilterExtensions(browseDTDFilterExtensions); - } - else - { - setTitle(XMLWizard.getString("_UI_WIZARD_SELECT_XSD_FILE_TITLE")); - setDescription(XMLWizard.getString("_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 XMLCatalogEntry getXMLCatalogEntry() - { - return panel.getXMLCatalogEntry(); - } - - public String computeErrorMessage() - { - String errorMessage = null; - String uri = getURI(); - if (uri != null) - { - if (!URIHelper.isReadableURI(uri,false)) - { - errorMessage = XMLWizard.getString("_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"); - } - - public void createControl(Composite parent) - { - // container group - Composite containerGroup = new Composite(parent,SWT.NONE); - //WorkbenchHelp.setHelp(containerGroup, XMLBuilderContextIds.XMLC_ROOT_PAGE); - 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(XMLWizard.getString("_UI_LABEL_ROOT_ELEMENT")); - combo = new Combo(containerGroup, SWT.DROP_DOWN | SWT.READ_ONLY); - combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - combo.addSelectionListener(this); - //WorkbenchHelp.setHelp(combo, XMLBuilderContextIds.XMLC_ROOT_ROOT); - - // Options - { - Group group = new Group(containerGroup, SWT.NONE); - group.setText(XMLWizard.getString("_UI_WIZARD_CONTENT_OPTIONS")); - //WorkbenchHelp.setHelp(group, XMLBuilderContextIds.XMLC_CURRENT_GROUP); - - 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(XMLWizard.getString("_UI_WIZARD_CREATE_OPTIONAL_ATTRIBUTES")); - radioButton[0].setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - radioButton[0].setSelection(false); - //WorkbenchHelp.setHelp(radioButton[0], XMLBuilderContextIds.XMLC_CREATE_OPTIONAL_ATTRIBUTES); - - radioButton[1] = new Button(group, SWT.CHECK); - radioButton[1].setText(XMLWizard.getString("_UI_WIZARD_CREATE_OPTIONAL_ELEMENTS")); - radioButton[1].setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - radioButton[1].setSelection(false); - //WorkbenchHelp.setHelp(radioButton[1], XMLBuilderContextIds.XMLC_CREATE_OPTIONAL_ELEMENTS); - - radioButton[2] = new Button(group, SWT.CHECK); - radioButton[2].setText(XMLWizard.getString("_UI_WIZARD_CREATE_FIRST_CHOICE")); - radioButton[2].setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - radioButton[2].setSelection(true); - //WorkbenchHelp.setHelp(radioButton[2], XMLBuilderContextIds.XMLC_CREATE_FIRST_CHOICE); - - radioButton[3] = new Button(group, SWT.CHECK); - radioButton[3].setText(XMLWizard.getString("_UI_WIZARD_FILL_ELEMENTS_AND_ATTRIBUTES")); - radioButton[3].setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - radioButton[3].setSelection(true); - //WorkbenchHelp.setHelp(radioButton[3], XMLBuilderContextIds.XMLC_FILL_ELEMENTS_AND_ATTRIBUTES); -/* - radioButton = new Button[2]; - - radioButton[0] = new Button(group, SWT.RADIO); - radioButton[0].setText(XMLWizard.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(XMLWizard.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) - { - } - - 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]; - } - - 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"); - 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"); - int defaultRootIndex = -1; - combo.removeAll(); - - - 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")) - { - 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")) - { - 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"; - 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; - } - else - 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 = XMLWizard.getString("_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; - - public XSDOptionsPanel(SelectRootElementPage parentPage, Composite parent) - { - super(parent, SWT.NONE); - this.parentPage = parentPage; - - setLayout(createOptionsPanelLayout()); - setLayoutData(new GridData(GridData.FILL_BOTH)); - - Composite co = new Composite(this, SWT.NONE); - co.setLayout(new GridLayout()); - - if (newFilePage != null && newFilePage.getContainerFullPath() != null) - { - // todo... this is a nasty mess. I need to revist this code. - // - String resourceURI = "platform:/resource" + newFilePage.getContainerFullPath().toString() + "/dummy"; - String resolvedPath = URIHelper.normalize(resourceURI, null, null); - if (resolvedPath.startsWith("file:/")) - { - resolvedPath = resolvedPath.substring(6); - } - // end nasty messs - String tableTitle = XMLWizard.getString("_UI_LABEL_NAMESPACE_INFORMATION"); - editNamespaces = new CommonEditNamespacesDialog(co, new Path(resolvedPath), tableTitle, true, true); - } - - UpdateListener updateListener = new UpdateListener() - { - public void updateOccured(Object object, Object arg) - { - updateErrorMessage((List)arg); - } - }; - } - - public void setNamespaceInfoList(List list) - { - editNamespaces.setNamespaceInfoList(list); - editNamespaces.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(XMLWizard.getString("_UI_LABEL_DOCTYPE_INFORMATION")); - //WorkbenchHelp.setHelp(group, XMLBuilderContextIds.XMLC_DOCUMENTATION_GROUP); - - 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(XMLWizard.getString("_UI_LABEL_PUBLIC_ID")); - publicIdField = new Text(group, SWT.SINGLE | SWT.BORDER); - publicIdField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - publicIdField.addModifyListener(this); - //WorkbenchHelp.setHelp(publicIdField, XMLBuilderContextIds.XMLC_PUBLIC); - - Label systemIdLabel = new Label(group, SWT.NONE); - systemIdLabel.setText(XMLWizard.getString("_UI_LABEL_SYSTEM_ID")); - systemIdField = new Text(group, SWT.SINGLE | SWT.BORDER); - systemIdField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - systemIdField.addModifyListener(this); - //WorkbenchHelp.setHelp(systemIdField, XMLBuilderContextIds.XMLC_SYSTEM); - } - - public void update() - { - String thePublicId = null; - String theSystemId = null; - XMLCatalogEntry xmlCatalogEntry = generator.getXMLCatalogEntry(); - - if (xmlCatalogEntry != null) - { - if (xmlCatalogEntry.getType() == XMLCatalogEntry.PUBLIC) - { - thePublicId = xmlCatalogEntry.getKey(); - theSystemId = xmlCatalogEntry.getWebAddress(); - if (theSystemId == null) - { - theSystemId = generator.getGrammarURI().startsWith("http:") ? generator.getGrammarURI() : URIHelper.getLastSegment(generator.getGrammarURI()); - } - } - else - { - theSystemId = xmlCatalogEntry.getKey(); - } - } - else - { - theSystemId = getDefaultSystemId(); - } - - publicIdField.setText(thePublicId != null ? thePublicId : ""); - systemIdField.setText(theSystemId != null ? theSystemId : ""); - } - - 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/XMLExampleProjectCreationWizard.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/XMLExampleProjectCreationWizard.java deleted file mode 100644 index 529c7f3011..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/XMLExampleProjectCreationWizard.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies 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.resource.ImageDescriptor; -import org.eclipse.wst.common.ui.wizards.ExampleProjectCreationWizard; - -/** - * Wizard used for creating the XML samples. - * Most functionality is inherited from ExampleProjectCreationWizard. - * - * @deprecated - to be removed in WTP 1.0M4 - */ -public class XMLExampleProjectCreationWizard extends ExampleProjectCreationWizard { - - public static String EXAMPLE_WIZARD_XP_ID = "org.eclipse.wst.xml.ui.XMLExampleProjectCreationWizardExtension"; //$NON-NLS-1$ - - - public XMLExampleProjectCreationWizard() { - super(); - - } - - - protected ImageDescriptor getImageDescriptor(String banner) { - return XMLWizard.getInstance().getImageDescriptor(banner); - } - - public String getWizardExtensionId(){ - return EXAMPLE_WIZARD_XP_ID; - } -} 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 e61d75e2af..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/XMLImportActionDelegate.java +++ /dev/null @@ -1,200 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies 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.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Iterator; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IActionDelegate; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.xml.uriresolver.util.URIHelper; -import org.osgi.framework.Bundle; - -public class XMLImportActionDelegate implements IActionDelegate -{ -// TODO verify these - private static final String validateXSDPluginID = "org.eclipse.wst.xsd.validation"; - private static final String xsdValidatorClassName = "org.eclipse.wst.xsd.validation.internal.ui.eclipse.XSDValidator"; - - private static final String validateDTDPluginID = "org.eclipse.wst.dtd.validation"; - private static final String dtdValidatorClassName = "org.eclipse.wst.dtd.validation.internal.ui.eclipse.DTDValidator"; - - private static final String validationReportClassName = "org.eclipse.wst.validation.xmltools.ValidationReport"; - - - /** - * 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; - - if (file.getName().endsWith(".dtd") || file.getName().endsWith(".xsd")) - { - IPath path = file.getLocation(); - String uri = URIHelper.getURIForFilePath(path.toString()); - - boolean validationPluginsFound = false; - - Boolean isValid = null; - - Class[] parameterTypes = new Class[] {String.class}; - Object[] arguments = new Object[] {uri}; - - try - { - - if (file.getName().endsWith(".xsd")) - { -// Here is the Reflection equivalent way of performing the following lines -// XSDValidator xsdValidator = XSDValidator.getInstance(); -// ValidationReport valreport = xsdValidator.validate(uri); - - Bundle validateXSDBundle = Platform.getBundle(validateXSDPluginID); - if (validateXSDBundle != null) - { - Class xsdValidatorClass, validationReportClass; - Object xsdValidatorObject, validationReportObject; - - xsdValidatorClass = validateXSDBundle.loadClass(xsdValidatorClassName); - - Method getInstanceMethod = xsdValidatorClass.getMethod("getInstance", null); - xsdValidatorObject = getInstanceMethod.invoke(null, null); // static and no parameters - - Method validateMethod = xsdValidatorClass.getMethod("validate", parameterTypes); - validationReportObject = validateMethod.invoke(xsdValidatorObject, arguments); - - validationReportClass = validateXSDBundle.loadClass(validationReportClassName); - - Method isValidMethod = validationReportClass.getMethod("isValid", null); - isValid = (Boolean)isValidMethod.invoke(validationReportObject, null); - - validationPluginsFound = true; // made it this far, so declare that validation can be performed - } - } - else - { -// Here is the Reflection equivalent way of performing the following lines -// DTDValidator dtdValidator = DTDValidator.getInstance(); -// ValidationReport valreport = dtdValidator.validate(uri); - - Bundle validateDTDBundle = Platform.getBundle(validateDTDPluginID); - - if (validateDTDBundle != null) - { - Class dtdValidatorClass, validationReportClass; - Object dtdValidatorObject, validationReportObject; - - dtdValidatorClass = validateDTDBundle.loadClass(dtdValidatorClassName); - - Method getInstanceMethod = dtdValidatorClass.getMethod("getInstance", null); - dtdValidatorObject = getInstanceMethod.invoke(null, null); // static and no parameters - - Method validateMethod = dtdValidatorClass.getMethod("validate", parameterTypes); - validationReportObject = validateMethod.invoke(dtdValidatorObject, arguments); - - validationReportClass = validateDTDBundle.loadClass(validationReportClassName); - - Method isValidMethod = validationReportClass.getMethod("isValid", null); - isValid = (Boolean)isValidMethod.invoke(validationReportObject, null); - - validationPluginsFound = true; // made it this far, so declare that validation can be performed - } - } - } - catch (ClassNotFoundException e) - { - } - catch (NoSuchMethodException e) - { - } - catch (IllegalAccessException e) - { - } - catch (InvocationTargetException e) - { - } - - if (validationPluginsFound) - { - if (isValid != null && !isValid.booleanValue()) - { - String title = XMLWizard.getString("_UI_DIALOG_TITLE_INVALID_GRAMMAR"); - String message = XMLWizard.getString("_UI_DIALOG_MESSAGE_INVALID_GRAMMAR"); - boolean answer = MessageDialog.openQuestion(Display.getDefault().getActiveShell(), title, message); - if (!answer) - return; - } - } - else - { - // TODO externalize these strings - String title = "Validation Plugins Unavailable"; - String message = "Validation cannot be performed because the validation plugins were disabled or not found. The generated file may be invalid. Do you wish to continue?"; - boolean answer = MessageDialog.openQuestion(Display.getDefault().getActiveShell(), title, message); - if (!answer) - return; - } - NewXMLWizard.showDialog(workbenchWindow.getShell(), file, structuredSelection); - } - } - } - - /** - * unused - */ - public void selectionChanged(IAction action, ISelection selection) - { - } - - // 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 654f6d6f3f..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/XMLSchemaValidationChecker.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies 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.xml.uriresolver.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 55e002146b..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/XMLWizard.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies 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 java.util.MissingResourceException; -import java.util.ResourceBundle; - -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.resource.ImageDescriptor; - -public class XMLWizard -{ - private ResourceBundle wizardResourceBundle; - protected static XMLWizard instance = new XMLWizard(); - - public synchronized static XMLWizard getInstance() { - return instance; - } - - public XMLWizard() - { - instance = this; - try { - wizardResourceBundle = ResourceBundle.getBundle("wizardResource"); //$NON-NLS-1$ - } - catch (java.util.MissingResourceException exception) { - wizardResourceBundle = null; - } - } - - public ResourceBundle getWizardResourceBundle() - { - return wizardResourceBundle; - } - - public static String getString(String key) - { - try { - ResourceBundle bundle = getInstance().getWizardResourceBundle(); - return bundle.getString(key); - } - catch (MissingResourceException e) { - return key; - } - } - - public ImageDescriptor getImageDescriptor(String name) - { - try { - URL url= new URL(Platform.getBundle("org.eclipse.wst.xml.ui").getEntry("/"), name); - 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/icons/generatexml_wiz.gif b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/icons/generatexml_wiz.gif Binary files differdeleted file mode 100644 index 2e4f667655..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/icons/generatexml_wiz.gif +++ /dev/null diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/wizardResource.properties b/bundles/org.eclipse.wst.xml.ui/src-wizards/wizardResource.properties deleted file mode 100644 index b1cdb33a11..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/wizardResource.properties +++ /dev/null @@ -1,163 +0,0 @@ -############################################################################### -# Copyright (c) 2001, 2004 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -! Properties file for component: XML Tools - New XML Wizard -! Packaged for translation in: xml.zip - -! Plugin - -_UI_XML_PLUGIN_NAME = XML Builder -_UI_PREF_XML_CATALOG = XML Catalog - -!XMLImportActionDelegate -_UI_DIALOG_NEW_TITLE = New -_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_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 &scratch -_UI_WIZARD_CREATE_XML_HEADING = Create XML File -_UI_WIZARD_CREATE_XML_EXPL = Select how you would like to create your XML file. -_UI_WIZARD_CREATE_XML_FILE_HEADING = XML File Name -_UI_WIZARD_CREATE_XML_FILE_EXPL = Specify a name for the 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_LABEL_DTD_FILENAME = DTD file name -_UI_WIZARD_SELECT_ROOT_HEADING = Select Root Element -_UI_WIZARD_SELECT_ROOT_EXPL = Select the root element of the XML file. -_UI_WIZARD_SELECT_SCHEMA_HEADING = Select Schema File -_UI_WIZARD_SELECT_SCHEMA_EXPL = Select the schema file you want to create the XML file from. -_UI_LABEL_SCHEMA_FILENAME = Schema file name: -_UI_LABEL_ROOT_ELEMENT_GROUP = &Root Element -_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_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_URI = URI -_UI_LABEL_URI_COLON = &URI: -_UI_LABEL_DETAILS_URI_COLON = URI: -_UI_KEY_TYPE_COLON = Key &Type: -_UI_KEY_TYPE_DETAILS_COLON = Key Type: -_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_LABEL_SPECIFY_ALTERNATIVE_WEB_URL = Specify &alternative Web address -_UI_WARNING_URI_MUST_NOT_HAVE_DOTS = URI must not included '.' or '..' - -_UI_WARNING_URI_NOT_FOUND_COLON = The specified resource cannot be located : -_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. - - -!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 = &New... -_UI_BUTTON_EDIT = &Edit... -_UI_BUTTON_DELETE = &Delete -_UI_LABEL_NEW_DIALOG_TITLE = New 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 - -!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 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. - -!NewModelWizard -_ERROR_NO_FILENAME = Enter a file name. -_ERROR_FILE_DOESNT_EXIST = File does not exist. -_ERROR_INVALID_FILENAME = Invalid file name. -_ERROR_BAD_FILENAME_EXTENSION = The specified file name must have a recognized extension (e.g. '.xml'). -_ERROR_FILE_ALREADY_EXISTS = The same file already exists. -_ERROR_ROOT_ELEMENT_MUST_BE_SPECIFIED = A root element must be specified. -_ERROR_XML_REQUIRES_NS_PREFIX = The schema instance requires a namespace prefix. -_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. -_ERROR_DOCUMENT_GENERATION_FAILURE = Document generation failed. -_UI_LABEL_ERROR_FILE_HAS_ERRORS = contains errors - -!diagnostic strings -! NOTE TO TRANSLATOR: Do not translate following line -DIAGNOSTIC_SHOW_DEBUG_TREE = NO - -_UI_MENU_GENERATE_XML_FROM_XSD = Generate XML ... diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/DOMObserver.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/DOMObserver.java deleted file mode 100644 index e94585515d..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/DOMObserver.java +++ /dev/null @@ -1,190 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.Timer; -import java.util.TimerTask; - -import org.eclipse.wst.common.contentmodel.modelquery.CMDocumentManager; -import org.eclipse.wst.common.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.common.contentmodel.modelqueryimpl.CMDocumentLoader; -import org.eclipse.wst.common.contentmodel.modelqueryimpl.InferredGrammarBuildingCMDocumentLoader; -import org.eclipse.wst.sse.core.INodeAdapter; -import org.eclipse.wst.sse.core.INodeNotifier; -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.xml.core.document.XMLModel; -import org.eclipse.wst.xml.core.modelquery.ModelQueryUtil; -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(Document document) { - ((INodeNotifier) document).addAdapter(this); - adapt(document.getDocumentElement()); - } - - 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 { - MyDocumentAdapter(Document document) { - super(document); - } - - 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) { - Element element = (Element) node; - switch (eventType) { - case INodeNotifier.CHANGE : { - invokeDelayedCMDocumentLoad(); - break; - } - 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; - } - } - } - } - - // - // - protected class MyTimerTask extends TimerTask { - public MyTimerTask() { - super(); - timerTaskCount++; - } - - public void run() { - timerTaskCount--; - if (timerTaskCount == 0) { - invokeCMDocumentLoad(); - } - } - } - - protected static Timer timer = new Timer(true); - protected Document document; - protected boolean isGrammarInferenceEnabled; - protected IStructuredModel model; - protected int timerTaskCount = 0; - - public DOMObserver(IStructuredModel model) { - this.document = (model instanceof XMLModel) ? ((XMLModel) model).getDocument() : null; - - if (document != null) { - ModelQuery modelQuery = ModelQueryUtil.getModelQuery(document); - if (modelQuery != null && modelQuery.getCMDocumentManager() != null) { - CMDocumentManager cmDocumentManager = modelQuery.getCMDocumentManager(); - cmDocumentManager.setPropertyEnabled(CMDocumentManager.PROPERTY_AUTO_LOAD, false); - } - - MyDocumentAdapter myDocumentAdapter = new MyDocumentAdapter(document); - } - } - - 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 - // - //invokeCMDocumentLoad(); - invokeDelayedCMDocumentLoad(); - } - - public void invokeCMDocumentLoad() { - ModelQuery modelQuery = ModelQueryUtil.getModelQuery(document); - if (modelQuery != null && modelQuery.getCMDocumentManager() != null) { - CMDocumentLoader loader = isGrammarInferenceEnabled ? new InferredGrammarBuildingCMDocumentLoader(document, modelQuery) : new CMDocumentLoader(document, modelQuery); - loader.loadCMDocuments(); - } - } - - public void invokeDelayedCMDocumentLoad() { - //Display.getCurrent().timerExec(2000, new MyTimerTask()); - timer.schedule(new MyTimerTask(), 2000); - } - - public void setGrammarInferenceEnabled(boolean isEnabled) { - isGrammarInferenceEnabled = isEnabled; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/JobStatusLineHelper.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/JobStatusLineHelper.java deleted file mode 100644 index b0803039ad..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/JobStatusLineHelper.java +++ /dev/null @@ -1,103 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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 org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.jobs.IJobChangeEvent; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.core.runtime.jobs.JobChangeAdapter; -import org.eclipse.jface.action.IStatusLineManager; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.common.contentmodel.modelquery.CMDocumentManager; - - -/** - * Updates the status line when an appropriate Job is about to be run. - */ -public class JobStatusLineHelper extends JobChangeAdapter { - private static JobStatusLineHelper instance; - - public static void init() { - if (instance == null) { - instance = new JobStatusLineHelper(); - } - } - - private int running = 0; - - private JobStatusLineHelper() { - Platform.getJobManager().addJobChangeListener(this); - } - - public void aboutToRun(IJobChangeEvent event) { - Job job = event.getJob(); - if (job.belongsTo(CMDocumentManager.class)) { - running++; - setStatusLine(event.getJob().getName()); - } - } - - public void done(IJobChangeEvent event) { - Job job = event.getJob(); - if (job.belongsTo(CMDocumentManager.class)) { - running--; - if (running == 0) { - setStatusLine(""); //$NON-NLS-1$ - } - } - } - - private Display getDisplay() { - return PlatformUI.getWorkbench().getDisplay(); - } - - private void setStatusLine(final String message) { - String msgString = message; - if (message == null) { - msgString = ""; //$NON-NLS-1$ - } - final String finalMessageForThread = msgString; - if (getDisplay() != null) { - Runnable runnable = new Runnable() { - public void run() { - IWorkbench workbench = PlatformUI.getWorkbench(); - if (workbench != null) { - IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow(); - if (workbenchWindow != null) { - IEditorPart part = workbenchWindow.getActivePage().getActiveEditor(); - // part is sometimes null by the time this runs - // ... must be better way to get actionBars - // and/or statLineManager? - if (part != null) { - IActionBars actionBars = part.getEditorSite().getActionBars(); - if (actionBars != null) { - IStatusLineManager statusLineManager = actionBars.getStatusLineManager(); - if (statusLineManager != null) { - statusLineManager.setMessage(finalMessageForThread); - } - } - } - } - } - } - }; - Display workbenchDefault = PlatformUI.getWorkbench().getDisplay(); - workbenchDefault.asyncExec(runnable); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/Logger.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/Logger.java deleted file mode 100644 index df38bba078..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/Logger.java +++ /dev/null @@ -1,20 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies 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; - -/** - * @deprecated moved to internal package because only this plugin should be - * using this Logger class. - */ -public class Logger extends org.eclipse.wst.xml.ui.internal.Logger { - // see org.eclipse.wst.xml.ui.internal.Logger -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/StructuredTextEditorXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/StructuredTextEditorXML.java deleted file mode 100644 index 1cf8a6048d..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/StructuredTextEditorXML.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.ResourceBundle; - -import org.eclipse.jface.action.Action; -import org.eclipse.wst.sse.ui.StructuredTextEditor; -import org.eclipse.wst.sse.ui.edit.util.ActionDefinitionIds; -import org.eclipse.wst.sse.ui.edit.util.StructuredTextEditorActionConstants; -import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; -import org.eclipse.wst.sse.ui.internal.search.FindOccurrencesActionProvider; -import org.eclipse.wst.xml.ui.actions.AddBlockCommentActionXML; -import org.eclipse.wst.xml.ui.actions.CleanupActionXML; -import org.eclipse.wst.xml.ui.actions.RemoveBlockCommentActionXML; -import org.eclipse.wst.xml.ui.actions.ToggleCommentActionXML; -import org.eclipse.wst.xml.ui.internal.editor.IHelpContextIds; -import org.eclipse.wst.xml.ui.internal.search.XMLFindOccurrencesAction; - -public class StructuredTextEditorXML extends StructuredTextEditor { - protected void createActions() { - super.createActions(); - - ResourceBundle resourceBundle = SSEUIPlugin.getDefault().getResourceBundle(); - - Action action = new CleanupActionXML(resourceBundle, StructuredTextEditorActionConstants.ACTION_NAME_CLEANUP_DOCUMENT + DOT, this); - action.setActionDefinitionId(ActionDefinitionIds.CLEANUP_DOCUMENT); - setAction(StructuredTextEditorActionConstants.ACTION_NAME_CLEANUP_DOCUMENT, action); - - /* - * action = new CommentActionXML(resourceBundle, - * StructuredTextEditorActionConstants.ACTION_NAME_COMMENT + DOT, - * this); action.setActionDefinitionId(ActionDefinitionIds.COMMENT); - * setAction(StructuredTextEditorActionConstants.ACTION_NAME_COMMENT, - * action); - * - * action = new UncommentActionXML(resourceBundle, - * StructuredTextEditorActionConstants.ACTION_NAME_UNCOMMENT + DOT, - * this); action.setActionDefinitionId(ActionDefinitionIds.UNCOMMENT); - * setAction(StructuredTextEditorActionConstants.ACTION_NAME_UNCOMMENT, - * action); - */ - - action = new ToggleCommentActionXML(resourceBundle, StructuredTextEditorActionConstants.ACTION_NAME_TOGGLE_COMMENT + DOT, this); - action.setActionDefinitionId(ActionDefinitionIds.TOGGLE_COMMENT); - setAction(StructuredTextEditorActionConstants.ACTION_NAME_TOGGLE_COMMENT, action); - - action = new AddBlockCommentActionXML(resourceBundle, StructuredTextEditorActionConstants.ACTION_NAME_ADD_BLOCK_COMMENT + DOT, this); - action.setActionDefinitionId(ActionDefinitionIds.ADD_BLOCK_COMMENT); - setAction(StructuredTextEditorActionConstants.ACTION_NAME_ADD_BLOCK_COMMENT, action); - - action = new RemoveBlockCommentActionXML(resourceBundle, StructuredTextEditorActionConstants.ACTION_NAME_REMOVE_BLOCK_COMMENT + DOT, this); - action.setActionDefinitionId(ActionDefinitionIds.REMOVE_BLOCK_COMMENT); - setAction(StructuredTextEditorActionConstants.ACTION_NAME_REMOVE_BLOCK_COMMENT, action); - - FindOccurrencesActionProvider foAction = new FindOccurrencesActionProvider(resourceBundle, StructuredTextEditorActionConstants.ACTION_NAME_FIND_OCCURRENCES + DOT, this); - foAction.addAction(new XMLFindOccurrencesAction(resourceBundle, "", this)); //$NON-NLS-1$ - foAction.setActionDefinitionId(ActionDefinitionIds.FIND_OCCURRENCES); - setAction(StructuredTextEditorActionConstants.ACTION_NAME_FIND_OCCURRENCES, foAction); - markAsSelectionDependentAction(StructuredTextEditorActionConstants.ACTION_NAME_FIND_OCCURRENCES, true); - } - - protected void initializeEditor() { - super.initializeEditor(); - setHelpContextId(IHelpContextIds.XML_SOURCEVIEW_HELPID); - } -} 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 d86870db3e..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/StructuredTextViewerConfigurationXML.java +++ /dev/null @@ -1,290 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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 org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.text.ITextDoubleClickStrategy; -import org.eclipse.jface.text.ITextHover; -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.formatter.IContentFormatter; -import org.eclipse.jface.text.formatter.MultiPassContentFormatter; -import org.eclipse.jface.text.information.IInformationPresenter; -import org.eclipse.jface.text.information.IInformationProvider; -import org.eclipse.jface.text.information.InformationPresenter; -import org.eclipse.jface.text.reconciler.IReconciler; -import org.eclipse.jface.text.reconciler.IReconcilingStrategy; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.wst.dtd.ui.style.LineStyleProviderForDTDSubSet; -import org.eclipse.wst.sse.core.IModelManager; -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.text.rules.StructuredTextPartitioner; -import org.eclipse.wst.sse.ui.StructuredTextReconciler; -import org.eclipse.wst.sse.ui.StructuredTextViewer; -import org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration; -import org.eclipse.wst.sse.ui.format.StructuredFormattingStrategy; -import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; -import org.eclipse.wst.sse.ui.preferences.CommonEditorPreferenceNames; -import org.eclipse.wst.sse.ui.preferences.PreferenceKeyGenerator; -import org.eclipse.wst.sse.ui.style.IHighlighter; -import org.eclipse.wst.sse.ui.style.LineStyleProvider; -import org.eclipse.wst.sse.ui.taginfo.AnnotationHoverProcessor; -import org.eclipse.wst.sse.ui.taginfo.ProblemAnnotationHoverProcessor; -import org.eclipse.wst.sse.ui.taginfo.TextHoverManager; -import org.eclipse.wst.sse.ui.util.EditorUtility; -import org.eclipse.wst.xml.core.format.FormatProcessorXML; -import org.eclipse.wst.xml.core.text.rules.StructuredTextPartitionerForXML; -import org.eclipse.wst.xml.ui.contentassist.NoRegionContentAssistProcessor; -import org.eclipse.wst.xml.ui.contentassist.XMLContentAssistProcessor; -import org.eclipse.wst.xml.ui.doubleclick.XMLDoubleClickStrategy; -import org.eclipse.wst.xml.ui.internal.autoedit.StructuredAutoEditStrategyXML; -import org.eclipse.wst.xml.ui.internal.correction.CorrectionProcessorXML; -import org.eclipse.wst.xml.ui.reconcile.StructuredTextReconcilingStrategyForContentModel; -import org.eclipse.wst.xml.ui.reconcile.StructuredTextReconcilingStrategyForMarkup; -import org.eclipse.wst.xml.ui.style.LineStyleProviderForXML; -import org.eclipse.wst.xml.ui.taginfo.XMLBestMatchHoverProcessor; -import org.eclipse.wst.xml.ui.taginfo.XMLInformationProvider; -import org.eclipse.wst.xml.ui.taginfo.XMLTagInfoHoverProcessor; - -public class StructuredTextViewerConfigurationXML extends StructuredTextViewerConfiguration { - InformationPresenter fInformationPresenter = null; - private boolean reconcilerStrategiesAreSet; - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration#getAutoEditStrategies(org.eclipse.jface.text.source.ISourceViewer) - */ - public Map getAutoEditStrategies(ISourceViewer sourceViewer) { - Map result = super.getAutoEditStrategies(sourceViewer); - - if (result.get(StructuredTextPartitionerForXML.ST_DEFAULT_XML) == null) - result.put(StructuredTextPartitionerForXML.ST_DEFAULT_XML, new ArrayList(1)); - List strategies = (List) result.get(StructuredTextPartitionerForXML.ST_DEFAULT_XML); - strategies.add(new StructuredAutoEditStrategyXML()); - return result; - } - - public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { - - if (configuredContentTypes == null) { - String[] xmlTypes = StructuredTextPartitionerForXML.getConfiguredContentTypes(); - configuredContentTypes = new String[xmlTypes.length + 2]; - configuredContentTypes[0] = StructuredTextPartitioner.ST_DEFAULT_PARTITION; - configuredContentTypes[1] = StructuredTextPartitioner.ST_UNKNOWN_PARTITION; - int index = 0; - System.arraycopy(xmlTypes, 0, configuredContentTypes, index += 2, xmlTypes.length); - } - return configuredContentTypes; - } - - public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) { - - IContentAssistant ca = super.getContentAssistant(sourceViewer); - if (ca != null && ca instanceof ContentAssistant) { - ContentAssistant contentAssistant = (ContentAssistant) ca; - IContentAssistProcessor xmlContentAssistProcessor = new XMLContentAssistProcessor(); - IContentAssistProcessor noRegionProcessor = new NoRegionContentAssistProcessor(); - addContentAssistProcessor(contentAssistant, xmlContentAssistProcessor, StructuredTextPartitioner.ST_DEFAULT_PARTITION); - addContentAssistProcessor(contentAssistant, xmlContentAssistProcessor, StructuredTextPartitionerForXML.ST_DEFAULT_XML); - addContentAssistProcessor(contentAssistant, noRegionProcessor, StructuredTextPartitioner.ST_UNKNOWN_PARTITION); - //contentAssistant.setContentAssistProcessor(xmlContentAssistProcessor, - // StructuredTextPartitioner.ST_DEFAULT_PARTITION); - //contentAssistant.setContentAssistProcessor(xmlContentAssistProcessor, - // StructuredTextPartitionerForXML.ST_DEFAULT_XML); - //contentAssistant.setContentAssistProcessor(noRegionProcessor, - // StructuredTextPartitioner.ST_UNKNOWN_PARTITION); - } - return ca; - } - - public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) { - final MultiPassContentFormatter formatter = new MultiPassContentFormatter(getConfiguredDocumentPartitioning(sourceViewer), StructuredTextPartitionerForXML.ST_DEFAULT_XML); - - formatter.setMasterStrategy(new StructuredFormattingStrategy(new FormatProcessorXML())); - - return formatter; - } - - public IContentAssistant getCorrectionAssistant(ISourceViewer sourceViewer) { - IContentAssistant ca = super.getCorrectionAssistant(sourceViewer); - - if (ca != null && ca instanceof ContentAssistant) { - ContentAssistant correctionAssistant = (ContentAssistant) ca; - ITextEditor editor = getTextEditor(); - if (editor != null) { - IContentAssistProcessor correctionProcessor = new CorrectionProcessorXML(editor); - correctionAssistant.setContentAssistProcessor(correctionProcessor, StructuredTextPartitionerForXML.ST_DEFAULT_XML); - correctionAssistant.setContentAssistProcessor(correctionProcessor, StructuredTextPartitionerForXML.ST_XML_CDATA); - correctionAssistant.setContentAssistProcessor(correctionProcessor, StructuredTextPartitionerForXML.ST_XML_COMMENT); - correctionAssistant.setContentAssistProcessor(correctionProcessor, StructuredTextPartitionerForXML.ST_XML_DECLARATION); - correctionAssistant.setContentAssistProcessor(correctionProcessor, StructuredTextPartitionerForXML.ST_XML_PI); - correctionAssistant.setContentAssistProcessor(correctionProcessor, StructuredTextPartitionerForXML.ST_DTD_SUBSET); - } - } - return ca; - } - - public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) { - - if (contentType.compareTo(StructuredTextPartitionerForXML.ST_DEFAULT_XML) == 0) - return new XMLDoubleClickStrategy(); - else - return super.getDoubleClickStrategy(sourceViewer, contentType); - } - - public IHighlighter getHighlighter(ISourceViewer sourceViewer) { - - IHighlighter highlighter = super.getHighlighter(sourceViewer); - if (highlighter != null) { - LineStyleProvider xmlProvider = new LineStyleProviderForXML(); - highlighter.addProvider(StructuredTextPartitionerForXML.ST_DEFAULT_XML, xmlProvider); - highlighter.addProvider(StructuredTextPartitionerForXML.ST_XML_CDATA, xmlProvider); - highlighter.addProvider(StructuredTextPartitionerForXML.ST_XML_COMMENT, xmlProvider); - highlighter.addProvider(StructuredTextPartitionerForXML.ST_XML_DECLARATION, xmlProvider); - highlighter.addProvider(StructuredTextPartitionerForXML.ST_XML_PI, xmlProvider); - highlighter.addProvider(StructuredTextPartitionerForXML.ST_DTD_SUBSET, new LineStyleProviderForDTDSubSet()); - } - return highlighter; - } - - public IInformationPresenter getInformationPresenter(ISourceViewer sourceViewer) { - - if (fInformationPresenter == null) { - fInformationPresenter = new InformationPresenter(getInformationPresenterControlCreator(sourceViewer)); - IInformationProvider xmlInformationProvider = new XMLInformationProvider(); - fInformationPresenter.setInformationProvider(xmlInformationProvider, StructuredTextPartitioner.ST_DEFAULT_PARTITION); - fInformationPresenter.setInformationProvider(xmlInformationProvider, StructuredTextPartitionerForXML.ST_DEFAULT_XML); - fInformationPresenter.setSizeConstraints(60, 10, true, true); - } - return fInformationPresenter; - } - - private IModelManager getModelManager() { - return StructuredModelManager.getInstance().getModelManager(); - } - - public IReconciler getReconciler(ISourceViewer sourceViewer) { - - if (fReconciler != null) { - // a reconciler should always be installed or disposed of - if (!fReconciler.isInstalled()) { - fReconciler = null; - reconcilerStrategiesAreSet = false; - } - } - - // the first time running through, there's no model (so no pref store) - // but the reconciler still needs to be created so that its document - // gets set - if (fReconciler == null) { - // create one - fReconciler = new StructuredTextReconciler(); - // a null editorPart is valid - //fReconciler.setEditor(editorPart); - } - - IPreferenceStore store = SSEUIPlugin.getDefault().getPreferenceStore(); - boolean reconcilingEnabled = store.getBoolean(CommonEditorPreferenceNames.EVALUATE_TEMPORARY_PROBLEMS); - - // the second time through, the strategies are set - if (fReconciler != null && !reconcilerStrategiesAreSet && reconcilingEnabled) { - StructuredTextViewer viewer = null; - if (sourceViewer instanceof StructuredTextViewer) { - viewer = ((StructuredTextViewer) sourceViewer); - } - IStructuredModel sModel = getModelManager().getExistingModelForRead(viewer.getDocument()); - try { - - - if (sModel != null) { - // check language (ContentTypeID).... - String contentTypeId = sModel.getModelHandler().getAssociatedContentTypeId(); - String generatedKey = PreferenceKeyGenerator.generateKey(CommonEditorPreferenceNames.EDITOR_VALIDATION_METHOD, contentTypeId); - String validationMethodPref = SSEUIPlugin.getInstance().getPreferenceStore().getString(generatedKey); - IReconcilingStrategy defaultStrategy = null; - - // pref set to no validation, so return - if (validationMethodPref.equals(CommonEditorPreferenceNames.EDITOR_VALIDATION_NONE)) - return fReconciler; - - // content model is the default for xml.. - // "Content Model" strategies (requires propagating - // adapter - // from AdapterFactoryProviderFor*) - - IReconcilingStrategy markupStrategy = new StructuredTextReconcilingStrategyForMarkup((ITextEditor) editorPart); - IReconcilingStrategy xmlStrategy = new StructuredTextReconcilingStrategyForContentModel((ITextEditor) editorPart); - defaultStrategy = xmlStrategy; - fReconciler.setReconcilingStrategy(markupStrategy, StructuredTextPartitioner.ST_DEFAULT_PARTITION); - fReconciler.setReconcilingStrategy(xmlStrategy, StructuredTextPartitionerForXML.ST_DEFAULT_XML); - fReconciler.setDefaultStrategy(defaultStrategy); - - reconcilerStrategiesAreSet = true; - } - } finally { - if (sModel != null) - sModel.releaseFromRead(); - } - } - return fReconciler; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getTextHover(org.eclipse.jface.text.source.ISourceViewer, - * java.lang.String, int) - */ - public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType, int stateMask) { - // look for appropriate text hover processor to return based on - // content type and state mask - if ((contentType == StructuredTextPartitioner.ST_DEFAULT_PARTITION) || (contentType == StructuredTextPartitionerForXML.ST_DEFAULT_XML)) { - // check which of xml's text hover is handling stateMask - TextHoverManager.TextHoverDescriptor[] hoverDescs = getTextHovers(); - int i = 0; - while (i < hoverDescs.length) { - if (hoverDescs[i].isEnabled() && EditorUtility.computeStateMask(hoverDescs[i].getModifierString()) == stateMask) { - String hoverType = hoverDescs[i].getId(); - if (TextHoverManager.COMBINATION_HOVER.equalsIgnoreCase(hoverType)) - return new XMLBestMatchHoverProcessor(); - else if (TextHoverManager.PROBLEM_HOVER.equalsIgnoreCase(hoverType)) - return new ProblemAnnotationHoverProcessor(); - else if (TextHoverManager.ANNOTATION_HOVER.equalsIgnoreCase(hoverType)) - return new AnnotationHoverProcessor(); - else if (TextHoverManager.DOCUMENTATION_HOVER.equalsIgnoreCase(hoverType)) - return new XMLTagInfoHoverProcessor(); - } - i++; - } - } - return super.getTextHover(sourceViewer, contentType, stateMask); - } - - public void unConfigure(ISourceViewer viewer) { - - super.unConfigure(viewer); - - // InformationPresenters - if (fInformationPresenter != null) { - fInformationPresenter.uninstall(); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/XMLEditorPlugin.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/XMLEditorPlugin.java deleted file mode 100644 index 155f50f57d..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/XMLEditorPlugin.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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 org.eclipse.wst.xml.ui.internal.XMLUIPlugin; - - -/** - * @deprecated use XMLUIPlugin instead - */ -public class XMLEditorPlugin extends XMLUIPlugin { - // just extending XMLUIPlugin to keep everything compatible -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/XMLSpellCheckTarget.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/XMLSpellCheckTarget.java deleted file mode 100644 index ce40145de8..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/XMLSpellCheckTarget.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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 org.eclipse.wst.sse.ui.SpellCheckTargetImpl; -import org.eclipse.wst.xml.core.parser.XMLRegionContext; - - -public class XMLSpellCheckTarget extends SpellCheckTargetImpl { - - public XMLSpellCheckTarget() { - super(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.SpellCheckTargetImpl#isValidType(java.lang.String) - */ - protected boolean isValidType(String type) { - boolean valid = false; - if (XMLRegionContext.XML_COMMENT_TEXT.equals(type) || XMLRegionContext.XML_CONTENT.equals(type)) { - valid = true; - } - return valid || super.isValidType(type); - } - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/AbstractNodeActionManager.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/AbstractNodeActionManager.java deleted file mode 100644 index d1f023f126..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/AbstractNodeActionManager.java +++ /dev/null @@ -1,653 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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.common.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.common.contentmodel.CMDataType; -import org.eclipse.wst.common.contentmodel.CMElementDeclaration; -import org.eclipse.wst.common.contentmodel.CMNode; -import org.eclipse.wst.common.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.common.contentmodel.util.CMDescriptionBuilder; -import org.eclipse.wst.common.contentmodel.util.DOMContentBuilder; -import org.eclipse.wst.common.contentmodel.util.DOMContentBuilderImpl; -import org.eclipse.wst.common.contentmodel.util.DOMNamespaceHelper; -import org.eclipse.wst.sse.core.IStructuredModel; -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; -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 = XMLUIPlugin.getResourceString("%_UI_MENU_ADD") + " " + text; //$NON-NLS-1$ //$NON-NLS-2$ - setImageDescriptor(imageDescriptorCache.getImageDescriptor(cmnode)); - } - - - public AddNodeAction(int nodeType, Node parent, int index) { - this.nodeType = nodeType; - this.index = index; - this.parent = parent; - - switch (nodeType) { - case Node.COMMENT_NODE : { - description = XMLUIPlugin.getResourceString("%_UI_MENU_COMMENT"); //$NON-NLS-1$ - undoDescription = XMLUIPlugin.getResourceString("%_UI_MENU_ADD_COMMENT"); //$NON-NLS-1$ - break; - } - case Node.PROCESSING_INSTRUCTION_NODE : { - description = XMLUIPlugin.getResourceString("%_UI_MENU_PROCESSING_INSTRUCTION"); //$NON-NLS-1$ - undoDescription = XMLUIPlugin.getResourceString("%_UI_MENU_ADD_PROCESSING_INSTRUCTION"); //$NON-NLS-1$ - break; - } - case Node.CDATA_SECTION_NODE : { - description = XMLUIPlugin.getResourceString("%_UI_MENU_CDATA_SECTION"); //$NON-NLS-1$ - undoDescription = XMLUIPlugin.getResourceString("%_UI_MENU_ADD_CDATA_SECTION"); //$NON-NLS-1$ - break; - } - case Node.TEXT_NODE : { - description = XMLUIPlugin.getResourceString("%_UI_MENU_PCDATA"); //$NON-NLS-1$ - undoDescription = XMLUIPlugin.getResourceString("%_UI_MENU_ADD_PCDATA"); //$NON-NLS-1$ - 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(XMLUIPlugin.getResourceString("%_UI_COMMENT_VALUE")); //$NON-NLS-1$ - break; - } - case Node.PROCESSING_INSTRUCTION_NODE : { - newChildNode = document.createProcessingInstruction(XMLUIPlugin.getResourceString("%_UI_PI_TARGET_VALUE"), XMLUIPlugin.getResourceString("%_UI_PI_DATA_VALUE")); //$NON-NLS-1$ //$NON-NLS-2$ - 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(XMLUIPlugin.getResourceString("%_UI_MENU_REMOVE")); //$NON-NLS-1$ - this.list = list; - } - - public DeleteAction(Node node) { - setText(XMLUIPlugin.getResourceString("%_UI_MENU_REMOVE")); //$NON-NLS-1$ - list = new Vector(); - list.add(node); - } - - public String getUndoDescription() { - return XMLUIPlugin.getResourceString("%DELETE"); //$NON-NLS-1$ - } - - 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 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 = attributeImage; - break; - } - case CMNode.DATA_TYPE : { - result = textImage; - break; - } - case CMNode.ELEMENT_DECLARATION : { - 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 = XMLUIPlugin.getResourceString("%_UI_MENU_COMMENT"); //$NON-NLS-1$ - break; - } - case Node.PROCESSING_INSTRUCTION_NODE : { - description = XMLUIPlugin.getResourceString("%_UI_MENU_PROCESSING_INSTRUCTION"); //$NON-NLS-1$ - break; - } - case Node.CDATA_SECTION_NODE : { - description = XMLUIPlugin.getResourceString("%_UI_MENU_CDATA_SECTION"); //$NON-NLS-1$ - break; - } - case Node.TEXT_NODE : { - description = XMLUIPlugin.getResourceString("%_UI_MENU_PCDATA"); //$NON-NLS-1$ - 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 XMLUIPlugin.getResourceString("%_UI_MENU_ADD") + " " + description; //$NON-NLS-1$ //$NON-NLS-2$ - } - - 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(XMLUIPlugin.getResourceString("%_UI_COMMENT_VALUE")); //$NON-NLS-1$ - break; - } - case Node.PROCESSING_INSTRUCTION_NODE : { - newChildNode = document.createProcessingInstruction(XMLUIPlugin.getResourceString("%_UI_PI_TARGET_VALUE"), XMLUIPlugin.getResourceString("%_UI_PI_DATA_VALUE")); //$NON-NLS-1$ //$NON-NLS-2$ - 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 = XMLUIPlugin.getResourceString("%_UI_LABEL_UNDO_REPLACE_DESCRIPTION"); //$NON-NLS-1$ - 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 viewer; - - public AbstractNodeActionManager(IStructuredModel model, ModelQuery modelQuery, Viewer viewer) { - super(model, modelQuery); - this.viewer = viewer; - } - - - public void beginNodeAction(NodeAction action) { - model.beginRecording(action, action.getUndoDescription()); - } - - - protected Action createAddAttributeAction(Element parent, CMAttributeDeclaration ad) { - Action action = null; - if (ad == null) { - action = new EditAttributeAction(this, parent, null, XMLUIPlugin.getResourceString("%_UI_MENU_NEW_ATTRIBUTE"), XMLUIPlugin.getResourceString("%_UI_MENU_NEW_ATTRIBUTE_TITLE")); //$NON-NLS-1$ //$NON-NLS-2$ - } 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(model, document, model.getBaseLocation(), XMLUIPlugin.getResourceString("%_UI_MENU_ADD_DTD_INFORMATION")); //$NON-NLS-1$ - } - - - protected Action createAddElementAction(Node parent, CMElementDeclaration ed, int index) { - Action action = null; - if (ed == null) { - action = new EditElementAction(this, parent, index, XMLUIPlugin.getResourceString("%_UI_MENU_NEW_ELEMENT"), XMLUIPlugin.getResourceString("%_UI_MENU_NEW_ELEMENT_TITLE")); //$NON-NLS-1$ //$NON-NLS-2$ - } 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, XMLUIPlugin.getResourceString("%_UI_MENU_ADD_PROCESSING_INSTRUCTION"), XMLUIPlugin.getResourceString("%ADD_PROCESSING_INSTRUCTION")); //$NON-NLS-1$ //$NON-NLS-2$ - action.setImageDescriptor(imageDescriptorCache.getImageDescriptor(new Integer(Node.PROCESSING_INSTRUCTION_NODE))); - return action; - } - - - protected Action createAddSchemaInfoAction(Element element) { - return new EditSchemaInfoAction(this, element.getOwnerDocument(), model.getBaseLocation(), XMLUIPlugin.getResourceString("%_UI_MENU_ADD_SCHEMA_INFORMATION")); //$NON-NLS-1$ - } - - - 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, XMLUIPlugin.getResourceString("%_UI_MENU_EDIT_ATTRIBUTE"), XMLUIPlugin.getResourceString("%_UI_MENU_EDIT_ATTRIBUTE_TITLE")); //$NON-NLS-1$ //$NON-NLS-2$ - } - - - protected Action createEditDoctypeAction(DocumentType doctype) { - return new EditDoctypeAction(model, doctype, model.getBaseLocation(), XMLUIPlugin.getResourceString("%_UI_MENU_EDIT_DOCTYPE")); //$NON-NLS-1$ - } - - - protected Action createEditProcessingInstructionAction(ProcessingInstruction pi) { - return new EditProcessingInstructionAction(this, pi, XMLUIPlugin.getResourceString("%_UI_MENU_EDIT_PROCESSING_INSTRUCTION"), XMLUIPlugin.getResourceString("%_UI_MENU_EDIT_PROCESSING_INSTRUCTION_TITLE")); //$NON-NLS-1$ //$NON-NLS-2$ - } - - - protected Action createEditSchemaInfoAction(Element element) { - return new EditSchemaInfoAction(this, element.getOwnerDocument(), model.getBaseLocation(), XMLUIPlugin.getResourceString("%_UI_MENU_EDIT_NAMESPACES")); //$NON-NLS-1$ - } - - - protected Action createRenameAction(Node node) { - Action result = null; - if (node instanceof Element) { - result = new EditElementAction(this, (Element) node, XMLUIPlugin.getResourceString("%_UI_MENU_RENAME"), XMLUIPlugin.getResourceString("%_UI_MENU_RENAME_TITLE")); //$NON-NLS-1$ //$NON-NLS-2$ - } - 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) { - model.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) { - result = (String) cmnode.getProperty("description"); //$NON-NLS-1$ - if (result == null) { - 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 model; - } - - - 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 (viewer != null) { - viewer.setSelection(new StructuredSelection(list), true); - } - } - - - public void setViewerSelection(Node node) { - if (viewer != null) { - viewer.setSelection(new StructuredSelection(node), true); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/ActionContributorXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/ActionContributorXML.java deleted file mode 100644 index 34812cabfd..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/ActionContributorXML.java +++ /dev/null @@ -1,203 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.actions; - -import java.util.ResourceBundle; - -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.IStatusLineManager; -import org.eclipse.jface.action.MenuManager; -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.edit.util.ActionContributor; -import org.eclipse.wst.sse.ui.edit.util.ActionDefinitionIds; -import org.eclipse.wst.sse.ui.edit.util.StructuredTextEditorActionConstants; -import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; - -/** - * 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.wst.xml.ui.StructuredTextEditorXML", "org.eclipse.wst.sse.ui.StructuredTextEditor"}; //$NON-NLS-1$ //$NON-NLS-2$ - protected RetargetTextEditorAction fCleanupDocument = null; - protected RetargetTextEditorAction fComment = null; - // tooltip - // action - protected RetargetTextEditorAction fContentAssist = null; - // action - protected RetargetTextEditorAction fFindOccurrences = null; - protected RetargetTextEditorAction fFormatActiveElements = null; - protected RetargetTextEditorAction fFormatDocument = null; - protected MenuManager fFormatMenu = null; - protected RetargetTextEditorAction fOpenFileAction = null; // open file - protected RetargetTextEditorAction fQuickFix = null; - - protected RetargetTextEditorAction fShowTooltipAction = null; // show - protected RetargetTextEditorAction fUncomment = null; - - public ActionContributorXML() { - super(); - - ResourceBundle resourceBundle = SSEUIPlugin.getDefault().getResourceBundle(); - - // edit commands - fShowTooltipAction = new RetargetTextEditorAction(resourceBundle, StructuredTextEditorActionConstants.ACTION_NAME_INFORMATION + StructuredTextEditorActionConstants.DOT); - fShowTooltipAction.setActionDefinitionId(ActionDefinitionIds.INFORMATION); - - fContentAssist = new RetargetTextEditorAction(resourceBundle, StructuredTextEditorActionConstants.ACTION_NAME_CONTENTASSIST_PROPOSALS + StructuredTextEditorActionConstants.DOT); - fContentAssist.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); - - fQuickFix = new RetargetTextEditorAction(resourceBundle, StructuredTextEditorActionConstants.ACTION_NAME_QUICK_FIX + StructuredTextEditorActionConstants.DOT); - fQuickFix.setActionDefinitionId(ActionDefinitionIds.QUICK_FIX); - - // source commands - fCleanupDocument = new RetargetTextEditorAction(resourceBundle, StructuredTextEditorActionConstants.ACTION_NAME_CLEANUP_DOCUMENT + StructuredTextEditorActionConstants.DOT); - fCleanupDocument.setActionDefinitionId(ActionDefinitionIds.CLEANUP_DOCUMENT); - - fFormatDocument = new RetargetTextEditorAction(resourceBundle, StructuredTextEditorActionConstants.ACTION_NAME_FORMAT_DOCUMENT + StructuredTextEditorActionConstants.DOT); - fFormatDocument.setActionDefinitionId(ActionDefinitionIds.FORMAT_DOCUMENT); - - fFormatActiveElements = new RetargetTextEditorAction(resourceBundle, StructuredTextEditorActionConstants.ACTION_NAME_FORMAT_ACTIVE_ELEMENTS + StructuredTextEditorActionConstants.DOT); - fFormatActiveElements.setActionDefinitionId(ActionDefinitionIds.FORMAT_ACTIVE_ELEMENTS); - - fFormatMenu = new MenuManager(SSEUIPlugin.getResourceString("%FormatMenu.label")); //$NON-NLS-1$ - fFormatMenu.add(fFormatDocument); - fFormatMenu.add(fFormatActiveElements); - - // navigate commands - fOpenFileAction = new RetargetTextEditorAction(resourceBundle, StructuredTextEditorActionConstants.ACTION_NAME_OPEN_FILE + StructuredTextEditorActionConstants.DOT); - fOpenFileAction.setActionDefinitionId(ActionDefinitionIds.OPEN_FILE); - - fFindOccurrences = new RetargetTextEditorAction(resourceBundle, StructuredTextEditorActionConstants.ACTION_NAME_FIND_OCCURRENCES + StructuredTextEditorActionConstants.DOT); - fFindOccurrences.setActionDefinitionId(ActionDefinitionIds.FIND_OCCURRENCES); - } - - 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(fShowTooltipAction); - editMenu.add(fContentAssist); - editMenu.add(fQuickFix); - editMenu.add(fMenuAdditionsGroupMarker); - } - - // source commands - String sourceMenuLabel = SSEUIPlugin.getResourceString("%SourceMenu.label"); //$NON-NLS-1$ - String sourceMenuId = "sourceMenuId"; // This is just a menu id. No - // need to translate. - // //$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(fFormatMenu); - 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); - } - } - - /* - * (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); - - fShowTooltipAction.setAction(getAction(textEditor, StructuredTextEditorActionConstants.ACTION_NAME_INFORMATION)); - fContentAssist.setAction(getAction(textEditor, StructuredTextEditorActionConstants.ACTION_NAME_CONTENTASSIST_PROPOSALS)); - fQuickFix.setAction(getAction(textEditor, StructuredTextEditorActionConstants.ACTION_NAME_QUICK_FIX)); - - 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)); - - fOpenFileAction.setAction(getAction(textEditor, StructuredTextEditorActionConstants.ACTION_NAME_OPEN_FILE)); - - fFindOccurrences.setAction(getAction(textEditor, StructuredTextEditorActionConstants.ACTION_NAME_FIND_OCCURRENCES)); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.ISourceViewerActionBarContributor#setViewerSpecificContributionsEnabled(boolean) - */ - public void setViewerSpecificContributionsEnabled(boolean enabled) { - super.setViewerSpecificContributionsEnabled(enabled); - - fShowTooltipAction.setEnabled(enabled); - fContentAssist.setEnabled(enabled); - fQuickFix.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); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/AddBlockCommentActionXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/AddBlockCommentActionXML.java deleted file mode 100644 index d39d2a7a44..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/AddBlockCommentActionXML.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.actions; - -import java.util.ResourceBundle; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.wst.sse.core.IndexedRegion; -import org.eclipse.wst.sse.core.exceptions.SourceEditingRuntimeException; -import org.eclipse.wst.sse.ui.edit.util.StructuredTextEditorActionConstants; -import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; -import org.eclipse.wst.xml.core.internal.document.CommentImpl; - -public class AddBlockCommentActionXML extends CommentActionXML { - protected int fCloseCommentOffset; - protected int fOpenCommentOffset; - protected IndexedRegion fSelectionEndIndexedRegion; - protected IndexedRegion fSelectionStartIndexedRegion; - - public AddBlockCommentActionXML(ResourceBundle bundle, String prefix, ITextEditor editor) { - super(bundle, prefix, editor); - } - - protected void init() { - super.init(); - - fSelectionStartIndexedRegion = fModel.getIndexedRegion(fSelectionStartOffset); - fSelectionEndIndexedRegion = fModel.getIndexedRegion(fSelectionEndOffset); - - if (fSelectionStartIndexedRegion == null || fSelectionEndIndexedRegion == null) - return; - - fOpenCommentOffset = fSelectionStartIndexedRegion.getStartOffset(); - fCloseCommentOffset = fSelectionEndIndexedRegion.getEndOffset() + OPEN_COMMENT.length(); - } - - protected void processAction() { - if (fSelection.getLength() == 0 && fSelectionStartIndexedRegion instanceof CommentImpl) - return; - - fModel.beginRecording(this, SSEUIPlugin.getResourceString(StructuredTextEditorActionConstants.ACTION_NAME_ADD_BLOCK_COMMENT + ".tooltip")); //$NON-NLS-1$ - fModel.aboutToChangeModel(); - - try { - fDocument.replace(fOpenCommentOffset, 0, OPEN_COMMENT); - fDocument.replace(fCloseCommentOffset, 0, CLOSE_COMMENT); - removeOpenCloseComments(fOpenCommentOffset + OPEN_COMMENT.length(), fCloseCommentOffset - fOpenCommentOffset - CLOSE_COMMENT.length()); - } catch (BadLocationException e) { - throw new SourceEditingRuntimeException(); - } - - fModel.changedModel(); - fModel.endRecording(this); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/BaseNodeActionManager.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/BaseNodeActionManager.java deleted file mode 100644 index 38b50f17e4..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/BaseNodeActionManager.java +++ /dev/null @@ -1,514 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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.common.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.common.contentmodel.CMDataType; -import org.eclipse.wst.common.contentmodel.CMDocument; -import org.eclipse.wst.common.contentmodel.CMElementDeclaration; -import org.eclipse.wst.common.contentmodel.CMNode; -import org.eclipse.wst.common.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.common.contentmodel.modelquery.ModelQueryAction; -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.xml.core.document.XMLModel; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -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 model; - protected ModelQuery modelQuery; - - protected BaseNodeActionManager(IStructuredModel model, ModelQuery modelQuery) { - this.model = 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 = (editMode == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) ? ModelQuery.INCLUDE_CHILD_NODES | ModelQuery.INCLUDE_SEQUENCE_GROUPS : 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 = ((XMLModel) model).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(XMLUIPlugin.getResourceString("%_UI_MENU_ADD_ATTRIBUTE")); //$NON-NLS-1$ - IMenuManager addChildMenu = new MyMenuManager(XMLUIPlugin.getResourceString("%_UI_MENU_ADD_CHILD")); //$NON-NLS-1$ - 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(XMLUIPlugin.getResourceString("%_UI_MENU_ADD_CHILD")); //$NON-NLS-1$ - 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(XMLUIPlugin.getResourceString("%_UI_MENU_ADD_BEFORE")); //$NON-NLS-1$ - IMenuManager addAfterMenu = new MyMenuManager(XMLUIPlugin.getResourceString("%_UI_MENU_ADD_AFTER")); //$NON-NLS-1$ - 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(XMLUIPlugin.getResourceString("%_UI_MENU_REPLACE_WITH")); //$NON-NLS-1$ - 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/actions/CleanupActionXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/CleanupActionXML.java deleted file mode 100644 index e5a3a13cce..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/CleanupActionXML.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.actions; - -import java.util.ResourceBundle; - -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.wst.sse.core.cleanup.IStructuredCleanupProcessor; -import org.eclipse.wst.sse.ui.edit.util.CleanupAction; -import org.eclipse.wst.xml.core.cleanup.CleanupProcessorXML; - - -public class CleanupActionXML extends CleanupAction { - protected IStructuredCleanupProcessor fCleanupProcessor; - - public CleanupActionXML(ResourceBundle bundle, String prefix, ITextEditor editor) { - super(bundle, prefix, editor); - } - - protected Dialog getCleanupDialog(Shell shell) { - if (fCleanupDialog == null) - fCleanupDialog = new CleanupDialogXML(shell); - - return fCleanupDialog; - } - - protected 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/actions/CleanupDialogXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/CleanupDialogXML.java deleted file mode 100644 index 9c55962b4d..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/CleanupDialogXML.java +++ /dev/null @@ -1,197 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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.help.WorkbenchHelp; -import org.eclipse.wst.common.encoding.CommonEncodingPreferenceNames; -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.sse.core.preferences.CommonModelPreferenceNames; -import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -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(SSEUIPlugin.getResourceString("%Cleanup_UI_")); //$NON-NLS-1$ = "Cleanup" - Composite composite = new Composite(parent, SWT.NULL); - createDialogAreaInComposite(composite); - initializeOptions(); - return composite; - } - - protected void createDialogAreaInComposite(Composite composite) { - - WorkbenchHelp.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(SSEUIPlugin.getResourceString("%Compress_empty_element_tags_UI_")); //$NON-NLS-1$ - fCheckBoxCompressEmptyElementTags.addSelectionListener(this); - - // Insert missing required attrs - fCheckBoxInsertRequiredAttrs = new Button(composite, SWT.CHECK); - fCheckBoxInsertRequiredAttrs.setText(SSEUIPlugin.getResourceString("%Insert_required_attributes_UI_")); //$NON-NLS-1$ - fCheckBoxInsertRequiredAttrs.addSelectionListener(this); - - // Insert missing begin/end tags - fCheckBoxInsertMissingTags = new Button(composite, SWT.CHECK); - fCheckBoxInsertMissingTags.setText(SSEUIPlugin.getResourceString("%Insert_missing_tags_UI_")); //$NON-NLS-1$ = "Insert missing tags" - fCheckBoxInsertMissingTags.addSelectionListener(this); - - // Quote attribute values - fCheckBoxQuoteAttrValues = new Button(composite, SWT.CHECK); - fCheckBoxQuoteAttrValues.setText(SSEUIPlugin.getResourceString("%Quote_attribute_values_UI_")); //$NON-NLS-1$ = "Quote attribute values" - fCheckBoxQuoteAttrValues.addSelectionListener(this); - - // Format source - fCheckBoxFormatSource = new Button(composite, SWT.CHECK); - fCheckBoxFormatSource.setText(SSEUIPlugin.getResourceString("%Format_source_UI_")); //$NON-NLS-1$ = "Format source" - fCheckBoxFormatSource.addSelectionListener(this); - - // Convert EOL code - fCheckBoxConvertEOLCodes = new Button(composite, SWT.CHECK); - fCheckBoxConvertEOLCodes.setText(SSEUIPlugin.getResourceString("%Convert_EOL_codes_UI_")); //$NON-NLS-1$ = "Convert end-of-line codes" - 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(SSEUIPlugin.getResourceString("%EOL_Windows_UI")); //$NON-NLS-1$ = "Windows" - fRadioButtonConvertEOLWindows.addSelectionListener(this); - fRadioButtonConvertEOLUnix = new Button(EOLCodes, SWT.RADIO); - fRadioButtonConvertEOLUnix.setText(SSEUIPlugin.getResourceString("%EOL_Unix_UI")); //$NON-NLS-1$ = "Unix" - fRadioButtonConvertEOLUnix.addSelectionListener(this); - fRadioButtonConvertEOLMac = new Button(EOLCodes, SWT.RADIO); - fRadioButtonConvertEOLMac.setText(SSEUIPlugin.getResourceString("%EOL_Mac_UI")); //$NON-NLS-1$ = "Mac" - 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(CommonModelPreferenceNames.COMPRESS_EMPTY_ELEMENT_TAGS)); - fCheckBoxInsertRequiredAttrs.setSelection(getModelPreferences().getBoolean(CommonModelPreferenceNames.INSERT_REQUIRED_ATTRS)); - fCheckBoxInsertMissingTags.setSelection(getModelPreferences().getBoolean(CommonModelPreferenceNames.INSERT_MISSING_TAGS)); - fCheckBoxQuoteAttrValues.setSelection(getModelPreferences().getBoolean(CommonModelPreferenceNames.QUOTE_ATTR_VALUES)); - fCheckBoxFormatSource.setSelection(getModelPreferences().getBoolean(CommonModelPreferenceNames.FORMAT_SOURCE)); - fCheckBoxConvertEOLCodes.setSelection(getModelPreferences().getBoolean(CommonModelPreferenceNames.CONVERT_EOL_CODES)); - String EOLCode = getModelPreferences().getString(CommonModelPreferenceNames.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(CommonModelPreferenceNames.COMPRESS_EMPTY_ELEMENT_TAGS, fCheckBoxCompressEmptyElementTags.getSelection()); - getModelPreferences().setValue(CommonModelPreferenceNames.INSERT_REQUIRED_ATTRS, fCheckBoxInsertRequiredAttrs.getSelection()); - getModelPreferences().setValue(CommonModelPreferenceNames.INSERT_MISSING_TAGS, fCheckBoxInsertMissingTags.getSelection()); - getModelPreferences().setValue(CommonModelPreferenceNames.QUOTE_ATTR_VALUES, fCheckBoxQuoteAttrValues.getSelection()); - getModelPreferences().setValue(CommonModelPreferenceNames.FORMAT_SOURCE, fCheckBoxFormatSource.getSelection()); - getModelPreferences().setValue(CommonModelPreferenceNames.CONVERT_EOL_CODES, fCheckBoxConvertEOLCodes.getSelection()); - if (fRadioButtonConvertEOLUnix.getSelection()) { - getModelPreferences().setValue(CommonModelPreferenceNames.CLEANUP_EOL_CODE, CommonEncodingPreferenceNames.LF); - } else if (fRadioButtonConvertEOLMac.getSelection()) { - getModelPreferences().setValue(CommonModelPreferenceNames.CLEANUP_EOL_CODE, CommonEncodingPreferenceNames.CR); - } else { - getModelPreferences().setValue(CommonModelPreferenceNames.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/actions/CommentActionXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/CommentActionXML.java deleted file mode 100644 index 1f6d59b690..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/CommentActionXML.java +++ /dev/null @@ -1,234 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.actions; - -import java.util.ResourceBundle; - -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.ISelection; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.texteditor.IDocumentProvider; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.ui.texteditor.TextEditorAction; -import org.eclipse.wst.sse.core.IModelManager; -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.exceptions.SourceEditingRuntimeException; -import org.eclipse.wst.sse.ui.edit.util.StructuredTextEditorActionConstants; -import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; - -public class CommentActionXML extends TextEditorAction { - protected static final String CLOSE_COMMENT = "-->"; //$NON-NLS-1$ - protected static final String OPEN_COMMENT = "<!--"; //$NON-NLS-1$ - - static IModelManager getModelManager() { - return StructuredModelManager.getInstance().getModelManager(); - } - - protected IDocument fDocument; - protected IStructuredModel fModel; - protected ITextSelection fSelection; - protected int fSelectionEndLine; - protected int fSelectionEndLineOffset; - protected int fSelectionEndOffset; - protected Position fSelectionPosition; - protected int fSelectionStartLine; - protected int fSelectionStartLineOffset; - protected int fSelectionStartOffset; - protected boolean fUpdateSelection; - - - public CommentActionXML(ResourceBundle bundle, String prefix, ITextEditor editor) { - super(bundle, prefix, editor); - } - - protected void comment(int openCommentOffset, int closeCommentOffset) { - try { - fDocument.replace(openCommentOffset, 0, OPEN_COMMENT); - fDocument.replace(closeCommentOffset, 0, CLOSE_COMMENT); - removeOpenCloseComments(openCommentOffset + OPEN_COMMENT.length(), closeCommentOffset - openCommentOffset - CLOSE_COMMENT.length()); - } - catch (BadLocationException e) { - throw new SourceEditingRuntimeException(); - } - } - - /** - * Release the current model - */ - void done() { - if (fModel != null) { - fModel.releaseFromEdit(); - fModel = null; - } - } - - protected ITextSelection getCurrentSelection() { - ITextEditor editor = getTextEditor(); - if (editor != null) { - ISelectionProvider provider = editor.getSelectionProvider(); - if (provider != null) { - ISelection selection = provider.getSelection(); - if (selection instanceof ITextSelection) - return (ITextSelection) selection; - } - } - return TextSelection.emptySelection(); - } - - protected void init() { - ITextEditor editor = getTextEditor(); - if (editor == null) - return; - - IDocumentProvider docProvider = editor.getDocumentProvider(); - - IEditorInput input = editor.getEditorInput(); - if (input == null) - return; - - fDocument = docProvider.getDocument(input); - if (fDocument == null) - return; - - IModelManager modelManager = getModelManager(); - fModel = modelManager.getExistingModelForEdit(fDocument); - if (fModel == null) - return; - - fSelection = getCurrentSelection(); - if (fSelection.isEmpty()) - return; - - fSelectionStartOffset = fSelection.getOffset(); - fSelectionEndOffset = fSelectionStartOffset + fSelection.getLength(); - - // add selection position to document - fSelectionPosition = new Position(fSelection.getOffset(), fSelection.getLength()); - try { - fDocument.addPosition(fSelectionPosition); - } - catch (BadLocationException e) { - throw new SourceEditingRuntimeException(); - } - - try { - fSelectionStartLine = fDocument.getLineOfOffset(fSelectionStartOffset); - fSelectionEndLine = fDocument.getLineOfOffset(fSelectionEndOffset); - fSelectionStartLineOffset = fDocument.getLineOffset(fSelectionStartLine); - fSelectionEndLineOffset = fDocument.getLineOffset(fSelectionEndLine); - } - catch (BadLocationException e) { - throw new SourceEditingRuntimeException(); - } - - // adjust selection end line - if (fSelectionEndLine > fSelectionStartLine && fSelectionEndLineOffset == fSelectionEndOffset) - fSelectionEndLine--; - } - - protected boolean isCommentLine(int line) { - try { - IRegion region = fDocument.getLineInformation(line); - String string = fDocument.get(region.getOffset(), region.getLength()).trim(); - return string.length() >= OPEN_COMMENT.length() + CLOSE_COMMENT.length() && string.startsWith(OPEN_COMMENT) && string.endsWith(CLOSE_COMMENT); - } - catch (BadLocationException e) { - throw new SourceEditingRuntimeException(); - } - } - - protected void prepareSelection() { - fUpdateSelection = fSelection.getLength() > 0 && fSelectionStartLineOffset == fSelectionStartOffset && !isCommentLine(fSelectionStartLine); - } - - protected void processAction() { - fModel.beginRecording(this, SSEUIPlugin.getResourceString(StructuredTextEditorActionConstants.ACTION_NAME_COMMENT + ".tooltip")); //$NON-NLS-1$ - fModel.aboutToChangeModel(); - - for (int i = fSelectionStartLine; i <= fSelectionEndLine; i++) { - try { - if (fDocument.getLineLength(i) > 0 && !isCommentLine(i)) { - int openCommentOffset = fDocument.getLineOffset(i); - int lineDelimiterLength = fDocument.getLineDelimiter(i) == null ? 0 : fDocument.getLineDelimiter(i).length(); - int closeCommentOffset = openCommentOffset + fDocument.getLineLength(i) - lineDelimiterLength + OPEN_COMMENT.length(); - comment(openCommentOffset, closeCommentOffset); - } - } - catch (BadLocationException e) { - throw new SourceEditingRuntimeException(); - } - } - - fModel.changedModel(); - fModel.endRecording(this); - } - - protected void removeOpenCloseComments(int offset, int length) { - try { - int adjusted_length = length; - - // remove open comments - String string = fDocument.get(offset, length); - int index = string.lastIndexOf(OPEN_COMMENT); - while (index != -1) { - fDocument.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 = fDocument.get(offset, adjusted_length); - index = string.lastIndexOf(CLOSE_COMMENT); - while (index != -1) { - fDocument.replace(offset + index, CLOSE_COMMENT.length(), ""); //$NON-NLS-1$ - index = string.lastIndexOf(CLOSE_COMMENT, index - 1); - } - } - catch (BadLocationException e) { - throw new SourceEditingRuntimeException(); - } - } - - public void run() { - init(); - prepareSelection(); - processAction(); - updateSelection(); - done(); - } - - - protected void setCurrentSelection(ITextSelection selection) { - ITextEditor editor = getTextEditor(); - if (editor != null) { - ISelectionProvider provider = editor.getSelectionProvider(); - if (provider != null) { - provider.setSelection(selection); - } - } - } - - protected void updateSelection() { - if (fUpdateSelection) { - ITextSelection selection = new TextSelection(fDocument, fSelectionPosition.getOffset() - OPEN_COMMENT.length(), fSelectionPosition.getLength() + OPEN_COMMENT.length()); - setCurrentSelection(selection); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/EditAttributeAction.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/EditAttributeAction.java deleted file mode 100644 index ffc4d88c31..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/EditAttributeAction.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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.dialogs.EditAttributeDialog; -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; -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/actions/EditDoctypeAction.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/EditDoctypeAction.java deleted file mode 100644 index 2c669c5e0c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/EditDoctypeAction.java +++ /dev/null @@ -1,187 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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.IStructuredModel; -import org.eclipse.wst.xml.core.document.XMLDocument; -import org.eclipse.wst.xml.core.document.XMLDocumentType; -import org.eclipse.wst.xml.core.internal.document.DocumentImpl; -import org.eclipse.wst.xml.ui.dialogs.EditDoctypeDialog; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -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) { - XMLDocument documentImpl = (XMLDocument) document; - XMLDocumentType doctypeImpl = (XMLDocumentType) 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() : XMLUIPlugin.getResourceString("%_UI_LABEL_ROOT_ELEMENT_VALUE"); //$NON-NLS-1$ - } - - 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 = XMLUIPlugin.getResourceString("%_UI_LABEL_EDIT_DOCTYPE"); //$NON-NLS-1$ - } - } 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 = XMLUIPlugin.getResourceString("%_UI_MENU_ADD_DTD_INFORMATION_TITLE"); //$NON-NLS-1$ - } - } - - 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 XMLDocumentType) { - XMLDocumentType doctypeImpl = (XMLDocumentType) 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/actions/EditElementAction.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/EditElementAction.java deleted file mode 100644 index a3507d8f6a..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/EditElementAction.java +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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.text.IStructuredDocumentRegion; -import org.eclipse.wst.xml.core.document.XMLElement; -import org.eclipse.wst.xml.core.document.XMLModel; -import org.eclipse.wst.xml.ui.dialogs.EditElementDialog; -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; -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 XMLElement) { - XMLElement elementImpl = (XMLElement) element; - XMLModel 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(XMLModel 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/actions/EditProcessingInstructionAction.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/EditProcessingInstructionAction.java deleted file mode 100644 index b8c118b21b..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/EditProcessingInstructionAction.java +++ /dev/null @@ -1,93 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.actions; - -import org.eclipse.jface.window.Window; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.wst.xml.ui.dialogs.EditProcessingInstructionDialog; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -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, XMLUIPlugin.getResourceString("%_UI_PI_TARGET_VALUE"), XMLUIPlugin.getResourceString("%_UI_PI_DATA_VALUE")); //$NON-NLS-1$ //$NON-NLS-2$ - } - - 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/actions/EditSchemaInfoAction.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/EditSchemaInfoAction.java deleted file mode 100644 index db9d410c1b..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/EditSchemaInfoAction.java +++ /dev/null @@ -1,163 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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.common.contentmodel.util.DOMNamespaceInfoManager; -import org.eclipse.wst.common.contentmodel.util.NamespaceInfo; -import org.eclipse.wst.xml.ui.dialogs.EditSchemaInfoDialog; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -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(XMLUIPlugin.getResourceString("%_UI_MENU_EDIT_SCHEMA_INFORMATION_TITLE")); //$NON-NLS-1$ - 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/actions/MenuBuilder.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/MenuBuilder.java deleted file mode 100644 index 0403f88d34..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/MenuBuilder.java +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.actions; - -import java.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/actions/NodeAction.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/NodeAction.java deleted file mode 100644 index ff91cdd068..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/NodeAction.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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/actions/RemoveBlockCommentActionXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/RemoveBlockCommentActionXML.java deleted file mode 100644 index 1030cdcf0e..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/RemoveBlockCommentActionXML.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.actions; - -import java.util.ResourceBundle; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.wst.sse.core.exceptions.SourceEditingRuntimeException; -import org.eclipse.wst.sse.ui.edit.util.StructuredTextEditorActionConstants; -import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; -import org.eclipse.wst.xml.core.internal.document.CommentImpl; - -public class RemoveBlockCommentActionXML extends AddBlockCommentActionXML { - public RemoveBlockCommentActionXML(ResourceBundle bundle, String prefix, ITextEditor editor) { - super(bundle, prefix, editor); - } - - protected void init() { - super.init(); - - fCloseCommentOffset = fSelectionEndIndexedRegion.getEndOffset() - OPEN_COMMENT.length() - CLOSE_COMMENT.length(); - } - - protected void processAction() { - fModel.beginRecording(this, SSEUIPlugin.getResourceString(StructuredTextEditorActionConstants.ACTION_NAME_REMOVE_BLOCK_COMMENT + ".tooltip")); //$NON-NLS-1$ - fModel.aboutToChangeModel(); - - if (fSelection.getLength() == 0) { - if (fSelectionStartIndexedRegion instanceof CommentImpl) { - try { - fDocument.replace(fOpenCommentOffset, OPEN_COMMENT.length(), ""); //$NON-NLS-1$ - fDocument.replace(fCloseCommentOffset, CLOSE_COMMENT.length(), ""); //$NON-NLS-1$ - } catch (BadLocationException e) { - throw new SourceEditingRuntimeException(); - } - } - } else { - if (fSelectionStartIndexedRegion instanceof CommentImpl) { - try { - fDocument.replace(fOpenCommentOffset, OPEN_COMMENT.length(), ""); //$NON-NLS-1$ - } catch (BadLocationException e) { - throw new SourceEditingRuntimeException(); - } - } - - if (fSelectionEndIndexedRegion instanceof CommentImpl) { - try { - fDocument.replace(fCloseCommentOffset, CLOSE_COMMENT.length(), ""); //$NON-NLS-1$ - } catch (BadLocationException e) { - throw new SourceEditingRuntimeException(); - } - } - } - removeOpenCloseComments(fOpenCommentOffset + OPEN_COMMENT.length(), fCloseCommentOffset - fOpenCommentOffset - CLOSE_COMMENT.length()); - - fModel.changedModel(); - fModel.endRecording(this); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/ReplacePrefixAction.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/ReplacePrefixAction.java deleted file mode 100644 index c94df41219..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/ReplacePrefixAction.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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.common.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/actions/ToggleCommentActionXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/ToggleCommentActionXML.java deleted file mode 100644 index 451d4ed51a..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/ToggleCommentActionXML.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.actions; - -import java.util.ResourceBundle; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IRegion; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.wst.sse.core.exceptions.SourceEditingRuntimeException; -import org.eclipse.wst.sse.ui.edit.util.StructuredTextEditorActionConstants; -import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; - -public class ToggleCommentActionXML extends UncommentActionXML { - public ToggleCommentActionXML(ResourceBundle bundle, String prefix, ITextEditor editor) { - super(bundle, prefix, editor); - } - - protected void processAction() { - fModel.beginRecording(this, SSEUIPlugin.getResourceString(StructuredTextEditorActionConstants.ACTION_NAME_COMMENT + ".tooltip")); //$NON-NLS-1$ - fModel.aboutToChangeModel(); - - for (int i = fSelectionStartLine; i <= fSelectionEndLine; i++) { - try { - if (fDocument.getLineLength(i) > 0) { - if (isCommentLine(i)) { - int lineOffset = fDocument.getLineOffset(i); - IRegion region = fDocument.getLineInformation(i); - String string = fDocument.get(region.getOffset(), region.getLength()); - int openCommentOffset = lineOffset + string.indexOf(OPEN_COMMENT); - int closeCommentOffset = lineOffset + string.indexOf(CLOSE_COMMENT) - OPEN_COMMENT.length(); - uncomment(openCommentOffset, closeCommentOffset); - } else { - int openCommentOffset = fDocument.getLineOffset(i); - int lineDelimiterLength = fDocument.getLineDelimiter(i) == null ? 0 : fDocument.getLineDelimiter(i).length(); - int closeCommentOffset = openCommentOffset + fDocument.getLineLength(i) - lineDelimiterLength + OPEN_COMMENT.length(); - comment(openCommentOffset, closeCommentOffset); - } - } - } catch (BadLocationException e) { - throw new SourceEditingRuntimeException(); - } - } - - fModel.changedModel(); - fModel.endRecording(this); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/UncommentActionXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/UncommentActionXML.java deleted file mode 100644 index 02e440bf6b..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/actions/UncommentActionXML.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.actions; - -import java.util.ResourceBundle; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IRegion; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.wst.sse.core.exceptions.SourceEditingRuntimeException; -import org.eclipse.wst.sse.ui.edit.util.StructuredTextEditorActionConstants; -import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; - -public class UncommentActionXML extends CommentActionXML { - public UncommentActionXML(ResourceBundle bundle, String prefix, ITextEditor editor) { - super(bundle, prefix, editor); - } - - protected void processAction() { - fModel.beginRecording(this, SSEUIPlugin.getResourceString(StructuredTextEditorActionConstants.ACTION_NAME_COMMENT + ".tooltip")); //$NON-NLS-1$ - fModel.aboutToChangeModel(); - - for (int i = fSelectionStartLine; i <= fSelectionEndLine; i++) { - try { - if (fDocument.getLineLength(i) > 0 && isCommentLine(i)) { - int lineOffset = fDocument.getLineOffset(i); - IRegion region = fDocument.getLineInformation(i); - String string = fDocument.get(region.getOffset(), region.getLength()); - int openCommentOffset = lineOffset + string.indexOf(OPEN_COMMENT); - int closeCommentOffset = lineOffset + string.indexOf(CLOSE_COMMENT) - OPEN_COMMENT.length(); - uncomment(openCommentOffset, closeCommentOffset); - } - } catch (BadLocationException e) { - throw new SourceEditingRuntimeException(); - } - } - - fModel.changedModel(); - fModel.endRecording(this); - } - - protected void uncomment(int openCommentOffset, int closeCommentOffset) { - try { - fDocument.replace(openCommentOffset, OPEN_COMMENT.length(), ""); //$NON-NLS-1$ - fDocument.replace(closeCommentOffset, CLOSE_COMMENT.length(), ""); //$NON-NLS-1$ - } catch (BadLocationException e) { - throw new SourceEditingRuntimeException(); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/AbstractContentAssistProcessor.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/AbstractContentAssistProcessor.java deleted file mode 100644 index 867961e94e..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/AbstractContentAssistProcessor.java +++ /dev/null @@ -1,2190 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.contentassist; - -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.Iterator; -import java.util.List; -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.swt.graphics.Image; -import org.eclipse.wst.common.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.common.contentmodel.CMContent; -import org.eclipse.wst.common.contentmodel.CMDataType; -import org.eclipse.wst.common.contentmodel.CMDocument; -import org.eclipse.wst.common.contentmodel.CMElementDeclaration; -import org.eclipse.wst.common.contentmodel.CMEntityDeclaration; -import org.eclipse.wst.common.contentmodel.CMGroup; -import org.eclipse.wst.common.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.common.contentmodel.CMNode; -import org.eclipse.wst.common.contentmodel.CMNodeList; -import org.eclipse.wst.common.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.common.contentmodel.modelquery.ModelQueryAction; -import org.eclipse.wst.common.contentmodel.util.DOMNamespaceHelper; -import org.eclipse.wst.common.encoding.ContentTypeEncodingPreferences; -import org.eclipse.wst.common.encoding.content.IContentTypeIdentifier; -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.sse.core.IndexedRegion; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.text.IStructuredDocument; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.text.ITextRegion; -import org.eclipse.wst.sse.core.text.ITextRegionContainer; -import org.eclipse.wst.sse.core.text.ITextRegionList; -import org.eclipse.wst.sse.core.util.Debug; -import org.eclipse.wst.sse.ui.IReleasable; -import org.eclipse.wst.sse.ui.StructuredTextViewer; -import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; -import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils; -import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal; -import org.eclipse.wst.xml.core.document.XMLDocument; -import org.eclipse.wst.xml.core.document.XMLElement; -import org.eclipse.wst.xml.core.document.XMLModel; -import org.eclipse.wst.xml.core.document.XMLNode; -import org.eclipse.wst.xml.core.internal.document.AttrImpl; -import org.eclipse.wst.xml.core.jsp.model.parser.temp.XMLJSPRegionContexts; -import org.eclipse.wst.xml.core.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.core.parser.XMLRegionContext; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages; -import org.eclipse.wst.xml.ui.taginfo.MarkupTagInfoProvider; -import org.eclipse.wst.xml.ui.templates.TemplateContextTypeIds; -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 { - protected static final String INTERNALERROR = SSEUIPlugin.getResourceString("%SEVERE_internal_error_occu_UI_"); //$NON-NLS-1$ = "SEVERE internal error occurred " - protected static final String UNKNOWN_ATTR = SSEUIPlugin.getResourceString("%No_known_attribute__UI_"); //$NON-NLS-1$ = "No known attribute " - protected static final String UNKNOWN_CONTEXT = SSEUIPlugin.getResourceString("%Content_Assist_not_availab_UI_"); //$NON-NLS-1$ = "Content Assist not available at the current location " - 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; - - protected List macroContexts = new ArrayList(); - - private final boolean showValues = true; - - public AbstractContentAssistProcessor() { - super(); - init(); - } - - protected void addAttributeNameProposals(ContentAssistRequest contentAssistRequest) { - XMLNode node = (XMLNode) contentAssistRequest.getNode(); - IStructuredDocumentRegion sdRegion = contentAssistRequest.getDocumentRegion(); - // retrieve the list of attributes - CMElementDeclaration elementDecl = getCMElementDeclaration(node); - if (elementDecl != null) { - CMNamedNodeMap attributes = elementDecl.getAttributes(); - 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) { - // CMVC 246618 - int isRequired = 0; - Image attrImage = null; - for (int i = 0; i < attributes.getLength(); i++) { - CMAttributeDeclaration attrDecl = (CMAttributeDeclaration) attributes.item(i); - if (attrDecl.getUsage() == CMAttributeDeclaration.REQUIRED) { - isRequired = XMLRelevanceConstants.R_REQUIRED; - attrImage = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATT_REQ_OBJ); - } else { - isRequired = 0; - attrImage = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE); - } - - - 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) { - 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); //CMVC - // 269884 - } - // 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 - (showValues && proposedText.indexOf("\"\"") < 0) ? proposedText : getRequiredName(node, attrDecl), //$NON-NLS-1$ - null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_NAME + isRequired); - } - contentAssistRequest.addProposal(proposal); - } - } - } - } else { - setErrorMessage(SSEUIPlugin.getResourceString("%25concat", (new Object[]{node.getNodeName()}))); //+ - // node.getNodeName() - // + "> - // is - // unknown"); - // //$NON-NLS-1$ - // = - // "Element - // <{0}> - // is - // unknown." - } - addTemplates(contentAssistRequest, TemplateContextTypeIds.ATTRIBUTE); - } - - protected void addAttributeValueProposals(ContentAssistRequest contentAssistRequest) { - XMLNode node = (XMLNode) 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() == XMLRegionContext.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(); - 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; - 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("'"))) //$NON-NLS-2$//$NON-NLS-1$ - 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)) { - CustomCompletionProposal proposal = new CustomCompletionProposal("\"" + possibleValue + "\"", //$NON-NLS-2$//$NON-NLS-1$ - contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), possibleValue.length() + 1, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE), possibleValue, 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) { - CustomCompletionProposal proposal = new CustomCompletionProposal("\"" + value + "\"", //$NON-NLS-2$//$NON-NLS-1$ - contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), value.length() + 1, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE), value, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE); - contentAssistRequest.addProposal(proposal); - if (currentValue.length() > 0 && !value.equals(currentValue)) { - proposal = new CustomCompletionProposal("\"" + currentValue + "\"", //$NON-NLS-2$//$NON-NLS-1$ - contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), currentValue.length() + 1, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE), currentValue, 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) { - proposal = new CustomCompletionProposal("\"" + currentValue + "\"", //$NON-NLS-2$//$NON-NLS-1$ - contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), 1, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE), "\"" + currentValue + "\"", //$NON-NLS-2$//$NON-NLS-1$ - null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE); - contentAssistRequest.addProposal(proposal); - } - } - } else - setErrorMessage(UNKNOWN_CONTEXT); - - addTemplates(contentAssistRequest, TemplateContextTypeIds.ATTRIBUTEVALUE); - } - - protected void addCommentProposal(ContentAssistRequest contentAssistRequest) { - contentAssistRequest.addProposal(new CustomCompletionProposal("<!-- -->", //$NON-NLS-1$ - contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), 5, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_COMMENT), SSEUIPlugin.getResourceString("%6concat", (new Object[]{" <!-- -->"})), //$NON-NLS-1$ = "comment {0}"//$NON-NLS-2$ - 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) { - addXMLProposal(contentAssistRequest); - addTemplates(contentAssistRequest, TemplateContextTypeIds.TAG); - } - - /** - * 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), SSEUIPlugin.getResourceString("%9concat", (new Object[]{" '>'"})), //$NON-NLS-1$ = "Close with {0}"//$NON-NLS-2$ - null, null, XMLRelevanceConstants.R_END_TAG_NAME); - contentAssistRequest.addProposal(proposal); - } else { - XMLNode node = (XMLNode) contentAssistRequest.getNode(); - ModelQuery modelQuery = ModelQueryUtil.getModelQuery(node.getOwnerDocument()); - Node aNode = contentAssistRequest.getNode(); - String matchString = contentAssistRequest.getMatchString(); - if (matchString.startsWith("</")) //$NON-NLS-1$ - matchString = matchString.substring(2); - while (aNode != null) { - if (aNode.getNodeType() == Node.ELEMENT_NODE) { - if (aNode.getNodeName().startsWith(matchString)) { - XMLNode aXMLNode = (XMLNode) 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 - if (contentAssistRequest.getRegion().getType() == XMLRegionContext.XML_TAG_NAME) { - proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getStartOffset(), contentAssistRequest.getRegion().getTextLength(), proposedText.length(), XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC), proposedText, null, proposedInfo, XMLRelevanceConstants.R_END_TAG_NAME); - } else { - proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), proposedText.length(), XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC), SSEUIPlugin.getResourceString("%9concat", (new Object[]{"'" + proposedText + "'"})), //$NON-NLS-1$ = "Close with {0}"//$NON-NLS-2$ //$NON-NLS-3$ - 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) { - XMLNode node = (XMLNode) contentAssistRequest.getParent(); - - // CMVC 241090 for special meta-info comment tags - if (isCommentNode(node)) { - // loop and find non comment node parent - while (node != null && isCommentNode(node)) { - node = (XMLNode) node.getParentNode(); - } - } - - // 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) { - // fix for CMVC 261790 - // //////////////////////////////////////////////////////////////////////////////////// - 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()) != XMLRegionContext.XML_END_TAG_OPEN && type != XMLRegionContext.XML_TAG_CLOSE && !needsEndTag(xmlEndTagOpen) && type != XMLRegionContext.XML_TAG_OPEN) { - xmlEndTagOpen = xmlEndTagOpen.getPrevious(); - } - - if (xmlEndTagOpen == null) - return; - - node = (XMLNode) node.getModel().getIndexedRegion(xmlEndTagOpen.getStartOffset()); - node = (XMLNode) 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 = SSEUIPlugin.getResourceString("%17concat", (new Object[]{tagName})); //$NON-NLS-1$ - addProposal = true; - } - } else if (type == XMLRegionContext.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 = SSEUIPlugin.getResourceString("%15concat", (new Object[]{node.getNodeName()})); //$NON-NLS-1$ - addProposal = true; - } else if (type == XMLRegionContext.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 = SSEUIPlugin.getResourceString("%15concat", (new Object[]{"/" + node.getNodeName()})); //$NON-NLS-1$ //$NON-NLS-2$ - addProposal = true; - } - } - // fix for CMVC 261790 - // //////////////////////////////////////////////////////////////////////////////////// - // fix for CMVC 263163, 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 = SSEUIPlugin.getResourceString("%17concat", (new Object[]{parent.getNodeName()})); //$NON-NLS-1$ - setErrorMessage(null); - addProposal = true; - } - } - // end fix for CMVC 261790 - // //////////////////////////////////////////////////////////////////////////////////// - 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, XMLNode 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... - // CMVC 242943 - // CMVC 245532 - 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 XMLNode) { - // ==> // int xmlpiNodePosition = - // ((XMLNode)child).getEndOffset(); - } - // skip white space and text - while ((child = child.getNextSibling()) != null && (child.getNodeType() == Node.TEXT_NODE)) { - } - // check if theres a node inbetween XMLPI and cursor position - if (child != null && child instanceof XMLNode) { - // CMVC 257486 - if (contentAssistRequest.getReplacementBeginPosition() >= ((XMLNode) child).getEndOffset() || !xmlpiIsFirstElement) { - insertDoctype = false; - } - } - break; - } - } - - if (!xmlpiFound) { - addXMLProposal(contentAssistRequest); - } else if (owningDocument.getDoctype() == null && isCursorAfterXMLPI(contentAssistRequest) && insertDoctype) { - addDocTypeProposal(contentAssistRequest); - } - } - - /** - * Close an unclosed start tag - */ - protected void addTagCloseProposals(ContentAssistRequest contentAssistRequest) { - XMLNode node = (XMLNode) 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); - - // 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(), XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC), SSEUIPlugin.getResourceString("%3concat", (new Object[]{getContentGenerator().getStartTagClose(node, elementDecl)})), //$NON-NLS-1$ = "Close with '{0}'" - 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, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC), SSEUIPlugin.getResourceString("%9concat", (new Object[]{" '>'"})), //$NON-NLS-1$ = "Close with {0}"//$NON-NLS-2$ - 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) { - // FIX FOR CMVC 247482 - // 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, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC), SSEUIPlugin.getResourceString("%5concat", (new Object[]{node.getNodeName()})), //$NON-NLS-1$ = "Close with '></{0}>'" - 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, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC), SSEUIPlugin.getResourceString("%9concat", (new Object[]{" \"/>\""})), //$NON-NLS-1$ = "Close with {0}"//$NON-NLS-2$ - 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, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC), SSEUIPlugin.getResourceString("%9concat", (new Object[]{" '>'"})), //$NON-NLS-1$ = "Close with {0}"//$NON-NLS-2$ - 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(); - List validActions = null; - String error = null; - - // CMVC #242943 shouldn't have proposals before XMLPI - // (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 && ((XMLDocument) parent).isXMLType() && !isCursorAfterXMLPI(contentAssistRequest)) { - // but we should always have macros - // need to be careful these are only added one time - addTemplates(contentAssistRequest, TemplateContextTypeIds.TAG); - return; - } - // only want proposals if cursor is after doctype... - if (!isCursorAfterDoctype(contentAssistRequest)) - return; - - // CMVC 248081 - // 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 XMLNode && isCommentNode((XMLNode) parent)) { - // loop and find non comment node? - while (parent != null && isCommentNode((XMLNode) parent)) { - parent = (XMLNode) 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 XMLNode) { - if (((XMLNode) parent).getLastStructuredDocumentRegion() != ((XMLNode) parent).getFirstStructuredDocumentRegion()) { - begin = ((XMLNode) parent).getFirstStructuredDocumentRegion().getEndOffset(); - length = ((XMLNode) 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 children - validActions = getAvailableChildrenAtIndex((Element) parent, childPosition); - cmnodes = getValidCMNodes(childPosition, ModelQueryAction.INSERT, validActions); - Iterator nodeIterator = cmnodes.iterator(); - if (!nodeIterator.hasNext()) { - if (getCMElementDeclaration(parent) != null) - error = SSEUIPlugin.getResourceString("%1concat", (new Object[]{parent.getNodeName()})); //$NON-NLS-1$ = "{0} has no available child tags." - else - error = SSEUIPlugin.getResourceString("%31concat", (new Object[]{parent.getNodeName()})); //$NON-NLS-1$ - } - 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$ - //$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); - // Account for the < and >. If attributes were - // added, the cursor will be placed - // at the offset before of the first character of the - // first attribute name. - int markupAdjustment = getContentGenerator().getMinimalStartTagLength(parent, elementDecl); - if (beginsWith(tagname, matchString)) { - String proposedText = getRequiredText(parent, elementDecl); - String proposedInfo = getAdditionalInfo(parentDecl, elementDecl); - CustomCompletionProposal proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), markupAdjustment, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC), tagname, null, proposedInfo, XMLRelevanceConstants.R_TAG_INSERTION); - contentAssistRequest.addProposal(proposal); - } - } - } - if (contentAssistRequest.getProposals().size() == 0) { - if (error != null) - setErrorMessage(error); - else if (contentAssistRequest.getMatchString() != null && contentAssistRequest.getMatchString().length() > 0) - setErrorMessage(SSEUIPlugin.getResourceString("%11concat", (new Object[]{parent.getNodeName(), contentAssistRequest.getMatchString()}))); //$NON-NLS-1$ - //$NON-NLS-1$ = "No known child tag names of <{0}> begin with \"{1}\"." - else - setErrorMessage(SSEUIPlugin.getResourceString("%14concat", (new Object[]{parent.getNodeName()}))); //$NON-NLS-1$ - } - } - } 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 = ((XMLNode) child).getFirstStructuredDocumentRegion().getStartOffset() + ((XMLNode) child).getFirstStructuredDocumentRegion().getTextLength(); - xmlpiFound = xmlpiFound || xmlpi; - doctypeFound = doctypeFound || doctype; - } - if (!xmlpiFound && contentAssistRequest.getReplacementBeginPosition() < minimumOffset) { - addXMLProposal(contentAssistRequest); - } - - 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) { - 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, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC), tagname, null, proposedInfo, XMLRelevanceConstants.R_TAG_INSERTION); - contentAssistRequest.addProposal(proposal); - } - } - } - } - addTemplates(contentAssistRequest, TemplateContextTypeIds.TAG); - } - - protected void addTagNameProposals(ContentAssistRequest contentAssistRequest, int childPosition) { - List cmnodes = null; - Node parent = contentAssistRequest.getParent(); - XMLNode node = (XMLNode) contentAssistRequest.getNode(); - List validActions = null; - String error = null; - String matchString = contentAssistRequest.getMatchString(); - if (parent.getNodeType() == Node.ELEMENT_NODE) { - // retrieve the list of children - validActions = getAvailableChildrenAtIndex((Element) parent, childPosition); - cmnodes = getValidCMNodes(childPosition, ModelQueryAction.INSERT, validActions); - 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$ - //$NON-NLS-1$ - matchString = matchString.substring(1); - if (!nodeIterator.hasNext()) - error = SSEUIPlugin.getResourceString("%8concat", (new Object[]{parent.getNodeName()})); //$NON-NLS-1$ - 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; - if (ed.getContentType() == CMElementDeclaration.EMPTY) { - proposedText += getContentGenerator().getStartTagClose(parent, ed); - cursorAdjustment = proposedText.length(); - } else { - cursorAdjustment = proposedText.length() + 1; - proposedText += "></" + getRequiredName(parent, elementDecl) + ">"; //$NON-NLS-2$//$NON-NLS-1$ - } - } - } - if (beginsWith(proposedText, matchString)) { - String proposedInfo = getAdditionalInfo(getCMElementDeclaration(parent), elementDecl); - CustomCompletionProposal proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), cursorAdjustment, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC), 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(SSEUIPlugin.getResourceString("%27concat", (new Object[]{parent.getNodeName(), contentAssistRequest.getMatchString()}))); //$NON-NLS-1$ - //$NON-NLS-1$ = "No known child tag names of <{0}> begin with \"{1}\"" - else - setErrorMessage(SSEUIPlugin.getResourceString("%28concat", (new Object[]{parent.getNodeName()}))); //$NON-NLS-1$ - } - } 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; - proposedText = getRequiredName(parent, ed); - if (!beginsWith(proposedText, matchString)) - continue; - if ((node != null && node.getAttributes() != null && node.getAttributes().getLength() > 0) || ((node.getNodeType() != Node.TEXT_NODE) && node.getFirstStructuredDocumentRegion().isEnded())) { - cursorAdjustment = proposedText.length(); - } else { - cursorAdjustment = proposedText.length(); - if (ed instanceof CMElementDeclaration) { - CMElementDeclaration elementDecl = (CMElementDeclaration) ed; - if (elementDecl.getContentType() == CMElementDeclaration.EMPTY) { - proposedText += getContentGenerator().getStartTagClose(parent, elementDecl); - cursorAdjustment = proposedText.length(); - } else { - cursorAdjustment = proposedText.length() + 1; - proposedText += "></" + getRequiredName(parent, elementDecl) + ">"; //$NON-NLS-2$//$NON-NLS-1$ - } - } - } - String proposedInfo = getAdditionalInfo(null, ed); - CustomCompletionProposal proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), cursorAdjustment, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC), getRequiredName(parent, ed), null, proposedInfo, XMLRelevanceConstants.R_TAG_NAME); - contentAssistRequest.addProposal(proposal); - } - } - } - - /** - * Adds templates to the list of proposals - * - * @param contentAssistRequest - * @param context - */ - protected void addTemplates(ContentAssistRequest contentAssistRequest, String context) { - if (macroContexts.contains(context)) - return; - if (contentAssistRequest == null) - return; - macroContexts.add(context); - - boolean useProposalList = !contentAssistRequest.shouldSeparate(); - - if (getTemplateCompletionProcessor() != null) { - getTemplateCompletionProcessor().setContextType(context); - ICompletionProposal[] proposals = getTemplateCompletionProcessor().computeCompletionProposals(fTextViewer, contentAssistRequest.getReplacementBeginPosition()); - for (int i = 0; i < proposals.length; ++i) { - if (useProposalList) - contentAssistRequest.addProposal(proposals[i]); - else - contentAssistRequest.addMacro(proposals[i]); - } - } - } - - protected void addXMLProposal(ContentAssistRequest contentAssistRequest) { - String proposedText = "<?xml version=\"1.0\" encoding=\"" + ContentTypeEncodingPreferences.getUserPreferredCharsetName(IContentTypeIdentifier.ContentTypeID_SSEXML) + "\"?>"; //$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(XMLNode 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(); - // 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) 221190 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, XMLNode nodeAtOffset, XMLNode 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, XMLNode nodeAtOffset, XMLNode 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 - XMLNode actualNode = (XMLNode) 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, XMLNode treeNode, XMLNode 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 == XMLRegionContext.XML_TAG_OPEN) { - contentAssistRequest = computeTagOpenProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode); - } else if (regionType == XMLRegionContext.XML_TAG_NAME) { - contentAssistRequest = computeTagNameProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode); - } else if (regionType == XMLRegionContext.XML_TAG_ATTRIBUTE_NAME) { - contentAssistRequest = computeAttributeProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode); - } else if (regionType == XMLRegionContext.XML_TAG_ATTRIBUTE_EQUALS) { - contentAssistRequest = computeEqualsProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode); - } else if (regionType == XMLRegionContext.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.. - XMLNode actualNode = (XMLNode) xmlnode.getModel().getIndexedRegion(sdRegion.getStartOffset(completionRegion)); - contentAssistRequest = newContentAssistRequest(actualNode, actualNode, sdRegion, completionRegion, documentPosition, 0, matchString); - addTagCloseProposals(contentAssistRequest); - } else if (regionType == XMLRegionContext.XML_TAG_ATTRIBUTE_VALUE) { - contentAssistRequest = computeAttributeValueProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode); - } else if ((regionType == XMLRegionContext.XML_TAG_CLOSE) || (regionType == XMLRegionContext.XML_EMPTY_TAG_CLOSE) || (regionType == XMLJSPRegionContexts.JSP_DIRECTIVE_CLOSE)) { - contentAssistRequest = computeTagCloseProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode); - } else if (regionType == XMLRegionContext.XML_END_TAG_OPEN) { - contentAssistRequest = computeEndTagOpenProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode); - } else if (regionType == XMLRegionContext.XML_CONTENT || regionType == XMLRegionContext.XML_CHAR_REFERENCE || regionType == XMLRegionContext.XML_ENTITY_REFERENCE || regionType == XMLRegionContext.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 == XMLJSPRegionContexts.JSP_COMMENT_OPEN || regionType == XMLJSPRegionContexts.JSP_DECLARATION_OPEN || regionType == XMLJSPRegionContexts.JSP_DIRECTIVE_OPEN || regionType == XMLJSPRegionContexts.JSP_EXPRESSION_OPEN || regionType == XMLJSPRegionContexts.JSP_SCRIPTLET_OPEN || regionType == XMLRegionContext.XML_DECLARATION_OPEN || regionType == XMLRegionContext.XML_PI_OPEN || regionType == XMLRegionContext.XML_COMMENT_OPEN || regionType == XMLRegionContext.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 == XMLJSPRegionContexts.JSP_COMMENT_OPEN || regionType == XMLJSPRegionContexts.JSP_DECLARATION_OPEN || regionType == XMLJSPRegionContexts.JSP_DIRECTIVE_OPEN || regionType == XMLJSPRegionContexts.JSP_EXPRESSION_OPEN || regionType == XMLJSPRegionContexts.JSP_SCRIPTLET_OPEN || regionType == XMLRegionContext.XML_DECLARATION_OPEN || regionType == XMLRegionContext.XML_PI_OPEN || regionType == XMLRegionContext.XML_COMMENT_OPEN || regionType == XMLRegionContext.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); - macroContexts.clear(); - - fTextViewer = textViewer; - - IndexedRegion treeNode = ContentAssistUtils.getNodeAt((StructuredTextViewer) textViewer, documentPosition); - - Node node = (Node) treeNode; - while (node != null && node.getNodeType() == Node.TEXT_NODE && node.getParentNode() != null) - node = node.getParentNode(); - XMLNode xmlnode = (XMLNode) 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.getInstance().getModelManager().getExistingModelForRead(textViewer.getDocument()); - try { - if (sModel != null) { - XMLDocument docNode = ((XMLModel) sModel).getDocument(); - contentAssistRequest = newContentAssistRequest(docNode, docNode, sdRegion, completionRegion, documentPosition, 0, null); - addEmptyDocumentProposals(contentAssistRequest); - addTemplates(contentAssistRequest, TemplateContextTypeIds.ALL); - addTemplates(contentAssistRequest, TemplateContextTypeIds.TAG); - } - } finally { - if (sModel != null) - sModel.releaseFromRead(); - } - 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$ - addTemplates(contentAssistRequest, TemplateContextTypeIds.ALL); - 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, (XMLNode) treeNode, xmlnode); - return contentAssistRequest.getCompletionProposals(); - } - - // compute normal proposals - contentAssistRequest = computeCompletionProposals(documentPosition, matchString, completionRegion, (XMLNode) 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); - } - // #180541 - addTemplates(contentAssistRequest, TemplateContextTypeIds.ALL); - - if (contentAssistRequest.getProposals().size() == 0) - setErrorMessage(UNKNOWN_CONTEXT); - - return contentAssistRequest.getCompletionProposals(); - } - - protected ContentAssistRequest computeContentProposals(int documentPosition, String matchString, ITextRegion completionRegion, XMLNode nodeAtOffset, XMLNode 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, XMLNode nodeAtOffset, XMLNode 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() == XMLRegionContext.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, XMLNode treeNode) { - // only handle XML content for now - Vector proposals = new Vector(); // ICompletionProposals - IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition); - if (completionRegion != null && completionRegion.getType() == XMLRegionContext.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.getFullText().trim().equals("&")) { //$NON-NLS-1$ - completionRegion = prev; - 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); //$NON-NLS-1$ - } - } - } - return (ICompletionProposal[]) ((proposals.size() > 0) ? proposals.toArray(new ICompletionProposal[proposals.size()]) : null); - } - - protected ContentAssistRequest computeEqualsProposals(int documentPosition, String matchString, ITextRegion completionRegion, XMLNode nodeAtOffset, XMLNode node) { - ContentAssistRequest contentAssistRequest = null; - IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition); - ITextRegion valueRegion = node.getStartStructuredDocumentRegion().getRegionAtCharacterOffset(sdRegion.getStartOffset(completionRegion) + completionRegion.getLength()); - if (valueRegion != null && valueRegion.getType() == XMLRegionContext.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, XMLNode nodeAtOffset, XMLNode 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); - addTemplates(contentAssistRequest, TemplateContextTypeIds.TAG); - addTemplates(contentAssistRequest, TemplateContextTypeIds.ALL); - return contentAssistRequest; - } - - protected ContentAssistRequest computeTagCloseProposals(int documentPosition, String matchString, ITextRegion completionRegion, XMLNode nodeAtOffset, XMLNode 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 = (XMLNode) 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, XMLNode nodeAtOffset, XMLNode node) { - ContentAssistRequest contentAssistRequest = null; - IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition); - - if (sdRegion != nodeAtOffset.getFirstStructuredDocumentRegion()) { - //completing the *first* tag in "<tagname1 |<tagname2" - XMLNode actualNode = (XMLNode) 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() == XMLRegionContext.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() != XMLRegionContext.XML_END_TAG_OPEN) { - contentAssistRequest = newContentAssistRequest(node, node.getParentNode(), sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion), completionRegion.getTextLength(), matchString); - addTagNameProposals(contentAssistRequest, getElementPositionForModelQuery(nodeAtOffset)); - } else { - XMLNode actualNode = (XMLNode) 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, XMLNode nodeAtOffset, XMLNode node) { - ContentAssistRequest contentAssistRequest = null; - IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition); - if (sdRegion != nodeAtOffset.getFirstStructuredDocumentRegion()) { - //completing the *first* XML_TAG_OPEN in "<<tagname" - XMLNode actualNode = (XMLNode) 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) { - 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; - int vc = (editMode == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) ? ModelQuery.VALIDITY_STRICT : ModelQuery.VALIDITY_NONE; - modelQuery.getInsertActions(parent, parentDecl, index, ic, vc, 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 XMLNode && (((XMLNode) child).getStartStructuredDocumentRegion() == null || ((XMLNode) child).getEndStructuredDocumentRegion() == null)) - continue; - if (Debug.displayInfo) - System.out.println(rootName + " already present!"); //$NON-NLS-1$ - setErrorMessage(SSEUIPlugin.getResourceString("%18concat", (new Object[]{rootName}))); //$NON-NLS-1$ = "The document element <{0}> is already present." - 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(SSEUIPlugin.getResourceString("%29concat", (new Object[]{rootName, location}))); //$NON-NLS-1$ = "No definition was found for element <{0}> in {1}" - else - setErrorMessage(SSEUIPlugin.getResourceString("%20concat", (new Object[]{rootName}))); //$NON-NLS-1$ = "No definition was found for element <{0}>" - } - } - } 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(SSEUIPlugin.getResourceString("%24concat", (new Object[]{location}))); //$NON-NLS-1$ = "No content model found for {0}." - else - setErrorMessage(SSEUIPlugin.getResourceString("%No_content_model_found_UI_")); //$NON-NLS-1$ = "No content model found" - } - } - - 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() == XMLRegionContext.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; - XMLNode node = (XMLNode) 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() != XMLRegionContext.XML_CONTENT || flatNode.getPrevious().getLastRegion().getType() == XMLRegionContext.XML_TAG_OPEN || flatNode.getPrevious().getLastRegion().getType() == XMLRegionContext.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 == XMLRegionContext.XML_TAG_ATTRIBUTE_EQUALS || regionType == XMLRegionContext.XML_TAG_OPEN || (offset > parent.getStartOffset(aRegion) + aRegion.getTextLength())) { - matchString = ""; //$NON-NLS-1$ - } else if (regionType == XMLRegionContext.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((StructuredTextViewer) 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() == XMLRegionContext.XML_TAG_NAME) { - name = sdRegion.getText(region); - break; - } - } - return name; - } - - /** - * Return the template completion processor to be used - * - AbstractTemplateCompletionProcessor - */ - protected AbstractTemplateCompletionProcessor getTemplateCompletionProcessor() { - return null; - } - - protected List getValidCMNodes(int childPosition, int kindOfAction, List modelQueryActions) { - 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 XMLDocument) && ((XMLDocument) doc).isXMLType(); - } - - // Initialize local settings - protected void init() { - // implement in subclasses - } - - protected boolean isCloseRegion(ITextRegion region) { - String type = region.getType(); - return ((type == XMLRegionContext.XML_PI_CLOSE) || (type == XMLRegionContext.XML_TAG_CLOSE) || (type == XMLRegionContext.XML_EMPTY_TAG_CLOSE) || (type == XMLRegionContext.XML_CDATA_CLOSE) || (type == XMLRegionContext.XML_COMMENT_CLOSE) || (type == XMLRegionContext.XML_ATTLIST_DECL_CLOSE) || (type == XMLRegionContext.XML_ELEMENT_DECL_CLOSE) || (type == XMLRegionContext.XML_DOCTYPE_DECLARATION_CLOSE) || (type == XMLJSPRegionContexts.JSP_CLOSE) || (type == XMLJSPRegionContexts.JSP_COMMENT_CLOSE) || (type == XMLJSPRegionContexts.JSP_DIRECTIVE_CLOSE) || (type == XMLRegionContext.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(XMLNode node) { - return (node != null && node instanceof XMLElement && ((XMLElement) 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 XMLNode) { - if (child.getNodeType() == Node.DOCUMENT_TYPE_NODE) { - xmldoctypeNodePosition = ((XMLNode) 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 XMLNode) { - xmlpiNodePosition = ((XMLNode) child).getEndOffset(); - isAfterXMLPI = (car.getReplacementBeginPosition() >= xmlpiNodePosition); - } - break; - } - } - return isAfterXMLPI; - } - - protected boolean isNameRegion(ITextRegion region) { - String type = region.getType(); - return ((type == XMLRegionContext.XML_TAG_NAME) || (type == XMLJSPRegionContexts.JSP_DIRECTIVE_NAME) || (type == XMLRegionContext.XML_ELEMENT_DECL_NAME) || (type == XMLRegionContext.XML_DOCTYPE_NAME) || (type == XMLRegionContext.XML_ATTLIST_DECL_NAME) || (type == XMLJSPRegionContexts.JSP_ROOT_TAG_NAME) || type == XMLJSPRegionContexts.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() == XMLRegionContext.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() == XMLRegionContext.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.getInstance().getModelManager().getExistingModelForRead(fTextViewer.getDocument()); - try { - if (sModel != null) { - XMLNode xmlNode = (XMLNode) 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, null); - } - - 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/contentassist/AbstractContentModelGenerator.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/AbstractContentModelGenerator.java deleted file mode 100644 index 27b0d7267b..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/AbstractContentModelGenerator.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.contentassist; - -import org.eclipse.wst.common.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.common.contentmodel.CMElementDeclaration; -import org.eclipse.wst.common.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.common.contentmodel.CMNode; -import org.eclipse.wst.common.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/contentassist/AbstractTemplateCompletionProcessor.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/AbstractTemplateCompletionProcessor.java deleted file mode 100644 index e5da49183f..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/AbstractTemplateCompletionProcessor.java +++ /dev/null @@ -1,113 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.contentassist; - -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITextViewer; -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.persistence.TemplateStore; -import org.eclipse.swt.graphics.Image; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages; - - -/** - * A completion processor that computes template proposals and works with - * AbstractContentAssistProcessor - */ -abstract public class AbstractTemplateCompletionProcessor extends TemplateCompletionProcessor { - private String fContextTypeId = null; - - /* (non-Javadoc) - * @see org.eclipse.jface.text.templates.TemplateCompletionProcessor#createProposal(org.eclipse.jface.text.templates.Template, org.eclipse.jface.text.templates.TemplateContext, org.eclipse.jface.text.IRegion, int) - */ - protected ICompletionProposal createProposal(Template template, TemplateContext context, IRegion region, int relevance) { - // CustomTemplateProposal turns the additional information to content - // fit for HTML - return new CustomTemplateProposal(template, context, region, getImage(template), relevance); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.templates.TemplateCompletionProcessor#getContextType(org.eclipse.jface.text.ITextViewer, - * org.eclipse.jface.text.IRegion) - */ - protected TemplateContextType getContextType(ITextViewer viewer, IRegion region) { - // another completion processor should have already set the current - // context type id, so just use that value instead of trying to - // determine - // the context type again - if (getTemplateContextRegistry() != null) { - return getTemplateContextRegistry().getContextType(getContextTypeId()); - } - return null; - } - - protected String getContextTypeId() { - return fContextTypeId; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.templates.TemplateCompletionProcessor#getImage(org.eclipse.jface.text.templates.Template) - */ - protected Image getImage(Template template) { - // just return the same image for now - return XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_MACRO); - } - - /** - * Return the template context registry to use with this completion - * processor - * - * @return ContextTypeRegistry - */ - abstract protected ContextTypeRegistry getTemplateContextRegistry(); - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.templates.TemplateCompletionProcessor#getTemplates(java.lang.String) - */ - protected Template[] getTemplates(String contextTypeId) { - if (getTemplateStore() != null) { - return getTemplateStore().getTemplates(contextTypeId); - } - return null; - } - - /** - * Return the template store to use with this template completion - * processor - * - * @return TemplateStore - */ - abstract protected TemplateStore getTemplateStore(); - - /** - * Set the current context type to use when determining completion - * proposals. - * - * @param contextTypeId - */ - public void setContextType(String contextTypeId) { - fContextTypeId = contextTypeId; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/AttributeContextInformation.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/AttributeContextInformation.java deleted file mode 100644 index f2c29631b9..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/AttributeContextInformation.java +++ /dev/null @@ -1,113 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.contentassist; - -import java.util.HashMap; - -import org.eclipse.jface.text.contentassist.IContextInformation; -import org.eclipse.swt.graphics.Image; -import org.eclipse.wst.sse.ui.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 { - 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; - - /** - * 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); - - 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/contentassist/AttributeContextInformationPresenter.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/AttributeContextInformationPresenter.java deleted file mode 100644 index ab19b30c7e..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/AttributeContextInformationPresenter.java +++ /dev/null @@ -1,112 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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.text.IStructuredDocument; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.text.ITextRegion; -import org.eclipse.wst.sse.core.text.ITextRegionList; -import org.eclipse.wst.xml.core.document.XMLNode; -import org.eclipse.wst.xml.core.parser.XMLRegionContext; - - -/** - * 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; - - /** - * @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... - IStructuredDocumentRegion startRegion = fModelUtil.getXMLNode(fDocumentPosition).getStartStructuredDocumentRegion(); - int start = startRegion.getStartOffset(); - int end = startRegion.getEndOffset(); - return documentPosition < end && documentPosition > start + 1; - } - - /** - * @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 - XMLNode 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() == XMLRegionContext.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/contentassist/AttributeContextInformationProvider.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/AttributeContextInformationProvider.java deleted file mode 100644 index bf2e0eb093..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/AttributeContextInformationProvider.java +++ /dev/null @@ -1,208 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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.common.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.common.contentmodel.CMContent; -import org.eclipse.wst.common.contentmodel.CMElementDeclaration; -import org.eclipse.wst.common.contentmodel.CMGroup; -import org.eclipse.wst.common.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.common.contentmodel.CMNode; -import org.eclipse.wst.common.contentmodel.CMNodeList; -import org.eclipse.wst.sse.core.text.IStructuredDocument; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.text.ITextRegionList; -import org.eclipse.wst.xml.core.document.XMLNode; -import org.eclipse.wst.xml.core.parser.XMLRegionContext; -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; - - XMLNode 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(XMLNode node) { - IContextInformation[] results = EMPTY_CONTEXT_INFO; - CMElementDeclaration decl = fModelUtil.getModelQuery().getCMElementDeclaration((Element) node); - if (decl != null) { - CMNamedNodeMap attributes = decl.getAttributes(); - - 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("")) //$NON-NLS-1$ - return new IContextInformation[]{new AttributeContextInformation(attrContextString, attrInfo.toString(), attrPosMap)}; - } - return results; - } - - /** - * @param node - - */ - IContextInformation[] getInfoForText(XMLNode 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("")) //$NON-NLS-1$ - 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() == XMLRegionContext.XML_END_TAG_OPEN; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/ContentAssistRequest.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/ContentAssistRequest.java deleted file mode 100644 index c674d7d475..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/ContentAssistRequest.java +++ /dev/null @@ -1,273 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.text.ITextRegion; -import org.eclipse.wst.sse.core.text.ITextRegionCollection; -import org.eclipse.wst.sse.core.util.StringUtils; -import org.eclipse.wst.sse.ui.preferences.PreferenceManager; -import org.w3c.dom.Node; - - -public class ContentAssistRequest { - protected IStructuredDocumentRegion documentRegion = null; - - - protected PreferenceManager fPreferenceManager = 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, PreferenceManager preferencesManager) { - super(); - setNode(node); - setParent(parent); - setDocumentRegion(documentRegion); - setRegion(completionRegion); - setMatchString(filter); - setReplacementBeginPosition(begin); - setReplacementLength(length); - fPreferenceManager = preferencesManager; - } - - 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; - } - - /** - * - * @return com.ibm.sed.structuredDocument.core.IStructuredDocumentRegion - */ - 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; - } - - public PreferenceManager getPreferenceManager() { - return fPreferenceManager; - } - - /** - * - * @return java.util.List - */ - public java.util.List getProposals() { - return proposals; - } - - /** - * - * @return com.ibm.sed.structuredDocument.core.ITextRegion - */ - 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 - * com.ibm.sed.structuredDocument.ITextRegion - */ - 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/contentassist/ContextInfoModelUtil.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/ContextInfoModelUtil.java deleted file mode 100644 index 1d85817bdb..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/ContextInfoModelUtil.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.contentassist; - -import org.eclipse.wst.common.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.sse.core.IModelManager; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.text.IStructuredDocument; -import org.eclipse.wst.xml.core.document.XMLModel; -import org.eclipse.wst.xml.core.document.XMLNode; -import org.eclipse.wst.xml.core.modelquery.ModelQueryUtil; - - -/** - * @author pavery - */ -public class ContextInfoModelUtil { - IStructuredDocument fDocument = null; - private final String SSE_MODEL_ID = "org.eclipse.wst.sse.core"; //$NON-NLS-1$ - - ContextInfoModelUtil(IStructuredDocument doc) { - fDocument = doc; - } - - public IStructuredDocument getDocument() { - return fDocument; - } - - public IModelManager getModelManager() { - return StructuredModelManager.getInstance().getModelManager(); - } - - public ModelQuery getModelQuery() { - ModelQuery mq = null; - - XMLModel xmlModel = (XMLModel) getModelManager().getExistingModelForRead(getDocument()); - mq = ModelQueryUtil.getModelQuery(xmlModel.getDocument()); - xmlModel.releaseFromRead(); - - return mq; - } - - public XMLNode getXMLNode(int offset) { - XMLModel xmlModel = (XMLModel) getModelManager().getExistingModelForRead(getDocument()); - XMLNode xmlNode = (XMLNode) xmlModel.getIndexedRegion(offset); - xmlModel.releaseFromRead(); - return xmlNode; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/CustomTemplateProposal.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/CustomTemplateProposal.java deleted file mode 100644 index 27b24fe59a..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/CustomTemplateProposal.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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.util.StringUtils; -import org.eclipse.wst.sse.ui.contentassist.IRelevanceCompletionProposal; - - -/** - * Purpose of this class is to make the additional proposal info into content - * fit for an HTML viewer (by escaping characters) - */ -public class CustomTemplateProposal extends TemplateProposal implements IRelevanceCompletionProposal { - - /** - * @param template - * @param context - * @param region - * @param image - */ - public CustomTemplateProposal(Template template, TemplateContext context, IRegion region, Image image) { - super(template, context, region, image); - } - - /** - * @param template - * @param context - * @param region - * @param image - * @param relevance - */ - public CustomTemplateProposal(Template template, TemplateContext context, IRegion region, Image image, int relevance) { - super(template, context, region, image, relevance); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getAdditionalProposalInfo() - */ - 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/contentassist/NoRegionContentAssistProcessor.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/NoRegionContentAssistProcessor.java deleted file mode 100644 index d3ca3e9049..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/NoRegionContentAssistProcessor.java +++ /dev/null @@ -1,263 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.contentassist; - - - -import java.util.HashMap; -import java.util.Iterator; - -import org.eclipse.core.resources.IResource; -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.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.ui.IReleasable; -import org.eclipse.wst.sse.ui.StructuredTextViewer; -import org.eclipse.wst.sse.ui.contentassist.IResourceDependentProcessor; -import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils; -import org.eclipse.wst.xml.core.parser.XMLRegionContext; -import org.eclipse.wst.xml.core.text.rules.StructuredTextPartitionerForXML; - - -/** - * 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, IResourceDependentProcessor, IReleasable { - - protected char completionProposalAutoActivationCharacters[] = null; - protected char contextInformationAutoActivationCharacters[] = null; - - private final ICompletionProposal[] EMPTY_PROPOSAL_SET = new ICompletionProposal[0]; - protected String fErrorMessage = null; - protected HashMap fNameToProcessorMap = null; - protected HashMap fPartitionToProcessorMap = null; - protected IResource fResource = null; - - public NoRegionContentAssistProcessor() { - super(); - fPartitionToProcessorMap = new HashMap(); - fNameToProcessorMap = new HashMap(); - initNameToProcessorMap(); - initPartitionToProcessorMap(); - - } - - /** - * 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; - } - - /** - * 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((StructuredTextViewer) viewer, documentOffset); - if (sdRegion != null) { - String currentRegionType = sdRegion.getType(); - //System.out.println("current region type is >> " + - // currentRegionType); - if (currentRegionType == XMLRegionContext.UNDEFINED) { - IStructuredDocumentRegion sdPrev = sdRegion.getPrevious(); - if (sdPrev != null) { - String prevRegionType = sdPrev.getType(); - //System.out.println("previous region type is >> " + - // prevRegionType); - } - } - } - // 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) fPartitionToProcessorMap.get(prevPartitionType); - } - return p; - } - - /** - * Necessary for certain content assist processors (such as - * JSPJavaContentAssistProcessor). This gets set in - * StructuredTextViewerConfiguration. - * - */ - public void initialize(IResource resource) { - fResource = resource; - setResourceOnProcessors(resource); - } - - /** - * Inits map for extra ContentAssistProcessors (useBean, get/setProperty) - */ - protected void initNameToProcessorMap() { - } - - /** - * Adds all relevent ContentAssistProcessors to the partition to processor - * map (just XML here) - */ - protected void initPartitionToProcessorMap() { - XMLContentAssistProcessor xmlProcessor = new XMLContentAssistProcessor(); - fPartitionToProcessorMap.put(StructuredTextPartitionerForXML.ST_DEFAULT_XML, 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); - } - - private void setResourceOnMap(IResource resource, HashMap map) { - if (!map.isEmpty()) { - Iterator keys = map.keySet().iterator(); - Object o = null; - while (keys.hasNext()) { - o = fPartitionToProcessorMap.get(keys.next()); - if (o instanceof IResourceDependentProcessor) - ((IResourceDependentProcessor) o).initialize(resource); - } - } - } - - /** - * @param resource - */ - private void setResourceOnProcessors(IResource resource) { - setResourceOnMap(resource, fPartitionToProcessorMap); - setResourceOnMap(resource, fNameToProcessorMap); - } - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/NonValidatingModelQueryAction.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/NonValidatingModelQueryAction.java deleted file mode 100644 index 1bdfb81983..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/NonValidatingModelQueryAction.java +++ /dev/null @@ -1,159 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.contentassist; - - - -import org.eclipse.wst.common.contentmodel.CMNode; - -public class NonValidatingModelQueryAction implements org.eclipse.wst.common.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.common.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.common.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/contentassist/ProposalComparator.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/ProposalComparator.java deleted file mode 100644 index 3a4bf4d69a..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/ProposalComparator.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.contentassist; - - - -import java.util.Comparator; - -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.wst.sse.ui.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 = java.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/contentassist/SimpleCMElementDeclaration.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/SimpleCMElementDeclaration.java deleted file mode 100644 index 42dce88174..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/SimpleCMElementDeclaration.java +++ /dev/null @@ -1,170 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.contentassist; - - - -public class SimpleCMElementDeclaration implements org.eclipse.wst.common.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.common.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.common.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.common.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.common.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/contentassist/SourceEditorImageHelper.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/SourceEditorImageHelper.java deleted file mode 100644 index bd9306b2ef..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/SourceEditorImageHelper.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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/contentassist/XMLContentAssistProcessor.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/XMLContentAssistProcessor.java deleted file mode 100644 index b3f095c55e..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/XMLContentAssistProcessor.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.contentassist; - -import org.eclipse.core.resources.IResource; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.util.IPropertyChangeListener; -import org.eclipse.jface.util.PropertyChangeEvent; -import org.eclipse.wst.common.encoding.content.IContentTypeIdentifier; -import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; -import org.eclipse.wst.sse.ui.preferences.CommonEditorPreferenceNames; -import org.eclipse.wst.sse.ui.preferences.PreferenceKeyGenerator; - -public class XMLContentAssistProcessor extends AbstractContentAssistProcessor implements IPropertyChangeListener { - - protected IPreferenceStore fPreferenceStore = null; - protected IResource fResource = null; - protected AbstractTemplateCompletionProcessor fTemplateProcessor = null; - - public XMLContentAssistProcessor() { - super(); - } - - protected IPreferenceStore getPreferenceStore() { - if (fPreferenceStore == null) - fPreferenceStore = SSEUIPlugin.getDefault().getPreferenceStore(); - //fPreferenceStore = - // CommonPreferencesPlugin.getDefault().getPreferenceStore(ContentType.ContentTypeID_XML); - - return fPreferenceStore; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.xml.ui.contentassist.AbstractContentAssistProcessor#getTemplateCompletionProcessor() - */ - protected AbstractTemplateCompletionProcessor 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(CommonEditorPreferenceNames.AUTO_PROPOSE) == 0 || property.compareTo(CommonEditorPreferenceNames.AUTO_PROPOSE_CODE) == 0) { - reinit(); - } - } - - protected void reinit() { - String key = PreferenceKeyGenerator.generateKey(CommonEditorPreferenceNames.AUTO_PROPOSE, IContentTypeIdentifier.ContentTypeID_SSEXML); - boolean doAuto = getPreferenceStore().getBoolean(key); - if (doAuto) { - key = PreferenceKeyGenerator.generateKey(CommonEditorPreferenceNames.AUTO_PROPOSE_CODE, IContentTypeIdentifier.ContentTypeID_SSEXML); - 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/contentassist/XMLContentAssistUtilities.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/XMLContentAssistUtilities.java deleted file mode 100644 index 3bac2eda6f..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/XMLContentAssistUtilities.java +++ /dev/null @@ -1,469 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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.wst.sse.core.IndexedRegion; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.text.ITextRegion; -import org.eclipse.wst.sse.core.text.ITextRegionContainer; -import org.eclipse.wst.sse.core.util.ScriptLanguageKeys; -import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; -import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils; -import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal; -import org.eclipse.wst.xml.core.document.XMLElement; -import org.eclipse.wst.xml.core.document.XMLNode; -import org.eclipse.wst.xml.core.jsp.model.parser.temp.XMLJSPRegionContexts; -import org.eclipse.wst.xml.core.parser.XMLRegionContext; -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 { - 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 path in realation to com.ibm.sed. - * structured. contentassist. xmlSourceEditorImageHelper - * @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; - XMLNode xnode = null; - String tagName = ""; //$NON-NLS-1$ - if (indexedNode instanceof XMLNode) { - xnode = ((XMLNode) indexedNode); - // it's ended already... - if (xnode.getEndStructuredDocumentRegion() != null) - return null; - XMLNode openNode = null; - if (!xnode.getNodeName().equalsIgnoreCase(parentTagName)) - openNode = (XMLNode) xnode.getParentNode(); - if (openNode != null) { - if (openNode instanceof XMLElement) { - isJSPTag = ((XMLElement) 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 = proposedText = "</" + tagName; // ResourceHandler - // wants text - // w/out - // ending '>' - // //$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("</")) //$NON-NLS-1$ - proposedText = tagName; - else if (last2chars.endsWith("<")) //$NON-NLS-1$ - proposedText = "/" + tagName; //$NON-NLS-1$ - } - - // create proposal - p = new CustomCompletionProposal(proposedText + ">", //$NON-NLS-1$ - documentPosition, 0, proposedText.length() + 1, XMLEditorPluginImageHelper.getInstance().getImage(imagePath), //$NON-NLS-1$ - SSEUIPlugin.getResourceString("%15concat", (new Object[]{proposedText})), //$NON-NLS-1$ = "End with '{0}>'" - null, null, XMLRelevanceConstants.R_END_TAG); - } else if (!hasEndTag && isJSPTag) { - - // create appropriate close tag text - String proposedText = proposedText = "%"; // ResourceHandler wants - // text w/out ending '>' - // //$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("<%")) //$NON-NLS-1$ - 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), //$NON-NLS-1$ - SSEUIPlugin.getResourceString("%15concat", (new Object[]{proposedText})), //$NON-NLS-1$ = "End with '{0}>'" - 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 image path in realation to com.ibm.sed. - * structured. contentassist. xmlSourceEditorImageHelper - * @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; - XMLNode xnode = null; - String tagName = ""; //$NON-NLS-1$ - if (indexedNode instanceof XMLNode) { - xnode = ((XMLNode) indexedNode); - // it's ended already... - if (xnode.getEndStructuredDocumentRegion() != null) - return null; - XMLNode styleNode = null; - if (!xnode.getNodeName().equalsIgnoreCase(parentTagName)) - styleNode = (XMLNode) 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 = proposedText = "</" + tagName; // ResourceHandler - // wants text - // w/out - // ending '>' - // //$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("</")) //$NON-NLS-1$ - proposedText = tagName; - else if (last2chars.endsWith("<")) //$NON-NLS-1$ - proposedText = "/" + tagName; //$NON-NLS-1$ - } - - // create proposal - p = new CustomCompletionProposal(proposedText + ">", //$NON-NLS-1$ - documentPosition, 0, proposedText.length() + 1, XMLEditorPluginImageHelper.getInstance().getImage(imagePath), //$NON-NLS-1$ - SSEUIPlugin.getResourceString("%15concat", (new Object[]{proposedText})), //$NON-NLS-1$ = "End with '{0}>'" - 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 - * - * @param fn - * @return boolean - */ - public static boolean isJSPCloseDelimiter(IStructuredDocumentRegion fn) { - if (fn == null) - return false; - return isJSPCloseDelimiter(fn.getType()); - } - - public static boolean isJSPCloseDelimiter(String type) { - if (type == null) - return false; - return (type == XMLJSPRegionContexts.JSP_CLOSE || type == XMLRegionContext.XML_TAG_CLOSE); - } - - /** - * Tells you if the flatnode is the JSP region <%%>, <%=%>, <%!%> - * - * @param fn - * @return boolean - */ - public static boolean isJSPDelimiter(IStructuredDocumentRegion fn) { - boolean isDelimiter = false; - String type = fn.getType(); - if (type != null) { - isDelimiter = isJSPDelimiter(type); - } - return isDelimiter; - } - - public static boolean isJSPDelimiter(String type) { - if (type == null) - return false; - return (isJSPOpenDelimiter(type) || isJSPCloseDelimiter(type)); - } - - /** - * Tells you if the flatnode is <%, <%=, or <%! - * - * @param fn - * @return boolean - */ - public static boolean isJSPOpenDelimiter(IStructuredDocumentRegion fn) { - if (fn == null) - return false; - return isJSPOpenDelimiter(fn.getType()); - } - - public static boolean isJSPOpenDelimiter(String type) { - if (type == null) - return false; - return (type == XMLJSPRegionContexts.JSP_SCRIPTLET_OPEN || type == XMLJSPRegionContexts.JSP_DECLARATION_OPEN || type == XMLJSPRegionContexts.JSP_EXPRESSION_OPEN); - } - - /** - * Tells you if the flatnode is the <jsp:scriptlet>, <jsp:expression>, or - * <jsp:declaration>tag - * - * @param fn - * @return boolean - */ - 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() == XMLRegionContext.XML_TAG_NAME) { - regionText = fn.getText(temp); - if (regionText.equalsIgnoreCase("jsp:scriptlet") || regionText.equalsIgnoreCase("jsp:expression") || regionText.equalsIgnoreCase("jsp:declaration")) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - 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/contentassist/XMLContentModelGenerator.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/XMLContentModelGenerator.java deleted file mode 100644 index 22cdb40a40..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/XMLContentModelGenerator.java +++ /dev/null @@ -1,126 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.contentassist; - - - -import org.eclipse.wst.common.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.common.contentmodel.CMDataType; -import org.eclipse.wst.common.contentmodel.CMElementDeclaration; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.xml.core.document.XMLNode; -import org.eclipse.wst.xml.core.jsp.model.parser.temp.XMLJSPRegionContexts; -import org.w3c.dom.Node; - - -public class XMLContentModelGenerator extends AbstractContentModelGenerator { - - /** - * 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(); - // = 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) { - buffer.append(attrType.getImpliedValue()); - } - // otherwise, if an enumerated list of values exists, use the - // first value - else if (attrType.getEnumeratedValues() != null && attrType.getEnumeratedValues().length > 0) { - buffer.append(attrType.getEnumeratedValues()[0]); - } - } - buffer.append("\""); //$NON-NLS-1$ - 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 XMLNode) { - IStructuredDocumentRegion node = ((XMLNode) notATagNode).getStartStructuredDocumentRegion(); - if (node != null && node.getNumberOfRegions() > 1 && node.getRegions().get(0).getType() == XMLJSPRegionContexts.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/contentassist/XMLRelevanceConstants.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/XMLRelevanceConstants.java deleted file mode 100644 index 0ac5df3932..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/XMLRelevanceConstants.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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_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/contentassist/XMLTemplateCompletionProcessor.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/XMLTemplateCompletionProcessor.java deleted file mode 100644 index c05d9d3f1f..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/XMLTemplateCompletionProcessor.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.contentassist; - -import org.eclipse.jface.text.templates.ContextTypeRegistry; -import org.eclipse.jface.text.templates.persistence.TemplateStore; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.templates.TemplateContextTypeXML; - - -/** - * Completion processor for XML Templates - */ -public class XMLTemplateCompletionProcessor extends AbstractTemplateCompletionProcessor { - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.xml.ui.contentassist.AbstractTemplateCompletionProcessor#getContextTypeId() - */ - protected String getContextTypeId() { - // turn the context type id into content type specific - return TemplateContextTypeXML.generateContextTypeId(super.getContextTypeId()); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.xml.ui.contentassist.AbstractTemplateCompletionProcessor#getTemplateContextRegistry() - */ - protected ContextTypeRegistry getTemplateContextRegistry() { - return getXMLEditorPlugin().getTemplateContextRegistry(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.xml.ui.contentassist.AbstractTemplateCompletionProcessor#getTemplateStore() - */ - protected TemplateStore getTemplateStore() { - return getXMLEditorPlugin().getTemplateStore(); - } - - /** - * Returns the XMLUIPlugin - * - * @return XMLUIPlugin - */ - private XMLUIPlugin getXMLEditorPlugin() { - return XMLUIPlugin.getDefault(); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dialogs/EditAttributeDialog.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dialogs/EditAttributeDialog.java deleted file mode 100644 index 8226a4fc9c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dialogs/EditAttributeDialog.java +++ /dev/null @@ -1,170 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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.help.WorkbenchHelp; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.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); - WorkbenchHelp.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(XMLUIPlugin.getResourceString("%_UI_LABEL_NAME_COLON")); //$NON-NLS-1$ - - 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(XMLUIPlugin.getResourceString("%_UI_LABEL_VALUE_COLON")); //$NON-NLS-1$ - - 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(XMLUIPlugin.getResourceString("%error_message_goes_here")); //$NON-NLS-1$ - 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 = XMLUIPlugin.getResourceString("%_ERROR_XML_ATTRIBUTE_ALREADY_EXISTS"); //$NON-NLS-1$ - } 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/dialogs/EditDoctypeDialog.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dialogs/EditDoctypeDialog.java deleted file mode 100644 index 443f85bc5c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dialogs/EditDoctypeDialog.java +++ /dev/null @@ -1,237 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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.help.WorkbenchHelp; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.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); - WorkbenchHelp.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(XMLUIPlugin.getResourceString("%_UI_LABEL_ROOT_ELEMENT_NAME_COLON")); //$NON-NLS-1$ - - rootElementNameField = new Text(composite, SWT.SINGLE | SWT.BORDER); - WorkbenchHelp.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(XMLUIPlugin.getResourceString("%_UI_LABEL_PUBLIC_ID_COLON")); //$NON-NLS-1$ - - publicIdField = new Text(composite, SWT.SINGLE | SWT.BORDER); - WorkbenchHelp.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); - WorkbenchHelp.setHelp(publicIdBrowseButton, XMLCommonUIContextIds.XCUI_DOCTYPE_PUBLIC_BROWSE); - publicIdBrowseButton.setText(XMLUIPlugin.getResourceString("%_UI_LABEL_BROWSE")); //$NON-NLS-1$ - publicIdBrowseButton.addSelectionListener(selectionListener); - - // row 3 - Label systemIdLabel = new Label(composite, SWT.NONE); - systemIdLabel.setText(XMLUIPlugin.getResourceString("%_UI_LABEL_SYSTEM_ID_COLON")); //$NON-NLS-1$ - - systemIdField = new Text(composite, SWT.SINGLE | SWT.BORDER); - WorkbenchHelp.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); - WorkbenchHelp.setHelp(systemIdBrowseButton, XMLCommonUIContextIds.XCUI_DOCTYPE_SYSTEM_BROWSE); - systemIdBrowseButton.setText(XMLUIPlugin.getResourceString("%_UI_LABEL_BROWSE")); //$NON-NLS-1$ - 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); - - 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 = XMLUIPlugin.getResourceString("%_UI_WARNING_SYSTEM_ID_MUST_BE_SPECIFIED"); //$NON-NLS-1$ - } else if (getModelValue(rootElementNameField.getText()) == null) { - errorMessage = XMLUIPlugin.getResourceString("%_UI_WARNING_ROOT_ELEMENT_MUST_BE_SPECIFIED"); //$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/dialogs/EditElementDialog.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dialogs/EditElementDialog.java deleted file mode 100644 index d196e129ac..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dialogs/EditElementDialog.java +++ /dev/null @@ -1,143 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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.help.WorkbenchHelp; -import org.eclipse.wst.xml.core.NameValidator; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.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); - WorkbenchHelp.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(XMLUIPlugin.getResourceString("%_UI_LABEL_ELEMENT_NAME")); //$NON-NLS-1$ - - 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(XMLUIPlugin.getResourceString("%error_message_goes_here")); //$NON-NLS-1$ - 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 = XMLUIPlugin.getResourceString("%_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/dialogs/EditEntityHelper.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dialogs/EditEntityHelper.java deleted file mode 100644 index 8b05e2492e..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dialogs/EditEntityHelper.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.uriresolver.XMLCatalogEntry; -import org.eclipse.wst.xml.uriresolver.util.URIHelper; - -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(XMLUIPlugin.getResourceString("%_UI_LABEL_SELECT_XML_CATALOG_ENTRY")); //$NON-NLS-1$ - 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, XMLCatalogEntry.SYSTEM); - dialog.create(); - dialog.getShell().setText(XMLUIPlugin.getResourceString("%_UI_LABEL_SPECIFY_SYSTEM_ID")); //$NON-NLS-1$ - 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/dialogs/EditNamespaceInfoDialog.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dialogs/EditNamespaceInfoDialog.java deleted file mode 100644 index db03c67d03..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dialogs/EditNamespaceInfoDialog.java +++ /dev/null @@ -1,250 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.dialogs; - -import java.util.List; - -import org.eclipse.core.resources.IFile; -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.wst.common.contentmodel.CMDocument; -import org.eclipse.wst.common.contentmodel.CMPlugin; -import org.eclipse.wst.common.contentmodel.util.NamespaceInfo; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.uriresolver.util.IdResolver; -import org.eclipse.wst.xml.uriresolver.util.IdResolverImpl; -import org.eclipse.wst.xml.uriresolver.util.URIHelper; - -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 info; - 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.info = info; - } - - protected void buttonPressed(int buttonId) { - if (buttonId == IDialogConstants.OK_ID) { - info.uri = uriField.getText(); - info.prefix = prefixField.getText(); - info.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 dialogArea = (Composite) super.createDialogArea(parent); - //TODO... SSE port - //WorkbenchHelp.setHelp(dialogArea, - // XMLCommonUIContextIds.XCUI_NAMESPACE_DIALOG); - - Composite composite = new Composite(dialogArea, 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(XMLUIPlugin.getResourceString("%_UI_LABEL_NAMESPACE_NAME_COLON")); //$NON-NLS-1$ - - uriField = new Text(composite, SWT.SINGLE | SWT.BORDER); - gd = new GridData(GridData.FILL_HORIZONTAL); - gd.grabExcessHorizontalSpace = true; - uriField.setLayoutData(gd); - uriField.setText(getDisplayValue(info.uri)); - uriField.addModifyListener(modifyListener); - uriField.setEnabled(info.getProperty("uri-readOnly") == null); //$NON-NLS-1$ - - Label placeHolder1 = new Label(composite, SWT.NONE); - - // row 2 - // - Label prefixLabel = new Label(composite, SWT.NONE); - prefixLabel.setText(XMLUIPlugin.getResourceString("%_UI_LABEL_PREFIX_COLON")); //$NON-NLS-1$ - - prefixField = new Text(composite, SWT.SINGLE | SWT.BORDER); - gd = new GridData(GridData.FILL_HORIZONTAL); - gd.grabExcessHorizontalSpace = true; - prefixField.setLayoutData(gd); - prefixField.setText(getDisplayValue(info.prefix)); - prefixField.addModifyListener(modifyListener); - prefixField.setEnabled(info.getProperty("prefix-readOnly") == null); //$NON-NLS-1$ - Label placeHolder2 = new Label(composite, SWT.NONE); - - // row 3 - // - Label locationHintLabel = new Label(composite, SWT.NONE); - locationHintLabel.setText(XMLUIPlugin.getResourceString("%_UI_LABEL_LOCATION_HINT_COLON")); //$NON-NLS-1$ - - locationHintField = new Text(composite, SWT.SINGLE | SWT.BORDER); - gd = new GridData(GridData.FILL_HORIZONTAL); - gd.grabExcessHorizontalSpace = true; - locationHintField.setLayoutData(gd); - locationHintField.setText(getDisplayValue(info.locationHint)); - locationHintField.addModifyListener(modifyListener); - locationHintField.setEnabled(info.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(XMLUIPlugin.getResourceString("%_UI_LABEL_BROWSE")); //$NON-NLS-1$ - browseButton.addSelectionListener(selectionListener); - browseButton.setEnabled(locationHintField.getEnabled()); - - // error message - errorMessageLabel = new Label(dialogArea, SWT.NONE); - errorMessageLabel.setText(XMLUIPlugin.getResourceString("%error_message_goes_here")); //$NON-NLS-1$ - errorMessageLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - 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$ - } - - protected void performBrowse() { - String[] extensions = {".xsd"}; //$NON-NLS-1$ - SelectFileOrXMLCatalogIdDialog dialog = new SelectFileOrXMLCatalogIdDialog(getShell(), extensions); - dialog.create(); - dialog.getShell().setText(XMLUIPlugin.getResourceString("%_UI_LABEL_SELECT_FILE")); //$NON-NLS-1$ - 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) { - 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); - IdResolver resolver = new IdResolverImpl(null); - grammarURI = resolver.resolveId(id, id); - } - - try { - CMDocument document = CMPlugin.getInstance().createCMDocument(grammarURI, "xsd"); //$NON-NLS-1$ - List namespaceInfoList = (List) document.getProperty("http://org.eclipse.wst/cm/properties/namespaceInfo"); //$NON-NLS-1$ - 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) { - } - } - } - - 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/dialogs/EditProcessingInstructionDialog.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dialogs/EditProcessingInstructionDialog.java deleted file mode 100644 index cda35f9309..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dialogs/EditProcessingInstructionDialog.java +++ /dev/null @@ -1,120 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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.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.help.WorkbenchHelp; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.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) { - Button okButton = 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); - WorkbenchHelp.setHelp(dialogArea, XMLCommonUIContextIds.XCUI_PROCESSING_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)); - - - GridData gd = new GridData(GridData.FILL_HORIZONTAL); - gd.widthHint = 250; - - Label targetLabel = new Label(composite, SWT.NONE); - targetLabel.setText(XMLUIPlugin.getResourceString("%_UI_LABEL_TARGET_COLON")); //$NON-NLS-1$ - - targetField = new Text(composite, SWT.SINGLE | SWT.BORDER); - targetField.setLayoutData(gd); - targetField.setText(getDisplayValue(target)); - - Label dataLabel = new Label(composite, SWT.NONE); - dataLabel.setText(XMLUIPlugin.getResourceString("%_UI_LABEL_DATA_COLON")); //$NON-NLS-1$ - - dataField = new Text(composite, SWT.SINGLE | SWT.BORDER); - dataField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - dataField.setText(getDisplayValue(data)); - - return dialogArea; - } - - 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/dialogs/EditSchemaInfoDialog.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dialogs/EditSchemaInfoDialog.java deleted file mode 100644 index 8f6096ef5d..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dialogs/EditSchemaInfoDialog.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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.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.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.nsedit.CommonEditNamespacesDialog; - -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) { - Button okButton = 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); - CommonEditNamespacesDialog editNamespacesControl = new CommonEditNamespacesDialog(dialogArea, resourceLocation, XMLUIPlugin.getResourceString("%_UI_NAMESPACE_DECLARATIONS"), false, true); //$NON-NLS-1$ - 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/dialogs/NamespaceInfoErrorHelper.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dialogs/NamespaceInfoErrorHelper.java deleted file mode 100644 index 9101f2fd8b..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dialogs/NamespaceInfoErrorHelper.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.dialogs; - -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.wst.common.contentmodel.util.DOMNamespaceInfoManager; -import org.eclipse.wst.common.contentmodel.util.NamespaceInfo; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.uriresolver.util.IdResolver; -import org.eclipse.wst.xml.uriresolver.util.URIHelper; - -public class NamespaceInfoErrorHelper { - - protected List errorList; - - public NamespaceInfoErrorHelper() { - } - - public String computeErrorMessage(List namespaceInfoList, IdResolver 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 = XMLUIPlugin.getResourceString("%_UI_WARNING_MORE_THAN_ONE_NS_WITH_NAME") + "'" + nsInfo.uri + "'"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } else { - result = XMLUIPlugin.getResourceString("%_UI_WARNING_MORE_THAN_ONE_NS_WITHOUT_NAME"); //$NON-NLS-1$ - } - 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 = XMLUIPlugin.getResourceString("%_UI_WARNING_MORE_THAN_ONE_NS_WITH_PREFIX") + "'" + nsInfo.prefix + "'"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - break; - } else { - result = XMLUIPlugin.getResourceString("%_UI_WARNING_MORE_THAN_ONE_NS_WITHOUT_PREFIX"); //$NON-NLS-1$ - break; - } - } else { - prefixTable.put(key, nsInfo); - } - - if (nsInfo.locationHint != null && idResolver != null) { - String grammarURI = idResolver.resolveId(nsInfo.locationHint, nsInfo.locationHint); - if (!URIHelper.isReadableURI(grammarURI, false)) { - result = XMLUIPlugin.getResourceString("%_UI_WARNING_SCHEMA_CAN_NOT_BE_LOCATED") + " '" + nsInfo.locationHint + "'"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - break; - } - } - if (idResolver != null && nsInfo.locationHint == null && !nsInfo.uri.equals(DOMNamespaceInfoManager.XSI_URI)) { - result = XMLUIPlugin.getResourceString("%_UI_WARNING_LOCATION_HINT_NOT_SPECIFIED") + " '" + nsInfo.uri + "'"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - break; - } - } else { - if (nsInfo.prefix != null) { - result = XMLUIPlugin.getResourceString("%_UI_WARNING_NAMESPACE_NAME_NOT_SPECIFIED") + " '" + nsInfo.prefix + "'"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - 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 = XMLUIPlugin.getResourceString("%_UI_WARNING_PREFIX_NOT_SPECIFIED") + " '" + nsInfo.uri + "'"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - break; - } - } - } - - return result; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dialogs/NamespaceInfoTable.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dialogs/NamespaceInfoTable.java deleted file mode 100644 index bcd71517c5..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dialogs/NamespaceInfoTable.java +++ /dev/null @@ -1,390 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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.common.contentmodel.util.NamespaceInfo; -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 = XMLUIPlugin.getResourceString("%_UI_NO_NAMESPACE_NAME"); //$NON-NLS-1$ - break; - } - case 1 : { - result = XMLUIPlugin.getResourceString("%_UI_NO_PREFIX"); //$NON-NLS-1$ - 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 = XMLUIPlugin.getResourceString("%_UI_LABEL_LOCATION_HINT"); //$NON-NLS-1$ - protected static final String NAMESPACE_URI = XMLUIPlugin.getResourceString("%_UI_LABEL_NAMESPACE_NAME"); //$NON-NLS-1$ - protected static final String PREFIX = XMLUIPlugin.getResourceString("%_UI_LABEL_PREFIX"); //$NON-NLS-1$ - 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(XMLUIPlugin.getResourceString("%_UI_LABEL_XML_SCHEMA_INFORMATION")); //$NON-NLS-1$ - 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(XMLUIPlugin.getResourceString("%_UI_BUTTON_NEW")); //$NON-NLS-1$ - newButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - newButton.addSelectionListener(selectionListener); - // add the Edit button - // - editButton = new Button(buttonComposite, SWT.NONE); - editButton.setText(XMLUIPlugin.getResourceString("%_UI_BUTTON_EDIT")); //$NON-NLS-1$ - editButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - editButton.addSelectionListener(selectionListener); - // add the Delete button - // - deleteButton = new Button(buttonComposite, SWT.NONE); - deleteButton.setText(XMLUIPlugin.getResourceString("%_UI_BUTTON_DELETE")); //$NON-NLS-1$ - 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) { - EditNamespaceInfoDialog dialog = invokeDialog(XMLUIPlugin.getResourceString("%_UI_LABEL_NEW_NAMESPACE_INFORMATION"), (NamespaceInfo) selectedObject); //$NON-NLS-1$ - performDelayedUpdate(); - } - } - - public void performNew() { - NamespaceInfo info = new NamespaceInfo(); - EditNamespaceInfoDialog dialog = invokeDialog(XMLUIPlugin.getResourceString("%_UI_LABEL_NEW_NAMESPACE_INFORMATION"), info); //$NON-NLS-1$ - 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/dialogs/SelectFileOrXMLCatalogIdDialog.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dialogs/SelectFileOrXMLCatalogIdDialog.java deleted file mode 100644 index 4c8397c90e..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dialogs/SelectFileOrXMLCatalogIdDialog.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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/dialogs/SelectFileOrXMLCatalogIdPanel.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dialogs/SelectFileOrXMLCatalogIdPanel.java deleted file mode 100644 index ff786ab18c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dialogs/SelectFileOrXMLCatalogIdPanel.java +++ /dev/null @@ -1,179 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.dialogs; - -import org.eclipse.core.resources.IFile; -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.viewers.SelectSingleFileView; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.uriresolver.XMLCatalog; -import org.eclipse.wst.xml.uriresolver.XMLCatalogEntry; -import org.eclipse.wst.xml.uriresolver.XMLCatalogPlugin; - -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(XMLUIPlugin.getResourceString("%_UI_RADIO_BUTTON_SELECT_FROM_WORKSPACE")); //$NON-NLS-1$ - 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(XMLUIPlugin.getResourceString("%_UI_RADIO_BUTTON_SELECT_FROM_CATALOG")); //$NON-NLS-1$ - 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); - - XMLCatalog xmlCatalog = XMLCatalogPlugin.getInstance().getDefaultXMLCatalog(); - selectXMLCatalogIdPanel = new SelectXMLCatalogIdPanel(pageBook, xmlCatalog); - selectXMLCatalogIdPanel.getTableViewer().addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - updateCompletionStateChange(); - } - }); - pageBook.showPage(selectSingleFileView.getControl()); - } - - public IFile getFile() { - IFile result = null; - if (radioButton[0].getSelection()) { - result = selectSingleFileView.getFile(); - } - return result; - } - - public XMLCatalogEntry getXMLCatalogEntry() { - XMLCatalogEntry 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/dialogs/SelectXMLCatalogIdDialog.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dialogs/SelectXMLCatalogIdDialog.java deleted file mode 100644 index 65cb8bd065..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dialogs/SelectXMLCatalogIdDialog.java +++ /dev/null @@ -1,111 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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.wst.xml.uriresolver.XMLCatalog; -import org.eclipse.wst.xml.uriresolver.XMLCatalogEntry; -import org.eclipse.wst.xml.uriresolver.XMLCatalogPlugin; - - - -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 XMLCatalogEntry) { - XMLCatalogEntry mappingInfo = (XMLCatalogEntry) selectedObject; - publicId = mappingInfo.getKey(); - systemId = computeDefaultSystemId(mappingInfo); - } - } - super.buttonPressed(buttonId); - } - - protected String computeDefaultSystemId(XMLCatalogEntry mappingInfo) { - String result = mappingInfo.getWebAddress(); - 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); - // TODO... SSE port - //WorkbenchHelp.setHelp(dialogArea, - // XMLCommonUIContextIds.XCUI_CATALOG_DIALOG); - - XMLCatalog xmlCatalog = XMLCatalogPlugin.getInstance().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/dialogs/SelectXMLCatalogIdPanel.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dialogs/SelectXMLCatalogIdPanel.java deleted file mode 100644 index 082ebc7a65..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dialogs/SelectXMLCatalogIdPanel.java +++ /dev/null @@ -1,129 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.dialogs; - -import java.util.Collection; -import java.util.Iterator; -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.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.uriresolver.XMLCatalog; -import org.eclipse.wst.xml.uriresolver.XMLCatalogEntry; - -public class SelectXMLCatalogIdPanel extends Composite { - protected int catalogEntryType; - protected boolean doTableSizeHack = false; - - protected XMLCatalogTableViewer tableViewer; - protected XMLCatalog xmlCatalog; - - public SelectXMLCatalogIdPanel(Composite parent, XMLCatalog xmlCatalog) { - super(parent, SWT.NONE); - this.xmlCatalog = 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(XMLUIPlugin.getResourceString("%_UI_LABEL_XML_CATALOG_COLON")); //$NON-NLS-1$ - - 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] = XMLUIPlugin.getResourceString("%_UI_LABEL_KEY"); //$NON-NLS-1$ - headings[1] = XMLUIPlugin.getResourceString("%_UI_LABEL_URI"); //$NON-NLS-1$ - - XMLCatalogTableViewer theTableViewer = new XMLCatalogTableViewer(parent, headings) { - - protected void addXMLCatalogEntries(List list, Collection collection) { - for (Iterator i = collection.iterator(); i.hasNext();) { - XMLCatalogEntry entry = (XMLCatalogEntry) i.next(); - if (catalogEntryType == 0) { - list.add(entry); - } else if (catalogEntryType == entry.getType()) { - list.add(entry); - } - } - } - - public Collection getXMLCatalogEntries() { - List result = null; - - if (xmlCatalog == 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(); - - addXMLCatalogEntries(result, xmlCatalog.getChildCatalog(XMLCatalog.SYSTEM_CATALOG_ID).getEntries()); - addXMLCatalogEntries(result, xmlCatalog.getChildCatalog(XMLCatalog.USER_CATALOG_ID).getEntries()); - } - return result; - } - }; - return theTableViewer; - } - - - public String getId() { - XMLCatalogEntry entry = getXMLCatalogEntry(); - return entry != null ? entry.getKey() : null; - } - - public XMLCatalogTableViewer getTableViewer() { - return tableViewer; - } - - public String getURI() { - XMLCatalogEntry entry = getXMLCatalogEntry(); - return entry != null ? entry.getURI() : null; - } - - public XMLCatalogEntry getXMLCatalogEntry() { - XMLCatalogEntry result = null; - ISelection selection = tableViewer.getSelection(); - Object selectedObject = (selection instanceof IStructuredSelection) ? ((IStructuredSelection) selection).getFirstElement() : null; - if (selectedObject instanceof XMLCatalogEntry) { - result = (XMLCatalogEntry) 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/dialogs/UpdateListener.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dialogs/UpdateListener.java deleted file mode 100644 index 2ae05bdcb1..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dialogs/UpdateListener.java +++ /dev/null @@ -1,20 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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/dialogs/XMLCatalogTableViewer.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dialogs/XMLCatalogTableViewer.java deleted file mode 100644 index 3f5262c8a5..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dialogs/XMLCatalogTableViewer.java +++ /dev/null @@ -1,198 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.dialogs; - -import java.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.xml.ui.internal.editor.XMLEditorPluginImageHelper; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages; -import org.eclipse.wst.xml.uriresolver.XMLCatalogEntry; -import org.eclipse.wst.xml.uriresolver.util.URIHelper; - - -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 XMLCatalogEntry && o2 instanceof XMLCatalogEntry) { - XMLCatalogEntry mappingInfo1 = (XMLCatalogEntry) o1; - XMLCatalogEntry mappingInfo2 = (XMLCatalogEntry) 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 XMLCatalogEntry) { - XMLCatalogEntry catalogEntry = (XMLCatalogEntry) 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 XMLCatalogEntry) { - XMLCatalogEntry catalogEntry = (XMLCatalogEntry) 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 XMLCatalogEntry) { - XMLCatalogEntry catalogEntry = (XMLCatalogEntry) 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/dnd/DragNodeCommand.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dnd/DragNodeCommand.java deleted file mode 100644 index 93f194874f..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dnd/DragNodeCommand.java +++ /dev/null @@ -1,228 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.dnd; - -import java.util.Collection; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - -import org.eclipse.swt.dnd.DND; -import org.eclipse.wst.common.ui.dnd.DefaultDragAndDropCommand; -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.xml.core.document.XMLNode; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.w3c.dom.Attr; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -public class DragNodeCommand extends DefaultDragAndDropCommand { - public DragNodeCommand(Object target, float location, int operations, int operation, Collection sources) { - super(target, location, operations, operation, sources); - } - - protected void beginModelChange(Node node, boolean batchUpdate) { - IStructuredModel structuredModel = getStructedModel(node); - if (structuredModel != null) { - structuredModel.beginRecording(this, XMLUIPlugin.getResourceString("%DragNodeCommand.0")); //$NON-NLS-1$ - if (batchUpdate) { - // structuredModel.aboutToChangeModel(); - } - } - } - - public boolean canExecute() { - return executeHelper(true); - } - - - public boolean doMove(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 { - Element targetElement = (Element) parentNode; - targetElement.setAttribute(sourceAttribute.getName(), sourceAttribute.getValue()); - sourceAttributeOwnerElement.removeAttributeNode(sourceAttribute); - } catch (Exception e) { - } - } - } - } else { - if ((parentNode.getNodeType() == Node.ELEMENT_NODE || parentNode.getNodeType() == Node.DOCUMENT_NODE) && !(refChild instanceof Attr)) { - result = true; - - if (!testOnly) { - 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) { - source.getParentNode().removeChild(source); - parentNode.insertBefore(source, refChild); - } - } - } - } - } - return result; - } - - protected void endModelChange(Node node, boolean batchUpdate) { - IStructuredModel structuredModel = getStructedModel(node); - if (structuredModel != null) { - structuredModel.endRecording(this); - if (batchUpdate) { - // structuredModel.changedModel(); - } - } - } - - public void execute() { - executeHelper(false); - } - - // - // - public 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 = doMove((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; - } - - protected Node getParentForDropPosition(Node node) { - Node result = null; - - int feedback = getFeedback(); - if (feedback == DND.FEEDBACK_SELECT) { - result = node; - } else { - result = getParentOrOwner(node); - } - return result; - } - - - protected Node getParentOrOwner(Node node) { - return (node.getNodeType() == Node.ATTRIBUTE_NODE) ? ((Attr) node).getOwnerElement() : node.getParentNode(); - } - - - protected 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; - } - - protected IStructuredModel getStructedModel(Node node) { - IStructuredModel result = null; - if (node instanceof XMLNode) { - result = ((XMLNode) node).getModel(); - } - return result; - } - - // returns true if a is an ancestore of b - // - protected 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. - */ - protected 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/dnd/XMLDragAndDropManager.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dnd/XMLDragAndDropManager.java deleted file mode 100644 index a7f0fe94da..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dnd/XMLDragAndDropManager.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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.dnd.DragAndDropCommand; -import org.eclipse.wst.common.ui.dnd.DragAndDropManager; -import org.eclipse.wst.common.ui.dnd.ObjectTransfer; -import org.eclipse.wst.common.ui.dnd.ViewerDragAdapter; -import org.eclipse.wst.common.ui.dnd.ViewerDropAdapter; -import org.w3c.dom.Node; - -public class XMLDragAndDropManager implements DragAndDropManager { - 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())); - } - - public XMLDragAndDropManager() { - } - - public DragAndDropCommand createCommand(Object target, float location, int operations, int operation, Collection source) { - DragAndDropCommand result = null; - if (target instanceof Node) { - Node node = (Node) target; - result = new DragNodeCommand(target, location, operations, operation, source); - } - return result; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/doubleclick/XMLDoubleClickStrategy.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/doubleclick/XMLDoubleClickStrategy.java deleted file mode 100644 index 93dbf16a3c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/doubleclick/XMLDoubleClickStrategy.java +++ /dev/null @@ -1,290 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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.IModelManager; -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.text.ITextRegion; -import org.eclipse.wst.sse.ui.StructuredTextViewer; -import org.eclipse.wst.xml.core.parser.XMLRegionContext; -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 = 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 IModelManager getModelManager() { - return StructuredModelManager.getInstance().getModelManager(); - } - - 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() == XMLRegionContext.XML_TAG_ATTRIBUTE_NAME) && (nextRegion != null) && (nextRegion.getType() == XMLRegionContext.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() == XMLRegionContext.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() == XMLRegionContext.XML_TAG_ATTRIBUTE_NAME)) { - fStructuredTextViewer.setSelectedRange(fStructuredDocumentRegion.getStartOffset(prevRegion), fTextRegion.getTextEnd() - prevRegion.getStart()); - } - } - } - - protected void processElementDoubleClicked() { - if (fTextRegion.getType() == XMLRegionContext.XML_TAG_ATTRIBUTE_VALUE) - processElementAttrValueDoubleClicked(); // special handling for - // XML_TAG_ATTRIBUTE_VALUE - else { - if (fDoubleClickCount == 1) { - fStructuredTextViewer.setSelectedRange(fStructuredDocumentRegion.getStart() + fTextRegion.getStart(), fTextRegion.getTextLength()); - } else if (fDoubleClickCount == 2) { - if (fTextRegion.getType() == XMLRegionContext.XML_TAG_ATTRIBUTE_NAME) - processElementAttrNameDoubleClicked2Times(); - else if (fTextRegion.getType() == XMLRegionContext.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() == XMLRegionContext.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/extension/IDesignViewerSelectionManager.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/extension/IDesignViewerSelectionManager.java deleted file mode 100644 index 5792dbf777..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/extension/IDesignViewerSelectionManager.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.extension; - -import org.eclipse.wst.sse.ui.ViewerSelectionManager; -import org.w3c.dom.Node; -import org.w3c.dom.ranges.Range; - - -/* - * This class is currently an internal class used by Quick Edit view. - */ -public interface IDesignViewerSelectionManager extends ViewerSelectionManager { - Node getFocusedNode(); - - Range getRange(); - - void pause(); - - void reset(); - - void resume(); -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/extension/IExtendedDesignEditor.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/extension/IExtendedDesignEditor.java deleted file mode 100644 index c73b66f47c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/extension/IExtendedDesignEditor.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.extension; - -import org.eclipse.ui.IEditorInput; -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.sse.ui.extension.IExtendedMarkupEditorExtension; - - -/* - * This class is currently an internal class used by Quick Edit view. - */ -public interface IExtendedDesignEditor extends IExtendedMarkupEditorExtension { - - IEditorInput getActiveEditorInput(); - - IStructuredModel getActiveModel(); - - IDesignViewerSelectionManager getDesignViewerSelectionMediator(); - - IEditorInput getEditorInput(); - - IStructuredModel getModel(); -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/extensions/XMLSourceEditingTextTools.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/extensions/XMLSourceEditingTextTools.java deleted file mode 100644 index 9bee91bef1..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/extensions/XMLSourceEditingTextTools.java +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.extensions; - - - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IResource; -import org.eclipse.wst.sse.core.IModelManager; -import org.eclipse.wst.sse.core.INodeAdapter; -import org.eclipse.wst.sse.core.INodeNotifier; -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.ui.extensions.breakpoint.NodeLocation; -import org.eclipse.wst.sse.ui.extensions.breakpoint.SourceEditingTextTools; -import org.eclipse.wst.xml.core.document.XMLModel; -import org.eclipse.wst.xml.core.document.XMLNode; -import org.eclipse.wst.xml.core.document.XMLText; -import org.w3c.dom.Document; -import org.w3c.dom.Node; - - -/** - * Implements SourceEditingTextTools interface - */ -public class XMLSourceEditingTextTools implements SourceEditingTextTools, INodeAdapter { - - protected class NodeLocationImpl implements NodeLocation { - private XMLNode node; - - public NodeLocationImpl(XMLNode 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; - } - } - - - 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.getInstance().getModelManager(); - IStructuredModel model = null; - try { - model = mm.getExistingModelForRead((IFile) res); - if (model == null || !(model instanceof XMLModel)) - return null; - - return ((XMLModel) model).getDocument(); - } finally { - if (model != null) - model.releaseFromRead(); - } - } - - /* - * (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 XMLNode) - return new NodeLocationImpl((XMLNode) node); - return null; - } - - public String getPageLanguage(Node node) { - return ""; //$NON-NLS-1$ - } - - public int getStartOffset(Node node) { - if (node == null || !(node instanceof XMLText)) - return -1; - - IStructuredDocumentRegion fnode = ((XMLText) 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 SourceEditingTextTools.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) { - } -} 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 e427490378..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/Logger.java +++ /dev/null @@ -1,159 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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/XMLUIPlugin.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPlugin.java deleted file mode 100644 index 7fc9649fe3..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPlugin.java +++ /dev/null @@ -1,273 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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 java.text.MessageFormat; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.text.templates.ContextTypeRegistry; -import org.eclipse.jface.text.templates.persistence.TemplateStore; -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.common.encoding.content.IContentTypeIdentifier; -import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; -import org.eclipse.wst.sse.ui.preferences.CommonEditorPreferenceNames; -import org.eclipse.wst.sse.ui.preferences.PreferenceKeyGenerator; -import org.eclipse.wst.sse.ui.preferences.ui.ColorHelper; -import org.eclipse.wst.sse.ui.registry.AdapterFactoryRegistry; -import org.eclipse.wst.sse.ui.registry.AdapterFactoryRegistryImpl; -import org.eclipse.wst.sse.ui.registry.embedded.EmbeddedAdapterFactoryRegistryImpl; -import org.eclipse.wst.xml.ui.JobStatusLineHelper; -import org.eclipse.wst.xml.ui.style.IStyleConstantsXML; -import org.eclipse.wst.xml.ui.templates.TemplateContextTypeXML; -import org.eclipse.wst.xml.ui.templates.TemplateContextTypeXMLAttribute; -import org.eclipse.wst.xml.ui.templates.TemplateContextTypeXMLAttributeValue; -import org.eclipse.wst.xml.ui.templates.TemplateContextTypeXMLTag; - -/** - * 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; - //Resource bundle. - private ResourceBundle resourceBundle; - private static final String KEY_PREFIX = "%"; //$NON-NLS-1$ - private static final String KEY_DOUBLE_PREFIX = "%%"; //$NON-NLS-1$ - - public static XMLUIPlugin getDefault() { - return instance; - } - - public synchronized static XMLUIPlugin getInstance() { - return instance; - } - - /** - * The template context type registry for the xml editor. - * - * @since 3.0 - */ - private ContextTypeRegistry fContextTypeRegistry; - - /** - * The template store for the xml editor. - * - * @since 3.0 - */ - private TemplateStore fTemplateStore; - - public XMLUIPlugin() { - super(); - instance = this; - - // Force a call to initialize default preferences since - // initializeDefaultPreferences is only called if *this* plugin's - // preference store is accessed - initializeDefaultXMLPreferences(SSEUIPlugin.getDefault().getPreferenceStore()); - - JobStatusLineHelper.init(); - } - - public AdapterFactoryRegistry getAdapterFactoryRegistry() { - return AdapterFactoryRegistryImpl.getInstance(); - - } - - public AdapterFactoryRegistry getEmbeddedAdapterFactoryRegistry() { - return EmbeddedAdapterFactoryRegistryImpl.getInstance(); - - } - - /** - * 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) { - fContextTypeRegistry = new ContributionContextTypeRegistry(); - - fContextTypeRegistry.addContextType(new TemplateContextTypeXML()); - fContextTypeRegistry.addContextType(new TemplateContextTypeXMLTag()); - fContextTypeRegistry.addContextType(new TemplateContextTypeXMLAttribute()); - fContextTypeRegistry.addContextType(new TemplateContextTypeXMLAttributeValue()); - } - - return fContextTypeRegistry; - } - - /** - * 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(), CommonEditorPreferenceNames.TEMPLATES_KEY); - - try { - fTemplateStore.load(); - } catch (IOException e) { - Logger.logException(e); - } - } - return fTemplateStore; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.plugin.AbstractUIPlugin#initializeDefaultPluginPreferences() - */ - protected void initializeDefaultPreferences(IPreferenceStore store) { - - // ignore this preference store - // use EditorPlugin preference store - IPreferenceStore editorStore = SSEUIPlugin.getDefault().getPreferenceStore(); - initializeDefaultXMLPreferences(editorStore); - } - - protected void initializeDefaultXMLPreferences(IPreferenceStore store) { - - String ctId = IContentTypeIdentifier.ContentTypeID_SSEXML; - - store.setDefault(PreferenceKeyGenerator.generateKey(CommonEditorPreferenceNames.CONTENT_ASSIST_SUPPORTED, ctId), true); - store.setDefault(PreferenceKeyGenerator.generateKey(CommonEditorPreferenceNames.AUTO_PROPOSE, ctId), true); - store.setDefault(PreferenceKeyGenerator.generateKey(CommonEditorPreferenceNames.AUTO_PROPOSE_CODE, ctId), CommonEditorPreferenceNames.LT); - - store.setDefault(CommonEditorPreferenceNames.EDITOR_VALIDATION_METHOD, CommonEditorPreferenceNames.EDITOR_VALIDATION_CONTENT_MODEL); //$NON-NLS-1$ - - store.setDefault(PreferenceKeyGenerator.generateKey(CommonEditorPreferenceNames.EDITOR_VALIDATION_METHOD, ctId), CommonEditorPreferenceNames.EDITOR_VALIDATION_CONTENT_MODEL); //$NON-NLS-1$ - store.setDefault(PreferenceKeyGenerator.generateKey(CommonEditorPreferenceNames.EDITOR_USE_INFERRED_GRAMMAR, ctId), true); - - // XML Style Preferences - String NOBACKGROUNDBOLD = " | null | false"; //$NON-NLS-1$ - String styleValue = ColorHelper.getColorString(127, 0, 127) + NOBACKGROUNDBOLD; - store.setDefault(PreferenceKeyGenerator.generateKey(IStyleConstantsXML.TAG_ATTRIBUTE_NAME, ctId), styleValue); - - styleValue = ColorHelper.getColorString(42, 0, 255) + NOBACKGROUNDBOLD; - store.setDefault(PreferenceKeyGenerator.generateKey(IStyleConstantsXML.TAG_ATTRIBUTE_VALUE, ctId), styleValue); - - styleValue = "null" + NOBACKGROUNDBOLD; //$NON-NLS-1$ - store.setDefault(PreferenceKeyGenerator.generateKey(IStyleConstantsXML.TAG_ATTRIBUTE_EQUALS, ctId), styleValue); // specified - // value - // is - // black; - // leaving - // as - // widget - // default - - styleValue = ColorHelper.getColorString(63, 95, 191) + NOBACKGROUNDBOLD; - store.setDefault(PreferenceKeyGenerator.generateKey(IStyleConstantsXML.COMMENT_BORDER, ctId), styleValue); - store.setDefault(PreferenceKeyGenerator.generateKey(IStyleConstantsXML.COMMENT_TEXT, ctId), styleValue); - - styleValue = ColorHelper.getColorString(0, 128, 128) + NOBACKGROUNDBOLD; - store.setDefault(PreferenceKeyGenerator.generateKey(IStyleConstantsXML.DECL_BORDER, ctId), styleValue); - - styleValue = ColorHelper.getColorString(0, 0, 128) + NOBACKGROUNDBOLD; - store.setDefault(PreferenceKeyGenerator.generateKey(IStyleConstantsXML.DOCTYPE_NAME, ctId), styleValue); - store.setDefault(PreferenceKeyGenerator.generateKey(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_PUBREF, ctId), styleValue); - - styleValue = ColorHelper.getColorString(128, 128, 128) + NOBACKGROUNDBOLD; - store.setDefault(PreferenceKeyGenerator.generateKey(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID, ctId), styleValue); - - styleValue = ColorHelper.getColorString(63, 127, 95) + NOBACKGROUNDBOLD; - store.setDefault(PreferenceKeyGenerator.generateKey(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_SYSREF, ctId), styleValue); - - styleValue = "null" + NOBACKGROUNDBOLD; //$NON-NLS-1$ - store.setDefault(PreferenceKeyGenerator.generateKey(IStyleConstantsXML.XML_CONTENT, ctId), styleValue); // specified - // value - // is - // black; - // leaving - // as - // widget - // default - - styleValue = ColorHelper.getColorString(0, 128, 128) + NOBACKGROUNDBOLD; - store.setDefault(PreferenceKeyGenerator.generateKey(IStyleConstantsXML.TAG_BORDER, ctId), styleValue); - - styleValue = ColorHelper.getColorString(63, 127, 127) + NOBACKGROUNDBOLD; - store.setDefault(PreferenceKeyGenerator.generateKey(IStyleConstantsXML.TAG_NAME, ctId), styleValue); - - styleValue = ColorHelper.getColorString(0, 128, 128) + NOBACKGROUNDBOLD; - store.setDefault(PreferenceKeyGenerator.generateKey(IStyleConstantsXML.PI_BORDER, ctId), styleValue); - - styleValue = "null" + NOBACKGROUNDBOLD; //$NON-NLS-1$ - store.setDefault(PreferenceKeyGenerator.generateKey(IStyleConstantsXML.PI_CONTENT, ctId), styleValue); // specified - // value - // is - // black; - // leaving - // as - // widget - // default - - styleValue = ColorHelper.getColorString(0, 128, 128) + NOBACKGROUNDBOLD; - store.setDefault(PreferenceKeyGenerator.generateKey(IStyleConstantsXML.CDATA_BORDER, ctId), styleValue); - - styleValue = ColorHelper.getColorString(0, 0, 0) + NOBACKGROUNDBOLD; - store.setDefault(PreferenceKeyGenerator.generateKey(IStyleConstantsXML.CDATA_TEXT, ctId), styleValue); - } - - /** - * Returns the string from the plugin's resource bundle, - * or 'key' if not found. - */ - public static String getResourceString(String value) { - String s = value.trim(); - if (!s.startsWith(KEY_PREFIX, 0)) - return s; - if (s.startsWith(KEY_DOUBLE_PREFIX, 0)) - return s.substring(1); - - int ix = s.indexOf(' '); - String key = ix == -1 ? s : s.substring(0, ix); - - ResourceBundle bundle = getDefault().getResourceBundle(); - try { - return (bundle != null) ? bundle.getString(key.substring(1)) : key; - } catch (MissingResourceException e) { - return key; - } - } - - public static String getResourceString(String key, Object[] args) { - - try { - return MessageFormat.format(getResourceString(key), args); - } catch (IllegalArgumentException e) { - return getResourceString(key); - } - - } - - /** - * Returns the plugin's resource bundle, - */ - public ResourceBundle getResourceBundle() { - try { - if (resourceBundle == null) - resourceBundle = ResourceBundle.getBundle("org.eclipse.wst.xml.ui.internal.XMLUIPluginResources"); - } catch (MissingResourceException x) { - resourceBundle = null; - } - return resourceBundle; - } -} 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 9179545989..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties +++ /dev/null @@ -1,222 +0,0 @@ -############################################################################### -# Copyright (c) 2001, 2004 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.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 -# -############################################################################### -## 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<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 -## 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 - -NEW=New -DELETE=Remove -ADD_TEXT=Add Text -ADD_CDATA_SECTION=Add CDATA Section -ADD_COMMENT=Add Commen&t -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_ADD_DOCTYPE=Add DOCTYPE... -_UI_MENU_EDIT_DOCTYPE=Edit DOCTYPE... -_UI_MENU_ADD_GRAMMAR_INFORMATION=Add Grammar Information -_UI_MENU_VALIDATE_XML=Validate XML File -_UI_LABEL_UNDO_ADD_DESCRIPTION=Add -_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_SCHEMA_INFORMATION=Edit &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_LABEL_LOADING_GRAMMAR=Loading grammar: - -_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_NAMESPACE_INFORMATION=Namespace 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 -_UI_LABEL_EDIT_NAMESPACE_INFORMATION=Edit Namespace Information - -# -# Assign links to an XML file -# -_UI_WORK_BENCH=Workbench Files... -_UI_FILE_SYSTEM=Import Files... -_UI_ASSIGN_XSL=Assign An XSL Stylesheet To The XML File -_UI_ASSIGN_DTD=Assign A DTD file To The XML File -_UI_ASSIGN_XSD=Assign An XML schema To The XML File -_UI_SELECT_XSL_TITLE=Select an XSL File -_UI_SELECT_XSL_DESC=Select an XSL file from the workbench. - -_UI_ASSIGN=Assign -_UI_XSD=XML Schema... -_UI_DTD=DTD... -_UI_XSL=XSL Stylesheet... - -# XMLValidator.java -_UI_XML_VALIDATOR=XML Validator -# SelectFileOrXMLCatalogIdPanel.java - -_UI_RADIO_BUTTON_SELECT_FROM_WORKSPACE=Select file from workbench -_UI_RADIO_BUTTON_SELECT_FROM_CATALOG=Select XML Catalog entry - -_UI_WARNING_TITLE_ROOT_ELEMENT_REQUIRED=Root Element Required -_UI_WARNING_DOCUMENT_REQUIRES_ROOT=The document requires a root element in order to add schema information. -_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: -TemplateContextTypeXMLTag.0=XML Tags -TemplateContextTypeXMLAttributeValue.0=XML Attribute Values -TemplateContextTypeXMLAttribute.0=XML Attributes -TemplateContextTypeXML.0=All XML -DragNodeCommand.0=Move -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 -QuickFixProcessorXML.16=Remove this attribute and its value -XMLPropertySourceAdapter.0=Attributes - -WorkbenchDefaultEncodingSettings.0=Use workbench encoding 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 60ac815960..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/autoedit/StructuredAutoEditStrategyXML.java +++ /dev/null @@ -1,119 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.IDocument; -import org.eclipse.ui.texteditor.ITextEditorExtension3; -import org.eclipse.wst.sse.core.IModelManager; -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.ui.StructuredDocumentCommand; -import org.eclipse.wst.sse.ui.edit.util.BasicAutoEditStrategy; -import org.eclipse.wst.xml.core.document.XMLElement; -import org.eclipse.wst.xml.core.document.XMLNode; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.w3c.dom.Node; - - -public class StructuredAutoEditStrategyXML extends BasicAutoEditStrategy { - public void customizeDocumentCommand(IDocument document, DocumentCommand command) { - StructuredDocumentCommand structuredDocumentCommand = (StructuredDocumentCommand) command; - Object textEditor = getActiveTextEditor(); - if (!(textEditor instanceof ITextEditorExtension3 && ((ITextEditorExtension3) textEditor).getInsertMode() == ITextEditorExtension3.SMART_INSERT)) - return; - - IStructuredModel model = null; - try { - model = getModelManager().getExistingModelForRead(document); - if (model != null) { - if (structuredDocumentCommand.text != null) { - smartInsertForComment(structuredDocumentCommand, document, model); - smartInsertForEndTag(structuredDocumentCommand, document, model); - } - } - } finally { - if (model != null) - model.releaseFromRead(); - } - } - - private IModelManager getModelManager() { - return StructuredModelManager.getInstance().getModelManager(); - } - - private boolean isCommentNode(XMLNode node) { - return (node != null && node instanceof XMLElement && ((XMLElement) node).isCommentTag()); - } - - private boolean isDocumentNode(XMLNode node) { - return (node != null && node.getNodeType() == Node.DOCUMENT_NODE); - } - - protected boolean isEndTagRequired(XMLNode node) { - - if (node == null) - return false; - return node.isContainer(); - } - - protected boolean prefixedWith(IDocument document, int offset, String string) { - - try { - return document.getLength() >= string.length() && document.get(offset - string.length(), string.length()).equals(string); - } catch (BadLocationException e) { - Logger.logException(e); - return false; - } - } - - protected void smartInsertForComment(StructuredDocumentCommand structuredDocumentCommand, IDocument document, IStructuredModel model) { - try { - if (structuredDocumentCommand.text.equals("-") && document.getLength() >= 3 && document.get(structuredDocumentCommand.offset - 3, 3).equals("<!-")) { //$NON-NLS-1$ //$NON-NLS-2$ - structuredDocumentCommand.text += " "; //$NON-NLS-1$ - structuredDocumentCommand.doit = false; - structuredDocumentCommand.addCommand(structuredDocumentCommand.offset, 0, " -->", null); //$NON-NLS-1$ - } - } catch (BadLocationException e) { - Logger.logException(e); - } - - } - - protected void smartInsertForEndTag(StructuredDocumentCommand structuredDocumentCommand, IDocument document, IStructuredModel model) { - try { - if (structuredDocumentCommand.text.equals("/") && document.getLength() >= 1 && document.get(structuredDocumentCommand.offset - 1, 1).equals("<")) { //$NON-NLS-1$ //$NON-NLS-2$ - XMLNode parentNode = (XMLNode) ((XMLNode) model.getIndexedRegion(structuredDocumentCommand.offset - 1)).getParentNode(); - if (isCommentNode(parentNode)) { - // loop and find non comment node parent - while (parentNode != null && isCommentNode(parentNode)) { - parentNode = (XMLNode) parentNode.getParentNode(); - } - } - - if (!isDocumentNode(parentNode)) { - IStructuredDocumentRegion endTagStructuredDocumentRegion = parentNode.getEndStructuredDocumentRegion(); - if (endTagStructuredDocumentRegion == null) { - structuredDocumentCommand.text += parentNode.getNodeName(); - structuredDocumentCommand.text += ">"; //$NON-NLS-1$ - } - } - } - } catch (BadLocationException e) { - Logger.logException(e); - } - - } -} 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 bfb47cb15d..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/CorrectionProcessorXML.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.ui.texteditor.ITextEditor; -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; - - -public class CorrectionProcessorXML extends StructuredCorrectionProcessor { - protected IQuickAssistProcessor fQuickAssistProcessor; - protected IQuickFixProcessor fQuickFixProcessor; - - public CorrectionProcessorXML(ITextEditor editor) { - super(editor); - } - - 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 02a593089c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/InsertRequiredAttrsQuickAssistProposal.java +++ /dev/null @@ -1,174 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.common.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.sse.core.exceptions.SourceEditingRuntimeException; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.text.ITextRegion; -import org.eclipse.wst.sse.ui.StructuredTextViewer; -import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils; -import org.eclipse.wst.xml.core.document.XMLNode; -import org.eclipse.wst.xml.core.parser.XMLRegionContext; -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; - -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) { - } - - /* - * (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) { - XMLNode node = (XMLNode) ContentAssistUtils.getNodeAt((StructuredTextViewer) viewer, offset); - IStructuredDocumentRegion startStructuredDocumentRegion = node.getStartStructuredDocumentRegion(); - int index = startStructuredDocumentRegion.getEndOffset(); - ITextRegion lastRegion = startStructuredDocumentRegion.getLastRegion(); - if (lastRegion.getType() == XMLRegionContext.XML_TAG_CLOSE) { - index--; - lastRegion = startStructuredDocumentRegion.getRegionAtCharacterOffset(index - 1); - } else if (lastRegion.getType() == XMLRegionContext.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) { - throw new SourceEditingRuntimeException(e); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getAdditionalProposalInfo() - */ - public String getAdditionalProposalInfo() { - return XMLUIPlugin.getResourceString("%InsertRequiredAttrsQuickAssistProposal.0"); //$NON-NLS-1$ - } - - /* - * (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 XMLUIPlugin.getResourceString("%InsertRequiredAttrsQuickAssistProposal.1"); //$NON-NLS-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 4d0008bb7a..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/ProblemIDsXML.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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 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 b2f00fa8dd..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/QuickAssistProcessorXML.java +++ /dev/null @@ -1,169 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.common.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.common.contentmodel.CMElementDeclaration; -import org.eclipse.wst.common.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.common.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.text.ITextRegion; -import org.eclipse.wst.sse.ui.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.document.XMLNode; -import org.eclipse.wst.xml.core.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.core.parser.XMLRegionContext; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; - - -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) { - XMLNode node = (XMLNode) ContentAssistUtils.getNodeAt(viewer, offset); - if (node != null && node.getNodeType() == Node.ELEMENT_NODE) { - IStructuredDocumentRegion startStructuredDocumentRegion = node.getStartStructuredDocumentRegion(); - if (startStructuredDocumentRegion != null && startStructuredDocumentRegion.containsOffset(offset)) { - XMLNode cursorNode = (XMLNode) 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) { - XMLNode node = (XMLNode) 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() == XMLRegionContext.XML_TAG_NAME || region.getType() == XMLRegionContext.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(); - 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) { - XMLNode node = (XMLNode) 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 8f9410ecd8..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/QuickFixProcessorXML.java +++ /dev/null @@ -1,147 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.XMLUIPlugin; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages; - -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(), XMLUIPlugin.getResourceString("%QuickFixProcessorXML.0"), null, "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - 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(), XMLUIPlugin.getResourceString("%QuickFixProcessorXML.1"), null, "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - proposals.add(new CompletionProposal("", tempAnnotation.getPosition().getOffset(), startTagEndOffset - tempAnnotation.getPosition().getOffset(), 0, getImage(), XMLUIPlugin.getResourceString("%QuickFixProcessorXML.2"), null, "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - proposals.add(new CompletionProposal("</" + tagName + ">", firstChildStartOffset, 0, 0, getImage(), XMLUIPlugin.getResourceString("%QuickFixProcessorXML.3"), null, "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - proposals.add(new CompletionProposal("</" + tagName + ">", endOffset, 0, 0, getImage(), XMLUIPlugin.getResourceString("%QuickFixProcessorXML.4"), null, "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - break; - case ProblemIDsXML.AttrsInEndTag : - proposals.add(new CompletionProposal("", tempAnnotation.getPosition().getOffset(), tempAnnotation.getPosition().getLength(), 0, getImage(), XMLUIPlugin.getResourceString("%QuickFixProcessorXML.5"), null, "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - 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(), XMLUIPlugin.getResourceString("%QuickFixProcessorXML.6"), null, "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - proposals.add(new CompletionProposal("", tempAnnotation.getPosition().getOffset(), tempAnnotation.getPosition().getLength(), 0, getImage(), XMLUIPlugin.getResourceString("%QuickFixProcessorXML.7"), null, "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - break; - case ProblemIDsXML.NoAttrValue : - defaultAttrValue = (String) tempAnnotation.getAdditionalFixInfo(); - proposals.add(new CompletionProposal("=\"" + defaultAttrValue + "\"", tempAnnotation.getPosition().getOffset() + tempAnnotation.getPosition().getLength(), 0, defaultAttrValue.length() + 3, getImage(), XMLUIPlugin.getResourceString("%QuickFixProcessorXML.6"), null, "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - proposals.add(new CompletionProposal("", tempAnnotation.getPosition().getOffset(), tempAnnotation.getPosition().getLength(), 0, getImage(), XMLUIPlugin.getResourceString("%QuickFixProcessorXML.7"), null, "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - break; - case ProblemIDsXML.SpacesBeforeTagName : - proposals.add(new CompletionProposal("", tempAnnotation.getPosition().getOffset(), tempAnnotation.getPosition().getLength(), 0, getImage(), XMLUIPlugin.getResourceString("%QuickFixProcessorXML.8"), null, "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - break; - case ProblemIDsXML.SpacesBeforePI : - proposals.add(new CompletionProposal("", tempAnnotation.getPosition().getOffset(), tempAnnotation.getPosition().getLength(), 0, getImage(), XMLUIPlugin.getResourceString("%QuickFixProcessorXML.9"), null, "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - break; - case ProblemIDsXML.NamespaceInPI : - proposals.add(new CompletionProposal("", tempAnnotation.getPosition().getOffset(), tempAnnotation.getPosition().getLength(), 0, getImage(), XMLUIPlugin.getResourceString("%QuickFixProcessorXML.10"), null, "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - break; - case ProblemIDsXML.UnknownElement : - proposals.add(new RemoveUnknownElementQuickFixProposal(tempAnnotation.getAdditionalFixInfo(), getImage(), XMLUIPlugin.getResourceString("%QuickFixProcessorXML.11"))); //$NON-NLS-1$ - proposals.add(new RenameInFileQuickAssistProposal()); - break; - case ProblemIDsXML.UnknownAttr : - proposals.add(new CompletionProposal("", tempAnnotation.getPosition().getOffset(), tempAnnotation.getPosition().getLength(), 0, getImage(), XMLUIPlugin.getResourceString("%QuickFixProcessorXML.7"), null, "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - proposals.add(new RenameInFileQuickAssistProposal()); - break; - case ProblemIDsXML.InvalidAttrValue : - proposals.add(new CompletionProposal("", tempAnnotation.getPosition().getOffset(), tempAnnotation.getPosition().getLength(), 0, getImage(), XMLUIPlugin.getResourceString("%QuickFixProcessorXML.12"), null, "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - 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(), XMLUIPlugin.getResourceString("%QuickFixProcessorXML.13"), null, "")); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case ProblemIDsXML.AttrValueNotQuoted : - String attrValue = (String) tempAnnotation.getAdditionalFixInfo(); - proposals.add(new CompletionProposal("\"" + attrValue + "\"", tempAnnotation.getPosition().getOffset(), tempAnnotation.getPosition().getLength(), attrValue.length() + 2, getImage(), XMLUIPlugin.getResourceString("%QuickFixProcessorXML.14"), null, "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - break; - case ProblemIDsXML.MissingClosingBracket : - proposals.add(new CompletionProposal(">", tempAnnotation.getPosition().getOffset() + tempAnnotation.getPosition().getLength(), 0, 1, getImage(), XMLUIPlugin.getResourceString("%QuickFixProcessorXML.15"), null, "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - 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 6af8773915..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/RemoveUnknownElementQuickFixProposal.java +++ /dev/null @@ -1,156 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.sse.core.exceptions.SourceEditingRuntimeException; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; - -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) { - } - - /* - * (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) { - throw new SourceEditingRuntimeException(e); - } catch (BadLocationException e) { - throw new SourceEditingRuntimeException(e); - } - } - - /* - * (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 = XMLUIPlugin.getResourceString("%QuickFixProcessorXML.11"); //$NON-NLS-1$ - - 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 711678b1cb..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/RenameInFileQuickAssistProposal.java +++ /dev/null @@ -1,182 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.exceptions.SourceEditingRuntimeException; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.text.ITextRegion; -import org.eclipse.wst.sse.ui.StructuredTextViewer; -import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils; -import org.eclipse.wst.xml.core.document.XMLNode; -import org.eclipse.wst.xml.core.parser.XMLRegionContext; -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; - -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) { - XMLNode node = (XMLNode) ContentAssistUtils.getNodeAt((StructuredTextViewer) 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() == XMLRegionContext.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() == XMLRegionContext.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) { - throw new SourceEditingRuntimeException(e); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getAdditionalProposalInfo() - */ - public String getAdditionalProposalInfo() { - return XMLUIPlugin.getResourceString("%RenameInFileQuickAssistProposal.0"); //$NON-NLS-1$ - } - - /* - * (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 XMLUIPlugin.getResourceString("%RenameInFileQuickAssistProposal.1"); //$NON-NLS-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 afad911401..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/SurroundWithNewElementQuickAssistProposal.java +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.exceptions.SourceEditingRuntimeException; -import org.eclipse.wst.sse.core.format.IStructuredFormatProcessor; -import org.eclipse.wst.sse.ui.StructuredTextViewer; -import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils; -import org.eclipse.wst.xml.core.document.XMLNode; -import org.eclipse.wst.xml.core.format.FormatProcessorXML; -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; -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) { - XMLNode cursorNode = (XMLNode) ContentAssistUtils.getNodeAt((StructuredTextViewer) viewer, offset); - // use parent node if text node is empty - if (cursorNode.getNodeType() == Node.TEXT_NODE && cursorNode.getNodeValue().trim().length() == 0) - cursorNode = (XMLNode) 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 - XMLNode newElementNode = (XMLNode) ContentAssistUtils.getNodeAt((StructuredTextViewer) 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) { - throw new SourceEditingRuntimeException(e); - } catch (BadLocationException e) { - throw new SourceEditingRuntimeException(e); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getAdditionalProposalInfo() - */ - public String getAdditionalProposalInfo() { - return XMLUIPlugin.getResourceString("%SurroundWithNewElementQuickAssistProposal.0"); //$NON-NLS-1$ - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getDisplayString() - */ - public String getDisplayString() { - return XMLUIPlugin.getResourceString("%SurroundWithNewElementQuickAssistProposal.1"); //$NON-NLS-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/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 072afcec6d..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/editor/IHelpContextIds.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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$ - - // XML Source page editor - public static final String XML_SOURCEVIEW_HELPID = PREFIX + "exml0000"; //$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$ -} 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 32338dfba8..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/editor/XMLEditorPluginImageHelper.java +++ /dev/null @@ -1,155 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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 8160f7781c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/editor/XMLEditorPluginImages.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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_TAG_GENERIC = "icons/full/obj16/tag-generic.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$ -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/search/XMLFindOccurrencesAction.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/search/XMLFindOccurrencesAction.java deleted file mode 100644 index 55a4407fa4..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/search/XMLFindOccurrencesAction.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.search; - -import java.util.ResourceBundle; - -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.wst.sse.ui.internal.search.BasicFindOccurrencesAction; -import org.eclipse.wst.xml.core.parser.XMLRegionContext; -import org.eclipse.wst.xml.core.text.rules.StructuredTextPartitionerForXML; - - - -/** - * <p> - * Configures a BasicFindOccurrencesAction with XML partitions and regions - * </p> - * - * <p> - * Uses default <code>getSearchQuery()</code>. - * </p> - * - * @author pavery - */ -public class XMLFindOccurrencesAction extends BasicFindOccurrencesAction { - - public XMLFindOccurrencesAction(ResourceBundle bundle, String prefix, ITextEditor editor) { - super(bundle, prefix, editor); - } - - public String[] getPartitionTypes() { - - return new String[]{StructuredTextPartitionerForXML.ST_DEFAULT_XML}; - } - - public String[] getRegionTypes() { - - return new String[]{XMLRegionContext.XML_TAG_NAME, XMLRegionContext.XML_TAG_ATTRIBUTE_NAME, XMLRegionContext.XML_TAG_ATTRIBUTE_VALUE}; - } - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/nsedit/CommonAddNamespacesControl.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/nsedit/CommonAddNamespacesControl.java deleted file mode 100644 index 03cf2de5fe..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/nsedit/CommonAddNamespacesControl.java +++ /dev/null @@ -1,265 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.nsedit; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.IFile; -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.contentmodel.util.NamespaceInfo; -import org.eclipse.wst.xml.ui.dialogs.SelectFileOrXMLCatalogIdDialog; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.uriresolver.util.IdResolver; -import org.eclipse.wst.xml.uriresolver.util.IdResolverImpl; -import org.eclipse.wst.xml.uriresolver.util.URIHelper; - -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(XMLUIPlugin.getResourceString("%_UI_ENTER_REQ_PREFIX_AND_NAMESPACE")); //$NON-NLS-1$ - - 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(XMLUIPlugin.getResourceString("%_UI_LABEL_PREFIX_COLON")); //$NON-NLS-1$ - - 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); - Label placeHolder1 = new Label(composite, SWT.NONE); - - // row 2 - // - Label uriLabel = new Label(composite, SWT.NONE); - uriLabel.setText(XMLUIPlugin.getResourceString("%_UI_LABEL_NAMESPACE_NAME_COLON")); //$NON-NLS-1$ - - 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); - - Label placeHolder2 = new Label(composite, SWT.NONE); - - // row 3 - // - Label locationHintLabel = new Label(composite, SWT.NONE); - locationHintLabel.setText(XMLUIPlugin.getResourceString("%_UI_LABEL_LOCATION_HINT_COLON")); //$NON-NLS-1$ - - 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(XMLUIPlugin.getResourceString("%_UI_LABEL_BROWSE")); //$NON-NLS-1$ - 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(XMLUIPlugin.getResourceString("%_UI_LABEL_SELECT_FILE")); //$NON-NLS-1$ - 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) { - 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); - IdResolver resolver = new IdResolverImpl(null); - grammarURI = resolver.resolveId(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(XMLUIPlugin.getResourceString("%_UI_SELECT_REGISTERED_NAMESPACES")); //$NON-NLS-1$ - radio1.addSelectionListener(this); - - radio2 = new Button(this, SWT.RADIO); - radio2.setText(XMLUIPlugin.getResourceString("%_UI_SPECIFY_NEW_NAMESPACE")); //$NON-NLS-1$ - 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(XMLUIPlugin.getResourceString("%_UI_SELECT_NAMESPACE_TO_ADD")); //$NON-NLS-1$ - - 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/nsedit/CommonAddNamespacesDialog.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/nsedit/CommonAddNamespacesDialog.java deleted file mode 100644 index a1ba50f0cb..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/nsedit/CommonAddNamespacesDialog.java +++ /dev/null @@ -1,188 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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.common.contentmodel.util.NamespaceInfo; -import org.eclipse.wst.xml.uriresolver.XMLCatalog; -import org.eclipse.wst.xml.uriresolver.XMLCatalogEntry; -import org.eclipse.wst.xml.uriresolver.XMLCatalogPlugin; - - -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(XMLCatalog catalog, List list) { - for (Iterator i = catalog.getEntries().iterator(); i.hasNext();) { - XMLCatalogEntry entry = (XMLCatalogEntry) i.next(); - if (entry.getType() == XMLCatalogEntry.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); - XMLCatalog catalog = XMLCatalogPlugin.getInstance().getDefaultXMLCatalog(); - addCatalogMapToList(catalog.getChildCatalog(XMLCatalog.USER_CATALOG_ID), list); - addCatalogMapToList(catalog.getChildCatalog(XMLCatalog.SYSTEM_CATALOG_ID), 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/nsedit/CommonEditNamespacesDialog.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/nsedit/CommonEditNamespacesDialog.java deleted file mode 100644 index 2ff3ee283e..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/nsedit/CommonEditNamespacesDialog.java +++ /dev/null @@ -1,318 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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.common.contentmodel.util.NamespaceInfo; -import org.eclipse.wst.xml.ui.dialogs.EditNamespaceInfoDialog; -import org.eclipse.wst.xml.ui.dialogs.NamespaceInfoErrorHelper; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; - -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(" " + XMLUIPlugin.getResourceString("%CommonEditNamespacesDialog.0") + " "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - 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(XMLUIPlugin.getResourceString("%_UI_BUTTON_EDIT")); //$NON-NLS-1$ - 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(XMLUIPlugin.getResourceString("%_UI_BUTTON_DELETE")); //$NON-NLS-1$ - 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) { - EditNamespaceInfoDialog dialog = invokeDialog(XMLUIPlugin.getResourceString("%_UI_LABEL_NEW_NAMESPACE_INFORMATION"), (NamespaceInfo) selection); //$NON-NLS-1$ - updateErrorMessage(namespaceInfoList); - performDelayedUpdate(); - } - } - - public void performNew() { - Shell shell = XMLUIPlugin.getInstance().getWorkbench().getActiveWorkbenchWindow().getShell(); - CommonAddNamespacesDialog dialog = new CommonAddNamespacesDialog(shell, XMLUIPlugin.getResourceString("%_UI_ADD_NAMESPACE_DECLARATIONS"), resourceLocation, namespaceInfoList); //$NON-NLS-1$ - 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$ - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/nsedit/CommonEditNamespacesTargetFieldDialog.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/nsedit/CommonEditNamespacesTargetFieldDialog.java deleted file mode 100644 index fb2506dc5d..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/nsedit/CommonEditNamespacesTargetFieldDialog.java +++ /dev/null @@ -1,104 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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.common.contentmodel.util.NamespaceInfo; -import org.eclipse.wst.xml.ui.dialogs.EditNamespaceInfoDialog; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; - -/* - * 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 resourceLocation) { - super(parent, resourceLocation, XMLUIPlugin.getResourceString("%_UI_NAMESPACE_DECLARATIONS")); //$NON-NLS-1$ - - 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(XMLUIPlugin.getResourceString("%_UI_TARGET_NAMESPACE")); //$NON-NLS-1$ - - 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; - } - - EditNamespaceInfoDialog dialog = invokeDialog(XMLUIPlugin.getResourceString("%_UI_LABEL_NEW_NAMESPACE_INFORMATION"), nsInfo); //$NON-NLS-1$ - 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); - } - - private 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/nsedit/CommonNamespaceInfoTable.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/nsedit/CommonNamespaceInfoTable.java deleted file mode 100644 index 7da1d32a5d..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/nsedit/CommonNamespaceInfoTable.java +++ /dev/null @@ -1,340 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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.common.contentmodel.util.NamespaceInfo; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; - -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 = XMLUIPlugin.getResourceString("%_UI_NO_PREFIX"); //$NON-NLS-1$ - break; - } - case COLUMN_NAMESPACE_URI : { - result = XMLUIPlugin.getResourceString("%_UI_NO_NAMESPACE_NAME"); //$NON-NLS-1$ - 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 = XMLUIPlugin.getResourceString("%_UI_LABEL_LOCATION_HINT"); //$NON-NLS-1$ - protected static final String LABEL_NAMESPACE_URI = XMLUIPlugin.getResourceString("%_UI_LABEL_NAMESPACE_NAME"); //$NON-NLS-1$ - protected static final String LABEL_PREFIX = XMLUIPlugin.getResourceString("%_UI_LABEL_PREFIX"); //$NON-NLS-1$ - 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/openon/DefaultOpenOnXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/openon/DefaultOpenOnXML.java deleted file mode 100644 index d81befb291..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/openon/DefaultOpenOnXML.java +++ /dev/null @@ -1,354 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.openon; - - - -import java.util.StringTokenizer; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.Path; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.Region; -import org.eclipse.wst.common.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.common.contentmodel.CMDataType; -import org.eclipse.wst.common.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.common.contentmodel.util.DOMNamespaceHelper; -import org.eclipse.wst.common.uriresolver.URIResolverPlugin; -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.sse.core.IndexedRegion; -import org.eclipse.wst.sse.core.util.StringUtils; -import org.eclipse.wst.sse.ui.openon.AbstractOpenOn; -import org.eclipse.wst.xml.core.document.XMLAttr; -import org.eclipse.wst.xml.core.document.XMLNode; -import org.eclipse.wst.xml.core.modelquery.ModelQueryUtil; -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; - - -/** - * This action class retrieves the link/file selected by the cursor and - * attempts to open the link/file in the default editor or web browser - */ -public class DefaultOpenOnXML extends AbstractOpenOn { - 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$ - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.AbstractOpenOn#doGetOpenOnRegion(int) - */ - protected IRegion doGetOpenOnRegion(int offset) { - // find the element for this node - Node currNode = getCurrentNode(offset); - if (currNode != null) { - // handle doc type node - if (currNode.getNodeType() == Node.DOCUMENT_TYPE_NODE) { - XMLNode docNode = (XMLNode) currNode; - return new Region(docNode.getStartOffset(), docNode.getEndOffset() - docNode.getStartOffset()); - } - - Attr linkableAtt = getLinkableAttrFromNode(currNode, offset); - // found attribute to open on - if (linkableAtt != null) { - XMLAttr att = (XMLAttr) linkableAtt; - // do not include quotes in attribute value region - int regOffset = att.getValueRegionStartOffset(); - int regLength = att.getValueRegion().getTextLength(); - String attValue = att.getValueRegionText(); - if (StringUtils.isQuoted(attValue)) { - regOffset = ++regOffset; - regLength = regLength - 2; - } - return new Region(regOffset, regLength); - } - } - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.AbstractOpenOn#doOpenOn(org.eclipse.jface.text.IRegion) - */ - protected void doOpenOn(IRegion region) { - String uriString = getURIString(region.getOffset()); - openFileInEditor(uriString); - } - - /** - * Get the base location from the current model - * - */ - protected String getBaseLocation() { - String baseLoc = null; - - // get the base location from the current model - IStructuredModel sModel = null; - try { - sModel = getModelManager().getExistingModelForRead(getDocument()); - if (sModel != null) { - baseLoc = sModel.getBaseLocation(); - if (baseLoc != null) { - IFile modelFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(baseLoc)); - if (modelFile != null) { - baseLoc = modelFile.getLocation().toString(); - } - } - } - } - finally { - if (sModel != null) { - sModel.releaseFromRead(); - } - } - return baseLoc; - } - - /** - * Returns the attribute node within node at offset - * - * @param node - * @param offset - * @return Node - */ - private Node 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 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 - */ - protected Node getCurrentNode(int offset) { - // get the current node at the offset (returns element, doctype, text) - IndexedRegion inode = null; - IStructuredModel sModel = getModelManager().getExistingModelForRead(getDocument()); - inode = sModel.getIndexedRegion(offset); - if (inode == null) - inode = sModel.getIndexedRegion(offset - 1); - sModel.releaseFromRead(); - - if (inode instanceof Node) { - return (Node) inode; - } - return null; - } - - /** - * Return an attr of element that is "openOn-able" if one exists. null - * otherwise - * - * @param element - - * cannot be null - * @return Attr attribute that can be used for open on, null if no - * attribute could be found - */ - protected Attr getLinkableAttr(Element element) { - ModelQuery mq = ModelQueryUtil.getModelQuery(element.getOwnerDocument()); - if (mq != null) { - // 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, mq)) { - return att; - } - } - } - return null; - } - - /** - * Return an attr of element that is "openOn-able" if one exists. null - * otherwise - * - * @param node - - * cannot be null - * @return Attr attribute that can be used for open on, null if no - * attribute could be found - */ - protected Attr getLinkableAttrFromNode(Node node, int offset) { - // check to see if we're already on an attribute we can work with - Attr currentAtt = null; - if (node.getNodeType() == Node.ATTRIBUTE_NODE) { - currentAtt = (Attr) node; - } - else { - Node attN = getCurrentAttrNode(node, offset); - if (attN != null) - currentAtt = (Attr) attN; - } - if ((currentAtt != null) && isLinkableAttr(currentAtt, null)) { - return currentAtt; - } - - // now check the whole element tag and see if there's an attribute we - // can work with - if (node.getNodeType() == Node.ELEMENT_NODE) { - // find an attribute that is "openOn-able" - return getLinkableAttr((Element) node); - } - 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 offset - */ - protected String getURIString(int offset) { - Node currNode = getCurrentNode(offset); - if (currNode != null) { - // need the base location, publicId, and systemId for URIResolver - String baseLoc = null; - String publicId = null; - String systemId = null; - - // handle doc type node - if (currNode.getNodeType() == Node.DOCUMENT_TYPE_NODE) { - baseLoc = getBaseLocation(); - publicId = ((DocumentType) currNode).getPublicId(); - systemId = ((DocumentType) currNode).getSystemId(); - } - else { // handle all other types of nodes - Attr linkableAtt = getLinkableAttrFromNode(currNode, offset); - // found attribute to open on - if (linkableAtt != null) { - baseLoc = getBaseLocation(); - String attrName = linkableAtt.getName(); - String attrValue = linkableAtt.getValue(); - attrValue = StringUtils.strip(attrValue); - - // handle schemaLocation attribute - String prefix = DOMNamespaceHelper.getPrefix(attrName); - String unprefixedName = DOMNamespaceHelper.getUnprefixedName(attrName); - if ((XMLNS.equals(prefix)) || (XMLNS.equals(unprefixedName))) { - publicId = attrValue; - systemId = getLocationHint(linkableAtt.getOwnerElement(), publicId); - } - else if ((XSI_NAMESPACE_URI.equals(DOMNamespaceHelper.getNamespaceURI(linkableAtt))) && (unprefixedName.equals("schemaLocation"))) { //$NON-NLS-1$ - // 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; - } - } - } - - String resolvedURI = resolveURI(baseLoc, publicId, systemId); - return resolvedURI; - } - return null; - } - - /** - * Checks to see if the given attribute is openOn-able. Attribute is - * openOn-able if it is a namespace declaration attribute or if the - * attribute value is of type URI. - * - * @param attr - * cannot be null - * @param query - * ModelQuery associated with the attribute (can be null) - * @return true if this attribute is "openOn-able" false otherwise - */ - protected boolean isLinkableAttr(Attr attr, ModelQuery query) { - String prefix = DOMNamespaceHelper.getPrefix(attr.getName()); - String unprefixedName = DOMNamespaceHelper.getUnprefixedName(attr.getName()); - // 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 (query != null) { - CMAttributeDeclaration attrDecl = query.getCMAttributeDeclaration(attr); - if ((attrDecl != null) && (attrDecl.getAttrType() != null) && (CMDataType.URI.equals(attrDecl.getAttrType().getDataTypeName()))) { - return true; - } - } - return false; - } - - /** - * Resolves the given URI information - * - * @param baseLocation - * @param publicId - * @param systemId - * @return String resolved uri. - */ - protected 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/preferences/EncodingSettings.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/preferences/EncodingSettings.java deleted file mode 100644 index 0cd9607563..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/preferences/EncodingSettings.java +++ /dev/null @@ -1,356 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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.common.encoding.CommonCharsetNames; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; - -/** - * 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 = XMLUIPlugin.getResourceString("%EncodingSettings.1"); //$NON-NLS-1$ - - private static String IANA_LABEL = XMLUIPlugin.getResourceString("%EncodingSettings.0"); //$NON-NLS-1$ - - 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/preferences/WorkbenchDefaultEncodingSettings.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/preferences/WorkbenchDefaultEncodingSettings.java deleted file mode 100644 index 6ee38dc2c6..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/preferences/WorkbenchDefaultEncodingSettings.java +++ /dev/null @@ -1,137 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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.common.encoding.CommonCharsetNames; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; - -/** - * 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.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(XMLUIPlugin.getResourceString("%WorkbenchDefaultEncodingSettings.0")); //$NON-NLS-1$ - - 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(); - } - - private 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/preferences/XMLColorPage.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/preferences/XMLColorPage.java deleted file mode 100644 index f1527a5cd4..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/preferences/XMLColorPage.java +++ /dev/null @@ -1,219 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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.help.WorkbenchHelp; -import org.eclipse.wst.common.encoding.content.IContentTypeIdentifier; -import org.eclipse.wst.sse.core.IModelManager; -import org.eclipse.wst.sse.core.StructuredModelManager; -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.preferences.PreferenceKeyGenerator; -import org.eclipse.wst.sse.ui.preferences.ui.AbstractColorPage; -import org.eclipse.wst.sse.ui.preferences.ui.StyledTextColorPicker; -import org.eclipse.wst.xml.core.parser.XMLRegionContext; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.internal.editor.IHelpContextIds; -import org.eclipse.wst.xml.ui.style.IStyleConstantsXML; - -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); - WorkbenchHelp.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, PreferenceKeyGenerator.generateKey((String) i.next(), IContentTypeIdentifier.ContentTypeID_SSEXML))); - } - - OverlayPreferenceStore.OverlayKey[] keys = new OverlayPreferenceStore.OverlayKey[overlayKeys.size()]; - overlayKeys.toArray(keys); - return keys; - } - - protected IPreferenceStore doGetPreferenceStore() { - return SSEUIPlugin.getDefault().getPreferenceStore(); - } - - public String getSampleText() { - return XMLUIPlugin.getResourceString("%Sample_XML_doc"); //$NON-NLS-1$ = "<?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(XMLRegionContext.XML_COMMENT_OPEN, IStyleConstantsXML.COMMENT_BORDER); - contextStyleMap.put(XMLRegionContext.XML_COMMENT_TEXT, IStyleConstantsXML.COMMENT_TEXT); - contextStyleMap.put(XMLRegionContext.XML_COMMENT_CLOSE, IStyleConstantsXML.COMMENT_BORDER); - - contextStyleMap.put(XMLRegionContext.XML_TAG_OPEN, IStyleConstantsXML.TAG_BORDER); - contextStyleMap.put(XMLRegionContext.XML_END_TAG_OPEN, IStyleConstantsXML.TAG_BORDER); - contextStyleMap.put(XMLRegionContext.XML_TAG_NAME, IStyleConstantsXML.TAG_NAME); - contextStyleMap.put(XMLRegionContext.XML_TAG_ATTRIBUTE_NAME, IStyleConstantsXML.TAG_ATTRIBUTE_NAME); - contextStyleMap.put(XMLRegionContext.XML_TAG_ATTRIBUTE_VALUE, IStyleConstantsXML.TAG_ATTRIBUTE_VALUE); - contextStyleMap.put(XMLRegionContext.XML_TAG_CLOSE, IStyleConstantsXML.TAG_BORDER); - contextStyleMap.put(XMLRegionContext.XML_EMPTY_TAG_CLOSE, IStyleConstantsXML.TAG_BORDER); - - contextStyleMap.put(XMLRegionContext.XML_DECLARATION_OPEN, IStyleConstantsXML.DECL_BORDER); - contextStyleMap.put(XMLRegionContext.XML_DECLARATION_CLOSE, IStyleConstantsXML.DECL_BORDER); - contextStyleMap.put(XMLRegionContext.XML_ELEMENT_DECLARATION, IStyleConstantsXML.DECL_BORDER); - contextStyleMap.put(XMLRegionContext.XML_ELEMENT_DECL_CLOSE, IStyleConstantsXML.DECL_BORDER); - - contextStyleMap.put(XMLRegionContext.XML_CONTENT, IStyleConstantsXML.XML_CONTENT); - } - - protected void initCommonDescriptions(Dictionary descriptions) { - - // create descriptions for hilighting types - descriptions.put(IStyleConstantsXML.COMMENT_BORDER, XMLUIPlugin.getResourceString("%Comment_Delimiters_UI_")); //$NON-NLS-1$ = "Comment Delimiters" - descriptions.put(IStyleConstantsXML.COMMENT_TEXT, XMLUIPlugin.getResourceString("%Comment_Content_UI_")); //$NON-NLS-1$ = "Comment Content" - descriptions.put(IStyleConstantsXML.TAG_BORDER, XMLUIPlugin.getResourceString("%Tag_Delimiters_UI_")); //$NON-NLS-1$ = "Tag Delimiters" - descriptions.put(IStyleConstantsXML.TAG_NAME, XMLUIPlugin.getResourceString("%Tag_Names_UI_")); //$NON-NLS-1$ = "Tag Names" - descriptions.put(IStyleConstantsXML.TAG_ATTRIBUTE_NAME, XMLUIPlugin.getResourceString("%Attribute_Names_UI_")); //$NON-NLS-1$ = "Attribute Names" - descriptions.put(IStyleConstantsXML.TAG_ATTRIBUTE_VALUE, XMLUIPlugin.getResourceString("%Attribute_Values_UI_")); //$NON-NLS-1$ = "Attribute Values" - descriptions.put(IStyleConstantsXML.DECL_BORDER, XMLUIPlugin.getResourceString("%Declaration_Delimiters_UI_")); //$NON-NLS-1$ = "Declaration Delimiters" - descriptions.put(IStyleConstantsXML.XML_CONTENT, XMLUIPlugin.getResourceString("%Content_UI_")); //$NON-NLS-1$ = "Content" - } - - 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); - } - - protected void initContextStyleMap(Dictionary contextStyleMap) { - - initCommonContextStyleMap(contextStyleMap); - initDocTypeContextStyleMap(contextStyleMap); - contextStyleMap.put(XMLRegionContext.XML_CDATA_OPEN, IStyleConstantsXML.CDATA_BORDER); - contextStyleMap.put(XMLRegionContext.XML_CDATA_TEXT, IStyleConstantsXML.CDATA_TEXT); - contextStyleMap.put(XMLRegionContext.XML_CDATA_CLOSE, IStyleConstantsXML.CDATA_BORDER); - - contextStyleMap.put(XMLRegionContext.XML_PI_OPEN, IStyleConstantsXML.PI_BORDER); - contextStyleMap.put(XMLRegionContext.XML_PI_CONTENT, IStyleConstantsXML.PI_CONTENT); - contextStyleMap.put(XMLRegionContext.XML_PI_CLOSE, IStyleConstantsXML.PI_BORDER); - - } - - protected void initDescriptions(Dictionary descriptions) { - - initCommonDescriptions(descriptions); - initDocTypeDescriptions(descriptions); - descriptions.put(IStyleConstantsXML.CDATA_BORDER, XMLUIPlugin.getResourceString("%CDATA_Delimiters_UI_")); //$NON-NLS-1$ = "CDATA Delimiters" - descriptions.put(IStyleConstantsXML.CDATA_TEXT, XMLUIPlugin.getResourceString("%CDATA_Content_UI_")); //$NON-NLS-1$ = "CDATA Content" - descriptions.put(IStyleConstantsXML.PI_BORDER, XMLUIPlugin.getResourceString("%Processing_Instruction_Del_UI_")); //$NON-NLS-1$ = "Processing Instruction Delimiters" - descriptions.put(IStyleConstantsXML.PI_CONTENT, XMLUIPlugin.getResourceString("%Processing_Instruction_Con_UI__UI_")); //$NON-NLS-1$ = "Processing Instruction Content" - } - - protected void initDocTypeContextStyleMap(Dictionary contextStyleMap) { - - contextStyleMap.put(XMLRegionContext.XML_ELEMENT_DECL_NAME, IStyleConstantsXML.DOCTYPE_NAME); - contextStyleMap.put(XMLRegionContext.XML_DOCTYPE_DECLARATION, IStyleConstantsXML.TAG_NAME); - contextStyleMap.put(XMLRegionContext.XML_DOCTYPE_DECLARATION_CLOSE, IStyleConstantsXML.DECL_BORDER); - - contextStyleMap.put(XMLRegionContext.XML_DOCTYPE_NAME, IStyleConstantsXML.DOCTYPE_NAME); - contextStyleMap.put(XMLRegionContext.XML_DOCTYPE_EXTERNAL_ID_PUBLIC, IStyleConstantsXML.DOCTYPE_EXTERNAL_ID); - contextStyleMap.put(XMLRegionContext.XML_DOCTYPE_EXTERNAL_ID_PUBREF, IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_PUBREF); - contextStyleMap.put(XMLRegionContext.XML_DOCTYPE_EXTERNAL_ID_SYSTEM, IStyleConstantsXML.DOCTYPE_EXTERNAL_ID); - contextStyleMap.put(XMLRegionContext.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, XMLUIPlugin.getResourceString("%DOCTYPE_Name_UI_")); //$NON-NLS-1$ = "DOCTYPE Name" - descriptions.put(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID, XMLUIPlugin.getResourceString("%DOCTYPE_SYSTEM/PUBLIC_Keyw_UI_")); //$NON-NLS-1$ = "DOCTYPE SYSTEM/PUBLIC Keyword" - descriptions.put(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_PUBREF, XMLUIPlugin.getResourceString("%DOCTYPE_Public_Reference_UI_")); //$NON-NLS-1$ = "DOCTYPE Public Reference" - descriptions.put(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_SYSREF, XMLUIPlugin.getResourceString("%DOCTYPE_System_Reference_UI_")); //$NON-NLS-1$ = "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.getInstance().getModelManager(); - picker.setParser(mmanager.createStructuredDocumentFor(IContentTypeIdentifier.ContentTypeID_SSEXML).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); - - picker.setGeneratorKey(IContentTypeIdentifier.ContentTypeID_SSEXML); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/preferences/XMLFilesPreferencePage.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/preferences/XMLFilesPreferencePage.java deleted file mode 100644 index 1ffffe4d89..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/preferences/XMLFilesPreferencePage.java +++ /dev/null @@ -1,200 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.preferences; - -import java.util.Vector; - -import org.eclipse.core.runtime.Preferences; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.swt.layout.GridData; -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.help.WorkbenchHelp; -import org.eclipse.wst.common.encoding.CommonEncodingPreferenceNames; -import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; -import org.eclipse.wst.sse.ui.preferences.ui.AbstractPreferencePage; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.eclipse.wst.xml.ui.internal.editor.IHelpContextIds; - -public class XMLFilesPreferencePage extends AbstractPreferencePage { - protected EncodingSettings fEncodingSettings = null; - - protected Combo fEndOfLineCode = null; - private Vector fEOLCodes = null; - - protected Control createContents(Composite parent) { - Composite composite = (Composite) super.createContents(parent); - WorkbenchHelp.setHelp(composite, IHelpContextIds.XML_PREFWEBX_FILES_HELPID); - createContentsForCreatingOrSavingGroup(composite); - createContentsForCreatingGroup(composite); - - setSize(composite); - loadPreferences(); - - return composite; - } - - protected void createContentsForCreatingGroup(Composite parent) { - Group creatingGroup = createGroup(parent, 1); - creatingGroup.setText(SSEUIPlugin.getResourceString("%Creating_files")); //$NON-NLS-1$ - - Label label = createLabel(creatingGroup, SSEUIPlugin.getResourceString("%Encoding_desc")); //$NON-NLS-1$ - - fEncodingSettings = new EncodingSettings(creatingGroup, SSEUIPlugin.getResourceString("%Encoding")); //$NON-NLS-1$ - } - - protected void createContentsForCreatingOrSavingGroup(Composite parent) { - Group creatingOrSavingGroup = createGroup(parent, 2); - creatingOrSavingGroup.setText(SSEUIPlugin.getResourceString("%Creating_or_saving_files")); //$NON-NLS-1$ - - Label label = createLabel(creatingOrSavingGroup, SSEUIPlugin.getResourceString("%End-of-line_code_desc")); //$NON-NLS-1$ - ((GridData) label.getLayoutData()).horizontalSpan = 2; - ((GridData) label.getLayoutData()).grabExcessHorizontalSpace = true; - - createLabel(creatingOrSavingGroup, SSEUIPlugin.getResourceString("%End-of-line_code")); //$NON-NLS-1$ - fEndOfLineCode = createDropDownBox(creatingOrSavingGroup); - populateLineDelimiters(); - } - - protected IPreferenceStore doGetPreferenceStore() { - return SSEUIPlugin.getDefault().getPreferenceStore(); - } - - protected void doSavePreferenceStore() { - XMLCorePlugin.getDefault().savePluginPreferences(); // model - } - - /** - * Return the currently selected line delimiter preference - * - * @return a line delimiter constant from CommonEncodingPreferenceNames - */ - private String getCurrentEOLCode() { - int i = fEndOfLineCode.getSelectionIndex(); - if (i >= 0) { - return (String) (fEOLCodes.elementAt(i)); - } - return ""; //$NON-NLS-1$ - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.preferences.ui.AbstractPreferencePage#getModelPreferences() - */ - protected Preferences getModelPreferences() { - return XMLCorePlugin.getDefault().getPluginPreferences(); - } - - protected void initializeValues() { - initializeValuesForCreatingOrSavingGroup(); - initializeValuesForCreatingGroup(); - } - - protected void initializeValuesForCreatingGroup() { - String encoding = getModelPreferences().getString(CommonEncodingPreferenceNames.OUTPUT_CODESET); - - fEncodingSettings.setIANATag(encoding); - } - - protected void initializeValuesForCreatingOrSavingGroup() { - String endOfLineCode = getModelPreferences().getString(CommonEncodingPreferenceNames.END_OF_LINE_CODE); - - if (endOfLineCode.length() > 0) - setCurrentEOLCode(endOfLineCode); - else - setCurrentEOLCode(CommonEncodingPreferenceNames.NO_TRANSLATION); - } - - protected void performDefaults() { - performDefaultsForCreatingOrSavingGroup(); - performDefaultsForCreatingGroup(); - - super.performDefaults(); - } - - protected void performDefaultsForCreatingGroup() { - String encoding = getModelPreferences().getDefaultString(CommonEncodingPreferenceNames.OUTPUT_CODESET); - - fEncodingSettings.setIANATag(encoding); - // fEncodingSettings.resetToDefaultEncoding(); - } - - protected void performDefaultsForCreatingOrSavingGroup() { - String endOfLineCode = getModelPreferences().getDefaultString(CommonEncodingPreferenceNames.END_OF_LINE_CODE); - - if (endOfLineCode.length() > 0) - setCurrentEOLCode(endOfLineCode); - else - setCurrentEOLCode(CommonEncodingPreferenceNames.NO_TRANSLATION); - } - - public boolean performOk() { - boolean result = super.performOk(); - - doSavePreferenceStore(); - - return result; - } - - /** - * Populates the vector containing the line delimiter to display string - * mapping and the combobox displaying line delimiters - */ - private void populateLineDelimiters() { - fEOLCodes = new Vector(); - fEndOfLineCode.add(SSEUIPlugin.getResourceString("%EOL_Unix")); //$NON-NLS-1$ - fEOLCodes.add(CommonEncodingPreferenceNames.LF); - - fEndOfLineCode.add(SSEUIPlugin.getResourceString("%EOL_Mac")); //$NON-NLS-1$ - fEOLCodes.add(CommonEncodingPreferenceNames.CR); - - fEndOfLineCode.add(SSEUIPlugin.getResourceString("%EOL_Windows")); //$NON-NLS-1$ - fEOLCodes.add(CommonEncodingPreferenceNames.CRLF); - - fEndOfLineCode.add(SSEUIPlugin.getResourceString("%EOL_NoTranslation")); //$NON-NLS-1$ - fEOLCodes.add(CommonEncodingPreferenceNames.NO_TRANSLATION); - } - - /** - * Select the line delimiter in the eol combobox - * - */ - private void setCurrentEOLCode(String eolCode) { - // Clear the current selection. - fEndOfLineCode.clearSelection(); - fEndOfLineCode.deselectAll(); - - int i = fEOLCodes.indexOf(eolCode); - if (i >= 0) { - fEndOfLineCode.select(i); - } - } - - protected void storeValues() { - storeValuesForCreatingOrSavingGroup(); - storeValuesForCreatingGroup(); - } - - protected void storeValuesForCreatingGroup() { - getModelPreferences().setValue(CommonEncodingPreferenceNames.OUTPUT_CODESET, fEncodingSettings.getIANATag()); - } - - protected void storeValuesForCreatingOrSavingGroup() { - String eolCode = getCurrentEOLCode(); - getModelPreferences().setValue(CommonEncodingPreferenceNames.END_OF_LINE_CODE, eolCode); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/preferences/XMLSourcePreferencePage.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/preferences/XMLSourcePreferencePage.java deleted file mode 100644 index f2c303599a..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/preferences/XMLSourcePreferencePage.java +++ /dev/null @@ -1,246 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.preferences; - -import org.eclipse.core.runtime.Preferences; -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.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.IWorkbenchPreferencePage; -import org.eclipse.ui.help.WorkbenchHelp; -import org.eclipse.wst.common.encoding.content.IContentTypeIdentifier; -import org.eclipse.wst.sse.core.preferences.CommonModelPreferenceNames; -import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; -import org.eclipse.wst.sse.ui.preferences.CommonEditorPreferenceNames; -import org.eclipse.wst.sse.ui.preferences.PreferenceKeyGenerator; -import org.eclipse.wst.sse.ui.preferences.ui.AbstractPreferencePage; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.eclipse.wst.xml.ui.internal.editor.IHelpContextIds; - -public class XMLSourcePreferencePage extends AbstractPreferencePage implements ModifyListener, SelectionListener, IWorkbenchPreferencePage { - // Content Assist - protected Button fAutoPropose; - protected Label fAutoProposeLabel; - protected Text fAutoProposeText; - protected Button fClearAllBlankLines; - protected Button fIndentUsingTabs; - // Formatting - protected Label fLineWidthLabel; - protected Text fLineWidthText; - protected Button fSplitMultiAttrs; - // grammar constraints - protected Button fUseInferredGrammar; - - protected Control createContents(Composite parent) { - Composite composite = (Composite) super.createContents(parent); - WorkbenchHelp.setHelp(composite, IHelpContextIds.XML_PREFWEBX_SOURCE_HELPID); - - createContentsForFormattingGroup(composite); - createContentsForContentAssistGroup(composite); - createContentsForGrammarConstraintsGroup(composite); - setSize(composite); - loadPreferences(); - - return composite; - } - - protected void createContentsForContentAssistGroup(Composite parent) { - Group contentAssistGroup = createGroup(parent, 2); - contentAssistGroup.setText(SSEUIPlugin.getResourceString("%Content_assist_UI_")); //$NON-NLS-1$ = "Content assist" - - fAutoPropose = createCheckBox(contentAssistGroup, SSEUIPlugin.getResourceString("%Automatically_make_suggest_UI_")); //$NON-NLS-1$ = "Automatically make suggestions" - ((GridData) fAutoPropose.getLayoutData()).horizontalSpan = 2; - fAutoPropose.addSelectionListener(this); - - fAutoProposeLabel = createLabel(contentAssistGroup, SSEUIPlugin.getResourceString("%Prompt_when_these_characte_UI_")); //$NON-NLS-1$ = "Prompt when these characters are inserted:" - fAutoProposeText = createTextField(contentAssistGroup); - } - - protected void createContentsForFormattingGroup(Composite parent) { - Group formattingGroup = createGroup(parent, 2); - formattingGroup.setText(SSEUIPlugin.getResourceString("%Formatting_UI_")); //$NON-NLS-1$ = "Formatting" - - fLineWidthLabel = createLabel(formattingGroup, SSEUIPlugin.getResourceString("%Line_width__UI_")); //$NON-NLS-1$ = "Line width:" - 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, SSEUIPlugin.getResourceString("%Split_&multiple_attributes_2")); //$NON-NLS-1$ - ((GridData) fSplitMultiAttrs.getLayoutData()).horizontalSpan = 2; - - fIndentUsingTabs = createCheckBox(formattingGroup, SSEUIPlugin.getResourceString("%&Indent_using_tabs_3")); //$NON-NLS-1$ - ((GridData) fIndentUsingTabs.getLayoutData()).horizontalSpan = 2; - - fClearAllBlankLines = createCheckBox(formattingGroup, SSEUIPlugin.getResourceString("%Clear_all_blank_lines_UI_")); //$NON-NLS-1$ = "Clear all blank lines" - ((GridData) fClearAllBlankLines.getLayoutData()).horizontalSpan = 2; - } - - protected void createContentsForGrammarConstraintsGroup(Composite parent) { - Group grammarConstraintsGroup = createGroup(parent, 1); - grammarConstraintsGroup.setText(SSEUIPlugin.getResourceString("%Grammar_Constraints")); //$NON-NLS-1$ - grammarConstraintsGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); - - fUseInferredGrammar = createCheckBox(grammarConstraintsGroup, SSEUIPlugin.getResourceString("%Use_inferred_grammar_in_absence_of_DTD/Schema")); //$NON-NLS-1$ - } - - protected IPreferenceStore doGetPreferenceStore() { - return SSEUIPlugin.getDefault().getPreferenceStore(); - } - - protected void doSavePreferenceStore() { - SSEUIPlugin.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); - } - } - } - - /* - * helper method to generate content type id specific preference keys - */ - protected String getKey(String key) { - String contentTypeId = IContentTypeIdentifier.ContentTypeID_SSEXML; - return PreferenceKeyGenerator.generateKey(key, contentTypeId); - } - - protected Preferences getModelPreferences() { - return XMLCorePlugin.getDefault().getPluginPreferences(); - } - - protected void initializeValues() { - initializeValuesForFormattingGroup(); - initializeValuesForContentAssistGroup(); - initializeValuesForGrammarConstraintsGroup(); - } - - protected void initializeValuesForContentAssistGroup() { - // Content Assist - fAutoPropose.setSelection(getPreferenceStore().getBoolean(getKey(CommonEditorPreferenceNames.AUTO_PROPOSE))); - fAutoProposeText.setText(getPreferenceStore().getString(getKey(CommonEditorPreferenceNames.AUTO_PROPOSE_CODE))); - } - - protected void initializeValuesForFormattingGroup() { - // Formatting - fLineWidthText.setText(getModelPreferences().getString(CommonModelPreferenceNames.LINE_WIDTH)); - fSplitMultiAttrs.setSelection(getModelPreferences().getBoolean(CommonModelPreferenceNames.SPLIT_MULTI_ATTRS)); - fIndentUsingTabs.setSelection(getModelPreferences().getBoolean(CommonModelPreferenceNames.INDENT_USING_TABS)); - fClearAllBlankLines.setSelection(getModelPreferences().getBoolean(CommonModelPreferenceNames.CLEAR_ALL_BLANK_LINES)); - } - - protected void initializeValuesForGrammarConstraintsGroup() { - fUseInferredGrammar.setSelection(getPreferenceStore().getBoolean(getKey(CommonEditorPreferenceNames.EDITOR_USE_INFERRED_GRAMMAR))); - } - - protected void performDefaults() { - performDefaultsForFormattingGroup(); - performDefaultsForContentAssistGroup(); - performDefaultsForGrammarConstraintsGroup(); - - validateValues(); - enableValues(); - - super.performDefaults(); - } - - protected void performDefaultsForContentAssistGroup() { - // Content Assist - fAutoPropose.setSelection(getPreferenceStore().getDefaultBoolean(getKey(CommonEditorPreferenceNames.AUTO_PROPOSE))); - fAutoProposeText.setText(getPreferenceStore().getDefaultString(getKey(CommonEditorPreferenceNames.AUTO_PROPOSE_CODE))); - } - - protected void performDefaultsForFormattingGroup() { - // Formatting - fLineWidthText.setText(getModelPreferences().getDefaultString(CommonModelPreferenceNames.LINE_WIDTH)); - fSplitMultiAttrs.setSelection(getModelPreferences().getDefaultBoolean(CommonModelPreferenceNames.SPLIT_MULTI_ATTRS)); - fIndentUsingTabs.setSelection(getModelPreferences().getDefaultBoolean(CommonModelPreferenceNames.INDENT_USING_TABS)); - fClearAllBlankLines.setSelection(getModelPreferences().getDefaultBoolean(CommonModelPreferenceNames.CLEAR_ALL_BLANK_LINES)); - } - - protected void performDefaultsForGrammarConstraintsGroup() { - fUseInferredGrammar.setSelection(getPreferenceStore().getDefaultBoolean(getKey(CommonEditorPreferenceNames.EDITOR_USE_INFERRED_GRAMMAR))); - } - - public boolean performOk() { - boolean result = super.performOk(); - - doSavePreferenceStore(); - - return result; - } - - protected void storeValues() { - storeValuesForFormattingGroup(); - storeValuesForContentAssistGroup(); - storeValuesForGrammarConstraintsGroup(); - } - - protected void storeValuesForContentAssistGroup() { - // Content Assist - getPreferenceStore().setValue(getKey(CommonEditorPreferenceNames.AUTO_PROPOSE), fAutoPropose.getSelection()); - getPreferenceStore().setValue(getKey(CommonEditorPreferenceNames.AUTO_PROPOSE_CODE), fAutoProposeText.getText()); - } - - protected void storeValuesForFormattingGroup() { - // Formatting - getModelPreferences().setValue(CommonModelPreferenceNames.LINE_WIDTH, fLineWidthText.getText()); - getModelPreferences().setValue(CommonModelPreferenceNames.SPLIT_MULTI_ATTRS, fSplitMultiAttrs.getSelection()); - getModelPreferences().setValue(CommonModelPreferenceNames.INDENT_USING_TABS, fIndentUsingTabs.getSelection()); - getModelPreferences().setValue(CommonModelPreferenceNames.CLEAR_ALL_BLANK_LINES, fClearAllBlankLines.getSelection()); - } - - protected void storeValuesForGrammarConstraintsGroup() { - getPreferenceStore().setValue(getKey(CommonEditorPreferenceNames.EDITOR_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; - } - } - - if (!isError) { - setErrorMessage(null); - setValid(true); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/preferences/XMLTemplatePreferencePage.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/preferences/XMLTemplatePreferencePage.java deleted file mode 100644 index b98697fe2f..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/preferences/XMLTemplatePreferencePage.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.preferences; - -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.ui.help.WorkbenchHelp; -import org.eclipse.ui.texteditor.templates.TemplatePreferencePage; -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 { - - 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); - WorkbenchHelp.setHelp(c, IHelpContextIds.XML_PREFWEBX_TEMPLATES_HELPID); - return c; - } - - /* - * (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/reconcile/AbstractReconcileStepAdapter.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/reconcile/AbstractReconcileStepAdapter.java deleted file mode 100644 index 07aae869ee..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/reconcile/AbstractReconcileStepAdapter.java +++ /dev/null @@ -1,156 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.reconcile; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.ITypedRegion; -import org.eclipse.jface.text.reconciler.IReconcileResult; -import org.eclipse.wst.sse.core.INodeNotifier; -import org.eclipse.wst.sse.core.IndexedRegion; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.text.rules.StructuredTextPartitioner; -import org.eclipse.wst.sse.ui.StructuredTextReconciler; -import org.eclipse.wst.sse.ui.internal.reconcile.IReconcileAnnotationKey; -import org.eclipse.wst.sse.ui.internal.reconcile.IReconcileStepAdapter; -import org.eclipse.wst.sse.ui.internal.reconcile.IStructuredReconcileStep; -import org.eclipse.wst.sse.ui.internal.reconcile.ReconcileAnnotationKey; -import org.eclipse.wst.xml.ui.internal.Logger; - - -/** - * This reconcile step is an adapter on the IStructuredModel. Validation is - * triggered from StructuredDocumentEvents - * - * @author pavery - */ -public class AbstractReconcileStepAdapter implements IReconcileStepAdapter { - - protected static final IReconcileResult[] EMPTY_RECONCILE_RESULT_SET = new IReconcileResult[0]; - protected List fDirtyElements = new ArrayList(); - private IStructuredReconcileStep fParentStep = null; - private HashSet fPartitionTypes = null; - - public AbstractReconcileStepAdapter() { - super(); - fPartitionTypes = new HashSet(); - } - - public IReconcileAnnotationKey createKey(IStructuredDocumentRegion sdRegion, int scope) { - ITypedRegion tr = null; - if (!sdRegion.isDeleted()) { - try { - tr = sdRegion.getParentDocument().getPartition(sdRegion.getStartOffset()); - } catch (BadLocationException e) { - // do nothing but leave tr as null - // probably due to changes made on another thread - } - } - String partitionType = (tr != null) ? tr.getType() : StructuredTextPartitioner.ST_UNKNOWN_PARTITION; - return createKey(partitionType, scope); - } - - public IReconcileAnnotationKey createKey(String partitionType, int scope) { - fPartitionTypes.add(partitionType); - return new ReconcileAnnotationKey(getParentStep(), partitionType, scope); - } - - public IStructuredReconcileStep getParentStep() { - return fParentStep; - } - - public String[] getPartitionTypes() { - String[] results = new String[fPartitionTypes.size()]; - System.arraycopy(fPartitionTypes.toArray(), 0, results, 0, results.length); - return results; - } - - - public boolean isAdapterForType(Object type) { - return type == IReconcileStepAdapter.class; - } - - protected boolean isCanceled(IProgressMonitor monitor) { - return monitor != null && monitor.isCanceled(); - } - - /** - * @param notifier - */ - public void markForReconciling(Object notifier) { - synchronized (fDirtyElements) { - // pa_TODO possible bottleneck - if (!fDirtyElements.contains(notifier)) { - Logger.trace(StructuredTextReconciler.TRACE_FILTER, "marking :" + notifier + ": for reconciling"); //$NON-NLS-1$ //$NON-NLS-2$ - fDirtyElements.add(notifier); - } - } - } - - /* - * (non-Javadoc) - * - * @see com.ibm.sed.model.INodeAdapter#notifyChanged(com.ibm.sed.model.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) { - // Adapters are notified before the JFace Document events are sent to - // the IReconciler - markForReconciling(notifier); - } - - public IReconcileResult[] reconcile(IProgressMonitor monitor, IndexedRegion xmlNode) { - List workingElements = null; - List results = new ArrayList(); - - IReconcileResult[] temp = EMPTY_RECONCILE_RESULT_SET; - synchronized (fDirtyElements) { - if (fDirtyElements != null && fDirtyElements.size() > 0) { - workingElements = new ArrayList(); - workingElements.addAll(0, fDirtyElements); - fDirtyElements = new ArrayList(); - } - } - if (workingElements != null) { - Iterator elements = workingElements.iterator(); - while (elements.hasNext() && !isCanceled(monitor)) { - temp = reconcile(elements.next(), monitor); - for (int i = 0; i < temp.length; i++) - results.add(temp[i]); - } - } - temp = new IReconcileResult[results.size()]; - System.arraycopy(results.toArray(), 0, temp, 0, results.size()); - return temp; - } - - protected IReconcileResult[] reconcile(Object o, IProgressMonitor monitor) { - return EMPTY_RECONCILE_RESULT_SET; - } - - /** - * @see org.eclipse.wst.sse.ui.IReleasable#release() - */ - public void release() { - // nothing to release - } - - public void setParentStep(IStructuredReconcileStep parentStep) { - fParentStep = parentStep; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/reconcile/ReconcileStepAdapterForXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/reconcile/ReconcileStepAdapterForXML.java deleted file mode 100644 index 790efc3924..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/reconcile/ReconcileStepAdapterForXML.java +++ /dev/null @@ -1,692 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.reconcile; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.StringTokenizer; -import java.util.Vector; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.text.Position; -import org.eclipse.jface.text.reconciler.IReconcileResult; -import org.eclipse.wst.common.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.common.contentmodel.CMDocument; -import org.eclipse.wst.common.contentmodel.CMElementDeclaration; -import org.eclipse.wst.common.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.common.contentmodel.CMNode; -import org.eclipse.wst.common.contentmodel.modelquery.CMDocumentManager; -import org.eclipse.wst.common.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.common.contentmodel.util.CMDocumentCache; -import org.eclipse.wst.common.contentmodel.util.CMDocumentCacheListener; -import org.eclipse.wst.sse.core.INodeNotifier; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.text.ITextRegion; -import org.eclipse.wst.sse.ui.IReleasable; -import org.eclipse.wst.sse.ui.StructuredTextReconciler; -import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; -import org.eclipse.wst.sse.ui.internal.reconcile.IReconcileAnnotationKey; -import org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation; -import org.eclipse.wst.xml.core.document.XMLAttr; -import org.eclipse.wst.xml.core.document.XMLElement; -import org.eclipse.wst.xml.core.document.XMLNode; -import org.eclipse.wst.xml.core.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.core.parser.XMLRegionContext; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.correction.ProblemIDsXML; -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; - -public class ReconcileStepAdapterForXML extends AbstractReconcileStepAdapter implements CMDocumentCacheListener, IReleasable { - - /** - * Record of notification sent to this adapter. Will be queued up so - * they're not dealt with until reconciling is actually called from the - * reconciler thread. - */ - public class NotificationEvent { - - public Object changedFeature; - - public int eventType; - - public Object newValue; - - public INodeNotifier notifier; - - public Object oldValue; - - public int pos; - - public NotificationEvent(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) { - - this.notifier = notifier; - this.eventType = eventType; - this.changedFeature = changedFeature; - this.oldValue = oldValue; - this.newValue = newValue; - this.pos = pos; - } - - // used (to see if notifications vector "contains()") - // so we don't queue up "duplicate" events, - // (indicates same eventType, notifier, and changedFeature) - public boolean equals(Object o) { - - boolean result = false; - if (o instanceof NotificationEvent) { - NotificationEvent e2 = (NotificationEvent) o; - if (this.notifier == null || e2.notifier == null || this.changedFeature == null || e2.changedFeature == null) { - result = false; - } - result = (this.eventType == e2.eventType && this.notifier == e2.notifier && this.changedFeature == e2.changedFeature); - } - return result; - } - } - - protected boolean fCaseSensitive = true; - protected CMDocumentCache fCMDocumentCache; - protected DocumentType fDocumentTypeForRefresh; - - protected boolean fNeedsRefreshAll = false; - - // required for thread safety - protected List fNotifications = new Vector(); - - // these are used in conjunction w/ cacheUpdated() notification - // in order to refresh the whole document - protected IProgressMonitor fProgressMonitorForRefresh; - - // counter used for repeated reconcile opreations - // to yield the thread control to the next thread - // to improve workbench performance - protected short fReconcileCount = 0; - - // will not attempt to validate attribute names starting with the - // following: - protected String[] ignoreAttributeNamesStartingWith = new String[]{"xmlns", "xsi:", "xml:"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - - // changing these elements may have an impact on the current content model - // (which suggests to mark everything dirty) - protected String[] mayImpactContentModel = new String[]{"DOCTYPE", "xmlns", "xsi", "xmlns:xsi", "xmlns:xsl", "xsi:schemaLocation", "taglib"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ - protected String SEVERITY_MISSING_REQUIRED_ATTR = TemporaryAnnotation.ANNOT_WARNING; - - // severities for the problems discoverable by this reconciler; possibly - // user configurable later - protected String SEVERITY_STRUCTURE = TemporaryAnnotation.ANNOT_ERROR; - protected String SEVERITY_UNKNOWN_ATTR = TemporaryAnnotation.ANNOT_ERROR; - protected String SEVERITY_UNKNOWN_ELEMENT = TemporaryAnnotation.ANNOT_ERROR; - - public ReconcileStepAdapterForXML() { - - super(); - } - - public void cacheCleared(CMDocumentCache arg0) { - // do nothing - } - - public void cacheUpdated(CMDocumentCache arg0, String arg1, int arg2, int arg3, CMDocument arg4) { - - // revalidate all - if (Logger.isTracing(StructuredTextReconciler.TRACE_FILTER)) { - String message = "[trace reconciler] > \r\n====================" + "\n cache updated:" + "\n arg0 :" + arg0 + "\n arg1 :" + arg1 + "\n arg3 :" + arg3 + "\n arg4 :" + arg4; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ - Logger.trace(StructuredTextReconciler.TRACE_FILTER, message); - } - if (arg3 == CMDocumentCache.STATUS_LOADED) { - Logger.trace(StructuredTextReconciler.TRACE_FILTER, "CMDocument finished loading :" + arg1); //$NON-NLS-1$ - doRefreshAll((INodeNotifier) fDocumentTypeForRefresh, fProgressMonitorForRefresh); - } - } - - protected IReconcileResult[] doRefreshAll(INodeNotifier notifier, IProgressMonitor monitor) { - - Logger.trace(StructuredTextReconciler.TRACE_FILTER, "[trace reconciler] > refreshing all"); //$NON-NLS-1$ - - synchronized (fDirtyElements) { - fDirtyElements.clear(); - } - Document doc = (((Node) notifier).getNodeType() != Node.DOCUMENT_NODE) ? ((Node) notifier).getOwnerDocument() : (Document) notifier; - return reconcileSubtree((INodeNotifier) doc, monitor); - } - - protected ModelQuery getModelQuery(Node node) { - - return (node.getNodeType() == Node.DOCUMENT_NODE) ? ModelQueryUtil.getModelQuery((Document) node) : ModelQueryUtil.getModelQuery(node.getOwnerDocument()); - } - - /** - * returns a list of required CMAttributeDeclarations for the given - * element. - * - * @param elementDecl - * - */ - protected List getRequiredAttributes(CMElementDeclaration elementDecl) { - - CMNamedNodeMap attrMap = elementDecl.getAttributes(); - Iterator it = attrMap.iterator(); - CMAttributeDeclaration attr = null; - List result = new ArrayList(); - while (it.hasNext()) { - attr = (CMAttributeDeclaration) it.next(); - if (attr.getUsage() == CMAttributeDeclaration.REQUIRED) { - result.add(attr); - } - } - return result; - } - - /** - * Determine if this Document is an XML/XHTML Document and whether to be - * case sensitive - */ - protected boolean isCaseSensitive(Node node) { - - return true; - } - - // CMVC 254838 - /** - * Indicates if the element is not in the ContentModel (if it's not in the - * ContentModel, but its parent is) - * - * @param element - * @param modelQuery - * @return whether or not the element is unknown according to its - * associated ContentModel. - */ - protected boolean isUnknown(Element element, ModelQuery modelQuery) { - - boolean result = false; - CMElementDeclaration ed = modelQuery.getCMElementDeclaration(element); - if (ed == null) { - // make sure parent declaration exists, and is not inferred - Node parentNode = element.getParentNode(); - if (parentNode != null && parentNode.getNodeType() == Node.ELEMENT_NODE) { - CMElementDeclaration parentEd = modelQuery.getCMElementDeclaration((Element) parentNode); - // 2/19/04 porting iFix for lax schema suppport - result = (parentEd != null) && !Boolean.TRUE.equals(parentEd.getProperty("isInferred")) //$NON-NLS-1$ - && !Boolean.TRUE.equals(parentEd.getProperty("isLax")); //$NON-NLS-1$ - } - // need one error for the root at least - // to indicate the document is wrong... - Document ownerDoc = element.getOwnerDocument(); - if (ownerDoc != null && ownerDoc.getDocumentElement() == element) { - CMDocument cmDoc = modelQuery.getCorrespondingCMDocument(ownerDoc); - result = (cmDoc != null && cmDoc.getElements().getLength() > 0); - } - } else { - if (ed.getProperty("isInferred") != null && Boolean.TRUE.equals(ed.getProperty("isInferred")) //$NON-NLS-1$ //$NON-NLS-2$ - || (ed.getProperty("partialContentModel") != null && Boolean.TRUE.equals(ed.getProperty("partialContentModel")))) { //$NON-NLS-1$ //$NON-NLS-2$ - result = false; - } - } - return result; - } - - /** - * Checks if name matches any mayImpactContentModel[] strings - * - * @param name - * @return if a match is found, return true, else return false - */ - private boolean mayAffectContentModel(String name) { - - // TODO (pa) may need to be smarter if the attribute name is broken... - StringTokenizer st = new StringTokenizer(name, ":", false); //$NON-NLS-1$ - String prefix = ""; //$NON-NLS-1$ - if (st.hasMoreTokens()) - prefix = st.nextToken(); - for (int i = 0; i < mayImpactContentModel.length; i++) { - if (mayImpactContentModel[i].indexOf(name) != -1 || mayImpactContentModel[i].startsWith(prefix)) - return true; - } - return false; - } - - public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) { - - synchronized (fNotifications) { - NotificationEvent newEvent = new NotificationEvent(notifier, eventType, changedFeature, oldValue, newValue, pos); - if (!fNotifications.contains(newEvent)) - fNotifications.add(newEvent); - } - } - - - public void processNotification(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos, IProgressMonitor monitor) { - - if (isCanceled(monitor)) - return; - - // (nsd) pa_TODO: we need to mark more or widen the scope affected by - // the next reconcile() call - // TODO: Handle multi-Node changes from Doctype Declarations, Taglib - // directives, - // and schema and namespace related attributes (DOCTYPE, taglib, - // xmlns, - // xsi...) - // ** we currently don't get a notify on changed taglib... - - // we're going to validate everything again anyways after - // proccessNotifications() has completed (in reconcile(): - // processNotifications() > refreshAll()), - // no sense to do it here if we refreshingAll - if (fNeedsRefreshAll) - return; - if (eventType == INodeNotifier.CHANGE || eventType == INodeNotifier.REMOVE) { - if (changedFeature instanceof Node && ((Node) changedFeature).getNodeType() == Node.ATTRIBUTE_NODE) { - if (mayAffectContentModel(((Node) changedFeature).getNodeName())) { - fNeedsRefreshAll = true; - } - } else if (changedFeature instanceof Node && ((Node) changedFeature).getNodeType() == Node.DOCUMENT_TYPE_NODE) { - fNeedsRefreshAll = true; - } else if (notifier instanceof Node && ((Node) notifier).getNodeType() == Node.DOCUMENT_TYPE_NODE) { - fNeedsRefreshAll = true; - } else { - // pa_TODO need to handle taglib definition changes... - // if(mayAffectContentModel(((Node)changedFeature).getNodeName())) - // { - // System.out.println("dunno what changed > " + - // changedFeature); - // fNeedsRefreshAll = true; - // } - } - if (isCanceled(monitor)) - return; - fNeedsRefreshAll = true; - } - if (eventType == INodeNotifier.CHANGE && changedFeature instanceof Element) { - markForReconciling(changedFeature); - } else if (eventType == INodeNotifier.ADD && newValue instanceof Node) { - Node newNode = (Node) newValue; - if (newNode.getNodeType() == Node.DOCUMENT_TYPE_NODE || newNode.getNodeName().equals("jsp:directive.taglib")) { // $NON-NLS-1$ - // //$NON-NLS-1$ - fNeedsRefreshAll = true; - } else { - markForReconciling(newNode); - } - } - markForReconciling(notifier); - } - - protected void processNotifications(IProgressMonitor monitor) { - - fProgressMonitorForRefresh = monitor; - NotificationEvent[] events = null; - synchronized (fNotifications) { - if (fNotifications.isEmpty()) { - return; - } - events = (NotificationEvent[]) fNotifications.toArray(new NotificationEvent[0]); - fNotifications.clear(); - } - for (int i = 0; i < events.length; i++) { - processNotification(events[i].notifier, events[i].eventType, events[i].changedFeature, events[i].oldValue, events[i].newValue, events[i].pos, monitor); - } - } - - - public IReconcileResult[] reconcile(IProgressMonitor monitor, XMLNode xmlNode) { - - processNotifications(monitor); - IReconcileResult[] results = EMPTY_RECONCILE_RESULT_SET; - if (fNeedsRefreshAll) { - results = doRefreshAll(xmlNode, monitor); - fNeedsRefreshAll = false; - } else { - results = super.reconcile(monitor, xmlNode); - } - return results; - } - - /** - * Called by super.reconcile(IAnnotationModel) on each Notifier - * - */ - protected IReconcileResult[] reconcile(Object o, IProgressMonitor monitor) { - - super.reconcile(o, monitor); - ModelQuery mq = null; - if (o instanceof XMLNode) { - XMLNode xmlNode = (XMLNode) o; - mq = getModelQuery(xmlNode); - if (mq != null) { - fCaseSensitive = isCaseSensitive(xmlNode); - return validate(mq, xmlNode); - } - } - - // if we are in a large reconciling loop (like when reconciling the - // entire doc), this ensures - // that other Threads have a chance to run. - yieldIfNeeded(); - return EMPTY_RECONCILE_RESULT_SET; - } - - /** - * Reconcile the Node and all children of the Notifier passed in. - * - * @param notifier - * @param monitor - */ - protected IReconcileResult[] reconcileSubtree(INodeNotifier notifier, IProgressMonitor monitor) { - - IReconcileResult[] temp = EMPTY_RECONCILE_RESULT_SET; - List results = new ArrayList(); - if (!isCanceled(monitor)) { - if (notifier != null && notifier instanceof XMLNode) { - XMLNode current = (XMLNode) notifier; - // loop siblings - while (current != null) { - // mark whatever type nodes we wanna make dirty - if (current.getNodeType() == Node.ELEMENT_NODE || current.getNodeType() == Node.DOCUMENT_TYPE_NODE || current.getNodeType() == Node.DOCUMENT_NODE || current.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) { - temp = reconcile(current, monitor); - for (int i = 0; i < temp.length; i++) - results.add(temp[i]); - } - // drop one level deeper if necessary - if (current.getFirstChild() != null) { - temp = reconcileSubtree((INodeNotifier) current.getFirstChild(), monitor); - for (int i = 0; i < temp.length; i++) - results.add(temp[i]); - } - current = (XMLNode) current.getNextSibling(); - } - } - temp = new IReconcileResult[results.size()]; - System.arraycopy(results.toArray(), 0, temp, 0, results.size()); - } - return temp; - } - - /** - * Called from the ReconcileAdapterFactory - * - */ - public void release() { - - if (fCMDocumentCache != null) { - fCMDocumentCache.removeListener(this); - fCMDocumentCache = null; - } - } - - /** - * Determines whether the given Attr should not be validated according to - * the ignoreAttributeNamesStartingWith array - * - * @param attr - */ - protected boolean shouldIgnore(Attr attr) { - - boolean result = false; - String name = attr.getNodeName(); - for (int i = 0; i < ignoreAttributeNamesStartingWith.length; i++) { - if (fCaseSensitive) { - if (name.startsWith(ignoreAttributeNamesStartingWith[i])) - result = true; - } else { - try { - if (name.length() >= ignoreAttributeNamesStartingWith[i].length() && ignoreAttributeNamesStartingWith[i].equalsIgnoreCase(name.substring(0, ignoreAttributeNamesStartingWith[i].length()))) - result = true; - } catch (StringIndexOutOfBoundsException e) { - result = true; - } - } - } - return result; - } - - private void updateCMDocumentCache(ModelQuery mq, XMLNode xmlNode) { - - if (mq != null) { - CMDocumentManager cmDocManager = mq.getCMDocumentManager(); - if (cmDocManager != null) { - CMDocumentCache newCache = cmDocManager.getCMDocumentCache(); - if (newCache != null) { - if (fCMDocumentCache == null) { - // create fCMDocCache if necessary - fCMDocumentCache = newCache; - fCMDocumentCache.addListener(this); - fDocumentTypeForRefresh = (DocumentType) xmlNode; - } else if (fCMDocumentCache != newCache) { - fCMDocumentCache.removeListener(this); - fCMDocumentCache = newCache; - fCMDocumentCache.addListener(this); - fDocumentTypeForRefresh = (DocumentType) xmlNode; - } - } - } - } - } - - /** - * Called by reconcile(IAnnotationModel, Object) when the Object is a - * Notifier - * - */ - protected IReconcileResult[] validate(ModelQuery mq, XMLNode xmlNode) { - - List results = new ArrayList(); - if (xmlNode == null || !(xmlNode.getNodeType() == Node.ELEMENT_NODE || xmlNode.getNodeType() == Node.DOCUMENT_TYPE_NODE)) - return EMPTY_RECONCILE_RESULT_SET; - // return early if the Node has gone stale - if (xmlNode.getParentNode() == null || xmlNode.getOwnerDocument() == null) { - return EMPTY_RECONCILE_RESULT_SET; - } - if (xmlNode.getNodeType() == Node.DOCUMENT_TYPE_NODE) { - // sets CMDocumentCacheListener (this) - updateCMDocumentCache(mq, xmlNode); - } - CMDocument doc = mq.getCorrespondingCMDocument(xmlNode.getOwnerDocument()); - // looks like this is a bad check to do... I thought we took it out - // before - // if(doc == null) - // return EMPTY_RECONCILE_RESULT_SET; - if (doc != null && doc.getElements().getLength() == 0) { - // an empty document - return EMPTY_RECONCILE_RESULT_SET; - } - // continue on null or FALSE; inferred grammars aren't predefined so - // there's no point in continuing - if (doc != null && doc.getProperty("isInferred") != null && Boolean.TRUE.equals(doc.getProperty("isInferred"))) { //$NON-NLS-1$ //$NON-NLS-2$ - return EMPTY_RECONCILE_RESULT_SET; - } - - // if xmlNode is DOCTYPE, skip to the first element - // if there are no elements, return (don't validate) - XMLNode elementNode = xmlNode; - if (xmlNode.getNodeType() == Node.DOCUMENT_TYPE_NODE) { - boolean elementFound = false; - while ((elementNode = (XMLNode) elementNode.getNextSibling()) != null) { - if (elementNode.getNodeType() == Node.ELEMENT_NODE) { - elementFound = true; - break; - } - } - if (!elementFound) - return EMPTY_RECONCILE_RESULT_SET; - } - XMLElement element = (XMLElement) elementNode; - // boolean needsEndTag = true; - - // test for a known element, if it's known, continue validating it - CMElementDeclaration elementDecl = mq.getCMElementDeclaration(element); - if (elementDecl != null) { - // needsEndTag = needsEndTag(elementNode, elementDecl); - NamedNodeMap attrs = element.getAttributes(); - List reqAttrList = getRequiredAttributes(elementDecl); - for (int i = 0; i < attrs.getLength(); i++) { - XMLAttr attr = (XMLAttr) attrs.item(i); - if (!shouldIgnore(attr)) { - - // iFix V511i - // CMVC 272647, attributes with namespace prefix get - // marked - // as error (even though they aren't) - // CMNode attrDecl = - // elementDecl.getAttributes().getNamedItem(attr.getNodeName()); - CMNode attrDecl = elementDecl.getAttributes().getNamedItem(attr.getLocalName()); - - // test for a known attribute - if (attrDecl != null) { - // test for a known value (if there is an enumerated - // list of them) - String[] values = mq.getPossibleDataTypeValues(element, attrDecl); - String currentValue = attr.getValue(); - boolean found = valueMatch(values, currentValue); - if (!found) { - int start = attr.getValueRegionStartOffset(); - int length = attr.getValueRegion().getTextLength(); - Object[] args = {currentValue.trim()}; - String message = SSEUIPlugin.getResourceString("%Invalid_value_{0}", args); - Position p = new Position(start, length); - IReconcileAnnotationKey key = createKey(elementNode.getFirstStructuredDocumentRegion(), IReconcileAnnotationKey.PARTIAL); - results.add(new TemporaryAnnotation(p, SEVERITY_UNKNOWN_ATTR, message, key)); - } - // remove from known required attribute list - reqAttrList.remove(attrDecl); - } else { - Object[] args = {attr.getName()}; - String message = SSEUIPlugin.getResourceString("%Unknown_attribute_{0}", args); - int start = attr.getNameRegionStartOffset(); - int length = attr.getNameRegion().getTextLength(); - Position p = new Position(start, length); - IReconcileAnnotationKey key = createKey(elementNode.getFirstStructuredDocumentRegion(), IReconcileAnnotationKey.PARTIAL); - results.add(new TemporaryAnnotation(p, SEVERITY_UNKNOWN_ATTR, message, key, ProblemIDsXML.UnknownAttr)); - } - } else { - // remove so we don't flag "ignored" attributes as missing - reqAttrList.remove(elementDecl.getAttributes().getNamedItem(attr.getNodeName())); - } - } - // if there are missing required attributes, create annotations - // for - // them - if (reqAttrList != null && !reqAttrList.isEmpty()) { - Iterator it = reqAttrList.iterator(); - int start = 0; - int length = 1; - CMAttributeDeclaration attr = null; - while (it.hasNext()) { - attr = (CMAttributeDeclaration) it.next(); - // sometimes getFirstStructuredDocumentRegion can return - // null, this is a safety - start = (element.getFirstStructuredDocumentRegion() != null) ? element.getFirstStructuredDocumentRegion().getStartOffset() : element.getStartOffset(); - length = (element.getFirstStructuredDocumentRegion() != null) ? element.getFirstStructuredDocumentRegion().getLength() : 1; - - Object[] args = {attr.getAttrName()}; - String message = SSEUIPlugin.getResourceString("%Missing_required_attribute_{0}", args); - - Position p = new Position(start, length); - IReconcileAnnotationKey key = createKey(elementNode.getFirstStructuredDocumentRegion(), IReconcileAnnotationKey.PARTIAL); - TemporaryAnnotation annotation = new TemporaryAnnotation(p, SEVERITY_MISSING_REQUIRED_ATTR, message, key, ProblemIDsXML.MissingRequiredAttr); - - IStructuredDocumentRegion startStructuredDocumentRegion = element.getStartStructuredDocumentRegion(); - if (startStructuredDocumentRegion != null) { - String requiredAttrName = attr.getAttrName(); - String defaultAttrValue = attr.getDefaultValue(); - String insertString; - if (defaultAttrValue == null) - insertString = requiredAttrName + "=\"" + requiredAttrName + "\""; //$NON-NLS-1$ //$NON-NLS-2$ - else - insertString = requiredAttrName + "=\"" + defaultAttrValue + "\""; //$NON-NLS-1$ //$NON-NLS-2$ - - ITextRegion lastRegion = startStructuredDocumentRegion.getLastRegion(); - int insertOffset = lastRegion.getEnd(); - if (lastRegion.getEnd() == lastRegion.getTextEnd()) - insertString = " " + insertString; //$NON-NLS-1$ - if (lastRegion.getType() == XMLRegionContext.XML_TAG_CLOSE) - insertOffset = lastRegion.getStart(); - Object[] additionalFixInfo = {insertString, new Integer(insertOffset)}; - annotation.setAdditionalFixInfo(additionalFixInfo); - results.add(annotation); - } - } - } - } else if (isUnknown(element, mq)) { // CMVC 254838 - int start = element.getStartOffset(); - int length = element.getEndOffset() - element.getStartOffset(); - if (element.getStartStructuredDocumentRegion() != null && element.getStartStructuredDocumentRegion().getNumberOfRegions() > 1) { - ITextRegion name = element.getStartStructuredDocumentRegion().getRegions().get(1); - start = element.getStartStructuredDocumentRegion().getStartOffset(name); - length = name.getTextLength(); - } - Object[] args = {element.getNodeName()}; - String message = SSEUIPlugin.getResourceString("%Unknown_element_{0}", args); - Position p = new Position(start, length); - IReconcileAnnotationKey key = createKey(elementNode.getFirstStructuredDocumentRegion(), IReconcileAnnotationKey.PARTIAL); - TemporaryAnnotation annotation = new TemporaryAnnotation(p, SEVERITY_UNKNOWN_ELEMENT, message, key, ProblemIDsXML.UnknownElement); - - // quick fix info - int startTagOffset = -1, startTagLength = -1, endTagOffset = -1, endTagLength = -1; - if (element.getStartStructuredDocumentRegion() != null) { - startTagOffset = element.getStartStructuredDocumentRegion().getStartOffset(); - startTagLength = element.getStartStructuredDocumentRegion().getLength(); - } - if (element.getEndStructuredDocumentRegion() != null) { - endTagOffset = element.getEndStructuredDocumentRegion().getStartOffset(); - endTagLength = element.getEndStructuredDocumentRegion().getLength(); - } - Object[] additionalFixInfo = {new Integer(startTagOffset), new Integer(startTagLength), new Integer(endTagOffset), new Integer(endTagLength)}; - - annotation.setAdditionalFixInfo(additionalFixInfo); - results.add(annotation); - } - IReconcileResult[] reconcileResults = new IReconcileResult[results.size()]; - System.arraycopy(results.toArray(), 0, reconcileResults, 0, results.size()); - return reconcileResults; - } - - /** - * Determines if String value is within the values array given the current - * case sensitivity - * - * @param values - * @param value - */ - protected boolean valueMatch(String[] values, String value) { - - boolean found = (values == null || values.length == 0 || value.length() == 0); - for (int j = 0; j < values.length && !found; j++) { - if (fCaseSensitive) { - if (values[j].equals(value)) - found = true; - } else if (values[j].equalsIgnoreCase(value)) - found = true; - } - return found; - } - - // CMVC 255301 - // If we are in a large reconciling loop, this ensures - // that other Threads have a chance to run. - protected void yieldIfNeeded() { - - // 100 is arbitrary, may need a better number - if (fReconcileCount >= 100) { - Thread.yield(); - fReconcileCount = 0; - } else { - fReconcileCount++; - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/reconcile/ReconcileStepForContentModel.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/reconcile/ReconcileStepForContentModel.java deleted file mode 100644 index 87690e11e9..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/reconcile/ReconcileStepForContentModel.java +++ /dev/null @@ -1,233 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.reconcile; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; - -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.reconciler.DirtyRegion; -import org.eclipse.jface.text.reconciler.IReconcileResult; -import org.eclipse.jface.text.reconciler.IReconcileStep; -import org.eclipse.wst.sse.core.AdapterFactory; -import org.eclipse.wst.sse.core.INodeNotifier; -import org.eclipse.wst.sse.core.IndexedRegion; -import org.eclipse.wst.sse.core.PropagatingAdapter; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.text.ITextRegion; -import org.eclipse.wst.sse.ui.StructuredTextReconciler; -import org.eclipse.wst.sse.ui.StructuredTextViewer; -import org.eclipse.wst.sse.ui.internal.reconcile.IReconcileAnnotationKey; -import org.eclipse.wst.sse.ui.internal.reconcile.IReconcileStepAdapter; -import org.eclipse.wst.sse.ui.internal.reconcile.StructuredReconcileStep; -import org.eclipse.wst.xml.core.document.XMLDocument; -import org.eclipse.wst.xml.core.document.XMLModel; -import org.eclipse.wst.xml.core.document.XMLNode; -import org.eclipse.wst.xml.core.parser.XMLRegionContext; -import org.eclipse.wst.xml.ui.internal.Logger; - - -/** - * A reconcile step for ContentModel based documents. - */ -public class ReconcileStepForContentModel extends StructuredReconcileStep { - private HashSet fLocalPartitionTypes = null; - - protected boolean fRanInitialValidate = false; - - public ReconcileStepForContentModel() { - super(); - fLocalPartitionTypes = new HashSet(); - } - - public ReconcileStepForContentModel(StructuredTextViewer viewer, IReconcileStep step) { - super(step); - fLocalPartitionTypes = new HashSet(); - } - - private void addPartitionTypes(String[] types) { - for (int i = 0; i < types.length; i++) - fLocalPartitionTypes.add(types[i]); - } - - /** - * Need to add partition types for ReconcileStepAdapterForXML here... - * - */ - public String[] getPartitionTypes() { - String[] superPartitionTypes = super.getPartitionTypes(); - String[] results = new String[superPartitionTypes.length + fLocalPartitionTypes.size()]; - System.arraycopy(superPartitionTypes, 0, results, 0, superPartitionTypes.length); - System.arraycopy(fLocalPartitionTypes.toArray(), 0, results, superPartitionTypes.length, fLocalPartitionTypes.size()); - return results; - } - - public int getScope() { - return IReconcileAnnotationKey.PARTIAL; - } - - public void initialValidate() { - - // (pa) perf: add the adapter for every node here - XMLModel xModel = (XMLModel) getModelManager().getExistingModelForRead(getDocument()); - XMLDocument doc = xModel.getDocument(); - xModel.releaseFromRead(); - PropagatingAdapter propagatingAdapter = (PropagatingAdapter) doc.getAdapterFor(PropagatingAdapter.class); - - List factories = propagatingAdapter.getAdaptOnCreateFactories(); - ReconcilerAdapterFactoryForXML rAdapterFactoryForXML = null; - AdapterFactory temp = null; - // find the ReconcileStepAdapterFactory - for (int i = 0; i < factories.size(); i++) { - temp = (AdapterFactory) factories.get(i); - if (temp.isFactoryForType(IReconcileStepAdapter.class)) { - rAdapterFactoryForXML = (ReconcilerAdapterFactoryForXML) temp; - break; - } - } - - if (rAdapterFactoryForXML != null) { - rAdapterFactoryForXML.setShouldMarkForReconciling(false); - initialValidateTree(doc, rAdapterFactoryForXML); - rAdapterFactoryForXML.setShouldMarkForReconciling(true); - } - } - - /** - * Mark the INodeNotifier (Node) and all children of the INodeNotifier - * passed in. - * - * @param notifier - */ - protected void initialValidateTree(INodeNotifier notifier, AdapterFactory rAdapterFactoryForXML) { - if (isCanceled()) - return; - - if (notifier != null && notifier instanceof XMLNode) { - XMLNode current = (XMLNode) notifier; - IReconcileStepAdapter adapter = null; - // loop siblings - // pa_TODO for large XML files this loop goes for a LONG time - // and the progress monitor never gets canceled - while (current != null && !isCanceled()) { - // adapt this notifier - adapter = (IReconcileStepAdapter) rAdapterFactoryForXML.adapt(current); - if (adapter != null) { - ((AbstractReconcileStepAdapter) adapter).setParentStep(this); - adapter.markForReconciling(current); - current.addAdapter(adapter); - adapter.reconcile(getProgressMonitor(), current); - } - if (current.getFirstChild() != null) { - initialValidateTree((XMLNode) current.getFirstChild(), rAdapterFactoryForXML); - } - current = (XMLNode) current.getNextSibling(); - } - } - } - - - // Determines whether the IStructuredDocumentRegion is a XML "end tag" - // since they're not allowed to have - // attribute ITextRegions - protected boolean isEndTag(IStructuredDocumentRegion structuredDocumentRegion) { - return structuredDocumentRegion.getFirstRegion().getType() == XMLRegionContext.XML_END_TAG_OPEN; - } - - // Determines whether the IStructuredDocumentRegion is a XML "start tag" - // since they need to be - // checked for proper XML attribute region sequences - protected boolean isStartTag(IStructuredDocumentRegion structuredDocumentRegion) { - return structuredDocumentRegion.getFirstRegion().getType() == XMLRegionContext.XML_TAG_OPEN; - } - - // Because we check the "proper" closing separately from attribute - // sequencing, we need to know what's - // an appropriate close. - protected boolean isTagCloseTextRegion(ITextRegion textRegion) { - return textRegion.getType() == XMLRegionContext.XML_TAG_CLOSE || textRegion.getType() == XMLRegionContext.XML_EMPTY_TAG_CLOSE; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.internal.ui.text.StructuredReconcileStep#reconcileModel(org.eclipse.jface.text.reconciler.DirtyRegion, - * org.eclipse.jface.text.IRegion) - */ - protected IReconcileResult[] reconcileModel(DirtyRegion dirtyRegion, IRegion subRegion) { - if (dirtyRegion == null) - return EMPTY_RECONCILE_RESULT_SET; - - // logging ------------------ - Logger.trace(StructuredTextReconciler.TRACE_FILTER, "[trace reconciler] > reconciling model in CONTENT MODEL step w/ dirty region: [" + dirtyRegion.getOffset() + ":" + dirtyRegion.getLength() + "]" + dirtyRegion.getText()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - // -------------------------- - - int start = dirtyRegion.getOffset(); - int length = dirtyRegion.getLength(); - - IReconcileResult[] results = validate(start, length); - - // logging ------------------ - Logger.trace(StructuredTextReconciler.TRACE_FILTER, "[trace reconciler] > CONTENT MODEL step done"); //$NON-NLS-1$ - // -------------------------- - return results; - } - - /** - * Forces the IReconcilerAdapters for XMLNodes overlapping the given - * region to "validate" their Nodes. - * - * @param startOffset - * @param length - */ - protected IReconcileResult[] validate(int startOffset, int length) { - List results = new ArrayList(); - IReconcileResult[] temp = EMPTY_RECONCILE_RESULT_SET; - - if (!fRanInitialValidate) { - initialValidate(); - fRanInitialValidate = true; - } else { - XMLModel model = (XMLModel) getModelManager().getExistingModelForRead(getDocument()); - int endOffset = startOffset + length; - - IndexedRegion indexedNode = model.getIndexedRegion(startOffset); - IReconcileStepAdapter adapter = null; - - // sometimes for single key type length can be 0 (startOffset == - // endOffset) - for (int i = startOffset; indexedNode != null && i <= endOffset && !isCanceled(); i++) { - - XMLNode xmlNode = (XMLNode) indexedNode; - adapter = (IReconcileStepAdapter) xmlNode.getAdapterFor(IReconcileStepAdapter.class); - if (adapter != null) { - temp = adapter.reconcile(getProgressMonitor(), xmlNode); - for (int j = 0; j < temp.length; j++) - results.add(temp[j]); - // this is for removal purposes later - addPartitionTypes(adapter.getPartitionTypes()); - } - // visited.add(indexedNode); - if (xmlNode.getFirstStructuredDocumentRegion() != null) - i += xmlNode.getFirstStructuredDocumentRegion().getLength(); - else - i++; - - indexedNode = model.getIndexedRegion(i); - } - model.releaseFromRead(); - } - return (IReconcileResult[]) results.toArray(new IReconcileResult[results.size()]); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/reconcile/ReconcileStepForMarkup.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/reconcile/ReconcileStepForMarkup.java deleted file mode 100644 index 38d96cf26a..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/reconcile/ReconcileStepForMarkup.java +++ /dev/null @@ -1,550 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.reconcile; - -import java.util.ArrayList; -import java.util.List; -import java.util.StringTokenizer; - -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.Position; -import org.eclipse.jface.text.reconciler.DirtyRegion; -import org.eclipse.jface.text.reconciler.IReconcileResult; -import org.eclipse.jface.text.reconciler.IReconcileStep; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.text.ITextRegion; -import org.eclipse.wst.sse.core.text.ITextRegionList; -import org.eclipse.wst.sse.ui.StructuredTextReconciler; -import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; -import org.eclipse.wst.sse.ui.internal.reconcile.IReconcileAnnotationKey; -import org.eclipse.wst.sse.ui.internal.reconcile.StructuredReconcileStep; -import org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation; -import org.eclipse.wst.xml.core.document.XMLModel; -import org.eclipse.wst.xml.core.document.XMLNode; -import org.eclipse.wst.xml.core.parser.XMLRegionContext; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.correction.ProblemIDsXML; -import org.w3c.dom.Node; - -/** - * Basic XML syntax checking step. - * - * @author pavery - */ -public class ReconcileStepForMarkup extends StructuredReconcileStep { - private String DQUOTE = "\""; //$NON-NLS-1$ - - protected String SEVERITY_ATTR_MISSING_VALUE = TemporaryAnnotation.ANNOT_ERROR; - protected String SEVERITY_ATTR_NO_VALUE = TemporaryAnnotation.ANNOT_ERROR; - // severities for the problems discoverable by this reconciler; possibly - // user configurable later - protected String SEVERITY_GENERIC_ILLFORMED_SYNTAX = TemporaryAnnotation.ANNOT_WARNING; - protected String SEVERITY_STRUCTURE = TemporaryAnnotation.ANNOT_ERROR; - protected String SEVERITY_SYNTAX_ERROR = TemporaryAnnotation.ANNOT_ERROR; - // used for attribute quote checking - private String SQUOTE = "'"; //$NON-NLS-1$ - - public ReconcileStepForMarkup() { - super(); - } - - public ReconcileStepForMarkup(IReconcileStep step) { - super(step); - } - - private void addAttributeError(String message, String attributeValueText, int start, int length, int problemId, IStructuredDocumentRegion sdRegion, List results) { - Position p = new Position(start, length); - IReconcileAnnotationKey key = createKey(sdRegion, getScope()); - TemporaryAnnotation annotation = new TemporaryAnnotation(p, SEVERITY_SYNTAX_ERROR, message, key, problemId); - annotation.setAdditionalFixInfo(attributeValueText); - results.add(annotation); - } - - private void checkAttributesInEndTag(IStructuredDocumentRegion structuredDocumentRegion, List results) { - ITextRegionList textRegions = structuredDocumentRegion.getRegions(); - int errorCount = 0; - int start = structuredDocumentRegion.getEndOffset(); - int end = structuredDocumentRegion.getEndOffset(); - for (int i = 0; i < textRegions.size() && errorCount < ELEMENT_ERROR_LIMIT; i++) { - ITextRegion textRegion = textRegions.get(i); - if (textRegion.getType() == XMLRegionContext.XML_TAG_ATTRIBUTE_NAME || textRegion.getType() == XMLRegionContext.XML_TAG_ATTRIBUTE_EQUALS || textRegion.getType() == XMLRegionContext.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 message = SSEUIPlugin.getResourceString("%End_tag_has_attributes"); //$NON-NLS-1$ - results.add(new TemporaryAnnotation(p, SEVERITY_GENERIC_ILLFORMED_SYNTAX, message, createKey(structuredDocumentRegion, getScope()), ProblemIDsXML.AttrsInEndTag)); - } - } - - - /** - * @param structuredDocumentRegion - * @param results - */ - private void checkClosingBracket(IStructuredDocumentRegion structuredDocumentRegion, List results) { - ITextRegionList regions = structuredDocumentRegion.getRegions(); - ITextRegion r = null; - boolean closed = false; - for (int i = 0; i < regions.size(); i++) { - r = regions.get(i); - if (r.getType() == XMLRegionContext.XML_TAG_CLOSE || r.getType() == XMLRegionContext.XML_EMPTY_TAG_CLOSE) - closed = true; - } - if (!closed) { - - String message = SSEUIPlugin.getResourceString("%ReconcileStepForMarkup.6"); //$NON-NLS-1$ - - int start = structuredDocumentRegion.getStartOffset(); - int length = structuredDocumentRegion.getText().trim().length(); - Position p = new Position(start, length); - IReconcileAnnotationKey key = createKey(structuredDocumentRegion, getScope()); - - TemporaryAnnotation annotation = new TemporaryAnnotation(p, SEVERITY_SYNTAX_ERROR, message, key, ProblemIDsXML.MissingClosingBracket); - results.add(annotation); - } - } - - private void checkEmptyTag(IStructuredDocumentRegion structuredDocumentRegion, List results) { - // navigate to name - ITextRegionList regions = structuredDocumentRegion.getRegions(); - if (regions.size() == 2) { - // missing name region - if (regions.get(0).getType() == XMLRegionContext.XML_TAG_OPEN && regions.get(1).getType() == XMLRegionContext.XML_TAG_CLOSE) { - String message = SSEUIPlugin.getResourceString("%ReconcileStepForMarkup.3"); //$NON-NLS-1$ - int start = structuredDocumentRegion.getStartOffset(); - int length = structuredDocumentRegion.getLength(); - Position p = new Position(start, length); - IReconcileAnnotationKey key = createKey(structuredDocumentRegion, getScope()); - - TemporaryAnnotation annotation = new TemporaryAnnotation(p, SEVERITY_SYNTAX_ERROR, message, key, ProblemIDsXML.EmptyTag); - results.add(annotation); - } - } - } - - private void checkForAttributeValue(IStructuredDocumentRegion structuredDocumentRegion, List results) { - // 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(); - IReconcileAnnotationKey key = createKey(structuredDocumentRegion, getScope()); - int errorCount = 0; - for (int i = 0; i < textRegions.size() && errorCount < ELEMENT_ERROR_LIMIT; i++) { - ITextRegion textRegion = textRegions.get(i); - if (textRegion.getType() == XMLRegionContext.XML_TAG_ATTRIBUTE_NAME || isTagCloseTextRegion(textRegion)) { - // dangling name and '=' - if (attrState == 2 && i >= 2) { - // create annotation - ITextRegion nameRegion = textRegions.get(i - 2); - Object[] args = {structuredDocumentRegion.getText(nameRegion)}; - String message = SSEUIPlugin.getResourceString("%Attribute_{0}_is_missing_a_value", args); - int start = structuredDocumentRegion.getStartOffset(nameRegion); - int end = structuredDocumentRegion.getTextEndOffset(nameRegion); - Position p = new Position(start, end - start); - TemporaryAnnotation annotation = new TemporaryAnnotation(p, SEVERITY_ATTR_MISSING_VALUE, message, key, ProblemIDsXML.MissingAttrValue); - - // quick fix info - ITextRegion equalsRegion = textRegions.get(i - 2 + 1); - int insertOffset = structuredDocumentRegion.getTextEndOffset(equalsRegion) - end; - Object[] additionalFixInfo = {structuredDocumentRegion.getText(nameRegion), new Integer(insertOffset)}; - annotation.setAdditionalFixInfo(additionalFixInfo); - - results.add(annotation); - errorCount++; - } - // name but no '=' (XML only) - else if (attrState == 1 && i >= 1) { - // create annotation - ITextRegion previousRegion = textRegions.get(i - 1); - Object[] args = {structuredDocumentRegion.getText(previousRegion)}; - String message = SSEUIPlugin.getResourceString("%Attribute_{0}_has_no_value", args); - int start = structuredDocumentRegion.getStartOffset(previousRegion); - int end = structuredDocumentRegion.getTextEndOffset(previousRegion); - Position p = new Position(start, end - start); - TemporaryAnnotation annotation = new TemporaryAnnotation(p, SEVERITY_ATTR_NO_VALUE, message, key, ProblemIDsXML.NoAttrValue); - - // quick fix info - annotation.setAdditionalFixInfo(structuredDocumentRegion.getText(previousRegion)); - - results.add(annotation); - errorCount++; - } - attrState = 1; - } else if (textRegion.getType() == XMLRegionContext.XML_TAG_ATTRIBUTE_EQUALS) { - attrState = 2; - } else if (textRegion.getType() == XMLRegionContext.XML_TAG_ATTRIBUTE_VALUE) { - attrState = 0; - } - } - - } - - private void checkForSpaceBeforeName(IStructuredDocumentRegion structuredDocumentRegion, List results) { - 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 message = SSEUIPlugin.getResourceString("%ReconcileStepForMarkup.2"); //$NON-NLS-1$ - int start = structuredDocumentRegion.getStartOffset(); - // find length of whitespace - int length = sdRegionText.trim().equals("") ? sdRegionText.length() : sdRegionText.indexOf(sdRegionText.trim()); //$NON-NLS-1$ - - Position p = new Position(start, length); - IReconcileAnnotationKey key = createKey(structuredDocumentRegion, getScope()); - - TemporaryAnnotation annotation = new TemporaryAnnotation(p, SEVERITY_SYNTAX_ERROR, message, key, ProblemIDsXML.SpacesBeforeTagName); - results.add(annotation); - } - } - } - } - - private void checkNoNamespaceInPI(IStructuredDocumentRegion structuredDocumentRegion, List results) { - // navigate to name - ITextRegionList regions = structuredDocumentRegion.getRegions(); - ITextRegion r = null; - int errorCount = 0; - for (int i = 0; i < regions.size() && errorCount < ELEMENT_ERROR_LIMIT; i++) { - r = regions.get(i); - if (r.getType() == XMLRegionContext.XML_TAG_NAME) { - String piText = structuredDocumentRegion.getText(r); - int index = piText.indexOf(":"); //$NON-NLS-1$ - if (index != -1) { - String message = SSEUIPlugin.getResourceString("%ReconcileStepForMarkup.4"); //$NON-NLS-1$ - int start = structuredDocumentRegion.getStartOffset(r) + index; - int length = piText.trim().length() - index; - Position p = new Position(start, length); - IReconcileAnnotationKey key = createKey(structuredDocumentRegion, getScope()); - - TemporaryAnnotation annotation = new TemporaryAnnotation(p, SEVERITY_SYNTAX_ERROR, message, key, ProblemIDsXML.NamespaceInPI); - results.add(annotation); - errorCount++; - } - } - } - } - - /** - * @param structuredDocumentRegion - * @param results - */ - private void checkQuotesForAttributeValues(IStructuredDocumentRegion structuredDocumentRegion, List results) { - ITextRegionList regions = structuredDocumentRegion.getRegions(); - ITextRegion r = null; - String attrValueText = ""; //$NON-NLS-1$ - int errorCount = 0; - for (int i = 0; i < regions.size() && errorCount < ELEMENT_ERROR_LIMIT; i++) { - r = regions.get(i); - if (r.getType() != XMLRegionContext.XML_TAG_ATTRIBUTE_VALUE) - continue; - - attrValueText = structuredDocumentRegion.getText(r); - // attribute value includes quotes in the string - // split up attribute value on quotes - StringTokenizer st = new 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 = SSEUIPlugin.getResourceString("%ReconcileStepForMarkup.0"); //$NON-NLS-1$ - addAttributeError(message, attrValueText, structuredDocumentRegion.getStartOffset(r), attrValueText.trim().length(), ProblemIDsXML.Unclassified, structuredDocumentRegion, results); - errorCount++; - } else { - // missing both - String message = SSEUIPlugin.getResourceString("%ReconcileStepForMarkup.1"); //$NON-NLS-1$ - addAttributeError(message, attrValueText, structuredDocumentRegion.getStartOffset(r), attrValueText.trim().length(), ProblemIDsXML.AttrValueNotQuoted, structuredDocumentRegion, results); - errorCount++; - } - } else if (size == 2) { - if (one.equals(SQUOTE) && !two.equals(SQUOTE) || one.equals(DQUOTE) && !two.equals(DQUOTE)) { - // missing closing quote - String message = SSEUIPlugin.getResourceString("%ReconcileStepForMarkup.0"); //$NON-NLS-1$ - addAttributeError(message, attrValueText, structuredDocumentRegion.getStartOffset(r), attrValueText.trim().length(), ProblemIDsXML.Unclassified, structuredDocumentRegion, results); - errorCount++; - } - } - } - // end of region for loop - } - - private void checkStartEndTagPairs(IStructuredDocumentRegion sdRegion, List results) { - // check start/end tag pairs - XMLNode xmlNode = getXMLNode(sdRegion); - boolean selfClosed = false; - String tagName = null; - int length = 0; - - if (xmlNode.isContainer()) { - IStructuredDocumentRegion endNode = xmlNode.getEndStructuredDocumentRegion(); - if (endNode == null) { - // analyze the tag (check self closing) - ITextRegionList regions = xmlNode.getStartStructuredDocumentRegion().getRegions(); - ITextRegion r = null; - for (int i = 0; i < regions.size(); i++) { - r = regions.get(i); - if (r.getType() == XMLRegionContext.XML_TAG_OPEN || r.getType() == XMLRegionContext.XML_TAG_CLOSE) { - length++; - } else if (r.getType() == XMLRegionContext.XML_TAG_NAME) { - tagName = sdRegion.getText(r); - length += tagName.length(); - } else if (r.getType() == XMLRegionContext.XML_EMPTY_TAG_CLOSE) { - selfClosed = true; - } - } - - if (!selfClosed && tagName != null) { - Object[] args = {tagName}; - String message = SSEUIPlugin.getResourceString("%Missing_end_tag_{0}", args); - - int start = sdRegion.getStart(); - Position p = new Position(start, length); - TemporaryAnnotation annotation = new TemporaryAnnotation(p, SEVERITY_STRUCTURE, message, createKey(sdRegion, getScope()), ProblemIDsXML.MissingEndTag); - - // quick fix info - String tagClose = "/>"; //$NON-NLS-1$ - int tagCloseOffset = xmlNode.getFirstStructuredDocumentRegion().getEndOffset(); - if (r != null && r.getType() == XMLRegionContext.XML_TAG_CLOSE) { - tagClose = "/"; //$NON-NLS-1$ - tagCloseOffset--; - } - XMLNode firstChild = (XMLNode) xmlNode.getFirstChild(); - while (firstChild != null && firstChild.getNodeType() == Node.TEXT_NODE) { - firstChild = (XMLNode) 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 - annotation.setAdditionalFixInfo(additionalFixInfo); - - results.add(annotation); - } - } - - } - } - - private void checkStartingSpaceForPI(IStructuredDocumentRegion structuredDocumentRegion, List results) { - IStructuredDocumentRegion prev = structuredDocumentRegion.getPrevious(); - if (prev != null) { - String prevText = prev.getFullText(); - if (prev.getType() == XMLRegionContext.XML_CONTENT && prevText.endsWith(" ")) { //$NON-NLS-1$ - String message = SSEUIPlugin.getResourceString("%ReconcileStepForMarkup.5"); //$NON-NLS-1$ - int start = prev.getStartOffset(); - int length = prev.getLength(); - Position p = new Position(start, length); - IReconcileAnnotationKey key = createKey(structuredDocumentRegion, getScope()); - - TemporaryAnnotation annotation = new TemporaryAnnotation(p, SEVERITY_SYNTAX_ERROR, message, key, ProblemIDsXML.SpacesBeforePI); - results.add(annotation); - } - } - } - - public int getScope() { - return IReconcileAnnotationKey.PARTIAL; - } - - /** - * A DirtyRegion can span multiple StructuredDocumentRegions. This method - * returns the StructuredDocumentRegions in a given dirty region. - * - * @param dirtyRegion - */ - private IStructuredDocumentRegion[] getStructuredDocumentRegions(DirtyRegion dirtyRegion) { - List regions = new ArrayList(); - IStructuredDocumentRegion sdRegion = getStructuredDocument().getRegionAtCharacterOffset(dirtyRegion.getOffset()); - if (sdRegion != null) { - if (!sdRegion.isDeleted()) - regions.add(sdRegion); - while ((sdRegion = sdRegion.getNext()) != null && sdRegion.getEndOffset() <= getXMLNode(sdRegion).getEndOffset()) { - if (!sdRegion.isDeleted()) - regions.add(sdRegion); - } - } - return (IStructuredDocumentRegion[]) regions.toArray(new IStructuredDocumentRegion[regions.size()]); - } - - private XMLNode getXMLNode(IStructuredDocumentRegion sdRegion) { - XMLModel xModel = null; - XMLNode xmlNode = null; - // get/release models should always be in a try/finally block - try { - xModel = (XMLModel) getModelManager().getExistingModelForRead(getDocument()); - // xModel is sometime null, when closing editor, for example - if (xModel != null) { - xmlNode = (XMLNode) 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) - return false; - return structuredDocumentRegion.getFirstRegion().getType() == XMLRegionContext.XML_END_TAG_OPEN; - } - - /** - * Determines if the IStructuredDocumentRegion is an XML Processing - * Instruction - * - * @param structuredDocumentRegion - * - */ - private boolean isPI(IStructuredDocumentRegion structuredDocumentRegion) { - return structuredDocumentRegion.getFirstRegion().getType() == XMLRegionContext.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) - return false; - return structuredDocumentRegion.getFirstRegion().getType() == XMLRegionContext.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() == XMLRegionContext.XML_TAG_CLOSE || textRegion.getType() == XMLRegionContext.XML_EMPTY_TAG_CLOSE; - } - - /** - * Determines if the IStructuredDocumentRegion is XML Content - * - * @param structuredDocumentRegion - * - */ - private boolean isXMLContent(IStructuredDocumentRegion structuredDocumentRegion) { - return structuredDocumentRegion.getFirstRegion().getType() == XMLRegionContext.XML_CONTENT; - } - - /* - * check syntax of dirty region - */ - protected IReconcileResult[] reconcile(IStructuredDocumentRegion structuredDocumentRegion) { - List results = new ArrayList(); - - // fix for https://w3.opensource.ibm.com/bugzilla/show_bug.cgi?id=1939 - // not sure why this was being done before - // if (structuredDocumentRegion.getType() == - // XMLRegionContext.XML_CONTENT) { - // // rollback to an open tag - // // ** can this be bad? removal region must exactly match add region - // // or else we may get duplicates - // while ((structuredDocumentRegion = - // structuredDocumentRegion.getPrevious()) != null && - // !isStartTag(structuredDocumentRegion)) { - // continue; - // } - // } - if (structuredDocumentRegion == null) - return EMPTY_RECONCILE_RESULT_SET; - - if (isStartTag(structuredDocumentRegion)) { - // check for attributes without a value - checkForAttributeValue(structuredDocumentRegion, results); - // check if started tag is ended - checkStartEndTagPairs(structuredDocumentRegion, results); - // check empty tag <> - checkEmptyTag(structuredDocumentRegion, results); - // check that each attribute has quotes - checkQuotesForAttributeValues(structuredDocumentRegion, results); - // check that the closing '>' is there - checkClosingBracket(structuredDocumentRegion, results); - } else if (isEndTag(structuredDocumentRegion)) { - checkAttributesInEndTag(structuredDocumentRegion, results); - // check that the closing '>' is there - checkClosingBracket(structuredDocumentRegion, results); - } else if (isPI(structuredDocumentRegion)) { - // check validity of processing instruction - checkStartingSpaceForPI(structuredDocumentRegion, results); - checkNoNamespaceInPI(structuredDocumentRegion, results); - } else if (isXMLContent(structuredDocumentRegion)) { - checkForSpaceBeforeName(structuredDocumentRegion, results); - } - - return (IReconcileResult[]) results.toArray(new IReconcileResult[results.size()]); - } - - /* - * @see org.eclipse.text.reconcilerpipe.AbstractReconcilePipeParticipant#reconcileModel(org.eclipse.jface.text.reconciler.DirtyRegion, - * org.eclipse.jface.text.IRegion) - */ - protected IReconcileResult[] reconcileModel(DirtyRegion dirtyRegion, IRegion subRegion) { - if (dirtyRegion == null) - return EMPTY_RECONCILE_RESULT_SET; - Logger.trace(StructuredTextReconciler.TRACE_FILTER, "[trace reconciler] > reconcile model in MARKUP step w/ dirty region: [" + dirtyRegion.getOffset() + ":" + dirtyRegion.getLength() + "]" + (dirtyRegion == null ? "null" : dirtyRegion.getText())); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - - IReconcileResult[] results = EMPTY_RECONCILE_RESULT_SET; - - // TODO: may need to add back some synch(doc) and/or synch(region[i]) - // to - // be thread safe - IStructuredDocumentRegion[] regions = getStructuredDocumentRegions(dirtyRegion); - for (int i = 0; i < regions.length; i++) { - // the region may be irrelevant at this point - // if the user has deleted it - if (!regions[i].isDeleted()) { - results = merge(results, reconcile(regions[i])); - } - } - - Logger.trace(StructuredTextReconciler.TRACE_FILTER, "[trace reconciler] > MARKUP step done"); //$NON-NLS-1$ - return results; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/reconcile/ReconcilerAdapterFactoryForXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/reconcile/ReconcilerAdapterFactoryForXML.java deleted file mode 100644 index 9bb05141fc..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/reconcile/ReconcilerAdapterFactoryForXML.java +++ /dev/null @@ -1,94 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.reconcile; - -import org.eclipse.wst.sse.core.AbstractAdapterFactory; -import org.eclipse.wst.sse.core.INodeAdapter; -import org.eclipse.wst.sse.core.INodeNotifier; -import org.eclipse.wst.sse.ui.internal.reconcile.IReconcileStepAdapter; -import org.eclipse.wst.xml.core.document.XMLModel; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - - -public class ReconcilerAdapterFactoryForXML extends AbstractAdapterFactory { - - /** - * This flag governs whether or not this ReconcilerFactory is responsible - * for marking nodes "dirty" when an adapter is created for them. This is - * true on startup, then set to false thereafter. - */ - protected boolean fShouldMarkForReconciling = false; - - protected AbstractReconcileStepAdapter singleton = null; - - public ReconcilerAdapterFactoryForXML() { - this(IReconcileStepAdapter.class, true); - } - - /** - * @param adapterKey - * @param registerAdapters - */ - public ReconcilerAdapterFactoryForXML(Object adapterKey, boolean registerAdapters) { - super(adapterKey, registerAdapters); - } - - protected void adaptAll(Node top) { - int length = top.getChildNodes().getLength(); - NodeList children = top.getChildNodes(); - for (int i = 0; i < length; i++) { - adaptAll(children.item(i)); - } - ((INodeNotifier) top).getAdapterFor(adapterKey); - } - - public void adaptAll(XMLModel model) { - if (adapterKey != null) - adaptAll(model.getDocument()); - } - - /* - * (non-Javadoc) - * - * @see com.ibm.sed.model.AbstractAdapterFactory#createAdapter(com.ibm.sed.model.INodeNotifier) - */ - protected INodeAdapter createAdapter(INodeNotifier target) { - if (target instanceof Node) { - Node nodeTarget = (Node) target; - if (nodeTarget.getNodeType() == Node.ELEMENT_NODE || nodeTarget.getNodeType() == Node.DOCUMENT_NODE || nodeTarget.getNodeType() == Node.DOCUMENT_TYPE_NODE) { - if (singleton == null) { - this.singleton = new ReconcileStepAdapterForXML(); - } - // (pa) perf: don't do this on initial startup - if (shouldMarkForReconciling()) - singleton.markForReconciling(target); - return singleton; - } - } - return null; - } - - public void release() { - if (this.singleton != null) - this.singleton.release(); - } - - public void setShouldMarkForReconciling(boolean should) { - fShouldMarkForReconciling = should; - } - - public boolean shouldMarkForReconciling() { - return fShouldMarkForReconciling; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/reconcile/StructuredTextReconcilingStrategyForContentModel.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/reconcile/StructuredTextReconcilingStrategyForContentModel.java deleted file mode 100644 index de6c0660c2..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/reconcile/StructuredTextReconcilingStrategyForContentModel.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.reconcile; - -import org.eclipse.jface.text.reconciler.IReconcileStep; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.wst.sse.ui.internal.reconcile.AbstractStructuredTextReconcilingStrategy; - - -/** - * - * @author pavery - */ -public class StructuredTextReconcilingStrategyForContentModel extends AbstractStructuredTextReconcilingStrategy { - - public StructuredTextReconcilingStrategyForContentModel(ITextEditor editor) { - super(editor); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.internal.ui.text.AbstractStructuredTextReconcilingStrategy#createReconcileSteps() - */ - public void createReconcileSteps() { - - IReconcileStep cmStep = new ReconcileStepForContentModel(); - fFirstStep = new ReconcileStepForMarkup(cmStep); - } - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/reconcile/StructuredTextReconcilingStrategyForMarkup.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/reconcile/StructuredTextReconcilingStrategyForMarkup.java deleted file mode 100644 index e4c0c2701a..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/reconcile/StructuredTextReconcilingStrategyForMarkup.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.reconcile; - -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.wst.sse.ui.internal.reconcile.AbstractStructuredTextReconcilingStrategy; - - -/** - * - * @author pavery - * - */ -public class StructuredTextReconcilingStrategyForMarkup extends AbstractStructuredTextReconcilingStrategy { - - public StructuredTextReconcilingStrategyForMarkup(ITextEditor editor) { - super(editor); - } - - public void createReconcileSteps() { - // only one step, to check syntax - fFirstStep = new ReconcileStepForMarkup(); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/registry/AdapterFactoryProviderForEmbeddedXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/registry/AdapterFactoryProviderForEmbeddedXML.java deleted file mode 100644 index 690355de54..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/registry/AdapterFactoryProviderForEmbeddedXML.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.registry; - -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.sse.core.modelhandler.EmbeddedTypeHandler; -import org.eclipse.wst.sse.ui.registry.embedded.EmbeddedAdapterFactoryProvider; -import org.eclipse.wst.xml.core.document.XMLDocument; -import org.eclipse.wst.xml.core.document.XMLModel; -import org.eclipse.wst.xml.core.modelhandler.EmbeddedXML; - - -public class AdapterFactoryProviderForEmbeddedXML implements EmbeddedAdapterFactoryProvider { - - /* - * @see AdapterFactoryProvider#addAdapterFactories(IStructuredModel) - */ - public void addAdapterFactories(IStructuredModel structuredModel) { - if (structuredModel instanceof XMLModel) { - XMLDocument doc = ((XMLModel) structuredModel).getDocument(); - } - } - - /* - * @see AdapterFactoryProvider#isFor(ContentTypeDescription) - */ - public boolean isFor(EmbeddedTypeHandler contentTypeDescription) { - return (contentTypeDescription instanceof EmbeddedXML); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/registry/AdapterFactoryProviderForXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/registry/AdapterFactoryProviderForXML.java deleted file mode 100644 index fee44961da..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/registry/AdapterFactoryProviderForXML.java +++ /dev/null @@ -1,141 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.registry; - -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.ui.views.properties.IPropertySource; -import org.eclipse.wst.common.contentmodel.modelquery.CMDocumentManager; -import org.eclipse.wst.common.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.common.encoding.content.IContentTypeIdentifier; -import org.eclipse.wst.sse.core.AdapterFactory; -import org.eclipse.wst.sse.core.IFactoryRegistry; -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.sse.core.PropagatingAdapter; -import org.eclipse.wst.sse.core.modelhandler.IDocumentTypeHandler; -import org.eclipse.wst.sse.core.util.Assert; -import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; -import org.eclipse.wst.sse.ui.preferences.CommonEditorPreferenceNames; -import org.eclipse.wst.sse.ui.preferences.PreferenceKeyGenerator; -import org.eclipse.wst.sse.ui.registry.AdapterFactoryProvider; -import org.eclipse.wst.sse.ui.views.contentoutline.IJFaceNodeAdapter; -import org.eclipse.wst.xml.core.document.XMLDocument; -import org.eclipse.wst.xml.core.document.XMLModel; -import org.eclipse.wst.xml.core.modelhandler.ModelHandlerForXML; -import org.eclipse.wst.xml.core.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.ui.DOMObserver; -import org.eclipse.wst.xml.ui.reconcile.ReconcilerAdapterFactoryForXML; -import org.eclipse.wst.xml.ui.views.contentoutline.JFaceNodeAdapterFactory; -import org.eclipse.wst.xml.ui.views.properties.XMLPropertySourceAdapterFactory; - -/** - * - */ -public class AdapterFactoryProviderForXML implements AdapterFactoryProvider { - - private final String EDITOR_PLUGIN_ID = "org.eclipse.wst.sse.ui"; // $NON-NLS-1$ - - // //$NON-NLS-1$ - - /* - * @see AdapterFactoryProvider#addAdapterFactories(IStructuredModel) - */ - public void addAdapterFactories(IStructuredModel structuredModel) { - - // add the normal content based factories to model's registry - addContentBasedFactories(structuredModel); - // Must update/add to propagating adapter here too - - if (structuredModel instanceof XMLModel) { - addPropagatingAdapters(structuredModel); - } - } - - protected void addContentBasedFactories(IStructuredModel structuredModel) { - IFactoryRegistry factoryRegistry = structuredModel.getFactoryRegistry(); - Assert.isNotNull(factoryRegistry, "Program Error: client caller must ensure model has factory registry"); //$NON-NLS-1$ - AdapterFactory factory = null; - // == this list came from the previous "XML only" list - - // what was this still here? (6/4/03) - // I commented out on 6/4/03) but may have been something "extra" - // initializing - // old content assist adapter unnecessarily? - //factory = - // factoryRegistry.getFactoryFor(com.ibm.sed.edit.adapters.ContentAssistAdapter.class); - - factory = factoryRegistry.getFactoryFor(IPropertySource.class); - if (factory == null) { - factory = new XMLPropertySourceAdapterFactory(); - factoryRegistry.addFactory(factory); - } - 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 = SSEUIPlugin.getDefault().getPreferenceStore(); - boolean useInferredGrammar = (store != null) ? store.getBoolean(PreferenceKeyGenerator.generateKey(CommonEditorPreferenceNames.EDITOR_USE_INFERRED_GRAMMAR, IContentTypeIdentifier.ContentTypeID_SSEXML)) : 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(); - } - } - } - } - - protected void addPropagatingAdapters(IStructuredModel structuredModel) { - AdapterFactory factory; - XMLModel xmlModel = (XMLModel) structuredModel; - XMLDocument document = xmlModel.getDocument(); - PropagatingAdapter propagatingAdapter = (PropagatingAdapter) document.getAdapterFor(PropagatingAdapter.class); - if (propagatingAdapter != null) { - // checking if we should bother adding this factory - // if the preference says not to check validity, we don't bother - // creating this factory - // to improve performance... - String contentTypeId = IContentTypeIdentifier.ContentTypeID_SSEXML; - IPreferenceStore store = SSEUIPlugin.getDefault().getPreferenceStore(); - if (store.getString(PreferenceKeyGenerator.generateKey(CommonEditorPreferenceNames.EDITOR_VALIDATION_METHOD, contentTypeId)).equals(CommonEditorPreferenceNames.EDITOR_VALIDATION_CONTENT_MODEL)) { - factory = new ReconcilerAdapterFactoryForXML(); - propagatingAdapter.addAdaptOnCreateFactory(factory); - // (pa) perf: - //propagatingAdapter.initializeForFactory(factory, - // xmlModel.getDocument()); - } - } - } - - - /* - * @see AdapterFactoryProvider#isFor(ContentTypeDescription) - */ - 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/style/IStyleConstantsXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/style/IStyleConstantsXML.java deleted file mode 100644 index 1164ca609d..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/style/IStyleConstantsXML.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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$ -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/style/LineStyleProviderForXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/style/LineStyleProviderForXML.java deleted file mode 100644 index 036bf93e90..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/style/LineStyleProviderForXML.java +++ /dev/null @@ -1,180 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.style; - -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.text.TextAttribute; -import org.eclipse.jface.util.PropertyChangeEvent; -import org.eclipse.wst.common.encoding.content.IContentTypeIdentifier; -import org.eclipse.wst.sse.core.text.ITextRegion; -import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; -import org.eclipse.wst.sse.ui.preferences.PreferenceKeyGenerator; -import org.eclipse.wst.sse.ui.style.AbstractLineStyleProvider; -import org.eclipse.wst.sse.ui.style.LineStyleProvider; -import org.eclipse.wst.xml.core.parser.XMLRegionContext; - -public class LineStyleProviderForXML extends AbstractLineStyleProvider implements LineStyleProvider { - public LineStyleProviderForXML() { - super(); - loadColors(); - } - - protected void clearColors() { - getTextAttributes().clear(); - } - - 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 == XMLRegionContext.XML_CONTENT) || (type == XMLRegionContext.XML_DOCTYPE_INTERNAL_SUBSET)) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.XML_CONTENT); - } else if ((type == XMLRegionContext.XML_TAG_OPEN) || (type == XMLRegionContext.XML_END_TAG_OPEN) || (type == XMLRegionContext.XML_TAG_CLOSE) || (type == XMLRegionContext.XML_EMPTY_TAG_CLOSE)) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.TAG_BORDER); - } else if ((type == XMLRegionContext.XML_CDATA_OPEN) || (type == XMLRegionContext.XML_CDATA_CLOSE)) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.CDATA_BORDER); - } else if (type == XMLRegionContext.XML_CDATA_TEXT) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.CDATA_TEXT); - } else if (type == XMLRegionContext.XML_TAG_ATTRIBUTE_NAME) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.TAG_ATTRIBUTE_NAME); - } else if (type == XMLRegionContext.XML_DOCTYPE_DECLARATION) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.TAG_NAME); - } else if (type == XMLRegionContext.XML_TAG_NAME) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.TAG_NAME); - } else if ((type == XMLRegionContext.XML_TAG_ATTRIBUTE_VALUE)) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.TAG_ATTRIBUTE_VALUE); - } else if (type == XMLRegionContext.XML_TAG_ATTRIBUTE_EQUALS) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.TAG_ATTRIBUTE_EQUALS); - } else if ((type == XMLRegionContext.XML_COMMENT_OPEN) || (type == XMLRegionContext.XML_COMMENT_CLOSE)) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.COMMENT_BORDER); - } else if (type == XMLRegionContext.XML_COMMENT_TEXT) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.COMMENT_TEXT); - } else if (type == XMLRegionContext.XML_DOCTYPE_NAME) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.DOCTYPE_NAME); - } else if (type == XMLRegionContext.XML_PI_CONTENT) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.PI_CONTENT); - } else if ((type == XMLRegionContext.XML_PI_OPEN) || (type == XMLRegionContext.XML_PI_CLOSE)) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.PI_BORDER); - } else if ((type == XMLRegionContext.XML_DECLARATION_OPEN) || (type == XMLRegionContext.XML_DECLARATION_CLOSE)) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.DECL_BORDER); - } else if (type == XMLRegionContext.XML_DOCTYPE_EXTERNAL_ID_SYSREF) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_SYSREF); - } else if (type == XMLRegionContext.XML_DOCTYPE_EXTERNAL_ID_PUBREF) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_PUBREF); - } else if (type == XMLRegionContext.XML_DOCTYPE_EXTERNAL_ID_PUBLIC || type == XMLRegionContext.XML_DOCTYPE_EXTERNAL_ID_SYSTEM) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID); - } else if (type == XMLRegionContext.UNDEFINED) { - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.CDATA_TEXT); - } else if (type == XMLRegionContext.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 if ((type == XMLRegionContext.XML_CHAR_REFERENCE) || (type == XMLRegionContext.XML_ENTITY_REFERENCE) || (type == XMLRegionContext.XML_PE_REFERENCE)) { - // we may want to character and entity references to have it own - // color in future, - // but for now, we'll make attribute value - return (TextAttribute) getTextAttributes().get(IStyleConstantsXML.TAG_ATTRIBUTE_VALUE); - } else { - // default, return null to signal "not handled" - // in which case, other factories should be tried - return null; - } - } - - protected IPreferenceStore getColorPreferences() { - return SSEUIPlugin.getDefault().getPreferenceStore(); - } - - protected String getPreferenceKey(String key) { - String contentTypeId = IContentTypeIdentifier.ContentTypeID_SSEXML; - return PreferenceKeyGenerator.generateKey(key, contentTypeId); - } - - protected void handlePropertyChange(PropertyChangeEvent event) { - String styleKey = null; - - if (event != null) { - String prefKey = event.getProperty(); - // check if preference changed is a style preference - if (getPreferenceKey(IStyleConstantsXML.TAG_NAME).equals(prefKey)) { - styleKey = IStyleConstantsXML.TAG_NAME; - } else if (getPreferenceKey(IStyleConstantsXML.TAG_BORDER).equals(prefKey)) { - styleKey = IStyleConstantsXML.TAG_BORDER; - } else if (getPreferenceKey(IStyleConstantsXML.TAG_ATTRIBUTE_NAME).equals(prefKey)) { - styleKey = IStyleConstantsXML.TAG_ATTRIBUTE_NAME; - } else if (getPreferenceKey(IStyleConstantsXML.TAG_ATTRIBUTE_VALUE).equals(prefKey)) { - styleKey = IStyleConstantsXML.TAG_ATTRIBUTE_VALUE; - } else if (getPreferenceKey(IStyleConstantsXML.TAG_ATTRIBUTE_EQUALS).equals(prefKey)) { - styleKey = IStyleConstantsXML.TAG_ATTRIBUTE_EQUALS; - } else if (getPreferenceKey(IStyleConstantsXML.COMMENT_BORDER).equals(prefKey)) { - styleKey = IStyleConstantsXML.COMMENT_BORDER; - } else if (getPreferenceKey(IStyleConstantsXML.COMMENT_TEXT).equals(prefKey)) { - styleKey = IStyleConstantsXML.COMMENT_TEXT; - } else if (getPreferenceKey(IStyleConstantsXML.CDATA_BORDER).equals(prefKey)) { - styleKey = IStyleConstantsXML.CDATA_BORDER; - } else if (getPreferenceKey(IStyleConstantsXML.CDATA_TEXT).equals(prefKey)) { - styleKey = IStyleConstantsXML.CDATA_TEXT; - } else if (getPreferenceKey(IStyleConstantsXML.DECL_BORDER).equals(prefKey)) { - styleKey = IStyleConstantsXML.DECL_BORDER; - } else if (getPreferenceKey(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID).equals(prefKey)) { - styleKey = IStyleConstantsXML.DOCTYPE_EXTERNAL_ID; - } else if (getPreferenceKey(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_PUBREF).equals(prefKey)) { - styleKey = IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_PUBREF; - } else if (getPreferenceKey(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_SYSREF).equals(prefKey)) { - styleKey = IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_SYSREF; - } else if (getPreferenceKey(IStyleConstantsXML.DOCTYPE_NAME).equals(prefKey)) { - styleKey = IStyleConstantsXML.DOCTYPE_NAME; - } else if (getPreferenceKey(IStyleConstantsXML.PI_CONTENT).equals(prefKey)) { - styleKey = IStyleConstantsXML.PI_CONTENT; - } else if (getPreferenceKey(IStyleConstantsXML.PI_BORDER).equals(prefKey)) { - styleKey = IStyleConstantsXML.PI_BORDER; - } else if (getPreferenceKey(IStyleConstantsXML.XML_CONTENT).equals(prefKey)) { - styleKey = IStyleConstantsXML.XML_CONTENT; - } - } - - if (styleKey != null) { - // overwrite style preference with new value - addTextAttribute(styleKey); - super.handlePropertyChange(event); - } - } - - protected void loadColors() { - clearColors(); - - 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); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/taginfo/MarkupTagInfoProvider.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/taginfo/MarkupTagInfoProvider.java deleted file mode 100644 index d450fe07e1..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/taginfo/MarkupTagInfoProvider.java +++ /dev/null @@ -1,174 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.taginfo; - -import org.eclipse.wst.common.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.common.contentmodel.CMDataType; -import org.eclipse.wst.common.contentmodel.CMDocumentation; -import org.eclipse.wst.common.contentmodel.CMElementDeclaration; -import org.eclipse.wst.common.contentmodel.CMNode; -import org.eclipse.wst.common.contentmodel.CMNodeList; -import org.eclipse.wst.common.contentmodel.util.CMDescriptionBuilder; -import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; - -/** - * 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 + SSEUIPlugin.getResourceString("%Data_Type____4") + SPACE + BOLD_END); //$NON-NLS-1$ - sb.append(dataTypeName); - sb.append(PARAGRAPH_END); - } - String[] enumeratedValue = dataType.getEnumeratedValues(); - if (enumeratedValue != null && enumeratedValue.length > 0) { - sb.append(PARAGRAPH_START + BOLD_START + SSEUIPlugin.getResourceString("%Enumerated_Values____5") + SPACE + BOLD_END); //$NON-NLS-1$ - 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 + SSEUIPlugin.getResourceString("%Element____1") + SPACE + BOLD_END); //$NON-NLS-1$ - sb.append(node.getNodeName()); - sb.append(PARAGRAPH_END); - 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 + SSEUIPlugin.getResourceString("%Content_Model____2") + SPACE + BOLD_END); //$NON-NLS-1$ - sb.append(description + PARAGRAPH_END); - } - } - printDocumentation(sb, node); - } else if (node.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) { - CMAttributeDeclaration ad = (CMAttributeDeclaration) node; - sb.append(PARAGRAPH_START + BOLD_START + SSEUIPlugin.getResourceString("%Attribute____3") + SPACE + BOLD_END); //$NON-NLS-1$ - sb.append(node.getNodeName()); - sb.append(PARAGRAPH_END); - CMDataType dataType = ad.getAttrType(); - if (dataType != null) { - printDataTypeInfo(sb, dataType); - } - printDocumentation(sb, node); - } else if (node.getNodeType() == CMNode.DATA_TYPE) { - sb.append(PARAGRAPH_START + BOLD_START + SSEUIPlugin.getResourceString("%Data_Type____4") + SPACE + BOLD_END); //$NON-NLS-1$ - 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)) { - sb.append(NEW_LINE); - 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); - } - } - } - } - - /** - * 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/taginfo/XMLBestMatchHoverProcessor.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/taginfo/XMLBestMatchHoverProcessor.java deleted file mode 100644 index fb93c7e348..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/taginfo/XMLBestMatchHoverProcessor.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.taginfo; - -import org.eclipse.jface.text.ITextHover; -import org.eclipse.wst.sse.ui.taginfo.AbstractBestMatchHoverProcessor; - - -/** - * Provides the best xml hover help documentation (by using other hover help - * processors) Priority of hover help processors is: ProblemHoverProcessor, - * XMLTagInfoHoverProcessor, AnnotationHoverProcessor - */ -public class XMLBestMatchHoverProcessor extends AbstractBestMatchHoverProcessor { - XMLTagInfoHoverProcessor fTagInfoHover; - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.structured.taginfo.AbstractBestMatchHoverProcessor#getTagInfoHover() - */ - protected ITextHover getTagInfoHover() { - if (fTagInfoHover == null) { - fTagInfoHover = new XMLTagInfoHoverProcessor(); - } - return fTagInfoHover; - } - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/taginfo/XMLInformationProvider.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/taginfo/XMLInformationProvider.java deleted file mode 100644 index ae52fe9fe0..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/taginfo/XMLInformationProvider.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.taginfo; - - - -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.information.IInformationProvider; -import org.eclipse.jface.text.information.IInformationProviderExtension; - -/** - * Provides context information for XML tags (Shows tooltip description) - * - * @author amywu - */ -public class XMLInformationProvider implements IInformationProvider, IInformationProviderExtension { - - private XMLBestMatchHoverProcessor fTextHover = null; - - public XMLInformationProvider() { - fTextHover = new XMLBestMatchHoverProcessor(); - } - - /* - * (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/taginfo/XMLTagInfoHoverProcessor.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/taginfo/XMLTagInfoHoverProcessor.java deleted file mode 100644 index 247334d7a9..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/taginfo/XMLTagInfoHoverProcessor.java +++ /dev/null @@ -1,334 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.taginfo; - - - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITextHover; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.Region; -import org.eclipse.wst.common.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.common.contentmodel.CMElementDeclaration; -import org.eclipse.wst.common.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.common.contentmodel.CMNode; -import org.eclipse.wst.common.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.common.contentmodel.util.DOMNamespaceHelper; -import org.eclipse.wst.sse.core.IndexedRegion; -import org.eclipse.wst.sse.core.text.IStructuredDocument; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.text.ITextRegion; -import org.eclipse.wst.sse.core.text.ITextRegionList; -import org.eclipse.wst.sse.core.util.Debug; -import org.eclipse.wst.sse.ui.StructuredTextViewer; -import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils; -import org.eclipse.wst.xml.core.document.XMLNode; -import org.eclipse.wst.xml.core.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.core.parser.XMLRegionContext; -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 - * - * @author amywu - * @see org.eclipse.jface.text.ITextHover - */ -public class XMLTagInfoHoverProcessor implements ITextHover { - protected MarkupTagInfoProvider fInfoProvider = null; - - /** - * Constructor for XMLTextHoverProcessor. - */ - public XMLTagInfoHoverProcessor() { - } - - /** - * 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((StructuredTextViewer) 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(); - XMLNode parentNode = (XMLNode) 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, XMLNode parentNode, IStructuredDocumentRegion flatNode, ITextRegion region) { - String result = null; - if (region == null) - return null; - String regionType = region.getType(); - if (regionType == XMLRegionContext.XML_TAG_NAME) - result = computeTagNameHelp((XMLNode) treeNode, parentNode, flatNode, region); - else if (regionType == XMLRegionContext.XML_TAG_ATTRIBUTE_NAME) - result = computeTagAttNameHelp((XMLNode) treeNode, parentNode, flatNode, region); - else if (regionType == XMLRegionContext.XML_TAG_ATTRIBUTE_VALUE) - result = computeTagAttValueHelp((XMLNode) treeNode, parentNode, flatNode, region); - return result; - } - - /** - * Computes the hover help for the attribute name - */ - protected String computeTagAttNameHelp(XMLNode xmlnode, XMLNode parentNode, IStructuredDocumentRegion flatNode, ITextRegion region) { - CMElementDeclaration elementDecl = getCMElementDeclaration(xmlnode); - String attName = flatNode.getText(region); - CMAttributeDeclaration attDecl = getCMAttributeDeclaration(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(XMLNode xmlnode, XMLNode parentNode, IStructuredDocumentRegion flatNode, ITextRegion region) { - CMElementDeclaration elementDecl = getCMElementDeclaration(xmlnode); - ITextRegion attrNameRegion = getAttrNameRegion(xmlnode, region); - - String attName = flatNode.getText(attrNameRegion); - CMAttributeDeclaration attDecl = getCMAttributeDeclaration(elementDecl, attName); - return getAdditionalInfo(elementDecl, attDecl); - } - - /** - * Computes the hover help for the tag name - */ - protected String computeTagNameHelp(XMLNode xmlnode, XMLNode 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(XMLNode 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() == XMLRegionContext.XML_TAG_ATTRIBUTE_NAME) - break; - } - return nameRegion; - } - - /** - * Retreives CMAttributeDeclaration indicated by attribute name within - * elementDecl - */ - protected CMAttributeDeclaration getCMAttributeDeclaration(CMElementDeclaration elementDecl, String attName) { - CMAttributeDeclaration attrDecl = null; - - if (elementDecl != null) { - CMNamedNodeMap attributes = elementDecl.getAttributes(); - 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 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 == XMLRegionContext.XML_TAG_NAME) || (regionType == XMLRegionContext.XML_TAG_ATTRIBUTE_NAME) || (regionType == XMLRegionContext.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 == XMLRegionContext.XML_TAG_NAME) || (regionType == XMLRegionContext.XML_TAG_ATTRIBUTE_NAME) || (regionType == XMLRegionContext.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/templates/TemplateContextTypeIds.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/templates/TemplateContextTypeIds.java deleted file mode 100644 index 38e9db7cd2..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/templates/TemplateContextTypeIds.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.templates; - -/** - * Contains a list of template context type ids - */ -public class TemplateContextTypeIds { - public static final String ALL = "all"; //$NON-NLS-1$ - public static final String ATTRIBUTE = "attribute"; //$NON-NLS-1$ - public static final String ATTRIBUTEVALUE = "attribute_value"; //$NON-NLS-1$ - public static final String TAG = "tag"; //$NON-NLS-1$ - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/templates/TemplateContextTypeXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/templates/TemplateContextTypeXML.java deleted file mode 100644 index 03fe461c1e..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/templates/TemplateContextTypeXML.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.templates; - -import org.eclipse.jface.text.templates.GlobalTemplateVariables; -import org.eclipse.jface.text.templates.TemplateContextType; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; - -/** - * 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 static final String XML_PREFIX = "xml_"; //$NON-NLS-1$ - - /** - * Generate a context type id that includes content type - * - * @param base_contextTypeId - * @return String - */ - public static String generateContextTypeId(String base_contextTypeId) { - return XML_PREFIX + base_contextTypeId; - } - - public TemplateContextTypeXML() { - this(generateContextTypeId(TemplateContextTypeIds.ALL), XMLUIPlugin.getResourceString("%TemplateContextTypeXML.0")); //$NON-NLS-1$ - } - - /** - * @param id - * @param name - */ - public TemplateContextTypeXML(String id, String name) { - super(id, name); - 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()); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/templates/TemplateContextTypeXMLAttribute.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/templates/TemplateContextTypeXMLAttribute.java deleted file mode 100644 index c82c1963b5..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/templates/TemplateContextTypeXMLAttribute.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.templates; - -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; - -/** - * Templates of this context type apply to any attributes within XML content - * type. - */ -public class TemplateContextTypeXMLAttribute extends TemplateContextTypeXML { - - public TemplateContextTypeXMLAttribute() { - super(generateContextTypeId(TemplateContextTypeIds.ATTRIBUTE), XMLUIPlugin.getResourceString("%TemplateContextTypeXMLAttribute.0")); //$NON-NLS-1$ - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/templates/TemplateContextTypeXMLAttributeValue.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/templates/TemplateContextTypeXMLAttributeValue.java deleted file mode 100644 index faed70f0b9..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/templates/TemplateContextTypeXMLAttributeValue.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.templates; - -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; - -/** - * Templates of this context type apply to any attribute values within XML - * content type. - */ -public class TemplateContextTypeXMLAttributeValue extends TemplateContextTypeXML { - - public TemplateContextTypeXMLAttributeValue() { - super(generateContextTypeId(TemplateContextTypeIds.ATTRIBUTEVALUE), XMLUIPlugin.getResourceString("%TemplateContextTypeXMLAttributeValue.0")); //$NON-NLS-1$ - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/templates/TemplateContextTypeXMLTag.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/templates/TemplateContextTypeXMLTag.java deleted file mode 100644 index b4c77545ec..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/templates/TemplateContextTypeXMLTag.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.templates; - -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; - -/** - * Templates of this context type apply to any tags within XML content type. - */ -public class TemplateContextTypeXMLTag extends TemplateContextTypeXML { - - public TemplateContextTypeXMLTag() { - super(generateContextTypeId(TemplateContextTypeIds.TAG), XMLUIPlugin.getResourceString("%TemplateContextTypeXMLTag.0")); //$NON-NLS-1$ - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/text/XMLDocumentRegionEdgeMatcher.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/text/XMLDocumentRegionEdgeMatcher.java deleted file mode 100644 index 901fe89f37..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/text/XMLDocumentRegionEdgeMatcher.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.text; - -import org.eclipse.wst.sse.ui.text.DocumentRegionEdgeMatcher; -import org.eclipse.wst.xml.core.parser.XMLRegionContext; - - -public class XMLDocumentRegionEdgeMatcher extends DocumentRegionEdgeMatcher { - - - public XMLDocumentRegionEdgeMatcher() { - super(new String[]{XMLRegionContext.XML_TAG_NAME, XMLRegionContext.XML_COMMENT_TEXT, XMLRegionContext.XML_CDATA_TEXT, XMLRegionContext.XML_PI_OPEN, XMLRegionContext.XML_PI_CONTENT}, null); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/util/SharedXMLEditorPluginImageHelper.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/util/SharedXMLEditorPluginImageHelper.java deleted file mode 100644 index 81c8a4440c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/util/SharedXMLEditorPluginImageHelper.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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/util/XMLCommonResources.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/util/XMLCommonResources.java deleted file mode 100644 index 9bcad9b90a..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/util/XMLCommonResources.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.util; - -import java.text.MessageFormat; -import java.util.ResourceBundle; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.eclipse.ui.views.markers.internal.ImageFactory; -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; - - protected ImageFactory imageFactory; - private ResourceBundle resourceBundle; - - public XMLCommonResources(XMLUIPlugin editorPlugin) { - instance = this; - this.editorPlugin = editorPlugin; - //imageFactory = new ImageFactory(); - try { - resourceBundle = ResourceBundle.getBundle("EditingXML"); //$NON-NLS-1$ - imageFactory = new ImageFactory(); - } catch (java.util.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/util/XMLCommonUIContextIds.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/util/XMLCommonUIContextIds.java deleted file mode 100644 index e421f2289b..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/util/XMLCommonUIContextIds.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.util; - -/** - * Context help id constants. - */ -public interface XMLCommonUIContextIds { - public static final String PLUGIN_NAME = "com.ibm.etools.xml.common.ui"; //$NON-NLS-1$ - - - /* CONTEXT_IDs for "Assign an XSL Stylesheet To The XML File" dialog */ - /* CONTEXT_ID comn0010 for the dropdown menu. Follow comnxxxx */ - public static final String XCUI_ASSIGN_XSL_TO_XML_DROPDOWN = PLUGIN_NAME + ".xcui1000"; //$NON-NLS-1$ - /* CONTEXT_ID comn0030 for the import button. Follow comnxxxx */ - public static final String XCUI_ASSIGN_XSL_TO_XML_IMPORT = PLUGIN_NAME + ".xcui3000"; //$NON-NLS-1$ - /* CONTEXT_ID comn0020 for the workbench button. Follow comnxxxx */ - public static final String XCUI_ASSIGN_XSL_TO_XML_WORKBENCH = PLUGIN_NAME + ".xcui2000"; //$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 xcui0030 for Public ID Browse Button */ - public static final String XCUI_DOCTYPE_PUBLIC_BROWSE = PLUGIN_NAME + ".xcui0040"; //$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 xcui0030 for System ID Browse Button */ - public static final String XCUI_DOCTYPE_SYSTEM_BROWSE = PLUGIN_NAME + ".xcui0060"; //$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/views/contentoutline/JFaceNodeAdapter.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/contentoutline/JFaceNodeAdapter.java deleted file mode 100644 index ff3eeaf1bc..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/contentoutline/JFaceNodeAdapter.java +++ /dev/null @@ -1,344 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -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.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.views.properties.PropertySheetPage; -import org.eclipse.wst.common.contentmodel.CMDocument; -import org.eclipse.wst.common.contentmodel.modelquery.CMDocumentManager; -import org.eclipse.wst.common.contentmodel.modelquery.CMDocumentManagerListener; -import org.eclipse.wst.common.contentmodel.util.CMDocumentCache; -import org.eclipse.wst.sse.core.AdapterFactory; -import org.eclipse.wst.sse.core.INodeNotifier; -import org.eclipse.wst.sse.ui.views.contentoutline.BufferedOutlineUpdater; -import org.eclipse.wst.sse.ui.views.contentoutline.IJFaceNodeAdapter; -import org.eclipse.wst.sse.ui.views.contentoutline.IJFaceNodeAdapterFactory; -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; -import org.w3c.dom.Node; - -/** - * Adapts a DOM node to a JFace viewer. - */ -public class JFaceNodeAdapter implements IJFaceNodeAdapter { - - public class CMDocumentManagerListenerImpl implements CMDocumentManagerListener { - - List beingRefreshed = Collections.synchronizedList(new ArrayList()); - - public void cacheCleared(org.eclipse.wst.common.contentmodel.util.CMDocumentCache cache) { - - } - - public void cacheUpdated(CMDocumentCache cache, final String uri, int oldStatus, int newStatus, CMDocument cmDocument) { - - if (newStatus == CMDocumentCache.STATUS_LOADED || newStatus == CMDocumentCache.STATUS_ERROR) { - refreshViewers(); - } - } - - private Display getDisplay() { - - return PlatformUI.getWorkbench().getDisplay(); - } - - public void propertyChanged(CMDocumentManager cmDocumentManager, String propertyName) { - - if (cmDocumentManager.getPropertyEnabled(CMDocumentManager.PROPERTY_AUTO_LOAD)) { - refreshViewers(); - } - } - - protected void refreshViewers() { - - // we're counting on getListers returning a "copy" of the - // listeners, so we'll be thread safe. - Collection listeners = ((IJFaceNodeAdapterFactory) adapterFactory).getListeners(); - Iterator iterator = listeners.iterator(); - while (iterator.hasNext()) { - Object listener = iterator.next(); - // now that we use aynchExec, we ourselves have to gaurd - // against - // agains adding some refreshes when its already being - // refreshed. - if (listener instanceof PropertySheetPage && (!beingRefreshed.contains(listener))) { - final PropertySheetPage propertySheetPage = (PropertySheetPage) listener; - beingRefreshed.add(propertySheetPage); - getDisplay().asyncExec(new Runnable() { - - public void run() { - - if (getDisplay().isDisposed()) { - return; - } - if (propertySheetPage.getControl() != null && !propertySheetPage.getControl().isDisposed()) { - propertySheetPage.refresh(); - beingRefreshed.remove(propertySheetPage); - } - } - }); - } - } - } - } - - final static Class ADAPTER_KEY = IJFaceNodeAdapter.class; - - // for debugging - private static final boolean DEBUG; - static { - String value = Platform.getDebugOption("org.eclipse.wst.sse.ui/debug/outline"); //$NON-NLS-1$ - DEBUG = value != null && value.equalsIgnoreCase("true"); //$NON-NLS-1$ - } - - protected AdapterFactory adapterFactory; - protected CMDocumentManagerListener cmDocumentManagerListener; - private BufferedOutlineUpdater fUpdater = null; - - public JFaceNodeAdapter(AdapterFactory adapterFactory) { - - super(); - this.adapterFactory = 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_ELEMENT); - 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) - // - Node node = (Node) object; - ArrayList v = new ArrayList(node.getChildNodes().getLength()); - 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 a CMDocumentManagerListener that can update JFace views when - * notified of CMDocumentManager events - */ - public org.eclipse.wst.common.contentmodel.modelquery.CMDocumentManagerListener getCMDocumentManagerListener() { - - if (cmDocumentManagerListener == null) - cmDocumentManagerListener = new CMDocumentManagerListenerImpl(); - return cmDocumentManagerListener; - } - - Display getDisplay() { - - // Note: the workbench should always have a display - // (unless running headless), whereas Display.getCurrent() - // only returns the display if the currently executing thread - // has one. - if (PlatformUI.isWorkbenchRunning()) - return PlatformUI.getWorkbench().getDisplay(); - else - return null; - } - - /** - * 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 (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) { - - Node node = (Node) object; - String nodeName = node.getNodeName(); - if (node.getNodeType() == Node.DOCUMENT_TYPE_NODE) - nodeName = "DOCTYPE:" + nodeName; //$NON-NLS-1$ - return nodeName; - } - - private BufferedOutlineUpdater getOutlineUpdater() { - if (fUpdater == null) - fUpdater = new BufferedOutlineUpdater(); - return fUpdater; - } - - public Object getParent(Object object) { - - Node node = (Node) object; - return node.getParentNode(); - } - - 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) { - - 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. - Collection listeners = ((JFaceNodeAdapterFactory) adapterFactory).getListeners(); - Iterator iterator = listeners.iterator(); - - while (iterator.hasNext()) { - Object listener = iterator.next(); - if (notifier instanceof Node && (listener instanceof StructuredViewer) && (eventType == INodeNotifier.STRUCTURE_CHANGED || (eventType == INodeNotifier.CHANGE && changedFeature == null))) { - - if (DEBUG) - System.out.println("JFaceNodeAdapter notified on event type > " + eventType); - - // 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 /* - * && - * structuredViewer.getControl().isVisible() - */) - getOutlineUpdater().processNode(structuredViewer, (Node) notifier); - } else if ((listener instanceof PropertySheetPage) && ((eventType == INodeNotifier.CHANGE) || (eventType == INodeNotifier.STRUCTURE_CHANGED))) { - PropertySheetPage propertySheetPage = (PropertySheetPage) listener; - if (propertySheetPage.getControl() != null /* - * && - * !propertySheetPage.getControl().isDisposed() - */) { - RefreshPropertySheetJob refreshPropertySheetJob = new RefreshPropertySheetJob(getDisplay(), XMLUIPlugin.getResourceString("%JFaceNodeAdapter.1"), propertySheetPage); //$NON-NLS-1$ - refreshPropertySheetJob.schedule(); - } - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/contentoutline/JFaceNodeAdapterFactory.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/contentoutline/JFaceNodeAdapterFactory.java deleted file mode 100644 index c13860683e..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/contentoutline/JFaceNodeAdapterFactory.java +++ /dev/null @@ -1,104 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.ArrayList; -import java.util.Collection; - -import org.eclipse.wst.common.contentmodel.modelquery.CMDocumentManager; -import org.eclipse.wst.common.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.sse.core.AbstractAdapterFactory; -import org.eclipse.wst.sse.core.AdapterFactory; -import org.eclipse.wst.sse.core.INodeAdapter; -import org.eclipse.wst.sse.core.INodeNotifier; -import org.eclipse.wst.sse.core.modelquery.ModelQueryAdapter; -import org.eclipse.wst.sse.ui.views.contentoutline.IJFaceNodeAdapter; -import org.eclipse.wst.sse.ui.views.contentoutline.IJFaceNodeAdapterFactory; - - -/** - * 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 { - protected CMDocumentManager cmDocumentManager; - /** - * This keeps track of all the listeners. - */ - protected ArrayList fListeners = new ArrayList(); - - 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 AdapterFactory copy() { - - return new JFaceNodeAdapterFactory(this.adapterKey, this.shouldRegisterAdapter); - } - - /** - * 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. Its is a shallow copy. - */ - public synchronized Collection getListeners() { - return (Collection) fListeners.clone(); - } - - protected void initAdapter(INodeAdapter adapter, INodeNotifier node) { - // register for CMDocumentManager events - if (((JFaceNodeAdapter) adapter).getCMDocumentManagerListener() != null) { - ModelQueryAdapter mqadapter = (ModelQueryAdapter) node.getAdapterFor(ModelQueryAdapter.class); - if (mqadapter != null) { - ModelQuery mquery = mqadapter.getModelQuery(); - if (mquery != null && mquery.getCMDocumentManager() != null) { - cmDocumentManager = mquery.getCMDocumentManager(); - cmDocumentManager.addListener(((JFaceNodeAdapter) adapter).getCMDocumentManagerListener()); - } - } - } - } - - public void release() { - // deregister from CMDocumentManager events - if (cmDocumentManager != null && singletonAdapter != null && ((JFaceNodeAdapter) singletonAdapter).getCMDocumentManagerListener() != null) { - cmDocumentManager.removeListener(((JFaceNodeAdapter) singletonAdapter).getCMDocumentManagerListener()); - } - } - - public synchronized void removeListener(Object listener) { - fListeners.remove(listener); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/contentoutline/JFaceNodeContentProvider.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/contentoutline/JFaceNodeContentProvider.java deleted file mode 100644 index d6a121215f..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/contentoutline/JFaceNodeContentProvider.java +++ /dev/null @@ -1,104 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.wst.sse.core.AdapterFactory; -import org.eclipse.wst.sse.core.INodeAdapter; -import org.eclipse.wst.sse.core.INodeNotifier; -import org.eclipse.wst.sse.ui.views.contentoutline.IJFaceNodeAdapter; -import org.eclipse.wst.xml.core.document.XMLModel; - - -/** - * 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 { - protected AdapterFactory adapterFactory; - - public JFaceNodeContentProvider(AdapterFactory jfaceAdapterFactory) { - super(); - this.adapterFactory = jfaceAdapterFactory; - } - - /** - * 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. - * - * @return com.ibm.sed.view.tree.DOMJFaceAdapter The JFace adapter - * @param adaptable - * java.lang.Object The object to get the adapter for - */ - protected IJFaceNodeAdapter getAdapter(Object adaptable) { - if (adaptable instanceof INodeNotifier) { - INodeAdapter adapter = adapterFactory.adapt((INodeNotifier) adaptable); - 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 XMLModel) - topNode = ((XMLModel) 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) { - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/contentoutline/JFaceNodeLabelProvider.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/contentoutline/JFaceNodeLabelProvider.java deleted file mode 100644 index 28c4d84a58..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/contentoutline/JFaceNodeLabelProvider.java +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ILabelProviderListener; -import org.eclipse.swt.graphics.Image; -import org.eclipse.wst.sse.core.AdapterFactory; -import org.eclipse.wst.sse.core.INodeNotifier; -import org.eclipse.wst.sse.ui.views.contentoutline.IJFaceNodeAdapter; - - -/** - * A class that uses a JFaceNodeAdapterFactory to provide adapters to provide - * the labels and images for DOM nodes. - */ -public class JFaceNodeLabelProvider implements ILabelProvider { - - protected AdapterFactory adapterFactory; - - /** - * JFaceNodeLabelProvider constructor comment. - */ - public JFaceNodeLabelProvider(AdapterFactory adapterFactory) { - super(); - this.adapterFactory = adapterFactory; - } - - /** - * Adds a listener to the label provider. A label provider should inform - * its listener about state changes that enforces rendering of the visual - * part that uses this label provider. - */ - public void addListener(ILabelProviderListener listener) { - // The label provider state never changes so we do not have - // to implement this method. - } - - /** - * The visual part that is using this label provider is about to be - * disposed. Deallocate all allocated SWT resources. - */ - public void dispose() { - // Nothing to dispose - } - - /** - * Returns the JFace adapter for the specified object. - * - * @return com.ibm.sed.view.tree.DOMJFaceAdapter The JFace adapter - * @param adaptable - * java.lang.Object The object to get the adapter for - */ - protected IJFaceNodeAdapter getAdapter(Object adaptable) { - return (IJFaceNodeAdapter) adapterFactory.adapt((INodeNotifier) adaptable); - } - - /** - * Returns the image for the label of the given element, for use in the - * given viewer. - * - * @param element - * The element for which to provide the label image. Element - * can be <code>null</code> indicating no input object is set - * to the viewer. - */ - public Image getImage(Object element) { - return getAdapter(element).getLabelImage(element); - } - - /** - * Returns the text for the label of the given element, for use in the - * given viewer. - * - * @param element - * The element for which to provide the label text. Element can - * be <code>null</code> indicating no input object is set to - * the viewer. - */ - public java.lang.String getText(Object element) { - // This was returning null, on occasion ... probably should not be, - // but - // took the quick and easy way out for now. (dmw 3/8/01) - String result = getAdapter(element).getLabelText(element); - if (result == null) - result = "";//$NON-NLS-1$ - return result; - } - - /** - * Checks whether this label provider is affected by the given domain - * event. - */ - public boolean isAffected(Object dummy) {//DomainEvent event) { - //return event.isModifier(DomainEvent.NON_STRUCTURE_CHANGE); - return true; - - } - - /** - * Returns whether the label would be affected by a change to the given - * property of the given element. This can be used to optimize a - * non-structural viewer update. If the property mentioned in the update - * does not affect the label, then the viewer need not update the label. - * - * @param element - * the element - * @param property - * the property - * @return <code>true</code> if the label would be affected, and - * <code>false</code> if it would be unaffected - */ - public boolean isLabelProperty(Object element, String property) { - return false; - } - - /** - * Removes a listener from the label provider. - */ - public void removeListener(ILabelProviderListener listener) { - // The label provider state never changes so we do not have - // to implement this method. - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/contentoutline/RefreshOutlineJob.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/contentoutline/RefreshOutlineJob.java deleted file mode 100644 index 093b76e054..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/contentoutline/RefreshOutlineJob.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.progress.UIJob; -import org.eclipse.wst.sse.core.INodeNotifier; -import org.w3c.dom.Node; - -/** - * @deprecated should be using org.eclipse.wst.sse.ui.views.contentoutline.RefreshOutlineJob - */ -public class RefreshOutlineJob extends UIJob { - - private INodeNotifier fNodeNotifier; - private StructuredViewer fStructuredViewer; - - /** - * @param jobDisplay - * @param name - */ - public RefreshOutlineJob(Display jobDisplay, String name, StructuredViewer structuredViewer, INodeNotifier nodeNotifier) { - super(jobDisplay, name); - setPriority(Job.SHORT); - - setStructuredViewer(structuredViewer); - setNodeNotifier(nodeNotifier); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor) - */ - public IStatus runInUIThread(IProgressMonitor monitor) { - IStatus result = Status.OK_STATUS; - try { - Control control = fStructuredViewer.getControl(); - // we should have check before even scheduling this, but even if - // ok then, need to check again, right before executing. - if (control != null && !control.isDisposed()) { - - if ((fNodeNotifier instanceof Node) && (((Node) fNodeNotifier).getParentNode() == null)) { - // refresh whole document - fStructuredViewer.refresh(); - } else { - // refresh only the node that's changed - fStructuredViewer.refresh(fNodeNotifier); - } - } - } catch (Exception e) { - result = errorStatus(e); - } finally { - monitor.done(); - } - return result; - } - - /** - * @param nodeNotifier - */ - private void setNodeNotifier(INodeNotifier nodeNotifier) { - fNodeNotifier = nodeNotifier; - - } - - /** - * @param structuredViewer - */ - private void setStructuredViewer(StructuredViewer structuredViewer) { - fStructuredViewer = structuredViewer; - - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/contentoutline/RefreshPropertySheetJob.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/contentoutline/RefreshPropertySheetJob.java deleted file mode 100644 index e20a28bd33..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/contentoutline/RefreshPropertySheetJob.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.progress.UIJob; -import org.eclipse.ui.views.properties.PropertySheetPage; - - -public class RefreshPropertySheetJob extends UIJob { - - - private PropertySheetPage fPropertySheetPage; - - /** - * @param jobDisplay - * @param name - */ - public RefreshPropertySheetJob(Display jobDisplay, String name, PropertySheetPage propertySheetPage) { - super(jobDisplay, name); - setPriority(Job.SHORT); - fPropertySheetPage = propertySheetPage; - } - - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor) - */ - public IStatus runInUIThread(IProgressMonitor monitor) { - IStatus result = Status.OK_STATUS; - try { - Control control = fPropertySheetPage.getControl(); - // we should have check before even scheduling this, but even if - // ok then, need to check again, right before executing. - if (control != null && !control.isDisposed()) { - fPropertySheetPage.refresh(); - } - } catch (Exception e) { - result = errorStatus(e); - } finally { - monitor.done(); - } - return result; - } -} 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 d37302d0c3..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/contentoutline/XMLContentOutlineConfiguration.java +++ /dev/null @@ -1,226 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.ArrayList; -import java.util.List; - -import org.eclipse.jface.action.IMenuListener; -import org.eclipse.jface.action.IMenuManager; -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.TreeViewer; -import org.eclipse.swt.dnd.DragSourceEvent; -import org.eclipse.swt.dnd.DropTargetEvent; -import org.eclipse.swt.dnd.Transfer; -import org.eclipse.wst.common.ui.dnd.ObjectTransfer; -import org.eclipse.wst.common.ui.dnd.ViewerDragAdapter; -import org.eclipse.wst.common.ui.dnd.ViewerDropAdapter; -import org.eclipse.wst.sse.core.AdapterFactory; -import org.eclipse.wst.sse.ui.IReleasable; -import org.eclipse.wst.sse.ui.view.events.NodeSelectionChangedEvent; -import org.eclipse.wst.sse.ui.views.contentoutline.StructuredContentOutlineConfiguration; -import org.eclipse.wst.xml.ui.dnd.XMLDragAndDropManager; -import org.w3c.dom.Attr; -import org.w3c.dom.Node; - -public class XMLContentOutlineConfiguration extends StructuredContentOutlineConfiguration { - - protected class ActionManagerMenuListener implements IMenuListener, IReleasable { - private XMLNodeActionManager fActionManager; - private TreeViewer fTreeViewer; - - public ActionManagerMenuListener(TreeViewer viewer) { - fTreeViewer = viewer; - fActionManager = createNodeActionManager(fTreeViewer); - } - - public void menuAboutToShow(IMenuManager manager) { - if (fActionManager != null) - fActionManager.fillContextMenu(manager, fTreeViewer.getSelection()); - } - - public void release() { - fTreeViewer = null; - fActionManager.setModel(null); - } - } - - protected ActionManagerMenuListener fContextMenuFiller = null; - - private TransferDragSourceListener[] fTransferDragSourceListeners; - private TransferDropTargetListener[] fTransferDropTargetListeners; - - public XMLContentOutlineConfiguration() { - super(); - } - - protected XMLNodeActionManager createNodeActionManager(TreeViewer treeViewer) { - return new XMLNodeActionManager(getEditor().getModel(), treeViewer); - } - - public IContentProvider getContentProvider(TreeViewer viewer) { - if (fContentProvider == null) { - if (getFactory() != null) { - fContentProvider = new JFaceNodeContentProvider((AdapterFactory) getFactory()); - } else { - fContentProvider = super.getContentProvider(viewer); - } - } - return fContentProvider; - } - - /** - * @see org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration#getLabelProvider(org.eclipse.jface.viewers.TreeViewer) - */ - public ILabelProvider getLabelProvider(TreeViewer viewer) { - if (fLabelProvider == null) { - if (getFactory() != null) { - fLabelProvider = new JFaceNodeLabelProvider((AdapterFactory) getFactory()); - } else { - fLabelProvider = super.getLabelProvider(viewer); - } - } - return fLabelProvider; - } - - /** - * @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#getNodes(java.util.List) - */ - public List getNodes(List nodes) { - List filteredNodes = new ArrayList(super.getNodes(nodes)); - for (int i = 0; i < filteredNodes.size(); i++) { - Object selectedNode = filteredNodes.get(i); - if (selectedNode instanceof Node) { - Node eachNode = (Node) selectedNode; - // replace attribute node in selection with its parent - if (eachNode.getNodeType() == Node.ATTRIBUTE_NODE) - filteredNodes.set(i, ((Attr) eachNode).getOwnerElement()); - // replace TextNode in selection with its parent - else if (eachNode.getNodeType() == Node.TEXT_NODE) - filteredNodes.set(i, eachNode.getParentNode()); - } - } - return filteredNodes; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration#getSelectedNodes(org.eclipse.wst.sse.ui.view.events.NodeSelectionChangedEvent) - */ - public List getSelectedNodes(NodeSelectionChangedEvent event) { - return getNodes(super.getSelectedNodes(event)); - } - - /** - * @see org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration#getTransferDragSourceListeners(org.eclipse.jface.viewers.TreeViewer) - */ - public TransferDragSourceListener[] getTransferDragSourceListeners(TreeViewer treeViewer) { - if (fTransferDragSourceListeners == null) { - // emulate the XMLDragAndDropManager - final ViewerDragAdapter dragAdapter = new ViewerDragAdapter(treeViewer); - fTransferDragSourceListeners = new TransferDragSourceListener[]{new TransferDragSourceListener() { - public void dragFinished(DragSourceEvent event) { - dragAdapter.dragFinished(event); - } - - public void dragSetData(DragSourceEvent event) { - dragAdapter.dragSetData(event); - } - - public void dragStart(DragSourceEvent event) { - dragAdapter.dragStart(event); - } - - public Transfer getTransfer() { - return ObjectTransfer.getInstance(); - } - }}; - } - - return fTransferDragSourceListeners; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration#getTransferDropTargetListeners(org.eclipse.jface.viewers.TreeViewer) - */ - public TransferDropTargetListener[] getTransferDropTargetListeners(TreeViewer treeViewer) { - if (fTransferDropTargetListeners == null) { - // emulate the XMLDragAnDropManager - final ViewerDropAdapter dropAdapter = new ViewerDropAdapter(treeViewer, new XMLDragAndDropManager()); - fTransferDropTargetListeners = new TransferDropTargetListener[]{new TransferDropTargetListener() { - public void dragEnter(DropTargetEvent event) { - dropAdapter.dragEnter(event); - } - - public void dragLeave(DropTargetEvent event) { - dropAdapter.dragLeave(event); - } - - public void dragOperationChanged(DropTargetEvent event) { - dropAdapter.dragOperationChanged(event); - } - - public void dragOver(DropTargetEvent event) { - dropAdapter.dragOver(event); - } - - public void drop(DropTargetEvent event) { - dropAdapter.drop(event); - } - - public void dropAccept(DropTargetEvent event) { - dropAdapter.dropAccept(event); - } - - public Transfer getTransfer() { - return ObjectTransfer.getInstance(); - } - - public boolean isEnabled(DropTargetEvent event) { - return getTransfer().isSupportedType(event.currentDataType); - } - }}; - } - return fTransferDropTargetListeners; - } - - public void unconfigure(TreeViewer viewer) { - super.unconfigure(viewer); - fTransferDragSourceListeners = null; - fTransferDropTargetListeners = null; - if (fContextMenuFiller != null) { - fContextMenuFiller.release(); - fContextMenuFiller = null; - } - // TODO: Add DnD support - // XMLDragAndDropManager.addDragAndDropSupport(fTreeViewer); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/contentoutline/XMLNodeActionManager.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/contentoutline/XMLNodeActionManager.java deleted file mode 100644 index 9fe7c36c70..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/contentoutline/XMLNodeActionManager.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.jface.viewers.Viewer; -import org.eclipse.wst.common.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.sse.core.format.IStructuredFormatProcessor; -import org.eclipse.wst.xml.core.format.FormatProcessorXML; -import org.eclipse.wst.xml.core.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.ui.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 - model.aboutToChangeModel(); - - // format selected node - IStructuredFormatProcessor formatProcessor = new FormatProcessorXML(); - formatProcessor.formatNode(newElement); - } finally { - // tell the model that we are done with the big model change - model.changedModel(); - } - } - - public void setModel(IStructuredModel newModel) { - model = 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/views/properties/ProcessingInstructionPropertySourceAdapter.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/properties/ProcessingInstructionPropertySourceAdapter.java deleted file mode 100644 index 00302f2905..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/properties/ProcessingInstructionPropertySourceAdapter.java +++ /dev/null @@ -1,156 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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 org.eclipse.ui.views.properties.IPropertyDescriptor; -import org.eclipse.ui.views.properties.IPropertySource; -import org.eclipse.wst.sse.core.INodeAdapter; -import org.eclipse.wst.sse.core.INodeNotifier; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.text.ITextRegion; -import org.eclipse.wst.sse.core.text.ITextRegionList; -import org.eclipse.wst.sse.core.util.StringUtils; -import org.eclipse.wst.sse.ui.util.Assert; -import org.eclipse.wst.sse.ui.views.properties.CustomPropertyDescriptor; -import org.eclipse.wst.sse.ui.views.properties.IPropertySourceExtension; -import org.eclipse.wst.xml.core.document.XMLNode; -import org.eclipse.wst.xml.core.parser.XMLRegionContext; -import org.w3c.dom.Node; -import org.w3c.dom.ProcessingInstruction; - - -/** - * An IPropertySource implementation for a JFace viewer used to display - * properties of DOM nodes. Requires an adapter factory to create JFace - * adapters for the nodes in the tree. - */ -public class ProcessingInstructionPropertySourceAdapter implements INodeAdapter, IPropertySource, IPropertySourceExtension { - protected final static String CATEGORY_ATTRIBUTES = "Instructions"; //$NON-NLS-1$ - - protected IPropertyDescriptor[] fDescriptors = null; - protected Node fNode = null; - - public ProcessingInstructionPropertySourceAdapter(INodeNotifier target) { - super(); - fNode = (Node) target; - Assert.isTrue(target instanceof XMLNode); - Assert.isTrue(fNode.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE); - } - - /** - * Returns the current collection of property descriptors. - * - * @return all valid descriptors. - */ - protected IPropertyDescriptor[] createPropertyDescriptors() { - boolean isXML = ((ProcessingInstruction) fNode).getTarget().equalsIgnoreCase("xml"); //$NON-NLS-1$ - if (!isXML) - return new IPropertyDescriptor[0]; - CustomPropertyDescriptor[] descriptors = new CustomPropertyDescriptor[2]; - descriptors[0] = new CustomPropertyDescriptor("version", "version", null); //$NON-NLS-1$ //$NON-NLS-2$ - descriptors[0].setCategory(CATEGORY_ATTRIBUTES); - descriptors[1] = new CustomPropertyDescriptor("encoding", "encoding", null); //$NON-NLS-1$ //$NON-NLS-2$ - descriptors[1].setCategory(CATEGORY_ATTRIBUTES); - return descriptors; - } - - /** - * 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 IPropertyDescriptor[] getPropertyDescriptors() { - if (fDescriptors == null) { - fDescriptors = createPropertyDescriptors(); - } - return fDescriptors; - } - - /** - * Returns the current value for the named property. - */ - public Object getPropertyValue(Object nameObject) { - XMLNode node = (XMLNode) fNode; - String value = null; - String name = null; - IStructuredDocumentRegion docRegion = node.getFirstStructuredDocumentRegion(); - if (docRegion == null) - return null; - ITextRegionList regions = docRegion.getRegions(); - ITextRegion region = null; - int i = 2; - while (value == null && i < regions.size()) { - region = regions.get(i); - if (region.getType().equals(XMLRegionContext.XML_TAG_ATTRIBUTE_NAME)) - name = docRegion.getText(region); - else if (region.getType().equals(XMLRegionContext.XML_TAG_ATTRIBUTE_VALUE) && name != null && name.equals(nameObject)) - value = docRegion.getText(region); - i++; - } - if (value != null) - value = StringUtils.strip(value); - return value; - } - - /** - * Allowing the INodeAdapter to compare itself against the type allows it - * to return true in more than one case. - */ - public boolean isAdapterForType(Object type) { - return type == IPropertySource.class; - } - - /** - * 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) { - return false; - } - - public void notifyChanged(INodeNotifier notifier, int eventType, java.lang.Object changedFeature, java.lang.Object oldValue, java.lang.Object newValue, int pos) { - } - - /** - * Remove the given attribute from the Node - * - * @param propertyObject - */ - public void removeProperty(Object propertyObject) { - } - - /** - * Resets the specified property's value to its default value. - */ - public void resetPropertyValue(Object propertyObject) { - } - - /** - * Sets the named property to the given value. - * - */ - public void setPropertyValue(Object nameObject, Object value) { - } -} 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 7ce0ff08a2..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/properties/XMLPropertySheetConfiguration.java +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.ArrayList; -import java.util.List; - -import org.eclipse.jface.text.ITextSelection; -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.wst.sse.ui.views.properties.StructuredPropertySheetConfiguration; -import org.w3c.dom.Attr; -import org.w3c.dom.Node; - - -public class XMLPropertySheetConfiguration extends StructuredPropertySheetConfiguration { - - /** - * - */ - public XMLPropertySheetConfiguration() { - super(); - } - - /** - * @see org.eclipse.wst.sse.ui.views.properties.PropertySheetConfiguration#getSelection(org.eclipse.ui.IWorkbenchPart, - * org.eclipse.jface.viewers.ISelection) - */ - public ISelection getSelection(IWorkbenchPart selectingPart, ISelection selection) { - // On Attr nodes, select the owner Element. On Text nodes, select the - // parent Element. - ISelection preferredSelection = selection; - if (selection instanceof ITextSelection) { - // on text selection, find the appropriate Node - ITextSelection textSel = (ITextSelection) selection; - if (getModel() != null) { - Object inode = getModel().getIndexedRegion(textSel.getOffset()); - if (inode instanceof Node) { - Node node = (Node) inode; - // replace Attribute Node with its owner - if (node.getNodeType() == Node.ATTRIBUTE_NODE) - inode = ((Attr) node).getOwnerElement(); - // replace Text Node with its parent - else if ((node.getNodeType() == Node.TEXT_NODE || (node.getNodeType() == Node.CDATA_SECTION_NODE)) && node.getParentNode() != null) { - inode = node.getParentNode(); - } - } - if (inode != null) { - List inputList = new ArrayList(1); - inputList.add(inode); - preferredSelection = new StructuredSelection(inputList); - } - } - } else if (selection instanceof IStructuredSelection) { - IStructuredSelection structuredSel = (IStructuredSelection) selection; - if (getModel() != null) { - List inputList = new ArrayList(structuredSel.toList()); - for (int i = 0; i < inputList.size(); i++) { - Object inode = inputList.get(i); - if (inode instanceof Node) { - Node node = (Node) inputList.get(i); - // replace Attribute Node with its owner - if (node.getNodeType() == Node.ATTRIBUTE_NODE) - inputList.set(i, ((Attr) node).getOwnerElement()); - // replace Text Node with its parent - else if ((node.getNodeType() == Node.TEXT_NODE || (node.getNodeType() == Node.CDATA_SECTION_NODE)) && node.getParentNode() != null) { - inputList.set(i, node.getParentNode()); - } - } - } - preferredSelection = new StructuredSelection(inputList); - } - } - return preferredSelection; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/properties/XMLPropertySourceAdapter.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/properties/XMLPropertySourceAdapter.java deleted file mode 100644 index c707663cbb..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/properties/XMLPropertySourceAdapter.java +++ /dev/null @@ -1,668 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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.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.TextPropertyDescriptor; -import org.eclipse.wst.common.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.common.contentmodel.CMDataType; -import org.eclipse.wst.common.contentmodel.CMElementDeclaration; -import org.eclipse.wst.common.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.common.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.sse.core.INodeAdapter; -import org.eclipse.wst.sse.core.INodeNotifier; -import org.eclipse.wst.sse.ui.views.properties.EnumeratedStringPropertyDescriptor; -import org.eclipse.wst.sse.ui.views.properties.IPropertySourceExtension; -import org.eclipse.wst.xml.core.document.DocumentTypeAdapter; -import org.eclipse.wst.xml.core.document.XMLNode; -import org.eclipse.wst.xml.core.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -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. Requires an adapter factory to create JFace - * adapters for the nodes in the tree. - */ -public class XMLPropertySourceAdapter implements INodeAdapter, IPropertySource, IPropertySourceExtension { - protected final static String CATEGORY_ATTRIBUTES = XMLUIPlugin.getResourceString("%XMLPropertySourceAdapter.0"); //$NON-NLS-1$ - - 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; - protected boolean fCaseSensitive = true; - protected IPropertyDescriptor[] fDescriptors = null; - protected Node fNode = null; - - protected Stack fValuesBeingSet = new Stack(); - - public XMLPropertySourceAdapter(INodeNotifier target) { - super(); - fNode = (Node) target; - if (fNode instanceof XMLNode) { - Document ownerDocument = fNode.getOwnerDocument(); - if (ownerDocument == null) { - // if ownerDocument is null, then it must be the Document Node - ownerDocument = (Document) fNode; - } - DocumentTypeAdapter adapter = (DocumentTypeAdapter) ((INodeNotifier) ownerDocument).getAdapterFor(DocumentTypeAdapter.class); - if (adapter != null) - fCaseSensitive = adapter.getTagNameCase() == DocumentTypeAdapter.STRICT_CASE; - } - } - - private String[] _getValidFixedStrings(CMAttributeDeclaration attrDecl, CMDataType helper) { - String attributeName = attrDecl.getAttrName(); - 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 = attrDecl.getAttrName(); - 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; - } - - protected void clearDescriptors() { - fDescriptors = null; - } - - protected IPropertyDescriptor createDefaultPropertyDescriptor(String attributeName) { - return createDefaultPropertyDescriptor(attributeName, false); - } - - protected 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 - EnumeratedStringPropertyDescriptor descriptor = new EnumeratedStringPropertyDescriptor(attrDecl.getAttrName(), attrDecl.getAttrName(), _getValidStrings(attrDecl, valuesHelper)); - descriptor.setCategory(getCategory(attrDecl)); - descriptor.setDescription(attrDecl.getAttrName()); - 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 - EnumeratedStringPropertyDescriptor descriptor = new EnumeratedStringPropertyDescriptor(attrDecl.getNodeName(), attrDecl.getNodeName(), _getValidFixedStrings(attrDecl, helper)); - descriptor.setCategory(getCategory(attrDecl)); - descriptor.setDescription(attrDecl.getAttrName()); - 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. - */ - protected IPropertyDescriptor[] createPropertyDescriptors() { - CMNamedNodeMap attrMap = null; - CMElementDeclaration ed = getDeclaration(); - if (ed != null) { - attrMap = ed.getAttributes(); - } - - 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 { - 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 - if (attrDecl != null) { - descriptor = createPropertyDescriptor(attrDecl); - if (descriptor != null) - names.add(attrDecl.getNodeName()); - } else { - 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); - if (!names.contains(attrDecl.getAttrName())) { - IPropertyDescriptor holdDescriptor = createPropertyDescriptor(attrDecl); - if (holdDescriptor != null) { - 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) { - TextPropertyDescriptor descriptor = new TextPropertyDescriptor(attrDecl.getAttrName(), attrDecl.getAttrName()); - descriptor.setCategory(getCategory(attrDecl)); - descriptor.setDescription(attrDecl.getAttrName()); - if (attrDecl.getUsage() != CMAttributeDeclaration.REQUIRED && fSetExpertFilter) - descriptor.setFilterFlags(new String[]{IPropertySheetEntry.FILTER_ID_EXPERT}); - return descriptor; - } - - protected 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; - } - - protected 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 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 XMLNode) - returnedValue = ((XMLNode) attribute).getValueSource(); - else - returnedValue = attribute.getNodeValue(); - } - } - if (returnedValue == null) - returnedValue = ""; //$NON-NLS-1$ - return returnedValue; - } - - protected 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; - } - - /** - * Allowing the INodeAdapter to compare itself against the type allows it - * to return true in more than one case. - */ - public boolean isAdapterForType(Object type) { - return type == IPropertySource.class; - } - - protected boolean isFixedValue(CMAttributeDeclaration attrDecl) { - if (attrDecl == null) - return true; - - CMDataType attrType = attrDecl.getAttrType(); - if (attrType != null) { - return attrType.getImpliedValueKind() == CMDataType.IMPLIED_VALUE_FIXED || attrDecl.getUsage() == CMAttributeDeclaration.FIXED; - } - return false; - } - - /** - * 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; - } - - public void notifyChanged(INodeNotifier notifier, int eventType, java.lang.Object changedFeature, java.lang.Object oldValue, java.lang.Object newValue, int pos) { - } - - /** - * 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(); - } - - 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 XMLNode) - ((XMLNode) 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 XMLNode) - ((XMLNode) 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(); - } - // 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 = attrDecl.getAttrName(); - 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 = attrDecl.getAttrName(); - 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/views/properties/XMLPropertySourceAdapterFactory.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/properties/XMLPropertySourceAdapterFactory.java deleted file mode 100644 index 0d14000882..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/views/properties/XMLPropertySourceAdapterFactory.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.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 org.eclipse.ui.views.properties.IPropertySource; -import org.eclipse.wst.sse.core.AbstractAdapterFactory; -import org.eclipse.wst.sse.core.AdapterFactory; -import org.eclipse.wst.sse.core.INodeAdapter; -import org.eclipse.wst.sse.core.INodeNotifier; -import org.w3c.dom.Node; - - -public class XMLPropertySourceAdapterFactory extends AbstractAdapterFactory { - - public XMLPropertySourceAdapterFactory() { - super(IPropertySource.class, true); - } - - public XMLPropertySourceAdapterFactory(Object adapterKey, boolean registerAdapters) { - super(adapterKey, registerAdapters); - } - - public AdapterFactory copy() { - return new XMLPropertySourceAdapterFactory(this.adapterKey, this.shouldRegisterAdapter); - } - - protected INodeAdapter createAdapter(INodeNotifier target) { - // at the moment, only one implementation exists - if (target != null && target instanceof Node && ((Node) target).getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) - return new ProcessingInstructionPropertySourceAdapter(target); - return new XMLPropertySourceAdapter(target); - } -} 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 4a178765c2..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates.properties +++ /dev/null @@ -1,14 +0,0 @@ -############################################################################### -# Copyright (c) 2001, 2004 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.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 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 1ba2929662..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates.xml +++ /dev/null @@ -1,5 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<templates> - -<template name="%Templates.comment.name" description="%Templates.comment.desc" id="org.eclipse.wst.xml.ui.templates.comment" context="xml_tag" enabled="true"><!-- ${cursor} --></template> -</templates> diff --git a/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates_de.properties b/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates_de.properties deleted file mode 100644 index 9d5e20bf40..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates_de.properties +++ /dev/null @@ -1,14 +0,0 @@ -############################################################################### -# Copyright (c) 2001, 2004 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.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=Kommentar -Templates.comment.desc=XML-Kommentar diff --git a/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates_es.properties b/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates_es.properties deleted file mode 100644 index 3a5d4a3114..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates_es.properties +++ /dev/null @@ -1,14 +0,0 @@ -############################################################################### -# Copyright (c) 2001, 2004 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.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=Comentario xml diff --git a/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates_fr.properties b/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates_fr.properties deleted file mode 100644 index 15246b2d68..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates_fr.properties +++ /dev/null @@ -1,14 +0,0 @@ -############################################################################### -# Copyright (c) 2001, 2004 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.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=commentaire -Templates.comment.desc=commentaire xml diff --git a/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates_it.properties b/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates_it.properties deleted file mode 100644 index 7319bebc3d..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates_it.properties +++ /dev/null @@ -1,14 +0,0 @@ -############################################################################### -# Copyright (c) 2001, 2004 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.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=commento -Templates.comment.desc=commento xml diff --git a/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates_ja.properties b/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates_ja.properties deleted file mode 100644 index 8c87bc80fa..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates_ja.properties +++ /dev/null @@ -1,14 +0,0 @@ -############################################################################### -# Copyright (c) 2001, 2004 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.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=\u30b3\u30e1\u30f3\u30c8 -Templates.comment.desc=xml \u30b3\u30e1\u30f3\u30c8 diff --git a/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates_ko.properties b/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates_ko.properties deleted file mode 100644 index 8c61a284af..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates_ko.properties +++ /dev/null @@ -1,14 +0,0 @@ -############################################################################### -# Copyright (c) 2001, 2004 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.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=\uc8fc\uc11d -Templates.comment.desc=xml \uc8fc\uc11d diff --git a/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates_pt_BR.properties b/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates_pt_BR.properties deleted file mode 100644 index 3fe1125463..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates_pt_BR.properties +++ /dev/null @@ -1,14 +0,0 @@ -############################################################################### -# Copyright (c) 2001, 2004 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.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=coment\u00e1rio -Templates.comment.desc=coment\u00e1rio xml diff --git a/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates_zh_CN.properties b/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates_zh_CN.properties deleted file mode 100644 index 9bff0b4d3d..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates_zh_CN.properties +++ /dev/null @@ -1,14 +0,0 @@ -############################################################################### -# Copyright (c) 2001, 2004 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.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=\u6ce8\u91ca -Templates.comment.desc=xml \u6ce8\u91ca diff --git a/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates_zh_TW.properties b/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates_zh_TW.properties deleted file mode 100644 index b051523c64..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/templates/xmldefault-templates_zh_TW.properties +++ /dev/null @@ -1,14 +0,0 @@ -############################################################################### -# Copyright (c) 2001, 2004 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.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=\u8a3b\u89e3 -Templates.comment.desc=xml \u8a3b\u89e3 |