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