Initial commit from SVN.

This commit is contained in:
wcrisman
2014-05-30 10:31:51 -07:00
commit b45e56b890
1968 changed files with 370949 additions and 0 deletions

View File

@@ -0,0 +1,476 @@
/*
* 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.client.cell;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Button;
import com.common.thread.IRunnable;
import com.common.util.IIterator;
import com.foundation.tcv.client.view.ResourceHolder;
import com.foundation.tcv.swt.cell.ICellButton;
import com.foundation.tcv.swt.client.ICellContainer;
import com.foundation.tcv.swt.client.RowObject;
import com.foundation.tcv.view.ViewMessage;
import com.foundation.view.AbstractResourceHolder;
import com.foundation.view.JefImage;
import com.foundation.view.swt.util.SwtUtilities;
public class CellButton extends CellComponent implements ICellButton {
/** The control style. */
private int style = 0;
/** The control's default selection state. */
private Boolean selection = Boolean.FALSE;
/** Whether selection notifications to the server will block for a response. */
private boolean blockOnSelections = false;
/** Whether the selection state should be auto-synchronized. */
private boolean autoSynchronizeSelection = true;
/** The delay to be used when auto synchronizing changes. */
private long autoSynchronizeSelectionDelay = 500;
/** A holder for the value of the text. */
private ResourceHolder textHolder = new ResourceHolder(this);
/** A holder for the value of the image. */
private ResourceHolder imageHolder = new ResourceHolder(this);
/** The swt image last held by the image holder. */
private Image swtImage = null;
/**
* Maintains the cell data for the control. A control may only exist if it is visible, but the data must be maintained regardless.
*/
public class ButtonCellControlData extends CellControlData {
/** The control's selection state. */
private Boolean selection = null;
/** The control's text. */
private Object text = null;
/** The control's image. */
private Object image = null;
/**
* ButtonCellControlData constructor.
* @param rowObject The row for the cell.
*/
public ButtonCellControlData(RowObject rowObject) {
super(rowObject);
}//ButtonCellControlData()//
}//ButtonCellControlData//
/**
* Encapsulates a control with related data such as listeners and the data model for the cell.
*/
public class ButtonCellControl extends CellControl implements SelectionListener {
/** The last set image. This will be used to dispose of the image. */
private Image swtImage = null;
/** The resource holder for the text. */
private ResourceHolder textHolder = new ResourceHolder(this);
/** The resource holder for the image. */
private ResourceHolder imageHolder = new ResourceHolder(this);
/** Whether the button tracks a state. */
private final boolean isStateful;
/** The task that auto synchronizes the selection state after a short delay. */
private Task autoSynchronizeSelectionTask = null;
/**
* ButtonCellControl constructor.
* @param control The control being encapsulated.
* @param cellData The cell's data.
*/
public ButtonCellControl(Button control, ButtonCellControlData cellData) {
super(control, cellData);
isStateful = ((control.getStyle() & SWT.CHECK) > 0) || ((control.getStyle() & SWT.RADIO) > 0) || ((control.getStyle() & SWT.TOGGLE) > 0);
getSwtButton().addSelectionListener(this);
}//ButtonCellControl()//
/**
* Gets the button cell data for the control.
* @return The cell data for the button control.
*/
public ButtonCellControlData getButtonCellControlData() {
return (ButtonCellControlData) getCellControlData();
}//getButtonCellControlData()//
/**
* Gets the button control.
* @return The button being encapsulated.
*/
public Button getSwtButton() {
return (Button) getSwtControl();
}//getSwtButton()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent.CellControl#initialize()
*/
public void initialize() {
super.initialize();
}//initialize()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent.CellControl#refresh()
*/
public void refresh() {
super.refresh();
refreshImage();
refreshSelection();
refreshText();
}//refresh()//
/**
* Refreshes the image value.
*/
public void refreshImage() {
imageHolder.setValue(getButtonCellControlData().image != null ? getButtonCellControlData().image : CellButton.this.imageHolder.getValue());
}//refreshImage()//
/**
* Refreshes the selection value.
*/
public void refreshSelection() {
if(isStateful) {
controlSetSelection(getButtonCellControlData().selection != null ? getButtonCellControlData().selection.booleanValue() : CellButton.this.selection != null ? CellButton.this.selection.booleanValue() : false);
}//if//
}//refreshSelection()//
/**
* Refreshes the text value.
*/
public void refreshText() {
textHolder.setValue(getButtonCellControlData().text != null ? getButtonCellControlData().text : CellButton.this.textHolder.getValue());
}//refreshText()//
/* (non-Javadoc)
* @see com.foundation.view.swt.cell.CellComponent.CellControl#release()
*/
public void release() {
if(textHolder != null) {
textHolder.release();
}//if//
if(imageHolder != null) {
imageHolder.release();
}//if//
if((swtImage != null) && (!swtImage.isDisposed())) {
swtImage.dispose();
}//if//
if(!getSwtButton().isDisposed()) {
getSwtButton().removeSelectionListener(this);
}//if//
//Ignore any pending synchronizations.//
synchronized(this) {
if(autoSynchronizeSelectionTask != null) {
removeTask(autoSynchronizeSelectionTask);
autoSynchronizeSelectionTask = null;
}//if//
}//synchronized//
super.release();
}//release()//
/**
* Forces any pending synchronizations to complete.
*/
public void synchronize() {
if(autoSynchronizeSelectionTask != null) {
removeTask(autoSynchronizeSelectionTask);
autoSynchronizeSelectionTask.execute();
autoSynchronizeSelectionTask = null;
}//if//
}//synchronize()//
/* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
*/
public void widgetDefaultSelected(SelectionEvent event) {
}//widgetDefaultSelected()//
/* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
public void widgetSelected(SelectionEvent event) {
selectionChanged(getSwtButton().getSelection());
}//widgetSelected()//
/**
* Called when the selection is changed in the view control.
* This method updates all bindings and
* @param isSelected Whether the control is selected (stateful controls only).
*/
protected void selectionChanged(final boolean isSelected) {
if(blockOnSelections || autoSynchronizeSelection) {
if((!blockOnSelections) && (autoSynchronizeSelectionDelay > 0)) {
//Start a task to send the text to the server after a short delay. This will reduce the overhead of auto synchronizing the selection.//
synchronized(this) {
if(autoSynchronizeSelectionTask != null) {
removeTask(autoSynchronizeSelectionTask);
}//if//
autoSynchronizeSelectionTask = new Task() {
public void execute() {
//Make sure that this task is still valid and is not being superceeded.//
synchronized(ButtonCellControl.this) {
if(autoSynchronizeSelectionTask == this) {
//Cleanup after the task.//
autoSynchronizeSelectionTask = null;
getEventLoop().executeAsync(new IRunnable() {
public Object run() {
sendMessage(MESSAGE_VIEW_SYNCHRONIZE_SELECTION, isSelected ? Boolean.TRUE : Boolean.FALSE, null, getButtonCellControlData().getRowObject().getObjectId(), 0);
return null;
}//run()//
});
}//if//
}//synchronized//
}//run()//
};
addTask(autoSynchronizeSelectionTask, autoSynchronizeSelectionDelay);
}//synchronized//
}//if//
else {
if(blockOnSelections) {
sendRoundTripMessage(MESSAGE_VIEW_SYNCHRONIZE_SELECTION, isSelected ? Boolean.TRUE : Boolean.FALSE, null, getButtonCellControlData().getRowObject().getObjectId(), 0, null);
}//if//
else {
sendMessage(MESSAGE_VIEW_SYNCHRONIZE_SELECTION, isSelected ? Boolean.TRUE : Boolean.FALSE, null, getButtonCellControlData().getRowObject().getObjectId(), 0);
}//else//
}//else//
}//if//
if(isStateful) {
getButtonCellControlData().selection = isSelected ? Boolean.TRUE : Boolean.FALSE;
}//if//
}//selectionChanged()//
/**
* Sets the text.
* @param text The text to display.
*/
protected void controlSetText(String text) {
if(getSwtButton() != null) {
getSwtButton().setText(text);
}//if//
}//controlSetText()//
/**
* Sets the image.
* @param image The image to display.
*/
protected void controlSetImage(JefImage image) {
if(swtImage != null) {
swtImage.dispose();
swtImage = null;
}//if//
if(image != null) {
swtImage = SwtUtilities.getImage(getSwtControl().getDisplay(), image);
}//if//
getSwtButton().setImage(swtImage);
}//controlSetImage()//
/**
* Sets the component's selection state.
* @param isSelected Whether the button is to be selected.
*/
protected void controlSetSelection(boolean isSelected) {
//Some components may not have controls, such as value holders.//
if(getSwtButton() != null) {
getSwtButton().setSelection(isSelected);
}//if//
}//controlSetSelection()//
/* (non-Javadoc)
* @see com.foundation.view.IResourceHolderComponent#resourceHolderChanged(com.foundation.view.AbstractResourceHolder, java.lang.Object, java.lang.Object)
*/
public void resourceHolderChanged(AbstractResourceHolder resourceHolder, Object oldValue, Object newValue, int flags) {
if(resourceHolder == textHolder) {
controlSetText((String) resourceHolder.getValue());
}//if//
else if(resourceHolder == imageHolder) {
controlSetImage((JefImage) resourceHolder.getValue());
}//else if//
else {
super.resourceHolderChanged(resourceHolder, oldValue, newValue, flags);
}//else//
}//resourceHolderChanged()//
}//ButtonCellControl//
/**
* CellButton constructor.
*/
public CellButton() {
}//CellButton()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#supportsControl()
*/
public boolean supportsControl() {
return true;
}//supportsControl()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#initializeCellControl(com.foundation.tcv.swt.client.cell.CellComponent.CellControlData)
*/
protected CellControl initializeCellControl(CellControlData cellControlData) {
return new ButtonCellControl(new Button(getCellContainer().getSwtComposite(cellControlData.getRowObject()), style), (ButtonCellControlData) cellControlData);
}//initializeCellControl()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#initializeCellControlData(com.foundation.tcv.swt.client.CollectionComponent.RowObject)
*/
protected CellControlData initializeCellControlData(RowObject rowObject) {
return new ButtonCellControlData(rowObject);
}//initializeCellControlData()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#releaseCellControlData(com.foundation.tcv.swt.client.cell.CellComponent.CellControlData)
*/
protected void releaseCellControlData(CellControlData cellControlData) {
}//releaseCellControlData()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#paintCell(com.foundation.tcv.swt.client.cell.CellComponent.CellControlData, org.eclipse.swt.graphics.GC)
*/
protected void paintCell(CellControlData cellControlData, GC graphics) {
}//paintCell()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#internalViewRelease()
*/
protected void internalViewRelease() {
if(textHolder != null) {
textHolder.release();
}//if//
if(imageHolder != null) {
imageHolder.release();
}//if//
if((swtImage != null) && (!swtImage.isDisposed())) {
swtImage.dispose();
}//if//
super.internalViewRelease();
}//internalViewRelease()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.AbstractComponent#internalProcessMessage(com.foundation.tcv.view.ViewMessage)
*/
public Object internalProcessMessage(ViewMessage viewMessage) {
Object result = null;
switch(viewMessage.getMessageNumber()) {
case MESSAGE_INITIALIZE: {
int[] data = (int[]) viewMessage.getMessageData();
setCellContainer((ICellContainer) getComponent(data[0]));
style = data[1];
getCellContainer().addCellComponent(this);
break;
}//case//
case MESSAGE_SET_IMAGE: {
setImage(viewMessage.getMessageData(), viewMessage.getMessageInteger() != -1 ? (ButtonCellControlData) getCellControlData(getCellContainer().getRowObject(viewMessage.getMessageInteger())) : null);
break;
}//case//
case MESSAGE_SET_TEXT: {
setText(viewMessage.getMessageData(), viewMessage.getMessageInteger() != -1 ? (ButtonCellControlData) getCellControlData(getCellContainer().getRowObject(viewMessage.getMessageInteger())) : null);
break;
}//case//
case MESSAGE_SET_AUTO_SYNCHRONIZE_SELECTION: {
autoSynchronizeSelection = ((Boolean) viewMessage.getMessageData()).booleanValue();
break;
}//case//
case MESSAGE_SET_AUTO_SYNCHRONIZE_SELECTION_DELAY: {
autoSynchronizeSelectionDelay = ((Long) viewMessage.getMessageData()).longValue();
break;
}//case//
case MESSAGE_SET_BLOCK_ON_SELECTIONS: {
blockOnSelections = ((Boolean) viewMessage.getMessageData()).booleanValue();
break;
}//case//
case MESSAGE_SET_IS_SELECTED: {
setSelection((Boolean) viewMessage.getMessageData(), viewMessage.getMessageInteger() != -1 ? (ButtonCellControlData) getCellControlData(getCellContainer().getRowObject(viewMessage.getMessageInteger())) : null);
break;
}//case//
default: {
result = super.internalProcessMessage(viewMessage);
}//default//
}//switch//
return result;
}//internalProcessMessage()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#internalResourceHolderChanged(com.foundation.tcv.client.view.ResourceHolder, java.lang.Object, java.lang.Object)
*/
protected void internalResourceHolderChanged(ResourceHolder resourceHolder, Object oldValue, Object newValue, int flags) {
if(resourceHolder == textHolder) {
IIterator iterator = getCellControlIterator();
//Update the existing controls.//
while(iterator.hasNext()) {
ButtonCellControl cellControl = (ButtonCellControl) iterator.next();
cellControl.refreshText();
}//while//
}//if//
else if(resourceHolder == imageHolder) {
IIterator iterator = getCellControlIterator();
if(swtImage != null) {
swtImage.dispose();
}//if//
if(newValue != null) {
swtImage = SwtUtilities.getImage(getDisplay(), (JefImage) newValue);
}//if//
//Update the existing controls.//
while(iterator.hasNext()) {
ButtonCellControl cellControl = (ButtonCellControl) iterator.next();
cellControl.refreshImage();
}//while//
}//else if//
else {
super.internalResourceHolderChanged(resourceHolder, oldValue, newValue, flags);
}//else//
}//internalResourceHolderChanged()//
/**
* Sets the image for the cell control(s).
* @param value The new value.
* @param cellControlData The cell control data if changing a specific cell, otherwise null.
*/
protected void setImage(Object value, ButtonCellControlData cellControlData) {
if(cellControlData == null) {
if(imageHolder == null) {
imageHolder = new ResourceHolder(this);
}//if//
imageHolder.setValue(value);
}//if//
else {
cellControlData.image = value;
if(cellControlData.getCellControl() != null) {
((ButtonCellControl) cellControlData.getCellControl()).refreshImage();
}//if//
}//else//
}//setImage()//
/**
* Sets the text for the cell control(s).
* @param value The new value.
* @param cellControlData The cell control data if changing a specific cell, otherwise null.
*/
protected void setText(Object value, ButtonCellControlData cellControlData) {
if(cellControlData == null) {
if(textHolder == null) {
textHolder = new ResourceHolder(this);
}//if//
textHolder.setValue(value);
}//if//
else {
cellControlData.text = value;
if(cellControlData.getCellControl() != null) {
((ButtonCellControl) cellControlData.getCellControl()).refreshText();
}//if//
}//else//
}//setText()//
/**
* Sets the selection for the cell control(s).
* @param value The new value.
* @param cellControlData The cell control data if changing a specific cell, otherwise null.
*/
protected void setSelection(Boolean value, ButtonCellControlData cellControlData) {
cellControlData.selection = value;
if(cellControlData.getCellControl() != null) {
((ButtonCellControl) cellControlData.getCellControl()).refreshSelection();
}//if//
}//setSelection()//
}//CellButton//

View File

@@ -0,0 +1,742 @@
/*
* Copyright (c) 2007,2008 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.client.cell;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.Combo;
import com.common.thread.IRunnable;
import com.common.util.IIterator;
import com.common.util.LiteList;
import com.common.util.optimized.IntObjectHashMap;
import com.foundation.tcv.swt.cell.IComboBox;
import com.foundation.tcv.swt.client.ICellContainer;
import com.foundation.tcv.swt.client.RowObject;
import com.foundation.tcv.view.ViewMessage;
public class CellComboBox extends CellComponent implements IComboBox {
/** Used by the hidden data to identify when the previous value has not yet been assigned a value. */
protected static final Object UNSET_VALUE = new Object();
/** The control style. */
private int style = 0;
/** Whether the user can type a custom selection. If this is true and the selection attribute is not a String type then the user input must match a list item's text. */
private boolean allowUserItems = false;
/** Whether the selection should be automatically sent to the model. */
private boolean autoSynchronizeSelection = false;
/** The number of milliseconds of delay before auto synchronizing the selection. */
private long autoSynchronizeSelectionDelay = 500;
/** Whether the UI should block until the selection has completed its synchronization. */
private boolean blockOnSelections = false;
/** Maps the row objects by their unique object identifiers. */
private IntObjectHashMap rowObjectByObjectIdMap = new IntObjectHashMap(100, 200);
/** Maps the row objects given the index in the control. An object can be represented more than once in the control if the same row object exists in multiple indices. */
private LiteList rowObjectByIndexMap = new LiteList(100, 200);
/** The text limit to use with the combo box controls. */
private int textLimit = -1;
public static class ComboRowObject extends RowObject {
/** The row's text. */
private String text = null;
/**
* ComboRowObject constructor.
* @param objectId the row object's identifier.
*/
public ComboRowObject(int objectId) {
super(objectId, -1);
}//ComboRowObject()//
/**
* Gets the text for the row.
* @return The row's text.
*/
public String getText() {
return text;
}//getText()//
/**
* Sets the text for the row.
* @param text The row's text.
*/
public void setText(String text) {
this.text = text;
}//setText()//
}//ComboRowObject()//
/**
* Maintains the cell data for the control. A control may only exist if it is visible, but the data must be maintained regardless.
*/
public class ComboBoxCellControlData extends CellControlData {
/** The currently selected index (on the server). A negative one indicates no selection or a custom selection. */
private int selectedObjectIdOnServer = -1;
/** The custom selection last sent to the server or received by the server. This will be null if there is no custom selection or there is no selection at all. */
private String customSelectionOnServer = null;
/** The currently selected index. A negative one indicates no selection or a custom selection. */
private int selectedObjectId = -1;
/** The current custom selection. This will be null if there is no custom selection or there is no selection at all. */
private String customSelection = null;
/**
* ComboBoxCellControlData constructor.
* @param rowObject The row for the cell.
*/
public ComboBoxCellControlData(RowObject rowObject) {
super(rowObject);
}//ComboBoxCellControlData()//
/**
* Gets the currently selected object identifier on the server.
* @return The object identifier for the selection known by the server, or -1 for no selection.
*/
protected int getSelectedObjectIdOnServer() {
return selectedObjectIdOnServer;
}//getSelectedObjectIdOnServer()//
/**
* Sets the currently selected object identifier on the server.
* @param objectId The object identifier for the selection known by the server, or -1 for no selection.
*/
protected void setSelectedObjectIdOnServer(int objectId) {
this.selectedObjectIdOnServer = objectId;
}//setSelectedObjectIdOnServer()//
/**
* Gets the current custom selection text on the server.
* @return The selection text, or null if there isn't a custom selection.
*/
protected String getCustomSelectionOnServer() {
return customSelectionOnServer;
}//getCustomSelectionOnServer()//
/**
* Sets the current custom selection text on the server.
* @param customSelection The selection text, or null if there isn't a custom selection.
*/
protected void setCustomSelectionOnServer(String customSelection) {
this.customSelectionOnServer = customSelection;
}//setCustomSelectionOnServer()//
/**
* Gets the currently selected object identifier.
* @return The object identifier for the selection, or -1 for no selection or custom selection.
*/
protected int getSelectedObjectId() {
return selectedObjectId;
}//getSelectedObjectId()//
/**
* Sets the currently selected object identifier.
* @param objectId The object identifier for the selection, or -1 for no selection or custom selection.
*/
protected void setSelectedObjectId(int objectId) {
this.selectedObjectId = objectId;
}//setSelectedObjectId()//
/**
* Gets the current custom selection text.
* @return The selection text, or null if there isn't a custom selection.
*/
protected String getCustomSelection() {
return customSelection;
}//getCustomSelection()//
/**
* Sets the current custom selection text.
* @param customSelection The selection text, or null if there isn't a custom selection.
*/
protected void setCustomSelection(String customSelection) {
this.customSelection = customSelection;
}//setCustomSelection()//
}//ComboBoxCellControlData//
/**
* Encapsulates a control with related data such as listeners and the data model for the cell.
*/
public class ComboBoxCellControl extends CellControl implements SelectionListener, ModifyListener {
/** The task that auto synchronizes the selection after a short delay. */
protected Task autoSynchronizeSelectionTask = null;
/** Used to stop selection events from being handled while the items are being changed. */
private boolean suspendSelectionEvents = false;
/**
* ComboBoxCellControl constructor.
* @param control The control being encapsulated.
* @param cellData The cell's data.
*/
public ComboBoxCellControl(Combo control, ComboBoxCellControlData cellData) {
super(control, cellData);
getSwtCombo().addSelectionListener(this);
getSwtCombo().addModifyListener(this);
}//ComboBoxCellControl()//
protected void controlRemoveAll() {
suspendSelectionEvents = true;
getSwtCombo().removeAll();
suspendSelectionEvents = false;
}//controlRemoveAll()//
protected void controlSetItems(Object[] items) {
String[] itemTexts = new String[items.length];
System.arraycopy(items, 0, itemTexts, 0, itemTexts.length);
suspendSelectionEvents = true;
try {
getSwtCombo().setItems(itemTexts);
}//try//
finally {
suspendSelectionEvents = false;
}//finally//
}//controlSetItems()//
protected void controlSetItem(int index, Object itemData) {
suspendSelectionEvents = true;
getSwtCombo().setItem(index, (String) itemData);
suspendSelectionEvents = false;
}//controlSetItem()//
protected void controlAddItem(Object itemData, int index) {
suspendSelectionEvents = true;
getSwtCombo().add((String) itemData, index);
suspendSelectionEvents = false;
}//controlAddItem()//
protected void controlAddItem(Object itemData) {
suspendSelectionEvents = true;
getSwtCombo().add((String) itemData);
suspendSelectionEvents = false;
}//controlAddItem()//
protected void controlRemoveItem(int index) {
suspendSelectionEvents = true;
getSwtCombo().remove(index);
suspendSelectionEvents = false;
}//controlRemoveItem()//
protected int controlGetSelection() {
return getSwtCombo().getSelectionIndex();
}//controlGetSelection()//
protected void controlSetSelection(int index) {
suspendSelectionEvents = true;
if(index == -1) {
getSwtCombo().deselectAll();
}//if//
else {
getSwtCombo().select(index);
}//else//
suspendSelectionEvents = false;
}//controlSetSelection()//
protected void controlSetSelection(String text) {
suspendSelectionEvents = true;
if(text == null) {
getSwtCombo().deselectAll();
}//if//
else {
getSwtCombo().setText(text);
}//else//
suspendSelectionEvents = false;
}//controlSetSelection()//
protected int controlGetSelectionCount() {
return getSwtCombo().getText().length() > 0 ? 1 : 0;
}//controlGetSelectionCount()//
/**
* Gets the combo box cell data for the control.
* @return The cell data for the combo control.
*/
public ComboBoxCellControlData getComboBoxCellControlData() {
return (ComboBoxCellControlData) getCellControlData();
}//getComboBoxCellControlData()//
/**
* Gets the combo box control.
* @return The combo box being encapsulated.
*/
public Combo getSwtCombo() {
return (Combo) getSwtControl();
}//getSwtCombo()//
/* (non-Javadoc)
* @see com.foundation.view.swt.cell.CellComponent.CellControl#release()
*/
public void release() {
if((getSwtCombo() != null) && (!getSwtCombo().isDisposed())) {
getSwtCombo().removeSelectionListener(this);
getSwtCombo().removeModifyListener(this);
}//if//
//Ignore any pending synchronizations.//
synchronized(this) {
if(autoSynchronizeSelectionTask != null) {
removeTask(autoSynchronizeSelectionTask);
autoSynchronizeSelectionTask = null;
}//if//
}//synchronized//
super.release();
}//release()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent.CellControl#refresh()
*/
public void refresh() {
refreshCollection();
refreshSelection();
super.refresh();
}//refresh()//
/**
* Refreshes the selection.
*/
public void refreshSelection() {
controlSetSelection(getComboBoxCellControlData().selectedObjectIdOnServer);
}//refreshSelection()//
/**
* Refreshes the collection.
*/
public void refreshCollection() {
if(getRowObjectByIndexMap().getSize() > 0) {
String[] texts = new String[getRowObjectByIndexMap().getSize()];
for(int index = 0; index < texts.length; index++) {
texts[index] = getRowObjectAtIndex(index).text;
}//for//
suspendSelectionEvents = true;
getSwtCombo().setItems(texts);
suspendSelectionEvents = false;
}//if//
else {
suspendSelectionEvents = true;
getSwtCombo().removeAll();
suspendSelectionEvents = false;
}//else//
}//refreshCollection()//
/**
* Forces any pending synchronizations to complete.
*/
public void synchronize() {
if(!getAutoSynchronizeSelection()) {
synchronizeSelection();
}//if//
else {
synchronized(this) {
if(autoSynchronizeSelectionTask != null) {
removeTask(autoSynchronizeSelectionTask);
autoSynchronizeSelectionTask.execute();
autoSynchronizeSelectionTask = null;
}//if//
}//synchronized//
}//else//
}//synchronize()//
/**
* Determines whether there is a custom selection.
* @return Whether the user has typed a value in the control that is not in the set to select from.
*/
protected boolean hasCustomSelection() {
return getAllowUserItems() && (getSwtCombo().getSelectionIndex() == -1) && (getSwtCombo().getText() != null) && (getSwtCombo().getText().length() > 0);
}//hasCustomSelection()//
/**
* Gets the set of selected object identifiers.
* @return The set of selected object identifiers, or null if nothing is selected.
*/
protected int getSelectedObjectId() {
int selectionIndex = getSwtCombo().getSelectionIndex();
return selectionIndex != -1 ? getRowObjectAtIndex(selectionIndex).objectId : -1;
}//getSelectedObjectId()//
/* (non-Javadoc)
* @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
*/
public void modifyText(ModifyEvent event) {
if(!suspendSelectionEvents) {
//TODO: Shouldn't this always call widgetSelected(null)?
if(getSwtCombo().getSelectionIndex() == -1) {
widgetSelected(null);
}//if//
}//if//
}//modifyText()//
/* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
*/
public void widgetDefaultSelected(SelectionEvent event) {
widgetSelected(event);
}//widgetDefaultSelected()//
/* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
public void widgetSelected(SelectionEvent event) {
ComboBoxCellControlData cellData = getComboBoxCellControlData();
if(getAutoSynchronizeSelection()) {
if(getAutoSynchronizeSelectionDelay() > 0) {
final int selectedObjectId = !hasCustomSelection() ? getSelectedObjectId() : -1;
final String customSelection = hasCustomSelection() ? getSwtCombo().getText() : null;
final int externalObjectId = cellData.getRowObject().getObjectId();
if(((customSelection != null) && (!customSelection.equals(cellData.getCustomSelectionOnServer()))) || (selectedObjectId != cellData.getSelectedObjectIdOnServer())) {
//Update the known server state.//
cellData.setSelectedObjectIdOnServer(selectedObjectId);
cellData.setCustomSelectionOnServer(customSelection);
//Start a task to send the selection to the server after a short delay. This will reduce the overhead of auto synchronizing the selection.//
synchronized(this) {
if(autoSynchronizeSelectionTask != null) {
removeTask(autoSynchronizeSelectionTask);
}//if//
autoSynchronizeSelectionTask = new Task() {
public void execute() {
//Make sure that this task is still valid and is not being superceeded.//
synchronized(CellComboBox.this) {
if(autoSynchronizeSelectionTask == this) {
//Cleanup after the task.//
autoSynchronizeSelectionTask = null;
getEventLoop().executeAsync(new IRunnable() {
public Object run() {
sendMessage(MESSAGE_VIEW_SYNCHRONIZE_SELECTION, customSelection, null, selectedObjectId, externalObjectId);
return null;
}//run()//
});
}//if//
}//synchronized//
}//run()//
};
addTask(autoSynchronizeSelectionTask, getAutoSynchronizeSelectionDelay());
}//synchronized//
}//if//
}//if//
else {
synchronizeSelection();
}//else//
}//if//
}//widgetSelected()//
/**
* Synchronizes the selection to the model from the view.
* <p>This method has no logic to examine the auto synchronization state. It simply synchronizes the selection immediatly.</p>
*/
protected void synchronizeSelection() {
ComboBoxCellControlData cellData = getComboBoxCellControlData();
int externalObjectId = cellData.getRowObject().getObjectId();
if(hasCustomSelection()) {
String text = getSwtCombo().getText();
if(!text.equals(cellData.getCustomSelectionOnServer())) {
cellData.setSelectedObjectIdOnServer(-1);
cellData.setCustomSelectionOnServer(text);
if(blockOnSelections) {
sendRoundTripMessage(MESSAGE_VIEW_SYNCHRONIZE_SELECTION, text, null, -1, externalObjectId, null);
}//if//
else {
sendMessage(MESSAGE_VIEW_SYNCHRONIZE_SELECTION, text, null, -1, externalObjectId);
}//else//
}//if//
}//if//
else {
int selectionIndex = getSwtCombo().getSelectionIndex();
int objectId = selectionIndex != -1 ? getRowObjectAtIndex(selectionIndex).objectId : -1;
if(objectId != cellData.getSelectedObjectIdOnServer()) {
cellData.setSelectedObjectIdOnServer(objectId);
cellData.setCustomSelectionOnServer(null);
if(blockOnSelections) {
sendRoundTripMessage(MESSAGE_VIEW_SYNCHRONIZE_SELECTION, null, null, objectId, externalObjectId, null);
}//if//
else {
sendMessage(MESSAGE_VIEW_SYNCHRONIZE_SELECTION, null, null, objectId, externalObjectId);
}//else//
}//if//
}//else//
}//synchronizeSelection()//
}//ComboBoxCellControl//
/**
* ComboBox constructor.
*/
public CellComboBox() {
}//ComboBox()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#internalProcessMessage(com.foundation.tcv.view.ViewMessage)
*/
public Object internalProcessMessage(ViewMessage viewMessage) {
Object retVal = null;
switch(viewMessage.getMessageNumber()) {
case MESSAGE_INITIALIZE: {
int[] data = (int[]) viewMessage.getMessageData();
setCellContainer((ICellContainer) getComponent(data[0]));
style = data[1];
getCellContainer().addCellComponent(this);
break;
}//case//
case MESSAGE_SET_TEXT_LIMIT: {
IIterator iterator = getCellControlIterator();
textLimit = ((Integer) viewMessage.getMessageData()).intValue();
//Update existing controls.//
while(iterator.hasNext()) {
((ComboBoxCellControl) iterator.next()).getSwtCombo().setTextLimit(textLimit);
}//while//
break;
}//case//
case MESSAGE_SET_ITEMS: { //A string array and an int array. The int array is the object ID's.//
IIterator iterator = getCellControlIterator();
String[] texts = (String[]) viewMessage.getMessageData();
int[] objectIds = (int[]) viewMessage.getMessageSecondaryData();
if(texts == null) {
getRowObjectByObjectIdMap().removeAll();
getRowObjectByIndexMap().removeAll();
}//if//
else {
//Remove all the mappings.//
getRowObjectByObjectIdMap().removeAll();
getRowObjectByIndexMap().removeAll();
//Initialize the mappings between indexes and object IDs.//
for(int index = 0; index < objectIds.length; index++) {
ComboRowObject rowObject = getRowObject(objectIds[index]);
//Create a row object or increment its reference count.//
if(rowObject == null) {
rowObject = (ComboRowObject) createRowObject(objectIds[index]);
rowObject.text = texts[index];
getRowObjectByObjectIdMap().put(rowObject.objectId, rowObject);
}//if//
else {
rowObject.referenceCount++;
}//else//
getRowObjectByIndexMap().add(rowObject);
}//for//
}//else//
//Update existing controls.//
while(iterator.hasNext()) {
((ComboBoxCellControl) iterator.next()).refreshCollection();
}//while//
break;
}//case//
case MESSAGE_ADD_ITEM: { //Sends item data and object ID and an optional index.//
IIterator iterator = getCellControlIterator();
String text = (String) viewMessage.getMessageData();
int objectId = viewMessage.getMessageInteger();
ComboRowObject rowObject = getRowObject(objectId);
int index = viewMessage.getMessageSecondaryInteger();
//Create a row object or increment its reference count.//
if(rowObject == null) {
rowObject = (ComboRowObject) createRowObject(objectId);
rowObject.text = text;
getRowObjectByObjectIdMap().put(rowObject.objectId, rowObject);
}//if//
else {
rowObject.referenceCount++;
text = rowObject.text;
}//else//
//If an index was provided then place the item at the requested index.//
if(index != -1) {
//A little error checking just in case.//
if(index > rowObjectByIndexMap.getSize()) {
index = rowObjectByIndexMap.getSize();
}//if//
//Update the mappings.//
rowObjectByIndexMap.add(index, rowObject);
}//if//
else {
//Update the mappings.//
rowObjectByIndexMap.add(rowObject);
}//else//
//Update existing controls.//
while(iterator.hasNext()) {
//TODO: Do we want to refresh the whole collection, or just add the one item?
((ComboBoxCellControl) iterator.next()).refreshCollection();
}//while//
break;
}//case//
case MESSAGE_REMOVE_ITEM: { //Note: Since removals are most often of selected items we will first try removing selected objects with the same object id.//
IIterator iterator = getCellControlIterator();
int objectId = viewMessage.getMessageInteger();
RowObject rowObject = getRowObject(objectId);
//Remove the first instance of the row object from the list.//
getRowObjectByIndexMap().remove(rowObject);
rowObject.referenceCount--;
if(rowObject.referenceCount == 0) {
getRowObjectByObjectIdMap().remove(objectId);
}//if//
//Update existing controls.//
while(iterator.hasNext()) {
//TODO: Do we want to refresh the whole collection, or just remove the one item?
((ComboBoxCellControl) iterator.next()).refreshCollection();
}//while//
break;
}//case//
case MESSAGE_REMOVE_ALL: {
IIterator iterator = getCellControlIterator();
getRowObjectByObjectIdMap().removeAll();
getRowObjectByIndexMap().removeAll();
//Update existing controls.//
while(iterator.hasNext()) {
((ComboBoxCellControl) iterator.next()).refreshCollection();
}//while//
break;
}//case//
case MESSAGE_SET_ITEM_TEXT: {
IIterator iterator = getCellControlIterator();
String text = (String) viewMessage.getMessageData();
int objectId = viewMessage.getMessageInteger();
ComboRowObject rowObject = getRowObject(objectId);
//Set the row object's value.//
rowObject.text = text;
//Update existing controls.//
while(iterator.hasNext()) {
//TODO: Should we update the one item's text?
((ComboBoxCellControl) iterator.next()).refreshCollection();
}//while//
break;
}//case//
case MESSAGE_SET_SELECTION: {
String text = (String) viewMessage.getMessageData();
int collectionObjectId = viewMessage.getMessageInteger();
int externalObjectId = viewMessage.getMessageSecondaryInteger();
ComboBoxCellControlData controlData = (ComboBoxCellControlData) getCellControlData(getCellContainer().getRowObject(externalObjectId));
controlData.customSelectionOnServer = text;
controlData.selectedObjectIdOnServer = collectionObjectId;
if(controlData.getCellControl() != null) {
((ComboBoxCellControl) controlData.getCellControl()).refreshSelection();
}//if//
break;
}//case//
case MESSAGE_SET_AUTO_SYNCHRONIZE_SELECTION: {
autoSynchronizeSelection = ((Boolean) viewMessage.getMessageData()).booleanValue();
break;
}//case//
case MESSAGE_SET_AUTO_SYNCHRONIZE_SELECTION_DELAY: {
autoSynchronizeSelectionDelay = ((Long) viewMessage.getMessageData()).longValue();
break;
}//case//
default: {
retVal = super.internalProcessMessage(viewMessage);
}//default//
}//switch//
return retVal;
}//internalProcessMessage()//
/**
* Creates a new row object.
* @param objectId The identifier for the combo box collection object that is represented by the row.
* @return An empty row object.
*/
protected RowObject createRowObject(int objectId) {
return new ComboRowObject(objectId);
}//createRowObject()//
/**
* Gets the row object containing the data for the object with the given identifier.
* @param objectId Identifies the object that the row object represents.
* @return The row object that is the avatar for the object identified by the object id.
*/
public ComboRowObject getRowObject(int objectId) {
return (ComboRowObject) rowObjectByObjectIdMap.get(objectId);
}//getRowObject()//
/**
* Gets the row object for the given display collection index.
* @param index The zero based index of the row object in the display collection.
* @return The row object for the display index.
*/
protected ComboRowObject getRowObjectAtIndex(int index) {
return (ComboRowObject) rowObjectByIndexMap.get(index);
}//getRowObjectAtIndex()//
/**
* Determines whether the control allows the user to type in custom items (combobox).
* @return Whether users will be allowed to type in a custom value.
*/
protected boolean getAllowUserItems() {
return allowUserItems;
}//getAllowUserItems()//
/**
* Gets whether the control allows the user to type in custom items (combobox).
* @param allowUserItems Whether users will be allowed to type in a custom value.
*/
protected void setAllowUserItems(boolean allowUserItems) {
this.allowUserItems = allowUserItems;
}//setAllowUserItems()//
/**
* Gets whether the control should automatically synchronize all selections.
* @return Whether selections should automatically get sent to the server.
*/
protected boolean getAutoSynchronizeSelection() {
return autoSynchronizeSelection;
}//getAutoSynchronizeSelection()//
/**
* Sets whether the control should automatically synchronize all selections.
* @param autoSynchronizeSelection Whether selections should automatically get sent to the server.
*/
protected void setAutoSynchronizeSelection(boolean autoSynchronizeSelection) {
this.autoSynchronizeSelection = autoSynchronizeSelection;
}//setAutoSynchronizeSelection()//
/**
* Gets the delay in milliseconds between the selection event and updating the model.
* @return The number of milliseconds to wait before updating the model.
*/
protected long getAutoSynchronizeSelectionDelay() {
return autoSynchronizeSelectionDelay;
}//getAutoSynchronizeSelectionDelay()//
/**
* Sets the delay in milliseconds between the selection event and updating the model.
* @param autoSynchronizeSelectionDelay The number of milliseconds to wait before updating the model.
*/
protected void setAutoSynchronizeSelectionDelay(long autoSynchronizeSelectionDelay) {
this.autoSynchronizeSelectionDelay = autoSynchronizeSelectionDelay;
}//setAutoSynchronizeSelectionDelay()//
/**
* Gets the map of row objects by their object identifiers.
* @return The index of row objects by object identifier.
*/
protected IntObjectHashMap getRowObjectByObjectIdMap() {
return rowObjectByObjectIdMap;
}//getRowObjectByObjectIdMap()//
/**
* Gets the list of row objects indexed in display order.
* @return The set of row objects in display order.
*/
protected LiteList getRowObjectByIndexMap() {
return rowObjectByIndexMap;
}//getRowObjectByObjectIdMap()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#initializeCellControl(com.foundation.tcv.swt.client.cell.CellComponent.CellControlData)
*/
protected CellControl initializeCellControl(CellControlData cellControlData) {
Combo combo = new Combo(getCellContainer().getSwtComposite(cellControlData.getRowObject()), style);
return new ComboBoxCellControl(combo, (ComboBoxCellControlData) cellControlData);
}//initializeCellControl()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#initializeCellControlData(com.foundation.tcv.swt.client.CollectionComponent.RowObject)
*/
protected CellControlData initializeCellControlData(RowObject rowObject) {
return new ComboBoxCellControlData(rowObject);
}//initializeCellControlData()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#releaseCellControlData(com.foundation.tcv.swt.client.cell.CellComponent.CellControlData)
*/
protected void releaseCellControlData(CellControlData cellControlData) {
}//releaseCellControlData()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#supportsControl()
*/
public boolean supportsControl() {
return true;
}//supportsControl()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#paintCell(com.foundation.tcv.swt.client.cell.CellComponent.CellControlData, org.eclipse.swt.graphics.GC)
*/
protected void paintCell(CellControlData cellControlData, GC graphics) {
}//paintCell()//
}//ComboBox//

View File

@@ -0,0 +1,977 @@
/*
* 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.client.cell;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import com.common.debug.Debug;
import com.common.util.*;
import com.foundation.tcv.client.controller.SessionViewController;
import com.foundation.tcv.client.view.IAbstractClientViewComponent;
import com.foundation.tcv.client.view.ResourceHolder;
import com.foundation.tcv.swt.cell.ICellComponent;
import com.foundation.tcv.swt.client.AbstractComponent;
import com.foundation.tcv.swt.client.Container;
import com.foundation.tcv.swt.client.ICellContainer;
import com.foundation.tcv.swt.client.RowObject;
import com.foundation.tcv.view.ViewMessage;
import com.foundation.view.AbstractMultiResourceHolder;
import com.foundation.view.AbstractResourceHolder;
import com.foundation.view.JefColor;
import com.foundation.view.JefFont;
import com.foundation.view.resource.AbstractResourceService;
/**
* <p>Programming Note: Handling VariableAssociations whose values are placed in ResourceHolders.<br>
* This class demonstrates how to do this with the foreground and background colors, font, and tool tip text.
* The server send the object that is the value for either the row or for all rows.
* All rows values are saved in the CellComponent class and the per-row values are saved in the CellControlData.
* The CellControl's are all notified upon this change and they re-set their ResourceHolder's value to this object.
* The CellControl's also initialize the ResourceHolder's value when the control is setup.
* The ResourceHolder's fire change events which cause the actual control to be updated with the correct value.</p>
*/
public abstract class CellComponent extends AbstractComponent implements ICellComponent {
public static final int USE_CONTROL_ALWAYS = 0;
public static final int USE_CONTROL_NEVER = 1;
public static final int USE_CONTROL_ON_SELECTION = 2;
/** The container containing this component. */
private ICellContainer cellContainer = null;
/** The set of CellControlData instances, one for each RowObject. */
private IHashMap cellControlDataByRowObject = new LiteHashMap(500);
/** The set of all cell controls. Not all cells may have a controls as only those cells that are visible must have one. */
private IHashSet cellControls = new LiteHashSet(50);
/** The optional decimal scale to be used by the component if it deals with decimal values. */
private Integer decimalScale = null;
/** The resource holder for the foreground color. */
private ResourceHolder foregroundColorHolder = null;
/** The resource holder for the background color. */
private ResourceHolder backgroundColorHolder = null;
/** The resource holder for the font. */
private ResourceHolder fontHolder = null;
/** The resource holder for the tool tipe text. */
private ResourceHolder toolTipTextHolder = null;
/** The currently active background color. This is used to ensure that the correct color is destroyed when cleaning up. */
private Color currentBackgroundColor = null;
/** The currently active foreground color. This is used to ensure that the correct color is destroyed when cleaning up. */
private Color currentForegroundColor = null;
/** The currently active font. This is used to ensure that the correct font is destroyed when cleaning up. */
private Font currentFont = null;
/** The optonal layout data used by the cell component if it resides in a cell panel. */
private Object layoutData = null;
/**
* Maintains the cell data for the control. A control may only exist if it is visible, but the data must be maintained regardless.
*/
public abstract class CellControlData {
/** The reference to the cell control that is currently displaying the data. This may be null if the cell is not currently displayed. This will also be null if the cell doesn't use a component to render, but instead performs its own rendering. */
private CellControl cellControl = null;
/** The row object for the row the cell exists in. */
private RowObject rowObject = null;
/** The control's enabled state. */
private Boolean isEnabled = Boolean.TRUE;
/** The control's foreground color prior to being placed in the holder. */
private Object foregroundColor = null;
/** The control's background color prior to being placed in the holder. */
private Object backgroundColor = null;
/** The control's font prior to being placed in the holder. */
private Object font = null;
/** The control's tool tip prior to being placed in the holder. */
private Object toolTipText = null;
/**
* CellControlData constructor.
* @param rowObject The row for the cell.
*/
public CellControlData(RowObject rowObject) {
this.rowObject = rowObject;
}//CellControlData()//
/**
* Gets the cell control associated with the data.
* @return The cell control if one exists.
*/
public CellControl getCellControl() {
return cellControl;
}//getCellControl()//
/**
* Gets the object representing the row the cell exists in.
* @return The row for the cell.
*/
public RowObject getRowObject() {
return rowObject;
}//getRowObject()//
}//CellControlData//
/**
* Encapsulates a control with related data such as listeners and the data model for the cell.
*/
public abstract class CellControl implements IAbstractClientViewComponent {
/** The control that handles the display of the cell. */
private Control control = null;
/** The currently active background color. This is used to ensure that the correct color is destroyed when cleaning up. */
private Color currentBackgroundColor = null;
/** The currently active foreground color. This is used to ensure that the correct color is destroyed when cleaning up. */
private Color currentForegroundColor = null;
/** The currently active font. This is used to ensure that the correct font is destroyed when cleaning up. */
private Font currentFont = null;
/** The resource holder for the foreground color. */
private ResourceHolder foregroundColorHolder = null;
/** The resource holder for the background color. */
private ResourceHolder backgroundColorHolder = null;
/** The resource holder for the font. */
private ResourceHolder fontHolder = null;
/** The resource holder for the tool tipe text. */
private ResourceHolder toolTipTextHolder = null;
/** The cell data for the control. */
private CellControlData cellData = null;
/**
* CellControl constructor.
* @param control The control being encapsulated.
* @param cellData The cell's data.
*/
public CellControl(Control control, CellControlData cellData) {
this.control = control;
this.cellData = cellData;
control.setData(this);
if(cellData.backgroundColor != null) {
backgroundColorHolder = new ResourceHolder(this);
backgroundColorHolder.setValue(cellData.backgroundColor);
}//if//
if(cellData.foregroundColor != null) {
foregroundColorHolder = new ResourceHolder(this);
foregroundColorHolder.setValue(cellData.foregroundColor);
}//if//
if(cellData.font != null) {
fontHolder = new ResourceHolder(this);
fontHolder.setValue(cellData.font);
}//if//
}//CellControl()//
/* (non-Javadoc)
* @see com.foundation.view.IResourceHolderComponent#getResourceService()
*/
public AbstractResourceService getResourceService() {
return CellComponent.this.getResourceService();
}//getResourceService()//
/**
* Gets the cell component that the control was created by.
* @return The control's component.
*/
public CellComponent getCellComponent() {
return CellComponent.this;
}//getCellComponent()//
/**
* Gets the data for the control in the cell.
* @return The cell data for the control.
*/
public CellControlData getCellControlData() {
return cellData;
}//getCellControlData()//
/* (non-Javadoc)
* @see com.foundation.tcv.client.view.IAbstractClientViewComponent#getSessionViewController()
*/
public SessionViewController getSessionViewController() {
return CellComponent.this.getSessionViewController();
}//getSessionViewController()//
/* (non-Javadoc)
* @see com.foundation.tcv.client.view.IAbstractClientViewComponent#initialize(int, com.foundation.tcv.client.controller.SessionViewController)
*/
public final void initialize(int number, SessionViewController sessionViewController) {
//Never called.//
}//initialize()//
/* (non-Javadoc)
* @see com.foundation.tcv.view.IAbstractRemoteViewComponent#processMessage(com.foundation.tcv.view.ViewMessage)
*/
public Object processMessage(ViewMessage viewMessage) {
//Never called.//
return null;
}//processMessage()//
/* (non-Javadoc)
* @see com.foundation.tcv.view.IAbstractRemoteViewComponent#processRequest(int, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object)
*/
public Object processRequest(int eventNumber, Object value1, Object value2, Object value3, Object value4) {
//Never called.//
return null;
}//processRequest()//
/* (non-Javadoc)
* @see com.foundation.view.IResourceHolderComponent#resourceHolderChanged(com.foundation.view.AbstractResourceHolder, java.lang.Object, java.lang.Object)
*/
public void resourceHolderChanged(AbstractResourceHolder resourceHolder, Object oldValue, Object newValue, int flags) {
if(resourceHolder == foregroundColorHolder) {
destroyColor(getCurrentForegroundColor());
setCurrentForegroundColor(createColor((JefColor) resourceHolder.getValue()));
controlUpdateForegroundColor();
}//if//
else if(resourceHolder == backgroundColorHolder) {
destroyColor(getCurrentBackgroundColor());
setCurrentBackgroundColor(createColor((JefColor) resourceHolder.getValue()));
controlUpdateBackgroundColor();
}//else if//
else if(resourceHolder == fontHolder) {
destroyFont(getCurrentFont());
setCurrentFont(createFont((JefFont[]) resourceHolder.getValue()));
controlUpdateFont();
}//else if//
else if(resourceHolder == toolTipTextHolder) {
controlSetToolTipText((String) resourceHolder.getValue());
}//else if//
}//resourceHolderChanged()//
/* (non-Javadoc)
* @see com.foundation.view.IResourceHolderComponent#resourceHolderChanged(com.foundation.view.AbstractMultiResourceHolder, com.common.util.IHashSet, java.lang.Object, java.lang.Object)
*/
public void resourceHolderChanged(AbstractMultiResourceHolder resourceHolder, IHashSet rows, Object oldValue, Object newValue) {
}//resourceHolderChanged()//
/* (non-Javadoc)
* @see com.foundation.view.IResourceHolderComponent#resourceHolderChanged(com.foundation.view.AbstractMultiResourceHolder, java.lang.Object, java.lang.Object, java.lang.Object)
*/
public void resourceHolderChanged(AbstractMultiResourceHolder resourceHolder, Object row, Object oldValue, Object newValue) {
}//resourceHolderChanged()//
/**
* Gets the SWT control for this cell control.
* @return The control being encapsulated.
*/
public Control getSwtControl() {
return control;
}//getSwtControl()//
/**
* Initializes the control.
*/
public void initialize() {
getSwtControl().setLayoutData(layoutData);
}//initialize()//
/**
* Refreshes the control.
*/
public void refresh() {
controlUpdateBackgroundColor();
controlUpdateFont();
controlUpdateForegroundColor();
refreshIsEnabled();
refreshToolTipText();
}//refresh()//
/**
* Updates the background color being used by the component.
*/
public void controlUpdateBackgroundColor() {
Color newColor = null;
if(getCurrentFont() != null) {
newColor = getCurrentBackgroundColor();
}//if//
else if(CellComponent.this.getCurrentFont() != null) {
newColor = CellComponent.this.getCurrentBackgroundColor();
}//else if//
if(getSwtControl().getBackground() != newColor) {
getSwtControl().setBackground(newColor);
}//if//
}//controlUpdateBackgroundColor()//
/**
* Updates the foreground color being used by the component.
*/
public void controlUpdateForegroundColor() {
Color newColor = null;
if(getCurrentFont() != null) {
newColor = getCurrentForegroundColor();
}//if//
else if(CellComponent.this.getCurrentFont() != null) {
newColor = CellComponent.this.getCurrentForegroundColor();
}//else if//
if(getSwtControl().getForeground() != newColor) {
getSwtControl().setForeground(newColor);
}//if//
}//controlUpdateForegroundColor()//
/**
* Updates the font being used by the component.
*/
public void controlUpdateFont() {
Font newFont = null;
if(getCurrentFont() != null) {
newFont = getCurrentFont();
}//if//
else if(CellComponent.this.getCurrentFont() != null) {
newFont = CellComponent.this.getCurrentFont();
}//else if//
if(getSwtControl().getFont() != newFont) {
getSwtControl().setFont(newFont);
}//if//
}//controlUpdateFont()//
/**
* Refreshes the tool tip value.
*/
public void refreshToolTipText() {
//Check for a common value which will only be set if the value is a single association.//
if(CellComponent.this.toolTipTextHolder != null) {
getSwtControl().setToolTipText((String) CellComponent.this.toolTipTextHolder.getValue());
}//if//
else { //Use a value per row.//
if(toolTipTextHolder == null) {
toolTipTextHolder = new ResourceHolder(this);
}//if//
toolTipTextHolder.setValue(getCellControlData().toolTipText);
}//else//
}//refreshToolTipText()//
/**
* Refreshes the control's enabled state.
*/
public void refreshIsEnabled() {
controlSetIsEnabled(getCellControlData().isEnabled == null ? true : getCellControlData().isEnabled.booleanValue());
}//refreshIsEnabled()//
/**
* Releases the control.
*/
public void release() {
if(toolTipTextHolder != null) {
toolTipTextHolder.release();
}//if//
if(backgroundColorHolder != null) {
backgroundColorHolder.release();
}//if//
if(foregroundColorHolder != null) {
foregroundColorHolder.release();
}//if//
if(fontHolder != null) {
fontHolder.release();
}//if//
if(getCurrentBackgroundColor() != null) {
destroyColor(getCurrentBackgroundColor());
}//if//
if(getCurrentForegroundColor() != null) {
destroyColor(getCurrentForegroundColor());
}//if//
if(getCurrentFont() != null) {
destroyFont(getCurrentFont());
}//if//
if((control != null) && (!control.isDisposed())) {
control.dispose();
}//if//
}//release()//
/**
* Forces any pending synchronizations to complete.
*/
public abstract void synchronize();
/**
* Gets the current foreground color used by the component.
* @return The currently used foreground color, or null if none is provided.
*/
protected Color getCurrentForegroundColor() {
return currentForegroundColor;
}//getCurrentForegroundColor()//
/**
* Sets the current foreground color used by the component.
* @param currentForegroundColor The currently used foreground color, or null if none is provided.
*/
protected void setCurrentForegroundColor(Color currentForegroundColor) {
this.currentForegroundColor = currentForegroundColor;
}//setCurrentForegroundColor()//
/**
* Gets the current background color used by the component.
* @return The currently used background color, or null if none is provided.
*/
protected Color getCurrentBackgroundColor() {
return currentBackgroundColor;
}//getCurrentBackgroundColor()//
/**
* Sets the current background color used by the component.
* @param currentBackgroundColor The currently used background color, or null if none is provided.
*/
protected void setCurrentBackgroundColor(Color currentBackgroundColor) {
this.currentBackgroundColor = currentBackgroundColor;
}//setCurrentBackgroundColor()//
/**
* Gets the current font used by the component.
* @return The currently used font, or null if none is provided.
*/
protected Font getCurrentFont() {
return currentFont;
}//getCurrentFont()//
/**
* Sets the current font used by the component.
* @param currentFont The currently used font, or null if none is provided.
*/
protected void setCurrentFont(Font currentFont) {
this.currentFont = currentFont;
}//setCurrentFont()//
/**
* Sets the component's enabled state.
* @param isEnabled Whether the enabled state should be altered to be enabled, otherwise it is altered to be disabled.
*/
protected void controlSetIsEnabled(boolean isEnabled) {
getSwtControl().setEnabled(isEnabled);
}//controlSetEnabledState()//
/**
* Sets the tool tip.
* @param toolTipText The text to display in the default tool tip.
*/
protected void controlSetToolTipText(String toolTipText) {
getSwtControl().setToolTipText(toolTipText);
}//controlSetToolTipText()//
}//CellControl//
/**
* CellComponent constructor.
*/
public CellComponent() {
}//CellComponent()//
/**
* Whether the component will utilize a paint routine to draw the information.
* @return Whether a draw capability will be used by this cell component (which may be different from whether the cell component supports a draw routine).
*/
public boolean usePaint() {
return !supportsControl() && supportsPaint();
}//usePaint()//
/**
* Whether the component will utilize a control to draw the information.
* @return One of the identifiers indicating whether a control will be used by this cell component (which may be different from whether the cell component supports a creation of a control).
*/
public int useControl() {
return supportsControl() ? USE_CONTROL_ALWAYS : USE_CONTROL_NEVER;
}//useControl()//
/**
* Determines whether the component creates interactive controls and has implemented the initializeCellControl(CellControlData) method.
* @return Whether this component builds cell controls.
* @see #initializeCellControl(CellControlData)
*/
public boolean supportsControl() {
return false;
}//supportsControl()//
/**
* Determines whether the component is capable of painting a cell in place of a control.
* @return Whether this component paints a cell.
* @see #paintCell(CellControlData, GC)
*/
public boolean supportsPaint() {
return false;
}//supportsPaint()//
/**
* Gets whether the controls should grab any available horizontal space.
* @return Whether the control will use all available horizontal space.
*/
public boolean grabHorizontalSpace() {
return true;
}//grabHorizontalSpace()//
/**
* Gets whether the controls should grab any available vertical space.
* @return Whether the control will use all available vertical space.
*/
public boolean grabVerticalSpace() {
return true;
}//grabVerticalSpace()//
/**
* Gets the horizontal alignment for the controls.
* @return The control's horizontal alignment.
*/
public int getHorizontalAlignment() {
return HORIZONTAL_ALIGN_LEFT;
}//getHorizontalAlignment()//
/**
* Gets the vertical alignment for the controls.
* @return The control's vertical alignment.
*/
public int getVerticalAlignment() {
return VERTICAL_ALIGN_CENTER;
}//getVerticalAlignment()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.AbstractComponent#getContainer()
*/
public Container getContainer() {
return cellContainer != null ? cellContainer.getContainer() : null;
}//getContainer()//
/**
* Gets the parent cell container for this component.
* @return The view component containing this cell component.
*/
public ICellContainer getCellContainer() {
return cellContainer;
}//getCellContainer()//
/**
* Sets the parent cell container for this component.
* @param cellContainer The view component containing this cell component.
*/
protected void setCellContainer(ICellContainer cellContainer) {
this.cellContainer = cellContainer;
}//setCellContainer()//
/**
* Gets the optional decimal scale to be used by the component if it deals with decimal values.
* <p>Note: Controls can override this to handle a change in the scale.</p>
* @return The optional decimal scale which if negative by default should trim extra zeros (note that BigDecimal does not automatically do this).
*/
public Integer getDecimalScale() {
return decimalScale;
}//getDecimalScale()//
/**
* Sets the optional decimal scale to be used by the component if it deals with decimal values.
* @param decimalScale The optional decimal scale which if negative by default should trim extra zeros (note that BigDecimal does not automatically do this).
*/
public void setDecimalScale(Integer decimalScale) {
this.decimalScale = decimalScale;
}//setDecimalScale()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.AbstractComponent#getShell()
*/
public Shell getShell() {
return getContainer() != null ? getContainer().getShell() : null;
}//getShell()//
/**
* Creates all controls associated with this component.
* @param rowObject The model object representative for the row/cell.
* @return The control (or tree of controls) that allows interaction with the cell data.
*/
public final Control createCellControl(RowObject rowObject) {
CellControlData cellControlData = getCellControlData(rowObject);
CellControl cellControl = internalCreateCellControl(cellControlData);
cellControl.initialize();
cellControl.refresh();
return cellControl.getSwtControl();
}//createCellControl()//
/**
* Creates a control associated with this component.
* @param cellControlData The model object representative for the row/cell.
* @return The cell control that was created.
*/
protected CellControl internalCreateCellControl(CellControlData cellControlData) {
CellControl cellControl = initializeCellControl(cellControlData);
cellControlData.cellControl = cellControl;
cellControls.add(cellControl);
return cellControl;
}//internalCreateCellControl()//
/**
* Destroys a control associated with this component.
* @param control The control no longer required.
*/
public final void destroyControl(Control control) {
CellControl cellControl = (CellControl) control.getData();
//Force any pending synchronizations to complete.//
cellControl.synchronize();
//Release the resources.//
cellControl.release();
//Remove the mapping.//
cellControl.getCellControlData().cellControl = null;
cellControls.remove(cellControl);
}//destroyControl()//
/**
* Initializes a new CellControl instance complete with a view control which has a back reference to the CellControl.
* @param cellControlData The cell data for the control.
* @return The control container for the cell.
*/
protected abstract CellControl initializeCellControl(CellControlData cellControlData);
/**
* Initializes a new cell control data for the row.
* @param rowObject The row data for which a cell control data object will be created.
* @return The data container for the cell in the given row.
*/
protected abstract CellControlData initializeCellControlData(RowObject rowObject);
/**
* Releases the data for a cell in a row that no longer exists.
* @param cellControlData The cell data to be released.
*/
protected abstract void releaseCellControlData(CellControlData cellControlData);
/**
* Requests the component paint a cell.
* <p>Warning: The graphics context may be reused. All changes must be reset prior to method exit.
* @param cellControlData The cell data to be drawn.
* @param graphics The graphics context used to affect the cell pixels.
*/
protected abstract void paintCell(CellControlData cellControlData, GC graphics);
/**
* Requests the component paint a cell.
* @param rowObject The row object supplying the data to be drawn.
* @param graphics The graphics context.
*/
public final void paintCell(RowObject rowObject, GC graphics) {
paintCell(getCellControlData(rowObject), graphics);
}//paintCell()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.AbstractComponent#internalViewInitialize()
*/
protected void internalViewInitialize() {
super.internalViewInitialize();
}//internalViewInitialize()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.AbstractComponent#internalViewInitializeAll()
*/
protected void internalViewInitializeAll() {
super.internalViewInitializeAll();
}//internalViewInitializeAll()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.AbstractComponent#internalViewRelease()
*/
protected void internalViewRelease() {
IIterator iterator = getCellControlIterator();
//Release all controls.//
while(iterator.hasNext()) {
((CellControl) iterator.next()).release();
}//while//
if(toolTipTextHolder != null) {
toolTipTextHolder.release();
}//if//
if(backgroundColorHolder != null) {
backgroundColorHolder.release();
}//if//
if(foregroundColorHolder != null) {
foregroundColorHolder.release();
}//if//
if(fontHolder != null) {
fontHolder.release();
}//if//
if(getCurrentBackgroundColor() != null) {
destroyColor(getCurrentBackgroundColor());
}//if//
if(getCurrentForegroundColor() != null) {
destroyColor(getCurrentForegroundColor());
}//if//
if(getCurrentFont() != null) {
destroyFont(getCurrentFont());
}//if//
super.internalViewRelease();
}//internalViewRelease()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.AbstractComponent#internalViewReleaseAll()
*/
protected void internalViewReleaseAll() {
super.internalViewReleaseAll();
}//internalViewReleaseAll()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.AbstractComponent#internalViewSynchronize()
*/
protected final void internalViewSynchronize() {
//Never called.//
super.internalViewSynchronize();
}//internalViewSynchronize()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.AbstractComponent#internalViewSynchronizeAll()
*/
protected void internalViewSynchronizeAll() {
//Never called.//
super.internalViewSynchronizeAll();
}//internalViewSynchronizeAll()//
/**
* Registers a row object with the cell component which must create the necessary data structures for the cell data.
* @param rowObject The row being registered.
*/
public void register(RowObject rowObject) {
cellControlDataByRowObject.put(rowObject, initializeCellControlData(rowObject));
}//register()//
/**
* Unregisters a row object with the cell component which must release cell resources.
* @param rowObject The row being unregistered.
*/
public void unregister(RowObject rowObject) {
CellControlData data = (CellControlData) cellControlDataByRowObject.remove(rowObject);
releaseCellControlData(data);
}//unregister()//
/**
* Gets the cell data for the given row object.
* @param rowObject The row's model object associated with the requested control data.
* @return The cell data for the given row object.
*/
public final CellControlData getCellControlData(RowObject rowObject) {
return (CellControlData) cellControlDataByRowObject.get(rowObject);
}//getCellControlData()//
/**
* Gets an iterator over the CellControl instances, one for each control setup for a cell.
* @return The iterator over the controls for the cells.
*/
public final IIterator getCellControlIterator() {
return cellControls.iterator();
}//getCellControlIterator()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.AbstractComponent#internalProcessMessage(com.foundation.tcv.view.ViewMessage)
*/
public Object internalProcessMessage(ViewMessage viewMessage) {
Object result = null;
switch(viewMessage.getMessageNumber()) {
case MESSAGE_SET_IS_ENABLED: {
CellControlData cellControlData = getCellControlData(getCellContainer().getRowObject(viewMessage.getMessageInteger()));
Boolean value = (Boolean) viewMessage.getMessageData();
if(cellControlData == null) {
Debug.log("Bad cell control data.");
}//if//
cellControlData.isEnabled = value;
if(cellControlData.getCellControl() != null) {
cellControlData.getCellControl().refreshIsEnabled();
}//if//
break;
}//case//
case MESSAGE_SET_BACKGROUND_COLOR: {
setBackgroundColor(viewMessage.getMessageData(), viewMessage.getMessageInteger() != -1 ? getCellControlData(getCellContainer().getRowObject(viewMessage.getMessageInteger())) : null);
break;
}//case//
case MESSAGE_SET_FOREGROUND_COLOR: {
setForegroundColor(viewMessage.getMessageData(), viewMessage.getMessageInteger() != -1 ? getCellControlData(getCellContainer().getRowObject(viewMessage.getMessageInteger())) : null);
break;
}//case//
case MESSAGE_SET_FONTS: {
setFont(viewMessage.getMessageData(), viewMessage.getMessageInteger() != -1 ? getCellControlData(getCellContainer().getRowObject(viewMessage.getMessageInteger())) : null);
break;
}//case//
case MESSAGE_SET_TOOL_TIP_TEXT: {
setToolTipText(viewMessage.getMessageData(), viewMessage.getMessageInteger() != -1 ? getCellControlData(getCellContainer().getRowObject(viewMessage.getMessageInteger())) : null);
break;
}//case//
case MESSAGE_SET_DECIMAL_SCALE: {
setDecimalScale((Integer) viewMessage.getMessageData());
break;
}//case//
case MESSAGE_SET_LAYOUT_DATA: {
setLayoutData(viewMessage.getMessageData());
break;
}//case//
default: {
result = super.internalProcessMessage(viewMessage);
}//default//
}//switch//
return result;
}//internalProcessMessage()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.AbstractComponent#internalResourceHolderChanged(com.foundation.tcv.client.view.ResourceHolder, java.lang.Object, java.lang.Object, int)
*/
protected void internalResourceHolderChanged(ResourceHolder resourceHolder, Object oldValue, Object newValue, int flags) {
if(resourceHolder == backgroundColorHolder) {
IIterator iterator = getCellControlIterator();
destroyColor(getCurrentBackgroundColor());
setCurrentBackgroundColor(createColor((JefColor) newValue));
//Update the existing controls.//
while(iterator.hasNext()) {
CellControl cellControl = (CellControl) iterator.next();
cellControl.controlUpdateBackgroundColor();
}//while//
}//if//
else if(resourceHolder == foregroundColorHolder) {
IIterator iterator = getCellControlIterator();
destroyColor(getCurrentForegroundColor());
setCurrentForegroundColor(createColor((JefColor) newValue));
//Update the existing controls.//
while(iterator.hasNext()) {
CellControl cellControl = (CellControl) iterator.next();
cellControl.controlUpdateForegroundColor();
}//while//
}//else if//
else if(resourceHolder == fontHolder) {
IIterator iterator = getCellControlIterator();
destroyFont(getCurrentFont());
setCurrentFont(createFont((JefFont[]) newValue));
//Update the existing controls.//
while(iterator.hasNext()) {
CellControl cellControl = (CellControl) iterator.next();
cellControl.controlUpdateFont();
}//while//
}//else if//
else if(resourceHolder == toolTipTextHolder) {
IIterator iterator = getCellControlIterator();
//Update the existing controls.//
while(iterator.hasNext()) {
CellControl cellControl = (CellControl) iterator.next();
cellControl.refreshToolTipText();
}//while//
}//else if//
else {
super.internalResourceHolderChanged(resourceHolder, oldValue, newValue, flags);
}//else//
}//internalResourceHolderChanged()//
/**
* Sets the background color for the cell control(s).
* @param value The new value.
* @param cellControlData The cell control data if changing a specific cell, otherwise null.
*/
protected void setBackgroundColor(Object value, CellControlData cellControlData) {
if(cellControlData == null) {
if(backgroundColorHolder == null) {
backgroundColorHolder = new ResourceHolder(this);
}//if//
backgroundColorHolder.setValue(value);
}//if//
else {
cellControlData.backgroundColor = value;
if(cellControlData.getCellControl() != null) {
CellControl cellControl = cellControlData.getCellControl();
if(cellControl.backgroundColorHolder == null) {
cellControl.backgroundColorHolder = new ResourceHolder(cellControl);
}//if//
cellControl.backgroundColorHolder.setValue(value);
}//if//
}//else//
}//setBackgroundColor()//
/**
* Sets the foreground color for the cell control(s).
* @param value The new value.
* @param cellControlData The cell control data if changing a specific cell, otherwise null.
*/
protected void setForegroundColor(Object value, CellControlData cellControlData) {
if(cellControlData == null) {
if(foregroundColorHolder == null) {
foregroundColorHolder = new ResourceHolder(this);
}//if//
foregroundColorHolder.setValue(value);
}//if//
else {
cellControlData.foregroundColor = value;
if(cellControlData.getCellControl() != null) {
CellControl cellControl = cellControlData.getCellControl();
if(cellControl.foregroundColorHolder == null) {
cellControl.foregroundColorHolder = new ResourceHolder(cellControl);
}//if//
cellControl.foregroundColorHolder.setValue(value);
}//if//
}//else//
}//setForegroundColor()//
/**
* Sets the font for the cell control(s).
* @param value The new value.
* @param cellControlData The cell control data if changing a specific cell, otherwise null.
*/
protected void setFont(Object value, CellControlData cellControlData) {
if(cellControlData == null) {
if(fontHolder == null) {
fontHolder = new ResourceHolder(this);
}//if//
fontHolder.setValue(value);
}//if//
else {
cellControlData.font = value;
if(cellControlData.getCellControl() != null) {
CellControl cellControl = cellControlData.getCellControl();
if(cellControl.fontHolder == null) {
cellControl.fontHolder = new ResourceHolder(cellControl);
}//if//
cellControl.fontHolder.setValue(value);
}//if//
}//else//
}//setFont()//
/**
* Sets the tool tip text for the cell control(s).
* @param value The new value.
* @param cellControlData The cell control data if changing a specific cell, otherwise null.
*/
protected void setToolTipText(Object value, CellControlData cellControlData) {
if(cellControlData == null) {
if(toolTipTextHolder == null) {
toolTipTextHolder = new ResourceHolder(this);
}//if//
toolTipTextHolder.setValue(value);
}//if//
else {
cellControlData.toolTipText = value;
if(cellControlData.getCellControl() != null) {
cellControlData.getCellControl().refreshToolTipText();
}//if//
}//else//
}//setToolTipText()//
/**
* Sets the layout data for the component.
* @param layoutData The data that describes how the component is to be layed out within its parent.
*/
public void setLayoutData(Object layoutData) {
this.layoutData = layoutData;
}//setLayoutData()//
/**
* Gets the current foreground color used by the component.
* @return The currently used foreground color, or null if none is provided.
*/
protected Color getCurrentForegroundColor() {
return currentForegroundColor;
}//getCurrentForegroundColor()//
/**
* Sets the current foreground color used by the component.
* @param currentForegroundColor The currently used foreground color, or null if none is provided.
*/
protected void setCurrentForegroundColor(Color currentForegroundColor) {
this.currentForegroundColor = currentForegroundColor;
}//setCurrentForegroundColor()//
/**
* Gets the current background color used by the component.
* @return The currently used background color, or null if none is provided.
*/
protected Color getCurrentBackgroundColor() {
return currentBackgroundColor;
}//getCurrentBackgroundColor()//
/**
* Sets the current background color used by the component.
* @param currentBackgroundColor The currently used background color, or null if none is provided.
*/
protected void setCurrentBackgroundColor(Color currentBackgroundColor) {
this.currentBackgroundColor = currentBackgroundColor;
}//setCurrentBackgroundColor()//
/**
* Gets the current font used by the component.
* @return The currently used font, or null if none is provided.
*/
protected Font getCurrentFont() {
return currentFont;
}//getCurrentFont()//
/**
* Sets the current font used by the component.
* @param currentFont The currently used font, or null if none is provided.
*/
protected void setCurrentFont(Font currentFont) {
this.currentFont = currentFont;
}//setCurrentFont()//
}//CellComponent//

View File

@@ -0,0 +1,362 @@
/*
* Copyright (c) 2007,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.client.cell;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import com.common.util.IIterator;
import com.common.util.IList;
import com.common.util.LiteList;
import com.foundation.tcv.swt.client.Container;
import com.foundation.tcv.swt.client.ICellContainer;
import com.foundation.tcv.swt.client.Layout;
import com.foundation.tcv.swt.client.RowObject;
import com.foundation.tcv.view.ViewMessage;
import com.foundation.view.swt.cell.CellContainer.ContainerControl;
public abstract class CellContainer extends CellComponent implements ICellContainer, com.foundation.tcv.swt.cell.ICellContainer {
/** A collection of components contained by this container. */
private IList cellComponents = null;
/** The layout used by the container. */
private Layout layout = null;
/** The ordering of the contained cell components for tabbing. */
private CellComponent[] tabOrder = null;
/** The inheritance of the background for this container. */
private int inheritType = 0;
public class ContainerCellControlData extends CellControlData {
/**
* ContainerCellControlData constructor.
* @param rowObject The row for the cell.
*/
public ContainerCellControlData(RowObject rowObject) {
super(rowObject);
}//ContainerCellControlData()//
}//ContainerCellControlData//
public class ContainerCellControl extends CellControl {
/**
* ContainerCellControl constructor.
* @param control The control being encapsulated.
* @param cellData The cell's data.
*/
public ContainerCellControl(Composite control, ContainerCellControlData cellData) {
super(control, cellData);
}//ContainerCellControl()//
/**
* Gets the button cell data for the control.
* @return The cell data for the button control.
*/
public ContainerCellControlData getContainerCellControlData() {
return (ContainerCellControlData) getCellControlData();
}//getContainerCellControlData()//
/**
* Gets the button control.
* @return The button being encapsulated.
*/
public Composite getSwtComposite() {
return (Composite) getSwtControl();
}//getSwtButton()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent.CellControl#initialize()
*/
public void initialize() {
if(CellContainer.this.getLayout() != null) {
getSwtComposite().setLayout(CellContainer.this.getLayout().createLayout(getContainerCellControlData().getRowObject()));
}//if//
super.initialize();
setInheritBackground(CellContainer.this.inheritType);
//Initialize the child cell components.//
for(int index = 0; index < getCellComponents().getSize(); index++) {
((CellComponent) getCellComponents().get(index)).getCellControlData(getCellControlData().getRowObject()).getCellControl().initialize();
}//for//
if((getTabOrder() != null) && (getTabOrder().length > 0)) {
Control[] tabList = new Control[getTabOrder().length];
for(int index = 0; index < getTabOrder().length; index++) {
tabList[index] = getTabOrder()[index].getCellControlData(getCellControlData().getRowObject()).getCellControl().getSwtControl();
}//for//
getSwtComposite().setTabList(tabList);
}//if//
}//initialize()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent.CellControl#refresh()
*/
public void refresh() {
super.refresh();
//Refresh the child cell components.//
for(int index = 0; index < getCellComponents().getSize(); index++) {
((CellComponent) getCellComponents().get(index)).getCellControlData(getCellControlData().getRowObject()).getCellControl().refresh();
}//for//
}//refresh()//
/* (non-Javadoc)
* @see com.foundation.view.swt.cell.CellComponent.CellControl#release()
*/
public void release() {
super.release();
//Release the child cell components.//
for(int index = 0; index < getCellComponents().getSize(); index++) {
((CellComponent) getCellComponents().get(index)).getCellControlData(getCellControlData().getRowObject()).getCellControl().release();
}//for//
}//release()//
/**
* Forces any pending synchronizations to complete.
*/
public void synchronize() {
//Synchronize the child cell components.//
for(int index = 0; index < getCellComponents().getSize(); index++) {
((CellComponent) getCellComponents().get(index)).getCellControlData(getCellControlData().getRowObject()).getCellControl().synchronize();
}//for//
}//synchronize()//
/**
* Sets the background inheritance for all children.
* @param inherit Whether the background of this composite should be inherited by all child controls. The default value will cause children that don't specify otherwise to inherit the background.
* @see #INHERIT_NONE
* @see #INHERIT_DEFAULT
* @see #INHERIT_FORCE
*/
public void setInheritBackground(int inheritType) {
int mode = inheritType == INHERIT_FORCE ? SWT.INHERIT_FORCE : inheritType == INHERIT_DEFAULT ? SWT.INHERIT_DEFAULT : SWT.INHERIT_NONE;
getSwtComposite().setBackgroundMode(mode);
}//setInheritBackground()//
}//ContainerCellControl//
/**
* CellContainer constructor.
*/
public CellContainer() {
}//CellContainer()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#register(com.foundation.tcv.swt.client.RowObject)
*/
public void register(RowObject rowObject) {
super.register(rowObject);
if(cellComponents != null) {
for(int index = 0; index < cellComponents.getSize(); index++) {
CellComponent next = (CellComponent) cellComponents.get(index);
next.register(rowObject);
}//for//
}//if//
}//register()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#unregister(com.foundation.tcv.swt.client.RowObject)
*/
public void unregister(RowObject rowObject) {
super.unregister(rowObject);
if(cellComponents != null) {
for(int index = 0; index < cellComponents.getSize(); index++) {
CellComponent next = (CellComponent) cellComponents.get(index);
next.unregister(rowObject);
}//for//
}//if//
}//unregister()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#paintCell(com.foundation.tcv.swt.client.cell.CellComponent.CellControlData, org.eclipse.swt.graphics.GC)
*/
protected void paintCell(CellControlData cellControlData, GC graphics) {
//Does nothing. TODO: Should some components of a cell container be paintable and others are not?
}//paintCell()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.ICellContainer#addCellComponent(com.foundation.tcv.swt.client.cell.CellComponent)
*/
public void addCellComponent(CellComponent component) {
if(cellComponents == null) {
cellComponents = new LiteList(10, 20);
}//if//
cellComponents.add(component);
if(isInitialized()) {
component.internalViewInitializeAll();
}//if//
}//addCellComponent()//
/**
* Removes a cell component that was child of this container.
* @param component The cell component to no longer be contained by this container.
*/
public void removeCellComponent(CellComponent component) {
cellComponents.remove(component);
}//removeCellComponent()//
/**
* Gets the collection of cell components for this container.
* @return The cell components contained within this container.
*/
public IList getCellComponents() {
return cellComponents == null ? LiteList.EMPTY_LIST : cellComponents;
}//getCellComponents()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.ICellContainer#getRowObject(int)
*/
public RowObject getRowObject(int objectId) {
return getCellContainer().getRowObject(objectId);
}//getRowObject()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.ICellContainer#getRowObjects()
*/
public IIterator getRowObjects() {
return getCellContainer().getRowObjects();
}//getRowObjects()//
/**
* Gets the layout for this container.
* @return The container's layout.
*/
public Layout getLayout() {
return layout;
}//getLayout()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.ICellContainer#setLayout(com.foundation.tcv.swt.client.Layout)
*/
public void setLayout(Layout layout) {
this.layout = layout;
}//setLayout()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.ICellContainer#getSwtComposite(com.foundation.tcv.swt.client.RowObject)
*/
public Composite getSwtComposite(RowObject rowObject) {
return ((ContainerCellControl) ((ContainerCellControlData) getCellControlData(rowObject)).getCellControl()).getSwtComposite();
}//getSwtComposite()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.ICellContainer#getSwtComposites()
*/
public IIterator getSwtComposites() {
final IIterator cellControlIterator = getCellControlIterator();
return new IIterator() {
public void resetToFront() {
cellControlIterator.resetToFront();
}//resetToFont()//
public boolean remove() {
return false;
}//remove()//
public Object next() {
return ((ContainerControl) cellControlIterator.next()).getSwtComposite();
}//next()//
public boolean hasNext() {
return cellControlIterator.hasNext();
}//hasNext()//
};
}//getSwtComposite()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#getContainer()
*/
public Container getContainer() {
return getCellContainer() == null ? null : getCellContainer().getContainer();
}//getContainer()//
/* (non-Javadoc)
* @see com.foundation.view.swt.cell.CellComponent#internalViewInitializeAll()
*/
protected void internalViewInitializeAll() {
super.internalViewInitializeAll();
if(cellComponents != null) {
for(int index = 0; index < cellComponents.getSize(); index++) {
((CellComponent) cellComponents.get(index)).internalViewInitializeAll();
}//for//
}//if//
}//internalViewInitializeAll()//
/* (non-Javadoc)
* @see com.foundation.view.swt.cell.CellComponent#internalViewReleaseAll()
*/
protected void internalViewReleaseAll() {
super.internalViewReleaseAll();
if(cellComponents != null) {
for(int index = 0; index < cellComponents.getSize(); index++) {
((CellComponent) cellComponents.get(index)).internalViewReleaseAll();
}//for//
}//if//
}//internalViewReleaseAll()//
/* (non-Javadoc)
* @see com.foundation.view.swt.cell.CellComponent#internalViewSynchronizeAll()
*/
protected void internalViewSynchronizeAll() {
super.internalViewSynchronizeAll();
if(cellComponents != null) {
for(int index = 0; index < cellComponents.getSize(); index++) {
((CellComponent) cellComponents.get(index)).internalViewSynchronizeAll();
}//for//
}//if//
}//internalViewSynchronizeAll()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.AbstractComponent#internalProcessMessage(com.foundation.tcv.view.ViewMessage)
*/
public Object internalProcessMessage(ViewMessage viewMessage) {
Object result = null;
switch(viewMessage.getMessageNumber()) {
case MESSAGE_SET_TAB_ORDER: {
int[] componentNumbers = (int[]) viewMessage.getMessageData();
CellComponent[] array = new CellComponent[componentNumbers.length];
for(int index = 0; index < componentNumbers.length; index++) {
array[index] = (CellComponent) getComponent(componentNumbers[index]);
}//for//
setTabOrder(array);
break;
}//case//
case MESSAGE_SET_INHERIT_BACKGROUND: {
setInheritBackground(viewMessage.getMessageInteger());
break;
}//case//
default: {
result = super.internalProcessMessage(viewMessage);
}//default//
}//switch//
return result;
}//internalProcessMessage()//
/**
* Gets the tab ordering for the cell components contained within the panel.
* @return The panel's component tab ordering.
*/
protected CellComponent[] getTabOrder() {
return tabOrder;
}//getTabOrder()//
/**
* Sets the tab ordering for the cell components contained within the panel.
* @param tabOrder The panel's component tab ordering.
*/
protected void setTabOrder(CellComponent[] tabOrder) {
this.tabOrder = tabOrder;
}//setTabOrder()//
/**
* Sets the background inheritance for all children.
* @param inherit Whether the background of this composite should be inherited by all child controls. The default value will cause children that don't specify otherwise to inherit the background.
* @see #INHERIT_NONE
* @see #INHERIT_DEFAULT
* @see #INHERIT_FORCE
*/
public void setInheritBackground(int inheritType) {
IIterator iterator = getCellControlIterator();
//Update the existing controls.//
while(iterator.hasNext()) {
ContainerControl containerControl = (ContainerControl) iterator.next();
containerControl.setInheritBackground(inheritType);
}//while//
this.inheritType = inheritType;
}//setInheritBackground()//
}//CellContainer//

View File

@@ -0,0 +1,340 @@
/*
* Copyright (c) 2006,2008 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.client.cell;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.DateTime;
import com.common.thread.IRunnable;
import com.foundation.tcv.swt.cell.ICellDateTime;
import com.foundation.tcv.swt.client.ICellContainer;
import com.foundation.tcv.swt.client.RowObject;
import com.foundation.tcv.view.ViewMessage;
public class CellDateTime extends CellComponent implements ICellDateTime {
/** The control style. */
private int style = 0;
/** Whether the selection state should be auto-synchronized. */
private boolean autoSynchronizeSelection = true;
/** The delay to be used when auto synchronizing changes. */
private long autoSynchronizeSelectionDelay = 500;
/** Whether the year should be transfered to/from the view/model. */
private boolean includeYear = false;
/** Whether the month should be transfered to/from the view/model. */
private boolean includeMonth = false;
/** Whether the day should be transfered to/from the view/model. */
private boolean includeDay = false;
/** Whether the hour should be transfered to/from the view/model. */
private boolean includeHour = false;
/** Whether the minutes should be transfered to/from the view/model. */
private boolean includeMinute = false;
/** Whether the seconds should be transfered to/from the view/model. */
private boolean includeSecond = false;
/**
* Maintains the cell data for the control. A control may only exist if it is visible, but the data must be maintained regardless.
*/
public class DateTimeCellControlData extends CellControlData {
/** The control's selection state. */
private Date selection = null;
/**
* DateTimeCellControlData constructor.
* @param rowObject The row for the cell.
*/
public DateTimeCellControlData(RowObject rowObject) {
super(rowObject);
}//DateTimeCellControlData()//
}//DateTimeCellControlData//
/**
* Encapsulates a control with related data such as listeners and the data model for the cell.
*/
public class DateTimeCellControl extends CellControl implements SelectionListener {
/** The task that auto synchronizes the selection state after a short delay. */
private Task autoSynchronizeSelectionTask = null;
/** The calendar used to transfer the date/time data to/from the model. */
private Calendar calendar = GregorianCalendar.getInstance();
/**
* DateTimeCellControl constructor.
* @param control The control being encapsulated.
* @param cellData The cell's data.
*/
public DateTimeCellControl(DateTime control, DateTimeCellControlData cellData) {
super(control, cellData);
getSwtDateTime().addSelectionListener(this);
}//DateTimeCellControl()//
/**
* Gets the button cell data for the control.
* @return The cell data for the button control.
*/
public DateTimeCellControlData getDateTimeCellControlData() {
return (DateTimeCellControlData) getCellControlData();
}//getDateTimeCellControlData()//
/**
* Gets the button control.
* @return The button being encapsulated.
*/
public org.eclipse.swt.widgets.DateTime getSwtDateTime() {
return (org.eclipse.swt.widgets.DateTime) getSwtControl();
}//getSwtDateTime()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent.CellControl#initialize()
*/
public void initialize() {
super.initialize();
}//initialize()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent.CellControl#refresh()
*/
public void refresh() {
super.refresh();
refreshSelection();
}//refresh()//
/**
* Refreshes the selection value.
*/
public void refreshSelection() {
controlSetSelection(getDateTimeCellControlData().selection != null ? getDateTimeCellControlData().selection : new Date());
}//refreshSelection()//
/* (non-Javadoc)
* @see com.foundation.view.swt.cell.CellComponent.CellControl#release()
*/
public void release() {
if(!getSwtDateTime().isDisposed()) {
getSwtDateTime().removeSelectionListener(this);
}//if//
//Ignore any pending synchronizations.//
synchronized(this) {
if(autoSynchronizeSelectionTask != null) {
removeTask(autoSynchronizeSelectionTask);
autoSynchronizeSelectionTask = null;
}//if//
}//synchronized//
super.release();
}//release()//
/**
* Forces any pending synchronizations to complete.
*/
public void synchronize() {
if(autoSynchronizeSelectionTask != null) {
removeTask(autoSynchronizeSelectionTask);
autoSynchronizeSelectionTask.execute();
autoSynchronizeSelectionTask = null;
}//if//
}//synchronize()//
/* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
*/
public void widgetDefaultSelected(SelectionEvent event) {
}//widgetDefaultSelected()//
/* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
public void widgetSelected(SelectionEvent event) {
if(includeYear) {
calendar.set(Calendar.YEAR, getSwtDateTime().getYear());
}//if//
if(includeMonth) {
calendar.set(Calendar.MONTH, getSwtDateTime().getMonth());
}//if//
if(includeDay) {
calendar.set(Calendar.DAY_OF_MONTH, getSwtDateTime().getDay());
}//if//
if(includeHour) {
calendar.set(Calendar.HOUR_OF_DAY, getSwtDateTime().getHours());
}//if//
if(includeMinute) {
calendar.set(Calendar.MINUTE, getSwtDateTime().getMinutes());
}//if//
if(includeSecond) {
calendar.set(Calendar.SECOND, getSwtDateTime().getSeconds());
}//if//
selectionChanged(calendar.getTime());
}//widgetSelected()//
/**
* Called when the selection is changed in the view control.
* This method updates all bindings and
* @param date The current selection.
*/
protected void selectionChanged(final Date date) {
if(autoSynchronizeSelection) {
if(autoSynchronizeSelectionDelay > 0) {
//Start a task to send the text to the server after a short delay. This will reduce the overhead of auto synchronizing the selection.//
synchronized(this) {
if(autoSynchronizeSelectionTask != null) {
removeTask(autoSynchronizeSelectionTask);
}//if//
autoSynchronizeSelectionTask = new Task() {
public void execute() {
//Make sure that this task is still valid and is not being superceeded.//
synchronized(DateTimeCellControl.this) {
if(autoSynchronizeSelectionTask == this) {
//Cleanup after the task.//
autoSynchronizeSelectionTask = null;
getEventLoop().executeAsync(new IRunnable() {
public Object run() {
sendMessage(MESSAGE_VIEW_SYNCHRONIZE_SELECTION, date, null, getDateTimeCellControlData().getRowObject().getObjectId(), 0);
return null;
}//run()//
});
}//if//
}//synchronized//
}//run()//
};
addTask(autoSynchronizeSelectionTask, autoSynchronizeSelectionDelay);
}//synchronized//
}//if//
else {
sendMessage(MESSAGE_VIEW_SYNCHRONIZE_SELECTION, date, null, getDateTimeCellControlData().getRowObject().getObjectId(), 0);
}//else//
}//if//
getDateTimeCellControlData().selection = date;
}//selectionChanged()//
/**
* Sets the component's selection state.
* @param isSelected Whether the button is to be selected.
*/
protected void controlSetSelection(Date date) {
if(getSwtDateTime() != null) {
date = date == null ? new Date() : date;
calendar.setTime(date);
if(includeYear) {
getSwtDateTime().setYear(calendar.get(Calendar.YEAR));
}//if//
if(includeMonth) {
getSwtDateTime().setMonth(calendar.get(Calendar.MONTH));
}//if//
if(includeDay) {
getSwtDateTime().setDay(calendar.get(Calendar.DAY_OF_MONTH));
}//if//
if(includeHour) {
getSwtDateTime().setHours(calendar.get(Calendar.HOUR_OF_DAY));
}//if//
if(includeMinute) {
getSwtDateTime().setMinutes(calendar.get(Calendar.MINUTE));
}//if//
if(includeSecond) {
getSwtDateTime().setSeconds(calendar.get(Calendar.SECOND));
}//if//
}//if//
}//controlSetSelection()//
}//DateTimeCellControl//
/**
* CellDateTime constructor.
*/
public CellDateTime() {
}//CellDateTime()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#supportsControl()
*/
public boolean supportsControl() {
return true;
}//supportsControl()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#initializeCellControl(com.foundation.tcv.swt.client.cell.CellComponent.CellControlData)
*/
protected CellControl initializeCellControl(CellControlData cellControlData) {
return new DateTimeCellControl(new DateTime(getCellContainer().getSwtComposite(cellControlData.getRowObject()), style), (DateTimeCellControlData) cellControlData);
}//initializeCellControl()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#initializeCellControlData(com.foundation.tcv.swt.client.CollectionComponent.RowObject)
*/
protected CellControlData initializeCellControlData(RowObject rowObject) {
return new DateTimeCellControlData(rowObject);
}//initializeCellControlData()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#releaseCellControlData(com.foundation.tcv.swt.client.cell.CellComponent.CellControlData)
*/
protected void releaseCellControlData(CellControlData cellControlData) {
}//releaseCellControlData()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#paintCell(com.foundation.tcv.swt.client.cell.CellComponent.CellControlData, org.eclipse.swt.graphics.GC)
*/
protected void paintCell(CellControlData cellControlData, GC graphics) {
}//paintCell()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#internalViewRelease()
*/
protected void internalViewRelease() {
super.internalViewRelease();
}//internalViewRelease()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.AbstractComponent#internalProcessMessage(com.foundation.tcv.view.ViewMessage)
*/
public Object internalProcessMessage(ViewMessage viewMessage) {
Object result = null;
switch(viewMessage.getMessageNumber()) {
case MESSAGE_INITIALIZE: {
setCellContainer((ICellContainer) getComponent(viewMessage.getMessageInteger()));
style = viewMessage.getMessageSecondaryInteger();
getCellContainer().addCellComponent(this);
includeYear = (((style & STYLE_DATE) > 0) || ((style & STYLE_CALENDAR) > 0));
includeMonth = (((style & STYLE_DATE) > 0) || ((style & STYLE_CALENDAR) > 0));
includeDay = ((((style & STYLE_DATE) > 0) && ((style & STYLE_SHORT) == 0)) || ((style & STYLE_CALENDAR) > 0));
includeHour = ((style & STYLE_TIME) > 0);
includeMinute = ((style & STYLE_TIME) > 0);
includeSecond = (((style & STYLE_TIME) > 0) && ((style & STYLE_SHORT) == 0));
break;
}//case//
case MESSAGE_SET_AUTO_SYNCHRONIZE_SELECTION: {
autoSynchronizeSelection = ((Boolean) viewMessage.getMessageData()).booleanValue();
break;
}//case//
case MESSAGE_SET_AUTO_SYNCHRONIZE_SELECTION_DELAY: {
autoSynchronizeSelectionDelay = ((Long) viewMessage.getMessageData()).longValue();
break;
}//case//
case MESSAGE_VIEW_REFRESH_SELECTION: {
setSelection((Date) viewMessage.getMessageData(), viewMessage.getMessageInteger() != -1 ? (DateTimeCellControlData) getCellControlData(getCellContainer().getRowObject(viewMessage.getMessageInteger())) : null);
break;
}//case//
default: {
result = super.internalProcessMessage(viewMessage);
}//default//
}//switch//
return result;
}//internalProcessMessage()//
/**
* Sets the selection for the cell control(s).
* @param value The new value.
* @param cellControlData The cell control data if changing a specific cell, otherwise null.
*/
protected void setSelection(Date value, DateTimeCellControlData cellControlData) {
cellControlData.selection = value;
if(cellControlData.getCellControl() != null) {
((DateTimeCellControl) cellControlData.getCellControl()).refreshSelection();
}//if//
}//setSelection()//
}//CellDateTime//

View File

@@ -0,0 +1,136 @@
/*
* Copyright (c) 2007,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.client.cell;
import org.eclipse.swt.widgets.Composite;
import com.foundation.tcv.swt.cell.ICellPanel;
import com.foundation.tcv.swt.client.ICellContainer;
import com.foundation.tcv.swt.client.RowObject;
import com.foundation.tcv.view.ViewMessage;
public class CellPanel extends CellContainer implements ICellPanel {
/** The control style. */
private int style = 0;
public class PanelCellControlData extends ContainerCellControlData {
/**
* PanelCellControlData constructor.
* @param rowObject The row for the cell.
*/
public PanelCellControlData(RowObject rowObject) {
super(rowObject);
}//PanelCellControlData()//
}//PanelCellControlData//
public class PanelCellControl extends ContainerCellControl {
/**
* PanelCellControl constructor.
* @param control The control being encapsulated.
* @param cellData The cell's data.
*/
public PanelCellControl(Composite control, PanelCellControlData cellData) {
super(control, cellData);
}//PanelCellControl()//
/**
* Gets the cell data for the control.
* @return The cell data for the control.
*/
public PanelCellControlData getPanelCellControlData() {
return (PanelCellControlData) getCellControlData();
}//getPanelCellControlData()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent.CellControl#initialize()
*/
public void initialize() {
super.initialize();
}//initialize()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent.CellControl#refresh()
*/
public void refresh() {
super.refresh();
}//refresh()//
/* (non-Javadoc)
* @see com.foundation.view.swt.cell.CellComponent.CellControl#release()
*/
public void release() {
super.release();
}//release()//
/**
* Forces any pending synchronizations to complete.
*/
public void synchronize() {
super.synchronize();
}//synchronize()//
}//PanelCellControl//
/**
* CellPanel constructor.
*/
public CellPanel() {
super();
}//CellPanel()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#initializeCellControl(com.foundation.tcv.swt.client.cell.CellComponent.CellControlData)
*/
protected CellControl initializeCellControl(CellControlData cellControlData) {
return new PanelCellControl(new Composite(getCellContainer().getSwtComposite(cellControlData.getRowObject()), style), (PanelCellControlData) cellControlData);
}//initializeCellControl()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#internalCreateCellControl(com.foundation.tcv.swt.client.cell.CellComponent.CellControlData)
*/
protected CellControl internalCreateCellControl(CellControlData cellControlData) {
CellControl result = super.internalCreateCellControl(cellControlData);
//Initialize the child cell components.//
for(int index = 0; index < getCellComponents().getSize(); index++) {
((CellComponent) getCellComponents().get(index)).createCellControl(cellControlData.getRowObject());
}//for//
return result;
}//internalCreateCellControl()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#initializeCellControlData(com.foundation.tcv.swt.client.RowObject)
*/
protected CellControlData initializeCellControlData(RowObject rowObject) {
return new PanelCellControlData(rowObject);
}//initializeCellControlData()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#releaseCellControlData(com.foundation.tcv.swt.client.cell.CellComponent.CellControlData)
*/
protected void releaseCellControlData(CellControlData cellControlData) {
}//releaseCellControlData()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#supportsControl()
*/
public boolean supportsControl() {
return true;
}//supportsControl()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.AbstractComponent#internalProcessMessage(com.foundation.tcv.view.ViewMessage)
*/
public Object internalProcessMessage(ViewMessage viewMessage) {
Object result = null;
switch(viewMessage.getMessageNumber()) {
case MESSAGE_INITIALIZE: {
int[] data = (int[]) viewMessage.getMessageData();
setCellContainer((ICellContainer) getComponent(data[0]));
style = data[1];
getCellContainer().addCellComponent(this);
break;
}//case//
default: {
result = super.internalProcessMessage(viewMessage);
}//default//
}//switch//
return result;
}//internalProcessMessage()//
}//CellPanel//

View File

@@ -0,0 +1,192 @@
/*
* Copyright (c) 2007,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.client.cell;
import java.math.BigDecimal;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
import com.foundation.tcv.swt.cell.IProgress;
import com.foundation.tcv.swt.client.ICellContainer;
import com.foundation.tcv.swt.client.RowObject;
import com.foundation.tcv.view.ViewMessage;
import com.foundation.view.JefColor;
import com.foundation.view.swt.util.SwtUtilities;
public class CellProgress extends CellComponent implements IProgress {
/** The multiplier used to generate an integer from the current progress value. */
private BigDecimal multiplier = null;
/** The progress color. */
private JefColor foreground = new JefColor("blue");
/** The progress style. */
private int style = 0;
/** The control's default maximum. */
private int maximum = 0;
/** The control's default minimum. */
private int minimum = 0;
/**
* Maintains the cell data for the control. A control may only exist if it is visible, but the data must be maintained regardless.
*/
public class ProgressCellControlData extends CellControlData {
/** The current progress in its original form. */
private BigDecimal currentProgress = null;
/**
* ProgressCellControlData constructor.
* @param rowObject The row for the cell.
*/
public ProgressCellControlData(RowObject rowObject) {
super(rowObject);
}//ProgressCellControlData()//
/**
* Gets the current progress.
* @return The current progress in its original form.
*/
public BigDecimal getCurrentProgress() {
return currentProgress;
}//getCurrentProgress()//
/**
* Sets the current progress.
* @param currentProgress The current progress in its original form.
*/
public void setCurrentProgress(BigDecimal currentProgress) {
this.currentProgress = currentProgress;
}//setCurrentProgress()//
}//ProgressCellControlData//
/**
* Progress constructor.
*/
public CellProgress() {
}//Progress()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#supportsPaint()
*/
public boolean supportsPaint() {
return true;
}//supportsPaint()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.AbstractComponent#internalProcessMessage(com.foundation.tcv.view.ViewMessage)
*/
public Object internalProcessMessage(ViewMessage viewMessage) {
Object result = null;
switch(viewMessage.getMessageNumber()) {
case MESSAGE_INITIALIZE: {
int[] data = (int[]) viewMessage.getMessageData();
setCellContainer((ICellContainer) getComponent(data[0]));
style = data[1];
getCellContainer().addCellComponent(this);
break;
}//case//
case MESSAGE_SET_MAXIMUM: {
maximum = viewMessage.getMessageData() != null ? ((Integer) viewMessage.getMessageData()).intValue() : 1;
break;
}//case//
case MESSAGE_SET_MINIMUM: {
minimum = viewMessage.getMessageData() != null ? ((Integer) viewMessage.getMessageData()).intValue() : 0;
break;
}//case//
case MESSAGE_SET_PROGRESS: {
ProgressCellControlData controlData = (ProgressCellControlData) getCellControlData(getCellContainer().getRowObject(viewMessage.getMessageInteger()));
controlData.setCurrentProgress(viewMessage.getMessageData() != null ? (BigDecimal) viewMessage.getMessageData() : new BigDecimal(minimum));
//TODO: Narrow this to the affected cell.
getContainer().getSwtComposite().redraw();
break;
}//case//
case MESSAGE_SET_MULTIPLIER: {
setMultiplier((BigDecimal) viewMessage.getMessageData());
//TODO: Narrow this to the affected cell.
getContainer().getSwtComposite().redraw();
break;
}//case//
default: {
result = super.internalProcessMessage(viewMessage);
}//default//
}//switch//
return result;
}//internalProcessMessage()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#initializeCellControl(com.foundation.tcv.swt.client.cell.CellComponent.CellControlData)
*/
protected CellControl initializeCellControl(CellControlData cellControlData) {
return null;
}//initializeCellControl()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#initializeCellControlData(com.foundation.tcv.swt.client.CollectionComponent.RowObject)
*/
protected CellControlData initializeCellControlData(RowObject rowObject) {
return new ProgressCellControlData(rowObject);
}//initializeCellControlData()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#releaseCellControlData(com.foundation.tcv.swt.client.cell.CellComponent.CellControlData)
*/
protected void releaseCellControlData(CellControlData cellControlData) {
}//releaseCellControlData()//
/* (non-Javadoc)
* @see com.foundation.tcv.swt.client.cell.CellComponent#paintCell(com.foundation.tcv.swt.client.cell.CellComponent.CellControlData, org.eclipse.swt.graphics.GC)
*/
protected void paintCell(CellControlData cellControlData, GC graphics) {
ProgressCellControlData progressData = ((ProgressCellControlData) cellControlData);
BigDecimal currentProgress = progressData.getCurrentProgress();
double progress;
if(currentProgress != null) {
if(multiplier != null) {
currentProgress = currentProgress.multiply(multiplier);
}//if//
progress = currentProgress.doubleValue();
if(progress != minimum) {
Rectangle rectangle = graphics.getClipping();
double width = rectangle.width;
Color foreground = SwtUtilities.getColor(graphics.getDevice(), this.foreground);
Color oldForeground = graphics.getForeground();
Color oldBackground = graphics.getBackground();
//Set the graphics context's initial settings.//
graphics.setForeground(foreground);
graphics.setBackground(foreground);
//Draw the progress bar.//
rectangle.height -= 2;
rectangle.y--;
rectangle.width = (int) Math.ceil(width / ((maximum - minimum) / progress));
graphics.fillRectangle(rectangle);
//Reset the graphics context settings.//
graphics.setForeground(oldForeground);
graphics.setBackground(oldBackground);
if(!this.foreground.isColorConstant()) {
foreground.dispose();
}//if//
}//if//
}//if//
}//paintCell()//
/**
* Gets the multiplier used to construct an integer from the progress value.
* @return The progress multiplier.
*/
public BigDecimal getMultiplier() {
return multiplier;
}//getMultiplier()//
/**
* Sets the multiplier used to construct an integer from the progress value.
* @param multiplier The progress multiplier.
*/
public void setMultiplier(BigDecimal multiplier) {
this.multiplier = multiplier;
}//setMultiplier()//
}//Progress//