Fixes #2267
authorn.hoffmann <n.hoffmann@localhost>
Thu, 21 Apr 2011 10:13:20 +0000 (10:13 +0000)
committern.hoffmann <n.hoffmann@localhost>
Thu, 21 Apr 2011 10:13:20 +0000 (10:13 +0000)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/forms/PointElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/forms/TextWithLabelElement.java

index bb65087ce56fe0ff3784323712b05b0b590f5748..cd69f1633265b4756104a5d90dc06e3d6b048654 100644 (file)
@@ -1,12 +1,12 @@
 // $Id$
 /**
-* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
-* http://www.e-taxonomy.eu
-* 
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
+ * Copyright (C) 2007 EDIT
+ * European Distributed Institute of Taxonomy 
+ * http://www.e-taxonomy.eu
+ 
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * See LICENSE.TXT at the top of this package for the full license terms.
+ */
 
 package eu.etaxonomy.taxeditor.ui.forms;
 
@@ -20,99 +20,137 @@ import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.TermComboType;
 import eu.etaxonomy.taxeditor.ui.term.ReferenceSystemComboElement;
 
 /**
- * <p>PointElement class.</p>
- *
+ * <p>
+ * PointElement class.
+ * </p>
+ * 
  * @author n.hoffmann
  * @created Oct 15, 2010
  * @version 1.0
  */
-public class PointElement extends AbstractCdmFormElement implements IEntityElement<Point>{
+public class PointElement extends AbstractCdmFormElement implements
+               IEntityElement<Point> {
 
        private Point point;
-       
-       private ReferenceSystemComboElement combo_referenceSystem;
-       private TextWithLabelElement text_latitude;     
-       private TextWithLabelElement text_longitude;    
-       private NumberWithLabelElement number_errorRadius;
-       
+
+       private final TextWithLabelElement text_latitude;
+       private final TextWithLabelElement text_longitude;
+       private final NumberWithLabelElement number_errorRadius;
+       private final ReferenceSystemComboElement combo_referenceSystem;
+
+       private final TextWithLabelElement text_latitudeParsed;
+
+       private final TextWithLabelElement text_longitudeParsed;
+
        /**
-        * <p>Constructor for PointElement.</p>
-        *
-        * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory} object.
-        * @param formElement a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement} object.
-        * @param point a {@link eu.etaxonomy.cdm.model.location.Point} object.
-        * @param style a int.
+        * <p>
+        * Constructor for PointElement.
+        * </p>
+        * 
+        * @param formFactory
+        *            a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory}
+        *            object.
+        * @param formElement
+        *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
+        *            object.
+        * @param point
+        *            a {@link eu.etaxonomy.cdm.model.location.Point} object.
+        * @param style
+        *            a int.
         */
-       public PointElement(CdmFormFactory formFactory, ICdmFormElement formElement, Point point,  final int style) {
+       public PointElement(CdmFormFactory formFactory,
+                       ICdmFormElement formElement, Point point, final int style) {
                super(formFactory, formElement);
-               
+
                formFactory.addPropertyChangeListener(this);
-               
-               text_latitude = formFactory.createTextWithLabelElement(formElement, "Latitude (hexagesimal)", null, style);
-               text_longitude = formFactory.createTextWithLabelElement(formElement, "Longitude (hexagesimal)", null, style);
-               number_errorRadius = formFactory.createIntegerTextWithLabelElement(formElement, "Error Radius (m)", null, style);
-               combo_referenceSystem = (ReferenceSystemComboElement) formFactory.createTermComboElement(TermComboType.REFERENCE_SYSTEM, formElement, "Reference System", null, style);
-               
+
+               text_latitude = formFactory.createTextWithLabelElement(formElement,
+                               "Latitude (hexagesimal)", null, style);
+               text_latitudeParsed = formFactory.createTextWithLabelElement(
+                               formElement, "", null, style);
+               text_latitudeParsed.setEnabled(false);
+               text_longitude = formFactory.createTextWithLabelElement(formElement,
+                               "Longitude (hexagesimal)", null, style);
+               text_longitudeParsed = formFactory.createTextWithLabelElement(
+                               formElement, "", null, style);
+               text_longitudeParsed.setEnabled(false);
+               number_errorRadius = formFactory.createIntegerTextWithLabelElement(
+                               formElement, "Error Radius (m)", null, style);
+               combo_referenceSystem = (ReferenceSystemComboElement) formFactory
+                               .createTermComboElement(TermComboType.REFERENCE_SYSTEM,
+                                               formElement, "Reference System", null, style);
+
                setPoint(point);
        }
 
-       /* (non-Javadoc)
+       /*
+        * (non-Javadoc)
+        * 
         * @see eu.etaxonomy.taxeditor.forms.ISelectable#setSelected(boolean)
         */
        /** {@inheritDoc} */
        @Override
        public void setSelected(boolean selected) {
-               
+
        }
-       
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see
+        * eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#propertyChange(org
+        * .eclipse.jface.util.PropertyChangeEvent)
         */
        /** {@inheritDoc} */
        @Override
        public void propertyChange(PropertyChangeEvent event) {
-               if(event == null){
+               if (event == null) {
                        return;
                }
-               
+
                boolean propagate = false;
-               
+
                Object eventSource = event.getSource();
-               if(eventSource == text_latitude){
+               if (eventSource == text_latitude) {
                        try {
                                getPoint().setLatitudeByParsing(text_latitude.getText());
-                               text_latitude.setText(point.getLatitudeSexagesimal().toString(false));
-                               text_latitude.setBackground(getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
+                               text_latitudeParsed.setText(point.getLatitudeSexagesimal()
+                                               .toString(false));
+                               text_latitude
+                                               .setBackground(getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
                                propagate = true;
                        } catch (ParseException e) {
-                               text_latitude.setBackground(getColor(Resources.COLOR_PARSE_ERROR));
+                               text_latitude
+                                               .setBackground(getColor(Resources.COLOR_PARSE_ERROR));
                        }
-               }
-               else if(eventSource == text_longitude){
+               } else if (eventSource == text_longitude) {
                        try {
                                getPoint().setLongitudeByParsing(text_longitude.getText());
-                               text_longitude.setText(point.getLongitudeSexagesimal().toString(false));
-                               text_longitude.setBackground(getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
+                               text_longitudeParsed.setText(point.getLongitudeSexagesimal()
+                                               .toString(false));
+                               text_longitude
+                                               .setBackground(getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
                                propagate = true;
                        } catch (ParseException e) {
-                               text_latitude.setBackground(getColor(Resources.COLOR_PARSE_ERROR));
+                               text_longitude
+                                               .setBackground(getColor(Resources.COLOR_PARSE_ERROR));
                        }
-               }
-               else if(eventSource == number_errorRadius){
+               } else if (eventSource == number_errorRadius) {
                        getPoint().setErrorRadius(number_errorRadius.getInteger());
                        propagate = true;
-               }
-               else if(eventSource == combo_referenceSystem){
+               } else if (eventSource == combo_referenceSystem) {
                        getPoint().setReferenceSystem(combo_referenceSystem.getSelection());
                        propagate = true;
-               }       
-               
-               if(propagate){
+               }
+
+               if (propagate) {
                        firePropertyChangeEvent(new CdmPropertyChangeEvent(this, event));
                }
        }
 
-       /* (non-Javadoc)
+       /*
+        * (non-Javadoc)
+        * 
         * @see eu.etaxonomy.taxeditor.forms.IEntityElement#getEntity()
         */
        /** {@inheritDoc} */
@@ -122,39 +160,53 @@ public class PointElement extends AbstractCdmFormElement implements IEntityEleme
        }
 
        /**
-        * <p>setEntity</p>
-        *
-        * @param point a {@link eu.etaxonomy.cdm.model.location.Point} object.
+        * <p>
+        * setEntity
+        * </p>
+        * 
+        * @param point
+        *            a {@link eu.etaxonomy.cdm.model.location.Point} object.
         */
-       public void setEntity(Point point){
+       public void setEntity(Point point) {
                setPoint(point);
        }
-       
+
        /**
-        * <p>Setter for the field <code>point</code>.</p>
-        *
-        * @param point the point to set
+        * <p>
+        * Setter for the field <code>point</code>.
+        * </p>
+        * 
+        * @param point
+        *            the point to set
         */
        public void setPoint(Point point) {
                this.point = point;
-               if(point != null){
-                       text_latitude.setText(point.getLatitudeSexagesimal() == null ? "" : point.getLatitudeSexagesimal().toString(false));
-                       text_longitude.setText(point.getLongitudeSexagesimal() == null ? "" : point.getLongitudeSexagesimal().toString(false));
+               if (point != null) {
+                       String latitude = point.getLatitudeSexagesimal() == null ? ""
+                                       : point.getLatitudeSexagesimal().toString(false);
+                       String longitude = point.getLongitudeSexagesimal() == null ? ""
+                                       : point.getLongitudeSexagesimal().toString(false);
+                       text_latitude.setText(latitude);
+                       text_latitudeParsed.setText(latitude);
+                       text_longitude.setText(longitude);
+                       text_longitudeParsed.setText(longitude);
                        number_errorRadius.setInteger(point.getErrorRadius());
                        combo_referenceSystem.setSelection(point.getReferenceSystem());
                }
        }
 
        /**
-        * <p>Getter for the field <code>point</code>.</p>
-        *
+        * <p>
+        * Getter for the field <code>point</code>.
+        * </p>
+        * 
         * @return the point
         */
        public Point getPoint() {
-               if(point == null){
+               if (point == null) {
                        point = Point.NewInstance();
                }
-               
+
                return point;
        }
 
index 866730348c6ec4f16a54f5d7138673e93d2997bb..d50920b87a5f13b38fc2a1b98efe9645532b083e 100644 (file)
@@ -19,80 +19,99 @@ import eu.etaxonomy.cdm.common.CdmUtils;
 import eu.etaxonomy.taxeditor.preference.Resources;
 
 /**
- * <p>TextWithLabelElement class.</p>
- *
+ * <p>
+ * TextWithLabelElement class.
+ * </p>
+ * 
  * @author n.hoffmann
  * @version $Id: $
  */
-public class TextWithLabelElement extends AbstractCdmFormElement implements ModifyListener, IEnableableFormElement{
-               
+public class TextWithLabelElement extends AbstractCdmFormElement implements
+               ModifyListener, IEnableableFormElement {
+
        protected Text text;
        private Label label;
-       
+
        /** Constant <code>MAX_HEIGHT=0</code> */
        public static final int MAX_HEIGHT = 0;
        /** Constant <code>SINGLE=-1</code> */
        public static final int SINGLE = -1;
-       
+
        /**
-        * <p>Constructor for TextWithLabelElement.</p>
-        *
-        * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory} object.
-        * @param parentElement a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement} object.
-        * @param labelString a {@link java.lang.String} object.
-        * @param initialText a {@link java.lang.String} object.
-        * @param textHeight a {@link java.lang.Integer} object.
-        * @param style a int.
+        * <p>
+        * Constructor for TextWithLabelElement.
+        * </p>
+        * 
+        * @param formFactory
+        *            a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory}
+        *            object.
+        * @param parentElement
+        *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
+        *            object.
+        * @param labelString
+        *            a {@link java.lang.String} object.
+        * @param initialText
+        *            a {@link java.lang.String} object.
+        * @param textHeight
+        *            a {@link java.lang.Integer} object.
+        * @param style
+        *            a int.
         */
-       protected TextWithLabelElement(CdmFormFactory formFactory, ICdmFormElement parentElement, String labelString, String initialText, Integer textHeight, int style) 
-       {
+       protected TextWithLabelElement(CdmFormFactory formFactory,
+                       ICdmFormElement parentElement, String labelString,
+                       String initialText, Integer textHeight, int style) {
                super(formFactory, parentElement);
-               
-               if(labelString != null && ! labelString.equals("")){
-                       label = formFactory.createLabel(getLayoutComposite(), CdmUtils.Nz(labelString), SWT.NULL);
+
+               if (labelString != null) {
+                       label = formFactory.createLabel(getLayoutComposite(),
+                                       CdmUtils.Nz(labelString), SWT.NULL);
                        addControl(label);
                        label.setLayoutData(CdmFormFactory.LEFT());
                }
-               
-               int scrollStyle = textHeight == null ? SWT.NULL : (SWT.V_SCROLL | SWT.MULTI);
-               text = formFactory.createText(getLayoutComposite(), "", SWT.BORDER | SWT.WRAP | scrollStyle);
-       
+
+               int scrollStyle = textHeight == null ? SWT.NULL
+                               : (SWT.V_SCROLL | SWT.MULTI);
+               text = formFactory.createText(getLayoutComposite(), "", SWT.BORDER
+                               | SWT.WRAP | scrollStyle);
+
                addControl(text);
-                       
-//             text.setWO
-               
-               if(textHeight == null){
-                       text.addKeyListener( new KeyAdapter(){
+
+               // text.setWO
+
+               if (textHeight == null) {
+                       text.addKeyListener(new KeyAdapter() {
                                @Override
                                public void keyPressed(KeyEvent e) {
-                                       if(e.character == SWT.CR){
-                                               // Don't accept carriage returns as input when in single line mode
+                                       if (e.character == SWT.CR) {
+                                               // Don't accept carriage returns as input when in single
+                                               // line mode
                                                e.doit = false;
-                                       }else if(e.character == SWT.TAB){
+                                       } else if (e.character == SWT.TAB) {
                                                // traverse is not working for wrapped text widgets so
                                                // we reintroduce it here
                                                e.doit = false;
-                                               TextWithLabelElement.this.text.traverse(SWT.TRAVERSE_TAB_NEXT);
+                                               TextWithLabelElement.this.text
+                                                               .traverse(SWT.TRAVERSE_TAB_NEXT);
                                        }
                                }
                        });
                }
-               
+
                TableWrapData layoutData = CdmFormFactory.FILL();
-               if (textHeight != null && textHeight > 0){
-                       ((TableWrapData) layoutData).heightHint = textHeight;
-               }       
-               
+               if (textHeight != null && textHeight > 0) {
+                       (layoutData).heightHint = textHeight;
+               }
+
                text.setLayoutData(layoutData);
-               
+
                text.addModifyListener(this);
-               
+
                setText(initialText);
        }
-       
+
        /**
         * Get the text of this composites text composite
-        *
+        * 
         * @return a {@link java.lang.String} object.
         */
        public String getText() {
@@ -101,25 +120,30 @@ public class TextWithLabelElement extends AbstractCdmFormElement implements Modi
 
        /**
         * Set the text of this composites text composite
-        *
-        * @param string a {@link java.lang.String} object.
+        * 
+        * @param string
+        *            a {@link java.lang.String} object.
         */
        public void setText(String string) {
                Listener[] listeners = text.getListeners(SWT.Modify);
-               
-               for(Listener listener :  listeners){
+
+               for (Listener listener : listeners) {
                        text.removeListener(SWT.Modify, listener);
                }
-               
+
                text.setText(CdmUtils.Nz(string));
-               
-               for(Listener listener :  listeners){
+
+               for (Listener listener : listeners) {
                        text.addListener(SWT.Modify, listener);
                }
        }
 
-       /* (non-Javadoc)
-        * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
+       /*
+        * (non-Javadoc)
+        * 
+        * @see
+        * org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events
+        * .ModifyEvent)
         */
        /** {@inheritDoc} */
        public void modifyText(ModifyEvent e) {
@@ -134,26 +158,30 @@ public class TextWithLabelElement extends AbstractCdmFormElement implements Modi
        /** {@inheritDoc} */
        public void setEnabled(boolean enabled) {
                text.setEnabled(enabled);
-               String symbolicName = enabled ? Resources.COLOR_FONT_DEFAULT : Resources.COLOR_TEXT_DISABLED;
+               String symbolicName = enabled ? Resources.COLOR_FONT_DEFAULT
+                               : Resources.COLOR_TEXT_DISABLED;
                text.setForeground(getColor(symbolicName));
        }
 
        /** {@inheritDoc} */
        public void setIrrelevant(boolean irrelevant) {
-               String colorId = irrelevant ? Resources.COLOR_COMPOSITE_IRRELEVANT : Resources.COLOR_COMPOSITE_BACKGROUND;
-               
+               String colorId = irrelevant ? Resources.COLOR_COMPOSITE_IRRELEVANT
+                               : Resources.COLOR_COMPOSITE_BACKGROUND;
+
                Color color = getColor(colorId);
                text.setBackground(color);
        }
-       
+
        /** {@inheritDoc} */
        @Override
        public void setBackground(Color color) {
-               if(label != null)
+               if (label != null)
                        label.setBackground(color);
        }
-       
-       /* (non-Javadoc)
+
+       /*
+        * (non-Javadoc)
+        * 
         * @see eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#setFocus()
         */
        /** {@inheritDoc} */
@@ -163,18 +191,23 @@ public class TextWithLabelElement extends AbstractCdmFormElement implements Modi
        }
 
        /**
-        * <p>getMainControl</p>
-        *
+        * <p>
+        * getMainControl
+        * </p>
+        * 
         * @return a {@link org.eclipse.swt.widgets.Control} object.
         */
        public Control getMainControl() {
                return text;
        }
-       
+
        /**
-        * <p>setTextLimit</p>
-        *
-        * @param limit a int.
+        * <p>
+        * setTextLimit
+        * </p>
+        * 
+        * @param limit
+        *            a int.
         */
        public void setTextLimit(int limit) {
                text.setTextLimit(limit);