public class GlusterHookSyncStatusColumn extends AbstractImageResourceColumn<GlusterHookEntity> { private static final ApplicationResources resources = AssetProvider.getResources(); @Override public ImageResource getValue(GlusterHookEntity hookEntity) { if (hookEntity.hasConflicts()) { return resources.alertImage(); } return null; } }
public class SubTabNetworkClusterView extends AbstractSubTabTableView< NetworkView, PairQueryable<Cluster, NetworkCluster>, NetworkListModel, NetworkClusterListModel> implements SubTabNetworkClusterPresenter.ViewDef { interface ViewIdHandler extends ElementIdHandler<SubTabNetworkClusterView> { ViewIdHandler idHandler = GWT.create(ViewIdHandler.class); } private final SafeHtml displayImage; private final SafeHtml migrationImage; private final SafeHtml glusterNwImage; private final SafeHtml emptyImage; private final SafeHtml managementImage; private static final ApplicationResources resources = AssetProvider.getResources(); private static final ApplicationConstants constants = AssetProvider.getConstants(); @Inject public SubTabNetworkClusterView( SearchableDetailModelProvider< PairQueryable<Cluster, NetworkCluster>, NetworkListModel, NetworkClusterListModel> modelProvider) { super(modelProvider); displayImage = SafeHtmlUtils.fromTrustedString( AbstractImagePrototype.create(resources.networkMonitor()).getHTML()); migrationImage = SafeHtmlUtils.fromTrustedString( AbstractImagePrototype.create(resources.migrationNetwork()).getHTML()); glusterNwImage = SafeHtmlUtils.fromTrustedString( AbstractImagePrototype.create(resources.glusterNetwork()).getHTML()); emptyImage = SafeHtmlUtils.fromTrustedString( AbstractImagePrototype.create(resources.networkEmpty()).getHTML()); managementImage = SafeHtmlUtils.fromTrustedString( AbstractImagePrototype.create(resources.mgmtNetwork()).getHTML()); initTable(); initWidget(getTable()); } @Override protected void generateIds() { ViewIdHandler.idHandler.generateAndSetIds(this); } void initTable() { getTable().enableColumnResizing(); AbstractTextColumn<PairQueryable<Cluster, NetworkCluster>> nameColumn = new AbstractTextColumn<PairQueryable<Cluster, NetworkCluster>>() { @Override public String getValue(PairQueryable<Cluster, NetworkCluster> object) { return object.getFirst().getName(); } }; nameColumn.makeSortable(); getTable().addColumn(nameColumn, constants.nameCluster(), "400px"); // $NON-NLS-1$ AbstractTextColumn<PairQueryable<Cluster, NetworkCluster>> versionColumn = new AbstractTextColumn<PairQueryable<Cluster, NetworkCluster>>() { @Override public String getValue(PairQueryable<Cluster, NetworkCluster> object) { return object.getFirst().getCompatibilityVersion().getValue(); } }; versionColumn.makeSortable(); getTable().addColumn(versionColumn, constants.comptVersCluster(), "130px"); // $NON-NLS-1$ AbstractCheckboxColumn<PairQueryable<Cluster, NetworkCluster>> attachedColumn = new AbstractCheckboxColumn<PairQueryable<Cluster, NetworkCluster>>(true) { @Override public Boolean getValue(PairQueryable<Cluster, NetworkCluster> object) { return object.getSecond() != null; } @Override protected boolean canEdit(PairQueryable<Cluster, NetworkCluster> object) { return false; } }; attachedColumn.makeSortable(); getTable() .addColumn(attachedColumn, constants.attachedNetworkCluster(), "120px"); // $NON-NLS-1$ NetworkClusterStatusColumn statusColumn = new NetworkClusterStatusColumn(); statusColumn.makeSortable(new SimpleStatusColumnComparator<>(statusColumn)); getTable().addColumn(statusColumn, constants.networkStatus(), "120px"); // $NON-NLS-1$ AbstractCheckboxColumn<PairQueryable<Cluster, NetworkCluster>> netRequiredColumn = new AbstractCheckboxColumn<PairQueryable<Cluster, NetworkCluster>>(true) { @Override public Boolean getValue(PairQueryable<Cluster, NetworkCluster> object) { if (object.getSecond() != null) { return object.getSecond().isRequired(); } return false; } @Override protected boolean canEdit(PairQueryable<Cluster, NetworkCluster> object) { return false; } }; netRequiredColumn.makeSortable(); getTable().addColumn(netRequiredColumn, constants.requiredNetCluster(), "120px"); // $NON-NLS-1$ AbstractSafeHtmlColumn<PairQueryable<Cluster, NetworkCluster>> netRoleColumn = new AbstractSafeHtmlColumn<PairQueryable<Cluster, NetworkCluster>>() { @Override public SafeHtml getValue(PairQueryable<Cluster, NetworkCluster> object) { List<SafeHtml> images = new LinkedList<>(); if (object.getSecond() != null) { if (object.getSecond().isManagement()) { images.add(managementImage); } else { images.add(emptyImage); } if (object.getSecond().isDisplay()) { images.add(displayImage); } else { images.add(emptyImage); } if (object.getSecond().isMigration()) { images.add(migrationImage); } else { images.add(emptyImage); } if (object.getSecond().isGluster()) { images.add(glusterNwImage); } else { images.add(emptyImage); } } return MultiImageColumnHelper.getValue(images); } @Override public SafeHtml getTooltip(PairQueryable<Cluster, NetworkCluster> object) { Map<SafeHtml, String> imagesToText = new LinkedHashMap<>(); if (object.getSecond() != null) { if (object.getSecond().isManagement()) { imagesToText.put(managementImage, constants.managementItemInfo()); } if (object.getSecond().isDisplay()) { imagesToText.put(displayImage, constants.displayItemInfo()); } if (object.getSecond().isMigration()) { imagesToText.put(migrationImage, constants.migrationItemInfo()); } if (object.getSecond().isGluster()) { imagesToText.put(glusterNwImage, constants.glusterNwItemInfo()); } } return MultiImageColumnHelper.getTooltip(imagesToText); } }; netRoleColumn.makeSortable( new Comparator<PairQueryable<Cluster, NetworkCluster>>() { private int calculateValue(NetworkCluster networkCluster) { int res = 0; if (networkCluster != null) { if (networkCluster.isManagement()) { res += 10; } if (networkCluster.isDisplay()) { res += 4; } if (networkCluster.isMigration()) { res += 2; } if (networkCluster.isGluster()) { res += 1; } } return res; } @Override public int compare( PairQueryable<Cluster, NetworkCluster> o1, PairQueryable<Cluster, NetworkCluster> o2) { return calculateValue(o1.getSecond()) - calculateValue(o2.getSecond()); } }); getTable().addColumn(netRoleColumn, constants.roleNetCluster(), "120px"); // $NON-NLS-1$ AbstractTextColumn<PairQueryable<Cluster, NetworkCluster>> descriptionColumn = new AbstractTextColumn<PairQueryable<Cluster, NetworkCluster>>() { @Override public String getValue(PairQueryable<Cluster, NetworkCluster> object) { return object.getFirst().getDescription(); } }; descriptionColumn.makeSortable(); getTable().addColumn(descriptionColumn, constants.descriptionCluster(), "400px"); // $NON-NLS-1$ getTable() .addActionButton( new WebAdminButtonDefinition<PairQueryable<Cluster, NetworkCluster>>( constants.assignUnassignNetwork()) { @Override protected UICommand resolveCommand() { return getDetailModel().getManageCommand(); } }); } }
public class SharedMacPoolView extends Composite { private final PermissionModelProvider<MacPool, SharedMacPoolListModel> permissionModelProvider; private final SharedMacPoolModelProvider sharedMacPoolModelProvider; private final SimpleActionTable<MacPool> macPoolTable; private final PermissionListModelTable<PermissionListModel<MacPool>> authorizationTable; private final EventBus eventBus; private final ClientStorage clientStorage; private final MainTableHeaderlessResources headerlessResources; private final MainTableResources tableResources; private final SplitLayoutPanel rootPanel; private static final ApplicationResources resources = AssetProvider.getResources(); private static final ApplicationConstants constants = AssetProvider.getConstants(); @Inject public SharedMacPoolView( final SharedMacPoolModelProvider sharedMacPoolModelProvider, final PermissionModelProvider<MacPool, SharedMacPoolListModel> permissionModelProvider, final EventBus eventBus, final ClientStorage clientStorage, final MainTableHeaderlessResources headerlessResources, final MainTableResources tableResources) { this.sharedMacPoolModelProvider = sharedMacPoolModelProvider; this.permissionModelProvider = permissionModelProvider; this.eventBus = eventBus; this.clientStorage = clientStorage; this.headerlessResources = headerlessResources; this.tableResources = tableResources; macPoolTable = createMacPoolTable(); authorizationTable = new PermissionListModelTable<>(permissionModelProvider, eventBus, clientStorage); authorizationTable.initTable(); authorizationTable .getTable() .getSelectionModel() .addSelectionChangeHandler( new SelectionChangeEvent.Handler() { @Override public void onSelectionChange(SelectionChangeEvent event) { permissionModelProvider.setSelectedItems( authorizationTable.getTable().getSelectedItems()); } }); rootPanel = createRootPanel(); setupAuthorizationTableVisibility(false); initWidget(rootPanel); } private void setupAuthorizationTableVisibility(boolean visible) { rootPanel.clear(); if (visible) { rootPanel.addSouth(authorizationTable, 150); } rootPanel.add(macPoolTable); } private SplitLayoutPanel createRootPanel() { SplitLayoutPanel rootPanel = new SplitLayoutPanel(); rootPanel.setHeight("495px"); // $NON-NLS-1$ rootPanel.setWidth("100%"); // $NON-NLS-1$ return rootPanel; } private SimpleActionTable<MacPool> createMacPoolTable() { final SimpleActionTable<MacPool> macPoolTable = new SimpleActionTable<>( sharedMacPoolModelProvider, headerlessResources, tableResources, eventBus, clientStorage); macPoolTable.addColumn( new AbstractImageResourceColumn<MacPool>() { @Override public ImageResource getValue(MacPool macPool) { return macPool.isDefaultPool() ? resources.lockImage() : null; } }, constants.empty(), "20px"); //$NON-NLS-1$ macPoolTable.addColumn( new AbstractTextColumn<MacPool>() { @Override public String getValue(MacPool macPool) { return macPool.getName(); } }, constants.configureMacPoolNameColumn(), "100px"); //$NON-NLS-1$ macPoolTable.addColumn( new AbstractTextColumn<MacPool>() { @Override public String getValue(MacPool macPool) { return macPool.getDescription(); } }, constants.configureMacPoolDescriptionColumn(), "300px"); //$NON-NLS-1$ macPoolTable.addActionButton( new WebAdminButtonDefinition<MacPool>(constants.configureMacPoolAddButton()) { @Override protected UICommand resolveCommand() { return sharedMacPoolModelProvider.getModel().getNewCommand(); } }); macPoolTable.addActionButton( new WebAdminButtonDefinition<MacPool>(constants.configureMacPoolEditButton()) { @Override protected UICommand resolveCommand() { return sharedMacPoolModelProvider.getModel().getEditCommand(); } }); macPoolTable.addActionButton( new WebAdminButtonDefinition<MacPool>(constants.configureMacPoolRemoveButton()) { @Override protected UICommand resolveCommand() { return sharedMacPoolModelProvider.getModel().getRemoveCommand(); } }); macPoolTable .getSelectionModel() .addSelectionChangeHandler( new SelectionChangeEvent.Handler() { @Override public void onSelectionChange(SelectionChangeEvent event) { final List<MacPool> selectedItems = macPoolTable.getSelectedItems(); sharedMacPoolModelProvider.setSelectedItems(selectedItems); final PermissionListModel<MacPool> model = permissionModelProvider.getModel(); if (selectedItems.size() == 1) { model.setEntity(selectedItems.get(0)); setupAuthorizationTableVisibility(true); } else { model.setEntity(null); setupAuthorizationTableVisibility(false); } } }); return macPoolTable; } }