Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9209949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:57:53+00:00 2026-06-18T00:57:53+00:00

Data Model Class – Datamodel ArrayList = dataArray (stores data for tableviewer) clearArray() –

  • 0

Data Model Class – Datamodel

ArrayList = dataArray (stores data for tableviewer)
clearArray() – Method that clears the array

Table Viewer Class – DataTableViewer

The last column of the table displays a button

Dialog Class – DataDialog

Create Table Viewer:

viewer.setInput(DataModel.getInstance().getArrayData());

Dialog Button = Clear Results:

DataModel.getInstance().clearArray();
viewer.refresh();

Issue

When the user clicks the Clear Results button. It removes the displayed data from the table. But the buttons are still displaying in the table.

I know the problem has to be because the clear button is clearing the dataArray in the DataModel. The buttons are not getting notified that the data is now gone.

How can I refresh the buttons, so when the user clears the table, the buttons clear as well?

* EDIT **

I did not include all code, but I have tried to show the basics for my issue.
Class where I am building a arraylist of data to show in the table.

public class DataModel  {

   static ArrayList data = new ArrayList();

   private DataModel() {
   }

   public void buildArray(String id, String name) {
      data.add(id, name)
   }

   public void clearArray() {
      data.clear();
   }    

   public ArrayList getDataArray() {
       return data;
   }   
 }    

This is the table viewer class

public class DataTableViewer extends TableViewer {   

public DataTableViewer() {
   Table table = getTable();
   createColumns();
   table.setHeaderVisible(true);
   table.setLinesVisible(true);
   setContentProvider(new ArrayContentProvider());
}

private void createColumns() {
   TableViewerColumn col = new TableViewerColumn(this , SWT.NONE);
   col.getColumn().setWidth(150);
   col.getColumn().setText("ID");
   col.setLabelProvider(new ColorColumnLabelProvider());

   col = new TableViewerColumn(this , SWT.NONE);
   col.getColumn().setWidth(150);
   col.getColumn().setText("Name");
   col.setLabelProvider(new ColorColumnLabelProvider());

   col = new TableViewerColumn(this , SWT.NONE);
   col.getColumn().setWidth(50);
   col.getColumn().setText("");
   col.setLabelProvider(new ColorColumnLabelProvider());
}

public class ColorColumnLabelProvider extends ColumnLabelProvider {
   @Override
   public void update(final ViewerCell cell) {
      Object element = cell.getElement();
      if(element instanceof DataModel.SaveData) {
        DataModel.SaveData p = (DataModel.SaveData) element;
        switch(cell.getColumnIndex()) {            
           case 0: {
              cell.setText(p.getID());
              break;
           }
           case 1: {
              cell.setText(p.getName());
              break;
           }
           case 2: {
              Map<Object, Button> buttons = new HashMap<Object, Button>();   
              TableItem item = (TableItem) cell.getItem();
              Button button;
              String filename = (((DataModel.SaveData) element).getID() + "/" + ((DataModel.SaveData) element).getName());
              if(buttons.containsKey(cell.getElement())) {
                 button = buttons.get(cell.getElement());
              }
              else
              {
                button = new Button((Composite) cell.getViewerRow().getControl(),SWT.PUSH);
                button.setImage(appReg.getImage("ICON"));
                button.setData("file.id", filename);
                buttons.put(cell.getElement(), button);
              }
              TableEditor editor = new TableEditor(item.getParent());
              editor.grabHorizontal  = true;
              editor.grabVertical = true;
              editor.setEditor(button , item, cell.getColumnIndex());
              button.addListener(SWT.Selection, new SelectionListener());
              editor.layout();
              break;
           }

class SelectionListener implements Listener {

  public SelectionListener() {
  }

  @Override
  public void handleEvent(Event event) {
    if (event.widget instanceof Button) {
      String fileId =  (String) event.widget.getData("file.id");
      final File viewerFile = new File(fileId);
      try {
        Desktop.getDesktop().open(viewerFile);
      }
      catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
  }// End SelectionListener Class
} 

This is the dialog class that displays the tableviewer built from the arraylist from the DataModel class and using the table from DataTableViewer class.

 public class DataDialog extends TitleAreaDialog {

   Button clearButton;
   DataTableViewer  viewer;

    public DataDialog() {
    }

    protected Control createDialogArea() {
        createClearResultsButton();
        createTableViewer();
}

private void createTableViewer() {
    viewer = new DataTableViewer(parent, SWT.BORDER|SWT.V_SCROLL|SWT.FULL_SELECTION | SWT.MULTI);
        viewer.setInput(DataModel.getInstance().getDataArray());
}

protected void createClearResultsButton() {
    clearButton = new Button(composite, SWT.PUSH);
        clearButton.setText("Clear Results");
        clearButton.addSelectionListener(new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
             boolean more = MessageDialog.openConfirm(null, "Confirmation Message", "Are you sure you want to remove all results from the table?");
           if(more == true) {
              clearTableRows(); 
           }
        }
    });
}

public void clearTableRows() { 
     DataModel.getInstance().clearDataArray();
     viewer.refresh();
 }
}   

The Basic Issue :
1. DialogData class – opens

  1. User sees 2 rows in the table with a button for each row in the 3rd column.

  2. Each button corresponds with specific data in their row (maybe filename)

  3. The user is finished viewing the data in the table.

  4. The user clicks on the clear button to remove the data

  5. Clicked method clears the ArrayList data in DataModel class.
    The code then refreshes the viewer.

  6. The user now sees a blank table, but the buttons are still visible.

I am trying to figure out how to dispose of the buttons or how to clear the Button map in the DataTableViewer Class, when the rest of the data is cleared.

I think when the data is clear, that does not reset the buttons. So the buttons that has already been create is still valid and stored in the Map.

I hope this is more understanding.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:57:54+00:00Added an answer on June 18, 2026 at 12:57 am

    With the method viewer.getTable().getChildren(); you are able to access all children of the Table.

    You are able to iterate over all children of the Table and dispose the Buttons manually.

    Control[] children = viewer.getTable().getChildren();
    for(Control element : children) {
        if(element instanceof Button) {
            element.dispose();
        }
    }
    

    I couldn’t get your example running, so I hope it works for your case. You probably have to paste my code in your method clearTableRows();

    Something like this:

    public void clearTableRows() {
        DataModel.getInstance().clearDataArray();
    
        Control[] children = viewer.getTable().getChildren();
        for (Control element : children) {
            if (element instanceof Button) {
                element.dispose();
            }
        }
        viewer.refresh();
    }
    

    Source:

    • Eclipse API: Composite.getChildren()
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that contains data from some model. This class has metadata
I´ve got a ADO.Net Entity Data Model that contains a table called DJ .
Is Model only Entity Data Model class of my database? Model as simple place
I want to use Services(WCF/RIA /Web) to take data from Entity Data Model class
This is what my data model classes look like: public class Employee { public
I attempt to use webservice return POCO class generated from entity data model as
In my model I have: class Log < ActiveRecord::Base serialize :data ... def self.recover(table_name,
How can I get at the Labels data from within my Task model? class
I have two data sets in google app engine datastore. class First_Set(db.Model): start_time =
To start with, below are my two model classes. public class DataModel { [Required]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.