2 * Copyright (C) 2014 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
;
11 import java
.util
.UUID
;
13 import org
.eclipse
.jface
.dialogs
.InputDialog
;
14 import org
.eclipse
.jface
.window
.Window
;
15 import org
.eclipse
.swt
.events
.SelectionAdapter
;
16 import org
.eclipse
.swt
.events
.SelectionEvent
;
17 import org
.eclipse
.swt
.events
.SelectionListener
;
18 import org
.eclipse
.swt
.widgets
.Button
;
19 import org
.eclipse
.swt
.widgets
.Shell
;
21 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptiveDataSetService
;
22 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
23 import eu
.etaxonomy
.cdm
.model
.description
.DescriptiveDataSet
;
24 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
25 import eu
.etaxonomy
.taxeditor
.newWizard
.AbstractNewEntityWizard
;
26 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
33 public class DescriptiveDataSetSelectionDialog
extends
34 AbstractFilteredCdmResourceSelectionDialog
<DescriptiveDataSet
> {
36 public static DescriptiveDataSet
select(Shell shell
, DescriptiveDataSet descriptiveDataSet
){
37 DescriptiveDataSetSelectionDialog dialog
= new DescriptiveDataSetSelectionDialog(shell
,
38 "Choose descriptive data set", false, DescriptiveDataSetSelectionDialog
.class.getCanonicalName(), descriptiveDataSet
);
39 return getSelectionFromDialog(dialog
);
43 * <p>Constructor for FilteredDerivedUnitSelectionDialog.</p>
45 protected DescriptiveDataSetSelectionDialog(Shell shell
, String title
,
46 boolean multi
, String settings
, DescriptiveDataSet cdmObject
) {
47 super(shell
, title
, multi
, settings
, cdmObject
);
52 protected DescriptiveDataSet
getPersistentObject(UUID uuid
) {
53 Object object
= CdmStore
.getService(IDescriptiveDataSetService
.class).load(uuid
);
55 DescriptiveDataSet descriptiveDataSet
= (DescriptiveDataSet
) HibernateProxyHelper
.deproxy(object
);
57 if(descriptiveDataSet
!= null){
58 return descriptiveDataSet
;
60 MessagingUtils
.error(this.getClass(), "Selected element is not a descriptive data set", null);
66 protected void callService(String pattern
) {
67 model
= CdmStore
.getService(IDescriptiveDataSetService
.class).getDescriptiveDataSetUuidAndTitleCache(limitOfInitialElements
, pattern
);
71 protected String
getTitle(DescriptiveDataSet cdmObject
) {
73 return cdmObject
.getLabel();
75 return super.getTitle(cdmObject
);
80 protected AbstractNewEntityWizard
getNewEntityWizard(String parameter
) {
85 protected SelectionListener
getNewWizardButtonSelectionListener(){
86 return new SelectionAdapter() {
89 public void widgetSelected(SelectionEvent e
) {
90 Object source
= e
.getSource();
91 if (source
instanceof Button
){
92 Button sourceButton
= (Button
) source
;
94 InputDialog dialog
= new InputDialog(getShell(), "Descriptive Data Set label", "Enter label for descriptive data set", null, null);
95 if (dialog
.open() == Window
.OK
) {
96 // User clicked OK; update the label with the input
97 DescriptiveDataSet descriptiveDataSet
= DescriptiveDataSet
.NewInstance();
98 CdmStore
.getService(IDescriptiveDataSetService
.class).merge(descriptiveDataSet
,true);
99 descriptiveDataSet
.setLabel(dialog
.getValue());
101 setPattern(descriptiveDataSet
);
109 protected String
[] getNewWizardText() {
110 return new String
[]{"Descriptive Data Set "};