]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.annotation.ui/src/org/simantics/annotation/ui/wizard/WizardExtensionFactory.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.annotation.ui / src / org / simantics / annotation / ui / 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.annotation.ui.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.annotation.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 annotation type export wizard.
31      */
32     public static final String ANNOTATION_TYPE_EXPORT_WIZARD = "annotationTypeExportWizard"; // $//$NON-NLS-1$
33
34     /**
35      * Factory ID for the annotation type import wizard.
36      */
37     public static final String ANNOTATION_TYPE_IMPORT_WIZARD = "annotationTypeImportWizard"; // $//$NON-NLS-1$
38  
39     private IConfigurationElement config;
40
41     private String id;
42
43     private String propertyName;
44
45     public WizardExtensionFactory() {
46         // do nothing
47     }
48
49     private Object configure(Object obj) throws CoreException {
50         if (obj instanceof IExecutableExtension) {
51             ((IExecutableExtension) obj).setInitializationData(config, propertyName, null);
52         }
53         return obj;
54     }
55
56     @Override
57     public Object create() throws CoreException {
58         if (ANNOTATION_TYPE_EXPORT_WIZARD.equals(id)) {
59             return configure(new AnnotationTypeExportWizard());
60         }
61         if (ANNOTATION_TYPE_IMPORT_WIZARD.equals(id)) {
62             return configure(new AnnotationTypeImportWizard());
63         }
64
65         throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
66                 0, "Unknown id in data argument for " + getClass(), null)); //$NON-NLS-1$
67     }
68
69     @Override
70     public void setInitializationData(IConfigurationElement config, String propertyName, Object data)
71     throws CoreException {
72
73         if (data instanceof String) {
74             id = (String) data;
75         } else {
76             throw new CoreException(new Status(IStatus.ERROR,
77                     Activator.PLUGIN_ID, 0,
78                     "Data argument must be a String for " + getClass(), null)); //$NON-NLS-1$
79         }
80         this.config = config;
81         this.propertyName = propertyName;
82     }
83
84 }