|
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 09:09 |
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();
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.03068 seconds