Files
Brainstorm/Foundation SWT View Builder/src/com/foundation/view/swt/builder/CollectionComponentBuilder.java
2014-05-30 10:31:51 -07:00

210 lines
11 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.view.swt.builder;
import com.common.util.*;
import com.foundation.view.JefColor;
import com.foundation.view.JefFont;
import com.foundation.view.definition.*;
import com.foundation.view.builder.*;
public abstract class CollectionComponentBuilder extends ScrollableComponentBuilder {
protected static final int HIDDEN_DATA_TYPE_CODE_BOOLEAN = 0;
protected static final int HIDDEN_DATA_TYPE_CODE_INTEGER = 1;
protected static final int HIDDEN_DATA_TYPE_CODE_STRING = 2;
protected static final int HIDDEN_DATA_TYPE_CODE_COLOR = 3;
protected static final int HIDDEN_DATA_TYPE_CODE_FONT = 4;
protected static final String PROPERTY_AUTO_SYNCHRONIZE_SELECTION = "auto-synchronize-selection";
protected static final String PROPERTY_AUTO_SYNCHRONIZE_SELECTION_DELAY = "auto-synchronize-selection-delay";
protected static final String PROPERTY_AUTO_VALIDATE = "auto-validate";
protected static final String PROPERTY_DATA = "data";
protected static final String ASSOCIATION_COLLECTION = "collection";
protected static final String ASSOCIATION_SELECTION = "selection";
protected static final String ASSOCIATION_DATA = "data";
protected static final String METHOD_DOUBLE_CLICK = "double-click";
protected static final String COMPONENT_HIDDEN_DATA = "hidden-data";
protected static final String LINK_SELECTION = "selection";
protected static final IHashMap styleMap = new LiteHashMap(ScrollableComponentBuilder.styleMap);
protected static final IHashMap linkMap = new LiteHashMap(ScrollableComponentBuilder.linkMap);
private int hiddenDataAssociationIndex = 0;
/**
* CollectionComponentBuilder constructor.
*/
public CollectionComponentBuilder() {
super();
}//CollectionComponentBuilder()//
/**
* Determines whether the control allows the user to select more than one value.
* @param The component data representing the control.
* @return Whether the user may make more than one selection for the control.
*/
public abstract boolean allowMultiSelection(IComponentData data);
/* (non-Javadoc)
* @see com.foundation.view.builder.IBuilder#appendInitializationBody(com.foundation.view.builder.IViewSourceBuilder, java.lang.StringBuffer, com.foundation.view.definition.ComponentData, java.lang.String)
*/
public void appendInitializationBody(IViewSourceBuilder viewBuilder, StringBuffer buffer, IComponentData data, String variableName) {
Boolean autoSynchronizeSelection = (Boolean) data.getPropertyValue(PROPERTY_AUTO_SYNCHRONIZE_SELECTION);
Long autoSynchronizeSelectionDelay = (Long) data.getPropertyValue(PROPERTY_AUTO_SYNCHRONIZE_SELECTION_DELAY);
Boolean autoValidate = (Boolean) data.getPropertyValue(PROPERTY_AUTO_VALIDATE);
IMethodPart doubleClickMethod = data.getMethod(METHOD_DOUBLE_CLICK);
IList hiddenData = new LiteList(10, 20);
data.getComponents(hiddenData, COMPONENT_HIDDEN_DATA, true);
if(autoSynchronizeSelection != null) {
buffer.append("\t" + variableName + ".setAutoSynchronizeSelection(" + autoSynchronizeSelection + ");\r\n");
}//if//
if(autoSynchronizeSelectionDelay != null) {
buffer.append("\t" + variableName + ".setAutoSynchronizeSelectionDelay(" + autoSynchronizeSelectionDelay + "l);\r\n");
}//if//
if(autoValidate != null) {
buffer.append("\t" + variableName + ".setAutoValidate(" + autoValidate + ");\r\n");
}//if//
appendAssociation(viewBuilder, buffer, data, ASSOCIATION_COLLECTION, variableName, "setCollectionAssociation", "ASSOCIATION_COLLECTION", IViewSourceBuilder.ACCESS_TYPE_GET_ONLY);
appendAssociation(viewBuilder, buffer, data, ASSOCIATION_SELECTION, variableName, "setSelectionAssociation", "ASSOCIATION_SELECTION", allowMultiSelection(data) ? IViewSourceBuilder.ACCESS_TYPE_GET_ONLY : IViewSourceBuilder.ACCESS_TYPE_BOTH);
if((doubleClickMethod != null) && (doubleClickMethod.getName() != null)) {
String associationIdentifier = viewBuilder.addMethodAssociationIdentifier(data.getDocumentElement(), variableName, METHOD_DOUBLE_CLICK);
viewBuilder.addDirectMethodHandler(data, associationIdentifier, doubleClickMethod);
buffer.append("\t");
buffer.append(variableName);
buffer.append(".setDoubleClickMethod(");
viewBuilder.appendMethodAssociation(buffer, variableName, doubleClickMethod, associationIdentifier);
buffer.append(");\r\n");
}//if//
//Add the data for all the columns.//
for(int hiddenDataIndex = 0; hiddenDataIndex < hiddenData.getSize(); hiddenDataIndex++) {
appendHiddenDataBody(viewBuilder, buffer, (IComponentData) hiddenData.get(hiddenDataIndex), variableName, hiddenDataIndex);
}//for//
super.appendInitializationBody(viewBuilder, buffer, data, variableName);
}//appendInitializationBody()//
/**
* Appends the hidden data 'column' code for one hidden data part.
* @param buffer The buffer to write the java source to.
* @param component The hidden data's component which contains all the info necessary to build the source for the hidden data.
* @param variableName The hidden data's assigned variable name. This is a local variable and not an object level attribute.
* @param hiddenDataIndex The index of the hidden data component within this collection component.
*/
protected void appendHiddenDataBody(IViewSourceBuilder viewBuilder, StringBuffer buffer, IComponentData component, String variableName, int hiddenDataIndex) {
String componentTypeName = component.getComponentType().getName();
Object dataProperty = component.getPropertyValue(PROPERTY_DATA);
if(componentTypeName.equals("hidden-boolean")) {
appendHiddenDataBody(viewBuilder, buffer, component, variableName, "Boolean", dataProperty != null ? ((Boolean) dataProperty).booleanValue() ? "Boolean.TRUE" : "Boolean.FALSE" : null, hiddenDataIndex);
}//if//
else if(componentTypeName.equals("hidden-integer")) {
appendHiddenDataBody(viewBuilder, buffer, component, variableName, "Integer", dataProperty != null ? ((Integer) dataProperty).toString() : null, hiddenDataIndex);
}//else if//
else if(componentTypeName.equals("hidden-string")) {
appendHiddenDataBody(viewBuilder, buffer, component, variableName, "String", dataProperty != null ? "\"" + ((String) dataProperty) + "\"" : null, hiddenDataIndex);
}//else if//
else if(componentTypeName.equals("hidden-color")) {
appendHiddenDataBody(viewBuilder, buffer, component, variableName, "Color", dataProperty != null ? "new " + JefColor.class.getName() + "(\"" + dataProperty.toString() + "\")" : null, hiddenDataIndex);
}//else if//
else if(componentTypeName.equals("hidden-font")) {
appendHiddenDataBody(viewBuilder, buffer, component, variableName, "Font", dataProperty != null ? "new " + JefFont.class.getName() + "(\"" + JefFont.getJefFontsString((JefFont[]) dataProperty) + "\")" : null, hiddenDataIndex);
}//else if//
}//appendHiddenDataBody()//
/**
* Appends the hidden data 'column' code for one hidden data part.
* @param buffer The buffer to write the java source to.
* @param component The hidden data's component which contains all the info necessary to build the source for the hidden data.
* @param variableName The hidden data's assigned variable name. This is a local variable and not an object level attribute.
* @param typeName The name of the hidden data's data type as used by the addHiddenXXX() method defined by the collection component and the IHiddenXXX interface that the method returns.
* @param defaultValueCode The code whose result is passed to the setData(..) method, or null if no data property was specified.
* @param hiddenDataIndex The index of the hidden data component within this collection component.
*/
protected void appendHiddenDataBody(IViewSourceBuilder viewBuilder, StringBuffer buffer, IComponentData component, String variableName, String typeName, String defaultValueCode, int hiddenDataIndex) {
String hiddenDataVariableName = variableName + "HiddenDataPart" + hiddenDataIndex;
IAssociationGroupPart dataAssociations = component.getAssociations(ASSOCIATION_DATA);
viewBuilder.addAttribute(getComponentClassName() + ".IHidden" + typeName, hiddenDataVariableName);
buffer.append("\t");
//buffer.append(getComponentClassName() + ".IHidden" + typeName);
//buffer.append(" ");
buffer.append(hiddenDataVariableName);
buffer.append(" = ");
buffer.append(variableName);
buffer.append(".addHidden" + typeName + "();\r\n");
if(defaultValueCode != null) {
buffer.append("\t" + hiddenDataVariableName + ".setData(" + defaultValueCode + ");\r\n");
}//if//
if(dataAssociations != null) {
buffer.append("\t");
buffer.append(hiddenDataVariableName);
buffer.append(".setDataAssociation(");
viewBuilder.appendAssociation(component, buffer, variableName, dataAssociations, "ASSOCIATION_DATA_" + hiddenDataAssociationIndex++, IViewSourceBuilder.ACCESS_TYPE_GET_ONLY);
buffer.append(");\r\n");
}//if//
}//appendHiddenDataBody()//
/* (non-Javadoc)
* @see com.foundation.view.builder.IBuilder#appendLinks(com.foundation.view.builder.IViewSourceBuilder, java.lang.StringBuffer, com.foundation.view.definition.ComponentData, java.lang.String)
*/
public void appendLinks(IViewSourceBuilder viewBuilder, StringBuffer buffer, IComponentData data, String variableName) {
IList selectionLinks = data.getLinks(LINK_SELECTION);
IList hiddenData = new LiteList(10, 20);
data.getComponents(hiddenData, COMPONENT_HIDDEN_DATA, true);
if(selectionLinks != null) {
for(int index = 0; index < selectionLinks.getSize(); index++) {
ILinkPart part = (ILinkPart) selectionLinks.get(index);
buffer.append("\t");
buffer.append(variableName);
buffer.append(".addSelectionLink(");
viewBuilder.appendLink(data, buffer, part);
buffer.append(");\r\n");
}//for//
}//if//
//Add the data for all the columns.//
for(int hiddenDataIndex = 0; hiddenDataIndex < hiddenData.getSize(); hiddenDataIndex++) {
IComponentData component = (IComponentData) hiddenData.get(hiddenDataIndex);
String hiddenDataVariableName = variableName + "HiddenDataPart" + hiddenDataIndex;
selectionLinks = component.getLinks(LINK_SELECTION);
if(selectionLinks != null) {
for(int index = 0; index < selectionLinks.getSize(); index++) {
ILinkPart part = (ILinkPart) selectionLinks.get(index);
buffer.append("\t");
buffer.append(hiddenDataVariableName);
buffer.append(".addSelectionLink(");
viewBuilder.appendLink(component, buffer, part);
buffer.append(");\r\n");
}//for//
}//if//
}//for//
}//appendLinks()//
/* (non-Javadoc)
* @see com.foundation.view.swt.builder.AbstractBuilder#getStyleMap()
*/
public IHashMap getStyleMap() {
return styleMap;
}//getStyleMap()//
/* (non-Javadoc)
* @see com.foundation.view.swt.builder.AbstractBuilder#getLinkMap()
*/
public IHashMap getLinkMap() {
return linkMap;
}//getLinkMap()//
}//CollectionComponentBuilder//