Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Snippet036FocusBorderCellHighlighter
Snippet036FocusBorderCellHighlighter [message #324715] Thu, 31 January 2008 02:28 Go to next message
Eclipse UserFriend
Hi there,

I am using a DialogCellEditor in the 3rd column instead of a
TextCellEditor. So, when I double-click on the column the cell enters into
an editable mode; which display the label + the button; which is perfect!

However, if I single-click on any other cell/column, then the previous
cell loses its focus; but it is still displaying the button instead of
returning to its original editor value.

If you edit the Snippet036FocusBorderCellHighlighter class and add the
code below (replace DatePickerDialog with any dummy dialog since you don't
need to launch the dialog), you will see the problem.

Is there a workaround for this or is this a bug? Thanks in advance!

..
...
protected class DateDialogCellEditor extends DialogCellEditor {
public DateDialogCellEditor(Composite parent) {
super(parent);
}
@Override
protected Object openDialogBox(Control cellEditorWindow) {
DatePickerDialog dialog = new
DatePickerDialog(cellEditorWindow.getShell());
return dialog.open();
}
}

public Snippet036FocusBorderCellHighlighter(Shell shell) {
...
....
v.setCellEditors(new CellEditor[] { new TextCellEditor(v.getTable()),
new TextCellEditor(v.getTable()), new DateDialogCellEditor(v.getTable())
});
...
..
Re: Snippet036FocusBorderCellHighlighter [message #324716 is a reply to message #324715] Thu, 31 January 2008 02:43 Go to previous messageGo to next message
Eclipse UserFriend
This is a multi-part message in MIME format.
--------------020304090608090103090109
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Hi,

Is there an exception logged (I ask because the return value from
DatePickerDialog is a Date, right)? Isn't there any exception in your
console logged?

I've just tested on OS-X with JFace from HEAD (+ SWT from I20080122)
with the snippet attached and the Editor is correctly disabled. I
replaced your DatePicker (which is not available on my installation with
a standard dialog).

Tom

AJ schrieb:
> Hi there,
>
> I am using a DialogCellEditor in the 3rd column instead of a
> TextCellEditor. So, when I double-click on the column the cell enters
> into an editable mode; which display the label + the button; which is
> perfect!
>
> However, if I single-click on any other cell/column, then the previous
> cell loses its focus; but it is still displaying the button instead of
> returning to its original editor value.
>
> If you edit the Snippet036FocusBorderCellHighlighter class and add the
> code below (replace DatePickerDialog with any dummy dialog since you
> don't need to launch the dialog), you will see the problem.
>
> Is there a workaround for this or is this a bug? Thanks in advance!
>
> .
> ..
> protected class DateDialogCellEditor extends DialogCellEditor {
> public DateDialogCellEditor(Composite parent) {
> super(parent);
> }
> @Override
> protected Object openDialogBox(Control cellEditorWindow) {
> DatePickerDialog dialog = new
> DatePickerDialog(cellEditorWindow.getShell());
> return dialog.open();
> }
> }
>
> public Snippet036FocusBorderCellHighlighter(Shell shell) {
> ...
> ....
> v.setCellEditors(new CellEditor[] { new TextCellEditor(v.getTable()),
> new TextCellEditor(v.getTable()), new DateDialogCellEditor(v.getTable())
> });
> ..
> .
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------

--------------020304090608090103090109
Content-Type: text/plain;
name="Snippet036FocusBorderCellHighlighter.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="Snippet036FocusBorderCellHighlighter.java"

/*********************************************************** ********************
* Copyright (c) 2006 Tom Schindl 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:
* Tom Schindl - initial API and implementation
************************************************************ *******************/

package org.eclipse.jface.snippets.viewers;

import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.resource.FontRegistry;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnViewerEditor;
import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent;
import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrate gy;
import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableColorProvider;
import org.eclipse.jface.viewers.ITableFontProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerEditor;
import org.eclipse.jface.viewers.TableViewerFocusCellManager;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TableColumn;

/**
* Example of a different focus cell rendering with a simply focus border
*
* @author Tom Schindl <tom.schindl@bestsolution.at>
*
*/
public class Snippet036FocusBorderCellHighlighter {

private class MyContentProvider implements IStructuredContentProvider {

/*
* (non-Javadoc)
*
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElem ents(java.lang.Object)
*/
public Object[] getElements(Object inputElement) {
return (MyModel[]) inputElement;
}

/*
* (non-Javadoc)
*
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
*/
public void dispose() {

}

/*
* (non-Javadoc)
*
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org. eclipse.jface.viewers.Viewer,
* java.lang.Object, java.lang.Object)
*/
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {

}

}

public static boolean flag = true;

public class MyModel {
public int counter;

public MyModel(int counter) {
this.counter = counter;
}

public String toString() {
return "Item " + this.counter;
}
}

public class MyLabelProvider extends LabelProvider implements
ITableLabelProvider, ITableFontProvider, ITableColorProvider {
FontRegistry registry = new FontRegistry();

public Image getColumnImage(Object element, int columnIndex) {
return null;
}

public String getColumnText(Object element, int columnIndex) {
return "Column " + columnIndex + " => " + element.toString();
}

public Font getFont(Object element, int columnIndex) {
return null;
}

public Color getBackground(Object element, int columnIndex) {
return null;
}

public Color getForeground(Object element, int columnIndex) {
return null;
}

}

protected class DateDialogCellEditor extends org.eclipse.jface.viewers.DialogCellEditor {
public DateDialogCellEditor(Composite parent) {
super(parent);
}

protected Object openDialogBox(Control cellEditorWindow) {
TitleAreaDialog dialog = new TitleAreaDialog(cellEditorWindow.getShell());
return new Integer(dialog.open());
}
}


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

v.setCellEditors(new CellEditor[] { new TextCellEditor(v.getTable()), new TextCellEditor(v.getTable()), new DateDialogCellEditor(v.getTable()) });
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","2","3"});

TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(v,new FocusBorderCellHighlighter(v));
ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(v) {
protected boolean isEditorActivationEvent(
ColumnViewerEditorActivationEvent event) {
return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
|| event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTI ON
|| (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR)
|| event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
}
};

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


TableColumn column = new TableColumn(v.getTable(), SWT.NONE);
column.setWidth(200);
column.setMoveable(true);
column.setText("Column 1");

column = new TableColumn(v.getTable(), SWT.NONE);
column.setWidth(200);
column.setMoveable(true);
column.setText("Column 2");

column = new TableColumn(v.getTable(), SWT.NONE);
column.setWidth(200);
column.setMoveable(true);
column.setText("Column 3");


MyModel[] model = createModel();
v.setInput(model);
v.getTable().setLinesVisible(true);
v.getTable().setHeaderVisible(true);
}

private MyModel[] createModel() {
MyModel[] elements = new MyModel[10];

for (int i = 0; i < 10; i++) {
elements[i] = new MyModel(i);
}

return elements;
}

/**
* @param args
*/
public static void main(String[] args) {
Display display = new Display();

Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
new Snippet036FocusBorderCellHighlighter(shell);
shell.open();

while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}

display.dispose();

}

}

--------------020304090608090103090109--
Re: Snippet036FocusBorderCellHighlighter [message #324717 is a reply to message #324716] Thu, 31 January 2008 02:49 Go to previous messageGo to next message
Eclipse UserFriend
Tom Schindl schrieb:
> Hi,
>
> Is there an exception logged (I ask because the return value from
> DatePickerDialog is a Date, right)? Isn't there any exception in your
> console logged?
>

Seems I'm not awake (asking the same thing 2 times :-), still I don't
think this can work.

Tom

--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: Snippet036FocusBorderCellHighlighter [message #324733 is a reply to message #324717] Thu, 31 January 2008 08:51 Go to previous messageGo to next message
Eclipse UserFriend
Hi Tom,

The dialog returns a formatted string, however, you don't have to click on
the button or launch the dialog to see the problem.

There are not exceptions reported in the .log file or on the console or
error log views.

I am also running it on OS/X, but I am using the 3.3.1.1 release build.

Sorry, but are you saying that it works fine with the latest 3.4
integration build?

Thanks!
Re: Snippet036FocusBorderCellHighlighter [message #324734 is a reply to message #324733] Thu, 31 January 2008 09:11 Go to previous messageGo to next message
Eclipse UserFriend
Does my snippet produce the same behaviour? Can you give me a detailed
list how to reproduce (1. Click here 2. ...) our send me a completely
runnable snippet with the all code I need (if you don't want to send it
to the list you can send it to me privately).

As said I have tested with JFace from CVS-HEAD 3.4 and SWT from an
integration build. We have fixed many bugs in 3.4 so it could be that
this is why I'm not seeing the problem.

Tom

AJ schrieb:
> Hi Tom,
>
> The dialog returns a formatted string, however, you don't have to click
> on the button or launch the dialog to see the problem.
> There are not exceptions reported in the .log file or on the console or
> error log views.
>
> I am also running it on OS/X, but I am using the 3.3.1.1 release build.
>
> Sorry, but are you saying that it works fine with the latest 3.4
> integration build?
>
> Thanks!


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: Snippet036FocusBorderCellHighlighter [message #324742 is a reply to message #324734] Thu, 31 January 2008 10:18 Go to previous messageGo to next message
Eclipse UserFriend
This is a multi-part message in MIME format.
--------------040006030805080001020802
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Ah. I see. This is an OS-X only problem! If you run this snippet on
win32 where a Button can receive the focus the editor is deactivated
when the cell blurs (by the way the Cursor-Implementation only looks
nice on OS-X and on OS-X I get an NPE when shutting down :-(.

This seems to be a problem nobody ever had when. IMHO the
DialogCellEditor always looks scrambled in OS-X because the button
doesn't fit into the cell.

My suggestion would be fork the current DialogCellEditor remove the
SWT-Button-Stuff and directly open the editor on DoubleClick.

If you want to use the DialogCellEditor as it comes from JFace I think
you have only one chance :-)

You need to cancle an active editor when ever your the focus-cell
changes and an editor is active!

I've attached a patched cursor cell highlighter.

Tom

Tom Schindl schrieb:
> Does my snippet produce the same behaviour? Can you give me a detailed
> list how to reproduce (1. Click here 2. ...) our send me a completely
> runnable snippet with the all code I need (if you don't want to send it
> to the list you can send it to me privately).
>
> As said I have tested with JFace from CVS-HEAD 3.4 and SWT from an
> integration build. We have fixed many bugs in 3.4 so it could be that
> this is why I'm not seeing the problem.
>
> Tom
>
> AJ schrieb:
>> Hi Tom,
>>
>> The dialog returns a formatted string, however, you don't have to
>> click on the button or launch the dialog to see the problem.
>> There are not exceptions reported in the .log file or on the console
>> or error log views.
>>
>> I am also running it on OS/X, but I am using the 3.3.1.1 release build.
>>
>> Sorry, but are you saying that it works fine with the latest 3.4
>> integration build?
>>
>> Thanks!
>
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------

--------------040006030805080001020802
Content-Type: text/plain;
name="CursorCellHighlighter.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="CursorCellHighlighter.java"

/*********************************************************** ********************
* 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
************************************************************ ******************/

package org.eclipse.jface.snippets.viewers;

import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent;
import org.eclipse.jface.viewers.ColumnViewerEditorActivationListen er;
import org.eclipse.jface.viewers.ColumnViewerEditorDeactivationEven t;
import org.eclipse.jface.viewers.FocusCellHighlighter;
import org.eclipse.jface.viewers.ViewerCell;



/**
* @since 3.3
*
*/
public class CursorCellHighlighter extends FocusCellHighlighter {
private ColumnViewer viewer;

private AbstractCellCursor cursor;

/**
* @param viewer
* @param cursor
*/
public CursorCellHighlighter(ColumnViewer viewer,
AbstractCellCursor cursor) {
super(viewer);
this.viewer = viewer;
this.cursor = cursor;
}

protected void focusCellChanged(ViewerCell cell) {
super.focusCellChanged(cell);
if( ! viewer.isCellEditorActive() ) {
cursor.setSelection(cell, 0); //TODO THE TIME
cursor.setVisible(true);
} else {
viewer.cancelEditing();
}
}

protected void init() {
hookListener();
}

private void hookListener() {
ColumnViewerEditorActivationListener listener = new ColumnViewerEditorActivationListener() {

public void afterEditorActivated(
ColumnViewerEditorActivationEvent event) {

}

public void afterEditorDeactivated(
ColumnViewerEditorDeactivationEvent event) {
cursor.setVisible(true);
cursor.setSelection(getFocusCell(), 0); //TODO THE TIME
}

public void beforeEditorActivated(
ColumnViewerEditorActivationEvent event) {
cursor.setVisible(false);
}

public void beforeEditorDeactivated(
ColumnViewerEditorDeactivationEvent event) {

}
};

viewer.getColumnViewerEditor().addEditorActivationListener(l istener);
}
}

--------------040006030805080001020802--
Re: Snippet036FocusBorderCellHighlighter [message #324759 is a reply to message #324742] Thu, 31 January 2008 12:00 Go to previous messageGo to next message
Eclipse UserFriend
Tom,

The attachment fixed it. Thanks a lot!

Is there any plan to fix the cursor implementation for Windows? I am
assuming it will look bad on Linux too.
Re: Snippet036FocusBorderCellHighlighter [message #324762 is a reply to message #324759] Thu, 31 January 2008 12:19 Go to previous messageGo to next message
Eclipse UserFriend
Hi AJ,

Well I can only say when I have time :-) It's only a sample
implementation and nothing we provide as API.

Please log a bug against platform/ui so i doesn't fall of my radar :-)

The API implementation we provide is OwnerDrawCellFocusHighlighter.

Tom

AJ schrieb:
> Tom,
>
> The attachment fixed it. Thanks a lot!
>
> Is there any plan to fix the cursor implementation for Windows? I am
> assuming it will look bad on Linux too.
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: Snippet036FocusBorderCellHighlighter [message #324882 is a reply to message #324742] Mon, 04 February 2008 02:29 Go to previous messageGo to next message
Eclipse UserFriend
Hey Tom,

As per your suggestion, I forked the current DialogCellEditor, removed the
SWT-Button-Stuff, and set to open the editor on DoubleClick. However, it
does it after 2 set of DoubleClicks. The first one switches the cell to
edit mode, then I have to double-click again to open the dialog.

I tried to open the dialog (via focusGained), but it does not seem to
work. So, is there a way to launch the dialog with the first DoubleClick
on the cell?

Thanks!
Re: Snippet036FocusBorderCellHighlighter [message #324888 is a reply to message #324882] Mon, 04 February 2008 03:27 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

Well I'd open the Dialog when CellEditor#activate() is called.

Tom

AJ schrieb:
> Hey Tom,
>
> As per your suggestion, I forked the current DialogCellEditor, removed
> the SWT-Button-Stuff, and set to open the editor on DoubleClick.
> However, it does it after 2 set of DoubleClicks. The first one switches
> the cell to edit mode, then I have to double-click again to open the
> dialog.
>
> I tried to open the dialog (via focusGained), but it does not seem to
> work. So, is there a way to launch the dialog with the first
> DoubleClick on the cell?
>
> Thanks!
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: Snippet036FocusBorderCellHighlighter [message #324904 is a reply to message #324888] Mon, 04 February 2008 07:01 Go to previous messageGo to next message
Eclipse UserFriend
Perfect, that did it. Thanks Tom!
Re: Snippet036FocusBorderCellHighlighter [message #324906 is a reply to message #324904] Mon, 04 February 2008 07:34 Go to previous message
Eclipse UserFriend
You could even only open when (double)clicked (e.g. not when user tabs
into the cell) by overloading
CellEditor#activate(ColumnViewerEditorActivationEvent).

In case the user tabs into the control he/she would e.g. need to press
space to open the editor.

Tom

AJ schrieb:
> Perfect, that did it. Thanks Tom!
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Previous Topic:Single instance of an RCP application
Next Topic:confusing Project.members() behavior
Goto Forum:
  


Current Time: Thu Jul 17 10:24:59 EDT 2025

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

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

Back to the top