admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1 | /* |
| 2 | * To change this template, choose Tools | Templates |
| 3 | * and open the template in the editor. |
| 4 | */ |
| 5 | package tai_ofa; |
| 6 | |
| 7 | import java.io.BufferedReader; |
| 8 | import java.io.File; |
| 9 | import java.io.FileNotFoundException; |
| 10 | import java.io.FileReader; |
| 11 | import java.io.IOException; |
| 12 | import java.nio.file.Path; |
| 13 | import java.util.ArrayList; |
| 14 | import java.util.HashMap; |
| 15 | |
| 16 | import java.util.Iterator; |
| 17 | import java.util.Locale; |
| 18 | import java.util.Map; |
| 19 | import java.util.Set; |
| 20 | import java.util.logging.Level; |
| 21 | import java.util.logging.Logger; |
| 22 | import javafx.application.Application; |
| 23 | import javafx.application.Platform; |
| 24 | import javafx.beans.value.ChangeListener; |
| 25 | import javafx.beans.value.ObservableValue; |
| 26 | import javafx.collections.ObservableList; |
| 27 | import javafx.event.ActionEvent; |
| 28 | import javafx.event.Event; |
| 29 | import javafx.event.EventHandler; |
| 30 | import javafx.geometry.Insets; |
| 31 | import javafx.geometry.Orientation; |
| 32 | import javafx.geometry.Pos; |
| 33 | import javafx.scene.Group; |
| 34 | import javafx.scene.Node; |
| 35 | import javafx.scene.Scene; |
| 36 | import javafx.scene.control.Accordion; |
| 37 | import javafx.scene.control.Button; |
| 38 | import javafx.scene.control.ComboBox; |
| 39 | import javafx.scene.control.ComboBoxBuilder; |
| 40 | import javafx.scene.control.ContextMenu; |
| 41 | import javafx.scene.control.Label; |
| 42 | import javafx.scene.control.Menu; |
| 43 | import javafx.scene.control.MenuBar; |
| 44 | import javafx.scene.control.MenuButton; |
| 45 | import javafx.scene.control.MenuItem; |
| 46 | import javafx.scene.control.Separator; |
| 47 | import javafx.scene.control.SeparatorMenuItem; |
| 48 | import javafx.scene.control.SplitPane; |
| 49 | import javafx.scene.control.Tab; |
| 50 | import javafx.scene.control.TabPane; |
| 51 | import javafx.scene.control.TextArea; |
| 52 | import javafx.scene.control.TextField; |
| 53 | import javafx.scene.control.TextFieldBuilder; |
| 54 | import javafx.scene.control.TitledPane; |
| 55 | import javafx.scene.control.ToolBar; |
| 56 | import javafx.scene.control.Tooltip; |
| 57 | import javafx.scene.control.TreeCell; |
| 58 | import javafx.scene.control.TreeItem; |
| 59 | import javafx.scene.control.TreeView; |
| 60 | import javafx.scene.effect.Effect; |
| 61 | import javafx.scene.image.Image; |
| 62 | import javafx.scene.image.ImageView; |
| 63 | import javafx.scene.input.InputEvent; |
| 64 | import javafx.scene.input.MouseButton; |
| 65 | import javafx.scene.input.MouseEvent; |
| 66 | import javafx.scene.layout.GridPane; |
| 67 | import javafx.scene.layout.HBox; |
| 68 | import javafx.scene.layout.Pane; |
| 69 | import javafx.scene.layout.VBox; |
| 70 | import javafx.scene.layout.VBoxBuilder; |
| 71 | import javafx.scene.paint.Color; |
| 72 | import javafx.scene.text.Font; |
| 73 | import javafx.scene.text.FontWeight; |
| 74 | import javafx.scene.text.Text; |
| 75 | import javafx.stage.FileChooser; |
| 76 | import javafx.stage.FileChooser.ExtensionFilter; |
| 77 | import javafx.stage.Modality; |
| 78 | import javafx.stage.Screen; |
| 79 | import javafx.stage.Stage; |
| 80 | import javafx.util.Callback; |
| 81 | import javax.swing.JOptionPane; |
| 82 | import javax.swing.SingleSelectionModel; |
| 83 | |
| 84 | /** |
| 85 | * |
| 86 | * @author Raghav Kashyap (raghavkashyap@paxterrasolutions.com) |
| 87 | |
| 88 | * TestON is free software: you can redistribute it and/or modify |
| 89 | * it under the terms of the GNU General Public License as published by |
| 90 | * the Free Software Foundation, either version 2 of the License, or |
| 91 | * (at your option) any later version. |
| 92 | |
| 93 | * TestON is distributed in the hope that it will be useful, |
| 94 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 95 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 96 | * GNU General Public License for more details. |
| 97 | |
| 98 | * You should have received a copy of the GNU General Public License |
| 99 | * along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 100 | |
| 101 | * |
| 102 | */ |
| 103 | public class TAI_OFA extends Application { |
| 104 | |
| 105 | MenuBar OFA_MenuBar = new MenuBar(); |
| 106 | Scene scene; |
| 107 | TAILocale label = new TAILocale(new Locale("en", "EN")); |
| 108 | Stage copyStage; |
| 109 | double toolBarHeight, menuBarHeight; |
| 110 | ToolBar toolbar = new ToolBar(); |
| 111 | TitledPane projectExplorer; |
| 112 | TitledPane logExlorer; |
| 113 | TitledPane driverExplorer; |
| 114 | TreeView<String> projectExplorerTreeView, logExplorerTreeView, driverExplorerTreeView; |
| 115 | TreeItem<String> driverExplorerTree; |
| 116 | static double OFAContainerWidth, OFAContainerHeight; |
| 117 | boolean projectExplorerFlag, editorFlag; |
| 118 | ContextMenu contextMenu; |
| 119 | TAI_OFA OFAReference; |
| 120 | TabPane explorerTabPane, editorTabPane; |
| 121 | FileChooser openParams; |
| 122 | OFAFileOperations fileOperation = new OFAFileOperations(); |
| 123 | Tab explorerTab; |
| 124 | Accordion explorer; |
| 125 | TreeItem<String> projectExplorerTree, logExplorerTree; |
| 126 | OFAWizard wizard; |
| 127 | AddParams addParams; |
| 128 | String paramsFileContent, projectWorkSpacePath; |
| 129 | OFATestSummary testSummaryPop; |
| 130 | Button Save; |
| 131 | MenuItem saveAll; |
| 132 | MenuItem closeAll; |
| 133 | |
| 134 | public TAI_OFA() { |
| 135 | OFAReference = this; |
| 136 | |
| 137 | } |
| 138 | |
| 139 | public TAI_OFA(TabPane pane, Scene sc, TabPane pane1) { |
| 140 | editorTabPane = pane; |
| 141 | scene = sc; |
| 142 | explorerTabPane = pane1; |
| 143 | OFAReference = this; |
| 144 | } |
| 145 | |
| 146 | @Override |
| 147 | public void start(Stage primaryStage) { |
| 148 | copyStage = primaryStage; |
| 149 | Group root = new Group(); |
| 150 | |
| 151 | projectWorkSpacePath = label.hierarchyTestON; |
| 152 | scene = new Scene(root, 800, 600, Color.DARKGRAY); |
| 153 | VBox baseBox = new VBox(); |
| 154 | getFileMenu(); |
| 155 | getEditMenu(); |
| 156 | getViewMenu(); |
| 157 | getRunMenu(); |
| 158 | getHelpMenu(); |
| 159 | getToolBar(); |
| 160 | OFA_MenuBar.setPrefWidth(scene.widthProperty().get()); |
| 161 | toolbar.prefWidthProperty().bind(scene.widthProperty()); |
| 162 | toolbar.setMinHeight(scene.heightProperty().get() / 20);; |
| 163 | toolBarHeight = toolbar.getMinHeight(); |
| 164 | OFA_MenuBar.setPrefHeight(scene.heightProperty().get() / 20); |
| 165 | menuBarHeight = OFA_MenuBar.getPrefHeight(); |
| 166 | explorerTabPane = new TabPane(); |
| 167 | editorTabPane = new TabPane(); |
| 168 | explorer = new Accordion(); |
| 169 | explorerTab = new Tab("Explorer"); |
| 170 | explorerTabPane.setLayoutX(0); |
| 171 | projectExplorerFlag = true; |
| 172 | |
| 173 | getProjectExplorer(); |
| 174 | getLogExplorer(); |
| 175 | getDriverExplorer(); |
| 176 | explorer.setMinSize(200, scene.getHeight() - 40); |
| 177 | explorer.getPanes().addAll(projectExplorer, logExlorer, driverExplorer); |
| 178 | explorerTabPane.prefHeightProperty().bind(scene.heightProperty()); |
| 179 | explorerTabPane.setMinWidth(200); |
| 180 | explorerTab.setContent(explorer); |
| 181 | explorerTabPane.getTabs().addAll(explorerTab); |
| 182 | editorTabPane.setLayoutX(270); |
| 183 | final Pane basePane = new Pane(); |
| 184 | explorerTabPane.prefHeightProperty().bind(scene.heightProperty().subtract(toolBarHeight + menuBarHeight + 1)); |
| 185 | basePane.getChildren().addAll(explorerTabPane, new Separator(Orientation.VERTICAL), editorTabPane); |
| 186 | basePane.autosize(); |
| 187 | baseBox.getChildren().addAll(OFA_MenuBar, toolbar, basePane); |
| 188 | baseBox.prefHeightProperty().bind(primaryStage.heightProperty()); |
| 189 | OFAContainerWidth = scene.getWidth(); |
| 190 | OFAContainerHeight = scene.getHeight(); |
| 191 | root.getChildren().addAll(baseBox); |
| 192 | primaryStage.setTitle("TestON - Automation is O{pe}N"); |
| 193 | primaryStage.setScene(scene); |
| 194 | primaryStage.setResizable(true); |
| 195 | primaryStage.sizeToScene(); |
| 196 | primaryStage.show(); |
| 197 | } |
| 198 | |
| 199 | public void getFileMenu() { |
| 200 | |
| 201 | |
| 202 | //adding Menus |
| 203 | Menu fileMenu = new Menu(label.fileMenu); |
| 204 | |
| 205 | //adding File Menu |
| 206 | Image newImage = new Image("images/newIcon.jpg", 20.0, 20.0, true, true); |
| 207 | Image saveAllImage = new Image("images/saveAll.jpg", 20.0, 20.0, true, true); |
| 208 | |
| 209 | Menu newFileMenu = new Menu("New", new ImageView(newImage)); |
| 210 | MenuItem newTest = new MenuItem("New Test"); |
| 211 | MenuItem componentDriver = new MenuItem(label.newDriver); |
| 212 | MenuItem newParams = new MenuItem(label.newParams); |
| 213 | MenuItem newTopology = new MenuItem(label.newTopology); |
| 214 | MenuItem testScript = new MenuItem(label.newTestScript); |
| 215 | newFileMenu.getItems().addAll(newTest, componentDriver, newParams, newTopology, testScript); |
| 216 | |
| 217 | |
| 218 | newTopology.setOnAction(new EventHandler<ActionEvent>() { |
| 219 | @Override |
| 220 | public void handle(ActionEvent t) { |
| 221 | try { |
| 222 | wizard = new OFAWizard(projectExplorerTree, 3, projectExplorerTree.getChildren(), projectExplorerTreeView); |
| 223 | wizard.setOFA(OFAReference); |
| 224 | wizard.start(new Stage()); |
| 225 | |
| 226 | } catch (Exception ex) { |
| 227 | Logger.getLogger(TAI_OFA.class.getName()).log(Level.SEVERE, null, ex); |
| 228 | } |
| 229 | } |
| 230 | }); |
| 231 | |
| 232 | newTest.setOnAction(new EventHandler<ActionEvent>() { |
| 233 | @Override |
| 234 | public void handle(ActionEvent t) { |
| 235 | wizard = new OFAWizard(projectExplorerTree, 1, projectExplorerTree.getChildren(), projectExplorerTreeView); |
| 236 | wizard.setOFA(OFAReference); |
| 237 | try { |
| 238 | wizard.start(new Stage()); |
| 239 | } catch (Exception ex) { |
| 240 | Logger.getLogger(TAI_OFA.class.getName()).log(Level.SEVERE, null, ex); |
| 241 | } |
| 242 | } |
| 243 | }); |
| 244 | |
| 245 | newParams.setOnAction(new EventHandler<ActionEvent>() { |
| 246 | @Override |
| 247 | public void handle(ActionEvent t) { |
| 248 | addParams = new AddParams(); |
| 249 | addParams.setOFA(OFAReference); |
| 250 | addParams.getNewParams(); |
| 251 | } |
| 252 | }); |
| 253 | |
| 254 | |
| 255 | Image openImage = new Image("images/open.png", 15.0, 15.0, true, true); |
| 256 | Menu open = new Menu(label.open, new ImageView(openImage)); |
| 257 | MenuItem openParams = new MenuItem("Params"); |
| 258 | Menu openTestScript = new Menu("Test Script"); |
| 259 | MenuItem pyTest = new MenuItem("Python TestScript"); |
| 260 | MenuItem ospkTest = new MenuItem("OpenSpeak TestScript"); |
| 261 | openTestScript.getItems().addAll(pyTest, ospkTest); |
| 262 | |
| 263 | MenuItem openTopology = new MenuItem("Topology"); |
| 264 | MenuItem openDriver = new MenuItem("Driver"); |
| 265 | |
| 266 | open.getItems().addAll(openParams, openTopology, openTestScript, openDriver); |
| 267 | |
| 268 | openParams.setOnAction(new EventHandler<ActionEvent>() { |
| 269 | @Override |
| 270 | public void handle(ActionEvent t) { |
| 271 | openFile("params", ""); |
| 272 | } |
| 273 | }); |
| 274 | |
| 275 | ospkTest.setOnAction(new EventHandler<ActionEvent>() { |
| 276 | @Override |
| 277 | public void handle(ActionEvent t) { |
| 278 | openFile("ospk", ""); |
| 279 | } |
| 280 | }); |
| 281 | |
| 282 | |
| 283 | Image saveImage = new Image("images/Save_24x24.png", 15.0, 15.0, true, true); |
| 284 | MenuItem save = new MenuItem(label.save, new ImageView(saveImage)); |
| 285 | |
| 286 | MenuItem saveAs = new MenuItem(label.saveAs); |
| 287 | saveAll = new MenuItem(label.saveAll, new ImageView(saveAllImage)); |
| 288 | |
| 289 | Image exitImage = new Image("images/exit.gif", 15.0, 15.0, true, true); |
| 290 | MenuItem exit = new MenuItem(label.exit, new ImageView(exitImage)); |
| 291 | exit.setOnAction(new EventHandler<ActionEvent>() { |
| 292 | @Override |
| 293 | public void handle(ActionEvent t) { |
| 294 | copyStage.close(); |
| 295 | } |
| 296 | }); |
| 297 | Image closeImage = new Image("images/close_icon2.jpg", 15.0, 15.0, true, true); |
| 298 | MenuItem close = new MenuItem(label.close, new ImageView(closeImage)); |
| 299 | closeAll = new MenuItem(label.closeAll); |
| 300 | fileMenu.getItems().addAll(newFileMenu, open, save, saveAll, saveAs, new SeparatorMenuItem(), close, closeAll, new SeparatorMenuItem(), exit); |
| 301 | |
| 302 | OFA_MenuBar.getMenus().addAll(fileMenu); |
| 303 | } |
| 304 | |
| 305 | public void getProjectExplorer() { |
| 306 | |
| 307 | projectWorkSpacePath = label.hierarchyTestON + "/tests/"; |
| 308 | File[] file = File.listRoots(); |
| 309 | Path name = new File(projectWorkSpacePath).toPath(); |
| 310 | OFALoadTree treeNode = new OFALoadTree(name); |
| 311 | |
| 312 | treeNode.setExpanded(true); |
| 313 | projectExplorerTree = treeNode; |
| 314 | for (int i = 0; i < treeNode.getChildren().size(); i++) { |
| 315 | if (treeNode.getChildren().get(i).getValue().equals("__init__")) { |
| 316 | treeNode.getChildren().remove(treeNode.getChildren().get(i)); |
| 317 | } |
| 318 | } |
| 319 | projectExplorerTreeView = new TreeView<String>(treeNode); |
| 320 | VBox projectExpl = new VBox(); |
| 321 | Button newTest = new Button("New Test"); |
| 322 | projectExplorerTreeView.setMinHeight(scene.getHeight() - (40 + toolBarHeight + menuBarHeight)); |
| 323 | projectExpl.getChildren().addAll(newTest, projectExplorerTreeView); |
| 324 | projectExplorer = new TitledPane("Project Explorer", projectExpl); |
| 325 | projectExplorer.setContent(projectExpl); |
| 326 | |
| 327 | newTest.setOnAction(new EventHandler<ActionEvent>() { |
| 328 | @Override |
| 329 | public void handle(ActionEvent t) { |
| 330 | wizard = new OFAWizard(projectExplorerTree, 1, projectExplorerTree.getChildren(), projectExplorerTreeView); |
| 331 | wizard.setOFA(OFAReference); |
| 332 | try { |
| 333 | wizard.start(new Stage()); |
| 334 | } catch (Exception ex) { |
| 335 | Logger.getLogger(TAI_OFA.class.getName()).log(Level.SEVERE, null, ex); |
| 336 | } |
| 337 | } |
| 338 | }); |
| 339 | |
| 340 | projectExplorerTreeView.setOnMouseClicked(new EventHandler<MouseEvent>() { |
| 341 | @Override |
| 342 | public void handle(MouseEvent arg0) { |
| 343 | |
| 344 | if (arg0.getButton() == MouseButton.SECONDARY) { |
| 345 | contextMenu(); |
| 346 | contextMenu.show(projectExplorerTreeView, arg0.getScreenX(), arg0.getScreenY()); |
| 347 | |
| 348 | } else if (arg0.getClickCount() == 2) { |
| 349 | String path = ""; |
| 350 | TreeItem<String> selectedTreeItem = projectExplorerTreeView.getSelectionModel().getSelectedItem(); |
| 351 | try { |
| 352 | |
| 353 | path = label.hierarchyTestON + "/tests/" + selectedTreeItem.getParent().getValue().toString() + "/" + selectedTreeItem.getValue(); |
| 354 | if (selectedTreeItem.isLeaf()) { |
| 355 | if (selectedTreeItem.getGraphic().getId().equals(".params")) { |
| 356 | path = path + ".params"; |
| 357 | } else if (selectedTreeItem.getGraphic().getId().equals(".topo")) { |
| 358 | path = path + ".topo"; |
| 359 | } else if (selectedTreeItem.getGraphic().getId().equals(".py")) { |
| 360 | path = path + ".py"; |
| 361 | } else if (selectedTreeItem.getGraphic().getId().equals(".ospk")) { |
| 362 | path = path + ".ospk"; |
| 363 | } |
| 364 | String fileContent = fileOperation.getContents(new File(path)); |
| 365 | editorFlag = true; |
| 366 | checkEditor(); |
| 367 | OFATabEditor(new CodeEditor(fileContent), new CodeEditorParams(fileContent), new File(path).getAbsolutePath(), ""); |
| 368 | } else if (!selectedTreeItem.isLeaf()) { |
| 369 | } |
| 370 | |
| 371 | |
| 372 | |
| 373 | } catch (Exception e) { |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | }); |
| 378 | |
| 379 | projectExplorerTreeView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() { |
| 380 | @Override |
| 381 | public void changed(ObservableValue observable, Object oldValus, Object newValue) { |
| 382 | ObservableList<TreeItem<String>> tata = projectExplorerTreeView.getSelectionModel().getSelectedItems(); |
| 383 | |
| 384 | TreeItem treeItem = (TreeItem) newValue; |
| 385 | } |
| 386 | }); |
| 387 | |
| 388 | |
| 389 | explorerTab.setOnClosed(new EventHandler<Event>() { |
| 390 | @Override |
| 391 | public void handle(Event closeEvent) { |
| 392 | explorerTabPane.setVisible(false); |
| 393 | projectExplorerFlag = false; |
| 394 | checkEditor(); |
| 395 | |
| 396 | } |
| 397 | }); |
| 398 | |
| 399 | |
| 400 | } |
| 401 | |
| 402 | public void loadLogExlporer() { |
| 403 | String projectWorkSpacePaths = label.hierarchyTestON + "/logs/"; |
| 404 | File[] file = File.listRoots(); |
| 405 | Path name = new File(projectWorkSpacePaths).toPath(); |
| 406 | OFALoadTree treeNode = new OFALoadTree(name); |
| 407 | treeNode.setExpanded(true); |
| 408 | logExplorerTreeView = new TreeView<String>(treeNode); |
| 409 | } |
| 410 | |
| 411 | public void getLogExplorer() { |
| 412 | |
| 413 | loadLogExlporer(); |
| 414 | VBox logExpl = new VBox(); |
| 415 | logExplorerTreeView.setMinHeight(scene.getHeight() - (toolBarHeight + menuBarHeight + 20)); |
| 416 | logExpl.getChildren().addAll(logExplorerTreeView); |
| 417 | logExlorer = new TitledPane("Log Explorer", logExpl); |
| 418 | |
| 419 | VBox logExplore = new VBox(); |
| 420 | Button refresh = new Button("refresh"); |
| 421 | logExplorerTreeView.setMinHeight(scene.getHeight() - (40 + toolBarHeight + menuBarHeight)); |
| 422 | logExplore.getChildren().addAll(refresh, logExplorerTreeView); |
| 423 | logExlorer.setContent(logExplore); |
| 424 | |
| 425 | refresh.setOnAction(new EventHandler<ActionEvent>() { |
| 426 | @Override |
| 427 | public void handle(ActionEvent t) { |
| 428 | String projectWorkSpacePaths = label.hierarchyTestON + "/logs/"; |
| 429 | File[] file = File.listRoots(); |
| 430 | Path name = new File(projectWorkSpacePaths).toPath(); |
| 431 | OFALoadTree treeNode = new OFALoadTree(name); |
| 432 | treeNode.setExpanded(true); |
| 433 | |
| 434 | logExplorerTreeView.setRoot(treeNode); |
| 435 | } |
| 436 | }); |
| 437 | |
| 438 | |
| 439 | logExplorerTreeView.setOnMouseClicked(new EventHandler<MouseEvent>() { |
| 440 | @Override |
| 441 | public void handle(MouseEvent click) { |
| 442 | if (click.getClickCount() == 2 && click.getButton() == MouseButton.PRIMARY) { |
| 443 | TreeItem<String> selectedItem = logExplorerTreeView.getSelectionModel().getSelectedItem(); |
| 444 | String fileExtentsion = selectedItem.getGraphic().getId(); |
| 445 | String selectedFilePath = label.hierarchyTestON + "/logs/" + selectedItem.getParent().getValue() + "/" + selectedItem.getValue() + fileExtentsion; |
| 446 | String fileContent = fileOperation.getContents(new File(selectedFilePath)); |
| 447 | editorFlag = true; |
| 448 | |
| 449 | checkEditor(); |
| 450 | OFATabEditor(new CodeEditor(fileContent), new CodeEditorParams(""), new File(selectedFilePath).getAbsolutePath(), ""); |
| 451 | } |
| 452 | } |
| 453 | }); |
| 454 | } |
| 455 | |
| 456 | public void getDriverExplorer() { |
| 457 | |
| 458 | projectWorkSpacePath = label.hierarchyTestON + "/drivers/common"; |
| 459 | |
| 460 | final Node rootIcon = new ImageView(new Image(getClass().getResourceAsStream("/images/project.jpeg"), 16, 16, true, true)); |
| 461 | driverExplorerTree = new TreeItem<String>("Drivers"); |
| 462 | File[] file = File.listRoots(); |
| 463 | |
| 464 | Path name = new File(projectWorkSpacePath).toPath(); |
| 465 | OFALoadTree treeNode = new OFALoadTree(name); |
| 466 | |
| 467 | driverExplorerTree.setExpanded(true); |
| 468 | //create the tree view |
| 469 | driverExplorerTreeView = new TreeView<String>(treeNode); |
| 470 | driverExplorer = new TitledPane("Driver Explorer", driverExplorerTreeView); |
| 471 | |
| 472 | driverExplorer.prefHeight(scene.heightProperty().get()); |
| 473 | |
| 474 | VBox driverExpl = new VBox(); |
| 475 | driverExpl.getChildren().addAll(new Button("New Driver"), driverExplorerTreeView); |
| 476 | driverExplorerTreeView.setShowRoot(false); |
| 477 | driverExplorerTreeView.setMinHeight(scene.getHeight() - (toolBarHeight + menuBarHeight + 50)); |
| 478 | |
| 479 | driverExplorer.setContent(driverExpl); |
| 480 | driverExplorer.prefHeight(scene.heightProperty().get()); |
| 481 | |
| 482 | |
| 483 | ObservableList<TreeItem<String>> children = driverExplorerTree.getChildren(); |
| 484 | Iterator<TreeItem<String>> tree = children.iterator(); |
| 485 | while (tree.hasNext()) { |
| 486 | TreeItem<String> value = tree.next(); |
| 487 | if (value.getValue().equals("common")) { |
| 488 | driverExplorerTreeView.setShowRoot(false); |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | driverExplorerTreeView.setOnMouseClicked(new EventHandler<MouseEvent>() { |
| 493 | @Override |
| 494 | public void handle(MouseEvent event) { |
| 495 | |
| 496 | if (event.getClickCount() == 1 && event.getButton() == MouseButton.PRIMARY) { |
| 497 | //final Node rootIcon = new ImageView(new Image(getClass().getResourceAsStream("/images/project.jpeg"))); |
| 498 | TreeItem<String> driverSelectedItem = driverExplorerTreeView.getSelectionModel().getSelectedItem(); |
| 499 | |
| 500 | try { |
| 501 | String[] splitSelectedDriver = driverSelectedItem.getValue().split("\\."); |
| 502 | |
| 503 | String path = null; |
| 504 | TreeItem selectedTreeItem = driverSelectedItem.getParent(); |
| 505 | TreeItem selectedParentItem = selectedTreeItem.getParent(); |
| 506 | |
| 507 | path = projectWorkSpacePath + "/" + driverSelectedItem.getParent().getParent().getValue() + "/" + driverSelectedItem.getParent().getValue() |
| 508 | + "/" + driverSelectedItem.getValue() + ".py"; |
| 509 | |
| 510 | if (driverSelectedItem.getParent().getValue().equals("emulator")) { |
| 511 | path = projectWorkSpacePath + "/" + driverSelectedItem.getParent().getParent().getValue() + "/" + driverSelectedItem.getParent().getValue() |
| 512 | + "/" + driverSelectedItem.getValue() + ".py"; |
| 513 | } else if (driverSelectedItem.getParent().getValue().equals("api")) { |
| 514 | path = projectWorkSpacePath + "/" + driverSelectedItem.getParent().getValue() + "/" + driverSelectedItem.getValue() + ".py"; |
| 515 | } else if (driverSelectedItem.getParent().getValue().equals("tool")) { |
| 516 | path = projectWorkSpacePath + "/" + driverSelectedItem.getParent().getParent().getValue() + "/" + driverSelectedItem.getParent().getValue() |
| 517 | + "/" + driverSelectedItem.getValue() + ".py"; |
| 518 | } else if (driverSelectedItem.getParent().getValue().equals("cli")) { |
| 519 | path = projectWorkSpacePath + "/" + driverSelectedItem.getParent().getValue() + "/" + driverSelectedItem.getValue() + ".py"; |
| 520 | } |
| 521 | String fileContent = fileOperation.getContents(new File(path)); |
| 522 | projectExplorerFlag = true; |
| 523 | checkEditor(); |
| 524 | OFATabEditor(new CodeEditor(fileContent), new CodeEditorParams(""), path, driverSelectedItem.getValue()); |
| 525 | |
| 526 | |
| 527 | } catch (Exception e) { |
| 528 | } |
| 529 | |
| 530 | } |
| 531 | } |
| 532 | }); |
| 533 | |
| 534 | |
| 535 | |
| 536 | driverExplorerTreeView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() { |
| 537 | @Override |
| 538 | public void changed(ObservableValue observable, Object oldValus, Object newValue) { |
| 539 | ObservableList<TreeItem<String>> tata = projectExplorerTreeView.getSelectionModel().getSelectedItems(); |
| 540 | |
| 541 | TreeItem treeItem = (TreeItem) newValue; |
| 542 | } |
| 543 | }); |
| 544 | |
| 545 | driverExplorerTree.setExpanded(true); |
| 546 | |
| 547 | } |
| 548 | |
| 549 | public void contextMenu() { |
| 550 | contextMenu = new ContextMenu(); |
| 551 | Image copyImage = new Image("images/Copy.png", 20.0, 20.0, true, true); |
| 552 | Image cutImage = new Image("images/Cut.png", 20.0, 20.0, true, true); |
| 553 | Image pasteImage = new Image("images/Paste.jpg", 20.0, 20.0, true, true); |
| 554 | Image deleteImage = new Image("images/delete.png", 20.0, 20.0, true, true); |
| 555 | |
| 556 | Menu newContextMenu = new Menu(label.contextNew); |
| 557 | MenuItem scriptContextMenu = new MenuItem(label.contextTest); |
| 558 | newContextMenu.getItems().add(scriptContextMenu); |
| 559 | MenuItem openContextMenu = new MenuItem(label.contextOpen); |
| 560 | MenuItem cutContextMenu = new MenuItem(label.contextCut, new ImageView(cutImage)); |
| 561 | MenuItem copyContextMenu = new MenuItem(label.contextCopy, new ImageView(copyImage)); |
| 562 | MenuItem pasteContextMenu = new MenuItem(label.contextPaste, new ImageView(pasteImage)); |
| 563 | MenuItem refreshContextMenu = new MenuItem(label.contextRefresh); |
| 564 | MenuItem deleteContextMenu = new MenuItem(label.contextDelete, new ImageView(deleteImage)); |
| 565 | |
| 566 | refreshContextMenu.setOnAction(new EventHandler<ActionEvent>() { |
| 567 | @Override |
| 568 | public void handle(ActionEvent t) { |
| 569 | refreshLogExplorer(); |
| 570 | } |
| 571 | }); |
| 572 | |
| 573 | openContextMenu.setOnAction(new EventHandler<ActionEvent>() { |
| 574 | @Override |
| 575 | public void handle(ActionEvent args0) { |
| 576 | TreeItem<String> selectedTreeItem = projectExplorerTreeView.getSelectionModel().getSelectedItem(); |
| 577 | |
| 578 | } |
| 579 | }); |
| 580 | |
| 581 | contextMenu.getItems().addAll(newContextMenu, openContextMenu, cutContextMenu, copyContextMenu, pasteContextMenu, refreshContextMenu, deleteContextMenu); |
| 582 | projectExplorerTreeView.contextMenuProperty().setValue(contextMenu); |
| 583 | scriptContextMenu.setOnAction(new EventHandler<ActionEvent>() { |
| 584 | @Override |
| 585 | public void handle(ActionEvent arg0) { |
| 586 | } |
| 587 | }); |
| 588 | } |
| 589 | |
| 590 | public void getEditMenu() { |
| 591 | //adding Edit Menu |
| 592 | Image copyImage = new Image("images/Copy.png", 20.0, 20.0, true, true); |
| 593 | Image cutImage = new Image("images/Cut.png", 20.0, 20.0, true, true); |
| 594 | Image pasteImage = new Image("images/Paste.jpg", 20.0, 20.0, true, true); |
| 595 | |
| 596 | |
| 597 | Menu editMenu = new Menu(label.editMenu); |
| 598 | MenuItem cut = new MenuItem(label.cut, new ImageView(cutImage)); |
| 599 | MenuItem copy = new MenuItem(label.copy, new ImageView(copyImage)); |
| 600 | MenuItem paste = new MenuItem(label.paste, new ImageView(pasteImage)); |
| 601 | MenuItem select = new MenuItem(label.select); |
| 602 | MenuItem selectAll = new MenuItem(label.selectAll); |
| 603 | |
| 604 | editMenu.getItems().addAll(cut, copy, paste, select, selectAll); |
| 605 | OFA_MenuBar.getMenus().addAll(editMenu); |
| 606 | |
| 607 | |
| 608 | } |
| 609 | |
| 610 | public void getViewMenu() { |
| 611 | //add View Menu |
| 612 | Menu viewMenu = new Menu(label.viewMenu); |
| 613 | MenuItem Explorer = new MenuItem("Explorer"); |
| 614 | MenuItem commandOptions = new MenuItem("CommandLine Explorer"); |
| 615 | |
| 616 | |
| 617 | viewMenu.getItems().addAll(Explorer, commandOptions); |
| 618 | OFA_MenuBar.getMenus().addAll(viewMenu); |
| 619 | |
| 620 | Explorer.setOnAction(new EventHandler<ActionEvent>() { |
| 621 | @Override |
| 622 | public void handle(ActionEvent t) { |
| 623 | |
| 624 | explorerTab = new Tab("Explorer"); |
| 625 | explorerTabPane.setLayoutX(0); |
| 626 | projectExplorerFlag = true; |
| 627 | |
| 628 | explorerTab.setContent(explorer); |
| 629 | |
| 630 | explorerTabPane.getTabs().addAll(explorerTab); |
| 631 | editorTabPane.setLayoutX(270); |
| 632 | explorerTabPane.setVisible(true); |
| 633 | projectExplorerFlag = true; |
| 634 | |
| 635 | |
| 636 | checkEditor(); |
| 637 | |
| 638 | |
| 639 | } |
| 640 | }); |
| 641 | |
| 642 | |
| 643 | } |
| 644 | |
| 645 | public void getToolBar() { |
| 646 | Image newImage = new Image("images/newIcon.jpg", 20.0, 20.0, true, true); |
| 647 | MenuButton New = new MenuButton("", new ImageView(newImage)); |
| 648 | New.setTooltip(new Tooltip("New")); |
| 649 | MenuItem newTest = new MenuItem("New Test"); |
| 650 | MenuItem componentDriver = new MenuItem(label.newDriver); |
| 651 | MenuItem newParams = new MenuItem(label.newParams); |
| 652 | MenuItem newTopology = new MenuItem(label.newTopology); |
| 653 | MenuItem testScript = new MenuItem(label.newTestScript); |
| 654 | |
| 655 | New.getItems().addAll(newTest, componentDriver, newParams, newTopology, testScript); |
| 656 | New.setMinWidth(2); |
| 657 | |
| 658 | newTest.setOnAction(new EventHandler<ActionEvent>() { |
| 659 | @Override |
| 660 | public void handle(ActionEvent t) { |
| 661 | wizard = new OFAWizard(projectExplorerTree, 1, projectExplorerTree.getChildren(), projectExplorerTreeView); |
| 662 | wizard.setOFA(OFAReference); |
| 663 | try { |
| 664 | wizard.start(new Stage()); |
| 665 | } catch (Exception ex) { |
| 666 | Logger.getLogger(TAI_OFA.class.getName()).log(Level.SEVERE, null, ex); |
| 667 | } |
| 668 | } |
| 669 | }); |
| 670 | |
| 671 | |
| 672 | newParams.setOnAction(new EventHandler<ActionEvent>() { |
| 673 | @Override |
| 674 | public void handle(ActionEvent arg0) { |
| 675 | try { |
| 676 | wizard = new OFAWizard(projectExplorerTree, 2, projectExplorerTree.getChildren(), projectExplorerTreeView); |
| 677 | wizard.setOFA(OFAReference); |
| 678 | wizard.start(new Stage()); |
| 679 | |
| 680 | } catch (Exception ex) { |
| 681 | Logger.getLogger(TAI_OFA.class.getName()).log(Level.SEVERE, null, ex); |
| 682 | } |
| 683 | } |
| 684 | }); |
| 685 | |
| 686 | //Open Icon on Tool Bar |
| 687 | Image openImage = new Image("images/open.png", 20.0, 20.0, true, true); |
| 688 | MenuButton Open = new MenuButton("", new ImageView(openImage)); |
| 689 | Open.setTooltip(new Tooltip("Open")); |
| 690 | MenuItem openComponentDriver = new MenuItem(label.newDriver); |
| 691 | MenuItem openParams = new MenuItem(label.newParams); |
| 692 | MenuItem openTopology = new MenuItem(label.newTopology); |
| 693 | MenuItem openTestScript = new MenuItem(label.newTestScript); |
| 694 | |
| 695 | Open.getItems().addAll(openComponentDriver, openParams, openTopology, openTestScript); |
| 696 | Image saveImage = new Image("images/Save_24x24.png", 20.0, 20.0, true, true); |
| 697 | Save = new Button("", new ImageView(saveImage)); |
| 698 | Save.setTooltip(new Tooltip("Save")); |
| 699 | |
| 700 | Image configImage = new Image("images/project_1.jpeg", 20.0, 20.0, true, true); |
| 701 | Button configuration = new Button("", new ImageView(configImage)); |
| 702 | configuration.setTooltip(new Tooltip("Run With ...")); |
| 703 | |
| 704 | Image playImage = new Image("images/Play.png", 20.0, 20.0, true, true); |
| 705 | MenuButton play = new MenuButton("", new ImageView(playImage)); |
| 706 | play.setTooltip(new Tooltip("Run")); |
| 707 | |
| 708 | MenuItem run = new MenuItem("Run"); |
| 709 | MenuItem runWithOptionButton = new MenuItem("Run With ..."); |
| 710 | |
| 711 | play.getItems().addAll(run, runWithOptionButton); |
| 712 | Image pauseImage = new Image("images/Pause.png", 20.0, 20.0, true, true); |
| 713 | Button pause = new Button("", new ImageView(pauseImage)); |
| 714 | pause.setTooltip(new Tooltip("Pause")); |
| 715 | |
| 716 | run.setOnAction(new EventHandler<ActionEvent>() { |
| 717 | @Override |
| 718 | public void handle(ActionEvent t) { |
| 719 | testSummaryPop = new OFATestSummary(OFAReference, copyStage); |
| 720 | testSummaryPop.start(new Stage()); |
| 721 | Runnable firstRunnable = new Runnable() { |
| 722 | @Override |
| 723 | public void run() { |
| 724 | try { |
| 725 | } catch (Exception e) { |
| 726 | e.printStackTrace(); |
| 727 | } |
| 728 | } |
| 729 | }; |
| 730 | Runnable secondRunnable = new Runnable() { |
| 731 | @Override |
| 732 | public void run() { |
| 733 | try { |
| 734 | ExecuteTest testExecute = new ExecuteTest(testSummaryPop.getTable(), testSummaryPop.getData(), testSummaryPop.getChart(), |
| 735 | testSummaryPop.getFinalSummaryTable(), testSummaryPop.getFinalSummaryData(), |
| 736 | testSummaryPop.getVieLogsButton(), testSummaryPop.getpieChartData(), |
| 737 | testSummaryPop.getPassData(), testSummaryPop.getFailData(), testSummaryPop.getAbortData(), |
| 738 | testSummaryPop.getNoResultData(), editorTabPane.getSelectionModel().getSelectedItem().getText().substring(0, editorTabPane.getSelectionModel().getSelectedItem().getText().lastIndexOf('.')), testSummaryPop.getTextArea("log"), testSummaryPop.getStepTable(), testSummaryPop.getStepData(), testSummaryPop.getTextArea("pox"), testSummaryPop.getTextArea("mininet"), testSummaryPop.getTextArea("flowvisor")); |
| 739 | |
| 740 | testExecute.runTest(); |
| 741 | } catch (Exception iex) { |
| 742 | } |
| 743 | } |
| 744 | }; |
| 745 | |
| 746 | Platform.runLater(firstRunnable); |
| 747 | Platform.runLater(secondRunnable); |
| 748 | } |
| 749 | }); |
| 750 | |
| 751 | |
| 752 | runWithOptionButton.setOnAction(new EventHandler<ActionEvent>() { |
| 753 | @Override |
| 754 | public void handle(ActionEvent t) { |
| 755 | OFATestParameters testParameter = new OFATestParameters(OFAReference); |
| 756 | testParameter.setProjectView(projectExplorerTreeView); |
| 757 | testParameter.setProjectList(projectExplorerTree.getChildren()); |
| 758 | testParameter.start(new Stage()); |
| 759 | } |
| 760 | }); |
| 761 | |
| 762 | Image stopImage = new Image("images/Stop.png", 20.0, 20.0, true, true); |
| 763 | Button stop = new Button("", new ImageView(stopImage)); |
| 764 | stop.setTooltip(new Tooltip("Stop")); |
| 765 | |
| 766 | Image resumeImage = new Image("images/Resume_1.png", 20.0, 20.0, true, true); |
| 767 | Button resume = new Button("", new ImageView(resumeImage)); |
| 768 | resume.setTooltip(new Tooltip("Resume")); |
| 769 | |
| 770 | Image copyImage = new Image("images/Copy.png", 20.0, 20.0, true, true); |
| 771 | Button copy = new Button("", new ImageView(copyImage)); |
| 772 | copy.setTooltip(new Tooltip("Copy")); |
| 773 | |
| 774 | Image cutImage = new Image("images/Cut.png", 20.0, 20.0, true, true); |
| 775 | Button cut = new Button("", new ImageView(cutImage)); |
| 776 | cut.setTooltip(new Tooltip("Cut")); |
| 777 | |
| 778 | Image pasteImage = new Image("images/Paste.jpg", 20.0, 20.0, true, true); |
| 779 | Button paste = new Button("", new ImageView(pasteImage)); |
| 780 | paste.setTooltip(new Tooltip("Paste")); |
| 781 | |
| 782 | Image exitImage = new Image("images/exit.gif", 20.0, 20.0, true, true); |
| 783 | Button exit = new Button("", new ImageView(exitImage)); |
| 784 | exit.setTooltip(new Tooltip("Exit")); |
| 785 | |
| 786 | |
| 787 | |
| 788 | |
| 789 | toolbar.getItems().addAll(New, Open, Save, new Separator(Orientation.VERTICAL), cut, copy, paste, new Separator(Orientation.VERTICAL), configuration, play, pause, stop, resume, new Separator(Orientation.VERTICAL), exit); |
| 790 | |
| 791 | } |
| 792 | |
| 793 | public void getRunMenu() { |
| 794 | //adding Run Menu |
| 795 | Menu runMenu = new Menu(label.runMenu); |
| 796 | Image pauseImage = new Image("images/Pause.png", 20.0, 20.0, true, true); |
| 797 | Image playImage = new Image("images/Play.png", 20.0, 20.0, true, true); |
| 798 | Image stopImage = new Image("images/Stop.png", 20.0, 20.0, true, true); |
| 799 | Image configImage = new Image("images/Settings.jpg", 20.0, 20.0, true, true); |
| 800 | Image resumeImage = new Image("images/Resume_1.png", 20.0, 20.0, true, true); |
| 801 | |
| 802 | |
| 803 | MenuItem run = new MenuItem(label.runMenu, new ImageView(playImage)); |
| 804 | MenuItem pause = new MenuItem(label.pauseTest, new ImageView(pauseImage)); |
| 805 | MenuItem resume = new MenuItem(label.resumeTest, new ImageView(resumeImage)); |
| 806 | MenuItem stop = new MenuItem(label.stopTest, new ImageView(stopImage)); |
| 807 | MenuItem config = new MenuItem("Settings", new ImageView(configImage)); |
| 808 | |
| 809 | runMenu.getItems().addAll(run, pause, resume, stop, new SeparatorMenuItem(), config); |
| 810 | OFA_MenuBar.getMenus().addAll(runMenu); |
| 811 | } |
| 812 | |
| 813 | public void getHelpMenu() { |
| 814 | //adding Help Menu |
| 815 | Menu helpMenu = new Menu(label.helpMenu); |
| 816 | MenuItem about = new MenuItem(label.aboutHelp); |
| 817 | MenuItem help = new MenuItem(label.helpMenu); |
| 818 | |
| 819 | helpMenu.getItems().addAll(about, help); |
| 820 | OFA_MenuBar.getMenus().addAll(helpMenu); |
| 821 | } |
| 822 | |
| 823 | public void OFATabEditor(final CodeEditor Content, final CodeEditorParams ContentParams, final String title, String str) { |
| 824 | //saveFileItem.setDisable(false); |
| 825 | ContentParams.setOFA(OFAReference); |
| 826 | |
| 827 | final Tab editorTab = new Tab(); |
| 828 | final File fileName; |
| 829 | ObservableList<Tab> allTab = editorTabPane.getTabs(); |
| 830 | if (allTab.isEmpty()) { |
| 831 | String fname = ""; |
| 832 | String ext = ""; |
| 833 | int mid = title.lastIndexOf("."); |
| 834 | fname = title.substring(0, mid); |
| 835 | ext = title.substring(mid + 1, title.length()); |
| 836 | |
| 837 | if ("params".equals(ext) || "topo".equals(ext)) { |
| 838 | |
| 839 | ContentParams.prefWidthProperty().bind(scene.widthProperty().subtract(270)); |
| 840 | |
| 841 | fileName = new File(title); |
| 842 | editorTab.setText(fileName.getName()); |
| 843 | editorTab.setContent(ContentParams); |
| 844 | editorTab.setId(title); |
| 845 | String currentTab1 = editorTab.getId(); |
| 846 | |
| 847 | editorTabPane.getTabs().add(editorTab); |
| 848 | |
| 849 | javafx.scene.control.SingleSelectionModel<Tab> selectionModel = editorTabPane.getSelectionModel(); |
| 850 | selectionModel.select(editorTab); |
| 851 | ContentParams.setOnKeyReleased(new EventHandler<InputEvent>() { |
| 852 | @Override |
| 853 | public void handle(InputEvent arg0) { |
| 854 | javafx.scene.control.SingleSelectionModel<Tab> selectionModel = editorTabPane.getSelectionModel(); |
| 855 | String currentTab1 = selectionModel.getSelectedItem().getId(); |
| 856 | String currentTabTitle = selectionModel.getSelectedItem().getText(); |
| 857 | if (fileName.getName().equals(currentTabTitle)) { |
| 858 | selectionModel.getSelectedItem().setText("* " + currentTabTitle); |
| 859 | Save.setOnAction(new EventHandler<ActionEvent>() { |
| 860 | @Override |
| 861 | public void handle(ActionEvent arg0) { |
| 862 | |
| 863 | javafx.scene.control.SingleSelectionModel<Tab> selectionModel = editorTabPane.getSelectionModel(); |
| 864 | String currentTab1 = selectionModel.getSelectedItem().getId(); |
| 865 | selectionModel.getSelectedItem().setText(fileName.getName()); |
| 866 | String currentFileContent = ContentParams.getCodeAndSnapshot(); |
| 867 | |
| 868 | try { |
| 869 | |
| 870 | ArrayList<String> textContent = new ArrayList<String>(); |
| 871 | String textAreaCon = ContentParams.getCodeAndSnapshot(); |
| 872 | |
| 873 | String[] textAreaContent = textAreaCon.split("\n"); |
| 874 | |
| 875 | for (String string : textAreaContent) { |
| 876 | textContent.add(string); |
| 877 | } |
| 878 | |
| 879 | HashMap errorHash = new HashMap(); |
| 880 | fileOperation.saveFile(fileName, currentFileContent); |
| 881 | } catch (FileNotFoundException ex) { |
| 882 | Logger.getLogger(TAI_OFA.class.getName()).log(Level.SEVERE, null, ex); |
| 883 | } catch (IOException ex) { |
| 884 | Logger.getLogger(TAI_OFA.class.getName()).log(Level.SEVERE, null, ex); |
| 885 | } |
| 886 | |
| 887 | } |
| 888 | }); |
| 889 | } else { |
| 890 | } |
| 891 | } |
| 892 | }); |
| 893 | |
| 894 | } else { |
| 895 | fileName = new File(title); |
| 896 | |
| 897 | editorTab.setText(fileName.getName()); |
| 898 | editorTab.setId(title); |
| 899 | Content.prefWidthProperty().bind(scene.widthProperty()); |
| 900 | editorTab.setContent(Content); |
| 901 | String currentTab = editorTab.getId(); |
| 902 | |
| 903 | editorTabPane.getTabs().addAll(editorTab); |
| 904 | |
| 905 | javafx.scene.control.SingleSelectionModel<Tab> selectionModel = editorTabPane.getSelectionModel(); |
| 906 | selectionModel.select(editorTab); |
| 907 | Content.setOnKeyReleased(new EventHandler<InputEvent>() { |
| 908 | @Override |
| 909 | public void handle(InputEvent arg0) { |
| 910 | javafx.scene.control.SingleSelectionModel<Tab> selectionModel = editorTabPane.getSelectionModel(); |
| 911 | String currentTab = selectionModel.getSelectedItem().getId(); |
| 912 | File file = new File(currentTab); |
| 913 | |
| 914 | String currentTabTitle = selectionModel.getSelectedItem().getText(); |
| 915 | |
| 916 | |
| 917 | if (file.getName().equals(currentTabTitle)) { |
| 918 | selectionModel.getSelectedItem().setText("* " + currentTabTitle); |
| 919 | Save.setOnAction(new EventHandler<ActionEvent>() { |
| 920 | @Override |
| 921 | public void handle(ActionEvent arg0) { |
| 922 | javafx.scene.control.SingleSelectionModel<Tab> selectionModel = editorTabPane.getSelectionModel(); |
| 923 | String currentTab = selectionModel.getSelectedItem().getId(); |
| 924 | File file = new File(currentTab); |
| 925 | selectionModel.getSelectedItem().setText(file.getName()); |
| 926 | File fileName = new File(currentTab); |
| 927 | String currentFileContent = Content.getCodeAndSnapshot(); |
| 928 | try { |
| 929 | fileOperation.saveFile(fileName, currentFileContent); |
| 930 | } catch (FileNotFoundException ex) { |
| 931 | Logger.getLogger(TAI_OFA.class.getName()).log(Level.SEVERE, null, ex); |
| 932 | } catch (IOException ex) { |
| 933 | Logger.getLogger(TAI_OFA.class.getName()).log(Level.SEVERE, null, ex); |
| 934 | } |
| 935 | |
| 936 | } |
| 937 | }); |
| 938 | } else { |
| 939 | } |
| 940 | |
| 941 | } |
| 942 | }); |
| 943 | |
| 944 | File path = new File(OFAReference.editorTabPane.getSelectionModel().getSelectedItem().getId()); |
| 945 | String[] currentFileExtintion = path.getName().split("\\."); |
| 946 | if (currentFileExtintion[1].equals("ospk")) { |
| 947 | OFAContentHelp contentHelp = new OFAContentHelp(Content, OFAReference); |
| 948 | contentHelp.ospkHelp(); |
| 949 | } |
| 950 | } |
| 951 | } else { |
| 952 | boolean tabexistsFlag = false; |
| 953 | for (Tab tab : allTab) { |
| 954 | if (tab.getId().equals(title)) { |
| 955 | javafx.scene.control.SingleSelectionModel<Tab> selectionModel = editorTabPane.getSelectionModel(); |
| 956 | selectionModel.select(tab); |
| 957 | tabexistsFlag = true; |
| 958 | break; |
| 959 | } else { |
| 960 | } |
| 961 | } |
| 962 | if (tabexistsFlag == false) { |
| 963 | |
| 964 | String fname = ""; |
| 965 | String ext = ""; |
| 966 | int mid = title.lastIndexOf("."); |
| 967 | fname = title.substring(0, mid); |
| 968 | ext = title.substring(mid + 1, title.length()); |
| 969 | |
| 970 | if ("params".equals(ext) || "topo".equals(ext)) { |
| 971 | |
| 972 | ContentParams.prefWidthProperty().bind(scene.widthProperty().subtract(500)); |
| 973 | |
| 974 | fileName = new File(title); |
| 975 | editorTab.setText(fileName.getName()); |
| 976 | editorTab.setContent(ContentParams); |
| 977 | editorTab.setId(title); |
| 978 | String currentTab1 = editorTab.getId(); |
| 979 | editorTabPane.getTabs().add(editorTab); |
| 980 | |
| 981 | javafx.scene.control.SingleSelectionModel<Tab> selectionModel = editorTabPane.getSelectionModel(); |
| 982 | selectionModel.select(editorTab); |
| 983 | |
| 984 | ContentParams.setOnKeyReleased(new EventHandler<InputEvent>() { |
| 985 | @Override |
| 986 | public void handle(InputEvent arg0) { |
| 987 | javafx.scene.control.SingleSelectionModel<Tab> selectionModel = editorTabPane.getSelectionModel(); |
| 988 | String currentTab1 = selectionModel.getSelectedItem().getId(); |
| 989 | |
| 990 | String currentTabTitle = selectionModel.getSelectedItem().getText(); |
| 991 | |
| 992 | if (fileName.getName().equals(currentTabTitle)) { |
| 993 | selectionModel.getSelectedItem().setText("* " + currentTabTitle); |
| 994 | Save.setOnAction(new EventHandler<ActionEvent>() { |
| 995 | @Override |
| 996 | public void handle(ActionEvent arg0) { |
| 997 | |
| 998 | javafx.scene.control.SingleSelectionModel<Tab> selectionModel = editorTabPane.getSelectionModel(); |
| 999 | String currentTab1 = selectionModel.getSelectedItem().getId(); |
| 1000 | |
| 1001 | selectionModel.getSelectedItem().setText(fileName.getName()); |
| 1002 | String currentFileContent = ContentParams.getCodeAndSnapshot(); |
| 1003 | try { |
| 1004 | fileOperation.saveFile(fileName, currentFileContent); |
| 1005 | } catch (FileNotFoundException ex) { |
| 1006 | Logger.getLogger(TAI_OFA.class.getName()).log(Level.SEVERE, null, ex); |
| 1007 | } catch (IOException ex) { |
| 1008 | Logger.getLogger(TAI_OFA.class.getName()).log(Level.SEVERE, null, ex); |
| 1009 | } |
| 1010 | |
| 1011 | } |
| 1012 | }); |
| 1013 | } else { |
| 1014 | } |
| 1015 | } |
| 1016 | }); |
| 1017 | } else { |
| 1018 | fileName = new File(title); |
| 1019 | |
| 1020 | editorTab.setText(fileName.getName()); |
| 1021 | editorTab.setId(title); |
| 1022 | Content.prefWidthProperty().bind(scene.widthProperty()); |
| 1023 | editorTab.setContent(Content); |
| 1024 | String currentTab = editorTab.getId(); |
| 1025 | |
| 1026 | editorTabPane.getTabs().addAll(editorTab); |
| 1027 | javafx.scene.control.SingleSelectionModel<Tab> selectionModel = editorTabPane.getSelectionModel(); |
| 1028 | selectionModel.select(editorTab); |
| 1029 | |
| 1030 | Content.setOnKeyReleased(new EventHandler<InputEvent>() { |
| 1031 | @Override |
| 1032 | public void handle(InputEvent arg0) { |
| 1033 | javafx.scene.control.SingleSelectionModel<Tab> selectionModel = editorTabPane.getSelectionModel(); |
| 1034 | String currentTab = selectionModel.getSelectedItem().getId(); |
| 1035 | File file = new File(currentTab); |
| 1036 | |
| 1037 | String currentTabTitle = selectionModel.getSelectedItem().getText(); |
| 1038 | |
| 1039 | |
| 1040 | if (file.getName().equals(currentTabTitle)) { |
| 1041 | selectionModel.getSelectedItem().setText("* " + currentTabTitle); |
| 1042 | Save.setOnAction(new EventHandler<ActionEvent>() { |
| 1043 | @Override |
| 1044 | public void handle(ActionEvent arg0) { |
| 1045 | javafx.scene.control.SingleSelectionModel<Tab> selectionModel = editorTabPane.getSelectionModel(); |
| 1046 | String currentTab = selectionModel.getSelectedItem().getId(); |
| 1047 | File file = new File(currentTab); |
| 1048 | selectionModel.getSelectedItem().setText(file.getName()); |
| 1049 | File fileName = new File(currentTab); |
| 1050 | String currentFileContent = Content.getCodeAndSnapshot(); |
| 1051 | try { |
| 1052 | fileOperation.saveFile(fileName, currentFileContent); |
| 1053 | } catch (FileNotFoundException ex) { |
| 1054 | Logger.getLogger(TAI_OFA.class.getName()).log(Level.SEVERE, null, ex); |
| 1055 | } catch (IOException ex) { |
| 1056 | Logger.getLogger(TAI_OFA.class.getName()).log(Level.SEVERE, null, ex); |
| 1057 | } |
| 1058 | |
| 1059 | } |
| 1060 | }); |
| 1061 | } else { |
| 1062 | } |
| 1063 | |
| 1064 | } |
| 1065 | }); |
| 1066 | |
| 1067 | File path = new File(OFAReference.editorTabPane.getSelectionModel().getSelectedItem().getId()); |
| 1068 | String[] currentFileExtintion = path.getName().split("\\."); |
| 1069 | if (currentFileExtintion[1].equals("ospk")) { |
| 1070 | OFAContentHelp contentHelp = new OFAContentHelp(Content, OFAReference); |
| 1071 | contentHelp.ospkHelp(); |
| 1072 | } |
| 1073 | } |
| 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | editorTab.setOnSelectionChanged(new EventHandler<Event>() { |
| 1078 | @Override |
| 1079 | public void handle(Event arg0) { |
| 1080 | |
| 1081 | String currentTab = editorTab.getId(); |
| 1082 | String fname = ""; |
| 1083 | String ext = ""; |
| 1084 | int mid = currentTab.lastIndexOf("."); |
| 1085 | fname = currentTab.substring(0, mid); |
| 1086 | try { |
| 1087 | } catch (ArrayIndexOutOfBoundsException e) { |
| 1088 | } |
| 1089 | |
| 1090 | |
| 1091 | |
| 1092 | final File fileName; |
| 1093 | if ("params".equals(ext) || "topo".equals(ext)) { |
| 1094 | |
| 1095 | |
| 1096 | Save.setOnAction(new EventHandler<ActionEvent>() { |
| 1097 | @Override |
| 1098 | public void handle(ActionEvent arg0) { |
| 1099 | javafx.scene.control.SingleSelectionModel<Tab> selectionModel = editorTabPane.getSelectionModel(); |
| 1100 | String currentTab = selectionModel.getSelectedItem().getId(); |
| 1101 | File file = new File(currentTab); |
| 1102 | selectionModel.getSelectedItem().setText(file.getName()); |
| 1103 | File fileName = new File(currentTab); |
| 1104 | String currentFileContent = ContentParams.getCodeAndSnapshot(); |
| 1105 | try { |
| 1106 | fileOperation.saveFile(fileName, currentFileContent); |
| 1107 | } catch (FileNotFoundException ex) { |
| 1108 | Logger.getLogger(TAI_OFA.class.getName()).log(Level.SEVERE, null, ex); |
| 1109 | } catch (IOException ex) { |
| 1110 | Logger.getLogger(TAI_OFA.class.getName()).log(Level.SEVERE, null, ex); |
| 1111 | } |
| 1112 | |
| 1113 | } |
| 1114 | }); |
| 1115 | |
| 1116 | } else { |
| 1117 | |
| 1118 | Save.setOnAction(new EventHandler<ActionEvent>() { |
| 1119 | @Override |
| 1120 | public void handle(ActionEvent arg0) { |
| 1121 | |
| 1122 | javafx.scene.control.SingleSelectionModel<Tab> selectionModel = editorTabPane.getSelectionModel(); |
| 1123 | String currentTab = selectionModel.getSelectedItem().getId(); |
| 1124 | File file = new File(currentTab); |
| 1125 | selectionModel.getSelectedItem().setText(file.getName()); |
| 1126 | File fileName = new File(currentTab); |
| 1127 | String currentFileContent = Content.getCodeAndSnapshot(); |
| 1128 | try { |
| 1129 | fileOperation.saveFile(fileName, currentFileContent); |
| 1130 | } catch (FileNotFoundException ex) { |
| 1131 | Logger.getLogger(TAI_OFA.class.getName()).log(Level.SEVERE, null, ex); |
| 1132 | } catch (IOException ex) { |
| 1133 | Logger.getLogger(TAI_OFA.class.getName()).log(Level.SEVERE, null, ex); |
| 1134 | } |
| 1135 | |
| 1136 | } |
| 1137 | }); |
| 1138 | } |
| 1139 | } |
| 1140 | }); |
| 1141 | |
| 1142 | //SaveAll Option in file menu click event |
| 1143 | |
| 1144 | saveAll.setOnAction(new EventHandler<ActionEvent>() { |
| 1145 | @Override |
| 1146 | public void handle(ActionEvent arg0) { |
| 1147 | |
| 1148 | ObservableList<Tab> allTab = editorTabPane.getTabs(); |
| 1149 | javafx.scene.control.SingleSelectionModel<Tab> selectedItemToGetBack = editorTabPane.getSelectionModel(); |
| 1150 | Tab selectedTabBeforeSaveAll = selectedItemToGetBack.getSelectedItem(); |
| 1151 | for (Tab tab : allTab) { |
| 1152 | javafx.scene.control.SingleSelectionModel<Tab> selectedItem = editorTabPane.getSelectionModel(); |
| 1153 | |
| 1154 | selectedItem.select(tab); |
| 1155 | String currentTab = tab.getId(); |
| 1156 | String fname = ""; |
| 1157 | String ext = ""; |
| 1158 | int mid = currentTab.lastIndexOf("."); |
| 1159 | fname = currentTab.substring(0, mid); |
| 1160 | ext = currentTab.substring(mid + 1, currentTab.length()); |
| 1161 | final File fileName; |
| 1162 | String checkModifier = selectedItem.getSelectedItem().getText(); |
| 1163 | File exactPath = new File(currentTab); |
| 1164 | String properName = exactPath.getName(); |
| 1165 | if (!checkModifier.equals(properName)) { |
| 1166 | |
| 1167 | if ("params".equals(ext) || "topo".equals(ext)) { |
| 1168 | javafx.scene.control.SingleSelectionModel<Tab> selectedItem1 = editorTabPane.getSelectionModel(); |
| 1169 | String currentTab1 = tab.getId(); |
| 1170 | File file = new File(currentTab1); |
| 1171 | |
| 1172 | File fileName1 = new File(currentTab1); |
| 1173 | selectedItem1.getSelectedItem().setText(fileName1.getName()); |
| 1174 | String currentFileContent = ((CodeEditorParams) tab.getContent()).getCodeAndSnapshot(); |
| 1175 | try { |
| 1176 | fileOperation.saveFile(fileName1, currentFileContent); |
| 1177 | } catch (FileNotFoundException ex) { |
| 1178 | Logger.getLogger(TAI_OFA.class.getName()).log(Level.SEVERE, null, ex); |
| 1179 | } catch (IOException ex) { |
| 1180 | Logger.getLogger(TAI_OFA.class.getName()).log(Level.SEVERE, null, ex); |
| 1181 | } |
| 1182 | |
| 1183 | |
| 1184 | } else { |
| 1185 | javafx.scene.control.SingleSelectionModel<Tab> selectedItem1 = editorTabPane.getSelectionModel(); |
| 1186 | String currentTab2 = tab.getId(); |
| 1187 | |
| 1188 | File fileName2 = new File(currentTab2); |
| 1189 | selectedItem1.getSelectedItem().setText(fileName2.getName()); |
| 1190 | String currentFileContent = ((CodeEditor) tab.getContent()).getCodeAndSnapshot(); |
| 1191 | try { |
| 1192 | fileOperation.saveFile(fileName2, currentFileContent); |
| 1193 | } catch (FileNotFoundException ex) { |
| 1194 | Logger.getLogger(TAI_OFA.class.getName()).log(Level.SEVERE, null, ex); |
| 1195 | } catch (IOException ex) { |
| 1196 | Logger.getLogger(TAI_OFA.class.getName()).log(Level.SEVERE, null, ex); |
| 1197 | } |
| 1198 | |
| 1199 | } |
| 1200 | |
| 1201 | } |
| 1202 | } |
| 1203 | selectedItemToGetBack.select(selectedTabBeforeSaveAll); |
| 1204 | } |
| 1205 | }); |
| 1206 | |
| 1207 | editorTab.setOnClosed(new EventHandler<Event>() { |
| 1208 | @Override |
| 1209 | public void handle(Event arg0) { |
| 1210 | javafx.scene.control.SingleSelectionModel<Tab> selectedItem1 = editorTabPane.getSelectionModel(); |
| 1211 | String fileName = editorTab.getId(); |
| 1212 | String tabName = editorTab.getText(); |
| 1213 | File tabIdentity = new File(fileName); |
| 1214 | String properName = tabIdentity.getName(); |
| 1215 | if (!properName.equals(tabName)) { |
| 1216 | int optionPressed = JOptionPane.showConfirmDialog(null, "Would you like to save the content of this tab\n"); |
| 1217 | if (optionPressed == 0) { |
| 1218 | String extension = fileOperation.getExtension(editorTab.getText()); |
| 1219 | if ("params".equals(extension) || "topo".equals(extension)) { |
| 1220 | try { |
| 1221 | String tabContent = ((CodeEditorParams) editorTab.getContent()).getCodeAndSnapshot(); |
| 1222 | fileOperation.saveFile(tabIdentity, tabContent); |
| 1223 | } catch (FileNotFoundException ex) { |
| 1224 | Logger.getLogger(TAI_OFA.class.getName()).log(Level.SEVERE, null, ex); |
| 1225 | } catch (IOException ex) { |
| 1226 | Logger.getLogger(TAI_OFA.class.getName()).log(Level.SEVERE, null, ex); |
| 1227 | } |
| 1228 | } else { |
| 1229 | try { |
| 1230 | String tabContent1 = ((CodeEditor) editorTab.getContent()).getCodeAndSnapshot(); |
| 1231 | fileOperation.saveFile(tabIdentity, tabContent1); |
| 1232 | } catch (FileNotFoundException ex) { |
| 1233 | Logger.getLogger(TAI_OFA.class.getName()).log(Level.SEVERE, null, ex); |
| 1234 | } catch (IOException ex) { |
| 1235 | Logger.getLogger(TAI_OFA.class.getName()).log(Level.SEVERE, null, ex); |
| 1236 | } |
| 1237 | } |
| 1238 | } |
| 1239 | } |
| 1240 | |
| 1241 | } |
| 1242 | }); |
| 1243 | |
| 1244 | closeAll.setOnAction(new EventHandler<ActionEvent>() { |
| 1245 | @Override |
| 1246 | public void handle(ActionEvent arg0) { |
| 1247 | Stage dialogStage = new Stage(); |
| 1248 | dialogStage.initModality(Modality.NONE); |
| 1249 | dialogStage.setScene(new Scene(VBoxBuilder.create(). |
| 1250 | children(new Text("Yes"), new Button("No")). |
| 1251 | alignment(Pos.CENTER).padding(new Insets(5)).build())); |
| 1252 | dialogStage.show(); |
| 1253 | |
| 1254 | |
| 1255 | } |
| 1256 | }); |
| 1257 | |
| 1258 | } |
| 1259 | |
| 1260 | public void openFile(String extension, String extension2) { |
| 1261 | File selected; |
| 1262 | String fileContent = ""; |
| 1263 | openParams = new FileChooser(); |
| 1264 | if ("".equals(extension2)) { |
| 1265 | openParams.getExtensionFilters().add(new ExtensionFilter("Display only (*." + extension + ") files", "*." + extension)); |
| 1266 | } else { |
| 1267 | openParams.getExtensionFilters().add(new ExtensionFilter("Display only (*." + extension + ")" + "files", "*." + extension)); |
| 1268 | openParams.getExtensionFilters().add(new ExtensionFilter("Display only (*." + extension2 + ") files", "*." + extension2)); |
| 1269 | } |
| 1270 | selected = openParams.showOpenDialog(contextMenu); |
| 1271 | try { |
| 1272 | fileContent = fileOperation.getContents(selected); |
| 1273 | checkEditor(); |
| 1274 | String filename = selected.getName(); |
| 1275 | checkEditor(); |
| 1276 | OFATabEditor(new CodeEditor(fileContent), new CodeEditorParams(fileContent), selected.getAbsolutePath(), ""); |
| 1277 | } catch (Exception e) { |
| 1278 | } |
| 1279 | |
| 1280 | editorTabPane.prefWidthProperty().bind(scene.widthProperty().subtract(200)); |
| 1281 | } |
| 1282 | |
| 1283 | public void checkEditor() { |
| 1284 | if (projectExplorerFlag == false && editorFlag == false) { |
| 1285 | editorFlag = true; |
| 1286 | editorTabPane.prefHeightProperty().bind(scene.heightProperty().subtract(40)); |
| 1287 | editorTabPane.setLayoutX(explorerTabPane.getLayoutX()); |
| 1288 | editorTabPane.setMaxWidth(OFAContainerWidth); |
| 1289 | } else if (projectExplorerFlag == true && editorFlag == false) { |
| 1290 | editorFlag = true; |
| 1291 | editorTabPane.setLayoutX(explorerTabPane.getLayoutX() + explorerTabPane.getWidth()); |
| 1292 | editorTabPane.prefHeightProperty().bind(scene.heightProperty().subtract(65)); |
| 1293 | editorTabPane.prefWidthProperty().bind(scene.widthProperty().subtract(250)); |
| 1294 | |
| 1295 | } else if (editorFlag == true && projectExplorerFlag == false) { |
| 1296 | editorTabPane.setLayoutX(explorerTabPane.getLayoutX()); |
| 1297 | editorTabPane.prefHeightProperty().bind(scene.heightProperty().subtract(65)); |
| 1298 | editorTabPane.prefWidthProperty().bind(scene.widthProperty()); |
| 1299 | } else if (editorFlag == true && projectExplorerFlag == true) { |
| 1300 | editorTabPane.prefHeightProperty().bind(scene.heightProperty().subtract(65)); |
| 1301 | editorTabPane.prefWidthProperty().bind(scene.widthProperty().subtract(explorerTabPane.getWidth())); |
| 1302 | editorTabPane.setLayoutX(explorerTabPane.getLayoutX() + explorerTabPane.getWidth()); |
| 1303 | } |
| 1304 | |
| 1305 | } |
| 1306 | |
| 1307 | public void refreshLogExplorer() { |
| 1308 | |
| 1309 | |
| 1310 | String projectWorkSpacePaths = label.hierarchyTestON + "/logs/"; |
| 1311 | File[] file = File.listRoots(); |
| 1312 | Path name = new File(projectWorkSpacePaths).toPath(); |
| 1313 | OFALoadTree treeNode = new OFALoadTree(name); |
| 1314 | treeNode.setExpanded(true); |
| 1315 | |
| 1316 | |
| 1317 | } |
| 1318 | |
| 1319 | /** |
| 1320 | * |
| 1321 | * @param args the command line arguments |
| 1322 | */ |
| 1323 | public static void main(String[] args) { |
| 1324 | launch(args); |
| 1325 | } |
| 1326 | } |