Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » wrong position of cursor when editing a cell in a table
wrong position of cursor when editing a cell in a table [message #16727] Fri, 26 June 2009 14:00
maxime hochet is currently offline maxime hochetFriend
Messages: 1
Registered: July 2009
Junior Member
Hello to anyone,

I have a problem with SWT or JFace and I have posted a message in the SWT
newsgroup :

I try to do something with tables using JFace : When the I type on the
keyboard a letter, the TextCellEditor (and its Control : an instance of
Text) must be in editing mode and the key pressed which is the source of
an event must have its value in the field.

For doing this, the faster way I found is to adapt a little bit the JFace
snippet044 :
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jface.s nippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippet s/viewers/Snippet044NoColumnTableViewerKeyboardEditing.java? view=markup

/* --- start code added --- */
private boolean keyPressed;

private char eventChar;

/* --- end code added --- */

public Snippet044NoColumnTableViewerKeyboardEditing(Shell shell) {
final TableViewer v = new TableViewer(shell, SWT.BORDER |
SWT.FULL_SELECTION);
v.setLabelProvider(new MyLabelProvider());
v.setContentProvider(new MyContentProvider());

/* --- start code added --- */
CellEditor cellEditor = new TextCellEditor(v.getTable());
final Text text = (Text) cellEditor.getControl();

text.addFocusListener(new FocusListener() {

@Override
public void focusGained(FocusEvent e) {

if (keyPressed) {
String myString = String.valueOf(eventChar);
text.setText(myString);
}

}

@Override
public void focusLost(FocusEvent e) {
keyPressed = false;
}
});

v.setCellEditors(new CellEditor[] { cellEditor });
/* --- end code added --- */

v.setCellModifier(new ICellModifier() {

public boolean canModify(Object element, String property) {
return true;
}

public Object getValue(Object element, String property) {
return "Column " + property + " => " + element.toString();
}

public void modify(Object element, String property, Object
value) {

}

});

v.setColumnProperties(new String[] { "1" });

TableViewerFocusCellManager focusCellManager = new
TableViewerFocusCellManager(v,
new FocusCellOwnerDrawHighlighter(v));
ColumnViewerEditorActivationStrategy actSupport = new
ColumnViewerEditorActivationStrategy(
v) {
protected boolean
isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {

/* --- start code added --- */
boolean toReturn = event.eventType ==
ColumnViewerEditorActivationEvent.TRAVERSAL
|| event.eventType ==
ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTI ON
|| (event.eventType ==
ColumnViewerEditorActivationEvent.KEY_PRESSED && Character
.isLetter(event.character))
|| event.eventType ==
ColumnViewerEditorActivationEvent.PROGRAMMATIC;

if (event.eventType ==
ColumnViewerEditorActivationEvent.KEY_PRESSED
&& Character.isLetter(event.character)) {
keyPressed = true;
eventChar = (char) event.keyCode;
}
/* --- end code added --- */

return toReturn;
}
};

TableViewerEditor.create(
v,
focusCellManager,
actSupport,
ColumnViewerEditor.TABBING_HORIZONTAL
| ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
| ColumnViewerEditor.TABBING_VERTICAL
| ColumnViewerEditor.KEYBOARD_ACTIVATION);
...


I have now a problem, the cursor in the field is left positioned and I
would like it right positioned. And I don’t know how to do this. When I
type ‘abc’, the result displayed is ‘bca’.

Should I use other classes?

Thanks for any help.

Maxime.

NB : When a cell is in an editing mode, if I close the window, I get a
org.eclipse.swt.SWTException.
Previous Topic:Changing the focus button in a wizard page or launch tab
Next Topic:A composite on top of another one.
Goto Forum:
  


Current Time: Tue Apr 16 21:20:52 GMT 2024

Powered by FUDForum. Page generated in 1.03516 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top