Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Show EObject in Diagram
Show EObject in Diagram [message #919930] Sat, 22 September 2012 14:18 Go to next message
Philipp El is currently offline Philipp ElFriend
Messages: 14
Registered: September 2012
Junior Member
Hi,

i have a problem with showing EOject elements in diagram.

Deleting a View from the diagram i have already solved as followed:

The method call is done in the following code fragment:

ReferencableElement elementToHide = (ReferencableElement)(selectedItem.getData());
...
HelperClass.deleteViewObjectOf(elementToHide);


The following two methods give the Command for deletion:

public static CompoundCommand deleteViewObjectOf (Object element) {
	List<Object> singleElementList = new ArrayList<Object>();
	singleElementList.add(element);
	return deleteViewObjectOf(singleElementList);
}


public static CompoundCommand deleteViewObjectOf (Collection<?> elements) {
	if (getEditingDomain() != null) {
		Diagram d = ModelUtils.getDiagram(getEditingDomain());
		CompoundCommand cc = new CompoundCommand(Messages.Helpers_hide_all_elements);

		Hashtable<Object, Object> model hash = new Hashtable<Object, Object>();

		for (Object obj : elements) {
			modelhash.put(obj, obj);	
		}

		DiagramCommandStack dcs = modeller.getDefaultViewDiagramCommandStack();
		org.eclipse.gef.commands.CompoundCommand gefcc = new org.eclipse.gef.commands.CompoundCommand();

		for (Object obj : d.getChildren()) {
			if (obj instanceof View) {
				View v = (View)obj;
				v.getElement();

				if (model hash.containsKey(v.getElement())) {
					org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand dc = new org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand(getEditingDomain(), v);
					gefcc.add(new ICommandProxy(dc));
				}
			}
		} 

		for (Object obj : d.getEdges()) {
			if (obj instanceof View) {
				View v = (View)obj;
				v.getElement();

				if (model hash.containsKey(v.getElement())) {
					org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand dc = new org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand(getEditingDomain(), v);
					gefcc.add(new ICommandProxy(dc));
				}
			}
		} 


		try {
			dcs.execute(gefcc);
		}
		catch(Exception ex) {
			ex.printStackTrace();
		}
		cc.append(new DeleteCommand(getEditingDomain(), elements))
		return cc;	
	}
	return null;
}


Deleting View elements works fine as already mentioned.

Now my question: How should i adjust the following method that an EObject or a ReferencableElement can be shown?


public static CompoundCommand deleteViewObjectOf (Collection<?> elements) {
	if (getEditingDomain() != null) {
		Diagram d = ModelUtils.getDiagram(getEditingDomain());
		CompoundCommand cc = new CompoundCommand(Messages.Helpers_hide_all_elements);

		Hashtable<Object, Object> model hash = new Hashtable<Object, Object>();

		for (Object obj : elements) {
			modelhash.put(obj, obj);	
		}

		DiagramCommandStack dcs = modeller.getDefaultViewDiagramCommandStack();
		org.eclipse.gef.commands.CompoundCommand gefcc = new org.eclipse.gef.commands.CompoundCommand();

		for (Object obj : d.getChildren()) {
			if (obj instanceof View) {
				View v = (View)obj;
				v.getElement();

				if (model hash.containsKey(v.getElement())) {
					//todo
				}
			}
		} 

		for (Object obj : d.getEdges()) {
			if (obj instanceof View) {
				View v = (View)obj;
				v.getElement();

				if (model hash.containsKey(v.getElement())) {
					//todo
				}
			}
		} 


		try {
			dcs.execute(gefcc);
		}
		catch(Exception ex) {
			ex.printStackTrace();
		}
		//todo
		return cc;	
	}
	return null;
}


Thanks and best regards,

Philipp

[Updated on: Sat, 22 September 2012 14:21]

Report message to a moderator

Re: Show EObject in Diagram [message #921714 is a reply to message #919930] Mon, 24 September 2012 11:16 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph GerbigFriend
Messages: 702
Registered: November 2009
Senior Member
Hi Philipp,

what is your overall goal? Do you use GMF Tooling?

Ralph
Re: Show EObject in Diagram [message #921725 is a reply to message #921714] Mon, 24 September 2012 11:27 Go to previous messageGo to next message
Philipp El is currently offline Philipp ElFriend
Messages: 14
Registered: September 2012
Junior Member
Hi Ralph,

my overall goal is to hide or show certain EObect's in the diagram.
Hiding EObject's already works fine as described above.

Thanks.

Best regards,

Philipp
Re: Show EObject in Diagram [message #921915 is a reply to message #921725] Mon, 24 September 2012 14:50 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph GerbigFriend
Messages: 702
Registered: November 2009
Senior Member
Hi,

did you try to set the views visible property to true false instead of deleting the view?

Ralph
Re: Show EObject in Diagram [message #922112 is a reply to message #921915] Mon, 24 September 2012 18:56 Go to previous messageGo to next message
Philipp El is currently offline Philipp ElFriend
Messages: 14
Registered: September 2012
Junior Member
Hi Ralph,

yes i tried it, but it didn't work so.
Hiding elements isn't faulty.
The problem is the showing of the elements.

Thanks!

Best regards,

Philipp
Re: Show EObject in Diagram [message #934242 is a reply to message #922112] Fri, 05 October 2012 19:42 Go to previous message
Aurélien Pupier is currently offline Aurélien PupierFriend
Messages: 637
Registered: July 2009
Location: Grenoble, FRANCE
Senior Member

Hi,

you should take a look to Mylyn modeling bridge: http://wiki.eclipse.org/Mylyn/Modeling_Bridge
You can hide/show editparts depending on a context.

Regards,


Aurélien Pupier - Red Hat
Senior Software Engineer in Fuse Tooling team
Previous Topic:Get an image from a GMF/EMF diagram
Next Topic:Use GMF diagram only as a viewer rather than a editor
Goto Forum:
  


Current Time: Tue Apr 23 16:14:02 GMT 2024

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

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

Back to the top