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=afa7f40a2242764bc02d1970ed3a790cc25146f5;hb=ffae9b42c7c9d7c22e8f3a976aea5055d1cb9526;hp=914fb2f3c0832720c75dd966c5220546e05ada34;hpb=38902818500a67f6a55973b9acbd4194f7a82838;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 914fb2f3..afa7f40a 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); @@ -54,13 +77,17 @@ public class InstructionTable private void createColumns() { + viewer.getTable().setVisible(false); + 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 +95,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,11 +120,15 @@ 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); } + + 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) @@ -136,10 +176,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) { @@ -152,9 +201,6 @@ public class InstructionTable column.pack(); if (column.getWidth() < maxWidth) column.setWidth(maxWidth); - column.setResizable(true); - column.setMoveable(false); - return viewerColumn; } public LazyTableViewer getTableViewer()