Hi Joel,
Joel Cordeiro escribió:
Hi again,
The problem is that i'm out of time. I'm working on a project, and the time
is getting out, and i can't solve the problems. I have already read what's
important on dev's guide, but it didn't helped me.
Follow i write my doubts that i try to find over the internet and the dev's
guide, and i couldn't find a answer about how to do that (if it is in the
dev's guide, please tell me where):
1. If i'm using a job, i should register the interceptor class that
implements XContextMenuInterceptor, on the execute method, right?
yes (but that's not all: as the controller can be disposed - and so your
interceptor-, you'll have to listen to some events and register your
interceptor again)
2. How does i do that? The book doesn't explain that, they give a little
example using a client application.
yes, it's true. The example is a good starting point, but far away from
reality.
When your execute() method is invoked, you'll get a css.beans.NamedValue
sequence. If your Job is registered for document events (EnvType is
"DOCUMENTEVENT"), then you'll get a reference to the document model
(css.frame.XModel).
First, check if the doc. model is of the type you're interested in
(let's say OOo Writer)
Then get the controller from the model ( XModel.getCurrentController()
), and register the interceptor.
3. I have to write a protocol handler to create a action when a user click
one of my new entries on the context. I have a class that implement
XDisptachProvider and XDispatch, and the method queryDispatch returns
itself. The method dispatch have to parameters, url and property value. With
that, how can i know the name of the menu entry the user selected?
both queryDispatch() and dispatch() are invoked with a css.util.URL,
check this URL to see if it matches with the command URL you set in your
new context menu entry.
Did you see the example I told you before in
http://www.arielconstenlahaile.com.ar/ooo/tmp/dbaccess/DatabaseControllerDemo.zip?
Just pay attention at:
* The Job:
- DatabaseControllerDemo/src/Jobs.xcu is the configuration file that
register the Job for the events OnLoad and OnNew
-
DatabaseControllerDemo/src/ar/com/arielconstenlahaile/openoffice/menuinterceptor/JobImplementation.java
implements the Job. Only look at how execute() reads the arguments it
gets when invoked, how it gets the css.frame.XModel and
css.frame.XController, how it checks the component type . You can
register the interceptor there, in the example I instantiate a class
that handles all these things:
// only the component is of the type we are interested in
if ( Helper.checkComponent( sModuleIdentifier ) ) {
DocumentHandler demo = new DocumentHandler(
m_xModel, m_xFrame, m_xController,
OfficeComponentType.get(sModuleIdentifier));
}
I register the interceptor in the constructor:
// REGISTER THE CONTEXT MENU INTERCEPTOR
// here an css.frame.XModel2.getControllers() may also be useful
if ( xController!=null ) {
if ( registerInterceptor( xController, this ) ){
m_aInterceptorsCollection.add( xController );
//xController.addEventListener( );
}
}
where registerInterceptor() is
private boolean registerInterceptor(
XController xController,
XContextMenuInterceptor
aContextMenuInterceptor)
{
boolean bRegistered = false;
if ( xController != null && aContextMenuInterceptor != null ) {
XContextMenuInterception xContextMenuInterception=
(XContextMenuInterception)
UnoRuntime.queryInterface(
XContextMenuInterception.class, xController);
if ( xContextMenuInterception != null ) {
xContextMenuInterception.registerContextMenuInterceptor(
aContextMenuInterceptor);
bRegistered = true;
}
}
Helper.debug("\nTrying to register a context menu
interceptor...\n" +
"\t%s",
bRegistered ? "Context menu registered." : "Imposible
to register the interceptor");
return bRegistered;
}
* The ProtocolHandler:
- DatabaseControllerDemo/src/ProtocolHandler.xcu is the configuration
file that registers my ProtocolHandler to handle command whose URL
protocol is ar.com.arielconstenlahaile.openoffice.Menuinterceptor:*
Then, I must set in the context menu entry a CommandURL using this protocol
-
DatabaseControllerDemo/src/ar/com/arielconstenlahaile/openoffice/menuinterceptor/ProtocolHandlerImpl.java
is the protocol handler/ dispatch object implementation
Look how in queryDispatch() and dispatch() the URL they get is checked
if matches the protocol registered in the config. file
* the context menu interceptor in
DatabaseControllerDemo/src/ar/com/arielconstenlahaile/openoffice/menuinterceptor/DocumentHandler.java
may be rather confusing, just pay attention at
public ContextMenuInterceptorAction notifyContextMenuExecute(
ContextMenuExecuteEvent aEvent)
and how as CommandURL of the context menu entry, I set commands that my
ProtocolHandler can handle:
...
xMenuEntry.setPropertyValue( "CommandURL", ProtocolHandlerImpl.FUNCTION1 );
...
(it does other things, one useful is inspectActionTriggerContainer()
where it prints a tree with the content of the context menu it recivies;
and shows how to add entries at a desired position)
On Sat, Oct 4, 2008 at 5:30 AM, Ariel Constenla-Haile <
[EMAIL PROTECTED]> wrote:
Hi Joel,
What you're trying to do is something complex: if there was an example
for adding a context menu entry via an extension, and we should set a
level of knowledge required to understand it, I'd set the level to
DIFFICULT/COMPLEX and the like; so you will have to be patient and study
gradually.
I'd summarize the requirements as follow:
* knowledge about how a context menu interceptor works (this includes
handling the document selection)
* knowledge about ProtocolHandler implementation
* knowledge about Job implementation
* obviously a general knowledge about how extension work in OOo
(configuration files, etc.)
I forgot to add that one has to know how to listen to Frame actions,
listen to document events (like OnViewCreated), ... , in short: a deep
understanding of the application framework.
Regards
Ariel.
--
Ariel Constenla-Haile
La Plata, Argentina
[EMAIL PROTECTED]
http://www.ArielConstenlaHaile.com.ar/ooo/
"Aus der Kriegsschule des Lebens
- Was mich nicht umbringt,
macht mich härter."
Nietzsche Götzendämmerung, Sprüche und Pfeile, 8.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]