Files
Brainstorm/Foundation/src/com/foundation/view/MethodAssociation.java
2014-05-30 10:31:51 -07:00

84 lines
3.4 KiB
Java

/*
* Copyright (c) 2003,2007 Declarative Engineering LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Declarative Engineering LLC
* verson 1 which accompanies this distribution, and is available at
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
*/
package com.foundation.view;
import com.common.debug.*;
public class MethodAssociation extends ValueHolderAssociation implements IMethodAssociation {
private int associationNumber = 0;
private IAssociationHandler handler = null;
/** The listener for held value changed notifications. */
private IMethodAssociationChangeListener listener = null;
/**
* MethodAssociation constructor.
* @param handler The object that handles the method invocations.
* @param associationNumber The association number which will be passed to the handler when the assocation is invoked. This number allows fast indexing of the methods that the handler handles.
* @param component The component the association is connected to.
* @param valueHolderName The optional name of the value holder for the association.
* @param heldType The optional class which is a subclass of the value holder's held type and defines the association.
* @param rowType The optional class which defines the association if a held type or value holder is not provided, and it determines whether this association is used based on whether it matches the control's row type.
*/
public MethodAssociation(IAssociationHandler handler, int associationNumber, IAbstractComponent component, String valueHolderName, Class heldType, Class rowType) {
super(component, valueHolderName, heldType, rowType);
this.handler = handler;
this.associationNumber = associationNumber;
}//MethodAssociation()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.server.IMethodAssociation#invoke(java.lang.Object[], boolean)
*/
public Object invoke(Object[] parameters, boolean synchronous) {
return invoke(null, parameters, synchronous);
}//invoke()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.server.IMethodAssociation#invoke(java.lang.Object, java.lang.Object[], boolean)
*/
public Object invoke(final Object value, final Object[] parameters, boolean synchronous) {
Object result = null;
Object object = value != null ? value : getValueHolder().getValue();
try {
if(object != null) {
result = handler.invokeMethod(associationNumber, object, parameters);
}//if//
}//try//
catch(Throwable e) {
Debug.log(e);
}//catch//
return result;
}//invoke()//
/* (non-Javadoc)
* @see com.foundation.view.IMethodAssociation#heldValueChanged()
*/
public void heldValueChanged() {
listener.onEventFired(this);
}//heldValueChanged()//
/* (non-Javadoc)
* @see com.foundation.view.IMethodAssociation#register()
*/
public void register() {
if(getIsValueHolderAssociated()) {
getValueHolder().registerListener(this);
}//if//
}//register()//
/* (non-Javadoc)
* @see com.foundation.view.IMethodAssociation#unregister()
*/
public void unregister() {
if(getIsValueHolderAssociated()) {
getValueHolder().unregisterListener(this);
}//if//
}//unregister()//
/* (non-Javadoc)
* @see com.foundation.view.IMethodAssociation#setChangeListener(com.foundation.view.IMethodAssociationChangeListener)
*/
public void setChangeListener(IMethodAssociationChangeListener listener) {
this.listener = listener;
}//setChangeListener()//
}//MethodAssociation//