Project

General

Profile

Download (4.22 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.forms.widgets.ScrolledForm;
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
	public static void reflowParentScrolledForm(Composite composite, boolean flushCashes){
91
        ScrolledForm scrolledForm = null;
92
        Composite parent = composite;
93
        while(parent!=null && !(parent instanceof ScrolledForm)){
94
            parent = parent.getParent();
95
        }
96
        scrolledForm = (ScrolledForm)parent;
97
        if(scrolledForm!=null){
98
            scrolledForm.reflow(flushCashes);
99
            scrolledForm.redraw();
100
        }
101
    }
102

    
103

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

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

    
122
    /**
123
     * Cleans title string for output in section titles<br>
124
     * E.g. escapes '&' with "&&" to avoid mnemonic handling (see
125
     * Label.setText() documentation)<br>
126
     * see also #4302
127
     *
128
     * @param title
129
     *            the title string to clean
130
     * @return the cleaned title string
131
     */
132
	public static String cleanTitleString(String title){
133
	    return title.replace("&", "&&");
134
	}
135

    
136
}
(10-10/14)