[jbosstools-commits] JBoss Tools SVN: r17494 - in trunk/jst/plugins/org.jboss.tools.jst.css: META-INF and 4 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Wed Sep 9 12:09:15 EDT 2009


Author: sdzmitrovich
Date: 2009-09-09 12:09:14 -0400 (Wed, 09 Sep 2009)
New Revision: 17494

Added:
   trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/
   trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSSelectionListener.java
   trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSStyleManager.java
   trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSStyleRuleContainer.java
   trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/StyleAttribyteContainer.java
   trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/StyleContainer.java
Removed:
   trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/view/CSSViewUtil.java
Modified:
   trunk/jst/plugins/org.jboss.tools.jst.css/META-INF/MANIFEST.MF
   trunk/jst/plugins/org.jboss.tools.jst.css/plugin.xml
   trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/CssPlugin.java
   trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/properties/CSSPropertyPage.java
   trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/view/CSSEditorView.java
   trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/view/CSSPreview.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4850

Modified: trunk/jst/plugins/org.jboss.tools.jst.css/META-INF/MANIFEST.MF
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.css/META-INF/MANIFEST.MF	2009-09-09 16:01:21 UTC (rev 17493)
+++ trunk/jst/plugins/org.jboss.tools.jst.css/META-INF/MANIFEST.MF	2009-09-09 16:09:14 UTC (rev 17494)
@@ -12,7 +12,10 @@
  org.eclipse.core.databinding,
  org.eclipse.wst.css.core,
  org.eclipse.jdt.ui,
- org.eclipse.debug.ui
+ org.eclipse.debug.ui,
+ org.eclipse.wst.sse.core,
+ org.eclipse.jface.text,
+ org.eclipse.wst.xml.core
 Bundle-RequiredExecutionEnvironment: J2SE-1.5
 Bundle-ActivationPolicy: lazy
 Export-Package: org.jboss.tools.jst.css,

Modified: trunk/jst/plugins/org.jboss.tools.jst.css/plugin.xml
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.css/plugin.xml	2009-09-09 16:01:21 UTC (rev 17493)
+++ trunk/jst/plugins/org.jboss.tools.jst.css/plugin.xml	2009-09-09 16:09:14 UTC (rev 17494)
@@ -3,7 +3,7 @@
 <plugin>
 	<extension point="org.eclipse.ui.views.properties.tabbed.propertyContributor">
 		<propertyContributor contributorId="org.eclipse.wst.css.core.csssource.source"
-			typeMapper="org.jboss.tools.jst.css.properties.TypeMapper">
+			>
 			<propertyCategory category="general">
 			</propertyCategory>
 		</propertyContributor>
@@ -35,58 +35,58 @@
 			<propertySection class="org.jboss.tools.jst.css.properties.TextSection"
 				id="org.jboss.tools.jst.css.textFontTab" tab="org.jboss.tools.jst.css.textFontTab">
 				<input
-					type="org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule">
+					type="org.jboss.tools.jst.css.common.StyleContainer">
 				</input>
 			</propertySection>
 			<propertySection
 				class="org.jboss.tools.jst.css.properties.BackgroundSection" id="org.jboss.tools.jst.css.backgroundTab"
 				tab="org.jboss.tools.jst.css.backgroundTab" >
 				<input 
-					type="org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule">
+					type="org.jboss.tools.jst.css.common.StyleContainer">
 				</input>
 			</propertySection>
 			<propertySection class="org.jboss.tools.jst.css.properties.BoxesSection"
 				id="org.jboss.tools.jst.css.boxesTab" tab="org.jboss.tools.jst.css.boxesTab">
 				<input
-					type="org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule">
+					type="org.jboss.tools.jst.css.common.StyleContainer">
 				</input>
 			</propertySection>
 			<propertySection
 				class="org.jboss.tools.jst.css.properties.PropertiesSection" id="org.jboss.tools.jst.css.propertyTab"
 				tab="org.jboss.tools.jst.css.propertyTab">
 				<input
-					type="org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule">
+					type="org.jboss.tools.jst.css.common.StyleContainer">
 				</input>
 			</propertySection>
 			<propertySection
 				class="org.jboss.tools.jst.css.properties.QuickEditSection" id="org.jboss.tools.jst.css.quickEditTab"
 				tab="org.jboss.tools.jst.css.quickEditTab">
 				<input
-					type="org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule">
+					type="org.jboss.tools.jst.css.common.StyleContainer">
 				</input>
 			</propertySection>
 			<propertySection class="org.jboss.tools.jst.css.properties.MessageCSSSection"
 				id="org.jboss.tools.jst.css.messageSection" tab="org.jboss.tools.jst.css.textFontTab">
 				<input
-					type="org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule">
+					type="org.jboss.tools.jst.css.common.StyleContainer">
 				</input>
 			</propertySection>
 			<propertySection class="org.jboss.tools.jst.css.properties.MessageCSSSection"
 				id="org.jboss.tools.jst.css.messageSection" tab="org.jboss.tools.jst.css.backgroundTab">
 				<input
-					type="org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule">
+					type="org.jboss.tools.jst.css.common.StyleContainer">
 				</input>
 			</propertySection>
 			<propertySection class="org.jboss.tools.jst.css.properties.MessageCSSSection"
 				id="org.jboss.tools.jst.css.messageSection" tab="org.jboss.tools.jst.css.boxesTab">
 				<input
-					type="org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule">
+					type="org.jboss.tools.jst.css.common.StyleContainer">
 				</input>
 			</propertySection>
 			<propertySection class="org.jboss.tools.jst.css.properties.MessageCSSSection"
 				id="org.jboss.tools.jst.css.messageSection" tab="org.jboss.tools.jst.css.quickEditTab">
 				<input
-					type="org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule">
+					type="org.jboss.tools.jst.css.common.StyleContainer">
 				</input>
 			</propertySection>
 		</propertySections>

Modified: trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/CssPlugin.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/CssPlugin.java	2009-09-09 16:01:21 UTC (rev 17493)
+++ trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/CssPlugin.java	2009-09-09 16:09:14 UTC (rev 17494)
@@ -11,6 +11,8 @@
 
 package org.jboss.tools.jst.css;
 
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
 import org.osgi.framework.BundleContext;
@@ -25,7 +27,7 @@
 
 	// The shared instance
 	private static CssPlugin plugin;
-	
+
 	/**
 	 * The constructor
 	 */
@@ -34,7 +36,10 @@
 
 	/*
 	 * (non-Javadoc)
-	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+	 * 
+	 * @see
+	 * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
+	 * )
 	 */
 	public void start(BundleContext context) throws Exception {
 		super.start(context);
@@ -43,7 +48,10 @@
 
 	/*
 	 * (non-Javadoc)
-	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+	 * 
+	 * @see
+	 * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
+	 * )
 	 */
 	public void stop(BundleContext context) throws Exception {
 		plugin = null;
@@ -52,7 +60,7 @@
 
 	/**
 	 * Returns the shared instance
-	 *
+	 * 
 	 * @return the shared instance
 	 */
 	public static CssPlugin getDefault() {
@@ -60,13 +68,22 @@
 	}
 
 	/**
-	 * Returns an image descriptor for the image file at the given
-	 * plug-in relative path
-	 *
-	 * @param path the path
+	 * Returns an image descriptor for the image file at the given plug-in
+	 * relative path
+	 * 
+	 * @param path
+	 *            the path
 	 * @return the image descriptor
 	 */
 	public static ImageDescriptor getImageDescriptor(String path) {
 		return imageDescriptorFromPlugin(PLUGIN_ID, path);
 	}
+
+	/**
+	 * 
+	 * @param message
+	 */
+	public static void log(String message) {
+		getDefault().getLog().log(new Status(IStatus.ERROR, message, null));
+	}
 }

Added: trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSSelectionListener.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSSelectionListener.java	                        (rev 0)
+++ trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSSelectionListener.java	2009-09-09 16:09:14 UTC (rev 17494)
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ *     Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.jst.css.common;
+
+import org.eclipse.core.runtime.ListenerList;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.ui.INullSelectionListener;
+import org.eclipse.ui.ISelectionListener;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+import org.jboss.tools.jst.css.CssPlugin;
+
+public class CSSSelectionListener implements ISelectionListener {
+
+	private static CSSSelectionListener instance;
+
+	private ListenerList listeners = new ListenerList();
+
+	CSSStyleManager styleManager = new CSSStyleManager();
+
+	private CSSSelectionListener() {
+	}
+
+	public synchronized static CSSSelectionListener getInstance() {
+
+		if (instance == null) {
+			instance = new CSSSelectionListener();
+		}
+		return instance;
+	}
+
+	public void addSelectionListener(ISelectionListener listener) {
+
+		// if added the first listener start listing
+		if (listeners.size() == 0)
+			startListening();
+
+		listeners.add(listener);
+	}
+
+	public void removeSelectionListener(ISelectionListener listener) {
+		listeners.remove(listener);
+
+		// if removed last listener start listing
+		if (listeners.size() == 0)
+			stopListening();
+	}
+
+	private void startListening() {
+		PlatformUI.getWorkbench().getActiveWorkbenchWindow()
+				.getSelectionService().addPostSelectionListener(this);
+
+	}
+
+	private void stopListening() {
+		PlatformUI.getWorkbench().getActiveWorkbenchWindow()
+				.getSelectionService().removePostSelectionListener(this);
+
+	}
+
+	public void selectionChanged(IWorkbenchPart part, ISelection selection) {
+
+		StyleContainer styleContainer = styleManager
+				.recognizeCSSStyle(selection);
+
+		ISelection selectionToLiteners = null;
+
+		if (styleContainer != null) {
+			selectionToLiteners = new StructuredSelection(styleContainer);
+		} else {
+			selectionToLiteners = StructuredSelection.EMPTY;
+		}
+
+		Object[] array = listeners.getListeners();
+		for (int i = 0; i < array.length; i++) {
+			final ISelectionListener l = (ISelectionListener) array[i];
+			if ((part != null && selection != null)
+					|| l instanceof INullSelectionListener) {
+
+				try {
+					l.selectionChanged(part, selectionToLiteners);
+				} catch (Exception e) {
+					CssPlugin.log(e.getLocalizedMessage());
+				}
+			}
+
+		}
+
+	}
+}


Property changes on: trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSSelectionListener.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Added: trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSStyleManager.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSStyleManager.java	                        (rev 0)
+++ trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSStyleManager.java	2009-09-09 16:09:14 UTC (rev 17494)
@@ -0,0 +1,218 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ *     Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.css.common;
+
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetAdapter;
+import org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument;
+import org.eclipse.wst.css.core.internal.provisional.document.ICSSModel;
+import org.eclipse.wst.css.core.internal.provisional.document.ICSSNode;
+import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
+import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap;
+import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
+import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.Text;
+import org.w3c.dom.css.CSSStyleRule;
+import org.w3c.dom.css.CSSStyleSheet;
+import org.w3c.dom.css.ElementCSSInlineStyle;
+
+/**
+ * @author Sergey Dzmitrovich
+ * 
+ */
+public class CSSStyleManager {
+
+	public static final String STYLE_TAG_NAME = "style"; //$NON-NLS-1$
+
+	public static final String STYLE_ATTRIBUTE_NAME = "style"; //$NON-NLS-1$
+
+	/**
+	 * 
+	 * @param selection
+	 * @return
+	 */
+	public StyleContainer recognizeCSSStyle(ISelection selection) {
+
+		StyleContainer container = null;
+		if (selection instanceof IStructuredSelection) {
+
+			Object selectedObject = ((IStructuredSelection) selection)
+					.getFirstElement();
+
+			// if selected object is node in css file
+			if (selectedObject instanceof ICSSNode) {
+
+				CSSStyleRule styleRule = getStyleRule((ICSSNode) selectedObject);
+
+				if (styleRule != null)
+					container = new CSSStyleRuleContainer(styleRule);
+
+			} else if ((selectedObject instanceof IDOMElement)
+					|| (selectedObject instanceof IDOMAttr)) {
+
+				Element selectedElement = null;
+
+				if (selectedObject instanceof Attr)
+					selectedElement = ((Attr) selectedObject).getOwnerElement();
+				else
+					selectedElement = (Element) selectedObject;
+
+				if (isSuitableElement(selectedElement)) {
+
+					container = new StyleAttribyteContainer(selectedElement);
+
+				}
+			} else if (selectedObject instanceof Text) {
+
+				Text styleText = (Text) selectedObject;
+
+				Node parentNode = styleText.getParentNode();
+
+				if ((parentNode != null)
+						&& STYLE_TAG_NAME.equalsIgnoreCase(parentNode
+								.getNodeName())) {
+
+					int offset = getRelationalOffset(styleText,
+							((ITextSelection) selection).getOffset());
+
+					CSSStyleSheet sheet = getSheet(parentNode);
+
+					ICSSNode node = getNode(sheet, offset);
+
+					CSSStyleRule styleRule = getStyleRule(node);
+
+					if (styleRule != null) {
+						container = new CSSStyleRuleContainer(styleRule);
+					}
+				}
+			}
+		}
+		return container;
+	}
+
+	/**
+	 * 
+	 * @param styleContainer
+	 * @return
+	 */
+	private CSSStyleSheet getSheet(Node styleContainer) {
+
+		if (styleContainer instanceof INodeNotifier) {
+
+			INodeNotifier notifier = (INodeNotifier) styleContainer;
+
+			IStyleSheetAdapter adapter = (IStyleSheetAdapter) notifier
+					.getAdapterFor(IStyleSheetAdapter.class);
+
+			if (adapter != null) {
+
+				return (CSSStyleSheet) adapter.getSheet();
+			}
+
+		}
+		return null;
+	}
+
+	/**
+	 * 
+	 * @param sheet
+	 * @param offset
+	 * @return
+	 */
+	private ICSSNode getNode(CSSStyleSheet sheet, int offset) {
+
+		ICSSModel model = ((ICSSDocument) sheet).getModel();
+
+		if (model != null)
+
+			return (ICSSNode) model.getIndexedRegion(offset);
+
+		return null;
+
+	}
+
+	/**
+	 * 
+	 * @param element
+	 * @return
+	 */
+	private boolean isSuitableElement(Element element) {
+
+		if (element instanceof ElementCSSInlineStyle
+				&& isAttributeAvailable(element, STYLE_TAG_NAME)) {
+			return true;
+		}
+
+		return false;
+	}
+
+	/**
+	 * 
+	 * @param node
+	 * @return
+	 */
+	private CSSStyleRule getStyleRule(ICSSNode node) {
+
+		while (node != null) {
+
+			if (node instanceof CSSStyleRule)
+				return (CSSStyleRule) node;
+
+			node = node.getParentNode();
+		}
+
+		return null;
+	}
+
+	/**
+	 * 
+	 * @param selection
+	 * @param styleText
+	 * @return
+	 */
+	private int getRelationalOffset(Node basicNode, int absoluteOffset) {
+
+		return absoluteOffset - ((IndexedRegion) basicNode).getStartOffset();
+	}
+
+	
+	/**
+	 * @param element
+	 * @param attrName
+	 * @return
+	 */
+	private static boolean isAttributeAvailable(Element element, String attrName) {
+		ModelQuery modelQuery = ModelQueryUtil.getModelQuery(element
+				.getOwnerDocument());
+		if (modelQuery != null) {
+			CMElementDeclaration decl = modelQuery
+					.getCMElementDeclaration(element);
+			if (decl != null) {
+				CMNamedNodeMap map = decl.getAttributes();
+				if ((CMAttributeDeclaration) map.getNamedItem(attrName) != null) {
+					return true;
+				}
+			}
+		}
+
+		return false;
+	}
+}


Property changes on: trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSStyleManager.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Added: trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSStyleRuleContainer.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSStyleRuleContainer.java	                        (rev 0)
+++ trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSStyleRuleContainer.java	2009-09-09 16:09:14 UTC (rev 17494)
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ *     Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.css.common;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.Constants;
+import org.w3c.dom.css.CSSStyleDeclaration;
+import org.w3c.dom.css.CSSStyleRule;
+
+/**
+ * @author Sergey Dzmitrovich
+ * 
+ */
+public class CSSStyleRuleContainer extends StyleContainer {
+
+	private CSSStyleRule styleRule;
+
+	public CSSStyleRuleContainer(CSSStyleRule styleRule) {
+		this.styleRule = styleRule;
+	}
+
+	public void applyStyleAttributes(Map<String, String> attributes) {
+
+		final CSSStyleDeclaration declaration = styleRule.getStyle();
+
+		// set properties
+
+		if (attributes != null) {
+
+			if ((attributes.size() == 0) && (declaration.getLength() > 0)) {
+				declaration.setCssText(Constants.EMPTY);
+			} else {
+				for (final Map.Entry<String, String> me : attributes.entrySet()) {
+					if ((me.getValue() == null)
+							|| (me.getValue().length() == 0)) {
+						declaration.removeProperty(me.getKey());
+					} else {
+						declaration.setProperty(me.getKey(), me.getValue(),
+								Constants.EMPTY);
+					}
+				}
+
+			}
+		}
+
+	}
+
+	public Map<String, String> getStyleAttributes() {
+		CSSStyleDeclaration declaration = styleRule.getStyle();
+		Map<String, String> styleMap = new HashMap<String, String>();
+		for (int i = 0; i < declaration.getLength(); i++) {
+			String propperty = declaration.item(i);
+			String value = declaration.getPropertyValue(propperty);
+			styleMap.put(propperty, value);
+		}
+
+		return styleMap;
+	}
+
+	public Object getStyleObject() {
+		return styleRule;
+	}
+
+}


Property changes on: trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSStyleRuleContainer.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Added: trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/StyleAttribyteContainer.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/StyleAttribyteContainer.java	                        (rev 0)
+++ trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/StyleAttribyteContainer.java	2009-09-09 16:09:14 UTC (rev 17494)
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ *     Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.css.common;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.CSSConstants;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.Constants;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.Util;
+import org.w3c.dom.Element;
+
+/**
+ * @author Sergey Dzmitrovich
+ * 
+ */
+public class StyleAttribyteContainer extends StyleContainer {
+
+	public static final String STYLE_ATTRIBUTE_NAME = "style"; //$NON-NLS-1$
+
+	private Element element;
+
+	public StyleAttribyteContainer(Element element) {
+		this.element = element;
+	}
+
+	public void applyStyleAttributes(Map<String, String> attributes) {
+
+		StringBuffer buf = new StringBuffer();
+		for (Map.Entry<String, String> me : attributes.entrySet()) {
+
+			if ((me.getValue() != null) && (me.getValue().length() != 0))
+				buf.append(me.getKey() + Constants.COLON + me.getValue()
+						+ Constants.SEMICOLON);
+		}
+
+		element.setAttribute(STYLE_ATTRIBUTE_NAME, buf.toString());
+
+	}
+
+	public Map<String, String> getStyleAttributes() {
+
+		String styleString = element.getAttribute(STYLE_ATTRIBUTE_NAME);
+
+		Map<String, String> styleMap = new HashMap<String, String>();
+
+		if ((styleString != null) && (styleString.length() > 0)) {
+
+			String[] styles = styleString.split(Constants.SEMICOLON);
+			for (String styleElement : styles) {
+				String[] styleElementParts = styleElement.trim().split(
+						Constants.COLON);
+				if ((styleElementParts != null)
+						&& (styleElementParts.length == 2)
+						&& Util.searchInElement(styleElementParts[0],
+								CSSConstants.CSS_STYLES_MAP)) {
+
+					styleMap.put(styleElementParts[0], styleElementParts[1]);
+				}
+			}
+
+		}
+
+		return styleMap;
+	}
+
+	public Object getStyleObject() {
+		return element;
+	}
+
+}


Property changes on: trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/StyleAttribyteContainer.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Added: trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/StyleContainer.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/StyleContainer.java	                        (rev 0)
+++ trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/StyleContainer.java	2009-09-09 16:09:14 UTC (rev 17494)
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ *     Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.css.common;
+
+import java.util.Map;
+
+/**
+ * @author Sergey Dzmitrovich
+ * 
+ */
+public abstract class StyleContainer {
+
+	public abstract Map<String, String> getStyleAttributes();
+
+	public abstract void applyStyleAttributes(Map<String, String> attributes);
+
+	public abstract Object getStyleObject();
+
+	public boolean equals(Object obj) {
+		if (obj instanceof StyleContainer)
+			obj = ((StyleContainer) obj).getStyleObject();
+		return getStyleObject().equals(obj);
+	}
+
+}


Property changes on: trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/StyleContainer.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Modified: trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/properties/CSSPropertyPage.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/properties/CSSPropertyPage.java	2009-09-09 16:01:21 UTC (rev 17493)
+++ trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/properties/CSSPropertyPage.java	2009-09-09 16:09:14 UTC (rev 17494)
@@ -12,8 +12,6 @@
 package org.jboss.tools.jst.css.properties;
 
 import java.util.Map;
-import java.util.Set;
-import java.util.Map.Entry;
 
 import org.eclipse.core.databinding.DataBindingContext;
 import org.eclipse.core.databinding.observable.ChangeEvent;
@@ -29,13 +27,10 @@
 import org.eclipse.ui.part.IPageSite;
 import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor;
 import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
-import org.eclipse.wst.css.core.internal.provisional.document.ICSSNode;
+import org.jboss.tools.jst.css.common.CSSSelectionListener;
+import org.jboss.tools.jst.css.common.StyleContainer;
 import org.jboss.tools.jst.css.view.CSSEditorView;
-import org.jboss.tools.jst.css.view.CSSViewUtil;
-import org.jboss.tools.jst.jsp.outline.cssdialog.common.Constants;
 import org.jboss.tools.jst.jsp.outline.cssdialog.common.StyleAttributes;
-import org.w3c.dom.css.CSSStyleDeclaration;
-import org.w3c.dom.css.CSSStyleRule;
 
 /**
  * @author Sergey Dzmitrovich
@@ -67,9 +62,9 @@
 	@Override
 	public void init(IPageSite pageSite) {
 		super.init(pageSite);
-		pageSite.getWorkbenchWindow().getSelectionService()
-				.addPostSelectionListener(this);
 
+		CSSSelectionListener.getInstance().addSelectionListener(this);
+
 		// FIXED FOR JBIDE-4791
 		pageSite.setSelectionProvider(new ISelectionProvider() {
 
@@ -81,8 +76,7 @@
 			}
 
 			public ISelection getSelection() {
-				return selectedObject != null ? new StructuredSelection(
-						selectedObject) : StructuredSelection.EMPTY;
+				return getCurrentSelection();
 			}
 
 			public void addSelectionChangedListener(
@@ -93,8 +87,7 @@
 
 	@Override
 	public void dispose() {
-		getSite().getWorkbenchWindow().getSelectionService()
-				.removePostSelectionListener(this);
+		CSSSelectionListener.getInstance().removeSelectionListener(this);
 		super.dispose();
 	}
 
@@ -104,24 +97,15 @@
 		if ((this.part != part) && (selection instanceof IStructuredSelection)) {
 			IStructuredSelection structuredSelection = (IStructuredSelection) selection;
 			Object newSelectedObject = structuredSelection.getFirstElement();
-			if (structuredSelection.getFirstElement() instanceof ICSSNode) {
+			if (structuredSelection.getFirstElement() instanceof StyleContainer) {
 
-				CSSStyleRule styleRule = CSSViewUtil
-						.getStyleRule((ICSSNode) structuredSelection
-								.getFirstElement());
+				updateStyleAttributes(((StyleContainer) newSelectedObject)
+						.getStyleAttributes());
 
-				if (styleRule != null) {
-					((IObservable) styleAttributes.getAttributeMap())
-							.removeChangeListener(this);
-					updateStyleAttributes(styleRule);
-					((IObservable) styleAttributes.getAttributeMap())
-							.addChangeListener(this);
-					newSelectedObject = styleRule;
-				}
-
 			}
 
-			if (selectedObject != newSelectedObject)
+			if ((selectedObject == null)
+					|| (!selectedObject.equals(newSelectedObject)))
 				super.selectionChanged(part, selection);
 			selectedObject = newSelectedObject;
 
@@ -129,43 +113,30 @@
 
 	}
 
-	private void updateStyleAttributes(CSSStyleRule styleRule) {
+	private void updateStyleAttributes(Map<String, String> attributes) {
 
-		getStyleAttributes().setStyleProperties(
-				CSSViewUtil.getStyleAttributes(styleRule));
+		((IObservable) getStyleAttributes().getAttributeMap())
+				.removeChangeListener(this);
+		getStyleAttributes().setStyleProperties(attributes);
+		((IObservable) getStyleAttributes().getAttributeMap())
+				.addChangeListener(this);
 
 	}
 
 	public void handleChange(ChangeEvent event) {
 
-		if (selectedObject instanceof CSSStyleRule) {
+		if (selectedObject instanceof StyleContainer) {
 
-			final CSSStyleDeclaration declaration = ((CSSStyleRule) selectedObject)
-					.getStyle();
-
-			// set properties
-			final Set<Entry<String, String>> set = styleAttributes.entrySet();
-
-			if ((set.size() == 0) && (declaration.getLength() > 0)) {
-				declaration.setCssText(Constants.EMPTY);
-			} else {
-				for (final Map.Entry<String, String> me : set) {
-					if ((me.getValue() == null)
-							|| (me.getValue().length() == 0)) {
-						declaration.removeProperty(me.getKey());
-					} else {
-						declaration.setProperty(me.getKey(), me.getValue(),
-								Constants.EMPTY);
-					}
-				}
-			}
+			((StyleContainer) selectedObject)
+					.applyStyleAttributes(getStyleAttributes()
+							.getAttributeMap());
 		}
 
-		notifySelectionChanged(new StructuredSelection(selectedObject));
+		notifySelectionChanged(getCurrentSelection());
 
 	}
 
-	protected void notifySelectionChanged(StructuredSelection selection) {
+	protected void notifySelectionChanged(ISelection selection) {
 		part.postSelectionChanged(new SelectionChangedEvent(part
 				.getSelectionProvider(), selection));
 	}
@@ -182,4 +153,14 @@
 		return styleAttributes;
 	}
 
+	public ISelection getCurrentSelection() {
+
+		Object currentSelectedObject = selectedObject;
+		if (selectedObject instanceof StyleContainer)
+			currentSelectedObject = ((StyleContainer) selectedObject)
+					.getStyleObject();
+		return currentSelectedObject != null ? new StructuredSelection(
+				currentSelectedObject) : StructuredSelection.EMPTY;
+
+	}
 }

Modified: trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/view/CSSEditorView.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/view/CSSEditorView.java	2009-09-09 16:01:21 UTC (rev 17493)
+++ trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/view/CSSEditorView.java	2009-09-09 16:09:14 UTC (rev 17494)
@@ -11,6 +11,7 @@
 
 package org.jboss.tools.jst.css.view;
 
+import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.SelectionChangedEvent;
 import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.part.IContributedContentsView;
@@ -29,6 +30,11 @@
 	static public String CONTRIBUTOR_ID = "org.eclipse.wst.css.core.csssource.source"; //$NON-NLS-1$
 
 	@Override
+	public void selectionChanged(IWorkbenchPart part, ISelection sel) {
+		// do nothing
+	}
+
+	@Override
 	protected PageRec doCreatePage(final IWorkbenchPart part) {
 		if (part instanceof PropertySheet) {
 			return null;
@@ -55,7 +61,8 @@
 	public SelectionProvider getSelectionProvider() {
 		return super.getSelectionProvider();
 	}
-	public void postSelectionChanged(SelectionChangedEvent event){
+
+	public void postSelectionChanged(SelectionChangedEvent event) {
 		getSelectionProvider().postSelectionChanged(event);
 	}
 

Modified: trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/view/CSSPreview.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/view/CSSPreview.java	2009-09-09 16:01:21 UTC (rev 17493)
+++ trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/view/CSSPreview.java	2009-09-09 16:09:14 UTC (rev 17494)
@@ -32,10 +32,10 @@
 import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.part.ViewPart;
-import org.eclipse.wst.css.core.internal.provisional.document.ICSSNode;
+import org.jboss.tools.jst.css.common.CSSSelectionListener;
+import org.jboss.tools.jst.css.common.StyleContainer;
 import org.jboss.tools.jst.css.messages.CSSUIMessages;
 import org.jboss.tools.jst.jsp.outline.cssdialog.common.Constants;
-import org.w3c.dom.css.CSSStyleRule;
 
 /**
  * @author Sergey Dzmitrovich
@@ -51,20 +51,17 @@
 
 	private Map<String, String> styleAttributes = new HashMap<String, String>();
 
-	// private String location;
-	// private String selectorName;
-
 	@Override
 	public void init(IViewSite site) throws PartInitException {
 		super.init(site);
-		site.getWorkbenchWindow().getSelectionService()
-				.addPostSelectionListener(this);
+
+		CSSSelectionListener.getInstance().addSelectionListener(this);
 	}
 
 	@Override
 	public void dispose() {
-		getSite().getWorkbenchWindow().getSelectionService()
-				.removePostSelectionListener(this);
+
+		CSSSelectionListener.getInstance().removeSelectionListener(this);
 		super.dispose();
 	}
 
@@ -161,20 +158,15 @@
 
 		if (selection instanceof IStructuredSelection) {
 			IStructuredSelection structuredSelection = (IStructuredSelection) selection;
-			if (structuredSelection.getFirstElement() instanceof ICSSNode) {
+			if (structuredSelection.getFirstElement() instanceof StyleContainer) {
 
-				CSSStyleRule styleRule = CSSViewUtil
-						.getStyleRule((ICSSNode) structuredSelection
-								.getFirstElement());
+				styleAttributes = ((StyleContainer) structuredSelection
+						.getFirstElement()).getStyleAttributes();
 
-				if (styleRule != null) {
-					styleAttributes = CSSViewUtil.getStyleAttributes(styleRule);
-
-				} else {
-					styleAttributes.clear();
-				}
-
+			} else {
+				styleAttributes.clear();
 			}
+
 			updateBrowser();
 		}
 

Deleted: trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/view/CSSViewUtil.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/view/CSSViewUtil.java	2009-09-09 16:01:21 UTC (rev 17493)
+++ trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/view/CSSViewUtil.java	2009-09-09 16:09:14 UTC (rev 17494)
@@ -1,54 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007-2009 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributor:
- *     Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-
-package org.jboss.tools.jst.css.view;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.wst.css.core.internal.provisional.document.ICSSNode;
-import org.w3c.dom.css.CSSStyleDeclaration;
-import org.w3c.dom.css.CSSStyleRule;
-
-/**
- * @author Sergey Dzmitrovich
- * 
- */
-public class CSSViewUtil {
-
-	public static CSSStyleRule getStyleRule(ICSSNode node) {
-
-		while (node != null) {
-
-			if (node instanceof CSSStyleRule)
-				return (CSSStyleRule) node;
-
-			node = node.getParentNode();
-		}
-
-		return null;
-	}
-
-	public static Map<String, String> getStyleAttributes(CSSStyleRule styleRule) {
-
-		CSSStyleDeclaration declaration = styleRule.getStyle();
-		Map<String, String> styleMap = new HashMap<String, String>();
-		for (int i = 0; i < declaration.getLength(); i++) {
-			String propperty = declaration.item(i);
-			String value = declaration.getPropertyValue(propperty);
-			styleMap.put(propperty, value);
-		}
-
-		return styleMap;
-
-	}
-
-}



More information about the jbosstools-commits mailing list