List of usage examples for com.intellij.openapi.ui Messages showErrorDialog
public static void showErrorDialog(String message, @NotNull @Nls(capitalization = Nls.Capitalization.Title) String title)
From source file:com.google.gct.idea.debugger.CloudDebugProcess.java
License:Apache License
@Override public boolean checkCanPerformCommands() { Messages.showErrorDialog( "The Cloud Debugger does not pause execution. Therefore, this feature is unavailable.", "Not Supported"); return false; }
From source file:com.google.gct.idea.debugger.ProjectRepositoryValidator.java
License:Apache License
private void unstash(final @NotNull Project project, @NotNull final Ref<StashInfo> targetStash, @NotNull final VirtualFile root) { if (myRepoState.getSourceRepository() == null || myRepoState.getOriginalBranchName() == null || (!myRepoState.getOriginalBranchName() .equals(myRepoState.getSourceRepository().getCurrentBranchName()) && !myRepoState.getOriginalBranchName() .equals(myRepoState.getSourceRepository().getCurrentRevision()))) { Messages.showErrorDialog( GctBundle.getString("clouddebug.erroroncheckout", myRepoState.getOriginalBranchName()), "Error"); return;/*w ww .j a v a2 s.c o m*/ } final GitLineHandler handler = new GitLineHandler(project, root, GitCommand.STASH); handler.addParameters("apply"); handler.addParameters("--index"); addStashParameter(project, handler, targetStash.get().getStash()); final AtomicBoolean conflict = new AtomicBoolean(); handler.addLineListener(new GitLineHandlerAdapter() { @Override public void onLineAvailable(String line, Key outputType) { if (line.contains("Merge conflict")) { conflict.set(true); } } }); GitUntrackedFilesOverwrittenByOperationDetector untrackedFilesDetector = new GitUntrackedFilesOverwrittenByOperationDetector( root); GitLocalChangesWouldBeOverwrittenDetector localChangesDetector = new GitLocalChangesWouldBeOverwrittenDetector( root, MERGE); handler.addLineListener(untrackedFilesDetector); handler.addLineListener(localChangesDetector); AccessToken token = DvcsUtil.workingTreeChangeStarted(project); try { final Ref<GitCommandResult> result = Ref.create(); ProgressManager.getInstance() .run(new Task.Modal(handler.project(), GitBundle.getString("unstash.unstashing"), false) { @Override public void run(@NotNull final ProgressIndicator indicator) { indicator.setIndeterminate(true); handler.addLineListener(new GitHandlerUtil.GitLineHandlerListenerProgress(indicator, handler, "stash", false)); Git git = ServiceManager.getService(Git.class); result.set(git .runCommand(new Computable.PredefinedValueComputable<GitLineHandler>(handler))); } }); ServiceManager.getService(project, GitPlatformFacade.class).hardRefresh(root); GitCommandResult res = result.get(); if (conflict.get()) { Messages.showDialog(GctBundle.getString("clouddebug.unstashmergeconflicts"), "Merge Conflicts", new String[] { "Ok" }, 0, Messages.getErrorIcon()); } else if (untrackedFilesDetector.wasMessageDetected()) { UntrackedFilesNotifier.notifyUntrackedFilesOverwrittenBy(project, root, untrackedFilesDetector.getRelativeFilePaths(), "unstash", null); } else if (localChangesDetector.wasMessageDetected()) { LocalChangesWouldBeOverwrittenHelper.showErrorDialog(project, root, "unstash", localChangesDetector.getRelativeFilePaths()); } else if (!res.success()) { GitUIUtil.showOperationErrors(project, handler.errors(), handler.printableCommandLine()); } else if (res.success()) { ProgressManager.getInstance().run(new Task.Modal(project, GctBundle.getString("clouddebug.removestashx", targetStash.get().getStash()), false) { @Override public void run(@NotNull ProgressIndicator indicator) { if (myProject == null) { return; } final GitSimpleHandler h = new GitSimpleHandler(myProject, root, GitCommand.STASH); h.addParameters("drop"); addStashParameter(project, h, targetStash.get().getStash()); try { h.run(); h.unsilence(); } catch (final VcsException ex) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { GitUIUtil.showOperationError(myProject, ex, h.printableCommandLine()); } }); } } }); } } finally { DvcsUtil.workingTreeChangeFinished(project, token); } }
From source file:com.google.gct.idea.samples.SampleImportAction.java
License:Apache License
@Override public void actionPerformed(AnActionEvent e) { // TODO: perhaps this should go somewhere else final SamplesIndex samplesService; SamplesIndex.Builder myBuilder = new SamplesIndex.Builder(new NetHttpTransport(), new JacksonFactory(), null);/*from w w w.j a v a 2s . co m*/ samplesService = myBuilder.build(); final AtomicReference<SampleCollection> sampleList = new AtomicReference<SampleCollection>(null); new Task.Modal(null, GctBundle.message("sample.import.title"), false) { @Override public void run(@NotNull ProgressIndicator indicator) { indicator.setText(GctBundle.message("sample.index.downloading")); try { sampleList.set(samplesService.samples().listSamples().set("technology", "android").execute()); } catch (IOException ex) { LOG.warn(GctBundle.message("sample.index.download.failed")); sampleList.set(null); } } }.queue(); if (sampleList.get() == null || sampleList.get().size() == 0) { Messages.showErrorDialog(GctBundle.message("sample.index.download.failed"), GctBundle.message("sample.import.error.title")); return; } UsageTracker.getInstance().trackEvent(GctTracking.CATEGORY, GctTracking.SAMPLES, "browse", null); SampleImportWizard wizard = new SampleImportWizard(null, sampleList.get()); wizard.show(); }
From source file:com.google.gct.idea.samples.SampleImportWizard.java
License:Apache License
@Override public void init() { if (!AndroidSdkUtils.isAndroidSdkAvailable()) { String title = "SDK problem"; String msg = "<html>Your Android SDK is missing or out of date.<br>" + "You can configure your SDK via <b>Configure | Project Defaults | Project Structure | SDKs</b></html>"; super.init(); Messages.showErrorDialog(msg, title); return;/*from ww w . ja v a2 s . c om*/ } addPath(new SampleImportWizardPath(mySampleList, getDisposable())); super.init(); }
From source file:com.google.gct.idea.samples.SampleImportWizardPath.java
License:Apache License
private boolean performFinishingActionsInternal() { Sample sample = myState.get(SAMPLE_KEY); String sampleName = myState.get(SAMPLE_NAME); File sampleDir = new File(myState.get(SAMPLE_DIR)); assert !sampleDir.exists(); if (!FileUtilRt.createDirectory(sampleDir)) { Messages.showErrorDialog(GctBundle.message("create.project.dir.failed"), GctBundle.message("sample.import.error.title")); return false; }/*from ww w .j a v a2s .c o m*/ Project project = ProjectManager.getInstance().createProject(sampleName, sampleDir.getAbsolutePath()); String url = trimSlashes(sample.getCloneUrl()); GithubRepoContents downloadResult = GithubRepoContents.download(project, url, null, null); String errorMessage = downloadResult.getErrorMessage(); if (errorMessage != null) { LOG.error(errorMessage); Messages.showErrorDialog(errorMessage, GctBundle.message("sample.import.error.title")); return false; } List<File> sampleRoots = downloadResult.getSampleRoots(); if (sampleRoots.size() == 0) { Messages.showErrorDialog(GctBundle.message("git.project.dir.empty"), GctBundle.message("sample.import.error.title")); return false; } File rootFolder = downloadResult.getRootFolder(); try { String path = sample.getPath(); if (!Strings.isNullOrEmpty(path)) { // we have a path to work with, find the project that matches it path = trimSlashes(path); sampleSearch: { for (File sampleRoot : sampleRoots) { if (sampleRoot.getCanonicalPath().equals(new File(rootFolder, path).getCanonicalPath())) { // we found our sample root FileUtil.copyDir(sampleRoot, new File(project.getBasePath())); break sampleSearch; } } // we have a project that doesn't contain the sample root we're looking for... notify the user Messages.showErrorDialog(GctBundle.message("git.project.missing.sample.root", path), GctBundle.message("sample.import.error.title")); return false; } } else { // no root was specified, just grab the first root FileUtil.copyDir(sampleRoots.get(0), new File(project.getBasePath())); } } catch (IOException e) { LOG.error(e); Messages.showErrorDialog(GctBundle.message("sample.copy.to.project.failed"), GctBundle.message("sample.import.error.title")); return false; } UsageTracker.getInstance().trackEvent(GctTracking.CATEGORY, GctTracking.SAMPLES, sampleName, null); GradleProjectImporter.getInstance().importProject(project.getBaseDir()); // TODO : display the correct starting file for users return true; }
From source file:com.google.gct.idea.settings.ExportSettings.java
License:Apache License
public static void doExport(String path) { final Set<ExportableComponent> exportableComponents = new HashSet<ExportableComponent>(Arrays .asList(ApplicationManager.getApplication().getComponents(ExportableApplicationComponent.class))); exportableComponents.addAll(/*from www. j a v a 2 s. com*/ ServiceBean.loadServicesFromBeans(ExportableComponent.EXTENSION_POINT, ExportableComponent.class)); if (exportableComponents.isEmpty()) { return; } Set<File> exportFiles = new HashSet<File>(); for (final ExportableComponent markedComponent : exportableComponents) { ContainerUtil.addAll(exportFiles, markedComponent.getExportFiles()); } ApplicationManager.getApplication().saveSettings(); final File saveFile = new File(path); try { if (saveFile.exists()) { final int ret = Messages.showOkCancelDialog( IdeBundle.message("prompt.overwrite.settings.file", FileUtil.toSystemDependentName(saveFile.getPath())), IdeBundle.message("title.file.already.exists"), Messages.getWarningIcon()); if (ret != Messages.OK) return; } final JarOutputStream output = new JarOutputStream(new FileOutputStream(saveFile)); try { final File configPath = new File(PathManager.getConfigPath()); final HashSet<String> writtenItemRelativePaths = new HashSet<String>(); for (File file : exportFiles) { final String rPath = FileUtil.getRelativePath(configPath, file); assert rPath != null; final String relativePath = FileUtil.toSystemIndependentName(rPath); if (file.exists()) { ZipUtil.addFileOrDirRecursively(output, saveFile, file, relativePath, null, writtenItemRelativePaths); } } exportInstalledPlugins(saveFile, output, writtenItemRelativePaths); final File magicFile = new File(FileUtil.getTempDirectory(), SETTINGS_JAR_MARKER); FileUtil.createIfDoesntExist(magicFile); magicFile.deleteOnExit(); ZipUtil.addFileToZip(output, magicFile, SETTINGS_JAR_MARKER, writtenItemRelativePaths, null); } finally { output.close(); } } catch (IOException e1) { Messages.showErrorDialog(IdeBundle.message("error.writing.settings", e1.toString()), IdeBundle.message("title.error.writing.file")); } }
From source file:com.google.gct.idea.settings.ImportSettings.java
License:Apache License
/** * Parse and update the IDEA settings in the jar at <code>path</code>. * Note: This function might require a restart of the application. * @param path The location of the jar with the new IDEA settings. *///from w ww. j a v a 2 s .c om public static void doImport(String path) { final File saveFile = new File(path); try { if (!saveFile.exists()) { Messages.showErrorDialog(IdeBundle.message("error.cannot.find.file", presentableFileName(saveFile)), DIALOG_TITLE); return; } // What is this file used for? final ZipEntry magicEntry = new ZipFile(saveFile).getEntry(SETTINGS_JAR_MARKER); if (magicEntry == null) { Messages.showErrorDialog( "The file " + presentableFileName(saveFile) + " contains no settings to import", DIALOG_TITLE); return; } final ArrayList<ExportableComponent> registeredComponents = new ArrayList<ExportableComponent>( Arrays.asList(ApplicationManager.getApplication() .getComponents(ExportableApplicationComponent.class))); registeredComponents.addAll(ServiceBean.loadServicesFromBeans(ExportableComponent.EXTENSION_POINT, ExportableComponent.class)); List<ExportableComponent> storedComponents = getComponentsStored(saveFile, registeredComponents); Set<String> relativeNamesToExtract = new HashSet<String>(); for (final ExportableComponent aComponent : storedComponents) { final File[] exportFiles = aComponent.getExportFiles(); for (File exportFile : exportFiles) { final File configPath = new File(PathManager.getConfigPath()); final String rPath = FileUtil.getRelativePath(configPath, exportFile); assert rPath != null; final String relativePath = FileUtil.toSystemIndependentName(rPath); relativeNamesToExtract.add(relativePath); } } relativeNamesToExtract.add(PluginManager.INSTALLED_TXT); final File tempFile = new File(PathManager.getPluginTempPath() + "/" + saveFile.getName()); FileUtil.copy(saveFile, tempFile); File outDir = new File(PathManager.getConfigPath()); final ImportSettingsFilenameFilter filenameFilter = new ImportSettingsFilenameFilter( relativeNamesToExtract); StartupActionScriptManager.ActionCommand unzip = new StartupActionScriptManager.UnzipCommand(tempFile, outDir, filenameFilter); StartupActionScriptManager.addActionCommand(unzip); // remove temp file StartupActionScriptManager.ActionCommand deleteTemp = new StartupActionScriptManager.DeleteCommand( tempFile); StartupActionScriptManager.addActionCommand(deleteTemp); UpdateSettings.getInstance().forceCheckForUpdateAfterRestart(); String key = ApplicationManager.getApplication().isRestartCapable() ? "message.settings.imported.successfully.restart" : "message.settings.imported.successfully"; final int ret = Messages.showOkCancelDialog( IdeBundle.message(key, ApplicationNamesInfo.getInstance().getProductName(), ApplicationNamesInfo.getInstance().getFullProductName()), IdeBundle.message("title.restart.needed"), Messages.getQuestionIcon()); if (ret == Messages.OK) { ((ApplicationEx) ApplicationManager.getApplication()).restart(true); } } catch (ZipException e1) { Messages.showErrorDialog( "Error reading file " + presentableFileName(saveFile) + ".\\nThere was " + e1.getMessage(), DIALOG_TITLE); } catch (IOException e1) { Messages.showErrorDialog(IdeBundle.message("error.reading.settings.file.2", presentableFileName(saveFile), e1.getMessage()), DIALOG_TITLE); } }
From source file:com.google.idea.blaze.android.resources.actions.BlazeCreateResourceDirectoryDialog.java
License:Open Source License
@Override protected void doOKAction() { final String dirName = myDirectoryNameTextField.getText(); assert dirName != null; PsiDirectory resourceDirectory = getResourceDirectory(); if (resourceDirectory == null) { Module module = LangDataKeys.MODULE.getData(myDataContext); Messages.showErrorDialog(AndroidBundle.message("check.resource.dir.error", module), CommonBundle.getErrorTitle()); // Not much the user can do, just close the dialog. super.doOKAction(); return;//from www . ja v a2 s .c o m } myValidator = myValidatorFactory.create(resourceDirectory); if (myValidator.checkInput(dirName) && myValidator.canClose(dirName)) { super.doOKAction(); } }
From source file:com.google.idea.blaze.android.run.binary.BlazeAndroidBinaryRunConfigurationStateEditor.java
License:Open Source License
BlazeAndroidBinaryRunConfigurationStateEditor(RunConfigurationStateEditor commonStateEditor, Project project) { this.commonStateEditor = commonStateEditor; setupUI(project);//from w w w . j a va 2 s . c o m userIdField.setMinValue(0); activityField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (!project.isInitialized()) { return; } // We find all Activity classes in the module for the selected variant // (or any of its deps). final JavaPsiFacade facade = JavaPsiFacade.getInstance(project); PsiClass activityBaseClass = facade.findClass(AndroidUtils.ACTIVITY_BASE_CLASS_NAME, ProjectScope.getAllScope(project)); if (activityBaseClass == null) { Messages.showErrorDialog(panel, AndroidBundle.message("cant.find.activity.class.error")); return; } GlobalSearchScope searchScope = GlobalSearchScope.projectScope(project); PsiClass initialSelection = facade.findClass(activityField.getChildComponent().getText(), searchScope); TreeClassChooser chooser = TreeClassChooserFactory.getInstance(project) .createInheritanceClassChooser("Select Activity Class", searchScope, activityBaseClass, initialSelection, null); chooser.showDialog(); PsiClass selClass = chooser.getSelected(); if (selClass != null) { // This must be done because Android represents // inner static class paths differently than java. String qualifiedActivityName = ActivityLocatorUtils.getQualifiedActivityName(selClass); activityField.getChildComponent().setText(qualifiedActivityName); } } }); ActionListener listener = e -> activityField.setEnabled(launchCustomButton.isSelected()); launchCustomButton.addActionListener(listener); launchDefaultButton.addActionListener(listener); launchNothingButton.addActionListener(listener); instantRunCheckBox.setVisible(InstantRunExperiment.INSTANT_RUN_ENABLED.getValue()); /* Only one of mobile-install and instant run can be selected at any one time */ mobileInstallCheckBox.addActionListener(e -> { if (mobileInstallCheckBox.isSelected()) { instantRunCheckBox.setSelected(false); } }); instantRunCheckBox.addActionListener(e -> { if (instantRunCheckBox.isSelected()) { mobileInstallCheckBox.setSelected(false); } }); mobileInstallCheckBox .addActionListener(e -> splitApksCheckBox.setVisible(mobileInstallCheckBox.isSelected())); useWorkProfileIfPresentCheckBox.addActionListener(e -> { setUserIdEnabled(!useWorkProfileIfPresentCheckBox.isSelected()); }); }
From source file:com.google.idea.blaze.android.sync.importer.problems.AddGeneratedResourceDirectoryNavigatable.java
License:Open Source License
private static void addDirectoryToProjectView(Project project, File projectViewFile, ArtifactLocation generatedResDir) { ProjectViewEdit edit = ProjectViewEdit.editLocalProjectView(project, builder -> { ListSection<GenfilesPath> existingSection = builder.getLast(GeneratedAndroidResourcesSection.KEY); ListSection.Builder<GenfilesPath> directoryBuilder = ListSection .update(GeneratedAndroidResourcesSection.KEY, existingSection); directoryBuilder.add(new GenfilesPath(generatedResDir.getRelativePath())); builder.replace(existingSection, directoryBuilder); return true; });// w w w. ja v a 2 s .c o m if (edit == null) { Messages.showErrorDialog( "Could not modify project view. Check for errors in your project view and try again", "Error"); return; } edit.apply(); VirtualFile projectView = VfsUtil.findFileByIoFile(projectViewFile, false); if (projectView != null) { FileEditorManager.getInstance(project).openEditor(new OpenFileDescriptor(project, projectView), true); } }