Example usage for org.eclipse.jface.viewers ICellModifier getValue

List of usage examples for org.eclipse.jface.viewers ICellModifier getValue

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers ICellModifier getValue.

Prototype

public Object getValue(Object element, String property);

Source Link

Document

Returns the value for the given property of the given element.

Usage

From source file:org.eclipse.bpel.ui.details.providers.TableProvider.java

License:Open Source License

public Object getValue(Object element, String property) {
    // delegate to the appropriate cell modifier.
    ICellModifier cm = (ICellModifier) propertyToCellModifier.get(property);
    if (cm != null)
        return cm.getValue(element, property);
    // no cell modifier found.
    return null;/*from  ww w . java2s  .  c om*/
}

From source file:org.eclipse.bpmn2.modeler.core.merrimac.providers.TableProvider.java

License:Open Source License

public Object getValue(Object element, String property) {
    // delegate to the appropriate cell modifier.
    ICellModifier cm = (ICellModifier) propertyToCellModifier.get(property);
    if (cm != null && element != null)
        return cm.getValue(element, property);
    // no cell modifier found.
    return null;//from w  ww.j  a  va2s  .c  o  m
}

From source file:org.eclipse.debug.internal.ui.views.memory.renderings.AsyncTableRenderingViewer.java

License:Open Source License

/**
 * Activate cell editor and pre-fill it with initial value.
 * If initialValue is null, use cell content as initial value
 * @param initialValue the initial value for the cell editor
 *///from  www .  j a  v a 2  s.co  m
private void activateCellEditor(String initialValue) {

    final int col = fTableCursor.getColumn();
    final int row = indexOf(fSelectionKey);

    if (row < 0)
        return;

    // do not allow user to edit address column
    if (col == 0 || col > getNumCol()) {
        return;
    }

    ICellModifier cellModifier = null;

    cellModifier = getCellModifier();

    TableItem tableItem = getTable().getItem(row);

    Object element = tableItem.getData();

    if (element != null) {
        Object property = getColumnProperties()[col];
        Object value = cellModifier.getValue(element, (String) property);
        boolean canEdit = cellModifier.canModify(element, (String) property);

        if (!canEdit)
            return;

        CellEditor editor = getCellEditors()[col];
        if (editor != null) {
            // The control that will be the editor must be a child of the
            // Table
            Control control = editor.getControl();

            Object cellValue = null;

            if (initialValue != null) {
                cellValue = initialValue;
            } else {
                cellValue = value;
            }

            editor.setValue(cellValue);

            fCursorEditor.horizontalAlignment = SWT.LEFT;
            fCursorEditor.grabHorizontal = true;

            // Open the editor editor in selected column of the selected
            // row.
            fCursorEditor.setEditor(control, tableItem, col);

            // Assign focus to the editor control
            editor.setFocus();

            if (initialValue != null && control instanceof Text) {
                ((Text) control).clearSelection();
            }

            control.setFont(JFaceResources.getFont(IInternalDebugUIConstants.FONT_NAME));

            // add listeners for the editor control
            addListeners(control);

            fCellEditorListener = new CellEditorListener(row, col, editor);
            editor.addListener(fCellEditorListener);

            // move cursor below editor control
            fTableCursor.moveBelow(control);
        }
    }
}

From source file:org.eclipse.debug.ui.memory.AbstractTableRendering.java

License:Open Source License

/**
 * Activate cell editor and pre-fill it with initial value.
 * If initialValue is null, use cell content as initial value
 * @param initialValue the initial value to edit 
 *//*from w w w.  ja v  a2s.c  om*/
private void activateCellEditor(String initialValue) {

    int col = fTableCursor.getColumn();
    int row = findAddressIndex(fSelectedAddress);

    if (row < 0)
        return;
    // do not allow user to edit address column
    if (col == 0 || col > getNumCol()) {
        return;
    }

    ICellModifier cellModifier = null;

    if (fTableViewer == null) {
        return;
    }
    cellModifier = fTableViewer.getCellModifier();

    TableItem tableItem = fTableViewer.getTable().getItem(row);

    Object element = tableItem.getData();
    Object property = fTableViewer.getColumnProperties()[col];
    Object value = cellModifier.getValue(element, (String) property);

    // The cell modifier canModify function always returns false if the edit action 
    // is not invoked from here.  This is to prevent data to be modified when
    // the table cursor loses focus from a cell.  By default, data will
    // be changed in a table when the cell loses focus.  This is to workaround
    // this default behavior and only change data when the cell editor
    // is activated.
    ((TableRenderingCellModifier) cellModifier).setEditActionInvoked(true);
    boolean canEdit = cellModifier.canModify(element, (String) property);
    ((TableRenderingCellModifier) cellModifier).setEditActionInvoked(false);

    if (!canEdit)
        return;

    // activate based on current cursor position
    TextCellEditor selectedEditor = (TextCellEditor) fTableViewer.getCellEditors()[col];

    if (fTableViewer != null && selectedEditor != null) {
        // The control that will be the editor must be a child of the Table
        Text text = (Text) selectedEditor.getControl();

        String cellValue = null;

        if (initialValue != null) {
            cellValue = initialValue;
        } else {
            cellValue = ((String) value);
        }

        text.setText(cellValue);

        fCursorEditor.horizontalAlignment = SWT.LEFT;
        fCursorEditor.grabHorizontal = true;

        // Open the text editor in selected column of the selected row.
        fCursorEditor.setEditor(text, tableItem, col);

        // Assign focus to the text control
        selectedEditor.setFocus();

        if (initialValue != null) {
            text.clearSelection();
        }

        text.setFont(JFaceResources.getFont(IInternalDebugUIConstants.FONT_NAME));

        // add listeners for the text control
        addListeners(text);

        // move cursor below text control
        fTableCursor.moveBelow(text);
    }
}

From source file:org.eclipse.epf.authoring.ui.celleditors.ProcessCheckBoxCellEditor.java

License:Open Source License

public Image getImage(TreeItem item, String columnproperty) {
    final ICellModifier modifier = getCellModifier();
    Object element = item.getData();
    if (element == null)
        return null;
    //      if (columnproperty == IBSItemProvider.COL_IS_ONGOING
    //            || columnproperty == IBSItemProvider.COL_IS_REPEATABLE
    //            || columnproperty == IBSItemProvider.COL_IS_EVENT_DRIVEN) {
    //         if (!(TngUtil.unwrap(element) instanceof WorkBreakdownElement)) {
    //            return null;
    //         }/*from w  ww. jav a2 s .c o m*/
    //      }
    Object value = modifier.getValue(element, columnproperty);
    if (value == null || !(value instanceof Boolean))
        return null;
    boolean canModify = modifier.canModify(element, columnproperty);

    if (((Boolean) value).booleanValue()) {
        return canModify ? checkImage : disableCheckImage;
    } else {
        return canModify ? uncheckImage : disableUncheckImage;
    }
}

From source file:org.eclipse.epf.authoring.ui.celleditors.ProcessCheckBoxCellEditor.java

License:Open Source License

public void modify(TreeItem item, String columnproperty) {
    final ICellModifier modifier = getCellModifier();
    if (!modifier.canModify(item.getData(), columnproperty))
        return;/*from ww  w  .  jav a  2s . co m*/
    modifier.modify(item, columnproperty,
            new Boolean(!((Boolean) modifier.getValue(item.getData(), columnproperty)).booleanValue()));
}

From source file:org.eclipse.mdht.uml.common.ui.util.AdapterFactoryCellModifier.java

License:Open Source License

public Object getValue(Object element, String property) {
    // Get the adapter from the factory.
    ICellModifier cellModifier = (ICellModifier) adapterFactory.adapt(element, ICellModifierClass);

    // Now we could check that the adapter implements interface ICellModifier.
    if (cellModifier != null) {
        // And delegate the call.
        return cellModifier.getValue(element, property);
    }//from  www  .  j  a  v  a  2  s. c om
    return null;
}

From source file:org.eclipsetrader.ui.internal.markets.TimeScheduleEditorTest.java

License:Open Source License

public void testEditOpenTime() throws Exception {
    TimeScheduleEditor editor = new TimeScheduleEditor(shell);
    editor.setSchedule(new MarketTime[] { new MarketTime(getTime(9, 0), getTime(16, 0)), });
    MarketTimeElement element = (MarketTimeElement) editor.getViewer().getTable().getItem(0).getData();
    ICellModifier cellModifier = editor.getViewer().getCellModifier();
    assertTrue(cellModifier.canModify(element, "0"));
    assertEquals(element.getOpenTime(), cellModifier.getValue(element, "0"));
    cellModifier.modify(element, "0", getTime(10, 30));
    assertEquals(getTime(10, 30), element.getOpenTime());
}

From source file:org.eclipsetrader.ui.internal.markets.TimeScheduleEditorTest.java

License:Open Source License

public void testEditCloseTime() throws Exception {
    TimeScheduleEditor editor = new TimeScheduleEditor(shell);
    editor.setSchedule(new MarketTime[] { new MarketTime(getTime(9, 0), getTime(16, 0)), });
    MarketTimeElement element = (MarketTimeElement) editor.getViewer().getTable().getItem(0).getData();
    ICellModifier cellModifier = editor.getViewer().getCellModifier();
    assertTrue(cellModifier.canModify(element, "1"));
    assertEquals(element.getCloseTime(), cellModifier.getValue(element, "1"));
    cellModifier.modify(element, "1", getTime(10, 30));
    assertEquals(getTime(10, 30), element.getCloseTime());
}

From source file:org.eclipsetrader.ui.internal.markets.TimeScheduleEditorTest.java

License:Open Source License

public void testEditDescription() throws Exception {
    TimeScheduleEditor editor = new TimeScheduleEditor(shell);
    editor.setSchedule(new MarketTime[] { new MarketTime(getTime(9, 0), getTime(16, 0)), });
    MarketTimeElement element = (MarketTimeElement) editor.getViewer().getTable().getItem(0).getData();
    ICellModifier cellModifier = editor.getViewer().getCellModifier();
    assertTrue(cellModifier.canModify(element, "2"));
    assertEquals("", cellModifier.getValue(element, "2"));
    cellModifier.modify(element, "2", "New Description");
    assertEquals("New Description", element.getDescription());
}