]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.annotation.ui/src/org/simantics/annotation/ui/wizard/WizardExtensionFactory.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.annotation.ui / src / org / simantics / annotation / ui / wizard / WizardExtensionFactory.java
1 /*******************************************************************************\r
2  * Copyright (c) 2012 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.annotation.ui.wizard;\r
13 \r
14 import org.eclipse.core.runtime.CoreException;\r
15 import org.eclipse.core.runtime.IConfigurationElement;\r
16 import org.eclipse.core.runtime.IExecutableExtension;\r
17 import org.eclipse.core.runtime.IExecutableExtensionFactory;\r
18 import org.eclipse.core.runtime.IStatus;\r
19 import org.eclipse.core.runtime.Status;\r
20 import org.simantics.annotation.ui.Activator;\r
21 \r
22 /**\r
23  * A factory for diagram template related wizard extensions.\r
24  * \r
25  * @author Tuukka Lehtonen\r
26  */\r
27 public class WizardExtensionFactory implements IExecutableExtensionFactory, IExecutableExtension {\r
28 \r
29     /**\r
30      * Factory ID for the annotation type export wizard.\r
31      */\r
32     public static final String ANNOTATION_TYPE_EXPORT_WIZARD = "annotationTypeExportWizard"; // $//$NON-NLS-1$\r
33 \r
34     /**\r
35      * Factory ID for the annotation type import wizard.\r
36      */\r
37     public static final String ANNOTATION_TYPE_IMPORT_WIZARD = "annotationTypeImportWizard"; // $//$NON-NLS-1$\r
38  \r
39     private IConfigurationElement config;\r
40 \r
41     private String id;\r
42 \r
43     private String propertyName;\r
44 \r
45     public WizardExtensionFactory() {\r
46         // do nothing\r
47     }\r
48 \r
49     private Object configure(Object obj) throws CoreException {\r
50         if (obj instanceof IExecutableExtension) {\r
51             ((IExecutableExtension) obj).setInitializationData(config, propertyName, null);\r
52         }\r
53         return obj;\r
54     }\r
55 \r
56     @Override\r
57     public Object create() throws CoreException {\r
58         if (ANNOTATION_TYPE_EXPORT_WIZARD.equals(id)) {\r
59             return configure(new AnnotationTypeExportWizard());\r
60         }\r
61         if (ANNOTATION_TYPE_IMPORT_WIZARD.equals(id)) {\r
62             return configure(new AnnotationTypeImportWizard());\r
63         }\r
64 \r
65         throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID,\r
66                 0, "Unknown id in data argument for " + getClass(), null)); //$NON-NLS-1$\r
67     }\r
68 \r
69     @Override\r
70     public void setInitializationData(IConfigurationElement config, String propertyName, Object data)\r
71     throws CoreException {\r
72 \r
73         if (data instanceof String) {\r
74             id = (String) data;\r
75         } else {\r
76             throw new CoreException(new Status(IStatus.ERROR,\r
77                     Activator.PLUGIN_ID, 0,\r
78                     "Data argument must be a String for " + getClass(), null)); //$NON-NLS-1$\r
79         }\r
80         this.config = config;\r
81         this.propertyName = propertyName;\r
82     }\r
83 \r
84 }\r