Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcbateman2009-08-11 00:15:04 +0000
committercbateman2009-08-11 00:15:04 +0000
commitc13ddaffccecfb04369703799790bd94f9a868a2 (patch)
treea0f82ab2ddf32823b89b1d7a6bfc6a8e7959630c
parent65ebde26b4859b3e6e164be8792c3e90d9d06bbc (diff)
downloadwebtools.jsf-c13ddaffccecfb04369703799790bd94f9a868a2.tar.gz
webtools.jsf-c13ddaffccecfb04369703799790bd94f9a868a2.tar.xz
webtools.jsf-c13ddaffccecfb04369703799790bd94f9a868a2.zip
Fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=285807.
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.common/META-INF/MANIFEST.MF1
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/pde/AbstractRegistryReader.java81
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/pde/AbstractSimpleClassExtensionRegistryReader.java221
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.standard.tagsupport/metadata/jsf_html_dti.xml38
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/schema/pageDesignerExtension.exsd20
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtmanager/converter/internal/AbstractAttributeValueResolver.java27
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtmanager/converter/internal/AttributeValueResolverRegistryReader.java75
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtmanager/converter/internal/DTTagConverterDecorator.java624
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtmanager/converter/internal/IAttributeValueResolver.java44
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/actions/DesignerStyleActionGroup.java7
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/parts/DocumentEditPart.java46
11 files changed, 950 insertions, 234 deletions
diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/META-INF/MANIFEST.MF b/jsf/plugins/org.eclipse.jst.jsf.common/META-INF/MANIFEST.MF
index 78a15afb3..b47e34913 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.common/META-INF/MANIFEST.MF
+++ b/jsf/plugins/org.eclipse.jst.jsf.common/META-INF/MANIFEST.MF
@@ -12,6 +12,7 @@ Export-Package: org.eclipse.jst.jsf.common;x-internal:=true,
org.eclipse.jst.jsf.common.facet.libraryprovider.jsf;x-internal:=true,
org.eclipse.jst.jsf.common.internal;x-friends:="org.eclipse.jst.jsf.core",
org.eclipse.jst.jsf.common.internal.managedobject;x-internal:=true,
+ org.eclipse.jst.jsf.common.internal.pde;x-internal:=true,
org.eclipse.jst.jsf.common.internal.policy;x-internal:=true,
org.eclipse.jst.jsf.common.internal.resource;x-friends:="org.eclipse.jst.jsf.core.tests",
org.eclipse.jst.jsf.common.internal.strategy;x-internal:=true,
diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/pde/AbstractRegistryReader.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/pde/AbstractRegistryReader.java
new file mode 100644
index 000000000..1773efbc8
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/pde/AbstractRegistryReader.java
@@ -0,0 +1,81 @@
+package org.eclipse.jst.jsf.common.internal.pde;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * A utility base class that simplifies the reading and caching of extension
+ * point information.
+ *
+ * @author cbateman
+ * @param <T>
+ *
+ */
+public abstract class AbstractRegistryReader<T>
+{
+ private final String _extPtNamespace;
+ private final String _extPtId;
+ private List<T> _extensions;
+ private final AtomicBoolean _isInitialized = new AtomicBoolean(false);
+
+ /**
+ * @param extPtNamespace
+ * @param extPtId
+ */
+ protected AbstractRegistryReader(final String extPtNamespace,
+ final String extPtId)
+ {
+ _extPtNamespace = extPtNamespace;
+ _extPtId = extPtId;
+ }
+
+ /**
+ * @return the extensions
+ */
+ public final List<T> getExtensions()
+ {
+ synchronized (_isInitialized)
+ {
+ if (_isInitialized.compareAndSet(false, true))
+ {
+ initialize();
+ }
+ return _extensions;
+ }
+ }
+
+ /**
+ * @param extensions
+ */
+ protected final void internalSetExtensions(List<T> extensions)
+ {
+ if (_extensions != null)
+ {
+ throw new IllegalStateException(
+ "internalSetExtensions should be called exactly once"); //$NON-NLS-1$
+ }
+ _extensions = Collections.unmodifiableList(extensions);
+ }
+
+ /**
+ * Called exactly once to initialize the registry.
+ */
+ protected abstract void initialize();
+
+ /**
+ * @return the extension point id. see IConfigurationElement.getName
+ */
+ protected final String getExtPtId()
+ {
+ return _extPtId;
+ }
+
+ /**
+ * @return the namespace of the extension point. see Bundle.getSymbolicName
+ */
+ protected final String getExtPtNamespace()
+ {
+ return _extPtNamespace;
+ }
+}
diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/pde/AbstractSimpleClassExtensionRegistryReader.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/pde/AbstractSimpleClassExtensionRegistryReader.java
new file mode 100644
index 000000000..594fa1a38
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/pde/AbstractSimpleClassExtensionRegistryReader.java
@@ -0,0 +1,221 @@
+package org.eclipse.jst.jsf.common.internal.pde;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jst.jsf.common.JSFCommonPlugin;
+
+/**
+ * @author cbateman
+ * @param <T>
+ *
+ */
+public abstract class AbstractSimpleClassExtensionRegistryReader<T> extends
+ AbstractRegistryReader<T>
+{
+
+ private final String _attributeName;
+ private final String _configElementName;
+ private final Comparator<SortableExecutableExtension<T>> _comparator;
+
+ /**
+ * @param extPtNamespace
+ * @param extPtId
+ * @param configElementName
+ * @param attributeName
+ * @param listComparator
+ * May be null if no sorting of the extensions list is required.
+ */
+ protected AbstractSimpleClassExtensionRegistryReader(
+ final String extPtNamespace, final String extPtId,
+ final String configElementName, final String attributeName,
+ final Comparator<SortableExecutableExtension<T>> listComparator)
+ {
+ super(extPtNamespace, extPtId);
+ _configElementName = configElementName;
+ _attributeName = attributeName;
+ _comparator = listComparator;
+ }
+
+ @Override
+ protected final void initialize()
+ {
+ final List<SortableExecutableExtension<T>> result = new ArrayList<SortableExecutableExtension<T>>();
+ final IExtensionPoint extensionPoint = Platform.getExtensionRegistry()
+ .getExtensionPoint(getExtPtNamespace(), getExtPtId());
+ IExtension[] extensions = extensionPoint.getExtensions();
+ for (int i = 0; i < extensions.length; i++)
+ {
+ IExtension ext = extensions[i];
+ IConfigurationElement[] tagConverter = ext
+ .getConfigurationElements();
+
+ for (int j = 0; j < tagConverter.length; j++)
+ {
+ final IConfigurationElement element = tagConverter[j];
+
+ if (element.getName().equals(_configElementName))
+ {
+ element.getAttribute(_attributeName);
+ try
+ {
+ final T obj = (T) element
+ .createExecutableExtension(_attributeName);
+ result.add(new SortableExecutableExtension<T>(
+ _comparator, element.getContributor().getName(),
+ obj));
+ } catch (ClassCastException ce)
+ {
+ handleLoadFailure(new CoreException(new Status(
+ IStatus.ERROR, JSFCommonPlugin.PLUGIN_ID,
+ "Extension class is not the expected type", ce))); //$NON-NLS-1$
+ } catch (CoreException e)
+ {
+ handleLoadFailure(e);
+ }
+ }
+ }
+ }
+
+ if (result.size() > 0)
+ {
+ if (_comparator != null)
+ {
+ Collections.sort(result, _comparator);
+ }
+ } else
+ {
+ JSFCommonPlugin.log(IStatus.WARNING, String.format(
+ "No extensions found for: %s.%s", //$NON-NLS-1$
+ getExtPtNamespace(), getExtPtId()));
+ }
+ final List<T> finalExtensions = new ArrayList<T>();
+ for (final SortableExecutableExtension<T> sortable : result)
+ {
+ finalExtensions.add(sortable.getExtensionObject());
+ }
+ internalSetExtensions(finalExtensions);
+ }
+
+ /**
+ * Called by initialize when an error occurs trying to load a class from an
+ * extension point. Sub-class should implement to handle the failure,
+ * typically to log it using their bundle id.
+ *
+ * @param ce
+ */
+ protected abstract void handleLoadFailure(final CoreException ce);
+
+ /**
+ * A comparator that sorts canonically by extension namespace and id, but
+ * can make exceptions for certain prefices.
+ *
+ * @param <T>
+ *
+ */
+ protected abstract static class CanonicalComparatorWithPrefixExceptions<T>
+ implements Comparator<SortableExecutableExtension<T>>
+ {
+
+ public int compare(SortableExecutableExtension<T> o1,
+ SortableExecutableExtension<T> o2)
+ {
+ int result = prefixSort(o1, o2);
+
+ // if the prefix sort doesn't distinguish a sort order, then
+ // compare it canonically
+ if (result == 0)
+ {
+ result = o1.getContributorId().compareTo(o2.getContributorId());
+ }
+
+ return result;
+ }
+
+ /**
+ * @param o1
+ * @param o2
+ * @return -1 if o1 should sort before o2 based on prefix. 1 if o2
+ * should sort before o1 or 0 if there is sort preference based
+ * on prefix.
+ */
+ protected abstract int prefixSort(SortableExecutableExtension<T> o1,
+ SortableExecutableExtension<T> o2);
+ }
+
+ /**
+ * Used to sort extensions before locking down the list.
+ *
+ * @param <T>
+ */
+ protected final static class SortableExecutableExtension<T> implements
+ Comparable<SortableExecutableExtension>
+ {
+ private final Comparator _comparator;
+ private final String _contributorId;
+ private final T _extensionObject;
+
+ private SortableExecutableExtension(final Comparator comparator,
+ final String contributorId, final T extensionObject)
+ {
+ if (comparator == null)
+ {
+ _comparator = new Comparator<T>()
+ {
+ public int compare(T o1, T o2)
+ {
+ // always return equal.
+ return 0;
+ }
+ };
+ } else
+ {
+ _comparator = comparator;
+ }
+ _contributorId = contributorId;
+ _extensionObject = extensionObject;
+ }
+
+ public int compareTo(SortableExecutableExtension o)
+ {
+ return _comparator.compare(this, o);
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ return _comparator.compare(this, obj) == 0;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return _contributorId.hashCode() ^ _extensionObject.hashCode();
+ }
+
+ /**
+ * @return the id of the bundle that contributed this extension
+ */
+ public String getContributorId()
+ {
+ return _contributorId;
+ }
+
+ /**
+ * @return the extension object
+ */
+ public T getExtensionObject()
+ {
+ return _extensionObject;
+ }
+ }
+}
diff --git a/jsf/plugins/org.eclipse.jst.jsf.standard.tagsupport/metadata/jsf_html_dti.xml b/jsf/plugins/org.eclipse.jst.jsf.standard.tagsupport/metadata/jsf_html_dti.xml
index 8841c0b11..5e9013f5f 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.standard.tagsupport/metadata/jsf_html_dti.xml
+++ b/jsf/plugins/org.eclipse.jst.jsf.standard.tagsupport/metadata/jsf_html_dti.xml
@@ -60,8 +60,9 @@
<tag-decorate-info id="vpd-decorate-design"
multiLevel="true"
widget="true"
- setNonVisualChildElements="true"
- />
+ setNonVisualChildElements="true">
+ <resolve-attribute-value attributeName="value"/>
+ </tag-decorate-info>
<tag-decorate-info id="vpd-decorate-preview">
<resolve-attribute-value attributeName="value"/>
</tag-decorate-info>
@@ -215,6 +216,10 @@
<tag-decorate-info id="vpd-decorate-preview">
<resolve-attribute-value attributeName="value"/>
</tag-decorate-info>
+
+ <tag-decorate-info id="vpd-decorate-design">
+ <resolve-attribute-value attributeName="value"/>
+ </tag-decorate-info>
</value>
</trait>
</entity>
@@ -244,6 +249,10 @@
<tag-decorate-info id="vpd-decorate-preview">
<resolve-attribute-value attributeName="value"/>
</tag-decorate-info>
+
+ <tag-decorate-info id="vpd-decorate-design">
+ <resolve-attribute-value attributeName="value"/>
+ </tag-decorate-info>
</value>
</trait>
</entity>
@@ -268,10 +277,14 @@
multiLevel="true"
widget="true"
setNonVisualChildElements="true"
- />
+ >
+ <resolve-attribute-value attributeName="value"/>
+ </tag-decorate-info>
<tag-decorate-info id="vpd-decorate-preview"
resolveChildText="true"
- />
+ >
+ <resolve-attribute-value attributeName="value"/>
+ </tag-decorate-info>
</value>
</trait>
</entity>
@@ -355,11 +368,14 @@
needBorderDecorator="true"
multiLevel="true"
widget="true"
- setNonVisualChildElements="true"
- />
+ setNonVisualChildElements="true">
+ <resolve-attribute-value attributeName="./text()/"/>
+ </tag-decorate-info>
<tag-decorate-info id="vpd-decorate-preview"
resolveChildText="true"
- />
+ >
+ <resolve-attribute-value attributeName="./text()/"/>
+ </tag-decorate-info>
</value>
</trait>
</entity>
@@ -415,10 +431,14 @@
multiLevel="true"
widget="true"
setNonVisualChildElements="true"
- />
+ >
+ <resolve-attribute-value attributeName="./text()/"/>
+ </tag-decorate-info>
<tag-decorate-info id="vpd-decorate-preview"
resolveChildText="true"
- />
+ >
+ <resolve-attribute-value attributeName="./text()/"/>
+ </tag-decorate-info>
</value>
</trait>
</entity>
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/schema/pageDesignerExtension.exsd b/jsf/plugins/org.eclipse.jst.pagedesigner/schema/pageDesignerExtension.exsd
index a3ddcd40a..4ed77d50b 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/schema/pageDesignerExtension.exsd
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/schema/pageDesignerExtension.exsd
@@ -28,6 +28,7 @@
<element ref="dtResourceProvider" minOccurs="0" maxOccurs="unbounded"/>
<element ref="propertyPageFactory" minOccurs="0" maxOccurs="unbounded"/>
<element ref="paletteFactory" minOccurs="0" maxOccurs="unbounded"/>
+ <element ref="attributeValueResolver" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
@@ -211,9 +212,9 @@ The exception to this rule is that if the reference is not plugin-qualified, the
<documentation>
Class extending &lt;code&gt;org.eclipse.jst.pagedesigner.dtresourceprovider.AbstractDTResourceProvider&lt;/code&gt;.
</documentation>
- <appinfo>
+ <appInfo>
<meta.attribute kind="java" basedOn="org.eclipse.jst.pagedesigner.dtresourceprovider.AbstractDTResourceProvider:"/>
- </appinfo>
+ </appInfo>
</annotation>
</attribute>
</complexType>
@@ -249,6 +250,21 @@ The exception to this rule is that if the reference is not plugin-qualified, the
</complexType>
</element>
+ <element name="attributeValueResolver">
+ <complexType>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java" basedOn="org.eclipse.jst.pagedesigner.dtmanager.converter.internal.AbstractAttributeValueResolver:"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
<annotation>
<appInfo>
<meta.section type="since"/>
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtmanager/converter/internal/AbstractAttributeValueResolver.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtmanager/converter/internal/AbstractAttributeValueResolver.java
new file mode 100644
index 000000000..3fbfae562
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtmanager/converter/internal/AbstractAttributeValueResolver.java
@@ -0,0 +1,27 @@
+package org.eclipse.jst.pagedesigner.dtmanager.converter.internal;
+
+import org.w3c.dom.Element;
+
+/**
+ *
+ *
+ */
+public abstract class AbstractAttributeValueResolver implements
+ IAttributeValueResolver
+{
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jst.pagedesigner.dtmanager.converter.internal.IAttributeValueResolver#canResolve(org.w3c.dom.Element, org.w3c.dom.Element, java.lang.String)
+ */
+ public abstract boolean canResolve(Element originalElement,
+ Element convertedElement, String convertedAttrName,
+ final String convertedAttrValue);
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jst.pagedesigner.dtmanager.converter.internal.IAttributeValueResolver#resolveAttribute(org.w3c.dom.Element, org.w3c.dom.Element, java.lang.String)
+ */
+ public abstract String resolveAttribute(Element originalElement,
+ Element convertedElement, String convertedAttrName,
+ final String convertedAttrValue);
+
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtmanager/converter/internal/AttributeValueResolverRegistryReader.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtmanager/converter/internal/AttributeValueResolverRegistryReader.java
new file mode 100644
index 000000000..64d045b8c
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtmanager/converter/internal/AttributeValueResolverRegistryReader.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Sybase, Inc. and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Sybase, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.dtmanager.converter.internal;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jst.jsf.common.internal.pde.AbstractSimpleClassExtensionRegistryReader;
+import org.eclipse.jst.pagedesigner.IJMTConstants;
+import org.eclipse.jst.pagedesigner.PDPlugin;
+
+/**
+ * @author mengbo
+ * @version 1.5
+ */
+public class AttributeValueResolverRegistryReader extends
+ AbstractSimpleClassExtensionRegistryReader<IAttributeValueResolver>
+{
+ private final static AttributeValueResolverRegistryReader INSTANCE = new AttributeValueResolverRegistryReader();
+
+ /**
+ * Not externally instantiable.
+ */
+ private AttributeValueResolverRegistryReader()
+ {
+ super(PDPlugin.getPluginId(),
+ IJMTConstants.EXTENSION_POINT_PAGEDESIGNER,
+ "attributeValueResolver", //$NON-NLS-1$
+ "class", //$NON-NLS-1$
+ new CanonicalComparatorWithPrefixExceptions<IAttributeValueResolver>()
+ {
+ @Override
+ protected int prefixSort(
+ SortableExecutableExtension<IAttributeValueResolver> o1,
+ SortableExecutableExtension<IAttributeValueResolver> o2)
+ {
+ // if o1 is contributed by open source, sort it
+ // after
+ if (o1.getContributorId().startsWith("org.eclipse.jst")) //$NON-NLS-1$
+ {
+ return 1;
+ }
+ // if o2 is contributed by open source, sort o1 first
+ else if (o2.getContributorId().startsWith("org.eclipse.jst")) //$NON-NLS-1$
+ {
+ return -1;
+ }
+ // otherwise, we don't care
+ return 0;
+ }
+ });
+ }
+
+ /**
+ * @return singleton instance.
+ */
+ public static AttributeValueResolverRegistryReader getInstance()
+ {
+ return INSTANCE;
+ }
+
+ @Override
+ protected void handleLoadFailure(CoreException ce)
+ {
+ PDPlugin.log("Loading Attribute Value Resolver extensions", ce); //$NON-NLS-1$
+ }
+
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtmanager/converter/internal/DTTagConverterDecorator.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtmanager/converter/internal/DTTagConverterDecorator.java
index 59d66830e..124c1ba1d 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtmanager/converter/internal/DTTagConverterDecorator.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtmanager/converter/internal/DTTagConverterDecorator.java
@@ -7,21 +7,25 @@
*
* Contributors:
* Oracle Corporation - initial API and implementation
- *******************************************************************************/
+ *******************************************************************************/
package org.eclipse.jst.pagedesigner.dtmanager.converter.internal;
import java.net.URL;
+import javax.servlet.jsp.el.ELException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
+import org.eclipse.core.runtime.ISafeRunnable;
+import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jst.jsf.common.metadata.Trait;
import org.eclipse.jst.jsf.common.metadata.internal.IImageDescriptorProvider;
import org.eclipse.jst.jsf.common.metadata.internal.IMetaDataSourceModelProvider;
import org.eclipse.jst.jsf.common.metadata.internal.IResourceURLProvider;
+import org.eclipse.jst.pagedesigner.PDPlugin;
import org.eclipse.jst.pagedesigner.converter.IConverterFactory;
import org.eclipse.jst.pagedesigner.converter.ITagConverter;
import org.eclipse.jst.pagedesigner.dtmanager.DTManager;
@@ -40,231 +44,419 @@ import org.w3c.dom.Text;
*
* @author Ian Trimble - Oracle
*/
-public class DTTagConverterDecorator implements ITagConverterDecorator {
+public class DTTagConverterDecorator implements ITagConverterDecorator
+{
- private static final String DECORATE_INFO_ID_DESIGN = "vpd-decorate-design"; //$NON-NLS-1$
- private static final String DECORATE_INFO_ID_PREVIEW = "vpd-decorate-preview"; //$NON-NLS-1$
- private static final String MD_PLUGIN_LOCATION = "$metadata-plugin-location$"; //$NON-NLS-1$
+ private static final String DECORATE_INFO_ID_DESIGN = "vpd-decorate-design"; //$NON-NLS-1$
+ private static final String DECORATE_INFO_ID_PREVIEW = "vpd-decorate-preview"; //$NON-NLS-1$
+ private static final String MD_PLUGIN_LOCATION = "$metadata-plugin-location$"; //$NON-NLS-1$
- /*
- * (non-Javadoc)
- * @see org.eclipse.jst.pagedesigner.dtmanager.converter.ITagConverterDecorator#decorate(org.eclipse.jst.pagedesigner.converter.ITagConverter)
- */
- public void decorate(ITagConverter tagConverter) {
- if (!(tagConverter instanceof DTTagConverter)) {
- throw new IllegalArgumentException("ITagConverter argument must be an instance of DTTagConverter"); //$NON-NLS-1$
- }
- DTTagConverter dtTagConverter = (DTTagConverter)tagConverter;
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jst.pagedesigner.dtmanager.converter.ITagConverterDecorator
+ * #decorate(org.eclipse.jst.pagedesigner.converter.ITagConverter)
+ */
+ public void decorate(ITagConverter tagConverter)
+ {
+ if (!(tagConverter instanceof DTTagConverter))
+ {
+ throw new IllegalArgumentException(
+ "ITagConverter argument must be an instance of DTTagConverter"); //$NON-NLS-1$
+ }
+ DTTagConverter dtTagConverter = (DTTagConverter) tagConverter;
- if (dtTagConverter.getMode() == IConverterFactory.MODE_DESIGNER) {
- decorateFromDTInfo(dtTagConverter, DECORATE_INFO_ID_DESIGN);
- } else if (dtTagConverter.getMode() == IConverterFactory.MODE_PREVIEW) {
- decorateFromDTInfo(dtTagConverter, DECORATE_INFO_ID_PREVIEW);
- }
+ if (dtTagConverter.getMode() == IConverterFactory.MODE_DESIGNER)
+ {
+ decorateFromDTInfo(dtTagConverter, DECORATE_INFO_ID_DESIGN);
+ } else if (dtTagConverter.getMode() == IConverterFactory.MODE_PREVIEW)
+ {
+ decorateFromDTInfo(dtTagConverter, DECORATE_INFO_ID_PREVIEW);
+ }
- if (tagConverter.getResultElement() == null && tagConverter.isVisualByHTML()) {
- createUnknownTagRepresentation(dtTagConverter);
- }
- }
+ if (tagConverter.getResultElement() == null
+ && tagConverter.isVisualByHTML())
+ {
+ createUnknownTagRepresentation(dtTagConverter);
+ }
+ }
- /**
- * Performs decoration of the specified DTTagConverter instance from
- * IDTInfo (metadata) for the specified (by ID) TagDecorateInfo.
- *
- * @param dtTagConverter DTTagConverter instance.
- * @param tagDecorateInfoID ID of the TagDecorateInfo to be located in
- * metadata.
- */
- protected void decorateFromDTInfo(DTTagConverter dtTagConverter, String tagDecorateInfoID) {
- Element srcElement = dtTagConverter.getHostElement();
- DTManager dtManager = DTManager.getInstance();
- IDTInfo dtInfo = dtManager.getDTInfo(srcElement);
- if (dtInfo != null) {
- TagDecorateInfo tdInfo = dtInfo.getTagDecorateInfo(tagDecorateInfoID);
- if (tdInfo != null) {
- dtTagConverter.setMultiLevel(tdInfo.isMultiLevel());
- dtTagConverter.setNeedBorderDecorator(tdInfo.isNeedBorderDecorator());
- dtTagConverter.setNeedTableDecorator(tdInfo.isNeedTableDecorator());
- if (tdInfo.isNonVisual()) {
- setNonVisual(dtTagConverter, dtInfo, tdInfo.getNonVisualImagePath());
- }
- if (tdInfo.isResolveChildText()) {
- resolveChildText(dtTagConverter.getResultElement(), dtInfo);
- }
- if (tdInfo.isSetNonVisualChildElements()) {
- setNonVisualChildElements(dtTagConverter, srcElement);
- }
- dtTagConverter.setWidget(tdInfo.isWidget());
- dtTagConverter.setMinHeight(tdInfo.getMinHeight());
- dtTagConverter.setMinWidth(tdInfo.getMinWidth());
- ResolveAttributeValue resAttrValue = tdInfo.getResolveAttributeValue();
- if (resAttrValue != null) {
- String attributeName = resAttrValue.getAttributeName();
- if (attributeName != null && attributeName.length() > 0) {
- resolveAttributeValue(dtTagConverter.getResultElement(), attributeName, dtInfo);
- }
- }
- }
- }
- }
+ /**
+ * Performs decoration of the specified DTTagConverter instance from IDTInfo
+ * (metadata) for the specified (by ID) TagDecorateInfo.
+ *
+ * @param dtTagConverter
+ * DTTagConverter instance.
+ * @param tagDecorateInfoID
+ * ID of the TagDecorateInfo to be located in metadata.
+ */
+ protected void decorateFromDTInfo(DTTagConverter dtTagConverter,
+ String tagDecorateInfoID)
+ {
+ Element srcElement = dtTagConverter.getHostElement();
+ DTManager dtManager = DTManager.getInstance();
+ IDTInfo dtInfo = dtManager.getDTInfo(srcElement);
+ if (dtInfo != null)
+ {
+ TagDecorateInfo tdInfo = dtInfo
+ .getTagDecorateInfo(tagDecorateInfoID);
+ if (tdInfo != null)
+ {
+ dtTagConverter.setMultiLevel(tdInfo.isMultiLevel());
+ dtTagConverter.setNeedBorderDecorator(tdInfo
+ .isNeedBorderDecorator());
+ dtTagConverter.setNeedTableDecorator(tdInfo
+ .isNeedTableDecorator());
+ if (tdInfo.isNonVisual())
+ {
+ setNonVisual(dtTagConverter, dtInfo, tdInfo
+ .getNonVisualImagePath());
+ }
+ if (tdInfo.isResolveChildText())
+ {
+ resolveChildText(dtTagConverter.getResultElement(), dtInfo);
+ }
+ if (tdInfo.isSetNonVisualChildElements())
+ {
+ setNonVisualChildElements(dtTagConverter, srcElement);
+ }
+ dtTagConverter.setWidget(tdInfo.isWidget());
+ dtTagConverter.setMinHeight(tdInfo.getMinHeight());
+ dtTagConverter.setMinWidth(tdInfo.getMinWidth());
+ ResolveAttributeValue resAttrValue = tdInfo
+ .getResolveAttributeValue();
+ if (resAttrValue != null)
+ {
+ String attributeName = resAttrValue.getAttributeName();
+ if (attributeName != null && attributeName.length() > 0)
+ {
+ resolveAttributeValue(dtTagConverter.getHostElement(),
+ dtTagConverter.getResultElement(),
+ attributeName, dtInfo, tagDecorateInfoID);
+ }
+ }
+ }
+ }
+ }
- /**
- * Creates a visual representation result Element for an unknown tag.
- *
- * @param dtTagConverter DTTagConverter instance.
- */
- protected void createUnknownTagRepresentation(DTTagConverter dtTagConverter) {
- Element element = dtTagConverter.createElement("span"); //$NON-NLS-1$
- element.setAttribute("style", "color:red;font-weight:bold;"); //$NON-NLS-1$ //$NON-NLS-2$
- Text text = dtTagConverter.createText("<" + dtTagConverter.getHostElement().getTagName() + "/>"); //$NON-NLS-1$ //$NON-NLS-2$
- element.appendChild(text);
- dtTagConverter.setResultElement(element);
- dtTagConverter.setWidget(true);
- }
+ /**
+ * Creates a visual representation result Element for an unknown tag.
+ *
+ * @param dtTagConverter
+ * DTTagConverter instance.
+ */
+ protected void createUnknownTagRepresentation(DTTagConverter dtTagConverter)
+ {
+ Element element = dtTagConverter.createElement("span"); //$NON-NLS-1$
+ element.setAttribute("style", "color:red;font-weight:bold;"); //$NON-NLS-1$ //$NON-NLS-2$
+ Text text = dtTagConverter
+ .createText("<" + dtTagConverter.getHostElement().getTagName() + "/>"); //$NON-NLS-1$ //$NON-NLS-2$
+ element.appendChild(text);
+ dtTagConverter.setResultElement(element);
+ dtTagConverter.setWidget(true);
+ }
- /**
- * Adds child Elements of the specified source Element to the specified
- * DTTagConverter instance's collection of non-visual children.
- *
- * @param dtTagConverter DTTagConverter instance.
- * @param srcElement Source Element for which child Elements are to be
- * added.
- */
- protected void setNonVisualChildElements(DTTagConverter dtTagConverter, Element srcElement) {
- NodeList childNodes = srcElement.getChildNodes();
- for (int i = 0; i < childNodes.getLength(); i++) {
- Node curNode = childNodes.item(i);
- if (curNode.getNodeType() == Node.ELEMENT_NODE) {
- dtTagConverter.addNonVisualChildElement((Element)curNode);
- }
- }
- }
+ /**
+ * Adds child Elements of the specified source Element to the specified
+ * DTTagConverter instance's collection of non-visual children.
+ *
+ * @param dtTagConverter
+ * DTTagConverter instance.
+ * @param srcElement
+ * Source Element for which child Elements are to be added.
+ */
+ protected void setNonVisualChildElements(DTTagConverter dtTagConverter,
+ Element srcElement)
+ {
+ NodeList childNodes = srcElement.getChildNodes();
+ for (int i = 0; i < childNodes.getLength(); i++)
+ {
+ Node curNode = childNodes.item(i);
+ if (curNode.getNodeType() == Node.ELEMENT_NODE)
+ {
+ dtTagConverter.addNonVisualChildElement((Element) curNode);
+ }
+ }
+ }
- /**
- * Performs simple EL resolution for the child Text Node of the specified
- * source Element instance.
- *
- * @param srcElement Source Element for which child Text Node EL resolution
- * is to be performed.
- * @param dtInfo IDTInfo instance.
- */
- protected void resolveChildText(Element srcElement, IDTInfo dtInfo) {
- if (srcElement != null) {
- NodeList childNodes = srcElement.getChildNodes();
- for (int i = 0; i < childNodes.getLength(); i++) {
- Node childNode = childNodes.item(i);
- if (childNode.getNodeType() == Node.TEXT_NODE) {
- Text textNode = (Text)childNode;
- String textNodeValue = textNode.getNodeValue();
- try {
- String newTextNodeValue;
- if (textNodeValue.contains(MD_PLUGIN_LOCATION)) {
- newTextNodeValue = resolveMDPluginLocation(textNodeValue, dtInfo);
- } else {
- newTextNodeValue = (String)PageExpressionContext.getCurrent().evaluateExpression(textNodeValue, String.class, null);
- }
- if (newTextNodeValue != null && !textNodeValue.equals(newTextNodeValue)) {
- textNode.setNodeValue(newTextNodeValue);
- }
- } catch(Exception ex) {
- //ignore - could not resolve, do not change existing value
- }
- }
- }
- }
- }
+ /**
+ * Performs simple EL resolution for the child Text Node of the specified
+ * source Element instance.
+ *
+ * @param srcElement
+ * Source Element for which child Text Node EL resolution is to
+ * be performed.
+ * @param dtInfo
+ * IDTInfo instance.
+ */
+ protected void resolveChildText(Element srcElement, IDTInfo dtInfo)
+ {
+ if (srcElement != null)
+ {
+ NodeList childNodes = srcElement.getChildNodes();
+ for (int i = 0; i < childNodes.getLength(); i++)
+ {
+ Node childNode = childNodes.item(i);
+ if (childNode.getNodeType() == Node.TEXT_NODE)
+ {
+ Text textNode = (Text) childNode;
+ String textNodeValue = textNode.getNodeValue();
+ try
+ {
+ String newTextNodeValue;
+ if (textNodeValue.contains(MD_PLUGIN_LOCATION))
+ {
+ newTextNodeValue = resolveMDPluginLocation(
+ textNodeValue, dtInfo);
+ } else
+ {
+ newTextNodeValue = (String) PageExpressionContext
+ .getCurrent().evaluateExpression(
+ textNodeValue, String.class, null);
+ }
+ if (newTextNodeValue != null
+ && !textNodeValue.equals(newTextNodeValue))
+ {
+ textNode.setNodeValue(newTextNodeValue);
+ }
+ } catch (Exception ex)
+ {
+ // ignore - could not resolve, do not change existing
+ // value
+ }
+ }
+ }
+ }
+ }
- /**
- * Performs simple EL resolution for the value of the specified attribute
- * of the specified Element.
- *
- * @param srcElement Source Element instance.
- * @param attributeName Name of attribute for which the value should be
- * resolved.
- * @param dtInfo IDTInfo instance.
- */
- protected void resolveAttributeValue(Element srcElement, String attributeName, IDTInfo dtInfo) {
- if (srcElement != null) {
- Element targetElement = srcElement;
- String targetAttributeName = attributeName;
- //determine if attributeName is XPath and re-target as appropriate
- if (attributeName.contains("/")) { //$NON-NLS-1$
- int lastSlashPos = attributeName.lastIndexOf("/"); //$NON-NLS-1$
- String xPathExpression = attributeName.substring(0, lastSlashPos);
- XPath xPath = XPathFactory.newInstance().newXPath();
- try {
- Object resultObject = xPath.evaluate(xPathExpression, srcElement, XPathConstants.NODE);
- if (resultObject instanceof Element) {
- targetElement = (Element)resultObject;
- targetAttributeName = attributeName.substring(lastSlashPos + 1);
- }
- } catch(XPathExpressionException xee) {
- //could not evaluate - leave targetElement and targetAttributeName unchanged
- }
- }
- String oldAttributeValue = targetElement.getAttribute(targetAttributeName);
- if (oldAttributeValue != null && oldAttributeValue.length() > 0) {
- try {
- String newAttributeValue;
- if (oldAttributeValue.contains(MD_PLUGIN_LOCATION)) {
- newAttributeValue = resolveMDPluginLocation(oldAttributeValue, dtInfo);
- } else {
- newAttributeValue = (String)PageExpressionContext.getCurrent().evaluateExpression(oldAttributeValue, String.class, null);
- }
- if (newAttributeValue != null && !oldAttributeValue.equals(newAttributeValue)) {
- targetElement.setAttribute(targetAttributeName, newAttributeValue);
- }
- } catch(Exception ex) {
- //ignore - could not resolve, do not change existing value
- }
- }
- }
- }
+ /**
+ * Performs simple EL resolution for the value of the specified attribute of
+ * the specified Element.
+ *
+ * @param srcElement
+ *
+ * @param targetElement
+ * Source Element instance.
+ * @param attributeName
+ * Name of attribute for which the value should be resolved.
+ * @param dtInfo
+ * IDTInfo instance.
+ * @param tagDecorateInfoID
+ */
+ protected void resolveAttributeValue(Element srcElement,
+ Element targetElement, String attributeName, IDTInfo dtInfo,
+ String tagDecorateInfoID)
+ {
+ if (targetElement != null)
+ {
+ String oldAttributeValue = null;
+ String targetAttributeName = attributeName;
+ // determine if attributeName is XPath and re-target as appropriate
+ if (attributeName.contains("/")) { //$NON-NLS-1$
+ int lastSlashPos = attributeName.lastIndexOf("/"); //$NON-NLS-1$
+ String xPathExpression = attributeName.substring(0,
+ lastSlashPos);
+ XPath xPath = XPathFactory.newInstance().newXPath();
+ try
+ {
+ Object resultObject = xPath.evaluate(xPathExpression,
+ targetElement, XPathConstants.NODE);
+ if (resultObject instanceof Element)
+ {
+ targetElement = (Element) resultObject;
+ targetAttributeName = attributeName
+ .substring(lastSlashPos + 1);
+ }
+ else if (resultObject instanceof Text)
+ {
+ Node parentNode = ((Text)resultObject).getParentNode();
+ if (parentNode instanceof Element)
+ {
+ parentNode.normalize();
+ targetAttributeName = IAttributeValueResolver.TEXT_NODE_KEY;
+ oldAttributeValue = ((Text)resultObject).getNodeValue();
+ }
+ }
+ }
+ catch (XPathExpressionException xee)
+ {
+ // could not evaluate - leave targetElement and
+ // targetAttributeName unchanged
+ }
+ }
- /**
- * Resolves any instance of MD_PLUGIN_LOCATION in input String.
- *
- * @param input Input String.
- * @param dtInfo IDTInfo instance.
- * @return Input String with any instance of MD_PLUGIN_LOCATION resolved.
- */
- protected String resolveMDPluginLocation(String input, IDTInfo dtInfo) {
- String output = input;
- if (input != null && input.contains(MD_PLUGIN_LOCATION)) {
- int tokenStart = input.indexOf(MD_PLUGIN_LOCATION);
- int tokenEnd = tokenStart + MD_PLUGIN_LOCATION.length();
- String prefix = input.substring(0, tokenStart);
- String suffix = input.substring(tokenEnd);
- Trait trait = dtInfo.getTrait();
- IMetaDataSourceModelProvider mdSourceModelProvider = trait.getSourceModelProvider();
- IResourceURLProvider resourceURLProvider = (IResourceURLProvider)mdSourceModelProvider.getAdapter(IResourceURLProvider.class);
- URL url = resourceURLProvider.getResourceURL("/META-INF/"); //$NON-NLS-1$
- String resolvedToken = url.toExternalForm();
- resolvedToken = resolvedToken.substring(0, resolvedToken.length() - 10);
- output = prefix + resolvedToken + suffix;
- }
- return output;
- }
+
+ if (!IAttributeValueResolver.TEXT_NODE_KEY.equals(targetAttributeName))
+ {
+ oldAttributeValue = targetElement.getAttribute(targetAttributeName);
+ }
- /**
- * Sets DTTagConverter instance as non-visual as HTML and sets the
- * ImageDescriptor instance that DTTagConverter will use to return an Image
- * for rendering.
- *
- * @param dtTagConverter DTTagConverter instance.
- * @param dtInfo IDTInfo instance.
- * @param imagePath Image path, relative to declaring plug-in.
- */
- protected void setNonVisual(DTTagConverter dtTagConverter, IDTInfo dtInfo, String imagePath) {
- dtTagConverter.setVisualByHTML(false);
- if (imagePath != null && imagePath.length() > 0) {
- Trait trait = dtInfo.getTrait();
- IImageDescriptorProvider imgDescProvider = (IImageDescriptorProvider)trait.getSourceModelProvider().getAdapter(IImageDescriptorProvider.class);
- if (imgDescProvider != null) {
- ImageDescriptor imageDescriptor = imgDescProvider.getImageDescriptor(imagePath);
- dtTagConverter.setVisualImageDescriptor(imageDescriptor);
- }
- }
- }
+ if (oldAttributeValue != null && oldAttributeValue.length() > 0)
+ {
+ String newAttributeValue;
+ if (oldAttributeValue.contains(MD_PLUGIN_LOCATION))
+ {
+ newAttributeValue = resolveMDPluginLocation(
+ oldAttributeValue, dtInfo);
+ }
+ else
+ {
+ newAttributeValue = resolveAttributeValue(srcElement,
+ targetElement, targetAttributeName,
+ oldAttributeValue, tagDecorateInfoID);
+ }
+ if (newAttributeValue != null
+ && !oldAttributeValue.equals(newAttributeValue))
+ {
+ if (IAttributeValueResolver.TEXT_NODE_KEY
+ .equals(targetAttributeName))
+ {
+ for (int i = targetElement.getChildNodes().getLength()-1; i >= 0; i--)
+ {
+ Node childNode = targetElement.getChildNodes().item(i);
+ if (childNode.getNodeType() == Node.TEXT_NODE)
+ {
+ targetElement.removeChild(childNode);
+ }
+ }
+ targetElement.appendChild(targetElement.getOwnerDocument().createTextNode(newAttributeValue));
+ }
+ else
+ {
+ targetElement.setAttribute(targetAttributeName,
+ newAttributeValue);
+ }
+ }
+ }
+ }
+ }
+
+ private String resolveAttributeValue(final Element originalElement,
+ final Element convertedElement,
+ final String convertedAttributeName, final String oldAttributeValue,
+ final String tagDecorateInfoID)
+ {
+ String newValue = null;
+ boolean valueResolved = false;
+ final String[] result = new String[1];
+
+ for (final IAttributeValueResolver resolver : AttributeValueResolverRegistryReader
+ .getInstance().getExtensions())
+ {
+ SafeRunner.run(new ISafeRunnable()
+ {
+ public void handleException(Throwable exception)
+ {
+ PDPlugin
+ .log(
+ "While resolving attribute in converter decorator", exception); //$NON-NLS-1$
+ }
+
+ public void run() throws Exception
+ {
+ if (resolver.canResolve(originalElement,
+ convertedElement, convertedAttributeName, oldAttributeValue))
+ {
+ result[0] = resolver.resolveAttribute(
+ originalElement, convertedElement,
+ convertedAttributeName, oldAttributeValue);
+ }
+ }
+ });
+ if (result[0] != null)
+ {
+ newValue = result[0];
+ valueResolved = true;
+ break;
+ }
+ }
+
+ if (!valueResolved &&
+ // maintain backward compatibility: only do this default
+ // behaviour for the preview
+ tagDecorateInfoID.equals(DECORATE_INFO_ID_PREVIEW))
+ {
+ // fall- through to default case.
+ try
+ {
+
+ PageExpressionContext current = PageExpressionContext.getCurrent();
+ if (current != null)
+ {
+ return (String) current
+ .evaluateExpression(oldAttributeValue, String.class,
+ null);
+ }
+ } catch (ELException e)
+ {
+ // ignore. we will just return null since couldn't resolve
+ }
+ }
+ return newValue;
+ }
+
+ /**
+ * Resolves any instance of MD_PLUGIN_LOCATION in input String.
+ *
+ * @param input
+ * Input String.
+ * @param dtInfo
+ * IDTInfo instance.
+ * @return Input String with any instance of MD_PLUGIN_LOCATION resolved.
+ */
+ protected String resolveMDPluginLocation(String input, IDTInfo dtInfo)
+ {
+ String output = input;
+ if (input != null && input.contains(MD_PLUGIN_LOCATION))
+ {
+ int tokenStart = input.indexOf(MD_PLUGIN_LOCATION);
+ int tokenEnd = tokenStart + MD_PLUGIN_LOCATION.length();
+ String prefix = input.substring(0, tokenStart);
+ String suffix = input.substring(tokenEnd);
+ Trait trait = dtInfo.getTrait();
+ IMetaDataSourceModelProvider mdSourceModelProvider = trait
+ .getSourceModelProvider();
+ IResourceURLProvider resourceURLProvider = (IResourceURLProvider) mdSourceModelProvider
+ .getAdapter(IResourceURLProvider.class);
+ URL url = resourceURLProvider.getResourceURL("/META-INF/"); //$NON-NLS-1$
+ String resolvedToken = url.toExternalForm();
+ resolvedToken = resolvedToken.substring(0,
+ resolvedToken.length() - 10);
+ output = prefix + resolvedToken + suffix;
+ }
+ return output;
+ }
+
+ /**
+ * Sets DTTagConverter instance as non-visual as HTML and sets the
+ * ImageDescriptor instance that DTTagConverter will use to return an Image
+ * for rendering.
+ *
+ * @param dtTagConverter
+ * DTTagConverter instance.
+ * @param dtInfo
+ * IDTInfo instance.
+ * @param imagePath
+ * Image path, relative to declaring plug-in.
+ */
+ protected void setNonVisual(DTTagConverter dtTagConverter, IDTInfo dtInfo,
+ String imagePath)
+ {
+ dtTagConverter.setVisualByHTML(false);
+ if (imagePath != null && imagePath.length() > 0)
+ {
+ Trait trait = dtInfo.getTrait();
+ IImageDescriptorProvider imgDescProvider = (IImageDescriptorProvider) trait
+ .getSourceModelProvider().getAdapter(
+ IImageDescriptorProvider.class);
+ if (imgDescProvider != null)
+ {
+ ImageDescriptor imageDescriptor = imgDescProvider
+ .getImageDescriptor(imagePath);
+ dtTagConverter.setVisualImageDescriptor(imageDescriptor);
+ }
+ }
+ }
}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtmanager/converter/internal/IAttributeValueResolver.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtmanager/converter/internal/IAttributeValueResolver.java
new file mode 100644
index 000000000..e654f5cae
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtmanager/converter/internal/IAttributeValueResolver.java
@@ -0,0 +1,44 @@
+package org.eclipse.jst.pagedesigner.dtmanager.converter.internal;
+
+import org.w3c.dom.Element;
+
+/**
+ * Marks an object that can resolve the runtime value of an attribute at
+ * design time. The "runtime" value may be a best-guess or simulated value.
+ *
+ * @author cbateman
+ *
+ */
+public interface IAttributeValueResolver
+{
+ /**
+ * Passed as convertedAttrName if the convertedElement's text content
+ * is the 'attribute' to be resolved.
+ */
+ public static final String TEXT_NODE_KEY = "#text"; //$NON-NLS-1$
+
+ /**
+ * @param originalElement
+ * @param convertedElement
+ * @param convertedAttrName
+ * @param convertedAttrValue
+ *
+ * @return true if this resolver can resolve the value of attrName on domNode
+ */
+ public abstract boolean canResolve(final Element originalElement,
+ final Element convertedElement,
+ final String convertedAttrName,
+ final String convertedAttrValue);
+
+ /**
+ * @param originalElement
+ * @param convertedElement
+ * @param convertedAttrName
+ * @param convertedAttrValue
+ * @return the resolved String value of attrName. A value of null does not necessarily
+ * mean that the value couldn't be resolved.
+ */
+ public abstract String resolveAttribute(final Element originalElement,
+ final Element convertedElement, final String convertedAttrName,
+ final String convertedAttrValue);
+} \ No newline at end of file
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/actions/DesignerStyleActionGroup.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/actions/DesignerStyleActionGroup.java
index b100321ff..6c121dfb8 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/actions/DesignerStyleActionGroup.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/actions/DesignerStyleActionGroup.java
@@ -197,9 +197,12 @@ public class DesignerStyleActionGroup extends ActionGroup
{
final IHandlerService service = (IHandlerService) _htmlEditor.getSite()
.getService(IHandlerService.class);
- for (final IHandlerActivation activation : _handlers)
+ if (service != null)
{
- service.deactivateHandler(activation);
+ for (final IHandlerActivation activation : _handlers)
+ {
+ service.deactivateHandler(activation);
+ }
}
_handlers.clear();
}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/parts/DocumentEditPart.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/parts/DocumentEditPart.java
index 71a42143d..92c9bb9f4 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/parts/DocumentEditPart.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/parts/DocumentEditPart.java
@@ -81,6 +81,25 @@ public class DocumentEditPart extends NodeEditPart implements StyleListener,
refresh();
}
+ /**
+ * @param recursive
+ */
+ public void refresh(final boolean recursive)
+ {
+ if (!recursive)
+ {
+ refresh();
+ }
+ else
+ {
+ refreshVisuals();
+ refreshChildren(recursive);
+ refreshSourceConnections();
+ refreshTargetConnections();
+
+ }
+ }
+
/*
* (non-Javadoc)
*
@@ -104,13 +123,30 @@ public class DocumentEditPart extends NodeEditPart implements StyleListener,
* @see org.eclipse.gef.editparts.AbstractEditPart#refreshChildren()
*/
protected void refreshChildren() {
- super.refreshChildren();
- List children1 = getChildren();
- for (int i = 0, size = children1.size(); i < size; i++) {
- ((EditPart) children1.get(i)).refresh();
- }
+ refreshChildren(false);
}
+ /**
+ * @param recursive
+ */
+ protected void refreshChildren(final boolean recursive)
+ {
+ super.refreshChildren();
+ List children1 = getChildren();
+ for (int i = 0, size = children1.size(); i < size; i++)
+ {
+ final EditPart editPart = (EditPart) children1.get(i);
+ if (editPart instanceof ElementEditPart)
+ {
+ ((ElementEditPart)editPart).refresh(recursive);
+ }
+ else
+ {
+ editPart.refresh();
+ }
+ }
+ }
+
// protected void removeChildVisual(EditPart childEditPart)
// {
// if (childEditPart instanceof SubNodeEditPart)

Back to the top