]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.views.swt/src/org/simantics/views/swt/WizardFactory.java
Added utility for truncating collected history data
[simantics/platform.git] / bundles / org.simantics.views.swt / src / org / simantics / views / swt / WizardFactory.java
1 package org.simantics.views.swt;
2
3 import org.eclipse.core.runtime.CoreException;
4 import org.eclipse.core.runtime.IConfigurationElement;
5 import org.eclipse.core.runtime.IExecutableExtension;
6 import org.eclipse.core.runtime.IExecutableExtensionFactory;
7 import org.eclipse.core.runtime.IStatus;
8 import org.eclipse.core.runtime.Status;
9
10 /**
11  * 
12  * @author Antti Villberg
13  */
14 public class WizardFactory implements IExecutableExtensionFactory, IExecutableExtension {
15     
16     private IConfigurationElement config;
17
18     private String id;
19
20     private String propertyName;
21
22     public WizardFactory() {
23         // do nothing
24     }
25
26     private Object configure(Object obj) throws CoreException {
27         if (obj instanceof IExecutableExtension) {
28             ((IExecutableExtension) obj).setInitializationData(config, propertyName, null);
29         }
30         return obj;
31     }
32
33     @Override
34     public Object create() throws CoreException {
35         
36         return configure(new ModelledWizard(id));
37         
38     }
39
40     @Override
41     public void setInitializationData(IConfigurationElement config, String propertyName, Object data)
42     throws CoreException {
43         //System.out.println("setInitializationData: " + config + ", " + propertyName + ", " + data);
44
45         if (data instanceof String) {
46             id = (String) data;
47         } else {
48             throw new CoreException(new Status(IStatus.ERROR,
49                     Activator.PLUGIN_ID, 0,
50                     "Data argument must be a String for " + getClass(), null)); //$NON-NLS-1$
51         }
52         this.config = config;
53         this.propertyName = propertyName;
54     }
55
56 }