MappingGraphManager.java 21 KB

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