1
|
/**
|
2
|
* Copyright (C) 2019 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.element;
|
10
|
|
11
|
import org.eclipse.core.runtime.IStatus;
|
12
|
import org.eclipse.core.runtime.Status;
|
13
|
import org.eclipse.swt.SWT;
|
14
|
import org.eclipse.swt.events.SelectionAdapter;
|
15
|
import org.eclipse.swt.events.SelectionEvent;
|
16
|
import org.eclipse.swt.widgets.Button;
|
17
|
import org.eclipse.swt.widgets.Composite;
|
18
|
|
19
|
import eu.etaxonomy.cdm.model.agent.ORCID;
|
20
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
21
|
import eu.etaxonomy.taxeditor.model.ImageResources;
|
22
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
23
|
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
|
24
|
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
|
25
|
|
26
|
/**
|
27
|
* @author k.luther
|
28
|
* @since 11.11.2019
|
29
|
*/
|
30
|
public class OrcidWithLabelElement extends AbstractUriWithExceptionLabelElement<ORCID> {
|
31
|
|
32
|
private Button btnOpenBrowser;
|
33
|
|
34
|
/**
|
35
|
* @param formFactory
|
36
|
* @param parentElement
|
37
|
* @param labelString
|
38
|
* @param initialObject
|
39
|
* @param textHeight
|
40
|
* @param style
|
41
|
*/
|
42
|
protected OrcidWithLabelElement(CdmFormFactory formFactory, ICdmFormElement parentElement, String labelString,
|
43
|
ORCID initialObject, Integer textHeight, int style) {
|
44
|
super(formFactory, parentElement, labelString, initialObject, textHeight, style);
|
45
|
exceptionString = Messages.OrcidWithLabelElement_ORCID_NOT_SAVED;
|
46
|
}
|
47
|
|
48
|
/**
|
49
|
* {@inheritDoc}
|
50
|
*/
|
51
|
@Override
|
52
|
public void setParsedText(ORCID object) {
|
53
|
if(object != null){
|
54
|
super.setText(object.toString());
|
55
|
}
|
56
|
|
57
|
}
|
58
|
|
59
|
/**
|
60
|
* {@inheritDoc}
|
61
|
*/
|
62
|
@Override
|
63
|
protected ORCID getParsedText() throws Exception {
|
64
|
String orcidText = super.getText();
|
65
|
if(orcidText!=null){
|
66
|
return ORCID.fromString(super.getText());
|
67
|
}
|
68
|
return null;
|
69
|
}
|
70
|
|
71
|
@Override
|
72
|
protected void init(CdmFormFactory formFactory, String labelString, ORCID initialObject, Integer textHeight, int style) {
|
73
|
|
74
|
//label
|
75
|
initLabel(formFactory, labelString, false, getLayoutComposite());
|
76
|
Composite textAndButton = formFactory.createComposite(getLayoutComposite(), style);
|
77
|
addControl(textAndButton);
|
78
|
textAndButton.setLayout(LayoutConstants.LAYOUT(2, false));
|
79
|
textAndButton.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
|
80
|
|
81
|
//uri text
|
82
|
initText(formFactory, null, textHeight, null, false, style, textAndButton);
|
83
|
setParsedText(initialObject);
|
84
|
//button
|
85
|
btnOpenBrowser = formFactory.createButton(textAndButton, "", SWT.NONE); //$NON-NLS-1$
|
86
|
btnOpenBrowser.setImage(ImageResources.getImage(ImageResources.WEB));
|
87
|
btnOpenBrowser.setToolTipText(Messages.UriWithLabelElement_OPEN_EXTERNAL_BROWSER);
|
88
|
btnOpenBrowser.addSelectionListener(new SelectionAdapter() {
|
89
|
@Override
|
90
|
public void widgetSelected(SelectionEvent e) {
|
91
|
String errorTitle = Messages.UriWithLabelElement_INVALID_URL;
|
92
|
String errorText = Messages.UriWithLabelElement_COULD_NOT_OPEN_BROWSER;
|
93
|
|
94
|
ORCID orcid = parseText();
|
95
|
if(orcid!=null){
|
96
|
try {
|
97
|
WorkbenchUtility.openWebpage(orcid.asURI());
|
98
|
} catch (IllegalArgumentException iae) {
|
99
|
MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, iae));
|
100
|
}
|
101
|
}
|
102
|
else{
|
103
|
MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, null));
|
104
|
}
|
105
|
}
|
106
|
});
|
107
|
btnOpenBrowser.setLayoutData(LayoutConstants.RIGHT());
|
108
|
initExceptionLabel(getLayoutComposite(), formFactory);
|
109
|
}
|
110
|
|
111
|
|
112
|
// @Override
|
113
|
// public ORCID parseText(){
|
114
|
// try {
|
115
|
// labelException.setText("");
|
116
|
// labelException.setFont(JFaceResources.getFontRegistry().get(JFaceResources.DEFAULT_FONT));
|
117
|
// labelException.setForeground(getPersistentBackground());
|
118
|
// return getParsedText();
|
119
|
// } catch (Exception e) {
|
120
|
// labelException.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
|
121
|
// labelException.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
|
122
|
// labelException.setText(Messages.OrcidWithLabelElement_ORCID_NOT_SAVED + " " + e.getLocalizedMessage());
|
123
|
// labelException.requestLayout();
|
124
|
// return null;
|
125
|
// }
|
126
|
// }
|
127
|
|
128
|
}
|
129
|
|