I am working on eclipse plugin. I create an extension point on eclipse plugin. I've added a dropdown list. So I implemented a listener to know when the value changed and execute my logic. Here the snippet of the extension point :
<extension point="org.eclipse.ui.views.properties.tabbed.propertyTabs">
<propertyTabs contributorId="com.ibm.xtools.modeler.ui.properties">
<propertyTab
label="My new Label"
category="Core"
afterTab="modeleditor.property.tab.AdvancedTab"
id="com.test.plugin.tabs.MyNewTab"/>
</propertyTabs>
</extension>
<extension point="org.eclipse.ui.views.properties.tabbed.propertySections">
<propertySections contributorId="com.ibm.xtools.modeler.ui.properties">
<propertySection
class="com.test.plugin.sections.MyNewTabSection"
tab="com.test.plugin.tabs.MyNewTab"
filter="com.test.plugin.sections.MyNewTabSection$Filter"
id="com.bnpp.ism.test.profile.tabs.MyNewTab">
</propertySection>
</propertySections>
</extension>
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
import org.eclipse.uml2.uml.Enumeration;
import org.eclipse.uml2.uml.NamedElement;
public class MyNewTabSection extends SuperSection{
private ComboViewer comboViewer;
private ISelectionChangedListener comboViewerSelectionListener;
private Label myLabel;
private final static List<String> myValues = new ArrayList<String>(Arrays.asList("FIRST","TWO","THREE"));
public static class Filter extends AbstractFilter{
public Filter() {
super();
}
}
@Override
public void createControls(Composite parent,TabbedPropertySheetPage tabbedPropertySheetPage) {
super.createControls(parent,tabbedPropertySheetPage);
addLabel();
addComboViewer();
@Override
protected void addListeners() {
comboViewer.addSelectionChangedListener(getComboViewerSelectionListener());
}
@Override
protected void removeListeners() {
comboViewer.removeSelectionChangedListener(getComboViewerSelectionListener());
}
@Override
protected boolean acceptElement(EObject element) {
return element instanceof Enumeration;
}
private void addComboViewer() {
FormData data;
comboViewer = new ComboViewer(composite);
data = new FormData();
data.left = new FormAttachment(myLabel,10);
data.top = new FormAttachment(15,110);
comboViewer.getCombo().setText(" ");
comboViewer.getCombo().setLayoutData(data);
comboViewer.setContentProvider(new ArrayContentProvider());
comboViewer.setInput(myValues);
}
private void addReferenceTypeCombo() {
FormData data;
comboViewer = new ComboViewer(composite);
data = new FormData();
data.left = new FormAttachment(myLabel,10);// 10,110
data.width = 100;
data.top = new FormAttachment(15,110);
comboViewer.getCombo().setText(" ");
comboViewer.getCombo().setLayoutData(data);
comboViewer.setContentProvider(new ArrayContentProvider());
NomenclatureTypeView[] values = NomenclatureTypeView.values();
comboViewer.setInput(myValues);
}
private void addLabel() {
FormData data;
nomenclatureLabel = new Label(composite,0);
data = new FormData();
data.left = new FormAttachment(10,110);
data.top = new FormAttachment(15,110);
myLabel.setLayoutData(data);
myLabel.setBackground(white);
myLabel.setText("My Label text");
}
private ISelectionChangedListener getComboViewerSelectionListener() {
if (comboViewerSelectionListener == null) {
comboViewerSelectionListener = new ISelectionChangedListener(){
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
Object firstElement = selection.getFirstElement();
final String value = firstElement.toString();
Object firstElementA = comboViewer.getElementAt(0);
if (firstElement != null) {
comboViewer.setSelection(new StructuredSelection(firstElement));
}
// some logic
}
};
}
return comboViewerSelectionListener;
}
@Override
protected void initInternalInput(EObject element) {
this.element = (NamedElement) element;
}
@Override
protected void resetInternalInput() {
this.element = null;
}
}
When I click on the Tab I can see the dropdown list with my value (ONE, TWO, THREE). But when I select a value of the list the listener run many times. It's strange because I just select one time the value. It runs the listener code many times until having the following exception :
!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.StackOverflowError
at org.eclipse.swt.widgets.Control.windowProc(Control.java:3877)
at org.eclipse.swt.widgets.Combo.windowProc(Combo.java:2058)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4545)
at org.eclipse.swt.internal.win32.OS.SendMessageW(Native Method)
at org.eclipse.swt.internal.win32.OS.SendMessage(OS.java:3012)
at org.eclipse.swt.widgets.Combo.select(Combo.java:1386)
at org.eclipse.jface.viewers.ComboViewer.listSetSelection(ComboViewer.java:212)
at org.eclipse.jface.viewers.AbstractListViewer.setSelectionToWidget(AbstractListViewer.java:513)
at org.eclipse.jface.viewers.StructuredViewer.setSelectionToWidget(StructuredViewer.java:1680)
at org.eclipse.jface.viewers.StructuredViewer.setSelection(StructuredViewer.java:1636)
at org.eclipse.jface.viewers.Viewer.setSelection(Viewer.java:392)
at com.test.plugin.sections.myNewTabSection$2.selectionChanged(myNewTabSection.java:178)
at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java:162)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
at org.eclipse.core.runtime.Platform.run(Platform.java:880)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:48)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
at org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer.java:160)
at org.eclipse.jface.viewers.StructuredViewer.updateSelection(StructuredViewer.java:2062)
at org.eclipse.jface.viewers.StructuredViewer.setSelection(StructuredViewer.java:1638)
at org.eclipse.jface.viewers.Viewer.setSelection(Viewer.java:392)
at com.test.plugin.sections.MyNewTabSection$2.selectionChanged(MyNewTabSection.java:178)
at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java:162)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
at org.eclipse.core.runtime.Platform.run(Platform.java:880)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:48)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
at org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer.java:160)
at org.eclipse.jface.viewers.StructuredViewer.updateSelection(StructuredViewer.java:2062)
at org.eclipse.jface.viewers.StructuredViewer.setSelection(StructuredViewer.java:1638)
at org.eclipse.jface.viewers.Viewer.setSelection(Viewer.java:392)
at com.test.plugin.sections.MyNewTabSection$2.selectionChanged(MyNewTabSection.java:178)
at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java:162)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
at org.eclipse.core.runtime.Platform.run(Platform.java:880)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:48)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
at org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer.java:160)
at org.eclipse.jface.viewers.StructuredViewer.updateSelection(StructuredViewer.java:2062)
at org.eclipse.jface.viewers.StructuredViewer.setSelection(StructuredViewer.java:1638)
at org.eclipse.jface.viewers.Viewer.setSelection(Viewer.java:392)
at com.test.plugin.sections.MyNewTabSection$2.selectionChanged(MyNewTabSection.java:178)
at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java:162)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
at org.eclipse.core.runtime.Platform.run(Platform.java:880)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:48)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
at org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer.java:160)
at org.eclipse.jface.viewers.StructuredViewer.updateSelection(StructuredViewer.java:2062)
at org.eclipse.jface.viewers.StructuredViewer.setSelection(StructuredViewer.java:1638)
at org.eclipse.jface.viewers.Viewer.setSelection(Viewer.java:392)
at com.test.plugin.sections.MyNewTabSection$2.selectionChanged(MyNewTabSection.java:178)
at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java:162)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
at org.eclipse.core.runtime.Platform.run(Platform.java:880)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:48)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
at org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer.java:160)
at org.eclipse.jface.viewers.StructuredViewer.updateSelection(StructuredViewer.java:2062)
at org.eclipse.jface.viewers.StructuredViewer.setSelection(StructuredViewer.java:1638)
at org.eclipse.jface.viewers.Viewer.setSelection(Viewer.java:392)
at com.test.plugin.sections.MyNewTabSection$2.selectionChanged(MyNewTabSection.java:178)
at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java:162)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
at org.eclipse.core.runtime.Platform.run(Platform.java:880)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:48)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
at org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer.java:160)
at org.eclipse.jface.viewers.StructuredViewer.updateSelection(StructuredViewer.java:2062)
at org.eclipse.jface.viewers.StructuredViewer.setSelection(StructuredViewer.java:1638)
at org.eclipse.jface.viewers.Viewer.setSelection(Viewer.java:392)
at com.test.plugin.sections.MyNewTabSection$2.selectionChanged(MyNewTabSection.java:178)
at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java:162)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
at org.eclipse.core.runtime.Platform.run(Platform.java:880)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:48)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
at org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer.java:160)
at org.eclipse.jface.viewers.StructuredViewer.updateSelection(StructuredViewer.java:2062)
at org.eclipse.jface.viewers.StructuredViewer.setSelection(StructuredViewer.java:1638)
at org.eclipse.jface.viewers.Viewer.setSelection(Viewer.java:392)
at com.test.plugin.sections.MyNewTabSection$2.selectionChanged(MyNewTabSection.java:178)
at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java:162)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
at org.eclipse.core.runtime.Platform.run(Platform.java:880)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:48)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
at org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer.java:160)
at org.eclipse.jface.viewers.StructuredViewer.updateSelection(StructuredViewer.java:2062)
at org.eclipse.jface.viewers.StructuredViewer.setSelection(StructuredViewer.java:1638)
at org.eclipse.jface.viewers.Viewer.setSelection(Viewer.java:392)
at com.test.plugin.sections.MyNewTabSection$2.selectionChanged(MyNewTabSection.java:178)
at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java:162)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
at org.eclipse.core.runtime.Platform.run(Platform.java:880)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:48)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
at org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer.java:160)
at org.eclipse.jface.viewers.StructuredViewer.updateSelection(StructuredViewer.java:2062)
at org.eclipse.jface.viewers.StructuredViewer.setSelection(StructuredViewer.java:1638)
at org.eclipse.jface.viewers.Viewer.setSelection(Viewer.java:392)
at com.test.plugin.sections.MyNewTabSection$2.selectionChanged(MyNewTabSection.java:178)
at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java:162)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
at org.eclipse.core.runtime.Platform.run(Platform.java:880)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:48)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
at org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer.java:160)
at org.eclipse.jface.viewers.StructuredViewer.updateSelection(StructuredViewer.java:2062)
at org.eclipse.jface.viewers.StructuredViewer.setSelection(StructuredViewer.java:1638)
at org.eclipse.jface.viewers.Viewer.setSelection(Viewer.java:392)
at com.test.plugin.sections.MyNewTabSection$2.selectionChanged(MyNewTabSection.java:178)
at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java:162)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
at org.eclipse.core.runtime.Platform.run(Platform.java:880)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:48)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
at org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer.java:160)
at org.eclipse.jface.viewers.StructuredViewer.updateSelection(StructuredViewer.java:2062)
at org.eclipse.jface.viewers.StructuredViewer.setSelection(StructuredViewer.java:1638)
at org.eclipse.jface.viewers.Viewer.setSelection(Viewer.java:392)
at com.test.plugin.sections.MyNewTabSection$2.selectionChanged(MyNewTabSection.java:178)
at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java:162)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
at org.eclipse.core.runtime.Platform.run(Platform.java:880)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:48)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
at org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer.java:160)
at org.eclipse.jface.viewers.StructuredViewer.updateSelection(StructuredViewer.java:2062)
at org.eclipse.jface.viewers.StructuredViewer.setSelection(StructuredViewer.java:1638)
at org.eclipse.jface.viewers.Viewer.setSelection(Viewer.java:392)
at com.test.plugin.sections.MyNewTabSection$2.selectionChanged(MyNewTabSection.java:178)
at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java:162)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
at org.eclipse.core.runtime.Platform.run(Platform.java:880)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:48)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
at org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer.java:160)
at org.eclipse.jface.viewers.StructuredViewer.updateSelection(StructuredViewer.java:2062)
at org.eclipse.jface.viewers.StructuredViewer.setSelection(StructuredViewer.java:1638)
at org.eclipse.jface.viewers.Viewer.setSelection(Viewer.java:392)
at com.test.plugin.sections.MyNewTabSection$2.selectionChanged(MyNewTabSection.java:178)
at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java:162)
Certainly comboViewer.setSelection
in your listener trigger a SelectionChange
event that will be caught by your listener which trigger ... and so on