223 lines
7.6 KiB
Java
223 lines
7.6 KiB
Java
/*
|
|
* Copyright (c) 2006,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.common.util.LiteList;
|
|
import com.foundation.tcv.swt.ICoolBar;
|
|
import com.foundation.view.IAbstractContainer;
|
|
import com.foundation.view.SingleAssociationContainer;
|
|
import com.foundation.view.SingleResourceAssociation;
|
|
|
|
public class CoolBar extends Container implements ICoolBar {
|
|
/** The collection of CoolItem instances contained by the cool bar. */
|
|
private LiteList coolItems = new LiteList(10, 20);
|
|
|
|
/**
|
|
* Encapsulates an item in the bar.
|
|
*/
|
|
public static class CoolItem extends AbstractComponent implements ICoolBar.ICoolItem {
|
|
private Container container = null;
|
|
/** The resource defining the visible state for the item. */
|
|
private SingleResourceAssociation isVisible = new SingleResourceAssociation(this, this, getViewContext(), SingleResourceAssociation.TYPE_BOOLEAN, false, Boolean.TRUE);
|
|
|
|
/**
|
|
* CoolItem 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.
|
|
* @see #STYLE_DROP_DOWN
|
|
*/
|
|
public CoolItem(Container parent, String name, int style) {
|
|
super(parent.getSessionViewController());
|
|
container = parent;
|
|
//Initialize the client component.//
|
|
sendMessage(MESSAGE_INITIALIZE, new int[] {parent.getNumber(), style});
|
|
((CoolBar) parent).addCoolItem(this);
|
|
}//CoolItem()//
|
|
/* (non-Javadoc)
|
|
* @see com.foundation.view.IAbstractComponent#getName()
|
|
*/
|
|
public String getName() {
|
|
return "__CoolBarItem__";
|
|
}//getName()//
|
|
/* (non-Javadoc)
|
|
* @see com.foundation.tcv.swt.server.AbstractComponent#internalViewInitialize()
|
|
*/
|
|
protected void internalViewInitialize() {
|
|
super.internalViewInitialize();
|
|
isVisible.initialize();
|
|
}//internalViewInitialize()//
|
|
/* (non-Javadoc)
|
|
* @see com.foundation.tcv.swt.server.AbstractComponent#internalViewRelease()
|
|
*/
|
|
protected void internalViewRelease() {
|
|
isVisible.release();
|
|
super.internalViewRelease();
|
|
}//internalViewRelease()//
|
|
/* (non-Javadoc)
|
|
* @see com.foundation.tcv.swt.server.AbstractComponent#internalViewRefresh()
|
|
*/
|
|
protected void internalViewRefresh() {
|
|
internalViewRefreshIsVisible();
|
|
sendMessage(MESSAGE_AUTO_SIZE, null);
|
|
}//internalViewRefresh()//
|
|
/**
|
|
* Refreshes whether the component is visible based on the attribute value or if null the default flag value.
|
|
*/
|
|
protected void internalViewRefreshIsVisible() {
|
|
if(isVisible.refresh()) {
|
|
sendMessage(MESSAGE_IS_VISIBLE, isVisible.getValue() == null ? Boolean.TRUE : (Boolean) isVisible.getValue());
|
|
}//if//
|
|
}//internalViewRefreshIsVisible()//
|
|
/* (non-Javadoc)
|
|
* @see com.foundation.view.swt.Component#internalOnValueChanged(com.foundation.view.SingleResourceAssociation)
|
|
*/
|
|
protected void internalOnValueChanged(SingleResourceAssociation resourceAssociation, int flags) {
|
|
if(resourceAssociation == isVisible) {
|
|
internalViewRefreshIsVisible();
|
|
}//if//
|
|
else {
|
|
super.internalOnValueChanged(resourceAssociation, flags);
|
|
}//else//
|
|
}//internalOnValueChanged()//
|
|
/**
|
|
* Sets the association container used to access the visibility.
|
|
* @param container The visibility association metadata.
|
|
*/
|
|
public void setIsVisibleAssociation(SingleAssociationContainer container) {
|
|
verifyThread();
|
|
this.isVisible.setAssociations(container);
|
|
}//setIsVisibleAssociation()//
|
|
/**
|
|
* Sets whether the component is visible (by default if an attribute is bound to this value).
|
|
* @param isVisible Whether the user can see the component.
|
|
*/
|
|
public void setIsVisible(boolean isVisible) {
|
|
verifyThread();
|
|
this.isVisible.setDefaultValue(isVisible ? Boolean.TRUE : Boolean.FALSE);
|
|
}//setIsVisible()//
|
|
/**
|
|
* Sets the cool item initial size.
|
|
* @param width
|
|
* @param height
|
|
*/
|
|
public void setSize(int width, int height) {
|
|
sendMessage(MESSAGE_SET_SIZE, new int[] {width, height});
|
|
}//setSize()//
|
|
/**
|
|
* Sets the cool item minimum size.
|
|
* @param width
|
|
* @param height
|
|
*/
|
|
public void setMinimumSize(int width, int height) {
|
|
sendMessage(MESSAGE_SET_MINIMUM_SIZE, new int[] {width, height});
|
|
}//setMinimumSize()//
|
|
/**
|
|
* Sets the cool item preferred size.
|
|
* @param width
|
|
* @param height
|
|
*/
|
|
public void setPreferredSize(int width, int height) {
|
|
sendMessage(MESSAGE_SET_PREFERRED_SIZE, new int[] {width, height});
|
|
}//setPreferredSize()//
|
|
/**
|
|
* Sets the control used by the cool item.
|
|
* @param control The cool item's control.
|
|
*/
|
|
public void setControl(Component control) {
|
|
sendMessage(MESSAGE_SET_CONTROL, new int[] {control.getNumber()});
|
|
}//setControl()//
|
|
/* (non-Javadoc)
|
|
* @see com.foundation.tcv.swt.server.AbstractComponent#getClientClassName()
|
|
*/
|
|
protected String getClientClassName() {
|
|
return "com.foundation.tcv.swt.client.CoolBar$CoolItem";
|
|
}//getClientClassName()//
|
|
/* (non-Javadoc)
|
|
* @see com.foundation.view.IAbstractComponent#getContainer()
|
|
*/
|
|
public IAbstractContainer getContainer() {
|
|
return container;
|
|
}//getContainer()//
|
|
}//CoolItem//
|
|
/**
|
|
* Button 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.
|
|
* @see #STYLE_ARROW
|
|
* @see #STYLE_CHECK
|
|
* @see #STYLE_PUSH
|
|
* @see #STYLE_RADIO
|
|
* @see #STYLE_TOGGLE
|
|
* @see #STYLE_FLAT
|
|
* @see #STYLE_LEFT
|
|
* @see #STYLE_RIGHT
|
|
* @see #STYLE_CENTER
|
|
* @see #STYLE_UP
|
|
* @see #STYLE_DOWN
|
|
*/
|
|
public CoolBar(Container parent, String name, int style) {
|
|
super(parent, name, style);
|
|
|
|
//Initialize the client component.//
|
|
sendMessage(MESSAGE_INITIALIZE, new int[] {parent.getNumber(), style});
|
|
}//CoolBar()//
|
|
/**
|
|
* Adds a cool item to the bar.
|
|
* @param coolItem The item to be added.
|
|
*/
|
|
protected void addCoolItem(CoolItem coolItem) {
|
|
coolItems.add(coolItem);
|
|
|
|
if(isInitialized()) {
|
|
//TODO: Initialize the cool item.
|
|
//Will the cool item's component already be initilialized?
|
|
//Would this ever occur?
|
|
}//if//
|
|
}//addCoolItem()//
|
|
/* (non-Javadoc)
|
|
* @see com.foundation.tcv.swt.server.AbstractComponent#internalViewInitializeAll()
|
|
*/
|
|
protected void internalViewInitializeAll() {
|
|
super.internalViewInitializeAll();
|
|
|
|
//Initialize all the cool items.//
|
|
for(int index = 0; index < coolItems.getSize(); index++) {
|
|
((CoolItem) coolItems.get(index)).internalViewInitialize();
|
|
}//for//
|
|
}//internalViewInitializeAll()//
|
|
/* (non-Javadoc)
|
|
* @see com.foundation.tcv.swt.server.AbstractComponent#internalViewReleaseAll()
|
|
*/
|
|
protected void internalViewReleaseAll() {
|
|
//Release all the cool items.//
|
|
for(int index = 0; index < coolItems.getSize(); index++) {
|
|
((CoolItem) coolItems.get(index)).internalViewRelease();
|
|
}//for//
|
|
|
|
super.internalViewReleaseAll();
|
|
}//internalViewReleaseAll()//
|
|
/* (non-Javadoc)
|
|
* @see com.foundation.tcv.swt.server.AbstractComponent#internalViewRefreshAll()
|
|
*/
|
|
protected void internalViewRefreshAll() {
|
|
super.internalViewRefreshAll();
|
|
|
|
//Refresh all the cool items.//
|
|
for(int index = 0; index < coolItems.getSize(); index++) {
|
|
((CoolItem) coolItems.get(index)).internalViewRefresh();
|
|
}//for//
|
|
}//internalViewRefreshAll()//
|
|
/* (non-Javadoc)
|
|
* @see com.foundation.tcv.swt.server.AbstractComponent#getClientClassName()
|
|
*/
|
|
protected String getClientClassName() {
|
|
return "com.foundation.tcv.swt.client.CoolBar";
|
|
}//getClientClassName()//
|
|
}//CoolBar// |