Merge branch 'development' of
authorFabian Stemmler <stemmler@in.tum.de>
Tue, 24 Sep 2019 14:29:34 +0000 (16:29 +0200)
committerFabian Stemmler <stemmler@in.tum.de>
Tue, 24 Sep 2019 14:29:34 +0000 (16:29 +0200)
https://gitlab.lrz.de/lrr-tum/students/eragp-misim-2019.git into
development

Conflicts:
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/views/LogicUIPart.java

21 files changed:
plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900MachineDefinition.java
plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/LogicUICanvas.java
plugins/net.mograsim.machine/src/net/mograsim/machine/MachineDefinition.java
plugins/net.mograsim.machine/src/net/mograsim/machine/MachineRegistry.java
plugins/net.mograsim.plugin.core/plugin.xml
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/MachineContext.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/MainPreferencePage.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/AddMograsimNatureHandler.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/MachineContext.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/MachineContextSwtTools.java [new file with mode: 0644]
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/ProjectContextEvent.java [new file with mode: 0644]
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/ProjectContextListener.java [new file with mode: 0644]
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/ProjectMachineContext.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/BooleanEditingSupport.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionTable.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionTableRow.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerEditingSupport.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/MnemonicCellEditorValidator.java [deleted file]
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/MnemonicEditingSupport.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/views/LogicUIPart.java
plugins/net.mograsim.preferences/src/net/mograsim/preferences/DefaultPreferences.java

index e75c79a..1ed0372 100644 (file)
@@ -11,6 +11,14 @@ import net.mograsim.machine.Register;
 //(used for detecting installed machines in plugin.core)
 public class Am2900MachineDefinition implements MachineDefinition
 {
+       public static final String AM2900_MACHINE_ID = "Am2900";
+
+       @Override
+       public String getId()
+       {
+               return AM2900_MACHINE_ID;
+       }
+
        @Override
        public Am2900Machine createNew()
        {
@@ -65,4 +73,5 @@ public class Am2900MachineDefinition implements MachineDefinition
        {
                return Am2900MicroInstructionMemoryDefinition.instance;
        }
+
 }
index c4a8c2d..50e6471 100644 (file)
@@ -27,8 +27,7 @@ import net.mograsim.logic.core.types.BitVector;
 import net.mograsim.logic.model.model.LogicModel;
 import net.mograsim.logic.model.model.components.ModelComponent;
 import net.mograsim.logic.model.model.components.submodels.SubmodelComponent;
-import net.mograsim.logic.model.model.components.submodels.SubmodelInterface;
-import net.mograsim.logic.model.model.wires.ModelWireCrossPoint;
+import net.mograsim.logic.model.snippets.highlevelstatehandlers.DefaultHighLevelStateHandler;
 import net.mograsim.preferences.Preferences;
 
 /**
@@ -216,21 +215,24 @@ public class LogicUICanvas extends ZoomableCanvas
                recalculateQueued.set(false);
                componentsByItemIndex.clear();
                componentSelector.setItems();
-               addComponentSelectorItems(componentsByItemIndex, "", componentSelector, model);
+               addComponentSelectorItems(componentsByItemIndex, "", componentSelector, model,
+                               Preferences.current().getInt("net.mograsim.logic.model.debug.hlsshelldepth"));
        }
 
        private void addComponentSelectorItems(List<ModelComponent> componentsByItemIndex, String base, Combo componentSelector,
-                       LogicModel model)
+                       LogicModel model, int depth)
        {
                model.getComponentsByName().values().stream().sorted((c1, c2) -> c1.getName().compareTo(c2.getName())).forEach(c ->
                {
-                       if (!(c instanceof ModelWireCrossPoint || c instanceof SubmodelInterface))
+                       if (!(c.getHighLevelStateHandler() instanceof DefaultHighLevelStateHandler))
                        {
                                String item = base + c.getName();
                                componentsByItemIndex.add(c);
                                componentSelector.add(item);
-                               if (c instanceof SubmodelComponent)
-                                       addComponentSelectorItems(componentsByItemIndex, item + " -> ", componentSelector, ((SubmodelComponent) c).submodel);
+                               // this causes negative numbers to result in infinite depth
+                               if (depth != 0 && c instanceof SubmodelComponent)
+                                       addComponentSelectorItems(componentsByItemIndex, item + " -> ", componentSelector, ((SubmodelComponent) c).submodel,
+                                                       depth - 1);
                        }
                });
        }
index 02cf375..8f1ee26 100644 (file)
@@ -6,6 +6,14 @@ import net.mograsim.machine.mi.MicroInstructionMemoryDefinition;
 
 public interface MachineDefinition
 {
+       /**
+        * This returns the MachineDefinitions ID. This must be consistent and coherent with the id in the extension point (Eclipse plugin xml)
+        * providing the definition.
+        * 
+        * @return a human readable, unique id representing the specified machine.
+        * @author Christian Femers
+        */
+       String getId();
 
        /**
         * Creates a new instance of the machine
index 28e7921..ca52eae 100644 (file)
@@ -3,7 +3,11 @@ package net.mograsim.machine;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IConfigurationElement;
 import org.eclipse.core.runtime.IExtension;
@@ -14,9 +18,11 @@ import org.eclipse.core.runtime.Platform;
 
 public class MachineRegistry
 {
+
        private static final String MACHINE_EXT_ID = "net.mograsim.machine.machine_definition";
 
-       private static final Map<String, MachineDefinition> installedMachines = new HashMap<>();
+       private static final Map<String, MachineDefinition> installedMachines = Collections.synchronizedMap(new HashMap<>());
+       private static final Set<MachineRegistryListener> listeners = Collections.synchronizedSet(new HashSet<>());
 
        private static void reload()
        {
@@ -35,7 +41,11 @@ public class MachineRegistry
                                if (o instanceof MachineDefinition)
                                {
                                        System.out.println("Found " + id);
-                                       installedMachines.put(id, (MachineDefinition) o);
+                                       MachineDefinition md = (MachineDefinition) o;
+                                       if (Objects.equals(id, md.getId()))
+                                               installedMachines.put(id, md);
+                                       else
+                                               System.err.println("Machine definition ids to not match: " + id + " and " + md.getId());
                                } else
                                {
                                        System.err.println("Invalid machine definition: " + o + "(id=" + id + "");
@@ -46,6 +56,7 @@ public class MachineRegistry
                {
                        System.out.println(ex.getMessage());
                }
+               notifyListeners();
        }
 
        public static void initialize()
@@ -89,4 +100,26 @@ public class MachineRegistry
        {
                return installedMachines.get(id);
        }
+
+       private static void notifyListeners()
+       {
+               Map<String, MachineDefinition> unmodMachines = getInstalledMachines();
+               listeners.forEach(l -> l.onReload(unmodMachines));
+       }
+
+       public static void addMachineRegistryListener(MachineRegistryListener listener)
+       {
+               listeners.add(listener);
+       }
+
+       public static void removeMachineRegistryListener(MachineRegistryListener listener)
+       {
+               listeners.remove(listener);
+       }
+
+       @FunctionalInterface
+       public interface MachineRegistryListener
+       {
+               void onReload(Map<String, MachineDefinition> installedMachines);
+       }
 }
index e9c762a..76a2161 100644 (file)
             category="net.mograsim.plugin"
             class="net.mograsim.plugin.views.LogicUIPart"
             icon="icons/mograsim/blue-orange/icon_blue-orange_16.png"
-            id="net.mograsim.plugin.core.view1"
+            id="net.mograsim.plugin.core.simulationView"
             inject="true"
             name="%view.name.0"
             restorable="true">
index 9da121a..c22c1c7 100644 (file)
@@ -6,7 +6,12 @@ import java.util.Set;
 
 import net.mograsim.machine.Machine;
 import net.mograsim.machine.MachineRegistry;
+import net.mograsim.plugin.nature.ProjectMachineContext;
 
+/**
+ * @deprecated use the {@link ProjectMachineContext} instead to make the context project dependent.
+ */
+@Deprecated(forRemoval = true)
 public class MachineContext
 {
        private Machine machine;
index 69430ed..b647a08 100644 (file)
@@ -2,6 +2,8 @@ package net.mograsim.plugin;
 
 import org.eclipse.jface.preference.BooleanFieldEditor;
 import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.jface.preference.IntegerFieldEditor;
+import org.eclipse.swt.widgets.Composite;
 import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.IWorkbenchPreferencePage;
 
@@ -21,7 +23,10 @@ public class MainPreferencePage extends FieldEditorPreferencePage implements IWo
        @Override
        protected void createFieldEditors()
        {
-               addField(new BooleanFieldEditor("net.mograsim.logic.model.debug.openhlsshell", "Open the debug HLS shell", getFieldEditorParent()));
+               Composite parent = getFieldEditorParent();
+               addField(new BooleanFieldEditor("net.mograsim.logic.model.debug.openhlsshell", "Open the debug HLS shell", parent));
+               addField(new IntegerFieldEditor("net.mograsim.logic.model.debug.hlsshelldepth",
+                               "Depth of components to list in the debug HLS shell", parent));
                // TODO add other preferences
        }
 }
\ No newline at end of file
index f4d0357..aa5d5d6 100644 (file)
@@ -43,7 +43,7 @@ public class AddMograsimNatureHandler extends AbstractHandler
                                {
                                        try
                                        {
-                                               ms.add(toggleNature(project));
+                                               ms.add(addNature(project));
                                        }
                                        catch (CoreException e)
                                        {
@@ -63,7 +63,7 @@ public class AddMograsimNatureHandler extends AbstractHandler
         * @param project to have Mograsim nature
         * @return
         */
-       private IStatus toggleNature(IProject project) throws CoreException
+       public static IStatus addNature(IProject project) throws CoreException
        {
                IProjectDescription description = project.getDescription();
                String[] natures = description.getNatureIds();
index b170848..2e02e31 100644 (file)
@@ -13,6 +13,7 @@ import org.eclipse.ui.preferences.ScopedPreferenceStore;
 import net.mograsim.machine.Machine;
 import net.mograsim.machine.MachineDefinition;
 import net.mograsim.machine.MachineRegistry;
+import net.mograsim.plugin.nature.ProjectContextEvent.ProjectContextEventType;
 
 public class MachineContext
 {
@@ -112,6 +113,8 @@ public class MachineContext
        final void updateDefinition()
        {
                machineDefinition = machineId.map(MachineRegistry::getMachine);
+               machineDefinition.ifPresent(md -> setActiveMachine(md.createNew()));
+               ProjectMachineContext.notifyListeners(new ProjectContextEvent(this, ProjectContextEventType.MACHINE_DEFINITION_CHANGE));
        }
 
        private void preferenceListener(PropertyChangeEvent changeEvent)
diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/MachineContextSwtTools.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/MachineContextSwtTools.java
new file mode 100644 (file)
index 0000000..9c0ad0b
--- /dev/null
@@ -0,0 +1,199 @@
+package net.mograsim.plugin.nature;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Consumer;
+import java.util.function.Function;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jface.viewers.ComboViewer;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.ViewerComparator;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+
+import net.mograsim.machine.MachineDefinition;
+import net.mograsim.machine.MachineRegistry;
+import net.mograsim.plugin.nature.ProjectContextEvent.ProjectContextEventType;
+
+public final class MachineContextSwtTools
+{
+       private static final Map<String, MachineDefinition> INSTALLED_MACHINES = MachineRegistry.getInstalledMachines();
+       private static final Map<IProject, MachineContext> PROJECT_MACHINE_CONTEXTS = ProjectMachineContext.getAllProjectMachineContexts();
+
+       private MachineContextSwtTools()
+       {
+               // not instantiable
+       }
+
+       public static MachineCombo createMachineSelector(Composite parent, int style)
+       {
+               return new MachineCombo(parent, style);
+       }
+
+       public static MograsimProjectCombo createMograsimProjectSelector(Composite parent, int style)
+       {
+               return new MograsimProjectCombo(parent, style);
+       }
+
+       public abstract static class AdvancedCombo<T>
+       {
+               final ComboViewer combo;
+               private Set<Consumer<T>> listeners;
+
+               public AdvancedCombo(Composite parent, Function<T, String> labelProvider)
+               {
+                       this(parent, SWT.NONE, labelProvider);
+               }
+
+               public AdvancedCombo(Composite parent, int style, Function<T, String> labelProvider)
+               {
+                       listeners = Collections.synchronizedSet(new HashSet<>());
+                       combo = new ComboViewer(parent, style);
+                       combo.addSelectionChangedListener(e -> updateSelection());
+                       combo.setComparator(new ViewerComparator());
+                       combo.setLabelProvider(new LabelProvider()
+                       {
+                               @SuppressWarnings("unchecked")
+                               @Override
+                               public String getText(Object element)
+                               {
+                                       try
+                                       {
+                                               return labelProvider.apply((T) element);
+                                       }
+                                       catch (ClassCastException e)
+                                       {
+                                               return "Invalid Element: " + e.getLocalizedMessage();
+                                       }
+                               }
+                       });
+               }
+
+               public final ComboViewer getCombo()
+               {
+                       return combo;
+               }
+
+               @SuppressWarnings("unchecked")
+               public T getSelection()
+               {
+                       return (T) combo.getStructuredSelection().getFirstElement();
+               }
+
+               private void updateSelection()
+               {
+                       T active = getSelection();
+                       listeners.forEach(l -> l.accept(active));
+               }
+
+               public final void addListener(Consumer<T> listener)
+               {
+                       listeners.add(listener);
+               }
+
+               public final void removeListener(Consumer<T> listener)
+               {
+                       listeners.remove(listener);
+               }
+
+               public void refreshContent()
+               {
+                       Display.getDefault().asyncExec(combo::refresh);
+               }
+       }
+
+       public static class MachineCombo extends AdvancedCombo<MachineDefinition>
+       {
+               private static final Set<MachineCombo> machineComboListeners = Collections.synchronizedSet(new HashSet<>());
+
+               static
+               {
+                       MachineRegistry.addMachineRegistryListener(newMap -> machineComboListeners.forEach(AdvancedCombo::refreshContent));
+               }
+
+               public MachineCombo(Composite parent)
+               {
+                       this(parent, SWT.NONE);
+               }
+
+               public MachineCombo(Composite parent, int style)
+               {
+                       super(parent, style, MachineDefinition::getId);
+                       combo.setContentProvider(new IStructuredContentProvider()
+                       {
+                               @Override
+                               public void dispose()
+                               {
+                                       machineComboListeners.remove(MachineCombo.this);
+                               }
+
+                               @Override
+                               public Object[] getElements(Object inputElement)
+                               {
+                                       return INSTALLED_MACHINES.values().toArray();
+                               }
+                       });
+                       combo.setInput(this);
+                       machineComboListeners.add(this);
+               }
+       }
+
+       public static class MograsimProjectCombo extends AdvancedCombo<IProject>
+       {
+               private static final Set<MograsimProjectCombo> projectComboListeners = Collections.synchronizedSet(new HashSet<>());
+
+               static
+               {
+                       ProjectMachineContext.addProjectContextListener(projectEvent ->
+                       {
+                               if (projectEvent.getEventType() != ProjectContextEventType.OTHER_CHANGE)
+                                       projectComboListeners.forEach(AdvancedCombo::refreshContent);
+                       });
+               }
+
+               public MograsimProjectCombo(Composite parent)
+               {
+                       this(parent, SWT.NONE);
+               }
+
+               public MograsimProjectCombo(Composite parent, int style)
+               {
+                       super(parent, style, IProject::getName);
+                       combo.setContentProvider(new IStructuredContentProvider()
+                       {
+                               @Override
+                               public void dispose()
+                               {
+                                       projectComboListeners.remove(MograsimProjectCombo.this);
+                               }
+
+                               @Override
+                               public Object[] getElements(Object inputElement)
+                               {
+                                       return PROJECT_MACHINE_CONTEXTS.values().stream().filter(mc -> mc.getProject().isOpen() && mc.isCurrentyValid())
+                                                       .map(MachineContext::getProject).toArray();
+                               }
+                       });
+                       combo.setInput(this);
+                       projectComboListeners.add(this);
+               }
+       }
+
+       /**
+        * XXX: of no use?
+        */
+       static Optional<String> getSelection(Combo c)
+       {
+               int selectionIndex = c.getSelectionIndex();
+               if (selectionIndex == -1)
+                       return Optional.empty();
+               return Optional.of(c.getItem(selectionIndex));
+       }
+}
diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/ProjectContextEvent.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/ProjectContextEvent.java
new file mode 100644 (file)
index 0000000..059b3ea
--- /dev/null
@@ -0,0 +1,53 @@
+package net.mograsim.plugin.nature;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResourceChangeEvent;
+
+public class ProjectContextEvent
+{
+       private final MachineContext machineContext;
+       private final ProjectContextEventType eventType;
+
+       public ProjectContextEvent(MachineContext machineContext, ProjectContextEventType eventType)
+       {
+               this.machineContext = machineContext;
+               this.eventType = eventType;
+       }
+
+       public final MachineContext getMachineContext()
+       {
+               return machineContext;
+       }
+
+       public final ProjectContextEventType getEventType()
+       {
+               return eventType;
+       }
+
+       public final IProject getProject()
+       {
+               return machineContext.getProject();
+       }
+
+       public enum ProjectContextEventType
+       {
+               NEW, MACHINE_DEFINITION_CHANGE, OTHER_CHANGE, REFRESH, CLOSE, DELETE;
+
+               static ProjectContextEventType ofResourceChangeEvent(int id)
+               {
+                       switch (id)
+                       {
+                       case IResourceChangeEvent.POST_CHANGE:
+                               return OTHER_CHANGE;
+                       case IResourceChangeEvent.PRE_CLOSE:
+                               return CLOSE;
+                       case IResourceChangeEvent.PRE_DELETE:
+                               return DELETE;
+                       case IResourceChangeEvent.PRE_REFRESH:
+                               return REFRESH;
+                       default:
+                               return null;
+                       }
+               }
+       }
+}
\ No newline at end of file
diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/ProjectContextListener.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/ProjectContextListener.java
new file mode 100644 (file)
index 0000000..f7366bc
--- /dev/null
@@ -0,0 +1,7 @@
+package net.mograsim.plugin.nature;
+
+@FunctionalInterface
+public interface ProjectContextListener
+{
+       void onProjectContextChange(ProjectContextEvent projectContextEvent);
+}
\ No newline at end of file
index 0e6185c..86b9df6 100644 (file)
@@ -2,20 +2,27 @@ package net.mograsim.plugin.nature;
 
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Optional;
+import java.util.Set;
 
 import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResourceChangeEvent;
 import org.eclipse.core.resources.ProjectScope;
+import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.Adapters;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.ui.preferences.ScopedPreferenceStore;
 
+import net.mograsim.plugin.nature.ProjectContextEvent.ProjectContextEventType;
+
 public class ProjectMachineContext
 {
        private static Map<IProject, MachineContext> projectMachineContexts = Collections.synchronizedMap(new HashMap<>());
+       private static final Set<ProjectContextListener> listeners = Collections.synchronizedSet(new HashSet<>());
 
        public static final String MOGRASIM_PROJECT_PREFS_NODE = "net.mograsim";
        public static final String MACHINE_PROPERTY = "net.mograsim.projectMachineId";
@@ -28,6 +35,7 @@ public class ProjectMachineContext
                validateMograsimNatureProject(project);
                mc = new MachineContext(project);
                projectMachineContexts.put(project, mc);
+               notifyListeners(new ProjectContextEvent(mc, ProjectContextEventType.NEW));
                return mc;
        }
 
@@ -38,6 +46,11 @@ public class ProjectMachineContext
                return getMachineContextOf(project);
        }
 
+       public static Map<IProject, MachineContext> getAllProjectMachineContexts()
+       {
+               return Collections.unmodifiableMap(projectMachineContexts);
+       }
+
        static ScopedPreferenceStore getProjectPrefs(IProject mograsimProject)
        {
                return new ScopedPreferenceStore(new ProjectScope(mograsimProject), MOGRASIM_PROJECT_PREFS_NODE);
@@ -88,4 +101,39 @@ public class ProjectMachineContext
                        return Optional.of(preferenceStore.getString(MACHINE_PROPERTY));
                return Optional.empty();
        }
+
+       static void notifyListeners(ProjectContextEvent projectContextEvent)
+       {
+               listeners.forEach(l -> l.onProjectContextChange(projectContextEvent));
+       }
+
+       public static void addProjectContextListener(ProjectContextListener listener)
+       {
+               listeners.add(listener);
+       }
+
+       public static void removeProjectContextListener(ProjectContextListener listener)
+       {
+               listeners.remove(listener);
+       }
+
+       static
+       {
+               ResourcesPlugin.getWorkspace().addResourceChangeListener(ProjectMachineContext::resourceChanged);
+       }
+
+       private static void resourceChanged(IResourceChangeEvent event)
+       {
+//             System.out.println(((ResourceChangeEvent) event).toDebugString());
+               ProjectContextEventType eventType = ProjectContextEventType.ofResourceChangeEvent(event.getType());
+               if (eventType == null)
+                       return;
+               if (event.getResource() == null || event.getResource().getProject() == null)
+                       return;
+               MachineContext mc = projectMachineContexts.get(event.getResource().getProject());
+               if (mc == null)
+                       return;
+//             System.out.println("  " + eventType + " - " + mc.getProject());
+               notifyListeners(new ProjectContextEvent(mc, eventType));
+       }
 }
index fa7a918..8cdaae2 100644 (file)
@@ -1,19 +1,21 @@
 package net.mograsim.plugin.tables.mi;
 
 import org.eclipse.jface.viewers.CellEditor;
-import org.eclipse.jface.viewers.CheckboxCellEditor;
+import org.eclipse.jface.viewers.ComboBoxCellEditor;
 import org.eclipse.jface.viewers.EditingSupport;
 import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.swt.SWT;
 
 import net.mograsim.logic.core.types.Bit;
 import net.mograsim.machine.mi.MicroInstruction;
 import net.mograsim.machine.mi.MicroInstructionDefinition;
 import net.mograsim.machine.mi.parameters.BooleanClassification;
 import net.mograsim.machine.mi.parameters.MicroInstructionParameter;
+import net.mograsim.machine.mi.parameters.Mnemonic;
 
 public class BooleanEditingSupport extends EditingSupport
 {
-       private final CheckboxCellEditor editor;
+       private final ComboBoxCellEditor editor;
        private final BooleanClassification boolClass;
        private final TableViewer viewer;
        private final int index;
@@ -23,7 +25,10 @@ public class BooleanEditingSupport extends EditingSupport
                super(viewer);
                this.viewer = viewer;
                this.boolClass = (BooleanClassification) definition.getParameterClassification(index);
-               editor = new CheckboxCellEditor(viewer.getTable());
+               editor = new ComboBoxCellEditor(viewer.getTable(), boolClass.getStringValues(), SWT.READ_ONLY);
+               editor.setActivationStyle(
+                               ComboBoxCellEditor.DROP_DOWN_ON_TRAVERSE_ACTIVATION | ComboBoxCellEditor.DROP_DOWN_ON_PROGRAMMATIC_ACTIVATION
+                                               | ComboBoxCellEditor.DROP_DOWN_ON_MOUSE_ACTIVATION | ComboBoxCellEditor.DROP_DOWN_ON_KEY_ACTIVATION);
                this.index = index;
        }
 
@@ -43,7 +48,8 @@ public class BooleanEditingSupport extends EditingSupport
        protected Object getValue(Object element)
        {
                InstructionTableRow row = (InstructionTableRow) element;
-               return row.data.getCell(row.address).getParameter(index).getValue().getMSBit(0).equals(Bit.ONE);
+               // true is 0 because the true value comes first in the combo box
+               return row.data.getCell(row.address).getParameter(index).getValue().getMSBit(0).equals(Bit.ONE) ? 0 : 1;
        }
 
        @Override
@@ -51,7 +57,11 @@ public class BooleanEditingSupport extends EditingSupport
        {
                InstructionTableRow row = (InstructionTableRow) element;
                MicroInstructionParameter[] params = row.data.getCell(row.address).getParameters();
-               params[index] = boolClass.get((Boolean) value);
+               // true is 0 because the true value comes first in the combo box
+               Mnemonic newParam = boolClass.get(value.equals(0) ? true : false);
+               if (newParam.equals(params[index]))
+                       return;
+               params[index] = newParam;
                row.data.setCell(row.address, MicroInstruction.create(params));
                viewer.update(element, null);
        }
index 936ba5c..2a3ad6c 100644 (file)
@@ -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);
@@ -137,7 +160,6 @@ 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;
index 7cef835..4966b13 100644 (file)
@@ -9,4 +9,4 @@ public class InstructionTableRow extends TableRow<MicroInstructionMemory>
        {
                super(address, data);
        }
-}
+}
\ No newline at end of file
index 4f5b616..a821a76 100644 (file)
@@ -32,7 +32,10 @@ public class IntegerEditingSupport extends NumberCellEditingSupport
        {
                InstructionTableRow row = ((InstructionTableRow) element);
                MicroInstructionParameter[] params = row.data.getCell(row.address).getParameters();
-               params[index] = new IntegerImmediate(value, classification.getExpectedBits());
+               IntegerImmediate newParam = new IntegerImmediate(value, classification.getExpectedBits());
+               if (params[index].equals(newParam))
+                       return;
+               params[index] = newParam;
                row.data.setCell(row.address, MicroInstruction.create(params));
                provider.update(row.address);
 //             viewer.update(element, null); Does not do anything for some reason
diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/MnemonicCellEditorValidator.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/MnemonicCellEditorValidator.java
deleted file mode 100644 (file)
index 98181c4..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-package net.mograsim.plugin.tables.mi;
-
-import org.eclipse.jface.viewers.ICellEditorValidator;
-
-import net.mograsim.machine.mi.parameters.MnemonicFamily;
-
-public class MnemonicCellEditorValidator implements ICellEditorValidator
-{
-       private MnemonicFamily family;
-
-       public MnemonicCellEditorValidator(MnemonicFamily family)
-       {
-               this.family = family;
-       }
-
-       @Override
-       public String isValid(Object value)
-       {
-               int index = (Integer) value;
-               return index >= 0 && index < family.size() ? null
-                               : String.format("MnemonicFamily has %s elements, index %s is out of bounds", family.size(), value.toString());
-       }
-
-}
index 1140e68..7248f4f 100644 (file)
@@ -25,8 +25,10 @@ public class MnemonicEditingSupport extends EditingSupport
                super(viewer);
                family = (MnemonicFamily) definition.getParameterClassifications()[index];
                editor = new ComboBoxCellEditor(viewer.getTable(), family.getStringValues(), SWT.READ_ONLY);
+               editor.setActivationStyle(
+                               ComboBoxCellEditor.DROP_DOWN_ON_TRAVERSE_ACTIVATION | ComboBoxCellEditor.DROP_DOWN_ON_PROGRAMMATIC_ACTIVATION
+                                               | ComboBoxCellEditor.DROP_DOWN_ON_MOUSE_ACTIVATION | ComboBoxCellEditor.DROP_DOWN_ON_KEY_ACTIVATION);
                this.index = index;
-               editor.setValidator(new MnemonicCellEditorValidator(family));
                this.provider = provider;
        }
 
@@ -54,7 +56,10 @@ public class MnemonicEditingSupport extends EditingSupport
        {
                InstructionTableRow row = ((InstructionTableRow) element);
                MicroInstructionParameter[] params = row.data.getCell(row.address).getParameters();
-               params[index] = family.get((Integer) value);
+               Mnemonic newParam = family.get((Integer) value);
+               if (newParam.equals(params[index]))
+                       return;
+               params[index] = newParam;
                row.data.setCell(row.address, MicroInstruction.create(params));
                provider.update(row.address);
        }
index b1d0756..736aab3 100644 (file)
@@ -26,6 +26,9 @@ import net.mograsim.machine.mi.AssignableMicroInstructionMemory;
 import net.mograsim.plugin.EclipsePreferences;
 import net.mograsim.plugin.MachineContext;
 import net.mograsim.plugin.MograsimActivator;
+import net.mograsim.plugin.nature.MachineContextSwtTools;
+import net.mograsim.plugin.nature.MachineContextSwtTools.MachineCombo;
+import net.mograsim.plugin.nature.MachineContextSwtTools.MograsimProjectCombo;
 import net.mograsim.plugin.tables.DisplaySettings;
 import net.mograsim.plugin.tables.mi.ActiveInstructionPreviewContentProvider;
 import net.mograsim.plugin.tables.mi.InstructionTable;
@@ -45,6 +48,7 @@ public class LogicUIPart extends ViewPart
        {
                if (exec != null)
                        exec.stopLiveExecution();
+               super.dispose();
        }
 
        @Override
@@ -93,7 +97,11 @@ public class LogicUIPart extends ViewPart
        private void addSimulationControlWidgets(Composite parent)
        {
                Composite c = new Composite(parent, SWT.NONE);
-               c.setLayout(new GridLayout(5, false));
+               c.setLayout(new GridLayout(7, false));
+
+               MograsimProjectCombo projectCombo = MachineContextSwtTools.createMograsimProjectSelector(c, SWT.NONE);
+               MachineCombo machineCombo = MachineContextSwtTools.createMachineSelector(c, SWT.NONE);
+
                Button sbseButton = new Button(c, SWT.CHECK);
                Button pauseButton = new Button(c, SWT.TOGGLE);
 
index b261003..f3d0b69 100644 (file)
@@ -23,6 +23,8 @@ public class DefaultPreferences extends Preferences
        {
                switch (name)
                {
+               case "net.mograsim.logic.model.debug.hlsshelldepth":
+                       return -1;
                default:
                        throw new IllegalArgumentException("Unknown int preference name: " + name);
                }