Merge develop into branch
authorPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 25 Aug 2015 06:22:23 +0000 (08:22 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 25 Aug 2015 06:22:23 +0000 (08:22 +0200)
1  2 
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/UriWithLabelElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/AbstractCdmDetailSection.java

index 915e342f2ea4ad3a8edcff75d716b129c727c0d4,31486b409b4788876b0f697593e6c9dc7a7dbf6d..e7c1e2e7bcf37ee9deae59855b122b143ef26f6e
  
  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.jface.resource.JFaceResources;
  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.TableWrapLayout;
  
+ import eu.etaxonomy.taxeditor.Messages;
 +import eu.etaxonomy.taxeditor.model.ImageResources;
 +import eu.etaxonomy.taxeditor.model.MessagingUtils;
 +import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
  
  /**
   * @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);
  
 -              labelException = formFactory.createLabel(getLayoutComposite(), "", SWT.WRAP); //$NON-NLS-1$
 -              labelException.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
 +              //label
 +        initLabel(formFactory, labelString, false, getLayoutComposite());
 +
 +        //composite(uri + button)
 +        Composite textAndButton = formFactory.createComposite(getLayoutComposite(), style);
 +        textAndButton.setLayout(LayoutConstants.LAYOUT(2, false));
 +        textAndButton.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
 +
 +        //uri text
 +        initText(formFactory, null, textHeight, null, false, style, textAndButton);
 +
 +        //button
 +              btnOpenBrowser = formFactory.createButton(textAndButton, "", SWT.NONE);
 +              btnOpenBrowser.setImage(ImageResources.getImage(ImageResources.WEB));
 +              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 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(getLayoutComposite(), "", SWT.WRAP);
 +              int numColumns = AbstractFormSection.DEFAULT_NUM_COLUMNS;
 +              if(getLayoutComposite().getLayout() instanceof TableWrapLayout){
 +                  numColumns = ((TableWrapLayout)getLayoutComposite().getLayout()).numColumns;
 +              }
 +        labelException.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(numColumns, 1));
                addControl(labelException);
                setUri(initialUri);
        }
  
        public URI getUri(){
          try {
-             labelException.setBackground(getPersistentBackground());
-             labelException.setText("");
+             labelException.setFont(JFaceResources.getFontRegistry().get(JFaceResources.DEFAULT_FONT));
+             labelException.setForeground(getPersistentBackground());
+             labelException.setText(""); //$NON-NLS-1$
              return new URI(super.getText());
          } catch (Exception e) {
-             labelException.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
-             labelException.setText(e.getMessage());
+             labelException.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
+             labelException.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
+             labelException.setText(Messages.UriWithLabelElement_URL_NOT_SAVED+e.getMessage());
              return null;
          }
        }
index f88a9d0bfbc3ea8f48e0089007a034de890463af,1d279078c2e55a8004b3448d2bbe20ac4ebd3a2c..cf2a786c869a2fd781942d8c52231af1900b5fea
@@@ -70,7 -70,7 +70,7 @@@ public abstract class AbstractCdmDetail
        protected void createControlsByType(AbstractCdmDetailSection<ENTITY> formElement, Class<ENTITY> entityClass, int style) {
            TableWrapLayout layout = (TableWrapLayout) getLayoutComposite().getLayout();
            layout.topMargin = 10;
 -          layout.numColumns = 2;
 +          layout.numColumns = DEFAULT_NUM_COLUMNS;
  
            getLayoutComposite().setLayout(layout);
            if(entityClass==null){
                String title = "";
                if (getEntity() != null && (getEntity() instanceof IdentifiableEntity) && !(getEntity() instanceof SpecimenOrObservationBase)) {
                        title = ": " + ((IdentifiableEntity) getEntity()).getTitleCache();
+                       // we have to duplicate ampersands otherwise they are treated as
+                       // mnenomic (see Label.setText() documentation)
+                       // see also #4302
+                       title = title.replace("&", "&&");
                }
                this.setText(String.format("%s%s", getHeading(), title));
                setTextClient(createToolbar());