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
.ui
.PartInitException
;
26 import org
.eclipse
.ui
.PlatformUI
;
27 import org
.eclipse
.ui
.forms
.widgets
.TableWrapLayout
;
29 import eu
.etaxonomy
.taxeditor
.model
.ImageResources
;
30 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
31 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
35 * @created Dec 20, 2010
38 public class UriWithLabelElement
extends TextWithLabelElement
{
40 private final Label labelException
;
41 private final Button btnOpenBrowser
;
43 protected UriWithLabelElement(CdmFormFactory formFactory
,
44 ICdmFormElement parentElement
, String labelString
,
45 URI initialUri
, Integer textHeight
, int style
) {
46 super(formFactory
, parentElement
, false);
48 initLabel(formFactory
, labelString
, false, getLayoutComposite());
50 Composite textAndButton
= formFactory
.createComposite(getLayoutComposite(), style
);
51 textAndButton
.setLayout(LayoutConstants
.LAYOUT(2, false));
52 textAndButton
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY());
54 btnOpenBrowser
= formFactory
.createButton(textAndButton
, "", SWT
.NONE
);
55 btnOpenBrowser
.setImage(ImageResources
.getImage(ImageResources
.WEB
));
56 btnOpenBrowser
.setToolTipText("Open in external browser");
57 btnOpenBrowser
.addSelectionListener(new SelectionAdapter() {
59 public void widgetSelected(SelectionEvent e
) {
60 String errorTitle
= "Invalid URL";
61 String errorText
= "Could not open external browser. URL is invalid";
66 PlatformUI
.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(uri
.toURL());
67 } catch (PartInitException pie
) {
68 MessagingUtils
.informationDialog(errorTitle
, new Status(IStatus
.WARNING
, TaxeditorStorePlugin
.PLUGIN_ID
, errorText
, pie
));
69 } catch (MalformedURLException mue
) {
70 MessagingUtils
.informationDialog(errorTitle
, new Status(IStatus
.WARNING
, TaxeditorStorePlugin
.PLUGIN_ID
, errorText
, mue
));
71 } catch (IllegalArgumentException iae
) {
72 MessagingUtils
.informationDialog(errorTitle
, new Status(IStatus
.WARNING
, TaxeditorStorePlugin
.PLUGIN_ID
, errorText
, iae
));
77 btnOpenBrowser
.setLayoutData(LayoutConstants
.RIGHT());
79 initLabel(formFactory
, labelString
, false, textAndButton
);
81 labelException
= formFactory
.createLabel(getLayoutComposite(), "", SWT
.WRAP
);
82 int numColumns
= AbstractFormSection
.DEFAULT_NUM_COLUMNS
;
83 if(getLayoutComposite().getLayout() instanceof TableWrapLayout
){
84 numColumns
= ((TableWrapLayout
)getLayoutComposite().getLayout()).numColumns
;
86 labelException
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(numColumns
, 1));
87 addControl(labelException
);
91 public void setUri(URI uri
) {
93 super.setText(uri
.toString());
99 labelException
.setBackground(getPersistentBackground());
100 labelException
.setText("");
101 return new URI(super.getText());
102 } catch (Exception e
) {
103 labelException
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_RED
));
104 labelException
.setText(e
.getMessage());