Moving editor sources back into trunk
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / propertysheet / name / NameRelationsPropertyDescriptor.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.name;
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.jface.window.Window;
16 import org.eclipse.jface.wizard.Wizard;
17 import org.eclipse.jface.wizard.WizardDialog;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.swt.widgets.Control;
20 import org.eclipse.ui.views.properties.PropertyDescriptor;
21
22 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
23 import eu.etaxonomy.taxeditor.editor.EditorUtil;
24 import eu.etaxonomy.taxeditor.propertysheet.namerelations.wizard.NameRelationsListWizard;
25
26 /**
27 * Property sheet descriptor that pops up a dialog window
28 * returning a set.
29 *
30 * @author p.ciardelli
31 * @created 19.05.2008
32 * @version 1.0
33 */
34 public class NameRelationsPropertyDescriptor extends PropertyDescriptor {
35 private static final Logger logger = Logger
36 .getLogger(NameRelationsPropertyDescriptor.class);
37
38 private TaxonNameBase name;
39
40 public NameRelationsPropertyDescriptor(Object id, String displayName, TaxonNameBase name) {
41 super(id, displayName);
42 this.name = name;
43 }
44
45 public CellEditor createPropertyEditor(Composite parent) {
46 CellEditor editor = new DialogCellEditor(parent) {
47
48 @Override
49 protected Object openDialogBox(
50 Control cellEditorWindow) {
51 Wizard wizard = new NameRelationsListWizard(name);
52 WizardDialog dialog = new WizardDialog(EditorUtil.getShell(), wizard);
53 dialog.create();
54 int returnCode = dialog.open();
55
56 if (returnCode == Window.OK) {
57 return new NameRelationsPropertySource(name, name.getNameRelations());
58 } else {
59 return null;
60 }
61
62 }
63 };
64 if (getValidator() != null) {
65 editor.setValidator(getValidator());
66 }
67 return editor;
68 }
69 }