Search in sources :

Example 1 with Nameable

use of org.ovirt.engine.core.common.businessentities.Nameable in project ovirt-engine by oVirt.

the class RemoveQosModel method handleSetMessageQueryResult.

protected void handleSetMessageQueryResult(FrontendMultipleQueryAsyncResult result) {
    Map<String, String> entitiesAndQos = new HashMap<>();
    setHelpTag(getRemoveQosHelpTag());
    setHashName(getRemoveQosHashName());
    int index = 0;
    for (QueryReturnValue returnValue : result.getReturnValues()) {
        for (Nameable entity : (List<Nameable>) returnValue.getReturnValue()) {
            entitiesAndQos.put(entity.getName(), sourceListModel.getSelectedItems().get(index).getName());
        }
        index++;
    }
    if (entitiesAndQos.isEmpty()) {
        ArrayList<String> list = new ArrayList<>();
        for (T item : sourceListModel.getSelectedItems()) {
            list.add(item.getName());
        }
        setItems(list);
    } else {
        setMessage(getRemoveQosMessage(entitiesAndQos.size()));
        ArrayList<String> list = new ArrayList<>();
        for (Entry<String, String> item : entitiesAndQos.entrySet()) {
            // $NON-NLS-1$ //$NON-NLS-2$
            list.add(item.getKey() + " (" + item.getValue() + ")");
        }
        setItems(list);
    }
}
Also used : Nameable(org.ovirt.engine.core.common.businessentities.Nameable) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with Nameable

use of org.ovirt.engine.core.common.businessentities.Nameable in project ovirt-engine by oVirt.

the class RemoveStorageQosModel method handleSetMessageQueryResult.

protected void handleSetMessageQueryResult(FrontendMultipleQueryAsyncResult result) {
    setHelpTag(getRemoveQosHelpTag());
    setHashName(getRemoveQosHashName());
    int index = 0;
    int numberOfTimesUsedByDiskProfiles = 0;
    ArrayList<String> list = new ArrayList<>();
    for (QueryReturnValue returnValue : result.getReturnValues()) {
        List<Nameable> diskProfileEntities = returnValue.getReturnValue();
        String qosName = sourceListModel.getSelectedItems().get(index).getName();
        if (diskProfileEntities.size() == 0) {
            list.add(qosName);
        } else {
            numberOfTimesUsedByDiskProfiles += diskProfileEntities.size();
            List<String> diskProfileNames = new ArrayList<>();
            for (Nameable diskProfileEntity : diskProfileEntities) {
                String diskProfileName = diskProfileEntity.getName();
                diskProfileNames.add(diskProfileName);
            }
            // $NON-NLS-1$
            String diskProfileNamesAsString = String.join(", ", diskProfileNames);
            list.add(ConstantsManager.getInstance().getMessages().removeStorageQoSItem(qosName, diskProfileNamesAsString));
        }
        index++;
    }
    setMessage(getRemoveQosMessage(numberOfTimesUsedByDiskProfiles));
    setItems(list);
}
Also used : Nameable(org.ovirt.engine.core.common.businessentities.Nameable) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) ArrayList(java.util.ArrayList)

Example 3 with Nameable

use of org.ovirt.engine.core.common.businessentities.Nameable in project ovirt-engine by oVirt.

the class ListModelSearchBox method setInternalRowData.

private void setInternalRowData(int start, List<? extends T> values) {
    final int oldCount = menu.getWidgetCount();
    clearMenu();
    emptyMenuHandlers();
    for (T model : values) {
        if (model instanceof Nameable) {
            final String text = getName(model).asString();
            final AnchorListItem item = new SearchBoxAnchorListItem(this);
            item.setText(text);
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                @Override
                public void execute() {
                    if (StringHelper.isNotNullOrEmpty(currentSearch)) {
                        String newText = text.replaceAll(currentSearch, // $NON-NLS-1$
                        "<strong>" + currentSearch + // $NON-NLS-1$
                        "</strong>");
                        item.getWidget(0).getElement().setInnerHTML(newText);
                    }
                }
            });
            menuHandlers.add(item.addClickHandler(this));
            menu.add(item);
        }
    }
    if (oldCount != menu.getWidgetCount()) {
        currentFocusIndex = 0;
    }
    if (currentFocusIndex >= menu.getWidgetCount() - 1) {
        currentFocusIndex = menu.getWidgetCount() - 1;
    }
    if (currentFocusIndex >= 0) {
        ((AnchorListItem) menu.getWidget(currentFocusIndex)).setFocus(true);
    }
}
Also used : Nameable(org.ovirt.engine.core.common.businessentities.Nameable) AnchorListItem(org.gwtbootstrap3.client.ui.AnchorListItem) GWT(com.google.gwt.core.client.GWT) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand)

Example 4 with Nameable

use of org.ovirt.engine.core.common.businessentities.Nameable in project ovirt-engine by oVirt.

the class ReplacementUtilsTest method replaceWithNameableCollection.

@Test
public void replaceWithNameableCollection() {
    Nameable item = () -> PROPERTY_VALUE;
    List<Nameable> items = Collections.singletonList(item);
    validateReplacements(ReplacementUtils.replaceWithNameable(PROPERTY_NAME, items), items);
}
Also used : Nameable(org.ovirt.engine.core.common.businessentities.Nameable) Test(org.junit.Test)

Aggregations

Nameable (org.ovirt.engine.core.common.businessentities.Nameable)4 ArrayList (java.util.ArrayList)2 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)2 GWT (com.google.gwt.core.client.GWT)1 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 HashMap (java.util.HashMap)1 List (java.util.List)1 AnchorListItem (org.gwtbootstrap3.client.ui.AnchorListItem)1 Test (org.junit.Test)1