Author: yzhishko
Date: 2010-02-26 12:22:51 -0500 (Fri, 26 Feb 2010)
New Revision: 20519
Modified:
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/CSSStyleRuleContainer.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-5954 - fixed
Modified:
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/CSSStyleListener.java 2010-02-26
15:06:28 UTC (rev 20518)
+++
trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSStyleListener.java 2010-02-26
17:22:51 UTC (rev 20519)
@@ -20,10 +20,12 @@
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.views.contentoutline.ContentOutline;
+import org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem;
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;
+@SuppressWarnings("restriction")
public class CSSStyleListener implements ISelectionListener, INodeAdapter,
IPartListener {
@@ -148,6 +150,8 @@
public void notifyChanged(INodeNotifier notifier, int eventType,
Object changedFeature, Object oldValue, Object newValue, int pos) {
+ clearListeners(newValue);
+ clearListeners(oldValue);
Object[] array = listeners.getListeners();
for (int i = 0; i < array.length; i++) {
final ICSSViewListner l = (ICSSViewListner) array[i];
@@ -161,9 +165,22 @@
}
}
-
}
-
+
+ /*
+ * Fixed by yzhishko. See
https://jira.jboss.org/jira/browse/JBIDE-5954.
+ */
+ private void clearListeners(Object node){
+ if (!(node instanceof ICSSStyleDeclItem)) {
+ return;
+ }
+ if (!(node instanceof INodeNotifier)) {
+ return;
+ }
+ ((INodeNotifier)node).removeAdapter(this);
+ ((INodeNotifier)node).addAdapter(this);
+ }
+
public void partActivated(IWorkbenchPart part) {
currentPart = part;
Object[] array = listeners.getListeners();
Modified:
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 2010-02-26
15:06:28 UTC (rev 20518)
+++
trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/common/CSSStyleRuleContainer.java 2010-02-26
17:22:51 UTC (rev 20519)
@@ -13,6 +13,7 @@
import java.util.HashMap;
import java.util.Map;
+import org.eclipse.wst.css.core.internal.provisional.document.ICSSNode;
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;
@@ -24,6 +25,7 @@
* @author Sergey Dzmitrovich
*
*/
+@SuppressWarnings("restriction")
public class CSSStyleRuleContainer extends StyleContainer {
private CSSStyleRule styleRule;
@@ -80,12 +82,46 @@
ICSSStyleDeclaration declaration = (ICSSStyleDeclaration) styleRule
.getStyle();
addNodeAdapter(declaration, adapter);
- ICSSNodeList nodeList = declaration.getChildNodes();
+ addNodeListenersForChildren(declaration, adapter);
+ }
+
+ /*
+ * Fixed by yzhishko. See
https://jira.jboss.org/jira/browse/JBIDE-5954.
+ */
+ private void addNodeListenersForChildren(Object node, INodeAdapter adapter){
+ if (!(node instanceof ICSSNode)) {
+ return;
+ }
+ ICSSNode cssNode = (ICSSNode) node;
+ ICSSNodeList nodeList = cssNode.getChildNodes();
+ if (nodeList == null) {
+ return;
+ }
for (int i = 0; i < nodeList.getLength(); i++) {
- addNodeAdapter(nodeList.item(i), adapter);
+ ICSSNode cssChildNode = nodeList.item(i);
+ addNodeAdapter(cssChildNode, adapter);
+ addNodeListenersForChildren(cssChildNode, adapter);
}
-
}
+
+ /*
+ * Fixed by yzhishko. See
https://jira.jboss.org/jira/browse/JBIDE-5954.
+ */
+ private void removeNodeListenersForChildren(Object node, INodeAdapter adapter){
+ if (!(node instanceof ICSSNode)) {
+ return;
+ }
+ ICSSNode cssNode = (ICSSNode) node;
+ ICSSNodeList nodeList = cssNode.getChildNodes();
+ if (nodeList == null) {
+ return;
+ }
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ ICSSNode cssChildNode = nodeList.item(i);
+ removeNodeAdapter(cssChildNode, adapter);
+ removeNodeListenersForChildren(cssChildNode, adapter);
+ }
+ }
@Override
public void removeNodelListener(INodeAdapter adapter) {
@@ -93,11 +129,7 @@
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);
- }
-
+ removeNodeListenersForChildren(declaration, adapter);
}
@Override