Beanshell:
Code: Select all
import com.sun.star.uno.Type;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.lib.uno.helper.PropertySet;
import com.sun.star.lib.uno.helper.WeakBase;
import com.sun.star.task.XJobExecutor;
import com.sun.star.lang.XInitialization;
import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.XPropertyChangeListener;
import com.sun.star.beans.PropertyChangeEvent;
import com.sun.star.lang.EventObject;
import com.sun.star.uno.AnyConverter;
import com.sun.star.xml.crypto.sax.XElementStackKeeper ; // defines a start and a stop routine
// Workaround for http://qa.openoffice.org/issues/show_bug.cgi?id=89978 needed from OO 2.4 onwards
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
// This prevents an error message when executing the script a second time
try { Class.forName("ms777Timer_06");}
catch (ClassNotFoundException e) {
System.out.println( "class not found - compiling start" );
public class ms777Timer_06 extends PropertySet implements XElementStackKeeper
{
// These are the properties of the PropertySet
public boolean bFixedRate = true;
public boolean bIsRunning = false;
public int lPeriodInMilliSec = 2000;
public int lDelayInMilliSec = 0;
public int lMaxIterations = 5;
public int lCurrentIteration = 0;
public XJobExecutor xJob = null;
// These are some additional properties
Task xTask =null;
Timer xTimer = null;
public ms777Timer_06() {
registerProperty("bFixedRate", (short) 0);
registerProperty("bIsRunning", (short) com.sun.star.beans.PropertyAttribute.READONLY);
registerProperty("lPeriodInMilliSec", (short) 0);
registerProperty("lDelayInMilliSec", (short) 0);
registerProperty("lMaxIterations", (short) 0);
registerProperty("lCurrentIteration", (short) 0);
registerProperty("xJob", (short) com.sun.star.beans.PropertyAttribute.MAYBEVOID);
xTimer = new Timer();
}
//XElementStackKeeper
public void start() {
stop();
if (xJob==null) {return;}
xTask = new Task();
lCurrentIteration = 1;
bIsRunning = true;
if (bFixedRate) {
xTimer.scheduleAtFixedRate( xTask, (long) lDelayInMilliSec, (long) lPeriodInMilliSec );
} else {
xTimer.schedule( xTask, (long) lDelayInMilliSec, (long) lPeriodInMilliSec );
}
}
public void stop() {
lCurrentIteration = 0;
bIsRunning = false;
if (xTask!=null) { xTask.cancel();}
}
public void retrieve(com.sun.star.xml.sax.XDocumentHandler h, boolean b) { }
class Task extends TimerTask {
public void run() {
xJob.trigger(lCurrentIteration.toString());
lCurrentIteration +=1;
if (lCurrentIteration > lMaxIterations) {
stop();
}
}
}
}
System.out.println( "class not found - compiling end" );
} // of catch (ClassNotFoundException e)
System.out.println( "generating timer property set ... " );
return new ms777Timer_06();
Code: Select all
REM ***** Basiccode for timer-macro *****
Sub Timermakro
oP = GenerateTimerPropertySet()
oJob1 = createUnoListener("JOB1_", "com.sun.star.task.XJobExecutor")
oP.xJob = oJob1
oP.lMaxIterations = 5
oP.lPeriodInMilliSec = 25000
oP.start()
End Sub
function GenerateTimerPropertySet() as Any
oSP = ThisComponent.getScriptProvider("")
oScript = oSP.getScript("vnd.sun.star.script:timer.timer.bsh?language=BeanShell&location=document")
GenerateTimerPropertySet = oScript.invoke(Array(), Array(), Array()
end function
sub JOB1_trigger(s as String)
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(document, ".uno:Refresh", "", 0, Array())
end sub
But since the sub is triggered from the timer and not from something inside the form I can't find how to reach the TextBox1-control.
I have tried to xray every possible way of ThisComponent.... but even if I can find the form "Levlista" I cannot reach the controls inside the form.
Models, views, frames, my head is boiling now so I will go and put it in the freezer and cool down. In the meantime if anyone know where I get it all wrong please share it with me.