MappingGraphManager.java 20 KB

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