Initial commit from SVN.
This commit is contained in:
@@ -0,0 +1,192 @@
|
||||
/*
|
||||
* 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.events.*;
|
||||
import org.eclipse.swt.graphics.*;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
|
||||
import com.foundation.tcv.swt.*;
|
||||
import com.foundation.tcv.view.*;
|
||||
import com.foundation.tcv.client.controller.SessionViewController;
|
||||
|
||||
public class Window extends Frame implements ShellListener, IWindow {
|
||||
private Window parent = null; //The parent in this case is not the container, but used for dialog like functionality.//
|
||||
private boolean setInitialVisibility = true;
|
||||
private boolean setInitialFocus = true;
|
||||
/**
|
||||
* Window constructor.
|
||||
*/
|
||||
public Window() {
|
||||
super();
|
||||
}//Window()//
|
||||
/**
|
||||
* Gets the SWT shell that represents this frame.
|
||||
* @return The shell providing visualization for this frame.
|
||||
*/
|
||||
public org.eclipse.swt.widgets.Shell getSwtShell() {
|
||||
return (org.eclipse.swt.widgets.Shell) getSwtControl();
|
||||
}//getSwtShell()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.tcv.swt.client.Frame#registerShellListeners()
|
||||
*/
|
||||
protected void registerShellListeners() {
|
||||
//Add this component as a shell listener so we get shell events.//
|
||||
getSwtShell().addShellListener(this);
|
||||
}//registerShellListeners()//
|
||||
/* (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#internalViewRelease()
|
||||
*/
|
||||
protected void internalViewRelease() {
|
||||
try {
|
||||
if((getSwtShell() != null) && (!getSwtShell().isDisposed())) {
|
||||
//Add this component as a shell listener so we get shell events.//
|
||||
getSwtShell().addShellListener(this);
|
||||
}//if//
|
||||
|
||||
super.internalViewRelease();
|
||||
}//try//
|
||||
finally {
|
||||
if(parent != null) {
|
||||
//TODO: Find a way to bring the window to the forefront.//
|
||||
// parent.getSwtShell().setEnabled(true);
|
||||
parent.getSwtShell().setFocus();
|
||||
parent = null;
|
||||
}//if//
|
||||
}//finally//
|
||||
}//internalViewRelease()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.tcv.swt.client.AbstractComponent#internalProcessMessage(com.foundation.tcv.model.ViewMessage)
|
||||
*/
|
||||
public Object internalProcessMessage(ViewMessage viewMessage) {
|
||||
Object retVal = null;
|
||||
|
||||
switch(viewMessage.getMessageNumber()) {
|
||||
case MESSAGE_INITIALIZE: {
|
||||
if(getSwtWidget() == null) {
|
||||
long[] parentId = (long[]) viewMessage.getMessageData();
|
||||
int style = viewMessage.getMessageInteger();
|
||||
Window parent = (Window) (parentId != null ? getComponent(parentId) : null);
|
||||
|
||||
if(parent != null) {
|
||||
this.parent = parent;
|
||||
// parent.getSwtShell().setEnabled(false);
|
||||
setSwtWidget(new org.eclipse.swt.widgets.Shell(parent.getSwtShell(), style));
|
||||
}//if//
|
||||
else {
|
||||
setSwtWidget(new org.eclipse.swt.widgets.Shell(getDisplay(), style));
|
||||
}//else//
|
||||
|
||||
getSwtWidget().setData(this);
|
||||
}//if//
|
||||
break;
|
||||
}//case//
|
||||
case MESSAGE_SET_IS_VISIBLE: {
|
||||
if(setInitialVisibility && ((Boolean) viewMessage.getMessageData()).booleanValue()) {
|
||||
setInitialVisibility = false;
|
||||
centerOnParent();
|
||||
}//if//
|
||||
|
||||
retVal = super.internalProcessMessage(viewMessage);
|
||||
break;
|
||||
}//case//
|
||||
case MESSAGE_SET_FOCUS: {
|
||||
grabFocus();
|
||||
break;
|
||||
}//case//
|
||||
default: {
|
||||
retVal = super.internalProcessMessage(viewMessage);
|
||||
}//default//
|
||||
}//switch//
|
||||
|
||||
return retVal;
|
||||
}//internalProcessMessage()//
|
||||
/**
|
||||
* Grabs focus.
|
||||
*/
|
||||
protected void grabFocus() {
|
||||
if(setInitialFocus) {
|
||||
Control focusControl = locateInitialFocusControl(getSwtComposite());
|
||||
|
||||
setInitialFocus = false;
|
||||
|
||||
if(focusControl != null) {
|
||||
focusControl.setFocus();
|
||||
}//if//
|
||||
}//if//
|
||||
else {
|
||||
getSwtDecorations().setFocus();
|
||||
}//else//
|
||||
}//grabFocus()//
|
||||
/**
|
||||
* Recursively searches for the initial focus control.
|
||||
* @param parent The parent composite to look in.
|
||||
* @return The initial focus control.
|
||||
*/
|
||||
private Control locateInitialFocusControl(Composite parent) {
|
||||
Control[] tabList = parent.getTabList();
|
||||
Control result = null;
|
||||
|
||||
if(tabList != null && tabList.length > 0) {
|
||||
for(int index = 0; result == null && index < tabList.length; index++) {
|
||||
if(tabList[index] instanceof Composite) {
|
||||
result = locateInitialFocusControl((Composite) tabList[index]);
|
||||
}//if//
|
||||
else {
|
||||
result = tabList[index];
|
||||
}//else//
|
||||
}//for//
|
||||
}//if//
|
||||
|
||||
return result;
|
||||
}//locateInitialFocusControl()//
|
||||
/**
|
||||
* Centers the view on its parent if there is one.
|
||||
*/
|
||||
protected void centerOnParent() {
|
||||
if(parent != null) { //Center the window on the parent if there is one. TODO: Allow a way to turn this centering off?//
|
||||
Rectangle parentBounds = parent.getShell().getBounds();
|
||||
Point size = getSwtShell().getSize();
|
||||
Rectangle displayArea = getSwtShell().getDisplay().getClientArea();
|
||||
int x = ((parentBounds.width - size.x) >> 1) + parentBounds.x;
|
||||
int y = ((parentBounds.height - size.y) >> 1) + parentBounds.y;
|
||||
|
||||
if((x + size.x) - parentBounds.x > displayArea.width) {
|
||||
x = (displayArea.width - size.x) + parentBounds.x;
|
||||
}//if//
|
||||
|
||||
if((y + size.y) - parentBounds.y > displayArea.height) {
|
||||
y = (displayArea.height - size.y) + parentBounds.y;
|
||||
}//if//
|
||||
|
||||
if(x - parentBounds.x < 0) {
|
||||
x = parentBounds.x;
|
||||
}//if//
|
||||
|
||||
if(y - parentBounds.y < 0) {
|
||||
y = parentBounds.y;
|
||||
}//if//
|
||||
|
||||
getSwtShell().setLocation(x, y);
|
||||
}//if//
|
||||
}//centerOnParent()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.tcv.client.view.IAbstractClientViewComponent#initialize(int, com.foundation.tcv.client.controller.SessionViewController)
|
||||
*/
|
||||
public void initialize(int number, SessionViewController sessionViewController) {
|
||||
//Perform the general initialization first.//
|
||||
super.initialize(number, sessionViewController);
|
||||
}//initialize()//
|
||||
}//Window//
|
||||
Reference in New Issue
Block a user