Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
507595 Adding Sortable to Table Columns
Change-Id: I80a5605e36b10daa0ec90c082c37c58d332f6501 Signed-off-by: Francesco Guidieri <francesco.guidieri@gmail.com> https://bugs.eclipse.org/bugs/show_bug.cgi?id=507595 Change-Id: I80a5605e36b10daa0ec90c082c37c58d332f6501
- Loading branch information
Showing
17 changed files
with
1,115 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
...y.common/src/org/eclipse/emf/parsley/internal/viewers/GenericFeatureViewerComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2016 RCP Vision (http://www.rcp-vision.com) and others. | ||
* 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: | ||
* Francesco Guidieri - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.emf.parsley.internal.viewers; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.emf.ecore.EStructuralFeature; | ||
import org.eclipse.emf.parsley.util.EmfParsleyUtil; | ||
import org.eclipse.jface.viewers.Viewer; | ||
import org.eclipse.jface.viewers.ViewerComparator; | ||
import org.eclipse.swt.SWT; | ||
|
||
/** | ||
* @since 1.1 | ||
* @author Francesco Guidieri | ||
*/ | ||
public class GenericFeatureViewerComparator extends ViewerComparator { | ||
|
||
private int propertyIndex; | ||
private int direction; | ||
|
||
private List<EStructuralFeature> features; | ||
|
||
public GenericFeatureViewerComparator() { | ||
this.propertyIndex = 0; | ||
this.direction = SWT.NONE; | ||
} | ||
|
||
public void init(List<EStructuralFeature> features) { | ||
this.features = features; | ||
} | ||
|
||
public int getDirection() { | ||
return direction; | ||
} | ||
|
||
public int getPropertyIndex() { | ||
return propertyIndex; | ||
} | ||
|
||
public void setPropertyIndex(int column) { | ||
if (column == this.propertyIndex) { | ||
// Same column as last sort; toggle the direction | ||
switch (direction) { | ||
case SWT.NONE: | ||
direction = SWT.UP; | ||
break; | ||
case SWT.UP: | ||
direction = SWT.DOWN; | ||
break; | ||
default: | ||
direction = SWT.NONE; | ||
} | ||
} else { | ||
// New column; do an ascending sort | ||
propertyIndex = column; | ||
direction = SWT.UP; | ||
} | ||
} | ||
|
||
@Override | ||
public int compare(Viewer viewer, Object e1, Object e2) { | ||
EObject p1 = (EObject) e1; | ||
EObject p2 = (EObject) e2; | ||
// If none, no compare | ||
if (direction == SWT.NONE) { | ||
return 0; | ||
} | ||
|
||
EStructuralFeature feature = features.get(propertyIndex); | ||
int rc = compareValue(p1, p2, feature); | ||
// If descending order, flip the direction | ||
if (direction == SWT.DOWN) { | ||
rc = -rc; | ||
} | ||
return rc; | ||
} | ||
|
||
protected int compareValue(EObject p1, EObject p2, EStructuralFeature feature) { | ||
Object value1 = p1.eGet(feature); | ||
Object value2 = p2.eGet(feature); | ||
return EmfParsleyUtil.compareValues(value1, value2); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
...ley.tests.models/src/org/eclipse/emf/parsley/tests/models/testmodels/ClassForCompare.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/** | ||
*/ | ||
package org.eclipse.emf.parsley.tests.models.testmodels; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.Date; | ||
import org.eclipse.emf.ecore.EObject; | ||
|
||
/** | ||
* <!-- begin-user-doc --> | ||
* A representation of the model object '<em><b>Class For Compare</b></em>'. | ||
* <!-- end-user-doc --> | ||
* | ||
* <p> | ||
* The following features are supported: | ||
* </p> | ||
* <ul> | ||
* <li>{@link org.eclipse.emf.parsley.tests.models.testmodels.ClassForCompare#getStringAttribute <em>String Attribute</em>}</li> | ||
* <li>{@link org.eclipse.emf.parsley.tests.models.testmodels.ClassForCompare#getIntAttribute <em>Int Attribute</em>}</li> | ||
* <li>{@link org.eclipse.emf.parsley.tests.models.testmodels.ClassForCompare#getBigDecimalAttribute <em>Big Decimal Attribute</em>}</li> | ||
* <li>{@link org.eclipse.emf.parsley.tests.models.testmodels.ClassForCompare#getDateAttribute <em>Date Attribute</em>}</li> | ||
* </ul> | ||
* | ||
* @see org.eclipse.emf.parsley.tests.models.testmodels.TestmodelsPackage#getClassForCompare() | ||
* @model | ||
* @generated | ||
*/ | ||
public interface ClassForCompare extends EObject { | ||
/** | ||
* Returns the value of the '<em><b>String Attribute</b></em>' attribute. | ||
* <!-- begin-user-doc --> | ||
* <p> | ||
* If the meaning of the '<em>String Attribute</em>' attribute isn't clear, | ||
* there really should be more of a description here... | ||
* </p> | ||
* <!-- end-user-doc --> | ||
* @return the value of the '<em>String Attribute</em>' attribute. | ||
* @see #setStringAttribute(String) | ||
* @see org.eclipse.emf.parsley.tests.models.testmodels.TestmodelsPackage#getClassForCompare_StringAttribute() | ||
* @model | ||
* @generated | ||
*/ | ||
String getStringAttribute(); | ||
|
||
/** | ||
* Sets the value of the '{@link org.eclipse.emf.parsley.tests.models.testmodels.ClassForCompare#getStringAttribute <em>String Attribute</em>}' attribute. | ||
* <!-- begin-user-doc --> | ||
* <!-- end-user-doc --> | ||
* @param value the new value of the '<em>String Attribute</em>' attribute. | ||
* @see #getStringAttribute() | ||
* @generated | ||
*/ | ||
void setStringAttribute(String value); | ||
|
||
/** | ||
* Returns the value of the '<em><b>Int Attribute</b></em>' attribute. | ||
* <!-- begin-user-doc --> | ||
* <p> | ||
* If the meaning of the '<em>Int Attribute</em>' attribute isn't clear, | ||
* there really should be more of a description here... | ||
* </p> | ||
* <!-- end-user-doc --> | ||
* @return the value of the '<em>Int Attribute</em>' attribute. | ||
* @see #setIntAttribute(int) | ||
* @see org.eclipse.emf.parsley.tests.models.testmodels.TestmodelsPackage#getClassForCompare_IntAttribute() | ||
* @model | ||
* @generated | ||
*/ | ||
int getIntAttribute(); | ||
|
||
/** | ||
* Sets the value of the '{@link org.eclipse.emf.parsley.tests.models.testmodels.ClassForCompare#getIntAttribute <em>Int Attribute</em>}' attribute. | ||
* <!-- begin-user-doc --> | ||
* <!-- end-user-doc --> | ||
* @param value the new value of the '<em>Int Attribute</em>' attribute. | ||
* @see #getIntAttribute() | ||
* @generated | ||
*/ | ||
void setIntAttribute(int value); | ||
|
||
/** | ||
* Returns the value of the '<em><b>Big Decimal Attribute</b></em>' attribute. | ||
* <!-- begin-user-doc --> | ||
* <p> | ||
* If the meaning of the '<em>Big Decimal Attribute</em>' attribute isn't clear, | ||
* there really should be more of a description here... | ||
* </p> | ||
* <!-- end-user-doc --> | ||
* @return the value of the '<em>Big Decimal Attribute</em>' attribute. | ||
* @see #setBigDecimalAttribute(BigDecimal) | ||
* @see org.eclipse.emf.parsley.tests.models.testmodels.TestmodelsPackage#getClassForCompare_BigDecimalAttribute() | ||
* @model | ||
* @generated | ||
*/ | ||
BigDecimal getBigDecimalAttribute(); | ||
|
||
/** | ||
* Sets the value of the '{@link org.eclipse.emf.parsley.tests.models.testmodels.ClassForCompare#getBigDecimalAttribute <em>Big Decimal Attribute</em>}' attribute. | ||
* <!-- begin-user-doc --> | ||
* <!-- end-user-doc --> | ||
* @param value the new value of the '<em>Big Decimal Attribute</em>' attribute. | ||
* @see #getBigDecimalAttribute() | ||
* @generated | ||
*/ | ||
void setBigDecimalAttribute(BigDecimal value); | ||
|
||
/** | ||
* Returns the value of the '<em><b>Date Attribute</b></em>' attribute. | ||
* <!-- begin-user-doc --> | ||
* <p> | ||
* If the meaning of the '<em>Date Attribute</em>' attribute isn't clear, | ||
* there really should be more of a description here... | ||
* </p> | ||
* <!-- end-user-doc --> | ||
* @return the value of the '<em>Date Attribute</em>' attribute. | ||
* @see #setDateAttribute(Date) | ||
* @see org.eclipse.emf.parsley.tests.models.testmodels.TestmodelsPackage#getClassForCompare_DateAttribute() | ||
* @model | ||
* @generated | ||
*/ | ||
Date getDateAttribute(); | ||
|
||
/** | ||
* Sets the value of the '{@link org.eclipse.emf.parsley.tests.models.testmodels.ClassForCompare#getDateAttribute <em>Date Attribute</em>}' attribute. | ||
* <!-- begin-user-doc --> | ||
* <!-- end-user-doc --> | ||
* @param value the new value of the '<em>Date Attribute</em>' attribute. | ||
* @see #getDateAttribute() | ||
* @generated | ||
*/ | ||
void setDateAttribute(Date value); | ||
|
||
} // ClassForCompare |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.