Author: scabanovich
Date: 2008-05-30 06:01:34 -0400 (Fri, 30 May 2008)
New Revision: 8451
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/ecore/pages/PagesElement.java
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/ecore/pages/PagesModel.java
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/ecore/pages/impl/PageImpl.java
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/ecore/pages/impl/PagesElementImpl.java
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/ecore/pages/impl/PagesModelImpl.java
Log:
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/ecore/pages/PagesElement.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/ecore/pages/PagesElement.java 2008-05-30
07:55:54 UTC (rev 8450)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/ecore/pages/PagesElement.java 2008-05-30
10:01:34 UTC (rev 8451)
@@ -113,4 +113,9 @@
void setData(Object value);
public void dataChanged();
+
+ public PagesModel getPagesModel();
+
+ public void childAdded(Object childData);
+
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/ecore/pages/PagesModel.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/ecore/pages/PagesModel.java 2008-05-30
07:55:54 UTC (rev 8450)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/ecore/pages/PagesModel.java 2008-05-30
10:01:34 UTC (rev 8451)
@@ -12,6 +12,12 @@
public PagesElement findElement(Object data);
+ public void bindElement(Object data, PagesElement element);
+
+ public Link findLink(Object data);
+
+ public void bindLink(Object data, Link link);
+
public void load();
public void dispose();
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/ecore/pages/impl/PageImpl.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/ecore/pages/impl/PageImpl.java 2008-05-30
07:55:54 UTC (rev 8450)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/ecore/pages/impl/PageImpl.java 2008-05-30
10:01:34 UTC (rev 8451)
@@ -188,4 +188,5 @@
}
}
+
} //PageImpl
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/ecore/pages/impl/PagesElementImpl.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/ecore/pages/impl/PagesElementImpl.java 2008-05-30
07:55:54 UTC (rev 8450)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/ecore/pages/impl/PagesElementImpl.java 2008-05-30
10:01:34 UTC (rev 8451)
@@ -26,8 +26,12 @@
import org.eclipse.emf.ecore.util.InternalEList;
import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.seam.pages.xml.model.SeamPagesConstants;
+import org.jboss.tools.seam.pages.xml.model.helpers.SeamPagesProcessStructureHelper;
import org.jboss.tools.seam.ui.pages.editor.ecore.pages.Link;
import org.jboss.tools.seam.ui.pages.editor.ecore.pages.PagesElement;
+import org.jboss.tools.seam.ui.pages.editor.ecore.pages.PagesFactory;
+import org.jboss.tools.seam.ui.pages.editor.ecore.pages.PagesModel;
import org.jboss.tools.seam.ui.pages.editor.ecore.pages.PagesPackage;
/**
@@ -573,6 +577,15 @@
* <!-- end-user-doc -->
* @generated NOT
*/
+ public PagesModel getPagesModel() {
+ return parent == null ? null : parent.getPagesModel();
+ }
+
+ /**
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated NOT
+ */
public void dataChanged() {
}
@@ -582,6 +595,41 @@
* <!-- end-user-doc -->
* @generated NOT
*/
+ public void childAdded(Object childData) {
+ PagesModel pagesModel = getPagesModel();
+ if(pagesModel == null) return;
+
+ if(childData instanceof XModelObject) {
+ SeamPagesProcessStructureHelper h = SeamPagesProcessStructureHelper.getInstance();
+ XModelObject object = (XModelObject)childData;
+ if(object.getModelEntity().getName().equals(SeamPagesConstants.ENT_PROCESS_ITEM_OUTPUT))
{
+ PagesElement from = this; //pagesModel.findElement(object);
+ XModelObject t = h.getItemOutputTarget(object);
+ if(t == null) {
+ //report
+ return;
+ }
+ PagesElement to = pagesModel.findElement(t);
+ if(to == null) {
+ //TODO report failure
+ return;
+ }
+ Link link = PagesFactory.eINSTANCE.createLink();
+ pagesModel.bindLink(childData, link);
+ link.setFromElement(from);
+ link.setToElement(to);
+ link.setName(h.getItemOutputPresentation(object));
+ link.setShortcut(h.isShortcut(object));
+ }
+ }
+
+ }
+
+ /**
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated NOT
+ */
protected XModelObject getModelObject() {
if(data instanceof XModelObject) {
return (XModelObject)data;
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/ecore/pages/impl/PagesModelImpl.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/ecore/pages/impl/PagesModelImpl.java 2008-05-30
07:55:54 UTC (rev 8450)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/ecore/pages/impl/PagesModelImpl.java 2008-05-30
10:01:34 UTC (rev 8451)
@@ -7,6 +7,7 @@
package org.jboss.tools.seam.ui.pages.editor.ecore.pages.impl;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
import org.eclipse.draw2d.geometry.Dimension;
@@ -57,6 +58,13 @@
* <!-- end-user-doc -->
* @generated NOT
*/
+ Map<String, Link> linksByPath = null;
+
+ /**
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated NOT
+ */
XModelTreeListener modelListener = new ML();
/**
@@ -83,6 +91,15 @@
* <!-- end-user-doc -->
* @generated NOT
*/
+ public PagesModel getPagesModel() {
+ return this;
+ }
+
+ /**
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated NOT
+ */
public PagesElement findElement(Object data) {
if(data instanceof XModelObject) {
data = ((XModelObject)data).getPath();
@@ -99,6 +116,20 @@
* <!-- end-user-doc -->
* @generated NOT
*/
+ public void bindElement(Object data, PagesElement element) {
+ element.setData(data);
+ if(data instanceof XModelObject) {
+ addElement((XModelObject)data, element);
+ } else if(data != null) {
+ elementsByPath.put(data.toString(), element);
+ }
+ }
+
+ /**
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated NOT
+ */
void addElement(XModelObject data, PagesElement element) {
elementsByPath.put(data.getPath(), element);
}
@@ -108,12 +139,62 @@
* <!-- end-user-doc -->
* @generated NOT
*/
+ public Link findLink(Object data) {
+ if(data instanceof XModelObject) {
+ data = ((XModelObject)data).getPath();
+ }
+ if(data instanceof String) {
+ Link result = linksByPath.get(data);
+ return result;
+ }
+ return null;
+ }
+
+ /**
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated NOT
+ */
+ public void bindLink(Object data, Link link) {
+ link.setData(data);
+ if(data instanceof XModelObject) {
+ linksByPath.put(((XModelObject)data).getPath(), link);
+ } else if(data != null) {
+ linksByPath.put(data.toString(), link);
+ }
+ }
+
+ void unbind(String path) {
+ Iterator<String> it = elementsByPath.keySet().iterator();
+ while(it.hasNext()) {
+ String p = it.next();
+ if(p.equals(path) || p.startsWith(path + "/")) {
+ it.remove();
+ }
+ }
+ it = linksByPath.keySet().iterator();
+ while(it.hasNext()) {
+ String p = it.next();
+ if(p.equals(path) || path.startsWith(p + "/")) {
+ it.remove();
+ }
+ }
+ }
+
+ /**
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated NOT
+ */
public void load() {
XModelObject installedProcess = (XModelObject)getData();
if(installedProcess == null) return;
elementsByPath = new HashMap<String, PagesElement>();
+ linksByPath = new HashMap<String, Link>();
+
addElement(installedProcess, this);
+
XModelObject[] is = h.getItems(installedProcess);
for (int i = 0; i < is.length; i++) {
addItem(is[i]);
@@ -126,25 +207,46 @@
installedProcess.getModel().addModelTreeListener(modelListener);
}
+ /**
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated NOT
+ */
+ public void childAdded(Object childData) {
+ if(childData instanceof XModelObject) {
+ XModelObject added = (XModelObject)childData;
+ addItem(added);
+ addItemLinks(added);
+ }
+ }
+
+ /**
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated NOT
+ */
private void addItem(XModelObject item) {
String type = item.getAttributeValue(SeamPagesConstants.ATTR_TYPE);
if(SeamPagesConstants.TYPE_PAGE.equals(type)) {
Page page = PagesFactory.eINSTANCE.createPage();
- page.setData(item);
+ bindElement(item, page);
page.dataChanged();
- addElement(item, page);
getChildren().add(page);
} else if(SeamPagesConstants.TYPE_EXCEPTION.equals(type)) {
PgException exc = PagesFactory.eINSTANCE.createPgException();
- exc.setData(item);
+ bindElement(item, exc);
exc.dataChanged();
- addElement(item, exc);
getChildren().add(exc);
} else {
//TODO
}
}
+ /**
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated NOT
+ */
private void addItemLinks(XModelObject item) {
String type = item.getAttributeValue(SeamPagesConstants.ATTR_TYPE);
if(SeamPagesConstants.TYPE_PAGE.equals(type)
@@ -156,22 +258,7 @@
}
XModelObject[] os = h.getOutputs(item);
for (int j = 0; j < os.length; j++) {
- XModelObject t = h.getItemOutputTarget(os[j]);
- if(t == null) {
- //TODO report failure
- return;
- }
- PagesElement to = findElement(t);
- if(to == null) {
- //TODO report failure
- return;
- }
- Link link = PagesFactory.eINSTANCE.createLink();
- link.setData(os[j]);
- link.setFromElement(from);
- link.setToElement(to);
- link.setName(h.getItemOutputPresentation(os[j]));
- link.setShortcut(h.isShortcut(os[j]));
+ from.childAdded(os[j]);
}
}
}
@@ -181,17 +268,6 @@
* <!-- end-user-doc -->
* @generated NOT
*/
- public void update() {
- XModelObject installedProcess = (XModelObject)getData();
- if(installedProcess == null) return;
-
- }
-
- /**
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated NOT
- */
public void dispose() {
XModelObject installedProcess = (XModelObject)getData();
if(installedProcess == null) return;
@@ -238,17 +314,16 @@
if(event.kind() == XModelTreeEvent.CHILD_ADDED) {
XModelObject added = (XModelObject)event.getInfo();
if(target == installedProcess) {
- addItem(added);
- addItemLinks(added);
+ childAdded(added);
} else {
PagesElement item = findElement(target);
- //TODO
+ item.childAdded(added);
}
} else if(event.kind() == XModelTreeEvent.CHILD_REMOVED) {
if(target == installedProcess) {
PagesElement removed = findElement(event.getInfo());
if(removed != null) {
- elementsByPath.remove(event.getInfo());
+
Link[] ls = removed.getOutputLinks().toArray(new Link[0]);
for (int i = 0; i < ls.length; i++) {
ls[i].setFromElement(null);
@@ -261,11 +336,19 @@
}
getChildren().remove(removed);
}
- } else {
+ } else if(findElement(target) != null) {
+ Link removed = findLink(event.getInfo());
+ if(removed != null) {
+ removed.setToElement(null);
+ removed.setFromElement(null);
+ linksByPath.remove(event.getInfo());
+ }
}
+
+ unbind(event.getInfo().toString());
}
- update();
+
}
}