Merge branch 'development' of
authorFabian Stemmler <stemmler@in.tum.de>
Fri, 20 Sep 2019 16:23:46 +0000 (18:23 +0200)
committerFabian Stemmler <stemmler@in.tum.de>
Fri, 20 Sep 2019 16:23:46 +0000 (18:23 +0200)
https://gitlab.lrz.de/lrr-tum/students/eragp-misim-2019.git into
development

Conflicts:
plugins/net.mograsim.machine/src/net/mograsim/machine/mi/MicroInstructionMemoryParser.java
plugins/net.mograsim.plugin.core/META-INF/MANIFEST.MF

1  2 
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionTable.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionView.java

@@@ -57,10 -57,12 +57,12 @@@ public class InstructionTabl
                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();
  
                {
                        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())
                        {
                                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" };
                        provider = new IntegerColumnLabelProvider(displaySettings, index);
                        break;
                case MNEMONIC:
+ //                    viewerColumn.setEditingSupport(editingSupport)
                        support = new MnemonicEditingSupport(viewer, miDef, index, this.provider);
                        provider = new ParameterLabelProvider(index);
                        break;
                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)
                {
                column.pack();
                if (column.getWidth() < maxWidth)
                        column.setWidth(maxWidth);
-               column.setResizable(true);
-               column.setMoveable(false);
-               return viewerColumn;
        }
  
        public LazyTableViewer getTableViewer()
@@@ -1,10 -1,10 +1,10 @@@
  package net.mograsim.plugin.tables.mi;
  
 -import java.io.BufferedReader;
 -import java.io.File;
 -import java.io.FileReader;
  import java.io.IOException;
 +import java.io.InputStream;
  
 +import org.eclipse.core.resources.IFile;
 +import org.eclipse.core.runtime.CoreException;
  import org.eclipse.core.runtime.IProgressMonitor;
  import org.eclipse.swt.SWT;
  import org.eclipse.swt.layout.GridData;
@@@ -12,9 -12,10 +12,9 @@@ import org.eclipse.swt.layout.GridLayou
  import org.eclipse.swt.widgets.Button;
  import org.eclipse.swt.widgets.Composite;
  import org.eclipse.swt.widgets.Display;
 -import org.eclipse.swt.widgets.FileDialog;
  import org.eclipse.ui.IEditorInput;
  import org.eclipse.ui.IEditorSite;
 -import org.eclipse.ui.IPathEditorInput;
 +import org.eclipse.ui.IFileEditorInput;
  import org.eclipse.ui.PartInitException;
  import org.eclipse.ui.part.EditorPart;
  
@@@ -33,6 -34,7 +33,6 @@@ public class InstructionView extends Ed
        private InstructionTableContentProvider provider;
        private int highlighted = 0;
        private boolean dirty = false;
 -      private String machineName;
        private MicroInstructionMemory memory;
        private InstructionTable table;
  
@@@ -66,7 -68,8 +66,8 @@@
                        viewer.highlightRow(highlighted, false);
                        highlighted = index;
                        viewer.highlightRow(index, true);
-                       viewer.getTable().setTopIndex(index);
+                       viewer.getTable().showItem(viewer.getTable().getItem(Math.min((int) memory.getDefinition().getMaximalAddress(), index + 2)));
+                       viewer.getTable().showItem(viewer.getTable().getItem(index));
                });
        }
  
        public void bindMicroInstructionMemory(MicroInstructionMemory memory)
        {
                this.memory = memory;
 -              this.memory.registerCellModifiedListener(this);
 -              this.memory.registerActiveMicroInstructionChangedListener(this);
 +              if (memory != null)
 +              {
 +                      this.memory.registerCellModifiedListener(this);
 +                      this.memory.registerActiveMicroInstructionChangedListener(this);
 +              }
                if (table != null)
                        table.bindMicroInstructionMemory(memory);
        }
  
 -      private void open(String file)
 +      private void open(IFile file)
        {
 -              try (BufferedReader bf = new BufferedReader(new FileReader(file)))
 +              try
                {
 -                      machineName = bf.readLine();
 -                      bindMicroInstructionMemory(MicroInstructionMemoryParser.parseMemory(machineName, bf));
 +                      bindMicroInstructionMemory(MicroInstructionMemoryParser.parseMemory(
 +                                      MachineContext.getInstance().getMachine().getDefinition().getMicroInstructionMemoryDefinition(), file.getContents()));
                }
 -              catch (IOException | MicroInstructionMemoryParseException e)
 +              catch (IOException | MicroInstructionMemoryParseException | CoreException e)
                {
                        e.printStackTrace();
                }
        }
  
 -      private void save(String file)
 +      private void save(IFile file, IProgressMonitor progressMonitor)
        {
                if (memory == null)
                {
                        System.err.println("Failed to write MicroprogrammingMemory to File. No MicroprogrammingMemory assigned.");
                        return;
                }
 -              try
 +              try (InputStream toWrite = MicroInstructionMemoryParser.write(memory))
                {
 -                      MicroInstructionMemoryParser.write(memory, machineName, file);
 +                      file.setContents(toWrite, 0, progressMonitor);
                }
 -              catch (IOException e)
 +              catch (IOException | CoreException e)
                {
                        e.printStackTrace();
                }
        public void doSave(IProgressMonitor progressMonitor)
        {
                IEditorInput input = getEditorInput();
 -              if (input instanceof IPathEditorInput)
 +              if (input instanceof IFileEditorInput)
                {
 -                      IPathEditorInput pathInput = (IPathEditorInput) input;
 -                      save(pathInput.getPath().toOSString());
 +                      IFileEditorInput pathInput = (IFileEditorInput) input;
 +                      save(pathInput.getFile(), progressMonitor);
                        setDirty(false);
                }
        }
        @Override
        public void doSaveAs()
        {
 -              openSaveAsDialog();
 +//            openSaveAsDialog();
        }
  
 -      private void openSaveAsDialog()
 -      {
 -              FileDialog d = new FileDialog(table.getTableViewer().getTable().getShell(), SWT.SAVE);
 -              d.open();
 -              String filename = d.getFileName();
 -              if (!filename.equals(""))
 -              {
 -                      save(d.getFilterPath() + File.separator + filename);
 -                      setDirty(false);
 -              }
 -      }
 +//    private void openSaveAsDialog()
 +//    {
 +//            FileDialog d = new FileDialog(table.getTableViewer().getTable().getShell(), SWT.SAVE);
 +//            d.open();
 +//            String filename = d.getFileName();
 +//            if (!filename.equals(""))
 +//            {
 +//                    save(d.getFilterPath() + File.separator + filename);
 +//                    setDirty(false);
 +//            }
 +//    }
  
        @Override
        public void init(IEditorSite site, IEditorInput input) throws PartInitException
        {
                setSite(site);
                setInput(input);
 -              if (input instanceof IPathEditorInput)
 +              if (input instanceof IFileEditorInput)
                {
 -                      IPathEditorInput pathInput = (IPathEditorInput) input;
 -                      setPartName(pathInput.getName());
 -                      open(pathInput.getPath().toOSString());
 +                      IFileEditorInput fileInput = (IFileEditorInput) input;
 +                      setPartName(fileInput.getName());
 +                      open(fileInput.getFile());
                }
 +
        }
  
        @Override
        @Override
        public boolean isSaveAsAllowed()
        {
 -              return true;
 +              return false;
        }
  
        @Override