2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.ui
.element
;
12 import java
.net
.MalformedURLException
;
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
;
25 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
26 import eu
.etaxonomy
.taxeditor
.model
.ImageResources
;
27 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
28 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
32 * @created Dec 20, 2010
35 public class UriWithLabelElement
extends AbstractUriWithExceptionLabelElement
<URI
> {
37 private Button btnOpenBrowser
;
39 protected UriWithLabelElement(CdmFormFactory formFactory
, ICdmFormElement parentElement
, String labelString
,
40 URI initialObject
, Integer textHeight
, int style
) {
41 super(formFactory
, parentElement
, labelString
, initialObject
, textHeight
, style
);
49 protected void init(CdmFormFactory formFactory
, String labelString
, URI initialObject
, Integer textHeight
, int style
) {
52 initLabel(formFactory
, labelString
, false, getLayoutComposite());
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());
61 initText(formFactory
, null, textHeight
, null, false, style
, textAndButton
);
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() {
69 public void widgetSelected(SelectionEvent e
) {
70 String errorTitle
= Messages
.UriWithLabelElement_INVALID_URL
;
71 String errorText
= Messages
.UriWithLabelElement_COULD_NOT_OPEN_BROWSER
;
73 URI uri
= parseText();
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
));
86 MessagingUtils
.informationDialog(errorTitle
, new Status(IStatus
.WARNING
, TaxeditorStorePlugin
.PLUGIN_ID
, errorText
, null));
90 btnOpenBrowser
.setLayoutData(LayoutConstants
.RIGHT());
92 initExceptionLabel(getLayoutComposite(), formFactory
, initialObject
);
101 public void setParsedText(URI object
) {
103 super.setText(object
.toString());
111 protected URI
getParsedText() throws Exception
{
112 return new URI(super.getText());