1 package org.simantics.views.swt.client.impl;
5 import org.eclipse.swt.custom.CCombo;
6 import org.eclipse.swt.events.SelectionEvent;
7 import org.eclipse.swt.events.SelectionListener;
8 import org.eclipse.swt.widgets.Composite;
9 import org.simantics.scl.runtime.tuple.Tuple;
12 public class SWTCCombo extends SWTComboBase<CCombo> {
14 private static final long serialVersionUID = 2529612234578912642L;
16 private final SelectionListener listener = new SelectionListener() {
19 public void widgetSelected(SelectionEvent e) {
21 int selectionIndex = control.getSelectionIndex();
22 if (selectionIndex == -1)
25 String[] items = control.getItems();
27 String key = items[selectionIndex];
37 public void widgetDefaultSelected(SelectionEvent e) {
46 public void createControls(Composite parent) {
48 control = new CCombo(parent, style);
49 control.addSelectionListener(listener);
55 public void synchronizeAvailable(List<Tuple> available) {
56 if(available != null) {
58 control.removeSelectionListener(listener);
59 control.setData(available);
60 control.clearSelection();
63 } catch (Throwable t) {
66 if (available != null) {
68 for(Tuple key : available) {
69 control.add((String)key.toArray()[0]);
70 control.setData((String)key.toArray()[0], index++);
72 String selectionKey = (String)control.getData("_SelectionKey");
73 if(selectionKey != null) {
74 Integer selectionIndex = (Integer)control.getData(selectionKey);
75 if(selectionIndex != null) control.select(selectionIndex);
78 control.addSelectionListener(listener);
80 // // This seems to be necessary for correct size computations
81 // widget.getControl().getParent().layout(true);
85 public void synchronizeSelected(String selected) {
86 if(selected != null) {
88 control.removeSelectionListener(listener);
89 control.setData("_SelectionKey", selected);
90 Integer selectionIndex = (Integer)control.getData(selected);
91 if(selectionIndex != null) control.select(selectionIndex);
92 control.addSelectionListener(listener);
94 // // This seems to be necessary for correct size computations
95 // widget.getControl().getParent().layout(true);
99 public String readSelected() {
103 public List<Tuple> readAvailable() {