Package Express.windows

Source Code of Express.windows.ArrayDesc

/*
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 Express.windows;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;

import javax.swing.JCheckBox;
import javax.swing.JComponent;

import DisplayProject.Array_Of_JComponent;
import DisplayProject.BodyGrid;
import DisplayProject.Constants;
import DisplayProject.RadioList;
import DisplayProject.UIutils;
import DisplayProject.actions.ArrayTopRow;
import DisplayProject.actions.ArrayVisibleRows;
import DisplayProject.actions.ColourChange;
import DisplayProject.actions.Column;
import DisplayProject.actions.ColumnCount;
import DisplayProject.actions.Name;
import DisplayProject.actions.Row;
import DisplayProject.actions.WidgetState;
import DisplayProject.binding.beans.ExtendedPropertyChangeSupport;
import DisplayProject.binding.beans.Observable;
import DisplayProject.controls.ArrayField;
import Express.services.Array_Of_BusinessClass;
import Express.services.BusinessClass;
import Framework.RuntimeProperties;

/**
* The ArrayDesc class defines enhancements to the {@link DisplayProkect.controls.ArrayField}.
* <p>
* @author ITerative Consulting
* @since  26-Feb-2008
*/
@RuntimeProperties(isDistributed=false, isAnchored=false, isShared=false, isTransactional=false)
@SuppressWarnings("serial")
public class ArrayDesc
        implements Serializable, Observable
{

    // ----------
    // Attributes
    // ----------
    public PropertyChangeSupport qq_Listeners = new ExtendedPropertyChangeSupport(this, true);
    private int currentRow;
    private Array_Of_BusinessClass<BusinessClass> data;
    private ArrayField field;

    // ------------
    // Constructors
    // ------------
    public ArrayDesc() {
        // Explicitly call the superclass constructor to prevent the implicit call
        super();
        this.currentRow = 0;
        this.data = null;
        this.field = null;
    }

    // ----------------------
    // Accessors and Mutators
    // ----------------------
    public void setCurrentRow(int currentRow) {
        int oldValue = this.currentRow;
        this.currentRow = currentRow;
        this.qq_Listeners.firePropertyChange("currentRow", oldValue, this.currentRow);
    }

    public int getCurrentRow() {
        return this.currentRow;
    }

    public void setData(Array_Of_BusinessClass<BusinessClass> data) {
        Array_Of_BusinessClass<BusinessClass> oldValue = this.data;
        this.data = data;
        this.qq_Listeners.firePropertyChange("data", oldValue, this.data);
    }

    public Array_Of_BusinessClass<BusinessClass> getData() {
        return this.data;
    }

    public void setField(ArrayField field) {
        ArrayField oldValue = this.field;
        this.field = field;
        this.qq_Listeners.firePropertyChange("field", oldValue, this.field);
    }

    public ArrayField getField() {
        return this.field;
    }

    // -------
    // Methods
    // -------
    public void addPropertyChangeListener(String property, PropertyChangeListener listener) {
        qq_Listeners.addPropertyChangeListener(property, listener);
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        qq_Listeners.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(String property, PropertyChangeListener listener) {
        qq_Listeners.removePropertyChangeListener(property, listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        qq_Listeners.removePropertyChangeListener(listener);
    }

    /**
     * deselectRow<p>
     * DeselectRow<br>
     *     DeselectRow removes the row highlight from<br>
     *     the given row.<br>
     * <p>
     * <p>
     * <p>
     * if called from SelectRow, the row number given has<br>
     * already been corrected to fit within the acceptable<br>
     * boundaries.  (ie. Index passed in may be 17, but only<br>
     * five rows displayed in the array, so 17 must be corrected<br>
     * to a number between 1 and 5).<br>
     * <p>
     * @param row Type: int
     * @param alreadyCorrected Type: boolean (Input) (default in Forte: FALSE)
     */
    public void deselectRow(int row, boolean alreadyCorrected) {
        if (alreadyCorrected == false && ArrayTopRow.get(this.getField()) != 0) {
            row = row-ArrayTopRow.get(this.getField())+1;
        }
        if (row >= 1 && row <= ArrayVisibleRows.get(this.getField())) {

            for (int c = 1; c <= ColumnCount.get(BodyGrid.get(this.getField())); c++) {
                if (WidgetState.get(this.getField().getColumnTemplate(c)) == Constants.FS_UPDATE || WidgetState.get(this.getField().getColumnTemplate(c)) == Constants.FS_QUERY) {

                    if (this.getField(row, c) instanceof JCheckBox || this.getField(row, c) instanceof RadioList) {
                        ColourChange.setBackground(this.getField(row, c), Constants.C_GRAY2);
                    }
                    else {
                        ColourChange.setBackground(this.getField(row, c), Constants.C_WHITE);
                    }
                }
                else {
                    ColourChange.setBackground(this.getField(row, c), Constants.C_GRAY2);
                }
            }
        }
    }
    public void deselectRow(int row) {
      this.deselectRow(row, false);
    }

    /**
     * getField<p>
     * GetField<br>
     *     GetField returns the field at the given row and<br>
     *     column in the given array of fields (assumed to<br>
     *     be the BodyGrid from the array field).<br>
     * <p>
     * @param row Type: int
     * @param column Type: int
     * @return JComponent
     */
    public JComponent getField(int row, int column) {
        Array_Of_JComponent<JComponent> qq_localVector = new Array_Of_JComponent<JComponent>(JComponent.class, BodyGrid.get(this.getField()).getComponents());
        if (qq_localVector != null) {
            for (JComponent f : qq_localVector) {
                if (Row.get(f) == row && Column.get(f) == column) {
                    return f;
                }
            }
        }

        return null;
    }

    /**
     * getField<p>
     * GetField<br>
     *     GetField returns the field at the given row and<br>
     *     column in the given array of fields (assumed to<br>
     *     be the BodyGrid from the array field).<br>
     * <p>
     * @param row Type: int
     * @param column Type: String
     * @param correctRowIndex Type: boolean (Input) (default in Forte: TRUE)
     * @return JComponent
     */
    public JComponent getField(int row, String column, boolean correctRowIndex) {
        if (correctRowIndex) {
            row = row-ArrayTopRow.get(this.getField())+1;
        }

        Array_Of_JComponent<JComponent> qq_localVector = new Array_Of_JComponent<JComponent>(JComponent.class, BodyGrid.get(this.getField()).getComponents());
        if (qq_localVector != null) {
            for (JComponent f : qq_localVector) {
                if (Row.get(f) == row && Name.get(f).compare(column) == 0) {
                    return f;
                }
            }
        }

        return null;
    }

    /**
     * selectRow<p>
     * SelectRow<br>
     *      SelectRow sets the fill color on all fields in the<br>
     *     given row to the highlight color.<br>
     * <p>
     * <p>
     * <p>
     * return the previously selected row's background to normal<br>
     * <p>
     * @param row Type: int
     */
    public void selectRow(int row) {
        if (row-ArrayTopRow.get(this.getField())+1 != this.getCurrentRow()) {
            this.deselectRow(this.getCurrentRow(), true);
        }

        //
        // make the given record the current row in the array field.
        //
        UIutils.setCurrentRow(this.getField(), row);

        //
        // Calculate the row of the array field on the screen
        // that this record occupies (the array field has some
        // number of displayed rows on the screen, the underlying
        // data may have many more rows).
        //
        if (ArrayTopRow.get(this.getField()) != 0) {
            this.setCurrentRow(row-ArrayTopRow.get(this.getField())+1);
        }
        else {
            this.setCurrentRow(row);
        }

        //
        // now set the newly selected row's background to show that
        // it's the selected row.
        //
        if (this.getCurrentRow() >= 1 && this.getCurrentRow() <= ArrayVisibleRows.get(this.getField())) {
            for (int c = 1; c <= ColumnCount.get(BodyGrid.get(this.getField())); c++) {
                //
                // Save the current colors in case the are different
                // than what is normal.
                //
                // Don't set the color of a toggleField
                if (!(this.getField().getColumnTemplate(c) instanceof JCheckBox)) {
                    if (WidgetState.get(this.getField().getColumnTemplate(c)) == Constants.FS_UPDATE || WidgetState.get(this.getField().getColumnTemplate(c)) == Constants.FS_QUERY) {
                        ColourChange.setBackground(this.getField(this.getCurrentRow(), c), Constants.C_PALEYELLOW);
                    }
                    else {
                        ColourChange.setBackground(this.getField(this.getCurrentRow(), c), Constants.C_GRAY1);
                    }
                }
            }
        }
    }
// end class ArrayDesc
// c Pass 2 Conversion Time: 297 milliseconds
TOP

Related Classes of Express.windows.ArrayDesc

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.