示例#1
0
  public static void fillVMMenu(IMenuManager manager, VMTreeObject selection) {

    VMTreeObjectVMinGroup vminGroup = (VMTreeObjectVMinGroup) selection;
    if (selection.getParent().getName().equals(Constants.VM_GROUP_DEFAULT_NAME)) {
      MenuManager addtogroupMenu = new MenuManager("Ìí¼Óµ½...");
      for (VMTreeObject group : vminGroup.getParent().getParent().getChildren()) {
        if (!group.getName().equals(Constants.VM_GROUP_DEFAULT_NAME)) {
          addtogroupMenu.add(new AddtoGroupAction(vminGroup, (VMTreeObjectGroup) group));
        }
      }
      manager.add(addtogroupMenu);
    } else {
      manager.add(new ResetGroupAction(vminGroup));
    }
    manager.add(new Separator());
    VMTreeObjectVM vm = vminGroup.getVmObject();
    VM.Record record = vm.getRecord();
    Types.VmPowerState state = record.powerState;
    if (state.equals(Types.VmPowerState.RUNNING)) {
      manager.add(new ShutDownAction(vm));
      manager.add(new RebootAction(vm));
    } else {
      manager.add(new StartAction(vm));
    }
  }
示例#2
0
 public static void fillVmListMenu(IMenuManager manager, List<VMTreeObject> list) {
   List<VMTreeObjectVMinGroup> vmList = new ArrayList<VMTreeObjectVMinGroup>();
   boolean isDefault = true;
   boolean isNotDefault = true;
   for (VMTreeObject o : list) {
     if (o.getParent().getName().equals(Constants.VM_GROUP_DEFAULT_NAME)) {
       isNotDefault = false;
     } else {
       isDefault = false;
     }
     vmList.add((VMTreeObjectVMinGroup) o);
   }
   if (isDefault) {
     MenuManager addtogroupMenu = new MenuManager("Ìí¼Óµ½...");
     for (VMTreeObject group : vmList.get(0).getParent().getParent().getChildren()) {
       if (!group.getName().equals(Constants.VM_GROUP_DEFAULT_NAME)) {
         addtogroupMenu.add(new AddtoGroupAction(vmList, (VMTreeObjectGroup) group));
       }
     }
     manager.add(addtogroupMenu);
     return;
   }
   if (isNotDefault) {
     manager.add(new ResetGroupAction(vmList));
   }
 }
示例#3
0
 public static void remove(VMTreeObject o) {
   final VMTreeObject shadow = o.getShadowObject();
   if (shadow == null) {
     return;
   }
   if (shadow.getParent() != null) {
     shadow.getParent().getChildrenList().remove(shadow);
   }
   if (Constants.groupView != null) {
     Display display = PlatformUI.getWorkbench().getDisplay();
     if (!display.isDisposed()) {
       Runnable runnable =
           new Runnable() {
             public void run() {
               Constants.groupView.getViewer().remove(shadow);
               Constants.groupView.getViewer().refresh();
             }
           };
       display.syncExec(runnable);
     }
   }
 }
示例#4
0
  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);
      }
    }
  }
示例#5
0
  @Override
  public void createPartControl(Composite parent) {

    viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    drillDownAdapter = new DrillDownAdapter(viewer);
    viewer.setContentProvider(new VMTreeContentProvider());
    viewer.setLabelProvider(new VMTreeGroupLabelProvider());
    viewer.setInput(invisibleRoot);
    drillDownAdapter.addNavigationActions(getViewSite().getActionBars().getToolBarManager());

    viewer
        .getTree()
        .addListener(
            SWT.Selection,
            new Listener() {
              public void handleEvent(Event event) {

                VMTreeObject object = (VMTreeObject) GetSelectedObject();
                VMTreeObject select = null;
                if (object instanceof VMTreeObjectVMinGroup) {
                  select = ((VMTreeObjectVMinGroup) object).getVmObject();
                } else if (object instanceof VMTreeObjectPoolinGroup) {
                  select = ((VMTreeObjectPoolinGroup) object).getPoolObject();
                } else if (object instanceof VMTreeObjectHostinGroup) {
                  select = ((VMTreeObjectHostinGroup) object).getHostObject();
                }
                if (select != null && !select.getItemState().equals(ItemState.changing)) {
                  ISelection selection = new StructuredSelection(new Object[] {select});
                  if (Constants.treeView != null && Constants.treeView.getViewer() != null) {
                    Constants.treeView.getViewer().setSelection(selection);
                    Constants.pageBookView.selectionChanged(
                        Constants.treeView, Constants.treeView.getViewer().getSelection());
                    PageBookViewState.addState();
                  }
                }
              }
            });

    invisibleRoot.addChild(Constants.VMGROUPS_TREE);

    CreateContextMenu();

    viewer.expandAll();
    viewer.refresh();
    ISelection selection = new StructuredSelection(new Object[] {Constants.VMGROUPS_TREE});
    viewer.setSelection(selection);

    Constants.groupView = this;
  }
示例#6
0
  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;
  }
示例#7
0
  public static void fillGroupMenu(IMenuManager manager, VMTreeObject selection) {

    if (!selection.getName().equals(Constants.VM_GROUP_DEFAULT_NAME)) {
      manager.add(new DeleteGroupAction((VMTreeObjectGroup) selection));
    }
  }