<@doc alias="modelsList" hierarchy="GMLDOM"> Holds a list of models names Abstract class This class cotaines implementation for handling list of models. It is used by favorites and recent models The list holds objects of type ModelInfo (c) SAP AG 2003-2006. All rights reserved. /////////////////////////////////////////////////////////////////////// // CLASS HEADER abstract Class ModelsList; readonly property list = ^ModelInfo[]; readonly property listName = ""; <@method name="init" scope="public"> prepare the list of favorites and list of recent models method init() this.list = []; var tmplist=GETVAR(this.listName); if(!tmplist) return; for (var i=0, len=tmplist.length; i general method for adding a model to a list The model to add method addModel(modelInfo) try { if (!ISA(modelInfo, 'env:ModelInfo')) return false; modelInfo.normalize(); //display model name only (not the full path) this.setModelDisplayName(modelInfo); //if the model already exists - remove it and re-insert it in the right place var k = this.getIndex(modelInfo); if (k >= 0) this.list.splice(k, 1); this.list.unshift(modelInfo); //update the order of the list after new item insert this.updateIndex(); //sort this.saveList(); return true; } catch(e) { WRITE("addModel has failed: " + e.description); return false; } end ////////////////////////////////////////////////////////////////////////// // CLEAR LIST ////////////////////////////////////////////////////////////////////////// <@method name="clearList" scope="public"> Clears the list method clearList() this.resetList(); this.saveList(); end <@method name="resetPanelModels" scope="public"> reset the lists method resetList() this.list = []; end ////////////////////////////////////////////////////////////////////////// // GET LIST ////////////////////////////////////////////////////////////////////////// <@method name="getList" scope="public"> Gets the requested list in the right order. The order is determined while saving, so no changing of order here recent - chronological favorites - alphabetical An array of the handles of the recent models, in chronological order method getList() //if production kit was chosen in aplication openening (in url) then get the models of the kit type if(_mainProductionKit) { var newList = []; for(i=0, len=this.list.length; i Updates a specified model in the list, if it is found if newModelInfo is null, the model will be deleted from list type of model The old model The new model that will replace ~oldModelInfo; if omitted, ~oldModelInfo will be removed method updateModel(oldModelInfo, newModelInfo, listOf) if (!ISA(oldModelInfo, 'env:ModelInfo')) return; oldModelInfo.normalize(); if (ISA(newModelInfo, 'env:ModelInfo')) newModelInfo.normalize(); else newModelInfo=null; if (newModelInfo) { //update the model //find the model in the list var index = this.getIndex(oldModelInfo); if(index >= 0) { newModelInfo.modelType = oldModelInfo.modelType; this.setModelDisplayName(newModelInfo); this.list[index] = newModelInfo; //order the list after a change in an item this.updateIndex(); } } else { //delete the model this.removeModel(oldModelInfo); } this.saveList(); // Recursively update all models that belong to the deleted/renamed folder var typeStr = oldModelInfo.modelUrn.substr(oldModelInfo.modelUrn.length-4,4); if (typeStr != '.dir') return; if (newModelInfo && newModelInfo.modelUrn) { var response = _channel2.executeService("LibManager", "actionListFolders", [newModelInfo.modelUrn, 'A', false], null, null); if (!response) return; var newUrnMid = newModelInfo.modelUrn.substr(0,newModelInfo.modelUrn.length-4).substr(newModelInfo.modelUrn.indexOf('.')+1) var oldUrnMid = oldModelInfo.modelUrn.substr(0,oldModelInfo.modelUrn.length-4).substr(oldModelInfo.modelUrn.indexOf('.')+1) var items=response.childNodes, item; var newModelInf, oldModelInf; while (item = items.nextNode) { newModelInf = _channel2.toModelHandle(item.getAttribute('urn')); oldModelInf = _channel2.toModelHandle(newModelInf.modelUrn.replace(newUrnMid, oldUrnMid)); oldModelInf.modelName = newModelInf.modelName.replace(newUrnMid, oldUrnMid); this.updateModel(oldModelInf, newModelInf); } } else { var response = _channel2.executeService("LibManager", "actionListFolders", [oldModelInfo.modelUrn, 'A', false], null, null); if (!response) return; var items=response.childNodes, item; while (item = items.nextNode) this.updateModel(_channel2.toModelHandle(item.getAttribute('urn')), null); } end method getIndex(modelInfo) for (var i=0, len=this.list.length; i=0) this.list.splice(index, 1); end <@method name="removeModels" scope="private"> removes requested models from the list of models list of models to be removed, each entry contains a modelInfo method removeModels(deletedList) var modelInfo={}, position; for(var i=0, len=deletedList.length; i sort the list should be implemented by the inheriting class according to its sorting algorithm method updateIndex() end ////////////////////////////////////////////////////////////////////////// // SAVE LIST ////////////////////////////////////////////////////////////////////////// method saveList() var saveList = []; for (var i=0, len=this.list.length; iupdateModelsList'); $MAINMENU.refreshDynamicMenubar(); end method setModelDisplayName(modelInfo) modelInfo.displayName = modelInfo.modelName.substring(modelInfo.modelName.lastIndexOf('/')+1); modelInfo.displayName = modelInfo.displayName.substring(modelInfo.displayName.lastIndexOf('.')+1); end