Fix multi-select for stages

This commit is contained in:
SiboVG 2022-06-27 22:55:11 +02:00
parent 7ee5a17af9
commit d82058417a

View File

@ -19,6 +19,7 @@ import java.net.URL;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@ -300,17 +301,23 @@ public class BasicFrame extends JFrame {
componentSelectionModel.addTreeSelectionListener(new TreeSelectionListener() { componentSelectionModel.addTreeSelectionListener(new TreeSelectionListener() {
@Override @Override
public void valueChanged(TreeSelectionEvent e) { public void valueChanged(TreeSelectionEvent e) {
TreePath selPath = e.getNewLeadSelectionPath(); if (tree == null || tree.getSelectionPaths() == null || tree.getSelectionPaths().length == 0
if (selPath == null) return; || rocketpanel == null) return;
RocketComponent c = (RocketComponent) selPath.getLastPathComponent();
// Get all the components that need to be selected = currently selected components + children of stages/boosters/podsets
List<RocketComponent> children = new ArrayList<>(Arrays.asList(rocketpanel.getFigure().getSelection()));
for (TreePath p : tree.getSelectionPaths()) {
if (p != null) {
RocketComponent c = (RocketComponent) p.getLastPathComponent();
if (c instanceof AxialStage || c instanceof Rocket || c instanceof PodSet) { if (c instanceof AxialStage || c instanceof Rocket || c instanceof PodSet) {
if (rocketpanel == null) return; Iterator<RocketComponent> iter = c.iterator(false);
while (iter.hasNext()) {
List<RocketComponent> children = new LinkedList<>(); RocketComponent child = iter.next();
for (RocketComponent child : c) {
children.add(child); children.add(child);
} }
}
}
}
// Select all the child components // Select all the child components
if (rocketpanel.getFigure() != null && rocketpanel.getFigure3d() != null) { if (rocketpanel.getFigure() != null && rocketpanel.getFigure3d() != null) {
@ -318,7 +325,6 @@ public class BasicFrame extends JFrame {
rocketpanel.getFigure3d().setSelection(children.toArray(new RocketComponent[0])); rocketpanel.getFigure3d().setSelection(children.toArray(new RocketComponent[0]));
} }
} }
}
}); });
// Double-click opens config dialog // Double-click opens config dialog