blob: d046989975fe7d7bcbb5a0ebc3f555c835c14672 [file] [log] [blame]
adminbae64d82013-08-01 10:50:15 -07001/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5package tai_ofa;
6
7import java.io.BufferedWriter;
8import java.io.File;
9import java.io.FileWriter;
10import java.io.IOException;
11import java.nio.file.Path;
12import java.security.acl.Owner;
13import java.util.ArrayList;
14import java.util.HashMap;
15import java.util.Iterator;
16import java.util.Locale;
17import java.util.Map;
18import java.util.Observable;
19import java.util.Set;
20import java.util.Stack;
21import java.util.logging.Level;
22import java.util.logging.Logger;
23import javafx.application.Application;
24import javafx.beans.property.DoubleProperty;
25import javafx.beans.value.ChangeListener;
26import javafx.beans.value.ObservableValue;
27import javafx.collections.FXCollections;
28import javafx.collections.ObservableList;
29import javafx.event.ActionEvent;
30import javafx.event.EventHandler;
31import javafx.geometry.Insets;
32import javafx.geometry.Orientation;
33import javafx.geometry.Side;
34import javafx.scene.Cursor;
35import javafx.scene.Node;
36import javafx.scene.Parent;
37import javafx.scene.Scene;
38import javafx.scene.control.Button;
39import javafx.scene.control.ComboBox;
40import javafx.scene.control.ComboBoxBuilder;
41import javafx.scene.control.ContextMenu;
42import javafx.scene.control.Label;
43import javafx.scene.control.MenuItem;
44import javafx.scene.control.MultipleSelectionModel;
45import javafx.scene.control.Separator;
46import javafx.scene.control.SingleSelectionModel;
47import javafx.scene.control.Tab;
48import javafx.scene.control.TabPane;
49import javafx.scene.control.TextField;
50import javafx.scene.control.TextFieldBuilder;
51import javafx.scene.control.ToolBar;
52import javafx.scene.control.Tooltip;
53import javafx.scene.control.TreeItem;
54import javafx.scene.control.TreeView;
55import javafx.scene.effect.DropShadow;
56import javafx.scene.image.Image;
57import javafx.scene.image.ImageView;
58import javafx.scene.input.ClipboardContent;
59import javafx.scene.input.DragEvent;
60import javafx.scene.input.Dragboard;
61import javafx.scene.input.KeyEvent;
62import javafx.scene.input.MouseButton;
63import javafx.scene.input.MouseDragEvent;
64import javafx.scene.input.MouseEvent;
65import javafx.scene.input.TransferMode;
66import javafx.scene.layout.BorderPane;
67import javafx.scene.layout.BorderPaneBuilder;
68import javafx.scene.layout.GridPane;
69import javafx.scene.layout.GridPaneBuilder;
70import javafx.scene.layout.HBox;
71import javafx.scene.layout.Pane;
72import javafx.scene.layout.Priority;
73import javafx.scene.layout.Region;
74import javafx.scene.layout.StackPane;
75import javafx.scene.layout.VBox;
76import javafx.scene.paint.Color;
77import javafx.scene.shape.Circle;
78import javafx.scene.shape.Line;
79import javafx.scene.shape.StrokeLineCap;
80import javafx.scene.text.Font;
81import javafx.scene.text.FontWeight;
82import javafx.scene.text.Text;
83import javafx.stage.Stage;
84
85/**
86 *
87 * @author Raghav Kashyap (raghavkashyap@paxterrasolutions.com)
88
89 * TestON is free software: you can redistribute it and/or modify
90 * it under the terms of the GNU General Public License as published by
91 * the Free Software Foundation, either version 2 of the License, or
92 * (at your option) any later version.
93
94 * TestON is distributed in the hope that it will be useful,
95 * but WITHOUT ANY WARRANTY; without even the implied warranty of
96 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
97 * GNU General Public License for more details.
98
99 * You should have received a copy of the GNU General Public License
100 * along with TestON. If not, see <http://www.gnu.org/licenses/>.
101
102 */
103public class OFAWizard extends Application {
104
105 NewWizard wizard;
106 TAI_OFA referenceOFA;
107
108 public OFAWizard() {
109 }
110 TreeItem<String> rootItem;
111 TreeItem<String> testTree;
112 ObservableList<TreeItem<String>> listProject;
113 TreeView<String> projectTree;
114 int caseNumber;
115 String paramsFileName;
116
117 public OFAWizard(TreeItem<String> root, int i, ObservableList<TreeItem<String>> listProject1, TreeView<String> projectTree1) {
118 rootItem = root;
119 caseNumber = i;
120 listProject = listProject1;
121 projectTree = projectTree1;
122 }
123
124 public void setOFA(TAI_OFA ofa) {
125 this.referenceOFA = ofa;
126 }
127
128 @Override
129 public void start(Stage stage) throws Exception {
130 wizard = new NewWizard(stage, rootItem, referenceOFA, caseNumber, listProject, projectTree);
131 stage.setTitle("TestON - Automation is O{pe}N ");
132 Scene scene = new Scene(wizard, 700, 400);
133 stage.setScene(scene);
134 stage.setResizable(false);
135 scene.getStylesheets().addAll(this.getClass().getResource("wizard.css").toExternalForm());
136 paramsFileName = wizard.paramsFileName;
137 stage.show();
138 }
139
140 public void setProjectList(ObservableList<TreeItem<String>> list) {
141 listProject = list;
142 }
143
144 public void setProjectView(TreeView<String> tree) {
145 projectTree = tree;
146 }
147}
148
149/**
150 * basic wizard infrastructure class
151 */
152class Wizard extends StackPane {
153
154 private static final int UNDEFINED = -1;
155 private ObservableList<WizardPage> pages = FXCollections.observableArrayList();
156 private Stack<Integer> history = new Stack();
157 private int curPageIdx = UNDEFINED;
158 NewWizard newWizardObjct;
159
160 public Wizard() {
161 }
162
163 void setAllData(WizardPage... nodes) {
164 for (WizardPage wizardPage : nodes) {
165 wizardPage.setNewWizard(newWizardObjct);
166 pages.add(wizardPage);
167 }
168 navTo(0);
169 setStyle("-fx-padding: 0; -fx-background-color: cornsilk;");
170 }
171
172 Wizard(WizardPage... nodes) {
173 for (WizardPage wizardPage : nodes) {
174 wizardPage.setNewWizard(newWizardObjct);
175 pages.add(wizardPage);
176 }
177 navTo(0);
178 setStyle("-fx-padding: 0; -fx-background-color: cornsilk;");
179 }
180
181 ObservableList<WizardPage> getAllChildrens() {
182 return pages;
183 }
184
185 void nextPage() {
186 if (hasNextPage()) {
187 navTo(curPageIdx + 1);
188 }
189 }
190
191 void priorPage() {
192 if (hasPriorPage()) {
193 navTo(history.pop(), false);
194 }
195 }
196
197 boolean hasNextPage() {
198 return (curPageIdx < pages.size() - 1);
199 }
200
201 boolean hasPriorPage() {
202 return !history.isEmpty();
203 }
204
205 void navTo(int nextPageIdx, boolean pushHistory) {
206 if (nextPageIdx < 0 || nextPageIdx >= pages.size()) {
207 return;
208 }
209 if (curPageIdx != UNDEFINED) {
210 if (pushHistory) {
211 history.push(curPageIdx);
212 }
213 }
214
215 WizardPage nextPage = pages.get(nextPageIdx);
216 curPageIdx = nextPageIdx;
217 getChildren().clear();
218 getChildren().add(nextPage);
219 nextPage.manageButtons();
220 }
221
222 void navTo(int nextPageIdx) {
223 navTo(nextPageIdx, true);
224 }
225
226 void navTo(String id) {
227 Node page = lookup("#" + id);
228 if (page != null) {
229 int nextPageIdx = pages.indexOf(page);
230 if (nextPageIdx != UNDEFINED) {
231 navTo(nextPageIdx);
232 }
233 }
234 }
235
236 public void finish() {
237 }
238
239 public void cancel() {
240 }
241
242 public void setNewWizard(NewWizard newWizardObj) {
243 newWizardObjct = newWizardObj;
244 }
245}
246
247/**
248 * basic wizard page class
249 */
250abstract class WizardPage extends VBox {
251
252 TAILocale label = new TAILocale(new Locale("en", "EN"));
253 Button priorButton = new Button("<< Previous");
254 Button nextButton = new Button("Next >>");
255 Button cancelButton = new Button("Cancel");
256 Button finishButton = new Button("Finish");
257 NewWizard newWizardReference;
258
259 WizardPage(String title) {
260 //getChildren().add(der.create().text(title).build());
261 setId(title);
262 setSpacing(0);
263 setStyle("-fx-padding:0; -fx-background-color: white; ");
264 Region spring = new Region();
265 VBox.setVgrow(spring, Priority.ALWAYS);
266 getChildren().addAll(getContent(), spring, getButtons());
267
268 priorButton.setOnAction(new EventHandler<ActionEvent>() {
269 @Override
270 public void handle(ActionEvent actionEvent) {
271 priorPage();
272 }
273 });
274
275 nextButton.setOnAction(new EventHandler<ActionEvent>() {
276 @Override
277 public void handle(ActionEvent t) {
278 nextPage();
279 }
280 });
281
282 cancelButton.setOnAction(new EventHandler<ActionEvent>() {
283 @Override
284 public void handle(ActionEvent t) {
285 getWizard().cancel();
286 }
287 });
288
289 finishButton.setOnAction(new EventHandler<ActionEvent>() {
290 @Override
291 public void handle(ActionEvent t) {
292 getWizard().finish();
293 }
294 });
295 }
296
297 HBox getButtons() {
298 Region spring = new Region();
299 HBox.setHgrow(spring, Priority.ALWAYS);
300 HBox buttonBar = new HBox(5);
301 cancelButton.setCancelButton(true);
302 // finishButton.setDefaultButton(true);
303 buttonBar.getChildren().addAll(spring, priorButton, nextButton, cancelButton, finishButton);
304 return buttonBar;
305 }
306
307 abstract Parent getContent();
308
309 boolean hasNextPage() {
310 return getWizard().hasNextPage();
311 }
312
313 boolean hasPriorPage() {
314 return getWizard().hasPriorPage();
315 }
316
317 void nextPage() {
318 getWizard().nextPage();
319 }
320
321 void priorPage() {
322 getWizard().priorPage();
323 }
324
325 void navTo(String id) {
326 getWizard().navTo(id);
327 }
328
329 Wizard getWizard() {
330 return (Wizard) getParent();
331 }
332
333 public void manageButtons() {
334 if (!hasPriorPage()) {
335 priorButton.setDisable(true);
336 }
337
338 if (!hasNextPage()) {
339 nextButton.setDisable(true);
340 }
341 }
342
343 public void setNewWizard(NewWizard refWizard) {
344 newWizardReference = refWizard;
345 }
346}
347
348/*
349 * this Class shows the OFA wizard
350 */
351class NewWizard extends Wizard {
352
353 String[] splitDeviceDetails;
354 TestWizard testWizard;
355 Stage owner;
356 String topologyDemo, paramFileDemo, ospkFileDemo;
357 TreeItem<String> projectExplorerTreeItem;
358 OFALoadTree projectNameTree;
359 TAI_OFA referenceOFA;
360 TAILocale label = new TAILocale(new Locale("en", "EN"));
361 String OFAUiPath = label.hierarchyTestON + "/tests/";
362 TreeItem<String> treeItem1;
363 String paramsFileName, topoFileName;
364 boolean flag = false;
365 String topologyFileDemo;
366 String[] splitDeviceDetail;
367
368 public NewWizard(Stage owner, TreeItem<String> treeItem, TAI_OFA reference, int caseNumber, final ObservableList<TreeItem<String>> listProject1, TreeView<String> projectTree1) {
369 super();
370
371 super.setNewWizard(this);
372
373 this.owner = owner;
374 testWizard = new TestWizard();
375
376 switch (caseNumber) {
377 /*
378 * cases ---
379 * 1. New Project
380 * 2. New Params file
381 * 3. New Topology file
382 * 4. New Driver
383 *
384 */
385 case 1:
386 final ProjectWizard projectWizard = new ProjectWizard();
387 ParamsWizard paramsWizard = new ParamsWizard();
388 super.setAllData(projectWizard, paramsWizard, new TopologyWizard());
389 projectWizard.projectName.textProperty().addListener(new ChangeListener<String>() {
390 @Override
391 public void changed(ObservableValue<? extends String> arg0, String arg1, String arg2) {
392 String message = "\nYour projectName must be\n" + "started with alphabate and \nshould not have special symbol";
393 textValidation("([a-zA-Z]\\d*[a-zA_Z])+|([a-zA-Z]\\d*)+|", arg2, projectWizard.error, projectWizard.nextButton, message, projectWizard.projectName);
394 }
395 });
396 projectExplorerTreeItem = treeItem;
397 referenceOFA = reference;
398 paramsWizard.gridPane.add(testWizard.testParams, 0, 0);
399 paramsWizard.gridPane.add(new Label(label.wizEmailId), 0, 2);
400 paramsWizard.gridPane.add(testWizard.emailId, 1, 2);
401 paramsWizard.gridPane.add(new Label("Log Directory "), 0, 3);
402 paramsWizard.gridPane.add(testWizard.log_dir, 1, 3);
403 paramsWizard.gridPane.add(new Label(label.wizNumberofTestCases), 0, 4);
404 paramsWizard.gridPane.add(testWizard.testCases, 1, 4);
405 paramsWizard.gridPane.add(testWizard.imageHouse, 60, 0);
406 paramsWizard.nextButton.setDisable(false);
407 break;
408
409 case 2:
410
411 super.setAllData(testWizard);
412 projectExplorerTreeItem = treeItem;
413 referenceOFA = reference;
414 testWizard.gridPane.add(new Label(label.wizProject), 0, 1);
415 testWizard.gridPane.add(testWizard.projectNameList, 1, 1);
416 testWizard.gridPane.add(new Label(label.wizParamName), 0, 3);
417
418 testWizard.gridPane.add(testWizard.paramName, 1, 3);
419
420 testWizard.nextButton.setDisable(true);
421
422 testWizard.paramName.textProperty().addListener(new ChangeListener<String>() {
423 @Override
424 public void changed(ObservableValue<? extends String> arg0, String arg1, String arg2) {
425 if (!arg2.isEmpty()) {
426 testWizard.projectNameList.valueProperty().addListener(new ChangeListener() {
427 @Override
428 public void changed(ObservableValue arg0, Object arg1, Object arg2) {
429 if (!arg2.toString().isEmpty()) {
430 testWizard.testNameList.valueProperty().addListener(new ChangeListener() {
431 @Override
432 public void changed(ObservableValue arg0, Object arg1, Object arg2) {
433 testWizard.finishButton.setDisable(arg2.toString().isEmpty());
434 }
435 });
436 }
437 }
438 });
439 }
440 }
441 });
442 Iterator<TreeItem<String>> projectList1 = listProject1.iterator();
443 testWizard.projectNameList.getItems().clear();
444 while (projectList1.hasNext()) {
445 TreeItem<String> projectComb = projectList1.next();
446 projectComb.getValue();
447 testWizard.projectNameList.getItems().add(projectComb.getValue());
448 }
449
450 testWizard.projectNameList.setOnAction(new EventHandler<ActionEvent>() {
451 @Override
452 public void handle(ActionEvent arg0) {
453
454 final Iterator<TreeItem<String>> projectIterator = listProject1.iterator();
455 while (projectIterator.hasNext()) {
456 final TreeItem<String> treeItem = projectIterator.next();
457 ObservableList<TreeItem<String>> list = treeItem.getChildren();
458 if (treeItem.getValue().equalsIgnoreCase(testWizard.projectNameList.getSelectionModel().getSelectedItem().toString())) {
459 ObservableList<TreeItem<String>> children = treeItem.getChildren();
460 final Iterator<TreeItem<String>> testListIterator = children.iterator();
461 while (testListIterator.hasNext()) {
462 TreeItem<String> testComb = testListIterator.next();
463 testComb.getValue();
464 }
465 }
466 }
467 }
468 });
469 break;
470
471 case 3:
472 final ParamsWizard paramWizard = new ParamsWizard();
473 super.setAllData(paramWizard, new TopologyWizard());
474 projectExplorerTreeItem = treeItem;
475 referenceOFA = reference;
476 paramWizard.gridPane.add(testWizard.testParams, 0, 0);
477 paramWizard.gridPane.add(new Label("Test Name :"), 0, 2);
478 paramWizard.gridPane.add(testWizard.projectNameList, 1, 2);
479 paramWizard.gridPane.add(new Label("Topology Name"), 0, 3);
480 paramWizard.gridPane.add(testWizard.topologyName, 1, 3);
481 paramWizard.gridPane.add(testWizard.imageHouse, 60, 0);
482 paramWizard.nextButton.setDisable(true);
483 Iterator<TreeItem<String>> projectList2 = listProject1.iterator();
484 testWizard.projectNameList.getItems().clear();
485 while (projectList2.hasNext()) {
486 TreeItem<String> projectComb = projectList2.next();
487 projectComb.getValue();
488 testWizard.projectNameList.getItems().add(projectComb.getValue());
489 }
490
491 testWizard.projectNameList.setOnAction(new EventHandler<ActionEvent>() {
492 @Override
493 public void handle(ActionEvent arg0) {
494
495 final Iterator<TreeItem<String>> projectIterator = listProject1.iterator();
496 while (projectIterator.hasNext()) {
497 final TreeItem<String> treeItem = projectIterator.next();
498 ObservableList<TreeItem<String>> list = treeItem.getChildren();
499 if (treeItem.getValue().equalsIgnoreCase(testWizard.projectNameList.getSelectionModel().getSelectedItem().toString())) {
500 ObservableList<TreeItem<String>> children = treeItem.getChildren();
501 final Iterator<TreeItem<String>> testListIterator = children.iterator();
502 while (testListIterator.hasNext()) {
503 TreeItem<String> testComb = testListIterator.next();
504 testComb.getValue();
505 }
506 }
507 }
508 }
509 });
510
511 testWizard.topologyName.setOnKeyReleased(new EventHandler<KeyEvent>() {
512 @Override
513 public void handle(KeyEvent t) {
514 if (!testWizard.topologyName.getText().isEmpty()) {
515 paramWizard.nextButton.setDisable(false);
516 } else {
517 paramWizard.nextButton.setDisable(true);
518 }
519 }
520 });
521 break;
522 }
523 }
524
525 @Override
526 public void finish() {
527 String projectName = null;
528 String testName = null;
529 String testParamsName = null;
530 String testTopologyName = null;
531 ObservableList<WizardPage> nodeList = super.getAllChildrens();
532 int i = 0;
533
534 while (i < nodeList.size()) {
535 WizardPage node = nodeList.get(i);
536 if (node.getId().equals(label.wizProjectWizardId)) {
537 ProjectWizard projectWizard = (ProjectWizard) node;
538 projectName = projectWizard.getName();
539 new File(OFAUiPath + projectName).mkdir();
540 String projectWorkSpacePath = OFAUiPath + projectName;
541 File[] file = File.listRoots();
542 Path name = new File(projectWorkSpacePath).toPath();
543 projectNameTree = new OFALoadTree(name);
544
545 projectExplorerTreeItem.getChildren().add(projectNameTree);
546 String pathToFiles = projectNameTree.getFullPath() + "/";
547
548
549 Path ospkName = new File(projectNameTree.getFullPath() + "/" + projectName + ".ospk").toPath();
550 Path paramsName = new File(projectNameTree.getFullPath() + "/" + projectName + ".params").toPath();
551 Path topologyName = new File(projectNameTree.getFullPath() + "/" + projectName + ".topo").toPath();
552
553 OFALoadTree topologyTestTree = new OFALoadTree(topologyName);
554 topologyTestTree.setValue(topologyName.toString().replace(topologyName.toString(), projectName));
555
556 OFALoadTree ospkTestTree = new OFALoadTree(ospkName);
557 ospkTestTree.setValue(ospkName.toString().replace(ospkName.toString(), projectName));
558
559 OFALoadTree paramTestTree = new OFALoadTree(paramsName);
560 paramTestTree.setValue(paramsName.toString().replace(paramsName.toString(), projectName));
561 projectNameTree.getChildren().addAll(topologyTestTree, paramTestTree, ospkTestTree);
562
563 paramFileDemo = "<PARAMS>" + "\n\t" + "<testcases> \"1\" </testcases>" + "\n\t"
564 + "<mail> " + testWizard.emailId.getText() + "</mail>\n\t" + "<log_dir>" + testWizard.log_dir.getText() + "</log_dir>" + "\n\n\t"
565 + "<CASE1>" + "\n\t\t" + "#Enter your CASE parameter here in the form" + "\n\t\t" + "#param = value"
566 + "\n\t\t" + "<STEP1>" + "\n\t\t\t" + "#Enter your STEP parameter here in the form" + "\n\t\t\t" + "#param = value" + "\n\t\t" + "</STEP1>" + "\n\t" + "</CASE1>"
567 + "\n" + "\n</PARAMS>";
568
569 ospkFileDemo = "CASE 1" + "\n" + "\t" + "NAME" + " " + "\"Give test case name \"" + "\n" + "\t"
570 + "DESC \"Give test case description\"" + "\n" + "END CASE";
571
572 testTopologyName = projectName + ".topo";
573 String topoFileDemo = "<TOPOLOGY>" + "\n\t<COMPONENT>" + "\n\t\t# put components here as given below" + "\n\t\t<component1>" + "\n\t\t\t# put component parameters here"
574 + "\n\t\t <host> 192.168.56.101 </host>" + "\n\t\t</component1>" + "\n\t</COMPONENT>" + "</TOPOLOGY>";
575
576 try {
577 new File(pathToFiles + "/" + projectName + ".ospk").createNewFile();
578 new File(pathToFiles + "/" + projectName + ".params").createNewFile();
579 new File(pathToFiles + "/" + projectName + ".topo").createNewFile();
580 new File(pathToFiles + "/" + "__init__.py").createNewFile();
581 } catch (IOException ex) {
582
583 }
584 writeInFile(pathToFiles + "/" + projectName + ".params", paramFileDemo);
585 writeInFile(pathToFiles + "/" + projectName + ".ospk", ospkFileDemo);
586
587 referenceOFA.checkEditor();
588
589 } else if (node.getId().equals(label.wizTestWizardId)) {
590
591 testWizard = (TestWizard) node;
592 String selectedProject = testWizard.projectNameList.getSelectionModel().getSelectedItem().toString();
593 String paramName = testWizard.paramName.getText();
594 String pathParams = "";
595 for (int index = 0; index < referenceOFA.projectExplorerTree.getChildren().size(); index++) {
596
597 if (referenceOFA.projectExplorerTree.getChildren().get(index).getValue().equals(selectedProject)) {
598
599 pathParams = OFAUiPath + selectedProject;
600 Path name = new File(OFAUiPath + selectedProject + "/" + paramName).toPath();
601 OFALoadTree testSelection = new OFALoadTree(name);
602
603 Path paramsName = new File(name + ".params").toPath();
604 paramsFileName = paramsName.toString();
605 OFALoadTree paramsTestTree = new OFALoadTree(paramsName);
606 paramsTestTree.setValue(paramName);
607 referenceOFA.projectExplorerTree.getChildren().get(index).getChildren().addAll(paramsTestTree);
608 try {
609 new File(paramsFileName).createNewFile();
610 } catch (IOException ex) {
611 Logger.getLogger(NewWizard.class.getName()).log(Level.SEVERE, null, ex);
612 }
613 writeInFile(paramsFileName, referenceOFA.paramsFileContent);
614 }
615 }
616
617
618 } else if (node.getId().equals(label.wizTopologyWizardId)) {
619 TopologyWizard topoWizard = (TopologyWizard) node;
620
621 ArrayList<String> deviceName = new ArrayList<String>();
622 Iterator<TextField> attributeIterator = topoWizard.getDeviceNameList().iterator();
623 while (attributeIterator.hasNext()) {
624 TextField iteratorAttributeText = attributeIterator.next();
625 deviceName.add(iteratorAttributeText.getText());
626 }
627 topologyFileDemo = "<TOPOLOGY>" + "\n\t" + "<COMPONENT>" + "\n\t";
628
629 for (String device : topoWizard.getPropertyDetail()) {
630 splitDeviceDetail = device.split("\n");
631 topologyFileDemo += "\n\t\t" + "<" + splitDeviceDetail[0] + ">";
632 splitDeviceDetail = device.split("\n");
633 try {
634 topologyFileDemo += "\n\t\t\t" + "<hostname> " + splitDeviceDetail[1] + "</hostname>\n\t\t\t" + "<user>" + splitDeviceDetail[2]
635 + "</user>\n\t\t\t" + "<password>" + splitDeviceDetail[3] + "</password>\n\t\t\t" + "<type>" + splitDeviceDetail[5] + "</type>\n\t\t\t" + "<coordinate(x,y)>"
636 + splitDeviceDetail[7] + "</coordinate(x,y)>\n\t\t\t";
637
638 if (topoWizard.topoplogy.testTargetRadioButton.isSelected()) {
639 topologyFileDemo += "<test_target> 1 </test_target>\n\t\t\t" + "<COMPONENTS>";
640 } else {
641 topologyFileDemo += "<COMPONENTS>";
642 }
643 String[] deviceDetailsArray = topoWizard.interFaceValue.toArray(new String[topoWizard.interFaceValue.size()]);
644 int noOfDevices = 0;
645 for (String name : topoWizard.interFaceName) {
646 String propertyDetail = deviceDetailsArray[noOfDevices++];
647 String[] details = propertyDetail.split("\\_");
648 String[] splitInterFace = name.split("\\_");
649 if (splitInterFace[1].equals(splitDeviceDetail[0]) && details[1].equals(splitDeviceDetail[0])) {
650 // topologyFileDemo += "\n\t\t\t"+splitInterFace[0]+"="+details[0];
651 }
652 }
653 for (HashMap<String, String> interFaceDetail : topoWizard.arrayOfInterFaceHash) {
654 Set set = interFaceDetail.entrySet();
655 Iterator interFaceHashDetailIterator = set.iterator();
656 while (interFaceHashDetailIterator.hasNext()) {
657 Map.Entry me = (Map.Entry) interFaceHashDetailIterator.next();
658 String[] deviceNameAndiniterFaceValue = me.getValue().toString().split("\\_");
659 if (deviceNameAndiniterFaceValue[1].equals(splitDeviceDetail[0])) {
660 if (!me.getKey().toString().isEmpty()) {
661 if (!me.getKey().toString().equals("//s+")) {
662 topologyFileDemo += "\n\t\t\t\t" + "<" + me.getKey().toString() + ">" + deviceNameAndiniterFaceValue[0].toString() + "</" + me.getKey().toString() + ">";
663
664 }
665 }
666 }
667
668 }
669 topologyFileDemo += "\n\t\t\t</COMPONENTS>";
670 }
671
672 topologyFileDemo += "\n\t\t" + "</" + splitDeviceDetail[0] + ">";
673
674 } catch (Exception e) {
675 }
676 }
677 Set set = topoWizard.linkTopologyHash.entrySet();
678 Iterator linkHashDetailIterator = set.iterator();
679 while (linkHashDetailIterator.hasNext()) {
680 Map.Entry me = (Map.Entry) linkHashDetailIterator.next();
681
682 String[] linkValue = me.getValue().toString().split("_");
683 String[] linkCoordinates = me.getKey().toString().split("_");
684
685 topologyFileDemo += "\n\t\t" + "<" + linkValue[0] + ">";
686 topologyFileDemo += "\n\t\t\t" + "<" + linkValue[2].toString() + ">" + linkValue[3].toString() + "</" + linkValue[2].toString() + ">";
687 topologyFileDemo += "\n\t\t\t" + "<" + linkValue[4].toString() + ">" + linkValue[5].toString() + "</" + linkValue[4].toString() + ">";
688 topologyFileDemo += "\n\t\t\t" + "<linkCoordinates(startx,starty,endx,endy)" + ">" + linkCoordinates[1].toString() + "," + linkCoordinates[2] + "," + linkCoordinates[3] + "," + linkCoordinates[4] + "</linkCoordinates(startx,starty,endx,endy)" + ">";
689 topologyFileDemo += "\n\t\t" + "</" + linkValue[0] + ">";
690
691 }
692
693 topologyFileDemo += "\n\t" + "</COMPONENT>" + "\n" + "</TOPOLOGY>";
694 String pathTopo = "";
695 if (testTopologyName != null) {
696 writeInFile(label.hierarchyTestON + "/tests/" + projectName + "/" + testTopologyName, topologyFileDemo);
697 } else {
698 String projectNames = testWizard.projectNameList.getSelectionModel().getSelectedItem().toString();
699 for (int index = 0; index < referenceOFA.projectExplorerTree.getChildren().size(); index++) {
700
701 if (referenceOFA.projectExplorerTree.getChildren().get(index).getValue().equals(projectNames)) {
702 pathTopo = OFAUiPath + projectNames;
703 Path name = new File(OFAUiPath + projectNames + "/" + testWizard.topologyName.getText()).toPath();
704 OFALoadTree testSelection = new OFALoadTree(name);
705
706 Path topoName = new File(name + ".topo").toPath();
707 topoFileName = topoName.toString();
708 OFALoadTree topoTestTree = new OFALoadTree(topoName);
709 topoTestTree.setValue(topoFileName);
710 topoTestTree.setValue(topoFileName.toString().replace(topoFileName.toString(), testWizard.topologyName.getText()));
711
712 referenceOFA.projectExplorerTree.getChildren().get(index).getChildren().addAll(topoTestTree);
713 try {
714 new File(topoFileName).createNewFile();
715 } catch (IOException ex) {
716 Logger.getLogger(NewWizard.class.getName()).log(Level.SEVERE, null, ex);
717 }
718 writeInFile(topoFileName, topologyFileDemo);
719 }
720 }
721
722 }
723
724 }
725
726 i++;
727 }
728 owner.close();
729 }
730
731 public String getParamsFileName() {
732 return paramsFileName;
733 }
734
735 public void writeInFile(String path, String demoFile) {
736 try {
737 // Create file
738 FileWriter fstream = new FileWriter(path);
739 BufferedWriter out = new BufferedWriter(fstream);
740 out.write(demoFile);
741 out.close();
742 } catch (Exception e) {
743
744 }
745 }
746
747 public void cancel() {
748
749 owner.close();
750 }
751
752 public void textValidation(String regExp, String arg2, Label error, Button nextButton, String text, TextField name) {
753 Tooltip tooltip = new Tooltip();
754 if (arg2.matches(regExp)) {
755 error.setVisible(false);
756 nextButton.setDisable(false);
757 } else {
758 error.setVisible(true);
759 nextButton.setDisable(true);
760 flag = true;
761 String errorImage = "/images/error.png";
762 Image saveImage = new Image(getClass().getResourceAsStream(errorImage), 18.0, 18.0, true, true);
763 ImageView imageSave = new ImageView(saveImage);
764 error.setGraphic(imageSave);
765
766 tooltip.autoFixProperty();
767 tooltip.setText(text);
768 tooltip.setStyle("-fx-background-color:white");
769 error.setTooltip(tooltip);
770 Image image = new Image(getClass().getResourceAsStream("/images/error.png"), 24.0, 24.0, true, true);
771 tooltip.setGraphic(new ImageView(image));
772 }
773 if (arg2.isEmpty() || flag == true) {
774 nextButton.setDisable(true);
775 flag = false;
776 }
777 }
778}
779
780/**
781 * This page gathers more information about the new Test
782 */
783class ProjectWizard extends WizardPage {
784
785 TextField projectName;
786 String newProjectName;
787 String name;
788 boolean flag = false;
789 Label error;
790 ImageView imageHouse;
791
792 public ProjectWizard() {
793 super("Project");
794
795 nextButton.setDisable(true);
796
797 finishButton.setDisable(true);
798 this.setId("projectWizard");
799
800 }
801
802 @Override
803 Parent getContent() {
804 projectName = TextFieldBuilder.create().build();
805
806 projectName.setMinWidth(170);
807 nextButton.setDisable(true);
808 error = new Label();
809 error.setVisible(false);
810
811 error.setTextFill(Color.RED);
812 imageHouse = new ImageView(new Image("images/paxterra_logo.jpg", 100, 100, true, true));
813
814 HBox image = new HBox();
815 image.setPadding(new Insets(0, 0, 0, 470));
816 Button Open = new Button();
817 String openImgPath = "/images/TestON.png";
818 Open.setStyle("-fx-background-color:white");
819 Open.setLayoutX(0);
820 Open.setLayoutY(0);
821 GridPane gridPane = new GridPane();
822 gridPane.setPadding(new Insets(70, 0, 0, 200));
823 gridPane.setHgap(10);
824 gridPane.setVgap(8);
825 Label project = new Label("Project Name");
826
827
828 gridPane.setId("pane");
829 gridPane.add(project, 0, 11);
830 gridPane.add(projectName, 1, 11);
831 gridPane.add(error, 2, 10);
832 gridPane.add(imageHouse, 10, 0);
833
834 return GridPaneBuilder.create().children(gridPane).build();
835
836 }
837
838 void nextPage() {
839 // If they have complaints, go to the normal next page
840
841 if (!projectName.getText().equals("")) {
842 super.nextPage();
843 newProjectName = projectName.getText();
844
845 } else {
846
847 // No complaints? Short-circuit the rest of the pages
848 navTo("ParamsWizard");
849 }
850 }
851
852 public String getName() {
853 return newProjectName;
854 }
855}
856
857/**
858 * This page gathers more information about the Test Script
859 */
860class TestWizard extends WizardPage {
861
862 TextField emailIds;
863 TextField numberOfTestCase;
864 TextField paramName;
865 TextField topologyName;
866 String getTestName, getEmailId;
867 String getNumberOfTestCases;
868 ObservableList<TreeItem<String>> listProject;
869 TreeView<String> projectTree;
870 ComboBox projectNameList;
871 ComboBox testNameList;
872 GridPane gridPane;
873 Label projectError, testError, emailIdError;
874 ImageView imageHouse;
875 Text testParams;
876 TextField testCases;
877 TextField emailId;
878 TextField log_dir;
879 Text caseParameter;
880 Button addParams;
881
882 public TestWizard() {
883 super("More Info");
884 this.setId("testWizard");
885 nextButton.setDisable(true);
886 finishButton.setDisable(false);
887 }
888
889 @Override
890 Parent getContent() {
891
892 HBox image = new HBox();
893 image.setPadding(new Insets(0, 0, 0, 470));
894
895 topologyName = TextFieldBuilder.create().build();
896 testParams = new Text("Test Params :");
897 testParams.setFont(Font.font("Arial", FontWeight.BOLD, 15));
898 testParams.setFill(Color.BLUE);
899 testCases = TextFieldBuilder.create().build();
900 emailId = TextFieldBuilder.create().build();
901 log_dir = TextFieldBuilder.create().build();
902 caseParameter = new Text("Case Params");
903 caseParameter.setFont(Font.font("Arial", FontWeight.BOLD, 10));
904 addParams = new Button("Add Case Params");
905 projectNameList = ComboBoxBuilder.create().build();
906 projectError = new Label();
907 projectError.setDisable(true);
908 paramName = TextFieldBuilder.create().build();
909 imageHouse = new ImageView(new Image("images/TestON.png", 200, 200, true, true));
910
911 testCases.lengthProperty().addListener(new ChangeListener<Number>() {
912 @Override
913 public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
914 if (newValue.intValue() > oldValue.intValue()) {
915 char ch = testCases.getText().charAt(oldValue.intValue());
916 //Check if the new character is the number or other's
917 if (!(ch >= '0' && ch <= '9')) {
918 testCases.setText(testCases.getText().substring(0, testCases.getText().length() - 1));
919 }
920 }
921 }
922 });
923
924 nextButton.setDisable(false);
925 finishButton.setDisable(false);
926 gridPane = new GridPane();
927 gridPane.setPadding(new Insets(30, 0, 0, 40));
928 gridPane.setHgap(0);
929 gridPane.setVgap(5);
930 return GridPaneBuilder.create().children(gridPane).build();
931 }
932
933 void nextPage() {
934
935 if (!emailId.getText().equals("") || numberOfTestCase.getText().equals("") || log_dir.getText().equals("")) {
936 super.nextPage();
937
938 getEmailId = emailId.getText();
939 getNumberOfTestCases = numberOfTestCase.getText();
940 } else {
941
942 navTo("topologyWizards");
943 }
944 }
945
946 public String getTestName() {
947 return getTestName;
948 }
949
950 public String getEmailId() {
951 return getEmailId;
952 }
953
954 public String getNumberOfTestCase() {
955 return getNumberOfTestCases;
956 }
957}
958
959/**
960 * This page gathers more information about the new Params File
961 */
962class ParamsWizard extends WizardPage {
963
964 TextField emailIds;
965 TextField numberOfTestCase;
966 TextField paramName;
967 TextField topologyName;
968 String getTestName, getEmailId;
969 String getNumberOfTestCases;
970 ObservableList<TreeItem<String>> listProject;
971 TreeView<String> projectTree;
972 ComboBox projectNameList;
973 ComboBox testNameList;
974 GridPane gridPane;
975 Label projectError, testError, emailIdError;
976 ImageView imageHouse;
977 // here is new list
978 Text testParams;
979 TextField testCases;
980 TextField emailId;
981 TextField log_dir;
982 Text caseParameter;
983 Button addParams;
984 TextField testTopology;
985
986 public ParamsWizard() {
987 super("More Info");
988 this.setId("paramsWizard");
989 nextButton.setDisable(true);
990 finishButton.setDisable(false);
991 }
992
993 @Override
994 Parent getContent() {
995
996 HBox image = new HBox();
997 image.setPadding(new Insets(0, 0, 0, 470));
998
999 testTopology = emailId = TextFieldBuilder.create().build();
1000 testParams = new Text("Test Params :");
1001 testParams.setId("testParamsTitle");
1002 testParams.setFont(Font.font("Arial", FontWeight.BOLD, 15));
1003 testParams.setFill(Color.BLUE);
1004
1005 DropShadow dropShadow = new DropShadow();
1006 dropShadow.setColor(Color.BLACK);
1007 dropShadow.setRadius(25);
1008 dropShadow.setSpread(0.25);
1009 testParams.setEffect(dropShadow);
1010
1011 testCases = TextFieldBuilder.create().build();
1012 emailId = TextFieldBuilder.create().build();
1013 log_dir = TextFieldBuilder.create().build();
1014 caseParameter = new Text("Case Params");
1015 caseParameter.setFont(Font.font("Arial", FontWeight.BOLD, 10));
1016 addParams = new Button("Add Case Params");
1017 projectNameList = ComboBoxBuilder.create().build();
1018 projectError = new Label();
1019 projectError.setDisable(true);
1020 paramName = TextFieldBuilder.create().build();
1021 imageHouse = new ImageView(new Image("images/paxterra_logo.jpg", 100, 100, true, true));
1022
1023 testCases.lengthProperty().addListener(new ChangeListener<Number>() {
1024 @Override
1025 public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
1026 if (newValue.intValue() > oldValue.intValue()) {
1027 char ch = testCases.getText().charAt(oldValue.intValue());
1028 //Check if the new character is the number or other's
1029 if (!(ch >= '0' && ch <= '9')) {
1030 testCases.setText(testCases.getText().substring(0, testCases.getText().length() - 1));
1031 }
1032 }
1033 }
1034 });
1035 nextButton.setDisable(false);
1036 finishButton.setDisable(false);
1037
1038 gridPane = new GridPane();
1039 gridPane.setPadding(new Insets(30, 0, 0, 40));
1040 gridPane.setHgap(0);
1041 gridPane.setVgap(5);
1042
1043 return GridPaneBuilder.create().children(gridPane).build();
1044
1045 }
1046
1047 void nextPage() {
1048
1049 if (!emailId.getText().equals("") || testCases.getText().equals("") || log_dir.getText().equals("")) {
1050 super.nextPage();
1051
1052 getEmailId = emailId.getText();
1053 getNumberOfTestCases = testCases.getText();
1054 } else {
1055
1056 navTo("topologyWizards");
1057 }
1058 }
1059
1060 public String getTestName() {
1061 return getTestName;
1062 }
1063
1064 public String getEmailId() {
1065 return getEmailId;
1066 }
1067
1068 public String getNumberOfTestCase() {
1069 return getNumberOfTestCases;
1070 }
1071}
1072
1073/**
1074 * This page gathers more information about the Test Topology
1075 */
1076class TopologyWizard extends WizardPage {
1077
1078 ArrayList<TextField> deviceNameList = new ArrayList<TextField>();
1079 ArrayList<String> draggedImagesName = new ArrayList<String>();
1080 OFATopology topoplogy;
1081 ArrayList<String> propertyValue = new ArrayList<String>();
1082 ArrayList<String> interFaceName = new ArrayList<String>();
1083 ArrayList<String> interFaceValue = new ArrayList<String>();
1084 TreeView<String> driverExplorerTreeView;
1085 ArrayList<String> webInfoList = new ArrayList<String>();
1086 ArrayList<String> webCisco = new ArrayList<String>();
1087 HashMap<String, String> interFaceHashDetail = new HashMap<String, String>();
1088 ArrayList<HashMap<String, String>> arrayOfInterFaceHash;
1089 HashMap<String, String> webToplogyHash = new HashMap<String, String>();
1090 ArrayList<HashMap<String, String>> arrayOfwebTopologyHash;
1091 OFATopologyLink topologyLink = new OFATopologyLink();
1092 HashMap<String, String> linkTopologyHash = new HashMap<String, String>();
1093 ArrayList<HashMap<String, String>> arrayOfLinkTopologyHash = new ArrayList<HashMap<String, String>>();
1094 ArrayList<String> topoEditorDeviceInfo = new ArrayList<String>();
1095 Button lineButtonHorizontal;
1096 TAILocale label = new TAILocale(new Locale("en", "EN"));
1097 boolean anchorFlag = false;
1098 boolean selectFlag = false;
1099
1100 public TopologyWizard() {
1101 super("");
1102 this.setId(label.wizTopologyWizardId);
1103 }
1104
1105 Parent getContent() {
1106 TAILocale label = new TAILocale(Locale.ENGLISH);
1107 VBox parentTopologyBox = new VBox();
1108 ToolBar canvasToolBar = new ToolBar();
1109 lineButtonHorizontal = new Button();
1110
1111 Tooltip horizontal = new Tooltip("Click to add horizontal line in canvas");
1112 lineButtonHorizontal.setTooltip(horizontal);
1113 Image image = new Image(getClass().getResourceAsStream("/images/Link1.png"), 28.0, 28.0, true, true);
1114 ImageView imageNew = new ImageView(image);
1115 lineButtonHorizontal.setGraphic(imageNew);
1116
1117 Button lineButtonVertical = new Button();
1118 Tooltip vertical = new Tooltip("Click to add vertical line in canvas");
1119 lineButtonVertical.setTooltip(vertical);
1120
1121 final Button deleteAllButton = new Button();
1122 Tooltip delete = new Tooltip("Click to reset or clear canvas");
1123 deleteAllButton.setTooltip(delete);
1124 Image image2 = new Image(getClass().getResourceAsStream("/images/Refresh.png"), 24.0, 24.0, true, true);
1125 ImageView imageNew2 = new ImageView(image2);
1126 deleteAllButton.setGraphic(imageNew2);
1127
1128 Image image1 = new Image(getClass().getResourceAsStream("/images/verticalLine.jpg"), 24.0, 24.0, true, true);
1129 ImageView imageNew1 = new ImageView(image1);
1130 lineButtonVertical.setGraphic(imageNew1);
1131
1132 canvasToolBar.getItems().addAll(lineButtonHorizontal, deleteAllButton);
1133 HBox topologyBox = new HBox();
1134 TabPane topologyPane = new TabPane();
1135 topologyPane.setSide(Side.LEFT);
1136 final Tab topologyModifiedDriverExplorerTab = new Tab("DEVICES");
1137 topologyPane.setMaxWidth(250);
1138
1139 String hostName = label.hierarchyTestON + "/drivers/common";
1140 final Node rootIcon = new ImageView(new Image(getClass().getResourceAsStream("/images/project.jpeg"), 16, 16, true, true));
1141 TreeItem<String> driverExplorerTree = new TreeItem<String>("Drivers");
1142 File[] file = File.listRoots();
1143 Path name = new File(hostName).toPath();
1144 LoadDirectory treeNode = new LoadDirectory(name);
1145 driverExplorerTree = treeNode;
1146 driverExplorerTree.setExpanded(true);
1147 driverExplorerTreeView = new TreeView<String>(driverExplorerTree);
1148 topologyModifiedDriverExplorerTab.setContent(driverExplorerTreeView);
1149 driverExplorerTreeView.setShowRoot(false);
1150 topologyPane.getTabs().add(topologyModifiedDriverExplorerTab);
1151 topologyModifiedDriverExplorerTab.setClosable(false);
1152
1153 final TabPane topologyNewCanvas = new TabPane();
1154 topologyNewCanvas.setSide(Side.BOTTOM);
1155 final Tab canvasTab = new Tab("Canvas");
1156 canvasTab.setClosable(false);
1157 Button mew = new Button("CLICK");
1158 mew.setGraphic(rootIcon);
1159 HBox hBox1 = new HBox();
1160 hBox1.setPrefWidth(345);
1161 hBox1.setPrefHeight(200);
1162 hBox1.setStyle("-fx-border-color: blue;"
1163 + "-fx-border-width: 1;"
1164 + "-fx-border-style: solid;");
1165 Pane box1 = new Pane();
1166 box1.setPrefWidth(500);
1167 box1.setPrefHeight(200);
1168 canvasTab.setContent(box1);
1169 topologyNewCanvas.getTabs().add(canvasTab);
1170 deleteAllButton.setOnAction(new EventHandler<ActionEvent>() {
1171 @Override
1172 public void handle(ActionEvent arg0) {
1173 Pane pane = (Pane) canvasTab.getContent();
1174 ObservableList<Node> list = pane.getChildren();
1175 pane.getChildren().removeAll(list);
1176
1177 }
1178 });
1179 lineButtonVertical.setOnAction(new EventHandler<ActionEvent>() {
1180 @Override
1181 public void handle(ActionEvent arg0) {
1182 final Line connecting = new Line();
1183 connecting.setStrokeWidth(3);
1184 connecting.setEndY(90);
1185 connecting.setLayoutX(33);
1186 connecting.setLayoutY(33);
1187
1188 final DraggableNode contentLine = new DraggableNode();
1189 contentLine.setOnMouseClicked(new EventHandler<MouseEvent>() {
1190 @Override
1191 public void handle(MouseEvent arg0) {
1192 if (arg0.getClickCount() == 2) {
1193 OFATopologyLink topologyLink = new OFATopologyLink();
1194 topologyLink.start(new Stage());
1195 } else if (arg0.getButton() == MouseButton.SECONDARY) {
1196 deleteLineContextMenu(contentLine, connecting, arg0);
1197 }
1198 }
1199 });
1200
1201 contentLine.getChildren().add(connecting);
1202
1203 Pane created = (Pane) canvasTab.getContent();
1204
1205 created.getChildren().addAll(contentLine);
1206 }
1207 });
1208
1209 driverExplorerTreeView.setOnDragDetected(new EventHandler<MouseEvent>() {
1210 @Override
1211 public void handle(MouseEvent arg0) {
1212 final MultipleSelectionModel<TreeItem<String>> selectedItem = driverExplorerTreeView.getSelectionModel();
1213 try {
1214 Image i = new Image(selectedItem.getSelectedItem().getGraphic().getId(), 60, 60, true, true);
1215 Dragboard db = driverExplorerTreeView.startDragAndDrop(TransferMode.COPY);
1216
1217 ClipboardContent content = new ClipboardContent();
1218 content.putImage(i);
1219 db.setContent(content);
1220
1221 arg0.consume();
1222 } catch (Exception e) {
1223 }
1224
1225 }
1226 });
1227
1228 final Pane pane = (Pane) canvasTab.getContent();
1229 pane.setOnDragOver(new EventHandler<DragEvent>() {
1230 @Override
1231 public void handle(DragEvent t) {
1232
1233 Dragboard db = t.getDragboard();
1234
1235 if (db.hasImage()) {
1236 t.acceptTransferModes(TransferMode.COPY);
1237 }
1238 t.consume();
1239 }
1240 });
1241
1242 pane.setOnDragDropped(new EventHandler<DragEvent>() {
1243 @Override
1244 public void handle(DragEvent event) {
1245
1246 Dragboard db = event.getDragboard();
1247
1248 if (db.hasImage()) {
1249
1250 insertImage(db.getImage(), pane, event.getX(), event.getY());
1251
1252 event.setDropCompleted(true);
1253 } else {
1254 event.setDropCompleted(false);
1255 }
1256 event.consume();
1257 }
1258 });
1259
1260 SingleSelectionModel<Tab> tab = topologyNewCanvas.getSelectionModel();
1261 tab.getSelectedItem().getContent().setOnMouseClicked(new EventHandler<MouseEvent>() {
1262 @Override
1263 public void handle(MouseEvent arg0) {
1264 SingleSelectionModel<Tab> tab1 = topologyNewCanvas.getSelectionModel();
1265 }
1266 });
1267
1268 topologyBox.getChildren().addAll(topologyPane, topologyNewCanvas);
1269 parentTopologyBox.getChildren().addAll(canvasToolBar, topologyBox);
1270 return parentTopologyBox;
1271 }
1272
1273 void insertImage(Image i, final Pane hb, double x, double y) {
1274 final TextField text = new TextField();
1275 final String[] deviceInfo;;
1276 text.setId(driverExplorerTreeView.getSelectionModel().getSelectedItem().getValue().toString() + "_" + driverExplorerTreeView.getSelectionModel().getSelectedItem().getParent().getValue());
1277 deviceInfo = text.getId().split("\\_");
1278 deviceNameList.add(text);
1279 text.setPrefWidth(100);
1280 ImageView iv = new ImageView();
1281 iv.setImage(i);
1282
1283 final DraggableNode content = new DraggableNode();
1284 final VBox hbox = new VBox();
1285 hbox.setPrefWidth(80);
1286 hbox.setPrefHeight(100);
1287 lineButtonHorizontal.setOnAction(new EventHandler<ActionEvent>() {
1288 @Override
1289 public void handle(ActionEvent arg0) {
1290 final Line connecting = new Line(33, 43, 33, 43);
1291 connecting.setId("Line");
1292 connecting.setStrokeLineCap(StrokeLineCap.ROUND);
1293 connecting.setStroke(Color.MIDNIGHTBLUE);
1294 connecting.setStrokeWidth(2.5);
1295 final TopologyWizard.Anchor anchor1 = new TopologyWizard.Anchor("Anchor 1", connecting.startXProperty(), connecting.startYProperty());
1296 final TopologyWizard.Anchor anchor2 = new TopologyWizard.Anchor("Anchor 2", connecting.endXProperty(), connecting.endYProperty());
1297 anchor1.setFill(Color.TRANSPARENT.deriveColor(1, 1, 1, 0.5));
1298 anchor2.setFill(Color.TRANSPARENT.deriveColor(1, 1, 1, 0.5));
1299 Circle[] circles = {anchor1, anchor2};
1300 for (Circle circle : circles) {
1301 enableDrag(circle);
1302 }
1303 enableDragLineWithAnchors(connecting, anchor1, anchor2);
1304
1305 anchor1.setOnMouseEntered(new EventHandler<MouseEvent>() {
1306 @Override
1307 public void handle(MouseEvent arg0) {
1308 anchor1.setFill(Color.GOLD.deriveColor(1, 1, 1, 0.5));
1309 anchor1.setVisible(true);
1310 anchor2.setVisible(true);
1311 }
1312 });
1313
1314 anchor1.setOnMouseExited(new EventHandler<MouseEvent>() {
1315 @Override
1316 public void handle(MouseEvent arg0) {
1317 anchor1.setFill(Color.TRANSPARENT.deriveColor(1, 1, 1, 0.5));
1318 anchor1.setVisible(false);
1319 anchor2.setVisible(false);
1320 }
1321 });
1322
1323 anchor2.setOnMouseEntered(new EventHandler<MouseEvent>() {
1324 @Override
1325 public void handle(MouseEvent arg0) {
1326 anchor2.setFill(Color.GOLD.deriveColor(1, 1, 1, 0.5));
1327 anchor1.setVisible(true);
1328 anchor2.setVisible(true);
1329 }
1330 });
1331
1332 anchor2.setOnMouseExited(new EventHandler<MouseEvent>() {
1333 @Override
1334 public void handle(MouseEvent arg0) {
1335 anchor2.setFill(Color.TRANSPARENT.deriveColor(1, 1, 1, 0.5));
1336 anchor1.setVisible(false);
1337 anchor2.setVisible(false);
1338 }
1339 });
1340
1341 connecting.setOnMouseEntered(new EventHandler<MouseEvent>() {
1342 @Override
1343 public void handle(MouseEvent arg0) {
1344 connecting.setStroke(Color.GOLD);
1345 anchor1.setVisible(true);
1346 anchor2.setVisible(true);
1347 }
1348 });
1349 connecting.setOnMouseExited(new EventHandler<MouseEvent>() {
1350 @Override
1351 public void handle(MouseEvent arg0) {
1352 connecting.setStroke(Color.MIDNIGHTBLUE);
1353 anchor1.setVisible(false);
1354 anchor2.setVisible(false);
1355
1356 }
1357 });
1358
1359 final DraggableNode contentLine = new DraggableNode();
1360
1361 connecting.setOnMouseClicked(new EventHandler<MouseEvent>() {
1362 @Override
1363 public void handle(MouseEvent arg0) {
1364 if (arg0.getClickCount() == 2) {
1365
1366 topologyLink.start(new Stage());
1367
1368 if (arrayOfLinkTopologyHash.isEmpty()) {
1369 for (HashMap<String, String> linkHash : arrayOfLinkTopologyHash) {
1370 Set linkSet = linkHash.entrySet();
1371 Iterator linkHashDetailIterator = linkSet.iterator();
1372 while (linkHashDetailIterator.hasNext()) {
1373
1374 Map.Entry linkMap = (Map.Entry) linkHashDetailIterator.next();
1375
1376 if (linkMap.getKey().toString().equals(connecting.getId())) {
1377 String[] linkValues = linkMap.getValue().toString().split("_");
1378
1379 topologyLink.nameText.setText(linkValues[0]);
1380 topologyLink.typeText.setText(linkValues[1]);
1381 topologyLink.devicesInTopoEditor.setEditable(true);
1382 topologyLink.devicesInTopoEditor.getSelectionModel().select(linkValues[2]);
1383 topologyLink.interfaceList2.setEditable(true);
1384 topologyLink.interfaceList2.getSelectionModel().select(linkValues[3]);
1385 topologyLink.destDevicesInTopoEditor.setEditable(true);
1386 topologyLink.destDevicesInTopoEditor.getSelectionModel().select(linkValues[4]);
1387 topologyLink.interfaceList4.setEditable(true);
1388 topologyLink.interfaceList4.getSelectionModel().select(linkValues[5]);
1389
1390 }
1391 }
1392 }
1393 }
1394
1395 for (String string : draggedImagesName) {
1396 topologyLink.devicesInTopoEditor.getItems().add(string);
1397 topologyLink.destDevicesInTopoEditor.getItems().add(string);
1398 }
1399
1400 topologyLink.devicesInTopoEditor.setOnAction(new EventHandler<ActionEvent>() {
1401 @Override
1402 public void handle(ActionEvent arg0) {
1403 topologyLink.interfaceList2.getItems().clear();
1404 try {
1405 for (HashMap<String, String> interFaceDetail : arrayOfInterFaceHash) {
1406 Set set = interFaceDetail.entrySet();
1407 Iterator interFaceHashDetailIterator = set.iterator();
1408 while (interFaceHashDetailIterator.hasNext()) {
1409 Map.Entry me = (Map.Entry) interFaceHashDetailIterator.next();
1410
1411 String[] deviceNameAndiniterFaceValue = me.getValue().toString().split("\\_");
1412
1413 if (deviceNameAndiniterFaceValue[1].equals(topologyLink.devicesInTopoEditor.getSelectionModel().getSelectedItem())) {
1414 if (!me.getKey().toString().equals("")) {
1415 topologyLink.interfaceList2.getItems().add(me.getKey().toString());
1416
1417 }
1418 }
1419
1420 }
1421 }
1422 } catch (Exception e) {
1423 }
1424 }
1425 });
1426
1427 topologyLink.destDevicesInTopoEditor.setOnAction(new EventHandler<ActionEvent>() {
1428 @Override
1429 public void handle(ActionEvent arg0) {
1430 topologyLink.interfaceList4.getItems().clear();
1431 try {
1432 for (HashMap<String, String> interFaceDetail : arrayOfInterFaceHash) {
1433 Set set = interFaceDetail.entrySet();
1434 Iterator interFaceHashDetailIterator = set.iterator();
1435 while (interFaceHashDetailIterator.hasNext()) {
1436 Map.Entry me = (Map.Entry) interFaceHashDetailIterator.next();
1437 String[] deviceNameAndiniterFaceValue = me.getValue().toString().split("\\_");
1438 if (deviceNameAndiniterFaceValue[1].equals(topologyLink.destDevicesInTopoEditor.getSelectionModel().getSelectedItem())) {
1439 if (!me.getKey().toString().equals("")) {
1440 topologyLink.interfaceList4.getItems().add(me.getKey().toString());
1441 }
1442 }
1443 }
1444 }
1445 } catch (Exception e) {
1446 }
1447 }
1448 });
1449
1450 topologyLink.finishSelectedLink.setOnAction(new EventHandler<ActionEvent>() {
1451 @Override
1452 public void handle(ActionEvent arg0) {
1453 connecting.setId(topologyLink.nameText.getText() + "_" + connecting.getStartX() + "_" + connecting.getStartY() + "_" + connecting.getEndX() + "_" + connecting.getEndY());
1454 String detailedString = topologyLink.nameText.getText() + "_" + topologyLink.typeText.getText() + "_" + topologyLink.devicesInTopoEditor.getSelectionModel().getSelectedItem() + "_" + topologyLink.interfaceList2.getSelectionModel().getSelectedItem() + "_" + topologyLink.destDevicesInTopoEditor.getSelectionModel().getSelectedItem() + "_" + topologyLink.interfaceList4.getSelectionModel().getSelectedItem() + "_";
1455 linkTopologyHash.put(connecting.getId(), detailedString);
1456 arrayOfLinkTopologyHash = new ArrayList<HashMap<String, String>>();
1457 arrayOfLinkTopologyHash.add(linkTopologyHash);
1458 topologyLink.copyStage.close();
1459 }
1460 });
1461 } else if (arg0.getButton() == MouseButton.SECONDARY) {
1462 deleteLineContextMenu(contentLine, connecting, arg0);
1463 }
1464 }
1465 });
1466 hb.getChildren().addAll(connecting, anchor1, anchor2);
1467 }
1468 });
1469
1470 content.setOnMouseClicked(new EventHandler<MouseEvent>() {
1471 @Override
1472 public void handle(MouseEvent arg0) {
1473 if (anchorFlag == false) {
1474 if (arg0.getClickCount() == 1) {
1475 final Line con = new Line();
1476 con.setStrokeLineCap(StrokeLineCap.ROUND);
1477 con.setStroke(Color.MIDNIGHTBLUE);
1478 con.setStrokeWidth(2.0);
1479
1480 final Line con1 = new Line();
1481 con1.setStrokeLineCap(StrokeLineCap.ROUND);
1482 con1.setStroke(Color.MIDNIGHTBLUE);
1483 con1.setStrokeWidth(2.0);
1484
1485 final Line con2 = new Line();
1486 con2.setStrokeLineCap(StrokeLineCap.ROUND);
1487 con2.setStroke(Color.MIDNIGHTBLUE);
1488 con2.setStrokeWidth(2.0);
1489
1490 final Line con3 = new Line();
1491 con3.setStrokeLineCap(StrokeLineCap.ROUND);
1492 con3.setStroke(Color.MIDNIGHTBLUE);
1493 con3.setStrokeWidth(2.0);
1494
1495 OFAAnchorInsideImageNode mainAnchor = new OFAAnchorInsideImageNode(226.0, 41.0);
1496 final Anchor anchor3 = new Anchor("anchor3", con.startXProperty(), con.startYProperty());
1497 final Anchor anchor4 = new Anchor("anchor4", con.endXProperty(), con.endYProperty());
1498 final Anchor anchor5 = new Anchor("anchor5", con1.startXProperty(), con1.startYProperty());
1499 final Anchor anchor6 = new Anchor("anchor6", con1.endXProperty(), con1.endYProperty());
1500 final Anchor anchor7 = new Anchor("anchor7", con2.startXProperty(), con2.startYProperty());
1501 final Anchor anchor8 = new Anchor("anchor8", con2.endXProperty(), con2.endYProperty());
1502 final Anchor anchor9 = new Anchor("anchor9", con3.startXProperty(), con3.startYProperty());
1503 final Anchor anchor10 = new Anchor("anchor10", con3.endXProperty(), con3.endYProperty());
1504 anchor3.setLayoutX(content.getLayoutX());
1505 anchor3.setLayoutY(content.getLayoutY());
1506 anchor3.setVisible(false);
1507 anchor4.setLayoutX(content.getLayoutX() + 40);
1508 anchor4.setLayoutY(content.getLayoutY());
1509 anchor5.setLayoutX(content.getLayoutX());
1510 anchor5.setLayoutY(content.getLayoutY());
1511 anchor5.setVisible(false);
1512 anchor6.setLayoutX(content.getLayoutX() + 40);
1513 anchor6.setLayoutY(content.getLayoutY() + 100);
1514 anchor7.setLayoutX(content.getLayoutX());
1515 anchor7.setLayoutY(content.getLayoutY());
1516 anchor7.setVisible(false);
1517 anchor8.setLayoutX(content.getLayoutX());
1518 anchor8.setLayoutY(content.getLayoutY() + 50);
1519 anchor9.setLayoutX(content.getLayoutX());
1520 anchor9.setLayoutY(content.getLayoutY());
1521 anchor9.setVisible(false);
1522 anchor10.setLayoutX(content.getLayoutX() + 80);
1523 anchor10.setLayoutY(content.getLayoutY() + 50);
1524
1525 con1.setLayoutX(anchor6.getLayoutX());
1526 con1.setLayoutY(anchor6.getLayoutY());
1527 con.setLayoutX(anchor4.getLayoutX());
1528 con.setLayoutY(anchor4.getLayoutY());
1529 con2.setLayoutX(anchor8.getLayoutX());
1530 con2.setLayoutY(anchor8.getLayoutY());
1531 con3.setLayoutX(anchor10.getLayoutX());
1532 con3.setLayoutY(anchor10.getLayoutY());
1533
1534 con.setId("connectingLine");
1535 con.setLayoutX(anchor4.getLayoutX());
1536 con.setLayoutY(anchor4.getLayoutY());
1537
1538 anchorFlag = true;
1539 hb.getChildren().addAll(con, anchor3, anchor4, con1, anchor5, anchor6, con2, anchor7, anchor8, con3, anchor9, anchor10);
1540 HashMap<Node, String> anchorNodeHash = new HashMap();
1541
1542 anchorNodeHash.put(anchor4, anchor4.getId());
1543 anchorNodeHash.put(anchor6, anchor6.getId());
1544 anchorNodeHash.put(anchor8, anchor8.getId());
1545 anchorNodeHash.put(anchor10, anchor10.getId());
1546 anchorNodeHash.put(con1, con1.getId());
1547 anchorNodeHash.put(con2, con2.getId());
1548 anchorNodeHash.put(con3, con3.getId());
1549 anchorNodeHash.put(con, con.getId());
1550
1551 final ObservableList<Node> allNodeInCanvas = hb.getChildren();
1552 mainAnchor.anchorsInsideImage(anchor4, 40, 0, 40, 100, hb, content, hbox, con, draggedImagesName, arrayOfInterFaceHash, linkTopologyHash, anchorNodeHash);
1553 mainAnchor.anchorsInsideImage(anchor6, 40, 100, 40, 0, hb, content, hbox, con, draggedImagesName, arrayOfInterFaceHash, linkTopologyHash, anchorNodeHash);
1554 mainAnchor.anchorsInsideImage(anchor8, 0, 50, 80, 50, hb, content, hbox, con, draggedImagesName, arrayOfInterFaceHash, linkTopologyHash, anchorNodeHash);
1555 mainAnchor.anchorsInsideImage(anchor10, 80, 50, 0, 50, hb, content, hbox, con, draggedImagesName, arrayOfInterFaceHash, linkTopologyHash, anchorNodeHash);
1556
1557 hbox.setOnDragDetected(new EventHandler<MouseEvent>() {
1558 @Override
1559 public void handle(MouseEvent t) {
1560 hbox.startFullDrag();
1561 }
1562 });
1563
1564 hbox.setOnMouseDragged(new EventHandler<MouseEvent>() {
1565 @Override
1566 public void handle(MouseEvent t) {
1567 anchorFlag = false;
1568 hb.getChildren().removeAll(con, con1, con2, con3, anchor4, anchor6, anchor8, anchor10);
1569 }
1570 });
1571
1572 content.setOnMouseMoved(new EventHandler<MouseEvent>() {
1573 @Override
1574 public void handle(MouseEvent arg0) {
1575 Double x13 = content.getScene().getX() + 482.0 + 53.0;
1576 Double x14 = content.getLayoutX() + 482.0;
1577 Double y13 = content.getScene().getY() + 142.0 + 92.0;
1578 Double y14 = content.getLayoutY() + 142.0;
1579 boolean exitFlag = false;
1580 for (int i = 0; i <= 80; i++) {
1581 for (int j = 0; j <= 100; j++) {
1582 Double x1 = content.getScene().getX();
1583 Double y1 = content.getScene().getX();
1584 Double x11 = x1 + i;
1585 Double y11 = y1 + j;
1586 if (x11 == arg0.getSceneX()) {
1587 if (y11 == arg0.getSceneY()) {
1588 exitFlag = true;
1589 }
1590 }
1591 }
1592 }
1593
1594 if (exitFlag == false) {
1595 anchorFlag = false;
1596 hb.getChildren().removeAll(con, con1, con2, con3, anchor4, anchor5, anchor6, anchor7, anchor8, anchor9, anchor10);
1597 }
1598 }
1599 });
1600
1601 }
1602 }
1603
1604 if (arg0.getClickCount() == 2) {
1605 if (deviceInfo[0].equals("fvtapidriver") || deviceInfo[0].equals("poxclidriver") || deviceInfo[0].equals("mininetclidriver") || deviceInfo[0].equals("dpctlclidriver")
1606 || deviceInfo[0].equals("floodlightclidriver") || deviceInfo[0].equals("flowvisorclidriver") || deviceInfo[0].equals("hpswitchclidriver")
1607 || deviceInfo[0].equals("remotevmdriver") || deviceInfo[0].equals("remotepoxdriver") || deviceInfo[0].equals("flowvisordriver") || deviceInfo[0].equals("switchclidriver")) {
1608 try {
1609 topoplogy = new OFATopology();
1610 topoplogy.start(new Stage());
1611 } catch (Exception ex) {
1612 Logger.getLogger(TopologyWizard.class.getName()).log(Level.SEVERE, null, ex);
1613 }
1614
1615 if (topoplogy.testTargetRadioButton.isSelected()) {
1616 selectFlag = true;
1617 }
1618
1619 topoplogy.cancelButton.setOnAction(new EventHandler<ActionEvent>() {
1620 @Override
1621 public void handle(ActionEvent arg0) {
1622 topoplogy.copyStage.close();
1623 }
1624 });
1625
1626 topoplogy.save.setOnAction(new EventHandler<ActionEvent>() {
1627 @Override
1628 public void handle(ActionEvent arg0) {
1629 topoplogy.getHostName = topoplogy.hostNameText.getText();
1630 topoplogy.getUserName = topoplogy.userNameText.getText();
1631 topoplogy.getPassword = topoplogy.passwordText.getText();
1632
1633 for (int i = 0; i < topoplogy.deviceTable.getItems().size(); i++) {
1634 topoplogy.deviceTable.getSelectionModel().select(i);
1635 interFaceHashDetail.put(topoplogy.deviceTable.getSelectionModel().getSelectedItem().getDeviceName().getText(), topoplogy.deviceTable.getSelectionModel().getSelectedItem().getDeviceType().getText() + "_" + text.getText());
1636 arrayOfInterFaceHash = new ArrayList<HashMap<String, String>>();
1637 arrayOfInterFaceHash.add(interFaceHashDetail);
1638 }
1639
1640 draggedImagesName.add(text.getText());
1641 propertyValue.add(text.getText() + "\n" + topoplogy.getHostName + "\n" + topoplogy.getUserName + "\n" + topoplogy.getPassword + "\n" + topoplogy.getTranportProtocol + "\n" + deviceInfo[0] + "\n" + topoplogy.getPort + "\n" + content.getId());
1642 topoplogy.copyStage.close();
1643 }
1644 });
1645 }
1646 if (deviceInfo[1].equals("cli") || deviceInfo[1].equals("poxclidriver") || deviceInfo[1].equals("mininetclidriver") || deviceInfo[1].equals("dpctlclidriver")
1647 || deviceInfo[1].equals("floodlightclidriver") || deviceInfo[1].equals("flowvisorclidriver") || deviceInfo[1].equals("hpswitchclidriver")
1648 || deviceInfo[1].equals("remotevmdriver") || deviceInfo[1].equals("remotepoxdriver") || deviceInfo[1].equals("flowvisordriver") || deviceInfo[1].equals("switchclidriver")) {
1649 try {
1650 topoplogy = new OFATopology();
1651 topoplogy.start(new Stage());
1652 } catch (Exception ex) {
1653 Logger.getLogger(TopologyWizard.class.getName()).log(Level.SEVERE, null, ex);
1654 }
1655
1656 topoplogy.cancelButton.setOnAction(new EventHandler<ActionEvent>() {
1657 @Override
1658 public void handle(ActionEvent arg0) {
1659 topoplogy.copyStage.close();
1660 }
1661 });
1662
1663 try {
1664 topoplogy.save.setOnAction(new EventHandler<ActionEvent>() {
1665 @Override
1666 public void handle(ActionEvent arg0) {
1667 topoplogy.getHostName = topoplogy.hostNameText.getText();
1668 topoplogy.getUserName = topoplogy.userNameText.getText();
1669 topoplogy.getPassword = topoplogy.passwordText.getText();
1670 for (int i = 0; i < topoplogy.deviceTable.getItems().size(); i++) {
1671 topoplogy.deviceTable.getSelectionModel().select(i);
1672 interFaceHashDetail.put(topoplogy.deviceTable.getSelectionModel().getSelectedItem().getDeviceName().getText(), topoplogy.deviceTable.getSelectionModel().getSelectedItem().getDeviceType().getText() + "_" + text.getText());
1673 arrayOfInterFaceHash = new ArrayList<HashMap<String, String>>();
1674 arrayOfInterFaceHash.add(interFaceHashDetail);
1675 }
1676 draggedImagesName.add(text.getText());
1677 propertyValue.add(text.getText() + "\n" + topoplogy.getHostName + "\n" + topoplogy.getUserName + "\n" + topoplogy.getPassword + "\n" + topoplogy.getTranportProtocol + "\n" + deviceInfo[0] + "\n" + topoplogy.getPort + "\n" + content.getId());
1678 topoplogy.copyStage.close();
1679 }
1680 });
1681 } catch (Exception e) {
1682 }
1683 }
1684
1685 }
1686 }
1687 });
1688
1689 final Button closeButton = new Button();
1690 Tooltip close = new Tooltip();
1691 close.setText("Delete this device");
1692 closeButton.setTooltip(close);
1693 Image image = new Image(getClass().getResourceAsStream("/images/close_icon2.jpg"), 12, 12, true, true);
1694 ImageView imageNew3 = new ImageView(image);
1695 closeButton.setGraphic(imageNew3);
1696 closeButton.setStyle("-fx-background-color: white;");
1697
1698 final ArrayList<Node> removeNodes = new ArrayList<Node>();
1699 closeButton.setOnAction(new EventHandler<ActionEvent>() {
1700 @Override
1701 public void handle(ActionEvent arg0) {
1702 OFAAnchorInsideImageNode node = new OFAAnchorInsideImageNode(224.0, 41.0);
1703 node.closeNodeOnCanvas(closeButton, hbox, hb, content);
1704 Node parent = hbox.getParent();
1705 ObservableList<Node> allCurrentNode = hb.getChildren();
1706 for (Node node1 : allCurrentNode) {
1707 if (node1.toString().contains("Line")) {
1708 if (!node1.toString().matches("Line[id=Line[id=null,null]]")) {
1709 if (node1.getId() != null) {
1710 String[] startLineNode = node1.getId().split(",");
1711 Integer nodeHash = content.hashCode();
1712
1713 if (nodeHash.toString().equals(startLineNode[0])) {
1714 removeNodes.add(node1);
1715 }
1716
1717 if (startLineNode.length == 2) {
1718 if (nodeHash.toString().equals(startLineNode[1])) {
1719 removeNodes.add(node1);
1720 }
1721 }
1722 }
1723 }
1724 }
1725 }
1726
1727 for (Node removenode : removeNodes) {
1728 hb.getChildren().remove(removenode);
1729 }
1730
1731 hb.getChildren().remove(content);
1732
1733 }
1734 });
1735
1736 hbox.getChildren().addAll(closeButton, iv, text);
1737 hbox.setId(iv.toString());
1738
1739 text.setPromptText("Device Name");
1740 content.getChildren().add(hbox);
1741
1742 content.setOnMouseEntered(new EventHandler<MouseEvent>() {
1743 @Override
1744 public void handle(MouseEvent arg0) {
1745 hbox.setStyle("-fx-border-color: Gold");
1746 }
1747 });
1748
1749 content.setOnMouseExited(new EventHandler<MouseEvent>() {
1750 @Override
1751 public void handle(MouseEvent arg0) {
1752 hbox.setStyle("-fx-border-color: Transparent");
1753 Double xcoordinate = content.getLayoutX();
1754 Double ycoordinate = content.getLayoutY();
1755 OFATopology device = new OFATopology();
1756
1757 content.setId(xcoordinate.toString() + "," + ycoordinate.toString());
1758 }
1759 });
1760
1761 content.setLayoutX(x - 40);
1762 content.setLayoutY(y - 30);
1763 hb.getChildren().add(content);
1764 }
1765
1766 void anchorsInsideImageNode(final Anchor anchor, final double bindLinex, final double bindLiney, final Pane hb, final DraggableNode content, final VBox hbox, final Line con) {
1767
1768
1769 final Line con11 = new Line();
1770
1771 anchor.setOnDragDetected(new EventHandler<MouseEvent>() {
1772 @Override
1773 public void handle(MouseEvent arg0) {
1774 anchor.startFullDrag();
1775 enableDrag(anchor);
1776 }
1777 });
1778
1779 anchor.setOnMouseExited(new EventHandler<MouseEvent>() {
1780 @Override
1781 public void handle(MouseEvent arg0) {
1782
1783 boolean exitFlag = false;
1784 for (int i = 0; i <= 80; i++) {
1785 for (int j = 0; j <= 100; j++) {
1786 Double x1 = anchor.getLayoutX() + 482.0;
1787 Double y1 = anchor.getLayoutY() + 142.0;
1788 Double x11 = x1 + i;
1789 Double y11 = y1 + j;
1790 if (x11 == arg0.getSceneX()) {
1791 if (y11 == arg0.getSceneY()) {
1792 exitFlag = true;
1793
1794 }
1795 }
1796 }
1797 }
1798 if (exitFlag == false) {
1799 hbox.setStyle("-fx-border-color: Transparent");
1800 anchor.setVisible(false);
1801 con.setVisible(false);
1802
1803 }
1804 }
1805 });
1806
1807 hbox.setOnMouseDragged(new EventHandler<MouseEvent>() {
1808 @Override
1809 public void handle(MouseEvent arg0) {
1810 try {
1811 con.setVisible(false);
1812 anchor.setVisible(false);
1813 hb.getChildren().removeAll(con, anchor);
1814 } catch (Exception e) {
1815 }
1816
1817 }
1818 });
1819
1820 anchor.setOnMouseDragReleased(new EventHandler<MouseDragEvent>() {
1821 @Override
1822 public void handle(MouseDragEvent arg0) {
1823
1824 ObservableList<Node> allNodesCanvas = hb.getChildren();
1825 boolean flag = false;
1826 try {
1827 for (Node node : allNodesCanvas) {
1828
1829 Double x = node.getLayoutX() + 226.0;
1830 Double y = node.getLayoutY() + 41.0;
1831
1832 if (node.toString().startsWith("DraggableNode")) {
1833 for (int i = 0; i <= 80; i++) {
1834 for (int j = 0; j <= 100; j++) {
1835 Double x1 = node.getLayoutX() + 226.0;
1836 Double y1 = node.getLayoutY() + 41.0;
1837 Double x11 = x1 + i;
1838 Double y11 = y1 + j;
1839 if (x11 == arg0.getSceneX()) {
1840 if (y11 == arg0.getSceneY()) {
1841 con11.setStrokeLineCap(StrokeLineCap.ROUND);
1842 con11.setStroke(Color.MIDNIGHTBLUE);
1843 con11.setStrokeWidth(2.0);
1844 con11.startXProperty().bind(content.layoutXProperty().add(bindLinex));
1845 con11.startYProperty().bind(content.layoutYProperty().add(bindLiney));
1846 con11.endXProperty().bind(node.layoutXProperty().add(bindLinex));
1847 con11.endYProperty().bind(node.layoutYProperty().add(bindLiney));
1848
1849 hbox.setStyle("-fx-border-color: Transparent");
1850
1851 hb.getChildren().add(con11);
1852 con.setVisible(false);
1853 anchor.setVisible(false);
1854 flag = true;
1855
1856 }
1857
1858 }
1859 }
1860 }
1861
1862 }
1863
1864 }
1865 if (flag == false) {
1866 con.setVisible(false);
1867 anchor.setVisible(false);
1868 }
1869 } catch (Exception e) {
1870
1871 }
1872
1873 }
1874 });
1875
1876 con11.setOnMouseEntered(new EventHandler<MouseEvent>() {
1877 @Override
1878 public void handle(MouseEvent arg0) {
1879
1880 con11.setStroke(Color.GOLD);
1881
1882 }
1883 });
1884 con11.setOnMouseExited(new EventHandler<MouseEvent>() {
1885 @Override
1886 public void handle(MouseEvent arg0) {
1887
1888 con11.setStroke(Color.MIDNIGHTBLUE);
1889 }
1890 });
1891
1892 final DraggableNode contentLine = new DraggableNode();
1893 con11.setOnMouseClicked(new EventHandler<MouseEvent>() {
1894 @Override
1895 public void handle(MouseEvent arg0) {
1896 if (arg0.getClickCount() == 2) {
1897
1898 topologyLink.start(new Stage());
1899
1900 if (arrayOfLinkTopologyHash.isEmpty()) {
1901 for (HashMap<String, String> linkHash : arrayOfLinkTopologyHash) {
1902 Set linkSet = linkHash.entrySet();
1903 Iterator linkHashDetailIterator = linkSet.iterator();
1904 while (linkHashDetailIterator.hasNext()) {
1905
1906 Map.Entry linkMap = (Map.Entry) linkHashDetailIterator.next();
1907 if (linkMap.getKey().toString().equals(con11.getId())) {
1908 String[] linkValues = linkMap.getValue().toString().split("_");
1909 topologyLink.nameText.setText(linkValues[0]);
1910 topologyLink.typeText.setText(linkValues[1]);
1911 topologyLink.devicesInTopoEditor.setEditable(true);
1912 topologyLink.devicesInTopoEditor.getSelectionModel().select(linkValues[2]);
1913 topologyLink.interfaceList2.setEditable(true);
1914 topologyLink.interfaceList2.getSelectionModel().select(linkValues[3]);
1915 topologyLink.destDevicesInTopoEditor.setEditable(true);
1916 topologyLink.destDevicesInTopoEditor.getSelectionModel().select(linkValues[4]);
1917 topologyLink.interfaceList4.setEditable(true);
1918 topologyLink.interfaceList4.getSelectionModel().select(linkValues[5]);
1919 }
1920 }
1921 }
1922 }
1923
1924 for (String string : draggedImagesName) {
1925 topologyLink.devicesInTopoEditor.getItems().add(string);
1926 topologyLink.destDevicesInTopoEditor.getItems().add(string);
1927 }
1928
1929 topologyLink.devicesInTopoEditor.setOnAction(new EventHandler<ActionEvent>() {
1930 @Override
1931 public void handle(ActionEvent arg0) {
1932 topologyLink.interfaceList2.getItems().clear();
1933 try {
1934 for (HashMap<String, String> interFaceDetail : arrayOfInterFaceHash) {
1935 Set set = interFaceDetail.entrySet();
1936 Iterator interFaceHashDetailIterator = set.iterator();
1937 while (interFaceHashDetailIterator.hasNext()) {
1938 Map.Entry me = (Map.Entry) interFaceHashDetailIterator.next();
1939 String[] deviceNameAndiniterFaceValue = me.getValue().toString().split("\\_");
1940 if (deviceNameAndiniterFaceValue[1].equals(topologyLink.devicesInTopoEditor.getSelectionModel().getSelectedItem())) {
1941 if (!me.getKey().toString().equals("")) {
1942 topologyLink.interfaceList2.getItems().add(me.getKey().toString());
1943 }
1944 }
1945 }
1946 }
1947 } catch (Exception e) {
1948 }
1949 }
1950 });
1951
1952 topologyLink.destDevicesInTopoEditor.setOnAction(new EventHandler<ActionEvent>() {
1953 @Override
1954 public void handle(ActionEvent arg0) {
1955
1956 topologyLink.interfaceList4.getItems().clear();
1957 try {
1958 for (HashMap<String, String> interFaceDetail : arrayOfInterFaceHash) {
1959 Set set = interFaceDetail.entrySet();
1960 Iterator interFaceHashDetailIterator = set.iterator();
1961 while (interFaceHashDetailIterator.hasNext()) {
1962 Map.Entry me = (Map.Entry) interFaceHashDetailIterator.next();
1963 String[] deviceNameAndiniterFaceValue = me.getValue().toString().split("\\_");
1964
1965 if (deviceNameAndiniterFaceValue[1].equals(topologyLink.destDevicesInTopoEditor.getSelectionModel().getSelectedItem())) {
1966 if (!me.getKey().toString().equals("")) {
1967 topologyLink.interfaceList4.getItems().add(me.getKey().toString());
1968 }
1969 }
1970 }
1971 }
1972 } catch (Exception e) {
1973 }
1974 }
1975 });
1976
1977 topologyLink.finishSelectedLink.setOnAction(new EventHandler<ActionEvent>() {
1978 @Override
1979 public void handle(ActionEvent arg0) {
1980 con11.setId(topologyLink.nameText.getText() + "_" + con11.getStartX() + "_" + con11.getStartY() + "_" + con11.getEndX() + "_" + con11.getEndY());
1981 String detailedString = topologyLink.nameText.getText() + "_" + topologyLink.typeText.getText() + "_" + topologyLink.devicesInTopoEditor.getSelectionModel().getSelectedItem() + "_" + topologyLink.interfaceList2.getSelectionModel().getSelectedItem() + "_" + topologyLink.destDevicesInTopoEditor.getSelectionModel().getSelectedItem() + "_" + topologyLink.interfaceList4.getSelectionModel().getSelectedItem() + "_";
1982 linkTopologyHash.put(con11.getId(), detailedString);
1983 arrayOfLinkTopologyHash = new ArrayList<HashMap<String, String>>();
1984 arrayOfLinkTopologyHash.add(linkTopologyHash);
1985 topologyLink.copyStage.close();
1986 }
1987 });
1988
1989
1990 }
1991 if (arg0.getButton() == MouseButton.SECONDARY) {
1992 deleteLineContextMenu(contentLine, con11, arg0);
1993
1994 }
1995 }
1996 });
1997
1998 }
1999
2000 void insertImage1(Image i, Tab hb) {
2001 ImageView iv = new ImageView();
2002 iv.setImage(i);
2003 setupGestureSource(iv);
2004 }
2005
2006 void setupGestureTarget(final HBox targetBox) {
2007 targetBox.setOnDragOver(new EventHandler<DragEvent>() {
2008 @Override
2009 public void handle(DragEvent event) {
2010 Dragboard db = event.getDragboard();
2011 if (db.hasImage()) {
2012 event.acceptTransferModes(TransferMode.COPY);
2013 }
2014 event.consume();
2015 }
2016 });
2017
2018 targetBox.setOnDragDropped(new EventHandler<DragEvent>() {
2019 @Override
2020 public void handle(DragEvent event) {
2021 Dragboard db = event.getDragboard();
2022 if (db.hasImage()) {
2023 event.setDropCompleted(true);
2024 } else {
2025 event.setDropCompleted(false);
2026 }
2027 event.consume();
2028 }
2029 });
2030 }
2031
2032 void setupGestureSource(final ImageView source) {
2033 source.setOnDragDetected(new EventHandler<MouseEvent>() {
2034 @Override
2035 public void handle(MouseEvent event) {
2036
2037 /*
2038 * allow any transfer mode
2039 */
2040 Dragboard db = source.startDragAndDrop(TransferMode.COPY);
2041
2042 /*
2043 * put a image on dragboard
2044 */
2045 ClipboardContent content = new ClipboardContent();
2046
2047 Image sourceImage = source.getImage();
2048 content.putImage(sourceImage);
2049 db.setContent(content);
2050
2051 event.consume();
2052 }
2053 });
2054
2055 }
2056
2057 void deleteLineContextMenu(final DraggableNode contentLine, final Line connecting, MouseEvent arg0) {
2058
2059 ContextMenu menu = new ContextMenu();
2060 MenuItem item = new MenuItem("Delete Line");
2061 item.setOnAction(new EventHandler<ActionEvent>() {
2062 @Override
2063 public void handle(ActionEvent arg0) {
2064 contentLine.setVisible(false);
2065 contentLine.getChildren().remove(connecting);
2066 }
2067 });
2068
2069 menu.getItems().add(item);
2070 menu.show(contentLine, arg0.getScreenX(), arg0.getScreenY());
2071
2072 }
2073
2074 public ArrayList<TextField> getDeviceNameList() {
2075 return deviceNameList;
2076 }
2077
2078 public ArrayList<String> getPropertyDetail() {
2079 return propertyValue;
2080 }
2081
2082 class Anchor extends Circle {
2083
2084 Anchor(String id, DoubleProperty x, DoubleProperty y) {
2085 super(x.get(), y.get(), 7);
2086 setId(id);
2087 setFill(Color.ANTIQUEWHITE.deriveColor(1, 1, 1, 0.75));
2088 setStroke(Color.GREY);
2089 x.bind(centerXProperty());
2090 y.bind(centerYProperty());
2091 }
2092 }
2093
2094 class Anchor2 extends DraggableNode {
2095
2096 Anchor2(String id, DoubleProperty x, DoubleProperty y) {
2097 super();
2098 setId(id);
2099
2100 x.bind(layoutXProperty());
2101 y.bind(layoutYProperty());
2102 }
2103 }
2104
2105 private void enableDragLineWithAnchors(final Line connecting, final Circle anchor1, final Circle anchor2) {
2106 final Delta dragDelta = new Delta();
2107
2108 connecting.setOnMousePressed(new EventHandler<MouseEvent>() {
2109 @Override
2110 public void handle(MouseEvent mouseEvent) {
2111 // record a delta distance for the drag and drop operation.
2112 dragDelta.x = connecting.getLayoutX() - mouseEvent.getX();
2113 dragDelta.y = connecting.getLayoutY() - mouseEvent.getY();
2114 dragDelta.x = anchor1.getLayoutX() - mouseEvent.getX();
2115 dragDelta.y = anchor1.getLayoutY() - mouseEvent.getY();
2116 dragDelta.x = anchor2.getLayoutX() - mouseEvent.getX();
2117 dragDelta.y = anchor2.getLayoutY() - mouseEvent.getY();
2118 connecting.getScene().setCursor(Cursor.MOVE);
2119 }
2120 });
2121 connecting.setOnMouseReleased(new EventHandler<MouseEvent>() {
2122 @Override
2123 public void handle(MouseEvent mouseEvent) {
2124 connecting.getScene().setCursor(Cursor.HAND);
2125 }
2126 });
2127 connecting.setOnMouseDragged(new EventHandler<MouseEvent>() {
2128 @Override
2129 public void handle(MouseEvent mouseEvent) {
2130 connecting.setLayoutX(mouseEvent.getX() + dragDelta.x);
2131 connecting.setLayoutY(mouseEvent.getY() + dragDelta.y);
2132 anchor1.setLayoutX(mouseEvent.getX() + dragDelta.x);
2133 anchor1.setLayoutY(mouseEvent.getY() + dragDelta.y);
2134 anchor2.setLayoutX(mouseEvent.getX() + dragDelta.x);
2135 anchor2.setLayoutY(mouseEvent.getY() + dragDelta.y);
2136
2137 }
2138 });
2139 connecting.setOnMouseEntered(new EventHandler<MouseEvent>() {
2140 @Override
2141 public void handle(MouseEvent mouseEvent) {
2142 if (!mouseEvent.isPrimaryButtonDown()) {
2143 connecting.getScene().setCursor(Cursor.HAND);
2144 }
2145 }
2146 });
2147
2148 connecting.setOnMouseExited(new EventHandler<MouseEvent>() {
2149 @Override
2150 public void handle(MouseEvent mouseEvent) {
2151 if (!mouseEvent.isPrimaryButtonDown()) {
2152 connecting.getScene().setCursor(Cursor.DEFAULT);
2153 }
2154 }
2155 });
2156 }
2157
2158 private void enableDrag(final Circle circle) {
2159 final TopologyWizard.Delta dragDelta = new TopologyWizard.Delta();
2160 circle.setOnMousePressed(new EventHandler<MouseEvent>() {
2161 @Override
2162 public void handle(MouseEvent mouseEvent) {
2163 // record a delta distance for the drag and drop operation.
2164 dragDelta.x = circle.getCenterX() - mouseEvent.getX();
2165 dragDelta.y = circle.getCenterY() - mouseEvent.getY();
2166 circle.getScene().setCursor(Cursor.MOVE);
2167 }
2168 });
2169 circle.setOnMouseReleased(new EventHandler<MouseEvent>() {
2170 @Override
2171 public void handle(MouseEvent mouseEvent) {
2172 circle.getScene().setCursor(Cursor.HAND);
2173 }
2174 });
2175 circle.setOnMouseDragged(new EventHandler<MouseEvent>() {
2176 @Override
2177 public void handle(MouseEvent mouseEvent) {
2178 circle.setCenterX(mouseEvent.getX() + dragDelta.x);
2179 circle.setCenterY(mouseEvent.getY() + dragDelta.y);
2180 }
2181 });
2182 circle.setOnMouseEntered(new EventHandler<MouseEvent>() {
2183 @Override
2184 public void handle(MouseEvent mouseEvent) {
2185 if (!mouseEvent.isPrimaryButtonDown()) {
2186 circle.getScene().setCursor(Cursor.HAND);
2187 }
2188 }
2189 });
2190 circle.setOnMouseExited(new EventHandler<MouseEvent>() {
2191 @Override
2192 public void handle(MouseEvent mouseEvent) {
2193 if (!mouseEvent.isPrimaryButtonDown()) {
2194 circle.getScene().setCursor(Cursor.DEFAULT);
2195 }
2196 }
2197 });
2198 }
2199
2200 class Delta {
2201
2202 double x, y;
2203 }
2204}