/******************************************************************************* | |
* Copyright (c) 2004-2008 Istvan Rath and Daniel Varro | |
* All rights reserved. This program and the accompanying materials | |
* are made available under the terms of the Eclipse Public License v1.0 | |
* which accompanies this distribution, and is available at | |
* http://www.eclipse.org/legal/epl-v10.html | |
* | |
* Contributors: | |
* Istvan Rath - initial API and implementation | |
*******************************************************************************/ | |
package org.eclipse.viatra2.treeeditor.providers; | |
import java.text.Collator; | |
import org.eclipse.jface.viewers.Viewer; | |
import org.eclipse.jface.viewers.ViewerSorter; | |
import org.eclipse.viatra2.core.IModelElement; | |
public class ViatraTreeviewSorter extends ViewerSorter { | |
public ViatraTreeviewSorter() { | |
super(); | |
} | |
public ViatraTreeviewSorter(Collator collator) { | |
super(collator); | |
} | |
@Override | |
public int compare(Viewer viewer, Object arg0, Object arg1) { | |
if (arg0 instanceof IModelElement && arg1 instanceof IModelElement) | |
{ | |
IModelElement a0 = (IModelElement) arg0; | |
IModelElement a1 = (IModelElement) arg1; | |
if (a0.getClass().equals(a1.getClass())) | |
return (a0.getName().compareTo(a1.getName())); | |
else if (a0.isEntity() && a1.isRelation()) | |
return +1; | |
else | |
return -1; | |
} | |
else if (arg0 instanceof IModelElement) return -1; | |
else if (arg1 instanceof IModelElement) return +1; | |
return 0; | |
} | |
} |