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

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

Introduction

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

Prototype

@Nullable
    public static String showInputDialog(@NotNull Component parent, String message,
            @Nls(capitalization = Nls.Capitalization.Title) String title, @Nullable Icon icon,
            @Nullable String initialValue, @Nullable InputValidator validator) 

Source Link

Usage

From source file:manuylov.maxim.ocaml.actions.BaseCreateOCamlFileAction.java

License:Open Source License

@Override
protected void invokeDialog(@Nonnull final Project project, @Nonnull final PsiDirectory directory,
        Consumer<PsiElement[]> elementsConsumer) {
    final MyInputValidator validator = new MyInputValidator(project, directory);
    Messages.showInputDialog(project, "Enter module name:",
            "New OCaml Module " + getCapitalizedType() + " File", Messages.getQuestionIcon(), null, validator);
    elementsConsumer.accept(validator.getCreatedElements());
}

From source file:org.cdv.intellij.ui.CDVNewFileAction.java

License:Open Source License

@NotNull
@Override// w w w  . j av a  2 s  .c  o  m
protected PsiElement[] invokeDialog(Project project, PsiDirectory psiDirectory) {
    final MyInputValidator validator = new MyInputValidator(project, psiDirectory);
    Messages.showInputDialog(project, "File name", "Create New " + CDVConstants.PLUGIN_NAME,
            Messages.getQuestionIcon(), "", validator);

    return validator.getCreatedElements();
}

From source file:org.consulo.compiler.impl.resourceCompiler.ResourceCompilerConfigurable.java

License:Apache License

private void showAddOrChangeDialog(final String initialValue) {
    String pattern = Messages.showInputDialog(myProject, "Pattern", "Enter Pattern", null, initialValue,
            new InputValidatorEx() {
                @Override/*from www . j  a va2 s.c  o m*/
                public boolean checkInput(String inputString) {
                    return (initialValue == null && myModel.getElementIndex(inputString) == -1
                            || initialValue != null) && getErrorText(inputString) == null;
                }

                @Override
                public boolean canClose(String inputString) {
                    return true;
                }

                @Nullable
                @Override
                public String getErrorText(String inputString) {
                    try {
                        ResourceCompilerConfiguration.convertToRegexp(inputString);
                        return null;
                    } catch (Exception ex) {
                        return ex.getMessage();
                    }
                }
            });

    if (pattern != null) {
        if (initialValue != null) {
            myModel.remove(initialValue);
        }

        myModel.add(pattern);
    }
}

From source file:org.cordovastudio.editors.designer.actions.AssignWeightAction.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent e) {
    final List<? extends RadViewComponent> targets = mySelectedChildren;
    if (targets.isEmpty()) {
        return;/*w  w  w . j  a  va  2 s  . co  m*/
    }
    String currentWeight = targets.get(0).getTag().getAttributeValue(ATTR_LAYOUT_WEIGHT, CORDOVASTUDIO_URI);
    if (currentWeight == null || currentWeight.isEmpty()) {
        currentWeight = "0.0";
    }

    String title = getTemplatePresentation().getDescription();
    InputValidator validator = null; // TODO: Number validation!
    final String weight = Messages.showInputDialog(myDesigner, "Enter Weight Value:", title, null,
            currentWeight, validator);
    if (weight != null) {

        myDesigner.getToolProvider().execute(new ThrowableRunnable<Exception>() {
            @Override
            public void run() throws Exception {
                ApplicationManager.getApplication().runWriteAction(new Runnable() {
                    @Override
                    public void run() {
                        if (weight.isEmpty()) {
                            // Remove attributes
                            ClearWeightsAction.clearWeights(myLayout, targets);
                        } else {
                            for (RadViewComponent target : targets) {
                                target.getTag().setAttribute(ATTR_LAYOUT_WEIGHT, CORDOVASTUDIO_URI, weight);
                            }
                        }
                    }
                });
            }
        }, getTemplatePresentation().getDescription(), true);
    }
}

From source file:org.cordovastudio.editors.designer.designSurface.preview.RenderPreview.java

License:Apache License

/**
 * Handles clicks within the preview (x and y are positions relative within the
 * preview/*from w ww. j av  a2  s  . co  m*/
 *
 * @param x the x coordinate within the preview where the click occurred
 * @param y the y coordinate within the preview where the click occurred
 * @return true if this preview handled (and therefore consumed) the click
 */
public boolean click(int x, int y) {
    if (y >= myTitleHeight && y < myTitleHeight + HEADER_HEIGHT) {
        int left = 0;
        left += AllIcons.Actions.CloseNewHovered.getIconWidth();
        if (x <= left) {
            // Delete
            myManager.deletePreview(this);
            return true;
        }
        if (ZOOM_SUPPORT) {
            left += CordovaIcons.Toolbar.ZoomIn.getIconWidth();
            if (x <= left) {
                // Zoom in
                myScale *= (1 / 0.5);
                if (Math.abs(myScale - 1.0) < 0.0001) {
                    myScale = 1.0;
                }

                myManager.scheduleRender(this, 0);
                myManager.layout(true);
                myManager.redraw();
                return true;
            }
            left += CordovaIcons.Toolbar.ZoomOut.getIconWidth();
            if (x <= left) {
                // Zoom out
                myScale *= (0.5 / 1);
                if (Math.abs(myScale - 1.0) < 0.0001) {
                    myScale = 1.0;
                }
                myManager.scheduleRender(this, 0);

                myManager.layout(true);
                myManager.redraw();
                return true;
            }
        }
        left += AllIcons.Actions.Edit.getIconWidth();
        if (x <= left) {
            // Edit. For now, just rename
            Project project = myConfiguration.getConfigurationManager().getProject();
            String newName = Messages.showInputDialog(project, "Name:", "Rename Preview", null,
                    myConfiguration.getDisplayName(), null);
            if (newName != null) {
                myConfiguration.setDisplayName(newName);
                myManager.redraw();
            }

            return true;
        }

        // Clicked anywhere else on header
        // Perhaps open Edit dialog here?
    }

    myManager.switchTo(this);
    return true;
}

From source file:org.f3.ideaplugin.NewF3ClassAction.java

License:Open Source License

@NotNull
protected final PsiElement[] invokeDialog(Project project, PsiDirectory directory) {
    Module module = ModuleUtil.findModuleForFile(directory.getVirtualFile(), project);
    if (module == null)
        return PsiElement.EMPTY_ARRAY;

    MyInputValidator validator = new MyInputValidator(project, directory);
    Messages.showInputDialog(project, "Enter a new class name", "New F3 Class", Messages.getQuestionIcon(), "",
            validator);/*from ww w .  j  a  va 2 s  .  c  om*/

    return validator.getCreatedElements();
}

From source file:org.intellij.erlang.runconfig.ui.ErlangDebugOptionsEditorForm.java

License:Apache License

private void createUIComponents() {
    //noinspection unchecked
    myModulesNotToInterpretListModel = new CollectionListModel();
    myModulesNotToInterpretList = new JBList(myModulesNotToInterpretListModel);
    myModulesNotToInterpretList.setCellRenderer(new JBList.StripedListCellRenderer());
    myModulesNotToInterpretList.setEmptyText("Add non-debuggable modules here (e.g. NIF modules)");
    myModulesNotToInterpretPanel = ToolbarDecorator
            .createDecorator(myModulesNotToInterpretList, myModulesNotToInterpretListModel)
            .setAddAction(anActionButton -> {
                InputValidator inputValidator = new InputValidator() {
                    @Override//w w  w. ja v a  2 s  . co m
                    public boolean checkInput(String moduleName) {
                        return !StringUtil.isEmptyOrSpaces(moduleName) && !myModulesNotToInterpretListModel
                                .getItems().contains(StringUtil.trim(moduleName));
                    }

                    @Override
                    public boolean canClose(String s) {
                        return true;
                    }
                };
                String module = Messages.showInputDialog(myModulesNotToInterpretList, "Module name",
                        "Add a Non-Debuggable Module", ErlangIcons.FILE, null, inputValidator);
                if (module != null) {
                    //noinspection unchecked
                    myModulesNotToInterpretListModel.add(StringUtil.trim(module));
                }
            }).setRemoveAction(anActionButton -> ListUtil.removeSelectedItems(myModulesNotToInterpretList))
            .setMoveUpAction(null).setMoveDownAction(null).createPanel();
    myModulesNotToInterpretPanel
            .setBorder(IdeBorderFactory.createTitledBorder("Modules not to interpret", true));
}

From source file:org.intellij.stripes.actions.StripesNewActionBeanAction.java

License:Apache License

@NotNull
@Override//from  www. jav  a 2  s.c om
protected PsiElement[] invokeDialog(Project project, PsiDirectory directory) {
    MyInputValidator validator = new MyInputValidator(project, directory);
    Messages.showInputDialog(project, "Enter Name for New Stripes ActionBean", "New Stripes Action Bean",
            Messages.getQuestionIcon(), "", validator);
    return validator.getCreatedElements();
}

From source file:org.jboss.errai.idea.plugin.actions.NewErraiUIEntryPoint.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent e) {
    final VirtualFile directory = e.getData(PlatformDataKeys.VIRTUAL_FILE);

    final String name = Messages.showInputDialog(e.getProject(),
            "Type a new name for your Errai UI @EntryPoint. (Do not include file extension)",
            "Create new Errai UI-based @EntryPoint", ErraiActionGroup.ERRAI_ICON, "", new InputValidator() {

                boolean valid = false;

                private boolean validate(String name) {
                    final String trimmed = name.trim();

                    return trimmed.length() != 0 && trimmed.indexOf('.') == -1
                            && !(!Character.isLetter(trimmed.charAt(0)) || !trimmed.matches("^[A-Za-z0-9_]*$"));
                }//from   w ww . ja  v  a2  s. co m

                @Override
                public boolean checkInput(String inputString) {
                    this.valid = validate(inputString);
                    return valid;
                }

                @Override
                public boolean canClose(String inputString) {
                    return valid;
                }
            });

    if (name == null) {
        return;
    }

    final String trimmed = name.trim();

    final PsiDirectory psiDirectory = PsiManager.getInstance(e.getProject()).findDirectory(directory);

    final PsiElement templateFile = FileTemplateUtil.createFileFromTemplate("ErraiUIEntryPoint.java", trimmed,
            psiDirectory, new HashMap<String, String>() {
                {
                    put("TEMPLATED_ANNOTATION_TYPE", Types.TEMPLATED);
                    put("ERRAI_ENTRYPOINT_TYPE", Types.ENTRY_POINT);
                    put("ERRAI_EVENTHANDLER_TYPE", Types.EVENTHANDLER);
                    put("ERRAI_DATAFIELD_TYPE", Types.DATAFIELD);

                    put("GWT_COMPOSITE_TYPE", Types.GWT_COMPOSITE);
                    put("GWT_CLICKEVENT_TYPE", Types.GWT_CLICKEVENT);
                    put("GWT_BUTTON_TYPE", Types.GWT_BUTTON);
                    put("GWT_TEXTBOX_TYPE", Types.GWT_TEXTBOX);

                    put("JAVAX_INJECT_TYPE", Types.JAVAX_INJECT);
                }
            });

    FileTemplateUtil.createFileFromTemplate("EntryPointTemplatedFile.html", name, psiDirectory,
            Collections.<String, String>emptyMap());

    templateFile.getContainingFile().navigate(true);
}

From source file:org.jboss.errai.idea.plugin.actions.NewTemplatedWidgetAction.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent e) {
    final VirtualFile virtualFile = e.getData(PlatformDataKeys.VIRTUAL_FILE);
    final VirtualFile directory;

    if (virtualFile.isDirectory()) {
        directory = virtualFile;/*from w ww .j av a2  s .  c o  m*/
    } else {
        directory = virtualFile.getParent();
    }

    final String name = Messages.showInputDialog(e.getProject(),
            "Type a new name for your Errai UI template. (Do not include file extension)",
            "Create new Errai UI template", ErraiActionGroup.ERRAI_ICON, "", new InputValidator() {

                boolean valid = false;

                private boolean validate(String name) {
                    final String trimmed = name.trim();

                    return trimmed.length() != 0 && trimmed.indexOf('.') == -1
                            && !(!Character.isLetter(trimmed.charAt(0)) || !trimmed.matches("^[A-Za-z0-9_]*$"));
                }

                @Override
                public boolean checkInput(String inputString) {
                    this.valid = validate(inputString);
                    return valid;
                }

                @Override
                public boolean canClose(String inputString) {
                    return valid;
                }
            });

    if (name == null) {
        return;
    }

    final String trimmed = name.trim();

    final PsiDirectory psiDirectory = PsiManager.getInstance(e.getProject()).findDirectory(directory);

    final PsiElement templateFile = FileTemplateUtil.createFileFromTemplate("TemplatedBean.java", trimmed,
            psiDirectory, new HashMap<String, String>() {
                {
                    put("TEMPLATED_ANNOTATION_TYPE", Types.TEMPLATED);
                    put("GWT_COMPOSITE_TYPE", Types.GWT_COMPOSITE);
                    put("JAVAX_INJECT_TYPE", Types.JAVAX_INJECT);
                }
            });

    FileTemplateUtil.createFileFromTemplate("TemplatedFile.html", name, psiDirectory,
            Collections.<String, String>emptyMap());

    templateFile.getContainingFile().navigate(true);
}