Initial commit from SVN.
This commit is contained in:
@@ -0,0 +1,307 @@
|
||||
/*
|
||||
* Copyright (c) 2003,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.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
|
||||
import com.common.util.*;
|
||||
import com.foundation.tcv.swt.*;
|
||||
import com.foundation.tcv.view.*;
|
||||
|
||||
public abstract class Container extends ScrollableComponent implements IContainer, IAbstractSwtContainer {
|
||||
/** A collection of components contained by this container. */
|
||||
private IList components = new LiteList(10, 30);
|
||||
/** The layout used by the container. */
|
||||
private Layout layout = null;
|
||||
/**
|
||||
* Container constructor.
|
||||
*/
|
||||
public Container() {
|
||||
}//Container()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.tcv.swt.client.IAbstractSwtContainer#getSwtComposite()
|
||||
*/
|
||||
public Composite getSwtComposite() {
|
||||
return (Composite) getSwtControl();
|
||||
}//getComposite()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.tcv.swt.client.IAbstractSwtContainer#getSwtParent()
|
||||
*/
|
||||
public Composite getSwtParent() {
|
||||
return (Composite) getSwtControl();
|
||||
}//getSwtParent()//
|
||||
/**
|
||||
* Adds a component as a child of this container.
|
||||
* @param component The component to be contained by this container.
|
||||
*/
|
||||
public void addComponent(Component component) {
|
||||
components.add(component);
|
||||
}//addComponent()//
|
||||
/**
|
||||
* Removes a component that was child of this container.
|
||||
* @param component The component to no longer be contained by this container.
|
||||
*/
|
||||
public void removeComponent(Component component) {
|
||||
components.remove(component);
|
||||
}//removeComponent()//
|
||||
/**
|
||||
* Gets the collection of components contained by this container.
|
||||
* @return The collection of all contained components.
|
||||
*/
|
||||
public IList getComponents() {
|
||||
return components;
|
||||
}//getComponents()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.tcv.swt.client.Component#getFocusControl()
|
||||
*/
|
||||
protected Control getFocusControl() {
|
||||
Control result = getSwtControl().isFocusControl() ? getSwtControl() : null;
|
||||
|
||||
if(result != null) {
|
||||
for(int index = 0; (result == null) && (index < getComponents().getSize()); index++) {
|
||||
Component component = (Component) getComponents().get(index);
|
||||
|
||||
result = component.getFocusControl();
|
||||
}//for//
|
||||
}//if//
|
||||
|
||||
return result;
|
||||
}//getFocusControl()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.tcv.swt.client.AbstractComponent#internalViewInitializeAll()
|
||||
*/
|
||||
protected void internalViewInitializeAll() {
|
||||
IList components = getComponents();
|
||||
IIterator iterator = components.iterator();
|
||||
|
||||
//Initialize all contained components that are not value holders.//
|
||||
while(iterator.hasNext()) {
|
||||
Component component = (Component) iterator.next();
|
||||
|
||||
component.internalViewInitializeAll();
|
||||
}//for//
|
||||
|
||||
super.internalViewInitializeAll();
|
||||
}//internalViewInitializeAll()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.tcv.swt.client.AbstractComponent#internalViewReleaseAll()
|
||||
*/
|
||||
protected void internalViewReleaseAll() {
|
||||
IIterator iterator = new LiteList(getComponents()).iterator();
|
||||
|
||||
//Release sub-components.//
|
||||
while(iterator.hasNext()) {
|
||||
Component component = (Component) iterator.next();
|
||||
|
||||
component.internalViewReleaseAll();
|
||||
}//for//
|
||||
|
||||
super.internalViewReleaseAll();
|
||||
}//internalViewReleaseAll()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.tcv.swt.client.AbstractComponent#internalViewSynchronizeAll()
|
||||
*/
|
||||
protected void internalViewSynchronizeAll() {
|
||||
IIterator iterator = components.iterator();
|
||||
|
||||
//Synchronize sub-components.//
|
||||
while(iterator.hasNext()) {
|
||||
Component component = (Component) iterator.next();
|
||||
|
||||
component.internalViewSynchronizeAll();
|
||||
}//for//
|
||||
|
||||
super.internalViewSynchronizeAll();
|
||||
}//internalViewSynchronizeAll()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.tcv.swt.client.AbstractComponent#internalViewInitialize()
|
||||
*/
|
||||
protected void internalViewInitialize() {
|
||||
super.internalViewInitialize();
|
||||
|
||||
if(layout != null) {
|
||||
layout.initialize();
|
||||
getSwtParent().setLayout(layout.createLayout(null));
|
||||
}//if//
|
||||
}//internalViewInitialize()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.tcv.swt.client.AbstractComponent#internalViewRelease()
|
||||
*/
|
||||
protected void internalViewRelease() {
|
||||
if(layout != null) {
|
||||
layout.release();
|
||||
}//if//
|
||||
|
||||
super.internalViewRelease();
|
||||
}//internalViewRelease()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.tcv.swt.client.AbstractComponent#internalViewSynchronize()
|
||||
*/
|
||||
protected void internalViewSynchronize() {
|
||||
super.internalViewSynchronize();
|
||||
|
||||
if(layout != null) {
|
||||
layout.synchronize();
|
||||
}//if//
|
||||
}//internalViewSynchronize()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.tcv.swt.client.AbstractComponent#internalProcessMessage(com.foundation.tcv.model.ViewMessage)
|
||||
*/
|
||||
public Object internalProcessMessage(ViewMessage viewMessage) {
|
||||
Object result = null;
|
||||
|
||||
switch(viewMessage.getMessageNumber()) {
|
||||
case MESSAGE_LAYOUT: {
|
||||
layout();
|
||||
break;
|
||||
}//case//
|
||||
case MESSAGE_SET_TAB_ORDER: {
|
||||
int[] componentNumbers = (int[]) viewMessage.getMessageData();
|
||||
Control[] array = new Control[componentNumbers.length];
|
||||
|
||||
for(int index = 0; index < componentNumbers.length; index++) {
|
||||
array[index] = getComponent(componentNumbers[index]) instanceof Container ? ((Container) getComponent(componentNumbers[index])).getSwtParent() : ((Component) getComponent(componentNumbers[index])).getSwtControl();
|
||||
}//for//
|
||||
|
||||
getSwtParent().setTabList(array);
|
||||
break;
|
||||
}//case//
|
||||
case MESSAGE_CENTER: {
|
||||
long[] centerOnView = (long[]) viewMessage.getMessageData();
|
||||
|
||||
if(centerOnView != null) {
|
||||
center(centerOnView);
|
||||
}//if//
|
||||
else {
|
||||
center();
|
||||
}//else//
|
||||
break;
|
||||
}//case//
|
||||
case MESSAGE_INHERIT_BACKGROUND: {
|
||||
int inheritType = viewMessage.getMessageInteger();
|
||||
int mode = inheritType == INHERIT_FORCE ? SWT.INHERIT_FORCE : inheritType == INHERIT_DEFAULT ? SWT.INHERIT_DEFAULT : SWT.INHERIT_NONE;
|
||||
|
||||
getSwtComposite().setBackgroundMode(mode);
|
||||
|
||||
if(getSwtParent() != getSwtComposite()) {
|
||||
getSwtParent().setBackgroundMode(mode);
|
||||
}//if//
|
||||
break;
|
||||
}//case//
|
||||
case MESSAGE_PACK: {
|
||||
if(!isSuspendingLayouts()) {
|
||||
if(viewMessage.getMessageData() instanceof Boolean) {
|
||||
getSwtParent().pack(((Boolean) viewMessage.getMessageData()).booleanValue());
|
||||
}//if//
|
||||
else {
|
||||
getSwtParent().pack();
|
||||
}//else//
|
||||
|
||||
internalPack();
|
||||
}//if//
|
||||
break;
|
||||
}//case//
|
||||
default: {
|
||||
result = super.internalProcessMessage(viewMessage);
|
||||
}//case//
|
||||
}//switch//
|
||||
|
||||
return result;
|
||||
}//internalProcessMessage()//
|
||||
/**
|
||||
* Centers the view on the primary monitor.
|
||||
*/
|
||||
protected void center() {
|
||||
//Does nothing. This should be overloaded for subclasses which are capable of standalone behavior (window, frame, etc).//
|
||||
}//center()//
|
||||
/**
|
||||
* Centers the view on the primary monitor.
|
||||
* @param centerOnView The view to center on. If this is null then it will center on the primary monitor.
|
||||
*/
|
||||
protected void center(long[] centerOnView) {
|
||||
//Does nothing. This should be overloaded for subclasses which are capable of standalone behavior (window, frame, etc).//
|
||||
}//center()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.tcv.swt.client.Component#internalSetEnabledState(boolean, boolean)
|
||||
*/
|
||||
protected void internalSetEnabledState(boolean isEnabled, boolean isLocal) {
|
||||
IIterator iterator = getComponents().iterator();
|
||||
|
||||
if(isLocal) {
|
||||
isLocallyEnabled = isEnabled;
|
||||
}//if//
|
||||
else {
|
||||
isParentEnabled = isEnabled;
|
||||
}//else//
|
||||
|
||||
if(getSwtControl().getEnabled() != isLocallyEnabled && isParentEnabled) {
|
||||
//Update the control's state.//
|
||||
getSwtControl().setEnabled(isLocallyEnabled && isParentEnabled);
|
||||
|
||||
//Enable or disable all the contained components.//
|
||||
while(iterator.hasNext()) {
|
||||
AbstractComponent next = (AbstractComponent) iterator.next();
|
||||
|
||||
if(next instanceof Component) {
|
||||
((Component) next).internalSetEnabledState(isEnabled, false);
|
||||
}//if//
|
||||
}//while//
|
||||
}//if//
|
||||
}//internalSetEnabledState()//
|
||||
/**
|
||||
* Tells the container to layout the components contained within it.
|
||||
*/
|
||||
public final void layout() {
|
||||
if(!isSuspendingLayouts()) {
|
||||
getSwtParent().layout(true, true);
|
||||
internalLayout();
|
||||
}//if//
|
||||
}//layout()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.view.swt.AbstractComponent#internalPack()
|
||||
*/
|
||||
protected void internalPack() {
|
||||
//Call internalPack on all sub-components.//
|
||||
for(int index = 0; index < getComponents().getSize(); index++) {
|
||||
((AbstractComponent) getComponents().get(index)).internalPack();
|
||||
}//for//
|
||||
}//internalPack()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.view.swt.AbstractComponent#internalLayout()
|
||||
*/
|
||||
protected void internalLayout() {
|
||||
//Call internalLayout on all sub-components.//
|
||||
for(int index = 0; index < getComponents().getSize(); index++) {
|
||||
((AbstractComponent) getComponents().get(index)).internalLayout();
|
||||
}//for//
|
||||
}//internalLayout()//
|
||||
/**
|
||||
* Called after a child resizes.
|
||||
* This allows the opportunity for the container to appropriately handle the resize of children.
|
||||
*/
|
||||
public void postResize() {
|
||||
if(getContainer() != null) {
|
||||
getContainer().postResize();
|
||||
}//if//
|
||||
}//postResize()//
|
||||
/**
|
||||
* 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.IAbstractSwtContainer#setLayout(com.foundation.tcv.swt.client.Layout)
|
||||
*/
|
||||
public void setLayout(Layout layout) {
|
||||
this.layout = layout;
|
||||
}//setLayout()//
|
||||
}//Container//
|
||||
Reference in New Issue
Block a user