package jetbrains.mps.execution.lib.ui;
/*Generated by MPS */
import org.jetbrains.annotations.NotNull;
import java.util.List;
import jetbrains.mps.execution.lib.NodesDescriptor;
import jetbrains.mps.internal.collections.runtime.ListSequence;
import java.util.ArrayList;
import org.jetbrains.mps.openapi.module.SearchScope;
import jetbrains.mps.internal.collections.runtime.Sequence;
import jetbrains.mps.internal.collections.runtime.ISelector;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import jetbrains.mps.project.GlobalScope;
import org.jetbrains.mps.openapi.model.SNode;
import org.jetbrains.mps.openapi.module.FindUsagesFacade;
import org.jetbrains.mps.openapi.util.ProgressMonitor;
import jetbrains.mps.internal.collections.runtime.ITranslator2;
import org.jetbrains.mps.openapi.language.SAbstractConcept;
import jetbrains.mps.baseLanguage.closures.runtime._FunctionTypes;
import java.util.Set;
import java.util.Collections;
import jetbrains.mps.internal.collections.runtime.SetSequence;
import jetbrains.mps.internal.collections.runtime.IWhereFilter;
public class NodeBySeveralConceptChooser extends NodeChooser {
@NotNull
private final List<NodesDescriptor> myTargetConcepts = ListSequence.fromList(new ArrayList<NodesDescriptor>());
private final SearchScope myScope;
public NodeBySeveralConceptChooser(NodesDescriptor... targets) {
this(Sequence.fromIterable(Sequence.fromArray(targets)).toListSequence());
}
public NodeBySeveralConceptChooser(List<NodesDescriptor> targets) {
ListSequence.fromList(myTargetConcepts).addSequence(ListSequence.fromList(targets).select(new ISelector<NodesDescriptor, NodesDescriptor>() {
public NodesDescriptor select(NodesDescriptor it) {
return new NodesDescriptor((it.concept() == null ? MetaAdapterFactory.getConcept(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x10802efe25aL, "jetbrains.mps.lang.core.structure.BaseConcept") : it.concept()), it.filter());
}
}));
myScope = GlobalScope.getInstance();
}
@Override
protected List<SNode> findToChooseFromOnInit(final FindUsagesFacade manager, final ProgressMonitor monitor) {
return (List<SNode>) (ListSequence.fromList(myTargetConcepts).translate(new ITranslator2<NodesDescriptor, SNode>() {
public Iterable<SNode> translate(NodesDescriptor it) {
SAbstractConcept targetConcept = it.concept();
final _FunctionTypes._return_P1_E0<? extends Boolean, ? super SNode> function = it.filter();
Set<SNode> instances = manager.findInstances(myScope, Collections.singleton(targetConcept), false, monitor.subTask(10));
if (function == null) {
return instances;
} else {
return SetSequence.fromSet(instances).where(new IWhereFilter<SNode>() {
public boolean accept(SNode it) {
return function.invoke(it);
}
});
}
}
}).toListSequence());
}
}