X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2Fnature%2FProjectMachineContext.java;h=ecce9e818f68226e1340e0f0bddd7bf02b8d8ed7;hb=0eb525202d3c871a2a20f789af1728248f3cff11;hp=21122f072098d1771e26ef924b44261a92786633;hpb=a007be844bf57d526362c084abd68790692ce2a1;p=Mograsim.git diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/ProjectMachineContext.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/ProjectMachineContext.java index 21122f07..ecce9e81 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/ProjectMachineContext.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/ProjectMachineContext.java @@ -17,13 +17,15 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.ui.preferences.ScopedPreferenceStore; +import net.mograsim.machine.MachineRegistry; import net.mograsim.plugin.nature.ProjectContextEvent.ProjectContextEventType; /** * This class is a register for {@link MachineContext} mapped by their {@link IProject} *

* It can be used to obtain (and thereby create if necessary) {@link MachineContext}s for projects and {@link IAdaptable}s that are somewhat - * associated to Mograsim nature. The register is unique and static context of this class. + * associated to Mograsim nature. The register is unique and static context of this class. Since it also depends on the installed machines, + * it listens to changes of the {@link MachineRegistry}. * * @author Christian Femers * @@ -161,20 +163,29 @@ public class ProjectMachineContext static { ResourcesPlugin.getWorkspace().addResourceChangeListener(ProjectMachineContext::resourceChanged); + MachineRegistry.addMachineRegistryListener(newMap -> updateAllStatus()); + } + + private static void updateAllStatus() + { + projectMachineContexts.forEach((p, mc) -> mc.updateStatus()); } private static void resourceChanged(IResourceChangeEvent event) { -// System.out.println(((ResourceChangeEvent) event).toDebugString()); - ProjectContextEventType eventType = ProjectContextEventType.ofResourceChangeEvent(event.getType()); - if (eventType == null) + // We try to do as many cheap tests first as possible, because this listener is not limited to plain project actions. + if (event.getResource() == null) return; - if (event.getResource() == null || event.getResource().getProject() == null) + IProject project = event.getResource().getProject(); + if (project == null) return; - MachineContext mc = projectMachineContexts.get(event.getResource().getProject()); + MachineContext mc = projectMachineContexts.get(project); if (mc == null) return; -// System.out.println(" " + eventType + " - " + mc.getProject()); + ProjectContextEventType eventType = ProjectContextEventType.ofResourceChangeEvent(event.getType()); +// if (eventType == ProjectContextEventType.OTHER_CHANGE && project.isOpen()) +// return; // we don't care about all small changes (TODO: research if this has any drawbacks) + eventType.getForcedStatus().ifPresent(mc::forceUpdateStatus); notifyListeners(new ProjectContextEvent(mc, eventType)); } }