How do I know the Perspective has completed loading?

How do I know the Perspective has completed loading?
control.load(name)
but load function return ,In fact, load not end.

How do I know the end ?

I’m sorry, my English is very bad.

Once the method has returned, nothing more will happen. If your layout does not load completely, then the error is at another place. Like not registering all necessary factories or dockables. Also make sure you load the correct layout (i.e. use the correct value for the “name” parameter).

no,Certainly not ,layout does not load completely.

this.control.load(name);
loadPerspectiveSelView(name);

Look at the implementation of loadPerspectiveSelView(name)

Object rs = SettingDataManager.readLocalSetting(name, String.class);
            if (rs != null) {
                final String className = rs.toString();
                for (int i = 0; i < control.getCDockableCount(); i++) {
                    final CDockable dock = control.getCDockable(i);
                    if (dock instanceof DockingViewWrapper) {
                        String cn = ((DockingViewWrapper) dock).getViewFunction().getClass().getName();
                        if (cn.equals(className)) {
                            Thread thread = new Thread() {

                                @Override
                                public void run() {
                                    try {
                                        Thread.sleep(100);
                                    } catch (InterruptedException e) {
                                    }
                                    SwingUtilities.invokeLater(new Runnable() {
                                        @Override
                                        public void run() {
                                            ((DockingViewWrapper) dock).setViewActive(true);
                                        }
                                    });
                                }
                            };
                            thread.start();
                            break;
                        }
                    }
                }
            }

if not Thread.sleep(100);,then not success set.

I had to sleep(100).

test:

@Override
                        public void run() {
                            int f = Integer.parseInt(fStr);
                            List<String> names = SystemManager.getSystemManager().getMainFrame().getAllPerspectiveNameList();
                            for (final String name : names) {
                                SwingUtilities.invokeLater(new Runnable() {
                                    @Override
                                    public void run() {
                                        SystemManager.getSystemManager().getMainFrame().setCurPerspective(name);
                                    }
                                });
                                
                                try {
                                    Thread.sleep(f);
                                } catch (Exception ex) {

                                }
                            }
                        }

setCurPerspective contain load,If “f” is the more likely the smaller problems.

Ah, you are speaking of focus. Yes, focus is delayed simply because in Swing focus handling is a bit… weird. Do you load the layout from the EDT or from some other thread? Because if you are not in the EDT, then the framework will call the EDT just to switch the focus. So there might be multi threading issues as well.

The framework internally has a queue of components that requested the focus and tries to make sure that the newest request is handled. It even may request the focus multiple times because Swing sometimes just ignores a focus request.

How is this “setViewActive” method implemented? What version of the framework are you using? If you are not focusing a Dockable it might be possible to call “control.getController().setFocusedDockable( dockable, componentToFocus, true )” directly and transfer the focus that way.

Btw. the framework tries to acquire focus up to 200 milliseconds after the initial request, but no longer.

create many Perspective, Perspective contains many Dockable, Dockable created by the createBackup.

then use for() test load, Observe MainFrame layout ,Sometimes layout abnormal,Tab draw very strange ,

How is this “setViewActive” method implemented?


DockingViewWrapper extends DefaultSingleCDockable
..................
this.toFront();

In fact, call toFront();

because the framework does not remember the Perspective focus ,so I saved.

If the user quickly switch perspective, and add new Dockable, even in EDT, or may be a problem.

My current solution is:

public void setCurPerspective(String p) {
        if (!p.equals(currentPerspectiveName)) {
            // lock ui 
            startInfiniteLock();
            listenLoadEnd();
            savePerspective_PL(currentPerspectiveName);
            loadPerspective_PL(p);
            currentPerspectiveName = p;
            saveCurrentPerspectiveName();
        }
    }

Look at the implementation of listenLoadEnd();

private void listenLoadEnd(){
        Thread lt = new Thread(){

            @Override
            public void run(){
                try {
                    Thread.sleep(1500);
                } catch (InterruptedException e) {
                }
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        //stop lock UI
                        stopInfiniteLock();
                    }
                });
            }
        };
        lt.start();
    }

I lock the UI, otherwise the user to quickly switch perspective, as well as when switch adding a new Dockable.but only sleep to implement.

Eclipse THEME , extension Glass, Version 1.1.1p5c

I understand the issue, but at the moment I cannot solve it. The “toFront” method should work, I do not exactly know why in this case it does not. I’ll keep this issue on the todo list, but at the moment I can only give you the advice either to ignore focus, or to use your workaround. Although 1500ms are a bit much, 200ms should be enough.

“toFront” is work,“setViewActive” use “toFront”.

because the framework does not remember the Perspective focus ,so I remember .then toFront,
As the problem of load end, I had to use the sleep method.Now, it seems can work.