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);
49 initLabel(formFactory
, labelString
, false, getLayoutComposite());
51 //composite(uri + button)
52 Composite textAndButton
= formFactory
.createComposite(getLayoutComposite(), style
);
53 textAndButton
.setLayout(LayoutConstants
.LAYOUT(2, false));
54 textAndButton
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY());
57 initText(formFactory
, null, textHeight
, null, false, style
, textAndButton
);
60 btnOpenBrowser
= formFactory
.createButton(textAndButton
, "", SWT
.NONE
);
61 btnOpenBrowser
.setImage(ImageResources
.getImage(ImageResources
.WEB
));
62 btnOpenBrowser
.setToolTipText("Open in external browser");
63 btnOpenBrowser
.addSelectionListener(new SelectionAdapter() {
65 public void widgetSelected(SelectionEvent e
) {
66 String errorTitle
= "Invalid URL";
67 String errorText
= "Could not open external browser. URL is invalid";
72 PlatformUI
.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(uri
.toURL());
73 } catch (PartInitException pie
) {
74 MessagingUtils
.informationDialog(errorTitle
, new Status(IStatus
.WARNING
, TaxeditorStorePlugin
.PLUGIN_ID
, errorText
, pie
));
75 } catch (MalformedURLException mue
) {
76 MessagingUtils
.informationDialog(errorTitle
, new Status(IStatus
.WARNING
, TaxeditorStorePlugin
.PLUGIN_ID
, errorText
, mue
));
77 } catch (IllegalArgumentException iae
) {
78 MessagingUtils
.informationDialog(errorTitle
, new Status(IStatus
.WARNING
, TaxeditorStorePlugin
.PLUGIN_ID
, errorText
, iae
));
83 btnOpenBrowser
.setLayoutData(LayoutConstants
.RIGHT());
85 labelException
= formFactory
.createLabel(getLayoutComposite(), "", SWT
.WRAP
);
86 int numColumns
= AbstractFormSection
.DEFAULT_NUM_COLUMNS
;
87 if(getLayoutComposite().getLayout() instanceof TableWrapLayout
){
88 numColumns
= ((TableWrapLayout
)getLayoutComposite().getLayout()).numColumns
;
90 labelException
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(numColumns
, 1));
91 addControl(labelException
);
95 public void setUri(URI uri
) {
97 super.setText(uri
.toString());
103 labelException
.setBackground(getPersistentBackground());
104 labelException
.setText("");
105 return new URI(super.getText());
106 } catch (Exception e
) {
107 labelException
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_RED
));
108 labelException
.setText(e
.getMessage());