[jbosstools-commits] JBoss Tools SVN: r7004 - in trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template: util and 1 other directory.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Wed Mar 19 08:51:53 EDT 2008
Author: sdzmitrovich
Date: 2008-03-19 08:51:53 -0400 (Wed, 19 Mar 2008)
New Revision: 7004
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractEditableJsfTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractOutputJsfTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfCheckboxSelectItemTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfRadioSelectItemTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/JSF.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1718
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractEditableJsfTemplate.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractEditableJsfTemplate.java 2008-03-19 12:10:55 UTC (rev 7003)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractEditableJsfTemplate.java 2008-03-19 12:51:53 UTC (rev 7004)
@@ -34,7 +34,8 @@
* @author Sergey Dzmitrovich
*
*/
-public abstract class AbstractEditableJsfTemplate extends EditableTemplateAdapter {
+public abstract class AbstractEditableJsfTemplate extends
+ EditableTemplateAdapter {
// general jsf attributes
static private Map<String, String> attributes = new HashMap<String, String>();
@@ -168,10 +169,25 @@
setSourceSelection(pageContext, focusedNode, 0,
getLengthNode(focusedNode));
- pageContext.getVisualBuilder().setSelectionRectangle(
- (nsIDOMElement) mappingRealNode.getVisualElement()
- .queryInterface(
- nsIDOMElement.NS_IDOMELEMENT_IID));
+ // visual selection block
+
+ // get visual node
+ focusedVisualNode = getVisualNode(pageContext, focusedNode,
+ mappingRealNode.getElementData());
+
+ // if not find
+ if (focusedVisualNode == null)
+ focusedVisualNode = mappingRealNode.getVisualElement();
+
+ if (focusedVisualNode.getNodeType() != nsIDOMNode.ELEMENT_NODE)
+
+ focusedVisualNode = focusedVisualNode.getParentNode();
+
+ pageContext
+ .getVisualBuilder()
+ .setSelectionRectangle(
+ (nsIDOMElement) focusedVisualNode
+ .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID));
}
}
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractOutputJsfTemplate.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractOutputJsfTemplate.java 2008-03-19 12:10:55 UTC (rev 7003)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractOutputJsfTemplate.java 2008-03-19 12:51:53 UTC (rev 7004)
@@ -97,7 +97,7 @@
else {
// create info
- VpeChildrenInfo spanInfo = new VpeChildrenInfo(
+ VpeChildrenInfo targetVisualInfo = new VpeChildrenInfo(
targetVisualElement);
// get atribute's offset
@@ -114,13 +114,13 @@
Node child = list.item(i);
// add info to creation data
- spanInfo.addSourceChild(child);
+ targetVisualInfo.addSourceChild(child);
}
elementData.addAttributeData(new VpeAttributeData(outputAttr,
targetVisualElement, false));
- creationData.addChildrenInfo(spanInfo);
+ creationData.addChildrenInfo(targetVisualInfo);
}
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfCheckboxSelectItemTemplate.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfCheckboxSelectItemTemplate.java 2008-03-19 12:10:55 UTC (rev 7003)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfCheckboxSelectItemTemplate.java 2008-03-19 12:51:53 UTC (rev 7004)
@@ -1,56 +1,38 @@
/*******************************************************************************
- * Copyright (c) 2007-2008 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
- ******************************************************************************/
+ * Copyright (c) 2007-2008 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.jsf.vpe.jsf.template;
-import org.jboss.tools.jsf.vpe.jsf.template.util.NodeProxyUtil;
+import org.jboss.tools.jsf.vpe.jsf.template.util.JSF;
import org.jboss.tools.vpe.editor.VpeSourceDomBuilder;
import org.jboss.tools.vpe.editor.context.VpePageContext;
-import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
-import org.jboss.tools.vpe.editor.template.VpeAbstractTemplate;
-import org.jboss.tools.vpe.editor.template.VpeChildrenInfo;
import org.jboss.tools.vpe.editor.template.VpeCreationData;
import org.jboss.tools.vpe.editor.util.HTML;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
-import org.mozilla.interfaces.nsIDOMText;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
/**
* @author dmaliarevich
- *
+ *
*/
-public class JsfCheckboxSelectItemTemplate extends VpeAbstractTemplate {
+public class JsfCheckboxSelectItemTemplate extends AbstractOutputJsfTemplate {
- private static final String ITEM_LABEL = "itemLabel";
- private static final String TYPE_CHECKBOX = "checkbox";
- private static final String CLASS = "class";
+ private static final String TYPE_CHECKBOX = "checkbox"; //$NON-NLS-1$
// style of span
private static final String SPAN_STYLE_VALUE = "-moz-user-modify: read-write;"; //$NON-NLS-1$
- /*h:SelectManyCheckbox attributes*/
- private static final String DIR = "dir";
- private static final String DISABLED = "disabled";
- private static final String ENABLED_CLASS = "enabledClass";
- private static final String DISABLED_CLASS = "disabledClass";
-
-
- /* "escape" attribute of f:selectItem */
- private static final String ESCAPE = "escape";
-
- private String escape;
private String dir;
private String disabled;
private String enabledClass;
@@ -62,17 +44,19 @@
public JsfCheckboxSelectItemTemplate() {
}
- /* (non-Javadoc)
- * @see org.jboss.tools.vpe.editor.template.VpeTemplate#create(org.jboss.tools.vpe.editor.context.VpePageContext, org.w3c.dom.Node, org.mozilla.interfaces.nsIDOMDocument)
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.tools.vpe.editor.template.VpeTemplate#create(org.jboss.tools.vpe.editor.context.VpePageContext,
+ * org.w3c.dom.Node, org.mozilla.interfaces.nsIDOMDocument)
*/
public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
nsIDOMDocument visualDocument) {
-
+
readParentAttributes(sourceNode.getParentNode());
- readAttributes(sourceNode);
-
+
Element element = (Element) sourceNode;
-
+
nsIDOMElement input = visualDocument.createElement(HTML.TAG_INPUT);
nsIDOMElement label = visualDocument.createElement(HTML.TAG_LABEL);
// create span element
@@ -90,41 +74,19 @@
if (attrPresents(dir)) {
input.setAttribute(HTML.ATTR_DIR, dir);
}
-
- if (attrPresents(disabled) && "true".equalsIgnoreCase(disabled)) {
- label.setAttribute(CLASS, disabledClass);
+
+ if (attrPresents(disabled) && "true".equalsIgnoreCase(disabled)) { //$NON-NLS-1$
+ label.setAttribute(HTML.ATTR_CLASS, disabledClass);
} else if (attrPresents(enabledClass)) {
- label.setAttribute(CLASS, enabledClass);
+ label.setAttribute(HTML.ATTR_CLASS, enabledClass);
}
label.appendChild(labelSpan);
span.appendChild(input);
span.appendChild(label);
-
- Attr attr = null;
- if (element.hasAttribute(ITEM_LABEL)) {
- attr = element.getAttributeNode(ITEM_LABEL);
- }
- if (null != attr) {
- if (null == escape || "true".equalsIgnoreCase(escape)) {
- // show text as is
- String itemLabel = attr.getNodeValue();
- labelSpan.appendChild(visualDocument.createTextNode(itemLabel));
- } else {
- // show formatted text
- VpeChildrenInfo labelSpanInfo = new VpeChildrenInfo(labelSpan);
- // re-parse attribute's value
- NodeList list = NodeProxyUtil.reparseAttributeValue(attr);
- // add children to info
- for (int i = 0; i < list.getLength(); i++) {
- Node child = list.item(i);
- // add info to creation data
- labelSpanInfo.addSourceChild(child);
- }
- creationData.addChildrenInfo(labelSpanInfo);
- }
- }
+ processOutputAttribute(pageContext, visualDocument, element, labelSpan,
+ creationData);
return creationData;
}
@@ -132,12 +94,13 @@
/**
* Checks is attribute presents.
*
- * @param attr the attribute
+ * @param attr
+ * the attribute
*
* @return true, if successful
*/
private boolean attrPresents(String attr) {
- return ((null != attr) && (!"".equals(attr)));
+ return ((null != attr) && (!"".equals(attr))); //$NON-NLS-1$
}
/**
@@ -166,32 +129,20 @@
/**
* Read attributes from the h:SelectManyCheckbox element.
*
- * @param sourceNode the source node
+ * @param sourceNode
+ * the source node
*/
private void readParentAttributes(Node sourceNode) {
if (null == sourceNode) {
return;
}
Element source = (Element) sourceNode;
- dir = source.getAttribute(DIR);
- disabled = source.getAttribute(DISABLED);
- enabledClass = source.getAttribute(ENABLED_CLASS);
- disabledClass = source.getAttribute(DISABLED_CLASS);
+ dir = source.getAttribute(JSF.ATTR_DIR);
+ disabled = source.getAttribute(JSF.ATTR_DISABLED);
+ enabledClass = source.getAttribute(JSF.ATTR_ENABLED_CLASS);
+ disabledClass = source.getAttribute(JSF.ATTR_DISABLED_CLASS);
}
- /**
- * Read attributes from the source element.
- *
- * @param sourceNode the source node
- */
- private void readAttributes(Node sourceNode) {
- if (null == sourceNode) {
- return;
- }
- Element source = (Element) sourceNode;
- escape = source.getAttribute(ESCAPE);
- }
-
@Override
public void setSourceAttributeSelection(VpePageContext pageContext,
Element sourceElement, int offset, int length, Object data) {
@@ -199,4 +150,19 @@
sourceBuilder.setSelection(sourceElement, 0, 0);
}
+ @Override
+ protected Attr getOutputAttributeNode(Element element) {
+
+ if (element.hasAttribute(JSF.ATTR_ITEM_LABEL))
+ return element.getAttributeNode(JSF.ATTR_ITEM_LABEL);
+ return null;
+ }
+
+ @Override
+ public boolean isRecreateAtAttrChange(VpePageContext pageContext,
+ Element sourceElement, nsIDOMDocument visualDocument,
+ nsIDOMElement visualNode, Object data, String name, String value) {
+ return true;
+ }
+
}
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfRadioSelectItemTemplate.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfRadioSelectItemTemplate.java 2008-03-19 12:10:55 UTC (rev 7003)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfRadioSelectItemTemplate.java 2008-03-19 12:51:53 UTC (rev 7004)
@@ -12,21 +12,16 @@
import org.eclipse.wst.xml.core.internal.document.ElementImpl;
import org.jboss.tools.jsf.vpe.jsf.template.util.ComponentUtil;
-import org.jboss.tools.jsf.vpe.jsf.template.util.NodeProxyUtil;
+import org.jboss.tools.jsf.vpe.jsf.template.util.JSF;
import org.jboss.tools.vpe.editor.context.VpePageContext;
-import org.jboss.tools.vpe.editor.mapping.VpeAttributeData;
-import org.jboss.tools.vpe.editor.mapping.VpeElementData;
-import org.jboss.tools.vpe.editor.template.VpeChildrenInfo;
import org.jboss.tools.vpe.editor.template.VpeCreationData;
import org.jboss.tools.vpe.editor.util.HTML;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
-import org.mozilla.interfaces.nsIDOMText;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
/**
* @author sdzmitrovich
@@ -34,7 +29,7 @@
* template for radio select item
*
*/
-public class JsfRadioSelectItemTemplate extends AbstractEditableJsfTemplate{
+public class JsfRadioSelectItemTemplate extends AbstractOutputJsfTemplate {
/* "itemDisabled" attribute of f:selectItem */
public static final String ITEM_DISABLED = "itemDisabled"; //$NON-NLS-1$
@@ -48,20 +43,10 @@
// style of span
private static final String SPAN_STYLE_VALUE = "-moz-user-modify: read-write;"; //$NON-NLS-1$
- /* "itemLabel" attribute of f:selectItem */
- private static final String ITEM_LABEL = "itemLabel"; //$NON-NLS-1$
-
- /* "escape" attribute of f:selectItem */
- private static final String ESCAPE = "escape"; //$NON-NLS-1$
-
- /* "dir" attribute of f:selectSelectOneRadio */
- private static final String DIR = "dir"; //$NON-NLS-1$
-
private static final String CONSTANT_TRUE = "true"; //$NON-NLS-1$
private static final String CONSTANT_EMPTY = ""; //$NON-NLS-1$
private String dir;
- private String escape;
/**
*
@@ -82,7 +67,6 @@
Element element = (Element) sourceNode;
- VpeElementData elementData = new VpeElementData();
// create table element
nsIDOMElement table = visualDocument.createElement(HTML.TAG_TABLE);
boolean disabledItem = ComponentUtil.string2boolean(ComponentUtil
@@ -100,8 +84,7 @@
table.appendChild(label);
if (null != element) {
- escape = element.getAttribute(ESCAPE);
- dir = element.getAttribute(DIR);
+ dir = element.getAttribute(JSF.ATTR_DIR);
}
VpeCreationData creationData = new VpeCreationData(table);
@@ -117,47 +100,9 @@
radio.setAttribute(HTML.ATTR_DIR, dir);
}
- Attr attr = null;
- if (element.hasAttribute(ITEM_LABEL)) {
- attr = element.getAttributeNode(ITEM_LABEL);
- }
+ processOutputAttribute(pageContext, visualDocument, element, label,
+ creationData);
- if (null != attr) {
- if (null == escape || "true".equalsIgnoreCase(escape)) {
- // show text as is
-
- String itemLabel = attr.getNodeValue();
- String bundleValue = ComponentUtil.getBundleValue(pageContext,
- attr);
-
- nsIDOMText text;
- // if bundleValue differ from value then will be represent
- // bundleValue, but text will be not edit
- boolean isEditable = itemLabel.equals(bundleValue);
-
- text = visualDocument.createTextNode(bundleValue);
- // add attribute for ability of editing
-
- elementData.addAttributeData(new VpeAttributeData(attr, text,
- isEditable));
- label.appendChild(text);
- } else {
- // show formatted text
- VpeChildrenInfo labelSpanInfo = new VpeChildrenInfo(label);
- // re-parse attribute's value
- NodeList list = NodeProxyUtil.reparseAttributeValue(attr);
- // add children to info
- for (int i = 0; i < list.getLength(); i++) {
- Node child = list.item(i);
- // add info to creation data
- labelSpanInfo.addSourceChild(child);
- }
- elementData.addAttributeData(new VpeAttributeData(attr, label,
- false));
- creationData.addChildrenInfo(labelSpanInfo);
- }
- }
- creationData.setElementData(elementData);
return creationData;
}
@@ -222,4 +167,19 @@
return ((null != attr) && (!CONSTANT_EMPTY.equals(attr)));
}
+ @Override
+ protected Attr getOutputAttributeNode(Element element) {
+
+ if (element.hasAttribute(JSF.ATTR_ITEM_LABEL))
+ return element.getAttributeNode(JSF.ATTR_ITEM_LABEL);
+ return null;
+ }
+
+ @Override
+ public boolean isRecreateAtAttrChange(VpePageContext pageContext,
+ Element sourceElement, nsIDOMDocument visualDocument,
+ nsIDOMElement visualNode, Object data, String name, String value) {
+ return true;
+ }
+
}
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/JSF.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/JSF.java 2008-03-19 12:10:55 UTC (rev 7003)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/util/JSF.java 2008-03-19 12:51:53 UTC (rev 7004)
@@ -29,4 +29,14 @@
public static final String ATTR_FOR = "for"; //$NON-NLS-1$
+ public static final String ATTR_ITEM_LABEL = "itemLabel"; //$NON-NLS-1$
+
+ public static final String ATTR_DISABLED = "disabled"; //$NON-NLS-1$
+
+ public static final String ATTR_ENABLED_CLASS = "enabledClass"; //$NON-NLS-1$
+
+ public static final String ATTR_DISABLED_CLASS = "disabledClass"; //$NON-NLS-1$
+
+ public static final String ATTR_STYLE_CLASS = "styleClass"; //$NON-NLS-1$
+
}
More information about the jbosstools-commits
mailing list