- added util method to get for getting a CDM entity (used in authenication/permissio...
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / store / StoreUtil.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.store;
12
13 import java.util.UUID;
14
15 import org.eclipse.core.commands.operations.IOperationHistory;
16 import org.eclipse.core.commands.operations.IUndoContext;
17 import org.eclipse.jface.action.IStatusLineManager;
18 import org.eclipse.ui.IEditorInput;
19 import org.eclipse.ui.IEditorPart;
20
21 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
22 import eu.etaxonomy.cdm.model.common.CdmBase;
23 import eu.etaxonomy.taxeditor.model.AbstractUtility;
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 facade 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 facade
54 */
55 public static CdmBase getCdmEntity(Object object){
56 // TODO temporary solution for ticket #????
57 if(object instanceof DerivedUnitFacade){
58 return ((DerivedUnitFacade)object).getBaseUnit();
59 }
60 else if(object instanceof CdmBase){
61 return (CdmBase) object;
62 }
63 throw new IllegalArgumentException("Object is neither a CdmBase nor an EntityFacade");
64 }
65
66 /**
67 * <p>getOperationHistory</p>
68 *
69 * @return a {@link org.eclipse.core.commands.operations.IOperationHistory} object.
70 */
71 public static IOperationHistory getOperationHistory() {
72 return TaxeditorStorePlugin.getDefault().getWorkbench().
73 getOperationSupport().getOperationHistory();
74 }
75
76 /**
77 * <p>setStatusLineManager</p>
78 *
79 * @param manager a {@link org.eclipse.jface.action.IStatusLineManager} object.
80 */
81 public static void setStatusLineManager(IStatusLineManager manager) {
82 statusLineManager = manager;
83 }
84
85
86 /**
87 * <p>getUndoContext</p>
88 *
89 * @return a {@link org.eclipse.core.commands.operations.IUndoContext} object.
90 */
91 public static IUndoContext getUndoContext(){
92 return IOperationHistory.GLOBAL_UNDO_CONTEXT;
93 }
94
95 /**
96 * <p>getPluginId</p>
97 *
98 * @return a {@link java.lang.String} object.
99 */
100 public static String getPluginId(){
101 return TaxeditorStorePlugin.PLUGIN_ID;
102 }
103
104 /**
105 *
106 * @return
107 */
108 public static IEditorInput getActiveEditorInput() {
109 IEditorPart activeEditor = getActiveEditor();
110 if (activeEditor != null){
111 return activeEditor.getEditorInput();
112 }
113 return null;
114 }
115 }