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
.swt
.SWT
;
17 import org
.eclipse
.swt
.events
.SelectionAdapter
;
18 import org
.eclipse
.swt
.events
.SelectionEvent
;
19 import org
.eclipse
.swt
.widgets
.Button
;
20 import org
.eclipse
.swt
.widgets
.Composite
;
21 import org
.eclipse
.swt
.widgets
.Display
;
22 import org
.eclipse
.swt
.widgets
.Label
;
23 import org
.eclipse
.ui
.PartInitException
;
24 import org
.eclipse
.ui
.PlatformUI
;
25 import org
.eclipse
.ui
.forms
.widgets
.TableWrapData
;
27 import eu
.etaxonomy
.taxeditor
.model
.ImageResources
;
31 * @created Dec 20, 2010
34 public class UriWithLabelElement
extends TextWithLabelElement
{
36 private final Label labelException
;
37 private final Button btnOpenBrowser
;
39 protected UriWithLabelElement(CdmFormFactory formFactory
,
40 ICdmFormElement parentElement
, String labelString
,
41 URI initialUri
, Integer textHeight
, int style
) {
42 super(formFactory
, parentElement
, false);
44 Composite layoutComposite
= formFactory
.createComposite(getLayoutComposite());
45 layoutComposite
.setLayout(LayoutConstants
.LAYOUT(3, false));
46 layoutComposite
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2,1));
47 init(formFactory
, labelString
, null, textHeight
, null, false, style
, layoutComposite
);
50 btnOpenBrowser
= formFactory
.createButton(layoutComposite
, "", SWT
.NONE
);
51 btnOpenBrowser
.setImage(ImageResources
.getImage(ImageResources
.ADD_CHILD_TAXON_ICON
));
52 TableWrapData layoutData
= LayoutConstants
.RIGHT();
53 layoutData
.grabHorizontal
= false;
54 btnOpenBrowser
.setLayoutData(layoutData
);
55 btnOpenBrowser
.addSelectionListener(new SelectionAdapter() {
57 public void widgetSelected(SelectionEvent e
) {
61 PlatformUI
.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(uri
.toURL());
62 } catch (PartInitException e1
) {
63 // TODO Auto-generated catch block
65 } catch (MalformedURLException e1
) {
66 // TODO Auto-generated catch block
73 labelException
= formFactory
.createLabel(layoutComposite
, "", SWT
.WRAP
);
74 labelException
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(3, 1));
75 addControl(labelException
);
79 public void setUri(URI uri
) {
81 super.setText(uri
.toString());
87 labelException
.setBackground(getPersistentBackground());
88 labelException
.setText("");
89 return new URI(super.getText());
90 } catch (Exception e
) {
91 labelException
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_RED
));
92 labelException
.setText(e
.getMessage());