2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.editor
;
12 import java
.util
.UUID
;
14 import org
.eclipse
.core
.runtime
.IAdaptable
;
15 import org
.eclipse
.ui
.IElementFactory
;
16 import org
.eclipse
.ui
.IMemento
;
18 import eu
.etaxonomy
.cdm
.api
.service
.IClassificationService
;
19 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
20 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
21 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
25 * <p>TaxonEditorInputFactory class.</p>
31 public class TaxonEditorInputFactory
implements IElementFactory
{
34 * Factory id. The workbench plug-in registers a factory by this name
35 * with the "org.eclipse.ui.elementFactories" extension point.
37 private static final String ID_FACTORY
= "eu.etaxonomy.taxeditor.editor.name.taxonEditorInputFactory"; //$NON-NLS-1$
40 * Tag for the IFile.fullPath of the file resource.
42 private static final String TAXON_NODE_UUID
= "uuid"; //$NON-NLS-1$
45 * @see org.eclipse.ui.IElementFactory#createElement(org.eclipse.ui.IMemento)
48 public IAdaptable
createElement(IMemento memento
) {
50 String taxonNodeUuid
= memento
.getString(TAXON_NODE_UUID
);
51 if(! CdmStore
.isActive()){
54 if (taxonNodeUuid
== null || CdmStore
.getService(IClassificationService
.class).getTaxonNodeByUuid(UUID
.fromString(taxonNodeUuid
)) == null) {
55 MessagingUtils
.warn(this.getClass(), Messages
.TaxonEditorInputFactory_NOT_FOUND_TAXON
+ taxonNodeUuid
);
59 return TaxonEditorInput
.NewInstance(UUID
.fromString(taxonNodeUuid
));
60 } catch (Exception e
) {
61 MessagingUtils
.warningDialog(Messages
.TaxonEditorInputFactory_COULD_NOT_CREATE
, TaxonEditorInputFactory
.class, e
.getMessage());
67 * Returns the element factory id for this class.
69 * @return the element factory id
71 public static String
getFactoryId() {
76 * Saves the state of the given file editor input into the given memento.
78 * @param memento the storage area for element state
79 * @param input the file editor input
81 public static void saveState(IMemento memento
, TaxonEditorInput input
) {
82 String uuid
= input
.getTaxonNode().getUuid().toString();
83 memento
.putString(TAXON_NODE_UUID
, uuid
);