Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Nebula » Grid celleditor is not editable while it's content is too long
Grid celleditor is not editable while it's content is too long [message #872368] Tue, 15 May 2012 21:31 Go to next message
lushiwei lushiwei is currently offline lushiwei lushiwei
Messages: 12
Registered: June 2010
Junior Member
I set the v.setAutoPreferredHeight(true) in a grid. When the content of cell is too long(The high of GridItem is higher than the high of window), the celleditor can't be edited.
Any suggestion? thanks.
Re: Grid celleditor is not editable while it's content is too long [message #876775 is a reply to message #872368] Fri, 25 May 2012 05:09 Go to previous messageGo to next message
lushiwei lushiwei is currently offline lushiwei lushiwei
Messages: 12
Registered: June 2010
Junior Member
Post the sample code, I can't activate the editor from line 5 because the text is too long. Anyone can help me?
-----------------------------------------------
package org.eclipse.swt.nebula.snippets.grid;

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.ColumnViewerEditorActivationStrategy;
import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.nebula.jface.gridviewer.GridTableViewer;
import org.eclipse.nebula.jface.gridviewer.GridViewerEditor;
import org.eclipse.nebula.widgets.grid.GridColumn;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class TooLargeDataBug {
private String text ="very loooooooooooooooooooooooooooooooooooooooooooooooooooooooooog\nvery loooooooooooooooooooooooooooooooooooooooooooooooooooooooooog\n";

private class MyContentProvider implements IStructuredContentProvider {
public Object[] getElements(Object inputElement) {
return (MyModel[]) inputElement;
}

public void dispose() {
}

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() {
StringBuilder sb = new StringBuilder();
sb.append(text);
for(int i=0; i< counter; i++) sb.append(text);
return sb.toString();
}
}

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

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

public String getColumnText(Object element, int columnIndex) {
return element.toString();
}
}

public TooLargeDataBug(Shell shell) {
final GridTableViewer v = new GridTableViewer(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
v.setLabelProvider(new MyLabelProvider());
v.setContentProvider(new MyContentProvider());
v.setAutoPreferredHeight(true);

v.setCellEditors(new CellEditor[] { new TextCellEditor(v.getGrid(), SWT.MULTI | SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL), new TextCellEditor(v.getGrid(), SWT.MULTI | SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL) });
v.setCellModifier(new ICellModifier() {

public boolean canModify(Object element, String property) {
return true;
}

public Object getValue(Object element, String property) {
return element.toString();
}

public void modify(Object element, String property, Object value) {
}

});

v.setColumnProperties(new String[] {"1","2"});

ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(v) {
protected boolean isEditorActivationEvent(
ColumnViewerEditorActivationEvent event) {
return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
|| event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
|| (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR);
}
};

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

GridColumn column = new GridColumn(v.getGrid(), SWT.NONE);
column.setWordWrap(true);
column.setWidth(200);
column.setText("Column 1");

column = new GridColumn(v.getGrid(), SWT.NONE);
column.setWordWrap(true);
column.setWidth(200);
column.setText("Column 2");

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

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

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

return elements;
}

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

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

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

display.dispose();
}
}
Re: Grid celleditor is not editable while it's content is too long [message #1033835 is a reply to message #876775] Thu, 04 April 2013 13:48 Go to previous message
K S is currently offline K S
Messages: 4
Registered: February 2013
Junior Member
Hi lushiwei,

It seems I am having the same issue as you described above. Were you able to find a solution for this? Thanks in advance.
Previous Topic:Gantt Chart: how can i configure context menu
Next Topic:how to make a xviewer editable
Goto Forum:
  


Current Time: Mon Apr 21 00:51:47 EDT 2014

Powered by FUDForum. Page generated in 0.02344 seconds