Did some code cleanup. Removed obsolete and deprecated classes.
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / dialogs / filteredSelection / FilteredNameSelectionDialog.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * 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 package eu.etaxonomy.taxeditor.dialogs.filteredSelection;
12
13 import java.util.UUID;
14
15 import org.apache.log4j.Logger;
16 import org.eclipse.jface.dialogs.InputDialog;
17 import org.eclipse.jface.window.Window;
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Control;
21 import org.eclipse.swt.widgets.Event;
22 import org.eclipse.swt.widgets.Link;
23 import org.eclipse.swt.widgets.Listener;
24 import org.eclipse.swt.widgets.Shell;
25
26 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
27 import eu.etaxonomy.taxeditor.parser.ParseHandler;
28 import eu.etaxonomy.taxeditor.store.CdmStore;
29
30 /**
31 * @author n.hoffmann
32 * @created 04.06.2009
33 * @version 1.0
34 */
35 public class FilteredNameSelectionDialog extends AbstractFilteredCdmResourceSelectionDialog<TaxonNameBase> {
36 private static final Logger logger = Logger
37 .getLogger(FilteredNameSelectionDialog.class);
38
39 /**
40 * Creates a filtered selection dialog to select a name.
41 *
42 * @param shell
43 * The shell for displaying this widget
44 * @param name
45 * A name that should be selected when the dialog opens
46 * @return
47 * A name object upon selection
48 */
49 public static TaxonNameBase selectName(Shell shell, TaxonNameBase name) {
50 FilteredNameSelectionDialog dialog = new FilteredNameSelectionDialog(shell,
51 "Choose a name", false, name);
52 return getSelectionFromDialog(dialog);
53 }
54
55 /**
56 * @param shell
57 * @param title
58 * @param name
59 */
60 protected FilteredNameSelectionDialog(Shell shell, String title, boolean multi, TaxonNameBase name) {
61 super(shell, title, multi, FilteredNameSelectionDialog.class.getCanonicalName(), name);
62 }
63
64 /* (non-Javadoc)
65 * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#createExtendedContentArea(org.eclipse.swt.widgets.Composite)
66 */
67 @Override
68 protected Control createExtendedContentArea(Composite parent) {
69 Link link = new Link(parent, SWT.NONE);
70 link.setText("Click <A>here</A> to create a new name.");
71 link.addListener (SWT.Selection, new Listener () {
72 public void handleEvent(Event event) {
73 // TODO replace this with a wizard
74
75 InputDialog dialog = new InputDialog(getShell(), "Create a name", "Enter new name", "", null);
76 if (dialog.open() == Window.OK) {
77
78 TaxonNameBase name = ParseHandler.quickParse(dialog.getValue());
79
80 addObjectToModel(name);
81 setPattern(name);
82 }
83 }
84 });
85 return link;
86 }
87
88 /* (non-Javadoc)
89 * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#getPersistentObject(java.util.UUID)
90 */
91 @Override
92 protected TaxonNameBase getPersistentObject(UUID cdmUuid) {
93 return CdmStore.getNameService().load(cdmUuid);
94 }
95
96 /* (non-Javadoc)
97 * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#initModel()
98 */
99 @Override
100 protected void initModel() {
101 model = CdmStore.getNameService().getUuidAndTitleCache();
102 }
103 }