Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » How to save editor
How to save editor [message #632336] Tue, 12 October 2010 15:24 Go to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Hi guys,

my editor works with a model object which itself represents some data from a database.

I would like to save the changed model to the database, thus I override the doSave method in my editor. First I would like to open the ProgressMonitorDialog with the progress bar, then I woul like to show the busy indicator and do few things.
public void doSave(IProgressMonitor monitor) {
        final ProgressMonitorDialog pd = new ProgressMonitorDialog(RcpUtils.getWorkbenchShell());
        final IRunnableWithProgress runnable = new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask("Saving to the database...", IProgressMonitor.UNKNOWN);
                // This sleep represents saving to the database at this moment
                Thread.sleep(5000);
                monitor.done();
            }
        };
        try {
            pd.run(true, false, runnable);
        } catch (Exception e) {
            e.printStackTrace();
        }
        BusyIndicator.showWhile(Display.getDefault(), new Runnable() {
                  public void run() {
                        // This sleep represents an action with other editor
                        Thread.sleep(2000);
                        setDirty(false);
                    }
         });
}

The problem is, that busy indicator doesn't work properly. There in no busy indicator and all the UI is frozen. What do I wrong?
Re: How to save editor [message #634137 is a reply to message #632336] Wed, 20 October 2010 15:47 Go to previous messageGo to next message
Federico Gaule is currently offline Federico GauleFriend
Messages: 21
Registered: September 2010
Location: Buenos Aires, Argentina
Junior Member
I have tested your code and it works perfectly (Never got ui freezed).

How are you getting the activeShell ?
I do it calling

Activator.getDefault().getWorkbench().getActiveWorkbenchWind ow().getShell();

Regards.
fede
Re: How to save editor [message #634148 is a reply to message #634137] Wed, 20 October 2010 15:58 Go to previous message
Federico Gaule is currently offline Federico GauleFriend
Messages: 21
Registered: September 2010
Location: Buenos Aires, Argentina
Junior Member
BTW, instead of a progressMonitorDialog and a Runnable, you can (should) use a Job ( http://www.eclipse.org/articles/Article-Concurrency/jobs-api .html)

Regards
Previous Topic:Change the composite
Next Topic:Better way to update UI with a job
Goto Forum:
  


Current Time: Fri Apr 26 22:47:11 GMT 2024

Powered by FUDForum. Page generated in 0.03135 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top