Project

General

Profile

Download (15.7 KB) Statistics
| Branch: | Tag: | Revision:
1 729887cf n.hoffmann
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4 22cb6038 Patric Plitzner
* European Distributed Institute of Taxonomy
5 729887cf n.hoffmann
* http://www.e-taxonomy.eu
6 22cb6038 Patric Plitzner
*
7 729887cf n.hoffmann
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
11 78222507 n.hoffmann
package eu.etaxonomy.taxeditor.ui.dialog.selection;
12 729887cf n.hoffmann
13 b4fa7dfb n.hoffmann
import java.lang.reflect.Field;
14 729887cf n.hoffmann
import java.text.Collator;
15
import java.util.Comparator;
16
import java.util.HashSet;
17 757377b5 Katja Luther
import java.util.Iterator;
18 729887cf n.hoffmann
import java.util.List;
19
import java.util.Set;
20
import java.util.UUID;
21
22
import org.eclipse.core.runtime.CoreException;
23
import org.eclipse.core.runtime.IProgressMonitor;
24
import org.eclipse.core.runtime.IStatus;
25
import org.eclipse.core.runtime.OperationCanceledException;
26
import org.eclipse.core.runtime.Status;
27
import org.eclipse.jface.dialogs.IDialogSettings;
28
import org.eclipse.jface.viewers.ILabelProvider;
29
import org.eclipse.jface.viewers.LabelProvider;
30
import org.eclipse.jface.window.Window;
31 2d9a13f7 n.hoffmann
import org.eclipse.jface.wizard.WizardDialog;
32
import org.eclipse.swt.SWT;
33 9a0f58cd n.hoffmann
import org.eclipse.swt.events.SelectionAdapter;
34
import org.eclipse.swt.events.SelectionEvent;
35
import org.eclipse.swt.events.SelectionListener;
36 7b0c206b Cherian Mathew
import org.eclipse.swt.graphics.Cursor;
37 2d9a13f7 n.hoffmann
import org.eclipse.swt.widgets.Composite;
38
import org.eclipse.swt.widgets.Control;
39
import org.eclipse.swt.widgets.Link;
40 729887cf n.hoffmann
import org.eclipse.swt.widgets.Shell;
41
import org.eclipse.swt.widgets.Text;
42
import org.eclipse.ui.IMemento;
43
44 2d9a13f7 n.hoffmann
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
45
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
46 729887cf n.hoffmann
import eu.etaxonomy.cdm.model.common.CdmBase;
47 db5e366d n.hoffmann
import eu.etaxonomy.cdm.model.common.ICdmBase;
48 729887cf n.hoffmann
import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;
49 48d1a460 Andreas M��ller
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
50 2d9a13f7 n.hoffmann
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
51 41e2f693 Cherian Mathew
import eu.etaxonomy.taxeditor.model.MessagingUtils;
52 f211dd28 n.hoffmann
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
53 22cb6038 Patric Plitzner
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
54
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
55 729887cf n.hoffmann
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
56
57
/**
58 3be6ef3e n.hoffmann
 * <p>Abstract AbstractFilteredCdmResourceSelectionDialog class.</p>
59
 *
60 729887cf n.hoffmann
 * @author n.hoffmann
61
 * @created 04.06.2009
62
 * @version 1.0
63
 */
64 db5e366d n.hoffmann
public abstract class AbstractFilteredCdmResourceSelectionDialog<T extends ICdmBase> extends
65 7efbd7cf Katja Luther
		CdmFilteredItemsSelectionDialog implements IConversationEnabled {
66 729887cf n.hoffmann
67 496d0049 Patric Plitzner
	private final ConversationHolder conversation;
68 729887cf n.hoffmann
69
	protected List<UuidAndTitleCache<T>> model;
70 496d0049 Patric Plitzner
	private final Set<T> transientCdmObjects = new HashSet<T>();
71
	private final String settings;
72 7efbd7cf Katja Luther
	protected final int limitOfInitialElements = 100;
73 d33f8978 Katja Luther
	
74 9ac72187 l.morris
	protected T cdmBaseToBeFiltered;
75 22cb6038 Patric Plitzner
76 2e93b829 Cherian Mathew
77 729887cf n.hoffmann
	/**
78 3be6ef3e n.hoffmann
	 * <p>Constructor for AbstractFilteredCdmResourceSelectionDialog.</p>
79
	 *
80
	 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
81 22cb6038 Patric Plitzner
	 * @param conversation
82 3be6ef3e n.hoffmann
	 * @param title a {@link java.lang.String} object.
83
	 * @param multi a boolean.
84
	 * @param settings a {@link java.lang.String} object.
85
	 * @param cdmObject a T object.
86
	 * @param <T> a T object.
87 729887cf n.hoffmann
	 */
88 2d9a13f7 n.hoffmann
	protected AbstractFilteredCdmResourceSelectionDialog(Shell shell, ConversationHolder conversation, String title, boolean multi, String settings, T cdmObject) {
89 729887cf n.hoffmann
		super(shell, multi);
90
		setTitle(title);
91
		setMessage("Use * for wildcard, or ? to see all entries");
92
		this.settings = settings;
93 22cb6038 Patric Plitzner
94 2d9a13f7 n.hoffmann
		this.conversation = conversation;
95 fd602c14 Katja Luther
		this.cdmBaseToBeFiltered = cdmObject;
96 7b0c206b Cherian Mathew
		Cursor cursor = shell.getCursor();
97
		shell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT));
98 729887cf n.hoffmann
		init();
99
		initModel();
100 7b0c206b Cherian Mathew
		shell.setCursor(cursor);
101 b478a42f n.hoffmann
		String objectTitle = getTitle(cdmObject);
102 87348c2d Katja Luther
//		if (objectTitle != null) {
103
//			setInitialPattern(objectTitle);
104
//		}
105 22cb6038 Patric Plitzner
106 b478a42f n.hoffmann
		setListLabelProvider(createListLabelProvider());
107
		setDetailsLabelProvider(createDetailsLabelProvider());
108 22cb6038 Patric Plitzner
109 b4fa7dfb n.hoffmann
		setSelectionHistory(new ResourceSelectionHistory());
110 729887cf n.hoffmann
	}
111 22cb6038 Patric Plitzner
112 b478a42f n.hoffmann
	/**
113
	 * By default, we are returning the standard list label provider
114 22cb6038 Patric Plitzner
	 *
115
	 * Override in subclasses if you want different behavior
116
	 *
117 b478a42f n.hoffmann
	 * @return
118
	 */
119
	protected ILabelProvider createDetailsLabelProvider() {
120
		return createListLabelProvider();
121
	}
122
123
	/**
124 22cb6038 Patric Plitzner
	 *
125 b478a42f n.hoffmann
	 * @return
126
	 */
127
	protected ILabelProvider createListLabelProvider() {
128
		return new FilteredCdmResourceLabelProvider();
129
	}
130
131 729887cf n.hoffmann
	/**
132 b4fa7dfb n.hoffmann
	 * Override in subclasses.
133 729887cf n.hoffmann
	 * Will run before initModel()
134
	 */
135
	protected void init() {
136 22cb6038 Patric Plitzner
137 729887cf n.hoffmann
	}
138 22cb6038 Patric Plitzner
139 729887cf n.hoffmann
	/**
140 3be6ef3e n.hoffmann
	 * <p>getSelectionFromDialog</p>
141
	 *
142 78222507 n.hoffmann
	 * @param dialog a {@link eu.etaxonomy.taxeditor.ui.dialog.selection.AbstractFilteredCdmResourceSelectionDialog} object.
143 3be6ef3e n.hoffmann
	 * @param <TYPE> a TYPE object.
144
	 * @return a TYPE object.
145 729887cf n.hoffmann
	 */
146
	protected static <TYPE extends CdmBase> TYPE getSelectionFromDialog(AbstractFilteredCdmResourceSelectionDialog<TYPE> dialog) {
147 b4fa7dfb n.hoffmann
		//dialog.setInitialPattern("");
148
		int result = dialog.open();
149 22cb6038 Patric Plitzner
150 b4fa7dfb n.hoffmann
		if (result == Window.CANCEL) {
151 729887cf n.hoffmann
			return null;
152
		}
153 22cb6038 Patric Plitzner
154 729887cf n.hoffmann
		UUID uuid = dialog.getSelectedUuidAndTitleCache().getUuid();
155
		if(uuid == null){
156
			return null;
157 22cb6038 Patric Plitzner
		}
158 729887cf n.hoffmann
		return dialog.getCdmObjectByUuid(uuid);
159
	}
160 22cb6038 Patric Plitzner
161 729887cf n.hoffmann
	/**
162
	 * Check if object was created during the life of this dialog. If not,
163
	 * retrieve it from the CdmStore.
164 3be6ef3e n.hoffmann
	 *
165
	 * @param cdmUuid a {@link java.util.UUID} object.
166
	 * @return a T object.
167 729887cf n.hoffmann
	 */
168
	protected T getCdmObjectByUuid(UUID cdmUuid) {
169
		for (T cdmObject : transientCdmObjects) {
170
			if (cdmObject.getUuid().equals(cdmUuid)) {
171
				return cdmObject;
172
			}
173
		}
174
		return getPersistentObject(cdmUuid);
175
	}
176 22cb6038 Patric Plitzner
177 729887cf n.hoffmann
	/**
178 3be6ef3e n.hoffmann
	 * <p>getPersistentObject</p>
179
	 *
180
	 * @param uuid a {@link java.util.UUID} object.
181
	 * @return a T object.
182 729887cf n.hoffmann
	 */
183
	abstract protected T getPersistentObject(UUID uuid);
184
185
	/**
186
	 * @param cdmObject
187
	 */
188 2d9a13f7 n.hoffmann
//	protected void addObjectToModel(T cdmObject) {
189
//		model.add(new UuidAndTitleCache(cdmObject.getClass(), cdmObject.getUuid(), getTitle(cdmObject)));
190
//		transientCdmObjects.add(cdmObject);
191
//	}
192 729887cf n.hoffmann
193
	/**
194 3be6ef3e n.hoffmann
	 * <p>isObjectTransient</p>
195
	 *
196
	 * @param cdmObject a T object.
197
	 * @return a boolean.
198 729887cf n.hoffmann
	 */
199
	protected boolean isObjectTransient(T cdmObject) {
200
		return (getPersistentObject(cdmObject.getUuid()) == null);
201
	}
202
203
	/**
204 3be6ef3e n.hoffmann
	 * <p>getTitle</p>
205
	 *
206
	 * @param cdmObject a T object.
207
	 * @return a {@link java.lang.String} object.
208 729887cf n.hoffmann
	 */
209
	protected String getTitle(T cdmObject) {
210 e0b35bf1 n.hoffmann
		if(cdmObject == null){
211
			return "";
212
		}
213 22cb6038 Patric Plitzner
214 729887cf n.hoffmann
		if (cdmObject instanceof IIdentifiableEntity) {
215 22cb6038 Patric Plitzner
			return ((IIdentifiableEntity) cdmObject).getTitleCache();
216 729887cf n.hoffmann
		}
217 22cb6038 Patric Plitzner
218 b478a42f n.hoffmann
		throw new IllegalArgumentException("Generic method only" +
219
				" supports cdmObject of type IIdentifiableEntity." +
220
				" Please implement specific method in subclass.");
221 729887cf n.hoffmann
	}
222 22cb6038 Patric Plitzner
223 729887cf n.hoffmann
224 3be6ef3e n.hoffmann
	/** {@inheritDoc} */
225 2d9a13f7 n.hoffmann
	@Override
226
	public void refresh() {
227
		super.refresh();
228
	}
229 22cb6038 Patric Plitzner
230 827bea53 Katja Luther
231 729887cf n.hoffmann
232
	/* (non-Javadoc)
233
	 * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#createFilter()
234
	 */
235 3be6ef3e n.hoffmann
	/** {@inheritDoc} */
236 729887cf n.hoffmann
	@Override
237
	protected ItemsFilter createFilter() {
238
		return new ItemsFilter() {
239
240 b4fa7dfb n.hoffmann
			/**
241
			 * Always returns false to enforce refiltering even if the pattern is equal
242
			 */
243
			@Override
244
			public boolean equalsFilter(ItemsFilter filter) {
245
				return false;
246
			}
247 22cb6038 Patric Plitzner
248 729887cf n.hoffmann
			@Override
249
			public boolean isConsistentItem(Object item) {
250
				return false;
251
			}
252
253
			@Override
254
			public boolean matchItem(Object item) {
255
				String text = null;
256
				if(item instanceof UuidAndTitleCache){
257
					text = ((UuidAndTitleCache) item).getTitleCache();
258
				}else if(item instanceof String){
259
					text = (String) item;
260
				}
261
				return text != null ? matches(text) : false;
262
			}
263 22cb6038 Patric Plitzner
264 729887cf n.hoffmann
		};
265
	}
266 22cb6038 Patric Plitzner
267 729887cf n.hoffmann
268
	/**
269 3be6ef3e n.hoffmann
	 * Set the filter input to the Agent's title cache
270
	 *
271
	 * @param cdmObject a T object.
272 729887cf n.hoffmann
	 */
273
	protected void setPattern(T cdmObject) {
274 22cb6038 Patric Plitzner
		// FilteredSelection does some very tricky caching to make sure it
275
		// runs with high performance.
276 b4fa7dfb n.hoffmann
		// This works for most use cases, but we want to change the model while the dialog is open
277
		// and all the clever caching prevents the content provider from knowing that the model has changed
278 22cb6038 Patric Plitzner
		// I am aware, that this is a hack, but the FilteredSelectionDialog API does not offer a convenient
279 b4fa7dfb n.hoffmann
		// way to solve the problem.
280
		try {
281
			Field lastCompletedFilter = this.getClass().getSuperclass().getSuperclass().getDeclaredField("lastCompletedFilter");
282
			lastCompletedFilter.setAccessible(true);
283
			lastCompletedFilter.set(this, null);
284
		} catch (SecurityException e) {
285 41e2f693 Cherian Mathew
			MessagingUtils.error(getClass(), e);
286 b4fa7dfb n.hoffmann
		} catch (NoSuchFieldException e) {
287 41e2f693 Cherian Mathew
			MessagingUtils.error(getClass(), e);
288 b4fa7dfb n.hoffmann
		} catch (IllegalArgumentException e) {
289 41e2f693 Cherian Mathew
			MessagingUtils.error(getClass(), e);
290 b4fa7dfb n.hoffmann
		} catch (IllegalAccessException e) {
291 41e2f693 Cherian Mathew
			MessagingUtils.error(getClass(), e);
292 b4fa7dfb n.hoffmann
		}
293 22cb6038 Patric Plitzner
294
		// this also is not the nicest way to do it.
295 b4fa7dfb n.hoffmann
		// I am still amazed, that FilteredSelectionDialog does not offer any methods to change its data
296
		// once it was opened. Am I doing it wrong?
297 b478a42f n.hoffmann
		String pattern = getTitle(cdmObject);
298
		((Text) getPatternControl()).setText(pattern);
299 729887cf n.hoffmann
	}
300 22cb6038 Patric Plitzner
301 7efbd7cf Katja Luther
302
303 729887cf n.hoffmann
	/* (non-Javadoc)
304
	* @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#fillContentProvider(org.eclipse.ui.dialogs.FilteredItemsSelectionDialog.AbstractContentProvider, org.eclipse.ui.dialogs.FilteredItemsSelectionDialog.ItemsFilter, org.eclipse.core.runtime.IProgressMonitor)
305
	*/
306 3be6ef3e n.hoffmann
	/** {@inheritDoc} */
307 729887cf n.hoffmann
	@Override
308
	protected void fillContentProvider(AbstractContentProvider contentProvider,
309
		ItemsFilter itemsFilter, IProgressMonitor progressMonitor)
310
		throws CoreException {
311
		try {
312 22cb6038 Patric Plitzner
			if(model != null){
313 2d9a13f7 n.hoffmann
				progressMonitor.beginTask("Looking for entities", model.size());
314 757377b5 Katja Luther
				filterExcludedObjects();
315
				Iterator<UuidAndTitleCache<T>> iterator = model.iterator();
316
				UuidAndTitleCache<T> element;
317
				while(iterator.hasNext()){
318
				    element = iterator.next();
319 2d9a13f7 n.hoffmann
					contentProvider.add(element, itemsFilter);
320
					if (progressMonitor.isCanceled()) {
321
						throw new OperationCanceledException();
322
					}
323
					progressMonitor.worked(1);
324 729887cf n.hoffmann
				}
325 2d9a13f7 n.hoffmann
			}else{
326 41e2f693 Cherian Mathew
				MessagingUtils.warn(getClass(), "Model for Filtered Selection is null:" + this.getClass().getSimpleName());
327 729887cf n.hoffmann
			}
328
		}
329
		finally {
330
			progressMonitor.done();
331
		}
332
	}
333
334
	/* (non-Javadoc)
335
	 * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#getDialogSettings()
336
	 */
337 3be6ef3e n.hoffmann
	/** {@inheritDoc} */
338 729887cf n.hoffmann
	@Override
339
	protected IDialogSettings getDialogSettings() {
340
		IDialogSettings settings = TaxeditorStorePlugin.getDefault().getDialogSettings().getSection(getSettings());
341
342
		if (settings == null) {
343
			settings = TaxeditorStorePlugin.getDefault().getDialogSettings().addNewSection(getSettings());
344
		}
345
		return settings;
346
	}
347
348
	/* (non-Javadoc)
349
	 * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#getElementName(java.lang.Object)
350
	 */
351 3be6ef3e n.hoffmann
	/** {@inheritDoc} */
352 729887cf n.hoffmann
	@Override
353
	public String getElementName(Object item) {
354
		return ((UuidAndTitleCache) item).getTitleCache();
355
	}
356
357
	/* (non-Javadoc)
358
	 * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#getItemsComparator()
359
	 */
360 3be6ef3e n.hoffmann
	/** {@inheritDoc} */
361 729887cf n.hoffmann
	@Override
362
	protected Comparator getItemsComparator() {
363
		return new Comparator<UuidAndTitleCache>() {
364 496d0049 Patric Plitzner
			@Override
365 729887cf n.hoffmann
			public int compare(UuidAndTitleCache entity1,
366
					UuidAndTitleCache entity2) {
367
				Collator collator = Collator.getInstance();
368
				return collator.compare(entity1.getTitleCache(), entity2.getTitleCache());
369
			}
370
		};
371
	}
372
373
	/* (non-Javadoc)
374
	 * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#validateItem(java.lang.Object)
375
	 */
376 3be6ef3e n.hoffmann
	/** {@inheritDoc} */
377 729887cf n.hoffmann
	@Override
378
	protected IStatus validateItem(Object item) {
379
		return Status.OK_STATUS;
380
	}
381 22cb6038 Patric Plitzner
382 729887cf n.hoffmann
	/**
383 3be6ef3e n.hoffmann
	 * <p>getSelectedUuidAndTitleCache</p>
384
	 *
385
	 * @return a {@link eu.etaxonomy.cdm.model.common.UuidAndTitleCache} object.
386
	 */
387 729887cf n.hoffmann
	protected UuidAndTitleCache getSelectedUuidAndTitleCache() {
388
		Object[] result = getResult();
389
		return result[0] == null ? null : (UuidAndTitleCache) result[0];
390
	}
391 22cb6038 Patric Plitzner
392 3be6ef3e n.hoffmann
	/**
393
	 * <p>Getter for the field <code>settings</code>.</p>
394
	 *
395
	 * @return a {@link java.lang.String} object.
396
	 */
397 729887cf n.hoffmann
	public String getSettings()  {
398
		if(settings == null){
399
			throw new IllegalStateException("No SETTINGS set.");
400
		}
401
		return settings;
402
	}
403 22cb6038 Patric Plitzner
404 729887cf n.hoffmann
	/**
405 22cb6038 Patric Plitzner
	 *
406 729887cf n.hoffmann
	 * @author n.hoffmann
407
	 * @created Oct 19, 2009
408
	 * @version 1.0
409
	 */
410
	private class ResourceSelectionHistory extends SelectionHistory {
411
	    /*
412
	    * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog.SelectionHistory#restoreItemFromMemento(org.eclipse.ui.IMemento)
413
	   	*/
414 496d0049 Patric Plitzner
		@Override
415 729887cf n.hoffmann
		protected Object restoreItemFromMemento(IMemento element) {
416
			return element.getString("resource"); //$NON-NLS-1$
417
	  	}
418
	  	/*
419
	  	 * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog.SelectionHistory#storeItemToMemento(java.lang.Object,
420
	  	 *      org.eclipse.ui.IMemento)
421
	  	 */
422 496d0049 Patric Plitzner
		@Override
423 729887cf n.hoffmann
		protected void storeItemToMemento(Object item, IMemento element) {
424
			element.putString("resource", item.toString()); //$NON-NLS-1$
425
		}
426
	}
427 22cb6038 Patric Plitzner
428 3be6ef3e n.hoffmann
	/**
429
	 * <p>getNewWizardLinkText</p>
430
	 *
431
	 * @return a {@link java.lang.String} object.
432
	 */
433 2d9a13f7 n.hoffmann
	protected abstract String getNewWizardLinkText();
434 22cb6038 Patric Plitzner
435 3be6ef3e n.hoffmann
	/**
436
	 * <p>getNewEntityWizard</p>
437 22cb6038 Patric Plitzner
	 * @param parameter
438 f211dd28 n.hoffmann
	 * @return a {@link eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard} object.
439 3be6ef3e n.hoffmann
	 */
440 9a0f58cd n.hoffmann
	protected abstract AbstractNewEntityWizard getNewEntityWizard(String parameter);
441 22cb6038 Patric Plitzner
442 729887cf n.hoffmann
	public class FilteredCdmResourceLabelProvider extends LabelProvider {
443 496d0049 Patric Plitzner
		@Override
444 729887cf n.hoffmann
		public String getText(Object element) {
445
			if (element == null) {
446
				return null;
447
			}
448 22cb6038 Patric Plitzner
			UuidAndTitleCache uuidAndTitleCache = (UuidAndTitleCache) element;
449
			String titleCache = uuidAndTitleCache.getTitleCache();
450 b433159f Patric Plitzner
			if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_ID_IN_ENTITY_SELECTION_DIAOLOG)){
451 22cb6038 Patric Plitzner
			    titleCache += " ["+uuidAndTitleCache.getId()+"]";
452
			}
453
            return titleCache;
454
		}
455 729887cf n.hoffmann
	};
456
457 2d9a13f7 n.hoffmann
	/* (non-Javadoc)
458
	* @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#createExtendedContentArea(org.eclipse.swt.widgets.Composite)
459
	*/
460 3be6ef3e n.hoffmann
	/** {@inheritDoc} */
461 2d9a13f7 n.hoffmann
	@Override
462
	protected Control createExtendedContentArea(Composite parent) {
463 496d0049 Patric Plitzner
		String newWizardLinkText = getNewWizardLinkText();
464
        if(newWizardLinkText != null){
465 ea781c57 n.hoffmann
			Link link = new Link(parent, SWT.NONE);
466 496d0049 Patric Plitzner
			link.setText(newWizardLinkText);
467 9a0f58cd n.hoffmann
			link.addSelectionListener(getNewWizardLinkSelectionListener());
468 ea781c57 n.hoffmann
			return link;
469
		}
470
		return null;
471 2d9a13f7 n.hoffmann
	}
472 22cb6038 Patric Plitzner
473 9a0f58cd n.hoffmann
	protected SelectionListener getNewWizardLinkSelectionListener(){
474
		return new SelectionAdapter() {
475 22cb6038 Patric Plitzner
476 9a0f58cd n.hoffmann
			/* (non-Javadoc)
477
			 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
478
			 */
479
			@Override
480
			public void widgetSelected(SelectionEvent e) {
481 c158c2cf Cherian Mathew
482 eaa9ba52 Patrick Plitzner
			    AbstractNewEntityWizard wizard = getNewEntityWizard(e.text);
483
			    if(wizard!=null){
484
			        wizard.init(null, null);
485
			        if(wizard.getEntity() != null) {
486
			            WizardDialog dialog = new WizardDialog(getShell(), wizard);
487
			            int status = dialog.open();
488
489
			            if (status == IStatus.OK) {
490
491
			                T entity = (T) wizard.getEntity();
492 757377b5 Katja Luther
			               // model.add(new UuidAndTitleCache<T>(entity.getUuid(), entity.getId(), getTitle(entity)));
493 eaa9ba52 Patrick Plitzner
			                refresh();
494
			                setPattern(entity);
495
			                getConversationHolder().bind();
496
			            }
497
			            //FIXME : Need to make sure this is a stable fix (ticket 3822)
498
			            getConversationHolder().commit();
499
			        }
500
			    }
501 9a0f58cd n.hoffmann
			}
502
		};
503
	}
504 22cb6038 Patric Plitzner
505 3be6ef3e n.hoffmann
	/**
506
	 * <p>getConversationHolder</p>
507
	 *
508
	 * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
509
	 */
510 496d0049 Patric Plitzner
	@Override
511 2d9a13f7 n.hoffmann
	public ConversationHolder getConversationHolder() {
512
		return conversation;
513
	}
514 22cb6038 Patric Plitzner
515 3be6ef3e n.hoffmann
	/** {@inheritDoc} */
516 496d0049 Patric Plitzner
	@Override
517 2d9a13f7 n.hoffmann
	public void update(CdmDataChangeMap changeEvents) {}
518 9ac72187 l.morris
519
	/**
520 22cb6038 Patric Plitzner
	 * Don't want to add for example a taxon or synonym to itself
521
	 * so filter the list to remove the taxon in question
522 28b3f4aa Andreas Kohlbecker
	 * (<code>cdmBaseToBeFiltered</code>)
523
	 * so it is not available in the filtered list.
524 9ac72187 l.morris
	 */
525
	private void filterExcludedObjects() {
526
		if (model != null && cdmBaseToBeFiltered != null) {
527 22cb6038 Patric Plitzner
528 9ac72187 l.morris
			UuidAndTitleCache uuidAndTitleCacheToRemove = null;
529 22cb6038 Patric Plitzner
530 9ac72187 l.morris
			for (UuidAndTitleCache uuidAndTitleCache : model){
531
				if ((cdmBaseToBeFiltered.getUuid()).equals(uuidAndTitleCache.getUuid())) {
532
					uuidAndTitleCacheToRemove = uuidAndTitleCache;
533 22cb6038 Patric Plitzner
				}
534 9ac72187 l.morris
			}
535
			model.remove(uuidAndTitleCacheToRemove);
536
		}
537
	}
538 729887cf n.hoffmann
}