X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2Fnature%2FMachineContext.java;h=f3965f2a3976874e22a8f25de0273937adcff4a3;hb=648fc6e69e09fe4467cb6bac47934be1a7dcf0d6;hp=55316813aa6ef7f86d6597cd738660c4e06ddc85;hpb=500771048185ce356aed280970f5ff0f4473a146;p=Mograsim.git diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/MachineContext.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/MachineContext.java index 55316813..f3965f2a 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/MachineContext.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/MachineContext.java @@ -1,6 +1,13 @@ package net.mograsim.plugin.nature; -import static net.mograsim.plugin.nature.MachineContextStatus.*; +import static net.mograsim.plugin.nature.MachineContextStatus.ACTIVE; +import static net.mograsim.plugin.nature.MachineContextStatus.ACTIVE_CHANGED; +import static net.mograsim.plugin.nature.MachineContextStatus.BROKEN; +import static net.mograsim.plugin.nature.MachineContextStatus.CLOSED; +import static net.mograsim.plugin.nature.MachineContextStatus.DEAD; +import static net.mograsim.plugin.nature.MachineContextStatus.INTACT; +import static net.mograsim.plugin.nature.MachineContextStatus.READY; +import static net.mograsim.plugin.nature.MachineContextStatus.UNKOWN; import java.io.IOException; import java.util.HashSet; @@ -33,10 +40,12 @@ public class MachineContext final ScopedPreferenceStore prefs; Optional machineId = Optional.empty(); Optional machineDefinition = Optional.empty(); + @Deprecated(forRemoval = true) Optional activeMachine = Optional.empty(); private MachineContextStatus status = UNKOWN; + @Deprecated(forRemoval = true) private final Set machineListeners = new HashSet<>(); private final Set stateListeners = new HashSet<>(); @@ -63,7 +72,7 @@ public class MachineContext */ public final boolean isCurrentyValid() { - return status == READY || status == ACTIVE; + return status == READY || isActive(); } /** @@ -79,6 +88,7 @@ public class MachineContext /** * Returns true if a machine is instantiated and (possibly) running */ + @Deprecated(forRemoval = true) public final boolean isActive() { return status == ACTIVE || status == ACTIVE_CHANGED; @@ -113,11 +123,13 @@ public class MachineContext /** * Sets the active machine in the {@link MachineContext}'s project scope. */ + @Deprecated(forRemoval = true) public final void setActiveMachine(Machine machine) { + Optional oldMachine = activeMachine; activeMachine = Optional.ofNullable(machine); updateStatus(); - notifyActiveMachineListeners(); + notifyActiveMachineListeners(oldMachine, activeMachine); } public final Optional getMachineId() @@ -130,6 +142,7 @@ public class MachineContext return machineDefinition; } + @Deprecated(forRemoval = true) public final Optional getActiveMachine() { // activateMachine(); // TODO is this the best way to deal with this? @@ -142,13 +155,12 @@ public class MachineContext * * @return true if the activation was successful */ + @Deprecated(forRemoval = true) public final boolean activateMachine() { if (status == ACTIVE) return true; machineDefinition.ifPresent(md -> setActiveMachine(md.createNew())); - if (activeMachine.isPresent()) - System.out.format("Created new machine %s for project %s%n", activeMachine.get().getDefinition().getId(), owner.getName()); updateStatus(); return isActive(); } @@ -172,7 +184,6 @@ public class MachineContext if (oldStatus == newStatus) return; status = newStatus; - System.out.format("Project %s context status: %s -> %s%n", owner.getName(), oldStatus, newStatus); doPostStatusChangedAction(); notifyMachineContextStatusListeners(oldStatus); } @@ -183,6 +194,7 @@ public class MachineContext * * @return the raw status of the project at the time of the call. */ + @SuppressWarnings("removal") public final MachineContextStatus reevaluateStatus() { if (!owner.exists()) @@ -200,13 +212,14 @@ public class MachineContext return ACTIVE; } + @Deprecated(forRemoval = true) private void doPostStatusChangedAction() { if ((status == DEAD || status == CLOSED) && activeMachine.isPresent()) { - System.out.format("Removed machine %s for project %s%n", activeMachine.get().getDefinition().getId(), owner.getName()); + Optional oldMachine = activeMachine; activeMachine = Optional.empty(); - notifyActiveMachineListeners(); + notifyActiveMachineListeners(oldMachine, activeMachine); } } @@ -232,6 +245,11 @@ public class MachineContext return; machineId = newMachineDefinitionId; machineDefinition = machineId.map(MachineRegistry::getMachine); + if (machineDefinition.isEmpty() && newMachineDefinitionId.isPresent()) + { + // TODO open a dialog + System.err.println("Machine definition for ID " + newMachineDefinitionId.get() + " not found"); + } updateStatus(); ProjectMachineContext.notifyListeners(new ProjectContextEvent(this, ProjectContextEventType.MACHINE_DEFINITION_CHANGE)); } @@ -244,17 +262,20 @@ public class MachineContext } } - private void notifyActiveMachineListeners() + @Deprecated(forRemoval = true) + private void notifyActiveMachineListeners(Optional oldMachine, Optional newMachine) { - machineListeners.forEach(ob -> ob.setMachine(activeMachine)); + machineListeners.forEach(ob -> ob.setMachine(oldMachine, newMachine)); } + @Deprecated(forRemoval = true) public void addActiveMachineListener(ActiveMachineListener ob) { machineListeners.add(ob); - ob.setMachine(activeMachine); + ob.setMachine(Optional.empty(), activeMachine); } + @Deprecated(forRemoval = true) public void removeActiveMachineListener(ActiveMachineListener ob) { machineListeners.remove(ob); @@ -277,9 +298,10 @@ public class MachineContext } @FunctionalInterface + @Deprecated(forRemoval = true) public static interface ActiveMachineListener { - void setMachine(Optional machine); + void setMachine(Optional oldMachine, Optional newMachine); } @FunctionalInterface