CIB JView technischer Leitfaden

Einbindung des CIB jView in Java

In den unteren Abschnitten finden Sie kurze Codebeispiele für den Aufruf von CIB jView. Vergewissern Sie sich, dass die CIB office module sich im Library Path der Java Virtual Machine (JVM) und die benötigten JAR-Dateien in einem Classpath-Verzeichnis befinden.

Einbindung in eine HTML-Seite
Einbindung in eine Java Swing-Applikation
     ▸ Integration in Java-Applikation (JFrame) und Anzeige einer PDF-Datei
     ▸ Integration in Java-Applikation (JDialog) und Anzeige einer TIFF-Datei
     ▸ Integration in eine Java-Applikation mit gleichzeitiger Integration eines eigenen Druckdialoges
     ▸ Integration des CIB jView&rec in eine Java-Applikation und Anzeige einer RTF-Datei mit eingebettetem Rec-Edit-Feld
     ▸ Einmischen von RTF-Snippets in ein RTF-Dokument mit CIB merge und Speichern in ein anderes RTF-Dokument
     ▸
Interface CustomCloseDialogInfo zum Austausch von Informationen für den CustomCloseDialogCallback
Einbindung in eine Java SWT-Applikation

Einbindung in eine HTML-Seite

HTML-Seite mit einem integrierten jView-Applet

<html>
      <head>
            <title>CIB JView</title>
      </head>
      <body>
            <applet archive="CibJView.jar, ComodJobs.jar"
            code="de/cib/view/JCibViewApplet.class"                   width="100%" height="100%" ID="Applet1">
            </applet>
      </body>
</html>


Einbindung in eine Java Swing-Applikation

Integration in Java-Applikation (JFrame) und Anzeige einer PDF-Datei

import
javax.swing.JFrame;
import de.cib.gui.framework.ICibApplication;
import de.cib.view.*;
import com.cib.comod.jobs.*;
 
public class JViewFrame {
      public static void main(java.lang.String[] args) {
            JFrame myFrame = new JFrame();
            myFrame.setTitle("Test Frame");
            myFrame.setSize(800, 800);
            JCibView t_CIBView = new JCibView();
            t_CIBView.setFrame(myFrame);
      t_CIBView.setProperty(ICibApplication.PROPERTY_INPUTFILE,
                  "test.pdf");
            // keine Menüleiste anzeigen
      t_CIBView.setProperty(ICibApplication.PROPERTY_MENU_ENABLED,
                  new Boolean(false));
      t_CIBView.setProperty(ICibApplication.PROPERTY_EXPORT_ENABLED,
                  new Boolean(false));
            // keine JView Ini-Datei schreiben
      t_CIBView.setProperty(ICibApplication.PROPERTY_INIFILENAME,
                  null);
      t_CIBView.setProperty(ICibApplication.PROPERTY_TITLE,
                  new String("JCibView!"));
            t_CIBView.start();
            t_CIBView.load();
      myFrame.getContentPane().add(t_CIBView);
            myFrame.setVisible(true);
      }
}

Integration in Java-Applikation (JDialog) und Anzeige einer TIFF-Datei

import javax.swing.JDialog;
import de.cib.gui.framework.ICibApplication;
import de.cib.view.*;
import com.cib.comod.jobs.*;
 
public class JViewDialog {
      public static void main(java.lang.String[] args) {
            JDialog myDialog = new JDialog ();
            myDialog.setTitle("Test Dialog");
            myDialog.setSize(800, 800);
            JCibView t_CIBView = new JCibView();
            t_CIBView.setFrame(myDialog);
      t_CIBView.setProperty(ICibApplication.PROPERTY_INPUTFILE,
                  "example.tif");
            // keine Menüleiste anzeigen
      t_CIBView.setProperty(ICibApplication.PROPERTY_MENU_ENABLED,
                  new Boolean(false));
      t_CIBView.setProperty(ICibApplication.PROPERTY_EXPORT_ENABLED,
                  new Boolean(false));
            // keine JView Ini-Datei schreiben
      t_CIBView.setProperty(ICibApplication.PROPERTY_INIFILENAME,
                  null);
      t_CIBView.setProperty(ICibApplication.PROPERTY_TITLE,
                  new String("JCibView!"));
            t_CIBView.start();
            t_CIBView.load();
      myDialog.getContentPane().add(t_CIBView);
            myDialog.setVisible(true);
      }
}

Integration in eine Java-Applikation mit gleichzeitiger Integration eines eigenen Druckdialoges

Nachfolgendes Codebeispiel zeigt die Möglichkeit, einen selbstprogrammierten Druckdialog in den JView einzuhängen.

Wichtige Hinweise:

Wenn Sie die Klasse JCibPrinterJob erweitern, dann überschreiben Sie bitte die Methode print() nicht, oder wenn dies unvermeidlich ist, stellen Sie sicher, dass Sie die Methode super() aufrufen, sonst kann das Drucken nicht erwartungsgemäß erfolgen.

JCibView geht standardmäßig davon aus, dass die aktuelle Seite gedruckt werden soll. Er setzt intern die CIB Format Property ICibFormatJob.PROPERTY_CURRENTPAGE auf die aktuelle Seitenzahl. Um ein unerwünschtes Drucken nur der aktuellen Seite zu vermeiden, setzen Sie die Property PROPERTY_CURRENTPAGE auf -1.

import javax.swing.JFrame;
import de.cib.view.*;
import com.cib.comod.jobs.*;
import com.cib.comod.tools.print.*;
import java.awt.*;
 
public class JViewFrame {
 
      public static void main(java.lang.String[] args) {
            JFrame myFrame = new JFrame();
            myFrame.setTitle("Test Frame");
            myFrame.setSize(300,300);
            JCibView t_CIBView = new JCibView (myFrame);
 
            // Mein eigener PrinterJob soll benutzt werden
      System.setProperty("com.cib.tools.print.printerjob",
                  "my.package.MyPrinterJob");
      t_CIBView.setProperty(ICibApplication.PROPERTY_INPUTFILE,
                  "test.rtf");
      t_CIBView.setProperty(ICibApplication.PROPERTY_SEARCH_ENABLED,
                  new Boolean(false));
            // keine Menüleiste anzeigen
      t_CIBView.setProperty(ICibApplication.PROPERTY_MENU_ENABLED,
                  new Boolean(false));
      t_CIBView.setProperty(ICibApplication.PROPERTY_EXPORT_ENABLED,
                  new Boolean(false));
      t_CIBView.setProperty(ICibApplication.PROPERTY_TITLE,
                  new String("JCibView!"));
 
            t_CIBView.start();
            t_CIBView.load();
 
      myFrame.getContentPane().add(t_CIBView);
            myFrame.setVisible(true);
      }
}
 
package my.package;
import com.cib.comod.tools.print.*;
 
public class MyPrinterJob extends JCibPrinterJob {
      // Die Methode gibt true zurück, wenn gedruckt werden soll,
      // andernfalls false.
      public boolean printDialog()
      {
            // HHHHHHhhier fügen Sie Ihren Dialog-Code ein.
            .......
      }
}

Integration des CIB jView&rec in eine Java-Applikation und Anzeige einer RTF-Datei mit eingebettetem Rec-Edit-Feld

import java.awt.BorderLayout;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
 
import javax.swing.JFrame;
import javax.swing.WindowConstants;
 
import de.cib.gui.framework.ICibApplication;
import de.cib.gui.framework.JCibApplication;
import de.cib.jRec.ICibRecApplication;
import de.cib.util.trace.Trace;
 
public class JCibViewTest {
 
      public static final String TEST_FILENAME = "test_rec.rtf";
 
      public static void main(java.lang.String[] args) {
            // We need a frame to put the Viewer inside.
            JFrame t_frame = new JFrame();
           
            // We need a viewer.
            final JCibView t_CIBView = new JCibView();
            t_CIBView.setFrame(t_frame);
           
            // Prepare frame.
        t_frame.setDefaultCloseOperation(
                  WindowConstants.DO_NOTHING_ON_CLOSE);
           
            try {
                  t_frame.addWindowListener(new WindowAdapter() {
                        public void windowClosing(WindowEvent e) {
                              //call stop for clean ups!
                              t_CIBView.stop();
                        }
                  });
            }
            catch (Throwable exception) {
                Trace.trace("Prepare frame " , exception);
            }
            t_frame.setSize(
            (int)(Toolkit.getDefaultToolkit().getScreenSize()
                        .getWidth()) * 0.75),
                  (int) ((Toolkit.getDefaultToolkit()
                        .getScreenSize().getHeight()) * 0.75));
      t_frame.getContentPane().setLayout(new BorderLayout());
           
            // Prepare viewer.
            // Set input file (optional)
      t_CIBView.setProperty(ICibApplication.PROPERTY_INPUTFILE,                               TEST_FILENAME);
            // Enable JCibRec in JCibView (optional).
      t_CIBView.setProperty(ICibRecApplication.PROPERTY_REC_ENABLED,                   Boolean.TRUE);
            JCibApplication t_cibRec = t_CIBView.getRec();
           
            // Set constraints to allowed font list (optional).
            if (t_cibRec != null) {
                  String fontList = "Times New Roman; Arial; Courier New";
                t_CIBView.getRec().setProperty(
                  ICibRecApplication.PROPERTY_ALLOWED_FONT_LIST,
                        fontList);
            }
            // Use native print dialog (optional).
            // Otherwise the Java print dialog is used.
            t_CIBView.setProperty(
                  ICibApplication.PROPERTY_SHOWJPRINTDIALOG,
                        Boolean.FALSE);
           
            t_CIBView.start();           
            t_CIBView.load();
           
      t_frame.getContentPane().add(t_CIBView, BorderLayout.CENTER);
            t_frame.setVisible(true);
    }
}

Einmischen von RTF-Snippets in ein RTF-Dokument mit CIB merge und Speichern in ein anderes RTF-Dokument

import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
 
import com.cib.comod.jobs.ICibMergeJob;
import com.cib.comod.jobs.JCibMergeJob;
 
import de.cib.gui.framework.CibMessageDialog;
import de.cib.gui.util.trace.Trace;
import de.cib.metafile.Messages;
import de.cib.view.modules.jRec.jRecController;
import de.cib.webdesk.utilities.IOUtilities;
 
public class JMergeTestRunner {
 
      /**
       * Mischt zwei RTF-Snippets mit CIB merge in Input-RTF-Datei ein.
       * Das Ergebnis wird in die angegebene Output-Datei gespeichert.
       */
      public static void main(java.lang.String[] args) {
 
            // Set file path to example files - must be adjusted
            String path = "C:/Testfiles/";
           
            // Create RTF document by CIB merge job with merge/recombine.
            File inputFile = new File (path + "merge-Test-In.rtf");
            File outputFile = new File (path + "merge-Test-Out.rtf");
           
            String snippet0 = new String (path + "jRec_snippet_0");
            String snippet1 = new String (path + "jRec_snippet_1");
           
            HashMap<Integer, String> rtfControls =                         new HashMap<Integer, String>();
            rtfControls.put(new Integer(0),                         new String(IOUtilities.readFile(snippet0)));
            rtfControls.put(new Integer(1),                         new String(IOUtilities.readFile(snippet1)));
                       
            try {
                  // Merge-Job initialisieren
                  JCibMergeJob t_mergeJob =  new JCibMergeJob();
                  t_mergeJob.initialize();
                 
                  if (t_mergeJob != null && t_mergeJob.isInitialized()) {
                        File snippetDir = new File(                            jRecController.getSnippetDir());
                        // Merge Error log in Snippet-Verzeichnis speichern
                        File logFile = null;
                        if (snippetDir.exists()) {
                              logFile = new File(jRecController.getSnippetDir()                                      + "merge_recombine.log");
                              if (logFile.exists())
                                    logFile.delete();
                              t_mergeJob.setProperty(                                  ICibMergeJob.PROPERTY_ERRORFILE,                                     logFile.getAbsolutePath());
                              t_mergeJob.setProperty(                                    ICibMergeJob.PROPERTY_VERBOSE,                                     "5+all+source");
                        }
                        t_mergeJob.setProperty(                            ICibMergeJob.PROPERTY_INPUTFILE,                               inputFile.getAbsolutePath());
                        if (outputFile.exists())
                              outputFile.delete();
                        t_mergeJob.setProperty(                           ICibMergeJob.PROPERTY_OUTPUTFILE,                              outputFile.getAbsolutePath());
                        t_mergeJob.setProperty(                         ICibMergeJob.PROPERTY_EXTENDEDREF,                               Boolean.TRUE);
                        t_mergeJob.setProperty(                           ICibMergeJob.PROPERTY_CHARFORMAT, "auto");
                        t_mergeJob.setProperty(                               ICibMergeJob.PROPERTY_KEEP, "unresolved-ref");
                        // Neuer Parameter, um vorhandene Field-Results                         // bei nicht vorhandener Datenversorgung zu erhalten.
                        t_mergeJob.setProperty(
                              "--field-results=", "keepswitch");
                              "--field-results=", "keepswitch");
                        // RTF Snippets, die den Inhalt im RTF ersetzen.                         // Können auch von Platte kommen.
                        if (rtfControls != null) {
                              Integer fieldID;
                              String snippetName;
                              Iterator<Integer> it =                                  rtfControls.keySet().iterator();
                              while (it.hasNext()) {
                                    fieldID = it.next();
                                    String rtfPassage =                                           rtfControls.get(fieldID);
                                    if (rtfPassage != null) {
                                          // Set property value for rtf snippet
                                          snippetName = "cibrec-snippet"                                                 + fieldID.intValue() + ".rtf=";
                                          t_mergeJob.setProperty(                                                 "--directory-set=",                                                 snippetName + rtfPassage);
                                    }
                              }
                        }
                       
                        // Merge-Job ausführen
                        t_mergeJob.execute();
                       
                        // Fehlerbehandlung
                        int t_Error = ((Integer)t_mergeJob.getProperty(
                              ICibMergeJob.PROPERTY_ERROR)).intValue();
                              ICibMergeJob.PROPERTY_ERROR)).intValue();
                        if (t_Error != 0) {
                              // Fehler beim Ausführen des Merge-Jobs
                              String t_Errortext =
                                  (String)t_mergeJob.getProperty(
                                      ICibMergeJob.PROPERTY_ERRORTEXT);
                                  (String)t_mergeJob.getProperty(                                       ICibMergeJob.PROPERTY_ERRORTEXT);
                              Trace.traceln("Error executing merge job: "                                     + t_Error + " " + t_Errortext);
                        }
                  }
            } catch (Exception e) {
                // Fehlerbehandlung
                  Trace.traceln("Save RTF + fields with CIB merge failed.\n"
                        + "Please check the installation of cibmrg32.dll.");
                  e.printStackTrace();
            }
    }
}

Interface CustomCloseDialogInfo zum Austausch von Informationen für den CustomCloseDialogCallback


Die Datenstruktur CustomCloseDialogInfo dient zum Austausch von Informationen für den CustomCloseDialogCallback, sie ist im CIB jView (package de.cib.view.modules) definiert. 

Interface CustomCloseDialogInfo:

package
de.cib.view.modules;
 
/**
 * Interface describing the data structure for custom close dialog
 * with information to form and sign fields.
 *
 */
public interface CustomCloseDialogInfo {
 
      /**
       * Returns whether the form is changed or not
       * @return boolean flag
       */
      boolean isFormChanged();
     
      /**
       * Gets the unsigned mandatory field count
       * @return number of unsigned mandatory fields
       */
      int getUnsignedMandatorySignatureCount();
     
      /**
       * Gets the unsigned optional field count
       * @return number of unsigned optional fields
       */
      int getUnsignedOptionalSignatureCount();
}

 

Das Interface CustomCloseDialogCallback ist im CIB jView (package de.cib.view.modules) definiert und umfasst folgende Methoden.

Interface CustomCloseDialogCallback:

package
de.cib.view.modules;
 
/**
 * Interface defining the callback for custom close dialog
 *
 */
public interface CustomCloseDialogCallback {
           
      /**
       * Method showCustomCloseDialog
       * @param customCloseDialogInfo interface to read form&sign data
       * @return returnCode of CustomCloseDialog
       *  0 - Yes
       *  1 - No
       *  2 - Cancel
       */
      public int showCustomCloseDialog(
CustomCloseDialogInfo customCloseDialogInfo);
 
}

 

Der Aufrufer muss sich dazu bei der JView-Instanz als Listener anmelden, dazu ein Code-Beispiel:

//
register CustomCloseDialogCallback
viewer.setCustomCloseDialogCallback(new CustomCloseDialogCallback() {
      @Override
      public int showCustomCloseDialog(
CustomCloseDialogInfo customCloseDialog) {
            int unsignedMandatoryCount = customCloseDialog
            .getUnsignedMandatorySignatureCount();
            int unsignedOptionalCount = customCloseDialog
.getUnsignedOptionalSignatureCount();
            int unsignedSignatureCount = unsignedMandatoryCount
                  + unsignedOptionalCount;
            String message = "";
            if (customCloseDialog.isFormChanged())
                  message = "Das Dokument enthält Änderungen an Formularfeldern, die noch nicht gespeichert wurden.";
 
            if (unsignedSignatureCount > 0) {
                  if (!message.isEmpty())
                        message += "\n";
                  message += "Das Dokument enthält noch %1 zu signierende(s) Feld(er), %2 Pflicht- und %3 optionale Feld(er).";
                  message = message.replaceFirst("%1",
                  String.valueOf(unsignedSignatureCount));
                  String.valueOf(unsignedSignatureCount));
                  message = message.replaceFirst("%2",                   String.valueOf(unsignedMandatoryCount));
                  message = message.replaceFirst("%3",                   String.valueOf(unsignedOptionalCount));
            }
            if (message.isEmpty())
                  return JCibOptionPane.YES_OPTION;
 
            message += "\nMöchten Sie die Bearbeitung trotzdem beenden?";
            return JCibOptionPane.showYesNoDialog(                   viewer, message,"Rückfrage"));
      }
});

  

Methode zur Abfrage des Rückgabewerts beim Beenden-Dialog:

In der Viewer-Instanz (Klasse JCibView) ist die Methode getCloseAction() verfügbar, die den Rückgabewert des Beenden-Dialogs liefert.

int closeDialogButton = viewer.getCloseAction();

Mögliche Werte (siehe auch CustomCloseDialogCallback):

 0 – Ja
 1 – Nein
 2 – Abbrechen
-1 – Vorbelegung (Dialog wurde nicht geöffnet)

Code-Beispiel für die Abfrage des gedrückten Buttons nach dem Beenden im Exit-Hook:

viewer.setExitHook(new Runnable() {
      public void run() {
            // do post processing here
            viewer.stop();
            // unregister FormFieldCallback Listener
      viewer.setFormFieldCallback(null);
            // Unregister SignFieldCallback Listener
      viewer.setSignFieldCallback(null);
 
            int closeDialogButton = viewer.getCloseAction();
            System.out.println("The following button was pressed in the close dialog: " + closeDialogButton);
      } });


Einbindung in eine Java SWT-Applikation

Um JCibView in eine SWT-Applikation zu integrieren, müssen einige Besonderheiten beachtet werden. JCibView muss in einen AWT-Frame eingebettet werden, der als oberstes Objekt eine Instanz von RootPaneContainer (z.B. JApplet) enthält. In diesen RootPaneContainer werden dann alle weiteren Komponenten eingefügt.

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Frame;
 
import javax.swing.JApplet;
import javax.swing.SwingUtilities;
 
import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
 
import de.cib.gui.framework.ICibApplication;
import de.cib.view.JCibView;
 
public class JViewInSWT {
 
      public static final String TEST_FILENAME = "c://tmp//testdoc.rtf";
 
      public static void main(String[] args)
      {
            final Display display = new Display();
            final Shell shell = new Shell(display);
            shell.setLayout(new FillLayout());
            shell.setText("Shell for JView integriert in SWT");
            Composite composite = new Composite(shell, SWT.NO_BACKGROUND
                  | SWT.EMBEDDED);
           
            /*
             * Set a Windows specific AWT property that prevents
             * heavyweight components from erasing their background.
             * Note that this is a global property and cannot be scoped.
             * It might not be suitable for your application.
             */
            try {
                System.setProperty("sun.awt.noerasebackground", "true");
            }
            catch (NoSuchMethodError error) {
            }
           
            /* Create and set up frame */
            // Use an embedded frame for SWT/AWT integration
            Frame frame = SWT_AWT.new_Frame(composite);
            final JCibView viewer = new JCibView(frame);
           
            // SWT/AWT needs a RootPaneContainer as intermediate object,
            // for example a JApplet object.
            JApplet applet = new JApplet();
            frame.add(applet);
           
            // Get content pane from the applet
            Container contentPane = applet.getContentPane();
            contentPane.setLayout(new BorderLayout());
      contentPane.add(viewer.getJMenuBar(), BorderLayout.NORTH);
            contentPane.add(viewer, BorderLayout.CENTER);
            contentPane.setVisible(true);
           
            frame.pack();
            frame.setVisible(true);
 
            viewer.setVisible(true);
 
            // Set input file (optional)
      viewer.setProperty(ICibApplication.PROPERTY_INPUTFILE,                               TEST_FILENAME);
      viewer.setProperty(ICibApplication.PROPERTY_TITLE,                   "CIB JView integriert in SWT");
           
            viewer.start();
            viewer.load();
           
            shell.open();
           
            // Grab focus after shell open using invokeLater
           SwingUtilities.invokeLater(new Runnable()
            {
                  public void run()
                  {
                        viewer.grabFocus();
                  }
            });
           
            while (!shell.isDisposed()) {
                  if (!display.readAndDispatch())
                        display.sleep();
            }
           
            display.dispose();
      }
}