Author: tfennelly
Date: 2010-10-26 17:23:15 -0400 (Tue, 26 Oct 2010)
New Revision: 26075
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.templating/src/org/jboss/tools/smooks/templating/model/ModelBuilder.java
trunk/smooks/plugins/org.jboss.tools.smooks.templating/src/org/jboss/tools/smooks/templating/model/csv/CSVModelBuilder.java
trunk/smooks/plugins/org.jboss.tools.smooks.templating/src/org/jboss/tools/smooks/templating/model/xml/XMLSampleModelBuilder.java
trunk/smooks/plugins/org.jboss.tools.smooks.templating/src/org/jboss/tools/smooks/templating/model/xml/XSDModelBuilder.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/model/InputDataTreeNodeModel.java
Log:
https://jira.jboss.org/browse/JBIDE-7330
Broken links in java2csv editor Smooks editor
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.templating/src/org/jboss/tools/smooks/templating/model/ModelBuilder.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.templating/src/org/jboss/tools/smooks/templating/model/ModelBuilder.java 2010-10-26
17:44:41 UTC (rev 26074)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.templating/src/org/jboss/tools/smooks/templating/model/ModelBuilder.java 2010-10-26
21:23:15 UTC (rev 26075)
@@ -25,6 +25,7 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
import org.milyn.xml.DomUtils;
import javax.xml.XMLConstants;
@@ -269,4 +270,58 @@
return !enforce.equals("false"); //$NON-NLS-1$
}
+
+ /**
+ * Does the model element contain child elements.
+ * @param element The element to test.
+ * @return true if the element contains child elements, otherwise false.
+ */
+ public static boolean hasChildElements(Element element) {
+ NodeList childNodes = element.getChildNodes();
+ int numChildren = childNodes.getLength();
+
+ for(int i = 0; i < numChildren; i++) {
+ if(childNodes.item(i).getNodeType() == Node.ELEMENT_NODE) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Set the model as being strict, or not.
+ * <p/>
+ * A strict model should have cardinality info attached e.g. minOccurs/maxOccurs,
required etc.
+ * @param model The model Document node.
+ * @param strict True if the model is strict, otherwise false.
+ */
+ public static void setStrictModel(Document model, boolean strict) {
+ Element documentElement = model.getDocumentElement();
+
+ if(documentElement == null) {
+ throw new IllegalStateException("Call to 'markStrictModel' before the
model's root element has been added."); //$NON-NLS-1$
+ }
+
+ documentElement.setAttributeNS(NAMESPACE, "smk:strict",
Boolean.toString(strict)); //$NON-NLS-1$
+ }
+
+ /**
+ * Is the model strict, or not.
+ * <p/>
+ * A strict model should have cardinality info attached e.g. minOccurs/maxOccurs,
required etc.
+ * @param model The model Document node.
+ * @return True if the model is strict, otherwise false.
+ */
+ public static boolean isStrictModel(Document model) {
+ Element documentElement = model.getDocumentElement();
+
+ if(documentElement == null) {
+ throw new IllegalStateException("Call to 'isStrictModel' before the
model's root element has been added."); //$NON-NLS-1$
+ }
+
+ String strict = documentElement.getAttributeNS(NAMESPACE, "strict");
//$NON-NLS-1$
+
+ return Boolean.parseBoolean(strict);
+ }
}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.templating/src/org/jboss/tools/smooks/templating/model/csv/CSVModelBuilder.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.templating/src/org/jboss/tools/smooks/templating/model/csv/CSVModelBuilder.java 2010-10-26
17:44:41 UTC (rev 26074)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.templating/src/org/jboss/tools/smooks/templating/model/csv/CSVModelBuilder.java 2010-10-26
21:23:15 UTC (rev 26075)
@@ -52,6 +52,9 @@
record.appendChild(fieldElement);
}
+ // The model has some cardinality metadata attached, so mark it as a strict
model...
+ ModelBuilder.setStrictModel(model, true);
+
return model;
}
}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.templating/src/org/jboss/tools/smooks/templating/model/xml/XMLSampleModelBuilder.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.templating/src/org/jboss/tools/smooks/templating/model/xml/XMLSampleModelBuilder.java 2010-10-26
17:44:41 UTC (rev 26074)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.templating/src/org/jboss/tools/smooks/templating/model/xml/XMLSampleModelBuilder.java 2010-10-26
21:23:15 UTC (rev 26075)
@@ -84,6 +84,10 @@
Element documentElement = model.getDocumentElement();
+ // The model has no metadata attached since it is based on only a sample,
+ // so mark it as not being a strict model...
+ ModelBuilder.setStrictModel(model, false);
+
trimNonModelNodes(documentElement);
configureModelElementTypes(documentElement);
configureModelElementCardinality(documentElement);
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.templating/src/org/jboss/tools/smooks/templating/model/xml/XSDModelBuilder.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.templating/src/org/jboss/tools/smooks/templating/model/xml/XSDModelBuilder.java 2010-10-26
17:44:41 UTC (rev 26074)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.templating/src/org/jboss/tools/smooks/templating/model/xml/XSDModelBuilder.java 2010-10-26
21:23:15 UTC (rev 26075)
@@ -91,6 +91,9 @@
Document model = createModelInstance();
expand(rootElement, 1, 1, model, model);
+ // The model has detailed metadata attached, so mark it as a strict model...
+ ModelBuilder.setStrictModel(model, true);
+
return model;
}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/model/InputDataTreeNodeModel.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/model/InputDataTreeNodeModel.java 2010-10-26
17:44:41 UTC (rev 26074)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/model/InputDataTreeNodeModel.java 2010-10-26
21:23:15 UTC (rev 26075)
@@ -18,6 +18,7 @@
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.jboss.tools.smooks.configuration.editors.uitls.SmooksUIUtils;
+import org.jboss.tools.smooks.configuration.editors.xml.AbstractXMLObject;
import org.jboss.tools.smooks.configuration.editors.xml.TagObject;
import org.jboss.tools.smooks.configuration.editors.xml.TagPropertyObject;
import org.jboss.tools.smooks.gef.model.AbstractSmooksGraphicalModel;
@@ -84,25 +85,34 @@
@Override
public boolean canLinkWithTarget(Object model) {
TreeNodeModel targetNode = (TreeNodeModel) model;
- System.out.println(targetNode);
if (targetNode == this
|| targetNode.getModelRootNode() == getModelRootNode()) {
return false;
}
- Object data = AdapterFactoryEditingDomain.unwrap(targetNode.getData());
- AbstractSmooksGraphicalModel pm = targetNode;
- while (pm != null && !(pm instanceof FreemarkerTemplateGraphicalModel)) {
- pm = pm.getParent();
+ Object targetData = AdapterFactoryEditingDomain.unwrap(targetNode.getData());
+ AbstractSmooksGraphicalModel targetModel = targetNode;
+ while (targetModel != null && !(targetModel instanceof
FreemarkerTemplateGraphicalModel)) {
+ targetModel = targetModel.getParent();
}
- if (data instanceof IFreemarkerTemplateModel && pm instanceof
FreemarkerTemplateGraphicalModel) {
- TemplateBuilder builder = ((FreemarkerTemplateGraphicalModel)
pm).getTemplateBuilder();
- if (((IFreemarkerTemplateModel) data).isHidden(builder)) {
+ if (targetData instanceof IFreemarkerTemplateModel && targetModel instanceof
FreemarkerTemplateGraphicalModel) {
+ TemplateBuilder builder = ((FreemarkerTemplateGraphicalModel)
targetModel).getTemplateBuilder();
+ if (((IFreemarkerTemplateModel) targetData).isHidden(builder)) {
return false;
}
- if (data instanceof FreemarkerTemplateXMLModel) {
- if (!((FreemarkerTemplateXMLModel) data).getXMLNodeChildren().isEmpty()) {
+ if (targetData instanceof FreemarkerTemplateXMLModel) {
+ FreemarkerTemplateXMLModel targetDataModel = (FreemarkerTemplateXMLModel)
targetData;
+ if (!targetDataModel.getXMLNodeChildren().isEmpty()) {
+ // The target node has child nodes. The only thing it can connect to on the source
is
+ // a collection node.
+ Object sourceData = AdapterFactoryEditingDomain.unwrap(this.getData());
+ if(sourceData instanceof AbstractXMLObject) {
+ Element sourceElement = ((AbstractXMLObject)sourceData).getReferenceElement();
+ if(ModelBuilder.isCollection(sourceElement) ||
(!ModelBuilder.isStrictModel(sourceElement.getOwnerDocument()) &&
ModelBuilder.hasChildElements(sourceElement))) {
+ return true;
+ }
+ }
return false;
}
}
@@ -134,17 +144,17 @@
pgm = pgm.getParent();
}
}
- if (data instanceof TagPropertyObject) {
+ if (targetData instanceof TagPropertyObject) {
// Only OK to link to an attribute from a valid Value node...
return isValidValueNode();
- } else if (data instanceof TagObject) {
+ } else if (targetData instanceof TagObject) {
if (targetNode.isValidValueNode()) {
return isValidValueNode();
} else if (targetNode.isValidCollectionNode()) {
return isValidCollectionNode();
}
- } else if (data instanceof EObject) {
- if (SmooksUIUtils.getSelectorFeature((EObject) data) != null) {
+ } else if (targetData instanceof EObject) {
+ if (SmooksUIUtils.getSelectorFeature((EObject) targetData) != null) {
return true;
}
}