|
@@ -46,16 +46,14 @@ public class ClipboardController {
|
|
|
|
|
|
public void copy(CpsUpperNode upperNode) {
|
|
|
|
|
|
- ArrayList<AbstractCpsObject> foundObj = (upperNode == null ? model.getObjectsOnCanvas() : upperNode.getNodes());
|
|
|
- ArrayList<CpsEdge> foundedge = (upperNode == null ? model.getEdgesOnCanvas() : upperNode.getNodeEdges());
|
|
|
-
|
|
|
JsonObject file = new JsonObject();
|
|
|
ArrayDeque<AbstractCpsObject> queue = new ArrayDeque<>();
|
|
|
- HashMap<Integer, Integer> idMap = new HashMap<>();
|
|
|
AbstractCpsObject u = null;
|
|
|
|
|
|
store.initNumeration();
|
|
|
|
|
|
+ file.add("SAV", new JsonPrimitive((upperNode == null ? "CVS" : "" + upperNode.getID())));
|
|
|
+
|
|
|
for (AbstractCpsObject abs : model.getSelectedCpsObjects()) {
|
|
|
queue.add(abs);
|
|
|
}
|
|
@@ -65,8 +63,9 @@ public class ClipboardController {
|
|
|
u = queue.pop();
|
|
|
|
|
|
String key = "CVSOBJECT" + store.getNumerator(NUMTYPE.OBJECT);
|
|
|
- idMapping(u, idMap);
|
|
|
file.add(key, gson.toJsonTree(u, AbstractCpsObject.class));
|
|
|
+ edgeToJson(EDGETYPE.CONNECTION, file, u.getID(), u.getConnections());
|
|
|
+
|
|
|
if (u instanceof HolonObject)
|
|
|
store.elementsToJson(TYPE.CANVAS, file, u);
|
|
|
|
|
@@ -78,13 +77,14 @@ public class ClipboardController {
|
|
|
for (AbstractCpsObject adjacent : ((CpsUpperNode) u).getNodes()) {
|
|
|
queue.add(adjacent);
|
|
|
}
|
|
|
+ edgeToJson(EDGETYPE.NODE, file, u.getID(), ((CpsUpperNode) u).getNodeEdges());
|
|
|
+ edgeToJson(EDGETYPE.OLD, file, u.getID(), ((CpsUpperNode) u).getOldEdges());
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- for (CpsEdge edge : foundedge) {
|
|
|
- if(model.getSelectedCpsObjects().contains(edge.getA()) && model.getSelectedCpsObjects().contains(edge.getB()))
|
|
|
- return;
|
|
|
- }
|
|
|
+ if (upperNode == null)
|
|
|
+ edgeToJson(EDGETYPE.CANVAS, file, 0, model.getEdgesOnCanvas());
|
|
|
+ else
|
|
|
+ edgeToJson(EDGETYPE.NODE, file, upperNode.getID(), model.getEdgesOnCanvas());
|
|
|
|
|
|
StringSelection selection = new StringSelection(gson.toJson(file));
|
|
|
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
|
@@ -92,56 +92,73 @@ public class ClipboardController {
|
|
|
|
|
|
}
|
|
|
|
|
|
- private void idMapping(AbstractCpsObject u, HashMap<Integer, Integer> idMap) {
|
|
|
- // TODO Auto-generated method stub
|
|
|
- int id = u.getID();
|
|
|
- u.setID(IdCounter.nextId());
|
|
|
- idMap.put(id, u.getID());
|
|
|
- }
|
|
|
-
|
|
|
public void paste() {
|
|
|
|
|
|
}
|
|
|
|
|
|
- private void edgeToJson(EDGETYPE type, JsonObject file, int id, CpsEdge edge) {
|
|
|
+ public void edgeToJson(EDGETYPE type, JsonObject file, int id, ArrayList<CpsEdge> arr) {
|
|
|
// TODO Auto-generated method stub
|
|
|
String k = null;
|
|
|
boolean b = false;
|
|
|
JsonObject temp = new JsonObject();
|
|
|
|
|
|
+ for (CpsEdge edge : arr) {
|
|
|
+ if (model.getClipboradObjects().contains(edge.getA())
|
|
|
+ && model.getClipboradObjects().contains(edge.getB())) {
|
|
|
+ // add properties and only the ids from a and b
|
|
|
+ temp.add("properties", gson.toJsonTree(edge));
|
|
|
+ temp.add("A", new JsonPrimitive(edge.getA().getID()));
|
|
|
+ temp.add("B", new JsonPrimitive(edge.getB().getID()));
|
|
|
+
|
|
|
+ // Key and occasionally the id of Uppernode
|
|
|
+ switch (type) {
|
|
|
+ case CANVAS:
|
|
|
+ k = "CVSEDGE" + store.getNumerator(NUMTYPE.EDGE);
|
|
|
+ break;
|
|
|
+ case CONNECTION:
|
|
|
+ k = "CONNEDGE" + store.getNumerator(NUMTYPE.CONNECTION);
|
|
|
+ break;
|
|
|
+ case NODE:
|
|
|
+ temp.add("ID", new JsonPrimitive(id));
|
|
|
+ k = "NODEEDGE" + store.getNumerator(NUMTYPE.NODEEDGE);
|
|
|
+ break;
|
|
|
+ case OLD:
|
|
|
+ temp.add("ID", new JsonPrimitive(id));
|
|
|
+ k = "OLDEDGE" + store.getNumerator(NUMTYPE.OLDEDGE);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ // lookup if the CVS, NODE or OLDEDGE are also connections
|
|
|
+ if (edge.getA().getConnections().contains(edge) && edge.getA().getConnections().contains(edge)
|
|
|
+ && !type.equals(EDGETYPE.CONNECTION))
|
|
|
+ b = true;
|
|
|
+ temp.add("connection", new JsonPrimitive(b));
|
|
|
+ file.add(k, gson.toJsonTree(temp));
|
|
|
+ temp = new JsonObject();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void getObjectsInDepth() {
|
|
|
+ model.setClipboradObjects(new ArrayList<>());
|
|
|
+ for (AbstractCpsObject obj : model.getSelectedCpsObjects()) {
|
|
|
+ clipboadDepth(obj);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- // add properties and only the ids from a and b
|
|
|
- temp.add("properties", gson.toJsonTree(edge));
|
|
|
- temp.add("A", new JsonPrimitive(edge.getA().getID()));
|
|
|
- temp.add("B", new JsonPrimitive(edge.getB().getID()));
|
|
|
-
|
|
|
- // Key and occasionally the id of Uppernode
|
|
|
- switch (type) {
|
|
|
- case CANVAS:
|
|
|
- k = "CVSEDGE" + store.getNumerator(NUMTYPE.EDGE);
|
|
|
- break;
|
|
|
- case CONNECTION:
|
|
|
- k = "CONNEDGE" + store.getNumerator(NUMTYPE.CONNECTION);
|
|
|
- break;
|
|
|
- case NODE:
|
|
|
- temp.add("ID", new JsonPrimitive(id));
|
|
|
- k = "NODEEDGE" + store.getNumerator(NUMTYPE.NODEEDGE);
|
|
|
- break;
|
|
|
- case OLD:
|
|
|
- temp.add("ID", new JsonPrimitive(id));
|
|
|
- k = "OLDEDGE" + store.getNumerator(NUMTYPE.OLDEDGE);
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
+ public void clipboadDepth(AbstractCpsObject obj) {
|
|
|
+ if (!(obj instanceof CpsUpperNode)) {
|
|
|
+ model.getClipboradObjects().add(obj);
|
|
|
+ return;
|
|
|
+ } else {
|
|
|
+ model.getClipboradObjects().add(obj);
|
|
|
+ for (AbstractCpsObject abs : ((CpsUpperNode) obj).getNodes()) {
|
|
|
+ clipboadDepth(abs);
|
|
|
}
|
|
|
- // lookup if the CVS, NODE or OLDEDGE are also connections
|
|
|
- if (edge.getA().getConnections().contains(edge) && edge.getA().getConnections().contains(edge)
|
|
|
- && !type.equals(EDGETYPE.CANVAS))
|
|
|
- b = true;
|
|
|
- temp.add("connection", new JsonPrimitive(b));
|
|
|
- file.add(k, gson.toJsonTree(temp));
|
|
|
- temp = new JsonObject();
|
|
|
-
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private void initGson() {
|