blob: 486bdcb3707fd904cc07694845fb0e7af2cf535b [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:
<<<<<<< HEAD
* Pierre Allard - initial API and implementation
* Regent L'Archeveque
*
=======
* Pierre Allard,
* Regent L'Archeveque - initial API and implementation
*
>>>>>>> refs/heads/eclipse_pa
* SPDX-License-Identifier: EPL-1.0
*
*******************************************************************************/
package org.eclipse.apogy.addons.vehicle.ui.commands;
import java.util.Iterator;
import org.eclipse.apogy.addons.vehicle.VehiclePoseCorrector;
import org.eclipse.apogy.common.ApogyCommonOSGiUtilities;
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;
public class ReInitializeWheeledVehiclePoseCorrectorCommand 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 VehiclePoseCorrector) {
final VehiclePoseCorrector corrector = (VehiclePoseCorrector) selection;
if (!corrector.isInitializing()) {
Job job = new Job("ReInitialize WheeledVehiculePoseCorrector") {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
corrector.reInitialize();
return Status.OK_STATUS;
} catch (Throwable t) {
return new Status(IStatus.ERROR, ApogyCommonOSGiUtilities.INSTANCE.getBundleSymbolicName(getClass()),
"Failed to ReInitialize VehiclePoseCorrector !", t);
}
}
};
job.schedule();
} else {
return new Status(IStatus.WARNING, ApogyCommonOSGiUtilities.INSTANCE.getBundleSymbolicName(getClass()),
"ReInitialize rejected : corrector is already initializing.");
}
}
}
return null;
}
}