diff --git a/Architecture_Document.pdf b/Architecture_Document.pdf index a26b8ca..12cee9f 100644 Binary files a/Architecture_Document.pdf and b/Architecture_Document.pdf differ diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/ApperancePrefView.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/AppearancePrefView.java similarity index 63% rename from OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/ApperancePrefView.java rename to OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/AppearancePrefView.java index 52744be..572764c 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/ApperancePrefView.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/AppearancePrefView.java @@ -2,7 +2,12 @@ import com.mycompany.orientdbvisualizationtool.controller.PreferencesMenuController; -public class ApperancePrefView extends View { +/** + * Used for the preference view appearance + * + * @author Yona + */ +public class AppearancePrefView extends View { private PreferencesMenuController controller; @@ -10,11 +15,16 @@ public class ApperancePrefView extends View { * Constructor * */ - public ApperancePrefView() { + public AppearancePrefView() { super("fxml/PreferencesMenu.fxml"); controller = fxmlLoader.getController(); } + /** + * sets the controller for the view + * + * @return controller + */ public PreferencesMenuController getController() { return controller; } diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/AspectRatio.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/AspectRatio.java new file mode 100644 index 0000000..dc667cc --- /dev/null +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/AspectRatio.java @@ -0,0 +1,17 @@ +package com.mycompany.orientdbvisualizationtool.View; + +/** + * class for vertical and horizontal aspect ratio. + */ +public class AspectRatio { + + /** + * horizontal ratio part + */ + public static int Horizontal = 16; + /** + * vertical ratio part + */ + public static int Vertical = 9; + +} diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/Edge.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/Edge.java index 9ccd841..8d886ca 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/Edge.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/Edge.java @@ -56,20 +56,4 @@ public Node getFirstNode() { public Node getSecondNode() { return secondNode; } - - /** - * - * @param firstNode start node of edge line - */ - public void setFirstNode(Node firstNode) { - this.firstNode = firstNode; - } - - /** - * - * @param secondNode end node of edge line - */ - public void setSecondNode(Node secondNode) { - this.secondNode = secondNode; - } } diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/MainView.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/MainView.java index 7ae26df..701a80f 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/MainView.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/MainView.java @@ -12,6 +12,7 @@ public class MainView extends View { private MainController controller; + private boolean hasStarted = false; /** * Constructor @@ -27,8 +28,11 @@ public MainView() { */ @Override public void start() { - controller.setPlaceManager(PlaceManager.getInstance()); - controller.addRootNodeToPane(); - controller.populateTreeView(""); + if (!hasStarted) { + controller.setPlaceManager(PlaceManager.getInstance()); + controller.addRootNodeToPane(); + controller.populateTreeView(""); + hasStarted = true; + } } } diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/Node.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/Node.java index b4660b9..c82c85d 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/Node.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/Node.java @@ -9,8 +9,6 @@ import javafx.scene.layout.*; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; -import javafx.scene.text.Font; -import javafx.scene.text.Text; /** * Node represents a vertex in view. @@ -19,11 +17,8 @@ */ public class Node extends StackPane { - private Text label; - private String nodeName; - private String nodeDisplayName; + private NodeLabel nodeLabel; private String nodeId; - private String nodeType; private boolean selected; private Rectangle rectangle; private Color DEFAULT_COLOR; @@ -33,31 +28,23 @@ public class Node extends StackPane { private VBox childrenVBox; private Pane containerPane; - /** * Constructor * * @param id The id of the node - * @param nodeName The name of the node * @param NodeType The type of the node * @param displayName The display name of the node + * @param controller The controller for this node */ - public Node(String id, String nodeName, String NodeType, String displayName, MainController controller) { + public Node(String id, String NodeType, String displayName, MainController controller) { this.nodeId = id; this.selected = false; this.expanded = false; - this.nodeName = nodeName; - this.nodeType = NodeType; - this.nodeDisplayName = displayName; this.DEFAULT_COLOR = Color.LIGHTGRAY; this.DEFAULT_SELECTED_COLOR = Color.LAVENDER; this.setId("NodeStackPane"); - - this.label = new Text(displayName); - this.label.setFont(new Font(13)); - this.label.setId("NodeLabel"); - + this.nodeLabel = new NodeLabel(displayName); this.mainController = controller; this.setRectangleProperty(); this.setLayoutProperties(); @@ -81,7 +68,6 @@ private void setLayoutProperties() { this.containerPane = new Pane(); this.containerPane.getChildren().addAll(this, childrenVBox); this.containerPane.layout(); - } /** @@ -90,7 +76,7 @@ private void setLayoutProperties() { private void setRectangleProperty() { //rounded rectangle this.rectangle = new Rectangle(); - this.rectangle.setWidth(label.getLayoutBounds().getWidth() + 30); + this.rectangle.setWidth(nodeLabel.getMaxWidth() + 30); this.rectangle.setHeight(40.0f); this.rectangle.setArcWidth(40); this.rectangle.setArcHeight(40); @@ -99,19 +85,6 @@ private void setRectangleProperty() { this.rectangle.setId("NodeRectangle"); } - /** - * Constructor - * - * @param id The id of the node - * @param nodeName The name of the node - * @param NodeType The type of the node - */ - public Node(String id, String nodeName, String NodeType, MainController controller) { - this(id, nodeName, NodeType, nodeName, controller); - this.DEFAULT_COLOR = Color.LIGHTGRAY; - this.DEFAULT_SELECTED_COLOR = Color.LAVENDER; - } - /** * Sets properties for mouse events. Mouse pressed -> selection 2x Mouse * click -> expansion of node Mouse entered/exited -> highlight node @@ -129,17 +102,8 @@ private void setMouseListenerProperties() { * * @return javafx label */ - public Text getLabel() { - return label; - } - - /** - * Adds aa vertical box to a vertical box - * @param vBox The vertical box that needs to be added - */ - public void addToVBox(VBox vBox) { - vBox.getChildren().add(this); - vBox.layout(); + public NodeLabel getLabel() { + return nodeLabel; } /** @@ -182,13 +146,6 @@ public void setExpanded(Boolean expanded) { this.expanded = expanded; } - /** - * @param vbox The new vertical box - */ - public void setChildrenVBox(VBox vbox) { - this.childrenVBox = vbox; - } - /** * @return The node id */ @@ -196,27 +153,6 @@ public String getNodeId() { return nodeId; } - /** - * @return The node name - */ - public String getNodeName() { - return nodeName; - } - - /** - * @return The display name - */ - public String getDisplayName() { - return nodeDisplayName; - } - - /** - * @return The node type - */ - public String getNodeType() { - return nodeType; - } - /** * @return The vertical box for the children */ diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/NodeLabel.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/NodeLabel.java new file mode 100644 index 0000000..116e8ef --- /dev/null +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/NodeLabel.java @@ -0,0 +1,28 @@ +package com.mycompany.orientdbvisualizationtool.View; + +import javafx.geometry.Pos; +import javafx.scene.control.Label; +import javafx.scene.control.OverrunStyle; +import javafx.scene.text.Font; + +/** + * NodeLabel represents the label to display the name for node + */ +public class NodeLabel extends Label { + + /** + * constructor + * + * @param displayName the string that the label displays + */ + public NodeLabel(String displayName) { + super(); + this.setText(displayName); + this.setAlignment(Pos.CENTER); + this.setTextOverrun(OverrunStyle.LEADING_ELLIPSIS); + this.setMaxWidth(170); + this.setFont(new Font(13)); + this.getStyleClass().remove("label"); + this.setId("NodeLabel"); + } +} diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/ShowMoreNode.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/ShowMoreNode.java new file mode 100644 index 0000000..1b30dc2 --- /dev/null +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/ShowMoreNode.java @@ -0,0 +1,23 @@ +package com.mycompany.orientdbvisualizationtool.View; + +import com.mycompany.orientdbvisualizationtool.controller.MainController; + +/** + * a special control node for showing more nodes used when the number of + * children nodes is too large + */ +public class ShowMoreNode extends Node { + + private int remainingNodes; + + /** + * Constructor + * + * @param controller main controller for node + * @param remainingNodes The remaining nodes + */ + public ShowMoreNode(MainController controller, int remainingNodes) { + super("Show more node", "", "Show more(" + remainingNodes + ")", controller); + this.remainingNodes = remainingNodes; + } +} diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/View.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/View.java index d87a76b..2c3b644 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/View.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/View.java @@ -28,10 +28,10 @@ public View(String resource) { try { fxmlLoader = new FXMLLoader(getClass().getClassLoader().getResource(resource)); Parent root = fxmlLoader.load(); - scene = new Scene(root, WIDTH, WIDTH * 9 / 16); + scene = new Scene(root, WIDTH, WIDTH * AspectRatio.Vertical / AspectRatio.Horizontal); scene.getStylesheets().add("styles/01_DefaultStyle.css"); } catch (Exception e) { - e.printStackTrace(); + e.printStackTrace(); //needs to change to some sort of error pane } } @@ -49,9 +49,8 @@ public static int getWIDTH() { public void start() { } - /** - * + * * @return The scene */ public Scene getScene() { diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/VisApplication.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/VisApplication.java index 6a36d46..2430b64 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/VisApplication.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/View/VisApplication.java @@ -1,6 +1,7 @@ package com.mycompany.orientdbvisualizationtool.View; import javafx.application.Application; +import javafx.scene.Scene; import javafx.scene.image.Image; import javafx.stage.Stage; @@ -13,7 +14,7 @@ public class VisApplication extends Application { private View mainView; private View menuView; - private ApperancePrefView appearancePrefView; + private AppearancePrefView appearancePrefView; private Stage primaryStage; private static VisApplication singletonInstance; @@ -40,7 +41,7 @@ public void startUp(Stage primaryStage) { primaryStage.setTitle("Sustainable Buildings orientDB Visualizing Tool"); mainView = new MainView(); menuView = new MainMenuView(); - appearancePrefView = new ApperancePrefView(); + appearancePrefView = new AppearancePrefView(); changeToMenu(); } @@ -51,8 +52,9 @@ public void changeToMain() { mainView.start(); primaryStage.setScene(mainView.getScene()); primaryStage.setWidth(MainView.getWIDTH()); - primaryStage.setHeight(MainView.getWIDTH() * 9 / 16); + primaryStage.setHeight(MainView.getWIDTH() * AspectRatio.Vertical / AspectRatio.Horizontal); primaryStage.centerOnScreen(); + primaryStage.setResizable(true); primaryStage.show(); } @@ -62,8 +64,13 @@ public void changeToMain() { public void changeToMenu() { menuView.start(); primaryStage.setScene(menuView.getScene()); + primaryStage.setResizable(true); primaryStage.show(); } + + public Scene getScene() { + return primaryStage.getScene(); + } /** * switches to preferences @@ -74,6 +81,9 @@ public void changeToPreferences() { primaryStage.setScene(appearancePrefView.getScene()); primaryStage.setWidth(600); primaryStage.setHeight(490); + primaryStage.centerOnScreen(); + primaryStage.setMaximized(false); + primaryStage.setResizable(false); primaryStage.show(); } diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/VisTool.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/VisTool.java index bbdb672..894e3f1 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/VisTool.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/VisTool.java @@ -7,6 +7,8 @@ import com.mycompany.orientdbvisualizationtool.model.Entity; import com.mycompany.orientdbvisualizationtool.model.Organization; +import java.util.Arrays; +import java.util.List; import java.util.Random; import javafx.application.Application; @@ -37,7 +39,6 @@ private static void testDataForFrontEnd() { addTestOrganizations(); } - /** * Adds test organization */ @@ -81,8 +82,8 @@ private static void addTestPlaces(Place parent, int index) { Place newPlace = manager.addPlace(id, name, currentCategory, parent); addEntities(newPlace); - //recursvily call it for all the children - int childrenAmount = 5; + //recursively call it for all the children + int childrenAmount = 3 + (new Random()).nextInt(15); for (int i = 0; i < childrenAmount; i++) { addTestPlaces(newPlace, index + 1); } @@ -95,8 +96,17 @@ private static void addTestPlaces(Place parent, int index) { */ private static void addEntities(Place currentPlace) { Random random = new Random(); + List entities = Arrays.asList("Electricity-", "Gas-", "Light-", "Sound-", "Humidity-"); + List type = Arrays.asList("Generation", "Balance", "Consumption", "Environment", "Simulation"); + List sensor = Arrays.asList("", "", "-Sensor", "-Virtual-Sensor", "-Windowed-Data"); for (int i = 0; i < random.nextInt(100); i++) { - Entity newEntity = new Entity("long_name_for_testdata_sensor_stuff_" + i); + int j = random.nextInt(5); + String entityName = entities.get(j); + j = random.nextInt(5); + entityName += type.get(j); + j = random.nextInt(5); + entityName += sensor.get(j); + Entity newEntity = new Entity(entityName + i); currentPlace.addEntity(newEntity); } } diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/CenterPaneActions/CenterPaneDraggedAction.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/CenterPaneActions/CenterPaneDraggedAction.java index 0e4d462..2df1051 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/CenterPaneActions/CenterPaneDraggedAction.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/CenterPaneActions/CenterPaneDraggedAction.java @@ -14,15 +14,17 @@ public class CenterPaneDraggedAction implements EventHandler { private AnchorPane Center_Anchor_Pane; private Rectangle selectionArea; + private MainController controller; private Double mouseSourceX; private Double mouseSourceY; - private MainController controller; /** * constructor + * * @param Center_Anchor_Pane anchor to which the mouse drag event occurs * @param selectionArea rectangle drawn to represent an area selection - * @param controller mainController class containing the source mouse pressed x and y properties + * @param controller mainController class containing the source mouse + * pressed x and y properties */ public CenterPaneDraggedAction(AnchorPane Center_Anchor_Pane, Rectangle selectionArea, MainController controller) { this.Center_Anchor_Pane = Center_Anchor_Pane; diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/CenterPaneActions/CenterPanePressedAction.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/CenterPaneActions/CenterPanePressedAction.java index 97e28dd..181741f 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/CenterPaneActions/CenterPanePressedAction.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/CenterPaneActions/CenterPanePressedAction.java @@ -17,7 +17,8 @@ public class CenterPanePressedAction implements EventHandler { /** * - * @param controller main controller class that contains source mouse x and y for mouse pressed + * @param controller main controller class that contains source mouse x and + * y for mouse pressed * @param nodes list of nodes for keeping track of selection/deselection */ public CenterPanePressedAction(MainController controller, ArrayList nodes) { diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/CenterPaneActions/CenterPaneReleasedAction.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/CenterPaneActions/CenterPaneReleasedAction.java index 9192af9..5795b57 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/CenterPaneActions/CenterPaneReleasedAction.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/CenterPaneActions/CenterPaneReleasedAction.java @@ -21,6 +21,7 @@ public class CenterPaneReleasedAction implements EventHandler { /** * constructor + * * @param selectionArea rectangle drawn to represent an area selection * @param Center_Anchor_Pane anchor to which the mouse released event occurs * @param nodes list of nodes for keeping track of selection/deselection diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/CenterPaneActions/ScrollZoomAction.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/CenterPaneActions/ScrollZoomAction.java index a47412b..3b9a0c9 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/CenterPaneActions/ScrollZoomAction.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/CenterPaneActions/ScrollZoomAction.java @@ -62,4 +62,4 @@ public void handle(ScrollEvent event) { event.consume(); } } -} \ No newline at end of file +} diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/CollapseButtonsAction/CollapseButtonAction.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/CollapseButtonsAction/CollapseButtonAction.java index 84981a3..4ef0d63 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/CollapseButtonsAction/CollapseButtonAction.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/CollapseButtonsAction/CollapseButtonAction.java @@ -19,6 +19,7 @@ public abstract class CollapseButtonAction { /** * constructor + * * @param Collapse_Button button for collapsing pane * @param Split_Pane pane containing the pane that is to be collapsed * @param Collapse_Anchor_Pane pane to be collapsed/expanded @@ -38,58 +39,79 @@ public CollapseButtonAction(Button Collapse_Button, SplitPane Split_Pane, Anchor * Sets up the properties of panel collapse or panel contract button */ private void setPanelCollapseButtonProperty() { - if(left) { - Collapse_Button.setOnAction(event -> { - if (Split_Pane.getItems().contains(Collapse_Anchor_Pane)) { - Split_Pane.getItems().remove(Collapse_Anchor_Pane); - int splitPaneSize = Split_Pane.getItems().size(); - if (splitPaneSize == 2) { - Split_Pane.setDividerPosition(0, 0.8); - Center_Anchor_Pane.setPrefWidth(WIDTH * .80); - } else if (splitPaneSize == 1) { - Center_Anchor_Pane.setPrefWidth(WIDTH); - } - Collapse_Button.setText("▶"); - } else { - Split_Pane.getItems().add(0, Collapse_Anchor_Pane); - int splitPaneSize = Split_Pane.getItems().size(); - if (splitPaneSize == 2) { - Split_Pane.setDividerPosition(0, 0.2); - Center_Anchor_Pane.setPrefWidth(WIDTH * .80); - } else if (splitPaneSize == 3) { - Split_Pane.setDividerPosition(0, 0.2); - Split_Pane.setDividerPosition(1, 0.8); - Center_Anchor_Pane.setPrefWidth(WIDTH * .60); - } - Collapse_Button.setText("◀"); - } - }); + if (left) { + setCollapseButton("▶", "◀", 0.8); } else { - Collapse_Button.setOnAction(event -> { - if (Split_Pane.getItems().contains(Collapse_Anchor_Pane)) { - Split_Pane.getItems().remove(Collapse_Anchor_Pane); - int splitPaneSize = Split_Pane.getItems().size(); - if (splitPaneSize == 2) { - Split_Pane.setDividerPosition(0, 0.2); - Center_Anchor_Pane.setPrefWidth(WIDTH * .80); - } else if (splitPaneSize == 1) { - Center_Anchor_Pane.setPrefWidth(WIDTH); - } - Collapse_Button.setText("◀"); - } else { - Split_Pane.getItems().add(Split_Pane.getItems().size(), Collapse_Anchor_Pane); - int splitPaneSize = Split_Pane.getItems().size(); - if (splitPaneSize == 2) { - Split_Pane.setDividerPosition(0, 0.8); - Center_Anchor_Pane.setPrefWidth(WIDTH * .80); - } else if (splitPaneSize == 3) { - Split_Pane.setDividerPosition(0, 0.2); - Split_Pane.setDividerPosition(1, 0.8); - Center_Anchor_Pane.setPrefWidth(WIDTH * .60); - } - Collapse_Button.setText("▶"); - } - }); + setCollapseButton("◀", "▶", 0.2); } } + + /** + * Sets the collapse button + * + * @param collapseSymbol The symbol that represents collapsing + * @param expandSymbol The symbol that represents expanding + * @param dividerLocation The location of the divider for the menu + */ + private void setCollapseButton(String collapseSymbol, String expandSymbol, double dividerLocation) { + Collapse_Button.setOnAction(event -> { + if (Split_Pane.getItems().contains(Collapse_Anchor_Pane)) { + splitPaneRemove(collapseSymbol, dividerLocation); + } else { + splitPaneAdd(expandSymbol, 1 - dividerLocation); + } + }); + } + + /** + * Expands the menu + * + * @param symbol The symbol that should be printed on the footer + * @param dividerLocation The location of the divider for the menu + */ + private void splitPaneAdd(String symbol, double dividerLocation) { + addToAnchorPane(symbol); + int splitPaneSize = Split_Pane.getItems().size(); + if (splitPaneSize == 2) { + Split_Pane.setDividerPosition(0, dividerLocation); + Center_Anchor_Pane.setPrefWidth(WIDTH * .80); + } else if (splitPaneSize == 3) { + Split_Pane.setDividerPosition(0, 0.2); + Split_Pane.setDividerPosition(1, 0.8); + Center_Anchor_Pane.setPrefWidth(WIDTH * .60); + } + Collapse_Button.setText(symbol); + } + + /** + * Adds items to the anchor pane + * + * @param symbol The symbol that is used to determine which size to add + */ + private void addToAnchorPane(String symbol) { + if (symbol.equals("▶")) { + Split_Pane.getItems().add(Split_Pane.getItems().size(), Collapse_Anchor_Pane); + + } else { + Split_Pane.getItems().add(0, Collapse_Anchor_Pane); + } + } + + /** + * Collapses the menu + * + * @param symbol The symbol that should be printed on the footer + * @param dividerLocation The location of the divider for the menu + */ + private void splitPaneRemove(String symbol, double dividerLocation) { + Split_Pane.getItems().remove(Collapse_Anchor_Pane); + int splitPaneSize = Split_Pane.getItems().size(); + if (splitPaneSize == 2) { + Split_Pane.setDividerPosition(0, dividerLocation); + Center_Anchor_Pane.setPrefWidth(WIDTH * .80); + } else if (splitPaneSize == 1) { + Center_Anchor_Pane.setPrefWidth(WIDTH); + } + Collapse_Button.setText(symbol); + } } diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/CollapseButtonsAction/CollapseButtonActionBuilder.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/CollapseButtonsAction/CollapseButtonActionBuilder.java index 3c5baff..ebfa3ae 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/CollapseButtonsAction/CollapseButtonActionBuilder.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/CollapseButtonsAction/CollapseButtonActionBuilder.java @@ -19,7 +19,7 @@ public class CollapseButtonActionBuilder { * setting the Collapse_Button * * @param collapse_button button that collapses panel - * @return + * @return builder with collapse_button */ public CollapseButtonActionBuilder setCollapse_Button(Button collapse_button) { this.collapse_button = collapse_button; @@ -30,7 +30,7 @@ public CollapseButtonActionBuilder setCollapse_Button(Button collapse_button) { * setting the split_pane * * @param split_pane container for the panel to be collapsed - * @return + * @return builder with split_pane set */ public CollapseButtonActionBuilder setSplit_Pane(SplitPane split_pane) { this.split_pane = split_pane; @@ -40,8 +40,9 @@ public CollapseButtonActionBuilder setSplit_Pane(SplitPane split_pane) { /** * setting collapse_anchor_pane * - * @param collapse_anchor_pane the isLeft or right pane that is to be collapsed - * @return + * @param collapse_anchor_pane the isLeft or right pane that is to be + * collapsed + * @return builder with collapse_anchor_pane set */ public CollapseButtonActionBuilder setCollapse_Anchor_Pane(AnchorPane collapse_anchor_pane) { this.collapse_anchor_pane = collapse_anchor_pane; @@ -51,9 +52,9 @@ public CollapseButtonActionBuilder setCollapse_Anchor_Pane(AnchorPane collapse_a /** * setting the center_anchor_pane * - * @param center_anchor_pane the pane on the center that adjusts size accordingly to the - * collapse or expansion of isLeft/right pane - * @return + * @param center_anchor_pane the pane on the center that adjusts size + * accordingly to the collapse or expansion of isLeft/right pane + * @return builder with Center_anchor_pane set */ public CollapseButtonActionBuilder setCenter_Anchor_Pane(AnchorPane center_anchor_pane) { this.center_anchor_pane = center_anchor_pane; @@ -63,8 +64,8 @@ public CollapseButtonActionBuilder setCenter_Anchor_Pane(AnchorPane center_ancho /** * setting the isLeft parameter * - * @param isLeft boolean to distinguish betten isLeft or right panel. - * @return + * @param isLeft boolean to distinguish between isLeft or right panel. + * @return setting isLeft */ public CollapseButtonActionBuilder setIsLeft(Boolean isLeft) { this.isLeft = isLeft; @@ -74,7 +75,7 @@ public CollapseButtonActionBuilder setIsLeft(Boolean isLeft) { /** * the creation of the CollapseButtonAction * - * @return + * @return a collapse button action for left/right */ public CollapseButtonAction createCollapseButtonAction() { if (isLeft) { @@ -86,21 +87,24 @@ public CollapseButtonAction createCollapseButtonAction() { } } + /** + * validates if the action built has all the required fields + */ private void validate() { if (isLeft == null) { throw new IllegalStateException("Parameter isLeft is not set and is required for build."); } - if(collapse_button == null) { + if (collapse_button == null) { throw new IllegalStateException("Parameter collapse_button is not set and is required for build."); } - if(split_pane == null) { + if (split_pane == null) { throw new IllegalStateException("Parameter split_pane is not set and is required for build."); } - if(collapse_anchor_pane == null) { + if (collapse_anchor_pane == null) { throw new IllegalStateException("Parameter collapse_anchor_pane is not set and is required for build."); } - if(center_anchor_pane == null) { + if (center_anchor_pane == null) { throw new IllegalStateException("Parameter center_anchor_pane is not set and is required for build."); } } -} \ No newline at end of file +} diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/CollapseButtonsAction/LeftCollapseButtonAction.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/CollapseButtonsAction/LeftCollapseButtonAction.java index 40e28b1..38bd624 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/CollapseButtonsAction/LeftCollapseButtonAction.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/CollapseButtonsAction/LeftCollapseButtonAction.java @@ -4,7 +4,6 @@ import javafx.scene.control.SplitPane; import javafx.scene.layout.AnchorPane; - /** * Class that defines action taken when left collapse button is clicked. */ @@ -12,6 +11,7 @@ public class LeftCollapseButtonAction extends CollapseButtonAction { /** * constructor for collapse button for left pane + * * @param Collapse_Button button for collapsing pane * @param Split_Pane pane containing the pane that is to be collapsed * @param Collapse_Anchor_Pane pane to be collapsed/expanded diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/CollapseButtonsAction/RightCollapseButtonAction.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/CollapseButtonsAction/RightCollapseButtonAction.java index 3579a8a..c182e78 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/CollapseButtonsAction/RightCollapseButtonAction.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/CollapseButtonsAction/RightCollapseButtonAction.java @@ -1,6 +1,5 @@ package com.mycompany.orientdbvisualizationtool.controller.CollapseButtonsAction; -import com.mycompany.orientdbvisualizationtool.controller.CollapseButtonsAction.CollapseButtonAction; import javafx.scene.control.Button; import javafx.scene.control.SplitPane; import javafx.scene.layout.AnchorPane; @@ -12,6 +11,7 @@ public class RightCollapseButtonAction extends CollapseButtonAction { /** * constructor for collapse button for right pane + * * @param Collapse_Button button for collapsing pane * @param Split_Pane pane containing the pane that is to be collapsed * @param Collapse_Anchor_Pane pane to be collapsed/expanded diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/MainController.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/MainController.java index eab228c..7ad4bd9 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/MainController.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/MainController.java @@ -20,6 +20,7 @@ import javafx.fxml.FXML; import javafx.scene.control.*; import javafx.scene.control.cell.PropertyValueFactory; +import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.*; import javafx.scene.paint.Color; @@ -67,21 +68,27 @@ public class MainController extends ParentController { private AnchorPane Center_Anchor_Pane; @FXML private TextField Location_Search; + @FXML + private Button Search_Button; private ArrayList nodes; private ArrayList edges; - private Double mouseSourceX = 0.; - private Double mouseSourceY = 0.; + private Double mouseSourceX; + private Double mouseSourceY; private Rectangle selectionArea; private PlaceManager placeManager; private static final int WIDTH = MainView.getWIDTH(); + private final ObservableList tableViewObserveData = FXCollections.observableArrayList(); /** * The main default properties of controller are initialized */ - @FXML public void initialize() { + @FXML + public void initialize() { nodes = new ArrayList<>(); edges = new ArrayList<>(); + mouseSourceX = 0.; + mouseSourceY = 0.; Node_Name_Text_Field.setDisable(true); Node_Name_Text_Field.setStyle("-fx-opacity: 1;"); @@ -97,7 +104,7 @@ public class MainController extends ParentController { Center_Anchor_Pane.layout(); Center_Anchor_Pane.setPrefWidth(WIDTH * .60); - Center_Anchor_Pane.setPrefHeight(WIDTH * 9 / 16); + Center_Anchor_Pane.setPrefHeight(WIDTH * AspectRatio.Vertical / AspectRatio.Horizontal); Center_Anchor_Pane.setId("Center_Anchor_Pane"); setCenterAnchorMouseProperties(); @@ -107,16 +114,17 @@ public class MainController extends ParentController { setThemeChoiceBoxProperty(); zoomFunction(); - Location_Search.textProperty().addListener((observable, oldValue, newValue) -> { - - populateTreeView(newValue); - }); + Location_Search.setOnAction(event -> populateTreeView(Location_Search.getText())); + Search_Button.setOnAction(event -> populateTreeView(Location_Search.getText())); } /** * Buttons for collapsing left and right panels are set up. */ private void setCollapseButtons() { + SplitPane.setResizableWithParent(Center_Split_Pane.getItems().get(0), Boolean.FALSE); + SplitPane.setResizableWithParent(Center_Split_Pane.getItems().get(2), Boolean.FALSE); + AnchorPane left_Anchor_Pane = (AnchorPane) Center_Split_Pane.getItems().get(0); AnchorPane right_Anchor_Pane = (AnchorPane) Center_Split_Pane.getItems().get(2); @@ -141,7 +149,7 @@ private void setCollapseButtons() { * Setting the check choice box property to enable different themes */ private void setThemeChoiceBoxProperty() { - Theme_Choice_Box.getSelectionModel().selectedIndexProperty().addListener(new ThemeChoiceBoxAction(Center_Anchor_Pane, Theme_Choice_Box)); + Theme_Choice_Box.getSelectionModel().selectedIndexProperty().addListener(new ThemeChoiceBoxAction(Theme_Choice_Box)); } /** @@ -173,9 +181,9 @@ private void zoomFunction() { } /** - * Action taken when mouse dragged in center anchor pane - * Action taken when mouse pressed in center anchor pane - * Action taken when mouse released in center anchor pane + * Action taken when mouse dragged in center anchor pane Action taken when + * mouse pressed in center anchor pane Action taken when mouse released in + * center anchor pane */ private void setCenterAnchorMouseProperties() { Center_Anchor_Pane.setOnMouseDragged(new CenterPaneDraggedAction(Center_Anchor_Pane, selectionArea, this)); @@ -198,10 +206,9 @@ public void setPlaceManager(PlaceManager placeManager) { public void addRootNodeToPane() { Place rootPlace = placeManager.getRoot(); String id = rootPlace.getId(); - String name = rootPlace.getName(); String type = rootPlace.getType().toString(); String displayName = rootPlace.toString(); - Node rootNode = new Node(id, name, type, displayName, this); + Node rootNode = new Node(id, type, displayName, this); nodes.add(rootNode); VBox rootVBox = new VBox(15); @@ -214,33 +221,32 @@ public void addRootNodeToPane() { Center_Anchor_Pane.layout(); } - private final ObservableList tableViewObserveData = FXCollections.observableArrayList(); - /** - * Sets the fields of a node/place object when the node is selected (to be shown on right panel). + * Sets the fields of a node/place object when the node is selected (to be + * shown on right panel). * * @param node has properties to be shown. */ public void showSelectedNodeDetails(Node node) { - Place nodePlace = placeManager.getPlace(node.getNodeId()); - - //setting the text fields on right panel - Node_Name_Text_Field.setText(nodePlace.toString()); - Node_ID_Text_Field.setText(nodePlace.getId()); - Node_Type_Text_Field.setText(nodePlace.getType().toString()); - - //setting the status bar contents - Left_Status_Label.setTooltip(new Tooltip("Path to the currently selected place")); - Left_Status_Label.setGraphic(iconize(nodePlace.getType())); - Left_Status_Label.setText("/" + nodePlace.getPath()); - Right_Status_Label.setText(nodePlace.getChildren().size() + " | children "); - - tableViewObserveData.clear(); - PlaceManager placeManager = PlaceManager.getInstance(); - Place place = placeManager.getPlace(node.getNodeId()); - place.loadEntities(); - ArrayList placeEntities = place.getEntities(); - tableViewObserveData.addAll(placeEntities); + if (!node.getNodeId().equals("Show more node")) { + Place nodePlace = placeManager.getPlace(node.getNodeId()); + + //setting the text fields on right panel + Node_Name_Text_Field.setText(nodePlace.getShortName()); + Node_ID_Text_Field.setText(nodePlace.getId()); + Node_Type_Text_Field.setText(nodePlace.getType().toString()); + + //setting the status bar contents + Left_Status_Label.setTooltip(new Tooltip("Path to the currently selected place")); + Left_Status_Label.setGraphic(iconize(nodePlace.getType())); + Left_Status_Label.setText("/" + nodePlace.getPath()); + Right_Status_Label.setText(nodePlace.getChildren().size() + " | children "); + + tableViewObserveData.clear(); + nodePlace.loadEntities(); + ArrayList placeEntities = nodePlace.getEntities(); + tableViewObserveData.addAll(placeEntities); + } } /** @@ -262,15 +268,16 @@ public ArrayList getEdges() { * function for populateTreeView(); * * @param sourcePlace source Place to create a parent treeView item - * @param sourceItem a source treeView-item to which children treeView-items are added + * @param sourceItem a source treeView-item to which children treeView-items + * are added * @param searchKey the string to search for * @return source tree item populated with children tree items */ private TreeItem recursePopulateTreeView(Place sourcePlace, TreeItem sourceItem, String searchKey) { if (sourcePlace.getChildren().isEmpty()) { - if(sourcePlace.toString().toLowerCase().contains(searchKey.toLowerCase())){ + if (sourcePlace.toString().toLowerCase().contains(searchKey.toLowerCase())) { return sourceItem; - }else{ + } else { return null; } } @@ -280,12 +287,12 @@ private TreeItem recursePopulateTreeView(Place sourcePlace, TreeItem sourceItem, childItem.setExpanded(true); TreeItem children = recursePopulateTreeView(place, childItem, searchKey); - if(children != null || place.toString().toLowerCase().contains(searchKey.toLowerCase())){ + if (children != null || place.toString().toLowerCase().contains(searchKey.toLowerCase())) { sourceItem.getChildren().add(children); childItem.setGraphic(iconize(place.getType())); } } - if(sourcePlace.toString().toLowerCase().contains(searchKey.toLowerCase()) || !sourceItem.getChildren().isEmpty()){ + if (sourcePlace.toString().toLowerCase().contains(searchKey.toLowerCase()) || !sourceItem.getChildren().isEmpty()) { return sourceItem; } return null; @@ -293,11 +300,12 @@ private TreeItem recursePopulateTreeView(Place sourcePlace, TreeItem sourceItem, /** * populates the tree view with data from model + * * @param searchKey the string to search for */ public void populateTreeView(String searchKey) { Place rootPlace = placeManager.getRoot(); - String itemName = rootPlace.getType().toString() + ": " + rootPlace.toString(); + String itemName = rootPlace.toString(); TreeItem rootItem = new TreeItem<>(itemName); rootItem.setExpanded(true); rootItem.setGraphic(new ImageView("icons/location-icon.png")); @@ -350,7 +358,51 @@ public void setMouseSourceY(Double mouseSourceY) { this.mouseSourceY = mouseSourceY; } + /** + * opens the preferences window + * + * @param actionEvent for preferences menu item + */ public void openPreferences(ActionEvent actionEvent) { VisApplication.getInstance().changeToPreferences(); } -} \ No newline at end of file + + /** + * select all nodes + * + * @param actionEvent for select all menu item + */ + public void selectAllNodes(ActionEvent actionEvent) { + for (Node node : nodes) { + node.setSelected(true); + } + } + + /** + * unselect all nodes + * + * @param actionEvent for un select all menu item + */ + public void unselectAllNodes(ActionEvent actionEvent) { + for (Node node : nodes) { + node.setSelected(false); + } + } + + /** + * shows the about dialogue for the program. + * + * @param actionEvent for the 'About' menu item. + */ + public void showAboutVisTool(ActionEvent actionEvent) { + String aboutContent = "A tool to visualize the hierarchical data from Sustainable Buildings.\n\n" + + "Authors:\nNiels Bugel\nAlbert Dijkstra\nCarlos Isasa\nEmanuel Nae\nYona Moreda\n"; + Alert alert = new Alert(Alert.AlertType.CONFIRMATION, aboutContent, ButtonType.OK); + Stage stage = (Stage) alert.getDialogPane().getScene().getWindow(); + stage.getIcons().add(new Image("/icons/sb-icon.png")); + alert.setHeaderText("OrientDB Visualization Tool 2019\n"); + alert.setTitle("ABOUT"); + alert.setHeight(450); + alert.showAndWait(); + } +} diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/MainMenuController.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/MainMenuController.java index 7430b75..32cc33b 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/MainMenuController.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/MainMenuController.java @@ -1,6 +1,7 @@ package com.mycompany.orientdbvisualizationtool.controller; import com.mycompany.orientdbvisualizationtool.View.VisApplication; +import com.mycompany.orientdbvisualizationtool.controller.ThemeChoiceAction.ThemeChoiceBoxAction; import com.mycompany.orientdbvisualizationtool.database.DatabaseManager; import com.mycompany.orientdbvisualizationtool.model.Organization; import com.mycompany.orientdbvisualizationtool.model.Property; @@ -11,6 +12,8 @@ import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.control.ChoiceBox; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.TextField; @@ -46,6 +49,10 @@ public class MainMenuController extends ParentController { private TextField Organization_Search; @FXML private TextField Location_Search; + @FXML + private Button Select_Field; + @FXML + private ChoiceBox Theme_Choice_Box; private final ObservableList propertiesTable = FXCollections.observableArrayList(); private OrganizationManager organizationManager; @@ -65,9 +72,11 @@ public void initialize() { Node_Type_Text_Field.setDisable(true); Node_Type_Text_Field.setStyle("-fx-opacity: 1;"); Properties_Table.setSelectionModel(null); + Select_Field.setVisible(false); organizationManager = OrganizationManager.getInstance(); initLocationTreeView(); populateOrganizationTreeView(); + setThemeChoiceBoxProperty(); Properties_Table.setPrefWidth(240); Properties_Table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); @@ -82,14 +91,36 @@ public void initialize() { * @param nodePlace Has properties to be shown. */ public void showSelectedPlaceDetails(Place nodePlace) { - Node_Name_Text_Field.setText(nodePlace.toString()); - Node_ID_Text_Field.setText(nodePlace.toString()); + Select_Field.setVisible(true); + Node_Name_Text_Field.setText(nodePlace.getShortName()); + Node_ID_Text_Field.setText(nodePlace.getId()); Node_Type_Text_Field.setText(nodePlace.getType().toString()); propertiesTable.clear(); nodePlace.loadAttributes(); propertiesTable.addAll(nodePlace.getAttributes().getProperties()); } + /** + * Sets the fields of an organization to be shown on right panel. + * + * @param nodeOrganization Has properties to be shown. + */ + public void showSelectedPlaceDetails(Organization nodeOrganization) { + Select_Field.setVisible(false); + Node_Name_Text_Field.setText(nodeOrganization.getName()); + Node_ID_Text_Field.setText(nodeOrganization.getId()); + Node_Type_Text_Field.setText("Organization"); + propertiesTable.clear(); + nodeOrganization.loadAttributes(); + propertiesTable.addAll(nodeOrganization.getAttributes().getProperties()); + } + + /** + * Setting the check choice box property to enable different themes + */ + private void setThemeChoiceBoxProperty() { + Theme_Choice_Box.getSelectionModel().selectedIndexProperty().addListener(new ThemeChoiceBoxAction(Theme_Choice_Box)); + } /** * populates the tree view with data from model @@ -97,19 +128,20 @@ public void showSelectedPlaceDetails(Place nodePlace) { public void populateOrganizationTreeView() { Organization_Tree_View.setRoot(new TreeItem<>()); searchOrganization(""); + Organization_Search.textProperty().addListener((observable, oldValue, newValue) -> { - searchOrganization(newValue); }); - + Organization_Tree_View.getSelectionModel().selectedItemProperty() .addListener((v, oldValue, newValue) -> { if (newValue == null) { return; } populateLocationTreeView(((TreeItem) newValue).getValue()); + showSelectedPlaceDetails(currentOrganization); }); - + Organization_Tree_View.setShowRoot(false); } @@ -122,9 +154,9 @@ public void populateLocationTreeView(String id) { currentOrganization = organizationManager.getOrganization(id); searchLocations(""); } - - private void initLocationTreeView(){ - + + private void initLocationTreeView() { + TreeItem rootItem = new TreeItem<>(); Location_Tree_View.setRoot(rootItem); Location_Tree_View.setShowRoot(false); @@ -137,9 +169,8 @@ private void initLocationTreeView(){ currentPlace = ((TreeItem) newValue).getValue(); showSelectedPlaceDetails(currentPlace); }); - + Location_Search.textProperty().addListener((observable, oldValue, newValue) -> { - searchLocations(newValue); }); } @@ -163,18 +194,19 @@ public void selectPlace() { db.getPlaceData().refresh(currentPlace.getId()); VisApplication.getInstance().changeToMain(); } - + /** * Searches trough the organizations + * * @param searchKey string to search for */ - public void searchOrganization(String searchKey){ + public void searchOrganization(String searchKey) { TreeItem rootItem = Organization_Tree_View.getRoot(); rootItem.getChildren().clear(); List organizations = organizationManager.getOrganizations(); for (Organization o : organizations) { String itemName = o.getId(); - if(itemName.toLowerCase().contains(searchKey.toLowerCase())){ + if (itemName.toLowerCase().contains(searchKey.toLowerCase())) { TreeItem newItem = new TreeItem<>(itemName); newItem.setExpanded(true); newItem.setGraphic(new ImageView("icons/organization-icon.png")); @@ -182,23 +214,24 @@ public void searchOrganization(String searchKey){ } } } - + /** - * Searches trough the locations + * Searches through the locations + * * @param searchKey string to search for */ - public void searchLocations(String searchKey){ - - if(currentOrganization == null){ + public void searchLocations(String searchKey) { + + if (currentOrganization == null) { return; } - + TreeItem rootItem = Location_Tree_View.getRoot(); rootItem.getChildren().clear(); - + List places = currentOrganization.getPlaces(); for (Place p : places) { - if(p.getName().toLowerCase().contains(searchKey.toLowerCase())){ + if (p.getName().toLowerCase().contains(searchKey.toLowerCase())) { TreeItem newItem = new TreeItem<>(p); newItem.setExpanded(true); newItem.setGraphic(iconize(p.getType())); diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/NodeAction/NodeMouseClickedAction.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/NodeAction/NodeMouseClickedAction.java index afc8788..4060adf 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/NodeAction/NodeMouseClickedAction.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/NodeAction/NodeMouseClickedAction.java @@ -2,6 +2,7 @@ import com.mycompany.orientdbvisualizationtool.View.Edge; import com.mycompany.orientdbvisualizationtool.View.Node; +import com.mycompany.orientdbvisualizationtool.View.ShowMoreNode; import com.mycompany.orientdbvisualizationtool.controller.MainController; import com.mycompany.orientdbvisualizationtool.model.managers.PlaceManager; import com.mycompany.orientdbvisualizationtool.model.places.Place; @@ -30,10 +31,10 @@ public class NodeMouseClickedAction implements EventHandler { /** * constructor * - * @param node node to be clicked on + * @param node node to be clicked on * @param controller main controller - * @param nodes list for tracking edges when node expanded/contracted - * @param edges list for tracking edges when edges expanded/contracted + * @param nodes list for tracking edges when node expanded/contracted + * @param edges list for tracking edges when edges expanded/contracted */ public NodeMouseClickedAction(Node node, MainController controller, ArrayList nodes, ArrayList edges) { this.node = node; @@ -44,17 +45,24 @@ public NodeMouseClickedAction(Node node, MainController controller, ArrayList childrenPlaces = sourcePlace.getChildren(); + int i = 0; if (!childrenPlaces.isEmpty()) { for (Place place : childrenPlaces) { String id = place.getId(); - String name = place.getName(); String type = place.getType().toString(); String displayName = place.toString(); - Node childNode = new Node(id, name, type, displayName, controller); + Node childNode = new Node(id, type, displayName, controller); nodes.add(childNode); childrenVBox.getChildren().add(childNode.getContainerPane()); childrenVBox.layout(); + if (limit != -1 && i > limit) { + ShowMoreNode showMoreNode = new ShowMoreNode(controller, childrenPlaces.size() - i); + nodes.add(showMoreNode); + childrenVBox.getChildren().add(showMoreNode.getContainerPane()); + childrenVBox.layout(); + break; + } + i++; } } redrawEdges(parentNode); @@ -179,16 +197,23 @@ private void removeNodeAndChildren(Node node) { } /** - * Mouse click event handle for expanding/contracting node + * Mouse click event handle for expanding/contracting node to a certain + * expansion point * * @param event for mouse clicked */ @Override public void handle(MouseEvent event) { if (event.getButton().equals(MouseButton.PRIMARY)) { - //Double click - if (event.getClickCount() == 2) { - expandContractNode(node); + //ShowMore node is clicked + if (node.getNodeId().equals("Show more node")) { + VBox childrenVBox = (VBox) node.getContainerPane().getParent(); + Pane containerPane = (Pane) childrenVBox.getParent(); + Node showMoreParentNode = (Node) containerPane.getChildren().get(0); + expandContractNode(showMoreParentNode, -1); + } else if (event.getClickCount() == 2) { //Double click -> expand to a integer limit + int expansionLimit = 10; + expandContractNode(node, expansionLimit); } } } diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/NodeAction/NodeMouseEnteredAction.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/NodeAction/NodeMouseEnteredAction.java index 220ffe5..5f39dc6 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/NodeAction/NodeMouseEnteredAction.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/NodeAction/NodeMouseEnteredAction.java @@ -13,6 +13,7 @@ public class NodeMouseEnteredAction implements EventHandler { /** * constructor + * * @param node to be handled with mouse entered event */ public NodeMouseEnteredAction(Node node) { @@ -21,6 +22,7 @@ public NodeMouseEnteredAction(Node node) { /** * Node is highlighted when entered + * * @param event for mouse entered */ @Override diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/NodeAction/NodeMouseExitedAction.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/NodeAction/NodeMouseExitedAction.java index c490900..c827258 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/NodeAction/NodeMouseExitedAction.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/NodeAction/NodeMouseExitedAction.java @@ -14,6 +14,7 @@ public class NodeMouseExitedAction implements EventHandler { /** * constructor + * * @param node to be handled with mouse exited event */ public NodeMouseExitedAction(Node node) { @@ -22,6 +23,7 @@ public NodeMouseExitedAction(Node node) { /** * Node is no longer highlighted when exited + * * @param event for mouse exited. */ @Override diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/NodeAction/NodeMousePressedAction.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/NodeAction/NodeMousePressedAction.java index 5d8ecb1..93a901c 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/NodeAction/NodeMousePressedAction.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/NodeAction/NodeMousePressedAction.java @@ -13,6 +13,7 @@ public class NodeMousePressedAction implements EventHandler { /** * constructor + * * @param node for setting selection when mouse pressed */ public NodeMousePressedAction(Node node) { @@ -21,6 +22,7 @@ public NodeMousePressedAction(Node node) { /** * Node is selected when mouse pressed + * * @param event event for setting selection */ @Override diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/ParentController.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/ParentController.java index 65425c5..a6f5f1b 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/ParentController.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/ParentController.java @@ -39,4 +39,5 @@ protected ImageView iconize(PlaceCategory placeType) { } return view; } + } diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/PreferencesMenuController.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/PreferencesMenuController.java index 4931271..c82cfdd 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/PreferencesMenuController.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/PreferencesMenuController.java @@ -6,11 +6,13 @@ import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.*; +import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.AnchorPane; import javafx.scene.paint.Color; import javafx.scene.shape.Line; import javafx.stage.FileChooser; +import javafx.stage.Stage; import javafx.stage.Window; import java.io.BufferedWriter; @@ -18,64 +20,104 @@ import java.io.FileWriter; import java.io.IOException; import java.nio.file.Paths; +import java.util.Optional; +/** + * Controller for the menu + * + * @author Yona + */ public class PreferencesMenuController { private Scene mainScene; //color pickers - @FXML private ColorPicker Base_Color_Picker; - @FXML private ColorPicker Accent_Color_Picker; - @FXML private ColorPicker Focus_Color_Picker; - @FXML private ColorPicker Faint_Focus_Color_Picker; - - @FXML private ColorPicker CP_Background_Color_Picker; - @FXML private ColorPicker CP_Grid_Outer_Lines_Color_Picker; - @FXML private ColorPicker CP_Grid_Inner_Lines_Color_Picker; - - @FXML private ColorPicker Menu_Bar_Color_Picker; - @FXML private ColorPicker Menu_Item_Color_Picker; - - @FXML private ColorPicker Node_Label_Color_Picker; - @FXML private ColorPicker Edge_Color_Picker; - - @FXML private ColorPicker Button_Color_Picker; - @FXML private ColorPicker Button_Text_Color_Picker; - - @FXML private ColorPicker Text_Field_Label_Color_Picker; - @FXML private ColorPicker Text_Field_Color_Picker; - @FXML private ColorPicker Text_Field_Text_Color_Picker; + @FXML + private ColorPicker Base_Color_Picker; + @FXML + private ColorPicker Accent_Color_Picker; + @FXML + private ColorPicker Focus_Color_Picker; + @FXML + private ColorPicker Faint_Focus_Color_Picker; + + @FXML + private ColorPicker CP_Background_Color_Picker; + @FXML + private ColorPicker CP_Grid_Outer_Lines_Color_Picker; + @FXML + private ColorPicker CP_Grid_Inner_Lines_Color_Picker; + + @FXML + private ColorPicker Menu_Bar_Color_Picker; + @FXML + private ColorPicker Menu_Item_Color_Picker; + + @FXML + private ColorPicker Node_Label_Color_Picker; + @FXML + private ColorPicker Edge_Color_Picker; + + @FXML + private ColorPicker Button_Color_Picker; + @FXML + private ColorPicker Button_Text_Color_Picker; + + @FXML + private ColorPicker Text_Field_Label_Color_Picker; + @FXML + private ColorPicker Text_Field_Color_Picker; + @FXML + private ColorPicker Text_Field_Text_Color_Picker; //sample center pane - @FXML private AnchorPane Sample_Center_Pane; + @FXML + private AnchorPane Sample_Center_Pane; //sample menu bar - @FXML private MenuBar Sample_Menu_Bar; + @FXML + private MenuBar Sample_Menu_Bar; //sample tree - @FXML private Label Sample_Parent_Entity; - @FXML private Line Sample_Edge_1; - @FXML private Line Sample_Edge_2; - @FXML private Line Sample_Edge_3; - @FXML private Label Sample_Child_Entity_1; - @FXML private Label Sample_Child_Entity_2; - @FXML private Label Sample_Child_Entity_3; + @FXML + private Label Sample_Parent_Entity; + @FXML + private Line Sample_Edge_1; + @FXML + private Line Sample_Edge_2; + @FXML + private Line Sample_Edge_3; + @FXML + private Label Sample_Child_Entity_1; + @FXML + private Label Sample_Child_Entity_2; + @FXML + private Label Sample_Child_Entity_3; //text field and buttons - @FXML private Label Sample_TF_Label; - @FXML private TextField Sample_Text_Field; - @FXML private Button Sample_Button_1; - @FXML private Button Sample_Button_2; - @FXML private Button Sample_Button_3; - - @FXML private Button Save_Button; - @FXML private Button Open_Button; - @FXML private Button Cancel_Button; + @FXML + private Label Sample_TF_Label; + @FXML + private TextField Sample_Text_Field; + @FXML + private Button Sample_Button_1; + @FXML + private Button Sample_Button_2; + @FXML + private Button Sample_Button_3; + + @FXML + private Button Save_Button; + @FXML + private Button Open_Button; + @FXML + private Button Cancel_Button; /** * sets the properties of color pickers as the preferences window starts */ - @FXML public void initialize() { + @FXML + public void initialize() { setColorPickerActions(); setButtonActions(); } @@ -86,64 +128,153 @@ public class PreferencesMenuController { private void setButtonActions() { Save_Button.setOnAction(event -> { try { - fileChooserDialog(event, true); + saveThemeDialog(); } catch (IOException e) { e.printStackTrace(); } }); - Open_Button.setOnAction(event -> { - try { - fileChooserDialog(event, false); - } catch (IOException e) { - e.printStackTrace(); + Open_Button.setOnAction(this::loadingDialogue); + Cancel_Button.setOnAction(event -> { + Alert alert = getAlert("Return to main application without saving?", ""); + if (alert.getResult() == ButtonType.YES) { + VisApplication.getInstance().changeToMenu(); + } else if (alert.getResult() == ButtonType.NO) { + try { + saveThemeDialog(); + } catch (IOException e) { + e.printStackTrace(); + } } }); - Cancel_Button.setOnAction(event -> VisApplication.getInstance().changeToMain()); } /** - * opens a file choosing dialog for saving or choosing a theme css file + * dialogue for loading theme files * - * @param event button action event - * @param isSaving boolean to distinguish between a saving and a loading file chooser - * @throws IOException for bufferedWriter and creating new file + * @param event action event for getting stage window */ - private void fileChooserDialog(ActionEvent event, boolean isSaving) throws IOException { - FileChooser fileChooser = fileChooserWithInitialProperties(isSaving); - File selectedFile; + private void loadingDialogue(ActionEvent event) { + FileChooser fileChooser = fileChooserWithInitialProperties(); Window mainStage = ((Node) event.getTarget()).getScene().getWindow(); - if (isSaving) { //saving theme file - selectedFile = fileChooser.showSaveDialog(mainStage); - if (selectedFile != null) { - if (!selectedFile.exists()) { - selectedFile.createNewFile(); + File selectedFile = fileChooser.showOpenDialog(mainStage); + if (selectedFile != null) { + mainScene.getStylesheets().add("styles/" + selectedFile.getName()); + VisApplication.getInstance().changeToMain(); + } + } + + /** + * opens a file choosing dialog for saving a theme css file + * + * @throws IOException for bufferedWriter and creating new file + */ + private void saveThemeDialog() throws IOException { + TextInputDialog textInputDialog = getTextInputDialogue(); + Optional text = textInputDialog.showAndWait(); + if (text.isPresent()) { + String currentPath = Paths.get(".").toAbsolutePath().normalize().toString(); + File selectedFile = new File(currentPath + "/OrientDBVisualizationTool/src/main/resources/styles/" + text.get() + ".css"); + if (selectedFile.exists()) { + Alert alert = getAlert("Replace already existing file?", ""); + if (alert.getResult() == ButtonType.YES) { + saveToFile(selectedFile); + } else if (alert.getResult() == ButtonType.NO) { + text = textInputDialog.showAndWait(); + if (text.isPresent()) { + selectedFile = new File(currentPath + "/OrientDBVisualizationTool/src/main/resources/styles/" + text.get() + ".css"); + saveToFile(selectedFile); + } } + } else { saveToFile(selectedFile); - showConfirmationDialog(selectedFile); - } - } else { //loading or opening theme file - selectedFile = fileChooser.showOpenDialog(mainStage); - if (selectedFile != null) {//TODO:: MAKE SURE ALL CSS FILES ARE STORED IN RESOURCES/STYLES FOLDER - mainScene.getStylesheets().add("styles/" + selectedFile.getName()); - VisApplication.getInstance().changeToMain(); } } } + /** + * shows the save confirmation dialogue + * + * @param selectedFile file that is saved. + */ + private void showSaveConfirmation(File selectedFile) { + Alert confirm = new Alert(Alert.AlertType.CONFIRMATION, selectedFile.getName() + " has been saved successfully.\n\n" + + selectedFile.getPath() + + "\n\nTheme file can be applied after the application is restarted.\n" + + "Program will now return to the Main Tree View.", ButtonType.OK); + confirm.setHeight(300); + setStageIcon(confirm); + confirm.setHeaderText(""); + confirm.setGraphic(getSBIcon()); + confirm.showAndWait(); + VisApplication.getInstance().changeToMain(); + } + + /** + * gets alert dialog with given content text + * + * @param contentText displayed as content for alert + * @param headerText displayed as header text for alert + * @return alert with contentText + */ + private Alert getAlert(String contentText, String headerText) { + Alert alert = new Alert(Alert.AlertType.CONFIRMATION, contentText, + ButtonType.YES, ButtonType.NO, ButtonType.CANCEL); + setStageIcon(alert); + alert.setGraphic(getSBIcon()); + alert.setHeaderText(headerText); + alert.showAndWait(); + return alert; + } + + /** + * sets the stage icon for an alert + * + * @param alert which is needs an icon + */ + private void setStageIcon(Dialog alert) { + Stage stage = (Stage) alert.getDialogPane().getScene().getWindow(); + stage.getIcons().add(new Image("/icons/sb-icon.png")); + } + + /** + * gets the text input dialogue for saving + * + * @return text input dialogue for saving + */ + private TextInputDialog getTextInputDialogue() { + TextInputDialog textInputDialog = new TextInputDialog("Untitled_Theme"); + textInputDialog.setGraphic(getSBIcon()); + textInputDialog.setTitle("Save As"); + textInputDialog.setContentText("File name: "); + textInputDialog.setHeaderText("Do you want to save changes to Untitled_Theme?"); + setStageIcon(textInputDialog); + Stage stage = (Stage) textInputDialog.getDialogPane().getScene().getWindow(); + stage.getIcons().add(new Image("/icons/sb-icon.png")); + return textInputDialog; + } + + /** + * gets the sb icon with ImageView wrapper + * + * @return the SB-icon within image view + */ + private ImageView getSBIcon() { + ImageView imageView = new ImageView(new Image("/icons/sb-icon.png")); + imageView.setFitHeight(60); + imageView.setFitWidth(80); + return imageView; + } + /** * fileChooser is created with a starting directory and title - * @param isSaving for setting the title ("Open Theme File" or "Save Theme File") + * * @return fileChooser */ - private FileChooser fileChooserWithInitialProperties(boolean isSaving) { + private FileChooser fileChooserWithInitialProperties() { FileChooser fileChooser = new FileChooser(); String currentPath = Paths.get(".").toAbsolutePath().normalize().toString(); File initialDirectory = new File(currentPath + "/OrientDBVisualizationTool/src/main/resources/styles"); - if (isSaving) { - fileChooser.setTitle("Save Theme File"); - } else { - fileChooser.setTitle("Open Theme File"); - } + fileChooser.setTitle("Open Theme File"); if (initialDirectory.exists()) { fileChooser.setInitialDirectory(initialDirectory); } @@ -153,6 +284,7 @@ private FileChooser fileChooserWithInitialProperties(boolean isSaving) { /** * writes to selected file + * * @param selectedFile file to which contents are written in * @throws IOException for bufferedWriter */ @@ -160,30 +292,13 @@ private void saveToFile(File selectedFile) throws IOException { BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(selectedFile)); bufferedWriter.write(getNewCssContent()); bufferedWriter.close(); + showSaveConfirmation(selectedFile); + VisApplication.getInstance().changeToMain(); } /** - * After saving, gives option to apply newly created theme - * @param selectedFile newly created and saved theme file. - */ - private void showConfirmationDialog(File selectedFile) { - Alert alert = new Alert(Alert.AlertType.CONFIRMATION, "Apply the saved theme?\nTheme file must be located under resources/styles", ButtonType.YES, ButtonType.NO, ButtonType.CANCEL); - ImageView imageView = new ImageView("icons/sb-icon.png"); - imageView.setFitHeight(60); - imageView.setFitWidth(80); - alert.setGraphic(imageView); - alert.showAndWait(); - if (alert.getResult() == ButtonType.YES) { - mainScene.getStylesheets().add("styles/" + selectedFile.getName()); - VisApplication.getInstance().changeToMain(); - } else { - VisApplication.getInstance().changeToMain(); - } - } - - /** - * Updates the appropriate sample entities displayed in the preferences window - * following the changes made in color pickers + * Updates the appropriate sample entities displayed in the preferences + * window following the changes made in color pickers */ private void setColorPickerActions() { CP_Background_Color_Picker.setOnAction(event -> Sample_Center_Pane.setStyle(getNewCenterPaneStyle())); @@ -224,8 +339,9 @@ private void setColorPickerActions() { /** * converts color picker hex values to web RGB color values + * * @param color colorPicker with hex value - * @return + * @return rgb code in web format */ private String toRGBCode(ColorPicker color) { Color color1 = color.getValue(); @@ -235,18 +351,20 @@ private String toRGBCode(ColorPicker color) { /** * generates a css configuration for centerPane + * * @return New css configuration for centerPane */ private String getNewCenterPaneStyle() { - return " -fx-background-color: " + toRGBCode(CP_Background_Color_Picker) + ",\n" + - " linear-gradient(from 0px 0px to 20px 0px, repeat, " + toRGBCode(CP_Grid_Inner_Lines_Color_Picker) + " 0%, transparent 5%, transparent 95%, " + toRGBCode(CP_Grid_Inner_Lines_Color_Picker) + " 100% ),\n" + - " linear-gradient(from 0px 0px to 0px 20px, repeat, " + toRGBCode(CP_Grid_Inner_Lines_Color_Picker) + " 0%, transparent 5%, transparent 95%, " + toRGBCode(CP_Grid_Inner_Lines_Color_Picker) + " 100% ),\n" + - " linear-gradient(from 0px 0px to 100px 0px, repeat, " + toRGBCode(CP_Grid_Outer_Lines_Color_Picker) + " 0%, transparent 1%, transparent 99%, " + toRGBCode(CP_Grid_Outer_Lines_Color_Picker) + " 100% ),\n" + - " linear-gradient(from 0px 0px to 0px 100px, repeat, " + toRGBCode(CP_Grid_Outer_Lines_Color_Picker) + " 0%, transparent 1%, rgba(100, 100, 100, 0) 99%, " + toRGBCode(CP_Grid_Outer_Lines_Color_Picker) + " 100%);"; + return " -fx-background-color: " + toRGBCode(CP_Background_Color_Picker) + ",\n" + + " linear-gradient(from 0px 0px to 20px 0px, repeat, " + toRGBCode(CP_Grid_Inner_Lines_Color_Picker) + " 0%, transparent 5%, transparent 95%, " + toRGBCode(CP_Grid_Inner_Lines_Color_Picker) + " 100% ),\n" + + " linear-gradient(from 0px 0px to 0px 20px, repeat, " + toRGBCode(CP_Grid_Inner_Lines_Color_Picker) + " 0%, transparent 5%, transparent 95%, " + toRGBCode(CP_Grid_Inner_Lines_Color_Picker) + " 100% ),\n" + + " linear-gradient(from 0px 0px to 100px 0px, repeat, " + toRGBCode(CP_Grid_Outer_Lines_Color_Picker) + " 0%, transparent 1%, transparent 99%, " + toRGBCode(CP_Grid_Outer_Lines_Color_Picker) + " 100% ),\n" + + " linear-gradient(from 0px 0px to 0px 100px, repeat, " + toRGBCode(CP_Grid_Outer_Lines_Color_Picker) + " 0%, transparent 1%, rgba(100, 100, 100, 0) 99%, " + toRGBCode(CP_Grid_Outer_Lines_Color_Picker) + " 100%);"; } /** * generates a css configuration for MenuBar + * * @return New css configuration for MenuBar */ private String getNewMenuBarStyle() { @@ -255,6 +373,7 @@ private String getNewMenuBarStyle() { /** * generates a css configuration for Menu + * * @return New css configuration for Menu */ private String getNewMenuStyle() { @@ -263,6 +382,7 @@ private String getNewMenuStyle() { /** * generates a css configuration for NodeLabel + * * @return New css configuration for NodeLabel */ private String getNewNodeLabelStyle() { @@ -271,6 +391,7 @@ private String getNewNodeLabelStyle() { /** * generates a css configuration for Edge + * * @return New css configuration for Edge */ private String getNewEdgeStyle() { @@ -279,15 +400,17 @@ private String getNewEdgeStyle() { /** * generates a css configuration for Button + * * @return New css configuration for Button */ private String getNewButtonStyle() { - return " -fx-background-color: linear-gradient(#706e6a," + toRGBCode(Button_Color_Picker) + ");\n" + - " -fx-text-fill: " + toRGBCode(Button_Text_Color_Picker) + ";\n"; + return " -fx-background-color: linear-gradient(#706e6a," + toRGBCode(Button_Color_Picker) + ");\n" + + " -fx-text-fill: " + toRGBCode(Button_Text_Color_Picker) + ";\n"; } /** * generates a css configuration for TextFieldLabel + * * @return New css configuration for TextFieldLabel */ private String getNewTextFieldLabelStyle() { @@ -296,66 +419,70 @@ private String getNewTextFieldLabelStyle() { /** * generates a css configuration for TextField + * * @return New css configuration for TextField */ private String getNewTextFieldStyle() { - return " -fx-text-fill: " + toRGBCode(Text_Field_Text_Color_Picker) + ";\n" + - " -fx-background-color: linear-gradient(#706e6a," + toRGBCode(Text_Field_Color_Picker) + ");\n"; + return " -fx-text-fill: " + toRGBCode(Text_Field_Text_Color_Picker) + ";\n" + + " -fx-background-color: linear-gradient(#706e6a," + toRGBCode(Text_Field_Color_Picker) + ");\n"; } /** * generates a css configuration for Root + * * @return New css configuration for Root */ private String getNewRootStyle() { - return " -fx-base: " + toRGBCode(Base_Color_Picker) + ";\n" + - " -fx-accent: " + toRGBCode(Accent_Color_Picker) + ";\n" + - " -fx-default-button: " + toRGBCode(Button_Color_Picker) + ";\n" + - " -fx-focus-color: " + toRGBCode(Focus_Color_Picker) + ";\n" + - " -fx-faint-focus-color: " + toRGBCode(Faint_Focus_Color_Picker) + ";\n" + - " -fx-focused-text-base-color : ladder(\n" + - " -fx-selection-bar,\n" + - " -fx-light-text-color 45%,\n" + - " -fx-dark-text-color 46%,\n" + - " -fx-dark-text-color 59%,\n" + - " -fx-mid-text-color 60%\n" + - " );\n" + - " -fx-focused-mark-color : -fx-focused-text-base-color;\n"; + return " -fx-base: " + toRGBCode(Base_Color_Picker) + ";\n" + + " -fx-accent: " + toRGBCode(Accent_Color_Picker) + ";\n" + + " -fx-default-button: " + toRGBCode(Button_Color_Picker) + ";\n" + + " -fx-focus-color: " + toRGBCode(Focus_Color_Picker) + ";\n" + + " -fx-faint-focus-color: " + toRGBCode(Faint_Focus_Color_Picker) + ";\n" + + " -fx-focused-text-base-color : ladder(\n" + + " -fx-selection-bar,\n" + + " -fx-light-text-color 45%,\n" + + " -fx-dark-text-color 46%,\n" + + " -fx-dark-text-color 59%,\n" + + " -fx-mid-text-color 60%\n" + + " );\n" + + " -fx-focused-mark-color : -fx-focused-text-base-color;\n"; } /** * generates a css configuration from all css components + * * @return New css configuration */ private String getNewCssContent() { - String content = ".root {\n" + getNewRootStyle() + "}\n\n" + - ".text-input:focused {\n" + - " -fx-highlight-text-fill: ladder(\n" + - " -fx-highlight-fill,\n" + - " -fx-light-text-color 45%,\n" + - " -fx-dark-text-color 46%,\n" + - " -fx-dark-text-color 59%,\n" + - " -fx-mid-text-color 60%\n" + - " );\n" + - "}\n\n" + - "#Center_Anchor_Pane{\n" + getNewCenterPaneStyle() + "}\n\n" + - ".button {\n" + getNewButtonStyle() + "}\n\n" + - ".label {\n" + getNewTextFieldLabelStyle() + "}\n\n" + - ".menu-bar {\n" + getNewMenuBarStyle() + "}\n\n" + - ".menu {\n" + getNewMenuStyle() + "}\n\n" + - ".menu-item {\n" + getNewMenuStyle() + "}\n\n" + - ".text-field {\n" + getNewTextFieldStyle() + "}\n\n" + - "#NodeRectangle{\n" + - " -fx-fill: lightgray;\n" + - " -fx-stroke: darkgray;\n" + - "}\n\n" + - "#NodeLabel {\n" + getNewNodeLabelStyle() + "}\n\n" + - "#Edge{\n" + getNewEdgeStyle() + "}"; + String content = ".root {\n" + getNewRootStyle() + "}\n\n" + + ".text-input:focused {\n" + + " -fx-highlight-text-fill: ladder(\n" + + " -fx-highlight-fill,\n" + + " -fx-light-text-color 45%,\n" + + " -fx-dark-text-color 46%,\n" + + " -fx-dark-text-color 59%,\n" + + " -fx-mid-text-color 60%\n" + + " );\n" + + "}\n\n" + + "#Center_Anchor_Pane{\n" + getNewCenterPaneStyle() + "}\n\n" + + ".button {\n" + getNewButtonStyle() + "}\n\n" + + ".label {\n" + getNewTextFieldLabelStyle() + "}\n\n" + + ".menu-bar {\n" + getNewMenuBarStyle() + "}\n\n" + + ".menu {\n" + getNewMenuStyle() + "}\n\n" + + ".menu-item {\n" + getNewMenuStyle() + "}\n\n" + + ".text-field {\n" + getNewTextFieldStyle() + "}\n\n" + + "#NodeRectangle{\n" + + " -fx-fill: lightgray;\n" + + " -fx-stroke: darkgray;\n" + + "}\n\n" + + "#NodeLabel {\n" + getNewNodeLabelStyle() + "}\n\n" + + "#Edge{\n" + getNewEdgeStyle() + "}"; return content; } /** * sets the main application scene for applying the theme + * * @param scene used for applying the theme */ public void setApplicationScene(Scene scene) { diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/ShowHideNodeAction/HideNodesButtonAction.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/ShowHideNodeAction/HideNodesButtonAction.java index 9d45f91..3b18e91 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/ShowHideNodeAction/HideNodesButtonAction.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/ShowHideNodeAction/HideNodesButtonAction.java @@ -17,6 +17,7 @@ public class HideNodesButtonAction implements EventHandler { /** * constructor + * * @param nodes list of nodes for keeping track of selection/deselection * @param edges list of edges for keeping track of selection/deselection */ @@ -27,6 +28,7 @@ public HideNodesButtonAction(ArrayList nodes, ArrayList edges) { /** * hides selected nodes by setting their visibility to false + * * @param event action event for button */ @Override diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/ShowHideNodeAction/ShowNodesButtonAction.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/ShowHideNodeAction/ShowNodesButtonAction.java index 6a84158..1c4d6ea 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/ShowHideNodeAction/ShowNodesButtonAction.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/ShowHideNodeAction/ShowNodesButtonAction.java @@ -17,6 +17,7 @@ public class ShowNodesButtonAction implements EventHandler { /** * constructor + * * @param nodes list of nodes for keeping track of selection/deselection * @param edges list of edges for keeping track of selection/deselection */ @@ -27,6 +28,7 @@ public ShowNodesButtonAction(ArrayList nodes, ArrayList edges) { /** * shows hidden nodes by setting their visibility to true. + * * @param event action event for button */ @Override diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/TableViewAction/TableViewItemClickedAction.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/TableViewAction/TableViewItemClickedAction.java index 1779aaf..4d61b92 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/TableViewAction/TableViewItemClickedAction.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/TableViewAction/TableViewItemClickedAction.java @@ -1,6 +1,5 @@ package com.mycompany.orientdbvisualizationtool.controller.TableViewAction; - import com.mycompany.orientdbvisualizationtool.model.Entity; import javafx.scene.control.Alert; import javafx.scene.control.TableView; @@ -9,6 +8,7 @@ import javafx.scene.input.MouseEvent; import javafx.event.EventHandler; +import javafx.stage.Stage; /** * Action performed when Table View Item is clicked @@ -19,6 +19,7 @@ public class TableViewItemClickedAction implements EventHandler { /** * constructor + * * @param table_View the table on which action is performed on */ public TableViewItemClickedAction(TableView table_View) { @@ -26,7 +27,9 @@ public TableViewItemClickedAction(TableView table_View) { } /** - * Entity details are displayed as an entity item is double clicked in table view. + * Entity details are displayed as an entity item is double clicked in table + * view. + * * @param event mouse event for action */ @Override @@ -34,16 +37,28 @@ public void handle(MouseEvent event) { if (event.getClickCount() == 2) { Entity entity = (Entity) Table_View.getSelectionModel().getSelectedItem(); Alert alert = new Alert(Alert.AlertType.INFORMATION); + alert.getDialogPane().setMinWidth(800); + Stage stage = (Stage) alert.getDialogPane().getScene().getWindow(); + stage.getIcons().add(new Image("/icons/sb-icon.png")); alert.setTitle("Entity Information"); alert.setHeaderText("Entity details"); - alert.setContentText("Entity ID:\n" + entity.getId() + "\n\nEntity Description:\n" + - "\n\n"); - ImageView imageView = new ImageView(new Image("/icons/sb-icon.png")); - imageView.setFitHeight(60); - imageView.setFitWidth(80); + alert.setContentText("Entity ID:\n" + entity.getId() + "\n\nEntity Description:" + + getEntityDescription(entity)); + ImageView imageView = new ImageView(new Image("/icons/sensor-icon.png")); + imageView.setFitHeight(64); + imageView.setFitWidth(64); alert.setGraphic(imageView); alert.showAndWait(); } } + private String getEntityDescription(Entity entity) { + String entityDescription = ""; + entity.loadAttributes(); + for (String s : entity.getAttributes().getTypes()) { + entityDescription += "\n" + s; + } + return entityDescription; + } + } diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/ThemeChoiceAction/ThemeChoiceBoxAction.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/ThemeChoiceAction/ThemeChoiceBoxAction.java index 16f741e..6a0c9f0 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/ThemeChoiceAction/ThemeChoiceBoxAction.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/controller/ThemeChoiceAction/ThemeChoiceBoxAction.java @@ -1,30 +1,28 @@ package com.mycompany.orientdbvisualizationtool.controller.ThemeChoiceAction; +import com.mycompany.orientdbvisualizationtool.View.View; import com.mycompany.orientdbvisualizationtool.View.VisApplication; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.scene.control.ChoiceBox; -import javafx.scene.layout.AnchorPane; import java.io.File; import java.util.Objects; +import javafx.scene.Scene; /** * Action taken when theme choice box is used/clicked. */ public class ThemeChoiceBoxAction implements ChangeListener { - private AnchorPane Center_Anchor_Pane; private ChoiceBox Theme_Choice_Box; /** * constructor * - * @param Center_Anchor_Pane anchor pane to which theme adjustments are made to. * @param Theme_Choice_Box choice box that contains options for different themes. */ - public ThemeChoiceBoxAction(AnchorPane Center_Anchor_Pane, ChoiceBox Theme_Choice_Box) { - this.Center_Anchor_Pane = Center_Anchor_Pane; + public ThemeChoiceBoxAction(ChoiceBox Theme_Choice_Box) { this.Theme_Choice_Box = Theme_Choice_Box; setThemeChoiceBoxProperty(); } @@ -33,7 +31,7 @@ public ThemeChoiceBoxAction(AnchorPane Center_Anchor_Pane, ChoiceBox Theme_Choic * Setting the check choice box property */ private void setThemeChoiceBoxProperty() { - Theme_Choice_Box.getItems().addAll("Default Theme", "Dark Mode", "Natural Blue", "S.B. Green", "Crimson Red", "Create a custom theme"); + Theme_Choice_Box.getItems().addAll("Default Theme", "Dark Mode", "Natural Blue", "S.B. Green", "Crimson Red", "Custom Theme"); Theme_Choice_Box.getSelectionModel().selectFirst(); } @@ -48,8 +46,9 @@ private void setThemeChoiceBoxProperty() { public void changed(ObservableValue observable, Number oldValue, Number newValue) { if (newValue.intValue() != 5) { File folder = new File(getClass().getResource("/styles").getPath()); - Center_Anchor_Pane.getScene().getStylesheets().remove("styles/" + Objects.requireNonNull(folder.listFiles())[oldValue.intValue()].getName()); - Center_Anchor_Pane.getScene().getStylesheets().add("styles/" + Objects.requireNonNull(folder.listFiles())[newValue.intValue()].getName()); + Scene currentScene = VisApplication.getInstance().getScene(); + currentScene.getStylesheets().remove("styles/" + Objects.requireNonNull(folder.listFiles())[oldValue.intValue()].getName()); + currentScene.getStylesheets().add("styles/" + Objects.requireNonNull(folder.listFiles())[newValue.intValue()].getName()); } else { VisApplication.getInstance().changeToPreferences(); } diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/database/Attributes.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/database/Attributes.java index 2e1864d..49a0a66 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/database/Attributes.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/database/Attributes.java @@ -6,7 +6,7 @@ /** * Class that can retrieve and save the attributes of a certain vertex - * + * * @author Niels, Albert, Carlos */ public class Attributes { @@ -31,9 +31,9 @@ public Attributes() { * @param keys The list of property keys we want to try to add */ protected void addProperties(Vertex v, String[] keys) { - for (int i = 0; i < keys.length; i++) { - if (hasProperty(keys[i], v)) { - Property prop = new Property(keys[i], v.getProperty(keys[i])); + for (String key : keys) { + if (hasProperty(key, v)) { + Property prop = new Property(key, v.getProperty(key)); properties.add(prop); } } diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/database/EntityAttributes.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/database/EntityAttributes.java index a1fb726..ebd501b 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/database/EntityAttributes.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/database/EntityAttributes.java @@ -1,5 +1,5 @@ /** - * + * */ package com.mycompany.orientdbvisualizationtool.database; @@ -13,27 +13,49 @@ * @author Carlos * */ -public class EntityAttributes{ - private ArrayList types; - - public EntityAttributes (Vertex v){ - Iterable parents; - types = new ArrayList(); - parents = v.getEdges(Direction.OUT, "instance-of"); - for(Edge e : parents) { - try { - types.add(e.getVertex(Direction.IN).getProperty("type-id")); - } catch (Exception ex) { - continue; - } - } - } - - /** - * @return the types - */ - public ArrayList getTypes() { - return types; - } +public class EntityAttributes { + + private ArrayList types; + + /** + * Constructor + * + * @param v The vertex it needs to load the attributes of + */ + public EntityAttributes(Vertex v) { + Iterable parents; + types = new ArrayList(); + parents = v.getEdges(Direction.OUT, "instance-of"); + for (Edge e : parents) { + if (hasProperty(e)) { + types.add(e.getVertex(Direction.IN).getProperty("type-id")); + } + } + } + + /** + * Checks if a certain node has a certain property + * + * @param edge The edge to which the node is connected + * @return If the node has a certain property + */ + private boolean hasProperty(Edge edge) { + try { + String value = edge.getVertex(Direction.IN).getProperty("type-id"); + if (value == null) { + return false; + } + } catch (Exception e) { + return false; + } + return true; + } + + /** + * @return the types + */ + public ArrayList getTypes() { + return types; + } } diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/database/EntityData.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/database/EntityData.java index 35d6456..84e2e50 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/database/EntityData.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/database/EntityData.java @@ -11,7 +11,6 @@ import com.google.common.collect.Sets; import com.mycompany.orientdbvisualizationtool.model.Entity; -import com.mycompany.orientdbvisualizationtool.model.places.Place; /** * Responsible for retrieving specific information about entities from the @@ -131,15 +130,15 @@ private boolean isSensor(Vertex v) { } return false; } - + /** * Retrieves the attributes of a certain entity - * + * * @param entity The place we want to retrieve the attributes from * @return A class containing all the attributes */ - public EntityAttributes getAttributes(Entity ent) { - Vertex v = getVertexById("V_instance.id", ent.getId()); + public EntityAttributes getAttributes(Entity entity) { + Vertex v = getVertexById("V_instance.id", entity.getId()); return new EntityAttributes(v); } } diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/database/OrganizationData.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/database/OrganizationData.java index c4fc4e0..8d8ee6f 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/database/OrganizationData.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/database/OrganizationData.java @@ -16,6 +16,7 @@ public class OrganizationData extends Database { private final OrganizationManager organizationManager; + private Organization allOrganization; /** * constructor @@ -63,6 +64,9 @@ public void refreshAll() { for (Vertex v : queryVertices("SELECT id FROM V_organization WHERE @RID IN (SELECT out FROM E_owns)")) { refresh(v); } + addAllOrganization(); + addNoOrganization(); + organizationManager.addOrganization(allOrganization); } /** @@ -75,4 +79,30 @@ public OrganizationAttributes getAttributes(Organization org) { Vertex v = getVertexById("V_organization.id", org.getId()); return new OrganizationAttributes(v); } + + /** + * Adds all the unconnected places + */ + private void addNoOrganization() { + Organization organization = new Organization("Unknown"); + for (Place p : allOrganization.getPlaces()) { + organization.addPlace(p); + } + //list of places that have an organization + for (Organization o : OrganizationManager.getInstance().getOrganizations()) { + organization.getPlaces().removeAll(o.getPlaces()); + } + organizationManager.addOrganization(organization); + } + + /** + * Adds all the places + */ + private void addAllOrganization() { + allOrganization = new Organization("All"); + for (Vertex v : queryVertices("SELECT * FROM V_location ")) { + Place newPlace = new Location(v.getProperty("id"), v.getProperty("name")); + allOrganization.addPlace(newPlace); + } + } } diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/database/PlaceAttributes.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/database/PlaceAttributes.java index 5ce6a3a..3c97045 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/database/PlaceAttributes.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/database/PlaceAttributes.java @@ -34,14 +34,13 @@ private void addStringProperties(Vertex v) { "name", "postal", "e-label", - "building-type", - }; + "building-type",}; addProperties(v, keys); } - + /** - * Adds all the properties to the list of properties that have a double/float - * values + * Adds all the properties to the list of properties that have a + * double/float values * * @param v The vertex we want the properties from */ diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/database/PlaceData.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/database/PlaceData.java index 8656640..2c2b820 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/database/PlaceData.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/database/PlaceData.java @@ -70,7 +70,7 @@ private void addPlaceToModel(Vertex place, Place parent) { /** * Retrieves the attributes of a certain place - * + * * @param place The place we want to retrieve the attributes from * @return A class containing all the attributes */ diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/model/Entity.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/model/Entity.java index 3d9b97c..b0ebbce 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/model/Entity.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/model/Entity.java @@ -1,16 +1,19 @@ package com.mycompany.orientdbvisualizationtool.model; +import com.mycompany.orientdbvisualizationtool.database.DatabaseManager; +import com.mycompany.orientdbvisualizationtool.database.EntityAttributes; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; /** * Contains all the data about an entity - * + * * @author Niels, Albert */ public class Entity { private final StringProperty id; + private EntityAttributes attributes; /** * constructor @@ -29,8 +32,30 @@ public String getId() { return id.get(); } + /** + * Returns a string representation of this class + * + * @return The string representation of this class + */ @Override - public String toString(){ + public String toString() { return id.get(); } + + /** + * Loads the attributes for this place + */ + public void loadAttributes() { + if (attributes == null) { + attributes = DatabaseManager.getInstance().getEntityData().getAttributes(this); + } + } + + /** + * + * @return The entity attributes + */ + public EntityAttributes getAttributes() { + return attributes; + } } diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/model/Organization.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/model/Organization.java index 0fad0ff..e20dbd4 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/model/Organization.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/model/Organization.java @@ -1,5 +1,7 @@ package com.mycompany.orientdbvisualizationtool.model; +import com.mycompany.orientdbvisualizationtool.database.DatabaseManager; +import com.mycompany.orientdbvisualizationtool.database.OrganizationAttributes; import com.mycompany.orientdbvisualizationtool.model.places.Place; import java.util.ArrayList; import java.util.List; @@ -13,7 +15,9 @@ public class Organization { private final String id; + private final String name; private List places; + private OrganizationAttributes attributes; /** * Constructor @@ -22,9 +26,20 @@ public class Organization { */ public Organization(String id) { this.id = id; + name = getNameFromId(id); places = new ArrayList<>(); } + private String getNameFromId(String id) { + String newName; + try { + newName = id.substring(id.lastIndexOf('.') + 1); + } catch (Exception e) { + return id; + } + return newName; + } + /** * adds a location the list of locations * @@ -42,6 +57,14 @@ public String getId() { return id; } + /** + * + * @return The name of the organization + */ + public String getName() { + return name; + } + /** * Dereferences the list of places */ @@ -56,4 +79,21 @@ public void dereferenceAll() { public List getPlaces() { return places; } + + /** + * Loads the attributes for this place + */ + public void loadAttributes() { + if (attributes == null) { + attributes = DatabaseManager.getInstance().getOrganizationData().getAttributes(this); + } + } + + /** + * + * @return The organization attributes + */ + public OrganizationAttributes getAttributes() { + return attributes; + } } diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/model/Property.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/model/Property.java index beccf1c..38d92f7 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/model/Property.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/model/Property.java @@ -5,10 +5,11 @@ /** * A struct to store a property and a property value - * + * * @author Niels, Albert */ public class Property { + /** * The name that describes what kind of property it is */ @@ -18,18 +19,31 @@ public class Property { */ private final StringProperty value; + /** + * Constructor + * + * @param key Property description + * @param value Property value + */ public Property(String key, String value) { this.key = new SimpleStringProperty(key); this.value = new SimpleStringProperty(value); } + /** + * + * @return property key/description + */ public String getKey() { return key.get(); } + /** + * + * @return property value + */ public String getValue() { return value.get(); } - - + } diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/model/managers/OrganizationManager.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/model/managers/OrganizationManager.java index 2d6bca6..924e4bf 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/model/managers/OrganizationManager.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/model/managers/OrganizationManager.java @@ -73,7 +73,7 @@ public List getOrganizations() { /** * Retrieves an organization based on an id - * + * * @param id The id of the organization * @return The organization */ diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/model/managers/PlaceManager.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/model/managers/PlaceManager.java index 885c109..1f761a8 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/model/managers/PlaceManager.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/model/managers/PlaceManager.java @@ -35,7 +35,7 @@ public static PlaceManager getInstance() { } /** - * Links a child and a parent to eachother if they exist + * Links a child and a parent to each other if they exist * * @param child The child we want to link the parent to * @param parent The parent we want to link a child to @@ -104,6 +104,7 @@ public void emptyPlaces() { for (Place p : places) { p.dereferenceAll(); } + places = null; places = new ArrayList<>(); } diff --git a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/model/places/Place.java b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/model/places/Place.java index 9b6f050..2e94f4f 100644 --- a/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/model/places/Place.java +++ b/OrientDBVisualizationTool/src/main/java/com/mycompany/orientdbvisualizationtool/model/places/Place.java @@ -200,20 +200,37 @@ public String getPath() { } /** - * + * * @return The attributes of a place */ public PlaceAttributes getAttributes() { return attributes; } - + /** * Loads the attributes for this place */ public void loadAttributes() { - if(attributes == null) { + if (attributes == null) { attributes = DatabaseManager.getInstance().getPlaceData().getAttributes(this); } } - + + /** + * Checks if this place is equal to an object + * + * @param o The object this place is compared to + * @return Whether or not this place is equal to the object + */ + @Override + public boolean equals(Object o) { + if (o instanceof Place) { + Place p = (Place) o; + if (p.getId().equals(id) && p.getName().equals(name)) { + return true; + } + } + return false; + } + } diff --git a/OrientDBVisualizationTool/src/main/resources/fxml/MainDesign.fxml b/OrientDBVisualizationTool/src/main/resources/fxml/MainDesign.fxml index 1189cc1..c9585c6 100644 --- a/OrientDBVisualizationTool/src/main/resources/fxml/MainDesign.fxml +++ b/OrientDBVisualizationTool/src/main/resources/fxml/MainDesign.fxml @@ -29,17 +29,7 @@ - - + @@ -47,22 +37,13 @@ - - - - - - + + - + @@ -82,7 +63,7 @@ -