From 24f5f2e8eafc38f40d1ae4925d0c3517a7cd2457 Mon Sep 17 00:00:00 2001 From: Patrick Plitzner Date: Mon, 10 Aug 2015 17:17:18 +0200 Subject: [PATCH] some layout changes --- .../ui/element/UriWithLabelElement.java | 42 +++++++++++++------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/UriWithLabelElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/UriWithLabelElement.java index e42490f5f..0ac7c1e4a 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/UriWithLabelElement.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/UriWithLabelElement.java @@ -13,6 +13,8 @@ package eu.etaxonomy.taxeditor.ui.element; import java.net.MalformedURLException; import java.net.URI; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; @@ -20,11 +22,15 @@ 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.swt.widgets.Layout; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.forms.widgets.TableWrapData; +import org.eclipse.ui.forms.widgets.TableWrapLayout; import eu.etaxonomy.taxeditor.model.ImageResources; +import eu.etaxonomy.taxeditor.model.MessagingUtils; +import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin; /** * @author n.hoffmann @@ -35,43 +41,53 @@ public class UriWithLabelElement extends TextWithLabelElement { private final Label labelException; private final Button btnOpenBrowser; + private static final int NUM_COLUMNS = 3; protected UriWithLabelElement(CdmFormFactory formFactory, ICdmFormElement parentElement, String labelString, URI initialUri, Integer textHeight, int style) { super(formFactory, parentElement, false); + Layout parentLayout = getLayoutComposite().getLayout(); + int parentNumColumns = 2; + if(parentLayout instanceof TableWrapLayout){ + parentNumColumns = ((TableWrapLayout)parentLayout).numColumns; + } 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); + addControl(layoutComposite); + layoutComposite.setLayout(LayoutConstants.LAYOUT(3, true)); + layoutComposite.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(parentNumColumns, 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.setToolTipText("Open in external browser"); btnOpenBrowser.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { + String errorTitle = "Invalid URL"; + String errorText = "Could not open external browser. URL is invalid"; + 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(); + } catch (PartInitException pie) { + MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, pie)); + } catch (MalformedURLException mue) { + MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, mue)); + } catch (IllegalArgumentException iae) { + MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, iae)); } } } }); + btnOpenBrowser.setLayoutData(LayoutConstants.RIGHT()); labelException = formFactory.createLabel(layoutComposite, "", SWT.WRAP); - labelException.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(3, 1)); + labelException.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(NUM_COLUMNS, 1)); addControl(labelException); setUri(initialUri); } -- 2.34.1