[jbosstools-commits] JBoss Tools SVN: r17662 - trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Fri Sep 18 11:02:41 EDT 2009


Author: sdzmitrovich
Date: 2009-09-18 11:02:38 -0400 (Fri, 18 Sep 2009)
New Revision: 17662

Added:
   trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSStyleListener.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/ICSSViewListner.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/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
Log:
https://jira.jboss.org/jira/browse/JBIDE-4849

Deleted: 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	2009-09-18 13:27:39 UTC (rev 17661)
+++ trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSSelectionListener.java	2009-09-18 15:02:38 UTC (rev 17662)
@@ -1,103 +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.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);
-//		 PlatformUI.getWorkbench().getActiveWorkbenchWindow()
-//		 .getSelectionService().addSelectionListener(this);
-	}
-
-	private void stopListening() {
-		PlatformUI.getWorkbench().getActiveWorkbenchWindow()
-				.getSelectionService().removePostSelectionListener(this);
-		// PlatformUI.getWorkbench().getActiveWorkbenchWindow()
-		// .getSelectionService().addSelectionListener(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());
-				}
-			}
-
-		}
-
-	}
-}

Copied: trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSStyleListener.java (from rev 17608, 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/CSSStyleListener.java	                        (rev 0)
+++ trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSStyleListener.java	2009-09-18 15:02:38 UTC (rev 17662)
@@ -0,0 +1,195 @@
+/*******************************************************************************
+ * 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.IEditorPart;
+import org.eclipse.ui.IPartListener;
+import org.eclipse.ui.ISelectionListener;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.views.contentoutline.ContentOutline;
+import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
+import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
+import org.jboss.tools.jst.css.CssPlugin;
+
+public class CSSStyleListener implements ISelectionListener, INodeAdapter,
+		IPartListener {
+
+	private static CSSStyleListener instance;
+
+	private ListenerList listeners = new ListenerList();
+
+	private CSSStyleManager styleManager = new CSSStyleManager();
+
+	private StyleContainer currentStyle;
+
+	private IWorkbenchPart currentPart;
+
+	private CSSStyleListener() {
+	}
+
+	public synchronized static CSSStyleListener getInstance() {
+
+		if (instance == null) {
+			instance = new CSSStyleListener();
+		}
+		return instance;
+	}
+
+	public void addSelectionListener(ICSSViewListner listener) {
+
+		// if added the first listener start listing
+		if (listeners.size() == 0)
+			startListening();
+
+		listeners.add(listener);
+	}
+
+	public void removeSelectionListener(ICSSViewListner listener) {
+		listeners.remove(listener);
+
+		// if removed last listener start listing
+		if (listeners.size() == 0)
+			stopListening();
+	}
+
+	private void startListening() {
+		PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService()
+				.addPartListener(this);
+		PlatformUI.getWorkbench().getActiveWorkbenchWindow()
+				.getSelectionService().addPostSelectionListener(this);
+
+		// PlatformUI.getWorkbench().getActiveWorkbenchWindow()
+		// .getSelectionService().addSelectionListener(this);
+	}
+
+	private void stopListening() {
+		PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService()
+				.removePartListener(this);
+		PlatformUI.getWorkbench().getActiveWorkbenchWindow()
+				.getSelectionService().removePostSelectionListener(this);
+		// PlatformUI.getWorkbench().getActiveWorkbenchWindow()
+		// .getSelectionService().addSelectionListener(this);
+
+	}
+
+	public void selectionChanged(IWorkbenchPart part, ISelection selection) {
+
+		StyleContainer newStyle = styleManager.recognizeCSSStyle(selection);
+
+		if (isImportant(part)
+				&& ((currentStyle == null) || !(currentStyle.equals(newStyle)))) {
+
+			disconnect(currentStyle);
+			connect(newStyle);
+			currentStyle = newStyle;
+
+			ISelection selectionToLiteners = null;
+
+			if (newStyle != null) {
+				selectionToLiteners = new StructuredSelection(newStyle);
+			} else {
+				selectionToLiteners = StructuredSelection.EMPTY;
+			}
+
+			Object[] array = listeners.getListeners();
+			for (int i = 0; i < array.length; i++) {
+				final ICSSViewListner l = (ICSSViewListner) array[i];
+				if ((part != null) && (l != currentPart) && (selection != null)) {
+
+					try {
+						l.selectionChanged(part, selectionToLiteners);
+					} catch (Exception e) {
+						CssPlugin.log(e.getLocalizedMessage());
+					}
+				}
+
+			}
+
+		}
+
+	}
+
+	protected boolean isImportant(IWorkbenchPart part) {
+		if ((part instanceof IEditorPart) || (part instanceof ContentOutline))
+			return true;
+		return false;
+	}
+
+	private void connect(StyleContainer style) {
+
+		if (style != null) {
+			style.addNodeListener(this);
+		}
+
+	}
+
+	private void disconnect(StyleContainer style) {
+		if (style != null) {
+			style.removeNodelListener(this);
+		}
+	}
+
+	public boolean isAdapterForType(Object type) {
+		return type.equals(CSSStyleListener.class);
+	}
+
+	public void notifyChanged(INodeNotifier notifier, int eventType,
+			Object changedFeature, Object oldValue, Object newValue, int pos) {
+		Object[] array = listeners.getListeners();
+		for (int i = 0; i < array.length; i++) {
+			final ICSSViewListner l = (ICSSViewListner) array[i];
+
+			if (currentPart != l) {
+				try {
+					l.styleChanged(currentStyle);
+				} catch (Exception e) {
+					CssPlugin.log(e.getLocalizedMessage());
+				}
+			}
+
+		}
+
+	}
+
+	public void partActivated(IWorkbenchPart part) {
+		currentPart = part;
+		Object[] array = listeners.getListeners();
+		for (int i = 0; i < array.length; i++) {
+			final ICSSViewListner l = (ICSSViewListner) array[i];
+
+			if (l instanceof IPartListener) {
+				try {
+					((IPartListener) l).partActivated(part);
+				} catch (Exception e) {
+					CssPlugin.log(e.getLocalizedMessage());
+				}
+			}
+		}
+	}
+
+	public void partBroughtToTop(IWorkbenchPart part) {
+		partActivated(part);
+	}
+
+	public void partClosed(IWorkbenchPart part) {
+	}
+
+	public void partDeactivated(IWorkbenchPart part) {
+	}
+
+	public void partOpened(IWorkbenchPart part) {
+	}
+}

Deleted: 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	2009-09-18 13:27:39 UTC (rev 17661)
+++ trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSStyleManager.java	2009-09-18 15:02:38 UTC (rev 17662)
@@ -1,216 +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.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.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 Element)
-					|| (selectedObject instanceof Attr)) {
-
-				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;
-	}
-}

Copied: trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSStyleManager.java (from rev 17608, 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-18 15:02:38 UTC (rev 17662)
@@ -0,0 +1,216 @@
+/*******************************************************************************
+ * 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.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 Element)
+					|| (selectedObject instanceof Attr)) {
+
+				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)
+					&& (selection instanceof ITextSelection)) {
+
+				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;
+	}
+}

Deleted: 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	2009-09-18 13:27:39 UTC (rev 17661)
+++ trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSStyleRuleContainer.java	2009-09-18 15:02:38 UTC (rev 17662)
@@ -1,75 +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.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 if (!me.getValue().equals(
-							declaration.getPropertyValue(me.getKey()))) {
-						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;
-	}
-
-}

Copied: trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSStyleRuleContainer.java (from rev 17608, 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-18 15:02:38 UTC (rev 17662)
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * 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.eclipse.wst.css.core.internal.provisional.document.ICSSNodeList;
+import org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration;
+import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
+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 if (!me.getValue().equals(
+							declaration.getPropertyValue(me.getKey()))) {
+						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;
+	}
+
+	@Override
+	public void addNodeListener(INodeAdapter adapter) {
+		ICSSStyleDeclaration declaration = (ICSSStyleDeclaration) styleRule
+				.getStyle();
+		addNodeAdapter(declaration, adapter);
+		ICSSNodeList nodeList = declaration.getChildNodes();
+		for (int i = 0; i < nodeList.getLength(); i++) {
+			addNodeAdapter(nodeList.item(i), adapter);
+		}
+
+	}
+
+	@Override
+	public void removeNodelListener(INodeAdapter adapter) {
+
+		ICSSStyleDeclaration declaration = (ICSSStyleDeclaration) styleRule
+				.getStyle();
+		removeNodeAdapter(declaration, adapter);
+		ICSSNodeList nodeList = declaration.getChildNodes();
+		for (int i = 0; i < nodeList.getLength(); i++) {
+			removeNodeAdapter(nodeList.item(i), adapter);
+		}
+
+	}
+
+}

Added: trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/ICSSViewListner.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/ICSSViewListner.java	                        (rev 0)
+++ trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/ICSSViewListner.java	2009-09-18 15:02:38 UTC (rev 17662)
@@ -0,0 +1,9 @@
+package org.jboss.tools.jst.css.common;
+
+import org.eclipse.ui.ISelectionListener;
+
+public interface ICSSViewListner extends ISelectionListener {
+
+	public void styleChanged(StyleContainer styleContainer);
+
+}


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

Deleted: 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	2009-09-18 13:27:39 UTC (rev 17661)
+++ trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/StyleAttribyteContainer.java	2009-09-18 15:02:38 UTC (rev 17662)
@@ -1,79 +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.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;
-	}
-
-}

Copied: trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/StyleAttribyteContainer.java (from rev 17608, 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-18 15:02:38 UTC (rev 17662)
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * 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.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
+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;
+	}
+
+	@Override
+	public void addNodeListener(INodeAdapter adapter) {
+		addNodeAdapter(element, adapter);
+		
+	}
+
+	@Override
+	public void removeNodelListener(INodeAdapter adapter) {
+		removeNodeAdapter(element, adapter);
+		
+	}
+
+}

Deleted: 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	2009-09-18 13:27:39 UTC (rev 17661)
+++ trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/StyleContainer.java	2009-09-18 15:02:38 UTC (rev 17662)
@@ -1,33 +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.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);
-	}
-
-}

Copied: trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/StyleContainer.java (from rev 17608, 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-18 15:02:38 UTC (rev 17662)
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * 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;
+
+import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
+import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
+
+/**
+ * @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);
+	}
+
+	protected void addNodeAdapter(Object node, INodeAdapter adapter) {
+
+		if (node instanceof INodeNotifier)
+			((INodeNotifier) node).addAdapter(adapter);
+
+	}
+
+	protected void removeNodeAdapter(Object node, INodeAdapter adapter) {
+		if (node instanceof INodeNotifier)
+			((INodeNotifier) node).removeAdapter(adapter);
+
+	}
+
+	public abstract void addNodeListener(INodeAdapter adapter);
+
+	public abstract void removeNodelListener(INodeAdapter adapter);
+
+}



More information about the jbosstools-commits mailing list