MappingGraphManager.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. package de.tu_darmstadt.informatik.tk.scopviz.graphs;
  2. import java.util.Collection;
  3. import java.util.HashMap;
  4. import java.util.LinkedList;
  5. import org.graphstream.algorithm.Toolkit;
  6. import org.graphstream.graph.Edge;
  7. import org.graphstream.graph.Node;
  8. import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
  9. import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
  10. import de.tu_darmstadt.informatik.tk.scopviz.ui.MetricboxManager;
  11. /**
  12. * Class extending GraphManager. Offers the possibility to merge an underlay and
  13. * an operator graph.
  14. *
  15. *
  16. * @author Matthias Wilhelm
  17. *
  18. */
  19. public class MappingGraphManager extends GraphManager implements EdgeCreatedListener, NodeCreatedListener {
  20. public static final String UNDERLAY = "underlay";
  21. public static final String OPERATOR = "operator";
  22. public static final String ATTRIBUTE_KEY_PROCESS_NEED = "process-need";
  23. public static final String ATTRIBUTE_KEY_PROCESS_USE = "process-use";
  24. public static final String ATTRIBUTE_KEY_PROCESS_MAX = "process-max";
  25. public static final String ATTRIBUTE_KEY_MAPPING = "mapping";
  26. public static final String ATTRIBUTE_KEY_MAPPING_PARENT = "mapping-parent";
  27. public static final String ATTRIBUTE_KEY_MAPPING_PARENT_ID = "mapping-parent-id";
  28. public static final String UI_CLASS_MAPPING = "mapping";
  29. private static final double UNDERLAYER_MOVE_Y = 0;
  30. private static final double OPERATOR_MOVE_Y = 1.5;
  31. private static final double SCALE_WIDTH = 2;
  32. private static final double SCALE_HEIGHT = 1;
  33. /** Variables to keep track of new Nodes in the underlay graph */
  34. private boolean underlayNodesChanged = false;
  35. /** Variables to keep track of new Nodes in the operator graph */
  36. private boolean operatorNodesChanged = false;
  37. /** References to the underlay graph */
  38. GraphManager underlay;
  39. /** References to the operator graph */
  40. GraphManager operator;
  41. /** Map to store the id of the underlay and operator graphs IDs */
  42. HashMap<String, String> parentsID;
  43. /**
  44. * Creates a new manager for an empty graph. there is no need to check for
  45. * unique ID's for nodes and edges.
  46. *
  47. * @param graph
  48. * assumes a empty graph
  49. * @param underlay
  50. * the underlay graph
  51. * @param operator
  52. * the operator graph
  53. */
  54. public MappingGraphManager(MyGraph graph, GraphManager underlay, GraphManager operator) {
  55. super(graph);
  56. underlay.deselect();
  57. operator.deselect();
  58. this.underlay = underlay;
  59. this.operator = operator;
  60. parentsID = new HashMap<>();
  61. parentsID.put(UNDERLAY, underlay.getGraph().getId());
  62. parentsID.put(OPERATOR, operator.getGraph().getId());
  63. Debug.out("Created a new Mapping");
  64. graph.addSubGraph(underlay.getGraph());
  65. graph.addSubGraph(operator.getGraph());
  66. mergeGraph(underlay, UNDERLAY, UNDERLAYER_MOVE_Y);
  67. mergeGraph(operator, OPERATOR, OPERATOR_MOVE_Y);
  68. autoMapSourcesAndSinks(underlay, operator);
  69. view.getCamera().resetView();
  70. }
  71. /**
  72. *
  73. * @param g
  74. */
  75. public void loadGraph(MyGraph g) {
  76. // reset used capacity to 0 for every procEnabled node
  77. for (Node n : this.g.getNodeSet()) {
  78. if (hasClass(n, UI_CLASS_PROCESSING_ENABLED)) {
  79. resetCapacity(n);
  80. }
  81. }
  82. // recreates mapping edges from saved Attributes
  83. autoMapLoadedEdgeAttributes(underlay, operator);
  84. // recreates every mapping edge to properly calculate capacities
  85. for (Edge e : g.getEdgeSet()) {
  86. if (e.getAttribute(ATTRIBUTE_KEY_MAPPING) != null && (boolean) e.getAttribute(ATTRIBUTE_KEY_MAPPING)) {
  87. createEdge(e.getSourceNode().getId(), e.getTargetNode().getId());
  88. }
  89. }
  90. }
  91. /**
  92. * Adds all nodes and edges of the given graph, adds a prefix to the ID of
  93. * every node and edge and offsets the normalized coordinates in y
  94. * direction.
  95. *
  96. * @param gm
  97. * the graph to be added
  98. * @param idPrefix
  99. * the prefix for the ID of every node and edge
  100. * @param moveY
  101. * the offset of the y coordinate
  102. */
  103. private void mergeGraph(GraphManager gm, String idPrefix, double moveY) {
  104. mergeNodes(gm, idPrefix, moveY);
  105. // Debug only
  106. int i = 0;
  107. for (Edge edge : gm.getGraph().getEdgeSet()) {
  108. addEdge(edge, idPrefix);
  109. // Debug only
  110. i++;
  111. }
  112. Debug.out("added " + i + " Edge" + (i == 1 ? "" : "s") + " from \"" + idPrefix + "\"");
  113. }
  114. /**
  115. * Adds all nodes of the given graph, adds a prefix to the ID of every node
  116. * and offsets the normalized coordinates in y direction.
  117. *
  118. * @param gm
  119. * the graph to be added
  120. * @param idPrefix
  121. * the prefix for the ID of every node
  122. * @param moveY
  123. * the offset of the y coordinate
  124. */
  125. private void mergeNodes(GraphManager gm, String idPrefix, double moveY) {
  126. // precalculate scale and offset to normalize x coordinates
  127. double maxX = gm.getMaxX();
  128. double minX = gm.getMinX();
  129. double scaleX = SCALE_WIDTH / (maxX - minX);
  130. double addX = -minX * scaleX;
  131. if (maxX == minX) {
  132. scaleX = 0;
  133. addX = -SCALE_WIDTH / 2;
  134. } else {
  135. scaleX = SCALE_WIDTH / (maxX - minX);
  136. addX = -minX * scaleX;
  137. }
  138. // precalculate scale and offset to normalize y coordinates
  139. double maxY = gm.getMaxY();
  140. double minY = gm.getMinY();
  141. double scaleY;
  142. double addY;
  143. if (maxY == minY) {
  144. scaleY = 0;
  145. addY = SCALE_HEIGHT / 2 + moveY;
  146. } else {
  147. scaleY = SCALE_HEIGHT / (maxY - minY);
  148. addY = -minY * scaleY + moveY;
  149. }
  150. // Debug only
  151. int i = 0;
  152. // loops through all nodes, adds them if they don't exist already and
  153. // normalizes their coordinates
  154. for (Node node : gm.getGraph().getNodeSet()) {
  155. // add node if it doesn't exist
  156. Node newNode = getGraph().getNode(idPrefix + node.getId());
  157. if (newNode == null) {
  158. addNode(node, idPrefix);
  159. newNode = getGraph().getNode(idPrefix + node.getId());
  160. // Debug only
  161. i++;
  162. }
  163. // normalize coordinates
  164. double[] n = Toolkit.nodePosition(node);
  165. double cX = n[0];
  166. double x = cX * scaleX + addX;
  167. double cY = n[1];
  168. double y = cY * scaleY + addY;
  169. newNode.changeAttribute("x", x);
  170. newNode.changeAttribute("y", y);
  171. if (hasClass(newNode, UI_CLASS_PROCESSING_ENABLED)) {
  172. initCapacity(newNode);
  173. }
  174. }
  175. Debug.out("added " + i + " Node" + (i == 1 ? "" : "s") + " from \"" + idPrefix + "\"");
  176. }
  177. /**
  178. * Gets invoked by the GraphDisplayManager every time the mapping layer is
  179. * loaded. Checks whether nodes have been added to the parent graphs
  180. */
  181. public void activated() {
  182. if (underlayNodesChanged) {
  183. mergeNodes(underlay, UNDERLAY, UNDERLAYER_MOVE_Y);
  184. underlayNodesChanged = false;
  185. }
  186. if (operatorNodesChanged) {
  187. mergeNodes(operator, OPERATOR, OPERATOR_MOVE_Y);
  188. operatorNodesChanged = false;
  189. }
  190. }
  191. /**
  192. * Checks whether the given graph is underlay or operator graph to this
  193. * object or not.
  194. *
  195. * @param gm
  196. * the graph to check
  197. * @return true if the given graph is underlay or operator graph to this
  198. * graph. false otherwise
  199. */
  200. public boolean hasGraphManagerAsParent(GraphManager gm) {
  201. return (underlay.getGraph().getId().equals(gm.getGraph().getId()))
  202. || (operator.getGraph().getId().equals(gm.getGraph().getId()));
  203. }
  204. /**
  205. * Adds a <b>Copy</b> of the given Edge to the graph. The Copy retains the
  206. * ID and all attributes but adds the ID prefix in front of the all old IDs.
  207. *
  208. * @param e
  209. * the Edge to be added to the graph
  210. * @param idPrefix
  211. * the String to be added as prefix to the ID
  212. */
  213. private void addEdge(Edge e, String idPrefix) {
  214. HashMap<String, Object> attributes = new HashMap<>();
  215. for (String s : e.getAttributeKeySet()) {
  216. attributes.put(s, e.getAttribute(s));
  217. }
  218. attributes.put(ATTRIBUTE_KEY_MAPPING, false);
  219. attributes.put(ATTRIBUTE_KEY_MAPPING_PARENT, idPrefix);
  220. attributes.put(ATTRIBUTE_KEY_MAPPING_PARENT_ID, parentsID.get(idPrefix));
  221. g.addEdge(idPrefix + e.getId(), idPrefix + e.getSourceNode().getId(), idPrefix + e.getTargetNode().getId(),
  222. e.isDirected());
  223. g.getEdge(idPrefix + e.getId()).addAttributes(attributes);
  224. }
  225. @Override
  226. public void addNode(Node n) {
  227. // This function mustn't be called.
  228. Debug.out("Someone called addNode(Node n) with a MappingGraphManager");
  229. }
  230. /**
  231. * Adds a <b>Copy</b> of the given Node to the graph. The Copy retains the
  232. * ID and all attributes but adds the ID prefix in front of the old ID.
  233. *
  234. * @param n
  235. * the Node to be added to the graph
  236. * @param idPrefix
  237. * the String to be added as prefix to the ID
  238. */
  239. private void addNode(Node n, String idPrefix) {
  240. HashMap<String, Object> attributes = new HashMap<>();
  241. for (String s : n.getAttributeKeySet()) {
  242. attributes.put(s, n.getAttribute(s));
  243. }
  244. attributes.put(ATTRIBUTE_KEY_MAPPING_PARENT, idPrefix);
  245. attributes.put(ATTRIBUTE_KEY_MAPPING_PARENT_ID, parentsID.get(idPrefix));
  246. g.addNode(idPrefix + n.getId());
  247. g.getNode(idPrefix + n.getId()).addAttributes(attributes);
  248. }
  249. @Override
  250. public void nodeCreated(Node n, String graphID) {
  251. if (graphID.equals(underlay.getGraph().getId()))
  252. underlayNodesChanged = true;
  253. else if (graphID.equals(operator.getGraph().getId()))
  254. operatorNodesChanged = true;
  255. }
  256. @Override
  257. public void edgeCreated(Edge e, String graphID) {
  258. if (graphID.equals(underlay.getGraph().getId()))
  259. addEdge(e, UNDERLAY);
  260. else if (graphID.equals(operator.getGraph().getId()))
  261. addEdge(e, OPERATOR);
  262. }
  263. @Override
  264. public void createEdges(String id) {
  265. super.createEdges(id);
  266. if (lastClickedID != null) {
  267. Double need = g.getNode(lastClickedID).getAttribute(ATTRIBUTE_KEY_PROCESS_NEED);
  268. if (need != null)
  269. for (Node n : g.getNodeSet())
  270. if (hasClass(n, UI_CLASS_PROCESSING_ENABLED))
  271. showExpectedCapacity(n, need);
  272. }
  273. // erstmal drin lassen, sollte von deselectNodesAfterEdgeCreation
  274. // gehandelt werden
  275. /*
  276. * else { for (Node n : g.getNodeSet()) if (hasClass(n,
  277. * UI_CLASS_PROCESSING_ENABLED)) showExpectedCapacity(n, 0); }
  278. */
  279. }
  280. @Override
  281. protected void deselectNodesAfterEdgeCreation(String nodeID) {
  282. super.deselectNodesAfterEdgeCreation(nodeID);
  283. for (Node n : g.getNodeSet())
  284. if (hasClass(n, UI_CLASS_PROCESSING_ENABLED))
  285. showExpectedCapacity(n, 0);
  286. }
  287. /**
  288. * checks whether the Node can handle the load first.<br/>
  289. * creates a edge between to nodes
  290. */
  291. @Override
  292. public boolean createEdge(String to, String from) {
  293. Node fromNode = getGraph().getNode(from);
  294. Node toNode = getGraph().getNode(to);
  295. if (fromNode.hasEdgeBetween(to))
  296. return false;
  297. for (Edge e : fromNode.getEdgeSet()) {
  298. Boolean mapped = e.getAttribute("mapping");
  299. if (mapped != null && mapped)
  300. return false;
  301. }
  302. String fromParent = fromNode.getAttribute(ATTRIBUTE_KEY_MAPPING_PARENT);
  303. String toParent = toNode.getAttribute(ATTRIBUTE_KEY_MAPPING_PARENT);
  304. if (fromParent == null || toParent == null)
  305. return false;
  306. if (fromParent.equals(toParent)) {
  307. deselectNodesAfterEdgeCreation(lastClickedID);
  308. /*
  309. * lastClickedID = to; selectNodeForEdgeCreation(lastClickedID);
  310. */
  311. return false;
  312. }
  313. String newID = Main.getInstance().getUnusedID();
  314. Edge e;
  315. Node underlayNode;
  316. Node operatorNode;
  317. if (fromParent.equals(UNDERLAY)) {
  318. underlayNode = fromNode;
  319. operatorNode = toNode;
  320. } else if (toParent.equals(UNDERLAY)) {
  321. underlayNode = toNode;
  322. operatorNode = fromNode;
  323. } else
  324. return false;
  325. // check if processing enabled node
  326. if (!hasClass(underlayNode, UI_CLASS_PROCESSING_ENABLED))
  327. return false;
  328. // check and update capacity
  329. if (!addMapping(underlayNode, operatorNode)) {
  330. Debug.out("Could not place Mapping Edge due to insufficient capacity!", 2);
  331. return false;
  332. }
  333. e = getGraph().addEdge(newID, operatorNode, underlayNode, true);
  334. Debug.out("Created an directed edge with Id " + newID + " from " + operatorNode + " to " + underlayNode);
  335. // adds an Attribute for loading Edges from file
  336. GraphHelper.propagateAttribute(this.g, underlayNode, "mappingEdge", newID);
  337. underlay.getGraph().getNode(underlayNode.getId().substring(8)).addAttribute("mappingEdge", newID);
  338. GraphHelper.propagateAttribute(this.g, operatorNode, "mappingEdge", newID);
  339. operator.getGraph().getNode(operatorNode.getId().substring(8)).addAttribute("mappingEdge", newID);
  340. e.addAttribute("ui.class", UI_CLASS_MAPPING);
  341. e.addAttribute(ATTRIBUTE_KEY_MAPPING, true);
  342. selectEdge(newID);
  343. MetricboxManager.updateMetrics();
  344. return true;
  345. }
  346. /**
  347. * Initialize the pie chart for the given node. It uses the process_use and
  348. * process_max values of the given node. If process_max is null or 0 it
  349. * won't do anything. If process_use is null it will be initialized to 0.
  350. *
  351. * @param underlayNode
  352. * The Node for which the pie chart should be initialized
  353. */
  354. private void initCapacity(Node underlayNode) {
  355. Double used = underlayNode.getAttribute(ATTRIBUTE_KEY_PROCESS_USE);
  356. Double max = underlayNode.getAttribute(ATTRIBUTE_KEY_PROCESS_MAX);
  357. if (max == null || max == 0)
  358. return;
  359. if (used == null)
  360. used = new Double(0);
  361. double[] pieValues = { used / max, 0, 1 - used / max };
  362. underlayNode.setAttribute("ui.pie-values", pieValues);
  363. underlayNode.setAttribute(ATTRIBUTE_KEY_PROCESS_USE, used);
  364. }
  365. /**
  366. * Resets the pie chart for the given node. If process_max is null or 0 it
  367. * won't display anything. Process_use set to 0.
  368. *
  369. * @param underlayNode
  370. * The Node for which the pie chart should be initialized
  371. */
  372. private void resetCapacity(Node underlayNode) {
  373. Double used = new Double(0);
  374. underlayNode.setAttribute(ATTRIBUTE_KEY_PROCESS_USE, used);
  375. Double max = underlayNode.getAttribute(ATTRIBUTE_KEY_PROCESS_MAX);
  376. if (max == null || max == 0)
  377. return;
  378. double[] pieValues = { 0, 0, 1 };
  379. underlayNode.setAttribute("ui.pie-values", pieValues);
  380. }
  381. /**
  382. * Checks and updates the Capacity for a procEn node. Tries to map the given
  383. * operatorNode to the given underlayNode.
  384. *
  385. * @param underlayNode
  386. * The underlayNode the operatorNode gets mapped to
  387. * @param operatorNode
  388. * The operatorNode which gets mapped
  389. * @return true if the mapping was successful. false otherwise.
  390. */
  391. private boolean addMapping(Node underlayNode, Node operatorNode) {
  392. Double needed = operatorNode.getAttribute(ATTRIBUTE_KEY_PROCESS_NEED);
  393. if (needed == null)
  394. return true;
  395. return changeCapacity(underlayNode, needed);
  396. }
  397. /**
  398. * Checks and updates the Capacity for a procEn node. Tries to unmap the
  399. * given operatorNode to the given underlayNode.
  400. *
  401. * @param underlayNode
  402. * The underlayNode the operatorNode gets mapped to
  403. * @param operatorNode
  404. * The operatorNode which gets mapped
  405. * @return true if the mapping was successful. false otherwise.
  406. */
  407. private boolean removeMapping(Node underlayNode, Node operatorNode) {
  408. Double needed = operatorNode.getAttribute(ATTRIBUTE_KEY_PROCESS_NEED);
  409. if (needed == null)
  410. return true;
  411. return changeCapacity(underlayNode, -needed);
  412. }
  413. /**
  414. * Checks and updates the Capacity for a procEn node. Tries to map the
  415. * capacity to the given underlayNode.
  416. *
  417. * @param underlayNode
  418. * The underlayNode which capacity gets updated
  419. * @param capacity
  420. * The capacity. may be positive or negative
  421. * @return true if the capacity change was successful. false otherwise.
  422. */
  423. private boolean changeCapacity(Node underlayNode, double capacity) {
  424. Double needed = capacity;
  425. Double used = underlayNode.getAttribute(ATTRIBUTE_KEY_PROCESS_USE);
  426. Double max = underlayNode.getAttribute(ATTRIBUTE_KEY_PROCESS_MAX);
  427. if (needed == 0)
  428. return true;
  429. if (max == null || max == 0)
  430. if (needed > 0)
  431. return false;
  432. if (used == null)
  433. used = new Double(0);
  434. if (used + needed > max)
  435. return false;
  436. used += needed;
  437. double[] pieValues = { used / max, 0, 1 - used / max };
  438. underlayNode.setAttribute("ui.pie-values", pieValues);
  439. underlayNode.setAttribute(ATTRIBUTE_KEY_PROCESS_USE, used);
  440. return true;
  441. }
  442. /**
  443. * Displays the capacity change to the node if the needed Cost is applied.
  444. *
  445. * @param underlayNode
  446. * The node which gets updated
  447. * @param need
  448. * the capacity change
  449. */
  450. private void showExpectedCapacity(Node underlayNode, double need) {
  451. Double used = underlayNode.getAttribute(ATTRIBUTE_KEY_PROCESS_USE);
  452. Double max = underlayNode.getAttribute(ATTRIBUTE_KEY_PROCESS_MAX);
  453. if (max == null || max == 0)
  454. return;
  455. if (used == null)
  456. used = new Double(0);
  457. double[] pieValues = { used / max, 0, 1 - used / max, 0 };
  458. if (need + used > max) {
  459. pieValues[3] = pieValues[2];
  460. pieValues[2] = 0;
  461. } else {
  462. pieValues[1] = need / max;
  463. pieValues[2] -= need / max;
  464. }
  465. underlayNode.setAttribute("ui.pie-values", pieValues);
  466. underlayNode.setAttribute(ATTRIBUTE_KEY_PROCESS_USE, used);
  467. }
  468. @Override
  469. protected boolean selectNodeForEdgeCreation(String nodeID) {
  470. Node n = g.getNode(nodeID);
  471. String parent = n.getAttribute(ATTRIBUTE_KEY_MAPPING_PARENT);
  472. if (parent == null)
  473. return false;
  474. if (parent.equals(OPERATOR)) {
  475. for (Edge e : n.getEdgeSet()) {
  476. Boolean isMapped = e.getAttribute(ATTRIBUTE_KEY_MAPPING);
  477. if (isMapped != null && isMapped)
  478. return false;
  479. }
  480. return super.selectNodeForEdgeCreation(nodeID);
  481. }
  482. if (hasClass(n, UI_CLASS_PROCESSING_ENABLED))
  483. return super.selectNodeForEdgeCreation(nodeID);
  484. return false;
  485. }
  486. @Override
  487. public void deleteEdge(final String id) {
  488. Edge e = g.getEdge(id);
  489. if ((boolean) e.getAttribute(ATTRIBUTE_KEY_MAPPING)) {
  490. Node operatorNode = e.getSourceNode();
  491. Node underlayNode = e.getTargetNode();
  492. // delete mapping attriute
  493. GraphHelper.propagateAttribute(this.g, underlayNode, "mappingEdge", null);
  494. underlay.getGraph().getNode(underlayNode.getId().substring(8)).removeAttribute("mappingEdge");
  495. GraphHelper.propagateAttribute(this.g, operatorNode, "mappingEdge", null);
  496. operator.getGraph().getNode(operatorNode.getId().substring(8)).removeAttribute("mappingEdge");
  497. removeMapping(underlayNode, operatorNode);
  498. super.deleteEdge(id);
  499. }
  500. MetricboxManager.updateMetrics();
  501. }
  502. @Override
  503. public void deleteNode(String id) {
  504. Debug.out("default delete Node prevented");
  505. }
  506. @Override
  507. public void undelete() {
  508. super.undelete();
  509. for (Edge e : deletedEdges) {
  510. if ((boolean) e.getAttribute(ATTRIBUTE_KEY_MAPPING))
  511. changeCapacity(e.getTargetNode(), e.getSourceNode().getAttribute(ATTRIBUTE_KEY_PROCESS_NEED));
  512. }
  513. }
  514. private void autoMapSourcesAndSinks(GraphManager underlay, GraphManager operator) {
  515. // TODO Andere Farbe für automatisch erstellte Mappingkanten von Quellen
  516. // und Senken
  517. for (Node operatorNode : getOperatorNodeSet()) {
  518. if (operatorNode.getAttribute("typeofNode").toString().equals("source")) {
  519. for (Node underlayNode : getUnderlayNodeSet()) {
  520. if (operatorNode.getAttribute("identifier") != null && operatorNode.getAttribute("identifier")
  521. .equals(underlayNode.getAttribute("identifier"))) {
  522. String newID = Main.getInstance().getUnusedID(this);
  523. Edge e = getGraph().addEdge(newID, operatorNode, underlayNode, true);
  524. Debug.out("Created an directed edge with Id " + newID + " from " + operatorNode + " to "
  525. + underlayNode);
  526. e.addAttribute("ui.class", UI_CLASS_MAPPING);
  527. e.addAttribute(ATTRIBUTE_KEY_MAPPING, true);
  528. }
  529. }
  530. } else if (operatorNode.getAttribute("typeofNode").equals("sink")) {
  531. for (Node underlayNode : getUnderlayNodeSet()) {
  532. String identifier = operatorNode.getAttribute("identifier");
  533. if (identifier != null && identifier.equals(underlayNode.getAttribute("identifier"))) {
  534. String newID = Main.getInstance().getUnusedID(this);
  535. Edge e = getGraph().addEdge(newID, operatorNode, underlayNode, true);
  536. Debug.out("Created an directed edge with Id " + newID + " from " + operatorNode + " to "
  537. + underlayNode);
  538. e.addAttribute("ui.class", UI_CLASS_MAPPING);
  539. e.addAttribute(ATTRIBUTE_KEY_MAPPING, true);
  540. }
  541. }
  542. }
  543. }
  544. }
  545. private Collection<Node> getOperatorNodeSet() {
  546. LinkedList<Node> result = new LinkedList<Node>();
  547. for (Node n : getGraph().getNodeSet()) {
  548. if (n.getAttribute(ATTRIBUTE_KEY_MAPPING_PARENT) == OPERATOR) {
  549. result.add(n);
  550. }
  551. }
  552. return result;
  553. }
  554. private Collection<Node> getUnderlayNodeSet() {
  555. LinkedList<Node> result = new LinkedList<Node>();
  556. for (Node n : getGraph().getNodeSet()) {
  557. if (n.getAttribute(ATTRIBUTE_KEY_MAPPING_PARENT) == UNDERLAY) {
  558. result.add(n);
  559. }
  560. }
  561. return result;
  562. }
  563. private void autoMapLoadedEdgeAttributes(GraphManager underlay2, GraphManager operator2) {
  564. for (Node operatorNode : getOperatorNodeSet()) {
  565. for (Node underlayNode : getUnderlayNodeSet()) {
  566. String identifier = operatorNode.getAttribute("mappingEdge");
  567. if (identifier != null && identifier.equals(underlayNode.getAttribute("mappingEdge"))) {
  568. createEdge(operatorNode.getId(), underlayNode.getId());
  569. }
  570. }
  571. }
  572. }
  573. }