Preserve z-order of components when copy-pasting

This commit is contained in:
Branislav Stojkovic
2018-12-15 18:35:51 +01:00
parent 2ee81093a0
commit 3939d2c5a7
5 changed files with 21 additions and 2 deletions
@@ -22,10 +22,11 @@
package org.diylc.presenter;
import java.util.Comparator;
import org.diylc.common.ComponentType;
import org.diylc.common.PropertyWrapper;
import org.diylc.core.IDIYComponent;
import org.diylc.core.Project;
public class ComparatorFactory {
@@ -127,5 +128,17 @@ public class ComparatorFactory {
};
}
return componentZOrderComparator;
}
public Comparator<IDIYComponent<?>> getComponentProjectZOrderComparator(final Project project) {
return new Comparator<IDIYComponent<?>>() {
@Override
public int compare(IDIYComponent<?> o1, IDIYComponent<?> o2) {
int index1 = project.getComponents().indexOf(o1);
int index2 = project.getComponents().indexOf(o2);
return new Integer(index1).compareTo(index2);
}
};
}
}
@@ -831,7 +831,9 @@ public class Presenter implements IPlugInPort {
@Override
public Collection<IDIYComponent<?>> getSelectedComponents() {
return selectedComponents;
List<IDIYComponent<?>> selection = new ArrayList<IDIYComponent<?>>(selectedComponents);
Collections.sort(selection, ComparatorFactory.getInstance().getComponentProjectZOrderComparator(currentProject));
return selection;
}
@SuppressWarnings("unchecked")