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

296 lines
14 KiB
Java
Raw Normal View History

2014-05-30 10:31:51 -07:00
/*
* Copyright (c) 2006,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.JefImage;
import com.foundation.view.resource.ResourceReference;
import com.foundation.view.builder.*;
import com.foundation.view.definition.*;
public class ToolItemBuilder extends AbstractBuilder {
protected static final String STYLE_FLAT = "flat";
protected static final String STYLE_PUSH = "push";
//These styles are only for toggle type buttons.//
protected static final String STYLE_CHECK = "check";
protected static final String STYLE_RADIO = "radio";
//The separator style which is also used for custom controls.//
protected static final String STYLE_SEPARATOR = "separator";
//The drop down style which is currently only used in conjunction with a popup (floating) menu.//
protected static final String STYLE_DROP_DOWN = "drop down";
//The width property can only be used with a separator or custom control.//
protected static final String PROPERTY_WIDTH = "width";
//The text and image are used with any non-separator.//
protected static final String PROPERTY_TEXT = "text";
protected static final String PROPERTY_IMAGE = "image";
protected static final String PROPERTY_ROLLOVER_IMAGE = "rollover-image";
protected static final String PROPERTY_DISABLED_IMAGE = "disabled-image";
protected static final String PROPERTY_TOOL_TIP_TEXT = "tool-tip-text";
protected static final String PROPERTY_IS_ENABLED = "is-enabled";
//The selection state properties are used with the check or radio styles.//
protected static final String PROPERTY_IS_SELECTED = "is-selected";
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 ASSOCIATION_TEXT = "text";
protected static final String ASSOCIATION_IMAGE = "image";
protected static final String ASSOCIATION_ROLLOVER_IMAGE = "rollover-image";
protected static final String ASSOCIATION_DISABLED_IMAGE = "disabled-image";
protected static final String ASSOCIATION_TOOL_TIP_TEXT = "tool-tip-text";
protected static final String ASSOCIATION_SELECTION = "selection";
protected static final String ASSOCIATION_IS_ENABLED = "is-enabled";
protected static final String METHOD_SELECTION = "selection";
protected static final String LINK_SELECTION = "selection";
protected static final String COMPONENT_MENU_FLOATING = "menu-floating";
private static final String LINK_TARGET_SELECTION = "selection";
private static final String LINK_TARGET_TEXT = "text";
private static final String LINK_TARGET_IMAGE = "image";
private static final String LINK_TARGET_DISABLED_IMAGE = "disabled-image";
private static final String LINK_TARGET_ROLLOVER_IMAGE = "rollover-image";
private static final String LINK_TARGET_TOOL_TIP_TEXT = "tool-tip-text";
private static final String LINK_TARGET_IS_ENABLED = "is-enabled";
protected static final IHashMap styleMap = new LiteHashMap(AbstractBuilder.styleMap);
protected static final IHashMap linkMap = new LiteHashMap(AbstractBuilder.linkMap);
static {
styleMap.put(STYLE_FLAT, "STYLE_FLAT");
//These styles are only for push type buttons.//
styleMap.put(STYLE_PUSH, "STYLE_PUSH");
//These styles are only for toggle type buttons.//
styleMap.put(STYLE_CHECK, "STYLE_CHECK");
styleMap.put(STYLE_RADIO, "STYLE_RADIO");
//The separator can be used for custon controls, and the drop down is used with a popup menu.//
styleMap.put(STYLE_SEPARATOR, "STYLE_SEPARATOR");
styleMap.put(STYLE_DROP_DOWN, "STYLE_DROP_DOWN");
linkMap.put(LINK_TARGET_SELECTION, "LINK_TARGET_SELECTION");
linkMap.put(LINK_TARGET_TEXT, "LINK_TARGET_TEXT");
linkMap.put(LINK_TARGET_IMAGE, "LINK_TARGET_IMAGE");
linkMap.put(LINK_TARGET_DISABLED_IMAGE, "LINK_TARGET_DISABLED_IMAGE");
linkMap.put(LINK_TARGET_ROLLOVER_IMAGE, "LINK_TARGET_ROLLOVER_IMAGE");
linkMap.put(LINK_TARGET_TOOL_TIP_TEXT, "LINK_TARGET_TOOL_TIP_TEXT");
linkMap.put(LINK_TARGET_IS_ENABLED, "LINK_TARGET_IS_ENABLED");
}//static//
/**
* CoolItemBuilder constructor.
*/
public ToolItemBuilder() {
super();
}//CoolItemBuilder()//
/* (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);
buffer.append("\t" + variableName + " = new " + getComponentClassName().replace('$', '.') + "(");
appendComponentConstructorParameters(viewBuilder, buffer, data, "parent");
buffer.append(");\r\n");
buffer.append("\t\r\n");
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) {
ISet styles = data.getStyles();
IList components = data.getComponents();
Integer width = (Integer) data.getPropertyValue(PROPERTY_WIDTH);
Object text = (Object) data.getPropertyValue(PROPERTY_TEXT);
Object toolTipText = (Object) data.getPropertyValue(PROPERTY_TOOL_TIP_TEXT);
Object image = (Object) data.getPropertyValue(PROPERTY_IMAGE);
Object rolloverImage = (Object) data.getPropertyValue(PROPERTY_ROLLOVER_IMAGE);
Object disabledImage = (Object) data.getPropertyValue(PROPERTY_DISABLED_IMAGE);
Boolean isSelected = (Boolean) data.getPropertyValue(PROPERTY_IS_SELECTED);
Object isEnabled = (Object) data.getPropertyValue(PROPERTY_IS_ENABLED);
Boolean autoSynchronizeSelection = (Boolean) data.getPropertyValue(PROPERTY_AUTO_SYNCHRONIZE_SELECTION);
Long autoSynchronizeSelectionDelay = (Long) data.getPropertyValue(PROPERTY_AUTO_SYNCHRONIZE_SELECTION_DELAY);
IMethodPart selectionMethod = data.getMethod(METHOD_SELECTION);
boolean isPush = styles.containsValue(STYLE_PUSH);
boolean isToggle = styles.containsValue(STYLE_CHECK) || styles.containsValue(STYLE_RADIO);
boolean isSeparator = styles.containsValue(STYLE_SEPARATOR);
boolean isDropMenu = styles.containsValue(STYLE_DROP_DOWN);
IComponentData floatingMenu = data.getComponent(COMPONENT_MENU_FLOATING, true);
if((isSeparator) && (components.getSize() == 1)) {
IComponentData component = (IComponentData) components.getFirst();
if(component != null) {
String initializeMethodName = viewBuilder.addInitializeComponentMethod(component);
//Initialize the control.//
buffer.append('\t');
buffer.append(initializeMethodName);
buffer.append('(');
buffer.append(viewBuilder.getComponentAttributeName(data.getParent()));
buffer.append(");\r\n");
//Pass the control to the item.//
buffer.append('\t');
buffer.append(variableName);
buffer.append(".setControl(");
buffer.append(viewBuilder.getComponentAttributeName(component));
buffer.append(");\r\n");
}//if//
}//if//
if(width != null) {
buffer.append("\t" + variableName + ".setWidth(" + width + ");\r\n");
}//if//
if(!isSeparator) {
if((isDropMenu) && (floatingMenu != null)) {
String initializeMethodName;
//Create the initialize menu method but use the tool item's tool bar as the menu parent since only components can have menus as children.//
floatingMenu.setParent(data.getParent());
initializeMethodName = viewBuilder.addInitializeMenuMethod(data, floatingMenu, "DropDownMenu");
floatingMenu.setParent(data);
buffer.append('\t');
buffer.append(initializeMethodName);
buffer.append('(');
buffer.append(viewBuilder.getComponentAttributeName(data.getParent()));
buffer.append(");\r\n");
buffer.append('\t');
buffer.append(variableName);
buffer.append(".setMenu(");
buffer.append(viewBuilder.getComponentAttributeName(floatingMenu));
buffer.append(");\r\n");
}//if//
if(text != null) {
if(text instanceof ResourceReference) {
buffer.append("\t" + variableName + ".setText(new " + ResourceReference.class.getName() + "(\"" + ((ResourceReference) text).getResourceUrl() + "\"));\r\n");
}//if//
else {
buffer.append("\t" + variableName + ".setText(\"" + text + "\");\r\n");
}//else//
}//if//
if(toolTipText != null) {
if(toolTipText instanceof ResourceReference) {
buffer.append("\t" + variableName + ".setToolTipText(new " + ResourceReference.class.getName() + "(\"" + ((ResourceReference) toolTipText).getResourceUrl() + "\"));\r\n");
}//if//
else {
buffer.append("\t" + variableName + ".setToolTipText(\"" + toolTipText + "\");\r\n");
}//else//
}//if//
if(image != null) {
if(image instanceof ResourceReference) {
buffer.append("\t" + variableName + ".setImage(new " + ResourceReference.class.getName() + "(\"" + ((ResourceReference) image).getResourceUrl() + "\"));\r\n");
}//if//
else {
buffer.append("\t" + variableName + ".setImage(new " + JefImage.class.getName() + "(\"" + image + "\"));\r\n");
}//else//
}//if//
if(rolloverImage != null) {
if(rolloverImage instanceof ResourceReference) {
buffer.append("\t" + variableName + ".setHotImage(new " + ResourceReference.class.getName() + "(\"" + ((ResourceReference) rolloverImage).getResourceUrl() + "\"));\r\n");
}//if//
else {
buffer.append("\t" + variableName + ".setHotImage(new " + JefImage.class.getName() + "(\"" + rolloverImage + "\"));\r\n");
}//else//
}//if//
if(disabledImage != null) {
if(disabledImage instanceof ResourceReference) {
buffer.append("\t" + variableName + ".setDisabledImage(new " + ResourceReference.class.getName() + "(\"" + ((ResourceReference) disabledImage).getResourceUrl() + "\"));\r\n");
}//if//
else {
buffer.append("\t" + variableName + ".setDisabledImage(new " + JefImage.class.getName() + "(\"" + disabledImage + "\"));\r\n");
}//else//
}//if//
if(isEnabled != null) {
if(isEnabled instanceof ResourceReference) {
buffer.append("\t" + variableName + ".setIsEnabled(new " + ResourceReference.class.getName() + "(\"" + ((ResourceReference) isEnabled).getResourceUrl() + "\"));\r\n");
}//if//
else {
buffer.append("\t" + variableName + ".setIsEnabled(" + ((Boolean) isEnabled).booleanValue() + ");\r\n");
}//else//
}//if//
if(isToggle && (isSelected != null)) {
buffer.append("\t" + variableName + ".setIsSelected(" + (((Boolean) isSelected).booleanValue() ? "Boolean.TRUE" : "Boolean.FALSE") + ");\r\n");
}//if//
appendAssociation(viewBuilder, buffer, data, ASSOCIATION_TEXT, variableName, "setTextAssociation", "ASSOCIATION_TEXT", 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);
appendAssociation(viewBuilder, buffer, data, ASSOCIATION_ROLLOVER_IMAGE, variableName, "setHotImageAssociation", "ASSOCIATION_ROLLOVER_IMAGE", IViewSourceBuilder.ACCESS_TYPE_GET_ONLY);
appendAssociation(viewBuilder, buffer, data, ASSOCIATION_DISABLED_IMAGE, variableName, "setDisabledTextAssociation", "ASSOCIATION_DISABLED_IMAGE", IViewSourceBuilder.ACCESS_TYPE_GET_ONLY);
appendAssociation(viewBuilder, buffer, data, ASSOCIATION_IS_ENABLED, variableName, "setIsEnabledAssociation", "ASSOCIATION_IS_ENABLED", IViewSourceBuilder.ACCESS_TYPE_GET_ONLY);
if(isToggle && autoSynchronizeSelection != null) {
buffer.append("\t" + variableName + ".setAutoSynchronizeSelection(" + autoSynchronizeSelection + ");\r\n");
}//if//
if(isToggle && autoSynchronizeSelectionDelay != null) {
buffer.append("\t" + variableName + ".setAutoSynchronizeSelectionDelay(" + autoSynchronizeSelectionDelay + "l);\r\n");
}//if//
if(isToggle) {
appendAssociation(viewBuilder, buffer, data, ASSOCIATION_SELECTION, variableName, "setSelectionAssociation", "ASSOCIATION_SELECTION", IViewSourceBuilder.ACCESS_TYPE_BOTH);
}//if//
if((isPush) && (selectionMethod != null)) {
String associationIdentifier = viewBuilder.addMethodAssociationIdentifier(data.getDocumentElement(), variableName, METHOD_SELECTION);
viewBuilder.addDirectMethodHandler(data, associationIdentifier, selectionMethod);
buffer.append("\t");
buffer.append(variableName);
buffer.append(".setSelectionMethod(");
viewBuilder.appendMethodAssociation(buffer, variableName, selectionMethod, associationIdentifier);
buffer.append(");\r\n");
}//if//
}//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) {
IList selectionLinks = data.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(variableName);
buffer.append(".addSelectionLink(");
viewBuilder.appendLink(data, buffer, part);
buffer.append(");\r\n");
}//for//
}//if//
}//appendLinks()//
/* (non-Javadoc)
* @see com.foundation.view.builder.IBuilder#getComponentClassName()
*/
public String getComponentClassName() {
return "com.foundation.view.swt.ToolBar.ToolItem";
}//getComponentClassName()//
/* (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()//
}//TabPanelBuilder//