Project

General

Profile

Download (2.48 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
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.
9
*/
10

    
11
package eu.etaxonomy.taxeditor.editor;
12

    
13
import java.util.UUID;
14

    
15
import org.eclipse.core.runtime.IAdaptable;
16
import org.eclipse.ui.IElementFactory;
17
import org.eclipse.ui.IMemento;
18

    
19
import eu.etaxonomy.taxeditor.store.CdmStore;
20

    
21

    
22
/**
23
 * <p>TaxonEditorInputFactory class.</p>
24
 *
25
 * @author p.ciardelli
26
 * @created 23.04.2009
27
 * @version 1.0
28
 */
29
public class TaxonEditorInputFactory implements IElementFactory {
30

    
31
    /**
32
     * Factory id. The workbench plug-in registers a factory by this name
33
     * with the "org.eclipse.ui.elementFactories" extension point.
34
     */
35
    private static final String ID_FACTORY = "eu.etaxonomy.taxeditor.editor.TaxonEditorInputFactory"; //$NON-NLS-1$
36
	
37
    /**
38
     * Tag for the IFile.fullPath of the file resource.
39
     */
40
    private static final String TAXON_NODE_UUID = "uuid"; //$NON-NLS-1$
41
    
42
	/* (non-Javadoc)
43
	 * @see org.eclipse.ui.IElementFactory#createElement(org.eclipse.ui.IMemento)
44
	 */
45
	/** {@inheritDoc} */
46
	public IAdaptable createElement(IMemento memento) {
47
        // Get the uuid
48
        String taxonNodeUuid = memento.getString(TAXON_NODE_UUID);
49
        if(! CdmStore.isActive()){
50
        	return null;
51
        }
52
        if (taxonNodeUuid == null || CdmStore.getClassificationService().getTaxonNodeByUuid(UUID.fromString(taxonNodeUuid)) == null) {
53
        	EditorUtil.warn(this.getClass(), "Couldn't find taxon node with UUID " + taxonNodeUuid);
54
        	return null;
55
        }
56
        try {
57
			return TaxonEditorInput.NewInstance(UUID.fromString(taxonNodeUuid));
58
		} catch (Exception e) {
59
			EditorUtil.warningDialog("Could not create element", TaxonEditorInputFactory.class, e.getMessage());
60
		}
61
		return null;
62
	}	
63
	
64
    /**
65
     * Returns the element factory id for this class.
66
     *
67
     * @return the element factory id
68
     */
69
    public static String getFactoryId() {
70
        return ID_FACTORY;
71
    }
72
    
73
    /**
74
     * Saves the state of the given file editor input into the given memento.
75
     *
76
     * @param memento the storage area for element state
77
     * @param input the file editor input
78
     */
79
    public static void saveState(IMemento memento, TaxonEditorInput input) {
80
    	String uuid = input.getTaxonNode().getUuid().toString();
81
        memento.putString(TAXON_NODE_UUID, uuid);
82
    }
83
}
(14-14/15)