Ariel Constenla-Haile escribió:
Hi Sean,

Hi,
I want customize view of openoffice 3.0 beta thought execute Java code.
The "slot:5920" could hide StatusBar,but the "slot:6661" is invalid.
Can anybody ask me , what is MenuBarVisible's new slotID in new OpenOffice 3.0 Beta?

slots are from OOo's stone age, you should try to use the UNO commnad URLs:

".uno:StatusBarVisible"
".uno:MenuBarVisible"

and you may try to use the newer API: XDispatchHelper

Anyway, (1) ".uno:MenuBarVisible" seems not to work in 2.4.0 (I'm not sure if this is this a bug, or this command does not work just because it isn't available in the UI, and so they have remove it), (2) you should avoid using the dispatch mechanism for this, and use instead the ayoutManager, see the sample below: it is even *simpler*, and here you

here it must say *LayoutManager* (mmm... I should read before pressing
"Send"; but well, I'm forgiven, as even the APi has/had its own typo ;-)
http://api.openoffice.org/docs/common/ref/com/sun/star/frame/Frame.html#LayoutManger
- issue already submitted, and now fixed by Jürgen)



*can* set the menu bar not visible!

Regards
Ariel.

//***************************************************************************

import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.XPropertySet;
import com.sun.star.uno.XComponentContext;
import com.sun.star.comp.helper.Bootstrap;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.frame.XDispatchHelper;
import com.sun.star.frame.XDispatchProvider;
import com.sun.star.frame.XFrame;
import com.sun.star.frame.XLayoutManager;
import com.sun.star.frame.XModel;
import com.sun.star.lang.XComponent;
import com.sun.star.uno.UnoRuntime;

/**
 *
 * @author ariel
 */
public class UIElementsDemo {

    private XComponentContext m_xContext;

    /** Creates a new instance of DispatchDemo */
    public UIElementsDemo(XComponentContext xContext) {
        m_xContext = xContext;
    }


    protected void runDispatchDemo() {
        try {
            XModel xModel = (XModel) UnoRuntime.queryInterface(
                    XModel.class, createNewDoc(m_xContext, "swriter") );

            XFrame xFrame = xModel.getCurrentController().getFrame();

            PropertyValue[] aDispatchArgs = new PropertyValue[1];
            aDispatchArgs[0] = new PropertyValue();
            aDispatchArgs[0].Name = "StatusBarVisible";
            aDispatchArgs[0].Value = Boolean.FALSE;

            executeDispatch(m_xContext, xFrame, ".uno:StatusBarVisible",
                    "", 0, aDispatchArgs);

            aDispatchArgs[0].Name = "MenuBarVisible";

            executeDispatch(m_xContext, xFrame, ".uno:MenuBarVisible",
                    "", 0, aDispatchArgs);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    protected void runLayoutManagerDemo() {
        String sStatusBar = "private:resource/statusbar/statusbar";
        String sMenuBar = "private:resource/menubar/menubar";
        try {
            XComponent xComponent = createNewDoc(m_xContext, "swriter");

            XLayoutManager xLayoutManager = getLayoutManager(xComponent);

            toggleUIElement(xLayoutManager, sStatusBar);

            toggleUIElement(xLayoutManager, sMenuBar);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public static XLayoutManager getLayoutManager(XComponent xComponent) {
        XLayoutManager xLayoutManager = null;
        try {
            XModel xModel = (XModel) UnoRuntime.queryInterface(
                    XModel.class, xComponent);
            XFrame xFrame = xModel.getCurrentController().getFrame();

            XPropertySet xPropertySet = (XPropertySet)
UnoRuntime.queryInterface(
                    XPropertySet.class, xFrame);
            xLayoutManager = (XLayoutManager) UnoRuntime.queryInterface(
                    XLayoutManager.class,
                    xPropertySet.getPropertyValue("LayoutManager"));
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return xLayoutManager;
        }
    }

    private void toggleUIElement(XLayoutManager xLayoutManager, String
sUIElement) {
        if (xLayoutManager.isElementVisible(sUIElement)) {
            xLayoutManager.hideElement(sUIElement);
        } else {
            xLayoutManager.showElement(sUIElement);
        }
    }

    public XComponent createNewDoc(XComponentContext xContext, String
sDocType) throws Exception {
        XComponentLoader xComponentLoader = (XComponentLoader)
                UnoRuntime.queryInterface(XComponentLoader.class,
                m_xContext.getServiceManager().createInstanceWithContext(
                "com.sun.star.frame.Desktop", m_xContext));

        return (XComponent) UnoRuntime.queryInterface(
                XComponent.class, xComponentLoader.loadComponentFromURL(
                "private:factory/" + sDocType, "_default", 0, new
PropertyValue[]{}));
    }

    public static XDispatchHelper getDispatchHelper(XComponentContext
xContext) {
        XDispatchHelper xDispatchHelper = null;
        try {
            xDispatchHelper = (XDispatchHelper) UnoRuntime.queryInterface(
                    XDispatchHelper.class,
                    xContext.getServiceManager().createInstanceWithContext(
                    "com.sun.star.frame.DispatchHelper", xContext));
        } catch (com.sun.star.uno.Exception ex) {
            ex.printStackTrace();
        }
        return xDispatchHelper;
    }

    public static void executeDispatch(
                                    XComponentContext xContext,
                                    XFrame xFrame,
                                    String aDispatchURL,
                                    String aTargetFrameName,
                                    int iSearchFlags,
                                    PropertyValue[] someArgs) {

        XDispatchHelper xDispatchHelper = getDispatchHelper(xContext);
        XDispatchProvider xDispatchProvider = (XDispatchProvider)
                UnoRuntime.queryInterface(XDispatchProvider.class, xFrame);
        xDispatchHelper.executeDispatch(
                xDispatchProvider, aDispatchURL, aTargetFrameName,
iSearchFlags, someArgs);
    }





    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            // get the remote office component context
            XComponentContext xContext = Bootstrap.bootstrap();

            UIElementsDemo demo = new UIElementsDemo(xContext);

            demo.runDispatchDemo();

            demo.runLayoutManagerDemo();


        } catch (java.lang.Exception e) {
            e.printStackTrace();
        } finally {
            System.exit(0);
        }
    }

}

//***********************************************************************



--
Ariel Constenla-Haile
La Plata, Argentina

[EMAIL PROTECTED]
[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]

Reply via email to