How is the best way one, more document to be opened and closed again?
In my application very frequently the document is changed, with the
current version functions this, it is however very careless. It
comes to so some side effects.
1. For example a document is with renewed opens write protected,
only if I close application and OOo over the Taskamanger terminate
(OOo) that can i use this document.
2. Also after repeated application, are unknown (new) documents
start in OOo still opened, apparently have are not completely clean
mine to close the OOo.
3. And still another thing, I works on partially the document by my
application, but I use the XComponent, or better said XTextDocument
which I after that open measure:
---
if ( xDesktop.getCurrentComponent() != null ) {
xComponent = xDesktop.getCurrentComponent();
xTextDocument = (XTextDocument)UnoRuntime.queryInterface(
XTextDocument.class, xComponent);
---
Very frequently this folds also, but there are also moments in which
I the document to change or a further times open must, until
XComponent is not equal to NULL and can afterwards from this then
XTextDocument use.
Can any help me (again)?
Erik
----------------------------------------------
I close the OOeBean in Main class, with ...
----------------------------------------------
....
shell.addDisposeListener(new DisposeListener(){
public void widgetDisposed(DisposeEvent arg0) {
//ControllerOOo.closeDocument();
ControllerOOo.closeBeanFacade();
}
});
.....
----------------------------------------------
The shortened current version my OOo class:
----------------------------------------------
public class ControllerOOo {
private static ControllerOOo instance = null;
private static Composite comp;
private static Dokument dokument;
private static XDesktop xDesktop;
private static XComponent xComponent;
private static XTextDocument xTextDocument;
private static XTextCursor aktCursor;
private static XDocument xDocument;
private static Process __oooProcess;
private static OOoBean bean;
private static XComponentLoader xComponentLoader;
private static PropertyValue[] loadProps = null;
//===========================================================================
private ControllerOOo() {
}
public static ControllerOOo getInstance(){
if (instance == null){
instance = new ControllerOOo();
}
return instance;
}
//===========================================================================
public Composite init(Composite parent) {
comp = new Composite(parent, SWT.NO_BACKGROUND | SWT.EMBEDDED);
return comp;
}
public static void initBeanFacade(){
loadProps = new PropertyValue[2];
Frame frame = SWT_AWT.new_Frame(comp);
Panel panel = new Panel(new BorderLayout());
frame.add(panel);
JRootPane root = new JRootPane();
panel.add(root);
Container contentPane = root.getContentPane();
bean = new OOoBean();
contentPane.add(bean);
xDesktop = null;
setLoadProps(true);
beanSetDocument("private:factory/swriter",loadProps);
}
//=== OPENOFFICE ===================================
public void oeffnen(boolean hidden, Dokument dokument) {
this.dokument = dokument;
String datei = dokument.getDatei();
String loadUrl = "";
// den Dateinamen für eine gültige (uno)URL aufbereiten
try {
java.io.File sourceFile = new java.io.File(datei);
StringBuffer loadUrlSB = new StringBuffer("file:///");
loadUrlSB.append(sourceFile.getCanonicalPath().replace('\\',
'/'));
loadUrl = loadUrlSB.toString();
} catch (IOException e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
// closeDocument();
setLoadProps(hidden);
beanSetDocument(loadUrl,loadProps);
if (xComponent != null){
xTextDocument = (XTextDocument)UnoRuntime.queryInterface(
XTextDocument.class, xComponent);
if (dokument.getTyp() == SGV.BERICHT){
variablenEinfuegen();
kapitelListeEinfuegen();
}
}
}
public void drucken(Dokument dokument) {
oeffnen(true,dokument);
if ( xDesktop.getCurrentComponent() != null ) {
xComponent = xDesktop.getCurrentComponent();
xTextDocument = (XTextDocument)UnoRuntime.queryInterface(
XTextDocument.class, xComponent);
// query the XPrintable interface from your document
XPrintable xPrintable =
(XPrintable)UnoRuntime.queryInterface(XPrintable.class, xComponent);
// create an empty printOptions array
PropertyValue[] printOpts = new PropertyValue[0];
// Drucken des Dokumentes
try {
xPrintable.print(printOpts);
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
}
}
private static void setLoadProps(boolean hidden){
// Eigenschaften für das Laden (siehe
com.sun.star.document.MediaDescriptor )
loadProps[0] = new PropertyValue();
loadProps[0].Name = "NoRestore";
loadProps[0].Value = new Boolean(true);
loadProps[1] = new PropertyValue();
loadProps[1].Name = "Hidden";
loadProps[1].Value = new Boolean(hidden);
// loadProps[2] = new PropertyValue();
// loadProps[2].Name = "Overwrite";
// loadProps[2].Value = new Boolean(true);
}
//======================= OOo BEAN
==========================================
public static void beanSetDocument(String url, PropertyValue[]
loadProps) {
try {
bean.clearDocument(true);
bean.loadFromURL(url, loadProps);
bean.aquireSystemWindow();
xDesktop = bean.getOOoDesktop();
xComponent = xDesktop.getCurrentComponent();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (CloseVetoException e) {
e.printStackTrace();
} catch (NoConnectionException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (SystemWindowException e) {
e.printStackTrace();
}
}
public static void beanStopOOo() {
try {
bean.setVisible(false);
bean.stopOOoConnection();
} catch (DisposedException e) {
// e.printStackTrace();
}
if (__oooProcess != null) {
__oooProcess.destroy();
}
}
public void beanSaveDocument(int beanId) throws Exception {
try {
bean.getDocument().store();
} catch (com.sun.star.io.IOException e) {
// TODO Automatisch erstellter Catch-Block
e.printStackTrace();
} catch (NoConnectionException e) {
// TODO Automatisch erstellter Catch-Block
e.printStackTrace();
}
}
public boolean beanIsDocumentModify(int beanId) {
boolean result = false;
try {
result = bean.getDocument().isModified();
} catch (NoConnectionException e) { } // ignored
return result;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]