@Override public void edit(Persistable p) { super.edit(p); App app = (App) p; // if (app != null && app.getVisualControlsManager().getControls() != null && // app.getVisualControlsManager().getControls().size() > 0){ // logger.info("First visualControl.getControl(): " + // app.getVisualControlsManager().getControls().iterator().next().getControl()); // } textFieldNameApp.setText(app == null ? "" : app.getName()); textFieldExtensionsApp.setText(app == null ? "" : Utils.join(app.getExtensions(), ",")); checkInstanceApp.setSelected(app == null ? false : app.getForceOneInstance()); textFieldArgFileApp.setText(app == null ? "" : app.getArgumentsFile()); textFieldArgDirApp.setText(app == null ? "" : app.getArgumentsDir()); textFieldPathApp.setText(app == null ? "" : app.getPath()); if (app != null) { appControlsTableModel.setData(app.getControlsManager().getControls()); appVisualControlsTableModel.setData(app.getVisualControlsManager().getControls()); } else { appControlsTableModel.clearData(); appVisualControlsTableModel.clearData(); } setSelectedWindow(app == null ? null : app.getWindowName()); listenViewChanges = true; }
private void btnEditAppSaveActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnEditAppSaveActionPerformed Persistable p = panelListPersistable.getSelectedItem(); if (p != null) { App app = (App) p; app.setName(textFieldNameApp.getText()); // app.setDescription(textFieldDescriptionCategory.getText()); app.setExtensions(new HashSet<>(Arrays.asList(textFieldExtensionsApp.getText().split(",")))); app.setForceOneInstance(checkInstanceApp.isSelected()); app.setArgumentsFile(textFieldArgFileApp.getText()); app.setArgumentsDir(textFieldArgDirApp.getText()); app.setPath(textFieldPathApp.getText()); app.setWindowName(comboWindowName.getSelectedItem().toString()); // determining app.relativePath if (!Utils.isEmpty(app.getPath())) { Map<String, String> env = System.getenv(); for (String commonPath : PcControllerFactory.getPcController().getBinDefaultPaths()) { if (commonPath.startsWith("%")) { String s = commonPath.substring(1, commonPath.length() - 1); for (String k : env.keySet()) { if (k.equalsIgnoreCase(s.toUpperCase())) { commonPath = env.get(k); break; } } } if (!Utils.isEmpty(commonPath)) { if (app.getPath().startsWith(commonPath)) { String relativePath = app.getPath().substring(commonPath.length()); if (relativePath.startsWith("" + File.separatorChar)) { relativePath = relativePath.substring(1); } app.setRelativePath(relativePath); break; } } } } ControlsManager controlsManager = app.getControlsManager(); VisualControlsManager visualControlsManager = app.getVisualControlsManager(); // controlsManager.clear(); // visualControlsManager.clear(); Iterator<Control> it = controlsManager.getControls().iterator(); while (it.hasNext()) { Control control = it.next(); if (((AppControlsTableModel) tableControls.getModel()).getControlPosition(control)[0] == -1) { it.remove(); } } for (int i = 0; i < tableControls.getRowCount(); i++) { Control c = (Control) ((AppControlsTableModel) tableControls.getModel()).getControlAt(i, -1); if (c != null) { c.clean(); if (!c.isEmpty()) { try { c.validate(); } catch (IllegalArgumentException e) { // TODO e.printStackTrace(); } if (c.getId() == null) { controlsManager.addControl(c); } } } } Iterator<VisualControl> it2 = visualControlsManager.getControls().iterator(); while (it2.hasNext()) { VisualControl control = it2.next(); boolean found = false; for (int i = 0; i < tableVisualControls.getRowCount(); i++) { for (int j = 0; j < tableVisualControls.getColumnCount(); j++) { VisualControl c = (VisualControl) tableVisualControls.getModel().getValueAt(i, j); if (control == c) { found = true; break; } } } if (!found) { it2.remove(); } } for (int i = 0; i < tableVisualControls.getRowCount(); i++) { for (int j = 0; j < tableVisualControls.getColumnCount(); j++) { VisualControl c = (VisualControl) tableVisualControls.getModel().getValueAt(i, j); if (c != null) { try { c.validate(); } catch (IllegalArgumentException e) { // TODO e.printStackTrace(); } if (c.getId() == null) { visualControlsManager.addControl(c); } } } } } panelListPersistable.clearSelection(); } // GEN-LAST:event_btnEditAppSaveActionPerformed