Search in sources :

Example 1 with NetworkCommand

use of org.ovirt.engine.ui.uicommonweb.models.hosts.network.NetworkCommand in project ovirt-engine by oVirt.

the class NetworkPanel method onAction.

@Override
protected void onAction() {
    if (item.isManaged()) {
        item.edit();
    } else {
        Map<NetworkOperation, List<NetworkCommand>> operationMap = item.getSetupModel().commandsFor(item);
        final NetworkCommand detach = operationMap.get(NetworkOperation.REMOVE_UNMANAGED_NETWORK).get(0);
        item.getSetupModel().onOperation(NetworkOperation.REMOVE_UNMANAGED_NETWORK, detach);
    }
}
Also used : List(java.util.List) NetworkCommand(org.ovirt.engine.ui.uicommonweb.models.hosts.network.NetworkCommand) NetworkOperation(org.ovirt.engine.ui.uicommonweb.models.hosts.network.NetworkOperation)

Example 2 with NetworkCommand

use of org.ovirt.engine.ui.uicommonweb.models.hosts.network.NetworkCommand in project ovirt-engine by oVirt.

the class NetworkItemPanel method menuFor.

/**
 * Generate a Menu for the provided Network Item.
 */
private MenuBar menuFor(NetworkItemModel<?> item) {
    MenuBar menu = rootMenu(item);
    Map<NetworkOperation, List<NetworkCommand>> operationMap = item.getSetupModel().commandsFor(item);
    for (final Entry<NetworkOperation, List<NetworkCommand>> entry : operationMap.entrySet()) {
        final List<NetworkCommand> commands = entry.getValue();
        if (entry.getKey().isUnary()) {
            // $NON-NLS-1$
            assert commands.size() == 1 : "Got a NetworkCommand List with more than one Unary Operation";
            menu.addItem(entry.getKey().getVerb(item), () -> executeCommand(entry.getKey(), commands.get(0)));
        } else {
            Collections.sort(commands, Comparator.comparing(NetworkCommand::getName, new LexoNumericComparator()));
            MenuBar subMenu = subMenu();
            for (final NetworkCommand command : commands) {
                subMenu.addItem(new MenuItem(command.getName(), () -> executeCommand(entry.getKey(), command)));
            }
            menu.addItem(entry.getKey().getVerb(item), subMenu);
        }
    }
    return menu;
}
Also used : MenuBar(org.ovirt.engine.ui.common.widget.MenuBar) LexoNumericComparator(org.ovirt.engine.core.common.businessentities.comparators.LexoNumericComparator) List(java.util.List) MenuItem(com.google.gwt.user.client.ui.MenuItem) NetworkCommand(org.ovirt.engine.ui.uicommonweb.models.hosts.network.NetworkCommand) NetworkOperation(org.ovirt.engine.ui.uicommonweb.models.hosts.network.NetworkOperation)

Aggregations

List (java.util.List)2 NetworkCommand (org.ovirt.engine.ui.uicommonweb.models.hosts.network.NetworkCommand)2 NetworkOperation (org.ovirt.engine.ui.uicommonweb.models.hosts.network.NetworkOperation)2 MenuItem (com.google.gwt.user.client.ui.MenuItem)1 LexoNumericComparator (org.ovirt.engine.core.common.businessentities.comparators.LexoNumericComparator)1 MenuBar (org.ovirt.engine.ui.common.widget.MenuBar)1