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

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

Introduction

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

Prototype

@YesNoCancelResult
public static int showYesNoCancelDialog(String message,
        @Nls(capitalization = Nls.Capitalization.Title) String title, Icon icon) 

Source Link

Document

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

Usage

From source file:com.intellij.codeInsight.daemon.impl.quickfix.AddExceptionToThrowsFix.java

License:Apache License

static void addExceptionsToThrowsList(@NotNull final Project project, @NotNull final PsiMethod targetMethod,
        @NotNull final Set<PsiClassType> unhandledExceptions) {
    final PsiMethod[] superMethods = getSuperMethods(targetMethod);

    boolean hasSuperMethodsWithoutExceptions = hasSuperMethodsWithoutExceptions(superMethods,
            unhandledExceptions);//from  w w w.j ava  2  s . c o m

    final boolean processSuperMethods;
    if (hasSuperMethodsWithoutExceptions && superMethods.length > 0) {
        int result = Messages.showYesNoCancelDialog(
                QuickFixBundle.message("add.exception.to.throws.inherited.method.warning.text",
                        targetMethod.getName()),
                QuickFixBundle.message("method.is.inherited.warning.title"), Messages.getQuestionIcon());

        if (result == 0) {
            processSuperMethods = true;
        } else if (result == 1) {
            processSuperMethods = false;
        } else {
            return;
        }
    } else {
        processSuperMethods = false;
    }

    ApplicationManager.getApplication().runWriteAction(new Runnable() {
        @Override
        public void run() {
            if (!FileModificationService.getInstance().prepareFileForWrite(targetMethod.getContainingFile()))
                return;
            if (processSuperMethods) {
                for (PsiMethod superMethod : superMethods) {
                    if (!FileModificationService.getInstance()
                            .prepareFileForWrite(superMethod.getContainingFile()))
                        return;
                }
            }

            try {
                processMethod(project, targetMethod, unhandledExceptions);

                if (processSuperMethods) {
                    for (PsiMethod superMethod : superMethods) {
                        processMethod(project, superMethod, unhandledExceptions);
                    }
                }
            } catch (IncorrectOperationException e) {
                LOG.error(e);
            }
        }
    });
}

From source file:com.intellij.lang.ant.config.execution.AntBuildMessageView.java

License:Apache License

/**
 * @return can be null if user cancelled operation
 *//*from w w  w . ja  v a2  s . c  o m*/
@Nullable
public static AntBuildMessageView openBuildMessageView(Project project, AntBuildFileBase buildFile,
        String[] targets) {
    final VirtualFile antFile = buildFile.getVirtualFile();
    if (!LOG.assertTrue(antFile != null)) {
        return null;
    }

    // check if there are running instances of the same build file

    MessageView ijMessageView = MessageView.SERVICE.getInstance(project);
    Content[] contents = ijMessageView.getContentManager().getContents();
    for (Content content : contents) {
        if (content.isPinned()) {
            continue;
        }
        AntBuildMessageView buildMessageView = content.getUserData(KEY);
        if (buildMessageView == null) {
            continue;
        }

        if (!antFile.equals(buildMessageView.getBuildFile().getVirtualFile())) {
            continue;
        }

        if (buildMessageView.isStopped()) {
            ijMessageView.getContentManager().removeContent(content, true);
            continue;
        }

        int result = Messages.showYesNoCancelDialog(
                AntBundle.message("ant.is.active.terminate.confirmation.text"),
                AntBundle.message("starting.ant.build.dialog.title"), Messages.getQuestionIcon());

        switch (result) {
        case 0: // yes
            buildMessageView.stopProcess();
            ijMessageView.getContentManager().removeContent(content, true);
            continue;
        case 1: // no
            continue;
        default: // cancel
            return null;
        }
    }

    final AntBuildMessageView messageView = new AntBuildMessageView(project, buildFile, targets);
    String contentName = buildFile.getPresentableName();
    contentName = BUILD_CONTENT_NAME + " (" + contentName + ")";

    final Content content = ContentFactory.SERVICE.getInstance().createContent(messageView.getComponent(),
            contentName, true);
    content.putUserData(KEY, messageView);
    ijMessageView.getContentManager().addContent(content);
    ijMessageView.getContentManager().setSelectedContent(content);
    content.setDisposer(new Disposable() {
        @Override
        public void dispose() {
            Disposer.dispose(messageView.myAlarm);
        }
    });
    new CloseListener(content, ijMessageView.getContentManager(), project);
    // Do not inline next two variabled. Seeking for NPE.
    ToolWindow messageToolWindow = ToolWindowManager.getInstance(project)
            .getToolWindow(ToolWindowId.MESSAGES_WINDOW);
    messageToolWindow.activate(null);
    return messageView;
}

From source file:com.intellij.plugins.haxe.ide.refactoring.memberPushDown.PushDownProcessor.java

License:Apache License

@Override
protected boolean preprocessUsages(final Ref<UsageInfo[]> refUsages) {
    final UsageInfo[] usagesIn = refUsages.get();
    final PushDownConflicts pushDownConflicts = new PushDownConflicts(myClass, myMemberInfos);
    pushDownConflicts.checkSourceClassConflicts();

    if (usagesIn.length == 0) {
        if (myClass.isEnum() || myClass.hasModifierProperty(PsiModifier.FINAL)) {
            if (Messages.showOkCancelDialog(
                    (myClass.isEnum()/*w  w w. j  a va2 s.c  o m*/
                            ? "Enum " + myClass.getQualifiedName() + " doesn't have constants to inline to. "
                            : "Final class " + myClass.getQualifiedName() + "does not have inheritors. ")
                            + "Pushing members down will result in them being deleted. "
                            + "Would you like to proceed?",
                    JavaPushDownHandler.REFACTORING_NAME, Messages.getWarningIcon()) != Messages.OK) {
                return false;
            }
        } else {
            String noInheritors = myClass.isInterface()
                    ? RefactoringBundle.message("interface.0.does.not.have.inheritors",
                            myClass.getQualifiedName())
                    : RefactoringBundle.message("class.0.does.not.have.inheritors", myClass.getQualifiedName());
            final String message = noInheritors + "\n"
                    + RefactoringBundle.message("push.down.will.delete.members");
            final int answer = Messages.showYesNoCancelDialog(message, JavaPushDownHandler.REFACTORING_NAME,
                    Messages.getWarningIcon());
            if (answer == Messages.YES) {
                myCreateClassDlg = CreateSubclassAction.chooseSubclassToCreate(myClass);
                if (myCreateClassDlg != null) {
                    pushDownConflicts.checkTargetClassConflicts(null, false,
                            myCreateClassDlg.getTargetDirectory());
                    return showConflicts(pushDownConflicts.getConflicts(), usagesIn);
                } else {
                    return false;
                }
            } else if (answer != Messages.NO)
                return false;
        }
    }
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            ApplicationManager.getApplication().runReadAction(new Runnable() {
                @Override
                public void run() {
                    for (UsageInfo usage : usagesIn) {
                        final PsiElement element = usage.getElement();
                        if (element instanceof PsiClass) {
                            pushDownConflicts.checkTargetClassConflicts((PsiClass) element, usagesIn.length > 1,
                                    element);
                        }
                    }
                }
            });
        }
    };

    if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(runnable,
            RefactoringBundle.message("detecting.possible.conflicts"), true, myProject)) {
        return false;
    }

    for (UsageInfo info : usagesIn) {
        final PsiElement element = info.getElement();
        if (element instanceof PsiFunctionalExpression) {
            pushDownConflicts.getConflicts().putValue(element,
                    RefactoringBundle.message("functional.interface.broken"));
        }
    }
    final PsiAnnotation annotation = AnnotationUtil.findAnnotation(myClass,
            CommonClassNames.JAVA_LANG_FUNCTIONAL_INTERFACE);
    if (annotation != null && isMoved(LambdaUtil.getFunctionalInterfaceMethod(myClass))) {
        pushDownConflicts.getConflicts().putValue(annotation,
                RefactoringBundle.message("functional.interface.broken"));
    }
    return showConflicts(pushDownConflicts.getConflicts(), usagesIn);
}

From source file:com.intellij.refactoring.memberPushDown.PushDownProcessor.java

License:Apache License

protected boolean preprocessUsages(final Ref<UsageInfo[]> refUsages) {
    final UsageInfo[] usagesIn = refUsages.get();
    final PushDownConflicts pushDownConflicts = new PushDownConflicts(myClass, myMemberInfos);
    pushDownConflicts.checkSourceClassConflicts();

    if (usagesIn.length == 0) {
        if (myClass.isEnum() || myClass.hasModifierProperty(PsiModifier.FINAL)) {
            if (Messages.showOkCancelDialog(
                    (myClass.isEnum()//from ww w.  j  ava2 s.c om
                            ? "Enum " + myClass.getQualifiedName() + " doesn't have constants to inline to. "
                            : "Final class " + myClass.getQualifiedName() + "does not have inheritors. ")
                            + "Pushing members down will result in them being deleted. "
                            + "Would you like to proceed?",
                    JavaPushDownHandler.REFACTORING_NAME,
                    Messages.getWarningIcon()) != DialogWrapper.OK_EXIT_CODE) {
                return false;
            }
        } else {
            String noInheritors = myClass.isInterface()
                    ? RefactoringBundle.message("interface.0.does.not.have.inheritors",
                            myClass.getQualifiedName())
                    : RefactoringBundle.message("class.0.does.not.have.inheritors", myClass.getQualifiedName());
            final String message = noInheritors + "\n"
                    + RefactoringBundle.message("push.down.will.delete.members");
            final int answer = Messages.showYesNoCancelDialog(message, JavaPushDownHandler.REFACTORING_NAME,
                    Messages.getWarningIcon());
            if (answer == DialogWrapper.OK_EXIT_CODE) {
                myCreateClassDlg = CreateSubclassAction.chooseSubclassToCreate(myClass);
                if (myCreateClassDlg != null) {
                    pushDownConflicts.checkTargetClassConflicts(null, false,
                            myCreateClassDlg.getTargetDirectory());
                    return showConflicts(pushDownConflicts.getConflicts(), usagesIn);
                } else {
                    return false;
                }
            } else if (answer != 1)
                return false;
        }
    }
    Runnable runnable = new Runnable() {
        public void run() {
            for (UsageInfo usage : usagesIn) {
                final PsiElement element = usage.getElement();
                if (element instanceof PsiClass) {
                    pushDownConflicts.checkTargetClassConflicts((PsiClass) element, usagesIn.length > 1,
                            element);
                }
            }
        }
    };

    if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(runnable,
            RefactoringBundle.message("detecting.possible.conflicts"), true, myProject)) {
        return false;
    }
    return showConflicts(pushDownConflicts.getConflicts(), usagesIn);
}

From source file:com.intellij.refactoring.typeMigration.TypeMigrationLabeler.java

License:Apache License

boolean addRoot(final TypeMigrationUsageInfo usageInfo, final PsiType type, final PsiElement place,
        boolean alreadyProcessed) {
    if (myShowWarning && myMigrationRoots.size() > 10
            && !ApplicationManager.getApplication().isUnitTestMode()) {
        myShowWarning = false;/*from w w w  .  ja v a2  s.com*/
        try {
            final Runnable checkTimeToStopRunnable = new Runnable() {
                public void run() {
                    if (Messages.showYesNoCancelDialog(
                            "Found more than 10 roots to migrate. Do you want to preview?", "Type Migration",
                            Messages.getWarningIcon()) == DialogWrapper.OK_EXIT_CODE) {
                        myException = new MigrateException();
                    }
                }
            };
            SwingUtilities.invokeLater(checkTimeToStopRunnable);
        } catch (Exception e) {
            //do nothing
        }
    }
    if (myException != null)
        throw myException;
    rememberRootTrace(usageInfo, type, place, alreadyProcessed);
    if (!alreadyProcessed && !getTypeEvaluator().setType(usageInfo, type)) {
        alreadyProcessed = true;
    }

    if (!alreadyProcessed)
        myMigrationRoots.addFirst(new Pair<TypeMigrationUsageInfo, PsiType>(usageInfo, type));
    return alreadyProcessed;
}

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

License:Open Source License

/**
 * Listener method for remove button which
 * deletes the selected component.//from w  w  w .  ja  v a 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.SSLOffloadingPanel.java

License:Open Source License

private WindowsAzureEndpoint findInputEndpt() throws WindowsAzureInvalidProjectOperationException {
    WindowsAzureEndpoint endpt = null;//from  w w  w  . j av a2  s .  c om
    WindowsAzureEndpoint sessionAffEndPt = waRole.getSessionAffinityInputEndpoint();
    // check session affinity is already enabled, then consider same endpoint
    if (sessionAffEndPt != null) {
        // check port of session affinity endpoint
        String stSesPubPort = sessionAffEndPt.getPort();
        if (stSesPubPort.equalsIgnoreCase(String.valueOf(HTTP_PORT))) {
            // check 443 is already available on same role (input enpoint)
            WindowsAzureEndpoint httpsEndPt = WAEclipseHelperMethods.findEndpointWithPubPort(HTTPS_PORT,
                    waRole);
            if (httpsEndPt != null) {
                /*
                * If HTTPS endpoint with public port 443,
                * is present on same role then show warning
                */
                PluginUtil.displayWarningDialog(String.format(message("httpsPresentSt"), httpsEndPt.getName(),
                        httpsEndPt.getPort(), httpsEndPt.getName()), message("sslTtl"));
                endpt = null;
            } else {
                /*
                 * Check if 443 is used on same role (instance endpoint)
                 * or any other role
                 * if yes then consider 8443.
                 */
                int portToUse = HTTPS_PORT;
                if (WAEclipseHelperMethods.findRoleWithEndpntPubPort(HTTPS_PORT, waProjManager) != null) {
                    // need to use 8443
                    int pubPort = HTTPS_NXT_PORT;
                    while (!waProjManager.isValidPort(String.valueOf(pubPort),
                            WindowsAzureEndpointType.Input)) {
                        pubPort++;
                    }
                    portToUse = pubPort;
                }
                int choice = Messages.showYesNoDialog(
                        message("sslhttp").replace("${epName}", sessionAffEndPt.getName())
                                .replace("${pubPort}", String.valueOf(portToUse))
                                .replace("${privPort}", sessionAffEndPt.getPrivatePort()),
                        message("sslTtl"), Messages.getQuestionIcon());
                if (choice == Messages.YES) {
                    sessionAffEndPt.setPort(String.valueOf(portToUse));
                    endpt = sessionAffEndPt;
                } else {
                    // no button pressed
                    endpt = null;
                }
            }
        } else {
            // port is other than 80, then directly consider it.
            endpt = sessionAffEndPt;
        }
    } else {
        // check this role uses public port 443
        endpt = WAEclipseHelperMethods.findEndpointWithPubPort(HTTPS_PORT, waRole);
        if (endpt != null) {
            // endpoint on this role uses public port 443
            PluginUtil.displayWarningDialog(message("sslTtl"), message("sslWarnMsg"));
        } else {
            // check if another role uses 443 as a public port
            WindowsAzureRole roleWithHTTPS = WAEclipseHelperMethods.findRoleWithEndpntPubPort(HTTPS_PORT,
                    waProjManager);
            if (roleWithHTTPS != null) {
                // another role uses 443 as a public port
                // 1. If this role uses public port 80
                endpt = WAEclipseHelperMethods.findEndpointWithPubPort(HTTP_PORT, waRole);
                if (endpt != null) {
                    /*
                     * endpoint on this role uses public port 80
                     * and 443 has been used on some other role then set to 8443
                     * or some suitable public port
                     */
                    int pubPort = HTTPS_NXT_PORT;
                    while (!waProjManager.isValidPort(String.valueOf(pubPort),
                            WindowsAzureEndpointType.Input)) {
                        pubPort++;
                    }
                    int choice = Messages.showYesNoDialog(
                            message("sslhttp").replace("${epName}", endpt.getName())
                                    .replace("${pubPort}", String.valueOf(pubPort))
                                    .replace("${privPort}", endpt.getPrivatePort()),
                            message("sslTtl"), Messages.getQuestionIcon());
                    if (choice == Messages.YES) {
                        endpt.setPort(String.valueOf(pubPort));
                    } else {
                        // no button pressed
                        endpt = null;
                    }
                } else {
                    // 2. Ask for creating new endpoint
                    List<String> endPtData = WASSLOffloadingUtilMethods.prepareEndpt(HTTPS_NXT_PORT, waRole,
                            waProjManager);
                    int choice = Messages.showYesNoCancelDialog(String.format(message("sslNoHttp"),
                            endPtData.get(0), endPtData.get(1), endPtData.get(2)), message("sslTtl"),
                            Messages.getQuestionIcon());
                    if (choice == Messages.YES) {
                        endpt = waRole.addEndpoint(endPtData.get(0), WindowsAzureEndpointType.Input,
                                endPtData.get(2), endPtData.get(1));
                        setModified(true);
                    } else {
                        // no button pressed
                        endpt = null;
                    }
                }
            } else {
                // no public port 443 on this role, nor on other any role
                // 1. If this role uses public port 80
                endpt = WAEclipseHelperMethods.findEndpointWithPubPort(HTTP_PORT, waRole);
                if (endpt != null) {
                    // endpoint on this role uses public port 80
                    int choice = Messages.showYesNoDialog(
                            message("sslhttp").replace("${epName}", endpt.getName())
                                    .replace("${pubPort}", String.valueOf(HTTPS_PORT))
                                    .replace("${privPort}", endpt.getPrivatePort()),
                            message("sslTtl"), Messages.getQuestionIcon());
                    if (choice == Messages.YES) {
                        endpt.setPort(String.valueOf(HTTPS_PORT));
                    } else {
                        // no button pressed
                        endpt = null;
                    }
                } else {
                    // 2. Ask for creating new endpoint
                    List<String> endPtData = WASSLOffloadingUtilMethods.prepareEndpt(HTTPS_PORT, waRole,
                            waProjManager);
                    int choice = Messages.showYesNoDialog(String.format(message("sslNoHttp"), endPtData.get(0),
                            endPtData.get(1), endPtData.get(2)), message("sslTtl"), Messages.getQuestionIcon());
                    if (choice == Messages.YES) {
                        endpt = waRole.addEndpoint(endPtData.get(0), WindowsAzureEndpointType.Input,
                                endPtData.get(2), endPtData.get(1));
                        setModified(true);
                    } else {
                        // no button pressed
                        endpt = null;
                    }
                }
            }
        }
    }
    return endpt;
}

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

License:Apache License

/**
 * Listener method for remove button which
 * deletes the selected component./*from ww  w . jav a  2s. c om*/
 */
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.microsoftopentechnologies.intellij.ui.azureroles.SSLOffloadingPanel.java

License:Apache License

private WindowsAzureEndpoint findInputEndpt() throws WindowsAzureInvalidProjectOperationException {
    WindowsAzureEndpoint endpt = null;/* www . j av a 2 s .  c o m*/
    WindowsAzureEndpoint sessionAffEndPt = waRole.getSessionAffinityInputEndpoint();
    // check session affinity is already enabled, then consider same endpoint
    if (sessionAffEndPt != null) {
        // check port of session affinity endpoint
        String stSesPubPort = sessionAffEndPt.getPort();
        if (stSesPubPort.equalsIgnoreCase(String.valueOf(HTTP_PORT))) {
            // check 443 is already available on same role (input enpoint)
            WindowsAzureEndpoint httpsEndPt = WAEclipseHelperMethods.findEndpointWithPubPort(HTTPS_PORT,
                    waRole);
            if (httpsEndPt != null) {
                /*
                 * If HTTPS endpoint with public port 443,
                 * is present on same role then show warning
                 */
                PluginUtil.displayWarningDialog(String.format(message("httpsPresentSt"), httpsEndPt.getName(),
                        httpsEndPt.getPort(), httpsEndPt.getName()), message("sslTtl"));
                endpt = null;
            } else {
                /*
                 * Check if 443 is used on same role (instance endpoint)
                 * or any other role
                 * if yes then consider 8443.
                 */
                int portToUse = HTTPS_PORT;
                if (WAEclipseHelperMethods.findRoleWithEndpntPubPort(HTTPS_PORT, waProjManager) != null) {
                    // need to use 8443
                    int pubPort = HTTPS_NXT_PORT;
                    while (!waProjManager.isValidPort(String.valueOf(pubPort),
                            WindowsAzureEndpointType.Input)) {
                        pubPort++;
                    }
                    portToUse = pubPort;
                }
                int choice = Messages.showYesNoDialog(
                        message("sslhttp").replace("${epName}", sessionAffEndPt.getName())
                                .replace("${pubPort}", String.valueOf(portToUse))
                                .replace("${privPort}", sessionAffEndPt.getPrivatePort()),
                        message("sslTtl"), Messages.getQuestionIcon());
                if (choice == Messages.YES) {
                    sessionAffEndPt.setPort(String.valueOf(portToUse));
                    endpt = sessionAffEndPt;
                } else {
                    // no button pressed
                    endpt = null;
                }
            }
        } else {
            // port is other than 80, then directly consider it.
            endpt = sessionAffEndPt;
        }
    } else {
        // check this role uses public port 443
        endpt = WAEclipseHelperMethods.findEndpointWithPubPort(HTTPS_PORT, waRole);
        if (endpt != null) {
            // endpoint on this role uses public port 443
            PluginUtil.displayWarningDialog(message("sslTtl"), message("sslWarnMsg"));
        } else {
            // check if another role uses 443 as a public port
            WindowsAzureRole roleWithHTTPS = WAEclipseHelperMethods.findRoleWithEndpntPubPort(HTTPS_PORT,
                    waProjManager);
            if (roleWithHTTPS != null) {
                // another role uses 443 as a public port
                // 1. If this role uses public port 80
                endpt = WAEclipseHelperMethods.findEndpointWithPubPort(HTTP_PORT, waRole);
                if (endpt != null) {
                    /*
                     * endpoint on this role uses public port 80
                     * and 443 has been used on some other role then set to 8443
                     * or some suitable public port
                     */
                    int pubPort = HTTPS_NXT_PORT;
                    while (!waProjManager.isValidPort(String.valueOf(pubPort),
                            WindowsAzureEndpointType.Input)) {
                        pubPort++;
                    }
                    int choice = Messages.showYesNoDialog(
                            message("sslhttp").replace("${epName}", endpt.getName())
                                    .replace("${pubPort}", String.valueOf(pubPort))
                                    .replace("${privPort}", endpt.getPrivatePort()),
                            message("sslTtl"), Messages.getQuestionIcon());
                    if (choice == Messages.YES) {
                        endpt.setPort(String.valueOf(pubPort));
                    } else {
                        // no button pressed
                        endpt = null;
                    }
                } else {
                    // 2. Ask for creating new endpoint
                    List<String> endPtData = WASSLOffloadingUtilMethods.prepareEndpt(HTTPS_NXT_PORT, waRole,
                            waProjManager);
                    int choice = Messages.showYesNoCancelDialog(String.format(message("sslNoHttp"),
                            endPtData.get(0), endPtData.get(1), endPtData.get(2)), message("sslTtl"),
                            Messages.getQuestionIcon());
                    if (choice == Messages.YES) {
                        endpt = waRole.addEndpoint(endPtData.get(0), WindowsAzureEndpointType.Input,
                                endPtData.get(2), endPtData.get(1));
                        setModified(true);
                    } else {
                        // no button pressed
                        endpt = null;
                    }
                }
            } else {
                // no public port 443 on this role, nor on other any role
                // 1. If this role uses public port 80
                endpt = WAEclipseHelperMethods.findEndpointWithPubPort(HTTP_PORT, waRole);
                if (endpt != null) {
                    // endpoint on this role uses public port 80
                    int choice = Messages.showYesNoDialog(
                            message("sslhttp").replace("${epName}", endpt.getName())
                                    .replace("${pubPort}", String.valueOf(HTTPS_PORT))
                                    .replace("${privPort}", endpt.getPrivatePort()),
                            message("sslTtl"), Messages.getQuestionIcon());
                    if (choice == Messages.YES) {
                        endpt.setPort(String.valueOf(HTTPS_PORT));
                    } else {
                        // no button pressed
                        endpt = null;
                    }
                } else {
                    // 2. Ask for creating new endpoint
                    List<String> endPtData = WASSLOffloadingUtilMethods.prepareEndpt(HTTPS_PORT, waRole,
                            waProjManager);
                    int choice = Messages.showYesNoDialog(String.format(message("sslNoHttp"), endPtData.get(0),
                            endPtData.get(1), endPtData.get(2)), message("sslTtl"), Messages.getQuestionIcon());
                    if (choice == Messages.YES) {
                        endpt = waRole.addEndpoint(endPtData.get(0), WindowsAzureEndpointType.Input,
                                endPtData.get(2), endPtData.get(1));
                        setModified(true);
                    } else {
                        // no button pressed
                        endpt = null;
                    }
                }
            }
        }
    }
    return endpt;
}

From source file:generate.tostring.view.MethodExistsDialog.java

License:Apache License

/**
 * Shows this dialog.//from  w  w  w  . ja  v  a 2 s  . c o m
 * <p/>
 * The user now has the choices to either:
 * <ul>
 *    <li/>Replace existing method
 *    <li/>Create a duplicate method
 *    <li/>Cancel
 * </ul>
 *
 * @param targetMethodName   the name of the target method (toString)
 * @return the chosen conflict resolution policy (never null)
 */
public static ConflictResolutionPolicy showDialog(String targetMethodName) {
    int exit = Messages.showYesNoCancelDialog("Replace existing " + targetMethodName + " method",
            "Method Already Exists", Messages.getQuestionIcon());
    if (exit == JOptionPane.CLOSED_OPTION || exit == JOptionPane.CANCEL_OPTION) {
        return CancelPolicy.getInstance();
    } else if (exit == JOptionPane.YES_OPTION) {
        return ReplacePolicy.getInstance();
    } else if (exit == JOptionPane.NO_OPTION) {
        return DuplicatePolicy.getInstance();
    }

    throw new IllegalArgumentException("exit code [" + exit + "] from YesNoCancelDialog not supported");
}