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

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

Introduction

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

Prototype

public void cancelEditing() 

Source Link

Document

Cancels a currently active cell editor if one is active.

Usage

From source file:com.rcpcompany.uibindings.extests.leaks.ViewerEditorLeakTest.java

License:Open Source License

@Test
public void testLeak() {
    /*/*from   w w  w.  ja v  a  2s . co  m*/
     * Count number of adapters
     */
    final int beforeCount = countAdapters(myShop);

    /*
     * Edit a cell
     */
    final ColumnViewer viewer = myTableCreator.getBinding().getViewer();
    viewer.editElement(myCustomer1, 0);

    // assertNotNull(column.myEditingSupport);
    // final ValueBinding b = (ValueBinding) column.myEditingSupport.myEditorBinding;
    // assertNotNull(b);
    // final IObservableValue observable = b.getUIObservable();
    //
    // observable.setValue("New name");

    viewer.cancelEditing();

    /*
     * Recount
     */
    final int afterCount = countAdapters(myShop);

    assertEquals(beforeCount, afterCount);
}

From source file:org.eclipse.rcptt.tesla.nebula.NebulaUIProcessor.java

License:Open Source License

@Override
protected CellEditorSupport createCellEditorSupport() {
    return new CellEditorSupport(this) {
        protected Response handleActivateCellEditor(final ActivateCellEditor command) {
            Element element = command.getElement();
            if (!element.getKind().equals(NebulaElementKinds.GRID))
                return super.handleActivateCellEditor(command);

            SWTUIElement uiElement = getMapper().get(element);
            final Grid grid = (Grid) PlayerWrapUtils.unwrapWidget(uiElement);
            final ColumnViewer viewer = TeslaSWTAccess.getThis(ColumnViewer.class, grid, SWT.MouseDown);

            getPlayer().exec("Activate editor in Nebula Grid", new Runnable() {
                public void run() {
                    Object item = ((IStructuredSelection) viewer.getSelection()).getFirstElement();

                    if (item != null)
                        viewer.editElement(item, command.getColumn());
                }//from   w  w w  .ja va 2  s .  c  o  m
            });

            return factory.createBooleanResponse();
        }

        protected Response handleCancelCellEditor(final CancelCellEditor command) {
            Element element = command.getElement();
            if (!element.getKind().equals(NebulaElementKinds.GRID))
                return super.handleCancelCellEditor(command);

            SWTUIElement uiElement = getMapper().get(element);
            final Grid grid = (Grid) PlayerWrapUtils.unwrapWidget(uiElement);
            final ColumnViewer viewer = TeslaSWTAccess.getThis(ColumnViewer.class, grid, SWT.MouseDown);

            getPlayer().exec("Cancel editing in Nebula Grid", new Runnable() {
                public void run() {
                    viewer.cancelEditing();
                }
            });

            return factory.createBooleanResponse();
        }

        @Override
        protected Response handleApplyCellEditor(final ApplyCellEditor command) {
            Element element = command.getElement();
            if (!element.getKind().equals(NebulaElementKinds.GRID))
                return super.handleApplyCellEditor(command);

            getPlayer().exec("Apply editing in Nebula Grid", new Runnable() {
                public void run() {
                    CellEditor editor = TeslaCellEditorManager.getInstance().getLastActivatedByAnyMethod();
                    if (editor != null) {
                        TeslaCellEditorManager.getInstance().forceRemove(editor);
                        TeslaSWTAccess.callMethodValueChanged(editor, "valueChanged", editor.isValueValid(),
                                true);
                        TeslaSWTAccess.callMethod(editor, "fireApplyEditorValue");
                        if (editor instanceof ComboBoxViewerCellEditor) {
                            TeslaSWTAccess.callMethod(ComboBoxViewerCellEditor.class, editor,
                                    "applyEditorValueAndDeactivate");
                        }
                        editor.deactivate();
                    }
                }
            });

            return factory.createBooleanResponse();
        }
    };
}