[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.rcp] Re: timer and jasper

It should not sleep or loop in the action itself. Try getting the view to do the refresh. The action could set the refresh interval on the view. Using Display.timerExec should work, as long as it's called in the UI thread.

I also find it strange that your view is being opened in the action's constructor. I would expect it to be already opened by your perspective, or only opened when the user runs the action.
Also note that the workbench window is given to the action delegate (in IWorkbenchWindowActionDelegate.init). Using PlatformUI.getWorkbench().getActiveWorkbenchWindow() is discouraged.


Nick

udayms wrote:
Hi All,
I am still on war with getting jasper and swt working. :)

My latest issue is as follows. I want my report to reload every 50 seconds.

[code]

import net.sf.jasperreports.engine.JasperPrint;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
..

public class CSReportAction implements IWorkbenchWindowActionDelegate {
	CustomerInfo cusInfo = null;
	ReportView rv = null;
	
	
	/**
	 * The constructor.
	 */
	public CSReportAction() {
		try {
			rv = (ReportView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(ReportView.ID_REPORT_VIEW);
		} catch (PartInitException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * The action has been activated. The argument of the
	 * method represents the 'real' action sitting
	 * in the workbench UI.
	 * @see IWorkbenchWindowActionDelegate#run
	 */
	public void run(IAction action) {
		cusInfo = new CustomerInfo(new Shell(), SWT.NONE);
		cusInfo.open();
//		while(true)	{	
			
			System.out.println("Calling reports...");
			JasperPrint jprint = ReportGen.generateReport(cusInfo.getCustomerInfo());
			System.out.println("Passed Customer No -" + cusInfo.getCustomerInfo() + "- to the Jprint.");
			
			try {
				rv.getReportViewer().setDocument(jprint);
				System.out.println("JPrint object displayed in browser.");
				System.out.println("Reports done.");
				System.out.println("--------------------------------------------");
				
				
			} catch (Exception e) {
				e.printStackTrace();
			}
			
//			if(rv.getReportViewer().hasDocument()){
//
//			try {
//				synchronized(this){
//				wait(50000);
//				}
//			} catch (InterruptedException e) {
//				System.out.println("Error while waiting"+e);
//			}catch (Exception e1) {
//				System.out.println("Error while waiting2"+e1);
//
//			}
//			}
			

		
		
	}
	
	public void selectionChanged(IAction action, ISelection selection) {
	}
	
	public void dispose() {
	}
	
	public void init(IWorkbenchWindow window) {
		
	}
}
[/code]

What I trying to do here, when I click on a button, I take the customer id from the user and call the generatereport method, which returns me the jasperprint object. Now, I load the report using the getReportViewer.setDocument().

Now, I want this report to reload at specific intervals. So, I first used the timer methods. I got the message - 'not thread owner'. I presumed it was because, my timer method was starting another thread inside the main run() thread, which is not permitted. So, I tried using the simple wait(). This also isnt working.

Any idea? Anybody?

-Uday


--
View in EZ forum: http://www.eclipsezone.com/eclipse/forums/m91949405.html