Hello Everyone,
I have a trading application based on SWT and has many
application swt window objects that are opened for seeing quotes. I also added
Excel OLE component which is also opened through this application.
I constantly publish quote information to both excel and
another swt window and process events from excel. I am having some event
thread problems here,
Excel (OleFrame) is taking control of event thread most of
the time and not allowing other windows to paint their data, once I stop publishing
I can see painting on non-excel windows.
In the event handler method I have put all the logic
in Display.async() method and any read or write to Excel is also done in async thread.
Looks like too many events being triggered are forcing excel to take
control of the event thread often. If I delay the
quote by a sec I still see pause every second on non-excel windows.
Here’s the code snippets,
public class LaunchPadWindow extends ApplicationWindow {
//menu
option to open Excel
//menu
option to open another window
}
public class ExcelApplication
{
private final OleControlSite controlSite;
private final OleAutomation application;
private final OleAutomation workbooks;
private final OleAutomation workbook;
private final Shell shell;
public ExcelApplication(Shell shell) {
}
public void open(String file) {
Display display = Display.getCurrent();
shell = new Shell(display);
OleFrame
frame = new OleFrame(shell, SWT.NONE);
controlSite = new OleControlSite(frame, SWT.NONE, "Excel.Application");
controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);
OleAutomation
excelSheet = new OleAutomation(controlSite);
Variant
applicationVariant = excelSheet.getProperty(WORKBOOK_APPLICATION);
application = applicationVariant.getAutomation();
applicationVariant.dispose();
Variant
workbooksVariant = application.getProperty(APPLICATION_WORKBOOKS);
workbooks = workbooksVariant.getAutomation();
Variant[] arguments = new Variant[] { new Variant(new File(fileName).getPath()) };
Variant workbookVariant = workbooks.invoke(WORKBOOKS_OPEN, arguments);
if (workbookVariant == null) {
throw new IOException(String.format("Could not open workbook
'%s'", arguments[0].getString()));
}
else if (workbookVariant.getType() == OLE.VT_EMPTY) {
throw new IOException(String.format("Could not open workbook
'%s'",
arguments[0].getString()));
}
workbook
= workbookVariant.getAutomation();
application.setProperty(APPLICATION_VISIBLE, new Variant(true));
}
}
Please let me know any suggestion/comments/fix I can use to
solve this.
Thanks,
Suresh