Revision b7c97484
Added by Katja Luther almost 4 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/DoiWithLabelElement.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.taxeditor.ui.element; |
10 | 10 |
|
11 |
import java.io.IOException; |
|
12 |
import java.net.URL; |
|
13 |
|
|
14 |
import org.eclipse.core.runtime.IStatus; |
|
15 |
import org.eclipse.core.runtime.Status; |
|
11 | 16 |
import org.eclipse.jface.resource.JFaceResources; |
12 | 17 |
import org.eclipse.swt.SWT; |
18 |
import org.eclipse.swt.events.SelectionAdapter; |
|
19 |
import org.eclipse.swt.events.SelectionEvent; |
|
20 |
import org.eclipse.swt.widgets.Button; |
|
13 | 21 |
import org.eclipse.swt.widgets.Composite; |
14 | 22 |
import org.eclipse.swt.widgets.Display; |
15 | 23 |
import org.eclipse.ui.forms.widgets.TableWrapLayout; |
16 | 24 |
|
17 | 25 |
import eu.etaxonomy.cdm.common.DOI; |
18 | 26 |
import eu.etaxonomy.taxeditor.l10n.Messages; |
27 |
import eu.etaxonomy.taxeditor.model.ImageResources; |
|
28 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
|
29 |
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin; |
|
30 |
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility; |
|
19 | 31 |
|
20 | 32 |
/** |
21 | 33 |
* @author k.luther |
... | ... | |
24 | 36 |
*/ |
25 | 37 |
public class DoiWithLabelElement extends AbstractUriWithExceptionLabelElement<DOI> { |
26 | 38 |
|
39 |
private Button btnOpenBrowser; |
|
40 |
|
|
27 | 41 |
/** |
28 | 42 |
* @param formFactory |
29 | 43 |
* @param parentElement |
... | ... | |
68 | 82 |
initLabel(formFactory, labelString, false, getLayoutComposite()); |
69 | 83 |
//uri text |
70 | 84 |
initText(formFactory, null, textHeight, null, false, style, getLayoutComposite()); |
85 |
|
|
86 |
Composite textAndButton = formFactory.createComposite(getLayoutComposite(), style); |
|
87 |
addControl(textAndButton); |
|
88 |
textAndButton.setLayout(LayoutConstants.LAYOUT(2, false)); |
|
89 |
textAndButton.setLayoutData(LayoutConstants.FILL_HORIZONTALLY()); |
|
90 |
//button |
|
91 |
btnOpenBrowser = formFactory.createButton(textAndButton, "", SWT.NONE); //$NON-NLS-1$ |
|
92 |
btnOpenBrowser.setImage(ImageResources.getImage(ImageResources.WEB)); |
|
93 |
btnOpenBrowser.setToolTipText(Messages.UriWithLabelElement_OPEN_EXTERNAL_BROWSER); |
|
94 |
btnOpenBrowser.addSelectionListener(new SelectionAdapter() { |
|
95 |
@Override |
|
96 |
public void widgetSelected(SelectionEvent e) { |
|
97 |
String errorTitle = Messages.UriWithLabelElement_INVALID_URL; |
|
98 |
String errorText = Messages.UriWithLabelElement_COULD_NOT_OPEN_BROWSER; |
|
99 |
|
|
100 |
DOI doi= parseText(); |
|
101 |
if(doi!=null){ |
|
102 |
try { |
|
103 |
WorkbenchUtility.openWebpage(new URL(doi.asURI())); |
|
104 |
} catch (IOException pie) { |
|
105 |
MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, pie)); |
|
106 |
} catch (IllegalArgumentException iae) { |
|
107 |
MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, iae)); |
|
108 |
} |
|
109 |
} |
|
110 |
else{ |
|
111 |
MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, null)); |
|
112 |
} |
|
113 |
} |
|
114 |
}); |
|
115 |
btnOpenBrowser.setLayoutData(LayoutConstants.RIGHT()); |
|
71 | 116 |
initExceptionLabel(getLayoutComposite(), formFactory, initialObject); |
72 | 117 |
} |
73 | 118 |
|
Also available in: Unified diff
fix #8988: add browse button to doi field