Author: scabanovich
Date: 2008-05-27 10:02:11 -0400 (Tue, 27 May 2008)
New Revision: 8372
Added:
trunk/seam/plugins/org.jboss.tools.seam.pages.xml/src/org/jboss/tools/seam/pages/xml/model/helpers/SeamPagesProcessStructureHelper.java
Modified:
trunk/seam/plugins/org.jboss.tools.seam.pages.xml/src/org/jboss/tools/seam/pages/xml/model/SeamPagesConstants.java
trunk/seam/plugins/org.jboss.tools.seam.pages.xml/src/org/jboss/tools/seam/pages/xml/model/helpers/SeamPagesProcessHelper.java
Log:
Modified:
trunk/seam/plugins/org.jboss.tools.seam.pages.xml/src/org/jboss/tools/seam/pages/xml/model/SeamPagesConstants.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.pages.xml/src/org/jboss/tools/seam/pages/xml/model/SeamPagesConstants.java 2008-05-27
12:57:39 UTC (rev 8371)
+++
trunk/seam/plugins/org.jboss.tools.seam.pages.xml/src/org/jboss/tools/seam/pages/xml/model/SeamPagesConstants.java 2008-05-27
14:02:11 UTC (rev 8372)
@@ -35,6 +35,8 @@
public String ATTR_PATH = "path"; //$NON-NLS-1$
public String ATTR_VALUE = "value"; //$NON-NLS-1$
public String ATTR_TYPE = "type"; //$NON-NLS-1$
+ public String ATTR_TARGET = "target"; //$NON-NLS-1$
+ public String ATTR_ID = "id"; //$NON-NLS-1$
public String ATTR_VIEW_ID = "view id"; //$NON-NLS-1$
Modified:
trunk/seam/plugins/org.jboss.tools.seam.pages.xml/src/org/jboss/tools/seam/pages/xml/model/helpers/SeamPagesProcessHelper.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.pages.xml/src/org/jboss/tools/seam/pages/xml/model/helpers/SeamPagesProcessHelper.java 2008-05-27
12:57:39 UTC (rev 8371)
+++
trunk/seam/plugins/org.jboss.tools.seam.pages.xml/src/org/jboss/tools/seam/pages/xml/model/helpers/SeamPagesProcessHelper.java 2008-05-27
14:02:11 UTC (rev 8372)
@@ -1,12 +1,16 @@
package org.jboss.tools.seam.pages.xml.model.helpers;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.util.XModelObjectUtil;
+import org.jboss.tools.jst.web.model.ReferenceObject;
import org.jboss.tools.jst.web.model.helpers.autolayout.AutoLayout;
import org.jboss.tools.seam.pages.xml.model.SeamPagesConstants;
import org.jboss.tools.seam.pages.xml.model.helpers.autolayout.SeamPagesItems;
@@ -115,7 +119,6 @@
XModelObject target = rule.getChildByPath("target");
if(target == null) return;
String tvi = target.getAttributeValue(ATTR_VIEW_ID);
- if(tvi == null) tvi = target.getAttributeValue("error code");
if(tvi == null) return;
String ppt = toNavigationRulePathPart(tvi);
targets.put(ppt, getTemplate());
@@ -193,14 +196,145 @@
}
}
- private void updatePageItem(XModelObject g) {
-
+ private void updatePageItem(ReferenceObjectImpl item) {
+ if(item.isUpToDate()) return;
+ item.notifyUpdate();
+ XModelObject sourcePage = item.getReference();
+ item.setAttributeValue(ATTR_ID, sourcePage.getPathPart());
+ item.setAttributeValue(ATTR_PATH, sourcePage.getAttributeValue(ATTR_VIEW_ID));
+ XModelObject[] cs = getPageTargets(sourcePage);
+ updateOutputs(item, cs);
}
+
+ private XModelObject[] getPageTargets(XModelObject o) {
+ XModelObject[] ns = o.getChildren();
+ List<XModelObject> result = null;
+ for (int i = 0; i < ns.length; i++) {
+ String entity = ns[i].getModelEntity().getName();
+ if(!entity.startsWith(ENT_NAVIGATION)) continue;
+ if(entity.startsWith(ENT_NAVIGATION_RULE)) {
+ XModelObject t = getTargetChild(ns[i]);
+ if(t != null) {
+ if(result == null) result = new ArrayList<XModelObject>();
+ result.add(t);
+ }
+ } else {
+ XModelObject[] rs = ns[i].getChildren();
+ for (int k = 0; k < rs.length; k++) {
+ XModelObject t = getTargetChild(rs[k]);
+ if(t != null) {
+ if(result == null) result = new ArrayList<XModelObject>();
+ result.add(t);
+ }
+ }
+ }
+ }
+ return result == null ? new XModelObject[0]
+ : result.toArray(new XModelObject[0]);
+ }
- private void updateExceptionItem(XModelObject g) {
-
+ private void updateExceptionItem(ReferenceObjectImpl item) {
+ if(item.isUpToDate()) return;
+ item.notifyUpdate();
+ XModelObject exc = item.getReference();
+ item.setAttributeValue(ATTR_ID, exc.getPathPart());
+ item.setAttributeValue(ATTR_PATH, exc.getAttributeValue(ATTR_VIEW_ID));
+ XModelObject t = getTargetChild(exc);
+ XModelObject[] cs = t == null ? new XModelObject[0] : new XModelObject[]{t};
+ updateOutputs(item, cs);
}
+
+ private XModelObject getTargetChild(XModelObject o) {
+ XModelObject t = o.getChildByPath("target");
+ if(t == null || t.getModelEntity().getAttribute(ATTR_VIEW_ID) == null) return null;
+ return t;
+ }
+ private void updateOutputs(ReferenceObjectImpl item, XModelObject[] cases) {
+ XModelObject[] os = item.getChildren();
+ if(isOutputOrderUpToDate(cases, os)) {
+ updateOutputs_1(item, cases, os);
+ } else {
+ updateOutputs_2(item, cases, os);
+ }
+ }
+
+ private void updateOutputs_1(ReferenceObjectImpl item, XModelObject[] cases,
XModelObject[] outputs) {
+ int c = 0;
+ for (int i = 0; i < cases.length; i++) {
+ XModelObject output = null;
+ if(c < outputs.length) {
+ output = outputs[c];
+ } else {
+ output = createOutput(item, cases[i]);
+ }
+ ReferenceObjectImpl r = (ReferenceObjectImpl)output;
+ r.setReference(cases[i]);
+ updateOutput(r);
+ ++c;
+ }
+ for (int i = c; i < outputs.length; i++) outputs[i].removeFromParent();
+ }
+
+ private void updateOutputs_2(ReferenceObjectImpl item, XModelObject[] cases,
XModelObject[] outputs) {
+ Map<String,XModelObject> map = new HashMap<String,XModelObject>();
+ for (int i = 0; i < outputs.length; i++) {
+ XModelObject output = outputs[i];
+ output.removeFromParent();
+ map.put(output.getAttributeValue(ATTR_ID), output);
+ }
+ for (int i = 0; i < cases.length; i++) {
+ XModelObject output = map.get(cases[i].getPathPart());
+ if(output == null) {
+ output = createOutput(item, cases[i]);
+ } else {
+ item.addChild(output);
+ }
+ ReferenceObjectImpl r = (ReferenceObjectImpl)output;
+ r.setReference(cases[i]);
+ updateOutput(r);
+ }
+ }
+
+ private boolean isOutputOrderUpToDate(XModelObject[] cases, XModelObject[] outputs) {
+ for (int i = 0; i < cases.length && i < outputs.length; i++) {
+ ReferenceObject r = (ReferenceObject)outputs[i];
+ if(r.getReference() == cases[i]) continue;
+ String pp = cases[i].getPathPart();
+ String id = outputs[i].getAttributeValue(ATTR_ID);
+ if(!pp.equals(id)) return false;
+ }
+ return true;
+ }
+
+ private XModelObject createOutput(XModelObject item, XModelObject rulecase) {
+ XModelObject output = item.getModel().createModelObject(ENT_PROCESS_ITEM_OUTPUT,
null);
+ output.setAttributeValue(ATTR_ID, rulecase.getPathPart());
+ output.setAttributeValue(ATTR_PATH, rulecase.getAttributeValue(ATTR_VIEW_ID));
+ String name = XModelObjectUtil.createNewChildName("output", item);
+ output.setAttributeValue(ATTR_NAME, name);
+ item.addChild(output);
+ return output;
+ }
+
+ private void updateOutput(ReferenceObjectImpl output) {
+ if(output.isUpToDate()) return;
+ output.notifyUpdate();
+ XModelObject rulecase = output.getReference();
+ output.setAttributeValue(ATTR_ID, rulecase.getPathPart());
+ String path = rulecase.getAttributeValue(ATTR_VIEW_ID);
+ output.setAttributeValue(ATTR_PATH, path);
+// String title =
SeamPagesProcessStructureHelper.createItemOutputPresentation(rulecase);
+// output.setAttributeValue("title", title);
+ XModelObject g = findGroupByPath(path);
+ String target = (g == null) ? "" : g.getPathPart();
+ output.setAttributeValue(ATTR_TARGET, target);
+ }
+
+ private XModelObject findGroupByPath(String path) {
+ return getPage(path);
+ }
+
public void autolayout() {
AutoLayout auto = new AutoLayout();
auto.setItems(new SeamPagesItems());
Added:
trunk/seam/plugins/org.jboss.tools.seam.pages.xml/src/org/jboss/tools/seam/pages/xml/model/helpers/SeamPagesProcessStructureHelper.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.pages.xml/src/org/jboss/tools/seam/pages/xml/model/helpers/SeamPagesProcessStructureHelper.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.pages.xml/src/org/jboss/tools/seam/pages/xml/model/helpers/SeamPagesProcessStructureHelper.java 2008-05-27
14:02:11 UTC (rev 8372)
@@ -0,0 +1,58 @@
+package org.jboss.tools.seam.pages.xml.model.helpers;
+
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.jst.web.model.ReferenceObject;
+import org.jboss.tools.jst.web.model.helpers.WebProcessStructureHelper;
+import org.jboss.tools.seam.pages.xml.model.SeamPagesConstants;
+
+public class SeamPagesProcessStructureHelper extends WebProcessStructureHelper implements
SeamPagesConstants {
+ SeamPagesProcessStructureHelper instance = new SeamPagesProcessStructureHelper();
+
+ public XModelObject getParentProcess(XModelObject element) {
+ XModelObject p = element;
+ while(p != null && p.getFileType() == XModelObject.NONE &&
+ !ENT_PROCESS.equals(p.getModelEntity().getName())) p = p.getParent();
+ return p;
+ }
+
+ public XModelObject[] getItems(XModelObject process) {
+ return process.getChildren(ENT_PROCESS_ITEM);
+ }
+
+ public XModelObject[] getOutputs(XModelObject item) {
+ return item.getChildren(ENT_PROCESS_ITEM_OUTPUT);
+ }
+
+ public String getPath(XModelObject element) {
+ return element.getAttributeValue(ATTR_PATH);
+ }
+
+ public XModelObject getItemOutputTarget(XModelObject itemOutput) {
+ return
itemOutput.getParent().getParent().getChildByPath(itemOutput.getAttributeValue(ATTR_TARGET));
+ }
+
+ public String getItemOutputPresentation(XModelObject itemOutput) {
+// boolean s = isShortcut(itemOutput);
+ return itemOutput.getPresentationString();
+ }
+
+ public boolean isPattern(XModelObject item) {
+ String path = item.getAttributeValue(ATTR_PATH);
+ return (path != null) && (path.length() == 0 || path.indexOf('*') >=
0);
+ }
+
+ public boolean isUnconfirmedPage(XModelObject item) {
+ String type = item.getAttributeValue(ATTR_TYPE);
+ if(!TYPE_PAGE.equals(type)) return false;
+ if(isPattern(item)) return false;
+ return !"true".equals(item.getAttributeValue("confirmed"));
+ }
+
+ public XModelObject getReference(XModelObject diagramObject) {
+ if(diagramObject instanceof ReferenceObject) {
+ return ((ReferenceObject)diagramObject).getReference();
+ }
+ return null;
+ }
+
+}
Show replies by date