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

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

Introduction

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

Prototype

public int open() 

Source Link

Document

Opens this window, creating it first if it has not yet been created.

Usage

From source file:gov.nasa.ensemble.common.ui.wizard.DefaultOverwriteQueryImpl.java

License:Open Source License

@Override
public String queryOverwrite(String pathString) {
    if (alwaysOverwrite) {
        return ALL;
    }/*from  w  w  w. j a  v  a 2  s .  c o  m*/
    final String returnCode[] = { CANCEL };
    final String msg = NLS.bind(IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteQuestion,
            pathString);
    final String[] options = { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
            IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL };
    shell.getDisplay().syncExec(new Runnable() {
        @Override
        public void run() {
            MessageDialog dialog = new MessageDialog(shell,
                    IDEWorkbenchMessages.CopyFilesAndFoldersOperation_question, null, msg,
                    MessageDialog.QUESTION, options, 0) {
                @Override
                protected int getShellStyle() {
                    return super.getShellStyle() | SWT.SHEET;
                }
            };
            dialog.open();
            int returnVal = dialog.getReturnCode();
            String[] returnCodes = { YES, ALL, NO, CANCEL };
            returnCode[0] = returnVal == -1 ? CANCEL : returnCodes[returnVal];
        }
    });
    if (returnCode[0] == ALL) {
        alwaysOverwrite = true;
    } else if (returnCode[0] == CANCEL) {
        canceled = true;
    }
    return returnCode[0];
}

From source file:gov.nasa.ensemble.core.plan.editor.lifecycle.WizardPlanExportPage.java

License:Open Source License

/**
 * Displays a Yes/No question to the user with the specified message and returns
 * the user's response.//from w w w . j a v a  2  s  .  c  o m
 *
 * @param message the question to ask
 * @return <code>true</code> for Yes, and <code>false</code> for No
 */
protected boolean queryYesNoQuestion(String message) {
    MessageDialog dialog = new MessageDialog(getContainer().getShell(), "Question", (Image) null, message,
            MessageDialog.NONE, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
    // ensure yes is the default

    return dialog.open() == 0;
}

From source file:gov.nasa.ensemble.core.plan.editor.MultiPagePlanEditor.java

License:Open Source License

/**
 * Check to see if this plan was upgraded to the current AD
 * /*  www  .  java  2s.  c o  m*/
 * @param plan the plan being checked
 * @param workbenchWindow the parent for a warning message dialog
 * @return true if compatibility feedback is present, false otherwise
 */
private static boolean checkPlanCompatibility(EPlan plan, IWorkbenchWindow workbenchWindow) {
    String upgradeNotes = (String) WrapperUtils.getRegistered(plan)
            .getTransientProperty(EditorPlugin.ATTRIBUTE_UPGRADE_NOTES);
    if ((upgradeNotes != null) && upgradeNotes.trim().length() > 0) {
        Shell parent = workbenchWindow.getShell();
        String title = "Plan Compatibility";
        String message = "The plan has been upgraded to the latest AD.";
        String version_ad = ActivityDictionary.getInstance().getVersion();
        if (version_ad != null) {
            message += "\nversion: " + version_ad;
        }
        URL url = null;
        if (upgradeNotes.startsWith("http:") || upgradeNotes.endsWith("html")) {
            try {
                url = new URL(upgradeNotes);
            } catch (MalformedURLException e) {
                // fall out with url = null
            }
        }
        if (url != null) {
            MessageDialog dialog = new MessageDialog(parent, title, null,
                    message + "\n\nDo you wish to open the report?\n" + upgradeNotes, MessageDialog.INFORMATION,
                    new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
            int result = dialog.open();
            if (result == 0) {
                IWorkbenchBrowserSupport browserSupport = PlatformUI.getWorkbench().getBrowserSupport();
                try {
                    IWebBrowser browser = browserSupport.getExternalBrowser();
                    browser.openURL(url);
                } catch (PartInitException e) {
                    MessageDialog.openError(parent, "Error", "Failed to open external browser on URL:\n" + url);
                }
            }
        } else {
            MessageDialog dialog = new MessageDialog(parent, title, null, message + "\n\n" + upgradeNotes,
                    MessageDialog.INFORMATION, new String[] { IDialogConstants.OK_LABEL }, 0);
            dialog.open();
        }
        return true;
    }
    return false;
}

From source file:gov.nasa.ensemble.core.plan.editor.MultiPagePlanEditor.java

License:Open Source License

/**
 * Is the user editing the plan the "custodian" of the plan?
 * @param plan a plan/*from   www . j  av a2 s  .  co  m*/
 * @return whether this editor user is the custodian of the given plan
 */
private boolean checkCustodian(EPlan plan) {
    if (PlanEditorPreferences.isCheckCustodian()) {
        String worldPermissions = WrapperUtils.getAttributeValue(plan,
                PermissionConstants.WORLD_PERMISSIONS_KEY);
        if (worldPermissions == null || !PermissionConstants.PERMISSION_EDIT_BY_ROLE.equals(worldPermissions)) {
            String custodian = WrapperUtils.getAttributeValue(plan, EditorPlugin.ATTRIBUTE_CUSTODIAN);
            String ensembleUser = AuthenticationUtil.getEnsembleUser();
            if ((custodian != null) && (ensembleUser != null) && !custodian.equals(ensembleUser)) {
                IWorkbenchWindow window = getEditorSite().getWorkbenchWindow();
                String message = "The custodian of this plan is " + custodian + ", " + "but your username is "
                        + ensembleUser + ".  " + "Are you sure you want to save?";
                MessageDialog dialog = new MessageDialog(window.getShell(), "Custodian/User mismatch", null,
                        message, MessageDialog.WARNING,
                        new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 1);
                return 0 == dialog.open();
            }
        }
    }
    return true;
}

From source file:gov.redhawk.frontend.ui.internal.AllocateHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveMenuSelection(event);
    if (selection == null) {
        selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
    }/*from www . j  a v  a  2s.  c  o m*/

    if (selection.getFirstElement() instanceof TunerStatus && selection.size() > 1) {
        Object[] items = selection.toArray();
        TunerStatus[] tuners = castArray(items, new TunerStatus[0]);
        if (tuners.length > 0) {
            WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event),
                    new TunerAllocationWizard(tuners[0]));
            dialog.open();
        }
    } else {
        Object obj = selection.getFirstElement();
        if (obj instanceof UnallocatedTunerContainer) {
            UnallocatedTunerContainer container = (UnallocatedTunerContainer) obj;
            TunerStatus[] tuners = getUnallocatedTunersOfType(container.getTunerContainer(),
                    container.getTunerType());
            if (tuners.length > 0) {
                WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event),
                        new TunerAllocationWizard(tuners[0]));
                dialog.open();
            }
        } else if (obj instanceof TunerContainer) {
            TunerContainer container = (TunerContainer) obj;
            TunerStatus[] tuners = container.getTunerStatus().toArray(new TunerStatus[0]);
            if (tuners.length > 0) {
                WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event),
                        new TunerAllocationWizard(tuners[0]));
                dialog.open();
            } else {
                ScaDevice<?> device = ScaEcoreUtils.getEContainerOfType(container, ScaDevice.class);
                if (device != null) {
                    WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event),
                            new TunerAllocationWizard(FrontendFactory.eINSTANCE.createTunerStatus(), device));
                    warnNoTuners(event);
                    dialog.open();
                } else {
                    MessageDialog warning = new MessageDialog(HandlerUtil.getActiveShell(event),
                            "Error - No Device Found", null, "The device could not be found.",
                            MessageDialog.ERROR, new String[] { "OK" }, 0);
                    warning.open();
                    return null;
                }
            }
        } else if (obj instanceof ScaDevice<?>) {
            ScaDevice<?> device = (ScaDevice<?>) obj;
            TunerContainer container = TunerUtils.INSTANCE.getTunerContainer(device);
            if (container == null) {
                MessageDialog warning = new MessageDialog(HandlerUtil.getActiveShell(event),
                        "Error - No Tuner Container Found", null,
                        "The device's tuner container could not be found.  Make sure the device's \"Data Providers Enabled\" property is set to \"true\".",
                        MessageDialog.ERROR, new String[] { "OK" }, 0);
                warning.open();
                return null;
            }
            TunerStatus[] tuners = container.getTunerStatus().toArray(new TunerStatus[0]);
            if (tuners.length > 0) {
                WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event),
                        new TunerAllocationWizard(tuners[0]));
                dialog.open();
            } else {
                WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event),
                        new TunerAllocationWizard(FrontendFactory.eINSTANCE.createTunerStatus(), device));
                warnNoTuners(event);
                dialog.open();
            }
        }
    }

    return null;
}

From source file:gov.redhawk.frontend.ui.internal.AllocateHandler.java

License:Open Source License

private void warnNoTuners(ExecutionEvent event) {
    MessageDialog warning = new MessageDialog(HandlerUtil.getActiveShell(event),
            "Warning - No Tuners Available", null,
            "The selected device has no tuners.  Dynamic tuner creation may not be supported.",
            MessageDialog.WARNING, new String[] { "OK" }, 0);
    warning.open();
}

From source file:gov.redhawk.frontend.ui.internal.DeallocateAction.java

License:Open Source License

private int confirmDeallocate(TunerStatus tuner) {
    MessageDialog warning = new MessageDialog(Display.getCurrent().getActiveShell(), "Deallocation Warning",
            null,//from  www  .j av a  2 s .c o  m
            "Some selected tuners have listeners.  Deallocating them will also deallocate all of their listeners.  Deallocate them anyway?",
            MessageDialog.WARNING, new String[] { "Cancel", "Yes" }, 0);
    return warning.open();
}

From source file:gov.redhawk.frontend.ui.internal.DeallocateHandler.java

License:Open Source License

private int confirmDeallocate(TunerStatus tuner, ExecutionEvent event) {
    MessageDialog warning = new MessageDialog(HandlerUtil.getActiveWorkbenchWindow(event).getShell(),
            "Deallocation Warning", null,
            "Some selected tuners have listeners.  Deallocating them will also deallocate all of their listeners.  Deallocate them anyway?",
            MessageDialog.WARNING, new String[] { "Cancel", "Yes" }, 0);
    return warning.open();
}

From source file:gov.redhawk.ide.codegen.ui.internal.command.GenerateCodeHandler.java

License:Open Source License

/**
 * Check to see if any implementation is configured using the Manual Code Generator option
 * @param parent/*from w w w  .j ava  2s.  c o  m*/
 * @param impls
 * @throws CoreException
 */
private boolean checkManualGeneratorImpls(Shell parent, List<Implementation> impls) throws CoreException {
    if (impls == null || impls.isEmpty()) {
        throw new OperationCanceledException();
    }
    boolean shouldGenerate = true;
    final SoftPkg softPkg = (SoftPkg) impls.get(0).eContainer();
    final WaveDevSettings waveDev = CodegenUtil.loadWaveDevSettings(softPkg);
    boolean hasManualGenerator = false;
    int manualImpls = 0;
    for (final Implementation impl : impls) {
        hasManualGenerator = isManualGenerator(impl, waveDev);
        if (hasManualGenerator) {
            manualImpls++;
        }
    }
    if (manualImpls > 0) {
        String name = softPkg.getName();
        String message = "Some implementations in " + name + " require manual code generation.\n\n"
                + "Automatic Code Generation is only available for implementations using supported code generators.";
        MessageDialog dialog = new MessageDialog(parent, "Manual Code Generation Required", null, message,
                MessageDialog.INFORMATION, new String[] { "OK" }, 0);
        dialog.open();
    }
    // If all implementations require manual code generation, then do not start the generation process
    if (manualImpls == impls.size()) {
        shouldGenerate = false;
    }
    return shouldGenerate;
}

From source file:gov.redhawk.ide.codegen.ui.internal.command.GenerateCodeHandler.java

License:Open Source License

private boolean shouldUpgrade(Shell parent, String name) throws CoreException {
    String message = name + " uses deprecated code generators.\n\n" + "Would you like to upgrade this project?";
    MessageDialog dialog = new MessageDialog(parent, "Deprecated Generator", null, message,
            MessageDialog.WARNING, new String[] { "Upgrade", "Cancel" }, 1);
    switch (dialog.open()) {
    case 0: // Upgrade
        return true;
    case 1:// Cancel
    default:/*from w  ww. j  a va2  s  .  c om*/
        throw new OperationCanceledException();
    }
}