Project

General

Profile

« Previous | Next » 

Revision cdf77847

Added by Patrick Plitzner almost 11 years ago

  • simplified code for opening editor in TaxonNavigator

    • used IPartContentHasXYZ interfaces for selectionChanged() in Supplemental- and DetailsViewPart
    • formatted code
    • fixed warnings

View differences:

eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationUtil.java
1 1
/**
2 2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
......
37 37
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
38 38
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
39 39
import eu.etaxonomy.taxeditor.editor.EditorUtil;
40
import eu.etaxonomy.taxeditor.editor.OpenEditorConfiguration;
41 40
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
42 41
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
43 42
import eu.etaxonomy.taxeditor.model.AbstractUtility;
......
53 52
 */
54 53
public class NavigationUtil extends AbstractUtility{
55 54
	private static IUndoContext defaultUndoContext;
56
		
55

  
57 56
	/**
58 57
	 * <p>executeEditHandler</p>
59 58
	 */
60 59
	public static void executeEditHandler(){
61 60

  
62 61
		String commandId = "eu.etaxonomy.taxeditor.navigation.command.editSelection";
63
		
64
		IHandlerService handlerService = (IHandlerService) NavigationUtil.getService(IHandlerService.class); 
62

  
63
		IHandlerService handlerService = (IHandlerService) AbstractUtility.getService(IHandlerService.class);
65 64
		try {
66 65
			handlerService.executeCommand(commandId, null);
67 66
		} catch (ExecutionException e) {
68
			NavigationUtil.error(NavigationUtil.class, e);
67
			AbstractUtility.error(NavigationUtil.class, e);
69 68
		} catch (NotDefinedException e) {
70
			NavigationUtil.error(NavigationUtil.class, e);
69
			AbstractUtility.error(NavigationUtil.class, e);
71 70
		} catch (NotEnabledException e) {
72
			NavigationUtil.error(NavigationUtil.class, e);
71
			AbstractUtility.error(NavigationUtil.class, e);
73 72
		} catch (NotHandledException e) {
74
			NavigationUtil.error(NavigationUtil.class, e);
73
			AbstractUtility.error(NavigationUtil.class, e);
75 74
		}
76 75
	}
77
	
76

  
78 77
	/**
79 78
	 * <p>openEditor</p>
80 79
	 *
81 80
	 * @param selectedObject a {@link eu.etaxonomy.cdm.model.common.CdmBase} object.
82 81
	 */
83 82
	public static void openEditor(ICdmBase selectedObject){
84
		UUID entityUuid = selectedObject.getUuid();	
85
		try {	
83
		UUID entityUuid = selectedObject.getUuid();
84
		try {
86 85
			if(selectedObject instanceof TaxonNode){
87 86
				EditorUtil.openTaxonNode(entityUuid);
88 87
			}else if(selectedObject instanceof TaxonBase){
......
96 95
				warningDialog("Unsupported Type", NavigationUtil.class, "No editor exists for the current selection: " + selectedObject);
97 96
			}
98 97
		} catch (PartInitException e) {
99
			NavigationUtil.error(NavigationUtil.class, "Error opening the editor", e);
98
			AbstractUtility.error(NavigationUtil.class, "Error opening the editor", e);
100 99
		} catch (Exception e) {
101
			EditorUtil.warningDialog("Could not create Taxon", NavigationUtil.class, e.getMessage());
100
			AbstractUtility.warningDialog("Could not create Taxon", NavigationUtil.class, e.getMessage());
102 101
		}
103 102
	}
104
	
103

  
105 104
	public static void openEditor(Object selectedObject){
106 105
		if (selectedObject instanceof UuidAndTitleCache){
107 106
			Class type = ((UuidAndTitleCache) selectedObject).getType();
......
109 108
				try {
110 109
					EditorUtil.openTaxonBase(((UuidAndTitleCache) selectedObject).getUuid());
111 110
				} catch (PartInitException e) {
112
					NavigationUtil.error(NavigationUtil.class, "Error opening the editor", e);
111
					AbstractUtility.error(NavigationUtil.class, "Error opening the editor", e);
113 112
				}
114 113
			}
115 114
		}else if(selectedObject instanceof ICdmBase){
116
			openEditor((ICdmBase) selectedObject); 
115
			openEditor((ICdmBase) selectedObject);
117 116
		}else{
118
			NavigationUtil.error(NavigationUtil.class, new IllegalArgumentException("Selected object is not supported: " + selectedObject));
117
			AbstractUtility.error(NavigationUtil.class, new IllegalArgumentException("Selected object is not supported: " + selectedObject));
119 118
		}
120 119
	}
121
	
120

  
122 121
	/**
123 122
	 * <p>openEmpty</p>
124 123
	 *
......
128 127
		try {
129 128
			EditorUtil.openEmpty(parentNodeUuid);
130 129
		} catch (PartInitException e) {
131
			NavigationUtil.error(NavigationUtil.class, "Error opening the editor", e);
130
			AbstractUtility.error(NavigationUtil.class, "Error opening the editor", e);
132 131
		}
133 132
	}
134
	
133

  
135 134
	/**
136 135
	 * <p>getShell</p>
137 136
	 *
......
150 149
		return TaxeditorNavigationPlugin.getDefault().getWorkbench().
151 150
				getActiveWorkbenchWindow();
152 151
	}
153
	
152

  
154 153
	/**
155 154
	 * <p>getWorkbenchUndoContext</p>
156 155
	 *
......
169 168
	public static IUndoContext getUndoContext() {
170 169
		// FIXME this has to be more specific. Every widget has to have its own undo context
171 170
//		return IOperationHistory.GLOBAL_UNDO_CONTEXT;
172
		
173
		// Plug-ins that wish their operations to be undoable from workbench views 
174
		// such as the Navigator or Package Explorer should assign the workbench 
175
		// undo context to their operations. 
171

  
172
		// Plug-ins that wish their operations to be undoable from workbench views
173
		// such as the Navigator or Package Explorer should assign the workbench
174
		// undo context to their operations.
176 175
		if (defaultUndoContext == null) {
177 176
			defaultUndoContext = new UndoContext();
178 177
		}
......
186 185
	 * @return a boolean.
187 186
	 */
188 187
	public static boolean isDirty(TaxonNode taxonNode){
189
		
188

  
190 189
		for (IEditorReference reference : getActivePage().getEditorReferences()) {
191
			
190

  
192 191
			try {
193 192
				if (reference.getEditorInput() instanceof TaxonEditorInput) {
194 193
					TaxonEditorInput editorInput = (TaxonEditorInput) reference.getEditorInput();
......
197 196
					}
198 197
				}
199 198
			} catch (PartInitException e) {
200
				NavigationUtil.error(NavigationUtil.class, e.getMessage(), e);
199
				AbstractUtility.error(NavigationUtil.class, e.getMessage(), e);
201 200
				throw new RuntimeException(e);
202 201
			}
203
			
202

  
204 203
		}
205 204
		return false;
206 205
	}
......
214 213
	public static void selectInNavigator(final Object element, final Object parentElement) {
215 214
		Display.getDefault().asyncExec(new Runnable(){
216 215

  
217
			public void run() {
216
			@Override
217
            public void run() {
218 218
				TaxonNavigator navigator = showNavigator();
219 219

  
220 220
				if (navigator != null) {
......
223 223
						if (parentElement != null) {
224 224
							viewer.setExpandedState(parentElement, true);
225 225
						}
226
						viewer.setSelection(new StructuredSelection((TaxonNode) element));
226
						viewer.setSelection(new StructuredSelection(element));
227 227
					}
228 228
				}
229 229
			}
230
			
230

  
231 231
		});
232 232
	}
233 233

  
......
239 239
	public static void openSearch(Object selection) {
240 240
		if(selection instanceof Taxon){
241 241
			Taxon taxon = (Taxon) selection;
242
			
242

  
243 243
			handleOpeningOfMultipleTaxonNodes(taxon.getTaxonNodes());
244
			
244

  
245 245
		}else if(selection instanceof Synonym){
246 246
			Synonym synonym = (Synonym) selection;
247
			
247

  
248 248
			handleOpeningOfMultipleTaxa(synonym.getAcceptedTaxa());
249
			
249

  
250 250
		}else{
251 251
			warningDialog("Not implemented yet", NavigationUtil.class, "You chose to open a name that has no connection to a taxon. The Editor does not support editing of such a content type at the moment.");
252 252
		}
253
		
253

  
254 254
	}
255 255

  
256 256
	private static void handleOpeningOfMultipleTaxa(Set<Taxon> acceptedTaxa) {
......
271 271
	 */
272 272
	private static void handleOpeningOfMultipleTaxonNodes(
273 273
			Set<TaxonNode> taxonNodes) {
274
		
274

  
275 275
		if(taxonNodes.size() == 1){
276 276
			openEditor(taxonNodes.iterator().next());
277 277
		}else if(taxonNodes.size() > 1){

Also available in: Unified diff