/******************************************************************************* * Copyright (c) 2014, 2015 Red Hat. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Red Hat - Initial Contribution *******************************************************************************/ package org.eclipse.linuxtools.internal.docker.ui.commands; import java.util.stream.Stream; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.jface.viewers.ITreeSelection; import org.eclipse.linuxtools.docker.core.DockerConnectionManager; import org.eclipse.linuxtools.docker.core.IDockerConnection; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.handlers.HandlerUtil; import org.eclipse.ui.navigator.CommonNavigator; import org.eclipse.ui.navigator.CommonViewer; /** * Removes the selected {@link IDockerConnection}(s) */ public class RemoveConnectionCommandHandler extends AbstractHandler { @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; } }