150 lines
5.2 KiB
Java
150 lines
5.2 KiB
Java
|
|
/*
|
||
|
|
* 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.view.swt;
|
||
|
|
|
||
|
|
import com.foundation.view.MultiResourceAssociation;
|
||
|
|
import com.foundation.view.ResourceAssociation;
|
||
|
|
import com.foundation.view.SingleAssociationContainer;
|
||
|
|
import com.foundation.view.SingleResourceAssociation;
|
||
|
|
import com.foundation.view.VariableResourceAssociation;
|
||
|
|
|
||
|
|
public class CardLayout extends Layout {
|
||
|
|
/** The layout's top index resource. */
|
||
|
|
private VariableResourceAssociation topIndex = new VariableResourceAssociation(getContainer(), this, getViewContext(), SingleResourceAssociation.TYPE_INTEGER, false, new Integer(0));
|
||
|
|
/** The top and bottom margins. */
|
||
|
|
public int marginHeight = 0;
|
||
|
|
/** The left and right margins. */
|
||
|
|
public int marginWidth = 0;
|
||
|
|
/**
|
||
|
|
* CardLayout constructor.
|
||
|
|
* @param container The container that is using the layout.
|
||
|
|
*/
|
||
|
|
public CardLayout(IAbstractSwtContainer container) {
|
||
|
|
super(container);
|
||
|
|
}//CardLayout()//
|
||
|
|
/**
|
||
|
|
* CardLayout constructor.
|
||
|
|
* @param container The container that is using the layout.
|
||
|
|
*/
|
||
|
|
public CardLayout(ICellContainer container) {
|
||
|
|
super(container);
|
||
|
|
}//CardLayout()//
|
||
|
|
/**
|
||
|
|
* Changes the top index for an optional row object.
|
||
|
|
* @param rowObject The optional row object.
|
||
|
|
* @param index The new top index.
|
||
|
|
*/
|
||
|
|
protected void changeTopIndex(Object rowObject, final int index) {
|
||
|
|
applyChanges(null, new IChangeHandler() {
|
||
|
|
public void applyChanges(org.eclipse.swt.widgets.Composite composite) {
|
||
|
|
org.eclipse.swt.widgets.Layout layout = composite.getLayout();
|
||
|
|
|
||
|
|
if(layout instanceof com.foundation.view.swt.layout.CardLayout) {
|
||
|
|
((com.foundation.view.swt.layout.CardLayout) layout).topIndex = index;
|
||
|
|
composite.layout(true, false);
|
||
|
|
}//if//
|
||
|
|
}//applyChanges()//
|
||
|
|
});
|
||
|
|
}//changeTopIndex()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.view.swt.Layout#createLayout(java.lang.Object)
|
||
|
|
*/
|
||
|
|
public org.eclipse.swt.widgets.Layout createLayout(Object rowObject) {
|
||
|
|
com.foundation.view.swt.layout.CardLayout result = new com.foundation.view.swt.layout.CardLayout();
|
||
|
|
|
||
|
|
result.marginHeight = marginHeight;
|
||
|
|
result.marginWidth = marginWidth;
|
||
|
|
|
||
|
|
if(isInitialized()) {
|
||
|
|
changeTopIndex(null, topIndex.getValue(rowObject) == null ? 0 : ((Integer) topIndex.getValue(rowObject)).intValue());
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
return result;
|
||
|
|
}//createLayout()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.view.swt.Layout#initialize()
|
||
|
|
*/
|
||
|
|
public void initialize() {
|
||
|
|
topIndex.initialize();
|
||
|
|
}//initialize()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.view.swt.Layout#refresh()
|
||
|
|
*/
|
||
|
|
public void refresh() {
|
||
|
|
refreshTopIndex();
|
||
|
|
}//refresh()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.view.swt.Layout#synchronize()
|
||
|
|
*/
|
||
|
|
public void synchronize() {
|
||
|
|
}//synchronize()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.view.swt.Layout#release()
|
||
|
|
*/
|
||
|
|
public void release() {
|
||
|
|
topIndex.release();
|
||
|
|
}//release()//
|
||
|
|
/**
|
||
|
|
* Refreshes the top index assocation.
|
||
|
|
*/
|
||
|
|
protected void refreshTopIndex() {
|
||
|
|
if(topIndex.refresh(null)) {
|
||
|
|
changeTopIndex(null, topIndex.getValue(null) == null ? 0 : ((Integer) topIndex.getValue(null)).intValue());
|
||
|
|
//layoutContainer(null, true, false);
|
||
|
|
}//if//
|
||
|
|
}//refreshTopIndex()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.view.swt.Layout#onValueChanged(com.foundation.view.ResourceAssociation, boolean)
|
||
|
|
*/
|
||
|
|
public void onValueChanged(ResourceAssociation resourceAssociation, int flags) {
|
||
|
|
if(topIndex.hasAssociation((SingleResourceAssociation) resourceAssociation)) {
|
||
|
|
if(topIndex.refresh(null)) {
|
||
|
|
changeTopIndex(null, topIndex.getValue(null) == null ? 0 : ((Integer) topIndex.getValue(null)).intValue());
|
||
|
|
//layoutContainer(null, true, false);
|
||
|
|
}//if//
|
||
|
|
}//if//
|
||
|
|
else {
|
||
|
|
super.onValueChanged(resourceAssociation, flags);
|
||
|
|
}//else//
|
||
|
|
}//onValueChanged()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.view.swt.Layout#onValueChanged(com.foundation.view.ResourceAssociation, java.lang.Object, boolean)
|
||
|
|
*/
|
||
|
|
public void onValueChanged(ResourceAssociation resourceAssociation, Object alteredItem, Object data, boolean isUpdate) {
|
||
|
|
if(topIndex.hasAssociation((MultiResourceAssociation) resourceAssociation)) {
|
||
|
|
if(topIndex.refresh(alteredItem)) {
|
||
|
|
changeTopIndex(null, topIndex.getValue(alteredItem) == null ? 0 : ((Integer) topIndex.getValue(alteredItem)).intValue());
|
||
|
|
//layoutContainer(null, true, false);
|
||
|
|
}//if//
|
||
|
|
}//if//
|
||
|
|
else {
|
||
|
|
super.onValueChanged(resourceAssociation, alteredItem, data, isUpdate);
|
||
|
|
}//else//
|
||
|
|
}//onValueChanged()//
|
||
|
|
/**
|
||
|
|
* Sets the layout margin width.
|
||
|
|
* @param marginWidth The layout margin width.
|
||
|
|
*/
|
||
|
|
public void setMarginWidth(int marginWidth) {
|
||
|
|
this.marginWidth = marginWidth;
|
||
|
|
}//setMarginWidth()//
|
||
|
|
/**
|
||
|
|
* Sets the layout margin height.
|
||
|
|
* @param marginHeight The layout margin height.
|
||
|
|
*/
|
||
|
|
public void setMarginHeight(int marginHeight) {
|
||
|
|
this.marginHeight = marginHeight;
|
||
|
|
}//setMarginHeight()//
|
||
|
|
/**
|
||
|
|
* Sets an association container used to access the text.
|
||
|
|
* @param container The text association metadata.
|
||
|
|
*/
|
||
|
|
public void setTopIndexAssociation(SingleAssociationContainer container) {
|
||
|
|
this.topIndex.setAssociations(container);
|
||
|
|
}//setTextAssociation()//
|
||
|
|
}//CardLayout//
|