some layout changes
authorPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 10 Aug 2015 15:17:18 +0000 (17:17 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 10 Aug 2015 15:17:18 +0000 (17:17 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/UriWithLabelElement.java

index e42490f5f03495abb89b6400614e2d6dc5310a7c..0ac7c1e4afc09ea6d2a3adfd97e1cc2ab0ce9196 100644 (file)
@@ -13,6 +13,8 @@ package eu.etaxonomy.taxeditor.ui.element;
 import java.net.MalformedURLException;
 import java.net.URI;
 
 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;
 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.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.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.ImageResources;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
 
 /**
  * @author n.hoffmann
 
 /**
  * @author n.hoffmann
@@ -35,43 +41,53 @@ public class UriWithLabelElement extends TextWithLabelElement {
 
     private final Label labelException;
     private final Button btnOpenBrowser;
 
     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);
 
 
        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());
         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));
 
                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) {
                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());
                        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 = formFactory.createLabel(layoutComposite, "", SWT.WRAP);
-               labelException.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(3, 1));
+               labelException.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(NUM_COLUMNS, 1));
                addControl(labelException);
                setUri(initialUri);
        }
                addControl(labelException);
                setUri(initialUri);
        }