Reputation: 161
In my RCP app, I have a tab folder widget. Each of the tab items in the tab folder widget holds a single table. The tab items (represent name of a specific hall) are dynamic and whenever a tab item is created dynamically, a table is created to be displayed within that tab item. The tab items are being dynamically created along with the table (and the table's content too) for each item in the tab folder.
Now when I try to retrieve the user selected values in the table in the first (or any other tab except the last one), I'm not able to get the values. I am able to retrieve and manipulate the table in the last tab item only. It seems like the preceding tables in the preceding tab items are replaced/overlapped by the new tables that are created dynamically later on. How do I solve this?
For Instance,
//createPartControl method
public void createPartControl(Composite parent) {
.....
.....
createTabFolder();
}
// createTabFolder() method
private void createTabFolder() {
tabFolder = new CTabFolder(comMainContainer, SWT.BORDER);
tabFolder.setBounds(204, 21, 769, 495);
tabFolder.setSelectionBackground(Display.getCurrent().getSystemColor(
SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
// display the tabitems in the tabfolder dynamically
try {
selectedDate = sdf.format(dateChooser.getSelectedDate());
rs = objHallBookingController.getHallList();
while (rs.next()) {
displayCtabItems(rs.getString("hall_name"),
rs.getInt("hall_id"));
}
} catch (SQLException e) {
e.printStackTrace();
}
}
// displayCtabItems method
private void displayCtabItems(String hallName, int hallId) {
tabItem = new CTabItem(tabFolder, SWT.NONE);
tabItem.setText(hallName);
comTabItem = new Composite(tabFolder, SWT.NONE);
tabItem.setControl(comTabItem);
tblHallBooking = new Table(comTabItem, SWT.BORDER | SWT.FULL_SELECTION);
tblHallBooking.setHeaderVisible(true);
tblHallBooking.setLinesVisible(true);
tblclmnTime = new TableColumn(tblHallBooking[hallId], SWT.NONE);
tblclmnTime.setWidth(88);
tblclmnTime.setText("Time");
tblclmnTitle = new TableColumn(tblHallBooking[hallId], SWT.NONE);
tblclmnTitle.setWidth(306);
tblclmnTitle.setText("Title");
// display contents in the table; working fine
displayHallOpeningTime(Integer.parseInt(txtHallId.getText()));
}
This code generates and displays the tab items and the tables. But I can't manipulate the contents in the tables in the tab items other than the last one.
Upvotes: 0
Views: 843
Reputation: 4843
You call method displayCTabItems(...)
more than one time (depends on rs.next()
)
while (rs.next()) {
displayCtabItems(rs.getString("hall_name"),
rs.getInt("hall_id"));
}
but you creates the Table instance tblHallBooking = new Table(comTabItem, SWT.BORDER | SWT.FULL_SELECTION);
again and again to same attribute tblHallBooking
, so in first cycle will have the attribute point to instance of Table in first tab, in second cycle will point to Table on second tab, etc. In every cycle you override value (instance "pointer") to Table on current creating tab.
You have to make Array of tables (size of array equals size of items in list objHallBookingController.getHallList();
) or you have to dynamically lookup to children of selected CTabItem and search for Table instance..
EDIT
Based on your comment, here could be way, how to get your table from selected CTabItem
Control parent = tabFolder.getSelection().getControl();
if(parent instanceof Composite) {
Composite parentComposite = (Composite) parent;
Control control = null;
for(int i = 0; i < parentComposite.getChildren().length; i++) {
if(parentComposite.getChildren()[i] instanceof Table) {
control = parentComposite.getChildren()[i];
break;
}
}
if(control != null) {
// now you have your table in control
Table tbl = (Table) control;
// do whatever you want with tbl
...
}
}
Upvotes: 2