Search in sources :

Example 96 with MessageBox

use of org.eclipse.swt.widgets.MessageBox in project knime-core by knime.

the class DeleteAction method confirmDeletion.

private boolean confirmDeletion(final List<IContainer> toDel, final List<IContainer> toDelWFs) {
    String msg = "";
    if (toDel.size() == 1) {
        boolean isGroup = toDelWFs.size() != 1;
        msg = "Do you want to delete the workflow ";
        if (isGroup) {
            msg += "group ";
        }
        msg += "\"" + toDel.get(0).getName() + "\"?\n";
    } else {
        int groups = toDel.size() - toDelWFs.size();
        if (groups == 0) {
            msg = "Do you want to delete all " + toDel.size() + " selected workflows?\n";
        } else {
            if (groups == 1) {
                msg = "Do you want to delete the workflow group \"" + toDel.get(0).getName() + "\"?\n";
            } else {
                msg = "Do you want to delete all " + toDel.size() + " workflow groups?\n";
            }
            if (toDelWFs.size() > 0) {
                if (groups == 1) {
                    msg += "It contains ";
                } else {
                    msg += "They contain ";
                }
                msg += toDelWFs.size() + " workflow";
                if (toDelWFs.size() > 1) {
                    msg += "s";
                }
                msg += ".\n";
            }
        }
    }
    msg += "\nThis operation cannot be undone.";
    MessageBox mb = new MessageBox(m_shell, SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL);
    mb.setMessage(msg);
    mb.setText("Confirm Deletion");
    if (mb.open() != SWT.OK) {
        LOGGER.debug("Deletion of " + toDel.size() + " items canceled by user.");
        return false;
    } else {
        LOGGER.debug("Deletion of " + toDel.size() + " items confirmed by user.");
        return true;
    }
}
Also used : MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 97 with MessageBox

use of org.eclipse.swt.widgets.MessageBox in project knime-core by knime.

the class HeadlessPreferencePage method checkChanges.

private void checkChanges() {
    boolean apply = m_apply;
    m_apply = false;
    if (apply) {
        return;
    }
    // get the preference store for the UI plugin
    IPreferenceStore store = KNIMECorePlugin.getDefault().getPreferenceStore();
    String currentTmpDir = store.getString(HeadlessPreferencesConstants.P_TEMP_DIR);
    boolean tempDirChanged = !m_tempPath.equals(currentTmpDir);
    if (tempDirChanged) {
        // reset the directory
        m_tempPath = currentTmpDir;
        MessageBox mb = new MessageBox(Display.getDefault().getActiveShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
        mb.setText("Restart workbench...");
        mb.setMessage("Changes of the temporary directory become " + "first available after restarting the workbench.\n" + "Do you want to restart the workbench now?");
        if (mb.open() != SWT.YES) {
            return;
        }
        PlatformUI.getWorkbench().restart();
    }
}
Also used : IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 98 with MessageBox

use of org.eclipse.swt.widgets.MessageBox in project yamcs-studio by yamcs.

the class AddCommentHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection sel = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
    Shell shell = HandlerUtil.getActiveShell(event);
    if (sel != null && sel instanceof IStructuredSelection) {
        IStructuredSelection selection = (IStructuredSelection) sel;
        if (selection.isEmpty()) {
            return null;
        }
        // Populate with text of first record. But only if single selection
        String initialValue = "";
        if (selection.size() == 1) {
            CommandHistoryRecord rec = (CommandHistoryRecord) selection.getFirstElement();
            String existingComment = rec.getTextForColumn("Comment", false);
            if (existingComment != null) {
                initialValue = existingComment;
            }
        }
        String dialogMessage;
        if (selection.size() == 1) {
            dialogMessage = "Add a comment for this command";
        } else {
            dialogMessage = "Add a comment for the " + selection.size() + " selected commands";
        }
        IInputValidator validator = newText -> null;
        InputDialog commentDialog = new InputDialog(shell, "Add Comment", dialogMessage, initialValue, validator) {

            @Override
            protected int getInputTextStyle() {
                return SWT.MULTI | SWT.BORDER | SWT.V_SCROLL;
            }

            @Override
            protected Control createDialogArea(Composite parent) {
                Control res = super.createDialogArea(parent);
                ((GridData) this.getText().getLayoutData()).heightHint = 4 * this.getText().getLineHeight();
                return res;
            }
        };
        int commentResult = commentDialog.open();
        if (commentResult == Window.OK) {
            String newComment = commentDialog.getValue();
            CommandingCatalogue catalogue = CommandingCatalogue.getInstance();
            // TODO improve me. Bundle into only one error message
            // Or even better: one api call.
            Iterator<?> it = selection.iterator();
            while (it.hasNext()) {
                CommandHistoryRecord rec = (CommandHistoryRecord) it.next();
                catalogue.updateCommandComment("realtime", rec.getCommandId(), newComment).exceptionally(t -> {
                    Display.getDefault().asyncExec(() -> {
                        MessageBox dialog = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
                        dialog.setText("Comment Update");
                        dialog.setMessage("Comment has not been updated. Details: " + t.getMessage());
                        // open dialog and await user selection
                        dialog.open();
                    });
                    return null;
                });
            }
        }
    }
    return null;
}
Also used : ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) InputDialog(org.eclipse.jface.dialogs.InputDialog) Shell(org.eclipse.swt.widgets.Shell) Iterator(java.util.Iterator) ExecutionException(org.eclipse.core.commands.ExecutionException) Display(org.eclipse.swt.widgets.Display) HandlerUtil(org.eclipse.ui.handlers.HandlerUtil) Window(org.eclipse.jface.window.Window) CommandingCatalogue(org.yamcs.studio.core.model.CommandingCatalogue) Composite(org.eclipse.swt.widgets.Composite) IInputValidator(org.eclipse.jface.dialogs.IInputValidator) SWT(org.eclipse.swt.SWT) MessageBox(org.eclipse.swt.widgets.MessageBox) ISelection(org.eclipse.jface.viewers.ISelection) AbstractHandler(org.eclipse.core.commands.AbstractHandler) GridData(org.eclipse.swt.layout.GridData) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Control(org.eclipse.swt.widgets.Control) InputDialog(org.eclipse.jface.dialogs.InputDialog) Composite(org.eclipse.swt.widgets.Composite) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) MessageBox(org.eclipse.swt.widgets.MessageBox) Shell(org.eclipse.swt.widgets.Shell) Control(org.eclipse.swt.widgets.Control) ISelection(org.eclipse.jface.viewers.ISelection) CommandingCatalogue(org.yamcs.studio.core.model.CommandingCatalogue) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 99 with MessageBox

use of org.eclipse.swt.widgets.MessageBox in project yamcs-studio by yamcs.

the class GUIUtil method openConfirmDialog.

/**
 *Open a dialog to ask for confirmation.
 * @param dialogMessage the message on the dialog.
 * @return true if user has clicked the YES button. False otherwise.
 */
public static boolean openConfirmDialog(final String dialogMessage) {
    MessageBox mb = new MessageBox(DisplayUtils.getDefaultShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
    mb.setMessage(dialogMessage);
    mb.setText("Confirm Dialog");
    int val = mb.open();
    if (val == SWT.YES)
        return true;
    return false;
}
Also used : MessageBox(org.eclipse.swt.widgets.MessageBox)

Aggregations

MessageBox (org.eclipse.swt.widgets.MessageBox)99 Shell (org.eclipse.swt.widgets.Shell)17 ArrayList (java.util.ArrayList)13 File (java.io.File)11 IOException (java.io.IOException)10 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10 GridData (org.eclipse.swt.layout.GridData)9 GridLayout (org.eclipse.swt.layout.GridLayout)9 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)9 Point (org.eclipse.swt.graphics.Point)8 Button (org.eclipse.swt.widgets.Button)8 Display (org.eclipse.swt.widgets.Display)8 Composite (org.eclipse.swt.widgets.Composite)7 FileDialog (org.eclipse.swt.widgets.FileDialog)7 Label (org.eclipse.swt.widgets.Label)7 List (java.util.List)6 SWTError (org.eclipse.swt.SWTError)6 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)6 SelectionListener (org.eclipse.swt.events.SelectionListener)6 SWT (org.eclipse.swt.SWT)5