Я строй приложения в SWT, который содержит два композиционных материалы, и мне нужно, чтобы общаться между ними ..как общаться между двумя композитами в SWT
Другими словами, когда я нажимаю в одной кнопке внутри композита " «Мне нужна таблица обновлений в составном« B »или получить элементы этой таблицы!
У меня есть два sugestions, но я не знаю, если они являются лучшим способом ...
- Pass базовый класс для композитов, и commucicate между родителем;
- композиты расширяет базовый класс и назвать, например, "parent.updateTableOfCompositeB()"
Я строю этот простой пример для лучшего compreention вопроса ..
мой базовый класс:
public class Test {
protected Shell shell;
public static void main(String[] args) {
try {
Test window = new Test();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
protected void createContents() {
shell = new Shell();
shell.setSize(450, 300);
shell.setText("SWT Application");
shell.setLayout(new FillLayout(SWT.HORIZONTAL));
Composite butComposite = new buttonsComp(shell, SWT.NONE);
Composite tableComposite = new TableComp(shell, SWT.NONE);
}
}
мои кнопки композит:
public class buttonsComp extends Composite {
public buttonsComp(Composite parent, int style) {
super(parent, style);
setLayout(new FillLayout(SWT.HORIZONTAL));
Button btnNewButton = new Button(this, SWT.NONE);
btnNewButton.setText("New Button");
Button btnAsd = new Button(this, SWT.NONE);
btnAsd.setText("asd");
}
@Override
protected void checkSubclass() {
}
}
мой состав таблицы
public class TableComp extends Composite {
private Table table;
public TableComp(Composite parent, int style) {
super(parent, style);
setLayout(new FillLayout(SWT.HORIZONTAL));
table = new Table(this, SWT.BORDER | SWT.FULL_SELECTION);
table.setHeaderVisible(true);
table.setLinesVisible(true);
TableColumn tblclmnColumn = new TableColumn(table, SWT.NONE);
tblclmnColumn.setWidth(100);
tblclmnColumn.setText("column1");
}
@Override
protected void checkSubclass() {
}
public void updateTable(){
for (int i = 0; i < 100; i++) {
TableItem item = new TableItem(table, i);
item.setText("bla" + i);
}
}
}
Каков наилучший способ?
жаль мой английский .. С уважением Александр