Package DisplayProject

Source Code of DisplayProject.PasswordDataField

/*
Copyright (c) 2003-2009 ITerative Consulting Pty Ltd. All Rights Reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:

o Redistributions of source code must retain the above copyright notice, this list of conditions and
the following disclaimer.
 
o Redistributions in binary form must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with the distribution.
   
o This jcTOOL Helper Class software, whether in binary or source form may not be used within,
or to derive, any other product without the specific prior written permission of the copyright holder

 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


*/
package DisplayProject;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Insets;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.util.Hashtable;
import java.util.IdentityHashMap;
import java.util.Map;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JMenuItem;
import javax.swing.JPasswordField;
import javax.swing.JTable;
import javax.swing.border.Border;
import javax.swing.text.BadLocationException;

import org.apache.log4j.Logger;

import DisplayProject.events.ChildEventHelper;
import DisplayProject.events.ClientEventManager;
import DisplayProject.factory.DataFieldFactory;
import DisplayProject.table.ArrayFieldCellHelper;
import DisplayProject.table.ArrayTableComponentCorrector;
import Framework.CloneHelper;
import Framework.DataValue;
import Framework.EventManager;
import Framework.ForteKeyboardFocusManager;
import Framework.ParameterHolder;

/**
* PasswordDataField
*/
@SuppressWarnings("serial")
public class PasswordDataField extends JPasswordField implements FocusListener, ArrayTableComponentCorrector {
  private static final Logger _log = Logger.getLogger(PasswordDataField.class);
    protected transient boolean firstKey = true;
    private static final int LEFT_PAD = 3;
    private PasswordDataField editor;
    private PasswordDataField renderer;
    private PasswordDataField columnTemplate;
    protected Object lastValue = "";
    private JTable table = null;
    private int tableRow = -1;
    private int tableColumn = -1;
    private boolean nullValueAllowed = false;
    protected boolean postEvents = true;
   
    /**
     * Determine whether to validate the password field on each keystroke. If this
     * value is true, then: <br>
     * <li>No AfterFirstKeystroke event will be posted
     * <li>An AfterValueChange event will be posted on each keystroke
     * <li>The underlying data committed to the model on each keypress
     */
    protected boolean validateOnKeystroke = false;

    protected boolean hasChanged = false;
   
    @SuppressWarnings("deprecation")
  protected DataMap map = null;

    public PasswordDataField() {
        super();
        addFocusListener(this);
        // TF:14/06/2008:Added the call to custom border to get the sizing correct
        this.customBorder();
        // TF:17 Sep 2009:Added the status text listener
        this.addMouseListener(StatusTextListener.sharedInstance());
      // TF:15/12/2009:DET-141:Set this up to allow inheriting of popup menu
      this.setInheritsPopupMenu(true);
    }

    /**
     * @return Returns the validateOnKeystroke.
     */
    public boolean isValidateOnKeystroke() {
        return validateOnKeystroke;
    }
    /**
     * @param validateOnKeystroke The validateOnKeystroke to set.
     */
    public void setValidateOnKeystroke(boolean validateOnKeystroke) {
        this.validateOnKeystroke = validateOnKeystroke;
    }
    public void focusGained(FocusEvent e) {
        this.firstKey = true;
        EventManager.startEventChain();
        int reason = ForteKeyboardFocusManager.getTraversalReason();
        if (reason != Constants.FC_SUPRESS) {
            Hashtable<String, Object> params = new Hashtable<String, Object>();
            params.put("reason", new ParameterHolder(reason));
            ClientEventManager.postEvent( this.correctPostingComponent(), "AfterFocusGain", params );
        }
        EventManager.endEventChain();
    }

    public void focusLost(FocusEvent e) {
        Component opp = e.getOppositeComponent();
        if (opp instanceof JButton) {
            JButton cancel = (JButton)e.getOppositeComponent();
            if(cancel.getVerifyInputWhenFocusTarget()==false) {
                return;
            }
        }
        if (opp instanceof JMenuItem) {
            JMenuItem cancel = (JMenuItem)e.getOppositeComponent();
            if(cancel.getVerifyInputWhenFocusTarget()==false) {
                return;
            }
        }

        // TF:If we're an editor of an array field, don't post this as the array field will do it explicitly
        if (ArrayFieldCellHelper.getArrayField(this) == null) {

        /*
         * Determine if we are traversing forward or backward and provide the correct focus loss reason
         */
        int reason = Constants.FC_KEYNEXT;
        Component next = this.getFocusCycleRootAncestor()
                .getFocusTraversalPolicy().getComponentAfter(
                        this.getFocusCycleRootAncestor(), this);
        if (e.getOppositeComponent() != next){
            reason = Constants.FC_KEYPREV;
        }

        if (firstKey){
            postBeforeFocusLoss(reason);
            return;
        }
        else {
            if (!validateOnKeystroke) {
                postAfterValueChange();
            }
            postBeforeFocusLoss(reason);
          }
        }
    }

    protected void processKeyEvent(KeyEvent e) {
        int code = e.getKeyCode();     
        char ch = e.getKeyChar();

        /*
         * if the key code is a action key
         * lat the super process it
         */
        if(code != KeyEvent.VK_UNDEFINED){
            if (e.getID() == KeyEvent.KEY_PRESSED){
                if (code == KeyEvent.VK_BACK_SPACE && this.isEditable()){
                    int pos = getCaretPosition();
                    int ss = getSelectionStart();
                    int ee = getSelectionEnd();
                    if (pos == 0 && ee == 0) return;
                    try {
                        if (ss != ee) {
                            getDocument().remove(ss, ee-ss);
                        } else {
                            getDocument().remove(pos-1, 1);
                        }
                        firstKeyStroke();
                    } catch (BadLocationException e1) {
                        Logger.getLogger(DataField.class).error("BadLocation exception in DataField", e1);
                    }
                }
                else {
                    if (code == KeyEvent.VK_DELETE && this.isEditable()) {
                        int pos = getCaretPosition();
                        int ss = getSelectionStart();
                        int ee = getSelectionEnd();
                        int lastPosition = getDocument() == null? -1: getDocument().getEndPosition().getOffset() - 1;
                        if (pos == lastPosition && ee == lastPosition && ss == lastPosition) return;
                        try {
                            if (ss != ee) {
                                getDocument().remove(ss, ee-ss);
                            } else {
                                getDocument().remove(pos, 1);
                            }
                            firstKeyStroke();
                        } catch (BadLocationException e1) {
                            Logger.getLogger(DataField.class).error("BadLocation exception in DataField", e1);
                        }
                    }
                    else {
                        super.processKeyEvent(e);
                    }
                }
            }
            return;
        }
        /*
         * othwerise process it as a character
         */
        else {
            if (Character.isIdentifierIgnorable(ch)) return;
            super.processKeyEvent(e);
            firstKeyStroke();
        }
    }

    protected void firstKeyStroke(){
        if (this.validateOnKeystroke) {
            this.postAfterValueChange(false);
        }
        if (this.firstKey){
            this.firstKey = false;
            if (!validateOnKeystroke){
                Hashtable<String, Object> qq_Params = new Hashtable<String, Object>();
                ClientEventManager.postEvent( this.correctPostingComponent(), "AfterFirstKeystroke", qq_Params );
                // TF:27/9/07:Revamped to use new event poster
                ChildEventHelper.postEventToAllParents(this.correctPostingComponent(), "ChildAfterFirstKeystroke");
            }
        }
    }
   
    public void loseFocus(int reason) {
        if (firstKey){
            postBeforeFocusLoss(reason);
            return;
        }
        else {
            if (!validateOnKeystroke) {
                postAfterValueChange();
            }
            postBeforeFocusLoss(reason);
        }
    }

    public void postBeforeFocusLoss(int reason) {
        EventManager.startEventChain();
        FocusHelper.addSetFocusPurgeAction(this);
//        FocusHelper.addPurgeAction(new RollbackAction());
        int realReason = ForteKeyboardFocusManager.getTraversalReason();
        if (realReason != Constants.FC_SUPRESS) {
            Hashtable<String, Object> params = new Hashtable<String, Object>();
            params.put("reason", new ParameterHolder(realReason));
            ClientEventManager.postEvent( this.correctPostingComponent(), "BeforeFocusLoss", params );
        }
        EventManager.endEventChain();
    }

    public void postAfterValueChange() {
        this.postAfterValueChange(true);
    }

    public void postAfterValueChange(boolean pIsFromFocusLoss) {
        try {
            EventManager.startEventChain();
            if (!firstKey || validateOnKeystroke) {
                String text = String.copyValueOf(getPassword());
                Hashtable<String, Object> qq_Params = new Hashtable<String, Object>();
                this.toData(text);
                lastValue = text;
                if (pIsFromFocusLoss) {
                    firstKey = true;
                }
                ClientEventManager.postEvent( this.correctPostingComponent(), "AfterValueChange", qq_Params );
                UIutils.setDataChangedFlag(this.correctPostingComponent());
                // TF:27/9/07:Revamped to use new event poster
                ChildEventHelper.postEventToAllParents(this.correctPostingComponent(), "ChildAfterValueChange");
            }
        }
        finally {
            EventManager.endEventChain();
        }
    }

    public void setValue(Object value) {
        if (value != null) {
            setText(value.toString());
            lastValue = value.toString();
        }
        else {
            setText("");
            lastValue = "";
        }
    }
   
    public Object getValue() {
        lastValue = "";
        String  password = "";
      char[]  passChar = null;
     
        try {
          passChar = getPassword();
          password = new String(passChar);
        } catch (NullPointerException e) {
          lastValue = password;
        }

        lastValue = password;
        return password;
    }


    @SuppressWarnings("deprecation")
  public DataMap getMap() {
        return map;
    }
    @SuppressWarnings("deprecation")
  public void setMap(DataMap map) {
        this.map = map;
    }

    public void fromData() {
        UIutils.invokeOnGuiThread(new Runnable () {
                @SuppressWarnings("deprecation")
        public void run() {
                  if (map != null) {
                        map.fromData();
                  }
                }
            });
    }

    @SuppressWarnings("deprecation")
  public void toData(Object o) {
        if (map != null) {
            map.toData(o);
        }
    }

    public PasswordDataField cloneComponent(){
        PasswordDataField clone = DataFieldFactory.newPasswordField("", getColumns());
        CloneHelper.cloneComponent(this, clone, new String[]{"UI", // class javax.swing.plaf.TextUI
                "UIClassID", // class java.lang.String
                "accessibleContext", // class javax.accessibility.AccessibleContext
                "action", // interface javax.swing.Action
                "actionCommand", // class java.lang.String
                "actionListeners", // class [Ljava.awt.event.ActionListener;
                "actionMap", // class javax.swing.ActionMap
                "actions", // class [Ljavax.swing.Action;
                "alignmentX", // float
                "alignmentY", // float
                "ancestorListeners", // class [Ljavax.swing.event.AncestorListener;
                //"autoscrolls", // boolean
                //"background", // class java.awt.Color
                //"border", // interface javax.swing.border.Border
                "caret", // interface javax.swing.text.Caret
                "caretColor", // class java.awt.Color
                "caretListeners", // class [Ljavax.swing.event.CaretListener;
                "caretPosition", // int
                //"columns", // int
                "component", // null
                "componentCount", // int
                "componentOrientation", // class java.awt.ComponentOrientation
                //"componentPopupMenu", // class javax.swing.JPopupMenu
                "components", // class [Ljava.awt.Component;
                "containerListeners", // class [Ljava.awt.event.ContainerListener;
                "debugGraphicsOptions", // int
                "disabledTextColor", // class java.awt.Color
                "document", // interface javax.swing.text.Document
                //"doubleBuffered", // boolean
                "dragEnabled", // boolean
                //"echoChar", // char
                //"editable", // boolean
                //"enabled", // boolean
                "focusAccelerator", // char
                "focusCycleRoot", // boolean
                "focusTraversalKeys", // null
                "focusTraversalPolicy", // class java.awt.FocusTraversalPolicy
                "focusTraversalPolicyProvider", // boolean
                "focusTraversalPolicySet", // boolean
                //"focusable", // boolean
                //"font", // class java.awt.Font
                //"foreground", // class java.awt.Color
                "graphics", // class java.awt.Graphics
                //"height", // int
                "highlighter", // interface javax.swing.text.Highlighter
                //"horizontalAlignment", // int
                "horizontalVisibility", // interface javax.swing.BoundedRangeModel
                //"inheritsPopupMenu", // boolean
                "inputMap", // null
                "inputMethodRequests", // interface java.awt.im.InputMethodRequests
                "inputVerifier", // class javax.swing.InputVerifier
                "insets", // class java.awt.Insets
                "keymap", // interface javax.swing.text.Keymap
                "layout", // interface java.awt.LayoutManager
                "managingFocus", // boolean
                "map", // interface DisplayProject.DataMap
                //"margin", // class java.awt.Insets
                //"maximumSize", // class java.awt.Dimension
                //"minimumSize", // class java.awt.Dimension
                // "name", // class java.lang.String
                "navigationFilter", // class javax.swing.text.NavigationFilter
                "nextFocusableComponent", // class java.awt.Component
                //"opaque", // boolean
                //"optimizedDrawingEnabled", // boolean
                "paintingTile", // boolean
                "password", // class [C
                "preferredScrollableViewportSize", // class java.awt.Dimension
                "preferredSize", // class java.awt.Dimension
                "registeredKeyStrokes", // class [Ljavax.swing.KeyStroke;
                //"requestFocusEnabled", // boolean
                "rootPane", // class javax.swing.JRootPane
                "scrollOffset", // int
                "scrollableTracksViewportHeight", // boolean
                "scrollableTracksViewportWidth", // boolean
                "selectedText", // class java.lang.String
                "selectedTextColor", // class java.awt.Color
                "selectionColor", // class java.awt.Color
                "selectionEnd", // int
                "selectionStart", // int
                "text", // class java.lang.String
                "toolTipText", // class java.lang.String
                "topLevelAncestor", // class java.awt.Container
                "transferHandler", // class javax.swing.TransferHandler
                //"validateOnKeystroke", // boolean
                "validateRoot", // boolean
                "value", // class java.lang.Object
                "verifyInputWhenFocusTarget", // boolean
                "vetoableChangeListeners", // class [Ljava.beans.VetoableChangeListener;
                //"visible", // boolean
                "visibleRect", // class java.awt.Rectangle
                //"width", // int
                //"x", // int
                //"y" // int
                });
        return clone;
    }

    /**
     * this method adjusts the lead spacing on a PasswordDataField to be more like Forte
     */
    private void customBorder(){
        Border newBorder = BorderFactory.createCompoundBorder(this.getBorder(),
                BorderFactory.createEmptyBorder(1, LEFT_PAD, 0, 0));
        this.setBorder(newBorder);

    }
    /**
     * If we have a password field that is sized to Natural and there is a number of columns set we must obey
     * the number of columns in preference to the current size.
     */
    @Override
    public Dimension getMinimumSize() {
      Dimension result = super.getMinimumSize();
      GridCell cell = GridCell.get(this);
        Insets insets = getInsets();
      if (cell.getWidthPolicy() == Constants.SP_NATURAL && this.getColumns() > 0) {
            result.width = getColumns() * getColumnWidth() + insets.left + insets.right;
      }
      if (cell.getHeightPolicy() == Constants.SP_NATURAL) {
        // Why "-2"? Because this is approximately what forte gave it, so things lay out pretty well
            result.height = this.getFontMetrics(this.getFont()).getHeight() + insets.top + insets.bottom - 2;
      }
      return result;
    }
   
    /**
     * Caching of the column width for efficiency
     */
    private int columnWidth = 0;
   
    /**
     * Override this method to ensure that we get a character size more similar to what Forte gave us
     */
    @Override
    protected int getColumnWidth() {
        if (columnWidth == 0) {
          columnWidth = UIutils.averageCharacter(this);
        }
        return columnWidth;
    }
   
    @Override
    public void setFont(Font f) {
      columnWidth = 0;
      super.setFont(f);
    }
   
    /**
     * Return a clone of this data field, suitable to use for a formatted cell renderer. The
     * difference between this and the normal cloneComponent() method is that this method will
     * return a data field that has methods overriden for efficiency in a table cell renderer.
     * These methods are: <tt>validate</tt> and <tt>revalidate</tt>.
     * @return
     */
    public PasswordDataField cloneComponentForRenderer() {
        this.renderer = new PasswordDataField() {
             // The following methods override the defaults for performance reasons
            public void validate() {}
            public void revalidate() {}
            // Do NOT override these 2 methods, even though you normally can for renderers!
            // protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {}
            // public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) {}
        };
        cloneComponentProperties(this.renderer, new IdentityHashMap<Object, Object>());
        return this.renderer;
    }
    // PM:31 Oct 2008:
    /**
     * Return a clone of this data field, suitable to use for a formatted cell renderer.
     * @return
     */
    public PasswordDataField cloneComponentForEditor() {
        this.editor = cloneComponent(new IdentityHashMap<Object, Object>());
        this.editor.columnTemplate = this;
        return editor;
    }

    private void cloneComponentProperties(PasswordDataField clone, Map<Object, Object> visitedObjects) {
        // The list of exclusions that will NOT get copied by the clone method
        String[] widgetCopyExclusions =
            new String[]{"UI", // class javax.swing.plaf.TextUI
                "UIClassID", // class java.lang.String
                "accessibleContext", // class javax.accessibility.AccessibleContext
                "action", // interface javax.swing.Action
                "actionCommand", // class java.lang.String
                "actionListeners", // class [Ljava.awt.event.ActionListener;
                "actionMap", // class javax.swing.ActionMap
                "actions", // class [Ljavax.swing.Action;
                //"alignmentX", // float
                //"alignmentY", // float
                //"allowsEmptyMasks", // boolean
                "ancestorListeners", // class [Ljavax.swing.event.AncestorListener;
                "autoscrolls", // boolean
                //"background", // class java.awt.Color
                //"border", // interface javax.swing.border.Border
                "caret", // interface javax.swing.text.Caret
                "caretColor", // class java.awt.Color
                "caretListeners", // class [Ljavax.swing.event.CaretListener;
                "caretPosition", // int
                "cb", // class javax.swing.JComboBox
                //"columns", // int
                "component", // null
                "componentCount", // int
                //"componentOrientation", // class java.awt.ComponentOrientation
                "componentPopupMenu", // class javax.swing.JPopupMenu
                "components", // class [Ljava.awt.Component;
                "containerListeners", // class [Ljava.awt.event.ContainerListener;
                //"dateFmt", // class java.text.SimpleDateFormat
                //"dateTemplate", // class cts.framework.TextData
                //"debugGraphicsOptions", // int
                "dirty", // boolean
                //"disabledTextColor", // class java.awt.Color
                "document", // interface javax.swing.text.Document
                //"doubleBuffered", // boolean
                //"dragEnabled", // boolean
                //"editFormatter", // class javax.swing.JFormattedTextField$AbstractFormatter
                //"editValid", // boolean
                //"editable", // boolean
                "editorComponent", // class java.awt.Component
                //"enabled", // boolean
                //"filter", // class javax.swing.text.DocumentFilter
                "focusAccelerator", // char
                "focusCycleRoot", // boolean
                "focusLostBehavior", // int
                "focusTraversalKeys", // null
                "focusTraversalPolicy", // class java.awt.FocusTraversalPolicy
                "focusTraversalPolicyProvider", // boolean
                "focusTraversalPolicySet", // boolean
                //"focusable", // boolean
                //"font", // class java.awt.Font
                //"foreground", // class java.awt.Color
                "formatter", // class javax.swing.JFormattedTextField$AbstractFormatter    // TF:24/10/2008:We cannot reuse the formatter, as the data field is installed onto the formatter
                "formatterFactory", // class javax.swing.JFormattedTextField$AbstractFormatterFactory  // TF:03/11/2008:We cannot reuse the formatter factory as this may store a reference to the widget
                "graphics", // class java.awt.Graphics
                //"height", // int
                "highlighter", // interface javax.swing.text.Highlighter
                //"horizontalAlignment", // int
                "horizontalVisibility", // interface javax.swing.BoundedRangeModel
                //"inheritsPopupMenu", // boolean
                "inputMap", // null
                "inputMethodRequests", // interface java.awt.im.InputMethodRequests
                "inputVerifier", // class javax.swing.InputVerifier
                //"insets", // class java.awt.Insets
                "item", // class java.lang.Object
                "keymap", // interface javax.swing.text.Keymap
                "lastValue", // class java.lang.Object
                //"layout", // interface java.awt.LayoutManager
                "managingFocus", // boolean
                "map", // interface cts.displayproject.DataMap
                //"margin", // class java.awt.Insets
                //"maskType", // int
                //"maxLength", // int
                //"maximumSize", // class java.awt.Dimension
                //"minimumSize", // class java.awt.Dimension
                // "name", // class java.lang.String
                "navigationFilter", // class javax.swing.text.NavigationFilter
                "nextFocusableComponent", // class java.awt.Component
                //"nullValueAllowed", // boolean
                //"opaque", // boolean
                //"optimizedDrawingEnabled", // boolean
                //"originalFormatText", // class java.lang.String
                "paintingTile", // boolean
                //"preferredScrollableViewportSize", // class java.awt.Dimension
                "preferredSize", // class java.awt.Dimension
                "registeredKeyStrokes", // class [Ljavax.swing.KeyStroke;
                //"requestFocusEnabled", // boolean
                "rootPane", // class javax.swing.JRootPane
                "scrollOffset", // int
                "scrollableTracksViewportHeight", // boolean
                "scrollableTracksViewportWidth", // boolean
                "selectedText", // class java.lang.String
                "selectedTextColor", // class java.awt.Color
                "selectionColor", // class java.awt.Color
                "selectionEnd", // int
                "selectionStart", // int
                "table", // class javax.swing.JTable
                "tableColumn", // int
                "tableRow", // int
                "text", // class java.lang.String
                "textValue", // class cts.framework.TextData
                //"toolTipText", // class java.lang.String
                "topLevelAncestor", // class java.awt.Container
                "transferHandler", // class javax.swing.TransferHandler
                //"validateOnKeystroke", // boolean
                "validateRoot", // boolean
                "value", // class java.lang.Object
                "valueNull", // boolean
                //"verifyInputWhenFocusTarget", // boolean
                "vetoableChangeListeners", // class [Ljava.beans.VetoableChangeListener;
                //"visible", // boolean
                "visibleRect", // class java.awt.Rectangle
                //"width", // int
                //"x", // int
                //"y" // int
                };

        CloneHelper.cloneComponent(this, clone, widgetCopyExclusions);
       
        visitedObjects.put(this, clone);
        // TF:12/02/2009:FTL-9:We need to clone the maxLength of the fixed length document too
        if (this.getDocument() instanceof FixedLengthDocument && clone.getDocument() instanceof FixedLengthDocument) {
          ((FixedLengthDocument)clone.getDocument()).setMaxLength(((FixedLengthDocument)this.getDocument()).getMaxLength());
        }
    }

    public PasswordDataField cloneComponent(Map<Object, Object> visitedObjects) {
        PasswordDataField clone = DataFieldFactory.newPasswordField("", getColumns());
        cloneComponentProperties(clone, visitedObjects);
        return clone;
    }
   
  /**
   * Get the component that is the column template for this array field. If there is no
   * column template, or this data field is not in an array, return <tt>this</tt>
   * @return
   */
  // FIXED: CCY: 9 Sep 2009 - Modify return type to JComponent
  public JComponent correctPostingComponent(){
    // PM:31 Oct 2008:this caters for a datafield being used as a column template
    if (this.columnTemplate != null){
      return this.columnTemplate;
    } else {
      return this;
    }
  }
 
  /**
   * Get the component which is actually used to edit the values in an array field. This is
   * not the column template, but rather the actual editor. If there is no editor, or this
   * data field is not in an array, return <tt>this</tt>
   * @return
   */
  // FIXED: CCY: 9 Sep 2009 - Modify return type to JComponent
  public JComponent correctSubscriptionComponent(){
    if (this.editor != null){
      return this.editor;
    } else {
      return this;
    }
  }
 
    public boolean isValueNull() {
        String uncommitted = "";
       
        try  {
          uncommitted = new String (getPassword());
        } catch (NullPointerException e) {
          _log.trace("isValueNull:", e);
        }
       
        boolean itSureIs = uncommitted.equalsIgnoreCase(DataValue.NL_FMSG_NULLVALUE);

        if (_log.isDebugEnabled()) {
          _log.debug("DataField " + getName() + ".isValueNull() -->" + uncommitted + "<-->" + Boolean.toString(itSureIs) + "<--");
        }
        return itSureIs;
    }
 
    public String toString() {
      String password = null;
     
      try {
        password = new String(getPassword());
      } catch (NullPointerException e) {
        password = "";
      }
     
      if (this.columnTemplate != null){
        return "CellEditor clone of PasswordDataField["+getName()+","+ password + ", " + "height " + getHeight()+ ", " + " width " + getWidth() + "]";
      } else {
        return "PasswordDataField["+getName()+","+ password + ", " + "height " + getHeight()+ ", " + " width " + getWidth() + "]";
      }
    }
   
    public Object getLastValue() {
        return lastValue;
    }
    public void setLastValue(Object lastValue) {
        this.lastValue = lastValue;
    }
    public void disableEvents(){
        this.postEvents = false;
    }
    public int getTableColumn() {
        return this.tableColumn;
    }
    public void setTableColumn(int tableColumn) {
        this.tableColumn = tableColumn;
    }
    public int getTableRow() {
        return this.tableRow;
    }
    public void setTableRow(int tableRow) {
        this.tableRow = tableRow;
    }

    public JTable getTable() {
        return this.table;
    }
    public void setTable(JTable table) {
        this.table = table;
    }
   
    public boolean isNullValueAllowed() {
      if (_log.isDebugEnabled()) {
        _log.debug("DataField " + getName() + ".isNullValueAllowed() -->" + Boolean.toString(nullValueAllowed) + "<--");
      }
        return nullValueAllowed;
    }
  /**
   * Override the tooltip text so that if it's being set to "" then we actually set the
   * value to null to remove the tooltip text, as this is how Forte behaved.
   */
  @Override
  public void setToolTipText(String pText) {
    if (pText == null || pText.equals("")) {
      super.setToolTipText(null);
    }
    else {
      super.setToolTipText(pText);
    }
  }
}
TOP

Related Classes of DisplayProject.PasswordDataField

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.