3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.editor
;
13 import java
.util
.UUID
;
15 import org
.eclipse
.core
.runtime
.IAdaptable
;
16 import org
.eclipse
.ui
.IElementFactory
;
17 import org
.eclipse
.ui
.IMemento
;
19 import eu
.etaxonomy
.cdm
.api
.service
.IClassificationService
;
20 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
24 * <p>TaxonEditorInputFactory class.</p>
30 public class TaxonEditorInputFactory
implements IElementFactory
{
33 * Factory id. The workbench plug-in registers a factory by this name
34 * with the "org.eclipse.ui.elementFactories" extension point.
36 private static final String ID_FACTORY
= "eu.etaxonomy.taxeditor.editor.name.taxonEditorInputFactory"; //$NON-NLS-1$
39 * Tag for the IFile.fullPath of the file resource.
41 private static final String TAXON_NODE_UUID
= "uuid"; //$NON-NLS-1$
44 * @see org.eclipse.ui.IElementFactory#createElement(org.eclipse.ui.IMemento)
47 public IAdaptable
createElement(IMemento memento
) {
49 String taxonNodeUuid
= memento
.getString(TAXON_NODE_UUID
);
50 if(! CdmStore
.isActive()){
53 if (taxonNodeUuid
== null || CdmStore
.getService(IClassificationService
.class).getTaxonNodeByUuid(UUID
.fromString(taxonNodeUuid
)) == null) {
54 EditorUtil
.warn(this.getClass(), "Couldn't find taxon node with UUID " + taxonNodeUuid
);
58 return TaxonEditorInput
.NewInstance(UUID
.fromString(taxonNodeUuid
));
59 } catch (Exception e
) {
60 EditorUtil
.warningDialog("Could not create element", TaxonEditorInputFactory
.class, e
.getMessage());
66 * Returns the element factory id for this class.
68 * @return the element factory id
70 public static String
getFactoryId() {
75 * Saves the state of the given file editor input into the given memento.
77 * @param memento the storage area for element state
78 * @param input the file editor input
80 public static void saveState(IMemento memento
, TaxonEditorInput input
) {
81 String uuid
= input
.getTaxonNode().getUuid().toString();
82 memento
.putString(TAXON_NODE_UUID
, uuid
);