use of org.cytoscape.filter.internal.filters.model.AdvancedSetting in project cytoscape-impl by cytoscape.
the class FilterReader method getAdvancedSettingFromStr.
private AdvancedSetting getAdvancedSettingFromStr(List<String> pAdvSettingStrVect) {
AdvancedSetting advSetting = new AdvancedSetting();
String line = null;
for (int i = 0; i < pAdvSettingStrVect.size(); i++) {
line = pAdvSettingStrVect.get(i);
if (line.startsWith("scope.global=true"))
advSetting.setGlobal(true);
if (line.startsWith("scope.global=false"))
advSetting.setGlobal(false);
if (line.startsWith("scope.session=true"))
advSetting.setSession(true);
if (line.startsWith("scope.session=false"))
advSetting.setSession(false);
if (line.startsWith("selection.node=true"))
advSetting.setNode(true);
if (line.startsWith("selection.node=false"))
advSetting.setNode(false);
if (line.startsWith("selection.edge=true"))
advSetting.setEdge(true);
if (line.startsWith("selection.edge=false"))
advSetting.setEdge(false);
if (line.startsWith("edge.source=true"))
advSetting.setSource(true);
if (line.startsWith("edge.source=false"))
advSetting.setSource(false);
if (line.startsWith("edge.target=true"))
advSetting.setTarget(true);
if (line.startsWith("edge.target=false"))
advSetting.setTarget(false);
if (line.startsWith("Relation=AND"))
advSetting.setRelation(Relation.AND);
if (line.startsWith("Relation=OR"))
advSetting.setRelation(Relation.OR);
}
return advSetting;
}
use of org.cytoscape.filter.internal.filters.model.AdvancedSetting in project cytoscape-impl by cytoscape.
the class FilterReader method getFilterFromStrList.
private CompositeFilter getFilterFromStrList(List<String> strList, Collection<CompositeFilter> filters) {
boolean isTopologyFilter = false;
boolean isInteractionFilter = false;
if (strList.get(0).startsWith("<TopologyFilter>")) {
isTopologyFilter = true;
}
if (strList.get(0).startsWith("<InteractionFilter>")) {
isInteractionFilter = true;
}
List<String> advSettingStrVect = new ArrayList<String>();
List<String> filterStrVect = new ArrayList<String>();
// Seperate AdvancedSetting from the rest
int startIndex = -1, endIndex = -1;
String line = null;
for (int i = 0; i < strList.size(); i++) {
line = strList.get(i);
if (line.startsWith("<AdvancedSetting>")) {
startIndex = i;
}
if (line.startsWith("</AdvancedSetting>")) {
endIndex = i;
break;
}
}
advSettingStrVect.addAll(strList.subList(startIndex + 1, endIndex));
filterStrVect.addAll(strList.subList(1, startIndex));
filterStrVect.addAll(strList.subList(endIndex + 1, strList.size()));
CompositeFilter retFilter = new CompositeFilter(ServicesUtil.cyApplicationManagerServiceRef);
retFilter.setAdvancedSetting(getAdvancedSettingFromStr(advSettingStrVect));
if (isTopologyFilter) {
retFilter = new TopologyFilter(ServicesUtil.cyApplicationManagerServiceRef);
retFilter.setAdvancedSetting(getAdvancedSettingFromStr(advSettingStrVect));
getTopologyFilterFromStr((TopologyFilter) retFilter, filterStrVect, filters);
return retFilter;
}
if (isInteractionFilter) {
AdvancedSetting advSetting = getAdvancedSettingFromStr(advSettingStrVect);
if (advSetting.isNodeChecked()) {
retFilter = new NodeInteractionFilter(ServicesUtil.cyApplicationManagerServiceRef);
} else {
// advSetting.isEdgeChecked() == true
retFilter = new EdgeInteractionFilter(ServicesUtil.cyApplicationManagerServiceRef);
}
retFilter.setAdvancedSetting(advSetting);
getInteractionFilterFromStr((InteractionFilter) retFilter, filterStrVect, filters);
return retFilter;
}
Collection<CompositeFilter> allFilters = new LinkedHashSet<CompositeFilter>();
for (int i = 0; i < filterStrVect.size(); i++) {
line = filterStrVect.get(i);
if (line.startsWith("name=")) {
String name = line.substring(5);
retFilter.setName(name);
}
if (line.startsWith("Negation=true")) {
retFilter.setNegation(true);
}
if (line.startsWith("Negation=false")) {
retFilter.setNegation(false);
}
if (line.startsWith("StringFilter=")) {
String _stringFilterValue = line.substring(13);
String[] _values = _stringFilterValue.split(":");
// controllingAttribute+":" + negation+ ":"+searchStr+":"+index_type;
StringFilter _strFilter = new StringFilter(quickFind);
_strFilter.setParent(retFilter);
_strFilter.setControllingAttribute(_values[0]);
_strFilter.setNegation((new Boolean(_values[1])).booleanValue());
// handle the case where ':' is part of the search string
String _searchStr = _stringFilterValue.substring(_values[0].length() + _values[1].length() + 2, _stringFilterValue.length() - _values[_values.length - 1].length() - 1);
_strFilter.setSearchStr(_searchStr);
_strFilter.setIndexType((new Integer(_values[_values.length - 1])).intValue());
retFilter.addChild(_strFilter);
}
if (line.startsWith("NumericFilter=")) {
String[] _values = line.substring(14).split(":");
// controllingAttribute + ":" + negation+ ":"+lowBound+":" +
// highBound+ ":"+index_type;
// Determine data type of the attribute
String dataType = "int";
if (_values[2].indexOf(".") >= 0 || _values[2].indexOf("E") >= 0 || _values[3].indexOf(".") >= 0 || _values[3].indexOf("E") >= 0) {
dataType = "double";
}
if (dataType.equalsIgnoreCase("double")) {
NumericFilter<Double> _numFilter = new NumericFilter<Double>(quickFind);
_numFilter.setParent(retFilter);
_numFilter.setControllingAttribute(_values[0]);
_numFilter.setNegation((new Boolean(_values[1])).booleanValue());
_numFilter.setLowBound(Double.valueOf(_values[2]));
_numFilter.setHighBound(Double.valueOf(_values[3]));
_numFilter.setIndexType((new Integer(_values[4])).intValue());
retFilter.addChild(_numFilter);
} else {
// dataType = "int"
NumericFilter<Integer> _numFilter = new NumericFilter<Integer>(quickFind);
_numFilter.setParent(retFilter);
_numFilter.setControllingAttribute(_values[0]);
_numFilter.setNegation((new Boolean(_values[1])).booleanValue());
_numFilter.setLowBound(Integer.valueOf(_values[2]));
_numFilter.setHighBound(Integer.valueOf(_values[3]));
_numFilter.setIndexType((new Integer(_values[4])).intValue());
retFilter.addChild(_numFilter);
}
}
if (line.startsWith("CompositeFilter=")) {
// e.g. CompositeFilter=AAA:true
String[] _values = line.substring(16).split(":");
String name = _values[0].trim();
String notValue = _values[1].trim();
// get the reference CompositeFilter
CompositeFilter cmpFilter = null;
for (CompositeFilter cf : allFilters) {
if (cf.getName().equalsIgnoreCase(name)) {
cmpFilter = cf;
break;
}
}
if (cmpFilter != null) {
retFilter.addChild(cmpFilter, (new Boolean(notValue)).booleanValue());
}
}
if (line.startsWith("TopologyFilter=")) {
// e.g. TopologyFilter=AAA:true
String[] _values = line.substring(15).split(":");
String name = _values[0].trim();
String notValue = _values[1].trim();
// get the reference TopologyFilter
TopologyFilter topoFilter = null;
for (CompositeFilter cf : allFilters) {
if (cf.getName().equalsIgnoreCase(name)) {
topoFilter = (TopologyFilter) cf;
break;
}
}
if (topoFilter != null) {
retFilter.addChild(topoFilter, (new Boolean(notValue)).booleanValue());
}
}
if (line.startsWith("InteractionFilter=")) {
// e.g. InteractionFilter=AAA:true
String[] _values = line.substring(15).split(":");
String name = _values[0].trim();
String notValue = _values[1].trim();
// get the reference InteractionFilter
InteractionFilter interactionFilter = null;
for (CompositeFilter cf : allFilters) {
if (cf.getName().equalsIgnoreCase(name)) {
interactionFilter = (InteractionFilter) cf;
break;
}
}
if (interactionFilter != null) {
retFilter.addChild(interactionFilter, (new Boolean(notValue)).booleanValue());
}
}
}
return retFilter;
}
use of org.cytoscape.filter.internal.filters.model.AdvancedSetting in project cytoscape-impl by cytoscape.
the class FilterWriter method getFiltersByScope.
private static CompositeFilter[] getFiltersByScope(Object[] pFilters, String pScope) {
if (pFilters == null || pFilters.length == 0) {
return null;
}
ArrayList<CompositeFilter> retFilterList = new ArrayList<CompositeFilter>();
for (int i = 0; i < pFilters.length; i++) {
CompositeFilter theFilter = (CompositeFilter) pFilters[i];
AdvancedSetting advSetting = theFilter.getAdvancedSetting();
if (pScope.equalsIgnoreCase("global")) {
if (advSetting.isGlobalChecked()) {
retFilterList.add(theFilter);
}
}
if (pScope.equalsIgnoreCase("session")) {
if (advSetting.isSessionChecked()) {
retFilterList.add(theFilter);
}
}
}
return retFilterList.toArray(new CompositeFilter[retFilterList.size()]);
}
Aggregations