270 lines
9.0 KiB
Java
270 lines
9.0 KiB
Java
/*
|
|
* 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.server;
|
|
|
|
import com.common.util.*;
|
|
import com.common.debug.*;
|
|
import com.foundation.util.*;
|
|
import com.foundation.view.*;
|
|
import com.foundation.controller.*;
|
|
import com.foundation.event.*;
|
|
import com.foundation.tcv.swt.*;
|
|
import com.foundation.tcv.view.*;
|
|
|
|
public class Panel extends Container implements IPanel {
|
|
/** The attribute that provides the collection of internal view controllers. */
|
|
private IAttributeAssociation internalViewsAttribute = null;
|
|
/** A support for receiving collection change events. */
|
|
private EventSupport eventSupport = new EventSupport(null);
|
|
/** The collection of internal view controllers. */
|
|
private ICollection internalViewControllers = null;
|
|
/** The collection of internal view controllers currently open. Maintaining this collection is necessary in the event that all view controllers are removed from the collection. */
|
|
private LiteList openViewControllers = null;
|
|
/** The next location. This was used for allowing floating frames, but that is currently disabled. */
|
|
//private int nextLocation = 0;
|
|
/** The location increment. This was used for allowing floating frames, but that is currently disabled. */
|
|
//private int locationIncrement = 20;
|
|
/**
|
|
* Panel default constructor.
|
|
* <p>Warning: This is only for use by the framework. This should never be called to create a useable instance.</p>
|
|
*/
|
|
public Panel() {
|
|
}//Panel()//
|
|
/**
|
|
* Panel constructor.
|
|
* @param parent A composite control which will be the parent of the new instance (cannot be null).
|
|
* @param name The unique component name.
|
|
* @param style The style of control to construct.
|
|
* @see #STYLE_NO_BACKGROUND
|
|
* @see #STYLE_NO_FOCUS
|
|
* @see #STYLE_NO_MERGE_PAINTS
|
|
* @see #STYLE_NO_REDRAW_RESIZE
|
|
* @see #STYLE_NO_RADIO_GROUP
|
|
* @see #STYLE_EMBEDDED
|
|
* @see #STYLE_DOUBLE_BUFFERED
|
|
* @see #STYLE_H_SCROLL
|
|
* @see #STYLE_V_SCROLL
|
|
* @see #STYLE_BORDER
|
|
* @see #STYLE_LEFT_TO_RIGHT
|
|
* @see #STYLE_RIGHT_TO_LEFT
|
|
*/
|
|
public Panel(Container parent, String name, int style) {
|
|
super(parent, name, style);
|
|
|
|
sendMessage(MESSAGE_INITIALIZE, null, null, parent.getNumber(), style);
|
|
}//Panel()//
|
|
/* (non-Javadoc)
|
|
* @see com.foundation.view.swt.Component#internalOnValueChanged(com.foundation.view.swt.IAttributeAssociation)
|
|
*/
|
|
protected void internalOnValueChanged(IAttributeAssociation attributeAssociation) {
|
|
if(attributeAssociation == internalViewsAttribute) {
|
|
internalViewRefresh();
|
|
}//if//
|
|
else {
|
|
super.internalOnValueChanged(attributeAssociation);
|
|
}//else//
|
|
}//internalOnValueChanged()//
|
|
/* (non-Javadoc)
|
|
* @see com.foundation.tcv.view.IViewComponent#processMessage(com.foundation.tcv.model.ViewMessage)
|
|
*/
|
|
public Object processMessage(ViewMessage viewMessage) {
|
|
Object retVal = null;
|
|
|
|
switch(viewMessage.getMessageNumber()) {
|
|
default: {
|
|
retVal = super.processMessage(viewMessage);
|
|
}//default//
|
|
}//switch//
|
|
|
|
return retVal;
|
|
}//processMessage()//
|
|
/* (non-Javadoc)
|
|
* @see com.foundation.tcv.swt.server.AbstractComponent#getClientClassName()
|
|
*/
|
|
protected String getClientClassName() {
|
|
return "com.foundation.tcv.swt.client.Panel";
|
|
}//getClientClassName()//
|
|
/**
|
|
* Sets the internal view controller collection.
|
|
* @param internalViewsAttribute The attribute containing the collection of view controllers representing views that exist within this panel.
|
|
*/
|
|
public void setInternalViewsAttribute(IAttributeAssociation internalViewsAttribute) {
|
|
this.internalViewsAttribute = internalViewsAttribute;
|
|
}//setInternalViewsAttribute()//
|
|
/* (non-Javadoc)
|
|
* @see com.foundation.tcv.swt.server.AbstractComponent#internalEvaluate(com.foundation.event.IEventEmitter, int, java.lang.Object[])
|
|
*/
|
|
protected void internalEvaluate(IEventEmitter eventEmitter, int eventNumber, Object[] arguments) {
|
|
//Add, remove, or replace items from the list.//
|
|
if(eventEmitter == internalViewControllers) {
|
|
if(eventNumber == IManagedCollection.EVENT.getNumber()) {
|
|
CollectionChangeEvent event = (CollectionChangeEvent) arguments[0];
|
|
|
|
if(event.hasAdds()) {
|
|
if(event.getAddedObjects() != null) {
|
|
IIterator iterator = event.getAddedObjects().iterator();
|
|
|
|
while(iterator.hasNext()) {
|
|
Object next = iterator.next();
|
|
|
|
openView((ViewController) next);
|
|
}//while//
|
|
}//if//
|
|
else {
|
|
openView((ViewController) event.getAddedObject());
|
|
}//else//
|
|
}//if//
|
|
|
|
if(event.hasRemoves()) {
|
|
if(event.getRemovedObjects() != null) {
|
|
IIterator iterator = event.getRemovedObjects().iterator();
|
|
|
|
while(iterator.hasNext()) {
|
|
Object next = iterator.next();
|
|
|
|
openViewControllers.remove(next);
|
|
closeView((ViewController) next);
|
|
}//while//
|
|
}//if//
|
|
else {
|
|
openViewControllers.remove(event.getRemovedObject());
|
|
closeView((ViewController) event.getRemovedObject());
|
|
}//else//
|
|
|
|
//if((arguments != null) && (arguments.length > 0) && (arguments[0] != null)) {
|
|
//}//if//
|
|
//else {
|
|
//Could optimize if removing all values, but there is no way to know if all values are being removed.//
|
|
// closeAllViews();
|
|
//}//else//
|
|
}//if//
|
|
}//if//
|
|
}//if//
|
|
}//internalEvaluate()//
|
|
/* (non-Javadoc)
|
|
* @see com.foundation.tcv.swt.server.AbstractComponent#internalViewInitialize()
|
|
*/
|
|
protected void internalViewInitialize() {
|
|
super.internalViewInitialize();
|
|
|
|
if(internalViewsAttribute != null) {
|
|
openViewControllers = new LiteList(10, 50);
|
|
internalViewsAttribute.register();
|
|
}//if//
|
|
}//internalViewInitialize()//
|
|
/* (non-Javadoc)
|
|
* @see com.foundation.tcv.swt.server.AbstractComponent#internalViewRelease()
|
|
*/
|
|
protected void internalViewRelease() {
|
|
super.internalViewRelease();
|
|
|
|
if(internalViewsAttribute != null) {
|
|
internalViewsAttribute.unregister();
|
|
eventSupport.unregisterAll();
|
|
closeAllViews();
|
|
}//if//
|
|
}//internalViewRelease()//
|
|
/* (non-Javadoc)
|
|
* @see com.foundation.tcv.swt.server.AbstractComponent#internalViewRefresh()
|
|
*/
|
|
protected void internalViewRefresh() {
|
|
super.internalViewRefresh();
|
|
|
|
if(internalViewsAttribute != null) {
|
|
ICollection internalViewControllers = (ICollection) internalViewsAttribute.getAttributeValue();
|
|
ICollection copy = null;
|
|
|
|
if(this.internalViewControllers != internalViewControllers) {
|
|
//Unregister the old event hooks.//
|
|
if(this.internalViewControllers instanceof IEventEmitter) {
|
|
eventSupport.unregisterAll((IEventEmitter) this.internalViewControllers);
|
|
}//if//
|
|
|
|
closeAllViews();
|
|
//Save a reference to the current collection in the model.//
|
|
this.internalViewControllers = internalViewControllers;
|
|
|
|
//Register the new event hooks.//
|
|
synchronized(internalViewControllers) {
|
|
if(internalViewControllers instanceof IManagedCollection) {
|
|
eventSupport.register(((IManagedCollection) internalViewControllers), IManagedCollection.EVENT.getNumber(), this, true);
|
|
}//if//
|
|
|
|
copy = new LiteList(internalViewControllers);
|
|
}//synchronized//
|
|
}//if//
|
|
|
|
if(copy != null) {
|
|
IIterator iterator = copy.iterator();
|
|
|
|
while(iterator.hasNext()) {
|
|
Object next = iterator.next();
|
|
|
|
if(next instanceof ViewController) {
|
|
openView((ViewController) next);
|
|
}//if//
|
|
else {
|
|
Debug.log("Error: Only view controllers may populate the collection of internal frames attached to the panel.");
|
|
}//else//
|
|
}//while//
|
|
}//if//
|
|
}//if//
|
|
}//internalViewRefresh()//
|
|
/**
|
|
* Opens the view for the associated view controller.
|
|
* @param viewController The view controller that will provide the view.
|
|
*/
|
|
private void openView(ViewController viewController) {
|
|
IView view = null;
|
|
|
|
addMessageHold();
|
|
openViewControllers.add(viewController);
|
|
view = viewController.openPartial(this, null);
|
|
|
|
if(view instanceof Frame) {
|
|
/*
|
|
int location = nextLocation;
|
|
|
|
if(location + ((Frame) view).getSwtControl().getSize().x > getSwtControl().getSize().x) {
|
|
location = 0;
|
|
}//if//
|
|
else if(location + ((Frame) view).getSwtControl().getSize().y > getSwtControl().getSize().y) {
|
|
location = 0;
|
|
}//else if//
|
|
|
|
nextLocation = location + locationIncrement;
|
|
((Frame) view).setLocation(location, location);
|
|
*/
|
|
}//if//
|
|
else {
|
|
//I could at some point wrapper the view component with a frame.//
|
|
Debug.log("Error: The view must be a frame for it to be a valid internal view.");
|
|
}//else//
|
|
|
|
removeMessageHold();
|
|
}//openView()//
|
|
/**
|
|
* Closes the view for the associated view controller.
|
|
* @param viewController The view controller that provided the view.
|
|
*/
|
|
private void closeView(ViewController viewController) {
|
|
viewController.close();
|
|
}//closeView()//
|
|
/**
|
|
* Closes all the internal views.
|
|
*/
|
|
private void closeAllViews() {
|
|
IIterator iterator = openViewControllers.iterator();
|
|
|
|
while(iterator.hasNext()) {
|
|
closeView((ViewController) iterator.next());
|
|
}//while//
|
|
|
|
openViewControllers.removeAll();
|
|
}//closeAllViews()//
|
|
}//Panel// |