3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.ui
.element
;
13 import java
.net
.MalformedURLException
;
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
;
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
;
33 * @created Dec 20, 2010
36 public class UriWithLabelElement
extends AbstractUriWithExceptionLabelElement
<URI
> {
38 private Button btnOpenBrowser
;
40 protected UriWithLabelElement(CdmFormFactory formFactory
, ICdmFormElement parentElement
, String labelString
,
41 URI initialObject
, Integer textHeight
, int style
) {
42 super(formFactory
, parentElement
, labelString
, initialObject
, textHeight
, style
);
50 protected void init(CdmFormFactory formFactory
, String labelString
, URI initialObject
, Integer textHeight
, int style
) {
53 initLabel(formFactory
, labelString
, false, getLayoutComposite());
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());
62 initText(formFactory
, null, textHeight
, null, false, style
, textAndButton
);
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() {
70 public void widgetSelected(SelectionEvent e
) {
71 String errorTitle
= Messages
.UriWithLabelElement_INVALID_URL
;
72 String errorText
= Messages
.UriWithLabelElement_COULD_NOT_OPEN_BROWSER
;
74 URI uri
= parseText();
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
));
87 MessagingUtils
.informationDialog(errorTitle
, new Status(IStatus
.WARNING
, TaxeditorStorePlugin
.PLUGIN_ID
, errorText
, null));
91 btnOpenBrowser
.setLayoutData(LayoutConstants
.RIGHT());
93 initExceptionLabel(getLayoutComposite(), formFactory
, initialObject
);
102 public void setParsedText(URI object
) {
104 super.setText(object
.toString());
112 protected URI
getParsedText() throws Exception
{
113 return new URI(super.getText());