Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Select All + Arrange All
Select All + Arrange All [message #178568] Fri, 21 March 2008 10:26 Go to next message
Sandip is currently offline SandipFriend
Messages: 39
Registered: July 2009
Member
Hi Team,

I have a situation here. Intention is to fire a command that selects
editparts in the active editor and perform arrange all.

For select all I am using -

IDiagramGraphicalViewer viewer = ((IDiagramWorkbenchPart)
ViewHelper.getInstance().getActiveEditorPart().getSite().get Part()).getDiagramGraphicalViewer();

if (viewer != null) {
//listEditPart is the list of editparts (nodes and edges) under current
diagram
if (!listEditPart.isEmpty()) {
viewer.setSelection(new StructuredSelection(listEditPart));

}
}
-This works fine.



For Arrange All I am using -

ArrangeRequest arrangeRequest = new
ArangeRequest(ActionIds.ACTION_ARRANGE_ALL);

arrangeRequest.setPartsToArrange(listEditPart);

DiagramDocumentEditor diagramEditor = (DiagramDocumentEditor)
ViewHelper.getInstance().getActiveEditorPart();


CompoundCommand cc1 = new CompoundCommand("Arrange All");

Command command1 =
diagramEditor.getDiagramEditPart().getCommand(arrangeRequest );
cc1.add(command1);

diagramEditor.getDiagramEditDomain().getDiagramCommandStack( )
.execute(cc1, new NullProgressMonitor());

diagramEditor.getDiagramEditPart().refresh();


Although It selects correctly, it doesnt perform the arrange all operation
as we see from the menu action.

Any idea why?
Re: Select All + Arrange All [message #178871 is a reply to message #178568] Tue, 25 March 2008 09:00 Go to previous messageGo to next message
Sandip is currently offline SandipFriend
Messages: 39
Registered: July 2009
Member
I found that Arrange All is arranging the selection, but only considering
the outermost object. Its behaving as if I have only selected the
outermost shape, and not done "Select All Shape" action.
Re: Select All + Arrange All [solved] [message #179468 is a reply to message #178871] Fri, 28 March 2008 06:13 Go to previous messageGo to next message
Sandip is currently offline SandipFriend
Messages: 39
Registered: July 2009
Member
Hi Guys,

The following code seems to work. Have an initial look. I will refactor
this a bit and update later

IDiagramGraphicalViewer viewer = ((IDiagramWorkbenchPart)
ViewHelper.getInstance().getActiveEditorPart().getSite().get Part())
getDiagramGraphicalViewer();

//Set the focus to the diagram editor
diagramEditor.setFocus();

//Sets the correct newly added elements as selected components.
// listEditPart is a list of editParts we want to select and arrange
if (viewer != null) {
if (!listEditPart.isEmpty()) {
viewer.setSelection(new StructuredSelection(listEditPart));
}
}

//Ensure that the focus shifts back to the DiagramEditor,
diagramEditor.getDiagramEditPart().setFocus(true); diagramEditor.getEditorSite().getPage().activate(diagramEdit or.getSite().getPart());

//Arrange The selected components.
//Two times running the action give better layout
ArrangeAction arrange =
ArrangeAction.createArrangeAllAction(diagramEditor.getEditor Site().getPage());

arrange.init();
arrange.setActionDefinitionId(ActionIds.ACTION_ARRANGE_ALL);
arrange.setup();

arrange.run( new SubProgressMonitor(monitor, 100));
arrange.run( new SubProgressMonitor(monitor, 100));

//Deselects newly added elements
if (viewer != null) {
viewer.select(diagramEditor.getDiagramEditPart());
}
Re: Select All + Arrange All [solved] [message #179500 is a reply to message #179468] Fri, 28 March 2008 08:36 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: trommas.yahoo.com

I tried your code, but this ArrangeAction class - where does it come
from? Is it a custom class? (also what is ViewHelper?)

Why not use ArrangeRequest?

I do this with:

ArrangeRequest arrangeRequest = new ArrangeRequest(
RequestConstants.REQ_ARRANGE_DEFERRED);

arrangeRequest.setViewAdaptersToArrange(editList);

selectedElement.getDiagramEditDomain().getDiagramCommandStac k().
execute(selectedElement.getCommand(arrangeRequest));


Cheers,

Tomas Zijdemans


Sandip wrote:
> Hi Guys,
> The following code seems to work. Have an initial look. I will refactor
> this a bit and update later
>
> IDiagramGraphicalViewer viewer = ((IDiagramWorkbenchPart)
> ViewHelper.getInstance().getActiveEditorPart().getSite().get Part())
> getDiagramGraphicalViewer();
>
> //Set the focus to the diagram editor
> diagramEditor.setFocus();
>
> //Sets the correct newly added elements as selected components.
> // listEditPart is a list of editParts we want to select and arrange
> if (viewer != null) {
> if (!listEditPart.isEmpty()) {
> viewer.setSelection(new
> StructuredSelection(listEditPart));
> }
> }
>
> //Ensure that the focus shifts back to the DiagramEditor,
> diagramEditor.getDiagramEditPart().setFocus(true);
> diagramEditor.getEditorSite().getPage().activate(diagramEdit or.getSite().getPart());
>
>
> //Arrange The selected components. //Two times running the action give
> better layout
> ArrangeAction arrange =
> ArrangeAction.createArrangeAllAction(diagramEditor.getEditor Site().getPage());
>
>
> arrange.init();
> arrange.setActionDefinitionId(ActionIds.ACTION_ARRANGE_ALL);
> arrange.setup();
>
> arrange.run( new SubProgressMonitor(monitor, 100));
> arrange.run( new SubProgressMonitor(monitor, 100));
>
> //Deselects newly added elements if (viewer != null) {
> viewer.select(diagramEditor.getDiagramEditPart());
> }
>
Re: Select All + Arrange All [solved] [message #179546 is a reply to message #179500] Fri, 28 March 2008 09:13 Go to previous messageGo to next message
Sandip is currently offline SandipFriend
Messages: 39
Registered: July 2009
Member
Hi Tomas,

We already tried that piece of code. Didnt seem to solve our purpose where
we need to rearrange inner components and connections.

Later we moved to ArrangeAction from
org.eclipse.gmf.runtime.diagram.ui.actions and it seem to work fine.
Re: Select All + Arrange All [solved] [message #179678 is a reply to message #179546] Fri, 28 March 2008 14:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: trommas.yahoo.com

Sandip wrote:
>
> Hi Tomas,
>
> We already tried that piece of code. Didnt seem to solve our purpose
> where we need to rearrange inner components and connections.
> Later we moved to ArrangeAction from
> org.eclipse.gmf.runtime.diagram.ui.actions and it seem to work fine.

Ok.. I don't have that class in my package, so I guess you subclassed:

org.eclipse.gmf.runtime.diagram.ui.actions.DiagramAction.
Re: Select All + Arrange All [solved] [message #180401 is a reply to message #179468] Wed, 02 April 2008 11:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: marsha.rohrer.swisscom.com

Hi Sandip,

Maybe a bit a silly question...but in which method did you add your code
extracts?

Thanks,
Marsha
Re: Select All + Arrange All [solved] [message #180409 is a reply to message #180401] Wed, 02 April 2008 12:16 Go to previous messageGo to next message
Sandip is currently offline SandipFriend
Messages: 39
Registered: July 2009
Member
Hi Marsha, I do not have a specific place to put this code. I have a
wizard from where I am adding few domain components in the diagram. The
intention was to auto arrange the editparts that got newly created. You
shud b able to run it from whereever you want. Ensure you have the list of
editparts and your active editor. Rest the code can help you.
Re: Select All + Arrange All [solved] [message #180438 is a reply to message #180409] Wed, 02 April 2008 13:51 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: marsha.rohrer.swisscom.com

Hi,

Ok...I was asking because I can't find the ViewHelper you are using....

Marsha
Re: Select All + Arrange All [message #184611 is a reply to message #178568] Mon, 28 April 2008 19:56 Go to previous message
Eclipse UserFriend
Originally posted by: birar01.ca.com

In case this is helpful to anyone:

I wanted to kick off an arrange all when the editor is started. I added the
following code to the generated DiagramEditor:

protected void initializeGraphicalViewerContents() {

super.initializeGraphicalViewerContents();


ArrangeRequest arrangeRequest = new
ArrangeRequest(ActionIds.ACTION_ARRANGE_ALL);

IGraphicalEditPart rootEP = (IGraphicalEditPart)
getDiagramGraphicalViewer().getRootEditPart().getContents();


List l = new ArrayList();

l.add(rootEP);


arrangeRequest.setPartsToArrange(l);


Command cmd = rootEP.getCommand(arrangeRequest);


getCommandStack().execute(cmd);

}





"Sandip" <sandip.b@in.bosch.com> wrote in message
news:6af76885b722de035e420af80ec3a31f$1@www.eclipse.org...
>
> Hi Team,
>
> I have a situation here. Intention is to fire a command that selects
> editparts in the active editor and perform arrange all.
>
> For select all I am using -
> IDiagramGraphicalViewer viewer = ((IDiagramWorkbenchPart)
> ViewHelper.getInstance().getActiveEditorPart().getSite().get Part()).getDiagramGraphicalViewer();
>
> if (viewer != null) { //listEditPart is the list of editparts (nodes and
> edges) under current diagram
> if (!listEditPart.isEmpty()) {
> viewer.setSelection(new StructuredSelection(listEditPart));
>
> }
> }
> -This works fine.
>
>
>
> For Arrange All I am using -
> ArrangeRequest arrangeRequest = new
> ArangeRequest(ActionIds.ACTION_ARRANGE_ALL);
>
> arrangeRequest.setPartsToArrange(listEditPart);
>
> DiagramDocumentEditor diagramEditor = (DiagramDocumentEditor)
> ViewHelper.getInstance().getActiveEditorPart();
>
>
> CompoundCommand cc1 = new CompoundCommand("Arrange All");
>
> Command command1 =
> diagramEditor.getDiagramEditPart().getCommand(arrangeRequest );
> cc1.add(command1);
>
> diagramEditor.getDiagramEditDomain().getDiagramCommandStack( )
> .execute(cc1, new NullProgressMonitor());
>
> diagramEditor.getDiagramEditPart().refresh();
>
>
> Although It selects correctly, it doesnt perform the arrange all operation
> as we see from the menu action.
> Any idea why?
>
>
>
>
>
Previous Topic:persisted edges
Next Topic:Hidden connections still displayed
Goto Forum:
  


Current Time: Thu Apr 25 05:40:07 GMT 2024

Powered by FUDForum. Page generated in 0.48797 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top