Home » Eclipse Projects » Eclipse Platform » How can I use inplace editing on singleclick and open a dialog on doubleclick ?
| |
Re: How can I use inplace editing on singleclick and open a dialog on doubleclick ? [message #331204 is a reply to message #331176] |
Thu, 28 August 2008 08:57 |
Eclipse User |
|
|
|
Originally posted by: user.domain.invalid
Tom Schindl schrieb:
> Well I guess this is supported out of the box because whenever you
> double click on a cell the first click is enableing the CellEditor and
> if the second click occurs in time of the double-click timeout the
> editor is disabled and a doubleClick-Event on the control is issued.
Unfortunatly this is not the case. I've added a mouselistener that
prints to console, it's never called.
Please try to run the snippet below.
This can be reproduzed both on 3.3. and 3.4.
Or maybe I'm just missing something ?
Regards,
Yves Harms
/*********************************************************** ********************
* 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
************************************************************ *******************/
import java.util.ArrayList;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.TreeViewerColumn;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
/**
* A simple TreeViewer to demonstrate usage
*
* @author Tom Schindl <tom.schindl@bestsolution.at>
*
*/
public class Snippet026TreeViewerTabEditing {
public Snippet026TreeViewerTabEditing(final Shell shell) {
final TreeViewer v = new TreeViewer(shell, SWT.BORDER
| SWT.FULL_SELECTION|SWT.MULTI);
v.getTree().setLinesVisible(true);
v.getTree().setHeaderVisible(true);
v.addSelectionChangedListener(new ISelectionChangedListener(){
public void selectionChanged(SelectionChangedEvent event)
{
System.out.println(((StructuredSelection)event.getSelection( )).size());
}});
v.getTree().addMouseListener(new MouseAdapter(){
@Override
public void mouseDoubleClick(MouseEvent e)
{
System.out.println("double click");
}
});
// TreeViewerFocusCellManager focusCellManager = new
TreeViewerFocusCellManager(v,new FocusCellOwnerDrawHighlighter(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;
// }
// };
//
// TreeViewerEditor.create(v, focusCellManager, actSupport,
ColumnViewerEditor.TABBING_HORIZONTAL
// | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
// | ColumnViewerEditor.TABBING_VERTICAL);
final TextCellEditor textCellEditor = new
TextCellEditor(v.getTree());
TreeViewerColumn column = new TreeViewerColumn(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setMoveable(true);
column.getColumn().setText("Column 1");
column.setLabelProvider(new ColumnLabelProvider() {
public String getText(Object element) {
return "Column 1 => " + element.toString();
}
});
column.setEditingSupport(new EditingSupport(v) {
protected boolean canEdit(Object element) {
return false;
}
protected CellEditor getCellEditor(Object element) {
return textCellEditor;
}
protected Object getValue(Object element) {
return ((MyModel) element).counter + "";
}
protected void setValue(Object element, Object value) {
((MyModel) element).counter = Integer
.parseInt(value.toString());
v.update(element, null);
}
});
column = new TreeViewerColumn(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setMoveable(true);
column.getColumn().setText("Column 2");
column.setLabelProvider(new ColumnLabelProvider() {
public String getText(Object element) {
return "Column 2 => " + element.toString();
}
});
column.setEditingSupport(new EditingSupport(v) {
protected boolean canEdit(Object element) {
return true;
}
protected CellEditor getCellEditor(Object element) {
return textCellEditor;
}
protected Object getValue(Object element) {
return ((MyModel) element).counter + "";
}
protected void setValue(Object element, Object value) {
((MyModel) element).counter = Integer
.parseInt(value.toString());
v.update(element, null);
}
});
column = new TreeViewerColumn(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setMoveable(true);
column.getColumn().setText("Column 3");
column.setLabelProvider(new ColumnLabelProvider() {
public String getText(Object element) {
return "Column 3 => " + element.toString();
}
});
column.setEditingSupport(new EditingSupport(v) {
protected boolean canEdit(Object element) {
return true;
}
protected CellEditor getCellEditor(Object element) {
return textCellEditor;
}
protected Object getValue(Object element) {
return ((MyModel) element).counter + "";
}
protected void setValue(Object element, Object value) {
((MyModel) element).counter = Integer
.parseInt(value.toString());
v.update(element, null);
}
});
v.setContentProvider(new MyContentProvider());
v.setInput(createModel());
}
private MyModel createModel() {
MyModel root = new MyModel(0, null);
root.counter = 0;
MyModel tmp;
MyModel subItem;
for (int i = 1; i < 10; i++) {
tmp = new MyModel(i, root);
root.child.add(tmp);
for (int j = 1; j < i; j++) {
subItem = new MyModel(j, tmp);
subItem.child.add(new MyModel(j * 100, subItem));
tmp.child.add(subItem);
}
}
return root;
}
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
new Snippet026TreeViewerTabEditing(shell);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
private class MyContentProvider implements ITreeContentProvider {
public Object[] getElements(Object inputElement) {
return ((MyModel) inputElement).child.toArray();
}
public void dispose() {
}
public void inputChanged(Viewer viewer, Object oldInput, Object
newInput) {
}
public Object[] getChildren(Object parentElement) {
return getElements(parentElement);
}
public Object getParent(Object element) {
if (element == null) {
return null;
}
return ((MyModel) element).parent;
}
public boolean hasChildren(Object element) {
return ((MyModel) element).child.size() > 0;
}
}
public class MyModel {
public MyModel parent;
public ArrayList child = new ArrayList();
public int counter;
public MyModel(int counter, MyModel parent) {
this.parent = parent;
this.counter = counter;
}
public String toString() {
String rv = "Item ";
if (parent != null) {
rv = parent.toString() + ".";
}
rv += counter;
return rv;
}
}
}
|
|
|
Re: How can I use inplace editing on singleclick and open a dialog on doubleclick ? [message #331207 is a reply to message #331204] |
Thu, 28 August 2008 10:27 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
It's not a MouseListener its a double-click listener on the Viewer.
Here's a corrected version giveing you the double clicked cell.
package org.eclipse.jface.snippets.viewers;
/*********************************************************** ********************
* 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
************************************************************ *******************/
import java.util.ArrayList;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.TreeViewerColumn;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
/**
* A simple TreeViewer to demonstrate usage
*
* @author Tom Schindl <tom.schindl@bestsolution.at>
*
*/
public class Snippet026TreeViewerTabEditing {
public Snippet026TreeViewerTabEditing(final Shell shell) {
final TreeViewer v = new TreeViewer(shell, SWT.BORDER
| SWT.FULL_SELECTION|SWT.MULTI);
v.getTree().setLinesVisible(true);
v.getTree().setHeaderVisible(true);
v.addSelectionChangedListener(new ISelectionChangedListener(){
public void selectionChanged(SelectionChangedEvent event)
{
System.out.println(((StructuredSelection)event.getSelection( )).size());
}});
v.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) {
System.err.println(v.getCell(v.getTree().toControl(v.getTree ().getDisplay().getCursorLocation())));
}
});
// getTree().addMouseListener(new MouseAdapter(){
//
// public void mouseDoubleClick(MouseEvent e)
// {
// System.out.println("double click");
// }
//
// });
// TreeViewerFocusCellManager focusCellManager = new
TreeViewerFocusCellManager(v,new FocusCellOwnerDrawHighlighter(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;
// }
// };
//
// TreeViewerEditor.create(v, focusCellManager, actSupport,
ColumnViewerEditor.TABBING_HORIZONTAL
// | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
// | ColumnViewerEditor.TABBING_VERTICAL);
final TextCellEditor textCellEditor = new
TextCellEditor(v.getTree());
TreeViewerColumn column = new TreeViewerColumn(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setMoveable(true);
column.getColumn().setText("Column 1");
column.setLabelProvider(new ColumnLabelProvider() {
public String getText(Object element) {
return "Column 1 => " + element.toString();
}
});
column.setEditingSupport(new EditingSupport(v) {
protected boolean canEdit(Object element) {
return false;
}
protected CellEditor getCellEditor(Object element) {
return textCellEditor;
}
protected Object getValue(Object element) {
return ((MyModel) element).counter + "";
}
protected void setValue(Object element, Object value) {
((MyModel) element).counter = Integer
.parseInt(value.toString());
v.update(element, null);
}
});
column = new TreeViewerColumn(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setMoveable(true);
column.getColumn().setText("Column 2");
column.setLabelProvider(new ColumnLabelProvider() {
public String getText(Object element) {
return "Column 2 => " + element.toString();
}
});
column.setEditingSupport(new EditingSupport(v) {
protected boolean canEdit(Object element) {
return true;
}
protected CellEditor getCellEditor(Object element) {
return textCellEditor;
}
protected Object getValue(Object element) {
return ((MyModel) element).counter + "";
}
protected void setValue(Object element, Object value) {
((MyModel) element).counter = Integer
.parseInt(value.toString());
v.update(element, null);
}
});
column = new TreeViewerColumn(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setMoveable(true);
column.getColumn().setText("Column 3");
column.setLabelProvider(new ColumnLabelProvider() {
public String getText(Object element) {
return "Column 3 => " + element.toString();
}
});
column.setEditingSupport(new EditingSupport(v) {
protected boolean canEdit(Object element) {
return true;
}
protected CellEditor getCellEditor(Object element) {
return textCellEditor;
}
protected Object getValue(Object element) {
return ((MyModel) element).counter + "";
}
protected void setValue(Object element, Object value) {
((MyModel) element).counter = Integer
.parseInt(value.toString());
v.update(element, null);
}
});
v.setContentProvider(new MyContentProvider());
v.setInput(createModel());
}
private MyModel createModel() {
MyModel root = new MyModel(0, null);
root.counter = 0;
MyModel tmp;
MyModel subItem;
for (int i = 1; i < 10; i++) {
tmp = new MyModel(i, root);
root.child.add(tmp);
for (int j = 1; j < i; j++) {
subItem = new MyModel(j, tmp);
subItem.child.add(new MyModel(j * 100, subItem));
tmp.child.add(subItem);
}
}
return root;
}
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
new Snippet026TreeViewerTabEditing(shell);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
private class MyContentProvider implements ITreeContentProvider {
public Object[] getElements(Object inputElement) {
return ((MyModel) inputElement).child.toArray();
}
public void dispose() {
}
public void inputChanged(Viewer viewer, Object oldInput, Object
newInput) {
}
public Object[] getChildren(Object parentElement) {
return getElements(parentElement);
}
public Object getParent(Object element) {
if (element == null) {
return null;
}
return ((MyModel) element).parent;
}
public boolean hasChildren(Object element) {
return ((MyModel) element).child.size() > 0;
}
}
public class MyModel {
public MyModel parent;
public ArrayList child = new ArrayList();
public int counter;
public MyModel(int counter, MyModel parent) {
this.parent = parent;
this.counter = counter;
}
public String toString() {
String rv = "Item ";
if (parent != null) {
rv = parent.toString() + ".";
}
rv += counter;
return rv;
}
}
}
--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
|
|
| |
Goto Forum:
Current Time: Thu Dec 12 21:36:38 GMT 2024
Powered by FUDForum. Page generated in 0.04511 seconds
|