Java Code Examples for com.intellij.openapi.ui.Messages#showMessageDialog()

The following examples show how to use com.intellij.openapi.ui.Messages#showMessageDialog() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PsiViewerDialog.java    From consulo with Apache License 2.0 6 votes vote down vote up
private PsiElement parseText(String text) {
  final Object source = getSource();
  try {
    if (source instanceof PsiViewerExtension) {
      return ((PsiViewerExtension)source).createElement(myProject, text);
    }
    if (source instanceof FileType) {
      final FileType type = (FileType)source;
      String ext = type.getDefaultExtension();
      if (myExtensionComboBox.isVisible()) {
        ext = myExtensionComboBox.getSelectedItem().toString().toLowerCase();
      }
      if (type instanceof LanguageFileType) {
        final Language language = ((LanguageFileType)type).getLanguage();
        final LanguageVersion languageVersion = (LanguageVersion)myDialectComboBox.getSelectedItem();
        return PsiFileFactory.getInstance(myProject).createFileFromText("Dummy." + ext, language, languageVersion, text);
      }
      return PsiFileFactory.getInstance(myProject).createFileFromText("Dummy." + ext, type, text);
    }
  }
  catch (IncorrectOperationException e) {
    Messages.showMessageDialog(myProject, e.getMessage(), "Error", Messages.getErrorIcon());
  }
  return null;
}
 
Example 2
Source File: UndoableGroup.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void reportUndoProblem(UnexpectedUndoException e, boolean isUndo) {
  String title;
  String message;

  if (isUndo) {
    title = CommonBundle.message("cannot.undo.dialog.title");
    message = CommonBundle.message("cannot.undo.message");
  }
  else {
    title = CommonBundle.message("cannot.redo.dialog.title");
    message = CommonBundle.message("cannot.redo.message");
  }

  if (!ApplicationManager.getApplication().isUnitTestMode()) {
    if (e.getMessage() != null) {
      message += ".\n" + e.getMessage();
    }
    Messages.showMessageDialog(myProject, message, title, Messages.getErrorIcon());
  }
  else {
    LOG.error(e);
  }
}
 
Example 3
Source File: HTMLExportUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void writeFile(final String folder, @NonNls final String fileName, CharSequence buf, final Project project) {
  try {
    HTMLExporter.writeFileImpl(folder, fileName, buf);
  }
  catch (IOException e) {
    Runnable showError = new Runnable() {
      @Override
      public void run() {
        final String fullPath = folder + File.separator + fileName;
        Messages.showMessageDialog(
          project,
          InspectionsBundle.message("inspection.export.error.writing.to", fullPath),
          InspectionsBundle.message("inspection.export.results.error.title"),
          Messages.getErrorIcon()
        );
      }
    };
    ApplicationManager.getApplication().invokeLater(showError, ModalityState.NON_MODAL);
    throw new ProcessCanceledException();
  }
}
 
Example 4
Source File: PhpBundleFileFactory.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Nullable
public static PsiElement invokeCreateCompilerPass(@NotNull PhpClass bundleClass, @Nullable Editor editor) {
    String className = Messages.showInputDialog("Class name for CompilerPass (no namespace needed): ", "New File", Symfony2Icons.SYMFONY);
    if(StringUtils.isBlank(className)) {
        return null;
    }

    if(!PhpNameUtil.isValidClassName(className)) {
        Messages.showMessageDialog(bundleClass.getProject(), "Invalid class name", "Error", Symfony2Icons.SYMFONY);
    }

    try {
        return PhpBundleFileFactory.createCompilerPass(bundleClass, className);
    } catch (Exception e) {
        if(editor != null) {
            HintManager.getInstance().showErrorHint(editor, "Error:" + e.getMessage());
        } else {
            JOptionPane.showMessageDialog(null, "Error:" + e.getMessage());
        }
    }

    return null;
}
 
Example 5
Source File: SingleConfigurableEditor.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
@RequiredUIAccess
protected void doOKAction() {
  try {
    if (myConfigurable.isModified()) myConfigurable.apply();

    ApplicationManager.getApplication().saveAll();
  }
  catch (ConfigurationException e) {
    if (e.getMessage() != null) {
      if (myProject != null) {
        Messages.showMessageDialog(myProject, e.getMessage(), e.getTitle(), Messages.getErrorIcon());
      }
      else {
        Messages.showMessageDialog(myParentComponent, e.getMessage(), e.getTitle(), Messages.getErrorIcon());
      }
    }
    return;
  }
  super.doOKAction();
}
 
Example 6
Source File: PropertyTable.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void showInvalidInput(Exception e) {
  Throwable cause = e.getCause();
  String message = cause == null ? e.getMessage() : cause.getMessage();

  if (message == null || message.length() == 0) {
    message = "No message";
  }

  Messages.showMessageDialog(formatErrorGettingValueMesage(message),
                             "Invalid Input",
                             Messages.getErrorIcon());
}
 
Example 7
Source File: StatisticsManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean createStoreFolder(){
  File homeFile = new File(STORE_PATH);
  if (!homeFile.exists()){
    if (!homeFile.mkdirs()){
      Messages.showMessageDialog(
              IdeBundle.message("error.saving.statistic.failed.to.create.folder", STORE_PATH),
              CommonBundle.getErrorTitle(),
              Messages.getErrorIcon()
      );
      return false;
    }
  }
  return true;
}
 
Example 8
Source File: FilterDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void doOKAction() {

  // Validate filter name

  myFilter.setName(myNameField.getText().trim());
  if (myFilter.getName().length() == 0) {
    Messages.showMessageDialog(myTable,
                               IdeBundle.message("error.filter.name.should.be.specified"),
                               CommonBundle.getErrorTitle(),
                               Messages.getErrorIcon());
    return;
  }
  for (int i = 0; i < myFilters.size(); i++) {
    TodoFilter filter = myFilters.get(i);
    if (myFilterIndex != i && myFilter.getName().equals(filter.getName())) {
      Messages.showMessageDialog(myTable,
                                 IdeBundle.message("error.filter.with.the.same.name.already.exists"),
                                 CommonBundle.getErrorTitle(),
                                 Messages.getErrorIcon());
      return;
    }
  }

  // Validate that at least one pettern is selected

  if (myFilter.isEmpty()) {
    Messages.showMessageDialog(myTable,
                               IdeBundle.message("error.filter.should.contain.at.least.one.pattern"),
                               CommonBundle.getErrorTitle(),
                               Messages.getErrorIcon());
    return;
  }

  super.doOKAction();
}
 
Example 9
Source File: CompileDriver.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void showNotSpecifiedError(@NonNls final String resourceId, List<String> modules, String editorNameToSelect) {
  String nameToSelect = null;
  final StringBuilder names = StringBuilderSpinAllocator.alloc();
  final String message;
  try {
    final int maxModulesToShow = 10;
    for (String name : modules.size() > maxModulesToShow ? modules.subList(0, maxModulesToShow) : modules) {
      if (nameToSelect == null) {
        nameToSelect = name;
      }
      if (names.length() > 0) {
        names.append(",\n");
      }
      names.append("\"");
      names.append(name);
      names.append("\"");
    }
    if (modules.size() > maxModulesToShow) {
      names.append(",\n...");
    }
    message = CompilerBundle.message(resourceId, modules.size(), names.toString());
  }
  finally {
    StringBuilderSpinAllocator.dispose(names);
  }

  if (ApplicationManager.getApplication().isUnitTestMode()) {
    LOG.error(message);
  }

  Messages.showMessageDialog(myProject, message, CommonBundle.getErrorTitle(), Messages.getErrorIcon());
  showConfigurationDialog(nameToSelect, editorNameToSelect);
}
 
Example 10
Source File: PsiNavigationDemoAction.java    From intellij-sdk-docs with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent anActionEvent) {
    Editor editor = anActionEvent.getData(CommonDataKeys.EDITOR);
    PsiFile psiFile = anActionEvent.getData(CommonDataKeys.PSI_FILE);
    if (editor == null || psiFile == null) return;
    int offset = editor.getCaretModel().getOffset();

    final StringBuilder infoBuilder = new StringBuilder();
    PsiElement element = psiFile.findElementAt(offset);
    infoBuilder.append("Element at caret: ").append(element).append("\n");
    if (element != null) {
        PsiMethod containingMethod = PsiTreeUtil.getParentOfType(element, PsiMethod.class);
        infoBuilder
                .append("Containing method: ")
                .append(containingMethod != null ? containingMethod.getName() : "none")
                .append("\n");
        if (containingMethod != null) {
            PsiClass containingClass = containingMethod.getContainingClass();
            infoBuilder
                    .append("Containing class: ")
                    .append(containingClass != null ? containingClass.getName() : "none")
                    .append("\n");

            infoBuilder.append("Local variables:\n");
            containingMethod.accept(new JavaRecursiveElementVisitor() {
                @Override
                public void visitLocalVariable(PsiLocalVariable variable) {
                    super.visitLocalVariable(variable);
                    infoBuilder.append(variable.getName()).append("\n");
                }
            });
        }
    }
    Messages.showMessageDialog(anActionEvent.getProject(), infoBuilder.toString(), "PSI Info", null);
}
 
Example 11
Source File: SlackSettings.java    From SlackStorm with GNU General Public License v2.0 5 votes vote down vote up
public void actionPerformed(AnActionEvent e) {
    this.project = e.getData(CommonDataKeys.PROJECT);

    String description = this.showInputDialog(SlackChannel.getIdDescription(), null);

    if (!isValidField(description)) {
        errorMessage();
        return;
    }

    String userAlias = this.showInputDialog(SlackChannel.getSenderNameDescription(), SlackChannel.getSenderNameDefaultValue());

    if (!isValidField(userAlias)) {
        errorMessage();
        return;
    }

    String icon = this.showInputDialog(SlackChannel.getSenderIconDescription(), SlackChannel.getDefaultSenderIcon());

    if (!isValidField(icon)) {
        errorMessage();
        return;
    }

    String channel = this.showInputDialog(SlackChannel.getChanneNameDescription(), "");

    String token = this.showInputDialog(SlackChannel.getTokenDescription(), null);

    if (!isValidField(token)) {
        errorMessage();
        return;
    }

    // Here all is good, we can create the channel
    SlackStorage.getInstance().registerChannel(new SlackChannel(token, description, userAlias, icon, channel));
    Messages.showMessageDialog(this.project, "Settings Saved.", "Information", Messages.getInformationIcon());
}
 
Example 12
Source File: CreateFromTemplateDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void doOKAction() {
  String fileName = myAttrPanel.getFileName();
  if (fileName != null && fileName.length() == 0) {
    Messages.showMessageDialog(myAttrComponent, IdeBundle.message("error.please.enter.a.file.name"), CommonBundle.getErrorTitle(), Messages.getErrorIcon());
    return;
  }
  doCreate(fileName);
  if (myCreatedElement != null) {
    super.doOKAction();
  }
}
 
Example 13
Source File: DownloadExerciseAction.java    From tmc-intellij with MIT License 5 votes vote down vote up
public void downloadExercises(Project project, boolean downloadAll) {
    logger.info("Performing DownloadExerciseAction. @DownloadExerciseAction");
    try {
        startDownloadExercise(project, downloadAll);
    } catch (Exception exception) {
        logger.warn("Downloading failed. @DownloadExerciseAction", exception);
        Messages.showMessageDialog(
                project,
                "Downloading failed \n"
                        + "Are your account details correct?\n"
                        + exception.getMessage(),
                "Result",
                Messages.getErrorIcon());
    }
}
 
Example 14
Source File: SlackSettings.java    From SlackStorm with GNU General Public License v2.0 5 votes vote down vote up
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    // Prompt since we are killing ALL
    if (Messages.showYesNoDialog(project, "This will clear all of your channels settings", "Slack Settings", SlackStorage.getSlackIcon()) == 0) {
        SlackStorage.getInstance().clearAll();
        Messages.showMessageDialog(project, "Settings cleared.", "Information", Messages.getInformationIcon());
    }
}
 
Example 15
Source File: SlackSettings.java    From SlackStorm with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    SlackStorage slackStorage = SlackStorage.getInstance();

    List<String> channelsId = SlackStorage.getInstance().getChannelsId();

    if (channelsId.size() > 0) {
        String channelToUpdate = Messages.showEditableChooseDialog(
                "Select the channel to edit",
                SlackChannel.getSettingsDescription(),
                SlackStorage.getSlackIcon(),
                channelsId.toArray(new String[channelsId.size()]),
                channelsId.get(0),
                null
        );

        if (channelsId.contains(channelToUpdate)) {
            // Load the channel
            SlackChannel selectedChannel = slackStorage.getSlackChannelByDescription(channelToUpdate);

            String description = this.showInputDialog(SlackChannel.getIdDescription(), selectedChannel.getId());
            if (!isValidField(description)) {
                errorMessage();
                return;
            }

            String userAlias = this.showInputDialog(SlackChannel.getSenderNameDescription(), selectedChannel.senderName);

            if (!isValidField(userAlias)) {
                errorMessage();
                return;
            }

            String icon = this.showInputDialog(SlackChannel.getSenderIconDescription(), selectedChannel.senderIcon);

            if (!isValidField(icon)) {
                errorMessage();
                return;
            }

            String channel = this.showInputDialog(SlackChannel.getChanneNameDescription(), selectedChannel.channelName);

            String token = this.showInputDialog(SlackChannel.getTokenDescription(), selectedChannel.token);

            if (!isValidField(token)) {
                errorMessage();
                return;
            }

            // To update, we just remove and add since the ID can change
            SlackStorage.getInstance().removeChannelByDescription(channelToUpdate);
            SlackStorage.getInstance().registerChannel(new SlackChannel(token, description, userAlias, icon, channel));
            Messages.showMessageDialog(project, "Channel \"" + channelToUpdate + "\" updated.", "Information", Messages.getInformationIcon());
        }
    }
}
 
Example 16
Source File: SelectedBlockHistoryAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected static void reportError(Exception exception) {
  Messages.showMessageDialog(exception.getLocalizedMessage(), VcsBundle.message("message.title.could.not.load.file.history"), Messages.getErrorIcon());
}
 
Example 17
Source File: CreateFromTemplateDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void showErrorDialog(final Exception e) {
  LOG.info(e);
  Messages.showMessageDialog(myProject, filterMessage(e.getMessage()), getErrorMessage(), Messages.getErrorIcon());
}
 
Example 18
Source File: TextBoxes.java    From patcher with Apache License 2.0 4 votes vote down vote up
public void actionPerformed(AnActionEvent event) {
    Project project = event.getData(PlatformDataKeys.PROJECT);
    String txt = Messages.showInputDialog(project, "What is your name?", "Input your name", Messages.getQuestionIcon());
    Messages.showMessageDialog(project, "Hello, " + txt + "!\n I am glad to see you.", "Information", Messages.getInformationIcon());
}
 
Example 19
Source File: LafManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void setCurrentLookAndFeel(UIManager.LookAndFeelInfo lookAndFeelInfo, boolean fire) {
  if (findLaf(lookAndFeelInfo.getClassName()) == null) {
    LOG.error("unknown LookAndFeel : " + lookAndFeelInfo);
    return;
  }
  try {
    JBColor.resetDark();

    IconLoader.resetDark();

    UIModificationTracker.getInstance().incModificationCount();

    ClassLoader targetClassLoader = null;
    if (lookAndFeelInfo instanceof LookAndFeelInfoWithClassLoader) {
      targetClassLoader = ((LookAndFeelInfoWithClassLoader)lookAndFeelInfo).getClassLoader();
      UIManager.setLookAndFeel(newInstance((LookAndFeelInfoWithClassLoader)lookAndFeelInfo));
    }
    else {
      UIManager.setLookAndFeel(lookAndFeelInfo.getClassName());
    }

    if (targetClassLoader != null) {
      final UIDefaults uiDefaults = UIManager.getLookAndFeelDefaults();

      uiDefaults.put("ClassLoader", targetClassLoader);
    }

    if (SystemInfo.isMacOSYosemite) {
      installMacOSXFonts(UIManager.getLookAndFeelDefaults());
    }

    if (fire) {
      fireUpdate();
    }
  }
  catch (Exception e) {
    LOG.error(e);
    Messages.showMessageDialog(IdeBundle.message("error.cannot.set.look.and.feel", lookAndFeelInfo.getName(), e.getMessage()), CommonBundle.getErrorTitle(), Messages.getErrorIcon());
    return;
  }
  myCurrentLaf = lookAndFeelInfo;
}
 
Example 20
Source File: NotificationUtils.java    From freeline with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * error message dialog
 * @param message
 */
public static void errorMsgDialog(String message) {
    Messages.showMessageDialog(message, "Error", Messages.getInformationIcon());
}