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