Inline editing of Trees and Tables

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

Inline editing of Trees and Tables

Postby Christian Schneider » Sun Jan 13, 2008 3:17 am

Does SWT Designer support inline editing of Trees and Tables?
Are there any considerations to follow when adding editing features manually to the widgets? How does it play together with Databinding?
Christian Schneider
 
Posts: 2
Joined: Sun Jan 13, 2008 3:14 am

Re: Inline editing of Trees and Tables

Postby Eric Clayberg » Sun Jan 13, 2008 6:06 am

Christian Schneider wrote:Does SWT Designer support inline editing of Trees and Tables?

I'm not sure what you mean by "inline editing". If you are asking whether you can add table and tree items in Designer and then direct edit them, then yes...

Image

If you are asking about support for table cell editors, then no. At the moment, cell editors are not a native capability of tables and table columns. Those are added on via complex event handlers that are highly dependent on what you want to do. The SWT Snippets page shows several examples of how you might do it depending on what you are trying to accomplish.

Christian Schneider wrote:Are there any considerations to follow when adding editing features manually to the widgets?

Not that I know of.

Christian Schneider wrote:How does it play together with Databinding?

No idea. That would be a good question for the Eclipse SWT or RCP newsgroup.
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: Inline editing of Trees and Tables

Postby Christian Schneider » Sun Mar 09, 2008 4:03 pm

I meant something like table cell editors. After some search I found a nice way to achieve table cell editing.

The interfaces I used are ColumnLabelProvider and EditingSupport. They are used together with the new TableViewerColumns.
The only bad thing is that they ar not visible in SWTDesigner. I guess this is because they are quite new. Will you support those in the near future?

I have built some quite generic code for the ColumnLabelProvider and EditingSupport. Perhaps you have some use for this. It allows you to simply set this BeanColumnLabelProvider to retrieve the column content from any bean. Together with some annotations on the model this could give some quite universal way to display and edit tables.

You use it like this:
Code: Select all
final TableViewerColumn newColumnTableColumn_3 = new TableViewerColumn(tableViewer, SWT.NONE);
      newColumnTableColumn_3.setEditingSupport(new BeanEditingSupport(tableViewer, "name"));
      newColumnTableColumn_3.setLabelProvider(new BeanColumnLabelProvider("name", MyColumnImages.getColumnImages()));
      newColumnTableColumn_3.getColumn().setWidth(200);
      newColumnTableColumn_3.getColumn().setText("Name");


Code: Select all


import java.util.HashMap;
import java.util.Map;

import org.apache.commons.beanutils.BeanMap;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.swt.graphics.Image;

import com.swtdesigner.ResourceManager;

public class BeanColumnLabelProvider extends ColumnLabelProvider {
   
   private String propertyName;
   Map<String, String> columnImages;

   public BeanColumnLabelProvider(String propertyName, HashMap<String, String> columnImages) {
      super();
      this.propertyName = propertyName;
   }

   @Override
   public String getText(Object element) {
      BeanMap bm = new BeanMap(element);
      return (String)bm.get(propertyName);
   }

   @Override
   public String getToolTipText(Object element) {
      return super.getToolTipText(element);
   }

   @Override
   public Image getImage(Object element) {
      String className = element.getClass().getSimpleName();
      if (!columnImages.containsKey(className)) return null;
      String iconPath = columnImages.get(className);
      ImageDescriptor imageDesc = ResourceManager.getImageDescriptor(BeanColumnLabelProvider.class, iconPath);
      return imageDesc.createImage();
   }
   
}


Code: Select all

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.beanutils.BeanMap;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.TreeItem;

public class BeanEditingSupport extends EditingSupport {

   private CellEditor cellEditor;
   private String propertyName;
   private TypeRepository typeRepo;

   public BeanEditingSupport(ColumnViewer viewer, String propertyName) {
      super(viewer);
      Composite parent = null;
      if (viewer instanceof TableViewer) {
         TableViewer tv = (TableViewer) viewer;
         parent = tv.getTable();
      }
      if (viewer instanceof TreeViewer) {
         TreeViewer tv = (TreeViewer) viewer;
         parent = tv.getTree();
      }
      this.propertyName = propertyName;
      this.cellEditor = new TextCellEditor(parent);

   }

   @Override
   protected boolean canEdit(Object element) {
      return true;
   }

   @Override
   protected CellEditor getCellEditor(Object element) {
      return cellEditor;
   }

   @Override
   protected Object getValue(Object element) {
      BeanMap beanMap = new BeanMap(element);
      Object value = beanMap.containsKey(propertyName)?beanMap.get(propertyName):"";
      return value;
   }

   @Override
   protected void setValue(Object element, Object value) {
      if (element instanceof TableItem) {
         element = ((TableItem)element).getData();
      }
      if (element instanceof TreeItem) {
         element = ((TreeItem)element).getData();
      }
      BeanMap beanMap = new BeanMap(element);
      
      if (beanMap.containsKey(propertyName)) {
         beanMap.put(propertyName, value);
      }
      getViewer().refresh(element);
   }

}
Christian Schneider
 
Posts: 2
Joined: Sun Jan 13, 2008 3:14 am

Re: Inline editing of Trees and Tables

Postby Eric Clayberg » Mon Mar 10, 2008 10:16 am

Christian Schneider wrote:The interfaces I used are ColumnLabelProvider and EditingSupport. They are used together with the new TableViewerColumns.
The only bad thing is that they ar not visible in SWTDesigner. I guess this is because they are quite new. Will you support those in the near future?

Yes. We do plan to support these later this year.
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: Inline editing of Trees and Tables

Postby madamovic » Fri May 08, 2009 7:45 pm

Is the table cell editing with Data Bindings supported in the latest version (v7.0)?
madamovic
 
Posts: 2
Joined: Fri May 08, 2009 7:38 pm

Re: Inline editing of Trees and Tables

Postby Eric Clayberg » Sun May 10, 2009 4:59 pm

madamovic wrote:Is the table cell editing with Data Bindings supported in the latest version (v7.0)?

v7.0 currently supports ColumnLabelProvider, EditingSupport and TableViewerColumn as stated earlier in this thread.

Support for table cell editing with Data Bindings will be added in the future.
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: Inline editing of Trees and Tables

Postby madamovic » Mon May 11, 2009 8:22 am

Eric Clayberg wrote:Support for table cell editing with Data Bindings will be added in the future.

Do you know approximately when this will be supported?
madamovic
 
Posts: 2
Joined: Fri May 08, 2009 7:38 pm

Re: Inline editing of Trees and Tables

Postby Eric Clayberg » Wed May 13, 2009 4:40 am

madamovic wrote:Do you know approximately when this will be supported?

In the next month or two.
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: Inline editing of Trees and Tables

Postby octavio » Fri May 15, 2009 6:28 pm

Eric Clayberg wrote:
madamovic wrote:Do you know approximately when this will be supported?

In the next month or two.


Eric,
Are you refering to an Eclipse API (perhaps the Nebula Grid) or an Instantiations development?

I need an editable table with databinding and spreadsheet-like navigation. My three attempts have failed in one way or another and I'm trying to figure out if I should lower my ambitions or just postpone them.

Appreciate your insight...

Octavio
octavio
 
Posts: 8
Joined: Sun May 04, 2008 4:50 pm

Re: Inline editing of Trees and Tables

Postby Eric Clayberg » Fri May 15, 2009 8:04 pm

Eclipse API
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: No registered users and 2 guests