blob: b2e683073dc6bb1183d44e564eef2a2373c2f2fe [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.util.ArrayList;
8import java.util.HashMap;
9import java.util.Locale;
10import javafx.application.Application;
11import javafx.collections.FXCollections;
12import javafx.collections.ObservableList;
13import javafx.event.Event;
14import javafx.event.EventHandler;
15import javafx.geometry.Insets;
16import javafx.scene.Scene;
17import javafx.scene.control.Button;
18import javafx.scene.control.ComboBox;
19import javafx.scene.control.Label;
20import javafx.scene.control.PasswordField;
21import javafx.scene.control.RadioButton;
22import javafx.scene.control.Tab;
23import javafx.scene.control.TabPane;
24import javafx.scene.control.TableColumn;
25import javafx.scene.control.TableColumn.CellEditEvent;
26import javafx.scene.control.TableView;
27import javafx.scene.control.TextField;
28import javafx.scene.control.TextFieldBuilder;
29import javafx.scene.control.cell.PropertyValueFactory;
30import javafx.scene.control.cell.TextFieldTableCell;
31import javafx.scene.input.KeyCode;
32import javafx.scene.input.KeyEvent;
33import javafx.scene.layout.GridPane;
34import javafx.scene.layout.HBox;
35import javafx.scene.layout.Pane;
36import javafx.stage.Stage;
37import sun.misc.Cleaner;
38
39/**
40 *
41 * @author Raghav Kashyap (raghavkashyap@paxterrasolutions.com)
42
43 * TestON is free software: you can redistribute it and/or modify
44 * it under the terms of the GNU General Public License as published by
45 * the Free Software Foundation, either version 2 of the License, or
46 * (at your option) any later version.
47
48 * TestON is distributed in the hope that it will be useful,
49 * but WITHOUT ANY WARRANTY; without even the implied warranty of
50 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
51 * GNU General Public License for more details.
52
53 * You should have received a copy of the GNU General Public License
54 * along with TestON. If not, see <http://www.gnu.org/licenses/>.
55
56 */
57public class OFATopology extends Application {
58
59 public OFATopology() {
60 }
61 ObservableList<OFATopologyInterface> data;
62 TableView<OFATopologyInterface> deviceTable;
63 TableColumn device;
64 TableColumn number;
65 TableColumn type;
66 int count = 1;
67 String getHostName, getUserName, getPassword, getTranportProtocol, getPort;
68 ArrayList<String> getAttribute = new ArrayList<String>();
69 ArrayList<String> getValue = new ArrayList<String>();
70 ArrayList<TextField> attributeList = new ArrayList<TextField>();
71 ArrayList<TextField> valueList = new ArrayList<TextField>();
72 TextField attributeText;
73 Button interFacesave;
74 TextField valueText;
75 Button save;
76 TextField hostNameText;
77 TextField userNameText;
78 PasswordField passwordText;
79 TextField portText;
80 TextField deviceText;
81 ComboBox<String> transportList;
82 Stage copyStage;
83 ArrayList<String> propertyDetail = new ArrayList<String>();
84 HashMap<TextField, TextField> hashProperty = new HashMap<TextField, TextField>();
85 Button defaultButton;
86 Button cancelButton;
87 RadioButton testTargetRadioButton;
88 TAILocale label = new TAILocale(new Locale("en", "EN"));
89
90 /**
91 * @param args the command line arguments
92 */
93 OFATopology(TextField text) {
94 deviceText = text;
95 }
96
97 @Override
98 public void start(final Stage primaryStage) {
99 copyStage = primaryStage;
100 primaryStage.setTitle(label.topoTitle);
101 primaryStage.setResizable(false);
102 TabPane toplogyTabPane = new TabPane();
103 toplogyTabPane.setMaxHeight(280);
104 Tab propertyTab = new Tab(label.topoProperties);
105 Tab interfaceTab = new Tab("Component");
106 propertyTab.setClosable(false);
107 interfaceTab.setClosable(false);
108 toplogyTabPane.getTabs().addAll(propertyTab, interfaceTab);
109
110 GridPane propertyGrid = new GridPane();
111 propertyGrid.setVgap(8);
112 propertyGrid.setHgap(10);
113 propertyGrid.setPadding(new Insets(10, 0, 0, 50));
114
115 Label attribute = new Label(label.topoAttribute);
116 attribute.setStyle("-fx-padding: 0; -fx-background-color: lightgray; -fx-border-width: 2;-fx-border-color: gray;");
117 propertyGrid.add(attribute, 0, 1);
118
119 Label value = new Label(label.topoValue);
120 value.setStyle("-fx-padding: 0; -fx-background-color: lightgray; -fx-border-width: 2;-fx-border-color: gray;");
121 propertyGrid.add(value, 1, 1);
122
123 Label hostName = new Label(label.topoHost);
124 propertyGrid.add(hostName, 0, 2);
125 hostNameText = new TextField();
126 propertyGrid.add(hostNameText, 1, 2);
127 Label userName = new Label(label.topoUserName);
128 propertyGrid.add(userName, 0, 3);
129 userNameText = new TextField();
130 propertyGrid.add(userNameText, 1, 3);
131 Label password = new Label(label.topoPassword);
132 propertyGrid.add(password, 0, 4);
133 passwordText = new PasswordField();
134 propertyGrid.add(passwordText, 1, 4);
135 Label transport = new Label(label.topoTransport);
136 transportList = new ComboBox<String>();
137 transportList.setMinWidth(200);
138 transportList.getItems().addAll(label.topoSSH, label.topoTELNET, label.topoFTP, label.topoRLOGIN);
139 Label testTargetLabel = new Label("Test Target");
140 propertyGrid.add(testTargetLabel, 0, 5);
141 testTargetRadioButton = new RadioButton("True");
142 propertyGrid.add(testTargetRadioButton, 1, 5);
143 HBox propertyButton = new HBox(5);
144
145 propertyButton.setPadding(new Insets(280, 0, 0, 140));
146 save = new Button(label.topoSave);
147 defaultButton = new Button(label.topoDefault);
148 cancelButton = new Button(label.topoCancel);
149 propertyButton.getChildren().addAll(save, defaultButton, cancelButton);
150 propertyTab.setContent(propertyGrid);
151
152 // interface tab code
153 GridPane interfaceGridPane = new GridPane();
154 interfaceGridPane.setVgap(20);
155 interfaceGridPane.setHgap(20);
156 interfaceGridPane.setPadding(new Insets(10, 0, 0, 10));
157 Label interFaceNumber = new Label("" + count);
158 attributeText = new TextField();
159 valueText = new TextField();
160
161 valueText.setOnKeyPressed(new EventHandler<KeyEvent>() {
162 @Override
163 public void handle(KeyEvent keyEvent) {
164 if (keyEvent.getCode() == KeyCode.ENTER) {
165 deviceTable.getSelectionModel().select(deviceTable.getItems().size() - 1);
166 if (deviceTable.getSelectionModel().isSelected(deviceTable.getItems().size() - 1)) {
167 if (!deviceTable.getSelectionModel().getSelectedItem().getDeviceName().getText().equals("") && !deviceTable.getSelectionModel().getSelectedItem().getDeviceType().getText().equals("")) {
168 addInterFace();
169 }
170 }
171 }
172 }
173 });
174
175 deviceTable = new TableView<OFATopologyInterface>();
176 data = FXCollections.observableArrayList(new OFATopologyInterface(interFaceNumber, attributeText, valueText));
177 deviceTable.setMinWidth(330);
178 deviceTable.setMaxHeight(200);
179 number = new TableColumn(label.topoInterfaces);
180 number.setCellValueFactory(new PropertyValueFactory<OFATopologyInterface, Label>("interFaceNumber"));
181 number.setMinWidth(90);
182 number.setResizable(false);
183 device = new TableColumn(label.topoAttribute);
184 device.setCellValueFactory(new PropertyValueFactory<OFATopologyInterface, TextField>("deviceName"));
185 device.setMaxWidth(119);
186 device.setResizable(false);
187 type = new TableColumn(label.topoValues);
188 type.setCellValueFactory(new PropertyValueFactory<OFATopologyInterface, TextField>("deviceType"));
189 type.setMaxWidth(119);
190 type.setResizable(false);
191 deviceTable.setItems(data);
192 deviceTable.getColumns().addAll(number, device, type);
193 interfaceGridPane.add(deviceTable, 0, 1);
194 interfaceTab.setContent(interfaceGridPane);
195 HBox interFaceButton = new HBox(5);
196 interFaceButton.setPadding(new Insets(0, 0, 0, 2));
197 attributeList.add(attributeText);
198 valueList.add(valueText);
199 hashProperty.put(attributeText, valueText);
200
201 interfaceGridPane.add(interFaceButton, 0, 2);
202 Pane root = new Pane();
203 root.getChildren().addAll(propertyButton, toplogyTabPane);
204 primaryStage.setScene(new Scene(root, 350, 300));
205 primaryStage.show();
206 }
207
208 public void addInterFace() {
209 int intNumber = ++count;
210 Label interFaceNumber = new Label("" + intNumber);
211 attributeText = new TextField();
212 attributeList.add(attributeText);
213 valueText = new TextField();
214 attributeText.setMaxWidth(120);
215 valueText.setMinWidth(120);
216 hashProperty.put(attributeText, valueText);
217 for (int i = 0; i < deviceTable.getItems().size(); i++) {
218 deviceTable.getSelectionModel().select(deviceTable.getItems().size() - 1);
219 }
220
221 deviceTable.getSelectionModel().select(deviceTable.getItems().size());
222 valueText.setOnKeyPressed(new EventHandler<KeyEvent>() {
223 @Override
224 public void handle(KeyEvent keyEvent) {
225 if (keyEvent.getCode() == KeyCode.ENTER) {
226 deviceTable.getSelectionModel().select(deviceTable.getItems().size() - 1);
227 if (deviceTable.getSelectionModel().isSelected(deviceTable.getItems().size() - 1)) {
228 if (!deviceTable.getSelectionModel().getSelectedItem().getDeviceName().getText().equals("") && !deviceTable.getSelectionModel().getSelectedItem().getDeviceType().getText().equals("")) {
229 addInterFace();
230 }
231 }
232
233 }
234 }
235 });
236 valueList.add(valueText);
237 data.add(new OFATopologyInterface(interFaceNumber, attributeText, valueText));
238 number.setCellValueFactory(new PropertyValueFactory<OFATopologyInterface, Label>("interFaceNumber"));
239 number.setMinWidth(90);
240 number.setResizable(false);
241 device.setCellValueFactory(new PropertyValueFactory<OFATopologyInterface, TextField>("deviceName"));
242 device.setMaxWidth(120);
243 device.setResizable(false);
244 type.setCellValueFactory(new PropertyValueFactory<OFATopologyInterface, TextField>("deviceType"));
245 type.setMaxWidth(120);
246 type.setResizable(false);
247 deviceTable.setItems(data);
248 deviceTable.setEditable(true);
249 }
250
251 public String getHostName() {
252 return getHostName;
253 }
254
255 public String getUserName() {
256 return getUserName;
257 }
258
259 public String getPassword() {
260 return getPassword;
261 }
262
263 public String getTransportProtocool() {
264 return getTranportProtocol;
265 }
266
267 public String getPort() {
268 return getPort;
269 }
270
271 public ArrayList getAtttribute() {
272 return getAttribute;
273 }
274
275 public ArrayList getValue() {
276 return getValue;
277 }
278}