Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » How do I override equals() of diagram editor input
How do I override equals() of diagram editor input [message #875456] Tue, 22 May 2012 19:30 Go to next message
Johnny Qin is currently offline Johnny QinFriend
Messages: 40
Registered: April 2012
Member
Hello everyone,

I am trying to figure out how to let diagram editor know whether user is opening a new diagram file or a already-opened one. In other words, when a diagram file is opened, double-click on the same file in Project Explorer should highlight the opened editor instead of creating a new editor instance.

Apparently init() of Graphiti's DiagramEditor sets a FileInput instance when user tries to open a diagram file, it then converts the FileInput object to DiagramEditorInput. For multiple FileInput instances of the same file, we get multiple DiagramEditorInput instances. Surprisingly, when debug the equals() in DiagramEditorInput,
if (getClass() != obj.getClass()) {
			return false;
		}

returns false because getClass() returns DiagramEditorInput but obj.getClass() gives FileInput. Any ideas?

@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		DiagramEditorInput other = (DiagramEditorInput) obj;
		if (uri == null) {
			if (other.uri != null) {
				return false;
			}
		} else if (!uri.equals(other.uri)) {
			return false;
		}
		if (providerId == null) {
			if (other.providerId != null) {
				return false;
			}
		} else if (!providerId.equals(other.providerId)) {
			return false;
		}
		return true;
	}


Thanks,
Johnny

[Updated on: Tue, 22 May 2012 19:52]

Report message to a moderator

Re: How do I override equals() of diagram editor input [message #875720 is a reply to message #875456] Wed, 23 May 2012 08:21 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1640
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Do you have your own editor (a DiagramEditor subclass)? In case yes, the
reason for this might be that the
org.eclipse.graphiti.ui.editor.DiagramEditorMatchingStrategy (or your own
subclass of it) is not set as the editor's matching strategy (done in
plugin.xml).

Michael
Re: How do I override equals() of diagram editor input [message #875885 is a reply to message #875720] Wed, 23 May 2012 13:54 Go to previous message
Johnny Qin is currently offline Johnny QinFriend
Messages: 40
Registered: April 2012
Member
Thanks Michael, this works perfectly.
Previous Topic:deletePictogramElement Performance
Next Topic:Ability to get visible size of diagram?
Goto Forum:
  


Current Time: Mon Dec 22 03:34:54 GMT 2014

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

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