| /******************************************************************************* |
| * 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 - initial API and implementation |
| * |
| * SPDX-License-Identifier: EPL-1.0 |
| * |
| *******************************************************************************/ |
| package org.eclipse.apogy.core.environment.surface.commands; |
| |
| import java.lang.reflect.InvocationTargetException; |
| import java.util.Iterator; |
| |
| import org.eclipse.apogy.common.topology.Node; |
| import org.eclipse.apogy.common.topology.ui.NodePresentation; |
| import org.eclipse.apogy.core.environment.surface.CartesianTriangularMeshMapLayer; |
| 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.core.runtime.IProgressMonitor; |
| import org.eclipse.jface.dialogs.ProgressMonitorDialog; |
| import org.eclipse.jface.operation.IRunnableWithProgress; |
| import org.eclipse.jface.viewers.IStructuredSelection; |
| import org.eclipse.swt.widgets.Display; |
| import org.eclipse.ui.handlers.HandlerUtil; |
| import org.slf4j.Logger; |
| import org.slf4j.LoggerFactory; |
| |
| public class ToggleCartesianTriangularMeshMapLayerVisibilityCommandHandler extends AbstractHandler implements |
| IHandler { |
| |
| private static final Logger Logger = LoggerFactory.getLogger(ToggleCartesianTriangularMeshMapLayerVisibilityCommandHandler.class); |
| |
| @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 CartesianTriangularMeshMapLayer) |
| { |
| final CartesianTriangularMeshMapLayer layer = (CartesianTriangularMeshMapLayer) selection; |
| IRunnableWithProgress runnable = new IRunnableWithProgress() |
| { |
| @Override |
| public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException |
| { |
| Node node = layer.getAbstractMapLayerNode(); |
| NodePresentation nodePresentation = org.eclipse.apogy.common.topology.ui.Activator.getTopologyPresentationRegistry().getPresentationNode(node); |
| if(nodePresentation != null) |
| { |
| nodePresentation.setVisible(!nodePresentation.isVisible()); |
| } |
| } |
| }; |
| |
| try |
| { |
| new ProgressMonitorDialog(Display.getCurrent().getActiveShell()).run(true, true, runnable); |
| } |
| catch (InvocationTargetException e) |
| { |
| Logger.error(e.getMessage(), e); |
| } |
| catch (InterruptedException e) |
| { |
| Logger.error(e.getMessage(), e); |
| } |
| } |
| } |
| return null; |
| } |
| } |