Search in sources :

Example 46 with MessageBox

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

the class CommandStackView method addPopupMenu.

private void addPopupMenu() {
    class CopySelectionListener implements SelectionListener {

        boolean cut = false;

        public CopySelectionListener(boolean cut) {
            this.cut = cut;
        }

        @Override
        public void widgetSelected(SelectionEvent event) {
            // check something is selected
            TableItem[] selection = commandTableViewer.getTable().getSelection();
            if (selection == null || selection.length == 0)
                return;
            // copy each selected items
            List<StackedCommand> scs = new ArrayList<>();
            for (TableItem ti : selection) {
                StackedCommand sc = (StackedCommand) (ti.getData());
                if (sc == null)
                    continue;
                scs.add(sc);
            }
            CommandClipboard.addStackedCommands(scs, cut, event.display);
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    }
    class PasteSelectionListener implements SelectionListener {

        PastingType pastingType;

        public PasteSelectionListener(PastingType pastingType) {
            this.pastingType = pastingType;
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent arg0) {
            widgetSelected(arg0);
        }

        @Override
        public void widgetSelected(SelectionEvent event) {
            StackedCommand sc = null;
            // sanity checks
            TableItem[] selection = commandTableViewer.getTable().getSelection();
            if (selection != null && selection.length > 0) {
                sc = (StackedCommand) (commandTableViewer.getTable().getSelection()[0].getData());
            }
            if (sc == null && pastingType != PastingType.APPEND)
                pastingType = PastingType.APPEND;
            // get commands from clipboard
            List<StackedCommand> copyedCommands = new ArrayList<>();
            try {
                copyedCommands = CommandClipboard.getCopiedCommands();
            } catch (Exception e) {
                String errorMessage = "Unable to build Stacked Command from the specifed source: ";
                log.log(Level.WARNING, errorMessage, e);
                commandTableViewer.getTable().getDisplay().asyncExec(() -> {
                    MessageBox dialog = new MessageBox(commandTableViewer.getTable().getShell(), SWT.ICON_ERROR | SWT.OK);
                    dialog.setText("Command Stack Edition");
                    dialog.setMessage(errorMessage + e.getMessage());
                    // open dialog and await user selection
                    dialog.open();
                });
                return;
            }
            if (copyedCommands.isEmpty())
                return;
            // paste
            int index = commandTableViewer.getIndex(sc);
            for (StackedCommand pastedCommand : copyedCommands) {
                if (pastingType == PastingType.APPEND) {
                    commandTableViewer.addTelecommand(pastedCommand);
                } else if (pastingType == PastingType.AFTER_ITEM) {
                    commandTableViewer.insertTelecommand(pastedCommand, index + selection.length);
                } else if (pastingType == PastingType.BEFORE_ITEM) {
                    commandTableViewer.insertTelecommand(pastedCommand, index);
                }
                index++;
            }
            // delete cut commands
            CommandStack.getInstance().getCommands().removeAll(CommandClipboard.getCutCommands());
            // refresh command stack view state
            IWorkbenchPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(CommandStackView.ID);
            CommandStackView commandStackView = (CommandStackView) part;
            commandStackView.refreshState();
        }
    }
    Table table = commandTableViewer.getTable();
    Menu contextMenu = new Menu(commandTableViewer.getTable());
    table.setMenu(contextMenu);
    MenuItem mItemCopy = new MenuItem(contextMenu, SWT.None);
    mItemCopy.setText("Copy");
    mItemCopy.addSelectionListener(new CopySelectionListener(false));
    MenuItem mItemCut = new MenuItem(contextMenu, SWT.None);
    mItemCut.setText("Cut");
    mItemCut.addSelectionListener(new CopySelectionListener(true));
    new MenuItem(contextMenu, SWT.SEPARATOR);
    MenuItem mItemPasteBefore = new MenuItem(contextMenu, SWT.None);
    mItemPasteBefore.setText("Paste Before");
    mItemPasteBefore.addSelectionListener(new PasteSelectionListener(PastingType.BEFORE_ITEM));
    MenuItem mItemPasteAfter = new MenuItem(contextMenu, SWT.None);
    mItemPasteAfter.setText("Paste After");
    mItemPasteAfter.addSelectionListener(new PasteSelectionListener(PastingType.AFTER_ITEM));
    MenuItem mItemPaste = new MenuItem(contextMenu, SWT.None);
    mItemPaste.setText("Paste Append");
    mItemPaste.addSelectionListener(new PasteSelectionListener(PastingType.APPEND));
    commandTableViewer.getTable().addListener(SWT.MouseDown, new Listener() {

        @Override
        public void handleEvent(Event event) {
            TableItem[] selection = commandTableViewer.getTable().getSelection();
            boolean pastBeforeAuthorized = true;
            boolean pastAfterAuthorized = true;
            StackedCommand sc1 = null;
            StackedCommand sc2 = null;
            if (selection.length > 0) {
                // prevent to edit part of the command stack that has already been executed
                sc1 = (StackedCommand) selection[0].getData();
                sc2 = (StackedCommand) selection[selection.length - 1].getData();
                int lastSelectionIndex = commandTableViewer.getIndex(sc2);
                sc2 = (StackedCommand) commandTableViewer.getElementAt(lastSelectionIndex + 1);
                pastBeforeAuthorized = sc1 != null && sc1.getStackedState() == StackedState.DISARMED;
                pastAfterAuthorized = sc2 == null || sc2.getStackedState() == StackedState.DISARMED;
            } else {
                pastBeforeAuthorized = false;
                pastAfterAuthorized = false;
            }
            if (event.button == 3) {
                contextMenu.setVisible(true);
                mItemCopy.setEnabled(selection.length != 0);
                mItemCut.setEnabled(selection.length != 0);
                mItemPaste.setEnabled(CommandClipboard.hasData());
                mItemPasteBefore.setEnabled(CommandClipboard.hasData() && pastBeforeAuthorized);
                mItemPasteAfter.setEnabled(CommandClipboard.hasData() && pastAfterAuthorized);
            } else {
                contextMenu.setVisible(false);
            }
        }
    });
}
Also used : Table(org.eclipse.swt.widgets.Table) Listener(org.eclipse.swt.widgets.Listener) ISourceProviderListener(org.eclipse.ui.ISourceProviderListener) SelectionListener(org.eclipse.swt.events.SelectionListener) TableItem(org.eclipse.swt.widgets.TableItem) ArrayList(java.util.ArrayList) MenuItem(org.eclipse.swt.widgets.MenuItem) MessageBox(org.eclipse.swt.widgets.MessageBox) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 47 with MessageBox

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

the class AddManualEventDialog method okPressed.

@Override
protected void okPressed() {
    String source = "Manual";
    if (userText != null && !userText.getText().isEmpty()) {
        source += " :: " + userText.getText();
    } else if (userLbl != null) {
        source += " :: " + userLbl.getText();
    }
    String message = messageText.getText();
    long generationTime = TimeEncoding.fromCalendar(RCPUtils.toCalendar(generationDatePicker, generationTimePicker));
    long receptionTime = TimeCatalogue.getInstance().getMissionTime();
    EventSeverity severity = EventSeverity.internalGetValueMap().findValueByNumber(severityCombo.getSelectionIndex() > 3 ? severityCombo.getSelectionIndex() + 1 : severityCombo.getSelectionIndex());
    EventCatalogue catalogue = EventCatalogue.getInstance();
    try {
        catalogue.createEvent(source, sequenceNumber++, message, generationTime, receptionTime, severity).whenComplete((data, exc) -> {
            if (exc == null) {
                Display.getDefault().asyncExec(() -> {
                    // MessageBox m = new MessageBox(getShell(),
                    // SWT.OK | SWT.ICON_INFORMATION | SWT.APPLICATION_MODAL);
                    // m.setText("Ok");
                    // m.setMessage("Added the manual event successfully.\n" + new String(data));
                    // m.open();
                    close();
                });
            } else {
                Display.getDefault().asyncExec(() -> {
                    MessageBox m = new MessageBox(getShell(), SWT.OK | SWT.ICON_ERROR | SWT.APPLICATION_MODAL);
                    m.setText("Error");
                    m.setMessage(exc.getMessage());
                    m.open();
                });
            }
        });
    } catch (Exception e) {
        Display.getDefault().asyncExec(() -> {
            MessageBox m = new MessageBox(getShell(), SWT.OK | SWT.ICON_ERROR | SWT.APPLICATION_MODAL);
            m.setText("Error");
            m.setMessage("Error: " + e.getMessage());
            m.open();
        });
    }
}
Also used : EventSeverity(org.yamcs.protobuf.Yamcs.Event.EventSeverity) EventCatalogue(org.yamcs.studio.core.model.EventCatalogue) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 48 with MessageBox

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

the class DataLinkTableViewer method showMessage.

private void showMessage(Shell shell, String string) {
    MessageBox dialog = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
    dialog.setText("Error");
    dialog.setMessage(string);
    // open dialog and await user selection
    dialog.open();
}
Also used : MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 49 with MessageBox

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

the class AbstractBoolControlFigure method openConfirmDialog.

/**
 * open a confirm dialog.
 *
 * @return false if user canceled, true if user pressed OK or no confirm
 *         dialog needed.
 */
private boolean openConfirmDialog() {
    // confirm & password input dialog
    if (password == null || password.equals("")) {
        MessageBox mb = new MessageBox(Display.getCurrent().getActiveShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
        mb.setMessage(confirmTip);
        mb.setText("Confirm Dialog");
        int val = mb.open();
        if (val == SWT.YES)
            return true;
    } else {
        InputDialog dlg = new InputDialog(Display.getCurrent().getActiveShell(), "Password Input Dialog", "Please input the password", "", new IInputValidator() {

            @Override
            public String isValid(String newText) {
                if (newText.equals(password))
                    return null;
                else
                    return "Password error!";
            }
        }) {

            @Override
            protected int getInputTextStyle() {
                return SWT.SINGLE | SWT.PASSWORD;
            }
        };
        dlg.setBlockOnOpen(true);
        int val = dlg.open();
        if (val == Window.OK)
            return true;
    }
    return false;
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) MessageBox(org.eclipse.swt.widgets.MessageBox) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 50 with MessageBox

use of org.eclipse.swt.widgets.MessageBox in project cogtool by cogtool.

the class WebCrawlImportDialog method messageBox.

public boolean messageBox(String message, int style) {
    if (style == SWT.ICON_ERROR) {
        message += "Do you want to try again?";
        style = style | SWT.YES | SWT.NO;
    }
    messageBox = new MessageBox(dialog, style);
    messageBox.setMessage(message);
    if (messageBox.open() == SWT.NO) {
        userResponse = CANCEL;
        dialog.close();
        return false;
    }
    return true;
}
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