Revision 2ab321a1
Added by Katja Luther over 3 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/OrcidWithLabelElement.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.taxeditor.ui.element; |
10 | 10 |
|
11 |
import org.eclipse.core.runtime.IStatus; |
|
12 |
import org.eclipse.core.runtime.Status; |
|
11 | 13 |
import org.eclipse.jface.resource.JFaceResources; |
12 | 14 |
import org.eclipse.swt.SWT; |
15 |
import org.eclipse.swt.events.SelectionAdapter; |
|
16 |
import org.eclipse.swt.events.SelectionEvent; |
|
17 |
import org.eclipse.swt.widgets.Button; |
|
13 | 18 |
import org.eclipse.swt.widgets.Composite; |
14 | 19 |
import org.eclipse.swt.widgets.Display; |
15 | 20 |
import org.eclipse.ui.forms.widgets.TableWrapLayout; |
16 | 21 |
|
17 | 22 |
import eu.etaxonomy.cdm.model.agent.ORCID; |
18 | 23 |
import eu.etaxonomy.taxeditor.l10n.Messages; |
24 |
import eu.etaxonomy.taxeditor.model.ImageResources; |
|
25 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
|
26 |
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin; |
|
27 |
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility; |
|
19 | 28 |
|
20 | 29 |
/** |
21 | 30 |
* @author k.luther |
... | ... | |
23 | 32 |
*/ |
24 | 33 |
public class OrcidWithLabelElement extends AbstractUriWithExceptionLabelElement<ORCID> { |
25 | 34 |
|
35 |
private Button btnOpenBrowser; |
|
36 |
|
|
26 | 37 |
/** |
27 | 38 |
* @param formFactory |
28 | 39 |
* @param parentElement |
... | ... | |
65 | 76 |
|
66 | 77 |
//label |
67 | 78 |
initLabel(formFactory, labelString, false, getLayoutComposite()); |
79 |
Composite textAndButton = formFactory.createComposite(getLayoutComposite(), style); |
|
80 |
addControl(textAndButton); |
|
81 |
textAndButton.setLayout(LayoutConstants.LAYOUT(2, false)); |
|
82 |
textAndButton.setLayoutData(LayoutConstants.FILL_HORIZONTALLY()); |
|
83 |
|
|
68 | 84 |
//uri text |
69 |
initText(formFactory, null, textHeight, null, false, style, getLayoutComposite()); |
|
85 |
initText(formFactory, null, textHeight, null, false, style, textAndButton); |
|
86 |
//button |
|
87 |
btnOpenBrowser = formFactory.createButton(textAndButton, "", SWT.NONE); //$NON-NLS-1$ |
|
88 |
btnOpenBrowser.setImage(ImageResources.getImage(ImageResources.WEB)); |
|
89 |
btnOpenBrowser.setToolTipText(Messages.UriWithLabelElement_OPEN_EXTERNAL_BROWSER); |
|
90 |
btnOpenBrowser.addSelectionListener(new SelectionAdapter() { |
|
91 |
@Override |
|
92 |
public void widgetSelected(SelectionEvent e) { |
|
93 |
String errorTitle = Messages.UriWithLabelElement_INVALID_URL; |
|
94 |
String errorText = Messages.UriWithLabelElement_COULD_NOT_OPEN_BROWSER; |
|
95 |
|
|
96 |
ORCID orcid = parseText(); |
|
97 |
if(orcid!=null){ |
|
98 |
try { |
|
99 |
WorkbenchUtility.openWebpage(orcid.asURI()); |
|
100 |
} catch (IllegalArgumentException iae) { |
|
101 |
MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, iae)); |
|
102 |
} |
|
103 |
} |
|
104 |
else{ |
|
105 |
MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, null)); |
|
106 |
} |
|
107 |
} |
|
108 |
}); |
|
109 |
btnOpenBrowser.setLayoutData(LayoutConstants.RIGHT()); |
|
70 | 110 |
initExceptionLabel(getLayoutComposite(), formFactory, initialObject); |
71 | 111 |
} |
72 | 112 |
|
... | ... | |
86 | 126 |
@Override |
87 | 127 |
public ORCID parseText(){ |
88 | 128 |
try { |
129 |
labelException.setText(""); |
|
89 | 130 |
labelException.setFont(JFaceResources.getFontRegistry().get(JFaceResources.DEFAULT_FONT)); |
90 | 131 |
labelException.setForeground(getPersistentBackground()); |
91 | 132 |
return getParsedText(); |
Also available in: Unified diff
fix #9040: add open in browser button to orcid