Project

General

Profile

Download (4.22 KB) Statistics
| Branch: | Tag: | Revision:
1 e8409423 n.hoffmann
/**
2
* Copyright (C) 2007 EDIT
3 09a1be0a Patric Plitzner
* European Distributed Institute of Taxonomy
4 e8409423 n.hoffmann
* http://www.e-taxonomy.eu
5 09a1be0a Patric Plitzner
*
6 e8409423 n.hoffmann
* 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 2602a12b p.ciardelli
import java.util.UUID;
13
14 df60b579 n.hoffmann
import org.eclipse.core.commands.operations.IOperationHistory;
15
import org.eclipse.core.commands.operations.IUndoContext;
16
import org.eclipse.jface.action.IStatusLineManager;
17 0fa0610e Patrick Plitzner
import org.eclipse.swt.widgets.Composite;
18
import org.eclipse.ui.forms.widgets.ScrolledForm;
19 df60b579 n.hoffmann
20 09a1be0a Patric Plitzner
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
21
import eu.etaxonomy.cdm.model.common.CdmBase;
22 9766a939 n.hoffmann
import eu.etaxonomy.taxeditor.model.AbstractUtility;
23 6d417ae0 Patric Plitzner
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
24 df60b579 n.hoffmann
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
25 e8409423 n.hoffmann
26
/**
27 3be6ef3e n.hoffmann
 * <p>StoreUtil class.</p>
28
 *
29 e8409423 n.hoffmann
 * @author n.hoffmann
30
 * @created 11.05.2009
31
 * @version 1.0
32
 */
33 2602a12b p.ciardelli
public class StoreUtil extends AbstractUtility {
34
35 3be6ef3e n.hoffmann
	/**
36
	 * <p>checktaxonExists</p>
37
	 *
38
	 * @param fromString a {@link java.util.UUID} object.
39
	 */
40 2602a12b p.ciardelli
	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 df60b579 n.hoffmann
	}
46 09a1be0a Patric Plitzner
47
	/**
48
	 * If the object given is already a {@link CdmBase} then it is returned.<br>
49 a9d0fdf8 Patric Plitzner
	 * If it is a kind of "container" for CDM objects then it is asked for its "responsible" CdmBase entity.<br>
50 09a1be0a Patric Plitzner
	 * Otherwise an exception is thrown.
51
	 * @param object the object to test for CdmBase
52
	 * @return a CdmBase object
53 a9d0fdf8 Patric Plitzner
	 * @throws IllegalArgumentException if the tested object is neither a CdmBase nor a CDM "container"
54 09a1be0a Patric Plitzner
	 */
55
	public static CdmBase getCdmEntity(Object object){
56 1cf32439 Patric Plitzner
        // TODO temporary solution for ticket #4091????
57 dfcde26e Andreas Müller
        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 1cf32439 Patric Plitzner
            return ((DerivedUnitFacade)object).baseUnit();
61 09a1be0a Patric Plitzner
        }
62 6d417ae0 Patric Plitzner
        else if(object instanceof FeatureNodeContainer){
63
            return ((FeatureNodeContainer) object).getFeatureNode();
64
        }
65 09a1be0a Patric Plitzner
        else if(object instanceof CdmBase){
66
            return (CdmBase) object;
67
        }
68 a9d0fdf8 Patric Plitzner
        throw new IllegalArgumentException("Object " + object.toString() + " is neither a CdmBase nor a CDM \"container\"");
69 09a1be0a Patric Plitzner
	}
70
71 3be6ef3e n.hoffmann
	/**
72
	 * <p>getOperationHistory</p>
73
	 *
74
	 * @return a {@link org.eclipse.core.commands.operations.IOperationHistory} object.
75
	 */
76 df60b579 n.hoffmann
	public static IOperationHistory getOperationHistory() {
77
		return TaxeditorStorePlugin.getDefault().getWorkbench().
78
					getOperationSupport().getOperationHistory();
79
	}
80 09a1be0a Patric Plitzner
81 3be6ef3e n.hoffmann
	/**
82
	 * <p>setStatusLineManager</p>
83
	 *
84
	 * @param manager a {@link org.eclipse.jface.action.IStatusLineManager} object.
85
	 */
86 df60b579 n.hoffmann
	public static void setStatusLineManager(IStatusLineManager manager) {
87
		statusLineManager = manager;
88
	}
89 09a1be0a Patric Plitzner
90 0fa0610e Patrick Plitzner
	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 6fd5b6eb Patrick Plitzner
            scrolledForm.redraw();
100 0fa0610e Patrick Plitzner
        }
101
    }
102
103 df60b579 n.hoffmann
104 3be6ef3e n.hoffmann
	/**
105
	 * <p>getUndoContext</p>
106
	 *
107
	 * @return a {@link org.eclipse.core.commands.operations.IUndoContext} object.
108
	 */
109 df60b579 n.hoffmann
	public static IUndoContext getUndoContext(){
110
		return IOperationHistory.GLOBAL_UNDO_CONTEXT;
111
	}
112 09a1be0a Patric Plitzner
113 3be6ef3e n.hoffmann
	/**
114
	 * <p>getPluginId</p>
115
	 *
116
	 * @return a {@link java.lang.String} object.
117
	 */
118 b9a0d300 l.morris
	public static String getPluginId(){
119 915cda99 n.hoffmann
		return TaxeditorStorePlugin.PLUGIN_ID;
120
	}
121 f18e39bb n.hoffmann
122 d98abaef Patrick Plitzner
    /**
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 df60b579 n.hoffmann
}