blob: cc350464c6cc2dbd0f678ff5b623dfa737da810a [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.invocator.ui.handlers;
import java.util.List;
import org.eclipse.apogy.core.invocator.AbstractProgramRuntime;
import org.eclipse.apogy.core.invocator.ApogyCoreInvocatorFacade;
import org.eclipse.apogy.core.invocator.Program;
import org.eclipse.apogy.core.invocator.ProgramRuntimeState;
import org.eclipse.apogy.core.invocator.ui.parts.ProgramPart;
import org.eclipse.e4.core.di.annotations.CanExecute;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.model.application.ui.basic.impl.PartImpl;
@SuppressWarnings("restriction")
public class ResumeProgramRuntimeHandler extends AbstractProgramRuntimeHandler {
@Execute
public void execute(MPart part) {
ProgramPart programPart = (ProgramPart) ((PartImpl) part).getObject();
Program program = programPart.getSelectedProgram();
List<AbstractProgramRuntime> runtimes = programPart.getRuntimes();
if (runtimes.size() > 0) {
for (int i = runtimes.size() - 1; i >= 0; i--) {
AbstractProgramRuntime runtime = runtimes.get(i);
if (runtime.getProgram() == program) {
runtime.resume();
break;
}
}
}
}
@Override
@CanExecute
public boolean canExecute(MPart part) {
if (ApogyCoreInvocatorFacade.INSTANCE.getActiveInvocatorSession() == null) {
return false;
}
if (ApogyCoreInvocatorFacade.INSTANCE.getActiveInvocatorSession().getProgramRuntimesList() == null) {
return false;
}
// if (part instanceof PartImpl && ((PartImpl) part).getObject() instanceof
// ProgramPart) {
if (part instanceof PartImpl && ((PartImpl) part).getObject() instanceof ProgramPart) {
ProgramPart programPart = (ProgramPart) ((PartImpl) part).getObject();
Program program = programPart.getSelectedProgram();
if (program == null)
return false;
for (AbstractProgramRuntime runtime : programPart.getRuntimes()) {
if (programPart.getRuntimes().indexOf(runtime) == programPart.getRuntimes().size() - 1
&& runtime.getProgram() == program && runtime.getState() == ProgramRuntimeState.SUSPENDED
|| runtime.getState() == ProgramRuntimeState.INITIALIZED) {
/**
* Can be executed if the runtime is suspended or initialized
*/
return true;
}
}
}
return false;
}
}