Search in sources :

Example 31 with ExecutionException

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

the class RunScriptHandler method prepareNonLocalScript.

/**
 * Attempts to set up a channel for a script that runs on a non-local host or user.
 * @return <code>true</code> on success, <code>false</code> on failure.
 * @throws ExecutionException If failure occurs during a (non-simple) launch,
 * this will throw an exception instead of returning <code>false</code>.
 */
private void prepareNonLocalScript() throws ExecutionException {
    try {
        ScpClient scpclient = new ScpClient(remoteOptions);
        // $NON-NLS-1$
        tmpfileName = new Path("/tmp").append(getFileName(fileName)).toOSString();
        scpclient.transfer(fileName, tmpfileName);
    } catch (final JSchException | IOException e) {
        String message = e instanceof JSchException ? // $NON-NLS-1$
        Localization.getString("RunScriptHandler.checkCredentials") : // $NON-NLS-1$
        Localization.getString("RunScriptHandler.ioError");
        throw new ExecutionException(message, e);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) JSchException(com.jcraft.jsch.JSchException) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException) ScpClient(org.eclipse.linuxtools.systemtap.ui.consolelog.ScpClient)

Example 32 with ExecutionException

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

the class ExportEventsHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    Shell shell = HandlerUtil.getActiveShell(event);
    IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
    EventLogView eventLogView = (EventLogView) part;
    // Ask for file to export
    FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
    dialog.setFilterExtensions(new String[] { "*.csv" });
    String targetFile = dialog.open();
    if (targetFile == null) {
        // cancelled
        return null;
    }
    // Write CSV
    try {
        List<Event> events = eventLogView.getEventLog().getEvents();
        writeEvents(new File(targetFile), events);
        MessageDialog.openInformation(shell, "Export Events", "Events exported successfully.");
    } catch (Exception e) {
        MessageDialog.openError(shell, "Export Events", "Unable to perform events export.\nDetails:" + e.getMessage());
    }
    return null;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) Event(org.yamcs.protobuf.Yamcs.Event) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 33 with ExecutionException

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

the class ExportCommandsHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    Shell shell = HandlerUtil.getActiveShell(event);
    IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
    CommandHistoryView view = (CommandHistoryView) part;
    // Ask for file to export
    FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
    dialog.setFilterExtensions(new String[] { "*.csv" });
    String targetFile = dialog.open();
    if (targetFile == null) {
        // cancelled
        return null;
    }
    // Write CSV
    try {
        writeEvents(new File(targetFile), view.getTableViewer().getTable());
        MessageDialog.openInformation(shell, "Export Command History", "Command History exported successfully.");
    } catch (Exception e) {
        MessageDialog.openError(shell, "Export Command History", "Unable to perform command history export.\nDetails:" + e.getMessage());
    }
    return null;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 34 with ExecutionException

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

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

the class OPIShell method sendUpdateCommand.

/**
 * Alert whoever is listening that a new OPIShell has been created.
 */
private static void sendUpdateCommand() {
    IServiceLocator serviceLocator = PlatformUI.getWorkbench();
    ICommandService commandService = (ICommandService) serviceLocator.getService(ICommandService.class);
    try {
        Command command = commandService.getCommand(OPI_SHELLS_CHANGED_ID);
        command.executeWithChecks(new ExecutionEvent());
    } catch (ExecutionException | NotHandledException | NotEnabledException | NotDefinedException e) {
        log.log(Level.WARNING, "Failed to send OPI shells changed command", e);
    }
}
Also used : NotHandledException(org.eclipse.core.commands.NotHandledException) Command(org.eclipse.core.commands.Command) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) IServiceLocator(org.eclipse.ui.services.IServiceLocator) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) ExecutionException(org.eclipse.core.commands.ExecutionException) NotEnabledException(org.eclipse.core.commands.NotEnabledException) ICommandService(org.eclipse.ui.commands.ICommandService)

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