
org.eclipse.jface.viewers.TableViewerEditor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jface Show documentation
Show all versions of jface Show documentation
JFace is a UI toolkit with classes for handling many common UI programming tasks. JFace is window-system-independent in both its API and implementation, and is designed to work with SWT without hiding it. JFace includes the usual UI toolkit components of image and font registries, text, dialog, preference and wizard frameworks, and progress reporting for long running operations. Two of its more interesting features are actions and viewers. The action mechanism allows user commands to be defined independently from their exact whereabouts in the UI. Viewers are model based adapters for certain SWT widgets, simplifying the presentation of application data structured as lists, tables or trees.
The newest version!
/*******************************************************************************
* Copyright (c) 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
* Tom Schindl - initial API and implementation
* fixes in bug 198665
******************************************************************************/
package org.eclipse.jface.viewers;
import java.util.List;
import org.eclipse.jface.viewers.CellEditor.LayoutData;
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Item;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
/**
* This is an editor-implementation for {@link Table}
*
* @since 3.3
*
*/
public final class TableViewerEditor extends ColumnViewerEditor {
/**
* This viewer's table editor.
*/
private TableEditor tableEditor;
private SWTFocusCellManager focusCellManager;
/**
* @param viewer
* the viewer the editor is attached to
* @param focusCellManager
* the cell focus manager if one used or null
* @param editorActivationStrategy
* the strategy used to decide about the editor activation
* @param feature
* the feature mask
*/
TableViewerEditor(TableViewer viewer, SWTFocusCellManager focusCellManager,
ColumnViewerEditorActivationStrategy editorActivationStrategy,
int feature) {
super(viewer, editorActivationStrategy, feature);
tableEditor = new TableEditor(viewer.getTable());
this.focusCellManager = focusCellManager;
}
/**
* Create a customized editor with focusable cells
*
* @param viewer
* the viewer the editor is created for
* @param focusCellManager
* the cell focus manager if one needed else null
* @param editorActivationStrategy
* activation strategy to control if an editor activated
* @param feature
* bit mask controlling the editor
*
* - {@link ColumnViewerEditor#DEFAULT}
* - {@link ColumnViewerEditor#TABBING_CYCLE_IN_ROW}
* - {@link ColumnViewerEditor#TABBING_HORIZONTAL}
* - {@link ColumnViewerEditor#TABBING_MOVE_TO_ROW_NEIGHBOR}
* - {@link ColumnViewerEditor#TABBING_VERTICAL}
*
* @see #create(TableViewer, ColumnViewerEditorActivationStrategy, int)
*/
public static void create(TableViewer viewer,
SWTFocusCellManager focusCellManager,
ColumnViewerEditorActivationStrategy editorActivationStrategy,
int feature) {
TableViewerEditor editor = new TableViewerEditor(viewer,
focusCellManager, editorActivationStrategy, feature);
viewer.setColumnViewerEditor(editor);
if (focusCellManager != null) {
focusCellManager.init();
}
}
/**
* Create a customized editor whose activation process is customized
*
* @param viewer
* the viewer the editor is created for
* @param editorActivationStrategy
* activation strategy to control if an editor activated
* @param feature
* bit mask controlling the editor
*
* - {@link ColumnViewerEditor#DEFAULT}
* - {@link ColumnViewerEditor#TABBING_CYCLE_IN_ROW}
* - {@link ColumnViewerEditor#TABBING_HORIZONTAL}
* - {@link ColumnViewerEditor#TABBING_MOVE_TO_ROW_NEIGHBOR}
* - {@link ColumnViewerEditor#TABBING_VERTICAL}
*
*/
public static void create(TableViewer viewer,
ColumnViewerEditorActivationStrategy editorActivationStrategy,
int feature) {
create(viewer, null, editorActivationStrategy, feature);
}
protected void setEditor(Control w, Item item, int columnNumber) {
tableEditor.setEditor(w, (TableItem) item, columnNumber);
}
protected void setLayoutData(LayoutData layoutData) {
tableEditor.grabHorizontal = layoutData.grabHorizontal;
tableEditor.horizontalAlignment = layoutData.horizontalAlignment;
tableEditor.minimumWidth = layoutData.minimumWidth;
}
public ViewerCell getFocusCell() {
if (focusCellManager != null) {
return focusCellManager.getFocusCell();
}
return super.getFocusCell();
}
protected void updateFocusCell(ViewerCell focusCell,
ColumnViewerEditorActivationEvent event) {
// Update the focus cell when we activated the editor with these 2
// events
if (event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC
|| event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL) {
List l = getViewer().getSelectionFromWidget();
if (focusCellManager != null) {
focusCellManager.setFocusCell(focusCell);
}
if (!l.contains(focusCell.getElement())) {
getViewer().setSelection(
new StructuredSelection(focusCell.getElement()),true);
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy