Word OLE : WIN32 « SWT JFace Eclipse « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » SWT JFace Eclipse » WIN32Screenshots 
Word OLE
Word OLE


/*******************************************************************************
 * All Right Reserved. Copyright (c) 1998, 2004 Jackwind Li Guojie
 
 * Created on 2004-6-21 18:48:57 by JACK $Id$
 *  
 ******************************************************************************/



import java.io.File;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.ole.win32.OLE;
import org.eclipse.swt.ole.win32.OleAutomation;
import org.eclipse.swt.ole.win32.OleClientSite;
import org.eclipse.swt.ole.win32.OleControlSite;
import org.eclipse.swt.ole.win32.OleFrame;
import org.eclipse.swt.ole.win32.Variant;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;

public class WordOLE extends ApplicationWindow {
  OleFrame oleFrame;
  OleClientSite clientSite;
  OleControlSite controlSite;

  /**
   @param parentShell
   */
  public WordOLE(Shell parentShell) {
    super(parentShell);

    addMenuBar();
    addToolBar(SWT.FLAT);
  }

  /*
   * (non-Javadoc)
   
   * @see org.eclipse.jface.window.Window#createContents(org.eclipse.swt.widgets.Composite)
   */
  protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NULL);
    composite.setLayout(new FillLayout());

    oleFrame = new OleFrame(composite, SWT.NULL);

    if (getMenuBarManager() != null) {
      MenuItem windowMenu =
        new MenuItem(getMenuBarManager().getMenu(), SWT.CASCADE);
      windowMenu.setText("[Window]");

      MenuItem containerMenu =
        new MenuItem(getMenuBarManager().getMenu(), SWT.CASCADE);
      containerMenu.setText("[Container]");

      MenuItem fileMenu =
        new MenuItem(getMenuBarManager().getMenu(), SWT.CASCADE);
      fileMenu.setText("[File]");

      oleFrame.setWindowMenus(new MenuItem[] { windowMenu });
      oleFrame.setContainerMenus(new MenuItem[] { containerMenu });
      oleFrame.setFileMenus(new MenuItem[] { fileMenu });

      System.out.println("menu set");
    }

    clientSite =
      new OleClientSite(oleFrame, SWT.NULL, new File("test.doc"));
    // clientSite = new OleClientSite(oleFrame, SWT.NONE,
    // "Word.Document.8");

    //   clientSite = new OleControlSite(oleFrame, SWT.NONE,
    //   "Word.Document.8");

    System.out.println(clientSite.getProgramID() ", " + clientSite);
    clientSite.doVerb(OLE.OLEIVERB_SHOW);

    return composite;
  }

  /*
   * (non-Javadoc)
   
   * @see org.eclipse.jface.window.ApplicationWindow#createToolBarManager(int)
   */
  protected ToolBarManager createToolBarManager(int style) {
    ToolBarManager manager = new ToolBarManager(style);

    Action actionSaveAs = new Action("Save as") {
      public void run() {
        FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
        String path = dialog.open();
        if (path != null) {
          if (clientSite.save(new File(path)false)) {
            System.out.println("Saved to file successfully.");
          else {
            System.err.println("Failed to save to file");
          }
        }
      }
    };

    Action actionDeactivate = new Action("Deactivate") {
      public void run() {
        clientSite.deactivateInPlaceClient();
      }
    };

    Action actionSpellCheck = new Action("Spell check") {
      public void run() {
        if ((clientSite.queryStatus(OLE.OLECMDID_SPELL)
          & OLE.OLECMDF_ENABLED)
          != 0) {
          clientSite.exec(
            OLE.OLECMDID_SPELL,
            OLE.OLECMDEXECOPT_PROMPTUSER,
            null,
            null);
        }
      }
    };

    Action actionOAGetSpellingChecked = new Action("OA: Get SpellingChecked") {
      public void run() {
        
        OleAutomation automation = new OleAutomation(clientSite);
        
        // looks up the ID for property SpellingChecked.
        int[] propertyIDs = automation.getIDsOfNames(new String[]{"SpellingChecked"});
        int propertyID = propertyIDs[0];
        
        Variant result = automation.getProperty(propertyID);
        System.out.println("SpellingChecked: " + result.getBoolean());
        
        automation.dispose();
      }
    };

    Action actionOASetSpellingChecked = new Action("OA: Set SpellingChecked") {
      public void run() {
        
        OleAutomation automation = new OleAutomation(clientSite);
        
        // looks up the ID for property SpellingChecked.
        int[] propertyIDs = automation.getIDsOfNames(new String[]{"SpellingChecked"});
        int propertyID = propertyIDs[0];
        
        boolean result = automation.setProperty(propertyID, new Variant(true));
        System.out.println(result ? "Successful" "Failed");
        
        automation.dispose();
      }
    };    
    
    Action actionOAInvokePrintPreview = new Action("OA: Invoke Select") {
      public void run() {
        OleAutomation automation = new OleAutomation(clientSite);
        
        // looks up the ID for method Select.
        int[] methodIDs = automation.getIDsOfNames(new String[]{"Select"});
        int methodID = methodIDs[0];
        
        Variant result = automation.invoke(methodID);
        System.out.println(result != null "Successful" "Failed");
        System.out.println(result);
        automation.dispose();
      }
    };    
    
    manager.add(actionSaveAs);
    manager.add(actionDeactivate);
    manager.add(actionSpellCheck);
    manager.add(actionOAGetSpellingChecked);
    manager.add(actionOASetSpellingChecked);
    manager.add(actionOAInvokePrintPreview);

    return manager;
  }

  public static void main(String[] args) {
    WordOLE wordOLE = new WordOLE(null);
    wordOLE.setBlockOnOpen(true);
    wordOLE.open();

    Display.getCurrent().dispose();
  }

}
           
       
Related examples in the same category
1. Invoke the system text editor on autoexec.bat
2. Place an icon with a popup menu on the system trayPlace an icon with a popup menu on the system tray
3. SWT Ole FrameSWT Ole Frame
4. OLE and ActiveX example snippet
5. Invoke an external batch fileInvoke an external batch file
6. Find the icon of the program that edits .bmp filesFind the icon of the program that edits .bmp files
7. Running a script within IE.Running a script within IE.
8. Reading and writing to a SAFEARRAY
9. Embed Word in an applet
10. OLE and ActiveX example: browse the typelibinfo for a program id
11. OLE and ActiveX example: get events from IE controlOLE and ActiveX example: get events from IE control
12. How to access About, Preferences and Quit menus on carbon
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.