Files
Brainstorm/Foundation SWT View Builder/src/com/foundation/view/swt/builder/TrayItemBuilder.java

181 lines
8.3 KiB
Java
Raw Normal View History

2014-05-30 10:31:51 -07:00
/*
* 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.controller.*;
import com.foundation.view.JefImage;
import com.foundation.view.resource.ResourceReference;
import com.foundation.view.builder.*;
import com.foundation.view.definition.*;
public class TrayItemBuilder extends AbstractBuilder {
protected static final String PROPERTY_IS_VISIBLE = "is-visible";
protected static final String PROPERTY_TOOL_TIP_TEXT = "tool-tip-text";
protected static final String PROPERTY_IMAGE = "image";
protected static final String ASSOCIATION_IS_VISIBLE = "is-visible";
protected static final String ASSOCIATION_TOOL_TIP_TEXT = "tool-tip-text";
protected static final String ASSOCIATION_IMAGE = "image";
private static final String LINK_TARGET_IS_VISIBLE = "is-visible";
private static final String LINK_TARGET_TOOL_TIP_TEXT = "tool-tip-text";
protected static final String COMPONENT_MENU_FLOATING = "menu-floating";
protected static final String COMPONENT_VALUE_HOLDER = "value-holder";
protected static final IHashMap styleMap = new LiteHashMap(ContainerBuilder.styleMap);
protected static final IHashMap linkMap = new LiteHashMap(ContainerBuilder.linkMap);
static {
linkMap.put(LINK_TARGET_IS_VISIBLE, "LINK_TARGET_IS_VISIBLE");
linkMap.put(LINK_TARGET_TOOL_TIP_TEXT, "LINK_TARGET_TOOL_TIP_TEXT");
}//static//
/**
* TrayItemBuilder constructor.
*/
public TrayItemBuilder() {
}//TrayItemBuilder()//
/* (non-Javadoc)
* @see com.foundation.view.builder.IBuilder#appendInitializationHead(com.foundation.view.builder.IViewSourceBuilder, StringBuffer, ComponentData)
*/
public void appendInitializationHead(IViewSourceBuilder viewBuilder, StringBuffer buffer, IComponentData data) {
String variableName = viewBuilder.getComponentAttributeName(data);
//Write out the constructor here only if this is not the primary component for the view.//
if(!viewBuilder.getPrimaryComponent().equals(data)) {
buffer.append("\t" + variableName + " = new " + getComponentClassName() + "(");
appendComponentConstructorParameters(viewBuilder, buffer, data, "parent");
buffer.append(");\r\n");
buffer.append("\t\r\n");
}//if//
appendInitializationBody(viewBuilder, buffer, data, variableName);
}//appendInitializationHead()//
/* (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) {
Object isVisible = (Object) data.getPropertyValue(PROPERTY_IS_VISIBLE);
Object toolTipText = (Object) data.getPropertyValue(PROPERTY_TOOL_TIP_TEXT);
Object image = (Object) data.getPropertyValue(PROPERTY_IMAGE);
IComponentData floatingMenu = data.getComponent(COMPONENT_MENU_FLOATING, true);
IList valueHolders = new LiteList(10, 20);
IIterator valueHolderIterator = null;
//Search for all value holders.//
data.getComponents(valueHolders, COMPONENT_VALUE_HOLDER, true);
valueHolderIterator = valueHolders.iterator();
//Call the initialize method on the contained value holders.//
while(valueHolderIterator.hasNext()) {
IComponentData next = (IComponentData) valueHolderIterator.next();
String initializeMethodName = viewBuilder.addInitializeComponentMethod(next, "com.foundation.view.IAbstractContainer");
buffer.append('\t');
buffer.append(initializeMethodName);
buffer.append('(');
buffer.append(variableName);
buffer.append(");\r\n");
}//while//
if(isVisible != null) {
if(isVisible instanceof ResourceReference) {
buffer.append("\t" + variableName + ".setDefaultIsVisible(new " + ResourceReference.class.getName() + "(\"" + ((ResourceReference) isVisible).getResourceUrl() + "\"));\r\n");
}//if//
else {
buffer.append("\t" + variableName + ".setDefaultIsVisible(" + ((Boolean) isVisible).booleanValue() + ");\r\n");
}//else//
}//if//
if(toolTipText != null) {
if(toolTipText instanceof ResourceReference) {
buffer.append("\t" + variableName + ".setDefaultToolTipText(new " + ResourceReference.class.getName() + "(\"" + ((ResourceReference) toolTipText).getResourceUrl() + "\"));\r\n");
}//if//
else {
buffer.append("\t" + variableName + ".setDefaultToolTipText(\"" + toolTipText + "\");\r\n");
}//else//
}//if//
appendAssociation(viewBuilder, buffer, data, ASSOCIATION_IS_VISIBLE, variableName, "setIsVisibleAssociation", "ASSOCIATION_IS_VISIBLE", IViewSourceBuilder.ACCESS_TYPE_GET_ONLY);
appendAssociation(viewBuilder, buffer, data, ASSOCIATION_TOOL_TIP_TEXT, variableName, "setToolTipTextAssociation", "ASSOCIATION_TOOL_TIP_TEXT", IViewSourceBuilder.ACCESS_TYPE_GET_ONLY);
appendAssociation(viewBuilder, buffer, data, ASSOCIATION_IMAGE, variableName, "setImageAssociation", "ASSOCIATION_IMAGE", IViewSourceBuilder.ACCESS_TYPE_GET_ONLY);
if(image != null) {
if(image instanceof ResourceReference) {
buffer.append("\t" + variableName + ".setDefaultImage(new " + ResourceReference.class.getName() + "(\"" + ((ResourceReference) image).getResourceUrl() + "\"));\r\n");
}//if//
else {
buffer.append("\t" + variableName + ".setDefaultImage(new " + JefImage.class.getName() + "(\"" + image + "\"));\r\n");
}//else//
}//if//
if(floatingMenu != null) {
String initializeMethodName = viewBuilder.addInitializeMenuMethod(data, floatingMenu, "PopupMenu");
buffer.append('\t');
buffer.append(initializeMethodName);
buffer.append('(');
buffer.append(variableName);
buffer.append(");\r\n");
}//if//
}//appendInitializationBody()//
/* (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) {
}//appendLinks()//
/* (non-Javadoc)
* @see com.foundation.view.builder.IBuilder#getComponentClassName()
*/
public String getComponentClassName() {
return "com.foundation.view.swt.TrayItem";
}//getComponentClassName()//
/**
* Gets the platform specific name of the container class.
* @return The qualified name of the container class.
*/
public String getContainerClassName() {
return "com.foundation.view.swt.Container";
}//getContainerClassName()//
/* (non-Javadoc)
* @see com.foundation.view.builder.IBuilder#buildConstructors(com.foundation.view.builder.IViewSourceBuilder, java.lang.StringBuffer, java.lang.String, com.foundation.view.definition.ComponentData)
*/
public void buildConstructors(IViewSourceBuilder viewBuilder, StringBuffer constructor, String className, IComponentData data) {
String componentName = viewBuilder.addComponentNameIdentifier(data.getDocumentElement(), viewBuilder.getComponentName(data));
constructor.append("/**\r\n");
constructor.append(" * ");
constructor.append(className);
constructor.append(" constructor.\r\n");
constructor.append(" * @param controller The view controller which will be assigned to the value holder(s) that don't depend on another value holder for their value.\r\n");
constructor.append(" */\r\n");
constructor.append("public ");
constructor.append(className);
constructor.append("(");
constructor.append(ViewController.class.getName());
constructor.append(" controller) {\r\n");
constructor.append("\tsuper(");
appendComponentConstructorParameters(viewBuilder, constructor, data, "controller.getContext()", componentName);
constructor.append(");\r\n\r\n");
constructor.append("\tsetController(controller);\r\n");
constructor.append("}//" + className + "()//\r\n");
}//buildConstructors()//
/* (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()//
}//TrayItemBuilder//