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

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

Introduction

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

Prototype

public static void openError(Shell parent, String title, String message) 

Source Link

Document

Convenience method to open a standard error dialog.

Usage

From source file:com.android.ide.eclipse.adt.internal.build.ConvertSwitchDialog.java

License:Open Source License

private void showWebPage() {
    try {//from w ww .  j av  a  2 s.  co m
        IWorkbench workbench = PlatformUI.getWorkbench();
        IWebBrowser browser = workbench.getBrowserSupport().getExternalBrowser();
        browser.openURL(new URL(URL));
    } catch (Exception e) {
        String message = String.format("Could not open browser. Vist\n%1$s\ninstead.", URL);
        MessageDialog.openError(getShell(), "Browser Error", message);
    }

}

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();/* ww  w  .j a v  a2  s.  com*/

    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.properties.PropertyFactory.java

License:Open Source License

public static Composite addWorkaround(Composite parent) {
    if (ButtonPropertyEditorPresentation.isInWorkaround) {
        Composite top = new Composite(parent, SWT.NONE);
        top.setLayout(new GridLayout(1, false));
        Label label = new Label(top, SWT.WRAP);
        label.setText("This dialog is shown instead of an inline text editor as a\n"
                + "workaround for an Eclipse bug specific to OSX Mountain Lion.\n"
                + "It should be fixed in Eclipse 4.3.");
        label.setForeground(top.getDisplay().getSystemColor(SWT.COLOR_RED));
        GridData data = new GridData();
        data.grabExcessVerticalSpace = false;
        data.grabExcessHorizontalSpace = false;
        data.horizontalAlignment = GridData.FILL;
        data.verticalAlignment = GridData.BEGINNING;
        label.setLayoutData(data);//from  w  w w .  ja v  a  2 s .  c  o  m

        Link link = new Link(top, SWT.NO_FOCUS);
        link.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
        link.setText("<a>https://bugs.eclipse.org/bugs/show_bug.cgi?id=388574</a>");
        link.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent event) {
                try {
                    IWorkbench workbench = PlatformUI.getWorkbench();
                    IWebBrowser browser = workbench.getBrowserSupport().getExternalBrowser();
                    browser.openURL(new URL(event.text));
                } catch (Exception e) {
                    String message = String.format("Could not open browser. Vist\n%1$s\ninstead.", event.text);
                    MessageDialog.openError(((Link) event.getSource()).getShell(), "Browser Error", message);
                }
            }
        });

        return top;
    }

    return null;
}

From source file:com.android.ide.eclipse.adt.internal.launch.AndroidLaunchController.java

License:Open Source License

/**
 * Looks for and returns an existing {@link ILaunchConfiguration} object for a
 * specified project./*w  w  w  .  j a  va 2 s  .c o  m*/
 * @param manager The {@link ILaunchManager}.
 * @param type The {@link ILaunchConfigurationType}.
 * @param projectName The name of the project
 * @return an existing <code>ILaunchConfiguration</code> object matching the project, or
 *      <code>null</code>.
 */
private static ILaunchConfiguration findConfig(ILaunchManager manager, ILaunchConfigurationType type,
        String projectName) {
    try {
        ILaunchConfiguration[] configs = manager.getLaunchConfigurations(type);

        for (ILaunchConfiguration config : configs) {
            if (config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, "") //$NON-NLS-1$
                    .equals(projectName)) {
                return config;
            }
        }
    } catch (CoreException e) {
        MessageDialog.openError(AdtPlugin.getShell(), "Launch Error", e.getStatus().getMessage());
    }

    // didn't find anything that matches. Return null
    return null;
}

From source file:com.android.ide.eclipse.adt.internal.launch.LaunchShortcut.java

License:Open Source License

@Override
public void launch(ISelection selection, String mode) {
    if (selection instanceof IStructuredSelection) {

        // get the object and the project from it
        IStructuredSelection structSelect = (IStructuredSelection) selection;
        Object o = structSelect.getFirstElement();

        // get the first (and normally only) element
        if (o instanceof IAdaptable) {
            IResource r = (IResource) ((IAdaptable) o).getAdapter(IResource.class);

            // get the project from the resource
            if (r != null) {
                IProject project = r.getProject();

                if (project != null) {
                    ProjectState state = Sdk.getProjectState(project);
                    if (state != null && state.isLibrary()) {

                        MessageDialog.openError(PlatformUI.getWorkbench().getDisplay().getActiveShell(),
                                "Android Launch", "Android library projects cannot be launched.");
                    } else {
                        // and launch
                        launch(project, mode);
                    }/*  ww w .  ja  v a2  s . c  om*/
                }
            }
        }
    }
}

From source file:com.android.ide.eclipse.adt.internal.project.ExportHelper.java

License:Open Source License

/**
 * Exports an unsigned release APK after prompting the user for a location.
 *
 * <strong>Must be called from the UI thread.</strong>
 *
 * @param project the project to export//from w  ww  .j  a v  a  2  s  .co m
 */
public static void exportUnsignedReleaseApk(final IProject project) {
    Shell shell = Display.getCurrent().getActiveShell();

    // get the java project to get the output directory
    IFolder outputFolder = BaseProjectHelper.getOutputFolder(project);
    if (outputFolder != null) {
        IPath binLocation = outputFolder.getLocation();

        // make the full path to the package
        String fileName = project.getName() + AndroidConstants.DOT_ANDROID_PACKAGE;

        File file = new File(binLocation.toOSString() + File.separator + fileName);

        if (file.exists() == false || file.isFile() == false) {
            MessageDialog.openError(Display.getCurrent().getActiveShell(), "Android IDE Plug-in", String
                    .format("Failed to export %1$s: %2$s doesn't exist!", project.getName(), file.getPath()));
            return;
        }

        // ok now pop up the file save window
        FileDialog fileDialog = new FileDialog(shell, SWT.SAVE);

        fileDialog.setText("Export Project");
        fileDialog.setFileName(fileName);

        final String saveLocation = fileDialog.open();
        if (saveLocation != null) {
            new Job("Android Release Export") {
                @Override
                protected IStatus run(IProgressMonitor monitor) {
                    try {
                        exportReleaseApk(project, new File(saveLocation), null, //key
                                null, //certificate
                                monitor);

                        // this is unsigned export. Let's tell the developers to run zip align
                        AdtPlugin.displayWarning("Android IDE Plug-in",
                                String.format("An unsigned package of the application was saved at\n%1$s\n\n"
                                        + "Before publishing the application you will need to:\n"
                                        + "- Sign the application with your release key,\n"
                                        + "- run zipalign on the signed package. ZipAlign is located in <SDK>/tools/\n\n"
                                        + "Aligning applications allows Android to use application resources\n"
                                        + "more efficiently.", saveLocation));

                        return Status.OK_STATUS;
                    } catch (CoreException e) {
                        AdtPlugin.displayError("Android IDE Plug-in",
                                String.format("Error exporting application:\n\n%1$s", e.getMessage()));
                        return e.getStatus();
                    }
                }
            }.schedule();
        }
    } else {
        MessageDialog.openError(shell, "Android IDE Plug-in", String
                .format("Failed to export %1$s: Could not get project output location", project.getName()));
    }
}

From source file:com.android.ide.eclipse.adt.internal.welcome.UsagePermissionPage.java

License:Open Source License

@Override
public void widgetSelected(SelectionEvent event) {
    if (event.getSource() == mLink) {
        try {//from   ww w .j a  v  a  2s  .co  m
            IWorkbench workbench = PlatformUI.getWorkbench();
            IWebBrowser browser = workbench.getBrowserSupport().getExternalBrowser();
            browser.openURL(new URL(event.text));
        } catch (Exception e) {
            String message = String.format("Could not open browser. Vist\n%1$s\ninstead.", event.text);
            MessageDialog.openError(getWizard().getContainer().getShell(), "Browser Error", message);
        }
    } else {
        // Radio buttons selected
        validatePage();
    }
}

From source file:com.android.ide.eclipse.adt.internal.wizards.actions.ExportAction.java

License:Open Source License

@Override
public void run(IAction action) {
    if (mSelection instanceof IStructuredSelection) {
        IStructuredSelection selection = (IStructuredSelection) mSelection;
        // get the unique selected item.
        if (selection.size() == 1) {
            Object element = selection.getFirstElement();

            // get the project object from it.
            IProject project = null;//ww  w  .j av a2  s  . c o m
            if (element instanceof IProject) {
                project = (IProject) element;
            } else if (element instanceof IAdaptable) {
                project = (IProject) ((IAdaptable) element).getAdapter(IProject.class);
            }

            // and finally do the action
            if (project != null) {
                if (!EclipseLintRunner.runLintOnExport(mShell, project)) {
                    return;
                }

                ProjectState state = Sdk.getProjectState(project);
                if (state.isLibrary()) {
                    MessageDialog.openError(mShell, "Android Export",
                            "Android library projects cannot be exported.");
                } else {
                    ExportHelper.exportUnsignedReleaseApk(project);
                }
            }
        }
    }
}

From source file:com.android.ide.eclipse.adt.internal.wizards.actions.ExportWizardAction.java

License:Open Source License

@Override
public void run(IAction action) {
    if (mSelection instanceof IStructuredSelection) {
        IStructuredSelection selection = (IStructuredSelection) mSelection;

        // get the unique selected item.
        if (selection.size() == 1) {
            Object element = selection.getFirstElement();

            // get the project object from it.
            IProject project = null;//from  w w w  .j ava2 s. co  m
            if (element instanceof IProject) {
                project = (IProject) element;
            } else if (element instanceof IAdaptable) {
                project = (IProject) ((IAdaptable) element).getAdapter(IProject.class);
            }

            // and finally do the action
            if (project != null) {
                if (!EclipseLintRunner.runLintOnExport(mWorkbench.getActiveWorkbenchWindow().getShell(),
                        project)) {
                    return;
                }

                ProjectState state = Sdk.getProjectState(project);
                if (state.isLibrary()) {
                    MessageDialog.openError(mWorkbench.getDisplay().getActiveShell(), "Android Export",
                            "Android library projects cannot be exported.");
                } else {
                    // call the export wizard on the current selection.
                    ExportWizard wizard = new ExportWizard();
                    wizard.init(mWorkbench, selection);
                    WizardDialog dialog = new WizardDialog(mWorkbench.getDisplay().getActiveShell(), wizard);
                    dialog.open();
                }
            }
        }
    }
}

From source file:com.android.ide.eclipse.adt.internal.wizards.newproject.NewProjectCreator.java

License:Open Source License

/**
 * Runs the operation in a different thread and display generated
 * exceptions.//from w  ww .jav a  2  s .c  o m
 *
 * @param op The asynchronous operation to run.
 */
private void runAsyncOperation(WorkspaceModifyOperation op) {
    try {
        mRunnableContext.run(true /* fork */, true /* cancelable */, op);
    } catch (InvocationTargetException e) {

        AdtPlugin.log(e, "New Project Wizard failed");

        // The runnable threw an exception
        Throwable t = e.getTargetException();
        if (t instanceof CoreException) {
            CoreException core = (CoreException) t;
            if (core.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
                // The error indicates the file system is not case sensitive
                // and there's a resource with a similar name.
                MessageDialog.openError(AdtPlugin.getShell(), "Error", "Error: Case Variant Exists");
            } else {
                ErrorDialog.openError(AdtPlugin.getShell(), "Error", core.getMessage(), core.getStatus());
            }
        } else {
            // Some other kind of exception
            String msg = t.getMessage();
            Throwable t1 = t;
            while (msg == null && t1.getCause() != null) {
                msg = t1.getMessage();
                t1 = t1.getCause();
            }
            if (msg == null) {
                msg = t.toString();
            }
            MessageDialog.openError(AdtPlugin.getShell(), "Error", msg);
        }
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}