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.element;
|
11
|
|
12
|
import java.io.IOException;
|
13
|
import java.net.URI;
|
14
|
|
15
|
import org.eclipse.core.runtime.IStatus;
|
16
|
import org.eclipse.core.runtime.Status;
|
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;
|
21
|
import org.eclipse.swt.widgets.Composite;
|
22
|
|
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;
|
28
|
|
29
|
/**
|
30
|
* @author n.hoffmann
|
31
|
* @created Dec 20, 2010
|
32
|
* @version 1.0
|
33
|
*/
|
34
|
public class UriWithLabelElement extends AbstractUriWithExceptionLabelElement<URI> {
|
35
|
|
36
|
private Button btnOpenBrowser;
|
37
|
|
38
|
protected UriWithLabelElement(CdmFormFactory formFactory, ICdmFormElement parentElement, String labelString,
|
39
|
URI initialObject, Integer textHeight, int style) {
|
40
|
super(formFactory, parentElement, labelString, initialObject, textHeight, style);
|
41
|
|
42
|
}
|
43
|
|
44
|
/**
|
45
|
* {@inheritDoc}
|
46
|
*/
|
47
|
@Override
|
48
|
protected void init(CdmFormFactory formFactory, String labelString, URI initialObject, Integer textHeight, int style) {
|
49
|
|
50
|
//label
|
51
|
initLabel(formFactory, labelString, false, getLayoutComposite());
|
52
|
|
53
|
//composite(uri + button)
|
54
|
Composite textAndButton = formFactory.createComposite(getLayoutComposite(), style);
|
55
|
addControl(textAndButton);
|
56
|
textAndButton.setLayout(LayoutConstants.LAYOUT(2, false));
|
57
|
textAndButton.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
|
58
|
|
59
|
//uri text
|
60
|
initText(formFactory, null, textHeight, null, false, style, textAndButton);
|
61
|
|
62
|
//button
|
63
|
btnOpenBrowser = formFactory.createButton(textAndButton, "", SWT.NONE); //$NON-NLS-1$
|
64
|
btnOpenBrowser.setImage(ImageResources.getImage(ImageResources.WEB));
|
65
|
btnOpenBrowser.setToolTipText(Messages.UriWithLabelElement_OPEN_EXTERNAL_BROWSER);
|
66
|
btnOpenBrowser.addSelectionListener(new SelectionAdapter() {
|
67
|
@Override
|
68
|
public void widgetSelected(SelectionEvent e) {
|
69
|
String errorTitle = Messages.UriWithLabelElement_INVALID_URL;
|
70
|
String errorText = Messages.UriWithLabelElement_COULD_NOT_OPEN_BROWSER;
|
71
|
|
72
|
URI uri = parseText();
|
73
|
if(uri!=null){
|
74
|
try {
|
75
|
WorkbenchUtility.openWebpage(uri.toURL());
|
76
|
} catch (IOException pie) {
|
77
|
MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, pie));
|
78
|
} catch (IllegalArgumentException iae) {
|
79
|
MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, iae));
|
80
|
}
|
81
|
}
|
82
|
else{
|
83
|
MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, null));
|
84
|
}
|
85
|
}
|
86
|
});
|
87
|
btnOpenBrowser.setLayoutData(LayoutConstants.RIGHT());
|
88
|
|
89
|
initExceptionLabel(getLayoutComposite(), formFactory, initialObject);
|
90
|
}
|
91
|
|
92
|
|
93
|
|
94
|
|
95
|
/**
|
96
|
* {@inheritDoc}
|
97
|
*/
|
98
|
@Override
|
99
|
public void setParsedText(URI object) {
|
100
|
if(object != null){
|
101
|
super.setText(object.toString());
|
102
|
}
|
103
|
}
|
104
|
|
105
|
/**
|
106
|
* {@inheritDoc}
|
107
|
*/
|
108
|
@Override
|
109
|
protected URI getParsedText() throws Exception {
|
110
|
return new URI(super.getText());
|
111
|
}
|
112
|
|
113
|
}
|