Initial commit from SVN.
This commit is contained in:
@@ -0,0 +1,687 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.events.SelectionListener;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import com.common.thread.IRunnable;
|
||||
import com.common.util.LiteList;
|
||||
import com.foundation.tcv.client.view.ResourceHolder;
|
||||
import com.foundation.tcv.model.LinkInfo;
|
||||
import com.foundation.tcv.swt.IToolBar;
|
||||
import com.foundation.tcv.view.ViewMessage;
|
||||
import com.foundation.view.JefImage;
|
||||
import com.foundation.view.LinkData;
|
||||
import com.foundation.view.swt.util.SwtUtilities;
|
||||
|
||||
public class ToolBar extends Container implements IToolBar {
|
||||
/** The collection of ToolItem instances contained by the tool bar. */
|
||||
private LiteList toolItems = new LiteList(10, 20);
|
||||
/** The collection of Menu instances associated with tool items. */
|
||||
private LiteList menus = new LiteList(10, 20);
|
||||
|
||||
/**
|
||||
* This tool item can be extended to provide customized tool item behavior.
|
||||
*/
|
||||
public static abstract class AbstractToolItem extends AbstractComponent implements IToolBar.IAbstractToolItem {
|
||||
private Container container = null;
|
||||
/** Whether this is a stateful item. */
|
||||
protected boolean isStateful = false;
|
||||
/** Whether this is a separator. */
|
||||
protected boolean isSeparator = false;
|
||||
/** Whether this is a separator. */
|
||||
protected boolean isDropDown = false;
|
||||
/** A counter tracking the number of times the component has been told to be disabled. This allows us to disable a container which in turn disables all components. */
|
||||
private int disabledCounter = 0;
|
||||
/** A holder for the value of the tool tip text. */
|
||||
private ResourceHolder toolTipTextHolder = new ResourceHolder(this);
|
||||
/** A holder for the value of the enabled state flag. */
|
||||
private ResourceHolder isEnabledHolder = new ResourceHolder(this);
|
||||
|
||||
/**
|
||||
* AbstractToolItem constructor.
|
||||
*/
|
||||
public AbstractToolItem() {
|
||||
}//AbstractToolItem()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.view.IAbstractComponent#getContainer()
|
||||
*/
|
||||
public Container getContainer() {
|
||||
return container;
|
||||
}//getContainer()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.view.swt.IInternalAbstractComponent#getShell()
|
||||
*/
|
||||
public Shell getShell() {
|
||||
return container != null ? container.getShell() : null;
|
||||
}//getShell()//
|
||||
/* (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: {
|
||||
if(getSwtToolItem() == null) {
|
||||
int[] data = (int[]) viewMessage.getMessageData();
|
||||
int style = data[1];
|
||||
|
||||
//Link to the parent container.//
|
||||
this.container = (Container) getComponent(data[0]);
|
||||
((ToolBar) getContainer()).addToolItem(this);
|
||||
//Create the SWT widget.//
|
||||
setSwtWidget(new org.eclipse.swt.widgets.ToolItem(((ToolBar) getContainer()).getSwtToolBar(), style));
|
||||
getSwtWidget().setData(this);
|
||||
isStateful = ((style & STYLE_RADIO) > 0) || ((style & STYLE_CHECK) > 0);
|
||||
isSeparator = ((style & STYLE_SEPARATOR) > 0);
|
||||
isDropDown = ((style & STYLE_DROP_DOWN) > 0);
|
||||
}//if//
|
||||
break;
|
||||
}//case//
|
||||
case MESSAGE_SET_IS_ENABLED: {
|
||||
isEnabledHolder.setValue(viewMessage.getMessageData());
|
||||
break;
|
||||
}//case//
|
||||
case MESSAGE_SET_TOOL_TIP_TEXT: {
|
||||
toolTipTextHolder.setValue(viewMessage.getMessageData());
|
||||
break;
|
||||
}//case//
|
||||
default: {
|
||||
result = super.internalProcessMessage(viewMessage);
|
||||
}//default//
|
||||
}//switch//
|
||||
|
||||
return result;
|
||||
}//internalProcessMessage()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.view.swt.AbstractComponent#internalOnLinkInvoked(int, java.lang.Object)
|
||||
*/
|
||||
protected void internalOnLinkInvoked(int linkTarget, Object data) {
|
||||
switch(linkTarget) {
|
||||
case LINK_TARGET_IS_ENABLED: {
|
||||
internalSetEnabledState(data != null && data instanceof Boolean ? ((Boolean) data).booleanValue() : false);
|
||||
break;
|
||||
}//case//
|
||||
case LINK_TARGET_TOOL_TIP_TEXT: {
|
||||
getSwtToolItem().setToolTipText(data instanceof String ? (String) data : "");
|
||||
break;
|
||||
}//case//
|
||||
default: {
|
||||
super.internalOnLinkInvoked(linkTarget, data);
|
||||
break;
|
||||
}//default//
|
||||
}//switch//
|
||||
}//internalOnLinkInvoked()//
|
||||
/* (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 resource, Object oldValue, Object newValue, int flags) {
|
||||
if(resource == toolTipTextHolder) {
|
||||
getSwtToolItem().setToolTipText((String) newValue);
|
||||
}//if//
|
||||
else if(resource == isEnabledHolder) {
|
||||
internalSetEnabledState(((Boolean) newValue).booleanValue());
|
||||
//TODO: Determine whether the size will change before resizing. This can help eliminate flashing.
|
||||
//resize();
|
||||
}//else if//
|
||||
else {
|
||||
super.internalResourceHolderChanged(resource, oldValue, newValue, flags);
|
||||
}//else//
|
||||
}//internalOnAssociationChanged()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.tcv.swt.client.AbstractComponent#internalViewRelease()
|
||||
*/
|
||||
protected void internalViewRelease() {
|
||||
toolTipTextHolder.release();
|
||||
isEnabledHolder.release();
|
||||
|
||||
if(!getSwtToolItem().isDisposed()) {
|
||||
getSwtToolItem().dispose();
|
||||
}//if//
|
||||
|
||||
super.internalViewRelease();
|
||||
}//internalViewRelease()//
|
||||
/**
|
||||
* Gets the swt tool item for this tool item.
|
||||
* @return The SWT tool item providing visualization for this tool item.
|
||||
*/
|
||||
public org.eclipse.swt.widgets.ToolItem getSwtToolItem() {
|
||||
return (org.eclipse.swt.widgets.ToolItem) getSwtWidget();
|
||||
}//getSwtToolItem()//
|
||||
/**
|
||||
* Performs the actual work of enable or disabling the component.
|
||||
* @param isEnabled Whether the enabled state should be altered to be enabled, otherwise it is altered to be disabled.
|
||||
*/
|
||||
protected void internalSetEnabledState(boolean isEnabled) {
|
||||
//Some components may not have controls, such as value holders.//
|
||||
if(getSwtToolItem() != null) {
|
||||
if(!isEnabled || disabledCounter > 0) {
|
||||
disabledCounter += !isEnabled ? 1 : -1;
|
||||
}//if//
|
||||
|
||||
if(isEnabled && disabledCounter == 0) {
|
||||
getSwtToolItem().setEnabled(true);
|
||||
}//if//
|
||||
else if(!isEnabled && disabledCounter == 1) {
|
||||
getSwtToolItem().setEnabled(false);
|
||||
}//else if//
|
||||
}//if//
|
||||
}//internalSetEnabledState()//
|
||||
/**
|
||||
* Forces the component to resize and requests that the window layout.
|
||||
*/
|
||||
public void resize() {
|
||||
if(isInitialized()) {
|
||||
getSwtToolItem().getParent().pack(true);
|
||||
getSwtToolItem().getParent().getShell().layout(true, true);
|
||||
}//if//
|
||||
}//resize()//
|
||||
}//AbstractToolItem//
|
||||
|
||||
/**
|
||||
* Encapsulates an item in the bar.
|
||||
*/
|
||||
public static class ToolItem extends AbstractToolItem implements IToolBar.IToolItem, SelectionListener {
|
||||
/** The custom control displayed by the tool item. */
|
||||
private Component control = null;
|
||||
/** The popup menu displayed when the tool item is a drop down. */
|
||||
private Menu menu = null;
|
||||
/** The linkage for the selection. */
|
||||
private Linkage selectionLinkage = new Linkage();
|
||||
/** The task that auto synchronizes the selection after a short delay. */
|
||||
private Task autoSynchronizeSelectionTask = null;
|
||||
/** Whether the selection state is auto synchronized. */
|
||||
private boolean autoSynchronizeSelection = true;
|
||||
/** The delay to be used when auto synchronizing changes to the text. */
|
||||
private long autoSynchronizeSelectionDelay = 0;
|
||||
/** Whether the item has a custom width. */
|
||||
private boolean customWidth = false;
|
||||
/** The last selection state in the model, known to the component. Used to reduce method calling & round trip messages. */
|
||||
private boolean selectionState = false;
|
||||
/** Whether selection notifications to the server will block for a response. */
|
||||
private boolean blockOnSelections = false;
|
||||
/** 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);
|
||||
/** A holder for the value of the hot image. */
|
||||
private ResourceHolder hotImageHolder = new ResourceHolder(this);
|
||||
/** A holder for the value of the disabled image. */
|
||||
private ResourceHolder disabledImageHolder = new ResourceHolder(this);
|
||||
|
||||
/**
|
||||
* ToolItem constructor.
|
||||
*/
|
||||
public ToolItem() {
|
||||
}//ToolItem()//
|
||||
/* (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_BLOCK_ON_SELECTIONS: {
|
||||
blockOnSelections = ((Boolean) viewMessage.getMessageData()).booleanValue();
|
||||
break;
|
||||
}//case//
|
||||
case MESSAGE_AUTO_SIZE: {
|
||||
//Auto calculate the width based on the packed size of the control.//
|
||||
//TODO: Should we set the control's height to the bar's height?
|
||||
if(!customWidth && isSeparator && control != null) {
|
||||
Point size;
|
||||
|
||||
control.getSwtControl().pack();
|
||||
size = control.getSwtControl().computeSize(SWT.DEFAULT, SWT.DEFAULT);
|
||||
getSwtToolItem().setWidth(size.x);
|
||||
}//if//
|
||||
break;
|
||||
}//case//
|
||||
case MESSAGE_SET_TEXT: {
|
||||
textHolder.setValue(viewMessage.getMessageData());
|
||||
break;
|
||||
}//case//
|
||||
case MESSAGE_SET_IMAGE: {
|
||||
imageHolder.setValue(viewMessage.getMessageData());
|
||||
break;
|
||||
}//case//
|
||||
case MESSAGE_SET_HOT_IMAGE: {
|
||||
hotImageHolder.setValue(viewMessage.getMessageData());
|
||||
break;
|
||||
}//case//
|
||||
case MESSAGE_SET_DISABLED_IMAGE: {
|
||||
disabledImageHolder.setValue(viewMessage.getMessageData());
|
||||
break;
|
||||
}//case//
|
||||
case MESSAGE_SET_IS_SELECTED: {
|
||||
Boolean isSelected = (Boolean) viewMessage.getMessageData();
|
||||
|
||||
//Only set the selection if it has changed.//
|
||||
if(isSelected.booleanValue() != getSwtToolItem().getSelection()) {
|
||||
getSwtToolItem().setSelection(isSelected.booleanValue());
|
||||
selectionState = isSelected.booleanValue();
|
||||
|
||||
//Send feedback to the server so that it will properly maintain state.//
|
||||
if(autoSynchronizeSelection) {
|
||||
sendMessage(MESSAGE_VIEW_SYNCHRONIZE_SELECTION, isSelected);
|
||||
}//if//
|
||||
|
||||
selectionLinkage.invoke(isSelected);
|
||||
}//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//
|
||||
case MESSAGE_ADD_SELECTION_LINK: {
|
||||
LinkInfo info = (LinkInfo) viewMessage.getMessageData();
|
||||
|
||||
selectionLinkage.add(new LinkData(getComponent(info.getComponent()), info.getTarget(), info.getData(), info.isBoolean(), info.invertLogic(), info.nullValue()));
|
||||
break;
|
||||
}//case//
|
||||
case MESSAGE_SET_CONTROL: {
|
||||
int[] data = (int[]) viewMessage.getMessageData();
|
||||
|
||||
control = (Component) getComponent(data[0]);
|
||||
//TODO: If we are already initialized we should swap controls. Currently this could not happen, but we may allow it in the future.
|
||||
break;
|
||||
}//case//
|
||||
case MESSAGE_SET_MENU: {
|
||||
int[] data = (int[]) viewMessage.getMessageData();
|
||||
|
||||
menu = (Menu) getComponent(data[0]);
|
||||
break;
|
||||
}//case//
|
||||
case MESSAGE_SET_WIDTH: {
|
||||
customWidth = true;
|
||||
getSwtToolItem().setWidth(((Integer) viewMessage.getMessageData()).intValue());
|
||||
break;
|
||||
}//case//
|
||||
default: {
|
||||
result = super.internalProcessMessage(viewMessage);
|
||||
}//default//
|
||||
}//switch//
|
||||
|
||||
return result;
|
||||
}//internalProcessMessage()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.view.swt.AbstractComponent#internalOnLinkInvoked(int, java.lang.Object)
|
||||
*/
|
||||
protected void internalOnLinkInvoked(int linkTarget, Object data) {
|
||||
switch(linkTarget) {
|
||||
case LINK_TARGET_SELECTION: {
|
||||
boolean isSelected = data instanceof Boolean ? ((Boolean) data).booleanValue() : false;
|
||||
|
||||
if(isStateful) {
|
||||
if(isSelected != getSwtToolItem().getSelection()) {
|
||||
getSwtToolItem().setSelection(isSelected);
|
||||
selectionChanged(isSelected);
|
||||
}//if//
|
||||
}//if//
|
||||
else {
|
||||
selectionChanged(true);
|
||||
}//else//
|
||||
break;
|
||||
}//case//
|
||||
case LINK_TARGET_IMAGE: {
|
||||
if(getSwtToolItem().getImage() != null) {
|
||||
getSwtToolItem().getImage().dispose();
|
||||
}//if//
|
||||
|
||||
getSwtToolItem().setImage(data instanceof JefImage ? SwtUtilities.getImage(getSwtToolItem().getDisplay(), (JefImage) data) : null);
|
||||
resize();
|
||||
break;
|
||||
}//case//
|
||||
case LINK_TARGET_DISABLED_IMAGE: {
|
||||
if(getSwtToolItem().getDisabledImage() != null) {
|
||||
getSwtToolItem().getDisabledImage().dispose();
|
||||
}//if//
|
||||
|
||||
getSwtToolItem().setDisabledImage(data instanceof JefImage ? SwtUtilities.getImage(getSwtToolItem().getDisplay(), (JefImage) data) : null);
|
||||
resize();
|
||||
break;
|
||||
}//case//
|
||||
case LINK_TARGET_ROLLOVER_IMAGE: {
|
||||
if(getSwtToolItem().getHotImage() != null) {
|
||||
getSwtToolItem().getHotImage().dispose();
|
||||
}//if//
|
||||
|
||||
getSwtToolItem().setHotImage(data instanceof JefImage ? SwtUtilities.getImage(getSwtToolItem().getDisplay(), (JefImage) data) : null);
|
||||
resize();
|
||||
break;
|
||||
}//case//
|
||||
case LINK_TARGET_TEXT: {
|
||||
getSwtToolItem().setText(data instanceof String ? (String) data : "");
|
||||
resize();
|
||||
break;
|
||||
}//case//
|
||||
default: {
|
||||
super.internalOnLinkInvoked(linkTarget, data);
|
||||
break;
|
||||
}//default//
|
||||
}//switch//
|
||||
}//internalOnLinkInvoked()//
|
||||
/* (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 resource, Object oldValue, Object newValue, int flags) {
|
||||
if(resource == textHolder) {
|
||||
getSwtToolItem().setText((String) newValue);
|
||||
resize();
|
||||
}//if//
|
||||
else if(resource == imageHolder) {
|
||||
destroyImage(getSwtToolItem().getImage());
|
||||
getSwtToolItem().setImage(createImage((JefImage) newValue));
|
||||
resize();
|
||||
}//else if//
|
||||
else if(resource == hotImageHolder) {
|
||||
destroyImage(getSwtToolItem().getHotImage());
|
||||
getSwtToolItem().setHotImage(createImage((JefImage) newValue));
|
||||
resize();
|
||||
}//else if//
|
||||
else if(resource == disabledImageHolder) {
|
||||
destroyImage(getSwtToolItem().getDisabledImage());
|
||||
getSwtToolItem().setDisabledImage(createImage((JefImage) newValue));
|
||||
resize();
|
||||
}//else if//
|
||||
else {
|
||||
super.internalResourceHolderChanged(resource, oldValue, newValue, flags);
|
||||
}//else//
|
||||
}//internalOnAssociationChanged()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.view.swt.AbstractComponent#internalViewInitialize()
|
||||
*/
|
||||
protected void internalViewInitialize() {
|
||||
getSwtToolItem().addSelectionListener(this);
|
||||
super.internalViewInitialize();
|
||||
|
||||
if(control != null) {
|
||||
getSwtToolItem().setControl(control.getSwtControl());
|
||||
}//if//
|
||||
}//internalViewInitialize()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.view.swt.AbstractComponent#internalViewRelease()
|
||||
*/
|
||||
protected void internalViewRelease() {
|
||||
destroyImage((JefImage) imageHolder.getValue());
|
||||
destroyImage((JefImage) hotImageHolder.getValue());
|
||||
destroyImage((JefImage) disabledImageHolder.getValue());
|
||||
|
||||
synchronized(this) {
|
||||
if(autoSynchronizeSelectionTask != null) {
|
||||
removeTask(autoSynchronizeSelectionTask);
|
||||
autoSynchronizeSelectionTask = null;
|
||||
}//if//
|
||||
}//synchronized//
|
||||
|
||||
if(!getSwtToolItem().isDisposed()) {
|
||||
getSwtToolItem().removeSelectionListener(this);
|
||||
getSwtToolItem().setControl(null);
|
||||
}//if//
|
||||
|
||||
textHolder.release();
|
||||
imageHolder.release();
|
||||
hotImageHolder.release();
|
||||
disabledImageHolder.release();
|
||||
|
||||
super.internalViewRelease();
|
||||
}//internalViewRelease()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.tcv.swt.client.AbstractComponent#internalViewSynchronize()
|
||||
*/
|
||||
protected void internalViewSynchronize() {
|
||||
super.internalViewSynchronize();
|
||||
|
||||
if(!autoSynchronizeSelection) {
|
||||
boolean selection = getSwtToolItem().getSelection();
|
||||
|
||||
if(selectionState != selection) {
|
||||
selectionState = selection;
|
||||
sendMessage(MESSAGE_VIEW_SYNCHRONIZE_SELECTION, selection ? Boolean.TRUE : Boolean.FALSE);
|
||||
}//if//
|
||||
}//if//
|
||||
}//internalViewSynchronize()//
|
||||
/**
|
||||
* Sets the control used by the tool item.
|
||||
* @param control The tool item's control.
|
||||
*/
|
||||
public void setControl(Component control) {
|
||||
this.control = control;
|
||||
}//setControl()//
|
||||
/* (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) {
|
||||
if(isSeparator && control != null) {
|
||||
//Do nothing.//
|
||||
//TODO: Do we need to pass this even to the control? Will we even get the event?
|
||||
}//if//
|
||||
else if(isDropDown && event.detail == SWT.ARROW) {
|
||||
Rectangle rect = getSwtToolItem().getBounds();
|
||||
Point point = new Point(rect.x, rect.y + rect.height);
|
||||
|
||||
//Show the drop down menu.//
|
||||
point = getSwtToolItem().getParent().toDisplay(point);
|
||||
|
||||
if(menu != null) {
|
||||
menu.getSwtMenu().setLocation(point.x, point.y);
|
||||
menu.getSwtMenu().setVisible(true);
|
||||
}//if//
|
||||
}//else if//
|
||||
else if(isSeparator) {
|
||||
//Ignore//
|
||||
}//else if//
|
||||
else {
|
||||
selectionChanged(getSwtToolItem().getSelection());
|
||||
}//else//
|
||||
}//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) {
|
||||
//Handle the button selection.//
|
||||
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(ToolItem.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);
|
||||
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);
|
||||
}//if//
|
||||
else {
|
||||
sendMessage(MESSAGE_VIEW_SYNCHRONIZE_SELECTION, isSelected ? Boolean.TRUE : Boolean.FALSE);
|
||||
}//else//
|
||||
}//else//
|
||||
}//if//
|
||||
|
||||
selectionLinkage.invoke(isStateful ? isSelected ? Boolean.TRUE : Boolean.FALSE : null);
|
||||
}//selectionChanged()//
|
||||
}//ToolItem//
|
||||
/**
|
||||
* ToolBar constructor.
|
||||
*/
|
||||
public ToolBar() {
|
||||
super();
|
||||
}//ToolBar()//
|
||||
/**
|
||||
* Adds a tool item to the bar.
|
||||
* @param toolItem The item to be added.
|
||||
*/
|
||||
protected void addToolItem(AbstractToolItem toolItem) {
|
||||
toolItems.add(toolItem); //TODO: Is this necessary?
|
||||
|
||||
if(isInitialized()) {
|
||||
//TODO: Initialize the tool item.
|
||||
//Will the tool item's component already be initilialized?
|
||||
//Would this ever occur?
|
||||
}//if//
|
||||
}//addToolItem()//
|
||||
/* (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: {
|
||||
if(getSwtToolBar() == null) {
|
||||
int[] data = (int[]) viewMessage.getMessageData();
|
||||
int style = data[1];
|
||||
|
||||
//Link to the parent container.//
|
||||
setContainer((Container) getComponent(data[0]));
|
||||
getContainer().addComponent(this);
|
||||
//Create the SWT widget.//
|
||||
setSwtWidget(new org.eclipse.swt.widgets.ToolBar(getContainer().getSwtParent(), style));
|
||||
getSwtWidget().setData(this);
|
||||
|
||||
//If the container has already been initialized then force the parent to re-layout so that this component will appear.//
|
||||
if(getContainer().isInitialized()) {
|
||||
getContainer().getSwtComposite().layout(true, true);
|
||||
}//if//
|
||||
}//if//
|
||||
break;
|
||||
}//case//
|
||||
default: {
|
||||
result = super.internalProcessMessage(viewMessage);
|
||||
}//default//
|
||||
}//switch//
|
||||
|
||||
return result;
|
||||
}//internalProcessMessage()//
|
||||
/**
|
||||
* Gets the SWT tool bar that represents this tool bar.
|
||||
* @return The SWT tool bar providing visualization for this tool bar.
|
||||
*/
|
||||
public org.eclipse.swt.widgets.ToolBar getSwtToolBar() {
|
||||
return (org.eclipse.swt.widgets.ToolBar) getSwtControl();
|
||||
}//getSwtToolBar()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.tcv.swt.client.AbstractComponent#internalViewInitialize()
|
||||
*/
|
||||
protected void internalViewInitialize() {
|
||||
//Add a listener to force the view to re-layout when the toolbar changes sizes (expands or contracts).//
|
||||
getSwtToolBar().addListener(SWT.Resize, new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
getSwtToolBar().getParent().layout(true, true);
|
||||
getSwtToolBar().getParent().redraw();
|
||||
}//handleEvent()//
|
||||
});
|
||||
super.internalViewInitialize();
|
||||
}//internalViewInitialize()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.tcv.swt.client.AbstractComponent#internalViewRelease()
|
||||
*/
|
||||
protected void internalViewRelease() {
|
||||
super.internalViewRelease();
|
||||
}//internalViewRelease()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.tcv.swt.client.AbstractComponent#internalViewInitializeAll()
|
||||
*/
|
||||
protected void internalViewInitializeAll() {
|
||||
super.internalViewInitializeAll();
|
||||
|
||||
//Initialize all the tool items.//
|
||||
for(int index = 0; index < toolItems.getSize(); index++) {
|
||||
((AbstractToolItem) toolItems.get(index)).internalViewInitialize();
|
||||
}//for//
|
||||
|
||||
//Initialize all the menus.//
|
||||
for(int index = 0; index < menus.getSize(); index++) {
|
||||
((Menu) menus.get(index)).internalViewInitializeAll();
|
||||
}//for//
|
||||
}//internalViewInitializeAll()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.tcv.swt.client.AbstractComponent#internalViewReleaseAll()
|
||||
*/
|
||||
protected void internalViewReleaseAll() {
|
||||
//Release all the tool items.//
|
||||
for(int index = 0; index < toolItems.getSize(); index++) {
|
||||
((AbstractToolItem) toolItems.get(index)).internalViewRelease();
|
||||
}//for//
|
||||
|
||||
//Release all the menus.//
|
||||
for(int index = 0; index < menus.getSize(); index++) {
|
||||
((Menu) menus.get(index)).internalViewReleaseAll();
|
||||
}//for//
|
||||
|
||||
super.internalViewReleaseAll();
|
||||
}//internalViewReleaseAll()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.tcv.swt.client.AbstractComponent#internalViewSynchronizeAll()
|
||||
*/
|
||||
protected void internalViewSynchronizeAll() {
|
||||
//Synchronize all the tool items.//
|
||||
for(int index = 0; index < toolItems.getSize(); index++) {
|
||||
((AbstractToolItem) toolItems.get(index)).internalViewSynchronize();
|
||||
}//for//
|
||||
|
||||
//Synchronize all the menus.//
|
||||
for(int index = 0; index < menus.getSize(); index++) {
|
||||
((Menu) menus.get(index)).internalViewSynchronizeAll();
|
||||
}//for//
|
||||
|
||||
super.internalViewSynchronizeAll();
|
||||
}//internalViewSynchronizeAll()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.tcv.swt.client.Component#setMenu(com.foundation.tcv.swt.client.Menu)
|
||||
*/
|
||||
public void setMenu(Menu menu) {
|
||||
menus.add(menu);
|
||||
|
||||
//A tool bar can have multiple menus associated with it. Each menu is tied to a drop down tool item. Since the tool item is not a control, the menu is linked to the bar instead.//
|
||||
if((isInitialized()) && (menu != null)) {
|
||||
menu.internalViewInitializeAll();
|
||||
}//if//
|
||||
}//setMenu()//
|
||||
}//ToolBar//
|
||||
Reference in New Issue
Block a user