Example usage for org.eclipse.jface.dialogs MessageDialog QUESTION

List of usage examples for org.eclipse.jface.dialogs MessageDialog QUESTION

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs MessageDialog QUESTION.

Prototype

int QUESTION

To view the source code for org.eclipse.jface.dialogs MessageDialog QUESTION.

Click Source Link

Document

Constant for the question image, or a simple dialog with the question image and Yes/No buttons (value 3).

Usage

From source file:com.android.glesv2debugger.ShaderEditor.java

License:Apache License

@Override
public void widgetSelected(SelectionEvent e) {
    if (e.getSource() == uploadShader && null != current) {
        uploadShader();/*  ww  w .  j  av  a2 s  .c o m*/
        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.internal.assetstudio.CreateAssetSetWizard.java

License:Open Source License

@Override
public boolean performFinish() {
    Map<String, Map<String, BufferedImage>> categories = ConfigureAssetSetPage.generateImages(mValues, false,
            null);//from   w w  w. j a  v  a  2 s.co  m

    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();//from  w  ww.j  av  a2s .  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 {//w ww  . j a 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.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   w  w  w . j ava2 s . co  m*/

    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*/);
        }
    }
}

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://  ww  w. j  a va2s  .  c om
 * <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:/*from   www  . j a  v  a2 s .c om*/
 * <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  w  w. j  a va  2  s  .  co m
            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.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;// w ww . j  av  a  2 s. c  o 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.j  a  va  2  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");
    }
}