diff options
author | itrimble | 2011-03-15 17:01:31 +0000 |
---|---|---|
committer | itrimble | 2011-03-15 17:01:31 +0000 |
commit | bb6167abcf793d292cbf56eed40c5be5356ae124 (patch) | |
tree | ac7a0b45f398880cbb1570b6df82859d836828ec | |
parent | 3579a376d826e95fb70421bb2d5c830c94986d38 (diff) | |
download | webtools.jsf-bb6167abcf793d292cbf56eed40c5be5356ae124.tar.gz webtools.jsf-bb6167abcf793d292cbf56eed40c5be5356ae124.tar.xz webtools.jsf-bb6167abcf793d292cbf56eed40c5be5356ae124.zip |
Bug 221730 - [API] inlineStyle properties dialog sets (invalid) style
11 files changed, 503 insertions, 45 deletions
diff --git a/jsf/plugins/org.eclipse.jst.jsf.apache.trinidad.tagsupport/metadata/trinidad.xml b/jsf/plugins/org.eclipse.jst.jsf.apache.trinidad.tagsupport/metadata/trinidad.xml index 218157a80..5b0dfa802 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.apache.trinidad.tagsupport/metadata/trinidad.xml +++ b/jsf/plugins/org.eclipse.jst.jsf.apache.trinidad.tagsupport/metadata/trinidad.xml @@ -703,7 +703,7 @@ </entity> <entity id="contentStyle"> <trait id="attribute-value-runtime-type"> - <value xsi:type="mdt:StringValue">org.eclipse.jst.pagedesigner.attributevalues.CSSStyleType</value> + <value xsi:type="mdt:StringValue">org.eclipse.jst.jsf.core.attributevalues.CSSStyleType</value> </trait> <trait id="category"> <value xsi:type="mdt:StringValue">%property.category.css</value> @@ -775,7 +775,7 @@ </entity> <entity id="contentStyle"> <trait id="attribute-value-runtime-type"> - <value xsi:type="mdt:StringValue">org.eclipse.jst.pagedesigner.attributevalues.CSSStyleType</value> + <value xsi:type="mdt:StringValue">org.eclipse.jst.jsf.core.attributevalues.CSSStyleType</value> </trait> <trait id="category"> <value xsi:type="mdt:StringValue">%property.category.css</value> @@ -816,7 +816,7 @@ </trait> <entity id="contentStyle"> <trait id="attribute-value-runtime-type"> - <value xsi:type="mdt:StringValue">org.eclipse.jst.pagedesigner.attributevalues.CSSStyleType</value> + <value xsi:type="mdt:StringValue">org.eclipse.jst.jsf.core.attributevalues.CSSStyleType</value> </trait> <trait id="category"> <value xsi:type="mdt:StringValue">%property.category.css</value> @@ -891,7 +891,7 @@ </entity> <entity id="contentStyle"> <trait id="attribute-value-runtime-type"> - <value xsi:type="mdt:StringValue">org.eclipse.jst.pagedesigner.attributevalues.CSSStyleType</value> + <value xsi:type="mdt:StringValue">org.eclipse.jst.jsf.core.attributevalues.CSSStyleType</value> </trait> <trait id="category"> <value xsi:type="mdt:StringValue">%property.category.css</value> @@ -947,7 +947,7 @@ </trait> <entity id="contentStyle"> <trait id="attribute-value-runtime-type"> - <value xsi:type="mdt:StringValue">org.eclipse.jst.pagedesigner.attributevalues.CSSStyleType</value> + <value xsi:type="mdt:StringValue">org.eclipse.jst.jsf.core.attributevalues.CSSStyleType</value> </trait> <trait id="category"> <value xsi:type="mdt:StringValue">%property.category.css</value> @@ -1013,7 +1013,7 @@ </trait> <entity id="contentStyle"> <trait id="attribute-value-runtime-type"> - <value xsi:type="mdt:StringValue">org.eclipse.jst.pagedesigner.attributevalues.CSSStyleType</value> + <value xsi:type="mdt:StringValue">org.eclipse.jst.jsf.core.attributevalues.CSSStyleType</value> </trait> <trait id="category"> <value xsi:type="mdt:StringValue">%property.category.css</value> @@ -1361,12 +1361,12 @@ </trait> <entity id="titleClass"> <trait id="attribute-value-runtime-type"> - <value xsi:type="mdt:StringValue">org.eclipse.jst.pagedesigner.attributevalues.CSSStyleType</value> + <value xsi:type="mdt:StringValue">org.eclipse.jst.jsf.core.attributevalues.CSSStyleType</value> </trait> </entity> <entity id="separatorClass"> <trait id="attribute-value-runtime-type"> - <value xsi:type="mdt:StringValue">org.eclipse.jst.pagedesigner.attributevalues.CSSStyleType</value> + <value xsi:type="mdt:StringValue">org.eclipse.jst.jsf.core.attributevalues.CSSStyleType</value> </trait> </entity> </entity> @@ -1594,7 +1594,7 @@ <entity id="icon"/> <entity id="contentStyle"> <trait id="attribute-value-runtime-type"> - <value xsi:type="mdt:StringValue">org.eclipse.jst.pagedesigner.attributevalues.CSSStyleType</value> + <value xsi:type="mdt:StringValue">org.eclipse.jst.jsf.core.attributevalues.CSSStyleType</value> </trait> <trait id="category"> <value xsi:type="mdt:StringValue">%property.category.css</value> @@ -1873,7 +1873,7 @@ <entity id="label"/> <entity id="labelStyle"> <trait id="attribute-value-runtime-type"> - <value xsi:type="mdt:StringValue">org.eclipse.jst.pagedesigner.attributevalues.CSSStyleType</value> + <value xsi:type="mdt:StringValue">org.eclipse.jst.jsf.core.attributevalues.CSSStyleType</value> </trait> </entity> <entity id="accessKey"> @@ -2058,7 +2058,7 @@ </entity> <entity id="contentStyle"> <trait id="attribute-value-runtime-type"> - <value xsi:type="mdt:StringValue">org.eclipse.jst.pagedesigner.attributevalues.CSSStyleType</value> + <value xsi:type="mdt:StringValue">org.eclipse.jst.jsf.core.attributevalues.CSSStyleType</value> </trait> <trait id="category"> <value xsi:type="mdt:StringValue">%property.category.css</value> @@ -3824,7 +3824,7 @@ <entityGroup id="common-trinidad-attributes"> <entity id="inlineStyle"> <trait id="attribute-value-runtime-type"> - <value xsi:type="mdt:StringValue">org.eclipse.jst.pagedesigner.attributevalues.CSSStyleType</value> + <value xsi:type="mdt:StringValue">org.eclipse.jst.jsf.core.attributevalues.CSSStyleType</value> </trait> <trait id="category"> <value xsi:type="mdt:StringValue">%property.category.core</value> @@ -3832,7 +3832,7 @@ </entity> <entity id="styleClass"> <trait id="attribute-value-runtime-type"> - <value xsi:type="mdt:StringValue">org.eclipse.jst.pagedesigner.attributevalues.CSSClassType</value> + <value xsi:type="mdt:StringValue">org.eclipse.jst.jsf.core.attributevalues.CSSClassType</value> </trait> <trait id="category"> <value xsi:type="mdt:StringValue">%property.category.core</value> @@ -4128,7 +4128,7 @@ <entityGroup id="common-select-tag-attributes"> <entity id="contentStyle"> <trait id="attribute-value-runtime-type"> - <value xsi:type="mdt:StringValue">org.eclipse.jst.pagedesigner.attributevalues.CSSStyleType</value> + <value xsi:type="mdt:StringValue">org.eclipse.jst.jsf.core.attributevalues.CSSStyleType</value> </trait> <trait id="category"> <value xsi:type="mdt:StringValue">%property.category.css</value> diff --git a/jsf/plugins/org.eclipse.jst.jsf.apache.trinidad.tagsupport/metadata/trinidad_html.xml b/jsf/plugins/org.eclipse.jst.jsf.apache.trinidad.tagsupport/metadata/trinidad_html.xml index a4e045cf3..63cd8f67e 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.apache.trinidad.tagsupport/metadata/trinidad_html.xml +++ b/jsf/plugins/org.eclipse.jst.jsf.apache.trinidad.tagsupport/metadata/trinidad_html.xml @@ -382,7 +382,7 @@ <entityGroup id="common-trinidadh-attributes"> <entity id="inlineStyle"> <trait id="attribute-value-runtime-type"> - <value xsi:type="mdt:StringValue">org.eclipse.jst.pagedesigner.attributevalues.CSSStyleType</value> + <value xsi:type="mdt:StringValue">org.eclipse.jst.jsf.core.attributevalues.CSSStyleType</value> </trait> <trait id="category"> <value xsi:type="mdt:StringValue">%property.category.core</value> @@ -390,7 +390,7 @@ </entity> <entity id="styleClass"> <trait id="attribute-value-runtime-type"> - <value xsi:type="mdt:StringValue">org.eclipse.jst.pagedesigner.attributevalues.CSSClassType</value> + <value xsi:type="mdt:StringValue">org.eclipse.jst.jsf.core.attributevalues.CSSClassType</value> </trait> <trait id="category"> <value xsi:type="mdt:StringValue">%property.category.core</value> diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/actions/single/ChangeStyleAction.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/actions/single/ChangeStyleAction.java index 272dd4f45..6236e2328 100644 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/actions/single/ChangeStyleAction.java +++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/actions/single/ChangeStyleAction.java @@ -37,14 +37,26 @@ public class ChangeStyleAction extends Action { private IDOMElement _element; + private String _attribute; + /** * @param part * @param ele */ public ChangeStyleAction(ElementEditPart part, IDOMElement ele) { + this(part, ele, "style");//$NON-NLS-1$ + } + + /** + * @param part + * @param ele + * @param styleAttributeName + */ + public ChangeStyleAction(ElementEditPart part, IDOMElement ele, String styleAttributeName) { super(MY_TEXT); this._editPart = part; this._element = ele; + this._attribute = styleAttributeName; } public void run() { @@ -58,7 +70,7 @@ public class ChangeStyleAction extends Action { StyleDialog dialog = new StyleDialog(shell, manager, _element, context); if (dialog.open() == Window.OK) { if (context.isModified()) { - ChangeStyleCommand c = new ChangeStyleCommand(_element, context); + ChangeStyleCommand c = new ChangeStyleCommand(_element, _attribute, context); c.execute(); } } diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/commands/single/ChangeStyleCommand.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/commands/single/ChangeStyleCommand.java index 4a88c341e..f518f4066 100644 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/commands/single/ChangeStyleCommand.java +++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/commands/single/ChangeStyleCommand.java @@ -13,9 +13,9 @@ package org.eclipse.jst.pagedesigner.commands.single; import java.util.Map; -import org.eclipse.jst.jsf.core.internal.tld.IJSFConstants; import org.eclipse.jst.pagedesigner.commands.CommandResources; import org.eclipse.jst.pagedesigner.dom.DOMStyleUtil; +import org.eclipse.jst.pagedesigner.properties.celleditors.CSSStyleDeclarationFactory; import org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration; import org.eclipse.wst.css.core.internal.util.declaration.CSSPropertyContext; import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; @@ -30,6 +30,8 @@ public class ChangeStyleCommand extends SingleNodeCommand { private CSSPropertyContext _context = null; + private String _styleAttrName; + /** * @param node * @param map @@ -38,16 +40,43 @@ public class ChangeStyleCommand extends SingleNodeCommand { super(CommandResources .getString("ChangeStyleCommand.Label.ChangeStyle"), node); //$NON-NLS-1$ _styleProperties = map; + _styleAttrName = "style"; //$NON-NLS-1$ + } + + /** + * @param node + * @param styleAttrName + * @param map + */ + public ChangeStyleCommand(IDOMElement node, String styleAttrName, Map map) { + super(CommandResources + .getString("ChangeStyleCommand.Label.ChangeStyle"), node); //$NON-NLS-1$ + _styleProperties = map; + _styleAttrName = styleAttrName; } /** * @param node * @param context + * @deprecated */ public ChangeStyleCommand(IDOMElement node, CSSPropertyContext context) { super(CommandResources .getString("ChangeStyleCommand.Label.ChangeStyle"), node); //$NON-NLS-1$ _context = context; + _styleAttrName = "style"; //$NON-NLS-1$ + } + + /** + * @param node + * @param styleAttrName + * @param context + */ + public ChangeStyleCommand(IDOMElement node, String styleAttrName, CSSPropertyContext context) { + super(CommandResources + .getString("ChangeStyleCommand.Label.ChangeStyle"), node); //$NON-NLS-1$ + _context = context; + _styleAttrName = styleAttrName; } /* @@ -60,13 +89,12 @@ public class ChangeStyleCommand extends SingleNodeCommand { try { if (_styleProperties != null) { IDOMElement original = this.getOriginalElement(); - DOMStyleUtil.insertStyle(original, _styleProperties); + DOMStyleUtil.insertStyle(original, _styleAttrName, _styleProperties); } else if (_context != null) { - ICSSStyleDeclaration styleDeclaration = (ICSSStyleDeclaration) ((ElementCSSInlineStyle) getOriginalElement()) - .getStyle(); + ICSSStyleDeclaration styleDeclaration = CSSStyleDeclarationFactory.getInstance().getStyleDeclaration(getOriginalElement(), _styleAttrName); if (styleDeclaration == null) { - getOriginalElement().setAttribute(IJSFConstants.ATTR_STYLE, + getOriginalElement().setAttribute(_styleAttrName, ""); //$NON-NLS-1$ styleDeclaration = (ICSSStyleDeclaration) ((ElementCSSInlineStyle) getOriginalElement()) .getStyle(); diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dom/DOMStyleUtil.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dom/DOMStyleUtil.java index 243f3729a..d729bb1a1 100644 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dom/DOMStyleUtil.java +++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dom/DOMStyleUtil.java @@ -27,6 +27,8 @@ import org.w3c.dom.css.ElementCSSInlineStyle; * @version 1.5 */ public final class DOMStyleUtil { + + private static final String STYLE_ATTR = "style"; //$NON-NLS-1$ /** * @param original * @param cssProperty @@ -34,11 +36,22 @@ public final class DOMStyleUtil { */ public static String getInlineStyleProperty(Element original, String cssProperty) { + return getInlineStyleProperty(original, STYLE_ATTR, cssProperty); + } + + /** + * @param original + * @param styleAttributeName + * @param cssProperty + * @return the inline style property + */ + public static String getInlineStyleProperty(Element original, String styleAttributeName, + String cssProperty) { if (original instanceof ElementCSSInlineStyle) { CSSStyleDeclaration styledecl = ((ElementCSSInlineStyle) original) .getStyle(); if (styledecl == null) { - if (original.getAttribute("style") == null) { //$NON-NLS-1$ + if (original.getAttribute(styleAttributeName) == null) { return null; } // else mean it has style attribute. @@ -55,11 +68,11 @@ public final class DOMStyleUtil { // normally should not happen. But anyway, we need to have a fail safe // path. - String oldstyle = original.getAttribute("style"); //$NON-NLS-1$ + String oldstyle = original.getAttribute(styleAttributeName); if (oldstyle == null || oldstyle.length() == 0) { return null; } - StringTokenizer tokenizer = new StringTokenizer(oldstyle, ";"); //$NON-NLS-1$ + StringTokenizer tokenizer = new StringTokenizer(oldstyle, ";"); //$NON-NLS-1$ while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken().trim(); @@ -80,18 +93,29 @@ public final class DOMStyleUtil { } /** - * insert style into element + * insert style into element - style attribute * * @param original * @param map */ public static void insertStyle(Element original, Map map) { + insertStyle(original, STYLE_ATTR, map); + } + + /** + * insert style into element + * + * @param original + * @param styleAttrName + * @param map + */ + public static void insertStyle(Element original, String styleAttrName, Map map) { if (original instanceof ElementCSSInlineStyle) { CSSStyleDeclaration styledecl = ((ElementCSSInlineStyle) original) .getStyle(); if (styledecl == null) { - if (original.getAttribute("style") == null) { //$NON-NLS-1$ - original.setAttribute("style", ""); //$NON-NLS-1$ //$NON-NLS-2$ + if (original.getAttribute(styleAttrName) == null) { + original.setAttribute(styleAttrName, ""); //$NON-NLS-1$ styledecl = ((ElementCSSInlineStyle) original).getStyle(); } } @@ -117,7 +141,7 @@ public final class DOMStyleUtil { // normally should not happen. But anyway, we need to have a fail safe // path. - String oldstyle = original.getAttribute("style"); //$NON-NLS-1$ + String oldstyle = original.getAttribute(styleAttrName); if (oldstyle == null) { oldstyle = ""; //$NON-NLS-1$ } @@ -159,16 +183,15 @@ public final class DOMStyleUtil { buffer.append(key).append(": ").append(value).append("; "); //$NON-NLS-1$ //$NON-NLS-2$ } } - original.setAttribute("style", buffer.toString()); //$NON-NLS-1$ + original.setAttribute(styleAttrName, buffer.toString()); } - /** * @param ele * @return true if supports the style attribute */ public static boolean supportStyleAttribute(IDOMElement ele) { CMElementDeclaration decl = CMUtil.getElementDeclaration(ele); - if (decl != null && decl.getAttributes().getNamedItem("style") != null) { //$NON-NLS-1$ + if (decl != null && decl.getAttributes().getNamedItem(STYLE_ATTR) != null) { return true; } return false; diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/properties/celleditors/AbstractCSSModelAdapter.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/properties/celleditors/AbstractCSSModelAdapter.java new file mode 100644 index 000000000..f5cc96240 --- /dev/null +++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/properties/celleditors/AbstractCSSModelAdapter.java @@ -0,0 +1,103 @@ +package org.eclipse.jst.pagedesigner.properties.celleditors; + +import java.util.Collection; +import java.util.Iterator; + +import org.eclipse.wst.css.core.internal.document.CSSModelImpl; +import org.eclipse.wst.css.core.internal.provisional.adapters.ICSSModelAdapter; +import org.eclipse.wst.css.core.internal.provisional.contenttype.ContentTypeIdForCSS; +import org.eclipse.wst.css.core.internal.provisional.document.ICSSModel; +import org.eclipse.wst.html.core.internal.htmlcss.StyleListener; +import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter; +import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; +import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; +import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; +import org.w3c.dom.Element; + +/** + * A slightly modified copy of {@link org.eclipse.wst.html.core.internal.htmlcss.AbstractCSSModelAdapter}. + */ +public abstract class AbstractCSSModelAdapter implements ICSSModelAdapter { + private final static String CSS_ID = ContentTypeIdForCSS.ContentTypeID_CSS; + + private Element element = null; + private ICSSModel model = null; + + /** + */ + AbstractCSSModelAdapter() { + super(); + } + /** + * @return ICSSModel + */ + protected ICSSModel createModel() { + // create embedded CSS model (not for external CSS) + if (getElement() == null) + return null; + IStructuredModel baseModel = ((IDOMNode) getElement()).getModel(); + ICSSModel newModel = (ICSSModel) baseModel.getModelManager().createUnManagedStructuredModelFor(CSS_ID); + ((CSSModelImpl) newModel).setOwnerDOMNode(getElement()); + return newModel; + } + + /** + * @return Element + */ + public Element getElement() { + return this.element; + } + + /** + * @return ICSSModel + */ + protected ICSSModel getExistingModel() { + return this.model; + } + + /** + * @param target element + * + */ + protected void notifyStyleChanged(Element target) { + INodeNotifier notifier = (INodeNotifier) target; + if (notifier == null) + return; + Collection adapters = notifier.getAdapters(); + if (adapters == null) + return; + Iterator it = adapters.iterator(); + if (it == null) + return; + while (it.hasNext()) { + INodeAdapter adapter = (INodeAdapter) it.next(); + if (adapter instanceof StyleListener) { + StyleListener listener = (StyleListener) adapter; + listener.styleChanged(); + } + } + } + + /** + */ + void setElement(Element element) { + this.element = element; + } + + /** + * check + * 1. If attributes of element is valid (type,rel ...) + * 2. If content model supports this element / attribute (future ?) + * @return validness flag + */ + protected boolean isValidAttribute() { + return (getElement() != null);//metadata has already established that this is a style attribute + } + + /** + * @param model + */ + protected void setModel(ICSSModel model) { + this.model = model; + } +} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/properties/celleditors/CSSDialogCellEditor.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/properties/celleditors/CSSDialogCellEditor.java index b43bcc339..6165de394 100644 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/properties/celleditors/CSSDialogCellEditor.java +++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/properties/celleditors/CSSDialogCellEditor.java @@ -13,8 +13,8 @@ package org.eclipse.jst.pagedesigner.properties.celleditors; import org.eclipse.jface.preference.PreferenceManager; import org.eclipse.jface.window.Window; -import org.eclipse.jst.jsf.core.internal.tld.IJSFConstants; import org.eclipse.jst.pagedesigner.commands.single.ChangeStyleCommand; +import org.eclipse.jst.pagedesigner.editors.properties.IPropertyPageDescriptor; import org.eclipse.jst.pagedesigner.ui.dialogs.StyleDialog; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; @@ -23,7 +23,6 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration; import org.eclipse.wst.css.core.internal.util.declaration.CSSPropertyContext; import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; -import org.w3c.dom.css.ElementCSSInlineStyle; /** * A css dialog cell editor @@ -31,14 +30,17 @@ import org.w3c.dom.css.ElementCSSInlineStyle; */ public class CSSDialogCellEditor extends EditableDialogCellEditor { private IDOMElement _element; + private IPropertyPageDescriptor _attr; /** * @param parent + * @param attr * @param element */ - public CSSDialogCellEditor(Composite parent, IDOMElement element) { + public CSSDialogCellEditor(Composite parent, IPropertyPageDescriptor attr, IDOMElement element) { super(parent); _element = element; + _attr = attr; } /* @@ -47,14 +49,14 @@ public class CSSDialogCellEditor extends EditableDialogCellEditor { * @see org.eclipse.jface.viewers.DialogCellEditor#openDialogBox(org.eclipse.swt.widgets.Control) */ protected Object openDialogBox(Control cellEditorWindow) { - ICSSStyleDeclaration styleDeclaration = (ICSSStyleDeclaration) ((ElementCSSInlineStyle) _element) - .getStyle(); - - PreferenceManager manager = new PreferenceManager(); - Shell shell = cellEditorWindow.getShell(); + final ICSSStyleDeclaration styleDeclaration = CSSStyleDeclarationFactory.getInstance(). + getStyleDeclaration(_element, _attr.getAttributeName()); + + final PreferenceManager manager = new PreferenceManager(); + final Shell shell = cellEditorWindow.getShell(); final CSSPropertyContext context = new CSSPropertyContext(styleDeclaration); - StyleDialog dialog = new StyleDialog(shell, manager, _element, context); + final StyleDialog dialog = new StyleDialog(shell, manager, _element, context); if (dialog.open() == Window.OK) { if (context.isModified()) { PlatformUI.getWorkbench().getDisplay().asyncExec( @@ -62,7 +64,7 @@ public class CSSDialogCellEditor extends EditableDialogCellEditor { { public void run() { - ChangeStyleCommand c = new ChangeStyleCommand(_element, context); + final ChangeStyleCommand c = new ChangeStyleCommand(_element, _attr.getAttributeName(), context); c.execute(); } }); @@ -70,7 +72,7 @@ public class CSSDialogCellEditor extends EditableDialogCellEditor { } String style = (_element == null ? null : _element - .getAttribute(IJSFConstants.ATTR_STYLE)); + .getAttribute(_attr.getAttributeName())); return style == null ? "" : style; //$NON-NLS-1$ } } diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/properties/celleditors/CSSStyleDeclarationFactory.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/properties/celleditors/CSSStyleDeclarationFactory.java new file mode 100644 index 000000000..f9b864358 --- /dev/null +++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/properties/celleditors/CSSStyleDeclarationFactory.java @@ -0,0 +1,46 @@ +package org.eclipse.jst.pagedesigner.properties.celleditors; + +import org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration; +import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; +import org.w3c.dom.Node; + +/** + * Creates {@link ICSSStyleDeclaration} adapters for tags where the attribute of interest is not necessarily named "style". + * This is to be used in conjunction with the inline CSS Style Dialog only where metadata has already + * established that the tag attribute is styleable. + */ +public class CSSStyleDeclarationFactory { + + private static CSSStyleDeclarationFactory instance = null; + /** + */ + private CSSStyleDeclarationFactory() { + super(); + } + + /** + * @param element - must not be null + * @param attrName - must not be null + * @return ICSSStyleDeclaration + * + */ + public ICSSStyleDeclaration getStyleDeclaration(final IDOMElement element, final String attrName) { + if ( element.getNodeType() != Node.ELEMENT_NODE) + return null; + + final TagStyleAttrAdapter newAdapter = new TagStyleAttrAdapter(attrName); + newAdapter.setElement(element); + return (ICSSStyleDeclaration)newAdapter.getStyle(); + } + + /** + * @return CSSStyleDeclarationAdapterFactory singleton + */ + public synchronized static CSSStyleDeclarationFactory getInstance() { + if (instance == null) + instance = new CSSStyleDeclarationFactory(); + return instance; + } + + +} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/properties/celleditors/CellEditorFactory.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/properties/celleditors/CellEditorFactory.java index de79670a5..65e9fb591 100644 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/properties/celleditors/CellEditorFactory.java +++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/properties/celleditors/CellEditorFactory.java @@ -42,6 +42,7 @@ import org.w3c.dom.Element; * * @author mengbo */ +@SuppressWarnings("deprecation") public class CellEditorFactory implements ITagAttributeCellEditorFactory { public CellEditor createCellEditor(Composite parent, IPropertyPageDescriptor attr, Element element) { @@ -101,7 +102,7 @@ public class CellEditorFactory implements ITagAttributeCellEditorFactory { // if (!param.equalsIgnoreCase("STYLE")) { // return null; // } - CSSDialogCellEditor cellEditor = new CSSDialogCellEditor(parent, + CSSDialogCellEditor cellEditor = new CSSDialogCellEditor(parent, attr, (IDOMElement) element); ed = cellEditor; } @@ -143,7 +144,7 @@ public class CellEditorFactory implements ITagAttributeCellEditorFactory { * * @see org.eclipse.jst.pagedesigner.meta.NEWMDIAttributeCellEditorFactory#createDialogField(org.eclipse.jst.pagedesigner.meta.IAttributeDescriptor, * org.w3c.dom.Element, org.w3c.dom.Element) - */ + */ public DialogField createDialogField(IPropertyPageDescriptor attr) { String type = attr.getValueType(); diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/properties/celleditors/TagStyleAttrAdapter.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/properties/celleditors/TagStyleAttrAdapter.java new file mode 100644 index 000000000..818be8333 --- /dev/null +++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/properties/celleditors/TagStyleAttrAdapter.java @@ -0,0 +1,242 @@ +package org.eclipse.jst.pagedesigner.properties.celleditors; + +import org.eclipse.wst.css.core.internal.parser.CSSSourceParser; +import org.eclipse.wst.css.core.internal.provisional.adapters.IStyleDeclarationAdapter; +import org.eclipse.wst.css.core.internal.provisional.document.ICSSModel; +import org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser; +import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; +import org.eclipse.wst.sse.core.internal.provisional.events.IStructuredDocumentListener; +import org.eclipse.wst.sse.core.internal.provisional.events.NewDocumentEvent; +import org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent; +import org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent; +import org.eclipse.wst.sse.core.internal.provisional.events.RegionsReplacedEvent; +import org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentRegionsReplacedEvent; +import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; +import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; +import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList; +import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.css.CSSStyleDeclaration; + +/** + * CSS style adapter for tags where the attribute name is not "style" + * <p> + * Basically a copy of StyleAttrAdapter with a few mods + */ +@SuppressWarnings("deprecation") +public class TagStyleAttrAdapter extends AbstractCSSModelAdapter implements IStructuredDocumentListener, IStyleDeclarationAdapter { + + private boolean ignoreNotification = false; + private String _styleAttrName; + + /** + * @param attrName + */ + TagStyleAttrAdapter(final String attrName) { + super(); + _styleAttrName = attrName; + } + + /** + */ + public ICSSModel getModel() { + ICSSModel model = getExistingModel(); + if (model == null && isModelNecessary()) { + model = createModel(); + if (model == null) + return null; + + IStructuredDocument structuredDocument = model.getStructuredDocument(); + if (structuredDocument == null) + return null; + + RegionParser parser = structuredDocument.getParser(); + if (parser instanceof CSSSourceParser) { + ((CSSSourceParser)parser).setParserMode(CSSSourceParser.MODE_DECLARATION); + } else { + return null; + } + + structuredDocument.addDocumentChangedListener(this); + + setModel(model); // need to set before valueChanged() + valueChanged(); + } + if (model != null && !isModelNecessary()) { + model = null; + valueChanged(); + } + return model; + } + + /** + */ + public CSSStyleDeclaration getStyle() { + ICSSModel model = getModel(); + if (model == null) + return null; + return (CSSStyleDeclaration) model.getDocument(); + } + + /** + * 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 == IStyleDeclarationAdapter.class); + } + + /** + */ + public void newModel(NewDocumentEvent event) { + if (event == null) + return; + if (event.getOriginalRequester() == this) + return; + + setValue(); + } + + /** + */ + public void noChange(NoChangeEvent structuredDocumentEvent) {// + } + + /** + */ + public void nodesReplaced(StructuredDocumentRegionsReplacedEvent event) { + if (event == null) + return; + if (event.getOriginalRequester() == this) + return; + + setValue(); + } + + /** + */ + public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) { + if (this.ignoreNotification) + return; + + if (eventType != INodeNotifier.CHANGE) + return; + Attr attr = (Attr) changedFeature; + if (attr == null) + return; + String name = attr.getName(); + if (name.equalsIgnoreCase(_styleAttrName)) { + valueChanged(); + } + } + + /** + */ + public void regionChanged(RegionChangedEvent event) { + if (event == null) + return; + if (event.getOriginalRequester() == this) + return; + + setValue(); + } + + /** + */ + public void regionsReplaced(RegionsReplacedEvent event) { + if (event == null) + return; + if (event.getOriginalRequester() == this) + return; + + setValue(); + } + + /** + */ + private void setValue() { + Element element = getElement(); + if (element == null) + return; + ICSSModel model = getExistingModel(); + if (model == null) + return; + IStructuredDocument structuredDocument = model.getStructuredDocument(); + if (structuredDocument == null) + return; + + String value = null; + IStructuredDocumentRegionList flatNodes = structuredDocument.getRegionList(); + if (flatNodes != null) { + int count = flatNodes.getLength(); + if (count > 0) { + StringBuffer buffer = new StringBuffer(); + for (int i = 0; i < count; i++) { + IStructuredDocumentRegion flatNode = flatNodes.item(i); + if (flatNode == null) + continue; + buffer.append(flatNode.getText()); + } + value = buffer.toString(); + } + } + + this.ignoreNotification = true; + if (value == null || value.length() == 0) { + element.removeAttribute(_styleAttrName); + } + else { + Attr attr = element.getAttributeNode(_styleAttrName); + if (attr != null) { + ((IDOMNode) attr).setValueSource(value); + } + else { + Document document = element.getOwnerDocument(); + attr = document.createAttribute(_styleAttrName); + ((IDOMNode) attr).setValueSource(value); + element.setAttributeNode(attr); + } + } + this.ignoreNotification = false; + + notifyStyleChanged(element); + } + + /** + */ + private void valueChanged() { + Element element = getElement(); + if (element == null) + return; + if (!isModelNecessary()) { // removed + setModel(null); + + notifyStyleChanged(element); + return; + } + + ICSSModel model = getExistingModel(); + if (model == null) + return; // defer + IStructuredDocument structuredDocument = model.getStructuredDocument(); + if (structuredDocument == null) + return; // error + + String value = null; + Attr attr = element.getAttributeNode(_styleAttrName); + if (attr != null) + value = ((IDOMNode) attr).getValueSource(); + structuredDocument.setText(this, value); + + notifyStyleChanged(element); + } + + /** + * @return boolean + */ + private boolean isModelNecessary() { + return getElement() != null; + } +} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/ui/dialogfields/StyleButtonDialogField.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/ui/dialogfields/StyleButtonDialogField.java index 0e05a5362..f2f3f003b 100644 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/ui/dialogfields/StyleButtonDialogField.java +++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/ui/dialogfields/StyleButtonDialogField.java @@ -31,6 +31,7 @@ import org.w3c.dom.css.ElementCSSInlineStyle; /** * @author mengbo + * @deprecated */ public class StyleButtonDialogField extends StringButtonDialogField implements IElementContextable { |