Project

General

Profile

Download (4.15 KB) Statistics
| Branch: | Tag: | Revision:
1 c4c08e81 n.hoffmann
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4 b48bc2d5 Patrick Plitzner
* European Distributed Institute of Taxonomy
5 c4c08e81 n.hoffmann
* http://www.e-taxonomy.eu
6 b48bc2d5 Patrick Plitzner
*
7 c4c08e81 n.hoffmann
* 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.
9
*/
10
11 78222507 n.hoffmann
package eu.etaxonomy.taxeditor.ui.element;
12 c4c08e81 n.hoffmann
13 a9b5194c Patrick Plitzner
import java.net.MalformedURLException;
14 c4c08e81 n.hoffmann
import java.net.URI;
15 6504f35c Patric Plitzner
16 24f5f2e8 Patrick Plitzner
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.Status;
18 191f2328 Patrick Plitzner
import org.eclipse.swt.SWT;
19 a9b5194c Patrick Plitzner
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.ui.PartInitException;
24
import org.eclipse.ui.PlatformUI;
25
26 2743a292 Patrick Plitzner
import eu.etaxonomy.taxeditor.Messages;
27 a9b5194c Patrick Plitzner
import eu.etaxonomy.taxeditor.model.ImageResources;
28 24f5f2e8 Patrick Plitzner
import eu.etaxonomy.taxeditor.model.MessagingUtils;
29
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
30 78222507 n.hoffmann
31 c4c08e81 n.hoffmann
/**
32
 * @author n.hoffmann
33
 * @created Dec 20, 2010
34
 * @version 1.0
35
 */
36 a45e3c4a Patrick Plitzner
public class UriWithLabelElement extends AbstractUriWithExceptionLabelElement<URI> {
37 c4c08e81 n.hoffmann
38 a45e3c4a Patrick Plitzner
    private Button btnOpenBrowser;
39 191f2328 Patrick Plitzner
40 a45e3c4a Patrick Plitzner
    protected UriWithLabelElement(CdmFormFactory formFactory, ICdmFormElement parentElement, String labelString,
41
            URI initialObject, Integer textHeight, int style) {
42
        super(formFactory, parentElement, labelString, initialObject, textHeight, style);
43 a9b5194c Patrick Plitzner
44 a45e3c4a Patrick Plitzner
	}
45
46
    /**
47
     * {@inheritDoc}
48
     */
49
    @Override
50
    protected void init(CdmFormFactory formFactory, String labelString, URI initialObject, Integer textHeight, int style) {
51
52
        //label
53 1fbf88c8 Patrick Plitzner
        initLabel(formFactory, labelString, false, getLayoutComposite());
54 24f5f2e8 Patrick Plitzner
55 59aac23b Patrick Plitzner
        //composite(uri + button)
56 1fbf88c8 Patrick Plitzner
        Composite textAndButton = formFactory.createComposite(getLayoutComposite(), style);
57 0320f89e Patrick Plitzner
        addControl(textAndButton);
58 1fbf88c8 Patrick Plitzner
        textAndButton.setLayout(LayoutConstants.LAYOUT(2, false));
59
        textAndButton.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
60 a9b5194c Patrick Plitzner
61 59aac23b Patrick Plitzner
        //uri text
62
        initText(formFactory, null, textHeight, null, false, style, textAndButton);
63
64
        //button
65 a45e3c4a Patrick Plitzner
        btnOpenBrowser = formFactory.createButton(textAndButton, "", SWT.NONE); //$NON-NLS-1$
66
        btnOpenBrowser.setImage(ImageResources.getImage(ImageResources.WEB));
67
        btnOpenBrowser.setToolTipText(Messages.UriWithLabelElement_OPEN_EXTERNAL_BROWSER);
68
        btnOpenBrowser.addSelectionListener(new SelectionAdapter() {
69
            @Override
70
            public void widgetSelected(SelectionEvent e) {
71
                String errorTitle = Messages.UriWithLabelElement_INVALID_URL;
72
                String errorText = Messages.UriWithLabelElement_COULD_NOT_OPEN_BROWSER;
73
74
                URI uri = parseText();
75
                if(uri!=null){
76
                    try {
77 a9b5194c Patrick Plitzner
                        PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(uri.toURL());
78 24f5f2e8 Patrick Plitzner
                    } catch (PartInitException pie) {
79
                        MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, pie));
80
                    } catch (MalformedURLException mue) {
81
                        MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, mue));
82
                    } catch (IllegalArgumentException iae) {
83
                        MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, iae));
84 a9b5194c Patrick Plitzner
                    }
85 a45e3c4a Patrick Plitzner
                }
86
                else{
87
                    MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, null));
88
                }
89
            }
90 a9b5194c Patrick Plitzner
        });
91 a45e3c4a Patrick Plitzner
        btnOpenBrowser.setLayoutData(LayoutConstants.RIGHT());
92
93
        initExceptionLabel(getLayoutComposite(), formFactory, initialObject);
94
    }
95 b48bc2d5 Patrick Plitzner
96
97 a45e3c4a Patrick Plitzner
98
    /**
99
     * {@inheritDoc}
100
     */
101
    @Override
102
    public void setParsedText(URI object) {
103
        if(object != null){
104
            super.setText(object.toString());
105 191f2328 Patrick Plitzner
        }
106 a45e3c4a Patrick Plitzner
    }
107
108
    /**
109
     * {@inheritDoc}
110
     */
111
    @Override
112
    protected URI getParsedText() throws Exception {
113
        return new URI(super.getText());
114
    }
115 b48bc2d5 Patrick Plitzner
116 c4c08e81 n.hoffmann
}