Project

General

Profile

Download (5.42 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.jface.dialogs.MessageDialog;
18
import org.eclipse.swt.widgets.Composite;
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.l10n.Messages;
24
import eu.etaxonomy.taxeditor.model.AbstractUtility;
25
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
26
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
27
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
28
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
29

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

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

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

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

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

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

    
107

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

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

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

    
140
    public static String getPrefKey(Class<? extends AbstractFormSection> sectionClass, Object entity) {
141
        return sectionClass.getCanonicalName()+";"+entity.getClass().getCanonicalName();
142
    }
143

    
144
    /**
145
     * Checks the dirty flag and, if set, prompts the user to optionally save
146
     * the editor
147
     *
148
     * @return <code>false</code> if the editor is not dirty anymore, either
149
     *         because it wasn't beforehand or because it has been saved.
150
     *         <code>true</code> otherwise
151
     */
152
    public static boolean checkDirty(IE4SavablePart editor){
153
        if (editor.isDirty()){
154
            boolean proceed = MessageDialog.openQuestion(null,
155
                    Messages.DefinedTermEditorE4_SAVE_TITLE, Messages.DefinedTermEditorE4_SAVE_MESSAGE);
156
            if (proceed) {
157
                editor.save(null);
158
                return false;
159
            }
160
            else{
161
                return true;
162
            }
163
        }
164
        else{
165
            return false;
166
        }
167
    }
168
}
(10-10/14)