getPartService() & Expand outline

A place for those developing Aptana plugins, scripts or extending the IDE to gather and discuss extending Studio beyond the standard features.

Moderator: Aptana Staff

getPartService() & Expand outline

Postby s1evedaniels » Thu Oct 02, 2008 10:00 am

Hi there,

I'm trying to use the getPartService to detect automatically expand the outline view whenever I open a document. (Doing this on activation because when I tried to expand the outline on the actual open event it fired too early before the document was actually open and affected the previously open document.)

My attempt is detailed here:

http://blogs.edgehill.ac.uk/webservices ... y-outline/

I thought this was all working perfectly. However today is a new day and I realise that getPartService isn't exactly working properly.
Once Aptana is loaded it appears to register the listener (verified by printing out notifications to the console). But non of the listener events fire at all. Once I open and modify the script (inserting a space anywhere) and save it, then it seems the getPartService listener is registered properly and all the events fire as expected.

Any help would be greatly appreciated.

Thanks
s1evedaniels
 
Posts: 2
Joined: Thu Oct 02, 2008 9:53 am

Postby klindsey » Thu Oct 02, 2008 6:27 pm

Hi Steve,

I was able to recreate what you are seeing and it turns out that the initial loading of the scripts at startup is not done on the UI thread. That means when you call IWorkbench.getActiveWorkbenchWindow(), you will get null which prevents you from registering your part listener. However, when you execute the script from the Scripts menu or view or when you make edits to that file, you are on the UI thread, which explains why that works when you run it that way.

I thought I had a solution for you using "runOnUIThread" off of global. That function takes another function which is run on the UI thread. Unfortunately, it runs that function asynchronously, so we don't have the return value before getPartService() exits. I've added sync and async versions of that function to Studio, but I'm not sure which release that will make it into (crossing my fingers for 1.2).

If you want to play around, here's what getPartService looks like now with a little extra error checking and some debugging statements:

Code: Select all
function getPartService()
{
    var workbench = Packages.org.eclipse.ui.PlatformUI.getWorkbench();
    var result = null;
   
    if (workbench)
    {
        var window = null;
       
        runOnUIThread(function() {
            window = workbench.getActiveWorkbenchWindow();

            if (window != null)
            {
                result = window.getPartService();
                out.println("result set to " + result);
            }
            else
            {
                out.println("window is not defined");
            }
        });
    }
    else
    {
        out.println("workbench is not defined");
    }
   
    out.println("getPartService() is returning " + result);
   
    return result;
}


You may be able to Thread.sleep until some flag is set inside the async call, but you'd probably have to check that you're not on the UI thread already.

-Kevin Lindsey
User avatar
klindsey
 
Posts: 81
Joined: Thu Jul 13, 2006 6:28 pm
Location: Fort Worth, TX

Postby klindsey » Fri Oct 03, 2008 3:43 pm

Just a quick FYI that the change I mentioned in my last post did make it into the 1.2 release candidate. Once that is available for download (soon), the code listed above should work as advertised.

Thanks,
Kevin
User avatar
klindsey
 
Posts: 81
Joined: Thu Jul 13, 2006 6:28 pm
Location: Fort Worth, TX

Postby s1evedaniels » Thu Oct 16, 2008 4:07 pm

Hi Kevin et al,

Just thought I'd confirm your post. Yes it works brilliantly!

I've documented my continued efforts and success here:

http://blogs.edgehill.ac.uk/webservices ... -monkeyed/

Thanks again!
s1evedaniels
 
Posts: 2
Joined: Thu Oct 02, 2008 9:53 am

Postby klindsey » Fri Oct 17, 2008 3:27 pm

Excellent and thanks for the post!

-Kevin Lindsey
User avatar
klindsey
 
Posts: 81
Joined: Thu Jul 13, 2006 6:28 pm
Location: Fort Worth, TX


Return to Customizing and Extending Studio