use of org.eclipse.swt.widgets.TreeColumn in project netxms by netxms.
the class AgentFileComparator method compare.
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
TreeColumn sortColumn = ((SortableTreeViewer) viewer).getTree().getSortColumn();
if (sortColumn == null)
return 0;
int rc;
switch(// $NON-NLS-1$
(Integer) sortColumn.getData("ID")) {
case AgentFileManager.COLUMN_NAME:
if (((AgentFile) e1).isDirectory() == ((AgentFile) e2).isDirectory()) {
rc = ((AgentFile) e1).getName().compareToIgnoreCase(((AgentFile) e2).getName());
} else {
rc = ((AgentFile) e1).isDirectory() ? -1 : 1;
}
break;
case AgentFileManager.COLUMN_TYPE:
if (((AgentFile) e1).isDirectory() == ((AgentFile) e2).isDirectory()) {
rc = ((AgentFile) e1).getExtension().compareToIgnoreCase(((AgentFile) e2).getExtension());
} else {
rc = ((AgentFile) e1).isDirectory() ? -1 : 1;
}
break;
case AgentFileManager.COLUMN_SIZE:
if ((((AgentFile) e1).isDirectory() == ((AgentFile) e2).isDirectory())) {
rc = Long.signum(((AgentFile) e1).getSize() - ((AgentFile) e2).getSize());
} else {
rc = ((AgentFile) e1).isDirectory() ? -1 : 1;
}
break;
case AgentFileManager.COLUMN_MODIFYED:
if ((((AgentFile) e1).isDirectory() == ((AgentFile) e2).isDirectory())) {
rc = ((AgentFile) e1).getModifyicationTime().compareTo(((AgentFile) e2).getModifyicationTime());
} else {
rc = ((AgentFile) e1).isDirectory() ? -1 : 1;
}
break;
case AgentFileManager.COLUMN_OWNER:
if ((((AgentFile) e1).isDirectory() == ((AgentFile) e2).isDirectory())) {
rc = ((AgentFile) e1).getOwner().compareTo(((AgentFile) e2).getOwner());
} else {
rc = ((AgentFile) e1).isDirectory() ? -1 : 1;
}
break;
case AgentFileManager.COLUMN_GROUP:
if ((((AgentFile) e1).isDirectory() == ((AgentFile) e2).isDirectory())) {
rc = ((AgentFile) e1).getGroup().compareTo(((AgentFile) e2).getGroup());
} else {
rc = ((AgentFile) e1).isDirectory() ? -1 : 1;
}
break;
case AgentFileManager.COLUMN_ACCESS_RIGHTS:
if ((((AgentFile) e1).isDirectory() == ((AgentFile) e2).isDirectory())) {
rc = ((AgentFile) e1).getAccessRights().compareTo(((AgentFile) e2).getAccessRights());
} else {
rc = ((AgentFile) e1).isDirectory() ? -1 : 1;
}
break;
default:
rc = 0;
break;
}
int dir = ((SortableTreeViewer) viewer).getTree().getSortDirection();
return (dir == SWT.UP) ? rc : -rc;
}
use of org.eclipse.swt.widgets.TreeColumn in project eclipse-integration-commons by spring-projects.
the class TreeViewerComposite method getDefaultSortColumn.
protected TreeColumn getDefaultSortColumn() {
if (defaultSortColumn == null) {
return null;
}
String sortColumnName = defaultSortColumn.getName();
if (sortColumnName == null) {
return null;
}
Tree tree = viewer.getTree();
TreeColumn[] columns = tree.getColumns();
if (columns != null) {
for (TreeColumn column : columns) {
if (sortColumnName.equals(column.getText())) {
return column;
}
}
}
return null;
}
use of org.eclipse.swt.widgets.TreeColumn in project eclipse-integration-commons by spring-projects.
the class TreeViewerComposite method initSorting.
protected void initSorting() {
TreeColumn sortColumn = getDefaultSortColumn();
Tree tree = viewer.getTree();
if (sortColumn != null) {
tree.setSortColumn(sortColumn);
tree.setSortDirection(SWT.UP);
}
}
use of org.eclipse.swt.widgets.TreeColumn in project pmd-eclipse-plugin by pmd.
the class AbstractTreeTableManager method columnIndexAt.
// TODO move to util
public static int columnIndexAt(TreeItem item, int xPosition) {
TreeColumn[] cols = item.getParent().getColumns();
Rectangle bounds;
for (int i = 0; i < cols.length; i++) {
bounds = item.getBounds(i);
if (bounds.x < xPosition && xPosition < (bounds.x + bounds.width)) {
return i;
}
}
return -1;
}
use of org.eclipse.swt.widgets.TreeColumn in project pmd-eclipse-plugin by pmd.
the class AbstractRuleColumnDescriptor method buildTreeColumn.
protected TreeColumn buildTreeColumn(Tree parent, final SortListener sortListener) {
TreeColumn tc = super.buildTreeColumn(parent);
tc.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
sortListener.sortBy(accessor(), e.widget);
}
});
return tc;
}
Aggregations