From 5500a6f4e7508013b52dcbc1c7dad34f31cfd4f0 Mon Sep 17 00:00:00 2001 From: Fabian Stemmler Date: Thu, 26 Sep 2019 16:43:53 +0200 Subject: [PATCH] Created CyclingCellEditor for BooleanEditingSupport --- .../tables/mi/BooleanEditingSupport.java | 8 +-- .../plugin/tables/mi/CyclingCellEditor.java | 61 +++++++++++++++++++ 2 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/CyclingCellEditor.java diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/BooleanEditingSupport.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/BooleanEditingSupport.java index 8fbfe392..3c0a6124 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/BooleanEditingSupport.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/BooleanEditingSupport.java @@ -1,11 +1,9 @@ package net.mograsim.plugin.tables.mi; import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.CheckboxCellEditor; import org.eclipse.jface.viewers.EditingSupport; import org.eclipse.jface.viewers.TableViewer; -import net.mograsim.logic.core.types.Bit; import net.mograsim.machine.mi.MicroInstruction; import net.mograsim.machine.mi.MicroInstructionDefinition; import net.mograsim.machine.mi.parameters.BooleanClassification; @@ -24,7 +22,7 @@ public class BooleanEditingSupport extends EditingSupport super(viewer); this.viewer = viewer; this.boolClass = (BooleanClassification) definition.getParameterClassification(index); - editor = new CheckboxCellEditor(viewer.getTable()); + editor = new CyclingCellEditor(viewer.getTable(), boolClass.size());// new CheckboxCellEditor(viewer.getTable()); this.index = index; } @@ -45,7 +43,7 @@ public class BooleanEditingSupport extends EditingSupport { InstructionTableRow row = (InstructionTableRow) element; // true is 0 because the true value comes first in the combo box - return row.data.getCell(row.address).getParameter(index).getValue().getMSBit(0).equals(Bit.ONE); + return ((Mnemonic) row.data.getCell(row.address).getParameter(index)).ordinal(); } @Override @@ -54,7 +52,7 @@ public class BooleanEditingSupport extends EditingSupport InstructionTableRow row = (InstructionTableRow) element; MicroInstructionParameter[] params = row.data.getCell(row.address).getParameters(); // true is 0 because the true value comes first in the combo box - Mnemonic newParam = boolClass.get((Boolean) value); + Mnemonic newParam = boolClass.get((Integer) value); params[index] = newParam; row.data.setCell(row.address, MicroInstruction.create(params)); diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/CyclingCellEditor.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/CyclingCellEditor.java new file mode 100644 index 00000000..41ec10cc --- /dev/null +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/CyclingCellEditor.java @@ -0,0 +1,61 @@ +package net.mograsim.plugin.tables.mi; + +import org.eclipse.jface.viewers.CellEditor; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; + +public class CyclingCellEditor extends CellEditor +{ + private final int size; + private int index = -1; + + public CyclingCellEditor(int size) + { + super(); + this.size = size; + } + + public CyclingCellEditor(Composite parent, int size) + { + super(parent); + this.size = size; + } + + public CyclingCellEditor(Composite parent, int size, int style) + { + super(parent, style); + this.size = size; + } + + @Override + protected Control createControl(Composite parent) + { + // Nothing to return + return null; + } + + @Override + protected Object doGetValue() + { + return index; + } + + @Override + protected void doSetFocus() + { + // Nothing to focus + } + + @Override + protected void doSetValue(Object index) + { + this.index = (Integer) index; + } + + @Override + public void activate() + { + index = (index + 1) % size; + fireApplyEditorValue(); + } +} -- 2.17.1