Project

General

Profile

« Previous | Next » 

Revision a9b5194c

Added by Patrick Plitzner almost 9 years ago

Add button to open URLs in external browser (#5062)

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/UriWithLabelElement.java
10 10

  
11 11
package eu.etaxonomy.taxeditor.ui.element;
12 12

  
13
import java.net.MalformedURLException;
13 14
import java.net.URI;
14 15

  
15 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;
16 21
import org.eclipse.swt.widgets.Display;
17 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;
26

  
27
import eu.etaxonomy.taxeditor.model.ImageResources;
18 28

  
19 29
/**
20 30
 * @author n.hoffmann
......
24 34
public class UriWithLabelElement extends TextWithLabelElement {
25 35

  
26 36
    private final Label labelException;
37
    private final Button btnOpenBrowser;
27 38

  
28 39
	protected UriWithLabelElement(CdmFormFactory formFactory,
29 40
			ICdmFormElement parentElement, String labelString,
30 41
			URI initialUri, Integer textHeight, int style) {
31
		super(formFactory, parentElement, labelString, null, textHeight, style);
42
		super(formFactory, parentElement, false);
43

  
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);
48

  
49

  
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() {
56
		    @Override
57
		    public void widgetSelected(SelectionEvent e) {
58
		        URI uri = getUri();
59
		        if(uri!=null){
60
		            try {
61
                        PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(uri.toURL());
62
                    } catch (PartInitException e1) {
63
                        // TODO Auto-generated catch block
64
                        e1.printStackTrace();
65
                    } catch (MalformedURLException e1) {
66
                        // TODO Auto-generated catch block
67
                        e1.printStackTrace();
68
                    }
69
		        }
70
		    }
71
        });
32 72

  
33
		labelException = formFactory.createLabel(getLayoutComposite(), "", SWT.WRAP);
34
		labelException.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
73
		labelException = formFactory.createLabel(layoutComposite, "", SWT.WRAP);
74
		labelException.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(3, 1));
35 75
		addControl(labelException);
36 76
		setUri(initialUri);
37 77
	}

Also available in: Unified diff