package forms.queryAspect
{
import core.AbstractModel;
import core.IModel;
import flash.events.Event;
import mx.collections.XMLListCollection;
import mx.events.CollectionEvent;
public class QueryColumnModel extends AbstractModel
{
namespace wfs = "http://www.opengis.net/wfs";
namespace xsd = "http://www.w3.org/2001/XMLSchema";
use namespace wfs;
use namespace xsd;
private var queryAspect:QueryAspectModel;
private var _properties:XMLListCollection;
private var _operators:XML =
PROPERTYISEQUALTO
PROPERTYISLESSTHAN
PROPERTYISGREATERTHAN
PROPERTYISLESSTHANOREQUALTO
PROPERTYISGREATERTHANOREQUALTO
PROPERTYISLIKE
PROPERTYISNULL
PROPERTYISBETWEEN
PROPERTYISIN
;
private function queryAspectChange(event:Event) : void {
dispatchEvent(new Event("nodeChange"));
}
public override function set parentModel(model:IModel) : void
{
if(queryAspect) {
queryAspect.removeEventListener("queryTypePropertyChange", queryAspectChange);
}
queryAspect = model as QueryAspectModel;
if(queryAspect) {
queryAspect.addEventListener("queryTypePropertyChange", queryAspectChange);
}
dispatchEvent(new Event("nodeChange"));
}
private function getFeatureTypeName(type:XML) : String {
var name:XMLList = type.child("Name");
if(name.length() == 0) {
name = type.child(new QName("http://www.opengis.net/wfs", "Name"));
}
var currentName:String;
if(name.length() == 0) {
currentName = type.toString();
} else {
currentName = name[0].toString();
}
return currentName;
}
private function getPrefix() : String {
var prefix:String = "";
var ftName:String = getFeatureTypeName(valueFeatureType);
if(ftName.indexOf(":") != -1) {
prefix = ftName.split(":")[0] + ":";
}
return prefix;
}
public function get valueFeatureType() : XML {
for each(var type:XML in validFeatureTypes) {
var currentName:String = getFeatureTypeName(type);
if(currentName == _node.OperandValueFT.toString()) {
return type;
}
}
return null;
}
[Bindable(event="nodeChange")]
public function set valueFeatureType(item:XML) : void {
_node.OperandValueFT = getFeatureTypeName(item);
getValidProperties();
dispatchEvent(new Event("nodeChange"));
}
[Bindable(event="nodeChange")]
public function get validFeatureTypes() : XMLList {
return queryAspect.validServerLayers;
}
public function get valueField() : XML {
var prefix:String = getPrefix();
for each(var property:XML in validProperties) {
if(prefix + property.@name == _node.OperandValueField) {
return property;
}
}
return null;
}
[Bindable(event="nodeChange")]
public function set valueField(newValueField:XML) : void {
_node.OperandValueField = getPrefix() + newValueField.@name;
dispatchEvent(new Event("nodeChange"));
}
public function get labelField() : XML {
var prefix:String = getPrefix();
for each(var property:XML in validProperties) {
if(prefix + property.@name == _node.OperandLabelField) {
return property;
}
}
return null;
}
[Bindable(event="nodeChange")]
public function set labelField(newLabelField:XML) : void {
_node.OperandLabelField = getPrefix() + newLabelField.@name;
dispatchEvent(new Event("nodeChange"));
}
protected override function refresh(event:Event = null) : void {
getValidProperties();
super.refresh(event);
}
private function getValidProperties() : void {
if(_dataSource && _node) {
var newProperties:XMLListCollection = _dataSource.serverInfo.getFeatureTypeAttributes(
queryAspect.server, valueFeatureType);
if(newProperties != _properties) {
if(_properties) {
_properties.removeEventListener(CollectionEvent.COLLECTION_CHANGE, refresh);
}
_properties = newProperties;
if(_properties) {
_properties.addEventListener(CollectionEvent.COLLECTION_CHANGE, refresh);
}
}
}
}
[Bindable(event="nodeChange")]
public function get validProperties() : XMLList {
return _properties.source.copy();
}
public function get searchType() : String {
return _node.SearchType;
}
[Bindable(event="nodeChange")]
public function set searchType(newSearchType:String) : void {
_node.SearchType = newSearchType;
dispatchEvent(new Event("nodeChange"));
}
public function get format() : String {
return _node.Format;
}
[Bindable(event="nodeChange")]
public function set format(newFormat:String) : void {
_node.Format = newFormat;
dispatchEvent(new Event("nodeChange"));
}
public function get validSearchTypes() : Array {
return ["ComboBox", "TextInput"];
}
[Bindable(event="nodeChange")]
public function get titles() : Array {
return getTitles(_node.Titles);
}
public function addToTitles(title:Object) : void {
doAddToTitles(title, _node.Titles);
dispatchEvent(new Event("nodeChange"));
}
[Bindable(event="nodeChange")]
public function get partOfAdvancedQuery() : Boolean {
if(queryAspect) {
return queryAspect.queryType == "advanced";
} else {
return false;
}
}
public function get validOperators() : XMLList {
return _operators.Operator;
}
[Bindable(event="nodeChange")]
public function get operators() : XMLList {
return _node.Operators.Operator.copy();
}
public function addToOperators(item:XML) : void {
if(_node.child("Operators").length() == 0) {
_node.appendChild();
}
_node.Operators[0].appendChild(item);
dispatchEvent(new Event("nodeChange"));
}
public function removeFromOperators(item:XML) : void {
_node.Operators[0].setChildren(_node.Operators.Operator.(valueOf() != item));
dispatchEvent(new Event("nodeChange"));
}
}
}