Search in sources :

Example 1 with CommandingCatalogue

use of org.yamcs.studio.core.model.CommandingCatalogue in project yamcs-studio by yamcs.

the class CommandQueuesTableViewer method updateQueueState.

// rebuild doesn't seem to do anything and therefore is not currently included in rest api
// keeping it around for future reference mostly
private void updateQueueState(CommandQueueInfo queue, QueueState queueState, boolean rebuild) {
    EditCommandQueueRequest req = EditCommandQueueRequest.newBuilder().setState(queueState.toString()).build();
    CommandingCatalogue catalogue = CommandingCatalogue.getInstance();
    catalogue.editQueue(queue, req);
}
Also used : EditCommandQueueRequest(org.yamcs.protobuf.Rest.EditCommandQueueRequest) CommandingCatalogue(org.yamcs.studio.core.model.CommandingCatalogue)

Example 2 with CommandingCatalogue

use of org.yamcs.studio.core.model.CommandingCatalogue in project yamcs-studio by yamcs.

the class ArmCommandHandler method armCommand.

private void armCommand(Shell activeShell, CommandStackView view, StackedCommand command) throws ExecutionException {
    IssueCommandRequest req = command.toIssueCommandRequest().setDryRun(true).build();
    CommandingCatalogue catalogue = CommandingCatalogue.getInstance();
    String qname;
    try {
        qname = command.getSelectedAliasEncoded();
    } catch (UnsupportedEncodingException e1) {
        throw new ExecutionException(e1.getMessage());
    }
    catalogue.sendCommand("realtime", qname, req).whenComplete((data, exc) -> {
        if (exc == null) {
            Display.getDefault().asyncExec(() -> {
                boolean doArm = false;
                SignificanceInfo significance = command.getMetaCommand().getSignificance();
                switch(significance.getConsequenceLevel()) {
                    case WATCH:
                    case WARNING:
                    case DISTRESS:
                    case CRITICAL:
                    case SEVERE:
                        String level = Character.toUpperCase(significance.getConsequenceLevel().toString().charAt(0)) + significance.getConsequenceLevel().toString().substring(1);
                        if (MessageDialog.openConfirm(activeShell, "Confirm", level + ": Are you sure you want to arm this command?\n" + "    " + command.toStyledString(view).getString() + "\n\n" + significance.getReasonForWarning())) {
                            doArm = true;
                        }
                        break;
                    case NONE:
                        doArm = true;
                        break;
                    default:
                        throw new IllegalStateException("Unexpected significance level " + significance.getConsequenceLevel());
                }
                if (doArm) {
                    log.info(String.format("Command armed %s", command));
                    command.setStackedState(StackedState.ARMED);
                    view.refreshState();
                }
            });
        } else {
            Display.getDefault().asyncExec(() -> {
                command.setStackedState(StackedState.REJECTED);
                view.clearArm();
                view.refreshState();
            });
        }
    });
}
Also used : SignificanceInfo(org.yamcs.protobuf.Mdb.SignificanceInfo) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CommandingCatalogue(org.yamcs.studio.core.model.CommandingCatalogue) ExecutionException(org.eclipse.core.commands.ExecutionException) IssueCommandRequest(org.yamcs.protobuf.Rest.IssueCommandRequest)

Example 3 with CommandingCatalogue

use of org.yamcs.studio.core.model.CommandingCatalogue 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 4 with CommandingCatalogue

use of org.yamcs.studio.core.model.CommandingCatalogue in project yamcs-studio by yamcs.

the class CommandQueuedTableViewer method updateQueueEntryState.

// rebuild doesn't seem to do anything and therefore is not currently included in rest api
// keeping it around for future reference mostly
private void updateQueueEntryState(CommandQueueEntry entry, String state, boolean rebuild) {
    EditCommandQueueEntryRequest req = EditCommandQueueEntryRequest.newBuilder().setState(state).build();
    CommandingCatalogue catalogue = CommandingCatalogue.getInstance();
    catalogue.editQueuedCommand(entry, req);
}
Also used : EditCommandQueueEntryRequest(org.yamcs.protobuf.Rest.EditCommandQueueEntryRequest) CommandingCatalogue(org.yamcs.studio.core.model.CommandingCatalogue)

Example 5 with CommandingCatalogue

use of org.yamcs.studio.core.model.CommandingCatalogue in project yamcs-studio by yamcs.

the class IssueCommandHandler method issueCommand.

private void issueCommand(Shell activeShell, CommandStackView view, StackedCommand command) throws ExecutionException {
    IssueCommandRequest req = command.toIssueCommandRequest().build();
    CommandingCatalogue catalogue = CommandingCatalogue.getInstance();
    String qname;
    try {
        qname = command.getSelectedAliasEncoded();
    } catch (UnsupportedEncodingException e1) {
        throw new ExecutionException(e1.getMessage());
    }
    catalogue.sendCommand("realtime", qname, req).whenComplete((data, exc) -> {
        if (exc == null) {
            Display.getDefault().asyncExec(() -> {
                log.info(String.format("Command issued. %s", req));
                command.setStackedState(StackedState.ISSUED);
                view.selectActiveCommand();
                view.refreshState();
            });
        } else {
            Display.getDefault().asyncExec(() -> {
                command.setStackedState(StackedState.REJECTED);
                view.refreshState();
            });
        }
    });
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) CommandingCatalogue(org.yamcs.studio.core.model.CommandingCatalogue) ExecutionException(org.eclipse.core.commands.ExecutionException) IssueCommandRequest(org.yamcs.protobuf.Rest.IssueCommandRequest)

Aggregations

CommandingCatalogue (org.yamcs.studio.core.model.CommandingCatalogue)7 ExecutionException (org.eclipse.core.commands.ExecutionException)3 IssueCommandRequest (org.yamcs.protobuf.Rest.IssueCommandRequest)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Iterator (java.util.Iterator)1 AbstractHandler (org.eclipse.core.commands.AbstractHandler)1 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)1 IInputValidator (org.eclipse.jface.dialogs.IInputValidator)1 InputDialog (org.eclipse.jface.dialogs.InputDialog)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Window (org.eclipse.jface.window.Window)1 SWT (org.eclipse.swt.SWT)1 GridData (org.eclipse.swt.layout.GridData)1 Composite (org.eclipse.swt.widgets.Composite)1 Control (org.eclipse.swt.widgets.Control)1 Display (org.eclipse.swt.widgets.Display)1 MessageBox (org.eclipse.swt.widgets.MessageBox)1 Shell (org.eclipse.swt.widgets.Shell)1 HandlerUtil (org.eclipse.ui.handlers.HandlerUtil)1