Show values into TableEditor [message #892017] |
Tue, 26 June 2012 20:28 |
|
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
public class Editor {
private static Table table;
private static TableEditor editor;
public static void main(String[] args) {
Display display = new Display();
Shell parent = new Shell(display);
createTable(parent);
parent.open();
while (!parent.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
private static void createTable(Shell parent) {
table = new Table (parent, SWT.BORDER | SWT.MULTI);
table.setLinesVisible(true);
table.setHeaderVisible(true);
TableColumn column = null;
for(String col : new String[] { "Combo", "Text"}){
column = new TableColumn(table, SWT.NONE);
column.setText(col);
column.pack();
}
for (int i=0; i<2; i++) {
new TableItem (table, SWT.NONE);
}
TableItem [] items = table.getItems ();
for (int i=0; i<items.length; i++) {
editor = new TableEditor (table);
CCombo typeCombo = new CCombo (table, SWT.NONE);
typeCombo.setText("");
typeCombo.setEditable(false);
for(String type: new String[]{"","1","2","3","4"}){
typeCombo.add(type);
}
typeCombo.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
showValues();
}
});
editor.grabHorizontal = true;
editor.setEditor(typeCombo, items[i], 0);
editor = new TableEditor (table);
Text shortNameText= new Text (table, SWT.NONE);
shortNameText.setText("");
shortNameText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent arg0) {
showValues();
}
});
editor.grabHorizontal = true;
editor.setEditor(shortNameText, items[i], 1);
Color editorColor = shortNameText.getBackground();
typeCombo.setBackground(editorColor);
}
table.pack();
}
protected static void showValues() {
System.out.println("[showValues]");
// TODO showValues
}
}
How I can show values into the TableEditor?
I need implements the method showValues()
Thanks.
|
|
|
|
Re: Show values into TableEditor [message #945705 is a reply to message #893129] |
Mon, 15 October 2012 14:54 |
|
Sorry Lakshmi Shanmugam, I don't see your response, I can find solution for my problem:
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
public class Editor {
private static Table table;
private static TableEditor editor;
public static void main(String[] args) {
Display display = new Display();
Shell parent = new Shell(display);
createTable(parent);
parent.open();
while (!parent.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
private static void createTable(Shell parent) {
table = new Table (parent, SWT.BORDER | SWT.MULTI);
table.setLinesVisible(true);
table.setHeaderVisible(true);
TableColumn column = null;
for(String col : new String[] { "Combo", "Text"}){
column = new TableColumn(table, SWT.NONE);
column.setText(col);
column.pack();
}
for (int i=0; i<2; i++) {
new TableItem (table, SWT.NONE);
}
TableItem [] items = table.getItems ();
for (int i=0; i<items.length; i++) {
editor = new TableEditor (table);
CCombo typeCombo = new CCombo (table, SWT.NONE);
typeCombo.setText("");
typeCombo.setEditable(false);
for(String type: new String[]{"","1","2","3","4"}){
typeCombo.add(type);
}
typeCombo.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
CCombo combo = (CCombo) e.getSource();
TableItem item = (TableItem) combo.getData();
item.setText(0,combo.getText());
showValues();
}
});
editor.grabHorizontal = true;
typeCombo.setData(items[i]);
editor.setEditor(typeCombo, items[i], 0);
editor = new TableEditor (table);
Text shortNameText= new Text (table, SWT.NONE);
shortNameText.setText("");
shortNameText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
Text text = (Text) e.getSource();
TableItem item = (TableItem) text.getData();
item.setText(1,text.getText());
showValues();
}
});
editor.grabHorizontal = true;
shortNameText.setData(items[i]);
editor.setEditor(shortNameText, items[i], 1);
Color editorColor = shortNameText.getBackground();
typeCombo.setBackground(editorColor);
}
table.pack();
}
protected static void showValues() {
for(TableItem item: table.getItems()){
System.out.println("Combo = " + item.getText(0));
System.out.println("Text = " + item.getText(1));
}
}
}
Thanks,
Revton
|
|
|
Powered by
FUDForum. Page generated in 0.02633 seconds