Example usage for com.intellij.openapi.ui Messages showYesNoDialog

List of usage examples for com.intellij.openapi.ui Messages showYesNoDialog

Introduction

In this page you can find the example usage for com.intellij.openapi.ui Messages showYesNoDialog.

Prototype

@YesNoResult
public static int showYesNoDialog(String message,
        @NotNull @Nls(capitalization = Nls.Capitalization.Title) String title, @Nullable Icon icon) 

Source Link

Document

Use this method only if you do not know project or component

Usage

From source file:com.microsoft.intellij.AzurePlugin.java

License:Open Source License

private void setValues(final String dataFile) throws Exception {
    final Document doc = ParseXMLUtilMethods.parseFile(dataFile);
    ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override//from w ww  .  j  av  a  2s .  co  m
        public void run() {
            boolean accepted = Messages.showYesNoDialog(message("preferenceQueMsg"),
                    message("preferenceQueTtl"), null) == Messages.YES;
            DataOperations.updatePropertyValue(doc, message("prefVal"), String.valueOf(accepted));

            DataOperations.updatePropertyValue(doc, message("pluginVersion"), PLUGIN_VERSION);
            DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
            DataOperations.updatePropertyValue(doc, message("instID"), dateFormat.format(new Date()));
            try {
                ParseXMLUtilMethods.saveXMLDocument(dataFile, doc);
            } catch (Exception ex) {
                LOG.error(message("error"), ex);
            }
            if (accepted) {
                AppInsightsCustomEvent.create(message("telAgrEvtName"), "");
            }
        }
    }, ModalityState.defaultModalityState());
}

From source file:com.microsoft.intellij.ui.ApplicationsTab.java

License:Open Source License

private ActionListener createRemoveButtonListener() {
    return new ActionListener() {
        @Override//from  ww w.j a  v  a 2s .  c o  m
        public void actionPerformed(ActionEvent e) {
            int curSelIndex = appTable.getSelectedRow();
            if (curSelIndex > -1) {
                if (!newRole) {
                    try {
                        int choice = Messages.showYesNoDialog(message("appRmvMsg"), message("appRmvTtl"),
                                Messages.getQuestionIcon());
                        if (choice == Messages.YES) {
                            String cmpntName = appList.get(curSelIndex).getImpAs();
                            String cmpntPath = String.format("%s%s%s%s%s",
                                    PluginUtil.getModulePath(ModuleManager.getInstance(project)
                                            .findModuleByName(waProjManager.getProjectName())),
                                    File.separator, waRole.getName(), message("approot"), cmpntName);
                            waRole.removeServerApplication(cmpntName);
                            modified = true;
                            if (!fileToDel.contains(cmpntPath)) {
                                fileToDel.add(cmpntPath);
                            }
                            //                                JdkSrvConfig.getTableViewer().refresh();
                            //                                JdkSrvConfigListener.disableRemoveButton();
                        } else {
                            return;
                        }
                    } catch (Exception ex) {
                        PluginUtil.displayErrorDialogAndLog(message("srvErrTtl"), message("rmvSrvAppErrMsg"),
                                ex);
                        return;
                    }
                }
                appList.remove(curSelIndex);
                ((ApplicationsTableModel) appTable.getModel()).fireTableDataChanged();

            }
        }
    };
}

From source file:com.microsoft.intellij.ui.azureroles.CachingPanel.java

License:Open Source License

/**
 * Listener method for remove button which
 * deletes the selected cache entry./*from w  ww.j av a  2s .  co m*/
 */
protected void removeBtnListener() {
    try {
        int choice = Messages.showYesNoDialog(message("cachRmvMsg"), message("cachRmvTtl"),
                Messages.getQuestionIcon());
        if (choice == Messages.YES) {
            WindowsAzureNamedCache cachToDel = tblCache.getSelectedObject();
            cachToDel.delete();
            tblCache.getListTableModel().setItems(new ArrayList<WindowsAzureNamedCache>(mapCache.values()));
            setModified(true);
        }
    } catch (WindowsAzureInvalidProjectOperationException e) {
        PluginUtil.displayErrorDialogAndLog(message("cachErrTtl"), message("cachDelErMsg"), e);
    }
}

From source file:com.microsoft.intellij.ui.azureroles.ComponentsPanel.java

License:Open Source License

/**
 * Listener method for remove button which
 * deletes the selected component.// w  ww .  j  ava 2 s.c o m
 */
private void removeComponent() {
    WindowsAzureRoleComponent component = tblComponents.getSelectedObject();
    //        IWorkspace workspace = ResourcesPlugin.getWorkspace();
    //        IWorkspaceRoot root = workspace.getRoot();
    //        WindowsAzureRoleComponent component = listComponents.get(selIndex);
    try {
        /* First condition: Checks component is part of a JDK,
         * server configuration
        * Second condition: For not showing error message
        * "Disable Server JDK Configuration"
        * while removing server application
        * when server or JDK  is already disabled.
        */
        if (component.getIsPreconfigured() && (!(component.getType().equals(message("typeSrvApp"))
                && windowsAzureRole.getServerName() == null))) {
            PluginUtil.displayErrorDialog(message("jdkDsblErrTtl"), message("jdkDsblErrMsg"));
        } else {
            int choice = Messages.showYesNoDialog(message("cmpntRmvMsg"), message("cmpntRmvTtl"),
                    Messages.getQuestionIcon());
            if (choice == Messages.YES) {
                String cmpntPath = String.format("%s%s%s%s%s",
                        PluginUtil.getModulePath(ModuleManager.getInstance(project)
                                .findModuleByName(waProjManager.getProjectName())),
                        File.separator, windowsAzureRole.getName(), message("approot"),
                        component.getDeployName());
                File file = new File(cmpntPath);
                // Check import source is equal to approot
                if (component.getImportPath().isEmpty() && file.exists()) {
                    int selected = Messages.showYesNoCancelDialog(message("cmpntSrcRmvMsg"),
                            message("cmpntSrcRmvTtl"), Messages.getQuestionIcon());
                    switch (selected) {
                    case Messages.YES:
                        //yes
                        component.delete();
                        //                                tblViewer.refresh();
                        fileToDel.add(file);
                        break;
                    case Messages.NO:
                        //no
                        component.delete();
                        //                                tblViewer.refresh();
                        break;
                    case Messages.CANCEL:
                        //cancel
                        break;
                    default:
                        break;
                    }
                } else {
                    component.delete();
                    //                        tblViewer.refresh();
                    fileToDel.add(file);
                }
                myModified = true;
            }
        }
        //            if (tblComponents.getItemCount() == 0) {
        //                // table is empty i.e. number of rows = 0
        //                btnRemove.setEnabled(false);
        //                btnEdit.setEnabled(false);
        //            }
    } catch (WindowsAzureInvalidProjectOperationException e) {
        PluginUtil.displayErrorDialogAndLog(message("cmpntSetErrTtl"), message("cmpntRmvErrMsg"), e);
    }
}

From source file:com.microsoft.intellij.ui.azureroles.EndpointDialog.java

License:Open Source License

/**
 * Disables the debugging if debug endpoint's type is changed to 'Internal',
 * and if private port is modified then assigns the new debugging port
 * by setting the modified endpoint as a debugging endpoint.
 *
 * @param oldType : old type of the endpoint.
 * @return retVal : false if any error occurs.
 * @throws WindowsAzureInvalidProjectOperationException
 *///from   ww w.j  a  v a2 s  .  c  om
private boolean handleChangeForDebugEndpt(WindowsAzureEndpointType oldType, String privatePort)
        throws WindowsAzureInvalidProjectOperationException {
    boolean retVal = true;
    if (oldType.equals(WindowsAzureEndpointType.Input)
            && comboType.getSelectedItem().equals(WindowsAzureEndpointType.Internal.toString())) {
        int choice = Messages.showYesNoDialog(
                String.format("%s%s%s", message("dlgEPDel"), message("dlgEPChangeType"), message("dlgEPDel2")),
                message("dlgTypeTitle"), Messages.getQuestionIcon());
        if (choice == Messages.YES) {
            waEndpt.setEndPointType((WindowsAzureEndpointType) comboType.getSelectedItem());
            waRole.setDebuggingEndpoint(null);
        } else {
            retVal = false;
        }
    } else if (privatePort == null) {
        PluginUtil.displayErrorDialog(message("dlgInvldPort"), message("dbgPort"));
        retVal = false;
    } else if (!waEndpt.getPrivatePort().equalsIgnoreCase(privatePort)) {
        boolean isSuspended = waRole.getStartSuspended();
        waRole.setDebuggingEndpoint(null);
        waEndpt.setPrivatePort(privatePort);
        waRole.setDebuggingEndpoint(waEndpt);
        waRole.setStartSuspended(isSuspended);
    }
    return retVal;
}

From source file:com.microsoft.intellij.ui.azureroles.EnvVarsPanel.java

License:Open Source License

/**
 * Listener for remove button, which removes the
 * environment variable from the role.//  w w  w. j a v a2  s  .c  om
 */
@SuppressWarnings("unchecked")
protected void removeBtnListener() {
    try {
        Entry<String, String> mapEntry = tblEnvVariables.getSelectedObject();
        // Check environment variable is associated with component
        if (waRole.getIsEnvPreconfigured(mapEntry.getKey())) {
            PluginUtil.displayErrorDialog(message("jdkDsblErrTtl"), message("envJdkDslErrMsg"));
        } else {
            int choice = Messages.showYesNoDialog(message("evRemoveMsg"), message("evRemoveTtl"),
                    Messages.getQuestionIcon());
            if (choice == Messages.YES) {
                /*
                 * to delete call rename with
                 * newName(second param) as empty
                 */
                waRole.renameRuntimeEnv(mapEntry.getKey(), "");
                setModified(true);
            }
        }
    } catch (Exception ex) {
        PluginUtil.displayErrorDialogAndLog(message("adRolErrTitle"),
                message("adRolErrMsgBox1") + message("adRolErrMsgBox2"), ex);
    }
}

From source file:com.microsoft.intellij.ui.azureroles.LoadBalancingPanel.java

License:Open Source License

/**
 * Enable session affinity.//from w  w  w .  ja v  a 2 s.  c  o  m
 */
protected void enableSessionAff() {
    try {
        WindowsAzureEndpoint endpt = null;
        isManualUpdate = false;
        populateEndPointList();
        endpt = WARLoadBalanceUtilMethods.findInputEndpt(waRole, endpointsList);
        if (endpt == null) {
            int choice = Messages.showYesNoDialog(message("lbCreateEndptTtl"), message("lbCreateEndptMsg"),
                    Messages.getQuestionIcon());
            if (choice == Messages.YES) {
                WindowsAzureEndpoint newEndpt = createEndpt();
                populateEndPointList();
                comboEndpt.setSelectedItem(String.format(message("dbgEndPtStr"), newEndpt.getName(),
                        newEndpt.getPort(), newEndpt.getPrivatePort()));
                waRole.setSessionAffinityInputEndpoint(newEndpt);
                btnSsnAffinity.setSelected(true);
                setModified(true);
                isEditableEndpointCombo(newEndpt);
            } else {
                btnSsnAffinity.setSelected(false);
                lblEndptToUse.setEnabled(false);
                comboEndpt.setEnabled(false);
            }
        } else {
            comboEndpt.setSelectedItem(String.format(message("dbgEndPtStr"), endpt.getName(), endpt.getPort(),
                    endpt.getPrivatePort()));
            waRole.setSessionAffinityInputEndpoint(endpt);
            setModified(true);
            isEditableEndpointCombo(endpt);
        }
    } catch (WindowsAzureInvalidProjectOperationException e) {
        PluginUtil.displayErrorDialogAndLog(message("adRolErrTitle"),
                message("adRolErrMsgBox1") + message("adRolErrMsgBox2"), e);
    } finally {
        isManualUpdate = true;
    }
}

From source file:com.microsoft.intellij.ui.azureroles.LocalStoragePanel.java

License:Open Source License

/**
 * Listener method for remove button which
 * deletes the selected local storage resource.
 *//*from  w  w  w .  ja v  a  2 s . co  m*/
@SuppressWarnings("unchecked")
protected void removeBtnListener() {
    try {
        WindowsAzureLocalStorage delRes = tblResources.getSelectedObject();
        /*
         * Check local storage selected for removal
        * is associated with caching then give error
        * and does not allow to remove.
        */
        if (delRes.isCachingLocalStorage()) {
            PluginUtil.displayErrorDialog(message("cachDsblErTtl"), message("lclStrRmvErMsg"));
        } else {
            int choice = Messages.showYesNoDialog(message("lclStgRmvMsg"), message("lclStgRmvTtl"),
                    Messages.getQuestionIcon());
            if (choice == Messages.YES) {
                delRes.delete();
                setModified(true);
                tblResources.getListTableModel().removeRow(tblResources.getSelectedRow());
            }
        }
    } catch (WindowsAzureInvalidProjectOperationException e) {
        PluginUtil.displayErrorDialogAndLog(message("lclStgSetErrTtl"), message("lclStgSetErrMsg"), e);
    }
}

From source file:com.microsoft.intellij.ui.azureroles.LocalStorageResourceDialog.java

License:Open Source License

/**
 * Validates the size of VM.//w  w  w  .  j a  v  a  2s .  c o m
 *
 * @param size : user entered size
 * @return isValidSize : true if size is valid else false.
 */
private boolean isValidSize(String size) {
    boolean isValidSize;
    try {
        int value = Integer.parseInt(size);
        if (value <= 0) {
            PluginUtil.displayErrorDialog(message("lclStgSizeErrTtl"), message("lclStgSizeErrMsg"));
            isValidSize = false;
        } else if (value > maxSize) {
            int choice = Messages.showYesNoDialog(
                    String.format("%s%s%s", message("lclStgMxSizeMsg1"), maxSize, message("lclStgMxSizeMsg2")),
                    message("lclStgMxSizeTtl"), Messages.getQuestionIcon());
            /*
             * If user selects No
             * then keep dialog open.
             */
            isValidSize = choice == Messages.YES;
        } else {
            isValidSize = true;
        }
    } catch (NumberFormatException e) {
        PluginUtil.displayErrorDialogAndLog(message("lclStgSizeErrTtl"), message("lclStgSizeErrMsg"), e);
        isValidSize = false;
    }
    return isValidSize;
}

From source file:com.microsoft.intellij.ui.azureroles.RoleEndpointsPanel.java

License:Open Source License

/**
 * Listener method for remove button which
 * deletes the selected endpoint./*from w  w w  .  j  a va 2 s .  c  o  m*/
 */
private void removeEndpoint() {
    WindowsAzureEndpoint waEndpoint = tblEndpoints.getSelectedObject();
    try {
        WindowsAzureEndpoint debugEndpt = windowsAzureRole.getDebuggingEndpoint();
        String dbgEndptName = "";
        if (debugEndpt != null) {
            dbgEndptName = debugEndpt.getName();
        }
        // delete the selected endpoint
        /*
         * Check end point selected for removal
        * is associated with Caching then give error
        * and does not allow to remove.
        */
        if (waEndpoint.isCachingEndPoint()) {
            PluginUtil.displayErrorDialog(message("cachDsblErTtl"), message("endPtRmvErMsg"));
        }
        /*
         * Check end point selected for removal
        * is associated with Debugging.
        */
        else if (waEndpoint.getName().equalsIgnoreCase(dbgEndptName)) {
            StringBuilder msg = new StringBuilder(message("dlgEPDel"));
            msg.append(message("dlgEPDel1"));
            msg.append(message("dlgEPDel2"));
            int choice = Messages.showYesNoDialog(msg.toString(), message("dlgDelEndPt1"),
                    Messages.getQuestionIcon());
            if (choice == Messages.YES) {
                waEndpoint.delete();
                setModified(true);
                windowsAzureRole.setDebuggingEndpoint(null);
            }
        }
        /*
         * Endpoint associated with both SSL
         * and Session affinity
         */
        else if (waEndpoint.isStickySessionEndpoint() && waEndpoint.isSSLEndpoint()) {
            int choice = Messages.showOkCancelDialog(message("bothDelMsg"), message("dlgDelEndPt1"),
                    Messages.getQuestionIcon());
            if (choice == Messages.OK) {
                setModified(true);
                if (waEndpoint.getEndPointType().equals(WindowsAzureEndpointType.Input)) {
                    windowsAzureRole.setSessionAffinityInputEndpoint(null);
                    windowsAzureRole.setSslOffloading(null, null);
                    waEndpoint.delete();
                } else {
                    windowsAzureRole.setSessionAffinityInputEndpoint(null);
                    windowsAzureRole.setSslOffloading(null, null);
                }
            }
        }
        /*
         * Check end point selected for removal
        * is associated with Load balancing
        * i.e (HTTP session affinity).
        */
        else if (waEndpoint.isStickySessionEndpoint()) {
            int choice = Messages.showOkCancelDialog(message("ssnAffDelMsg"), message("dlgDelEndPt1"),
                    Messages.getQuestionIcon());
            if (choice == Messages.OK) {
                setModified(true);
                if (waEndpoint.getEndPointType().equals(WindowsAzureEndpointType.Input)) {
                    windowsAzureRole.setSessionAffinityInputEndpoint(null);
                    waEndpoint.delete();
                } else {
                    windowsAzureRole.setSessionAffinityInputEndpoint(null);
                }
            }
        }
        /*
         * Endpoint associated with SSL
         */
        else if (waEndpoint.isSSLEndpoint()) {
            int choice = Messages.showOkCancelDialog(message("sslDelMsg"), message("dlgDelEndPt1"),
                    Messages.getQuestionIcon());
            if (choice == Messages.OK) {
                setModified(true);
                if (waEndpoint.getEndPointType().equals(WindowsAzureEndpointType.Input)) {
                    windowsAzureRole.setSslOffloading(null, null);
                    waEndpoint.delete();
                } else {
                    windowsAzureRole.setSslOffloading(null, null);
                }
            }
        }
        /*
         * Endpoint associated with SSL redirection.
         */
        else if (waEndpoint.isSSLRedirectEndPoint()) {
            int choice = Messages.showOkCancelDialog(message("sslRedirectDelMsg"), message("dlgDelEndPt1"),
                    Messages.getQuestionIcon());
            if (choice == Messages.OK) {
                windowsAzureRole.deleteSslOffloadingRedirectionEndpoint();
                setModified(true);
            }
        }
        /*
         * Normal end point.
         */
        else {
            int choice = Messages.showOkCancelDialog(message("dlgDelEndPt2"), message("dlgDelEndPt1"),
                    Messages.getQuestionIcon());
            if (choice == Messages.OK) {
                setModified(true);
                waEndpoint.delete();
            }
        }
    } catch (WindowsAzureInvalidProjectOperationException e) {
        PluginUtil.displayErrorDialogAndLog(message("adRolErrMsgBox1") + message("adRolErrMsgBox2"),
                message("adRolErrTitle"), e);
    }
}