compartment_nodes_persistence_fix [GMF Samples And Tutorials]
 
Table of Contents

Overview

When one build a diagram editor that automatically creates nodes into compartments, these nodes are not persisted until at least one node is connected to another node.

For example, on the diagram editor built in the 5th tutorial, if we create a new diagram, add a Plus operator into it, save it and close eclipse : when eclipe is re-opened, the Plus operator has lost its operator inputs and output :

Saved diagram :Re-opened diagram (operator inputs and output have disappeared):

If we simply add an Entry and connect it to our operator, this problem does not appear. When the input and output have been created, by default, GMF created it in a transcient state. The fact of connecting one node to another node (for example : the operator input to an entry) makes GMF turn it into persisted nodes.

Fix

To fix this, we must force the corresponding nodes to be persisted.

To do that, we just have to edit the java class XXXViewProvider of the xxx.diagram.providers package and localize the createNode method. Then we substitute the persisted variable by true for the nodes we want to be persisted by default.

If we take the diagram editor of the 5th tutorial, it gives :

	/**
	 * @generated NOT
	 */
	public Node createNode(IAdaptable semanticAdapter, View containerView,
			String semanticHint, int index, boolean persisted,
			PreferencesHint preferencesHint) {
		final EObject domainElement = getSemanticElement(semanticAdapter);
		final int visualID;
		if (semanticHint == null) {
			visualID = MathVisualIDRegistry.getNodeVisualID(containerView,
					domainElement);
		} else {
			visualID = MathVisualIDRegistry.getVisualID(semanticHint);
		}
		switch (visualID) {
		case ResultEditPart.VISUAL_ID:
			return createResult_2001(domainElement, containerView, index,
					persisted, preferencesHint);
		case EntryEditPart.VISUAL_ID:
			return createEntry_2002(domainElement, containerView, index,
					persisted, preferencesHint);
		case MinusOperatorEditPart.VISUAL_ID:
			return createMinusOperator_2003(domainElement, containerView,
					index, persisted, preferencesHint);
		case PlusOperatorEditPart.VISUAL_ID:
			return createPlusOperator_2004(domainElement, containerView, index,
					persisted, preferencesHint);
		case OperatorInputEditPart.VISUAL_ID:
			return createOperatorInput_3001(domainElement, containerView,
					//index, persisted, preferencesHint);
					index, true, preferencesHint); // persisted = true to ensure that the node is persisted
		case OperatorOutputEditPart.VISUAL_ID:
			return createOperatorOutput_3003(domainElement, containerView,
					//index, persisted, preferencesHint);
					index, true, preferencesHint); // persisted = true to ensure that the node is persisted
		}
		// can't happen, provided #provides(CreateNodeViewOperation) is correct
		return null;
	}

Thank you

I hope that this material will be helpful for you. If you want to support it, your help is welcome :

Discussion

Aurelien Pupier, 2010/02/16 08:39

Hi,

can it be related to this bug : https://bugs.eclipse.org/bugs/show_bug.cgi?id=281014 ? In this case another solution is to remove semantic hint in context viewclass.

Regards

Artem Tikhomirov, 2010/03/10 21:38

Hi,

Suggested fix (forcing persisted to be true) is quite awkward. The bugzilla Aurelien mentiones above is 100% relevant and describes reasons and possible fixes.

 
compartment_nodes_persistence_fix.txt · Last modified: 2011/08/08 20:08 by jfbraz
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki