Author: sdzmitrovich
Date: 2008-04-22 04:52:11 -0400 (Tue, 22 Apr 2008)
New Revision: 7678
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1773
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2008-04-22
08:28:02 UTC (rev 7677)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2008-04-22
08:52:11 UTC (rev 7678)
@@ -904,21 +904,38 @@
VpeElementMapping elementMapping = null;
VpeNodeMapping nodeMapping = domMapping.getNodeMapping(sourceNode);
if (nodeMapping instanceof VpeElementMapping) {
+
elementMapping = (VpeElementMapping) nodeMapping;
if (elementMapping != null && elementMapping.getTemplate() != null) {
- Node updateNode = elementMapping.getTemplate()
- .getNodeForUptate(pageContext,
- elementMapping.getSourceNode(),
- elementMapping.getVisualNode(),
- elementMapping.getData());
- if (updateNode != null && updateNode != sourceNode) {
- updateNode(updateNode);
- return;
- }
- }
+ Node updateNode = elementMapping.getTemplate()
+ .getNodeForUptate(pageContext,
+ elementMapping.getSourceNode(),
+ elementMapping.getVisualNode(),
+ elementMapping.getData());
+
+ /*
+ * special processing of "style" element
+ *
+ * for unification of updating nodes - or redevelop updating
+ * mechanism (for example : transfer this function to template )
+ * or redevelop template of "style" element
+ */
+ if (HTML.TAG_STYLE.equalsIgnoreCase(sourceNode.getNodeName())) {
+ // refresh style node
+ VpeStyleUtil.refreshStyleElement(this, elementMapping);
+ return;
+ }
+ if (updateNode != null && updateNode != sourceNode) {
+ updateNode(updateNode);
+ return;
+ }
+ }
}
+
+
nsIDOMNode visualOldNode = domMapping.remove(sourceNode);
getSourceNodes().remove(sourceNode);
+
if (sourceNode instanceof INodeNotifier) {
((INodeNotifier) sourceNode).removeAdapter(getSorceAdapter());
}
@@ -1006,7 +1023,7 @@
if (sourceParent != null && sourceParent.getLocalName() != null) {
String sourceParentName = sourceParent.getLocalName();
if (HTML.TAG_TEXTAREA.equalsIgnoreCase(sourceParentName)
- || HTML.TAG_OPTION.equalsIgnoreCase(sourceParentName)) {
+ || HTML.TAG_OPTION.equalsIgnoreCase(sourceParentName) ||
HTML.TAG_STYLE.equalsIgnoreCase(sourceParentName)) {
updateNode(sourceText.getParentNode());
return true;
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java 2008-04-22
08:28:02 UTC (rev 7677)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java 2008-04-22
08:52:11 UTC (rev 7678)
@@ -13,6 +13,7 @@
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@@ -25,11 +26,15 @@
import org.jboss.tools.common.model.project.IModelNature;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.jst.web.project.WebProject;
+import org.jboss.tools.vpe.editor.VpeVisualDomBuilder;
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.css.ResourceReference;
-import org.jboss.tools.vpe.editor.template.expression.VpeFunctionSrc;
-import org.jboss.tools.vpe.editor.template.expression.VpeValue;
+import org.jboss.tools.vpe.editor.mapping.VpeElementMapping;
+import org.mozilla.interfaces.nsIDOMElement;
+import org.mozilla.interfaces.nsIDOMNode;
+import org.mozilla.interfaces.nsIDOMNodeList;
import org.w3c.dom.Element;
+import org.w3c.dom.Node;
public class VpeStyleUtil {
@@ -621,5 +626,62 @@
}
return rootPath;
}
+
+ /**
+ * refresh style element
+ * @param visualDomBuilder
+ * @param sourceElement
+ * @param oldStyleNode
+ * @return
+ */
+ public static void refreshStyleElement(
+ VpeVisualDomBuilder visualDomBuilder,
+ VpeElementMapping elementMapping) {
+ nsIDOMNode value = null;
+
+ /*
+ * data property( of "style's" elementMapping ) contains
Map<Object,nsIDOMNode>.
+ * There is only one "style" visual element in this map. So we get this
+ * element from map
+ *
+ * there is potential danger in this manner of keeping "style"
+ * element ( use property "data" of Object type )
+ */
+
+ Map<Object, nsIDOMNode> map = (Map<Object, nsIDOMNode>) elementMapping
+ .getData();
+
+ // get "style" element
+ if (map != null) {
+
+ if (map.size() > 0) {
+ value = map.values().iterator().next();
+ }
+ }
+
+ if (value == null)
+ return;
+
+ // get new value of style element
+ Node textNode = elementMapping.getSourceNode().getFirstChild();
+ String text = null;
+
+ if (textNode != null) {
+ text = textNode.getNodeValue();
+ }
+
+
+ nsIDOMNodeList list = value.getChildNodes();
+
+ // remove all children of style element
+ for (int i = 0; i < list.getLength(); i++)
+ value.removeChild(list.item(i));
+
+ // add new value of style element
+ value.appendChild(visualDomBuilder.getXulRunnerEditor()
+ .getDOMDocument().createTextNode(text));
+
+ }
+
}
\ No newline at end of file