Hello,
I have try to use Eclipse SWT with a Seam-Application.
But sometimes, not every time, I receive an exception caused by:

SWTException: Invalid thread access 

Here the class use SWT:

  | package org.jboss.util;
  | 
  | import org.eclipse.swt.SWT;
  | import org.eclipse.swt.ole.win32.OleAutomation;
  | import org.eclipse.swt.ole.win32.OleClientSite;
  | import org.eclipse.swt.ole.win32.OleFrame;
  | import org.eclipse.swt.ole.win32.Variant;
  | import org.eclipse.swt.widgets.Display;
  | import org.eclipse.swt.widgets.Shell;
  | 
  | public class OLEaccess {
  |     
  |     private static Display display = new Display();
  |     public OLEaccess(){
  |     }
  |     public static int OUTLOOK_MAIL_ITEM = 0;
  | 
  |     
  | 
  |     private Shell shell = new Shell(display);
  | 
  |     private OleFrame frm = new OleFrame(shell, SWT.NONE);
  | 
  |     private OleClientSite site = new OleClientSite(frm, SWT.NONE, 
"Outlook.Application");
  | 
  |     private OleAutomation auto = new OleAutomation(site);
  |     
  |     private int[] GetNamespaceDispId = auto
  |     .getIDsOfNames(new String[] { "GetNamespace" });
  | 
  |     private Variant Namespace = auto.invoke(GetNamespaceDispId[0],
  |             new Variant[] { new Variant("MAPI") });
  |     
  |     private OleAutomation NamespaceAutomation = Namespace.getAutomation();
  |     
  |     private OleAutomation mailItemAutomation;
  |     
  | 
  |     public String send(String to, String subject, String bodyTxt) {
  |             int[] LogonDispId = NamespaceAutomation
  |             .getIDsOfNames(new String[] { "Logon" });
  |     
  |             int[] LogoffDispId = NamespaceAutomation
  |                     .getIDsOfNames(new String[] { "Logoff" });
  |             
  |             NamespaceAutomation.invoke(LogonDispId[0], new Variant[] {
  |                     new Variant("YOUR MAIL ACCOUNT"), new Variant("YOUR 
PASSWORD"),
  |                     new Variant(true), new Variant(true) });
  |             
  |             int[] CreateItemDispId = auto
  |                     .getIDsOfNames(new String[] { "CreateItem" });
  |             
  |             Variant mailItem = auto.invoke(CreateItemDispId[0],
  |                     new Variant[] { new Variant(OUTLOOK_MAIL_ITEM) });
  |             
  |             mailItemAutomation = mailItem.getAutomation();
  | 
  |             int[] ToPropertyDispId = mailItemAutomation
  |                             .getIDsOfNames(new String[] { "To" });
  | 
  |             mailItemAutomation.setProperty(ToPropertyDispId[0], new Variant(
  |                             "YOUR " +to));
  | 
  |             int[] SubjectPropertyDispId = mailItemAutomation
  |                             .getIDsOfNames(new String[] { "Subject" });
  | 
  |             mailItemAutomation
  |                             .setProperty(SubjectPropertyDispId[0], new 
Variant(
  |                                             subject +" "
  |                                                             + 
System.currentTimeMillis()));
  | 
  |             int[] BodyPropertyDispId = mailItemAutomation
  |                             .getIDsOfNames(new String[] { "Body" });
  | 
  |             mailItemAutomation.setProperty(BodyPropertyDispId[0], new 
Variant(
  |                             bodyTxt));
  | 
  |             int[] SendDispId = mailItemAutomation
  |                             .getIDsOfNames(new String[] { "Send" });
  | 
  |             mailItemAutomation.invoke(SendDispId[0]);
  | 
  |             NamespaceAutomation.invoke(LogoffDispId[0]);
  | 
  |             
  |             return "send";
  |     }
  |     
  |     public boolean dispose(){
  |             boolean rs = true;
  |             shell.dispose();
  | 
  |             auto.dispose();
  | 
  |             NamespaceAutomation.dispose();
  | 
  |             mailItemAutomation.dispose();
  | 
  |             site.deactivateInPlaceClient();
  |             site.dispose();
  | 
  |             frm.dispose();
  |             return rs;
  |     }
  | }
  | 

and the EJB

  | package org.jboss.business;
  | 
  | import java.io.Serializable;
  | 
  | import javax.ejb.Remove;
  | import javax.ejb.Stateful;
  | import javax.ejb.Stateless;
  | 
  | import org.jboss.seam.annotations.Name;
  | import org.jboss.seam.annotations.Scope;
  | import org.jboss.seam.annotations.Destroy;
  | import org.jboss.seam.ScopeType;
  | import org.jboss.util.OLEaccess;
  | 
  | @Stateful
  | @Name("outlookAccess")
  | @Scope(ScopeType.SESSION)
  | public class OutlookAccessAction implements OutlookAccess, Serializable {
  |     
  |     private OLEaccess ole = new OLEaccess();
  | 
  |     public String doAction()
  |     {
  |             ole.send("[EMAIL PROTECTED]", "Invoke SWT fom J2EE Webapp", 
"was langw wärt wird endlich gut");
  |             //ole.dispose();
  |             System.out.println("Action Called");
  |             return "success";
  |     }
  |     
  |     @Destroy @Remove                                                        
              
  |     public void destroy() {
  |             ole.dispose();
  |     }       
  | }
  | 
  | 

All swt dependencies are added to project.

Any idea?

Thanks
Andreas

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3978117#3978117

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3978117

_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to