|
@@ -7,7 +7,6 @@ import javafx.beans.property.ReadOnlyObjectWrapper;
|
|
|
import javafx.beans.value.ObservableValue;
|
|
|
import javafx.collections.FXCollections;
|
|
|
import javafx.collections.ObservableList;
|
|
|
-import javafx.event.EventHandler;
|
|
|
import javafx.scene.Node;
|
|
|
import javafx.scene.control.CheckBox;
|
|
|
import javafx.scene.control.TableCell;
|
|
@@ -33,6 +32,12 @@ public final class ToolboxManager {
|
|
|
*/
|
|
|
private static GUIController controller;
|
|
|
|
|
|
+ /**
|
|
|
+ * needed, so that MouseClickedEvent is not fired, when SelectionProperty
|
|
|
+ * was changed
|
|
|
+ */
|
|
|
+ private static boolean selectedPropertyChanged = false;
|
|
|
+
|
|
|
/**
|
|
|
* private constructor to prevent Instantiation.
|
|
|
*/
|
|
@@ -101,60 +106,99 @@ public final class ToolboxManager {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Handler for TableRows
|
|
|
+ * fired when the selected item in the Toolbox was changed
|
|
|
+ *
|
|
|
+ * @param ov
|
|
|
+ * @param oldVal
|
|
|
+ * the previous selected item
|
|
|
+ * @param newVal
|
|
|
+ * the new selected item
|
|
|
*/
|
|
|
- public static final EventHandler<MouseEvent> rowClickedHandler = new EventHandler<MouseEvent>() {
|
|
|
+ public static void selectedItemChanged(ObservableValue<? extends Pair<Object, String>> ov,
|
|
|
+ Pair<Object, String> oldVal, Pair<Object, String> newVal) {
|
|
|
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- @Override
|
|
|
- public void handle(MouseEvent event) {
|
|
|
+ if (newVal != null) {
|
|
|
|
|
|
- // Get the clicked TableRow
|
|
|
- Node node = ((Node) event.getTarget()).getParent();
|
|
|
- TableRow<Pair<Object, String>> row;
|
|
|
+ // change creation mode based on selected item
|
|
|
+ String rowString = newVal.getValue();
|
|
|
|
|
|
- if (node instanceof TableRow) {
|
|
|
- row = (TableRow<Pair<Object, String>>) node;
|
|
|
- } else {
|
|
|
- // clicking on text part
|
|
|
- row = (TableRow<Pair<Object, String>>) node.getParent();
|
|
|
- }
|
|
|
+ if (rowString.equals("Standard")) {
|
|
|
+ changeCreationMode(CreationMode.CREATE_STANDARD_NODE);
|
|
|
|
|
|
- // Set CreateModus based on pressed TableRow
|
|
|
- if (!row.isEmpty()) {
|
|
|
+ } else if (rowString.equals("Source")) {
|
|
|
+ changeCreationMode(CreationMode.CREATE_SOURCE_NODE);
|
|
|
|
|
|
- String rowString = row.getItem().getValue();
|
|
|
+ } else if (rowString.equals("Sink")) {
|
|
|
+ changeCreationMode(CreationMode.CREATE_SINK_NODE);
|
|
|
|
|
|
- if (rowString.equals("Standard")) {
|
|
|
- changeCreationMode(CreationMode.CREATE_STANDARD_NODE);
|
|
|
+ } else if (rowString.equals("EnProc")) {
|
|
|
+ changeCreationMode(CreationMode.CREATE_PROC_NODE);
|
|
|
|
|
|
- } else if (rowString.equals("Source")) {
|
|
|
- changeCreationMode(CreationMode.CREATE_SOURCE_NODE);
|
|
|
+ } else if (rowString.equals("operator")) {
|
|
|
+ changeCreationMode(CreationMode.CREATE_OPERATOR_NODE);
|
|
|
|
|
|
- } else if (rowString.equals("Sink")) {
|
|
|
- changeCreationMode(CreationMode.CREATE_SINK_NODE);
|
|
|
+ } else if (rowString.equals("Directed")) {
|
|
|
+ changeCreationMode(CreationMode.CREATE_DIRECTED_EDGE);
|
|
|
|
|
|
- } else if (rowString.equals("EnProc")) {
|
|
|
- changeCreationMode(CreationMode.CREATE_PROC_NODE);
|
|
|
+ } else if (rowString.equals("Undirected")) {
|
|
|
+ changeCreationMode(CreationMode.CREATE_UNDIRECTED_EDGE);
|
|
|
+ }
|
|
|
|
|
|
- } else if (rowString.equals("operator")) {
|
|
|
- changeCreationMode(CreationMode.CREATE_OPERATOR_NODE);
|
|
|
+ } else {
|
|
|
+ // selected item was an empty row
|
|
|
+ Main.getInstance().setCreationMode(CreationMode.CREATE_NONE);
|
|
|
+ }
|
|
|
|
|
|
- } else if (rowString.equals("Directed")) {
|
|
|
- changeCreationMode(CreationMode.CREATE_DIRECTED_EDGE);
|
|
|
+ // Unselecet Rows if Creation Mode is None
|
|
|
+ if (Main.getInstance().getCreationMode().equals(CreationMode.CREATE_NONE)) {
|
|
|
+ controller.toolbox.getSelectionModel().clearSelection();
|
|
|
+ }
|
|
|
|
|
|
- } else if (rowString.equals("Undirected")) {
|
|
|
- changeCreationMode(CreationMode.CREATE_UNDIRECTED_EDGE);
|
|
|
- }
|
|
|
+ // set this property to true, so the MouseClickedHandler doesn't also
|
|
|
+ // fire its event
|
|
|
+ selectedPropertyChanged = true;
|
|
|
|
|
|
- // Unselecet Rows if Creation Mode is None
|
|
|
- if (Main.getInstance().getCreationMode().equals(CreationMode.CREATE_NONE)) {
|
|
|
- controller.toolbox.getSelectionModel().clearSelection();
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * fired when a row was clicked
|
|
|
+ *
|
|
|
+ * @param event
|
|
|
+ */
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ public static void rowClickedHandler(MouseEvent event) {
|
|
|
+
|
|
|
+ // only use the handler when the selectionProperty Listener didn't fire
|
|
|
+ // its event
|
|
|
+ if (selectedPropertyChanged) {
|
|
|
+ selectedPropertyChanged = false;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Get the clicked TableRow
|
|
|
+ Node node = ((Node) event.getTarget()).getParent();
|
|
|
+ TableRow<Pair<Object, String>> row = null;
|
|
|
+
|
|
|
+ if (node instanceof TableRow) {
|
|
|
+ row = (TableRow<Pair<Object, String>>) node;
|
|
|
+ } else {
|
|
|
+ // clicking on picture part
|
|
|
+ try {
|
|
|
+ row = (TableRow<Pair<Object, String>>) node.getParent();
|
|
|
+
|
|
|
+ } catch (ClassCastException e) {
|
|
|
+ // there was a dragging move one the picture part when this
|
|
|
+ // exception is thrown -> cant get row from this action
|
|
|
+ return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- };
|
|
|
+ // clear selection if selected row was clicked again
|
|
|
+ if (row.isEmpty()
|
|
|
+ || controller.toolbox.getSelectionModel().selectedItemProperty().get().equals(row.getItem())) {
|
|
|
+ controller.toolbox.getSelectionModel().clearSelection();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* If currentMode already selected then deselect, otherwise set mode on
|
|
@@ -172,6 +216,7 @@ public final class ToolboxManager {
|
|
|
|
|
|
/**
|
|
|
* create a pair object under given picture and name
|
|
|
+ *
|
|
|
* @param picture
|
|
|
* @param name
|
|
|
* @return
|
|
@@ -208,8 +253,9 @@ public final class ToolboxManager {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * The actual TableCell, that renders the images of nodes and edges. (Image, String)-Cell
|
|
|
- * additional support for (String, String), (Integer, String), (Boolean, String), ("N/A", String) table cells
|
|
|
+ * The actual TableCell, that renders the images of nodes and edges. (Image,
|
|
|
+ * String)-Cell additional support for (String, String), (Integer, String),
|
|
|
+ * (Boolean, String), ("N/A", String) table cells
|
|
|
*
|
|
|
*/
|
|
|
public static class PairValueCell extends TableCell<Pair<Object, String>, Object> {
|
|
@@ -246,4 +292,5 @@ public final class ToolboxManager {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|