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
.jface
.resource
.JFaceResources
;
19 import org
.eclipse
.swt
.SWT
;
20 import org
.eclipse
.swt
.events
.SelectionAdapter
;
21 import org
.eclipse
.swt
.events
.SelectionEvent
;
22 import org
.eclipse
.swt
.widgets
.Button
;
23 import org
.eclipse
.swt
.widgets
.Composite
;
24 import org
.eclipse
.swt
.widgets
.Display
;
25 import org
.eclipse
.swt
.widgets
.Label
;
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
.Messages
;
31 import eu
.etaxonomy
.taxeditor
.model
.ImageResources
;
32 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
33 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
37 * @created Dec 20, 2010
40 public class UriWithLabelElement
extends TextWithLabelElement
{
42 private final Label labelException
;
43 private final Button btnOpenBrowser
;
45 protected UriWithLabelElement(CdmFormFactory formFactory
,
46 ICdmFormElement parentElement
, String labelString
,
47 URI initialUri
, Integer textHeight
, int style
) {
48 super(formFactory
, parentElement
, false);
51 initLabel(formFactory
, labelString
, false, getLayoutComposite());
53 //composite(uri + button)
54 Composite textAndButton
= formFactory
.createComposite(getLayoutComposite(), style
);
55 textAndButton
.setLayout(LayoutConstants
.LAYOUT(2, false));
56 textAndButton
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY());
59 initText(formFactory
, null, textHeight
, null, false, style
, textAndButton
);
62 btnOpenBrowser
= formFactory
.createButton(textAndButton
, "", SWT
.NONE
); //$NON-NLS-1$
63 btnOpenBrowser
.setImage(ImageResources
.getImage(ImageResources
.WEB
));
64 btnOpenBrowser
.setToolTipText(Messages
.UriWithLabelElement_OPEN_EXTERNAL_BROWSER
);
65 btnOpenBrowser
.addSelectionListener(new SelectionAdapter() {
67 public void widgetSelected(SelectionEvent e
) {
68 String errorTitle
= Messages
.UriWithLabelElement_INVALID_URL
;
69 String errorText
= Messages
.UriWithLabelElement_COULD_NOT_OPEN_BROWSER
;
74 PlatformUI
.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(uri
.toURL());
75 } catch (PartInitException pie
) {
76 MessagingUtils
.informationDialog(errorTitle
, new Status(IStatus
.WARNING
, TaxeditorStorePlugin
.PLUGIN_ID
, errorText
, pie
));
77 } catch (MalformedURLException mue
) {
78 MessagingUtils
.informationDialog(errorTitle
, new Status(IStatus
.WARNING
, TaxeditorStorePlugin
.PLUGIN_ID
, errorText
, mue
));
79 } catch (IllegalArgumentException iae
) {
80 MessagingUtils
.informationDialog(errorTitle
, new Status(IStatus
.WARNING
, TaxeditorStorePlugin
.PLUGIN_ID
, errorText
, iae
));
84 MessagingUtils
.informationDialog(errorTitle
, new Status(IStatus
.WARNING
, TaxeditorStorePlugin
.PLUGIN_ID
, errorText
, null));
88 btnOpenBrowser
.setLayoutData(LayoutConstants
.RIGHT());
90 labelException
= formFactory
.createLabel(getLayoutComposite(), "", SWT
.WRAP
); //$NON-NLS-1$
91 int numColumns
= AbstractFormSection
.DEFAULT_NUM_COLUMNS
;
92 if(getLayoutComposite().getLayout() instanceof TableWrapLayout
){
93 numColumns
= ((TableWrapLayout
)getLayoutComposite().getLayout()).numColumns
;
95 labelException
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(numColumns
, 1));
96 addControl(labelException
);
100 public void setUri(URI uri
) {
102 super.setText(uri
.toString());
108 labelException
.setFont(JFaceResources
.getFontRegistry().get(JFaceResources
.DEFAULT_FONT
));
109 labelException
.setForeground(getPersistentBackground());
110 labelException
.setText(""); //$NON-NLS-1$
111 return new URI(super.getText());
112 } catch (Exception e
) {
113 labelException
.setFont(JFaceResources
.getFontRegistry().getBold(JFaceResources
.DEFAULT_FONT
));
114 labelException
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_RED
));
115 labelException
.setText(Messages
.UriWithLabelElement_URL_NOT_SAVED
+e
.getMessage());