/* * 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 org.eclipse.swt.widgets.Composite; import com.common.debug.Debug; import com.common.util.IIterator; import com.foundation.controller.DecorationManager; import com.foundation.view.AbstractDecoration; import com.foundation.view.IVariableResourceAssociationChangeListener; import com.foundation.view.IViewContext; import com.foundation.view.ResourceAssociation; import com.foundation.view.resource.AbstractResourceService; public abstract class Layout implements IVariableResourceAssociationChangeListener { /** The container that uses this layout. Only one of the container or cellContainer will be provided. */ private IAbstractSwtContainer container = null; /** The cell container that uses this layout. */ private ICellContainer cellContainer = null; /** Whether the layout has been initialized yet. */ private boolean isInitialized = false; /** * A handler that is called to apply a set of changes to one or more layout. */ public interface IChangeHandler { /** * Applies the changes to the layout. * @param composite The composite whose layout to apply the changes to. */ public void applyChanges(org.eclipse.swt.widgets.Composite composite); }//IChangeHandler// /** * Layout constructor. * @param container The container that is using the layout. */ public Layout(IAbstractSwtContainer container) { this.container = container; }//Layout()// /** * Layout constructor. * @param cellContainer The cell container that is using the layout. */ public Layout(ICellContainer cellContainer) { if(cellContainer instanceof IAbstractSwtContainer) { this.container = (IAbstractSwtContainer) cellContainer; }//if// else { this.cellContainer = cellContainer; }//else// }//Layout()// /** * Gets whether the layout is already initialized. * @return Whether the layout has been initialized yet. */ public boolean isInitialized() { return isInitialized; }//isInitialized()// /** * Calls layout on the container. * @param rowObject The optional row object with which the container is associated. * @param changed If the container's cache should be flushed. * @param all If all the children also require laying out. */ protected void layoutContainer(Object rowObject, boolean changed, boolean all) { if(getCellContainer() != null) { if(rowObject != null) { getCellContainer().getSwtComposite(rowObject).layout(changed, all); }//if// else { IIterator iterator = getCellContainer().getSwtComposites(); while(iterator.hasNext()) { ((Composite) iterator.next()).layout(changed, all); }//while// }//else// }//if// else { getContainer().getSwtComposite().layout(changed, all); }//else// }//layoutContainer()// /** * Applies changes to the layout in the container. * @param rowObject The optional row object with which the container is associated. * @param handler The handler called to make the actual changes. */ protected void applyChanges(Object rowObject, IChangeHandler handler) { if(getCellContainer() != null) { if(rowObject != null) { handler.applyChanges(getCellContainer().getSwtComposite(rowObject)); }//if// else { IIterator iterator = getCellContainer().getSwtComposites(); while(iterator.hasNext()) { handler.applyChanges((Composite) iterator.next()); }//while// }//else// }//if// else { if(getContainer().getSwtComposite() != null && !getContainer().getSwtComposite().isDisposed()) { handler.applyChanges(getContainer().getSwtComposite()); }//if// }//else// }//applyChanges()// /** * Gets the view context for the layout. * @return The layout's view context. */ protected IViewContext getViewContext() { return container.getViewContext(); }//getViewContext()// /** * Gets the container using this layout. * @return The container that this layout supports. */ protected IAbstractSwtContainer getContainer() { return container; }//getContainer()// /** * Gets the cell container using this layout. * @return The cell container that this layout supports. */ protected ICellContainer getCellContainer() { return cellContainer; }//getCellContainer()// /** * Creates a layout that is used by an SWT control. * @param rowObject The optional row object that the layout is associated with. This should be provided if the cellComponent is specified, otherwise it should be null. * @return The SWT layout. */ public abstract org.eclipse.swt.widgets.Layout createLayout(Object rowObject); /** * Initializes the layout. */ public abstract void initialize(); /** * Refreshes the layout by transfering data from the model to the view. */ public abstract void refresh(); /** * Synchronizes the layout by transfering data from the view to the model. */ public abstract void synchronize(); /** * Releases the layout. */ public abstract void release(); /* (non-Javadoc) * @see com.foundation.view.ISingleResourceAssociationChangeListener#addDecoration(com.foundation.view.AbstractDecoration) */ public void addDecoration(AbstractDecoration decoration) { }//addDecoration()// /* (non-Javadoc) * @see com.foundation.view.IMultiResourceAssociationChangeListener#addDecoration(com.foundation.view.ResourceAssociation, java.lang.Object, java.lang.Object, com.foundation.view.AbstractDecoration) */ public void addDecoration(ResourceAssociation association, Object row, Object data, AbstractDecoration decoration) { }//addDecoration()// /* (non-Javadoc) * @see com.foundation.view.ISingleResourceAssociationChangeListener#addMessageHold() */ public void addMessageHold() { }//addMessageHold()// /* (non-Javadoc) * @see com.foundation.view.ISingleResourceAssociationChangeListener#getDecorationManager() */ public DecorationManager getDecorationManager() { return container.getDecorationManager(); }//getDecorationManager()// /* (non-Javadoc) * @see com.foundation.view.ISingleResourceAssociationChangeListener#getResourceService() */ public AbstractResourceService getResourceService() { return container.getResourceService(); }//getResourceService()// /* (non-Javadoc) * @see com.foundation.view.ISingleResourceAssociationChangeListener#onValueChanged(com.foundation.view.ResourceAssociation) */ public void onValueChanged(ResourceAssociation resourceAssociation, int flags) { Debug.log(new RuntimeException("Error: Unexpected (unhandled by Layout) resource association found. Resource URL: " + resourceAssociation.toString())); }//onValueChanged()// /* (non-Javadoc) * @see com.foundation.view.IMultiResourceAssociationChangeListener#onValueChanged(com.foundation.view.ResourceAssociation, java.lang.Object, java.lang.Object, boolean) */ public void onValueChanged(ResourceAssociation resourceAssociation, Object alteredItem, Object data, boolean isUpdate) { Debug.log(new RuntimeException("Error: Unexpected (unhandled by Layout) resource association found. Resource URL: " + resourceAssociation.toString())); }//onValueChanged()// /* (non-Javadoc) * @see com.foundation.view.IMultiResourceAssociationChangeListener#onModelExternallyChanged(com.foundation.view.ResourceAssociation, java.lang.Object, java.lang.Object, boolean, java.lang.Object) */ public void onModelExternallyChanged(ResourceAssociation resourceAssociation, Object alteredItem, Object data, boolean isCleared, Object originalValue) { }//onModelExternallyChanged()// /* (non-Javadoc) * @see com.foundation.view.ISingleResourceAssociationChangeListener#onModelExternallyChanged(com.foundation.view.ResourceAssociation, boolean, java.lang.Object) */ public void onModelExternallyChanged(ResourceAssociation resourceAssociation, boolean isCleared, Object originalValue) { }//onModelExternallyChanged()// /* (non-Javadoc) * @see com.foundation.view.ISingleResourceAssociationChangeListener#removeDecoration(com.foundation.view.AbstractDecoration) */ public void removeDecoration(AbstractDecoration decoration) { }//removeDecoration()// /* (non-Javadoc) * @see com.foundation.view.ISingleResourceAssociationChangeListener#removeMessageHold() */ public void removeMessageHold() { }//removeMessageHold()// /* (non-Javadoc) * @see com.foundation.view.IMultiResourceAssociationChangeListener#removeDecoration(com.foundation.view.ResourceAssociation, java.lang.Object, java.lang.Object, com.foundation.view.AbstractDecoration) */ public void removeDecoration(ResourceAssociation association, Object row, Object data, AbstractDecoration decoration) { }//removeDecoration()// }//Layout//