0

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.

nmargaritis
  • 859
  • 7
  • 21

1 Answers1

1

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)

aboyko
  • 1,337
  • 1
  • 9
  • 11
  • thanks for the reply, where should the changePropertyValueRequest should be created? My listener is within the edit part. Also this the command you refer to ? `final Command cmd = myEditPart.getCommand(req); cmd.execute();` – nmargaritis Oct 24 '14 at 21:20
  • You can create the request just about anywhere you see fit - no restrictions on that. I suppose the somewhat tricky part would be finding the right editpart to get the command. You can execute the command via cmd.execute(), but then it's unlikely to be executed in an EMF transaction. I'd recommend getting a reference to the CommandStack and executing the command from it. – aboyko Oct 26 '14 at 16:07
  • Thanks, I managed to do it by calling from my xxxEditPart and xxxNameEditPart (inside the double click listeners) the xxxCompartmentEditPart method that I created called collapseCompartment which accepts a Boolean. The method per se is `public void collapseCompartment(booelan collapse) { ChangePropertyValueRequest request = new ChangePropertyValueRequest( DiagramUIMessages.PropertyDescriptorFactory_CollapseCompartment, Properties.ID_COLLAPSED, collapse); getEditDomain().getCommandStack().execute(getCommand(request)); } ` I accept your answer as a solution. – nmargaritis Oct 27 '14 at 12:46