Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 282722 Details for
Bug 562872
TextCellEditor does not work on Linux if TreeViewer is initially empty
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
Snippet to show the problem
TextCellEditorBug.java (text/plain), 4.59 KB, created by
Phil Beauvoir
on 2020-05-06 05:38:00 EDT
(
hide
)
Description:
Snippet to show the problem
Filename:
MIME Type:
Creator:
Phil Beauvoir
Created:
2020-05-06 05:38:00 EDT
Size:
4.59 KB
patch
obsolete
>import java.util.ArrayList; >import java.util.List; > >import org.eclipse.jface.viewers.CellEditor; >import org.eclipse.jface.viewers.ICellModifier; >import org.eclipse.jface.viewers.ITreeContentProvider; >import org.eclipse.jface.viewers.LabelProvider; >import org.eclipse.jface.viewers.TextCellEditor; >import org.eclipse.jface.viewers.TreeViewer; >import org.eclipse.swt.SWT; >import org.eclipse.swt.events.SelectionAdapter; >import org.eclipse.swt.events.SelectionEvent; >import org.eclipse.swt.layout.GridData; >import org.eclipse.swt.layout.GridLayout; >import org.eclipse.swt.widgets.Button; >import org.eclipse.swt.widgets.Display; >import org.eclipse.swt.widgets.Shell; > > >public class TextCellEditorBug { > > private TreeViewer viewer; > > private class MyContentProvider implements ITreeContentProvider { > @Override > public Object[] getElements(Object inputElement) { > return ((MyModel)inputElement).child.toArray(); > } > > @Override > public Object[] getChildren(Object parentElement) { > return getElements(parentElement); > } > > @Override > public Object getParent(Object element) { > if( element == null) { > return null; > } > > return ((MyModel)element).parent; > } > > @Override > public boolean hasChildren(Object element) { > return ((MyModel)element).child.size() > 0; > } > > } > > public class MyModel { > public MyModel parent; > public List<MyModel> child = new ArrayList<>(); > public int counter; > > public MyModel(int counter, MyModel parent) { > this.parent = parent; > this.counter = counter; > } > > @Override > public String toString() { > String rv = "Item "; > if( parent != null ) { > rv = parent + "."; > } > > rv += counter; > > return rv; > } > } > > public TextCellEditorBug(final Shell shell) { > Button b1 = new Button(shell, SWT.PUSH); > b1.setText("1. Tree is empty - Click this to populate it and then click on a node to edit it. No text cell editor!"); > > Button b2 = new Button(shell, SWT.PUSH); > b2.setText("2. Now click this to create a new tree pre-populated and try to edit a node - text cell editor works!"); > b2.setEnabled(false); > > viewer = createTreeViewer(shell); > > b1.addSelectionListener(new SelectionAdapter() { > @Override > public void widgetSelected(SelectionEvent e) { > viewer.setInput(createModel()); > b1.setEnabled(false); > b2.setEnabled(true); > } > }); > > b2.addSelectionListener(new SelectionAdapter() { > @Override > public void widgetSelected(SelectionEvent e) { > viewer.getTree().dispose(); > viewer = createTreeViewer(shell); > viewer.setInput(createModel()); > > shell.layout(); > b2.setEnabled(false); > } > }); > } > > private TreeViewer createTreeViewer(Shell shell) { > final TreeViewer v = new TreeViewer(shell); > v.getTree().setLayoutData(new GridData(GridData.FILL_BOTH)); > v.setLabelProvider(new LabelProvider()); > v.setContentProvider(new MyContentProvider()); > > // Cell Editor > TextCellEditor cellEditor = new TextCellEditor(v.getTree()); > v.setColumnProperties(new String[]{ "col1" }); //$NON-NLS-1$ > v.setCellEditors(new CellEditor[]{ cellEditor }); > > v.setCellModifier(new ICellModifier() { > @Override > public void modify(Object element, String property, Object value) { > } > > @Override > public Object getValue(Object element, String property) { > return element == null ? null : element.toString(); > } > > @Override > public boolean canModify(Object element, String property) { > return true; > } > }); > > return v; > } > > private MyModel createModel() { > MyModel root = new MyModel(0,null); > root.counter = 0; > > MyModel tmp; > for( int i = 1; i < 10; i++ ) { > tmp = new MyModel(i, root); > root.child.add(tmp); > for( int j = 1; j < i; j++ ) { > tmp.child.add(new MyModel(j,tmp)); > } > } > > return root; > } > > public static void main(String[] args) { > Display display = new Display (); > Shell shell = new Shell(display); > shell.setLayout(new GridLayout()); > new TextCellEditorBug(shell); > shell.open (); > > while (!shell.isDisposed ()) { > if (!display.readAndDispatch ()) display.sleep (); > } > > display.dispose (); > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 562872
: 282722