@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();
   }
 }
 /**
  * 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;
 }
 /**
  * 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();
   String newEndptName = txtName.getText().trim();
   // validate endpoint name
   /*
    * Ignore if end point name is not edited.
    */
   if (!oldEndptName.equalsIgnoreCase(newEndptName)) {
     /*
      * Check endpoint name contain
      * alphanumeric and underscore characters only.
      * Starts with alphabet.
      */
     if (WAEclipseHelperMethods.isAlphaNumericUnderscore(newEndptName)) {
       /*
        * Check already used endpoint name is given.
        */
       boolean isValid =
           waRole.isAvailableEndpointName(
               newEndptName, (WindowsAzureEndpointType) comboType.getSelectedItem());
       if (!isValid) {
         // if name is not valid
         PluginUtil.displayErrorDialog(message("dlgInvdEdPtName1"), message("dlgInvdEdPtName2"));
         retVal = false;
       }
     } else {
       PluginUtil.displayErrorDialog(message("dlgInvdEdPtName1"), message("enPtAlphNuMsg"));
       retVal = false;
     }
   }
   if (retVal) {
     retVal = validatePorts(oldEndptName);
   }
   return retVal;
 }
 public void doOKAction() {
   try {
     if (waEndpt != null) {
       // Edit an endpoint scenario
       if (!editEndpt()) {
         return;
       }
     } else {
       // Add an endpoint scenario
       // validate name
       WindowsAzureEndpointType endPtType = (WindowsAzureEndpointType) comboType.getSelectedItem();
       String endPtName = txtName.getText().trim();
       /*
        * Check endpoint name contain
        * alphanumeric and underscore characters only.
        * Starts with alphabet.
        */
       if (WAEclipseHelperMethods.isAlphaNumericUnderscore(endPtName)) {
         boolean isValidName = waRole.isAvailableEndpointName(endPtName, endPtType);
         /*
          * Check already used endpoint name is given.
          */
         if (isValidName) {
           if (endPtType.equals(WindowsAzureEndpointType.InstanceInput)
               || endPtType.equals(WindowsAzureEndpointType.Internal)) {
             if (WAEndpointDialogUtilMethods.isDashPresent(
                 endPtType,
                 txtPrivatePort.getText(),
                 txtPrivatePortRangeEnd.getText(),
                 txtPublicPort.getText(),
                 txtPublicPortRangeEnd.getText())) {
               PluginUtil.displayErrorDialog(message("dlgInvldPort"), message("portRangeErrMsg"));
               return;
             }
           }
           // Check for valid range 1 to 65535
           if (WAEndpointDialogUtilMethods.isValidPortRange(
               endPtType,
               txtPrivatePort.getText(),
               txtPrivatePortRangeEnd.getText(),
               txtPublicPort.getText(),
               txtPublicPortRangeEnd.getText())) {
             // Combine port range
             String publicPort =
                 WAEndpointDialogUtilMethods.combinePublicPortRange(
                     txtPublicPort.getText(),
                     txtPublicPortRangeEnd.getText(),
                     endPtType.toString());
             String privatePort =
                 WAEndpointDialogUtilMethods.combinePrivatePortRange(
                     txtPrivatePort.getText(),
                     txtPrivatePortRangeEnd.getText(),
                     endPtType.toString());
             if (privatePort.equalsIgnoreCase(AUTO)) {
               privatePort = null;
             }
             // Validate and commit endpoint addition
             if (waRole.isValidEndpoint(endPtName, endPtType, privatePort, publicPort)) {
               waRole.addEndpoint(endPtName, endPtType, privatePort, publicPort);
             } else {
               PluginUtil.displayErrorDialog(message("dlgInvldPort"), message("dlgPortInUse"));
               return;
             }
           } else {
             PluginUtil.displayErrorDialog(message("dlgInvldPort"), message("rngErrMsg"));
             return;
           }
         } else {
           PluginUtil.displayErrorDialog(message("dlgInvdEdPtName1"), message("dlgInvdEdPtName2"));
           return;
         }
       } else {
         PluginUtil.displayErrorDialog(message("dlgInvdEdPtName1"), message("enPtAlphNuMsg"));
         return;
       }
     }
   } catch (WindowsAzureInvalidProjectOperationException ex) {
     PluginUtil.displayErrorDialogAndLog(
         message("rolsErr"), message("adRolErrMsgBox1") + message("adRolErrMsgBox2"), ex);
     return;
   }
   super.doOKAction();
 }