Set<Node> streamResult = new HashSet<Node>();
Set<Node> sourceNodesSet = new HashSet<Node>();
//Common Stream Query
LocalCommonStreamQuery stream;
//if action is called from PopupMenu
if (useSelection)
{
//open dialog
CommonStreamQueryParamDialog dialog =
new CommonStreamQueryParamDialog(this.main);
options = dialog.open(options);
//Return if Cancel was pressed
if ( !options.isCancel() )
{
options.setCancel(true);
}
else
{
return;
}
//Get Selected Nodes in graph
sourceNodesSet = getSelectedNodes();
//Common Stream Query
stream = new LocalCommonStreamQuery(sourceNodesSet,
options.isDownstream(),
options.getLengthLimit());
}
//if action is called from TopMenuBar
else
{
//open dialog
CommonStreamQueryParamWithEntitiesDialog dialog =
new CommonStreamQueryParamWithEntitiesDialog(main);
options = dialog.open(options);
if ( !options.isCancel() )
{
options.setCancel(true);
}
else
{
return;
}
//Get added entities from dialog
ArrayList<physicalEntity> addedEntities = dialog.getAddedEntities();
//States of each entity
Set<Set<Node>> sourceStatesSet = new LinkedHashSet<Set<Node>>();
Iterator<physicalEntity> addedEntitiesIterator =
addedEntities.iterator();
//for each entity
while(addedEntitiesIterator.hasNext())
{
//Get next entity
physicalEntity entity = addedEntitiesIterator.next();
//States of entity in Node type
Set<Node> entityNodeStates = new HashSet<Node>();
//States of entity in GraphObject type
Set<GraphObject> entityStates =
main.getRootGraph().getRelatedStates(entity);
//Replace complex members with complexes
main.getRootGraph().replaceComplexMembersWithComplexes(entityStates);
//Convert GraphObjects to Nodes
for (GraphObject go : entityStates)
{
if (go instanceof Node)
{
entityNodeStates.add((Node) go);
}
}
//Add states of entity to collection of states
sourceStatesSet.add(entityNodeStates);
sourceNodesSet.addAll(entityNodeStates);
}
//Common Stream Query
stream = new LocalCommonStreamQuery(sourceStatesSet,
options.isDownstream(),
options.getLengthLimit());
}
//Run Common Stream Query and get result
streamResult = stream.run();
/**
* To add the missing paths between the source set and the result set
* to the query result, PoI must be performed.
*/