10 |
10 |
|
11 |
11 |
|
12 |
12 |
import java.awt.Toolkit;
|
|
13 |
import java.net.URL;
|
13 |
14 |
|
14 |
15 |
import javax.swing.event.DocumentEvent;
|
15 |
16 |
|
16 |
17 |
import org.apache.commons.lang.StringUtils;
|
|
18 |
import org.eclipse.jface.resource.JFaceResources;
|
17 |
19 |
import org.eclipse.swt.SWT;
|
|
20 |
import org.eclipse.swt.events.ModifyEvent;
|
|
21 |
import org.eclipse.swt.events.ModifyListener;
|
18 |
22 |
import org.eclipse.swt.events.MouseEvent;
|
19 |
23 |
import org.eclipse.swt.events.MouseListener;
|
20 |
24 |
import org.eclipse.swt.graphics.Rectangle;
|
21 |
25 |
import org.eclipse.swt.layout.GridData;
|
22 |
26 |
import org.eclipse.swt.widgets.Button;
|
23 |
27 |
import org.eclipse.swt.widgets.Composite;
|
|
28 |
import org.eclipse.swt.widgets.Display;
|
|
29 |
import org.eclipse.swt.widgets.Label;
|
24 |
30 |
import org.eclipse.swt.widgets.List;
|
25 |
31 |
import org.eclipse.swt.widgets.Text;
|
26 |
32 |
|
27 |
33 |
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
|
28 |
34 |
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
|
29 |
35 |
import eu.etaxonomy.taxeditor.l10n.Messages;
|
|
36 |
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
|
30 |
37 |
|
31 |
38 |
|
32 |
39 |
/**
|
... | ... | |
34 |
41 |
* @date 20.04.2017
|
35 |
42 |
*
|
36 |
43 |
*/
|
37 |
|
public class ListComponent
|
|
44 |
public class ListComponent implements ModifyListener
|
38 |
45 |
{
|
39 |
46 |
private List list;
|
40 |
47 |
|
... | ... | |
43 |
50 |
private static final String noProvider = Messages.ListComponent_NO_PROVIDER_AVAILABLE;
|
44 |
51 |
private Button removeButton;
|
45 |
52 |
private Text providerURI;
|
|
53 |
protected Label labelException;
|
46 |
54 |
boolean isAdmin = false;
|
|
55 |
CdmPreferencePage preferencePage;
|
47 |
56 |
|
48 |
57 |
|
49 |
|
public ListComponent(Composite parent, int style, boolean isAdmin) {
|
|
58 |
public ListComponent(Composite parent, int style, boolean isAdmin, CdmPreferencePage parentPage) {
|
50 |
59 |
this.isAdmin= isAdmin;
|
|
60 |
this.preferencePage = parentPage;
|
51 |
61 |
list = new List(parent, SWT.BORDER | SWT.V_SCROLL);
|
52 |
62 |
GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, true, 2, 3);
|
53 |
63 |
gridData.grabExcessHorizontalSpace = true;
|
... | ... | |
58 |
68 |
|
59 |
69 |
CdmPreference providerListPreference = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.BioCaseProvider);
|
60 |
70 |
String allProviderString = ""; //$NON-NLS-1$
|
61 |
|
if (!isAdmin && providerListPreference.isAllowOverride()){
|
|
71 |
if (!isAdmin && (providerListPreference != null && providerListPreference.isAllowOverride())){
|
62 |
72 |
allProviderString = PreferencesUtil.getStringValue(PreferencePredicate.BioCaseProvider.getKey(), true);
|
63 |
73 |
}else{
|
64 |
74 |
if (providerListPreference != null){
|
... | ... | |
94 |
104 |
dataProviderUri.horizontalAlignment = GridData.FILL;
|
95 |
105 |
dataProviderUri.horizontalSpan = 3;
|
96 |
106 |
providerURI.setLayoutData(dataProviderUri);
|
|
107 |
providerURI.addModifyListener(this);
|
|
108 |
labelException = new Label(parent, SWT.NULL);
|
|
109 |
labelException.setText("");
|
|
110 |
|
|
111 |
|
|
112 |
labelException.setLayoutData(dataProviderUri);
|
97 |
113 |
|
98 |
114 |
Button addButton = new Button(parent, SWT.NULL);
|
99 |
115 |
AddListener addListener = new AddListener(addButton);
|
... | ... | |
135 |
151 |
}
|
136 |
152 |
|
137 |
153 |
list.setSelection(index-1);
|
138 |
|
|
|
154 |
preferencePage.setApply(true);
|
139 |
155 |
|
140 |
156 |
}
|
141 |
157 |
}
|
... | ... | |
217 |
233 |
String name = providerURI.getText();
|
218 |
234 |
|
219 |
235 |
//User didn't type in a unique name...
|
220 |
|
if (name.equals("") || alreadyInList(name)) { //$NON-NLS-1$
|
|
236 |
if (name.equals("") || alreadyInList(name) || !StringUtils.isBlank(labelException.getText())) { //$NON-NLS-1$
|
221 |
237 |
Toolkit.getDefaultToolkit().beep();
|
222 |
238 |
providerURI.selectAll();
|
223 |
239 |
return;
|
... | ... | |
245 |
261 |
//Select the new item
|
246 |
262 |
|
247 |
263 |
providerURI.setText(""); //$NON-NLS-1$
|
248 |
|
|
|
264 |
preferencePage.setApply(true);
|
249 |
265 |
}
|
250 |
266 |
}
|
251 |
267 |
|
... | ... | |
268 |
284 |
}
|
269 |
285 |
|
270 |
286 |
|
|
287 |
@Override
|
|
288 |
public void modifyText(ModifyEvent e) {
|
|
289 |
if(e.widget==providerURI){
|
|
290 |
Text text = (Text) e.widget;
|
|
291 |
boolean hasControlCharacters = false;
|
|
292 |
String textString = text.getText();
|
|
293 |
int stringLength = textString.length();
|
|
294 |
for (int i = 0; i < stringLength; i++) {
|
|
295 |
if (Character.isISOControl(textString.charAt(i))) {
|
|
296 |
hasControlCharacters = true;
|
|
297 |
break;
|
|
298 |
}
|
|
299 |
}
|
|
300 |
|
|
301 |
//remove control character such as line breaks etc.
|
|
302 |
try {
|
|
303 |
getParsedText();
|
|
304 |
labelException.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
|
|
305 |
labelException.setForeground(Display.getCurrent().getSystemColor(SWT.NULL));
|
|
306 |
labelException.setText("");
|
|
307 |
} catch (Exception exception) {
|
|
308 |
labelException.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
|
|
309 |
labelException.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
|
|
310 |
labelException.setText(Messages.UriWithLabelElement_URL_NOT_SAVED+exception.getLocalizedMessage());
|
|
311 |
}
|
|
312 |
}
|
|
313 |
|
|
314 |
|
|
315 |
}
|
|
316 |
|
|
317 |
|
|
318 |
protected URL getParsedText() throws Exception {
|
|
319 |
String uriText = providerURI.getText();
|
|
320 |
if(!StringUtils.isBlank(uriText)){
|
|
321 |
return new URL(providerURI.getText());
|
|
322 |
}
|
|
323 |
return null;
|
|
324 |
}
|
|
325 |
|
|
326 |
|
271 |
327 |
|
272 |
328 |
}
|
273 |
329 |
|
ref #8385: enable apply button when provider added or removed from preference