Editing Support beim JFace TableViewer

HarryXVI

Erfahrenes Mitglied
Hallo,
ich möchte die Zellen meines JFace TableViewers editierbar machen. Dazu habe ich das Tutorial von Lars Vogel (http://www.vogella.de/articles/EclipseJFaceTableAdvanced/article.html) durchgearbeitet und folgenden Code erstellt.


Java:
public class ColumnEditingSupport extends EditingSupport {
...
public ColumnEditingSupport(TableViewer tv_viewer, int column) {
		super(tv_viewer);
		this.viewer = tv_viewer;
		this.col_number = column;
	}
	
	@Override
	protected CellEditor getCellEditor(Object element) {
		// TODO Auto-generated method stub
		return new TextCellEditor(viewer.getTable());
	}

	@Override
	protected boolean canEdit(Object element) {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	protected Object getValue(Object element) {
		// TODO Auto-generated method stub
		return ((FieldRow) element).getValueAtColumn(col_number);
	}

	@Override
	protected void setValue(Object element, Object value) {
		// TODO Auto-generated method stub
		((FieldRow) element).setValueAtColumn(col_number, (String) value);
		viewer.refresh(element);
	}
}

In einer for-Schleife werden die Spalten des TableViewers erstellt:
Java:
final int current_col = i;
TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE);
TableColumn column = viewerColumn.getColumn();
column.setText(String.valueOf((char)(i+65)));
column.setWidth(20);
column.setResizable(true);
column.setMoveable(false);
viewerColumn.setLabelProvider(new CellLabelProvider() {
				
	@Override
	public void update(ViewerCell cell) {
		cell.setText( ((FieldRow) cell.getElement()).getValueAtColumn(current_col) );
				}
	});

viewerColumn.setEditingSupport(new ColumnEditingSupport(viewer, current_col));

Im Programm lässt sich eine Zelle im TableViewer anklicken und so markieren, als ob man sie editieren könnte. Wenn ich dann jedoch eine Taste drücke (Buchstabe, Zahl, etc.), wirft eclipse folgende Exception:

Java:
java.lang.NullPointerException
	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.isPartialMatch(KeyBindingDispatcher.java:478)
	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.press(KeyBindingDispatcher.java:505)
	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.processKeyEvent(KeyBindingDispatcher.java:563)
	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.filterKeySequenceBindings(KeyBindingDispatcher.java:374)
	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.access$0(KeyBindingDispatcher.java:321)
	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher$KeyDownFilter.handleEvent(KeyBindingDispatcher.java:82)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1262)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1052)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1062)
	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1104)
	at org.eclipse.swt.widgets.Text.sendKeyEvent(Text.java:1455)
	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1100)
	at org.eclipse.swt.widgets.Widget.wmChar(Widget.java:1509)
	at org.eclipse.swt.widgets.Control.WM_CHAR(Control.java:4640)
	at org.eclipse.swt.widgets.Text.WM_CHAR(Text.java:2259)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4528)
	at org.eclipse.swt.widgets.Text.windowProc(Text.java:2254)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4972)
	at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2531)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3752)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:969)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:885)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:90)
	at org.eclipse.e4.ui.internal.workbench.swt.E4Application.start(E4Application.java:145)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
java.lang.NullPointerException
	at org.eclipse.e4.ui.internal.workbench.swt.ShellActivationListener.getShellContext(ShellActivationListener.java:193)
	at org.eclipse.e4.ui.internal.workbench.swt.ShellActivationListener.activate(ShellActivationListener.java:114)
	at org.eclipse.e4.ui.internal.workbench.swt.ShellActivationListener.handleEvent(ShellActivationListener.java:73)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1262)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1052)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1058)
	at org.eclipse.swt.widgets.Decorations.WM_ACTIVATE(Decorations.java:1647)
	at org.eclipse.swt.widgets.Shell.WM_ACTIVATE(Shell.java:2137)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4525)
	at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:341)
	at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1610)
	at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:2061)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4972)
	at org.eclipse.swt.internal.win32.OS.BringWindowToTop(Native Method)
	at org.eclipse.swt.widgets.Decorations.bringToTop(Decorations.java:230)
	at org.eclipse.swt.widgets.Shell.open(Shell.java:1217)
	at org.eclipse.jface.window.Window.open(Window.java:797)
	at org.eclipse.jface.dialogs.ErrorDialog.open(ErrorDialog.java:360)
	at org.eclipse.e4.ui.internal.workbench.swt.WorkbenchStatusReporter.openDialog(WorkbenchStatusReporter.java:97)
	at org.eclipse.e4.ui.internal.workbench.swt.WorkbenchStatusReporter.report(WorkbenchStatusReporter.java:54)
	at org.eclipse.e4.core.services.statusreporter.StatusReporter.show(StatusReporter.java:132)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.safeHandle(PartRenderingEngine.java:1006)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.handle(PartRenderingEngine.java:990)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:978)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:885)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:90)
	at org.eclipse.e4.ui.internal.workbench.swt.E4Application.start(E4Application.java:145)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1386)

NullPointerExceptions sind mir nicht neu, aber in diesem Kontext kann ich überhaupt nichts damit anfangen. Weiß jemand Rat? Ich bin für eure Hilfe sehr dankbar.
 

genodeftest

Erfahrenes Mitglied
Klingt nach nem Bug in Eclipse. Wenn du die aktuellste Version von Eclipse verwendest, solltest du es mal unter https://bugs.eclipse.org/bugs/ melden.

EDIT: Zur Erklärung: In dem Stacktrace findet sich offensichtlich keine von dir erstellte Methode oder Klasse, damit hat irgend ein Teil der Eclipse-API den Fehler selbst erzeugt oder von dir übergebene Daten nicht ausreichend geprüft. Hast du irgend etwas an den Key Bindings gesetzt?

PS: probier doch erst mal, ob es sich evtl. um einen Konfigurationsfehler handelt, indem du deine Eclipse-Anwendung mal auf einen neuen „workspace“ loslässt und sicherstellst, dass diese Exception dort auch auftritt.
 
Zuletzt bearbeitet: