I18n for Specimen Editor
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / element / UriWithLabelElement.java
index 0ac7c1e4afc09ea6d2a3adfd97e1cc2ab0ce9196..b9d6300ecb985131e868427f47e5c4db8bf4a330 100644 (file)
@@ -15,6 +15,7 @@ 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;
@@ -22,12 +23,11 @@ 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.Messages;
 import eu.etaxonomy.taxeditor.model.ImageResources;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
@@ -41,34 +41,33 @@ 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());
-        addControl(layoutComposite);
+               //label
+        initLabel(formFactory, labelString, false, getLayoutComposite());
 
-        layoutComposite.setLayout(LayoutConstants.LAYOUT(3, true));
-        layoutComposite.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(parentNumColumns, 1));
+        //composite(uri + button)
+        Composite textAndButton = formFactory.createComposite(getLayoutComposite(), style);
+        addControl(textAndButton);
+        textAndButton.setLayout(LayoutConstants.LAYOUT(2, false));
+        textAndButton.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
 
-        init(formFactory, labelString, null, textHeight, null, false, style, layoutComposite);
+        //uri text
+        initText(formFactory, null, textHeight, null, false, style, textAndButton);
 
-               btnOpenBrowser = formFactory.createButton(layoutComposite, "", SWT.NONE);
-               btnOpenBrowser.setImage(ImageResources.getImage(ImageResources.ADD_CHILD_TAXON_ICON));
-               btnOpenBrowser.setToolTipText("Open in external browser");
+        //button
+               btnOpenBrowser = formFactory.createButton(textAndButton, "", SWT.NONE); //$NON-NLS-1$
+               btnOpenBrowser.setImage(ImageResources.getImage(ImageResources.WEB));
+               btnOpenBrowser.setToolTipText(Messages.UriWithLabelElement_OPEN_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";
+                       String errorTitle = Messages.UriWithLabelElement_INVALID_URL;
+                       String errorText = Messages.UriWithLabelElement_COULD_NOT_OPEN_BROWSER;
 
                        URI uri = getUri();
                        if(uri!=null){
@@ -82,12 +81,19 @@ public class UriWithLabelElement extends TextWithLabelElement {
                         MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, iae));
                     }
                        }
+                       else{
+                           MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, null));
+                       }
                    }
         });
                btnOpenBrowser.setLayoutData(LayoutConstants.RIGHT());
 
-               labelException = formFactory.createLabel(layoutComposite, "", SWT.WRAP);
-               labelException.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(NUM_COLUMNS, 1));
+               labelException = formFactory.createLabel(getLayoutComposite(), "", SWT.WRAP); //$NON-NLS-1$
+               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);
        }
@@ -100,12 +106,14 @@ public class UriWithLabelElement extends TextWithLabelElement {
 
        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.getLocalizedMessage());
             return null;
         }
        }