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

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

Introduction

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

Prototype

public MessageDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage,
        int dialogImageType, int defaultIndex, String... dialogButtonLabels) 

Source Link

Document

Create a message dialog.

Usage

From source file:com.android.ide.eclipse.adt.internal.assetstudio.ConfigureAssetSetPage.java

License:Open Source License

@Override
public void widgetSelected(SelectionEvent e) {
    if (mIgnore) {
        return;/*from ww  w  .ja  v  a  2  s.co m*/
    }

    Object source = e.getSource();
    boolean updateQuickly = true;

    // Tabs
    if (source == mImageRadio) {
        mValues.sourceType = CreateAssetSetWizardState.SourceType.IMAGE;
        chooseForegroundTab((Button) source, mImageForm);
        configureAssetType(mValues.type);
        updateTrimOptions();
    } else if (source == mClipartRadio) {
        mValues.sourceType = CreateAssetSetWizardState.SourceType.CLIPART;
        chooseForegroundTab((Button) source, mClipartForm);
        configureAssetType(mValues.type);
        updateTrimOptions();
    } else if (source == mTextRadio) {
        mValues.sourceType = CreateAssetSetWizardState.SourceType.TEXT;
        updateFontLabel();
        chooseForegroundTab((Button) source, mTextForm);
        configureAssetType(mValues.type);
        mText.setFocus();
        updateTrimOptions();
    }

    // Choose image file
    if (source == mPickImageButton) {
        FileDialog dialog = new FileDialog(mPickImageButton.getShell(), SWT.OPEN);

        String curLocation = mImagePathText.getText().trim();
        if (!curLocation.isEmpty()) {
            dialog.setFilterPath(curLocation);
        }

        String file = dialog.open();
        if (file != null) {
            mValues.imagePath = new File(file);
            mImagePathText.setText(file);
        }
    }

    // Enforce Radio Groups
    if (source == mCropRadio) {
        mCropRadio.setSelection(true); // Ensure that you can't toggle it off
        mCenterRadio.setSelection(false);
        mValues.crop = true;
    } else if (source == mCenterRadio) {
        mCenterRadio.setSelection(true);
        mCropRadio.setSelection(false);
        mValues.crop = false;
    }
    if (source == mSquareRadio) {
        mValues.shape = GraphicGenerator.Shape.SQUARE;
        setShape(mValues.shape);
    } else if (source == mCircleButton) {
        mValues.shape = GraphicGenerator.Shape.CIRCLE;
        setShape(mValues.shape);
    } else if (source == mNoShapeRadio) {
        mValues.shape = GraphicGenerator.Shape.NONE;
        setShape(mValues.shape);
    }

    if (source == mTrimCheckBox) {
        mValues.trim = mTrimCheckBox.getSelection();
    }

    if (source == mHoloDarkRadio) {
        mHoloDarkRadio.setSelection(true);
        mHoloLightRadio.setSelection(false);
        mValues.holoDark = true;
    } else if (source == mHoloLightRadio) {
        mHoloLightRadio.setSelection(true);
        mHoloDarkRadio.setSelection(false);
        mValues.holoDark = false;
    }

    if (source == mChooseClipart) {
        MessageDialog dialog = new MessageDialog(mChooseClipart.getShell(), "Choose Clip Art", null,
                "Choose Clip Art Image:", MessageDialog.NONE, new String[] { "Close" }, 0) {
            @Override
            protected Control createCustomArea(Composite parent) {
                // Outer form which just establishes a width for the inner form which
                // wraps in a RowLayout
                Composite outer = new Composite(parent, SWT.NONE);
                GridLayout gridLayout = new GridLayout();
                outer.setLayout(gridLayout);

                Composite chooserForm = new Composite(outer, SWT.NONE);
                GridData gd = new GridData();
                gd.grabExcessVerticalSpace = true;
                gd.widthHint = 450;
                chooserForm.setLayoutData(gd);
                RowLayout clipartFormLayout = new RowLayout(SWT.HORIZONTAL);
                clipartFormLayout.center = true;
                clipartFormLayout.wrap = true;
                chooserForm.setLayout(clipartFormLayout);

                MouseAdapter clickListener = new MouseAdapter() {
                    @Override
                    public void mouseDown(MouseEvent event) {
                        // Clicked on some of the sample art
                        if (event.widget instanceof ImageControl) {
                            ImageControl image = (ImageControl) event.widget;
                            mValues.clipartName = (String) image.getData();
                            close();

                            updateClipartPreview();
                            updatePreview();
                        }
                    }
                };
                Display display = chooserForm.getDisplay();
                Color hoverColor = display.getSystemColor(SWT.COLOR_RED);
                Iterator<String> clipartImages = GraphicGenerator.getClipartNames();
                while (clipartImages.hasNext()) {
                    String name = clipartImages.next();
                    try {
                        BufferedImage icon = GraphicGenerator.getClipartIcon(name);
                        if (icon != null) {
                            Image swtImage = SwtUtils.convertToSwt(display, icon, true, -1);
                            ImageControl img = new ImageControl(chooserForm, SWT.NONE, swtImage);
                            img.setData(name);
                            img.setHoverColor(hoverColor);
                            img.addMouseListener(clickListener);
                        }
                    } catch (IOException e1) {
                        AdtPlugin.log(e1, null);
                    }
                }
                outer.pack();
                outer.layout();
                return outer;
            }
        };
        dialog.open();
    }

    if (source == mBgButton) {
        ColorDialog dlg = new ColorDialog(mBgButton.getShell());
        dlg.setRGB(mBgColor);
        dlg.setText("Choose a new Background Color");
        RGB rgb = dlg.open();
        if (rgb != null) {
            // Dispose the old color, create the
            // new one, and set into the label
            mValues.background = rgb;
            updateColor(mBgButton.getDisplay(), rgb, true /*background*/);
        }
    } else if (source == mFgButton) {
        ColorDialog dlg = new ColorDialog(mFgButton.getShell());
        dlg.setRGB(mFgColor);
        dlg.setText("Choose a new Foreground Color");
        RGB rgb = dlg.open();
        if (rgb != null) {
            // Dispose the old color, create the
            // new one, and set into the label
            mValues.foreground = rgb;
            updateColor(mFgButton.getDisplay(), rgb, false /*background*/);
        }
    }

    if (source == mFontButton) {
        FontDialog dialog = new FontDialog(mFontButton.getShell());
        FontData[] fontList;
        if (mFontButton.getData() == null) {
            fontList = mFontButton.getDisplay().getFontList(mValues.getTextFont().getFontName(),
                    true /*scalable*/);
        } else {
            fontList = mFontButton.getFont().getFontData();
        }
        dialog.setFontList(fontList);
        FontData data = dialog.open();
        if (data != null) {
            Font font = new Font(mFontButton.getDisplay(), dialog.getFontList());
            mFontButton.setFont(font);
            mFontButton.setData(font);

            // Always use a large font for the rendering, even though user is typically
            // picking small font sizes in the font chooser
            //int dpi = mFontButton.getDisplay().getDPI().y;
            //int height = (int) Math.round(fontData.getHeight() * dpi / 72.0);
            int fontHeight = new TextRenderUtil.Options().fontSize;
            FontData fontData = font.getFontData()[0];
            int awtStyle = java.awt.Font.PLAIN;
            int swtStyle = fontData.getStyle();
            if ((swtStyle & SWT.ITALIC) != 0) {
                awtStyle |= java.awt.Font.ITALIC;
            }
            if ((swtStyle & SWT.BOLD) != 0) {
                awtStyle = java.awt.Font.BOLD;
            }
            mValues.setTextFont(new java.awt.Font(fontData.getName(), awtStyle, fontHeight));

            updateFontLabel();
            mFontButton.getParent().pack();
        }
    }

    if (source == mPaddingSlider) {
        mValues.padding = getPadding();
        mPercentLabel.setText(Integer.toString(getPadding()) + '%');

        // When dragging the slider, only do periodic updates
        updateQuickly = false;
    }

    requestUpdatePreview(updateQuickly);
}

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);// w w  w  . j a v  a  2s.c om

    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  . j  a  va  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 {//  w ww .j  a va  2s  . co 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());
    }//w w  w.  ja  v  a 2s .  c  o 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:/*from  w ww.  j ava  2 s . c o  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  . ja v a  2s  .  com
 * <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);//w  w  w. ja  v  a2  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.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.//from   w w  w.  j  a  v  a 2 s  .com
 * @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.ConfigureAssetSetPage.java

License:Open Source License

@Override
public void widgetSelected(SelectionEvent e) {
    if (mIgnore) {
        return;/*from  w w w. j  a v a  2s.co  m*/
    }

    Object source = e.getSource();
    boolean updateQuickly = true;

    // Tabs
    if (source == mImageRadio) {
        mValues.sourceType = CreateAssetSetWizardState.SourceType.IMAGE;
        chooseForegroundTab((Button) source, mImageForm);
    } else if (source == mClipartRadio) {
        mValues.sourceType = CreateAssetSetWizardState.SourceType.CLIPART;
        chooseForegroundTab((Button) source, mClipartForm);
    } else if (source == mTextRadio) {
        mValues.sourceType = CreateAssetSetWizardState.SourceType.TEXT;
        updateFontLabel();
        chooseForegroundTab((Button) source, mTextForm);
        mText.setFocus();
    }

    // Choose image file
    if (source == mPickImageButton) {
        FileDialog dialog = new FileDialog(mPickImageButton.getShell(), SWT.OPEN);
        String file = dialog.open();
        if (file != null) {
            mValues.imagePath = new File(file);
            mImagePathText.setText(file);
        }
    }

    // Enforce Radio Groups
    if (source == mCropRadio) {
        mCropRadio.setSelection(true); // Ensure that you can't toggle it off
        mCenterRadio.setSelection(false);
        mValues.crop = true;
    } else if (source == mCenterRadio) {
        mCenterRadio.setSelection(true);
        mCropRadio.setSelection(false);
        mValues.crop = false;
    }
    if (source == mSquareRadio) {
        mValues.shape = GraphicGenerator.Shape.SQUARE;
        setShape(mValues.shape);
    } else if (source == mCircleButton) {
        mValues.shape = GraphicGenerator.Shape.CIRCLE;
        setShape(mValues.shape);
    } else if (source == mNoShapeRadio) {
        mValues.shape = GraphicGenerator.Shape.NONE;
        setShape(mValues.shape);
    }

    if (SUPPORT_LAUNCHER_ICON_TYPES) {
        if (source == mSimpleRadio) {
            mSimpleRadio.setSelection(true);
            mGlossyRadio.setSelection(false);
            mFancyRadio.setSelection(false);
        } else if (source == mFancyRadio) {
            mFancyRadio.setSelection(true);
            mSimpleRadio.setSelection(false);
            mGlossyRadio.setSelection(false);
        } else if (source == mGlossyRadio) {
            mGlossyRadio.setSelection(true);
            mSimpleRadio.setSelection(false);
            mFancyRadio.setSelection(false);
        }
    }

    if (source == mTrimCheckBox) {
        mValues.trim = mTrimCheckBox.getSelection();
    }

    if (source == mHoloDarkRadio) {
        mHoloDarkRadio.setSelection(true);
        mHoloLightRadio.setSelection(false);
    } else if (source == mHoloLightRadio) {
        mHoloLightRadio.setSelection(true);
        mHoloDarkRadio.setSelection(false);
    }

    if (source == mChooseClipart) {
        MessageDialog dialog = new MessageDialog(mChooseClipart.getShell(), "Choose Clip Art", null,
                "Choose Clip Art Image:", MessageDialog.NONE, new String[] { "Close" }, 0) {
            @Override
            protected Control createCustomArea(Composite parent) {
                // Outer form which just establishes a width for the inner form which
                // wraps in a RowLayout
                Composite outer = new Composite(parent, SWT.NONE);
                GridLayout gridLayout = new GridLayout();
                outer.setLayout(gridLayout);

                Composite chooserForm = new Composite(outer, SWT.NONE);
                GridData gd = new GridData();
                gd.grabExcessVerticalSpace = true;
                gd.widthHint = 450;
                chooserForm.setLayoutData(gd);
                RowLayout clipartFormLayout = new RowLayout(SWT.HORIZONTAL);
                clipartFormLayout.center = true;
                clipartFormLayout.wrap = true;
                chooserForm.setLayout(clipartFormLayout);

                MouseAdapter clickListener = new MouseAdapter() {
                    @Override
                    public void mouseDown(MouseEvent event) {
                        // Clicked on some of the sample art
                        if (event.widget instanceof ImageControl) {
                            ImageControl image = (ImageControl) event.widget;
                            mValues.clipartName = (String) image.getData();
                            close();

                            updateClipartPreview();
                            updatePreview();
                        }
                    }
                };
                Display display = chooserForm.getDisplay();
                Color hoverColor = display.getSystemColor(SWT.COLOR_RED);
                Iterator<String> clipartImages = GraphicGenerator.getClipartNames();
                while (clipartImages.hasNext()) {
                    String name = clipartImages.next();
                    try {
                        BufferedImage icon = GraphicGenerator.getClipartIcon(name);
                        if (icon != null) {
                            Image swtImage = SwtUtils.convertToSwt(display, icon, true, -1);
                            ImageControl img = new ImageControl(chooserForm, SWT.NONE, swtImage);
                            img.setData(name);
                            img.setHoverColor(hoverColor);
                            img.addMouseListener(clickListener);
                        }
                    } catch (IOException e1) {
                        AdtPlugin.log(e1, null);
                    }
                }
                outer.pack();
                outer.layout();
                return outer;
            }
        };
        dialog.open();
    }

    if (source == mBgButton) {
        ColorDialog dlg = new ColorDialog(mBgButton.getShell());
        dlg.setRGB(mBgColor);
        dlg.setText("Choose a new Background Color");
        RGB rgb = dlg.open();
        if (rgb != null) {
            // Dispose the old color, create the
            // new one, and set into the label
            mValues.background = rgb;
            updateColor(mBgButton.getDisplay(), rgb, true /*background*/);
        }
    } else if (source == mFgButton) {
        ColorDialog dlg = new ColorDialog(mFgButton.getShell());
        dlg.setRGB(mFgColor);
        dlg.setText("Choose a new Foreground Color");
        RGB rgb = dlg.open();
        if (rgb != null) {
            // Dispose the old color, create the
            // new one, and set into the label
            mValues.foreground = rgb;
            updateColor(mFgButton.getDisplay(), rgb, false /*background*/);
        }
    }

    if (source == mFontButton) {
        FontDialog dialog = new FontDialog(mFontButton.getShell());
        FontData[] fontList;
        if (mFontButton.getData() == null) {
            fontList = mFontButton.getDisplay().getFontList(mValues.getTextFont().getFontName(),
                    true /*scalable*/);
        } else {
            fontList = mFontButton.getFont().getFontData();
        }
        dialog.setFontList(fontList);
        FontData data = dialog.open();
        if (data != null) {
            Font font = new Font(mFontButton.getDisplay(), dialog.getFontList());
            mFontButton.setFont(font);
            mFontButton.setData(font);

            // Always use a large font for the rendering, even though user is typically
            // picking small font sizes in the font chooser
            //int dpi = mFontButton.getDisplay().getDPI().y;
            //int height = (int) Math.round(fontData.getHeight() * dpi / 72.0);
            int fontHeight = new TextRenderUtil.Options().fontSize;
            FontData fontData = font.getFontData()[0];
            int awtStyle = java.awt.Font.PLAIN;
            int swtStyle = fontData.getStyle();
            if ((swtStyle & SWT.ITALIC) != 0) {
                awtStyle |= java.awt.Font.ITALIC;
            }
            if ((swtStyle & SWT.BOLD) != 0) {
                awtStyle = java.awt.Font.BOLD;
            }
            mValues.setTextFont(new java.awt.Font(fontData.getName(), awtStyle, fontHeight));

            updateFontLabel();
            mFontButton.getParent().pack();
        }
    }

    if (source == mPaddingSlider) {
        mValues.padding = getPadding();
        mPercentLabel.setText(Integer.toString(getPadding()) + '%');

        // When dragging the slider, only do periodic updates
        updateQuickly = false;
    }

    requestUpdatePreview(updateQuickly);
}