Project

General

Profile

Download (5.64 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.model.MessagingUtils;
27
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
28
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
29
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
30

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

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

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

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

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

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

    
108

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

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

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

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

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

    
170
    public static boolean confirmDelete(){
171
        return MessagingUtils.confirmDialog("Confirm deletion", "Do you really want to delete the selected element(s)?");
172
    }
173
}
(10-10/14)