Search in sources :

Example 31 with EntityModel

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

the class RegisterEntityInfoPanel method initAppsTable.

protected void initAppsTable() {
    appsTable = new EntityModelCellTable<>(false, true);
    AbstractTextColumn<String> appNameColumn = new AbstractTextColumn<String>() {

        @Override
        public String getValue(String appName) {
            return appName;
        }
    };
    appsTable.addColumn(appNameColumn, constants.nameSnapshot());
    appsTable.setRowData(new ArrayList<EntityModel>());
    // $NON-NLS-1$
    appsTable.setWidth("100%");
    appsTable.setSelectionModel(new NoSelectionModel());
    appsTable.setEmptyTableWidget(new NoItemsLabel());
}
Also used : NoItemsLabel(org.ovirt.engine.ui.common.widget.label.NoItemsLabel) NoSelectionModel(com.google.gwt.view.client.NoSelectionModel) AbstractTextColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractTextColumn) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) RegisterEntityModel(org.ovirt.engine.ui.uicommonweb.models.storage.RegisterEntityModel)

Example 32 with EntityModel

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

the class EntityModelCellTable method addSelectionChangeHandler.

public void addSelectionChangeHandler() {
    // Handle selection
    getSelectionModel().addSelectionChangeHandler(new Handler() {

        @Override
        public void onSelectionChange(SelectionChangeEvent event) {
            if (getListModel() == null || getListModel().getItems() == null) {
                return;
            }
            // Clear "IsSelected"
            for (EntityModel entity : (List<EntityModel>) getListModel().getItems()) {
                entity.setIsSelected(false);
            }
            // Set "IsSelected"
            SelectionModel<? super EntityModel> selectionModel = EntityModelCellTable.this.getSelectionModel();
            if (selectionModel instanceof SingleSelectionModel) {
                EntityModel selectedObject = ((SingleSelectionModel<EntityModel>) selectionModel).getSelectedObject();
                clearCurrentSelectedItems();
                if (selectedObject != null) {
                    selectedObject.setIsSelected(true);
                    getListModel().setSelectedItem(selectedObject);
                }
            } else if (selectionModel instanceof MultiSelectionModel) {
                List<EntityModel> selectedItems = new ArrayList<>();
                for (EntityModel entity : ((MultiSelectionModel<EntityModel>) selectionModel).getSelectedSet()) {
                    entity.setIsSelected(true);
                    selectedItems.add(entity);
                }
                clearCurrentSelectedItems();
                getListModel().setSelectedItems(selectedItems);
            }
        }

        private void clearCurrentSelectedItems() {
            getListModel().setSelectedItems(null);
            getListModel().setSelectedItem(null);
        }
    });
}
Also used : SingleSelectionModel(com.google.gwt.view.client.SingleSelectionModel) MultiSelectionModel(com.google.gwt.view.client.MultiSelectionModel) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) ArrayList(java.util.ArrayList) Handler(com.google.gwt.view.client.SelectionChangeEvent.Handler) SingleSelectionModel(com.google.gwt.view.client.SingleSelectionModel) SelectionModel(com.google.gwt.view.client.SelectionModel) NoSelectionModel(com.google.gwt.view.client.NoSelectionModel) MultiSelectionModel(com.google.gwt.view.client.MultiSelectionModel) SelectionChangeEvent(com.google.gwt.view.client.SelectionChangeEvent)

Example 33 with EntityModel

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

the class EntityModelCellTable method addCheckBoxColumn.

private void addCheckBoxColumn(boolean hideCheckbox, boolean showSelectAllCheckbox) {
    if (!hideCheckbox) {
        // Add selection column
        Column<EntityModel, Boolean> checkColumn = null;
        if (getSelectionModel() instanceof SingleSelectionModel) {
            checkColumn = new Column<EntityModel, Boolean>(new RadioboxCell(true, false)) {

                @Override
                public Boolean getValue(EntityModel object) {
                    return getSelectionModel().isSelected(object);
                }
            };
            addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant(constants.htmlNonBreakingSpace()));
        } else if (getSelectionModel() instanceof MultiSelectionModel) {
            checkColumn = new Column<EntityModel, Boolean>(new CheckboxCell(true, false)) {

                @Override
                public Boolean getValue(EntityModel object) {
                    return getSelectionModel().isSelected(object);
                }
            };
            if (showSelectAllCheckbox) {
                AbstractSelectAllCheckBoxHeader<EntityModel> selectAllHeader = new AbstractSelectAllCheckBoxHeader<EntityModel>() {

                    @Override
                    protected void selectionChanged(Boolean value) {
                        if (getListModel() == null || getListModel().getItems() == null) {
                            return;
                        }
                        handleSelection(value, getListModel(), getSelectionModel());
                    }

                    @Override
                    public Boolean getValue() {
                        if (getListModel() == null || getListModel().getItems() == null) {
                            return false;
                        }
                        return getCheckValue(getListModel().getItems(), getSelectionModel());
                    }
                };
                addColumn(checkColumn, selectAllHeader);
            } else {
                addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant(constants.htmlNonBreakingSpace()));
            }
        }
        if (checkColumn != null) {
            setColumnWidth(checkColumn, CHECK_COLUMN_WIDTH, Unit.PX);
            selectionColumnPresent = true;
        }
        addCellPreviewHandler(event -> {
            int columnIndex = event.getColumn();
            Cell<?> cell = getColumn(columnIndex).getCell();
            if (cell instanceof EventHandlingCell && ((EventHandlingCell) cell).handlesEvent(event)) {
                return;
            }
            if (BrowserEvents.CLICK.equals(event.getNativeEvent().getType()) && !(getSelectionModel() instanceof NoSelectionModel)) {
                // Let the selection column deal with this
                if (event.getColumn() == 0) {
                    return;
                }
                getSelectionModel().setSelected(event.getValue(), !getSelectionModel().isSelected(event.getValue()));
            }
        });
    }
}
Also used : SingleSelectionModel(com.google.gwt.view.client.SingleSelectionModel) MultiSelectionModel(com.google.gwt.view.client.MultiSelectionModel) NoSelectionModel(com.google.gwt.view.client.NoSelectionModel) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) RadioboxCell(org.ovirt.engine.ui.common.widget.table.cell.RadioboxCell) AbstractSelectAllCheckBoxHeader(org.ovirt.engine.ui.common.widget.table.header.AbstractSelectAllCheckBoxHeader) Column(com.google.gwt.user.cellview.client.Column) EventHandlingCell(org.ovirt.engine.ui.common.widget.table.cell.EventHandlingCell) CheckboxCell(org.ovirt.engine.ui.common.widget.table.cell.CheckboxCell)

Example 34 with EntityModel

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

the class VmDiskAttachPopupWidget method getReadOnlyCheckBoxColumn.

private AbstractCheckboxColumn<EntityModel> getReadOnlyCheckBoxColumn() {
    AbstractCheckboxColumn<EntityModel> readOnlyCheckboxColumn = new AbstractCheckboxColumn<EntityModel>((idx, object, value) -> {
        DiskModel diskModel = (DiskModel) object.getEntity();
        diskModel.setReadOnly(value);
    }) {

        @Override
        protected boolean canEdit(EntityModel object) {
            DiskModel diskModel = (DiskModel) object.getEntity();
            Disk disk = diskModel.getDisk();
            boolean isScsiPassthrough = disk.isScsiPassthrough();
            boolean ideLimitation = diskModel.getDiskInterface().getSelectedItem() == DiskInterface.IDE;
            return !isScsiPassthrough && !ideLimitation;
        }

        @Override
        public Boolean getValue(EntityModel object) {
            DiskModel diskModel = (DiskModel) object.getEntity();
            return diskModel.isReadOnly();
        }
    };
    return readOnlyCheckboxColumn;
}
Also used : AttachDiskModel(org.ovirt.engine.ui.uicommonweb.models.vms.AttachDiskModel) DiskModel(org.ovirt.engine.ui.uicommonweb.models.vms.DiskModel) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) AbstractCheckboxColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractCheckboxColumn) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk)

Example 35 with EntityModel

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

the class VmDiskAttachPopupWidget method edit.

@Override
public void edit(final AttachDiskModel disk) {
    driver.edit(disk);
    if (!isNewLunDiskEnabled) {
        disk.getDiskStorageType().setEntity(DiskStorageType.IMAGE);
    }
    revealDiskPanel(disk);
    diskTypePanel.addRadioButton(constants.imageDisk(), disk.getIsNew() || disk.getDisk().getDiskStorageType() == DiskStorageType.IMAGE, disk.getIsNew(), event -> {
        if (disk.getIsNew()) {
            disk.getDiskStorageType().setEntity(DiskStorageType.IMAGE);
            revealDiskPanel(disk);
        }
    });
    diskTypePanel.addRadioButton(constants.directLunDisk(), !disk.getIsNew() && disk.getDisk().getDiskStorageType() == DiskStorageType.LUN, disk.getIsNew(), event -> {
        if (disk.getIsNew()) {
            disk.getDiskStorageType().setEntity(DiskStorageType.LUN);
            revealDiskPanel(disk);
        }
    });
    diskTypePanel.addRadioButton(constants.cinderDisk(), !disk.getIsNew() && disk.getDisk().getDiskStorageType() == DiskStorageType.CINDER, disk.getIsNew(), event -> {
        if (disk.getIsNew()) {
            disk.getDiskStorageType().setEntity(DiskStorageType.CINDER);
            revealDiskPanel(disk);
        }
    });
    // Add event handlers
    disk.getPropertyChangedEvent().addListener((ev, sender, args) -> {
        String propName = args.propertyName;
        if (propName.equals("IsValid")) {
            // $NON-NLS-1$
            if (disk.getIsValid()) {
                attachDiskPanel.markAsValid();
            } else {
                attachDiskPanel.markAsInvalid(disk.getInvalidityReasons());
            }
        } else if ("Message".equals(propName)) {
            // $NON-NLS-1$
            if (StringHelper.isNotNullOrEmpty(disk.getMessage())) {
                messageLabel.setHTML(wrapInUnorderedList(disk.getMessage()));
            } else {
                // $NON-NLS-1$
                messageLabel.setHTML("");
            }
        }
    });
    disk.getWarningLabel().getPropertyChangedEvent().addListener((ev, sender, args) -> {
        EntityModel ownerModel = (EntityModel) sender;
        String propName = args.propertyName;
        if ("IsAvailable".equals(propName)) {
            // $NON-NLS-1$
            warningLabel.setVisible(ownerModel.getIsAvailable());
        }
    });
    disk.getWarningLabel().getEntityChangedEvent().addListener((ev, sender, args) -> warningLabel.setHTML(wrapInUnorderedList(disk.getWarningLabel().getEntity())));
    revealDiskPanel(disk);
}
Also used : EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel)

Aggregations

EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)105 ArrayList (java.util.ArrayList)56 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)27 List (java.util.List)26 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)23 AsyncDataProvider (org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider)22 ListModel (org.ovirt.engine.ui.uicommonweb.models.ListModel)22 ConstantsManager (org.ovirt.engine.ui.uicompat.ConstantsManager)22 ConfirmationModel (org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)20 HelpTag (org.ovirt.engine.ui.uicommonweb.help.HelpTag)19 ActionType (org.ovirt.engine.core.common.action.ActionType)18 Frontend (org.ovirt.engine.ui.frontend.Frontend)18 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)17 Guid (org.ovirt.engine.core.compat.Guid)17 PropertyChangedEventArgs (org.ovirt.engine.ui.uicompat.PropertyChangedEventArgs)17 VDS (org.ovirt.engine.core.common.businessentities.VDS)16 QueryType (org.ovirt.engine.core.common.queries.QueryType)16 NoSelectionModel (com.google.gwt.view.client.NoSelectionModel)13 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)13 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)13