home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-03-19 | 10.9 KB | 374 lines |
- /*
- * @(#ListPlus.java
- *
- * Copyright (c) 1997 Symantec Corporation. All Rights Reserved.
- *
- */
-
- package symantec.itools.db.awt;
-
- import java.util.*;
- import java.sql.*;
- import java.lang.*;
- import symantec.itools.db.net.*;
- import symantec.itools.db.pro.*;
- import java.awt.event.*;
- import symantec.itools.db.beans.binding.Name;
-
- /**
- * A dbAWARE ListPlus component.
- * <p>
- * This component can be "bound" to a projection within a relation view
- * so that it automatically gets and sets the values in that relation.
- * <p>
- */
- public class ListPlus extends java.awt.List implements ProjectionBean
- {
-
- /**
- * Constant value for the Triggering Event property.
- * Indicates the triggering event is FOCUS_LOST.
- */
- public static final int Focus_Event = ProjectionBeanHelper.Focus_Event;
- /**
- * Constant value for the Triggering Event property.
- * Indicates the triggering event is KEY_PRESSED.
- */
- public static final int Key_Event = ProjectionBeanHelper.Key_Event;
- /**
- * Constant value for the Triggering Event property.
- * Indicates the triggering event is ITEM_STATE_CHANGED.
- */
- public static final int Item_Event = ProjectionBeanHelper.Item_Event;
- /**
- * Constant value for the Triggering Event property.
- * Indicates the triggering event is ACTION_PERFORMED.
- */
- public static final int Action_Event = ProjectionBeanHelper.Action_Event;
-
- private boolean m_useStream = false;
-
- private ProjectionBeanHelper m_Helper = null;
- /**
- * The value of the Triggering Event property.
- * The type of event that triggers this component to commit its changes.
- * @see #getTriggeringEvent
- * @see #setTriggeringEvent
- * @see #Focus_Event
- * @see #Key_Event
- * @see #Item_Event
- * @see java.awt.Event#ACTION_EVENT
- */
- protected int TriggeringEvent=Item_Event;
-
- private int blockSize=10;
- private String IName;
- /**
- * Constructs a new ListPlus with no data connectivity, initially.
- *
- * @param rows defines the number of rows of items to display.
- */
- public ListPlus(int rows)
- {
- super(rows, false);
- m_Helper = new ProjectionBeanHelper(this);
- this.setTriggeringEvent(symantec.itools.db.awt.ListPlus.Item_Event);
- setMultipleSelections(false);
- }
-
- /**
- * Constructs a default ListPlus with no data connectivity, initially.
- */
- public ListPlus()
- {
- this(0);
- }
-
- /**
- * Adds the specified item to the end of the list.
- * @param item the item to be added
- */
- public synchronized void addItem(String item) {
- super.addItem(item, -1);
- staticItems.addElement(item);
- }
-
- private Vector staticItems = new Vector();
-
- // ProjectionBean interface methods
- /**
- * Sets whether the data value of this component may be modified.
- * @param value <code>true</code> if the value may not be modified,
- * <code>false</code>if the value may be modified
- */
- public void setReadOnly(boolean value)
- {
- }
-
- /**
- * Sets the value of this component to the given value.
- * @param value the new component value
- * @see #getData
- */
- String oldValue;
- public void setData(Object value) {
-
- boolean bitemFound = false;
- if(value!=null)
- {
- oldValue=value.toString();
- String text = value.toString();
- int numberOfRows=countItems();
- for (int index = 0; index < numberOfRows; index++)
- {
- if (text.equals(getItem(index)))
- {
- select(index);
- makeVisible(index);
- bitemFound = true;
- break;
- }
- }
- }
- if (!bitemFound)
- {
- int hasSelection=getSelectedIndex();
- if (hasSelection != -1)
- {
- deselect(hasSelection);
- }
- }
-
- }
-
- /**
- * Gets the one-relative index of the currently selected list item.
- * @return the one-relative item index, or 0 if no item is selected
- * @see #setIndexFromOne
- */
- public int getIndexFromOne()
- {
- return getSelectedIndex()+1;
- }
- /**
- * Selects a list item using its one-relative index.
- * @param i the one-relative item index
- * @see #getIndexFromOne
- */
- public void setIndexFromOne(int i)
- {
- select(i-1);
- }
-
- /**
- * Gets the value of this component.
- * @return the current component value
- * @see #setData
- */
- public Object getData() {
- return getSelectedItem();
- }
-
- /**
- * Gets whether this component saves its value as a text String.
- * @return <code>true</code> if the value is saved as text,
- * <code>false</code> otherwise
- */
- public boolean isTextBased() {
- return true;
- }
-
- /**
- * Gets the number of digits to the right of the decimal point for
- * this component's value.
- * @return the number of digits to the right of the decimal point
- */
- public int getScale() {
- return ProjBinder.DEFAULTSCALE;
- }
-
- /**
- * Registers the standard event listener(s) for this component.
- */
- public void registerListeners() {
- addItemListener(m_Helper);
- }
-
- // Lookup methods...
- symantec.itools.db.beans.binding.Mediator m_LookupMediator;
- Name lookupName=new Name();
- private String[] m_GetMethods={"getDataAt(row)"};
- private String[] m_SetMethods={"setDataAt(row,Value)"};
- private boolean isLookup=false;
-
- /**
- * Sets the value of the Lookup Name property.
- * This property is the name of a data source table and column.
- * It is used to fill this component with data.
- * @param lame the new lookup name
- * @see #getLookupName
- */
- public void setLookupName(String lname)
- {
- Name name = new Name(lname);
- isLookup=true;
- if(m_LookupMediator==null){
- m_LookupMediator =new symantec.itools.db.beans.binding.Mediator() ;
- m_LookupMediator.setOutput(this);
- m_LookupMediator.setSetMethods(m_SetMethods);
- }
- if(name.getNumberOfRows()==1)name.setNumberOfRows(-1);
- lookupName=name;
- m_LookupMediator.setDataBinding(name.getFullName());
- if(IName!=null)m_Helper.setDataBinding(new Name(IName));
-
- }
- /**
- * Gets the value of the Lookup Name property.
- * This property is the name of a data source table and column.
- * It is used to fill this component with data.
- * @return the property value
- * @see #setLookupName
- */
- public String getLookupName()
- {
- return lookupName.getFullName();
- }
- /**
- * Sets the value stored at a particular row.
- * @param row the zero-relative row index
- * @param value the new value
- * @see #getDataAt
- */
- int currentItems=0;
- String Value;
- public void setDataAt(int row,Object value)
- {
- int totalItems=countItems();
- int newNumberRows=m_LookupMediator.getOutputSize().height;
- if(currentItems>newNumberRows)
- {
- for(int r=newNumberRows;r<currentItems;r++)
- {
- delItem(0);
- }
- currentItems=newNumberRows;
- totalItems=newNumberRows;
- }
-
- if(row >=totalItems)
- {
- for(int i=totalItems;i<=row ;i++)
- {
- addItem(" ",i);
- }
- }
- if(value==null)value="";
- Value=value.toString();
- if(!getItem(row).equals(Value))replaceItem(Value,row );
- if(Value.equals("")){
- select(row);
- oldValue=null;
- }
- if(oldValue!=null)
- {
-
- if(oldValue.equals(Value)){
- select(row);
- oldValue=null;
- }
- }
- currentItems=newNumberRows;
-
-
- }
- /**
- * Gets the value stored at a particular row.
- * @param row the zero-relative row index
- * @return the value
- * @see #setDataAt
- */
- public Object getDataAt(int row)
- {
- int totalItems=countItems();
- if(row<totalItems)return (Object)getItem(row);
- return "";
- }
-
- /**
- * Sets the name of the data item to bind this component to.
- * @param name the data item name, like "MyTable@MyColumn"
- * @see #getDataBinding
- */
- public void setDataBinding(String name)
- {
- IName=name;
- m_Helper.setDataBinding(new Name(IName));
- }
-
- /**
- * Gets the name of the data item this component is bound to.
- * @returns the data item name, like "MyTable@MyColumn"
- * @see #setDataBinding
- */
- public String getDataBinding()
- {
- return m_Helper.getDataBinding().getFullName();
- }
-
- void removeAllListeners()
- {
- this.removeFocusListener(m_Helper);
- this.removeActionListener(m_Helper);
- this.removeItemListener(m_Helper);
- this.removeKeyListener(m_Helper);
- }
- /**
- * Sets the value of the Triggering Event property.
- * This determines the type of event that triggers the component to commit
- * its changes to the database.
- * @param event one of Focus_Event, Action_Event, Key_Event, or Item_Event
- * @see #getTriggeringEvent
- * @see #Focus_Event
- * @see java.awt.Event#ACTION_EVENT
- * @see #Key_Event
- * @see #Item_Event
- */
- public void setTriggeringEvent(int Event)
- {
- TriggeringEvent=Event;
- this.removeAllListeners();
- switch(Event){
- case symantec.itools.db.awt.ProjectionBeanHelper.Focus_Event:
- (this).addFocusListener(m_Helper);
- break;
- case symantec.itools.db.awt.ProjectionBeanHelper.Action_Event:
- (this).addActionListener(m_Helper);
- break;
- case symantec.itools.db.awt.ProjectionBeanHelper.Item_Event:
- (this).addItemListener(m_Helper);
- break;
- case symantec.itools.db.awt.ProjectionBeanHelper.Key_Event:
- (this).addKeyListener(m_Helper);
- break;
- default:
- (this).addActionListener(m_Helper);
- }
- }
- /**
- * Gets the current value of the Triggering Event property.
- * This determines the type of event that triggers the component to commit
- * its changes to the database.
- * @return one of Focus_Event, Action_Event, Key_Event, or Item_Event
- * @see #setTriggeringEvent
- * @see #Focus_Event
- * @see java.awt.Event#ACTION_EVENT
- * @see #Key_Event
- * @see #Item_Event
- */
- public int getTriggeringEvent()
- {
- return TriggeringEvent;
- }
- }
-