blob: e7137558d22e543b8761308eb8983b5ca7a58c67 [file] [log] [blame]
/*******************************************************************************
* 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,
* Olivier L. Larouche - initial API and implementation
*
* SPDX-License-Identifier: EPL-1.0
*******************************************************************************/
package org.eclipse.apogy.core.topology.ui.commands;
import java.util.Iterator;
import org.eclipse.apogy.core.invocator.Variable;
import org.eclipse.apogy.core.topology.ui.Activator;
import org.eclipse.apogy.core.topology.ui.ApogyCoreTopologyUIFacade;
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.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;
// FIXME Refactor into E4 handler.
public class ToggleVariableTopologyVisibilityCommandHandler 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 Variable)
{
final Variable variable = (Variable) selection;
Job job = new Job("Toggling Variable Visibility")
{
@Override
protected IStatus run(IProgressMonitor monitor)
{
try
{
ApogyCoreTopologyUIFacade.INSTANCE.toggleVisibility(variable);
return Status.OK_STATUS;
}
catch(Throwable t)
{
return new Status(IStatus.ERROR, Activator.ID, "Failed to toggle variable <" + variable.getName() + "> visibility !", t);
}
}
};
job.schedule();
}
}
return null;
}
}