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