[cooja] plugins/Visualizer: Fixed node selection in Delete menu handling

Previously if multiple motes were selected
and the context menu of a non-selected mote
was used to delete, not the clicked mote
but the other selected ones were removed.

This behavior is fixed so that if another
mote is clicked only this is deleted.
This commit is contained in:
Enrico Joerns 2014-06-06 11:31:36 +02:00
parent 6594684342
commit 3ada5671ef

View file

@ -1584,23 +1584,27 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
@Override @Override
public String getDescription(Visualizer visualizer, Mote mote) { public String getDescription(Visualizer visualizer, Mote mote) {
if (visualizer.getSelectedMotes().size() == 1) { if (visualizer.getSelectedMotes().contains(mote) && visualizer.getSelectedMotes().size() > 1) {
return "Delete " + mote;
} else {
return "Delete selected Motes"; return "Delete selected Motes";
} else {
return "Delete " + mote;
} }
} }
@Override @Override
public void doAction(Visualizer visualizer, Mote mote) { public void doAction(Visualizer visualizer, Mote mote) {
if (visualizer.getSelectedMotes().size() == 1) {
mote.getSimulation().removeMote(mote); /* If the currently clicked mote is note in the current mote selection,
} else { * select it exclusively */
if (!visualizer.getSelectedMotes().contains(mote)) {
visualizer.getSelectedMotes().clear();
visualizer.getSelectedMotes().add(mote);
}
for (Mote m : visualizer.getSelectedMotes()) { for (Mote m : visualizer.getSelectedMotes()) {
mote.getSimulation().removeMote(m); mote.getSimulation().removeMote(m);
} }
} }
}
}; };
protected static class ShowLEDMoteMenuAction implements MoteMenuAction { protected static class ShowLEDMoteMenuAction implements MoteMenuAction {