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){
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigator.java
1 1
// $Id$
2 2
/**
3 3
 * Copyright (C) 2007 EDIT
4
 * European Distributed Institute of Taxonomy 
4
 * European Distributed Institute of Taxonomy
5 5
 * http://www.e-taxonomy.eu
6
 * 
6
 *
7 7
 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 8
 * See LICENSE.TXT at the top of this package for the full license terms.
9 9
 */
......
18 18
import java.util.Set;
19 19
import java.util.UUID;
20 20

  
21
import org.eclipse.core.commands.Command;
22
import org.eclipse.core.commands.common.NotDefinedException;
23 21
import org.eclipse.core.runtime.IAdaptable;
24 22
import org.eclipse.core.runtime.IProgressMonitor;
25 23
import org.eclipse.jface.viewers.DoubleClickEvent;
......
27 25
import org.eclipse.ui.IMemento;
28 26
import org.eclipse.ui.IViewSite;
29 27
import org.eclipse.ui.PartInitException;
30
import org.eclipse.ui.commands.ICommandService;
31
import org.eclipse.ui.handlers.IHandlerService;
32 28
import org.eclipse.ui.navigator.CommonNavigator;
33 29

  
34 30
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
......
45 41

  
46 42
/**
47 43
 * Taxonomic tree implementation using Common Navigator Framework.
48
 * 
44
 *
49 45
 * @author p.ciardelli
50 46
 * @author n.hoffmann
51 47
 * @created 02.06.2009
......
60 56
	 */
61 57
	public static final String ID = "eu.etaxonomy.taxeditor.navigation.navigator"; //$NON-NLS-1$
62 58

  
63
	/**
64
	 * Constant
65
	 * <code>OPEN_COMMAND_ID="eu.etaxonomy.taxeditor.navigation.comma"{trunked}</code>
66
	 */
67
	public static final String OPEN_COMMAND_ID = "eu.etaxonomy.taxeditor.navigation.command.editSelection";
68

  
69 59
	private static final String TREE_PATH = "treepath";
70 60

  
71 61
	private static final String TREE_PATHS = "treepaths";
......
78 68

  
79 69
	/*
80 70
	 * (non-Javadoc)
81
	 * 
71
	 *
82 72
	 * @see org.eclipse.ui.navigator.CommonNavigator#getInitialInput()
83 73
	 */
84 74
	/** {@inheritDoc} */
......
120 110
	 */
121 111
	public void refresh() {
122 112
		if(getConversationHolder() != null){
123
			getConversationHolder().bind();			
113
			getConversationHolder().bind();
124 114
		}
125 115
		getCommonViewer().refresh();
126 116
	}
......
136 126
	 * <p>
137 127
	 * restore
138 128
	 * </p>
139
	 * 
129
	 *
140 130
	 * @param memento
141 131
	 *            a {@link org.eclipse.ui.IMemento} object.
142 132
	 * @param monitor
......
203 193

  
204 194
		List<CdmBase> pathList = new ArrayList<CdmBase>();
205 195

  
206
		if (string.length() == 0)
207
			return null;
196
		if (string.length() == 0) {
197
            return null;
198
        }
208 199

  
209 200
		for (String uuid : string.split(" ")) {
210 201
			CdmBase cdmBaseObject = CdmStore.getService(
......
216 207
						IClassificationService.class).load(
217 208
						UUID.fromString(uuid));
218 209

  
219
				if (cdmBaseObject == null)
220
					return null;
210
				if (cdmBaseObject == null) {
211
                    return null;
212
                }
221 213
			}
222 214
			pathList.add(cdmBaseObject);
223 215
		}
......
234 226
	 * <p>
235 227
	 * saveTreeState
236 228
	 * </p>
237
	 * 
229
	 *
238 230
	 * @param memento
239 231
	 *            a {@link org.eclipse.ui.IMemento} object.
240 232
	 * @param progressMonitor
......
274 266

  
275 267
	/*
276 268
	 * (non-Javadoc)
277
	 * 
269
	 *
278 270
	 * @see
279 271
	 * eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder
280 272
	 * ()
......
283 275
	 * <p>
284 276
	 * getConversationHolder
285 277
	 * </p>
286
	 * 
278
	 *
287 279
	 * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
288 280
	 *         object.
289 281
	 */
......
294 286

  
295 287
	/*
296 288
	 * (non-Javadoc)
297
	 * 
289
	 *
298 290
	 * @see
299 291
	 * eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update
300 292
	 * (eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
......
320 312

  
321 313
	/*
322 314
	 * (non-Javadoc)
323
	 * 
315
	 *
324 316
	 * @see org.eclipse.ui.part.WorkbenchPart#dispose()
325 317
	 */
326 318
	/** {@inheritDoc} */
......
335 327

  
336 328
	/*
337 329
	 * (non-Javadoc)
338
	 * 
330
	 *
339 331
	 * @see org.eclipse.ui.navigator.CommonNavigator#setFocus()
340 332
	 */
341 333
	/** {@inheritDoc} */
......
350 342

  
351 343
	/*
352 344
	 * (non-Javadoc)
353
	 * 
345
	 *
354 346
	 * @see
355 347
	 * eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation
356 348
	 * (eu.etaxonomy.cdm.model.common.CdmBase)
......
366 358
	 * <p>
367 359
	 * save
368 360
	 * </p>
369
	 * 
361
	 *
370 362
	 * @param memento
371 363
	 *            a {@link org.eclipse.ui.IMemento} object.
372 364
	 * @param monitor
......
383 375
	/** {@inheritDoc} */
384 376
	@Override
385 377
	protected void handleDoubleClick(DoubleClickEvent anEvent) {
386

  
387
		ICommandService commandService = (ICommandService) getSite()
388
				.getService(ICommandService.class);
389

  
390
		Command command = commandService.getCommand(OPEN_COMMAND_ID);
391
		if (command.isEnabled()) {
392
			IHandlerService handlerService = (IHandlerService) getSite()
393
					.getService(IHandlerService.class);
394
			try {
395
				handlerService.executeCommand(OPEN_COMMAND_ID, null);
396
			} catch (NotDefinedException e) {
397
				throw new RuntimeException("Could not find open command: "
398
						+ OPEN_COMMAND_ID);
399
			} catch (Exception e) {
400
				NavigationUtil
401
						.error(getClass(),
402
								"An exception occured while trying to open a selection",
403
								e);
404
			}
405
		}
378
		NavigationUtil.executeEditHandler();
406 379
		// If the double click is passed up to the super-class it will
407 380
		// expand/collapse trees.
408 381
		// We do not want that
......
413 386
	 * <p>
414 387
	 * onComplete
415 388
	 * </p>
416
	 * 
389
	 *
417 390
	 * @return a boolean.
418 391
	 */
419 392
	@Override
......
423 396

  
424 397
	/*
425 398
	 * (non-Javadoc)
426
	 * 
399
	 *
427 400
	 * @see org.eclipse.ui.part.WorkbenchPart#showBusy(boolean)
428 401
	 */
429 402
	/** {@inheritDoc} */
......
450 423
		if(o instanceof LoginManager){
451 424
			refresh();
452 425
		}
453
		
426

  
454 427
	}
455 428
}
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/EditHandler.java
2 2
// $Id$
3 3
/**
4 4
* Copyright (C) 2007 EDIT
5
* European Distributed Institute of Taxonomy 
5
* European Distributed Institute of Taxonomy
6 6
* http://www.e-taxonomy.eu
7
* 
7
*
8 8
* The contents of this file are subject to the Mozilla Public License Version 1.1
9 9
* See LICENSE.TXT at the top of this package for the full license terms.
10 10
*/
......
41 41
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
42 42
	 */
43 43
	/** {@inheritDoc} */
44
	public Object execute(ExecutionEvent event) throws ExecutionException {
45
	
44
	@Override
45
    public Object execute(ExecutionEvent event) throws ExecutionException {
46

  
46 47
		ISelection selection = HandlerUtil.getCurrentSelection(event);
47
		
48

  
48 49
		if(selection instanceof StructuredSelection){
49 50
			final StructuredSelection structuredSelection = (StructuredSelection) selection;
50
			
51

  
51 52
			if(structuredSelection.size() == 1 && structuredSelection.getFirstElement() instanceof Classification){
52 53
				Classification classification = (Classification) structuredSelection.getFirstElement();
53
				
54

  
54 55
				NewClassificationWizard classificationWizard = new NewClassificationWizard();
55 56
				classificationWizard.init(null, null);
56 57
				classificationWizard.setEntity(classification);
57 58
				WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event), classificationWizard);
58 59
				dialog.open();
59
				
60

  
60 61
			}
61 62
			else{
62 63

  
63 64
				Job job = new Job("Opening editor") {
64
					
65

  
65 66
					@Override
66 67
					protected IStatus run(IProgressMonitor monitor) {
67 68
						for(final Object selectedObject : structuredSelection.toArray()){
68
							
69

  
69 70
							Display.getDefault().asyncExec(new Runnable(){
70
	
71
								public void run() {
71

  
72
								@Override
73
                                public void run() {
72 74
									NavigationUtil.openEditor(selectedObject);
73 75
								}
74
								
76

  
75 77
							});
76 78
						}
77 79
						return Status.OK_STATUS;
78 80
					}
79 81
				};
80
				
82

  
81 83
				job.schedule();
82 84
			}
83 85
		}
84
		
86

  
85 87
		return null;
86 88
	}
87 89
}
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/search/SearchResultView.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
*/
......
41 41
import eu.etaxonomy.cdm.model.common.UuidAndTitleCache;
42 42
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
43 43
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
44
import eu.etaxonomy.taxeditor.model.AbstractUtility;
44 45
import eu.etaxonomy.taxeditor.model.ContextListenerAdapter;
45 46
import eu.etaxonomy.taxeditor.model.IContextListener;
46 47
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
......
56 57
 * @version 1.0
57 58
 */
58 59
public class SearchResultView extends ViewPart implements IConversationEnabled{
59
	
60

  
60 61
	private static Object[] EMPTY = new Object[0];
61
	
62

  
62 63
	private class ContextListener extends ContextListenerAdapter{
63 64
		/* (non-Javadoc)
64 65
		 * @see eu.etaxonomy.taxeditor.model.IContextListener#contextStop(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
......
66 67
		@Override
67 68
		public void contextStop(IMemento memento, IProgressMonitor monitor) {
68 69
			monitor.subTask("Getting rid of search results");
69
			NavigationUtil.hideView(SearchResultView.this);
70
			AbstractUtility.hideView(SearchResultView.this);
70 71
		}
71 72
	}
72
	
73

  
73 74
	/** Constant <code>ID="eu.etaxonomy.taxeditor.navigation.searc"{trunked}</code> */
74
	public static final String ID = 
75
	public static final String ID =
75 76
			"eu.etaxonomy.taxeditor.navigation.search.searchResultView"; //$NON-NLS-1$
76 77

  
77 78
	private TableViewer resultViewer;
......
85 86
	private Text status;
86 87

  
87 88
	private SearchJob searchJob;
88
	
89

  
89 90
	private IContextListener contextListener;
90
	
91

  
91 92
	/* (non-Javadoc)
92 93
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
93 94
	 */
94 95
	/** {@inheritDoc} */
95 96
	@Override
96 97
	public void createPartControl(Composite parent) {
97
		
98

  
98 99
		conversation = CdmStore.createConversation();
99 100
		contextListener = new ContextListener();
100 101
		CdmStore.getContextManager().addContextListener(contextListener);
101
		
102

  
102 103
		GridLayout layout = new GridLayout();
103 104
		layout.marginWidth = 0;
104 105
		layout.marginHeight = 0;
105
		
106

  
106 107
		parent.setLayout(layout);
107
		
108

  
108 109
		Composite infoComposite = createInfoComposite(parent);
109 110
		infoComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
110
		
111

  
111 112
		resultViewer = new TableViewer(parent, SWT.NONE);
112 113
		resultViewer.setContentProvider(new ArrayContentProvider());
113 114
		resultViewer.setLabelProvider(new SearchResultLabelProvider());
114 115
		resultViewer.addDoubleClickListener(new IDoubleClickListener() {
115
			public void doubleClick(DoubleClickEvent event) {
116
			@Override
117
            public void doubleClick(DoubleClickEvent event) {
116 118
				NavigationUtil.executeEditHandler();
117 119
			}
118 120
		});
119
		
121

  
120 122
		resultViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
121
		
123

  
122 124
		getSite().setSelectionProvider(resultViewer);
123
		
125

  
124 126
		// register context menu
125 127
		MenuManager menuMgr = new MenuManager();
126 128
		menuMgr.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
......
128 130

  
129 131
		Control control = resultViewer.getControl();
130 132
		Menu menu = menuMgr.createContextMenu(control);
131
		control.setMenu(menu);	
133
		control.setMenu(menu);
132 134
	}
133
	
135

  
134 136
	private Composite createInfoComposite(Composite parent){
135 137
		Composite composite = new Composite(parent, SWT.NULL);
136
		
138

  
137 139
		composite.setLayout(new GridLayout(2, false));
138
		
140

  
139 141
		Label searchStringLabel = new Label(composite, SWT.NULL);
140 142
		searchStringLabel.setText("Search String:");
141
		
143

  
142 144
		searchString = new Text(composite, SWT.NULL);
143 145
		searchString.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
144 146
		searchString.setEditable(false);
145 147
//		searchString.setText("                                               ");
146
		
148

  
147 149
		Label configurationDescriptionLabel = new Label(composite, SWT.NULL);
148 150
		configurationDescriptionLabel.setText("Search for:");
149
		
151

  
150 152
		configurationLabel = new Text(composite, SWT.WRAP);
151 153
		configurationLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
152 154
		configurationLabel.setEditable(false);
153
		
155

  
154 156
		Label statusLabel = new Label(composite, SWT.NULL);
155 157
		statusLabel.setText("Status:");
156
		
158

  
157 159
		status = new Text(composite, SWT.NULL);
158 160
		status.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
159 161
		status.setEditable(false);
160
		
162

  
161 163
		return composite;
162 164
	}
163
	
165

  
164 166
	/**
165 167
	 * <p>performSearch</p>
166 168
	 *
......
168 170
	 */
169 171
	public void performSearch(IFindTaxaAndNamesConfigurator configurator){
170 172
		setPartName("Search: '" + configurator.getTitleSearchString() + "'");
171
		
173

  
172 174
		searchString.setText(configurator.getTitleSearchString());
173
		
175

  
174 176
		List<String> includedEntities = new ArrayList<String>();
175
		if(configurator.isDoTaxa())
176
			includedEntities.add(SearchOption.TAXON.getLabel());
177
		if(configurator.isDoSynonyms())
178
			includedEntities.add(SearchOption.SYNONYM.getLabel());
179
		if(configurator.isDoNamesWithoutTaxa())
180
			includedEntities.add(SearchOption.NAME.getLabel());
177
		if(configurator.isDoTaxa()) {
178
            includedEntities.add(SearchOption.TAXON.getLabel());
179
        }
180
		if(configurator.isDoSynonyms()) {
181
            includedEntities.add(SearchOption.SYNONYM.getLabel());
182
        }
183
		if(configurator.isDoNamesWithoutTaxa()) {
184
            includedEntities.add(SearchOption.NAME.getLabel());
185
        }
181 186
		if(configurator.isDoTaxaByCommonNames()){
182 187
			includedEntities.add(SearchOption.COMMON_NAME.getLabel());
183 188
		}
184
		
189

  
185 190
		String includedEntitiesString = "";
186 191
		for (int i = 0; i < includedEntities.size(); i++){
187 192
			includedEntitiesString += includedEntities.get(i);
......
189 194
				includedEntitiesString += ", ";
190 195
			}
191 196
		}
192
		
197

  
193 198
		configurationLabel.setText(includedEntitiesString);
194
		
199

  
195 200
		status.setText("Searching...");
196
		
201

  
197 202
		searchJob = new SearchJob(Display.getCurrent(), configurator);
198 203
		searchJob.schedule();
199
		
204

  
200 205
	}
201
	
206

  
202 207
	/**
203 208
	 * <p>displaySearchResult</p>
204 209
	 *
......
206 211
	 */
207 212
	protected void displaySearchResult(List<UuidAndTitleCache<TaxonBase>> result) {
208 213
		if(result.size() > 0){
209
			resultViewer.setInput(result); 
214
			resultViewer.setInput(result);
210 215
			status.setText(result.size() + " entities found");
211 216
		}else{
212
			resultViewer.setInput(EMPTY); 
217
			resultViewer.setInput(EMPTY);
213 218
			status.setText("Search returned no results");
214 219
		}
215 220
	}
......
234 239
	 *
235 240
	 * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
236 241
	 */
237
	public ConversationHolder getConversationHolder() {
242
	@Override
243
    public ConversationHolder getConversationHolder() {
238 244
		return this.conversation;
239 245
	}
240 246

  
......
242 248
	 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
243 249
	 */
244 250
	/** {@inheritDoc} */
245
	public void update(CdmDataChangeMap changeEvents) {
251
	@Override
252
    public void update(CdmDataChangeMap changeEvents) {
246 253
		// TODO Auto-generated method stub
247
		
254

  
248 255
	}
249
	
256

  
250 257
	/* (non-Javadoc)
251 258
	 * @see org.eclipse.ui.part.WorkbenchPart#dispose()
252 259
	 */
......
255 262
	public void dispose() {
256 263
		super.dispose();
257 264
		conversation.close();
258
		if(searchJob != null)
259
			searchJob.cancel();
265
		if(searchJob != null) {
266
            searchJob.cancel();
267
        }
260 268
		CdmStore.getContextManager().removeContextListener(contextListener);
261 269
	}
262
	
270

  
263 271
	/**
264
	 * 
272
	 *
265 273
	 * @author n.hoffmann
266 274
	 * @created Feb 2, 2010
267 275
	 * @version 1.0
268 276
	 */
269 277
	class SearchJob extends Job{
270 278

  
271
		private IFindTaxaAndNamesConfigurator configurator;
272
		
273
		private Display display;
274
		
279
		private final IFindTaxaAndNamesConfigurator configurator;
280

  
281
		private final Display display;
282

  
275 283
		/**
276 284
		 * @param name
277 285
		 */
......
288 296
		protected IStatus run(IProgressMonitor monitor) {
289 297
			monitor.beginTask("", 100);
290 298
			monitor.worked(20);
291
			
299

  
292 300
			final List<UuidAndTitleCache<TaxonBase>> searchResult = CdmStore.getSearchManager().findTaxaAndNames(configurator);
293 301
			monitor.worked(40);
294
			
302

  
295 303
			if(! monitor.isCanceled()){
296 304
				display.asyncExec(new Runnable() {
297
					public void run() {
305
					@Override
306
                    public void run() {
298 307
						displaySearchResult(searchResult);
299 308
					}
300 309
				});
301 310
			}else{
302 311
				display.asyncExec(new Runnable() {
303
					public void run() {
312
					@Override
313
                    public void run() {
304 314
						status.setText("Cancelled");
305 315
					}
306 316
				});
......
308 318
			monitor.done();
309 319
			return Status.OK_STATUS;
310 320
		}
311
		
312
	}	
321

  
322
	}
313 323
}

Also available in: Unified diff