Moving editor sources back into trunk
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / propertysheet / AnnotationsPropertyDescriptor.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;
11
12 import java.util.Set;
13
14 import org.apache.log4j.Logger;
15 import org.eclipse.jface.viewers.CellEditor;
16 import org.eclipse.jface.viewers.DialogCellEditor;
17 import org.eclipse.swt.widgets.Composite;
18 import org.eclipse.swt.widgets.Control;
19 import org.eclipse.swt.widgets.Dialog;
20 import org.eclipse.ui.views.properties.PropertyDescriptor;
21
22 import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
23 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
24
25 /**
26 * Property sheet descriptor that pops up a dialog window
27 * returning a set.
28 *
29 * @author p.ciardelli
30 * @created 19.05.2008
31 * @version 1.0
32 */
33 abstract public class AnnotationsPropertyDescriptor extends PropertyDescriptor {
34 private static final Logger logger = Logger
35 .getLogger(AnnotationsPropertyDescriptor.class);
36
37 private AnnotatableEntity entity;
38
39 public AnnotationsPropertyDescriptor(Object id, String displayName, AnnotatableEntity entity) {
40 super(id, displayName);
41 this.entity = entity;
42 }
43
44 public CellEditor createPropertyEditor(Composite parent) {
45 CellEditor editor = new DialogCellEditor(parent) {
46
47 protected Dialog dialog;
48
49 @Override
50 protected Object openDialogBox(
51 Control cellEditorWindow) {
52 dialog = new AnnotationsDialog(cellEditorWindow.getShell(), entity);
53 Object value = ((AnnotationsDialog) dialog).open();
54 if (value instanceof Set) {
55
56 Set annotations = (Set) value;
57 saveAnnotations(annotations);
58 return new AnnotationPropertySource(annotations);
59 }
60 return null;
61 }
62
63 };
64 if (getValidator() != null) {
65 editor.setValidator(getValidator());
66 }
67 return editor;
68 }
69
70 abstract protected void saveAnnotations(Set set);
71 }