uidesigner/com.nokia.sdt.series60.componentlibrary/components/view/CAknView_queryContainment.js
changeset 0 fb279309251b
equal deleted inserted replaced
-1:000000000000 0:fb279309251b
       
     1 /*
       
     2 * Copyright (c) 2006 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 
       
    18 
       
    19 include("../containers/containerLibrary.js")
       
    20 include("../implLibrary.js")
       
    21 
       
    22 function CAknViewScript() {
       
    23 }
       
    24 
       
    25 // can contain single instance of navi content, control or status panes or top-level content
       
    26 function canContainComponent(component, children) {
       
    27 	var hasInstance = false;
       
    28 	var isAllowedType = false;
       
    29 	
       
    30 	if (isToolbar(component)) {
       
    31 		isAllowedType = true;
       
    32 		if (getToolbar(children) != null){
       
    33 			hasInstance = true;
       
    34 		}
       
    35 	}
       
    36 	
       
    37 	if (isControlPane(component)) {
       
    38 		isAllowedType = true;
       
    39 		if (getControlPane(children) != null)
       
    40 			hasInstance = true;
       
    41 	}
       
    42 	
       
    43 	if (isStatusPaneId(component.id)) {
       
    44 		isAllowedType = true;
       
    45 		if (getStatusPane(children) != null)
       
    46 			hasInstance = true;
       
    47 	}
       
    48 	
       
    49 	if (hasTopLevelContentContainerAttribute(component.attributes)) {
       
    50 		isAllowedType = true;
       
    51 		if (getContents(children) != null)
       
    52 			hasInstance = true;	
       
    53 	}
       
    54 		
       
    55 	if (hasInstance)
       
    56 		return buildSimpleContainmentErrorStatus(
       
    57 			lookupString("singleInstanceContainmentError"), 
       
    58 			new Array( component.friendlyName ));
       
    59 
       
    60 	if (!isAllowedType)
       
    61 		return buildSimpleContainmentErrorStatus(
       
    62 			lookupString("generalContainmentError"), 
       
    63 			new Array( component.friendlyName ));
       
    64 
       
    65 	return null;
       
    66 }
       
    67 
       
    68 CAknViewScript.prototype.canContainComponent = function(instance, otherComponent) {
       
    69 	return canContainComponent(otherComponent, instance.children);
       
    70 }
       
    71 
       
    72 CAknViewScript.prototype.canContainChild = function(instance, child) {
       
    73 	return canContainComponent(child.component, instance.children);
       
    74 }
       
    75 
       
    76 CAknViewScript.prototype.canRemoveChild = function(instance, child) {
       
    77 	return !hasTopLevelContentContainerAttribute(child.attributes);
       
    78 }
       
    79 
       
    80 CAknViewScript.prototype.isValidComponentInPalette = function(instance, otherComponent) {
       
    81 	return isControlPane(otherComponent) || 
       
    82 			isStatusPaneId(otherComponent.id) || 
       
    83 			hasTopLevelContentContainerAttribute(otherComponent.attributes);
       
    84 }
       
    85 
       
    86 	// note that laf will be null if a display model was not created
       
    87 CAknViewScript.prototype.validate = function(instance, laf) {
       
    88 	// S60 will panic if the CBA is configured for an options menu but
       
    89 	// the Avkon view resource doesn't specify one.
       
    90 	// Validate that if the CBA is so configured that the optionsMenu property
       
    91 	// is not undefined.
       
    92 	var result = null;
       
    93 	var hasFormChild = findAknFormChild(instance.children) != null;
       
    94 	var controlPane = getControlPane(instance.children);
       
    95 	if (controlPane != null) {
       
    96 		var needsOptionsMenu = controlPane.properties.info.leftId == "EAknSoftkeyOptions";
       
    97 		var optionsMenuName = hasFormChild ? null : instance.properties.optionsMenu;
       
    98 		if (needsOptionsMenu && ((optionsMenuName == null || optionsMenuName == ""))) {
       
    99     		result = new java.util.ArrayList;
       
   100 			result.add(createSimpleModelError(instance, 
       
   101 				"optionsMenu", 
       
   102 				lookupString("validateOptionsMenu"), 
       
   103 				[  ]));
       
   104 		}
       
   105 	}
       
   106 	// Adding a menubar object to a View containing a Form could give the user the mistaken
       
   107 	// impression that the menubar will be used in some way. 
       
   108 	// Validate that there is no menubar child when there is a Form child
       
   109 	if (hasFormChild) {
       
   110 		if (findImmediateChildByComponentID(instance.children, "com.nokia.sdt.series60.MenuBar")) {
       
   111 			if (result == null)
       
   112 				result = new java.util.ArrayList;
       
   113 			result.add(newModelMessage(IStatus.INFO, 
       
   114 						formatString(lookupString("validateMenubarWithForm"), [ ]), 
       
   115 						instance, null, null));
       
   116 		}
       
   117 	}
       
   118 	return result;
       
   119  }
       
   120 
       
   121 	// note that laf will be null if a display model was not created
       
   122 CAknViewScript.prototype.queryPropertyChange = function(instance, propertyPath,
       
   123 					newValue, laf) {
       
   124 	return null;
       
   125 }