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=2a3ad6c06e7d58489721170bc3ec97a492836118;hb=3eb713f4790896fbb3b71028a03b946a3d12dbd0;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..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); @@ -57,10 +80,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 +93,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 +118,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" }; @@ -133,10 +172,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 +197,6 @@ public class InstructionTable column.pack(); if (column.getWidth() < maxWidth) column.setWidth(maxWidth); - column.setResizable(true); - column.setMoveable(false); - return viewerColumn; } public LazyTableViewer getTableViewer()