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

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

Introduction

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

Prototype

public static void showWarningDialog(String message,
        @NotNull @Nls(capitalization = Nls.Capitalization.Title) String title) 

Source Link

Document

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

Usage

From source file:com.thoughtworks.gauge.rename.CustomRenameHandler.java

License:Open Source License

public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
    PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
    if (element == null)
        element = psiElement;//from   w  w  w.j  a v  a2 s  .  co m
    psiElement = element;
    String text = element.toString();

    //Finding text from annotation
    if (isMethod(element)) {
        List<String> values = StepUtil.getGaugeStepAnnotationValues((PsiMethod) element);
        if (values.size() == 0) {
            return;
        } else if (values.size() == 1)
            text = values.get(0);
        else if (values.size() > 1) {
            Messages.showWarningDialog("Refactoring for steps having aliases are not supported", "Warning");
            return;
        }
    } else if (isStep(element)) {
        text = ((SpecStepImpl) element).getStepValue().getStepAnnotationText();
    } else if (isConcept(element)) {
        text = removeIdentifiers(((ConceptStepImpl) element).getStepValue().getStepAnnotationText());
    }
    final RefactoringDialog form = new RefactoringDialog(this.editor.getProject(), file, this.editor, text);
    form.show();
}

From source file:com.wakatime.intellij.plugin.WakaTime.java

private void checkDebug() {
    if (WakaTime.DEBUG) {
        try {// ww w .ja v a  2  s  .c  om
            Messages.showWarningDialog(
                    "Running WakaTime in DEBUG mode. Your IDE may be slow when saving or editing files.",
                    "Debug");
        } catch (NullPointerException e) {
        }
    }
}

From source file:generate.tostring.GenerateToStringActionHandlerImpl.java

License:Apache License

/**
 * Entry for performing the action and code generation.
 *
 * @param project         the project, must not be <tt>null<tt>
 * @param clazz           the class, must not be <tt>null<tt>
 * @param quickTemplate   use this quick template, if <tt>null</tt> then the default template is used
 * @param insertPolicy    overrule to use this policy (usually by quickfix), <tt>null</tt> to use default
 *//*from   w w  w.  j a  v  a 2 s.  c o  m*/
private void doExecuteAction(@NotNull final Project project, @NotNull final PsiClass clazz,
        final TemplateResource quickTemplate, final InsertNewMethodPolicy insertPolicy) {
    logger.debug("+++ doExecuteAction - START +++");

    if (logger.isDebugEnabled()) {
        logger.debug("Current project " + project.getName());
    }

    // set all instance variabels
    this.project = project;
    this.clazz = clazz;
    this.psi = PsiAdapterFactory.getPsiAdapter();
    this.javaFile = psi.getSelectedJavaFile(project, psi.getPsiManager(project));
    this.config = GenerateToStringContext.getConfig();
    this.editor = psi.getSelectedEditor(project);
    this.manager = psi.getPsiManager(project);
    this.elementFactory = psi.getPsiElemetFactory(manager);
    this.codeStyleManager = psi.getCodeStyleManager(project);

    if (quickTemplate == null && config.isEnableTemplateQuickList()) {
        // display quick template dialog
        if (displayQuickTemplateDialog(insertPolicy)) {
            return; // return as the qucik template will execute this action again with the selected body to use
        }
    }

    // should we use quick template or default active template
    final TemplateResource template = (quickTemplate == null
            ? GenerateToStringContext.getConfig().getActiveTemplate()
            : quickTemplate);

    // is it a valid template
    if (!template.isValidTemplate()) {
        Messages.showWarningDialog(
                "The template is incompatible with this version of the plugin. See the default templates for compatible samples.",
                "Incompatible Template");
        return;
    }

    try {
        PsiField[] filteredFields = GenerateToStringUtils.filterAvailableFields(project, psi, elementFactory,
                clazz, config.getFilterPattern());
        if (logger.isDebugEnabled())
            logger.debug("Number of fields after filtering: " + filteredFields.length);

        PsiMethod[] filteredMethods = new PsiMethod[0];
        if (config.enableMethods) {
            // filter methods as it is enabled from config
            filteredMethods = GenerateToStringUtils.filterAvailableMethods(psi, elementFactory, clazz,
                    config.getFilterPattern());
            if (logger.isDebugEnabled())
                logger.debug("Number of methods after filtering: " + filteredMethods.length);
        }

        if (displayMememberChooser(filteredFields.length, filteredMethods.length, template)) {
            logger.debug("Displaying member chooser dialog");
            PsiElementClassMember[] dialogMembers = GenerateToStringUtils
                    .combineToClassMemberList(filteredFields, filteredMethods);
            final MemberChooser dialog = new MemberChooser(dialogMembers, true, true, project, false);
            // 1nd boolean is ???
            // 2nd boolean is to preselect all members or none
            // last boolean is to show/hide Insert @Override option in dialog
            dialog.setCopyJavadocVisible(false);
            dialog.selectElements(dialogMembers);
            dialog.setTitle("Choose Members for " + template.getTargetMethodName());
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    dialog.show();
                    if (MemberChooser.CANCEL_EXIT_CODE == dialog.getExitCode()) {
                        return; // stop action, since user clicked cancel in dialog
                    }
                    Collection<PsiMember> selectedMembers = GenerateToStringUtils
                            .convertClassMembersToPsiMembers(dialog.getSelectedElements());
                    executeGenerateActionLater(selectedMembers, template, insertPolicy);
                }
            });
        } else {
            // no dialog, so select all fields (filtered) and methods (filtered)
            logger.debug(
                    "Member chooser dialog not used - either disabled in settings or no fields/methods to select after filtering");

            Collection<PsiMember> selectedMembers = Arrays
                    .asList(GenerateToStringUtils.combineToMemberList(filteredFields, filteredMethods));
            executeGenerateAction(selectedMembers, template, insertPolicy);
        }
    } catch (IncorrectOperationException e) {
        GenerateToStringUtils.handleExeption(project, e);
    } catch (GenerateCodeException e) {
        GenerateToStringUtils.handleExeption(project, e);
    }

    logger.debug("+++ doExecuteAction - END +++");
}

From source file:io.ballerina.plugins.idea.actions.BallerinaCreateFileAction.java

License:Open Source License

@Override
protected void buildDialog(Project project, PsiDirectory directory,
        @NotNull CreateFileFromTemplateDialog.Builder builder) {

    if (directory.getName().equals(BALLERINA_SRC_DIR_NAME)) {
        Messages.showWarningDialog(
                "In a project, ballerina source files can only reside within ballerina " + "modules.",
                "Warning");
    }/*  www .  jav  a  2 s  .co m*/
    builder.setTitle(NEW_BALLERINA_FILE).addKind(BALLERINA_MAIN, BallerinaIcons.ICON, BALLERINA_MAIN)
            .addKind(BALLERINA_SERVICE, BallerinaIcons.ICON, BALLERINA_SERVICE)
            .addKind(BALLERINA_EMPTY_FILE, BallerinaIcons.ICON, BALLERINA_EMPTY_FILE);
}

From source file:org.sonarlint.intellij.tasks.ServerUpdateTask.java

License:Open Source License

public void run(@NotNull ProgressIndicator indicator) {
    indicator.setText("Fetching data...");

    try {/*from  ww  w.j av  a 2 s. co  m*/
        TaskProgressMonitor monitor = new TaskProgressMonitor(indicator);
        ServerConfiguration serverConfiguration = SonarLintUtils.getServerConfiguration(server);

        if (!onlyModules) {
            UpdateResult updateResult = engine.update(serverConfiguration, monitor);
            Collection<SonarAnalyzer> tooOld = updateResult.analyzers().stream()
                    .filter(SonarAnalyzer::sonarlintCompatible).filter(ServerUpdateTask::tooOld)
                    .collect(Collectors.toList());
            if (!tooOld.isEmpty()) {
                ApplicationManager.getApplication().invokeAndWait(() -> Messages
                        .showWarningDialog(buildMinimumVersionFailMessage(tooOld), "Analyzers Not Loaded"),
                        ModalityState.any());
            }
            log.log("Server binding '" + server.getName() + "' updated", LogOutput.Level.INFO);
        }

        updateModules(serverConfiguration, monitor);

    } catch (CanceledException e) {
        LOGGER.info("Update of server '" + server.getName() + "' was cancelled");
        log.log("Update of server '" + server.getName() + "' was cancelled", LogOutput.Level.INFO);
    } catch (Exception e) {
        LOGGER.info("Error updating from server '" + server.getName() + "'", e);
        final String msg = (e.getMessage() != null) ? e.getMessage()
                : ("Failed to update binding for server configuration '" + server.getName() + "'");
        ApplicationManager.getApplication().invokeAndWait(new RunnableAdapter() {
            @Override
            public void doRun() throws Exception {
                Messages.showErrorDialog((Project) null, msg, "Update Failed");
            }
        }, ModalityState.any());
    }
}

From source file:org.stepik.plugin.collective.ui.StepikSettingsPanel.java

License:Apache License

public StepikSettingsPanel() {
    initProjectOfSettings();//from w  w  w  . ja v  a 2s .  c  om
    //        myEmailTextField.setText(StudyTaskManager.getInstance(settingsProject).getUser().getEmail());
    mySignupTextField.addHyperlinkListener(new HyperlinkAdapter() {
        @Override
        protected void hyperlinkActivated(final HyperlinkEvent e) {
            BrowserUtil.browse(e.getURL());
        }
    });
    magicButton.setText("Magic auth");
    mySignupTextField
            .setText("<html>Do not have an account at stepik.org? <a href=\"https://stepik.org/registration\">"
                    + "Sign up" + "</a></html>");
    mySignupTextField.setBackground(myPane.getBackground());
    mySignupTextField.setCursor(new Cursor(Cursor.HAND_CURSOR));
    myAuthTypeLabel.setBorder(JBUI.Borders.emptyLeft(10));
    myAuthTypeComboBox.addItem(AUTH_PASSWORD);
    //        TODO later
    //        myAuthTypeComboBox.addItem(AUTH_TOKEN);
    //        final Project project = ProjectManager.getInstance().getDefaultProject();

    myTestButton.addActionListener(e -> {
        StudyTaskManager manager = StudyTaskManager.getInstance(settingsProject);
        StepikUser oldUser = manager.getUser();
        StepikUser testUser = new StepikUser(getEmail(), getPassword());
        manager.setUser(testUser);
        if (StepikConnectorLogin.loginFromSettings(settingsProject, testUser)) {
            String message = "Hello, " + manager.getUser().getName() + "!\n I am glad to see you.";
            Messages.showMessageDialog(message, "Check credentials", Messages.getInformationIcon());
        } else {
            Messages.showWarningDialog("Can't sign in.", "Check credentials");
        }
        manager.setUser(oldUser);
    });

    myPasswordField.getDocument().addDocumentListener(new DocumentAdapter() {
        @Override
        protected void textChanged(DocumentEvent e) {
            myCredentialsModified = true;
        }
    });

    DocumentListener passwordEraser = new DocumentAdapter() {
        @Override
        protected void textChanged(DocumentEvent e) {
            if (!myCredentialsModified) {
                erasePassword();
            }
        }
    };
    myEmailTextField.getDocument().addDocumentListener(passwordEraser);

    myPasswordField.addFocusListener(new FocusListener() {
        @Override
        public void focusGained(FocusEvent e) {
            if (!myCredentialsModified && !getPassword().isEmpty()) {
                erasePassword();
            }
        }

        @Override
        public void focusLost(FocusEvent e) {
        }
    });

    myAuthTypeComboBox.addItemListener(e -> {
        if (e.getStateChange() == ItemEvent.SELECTED) {
            String item = e.getItem().toString();
            if (AUTH_PASSWORD.equals(item)) {
                ((CardLayout) myCardPanel.getLayout()).show(myCardPanel, AUTH_PASSWORD);
            } else if (AUTH_TOKEN.equals(item)) {
                ((CardLayout) myCardPanel.getLayout()).show(myCardPanel, AUTH_TOKEN);
            }
            erasePassword();
        }
    });
}

From source file:org.stepik.plugin.collective.ui.StepikSettingsPanel.java

License:Apache License

public void apply() {
    if (myCredentialsModified) {
        initProjectOfSettings();/*from   w ww.jav a2s . c o  m*/
        StudyTaskManager manager = StudyTaskManager.getInstance(settingsProject);
        StepikUser basicUser = new StepikUser(getEmail(), getPassword());
        manager.setUser(basicUser);

        if (!StepikConnectorLogin.loginFromSettings(settingsProject, basicUser)) {
            Messages.showWarningDialog("Can't sign in.", "Check credentials");
        }
        LOG.info(manager.getUser().toString());
    }
    resetCredentialsModification();
}