MappingGraphManager.java 21 KB

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