Revision 3be6ef3e
Added by Niels Hoffmann over 13 years ago
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/TaxonEditorInputFactory.java | ||
---|---|---|
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 |
* @author p.ciardelli |
|
24 |
* @created 23.04.2009 |
|
25 |
* @version 1.0 |
|
26 |
*/ |
|
27 |
public class TaxonEditorInputFactory implements IElementFactory { |
|
28 |
|
|
29 |
/** |
|
30 |
* Factory id. The workbench plug-in registers a factory by this name |
|
31 |
* with the "org.eclipse.ui.elementFactories" extension point. |
|
32 |
*/ |
|
33 |
private static final String ID_FACTORY = "eu.etaxonomy.taxeditor.editor.TaxonEditorInputFactory"; //$NON-NLS-1$ |
|
34 |
|
|
35 |
/** |
|
36 |
* Tag for the IFile.fullPath of the file resource. |
|
37 |
*/ |
|
38 |
private static final String TAXON_NODE_UUID = "uuid"; //$NON-NLS-1$ |
|
39 |
|
|
40 |
/* (non-Javadoc) |
|
41 |
* @see org.eclipse.ui.IElementFactory#createElement(org.eclipse.ui.IMemento) |
|
42 |
*/ |
|
43 |
public IAdaptable createElement(IMemento memento) { |
|
44 |
// Get the uuid |
|
45 |
String taxonNodeUuid = memento.getString(TAXON_NODE_UUID); |
|
46 |
if(! CdmStore.isActive()){ |
|
47 |
return null; |
|
48 |
} |
|
49 |
if (taxonNodeUuid == null || CdmStore.getTaxonTreeService().getTaxonNodeByUuid(UUID.fromString(taxonNodeUuid)) == null) { |
|
50 |
EditorUtil.warn(this.getClass(), "Couldn't find taxon node with UUID " + taxonNodeUuid); |
|
51 |
return null; |
|
52 |
} |
|
53 |
try { |
|
54 |
return TaxonEditorInput.NewInstance(UUID.fromString(taxonNodeUuid)); |
|
55 |
} catch (Exception e) { |
|
56 |
EditorUtil.warningDialog("Could not create element", TaxonEditorInputFactory.class, e.getMessage()); |
|
57 |
} |
|
58 |
return null; |
|
59 |
} |
|
60 |
|
|
61 |
/** |
|
62 |
* Returns the element factory id for this class. |
|
63 |
* |
|
64 |
* @return the element factory id |
|
65 |
*/ |
|
66 |
public static String getFactoryId() { |
|
67 |
return ID_FACTORY; |
|
68 |
} |
|
69 |
|
|
70 |
/** |
|
71 |
* Saves the state of the given file editor input into the given memento. |
|
72 |
* |
|
73 |
* @param memento the storage area for element state |
|
74 |
* @param input the file editor input |
|
75 |
*/ |
|
76 |
public static void saveState(IMemento memento, TaxonEditorInput input) { |
|
77 |
String uuid = input.getTaxonNode().getUuid().toString(); |
|
78 |
memento.putString(TAXON_NODE_UUID, uuid); |
|
79 |
} |
|
80 |
} |
|
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.getTaxonTreeService().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 |
} |
Also available in: Unified diff
performed javacscript:fix and worked on documentation