View Full Version : Very Urgent: import and defer
Develance
04-18-2007, 01:46 PM
Hi all,
I've been reading the documentation and lots of posts but couldn't find what I need. I'm developing a quite large application using OL, and to avoid large loading times and memory issues I decided to import my libraries using <import> and instead of declaring objects in the canvas, my code does "new MyClass(...)"
I'm not new to OO but I am to OL, and can't understand very well how deferred instantiation works. Here are my questions:
1. Should I do this in canvas:
<import name="editProyecto" href="apps/bid/editProyecto.lzx" stage="defer"/>
or declare the class in my library like this:
<class name="editProyecto" extends="abm" initstage="defer">
Are both "defer" needed?
2. What I'm willing to do is: have multiple <import ...stage="defer"> and in script do:
new MyClass(canvas);
I've read about load() and completeInstantiation(), but I'm not getting anywhere.
I can post my code if needed.
Please, any help will be appreciated, since the project's deadline is before the end of this week :(
Thanks in advance
Develance
Develance
04-19-2007, 06:35 AM
Does anybody ever had to deal with <import> and defer?
It's a very urgent matter. Thx.
Develance
senshi
04-19-2007, 10:43 AM
With stage="defer" on an import-tag, you can load libraries on demand.
initstage="defer" controls the instantiation of the view's subviews, so basically with this attribute you can instantiate classes on demand.
Simple Example:
import_defer_main.lzx
<canvas debug="true" >
<import name="lib" href="import_defer_lib.lzx" stage="defer" />
<handler name="onload" reference="lib" args="loaded" >
Debug.write( "loaded library:", loaded );
</handler>
<simplelayout inset="15" axis="y" spacing="10" />
<button text="Load library" onclick="lib.load()" />
<button text="Create box" onclick="new box(container)" />
<button text="Create boxwrapper" >
<handler name="onclick" >
var a = canvas["list"];
if( !a ){
a = canvas.list = [];
}
a.push( new boxwrapper( container ) );
</handler>
</button>
<button text="Create Inner box" >
<handler name="onclick" >
var a = canvas["list"];
if( a ){
var itm;
while( (itm = a.pop()) ){
itm.completeInstantiation();
}
}
</handler>
</button>
<view id="container" bgcolor="yellow" >
<simplelayout inset="5" axis="x" spacing="10" />
</view>
</canvas>
import_defer_lib.lzx
<library>
<class name="box" extends="view" bgcolor="red" width="50" height="50" />
<class name="boxwrapper" extends="view" initstage="defer" >
<box bgcolor="green" />
</class>
</library>
Develance
04-19-2007, 10:58 AM
Hi senshi,
Your code works as expected, I'm now trying it on my app. I'll let you know the results in a couple of minutes.
Thank you very much for your reply and time.
Develance.
Develance
04-19-2007, 12:36 PM
Senshi,
Although your code works perfectly, I can't get mine to work. This is what I can see in Debug:
# load(): ok.
# new MyClass(): works, but with several warnings like:
WARNING: Redefining tag boxview from lz.boxview to boxview
WARNING: `boxview` is already defined. Use `lz.boxview` instead.
Why is this warning triggering?
# MyClass.open(): ERROR: Compiler.substitute:-1: call to undefined method \'make\'
Here is my code (it's a bit large but I think you'd rather take a look at the whole picture):
main.lzx
<canvas width="763" height="580" debug="true" bgcolor="#f0f0f0">
<!-- Librerias -->
<import name="editProyecto" href="apps/bid/editProyecto.lzx" stage="defer"/>
<import name="selectProyecto" href="apps/bid/selectProyecto.lzx" stage="defer"/>
<include href="util/lztimeout.lzx" />
<include href="apps/bid/gui.lzx" />
<include href="util/dashtab.lzx" />
<include href="resources.lzx"/>
<include href="base/basebutton.lzx" />
<include href="base/basetabslider.lzx" />
<include href="utils/layouts/wrappinglayout.lzx" />
<bluestyle name="defaultstyle" isdefault="true"/>
<splash/>
<resource src="img/progress_box.swf" name="progress"/>
<!-- Mensaje de Inicio -->
<window title="Iniciando" oninit="canvas.initdelay=400" pixellock="true" initstage="early" width="200" x="40%" y="40%">
<text x="${parent.progress.x}" name="message" y="${parent.progress.y - this.height-2}">
Iniciando entorno de aplicaciones...
</text>
<text x="${parent.message.width + 30}" y="${parent.message.y}" width="40">
<method event="onpercentcreated" reference="canvas" args="p">
pp = Math.floor( 100*p );
this.setText( pp + "%" );
</method>
</text>
<view resource="progress" name="progress" align="center" valign="middle" pixellock="true">
<view y="1" x="1" width="${parent.width * canvas.percentcreated - 2}" height="${parent.height-2}" bgcolor="#0A246A" />
</view>
<method event="oninit" reference="canvas">
this.destroy();
</method>
</window>
<!-- Datasets globales -->
<dataset name="dsConfigInterna" request="true" src="./util/config.xml" timeout="90000"/>
<datapointer id="dpConfig" xpath="dsConfigInterna:/" />
<!-- Atributos del canvas -->
<attribute name="vModalActiva" type="string"/>
<attribute name="timeoutDataset" type="number" when="immediately"/>
<attribute name="timeoutSesion" type="number" when="immediately"/>
<loadingAni name="loadingCursor" />
<!-- Mensaje temporal hasta que se termina el desarrollo -->
<alert text="Esta opción estará disponible próximamente." name="alertConstruccion" title="En construcción"/>
<method event="oninit">
dpConfig.selectChild(2);
canvas.timeoutDataset= dpConfig.xpathQuery('@timeoutdataset');
canvas.timeoutSesion= dpConfig.xpathQuery('@timeoutsesion');
</method>
<method name="abrirMenu" args="opcion">
canvas.vBienvenido.setVisible(false);
</method>
<method name="cerrarMenu" args="opcion">
canvas.vBienvenido.setVisible(true);
</method>
<!-- MENU -->
<menubar name="mbar" height="45">
<menu name="proyecto">Estudio de Licitaciones
<menuitem name="opcionObras" text="Obras">
<menu name="submenuObras" width="200">
<menuitem name="nuevaObra" text="Nueva Obra">
<handler name="onselect">
editProyecto.load();
</handler>
<handler name="onload" reference="editProyecto" args="loaded" >
canvas.abrirMenu();
canvas.vModalActiva = new editProyecto(canvas);
// canvas.vModalActiva.open();
</handler>
</menuitem>
<menuitem name="seleccionarObra" text="Seleccionar ..." onselect="canvas.abrirMenu();canvas.vModalActiva = new selectProyecto(canvas); canvas.vModalActiva.open();"/>
</menu>
</menuitem>
<menuseparator/>
<menuitem name="opcionAdministracion" text="Administración">
<menu name="admin" width="200">
<menuitem name="maestroEquipos" text="Maestro de Equipos" onselect="alertConstruccion.open();"/>
<menuitem name="maestroGastos" text="Maestro de Gastos" onselect="alertConstruccion.open();"/>
<menuitem name="maestroMO" text="Maestro de Mano de Obra" onselect="alertConstruccion.open();"/>
<menuitem name="maestroMateriales" text="Maestro de Materiales" onselect="alertConstruccion.open();"/>
<menuitem name="maestroNeumaticos" text="Maestro de Tipos de Neumático" onselect="alertConstruccion.open();"/>
<menuseparator/>
<menuitem name="contratantes" text="Contratantes" onselect="alertConstruccion.open();"/>
<menuitem name="empresas" text="Empresas" onselect="alertConstruccion.open();"/>
<menuitem name="monedas" text="Monedas" onselect="alertConstruccion.open();"/>
<menuitem name="rubrosGasto" text="Rubros de Gasto" onselect="alertConstruccion.open();"/>
<menuitem name="tipoEquipos" text="Tipos de Equipo" onselect="canvas.abrirMenu(); canvas.vModalActiva = new abmTipoEquipo(canvas); canvas.vModalActiva.open();"/>
<menuitem name="tipoTel" text="Tipos de Teléfono" onselect="alertConstruccion.open();"/>
<menuitem name="umCantidad" text="Unidades de Medida de Cantidad" onselect="alertConstruccion.open();"/>
<menuitem name="umPlazo" text="Unidades de Medida de Plazo" onselect="alertConstruccion.open();"/>
</menu>
</menuitem>
<menuseparator/>
<menuitem name="opcionConfig" text="Configuración" onselect="alertConstruccion.open();"/>
</menu>
<menu name="ief">IEF
<menuitem name="opc1ief" text="En construcción" onselect="alertConstruccion.open();"/>
</menu>
<menu name="agenda">Agenda
<menuitem name="opc1agenda" text="En construcción" onselect="alertConstruccion.open();"/>
</menu>
<menu name="dgr">DGR
<menuitem name="opc1dgr" text="En construcción" onselect="alertConstruccion.open();"/>
</menu>
<menu name="citi">CITI
<menuitem name="opc1citi" text="En construcción" onselect="alertConstruccion.open();"/>
</menu>
<menu name="explosivos">Explosivos
<menuitem name="opc1expl" text="En construcción" onselect="alertConstruccion.open();"/>
</menu>
<menu name="formularios">Formularios
<menuitem name="opc1form" text="En construcción" onselect="alertConstruccion.open();"/>
</menu>
</menubar>
<view height="40" width="40" resource="logo" y="1" x="${canvas.width-43}" opacity="0.5"/>
<view name="vBienvenido" align="center" valign="middle" fgcolor="#aaaaaa">
<text fontsize="20" align="center" valign="top">Bienvenido a la intranet de Michelotti e Hijos S.R.L.</text>
<text fontsize="12" align="center" y="30">Utilice el menú superior para acceder al sistema requerido</text>
</view>
<!-- Esto se tiene que reemplazar por la ventana de Login -->
<alert text="TIMEOUT: A LOGUEARSE DE NUEVO" name="alertTimeout" title="Ha expirado su sesión"/>
<!-- Controlador de timeout de sesion del usuario-->
<LzTimeout milliseconds="$once{canvas.timeoutSesion}">
<handler name="ontimeout">
alertTimeout.open();
</handler>
</LzTimeout>
</canvas>
editProyecto.lzx
<library>
<include href="gui.lzx"/>
<include href="comboClientes.lzx"/>
<include href="comboUMPlazo.lzx"/>
<include href="comboMoneda.lzx"/>
<include href="bid.lzx"/>
<class name="editProyecto" extends="abm"
title="Editar Obra"
align="center"
y="60"
pixellock="true">
<baseform name="fProyecto" x="1" y="1" width="450" height="250" >
<simplelayout axis="y" spacing="5"/>
<view>
<simplelayout axis="x" spacing="5"/>
<text>Obra</text>
<inputtextBase name="txtDescObra" width="400"></inputtextBase>
</view>
<view>
<simplelayout axis="x" spacing="5"/>
<text>Contratante</text>
<comboClientes/>
</view>
<view>
<simplelayout axis="x" spacing="5"/>
<text>Nº Licitación</text>
<inputtextBase name="txtNroLicitacion" width="100"></inputtextBase>
</view>
<view>
<simplelayout axis="x" spacing="5"/>
<text>Fecha de Presentación</text>
<inputtextBase name="txtFechaPresentacion" width="100"></inputtextBase>
</view>
<view>
<simplelayout axis="x" spacing="5"/>
<text>Plazo de Ejecución</text>
<inputtextBase name="txtPlazoEjecucion" width="150"></inputtextBase>
<comboUMPlazo/>
</view>
<view>
<simplelayout axis="x" spacing="5"/>
<text>Presupuesto Oficial</text>
<inputtextBase name="txtPresupuesto" width="150" ></inputtextBase>
<comboMoneda/>
</view>
<view>
<simplelayout axis="x" spacing="5"/>
<text>Usar Movilización de Obra</text>
<checkbox name="chkMovilizacion"/>
</view>
<!-- Solo para Proyectos Nuevos-->
<view>
<simplelayout axis="x" spacing="5"/>
<text multiline="true" width="200">Al crear una nueva obra, automáticamente se creará una Versión Inicial de la obra. Indique la descripción de la versión inicial:</text>
<inputtextBase name="txtVersion" width="250" ></inputtextBase>
</view>
<method event="onchanged" args="val">
</method>
</baseform>
<method name="procesarAceptar">
canvas.vModalActiva = new bid(canvas);
</method>
</class>
</library>
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.