/* * Copyright (c) 2005,2009 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.tcv.swt.server; import com.foundation.tcv.swt.ILink; import com.foundation.tcv.view.ViewMessage; import com.foundation.view.IMethodAssociation; import com.foundation.view.SingleAssociationContainer; import com.foundation.view.SingleResourceAssociation; public class Link extends Component implements ILink { /** Called when the link is pressed. */ private IMethodAssociation selectionMethod = null; /** The button's text resource. */ private SingleResourceAssociation text = new SingleResourceAssociation(this, this, getViewContext(), SingleResourceAssociation.TYPE_TEXT, false, ""); /** * Link constructor. * @param parent A composite control which will be the parent of the new instance (cannot be null). * @param name The unique component name. * @param style The style of control to construct. */ public Link(Container parent, String name, int style) { super(parent, name, style); //Initialize the client component.// sendMessage(MESSAGE_INITIALIZE, new int[] {parent.getNumber(), style}); }//Link()// /** * Sets the selection method called when the link is pressed. * @param selectionMethod The method called when the link is pressed. */ public void setSelectionMethod(IMethodAssociation selectionMethod) { verifyThread(); this.selectionMethod = selectionMethod; }//setSelectionMethod()// /** * Sets the component text. * @param text The text that will appear in the component. */ public void setText(String text) { verifyThread(); this.text.setDefaultValue(text); }//setText()// /** * Sets the association container used to access the text. * @param container The text association metadata. */ public void setTextAssociation(SingleAssociationContainer container) { verifyThread(); this.text.setAssociations(container); }//setTextAssociation()// /* (non-Javadoc) * @see com.foundation.tcv.swt.server.AbstractComponent#internalViewInitialize() */ protected void internalViewInitialize() { super.internalViewInitialize(); text.initialize(); }//internalViewInitialize()// /* (non-Javadoc) * @see com.foundation.tcv.swt.server.AbstractComponent#internalViewRefresh() */ protected void internalViewRefresh() { super.internalViewRefresh(); internalViewRefreshText(); }//internalViewRefresh()// /** * Refreshes the link text. */ protected void internalViewRefreshText() { if(text.refresh()) { sendMessage(MESSAGE_SET_TEXT, (String) text.getValue()); }//if// }//internalViewRefreshText()// /* (non-Javadoc) * @see com.foundation.tcv.swt.server.AbstractComponent#internalViewRelease() */ protected void internalViewRelease() { super.internalViewRelease(); text.release(); }//internalViewRelease()// /* (non-Javadoc) * @see com.foundation.view.swt.AbstractComponent#internalOnValueChanged(com.foundation.view.SingleResourceAssociation) */ protected void internalOnValueChanged(SingleResourceAssociation resourceAssociation, int flags) { if(resourceAssociation == text) { internalViewRefreshText(); }//else if// else { super.internalOnValueChanged(resourceAssociation, flags); }//else// }//internalOnValueChanged()// /* (non-Javadoc) * @see com.foundation.tcv.view.IViewComponent#processMessage(com.foundation.tcv.model.ViewMessage) */ public Object processMessage(ViewMessage viewMessage) { Object retVal = null; switch(viewMessage.getMessageNumber()) { case MESSAGE_VIEW_SYNCHRONIZE_SELECTION: { //Call the selection method.// selectionMethod.invoke(null, true); break; }//case// default: { retVal = super.processMessage(viewMessage); }//default// }//switch// return retVal; }//processMessage()// /* (non-Javadoc) * @see com.foundation.tcv.swt.server.AbstractComponent#getClientClassName() */ protected String getClientClassName() { return "com.foundation.tcv.swt.client.Link"; }//getClientClassName()// }//Link//