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

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

Introduction

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

Prototype

public static boolean openQuestion(Shell parent, String title, String message) 

Source Link

Document

Convenience method to open a simple Yes/No question dialog.

Usage

From source file:com.softlanding.rse.extensions.messages.MessageHandler.java

License:Open Source License

public void handleMessage(QueuedMessage message, MonitoredMessageQueue messageQueue) {
    String monString = queuedMessageSubSystem.getVendorAttribute(MonitoringProperties.VENDOR_ID,
            MonitoringProperties.MONITOR);
    if ((monString == null) || (monString.equals("false"))) //$NON-NLS-1$
        return;/*from  w ww  .j av  a 2s .c o  m*/
    msg = message;
    Display.getDefault().syncExec(new Runnable() {
        public void run() {
            String handling;
            if (msg.getType() == QueuedMessage.INQUIRY) {
                handling = queuedMessageSubSystem.getVendorAttribute(MonitoringProperties.VENDOR_ID,
                        MonitoringProperties.INQUIRY_NOTIFICATION);
                if (handling == null)
                    handling = "Dialog"; //$NON-NLS-1$
            } else {
                handling = queuedMessageSubSystem.getVendorAttribute(MonitoringProperties.VENDOR_ID,
                        MonitoringProperties.INFORMATIONAL_NOTIFICATION);
                if (handling == null)
                    handling = "eMail"; //$NON-NLS-1$
            }
            if (handling.equals("Beep")) //$NON-NLS-1$
                Display.getDefault().beep();
            if (handling.equals("eMail")) { //$NON-NLS-1$
                String eMail = queuedMessageSubSystem.getVendorAttribute(MonitoringProperties.VENDOR_ID,
                        MonitoringProperties.EMAIL_ADDRESS);
                String from = queuedMessageSubSystem.getVendorAttribute(MonitoringProperties.VENDOR_ID,
                        MonitoringProperties.EMAIL_FROM);
                String port = queuedMessageSubSystem.getVendorAttribute(MonitoringProperties.VENDOR_ID,
                        MonitoringProperties.EMAIL_PORT);
                String host = queuedMessageSubSystem.getVendorAttribute(MonitoringProperties.VENDOR_ID,
                        MonitoringProperties.EMAIL_HOST);
                if (from == null)
                    from = ExtensionsPlugin.getResourceString("MessageHandler.5") //$NON-NLS-1$
                            + queuedMessageSubSystem.getHost().getHostName();
                if (port == null)
                    port = "25"; //$NON-NLS-1$
                if ((eMail == null) || (eMail.trim().length() == 0) || (host == null)
                        || (host.trim().length() == 0)) {
                    if (MessageDialog.openQuestion(Display.getDefault().getActiveShell(),
                            ExtensionsPlugin.getResourceString("MessageHandler.7"), //$NON-NLS-1$
                            ExtensionsPlugin.getResourceString("MessageHandler.8"))) { //$NON-NLS-1$
                        QueuedMessageDialog dialog = new QueuedMessageDialog(
                                Display.getDefault().getActiveShell(), msg);
                        Display.getDefault().beep();
                        dialog.open();
                        return;
                    }
                }
                MessageQueueMailMessenger messenger = new MessageQueueMailMessenger();
                String[] recipients = { eMail };
                messenger.setRecipients(recipients);
                messenger.setMailFrom(from);
                messenger.setPort(port);
                messenger.setHost(host);
                try {
                    messenger.sendMail(msg);
                } catch (Exception e) {
                    String errorMessage = e.getMessage();
                    if (errorMessage == null)
                        errorMessage = e.toString();
                    errorMessage = errorMessage + ExtensionsPlugin.getResourceString("MessageHandler.9"); //$NON-NLS-1$
                    Display.getDefault().beep();
                    if (MessageDialog.openQuestion(Display.getDefault().getActiveShell(),
                            ExtensionsPlugin.getResourceString("MessageHandler.10"), errorMessage)) //$NON-NLS-1$
                        handling = "Dialog"; //$NON-NLS-1$
                }
            }
            if (handling.equals("Dialog")) { //$NON-NLS-1$
                Display.getDefault().beep();
                QueuedMessageDialog dialog = new QueuedMessageDialog(Display.getDefault().getActiveShell(),
                        msg);
                dialog.open();
            }
            if (remove && (msg.getType() != QueuedMessage.INQUIRY)) {
                try {
                    msg.getQueue().remove(msg.getKey());
                } catch (Exception e) {
                }
            }
        }
    });
}

From source file:com.softlanding.rse.extensions.spooledfiles.SpooledFileDeleteAction.java

License:Open Source License

public void run(IAction action) {
    Item[] items = null;/*from w  w w  .ja  v  a  2  s. c  om*/
    if (part instanceof SpooledFilesView)
        items = ((SpooledFilesView) part).getSelectedItems();
    if (items != null) {
        if (MessageDialog.openQuestion(
                ExtensionsPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(),
                ExtensionsPlugin.getResourceString("Confirm_Delete_Title"), //$NON-NLS-1$
                ExtensionsPlugin.getResourceString("Confirm_Delete_Message"))) { //$NON-NLS-1$
            for (int i = 0; i < items.length; i++) {
                SpooledFileModel model = (SpooledFileModel) items[i].getData();
                SpooledFile splf = model.getSpooledFile();
                try {
                    splf.delete();
                } catch (Exception e) {
                }
            }
        }
        if (part instanceof SpooledFilesView)
            ((SpooledFilesView) part).refresh();
    }
}

From source file:com.subgraph.vega.ui.scanner.ScanProbeTask.java

License:Open Source License

private boolean processProbeResult(IScanProbeResult probeResult) {
    if (probeResult.getProbeResultType() == ProbeResultType.PROBE_CONNECT_FAILED) {
        MessageDialog.openError(shell, "Failed to connect to target", probeResult.getFailureMessage());
        return false;
    } else if (probeResult.getProbeResultType() == ProbeResultType.PROBE_REDIRECT) {
        final URI redirectURI = probeResult.getRedirectTarget();
        if (!isTrivialRedirect(targetURI, redirectURI)) {
            String message = "Target address " + targetURI + " redirects to address " + redirectURI + "\n\n"
                    + "Would you like to scan " + redirectURI + " instead?";
            boolean doit = MessageDialog.openQuestion(shell, "Follow Redirect?", message);
            if (!doit) {
                return false;
            }//w w  w. jav  a2s  .c  o  m
        }
        scannerConfig.setBaseURI(probeResult.getRedirectTarget());
        return true;
    } else if (probeResult.getProbeResultType() == ProbeResultType.PROBE_REDIRECT_FAILED) {
        MessageDialog.openError(shell, "Redirect failure", probeResult.getFailureMessage());
        return false;
    }
    return true;
}

From source file:com.surelogic.common.ui.dialogs.NoLicenseDialog.java

@Override
public void notifyNoLicenseFor(final SLLicenseProduct product) {
    final String subject = product.toString();
    final UIJob job = new SLUIJob() {
        @Override//from  w  ww  .  j  a  va  2s  .co  m
        public IStatus runInUIThread(IProgressMonitor monitor) {
            if (f_toEclipseLog != null)
                f_toEclipseLog.notifyNoLicenseFor(product);
            final String title = I18N.msg("common.manage.licenses.dialog.noLicense.title");
            final String msg = I18N.msg("common.manage.licenses.dialog.noLicense.msg", subject);
            final Shell shell = EclipseUIUtility.getShell();
            if (MessageDialog.openQuestion(shell, title, msg)) {
                ManageLicensesDialog.open(shell);
            }
            return Status.OK_STATUS;
        }
    };
    job.schedule();
}

From source file:com.surelogic.common.ui.dialogs.NoLicenseDialog.java

@Override
public void notifyExpiration(final SLLicenseProduct product, final Date expiration) {
    final String subject = product.toString();
    final UIJob job = new SLUIJob() {
        @Override/*from w  w w  .  java 2  s  . c om*/
        public IStatus runInUIThread(IProgressMonitor monitor) {
            /*
             * Only notify the user once about a particular license.
             */
            if (!f_alreadyNotified.contains(subject)) {
                f_alreadyNotified.add(subject);
                if (f_toEclipseLog != null)
                    f_toEclipseLog.notifyExpiration(product, expiration);
                final String title = I18N.msg("common.manage.licenses.dialog.expiration.title");
                final String msg = I18N.msg("common.manage.licenses.dialog.expiration.msg", subject,
                        SLUtility.toStringDay(expiration));
                final Shell shell = EclipseUIUtility.getShell();
                if (MessageDialog.openQuestion(shell, title, msg)) {
                    ManageLicensesDialog.open(shell);
                }
            }
            return Status.OK_STATUS;
        }
    };
    job.schedule();
}

From source file:com.symbian.tdep.templates.carbide.SetTestableItemsPage.java

License:Open Source License

/**
 * Implement method of IDialogPage to create UI of this wizard page
 *//*from  ww w  .j ava 2s.  c  o m*/
public void createControl(Composite aComposite) {
    initializeDialogUnits(aComposite);

    IWizardPage lpage = this;
    while ((lpage = lpage.getPreviousPage()) != null) {
        if (lpage instanceof NewProjectPage) {
            iNewProjectPage = (NewProjectPage) lpage;
            break;
        }
    }

    final Composite lComposite = new Composite(aComposite, SWT.NONE);
    {
        lComposite.setLayout(new GridLayout(1, false));
        lComposite.setLayoutData(new GridData(GridData.FILL_BOTH));

        setControl(lComposite);

        iTreeViewer = new TreeViewer(lComposite, SWT.BORDER);

        // Content Provider
        iTreeViewer.setContentProvider(new ClassMethodContentProvider());

        // Label Provider
        iTreeViewer.setLabelProvider(new ClassMethodLabelProvider());

        // Selection Changed listener
        iTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
            public void selectionChanged(SelectionChangedEvent event) {
                checkButtonState();
            }
        });

        iTreeViewer.setComparator(new ViewerComparator());

        // Double Click Listener
        iTreeViewer.addDoubleClickListener(new IDoubleClickListener() {
            public void doubleClick(DoubleClickEvent event) {
                IStructuredSelection selection = (IStructuredSelection) event.getSelection();
                iSelectedItem = (ITestItem) selection.getFirstElement();
                if (iSelectedItem instanceof ClassItem) {
                    iBtnEditClass.notifyListeners(SWT.Selection, null);
                }
                if (iSelectedItem instanceof MethodItem) {
                    iBtnEditMethod.notifyListeners(SWT.Selection, null);
                }
            }
        });
        iTree = iTreeViewer.getTree();
        iTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    }

    final Composite lBtnComposite = new Composite(lComposite, SWT.NONE);
    {
        lBtnComposite.setLayout(new GridLayout(3, true));
        lBtnComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

        // Add Class Button
        iBtnAddClass = new Button(lBtnComposite, SWT.PUSH);
        iBtnAddClass.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        iBtnAddClass.setText(Messages.getString("ClassDialog.AddClass"));
        iBtnAddClass.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent event) {
                try {
                    ClassEditDialog dialog = new ClassEditDialog(lBtnComposite.getShell(),
                            Messages.getString("ClassDialog.AddClassTitle"), iProject);

                    if (dialog.open()) {
                        iProject.addChild(dialog.getClassItem());
                        iTreeViewer.add(iProject, dialog.getClassItem());
                        iTreeViewer.expandToLevel(dialog.getClassItem(), 0);
                    }
                    setPageComplete(isPageComplete());
                } catch (Exception e) {
                    e.printStackTrace();
                    IStatus lStatus = new Status(IStatus.WARNING, SetTestableItemsPage.class.getName(),
                            "Exception was thrown while adding class.", e);
                    TefTemplatesCarbidePlugin.getDefault().getLog().log(lStatus);
                }
            }
        });

        // Edit Class Button
        iBtnEditClass = new Button(lBtnComposite, SWT.PUSH);
        iBtnEditClass.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        iBtnEditClass.setText(Messages.getString("ClassDialog.EditClass"));
        iBtnEditClass.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent event) {
                ClassItem item;
                if (iSelectedItem instanceof ClassItem) {
                    item = (ClassItem) iSelectedItem;
                } else {
                    item = (ClassItem) iSelectedItem.getParent();
                }
                ClassEditDialog dialog = new ClassEditDialog(lBtnComposite.getShell(),
                        Messages.getString("ClassDialog.EditClassTitle"), item);
                if (dialog.open()) {
                    iTreeViewer.update(item, null);
                }
                setPageComplete(isPageComplete());
            }
        });

        // Delete Class Button
        iBtnDeleteClass = new Button(lBtnComposite, SWT.PUSH);
        iBtnDeleteClass.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        iBtnDeleteClass.setText(Messages.getString("ClassDialog.DeleteClass"));
        iBtnDeleteClass.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent event) {
                ClassItem item;
                if (iSelectedItem instanceof ClassItem) {
                    item = (ClassItem) iSelectedItem;
                } else {
                    item = (ClassItem) iSelectedItem.getParent();
                }
                boolean rlt = MessageDialog.openQuestion(lBtnComposite.getShell(),
                        Messages.getString("ClassDialog.ConfirmDelete"),
                        Messages.getString("ClassDialog.WhetherDeleteClass", item.getTestName()));
                if (rlt) {
                    ((ProjectItem) item.getParent()).removeChild(item);
                    iTreeViewer.remove(item);
                }
                setPageComplete(isPageComplete());
            }
        });

        // Add Method Button
        iBtnAddMethod = new Button(lBtnComposite, SWT.PUSH);
        iBtnAddMethod.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        iBtnAddMethod.setText(Messages.getString("MethodDialog.AddMethod"));
        iBtnAddMethod.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent event) {
                try {
                    ClassItem item;
                    if (iSelectedItem instanceof ClassItem) {
                        item = (ClassItem) iSelectedItem;
                    } else {
                        item = (ClassItem) iSelectedItem.getParent();
                    }
                    MethodEditDialog dialog = new MethodEditDialog(lBtnComposite.getShell(),
                            Messages.getString("MethodDialog.AddMethodTitle"), item);
                    if (dialog.open()) {
                        item.addChild(dialog.getMethodItem());
                        iTreeViewer.add(item, dialog.getMethodItem());
                        iTreeViewer.expandToLevel(dialog.getMethodItem(), 0);
                    }
                    setPageComplete(isPageComplete());
                } catch (Exception e) {
                    IStatus lStatus = new Status(IStatus.WARNING, SetTestableItemsPage.class.getName(),
                            "Exception was thrown while adding method.", e);
                    TefTemplatesCarbidePlugin.getDefault().getLog().log(lStatus);
                }
            }
        });

        // Edit Method Button
        iBtnEditMethod = new Button(lBtnComposite, SWT.PUSH);
        iBtnEditMethod.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        iBtnEditMethod.setText(Messages.getString("MethodDialog.EditMethod"));
        iBtnEditMethod.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent event) {
                MethodItem item = (MethodItem) iSelectedItem;
                MethodEditDialog dialog = new MethodEditDialog(lBtnComposite.getShell(),
                        Messages.getString("MethodDialog.EditMethodTitle"), item);
                if (dialog.open()) {
                    iTreeViewer.update(item, null);
                }
                setPageComplete(isPageComplete());
            }
        });

        // Delete Method Button
        iBtnDeleteMethod = new Button(lBtnComposite, SWT.PUSH);
        iBtnDeleteMethod.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        iBtnDeleteMethod.setText(Messages.getString("MethodDialog.DeleteMethod"));
        iBtnDeleteMethod.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent event) {
                MethodItem item = (MethodItem) iSelectedItem;
                boolean rlt = MessageDialog.openQuestion(lBtnComposite.getShell(),
                        Messages.getString("MethodDialog.ConfirmDelete"),
                        Messages.getString("MethodDialog.WhetherDeleteMethod", item.getTestName()));
                if (rlt) {
                    ((ClassItem) item.getParent()).removeChild(item);
                    iTreeViewer.remove(item);
                }
                setPageComplete(isPageComplete());
            }
        });
    }

    ((WizardDialog) getContainer()).addPageChangingListener(new IPageChangingListener() {
        public void handlePageChanging(PageChangingEvent event) {
            IWizardPage lTarPage = (IWizardPage) event.getTargetPage();
            if (lTarPage instanceof SetTestableItemsPage) {
                iProject.setName(iNewProjectPage.getProjectName());
                iTreeViewer.refresh();
            }
        }
    });

    // Set Input
    Vector vector = new Vector();
    vector.add(iProject);
    iTreeViewer.setInput(vector);
    iTreeViewer.setSelection(new TreeSelection(new TreePath(new Object[] { iProject })));
}

From source file:com.synflow.ngDesign.ui.internal.navigator.actions.CopyAction.java

License:Open Source License

/**
 * Set the clipboard contents. Prompt to retry if clipboard is busy.
 * //from   ww  w.j av  a 2s.co m
 * @param resources
 *            the resources to copy to the clipboard
 * @param fileNames
 *            file names of the resources to copy to the clipboard
 * @param names
 *            string representation of all names
 */
private void setClipboard(IResource[] resources, String[] fileNames, String names) {
    try {
        // set the clipboard contents
        if (fileNames.length > 0) {
            clipboard.setContents(new Object[] { resources, fileNames, names }, new Transfer[] {
                    ResourceTransfer.getInstance(), FileTransfer.getInstance(), TextTransfer.getInstance() });
        } else {
            clipboard.setContents(new Object[] { resources, names },
                    new Transfer[] { ResourceTransfer.getInstance(), TextTransfer.getInstance() });
        }
    } catch (SWTError e) {
        if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) {
            throw e;
        }
        if (MessageDialog.openQuestion(shell, "Problem with copy title", // TODO ResourceNavigatorMessages.CopyToClipboardProblemDialog_title,  //$NON-NLS-1$
                "Problem with copy.")) { //$NON-NLS-1$
            setClipboard(resources, fileNames, names);
        }
    }
}

From source file:com.technophobia.substeps.junit.action.SubstepsCopyAction.java

License:Open Source License

@Override
public void run() {
    final String trace = failureTrace.getTrace();
    String source = null;/*from   www .ja v a2  s .co  m*/
    if (trace != null) {
        source = convertLineTerminators(trace);
    } else if (testElement != null) {
        source = testElement.getTestName();
    }
    if (source == null || source.length() == 0)
        return;

    final TextTransfer plainTextTransfer = TextTransfer.getInstance();
    try {
        clipboard.setContents(new String[] { convertLineTerminators(source) },
                new Transfer[] { plainTextTransfer });
    } catch (final SWTError e) {
        if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD)
            throw e;
        if (MessageDialog.openQuestion(shell, SubstepsFeatureMessages.CopyTraceAction_problem,
                SubstepsFeatureMessages.CopyTraceAction_clipboard_busy))
            run();
    }
}

From source file:com.technophobia.substeps.junit.ui.TestRelauncher.java

License:Open Source License

private void stopIfCurrentlyRunning() {
    if (substepsRunSession.get().isKeptAlive()) {
        // prompt for terminating the existing run
        if (MessageDialog.openQuestion(shell,
                SubstepsFeatureMessages.SubstepsFeatureTestRunnerViewPart_terminate_title,
                SubstepsFeatureMessages.SubstepsFeatureTestRunnerViewPart_terminate_message)) {
            stopTest(); // TODO: wait for terminatio
        }//  ww w  .j a v  a 2s.  c o  m
    }
}

From source file:com.toubassi.filebunker.ui.configuration.ConfigurationDialog.java

License:Open Source License

private void deleteClicked() {
    GMailFileStore store = (GMailFileStore) ((IStructuredSelection) storeListViewer.getSelection())
            .getFirstElement();//from   ww w .j  a  v a2  s. c  o  m
    boolean ok = false;

    if (vault.doesStoreContainBackupFiles(store)) {
        ok = MessageDialog.openQuestion(getShell(), "Warning",
                "Files have previously been backed up to " + store.email()
                        + " and will not be accessible if you " + "delete it.  Are you sure you want to delete "
                        + store.email() + "?");
    } else {
        ok = MessageDialog.openQuestion(getShell(), "Warning",
                "Are you sure you want to delete " + store.email() + "?");
    }

    if (ok) {
        stores.remove(store);
        storeListViewer.refresh();
    }
}