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=936ba5c49a1b4bc69439c45d6f08dfe0db7a80ba;hb=232048c3959adad5f2c4caf9be97add732daecfc;hp=93179c08d43dcf91a170ce987a98e51cb74dd8be;hpb=41292b984ee229deb329c83b525006fd2840becb;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 93179c08..936ba5c4 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 @@ -57,10 +57,12 @@ public class InstructionTable int size = miDef.size(); columns = new TableViewerColumn[size + 1]; - TableViewerColumn col = createTableViewerColumn("Address", generateLongestHexStrings(12)); + TableViewerColumn col = createTableViewerColumn("Address"); columns[0] = col; col.setLabelProvider(new AddressLabelProvider()); + String[] columnTitles = new String[size]; + int bit = miDef.sizeInBits(); ParameterClassification[] classes = miDef.getParameterClassifications(); @@ -68,8 +70,17 @@ public class InstructionTable { int startBit = bit - 1; int endBit = bit = bit - classes[i].getExpectedBits(); - String name = startBit == endBit ? Integer.toString(startBit) : startBit + "..." + endBit; + String columnTitle = calculateColumnTitle(startBit, endBit); + columnTitles[i] = columnTitle; + col = createTableViewerColumn(columnTitle); + columns[i + 1] = col; + createEditingAndLabel(col, miDef, i); + } + calculateOptimalColumnSize(0, "Address", generateLongestHexStrings(12)); + + for (int i = 0; i < size; i++) + { String[] longestPossibleContents; switch (classes[i].getExpectedType()) { @@ -84,18 +95,23 @@ public class InstructionTable longestPossibleContents = new String[0]; break; } - - col = createTableViewerColumn(name, longestPossibleContents); - columns[i + 1] = col; - createEditingAndLabel(col, miDef, i); + calculateOptimalColumnSize(i + 1, columnTitles[i], longestPossibleContents); } } + private static String calculateColumnTitle(int startBit, int endBit) + { + return startBit == endBit ? Integer.toString(startBit) : startBit + "..." + endBit; + } + public void bindMicroInstructionMemory(MicroInstructionMemory memory) { this.memory = memory; - this.miDef = memory.getDefinition().getMicroInstructionDefinition(); - setViewerInput(memory); + if (memory != null) + { + this.miDef = memory.getDefinition().getMicroInstructionDefinition(); + setViewerInput(memory); + } } private static final String[] HEX_DIGITS = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" }; @@ -121,6 +137,7 @@ 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; @@ -133,10 +150,19 @@ public class InstructionTable col.getColumn().setToolTipText(miDef.getParameterDescription(index).orElse("")); } - private TableViewerColumn createTableViewerColumn(String title, String... longestPossibleContents) + private TableViewerColumn createTableViewerColumn(String title) { TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE); TableColumn column = viewerColumn.getColumn(); + column.setText(title); + column.setResizable(true); + column.setMoveable(false); + return viewerColumn; + } + + private void calculateOptimalColumnSize(int i, String title, String... longestPossibleContents) + { + TableColumn column = viewer.getTable().getColumn(i); int maxWidth = 0; for (String s : longestPossibleContents) { @@ -149,9 +175,6 @@ public class InstructionTable column.pack(); if (column.getWidth() < maxWidth) column.setWidth(maxWidth); - column.setResizable(true); - column.setMoveable(false); - return viewerColumn; } public LazyTableViewer getTableViewer()