Re: [api-dev] How to set false of MenuBarVaisible via Java?

2008-05-20 Thread SeanYoung
Thank you very much!It's OK!

--
From: "Ariel Constenla-Haile" <[EMAIL PROTECTED]>
Sent: Tuesday, May 20, 2008 12:53 PM
To: 
Subject: Re: [api-dev] How to set false of MenuBarVaisible via Java?

> 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 
> *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.is

Re: [api-dev] How to set false of MenuBarVaisible via Java?

2008-05-20 Thread Carsten Driesner
SeanYoung wrote:
> 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?
> 
> 
> dispatch( "slot:5920", "StatusBarVisible", false );
> dispatch( "slot:6661", "MenuBarVisible", false ); 
> 
Hi Sean,

As Ariel already stated slot commands have been deprecated since OOo 2.0
(although they still work). Don't rely on slot URLs as they can be
removed without further notice. The implementation for "slot:6661" which
uses the command URL ".uno:MenuBarVisible" was removed for
OpenOffice.org 2.0. There is a better way to show/hide the menu bar.
Please use the LayoutManager accessible via the frame of your document.
Ariel posted some code on how you can control the visibility of the ui
elements. Please use this way which is more powerful and consistent.

Regards,
Carsten

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



Re: [api-dev] How to set false of MenuBarVaisible via Java?

2008-05-19 Thread Ariel Constenla-Haile

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[]{}));
}

  

Re: [api-dev] How to set false of MenuBarVaisible via Java?

2008-05-19 Thread Ariel Constenla-Haile

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 
*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().createInstance

[api-dev] How to set false of MenuBarVaisible via Java?

2008-05-19 Thread SeanYoung
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?


dispatch( "slot:5920", "StatusBarVisible", false );
dispatch( "slot:6661", "MenuBarVisible", false ); 

//
 private boolean dispatch( String strSlotID, String strSlotName, boolean bValue 
)
 {
  try
  {
   XDispatchProvider xDispProv = (XDispatchProvider) 
UnoRuntime.queryInterface(XDispatchProvider.class,m_xDesktop.getCurrentFrame());
   m_xMultiComponentFactory.createInstanceWithContext(null, null);
   
   Object oTransformer = m_xMultiComponentFactory.createInstanceWithContext
 ("com.sun.star.util.URLTransformer", getXComponentContext());
   XURLTransformer xParser = (com.sun.star.util.XURLTransformer)
 UnoRuntime.queryInterface( XURLTransformer.class, oTransformer );
   URL[] aParseURL = new URL[1];
   aParseURL[0] = new URL();
   aParseURL[0].Complete = strSlotID;
   
   xParser.parseStrict(aParseURL);
   URL aURL = aParseURL[0];
   XDispatch xDispatcher = xDispProv.queryDispatch( aURL,"",0);
   if( xDispatcher != null )
   {
com.sun.star.beans.PropertyValue[] lProperties = new 
com.sun.star.beans.PropertyValue[1];
lProperties[0] = new com.sun.star.beans.PropertyValue();
lProperties[0].Name  = strSlotName;
lProperties[0].Value = new Boolean(bValue);   

PropertyValue[] props = new PropertyValue[1];
props[0] = new PropertyValue(strSlotName, 0, new 
Boolean(bValue),PropertyState.DIRECT_VALUE);

xDispatcher.dispatch( aURL, props );
   }
  }
  catch( com.sun.star.uno.Exception e)
  {
   System.err.println( " Exception " + e );
   e.printStackTrace( System.err );
  }
  
  return true;
 }