Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Show values into TableEditor
Show values into TableEditor [message #892017] Tue, 26 June 2012 20:28 Go to next message
Revton Braga is currently offline Revton BragaFriend
Messages: 6
Registered: May 2012
Junior Member

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 #893129 is a reply to message #892017] Mon, 02 July 2012 18:31 Go to previous messageGo to next message
Lakshmi P ShanmugamFriend
Messages: 279
Registered: July 2009
Location: India
Senior Member
Sorry, I didn't follow your question. What do you want to do in showValues()?

Lakshmi P Shanmugam
Re: Show values into TableEditor [message #945705 is a reply to message #893129] Mon, 15 October 2012 14:54 Go to previous message
Revton Braga is currently offline Revton BragaFriend
Messages: 6
Registered: May 2012
Junior Member

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
Previous Topic:Programatically open a menu from menubar
Next Topic:How to hide/disable refresh from Browser's context menu
Goto Forum:
  


Current Time: Thu Mar 28 17:40:20 GMT 2024

Powered by FUDForum. Page generated in 0.03773 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top