| /******************************************************************************* |
| * Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency |
| * 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: |
| * Pierre Allard, |
| * Regent L'Archeveque, |
| <<<<<<< HEAD |
| * Sebastien Gemme |
| * |
| ======= |
| * Sebastien Gemme - initial API and implementation |
| * |
| >>>>>>> refs/heads/eclipse_pa |
| * SPDX-License-Identifier: EPL-1.0 |
| * |
| *******************************************************************************/ |
| package org.eclipse.apogy.common.topology.ui.commands; |
| |
| import java.util.Iterator; |
| |
| import org.eclipse.apogy.common.converters.ApogyCommonConvertersFacade; |
| import org.eclipse.apogy.common.topology.Node; |
| import org.eclipse.apogy.common.topology.ui.NodePresentation; |
| import org.eclipse.core.commands.AbstractHandler; |
| import org.eclipse.core.commands.ExecutionEvent; |
| import org.eclipse.core.commands.ExecutionException; |
| import org.eclipse.core.commands.IHandler; |
| import org.eclipse.jface.viewers.IStructuredSelection; |
| import org.eclipse.ui.handlers.HandlerUtil; |
| |
| public class ToggleNodeVisibilityCommand extends AbstractHandler implements IHandler { |
| @Override |
| public Object execute(ExecutionEvent event) throws ExecutionException { |
| Iterator<?> selections = ((IStructuredSelection) HandlerUtil.getActiveMenuSelection(event)).iterator(); |
| |
| while (selections.hasNext()) { |
| Object selection = selections.next(); |
| |
| if (selection instanceof Node) { |
| Node node = (Node) selection; |
| NodePresentation nodePresentation = (NodePresentation) ApogyCommonConvertersFacade.INSTANCE |
| .convert(node, NodePresentation.class); |
| |
| if (nodePresentation != null) { |
| nodePresentation.setVisible(!nodePresentation.isVisible()); |
| } |
| } |
| } |
| return null; |
| } |
| } |