public void PostGetClusterNetworkList_New(java.util.ArrayList<network> network_list) { java.util.ArrayList<network> networks = new java.util.ArrayList<network>(); for (network a : network_list) { if (a.getStatus() == NetworkStatus.Operational) { networks.add(a); } } java.util.ArrayList<VmNetworkInterface> nics = Linq.<VmNetworkInterface>Cast(getItems()); int nicCount = nics.size(); String newNicName = DataProvider.GetNewNicName(nics); VmInterfaceModel model = (VmInterfaceModel) getWindow(); model.getNetwork().setItems(networks); model.getNetwork().setSelectedItem(networks.size() > 0 ? networks.get(0) : null); model .getNicType() .setItems(DataProvider.GetNicTypeList(getEntityStronglyTyped().getos(), false)); model .getNicType() .setSelectedItem(DataProvider.GetDefaultNicType(getEntityStronglyTyped().getos())); model.getName().setEntity(newNicName); model.getMAC().setIsAvailable(false); UICommand tempVar = new UICommand("OnSave", this); tempVar.setTitle("OK"); tempVar.setIsDefault(true); model.getCommands().add(tempVar); UICommand tempVar2 = new UICommand("Cancel", this); tempVar2.setTitle("Cancel"); tempVar2.setIsCancel(true); model.getCommands().add(tempVar2); }
@Override public void onSuccess(Object model, Object returnValue) { List<Disk> disks = adjustReturnValue(returnValue); Collections.sort(disks, new DiskByDiskAliasComparator()); ArrayList<DiskModel> diskModels = Linq.disksToDiskModelList(disks); List<EntityModel<DiskModel>> entities = Linq.toEntityModelList(Linq.filterDisksByType(diskModels, diskStorageType)); initAttachableDisks(entities); }
public void OnManage() { ListModel model = (ListModel) getWindow(); java.util.ArrayList<EntityModel> items = Linq.<EntityModel>Cast(model.getItems()); java.util.ArrayList<network> networks = Linq.<network>Cast(getItems()); if (getEntity() == null) { Cancel(); return; } java.util.ArrayList<VdcActionParametersBase> prms1 = new java.util.ArrayList<VdcActionParametersBase>(); for (EntityModel a : items) { boolean value = false; for (network b : networks) { if (b.getId().equals(((network) a.getEntity()).getId())) { value = true; break; } } if (a.getIsSelected() && !value) { prms1.add(new AttachNetworkToVdsGroupParameter(getEntity(), (network) a.getEntity())); } } // Call the command only if necessary (i.e. only if there are paramters): if (prms1.size() > 0) { Frontend.RunMultipleAction(VdcActionType.AttachNetworkToVdsGroup, prms1); } java.util.ArrayList<VdcActionParametersBase> prms2 = new java.util.ArrayList<VdcActionParametersBase>(); for (EntityModel a : items) { boolean value = true; for (network b : networks) { if (b.getId().equals(((network) a.getEntity()).getId())) { value = false; break; } } if (!a.getIsSelected() && !value) { prms2.add(new AttachNetworkToVdsGroupParameter(getEntity(), (network) a.getEntity())); } } // Call the command only if necessary (i.e. only if there are paramters): if (prms2.size() > 0) { Frontend.RunMultipleAction(VdcActionType.DetachNetworkToVdsGroup, prms2); } Cancel(); }
public void PostManage(java.util.ArrayList<network> networkList, ListModel model) { Collections.sort(networkList, new Linq.NetworkByNameComparer()); java.util.ArrayList<EntityModel> items = new java.util.ArrayList<EntityModel>(); for (network a : networkList) { if (!a.getname().equals("engine")) { EntityModel tempVar = new EntityModel(); tempVar.setEntity(a); tempVar.setTitle(a.getname()); items.add(tempVar); } } model.setItems(items); boolean noItems = items.isEmpty(); java.util.ArrayList<network> networks = Linq.<network>Cast(getItems()); java.util.ArrayList<EntityModel> selectedItems = new java.util.ArrayList<EntityModel>(); for (EntityModel item : items) { network net = (network) item.getEntity(); boolean value = false; for (network a : networks) { if (a.getId().equals(net.getId())) { value = true; break; } } item.setIsSelected(value); if (value) { selectedItems.add(item); } } model.setSelectedItems(selectedItems); UICommand tempVar2 = new UICommand("Cancel", this); tempVar2.setTitle("Cancel"); tempVar2.setIsDefault(noItems); tempVar2.setIsCancel(true); model.getCommands().add(tempVar2); if (!noItems) { UICommand tempVar3 = new UICommand("OnManage", this); tempVar3.setTitle("OK"); tempVar3.setIsDefault(true); model.getCommands().add(0, tempVar3); } }
private boolean isPlugAvailableByDisks(boolean plug) { ArrayList<Disk> disks = getSelectedItems() != null ? Linq.<Disk>cast(getSelectedItems()) : new ArrayList<Disk>(); for (Disk disk : disks) { boolean isLocked = disk.getDiskStorageType() == DiskStorageType.IMAGE && ((DiskImage) disk).getImageStatus() == ImageStatus.LOCKED; boolean isDiskHotpluggableInterface = false; if (getEntity() != null) { isDiskHotpluggableInterface = AsyncDataProvider.getInstance() .getDiskHotpluggableInterfaces( getEntity().getOs(), getEntity().getVdsGroupCompatibilityVersion()) .contains(disk.getDiskInterface()); } if (disk.getPlugged() == plug || isLocked || (!isDiskHotpluggableInterface && !isVmDown())) { return false; } } return true; }
protected void setImagesToModel(UnitVmModel model, List<String> images) { String oldCdImage = model.getCdImage().getSelectedItem(); model.getCdImage().setItems(images); model .getCdImage() .setSelectedItem((oldCdImage != null) ? oldCdImage : Linq.firstOrDefault(images)); }
public void remove() { if (getWindow() != null) { return; } ConfirmationModel model = new ConfirmationModel(); setWindow(model); model.setTitle(ConstantsManager.getInstance().getConstants().removeUsersTitle()); model.setHelpTag(HelpTag.remove_user); model.setHashName("remove_user"); // $NON-NLS-1$ ArrayList<String> list = new ArrayList<String>(); for (DbUser item : Linq.<DbUser>cast(getSelectedItems())) { list.add(item.getFirstName()); } model.setItems(list); UICommand tempVar = new UICommand("OnRemove", this); // $NON-NLS-1$ tempVar.setTitle(ConstantsManager.getInstance().getConstants().ok()); tempVar.setIsDefault(true); model.getCommands().add(tempVar); UICommand tempVar2 = new UICommand("Cancel", this); // $NON-NLS-1$ tempVar2.setTitle(ConstantsManager.getInstance().getConstants().cancel()); tempVar2.setIsCancel(true); model.getCommands().add(tempVar2); }
public void PostGetClusterNetworkList_Edit(java.util.ArrayList<network> network_list) { VmNetworkInterface nic = (VmNetworkInterface) getSelectedItem(); int nicCount = Linq.<VmNetworkInterface>Cast(getItems()).size(); java.util.ArrayList<network> networks = new java.util.ArrayList<network>(); for (network a : network_list) { if (a.getStatus() == NetworkStatus.Operational) { networks.add(a); } } VmInterfaceModel model = (VmInterfaceModel) getWindow(); model.getNetwork().setItems(networks); network network = null; for (network a : networks) { if (StringHelper.stringsEqual(a.getname(), nic.getNetworkName())) { network = a; break; } } model.getNetwork().setSelectedItem(network); Integer selectedNicType = nic.getType(); java.util.ArrayList<VmInterfaceType> nicTypes = DataProvider.GetNicTypeList( getEntityStronglyTyped().getos(), VmInterfaceType.forValue(selectedNicType) == VmInterfaceType.rtl8139_pv); model.getNicType().setItems(nicTypes); if (selectedNicType == null || !nicTypes.contains(VmInterfaceType.forValue(selectedNicType))) { selectedNicType = DataProvider.GetDefaultNicType(getEntityStronglyTyped().getos()).getValue(); } model.getNicType().setSelectedItem(VmInterfaceType.forValue(selectedNicType)); model.getName().setEntity(nic.getName()); model.getMAC().setIsAvailable(false); UICommand tempVar = new UICommand("OnSave", this); tempVar.setTitle("OK"); tempVar.setIsDefault(true); model.getCommands().add(tempVar); UICommand tempVar2 = new UICommand("Cancel", this); tempVar2.setTitle("Cancel"); tempVar2.setIsCancel(true); model.getCommands().add(tempVar2); }
@Override protected void selectExternalProvider() { final Network network = getNetwork(); getExternalProviders() .setSelectedItem( Linq.firstOrNull( getExternalProviders().getItems(), new Linq.NetworkSameProviderPredicate(network))); }
private void doUpdateTimeZone(final String selectedTimeZone) { final Collection<TimeZoneModel> timeZones = TimeZoneModel.getTimeZones(getTimeZoneType()); getModel().getTimeZone().setItems(timeZones); getModel() .getTimeZone() .setSelectedItem( Linq.firstOrDefault(timeZones, new Linq.TimeZonePredicate(selectedTimeZone))); }
private void updateActionAvailability() { ArrayList<DiskImage> disks = getSelectedItems() != null ? Linq.<DiskImage>cast(getSelectedItems()) : new ArrayList<DiskImage>(); getRemoveCommand().setIsExecutionAllowed(disks.size() > 0 && isRemoveCommandAvailable(disks)); }
@Override public final SafeHtml getValue(Snapshot snapshot) { // Get raw description string (ignore < and > characters). // Customize description style as needed. SafeHtml description = SafeHtmlUtils.fromString(snapshot.getDescription()); String descriptionStr = description.asString(); if (snapshot.getStatus() == SnapshotStatus.IN_PREVIEW) { List<String> previewedItems = new ArrayList<>(Arrays.asList(constants.vmConfiguration())); previewedItems.addAll(Linq.getDiskAliases(snapshot.getDiskImages())); descriptionStr = messages.snapshotPreviewing( descriptionStr, StringUtils.join(previewedItems, ", ")); // $NON-NLS-1$ description = templates.snapshotDescription("color:orange", descriptionStr); // $NON-NLS-1$ } else if (snapshot.getType() == SnapshotType.STATELESS) { descriptionStr = descriptionStr + " (" + constants.readonlyLabel() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ description = templates.snapshotDescription("font-style:italic", descriptionStr); // $NON-NLS-1$ } else if (snapshot.getType() == SnapshotType.PREVIEW) { descriptionStr = constants.snapshotDescriptionActiveVmBeforePreview(); description = templates.snapshotDescription("color:gray", descriptionStr); // $NON-NLS-1$ } else if (snapshot.getType() == SnapshotType.ACTIVE) { descriptionStr = constants.snapshotDescriptionActiveVm(); description = templates.snapshotDescription("color:gray", descriptionStr); // $NON-NLS-1$ } else if (snapshot.getType() == SnapshotType.REGULAR && !snapshot.getDiskImages().isEmpty()) { descriptionStr = messages.snapshotPreviewing( descriptionStr, StringUtils.join( Linq.getDiskAliases(snapshot.getDiskImages()), ", ")); // $NON-NLS-1$ description = templates.snapshotDescription("color:gold", descriptionStr); // $NON-NLS-1$ } return description; }
@Override public void setItems(Collection value) { ArrayList<Disk> disks = value != null ? Linq.<Disk>cast(value) : new ArrayList<Disk>(); Collections.sort(disks, new DiskByAliasComparer()); super.setItems(disks); updateActionAvailability(); }
public ArrayList<StorageDomain> filterStorageDomains(ArrayList<StorageDomain> storageDomains) { // filter only the Active storage domains (Active regarding the relevant storage pool). ArrayList<StorageDomain> list = new ArrayList<StorageDomain>(); for (StorageDomain a : storageDomains) { if (Linq.isDataActiveStorageDomain(a)) { list.add(a); } } // Filter according to system tree selection. if (getSystemTreeSelectedItem() != null && getSystemTreeSelectedItem().getType() == SystemTreeItemType.Storage) { StorageDomain selectStorage = (StorageDomain) getSystemTreeSelectedItem().getEntity(); StorageDomain sd = Linq.firstOrDefault(list, new Linq.StoragePredicate(selectStorage.getId())); list = new ArrayList<StorageDomain>(Arrays.asList(new StorageDomain[] {sd})); } return list; }
private boolean isMoveCommandAvailable() { ArrayList<Disk> disks = getSelectedItems() != null ? Linq.<Disk>cast(getSelectedItems()) : new ArrayList<Disk>(); for (Disk disk : disks) { if (!isImageDiskOK(disk) || (!isVmDown() && disk.getPlugged()) || disk.isDiskSnapshot()) { return false; } } return true; }
private boolean isRemoveCommandAvailable() { ArrayList<Disk> disks = getSelectedItems() != null ? Linq.<Disk>cast(getSelectedItems()) : new ArrayList<Disk>(); for (Disk disk : disks) { if (isDiskLocked(disk) || (!isVmDown() && disk.getPlugged())) { return false; } } return true; }
public void postUpdateHost(Collection<VDS> hosts) { // Filter hosts hosts = Linq.where(hosts, new Linq.HostStatusPredicate(VDSStatus.Up)); // Allow only hosts with version above 2.2 for export storage. ArrayList<VDS> list = new ArrayList<VDS>(); if (getCurrentStorageItem() != null && getCurrentStorageItem().getRole() == StorageDomainType.ImportExport) { for (VDS host : hosts) { if (host.getVdsGroupCompatibilityVersion().compareTo(new Version("2.2")) >= 0) { //$NON-NLS-1$ list.add(host); } } hosts = list; } VDS oldSelectedItem = getHost().getSelectedItem(); VDS selectedItem = null; // On Edit of active storage - only SPM is available. In edit of storage in maintenance, // any host can perform the operation, thus no need to filter to use just the SPM if (getStorage() != null && getStorage().getStatus() != StorageDomainStatus.Maintenance) { VDS spm = getSPM(hosts); hosts = spm != null ? Collections.singletonList(spm) : Collections.<VDS>emptyList(); } // Try to select previously selected host. if (oldSelectedItem != null) { selectedItem = Linq.firstOrDefault(hosts, new Linq.HostPredicate(oldSelectedItem.getId())); } // Select a default - if there's a SPM choose it, otherwise choose the first host in the list. if (selectedItem == null) { VDS spm = getSPM(hosts); selectedItem = spm == null ? Linq.firstOrDefault(hosts) : spm; } getHost().setItems(hosts, selectedItem); }
@Override protected void addUsersToModel(VdcQueryReturnValue returnValue, Set<String> excludeUsers) { Iterable<DbUser> filteredUsers = Linq.where( (ArrayList<DbUser>) returnValue.getReturnValue(), new Linq.DbUserPredicate(getTargetDbUser())); for (DbUser dbUser : filteredUsers) { if (!excludeUsers.contains(dbUser.getExternalId())) { EntityModel tempVar2 = new EntityModel(); tempVar2.setEntity(dbUser); getusers().add(tempVar2); } } }
@Override public void edit(final SnapshotModel model) { driver.edit(model); if (model.isShowMemorySnapshotWarning() && !model.isShowPartialSnapshotWarning()) { Style dialogStyle = getParent().getParent().getParent().getElement().getStyle(); dialogStyle.setWidth(450, Style.Unit.PX); dialogStyle.setHeight(200, Style.Unit.PX); } partialSnapshotWarningPanel.setVisible(model.isShowPartialSnapshotWarning()); memoryWarningPanel.setVisible(model.isShowMemorySnapshotWarning()); horizontalSeparator.setVisible( model.isShowPartialSnapshotWarning() && model.isShowMemorySnapshotWarning()); vmDisksLabel.setText( messages.vmDisksLabel( model.getVmDisks().size(), StringUtils.join(Linq.getDiskAliases(model.getVmDisks()), ", "))); // $NON-NLS-1$ snapshotDisksLabel.setText( messages.snapshotDisksLabel( model.getDisks().size(), StringUtils.join(Linq.getDiskAliases(model.getDisks()), ", "))); // $NON-NLS-1$ }
protected void doChangeDefautlHost(Guid hostGuid) { if (hostGuid != null) { Guid vdsId = hostGuid; if (getModel().getDefaultHost().getItems() != null) { getModel() .getDefaultHost() .setSelectedItem( Linq.firstOrDefault( getModel().getDefaultHost().getItems(), new Linq.HostPredicate(vdsId))); } getModel().getIsAutoAssign().setEntity(false); } else { getModel().getIsAutoAssign().setEntity(true); } }
@SuppressWarnings("rawtypes") @Override public void setItems(Iterable value) { ArrayList<Disk> disks = value != null ? Linq.<Disk>Cast(value) : new ArrayList<Disk>(); ArrayList<Disk> filteredDisks = new ArrayList<Disk>(); DiskStorageType diskStorageType = (DiskStorageType) getDiskViewType().getEntity(); for (Disk disk : disks) { if (diskStorageType == null || diskStorageType == disk.getDiskStorageType()) { filteredDisks.add(disk); } } super.setItems(filteredDisks); }
@Override protected List<StorageDomain> filterStorageDomains(List<StorageDomain> storageDomains) { List<StorageDomain> availableStorageDomains = new ArrayList<>(); // Filtering out domains that are not active for (StorageDomain storageDomainItem : storageDomains) { if (Linq.isDataActiveStorageDomain(storageDomainItem)) { availableStorageDomains.add(storageDomainItem); } } // Sorting by name Collections.sort(availableStorageDomains, new NameableComparator()); return availableStorageDomains; }
private void updateScanAlignmentCommandAvailability() { boolean isExecutionAllowed = true; if (getSelectedItems() != null && getEntity() != null) { ArrayList<Disk> disks = Linq.<Disk>cast(getSelectedItems()); for (Disk disk : disks) { if (!(disk instanceof LunDisk) && !isDiskOnBlockDevice(disk)) { isExecutionAllowed = false; break; } } } else { isExecutionAllowed = false; } getScanAlignmentCommand().setIsExecutionAllowed(isExecutionAllowed); // onPropertyChanged(new PropertyChangedEventArgs("IsScanAlignmentEnabled")); //$NON-NLS-1$ }
private boolean isLiveMoveCommandAvailable() { if (!getIsLiveStorageMigrationEnabled()) { return false; } VM vm = getEntity(); if (vm == null || !vm.getStatus().isUpOrPaused() || vm.isStateless()) { return false; } ArrayList<Disk> disks = getSelectedItems() != null ? Linq.<Disk>cast(getSelectedItems()) : new ArrayList<Disk>(); for (Disk disk : disks) { if (!isImageDiskOK(disk) || disk.isDiskSnapshot()) { return false; } } return true; }
private void postGetAttachedTags(UserListModel userListModel, TagListModel tagListModel) { if (userListModel.getLastExecutedCommand() == getAssignTagsCommand()) { ArrayList<Tags> attachedTags = Linq.distinct(userListModel.allAttachedTags, new TagsEqualityComparer()); for (Tags a : attachedTags) { int count = 0; for (Tags b : allAttachedTags) { if (b.gettag_id().equals(a.gettag_id())) { count++; } } userListModel.attachedTagsToEntities.put( a.gettag_id(), count == userListModel.getSelectedItems().size()); } tagListModel.setAttachedTagsToEntities(userListModel.attachedTagsToEntities); } else if ("OnAssignTags" .equals(userListModel.getLastExecutedCommand().getName())) // $NON-NLS-1$ { userListModel.postOnAssignTags(tagListModel.getAttachedTagsToEntities()); } }
@Override protected void addGroupsToModel(VdcQueryReturnValue returnValue, Set<String> excludeUsers) { Iterable<DbGroup> filteredGroups = Linq.where( (ArrayList<DbGroup>) returnValue.getReturnValue(), new Linq.DbGroupPredicate(getTargetDbGroup())); for (DbGroup group : filteredGroups) { if (!excludeUsers.contains(group.getId().toString())) { DbUser dbUser = new DbUser(); dbUser.setExternalId(group.getExternalId()); dbUser.setFirstName(group.getName()); dbUser.setLastName(""); // $NON-NLS-1$ dbUser.setLoginName(""); // $NON-NLS-1$ dbUser.setDomain(group.getDomain()); dbUser.setNamespace(group.getNamespace()); EntityModel entity = new EntityModel(); entity.setEntity(dbUser); getgroups().add(entity); } } }
public void onRemove() { ArrayList<DbUser> items = Linq.<DbUser>cast(getSelectedItems()); ArrayList<VdcActionParametersBase> userPrms = new ArrayList<VdcActionParametersBase>(); ArrayList<VdcActionParametersBase> groupPrms = new ArrayList<VdcActionParametersBase>(); for (DbUser item : items) { if (!item.isGroup()) { userPrms.add(new IdParameters(item.getId())); } else { groupPrms.add(new IdParameters(item.getId())); } } if (userPrms.size() > 0) { Frontend.getInstance().runMultipleAction(VdcActionType.RemoveUser, userPrms); } if (groupPrms.size() > 0) { Frontend.getInstance().runMultipleAction(VdcActionType.RemoveGroup, groupPrms); } cancel(); }
@Override protected void selectExternalProvider() { getExternalProviders().setSelectedItem(Linq.firstOrNull(getExternalProviders().getItems())); }