1 package com.proalpha.pds.ui.wizards.controller;
3 import java.lang.reflect.Method;
4 import java.util.HashMap;
5 import java.util.LinkedHashMap;
8 import org.eclipse.core.runtime.CoreException;
9 import org.eclipse.core.runtime.IStatus;
10 import org.eclipse.core.runtime.Status;
11 import org.eclipse.jface.dialogs.MessageDialog;
12 import org.eclipse.jface.viewers.ISelection;
13 import org.eclipse.jface.viewers.IStructuredSelection;
14 import org.eclipse.jface.window.Window;
15 import org.eclipse.jface.wizard.IWizardPage;
16 import org.eclipse.jface.wizard.Wizard;
17 import org.eclipse.ui.IWorkbench;
18 import org.eclipse.ui.IWorkbenchWizard;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 import com.proalpha.pds.exception.ProALPHANotAvailableException;
23 import com.proalpha.pds.generator.ContentGenerator;
24 import com.proalpha.pds.paconnector.Activator;
25 import com.proalpha.pds.paconnector.PaProject;
26 import com.proalpha.pds.paconnector.RunProgramInPa;
27 import com.proalpha.pds.paconnector.parameter.ParameterFactory;
28 import com.proalpha.pds.paconnector.parameter.StartparameterReader;
29 import com.proalpha.pds.paconnector.repository.RepositoryDelegate;
30 import com.proalpha.pds.paconnector.repository.RepositoryFactory;
31 import com.proalpha.pds.paconnector.repository.RepositoryInformations;
32 import com.proalpha.pds.paconnector.utils.ExceptionUtils;
33 import com.proalpha.pds.templates.data.DataContainerFactory;
34 import com.proalpha.pds.templates.data.IGeneratorDataContainer;
35 import com.proalpha.pds.ui.PaProjectSelection;
36 import com.proalpha.pds.ui.wizards.wizardpages.WizardMainPage;
37 import com.proalpha.pds.ui.wizards.wizardpages.WizardMainPageConfiguration;
38 import com.proalpha.pds.ui.wizards.wizardpages.WizardpageFactory;
50 public abstract class PaWizard extends Wizard {
52 private final Logger logger = LoggerFactory.getLogger(
PaWizard.class);
54 protected ISelection selection;
60 private LinkedHashMap<String, WizardMainPageConfiguration> configList;
68 protected Map<String, Object> wizardSettings;
74 setNeedsProgressMonitor(
true);
76 this.paProject =
Activator.
getDefault().getProjectManager().getPaProjectByProjectExplorer();
78 if (this.paProject ==
null || !this.paProject.getOeProject().getProject().isOpen()
79 || !
this.paProject.isAvailable()) {
82 if (dialog.open() == Window.OK) {
83 this.paProject = dialog.getSelectedProject();
87 if (this.paProject ==
null || !this.paProject.getOeProject().getProject().isOpen()
88 || !
this.paProject.isAvailable()) {
93 logger.debug(
"Running wizard for {}", this.paProject);
97 this.repositoryDelegate = repositoryFactory.createRepositoryDelegate(this.paProject);
98 this.repositoryInformations = repositoryFactory.createRepositoryInformations(this.paProject);
100 this.startparameterReader = parameterFactory.createStartparameterReader(this.paProject);
105 if (!this.paProject.isAvailable()) {
106 MessageDialog.openError(getShell(),
"Connect to version control failed",
107 "The version control is not available.");
108 throw new IllegalStateException(
"Version control is not available");
111 wizardSettings =
new HashMap<>();
128 new ContentGenerator(
"", dataContainer, wizardSettings.get(
"TemplateName").toString()).schedule();
129 }
catch (Exception e) {
137 protected void throwCoreException(String message)
throws CoreException {
138 IStatus status =
new Status(IStatus.ERROR,
"com.proalpha.java.plugins.templates", IStatus.OK, message,
null);
139 throw new CoreException(status);
148 public void init(IWorkbench wb, IStructuredSelection selection) {
149 this.selection = selection;
156 @SuppressWarnings(
"unchecked")
159 IWizardPage[] wizardPages = getPages();
161 for (IWizardPage page : wizardPages) {
162 Class<?>[] interfaces = page.getClass().getInterfaces();
163 for (Class<?> c : interfaces) {
164 if (c.getName().contains(
"IpaWizardPage")) {
166 Method method = page.getClass().getMethod(
"getSettings");
167 wizardSettings.putAll((HashMap<String, Object>) method.invoke(page));
168 }
catch (Exception e) {
185 wizardMainPage =
WizardpageFactory.createWizardMainPage(this.paProject, this.configList, this.repositoryDelegate,
186 this.repositoryInformations, this.startparameterReader);
188 addPage(wizardMainPage);
195 public RepositoryDelegate getRepositoryDelegate() {
196 return repositoryDelegate;
199 public RepositoryInformations getRepositoryInformations() {
200 return repositoryInformations;
203 public StartparameterReader getStartparameterReader() {
204 return startparameterReader;
207 public LinkedHashMap<String, WizardMainPageConfiguration> getConfigList() {
211 public void setConfigList(LinkedHashMap<String, WizardMainPageConfiguration> configList) {
212 this.configList = configList;
static Activator getDefault()
static void showAndLogErrorMessage(AbstractUIPlugin plugin, Throwable exception)
void init(IWorkbench wb, IStructuredSelection selection)