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.google.gct.idea.appengine.gradle.action.GenerateEndpointAction.java
License:Apache License
/** * Generates an endpoint class in the specified module and updates the gradle build file * to include endpoint dependencies if they don't already exist. *//*from ww w . java 2 s . c om*/ private void doAction(Project project, Module module, String packageName, String directory, @NonNls String classType) { if (classType.isEmpty()) { Messages.showErrorDialog(project, "Class object is required for Endpoint generation", ERROR_MESSAGE_TITLE); return; } // Check if there is a file with the same name as the file that will contain the endpoint class String endpointFileName = directory + "/" + classType + ENDPOINT_CLASS_SUFFIX; File temp = new File(endpointFileName); if (temp.exists()) { Messages.showErrorDialog(project, "\'" + temp.getName() + "\" already exists", ERROR_MESSAGE_TITLE); return; } AppEngineTemplates.TemplateInfo templateInfo = AppEngineTemplates.getAppEngineTemplate(ENDPOINT_TEMPLATE); if (templateInfo == null) { Messages.showErrorDialog(project, DEFAULT_ERROR_MESSAGE, ERROR_MESSAGE_TITLE); return; } final Template template = Template.createFromPath(templateInfo.getFile()); if (template == null) { Messages.showErrorDialog(project, DEFAULT_ERROR_MESSAGE, ERROR_MESSAGE_TITLE); return; } final File projectRoot = new File(project.getBasePath()); final File moduleRoot = new File(projectRoot, module.getName()); // Create the replacement map final Map<String, Object> replacementMap = new HashMap<String, Object>(); try { replacementMap.put(TemplateMetadata.ATTR_PROJECT_OUT, moduleRoot.getCanonicalPath()); } catch (Exception e) { Messages.showErrorDialog("Failed to resolve Module output destination : " + e.getMessage(), ERROR_MESSAGE_TITLE); LOG.error(e); return; } String className = String.valueOf(Character.toLowerCase(classType.charAt(0))); if (classType.length() > 1) { className += classType.substring(1); } replacementMap.put(ENTITY_NAME, className); replacementMap.put(ENTITY_TYPE, classType); replacementMap.put(TemplateMetadata.ATTR_SRC_DIR, directory); replacementMap.put(TemplateMetadata.ATTR_PACKAGE_NAME, packageName); AppEngineTemplates.populateEndpointParameters(replacementMap, packageName); ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { template.render(projectRoot, moduleRoot, replacementMap); } }); // Add any missing Endpoint dependency to the build file and sync updateBuildFile(project, module, template); // Open the new Endpoint class in the editor VirtualFile endpointFile = LocalFileSystem.getInstance().findFileByPath(endpointFileName); TemplateUtils.openEditor(project, endpointFile); }
From source file:com.google.gct.idea.debugger.CloudDebugProcessStateController.java
License:Apache License
/** * Called from the {@link CloudBreakpointHandler} to remove breakpoints from the server. * * @param breakpointId the {@link com.google.api.services.debugger.model.Breakpoint} Id to delete *///from w w w . ja v a 2 s. co m void deleteBreakpoint(@NotNull String breakpointId) { if (myState == null) { throw new IllegalStateException(); } final Debugger client = CloudDebuggerClient.getCloudDebuggerClient(myState); if (client == null) { LOG.warn("no client available attempting to setBreakpoint"); Messages.showErrorDialog(myState.getProject(), GctBundle.getString("clouddebug.bad.login.message"), GctBundle.getString("clouddebug.errortitle")); return; } try { client.debuggees().breakpoints().delete(myState.getDebuggeeId(), breakpointId).execute(); } catch (IOException ex) { LOG.warn("exception deleting breakpoint " + breakpointId, ex); } }
From source file:com.google.gct.idea.debugger.CloudDebugProcessStateController.java
License:Apache License
/** * Returns a fully realized {@link Breakpoint} with all results possibly asynchronously * * @param id the breakpoint id to resolve * @return a {@link ListenableFuture} that is set once the full breakpoint is loaded *//*from w w w.j a v a 2s .co m*/ @Nullable public ListenableFuture<Breakpoint> resolveBreakpoint(@NotNull final String id) { if (myState == null) { return null; } final Debugger client = CloudDebuggerClient.getCloudDebuggerClient(myState); if (client == null) { LOG.warn("no client available attempting to resolveBreakpointAsync"); Messages.showErrorDialog(myState.getProject(), GctBundle.getString("clouddebug.bad.login.message"), GctBundle.getString("clouddebug.errortitle")); return null; } List<Breakpoint> currentList = myState.getCurrentServerBreakpointList(); final SettableFuture<Breakpoint> future = SettableFuture.create(); final Ref<Breakpoint> resultingBreakpointRef = new Ref<Breakpoint>(); for (Breakpoint serverBreakpointCandidate : currentList) { if (serverBreakpointCandidate.getId().equals(id)) { resultingBreakpointRef.set(serverBreakpointCandidate); break; } } if (!resultingBreakpointRef.isNull()) { // If our breakpoint isn't final, they we do not need extra information and // can return the result immediately. if (resultingBreakpointRef.get().getIsFinalState() != Boolean.TRUE) { future.set(resultingBreakpointRef.get()); return future; } ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { @Override public void run() { //At this point, the user has selected a final state breakpoint which is not yet hydrated. //So we query the server to get this final on a worker thread and then run the runnable // back on ui GetBreakpointResponse response; try { response = client.debuggees().breakpoints().get(myState.getDebuggeeId(), id).execute(); Breakpoint result = response.getBreakpoint(); if (result != null) { resultingBreakpointRef.set(result); myFullFinalBreakpoints.put(id, result); future.set(resultingBreakpointRef.get()); } } catch (IOException e) { LOG.warn("IOException hydrating a snapshot. User may have deleted the snapshot", e); future.setException(e); } } }); return future; } LOG.warn("could not resolve breakpoint " + id); return null; }
From source file:com.google.gct.idea.debugger.CloudDebugProcessStateController.java
License:Apache License
/** * Called from the {@link CloudDebugProcessHandler} to set a breakpoint. * * @param serverBreakpoint the breakpoint being added * @param errorHandler the handler that gets called if an error occurs during the add call * @return the ID of the newly added breakpoint, if successful *///from w ww . ja v a 2 s .c om String setBreakpoint(@NotNull Breakpoint serverBreakpoint, @Nullable BreakpointErrorHandler errorHandler) { if (myState == null) { return null; } final Debugger client = CloudDebuggerClient.getCloudDebuggerClient(myState); if (client == null) { LOG.warn("no client available attempting to setBreakpoint"); Messages.showErrorDialog(myState.getProject(), GctBundle.getString("clouddebug.bad.login.message"), GctBundle.getString("clouddebug.errortitle")); return null; } try { // Delete old breakpoints at this location. List<Breakpoint> currentList = myState.getCurrentServerBreakpointList(); SourceLocation location = serverBreakpoint.getLocation(); for (Breakpoint serverBp : currentList) { if (serverBp.getIsFinalState() != Boolean.TRUE && serverBp.getLocation().getLine() != null && serverBp.getLocation().getLine().equals(location.getLine()) && !Strings.isNullOrEmpty(serverBp.getLocation().getPath()) && serverBp.getLocation().getPath().equals(location.getPath())) { deleteBreakpoint(serverBp.getId()); } } SetBreakpointResponse addResponse = client.debuggees().breakpoints() .set(myState.getDebuggeeId(), serverBreakpoint).execute(); if (addResponse != null && addResponse.getBreakpoint() != null) { Breakpoint result = addResponse.getBreakpoint(); if (result.getStatus() != null && result.getStatus().getIsError() == Boolean.TRUE && errorHandler != null && result.getStatus().getDescription() != null) { errorHandler.handleError(BreakpointUtil.getUserErrorMessage(result.getStatus())); } return addResponse.getBreakpoint().getId(); } } catch (IOException ex) { LOG.error("exception setting a breakpoint", ex); } return null; }
From source file:com.google.gct.idea.git.UploadSourceAction.java
License:Apache License
private static void uploadProjectToGoogleCloud(@NotNull final Project project, @Nullable final VirtualFile file) { BasicAction.saveAll();/*from w w w . ja v a 2 s. c o m*/ project.save(); final GitRepository gitRepository = getGitRepository(project, file); final boolean gitDetected = gitRepository != null; final VirtualFile root = gitDetected ? gitRepository.getRoot() : project.getBaseDir(); // check for existing git repo boolean externalRemoteDetected = false; if (gitDetected) { final String gcpRemote = GcpHttpAuthDataProvider.findGCPRemoteUrl(gitRepository); if (gcpRemote != null) { Messages.showErrorDialog(project, GctBundle.message("uploadtogcp.alreadyexists"), "Google"); return; } externalRemoteDetected = !gitRepository.getRemotes().isEmpty(); } ChooseProjectDialog dialog = new ChooseProjectDialog(project, GctBundle.message("uploadtogcp.selecttext"), GctBundle.message("uploadtogcp.oktext")); DialogManager.show(dialog); if (!dialog.isOK() || dialog.getCredentialedUser() == null || Strings.isNullOrEmpty(dialog.getProjectId())) { return; } final String projectId = dialog.getProjectId(); final CredentialedUser user = dialog.getCredentialedUser(); // finish the job in background final boolean finalExternalRemoteDetected = externalRemoteDetected; new Task.Backgroundable(project, GctBundle.message("uploadtogcp.backgroundtitle")) { @Override public void run(@NotNull ProgressIndicator indicator) { // creating empty git repo if git is not initialized LOG.info("Binding local project with Git"); if (!gitDetected) { LOG.info("No git detected, creating empty git repo"); indicator.setText(GctBundle.message("uploadtogcp.indicatorinit")); if (!createEmptyGitRepository(project, root, indicator)) { return; } } GitRepositoryManager repositoryManager = GitUtil.getRepositoryManager(project); final GitRepository repository = repositoryManager.getRepositoryForRoot(root); LOG.assertTrue(repository != null, "GitRepository is null for root " + root); if (repository == null) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { Messages.showErrorDialog(project, GctBundle.message("uploadtogcp.failedtocreategit"), "Google"); } }); return; } final String remoteUrl = GcpHttpAuthDataProvider.getGcpUrl(projectId); final String remoteName = finalExternalRemoteDetected ? "cloud-platform" : "origin"; LOG.info("Adding Google as a remote host"); indicator.setText(GctBundle.message("uploadtogcp.addingremote")); if (!addGitRemote(project, repository, remoteName, remoteUrl)) { return; } boolean succeeded = false; try { PropertiesComponent.getInstance(project).setValue(GcpHttpAuthDataProvider.GCP_USER, user.getEmail()); LOG.info("Fetching from Google remote"); indicator.setText(GctBundle.message("uploadtogcp.fetching")); if (!fetchGit(project, indicator, repository, remoteName) || hasRemoteBranch(project, repository, remoteName, projectId)) { return; } // create sample commit for binding project if (!performFirstCommitIfRequired(project, root, repository, indicator)) { return; } //git push origin master LOG.info("Pushing to Google master"); indicator.setText(GctBundle.message("uploadtogcp.pushingtotgcp")); if (!pushCurrentBranch(project, repository, remoteName, remoteUrl)) { return; } succeeded = true; } finally { if (!succeeded) { //remove the remote if possible on a failure, so the user can try again. removeGitRemote(project, repository, remoteName); } } showInfoURL(project, remoteName, GctBundle.message("uploadtogcp.success"), remoteUrl); } }.queue(); }
From source file:com.google.gct.idea.git.UploadSourceAction.java
License:Apache License
private static boolean isGitSupported(final Project project) { final GitVcsApplicationSettings settings = GitVcsApplicationSettings.getInstance(); final String executable = settings.getPathToGit(); final GitVersion version; try {/* w w w. j a va 2 s .c o m*/ version = GitVersion.identifyVersion(executable); } catch (Exception e) { Messages.showErrorDialog(project, GctBundle.message("uploadtogcp.giterror"), e.getMessage()); return false; } if (!version.isSupported()) { Messages.showWarningDialog(project, GctBundle.message("uploadtogcp.git.unsupported.message", version.toString(), GitVersion.MIN), GctBundle.message("uploadtogcp.giterror")); return false; } return true; }
From source file:com.google.gct.idea.git.UploadSourceAction.java
License:Apache License
private static boolean addGitRemote(final @NotNull Project project, @NotNull GitRepository repository, @NotNull String remote, final @NotNull String url) { final GitSimpleHandler handler = new GitSimpleHandler(project, repository.getRoot(), GitCommand.REMOTE); handler.setSilent(true);/*from ww w .j a v a2 s .c o m*/ try { handler.addParameters("add", remote, url); handler.run(); if (handler.getExitCode() != 0) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { Messages.showErrorDialog(project, GctBundle.message("uploadtogcp.addremotefailed", url, handler.getStderr()), GctBundle.message("uploadtogcp.addremotefailedtitle")); } }); return false; } // catch newly added remote repository.update(); return true; } catch (final VcsException e) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { Messages.showErrorDialog(project, GctBundle.message("uploadtogcp.addremotefailed", url, e.toString()), GctBundle.message("uploadtogcp.addremotefailedtitle")); } }); return false; } }
From source file:com.google.gct.idea.git.UploadSourceAction.java
License:Apache License
private static boolean performFirstCommitIfRequired(@NotNull final Project project, @NotNull VirtualFile root, @NotNull GitRepository repository, @NotNull ProgressIndicator indicator) { // check if there are no commits if (!repository.isFresh()) { return true; }//from w w w .ja v a 2 s . c o m LOG.info("Trying to commit"); try { LOG.info("Adding files for commit"); indicator.setText(GctBundle.getString("uploadsourceaction.addfiles")); // ask for files to add final List<VirtualFile> trackedFiles = ChangeListManager.getInstance(project).getAffectedFiles(); final Collection<VirtualFile> untrackedFiles = filterOutIgnored(project, repository.getUntrackedFilesHolder().retrieveUntrackedFiles()); trackedFiles.removeAll(untrackedFiles); // fix IDEA-119855 final List<VirtualFile> allFiles = new ArrayList<VirtualFile>(); allFiles.addAll(trackedFiles); allFiles.addAll(untrackedFiles); final Ref<GCPUntrackedFilesDialog> dialogRef = new Ref<GCPUntrackedFilesDialog>(); ApplicationManager.getApplication().invokeAndWait(new Runnable() { @Override public void run() { GCPUntrackedFilesDialog dialog = new GCPUntrackedFilesDialog(project, allFiles); if (!trackedFiles.isEmpty()) { dialog.setSelectedFiles(trackedFiles); } DialogManager.show(dialog); dialogRef.set(dialog); } }, indicator.getModalityState()); final GCPUntrackedFilesDialog dialog = dialogRef.get(); final Collection<VirtualFile> files2commit = dialog.getSelectedFiles(); if (!dialog.isOK() || files2commit.isEmpty()) { LOG.warn("user canceled out of initial commit. aborting..."); return false; } Collection<VirtualFile> files2add = ContainerUtil.intersection(untrackedFiles, files2commit); Collection<VirtualFile> files2rm = ContainerUtil.subtract(trackedFiles, files2commit); Collection<VirtualFile> modified = new HashSet<VirtualFile>(trackedFiles); modified.addAll(files2commit); GitFileUtils.addFiles(project, root, files2add); GitFileUtils.deleteFilesFromCache(project, root, files2rm); // commit LOG.info("Performing commit"); indicator.setText(GctBundle.getString("uploadsourceaction.performingcommit")); GitSimpleHandler handler = new GitSimpleHandler(project, root, GitCommand.COMMIT); handler.setStdoutSuppressed(false); handler.addParameters("-m", dialog.getCommitMessage()); handler.endOptions(); handler.run(); VcsFileUtil.refreshFiles(project, modified); } catch (final VcsException e) { LOG.warn(e); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { Messages.showErrorDialog(project, GctBundle.message("uploadtogcp.initialcommitfailed", e.toString()), GctBundle.message("uploadtogcp.initialcommitfailedtitle")); } }); return false; } LOG.info("Successfully created initial commit"); return true; }
From source file:com.google.gct.intellij.endpoints.action.GenerateClientLibrariesAction.java
License:Apache License
@Override public void actionPerformed(AnActionEvent e) { final Project project = e.getProject(); final Module appEngineModule = e.getData(LangDataKeys.MODULE); if (project == null || appEngineModule == null) { Messages.showErrorDialog(project, "Please select an App Engine module", ERROR_MESSAGE_TITLE); return;/*ww w . j av a2s . c o m*/ } AppEngineMavenProject appEngineMavenProject = AppEngineMavenProject.get(appEngineModule); if (appEngineMavenProject == null) { Messages.showErrorDialog(project, "Please select a valid Maven enabled App Engine project", ERROR_MESSAGE_TITLE); return; } Module androidLibModule = ModuleManager.getInstance(project) .findModuleByName(project.getName() + GctConstants.ANDROID_GCM_LIB_MODULE_SUFFIX); if (androidLibModule == null) { Messages.showWarningDialog(project, "Could not find associated Android library module (" + project.getName() + GctConstants.ANDROID_GCM_LIB_MODULE_SUFFIX + "), skipping copying of client libraries into Android", "Warning"); } doAction(appEngineMavenProject, androidLibModule); }
From source file:com.google.gct.intellij.endpoints.action.GenerateCloudBackendAction.java
License:Apache License
@Override public void actionPerformed(AnActionEvent e) { final Module androidModule = e.getData(LangDataKeys.MODULE); final Project project = e.getProject(); if (project == null || androidModule == null) { Messages.showErrorDialog(project, "Please select an android module to create a backend for", MESSAGE_TITLE);/*from w ww. j a va2 s . c om*/ return; } if (AndroidFacet.getInstance(androidModule) == null) { Messages.showErrorDialog(project, "Selected Module : " + androidModule.getName() + " is not an Android Module. If you selected the " + "root project, try selecting the Android Module instead.", MESSAGE_TITLE); return; } if (!passesExternalChecks(project)) { return; } // Make sure that the dir does not exist final String appEngineModuleName = androidModule.getName() + GctConstants.APP_ENGINE_MODULE_SUFFIX; final String appEngineLfsModuleFileDir = project.getBasePath() + File.separatorChar + appEngineModuleName; if (LocalFileSystem.getInstance().findFileByPath(appEngineLfsModuleFileDir) != null) { Messages.showErrorDialog(project, "Unable to generate an App Engine Backend named '" + appEngineModuleName + "'.\n" + "The directory '" + appEngineLfsModuleFileDir + "' already exists.", MESSAGE_TITLE); return; } // Look for the root package final ManifestInfo manifestInfo = ManifestInfo.get(androidModule); if (manifestInfo == null) { Messages.showErrorDialog(project, "Unable to generate an App Engine Backend named '" + appEngineModuleName + "'.\n" + "Cannot find the AndroidManifest.xml for the '" + androidModule.getName() + "' module.", MESSAGE_TITLE); return; } final String rootPackage = manifestInfo.getPackage(); if (rootPackage == null || rootPackage.isEmpty()) { Messages.showErrorDialog(project, "Unable to generate an App Engine Backend named '" + appEngineModuleName + "'.\n" + "Cannot find a package attribute in the <manifest> tag of AndroidManifest.xml.", MESSAGE_TITLE); return; } final String androidEndpointsLibModuleName = androidModule.getName() + GctConstants.ANDROID_GCM_LIB_MODULE_SUFFIX; final File androidLibModuleRoot = new File(project.getBasePath(), androidEndpointsLibModuleName); if (androidLibModuleRoot.exists()) { Messages.showErrorDialog(project, "Unable to generate an Android Library named named '" + androidEndpointsLibModuleName + "'.\n" + "The directory '" + androidLibModuleRoot.getPath() + "' already exists.", MESSAGE_TITLE); return; } final GenerateBackendDialog dialog = new GenerateBackendDialog(project); dialog.show(); if (dialog.isOK()) { doAction(project, androidModule, dialog); } }