Search in sources :

Example 81 with TreeColumn

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;
}
Also used : TreeColumn(org.eclipse.swt.widgets.TreeColumn) AgentFile(org.netxms.client.server.AgentFile)

Example 82 with TreeColumn

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;
}
Also used : TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree)

Example 83 with TreeColumn

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);
    }
}
Also used : TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree)

Example 84 with TreeColumn

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;
}
Also used : TreeColumn(org.eclipse.swt.widgets.TreeColumn) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point)

Example 85 with TreeColumn

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;
}
Also used : Listener(org.eclipse.swt.widgets.Listener) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Event(org.eclipse.swt.widgets.Event)

Aggregations

TreeColumn (org.eclipse.swt.widgets.TreeColumn)189 Tree (org.eclipse.swt.widgets.Tree)99 TreeViewer (org.eclipse.jface.viewers.TreeViewer)55 Composite (org.eclipse.swt.widgets.Composite)52 TreeItem (org.eclipse.swt.widgets.TreeItem)45 FillLayout (org.eclipse.swt.layout.FillLayout)40 Point (org.eclipse.swt.graphics.Point)39 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)28 Viewer (org.eclipse.jface.viewers.Viewer)28 GridData (org.eclipse.swt.layout.GridData)28 ControlEvent (org.eclipse.swt.events.ControlEvent)27 ControlAdapter (org.eclipse.swt.events.ControlAdapter)25 SelectionEvent (org.eclipse.swt.events.SelectionEvent)25 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)24 TableColumn (org.eclipse.swt.widgets.TableColumn)24 TableLayout (org.eclipse.jface.viewers.TableLayout)23 Table (org.eclipse.swt.widgets.Table)23 GridLayout (org.eclipse.swt.layout.GridLayout)22 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)21 ViewerPane (org.eclipse.emf.common.ui.ViewerPane)19