Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  // Copyright 2004, 2005 The Apache Software Foundation
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  //     http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
 // distributed under the License is distributed on an "AS IS" BASIS,
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
 package org.apache.tapestry.form;

Decorates an underlying IPropertySelectionModeladding an initial property. The label, option, and value of the initial property are configurable.

By default, the label will be rendered as disabled if its option is null. This behavior can be changed by setLabelAlwaysEnabled(boolean).

Author(s):
Paul Ferraro
Since:
4.0
 
 {
    
Empty model implementation. Avoids NullPointerExceptions when default constructor is used.
 
     private static final IPropertySelectionModel EMPTY_MODEL = new IPropertySelectionModel()
     {
        
 
         public int getOptionCount()
         {
             return 0;
         }

        
 
         public Object getOption(int index)
         {
             return null;
         }

        
 
         public String getLabel(int index)
         {
             return null;
         }

        
 
         public String getValue(int index)
         {
             return null;
         }
 
         public boolean isDisabled(int index)
         {
             return false;
         }
        
        
 
         public Object translateValue(String value)
         {
             return null;
         }
     };
     
     private IPropertySelectionModel _model;
 
     private String _label = "";
 
     private Object _option = null;
 
     private String _value = "";
 
     private boolean _labelAlwaysEnabled;
    
    
Constructs a new LabeledPropertySelectionModel using an empty model and default label, option, and value. Default constructor is made available so that this model may be specified as a component helper bean.
 
     {
         this();
     }

    
Constructs a new LabeledPropertySelectionModel using the specified model and default label, option, and value.

Parameters:
model the underlying model to decorate
    {
         = model;
    }

    
Constructs a new LabeledPropertySelectionModel using the specified model and label, and default option and value.

Parameters:
model the underlying model to decorate
label the label of the initial property
    {
        this(model);
         = label;
    }

    
Constructs a new LabeledPropertySelectionModel using the specified model, label, and option; and default value.

Parameters:
model the underlying model to decorate
label the label of the initial property
option the option value of the initial property
    public LabeledPropertySelectionModel(IPropertySelectionModel modelString labelObject option)
    {
        this(modellabel);
         = option;
    }

    
Constructs a new LabeledPropertySelectionModel using the specified model, label, option, and value.

Parameters:
model the underlying model to decorate
label the label of the initial property
option the option value of the initial property
value the value of the initial property
    public LabeledPropertySelectionModel(IPropertySelectionModel modelString labelObject optionString value)
    {
        this(modellabeloption);
         = value;
    }

    
Constructs a new LabeledPropertySelectionModel using the specified model, label, option, and value.

Parameters:
model the underlying model to decorate
label the label of the initial property
option the option value of the initial property
value the value of the initial property
labelAlwaysEnabled if the label should always be enabled
    public LabeledPropertySelectionModel(IPropertySelectionModel modelString labelObject optionString value,
                                         boolean labelAlwaysEnabled)
    {
        this(modellabeloptionvalue);
         = labelAlwaysEnabled;
    }

    
Returns the underlying IPropertySelectionModel.

Returns:
the underlying IPropertySelectionModel
    {
        return ;
    }

    
Sets the underlying IPropertySelectionModel.

Parameters:
model the IPropertySelectionModel to set
    public void setModel(IPropertySelectionModel model)
    {
         = model;
    }

    
    public int getOptionCount()
    {
        return .getOptionCount() + 1;
    }

    
    public Object getOption(int index)
    {
        return (index == 0) ?  : .getOption(index - 1);
    }

    
    public String getLabel(int index)
    {
        return (index == 0) ?  : .getLabel(index - 1);
    }

    
    public String getValue(int index)
    {
        return (index == 0) ?  : .getValue(index - 1);
    }
    public boolean isDisabled(int index)
    {
        return index == 0 ? (! &&  == null) : .isDisabled(index - 1);
    }
    
    
    public Object translateValue(String value)
    {
        if (value == null)
            return null;
        
        return value.equals() ?  : .translateValue(value);
    }

    
Returns the label of the initial IPropertySelectionModel option.

Returns:
a IPropertySelectionModel option label
    public String getLabel()
    {
        return ;
    }

    
Sets the label of the initial IPropertySelectionModel option.

Parameters:
label a IPropertySelectionModel option label
    public void setLabel(String label)
    {
         = label;
    }

    
Returns the value of the initial IPropertySelectionModel option.

Returns:
a IPropertySelectionModel option value
    public String getValue()
    {
        return ;
    }

    
Sets the value of the initial IPropertySelectionModel option.

Parameters:
value a IPropertySelectionModel option value
    public void setValue(String value)
    {
         = value;
    }

    
Returns the initial option.

Returns:
a PropertySelectionModel option
    public Object getOption()
    {
        return ;
    }

    
Sets the initial IPropertySelectionModel option.

Parameters:
option a IPropertySelectionModel option
    public void setOption(Object option)
    {
         = option;
    }

    
Returns if label should always be enabled.
    public boolean isLabelAlwaysEnabled()
    {
        return ;
    }

    
Sets the state of the label.
    public void setLabelAlwaysEnabled(boolean labelAlwaysEnabled)
    {
         = labelAlwaysEnabled;
    }
New to GrepCode? Check out our FAQ X