uidesigner/com.nokia.sdt.series60.componentlibrary/components/statuspane/StatusPane_queryContainment.js
author cawthron
Tue, 24 Mar 2009 22:20:21 -0500
changeset 2 d760517a8095
permissions -rw-r--r--
new
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
cawthron
parents:
diff changeset
     1
/*
cawthron
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
cawthron
parents:
diff changeset
     3
* All rights reserved.
cawthron
parents:
diff changeset
     4
* This component and the accompanying materials are made available
cawthron
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
cawthron
parents:
diff changeset
     6
* which accompanies this distribution, and is available
cawthron
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
cawthron
parents:
diff changeset
     8
*
cawthron
parents:
diff changeset
     9
* Initial Contributors:
cawthron
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
cawthron
parents:
diff changeset
    11
*
cawthron
parents:
diff changeset
    12
* Contributors:
cawthron
parents:
diff changeset
    13
*
cawthron
parents:
diff changeset
    14
* Description: 
cawthron
parents:
diff changeset
    15
*
cawthron
parents:
diff changeset
    16
*/
cawthron
parents:
diff changeset
    17
include("../containers/containerLibrary.js")
cawthron
parents:
diff changeset
    18
cawthron
parents:
diff changeset
    19
function StatusPaneQueryContainment() {
cawthron
parents:
diff changeset
    20
}
cawthron
parents:
diff changeset
    21
cawthron
parents:
diff changeset
    22
function isNaviTabsComponent(component) {
cawthron
parents:
diff changeset
    23
	var NAVI_TABS_ID = "com.nokia.sdt.series60.NaviTabs";
cawthron
parents:
diff changeset
    24
	return component.isOfType(NAVI_TABS_ID);
cawthron
parents:
diff changeset
    25
}
cawthron
parents:
diff changeset
    26
cawthron
parents:
diff changeset
    27
// can contain single instance of any allowed status pane content
cawthron
parents:
diff changeset
    28
function canContainComponent(component, children) {
cawthron
parents:
diff changeset
    29
cawthron
parents:
diff changeset
    30
	// early exit if not status content (we depend on other attributes)
cawthron
parents:
diff changeset
    31
	if (!hasStatusPaneContentAttribute(component.attributes)) {
cawthron
parents:
diff changeset
    32
		return buildSimpleContainmentErrorStatus(
cawthron
parents:
diff changeset
    33
			lookupString("spGeneralContainmentError"), 
cawthron
parents:
diff changeset
    34
			new Array( component.friendlyName ));
cawthron
parents:
diff changeset
    35
	}	
cawthron
parents:
diff changeset
    36
cawthron
parents:
diff changeset
    37
	// throw out if incorrect model type
cawthron
parents:
diff changeset
    38
	var disposition = component.attributes["model-type-disposition"];
cawthron
parents:
diff changeset
    39
	if (disposition == null)
cawthron
parents:
diff changeset
    40
		disposition = "any";
cawthron
parents:
diff changeset
    41
	if (disposition == "root" && !isInRootModel())
cawthron
parents:
diff changeset
    42
		return buildSimpleContainmentErrorStatus(
cawthron
parents:
diff changeset
    43
			lookupString("spStatusContentNotInRootContainmentError"), 
cawthron
parents:
diff changeset
    44
			[ component.friendlyName ]);			
cawthron
parents:
diff changeset
    45
	if (disposition == "view" && isInRootModel())
cawthron
parents:
diff changeset
    46
		return buildSimpleContainmentErrorStatus(
cawthron
parents:
diff changeset
    47
			lookupString("spStatusContentNotInViewContainmentError"), 
cawthron
parents:
diff changeset
    48
			[ component.friendlyName ]);			
cawthron
parents:
diff changeset
    49
	
cawthron
parents:
diff changeset
    50
	var hasInstance = false;
cawthron
parents:
diff changeset
    51
cawthron
parents:
diff changeset
    52
	var NAVI_BASE_ID = "com.nokia.sdt.series60.NaviBase";
cawthron
parents:
diff changeset
    53
	var isNaviContent = component.isOfType(NAVI_BASE_ID);
cawthron
parents:
diff changeset
    54
	var hasNaviContent = false;
cawthron
parents:
diff changeset
    55
	
cawthron
parents:
diff changeset
    56
//	println("cmp = " + component.id + ", attrs = " + component.attributes);	
cawthron
parents:
diff changeset
    57
	
cawthron
parents:
diff changeset
    58
	if (isNaviContent) {
cawthron
parents:
diff changeset
    59
		if (getStatusPaneContent(children, NAVI_BASE_ID) != null) {
cawthron
parents:
diff changeset
    60
			hasInstance = true;
cawthron
parents:
diff changeset
    61
			hasNaviContent = true;
cawthron
parents:
diff changeset
    62
		}
cawthron
parents:
diff changeset
    63
	} else {
cawthron
parents:
diff changeset
    64
		if (getStatusPaneContent(children, component.id) != null)
cawthron
parents:
diff changeset
    65
			hasInstance = true;
cawthron
parents:
diff changeset
    66
	}
cawthron
parents:
diff changeset
    67
cawthron
parents:
diff changeset
    68
	if (hasNaviContent)
cawthron
parents:
diff changeset
    69
		return buildSimpleContainmentErrorStatus(
cawthron
parents:
diff changeset
    70
			lookupString("spSingleNaviInstanceContainmentError"), 
cawthron
parents:
diff changeset
    71
			new Array( component.friendlyName ));			
cawthron
parents:
diff changeset
    72
	else if (hasInstance)
cawthron
parents:
diff changeset
    73
		return buildSimpleContainmentErrorStatus(
cawthron
parents:
diff changeset
    74
			lookupString("spSingleInstanceContainmentError"), 
cawthron
parents:
diff changeset
    75
			new Array( component.friendlyName ));			
cawthron
parents:
diff changeset
    76
cawthron
parents:
diff changeset
    77
	return null;
cawthron
parents:
diff changeset
    78
}
cawthron
parents:
diff changeset
    79
cawthron
parents:
diff changeset
    80
StatusPaneQueryContainment.prototype.canContainComponent = function(instance, otherComponent) {
cawthron
parents:
diff changeset
    81
	return canContainComponent(otherComponent, instance.children);
cawthron
parents:
diff changeset
    82
}
cawthron
parents:
diff changeset
    83
cawthron
parents:
diff changeset
    84
StatusPaneQueryContainment.prototype.canContainChild = function(instance, child) {
cawthron
parents:
diff changeset
    85
	return canContainComponent(child.component, instance.children);
cawthron
parents:
diff changeset
    86
}
cawthron
parents:
diff changeset
    87
cawthron
parents:
diff changeset
    88
StatusPaneQueryContainment.prototype.canRemoveChild = function(instance, child) {
cawthron
parents:
diff changeset
    89
	return true;
cawthron
parents:
diff changeset
    90
}
cawthron
parents:
diff changeset
    91
cawthron
parents:
diff changeset
    92
StatusPaneQueryContainment.prototype.isValidComponentInPalette = function(instance, otherComponent) {
cawthron
parents:
diff changeset
    93
cawthron
parents:
diff changeset
    94
	// throw out if incorrect model type
cawthron
parents:
diff changeset
    95
	var disposition = otherComponent.attributes["model-type-disposition"];
cawthron
parents:
diff changeset
    96
	if (disposition == null)
cawthron
parents:
diff changeset
    97
		disposition = "any";
cawthron
parents:
diff changeset
    98
	if (disposition == "root" && !isInRootModel())
cawthron
parents:
diff changeset
    99
		return false;
cawthron
parents:
diff changeset
   100
	if (disposition == "view" && isInRootModel())
cawthron
parents:
diff changeset
   101
		return false;
cawthron
parents:
diff changeset
   102
cawthron
parents:
diff changeset
   103
	var a = otherComponent.attributes;
cawthron
parents:
diff changeset
   104
	return hasStatusPaneContentAttribute(a);
cawthron
parents:
diff changeset
   105
}
cawthron
parents:
diff changeset
   106