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

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

Introduction

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

Prototype

int YES

To view the source code for com.intellij.openapi.ui Messages YES.

Click Source Link

Usage

From source file:com.intellij.ui.mac.MacMessagesImpl.java

License:Apache License

@Override
@Messages.YesNoResult//ww w .  j a va2 s . c  om
public int showYesNoDialog(@NotNull String title, String message, @NotNull String yesButton,
        @NotNull String noButton, @Nullable Window window,
        @Nullable DialogWrapper.DoNotAskOption doNotAskDialogOption) {
    return showAlertDialog(title, yesButton, null, noButton, message, window, false,
            doNotAskDialogOption) == Messages.YES ? Messages.YES : Messages.NO;
}

From source file:com.intellij.ui.mac.MacMessagesImpl.java

License:Apache License

@Messages.YesNoCancelResult
private static int convertReturnCodeFromNativeAlertDialog(int returnCode, String alternateText) {
    // DEFAULT = 1
    // ALTERNATE = 0
    // OTHER = -1 (cancel)

    int cancelCode;
    int code;/*from  ww  w  .j a  v  a  2  s . co m*/
    if (alternateText != null) {
        // DEFAULT = 0
        // ALTERNATE = 1
        // CANCEL = 2

        cancelCode = Messages.CANCEL;

        switch (returnCode) {
        case 1:
            code = Messages.YES;
            break;
        case 0:
            code = Messages.NO;
            break;
        case -1: // cancel
        default:
            code = Messages.CANCEL;
            break;
        }
    } else {
        // DEFAULT = 0
        // CANCEL = 1

        cancelCode = 1;

        switch (returnCode) {
        case 1:
            code = Messages.YES;
            break;
        case -1: // cancel
        default:
            code = Messages.NO;
            break;
        }
    }

    if (cancelCode == code) {
        code = Messages.CANCEL;
    }
    LOG.assertTrue(code == Messages.YES || code == Messages.NO || code == Messages.CANCEL, code);
    return code;
}

From source file:com.intellij.ui.messages.JBMacMessages.java

License:Apache License

@Override
public int showYesNoCancelDialog(@NotNull String title, String message, @NotNull String defaultButton,
        String alternateButton, String otherButton, @Nullable Window window,
        @Nullable DialogWrapper.DoNotAskOption doNotAskOption) {
    if (window == null) {
        window = getForemostWindow(null);
    }/*  w ww.j ava 2  s  .  c om*/
    SheetMessage sheetMessage = new SheetMessage(window, title, message, UIUtil.getQuestionIcon(),
            new String[] { defaultButton, alternateButton, otherButton }, null, defaultButton, alternateButton);
    String resultString = sheetMessage.getResult();
    int result = resultString.equals(defaultButton) ? Messages.YES
            : resultString.equals(alternateButton) ? Messages.NO : Messages.CANCEL;
    if (doNotAskOption != null) {
        doNotAskOption.setToBeShown(sheetMessage.toBeShown(), result);
    }
    return result;
}

From source file:com.intellij.ui.messages.JBMacMessages.java

License:Apache License

@Override
public int showYesNoDialog(@NotNull String title, String message, @NotNull String yesButton,
        @NotNull String noButton, @Nullable Window window) {
    if (window == null) {
        window = getForemostWindow(null);
    }/*  ww w.  j ava2 s .c o  m*/
    SheetMessage sheetMessage = new SheetMessage(window, title, message, UIUtil.getQuestionIcon(),
            new String[] { yesButton, noButton }, null, yesButton, noButton);
    return sheetMessage.getResult().equals(yesButton) ? Messages.YES : Messages.NO;
}

From source file:com.intellij.ui.messages.JBMacMessages.java

License:Apache License

@Override
public int showYesNoDialog(@NotNull String title, String message, @NotNull String yesButton,
        @NotNull String noButton, @Nullable Window window,
        @Nullable DialogWrapper.DoNotAskOption doNotAskDialogOption) {
    if (window == null) {
        window = getForemostWindow(null);
    }/*  w ww  . jav  a  2s  .c  om*/
    SheetMessage sheetMessage = new SheetMessage(window, title, message, UIUtil.getQuestionIcon(),
            new String[] { yesButton, noButton }, doNotAskDialogOption, yesButton, noButton);
    int result = sheetMessage.getResult().equals(yesButton) ? Messages.YES : Messages.NO;
    if (doNotAskDialogOption != null) {
        doNotAskDialogOption.setToBeShown(sheetMessage.toBeShown(), result);
    }
    return result;
}

From source file:com.intellij.uiDesigner.designSurface.InsertComponentProcessor.java

License:Apache License

private boolean checkAddModuleDependency(final ComponentItem item,
        final ModuleSourceOrderEntry moduleSourceOrderEntry) {
    final Module ownerModule = moduleSourceOrderEntry.getOwnerModule();
    int rc = Messages.showYesNoCancelDialog(myEditor,
            UIDesignerBundle.message("add.module.dependency.prompt", item.getClassName(), ownerModule.getName(),
                    myEditor.getModule().getName()),
            UIDesignerBundle.message("add.module.dependency.title"), Messages.getQuestionIcon());
    if (rc == Messages.CANCEL) {
        return false;
    }//  w  w w. j  av  a 2 s.  co m
    if (rc == Messages.YES) {
        ModuleRootModificationUtil.addDependency(myEditor.getModule(), ownerModule);
    }
    return true;
}

From source file:com.intellij.uiDesigner.designSurface.InsertComponentProcessor.java

License:Apache License

private boolean checkAddLibraryDependency(final ComponentItem item, final LibraryOrderEntry libraryOrderEntry) {
    int rc = Messages.showYesNoCancelDialog(myEditor,
            UIDesignerBundle.message("add.library.dependency.prompt", item.getClassName(),
                    libraryOrderEntry.getPresentableName(), myEditor.getModule().getName()),
            UIDesignerBundle.message("add.library.dependency.title"), Messages.getQuestionIcon());
    if (rc == Messages.CANCEL) {
        return false;
    }//  ww w  .  ja  v a  2  s. com
    if (rc == Messages.YES) {
        ApplicationManager.getApplication().runWriteAction(new Runnable() {
            @Override
            public void run() {
                final ModifiableRootModel model = ModuleRootManager.getInstance(myEditor.getModule())
                        .getModifiableModel();
                if (libraryOrderEntry.isModuleLevel()) {
                    copyModuleLevelLibrary(libraryOrderEntry.getLibrary(), model);
                } else {
                    model.addLibraryEntry(libraryOrderEntry.getLibrary());
                }
                model.commit();
            }
        });
    }
    return true;
}

From source file:com.intellij.uiDesigner.FormEditingUtil.java

License:Apache License

public static void deleteRowOrColumn(final GuiEditor editor, final RadContainer container,
        final int[] cellsToDelete, final boolean isRow) {
    Arrays.sort(cellsToDelete);// w w w .j a va 2s  .c o  m
    final int[] cells = ArrayUtil.reverseArray(cellsToDelete);
    if (!editor.ensureEditable()) {
        return;
    }

    Runnable runnable = new Runnable() {
        public void run() {
            if (!GridChangeUtil.canDeleteCells(container, cells, isRow)) {
                Set<RadComponent> componentsInColumn = new HashSet<RadComponent>();
                for (RadComponent component : container.getComponents()) {
                    GridConstraints c = component.getConstraints();
                    for (int cell : cells) {
                        if (c.contains(isRow, cell)) {
                            componentsInColumn.add(component);
                            break;
                        }
                    }
                }

                if (componentsInColumn.size() > 0) {
                    String message = isRow
                            ? UIDesignerBundle.message("delete.row.nonempty", componentsInColumn.size(),
                                    cells.length)
                            : UIDesignerBundle.message("delete.column.nonempty", componentsInColumn.size(),
                                    cells.length);

                    final int rc = Messages.showYesNoDialog(editor, message,
                            isRow ? UIDesignerBundle.message("delete.row.title")
                                    : UIDesignerBundle.message("delete.column.title"),
                            Messages.getQuestionIcon());
                    if (rc != Messages.YES) {
                        return;
                    }

                    deleteComponents(componentsInColumn, false);
                }
            }

            for (int cell : cells) {
                container.getGridLayoutManager().deleteGridCells(container, cell, isRow);
            }
            editor.refreshAndSave(true);
        }
    };
    CommandProcessor.getInstance().executeCommand(editor.getProject(), runnable,
            isRow ? UIDesignerBundle.message("command.delete.row")
                    : UIDesignerBundle.message("command.delete.column"),
            null);
}

From source file:com.liferay.ide.idea.ui.modules.LiferayModuleNameLocationComponent.java

License:Open Source License

private boolean _validateModulePaths() throws ConfigurationException {
    String moduleName = _getModuleName();
    String moduleFileDirectory = _moduleFileLocation.getText();

    if (moduleFileDirectory.length() == 0) {
        throw new ConfigurationException("Enter module file location");
    }/* w w w .  j  av  a 2s  .  co  m*/

    if (moduleName.length() == 0) {
        throw new ConfigurationException("Enter a module name");
    }

    if (!ProjectWizardUtil.createDirectoryIfNotExists(IdeBundle.message("directory.module.file"),
            moduleFileDirectory, _imlLocationChangedByUser)) {

        return false;
    }

    if (!ProjectWizardUtil.createDirectoryIfNotExists(IdeBundle.message("directory.module.content.root"),
            _moduleContentRoot.getText(), _contentRootChangedByUser)) {

        return false;
    }

    File moduleFile = new File(moduleFileDirectory, moduleName + ModuleFileType.DOT_DEFAULT_EXTENSION);

    if (moduleFile.exists()) {
        String identification = IdeBundle.message("project.new.wizard.module.identification");
        String existsTitle = IdeBundle.message("title.file.already.exists");
        String filePrompt = IdeBundle.message("prompt.overwrite.project.file", moduleFile.getAbsolutePath(),
                identification);

        int answer = Messages.showYesNoDialog(filePrompt, existsTitle, Messages.getQuestionIcon());

        if (answer != Messages.YES) {
            return false;
        }
    }

    return true;
}

From source file:com.liferay.ide.idea.ui.modules.LiferayNamePathComponent.java

License:Open Source License

public boolean validateNameAndPath(WizardContext context, boolean defaultFormat) throws ConfigurationException {
    String name = getNameValue();

    if (StringUtil.isEmptyOrSpaces(name)) {
        throw new ConfigurationException(IdeBundle.message("prompt.new.project.file.name",
                ApplicationInfo.getInstance().getVersionName(), context.getPresentationName()));
    }/*  w ww. j  a v  a2 s  .  co m*/

    String projectDirectory = getPath();

    if (StringUtil.isEmptyOrSpaces(projectDirectory)) {
        throw new ConfigurationException(
                IdeBundle.message("prompt.enter.project.file.location", context.getPresentationName()));
    }

    if (_shouldBeAbsolute && !new File(projectDirectory).isAbsolute()) {
        throw new ConfigurationException(StringUtil.capitalize(
                IdeBundle.message("file.location.should.be.absolute", context.getPresentationName())));
    }

    String message = IdeBundle.message("directory.project.file.directory", context.getPresentationName());

    if (!ProjectWizardUtil.createDirectoryIfNotExists(message, projectDirectory, isPathChangedByUser())) {
        return false;
    }

    File file = new File(projectDirectory);

    if (file.exists() && !file.canWrite()) {
        String msg = String.format(
                "Directory '%s' is not seem to be writable. Please consider another location.",
                projectDirectory);

        throw new ConfigurationException(msg);
    }

    for (Project project : ProjectManager.getInstance().getOpenProjects()) {
        if (ProjectUtil.isSameProject(projectDirectory, project)) {
            String msg = String.format(
                    "Directory '%s' is already taken by the project '%s'. Please consider another location.",
                    projectDirectory, project.getName());

            throw new ConfigurationException(msg);
        }
    }

    boolean shouldContinue = true;
    String fileName = defaultFormat ? name + ProjectFileType.DOT_DEFAULT_EXTENSION
            : Project.DIRECTORY_STORE_FOLDER;

    File projectFile = new File(file, fileName);

    if (projectFile.exists()) {
        message = IdeBundle.message("prompt.overwrite.project.file", projectFile.getAbsolutePath(),
                context.getPresentationName());

        int answer = Messages.showYesNoDialog(message, IdeBundle.message("title.file.already.exists"),
                Messages.getQuestionIcon());

        shouldContinue = answer == Messages.YES;
    }

    return shouldContinue;
}