Search in sources :

Example 1 with NetworkOperation

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

the class HostSetupNetworksPopupView method edit.

@Override
public void edit(HostSetupNetworksModel uicommonModel) {
    driver.edit(uicommonModel);
    uicommonModel.getNicsChangedEvent().addListener((ev, sender, args) -> {
        // this is called after both networks and nics were retrieved
        HostSetupNetworksModel model = (HostSetupNetworksModel) sender;
        if (!keepStatusText) {
            initStatusPanel();
        }
        keepStatusText = false;
        int scrollPosition = nicScrollPanel.getVerticalScrollPosition();
        updateNetworks(model.getNetworkModels());
        updateLabels(model.getNewNetworkLabelModel(), model.getLabelModels());
        updateNics(model.getNicModels());
        nicScrollPanel.setVerticalScrollPosition(scrollPosition);
        // mark as rendered
        rendered = true;
    });
    uicommonModel.getOperationCandidateEvent().addListener((ev, sender, args) -> {
        NetworkOperation candidate = args.getCandidate();
        NetworkItemModel<?> op1 = args.getOp1();
        NetworkItemModel<?> op2 = args.getOp2();
        if (candidate == null) {
            setErrorStatus(constants.noValidActionSetupNetwork());
        } else {
            if (candidate.isErroneousOperation()) {
                setErrorStatus(candidate.getMessage(op1, op2));
            } else {
                if (candidate.isDisplayNetworkAffected(op1, op2)) {
                    setWarningStatus(messages.moveDisplayNetworkWarning(candidate.getMessage(op1, op2)));
                } else if (candidate.isRequiredNetworkAffected(op1, op2)) {
                    setWarningStatus(messages.detachRequiredNetworkWarning(candidate.getMessage(op1, op2)));
                } else {
                    setValidStatus(candidate.getMessage(op1, op2));
                }
            }
        }
    });
    internalNetworkList.setSetupModel(uicommonModel);
    externalNetworkList.setSetupModel(uicommonModel);
    labelsList.setSetupModel(uicommonModel);
}
Also used : HostSetupNetworksModel(org.ovirt.engine.ui.uicommonweb.models.hosts.HostSetupNetworksModel) NetworkOperation(org.ovirt.engine.ui.uicommonweb.models.hosts.network.NetworkOperation)

Example 2 with NetworkOperation

use of org.ovirt.engine.ui.uicommonweb.models.hosts.network.NetworkOperation 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 3 with NetworkOperation

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

the class HostSetupNetworksModel method candidateOperation.

public boolean candidateOperation(String op1Key, String op1Type, String op2Key, String op2Type, boolean drop) {
    NetworkItemModel<?> op1 = getItemModel(op1Key, op1Type);
    NetworkItemModel<?> op2 = getItemModel(op2Key, op2Type);
    if (op1 == null) {
        // $NON-NLS-1$
        throw new IllegalArgumentException("null Operands");
    }
    NetworkOperation candidate = NetworkOperationFactory.operationFor(op1, op2, true);
    if (drop) {
        onOperation(candidate, candidate.getCommand(op1, op2, hostSetupNetworksParametersData));
    }
    // raise the candidate event only if it was changed
    if (!candidate.equals(currentCandidate) || !equals(op1, currentOp1) || !equals(op2, currentOp2)) {
        currentCandidate = candidate;
        currentOp1 = op1;
        currentOp2 = op2;
        getOperationCandidateEvent().raise(this, new OperationCandidateEventArgs(candidate, op1, op2));
    }
    return !candidate.isNullOperation();
}
Also used : OperationCandidateEventArgs(org.ovirt.engine.ui.uicommonweb.models.hosts.network.OperationCandidateEventArgs) NetworkOperation(org.ovirt.engine.ui.uicommonweb.models.hosts.network.NetworkOperation)

Example 4 with NetworkOperation

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

the class HostSetupNetworksModel method setLabelErrorsOnNicModels.

private void setLabelErrorsOnNicModels(Map<String, NetworkInterfaceModel> nicModels, List<LogicalNetworkModel> networkModelsWithLabelError, Map<String, String> labelToDesiredNicName) {
    for (LogicalNetworkModel networkModel : networkModelsWithLabelError) {
        NetworkInterfaceModel desiredNicModel = nicModels.get(labelToDesiredNicName.get(networkModel.getNetwork().getLabel()));
        NetworkOperation operation = NetworkOperationFactory.operationFor(networkModel, desiredNicModel);
        UIMessages messages = ConstantsManager.getInstance().getMessages();
        // Should be attached but can't due to conflict
        if (desiredNicModel != null) {
            if (operation.isNullOperation()) {
                networkModel.setErrorMessage(messages.networkLabelConflict(desiredNicModel.getName(), networkModel.getNetwork().getLabel()) + " " + // $NON-NLS-1$
                operation.getMessage(networkModel, desiredNicModel));
            } else {
                networkModel.setErrorMessage(messages.labeledNetworkNotAttached(desiredNicModel.getName(), networkModel.getNetwork().getLabel()));
            }
        }
    }
}
Also used : NetworkInterfaceModel(org.ovirt.engine.ui.uicommonweb.models.hosts.network.NetworkInterfaceModel) BondNetworkInterfaceModel(org.ovirt.engine.ui.uicommonweb.models.hosts.network.BondNetworkInterfaceModel) UIMessages(org.ovirt.engine.ui.uicompat.UIMessages) LogicalNetworkModel(org.ovirt.engine.ui.uicommonweb.models.hosts.network.LogicalNetworkModel) NetworkOperation(org.ovirt.engine.ui.uicommonweb.models.hosts.network.NetworkOperation)

Example 5 with NetworkOperation

use of org.ovirt.engine.ui.uicommonweb.models.hosts.network.NetworkOperation 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

NetworkOperation (org.ovirt.engine.ui.uicommonweb.models.hosts.network.NetworkOperation)5 List (java.util.List)2 NetworkCommand (org.ovirt.engine.ui.uicommonweb.models.hosts.network.NetworkCommand)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 HostSetupNetworksModel (org.ovirt.engine.ui.uicommonweb.models.hosts.HostSetupNetworksModel)1 BondNetworkInterfaceModel (org.ovirt.engine.ui.uicommonweb.models.hosts.network.BondNetworkInterfaceModel)1 LogicalNetworkModel (org.ovirt.engine.ui.uicommonweb.models.hosts.network.LogicalNetworkModel)1 NetworkInterfaceModel (org.ovirt.engine.ui.uicommonweb.models.hosts.network.NetworkInterfaceModel)1 OperationCandidateEventArgs (org.ovirt.engine.ui.uicommonweb.models.hosts.network.OperationCandidateEventArgs)1 UIMessages (org.ovirt.engine.ui.uicompat.UIMessages)1