Project

General

Profile

Download (4.08 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.swt.widgets.Composite;
18
import org.eclipse.ui.IEditorInput;
19
import org.eclipse.ui.forms.widgets.ScrolledForm;
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.model.FeatureNodeContainer;
25
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
26

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

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

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

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

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

    
91
	public static void reflowParentScrolledForm(Composite composite, boolean flushCashes){
92
        ScrolledForm scrolledForm = null;
93
        Composite parent = composite;
94
        while(parent!=null && !(parent instanceof ScrolledForm)){
95
            parent = parent.getParent();
96
        }
97
        scrolledForm = (ScrolledForm)parent;
98
        if(scrolledForm!=null){
99
            scrolledForm.reflow(flushCashes);
100
            scrolledForm.redraw();
101
        }
102
    }
103

    
104

    
105
	/**
106
	 * <p>getUndoContext</p>
107
	 *
108
	 * @return a {@link org.eclipse.core.commands.operations.IUndoContext} object.
109
	 */
110
	public static IUndoContext getUndoContext(){
111
		return IOperationHistory.GLOBAL_UNDO_CONTEXT;
112
	}
113

    
114
	/**
115
	 * <p>getPluginId</p>
116
	 *
117
	 * @return a {@link java.lang.String} object.
118
	 */
119
	public static String getPluginId(){
120
		return TaxeditorStorePlugin.PLUGIN_ID;
121
	}
122

    
123
	/**
124
	 *
125
	 * @return
126
	 */
127
	public static IEditorInput getActiveEditorInput() {
128
//		IEditorPart activeEditor = getActiveEditor();
129
//		if (activeEditor != null){
130
//			return activeEditor.getEditorInput();
131
//		}
132
		return null;
133
	}
134
}
(10-10/14)