package eu.etaxonomy.taxeditor.ui.element;
+import java.net.MalformedURLException;
import java.net.URI;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.forms.widgets.TableWrapData;
+
+import eu.etaxonomy.taxeditor.model.ImageResources;
/**
* @author n.hoffmann
public class UriWithLabelElement extends TextWithLabelElement {
private final Label labelException;
+ private final Button btnOpenBrowser;
protected UriWithLabelElement(CdmFormFactory formFactory,
ICdmFormElement parentElement, String labelString,
URI initialUri, Integer textHeight, int style) {
- super(formFactory, parentElement, labelString, null, textHeight, style);
+ super(formFactory, parentElement, false);
+
+ Composite layoutComposite = formFactory.createComposite(getLayoutComposite());
+ layoutComposite.setLayout(LayoutConstants.LAYOUT(3, false));
+ layoutComposite.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2,1));
+ init(formFactory, labelString, null, textHeight, null, false, style, layoutComposite);
+
+
+ btnOpenBrowser = formFactory.createButton(layoutComposite, "", SWT.NONE);
+ btnOpenBrowser.setImage(ImageResources.getImage(ImageResources.ADD_CHILD_TAXON_ICON));
+ TableWrapData layoutData = LayoutConstants.RIGHT();
+ layoutData.grabHorizontal = false;
+ btnOpenBrowser.setLayoutData(layoutData);
+ btnOpenBrowser.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ URI uri = getUri();
+ if(uri!=null){
+ try {
+ PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(uri.toURL());
+ } catch (PartInitException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ } catch (MalformedURLException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ }
+ }
+ });
- labelException = formFactory.createLabel(getLayoutComposite(), "", SWT.WRAP);
- labelException.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+ labelException = formFactory.createLabel(layoutComposite, "", SWT.WRAP);
+ labelException.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(3, 1));
addControl(labelException);
setUri(initialUri);
}