- public AbstractSwtPart(Composite parent, int style) {
- area = new Composite(parent, style);
- area.setLayout(CmsSwtUtils.noSpaceGridLayout());
+ protected DataPart<INPUT, TYPE> dataPart;
+
+ protected final SelectionListener selectionListener;
+
+ public AbstractSwtPart(Composite parent, int style, DataPart<INPUT, TYPE> dataPart) {
+ super(parent, style);
+ setLayout(CmsSwtUtils.noSpaceGridLayout());
+
+ this.dataPart = dataPart;
+
+ selectionListener = new SelectionListener() {
+
+ private static final long serialVersionUID = 4334785560035009330L;
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (dataPart.getOnSelected() != null)
+ dataPart.getOnSelected().accept((TYPE) e.item.getData());
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ if (dataPart.getOnAction() != null)
+ dataPart.getOnAction().accept((TYPE) e.item.getData());
+ }
+ };
+
+ dataPart.addView(this);
+ addDisposeListener((e) -> dataPart.removeView(this));