Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » How to set the selection programmatically?
How to set the selection programmatically? [message #1408826] Sat, 16 August 2014 06:31 Go to next message
Al B is currently offline Al BFriend
Messages: 47
Registered: June 2012
Member
Is a possible to set the selection to a PictogramElement programmatically?
Re: How to set the selection programmatically? [message #1408982 is a reply to message #1408826] Sat, 16 August 2014 17:59 Go to previous messageGo to next message
Al B is currently offline Al BFriend
Messages: 47
Registered: June 2012
Member
I was vague with my original question. I basically want to know if there is a way to avoid the de-selection of the current element when the property that adds the diamond is checked or at least a way to re-select it back programmatically. See attached screencast.
Re: How to set the selection programmatically? [message #1409695 is a reply to message #1408982] Mon, 18 August 2014 19:06 Go to previous messageGo to next message
Marek Jagielski is currently offline Marek JagielskiFriend
Messages: 97
Registered: April 2012
Member
Note that in DefaultToolBehaviorProvider you have method getSelection. I don't know if it can be useful for you as in my case it is invoked only when I hover any shape. I use it to deselect labels:
	@Override public PictogramElement getSelection(PictogramElement originalPe, PictogramElement[] oldSelection) {
		if(oldSelection.length > 1) {
			List<PictogramElement> withoutLabels = new ArrayList<>();
			for(PictogramElement pe : oldSelection) {
				String labelProperty = Graphiti.getPeService().getPropertyValue(pe,	SicConstants.LABEL_PROPERTY);
				if (Boolean.parseBoolean(labelProperty)) continue;
				withoutLabels.add(pe);
			}
			PictogramElement[] withoutLabelsArray = new PictogramElement[withoutLabels.size()];
			withoutLabels.toArray(withoutLabelsArray);
			getDiagramTypeProvider().getDiagramBehavior().getDiagramContainer().selectPictogramElements(withoutLabelsArray);
		}
		return null;
	}
Re: How to set the selection programmatically? [message #1409727 is a reply to message #1409695] Mon, 18 August 2014 21:20 Go to previous messageGo to next message
Al B is currently offline Al BFriend
Messages: 47
Registered: June 2012
Member
Thanks Marek for your suggestion.

I was able to workaround this by using this call in my AbstractUpdateFeature::update() implementation.

getActiveEditor().getDiagramBehavior().setPictogramElementForSelection(containerShape);

The new attached screencast shows the result I wanted.

Cheers!
Re: How to set the selection programmatically? [message #1411052 is a reply to message #1408826] Fri, 22 August 2014 09:10 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
DiagramEditor offers a method selectPictogramElements that does exactly
that.

Michael
Re: How to set the selection programmatically? [message #1411170 is a reply to message #1411052] Fri, 22 August 2014 15:04 Go to previous messageGo to next message
Al B is currently offline Al BFriend
Messages: 47
Registered: June 2012
Member
I tried that, but it didn't work.

getActiveEditor().selectPictogramElements(new PictogramElement[] {containerShape});
Re: How to set the selection programmatically? [message #1412942 is a reply to message #1411170] Wed, 27 August 2014 11:58 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Hm, the passed container shape instance must exist on the diagram,
especially it must live in the same editing domain/resource set as the
editor uses. Maybe that is causing trouble here?

Michael
Re: How to set the selection programmatically? [message #1413050 is a reply to message #1412942] Wed, 27 August 2014 16:39 Go to previous messageGo to next message
Al B is currently offline Al BFriend
Messages: 47
Registered: June 2012
Member
Yes, all live in the same editing domain and resource set

ContainerShape containerShape = (ContainerShape) context.getPictogramElement();
EditorAssist.getActiveEditor().getDiagramBehavior().setPictogramElementForSelection(containerShape);
Goal goal = (Goal) getBusinessObjectForPictogramElement(containerShape);
		
Object a = EditorAssist.getActiveEditor().getEditingDomain();
Object c = TransactionUtils.getDomain(containerShape);
Object d = TransactionUtils.getDomain(goal);
		
if (a == c && c == d && a == d) {
   System.out.println("YES, they all have the same editing domain and resourse set");

[Updated on: Wed, 27 August 2014 16:39]

Report message to a moderator

Re: How to set the selection programmatically? [message #1413434 is a reply to message #1413050] Thu, 28 August 2014 13:57 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
In the below coding you call setPictogramElementForSelection, but I
recommended to use selectPictogramElements. Have you tried with that as
well? The first one just sets a member variable for later selection, while
the second one really does the selection.
Michael
Re: How to set the selection programmatically? [message #1413465 is a reply to message #1413434] Thu, 28 August 2014 15:40 Go to previous messageGo to next message
Al B is currently offline Al BFriend
Messages: 47
Registered: June 2012
Member
Yes, I tried with selectPictogramElements, but nothing gets selected. setPictogramElementForSelection works though.

Maybe I'm not calling selectPictogramElements from the right place. I'm calling them from the AbstractUpdateFeature::update(IUpdateContext context) method.

[Updated on: Thu, 28 August 2014 15:46]

Report message to a moderator

Re: How to set the selection programmatically? [message #1474961 is a reply to message #1413465] Sat, 15 November 2014 22:20 Go to previous message
Marek Jagielski is currently offline Marek JagielskiFriend
Messages: 97
Registered: April 2012
Member
I have just made selection in UpdateFeature.

	
        @Override
	public boolean update(IUpdateContext context) {
		if(!updateNeededChecked) 
			if(!this.updateNeeded(context).toBoolean()) return false;
		
		boolean updated = false;
		if(superUpdateNeeded) updated = updated | super.update(context);
		
		ContainerShape parent = (ContainerShape) context.getPictogramElement();
		Task be = (Task) getBusinessObjectForPictogramElement(parent);
		
		if(descUpdateNeeded)    updated = updated | descUpdate   (parent, be);
		if(inputsUpdateNeeded)  updated = updated | inputsUpdate (parent, be);
		if(outputsUpdateNeeded) updated = updated | outputsUpdate(parent, be);
		if(atomicUpdateNeeded)  updated = updated | atomicUpdate (parent, be);
		if(paramsUpdateNeeded)  updated = updated | paramsUpdate (parent, be);

		if(updated) {
			getDiagramBehavior().getDiagramContainer().selectPictogramElements(new PictogramElement[] {});
			getDiagramBehavior().getDiagramContainer().selectPictogramElements(new PictogramElement[] { parent });
		}
		
		return updated;
	}

I needed to reselect pictogram element to refresh properties tab.

Works correctly.

[Updated on: Sat, 15 November 2014 22:21]

Report message to a moderator

Previous Topic:Get an instance of IDiagramContainer from a programmatically created diagram
Next Topic:How to disable Ctrl+Z option
Goto Forum:
  


Current Time: Tue Mar 19 08:35:56 GMT 2024

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

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

Back to the top