Here are the examples of the java api com.vaadin.data.util.BeanItem taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
9 Examples
19
Source : JobView.java
with Apache License 2.0
from opensecuritycontroller
with Apache License 2.0
from opensecuritycontroller
// This is also needed since Abort button should change to disabled if job state
// changes before user clicks on the table
@Override
protected void syncParentTable(BroadcastMessage msg, GetDtoFromEnreplacedyServiceApi<JobRecordDto> getDtoService) throws Exception {
super.syncParentTable(msg, getDtoService);
BeanItem<JobRecordDto> item = this.parentContainer.gereplacedem(msg.getEnreplacedyId());
JobRecordDto jobRecordDto = null;
if (item != null) {
jobRecordDto = item.getBean();
}
updateAbortButtonState(jobRecordDto);
}
18
Source : AbstractMappedEntityListPanel.java
with Apache License 2.0
from ijazfx
with Apache License 2.0
from ijazfx
private MGrid<T> buildMainGrid() {
MGrid<T> grid = new MGrid<>(enreplacedyClreplaced);
mainGridContainer = new BeanItemContainer<>(enreplacedyClreplaced);
grid.setContainerDataSource(mainGridContainer);
grid.setSizeFull();
String[] visibleProperties = visibleProperties();
if (visibleProperties != null) {
grid.withProperties(visibleProperties());
}
if (isGridCellFilterEnabled()) {
filter = new GridCellFilter(grid);
if (visibleProperties != null) {
addCellFiltersForVisibleProperties(filter, visibleProperties);
}
}
grid.setSelectionMode(SelectionMode.MULTI);
grid.addItemClickListener(event -> {
if (event.getPropertyId() != null) {
BeanItem<T> item = mainGridContainer.gereplacedem(event.gereplacedemId());
onGridItemClicked(item.getBean());
}
});
grid.addSelectionListener(event -> {
editButton.setEnabled(event.getSelected().size() == 1);
deleteButton.setEnabled(event.getSelected().size() > 0);
DashboardEventBus.sessionInstance().post(event.getSelected());
});
return grid;
}
17
Source : UpdateAlarmWindow.java
with Apache License 2.0
from opensecuritycontroller
with Apache License 2.0
from opensecuritycontroller
public clreplaced UpdateAlarmWindow extends BaseAlarmWindow {
private static final long serialVersionUID = 1L;
final String CAPTION = "Edit Alarm";
private static final Logger log = LoggerFactory.getLogger(UpdateAlarmWindow.clreplaced);
// current view reference
private AlarmView alarmView = null;
private BeanItem<AlarmDto> currentAlarm = null;
private UpdateAlarmServiceApi updateAlarmService;
public UpdateAlarmWindow(AlarmView alarmView, UpdateAlarmServiceApi updateAlarmService, GetEmailSettingsServiceApi getEmailSettingsService) throws Exception {
super(getEmailSettingsService);
this.alarmView = alarmView;
this.updateAlarmService = updateAlarmService;
this.currentAlarm = alarmView.getParenreplacedem();
createWindow(this.CAPTION);
}
@Override
public void populateForm() {
super.populateForm();
// filling fields with existing information
this.enabled.setValue((Boolean) this.currentAlarm.gereplacedemProperty("enabledAlarm").getValue());
this.alarmName.setValue(this.currentAlarm.gereplacedemProperty("name").getValue().toString());
this.eventType.setValue(this.currentAlarm.gereplacedemProperty("eventType").getValue());
if (this.eventType.getValue().equals(EventType.JOB_FAILURE) && this.currentAlarm.gereplacedemProperty("regexMatch").getValue() != null) {
this.regexMatch.setValue(this.currentAlarm.gereplacedemProperty("regexMatch").getValue().toString());
}
this.severity.setValue(this.currentAlarm.gereplacedemProperty("severity").getValue());
this.alarmAction.setValue(this.currentAlarm.gereplacedemProperty("alarmAction").getValue());
if (this.alarmAction.getValue().equals(AlarmAction.EMAIL)) {
this.email.setValue(this.currentAlarm.gereplacedemProperty("receipientEmail").getValue().toString());
}
}
@SuppressWarnings("unchecked")
@Override
public void submitForm() {
try {
if (validateForm()) {
// creating add alarm with user entered data
BaseRequest<AlarmDto> request = createRequest();
request.getDto().setId(this.currentAlarm.getBean().getId());
log.info("Updating alarm - " + this.alarmName.getValue());
BaseResponse res = this.updateAlarmService.dispatch(request);
if (res.getId() == null) {
ViewUtil.iscNotification("Error updating the alarm", null, Notification.Type.TRAY_NOTIFICATION);
}
// updating bean in the table container
this.alarmView.getParentContainer().getContainerProperty(request.getDto().getId(), "name").setValue(this.alarmName.getValue().trim());
this.alarmView.getParentContainer().getContainerProperty(request.getDto().getId(), "eventType").setValue(this.eventType.getValue());
this.alarmView.getParentContainer().getContainerProperty(request.getDto().getId(), "regexMatch").setValue(this.regexMatch.getValue().trim());
this.alarmView.getParentContainer().getContainerProperty(request.getDto().getId(), "severity").setValue(this.severity.getValue());
this.alarmView.getParentContainer().getContainerProperty(request.getDto().getId(), "alarmAction").setValue(this.alarmAction.getValue());
this.alarmView.getParentContainer().getContainerProperty(request.getDto().getId(), "receipientEmail").setValue(this.email.getValue().trim());
this.alarmView.getParentContainer().getContainerProperty(request.getDto().getId(), "enabledAlarm").setValue(this.enabled.getValue());
close();
}
} catch (Exception e) {
log.info("Error updating alarm", e);
ViewUtil.iscNotification(e.getMessage(), Notification.Type.ERROR_MESSAGE);
}
}
}
15
Source : UpdateManagerConnectorWindow.java
with Apache License 2.0
from opensecuritycontroller
with Apache License 2.0
from opensecuritycontroller
@SuppressWarnings("serial")
public clreplaced UpdateManagerConnectorWindow extends CRUDBaseWindow<OkCancelButtonModel> {
private static final Logger log = LoggerFactory.getLogger(UpdateManagerConnectorWindow.clreplaced);
protected List<ErrorType> errorTypesToIgnore = new ArrayList<>();
final String CAPTION = "Edit Manager Connector";
// current view reference
private final ManagerConnectorView mcView;
// form fields
private TextField name = null;
private TextField type = null;
private TextField ip = null;
private TextField user = null;
private PreplacedwordField pw = null;
private PreplacedwordField apiKey = null;
private final BeanItem<ApplianceManagerConnectorDto> currentMCObject;
private ArrayList<CertificateResolverModel> certificateResolverModelsList = null;
private final UpdateApplianceManagerConnectorServiceApi updateMCService;
private final PluginService pluginService;
private final ValidationApi validator;
private final X509TrustManagerApi trustManager;
private final ServerApi server;
public UpdateManagerConnectorWindow(ManagerConnectorView mcView, UpdateApplianceManagerConnectorServiceApi updateMCService, PluginService pluginService, ValidationApi validator, X509TrustManagerApi trustManager, ServerApi server) throws Exception {
this.mcView = mcView;
this.updateMCService = updateMCService;
this.pluginService = pluginService;
this.validator = validator;
this.trustManager = trustManager;
this.server = server;
this.currentMCObject = mcView.getParentContainer().gereplacedem(mcView.getParenreplacedemId());
createWindow(this.CAPTION);
}
@Override
public void populateForm() throws Exception {
this.name = new TextField("Name");
this.name.setImmediate(true);
this.type = new TextField("Type");
this.type.setImmediate(true);
this.type.setEnabled(false);
this.ip = new TextField("IP");
this.ip.setImmediate(true);
this.user = new TextField("UserName");
this.user.setImmediate(true);
this.pw = new PreplacedwordField("Preplacedword");
this.pw.setImmediate(true);
this.apiKey = new PreplacedwordField("API Key");
this.apiKey.setVisible(false);
this.apiKey.setImmediate(true);
this.apiKey.setRequired(true);
this.apiKey.setRequiredError("Api Key cannot be empty");
// filling fields with existing information
this.name.setValue(this.currentMCObject.gereplacedemProperty("name").getValue().toString());
this.type.setValue(this.currentMCObject.gereplacedemProperty("managerType").getValue().toString());
this.ip.setValue(this.currentMCObject.gereplacedemProperty("ipAddress").getValue().toString());
if (this.pluginService.isKeyAuth(this.currentMCObject.gereplacedemProperty("managerType").getValue().toString())) {
this.apiKey.setVisible(true);
this.apiKey.setValue(this.currentMCObject.gereplacedemProperty("apiKey").getValue().toString());
this.user.setVisible(false);
this.user.setValue("");
this.pw.setVisible(false);
this.pw.setValue("");
} else {
this.apiKey.setVisible(false);
this.user.setVisible(true);
this.user.setValue(this.currentMCObject.gereplacedemProperty("username").getValue().toString());
this.pw.setVisible(true);
this.pw.setValue(this.currentMCObject.gereplacedemProperty("preplacedword").getValue().toString());
}
// adding not null constraint
this.name.setRequired(true);
this.name.setRequiredError("Name cannot be empty");
this.type.setRequired(true);
this.type.setRequiredError("Type cannot be empty");
this.ip.setRequired(true);
this.ip.setRequiredError("IP cannot be empty");
this.user.setRequired(true);
this.user.setRequiredError("User Name cannot be empty");
this.pw.setRequired(true);
this.pw.setRequiredError("Preplacedword cannot be empty");
this.form.setMargin(true);
this.form.setSizeUndefined();
this.form.addComponent(this.name);
this.form.addComponent(this.type);
this.form.addComponent(this.ip);
this.ip.focus();
this.form.addComponent(this.user);
this.form.addComponent(this.pw);
this.form.addComponent(this.apiKey);
}
@Override
public boolean validateForm() {
try {
this.name.validate();
this.type.validate();
this.ip.validate();
this.validator.checkValidIpAddress(this.ip.getValue());
if (this.pluginService.isKeyAuth(this.type.getValue().toString())) {
this.apiKey.validate();
} else {
this.user.validate();
this.pw.validate();
}
return true;
} catch (Exception e) {
ViewUtil.iscNotification(e.getMessage() + ".", Notification.Type.ERROR_MESSAGE);
}
return false;
}
@Override
public void submitForm() {
try {
if (validateForm()) {
createAndSubmitRequest();
}
} catch (Exception exception) {
sslAwareHandleException(exception);
}
}
@SuppressWarnings("unchecked")
private void createAndSubmitRequest() throws Exception {
// creating update request with user modified data
DryRunRequest<ApplianceManagerConnectorRequest> updateRequest = new DryRunRequest<>();
updateRequest.setDto(new ApplianceManagerConnectorRequest());
updateRequest.getDto().setId(this.currentMCObject.getBean().getId());
updateRequest.getDto().setName(this.name.getValue().trim());
updateRequest.getDto().setManagerType(this.type.getValue().trim());
updateRequest.getDto().setIpAddress(this.ip.getValue().trim());
updateRequest.getDto().setUsername(this.user.getValue().trim());
updateRequest.getDto().setPreplacedword(this.pw.getValue().trim());
updateRequest.getDto().setApiKey(this.apiKey.getValue().trim());
HashSet<SslCertificateAttrDto> sslSet = new HashSet<>();
if (this.certificateResolverModelsList != null) {
sslSet.addAll(this.certificateResolverModelsList.stream().map(crm -> new SslCertificateAttrDto(crm.getAlias(), crm.getSha1())).collect(Collectors.toList()));
updateRequest.getDto().setSslCertificateAttrSet(sslSet);
}
updateRequest.addErrorsToIgnore(this.errorTypesToIgnore);
log.debug("Updating manager connector - " + this.name.getValue().trim());
// no response needed for update request
BaseJobResponse response = this.updateMCService.dispatch(updateRequest);
// updating bean in the table container
this.mcView.getParentContainer().getContainerProperty(updateRequest.getDto().getId(), "name").setValue(this.name.getValue().trim());
this.mcView.getParentContainer().getContainerProperty(updateRequest.getDto().getId(), "managerType").setValue(this.type.getValue().trim());
this.mcView.getParentContainer().getContainerProperty(updateRequest.getDto().getId(), "ipAddress").setValue(this.ip.getValue().trim());
this.mcView.getParentContainer().getContainerProperty(updateRequest.getDto().getId(), "username").setValue(this.user.getValue().trim());
this.mcView.getParentContainer().getContainerProperty(updateRequest.getDto().getId(), "preplacedword").setValue(this.pw.getValue().trim());
this.mcView.getParentContainer().getContainerProperty(updateRequest.getDto().getId(), "apiKey").setValue(this.apiKey.getValue().trim());
close();
ViewUtil.showJobNotification(response.getJobId(), this.server);
}
protected void sslAwareHandleException(final Exception originalException) {
if (originalException instanceof SslCertificatesExtendedException) {
SslCertificatesExtendedException sslCertificateException = (SslCertificatesExtendedException) originalException;
ArrayList<CertificateResolverModel> certificateResolverModels = sslCertificateException.getCertificateResolverModels();
try {
ViewUtil.addWindow(new AddSSLCertificateWindow(certificateResolverModels, new AddSSLCertificateWindow.SSLCertificateWindowInterface() {
@Override
public void submitFormAction(ArrayList<CertificateResolverModel> certificateResolverModels) {
UpdateManagerConnectorWindow.this.certificateResolverModelsList = certificateResolverModels;
}
@Override
public void cancelFormAction() {
handleException(originalException);
}
}, this.trustManager));
} catch (Exception e) {
handleException(originalException);
}
} else {
handleException(originalException);
}
}
private void handleException(final Exception originalException) {
String caption = VmidcMessages.getString(VmidcMessages_.MC_CONFIRM_CAPTION);
String contentText = null;
final Throwable cause;
if (originalException instanceof ErrorTypeException) {
ErrorType errorType = ((ErrorTypeException) originalException).getType();
cause = originalException.getCause();
if (errorType == ErrorType.MANAGER_CONNECTOR_EXCEPTION) {
if (cause instanceof SocketException || cause instanceof SSLException || cause instanceof SocketTimeoutException) {
contentText = VmidcMessages.getString(VmidcMessages_.MC_CONFIRM_IP, StringEscapeUtils.escapeHtml(this.name.getValue()));
} else {
handleCatchAllException(new Exception(VmidcMessages.getString(VmidcMessages_.GENERAL_REST_ERROR, this.ip.getValue(), cause.getMessage()), cause));
return;
}
} else if (errorType == ErrorType.IP_CHANGED_EXCEPTION) {
contentText = VmidcMessages.getString(VmidcMessages_.MC_WARNING_IPUPDATE);
}
} else {
cause = originalException;
}
if (contentText != null) {
final VmidcWindow<OkCancelButtonModel> alertWindow = WindowUtil.createAlertWindow(caption, contentText);
alertWindow.getComponentModel().setOkClickedListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
if (validateForm()) {
try {
if (originalException instanceof ErrorTypeException) {
ErrorType errorType = ((ErrorTypeException) originalException).getType();
UpdateManagerConnectorWindow.this.errorTypesToIgnore.add(errorType);
}
createAndSubmitRequest();
} catch (Exception e) {
handleException(e);
}
}
alertWindow.close();
}
});
ViewUtil.addWindow(alertWindow);
} else {
handleCatchAllException(cause);
}
}
}
15
Source : BaseVCWindow.java
with Apache License 2.0
from opensecuritycontroller
with Apache License 2.0
from opensecuritycontroller
public abstract clreplaced BaseVCWindow extends CRUDBaseWindow<OkCancelButtonModel> {
private static final String OPENSTACK_ICEHOUSE = "Icehouse";
private static final String KUBERNETES_1_6 = "v1.6";
/**
*/
private static final long serialVersionUID = 1L;
private static final Logger log = LoggerFactory.getLogger(BaseVCWindow.clreplaced);
public static final String DEFAULT_HTTPS = "false";
public static final String DEFAULT_RABBITMQ_USER = "guest";
public static final String DEFAULT_RABBITMQ_USER_PreplacedWORD = "guest";
public static final String DEFAULT_RABBITMQ_PORT = "5672";
protected static final String SHOW_ADVANCED_SETTINGS_CAPTION = VmidcMessages.getString(VmidcMessages_.SHOW_ADVANCED);
protected static final String KEYSTONE_CAPTION = VmidcMessages.getString(VmidcMessages_.KEYSTONE);
protected static final String SDN_CONTROLLER_CAPTION = "SDN Controller";
protected static final String OPENSTACK_CAPTION = VmidcMessages.getString(VmidcMessages_.KEYSTONE);
protected Map<String, String> providerAttributes = new HashMap<>();
protected List<ErrorType> errorTypesToIgnore = new ArrayList<>();
private HashSet<SslCertificateAttrDto> sslCertificateAttrs = new HashSet<>();
// current view referencecurrentVCObject
protected VirtualizationConnectorView vcView = null;
protected BeanItem<VirtualizationConnectorDto> currentVCObject = null;
// form fields
protected TextField name = null;
protected ComboBox virtualizationType = null;
// Controller input fields
protected TextField controllerIP = null;
protected TextField controllerUser = null;
protected PreplacedwordField controllerPW = null;
// Provider input fields
protected TextField providerIP = null;
protected TextField adminDomainId = null;
protected TextField adminProjectName = null;
protected TextField providerUser = null;
protected PreplacedwordField providerPW = null;
// Open stack Input Fields
protected ComboBox controllerType = null;
// All Panels
protected Panel controllerPanel = null;
protected Panel providerPanel = null;
protected Button advancedSettings = null;
private final PluginService pluginService;
private final ValidationApi validator;
private final X509TrustManagerApi trustManager;
public BaseVCWindow(PluginService pluginService, ValidationApi validator, X509TrustManagerApi trustManager) {
super();
this.pluginService = pluginService;
this.validator = validator;
this.trustManager = trustManager;
}
@Override
public boolean validateForm() {
try {
this.name.validate();
this.virtualizationType.validate();
if (this.virtualizationType.getValue().toString().equals(VirtualizationType.OPENSTACK.toString())) {
String controllerType = (String) BaseVCWindow.this.controllerType.getValue();
if (!NO_CONTROLLER_TYPE.equals(controllerType) && !this.pluginService.usesProviderCreds(controllerType)) {
this.controllerIP.validate();
this.validator.checkValidIpAddress(this.controllerIP.getValue());
this.controllerUser.validate();
this.controllerPW.validate();
}
}
this.providerIP.validate();
this.validator.checkValidIpAddress(this.providerIP.getValue());
if (this.adminDomainId.isVisible()) {
this.adminDomainId.validate();
}
if (this.adminProjectName.isVisible()) {
this.adminProjectName.validate();
}
this.providerUser.validate();
this.providerPW.validate();
return true;
} catch (Exception e) {
ViewUtil.iscNotification(e.getMessage() + ".", Notification.Type.ERROR_MESSAGE);
}
return false;
}
protected void buildForm() {
this.name = new TextField("Name");
this.name.setImmediate(true);
this.virtualizationType = new ComboBox("Type");
this.virtualizationType.setTextInputAllowed(false);
this.virtualizationType.setNullSelectionAllowed(false);
for (VirtualizationType virtualizationType : VirtualizationType.values()) {
this.virtualizationType.addItem(virtualizationType.toString());
}
this.virtualizationType.select(VirtualizationType.OPENSTACK.toString());
// adding not null constraint
this.name.setRequired(true);
this.name.setRequiredError("Name cannot be empty");
this.virtualizationType.setRequired(true);
this.virtualizationType.setRequiredError("Type cannot be empty");
this.form.setMargin(true);
this.form.setSizeUndefined();
this.form.addComponent(this.name);
this.name.focus();
this.form.addComponent(this.virtualizationType);
this.form.addComponent(controllerPanel());
this.form.addComponent(providerPanel());
this.advancedSettings = new Button(SHOW_ADVANCED_SETTINGS_CAPTION);
this.advancedSettings.setImmediate(true);
this.advancedSettings.setVisible(false);
this.advancedSettings.addClickListener(new ClickListener() {
/**
*/
private static final long serialVersionUID = 7124022733079327543L;
@Override
public void buttonClick(ClickEvent event) {
advancedSettingsClicked();
}
});
this.form.addComponent(this.advancedSettings);
}
// Returns OpenStack form
protected Panel providerPanel() {
this.providerPanel = new Panel();
this.providerPanel.setImmediate(true);
this.providerPanel.setCaption(OPENSTACK_CAPTION);
this.providerIP = new TextField("IP");
this.providerIP.setImmediate(true);
this.adminDomainId = new TextField("Admin Domain Id");
this.adminDomainId.setImmediate(true);
this.adminProjectName = new TextField("Admin Project Name");
this.adminProjectName.setImmediate(true);
this.providerUser = new TextField("User Name");
this.providerUser.setImmediate(true);
this.providerPW = new PreplacedwordField("Preplacedword");
this.providerPW.setImmediate(true);
// adding not null constraint
this.adminDomainId.setRequired(true);
this.adminDomainId.setRequiredError(this.providerPanel.getCaption() + " Admin Domain Id cannot be empty");
this.adminProjectName.setRequired(true);
this.adminProjectName.setRequiredError(this.providerPanel.getCaption() + " Admin Project Name cannot be empty");
this.providerIP.setRequired(true);
this.providerIP.setRequiredError(this.providerPanel.getCaption() + " IP cannot be empty");
this.providerUser.setRequired(true);
this.providerUser.setRequiredError(this.providerPanel.getCaption() + " User Name cannot be empty");
this.providerPW.setRequired(true);
this.providerPW.setRequiredError(this.providerPanel.getCaption() + " Preplacedword cannot be empty");
FormLayout providerFormPanel = new FormLayout();
providerFormPanel.addComponent(this.providerIP);
providerFormPanel.addComponent(this.adminDomainId);
providerFormPanel.addComponent(this.adminProjectName);
providerFormPanel.addComponent(this.providerUser);
providerFormPanel.addComponent(this.providerPW);
this.providerPanel.setContent(providerFormPanel);
return this.providerPanel;
}
protected Panel controllerPanel() {
this.controllerPanel = new Panel();
this.controllerPanel.setImmediate(true);
this.controllerPanel.setCaption(SDN_CONTROLLER_CAPTION);
this.controllerType = new ComboBox("Type");
this.controllerType.setTextInputAllowed(false);
this.controllerType.setNullSelectionAllowed(false);
this.controllerType.addItem(NO_CONTROLLER_TYPE);
for (String ct : this.pluginService.getControllerTypes()) {
this.controllerType.addItem(ct);
}
this.controllerType.setVisible(true);
this.controllerIP = new TextField("IP");
this.controllerIP.setImmediate(true);
this.controllerUser = new TextField("User Name");
this.controllerUser.setImmediate(true);
this.controllerPW = new PreplacedwordField("Preplacedword");
this.controllerPW.setImmediate(true);
// adding not null constraint
this.controllerIP.setRequired(true);
this.controllerIP.setRequiredError(this.controllerPanel.getCaption() + " IP cannot be empty");
this.controllerUser.setRequired(true);
this.controllerUser.setRequiredError(this.controllerPanel.getCaption() + " User Name cannot be empty");
this.controllerPW.setRequired(true);
this.controllerPW.setRequiredError(this.controllerPanel.getCaption() + " Preplacedword cannot be empty");
FormLayout sdn = new FormLayout();
sdn.addComponent(this.controllerType);
sdn.addComponent(this.controllerIP);
sdn.addComponent(this.controllerUser);
sdn.addComponent(this.controllerPW);
this.controllerPanel.setContent(sdn);
this.controllerType.addValueChangeListener(event -> updateControllerFields((String) BaseVCWindow.this.controllerType.getValue()));
this.controllerType.select(NO_CONTROLLER_TYPE);
return this.controllerPanel;
}
protected void handleException(final Exception originalException) {
String caption = VmidcMessages.getString(VmidcMessages_.VC_CONFIRM_CAPTION);
String contentText = null;
final Throwable exception;
if (originalException instanceof ErrorTypeException) {
ErrorType errorType = ((ErrorTypeException) originalException).getType();
exception = originalException.getCause();
// TODO this exception leaks large amounts of implementation detail out of the API
if (isOpenstack()) {
switch(errorType) {
case PROVIDER_EXCEPTION:
if (RestClientException.isConnectException(exception)) {
// Keystone Connect Exception
contentText = VmidcMessages.getString(VmidcMessages_.VC_CONFIRM_IP, KEYSTONE_CAPTION);
} else {
contentText = VmidcMessages.getString(VmidcMessages_.VC_CONFIRM_GENERAL, KEYSTONE_CAPTION, exception.getMessage());
}
break;
case PROVIDER_CONNECT_EXCEPTION:
contentText = VmidcMessages.getString(VmidcMessages_.VC_CONFIRM_IP, KEYSTONE_CAPTION);
break;
case PROVIDER_AUTH_EXCEPTION:
contentText = VmidcMessages.getString(VmidcMessages_.VC_CONFIRM_CREDS, KEYSTONE_CAPTION);
break;
case CONTROLLER_EXCEPTION:
contentText = handleControllerException(exception);
break;
case RABBITMQ_EXCEPTION:
contentText = VmidcMessages.getString(VmidcMessages_.VC_CONFIRM_RABBIT, exception.getMessage());
break;
case IP_CHANGED_EXCEPTION:
contentText = VmidcMessages.getString(VmidcMessages_.VC_WARNING_IPUPDATE);
break;
default:
contentText = VmidcMessages.getString(VmidcMessages_.VC_CONFIRM_GENERAL, KEYSTONE_CAPTION, exception.getMessage());
break;
}
}
} else if (originalException instanceof RestClientException) {
RestClientException rce = (RestClientException) originalException;
handleCatchAllException(new Exception(VmidcMessages.getString(VmidcMessages_.GENERAL_REST_ERROR, rce.getHost(), rce.getMessage()), originalException));
return;
} else {
exception = originalException;
}
if (contentText != null) {
final VmidcWindow<OkCancelButtonModel> alertWindow = WindowUtil.createAlertWindow(caption, contentText);
alertWindow.getComponentModel().setOkClickedListener(event -> {
try {
if (originalException instanceof ErrorTypeException) {
ErrorType errorType = ((ErrorTypeException) originalException).getType();
BaseVCWindow.this.errorTypesToIgnore.add(errorType);
}
submitForm();
} catch (Exception e) {
handleException(e);
}
alertWindow.close();
});
ViewUtil.addWindow(alertWindow);
} else {
handleCatchAllException(exception);
}
}
private boolean isOpenstack() {
return VirtualizationType.fromText(this.virtualizationType.getValue().toString()) == VirtualizationType.OPENSTACK;
}
private String handleControllerException(Throwable exception) {
String contentText = null;
if (RestClientException.isCredentialError(exception)) {
// SDN Invalid Credential Exception
contentText = VmidcMessages.getString(VmidcMessages_.VC_CONFIRM_CREDS, this.controllerType.getValue().toString());
} else if (RestClientException.isConnectException(exception)) {
// SDN Controller Connect Exception
contentText = VmidcMessages.getString(VmidcMessages_.VC_CONFIRM_IP, this.controllerType.getValue().toString());
} else {
// SDN Controller Connect Exception
contentText = VmidcMessages.getString(VmidcMessages_.VC_CONFIRM_GENERAL, this.controllerType.getValue().toString(), exception.getMessage());
}
return contentText;
}
void sslAwareHandleException(final Exception originalException) {
if (!(originalException instanceof SslCertificatesExtendedException)) {
handleException(originalException);
return;
}
SslCertificatesExtendedException unknownException = (SslCertificatesExtendedException) originalException;
ArrayList<CertificateResolverModel> certificateResolverModels = unknownException.getCertificateResolverModels();
try {
ViewUtil.addWindow(new AddSSLCertificateWindow(certificateResolverModels, new AddSSLCertificateWindow.SSLCertificateWindowInterface() {
@Override
public void submitFormAction(ArrayList<CertificateResolverModel> certificateResolverModels) {
if (certificateResolverModels != null) {
BaseVCWindow.this.sslCertificateAttrs.addAll(certificateResolverModels.stream().map(crm -> new SslCertificateAttrDto(crm.getAlias(), crm.getSha1())).collect(Collectors.toList()));
}
}
@Override
public void cancelFormAction() {
handleException(originalException);
}
}, this.trustManager));
} catch (Exception e) {
handleException(originalException);
}
}
/**
* Create and submits the add connector request.
*/
protected DryRunRequest<VirtualizationConnectorRequest> createRequest() throws Exception {
DryRunRequest<VirtualizationConnectorRequest> request = new DryRunRequest<>();
request.setDto(new VirtualizationConnectorRequest());
VirtualizationConnectorDto dto = request.getDto();
dto.setName(this.name.getValue().trim());
VirtualizationType virtualizationTypeValue = VirtualizationType.fromText(((String) this.virtualizationType.getValue()).trim());
dto.setType(virtualizationTypeValue);
dto.setControllerIP(this.controllerIP.getValue().trim());
dto.setControllerUser(this.controllerUser.getValue().trim());
dto.setControllerPreplacedword(this.controllerPW.getValue().trim());
dto.setProviderIP(this.providerIP.getValue().trim());
dto.setProviderUser(this.providerUser.getValue().trim());
dto.setProviderPreplacedword(this.providerPW.getValue().trim());
dto.setSslCertificateAttrSet(this.sslCertificateAttrs);
String domainId = this.adminDomainId.getValue();
if (domainId != null) {
dto.setAdminDomainId(domainId.trim());
}
String projectName = this.adminProjectName.getValue();
if (projectName != null) {
dto.setAdminProjectName(projectName.trim());
}
if (virtualizationTypeValue.equals(VirtualizationType.OPENSTACK)) {
dto.setProviderAttributes(this.providerAttributes);
}
request.addErrorsToIgnore(this.errorTypesToIgnore);
// TODO: Future. Get virtualization version this from user.
if (this.virtualizationType.getValue().equals(VirtualizationType.OPENSTACK.toString())) {
request.getDto().setSoftwareVersion(OPENSTACK_ICEHOUSE);
} else {
request.getDto().setSoftwareVersion(KUBERNETES_1_6);
}
request.getDto().setControllerType((String) BaseVCWindow.this.controllerType.getValue());
return request;
}
protected void advancedSettingsClicked() {
try {
ViewUtil.addWindow(new AdvancedSettingsWindow(this));
} catch (Exception e) {
ViewUtil.iscNotification(e.toString() + ".", Notification.Type.ERROR_MESSAGE);
}
}
protected void updateForm(String type) {
this.controllerIP.setValue("");
this.controllerUser.setValue("");
this.controllerPW.setValue("");
this.controllerPanel.setVisible(true);
if (type.equals(VirtualizationType.OPENSTACK.toString())) {
this.controllerPanel.setCaption(SDN_CONTROLLER_CAPTION);
this.providerPanel.setCaption(OPENSTACK_CAPTION);
this.controllerType.setVisible(true);
this.controllerType.setValue(NO_CONTROLLER_TYPE);
updateControllerFields(NO_CONTROLLER_TYPE);
this.adminDomainId.setVisible(true);
this.adminProjectName.setVisible(true);
this.advancedSettings.setVisible(true);
this.advancedSettings.setCaption(SHOW_ADVANCED_SETTINGS_CAPTION);
updateProviderFields();
}
this.controllerIP.setRequiredError(this.controllerPanel.getCaption() + " IP cannot be empty");
this.controllerUser.setRequiredError(this.controllerPanel.getCaption() + " User Name cannot be empty");
this.controllerPW.setRequiredError(this.controllerPanel.getCaption() + " Preplacedword cannot be empty");
this.providerIP.setRequiredError(this.providerPanel.getCaption() + " IP cannot be empty");
this.providerUser.setRequiredError(this.providerPanel.getCaption() + " User Name cannot be empty");
this.providerPW.setRequiredError(this.providerPanel.getCaption() + " Preplacedword cannot be empty");
this.adminDomainId.setRequiredError(this.providerPanel.getCaption() + " Admin Domain Id cannot be empty");
this.adminProjectName.setRequiredError(this.providerPanel.getCaption() + " Admin Project Name cannot be empty");
}
private void updateControllerFields(String type) {
boolean enableFields = false;
if (!type.equals(NO_CONTROLLER_TYPE)) {
try {
enableFields = !this.pluginService.usesProviderCreds(type.toString());
} catch (Exception e) {
log.error("Fail to get controller plugin instance", e);
}
}
BaseVCWindow.this.controllerIP.setEnabled(enableFields);
BaseVCWindow.this.controllerIP.setRequired(enableFields);
BaseVCWindow.this.controllerUser.setEnabled(enableFields);
BaseVCWindow.this.controllerUser.setRequired(enableFields);
BaseVCWindow.this.controllerPW.setEnabled(enableFields);
BaseVCWindow.this.controllerPW.setRequired(enableFields);
if (!enableFields) {
this.controllerIP.setValue("");
this.controllerUser.setValue("");
this.controllerPW.setValue("");
}
}
private void updateProviderFields() {
if (BaseVCWindow.this.virtualizationType.getValue().equals(VirtualizationType.OPENSTACK.toString())) {
// If user does not click advanced Settings we need to populate attributes with default values..
this.providerAttributes.put(ATTRIBUTE_KEY_HTTPS, DEFAULT_HTTPS);
this.providerAttributes.put(ATTRIBUTE_KEY_RABBITMQ_USER, DEFAULT_RABBITMQ_USER);
this.providerAttributes.put(ATTRIBUTE_KEY_RABBITMQ_PORT, DEFAULT_RABBITMQ_PORT);
this.providerAttributes.put(ATTRIBUTE_KEY_RABBITMQ_USER_PreplacedWORD, DEFAULT_RABBITMQ_USER_PreplacedWORD);
}
}
}
14
Source : UpdateUserWindow.java
with Apache License 2.0
from opensecuritycontroller
with Apache License 2.0
from opensecuritycontroller
public clreplaced UpdateUserWindow extends CRUDBaseWindow<OkCancelButtonModel> {
/**
*/
private static final long serialVersionUID = 1L;
final String CAPTION = "Edit User";
private static final Logger log = LoggerFactory.getLogger(UpdateUserWindow.clreplaced);
public static final String ROLE_ADMIN = "ADMIN";
// form fields
private TextField firstName = null;
private TextField lastName = null;
private TextField loginName = null;
private PreplacedwordField preplacedword = null;
private TextField email = null;
private ComboBox role = null;
private final BeanItem<UserDto> currentUser;
private final UpdateUserServiceApi updateUserService;
private final ServerApi server;
public UpdateUserWindow(UserView userView, UpdateUserServiceApi updateUserService, ServerApi server) throws Exception {
this.currentUser = userView.getParenreplacedem();
this.updateUserService = updateUserService;
this.server = server;
createWindow(this.CAPTION);
}
@Override
public void populateForm() {
this.loginName = new TextField("User Name");
this.loginName.setImmediate(true);
this.firstName = new TextField("First Name");
this.lastName = new TextField("Last Name");
this.preplacedword = new PreplacedwordField("Preplacedword");
this.preplacedword.setImmediate(true);
this.email = new TextField("Email");
this.email.addValidator(new EmailValidator("Please enter a valid email address"));
this.role = new ComboBox("Role");
this.role.setTextInputAllowed(false);
this.role.setNullSelectionAllowed(false);
this.role.addItem(UpdateUserWindow.ROLE_ADMIN);
this.role.select(UpdateUserWindow.ROLE_ADMIN);
// filling fields with existing information
this.loginName.setValue(this.currentUser.gereplacedemProperty("loginName").getValue().toString());
this.loginName.setEnabled(false);
this.preplacedword.setValue(this.currentUser.gereplacedemProperty("preplacedword").getValue().toString());
if (this.currentUser.gereplacedemProperty("email").getValue() != null) {
this.email.setValue(this.currentUser.gereplacedemProperty("email").getValue().toString());
}
if (this.currentUser.gereplacedemProperty("firstName").getValue() != null) {
this.firstName.setValue(this.currentUser.gereplacedemProperty("firstName").getValue().toString());
}
if (this.currentUser.gereplacedemProperty("lastName").getValue() != null) {
this.lastName.setValue(this.currentUser.gereplacedemProperty("lastName").getValue().toString());
}
this.role.setValue(this.currentUser.gereplacedemProperty("role").getValue().toString());
// adding not null constraint
this.loginName.setRequired(true);
this.loginName.setRequiredError("User Name cannot be Empty");
this.preplacedword.setRequired(true);
this.preplacedword.setRequiredError("Preplacedword Cannot be empty");
this.role.setRequired(true);
this.form.setMargin(true);
this.form.setSizeUndefined();
this.form.addComponent(this.loginName);
this.form.addComponent(this.firstName);
this.form.addComponent(this.lastName);
this.form.addComponent(this.preplacedword);
this.form.addComponent(this.email);
this.form.addComponent(this.role);
this.firstName.focus();
}
@Override
public boolean validateForm() {
try {
this.loginName.validate();
this.preplacedword.validate();
this.email.validate();
this.role.validate();
return true;
} catch (Exception e) {
log.debug("Validation error");
ViewUtil.iscNotification(e.getMessage() + ".", Notification.Type.ERROR_MESSAGE);
}
return false;
}
@Override
public void submitForm() {
try {
if (validateForm()) {
// creating add request with user entered data
UpdateUserRequest updateRequest = new UpdateUserRequest();
updateRequest.setId(this.currentUser.getBean().getId());
updateRequest.setFirstName(this.firstName.getValue().trim());
updateRequest.setLastName(this.lastName.getValue().trim());
updateRequest.setLoginName(this.loginName.getValue().trim());
updateRequest.setEmail(this.email.getValue().trim());
updateRequest.setPreplacedword(this.preplacedword.getValue());
updateRequest.setRole(this.role.getValue().toString());
log.info("Updating user - " + this.loginName.getValue());
UpdateUserResponse res = this.updateUserService.dispatch(updateRequest);
if (res.getJobId() != null) {
ViewUtil.showJobNotification(res.getJobId(), this.server);
}
close();
}
} catch (Exception e) {
log.info("Error updating user", e);
ViewUtil.iscNotification(e.getMessage(), Notification.Type.ERROR_MESSAGE);
}
}
}
14
Source : CRUDBaseSubView.java
with Apache License 2.0
from opensecuritycontroller
with Apache License 2.0
from opensecuritycontroller
/**
* @param <P>
* Parent DTO for this subView
* @param <C>
* children of the given parent object
*/
public abstract clreplaced CRUDBaseSubView<P extends BaseDto, C extends BaseDto> extends CssLayout {
/**
*/
private static final long serialVersionUID = 1L;
protected static final long NULL_SELECTION_ITEM_ID = -1L;
protected String replacedle;
protected CRUDBaseView<?, ?> currentView;
protected BeanItem<C> selectedItem;
protected long selectedItemId;
public FilterTable table;
protected BeanContainer<Long, C> tableContainer;
protected HorizontalLayout toolbar;
protected P parent;
protected ToolbarButtons[] buttons;
@SuppressWarnings("serial")
private final ClickListener buttonClickListener = new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
try {
buttonClicked(event);
} catch (Exception e) {
ViewUtil.showError("Error invoking action in subview", e);
}
}
};
public CRUDBaseSubView(CRUDBaseView<?, ?> currentView, String replacedle, ToolbarButtons[] buttons, P parent) {
super();
this.replacedle = replacedle;
this.currentView = currentView;
this.buttons = buttons;
this.parent = parent;
}
@Override
public void attach() {
// Note this must not be run in the constructor as the concrete
// sub-type will not be fully initialized (its constructor will not
// yet have run!).
createSubView(this.replacedle, this.buttons);
}
private void createSubView(String replacedle, ToolbarButtons[] buttons) {
setSizeFull();
final VerticalLayout layout = new VerticalLayout();
layout.addStyleName(StyleConstants.BASE_CONTAINER);
layout.setSizeFull();
final VerticalLayout panel = new VerticalLayout();
panel.addStyleName("panel");
panel.setSizeFull();
layout.addComponent(createHeader(replacedle));
layout.addComponent(panel);
if (buttons != null) {
panel.addComponent(createToolbar(buttons));
}
panel.addComponent(createTable());
panel.setExpandRatio(this.table, 1L);
layout.setExpandRatio(panel, 1L);
addComponent(layout);
}
@SuppressWarnings("serial")
private FilterTable createTable() {
this.table = new FilterTable();
this.table.setStyleName(ValoTheme.TABLE_COMPACT);
this.table.setSizeFull();
this.table.setSelectable(true);
this.table.setColumnCollapsingAllowed(true);
this.table.setColumnReorderingAllowed(true);
this.table.setImmediate(true);
this.table.setNullSelectionAllowed(false);
this.table.setFilterBarVisible(true);
this.table.setFilterGenerator(ViewUtil.getFilterGenerator());
initTable();
populateTable();
if (this.table.firsreplacedemId() != null) {
tableClicked((Long) this.table.firsreplacedemId());
this.table.setValue(this.table.firsreplacedemId());
}
// Handle Selection when filtering changes the items
this.table.addItemSetChangeListener(new ItemSetChangeListener() {
@Override
public void containerItemSetChange(ItemSetChangeEvent event) {
// If the table is empty, reset the selection so the child table updates itself
if (CRUDBaseSubView.this.table.gereplacedemIds().size() == 0) {
CRUDBaseSubView.this.table.setValue(null);
} else if (CRUDBaseSubView.this.table.getValue() == null || CRUDBaseSubView.this.table.getValue() instanceof Set && ((Set<?>) CRUDBaseSubView.this.table.getValue()).isEmpty()) {
// If the table does not have a selection but has items, select the first item
tableClicked((Long) CRUDBaseSubView.this.table.firsreplacedemId());
CRUDBaseSubView.this.table.setValue(CRUDBaseSubView.this.table.firsreplacedemId());
}
}
});
// Handle selection changes
this.table.addValueChangeListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
Object value = event.getProperty().getValue();
if (value != null) {
tableClicked((Long) value);
} else {
tableClicked(NULL_SELECTION_ITEM_ID);
}
}
});
return this.table;
}
// returns Header layout with view replacedle
@SuppressWarnings("serial")
private HorizontalLayout createHeader(String replacedle) {
HorizontalLayout header = ViewUtil.createSubHeader(replacedle, getSubViewHelpGuid());
Button refresh = new Button();
refresh.setStyleName(Reindeer.BUTTON_LINK);
refresh.setDescription("Refresh");
refresh.setIcon(new ThemeResource("img/Refresh.png"));
refresh.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
populateTable();
}
});
header.addComponent(refresh);
return header;
}
public HorizontalLayout createToolbar(ToolbarButtons[] crudButtons) {
this.toolbar = new HorizontalLayout();
this.toolbar.addStyleName("buttonToolbar");
for (ToolbarButtons button : crudButtons) {
if (button == null) {
continue;
}
Button buttonComponent = ViewUtil.buildToolbarButton(this.toolbar, button, this.buttonClickListener);
if (button == ToolbarButtons.ADD || button == ToolbarButtons.BACK) {
buttonComponent.setEnabled(true);
}
}
return this.toolbar;
}
protected String getSubViewHelpGuid() {
return null;
}
protected void tableClicked(long selectedItemId) {
if (selectedItemId != NULL_SELECTION_ITEM_ID) {
ViewUtil.setButtonsEnabled(true, this.toolbar);
setSelectedItemId(selectedItemId);
setSelectedItem(this.tableContainer.gereplacedem(this.selectedItemId));
this.table.setValue(selectedItemId);
} else {
ViewUtil.setButtonsEnabled(false, this.toolbar, Arrays.asList(ToolbarButtons.ADD.getId(), ToolbarButtons.BACK.getId()));
}
}
public BeanContainer<Long, C> getTableContainer() {
return this.tableContainer;
}
public void setTableContainer(BeanContainer<Long, C> tableContainer) {
this.tableContainer = tableContainer;
}
public long getSelectedItemId() {
return this.selectedItemId;
}
public void setSelectedItemId(long selectedItemId) {
this.selectedItemId = selectedItemId;
}
public BeanItem<C> getSelectedItem() {
return this.selectedItem;
}
public void setSelectedItem(BeanItem<C> selectedItem) {
this.selectedItem = selectedItem;
}
@SuppressWarnings("unchecked")
public void syncTable(BroadcastMessage msg, GetDtoFromEnreplacedyServiceFactoryApi getDtoFromEnreplacedyServiceFactory) throws Exception {
if (msg.getEventType().equals(EventType.DELETED)) {
// delete item from child container
getTableContainer().removeItem(msg.getEnreplacedyId());
if (this.table.firsreplacedemId() != null) {
// select first element from the table
tableClicked((Long) this.table.firsreplacedemId());
} else {
ViewUtil.setButtonsEnabled(false, this.toolbar, Arrays.asList(ToolbarButtons.ADD.getId(), ToolbarButtons.BACK.getId()));
}
} else {
C dto = null;
if (msg.getDto() == null) {
GetDtoFromEnreplacedyRequest req = new GetDtoFromEnreplacedyRequest();
req.setEnreplacedyId(msg.getEnreplacedyId());
req.setEnreplacedyName(msg.getReceiver());
ParameterizedType parameterizedType = (ParameterizedType) getClreplaced().getGenericSuperclreplaced();
Clreplaced<C> childClreplaced = (Clreplaced<C>) parameterizedType.getActualTypeArguments()[1];
GetDtoFromEnreplacedyServiceApi<C> getDtoService = getDtoFromEnreplacedyServiceFactory.getService(childClreplaced);
BaseDtoResponse<C> res = getDtoService.dispatch(req);
dto = res.getDto();
} else {
dto = (C) msg.getDto();
}
if (msg.getEventType().equals(EventType.UPDATED) && getTableContainer().gereplacedem(msg.getEnreplacedyId()) != null) {
ViewUtil.updateTableContainer(this.tableContainer, dto, this.table);
} else {
// check if the item belongs to the same parent enreplacedy which user is looking at
if (dto.getParentId().equals(this.currentView.getChildItemId())) {
// add item to sun view table
getTableContainer().addItemAt(0, msg.getEnreplacedyId(), dto);
}
}
}
}
@SuppressWarnings("unchecked")
protected P getDtoInContext() {
return (P) this.currentView.getChildContainer().gereplacedem(this.currentView.getChildItemId()).getBean();
}
public abstract void initTable();
public abstract void populateTable();
public abstract void buttonClicked(ClickEvent event) throws Exception;
}
14
Source : FaultContainer.java
with Apache License 2.0
from ijazfx
with Apache License 2.0
from ijazfx
@Override
protected boolean preplacedesFilters(Object itemId) {
BeanItem<Fault<ID, BEANTYPE>> item = getUnfilteredItem(itemId);
if (getFilters().isEmpty() || item.getBean() == null) {
return true;
}
final Iterator<Filter> i = getFilters().iterator();
while (i.hasNext()) {
final Filter f = i.next();
if (f instanceof SimpleStringFilter) {
SimpleStringFilter sf = (SimpleStringFilter) f;
KeyValueWrapper kvw = new KeyValueWrapper(item.getBean().getValue());
String value = kvw.stringForKeyPath(sf.getPropertyId().toString());
if (value == null) {
return false;
}
if (sf.isIgnoreCase()) {
if (sf.isOnlyMatchPrefix()) {
return value.toLowerCase().startsWith(sf.getFilterString().toLowerCase());
}
return value.toLowerCase().contains(sf.getFilterString().toLowerCase());
} else {
if (sf.isOnlyMatchPrefix()) {
return value.startsWith(sf.getFilterString());
}
return value.contains(sf.getFilterString());
}
}
if (!f.preplacedesFilter(itemId, item)) {
return false;
}
}
return true;
}
14
Source : BeanFaultContainer.java
with Apache License 2.0
from ijazfx
with Apache License 2.0
from ijazfx
@Override
protected boolean preplacedesFilters(Object itemId) {
BeanItem<BeanFault<ID, BEANTYPE>> item = getUnfilteredItem(itemId);
if (getFilters().isEmpty() || item.getBean() == null) {
return true;
}
final Iterator<Filter> i = getFilters().iterator();
while (i.hasNext()) {
final Filter f = i.next();
if (f instanceof SimpleStringFilter) {
SimpleStringFilter sf = (SimpleStringFilter) f;
KeyValueWrapper kvw = new KeyValueWrapper(item.getBean().getBean());
String value = kvw.stringForKeyPath(sf.getPropertyId().toString());
if (value == null) {
return false;
}
if (sf.isIgnoreCase()) {
if (sf.isOnlyMatchPrefix()) {
return value.toLowerCase().startsWith(sf.getFilterString().toLowerCase());
}
return value.toLowerCase().contains(sf.getFilterString().toLowerCase());
} else {
if (sf.isOnlyMatchPrefix()) {
return value.startsWith(sf.getFilterString());
}
return value.contains(sf.getFilterString());
}
}
if (!f.preplacedesFilter(itemId, item)) {
return false;
}
}
return true;
}