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.File; |
| 8 | import java.io.FileNotFoundException; |
| 9 | import java.io.IOException; |
| 10 | import java.util.ArrayList; |
| 11 | import java.util.Collection; |
| 12 | import java.util.Collections; |
| 13 | import java.util.HashMap; |
| 14 | import java.util.Iterator; |
| 15 | import java.util.Locale; |
| 16 | import java.util.Map; |
| 17 | import java.util.Set; |
| 18 | import java.util.logging.Level; |
| 19 | import java.util.logging.Logger; |
| 20 | import java.util.regex.Matcher; |
| 21 | import java.util.regex.Pattern; |
| 22 | import javafx.collections.FXCollections; |
| 23 | import javafx.collections.ObservableList; |
| 24 | import javafx.event.ActionEvent; |
| 25 | import javafx.event.EventHandler; |
| 26 | import javafx.geometry.Side; |
| 27 | import javafx.scene.Group; |
| 28 | import javafx.scene.control.ContextMenu; |
| 29 | import javafx.scene.control.Label; |
| 30 | import javafx.scene.control.ListView; |
| 31 | import javafx.scene.control.MenuItem; |
| 32 | import javafx.scene.control.TextField; |
| 33 | import javafx.scene.input.KeyCode; |
| 34 | import javafx.scene.input.KeyEvent; |
| 35 | import javafx.scene.layout.GridPane; |
| 36 | import javafx.scene.layout.StackPane; |
| 37 | |
| 38 | /** |
| 39 | * |
| 40 | * @author Raghav kashyap (raghavkashyap@paxterrasolutions.com) |
| 41 | |
| 42 | * TestON is free software: you can redistribute it and/or modify |
| 43 | * it under the terms of the GNU General Public License as published by |
| 44 | * the Free Software Foundation, either version 2 of the License, or |
| 45 | * (at your option) any later version. |
| 46 | |
| 47 | * TestON is distributed in the hope that it will be useful, |
| 48 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 49 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 50 | * GNU General Public License for more details. |
| 51 | |
| 52 | * You should have received a copy of the GNU General Public License |
| 53 | * along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 54 | |
| 55 | */ |
| 56 | public class OFAContentHelp { |
| 57 | |
| 58 | ContextMenu assertContext; |
| 59 | ArrayList<MenuItem> assertNameList; |
| 60 | CodeEditor Content; |
| 61 | TAI_OFA OFAReference; |
| 62 | String ospkCommand; |
| 63 | boolean keyPressed = false; |
| 64 | ArrayList<String> checkBuffer; |
| 65 | ContextMenu contextMenu, driverFunctionContextMenu; |
| 66 | ArrayList<String> myDevices; |
| 67 | ArrayList<MenuItem> myMenuItems; |
| 68 | ArrayList<String> driverFunctionName; |
| 69 | ArrayList<MenuItem> functionMenuItem; |
| 70 | OFAParamDeviceName paramFile; |
| 71 | String deviceTypePath; |
| 72 | ContextMenu commandNameContextMenu, withContextMenu, runDriverContextMenu; |
| 73 | ArrayList<MenuItem> bdtFunction; |
| 74 | String selectedDeviceName; |
| 75 | String selectedFunctionName; |
| 76 | TextField paraMeterListText; |
| 77 | ArrayList<String> parameterArrayList = new ArrayList<String>(); |
| 78 | ArrayList<TextField> parameterTextFieldList = new ArrayList<TextField>(); |
| 79 | String matchedCase; |
| 80 | ArrayList<Label> parameterLabel = new ArrayList<Label>(); |
| 81 | OFAFileOperations fileOperation = new OFAFileOperations(); |
| 82 | ObservableList<String> data; |
| 83 | Group popupRoot; |
| 84 | ListView<String> seleniumFunctionListView, cliFunctionListView; |
| 85 | String baseDeviceDriver, cliFunctionStr; |
| 86 | ArrayList<String> cliFunctionList = new ArrayList<String>(); |
| 87 | HashMap<String, String> cliFunctionWithArgumentMap = new HashMap<String, String>(); |
| 88 | String selectedCLiFunction; |
| 89 | String selectedSeleniumFunction; |
| 90 | TAILocale label = new TAILocale(new Locale("en", "EN")); |
| 91 | String OFAHarnessPath = label.hierarchyTestON; |
| 92 | String bdrPath; |
| 93 | String selectedDeviceType; |
| 94 | |
| 95 | public OFAContentHelp() { |
| 96 | } |
| 97 | |
| 98 | public OFAContentHelp(CodeEditor editor, TAI_OFA reference) { |
| 99 | this.Content = editor; |
| 100 | OFAReference = reference; |
| 101 | } |
| 102 | |
| 103 | public void assertContextMenu() { |
| 104 | assertContext = new ContextMenu(); |
| 105 | MenuItem equal = new MenuItem("EQUALS"); |
| 106 | MenuItem match = new MenuItem("MATCHES"); |
| 107 | MenuItem greater = new MenuItem("GREATER"); |
| 108 | MenuItem lesser = new MenuItem("LESSER"); |
| 109 | assertNameList = new ArrayList<MenuItem>(); |
| 110 | assertNameList.add(equal); |
| 111 | assertNameList.add(match); |
| 112 | assertNameList.add(greater); |
| 113 | assertNameList.add(lesser); |
| 114 | assertContext.getItems().addAll(equal, match, greater, lesser); |
| 115 | } |
| 116 | |
| 117 | public void ospkHelp() { |
| 118 | |
| 119 | Content.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() { |
| 120 | @Override |
| 121 | public void handle(KeyEvent keyEvent) { |
| 122 | if (keyEvent.getCode() == KeyCode.SPACE) { |
| 123 | ArrayList<Integer> existingCaseNumber = new ArrayList<Integer>(); |
| 124 | existingCaseNumber.add(0); |
| 125 | String[] content = Content.getCodeAndSnapshot().split("\n"); |
| 126 | for (int i = 0; i < content.length; i++) { |
| 127 | Pattern pattern = Pattern.compile("CASE\\s+(\\d+)\\s*"); |
| 128 | Matcher matchCase = pattern.matcher(content[i]); |
| 129 | |
| 130 | while (matchCase.find()) { |
| 131 | try { |
| 132 | int number = Integer.parseInt(matchCase.group(1)); |
| 133 | existingCaseNumber.add(number); |
| 134 | } catch (Exception e) { |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | int max = Collections.max(existingCaseNumber); |
| 140 | max = max + 1; |
| 141 | String caseNumbers = String.valueOf(max); |
| 142 | Content.setLine(Integer.parseInt(Content.getCurrentLineNumber()), Content.getCurrentLine().replace("CASE", "CASE" + " " + caseNumbers)); |
| 143 | } |
| 144 | |
| 145 | Pattern namePattern = Pattern.compile("\\s*NAME\\s+(.*)"); |
| 146 | Pattern descPattern = Pattern.compile("DESC\\s+(.*)"); |
| 147 | Pattern stepPattern = Pattern.compile("STEP\\s+(.*)"); |
| 148 | Pattern onPattern = Pattern.compile("ON\\s+(.*)"); |
| 149 | Pattern cmdPattern = Pattern.compile("ON\\s+(\\w+\\s+(.*))"); |
| 150 | Pattern runPattern = Pattern.compile("" + ospkCommand + "\\s+(.*)"); |
| 151 | Pattern assertPattern = Pattern.compile("ASSERT\\s+(.*)"); |
| 152 | Pattern usingPattern = Pattern.compile("(.*)\\s+USING\\s+"); |
| 153 | String[] OFAEditorLine = Content.getCodeAndSnapshot().split("\n"); |
| 154 | |
| 155 | final Matcher onMatch = onPattern.matcher(Content.getCurrentLine()); |
| 156 | final Matcher cmdMatch = cmdPattern.matcher(Content.getCurrentLine()); |
| 157 | final Matcher runMatch = runPattern.matcher(Content.getCurrentLine()); |
| 158 | final Matcher asertMatch = assertPattern.matcher(Content.getCurrentLine()); |
| 159 | final Matcher usingMatch = usingPattern.matcher(Content.getCurrentLine()); |
| 160 | Matcher nameMatch = namePattern.matcher(Content.getCurrentLine()); |
| 161 | Matcher descMatch = descPattern.matcher(Content.getCurrentLine()); |
| 162 | Matcher stepMatch = stepPattern.matcher(Content.getCurrentLine()); |
| 163 | while (nameMatch.find()) { |
| 164 | if (nameMatch.group(1).isEmpty()) { |
| 165 | if (keyEvent.getCode() == KeyCode.SPACE) { |
| 166 | Content.setLine(Integer.parseInt(Content.getCurrentLineNumber()), Content.getCurrentLine().replace("NAME", "NAME" + " " + "\"\"")); |
| 167 | } |
| 168 | |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | while (descMatch.find()) { |
| 173 | if (descMatch.group(1).isEmpty()) { |
| 174 | if (keyEvent.getCode() == KeyCode.SPACE) { |
| 175 | Content.setLine(Integer.parseInt(Content.getCurrentLineNumber()), Content.getCurrentLine().replace("DESC", "DESC" + " " + "\"\"")); |
| 176 | } |
| 177 | |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | while (stepMatch.find()) { |
| 182 | if (stepMatch.group(1).isEmpty()) { |
| 183 | if (keyEvent.getCode() == KeyCode.SPACE) { |
| 184 | Content.setLine(Integer.parseInt(Content.getCurrentLineNumber()), Content.getCurrentLine().replace("STEP", "STEP" + " " + "\"\"")); |
| 185 | } |
| 186 | |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | |
| 191 | while (onMatch.find()) { |
| 192 | if (onMatch.group(1).isEmpty()) { |
| 193 | if (keyEvent.getCode() == KeyCode.getKeyCode("Ctrl")) { |
| 194 | keyPressed = true; |
| 195 | } |
| 196 | |
| 197 | if (keyPressed == true) { |
| 198 | if (keyEvent.getCode() == KeyCode.SPACE) { |
| 199 | keyPressed = false; |
| 200 | onMatch.group(); |
| 201 | onDeviceContextMenu(); |
| 202 | contextMenu.show(OFAReference.editorTabPane, Side.TOP, Content.cursorPosfromLeft(), Content.cursorPosfromTop() + 65); |
| 203 | for (final MenuItem myMenuItem : myMenuItems) { |
| 204 | myMenuItem.setOnAction(new EventHandler<ActionEvent>() { |
| 205 | @Override |
| 206 | public void handle(ActionEvent arg0) { |
| 207 | HashMap<String, String> deviceNameAndType = paramFile.getdeviceNameAndType(); |
| 208 | Iterator paramIterator = deviceNameAndType.entrySet().iterator(); |
| 209 | while (paramIterator.hasNext()) { |
| 210 | Map.Entry mEntry = (Map.Entry) paramIterator.next(); |
| 211 | if (myMenuItem.getText().equals(mEntry.getKey())) { |
| 212 | selectedDeviceType = mEntry.getValue().toString(); |
| 213 | selectedDeviceType = selectedDeviceType.replaceAll("\\s+", ""); |
| 214 | String driverTypePath = OFAHarnessPath + "/drivers/common/"; |
| 215 | File aFile = new File(driverTypePath); |
| 216 | fileOperation.Process(aFile); |
| 217 | for (String path : fileOperation.filePath) { |
| 218 | String[] splitPath = path.split("\\/"); |
| 219 | String[] fileName = splitPath[splitPath.length - 1].split("\\."); |
| 220 | for (int p = 0; p < fileName.length; p++) { |
| 221 | if ((selectedDeviceType).equals(fileName[p])) { |
| 222 | deviceTypePath = path; |
| 223 | bdrPath = deviceTypePath.replaceAll("py", "ospk"); |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | } |
| 228 | } |
| 229 | selectedDeviceName = myMenuItem.getText(); |
| 230 | Content.setLine(Integer.parseInt(Content.getCurrentLineNumber()), Content.getCurrentLine().replace("ON", "ON" + " " + myMenuItem.getText())); |
| 231 | } |
| 232 | }); |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | } |
| 238 | } |
| 239 | while (cmdMatch.find()) { |
| 240 | if (cmdMatch.group(2).isEmpty()) { |
| 241 | if (keyEvent.getCode() == KeyCode.getKeyCode("Ctrl")) { |
| 242 | keyPressed = true; |
| 243 | } |
| 244 | |
| 245 | if (keyPressed == true) { |
| 246 | if (keyEvent.getCode() == KeyCode.SPACE) { |
| 247 | runContextMenu(); |
| 248 | commandNameContextMenu.show(OFAReference.editorTabPane, Side.TOP, Content.cursorPosfromLeft(), Content.cursorPosfromTop() + 115); |
| 249 | for (final MenuItem bdtCmd : bdtFunction) { |
| 250 | bdtCmd.setOnAction(new EventHandler<ActionEvent>() { |
| 251 | @Override |
| 252 | public void handle(ActionEvent t) { |
| 253 | ospkCommand = bdtCmd.getText(); |
| 254 | Content.setLine(Integer.parseInt(Content.getCurrentLineNumber()), Content.getCurrentLine().replace(selectedDeviceName, selectedDeviceName + " " + bdtCmd.getText())); |
| 255 | } |
| 256 | }); |
| 257 | } |
| 258 | } |
| 259 | } |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | while (runMatch.find()) { |
| 264 | |
| 265 | if (runMatch.group(1).isEmpty()) { |
| 266 | if (keyEvent.getCode() == KeyCode.getKeyCode("Ctrl")) { |
| 267 | keyPressed = true; |
| 268 | } |
| 269 | if (keyPressed == true) { |
| 270 | if (keyEvent.getCode() == KeyCode.SPACE) { |
| 271 | keyPressed = false; |
| 272 | |
| 273 | onDriverContextMenu(); |
| 274 | driverFunctionContextMenu.show(OFAReference.editorTabPane, Side.TOP, Content.cursorPosfromLeft(), Content.cursorPosfromTop() + 65); |
| 275 | |
| 276 | Group popupRoot = (Group) driverFunctionContextMenu.getScene().getRoot(); |
| 277 | final ListView<String> driverFunctionListView = new ListView<String>(); |
| 278 | data = FXCollections.observableArrayList(); |
| 279 | for (String function : driverFunctionName) { |
| 280 | data.add(function); |
| 281 | } |
| 282 | driverFunctionListView.setItems(data); |
| 283 | driverFunctionListView.setMaxHeight(100); |
| 284 | driverFunctionListView.setMaxWidth(150); |
| 285 | driverFunctionListView.getSelectionModel().selectFirst(); |
| 286 | |
| 287 | driverFunctionListView.addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() { |
| 288 | @Override |
| 289 | public void handle(KeyEvent arg0) { |
| 290 | if (arg0.getCode() == KeyCode.ENTER || arg0.getCode() == KeyCode.SPACE) { |
| 291 | selectedFunctionName = driverFunctionListView.getSelectionModel().getSelectedItem().toString(); |
| 292 | Content.setLine(Integer.parseInt(Content.getCurrentLineNumber()), Content.getCurrentLine().replace("RUN", "RUN" + " " + selectedFunctionName)); |
| 293 | driverFunctionContextMenu.hide(); |
| 294 | } |
| 295 | } |
| 296 | }); |
| 297 | popupRoot.getChildren().add(driverFunctionListView); |
| 298 | driverFunctionListView.requestFocus(); |
| 299 | } |
| 300 | } |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | while (asertMatch.find()) { |
| 305 | if (asertMatch.group(1).isEmpty()) { |
| 306 | if (keyEvent.getCode() == KeyCode.getKeyCode("Ctrl")) { |
| 307 | keyPressed = true; |
| 308 | } |
| 309 | |
| 310 | if (keyPressed == true) { |
| 311 | if (keyEvent.getCode() == KeyCode.SPACE) { |
| 312 | OFAContentHelp contentHelp = new OFAContentHelp(); |
| 313 | contentHelp.assertContextMenu(); |
| 314 | contentHelp.assertContext.show(OFAReference.editorTabPane, Side.TOP, Content.cursorPosfromLeft(), Content.cursorPosfromTop() + 65); |
| 315 | for (final MenuItem assertCommand : contentHelp.assertNameList) { |
| 316 | assertCommand.setOnAction(new EventHandler<ActionEvent>() { |
| 317 | @Override |
| 318 | public void handle(ActionEvent t) { |
| 319 | Content.setLine(Integer.parseInt(Content.getCurrentLineNumber()), Content.getCurrentLine().replace("ASSERT", "ASSERT " + assertCommand.getText())); |
| 320 | } |
| 321 | }); |
| 322 | } |
| 323 | } |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | } |
| 328 | |
| 329 | while (usingMatch.find()) { |
| 330 | if (!usingMatch.group(1).isEmpty()) { |
| 331 | if (keyEvent.getCode() == KeyCode.CONTROL) { |
| 332 | keyPressed = true; |
| 333 | } |
| 334 | |
| 335 | if (keyPressed == true) { |
| 336 | if (keyEvent.getCode() == KeyCode.SPACE) { |
| 337 | OFAParamDeviceName paramDeice = new OFAParamDeviceName(); |
| 338 | if (selectedDeviceType.equals("poxclidriver")) { |
| 339 | String baseCliDevice = bdrPath.replace(bdrPath, label.hierarchyTestON + "/drivers/common/cli/emulator/poxclidriver.py"); |
| 340 | paramDeice.driverFunctionName(baseCliDevice); |
| 341 | for (String functionName : paramDeice.driverFunctionName) { |
| 342 | driverFunctionName.add(functionName); |
| 343 | } |
| 344 | } else if (selectedDeviceType.equals("mininetclidriver")) { |
| 345 | String baseCliDevice = bdrPath.replace(bdrPath, label.hierarchyTestON + "/drivers/common/cli/emulator/mininetclidriver.py"); |
| 346 | paramDeice.driverFunctionName(baseCliDevice); |
| 347 | for (String functionName : paramDeice.driverFunctionName) { |
| 348 | driverFunctionName.add(functionName); |
| 349 | } |
| 350 | } else if (selectedDeviceType.equals("hpswitchclidriver")) { |
| 351 | String baseCliDevice = bdrPath.replace(bdrPath, label.hierarchyTestON + "/drivers/common/cli/remotetestbed/hpswitchclidriver.py"); |
| 352 | paramDeice.driverFunctionName(baseCliDevice); |
| 353 | for (String functionName : paramDeice.driverFunctionName) { |
| 354 | driverFunctionName.add(functionName); |
| 355 | } |
| 356 | } |
| 357 | if (selectedDeviceType.equals("flowvisorclidriver")) { |
| 358 | String baseCliDevice = bdrPath.replace(bdrPath, label.hierarchyTestON + "/drivers/common/cli/remotesys/flowvisorclidriver.py"); |
| 359 | paramDeice.driverFunctionName(baseCliDevice); |
| 360 | for (String functionName : paramDeice.driverFunctionName) { |
| 361 | driverFunctionName.add(functionName); |
| 362 | } |
| 363 | } |
| 364 | if (selectedDeviceType.equals("floodlightclidriver")) { |
| 365 | String baseCliDevice = bdrPath.replace(bdrPath, label.hierarchyTestON + "/drivers/common/cli/remotesys/floodlightclidriver.py"); |
| 366 | paramDeice.driverFunctionName(baseCliDevice); |
| 367 | for (String functionName : paramDeice.driverFunctionName) { |
| 368 | driverFunctionName.add(functionName); |
| 369 | } |
| 370 | } |
| 371 | if (selectedDeviceType.equals("remotepoxdriver")) { |
| 372 | String baseCliDevice = bdrPath.replace(bdrPath, label.hierarchyTestON + "/drivers/common/cli/remotesys/remotepoxdriver.py"); |
| 373 | paramDeice.driverFunctionName(baseCliDevice); |
| 374 | for (String functionName : paramDeice.driverFunctionName) { |
| 375 | driverFunctionName.add(functionName); |
| 376 | } |
| 377 | } |
| 378 | if (selectedDeviceType.equals("remotevmdriver")) { |
| 379 | String baseCliDevice = bdrPath.replace(bdrPath, label.hierarchyTestON + "/drivers/common/cli/remotesys/remotevmdriver.py"); |
| 380 | paramDeice.driverFunctionName(baseCliDevice); |
| 381 | for (String functionName : paramDeice.driverFunctionName) { |
| 382 | driverFunctionName.add(functionName); |
| 383 | } |
| 384 | } |
| 385 | if (selectedDeviceType.equals("dpctlclidriver")) { |
| 386 | String baseCliDevice = bdrPath.replace(bdrPath, label.hierarchyTestON + "/drivers/common/cli/tool/dpctlclidriver.py"); |
| 387 | paramDeice.driverFunctionName(baseCliDevice); |
| 388 | for (String functionName : paramDeice.driverFunctionName) { |
| 389 | driverFunctionName.add(functionName); |
| 390 | } |
| 391 | } |
| 392 | if (selectedDeviceType.equals("fvtapidriver")) { |
| 393 | String baseCliDevice = bdrPath.replace(bdrPath, label.hierarchyTestON + "/drivers/common/api/fvtapidriver.py"); |
| 394 | paramDeice.driverFunctionName(baseCliDevice); |
| 395 | for (String functionName : paramDeice.driverFunctionName) { |
| 396 | driverFunctionName.add(functionName); |
| 397 | } |
| 398 | } |
| 399 | HashMap<String, String> functionAndParameter = paramDeice.functionWithParameter; |
| 400 | Set set = functionAndParameter.entrySet(); |
| 401 | // Get an iterator |
| 402 | Iterator functionAndParameterIterator = set.iterator(); |
| 403 | // Display elements |
| 404 | final GridPane paramPanel = new GridPane(); |
| 405 | paramPanel.setStyle("-fx-background-color: DAE6F3;"); |
| 406 | String caseParameter = ""; |
| 407 | parameterLabel.clear(); |
| 408 | parameterTextFieldList.clear(); |
| 409 | while (functionAndParameterIterator.hasNext()) { |
| 410 | Map.Entry functionInfo = (Map.Entry) functionAndParameterIterator.next(); |
| 411 | if (selectedFunctionName.equals(functionInfo.getKey().toString())) { |
| 412 | String[] splitParameter = functionInfo.getValue().toString().split("\\,"); |
| 413 | if (splitParameter.length > 0) { |
| 414 | for (int j = 0; j < splitParameter.length; j++) { |
| 415 | Label parameterList = new Label(); |
| 416 | parameterLabel.add(parameterList); |
| 417 | paraMeterListText = new TextField(); |
| 418 | parameterList.setText(splitParameter[j]); |
| 419 | paramPanel.add(parameterList, 0, j); |
| 420 | paramPanel.add(paraMeterListText, 1, j); |
| 421 | parameterTextFieldList.add(paraMeterListText); |
| 422 | caseParameter += splitParameter[j].toLowerCase() + "AS " + "CASE" + "[" + splitParameter[j].toLowerCase() + "]" + ","; |
| 423 | } |
| 424 | } |
| 425 | } |
| 426 | } |
| 427 | withContextMenu(); |
| 428 | withContextMenu.show(OFAReference.editorTabPane, Side.TOP, Content.cursorPosfromLeft(), Content.cursorPosfromTop() + 65); |
| 429 | Group popupRoot = (Group) withContextMenu.getScene().getRoot(); |
| 430 | Group popupCSSBridge = (Group) popupRoot.getChildren().get(0); |
| 431 | StackPane popupContent = (StackPane) popupCSSBridge.getChildren().get(0); |
| 432 | popupRoot.getChildren().add(paramPanel); |
| 433 | if (!caseParameter.equals("")) { |
| 434 | try { |
| 435 | caseParameter = caseParameter.substring(0, caseParameter.length() - 1); |
| 436 | } catch (ArrayIndexOutOfBoundsException e) { |
| 437 | } |
| 438 | } |
| 439 | popupContent.setMaxHeight(OFAReference.editorTabPane.getHeight() - 400); |
| 440 | Content.setLine(Integer.parseInt(Content.getCurrentLineNumber()), Content.getCurrentLine().replace("USING", "USING" + " " + caseParameter)); |
| 441 | for (int k = Integer.parseInt(Content.getCurrentLineNumber()); k > 0; k--) { |
| 442 | Pattern firstUpperCasePattern = Pattern.compile("CASE\\s+(\\d)"); |
| 443 | Matcher firstUpperCaseMatch = firstUpperCasePattern.matcher(Content.getCurrentLine(k)); |
| 444 | if (firstUpperCaseMatch.find()) { |
| 445 | matchedCase = firstUpperCaseMatch.group(); |
| 446 | break; |
| 447 | } |
| 448 | } |
| 449 | try { |
| 450 | paraMeterListText.setOnKeyPressed(new EventHandler<KeyEvent>() { |
| 451 | @Override |
| 452 | public void handle(KeyEvent keyEvent) { |
| 453 | if (keyEvent.getCode() == KeyCode.ENTER) { |
| 454 | String paramCaseContent = ""; |
| 455 | String matchCaseWithoutSpace = matchedCase.replaceAll("\\s+", ""); |
| 456 | String currentTabPath = OFAReference.editorTabPane.getSelectionModel().getSelectedItem().getId(); |
| 457 | String paramFile = currentTabPath.replace(fileOperation.getExtension(currentTabPath), ".params"); |
| 458 | Pattern matchCasePattern = Pattern.compile("^\\s*\\<" + matchCaseWithoutSpace + "\\>"); |
| 459 | String fileContent[] = fileOperation.getContents(new File(paramFile)).split("\n"); |
| 460 | String myCase = ""; |
| 461 | Boolean caseFlag = false; |
| 462 | int k; |
| 463 | for (k = 0; k < fileContent.length; k++) { |
| 464 | Matcher caseMatch = matchCasePattern.matcher(fileContent[k]); |
| 465 | if (caseMatch.find()) { |
| 466 | myCase = caseMatch.group(); |
| 467 | caseFlag = true; |
| 468 | break; |
| 469 | } |
| 470 | } |
| 471 | if (caseFlag == true) { |
| 472 | String remainingConetent = ""; |
| 473 | int caseVarible = k; |
| 474 | k++; |
| 475 | for (; k < fileContent.length; k++) { |
| 476 | remainingConetent += "\n" + fileContent[k]; |
| 477 | } |
| 478 | String allContent = ""; |
| 479 | allContent += fileContent[0]; |
| 480 | for (int p = 1; p < caseVarible; p++) { |
| 481 | allContent += "\n" + fileContent[p]; |
| 482 | } |
| 483 | allContent += "\n\t<" + matchCaseWithoutSpace + ">"; |
| 484 | |
| 485 | for (int i = 0; i < parameterTextFieldList.size(); i++) { |
| 486 | String parameterLabels = parameterLabel.get(i).getText().replaceAll("\"", ""); |
| 487 | paramCaseContent += "\n\t\t<" + parameterLabels.toLowerCase() + ">" + parameterTextFieldList.get(i).getText() + "</" + parameterLabels.toLowerCase() + ">"; |
| 488 | } |
| 489 | |
| 490 | allContent += paramCaseContent; |
| 491 | allContent += remainingConetent; |
| 492 | String paramFilePath = OFAReference.editorTabPane.getSelectionModel().getSelectedItem().getId().replace(fileOperation.getExtension(OFAReference.editorTabPane.getSelectionModel().getSelectedItem().getId()), ".params"); |
| 493 | String paramFileContent = fileOperation.getContents(new File(paramFilePath)); |
| 494 | try { |
| 495 | fileOperation.setContents(new File(paramFilePath), allContent); |
| 496 | } catch (FileNotFoundException ex) { |
| 497 | Logger.getLogger(OFAContentHelp.class.getName()).log(Level.SEVERE, null, ex); |
| 498 | } catch (IOException ex) { |
| 499 | Logger.getLogger(OFAContentHelp.class.getName()).log(Level.SEVERE, null, ex); |
| 500 | } |
| 501 | withContextMenu.hide(); |
| 502 | paramPanel.setVisible(false); |
| 503 | } else { |
| 504 | paramCaseContent += "<" + matchCaseWithoutSpace + ">"; |
| 505 | for (int i = 0; i < parameterTextFieldList.size(); i++) { |
| 506 | paramCaseContent += "\n\t\t<" + parameterLabel.get(i).getText().toLowerCase() + ">" + parameterTextFieldList.get(i).getText() + "</" + parameterLabel.get(i).getText().toLowerCase() + ">"; |
| 507 | } |
| 508 | |
| 509 | paramCaseContent += "\n\t" + "</" + matchCaseWithoutSpace + ">"; |
| 510 | String paramFilePath = OFAReference.editorTabPane.getSelectionModel().getSelectedItem().getId().replace(fileOperation.getExtension(OFAReference.editorTabPane.getSelectionModel().getSelectedItem().getId()), ".params"); |
| 511 | String paramFileContent = fileOperation.getContents(new File(paramFilePath)); |
| 512 | String removeTestParam = paramFileContent.replace("</TEST_PARAMS>", " "); |
| 513 | removeTestParam += "\t" + paramCaseContent + "\n\n" + "</TEST_PARAMS>"; |
| 514 | try { |
| 515 | fileOperation.setContents(new File(paramFilePath), removeTestParam); |
| 516 | } catch (FileNotFoundException ex) { |
| 517 | Logger.getLogger(OFAContentHelp.class.getName()).log(Level.SEVERE, null, ex); |
| 518 | } catch (IOException ex) { |
| 519 | Logger.getLogger(OFAContentHelp.class.getName()).log(Level.SEVERE, null, ex); |
| 520 | } |
| 521 | withContextMenu.hide(); |
| 522 | paramPanel.setVisible(false); |
| 523 | } |
| 524 | } |
| 525 | } |
| 526 | }); |
| 527 | } catch (Exception e) { |
| 528 | } |
| 529 | |
| 530 | } |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | } |
| 535 | |
| 536 | checkBuffer = new ArrayList<String>(); |
| 537 | |
| 538 | if (keyEvent.getCode() == KeyCode.ENTER) { |
| 539 | String bufferedString = ""; |
| 540 | for (String s : checkBuffer) { |
| 541 | bufferedString += s; |
| 542 | } |
| 543 | Pattern pattern = Pattern.compile("CASE\\s+(\\d+)"); |
| 544 | Matcher match = pattern.matcher(bufferedString); |
| 545 | while (match.find()) { |
| 546 | Content.setCode(Content.getCodeAndSnapshot().replaceAll(bufferedString, bufferedString + "\n\n" + "END CASE")); |
| 547 | } |
| 548 | checkBuffer.clear(); |
| 549 | } |
| 550 | |
| 551 | } |
| 552 | }); |
| 553 | |
| 554 | Content.setOnKeyPressed(new EventHandler<KeyEvent>() { |
| 555 | @Override |
| 556 | public void handle(KeyEvent arg0) { |
| 557 | String text = arg0.getText(); |
| 558 | if (arg0.getCode() == KeyCode.ENTER) { |
| 559 | } else if (arg0.getCode() == KeyCode.BACK_SPACE) { |
| 560 | } else { |
| 561 | checkBuffer.add(text); |
| 562 | } |
| 563 | } |
| 564 | }); |
| 565 | } |
| 566 | |
| 567 | public void onDeviceContextMenu() { |
| 568 | contextMenu = new ContextMenu(); |
| 569 | myDevices = new ArrayList<String>(); |
| 570 | ArrayList<String> paramDeviceType = new ArrayList<String>(); |
| 571 | myMenuItems = new ArrayList<MenuItem>(); |
| 572 | |
| 573 | String selectedTabPath = OFAReference.editorTabPane.getSelectionModel().getSelectedItem().getId(); |
| 574 | String[] splitSelectedPath = selectedTabPath.split("\\/"); |
| 575 | String[] ospkFileName = splitSelectedPath[splitSelectedPath.length - 1].toString().split("\\."); |
| 576 | String paramFileName = ospkFileName[0] + ".topo"; |
| 577 | String paramFilePath = selectedTabPath.replace(splitSelectedPath[splitSelectedPath.length - 1].toString(), paramFileName); |
| 578 | paramFile = new OFAParamDeviceName(paramFilePath, ""); |
| 579 | paramFile.parseParamFile(); |
| 580 | |
| 581 | for (String deviceName : paramFile.getParamDeviceName()) { |
| 582 | myDevices.add(deviceName); |
| 583 | } |
| 584 | |
| 585 | for (String myDevice : myDevices) { |
| 586 | final MenuItem myMenuItem = new MenuItem(myDevice); |
| 587 | myMenuItem.setOnAction(new EventHandler<ActionEvent>() { |
| 588 | @Override |
| 589 | public void handle(ActionEvent arg0) { |
| 590 | } |
| 591 | }); |
| 592 | myMenuItems.add(myMenuItem); |
| 593 | } |
| 594 | |
| 595 | for (MenuItem myMenuItem : myMenuItems) { |
| 596 | contextMenu.getItems().addAll(myMenuItem); |
| 597 | |
| 598 | } |
| 599 | |
| 600 | OFAReference.editorTabPane.setContextMenu(contextMenu); |
| 601 | } |
| 602 | |
| 603 | public void onDriverContextMenu() { |
| 604 | driverFunctionContextMenu = new ContextMenu(); |
| 605 | driverFunctionName = new ArrayList<String>(); |
| 606 | driverFunctionName.clear(); |
| 607 | OFAParamDeviceName driverFile = new OFAParamDeviceName(); |
| 608 | |
| 609 | if (selectedDeviceType.equals("poxclidriver")) { |
| 610 | String baseCliDevice = bdrPath.replace(bdrPath, label.hierarchyTestON + "/drivers/common/cli/emulator/poxclidriver.py"); |
| 611 | driverFile.driverFunctionName(baseCliDevice); |
| 612 | for (String functionName : driverFile.driverFunctionName) { |
| 613 | driverFunctionName.add(functionName); |
| 614 | } |
| 615 | } else if (selectedDeviceType.equals("mininetclidriver")) { |
| 616 | String baseCliDevice = bdrPath.replace(bdrPath, label.hierarchyTestON + "/drivers/common/cli/emulator/mininetclidriver.py"); |
| 617 | driverFile.driverFunctionName(baseCliDevice); |
| 618 | for (String functionName : driverFile.driverFunctionName) { |
| 619 | driverFunctionName.add(functionName); |
| 620 | } |
| 621 | } |
| 622 | if (selectedDeviceType.equals("hpswitchdriver")) { |
| 623 | String baseCliDevice = bdrPath.replace(bdrPath, label.hierarchyTestON + "/drivers/common/cli/remotesys/hpswitchdriver.py"); |
| 624 | driverFile.driverFunctionName(baseCliDevice); |
| 625 | for (String functionName : driverFile.driverFunctionName) { |
| 626 | driverFunctionName.add(functionName); |
| 627 | } |
| 628 | } |
| 629 | if (selectedDeviceType.equals("dpctlclidriver")) { |
| 630 | String baseCliDevice = bdrPath.replace(bdrPath, label.hierarchyTestON + "/drivers/common/cli/tool/dpctlclidriver.py"); |
| 631 | driverFile.driverFunctionName(baseCliDevice); |
| 632 | for (String functionName : driverFile.driverFunctionName) { |
| 633 | driverFunctionName.add(functionName); |
| 634 | } |
| 635 | } |
| 636 | if (selectedDeviceType.equals("fvtapidriver")) { |
| 637 | String baseCliDevice = bdrPath.replace(bdrPath, label.hierarchyTestON + "/drivers/common/api/fvtapidriver.py"); |
| 638 | driverFile.driverFunctionName(baseCliDevice); |
| 639 | for (String functionName : driverFile.driverFunctionName) { |
| 640 | driverFunctionName.add(functionName); |
| 641 | } |
| 642 | } else if (selectedDeviceType.equals("hpswitchclidriver")) { |
| 643 | String baseCliDevice = bdrPath.replace(bdrPath, label.hierarchyTestON + "/drivers/common/cli/remotetestbed/hpswitchclidriver.py"); |
| 644 | driverFile.driverFunctionName(baseCliDevice); |
| 645 | for (String functionName : driverFile.driverFunctionName) { |
| 646 | driverFunctionName.add(functionName); |
| 647 | } |
| 648 | } |
| 649 | if (selectedDeviceType.equals("flowvisorclidriver")) { |
| 650 | String baseCliDevice = bdrPath.replace(bdrPath, label.hierarchyTestON + "/drivers/common/cli/remotetestbed/flowvisorclidriver.py"); |
| 651 | driverFile.driverFunctionName(baseCliDevice); |
| 652 | for (String functionName : driverFile.driverFunctionName) { |
| 653 | driverFunctionName.add(functionName); |
| 654 | } |
| 655 | } |
| 656 | if (selectedDeviceType.equals("floodlightclidriver")) { |
| 657 | String baseCliDevice = bdrPath.replace(bdrPath, label.hierarchyTestON + "/drivers/common/cli/remotetestbed/floodlightclidriver.py"); |
| 658 | driverFile.driverFunctionName(baseCliDevice); |
| 659 | for (String functionName : driverFile.driverFunctionName) { |
| 660 | driverFunctionName.add(functionName); |
| 661 | } |
| 662 | } |
| 663 | if (selectedDeviceType.equals("remotepoxdriver")) { |
| 664 | String baseCliDevice = bdrPath.replace(bdrPath, label.hierarchyTestON + "/drivers/common/cli/remotetestbed/remotepoxdriver.py"); |
| 665 | driverFile.driverFunctionName(baseCliDevice); |
| 666 | for (String functionName : driverFile.driverFunctionName) { |
| 667 | driverFunctionName.add(functionName); |
| 668 | } |
| 669 | } |
| 670 | if (selectedDeviceType.equals("remotevmdriver")) { |
| 671 | String baseCliDevice = bdrPath.replace(bdrPath, label.hierarchyTestON + "/drivers/common/cli/remotetestbed/remotevmdriver.py"); |
| 672 | driverFile.driverFunctionName(baseCliDevice); |
| 673 | for (String functionName : driverFile.driverFunctionName) { |
| 674 | driverFunctionName.add(functionName); |
| 675 | } |
| 676 | } |
| 677 | driverFunctionContextMenu.getItems().add(new MenuItem()); |
| 678 | } |
| 679 | |
| 680 | public void runContextMenu() { |
| 681 | commandNameContextMenu = new ContextMenu(); |
| 682 | MenuItem run = new MenuItem("RUN"); |
| 683 | MenuItem exec = new MenuItem("EXEC"); |
| 684 | MenuItem config = new MenuItem("CONFIG"); |
| 685 | bdtFunction = new ArrayList<MenuItem>(); |
| 686 | bdtFunction.add(run); |
| 687 | bdtFunction.add(exec); |
| 688 | bdtFunction.add(config); |
| 689 | commandNameContextMenu.getItems().addAll(run, exec, config); |
| 690 | } |
| 691 | |
| 692 | public void withContextMenu() { |
| 693 | withContextMenu = new ContextMenu(); |
| 694 | MenuItem item = new MenuItem(); |
| 695 | withContextMenu.getItems().add(item); |
| 696 | item.setDisable(true); |
| 697 | } |
| 698 | |
| 699 | // drivers context menu |
| 700 | public void runDriverContextMenu() { |
| 701 | runDriverContextMenu = new ContextMenu(); |
| 702 | MenuItem runDriverMenuItem = new MenuItem(""); |
| 703 | runDriverContextMenu.getItems().add(runDriverMenuItem); |
| 704 | } |
| 705 | } |