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