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);
}
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);
}
}
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();
}
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()));
}
}
}
}
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;
}
Aggregations