001: package fr.aliacom.form.swt.ui;
002:
003: import org.eclipse.swt.widgets.Composite;
004: import org.eclipse.swt.widgets.Control;
005: import org.w3c.dom.Element;
006:
007: import fr.aliacom.common.ui.ICard;
008: import fr.aliacom.form.common.FormLoader;
009: import fr.aliacom.form.common.IFormComponent;
010: import fr.aliacom.form.swt.BuilderFactory;
011: import fr.aliacom.form.swt.SWTBuilder;
012:
013: /**
014: * This class is used to provide card panel lazy loading. This greatly improves
015: * startup time of wizards with a lot of cards.
016: *
017: * @author tom
018: *
019: * (C) 2001, 2003 Thomas Cataldo
020: */
021: public final class SWTCard extends SWTBuilder implements ICard {
022:
023: private Element toParse;
024: private IFormComponent parent;
025: private FormLoader loader;
026: private BuilderFactory factory;
027: private IFormComponent ctrl;
028: private boolean loaded;
029: private String title;
030:
031: public SWTCard(Element toParse, IFormComponent parent,
032: FormLoader loader, BuilderFactory factory) {
033: this .toParse = toParse;
034: this .parent = parent;
035: this .loader = new FormLoader(loader.getCtx());
036: this .loader.setForm(loader.getForm());
037: this .factory = factory;
038: loaded = false;
039: }
040:
041: /**
042: * @see fr.aliacom.common.ui.ICard#isLoaded()
043: */
044: public boolean isLoaded() {
045: return loaded;
046: }
047:
048: /**
049: * @see fr.aliacom.common.ui.ICard#load()
050: */
051: public void load() {
052: buildChildren(toParse, parent, loader, factory);
053: loader.load();
054: Control[] children = ((Composite) parent.getNativeWidget())
055: .getChildren();
056: ctrl = new SWTControl(children[children.length - 1]);
057: // elect the element for garbage collection
058: toParse = null;
059: parent = null;
060: loader = null;
061: factory = null;
062: loaded = true;
063: }
064:
065: /**
066: * @see fr.aliacom.form.common.IFormComponent#reset()
067: */
068: public void reset() {
069: }
070:
071: /**
072: * @see fr.aliacom.form.common.IFormComponent#setValueBean(java.lang.Object)
073: */
074: public void setValueBean(Object bean) {
075: }
076:
077: /**
078: * @see fr.aliacom.form.common.IFormComponent#getNativeWidget()
079: */
080: public Object getNativeWidget() {
081: return null;
082: }
083:
084: /**
085: * @see fr.aliacom.form.swt.SWTBuilder#build(org.w3c.dom.Element, fr.aliacom.form.common.IFormComponent, fr.aliacom.form.common.FormLoader, fr.aliacom.form.swt.BuilderFactory)
086: */
087: public IFormComponent build(Element elem, IFormComponent parent,
088: FormLoader loader, BuilderFactory factory) {
089: throw new RuntimeException("SWTCard is not a real builder");
090: }
091:
092: /**
093: * @see fr.aliacom.common.ui.ICard#getComponent()
094: */
095: public IFormComponent getComponent() {
096: return ctrl;
097: }
098:
099: public void setTitle(String title) {
100: this .title = title;
101: }
102:
103: /**
104: * @see fr.aliacom.common.ui.ICard#getTitle()
105: */
106: public String getTitle() {
107: return title;
108: }
109:
110: }
|