Search in sources :

Example 1 with SafeHtmlHeader

use of org.ovirt.engine.ui.common.widget.table.header.SafeHtmlHeader in project ovirt-engine by oVirt.

the class ColumnResizeCellTable method addColumnImpl.

private void addColumnImpl(Column<T, ?> column, Header<?> header) {
    // build resizable headers, if necessary
    if (columnResizingEnabled && header instanceof AbstractCheckboxHeader) {
        header = createResizableCheckboxHeader(header, column);
    } else if (columnResizingEnabled) {
        header = createResizableHeader(column, header);
    } else if (applyHeaderStyle && header instanceof SafeHtmlHeader) {
        SafeHtmlHeader safeHtmlHeader = (SafeHtmlHeader) header;
        // not using Resizeable header, but still want it to look that way.
        // nonResizeableColumnHeader does that.
        // TODO nonResizeableColumnHeader copy-pastes CSS. fix.
        SafeHtml newValue = templates.nonResizeableColumnHeader(safeHtmlHeader.getValue());
        header = new SafeHtmlHeader(newValue, safeHtmlHeader.getTooltip());
    }
    // actually add the column
    super.addColumn(column, header);
    // Add empty no-width column as the last column
    if (columnResizingEnabled) {
        if (isColumnPresent(emptyNoWidthColumn)) {
            removeColumn(emptyNoWidthColumn);
        }
        super.addColumn(emptyNoWidthColumn, emptyNoWidthColumnHeader);
    }
    // Add column to header context menu
    if (header instanceof AbstractHeader) {
        ((AbstractHeader) header).setContextMenuHandler(ensureContextMenuHandler());
        contextPopup.getContextMenu().addItem(column);
    }
}
Also used : SafeHtmlHeader(org.ovirt.engine.ui.common.widget.table.header.SafeHtmlHeader) AbstractHeader(org.ovirt.engine.ui.common.widget.table.header.AbstractHeader) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) AbstractCheckboxHeader(org.ovirt.engine.ui.common.widget.table.header.AbstractCheckboxHeader)

Example 2 with SafeHtmlHeader

use of org.ovirt.engine.ui.common.widget.table.header.SafeHtmlHeader in project ovirt-engine by oVirt.

the class ClusterManageNetworkPopupView method initEntityModelCellTable.

private void initEntityModelCellTable() {
    boolean multiCluster = networks.asEditor().flush().isMultiCluster();
    // $NON-NLS-1$
    networks.addColumn(new NetworkNameTextColumnWithTooltip(), constants.nameNetwork(), "85px");
    networks.addColumn(new AttachedIndicatorCheckboxColumn(new AttachedIndicatorFieldUpdater()), new AttachedIndicatorCheckboxHeader(), // $NON-NLS-1$
    "90px");
    networks.addColumn(new RequiredIndicatorCheckboxColumn(new RequiredIndicatorFieldUpdater()), new RequiredAllCheckboxHeader(), // $NON-NLS-1$
    "110px");
    networks.addColumn(new VmNetworkImageSafeHtmlWithSafeHtmlTooltipColumn(), constants.vmNetwork(), // $NON-NLS-1$
    "80px");
    networks.addColumn(new ManagementNetworkIndicatorCheckboxColumn(multiCluster, new ManagementNetworkIndicatorFieldUpdater()), constants.managementItemInfo(), // $NON-NLS-1$
    "100px");
    networks.addColumn(new DisplayNetworkIndicatorCheckboxColumn(multiCluster, new DisplayNetworkIndicatorFieldUpdater()), new SafeHtmlHeader(SafeHtmlUtils.fromSafeConstant(constants.displayNetwork()), SafeHtmlUtils.fromSafeConstant(constants.changeDisplayNetworkWarning())), // $NON-NLS-1$
    "120px");
    networks.addColumn(new MigrationNetworkIndicatorCheckboxColumn(multiCluster, new MigrationNetworkIndicatorFieldUpdater()), constants.migrationNetwork(), // $NON-NLS-1$
    "125px");
    networks.addColumn(new GlusterNetworkIndicatorCheckboxColumn(multiCluster, new GlusterNetworkIndicatorFieldUpdater()), constants.glusterNetwork(), // $NON-NLS-1$
    "120px");
    networks.addColumn(new DefaultRouteNetworkIndicatorCheckboxColumn(multiCluster, new DefaultRouteNetworkIndicatorFieldUpdater()), constants.defaultRouteNetwork(), // $NON-NLS-1$
    "120px");
}
Also used : SafeHtmlHeader(org.ovirt.engine.ui.common.widget.table.header.SafeHtmlHeader)

Example 3 with SafeHtmlHeader

use of org.ovirt.engine.ui.common.widget.table.header.SafeHtmlHeader 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)

Aggregations

SafeHtmlHeader (org.ovirt.engine.ui.common.widget.table.header.SafeHtmlHeader)3 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)2 Context (com.google.gwt.cell.client.Cell.Context)1 GWT (com.google.gwt.core.client.GWT)1 BrowserEvents (com.google.gwt.dom.client.BrowserEvents)1 NativeEvent (com.google.gwt.dom.client.NativeEvent)1 ImageResource (com.google.gwt.resources.client.ImageResource)1 SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)1 SafeHtmlUtils (com.google.gwt.safehtml.shared.SafeHtmlUtils)1 UiBinder (com.google.gwt.uibinder.client.UiBinder)1 UiField (com.google.gwt.uibinder.client.UiField)1 Column (com.google.gwt.user.cellview.client.Column)1 AbstractImagePrototype (com.google.gwt.user.client.ui.AbstractImagePrototype)1 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)1 HTML (com.google.gwt.user.client.ui.HTML)1 Label (com.google.gwt.user.client.ui.Label)1 SimplePanel (com.google.gwt.user.client.ui.SimplePanel)1 SplitLayoutPanel (com.google.gwt.user.client.ui.SplitLayoutPanel)1 CellPreviewEvent (com.google.gwt.view.client.CellPreviewEvent)1 NoSelectionModel (com.google.gwt.view.client.NoSelectionModel)1