| View previous topic :: View next topic |
| Author |
Message |
mtzoua Newbie

Joined: 20 Nov 2008 Posts: 4
|
Posted: Thu Nov 20, 2008 4:29 am Post subject: JAVA - Listeners seem to be inactive |
|
|
hello,
I seem to have the following problem
i have created an application in java in which i want to place a custom menu in an OOo Writer.
I have created the menu successfully but i cannot find the way to attach a listener to them.
I tried to attach other listeners(MouseListener , EventListener , ActionperformedListener) to xComponent or the frame or the controller or the window BUT NONE OF THEM are detected...
Am i doing something WRONG???
Thanks in advance |
|
| Back to top |
|
 |
ms777 Super User


Joined: 07 Feb 2004 Posts: 1355
|
Posted: Fri Nov 21, 2008 7:36 am Post subject: Re: JAVA - Listeners seem to be inactive |
|
|
| mtzoua wrote: | | Am i doing something WRONG??? | Probably yes, but without giving some (simplified) code it is very difficult to help ... |
|
| Back to top |
|
 |
mtzoua Newbie

Joined: 20 Nov 2008 Posts: 4
|
Posted: Sun Nov 23, 2008 11:26 pm Post subject: |
|
|
Sorry for not posting earlier but i thought that something was wrong in the concept..
Here id what i an trying to do
- First of all i am creating a menu dynamically
- What i want is to catch an event when my new menu is clicked and then to add code so as to print lets say something in the document lets say "hello world"
BUT MY PROBLEM IS THAT IT NEVER GOES IN THE EVENTLISTENER
Here is my code
/////////////////////////////////////////////////////////
| Code: | public class CreateMenu {
private ArrayList<String> 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(ArrayList<String> 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;i<is_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 String[this.iuo_arraymenu.size()/4][4];
System.out.println("is_menus.length" + is_menus.length );
for(i=0;i<this.iuo_arraymenu.size();i=i+4){
is_menus[j][0] = this.iuo_arraymenu.get(i);
is_menus[j][1] = this.iuo_arraymenu.get(i+1);
is_menus[j][2] = this.iuo_arraymenu.get(i+2);
is_menus[j][3] = this.iuo_arraymenu.get(i+3);
j= j + 1;
}
}
}
private PropertyValue[] createMenuOption(String sMyCommand, String label)
throws IllegalArgumentException, IndexOutOfBoundsException,
WrappedTargetException {
PropertyValue[] loadProps = new PropertyValue[3];
loadProps[0] = new PropertyValue();
loadProps[1] = new PropertyValue();
loadProps[2] = new PropertyValue();
loadProps[0].Name = "CommandURL";
loadProps[0].Value = sMyCommand;
loadProps[1].Name = "Label";
loadProps[1].Value = label;
return loadProps;
}
private PropertyValue[] createMenuItem(String sMyCommand, String label) {
PropertyValue[] loadProps = new PropertyValue[2];
loadProps[0] = new PropertyValue();
loadProps[1] = new PropertyValue();
loadProps[0].Name = "CommandURL";
loadProps[0].Value = sMyCommand;
loadProps[1].Name = "Label";
loadProps[1].Value = label;
return loadProps;
}
public void getTopMenu() throws IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException{
for (int i=0;i<is_menus.length;i++){
if (is_menus[i][2].equals("0")){
CreateTreeTopMenu( is_menus[i][0] , 0 , is_menus[i][1]);
}
}
}
public void CreateTreeTopMenu( String as_fatherid , int ai_indexContainer , String as_menudescr ) throws IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException{
boolean lbl_found = false;
for (int i=0;i<is_menus.length;i++){
if (is_menus[i][2].equals(as_fatherid)){
lbl_found = true;
break;
}
}
if (!lbl_found) {
PropertyValue[] property = createMenuItem(".uno:PickList", as_menudescr);
oContainer[ai_indexContainer].insertByIndex(oContainer[ai_indexContainer].getCount(),property);
return;
}else{
int curindexContainer;
PropertyValue[] MenuOption = createMenuOption(".uno:PickList", as_menudescr);
curindexContainer = ai_indexContainer + 1;
oContainer[curindexContainer] = uiConfigManager.createSettings();
for (int i=0;i<is_menus.length;i++){
if (is_menus[i][2].equals(as_fatherid)){
CreateTreeTopMenu(is_menus[i][0], curindexContainer , is_menus[i][1] );
}
}
MenuOption[2].Name="ItemDescriptorContainer";
MenuOption[2].Value = oContainer[curindexContainer];
oContainer[ai_indexContainer].insertByIndex(oContainer[ai_indexContainer].getCount(),MenuOption);
}
}
}
|
//////////////////////////////////////////////////////////////////////////////////////////
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...
Maybe there is something i haven't undestood well
Thanks in advance |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|