/* * 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.builder.*; import com.foundation.view.definition.*; import com.foundation.view.resource.ResourceReference; public class FrameBuilder extends ContainerBuilder { protected static final String STYLE_MINIMIZE = "minimize"; protected static final String STYLE_MAXIMIZE = "maximize"; protected static final String STYLE_CLOSE = "close"; protected static final String STYLE_RESIZE = "resize"; protected static final String STYLE_TITLE = "title"; protected static final String STYLE_NO_TRIM = "no trim"; protected static final String STYLE_ON_TOP = "on top"; protected static final String STYLE_TOOL = "tool"; protected static final String STYLE_WINDOW_TRIM = "window trim"; protected static final String STYLE_DIALOG_TRIM = "dialog trim"; protected static final String METHOD_CLOSED = "closed"; protected static final String METHOD_ACTIVATED = "activated"; protected static final String METHOD_DEACTIVATED = "deactivated"; protected static final String METHOD_ICONIFIED = "iconified"; protected static final String METHOD_DEICONIFIED = "deiconified"; protected static final String COMPONENT_MENU_BAR = "menu-bar"; protected static final String PROPERTY_CONTAINER_IMAGES = "container-images"; protected static final String ASSOCIATION_CONTAINER_IMAGES = "container-images"; protected static final IHashMap styleMap = new LiteHashMap(ContainerBuilder.styleMap); protected static final IHashMap linkMap = new LiteHashMap(ContainerBuilder.linkMap); static { styleMap.put(STYLE_CLOSE, "STYLE_CLOSE"); styleMap.put(STYLE_MINIMIZE, "STYLE_MIN"); styleMap.put(STYLE_MAXIMIZE, "STYLE_MAX"); styleMap.put(STYLE_RESIZE, "STYLE_RESIZE"); styleMap.put(STYLE_TITLE, "STYLE_TITLE"); styleMap.put(STYLE_NO_TRIM, "STYLE_NO_TRIM"); styleMap.put(STYLE_WINDOW_TRIM, "STYLE_SHELL_TRIM"); styleMap.put(STYLE_DIALOG_TRIM, "STYLE_DIALOG_TRIM"); styleMap.put(STYLE_ON_TOP, "STYLE_ON_TOP"); styleMap.put(STYLE_TOOL, "STYLE_TOOL"); }//static// /** * FrameBuilder constructor. */ public FrameBuilder() { }//FrameBuilder()// /* (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) { IMethodPart closedMethod = data.getMethod(METHOD_CLOSED); IMethodPart activatedMethod = data.getMethod(METHOD_ACTIVATED); IMethodPart deactivatedMethod = data.getMethod(METHOD_DEACTIVATED); IMethodPart iconifiedMethod = data.getMethod(METHOD_ICONIFIED); IMethodPart deiconifiedMethod = data.getMethod(METHOD_DEICONIFIED); Object images = (Object) data.getPropertyValue(PROPERTY_CONTAINER_IMAGES); IComponentData menuBarComponent = (IComponentData) data.getComponent(COMPONENT_MENU_BAR, true); if(menuBarComponent != null) { String initializeMethodName = viewBuilder.addInitializeMenuMethod(data, menuBarComponent, "MenuBar"); buffer.append('\t'); buffer.append(initializeMethodName); buffer.append('('); buffer.append(variableName); buffer.append(");\r\n"); }//if// appendAssociation(viewBuilder, buffer, data, ASSOCIATION_CONTAINER_IMAGES, variableName, "setContainerImagesAssociation", "ASSOCIATION_CONTAINER_IMAGES", IViewSourceBuilder.ACCESS_TYPE_GET_ONLY); if(images != null) { if(images instanceof ResourceReference) { buffer.append("\t" + variableName + ".setDefaultContainerImages(new " + ResourceReference.class.getName() + "(\"" + ((ResourceReference) images).getResourceUrl() + "\"));\r\n"); }//if// else { String[] imagePaths = images.toString().split(";"); boolean isFirst = true; buffer.append("\t" + variableName + ".setDefaultContainerImages(new " + JefImage.class.getName() + "[] {"); for(int index = 0; index < imagePaths.length; index++) { String path = imagePaths[index] != null ? imagePaths[index].trim() : null; if(path != null && path.length() > 0) { if(!isFirst) { buffer.append(", "); }//if// else { isFirst = false; }//else// buffer.append("new " + JefImage.class.getName() + "(\""); buffer.append(path); buffer.append("\")"); }//if// }//for// buffer.append(");\r\n"); }//else// }//if// if(closedMethod != null) { String associationIdentifier = viewBuilder.addMethodAssociationIdentifier(data.getDocumentElement(), variableName, METHOD_CLOSED); viewBuilder.addDirectMethodHandler(data, associationIdentifier, closedMethod); buffer.append("\t" + variableName + ".setClosedMethod("); viewBuilder.appendMethodAssociation(buffer, variableName, closedMethod, associationIdentifier); buffer.append(");\r\n"); }//if// if(activatedMethod != null) { String associationIdentifier = viewBuilder.addMethodAssociationIdentifier(data.getDocumentElement(), variableName, METHOD_ACTIVATED); viewBuilder.addDirectMethodHandler(data, associationIdentifier, activatedMethod); buffer.append("\t" + variableName + ".setActivatedMethod("); viewBuilder.appendMethodAssociation(buffer, variableName, activatedMethod, associationIdentifier); buffer.append(");\r\n"); }//if// if(deactivatedMethod != null) { String associationIdentifier = viewBuilder.addMethodAssociationIdentifier(data.getDocumentElement(), variableName, METHOD_DEACTIVATED); viewBuilder.addDirectMethodHandler(data, associationIdentifier, deactivatedMethod); buffer.append("\t" + variableName + ".setDeactivatedMethod("); viewBuilder.appendMethodAssociation(buffer, variableName, deactivatedMethod, associationIdentifier); buffer.append(");\r\n"); }//if// if(iconifiedMethod != null) { String associationIdentifier = viewBuilder.addMethodAssociationIdentifier(data.getDocumentElement(), variableName, METHOD_ICONIFIED); viewBuilder.addDirectMethodHandler(data, associationIdentifier, iconifiedMethod); buffer.append("\t" + variableName + ".setIconifiedMethod("); viewBuilder.appendMethodAssociation(buffer, variableName, iconifiedMethod, associationIdentifier); buffer.append(");\r\n"); }//if// if(deiconifiedMethod != null) { String associationIdentifier = viewBuilder.addMethodAssociationIdentifier(data.getDocumentElement(), variableName, METHOD_DEICONIFIED); viewBuilder.addDirectMethodHandler(data, associationIdentifier, deiconifiedMethod); buffer.append("\t" + variableName + ".setDeiconifiedMethod("); viewBuilder.appendMethodAssociation(buffer, variableName, deiconifiedMethod, associationIdentifier); buffer.append(");\r\n"); }//if// //Make sure any buttons will be initialzed prior to setting any of them as the default.// super.appendInitializationBody(viewBuilder, buffer, data, variableName); }//appendInitializationBody()// /* (non-Javadoc) * @see com.foundation.view.builder.IBuilder#getComponentClassName() */ public String getComponentClassName() { return "com.foundation.view.swt.Frame"; }//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, "(" + getContainerClassName() + ") controller.getParentComponent()", 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()// }//FrameBuilder//