lock [Solved] Plugin Usage

7 years 11 months ago #754 by fpo
App.getInstance().getWorkspace().refreshProjects();
should work just fine since it is what we use when creating a new project or importing one in the workspace... Only problem I can think of for the refresh not happening is this not being called in the Display thread (but then you should probably get a InvalidThreadAccessException or something...)
Do you get any exception, or does the view just not refresh?
The topic has been locked.
7 years 11 months ago #755 by mersa
that's the weird thing about it. I'donĀ“t get any exception. everything seems just fine, except that there is no refresh
The topic has been locked.
7 years 11 months ago #756 by mersa
mmmh, it looks okay in debug mode. And you're right.
App.getInstance().getWorkspace().refreshProjects();

is the same way, the workspace is used in the modelio source.
I'll still need some debugging to find the problem..
The topic has been locked.
7 years 11 months ago - 7 years 11 months ago #757 by mersa
Ok, let me give you some result..

There seems to be a problem in the refreshProjects method. My project is added to the validprojects, but in the end the view is null.
private void updateNavigatorView() {
        WorkspaceNavigatorView view = getNavigatorView();
        if (view != null) {
            view.getCommonViewer().refresh();
        }
    }

let me take a look on getNavigatorView() to figure out the exact problem

Edit:
This part never finds equality(in getNavigatorView()):
for (IViewReference viewReference : viewReferences) {
            if ("com.modeliosoft.modelio.app.WorkspaceNavigatorViewID".equals(viewReference.getId())) {
                return (WorkspaceNavigatorView) viewReference.getView(false);
            }

Any Ideas?

Edit2: Maybe again the environment we are talking about: I'm using a module and call the method 'App.getInstance().getWorkspace().refreshProjects();' in it. Shouldn't we expect that there is no valid id in this case?
The topic has been locked.
7 years 11 months ago - 7 years 11 months ago #762 by fpo
Looking at the code, it seems to me that the problem is that the workspace view is not visible at the time you call #refreshProjects: getNavigatorView() returns null because the workspace view cannot be found among the view references of the active page (= the list of the IDs of all views visible on the active workbench page).

I tried another scenario and indeed reproduced that bug. This will need some fixing on our side.
I guess you can workaround that by switching active perspective to the Workspace perspective before calling the refreshProject.
IWorkbench workbench = PlatformUI.getWorkbench();
if (workbench == null) {
    return;
}
IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage();
if (activePage == null) {
    return;
}
IPerspectiveDescriptor perspectiveDescriptor = workbench.getPerspectiveRegistry().findPerspectiveWithId("com.modeliosoft.modelio.app.WorkspaceNavigatorViewID");
if (perspectiveDescriptor != null) {
    activePage.setPerspective(perspectiveDescriptor);
}

Edit: ok, there is a better way actually that doesn't force you to switch perspective: add a IPartListener2 to the active page that will provoke the refresh only when the workspace view becomes visible.
Something like:
IWorkbench workbench = PlatformUI.getWorkbench();
if (workbench == null) {
    return;
}
IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
if (activeWorkbenchWindow == null) {
    return;
}
IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
if (activePage == null) {
    return;
}
activePage.addPartListener(new IPartListener2() {
@Override
    public void partVisible(IWorkbenchPartReference partRef) {
        if (partRef.getId().equals("com.modeliosoft.modelio.app.WorkspaceNavigatorViewID")) {
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().removePartListener(this);
            App.getInstance().getWorkspace().refreshProjects();
        }
    }
    @Override
    public void partOpened(IWorkbenchPartReference partRef) {
    }
    @Override
    public void partInputChanged(IWorkbenchPartReference partRef) {
    }
    @Override
    public void partHidden(IWorkbenchPartReference partRef) {
    }
    @Override
    public void partDeactivated(IWorkbenchPartReference partRef) {
    }
    @Override
    public void partClosed(IWorkbenchPartReference partRef) {
    }
    @Override
    public void partBroughtToTop(IWorkbenchPartReference partRef) {
    }
    @Override
    public void partActivated(IWorkbenchPartReference partRef) {
    }
});

This is more or less the way I will fix it in the binary, but you won't get that fix until next release or next patch.

Edit2: make sure you register that listener only once for all pending updates ;)
The topic has been locked.
7 years 11 months ago #766 by mersa
Hey,

thank you very much for your effort, both for the code and your explanations. Now, everything works as planned :)
I'm looking foward to see the xmi serialization in the api sometine and keep dealing with the modelio api until then.
The topic has been locked.
Moderators: tmachmaab
Time to create page: 0.082 seconds
^ Back to Top