blob: 8ce695567a02a2a955af11b4626fbf9b9934ebcc [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.wizards;
import org.eclipse.apogy.common.ApogyCommonOSGiUtilities;
import org.eclipse.apogy.common.ui.ApogyCommonUiFacade;
import org.eclipse.apogy.core.invocator.ApogyCoreInvocatorFactory;
import org.eclipse.apogy.core.invocator.ApogyCoreInvocatorPackage;
import org.eclipse.apogy.core.invocator.ProgramSettings;
import org.eclipse.apogy.core.invocator.ProgramsGroup;
import org.eclipse.apogy.core.invocator.ScriptBasedProgram;
import org.eclipse.apogy.core.invocator.ScriptBasedProgramsGroup;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchWizard;
import org.eclipse.ui.plugin.AbstractUIPlugin;
public class NewScriptBasedProgramWizard extends Wizard implements INewWizard {
private NewScriptBasedProgramWizardPage newProgramWizardPage;
private final ScriptBasedProgramsGroup programsGroup;
private ProgramSettings programSettings;
/**
* Constructor for NewProgramsGroupWizard.
*/
public NewScriptBasedProgramWizard(ScriptBasedProgramsGroup programsGroup) {
super();
setWindowTitle("New Script Based Program");
setNeedsProgressMonitor(true);
// FIXME Implement loadImage in ApogyCommonUI.xcore.
ImageDescriptor image = AbstractUIPlugin.imageDescriptorFromPlugin(ApogyCommonOSGiUtilities.INSTANCE.getBundleSymbolicName(getClass()),
"icons/wizban/apogy_new_script_based_program.png");
setDefaultPageImageDescriptor(image);
this.programsGroup = programsGroup;
}
/**
* We will accept the selection in the workbench to see if we can initialize
* from it.
*
* @see IWorkbenchWizard#init(IWorkbench, IStructuredSelection)
*/
@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
}
/**
* Add the page to the wizard.
*/
@Override
public void addPages() {
addPage(getNewProgramWizardPage());
ApogyCommonUiFacade.INSTANCE.adjustWizardPage(getNewProgramWizardPage(), 0.8);
setForcePreviousAndNextButtons(true);
}
/**
* Returns the {@link NewScriptBasedProgramWizardPage }. If null is returned,
* the page is not added to the wizard.
*
* @return Reference to the page.
*/
protected NewScriptBasedProgramWizardPage getNewProgramWizardPage() {
if (this.newProgramWizardPage == null) {
this.newProgramWizardPage = new NewScriptBasedProgramWizardPage(getScriptBasedProgramsGroup(),
ApogyCoreInvocatorPackage.Literals.SCRIPT_BASED_PROGRAM, getProgramSettings());
}
return this.newProgramWizardPage;
}
/**
* This method should be overwritten to create the {@link ScriptBasedProgram}
* with a transaction.
*/
@Override
public boolean performFinish() {
return true;
}
/**
* Create and returns the instance of the {@link ProgramsGroup} that the new
* program will be contained.
*
* @return Reference to the {@link ProgramsGroup}.
*/
protected ScriptBasedProgramsGroup getScriptBasedProgramsGroup() {
if (this.programsGroup == null && this.newProgramWizardPage != null) {
return this.newProgramWizardPage.getScriptBasedProgramsGroup();
}
return this.programsGroup;
}
protected ScriptBasedProgramsGroup getCreationProgramsGroup() {
return this.newProgramWizardPage.getScriptBasedProgramsGroup();
}
protected ProgramSettings getProgramSettings() {
if (this.programSettings == null) {
this.programSettings = ApogyCoreInvocatorFactory.eINSTANCE.createProgramSettings();
}
return this.programSettings;
}
protected EClass getProgramType() {
return this.newProgramWizardPage.getProgramType();
}
}