List of usage examples for com.intellij.openapi.ui Messages showInputDialog
@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)
From source file:com.intellij.appengine.actions.AppEngineUploader.java
License:Apache License
@Nullable public static AppEngineUploader createUploader(@NotNull Project project, @NotNull Artifact artifact, @NotNull AppEngineServerConfiguration configuration, @NotNull ServerRuntimeInstance.DeploymentOperationCallback callback, @NotNull LoggingHandler loggingHandler) { final String explodedPath = artifact.getOutputPath(); if (explodedPath == null) { callback.errorOccurred("Output path isn't specified for '" + artifact.getName() + "' artifact"); return null; }//from w w w . java2s . co m final AppEngineFacet appEngineFacet = AppEngineUtil.findAppEngineFacet(project, artifact); if (appEngineFacet == null) { callback.errorOccurred("App Engine facet not found in '" + artifact.getName() + "' artifact"); return null; } final AppEngineSdk sdk = appEngineFacet.getSdk(); if (!sdk.getAppCfgFile().exists()) { callback.errorOccurred("Path to App Engine SDK isn't specified correctly in App Engine Facet settings"); return null; } PackagingElementResolvingContext context = ArtifactManager.getInstance(project).getResolvingContext(); VirtualFile descriptorFile = ArtifactUtil.findSourceFileByOutputPath(artifact, "WEB-INF/appengine-web.xml", context); final AppEngineWebApp root = AppEngineFacet.getDescriptorRoot(descriptorFile, appEngineFacet.getModule().getProject()); if (root != null) { final GenericDomValue<String> application = root.getApplication(); if (StringUtil.isEmptyOrSpaces(application.getValue())) { final String name = Messages.showInputDialog(project, "<html>Application name is not specified in appengine-web.xml.<br>" + "Enter application name (see your <a href=\"http://appengine.google.com\">AppEngine account</a>):</html>", CommonBundle.getErrorTitle(), null, "", null); if (name == null) return null; final PsiFile file = application.getXmlTag().getContainingFile(); new WriteCommandAction(project, file) { protected void run(@NotNull final Result result) { application.setStringValue(name); } }.execute(); final Document document = PsiDocumentManager.getInstance(project).getDocument(file); if (document != null) { FileDocumentManager.getInstance().saveDocument(document); } } } AppEngineAuthData authData = AppEngineAccountDialog.createAuthData(project, configuration); if (authData == null) return null; return new AppEngineUploader(project, artifact, appEngineFacet, sdk, authData, callback, loggingHandler); }
From source file:com.intellij.application.options.editor.JavaAutoImportConfigurable.java
License:Apache License
public JavaAutoImportConfigurable() { mySmartPasteCombo.addItem(INSERT_IMPORTS_ALWAYS); mySmartPasteCombo.addItem(INSERT_IMPORTS_ASK); mySmartPasteCombo.addItem(INSERT_IMPORTS_NONE); myExcludePackagesList = new JBList(); myExcludeFromImportAndCompletionPanel.add( ToolbarDecorator.createDecorator(myExcludePackagesList).setAddAction(new AnActionButtonRunnable() { @Override//from ww w . ja va 2s.co m public void run(AnActionButton button) { InputValidator validator = new InputValidator() { @Override public boolean checkInput(String inputString) { return ourPackagePattern.matcher(inputString).matches(); } @Override public boolean canClose(String inputString) { return checkInput(inputString); } }; String packageName = Messages.showInputDialog(myWholePanel, ApplicationBundle.message("exclude.from.completion.prompt"), ApplicationBundle.message("exclude.from.completion.title"), Messages.getWarningIcon(), "", validator); addExcludePackage(packageName); } }).disableUpDownActions().createPanel(), BorderLayout.CENTER); myExcludePackagesList.getEmptyText() .setText(ApplicationBundle.message("exclude.from.imports.no.exclusions")); }
From source file:com.intellij.codeInsight.daemon.impl.analysis.AddSchemaPrefixIntention.java
License:Apache License
@Override public void invoke(@Nonnull Project project, Editor editor, @Nonnull PsiElement element) throws IncorrectOperationException { final XmlAttribute xmlns = getXmlnsDeclaration(element); if (xmlns == null) { return;//from w w w .j ava 2 s . c o m } final String namespace = xmlns.getValue(); final XmlTag tag = xmlns.getParent(); if (tag != null) { final Set<String> ns = tag.getLocalNamespaceDeclarations().keySet(); final String nsPrefix = Messages.showInputDialog(project, "Namespace Prefix:", NAME, Messages.getInformationIcon(), "", new InputValidator() { @RequiredDispatchThread @Override public boolean checkInput(String inputString) { return !ns.contains(inputString); } @RequiredDispatchThread @Override public boolean canClose(String inputString) { return checkInput(inputString); } }); if (nsPrefix == null) { return; } final List<XmlTag> tags = new ArrayList<XmlTag>(); final List<XmlAttributeValue> values = new ArrayList<XmlAttributeValue>(); new WriteCommandAction(project, NAME, tag.getContainingFile()) { @Override protected void run(Result result) throws Throwable { tag.accept(new XmlRecursiveElementVisitor() { @Override public void visitXmlTag(XmlTag tag) { if (tag.getNamespace().equals(namespace) && tag.getNamespacePrefix().length() == 0) { tags.add(tag); } super.visitXmlTag(tag); } @Override public void visitXmlAttributeValue(XmlAttributeValue value) { PsiReference ref = null; boolean skip = false; for (PsiReference reference : value.getReferences()) { if (reference instanceof TypeOrElementOrAttributeReference) { ref = reference; } else if (reference instanceof SchemaPrefixReference) { skip = true; break; } } if (!skip && ref != null) { final PsiElement xmlElement = ref.resolve(); if (xmlElement instanceof XmlElement) { final XmlTag tag = PsiTreeUtil.getParentOfType(xmlElement, XmlTag.class, false); if (tag != null) { if (tag.getNamespace().equals(namespace)) { if (ref.getRangeInElement().getLength() == value.getValue().length()) { //no ns prefix values.add(value); } } } } } } }); for (XmlAttributeValue value : values) { ((XmlAttribute) value.getParent()).setValue(nsPrefix + ":" + value.getValue()); } for (XmlTag xmlTag : tags) { xmlTag.setName(nsPrefix + ":" + xmlTag.getLocalName()); } xmlns.setName("xmlns:" + nsPrefix); } }.execute(); } }
From source file:com.intellij.codeInsight.template.impl.TemplateListPanel.java
License:Apache License
private void installPopup() { final DumbAwareAction rename = new DumbAwareAction("Rename") { @Override/*from ww w . j a v a 2 s. co m*/ public void update(AnActionEvent e) { final int selected = getSingleSelectedIndex(); final TemplateGroup templateGroup = getGroup(selected); boolean enabled = templateGroup != null; e.getPresentation().setEnabled(enabled); e.getPresentation().setVisible(enabled); super.update(e); } @Override public void actionPerformed(AnActionEvent e) { renameGroup(); } }; rename.registerCustomShortcutSet( ActionManager.getInstance().getAction(IdeActions.ACTION_RENAME).getShortcutSet(), myTree); final DefaultActionGroup move = new DefaultActionGroup("Move", true) { @Override public void update(AnActionEvent e) { final Map<TemplateImpl, DefaultMutableTreeNode> templates = getSelectedTemplates(); boolean enabled = !templates.isEmpty(); e.getPresentation().setEnabled(enabled); e.getPresentation().setVisible(enabled); if (enabled) { Set<String> oldGroups = getAllGroups(templates); removeAll(); SchemesManager<TemplateGroup, TemplateGroup> schemesManager = TemplateSettings.getInstance() .getSchemesManager(); for (TemplateGroup group : getTemplateGroups()) { final String newGroupName = group.getName(); if (!oldGroups.contains(newGroupName)) { add(new DumbAwareAction(newGroupName) { @Override public void actionPerformed(AnActionEvent e) { moveTemplates(templates, newGroupName); } }); } } addSeparator(); add(new DumbAwareAction("New group...") { @Override public void actionPerformed(AnActionEvent e) { String newName = Messages.showInputDialog(myTree, "Enter the new group name:", "Move to a New Group", null, "", new TemplateGroupInputValidator(null)); if (newName != null) { moveTemplates(templates, newName); } } }); } } }; myTree.addMouseListener(new PopupHandler() { @Override public void invokePopup(Component comp, int x, int y) { final DefaultActionGroup group = new DefaultActionGroup(); group.add(rename); group.add(move); ActionManager.getInstance().createActionPopupMenu(ActionPlaces.UNKNOWN, group).getComponent() .show(comp, x, y); } }); }
From source file:com.intellij.codeInsight.template.impl.TemplateListPanel.java
License:Apache License
private void renameGroup() { final int selected = getSingleSelectedIndex(); final TemplateGroup templateGroup = getGroup(selected); if (templateGroup == null) return;/*ww w. j a v a2 s . c o m*/ final String oldName = templateGroup.getName(); String newName = Messages.showInputDialog(myTree, "Enter the new group name:", "Rename", null, oldName, new TemplateGroupInputValidator(oldName)); if (newName != null && !newName.equals(oldName)) { templateGroup.setName(newName); ((DefaultTreeModel) myTree.getModel()).nodeChanged(getNode(selected)); } }
From source file:com.intellij.codeInspection.ex.SeverityEditorDialog.java
License:Apache License
public SeverityEditorDialog(final JComponent parent, final HighlightSeverity severity, final SeverityRegistrar severityRegistrar) { super(parent, true); mySeverityRegistrar = severityRegistrar; myOptionsList.setCellRenderer(new DefaultListCellRenderer() { @Override/* w w w. j av a2 s .co m*/ public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { final Component rendererComponent = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (value instanceof SeverityBasedTextAttributes) { setText(((SeverityBasedTextAttributes) value).getSeverity().toString()); } return rendererComponent; } }); myOptionsList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (myCurrentSelection != null) { apply(myCurrentSelection); } myCurrentSelection = (SeverityBasedTextAttributes) myOptionsList.getSelectedValue(); if (myCurrentSelection != null) { reset(myCurrentSelection); myCard.show(myRightPanel, mySeverityRegistrar.isDefaultSeverity(myCurrentSelection.getSeverity()) ? DEFAULT : EDITABLE); } } }); myOptionsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JPanel leftPanel = ToolbarDecorator.createDecorator(myOptionsList) .setAddAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { final String name = Messages.showInputDialog(myPanel, InspectionsBundle.message("highlight.severity.create.dialog.name.label"), InspectionsBundle.message("highlight.severity.create.dialog.title"), Messages.getQuestionIcon(), "", new InputValidator() { @Override public boolean checkInput(final String inputString) { final ListModel listModel = myOptionsList.getModel(); for (int i = 0; i < listModel.getSize(); i++) { final String severityName = ((SeverityBasedTextAttributes) listModel .getElementAt(i)).getSeverity().myName; if (Comparing.strEqual(severityName, inputString)) return false; } return true; } @Override public boolean canClose(final String inputString) { return checkInput(inputString); } }); if (name == null) return; final TextAttributes textAttributes = CodeInsightColors.WARNINGS_ATTRIBUTES .getDefaultAttributes(); HighlightInfoType.HighlightInfoTypeImpl info = new HighlightInfoType.HighlightInfoTypeImpl( new HighlightSeverity(name, 50), TextAttributesKey.createTextAttributesKey(name)); SeverityBasedTextAttributes newSeverityBasedTextAttributes = new SeverityBasedTextAttributes( textAttributes.clone(), info); ((DefaultListModel) myOptionsList.getModel()).addElement(newSeverityBasedTextAttributes); myOptionsList.clearSelection(); ListScrollingUtil.selectItem(myOptionsList, newSeverityBasedTextAttributes); } }).setMoveUpAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { apply(myCurrentSelection); ListUtil.moveSelectedItemsUp(myOptionsList); } }).setMoveDownAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { apply(myCurrentSelection); ListUtil.moveSelectedItemsDown(myOptionsList); } }).createPanel(); ToolbarDecorator.findRemoveButton(leftPanel).addCustomUpdater(new AnActionButtonUpdater() { @Override public boolean isEnabled(AnActionEvent e) { return !mySeverityRegistrar.isDefaultSeverity( ((SeverityBasedTextAttributes) myOptionsList.getSelectedValue()).getSeverity()); } }); ToolbarDecorator.findUpButton(leftPanel).addCustomUpdater(new AnActionButtonUpdater() { @Override public boolean isEnabled(AnActionEvent e) { boolean canMove = ListUtil.canMoveSelectedItemsUp(myOptionsList); if (canMove) { SeverityBasedTextAttributes pair = (SeverityBasedTextAttributes) myOptionsList .getSelectedValue(); if (pair != null && mySeverityRegistrar.isDefaultSeverity(pair.getSeverity())) { final int newPosition = myOptionsList.getSelectedIndex() - 1; pair = (SeverityBasedTextAttributes) myOptionsList.getModel().getElementAt(newPosition); if (mySeverityRegistrar.isDefaultSeverity(pair.getSeverity())) { canMove = false; } } } return canMove; } }); ToolbarDecorator.findDownButton(leftPanel).addCustomUpdater(new AnActionButtonUpdater() { @Override public boolean isEnabled(AnActionEvent e) { boolean canMove = ListUtil.canMoveSelectedItemsDown(myOptionsList); if (canMove) { SeverityBasedTextAttributes pair = (SeverityBasedTextAttributes) myOptionsList .getSelectedValue(); if (pair != null && mySeverityRegistrar.isDefaultSeverity(pair.getSeverity())) { final int newPosition = myOptionsList.getSelectedIndex() + 1; pair = (SeverityBasedTextAttributes) myOptionsList.getModel().getElementAt(newPosition); if (mySeverityRegistrar.isDefaultSeverity(pair.getSeverity())) { canMove = false; } } } return canMove; } }); myPanel = new JPanel(new BorderLayout()); myPanel.add(leftPanel, BorderLayout.CENTER); myCard = new CardLayout(); myRightPanel = new JPanel(myCard); final JPanel disabled = new JPanel(new GridBagLayout()); final JButton button = new JButton(InspectionsBundle.message("severities.default.settings.message")); button.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { editColorsAndFonts(); } }); disabled.add(button, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); myRightPanel.add(DEFAULT, disabled); myRightPanel.add(EDITABLE, myOptionsPanel); myCard.show(myRightPanel, EDITABLE); myPanel.add(myRightPanel, BorderLayout.EAST); fillList(severity); init(); setTitle(InspectionsBundle.message("severities.editor.dialog.title")); reset((SeverityBasedTextAttributes) myOptionsList.getSelectedValue()); }
From source file:com.intellij.debugger.actions.AddSteppingFilterAction.java
License:Apache License
public void actionPerformed(final AnActionEvent e) { final DebuggerContextImpl debuggerContext = DebuggerAction.getDebuggerContext(e.getDataContext()); DebugProcessImpl process = debuggerContext.getDebugProcess(); if (process == null) { return;//from w w w. j a v a2 s .co m } final StackFrameProxyImpl proxy = PopFrameAction.getStackFrameProxy(e); process.getManagerThread().schedule(new DebuggerCommandImpl() { protected void action() throws Exception { final String name = getClassName(proxy != null ? proxy : debuggerContext.getFrameProxy()); if (name == null) { return; } final Project project = e.getData(CommonDataKeys.PROJECT); ApplicationManager.getApplication().invokeLater(() -> { String filter = Messages.showInputDialog(project, "", "Add Stepping Filter", null, name, null); if (filter != null) { ClassFilter[] newFilters = ArrayUtil.append( DebuggerSettings.getInstance().getSteppingFilters(), new ClassFilter(filter)); DebuggerSettings.getInstance().setSteppingFilters(newFilters); } }); } }); }
From source file:com.intellij.gwt.actions.GwtCreateActionBase.java
License:Apache License
@Override @Nonnull/* ww w .j a v a 2 s .c o m*/ protected final PsiElement[] invokeDialog(final Project project, final PsiDirectory directory) { Module module = ModuleUtil.findModuleForFile(directory.getVirtualFile(), project); if (module == null) { return PsiElement.EMPTY_ARRAY; } GoogleGwtModuleExtension facet = ModuleUtilCore.getExtension(module, GoogleGwtModuleExtension.class); if (facet == null) { return PsiElement.EMPTY_ARRAY; } if (requireGwtModule()) { final GwtModule gwtModule = findGwtModule(project, directory); if (gwtModule == null) { final String message = GwtBundle.message( "error.message.this.action.is.allowed.only.for.client.side.packages.of.a.gwt.module"); Messages.showErrorDialog(project, message, CommonBundle.getErrorTitle()); return PsiElement.EMPTY_ARRAY; } } MyInputValidator validator = new MyInputValidator(project, directory); Messages.showInputDialog(project, getDialogPrompt(), getDialogTitle(), Messages.getQuestionIcon(), "", validator); return validator.getCreatedElements(); }
From source file:com.intellij.history.integration.ui.actions.PutLabelAction.java
License:Apache License
@Override protected void showDialog(Project p, IdeaGateway gw, VirtualFile f, AnActionEvent e) { String labelName = Messages.showInputDialog(p, message("put.label.name"), message("put.label.dialog.title"), null, "", new NonEmptyInputValidator()); if (labelName == null) return;/*ww w .java2s.co m*/ LocalHistory.getInstance().putUserLabel(p, labelName); }
From source file:com.intellij.ide.actionMacro.ActionMacroConfigurationPanel.java
License:Apache License
public JPanel getPanel() { if (mySplitter == null) { mySplitter = new Splitter(false, 0.5f); final String value = PropertiesComponent.getInstance().getValue(SPLITTER_PROPORTION); if (value != null) { mySplitter.setProportion(Float.parseFloat(value)); }// w w w . ja v a 2s . co m mySplitter.setFirstComponent( ToolbarDecorator.createDecorator(myMacrosList).setEditAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { final int selIndex = myMacrosList.getSelectedIndex(); if (selIndex == -1) return; final ActionMacro macro = (ActionMacro) myMacrosModel.getElementAt(selIndex); String newName; do { newName = Messages.showInputDialog(mySplitter, IdeBundle.message("prompt.enter.new.name"), IdeBundle.message("title.rename.macro"), Messages.getQuestionIcon(), macro.getName(), null); if (newName == null || macro.getName().equals(newName)) return; } while (!canRenameMacro(newName)); if (myRenamingList == null) myRenamingList = new ArrayList<Pair<String, String>>(); myRenamingList.add(new Pair<String, String>(macro.getName(), newName)); macro.setName(newName); myMacrosList.repaint(); } private boolean canRenameMacro(final String name) { final Enumeration elements = myMacrosModel.elements(); while (elements.hasMoreElements()) { final ActionMacro macro = (ActionMacro) elements.nextElement(); if (macro.getName().equals(name)) { if (Messages.showYesNoDialog(IdeBundle.message("message.macro.exists", name), IdeBundle.message("title.macro.name.already.used"), Messages.getWarningIcon()) != 0) { return false; } myMacrosModel.removeElement(macro); break; } } return true; } }).disableAddAction().disableUpDownActions().createPanel()); mySplitter.setSecondComponent(ToolbarDecorator.createDecorator(myMacroActionsList) .setRemoveAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { final int macrosSelectedIndex = myMacrosList.getSelectedIndex(); if (macrosSelectedIndex != -1) { final ActionMacro macro = (ActionMacro) myMacrosModel .getElementAt(macrosSelectedIndex); macro.deleteAction(myMacroActionsList.getSelectedIndex()); } ListUtil.removeSelectedItems(myMacroActionsList); } }).disableAddAction().disableUpDownActions().createPanel()); } return mySplitter; }