Home » Eclipse Projects » Eclipse Platform » JFace 3.3 TableViewer, DialogCellEditor, Tabhandling
JFace 3.3 TableViewer, DialogCellEditor, Tabhandling [message #316425] |
Mon, 11 June 2007 10:27 |
Eclipse User |
|
|
|
Originally posted by: rainer.blesssing.impulsus.de
Hello,
the ColumnViewerEditor is not getting notified by the button in
DialogCellEditor if there is a traverse event (Tab is pressed to get to the
next cell). I tried to adding a traverse event handler like in CCombo, but
it seems not to be enough, because the event does not reach the
ColumnViewerEditor which handles the event.
Rainer
|
|
| | |
Re: JFace 3.3 TableViewer, DialogCellEditor, Tabhandling [message #316442 is a reply to message #316434] |
Mon, 11 June 2007 14:24 |
Eclipse User |
|
|
|
Originally posted by: rainer.blesssing.impulsus.de
Hello Tom,
thanks for your quick reply.
> Tom Schindl schrieb:
> > Hi,
> >
> > Could you please provide a minimal code-snippet I can run locally to see
> > what's happening.
> >
> > If there's really a problem we can fix it in 3.3.1 for 3.3.0 it's too
> > late.
> >
> > Tom
> >
The ColumnViewerEditor which handles the Tab Event, registers the
eventhandler to the control which is returned
by CellEditor.getControl() (Line 176 in ColumnViewerEditor).
But DialogCellEditor returns a Composite as the control and not the Button
which has the focus.
The addition of a traverse listener to the button fixes it (first code
snippet).
Rainer
------------------------------------------------------
/**
* Creates the button for this cell editor under the given parent control.
* <p>
* The default implementation of this framework method creates the button
* display on the right hand side of the dialog cell editor. Subclasses may
* extend or reimplement.
* </p>
*
* @param parent
* the parent control
* @return the new button control
*/
protected Button createButton(Composite parent) {
Button result = new Button(parent, SWT.DOWN);
result.setText("..."); //$NON-NLS-1$
result.addListener(SWT.Traverse,new Listener() {
public void handleEvent(Event e) {
editor.notifyListeners(SWT.Traverse, e);
}
});
return result;
}
---------------------------------
package org.eclipse.jface.snippets.viewers;
import java.text.MessageFormat;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.DialogCellEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Layout;
public class TestDialogCellEditor extends CellEditor {
/**
* Image registry key for three dot image (value
* <code>"cell_editor_dots_button_image"</code>).
*/
public static final String CELL_EDITOR_IMG_DOTS_BUTTON =
"cell_editor_dots_button_image";//$NON-NLS-1$
/**
* The editor control.
*/
private Composite editor;
/**
* The current contents.
*/
private Control contents;
/**
* The label that gets reused by <code>updateLabel</code>.
*/
private Label defaultLabel;
/**
* The button.
*/
private Button button;
/**
* Listens for 'focusLost' events and fires the 'apply' event as long as
the
* focus wasn't lost because the dialog was opened.
*/
private FocusListener buttonFocusListener;
/**
* The value of this cell editor; initially <code>null</code>.
*/
private Object value = null;
static {
ImageRegistry reg = JFaceResources.getImageRegistry();
reg.put(CELL_EDITOR_IMG_DOTS_BUTTON, ImageDescriptor.createFromFile(
DialogCellEditor.class, "images/dots_button.gif"));//$NON-NLS-1$
}
/**
* Internal class for laying out the dialog.
*/
private class DialogCellLayout extends Layout {
public void layout(Composite editor, boolean force) {
Rectangle bounds = editor.getClientArea();
Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, force);
if (contents != null) {
contents.setBounds(0, 0, bounds.width - size.x, bounds.height);
}
button.setBounds(bounds.width - size.x, 0, size.x, bounds.height);
}
public Point computeSize(Composite editor, int wHint, int hHint,
boolean force) {
if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT) {
return new Point(wHint, hHint);
}
Point contentsSize = contents.computeSize(SWT.DEFAULT, SWT.DEFAULT,
force);
Point buttonSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT,
force);
// Just return the button width to ensure the button is not clipped
// if the label is long.
// The label will just use whatever extra width there is
Point result = new Point(buttonSize.x, Math.max(contentsSize.y,
buttonSize.y));
return result;
}
}
/**
* Default DialogCellEditor style
*/
private static final int defaultStyle = SWT.NONE;
/**
* Creates a new dialog cell editor with no control
*
* @since 2.1
*/
public TestDialogCellEditor() {
setStyle(defaultStyle);
}
/**
* Creates a new dialog cell editor parented under the given control. The
* cell editor value is <code>null</code> initially, and has no validator.
*
* @param parent
* the parent control
*/
protected TestDialogCellEditor(Composite parent) {
this(parent, defaultStyle);
}
/**
* Creates a new dialog cell editor parented under the given control. The
* cell editor value is <code>null</code> initially, and has no validator.
*
* @param parent
* the parent control
* @param style
* the style bits
* @since 2.1
*/
protected TestDialogCellEditor(Composite parent, int style) {
super(parent, style);
}
/**
* Creates the button for this cell editor under the given parent control.
* <p>
* The default implementation of this framework method creates the button
* display on the right hand side of the dialog cell editor. Subclasses may
* extend or reimplement.
* </p>
*
* @param parent
* the parent control
* @return the new button control
*/
protected Button createButton(Composite parent) {
Button result = new Button(parent, SWT.DOWN);
result.setText("..."); //$NON-NLS-1$
return result;
}
/**
* Creates the controls used to show the value of this cell editor.
* <p>
* The default implementation of this framework method creates a label
* widget, using the same font and background color as the parent control.
* </p>
* <p>
* Subclasses may reimplement. If you reimplement this method, you should
* also reimplement <code>updateContents</code>.
* </p>
*
* @param cell
* the control for this cell editor
* @return the underlying control
*/
protected Control createContents(Composite cell) {
defaultLabel = new Label(cell, SWT.LEFT);
defaultLabel.setFont(cell.getFont());
defaultLabel.setBackground(cell.getBackground());
return defaultLabel;
}
/*
* (non-Javadoc) Method declared on CellEditor.
*/
protected Control createControl(Composite parent) {
Font font = parent.getFont();
Color bg = parent.getBackground();
editor = new Composite(parent, getStyle());
editor.setFont(font);
editor.setBackground(bg);
editor.setLayout(new DialogCellLayout());
contents = createContents(editor);
updateContents(value);
button = createButton(editor);
button.setFont(font);
button.addKeyListener(new KeyAdapter() {
/*
* (non-Javadoc)
*
* @see
org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.s wt.events.KeyEvent)
*/
public void keyReleased(KeyEvent e) {
if (e.character == '\u001b') { // Escape
fireCancelEditor();
}
}
});
button.addFocusListener(getButtonFocusListener());
button.addSelectionListener(new SelectionAdapter() {
/*
* (non-Javadoc)
*
* @see
org.eclipse.swt.events.SelectionListener#widgetSelected(org. eclipse.swt.events.SelectionEvent)
*/
public void widgetSelected(SelectionEvent event) {
// Remove the button's focus listener since it's guaranteed
// to lose focus when the dialog opens
button.removeFocusListener(getButtonFocusListener());
Object newValue = openDialogBox(editor);
// Re-add the listener once the dialog closes
button.addFocusListener(getButtonFocusListener());
if (newValue != null) {
boolean newValidState = isCorrect(newValue);
if (newValidState) {
markDirty();
doSetValue(newValue);
} else {
// try to insert the current value into the error
// message.
setErrorMessage(MessageFormat.format(getErrorMessage(),
new Object[] { newValue.toString() }));
}
fireApplyEditorValue();
}
}
});
setValueValid(true);
return button;
// return editor;
}
/*
* (non-Javadoc)
*
* Override in order to remove the button's focus listener if the
celleditor
* is deactivating.
*
* @see org.eclipse.jface.viewers.CellEditor#deactivate()
*/
public void deactivate() {
if (button != null && !button.isDisposed()) {
button.removeFocusListener(getButtonFocusListener());
}
super.deactivate();
}
/*
* (non-Javadoc) Method declared on CellEditor.
*/
protected Object doGetValue() {
return value;
}
/*
* (non-Javadoc) Method declared on CellEditor. The focus is set to the
cell
* editor's button.
*/
protected void doSetFocus() {
button.setFocus();
// add a FocusListener to the button
button.addFocusListener(getButtonFocusListener());
}
/**
* Return a listener for button focus.
*
* @return FocusListener
*/
private FocusListener getButtonFocusListener() {
if (buttonFocusListener == null) {
buttonFocusListener = new FocusListener() {
/*
* (non-Javadoc)
*
* @see
org.eclipse.swt.events.FocusListener#focusGained(org.eclipse .swt.events.FocusEvent)
*/
public void focusGained(FocusEvent e) {
// Do nothing
}
/*
* (non-Javadoc)
*
* @see
org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.s wt.events.FocusEvent)
*/
public void focusLost(FocusEvent e) {
TestDialogCellEditor.this.focusLost();
}
};
}
return buttonFocusListener;
}
/*
* (non-Javadoc) Method declared on CellEditor.
*/
protected void doSetValue(Object value) {
this.value = value;
updateContents(value);
}
/**
* Returns the default label widget created by <code>createContents</code>.
*
* @return the default label widget
*/
protected Label getDefaultLabel() {
return defaultLabel;
}
/**
* Opens a dialog box under the given parent control and returns the
* dialog's value when it closes, or <code>null</code> if the dialog was
* canceled or no selection was made in the dialog.
* <p>
* This framework method must be implemented by concrete subclasses. It is
* called when the user has pressed the button and the dialog box must pop
* up.
* </p>
*
* @param cellEditorWindow
* the parent control cell editor's window so that a subclass
can
* adjust the dialog box accordingly
* @return the selected value, or <code>null</code> if the dialog was
* canceled or no selection was made in the dialog
*/
protected Object openDialogBox(Control cellEditorWindow) {
// TODO Auto-generated method stub
return null;
}
/**
* Updates the controls showing the value of this cell editor.
* <p>
* The default implementation of this framework method just converts the
* passed object to a string using <code>toString</code> and sets this as
* the text of the label widget.
* </p>
* <p>
* Subclasses may reimplement. If you reimplement this method, you should
* also reimplement <code>createContents</code>.
* </p>
*
* @param value
* the new value of this cell editor
*/
protected void updateContents(Object value) {
if (defaultLabel == null) {
return;
}
String text = "";//$NON-NLS-1$
if (value != null) {
text = value.toString();
}
defaultLabel.setText(text);
}
}
|
|
| | | |
Re: JFace 3.3 TableViewer, DialogCellEditor, Tabhandling [message #337014 is a reply to message #316750] |
Tue, 21 July 2009 08:43 |
Eclipse User |
|
|
|
Originally posted by: bjoern.bjoernfischer.de
Hello everybody,
this issue an the bug is about two years old now. Will this be fixed or
can it be considered as NOFIX?
Regards,
Björn
Rainer Blessing schrieb:
> Hello!
>
> "Daniel Krügler" <dsp@bdal.de> schrieb im Newsbeitrag
> news:f4lmsu$c3h$1@build.eclipse.org...
>> Tom Schindl wrote:
>>> Would you be so kind to file a bug (against Platform/UI) and CC me. I'll
>>> then take care of it and see how we can fix this. If you could file a
>>> seperate bug for the snippet I'll integrate it into our collection.
>> Please provide the bug# also in this group that we can vote for it!
>>
>
> The bug # is: 193081
>
>
> Rainer Blessing
>
>
|
|
|
Goto Forum:
Current Time: Fri Sep 20 03:52:25 GMT 2024
Powered by FUDForum. Page generated in 0.04070 seconds
|