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.arc.cdt.debug.seecode.ui.UISeeCodePlugin.java

License:Open Source License

private void checkLicensingAlert(final int daysRemaining) {
    final int alertDays = SeeCodePlugin.getDefault().getPreferences().getInt(
            ISeeCodeConstants.PREF_LICENSE_EXPIRATION_DAYS, ISeeCodeConstants.DEF_PREF_LICENSE_EXPIRATION_DAYS);
    if (daysRemaining >= 0) {
        boolean alert = SeeCodePlugin.getDefault().getPreferences()
                .getBoolean(ISeeCodeConstants.PREF_LICENSE_EXPIRATION_ALERT, true);
        if (alertDays >= daysRemaining) {
            if (alert) {
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    @Override//from  w w  w .j  a  v a 2 s  .c  om
                    public void run() {
                        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                        String s;
                        if (daysRemaining == 0)
                            s = "after today";
                        else if (daysRemaining == 1)
                            s = "after tomorrow";
                        else
                            s = "in " + daysRemaining + " days";
                        MessageDialog dialog = new MessageDialog(shell, "License Expiration Alert", null, // accept
                                "Debugger license will expire " + s, MessageDialog.WARNING,
                                new String[] { IDialogConstants.OK_LABEL }, 0) {

                            @Override
                            protected Control createCustomArea(Composite parent) {
                                if (daysRemaining > 0 && daysRemaining <= 2) {
                                    Label label = new Label(parent, SWT.RIGHT);
                                    GridData data = new GridData();
                                    data.horizontalAlignment = GridData.END;
                                    data.grabExcessHorizontalSpace = true;
                                    label.setLayoutData(data);
                                    label.setText("You will be reminded again tomorrow.");
                                    setAlertDays(daysRemaining - 1);
                                    return label;
                                }
                                if (daysRemaining > 0) {
                                    Composite container = new Composite(parent, 0);
                                    GridData data = new GridData();
                                    data.horizontalAlignment = GridData.END;
                                    data.grabExcessHorizontalSpace = true;
                                    container.setLayoutData(data);
                                    container.setLayout(new GridLayout(3, false));
                                    Label label1 = new Label(container, SWT.LEFT);
                                    label1.setText("Remind me again when ");
                                    final Combo combo = new Combo(container, SWT.DROP_DOWN | SWT.READ_ONLY);
                                    Label label2 = new Label(container, SWT.LEFT);
                                    label2.setText(" days remain.");
                                    label2.setLayoutData(data);
                                    for (int i = Math.min(15, daysRemaining - 1); i >= 0; i--) {
                                        combo.add("" + i);
                                    }
                                    combo.select(0);
                                    setAlertDays(Integer.parseInt(combo.getItem(0)));
                                    combo.addSelectionListener(new SelectionListener() {

                                        @Override
                                        public void widgetDefaultSelected(SelectionEvent e) {
                                        }

                                        @Override
                                        public void widgetSelected(SelectionEvent e) {
                                            setAlertDays(Integer.parseInt(combo.getText()));
                                        }
                                    });
                                    return container;
                                }
                                return null;
                            }
                        };
                        if (dialog.open() == Window.OK) {
                            SeeCodePlugin.getDefault().getPreferences()
                                    .putInt(ISeeCodeConstants.PREF_LICENSE_EXPIRATION_DAYS, mAlertDays);
                        }
                    }
                });

            }
        } else if (daysRemaining > ISeeCodeConstants.DEF_PREF_LICENSE_EXPIRATION_DAYS
                && alertDays != ISeeCodeConstants.DEF_PREF_LICENSE_EXPIRATION_DAYS) {
            // License has been renewed. Reset things to default.
            restoreDefaultAlertDays();
        }
    } else if (alertDays != ISeeCodeConstants.DEF_PREF_LICENSE_EXPIRATION_DAYS) {
        // Evidently a permanent license; make sure we reset alert if he previously
        // had an expired one.
        restoreDefaultAlertDays();
    }
}

From source file:com.arc.cdt.debug.seecode.ui.UISeeCodePlugin.java

License:Open Source License

/**
 * Show an note box./* ww w.ja v a2 s  .  c  o  m*/
 * (We use JFace ErrorDialog instead of MessageBox. The latter is done outside
 * of Java and the WindowTester framework loses control).
 * @param title
 * @param message
 */
public static void showNote(String title, String message) {
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    MessageDialog dialog = new MessageDialog(shell, title, null, // accept
            // the
            // default
            // window
            // icon
            message, MessageDialog.INFORMATION, new String[] { IDialogConstants.OK_LABEL }, 0);
    dialog.setBlockOnOpen(false); // we want to be able to make box expire
    // ok is the default
    dialog.open();
    long expireTime = System.currentTimeMillis() + NOTE_TIME_OUT;
    Display display = shell.getDisplay();
    try {
        while (dialog.getShell() != null && !dialog.getShell().isDisposed()
                && System.currentTimeMillis() < expireTime) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
    } finally {
        if (dialog.getShell() != null && !dialog.getShell().isDisposed()) {
            dialog.close();
        }
    }
}

From source file:com.archimatetool.editor.model.impl.EditorModelManager.java

License:Open Source License

/**
 * Show dialog to save modified model// w  ww  . j  ava  2 s.com
 * @param model
 * @return true if the user chose to save the model or chose not to save the model, false if cancelled
 * @throws IOException 
 */
private boolean askSaveModel(IArchimateModel model) throws IOException {
    MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(),
            Messages.EditorModelManager_6, null, NLS.bind(Messages.EditorModelManager_7, model.getName()),
            MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                    IDialogConstants.CANCEL_LABEL },
            0);

    int result = dialog.open();

    // Yes
    if (result == 0) {
        return saveModel(model);
    }
    // No
    if (result == 1) {
        return true;
    }
    // Cancel
    return false;
}

From source file:com.architexa.org.eclipse.gef.ui.palette.customize.PaletteCustomizerDialog.java

License:Open Source License

/**
 * This is the method that is called everytime the selection in the outline
 * (treeviewer) changes.  //ww w  .  j  av  a 2 s  .co  m
 */
protected void handleOutlineSelectionChanged() {
    PaletteEntry entry = getSelectedPaletteEntry();

    if (activeEntry == entry) {
        return;
    }

    if (errorMessage != null) {
        MessageDialog dialog = new MessageDialog(getShell(), PaletteMessages.ERROR, null,
                PaletteMessages.ABORT_PAGE_FLIPPING_MESSAGE + "\n" + errorMessage, //$NON-NLS-1$
                MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0);
        dialog.open();
        treeviewer.addPostSelectionChangedListener(pageFlippingPreventer);
    } else {
        setActiveEntry(entry);
    }
    updateActions();
}

From source file:com.arm.cmsis.pack.installer.CpPackInstaller.java

License:Open Source License

protected int timeoutQuestion(String pdscUrl) {
    Display.getDefault().syncExec(() -> {
        MessageDialog dialog = new MessageDialog(null, Messages.CpPackInstaller_Timout, null,
                NLS.bind(Messages.CpPackInstaller_TimeoutMessage, pdscUrl, TIME_OUT / 1000),
                MessageDialog.QUESTION_WITH_CANCEL, new String[] { IDialogConstants.YES_LABEL,
                        IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
                0);//  www . j  ava  2 s .c o m
        wait = dialog.open();
    });
    return wait;
}

From source file:com.arm.cmsis.pack.installer.jobs.CpPackUnpackJob.java

License:Open Source License

private boolean myRun(IProgressMonitor monitor) {
    SubMonitor progress = SubMonitor.convert(monitor, 100);

    File sourceFile = new File(fSourceFilePath);
    monitor.setTaskName(Messages.CpPackUnpackJob_Unpacking + sourceFile.toString());

    if (fDestPath.toFile().exists()) {
        final String messageString = NLS.bind(Messages.CpPackUnpackJob_PathAlreadyExists,
                fDestPath.toOSString());
        Display.getDefault().syncExec(new Runnable() {
            @Override// w  w  w . ja  v  a 2  s . c  o m
            public void run() {
                final MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(),
                        Messages.CpPackUnpackJob_OverwriteQuery, null, messageString, MessageDialog.QUESTION,
                        new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                                IDialogConstants.CANCEL_LABEL },
                        0);
                returnCode = dialog.open();
            }
        });

        if (returnCode == IDialogConstants.OK_ID) {
            Utils.deleteFolderRecursive(fDestPath.toFile());
        } else {
            fResult.setSuccess(false);
            fResult.setErrorString(Messages.CpPackJob_CancelledByUser);
            return false;
        }
    }

    if (!sourceFile.exists()) {
        fResult.setSuccess(false);
        fResult.setErrorString(sourceFile.toString() + Messages.CpPackUnpackJob_SourceFileCannotBeFound);
        return true;
    }

    try {
        if (!fPackInstaller.unzip(sourceFile, fDestPath, progress.newChild(95))) {
            fResult.setSuccess(false);
            fResult.setErrorString(Messages.CpPackJob_CancelledByUser);
            Utils.deleteFolderRecursive(fDestPath.toFile());
            return false;
        }
        if (fPack != null) { // unpack job
            fPack.setPackState(PackState.INSTALLED);
            fPack.setFileName(fDestPath.append(fPack.getPackFamilyId() + CmsisConstants.EXT_PDSC).toString());
            fResult.setPack(fPack);
            fResult.setSuccess(true);
            return true;
        }
        Collection<String> files = new LinkedList<>();
        Utils.findPdscFiles(fDestPath.toFile(), files, 1);
        if (files.isEmpty()) {
            Utils.deleteFolderRecursive(fDestPath.toFile());
            fResult.setSuccess(false);
            fResult.setErrorString(Messages.CpPackUnpackJob_PdscFileNotFoundInFolder + fDestPath.toOSString());
            return true;
        }

        String file = files.iterator().next();
        ICpXmlParser parser = CpPlugIn.getPackManager().getParser();
        fPack = (ICpPack) parser.parseFile(file);
        if (fPack != null) {
            ICpItem urlItem = fPack.getFirstChild(CmsisConstants.URL);
            if (urlItem == null || !Utils.isValidURL(urlItem.getText())) {
                fPack.setPackState(PackState.GENERATED);
            } else {
                fPack.setPackState(PackState.INSTALLED);
            }
            fResult.setPack(fPack);
            fResult.setSuccess(true);
            return true;
        }
        Utils.deleteFolderRecursive(fDestPath.toFile());
        StringBuilder sb = new StringBuilder(Messages.CpPackUnpackJob_FailToParsePdscFile + file);
        for (String es : parser.getErrorStrings()) {
            sb.append(System.lineSeparator());
            sb.append(es);
        }
        fResult.setErrorString(sb.toString());
        fResult.setSuccess(false);
        return true;
    } catch (IOException e) {
        fResult.setSuccess(false);
        fResult.setErrorString(Messages.CpPackUnpackJob_FailedToUnzipFile + sourceFile.toString());
        Utils.deleteFolderRecursive(fDestPath.toFile());
        return true;
    }
}

From source file:com.arm.cmsis.pack.installer.OverwriteQuery.java

License:Open Source License

@Override
public String queryOverwrite(String pathString) {
    Path path = new Path(pathString);

    String messageString;//from  w w  w .j av a2s. co  m
    //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(Messages.OverwriteQuery_ExistsQuestion, pathString);
    } else {
        messageString = NLS.bind(Messages.OverwriteQuery_OverwriteNameAndPathQuestion, path.lastSegment(),
                path.removeLastSegments(1).toOSString());
    }

    final MessageDialog dialog = new MessageDialog(shell, Messages.OverwriteQuery_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) {
        @Override
        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.
    shell.getDisplay().syncExec(new Runnable() {
        @Override
        public void run() {
            dialog.open();
        }
    });
    return dialog.getReturnCode() < 0 ? CANCEL : response[dialog.getReturnCode()];
}

From source file:com.atlassian.connector.eclipse.team.ui.TeamUiUtils.java

License:Open Source License

public static void handleMissingTeamConnectors() {
    Display.getDefault().syncExec(new Runnable() {
        public void run() {
            new MessageDialog(WorkbenchUtil.getShell(), "No Atlassian SCM Integration installed", null,
                    "In order to access this functionality you need to install an Atlassian SCM Integration feature.\n\n"
                            + "You may install them by opening: Help | Install New Software, selecting 'Atlassian Connector for Eclipse' Update Site "
                            + "and chosing one or more integation features in 'Atlassian Integrations' category.",
                    MessageDialog.INFORMATION, new String[] { IDialogConstants.OK_LABEL }, 0).open();
        }//from   www  .j a  va2 s .  c o m
    });
}

From source file:com.byterefinery.rmbench.dialogs.PrinterSetupDialog.java

License:Open Source License

protected void okPressed() {
    if (selectedPrinter != null) {

        // check margin value
        if (!validMargin((int) (margin * Display.getCurrent().getDPI().x))) {
            String[] buttons = { "Ok" };
            MessageDialog mDialog = new MessageDialog(parentShell, "Error", null,
                    Messages.PrintDialog_marginValueError, MessageDialog.ERROR, buttons, 0);
            mDialog.open();//from   w  w  w.ja  v  a2 s .  co m
            marginText.setFocus();
            return;
        }

        RMBenchPlugin.getPrintState().margin = margin;
        RMBenchPlugin.getPrintState().printer = selectedPrinter;
    }

    super.okPressed();
}

From source file:com.byterefinery.rmbench.util.ModelManager.java

License:Open Source License

/**
 * show a 3-option dialog asking the user whether the current model should be saved
 * /*from  www  .java  2 s .c  o m*/
 * @return false if the dialog was cancelled, and thus the operation should not 
 * proceed
 */
private boolean querySaveModel(final Shell shell) {

    MessageDialog dialog = new MessageDialog(shell, RMBenchMessages.ModelView_SaveDlg_Title, null,
            RMBenchMessages.ModelView_SaveChanged_Message, MessageDialog.QUESTION, new String[] {
                    IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
            0);
    int result = dialog.open();
    if (result == 0) {
        IRunnableWithProgress runnable = new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {

                doSave(shell, monitor);
            }
        };
        try {
            new ProgressMonitorDialog(shell).run(false, true, runnable);
        } catch (InvocationTargetException e) {
            RMBenchPlugin.logError(e);
        } catch (InterruptedException e) {
            RMBenchPlugin.logError(e);
        }
    }

    return result != 2;
}