Example usage for org.eclipse.jface.viewers ColumnViewer getColumnViewerEditor

List of usage examples for org.eclipse.jface.viewers ColumnViewer getColumnViewerEditor

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers ColumnViewer getColumnViewerEditor.

Prototype

public ColumnViewerEditor getColumnViewerEditor() 

Source Link

Usage

From source file:com.rcpcompany.uibindings.internal.utils.UIHandlerUtils.java

License:Open Source License

/**
 * Moves the specified element in the viewer of the binding.
 * /*from ww w .ja  va  2  s  .  co m*/
 * @param vb the viewer binding
 * @param element the element to move
 * @param delta the amount to move
 * @param testOnly <code>true</code> if the move should only be tested for, but not performed
 * @return <code>true</code> if the element could be moved
 */
public static boolean moveElement(IViewerBinding vb, EObject element, int delta, boolean testOnly) {
    if (Activator.getDefault().TRACE_NAVIGATION_VIEWER) {
        LogUtils.debug(vb, "delta=" + delta + ", testOnly=" + testOnly + ", element=" + element);
    }

    Assert.isNotNull(vb);
    if (element == null)
        return false;

    final ColumnViewer viewer = vb.getViewer();
    /*
     * Don't move if there are any sorter or filters installed as these negates the visual
     * effect.
     */
    if (viewer.getComparator() != null || viewer.getFilters().length > 0)
        return false;

    // The list of objects
    final IObservableList list = vb.getList();

    // Old position
    final int oldPosition = list.indexOf(element);
    if (oldPosition == -1)
        return false;

    // New position
    int newPosition = oldPosition + delta;
    if (newPosition < 0) {
        newPosition = 0;
    }
    if (newPosition >= list.size()) {
        newPosition = list.size() - 1;
    }

    // Can not be moved?
    if (oldPosition == newPosition)
        return false;

    // Move it
    if (!testOnly) {
        final ColumnViewerEditor editor = viewer.getColumnViewerEditor();
        final ViewerCell oldFocusCell = editor.getFocusCell();

        list.move(newPosition, oldPosition);

        vb.setFocus(oldFocusCell.getColumnIndex(), element);
        // ((Table) viewer.getControl()).setSelection(newPosition);
    }
    return true;
}

From source file:com.rcpcompany.uibindings.internal.ViewerBindingImpl.java

License:Open Source License

@Override
public void updateSourceProviderState(ISourceProviderStateContext context) {
    final ColumnViewer viewer = getViewer();

    context.putSourceValue(Constants.SOURCES_ACTIVE_CONTAINER_BINDING, this);
    context.putSourceValue(Constants.SOURCES_ACTIVE_CONTAINER_BINDING_NO_CAF,
            (viewer.getComparator() == null && viewer.getFilters().length == 0));

    context.putSourceValue(Constants.SOURCES_ACTIVE_VIEWER_ELEMENT_TYPE, getModelType());

    EObject element = null;/*from   ww w . j av  a2 s.c  o m*/
    int columnIndex = -1;
    ContainerCellType type = null;

    ViewerCell cell;
    /*
     * If no specific position is specified in the event (x,y) = (0,0), then try using the
     * current focus cell. This is needed when navigating in the table.
     * 
     * Also do this if the widget of the event is not this viewers control. That happens when
     * extra widgets are mapped to this binding with IBinding.registerWidget()
     */
    final Event event = context.getEvent();
    final Point point = context.getLocation();
    if (event.x == 0 && event.y == 0 || event.widget != getControl()) {
        cell = viewer.getColumnViewerEditor().getFocusCell();
    } else {
        cell = viewer.getCell(point);
    }
    if (cell != null) {
        element = (EObject) cell.getElement();
        columnIndex = cell.getColumnIndex();
        type = ContainerCellType.DATA;
    } else {
        final Control c = viewer.getControl();
        if (c instanceof Table) {
            final Table t = (Table) c;
            final TableItem item = t.getItem(point);
            if (item != null) {
                element = (EObject) item.getData();
                type = ContainerCellType.ROW_TRAILER;
            } else {
                /*
                 * Below or above the table?
                 */
                if (point.y < 0) {
                    type = ContainerCellType.COLUMN_HEADER;
                } else {
                    type = ContainerCellType.COLUMN_TRAILER;
                }
            }
        }
        if (c instanceof Tree) {
            final Tree t = (Tree) c;
            final TreeItem item = t.getItem(point);
            if (item != null) {
                element = (EObject) item.getData();
                type = ContainerCellType.ROW_TRAILER;
            } else {
                /*
                 * Below or above the tree?
                 */
                if (point.y < 0) {
                    type = ContainerCellType.COLUMN_HEADER;
                } else {
                    type = ContainerCellType.COLUMN_TRAILER;
                }
            }
        }
    }

    if (type != null) {
        context.putSourceValue(Constants.SOURCES_ACTIVE_CONTAINER_CELL_TYPE, type.toString());
    }
    if (element != null) {
        context.putSourceValue(Constants.SOURCES_ACTIVE_VIEWER_ELEMENT, element);
        context.putSourceValue(Constants.SOURCES_ACTIVE_VIEWER_ELEMENT_MOVE_UP,
                UIHandlerUtils.moveElement(this, element, -1, true));
        context.putSourceValue(Constants.SOURCES_ACTIVE_VIEWER_ELEMENT_MOVE_DOWN,
                UIHandlerUtils.moveElement(this, element, 1, true));
    }

    if (columnIndex >= getFirstTableColumnOffset() && element != null) {
        final IColumnBindingCellInformation ci = getCell(columnIndex - getFirstTableColumnOffset(), element);
        final IObservableValue objectValue = ci.getObjectValue();
        final Object value = objectValue.getValue();

        final IValueBinding labelBinding = ci.getLabelBinding();
        context.putSourceValue(Constants.SOURCES_ACTIVE_BINDING, labelBinding);
        context.putSourceValue(Constants.SOURCES_ACTIVE_BINDING_RO, !ci.isChangeable());
        context.putSourceValue(Constants.SOURCES_ACTIVE_BINDING_VALUE, value);
        context.putSourceValue(Constants.SOURCES_ACTIVE_BINDING_TYPE, ""); //$NON-NLS-1$
        if (labelBinding != null) {
            context.putSourceValue(Constants.SOURCES_ACTIVE_BINDING_MODEL_OBJECT,
                    labelBinding.getModelObject());
            context.putSourceValue(Constants.SOURCES_ACTIVE_BINDING_FEATURE, labelBinding.getModelFeature());
            context.putSourceValue(Constants.SOURCES_ACTIVE_BINDING_UNSETTABLE,
                    labelBinding.getDataType().isUnsettable());
            context.putSourceValue(Constants.SOURCES_ACTIVE_BINDING_IS_SET, isSet(labelBinding));
        }
        context.putSourceValue(Constants.SOURCES_ACTIVE_BINDING_VALUE_DISPLAY, ci.getDisplayText());

        context.addObservedValue(ci.getLabelUIAttribute().getCurrentValue());
    }

    context.setSelectionProvider(getViewer());
}

From source file:org.robotframework.ide.eclipse.main.plugin.project.editor.libraries.ReferencedLibrariesEditingSupportTest.java

License:Apache License

@Test
public void properCellEditorIsProvided() {
    final ColumnViewer viewer = mock(ColumnViewer.class);
    when(viewer.getControl()).thenReturn(shellProvider.getShell());
    when(viewer.getColumnViewerEditor()).thenReturn(mock(ColumnViewerEditor.class));

    final ReferencedLibrariesEditingSupport support = new ReferencedLibrariesEditingSupport(viewer, null, null);

    assertThat(support.getCellEditor(new ReferencedLibrary())).isNull();
    assertThat(support.getCellEditor(new Object())).isNull();
    assertThat(support.getCellEditor(new RemoteLocation()))
            .isInstanceOf(ActivationCharPreservingTextCellEditor.class);
}