Listener output

Tower Ty tytower at hotmail.com.au
Thu Apr 24 16:30:51 PDT 2008


Barry Denton Wrote:

> Thanks Bill  I have typed listeners in tables  which are SetData and Selection type listeners.
> They should return  TableItem number and  x , y, point to identify them i think so.
> 
> They do not , can not work on table to change cells
> 
> 


I had a look at this too . I notice TableEditor has to produce its own sources for the cell identification.  See the below -I couldn't get the item no to go into table so I changed it a bit . This example is given  in the TextEditor.d file itself

module testTableEditor;
import dwt.DWT;
import dwt.widgets.Display;
import dwt.widgets.Shell;
import dwt.widgets.Table;
import dwt.widgets.TableColumn;
import dwt.widgets.TableItem;
import dwt.layout.GridLayout;
import dwt.custom.TableEditor;
import tango.util.Convert;
import tango.io.Stdout;
import TextUtil = tango.text.Util;
import dwt.events.SelectionEvent;
import dwt.events.SelectionListener;
import dwt.events.SelectionAdapter;
import dwt.events.ModifyListener;
import dwt.widgets.Control;
import dwt.widgets.Text;



void main () {
  Display display = new Display ();
  Shell shell = new Shell (display);
  shell.setText("Test TableEditor");
  GridLayout gridLayout = new GridLayout();
  shell.setLayout(gridLayout);

   final Table table = new Table(shell, DWT.FULL_SELECTION | DWT.HIDE_SELECTION);
   TableColumn column1 = new TableColumn(table, DWT.NONE);
   TableColumn column2 = new TableColumn(table, DWT.NONE);
   for (int i = 0; i < 10; i++) {
       TableItem item = new TableItem(table, DWT.NONE);
       char[][] needed = [ "item" , "edit this value" ];
       item.setText(needed);
      //item.setText(new char[][] {"item " + i, "edit this value"});original line
   }
   column1.pack();
   column2.pack();

   final TableEditor
   editor = new TableEditor(table);
   //The editor must have the same size as the cell and must
   //not be any smaller than 50 pixels.
   editor.horizontalAlignment = DWT.LEFT;
   editor.grabHorizontal = true;
   editor.minimumWidth = 50;
   // editing the second column
   final int EDITABLECOLUMN = 1;

   table.addSelectionListener(new class SelectionAdapter {
       public void widgetSelected(SelectionEvent e) {
           Stdout.print(e).newline;
// Clean up any previous editor control
           Control oldEditor = editor.getEditor();
           if (oldEditor !is null) oldEditor.dispose();
           // Identify the selected row
           TableItem item = cast (TableItem)e.item;
           if (item is null) return;
           // The control that will be the editor must be a child of the Table
           Text newEditor = new Text(table, DWT.NONE);
           newEditor.setText(item.getText(EDITABLECOLUMN));
           newEditor.addModifyListener(new class ModifyListener {
               public void modifyText(ModifyEvent e) {
                   Text text = cast (Text)editor.getEditor();
                   editor.getItem().setText(EDITABLECOLUMN, text.getText());
               }           }    );
           newEditor.selectAll();
           newEditor.setFocus();
           editor.setEditor(newEditor, item, EDITABLECOLUMN);
       }
   });
 



More information about the Digitalmars-d-dwt mailing list