| /******************************************************************************* |
| * 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 |
| * |
| <<<<<<< HEAD |
| * Contributors: |
| * Pierre Allard - initial API and implementation |
| * Regent L'Archeveque |
| * |
| ======= |
| * Contributors: |
| * Pierre Allard, |
| * Regent L'Archeveque - initial API and implementation |
| * |
| >>>>>>> refs/heads/eclipse_pa |
| * SPDX-License-Identifier: EPL-1.0 |
| *******************************************************************************/ |
| package org.eclipse.apogy.examples.satellite.ui.commands; |
| |
| import java.util.Iterator; |
| |
| import org.eclipse.apogy.examples.satellite.AbstractConstellationPlanner; |
| 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.emf.common.command.IdentityCommand; |
| import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain; |
| import org.eclipse.emf.edit.domain.EditingDomain; |
| import org.eclipse.jface.viewers.IStructuredSelection; |
| import org.eclipse.ui.handlers.HandlerUtil; |
| import org.slf4j.Logger; |
| import org.slf4j.LoggerFactory; |
| |
| //FIXME Convert into E4 |
| |
| public class GenerateConstellationCommandPlan extends AbstractHandler implements IHandler { |
| |
| private static final Logger Logger = LoggerFactory.getLogger(GenerateConstellationCommandPlan.class); |
| |
| @Override |
| public Object execute(ExecutionEvent event) throws ExecutionException { |
| Iterator<?> selections = ((IStructuredSelection) HandlerUtil.getActiveMenuSelection(event)).iterator(); |
| AbstractConstellationPlanner planner = (AbstractConstellationPlanner) selections.next(); |
| |
| if (planner != null) { |
| try { |
| new Job("Constellation Planner") { |
| @Override |
| protected IStatus run(IProgressMonitor monitor) { |
| try { |
| planner.plan(); |
| EditingDomain domain = AdapterFactoryEditingDomain.getEditingDomainFor(planner); |
| if (domain != null) { |
| domain.getCommandStack().execute(IdentityCommand.INSTANCE); |
| } |
| } catch (Exception e) { |
| Logger.error(e.getMessage(), e); |
| } |
| return Status.OK_STATUS; |
| } |
| }.schedule(); |
| } catch (Exception e) { |
| Logger.error(e.getMessage(), e); |
| } |
| } |
| return null; |
| } |
| } |