FileDocCategorySizeDatePackage
MVCUtils.javaAPI DocGlassfish v2 API14353Fri May 04 22:34:58 BST 2007com.sun.enterprise.tools.common.ui

MVCUtils

public class MVCUtils extends Object
author
vkraemer
version

Fields Summary
private static final String
TRUE
private static final String
EMPTY
Constructors Summary
private MVCUtils()
Creates new MVCUtils

    
Methods Summary
private static java.lang.StringgetStringElementValue(java.lang.Object model, java.lang.String propName)

        String retVal = EMPTY;
        Method reader = null;
        try {
            PropertyDescriptor destPd = new PropertyDescriptor(propName, model.getClass());
            reader = destPd.getReadMethod();
            Object tmp = reader.invoke(model,null);
            if (null != tmp)
                retVal =tmp.toString();
        }
        catch (Throwable t) {
            Reporter.critical(new StackTrace(t)); //NOI18N
        }
        return retVal;
    
public static voidlinkBooleanStringElement(java.lang.Object model, javax.swing.AbstractButton view, java.lang.String propName)

 //NOI18N
    
             
          
        view.addItemListener(new BooleanStringItemListener(model, propName));
        view.setSelected(getStringElementValue(model, propName).equals(TRUE));
    
public static voidlinkBooleanStringElement(java.lang.Object model, javax.swing.AbstractButton view)

        String propName = view.getName();
        if (null != propName) {
            linkBooleanStringElement(model,view,propName);
        }
        else
            Reporter.critical("the name of the " + model + " is null"); //NOI18N
    
public static voidlinkIntStringElement(java.lang.Object model, javax.swing.text.JTextComponent view, java.lang.String propName)

        view.addKeyListener(new IntStringItemListener(model,propName));
        view.setText(getStringElementValue(model,propName));
    
public static voidlinkIntStringElement(java.lang.Object model, javax.swing.text.JTextComponent view, java.lang.String propName, int defaultValue)

        view.addKeyListener(new IntStringItemListener(model,propName));
        String tval = getStringElementValue(model,propName);
        view.setText(getStringElementValue(model,propName));
        if (null == tval || tval.equals(EMPTY))
            view.setText(EMPTY + defaultValue);
    
public static voidlinkIntStringElement(java.lang.Object model, javax.swing.text.JTextComponent view, java.lang.String propName, int min, int max)

        view.addKeyListener(new IntStringItemListener(model,propName, min, max));
//        String tval = getStringElementValue(model,propName);
        view.setText(getStringElementValue(model,propName));
//        if (null == tval || tval.equals(""))
//            view.setText("" + defaultValue);
    
public static voidlinkIntStringElement(java.lang.Object model, javax.swing.text.JTextComponent view, java.lang.String propName, int defaultValue, int min, int max)

        view.addKeyListener(new IntStringItemListener(model,propName, min, max));
        String tval = getStringElementValue(model,propName);
        view.setText(getStringElementValue(model,propName));
        if (null == tval || tval.equals(EMPTY))
            view.setText(EMPTY + defaultValue);
    
public static voidlinkStringElement(java.lang.Object model, javax.swing.text.JTextComponent view, java.lang.String propName)

        view.addKeyListener(new StringItemListener(model,propName));
        view.setText(getStringElementValue(model,propName));
    
public static voidlinkStringElement(java.lang.Object model, javax.swing.text.JTextComponent view)

        String propName = view.getName();
        if (null != propName) {
            linkStringElement(model,view,propName);
        }
        else
            Reporter.critical("the name of the " + model + " is null"); //NOI18N
    
public static voidselectionSensitive(java.lang.Object hasListSelectionModel, java.awt.Component sensitiveItem)

        try {
            Method getter = hasListSelectionModel.getClass().getMethod("getSelectionModel",null); //NOI18N
            javax.swing.ListSelectionModel lsm[] = new javax.swing.ListSelectionModel[1];
            Class lsmArgs[] = { javax.swing.ListSelectionModel.class };
            if (null != getter) {
                lsm[0] = (javax.swing.ListSelectionModel) getter.invoke(hasListSelectionModel,null);
                if (null == lsm[0]) {
                    lsm[0] = new javax.swing.DefaultListSelectionModel();
                    Method putter = hasListSelectionModel.getClass().getMethod("setSelectionModel", lsmArgs); //NOI18N
                    putter.invoke(hasListSelectionModel,lsm);
                }
                lsm[0].addListSelectionListener(new SelectionActivator(sensitiveItem, hasListSelectionModel));
            }
        }
        catch (Throwable t) {
            Reporter.critical(new StackTrace(t)); //NOI18N
        }
    
public static voidvalidationSensitive(javax.swing.text.JTextComponent f, java.awt.Component sensitive, com.sun.enterprise.tools.common.Validator v)

        StringValidationListener svl = 
            new StringValidationListener(sensitive,v);
        
        f.addKeyListener(svl);