1 |
c4c08e81
|
n.hoffmann
|
/**
|
2 |
|
|
* Copyright (C) 2007 EDIT
|
3 |
b48bc2d5
|
Patrick Plitzner
|
* European Distributed Institute of Taxonomy
|
4 |
c4c08e81
|
n.hoffmann
|
* http://www.e-taxonomy.eu
|
5 |
b48bc2d5
|
Patrick Plitzner
|
*
|
6 |
c4c08e81
|
n.hoffmann
|
* 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 |
78222507
|
n.hoffmann
|
package eu.etaxonomy.taxeditor.ui.element;
|
11 |
c4c08e81
|
n.hoffmann
|
|
12 |
a9b5194c
|
Patrick Plitzner
|
import java.net.MalformedURLException;
|
13 |
c4c08e81
|
n.hoffmann
|
import java.net.URI;
|
14 |
6504f35c
|
Patric Plitzner
|
|
15 |
24f5f2e8
|
Patrick Plitzner
|
import org.eclipse.core.runtime.IStatus;
|
16 |
|
|
import org.eclipse.core.runtime.Status;
|
17 |
191f2328
|
Patrick Plitzner
|
import org.eclipse.swt.SWT;
|
18 |
a9b5194c
|
Patrick Plitzner
|
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 |
a86dbf9a
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
26 |
a9b5194c
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.model.ImageResources;
|
27 |
24f5f2e8
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
28 |
|
|
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
|
29 |
78222507
|
n.hoffmann
|
|
30 |
c4c08e81
|
n.hoffmann
|
/**
|
31 |
|
|
* @author n.hoffmann
|
32 |
|
|
* @created Dec 20, 2010
|
33 |
|
|
* @version 1.0
|
34 |
|
|
*/
|
35 |
a45e3c4a
|
Patrick Plitzner
|
public class UriWithLabelElement extends AbstractUriWithExceptionLabelElement<URI> {
|
36 |
c4c08e81
|
n.hoffmann
|
|
37 |
a45e3c4a
|
Patrick Plitzner
|
private Button btnOpenBrowser;
|
38 |
191f2328
|
Patrick Plitzner
|
|
39 |
a45e3c4a
|
Patrick Plitzner
|
protected UriWithLabelElement(CdmFormFactory formFactory, ICdmFormElement parentElement, String labelString,
|
40 |
|
|
URI initialObject, Integer textHeight, int style) {
|
41 |
|
|
super(formFactory, parentElement, labelString, initialObject, textHeight, style);
|
42 |
a9b5194c
|
Patrick Plitzner
|
|
43 |
a45e3c4a
|
Patrick Plitzner
|
}
|
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 |
1fbf88c8
|
Patrick Plitzner
|
initLabel(formFactory, labelString, false, getLayoutComposite());
|
53 |
24f5f2e8
|
Patrick Plitzner
|
|
54 |
59aac23b
|
Patrick Plitzner
|
//composite(uri + button)
|
55 |
1fbf88c8
|
Patrick Plitzner
|
Composite textAndButton = formFactory.createComposite(getLayoutComposite(), style);
|
56 |
0320f89e
|
Patrick Plitzner
|
addControl(textAndButton);
|
57 |
1fbf88c8
|
Patrick Plitzner
|
textAndButton.setLayout(LayoutConstants.LAYOUT(2, false));
|
58 |
|
|
textAndButton.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
|
59 |
a9b5194c
|
Patrick Plitzner
|
|
60 |
59aac23b
|
Patrick Plitzner
|
//uri text
|
61 |
|
|
initText(formFactory, null, textHeight, null, false, style, textAndButton);
|
62 |
|
|
|
63 |
|
|
//button
|
64 |
a45e3c4a
|
Patrick Plitzner
|
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 |
a9b5194c
|
Patrick Plitzner
|
PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(uri.toURL());
|
77 |
24f5f2e8
|
Patrick Plitzner
|
} 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 |
a9b5194c
|
Patrick Plitzner
|
}
|
84 |
a45e3c4a
|
Patrick Plitzner
|
}
|
85 |
|
|
else{
|
86 |
|
|
MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, null));
|
87 |
|
|
}
|
88 |
|
|
}
|
89 |
a9b5194c
|
Patrick Plitzner
|
});
|
90 |
a45e3c4a
|
Patrick Plitzner
|
btnOpenBrowser.setLayoutData(LayoutConstants.RIGHT());
|
91 |
|
|
|
92 |
|
|
initExceptionLabel(getLayoutComposite(), formFactory, initialObject);
|
93 |
|
|
}
|
94 |
b48bc2d5
|
Patrick Plitzner
|
|
95 |
|
|
|
96 |
a45e3c4a
|
Patrick Plitzner
|
|
97 |
|
|
/**
|
98 |
|
|
* {@inheritDoc}
|
99 |
|
|
*/
|
100 |
|
|
@Override
|
101 |
|
|
public void setParsedText(URI object) {
|
102 |
|
|
if(object != null){
|
103 |
|
|
super.setText(object.toString());
|
104 |
191f2328
|
Patrick Plitzner
|
}
|
105 |
a45e3c4a
|
Patrick Plitzner
|
}
|
106 |
|
|
|
107 |
|
|
/**
|
108 |
|
|
* {@inheritDoc}
|
109 |
|
|
*/
|
110 |
|
|
@Override
|
111 |
|
|
protected URI getParsedText() throws Exception {
|
112 |
|
|
return new URI(super.getText());
|
113 |
|
|
}
|
114 |
b48bc2d5
|
Patrick Plitzner
|
|
115 |
c4c08e81
|
n.hoffmann
|
}
|