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.Control;
|
20
|
import org.eclipse.swt.widgets.Shell;
|
21
|
import org.eclipse.swt.widgets.Text;
|
22
|
|
23
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
24
|
import eu.etaxonomy.cdm.api.service.IWorkingSetService;
|
25
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
26
|
import eu.etaxonomy.cdm.model.description.WorkingSet;
|
27
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
28
|
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
|
29
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
30
|
|
31
|
/**
|
32
|
* @author pplitzner
|
33
|
* @date 11.03.2014
|
34
|
*
|
35
|
*/
|
36
|
public class WorkingSetSelectionDialog extends
|
37
|
AbstractFilteredCdmResourceSelectionDialog<WorkingSet> {
|
38
|
|
39
|
public static WorkingSet select(Shell shell, ConversationHolder conversation, WorkingSet workingSet){
|
40
|
WorkingSetSelectionDialog dialog = new WorkingSetSelectionDialog(shell, conversation,
|
41
|
"Choose working set", false, WorkingSetSelectionDialog.class.getCanonicalName(), workingSet);
|
42
|
return getSelectionFromDialog(dialog);
|
43
|
}
|
44
|
|
45
|
/**
|
46
|
* <p>Constructor for FilteredDerivedUnitSelectionDialog.</p>
|
47
|
*/
|
48
|
protected WorkingSetSelectionDialog(Shell shell, ConversationHolder conversation, String title,
|
49
|
boolean multi, String settings, WorkingSet cdmObject) {
|
50
|
super(shell, conversation, title, multi, settings, cdmObject);
|
51
|
}
|
52
|
|
53
|
/** {@inheritDoc} */
|
54
|
@Override
|
55
|
protected WorkingSet getPersistentObject(UUID uuid) {
|
56
|
Object object = CdmStore.getService(IWorkingSetService.class).load(uuid);
|
57
|
|
58
|
WorkingSet workingSet = (WorkingSet) HibernateProxyHelper.deproxy(object);
|
59
|
|
60
|
if(workingSet != null){
|
61
|
return workingSet;
|
62
|
}
|
63
|
MessagingUtils.error(this.getClass(), "Selected element is not a working set", null);
|
64
|
return null;
|
65
|
}
|
66
|
|
67
|
/** {@inheritDoc} */
|
68
|
@Override
|
69
|
protected void search() {
|
70
|
Control control =getSearchField();
|
71
|
String pattern = null;
|
72
|
if (control != null){
|
73
|
pattern = ((Text)control).getText();
|
74
|
}
|
75
|
|
76
|
if (pattern == null || pattern.equals("?")){
|
77
|
model = CdmStore.getService(IWorkingSetService.class).getUuidAndTitleCache(null, null);
|
78
|
}else{
|
79
|
model = CdmStore.getService(IWorkingSetService.class).getUuidAndTitleCache(limitOfInitialElements, pattern);
|
80
|
}
|
81
|
}
|
82
|
|
83
|
@Override
|
84
|
protected String getTitle(WorkingSet cdmObject) {
|
85
|
if(cdmObject!=null){
|
86
|
return cdmObject.getLabel();
|
87
|
}
|
88
|
return super.getTitle(cdmObject);
|
89
|
}
|
90
|
|
91
|
/** {@inheritDoc} */
|
92
|
@Override
|
93
|
protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
|
94
|
return null;
|
95
|
}
|
96
|
|
97
|
@Override
|
98
|
protected SelectionListener getNewWizardButtonSelectionListener(){
|
99
|
return new SelectionAdapter() {
|
100
|
|
101
|
@Override
|
102
|
public void widgetSelected(SelectionEvent e) {
|
103
|
Object source = e.getSource();
|
104
|
if (source instanceof Button){
|
105
|
Button sourceButton = (Button) source;
|
106
|
}
|
107
|
InputDialog dialog = new InputDialog(getShell(), "Working set label", "Enter label for working set", null, null);
|
108
|
if (dialog.open() == Window.OK) {
|
109
|
// User clicked OK; update the label with the input
|
110
|
WorkingSet workingSet = WorkingSet.NewInstance();
|
111
|
CdmStore.getService(IWorkingSetService.class).merge(workingSet,true);
|
112
|
workingSet.setLabel(dialog.getValue());
|
113
|
refresh();
|
114
|
setPattern(workingSet);
|
115
|
}
|
116
|
}
|
117
|
};
|
118
|
}
|
119
|
|
120
|
/** {@inheritDoc} */
|
121
|
@Override
|
122
|
protected String[] getNewWizardText() {
|
123
|
return new String[]{"Working set "};
|
124
|
}
|
125
|
}
|