javaeclipse-pluginmodelingeclipse-gmf

GMF - Compartment expand/collapse programmatically


I have a class called EntitiesContainer that holds multiple compartments.

What I did is basically, when you right click on the compartment or compartmentName to listen to this event through a double click listener that is applied to both the compartmentXEditpart and compartmentXNameEditpart.

Now, I would like to achieve something like expanding or collapsing this compartment based on the double click but I havent found any way to do this. How can I approach it through the EditPart of this compartment?

Also would it be possible to close all other compartments when one opens, and if so this has to be done with AddSemanticListeners-listenerFilters ?

Any clues will be appreciated.


Solution

  • To expand/collapse compartment you'd need to create ChangePropertyValueRequest, get the command for that request from your compartment editpart and then execute that command on the command stack (expand is a boolean):

        ChangePropertyValueRequest request = new ChangePropertyValueRequest(
        DiagramUIMessages.PropertyDescriptorFactory_CollapseCompartment,
        Properties.ID_COLLAPSED, expand);
            getDomain().getCommandStack().execute(command);
    

    Yes you could also open/close other compartments buy creating the same request and creating extra commands (exactly as shown above) for sibling compartment editparts. The only complication is that you'd have to find those sibling compartment editoarts in the editparts tree. Also once you have a number of these commands wrap them in the GEF's CompoundCommand or GMF's CompositeCommand such that a number of commands is executed as one command and undo/redo actions would treat this case correctly. (Have a look at org.eclipse.gmf.runtime.diagram.ui.internal.tools.CompartmentCollapseTracker)