public static void addVM(VMTreeObjectVM vm) { VMTreeObjectRoot root = vm.getRoot(); if (root.getShadowObject() != null && vm.getShadowObject() == null) { // if(vm.getRecord()==null // ||vm.getRecord().powerState==null // ||!vm.getRecord().powerState.equals(Types.VmPowerState.RUNNING)){ // for(VMTreeObject o:root.getShadowObject().getChildren()){ // if(o.getName().equals(Constants.HALTED_VM_GROUP_DEFAULT_NAME)){ // VMTreeObjectVMinGroup vmInGroup = new VMTreeObjectVMinGroup(vm); // vm.setShadowObject(vmInGroup); // o.addChild(vmInGroup); // break; // } // } // }else{ for (VMTreeObject o : root.getShadowObject().getChildren()) { if (o.getName().equals(Constants.VM_GROUP_DEFAULT_NAME)) { VMTreeObjectVMinGroup vmInGroup = new VMTreeObjectVMinGroup(vm); vm.setShadowObject(vmInGroup); o.addChild(vmInGroup); break; } } // } } if (Constants.groupView != null) { Display display = PlatformUI.getWorkbench().getDisplay(); if (!display.isDisposed()) { Runnable runnable = new Runnable() { public void run() { Constants.groupView.getViewer().refresh(); } }; display.syncExec(runnable); } } }
public static boolean addServer(VMTreeObject object) { VMTreeObjectRootinGroup rootinGroup = null; if (object instanceof VMTreeObjectHost) { VMTreeObjectHost host = (VMTreeObjectHost) object; VMTreeObjectHostinGroup hostInGroup = new VMTreeObjectHostinGroup(host); host.setShadowObject(hostInGroup); rootinGroup = hostInGroup; } else { VMTreeObjectPool pool = (VMTreeObjectPool) object; VMTreeObjectPoolinGroup poolInGroup = new VMTreeObjectPoolinGroup(pool); pool.setShadowObject(poolInGroup); rootinGroup = poolInGroup; } rootinGroup.groupMap = GroupUtil.getGroupConfig(rootinGroup); ArrayList<VMTreeObjectVM> vmList = new ArrayList<VMTreeObjectVM>(); for (VMTreeObjectVM vm : ((VMTreeObjectRoot) object).vmMap.values()) { vmList.add(vm); } VMTreeObject defaultGroup = null; // VMTreeObject haltedVmGroup = null; // VMTreeObject templateGroup = null; for (VMTreeObject o : rootinGroup.getChildren()) { if (o.getName().equals(Constants.VM_GROUP_DEFAULT_NAME)) { defaultGroup = o; } // else if(o.getName().equals(Constants.HALTED_VM_GROUP_DEFAULT_NAME)){ // haltedVmGroup = o; // } // else if(o.getName().equals(Constants.TEMPLATE_GROUP_DEFAULT_NAME)){ // templateGroup = o; // } } if (defaultGroup == null) { defaultGroup = new VMTreeObjectGroup(Constants.VM_GROUP_DEFAULT_NAME); rootinGroup.addChild(defaultGroup); } // if(haltedVmGroup == null){ // haltedVmGroup = new VMTreeObjectGroup(Constants.HALTED_VM_GROUP_DEFAULT_NAME); // rootinGroup.addChild(haltedVmGroup); // } // if(templateGroup == null){ // templateGroup = new VMTreeObjectGroup(Constants.TEMPLATE_GROUP_DEFAULT_NAME); // rootinGroup.addChild(templateGroup); // } if (rootinGroup.groupMap != null) { ArrayList<VMTreeObjectVM> vminGroupList = new ArrayList<VMTreeObjectVM>(); for (String groupName : rootinGroup.groupMap.keySet()) { VMTreeObjectGroup group = new VMTreeObjectGroup(groupName); List<String> vminGroup = rootinGroup.groupMap.get(groupName); for (VMTreeObjectVM vm : vmList) { String vmUuid = vm.getApiObject().toWireString(); if (vminGroup.contains(vmUuid)) { // if(vm.getRecord()!=null // &&vm.getRecord().powerState!=null // &&vm.getRecord().powerState.equals(Types.VmPowerState.RUNNING)){ VMTreeObjectVMinGroup vmInGroup = new VMTreeObjectVMinGroup(vm); vm.setShadowObject(vmInGroup); group.addChild(vmInGroup); vminGroupList.add(vm); // } } } rootinGroup.addChild(group); } vmList.removeAll(vminGroupList); } else { rootinGroup.groupMap = new HashMap<String, List<String>>(); GroupUtil.addGroupConfig(rootinGroup); } for (VMTreeObjectVM vm : vmList) { VMTreeObjectVMinGroup vmInGroup = new VMTreeObjectVMinGroup(vm); vm.setShadowObject(vmInGroup); // if(vm.getRecord()!=null // &&vm.getRecord().powerState!=null // &&vm.getRecord().powerState.equals(Types.VmPowerState.RUNNING)){ defaultGroup.addChild(vmInGroup); // }else{ // haltedVmGroup.addChild(vmInGroup); // } } // for(VMTreeObjectTemplate vm:((VMTreeObjectRoot)object).templateMap.values()){ // VMTreeObjectTemplateinGroup vmInGroup = new VMTreeObjectTemplateinGroup(vm); // vm.setShadowObject(vmInGroup); // templateGroup.addChild(vmInGroup); // } Constants.VMGROUPS_TREE.addChild(rootinGroup); if (Constants.groupView != null) { Display display = PlatformUI.getWorkbench().getDisplay(); if (!display.isDisposed()) { Runnable runnable = new Runnable() { public void run() { Constants.groupView.getViewer().refresh(); } }; display.syncExec(runnable); } } return true; }