Remove TableEditor from Table

SWT Designer allows you to create the views, editors, perspectives, pref pages, composites, etc. that comprise Eclipse SWT & RCP applications and plug-ins.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

Remove TableEditor from Table

Postby alabasta » Wed Oct 20, 2010 3:08 am

Hi to all,
I'm a new user of SWT.
I've a problem with elimination of a row. In the third colum there are some buttons.

I've modified a snippet. This is my code:
Code: Select all

package swtsnippets;

/*
* Table example snippet: remove selected items (using popup menu)
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
*/
import org.eclipse.swt.*;
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;

public class Snippet53 {

public static void main (String [] args) {
   final Display display = new Display();
   Shell shell = new Shell(display);
   shell.setLayout(new GridLayout());
   final Table table = new Table(shell, SWT.MULTI | SWT.BORDER
         | SWT.FULL_SELECTION);
   GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
   data.heightHint = 200;
   table.setLayoutData(data);
   table.setLinesVisible(true);
   table.setHeaderVisible(true);
   
   createColumns(table);
   
   for (int i=0; i<8; i++) {
      TableItem item = new TableItem (table, SWT.NONE);
      item.setText (0,"Item " + i);
      item.setText (1,"Cane " + i);
      
      Button c = new Button(table, SWT.PUSH);
      c.setText("B"+i);
      
      c.setEnabled(true);
      TableEditor editor = new TableEditor(table);
      editor.grabHorizontal = editor.grabVertical = true;
      editor.setEditor(c, item, 2);
//      editor.setEditor(null, item, 2);
      
      item.setData("IO", editor);
   }
   Menu menu = new Menu (shell, SWT.POP_UP);
   table.setMenu (menu);
   MenuItem item = new MenuItem (menu, SWT.PUSH);
   item.setText ("Power Off");
   item.addListener (SWT.Selection, new Listener () {
      public void handleEvent (Event event) {
         TableItem ti = table.getItem(table.getSelectionIndex());
         TableEditor b = (TableEditor)ti.getData("IO");
         
         redispose(table,b);
         table.remove (table.getSelectionIndex());
      }


   });
   
   resizeColumns(table);
   
   shell.pack ();
   shell.open ();
   while (!shell.isDisposed ()) {
      if (!display.readAndDispatch ()) display.sleep ();
   }
   display.dispose ();
}

private static void redispose(Table table, TableEditor b) {
   Control [] controls = table.getChildren();
   System.out.println("->"+controls.length);
   for (int i = 0; i < controls.length; i++) {
      if(controls[i].equals(b.getEditor())){
         controls[i].setVisible(false);
         controls[i].dispose();
         System.out.println("Bingo");
      }
   }
}


private static void resizeColumns(Table table) {
   for (int i=0; i<3; i++) {
      table.getColumn (i).pack ();
      System.out.println(table.getHeaderHeight());
   }
   
}

private static void createColumns(Table table) {
   // Create five columns
      TableColumn column = new TableColumn(table, SWT.CENTER);
      column.setText("Prima");
     
      column = new TableColumn(table, SWT.CENTER);
      column.setText("MAC Address");
     
      column = new TableColumn(table, SWT.CENTER);
      column.setText("Parked");
}
}



I'm trying to do various test without any resoult. I've also tried to hide the button but i've some refresh problem that I'm not able to resolve. The solution is to eliminate the button but I accept any solutions.

Thanks.
Andrea.
alabasta
 
Posts: 2
Joined: Wed Oct 20, 2010 3:00 am

Re: Remove TableEditor from Table

Postby Eric Clayberg » Wed Oct 20, 2010 4:09 am

General SWT/RCP questions should be posted to the Eclipse SWT newsgroup.

We would like to keep this forum focused on SWT Designer itself.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Re: Remove TableEditor from Table

Postby alabasta » Wed Oct 20, 2010 4:44 am

I'm sorry. I'll change position but I can' t find it...
alabasta
 
Posts: 2
Joined: Wed Oct 20, 2010 3:00 am

Re: Remove TableEditor from Table

Postby Eric Clayberg » Wed Oct 20, 2010 4:51 am

Nothing to apologize for. You will just get better answers to general SWT questions in the Eclipse SWT newsgroup.

The folks monitoring this forum are focused on the SWT Designer product itself.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to SWT Designer

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest

cron