Refresh selection dialog after widget creation to evaluate button states
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / selection / DescriptiveDataSetSelectionDialog.java
1 /**
2 * Copyright (C) 2014 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 package eu.etaxonomy.taxeditor.ui.dialog.selection;
10
11 import java.util.UUID;
12
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;
20
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;
27
28 /**
29 * @author pplitzner
30 * @date 11.03.2014
31 *
32 */
33 public class DescriptiveDataSetSelectionDialog extends
34 AbstractFilteredCdmResourceSelectionDialog<DescriptiveDataSet> {
35
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);
40 }
41
42 /**
43 * <p>Constructor for FilteredDerivedUnitSelectionDialog.</p>
44 */
45 protected DescriptiveDataSetSelectionDialog(Shell shell, String title,
46 boolean multi, String settings, DescriptiveDataSet cdmObject) {
47 super(shell, title, multi, settings, cdmObject);
48 }
49
50 /** {@inheritDoc} */
51 @Override
52 protected DescriptiveDataSet getPersistentObject(UUID uuid) {
53 Object object = CdmStore.getService(IDescriptiveDataSetService.class).load(uuid);
54
55 DescriptiveDataSet descriptiveDataSet = (DescriptiveDataSet) HibernateProxyHelper.deproxy(object);
56
57 if(descriptiveDataSet != null){
58 return descriptiveDataSet;
59 }
60 MessagingUtils.error(this.getClass(), "Selected element is not a descriptive data set", null);
61 return null;
62 }
63
64 /** {@inheritDoc} */
65 @Override
66 protected void callService(String pattern) {
67 model = CdmStore.getService(IDescriptiveDataSetService.class).getDescriptiveDataSetUuidAndTitleCache(limitOfInitialElements, pattern);
68 }
69
70 @Override
71 protected String getTitle(DescriptiveDataSet cdmObject) {
72 if(cdmObject!=null){
73 return cdmObject.getLabel();
74 }
75 return super.getTitle(cdmObject);
76 }
77
78 /** {@inheritDoc} */
79 @Override
80 protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
81 return null;
82 }
83
84 @Override
85 protected SelectionListener getNewWizardButtonSelectionListener(){
86 return new SelectionAdapter() {
87
88 @Override
89 public void widgetSelected(SelectionEvent e) {
90 Object source = e.getSource();
91 if (source instanceof Button){
92 Button sourceButton = (Button) source;
93 }
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());
100 refresh();
101 setPattern(descriptiveDataSet);
102 }
103 }
104 };
105 }
106
107 /** {@inheritDoc} */
108 @Override
109 protected String[] getNewWizardText() {
110 return new String[]{"Descriptive Data Set "};
111 }
112
113 }