Search in sources :

Example 6 with AbstractCheckboxColumn

use of org.ovirt.engine.ui.common.widget.table.column.AbstractCheckboxColumn in project ovirt-engine by oVirt.

the class GlusterVolumeGeoReplicationSessionConfigPopupView method initConfigTable.

private void initConfigTable() {
    geoReplicationConfigTable = new EntityModelCellTable<>(false, true);
    geoReplicationConfigTable.setSelectionModel(new NoSelectionModel());
    geoReplicationConfigTable.addColumn(new AbstractEntityModelTextColumn<Pair<Boolean, GlusterGeoRepSessionConfiguration>>() {

        @Override
        protected String getText(Pair<Boolean, GlusterGeoRepSessionConfiguration> entity) {
            return entity.getSecond().getKey();
        }
    }, constants.optionKeyVolumeParameter(), // $NON-NLS-1$
    "150px");
    geoReplicationConfigTable.addColumn(new AbstractScrollableTextColumn<EntityModel<Pair<Boolean, GlusterGeoRepSessionConfiguration>>>() {

        @Override
        public String getValue(EntityModel<Pair<Boolean, GlusterGeoRepSessionConfiguration>> object) {
            return object.getEntity().getSecond().getDescription() == null ? constants.notAvailableLabel() : object.getEntity().getSecond().getDescription();
        }
    }, constants.descriptionVolumeParameter(), // $NON-NLS-1$
    "300px");
    geoReplicationConfigTable.addColumn(new GlusterConfigAwareColumn(), constants.optionValueVolumeParameter(), // $NON-NLS-1$
    "200px");
    geoReplicationConfigTable.addColumn(new AbstractCheckboxColumn<EntityModel<Pair<Boolean, GlusterGeoRepSessionConfiguration>>>(true, (index, object, value) -> object.getEntity().setFirst(value)) {

        @Override
        protected boolean canEdit(EntityModel<Pair<Boolean, GlusterGeoRepSessionConfiguration>> object) {
            return true;
        }

        @Override
        public Boolean getValue(EntityModel<Pair<Boolean, GlusterGeoRepSessionConfiguration>> object) {
            return object.getEntity().getFirst();
        }
    }, constants.resetGeoRepSessionConfig());
}
Also used : AbstractCheckboxColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractCheckboxColumn) EventBus(com.google.gwt.event.shared.EventBus) EntityModelCellTable(org.ovirt.engine.ui.common.widget.editor.EntityModelCellTable) AbstractEntityModelTextColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractEntityModelTextColumn) AssetProvider(org.ovirt.engine.ui.webadmin.gin.AssetProvider) ElementIdHandler(org.ovirt.engine.ui.common.idhandler.ElementIdHandler) Inject(com.google.inject.Inject) UiCommonEditorDriver(org.ovirt.engine.ui.common.editor.UiCommonEditorDriver) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) AbstractModelBoundPopupView(org.ovirt.engine.ui.common.view.popup.AbstractModelBoundPopupView) GWT(com.google.gwt.core.client.GWT) GlusterConfigAwareColumn(org.ovirt.engine.ui.common.widget.table.column.GlusterConfigAwareColumn) GlusterVolumeGeoReplicationSessionConfigModel(org.ovirt.engine.ui.uicommonweb.models.gluster.GlusterVolumeGeoReplicationSessionConfigModel) WithElementId(org.ovirt.engine.ui.common.idhandler.WithElementId) GlusterGeoRepSessionConfiguration(org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSessionConfiguration) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) UiBinder(com.google.gwt.uibinder.client.UiBinder) ApplicationConstants(org.ovirt.engine.ui.webadmin.ApplicationConstants) SimpleDialogPanel(org.ovirt.engine.ui.common.widget.dialog.SimpleDialogPanel) GlusterVolumeGeoReplicationSessionConfigPopupPresenterWidget(org.ovirt.engine.ui.webadmin.section.main.presenter.popup.gluster.GlusterVolumeGeoReplicationSessionConfigPopupPresenterWidget) UiField(com.google.gwt.uibinder.client.UiField) NoSelectionModel(com.google.gwt.view.client.NoSelectionModel) AbstractScrollableTextColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractScrollableTextColumn) Pair(org.ovirt.engine.core.common.utils.Pair) NoSelectionModel(com.google.gwt.view.client.NoSelectionModel) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) GlusterGeoRepSessionConfiguration(org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSessionConfiguration) GlusterConfigAwareColumn(org.ovirt.engine.ui.common.widget.table.column.GlusterConfigAwareColumn) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 7 with AbstractCheckboxColumn

use of org.ovirt.engine.ui.common.widget.table.column.AbstractCheckboxColumn in project ovirt-engine by oVirt.

the class AbstractNetworkPopupView method initEntityModelCellTable.

void initEntityModelCellTable() {
    AbstractCheckboxHeader assignAllHeader = new AbstractCheckboxHeader() {

        @Override
        protected void selectionChanged(Boolean value) {
            for (NetworkClusterModel networkClusterModel : getClustersTableItems()) {
                if (networkClusterModel.getIsChangable()) {
                    networkClusterModel.setAttached(value);
                    networkClusterModel.setRequired(value && networkClusterModel.isRequired());
                }
            }
            refreshClustersTable();
        }

        @Override
        public Boolean getValue() {
            for (NetworkClusterModel networkClusterModel : getClustersTableItems()) {
                if (networkClusterModel.getIsChangable() && !networkClusterModel.isAttached()) {
                    return false;
                }
            }
            return true;
        }

        @Override
        public boolean isEnabled() {
            for (NetworkClusterModel networkClusterModel : getClustersTableItems()) {
                if (networkClusterModel.getIsChangable()) {
                    return true;
                }
            }
            return false;
        }

        @Override
        public String getLabel() {
            return constants.attachAll();
        }
    };
    AbstractCheckboxHeader requiredAllHeader = new AbstractCheckboxHeader() {

        @Override
        protected void selectionChanged(Boolean value) {
            for (NetworkClusterModel networkClusterModel : getClustersTableItems()) {
                networkClusterModel.setRequired(value && networkClusterModel.isAttached());
            }
            refreshClustersTable();
        }

        @Override
        public Boolean getValue() {
            for (NetworkClusterModel networkClusterModel : getClustersTableItems()) {
                if (!networkClusterModel.isRequired()) {
                    return false;
                }
            }
            return true;
        }

        @Override
        public boolean isEnabled() {
            return isRequiredChangeable();
        }

        @Override
        public String getLabel() {
            return constants.requiredAll();
        }
    };
    clustersTable.addColumn(new AbstractTextColumn<NetworkClusterModel>() {

        @Override
        public String getValue(NetworkClusterModel model) {
            return model.getName();
        }
    }, constants.nameClusterHeader());
    clustersTable.addColumn(new AbstractCheckboxColumn<NetworkClusterModel>((index, model, value) -> {
        model.setAttached(value);
        model.setRequired(value && model.isRequired());
        refreshClustersTable();
    }) {

        @Override
        public Boolean getValue(NetworkClusterModel model) {
            return model.isAttached();
        }

        @Override
        protected boolean canEdit(NetworkClusterModel model) {
            return model.getIsChangable();
        }

        @Override
        public void render(Context context, NetworkClusterModel object, SafeHtmlBuilder sb) {
            super.render(context, object, sb);
            sb.append(templates.textForCheckBox(constants.attach()));
        }
    }, assignAllHeader, // $NON-NLS-1$
    "150px");
    clustersTable.addColumn(new AbstractCheckboxColumn<NetworkClusterModel>((index, model, value) -> {
        model.setRequired(value && model.isAttached());
        refreshClustersTable();
    }) {

        @Override
        public Boolean getValue(NetworkClusterModel model) {
            return model.isRequired();
        }

        @Override
        protected boolean canEdit(NetworkClusterModel model) {
            return isRequiredChangeable() && model.isAttached();
        }

        @Override
        public void render(Context context, NetworkClusterModel object, SafeHtmlBuilder sb) {
            super.render(context, object, sb);
            sb.append(templates.textForCheckBox(constants.required()));
        }
    }, requiredAllHeader, // $NON-NLS-1$
    "150px");
}
Also used : NetworkModel(org.ovirt.engine.ui.uicommonweb.models.datacenters.NetworkModel) EntityModelCellTable(org.ovirt.engine.ui.common.widget.editor.EntityModelCellTable) AssetProvider(org.ovirt.engine.ui.webadmin.gin.AssetProvider) VnicProfilesEditor(org.ovirt.engine.ui.webadmin.widget.vnicProfile.VnicProfilesEditor) Inject(com.google.inject.Inject) Container(org.gwtbootstrap3.client.ui.Container) Provider(org.ovirt.engine.core.common.businessentities.Provider) ApplicationMode(org.ovirt.engine.core.common.mode.ApplicationMode) Unit(com.google.gwt.dom.client.Style.Unit) HTML(com.google.gwt.user.client.ui.HTML) UiBinder(com.google.gwt.uibinder.client.UiBinder) Label(com.google.gwt.user.client.ui.Label) AbstractTabbedModelBoundPopupView(org.ovirt.engine.ui.common.view.popup.AbstractTabbedModelBoundPopupView) ListModelRadioGroupEditor(org.ovirt.engine.ui.common.widget.editor.ListModelRadioGroupEditor) Context(com.google.gwt.cell.client.Cell.Context) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) IntegerEntityModelTextBoxOnlyEditor(org.ovirt.engine.ui.common.widget.editor.generic.IntegerEntityModelTextBoxOnlyEditor) SelectionMode(org.ovirt.engine.ui.common.widget.editor.EntityModelCellTable.SelectionMode) NetworkClusterModel(org.ovirt.engine.ui.uicommonweb.models.datacenters.NetworkClusterModel) EventBus(com.google.gwt.event.shared.EventBus) DnsServersWidget(org.ovirt.engine.ui.webadmin.widget.provider.DnsServersWidget) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) WithElementId(org.ovirt.engine.ui.common.idhandler.WithElementId) ListModelSuggestBoxEditor(org.ovirt.engine.ui.common.widget.editor.generic.ListModelSuggestBoxEditor) ApplicationModeHelper(org.ovirt.engine.ui.uicommonweb.models.ApplicationModeHelper) FlowPanel(com.google.gwt.user.client.ui.FlowPanel) UiField(com.google.gwt.uibinder.client.UiField) DialogTabPanel(org.ovirt.engine.ui.common.widget.dialog.tab.DialogTabPanel) MtuSelector(org.ovirt.engine.ui.uicommonweb.models.datacenters.NetworkModel.MtuSelector) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) AbstractCheckboxColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractCheckboxColumn) StringEntityModelTextBoxEditor(org.ovirt.engine.ui.common.widget.editor.generic.StringEntityModelTextBoxEditor) StringEntityModelTextBoxOnlyEditor(org.ovirt.engine.ui.common.widget.editor.generic.StringEntityModelTextBoxOnlyEditor) Align(org.ovirt.engine.ui.common.widget.Align) GWT(com.google.gwt.core.client.GWT) ListModelListBoxEditor(org.ovirt.engine.ui.common.widget.editor.ListModelListBoxEditor) ArrayList(java.util.ArrayList) ApplicationConstants(org.ovirt.engine.ui.webadmin.ApplicationConstants) UiCommandButton(org.ovirt.engine.ui.common.widget.UiCommandButton) DialogTab(org.ovirt.engine.ui.common.widget.dialog.tab.DialogTab) ListModelListBoxOnlyEditor(org.ovirt.engine.ui.common.widget.editor.ListModelListBoxOnlyEditor) AbstractNetworkPopupPresenterWidget(org.ovirt.engine.ui.webadmin.section.main.presenter.popup.AbstractNetworkPopupPresenterWidget) Network(org.ovirt.engine.core.common.businessentities.network.Network) HostNetworkQos(org.ovirt.engine.core.common.businessentities.network.HostNetworkQos) EntityModelCheckBoxEditor(org.ovirt.engine.ui.common.widget.editor.generic.EntityModelCheckBoxEditor) AbstractCheckboxHeader(org.ovirt.engine.ui.common.widget.table.header.AbstractCheckboxHeader) EntityModelRadioButtonEditor(org.ovirt.engine.ui.common.widget.editor.generic.EntityModelRadioButtonEditor) NameRenderer(org.ovirt.engine.ui.common.widget.renderer.NameRenderer) ApplicationTemplates(org.ovirt.engine.ui.webadmin.ApplicationTemplates) SimpleDialogPanel(org.ovirt.engine.ui.common.widget.dialog.SimpleDialogPanel) TabName(org.ovirt.engine.ui.uicommonweb.models.TabName) ExternalSubnetWidget(org.ovirt.engine.ui.webadmin.widget.provider.ExternalSubnetWidget) AbstractTextColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractTextColumn) Context(com.google.gwt.cell.client.Cell.Context) NetworkClusterModel(org.ovirt.engine.ui.uicommonweb.models.datacenters.NetworkClusterModel) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) AbstractCheckboxHeader(org.ovirt.engine.ui.common.widget.table.header.AbstractCheckboxHeader)

Example 8 with AbstractCheckboxColumn

use of org.ovirt.engine.ui.common.widget.table.column.AbstractCheckboxColumn in project ovirt-engine by oVirt.

the class ImportNetworksPopupView method initEntityModelCellTables.

void initEntityModelCellTables() {
    providerNetworks.addColumn(new AbstractTextColumn<ExternalNetwork>() {

        @Override
        public String getValue(ExternalNetwork model) {
            return model.getDisplayName();
        }
    }, constants.nameNetworkHeader());
    importedNetworks.addColumn(new AbstractEditTextColumn<ExternalNetwork>((index, model, value) -> model.setDisplayName(value)) {

        @Override
        public String getValue(ExternalNetwork model) {
            return model.getDisplayName();
        }
    }, constants.nameNetworkHeader());
    Column<ExternalNetwork, String> idColumn = new AbstractTextColumn<ExternalNetwork>() {

        @Override
        public String getValue(ExternalNetwork model) {
            return model.getNetwork().getProvidedBy().getExternalId();
        }
    };
    providerNetworks.addColumn(idColumn, constants.idNetworkHeader());
    importedNetworks.addColumn(idColumn, constants.idNetworkHeader());
    dcColumn = new AbstractListModelListBoxColumn<ExternalNetwork, StoragePool>(new NameRenderer<StoragePool>()) {

        @Override
        public ListModel<StoragePool> getValue(ExternalNetwork network) {
            return network.getDataCenters();
        }
    };
    importedNetworks.addColumn(dcColumn, constants.dcNetworkHeader());
    AbstractCheckboxHeader publicAllHeader = new AbstractCheckboxHeader() {

        @Override
        protected void selectionChanged(Boolean value) {
            for (ExternalNetwork model : getAllImportedNetworks()) {
                model.setPublicUse(value);
            }
            refreshImportedNetworks();
        }

        @Override
        public Boolean getValue() {
            for (ExternalNetwork model : getAllImportedNetworks()) {
                if (!model.isPublicUse()) {
                    return false;
                }
            }
            return true;
        }

        @Override
        public boolean isEnabled() {
            return true;
        }

        @Override
        public void render(Context context, SafeHtmlBuilder sb) {
            super.render(context, sb);
            sb.append(ImportNetworksPopupView.templates.tableHeaderInlineImage(SafeHtmlUtils.fromTrustedString(new InfoIcon(SafeHtmlUtils.EMPTY_SAFE_HTML).toString())));
        }

        @Override
        public SafeHtml getTooltip() {
            return ImportNetworksPopupView.templates.textForCheckBoxHeader(constants.publicNetworkTooltip());
        }

        @Override
        public String getLabel() {
            return constants.publicNetwork();
        }
    };
    importedNetworks.addColumn(new AbstractCheckboxColumn<ExternalNetwork>((index, model, value) -> {
        model.setPublicUse(value);
        refreshImportedNetworks();
    }) {

        @Override
        public Boolean getValue(ExternalNetwork model) {
            return model.isPublicUse();
        }

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

        @Override
        public void render(Context context, ExternalNetwork object, SafeHtmlBuilder sb) {
            super.render(context, object, sb);
            // $NON-NLS-1$
            sb.append(templates.textForCheckBox(""));
        }
    }, publicAllHeader, // $NON-NLS-1$
    "80px");
}
Also used : StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) AbstractCheckboxColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractCheckboxColumn) EntityModelCellTable(org.ovirt.engine.ui.common.widget.editor.EntityModelCellTable) AssetProvider(org.ovirt.engine.ui.webadmin.gin.AssetProvider) Inject(com.google.inject.Inject) Provider(org.ovirt.engine.core.common.businessentities.Provider) AbstractModelBoundPopupView(org.ovirt.engine.ui.common.view.popup.AbstractModelBoundPopupView) GWT(com.google.gwt.core.client.GWT) ImportNetworksPopupPresenterWidget(org.ovirt.engine.ui.webadmin.section.main.presenter.popup.provider.ImportNetworksPopupPresenterWidget) ListModelListBoxEditor(org.ovirt.engine.ui.common.widget.editor.ListModelListBoxEditor) ArrayList(java.util.ArrayList) UiBinder(com.google.gwt.uibinder.client.UiBinder) ApplicationConstants(org.ovirt.engine.ui.webadmin.ApplicationConstants) BaseImportNetworksModel(org.ovirt.engine.ui.uicommonweb.models.networks.BaseImportNetworksModel) ExternalNetwork(org.ovirt.engine.ui.uicommonweb.models.providers.ExternalNetwork) Context(com.google.gwt.cell.client.Cell.Context) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) HorizontalSplitTable(org.ovirt.engine.ui.common.widget.HorizontalSplitTable) SafeHtmlUtils(com.google.gwt.safehtml.shared.SafeHtmlUtils) InfoIcon(org.ovirt.engine.ui.common.widget.dialog.InfoIcon) ApplicationResources(org.ovirt.engine.ui.webadmin.ApplicationResources) AbstractEditTextColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractEditTextColumn) EventBus(com.google.gwt.event.shared.EventBus) UiCommonEditorDriver(org.ovirt.engine.ui.common.editor.UiCommonEditorDriver) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) AbstractCheckboxHeader(org.ovirt.engine.ui.common.widget.table.header.AbstractCheckboxHeader) NameRenderer(org.ovirt.engine.ui.common.widget.renderer.NameRenderer) AbstractListModelListBoxColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractListModelListBoxColumn) WithElementId(org.ovirt.engine.ui.common.idhandler.WithElementId) ApplicationTemplates(org.ovirt.engine.ui.webadmin.ApplicationTemplates) List(java.util.List) SimpleDialogPanel(org.ovirt.engine.ui.common.widget.dialog.SimpleDialogPanel) 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) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) Context(com.google.gwt.cell.client.Cell.Context) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) NameRenderer(org.ovirt.engine.ui.common.widget.renderer.NameRenderer) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) InfoIcon(org.ovirt.engine.ui.common.widget.dialog.InfoIcon) AbstractTextColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractTextColumn) ExternalNetwork(org.ovirt.engine.ui.uicommonweb.models.providers.ExternalNetwork) AbstractCheckboxHeader(org.ovirt.engine.ui.common.widget.table.header.AbstractCheckboxHeader)

Example 9 with AbstractCheckboxColumn

use of org.ovirt.engine.ui.common.widget.table.column.AbstractCheckboxColumn in project ovirt-engine by oVirt.

the class ImportVmFromExportDomainPopupView method initMainTable.

protected void initMainTable() {
    this.table = new ListModelObjectCellTable<>();
    table.enableColumnResizing();
    AbstractImageResourceColumn<Object> isProblematicImportVmColumn = new AbstractImageResourceColumn<Object>() {

        @Override
        public ImageResource getValue(Object object) {
            ImportVmData importVmData = (ImportVmData) object;
            if (importVmData.getError() != null || importVmData.isNameExistsInTheSystem()) {
                return resources.errorImage();
            }
            if (importVmData.getWarning() != null) {
                return resources.alertImage();
            }
            return null;
        }

        @Override
        public SafeHtml getTooltip(Object object) {
            ImportVmData importVmData = (ImportVmData) object;
            String problem = null;
            if (importVmData.getError() != null) {
                problem = importVmData.getError();
            } else {
                problem = importVmData.isNameExistsInTheSystem() ? ConstantsManager.getInstance().getConstants().nameMustBeUniqueInvalidReason() : importVmData.getWarning();
            }
            return problem != null ? SafeHtmlUtils.fromSafeConstant(problem) : null;
        }
    };
    // $NON-NLS-1$
    table.addColumn(isProblematicImportVmColumn, constants.empty(), "30px");
    AbstractTextColumn<Object> nameColumn = new AbstractTextColumn<Object>() {

        @Override
        public String getValue(Object object) {
            String originalName = ((ImportVmData) object).getName();
            String givenName = ((ImportVmData) object).getVm().getName();
            return originalName.equals(givenName) ? givenName : // $NON-NLS-1$ //$NON-NLS-2$
            givenName + " (" + originalName + ")";
        }
    };
    // $NON-NLS-1$
    table.addColumn(nameColumn, constants.nameVm(), "150px");
    AbstractCheckboxColumn<Object> collapseSnapshotsColumn = new AbstractCheckboxColumn<Object>((index, model, value) -> {
        ((ImportVmData) model).getCollapseSnapshots().setEntity(value);
        customSelectionCellFormatType.setEnabled(value);
        diskTable.asEditor().edit(importModel.getImportDiskListModel());
    }) {

        @Override
        public Boolean getValue(Object model) {
            return ((ImportVmData) model).getCollapseSnapshots().getEntity();
        }

        @Override
        protected boolean canEdit(Object model) {
            return ((ImportVmData) model).getCollapseSnapshots().getIsChangable();
        }

        @Override
        protected String getDisabledMessage(Object model) {
            return ((ImportVmData) model).getCollapseSnapshots().getChangeProhibitionReason();
        }

        @Override
        public SafeHtml getTooltip(Object object) {
            SafeHtml superTooltip = super.getTooltip(object);
            if (superTooltip == null) {
                return SafeHtmlUtils.fromSafeConstant(constants.importAllocationModifiedCollapse());
            }
            return superTooltip;
        }
    };
    // $NON-NLS-1$
    table.addColumn(collapseSnapshotsColumn, constants.collapseSnapshots(), "130px");
    AbstractCheckboxColumn<Object> cloneVMColumn = new AbstractCheckboxColumn<Object>((index, model, value) -> {
        ((ImportVmData) model).getClone().setEntity(value);
        table.asEditor().edit(importModel);
    }) {

        @Override
        public Boolean getValue(Object model) {
            return ((ImportVmData) model).getClone().getEntity();
        }

        @Override
        protected boolean canEdit(Object model) {
            return ((ImportVmData) model).getClone().getIsChangable();
        }

        @Override
        protected String getDisabledMessage(Object model) {
            return ((ImportVmData) model).getClone().getChangeProhibitionReason();
        }
    };
    // $NON-NLS-1$
    table.addColumn(cloneVMColumn, constants.cloneVM(), "50px");
    AbstractTextColumn<Object> originColumn = new AbstractEnumColumn<Object, OriginType>() {

        @Override
        protected OriginType getRawValue(Object object) {
            return ((ImportVmData) object).getVm().getOrigin();
        }
    };
    // $NON-NLS-1$
    table.addColumn(originColumn, constants.originVm(), "100px");
    table.addColumn(new AbstractSafeHtmlColumn<Object>() {

        @Override
        public SafeHtml getValue(Object object) {
            return VmTypeColumn.getRenderedValue(((ImportVmData) object).getVm());
        }
    }, constants.empty(), // $NON-NLS-1$
    "30px");
    AbstractTextColumn<Object> memoryColumn = new AbstractTextColumn<Object>() {

        @Override
        public String getValue(Object object) {
            return messages.megabytes(String.valueOf(((ImportVmData) object).getVm().getVmMemSizeMb()));
        }
    };
    // $NON-NLS-1$
    table.addColumn(memoryColumn, constants.memoryVm(), "90px");
    AbstractTextColumn<Object> cpuColumn = new AbstractTextColumn<Object>() {

        @Override
        public String getValue(Object object) {
            return String.valueOf(((ImportVmData) object).getVm().getNumOfCpus());
        }
    };
    // $NON-NLS-1$
    table.addColumn(cpuColumn, constants.cpusVm(), "50px");
    AbstractTextColumn<Object> archColumn = new AbstractTextColumn<Object>() {

        @Override
        public String getValue(Object object) {
            return String.valueOf(((ImportVmData) object).getVm().getClusterArch());
        }
    };
    // $NON-NLS-1$
    table.addColumn(archColumn, constants.architectureVm(), "100px");
    AbstractTextColumn<Object> diskColumn = new AbstractTextColumn<Object>() {

        @Override
        public String getValue(Object object) {
            return String.valueOf(((ImportVmData) object).getVm().getDiskMap().size());
        }
    };
    // $NON-NLS-1$
    table.addColumn(diskColumn, constants.disksVm(), "55px");
    isObjectInSystemColumn = new AbstractImageResourceColumn<Object>() {

        @Override
        public ImageResource getValue(Object object) {
            return ((ImportVmData) object).isExistsInSystem() ? resources.logNormalImage() : null;
        }
    };
    // $NON-NLS-1$
    table.addColumn(isObjectInSystemColumn, constants.vmInSetup(), "100px");
    table.getSelectionModel().addSelectionChangeHandler(event -> {
        ImportVmData selectedObject = ((SingleSelectionModel<ImportVmData>) event.getSource()).getSelectedObject();
        customSelectionCellFormatType.setEnabled(selectedObject.getCollapseSnapshots().getEntity());
    });
    ScrollPanel sp = new ScrollPanel();
    sp.add(table);
    splitLayoutPanel.add(sp);
    table.getElement().getStyle().setPosition(Position.RELATIVE);
}
Also used : SingleSelectionModel(com.google.gwt.view.client.SingleSelectionModel) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) ImportVmData(org.ovirt.engine.ui.uicommonweb.models.vms.ImportVmData) AbstractCheckboxColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractCheckboxColumn) AbstractEnumColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractEnumColumn) ImageResource(com.google.gwt.resources.client.ImageResource) AbstractImageResourceColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractImageResourceColumn) AbstractTextColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractTextColumn) ScrollPanel(com.google.gwt.user.client.ui.ScrollPanel)

Example 10 with AbstractCheckboxColumn

use of org.ovirt.engine.ui.common.widget.table.column.AbstractCheckboxColumn 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

AbstractCheckboxColumn (org.ovirt.engine.ui.common.widget.table.column.AbstractCheckboxColumn)11 AbstractTextColumn (org.ovirt.engine.ui.common.widget.table.column.AbstractTextColumn)7 ListModel (org.ovirt.engine.ui.uicommonweb.models.ListModel)5 GWT (com.google.gwt.core.client.GWT)4 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)4 UiBinder (com.google.gwt.uibinder.client.UiBinder)4 UiField (com.google.gwt.uibinder.client.UiField)4 ArrayList (java.util.ArrayList)4 EntityModelCellTable (org.ovirt.engine.ui.common.widget.editor.EntityModelCellTable)4 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)4 Context (com.google.gwt.cell.client.Cell.Context)3 EventBus (com.google.gwt.event.shared.EventBus)3 ImageResource (com.google.gwt.resources.client.ImageResource)3 SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)3 ScrollPanel (com.google.gwt.user.client.ui.ScrollPanel)3 Inject (com.google.inject.Inject)3 UiCommonEditorDriver (org.ovirt.engine.ui.common.editor.UiCommonEditorDriver)3 WithElementId (org.ovirt.engine.ui.common.idhandler.WithElementId)3 SimpleDialogPanel (org.ovirt.engine.ui.common.widget.dialog.SimpleDialogPanel)3 ApplicationConstants (org.ovirt.engine.ui.webadmin.ApplicationConstants)3