Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Diagram Validation Decoration
Diagram Validation Decoration [message #979045] Sat, 10 November 2012 15:18 Go to next message
Rui Domingues is currently offline Rui DominguesFriend
Messages: 194
Registered: October 2010
Senior Member
With respect to showing model validation directly in diagrams I'm kind newbie.

Which ways do I have to decorate my diagram when something the metamodel+OCL+... doesn't allow ,is happening?

I'm using now DefaultToolBehaviorProvider#getDecorators to "indicate" when and where decoration must be placed, but I'm doing everything inside the method.

I want to separate or even use OCL and relate the constraints with diagram decoration.

Is there any way to do that? Can you point me some material / project.

Thanks in advance.

Rui Domingues


Re: Diagram Validation Decoration [message #981592 is a reply to message #979045] Mon, 12 November 2012 14:38 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Rui,

I don't have an example for that, but you might use EMF Validation to check
your model and create e.g. problem markers from it. Those markers could then
be used to add decorators to the diagram.

Not sure if that helps.

Michael
Re: Diagram Validation Decoration [message #1057748 is a reply to message #979045] Wed, 08 May 2013 14:24 Go to previous messageGo to next message
Mario Cortes is currently offline Mario CortesFriend
Messages: 3
Registered: March 2013
Junior Member
Hi Rui,

I'm interested to link Graphiti with OCL constraints. Did you finally managed to do that? And to add some decorators that relate OCL constraints?

In fact, I generated with EMF the Java Code corresponding to a very simple OCL constraint (it was tested using the Dynamic Creation Model in EMF).

But my doubt is how and when to link it with graphiti.
I was hoping that, that was aumatic (such the meta-model constraints that are evaluated at runtime when creating the graphiti graphical models), but ocl constraints do not seem to be taken into account when creating the model. How should this constraints should be verified in Graphiti?

I also tried EMF validation (I right click in the graphiti diagram and then Validate but no errors are shown even if the model do not respect the OCL constraints).

Thanks,

Mario
Re: Diagram Validation Decoration [message #1057751 is a reply to message #1057748] Wed, 08 May 2013 14:46 Go to previous messageGo to next message
Marek Jagielski is currently offline Marek JagielskiFriend
Messages: 97
Registered: April 2012
Member
Hi,
This is my code in getDecorators inspired by BPMN2 Modeler:

	private List<IDecorator> defaultDecorators(PictogramElement pe) {
		List<IDecorator> decorators = new ArrayList<IDecorator>();
		Object bo = getFeatureProvider().getBusinessObjectForPictogramElement(pe);

		int x_dec = -5;
		int y_dec = -5;

		ValidationStatusAdapter statusAdapter = (ValidationStatusAdapter) EcoreUtil.getRegisteredAdapter((EObject) bo, ValidationStatusAdapter.class);
		if(statusAdapter == null) return decorators;
		final IImageDecorator decorator;
		final IStatus status = statusAdapter.getValidationStatus();
		switch (status.getSeverity()) {
			case IStatus.INFO:    decorator = new ImageDecorator(IPlatformImageConstants.IMG_ECLIPSE_INFORMATION_TSK);	break;
		    case IStatus.WARNING: decorator = new ImageDecorator(IPlatformImageConstants.IMG_ECLIPSE_WARNING_TSK);      break;
		    case IStatus.ERROR:   decorator = new ImageDecorator(IPlatformImageConstants.IMG_ECLIPSE_ERROR_TSK);    	break;
		    default:              decorator = null;                                                                     break;
		}
		
		if (decorator != null) {
			decorator.setX(x_dec);
		    decorator.setY(y_dec);
		    decorator.setMessage(status.getMessage());
		    decorators.add(decorator);
		}
		return decorators;
	}


I am doing validation thanks to extentions
<extension point="org.eclipse.wst.validation.validatorV2">
<extension point="org.eclipse.emf.validation.constraintBindings">
<extension point="org.eclipse.emf.validation.constraintProviders">
<extension point="org.eclipse.emf.validation.validationListeners">
<extension point="org.eclipse.core.resources.markers">

For the example I send you to: https://git.eclipse.org/c/bpmn2-modeler/org.eclipse.bpmn2-modeler.git

Marek
Re: Diagram Validation Decoration [message #1057753 is a reply to message #1057751] Wed, 08 May 2013 14:54 Go to previous messageGo to next message
Marek Jagielski is currently offline Marek JagielskiFriend
Messages: 97
Registered: April 2012
Member
However,
In my case, I have still some issues in this subject:
+ Decorators are not showed immediately (you have to move any object), but this is problem described somewhere in forum;
+ I have problems with validation with projects with names with spaces. Problem is connected with encoding of EMF uris;
I have to spend more time to learn about validation, but if in meanwhile you will have similar problems and you know how to solve it let me know Wink
Marek
Re: Diagram Validation Decoration [message #1064023 is a reply to message #1057753] Mon, 17 June 2013 10:18 Go to previous message
Mario Cortes is currently offline Mario CortesFriend
Messages: 3
Registered: March 2013
Junior Member
Thanks for the answers!Thant gave me some clues!

I used the OCL plugin that permits to insert OCL constraints in the Ecore models:
http://help.eclipse.org/helios/index.jsp?topic=%2Forg.eclipse.ocl.doc%2Ftutorials%2Foclinecore%2FoclInEcoreTutorial.html

Then, I activate the option to generate the corresponding Java code from the EMF models.

That creates a Validator in the util folder (ChoreographyValidator) which contains a validate method. The latter includes a call to a method that validates the OCL constraint (validateParticipant_nullPlayedRoles).

Then, in the ToolBehaviorProvider within Graphiti, I include this code in the getDecorators method:

public IDecorator[] getDecorators(PictogramElement pe) {
		IFeatureProvider featureProvider = getFeatureProvider();
		Object bo = featureProvider.getBusinessObjectForPictogramElement(pe);
		
		
		if (bo instanceof Participant) {
			Participant participant = (Participant) bo;
			if (!ChoreographyValidator.INSTANCE.validateParticipant_nullPlayedRoles (participant, null, null)){
				IDecorator imageRenderingDecorator = new ImageDecorator(IPlatformImageConstants.IMG_ECLIPSE_INFORMATION_TSK);
				imageRenderingDecorator.setMessage("WARNING:"+ ChoreographyValidator.INSTANCE.PARTICIPANT__NULL_PLAYED_ROLES + ";"); //$NON-NLS-1$
				return new IDecorator[] { imageRenderingDecorator };
			}
			
		}
...


This creates the marker instantly when the ocl constraint is not respected. No need to move or update the graphical construct.
I neither need to use extensions. I just include a dependency to org.eclipse.ocl.examples.library.

Note that this was I little test. I need to improve the constraint system.
In addition, I had some problems with the OCL plugin (the CreateDynamicModel option do not worked as expected).

Cheers,

Mario

[Updated on: Mon, 17 June 2013 10:19]

Report message to a moderator

Previous Topic:Image is not displayed after reopen the plugin
Next Topic:How to keep active the model outline
Goto Forum:
  


Current Time: Thu Apr 25 16:24:20 GMT 2024

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

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

Back to the top