Project

General

Profile

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

    
10
package eu.etaxonomy.taxeditor.store;
11

    
12
import java.util.UUID;
13

    
14
import org.eclipse.core.commands.operations.IOperationHistory;
15
import org.eclipse.core.commands.operations.IUndoContext;
16
import org.eclipse.jface.action.IStatusLineManager;
17
import org.eclipse.ui.IEditorInput;
18
import org.eclipse.ui.IEditorPart;
19

    
20
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
21
import eu.etaxonomy.cdm.model.common.CdmBase;
22
import eu.etaxonomy.taxeditor.model.AbstractUtility;
23
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
24
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
25

    
26
/**
27
 * <p>StoreUtil class.</p>
28
 *
29
 * @author n.hoffmann
30
 * @created 11.05.2009
31
 * @version 1.0
32
 */
33
public class StoreUtil extends AbstractUtility {
34

    
35
	/**
36
	 * <p>checktaxonExists</p>
37
	 *
38
	 * @param fromString a {@link java.util.UUID} object.
39
	 */
40
	public static void checktaxonExists(UUID fromString) {
41
//        if (CdmStore.getTaxonService().getTaxonByUuid(UUID.fromString(uuid)) == null) {
42
//        	logger.warn("Couldn't find taxon with UUID " + uuid);
43
//        	return null;
44
//        }
45
	}
46

    
47
	/**
48
	 * If the object given is already a {@link CdmBase} then it is returned.<br>
49
	 * If it is a kind of "container" for CDM objects then it is asked for its "responsible" CdmBase entity.<br>
50
	 * Otherwise an exception is thrown.
51
	 * @param object the object to test for CdmBase
52
	 * @return a CdmBase object
53
	 * @throws IllegalArgumentException if the tested object is neither a CdmBase nor a CDM "container"
54
	 */
55
	public static CdmBase getCdmEntity(Object object){
56
        // TODO temporary solution for ticket #4091????
57
        if (object == null){
58
        	return null;   //not sure if an object should ever be null at this point, but this needs to be handled in calling methods
59
        }else if(object instanceof DerivedUnitFacade){
60
            return ((DerivedUnitFacade)object).baseUnit();
61
        }
62
        else if(object instanceof FeatureNodeContainer){
63
            return ((FeatureNodeContainer) object).getFeatureNode();
64
        }
65
        else if(object instanceof CdmBase){
66
            return (CdmBase) object;
67
        }
68
        throw new IllegalArgumentException("Object " + object.toString() + " is neither a CdmBase nor a CDM \"container\"");
69
	}
70

    
71
	/**
72
	 * <p>getOperationHistory</p>
73
	 *
74
	 * @return a {@link org.eclipse.core.commands.operations.IOperationHistory} object.
75
	 */
76
	public static IOperationHistory getOperationHistory() {
77
		return TaxeditorStorePlugin.getDefault().getWorkbench().
78
					getOperationSupport().getOperationHistory();
79
	}
80

    
81
	/**
82
	 * <p>setStatusLineManager</p>
83
	 *
84
	 * @param manager a {@link org.eclipse.jface.action.IStatusLineManager} object.
85
	 */
86
	public static void setStatusLineManager(IStatusLineManager manager) {
87
		statusLineManager = manager;
88
	}
89

    
90

    
91
	/**
92
	 * <p>getUndoContext</p>
93
	 *
94
	 * @return a {@link org.eclipse.core.commands.operations.IUndoContext} object.
95
	 */
96
	public static IUndoContext getUndoContext(){
97
		return IOperationHistory.GLOBAL_UNDO_CONTEXT;
98
	}
99

    
100
	/**
101
	 * <p>getPluginId</p>
102
	 *
103
	 * @return a {@link java.lang.String} object.
104
	 */
105
	public static String getPluginId(){
106
		return TaxeditorStorePlugin.PLUGIN_ID;
107
	}
108

    
109
	/**
110
	 *
111
	 * @return
112
	 */
113
	public static IEditorInput getActiveEditorInput() {
114
		IEditorPart activeEditor = getActiveEditor();
115
		if (activeEditor != null){
116
			return activeEditor.getEditorInput();
117
		}
118
		return null;
119
	}
120
}
(9-9/13)