List of usage examples for org.eclipse.jface.dialogs MessageDialog open
public int open()
From source file:com.amazonaws.eclipse.elasticbeanstalk.jobs.TerminateEnvironmentJob.java
License:Open Source License
@Override protected IStatus run(IProgressMonitor monitor) { AWSElasticBeanstalk client = AwsToolkitCore.getClientFactory(environment.getAccountId()) .getElasticBeanstalkClientByEndpoint(environment.getRegionEndpoint()); EnvironmentBehavior behavior = (EnvironmentBehavior) environment.getServer() .loadAdapter(EnvironmentBehavior.class, monitor); final DialogHolder dialogHolder = new DialogHolder(); Display.getDefault().syncExec(new Runnable() { public void run() { MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(), "Confirm environment termination", AwsToolkitCore.getDefault().getImageRegistry().get(AwsToolkitCore.IMAGE_AWS_ICON), "Are you sure you want to terminate the environment " + environment.getEnvironmentName() + "? All EC2 instances in the environment will be terminated and you will be unable to use " + "this environment again until you have recreated it.", MessageDialog.QUESTION_WITH_CANCEL, new String[] { "OK", "Cancel" }, 1); dialogHolder.dialog = dialog; dialog.open(); }// w ww.j av a 2 s .c o m }); if (dialogHolder.dialog.getReturnCode() != 0) { behavior.updateServerState(IServer.STATE_STOPPED); return Status.OK_STATUS; } try { if (doesEnvironmentExist()) { client.terminateEnvironment( new TerminateEnvironmentRequest().withEnvironmentName(environment.getEnvironmentName())); } // It's more correct to set the state to stopping, rather than stopped immediately, // but if we set it to stopping, WTP will block workspace actions waiting for the // environment's state to get updated to stopped. To prevent this, we stop immediately. behavior.updateServerState(IServer.STATE_STOPPED); return Status.OK_STATUS; } catch (AmazonClientException ace) { return new Status(Status.ERROR, ElasticBeanstalkPlugin.PLUGIN_ID, "Unable to terminate environment " + environment.getEnvironmentName() + " : " + ace.getMessage(), ace); } }
From source file:com.amazonaws.eclipse.explorer.dynamodb.DynamoDBTableNode.java
License:Apache License
/** * Sets the status of the table that this node represents, and changes to * the corresponding open action./*ww w .ja v a 2 s .c o m*/ */ public void setTableStatus(final TableStatus tableStatus) { this.tableStatus = tableStatus; if (tableStatus == null) { setOpenAction(new Action() { @Override public void run() { /* * Update the table status immediately when the node is * being opened, but has not been set with table status. */ AmazonDynamoDB dynamoDBClient = AwsToolkitCore.getClientFactory().getDynamoDBV2Client(); boolean describeTableError = false; TableStatus updatedStatus = null; try { updatedStatus = TableStatus.valueOf( dynamoDBClient.describeTable(new DescribeTableRequest().withTableName(tableName)) .getTable().getTableStatus()); } catch (AmazonServiceException ase) { if (ase.getErrorCode().equalsIgnoreCase("ResourceNotFoundException") == true) { /* Show warning that the table has already been deleted */ MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(), "Cannot open this table", AwsToolkitCore.getDefault().getImageRegistry() .get(AwsToolkitCore.IMAGE_AWS_ICON), "Table has been deleted.", MessageDialog.ERROR, new String[] { "OK" }, 0); dialog.open(); /* * We need to explicitly refresh the tree view if a * table node has already been deleted in DynamoDB */ DynamoDBContentProvider.getInstance().refresh(); return; } else { describeTableError = true; } } catch (IllegalArgumentException iae) { /* Unrecognized table status */ describeTableError = true; } if (describeTableError) { /* * Still allow the user to open the table editor if we * cannot get the table status now. (But the background * job will still keep trying to update the table * status). */ setOpenAction(new OpenTableEditorAction(tableName)); return; } /* assert: updatedStatus != null */ setTableStatus(updatedStatus); DynamoDBTableNode.this.getOpenAction().run(); } }); } else if (tableStatus == TableStatus.ACTIVE) { /* * Open the table editor only when the node is in ACTIVE status. */ setOpenAction(new OpenTableEditorAction(tableName)); } else { /* * For CREATING/DELETING/UPDATING, suppress opening the table editor. * Show a warning on the table status instead. */ setOpenAction(new Action() { @Override public void run() { /* Show the warning that the table is CREATING/DELETING/UPDATING */ MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(), "Cannot open this table", AwsToolkitCore.getDefault().getImageRegistry().get(AwsToolkitCore.IMAGE_AWS_ICON), "Cannot open this table(" + tableName + "), since it is in the status of " + tableStatus + ".", MessageDialog.ERROR, new String[] { "OK" }, 0); dialog.open(); } }); } }
From source file:com.amazonaws.eclipse.explorer.sns.CreateTopicWizard.java
License:Apache License
@Override public boolean performFinish() { String topicName = (String) page.getInputValue(TOPIC_NAME_INPUT); String displayName = (String) page.getInputValue(DISPLAY_NAME_INPUT); AmazonSNS client = AwsToolkitCore.getClientFactory().getSNSClient(); CreateTopicResult result = client.createTopic(new CreateTopicRequest(topicName)); if (displayName != null && displayName.length() > 0) { try {/*from ww w. j a va 2 s .c o m*/ client.setTopicAttributes(new SetTopicAttributesRequest().withTopicArn(result.getTopicArn()) .withAttributeName(DISPLAY_NAME_ATTRIBUTE).withAttributeValue(displayName)); } catch (AmazonClientException exception) { AwsToolkitCore.getDefault().logException("Error setting topic display name", exception); MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(), "Warning", null, ("The topic was successfully created, but the display " + "name could not be set (" + exception.toString() + ")"), MessageDialog.WARNING, new String[] { "OK" }, 0); dialog.open(); } } ContentProviderRegistry.refreshAllContentProviders(); return true; }
From source file:com.amazonaws.eclipse.lambda.invoke.handler.InvokeFunctionHandler.java
License:Open Source License
private static void askForDeploymentFirst(IProject project) { MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(), "Function not uploaded yet", null, "You need to upload the function to Lambda before invoking it.", MessageDialog.INFORMATION, new String[] { "Upload now", "Cancel" }, 0); int result = dialog.open(); if (result == 0) { trackUploadWizardOpenedBeforeFunctionInvoke(); UploadFunctionToLambdaCommandHandler.doUploadFunctionProjectToLambda(project); }// w w w .ja v a2 s . c o m }
From source file:com.android.glesv2debugger.ShaderEditor.java
License:Apache License
@Override public void widgetSelected(SelectionEvent e) { if (e.getSource() == uploadShader && null != current) { uploadShader();/* w ww. j a v a2s .com*/ return; } else if (e.getSource() == restoreShader && null != current) { current.source = styledText.getText(); styledText.setText(current.originalSource); return; } if (list.getSelectionCount() < 1) return; if (null != current && !current.source.equals(styledText.getText())) { String[] btns = { "&Upload", "&Save", "&Discard" }; MessageDialog dialog = new MessageDialog(this.getShell(), "Shader Edited", null, "Shader source has been edited", MessageDialog.QUESTION, btns, 0); int rc = dialog.open(); if (rc == SWT.DEFAULT || rc == 0) uploadShader(); else if (rc == 1) current.source = styledText.getText(); // else if (rc == 2) do nothing; selection is changing } String[] details = list.getSelection()[0].split("\\s+"); final int contextId = Integer.parseInt(details[0], 16); int name = Integer.parseInt(details[2]); current = sampleView.debugContexts.get(contextId).currentContext.serverShader.shaders.get(name); styledText.setText(current.source); }
From source file:com.android.ide.eclipse.adt.AdtPlugin.java
License:Open Source License
/** * Checks the location of the SDK in the prefs is valid. * If it is not, display a warning dialog to the user and try to display * some useful link to fix the situation (setup the preferences, perform an * update, etc.)/* w w w .j a v a 2 s .c o m*/ * * @return True if the SDK location points to an SDK. * If false, the user has already been presented with a modal dialog explaining that. */ public boolean checkSdkLocationAndId() { String sdkLocation = AdtPrefs.getPrefs().getOsSdkFolder(); return checkSdkLocationAndId(sdkLocation, new CheckSdkErrorHandler() { private String mTitle = "Android SDK"; /** * Handle an error, which is the case where the check did not find any SDK. * This returns false to {@link AdtPlugin#checkSdkLocationAndId()}. */ @Override public boolean handleError(Solution solution, String message) { displayMessage(solution, message, MessageDialog.ERROR); return false; } /** * Handle an warning, which is the case where the check found an SDK * but it might need to be repaired or is missing an expected component. * * This returns true to {@link AdtPlugin#checkSdkLocationAndId()}. */ @Override public boolean handleWarning(Solution solution, String message) { displayMessage(solution, message, MessageDialog.WARNING); return true; } private void displayMessage(final Solution solution, final String message, final int dialogImageType) { final Display disp = getDisplay(); disp.asyncExec(new Runnable() { @Override public void run() { Shell shell = disp.getActiveShell(); if (shell == null) { shell = AdtPlugin.getShell(); } if (shell == null) { return; } String customLabel = null; switch (solution) { case OPEN_ANDROID_PREFS: customLabel = "Open Preferences"; break; case OPEN_P2_UPDATE: customLabel = "Check for Updates"; break; case OPEN_SDK_MANAGER: customLabel = "Open SDK Manager"; break; } String btnLabels[] = new String[customLabel == null ? 1 : 2]; btnLabels[0] = customLabel; btnLabels[btnLabels.length - 1] = IDialogConstants.CLOSE_LABEL; MessageDialog dialog = new MessageDialog(shell, // parent mTitle, null, // dialogTitleImage message, dialogImageType, btnLabels, btnLabels.length - 1); int index = dialog.open(); if (customLabel != null && index == 0) { switch (solution) { case OPEN_ANDROID_PREFS: openAndroidPrefs(); break; case OPEN_P2_UPDATE: openP2Update(); break; case OPEN_SDK_MANAGER: openSdkManager(); break; } } } }); } private void openSdkManager() { // Open the standalone external SDK Manager since we know // that ADT on Windows is bound to be locking some SDK folders. // // Also when this is invoked because SdkManagerAction.run() fails, this // test will fail and we'll fallback on using the internal one. if (SdkManagerAction.openExternalSdkManager()) { return; } // Otherwise open the regular SDK Manager bundled within ADT if (!SdkManagerAction.openAdtSdkManager()) { // We failed because the SDK location is undefined. In this case // let's open the preferences instead. openAndroidPrefs(); } } private void openP2Update() { Display disp = getDisplay(); if (disp == null) { return; } disp.asyncExec(new Runnable() { @Override public void run() { String cmdId = "org.eclipse.equinox.p2.ui.sdk.update"; //$NON-NLS-1$ IWorkbench wb = PlatformUI.getWorkbench(); if (wb == null) { return; } ICommandService cs = (ICommandService) wb.getService(ICommandService.class); IHandlerService is = (IHandlerService) wb.getService(IHandlerService.class); if (cs == null || is == null) { return; } Command cmd = cs.getCommand(cmdId); if (cmd != null && cmd.isDefined()) { try { is.executeCommand(cmdId, null/*event*/); } catch (Exception ignore) { AdtPlugin.log(ignore, "Failed to execute command %s", cmdId); } } } }); } private void openAndroidPrefs() { PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(getDisplay().getActiveShell(), "com.android.ide.eclipse.preferences.main", //$NON-NLS-1$ preferencePageId null, // displayedIds null); // data dialog.open(); } }); }
From source file:com.android.ide.eclipse.adt.internal.assetstudio.CreateAssetSetWizard.java
License:Open Source License
@Override public boolean performFinish() { Map<String, Map<String, BufferedImage>> categories = ConfigureAssetSetPage.generateImages(mValues, false, null);/*ww w .j ava 2s . com*/ IProject project = mValues.project; // Write out the images into the project boolean yesToAll = false; mCreatedFiles = new ArrayList<IResource>(); for (Map<String, BufferedImage> previews : categories.values()) { for (Map.Entry<String, BufferedImage> entry : previews.entrySet()) { String relativePath = entry.getKey(); IPath dest = new Path(relativePath); IFile file = project.getFile(dest); if (file.exists()) { // Warn that the file already exists and ask the user what to do if (!yesToAll) { MessageDialog dialog = new MessageDialog(null, "File Already Exists", null, String.format("%1$s already exists.\nWould you like to replace it?", file.getProjectRelativePath().toOSString()), MessageDialog.QUESTION, new String[] { // Yes will be moved to the end because it's the default "Yes", "No", "Cancel", "Yes to All" }, 0); int result = dialog.open(); switch (result) { case 0: // Yes break; case 3: // Yes to all yesToAll = true; break; case 1: // No continue; case SWT.DEFAULT: case 2: // Cancel return false; } } try { file.delete(true, new NullProgressMonitor()); } catch (CoreException e) { AdtPlugin.log(e, null); } } AdtUtils.createWsParentDirectory(file.getParent()); BufferedImage image = entry.getValue(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); try { ImageIO.write(image, "PNG", stream); //$NON-NLS-1$ byte[] bytes = stream.toByteArray(); InputStream is = new ByteArrayInputStream(bytes); file.create(is, true /*force*/, null /*progress*/); mCreatedFiles.add(file); } catch (IOException e) { AdtPlugin.log(e, null); } catch (CoreException e) { AdtPlugin.log(e, null); } try { file.getParent().refreshLocal(1, new NullProgressMonitor()); } catch (CoreException e) { AdtPlugin.log(e, null); } } } // Finally select the files themselves selectFiles(project, mCreatedFiles); return true; }
From source file:com.android.ide.eclipse.adt.internal.editors.layout.gle2.ExportScreenshotAction.java
License:Open Source License
@Override public void run() { Shell shell = AdtPlugin.getShell();//w w w .jav a 2 s.c o m ImageOverlay imageOverlay = mCanvas.getImageOverlay(); BufferedImage image = imageOverlay.getAwtImage(); if (image != null) { FileDialog dialog = new FileDialog(shell, SWT.SAVE); dialog.setFilterExtensions(new String[] { "*.png" }); //$NON-NLS-1$ String path = dialog.open(); if (path != null) { if (!path.endsWith(DOT_PNG)) { path = path + DOT_PNG; } File file = new File(path); if (file.exists()) { MessageDialog d = new MessageDialog(null, "File Already Exists", null, String.format("%1$s already exists.\nWould you like to replace it?", path), MessageDialog.QUESTION, new String[] { // Yes will be moved to the end because it's the default "Yes", "No" }, 0); int result = d.open(); if (result != 0) { return; } } try { ImageIO.write(image, "PNG", file); //$NON-NLS-1$ } catch (IOException e) { AdtPlugin.log(e, null); } } } else { MessageDialog.openError(shell, "Error", "Image not available"); } }
From source file:com.android.ide.eclipse.adt.internal.editors.layout.gre.ClientRulesEngine.java
License:Open Source License
@Override public String displayFragmentSourceInput() { try {/*ww w .j a va2 s .c om*/ // Compute a search scope: We need to merge all the subclasses // android.app.Fragment and android.support.v4.app.Fragment IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); IProject project = mRulesEngine.getProject(); final IJavaProject javaProject = BaseProjectHelper.getJavaProject(project); if (javaProject != null) { IType oldFragmentType = javaProject.findType(CLASS_V4_FRAGMENT); // First check to make sure fragments are available, and if not, // warn the user. IAndroidTarget target = Sdk.getCurrent().getTarget(project); // No, this should be using the min SDK instead! if (target.getVersion().getApiLevel() < 11 && oldFragmentType == null) { // Compatibility library must be present MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(), "Fragment Warning", null, "Fragments require API level 11 or higher, or a compatibility " + "library for older versions.\n\n" + " Do you want to install the compatibility library?", MessageDialog.QUESTION, new String[] { "Install", "Cancel" }, 1 /* default button: Cancel */); int answer = dialog.open(); if (answer == 0) { if (!AddSupportJarAction.install(project)) { return null; } } else { return null; } } // Look up sub-types of each (new fragment class and compatibility fragment // class, if any) and merge the two arrays - then create a scope from these // elements. IType[] fragmentTypes = new IType[0]; IType[] oldFragmentTypes = new IType[0]; if (oldFragmentType != null) { ITypeHierarchy hierarchy = oldFragmentType.newTypeHierarchy(new NullProgressMonitor()); oldFragmentTypes = hierarchy.getAllSubtypes(oldFragmentType); } IType fragmentType = javaProject.findType(CLASS_FRAGMENT); if (fragmentType != null) { ITypeHierarchy hierarchy = fragmentType.newTypeHierarchy(new NullProgressMonitor()); fragmentTypes = hierarchy.getAllSubtypes(fragmentType); } IType[] subTypes = new IType[fragmentTypes.length + oldFragmentTypes.length]; System.arraycopy(fragmentTypes, 0, subTypes, 0, fragmentTypes.length); System.arraycopy(oldFragmentTypes, 0, subTypes, fragmentTypes.length, oldFragmentTypes.length); scope = SearchEngine.createJavaSearchScope(subTypes, IJavaSearchScope.SOURCES); } Shell parent = AdtPlugin.getShell(); final AtomicReference<String> returnValue = new AtomicReference<String>(); final AtomicReference<SelectionDialog> dialogHolder = new AtomicReference<SelectionDialog>(); final SelectionDialog dialog = JavaUI.createTypeDialog(parent, new ProgressMonitorDialog(parent), scope, IJavaElementSearchConstants.CONSIDER_CLASSES, false, // Use ? as a default filter to fill dialog with matches "?", //$NON-NLS-1$ new TypeSelectionExtension() { @Override public Control createContentArea(Composite parentComposite) { Composite composite = new Composite(parentComposite, SWT.NONE); composite.setLayout(new GridLayout(1, false)); Button button = new Button(composite, SWT.PUSH); button.setText("Create New..."); button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String fqcn = createNewFragmentClass(javaProject); if (fqcn != null) { returnValue.set(fqcn); dialogHolder.get().close(); } } }); return composite; } @Override public ITypeInfoFilterExtension getFilterExtension() { return new ITypeInfoFilterExtension() { @Override public boolean select(ITypeInfoRequestor typeInfoRequestor) { int modifiers = typeInfoRequestor.getModifiers(); if (!Flags.isPublic(modifiers) || Flags.isInterface(modifiers) || Flags.isEnum(modifiers) || Flags.isAbstract(modifiers)) { return false; } return true; } }; } }); dialogHolder.set(dialog); dialog.setTitle("Choose Fragment Class"); dialog.setMessage("Select a Fragment class (? = any character, * = any string):"); if (dialog.open() == IDialogConstants.CANCEL_ID) { return null; } if (returnValue.get() != null) { return returnValue.get(); } Object[] types = dialog.getResult(); if (types != null && types.length > 0) { return ((IType) types[0]).getFullyQualifiedName(); } } catch (JavaModelException e) { AdtPlugin.log(e, null); } catch (CoreException e) { AdtPlugin.log(e, null); } return null; }
From source file:com.android.ide.eclipse.adt.internal.preferences.LintPreferencePage.java
License:Open Source License
private void storeSettings() { // Lint on Save, Lint on Export if (mCheckExportCheckbox != null) { AdtPrefs prefs = AdtPrefs.getPrefs(); prefs.setLintOnExport(mCheckExportCheckbox.getSelection()); prefs.setLintOnSave(mCheckFileCheckbox.getSelection()); }//from www.j av a 2s . c om if (mConfiguration == null) { return; } mConfiguration.startBulkEditing(); try { // Severities for (Map.Entry<Issue, Severity> entry : mSeverities.entrySet()) { Issue issue = entry.getKey(); Severity severity = entry.getValue(); if (mConfiguration.getSeverity(issue) != severity) { if ((severity == issue.getDefaultSeverity()) && issue.isEnabledByDefault()) { severity = null; } mConfiguration.setSeverity(issue, severity); } } } finally { mConfiguration.finishBulkEditing(); } if (!mInitialSeverities.equals(mSeverities)) { // Ask user whether we should re-run the rules. MessageDialog dialog = new MessageDialog(null, "Lint Settings Have Changed", null, "The list of enabled checks has changed. Would you like to run lint now " + "to update the results?", MessageDialog.QUESTION, new String[] { "Yes", "No" }, 0); // yes is the default int result = dialog.open(); if (result == 0) { // Run lint on all the open Android projects IWorkspace workspace = ResourcesPlugin.getWorkspace(); IProject[] projects = workspace.getRoot().getProjects(); List<IProject> androidProjects = new ArrayList<IProject>(projects.length); for (IProject project : projects) { if (project.isOpen() && BaseProjectHelper.isAndroidProject(project)) { androidProjects.add(project); } } EclipseLintRunner.startLint(androidProjects, null, null, false /*fatalOnly*/, true /*show*/); } } }