Search in sources :

Example 41 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project linuxtools by eclipse.

the class RemoveConnectionCommandHandler method execute.

@Override
public Object execute(ExecutionEvent event) {
    final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    if (activePart instanceof CommonNavigator) {
        final CommonViewer viewer = ((CommonNavigator) activePart).getCommonViewer();
        final ITreeSelection selection = (ITreeSelection) viewer.getSelection();
        Stream.of(selection.getPaths()).forEach(p -> DockerConnectionManager.getInstance().removeConnection((IDockerConnection) p.getLastSegment()));
    }
    return null;
}
Also used : CommonNavigator(org.eclipse.ui.navigator.CommonNavigator) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) CommonViewer(org.eclipse.ui.navigator.CommonViewer) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection)

Example 42 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project linuxtools by eclipse.

the class RemoveContainerLogCommandHandler method execute.

@Override
public Object execute(final ExecutionEvent event) {
    final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    List<IDockerContainer> selectedContainers = CommandUtils.getSelectedContainers(activePart);
    if (activePart instanceof DockerContainersView) {
        connection = ((DockerContainersView) activePart).getConnection();
    }
    if (selectedContainers.size() != 1 || connection == null)
        return null;
    container = selectedContainers.get(0);
    IDockerContainerInfo info = connection.getContainerInfo(container.id());
    if (info.config().tty()) {
        Map<String, Object> properties = new HashMap<>();
        properties.put(ITerminalsConnectorConstants.PROP_DELEGATE_ID, "org.eclipse.tm.terminal.connector.streams.launcher.streams");
        properties.put(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID, "org.eclipse.tm.terminal.connector.streams.StreamsConnector");
        properties.put(ITerminalsConnectorConstants.PROP_TITLE, info.name());
        ITerminalService service = TerminalServiceFactory.getService();
        service.closeConsole(properties, null);
        return null;
    }
    final RunConsole rc = RunConsole.findConsole(container);
    if (rc != null) {
        RunConsole.removeConsole(rc);
    }
    return null;
}
Also used : IDockerContainer(org.eclipse.linuxtools.docker.core.IDockerContainer) RunConsole(org.eclipse.linuxtools.internal.docker.ui.consoles.RunConsole) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) HashMap(java.util.HashMap) ITerminalService(org.eclipse.tm.terminal.view.core.interfaces.ITerminalService) DockerContainersView(org.eclipse.linuxtools.internal.docker.ui.views.DockerContainersView) IDockerContainerInfo(org.eclipse.linuxtools.docker.core.IDockerContainerInfo)

Example 43 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project linuxtools by eclipse.

the class RemoveTagCommandHandler method execute.

@Override
public Object execute(final ExecutionEvent event) {
    final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    final List<IDockerImage> selectedImages = CommandUtils.getSelectedImages(activePart);
    final IDockerConnection connection = CommandUtils.getCurrentConnection(activePart);
    if (selectedImages.size() != 1 || connection == null) {
        Activator.log(new DockerException(CommandMessages.getString(// $NON-NLS-1$
        "Command.missing.selection.failure")));
        return null;
    }
    final IDockerImage image = selectedImages.get(0);
    final ImageRemoveTag wizard = new ImageRemoveTag(image);
    final boolean removeTag = CommandUtils.openWizard(wizard, HandlerUtil.getActiveShell(event));
    if (removeTag) {
        performRemoveTagImage(connection, wizard.getTag());
    }
    return null;
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) ImageRemoveTag(org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRemoveTag)

Example 44 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project linuxtools by eclipse.

the class ShowAllContainersCommandHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    final boolean checked = !HandlerUtil.toggleCommandState(event.getCommand());
    if (activePart instanceof DockerContainersView) {
        final DockerContainersView containersView = (DockerContainersView) activePart;
        containersView.showAllContainers(checked);
    }
    return null;
}
Also used : IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) DockerContainersView(org.eclipse.linuxtools.internal.docker.ui.views.DockerContainersView)

Example 45 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project linuxtools by eclipse.

the class ShowInSystemExplorerCommandHandler method execute.

@Override
public Object execute(final ExecutionEvent event) {
    final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    final List<DockerContainerVolume> volumes = CommandUtils.getSelectedVolumes(activePart);
    if (volumes == null || volumes.isEmpty()) {
        return null;
    }
    final DockerContainerVolume selectedVolume = volumes.get(0);
    final File hostFile = new File(selectedVolume.getHostPath());
    final String launchCmd = getShowInSystemExplorerCommand(hostFile);
    if (launchCmd == null) {
        return null;
    }
    final Job job = new Job(CommandMessages.getString("command.showIn.systemExplorer")) {

        // $NON-NLS-1$
        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            try {
                final Process p = getLaunchProcess(launchCmd, hostFile);
                final int retCode = p.waitFor();
                if (retCode != 0 && !Util.isWindows()) {
                    Activator.log(new DockerException(CommandMessages.getFormattedString(// $NON-NLS-1$
                    "command.showIn.systemExplorer.failure.command.execute", launchCmd, Integer.toString(retCode))));
                }
            } catch (IOException | InterruptedException e) {
                Activator.logErrorMessage(CommandMessages.getFormattedString(// $NON-NLS-1$
                "command.showIn.systemExplorer.failure", launchCmd), e);
            } finally {
                monitor.done();
            }
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();
    return null;
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) IOException(java.io.IOException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) DockerContainerVolume(org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerContentProvider.DockerContainerVolume) Job(org.eclipse.core.runtime.jobs.Job) File(java.io.File)

Aggregations

IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)116 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)30 IEditorPart (org.eclipse.ui.IEditorPart)25 ISelection (org.eclipse.jface.viewers.ISelection)22 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)22 Shell (org.eclipse.swt.widgets.Shell)21 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)21 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)16 IEditorInput (org.eclipse.ui.IEditorInput)14 ArrayList (java.util.ArrayList)13 IViewPart (org.eclipse.ui.IViewPart)13 IFile (org.eclipse.core.resources.IFile)11 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)11 PartInitException (org.eclipse.ui.PartInitException)9 Job (org.eclipse.core.runtime.jobs.Job)8 DockerException (org.eclipse.linuxtools.docker.core.DockerException)7 IDockerContainer (org.eclipse.linuxtools.docker.core.IDockerContainer)7 IResource (org.eclipse.core.resources.IResource)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 Command (org.eclipse.gef.commands.Command)6