|
@@ -1,5 +1,6 @@
|
|
|
package mdd.client;
|
|
|
|
|
|
+import javafx.collections.ObservableList;
|
|
|
import javafx.scene.Group;
|
|
|
import javafx.scene.Node;
|
|
|
import javafx.scene.input.*;
|
|
@@ -47,8 +48,9 @@ public class Processor extends Module{
|
|
|
for (Object ins : (JSONArray) jobj.get("inputs")){
|
|
|
JSONObject jin = (JSONObject) ins;
|
|
|
//TODO update prefix
|
|
|
- Input in = getModule(((JSONArray)jin.get("prefix")).get(1).toString()).getInput(jin.get("name").toString()+jin.get("appendix").toString());
|
|
|
- Output out = getModule(((JSONArray)jout.get("prefix")).get(1).toString()).getOutput(jout.get("name").toString()+jout.get("appendix").toString());
|
|
|
+ int lsize = ((JSONArray)jin.get("prefix")).size()-1;
|
|
|
+ Input in = getModule(((JSONArray)jin.get("prefix")).get(lsize).toString()).getInput(jin.get("name").toString()+jin.get("appendix").toString());
|
|
|
+ Output out = getModule(((JSONArray)jout.get("prefix")).get(lsize).toString()).getOutput(jout.get("name").toString()+jout.get("appendix").toString());
|
|
|
connections.getChildren().add(new Connection(in, out));
|
|
|
}
|
|
|
}
|
|
@@ -239,8 +241,9 @@ public class Processor extends Module{
|
|
|
System.out.println(jobj.toString());
|
|
|
JSONObject jin = (JSONObject)jobj.get("input");
|
|
|
JSONObject jout = (JSONObject)jobj.get("output");
|
|
|
- Input in = getModule(((JSONArray)jin.get("prefix")).get(0).toString()).getInput(jin.get("name").toString()+jin.get("appendix").toString());
|
|
|
- Output out = getModule(((JSONArray)jout.get("prefix")).get(0).toString()).getOutput(jout.get("name").toString()+jout.get("appendix").toString());
|
|
|
+ int lsize = ((JSONArray)jin.get("prefix")).size()-1;
|
|
|
+ Input in = getModule(((JSONArray)jin.get("prefix")).get(lsize).toString()).getInput(jin.get("name").toString()+jin.get("appendix").toString());
|
|
|
+ Output out = getModule(((JSONArray)jout.get("prefix")).get(lsize).toString()).getOutput(jout.get("name").toString()+jout.get("appendix").toString());
|
|
|
if (in != null && out != null) {
|
|
|
if (in.isConnected()) {
|
|
|
for (int i = 0; i < connections.getChildren().size(); ++i) {
|
|
@@ -263,11 +266,76 @@ public class Processor extends Module{
|
|
|
break;
|
|
|
}
|
|
|
break;
|
|
|
- }
|
|
|
+ case "remove":
|
|
|
+ switch (jobj.get("type").toString()) {
|
|
|
+ case "module":
|
|
|
+ ObservableList gmodule = modules.getChildren();
|
|
|
+ for (int i = 0; i < gmodule.size(); ++i) {
|
|
|
+ JSONObject json = ((Module) gmodule.get(i)).getJSONIdentifier();
|
|
|
+ if (json.equals(jobj)) {
|
|
|
+ ObservableList gin = ((Module) gmodule.get(i)).inputs.getChildren();
|
|
|
+ for (int j = 0; j < gin.size(); ++j){
|
|
|
+ Input in = (Input)gin.get(j);
|
|
|
+ if (in.isConnected()){
|
|
|
+ ObservableList gcon = connections.getChildren();
|
|
|
+ for (int k = 0; k < gcon.size(); ++k){
|
|
|
+ Connection con = (Connection)gcon.get(k);
|
|
|
+ if (con.in == in){
|
|
|
+ try {
|
|
|
+ con.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ //e.printStackTrace();
|
|
|
+ }
|
|
|
+ gcon.remove(k);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ObservableList gout = ((Module) gmodule.get(i)).outputs.getChildren();
|
|
|
+ for (int j = 0; j < gout.size(); ++j){
|
|
|
+ Output out = (Output)gout.get(j);
|
|
|
+ if (out.isConnected()){
|
|
|
+ ObservableList gcon = connections.getChildren();
|
|
|
+ for (int k = 0; k < gcon.size(); ++k){
|
|
|
+ Connection con = (Connection)gcon.get(k);
|
|
|
+ if (con.out == out){
|
|
|
+ try {
|
|
|
+ con.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ //e.printStackTrace();
|
|
|
+ }
|
|
|
+ gcon.remove(k);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ ((Module) gmodule.get(i)).close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ //e.printStackTrace();
|
|
|
+ }
|
|
|
+ modules.getChildren().remove(i);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "processor":
|
|
|
+ modules.getChildren().add(new Processor(jobj));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
}else if(event.equals("delete")){
|
|
|
if (args.get("prefix").equals(getAsPrefix())){
|
|
|
- System.out.println("[Processor] delete");
|
|
|
//TODO delete
|
|
|
+ JSONObject jmsg = new JSONObject();
|
|
|
+ jmsg.put("operation", "remove");
|
|
|
+ JSONObject jargs = new JSONObject();
|
|
|
+ jargs.put("subject", getJSONIdentifier());
|
|
|
+ jargs.put("object", args);
|
|
|
+ jmsg.put("args", jargs);
|
|
|
+ _eventHandler.publishEvent(10,"try", jmsg);
|
|
|
}
|
|
|
}
|
|
|
|