Wooww !!
You can actually open files in their native application with the native application embedded within the applet (any frame).
Okay.. I wont talk much.. See for yourself. Do add the DLLs in c:\windows\system32.
Here is the code:
package test;
import java.applet.*;import java.awt.FileDialog;import java.io.File;
import javax.activation.FileDataSource;
import org.eclipse.swt.SWT;import org.eclipse.swt.events.FocusEvent;import org.eclipse.swt.events.FocusListener;import org.eclipse.swt.events.MouseEvent;import org.eclipse.swt.events.MouseMoveListener;import org.eclipse.swt.ole.win32.OLE;import org.eclipse.swt.ole.win32.OleClientSite;import org.eclipse.swt.widgets.Control; public class ole extends Applet { org.eclipse.swt.widgets.Display display; org.eclipse.swt.widgets.Shell swtParent; java.awt.Canvas awtParent;
public void init () { Thread thread = new Thread (new Runnable () { public void run () { setLayout(new java.awt.GridLayout (1, 1)); awtParent = new java.awt.Canvas (); add (awtParent); display = new org.eclipse.swt.widgets.Display (); swtParent = org.eclipse.swt.awt.SWT_AWT.new_Shell (display, awtParent); swtParent.setLayout (new org.eclipse.swt.layout.FillLayout ()); org.eclipse.swt.ole.win32.OleFrame frame = new org.eclipse.swt.ole.win32.OleFrame (swtParent, org.eclipse.swt.SWT.NULL); final org.eclipse.swt.ole.win32.OleClientSite site; try { //if(fd.getText()!=null && fd.getText().length() !=0){ site = new org.eclipse.swt.ole.win32.OleClientSite(frame, org.eclipse.swt.SWT.NULL, "c:\\a.xls"); site.doVerb(OLE.OLEIVERB_INPLACEACTIVATE); site.addMouseMoveListener(new MouseMoveListener(){
public void mouseMove(MouseEvent arg0) { site.forceFocus(); } }); site.addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { System.out.println("client1 focus gained: " + e); site.doVerb(OLE.OLEIVERB_INPLACEACTIVATE ); } public void focusLost(FocusEvent e) { System.out.println("client1 focus lost: " + e); site.deactivateInPlaceClient(); } }); //} } catch (org.eclipse.swt.SWTException e) { String str = "Create OleClientSite Error" + e.toString (); System.out.println (str); return; } setSize (800, 600);
validate (); while (swtParent != null && !swtParent.isDisposed ()) { if (!display.readAndDispatch ()) display.sleep (); } } }); thread.start (); try { thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); }} public void stop (){ if (display != null && !display.isDisposed ()){ display.syncExec(new Runnable () { public void run () { if (swtParent != null && !swtParent.isDisposed ()) swtParent.dispose (); swtParent = null; display.dispose (); display = null; } }); remove (awtParent); awtParent = null; } } }
Sorry for the garbage . Be sure to include the jar files (eclipse plug-ins folder)
-Ranijth