X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2Fsharedontology%2Fwizard%2FWizardExtensionFactory.java;fp=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2Fsharedontology%2Fwizard%2FWizardExtensionFactory.java;h=7d3b9fa6478b1b0fb066dc5c276ecbcf2a5a1d6a;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/WizardExtensionFactory.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/WizardExtensionFactory.java new file mode 100644 index 000000000..7d3b9fa64 --- /dev/null +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/WizardExtensionFactory.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2012 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.modeling.ui.sharedontology.wizard; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExecutableExtension; +import org.eclipse.core.runtime.IExecutableExtensionFactory; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.simantics.modeling.ui.Activator; + +/** + * A factory for diagram template related wizard extensions. + * + * @author Tuukka Lehtonen + */ +public class WizardExtensionFactory implements IExecutableExtensionFactory, IExecutableExtension { + + /** + * Factory ID for the shared library export wizard. + */ + public static final String ANNOTATION_TYPE_EXPORT_WIZARD = "sharedOntologyExportWizard"; // $//$NON-NLS-1$ + public static final String MODEL_TYPE_EXPORT_WIZARD = "modelExportWizard"; // $//$NON-NLS-1$ + + /** + * Factory ID for the shared library import wizard. + */ + public static final String ANNOTATION_TYPE_IMPORT_WIZARD = "sharedOntologyImportWizard"; // $//$NON-NLS-1$ + + private IConfigurationElement config; + + private String id; + + private String propertyName; + + public WizardExtensionFactory() { + // do nothing + } + + private Object configure(Object obj) throws CoreException { + if (obj instanceof IExecutableExtension) { + ((IExecutableExtension) obj).setInitializationData(config, propertyName, null); + } + return obj; + } + + @Override + public Object create() throws CoreException { + if (ANNOTATION_TYPE_EXPORT_WIZARD.equals(id)) { + return configure(new SharedOntologyExportWizard()); + } + if (MODEL_TYPE_EXPORT_WIZARD.equals(id)) { + return configure(new ModelExportWizard()); + } + if (ANNOTATION_TYPE_IMPORT_WIZARD.equals(id)) { + return configure(new SharedOntologyImportWizard()); + } + + throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, + 0, "Unknown id in data argument for " + getClass(), null)); //$NON-NLS-1$ + } + + @Override + public void setInitializationData(IConfigurationElement config, String propertyName, Object data) + throws CoreException { + + if (data instanceof String) { + id = (String) data; + } else { + throw new CoreException(new Status(IStatus.ERROR, + Activator.PLUGIN_ID, 0, + "Data argument must be a String for " + getClass(), null)); //$NON-NLS-1$ + } + this.config = config; + this.propertyName = propertyName; + } + +}