List of usage examples for com.intellij.openapi.ui Messages getQuestionIcon
@NotNull public static Icon getQuestionIcon()
From source file:com.intellij.application.options.TagListDialog.java
License:Apache License
public TagListDialog(String title) { super(true);//from www.jav a 2 s . c o m myPanel = ToolbarDecorator.createDecorator(myList).setAddAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { final String tagName = Messages.showInputDialog(ApplicationBundle.message("editbox.enter.tag.name"), ApplicationBundle.message("title.tag.name"), Messages.getQuestionIcon()); if (tagName != null) { while (myData.contains(tagName)) { myData.remove(tagName); } myData.add(tagName); updateData(); myList.setSelectedIndex(myData.size() - 1); } } }).setRemoveAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { int selectedIndex = myList.getSelectedIndex(); if (selectedIndex >= 0) { myData.remove(selectedIndex); updateData(); if (selectedIndex >= myData.size()) { selectedIndex -= 1; } if (selectedIndex >= 0) { myList.setSelectedIndex(selectedIndex); } } } }).disableUpDownActions().createPanel(); setTitle(title); init(); }
From source file:com.intellij.codeInsight.actions.AbstractLayoutCodeProcessor.java
License:Apache License
private void runProcessOnFiles(final String where, final List<PsiFile> array) { boolean success = FileModificationService.getInstance().preparePsiElementsForWrite(array); if (!success) { List<PsiFile> writeables = new ArrayList<PsiFile>(); for (PsiFile file : array) { if (file.isWritable()) { writeables.add(file);/*from w ww . ja v a 2 s . c o m*/ } } if (writeables.isEmpty()) return; int res = Messages.showOkCancelDialog(myProject, CodeInsightBundle.message("error.dialog.readonly.files.message", where), CodeInsightBundle.message("error.dialog.readonly.files.title"), Messages.getQuestionIcon()); if (res != Messages.OK) { return; } array.clear(); array.addAll(writeables); } final Runnable[] resultRunnable = new Runnable[1]; runLayoutCodeProcess(new Runnable() { @Override public void run() { resultRunnable[0] = preprocessFiles(array); } }, new Runnable() { @Override public void run() { if (resultRunnable[0] != null) { resultRunnable[0].run(); } } }, array.size() > 1); }
From source file:com.intellij.codeInsight.daemon.impl.quickfix.AddExceptionToThrowsFix.java
License:Apache License
static void addExceptionsToThrowsList(@NotNull final Project project, @NotNull final PsiMethod targetMethod, @NotNull final Set<PsiClassType> unhandledExceptions) { final PsiMethod[] superMethods = getSuperMethods(targetMethod); boolean hasSuperMethodsWithoutExceptions = hasSuperMethodsWithoutExceptions(superMethods, unhandledExceptions);/*from ww w .j ava2s . c o m*/ final boolean processSuperMethods; if (hasSuperMethodsWithoutExceptions && superMethods.length > 0) { int result = Messages.showYesNoCancelDialog( QuickFixBundle.message("add.exception.to.throws.inherited.method.warning.text", targetMethod.getName()), QuickFixBundle.message("method.is.inherited.warning.title"), Messages.getQuestionIcon()); if (result == 0) { processSuperMethods = true; } else if (result == 1) { processSuperMethods = false; } else { return; } } else { processSuperMethods = false; } ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { if (!FileModificationService.getInstance().prepareFileForWrite(targetMethod.getContainingFile())) return; if (processSuperMethods) { for (PsiMethod superMethod : superMethods) { if (!FileModificationService.getInstance() .prepareFileForWrite(superMethod.getContainingFile())) return; } } try { processMethod(project, targetMethod, unhandledExceptions); if (processSuperMethods) { for (PsiMethod superMethod : superMethods) { processMethod(project, superMethod, unhandledExceptions); } } } catch (IncorrectOperationException e) { LOG.error(e); } } }); }
From source file:com.intellij.codeInsight.daemon.impl.quickfix.ModifierFix.java
License:Apache License
@Override public void invoke(@NotNull Project project, @NotNull PsiFile file, @Nullable("is null when called from inspection") Editor editor, @NotNull PsiElement startElement, @NotNull PsiElement endElement) { final PsiModifierList myModifierList = (PsiModifierList) startElement; final PsiVariable variable = myVariable == null ? null : myVariable.getElement(); if (!FileModificationService.getInstance().preparePsiElementForWrite(myModifierList)) return;//w w w .j a va2s .c o m final List<PsiModifierList> modifierLists = new ArrayList<PsiModifierList>(); final PsiFile containingFile = myModifierList.getContainingFile(); final PsiModifierList modifierList; if (variable != null && variable.isValid()) { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { try { variable.normalizeDeclaration(); } catch (IncorrectOperationException e) { LOG.error(e); } } }); modifierList = variable.getModifierList(); assert modifierList != null; } else { modifierList = myModifierList; } PsiElement owner = modifierList.getParent(); if (owner instanceof PsiMethod) { PsiModifierList copy = (PsiModifierList) myModifierList.copy(); changeModifierList(copy); final int accessLevel = PsiUtil.getAccessLevel(copy); OverridingMethodsSearch.search((PsiMethod) owner, owner.getResolveScope(), true) .forEach(new PsiElementProcessorAdapter<PsiMethod>(new PsiElementProcessor<PsiMethod>() { @Override public boolean execute(@NotNull PsiMethod inheritor) { PsiModifierList list = inheritor.getModifierList(); if (inheritor.getManager().isInProject(inheritor) && PsiUtil.getAccessLevel(list) < accessLevel) { modifierLists.add(list); } return true; } })); } if (!FileModificationService.getInstance().prepareFileForWrite(containingFile)) return; if (!modifierLists.isEmpty()) { if (Messages.showYesNoDialog(project, QuickFixBundle.message("change.inheritors.visibility.warning.text"), QuickFixBundle.message("change.inheritors.visibility.warning.title"), Messages.getQuestionIcon()) == DialogWrapper.OK_EXIT_CODE) { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { if (!FileModificationService.getInstance().preparePsiElementsForWrite(modifierLists)) { return; } for (final PsiModifierList modifierList : modifierLists) { changeModifierList(modifierList); } } }); } } ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { changeModifierList(modifierList); UndoUtil.markPsiFileForUndo(containingFile); } }); }
From source file:com.intellij.codeInsight.generation.GenerateEqualsHandler.java
License:Apache License
@Override protected ClassMember[] chooseOriginalMembers(PsiClass aClass, Project project, Editor editor) { myEqualsFields = null;//from w ww.j a va 2s.c om myHashCodeFields = null; myNonNullFields = PsiField.EMPTY_ARRAY; GlobalSearchScope scope = aClass.getResolveScope(); final PsiMethod equalsMethod = GenerateEqualsHelper.findMethod(aClass, GenerateEqualsHelper.getEqualsSignature(project, scope)); final PsiMethod hashCodeMethod = GenerateEqualsHelper.findMethod(aClass, GenerateEqualsHelper.getHashCodeSignature()); boolean needEquals = equalsMethod == null; boolean needHashCode = hashCodeMethod == null; if (!needEquals && !needHashCode) { String text = aClass instanceof PsiAnonymousClass ? CodeInsightBundle.message("generate.equals.and.hashcode.already.defined.warning.anonymous") : CodeInsightBundle.message("generate.equals.and.hashcode.already.defined.warning", aClass.getQualifiedName()); if (Messages.showYesNoDialog(project, text, CodeInsightBundle.message("generate.equals.and.hashcode.already.defined.title"), Messages.getQuestionIcon()) == DialogWrapper.OK_EXIT_CODE) { if (!ApplicationManager.getApplication().runWriteAction(new Computable<Boolean>() { @Override public Boolean compute() { try { equalsMethod.delete(); hashCodeMethod.delete(); return Boolean.TRUE; } catch (IncorrectOperationException e) { LOG.error(e); return Boolean.FALSE; } } }).booleanValue()) { return null; } else { needEquals = needHashCode = true; } } else { return null; } } boolean hasNonStaticFields = false; for (PsiField field : aClass.getFields()) { if (!field.hasModifierProperty(PsiModifier.STATIC)) { hasNonStaticFields = true; break; } } if (!hasNonStaticFields) { HintManager.getInstance().showErrorHint(editor, "No fields to include in equals/hashCode have been found"); return null; } GenerateEqualsWizard wizard = new GenerateEqualsWizard(project, aClass, needEquals, needHashCode); wizard.show(); if (!wizard.isOK()) return null; myEqualsFields = wizard.getEqualsFields(); myHashCodeFields = wizard.getHashCodeFields(); myNonNullFields = wizard.getNonNullFields(); return DUMMY_RESULT; }
From source file:com.intellij.codeInsight.intention.impl.CreateFieldFromParameterDialog.java
License:Apache License
@Override protected void doOKAction() { if (myCbFinal.isEnabled()) { PropertiesComponent.getInstance().setValue(PROPERTY_NAME, String.valueOf(myCbFinal.isSelected())); }/* w w w .j a v a2s. c o m*/ final PsiField[] fields = myTargetClass.getFields(); for (PsiField field : fields) { if (field.getName().equals(getEnteredName())) { int result = Messages.showOkCancelDialog(getContentPane(), CodeInsightBundle.message("dialog.create.field.from.parameter.already.exists.text", getEnteredName()), CodeInsightBundle.message("dialog.create.field.from.parameter.already.exists.title"), Messages.getQuestionIcon()); if (result == 0) { close(OK_EXIT_CODE); } else { return; } } } close(OK_EXIT_CODE); }
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 a va 2 s . com*/ 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.codeInspection.util.SpecialAnnotationsUtil.java
License:Apache License
public static JPanel createSpecialAnnotationsListControl(final List<String> list, final String borderTitle, final boolean acceptPatterns) { final SortedListModel<String> listModel = new SortedListModel<String>(new Comparator<String>() { @Override// ww w.ja v a 2s . c o m public int compare(final String o1, final String o2) { return o1.compareTo(o2); } }); final JList injectionList = new JBList(listModel); for (String s : list) { listModel.add(s); } injectionList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); injectionList.getModel().addListDataListener(new ListDataListener() { @Override public void intervalAdded(ListDataEvent e) { listChanged(); } private void listChanged() { list.clear(); for (int i = 0; i < listModel.getSize(); i++) { list.add((String) listModel.getElementAt(i)); } } @Override public void intervalRemoved(ListDataEvent e) { listChanged(); } @Override public void contentsChanged(ListDataEvent e) { listChanged(); } }); ToolbarDecorator toolbarDecorator = ToolbarDecorator.createDecorator(injectionList) .setAddAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { Project project = CommonDataKeys.PROJECT .getData(DataManager.getInstance().getDataContext(injectionList)); if (project == null) project = ProjectManager.getInstance().getDefaultProject(); TreeClassChooser chooser = TreeClassChooserFactory.getInstance(project) .createWithInnerClassesScopeChooser( InspectionsBundle.message("special.annotations.list.annotation.class"), GlobalSearchScope.allScope(project), new ClassFilter() { @Override public boolean isAccepted(PsiClass aClass) { return aClass.isAnnotationType(); } }, null); chooser.showDialog(); final PsiClass selected = chooser.getSelected(); if (selected != null) { listModel.add(selected.getQualifiedName()); } } }).setAddActionName(InspectionsBundle.message("special.annotations.list.add.annotation.class")) .disableUpDownActions(); if (acceptPatterns) { toolbarDecorator.setAddIcon(IconUtil.getAddClassIcon()) .addExtraAction(new AnActionButton( InspectionsBundle.message("special.annotations.list.annotation.pattern"), IconUtil.getAddPatternIcon()) { @Override public void actionPerformed(AnActionEvent e) { String selectedPattern = Messages.showInputDialog( InspectionsBundle.message("special.annotations.list.annotation.pattern"), InspectionsBundle.message("special.annotations.list.annotation.pattern"), Messages.getQuestionIcon()); if (selectedPattern != null) { listModel.add(selectedPattern); } } }) .setButtonComparator(InspectionsBundle.message("special.annotations.list.add.annotation.class"), InspectionsBundle.message("special.annotations.list.annotation.pattern"), "Remove"); } JPanel panel = new JPanel(new BorderLayout()); panel.add(SeparatorFactory.createSeparator(borderTitle, null), BorderLayout.NORTH); panel.add(toolbarDecorator.createPanel(), BorderLayout.CENTER); return panel; }
From source file:com.intellij.compiler.impl.CompileDriver.java
License:Apache License
private void startup(final CompileScope scope, final boolean isRebuild, final boolean forceCompile, final CompileStatusNotification callback, final CompilerMessage message, final boolean checkCachesVersion) { ApplicationManager.getApplication().assertIsDispatchThread(); ProblemsView.getInstance(myProject).clearOldMessages(null); final String contentName = forceCompile ? CompilerBundle.message("compiler.content.name.compile") : CompilerBundle.message("compiler.content.name.make"); final boolean isUnitTestMode = ApplicationManager.getApplication().isUnitTestMode(); final CompilerTask compileTask = new CompilerTask(myProject, contentName, isUnitTestMode, true, true, isCompilationStartedAutomatically(scope)); StatusBar.Info.set("", myProject, "Compiler"); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); FileDocumentManager.getInstance().saveAllDocuments(); final CompositeDependencyCache dependencyCache = createDependencyCache(); final CompileContextImpl compileContext = new CompileContextImpl(myProject, compileTask, scope, dependencyCache, !isRebuild && !forceCompile, isRebuild); for (Map.Entry<Pair<IntermediateOutputCompiler, Module>, Pair<VirtualFile, VirtualFile>> entry : myGenerationCompilerModuleToOutputDirMap .entrySet()) {//from w ww . j av a 2 s. c o m final Pair<VirtualFile, VirtualFile> outputs = entry.getValue(); final Pair<IntermediateOutputCompiler, Module> key = entry.getKey(); final Module module = key.getSecond(); compileContext.assignModule(outputs.getFirst(), module, false, key.getFirst()); compileContext.assignModule(outputs.getSecond(), module, true, key.getFirst()); } attachAnnotationProcessorsOutputDirectories(compileContext); final Runnable compileWork = new Runnable() { @Override public void run() { if (compileContext.getProgressIndicator().isCanceled()) { if (callback != null) { callback.finished(true, 0, 0, compileContext); } return; } try { if (myProject.isDisposed()) { return; } LOG.info("COMPILATION STARTED"); if (message != null) { compileContext.addMessage(message); } else { if (!isUnitTestMode) { //FIXME [VISTALL] notifyDeprecatedImplementation(); } } TranslatingCompilerFilesMonitor.getInstance().ensureInitializationCompleted(myProject, compileContext.getProgressIndicator()); doCompile(compileContext, isRebuild, forceCompile, callback, checkCachesVersion); } finally { FileUtil.delete(CompilerPaths.getRebuildMarkerFile(myProject)); } } }; compileTask.start(compileWork, new Runnable() { @Override public void run() { if (isRebuild) { final int rv = Messages.showOkCancelDialog(myProject, "You are about to rebuild the whole project.\nRun 'Make Project' instead?", "Confirm Project Rebuild", "Make", "Rebuild", Messages.getQuestionIcon()); if (rv == 0 /*yes, please, do run make*/) { startup(scope, false, false, callback, null, checkCachesVersion); return; } } startup(scope, isRebuild, forceCompile, callback, message, checkCachesVersion); } }); }
From source file:com.intellij.conversion.impl.ConversionServiceImpl.java
License:Apache License
@Override @NotNull//w w w . ja v a 2s .c om public ConversionResult convertModule(@NotNull final Project project, @NotNull final File moduleFile) { final IProjectStore stateStore = ((ProjectImpl) project).getStateStore(); final String url = stateStore.getPresentableUrl(); assert url != null : project; final String projectPath = FileUtil.toSystemDependentName(url); if (!isConversionNeeded(projectPath, moduleFile)) { return ConversionResultImpl.CONVERSION_NOT_NEEDED; } final int res = Messages.showYesNoDialog(project, IdeBundle.message("message.module.file.has.an.older.format.do.you.want.to.convert.it"), IdeBundle.message("dialog.title.convert.module"), Messages.getQuestionIcon()); if (res != Messages.YES) { return ConversionResultImpl.CONVERSION_CANCELED; } if (!moduleFile.canWrite()) { Messages.showErrorDialog(project, IdeBundle.message("error.message.cannot.modify.file.0", moduleFile.getAbsolutePath()), IdeBundle.message("dialog.title.convert.module")); return ConversionResultImpl.ERROR_OCCURRED; } try { ConversionContextImpl context = new ConversionContextImpl(projectPath); final List<ConversionRunner> runners = createConversionRunners(context, Collections.<String>emptySet()); final File backupFile = ProjectConversionUtil.backupFile(moduleFile); List<ConversionRunner> usedRunners = new ArrayList<ConversionRunner>(); for (ConversionRunner runner : runners) { if (runner.isModuleConversionNeeded(moduleFile)) { runner.convertModule(moduleFile); usedRunners.add(runner); } } context.saveFiles(Collections.singletonList(moduleFile), usedRunners); Messages.showInfoMessage(project, IdeBundle.message( "message.your.module.was.successfully.converted.br.old.version.was.saved.to.0", backupFile.getAbsolutePath()), IdeBundle.message("dialog.title.convert.module")); return new ConversionResultImpl(runners); } catch (CannotConvertException e) { LOG.info(e); Messages.showErrorDialog(IdeBundle.message("error.cannot.load.project", e.getMessage()), "Cannot Convert Module"); return ConversionResultImpl.ERROR_OCCURRED; } catch (IOException e) { LOG.info(e); return ConversionResultImpl.ERROR_OCCURRED; } }