From e4159f8cea57077c755030a421c091b28c7a8ecc Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Mon, 19 Mar 2012 17:06:20 -0700 Subject: Use new tree control in Materials panel. Signed-off-by: Nivesh Rajbhandari --- js/panels/Materials/materials-data.json | 43 ++++++++++++++++++++++ .../materials-library-panel.html | 43 ++++++++++++++++++---- .../materials-library-panel.js | 34 ++++++++--------- .../materials-popup.reel/materials-popup.js | 6 ++- 4 files changed, 99 insertions(+), 27 deletions(-) create mode 100644 js/panels/Materials/materials-data.json (limited to 'js/panels/Materials') diff --git a/js/panels/Materials/materials-data.json b/js/panels/Materials/materials-data.json new file mode 100644 index 00000000..f06ab6c8 --- /dev/null +++ b/js/panels/Materials/materials-data.json @@ -0,0 +1,43 @@ +{ + "label": "materials", + "children": [ + { + "label": "Ninja Materials", + "children": [ + { + "label": "Uber", + "id" : "UberMaterial" + }, + { + "label": "Bump Metal", + "id" : "BumpMetalMaterial" + }, + { + "label": "Linear Gradient", + "id" : "LinearGradientMaterial" + }, + { + "label": "Radial Gradient", + "id" : "RadialGradientMaterial" + }, + { + "label": "Flat", + "id" : "FlatMaterial" + } + ] + }, + { + "label": "Custom Materials", + "children": [ + { + "label": "Checker Board", + "id" : "CheckerBoard" + }, + { + "label": "Shiny Metal", + "id" : "ShinyMetal" + } + ] + } + ] +} \ No newline at end of file diff --git a/js/panels/Materials/materials-library-panel.reel/materials-library-panel.html b/js/panels/Materials/materials-library-panel.reel/materials-library-panel.html index fe17d0f8..4e41512f 100755 --- a/js/panels/Materials/materials-library-panel.reel/materials-library-panel.html +++ b/js/panels/Materials/materials-library-panel.reel/materials-library-panel.html @@ -46,10 +46,39 @@ } ] }, - "materialInfo": { - "module": "js/panels/Materials/materials-popup.reel", - "name": "MaterialsPopup" - }, + "materialInfo": { + "module": "js/panels/Materials/materials-popup.reel", + "name": "MaterialsPopup" + }, + "materialsController" : { + "module": "js/controllers/tree-controller", + "name": "TreeController", + "properties" : { + "branchKey" : "children", + "labelKey" : "label", + "delegate": {"@": "owner" } + }, + "bindings": { + "content": { + "boundObject": {"@": "owner"}, + "boundObjectPropertyPath": "materialsData" + } + } + }, + "materialsContainer" : { + "module" : "js/components/treeview/treeview.reel", + "name" : "Treeview", + "properties" : { + "element" : {"#": "materials_library_tree"}, + "branchComponent" : {"@": "branch" }, + "contentController": {"@": "materialsController"}, + "showRoot": false + } + }, + "branch" : { + "module" : "js/components/treeview/ninja-branch.reel", + "name" : "Branch" + }, "owner": { "module": "js/panels/Materials/materials-library-panel.reel", "name": "MaterialsLibraryPanels", @@ -65,9 +94,9 @@
-
-
    -
    +
    +
    +

    diff --git a/js/panels/Materials/materials-library-panel.reel/materials-library-panel.js b/js/panels/Materials/materials-library-panel.reel/materials-library-panel.js index bb550598..5fd86d00 100755 --- a/js/panels/Materials/materials-library-panel.reel/materials-library-panel.js +++ b/js/panels/Materials/materials-library-panel.reel/materials-library-panel.js @@ -4,29 +4,26 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. */ -var Tree = require("js/components/tree.reel").Tree, - MaterialsPopup = require("js/panels/Materials/materials-popup.reel").MaterialsPopup, - PopupMananger = require("js/components/popup-manager.reel").PopupMananger, +var Montage = require("montage/core/core").Montage, + Component = require("montage/ui/component").Component, + MaterialsData = require("js/panels/Materials/materials-data.json"), Popup = require("montage/ui/popup/popup.reel").Popup; -exports.MaterialsLibraryPanel = (require("montage/core/core").Montage).create(require("montage/ui/component").Component, { +exports.MaterialsLibraryPanel = Montage.create(Component, { + + materialsData: { + value: null + }, _hasFocus: { enumerable: false, value: false }, - - prepareForDraw: { - enumerable: false, - value: function() { - var treeHolderDiv = document.getElementById("materials_library_tree"); - var materialsTree = Tree.create(); - materialsTree.element = treeHolderDiv; - materialsTree.dataProvider = this._loadXMLDoc("js/panels/Materials/Materials.xml"); - materialsTree.needsDraw = true; - materialsTree.addEventListener("change", this, true); - } + didCreate: { + value: function() { + this.materialsData = MaterialsData; + } }, willDraw: { @@ -71,10 +68,9 @@ exports.MaterialsLibraryPanel = (require("montage/core/core").Montage).create(re } }, - captureChange: { - value:function(e) { - var tNode = e._event.treeNode; - this._showMaterialPopup(tNode.id); + handleNodeActivation: { + value:function(obj) { + this._showMaterialPopup(obj.id); } }, diff --git a/js/panels/Materials/materials-popup.reel/materials-popup.js b/js/panels/Materials/materials-popup.reel/materials-popup.js index 193e72b7..b44761bc 100755 --- a/js/panels/Materials/materials-popup.reel/materials-popup.js +++ b/js/panels/Materials/materials-popup.reel/materials-popup.js @@ -214,7 +214,11 @@ exports.MaterialsPopup = Montage.create(Component, { enumerable: true, value: function(materialID) { - this._materialName = materialID; + // Note that setting Array.length = 0 will empty arrays, + // which is fine if you use getMaterialData to get a new array, but not for the + // dummyData arrays. + this._materialsData.length = 0; + this._materialName = materialID; if( (materialID === "UberMaterial") || (materialID === "FlatMaterial") || -- cgit v1.2.3