List of usage examples for com.intellij.openapi.ui Messages getWarningIcon
@NotNull public static Icon getWarningIcon()
From source file:com.rtoth.boilerplate.BoilerplateJUnitGenerationAction.java
License:Open Source License
@Override public void actionPerformed(AnActionEvent event) { Project project = event.getData(PlatformDataKeys.PROJECT); // TODO: When would project ever be null? if (project != null) { // TODO: Eventually might want to handle multiple selection: // event.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY) PsiFile file = event.getData(LangDataKeys.PSI_FILE); // TODO: When would file ever be null? if (file != null && file instanceof PsiJavaFile) { try { PsiJavaFile sourceFile = (PsiJavaFile) file; Optional<PsiClass> optionalSourceClass = PsiUtility.getSingleClass(sourceFile); if (optionalSourceClass.isPresent()) { PsiClass sourceClass = optionalSourceClass.get(); // TODO: If we have to create the directory or file, it just exits without displaying the dialog... Optional<PsiClass> optionalTestClass = PsiUtility.findOrCreateTestClass(sourceClass); if (optionalTestClass.isPresent()) { PsiClass testClass = optionalTestClass.get(); GetTestMethodsDialog dialog = new GetTestMethodsDialog(sourceClass); if (dialog.showAndGet()) { TestCaseGenerator generator = new TestCaseGenerator(project); generator.createTestCases(testClass, dialog.getSelectedMethodRules()); }//from ww w . jav a 2 s.c om } else { // TODO: Probably not best to be throwing exceptions in here just to catch // them below... log a message explicitly instead? throw new TestGenerationException( "Error finding or generating test class for " + sourceClass.getName()); } } else { // TODO: Probably not best to be throwing exceptions in here just to catch // them below... log a message explicitly instead? throw new TestGenerationException("File does not contain exactly 1 java class."); } } catch (RuntimeException | TestGenerationException e) { e.printStackTrace(); Messages.showMessageDialog(project, e.getMessage(), "Warning", Messages.getWarningIcon()); throw new RuntimeException(e); } } } }
From source file:com.samebug.clients.idea.components.project.TutorialProjectComponent.java
License:Apache License
@Override public void apiStatusChange(@Nullable String apiStatus) { if (!apiStatusNotificationShowed && apiStatus != null) { apiStatusNotificationShowed = true; if (apiStatus.startsWith("DEPRECATED")) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override/*from w ww .j a v a2 s .c o m*/ public void run() { ToolWindowManager.getInstance(myProject).notifyByBalloon("Samebug", MessageType.WARNING, SamebugBundle.message("samebug.tutorial.apiStatus.deprecated"), Messages.getWarningIcon(), null); } }); } else if (apiStatus.startsWith("CLOSED")) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { ToolWindowManager.getInstance(myProject).notifyByBalloon("Samebug", MessageType.ERROR, SamebugBundle.message("samebug.tutorial.apiStatus.closed"), Messages.getErrorIcon(), null); } }); } } }
From source file:com.theoryinpractice.testng.TestNGFramework.java
License:Apache License
@Override protected PsiMethod findOrCreateSetUpMethod(PsiClass clazz) throws IncorrectOperationException { PsiMethod method = findSetUpMethod(clazz); if (method != null) return method; final PsiManager manager = clazz.getManager(); final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory(); String setUpName = "setUp"; PsiMethod patternMethod = createSetUpPatternMethod(factory); PsiMethod inClass = clazz.findMethodBySignature(patternMethod, false); if (inClass != null) { int exit = ApplicationManager.getApplication().isUnitTestMode() ? DialogWrapper.OK_EXIT_CODE : Messages.showYesNoDialog( "Method \'" + setUpName + "\' already exist but is not annotated as @BeforeMethod.", CommonBundle.getWarningTitle(), "Annotate", "Create new method", Messages.getWarningIcon()); if (exit == DialogWrapper.OK_EXIT_CODE) { new AddAnnotationFix(BeforeMethod.class.getName(), inClass).invoke(inClass.getProject(), null, inClass.getContainingFile()); return inClass; } else if (exit == DialogWrapper.CANCEL_EXIT_CODE) { inClass = null;// www . ja v a 2 s . c om int i = 0; while (clazz.findMethodBySignature(patternMethod, false) != null) { patternMethod.setName(setUpName + (++i)); } setUpName = patternMethod.getName(); } } final PsiClass superClass = clazz.getSuperClass(); if (superClass != null) { final PsiMethod[] methods = superClass.findMethodsBySignature(patternMethod, false); if (methods.length > 0) { final PsiModifierList modifierList = methods[0].getModifierList(); if (!modifierList.hasModifierProperty(PsiModifier.PRIVATE)) { //do not override private method @NonNls String pattern = "@" + BeforeMethod.class.getName() + "\n"; if (modifierList.hasModifierProperty(PsiModifier.PROTECTED)) { pattern += "protected "; } else if (modifierList.hasModifierProperty(PsiModifier.PUBLIC)) { pattern += "public "; } patternMethod = factory.createMethodFromText( pattern + "void " + setUpName + "() throws Exception {\nsuper." + setUpName + "();\n}", null); } } } final PsiMethod[] psiMethods = clazz.getMethods(); PsiMethod testMethod = null; for (PsiMethod psiMethod : psiMethods) { if (inClass == null && AnnotationUtil.isAnnotated(psiMethod, BeforeMethod.class.getName(), false)) { inClass = psiMethod; } if (testMethod == null && AnnotationUtil.isAnnotated(psiMethod, Test.class.getName(), false) && !psiMethod.hasModifierProperty(PsiModifier.PRIVATE)) { testMethod = psiMethod; } } if (inClass == null) { final PsiMethod psiMethod; if (testMethod != null) { psiMethod = (PsiMethod) clazz.addBefore(patternMethod, testMethod); } else { psiMethod = (PsiMethod) clazz.add(patternMethod); } JavaCodeStyleManager.getInstance(clazz.getProject()).shortenClassReferences(clazz); return psiMethod; } else if (inClass.getBody() == null) { return (PsiMethod) inClass.replace(patternMethod); } return inClass; }
From source file:de.mobilej.plugin.adc.ToolWindowFactory.java
License:Apache License
@NotNull private JPanel createPanel(@NotNull Project project) { // Create Panel and Content JPanel panel = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.LINE_START; devices = new ComboBox(new String[] { resourceBundle.getString("device.none") }); c.gridx = 0;//from w w w .ja va2 s . c om c.gridy = 0; panel.add(new JLabel("Device"), c); c.gridx = 1; c.gridy = 0; panel.add(devices, c); showLayoutBounds = new JBCheckBox(resourceBundle.getString("show.layout.bounds")); c.gridx = 0; c.gridy = 1; c.gridwidth = 2; panel.add(showLayoutBounds, c); showLayoutBounds.addActionListener(e -> { final String what = showLayoutBounds.isSelected() ? "true" : "\"\""; final String cmd = "setprop debug.layout " + what; ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> { ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true); userAction = true; executeShellCommand(cmd, true); userAction = false; }, resourceBundle.getString("setting.values.title"), false, null); }); localeChooser = new ComboBox(LOCALES); c.gridx = 0; c.gridy = 2; c.gridwidth = 2; panel.add(localeChooser, c); localeChooser.addActionListener(e -> { final LocaleData ld = (LocaleData) localeChooser.getSelectedItem(); if (ld == null) { return; } ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> { ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true); userAction = true; executeShellCommand( "am start -a SETMYLOCALE --es language " + ld.language + " --es country " + ld.county, false); userAction = false; }, resourceBundle.getString("setting.values.title"), false, null); }); goToActivityButton = new JButton(resourceBundle.getString("button.goto_activity")); c.gridx = 0; c.gridy = 3; c.gridwidth = 2; panel.add(goToActivityButton, c); goToActivityButton .addActionListener(e -> ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> { ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true); userAction = true; final String result = executeShellCommand("dumpsys activity top", false); userAction = false; if (result == null) { return; } ApplicationManager.getApplication().invokeLater(() -> { String activity = result.substring(result.indexOf("ACTIVITY ") + 9); activity = activity.substring(0, activity.indexOf(" ")); String pkg = activity.substring(0, activity.indexOf("/")); String clz = activity.substring(activity.indexOf("/") + 1); if (clz.startsWith(".")) { clz = pkg + clz; } GlobalSearchScope scope = GlobalSearchScope.allScope(project); PsiClass psiClass = JavaPsiFacade.getInstance(project).findClass(clz, scope); if (psiClass != null) { FileEditorManager fileEditorManager = FileEditorManager.getInstance(project); //Open the file containing the class VirtualFile vf = psiClass.getContainingFile().getVirtualFile(); //Jump there new OpenFileDescriptor(project, vf, 1, 0).navigateInEditor(project, false); } else { Messages.showMessageDialog(project, clz, resourceBundle.getString("error.class_not_found"), Messages.getWarningIcon()); return; } }); }, resourceBundle.getString("setting.values.title"), false, null)); inputOnDeviceButton = new JButton(resourceBundle.getString("button.input_on_device")); c.gridx = 0; c.gridy = 4; c.gridwidth = 2; panel.add(inputOnDeviceButton, c); inputOnDeviceButton.addActionListener(e -> { final String text2send = Messages.showMultilineInputDialog(project, resourceBundle.getString("send_text.message"), resourceBundle.getString("send_text.title"), storage.getLastSentText(), Messages.getQuestionIcon(), null); if (text2send != null) { storage.setLastSentText(text2send); ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> { ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true); userAction = true; doInputOnDevice(text2send); userAction = false; }, resourceBundle.getString("processing.title"), false, null); } }); clearDataButton = new JButton(resourceBundle.getString("button.clear_data")); c.gridx = 0; c.gridy = 5; c.gridwidth = 2; panel.add(clearDataButton, c); clearDataButton.addActionListener(actionEvent -> { ArrayList<String> appIds = new ArrayList<String>(); List<AndroidFacet> androidFacets = ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID); if (androidFacets != null) { for (AndroidFacet facet : androidFacets) { if (!facet.isLibraryProject()) { AndroidModel androidModel = facet.getAndroidModel(); if (androidModel != null) { String appId = androidModel.getApplicationId(); appIds.add(appId); } } } } ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> { ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true); userAction = true; for (String appId : appIds) { executeShellCommand("pm clear " + appId, false); } userAction = false; }, resourceBundle.getString("processing.title"), false, null); }); JPanel framePanel = new JPanel(new BorderLayout()); framePanel.add(panel, BorderLayout.NORTH); return framePanel; }
From source file:defrac.intellij.sdk.DefracSdkType.java
License:Apache License
@Override public void showCustomCreateUI(final SdkModel sdkModel, final JComponent parentComponent, final Consumer<Sdk> sdkCreatedCallback) { customImpl: {//from ww w. j a v a 2 s. co m final Collection<String> homePaths = suggestHomePaths(); if (homePaths.isEmpty()) { break customImpl; } final String home = homePaths.iterator().next(); final File homePath = new File(home); if (!homePath.isDirectory()) { break customImpl; } if (!checkDependency(sdkModel)) { if (Messages.showOkCancelDialog(parentComponent, getUnsatisfiedDependencyMessage(), "Cannot Create SDK", Messages.getWarningIcon()) != Messages.OK) { return; } if (fixDependency(sdkModel, sdkCreatedCallback) == null) { return; } } final String newSdkName = SdkConfigurationUtil.createUniqueSdkName(this, home, Arrays.asList(sdkModel.getSdks())); final ProjectJdkImpl newJdk = new ProjectJdkImpl(newSdkName, this); newJdk.setHomePath(home); sdkCreatedCallback.consume(newJdk); return; } super.showCustomCreateUI(sdkModel, parentComponent, sdkCreatedCallback); }
From source file:generate.tostring.GenerateToStringUtils.java
License:Apache License
/** * Handles any exception during the executing on this plugin. * * @param project PSI project//from ww w .java 2s. c o m * @param e the caused exception. * @throws RuntimeException is thrown for severe exceptions */ public static void handleExeption(Project project, Exception e) throws RuntimeException { e.printStackTrace(); // must print stacktrace to see caused in IDEA log / console log.error(e); if (e instanceof GenerateCodeException) { // code generation error - display velocity errror in error dialog so user can identify problem quicker Messages.showMessageDialog(project, "Velocity error generating code - see IDEA log for more details (stacktrace should be in idea.log):\n" + e.getMessage(), "Warning", Messages.getWarningIcon()); } else if (e instanceof PluginException) { // plugin related error - could be recoverable. Messages.showMessageDialog(project, "A PluginException was thrown while performing the action - see IDEA log for details (stacktrace should be in idea.log):\n" + e.getMessage(), "Warning", Messages.getWarningIcon()); } else if (e instanceof RuntimeException) { // unknown error (such as NPE) - not recoverable Messages.showMessageDialog(project, "An unrecoverable exception was thrown while performing the action - see IDEA log for details (stacktrace should be in idea.log):\n" + e.getMessage(), "Error", Messages.getErrorIcon()); throw (RuntimeException) e; // throw to make IDEA alert user } else { // unknown error (such as NPE) - not recoverable Messages.showMessageDialog(project, "An unrecoverable exception was thrown while performing the action - see IDEA log for details (stacktrace should be in idea.log):\n" + e.getMessage(), "Error", Messages.getErrorIcon()); throw new RuntimeException(e); // rethrow as runtime to make IDEA alert user } }
From source file:net.sf.logsupport.ui.util.Dialogs.java
License:Apache License
public static boolean confirmDelete(String what, String name) { if (name == null) { return Messages.showYesNoDialog( L10N.message("Dialogs.confirmDelete.confirmationTemplate.unnamed", what), L10N.message("Dialogs.confirmDelete.titleTemplate.unnamed", what), Messages.getWarningIcon()) == JOptionPane.YES_OPTION; } else {/*from ww w . j a v a 2 s. c om*/ return Messages.showYesNoDialog(L10N.message("Dialogs.confirmDelete.confirmationTemplate", what, name), L10N.message("Dialogs.confirmDelete.titleTemplate", what, name), Messages.getWarningIcon()) == JOptionPane.YES_OPTION; } }
From source file:net.sf.logsupport.ui.util.Dialogs.java
License:Apache License
public static boolean confirmOverwrite(String what) { return Messages.showYesNoDialog(L10N.message("Dialogs.confirmOverwrite.confirmationTemplate", what), L10N.message("Dialogs.confirmOverwrite.titleTemplate", what), Messages.getWarningIcon()) == JOptionPane.YES_OPTION; }
From source file:net.sourceforge.transparent.actions.CheckoutDialog.java
License:Open Source License
protected void doOKAction() { if (myConfiguration.FORCE_NON_EMPTY_COMMENT && getComment().length() == 0) { int requestForCheckin = Messages.showYesNoDialog("Check out with empty comment?", "Comment Is Empty", Messages.getWarningIcon()); if (requestForCheckin != OK_EXIT_CODE) { return; }//w w w. j a va 2 s . co m } // myConfiguration.LAST_COMMIT_MESSAGE = (getComment()); try { saveState(); super.doOKAction(); } catch (InputException ex) { ex.show(); } }
From source file:org.community.intellij.plugins.communitycase.actions.Init.java
License:Apache License
/** * {@inheritDoc}// www . j a va 2 s. c om */ public void actionPerformed(final AnActionEvent e) { final Project project = e.getData(PlatformDataKeys.PROJECT); if (project == null) { return; } FileChooserDescriptor fcd = new FileChooserDescriptor(false, true, false, false, false, false); fcd.setShowFileSystemRoots(true); fcd.setTitle(Bundle.getString("init.destination.directory.title")); fcd.setDescription(Bundle.getString("init.destination.directory.description")); fcd.setHideIgnored(false); final VirtualFile baseDir = project.getBaseDir(); final VirtualFile[] files = FileChooser.chooseFiles(project, fcd, baseDir); if (files.length == 0) { return; } final VirtualFile root = files[0]; if (Util.isUnder(root)) { final int v = Messages.showYesNoDialog(project, Bundle.message("init.warning.already.under.git", StringUtil.escapeXml(root.getPresentableUrl())), Bundle.getString("init.warning.title"), Messages.getWarningIcon()); if (v != 0) { return; } } LineHandler h = new LineHandler(project, root, Command.INIT); h.setRemote(true); HandlerUtil.doSynchronously(h, Bundle.getString("initializing.title"), h.printableCommandLine()); if (!h.errors().isEmpty()) { UiUtil.showOperationErrors(project, h.errors(), " init"); return; } int rc = Messages.showYesNoDialog(project, Bundle.getString("init.add.root.message"), Bundle.getString("init.add.root.title"), Messages.getQuestionIcon()); if (rc != 0) { return; } final String path = root.equals(baseDir) ? "" : root.getPath(); Vcs.getInstance(project) .runInBackground(new Task.Backgroundable(project, Bundle.getString("common.refreshing")) { public void run(@NotNull ProgressIndicator indicator) { refreshAndConfigureVcsMappings(project, root, path); } }); }