1
|
/**
|
2
|
* Copyright (C) 2007 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
|
|
10
|
package eu.etaxonomy.taxeditor.ui.dialog.selection;
|
11
|
|
12
|
import java.util.UUID;
|
13
|
|
14
|
import org.eclipse.swt.widgets.Control;
|
15
|
import org.eclipse.swt.widgets.Shell;
|
16
|
import org.eclipse.swt.widgets.Text;
|
17
|
|
18
|
import eu.etaxonomy.cdm.api.service.IReferenceService;
|
19
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
20
|
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
|
21
|
import eu.etaxonomy.taxeditor.newWizard.NewReferenceWizard;
|
22
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
23
|
|
24
|
/**
|
25
|
* <p>FilteredReferenceSelectionDialog class.</p>
|
26
|
*
|
27
|
* @author n.hoffmann
|
28
|
* @created 04.06.2009
|
29
|
* @version 1.0
|
30
|
*/
|
31
|
public class ReferenceSelectionDialog extends AbstractFilteredCdmResourceSelectionDialog<Reference> {
|
32
|
|
33
|
protected static boolean isInReference = false;
|
34
|
private Reference currentReference;
|
35
|
|
36
|
/**
|
37
|
* <p>select</p>
|
38
|
*
|
39
|
* @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
|
40
|
* @param shell a {@link org.eclipse.swt.widgets.Shell} object.
|
41
|
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
42
|
* @return a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
|
43
|
*/
|
44
|
public static Reference select(Shell shell, //ConversationHolder conversation,
|
45
|
Reference reference, boolean isInReference) {
|
46
|
ReferenceSelectionDialog dialog = new ReferenceSelectionDialog(shell, //conversation,
|
47
|
"Choose a reference", false, reference, isInReference);
|
48
|
return getSelectionFromDialog(dialog);
|
49
|
}
|
50
|
|
51
|
/**
|
52
|
* <p>select</p>
|
53
|
*
|
54
|
* @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
|
55
|
* @param shell a {@link org.eclipse.swt.widgets.Shell} object.
|
56
|
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
57
|
* @return a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
|
58
|
*/
|
59
|
public static Reference select(Shell shell, //ConversationHolder conversation,
|
60
|
Reference reference) {
|
61
|
ReferenceSelectionDialog dialog = new ReferenceSelectionDialog(shell, //conversation,
|
62
|
"Choose a reference", false, reference);
|
63
|
return getSelectionFromDialog(dialog);
|
64
|
}
|
65
|
|
66
|
|
67
|
|
68
|
/**
|
69
|
* <p>Constructor for FilteredReferenceSelectionDialog.</p>
|
70
|
*
|
71
|
* @param shell a {@link org.eclipse.swt.widgets.Shell} object.
|
72
|
* @param title a {@link java.lang.String} object.
|
73
|
* @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
|
74
|
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
75
|
* @param multi a boolean.
|
76
|
*/
|
77
|
protected ReferenceSelectionDialog(Shell shell, //ConversationHolder conversation,
|
78
|
String title, boolean multi, Reference reference) {
|
79
|
super(shell, //conversation,
|
80
|
title, multi, ReferenceSelectionDialog.class.getCanonicalName(), null);
|
81
|
this.currentReference = reference;
|
82
|
|
83
|
|
84
|
}
|
85
|
|
86
|
|
87
|
|
88
|
|
89
|
/**
|
90
|
* <p>Constructor for FilteredReferenceSelectionDialog.</p>
|
91
|
*
|
92
|
* @param shell a {@link org.eclipse.swt.widgets.Shell} object.
|
93
|
* @param title a {@link java.lang.String} object.
|
94
|
* @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
|
95
|
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
96
|
* @param multi a boolean.
|
97
|
*/
|
98
|
protected ReferenceSelectionDialog(Shell shell, //ConversationHolder conversation,
|
99
|
String title, boolean multi, Reference reference, boolean isInReference) {
|
100
|
super(shell, //conversation,
|
101
|
title, multi, ReferenceSelectionDialog.class.getCanonicalName(), null);
|
102
|
this.isInReference = isInReference;
|
103
|
this.currentReference = reference;
|
104
|
|
105
|
}
|
106
|
|
107
|
|
108
|
/* (non-Javadoc)
|
109
|
* @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#getPersistentObject(java.util.UUID)
|
110
|
*/
|
111
|
/** {@inheritDoc} */
|
112
|
@Override
|
113
|
protected Reference getPersistentObject(UUID cdmUuid) {
|
114
|
return CdmStore.getService(IReferenceService.class).load(cdmUuid);
|
115
|
}
|
116
|
|
117
|
/* (non-Javadoc)
|
118
|
* @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#search
|
119
|
*/
|
120
|
/** {@inheritDoc} */
|
121
|
@Override
|
122
|
protected void search() {
|
123
|
Control control =getSearchField();
|
124
|
String pattern = null;
|
125
|
if (control != null){
|
126
|
pattern = ((Text)control).getText();
|
127
|
}
|
128
|
|
129
|
if (pattern == null || pattern.equals("?")){
|
130
|
if (isInReference && currentReference != null){
|
131
|
model = CdmStore.getService(IReferenceService.class).getUuidAndTitleCache(null,null,currentReference.getType());
|
132
|
}else{
|
133
|
model = CdmStore.getService(IReferenceService.class).getUuidAndTitleCache(null,null);
|
134
|
}
|
135
|
}else{
|
136
|
if (isInReference && currentReference != null){
|
137
|
model = CdmStore.getService(IReferenceService.class).getUuidAndTitleCache(limitOfInitialElements,pattern, currentReference.getType());
|
138
|
}else{
|
139
|
model = CdmStore.getService(IReferenceService.class).getUuidAndTitleCache(limitOfInitialElements,pattern);
|
140
|
}
|
141
|
}
|
142
|
}
|
143
|
|
144
|
|
145
|
/** {@inheritDoc} */
|
146
|
@Override
|
147
|
protected String getTitle(Reference cdmObject) {
|
148
|
if(cdmObject == null){
|
149
|
return "";
|
150
|
}else{
|
151
|
return super.getTitle(cdmObject);
|
152
|
}
|
153
|
// }else{
|
154
|
// return DefaultReferenceCacheStrategy.putAuthorToEndOfString(cdmObject.getTitleCache(), cdmObject.getAuthorship().getTitleCache());
|
155
|
// }
|
156
|
}
|
157
|
|
158
|
/** {@inheritDoc} */
|
159
|
@Override
|
160
|
protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
|
161
|
return new NewReferenceWizard();
|
162
|
}
|
163
|
|
164
|
/** {@inheritDoc} */
|
165
|
@Override
|
166
|
protected String[] getNewWizardText() {
|
167
|
return new String[]{"Reference "};
|
168
|
}
|
169
|
|
170
|
}
|