Переглянути джерело

added Operators

added Operator Manager
added basicMappingOperator
changed OperatorInterface
	removed setup
	changed interface of calculate()

fixed a bug preventing some attributes from being shown
jascha Bohne 7 роки тому
батько
коміт
aaccb0673d

+ 3 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/graphs/GraphManager.java

@@ -572,6 +572,9 @@ public class GraphManager {
 	 */
 	protected void deselectNodesAfterEdgeCreation(String nodeID) {
 		Node n = getGraph().getNode(nodeID);
+		if(n == null){
+			return;
+		}
 		if (!hasClass(n, UI_CLASS_PROCESSING_ENABLED) || !GraphDisplayManager.getCurrentLayer().equals(Layer.MAPPING)) {
 			n.removeAttribute("ui.style");
 			n.changeAttribute("ui.style", "fill-color: #000000; size: 15px;");

+ 100 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/metrics/BasicMappingOperator.java

@@ -0,0 +1,100 @@
+package de.tu_darmstadt.informatik.tk.scopviz.metrics;
+
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.LinkedList;
+
+import org.graphstream.graph.Node;
+
+import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
+import de.tu_darmstadt.informatik.tk.scopviz.graphs.GraphManager;
+import de.tu_darmstadt.informatik.tk.scopviz.graphs.MappingGraphManager;
+import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
+import de.tu_darmstadt.informatik.tk.scopviz.metrics.interfaces.ScopvizGraphOperator;
+
+public class BasicMappingOperator implements ScopvizGraphOperator {
+
+	@Override
+	public void calculate(GraphManager g) {
+		//check if you are using a Mapping Graph
+		MappingGraphManager map;
+		if (g instanceof MappingGraphManager){
+			map = (MappingGraphManager) g;
+		} else {
+			Debug.out("ERROR: can only invoke " + getName() + " on a Mapping Graph", 3);
+			return;
+		}
+		
+		//find the Nodes that have to be mapped and where they can be mapped to
+		LinkedList<Node> operatorNodes = getOperatorNodes(map);
+		LinkedList<Node> procEnNodes = getProcEnNodes(map);
+		
+		
+		//Map the Nodes (beginning with the operatorNode with the highest Processing requirement)
+		operatorNodes.sort(operatorComparator);
+		Iterator<Node> procEnIterator;
+		Boolean successfull;
+		for (Node n: operatorNodes){
+			procEnIterator = procEnNodes.iterator();
+			successfull = false;
+			while(procEnIterator.hasNext() && !successfull){
+				successfull = map.createEdge(procEnIterator.next().getId(), n.getId());
+				Debug.out(new Boolean(successfull).toString());
+			}
+			if(!successfull){
+				Debug.out("WARNING: BasicMappingOperator could not map all Nodes");
+			}
+			
+		}
+	}
+
+	@Override
+	public String getName() {
+		return "Basic Automapping";
+	}
+	
+	protected LinkedList<Node> getProcEnNodes(GraphManager g){
+		LinkedList<Node> result = new LinkedList<Node>();
+		Iterator<Node> nodeIter= g.getGraph().getNodeIterator();
+		while(nodeIter.hasNext()){
+			Node n = nodeIter.next();
+			if("procEn".equals(n.getAttribute("typeofNode"))){
+				result.add(n);
+			}
+		}
+		return result;
+	}
+	
+	protected LinkedList<Node> getOperatorNodes(GraphManager g){
+		LinkedList<Node> result = new LinkedList<Node>();
+		Iterator<Node> nodeIter= g.getGraph().getNodeIterator();
+		while(nodeIter.hasNext()){
+			Node n = nodeIter.next();
+			if("operator".equals(n.getAttribute("typeofNode"))){
+				result.add(n);
+			}
+		}
+		return result;
+	}
+	
+	protected Comparator<Node> operatorComparator = new Comparator<Node>() {
+
+		@Override
+		public int compare(Node o1,Node o2) {
+			Main m = Main.getInstance();
+			
+			//this does: process-need(o1) - process-need(o2)
+			Double result =  m.convertAttributeTypes(o1.getAttribute("process-need"), new Double(0)) 
+					- m.convertAttributeTypes(o2.getAttribute("process-need"), new Double(0));
+			if(result == 0.0){
+				return 0;
+			}else if (result < 0.0){
+				return -1;
+			} else {
+				return 1;
+			}
+		}
+	};
+
+}

+ 25 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/metrics/TestOperator.java

@@ -0,0 +1,25 @@
+package de.tu_darmstadt.informatik.tk.scopviz.metrics;
+
+import java.util.Iterator;
+
+import org.graphstream.graph.Node;
+
+import de.tu_darmstadt.informatik.tk.scopviz.graphs.GraphManager;
+import de.tu_darmstadt.informatik.tk.scopviz.metrics.interfaces.ScopvizGraphOperator;
+
+public class TestOperator implements ScopvizGraphOperator {
+
+	@Override
+	public void calculate(GraphManager g) {
+		Iterator<Node> nodeIter = g.getGraph().getNodeIterator();
+		while(nodeIter.hasNext()){
+			nodeIter.next().addAttribute("ui.style", "fill-color: blue;");
+		}
+	}
+
+	@Override
+	public String getName() {
+		return "TestOperator";
+	}
+
+}

+ 3 - 15
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/metrics/interfaces/ScopvizGraphOperator.java

@@ -1,17 +1,9 @@
 package de.tu_darmstadt.informatik.tk.scopviz.metrics.interfaces;
 
-import java.util.LinkedList;
-
-import de.tu_darmstadt.informatik.tk.scopviz.graphs.MyGraph;
+import de.tu_darmstadt.informatik.tk.scopviz.graphs.GraphManager;
 
 public interface ScopvizGraphOperator {
-
-	/**
-	 * Metric Returns true if the GraphOperator requires the Setup() to be
-	 * called if this is false setup() will not be called.
-	 */
-	public boolean isSetupRequired();
-
+	
 	/**
 	 * calculates a new Version of the Graph using the given operator.
 	 * 
@@ -20,15 +12,11 @@ public interface ScopvizGraphOperator {
 	 * @return a list of Graphs that is the result of the operator on the Graph
 	 *         g
 	 */
-	public LinkedList<MyGraph> calculate(MyGraph g);
+	public void calculate(GraphManager g);
 
 	/**
 	 * returns the name of the Metric.
 	 */
 	public String getName();
 
-	/**
-	 * sets up the metric for the first use.
-	 */
-	public void setup();
 }

+ 2 - 1
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/GUIController.java

@@ -216,6 +216,7 @@ public class GUIController implements Initializable {
 		ToolboxManager.initializeItems();
 		PropertiesManager.initializeItems(properties);
 		ConsoleManager.initialize(this);
+		OperatorManager.initialize(this);
 
 		GraphDisplayManager.init(this);
 
@@ -280,7 +281,7 @@ public class GUIController implements Initializable {
 		quit.setOnAction((event) -> MenuBarManager.quitAction(event));
 		delete.setOnAction((event) -> MenuBarManager.deleteAction(event));
 		undelete.setOnAction((event) -> MenuBarManager.undeleteAction(event));
-		operators.setOnAction((event) -> MenuBarManager.undeleteAction(event));
+		operators.setOnAction((event) -> OperatorManager.openOperatorsDialog());
 		resetMapping.setOnAction((event) -> GraphDisplayManager.initMappingLayer(true));
 		updateMetricMI.setOnAction((event) -> MetricboxManager.updateMetrics());
 		updateMetricMI.setDisable(true);

+ 88 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/OperatorManager.java

@@ -0,0 +1,88 @@
+package de.tu_darmstadt.informatik.tk.scopviz.ui;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
+import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
+import de.tu_darmstadt.informatik.tk.scopviz.metrics.BasicMappingOperator;
+import de.tu_darmstadt.informatik.tk.scopviz.metrics.TestOperator;
+import de.tu_darmstadt.informatik.tk.scopviz.metrics.interfaces.ScopvizGraphOperator;
+import javafx.application.Platform;
+import javafx.collections.FXCollections;
+import javafx.geometry.Insets;
+import javafx.scene.control.ButtonType;
+import javafx.scene.control.ChoiceBox;
+import javafx.scene.control.Dialog;
+import javafx.scene.control.Label;
+import javafx.scene.control.ButtonBar.ButtonData;
+import javafx.scene.layout.GridPane;
+
+public class OperatorManager {
+
+	private static GUIController guiController;
+
+	private static HashMap<String, ScopvizGraphOperator> operators = new HashMap<String, ScopvizGraphOperator>();
+
+	/**
+	 * Initializes all GraphOperators for employment
+	 * 
+	 * ****Central method to add a new metric***** 
+	 * Add line: addOperator(new YourMetric()); for using it in the Operatordialog
+	 * **************************************************************
+	 * 
+	 */
+	private static void initializeGraphOperators(){
+		addOperator(new TestOperator());
+		addOperator(new  BasicMappingOperator());
+	}
+
+	public static void openOperatorsDialog(){
+		Dialog<ArrayList<String>> addPropDialog = new Dialog<>();
+		addPropDialog.setTitle("GraphOperators");
+
+		ButtonType addButtonType = new ButtonType("invoke on current graph", ButtonData.OK_DONE);
+		addPropDialog.getDialogPane().getButtonTypes().addAll(addButtonType, ButtonType.CANCEL);
+
+		// create grid
+		GridPane grid = new GridPane();
+		grid.setHgap(10);
+		grid.setVgap(10);
+		grid.setPadding(new Insets(20, 150, 10, 10));
+
+		//set DropDown Menu
+		ChoiceBox<String> operatorChooser = new ChoiceBox<>();
+		operatorChooser.setItems(FXCollections.observableArrayList(operators.keySet()));
+
+		//adding elements to grid
+		grid.add(new Label("Please select the operator you want to invoke on the current Gaph"), 0, 0);
+		grid.add(operatorChooser, 0, 1);
+
+		addPropDialog.getDialogPane().setContent(grid);
+
+		Platform.runLater(() -> operatorChooser.requestFocus());
+
+		// get new property values
+		addPropDialog.setResultConverter(dialogButton -> {
+			if (dialogButton == addButtonType) {
+				operators.get(operatorChooser.getSelectionModel().getSelectedItem())
+				.calculate(Main.getInstance().getGraphManager());
+				return null;
+			} else
+				return null;
+
+		});
+		addPropDialog.showAndWait();
+
+
+	}
+
+	public static void addOperator(ScopvizGraphOperator op){
+		operators.put(op.getName(), op);
+	}
+
+	public static void initialize(GUIController g){
+		initializeGraphOperators();
+		guiController = g;
+	}
+}

+ 10 - 1
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/PropertiesManager.java

@@ -295,12 +295,21 @@ public final class PropertiesManager {
 						&& Layer.OPERATOR == Main.getInstance().getGraphManager().getGraph().getAttribute("layer")) {
 					break;
 				}
+				Object actualAttribute = selected.getAttribute(key);
+				if (actualAttribute != null) {
+					newData.add(new KeyValuePair(key, String.valueOf(actualAttribute), actualAttribute.getClass()));
+				}
 				break;
 			case "process-need":
+				Debug.out(key);
 				if (selected instanceof Node
 						&& Layer.UNDERLAY == Main.getInstance().getGraphManager().getGraph().getAttribute("layer")) {
 					break;
 				}
+				actualAttribute = selected.getAttribute(key);
+				if (actualAttribute != null) {
+					newData.add(new KeyValuePair(key, String.valueOf(actualAttribute), actualAttribute.getClass()));
+				}
 				break;
 			case "process-max":
 				if (selected instanceof Node
@@ -313,7 +322,7 @@ public final class PropertiesManager {
 					break;
 				}
 			default:
-				Object actualAttribute = selected.getAttribute(key);
+				actualAttribute = selected.getAttribute(key);
 				if (actualAttribute != null) {
 					newData.add(new KeyValuePair(key, String.valueOf(actualAttribute), actualAttribute.getClass()));
 				}