/******************************************************************************* * Copyright (c) 2012 Wind River Systems, Inc. and others. 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: * Wind River Systems - initial API and implementation *******************************************************************************/ package org.eclipse.tcf.te.tcf.processes.ui.handler; import java.util.Iterator; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.tcf.protocol.Protocol; import org.eclipse.tcf.te.tcf.processes.core.model.interfaces.IProcessContextNode; import org.eclipse.tcf.te.tcf.processes.core.model.steps.DetachStep; import org.eclipse.ui.handlers.HandlerUtil; /** * Detach from process command handler implementation. */ public class DetachHandler extends AbstractHandler { /* (non-Javadoc) * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) */ @Override public Object execute(ExecutionEvent event) throws ExecutionException { ISelection selection = HandlerUtil.getCurrentSelection(event); if (selection instanceof IStructuredSelection && !selection.isEmpty()) { Iterator<?> iterator = ((IStructuredSelection)selection).iterator(); while (iterator.hasNext()) { final Object candidate = iterator.next(); if (candidate instanceof IProcessContextNode) { Runnable runnable = new Runnable() { @Override public void run() { DetachStep step = new DetachStep(); step.executeDetach((IProcessContextNode)candidate, null); } }; Protocol.invokeLater(runnable); } } } return null; } }