1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.ui.element;
|
12
|
|
13
|
import java.net.MalformedURLException;
|
14
|
import java.net.URI;
|
15
|
|
16
|
import org.eclipse.core.runtime.IStatus;
|
17
|
import org.eclipse.core.runtime.Status;
|
18
|
import org.eclipse.swt.SWT;
|
19
|
import org.eclipse.swt.events.SelectionAdapter;
|
20
|
import org.eclipse.swt.events.SelectionEvent;
|
21
|
import org.eclipse.swt.widgets.Button;
|
22
|
import org.eclipse.swt.widgets.Composite;
|
23
|
import org.eclipse.ui.PartInitException;
|
24
|
import org.eclipse.ui.PlatformUI;
|
25
|
|
26
|
import eu.etaxonomy.taxeditor.Messages;
|
27
|
import eu.etaxonomy.taxeditor.model.ImageResources;
|
28
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
29
|
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
|
30
|
|
31
|
/**
|
32
|
* @author n.hoffmann
|
33
|
* @created Dec 20, 2010
|
34
|
* @version 1.0
|
35
|
*/
|
36
|
public class UriWithLabelElement extends AbstractUriWithExceptionLabelElement<URI> {
|
37
|
|
38
|
private Button btnOpenBrowser;
|
39
|
|
40
|
protected UriWithLabelElement(CdmFormFactory formFactory, ICdmFormElement parentElement, String labelString,
|
41
|
URI initialObject, Integer textHeight, int style) {
|
42
|
super(formFactory, parentElement, labelString, initialObject, textHeight, style);
|
43
|
|
44
|
}
|
45
|
|
46
|
/**
|
47
|
* {@inheritDoc}
|
48
|
*/
|
49
|
@Override
|
50
|
protected void init(CdmFormFactory formFactory, String labelString, URI initialObject, Integer textHeight, int style) {
|
51
|
|
52
|
//label
|
53
|
initLabel(formFactory, labelString, false, getLayoutComposite());
|
54
|
|
55
|
//composite(uri + button)
|
56
|
Composite textAndButton = formFactory.createComposite(getLayoutComposite(), style);
|
57
|
addControl(textAndButton);
|
58
|
textAndButton.setLayout(LayoutConstants.LAYOUT(2, false));
|
59
|
textAndButton.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
|
60
|
|
61
|
//uri text
|
62
|
initText(formFactory, null, textHeight, null, false, style, textAndButton);
|
63
|
|
64
|
//button
|
65
|
btnOpenBrowser = formFactory.createButton(textAndButton, "", SWT.NONE); //$NON-NLS-1$
|
66
|
btnOpenBrowser.setImage(ImageResources.getImage(ImageResources.WEB));
|
67
|
btnOpenBrowser.setToolTipText(Messages.UriWithLabelElement_OPEN_EXTERNAL_BROWSER);
|
68
|
btnOpenBrowser.addSelectionListener(new SelectionAdapter() {
|
69
|
@Override
|
70
|
public void widgetSelected(SelectionEvent e) {
|
71
|
String errorTitle = Messages.UriWithLabelElement_INVALID_URL;
|
72
|
String errorText = Messages.UriWithLabelElement_COULD_NOT_OPEN_BROWSER;
|
73
|
|
74
|
URI uri = parseText();
|
75
|
if(uri!=null){
|
76
|
try {
|
77
|
PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(uri.toURL());
|
78
|
} catch (PartInitException pie) {
|
79
|
MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, pie));
|
80
|
} catch (MalformedURLException mue) {
|
81
|
MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, mue));
|
82
|
} catch (IllegalArgumentException iae) {
|
83
|
MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, iae));
|
84
|
}
|
85
|
}
|
86
|
else{
|
87
|
MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, null));
|
88
|
}
|
89
|
}
|
90
|
});
|
91
|
btnOpenBrowser.setLayoutData(LayoutConstants.RIGHT());
|
92
|
|
93
|
initExceptionLabel(getLayoutComposite(), formFactory, initialObject);
|
94
|
}
|
95
|
|
96
|
|
97
|
|
98
|
/**
|
99
|
* {@inheritDoc}
|
100
|
*/
|
101
|
@Override
|
102
|
public void setParsedText(URI object) {
|
103
|
if(object != null){
|
104
|
super.setText(object.toString());
|
105
|
}
|
106
|
}
|
107
|
|
108
|
/**
|
109
|
* {@inheritDoc}
|
110
|
*/
|
111
|
@Override
|
112
|
protected URI getParsedText() throws Exception {
|
113
|
return new URI(super.getText());
|
114
|
}
|
115
|
|
116
|
}
|