gd_table.heightHint = 100;
table.setLayoutData(gd_table);
table.setLinesVisible(true);
table.setHeaderVisible(true);
table.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
TableItem[] items = table.getSelection();
if (items != null && items.length > 0) {
int index = notifications.indexOf((Notification) items[0].getData());
Notification notification = notifications.get(index);
notifyFromText.setText(notification.getFrom());
notifyToText.setText(notification.getTo());
notifyToGroupsText.setText(notification.getToGroups());
notifyReplyToText.setText(notification.getReplyTo());
notifySubjectText.setText(notification.getSubject());
notifyBodyText.setText(notification.getBody());
notifyTypeText.setText(notification.getType());
notifyExpiresAtText.setText(notification.getExpiresAt());
} else {
notifyFromText.setText("");
notifyToText.setText("");
notifyToGroupsText.setText("");
notifyReplyToText.setText("");
notifySubjectText.setText("");
notifyBodyText.setText("");
notifyTypeText.setText("");
notifyExpiresAtText.setText("");
}
}
public void widgetDefaultSelected(SelectionEvent e) {
TableItem[] items = table.getSelection();
if (items != null && items.length > 0) {
int index = notifications.indexOf((Notification) items[0].getData());
Notification notification = notifications.get(index);
notifyFromText.setText(notification.getFrom());
notifyToText.setText(notification.getTo());
notifyToGroupsText.setText(notification.getToGroups());
notifyReplyToText.setText(notification.getReplyTo());
notifySubjectText.setText(notification.getSubject());
notifyBodyText.setText(notification.getBody());
notifyTypeText.setText(notification.getType());
notifyExpiresAtText.setText(notification.getExpiresAt());
} else {
notifyFromText.setText("");
notifyToText.setText("");
notifyToGroupsText.setText("");
notifyReplyToText.setText("");
notifySubjectText.setText("");
notifyBodyText.setText("");
notifyTypeText.setText("");
notifyExpiresAtText.setText("");
}
}
});
tableViewer.setContentProvider(new NotificationsContentProvider());
tableViewer.setInput(notifications);
// add/delete buttons
final Composite composite = new Composite(container, SWT.NONE);
composite.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
composite.setLayout(new RowLayout());
final Button addButton = new Button(composite, SWT.NONE);
addButton.setText("Add");
addButton.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
Notification notification = new Notification();
notification.setFrom(notifyFromText.getText());
notification.setTo(notifyToText.getText());
notification.setToGroups(notifyToGroupsText.getText());
notification.setReplyTo(notifyReplyToText.getText());
notification.setSubject(notifySubjectText.getText());
notification.setBody(notifyBodyText.getText());
notification.setType(notifyTypeText.getText());
notification.setExpiresAt(notifyExpiresAtText.getText());
notifications.add(notification);
tableViewer.add(notification);
tableViewer.refresh();
// clear fields after add operation
notifyFromText.setText("");
notifyToText.setText("");
notifyToGroupsText.setText("");
notifyReplyToText.setText("");
notifySubjectText.setText("");
notifyBodyText.setText("");
notifyTypeText.setText("");
notifyExpiresAtText.setText("");
}
public void widgetSelected(SelectionEvent e) {
Notification notification = new Notification();
notification.setFrom(notifyFromText.getText());
notification.setTo(notifyToText.getText());
notification.setToGroups(notifyToGroupsText.getText());
notification.setReplyTo(notifyReplyToText.getText());
notification.setSubject(notifySubjectText.getText());
notification.setBody(notifyBodyText.getText());
notification.setType(notifyTypeText.getText());
notification.setExpiresAt(notifyExpiresAtText.getText());
notifications.add(notification);
tableViewer.add(notification);
tableViewer.refresh();
// clear fields after add operation
notifyFromText.setText("");
notifyToText.setText("");
notifyToGroupsText.setText("");
notifyReplyToText.setText("");
notifySubjectText.setText("");
notifyBodyText.setText("");
notifyTypeText.setText("");
notifyExpiresAtText.setText("");
}
});
final Button deleteButton = new Button(composite, SWT.NONE);
deleteButton.setText("Remove");
deleteButton.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent event) {
TableItem[] items = table.getSelection();
if (items != null && items.length > 0) {
notifications.remove((Notification) items[0].getData());
tableViewer.remove(items[0]);
tableViewer.refresh();
}
}
public void widgetDefaultSelected(SelectionEvent event) {
TableItem[] items = table.getSelection();
if (items != null && items.length > 0) {
notifications.remove((Notification) items[0].getData());
tableViewer.remove(items[0]);
tableViewer.refresh();
}
}
});
final Button updateButton = new Button(composite, SWT.NONE);
updateButton.setText("Update");
updateButton.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent event) {
TableItem[] items = table.getSelection();
if (items != null && items.length > 0) {
int index = notifications.indexOf((Notification) items[0].getData());
Notification notification = notifications.get(index);
notification.setFrom(notifyFromText.getText());
notification.setTo(notifyToText.getText());
notification.setToGroups(notifyToGroupsText.getText());
notification.setReplyTo(notifyReplyToText.getText());
notification.setSubject(notifySubjectText.getText());
notification.setBody(notifyBodyText.getText());
notification.setType(notifyTypeText.getText());
notification.setExpiresAt(notifyExpiresAtText.getText());
tableViewer.refresh();
// clear fields after add operation
notifyFromText.setText("");
notifyToText.setText("");
notifyToGroupsText.setText("");
notifyReplyToText.setText("");
notifySubjectText.setText("");
notifyBodyText.setText("");
notifyTypeText.setText("");
notifyExpiresAtText.setText("");
}
}
public void widgetDefaultSelected(SelectionEvent event) {
TableItem[] items = table.getSelection();
if (items != null && items.length > 0) {
int index = notifications.indexOf((Notification) items[0].getData());
Notification notification = notifications.get(index);
notification.setFrom(notifyFromText.getText());
notification.setTo(notifyToText.getText());
notification.setToGroups(notifyToGroupsText.getText());
notification.setReplyTo(notifyReplyToText.getText());
notification.setSubject(notifySubjectText.getText());
notification.setBody(notifyBodyText.getText());
notification.setType(notifyTypeText.getText());
notification.setExpiresAt(notifyExpiresAtText.getText());
tableViewer.refresh();
// clear fields after add operation
notifyFromText.setText("");
notifyToText.setText("");
notifyToGroupsText.setText("");
notifyReplyToText.setText("");
notifySubjectText.setText("");
notifyBodyText.setText("");
notifyTypeText.setText("");
notifyExpiresAtText.setText("");
}
}
});
final Button clearButton = new Button(composite, SWT.NONE);
clearButton.setText("Clear");
clearButton.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent event) {
// clear fields after add operation
notifyFromText.setText("");
notifyToText.setText("");
notifyToGroupsText.setText("");