From: Daniel Kirschten Date: Mon, 23 Sep 2019 15:43:48 +0000 (+0200) Subject: Made InstructionTable a bit easier to use X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=424226156a244e05c560248efeabdf6f8eccc181;p=Mograsim.git Made InstructionTable a bit easier to use --- 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 fa7a918b..8cdaae27 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,19 +1,21 @@ package net.mograsim.plugin.tables.mi; import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.CheckboxCellEditor; +import org.eclipse.jface.viewers.ComboBoxCellEditor; import org.eclipse.jface.viewers.EditingSupport; import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.swt.SWT; 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; import net.mograsim.machine.mi.parameters.MicroInstructionParameter; +import net.mograsim.machine.mi.parameters.Mnemonic; public class BooleanEditingSupport extends EditingSupport { - private final CheckboxCellEditor editor; + private final ComboBoxCellEditor editor; private final BooleanClassification boolClass; private final TableViewer viewer; private final int index; @@ -23,7 +25,10 @@ public class BooleanEditingSupport extends EditingSupport super(viewer); this.viewer = viewer; this.boolClass = (BooleanClassification) definition.getParameterClassification(index); - editor = new CheckboxCellEditor(viewer.getTable()); + editor = new ComboBoxCellEditor(viewer.getTable(), boolClass.getStringValues(), SWT.READ_ONLY); + editor.setActivationStyle( + ComboBoxCellEditor.DROP_DOWN_ON_TRAVERSE_ACTIVATION | ComboBoxCellEditor.DROP_DOWN_ON_PROGRAMMATIC_ACTIVATION + | ComboBoxCellEditor.DROP_DOWN_ON_MOUSE_ACTIVATION | ComboBoxCellEditor.DROP_DOWN_ON_KEY_ACTIVATION); this.index = index; } @@ -43,7 +48,8 @@ public class BooleanEditingSupport extends EditingSupport protected Object getValue(Object element) { InstructionTableRow row = (InstructionTableRow) element; - return row.data.getCell(row.address).getParameter(index).getValue().getMSBit(0).equals(Bit.ONE); + // 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) ? 0 : 1; } @Override @@ -51,7 +57,11 @@ public class BooleanEditingSupport extends EditingSupport { InstructionTableRow row = (InstructionTableRow) element; MicroInstructionParameter[] params = row.data.getCell(row.address).getParameters(); - params[index] = boolClass.get((Boolean) value); + // true is 0 because the true value comes first in the combo box + Mnemonic newParam = boolClass.get(value.equals(0) ? true : false); + if (newParam.equals(params[index])) + return; + params[index] = newParam; row.data.setCell(row.address, MicroInstruction.create(params)); viewer.update(element, null); } diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionTable.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionTable.java index 936ba5c4..2a3ad6c0 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionTable.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionTable.java @@ -3,8 +3,14 @@ package net.mograsim.plugin.tables.mi; import java.util.Arrays; import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.jface.viewers.ColumnViewerEditor; +import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent; +import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy; import org.eclipse.jface.viewers.EditingSupport; +import org.eclipse.jface.viewers.FocusCellOwnerDrawHighlighter; import org.eclipse.jface.viewers.TableViewerColumn; +import org.eclipse.jface.viewers.TableViewerEditor; +import org.eclipse.jface.viewers.TableViewerFocusCellManager; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; @@ -31,7 +37,7 @@ public class InstructionTable public InstructionTable(Composite parent, DisplaySettings displaySettings) { - viewer = new LazyTableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER | SWT.VIRTUAL); + viewer = new LazyTableViewer(parent, SWT.FULL_SELECTION | SWT.BORDER | SWT.VIRTUAL); this.displaySettings = displaySettings; Table table = viewer.getTable(); @@ -39,6 +45,23 @@ public class InstructionTable table.setLinesVisible(true); viewer.setUseHashlookup(true); + TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(viewer, new FocusCellOwnerDrawHighlighter(viewer)); + + ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(viewer) + { + @Override + protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) + { + return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL + || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION + || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR) + || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC; + } + }; + int features = ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR + | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION; + TableViewerEditor.create(viewer, focusCellManager, actSupport, features); + GridData viewerData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH); viewerData.horizontalSpan = 3; viewer.getTable().setLayoutData(viewerData); @@ -137,7 +160,6 @@ public class InstructionTable provider = new IntegerColumnLabelProvider(displaySettings, index); break; case MNEMONIC: -// viewerColumn.setEditingSupport(editingSupport) support = new MnemonicEditingSupport(viewer, miDef, index, this.provider); provider = new ParameterLabelProvider(index); break; diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionTableRow.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionTableRow.java index 7cef835b..4966b139 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionTableRow.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionTableRow.java @@ -9,4 +9,4 @@ public class InstructionTableRow extends TableRow { super(address, data); } -} +} \ No newline at end of file diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerEditingSupport.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerEditingSupport.java index 4f5b6161..a821a76a 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerEditingSupport.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerEditingSupport.java @@ -32,7 +32,10 @@ public class IntegerEditingSupport extends NumberCellEditingSupport { InstructionTableRow row = ((InstructionTableRow) element); MicroInstructionParameter[] params = row.data.getCell(row.address).getParameters(); - params[index] = new IntegerImmediate(value, classification.getExpectedBits()); + IntegerImmediate newParam = new IntegerImmediate(value, classification.getExpectedBits()); + if (params[index].equals(newParam)) + return; + params[index] = newParam; row.data.setCell(row.address, MicroInstruction.create(params)); provider.update(row.address); // viewer.update(element, null); Does not do anything for some reason diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/MnemonicCellEditorValidator.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/MnemonicCellEditorValidator.java deleted file mode 100644 index 98181c46..00000000 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/MnemonicCellEditorValidator.java +++ /dev/null @@ -1,24 +0,0 @@ -package net.mograsim.plugin.tables.mi; - -import org.eclipse.jface.viewers.ICellEditorValidator; - -import net.mograsim.machine.mi.parameters.MnemonicFamily; - -public class MnemonicCellEditorValidator implements ICellEditorValidator -{ - private MnemonicFamily family; - - public MnemonicCellEditorValidator(MnemonicFamily family) - { - this.family = family; - } - - @Override - public String isValid(Object value) - { - int index = (Integer) value; - return index >= 0 && index < family.size() ? null - : String.format("MnemonicFamily has %s elements, index %s is out of bounds", family.size(), value.toString()); - } - -} diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/MnemonicEditingSupport.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/MnemonicEditingSupport.java index 1140e683..7248f4f5 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/MnemonicEditingSupport.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/MnemonicEditingSupport.java @@ -25,8 +25,10 @@ public class MnemonicEditingSupport extends EditingSupport super(viewer); family = (MnemonicFamily) definition.getParameterClassifications()[index]; editor = new ComboBoxCellEditor(viewer.getTable(), family.getStringValues(), SWT.READ_ONLY); + editor.setActivationStyle( + ComboBoxCellEditor.DROP_DOWN_ON_TRAVERSE_ACTIVATION | ComboBoxCellEditor.DROP_DOWN_ON_PROGRAMMATIC_ACTIVATION + | ComboBoxCellEditor.DROP_DOWN_ON_MOUSE_ACTIVATION | ComboBoxCellEditor.DROP_DOWN_ON_KEY_ACTIVATION); this.index = index; - editor.setValidator(new MnemonicCellEditorValidator(family)); this.provider = provider; } @@ -54,7 +56,10 @@ public class MnemonicEditingSupport extends EditingSupport { InstructionTableRow row = ((InstructionTableRow) element); MicroInstructionParameter[] params = row.data.getCell(row.address).getParameters(); - params[index] = family.get((Integer) value); + Mnemonic newParam = family.get((Integer) value); + if (newParam.equals(params[index])) + return; + params[index] = newParam; row.data.setCell(row.address, MicroInstruction.create(params)); provider.update(row.address); }