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.redhawk.ide.codegen.ui.internal.GenerateFilesDialog.java

License:Open Source License

protected boolean checkUserFile(boolean newValue, FileStatus element) {
    if (!askedUserFile) {
        if (newValue && !element.getDoItDefault()) {
            MessageDialog dialog = new MessageDialog(getShell(), "WARNING", null,
                    "The file '" + element.getFilename() + "' is a 'USER' file.\n"
                            + "This file may contain code that was written by the user.  "
                            + "\n\nCONTINUING WILL OVERWRITE THIS CODE.\n\n"
                            + "Are you sure you want to do this?",
                    MessageDialog.WARNING, new String[] { "Yes", "No" }, 1);
            if (dialog.open() == 0) {
                askedUserFile = true;/*from   w w  w.j  a  v a2  s  .com*/
                return true;
            } else {
                return false;
            }
        }
        return true;
    } else {
        return true;
    }
}

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

License:Open Source License

protected boolean checkSystemFile(boolean newValue, FileStatus element) {
    if (!askedSystemFileGenerate && newValue) {
        if (!element.getDoItDefault()) {
            MessageDialog dialog = new MessageDialog(getShell(), getShell().getText(), null,
                    "The 'SYSTEM' file '" + element.getFilename()
                            + "' has been modified and may contain code that was written by the user.\n\n"
                            + "It is recommended you overwrite this file.\n\n"
                            + "Do you want to overwrite this file?",
                    MessageDialog.QUESTION, new String[] { "Yes", "No" }, 1);
            if (dialog.open() == 0) {
                askedSystemFileGenerate = true;
                return true;
            } else {
                return false;
            }//  w  w  w. j a v  a2s . c  o  m
        }
    }

    return true;
}

From source file:gov.redhawk.ide.idl.ui.wizard.ScaIDLProjectPropertiesWizardPage.java

License:Open Source License

/**
 * Scan the first idl file in the list for a module name and if it's different than the current
 * module name, ask the user if they want to update it.
 *///from w w  w.  j a  va  2 s . c o m
private void updateModuleName() {
    final File file = new File(this.idlFiles.get(0));
    Scanner input = null;

    try {
        input = new Scanner(file);
    } catch (final FileNotFoundException e) {
        // PASS
    }

    while (input != null && input.hasNext()) {
        final String line = input.nextLine();

        if (line.contains("module")) {
            final String[] splitNames = line.split("[ ]+");

            for (final String token : splitNames) {
                if (!"module".equals(token) && token.matches("[A-Z]+")
                        && !this.moduleNameText.getText().equalsIgnoreCase(token)) {
                    final MessageDialog dialog = new MessageDialog(getShell(), "Update Module Name", null,
                            "Module " + token + " was found in the imported IDL file(s).  Update?",
                            MessageDialog.QUESTION, new String[] { "No", "Yes" }, 1);
                    final int selection = dialog.open();

                    if (selection == 1) {
                        this.moduleNameText.setText(token.toLowerCase());
                    }
                }
            }

            break;
        }
    }
}

From source file:gov.redhawk.ide.pydev.PyDevConfigureStartup.java

License:Open Source License

@Override
public void earlyStartup() {
    final String app = System.getProperty("eclipse.application");
    final boolean runConfig = app == null || "org.eclipse.ui.ide.workbench".equals(app);
    if (!runConfig) {
        return;//from w w  w  . ja  v  a 2s  . c o m
    }

    // If PyDev isn't configured at all, then prompt the user
    if (PydevPlugin.getPythonInterpreterManager().isConfigured()) {
        try {
            boolean configuredCorrectly = AutoConfigPydevInterpreterUtil
                    .isPydevConfigured(new NullProgressMonitor(), null);
            if (!configuredCorrectly) {
                PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        final String[] buttons = { "Ok", "Cancel" };
                        final MessageDialog dialog = new MessageDialog(
                                PlatformUI.getWorkbench().getDisplay().getActiveShell(), "Configure PyDev",
                                null,
                                "PyDev appears to be mis-configured for REDHAWK, would you like it to be re-configured?",
                                MessageDialog.QUESTION, buttons, 0);
                        dialog.open();
                        PyDevConfigureStartup.this.result = dialog.getReturnCode();

                        if (PyDevConfigureStartup.this.result < 1) {
                            new ConfigurePythonJob(false).schedule();
                        }
                    }

                });
            }
        } catch (CoreException e) {
            RedhawkIdePyDevPlugin.getDefault().getLog().log(new Status(e.getStatus().getSeverity(),
                    RedhawkIdePyDevPlugin.PLUGIN_ID, "Failed to auto configure.", e));
        }
    } else {
        PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

            @Override
            public void run() {
                new ConfigurePythonJob(false).schedule();
            }

        });
    }
}

From source file:gov.redhawk.ide.snapshot.internal.ui.SnapshotHandler.java

License:Open Source License

/**
 * the command has been executed, so extract extract the needed information
 * from the application context./*w w  w .jav a2s  . com*/
 */
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    Shell shell = HandlerUtil.getActiveShell(event);
    ISelection selection = HandlerUtil.getActiveMenuSelection(event);
    if (selection == null) {
        selection = HandlerUtil.getCurrentSelection(event);
    }
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection ss = (IStructuredSelection) selection;

        Object obj = ss.getFirstElement();
        ScaUsesPort port = PluginUtil.adapt(ScaUsesPort.class, obj);
        if (port != null) {
            if (port.eContainer() instanceof ResourceOperations) {
                final ResourceOperations lf = (ResourceOperations) port.eContainer();
                if (!lf.started()) {
                    MessageDialog dialog = new MessageDialog(HandlerUtil.getActiveShell(event),
                            "Start Resource", null,
                            "The ports container is not started.  Would you like to start it now?",
                            MessageDialog.QUESTION, new String[] { "Yes", "No" }, 0);
                    if (dialog.open() == Window.OK) {
                        Job job = new Job("Starting...") {

                            @Override
                            protected IStatus run(IProgressMonitor monitor) {
                                try {
                                    lf.start();
                                } catch (StartError e) {
                                    return new Status(Status.ERROR, SnapshotActivator.PLUGIN_ID,
                                            "Failed to start resource", e);
                                }
                                return Status.OK_STATUS;
                            }

                        };
                        job.schedule();
                    }
                }
            }
            BulkIOSnapshotWizard wizard = new BulkIOSnapshotWizard();
            WizardDialog dialog = new WizardDialog(shell, wizard);
            if (dialog.open() == Window.OK) {
                CorbaDataReceiver receiver = wizard.getCorbaReceiver();
                receiver.setPort(port);
                receiver.getDataWriter().getSettings().setType(BulkIOType.getType(port.getRepid()));

                final ScaItemProviderAdapterFactory factory = new ScaItemProviderAdapterFactory();
                final StringBuilder tooltip = new StringBuilder();
                List<String> tmpList = new LinkedList<String>();
                for (EObject eObj = port; !(eObj instanceof ScaDomainManagerRegistry)
                        && eObj != null; eObj = eObj.eContainer()) {
                    Adapter adapter = factory.adapt(eObj, IItemLabelProvider.class);
                    if (adapter instanceof IItemLabelProvider) {
                        IItemLabelProvider lp = (IItemLabelProvider) adapter;
                        tmpList.add(0, lp.getText(eObj));
                    }
                }
                for (Iterator<String> i = tmpList.iterator(); i.hasNext();) {
                    tooltip.append(i.next());
                    if (i.hasNext()) {
                        tooltip.append(" -> ");
                    }
                }
                factory.dispose();

                SnapshotJob job = new SnapshotJob("Snapshot of " + tooltip, receiver);
                job.schedule();
            }
        }
    }
    return null;
}

From source file:gov.redhawk.ide.ui.wizard.RedhawkImportWizardPage1.java

License:Open Source License

/**
 * The <code>WizardDataTransfer</code> implementation of this
 * <code>IOverwriteQuery</code> method asks the user whether the existing
 * resource at the given path should be overwritten.
 * //from ww w  .  ja va 2  s .c  om
 * @param pathString
 * @return the user's reply: one of <code>"YES"</code>, <code>"NO"</code>,
 * <code>"ALL"</code>, or <code>"CANCEL"</code>
 */
public String queryOverwrite(String pathString) {

    Path path = new Path(pathString);

    String messageString;
    // Break the message up if there is a file name and a directory
    // and there are at least 2 segments.
    if (path.getFileExtension() == null || path.segmentCount() < 2) {
        messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_existsQuestion, pathString);
    } else {
        messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_overwriteNameAndPathQuestion,
                path.lastSegment(), path.removeLastSegments(1).toOSString());
    }

    final MessageDialog dialog = new MessageDialog(getContainer().getShell(), IDEWorkbenchMessages.Question,
            null, messageString, MessageDialog.QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL,
                    IDialogConstants.CANCEL_LABEL },
            0) {
        protected int getShellStyle() {
            return super.getShellStyle() | SWT.SHEET;
        }
    };
    String[] response = new String[] { YES, ALL, NO, NO_ALL, CANCEL };
    // run in syncExec because callback is from an operation,
    // which is probably not running in the UI thread.
    getControl().getDisplay().syncExec(new Runnable() {
        public void run() {
            dialog.open();
        }
    });
    return (dialog.getReturnCode() < 0) ? CANCEL : response[dialog.getReturnCode()];
}

From source file:gov.redhawk.sca.internal.ui.handlers.RemoveDomainHandler.java

License:Open Source License

/**
 * {@inheritDoc}// w w  w  .j a  v a2s .  com
 */

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getActiveMenuSelection(event);
    if (selection == null) {
        selection = HandlerUtil.getCurrentSelection(event);
    }
    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection ss = (IStructuredSelection) selection;
        final MessageDialog dialog = new MessageDialog(
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Delete Domain Connection",
                null, "Are you sure you want to remove the selected domains?", MessageDialog.QUESTION,
                new String[] { "OK", "Cancel" }, 0);
        if (dialog.open() == Window.OK) {
            for (final Object obj : ss.toArray()) {
                if (obj instanceof ScaDomainManager) {
                    final ScaDomainManager domMgr = (ScaDomainManager) obj;
                    domMgr.disconnect();
                    ScaModelCommand.execute(domMgr, new ScaModelCommand() {

                        @Override
                        public void execute() {
                            ScaPlugin.getDefault().getDomainManagerRegistry(Display.getCurrent()).getDomains()
                                    .remove(domMgr);
                        }

                    });
                }
            }
        }
    }
    return null;
}

From source file:gov.redhawk.sca.ui.ConnectPortWizard.java

License:Open Source License

protected void performFinish(IProgressMonitor monitor) throws InterruptedException, InvocationTargetException {
    monitor.beginTask("Connecting...", IProgressMonitor.UNKNOWN);
    try {/* w ww  .ja v a 2 s  .  c om*/
        CorbaUtils.invoke(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                page.source.connectPort(page.target.getCorbaObj(), page.connectionID);
                return null;
            }
        }, monitor);
    } catch (final CoreException e) {
        UIJob uiJob = new UIJob("Port connection error") {
            @Override
            public IStatus runInUIThread(IProgressMonitor monitor) {
                Throwable cause = e.getCause();
                String errorMsg;
                if (cause instanceof InvalidPort) {
                    InvalidPort invalidPort = ((InvalidPort) cause);
                    errorMsg = "The source port refused to connect to the target.\n";
                    errorMsg += String.format("Received an InvalidPort exception (code %d, message '%s')",
                            invalidPort.errorCode, invalidPort.msg);
                } else {
                    errorMsg = "Error completing connection: " + cause.getMessage();
                }
                MessageDialog errorDialog = new MessageDialog(getShell(), "Error", null, errorMsg,
                        MessageDialog.ERROR, new String[] { "OK" }, 0);
                errorDialog.open();
                return Status.OK_STATUS;
            }
        };
        uiJob.schedule();

        throw new InvocationTargetException(e);

    }
}

From source file:gr.aueb.dmst.istlab.unixtools.views.preferences.PreferencesTableView.java

public String handleImportButton() {
    String filename = null;/*from w w w.  ja v a2  s.co  m*/

    // ask the user if he/she wants to overwrite the existing table
    MessageDialog messageDialog = new MessageDialog(getShell(), "Import commands", null,
            PropertiesLoader.CUSTOM_COMMAND_PAGE_IMPORT_MESSAGE, MessageDialog.QUESTION_WITH_CANCEL,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                    IDialogConstants.CANCEL_LABEL },
            0);

    if (messageDialog.open() == MessageDialog.OK) {
        // User has selected to open a single file
        FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN);
        filename = fileDialog.open();
    }

    return filename;
}

From source file:Gui.MainWindow_ver2.java

License:Open Source License

public MainWindow_ver2(org.eclipse.swt.widgets.Composite parent, int style) {
    super(parent, style);
    GameGui.getG().mainWindow = this;
    initGUI();//from   ww  w  . ja v  a  2 s . c  o  m
    //      addMouseListenersToCells();
    addDragListenersToLetters();
    addDropListenersToCells();
    initTextStatus();
    initAllCellsColors();
    initWindow();
    GameGui.initUsedLetters();
    shell.addShellListener(new ShellAdapter() {
        public void shellClosed(ShellEvent evt) {
            //            System.out.println("shell.shellClosed, event="+evt);
            if (isSaved == false) {
                saveBeforExitMessage();
            }
            String title = ("Are you sure you want to exit?");
            String message = ("Game Exit");
            String[] options = new String[2];
            options[0] = "YES";
            options[1] = "NO";
            MessageDialog m = new MessageDialog(shell, title, null, message, MessageDialog.QUESTION, options,
                    1);
            //               SWT.ICON_QUESTION | SWT.YES | SWT.NO);

            if (m.open() == 0) {
                GameGui.updateRecordList();
                GameGui.saveRecordList('b');
                GameGui.saveRecordList('a');
                display.dispose();
                try {
                    client.closeSocket();
                    gameThread.stop();
                } catch (Exception e) {
                }
            } else {
                evt.doit = false;
            }
        }
    });
}