Task #1297

RCP: 0.7.7, link the TBX initialization to theSWT ProgressDialog at start up

Added by Sebastien Jacquot about 4 years ago. Updated about 4 years ago.

Status:New Start date:04/02/2015
Priority:Normal Due date:
Assignee:- % Done:

0%

Category:Démarrage Spent time: -
Target version:TXM X.X

Description

Link the TBX initialization to the SWT ProgressDialog at start up.
At this moment, the progression bar of the dialog "Loading corpora" does not reflect the real tasks executed by the TBX (potentially problematic when having a lot of corpus and partitions).
A temporary workaround would be to switch ProgressDialog to "indeterminate" mode to show to the user that TXM is not hanging up.
A better solution would be to implement Observer pattern with a thread cyclically checking the TBX activity, e.g. numbers of corpus loaded, number of partitions created, and updating the progress bar every x ms or x seconds.

Solution 1

  • add an initialization level variable in org.txm.toolbox/src/java/org/txm/Toolbox.java
  • increment this level according to the steps of initialization, e.g.: 1 = loading properties, 2 = starting corpus engine, 2 = starting statistic engine, etc.
  • use this TBX level variable to update the IProgressMonitor state in org.txm.rcpapplication.ApplicationWorkbenchAdvisor.initializeUI(JobHandler)

History

#1 Updated by Sebastien Jacquot about 4 years ago

Some prototype working code dedicated to org.txm.rcpapplication.ApplicationWorkbenchAdvisor.initializeUI(JobHandler) inspired from the solution 1:

    Display.getDefault().syncExec(new Runnable() {
            @Override
            public void run() {
                try {

                    IProgressService service = PlatformUI.getWorkbench().getProgressService();
                    service.runInUI(service, new IRunnableWithProgress() {

                            @Override
                            public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {

                                monitor.beginTask("Initializing TXM Tool box", 200);

                                if (!Toolbox.isInitialized()) {
                                    try {

                                        new Thread(new Runnable() {
                                            @Override
                                            public void run() {
                                                try {
                                                    System.err.println("**************************************ApplicationWorkbenchAdvisor.initializeUI(...).new Runnable() {...}.run().new IRunnableWithProgress() {...}.run(...).new Runnable() {...}.run()");
//                                                    for(int i = 0; i < 999999999; i++) {
//                                                        
//                                                    }
                                                    Toolbox.initialize(getProperties());
                                                }
                                                catch(Exception e) {
                                                    // TODO Auto-generated catch block
                                                    e.printStackTrace();
                                                }
                                                // Initializes the charts SWT component provider
                                                Log.info(Messages.ApplicationWorkbenchAdvisor_87);
                                                Application.swtComponentProvider = SWTChartsComponentProvider.createChartsSWTComponentProvider(Toolbox.getChartsEngine());

                                            }
                                        }).start();

                                        int stepsLevel = 0;

                                        monitor.subTask("Loading properties");
                                        while(!Toolbox.isInitialized())    {
                                            //System.err.println("ApplicationWorkbenchAdvisor.initializeUI(...).new Runnable() {...}.run().new IRunnableWithProgress() {...}.run(...).new Runnable() {...}.run()");

                                            monitor.worked(1);

                                            // Properties loading terminated
                                            if(!Toolbox.getProperties().isEmpty() && stepsLevel < 1)    {
                                                stepsLevel++;
                                                monitor.subTask("Starting Corpus Engine");
                                            }
                                            else if(Toolbox.isSearchEngineInitialized() && stepsLevel < 2)    {
                                                stepsLevel++;
                                                monitor.subTask("Starting Statistic Engine");
                                            }
                                            else if(Toolbox.isStatEngineInitialized() && stepsLevel < 3)    {
                                                stepsLevel++;
                                                monitor.subTask("Loading corpora");
                                            }
                                            else if(stepsLevel == 3)    {
                                                monitor.subTask("Loading corpora: " + CorpusManager.getCorpusManager().getCorpora().get(0).getName());
                                            }

                                            //Display.getDefault().readAndDispatch();
//                                            Display.getDefault().getActiveShell().redraw();
                                            try {
                                                Thread.sleep(100);
                                            }
                                            catch(InterruptedException e) {
                                                // TODO Auto-generated catch block
                                                e.printStackTrace();
                                            }
                                        }
                                    }
                                    catch (Exception e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                    }
                                }

                                monitor.done(); 
                            }
                        }, ResourcesPlugin.getWorkspace().getRoot());

                }
                catch(InvocationTargetException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                catch(InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }); 

Also see PlatformUI.getWorkbench().getProgressService().busyCursorWhile();

#2 Updated by Sebastien Jacquot about 4 years ago

  • Description updated (diff)

Also available in: Atom PDF