List of usage examples for com.intellij.openapi.ui Messages showErrorDialog
public static void showErrorDialog(@Nullable Component component, String message, @NotNull @Nls(capitalization = Nls.Capitalization.Title) String title)
From source file:com.intellij.ide.actions.SaveAsDirectoryBasedFormatAction.java
License:Apache License
public void actionPerformed(AnActionEvent e) { final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext()); if (project instanceof ProjectEx) { final IProjectStore projectStore = ((ProjectEx) project).getStateStore(); if (StorageScheme.DIRECTORY_BASED != projectStore.getStorageScheme()) { final int result = Messages.showOkCancelDialog(project, "Project will be saved and reopened in new Directory-Based format.\nAre you sure you want to continue?", "Save project to Directory-Based format", Messages.getWarningIcon()); if (result == 0) { final VirtualFile baseDir = project.getBaseDir(); assert baseDir != null; File ideaDir = new File(baseDir.getPath(), ProjectEx.DIRECTORY_STORE_FOLDER + File.separatorChar); final boolean ok = (ideaDir.exists() && ideaDir.isDirectory()) || createDir(ideaDir); if (ok) { LocalFileSystem.getInstance().refreshAndFindFileByIoFile(ideaDir); final StateStorageManager storageManager = projectStore.getStateStorageManager(); final Collection<String> storageFileNames = new ArrayList<String>( storageManager.getStorageFileNames()); for (String file : storageFileNames) { storageManager.clearStateStorage(file); }// w w w. java2s .c om projectStore.setProjectFilePath(baseDir.getPath()); project.save(); ProjectUtil.closeAndDispose(project); ProjectUtil.openOrImport(baseDir.getPath(), null, false); } else { Messages.showErrorDialog(project, String.format("Unable to create '.idea' directory (%s)", ideaDir), "Error saving project!"); } } } } }
From source file:com.intellij.ide.favoritesTreeView.actions.AddNewFavoritesListAction.java
License:Apache License
public static String doAddNewFavoritesList(final Project project) { final FavoritesManager favoritesManager = FavoritesManager.getInstance(project); final String name = Messages.showInputDialog(project, IdeBundle.message("prompt.input.new.favorites.list.name"), IdeBundle.message("title.add.new.favorites.list"), Messages.getInformationIcon(), getUniqueName(project), new InputValidator() { @Override/*from w ww . jav a 2s. co m*/ public boolean checkInput(String inputString) { return inputString != null && inputString.trim().length() > 0; } @Override public boolean canClose(String inputString) { inputString = inputString.trim(); if (favoritesManager.getAvailableFavoritesListNames().contains(inputString)) { Messages.showErrorDialog(project, IdeBundle.message("error.favorites.list.already.exists", inputString.trim()), IdeBundle.message("title.unable.to.add.favorites.list")); return false; } return inputString.length() > 0; } }); if (name == null || name.length() == 0) return null; favoritesManager.createNewList(name); return name; }
From source file:com.intellij.ide.favoritesTreeView.FavoritesManager.java
License:Apache License
public void renameList(final Project project, @NotNull String listName) { final String newName = Messages.showInputDialog(project, IdeBundle.message("prompt.input.favorites.list.new.name", listName), IdeBundle.message("title.rename.favorites.list"), Messages.getInformationIcon(), listName, new InputValidator() { @Override// www .ja v a2s. c om public boolean checkInput(String inputString) { return inputString != null && inputString.trim().length() > 0; } @Override public boolean canClose(String inputString) { inputString = inputString.trim(); if (myName2FavoritesRoots.keySet().contains(inputString) || myProviders.keySet().contains(inputString)) { Messages.showErrorDialog(project, IdeBundle.message("error.favorites.list.already.exists", inputString.trim()), IdeBundle.message("title.unable.to.add.favorites.list")); return false; } return !inputString.isEmpty(); } }); if (newName != null && renameFavoritesList(listName, newName)) { rootsChanged(); } }
From source file:com.intellij.ide.fileTemplates.impl.AllFileTemplatesConfigurable.java
License:Apache License
private void onListSelectionChanged() { FileTemplate selectedValue = myCurrentTab.getSelectedTemplate(); FileTemplate prevTemplate = myEditor == null ? null : myEditor.getTemplate(); if (prevTemplate != selectedValue) { LOG.assertTrue(myEditor != null, "selected:" + selectedValue + "; prev:" + prevTemplate); //selection has changed if (myEditor.isModified()) { try { myModified = true;// w w w . j ava2 s.com myEditor.apply(); fireListChanged(); } catch (ConfigurationException e) { myCurrentTab.selectTemplate(prevTemplate); Messages.showErrorDialog(myMainPanel, e.getMessage(), IdeBundle.message("title.cannot.save.current.template")); return; } } if (selectedValue == null) { myEditor.setTemplate(null, FileTemplateManagerImpl.getInstanceImpl().getDefaultTemplateDescription()); myEditorComponent.repaint(); } else { selectTemplate(selectedValue); } } }
From source file:com.intellij.ide.hierarchy.method.OverrideImplementMethodAction.java
License:Apache License
public final void actionPerformed(final AnActionEvent event) { final DataContext dataContext = event.getDataContext(); final MethodHierarchyBrowser methodHierarchyBrowser = (MethodHierarchyBrowser) MethodHierarchyBrowserBase.DATA_KEY .getData(dataContext);/* ww w .ja v a 2 s .c o m*/ if (methodHierarchyBrowser == null) return; final Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project == null) return; final String commandName = event.getPresentation().getText(); ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { CommandProcessor.getInstance().executeCommand(project, new Runnable() { public void run() { try { final HierarchyNodeDescriptor[] selectedDescriptors = methodHierarchyBrowser .getSelectedDescriptors(); if (selectedDescriptors.length > 0) { final List<VirtualFile> files = new ArrayList<VirtualFile>( selectedDescriptors.length); for (HierarchyNodeDescriptor selectedDescriptor : selectedDescriptors) { final PsiFile containingFile = ((MethodHierarchyNodeDescriptor) selectedDescriptor) .getPsiClass().getContainingFile(); if (containingFile != null) { final VirtualFile vFile = containingFile.getVirtualFile(); if (vFile != null) { files.add(vFile); } } } final ReadonlyStatusHandler.OperationStatus status = ReadonlyStatusHandler .getInstance(project) .ensureFilesWritable(VfsUtil.toVirtualFileArray(files)); if (!status.hasReadonlyFiles()) { for (HierarchyNodeDescriptor selectedDescriptor : selectedDescriptors) { OverrideImplementUtil.overrideOrImplement( ((MethodHierarchyNodeDescriptor) selectedDescriptor).getPsiClass(), methodHierarchyBrowser.getBaseMethod()); } ToolWindowManager.getInstance(project).activateEditorComponent(); } else { ApplicationManager.getApplication().invokeLater(new Runnable() { public void run() { Messages.showErrorDialog(project, status.getReadonlyFilesMessage(), commandName); } }); } } } catch (IncorrectOperationException e) { LOG.error(e); } } }, commandName, null); } }); }
From source file:com.intellij.ide.passwordSafe.ui.PasswordSafePromptDialog.java
License:Apache License
/** * Ask password possibly asking password database first. The method could be invoked from any thread. If UI needs to be shown, * the method invokes {@link UIUtil#invokeAndWaitIfNeeded(Runnable)} * @param project the context project * @param title the dialog title * @param message the message describing a resource for which password is asked * @param requestor the password requestor * @param key the password key * @param resetPassword if true, the old password is removed from database and new password will be asked. * @param error the error text to show in the dialog * @param promptLabel the prompt label text * @param checkboxLabel the checkbox text @return null if dialog was cancelled or password (stored in database or a entered by user) *///from w w w. j a v a 2 s .c om @Nullable private static String askPassword(final Project project, final String title, final String message, @NotNull final Class<?> requestor, final String key, boolean resetPassword, final String error, final String promptLabel, final String checkboxLabel) { final PasswordSafeImpl ps = (PasswordSafeImpl) PasswordSafe.getInstance(); try { if (resetPassword) { ps.removePassword(project, requestor, key); } else { String pw = ps.getPassword(project, requestor, key); if (pw != null) { return pw; } } } catch (PasswordSafeException ex) { // ignore exception on get/reset phase if (LOG.isDebugEnabled()) { LOG.debug("Failed to retrieve or reset password", ex); } } final Ref<String> ref = Ref.create(); ApplicationManager.getApplication().invokeAndWait(new Runnable() { public void run() { PasswordSafeSettings.ProviderType type = ps.getSettings().getProviderType(); final PasswordPromptComponent component = new PasswordPromptComponent(type, message, false, promptLabel, checkboxLabel); PasswordSafePromptDialog d = new PasswordSafePromptDialog(project, title, component); d.setErrorText(error); if (d.showAndGet()) { ref.set(new String(component.getPassword())); try { if (component.isRememberSelected()) { ps.storePassword(project, requestor, key, ref.get()); } else if (!type.equals(PasswordSafeSettings.ProviderType.DO_NOT_STORE)) { ps.getMemoryProvider().storePassword(project, requestor, key, ref.get()); } } catch (PasswordSafeException e) { Messages.showErrorDialog(project, e.getMessage(), "Failed to Store Password"); if (LOG.isDebugEnabled()) { LOG.debug("Failed to store password", e); } } } } }, ModalityState.any()); return ref.get(); }
From source file:com.intellij.ide.projectView.actions.ImportModuleFromImlFileAction.java
License:Apache License
@Override public void actionPerformed(AnActionEvent e) { final VirtualFile[] files = e.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY); final Project project = getEventProject(e); if (files == null || project == null) return;/* w w w .j a v a 2 s.co m*/ try { final ModifiableModuleModel model = ModuleManager.getInstance(project).getModifiableModel(); for (VirtualFile file : files) { model.loadModule(file.getPath()); } AccessToken token = WriteAction.start(); try { model.commit(); } finally { token.finish(); } } catch (Exception ex) { LOG.info(ex); Messages.showErrorDialog(project, "Cannot import module: " + ex.getMessage(), CommonBundle.getErrorTitle()); } }
From source file:com.intellij.ide.ui.customization.CustomizableActionsPanel.java
License:Apache License
protected boolean doSetIcon(DefaultMutableTreeNode node, @Nullable String path, Component component) { if (StringUtil.isNotEmpty(path) && !new File(path).isFile()) { Messages.showErrorDialog(component, IdeBundle.message("error.file.not.found.message", path), IdeBundle.message("title.choose.action.icon")); return false; }//from w w w .j a va 2s.c o m String actionId = getActionId(node); if (actionId == null) return false; final AnAction action = ActionManager.getInstance().getAction(actionId); if (action != null && action.getTemplatePresentation() != null) { if (StringUtil.isNotEmpty(path)) { Image image = null; try { image = ImageLoader.loadFromStream(VfsUtil .convertToURL(VfsUtil.pathToUrl(path.replace(File.separatorChar, '/'))).openStream()); } catch (IOException e) { LOG.debug(e); } Icon icon = new File(path).exists() ? IconLoader.getIcon(image) : null; if (icon != null) { if (icon.getIconWidth() > EmptyIcon.ICON_18.getIconWidth() || icon.getIconHeight() > EmptyIcon.ICON_18.getIconHeight()) { Messages.showErrorDialog(component, IdeBundle.message("custom.icon.validation.message"), IdeBundle.message("title.choose.action.icon")); return false; } node.setUserObject(Pair.create(actionId, icon)); mySelectedSchema.addIconCustomization(actionId, path); } } else { node.setUserObject(Pair.create(actionId, null)); mySelectedSchema.removeIconCustomization(actionId); final DefaultMutableTreeNode nodeOnToolbar = findNodeOnToolbar(actionId); if (nodeOnToolbar != null) { editToolbarIcon(actionId, nodeOnToolbar); node.setUserObject(nodeOnToolbar.getUserObject()); } } return true; } return false; }
From source file:com.intellij.ide.util.newProjectWizard.AddModuleWizard.java
License:Apache License
protected boolean commitStepData(final ModuleWizardStep step) { try {//www . java 2s . co m if (!step.validate()) { return false; } } catch (ConfigurationException e) { Messages.showErrorDialog(myCurrentProject, e.getMessage(), e.getTitle()); return false; } step.updateDataModel(); return true; }
From source file:com.intellij.ide.util.PackageUtil.java
License:Apache License
public static boolean checkSourceRootsConfigured(final Module module, final boolean askUserToSetupSourceRoots) { VirtualFile[] sourceRoots = ModuleRootManager.getInstance(module).getSourceRoots(); if (sourceRoots.length == 0) { if (!askUserToSetupSourceRoots) { return false; }//from w w w .j a v a 2 s .c om Project project = module.getProject(); Messages.showErrorDialog(project, ProjectBundle.message("module.source.roots.not.configured.error", module.getName()), ProjectBundle.message("module.source.roots.not.configured.title")); ProjectSettingsService.getInstance(project).showModuleConfigurationDialog(module.getName(), ContentEntriesEditor.NAME); sourceRoots = ModuleRootManager.getInstance(module).getSourceRoots(); if (sourceRoots.length == 0) { return false; } } return true; }