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%2FSWTCombo.java;h=7e2d124da07302e11bc9507101ca35fd2e4dc07b;hb=91e878ce39c9db112d658b3236f29a13e12724e6;hp=75a2fe5c70b12839e359a308560f6519eb3ceeae;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/impl/SWTCombo.java b/bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/impl/SWTCombo.java index 75a2fe5c7..7e2d124da 100644 --- a/bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/impl/SWTCombo.java +++ b/bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/impl/SWTCombo.java @@ -1,96 +1,96 @@ -package org.simantics.views.swt.client.impl; - -import java.util.List; - -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.simantics.scl.runtime.tuple.Tuple; - -public class SWTCombo extends SWTComboBase { - - private static final long serialVersionUID = 3355806440902480450L; - - private final ModifyListener listener = new ModifyListener() { - - @Override - public void modifyText(ModifyEvent 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 createControls(Composite parent) { - - control = new Combo(parent, style); - // Must initially add modifylistener before invoking setProperties - // since setProperties will invoke synchronize*-methods, which do - // removeModifyListener + addModifyListener. Otherwise modify listener - // would get added twice to the control. - control.addModifyListener(listener); - - setProperties(); - - } - - public void synchronizeAvailable(List available) { - - if(available != null) { - - control.removeModifyListener(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.get(0)); - control.setData((String)key.get(0), index++); - } - String selectionKey = (String)control.getData("_SelectionKey"); - if(selectionKey != null) { - Integer selectionIndex = (Integer)control.getData(selectionKey); - if(selectionIndex != null) control.select(selectionIndex); - } - } - control.addModifyListener(listener); - -// // This seems to be necessary for correct size computations -// widget.getControl().getParent().layout(true); - } - } - - public void synchronizeSelected(String selected) { - - if(selected != null) { - - control.removeModifyListener(listener); - control.setData("_SelectionKey", selected); - Integer selectionIndex = (Integer)control.getData(selected); - if(selectionIndex != null) control.select(selectionIndex); - control.addModifyListener(listener); - - } - - } - -} +package org.simantics.views.swt.client.impl; + +import java.util.List; + +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.simantics.scl.runtime.tuple.Tuple; + +public class SWTCombo extends SWTComboBase { + + private static final long serialVersionUID = 3355806440902480450L; + + private final ModifyListener listener = new ModifyListener() { + + @Override + public void modifyText(ModifyEvent 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 createControls(Composite parent) { + + control = new Combo(parent, style); + // Must initially add modifylistener before invoking setProperties + // since setProperties will invoke synchronize*-methods, which do + // removeModifyListener + addModifyListener. Otherwise modify listener + // would get added twice to the control. + control.addModifyListener(listener); + + setProperties(); + + } + + public void synchronizeAvailable(List available) { + + if(available != null) { + + control.removeModifyListener(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.get(0)); + control.setData((String)key.get(0), index++); + } + String selectionKey = (String)control.getData("_SelectionKey"); + if(selectionKey != null) { + Integer selectionIndex = (Integer)control.getData(selectionKey); + if(selectionIndex != null) control.select(selectionIndex); + } + } + control.addModifyListener(listener); + +// // This seems to be necessary for correct size computations +// widget.getControl().getParent().layout(true); + } + } + + public void synchronizeSelected(String selected) { + + if(selected != null) { + + control.removeModifyListener(listener); + control.setData("_SelectionKey", selected); + Integer selectionIndex = (Integer)control.getData(selected); + if(selectionIndex != null) control.select(selectionIndex); + control.addModifyListener(listener); + + } + + } + +}