/** Listener for remove button, which removes the environment variable from the role. */ @SuppressWarnings("unchecked") protected void removeBtnListener() { int selIndex = tblViewer.getTable().getSelectionIndex(); if (selIndex > -1) { try { Entry<String, String> mapEntry = (Entry<String, String>) tblViewer.getTable().getItem(selIndex).getData(); // Check environment variable is associated with component if (windowsAzureRole.getIsEnvPreconfigured(mapEntry.getKey())) { errorTitle = Messages.jdkDsblErrTtl; errorMessage = Messages.envJdkDslErrMsg; MessageUtil.displayErrorDialog(getShell(), errorTitle, errorMessage); } else { boolean choice = MessageDialog.openQuestion(new Shell(), Messages.evRemoveTtl, Messages.evRemoveMsg); if (choice) { // to delete call rename with newName(second param) as empty windowsAzureRole.renameRuntimeEnv(mapEntry.getKey(), ""); tblViewer.refresh(); } } } catch (Exception ex) { errorTitle = Messages.adRolErrTitle; errorMessage = Messages.adRolErrMsgBox1 + Messages.adRolErrMsgBox2; MessageUtil.displayErrorDialog(this.getShell(), errorTitle, errorMessage); Activator.getDefault().log(errorMessage, ex); } } }
@SuppressWarnings("unchecked") @Override public String getColumnText(Object element, int colIndex) { String result = ""; try { Entry<String, String> mapEntry = (Entry<String, String>) element; switch (colIndex) { case 0: result = mapEntry.getKey(); break; case 1: result = mapEntry.getValue(); break; default: // This switch is for column indices. Here the switch always // have an valid index so default will never be reached. } } catch (Exception ex) { errorTitle = Messages.adRolErrTitle; errorMessage = Messages.adRolErrMsgBox1 + Messages.adRolErrMsgBox2; MessageUtil.displayErrorDialog(getShell(), errorTitle, errorMessage); Activator.getDefault().log(errorMessage, ex); } return result; }
/** * Creates a table viewer for environment variables table, which a) sets the input data for table * b) enables in-place modification. */ private void createTableViewer() { tblViewer = new TableViewer(tblEnvVariables); tblViewer.setUseHashlookup(true); tblViewer.setColumnProperties(new String[] {Messages.evColName, Messages.evColValue}); CellEditor[] editors = new CellEditor[2]; editors[0] = new TextCellEditor(tblEnvVariables); editors[1] = new TextCellEditor(tblEnvVariables); tblViewer.setCellEditors(editors); tblViewer.setContentProvider(new EnvVarContentProvider()); tblViewer.setLabelProvider(new EnvVarLabelProvider()); tblViewer.setCellModifier(new EnvVarCellModifier()); try { mapEnvVar = windowsAzureRole.getRuntimeEnv(); tblViewer.setInput(mapEnvVar.entrySet().toArray()); } catch (Exception ex) { errorTitle = Messages.rolsErr; errorMessage = Messages.adRolErrMsgBox1 + Messages.adRolErrMsgBox2; MessageUtil.displayErrorDialog(getShell(), errorTitle, errorMessage); Activator.getDefault().log(errorMessage, ex); } }
@Override protected void okPressed() { boolean okToProceed = true; try { if (isEditEndpt) { // if its an edit an endpoint scenario okToProceed = editEndpt(); } else { // for add an endpoint scenario boolean isValid = windowsAzureRole.isAvailableEndpointName(txtName.getText()); if (isValid) { boolean isValidendpoint = windowsAzureRole.isValidEndpoint( txtName.getText(), WindowsAzureEndpointType.valueOf(comboType.getText()), txtPrivatePort.getText(), txtPublicPort.getText()); if (isValidendpoint) { windowsAzureRole.addEndpoint( txtName.getText(), WindowsAzureEndpointType.valueOf(comboType.getText()), txtPrivatePort.getText(), txtPublicPort.getText()); } else { errorTitle = Messages.dlgInvldPort; errorMessage = Messages.dlgPortInUse; MessageUtil.displayErrorDialog(this.getShell(), errorTitle, errorMessage); okToProceed = false; } } else { errorTitle = Messages.dlgInvdEdPtName1; errorMessage = Messages.dlgInvdEdPtName2; MessageUtil.displayErrorDialog(this.getShell(), errorTitle, errorMessage); okToProceed = false; } } } catch (WindowsAzureInvalidProjectOperationException e) { errorTitle = Messages.rolsErr; errorMessage = Messages.adRolErrMsgBox1 + Messages.adRolErrMsgBox2; MessageUtil.displayErrorDialog(this.getShell(), errorTitle, errorMessage); Activator.getDefault().log(errorMessage, e); } if (okToProceed) { super.okPressed(); } }
/** * Validates public and private ports. And also makes changes corresponding to the debug endpoint. * * @param oldEndptName : old name of the endpoint. * @return retVal : false if any error occurs. * @throws WindowsAzureInvalidProjectOperationException */ private boolean validatePorts(String oldEndptName) throws WindowsAzureInvalidProjectOperationException { boolean retVal = true; WindowsAzureEndpointType oldType = waEndpt.getEndPointType(); WindowsAzureEndpoint debugEndpt = windowsAzureRole.getDebuggingEndpoint(); WindowsAzureEndpoint stickyEndpt = windowsAzureRole.getSessionAffinityInputEndpoint(); WindowsAzureEndpoint stickyIntEndpt = windowsAzureRole.getSessionAffinityInternalEndpoint(); String stcEndptName = ""; String dbgEndptName = ""; String stcIntEndptName = ""; if (debugEndpt != null) { // get the debugging endpoint name dbgEndptName = debugEndpt.getName(); } if (stickyEndpt != null) { stcEndptName = stickyEndpt.getName(); stcIntEndptName = stickyIntEndpt.getName(); } // validate ports boolean isValidendpoint = windowsAzureRole.isValidEndpoint( oldEndptName, WindowsAzureEndpointType.valueOf(comboType.getText()), txtPrivatePort.getText(), txtPublicPort.getText()); if (isValidendpoint) { if (oldEndptName.equalsIgnoreCase(dbgEndptName)) { retVal = handleChangeForDebugEndpt(oldType); } if (oldEndptName.equalsIgnoreCase(stcEndptName)) { retVal = handleChangeForStickyEndpt(oldType); } if (oldEndptName.equalsIgnoreCase(stcIntEndptName)) { retVal = handleChangeForStickyEndpt(oldType); } if (retVal) { // set the new values in the endpoint object. waEndpt.setEndPointType(WindowsAzureEndpointType.valueOf(comboType.getText())); waEndpt.setName(txtName.getText()); if (comboType.getText().equalsIgnoreCase(WindowsAzureEndpointType.Input.toString()) || comboType .getText() .equalsIgnoreCase(WindowsAzureEndpointType.InstanceInput.toString())) { waEndpt.setPort(txtPublicPort.getText()); } waEndpt.setPrivatePort(txtPrivatePort.getText()); } } else { errorTitle = Messages.dlgInvldPort; errorMessage = Messages.dlgPortInUse; MessageUtil.displayErrorDialog(this.getShell(), errorTitle, errorMessage); retVal = false; } return retVal; }
@SuppressWarnings("unchecked") @Override public void modify(Object variable, String columnName, Object modifiedVal) { try { TableItem tblItem = (TableItem) variable; Entry<String, String> mapEntry = (Entry<String, String>) tblItem.getData(); if (columnName.equals(Messages.evColName)) { String modifiedName = modifiedVal.toString(); boolean isValidName = true; for (Iterator<String> iterator = mapEnvVar.keySet().iterator(); iterator.hasNext(); ) { String key = iterator.next(); if (key.equalsIgnoreCase(modifiedName)) { isValidName = false; break; } } if (modifiedName.isEmpty()) { errorTitle = Messages.evNameEmptyTtl; errorMessage = Messages.evNameEmptyMsg; MessageUtil.displayErrorDialog(getShell(), errorTitle, errorMessage); } else if (!isValidName && !modifiedName.equalsIgnoreCase(mapEntry.getKey()) || windowsAzureRole.getLsEnv().contains(modifiedName)) { errorTitle = Messages.evInUseTitle; errorMessage = Messages.evInUseMsg; MessageUtil.displayErrorDialog(getShell(), errorTitle, errorMessage); } else { String name = modifiedName.trim(); name = name.replaceAll("[\\s]+", "_"); windowsAzureRole.renameRuntimeEnv(mapEntry.getKey(), name); } } else if (columnName.equals(Messages.evColValue)) { windowsAzureRole.setRuntimeEnv(mapEntry.getKey(), modifiedVal.toString().trim()); } tblViewer.refresh(); } catch (Exception ex) { errorTitle = Messages.adRolErrTitle; errorMessage = Messages.adRolErrMsgBox1 + Messages.adRolErrMsgBox2; MessageUtil.displayErrorDialog(getShell(), errorTitle, errorMessage); Activator.getDefault().log(errorMessage, ex); } }
/** Listener for add button, which launches a dialog to add an environment variable. */ protected void addBtnListener() { try { WAEnvVarDialog dialog = new WAEnvVarDialog(getShell(), mapEnvVar, windowsAzureRole); dialog.open(); tblViewer.refresh(); } catch (Exception ex) { errorTitle = Messages.evLaunchErrTtl; errorMessage = Messages.evErrLaunchMsg1 + Messages.evErrLaunchMsg2; MessageUtil.displayErrorDialog(getShell(), errorTitle, errorMessage); Activator.getDefault().log(errorMessage, ex); } }
@SuppressWarnings("unchecked") public Object getValue(Object element, String property) { Object result = null; try { Entry<String, String> mapEntry = (Entry<String, String>) element; if (property.equals(Messages.evColName)) { result = mapEntry.getKey(); } else if (property.equals(Messages.evColValue)) { result = mapEntry.getValue(); } } catch (Exception ex) { errorTitle = Messages.adRolErrTitle; errorMessage = Messages.adRolErrMsgBox1 + Messages.adRolErrMsgBox2; MessageUtil.displayErrorDialog(getShell(), errorTitle, errorMessage); Activator.getDefault().log(errorMessage, ex); } return result; }
/** Listener for edit button, which launches a dialog to edit an environment variable. */ @SuppressWarnings("unchecked") protected void editBtnListener() { int selIndex = tblViewer.getTable().getSelectionIndex(); if (selIndex > -1) { try { Entry<String, String> mapEntry = (Entry<String, String>) tblViewer.getTable().getItem(selIndex).getData(); WAEnvVarDialog dialog = new WAEnvVarDialog(getShell(), mapEnvVar, windowsAzureRole, mapEntry.getKey()); dialog.open(); tblViewer.refresh(); } catch (Exception ex) { errorTitle = Messages.evLaunchErrTtl; errorMessage = Messages.evErrLaunchMsg1 + Messages.evErrLaunchMsg2; MessageUtil.displayErrorDialog(getShell(), errorTitle, errorMessage); Activator.getDefault().log(errorMessage, ex); } } }
/** * This method edits an endpoint. For editing it also validates endpoint name and ports. * * @return retVal : false if any error occurs. * @throws WindowsAzureInvalidProjectOperationException */ private boolean editEndpt() throws WindowsAzureInvalidProjectOperationException { boolean retVal = true; String oldEndptName = waEndpt.getName(); if (!oldEndptName.equalsIgnoreCase(txtName.getText())) { // validate endpoint name boolean isValid = windowsAzureRole.isAvailableEndpointName(txtName.getText()); if (!isValid) { // if name is not valid errorTitle = Messages.dlgInvdEdPtName1; errorMessage = Messages.dlgInvdEdPtName2; MessageUtil.displayErrorDialog(this.getShell(), errorTitle, errorMessage); retVal = false; } } if (retVal) { retVal = validatePorts(oldEndptName); } return retVal; }
@Override public boolean performOk() { boolean okToProceed = true; try { if (!Activator.getDefault().isSaved()) { waProjManager.save(); Activator.getDefault().setSaved(true); } WAEclipseHelper.refreshWorkspace(Messages.rolsRefTitle, Messages.rolsRefMsg); } catch (WindowsAzureInvalidProjectOperationException e) { errorTitle = Messages.adRolErrTitle; errorMessage = Messages.adRolErrMsgBox1 + Messages.adRolErrMsgBox2; MessageUtil.displayErrorDialog(this.getShell(), errorTitle, errorMessage); Activator.getDefault().log(errorMessage, e); okToProceed = false; } if (okToProceed) { okToProceed = super.performOk(); } return okToProceed; }