Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Focus is not coming out of custom cell editor.
Focus is not coming out of custom cell editor. [message #1752411] Mon, 23 January 2017 14:21 Go to next message
Naveen Sabapathy is currently offline Naveen SabapathyFriend
Messages: 46
Registered: July 2016
Member
I have built a custom cell editor based on CDateTime for the Date/ Time field. While my editor is active, if I'm clicking a widget(Button) outside the nattable. The click handler is not getting invoked immediately. I need to press the button again to invoke the action in clickhandler.

How to avoid this condition?

package com.bmw.rac.pruefcubing.ptiview;

import java.util.Date;

import org.eclipse.nebula.widgets.cdatetime.CDT;
import org.eclipse.nebula.widgets.cdatetime.CDateTime;
import org.eclipse.nebula.widgets.nattable.edit.editor.AbstractCellEditor;
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum;
import org.eclipse.nebula.widgets.nattable.style.CellStyleAttributes;
import org.eclipse.nebula.widgets.nattable.widget.EditModeEnum;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

public class V4BPCCDateCellEditor extends AbstractCellEditor {

	/**
	 * The DateTime control which is the editor wrapped by this DateCellEditor.
	 */
	private CDateTime dateTime;

	/**
	 * Flag to configure whether the selection should move after a value was
	 * committed after pressing enter.
	 */
	private final boolean moveSelectionOnEnter;

	/**
	 * Date pattern
	 */
	private String pattern;

	/**
	 * Creates the default DateCellEditor that does not move the selection on
	 * committing the value by pressing enter.
	 */
	public V4BPCCDateCellEditor(String pattern) {
		this(false);
		this.pattern = pattern;
	}

	/**
	 * Creates a DateCellEditor.
	 *
	 * @param moveSelectionOnEnter
	 *            Flag to configure whether the selection should move after a
	 *            value was committed after pressing enter.
	 */
	public V4BPCCDateCellEditor(boolean moveSelectionOnEnter) {
		this.moveSelectionOnEnter = moveSelectionOnEnter;
	}

	@Override
	public Object getEditorValue() {
		return dateTime.getSelection();
	}

	@Override
	public void setEditorValue(Object value) {
		// in setCanonicalValue() we ensure that the value is of type Calendar
		// but an additional check to ensure type safety doesn't hurt
		if (value instanceof Date) {
			dateTime.setSelection((Date) value);
		}
	}

	@Override
	public CDateTime getEditorControl() {
		return dateTime;
	}

	@Override
	public CDateTime createEditorControl(final Composite parent1) {

		CDateTime dateControl = createCDateTime();
		dateControl.setPattern(pattern);
		// set style information configured in the associated cell style
		dateControl.setBackground(this.cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR));
		dateControl.setForeground(this.cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR));
		dateControl.setFont(this.cellStyle.getAttributeValue(CellStyleAttributes.FONT));

		// add a key listener that will commit or close the editor for special
		// key strokes
		dateControl.addKeyListener(new KeyAdapter() {

			@Override
			public void keyPressed(KeyEvent event) {
				if (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) {

					boolean commit = (event.stateMask == SWT.MOD3) ? false : true;
					MoveDirectionEnum move = MoveDirectionEnum.NONE;
					if (V4BPCCDateCellEditor.this.moveSelectionOnEnter
							&& V4BPCCDateCellEditor.this.editMode == EditModeEnum.INLINE) {
						if (event.stateMask == 0) {
							move = MoveDirectionEnum.DOWN;
						} else if (event.stateMask == SWT.MOD2) {
							move = MoveDirectionEnum.UP;
						}
					}

					if (commit)
						commit(move);

					if (V4BPCCDateCellEditor.this.editMode == EditModeEnum.DIALOG) {
						parent1.forceFocus();
					}
				} else if (event.keyCode == SWT.ESC && event.stateMask == 0) {
					close();
				}
			}
		});

		return dateControl;
	}

	@Override
	protected Control activateCell(Composite parent1, Object originalCanonicalValue) {
		this.dateTime = createEditorControl(parent1);
		this.dateTime.forceFocus();
		setCanonicalValue(originalCanonicalValue);
		return this.dateTime;
	}

	private CDateTime createCDateTime() {
		return new CDateTime(parent,CDT.BORDER | CDT.SPINNER | CDT.TAB_FIELDS | CDT.TIME_SHORT | CDT.DATE_SHORT);
	}
}
Re: Focus is not coming out of custom cell editor. [message #1752414 is a reply to message #1752411] Mon, 23 January 2017 14:48 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
You need some focus listeners. The best would be to check the provided implementation in the NatTable Nebula Extension added with https://bugs.eclipse.org/bugs/show_bug.cgi?id=497710 which will be released with NatTable 1.5

http://git.eclipse.org/c/nattable/org.eclipse.nebula.widgets.nattable.git/tree/org.eclipse.nebula.widgets.nattable.extension.nebula/src/org/eclipse/nebula/widgets/nattable/extension/nebula/cdatetime/CDateTimeCellEditor.java
Re: Focus is not coming out of custom cell editor. [message #1752418 is a reply to message #1752414] Mon, 23 January 2017 15:51 Go to previous messageGo to next message
Naveen Sabapathy is currently offline Naveen SabapathyFriend
Messages: 46
Registered: July 2016
Member
Thanks for the solution. When is the expected release of Nattable 1.5. Eagerly waiting for that.

Re: Focus is not coming out of custom cell editor. [message #1752420 is a reply to message #1752418] Mon, 23 January 2017 16:04 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
No concrete plans as I still wait for feedback on several additions. But don't expect it before March, as we depend on Nebula 1.2 for the latest RichText updates. And that release is planned for end of February https://projects.eclipse.org/projects/technology.nebula
Re: Focus is not coming out of custom cell editor. [message #1752631 is a reply to message #1752420] Wed, 25 January 2017 16:39 Go to previous messageGo to next message
Naveen Sabapathy is currently offline Naveen SabapathyFriend
Messages: 46
Registered: July 2016
Member
Thanks for the reply. Regarding the main query related to focus.
Is that the issue solved with the provided inline cell editor? After implementing the change also I'm facing the same issue.
Re: Focus is not coming out of custom cell editor. [message #1752682 is a reply to message #1752631] Thu, 26 January 2017 07:35 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Without debugging into details it looks to me like an issue with the CDAteTime widget. If you use the dropdowns, they are catching the focus events and therefore the click doesn't reach the button. If it is in inline mode, the widget does not close and the button click is performed.

I would need to debug into that specific issue in more detail to tell you more. But currently my time is planned for other things. If you find a solution feel free to post it here or even create a patch we can include.
Previous Topic:TreeLayer: Retrieve items lazily does not work properly
Next Topic:ComboBoxCellEditor can't save custom input value
Goto Forum:
  


Current Time: Fri Apr 26 07:35:47 GMT 2024

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

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

Back to the top