List of usage examples for org.eclipse.jface.dialogs MessageDialog open
public int open()
From source file:com.android.ide.eclipse.adt.internal.project.CompatibilityLibraryHelper.java
License:Open Source License
/** * Returns the correct tag to use for the given view tag. This is normally * the same as the tag itself. However, for some views which are not available * on all platforms, this will:/*from ww w. j a va2s . co m*/ * <ul> * <li> Check if the view is available in the compatibility library, * and if so, if the support library is not installed, will offer to * install it via the SDK manager. * <li> (The tool may also offer to adjust the minimum SDK of the project * up to a level such that the given tag is supported directly, and then * this method will return the original tag.) * <li> Check whether the compatibility library is included in the project, and * if not, offer to copy it into the workspace and add a library dependency. * <li> Return the alternative tag. For example, for "GridLayout", it will * (if the minimum SDK is less than 14) return "com.android.support.v7.GridLayout" * instead. * </ul> * * @param project the project to add the dependency into * @param tag the tag to look up, such as "GridLayout" * @return the tag to use in the layout, normally the same as the input tag but possibly * an equivalent compatibility library tag instead. */ @NonNull public static String getTagFor(@NonNull IProject project, @NonNull String tag) { boolean isGridLayout = tag.equals(FQCN_GRID_LAYOUT); boolean isSpace = tag.equals(FQCN_SPACE); if (isGridLayout || isSpace) { int minSdk = ManifestInfo.get(project).getMinSdkVersion(); if (minSdk < 14) { // See if the support library is installed in the SDK area // See if there is a local project in the workspace providing the // project IProject supportProject = getSupportProjectV7(); if (supportProject != null) { // Make sure I have a dependency on it ProjectState state = Sdk.getProjectState(project); if (state != null) { for (LibraryState library : state.getLibraries()) { if (supportProject.equals(library.getProjectState().getProject())) { // Found it: you have the compatibility library and have linked // to it: use the alternative tag return isGridLayout ? FQCN_GRID_LAYOUT_V7 : FQCN_SPACE_V7; } } } } // Ask user to install it String message = String.format("%1$s requires API level 14 or higher, or a compatibility " + "library for older versions.\n\n" + " Do you want to install the compatibility library?", tag); MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(), "Warning", null, message, MessageDialog.QUESTION, new String[] { "Install", "Cancel" }, 1 /* default button: Cancel */); int answer = dialog.open(); if (answer == 0) { if (supportProject != null) { // Just add library dependency if (!AddCompatibilityJarAction.addLibraryDependency(supportProject, project, true /* waitForFinish */)) { return tag; } } else { // Install library AND add dependency if (!AddCompatibilityJarAction.installLibrary(project, true /* waitForFinish */)) { return tag; } } return isGridLayout ? FQCN_GRID_LAYOUT_V7 : FQCN_SPACE_V7; } } } return tag; }
From source file:com.android.ide.eclipse.adt.internal.project.SupportLibraryHelper.java
License:Open Source License
/** * Returns the correct tag to use for the given view tag. This is normally * the same as the tag itself. However, for some views which are not available * on all platforms, this will:// ww w . java 2s . co m * <ul> * <li> Check if the view is available in the compatibility library, * and if so, if the support library is not installed, will offer to * install it via the SDK manager. * <li> (The tool may also offer to adjust the minimum SDK of the project * up to a level such that the given tag is supported directly, and then * this method will return the original tag.) * <li> Check whether the compatibility library is included in the project, and * if not, offer to copy it into the workspace and add a library dependency. * <li> Return the alternative tag. For example, for "GridLayout", it will * (if the minimum SDK is less than 14) return "com.android.support.v7.GridLayout" * instead. * </ul> * * @param project the project to add the dependency into * @param tag the tag to look up, such as "GridLayout" * @return the tag to use in the layout, normally the same as the input tag but possibly * an equivalent compatibility library tag instead. */ @NonNull public static String getTagFor(@NonNull IProject project, @NonNull String tag) { boolean isGridLayout = tag.equals(FQCN_GRID_LAYOUT); boolean isSpace = tag.equals(FQCN_SPACE); if (isGridLayout || isSpace) { int minSdk = ManifestInfo.get(project).getMinSdkVersion(); if (minSdk < 14) { // See if the support library is installed in the SDK area // See if there is a local project in the workspace providing the // project IProject supportProject = getSupportProjectV7(); if (supportProject != null) { // Make sure I have a dependency on it ProjectState state = Sdk.getProjectState(project); if (state != null) { for (LibraryState library : state.getLibraries()) { if (supportProject.equals(library.getProjectState().getProject())) { // Found it: you have the compatibility library and have linked // to it: use the alternative tag return isGridLayout ? FQCN_GRID_LAYOUT_V7 : FQCN_SPACE_V7; } } } } // Ask user to install it String message = String.format("%1$s requires API level 14 or higher, or a compatibility " + "library for older versions.\n\n" + " Do you want to install the compatibility library?", tag); MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(), "Warning", null, message, MessageDialog.QUESTION, new String[] { "Install", "Cancel" }, 1 /* default button: Cancel */); int answer = dialog.open(); if (answer == 0) { if (supportProject != null) { // Just add library dependency if (!AddSupportJarAction.addLibraryDependency(supportProject, project, true /* waitForFinish */)) { return tag; } } else { // Install library AND add dependency if (!AddSupportJarAction.installGridLayoutLibrary(project, true /* waitForFinish */)) { return tag; } } return isGridLayout ? FQCN_GRID_LAYOUT_V7 : FQCN_SPACE_V7; } } } return tag; }
From source file:com.android.ide.eclipse.adt.internal.wizards.templates.TemplateHandler.java
License:Open Source License
@SuppressWarnings("unused") private boolean canOverwrite(File file) { if (file.exists()) { // Warn that the file already exists and ask the user what to do if (!mYesToAll) { MessageDialog dialog = new MessageDialog(null, "File Already Exists", null, String.format("%1$s already exists.\nWould you like to replace it?", file.getPath()), MessageDialog.QUESTION, new String[] { // Yes will be moved to the end because it's the default "Yes", "No", "Cancel", "Yes to All" }, 0);//from w ww . j a v a2s. c om int result = dialog.open(); switch (result) { case 0: // Yes break; case 3: // Yes to all mYesToAll = true; break; case 1: // No return false; case SWT.DEFAULT: case 2: // Cancel mNoToAll = true; return false; } } if (mBackupMergedFiles) { return makeBackup(file); } else { return file.delete(); } } return true; }
From source file:com.android.ide.eclipse.auidt.AdtPlugin.java
License:Open Source License
/** * Checks the location of the SDK is valid and if it is, grab the SDK API version * from the SDK.// w ww.ja v a2 s.c om * @return false if the location is not correct. */ private boolean checkSdkLocationAndId() { String sdkLocation = AdtPrefs.getPrefs().getOsSdkFolder(); if (sdkLocation == null || sdkLocation.length() == 0) { return false; } return checkSdkLocationAndId(sdkLocation, new CheckSdkErrorHandler() { private String mTitle = "Android SDK Verification"; @Override public boolean handleError(Solution solution, String message) { displayMessage(solution, message, MessageDialog.ERROR); return false; } @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) { 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() { // Windows only: open the standalone external SDK Manager since we know // that ADT on Windows is bound to be locking some SDK folders. if (SdkConstants.CURRENT_PLATFORM == SdkConstants.PLATFORM_WINDOWS) { 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.auidt.internal.assetstudio.CreateAssetSetWizard.java
License:Open Source License
@Override public boolean performFinish() { Map<String, Map<String, BufferedImage>> categories = mConfigureAssetPage.generateImages(false); IProject project = mValues.project;/*from w ww .ja v a2s . co m*/ // 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); } } NewXmlFileWizard.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.auidt.internal.editors.layout.gle2.ExportScreenshotAction.java
License:Open Source License
@Override public void run() { Shell shell = AdtPlugin.getDisplay().getActiveShell(); 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;//from w ww .ja v a2 s.c o m } 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.auidt.internal.editors.layout.gre.ClientRulesEngine.java
License:Open Source License
@Override public String displayFragmentSourceInput() { try {/* w w w .ja v a 2 s . c o m*/ // 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.getDisplay().getActiveShell(); 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)) { 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.gldebugger.ShaderEditor.java
License:Apache License
public void widgetSelected(SelectionEvent e) { if (e.getSource() == uploadShader && null != current) { uploadShader();//from w ww .j a va 2 s . c om 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 = mGLFramesView.debugContexts.get(contextId).currentContext.serverShader.shaders.get(name); styledText.setText(current.source); }
From source file:com.android.ide.eclipse.traceview.editors.TraceviewEditor.java
License:Apache License
@Override public void doSaveAs() { Shell shell = getSite().getShell();/* w ww . j a v a 2s . co m*/ final IEditorInput input = getEditorInput(); final IEditorInput newInput; if (input instanceof FileEditorInput) { // the file is part of the current workspace FileEditorInput fileEditorInput = (FileEditorInput) input; SaveAsDialog dialog = new SaveAsDialog(shell); IFile original = fileEditorInput.getFile(); if (original != null) { dialog.setOriginalFile(original); } dialog.create(); if (original != null && !original.isAccessible()) { String message = String.format("The original file ''%s'' has been deleted or is not accessible.", original.getName()); dialog.setErrorMessage(null); dialog.setMessage(message, IMessageProvider.WARNING); } if (dialog.open() == Window.CANCEL) { return; } IPath filePath = dialog.getResult(); if (filePath == null) { return; } IWorkspace workspace = ResourcesPlugin.getWorkspace(); IFile file = workspace.getRoot().getFile(filePath); if (copy(shell, fileEditorInput.getURI(), file.getLocationURI()) == null) { return; } try { file.refreshLocal(IFile.DEPTH_ZERO, null); } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } newInput = new FileEditorInput(file); setInput(newInput); setPartName(newInput.getName()); } else if (input instanceof FileStoreEditorInput) { // the file is not part of the current workspace FileStoreEditorInput fileStoreEditorInput = (FileStoreEditorInput) input; FileDialog dialog = new FileDialog(shell, SWT.SAVE); IPath oldPath = URIUtil.toPath(fileStoreEditorInput.getURI()); if (oldPath != null) { dialog.setFileName(oldPath.lastSegment()); dialog.setFilterPath(oldPath.toOSString()); } String path = dialog.open(); if (path == null) { return; } // Check whether file exists and if so, confirm overwrite final File localFile = new File(path); if (localFile.exists()) { MessageDialog overwriteDialog = new MessageDialog(shell, "Save As", null, String.format("%s already exists.\nDo you want to replace it?", path), MessageDialog.WARNING, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1); // 'No' is the default if (overwriteDialog.open() != Window.OK) { return; } } IFileStore destFileStore = copy(shell, fileStoreEditorInput.getURI(), localFile.toURI()); if (destFileStore != null) { IFile file = getWorkspaceFile(destFileStore); if (file != null) { newInput = new FileEditorInput(file); } else { newInput = new FileStoreEditorInput(destFileStore); } setInput(newInput); setPartName(newInput.getName()); } } }
From source file:com.appnativa.studio.MessageDialogEx.java
License:Open Source License
/** * Convenience method to open a simple dialog as specified by the * <code>kind</code> flag.//from ww w . j a va2 s . co m * * @param kind * the kind of dialog to open, one of {@link #ERROR}, * {@link #INFORMATION}, {@link #QUESTION}, {@link #WARNING}, * {@link #CONFIRM}, or {@link #QUESTION_WITH_CANCEL}. * @param parent * the parent shell of the dialog, or <code>null</code> if none * @param title * the dialog's title, or <code>null</code> if none * @param message * the message * @param style * {@link SWT#NONE} for a default dialog, or {@link SWT#SHEET} for a * dialog with sheet behavior * @return the id of the button pressed */ public static int openEx(int kind, Shell parent, String title, String message, int style) { MessageDialog dialog = new MessageDialog(parent, title, null, message, kind, getButtonLabels(kind), style); return dialog.open(); }