b566f6db560677193bac50c028f2b1dbe44da962
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / propertysheet / reference / ReferenceSearchDescriptor.java
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.propertysheet.reference;
11
12 import org.eclipse.jface.viewers.CellEditor;
13 import org.eclipse.jface.viewers.DialogCellEditor;
14 import org.eclipse.swt.widgets.Composite;
15 import org.eclipse.swt.widgets.Control;
16 import org.eclipse.swt.widgets.Dialog;
17 import org.eclipse.ui.views.properties.PropertyDescriptor;
18
19 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
20
21 /**
22 * @author p.ciardelli
23 * @created 19.05.2008
24 * @version 1.0
25 */
26 abstract public class ReferenceSearchDescriptor extends PropertyDescriptor {
27
28 int searchType;
29
30 public ReferenceSearchDescriptor(Object id, String displayName, int searchType) {
31 super(id, displayName);
32
33 this.searchType = searchType;
34 }
35
36 public CellEditor createPropertyEditor(Composite parent) {
37 CellEditor editor = new DialogCellEditor(parent) {
38
39 protected Object openDialogBox(
40 Control cellEditorWindow) {
41 Dialog dialog = new ReferenceSearchDialog(cellEditorWindow.getShell(),
42 searchType);
43 Object value = ((ReferenceSearchDialog) dialog).open();
44 if (value instanceof ReferenceBase) {
45
46 ReferenceBase<?> reference = (ReferenceBase<?>) value;
47 saveReference(reference);
48 return new ReferencePropertySource(reference);
49 }
50 return null;
51 }
52 };
53 if (getValidator() != null) {
54 editor.setValidator(getValidator());
55 }
56 return editor;
57 }
58
59 abstract protected void saveReference(ReferenceBase<?> reference);
60 }