Search in sources :

Example 36 with ListModel

use of org.ovirt.engine.ui.uicommonweb.models.ListModel in project ovirt-engine by oVirt.

the class FenceAgentsEditor method createWidget.

@Override
protected FenceAgentWidget createWidget(final FenceAgentModel model) {
    modelProvider.initializeModel(model);
    FenceAgentWidget widget = new FenceAgentWidget();
    widget.addUpClickHandler(event -> {
        listModel.moveUp(model);
        updateButtonState();
    });
    widget.addDownClickHandler(event -> {
        listModel.moveDown(model);
        updateButtonState();
    });
    widget.addRemoveConcurrentGroupClickHandler(model, event -> {
        listModel.removeConcurrent(model);
        listModel.updateConcurrentList();
    });
    for (final FenceAgentModel concurrentModel : model.getConcurrentList()) {
        modelProvider.initializeModel(concurrentModel);
        widget.addRemoveConcurrentGroupClickHandler(concurrentModel, event -> {
            listModel.removeConcurrent(concurrentModel);
            listModel.updateConcurrentList();
        });
    }
    widget.edit(model);
    model.getManagementIp().getEntityChangedEvent().addListener((ev, sender, args) -> {
        listModel.updateConcurrentList();
        for (Pair<FenceAgentModel, FenceAgentWidget> modelWidgetPair : items) {
            modelWidgetPair.getSecond().refresh();
        }
    });
    model.getConcurrentSelectList().getSelectedItemChangedEvent().addListener((ev, sender, args) -> {
        if (sender instanceof ListModel) {
            @SuppressWarnings("unchecked") ListModel<String> sourceListModel = (ListModel<String>) sender;
            if (sourceListModel.getItems() != null && !sourceListModel.getItems().isEmpty() && sourceListModel.getItems() instanceof List) {
                List<String> options = (List<String>) sourceListModel.getItems();
                if (!options.get(0).equals(sourceListModel.getSelectedItem())) {
                    // Another option selected.
                    listModel.makeConcurrent(model, sourceListModel.getSelectedItem());
                }
            }
        }
    });
    return widget;
}
Also used : ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) FenceAgentListModel(org.ovirt.engine.ui.uicommonweb.models.hosts.FenceAgentListModel) FenceAgentModel(org.ovirt.engine.ui.uicommonweb.models.hosts.FenceAgentModel) List(java.util.List)

Example 37 with ListModel

use of org.ovirt.engine.ui.uicommonweb.models.ListModel in project ovirt-engine by oVirt.

the class VmSnapshotCustomPreviewPopupWidget method edit.

@Override
public void edit(PreviewSnapshotModel model) {
    driver.edit(model);
    previewSnapshotModel = model;
    snapshotInfoContainer.add(vmSnapshotInfoPanel);
    previewTable.asEditor().edit(previewSnapshotModel.getSnapshots());
    // Add selection listener
    model.getSnapshots().getSelectedItemChangedEvent().addListener((ev, sender, args) -> {
        ListModel snapshots = (ListModel) sender;
        SnapshotModel snapshotModel = (SnapshotModel) snapshots.getSelectedItem();
        if (snapshotModel != null) {
            vmSnapshotInfoPanel.updatePanel(snapshotModel);
        }
    });
    model.getSnapshots().getItemsChangedEvent().addListener((ev, sender, args) -> createPreviewTable());
}
Also used : ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) PreviewSnapshotModel(org.ovirt.engine.ui.uicommonweb.models.vms.PreviewSnapshotModel) SnapshotModel(org.ovirt.engine.ui.uicommonweb.models.vms.SnapshotModel)

Example 38 with ListModel

use of org.ovirt.engine.ui.uicommonweb.models.ListModel in project ovirt-engine by oVirt.

the class VmSnapshotCustomPreviewPopupWidget method createPreviewTable.

private void createPreviewTable() {
    previewTable.addColumn(new AbstractFullDateTimeColumn<SnapshotModel>() {

        @Override
        protected Date getRawValue(SnapshotModel snapshotModel) {
            return snapshotModel.getEntity().getCreationDate();
        }
    }, constants.dateSnapshot(), // $NON-NLS-1$
    "140px");
    previewTable.addColumn(new AbstractTextColumn<SnapshotModel>() {

        @Override
        public String getValue(SnapshotModel snapshotModel) {
            return snapshotModel.getEntity().getDescription();
        }
    }, constants.descriptionSnapshot(), // $NON-NLS-1$
    "100px");
    previewTable.setSelectionModel(new NoSelectionModel());
    Column<SnapshotModel, Boolean> vmConfColumn = new Column<SnapshotModel, Boolean>(new RadioboxCell()) {

        @Override
        public Boolean getValue(SnapshotModel model) {
            Snapshot snapshotVmConf = model.getEntity();
            Snapshot toPreviewVmConf = previewSnapshotModel.getSnapshotModel().getEntity();
            if (snapshotVmConf == null && toPreviewVmConf == null) {
                return true;
            }
            return snapshotVmConf != null && snapshotVmConf.equals(toPreviewVmConf);
        }

        @Override
        public void render(Context context, SnapshotModel snapshotModel, SafeHtmlBuilder sb) {
            if (!snapshotModel.getEntity().isVmConfigurationBroken()) {
                super.render(context, snapshotModel, sb);
            } else {
                sb.appendEscaped(constants.notAvailableLabel());
            }
        }
    };
    vmConfColumn.setFieldUpdater((index, snapshotModel, value) -> {
        previewSnapshotModel.setSnapshotModel(snapshotModel);
        previewSnapshotModel.clearMemorySelection();
        updateWarnings();
        refreshTable(previewTable);
        if (snapshotModel.getVm() == null) {
            snapshotModel.updateVmConfiguration(returnValue -> updateInfoPanel());
        } else {
            updateInfoPanel();
        }
    });
    previewTable.addColumn(vmConfColumn, new ImageResourceHeader(resources.vmConfIcon(), SafeHtmlUtils.fromTrustedString(constants.vmConfiguration())), // $NON-NLS-1$
    "30px");
    AbstractCheckboxColumn<SnapshotModel> memoryColumn = new AbstractCheckboxColumn<SnapshotModel>((index, snapshotModel, value) -> {
        previewSnapshotModel.getSnapshotModel().getMemory().setEntity(value);
        refreshTable(previewTable);
        updateWarnings();
    }) {

        @Override
        public Boolean getValue(SnapshotModel snapshotModel) {
            return snapshotModel.getMemory().getEntity();
        }

        @Override
        protected boolean canEdit(SnapshotModel snapshotModel) {
            boolean containsMemory = snapshotModel.getEntity().containsMemory();
            SnapshotModel selectedSnapshotModel = previewSnapshotModel.getSnapshotModel();
            return containsMemory && snapshotModel == selectedSnapshotModel;
        }

        @Override
        public void render(Context context, SnapshotModel snapshotModel, SafeHtmlBuilder sb) {
            if (snapshotModel.getEntity().containsMemory()) {
                super.render(context, snapshotModel, sb);
            } else {
                sb.appendEscaped(constants.notAvailableLabel());
            }
        }
    };
    previewTable.addColumn(memoryColumn, templates.iconWithText(imageResourceToSafeHtml(resources.memorySmallIcon()), constants.memorySnapshot()), // $NON-NLS-1$
    "100px");
    AbstractCheckboxColumn<SnapshotModel> vmLeaseColumn = new AbstractCheckboxColumn<SnapshotModel>((index, snapshotModel, value) -> {
        snapshotModel.getLeaseExists().setEntity(value);
        refreshTable(previewTable);
        updateWarnings();
    }) {

        @Override
        public Boolean getValue(SnapshotModel model) {
            if (model.getLeaseExists() != null) {
                return model.getLeaseExists().getEntity();
            }
            return false;
        }

        @Override
        protected boolean canEdit(SnapshotModel snapshotModel) {
            // prevent from selecting more then one leases in case many snapshots have leases
            if (snapshotModel.getLeaseExists() != null) {
                SnapshotModel result = previewSnapshotModel.getSnapshots().getItems().stream().filter(model -> model.getEntity().getId() != snapshotModel.getEntity().getId()).filter(model -> model.getLeaseExists().getEntity() != null).filter(model -> model.getLeaseExists().getEntity()).findFirst().orElse(null);
                return result == null;
            }
            return false;
        }

        @Override
        public void render(Context context, SnapshotModel snapshotModel, SafeHtmlBuilder sb) {
            if (snapshotModel.getLeaseExists().getEntity() != null) {
                super.render(context, snapshotModel, sb);
            } else {
                sb.appendEscaped(constants.notAvailableLabel());
            }
        }
    };
    // $NON-NLS-1$
    previewTable.addColumn(vmLeaseColumn, constants.leaseSnapshot(), "80px");
    List<DiskImage> disks = previewSnapshotModel.getAllDisks();
    Collections.sort(disks, new DiskByDiskAliasComparator());
    for (final DiskImage disk : disks) {
        previewTable.addColumn(new AbstractCheckboxColumn<SnapshotModel>((index, snapshotModel, value) -> {
            ListModel diskListModel = previewSnapshotModel.getDiskSnapshotsMap().get(disk.getId());
            DiskImage image = snapshotModel.getImageByDiskId(disk.getId());
            diskListModel.setSelectedItem(Boolean.TRUE.equals(value) ? image : null);
            refreshTable(previewTable);
            updateWarnings();
            updateInfoPanel();
        }) {

            @Override
            public Boolean getValue(SnapshotModel snapshotModel) {
                ListModel diskListModel = previewSnapshotModel.getDiskSnapshotsMap().get(disk.getId());
                DiskImage image = snapshotModel.getImageByDiskId(disk.getId());
                return image != null ? image.equals(diskListModel.getSelectedItem()) : false;
            }

            @Override
            protected boolean canEdit(SnapshotModel model) {
                return true;
            }

            @Override
            public void render(Context context, SnapshotModel snapshotModel, SafeHtmlBuilder sb) {
                DiskImage image = snapshotModel.getImageByDiskId(disk.getId());
                if (image == null) {
                    sb.appendEscaped(constants.notAvailableLabel());
                } else if (image.getImageStatus() == ImageStatus.ILLEGAL) {
                    sb.append(templates.text(constants.notAvailableLabel()));
                } else {
                    super.render(context, snapshotModel, sb);
                }
            }

            @Override
            public SafeHtml getTooltip(SnapshotModel model) {
                if (disk != null && disk.getId() != null) {
                    DiskImage image = model.getImageByDiskId(disk.getId());
                    if (image != null && image.getImageStatus() == ImageStatus.ILLEGAL) {
                        return SafeHtmlUtils.fromSafeConstant(constants.illegalStatus());
                    }
                }
                return null;
            }
        }, new SafeHtmlHeader(templates.iconWithText(imageResourceToSafeHtml(resources.diskIcon()), disk.getDiskAlias()), SafeHtmlUtils.fromString(disk.getId().toString())), // $NON-NLS-1$
        "120px");
        // Edit preview table
        previewTable.asEditor().edit(previewSnapshotModel.getSnapshots());
    }
    previewTable.addCellPreviewHandler(new CellPreviewEvent.Handler<EntityModel>() {

        long lastClick = -1000;

        @Override
        public void onCellPreview(CellPreviewEvent<EntityModel> event) {
            NativeEvent nativeEvent = event.getNativeEvent();
            long clickAt = System.currentTimeMillis();
            if (BrowserEvents.CLICK.equals(nativeEvent.getType())) {
                if (clickAt - lastClick < 300) {
                    // double click: 2 clicks detected within 300 ms
                    SnapshotModel selectedSnapshotModel = (SnapshotModel) event.getValue();
                    if (!selectedSnapshotModel.getEntity().isVmConfigurationBroken()) {
                        previewSnapshotModel.clearSelection(selectedSnapshotModel.getEntity().getId());
                        previewSnapshotModel.selectSnapshot(selectedSnapshotModel.getEntity().getId());
                        updateWarnings();
                        refreshTable(previewTable);
                    }
                }
                lastClick = System.currentTimeMillis();
            }
        }
    });
}
Also used : CommonApplicationConstants(org.ovirt.engine.ui.common.CommonApplicationConstants) PreviewSnapshotModel(org.ovirt.engine.ui.uicommonweb.models.vms.PreviewSnapshotModel) AbstractCheckboxColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractCheckboxColumn) BrowserEvents(com.google.gwt.dom.client.BrowserEvents) ImageResource(com.google.gwt.resources.client.ImageResource) EntityModelCellTable(org.ovirt.engine.ui.common.widget.editor.EntityModelCellTable) Date(java.util.Date) DiskByDiskAliasComparator(org.ovirt.engine.core.common.businessentities.comparators.DiskByDiskAliasComparator) GWT(com.google.gwt.core.client.GWT) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) HTML(com.google.gwt.user.client.ui.HTML) NativeEvent(com.google.gwt.dom.client.NativeEvent) ArrayList(java.util.ArrayList) ImageStatus(org.ovirt.engine.core.common.businessentities.storage.ImageStatus) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) UiBinder(com.google.gwt.uibinder.client.UiBinder) CellPreviewEvent(com.google.gwt.view.client.CellPreviewEvent) Label(com.google.gwt.user.client.ui.Label) Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) AssetProvider(org.ovirt.engine.ui.common.gin.AssetProvider) NoSelectionModel(com.google.gwt.view.client.NoSelectionModel) Context(com.google.gwt.cell.client.Cell.Context) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) AbstractImagePrototype(com.google.gwt.user.client.ui.AbstractImagePrototype) SafeHtmlUtils(com.google.gwt.safehtml.shared.SafeHtmlUtils) SplitLayoutPanel(com.google.gwt.user.client.ui.SplitLayoutPanel) CommonApplicationTemplates(org.ovirt.engine.ui.common.CommonApplicationTemplates) SimplePanel(com.google.gwt.user.client.ui.SimplePanel) CommonApplicationResources(org.ovirt.engine.ui.common.CommonApplicationResources) AbstractFullDateTimeColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractFullDateTimeColumn) ElementIdHandler(org.ovirt.engine.ui.common.idhandler.ElementIdHandler) AbstractModelBoundPopupWidget(org.ovirt.engine.ui.common.widget.uicommon.popup.AbstractModelBoundPopupWidget) UiCommonEditorDriver(org.ovirt.engine.ui.common.editor.UiCommonEditorDriver) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) SnapshotModel(org.ovirt.engine.ui.uicommonweb.models.vms.SnapshotModel) RadioboxCell(org.ovirt.engine.ui.common.widget.table.cell.RadioboxCell) List(java.util.List) FlowPanel(com.google.gwt.user.client.ui.FlowPanel) Column(com.google.gwt.user.cellview.client.Column) UiField(com.google.gwt.uibinder.client.UiField) AbstractTextColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractTextColumn) VmSnapshotInfoPanel(org.ovirt.engine.ui.common.widget.uicommon.vm.VmSnapshotInfoPanel) SafeHtmlHeader(org.ovirt.engine.ui.common.widget.table.header.SafeHtmlHeader) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) Collections(java.util.Collections) ImageResourceHeader(org.ovirt.engine.ui.common.widget.table.header.ImageResourceHeader) ImageResourceHeader(org.ovirt.engine.ui.common.widget.table.header.ImageResourceHeader) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) AbstractCheckboxColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractCheckboxColumn) AbstractFullDateTimeColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractFullDateTimeColumn) Column(com.google.gwt.user.cellview.client.Column) AbstractTextColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractTextColumn) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Context(com.google.gwt.cell.client.Cell.Context) NoSelectionModel(com.google.gwt.view.client.NoSelectionModel) RadioboxCell(org.ovirt.engine.ui.common.widget.table.cell.RadioboxCell) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) AbstractCheckboxColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractCheckboxColumn) PreviewSnapshotModel(org.ovirt.engine.ui.uicommonweb.models.vms.PreviewSnapshotModel) SnapshotModel(org.ovirt.engine.ui.uicommonweb.models.vms.SnapshotModel) Date(java.util.Date) CellPreviewEvent(com.google.gwt.view.client.CellPreviewEvent) DiskByDiskAliasComparator(org.ovirt.engine.core.common.businessentities.comparators.DiskByDiskAliasComparator) SafeHtmlHeader(org.ovirt.engine.ui.common.widget.table.header.SafeHtmlHeader) Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Example 39 with ListModel

use of org.ovirt.engine.ui.uicommonweb.models.ListModel in project ovirt-engine by oVirt.

the class ImportIscsiStorageView method addTargetsSelectionColumn.

private void addTargetsSelectionColumn() {
    AbstractSelectAllCheckBoxHeader<SanTargetModel> selectAllHeader = new AbstractSelectAllCheckBoxHeader<SanTargetModel>() {

        @Override
        protected void selectionChanged(Boolean value) {
            ListModel listModel = targetsTable.asEditor().flush();
            if (listModel == null || listModel.getItems() == null) {
                return;
            }
            handleSelection(value, listModel, targetsTable.getSelectionModel());
        }

        @Override
        public void handleSelection(Boolean value, ListModel listModel, SelectionModel selectionModel) {
            if (!listModel.getItems().iterator().hasNext()) {
                return;
            }
            ArrayList<SanTargetModel> selectedItems = new ArrayList<>();
            for (SanTargetModel entity : (Iterable<SanTargetModel>) listModel.getItems()) {
                if (!entity.getIsLoggedIn()) {
                    if (value) {
                        selectedItems.add(entity);
                    }
                    selectionModel.setSelected(entity, value);
                }
            }
            listModel.setSelectedItems(selectedItems);
        }

        @Override
        public Boolean getValue() {
            ListModel listModel = targetsTable.asEditor().flush();
            if (listModel == null || listModel.getItems() == null) {
                return false;
            }
            return getCheckValue(listModel.getItems(), targetsTable.getSelectionModel());
        }
    };
    AbstractCheckboxColumn<SanTargetModel> checkColumn = new AbstractCheckboxColumn<SanTargetModel>() {

        @Override
        protected boolean canEdit(SanTargetModel object) {
            return !object.getIsLoggedIn();
        }

        @Override
        public Boolean getValue(SanTargetModel object) {
            return targetsTable.getSelectionModel().isSelected(object) || object.getIsLoggedIn();
        }
    };
    // $NON-NLS-1$
    targetsTable.addColumn(checkColumn, selectAllHeader, "25px");
}
Also used : AbstractSelectAllCheckBoxHeader(org.ovirt.engine.ui.common.widget.table.header.AbstractSelectAllCheckBoxHeader) SanTargetModel(org.ovirt.engine.ui.uicommonweb.models.storage.SanTargetModel) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) ArrayList(java.util.ArrayList) SelectionModel(com.google.gwt.view.client.SelectionModel) MultiSelectionModel(com.google.gwt.view.client.MultiSelectionModel) AbstractCheckboxColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractCheckboxColumn)

Example 40 with ListModel

use of org.ovirt.engine.ui.uicommonweb.models.ListModel in project ovirt-engine by oVirt.

the class SanStorageLunToTargetList method createLeafNode.

@SuppressWarnings("unchecked")
@Override
protected TreeItem createLeafNode(ListModel leafModel) {
    if (hideLeaf) {
        return null;
    }
    EntityModelCellTable<ListModel<LunModel>> table = new EntityModelCellTable<>(false, (Resources) GWT.create(SanStorageListTargetTableResources.class), true);
    table.enableColumnResizing();
    table.addColumn(new TextColumn<SanTargetModel>() {

        @Override
        public String getValue(SanTargetModel model) {
            return model.getName();
        }
    }, constants.targetNameSanStorage(), // $NON-NLS-1$
    "500px");
    table.addColumn(new TextColumn<SanTargetModel>() {

        @Override
        public String getValue(SanTargetModel model) {
            return model.getAddress();
        }
    }, constants.addressSanStorage(), // $NON-NLS-1$
    "100px");
    table.addColumn(new TextColumn<SanTargetModel>() {

        @Override
        public String getValue(SanTargetModel model) {
            return model.getPort();
        }
    }, constants.portSanStorage(), // $NON-NLS-1$
    "80px");
    List<SanTargetModel> items = (List<SanTargetModel>) leafModel.getItems();
    if (items.isEmpty()) {
        return null;
    }
    table.setRowData(items);
    Object selectedItem = leafModel.getSelectedItem();
    leafModel.setSelectedItem(null);
    table.asEditor().edit(leafModel);
    leafModel.setSelectedItem(selectedItem);
    // $NON-NLS-1$
    table.setWidth("100%");
    TreeItem item = new TreeItem(table);
    addOpenHandlerToTree(tree, item, table);
    return item;
}
Also used : EntityModelCellTable(org.ovirt.engine.ui.common.widget.editor.EntityModelCellTable) SanTargetModel(org.ovirt.engine.ui.uicommonweb.models.storage.SanTargetModel) TreeItem(com.google.gwt.user.client.ui.TreeItem) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ListModel (org.ovirt.engine.ui.uicommonweb.models.ListModel)43 ArrayList (java.util.ArrayList)29 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)19 List (java.util.List)17 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)11 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)11 SearchableListModel (org.ovirt.engine.ui.uicommonweb.models.SearchableListModel)9 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)8 EntityModelCellTable (org.ovirt.engine.ui.common.widget.editor.EntityModelCellTable)8 AsyncDataProvider (org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider)8 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)7 TreeItem (com.google.gwt.user.client.ui.TreeItem)6 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)6 Model (org.ovirt.engine.ui.uicommonweb.models.Model)6 Provider (org.ovirt.engine.core.common.businessentities.Provider)5 QueryType (org.ovirt.engine.core.common.queries.QueryType)5 PropertyChangedEventArgs (org.ovirt.engine.ui.uicompat.PropertyChangedEventArgs)5 Collections (java.util.Collections)4 ApplicationMode (org.ovirt.engine.core.common.mode.ApplicationMode)4 Linq (org.ovirt.engine.ui.uicommonweb.Linq)4