Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Graphiti's missing features
Graphiti's missing features [message #1689409] Mon, 23 March 2015 14:20 Go to next message
Jerome S. is currently offline Jerome S.Friend
Messages: 9
Registered: March 2015
Junior Member
Dear Michael,

I am struggling with several functionalities that seem to be missing in Graphiti. Could you please tell me if there is a way to achieve them without hacking all the system? These functionalities are:


  • Do something when the user single-clicks on a shape. I would like to have a feature here to allow the user to select all shapes in a row with the shortcut "shift + click" that has not been implemented yet. With hacks I was thinking of using the method ToolBehaviorProvider#getSelectionInfoForShape() because it seems to be (the only one?) executed when the user clicks on a shape.
  • Treat moveShape as a SINGLE feature when several shapes are selected. Apparently this problem was already listed here: index.php?t=msg&th=488119&goto=1061837&#msg_1061837 but I haven't found any way to achieve my goal using the framework nor any bug filed in Bugzilla... I have found a dirty way to do it: I have a feature in "moveShape" that acts as a "moveShapes" feature and registers the time when it was executed. Then when it is called again and again on the other selected shapes that are moving, I check the current time and if it is less that a constant (100ms for example) I ignore the new move feature...


Besides I have found something weird in the framework: a lot of "get....Feature" are called several times instead of once. For example when I select a shape "getSelectionInfoForShape" is called 3 times, when I move a shape "getMoveShapeFeature" is called 4 times, etc. Is it a normal behavior?

Thank you in advance!
Best regards
Jérôme

[Updated on: Wed, 25 March 2015 10:29]

Report message to a moderator

Re: Graphiti's missing features [message #1690108 is a reply to message #1689409] Wed, 25 March 2015 10:15 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Jerome,

the single click is an easy one, there is a single click feature, similar to
the double click feature, see
http://help.eclipse.org/kepler/topic/org.eclipse.graphiti.doc/javadoc/org/eclipse/graphiti/tb/IToolBehaviorProvider.html#getSingleClickFeature(org.eclipse.graphiti.features.context.ISingleClickContext)

Regarding move of several shapes: that is currently not possible. Your trick
sounds really dirty, but I'm afraid there is currently no official means in
Graphiti to achieve that. And you have already seen the forum entry for
that, additionally there is an open enhancement bug:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=431651

Regarding the multiple call of get...Feature: that depends somewhat on the
structure of your diagram, especially with multi move. Without any further
issues I would consider that rather normal.

Michael
Re: Graphiti's missing features [message #1690112 is a reply to message #1690108] Wed, 25 March 2015 10:48 Go to previous message
Jerome S. is currently offline Jerome S.Friend
Messages: 9
Registered: March 2015
Junior Member
Michael,

Thanks for this reply, I was looking for a #getClickFeature in the toolBehaviorProvider and I didn't see the #getSingleClickFeature... Nevertheless this function doesn't fulfill all my needs because I do not have the keyboard context inside so I don't think I can know if the "SHIFT" key was down when the user clicked somewhere on the screen.

Indeed here is my implementation using a swt MouseAdapter on the main GraphicalViewer
graphicalViewer.getControl().addMouseListener(new MouseAdapter() {
	@Override
	public void mouseDown(MouseEvent me) {
		// Override default selection to select elements in the row
		// if the user presses shift+click
		else if ((me.stateMask & SWT.SHIFT) == SWT.SHIFT) {
			PictogramElement[] oldSelection = getSelectedPictogramElements();
			Arrays.sort(oldSelection, new Comparator<PictogramElement>() {
				
				@Override
				public int compare(PictogramElement p1, PictogramElement p2) {
					return p1.getGraphicsAlgorithm().getX() - p2.getGraphicsAlgorithm().getX();
				}
			});

			// As the selection is sorted, you can easily select all pictograms from selection.first to selection.last
			display.selectPictogramElementsInARow(oldSelection);
		}
	}
});


Regarding the multiple shapes move feature I have found a less dirty way to do it, the other idea was really really dirty. Here is an idea of the implementation that I did when I remarked that moveShape is called with the exact same deltaX() and deltaY() on all selected shapes that I am trying to move
(in the featureProvider called MyFeatureProvider)
private boolean lastTimeMoveCanExecute;
private IMoveShapeContext lastMoveShapeContext;

public void setLastTimeMoveCanExecute(boolean lastTimeMoveCanExecute) {
	this.lastTimeMoveCanExecute = lastTimeMoveCanExecute;
}

@Override
public IMoveShapeFeature getMoveShapeFeature(IMoveShapeContext context) {
	// Check if we are calling moveShape on multiple shapes that are moving
	// together. If yes, return the same result but with a move feature that
	// does nothing
	if (lastMoveShapeContext != null && context.getSourceContainer().equals(lastMoveShapeContext.getSourceContainer())
		&& context.getTargetContainer().equals(lastMoveShapeContext.getTargetContainer()) && context.getDeltaX() == lastMoveShapeContext.getDeltaX() && context.getDeltaY() == lastMoveShapeContext.getDeltaY()) {
		return new DefaultMoveShapeFeature(this) {
			@Override
			public boolean canMoveShape(IMoveShapeContext context) {
				return lastTimeMoveCanExecute;
			}

			@Override
			public void moveShape(IMoveShapeContext context) {
			}
		};
	}

	if (some_condition) {
		return new MyMoveFeature(this);
	}

	return return super.getMoveShapeFeature(context);
}

(in MyMoveFeature)
@Override
public boolean canMoveShape(IMoveShapeContext context) {
	MyFeatureProvider fp = (MyFeatureProvider) getFeatureProvider();
	
	// do stuff
	if (my_condition) {
		fp.setLastTimeMoveCanExecute(true);
		return true;
	} else {
		fp.setLastTimeMoveCanExecute(false);
		return false;
	}
}

@Override
public void moveShape(IMoveShapeContext context) {
	MyFeatureProvider fp = (MyFeatureProvider) getFeatureProvider();
	fp.setLastTimeMoveCanExecute(false);
	
	// do stuff
}


It's certainly not the best way to do it but I think it could be an acceptable workaround Smile.

PS. For the multiple call of get...Feature it seems that when I have a composed shape, for example a rectangle with several text shapes inside, the MoveShapeFeature is called once for each shape, causing all these calls. I think it would be better to have only one call for the "main" shape that is selected and moving.

[Updated on: Wed, 25 March 2015 10:58]

Report message to a moderator

Previous Topic:org.eclipse.graphiti.ui refactoring
Next Topic:Palette-Items Customize before/at Editor start
Goto Forum:
  


Current Time: Tue Mar 19 07:16:40 GMT 2024

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

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

Back to the top