Joachim Lingner schrieb:
Maybe you should post you questions in english AND german because the english translation is really hard to understand.

Joachim

I write into German, in hope me someone understand:), a machine English translation is to be found down
---------------------------------------------------------------------------------------------------------

Hallo Joachim, danke für deinen Hinweis, ich gelobe Besserung.

in meiner Anwendung öffnen ich ein OOoBean (im SWT-Fenster, Stack-Container). Anschließend wird dieses mit ein ausgewählten Dokument (Datei, vorliegend) "gefüttert", immer nur ein Dokument gleichzweitig, je nach Format "Vorlage" oder "Bericht" werden bei letzterem Benutzerfelder mit Daten aus der Anwendung gefüllt. An einer definierten Position, oder am Ende des Dokumentes, (wenn vorhanden) werden zusätzlich einzelne Kapitel aus der Anwendung eingefügt, mit einer unbestimmten Anzahl von Bausteinen. Gleichfalls hat der Anwender die Möglichkeit ggf. weitere Änderungen an dem Dokument vorzunehmen, das Speichern des Dokumentes geschieht hier noch manuell vom Anwender. (Später, sollte eine Änderung erkannt werden, mit nachfolgendem Dialog).

In meiner Anwendung wird sehr häufig das Dokument gewechselt, in der gegenwärtigen Version funktioniert dieses mehr oder weniger ganz gut, es ist jedoch sehr unsauber programmiert :(, es kommt dadurch zu entsprechenden undefenierbaren Nebeneffekten. 1. Es kann passieren, das ein Dokument nach dem Öffnen im OOoBean schreibgeschützt ist. Erst wenn ich die Anwendung und(!) den laufen OOo Prozess über den Taskamanger beenden (OOo), kann ich dieses Dokument wieder verwenden.

2. Nach einem Neustart meiner Anwendung, finde ich zum Teil noch "unbekannte" (leere) Dokument wieder (unter OOo Menü Fenster). Anscheint ist das Schließen meines OOoBean, auch daraus folgend der OpenOffice Anwendung, und dem zuletzt verwendenten Dokumentes (sehr) unsauber. Kann sich das jemand mal anschauen.

3. Nach dem öffnen eines Dokumentes in dem OOoBean greife ich über XComponent und XTextDocument auf dieses zu und bearbeite dieses. Zu 70-90% ist das auch erfolgreich, aber es kommt ab und zu vor, das das XComponent "null" aufweist, erst nach einem erneuten öffnen dieses Dokumentes, kann ich über XComponent darauf zu greifen. Zum Teil muss ich auch erst ein ganz anderes Dokument öffnen, damit dieses wieder funktioniert.

Gruß
Erik




Erik Zuehlke wrote:

...please my English excuses, if I have somewhat more time I also this will improve
----------------------------------------------------------------------------------------
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]


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




--
.......... Zühlke IT GbR ............
Informationstechnologien Training - Entwicklung - Support ..................................... Erik Zühlke Catharina-Fellendorf-Straße 105
      D - 21035 Hamburg
   Tel.: +49 40 735 97 799
   Fax.: +49 40 735 97 798
   Mail: [EMAIL PROTECTED]
.....................................


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

Reply via email to