Re: [dev] Need Help with Listeners

2008-11-25 Thread Mathias Bauer
Hi,

I'm afraid that you are on the wrong track. See my comments below.

[EMAIL PROTECTED] wrote:


 XController xController = xModel.getCurrentController();
 XFrame xFrame = xController.getFrame();
 xFrame.addEventListener(new com.sun.star.document.XEventListener() {

This registers your code for events that the frame can fire, but it
doesn't fire any events (except that is calls the disposing method of
all registered listeners in case it is closed and disposed).

 
 Sorry for the long post.
 As you can see i have attached in the xFrame.addEventListener but it is
 never fired...
 I have also tried to insert it to the xModel even the xController...
 But no lack...

The Controller also doesn't fire any events (except the mentioned
disposing call), the Model will fire events that happen in the
document, e.g. when it is closed, if the modified flag changes etc.,
but nothing related to GUI elements.

 Maybe there is something i haven't undestood well

If you want to bind your code to menu entries you should first get
familiar with our Dispatch Framework that is documented in our DevGuide.
In short words, each menu entries has an assigned command that gets
executed when the menu entry is selected. There are two ways to get
code called when a particular command is executed: Dispatch Interceptors
and ProtocolHandlers. While the latter seems to be more complicated at a
first glance it isn't (IMHO) and it's the way I recommend. As I wrote,
please read about it in our DevGuide.

Regards,
Mathias

-- 
Mathias Bauer (mba) - Project Lead OpenOffice.org Writer
OpenOffice.org Engineering at Sun: http://blogs.sun.com/GullFOSS
Please don't reply to [EMAIL PROTECTED].
I use it for the OOo lists and only rarely read other mails sent to it.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



[dev] Need Help with Listeners

2008-11-24 Thread [EMAIL PROTECTED]

Hello , 

I am trying to create a project doing the following 

1. First of all i am creating a menu dynamically - My menu consists of Menus
and Submenus
2. My goal is to catch an event when my new menu is clicked and then to add
code so as to print the menu Name in the document

BUT MY PROBLEM IS THAT IT NEVER GOES IN THE EVENTLISTENER!!! :-(

Here is my code
/

Code:
public class CreateMenu  {
   
private ArrayListString iuo_arraymenu;
private String[][] is_menus;
private XComponent xCurrentComponent;
private XMultiComponentFactory mxRemoteServiceManager = null;
private XComponentContext mxRemoteContext = null;
   
private XLayoutManager xLayoutManager =null;
private XModuleUIConfigurationManagerSupplier xCmSupplier = null;
private XUIConfigurationManager uiConfigManager = null;
private XIndexContainer oMenuBarSettings = null;
private XUIElementSettings xoMenuBarSettings = null;
private XIndexContainer[] oContainer = null;
   
private PropertyValue[] oMenuOTS= null;
   
private XIndexAccess settings;
   
String sMenuBar = private:resource/menubar/menubar;

public CreateMenu(ArrayListString iuo_arraymenu,
XComponent xCurrentComponent , 
XMultiComponentFactory mxRemoteServiceManager,
XComponentContext mxRemoteContext)
throws Exception {
   
this.iuo_arraymenu = iuo_arraymenu;
this.xCurrentComponent = xCurrentComponent;
this.mxRemoteServiceManager = mxRemoteServiceManager;
this.mxRemoteContext = mxRemoteContext;
this.ConvertArrayListToArray();
this.initialize();
this.createMenuMain();
this.getTopMenu();
oMenuMain[2].Name = ItemDescriptorContainer;
oMenuMain[2].Value = oContainer[0];
oMenuBarSettings.insertByIndex( oMenuBarSettings.getCount(),
oMenuMain);
xoMenuBarSettings.setSettings(oMenuBarSettings);
   
   
   
}

public void initialize() throws
WrappedTargetException,
UnknownPropertyException,
Exception{
   
XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class,
xCurrentComponent);
 
XController xController = xModel.getCurrentController();
XFrame xFrame = xController.getFrame();
xFrame.addEventListener(new com.sun.star.document.XEventListener() {

public void notifyEvent(com.sun.star.document.EventObject arg0)
{
System.out.print(IT NEVER GETS HERE);
}

public void disposing(EventObject arg0) {
System.out.print(IT NEVER GETS HERE);
}
});
   
XPropertySet xps = (XPropertySet) UnoRuntime.queryInterface(
XPropertySet.class, xFrame);
xLayoutManager = (XLayoutManager) UnoRuntime.queryInterface(
XLayoutManager.class,
xps.getPropertyValue(LayoutManager));
xCmSupplier = (XModuleUIConfigurationManagerSupplier) UnoRuntime.
  queryInterface(XModuleUIConfigurationManagerSupplier.class,
 
mxRemoteServiceManager.createInstanceWithContext(com.sun.star.ui.ModuleUIConfigurationManagerSupplier,mxRemoteContext));
uiConfigManager =
xCmSupplier.getUIConfigurationManager(com.sun.star.text.TextDocument);
oContainer = new XIndexContainer[this.getMenuContextSum()];
oContainer[0] = uiConfigManager.createSettings();
}
   
public int getMenuContextSum(){
   
int ll_sum = 0;
   
for (int i=0;iis_menus.length;i++ ){
if (is_menus[i][3].equals(0)) {
ll_sum= ll_sum + 1;
}
}
return ll_sum + 1;
   
}
   
public void createMenuMAIN() throws
NoSuchElementException,
IllegalArgumentException,
UnknownPropertyException,
PropertyVetoException,
WrappedTargetException,
IndexOutOfBoundsException{
   
settings = uiConfigManager.getSettings(sMenuBar, true);

// 2. init menu elements
XUIElement oMenuBar = xLayoutManager.getElement(sMenuBar);
XPropertySet props = (XPropertySet) UnoRuntime.queryInterface(
XPropertySet.class, oMenuBar);
props.setPropertyValue(Persistent, new Boolean(true));
xoMenuBarSettings = (XUIElementSettings) UnoRuntime
.queryInterface(XUIElementSettings.class, oMenuBar);
oMenuBarSettings = (XIndexContainer) UnoRuntime
.queryInterface(XIndexContainer.class, xoMenuBarSettings
.getSettings(true));

oMenuMAIN = createMenuOption(.uno:PickList, Main);
   
}
   
 public void ConvertArrayListToArray(){
int i , j;
   
if (!this.iuo_arraymenu.isEmpty()){
j=0;
is_menus = new  

Re: [dev] Need Help with Listeners

2008-11-24 Thread Carsten Driesner

[EMAIL PROTECTED] wrote:
Hello , 

I am trying to create a project doing the following 


1. First of all i am creating a menu dynamically - My menu consists of Menus
and Submenus
2. My goal is to catch an event when my new menu is clicked and then to add
code so as to print the menu Name in the document

BUT MY PROBLEM IS THAT IT NEVER GOES IN THE EVENTLISTENER!!! :-(

Here is my code
/

Code:
public class CreateMenu  {
   
private ArrayListString iuo_arraymenu;

private String[][] is_menus;
private XComponent xCurrentComponent;
private XMultiComponentFactory mxRemoteServiceManager = null;
private XComponentContext mxRemoteContext = null;
   
private XLayoutManager xLayoutManager =null;

private XModuleUIConfigurationManagerSupplier xCmSupplier = null;
private XUIConfigurationManager uiConfigManager = null;
private XIndexContainer oMenuBarSettings = null;
private XUIElementSettings xoMenuBarSettings = null;
private XIndexContainer[] oContainer = null;
   
private PropertyValue[] oMenuOTS= null;
   
private XIndexAccess settings;
   
String sMenuBar = private:resource/menubar/menubar;


public CreateMenu(ArrayListString iuo_arraymenu,
XComponent xCurrentComponent , 
XMultiComponentFactory mxRemoteServiceManager,

XComponentContext mxRemoteContext)
throws Exception {
   
this.iuo_arraymenu = iuo_arraymenu;

this.xCurrentComponent = xCurrentComponent;
this.mxRemoteServiceManager = mxRemoteServiceManager;
this.mxRemoteContext = mxRemoteContext;
this.ConvertArrayListToArray();
this.initialize();
this.createMenuMain();
this.getTopMenu();
oMenuMain[2].Name = ItemDescriptorContainer;
oMenuMain[2].Value = oContainer[0];
oMenuBarSettings.insertByIndex( oMenuBarSettings.getCount(),
oMenuMain);
xoMenuBarSettings.setSettings(oMenuBarSettings);
   
   
   
}


public void initialize() throws
WrappedTargetException,
UnknownPropertyException,
Exception{
   
XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class,

xCurrentComponent);
 
XController xController = xModel.getCurrentController();

XFrame xFrame = xController.getFrame();
xFrame.addEventListener(new com.sun.star.document.XEventListener() {

public void notifyEvent(com.sun.star.document.EventObject arg0)
{
System.out.print(IT NEVER GETS HERE);
}

public void disposing(EventObject arg0) {
System.out.print(IT NEVER GETS HERE);
}
});
   
XPropertySet xps = (XPropertySet) UnoRuntime.queryInterface(

XPropertySet.class, xFrame);
xLayoutManager = (XLayoutManager) UnoRuntime.queryInterface(
XLayoutManager.class,
xps.getPropertyValue(LayoutManager));
xCmSupplier = (XModuleUIConfigurationManagerSupplier) UnoRuntime.
  queryInterface(XModuleUIConfigurationManagerSupplier.class,
 
mxRemoteServiceManager.createInstanceWithContext(com.sun.star.ui.ModuleUIConfigurationManagerSupplier,mxRemoteContext));

uiConfigManager =
xCmSupplier.getUIConfigurationManager(com.sun.star.text.TextDocument);
oContainer = new XIndexContainer[this.getMenuContextSum()];
oContainer[0] = uiConfigManager.createSettings();
}
   
public int getMenuContextSum(){
   
int ll_sum = 0;
   
for (int i=0;iis_menus.length;i++ ){

if (is_menus[i][3].equals(0)) {
ll_sum= ll_sum + 1;
}
}
return ll_sum + 1;
   
}
   
public void createMenuMAIN() throws

NoSuchElementException,
IllegalArgumentException,
UnknownPropertyException,
PropertyVetoException,
WrappedTargetException,
IndexOutOfBoundsException{
   
settings = uiConfigManager.getSettings(sMenuBar, true);


// 2. init menu elements
XUIElement oMenuBar = xLayoutManager.getElement(sMenuBar);
XPropertySet props = (XPropertySet) UnoRuntime.queryInterface(
XPropertySet.class, oMenuBar);
props.setPropertyValue(Persistent, new Boolean(true));
xoMenuBarSettings = (XUIElementSettings) UnoRuntime
.queryInterface(XUIElementSettings.class, oMenuBar);
oMenuBarSettings = (XIndexContainer) UnoRuntime
.queryInterface(XIndexContainer.class, xoMenuBarSettings
.getSettings(true));

oMenuMAIN = createMenuOption(.uno:PickList, Main);
   
}
   
 public void ConvertArrayListToArray(){

int i , j;
   
if (!this.iuo_arraymenu.isEmpty()){

j=0;

Re: [dev] Need Help with Listeners

2008-11-24 Thread [EMAIL PROTECTED]

Carsten , 
thank you very much for the hint...I really had misunderstood...
thank you for the links..I will study them and i will try to implement what
i need

THANK YOU!!:handshake:


Hi,

it looks like you misunderstood how menus in OpenOffice.org work. Menus 
are only containers for commands. There is no event listener concept for 
menus controlled by OpenOffice.org. These commands are dispatched and 
processed by a so called Dispatch Provider. For more information, 
please look into the following chapter of the Developer's Guide:
http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/OfficeDev/Using_the_Dispatch_Framework

So there are two different ways to be called when a certain command is 
going to be dispatched. First, you can implement your own 
DispatchProvider which is responsible for your commands. A second way is 
to implement a dispatch interceptor, which intercept certain commands. 
For more information, please look into the following chapter of the 
Developer's Guide:
http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/OfficeDev/Dispatch_Interception

Regards,
Carsten

-- 
Carsten Driesner (cd at openoffice.org) - Project Lead OpenOffice.org 
Framework
Framework wiki: http://wiki.services.openoffice.org/wiki/Framework
OpenOffice.org Engineering at Sun: http://blogs.sun.com/GullFOSS

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-- 
View this message in context: 
http://www.nabble.com/Need-Help-with-Listeners-tp20660938p20675795.html
Sent from the openoffice - dev mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]