Hi Mitk Users,

 

I found some code that does exactly what I needed - in order to split the
editors on different Part Stacks after I add a new editor. Part of the
problem is that the code I found is from Eclipse and is written in Java.

 

I was able to convert this code to run in MITK, however, the behavior is not
correct as I expected (this was probably due to guessing code
substitutions).

 

1) In order to use this code correctly I need to understand the relations
between:

 

            WorkbenchPage, WorkbenchPart, WorkbenchPartSite, PartPane,
LayoutPart, LayoutContainer, EditorSashContainer, and PartStack

 

Please send any documentation showing how to access the EditorSashContainer
moving through the other classes.

 

2) Here is the Eclipse Java code:

 

/**

 * Split the editor area if there is at least two editors in it.

 */

private void splitEditorArea() {

            IWorkbenchPage workbenchPage =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

            IWorkbenchPart part = workbenchPage.getActivePart();

            PartPane partPane = ((PartSite) part.getSite()).getPane();

            LayoutPart layoutPart = partPane.getPart();

 

            IEditorReference[] editorReferences =
workbenchPage.getEditorReferences();

            // Do it only if we have more that one editor

            if (editorReferences.length > 1) {

                        // Get PartPane that correspond to the active editor

                        PartPane currentEditorPartPane = ((PartSite)
workbenchPage.getActiveEditor().getSite()).getPane();

                        EditorSashContainer editorSashContainer = null;

                        ILayoutContainer rootLayoutContainer =
layoutPart.getContainer();

                        if (rootLayoutContainer instanceof LayoutPart) {

                                    ILayoutContainer cont = ((LayoutPart)
rootLayoutContainer).getContainer();

                                    if (cont instanceof EditorSashContainer)
{

                                                editorSashContainer =
((EditorSashContainer) cont);

                                    }

                        }

                        /*

                         * Create a new part stack (i.e. a workbook) to home
the

                         * currentEditorPartPane which hold the active
editor

                         */

                        PartStack newPart =
createStack(editorSashContainer);

                        editorSashContainer.stack(currentEditorPartPane,
newPart);

                        if (rootLayoutContainer instanceof LayoutPart) {

                                    ILayoutContainer cont = ((LayoutPart)
rootLayoutContainer).getContainer();

                                    if (cont instanceof PartSashContainer) {

                                                // "Split" the editor area
by adding the new part

                                                ((PartSashContainer)
cont).add(newPart);

                                    }

                        }

            }

}

 

3) Here is my converted code that compiles and runs:

 

void FusionFileOpenAction::splitEditorArea() 

{

            berry::IWorkbenchPage::Pointer workbenchPage =
m_Window->GetActivePage();

            berry::IWorkbenchPart::Pointer part =
workbenchPage->GetActivePart();

            berry::IWorkbenchPartSite::Pointer partSite = part->GetSite();

            berry::PartPane::Pointer partPane =
partSite.Cast<berry::PartSite>()->GetPane();

            berry::LayoutPart::Pointer layoutPart =
partPane->GetContainer().Cast<berry::LayoutPart>();

 

            std::list<berry::IEditorReference::Pointer> editorReferences =
workbenchPage->GetEditorReferences();

            // Do it only if we have more that one editor

            if ( editorReferences.size() > 1 ) 

            {

                        // Get PartPane that correspond to the active editor

                        partSite =
workbenchPage->GetActiveEditor()->GetSite();

                        berry::PartPane::Pointer currentEditorPartPane =
partSite.Cast<berry::PartSite>()->GetPane();

                        berry::EditorSashContainer::Pointer
editorSashContainer;

                        berry::ILayoutContainer::Pointer rootLayoutContainer
= layoutPart->GetContainer();

 

                        if (
rootLayoutContainer.Cast<berry::LayoutPart>().IsNotNull() ) 

                        {

                                    berry::ILayoutContainer::Pointer cont =
rootLayoutContainer.Cast<berry::LayoutPart>()->GetContainer();

                                    if (
cont.Cast<berry::EditorSashContainer>().IsNotNull() ) // ViewSashContainer?

                                    {

                                                editorSashContainer =
cont.Cast<berry::EditorSashContainer>();

                                    }

                        }

 

                        /*

                         * Create a new part stack (i.e. a workbook) to home
the

                         * currentEditorPartPane which hold the active
editor

                         */

                        berry::PartStack::Pointer newPart =
editorSashContainer->CreateStack();

                        editorSashContainer->Stack(currentEditorPartPane,
newPart);

                        if (
rootLayoutContainer.Cast<berry::LayoutPart>().IsNotNull() ) 

                        {

                                    berry::ILayoutContainer::Pointer cont =
rootLayoutContainer.Cast<berry::LayoutPart>()->GetContainer();

 

                                    if (
cont.Cast<berry::PartSashContainer>().IsNotNull() ) 

                                    {

                                                // "Split" the editor area
by adding the new part

 
cont.Cast<berry::PartSashContainer>()->Add(newPart);

                                    }

                        }

            }

}

 

5) In order to make the code compile, I had to change a getPart() to
GetContainer() (see first 2 bolded lines). The problem actually occurs in
the 3rd bolded line. Instead of acquiring an object of type
EditorSashContainer, I end up with an object of ViewSashContainer.

 

Please help provide general information as well as specific solutions. If I
can understand the architecture better, I can solve my own problems.

 

Sincerely,

Joe Giacomini

 

 


 

------------------------------------------------------------------------------
Create and publish websites with WebMatrix
Use the most popular FREE web apps or write code yourself; 
WebMatrix provides all the features you need to develop and 
publish your website. http://p.sf.net/sfu/ms-webmatrix-sf
_______________________________________________
mitk-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mitk-users

Reply via email to