com.intellij.openapi.ui.MessageDialogBuilder Java Examples

The following examples show how to use com.intellij.openapi.ui.MessageDialogBuilder. 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: TableInfoServiceImpl.java    From EasyCode with MIT License 6 votes vote down vote up
/**
 * 类型校验,如果存在未知类型则引导用于去条件类型
 *
 * @param dbTable 原始表对象
 * @return 是否验证通过
 */
@Override
public boolean typeValidator(DbTable dbTable) {
    // 处理所有列
    JBIterable<? extends DasColumn> columns = DasUtil.getColumns(dbTable);
    List<TypeMapper> typeMapperList = CurrGroupUtils.getCurrTypeMapperGroup().getElementList();

    FLAG:
    for (DasColumn column : columns) {
        String typeName = column.getDataType().getSpecification();
        for (TypeMapper typeMapper : typeMapperList) {
            // 不区分大小写查找类型
            if (Pattern.compile(typeMapper.getColumnType(), Pattern.CASE_INSENSITIVE).matcher(typeName).matches()) {
                continue FLAG;
            }
        }
        // 没找到类型,引导用户去添加类型
        if (MessageDialogBuilder.yesNo(MsgValue.TITLE_INFO, String.format("数据库类型%s,没有找到映射关系,是否去添加?", typeName)).isYes()) {
            ShowSettingsUtil.getInstance().showSettingsDialog(project, "Type Mapper");
            return false;
        }
        // 用户取消添加
        return true;
    }
    return true;
}
 
Example #2
Source File: CSharpFindUsageHandler.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
@RequiredReadAction
public PsiElement[] getPrimaryElements()
{
	PsiElement psiElement = getPsiElement();
	if(OverrideUtil.isAllowForOverride(psiElement))
	{
		Collection<DotNetVirtualImplementOwner> members = OverrideUtil.collectOverridingMembers((DotNetVirtualImplementOwner) psiElement);
		if(!members.isEmpty())
		{
			MessageDialogBuilder.YesNo builder = MessageDialogBuilder.yesNo("Find Usage", "Search for base target ir current target?");
			builder = builder.yesText("Base Target");
			builder = builder.noText("This Target");

			if(builder.show() == Messages.OK)
			{
				return PsiUtilCore.toPsiElementArray(members);
			}
		}
	}
	return super.getPrimaryElements();
}
 
Example #3
Source File: LoginAction.java    From SmartIM4IntelliJ with Apache License 2.0 5 votes vote down vote up
@Override public void actionPerformed(AnActionEvent anActionEvent) {
    SmartClient client = imPanel.getClient();
    boolean ok = true;
    if (client.isLogin()) {
        ok = MessageDialogBuilder.yesNo("", "您已处于登录状态,确定要重新登录吗?").show() == 0;
    }
    if (ok) {
        client.setLoginCallback(new MyLoginCallback(client, imPanel));
        new Thread() {
            @Override public void run() {
                client.login();
            }
        }.start();
    } else {
        imPanel.initContacts();
    }
    //
    //        LoginDialog dialog = new LoginDialog(client);
    //        dialog.setSize(200, 240);
    //        dialog.setLocationRelativeTo(null);
    //        dialog.pack();
    //        dialog.setVisible(true);
    //        LOG.info("login : " + client.isLogin());
    //        if (client.isLogin()) {
    //            new LoadThread(client).start();
    //        } else {
    //            //fillTestData(client);
    //        }
}
 
Example #4
Source File: DirDiffTableModel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean confirmDeletion(int count) {
  return MessageDialogBuilder.yesNo("Confirm Delete", "Delete " + count + " items?").project(myProject).yesText("Delete").noText(CommonBundle.message("button.cancel")).doNotAsk(
          new DialogWrapper.DoNotAskOption() {
            @Override
            public boolean isToBeShown() {
              return WarnOnDeletion.isWarnWhenDeleteItems();
            }

            @Override
            public void setToBeShown(boolean value, int exitCode) {
              WarnOnDeletion.setWarnWhenDeleteItems(value);
            }

            @Override
            public boolean canBeHidden() {
              return true;
            }

            @Override
            public boolean shouldSaveOptionsOnCancel() {
              return true;
            }

            @Nonnull
            @Override
            public String getDoNotShowMessage() {
              return "Do not ask me again";
            }
          }).show() == Messages.YES;
}
 
Example #5
Source File: NotificationTestAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void hyperlinkUpdate(@Nonnull Notification notification, @Nonnull HyperlinkEvent event) {
  if (MessageDialogBuilder.yesNo("Notification Listener", event.getDescription() + "      Expire?").isYes()) {
    myNotification.expire();
    myNotification = null;
  }
}
 
Example #6
Source File: NotificationTestAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  Notification.get(e);
  if (MessageDialogBuilder.yesNo("AnAction", getTemplatePresentation().getText() + "      Expire?").isYes()) {
    myNotification.expire();
    myNotification = null;
  }
}
 
Example #7
Source File: FileUtils.java    From EasyCode with MIT License 4 votes vote down vote up
/**
 * 写入文件
 *
 * @param saveFile 需要保存的文件对象
 */
public void write(SaveFile saveFile) {
    // 校验目录是否存在
    PsiManager psiManager = PsiManager.getInstance(saveFile.getProject());
    PsiDirectory psiDirectory;
    VirtualFile directory = LocalFileSystem.getInstance().findFileByPath(saveFile.getPath());
    if (directory == null) {
        // 尝试创建目录
        if (saveFile.isOperateTitle() && !MessageDialogBuilder.yesNo(MsgValue.TITLE_INFO, "Directory " + saveFile.getPath() + " Not Found, Confirm Create?").isYes()) {
            return;
        }
        psiDirectory = WriteCommandAction.runWriteCommandAction(saveFile.getProject(), (Computable<PsiDirectory>) () -> {
            try {
                VirtualFile dir = VfsUtil.createDirectoryIfMissing(saveFile.getPath());
                LOG.assertTrue(dir != null);
                // 重载文件,防止发生IndexNotReadyException异常
                FileDocumentManager.getInstance().reloadFiles(dir);
                return psiManager.findDirectory(dir);
            } catch (IOException e) {
                LOG.error("path " + saveFile.getPath() + " error");
                ExceptionUtil.rethrow(e);
                return null;
            }
        });
    } else {
        psiDirectory = psiManager.findDirectory(directory);
    }
    if (psiDirectory == null) {
        return;
    }
    // 保存或替换文件
    PsiFile oldFile = psiDirectory.findFile(saveFile.getFile().getName());
    PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(saveFile.getProject());
    FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
    if (saveFile.isOperateTitle() && oldFile != null) {
        MessageDialogBuilder.YesNoCancel yesNoCancel = MessageDialogBuilder.yesNoCancel(MsgValue.TITLE_INFO, "File " + saveFile.getFile().getName() + " Exists, Select Operate Mode?");
        yesNoCancel.yesText("Cover");
        yesNoCancel.noText("Compare");
        yesNoCancel.cancelText("Cancel");
        int result = yesNoCancel.show();
        switch (result) {
            case Messages.YES:
                break;
            case Messages.NO:
                // 对比代码时也格式化代码
                if (saveFile.isReformat()) {
                    // 保留旧文件内容,用新文件覆盖旧文件执行格式化,然后再还原旧文件内容
                    String oldText = oldFile.getText();
                    WriteCommandAction.runWriteCommandAction(saveFile.getProject(), () -> psiDocumentManager.getDocument(oldFile).setText(saveFile.getFile().getText()));
                    // 提交所有改动,并非VCS中的提交文件
                    PsiDocumentManager.getInstance(saveFile.getProject()).commitAllDocuments();
                    reformatFile(saveFile.getProject(), Collections.singletonList(oldFile));
                    // 提交所有改动,并非VCS中的提交文件
                    PsiDocumentManager.getInstance(saveFile.getProject()).commitAllDocuments();
                    String newText = oldFile.getText();
                    WriteCommandAction.runWriteCommandAction(saveFile.getProject(), () -> psiDocumentManager.getDocument(oldFile).setText(oldText));
                    // 提交所有改动,并非VCS中的提交文件
                    PsiDocumentManager.getInstance(saveFile.getProject()).commitAllDocuments();
                    saveFile.setVirtualFile(new LightVirtualFile(saveFile.getFile().getName(), saveFile.getFile().getFileType(), newText));
                }
                CompareFileUtils.showCompareWindow(saveFile.getProject(), fileDocumentManager.getFile(psiDocumentManager.getDocument(oldFile)), saveFile.getVirtualFile());
                return;
            case Messages.CANCEL:
            default:
                return;
        }
    }
    PsiDirectory finalPsiDirectory = psiDirectory;
    PsiFile finalFile = WriteCommandAction.runWriteCommandAction(saveFile.getProject(), (Computable<PsiFile>) () -> {
        if (oldFile == null) {
            // 提交所有改动,并非VCS中的提交文件
            PsiDocumentManager.getInstance(saveFile.getProject()).commitAllDocuments();
            return (PsiFile) finalPsiDirectory.add(saveFile.getFile());
        } else {
            // 对旧文件进行替换操作
            Document document = psiDocumentManager.getDocument(oldFile);
            LOG.assertTrue(document != null);
            document.setText(saveFile.getFile().getText());
            return oldFile;
        }
    });
    // 判断是否需要进行代码格式化操作
    if (saveFile.isReformat()) {
        reformatFile(saveFile.getProject(), Collections.singletonList(finalFile));
    }
    // 提交所有改动,并非VCS中的提交文件
    PsiDocumentManager.getInstance(saveFile.getProject()).commitAllDocuments();
}
 
Example #8
Source File: ReplaceInProjectManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
public boolean showReplaceAllConfirmDialog(@Nonnull String usagesCount, @Nonnull String stringToFind, @Nonnull String filesCount, @Nonnull String stringToReplace) {
  return Messages.YES ==
         MessageDialogBuilder.yesNo(FindBundle.message("find.replace.all.confirmation.title"), FindBundle
                 .message("find.replace.all.confirmation", usagesCount, StringUtil.escapeXmlEntities(stringToFind), filesCount, StringUtil.escapeXmlEntities(stringToReplace))).yesText(FindBundle.message("find.replace.command")).project(myProject).noText(Messages.CANCEL_BUTTON).show();
}
 
Example #9
Source File: DesktopApplicationImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static boolean confirmExitIfNeeded(boolean exitConfirmed) {
  final boolean hasUnsafeBgTasks = ProgressManager.getInstance().hasUnsafeProgressIndicator();
  if (exitConfirmed && !hasUnsafeBgTasks) {
    return true;
  }

  DialogWrapper.DoNotAskOption option = new DialogWrapper.DoNotAskOption() {
    @Override
    public boolean isToBeShown() {
      return GeneralSettings.getInstance().isConfirmExit() && ProjectManager.getInstance().getOpenProjects().length > 0;
    }

    @Override
    public void setToBeShown(boolean value, int exitCode) {
      GeneralSettings.getInstance().setConfirmExit(value);
    }

    @Override
    public boolean canBeHidden() {
      return !hasUnsafeBgTasks;
    }

    @Override
    public boolean shouldSaveOptionsOnCancel() {
      return false;
    }

    @Nonnull
    @Override
    public String getDoNotShowMessage() {
      return "Do not ask me again";
    }
  };

  if (hasUnsafeBgTasks || option.isToBeShown()) {
    String message = ApplicationBundle.message(hasUnsafeBgTasks ? "exit.confirm.prompt.tasks" : "exit.confirm.prompt", ApplicationNamesInfo.getInstance().getFullProductName());

    if (MessageDialogBuilder.yesNo(ApplicationBundle.message("exit.confirm.title"), message).yesText(ApplicationBundle.message("command.exit")).noText(CommonBundle.message("button.cancel"))
                .doNotAsk(option).show() != Messages.YES) {
      return false;
    }
  }
  return true;
}