Project

General

Profile

Download (2.62 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.model.MessagingUtils;
21
import eu.etaxonomy.taxeditor.store.CdmStore;
22

    
23

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

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