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: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.
 * //www.j av  a  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}/*from ww w . j  a  v  a 2s  .  c o m*/
 */

@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 {//from   ww  w . ja  va 2s  . com
        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   ww w  . j  a v a 2 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  www .  j  av a2s  .c om
    //      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;
            }
        }
    });
}

From source file:Gui.MainWindow_ver2.java

License:Open Source License

public boolean showMessageDialog(String string, String string2) {
    String message = (string);/* w w w.j a  va  2 s  .c  o  m*/
    String title = (string2);
    String[] options = new String[2];
    options[0] = "YES";
    options[1] = "NO";
    MessageDialog messageBox = new MessageDialog(shell, title, null, message, MessageDialog.QUESTION, options,
            2);

    int response = messageBox.open();
    if (response == 0) {
        return true;
    } else {
        return false;
    }
}

From source file:Gui.MainWindow_ver2.java

License:Open Source License

private void saveBeforExitMessage() {
    if (!isMulti) {
        String title = ("Save before exit");
        String message = ("The current game was not saved. Would you like to save it?");
        String[] options = new String[2];
        options[0] = "YES";
        options[1] = "NO";
        MessageDialog messageBox = new MessageDialog(shell, title, null, message, MessageDialog.WARNING,
                options, 2);//from w w  w.j av a 2  s.com
        int response = messageBox.open();
        if (response == 0) {
            saveAction();
        }
    }
}

From source file:Gui.NewGameDialog.java

License:Open Source License

private void getNames() {
    String sel = numberOfPlayersCombo.getText();
    //      System.out.println(sel);
    if (!sel.equals("1") && !sel.equals("2") && !sel.equals("3") && !sel.equals("4")) {
        //         if (shell == null) System.out.println("bla");
        String title = ("Number of players error");
        String message = ("Number of players is not valid");
        MessageDialog m = new MessageDialog(dialogShell, title, null, message, MessageDialog.ERROR,
                new String[] { "OK" }, 1);
        m.open();/* w  w  w .  ja v a  2 s  . c om*/
        return;
    }
    int numberOfPlayers = Integer.parseInt(sel);

    String[] names = new String[4];
    names[0] = player1Text.getText();
    names[1] = player2Text.getText();
    names[2] = player3Text.getText();
    names[3] = player4Text.getText();
    //check that names are valid(non empty)
    for (int i = 0; i < numberOfPlayers; i++) {
        String isValid = isValidName(names[i]);
        if (isValid != null) {
            String title = ("Player name error");
            String message = ("Player name must be at length 1 at minimum and 15 at most");
            MessageDialog m = new MessageDialog(dialogShell, title, null, message, MessageDialog.ERROR,
                    new String[] { "OK" }, 1);
            m.open();
            return;
        }

    }

    boolean[] isAuto = new boolean[4];
    isAuto[0] = false;
    isAuto[1] = computerCheck2.getSelection();
    isAuto[2] = computerCheck3.getSelection();
    isAuto[3] = computerCheck4.getSelection();

    playersInfo = new PlayerInfo[numberOfPlayers];
    for (int i = 0; i < numberOfPlayers; i++) {
        playersInfo[i] = new PlayerInfo(names[i], isAuto[i]);
    }

    //      if (basicButton.getSelection()) {System.out.println("bla");}
    gameMode = basicButton.getSelection() ? 'b' : 'a';
    dialogShell.dispose();
}

From source file:Gui.NewMultiDialog.java

License:Open Source License

public void open() {
    try {// w  w w .ja  va  2  s  . c o m
        Shell parent = getParent();
        dialogShell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);

        {
            //Register as a resource user - SWTResourceManager will
            //handle the obtaining and disposing of resources
            SWTResourceManager.registerResourceUser(dialogShell);
        }

        dialogShell.setLayout(new FormLayout());
        dialogShell.setText("Multiplayer Dialog");
        {
            Existing = new Button(dialogShell, SWT.PUSH | SWT.CENTER);
            Existing.setText("Login");
            FormData ExistingLData = new FormData();
            ExistingLData.width = 66;
            ExistingLData.height = 33;
            ExistingLData.left = new FormAttachment(0, 1000, 131);
            ExistingLData.top = new FormAttachment(0, 1000, 120);
            Existing.setLayoutData(ExistingLData);
            Existing.addSelectionListener(new SelectionAdapter() {
                public void widgetSelected(SelectionEvent evt) {
                    //System.out.println("Existing.widgetSelected, event="+evt);
                    isClosed = false;
                    if (text1.getText().equals("")) {
                        String title = ("Error");
                        String message = ("You must specify your name");
                        MessageDialog m = new MessageDialog(dialogShell, title, null, message,
                                MessageDialog.ERROR, new String[] { "OK" }, 1);
                        m.open();

                    } else if (EmailText.isEnabled() == true) { //new user login
                        if (EmailText.getText().equals("")) {
                            String title = ("Error");
                            String message = ("If you login as new user you must specify your email");
                            MessageDialog m = new MessageDialog(dialogShell, title, null, message,
                                    MessageDialog.ERROR, new String[] { "OK" }, 1);
                            m.open();
                        } else if (text2.getText().equals("")) {
                            String title = ("Error");
                            String message = ("You must specify your password");
                            MessageDialog m = new MessageDialog(dialogShell, title, null, message,
                                    MessageDialog.ERROR, new String[] { "OK" }, 1);
                            m.open();
                        } else {
                            setClientInfo(true);
                            //                        System.out.println("login as new");
                        }
                    } else {
                        setClientInfo(false);
                        //                     System.out.println("login as user");
                    }
                }
            });
        }
        {
            cancelConnect = new Button(dialogShell, SWT.PUSH | SWT.CENTER);
            cancelConnect.setText("Cancel");
            FormData cancelConnectLData = new FormData();
            cancelConnectLData.width = 43;
            cancelConnectLData.height = 33;
            cancelConnectLData.top = new FormAttachment(0, 1000, 120);
            cancelConnectLData.left = new FormAttachment(0, 1000, 203);
            cancelConnectLData.right = new FormAttachment(1000, 1000, -41);
            cancelConnect.setLayoutData(cancelConnectLData);
            cancelConnect.addSelectionListener(new SelectionAdapter() {
                public void widgetSelected(SelectionEvent evt) {
                    isClosed = true;
                    dialogShell.dispose();
                }
            });
        }
        {
            newUser = new Button(dialogShell, SWT.PUSH | SWT.CENTER);
            newUser.setText("New User");
            FormData connectLData = new FormData();
            connectLData.width = 86;
            connectLData.height = 33;
            connectLData.top = new FormAttachment(0, 1000, 120);
            connectLData.left = new FormAttachment(0, 1000, 38);
            newUser.setLayoutData(connectLData);
            newUser.addSelectionListener(new SelectionAdapter() {
                public void widgetSelected(SelectionEvent evt) {
                    isClosed = false;
                    EmailText.setEnabled(true);
                    newUser.setEnabled(false);
                    label3.setEnabled(true);
                    //                  if (!text1.getText().equals(""))
                    //                     setClientInfo(true);
                    //                  else{
                    //                     MessageBox m = new MessageBox(dialogShell, SWT.ICON_ERROR);
                    //                     m.setText("Error");
                    //                     m.setMessage("You must specify the name");
                    //                     m.open();
                    //                  }
                }

            });
        }
        {
            EmailText = new Text(dialogShell, SWT.NONE);
            FormData EmailTextLData = new FormData();
            EmailTextLData.width = 119;
            EmailTextLData.height = 17;
            EmailTextLData.left = new FormAttachment(0, 1000, 91);
            EmailTextLData.top = new FormAttachment(0, 1000, 101);
            EmailText.setLayoutData(EmailTextLData);
            EmailText.setEnabled(false);
        }
        {
            text2 = new Text(dialogShell, SWT.NONE);
            FormData text2LData = new FormData();
            text2LData.width = 119;
            text2LData.height = 17;
            text2LData.left = new FormAttachment(0, 1000, 91);
            text2LData.top = new FormAttachment(0, 1000, 72);
            text2.setLayoutData(text2LData);
            text2.setEchoChar('*');
        }
        {
            text1 = new Text(dialogShell, SWT.NONE);
            FormData text1LData = new FormData();
            text1LData.width = 119;
            text1LData.height = 17;
            text1LData.left = new FormAttachment(0, 1000, 91);
            text1LData.top = new FormAttachment(0, 1000, 40);
            text1.setLayoutData(text1LData);
        }
        {
            label3 = new Label(dialogShell, SWT.NONE);
            label3.setText("Email:");
            FormData label3LData = new FormData();
            label3LData.width = 43;
            label3LData.height = 17;
            label3LData.left = new FormAttachment(0, 1000, 18);
            label3LData.top = new FormAttachment(0, 1000, 101);
            label3.setLayoutData(label3LData);
            label3.setFont(SWTResourceManager.getFont("Tahoma", 10, 0, false, false));
            label3.setEnabled(false);
        }
        {
            label2 = new Label(dialogShell, SWT.NONE);
            label2.setText("password:");
            FormData label2LData = new FormData();
            label2LData.width = 61;
            label2LData.height = 17;
            label2LData.left = new FormAttachment(0, 1000, 18);
            label2LData.top = new FormAttachment(0, 1000, 72);
            label2.setLayoutData(label2LData);
            label2.setFont(SWTResourceManager.getFont("Tahoma", 10, 0, false, false));
        }
        {
            label1 = new Label(dialogShell, SWT.NONE);
            label1.setText("username:");
            FormData label1LData = new FormData();
            label1LData.width = 61;
            label1LData.height = 20;
            label1LData.left = new FormAttachment(0, 1000, 18);
            label1LData.top = new FormAttachment(0, 1000, 40);
            label1.setLayoutData(label1LData);
            label1.setFont(SWTResourceManager.getFont("Tahoma", 10, 0, false, false));
        }
        {
            helpLabel = new Label(dialogShell, SWT.NONE);
            helpLabel.setText("Before login please read carefully the\nrelevant notes at the help window");
            FormData helpLabelData = new FormData();
            helpLabelData.width = 250;
            helpLabelData.height = 35;
            helpLabelData.left = new FormAttachment(0, 1000, 5);
            helpLabelData.top = new FormAttachment(0, 1000, 5);
            helpLabel.setLayoutData(helpLabelData);
            helpLabel.setFont(SWTResourceManager.getFont("Tahoma", 9, 0, false, false));

        }
        dialogShell.layout();
        dialogShell.pack();
        dialogShell.setLocation(getParent().toDisplay(100, 100));
        dialogShell.open();
        Display display = dialogShell.getDisplay();
        while (!dialogShell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:hydrograph.ui.graph.execution.tracking.connection.HydrographServerConnection.java

License:Apache License

/**
 * Opens a message dialog in case if there are issues while making
 * connection to server./*  w  w  w . j  a  v a 2 s.c o m*/
 *
 * @param job the job
 * @param shell the shell
 */
public void messageDialogForExecutionTracking(Job job, Shell shell) {
    String portNo;
    String host;
    if (job.isRemoteMode()) {
        portNo = TrackingDisplayUtils.INSTANCE.getRemotePortFromPreference();
        if (StringUtils.isBlank(portNo)) {
            portNo = PreferenceConstants.DEFAULT_PORT_NO;
        }
        if (PlatformUI.getPreferenceStore().getBoolean(PreferenceConstants.USE_REMOTE_CONFIGURATION)) {
            host = PlatformUI.getPreferenceStore().getString(PreferenceConstants.REMOTE_HOST);
        } else {
            host = job.getHost();
        }

    } else {
        portNo = TrackingDisplayUtils.INSTANCE.getPortFromPreference();
        if (StringUtils.isBlank(portNo)) {
            portNo = PreferenceConstants.DEFAULT_PORT_NO;
        }
        host = job.getHost();
    }
    String msg = "Execution tracking can't be displayed as connection refused on host: " + host
            + " with port no: " + portNo;
    MessageDialog dialog = new MessageDialog(shell, "Warning", null, msg, SWT.ICON_WARNING,
            new String[] { "OK" }, 0);
    dialog.open();
}