Search in sources :

Example 61 with ExecutionException

use of org.eclipse.core.commands.ExecutionException in project AutoRefactor by JnRouvignac.

the class ChooseRefactoringsWizardHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final Shell shell = HandlerUtil.getActiveShell(event);
    try {
        // Retrieve the targeted java element before the menu item is disposed by the framework
        final Wizard wizard = new ChooseRefactoringsWizard(AutoRefactorHandler.getSelectedJavaElements(event));
        final WizardDialog dialog = new WizardDialog(shell, wizard);
        dialog.open();
    } catch (final Exception e) {
        Display.getDefault().asyncExec(new Runnable() {

            @Override
            public void run() {
                final StringWriter sw = new StringWriter();
                final PrintWriter pw = new PrintWriter(sw);
                e.printStackTrace(pw);
                openInformation(shell, "Info", "An error has occurred:\n\n" + sw.toString());
            }
        });
    }
    return null;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) StringWriter(java.io.StringWriter) Wizard(org.eclipse.jface.wizard.Wizard) WizardDialog(org.eclipse.jface.wizard.WizardDialog) ExecutionException(org.eclipse.core.commands.ExecutionException) PrintWriter(java.io.PrintWriter)

Example 62 with ExecutionException

use of org.eclipse.core.commands.ExecutionException in project linuxtools by eclipse.

the class RunScriptHandler method isGuru.

/**
 * Checks the current script to determine if guru mode is required in order to run. This is determined
 * by the presence of embedded C.
 * @return True if the script contains embedded C code.
 */
private boolean isGuru() throws ExecutionException {
    File f = new File(fileName);
    try (FileReader fr = new FileReader(f)) {
        int curr = 0;
        int prev = 0;
        boolean front = false;
        boolean embedded = false;
        boolean inLineComment = false;
        boolean inBlockComment = false;
        while (-1 != (curr = fr.read())) {
            if (!inLineComment && !inBlockComment && prev == '%' && curr == '{') {
                front = true;
            } else if (!inLineComment && !inBlockComment && prev == '%' && curr == '}' && front) {
                embedded = true;
                break;
            } else if (!inBlockComment && ((prev == '/' && curr == '/') || curr == '#')) {
                inLineComment = true;
            } else if (!inLineComment && prev == '/' && curr == '*') {
                inBlockComment = true;
            } else if (curr == '\n') {
                inLineComment = false;
            } else if (prev == '*' && curr == '/') {
                inBlockComment = false;
            }
            prev = curr;
        }
        if (embedded) {
            return true;
        }
    } catch (FileNotFoundException fnfe) {
        // $NON-NLS-1$
        throw new ExecutionException(Localization.getString("RunScriptHandler.couldNotOpenScriptFile"), fnfe);
    } catch (IOException ie) {
        // $NON-NLS-1$
        throw new ExecutionException(Localization.getString("RunScriptHandler.fileIOError"), ie);
    }
    return false;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 63 with ExecutionException

use of org.eclipse.core.commands.ExecutionException 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 64 with ExecutionException

use of org.eclipse.core.commands.ExecutionException in project yamcs-studio by yamcs.

the class ExportCommandStackHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    // Get current command stack
    Collection<StackedCommand> scs = org.yamcs.studio.commanding.stack.CommandStack.getInstance().getCommands();
    if (scs == null || scs.isEmpty()) {
        MessageDialog.openError(Display.getCurrent().getActiveShell(), "Export Command Stack", "Current command stack is empty. No command to export.");
        return null;
    }
    FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
    dialog.setFilterExtensions(new String[] { "*.xml" });
    // dialog.setFilterPath("c:\\temp");
    String exportFile = dialog.open();
    System.out.println("export file choosen: " + exportFile);
    if (exportFile == null) {
        // cancelled
        return null;
    }
    // Build model
    org.yamcs.studio.commanding.stack.xml.CommandStack exportCommandStack = new org.yamcs.studio.commanding.stack.xml.CommandStack();
    List<org.yamcs.studio.commanding.stack.xml.CommandStack.Command> exportedCommands = exportCommandStack.getCommand();
    for (StackedCommand sc : scs) {
        org.yamcs.studio.commanding.stack.xml.CommandStack.Command c = new org.yamcs.studio.commanding.stack.xml.CommandStack.Command();
        c.setQualifiedName(sc.getMetaCommand().getQualifiedName());
        c.setSelectedAlias(sc.getSelectedAlias());
        c.setComment(sc.getComment());
        exportedCommands.add(c);
        List<CommandArgument> cas = c.getCommandArgument();
        Iterator<Entry<ArgumentInfo, String>> it = sc.getAssignments().entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<ArgumentInfo, String> pair = it.next();
            String argName = pair.getKey().getName();
            String argValue = pair.getValue();
            CommandArgument ca = new CommandArgument();
            ca.setArgumentName(argName);
            ca.setArgumentValue(argValue);
            cas.add(ca);
        }
    }
    // Write model to file
    try {
        File file = new File(exportFile);
        JAXBContext jaxbContext = JAXBContext.newInstance(org.yamcs.studio.commanding.stack.xml.CommandStack.class);
        Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
        jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        jaxbMarshaller.marshal(exportCommandStack, file);
        jaxbMarshaller.marshal(exportCommandStack, System.out);
    } catch (Exception e) {
        MessageDialog.openError(Display.getCurrent().getActiveShell(), "Export Command Stack", "Unable to perform command stack export.\nDetails:" + e.getMessage());
        return null;
    }
    MessageDialog.openInformation(Display.getCurrent().getActiveShell(), "Export Command Stack", "Command stack exported successfully.");
    return null;
}
Also used : CommandArgument(org.yamcs.studio.commanding.stack.xml.CommandStack.Command.CommandArgument) JAXBContext(javax.xml.bind.JAXBContext) Entry(java.util.Map.Entry) ArgumentInfo(org.yamcs.protobuf.Mdb.ArgumentInfo) Marshaller(javax.xml.bind.Marshaller) ExecutionException(org.eclipse.core.commands.ExecutionException) FileDialog(org.eclipse.swt.widgets.FileDialog) Map(java.util.Map) File(java.io.File)

Example 65 with ExecutionException

use of org.eclipse.core.commands.ExecutionException 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

ExecutionException (org.eclipse.core.commands.ExecutionException)66 CoreException (org.eclipse.core.runtime.CoreException)20 IFile (org.eclipse.core.resources.IFile)15 ArrayList (java.util.ArrayList)13 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)13 IStatus (org.eclipse.core.runtime.IStatus)12 Shell (org.eclipse.swt.widgets.Shell)12 Status (org.eclipse.core.runtime.Status)11 IEditorPart (org.eclipse.ui.IEditorPart)11 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)10 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 ISelection (org.eclipse.jface.viewers.ISelection)8 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)8 File (java.io.File)7 List (java.util.List)7 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)7 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)7 IProject (org.eclipse.core.resources.IProject)7 FileEditorInput (org.eclipse.ui.part.FileEditorInput)7