X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2Ftables%2Fmi%2FInstructionTable.java;h=25c0f7176d68d003846ce5736e7604bb9e51abf3;hb=648fc6e69e09fe4467cb6bac47934be1a7dcf0d6;hp=a806bd28c0abc0ceeb8051fc4687dcbf857ac2a9;hpb=a60db0eb036058aa47c928653da0b504452aa595;p=Mograsim.git 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 a806bd28..25c0f717 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 @@ -1,5 +1,7 @@ package net.mograsim.plugin.tables.mi; +import static net.mograsim.plugin.preferences.PluginPreferences.MPM_EDITOR_BITS_AS_COLUMN_NAME; + import java.util.Arrays; import org.eclipse.jface.viewers.ColumnLabelProvider; @@ -25,6 +27,7 @@ import net.mograsim.machine.mi.MicroInstructionDefinition; import net.mograsim.machine.mi.MicroInstructionMemory; import net.mograsim.machine.mi.parameters.MnemonicFamily; import net.mograsim.machine.mi.parameters.ParameterClassification; +import net.mograsim.plugin.MograsimActivator; import net.mograsim.plugin.tables.AddressLabelProvider; import net.mograsim.plugin.tables.DisplaySettings; import net.mograsim.plugin.tables.LazyTableViewer; @@ -38,14 +41,22 @@ public class InstructionTable private MicroInstructionMemory memory; private InstructionTableContentProvider provider; private final RowHighlighter highlighter; - private final ColorProvider cProv; + private final FontAndColorHelper cProv; + + private final boolean isEditable; public InstructionTable(Composite parent, DisplaySettings displaySettings, IThemeManager themeManager) + { + this(parent, displaySettings, themeManager, true); + } + + public InstructionTable(Composite parent, DisplaySettings displaySettings, IThemeManager themeManager, boolean allowEditing) { viewer = new LazyTableViewer(parent, SWT.FULL_SELECTION | SWT.BORDER | SWT.VIRTUAL); this.displaySettings = displaySettings; - this.cProv = new ColorProvider(viewer, themeManager); + this.cProv = new FontAndColorHelper(viewer, themeManager); this.highlighter = new RowHighlighter(viewer, cProv); + this.isEditable = allowEditing; Table table = viewer.getTable(); table.setHeaderVisible(true); @@ -90,7 +101,7 @@ public class InstructionTable int size = miDef.size(); columns = new TableViewerColumn[size + 1]; - TableViewerColumn col = createTableViewerColumn("Address"); + TableViewerColumn col = createTableViewerColumn("Address", null); columns[0] = col; col.setLabelProvider(new AddressLabelProvider() { @@ -122,9 +133,18 @@ public class InstructionTable { int startBit = bit - 1; int endBit = bit = bit - classes[i].getExpectedBits(); - String columnTitle = calculateColumnTitle(startBit, endBit); + + String columnTitle; + String bitString = startBit == endBit ? Integer.toString(startBit) : startBit + "..." + endBit; + // TODO add a listener + if (MograsimActivator.instance().getPluginPrefs().getBoolean(MPM_EDITOR_BITS_AS_COLUMN_NAME)) + columnTitle = bitString; + else + columnTitle = miDef.getParameterTitle(i).orElse(bitString); columnTitles[i] = columnTitle; - col = createTableViewerColumn(columnTitle); + String columnTooltip = miDef.getParameterDescription(i).orElse(null); + + col = createTableViewerColumn(columnTitle, columnTooltip); columns[i + 1] = col; createEditingAndLabel(col, miDef, i); } @@ -153,11 +173,6 @@ public class InstructionTable viewer.getTable().setVisible(true); } - private static String calculateColumnTitle(int startBit, int endBit) - { - return startBit == endBit ? Integer.toString(startBit) : startBit + "..." + endBit; - } - public void bindMicroInstructionMemory(MicroInstructionMemory memory) { this.memory = memory; @@ -183,31 +198,32 @@ public class InstructionTable switch (parameterClassification.getExpectedType()) { case BOOLEAN_IMMEDIATE: - support = new BooleanEditingSupport(viewer, miDef, index); + support = isEditable ? new BooleanEditingSupport(viewer, miDef, index) : null; provider = new ParameterLabelProvider(cProv, index); break; case INTEGER_IMMEDIATE: - support = new IntegerEditingSupport(viewer, miDef, index, displaySettings, this.provider); + support = isEditable ? new IntegerEditingSupport(viewer, miDef, index, displaySettings, this.provider) : null; provider = new IntegerColumnLabelProvider(displaySettings, cProv, index); break; case MNEMONIC: - support = new MnemonicEditingSupport(viewer, miDef, index, this.provider); + support = isEditable ? new MnemonicEditingSupport(viewer, miDef, index, this.provider) : null; provider = new ParameterLabelProvider(cProv, index); break; default: throw new IllegalStateException( "Unable to create EditingSupport for unknown ParameterType " + parameterClassification.getExpectedType()); } - col.setEditingSupport(support); + if (isEditable) + col.setEditingSupport(support); col.setLabelProvider(provider); - col.getColumn().setToolTipText(miDef.getParameterDescription(index).orElse("")); } - private TableViewerColumn createTableViewerColumn(String title) + private TableViewerColumn createTableViewerColumn(String title, String toolTip) { TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE); TableColumn column = viewerColumn.getColumn(); column.setText(title); + column.setToolTipText(toolTip); column.setResizable(true); column.setMoveable(false); return viewerColumn;