X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.views.swt.client%2Fsrc%2Forg%2Fsimantics%2Fviews%2Fswt%2Fclient%2Fimpl%2FSWTCCombo.java;h=df58d051baeeb0f204116fc5cd571c0965717614;hb=refs%2Fchanges%2F38%2F238%2F2;hp=3ab0bd513d51a308339a8214c7d43a78e6645f15;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/impl/SWTCCombo.java b/bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/impl/SWTCCombo.java index 3ab0bd513..df58d051b 100644 --- a/bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/impl/SWTCCombo.java +++ b/bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/impl/SWTCCombo.java @@ -1,107 +1,107 @@ -package org.simantics.views.swt.client.impl; - -import java.util.List; - -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.widgets.Composite; -import org.simantics.scl.runtime.tuple.Tuple; - - -public class SWTCCombo extends SWTComboBase { - - private static final long serialVersionUID = 2529612234578912642L; - - private final SelectionListener listener = new SelectionListener() { - - @Override - public void widgetSelected(SelectionEvent e) { - - int selectionIndex = control.getSelectionIndex(); - if (selectionIndex == -1) - return; - - String[] items = control.getItems(); - - String key = items[selectionIndex]; - - if(modifier != null) - modifier.apply(key); - - selected = key; - - } - - @Override - public void widgetDefaultSelected(SelectionEvent e) { - - widgetSelected(e); - - } - - }; - - @Override - public void createControls(Composite parent) { - - control = new CCombo(parent, style); - control.addSelectionListener(listener); - - setProperties(); - - } - - public void synchronizeAvailable(List available) { - if(available != null) { - - control.removeSelectionListener(listener); - control.setData(available); - control.clearSelection(); - try { - control.removeAll(); - } catch (Throwable t) { - t.printStackTrace(); - } - if (available != null) { - int index = 0; - for(Tuple key : available) { - control.add((String)key.toArray()[0]); - control.setData((String)key.toArray()[0], index++); - } - String selectionKey = (String)control.getData("_SelectionKey"); - if(selectionKey != null) { - Integer selectionIndex = (Integer)control.getData(selectionKey); - if(selectionIndex != null) control.select(selectionIndex); - } - } - control.addSelectionListener(listener); - -// // This seems to be necessary for correct size computations -// widget.getControl().getParent().layout(true); - } - } - - public void synchronizeSelected(String selected) { - if(selected != null) { - - control.removeSelectionListener(listener); - control.setData("_SelectionKey", selected); - Integer selectionIndex = (Integer)control.getData(selected); - if(selectionIndex != null) control.select(selectionIndex); - control.addSelectionListener(listener); - -// // This seems to be necessary for correct size computations -// widget.getControl().getParent().layout(true); - } - } - - public String readSelected() { - return selected; - } - - public List readAvailable() { - return available; - } - -} +package org.simantics.views.swt.client.impl; + +import java.util.List; + +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Composite; +import org.simantics.scl.runtime.tuple.Tuple; + + +public class SWTCCombo extends SWTComboBase { + + private static final long serialVersionUID = 2529612234578912642L; + + private final SelectionListener listener = new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + + int selectionIndex = control.getSelectionIndex(); + if (selectionIndex == -1) + return; + + String[] items = control.getItems(); + + String key = items[selectionIndex]; + + if(modifier != null) + modifier.apply(key); + + selected = key; + + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + + widgetSelected(e); + + } + + }; + + @Override + public void createControls(Composite parent) { + + control = new CCombo(parent, style); + control.addSelectionListener(listener); + + setProperties(); + + } + + public void synchronizeAvailable(List available) { + if(available != null) { + + control.removeSelectionListener(listener); + control.setData(available); + control.clearSelection(); + try { + control.removeAll(); + } catch (Throwable t) { + t.printStackTrace(); + } + if (available != null) { + int index = 0; + for(Tuple key : available) { + control.add((String)key.toArray()[0]); + control.setData((String)key.toArray()[0], index++); + } + String selectionKey = (String)control.getData("_SelectionKey"); + if(selectionKey != null) { + Integer selectionIndex = (Integer)control.getData(selectionKey); + if(selectionIndex != null) control.select(selectionIndex); + } + } + control.addSelectionListener(listener); + +// // This seems to be necessary for correct size computations +// widget.getControl().getParent().layout(true); + } + } + + public void synchronizeSelected(String selected) { + if(selected != null) { + + control.removeSelectionListener(listener); + control.setData("_SelectionKey", selected); + Integer selectionIndex = (Integer)control.getData(selected); + if(selectionIndex != null) control.select(selectionIndex); + control.addSelectionListener(listener); + +// // This seems to be necessary for correct size computations +// widget.getControl().getParent().layout(true); + } + } + + public String readSelected() { + return selected; + } + + public List readAvailable() { + return available; + } + +}