Hey,

Thanks for the info.

I do seem to run into problems trying to get it to work adding a
FrameActionListener.  Here's what happens.

1. I add an anonymous implementation of XFrameActionListener to the frame
when a document is loaded.
When I catch the FrameAction: "FrameAction.COMPONENT_REATTACHED" only I
catch the Action when PrintPreview is invoked.
When I catch using if - else and use "FrameAction.COMPONENT_ATTACHED" then
in the first "if", as described above, I can't catch an action when
PrintPreview is invoked.

2. In any of the given situations I cannot seem to get a hold of the
MenuBar.  It's always null.  I tried to get the XFrame in several ways,
which works and then try to get the XLayoutManager using the XPropertySet
from the different ways of getting the XFrame.  I get "an" XLayoutManager,
however it never has any Elements.  I print out the Elements received from
xLayoutManager.getElements(), but it's an empty Array. 

Here's the code I used:



> aFrame.addFrameActionListener(new XFrameActionListener(){
> 
>                     public void frameAction(FrameActionEvent
> frameActionEvent) {
> //                        System.out.println(frameActionEvent +
> "\t"+frameActionEvent.Action.getValue());
> //                        FrameAction.COMPONENT_ATTACHED;
>                        
> if(frameActionEvent.Action.equals(FrameAction.COMPONENT_REATTACHED)){
>                             Object source = frameActionEvent.Source;
>                             System.out.println("ReAttached!");
>                             try{
> 
>                                 addParagraafMenu(source);
>                             }catch(Exception e){
>                                 e.printStackTrace();
>                             }
>                         }
> // commented out because this causes the selection above not to trigger
> anymore
> //                        else
> if(frameActionEvent.Action.equals(FrameAction.COMPONENT_ATTACHED)){
> //
> //                            try {
> //                               
> addParagraafMenu(frameActionEvent.Source);
> //                            } catch (Exception e) {
> //                                e.printStackTrace();
> //                            }
> //                        }
>                     }
> 



> public void addParagraafMenu(Object source) throws Exception,
> WrappedTargetException, IndexOutOfBoundsException,
> IllegalArgumentException, PropertyVetoException {
>         //I can get this frame
>         XFrame srcFrame =
> (XFrame)UnoRuntime.queryInterface(XFrame.class,source);
> 
>         XMultiComponentFactory fact =
> iConnection.getComponentContext().getServiceManager();
>         Object desktop =
> fact.createInstanceWithContext("com.sun.star.frame.Desktop",iConnection.getComponentContext());
>         //Using the XDesktop I can also get the frame, but no help there
>         XDesktop xDesktop = (XDesktop)
> UnoRuntime.queryInterface(XDesktop.class,desktop);
> 
>         XPropertySet xps = (XPropertySet) UnoRuntime.queryInterface(
>                         XPropertySet.class, srcFrame);
>         //xLayoutManager is never null but never has any XUIElements
>         XLayoutManager xLayoutManager = (XLayoutManager)
> UnoRuntime.queryInterface(
>                         XLayoutManager.class,
>                         xps.getPropertyValue("LayoutManager"));
>         XUIElement myMenubar =
> xLayoutManager.getElement("private:resource/menubar/menubar");
> 
>         XUIElement[] elements = xLayoutManager.getElements();
>         for(XUIElement elem:elements){
>             String hmm = elem.toString()+"\t";
>             hmm.concat(elem.getRealInterface().toString());
>             System.out.println(hmm);
>         }
> 
>         XUIElementSettings myMenuBarSettings = (XUIElementSettings)
> UnoRuntime.queryInterface(XUIElementSettings.class,
>                 myMenubar);
>         XIndexContainer myMenuBarSettingsContainer = (XIndexContainer)
> UnoRuntime.queryInterface(
>                
> XIndexContainer.class,myMenuBarSettings.getSettings(true));
> 
>         XPropertySet menuBarSets = (XPropertySet)
> UnoRuntime.queryInterface(
>                         XPropertySet.class, myMenubar);
> 
>         menuBarSets.setPropertyValue("Persistent",new Boolean(false));
>         XMenuBar bar = (XMenuBar)
> UnoRuntime.queryInterface(XMenuBar.class,
> menuBarProps.getPropertyValue("XMenuBar"));
>         bar.insertItem((short) 0, "~Paragraaf",
> com.sun.star.awt.MenuItemStyle.AUTOCHECK, (short) 0);
>         //setting the menu
>         bar.setPopupMenu((short) 0, getPopupMenu());
>         bar.addMenuListener(this);
>         myMenuBarSettings.setSettings(myMenuBarSettingsContainer);
> 
>     }
> 




Carsten Driesner wrote:
> 
> Fhomasp wrote:
>> Hey,
>>
>> I implemented a custom menu item using one of the examples.  However this
>> extra menu item disappears as soon as a printpreview screen is invoked. 
>> The
>> menu item doesn't return when the printpreview is closed.
>>
>> Here's the code I used
>>   
> Hi Fhomasp,
> 
> You use non-persistent changes for the menu bar. The print preview 
> function uses a different controller implementation and therefore the 
> user interface elements are reinitialized, means destroyed and created. 
> That's why your changes get lost. You have to add a FrameActionListener 
> to the frame and redo your changes whenever your receive a 
> FRAMEACTION_ATTACHED, FRAMEACTION_REATTACHED notification.
> 
> Regards,
> Carsten
> 
> -- 
> Carsten Driesner (cd) - 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/custom-menu-item-disappearing-after-printpreview-tp22741195p22778415.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]

Reply via email to