3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.dialogs
.filteredSelection
;
13 import java
.util
.UUID
;
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
;
26 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
27 import eu
.etaxonomy
.taxeditor
.parser
.ParseHandler
;
28 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
35 public class FilteredNameSelectionDialog
extends AbstractFilteredCdmResourceSelectionDialog
<TaxonNameBase
> {
36 private static final Logger logger
= Logger
37 .getLogger(FilteredNameSelectionDialog
.class);
40 * Creates a filtered selection dialog to select a name.
43 * The shell for displaying this widget
45 * A name that should be selected when the dialog opens
47 * A name object upon selection
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
);
60 protected FilteredNameSelectionDialog(Shell shell
, String title
, boolean multi
, TaxonNameBase name
) {
61 super(shell
, title
, multi
, FilteredNameSelectionDialog
.class.getCanonicalName(), name
);
65 * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#createExtendedContentArea(org.eclipse.swt.widgets.Composite)
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
75 InputDialog dialog
= new InputDialog(getShell(), "Create a name", "Enter new name", "", null);
76 if (dialog
.open() == Window
.OK
) {
78 TaxonNameBase name
= ParseHandler
.quickParse(dialog
.getValue());
80 addObjectToModel(name
);
89 * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#getPersistentObject(java.util.UUID)
92 protected TaxonNameBase
getPersistentObject(UUID cdmUuid
) {
93 return CdmStore
.getNameService().load(cdmUuid
);
97 * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#initModel()
100 protected void initModel() {
101 model
= CdmStore
.getNameService().getUuidAndTitleCache();