MappingGraphManager.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  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(), e.isDirected());
  222. g.getEdge(idPrefix + e.getId()).addAttributes(attributes);
  223. }
  224. @Override
  225. public void addNode(Node n) {
  226. // This function mustn't be called.
  227. Debug.out("Someone called addNode(Node n) with a MappingGraphManager");
  228. }
  229. /**
  230. * Adds a <b>Copy</b> of the given Node to the graph. The Copy retains the
  231. * ID and all attributes but adds the ID prefix in front of the old ID.
  232. *
  233. * @param n
  234. * the Node to be added to the graph
  235. * @param idPrefix
  236. * the String to be added as prefix to the ID
  237. */
  238. private void addNode(Node n, String idPrefix) {
  239. HashMap<String, Object> attributes = new HashMap<>();
  240. for (String s : n.getAttributeKeySet()) {
  241. attributes.put(s, n.getAttribute(s));
  242. }
  243. attributes.put(ATTRIBUTE_KEY_MAPPING_PARENT, idPrefix);
  244. attributes.put(ATTRIBUTE_KEY_MAPPING_PARENT_ID, parentsID.get(idPrefix));
  245. g.addNode(idPrefix + n.getId());
  246. g.getNode(idPrefix + n.getId()).addAttributes(attributes);
  247. }
  248. @Override
  249. public void nodeCreated(Node n, String graphID) {
  250. if (graphID.equals(underlay.getGraph().getId()))
  251. underlayNodesChanged = true;
  252. else if (graphID.equals(operator.getGraph().getId()))
  253. operatorNodesChanged = true;
  254. }
  255. @Override
  256. public void edgeCreated(Edge e, String graphID) {
  257. if (graphID.equals(underlay.getGraph().getId()))
  258. addEdge(e, UNDERLAY);
  259. else if (graphID.equals(operator.getGraph().getId()))
  260. addEdge(e, OPERATOR);
  261. }
  262. @Override
  263. public void createEdges(String id) {
  264. super.createEdges(id);
  265. if (lastClickedID != null) {
  266. Double need = g.getNode(lastClickedID).getAttribute(ATTRIBUTE_KEY_PROCESS_NEED);
  267. if (need != null)
  268. for (Node n : g.getNodeSet())
  269. if (hasClass(n, UI_CLASS_PROCESSING_ENABLED))
  270. showExpectedCapacity(n, need);
  271. } else {
  272. for (Node n : g.getNodeSet())
  273. if (hasClass(n, UI_CLASS_PROCESSING_ENABLED))
  274. showExpectedCapacity(n, 0);
  275. }
  276. }
  277. /**
  278. * checks whether the Node can handle the load first.<br/>
  279. * creates a edge between to nodes
  280. */
  281. @Override
  282. public boolean createEdge(String to, String from) {
  283. Node fromNode = getGraph().getNode(from);
  284. Node toNode = getGraph().getNode(to);
  285. if (fromNode.hasEdgeBetween(to))
  286. return false;
  287. for (Edge e : fromNode.getEdgeSet()) {
  288. Boolean mapped = e.getAttribute("mapping");
  289. if (mapped != null && mapped)
  290. return false;
  291. }
  292. String fromParent = fromNode.getAttribute(ATTRIBUTE_KEY_MAPPING_PARENT);
  293. String toParent = toNode.getAttribute(ATTRIBUTE_KEY_MAPPING_PARENT);
  294. if (fromParent == null || toParent == null)
  295. return false;
  296. if (fromParent.equals(toParent)) {
  297. deselectNodesAfterEdgeCreation(lastClickedID);
  298. lastClickedID = to;
  299. selectNodeForEdgeCreation(lastClickedID);
  300. return false;
  301. }
  302. String newID = Main.getInstance().getUnusedID();
  303. Edge e;
  304. Node underlayNode;
  305. Node operatorNode;
  306. if (fromParent.equals(UNDERLAY)) {
  307. underlayNode = fromNode;
  308. operatorNode = toNode;
  309. } else if (toParent.equals(UNDERLAY)) {
  310. underlayNode = toNode;
  311. operatorNode = fromNode;
  312. } else
  313. return false;
  314. // check if processing enabled node
  315. if (!hasClass(underlayNode, UI_CLASS_PROCESSING_ENABLED))
  316. return false;
  317. // check and update capacity
  318. if (!addMapping(underlayNode, operatorNode)){
  319. Debug.out("Could not place Mapping Edge due to insufficient capacity!", 2);
  320. return false;
  321. }
  322. e = getGraph().addEdge(newID, operatorNode, underlayNode, true);
  323. Debug.out("Created an directed edge with Id " + newID + " from " + operatorNode + " to " + underlayNode);
  324. //adds an Attribute for loading Edges from file
  325. GraphHelper.propagateAttribute(this.g, underlayNode, "mappingEdge", newID);
  326. underlay.getGraph().getNode(underlayNode.getId().substring(8)).addAttribute("mappingEdge", newID);
  327. GraphHelper.propagateAttribute(this.g, operatorNode, "mappingEdge", newID);
  328. operator.getGraph().getNode(operatorNode.getId().substring(8)).addAttribute("mappingEdge", newID);
  329. e.addAttribute("ui.class", UI_CLASS_MAPPING);
  330. e.addAttribute(ATTRIBUTE_KEY_MAPPING, true);
  331. selectEdge(newID);
  332. MetricboxManager.updateMetrics();
  333. return true;
  334. }
  335. /**
  336. * Initialize the pie chart for the given node. It uses the process_use and
  337. * process_max values of the given node. If process_max is null or 0 it
  338. * won't do anything. If process_use is null it will be initialized to 0.
  339. *
  340. * @param underlayNode
  341. * The Node for which the pie chart should be initialized
  342. */
  343. private void initCapacity(Node underlayNode) {
  344. Double used = underlayNode.getAttribute(ATTRIBUTE_KEY_PROCESS_USE);
  345. Double max = underlayNode.getAttribute(ATTRIBUTE_KEY_PROCESS_MAX);
  346. if (max == null || max == 0)
  347. return;
  348. if (used == null)
  349. used = new Double(0);
  350. double[] pieValues = { used / max, 0, 1 - used / max };
  351. underlayNode.setAttribute("ui.pie-values", pieValues);
  352. underlayNode.setAttribute(ATTRIBUTE_KEY_PROCESS_USE, used);
  353. }
  354. /**
  355. * Resets the pie chart for the given node. If process_max is null or 0 it
  356. * won't display anything. Process_use set to 0.
  357. *
  358. * @param underlayNode
  359. * The Node for which the pie chart should be initialized
  360. */
  361. private void resetCapacity(Node underlayNode) {
  362. Double used = new Double(0);
  363. underlayNode.setAttribute(ATTRIBUTE_KEY_PROCESS_USE, used);
  364. Double max = underlayNode.getAttribute(ATTRIBUTE_KEY_PROCESS_MAX);
  365. if (max == null || max == 0)
  366. return;
  367. double[] pieValues = { 0, 0, 1 };
  368. underlayNode.setAttribute("ui.pie-values", pieValues);
  369. }
  370. /**
  371. * Checks and updates the Capacity for a procEn node. Tries to map the given
  372. * operatorNode to the given underlayNode.
  373. *
  374. * @param underlayNode
  375. * The underlayNode the operatorNode gets mapped to
  376. * @param operatorNode
  377. * The operatorNode which gets mapped
  378. * @return true if the mapping was successful. false otherwise.
  379. */
  380. private boolean addMapping(Node underlayNode, Node operatorNode) {
  381. Double needed = operatorNode.getAttribute(ATTRIBUTE_KEY_PROCESS_NEED);
  382. if (needed == null)
  383. return true;
  384. return changeCapacity(underlayNode, needed);
  385. }
  386. /**
  387. * Checks and updates the Capacity for a procEn node. Tries to unmap the
  388. * given operatorNode to the given underlayNode.
  389. *
  390. * @param underlayNode
  391. * The underlayNode the operatorNode gets mapped to
  392. * @param operatorNode
  393. * The operatorNode which gets mapped
  394. * @return true if the mapping was successful. false otherwise.
  395. */
  396. private boolean removeMapping(Node underlayNode, Node operatorNode) {
  397. Double needed = operatorNode.getAttribute(ATTRIBUTE_KEY_PROCESS_NEED);
  398. if (needed == null)
  399. return true;
  400. return changeCapacity(underlayNode, -needed);
  401. }
  402. /**
  403. * Checks and updates the Capacity for a procEn node. Tries to map the
  404. * capacity to the given underlayNode.
  405. *
  406. * @param underlayNode
  407. * The underlayNode which capacity gets updated
  408. * @param capacity
  409. * The capacity. may be positive or negative
  410. * @return true if the capacity change was successful. false otherwise.
  411. */
  412. private boolean changeCapacity(Node underlayNode, double capacity) {
  413. Double needed = capacity;
  414. Double used = underlayNode.getAttribute(ATTRIBUTE_KEY_PROCESS_USE);
  415. Double max = underlayNode.getAttribute(ATTRIBUTE_KEY_PROCESS_MAX);
  416. if (needed == 0)
  417. return true;
  418. if (max == null || max == 0)
  419. if (needed > 0)
  420. return false;
  421. if (used == null)
  422. used = new Double(0);
  423. if (used + needed > max)
  424. return false;
  425. used += needed;
  426. double[] pieValues = { used / max, 0, 1 - used / max };
  427. underlayNode.setAttribute("ui.pie-values", pieValues);
  428. underlayNode.setAttribute(ATTRIBUTE_KEY_PROCESS_USE, used);
  429. return true;
  430. }
  431. /**
  432. * Displays the capacity change to the node if the needed Cost is applied.
  433. *
  434. * @param underlayNode
  435. * The node which gets updated
  436. * @param need
  437. * the capacity change
  438. */
  439. private void showExpectedCapacity(Node underlayNode, double need) {
  440. Double used = underlayNode.getAttribute(ATTRIBUTE_KEY_PROCESS_USE);
  441. Double max = underlayNode.getAttribute(ATTRIBUTE_KEY_PROCESS_MAX);
  442. if (max == null || max == 0)
  443. return;
  444. if (used == null)
  445. used = new Double(0);
  446. double[] pieValues = { used / max, 0, 1 - used / max, 0 };
  447. if (need + used > max) {
  448. pieValues[3] = pieValues[2];
  449. pieValues[2] = 0;
  450. } else {
  451. pieValues[1] = need / max;
  452. pieValues[2] -= need / max;
  453. }
  454. underlayNode.setAttribute("ui.pie-values", pieValues);
  455. underlayNode.setAttribute(ATTRIBUTE_KEY_PROCESS_USE, used);
  456. }
  457. @Override
  458. protected boolean selectNodeForEdgeCreation(String nodeID) {
  459. Node n = g.getNode(nodeID);
  460. String parent = n.getAttribute(ATTRIBUTE_KEY_MAPPING_PARENT);
  461. if (parent == null)
  462. return false;
  463. if (parent.equals(OPERATOR))
  464. return super.selectNodeForEdgeCreation(nodeID);
  465. if (hasClass(n, UI_CLASS_PROCESSING_ENABLED))
  466. return super.selectNodeForEdgeCreation(nodeID);
  467. return false;
  468. }
  469. @Override
  470. public void deleteEdge(final String id) {
  471. Edge e = g.getEdge(id);
  472. if ((boolean) e.getAttribute(ATTRIBUTE_KEY_MAPPING)) {
  473. Node operatorNode = e.getSourceNode();
  474. Node underlayNode = e.getTargetNode();
  475. //delete mapping attriute
  476. GraphHelper.propagateAttribute(this.g, underlayNode, "mappingEdge", null);
  477. underlay.getGraph().getNode(underlayNode.getId().substring(8)).removeAttribute("mappingEdge");
  478. GraphHelper.propagateAttribute(this.g, operatorNode, "mappingEdge", null);
  479. operator.getGraph().getNode(operatorNode.getId().substring(8)).removeAttribute("mappingEdge");
  480. removeMapping(underlayNode, operatorNode);
  481. super.deleteEdge(id);
  482. }
  483. }
  484. @Override
  485. public void deleteNode(String id) {
  486. Debug.out("default delete Node prevented");
  487. }
  488. @Override
  489. public void undelete() {
  490. super.undelete();
  491. for (Edge e : deletedEdges) {
  492. if ((boolean) e.getAttribute(ATTRIBUTE_KEY_MAPPING))
  493. changeCapacity(e.getTargetNode(), e.getSourceNode().getAttribute(ATTRIBUTE_KEY_PROCESS_NEED));
  494. }
  495. }
  496. private void autoMapSourcesAndSinks(GraphManager underlay, GraphManager operator) {
  497. for (Node operatorNode : getOperatorNodeSet()) {
  498. if (operatorNode.getAttribute("typeofNode").toString().equals("source")) {
  499. for (Node underlayNode : getUnderlayNodeSet()) {
  500. if (operatorNode.getAttribute("identifier") != null && operatorNode.getAttribute("identifier")
  501. .equals(underlayNode.getAttribute("identifier"))) {
  502. String newID = Main.getInstance().getUnusedID(this);
  503. Edge e = getGraph().addEdge(newID, operatorNode, underlayNode, true);
  504. Debug.out("Created an directed edge with Id " + newID + " from " + operatorNode + " to "
  505. + underlayNode);
  506. e.addAttribute("ui.class", UI_CLASS_MAPPING);
  507. e.addAttribute(ATTRIBUTE_KEY_MAPPING, true);
  508. }
  509. }
  510. } else if (operatorNode.getAttribute("typeofNode").equals("sink")) {
  511. for (Node underlayNode : getUnderlayNodeSet()) {
  512. String identifier = operatorNode.getAttribute("identifier");
  513. if (identifier != null && identifier.equals(underlayNode.getAttribute("identifier"))) {
  514. String newID = Main.getInstance().getUnusedID(this);
  515. Edge e = getGraph().addEdge(newID, operatorNode, underlayNode, true);
  516. Debug.out("Created an directed edge with Id " + newID + " from " + operatorNode + " to "
  517. + underlayNode);
  518. e.addAttribute("ui.class", UI_CLASS_MAPPING);
  519. e.addAttribute(ATTRIBUTE_KEY_MAPPING, true);
  520. }
  521. }
  522. }
  523. }
  524. }
  525. private Collection<Node> getOperatorNodeSet() {
  526. LinkedList<Node> result = new LinkedList<Node>();
  527. for (Node n : getGraph().getNodeSet()) {
  528. if (n.getAttribute(ATTRIBUTE_KEY_MAPPING_PARENT) == OPERATOR) {
  529. result.add(n);
  530. }
  531. }
  532. return result;
  533. }
  534. private Collection<Node> getUnderlayNodeSet() {
  535. LinkedList<Node> result = new LinkedList<Node>();
  536. for (Node n : getGraph().getNodeSet()) {
  537. if (n.getAttribute(ATTRIBUTE_KEY_MAPPING_PARENT) == UNDERLAY) {
  538. result.add(n);
  539. }
  540. }
  541. return result;
  542. }
  543. private void autoMapLoadedEdgeAttributes(GraphManager underlay2, GraphManager operator2) {
  544. for (Node operatorNode : getOperatorNodeSet()) {
  545. for (Node underlayNode : getUnderlayNodeSet()) {
  546. String identifier = operatorNode.getAttribute("mappingEdge");
  547. if (identifier != null && identifier.equals(underlayNode.getAttribute("mappingEdge"))) {
  548. createEdge(operatorNode.getId(), underlayNode.getId());
  549. }
  550. }
  551. }
  552. }
  553. }