Project

General

Profile

Download (2.56 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.cdm.api.service.IClassificationService;
20
import eu.etaxonomy.taxeditor.store.CdmStore;
21

    
22

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

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