I'd like to propose the attached code be added as a method of the
WorkbenchContext class. I sometimes find myself with a need to access
the active TaskFrame for the Workbench, especially when I work on the
docking window integration. Perhaps others have found a need to do
this as well.

At any rate, any time I start to copy and paste code I get a little
nervous. This is usually a sign that I need to make a utility method.

If people think this change is a bad idea, I'll move the method to one
of my own OpenJUMP utility classes. If you have changes or
improvements to my implementation of the method, please let me know.
If there are no objections, I will commit a patch adding the method.

The Sunburned Surveyor
/**
* Returns the TaskFrame that for the "active" task. A task frame is considered 
to be "active"
* if its title matches the name of the task obtained from the plug-in contect 
passed as an
* argument to the method.
*/
public TaskFrame getTaskFrameForActiveTask(PlugInContext argPlugInContext)
{

        JUMPWorkbench jumpWorkbench = workbenchContext.getWorkbench();
        WorkbenchFrame frame = jumpWorkbench.getFrame();
                
        JInternalFrame[] internalFrames = frame.getInternalFrames();
                
        int arraySize = internalFrames.length;
        int counter = 0;
                
        while(counter < arraySize)
        {
                JInternalFrame toTest = internalFrames[counter];
                
                if(toTest instanceof TaskFrame == true)
                {
                        TaskFrame taskFrame = (TaskFrame) toTest;
                                
                        // Find the TaskFrame for the Task associated with the 
plug-in
                        // context given to this plug-in.
                        Task task = argPlugInContext.getTask();
                        String taskName = task.getName();
                                
                        String frameTitle = toTest.getTitle();
                                
                        if(frameTitle.equals(taskName) == true)
                        {
                                return toTest;
                        }
                }
        counter++;
        }
}
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to