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
.swt
.widgets
.Display
;
24 import org
.eclipse
.swt
.widgets
.Label
;
25 import org
.eclipse
.swt
.widgets
.Layout
;
26 import org
.eclipse
.ui
.PartInitException
;
27 import org
.eclipse
.ui
.PlatformUI
;
28 import org
.eclipse
.ui
.forms
.widgets
.TableWrapLayout
;
30 import eu
.etaxonomy
.taxeditor
.model
.ImageResources
;
31 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
32 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
36 * @created Dec 20, 2010
39 public class UriWithLabelElement
extends TextWithLabelElement
{
41 private final Label labelException
;
42 private final Button btnOpenBrowser
;
43 private static final int NUM_COLUMNS
= 3;
45 protected UriWithLabelElement(CdmFormFactory formFactory
,
46 ICdmFormElement parentElement
, String labelString
,
47 URI initialUri
, Integer textHeight
, int style
) {
48 super(formFactory
, parentElement
, false);
50 Layout parentLayout
= getLayoutComposite().getLayout();
51 int parentNumColumns
= 2;
52 if(parentLayout
instanceof TableWrapLayout
){
53 parentNumColumns
= ((TableWrapLayout
)parentLayout
).numColumns
;
55 Composite layoutComposite
= formFactory
.createComposite(getLayoutComposite());
56 addControl(layoutComposite
);
58 layoutComposite
.setLayout(LayoutConstants
.LAYOUT(3, false));
59 layoutComposite
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(parentNumColumns
, 1));
61 init(formFactory
, labelString
, null, textHeight
, null, false, style
, layoutComposite
);
63 btnOpenBrowser
= formFactory
.createButton(layoutComposite
, "", SWT
.NONE
);
64 btnOpenBrowser
.setImage(ImageResources
.getImage(ImageResources
.ADD_CHILD_TAXON_ICON
));
65 btnOpenBrowser
.setToolTipText("Open in external browser");
66 btnOpenBrowser
.addSelectionListener(new SelectionAdapter() {
68 public void widgetSelected(SelectionEvent e
) {
69 String errorTitle
= "Invalid URL";
70 String errorText
= "Could not open external browser. URL is invalid";
75 PlatformUI
.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(uri
.toURL());
76 } catch (PartInitException pie
) {
77 MessagingUtils
.informationDialog(errorTitle
, new Status(IStatus
.WARNING
, TaxeditorStorePlugin
.PLUGIN_ID
, errorText
, pie
));
78 } catch (MalformedURLException mue
) {
79 MessagingUtils
.informationDialog(errorTitle
, new Status(IStatus
.WARNING
, TaxeditorStorePlugin
.PLUGIN_ID
, errorText
, mue
));
80 } catch (IllegalArgumentException iae
) {
81 MessagingUtils
.informationDialog(errorTitle
, new Status(IStatus
.WARNING
, TaxeditorStorePlugin
.PLUGIN_ID
, errorText
, iae
));
86 btnOpenBrowser
.setLayoutData(LayoutConstants
.RIGHT());
88 labelException
= formFactory
.createLabel(layoutComposite
, "", SWT
.WRAP
);
89 labelException
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(NUM_COLUMNS
, 1));
90 addControl(labelException
);
94 public void setUri(URI uri
) {
96 super.setText(uri
.toString());
102 labelException
.setBackground(getPersistentBackground());
103 labelException
.setText("");
104 return new URI(super.getText());
105 } catch (Exception e
) {
106 labelException
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_RED
));
107 labelException
.setText(e
.getMessage());