What is the right way to update a table view in a Part in a Eclipse RCP project?
NickName:kenshinji Ask DateTime:2016-11-08T15:40:27

What is the right way to update a table view in a Part in a Eclipse RCP project?

Say I have a ItemListPart class in my RCP project, and there is a table to be displayed in it as following:

import java.util.List;

import javax.annotation.PostConstruct;

import org.eclipse.e4.ui.di.Focus;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

public class ItemListPart {
    private Table table;

    @PostConstruct 
    public void createControls(Composite parent){
      //I wish the ItemList could be changed from outside the ItemListPart class.
      List<Item> ItemList = getItemList();

      parent.setLayout(new GridLayout(2, false));

      table = new Table(parent, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
      table.setLinesVisible(true);
      table.setHeaderVisible(true);
      GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
      data.heightHint = 200;
      table.setLayoutData(data);

      String[] titles = { "Item Name", "Description"};
      for (int i = 0; i < titles.length; i++) {
          TableColumn column = new TableColumn(table, SWT.NONE);
          column.setText(titles[i]);
          table.getColumn(i).pack();
      }


      for(Item it:ItemList){
          TableItem item = new TableItem(table, SWT.NONE);
          item.setText(0, it.getName());
          item.setText(1, it.getDesc());
      }

      for (int i=0; i<titles.length; i++) {
          table.getColumn (i).pack ();
      }
    }

    @Focus
    public void onFocus() {
        table.setFocus();
    }
}

Here the ItemList<Item> is a List which I wish could be changed from outside the ItemListPart class, and whenever the data in ItemList<Item> changed, the table view could be auto refreshed according to the updated data. What is the right way to achieve this goal? Thanks.

Copyright Notice:Content Author:「kenshinji」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/40481424/what-is-the-right-way-to-update-a-table-view-in-a-part-in-a-eclipse-rcp-project

More about “What is the right way to update a table view in a Part in a Eclipse RCP project?” related questions

What is the right way to update a table view in a Part in a Eclipse RCP project?

Say I have a ItemListPart class in my RCP project, and there is a table to be displayed in it as following: import java.util.List; import javax.annotation.PostConstruct; import org.eclipse.e4.ui...

Show Detail

Is there any way to dynamically set the icon of view/part in eclipse rcp?

I want to change the image of view/part in eclipse rcp with my application theme .As of now this is not E4 application so we are still using org.eclipse.ui.views as extension point.So I had hardcod...

Show Detail

Eclipse RCP e4 : Add Project Explorer view

I am trying to integrate a Project Explorer view into an RCP e4 application I am working on. Unfortunately, the information I found online in SO and elsewhere do not provide much information on ho...

Show Detail

Eclipse RCP: Open View/ Part programmatically in detached mode

I can open a view or part using EPartService (see here). This will bring up the part within the last part stack as a new tab. How can I bring up the part in detached mode?

Show Detail

How to create new Eclipse RCP project using Maven?

How to create new Eclipse RCP project using Maven (preferably m2eclipse)? I read that there's plug-in for Maven that have idea about Eclipse. (Maven Eclipse Plugin) And then it looks like I need t...

Show Detail

How to make my spray project into a standalone eclipse rcp application?

I created an emf model and also a spray project. I am able to start the spray project over "Run as.." as an eclipse application and i will get an editor that depends on my emf model. Now i would l...

Show Detail

Eclipse RCP update a View after changes in the editor

i am new to Eclipse RCP and have the following Scenario: One plugin which is the Application Another witch is a view and does show some Data And a third which is the editor. in the view I can ri...

Show Detail

eclipse rcp updates

For eclipse rcp applications, if we want to add a new feature and that needs to be installed through update manager, dont we need to create update site? Request to clarify my following doubts. ...

Show Detail

Running and debugging Eclipse RCP as a Maven project

Is it still possible to run and debug Eclipse RCP projects inside Eclipse after they were converted to a Maven project (for example with the help of Maven Tycho plugin). Does the conversion to a Ma...

Show Detail

Adding custom right click menu into Eclipse's project explorer view in RCP application

Currently I'm using Eclipse's Project Explorer view into my RCP Application by writing the following line of command into my "Perspective.java" file... layout.addView(IPageLayout.ID_PROJECT_EXPLOR...

Show Detail