Merge pull request #274 from bsinno/fix_dialog_window_must_not_close_after_save_if_duplicate_exists

Fix for the dialog window must not close after save if duplicate exists.
This commit is contained in:
Kai Zimmermann
2016-09-01 11:37:58 +02:00
committed by GitHub
29 changed files with 510 additions and 432 deletions

View File

@@ -24,7 +24,7 @@ import org.eclipse.hawkbit.security.ControllerPreAuthenticatedGatewaySecurityTok
import org.eclipse.hawkbit.security.ControllerPreAuthenticatedSecurityHeaderFilter; import org.eclipse.hawkbit.security.ControllerPreAuthenticatedSecurityHeaderFilter;
import org.eclipse.hawkbit.security.DdiSecurityProperties; import org.eclipse.hawkbit.security.DdiSecurityProperties;
import org.eclipse.hawkbit.security.PreAuthTokenSourceTrustAuthenticationProvider; import org.eclipse.hawkbit.security.PreAuthTokenSourceTrustAuthenticationProvider;
import org.eclipse.hawkbit.security.PreAuthenficationFilter; import org.eclipse.hawkbit.security.PreAuthentificationFilter;
import org.eclipse.hawkbit.security.SystemSecurityContext; import org.eclipse.hawkbit.security.SystemSecurityContext;
import org.eclipse.hawkbit.tenancy.TenantAware; import org.eclipse.hawkbit.tenancy.TenantAware;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -45,7 +45,7 @@ public class AmqpControllerAuthentfication {
private final PreAuthTokenSourceTrustAuthenticationProvider preAuthenticatedAuthenticationProvider; private final PreAuthTokenSourceTrustAuthenticationProvider preAuthenticatedAuthenticationProvider;
private final List<PreAuthenficationFilter> filterChain = new ArrayList<>(); private final List<PreAuthentificationFilter> filterChain = new ArrayList<>();
@Autowired @Autowired
private ControllerManagement controllerManagement; private ControllerManagement controllerManagement;
@@ -107,7 +107,7 @@ public class AmqpControllerAuthentfication {
*/ */
public Authentication doAuthenticate(final TenantSecurityToken secruityToken) { public Authentication doAuthenticate(final TenantSecurityToken secruityToken) {
PreAuthenticatedAuthenticationToken authentication = new PreAuthenticatedAuthenticationToken(null, null); PreAuthenticatedAuthenticationToken authentication = new PreAuthenticatedAuthenticationToken(null, null);
for (final PreAuthenficationFilter filter : filterChain) { for (final PreAuthentificationFilter filter : filterChain) {
final PreAuthenticatedAuthenticationToken authenticationRest = createAuthentication(filter, secruityToken); final PreAuthenticatedAuthenticationToken authenticationRest = createAuthentication(filter, secruityToken);
if (authenticationRest != null) { if (authenticationRest != null) {
authentication = authenticationRest; authentication = authenticationRest;
@@ -119,7 +119,7 @@ public class AmqpControllerAuthentfication {
} }
private static PreAuthenticatedAuthenticationToken createAuthentication(final PreAuthenficationFilter filter, private static PreAuthenticatedAuthenticationToken createAuthentication(final PreAuthentificationFilter filter,
final TenantSecurityToken secruityToken) { final TenantSecurityToken secruityToken) {
if (!filter.isEnable(secruityToken)) { if (!filter.isEnable(secruityToken)) {

View File

@@ -68,7 +68,7 @@ public abstract class AbstractHttpControllerAuthenticationFilter extends Abstrac
private final AntPathMatcher pathExtractor; private final AntPathMatcher pathExtractor;
private PreAuthenficationFilter abstractControllerAuthenticationFilter; private PreAuthentificationFilter abstractControllerAuthenticationFilter;
/** /**
* Constructor for sub-classes. * Constructor for sub-classes.
@@ -111,7 +111,7 @@ public abstract class AbstractHttpControllerAuthenticationFilter extends Abstrac
} }
} }
protected abstract PreAuthenficationFilter createControllerAuthenticationFilter(); protected abstract PreAuthentificationFilter createControllerAuthenticationFilter();
@Override @Override
protected void successfulAuthentication(final HttpServletRequest request, final HttpServletResponse response, protected void successfulAuthentication(final HttpServletRequest request, final HttpServletResponse response,

View File

@@ -39,7 +39,7 @@ public class HttpControllerPreAuthenticateAnonymousDownloadFilter extends Abstra
} }
@Override @Override
protected PreAuthenficationFilter createControllerAuthenticationFilter() { protected PreAuthentificationFilter createControllerAuthenticationFilter() {
return new ControllerPreAuthenticatedAnonymousDownload(tenantConfigurationManagement, tenantAware, return new ControllerPreAuthenticatedAnonymousDownload(tenantConfigurationManagement, tenantAware,
systemSecurityContext); systemSecurityContext);
} }

View File

@@ -55,7 +55,7 @@ public class HttpControllerPreAuthenticateSecurityTokenFilter extends AbstractHt
} }
@Override @Override
protected PreAuthenficationFilter createControllerAuthenticationFilter() { protected PreAuthentificationFilter createControllerAuthenticationFilter() {
return new ControllerPreAuthenticateSecurityTokenFilter(tenantConfigurationManagement, controllerManagement, return new ControllerPreAuthenticateSecurityTokenFilter(tenantConfigurationManagement, controllerManagement,
tenantAware, systemSecurityContext); tenantAware, systemSecurityContext);
} }

View File

@@ -43,7 +43,7 @@ public class HttpControllerPreAuthenticatedGatewaySecurityTokenFilter
} }
@Override @Override
protected PreAuthenficationFilter createControllerAuthenticationFilter() { protected PreAuthentificationFilter createControllerAuthenticationFilter() {
return new ControllerPreAuthenticatedGatewaySecurityTokenFilter(tenantConfigurationManagement, tenantAware, return new ControllerPreAuthenticatedGatewaySecurityTokenFilter(tenantConfigurationManagement, tenantAware,
systemSecurityContext); systemSecurityContext);
} }

View File

@@ -54,7 +54,7 @@ public class HttpControllerPreAuthenticatedSecurityHeaderFilter extends Abstract
} }
@Override @Override
protected PreAuthenficationFilter createControllerAuthenticationFilter() { protected PreAuthentificationFilter createControllerAuthenticationFilter() {
return new ControllerPreAuthenticatedSecurityHeaderFilter(caCommonNameHeader, caAuthorityNameHeader, return new ControllerPreAuthenticatedSecurityHeaderFilter(caCommonNameHeader, caAuthorityNameHeader,
tenantConfigurationManagement, tenantAware, systemSecurityContext); tenantConfigurationManagement, tenantAware, systemSecurityContext);
} }

View File

@@ -22,7 +22,7 @@ import org.slf4j.LoggerFactory;
* *
* *
*/ */
public abstract class AbstractControllerAuthenticationFilter implements PreAuthenficationFilter { public abstract class AbstractControllerAuthenticationFilter implements PreAuthentificationFilter {
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractControllerAuthenticationFilter.class); private static final Logger LOGGER = LoggerFactory.getLogger(AbstractControllerAuthenticationFilter.class);

View File

@@ -16,7 +16,7 @@ import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken;
* *
* @see DdiSecurityProperties * @see DdiSecurityProperties
*/ */
public class ControllerPreAuthenticatedAnonymousFilter implements PreAuthenficationFilter { public class ControllerPreAuthenticatedAnonymousFilter implements PreAuthentificationFilter {
private final DdiSecurityProperties ddiSecurityConfiguration; private final DdiSecurityProperties ddiSecurityConfiguration;

View File

@@ -16,12 +16,9 @@ import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.GrantedAuthority;
/** /**
* Interface for Pre Authenfication. * Interface for Pre Authentification.
*
*
*
*/ */
public interface PreAuthenficationFilter { public interface PreAuthentificationFilter {
/** /**
* Check if the filter is enabled. * Check if the filter is enabled.
@@ -60,6 +57,6 @@ public interface PreAuthenficationFilter {
*/ */
default Collection<GrantedAuthority> getSuccessfulAuthenticationAuthorities() { default Collection<GrantedAuthority> getSuccessfulAuthenticationAuthorities() {
return Collections.emptyList(); return Collections.emptyList();
}; }
} }

View File

@@ -8,8 +8,6 @@
*/ */
package org.eclipse.hawkbit.ui.artifacts.smtable; package org.eclipse.hawkbit.ui.artifacts.smtable;
import java.io.Serializable;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.EntityFactory;
@@ -17,6 +15,7 @@ import org.eclipse.hawkbit.repository.SoftwareManagement;
import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent;
import org.eclipse.hawkbit.ui.common.CommonDialogWindow; import org.eclipse.hawkbit.ui.common.CommonDialogWindow;
import org.eclipse.hawkbit.ui.common.CommonDialogWindow.SaveDialogCloseListener;
import org.eclipse.hawkbit.ui.common.SoftwareModuleTypeBeanQuery; import org.eclipse.hawkbit.ui.common.SoftwareModuleTypeBeanQuery;
import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder; import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder;
import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder; import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder;
@@ -28,6 +27,7 @@ import org.eclipse.hawkbit.ui.utils.I18N;
import org.eclipse.hawkbit.ui.utils.SPUIComponentIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIComponentIdProvider;
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
import org.eclipse.hawkbit.ui.utils.SpringContextHelper;
import org.eclipse.hawkbit.ui.utils.UINotification; import org.eclipse.hawkbit.ui.utils.UINotification;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory;
@@ -48,7 +48,7 @@ import com.vaadin.ui.themes.ValoTheme;
*/ */
@SpringComponent @SpringComponent
@ViewScope @ViewScope
public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Serializable { public class SoftwareModuleAddUpdateWindow extends CustomComponent {
private static final long serialVersionUID = -5217675246477211483L; private static final long serialVersionUID = -5217675246477211483L;
@@ -85,6 +85,25 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Se
private FormLayout formLayout; private FormLayout formLayout;
/**
* Save or update the sw module.
*/
private final class SaveOnDialogCloseListener implements SaveDialogCloseListener {
@Override
public void saveOrUpdate() {
if (editSwModule) {
updateSwModule();
return;
}
addNewBaseSoftware();
}
@Override
public boolean canWindowSaveOrUpdate() {
return editSwModule || !isDuplicate();
}
}
/** /**
* Initialize Distribution Add and Edit Window. * Initialize Distribution Add and Edit Window.
*/ */
@@ -180,12 +199,8 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Se
setCompositionRoot(formLayout); setCompositionRoot(formLayout);
window = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW) window = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW)
.caption(i18n.get("upload.caption.add.new.swmodule")).content(this) .caption(i18n.get("upload.caption.add.new.swmodule")).content(this).layout(formLayout).i18n(i18n)
.saveButtonClickListener(event -> saveOrUpdate()).layout(formLayout).i18n(i18n) .saveDialogCloseListener(new SaveOnDialogCloseListener()).buildCommonDialogWindow();
.buildCommonDialogWindow();
window.getButtonsLayout().removeStyleName("actionButtonsMargin");
nameTextField.setEnabled(!editSwModule); nameTextField.setEnabled(!editSwModule);
versionTextField.setEnabled(!editSwModule); versionTextField.setEnabled(!editSwModule);
typeComboBox.setEnabled(!editSwModule); typeComboBox.setEnabled(!editSwModule);
@@ -200,19 +215,31 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Se
final String description = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue()); final String description = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue());
final String type = typeComboBox.getValue() != null ? typeComboBox.getValue().toString() : null; final String type = typeComboBox.getValue() != null ? typeComboBox.getValue().toString() : null;
if (HawkbitCommonUtil.isDuplicate(name, version, type)) { final SoftwareModule newBaseSoftwareModule = HawkbitCommonUtil.addNewBaseSoftware(entityFactory, name, version,
vendor, softwareManagement.findSoftwareModuleTypeByName(type), description);
if (newBaseSoftwareModule != null) {
/* display success message */
uiNotifcation.displaySuccess(i18n.get("message.save.success",
new Object[] { newBaseSoftwareModule.getName() + ":" + newBaseSoftwareModule.getVersion() }));
eventBus.publish(this, new SoftwareModuleEvent(BaseEntityEventType.NEW_ENTITY, newBaseSoftwareModule));
}
}
private boolean isDuplicate() {
final String name = nameTextField.getValue();
final String version = versionTextField.getValue();
final String type = typeComboBox.getValue() != null ? typeComboBox.getValue().toString() : null;
final SoftwareManagement swMgmtService = SpringContextHelper.getBean(SoftwareManagement.class);
final SoftwareModule swModule = swMgmtService.findSoftwareModuleByNameAndVersion(name, version,
swMgmtService.findSoftwareModuleTypeByName(type));
if (swModule != null) {
uiNotifcation.displayValidationError( uiNotifcation.displayValidationError(
i18n.get("message.duplicate.softwaremodule", new Object[] { name, version })); i18n.get("message.duplicate.softwaremodule", new Object[] { name, version }));
} else { return true;
final SoftwareModule newBaseSoftwareModule = HawkbitCommonUtil.addNewBaseSoftware(entityFactory, name,
version, vendor, softwareManagement.findSoftwareModuleTypeByName(type), description);
if (newBaseSoftwareModule != null) {
/* display success message */
uiNotifcation.displaySuccess(i18n.get("message.save.success",
new Object[] { newBaseSoftwareModule.getName() + ":" + newBaseSoftwareModule.getVersion() }));
eventBus.publish(this, new SoftwareModuleEvent(BaseEntityEventType.NEW_ENTITY, newBaseSoftwareModule));
}
} }
return false;
} }
/** /**
@@ -254,14 +281,6 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Se
typeComboBox.setValue(swModle.getType().getName()); typeComboBox.setValue(swModle.getType().getName());
} }
private void saveOrUpdate() {
if (editSwModule) {
updateSwModule();
} else {
addNewBaseSoftware();
}
}
public FormLayout getFormLayout() { public FormLayout getFormLayout() {
return formLayout; return formLayout;
} }

View File

@@ -34,7 +34,6 @@ import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.shared.ui.colorpicker.Color; import com.vaadin.shared.ui.colorpicker.Color;
import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.SpringComponent;
import com.vaadin.spring.annotation.ViewScope; import com.vaadin.spring.annotation.ViewScope;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Label; import com.vaadin.ui.Label;
import com.vaadin.ui.OptionGroup; import com.vaadin.ui.OptionGroup;
import com.vaadin.ui.TextField; import com.vaadin.ui.TextField;
@@ -47,7 +46,7 @@ import com.vaadin.ui.themes.ValoTheme;
*/ */
@SpringComponent @SpringComponent
@ViewScope @ViewScope
public class CreateUpdateSoftwareTypeLayout extends CreateUpdateTypeLayout { public class CreateUpdateSoftwareTypeLayout extends CreateUpdateTypeLayout<SoftwareModuleType> {
private static final long serialVersionUID = -5169398523815919367L; private static final long serialVersionUID = -5169398523815919367L;
private static final Logger LOG = LoggerFactory.getLogger(CreateUpdateSoftwareTypeLayout.class); private static final Logger LOG = LoggerFactory.getLogger(CreateUpdateSoftwareTypeLayout.class);
@@ -124,7 +123,7 @@ public class CreateUpdateSoftwareTypeLayout extends CreateUpdateTypeLayout {
super.optionValueChanged(event); super.optionValueChanged(event);
if (updateTypeStr.equals(event.getProperty().getValue())) { if (updateTagStr.equals(event.getProperty().getValue())) {
assignOptiongroup.setEnabled(false); assignOptiongroup.setEnabled(false);
} else { } else {
assignOptiongroup.setEnabled(true); assignOptiongroup.setEnabled(true);
@@ -192,18 +191,28 @@ public class CreateUpdateSoftwareTypeLayout extends CreateUpdateTypeLayout {
} }
@Override @Override
protected void save(final ClickEvent event) { protected void createEntity() {
final SoftwareModuleType existingSMTypeByKey = swTypeManagementService createNewSWModuleType();
.findSoftwareModuleTypeByKey(typeKey.getValue()); }
final SoftwareModuleType existingSMTypeByName = swTypeManagementService
.findSoftwareModuleTypeByName(tagName.getValue()); @Override
if (optiongroup.getValue().equals(createTypeStr)) { protected void updateEntity(final SoftwareModuleType entity) {
if (!checkIsDuplicateByKey(existingSMTypeByKey) && !checkIsDuplicate(existingSMTypeByName)) { updateSWModuleType(entity);
createNewSWModuleType(); }
}
} else { @Override
updateSWModuleType(existingSMTypeByName); protected SoftwareModuleType findEntityByKey() {
} return swTypeManagementService.findSoftwareModuleTypeByKey(typeKey.getValue());
}
@Override
protected SoftwareModuleType findEntityByName() {
return swTypeManagementService.findSoftwareModuleTypeByName(tagName.getValue());
}
@Override
protected String getDuplicateKeyErrorMessage(final SoftwareModuleType existingType) {
return i18n.get("message.type.key.swmodule.duplicate.check", new Object[] { existingType.getKey() });
} }
private void createNewSWModuleType() { private void createNewSWModuleType() {

View File

@@ -332,6 +332,7 @@ public class UploadStatusInfoWindow extends Window {
restoreState(); restoreState();
} }
@SuppressWarnings("unchecked")
private void uploadRecevied(final String filename, final SoftwareModule softwareModule) { private void uploadRecevied(final String filename, final SoftwareModule softwareModule) {
final Item item = uploads.addItem(getItemid(filename, softwareModule)); final Item item = uploads.addItem(getItemid(filename, softwareModule));
if (item != null) { if (item != null) {

View File

@@ -16,6 +16,7 @@ import javax.annotation.PostConstruct;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.MetaData; import org.eclipse.hawkbit.repository.model.MetaData;
import org.eclipse.hawkbit.repository.model.NamedVersionedEntity; import org.eclipse.hawkbit.repository.model.NamedVersionedEntity;
import org.eclipse.hawkbit.ui.common.CommonDialogWindow.SaveDialogCloseListener;
import org.eclipse.hawkbit.ui.common.builder.LabelBuilder; import org.eclipse.hawkbit.ui.common.builder.LabelBuilder;
import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder; import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder;
import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder; import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder;
@@ -97,6 +98,27 @@ public abstract class AbstractMetadataPopupLayout<E extends NamedVersionedEntity
private HorizontalLayout mainLayout; private HorizontalLayout mainLayout;
/**
* Save the metadata and never close the window after saving.
*/
private final class SaveOnDialogCloseListener implements SaveDialogCloseListener {
@Override
public void saveOrUpdate() {
onSave();
}
@Override
public boolean canWindowClose() {
return false;
}
@Override
public boolean canWindowSaveOrUpdate() {
return true;
}
}
@PostConstruct @PostConstruct
void init() { void init() {
createComponents(); createComponents();
@@ -117,11 +139,11 @@ public abstract class AbstractMetadataPopupLayout<E extends NamedVersionedEntity
selectedEntity = entity; selectedEntity = entity;
final String nameVersion = HawkbitCommonUtil.getFormattedNameVersion(entity.getName(), entity.getVersion()); final String nameVersion = HawkbitCommonUtil.getFormattedNameVersion(entity.getName(), entity.getVersion());
metadataWindow = new WindowBuilder(SPUIDefinitions.CUSTOM_METADATA_WINDOW) metadataWindow = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW)
.caption(getMetadataCaption(nameVersion)).content(this).saveButtonClickListener(event -> onSave()) .caption(getMetadataCaption(nameVersion)).content(this).cancelButtonClickListener(event -> onCancel())
.cancelButtonClickListener(event -> onCancel()).layout(mainLayout).i18n(i18n).buildCommonDialogWindow(); .id(SPUIComponentIdProvider.METADATA_POPUP_ID).layout(mainLayout).i18n(i18n)
.saveDialogCloseListener(new SaveOnDialogCloseListener()).buildCommonDialogWindow();
metadataWindow.setId(SPUIComponentIdProvider.METADATA_POPUP_ID);
metadataWindow.setHeight(550, Unit.PIXELS); metadataWindow.setHeight(550, Unit.PIXELS);
metadataWindow.setWidth(800, Unit.PIXELS); metadataWindow.setWidth(800, Unit.PIXELS);
metadataWindow.getMainLayout().setSizeFull(); metadataWindow.getMainLayout().setSizeFull();

View File

@@ -50,6 +50,7 @@ import com.vaadin.ui.AbstractLayout;
import com.vaadin.ui.AbstractOrderedLayout; import com.vaadin.ui.AbstractOrderedLayout;
import com.vaadin.ui.Alignment; import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button; import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.CheckBox; import com.vaadin.ui.CheckBox;
import com.vaadin.ui.Component; import com.vaadin.ui.Component;
@@ -89,11 +90,9 @@ public class CommonDialogWindow extends Window {
protected ValueChangeListener buttonEnableListener; protected ValueChangeListener buttonEnableListener;
private final ClickListener saveButtonClickListener;
private final ClickListener cancelButtonClickListener; private final ClickListener cancelButtonClickListener;
private final ClickListener closeClickListener = event -> close(); private final ClickListener closeClickListener = event -> onCloseEvent(event);
private final transient Map<Component, Object> orginalValues; private final transient Map<Component, Object> orginalValues;
@@ -101,6 +100,8 @@ public class CommonDialogWindow extends Window {
private final I18N i18n; private final I18N i18n;
private transient SaveDialogCloseListener closeListener;
/** /**
* Constructor. * Constructor.
* *
@@ -110,8 +111,8 @@ public class CommonDialogWindow extends Window {
* the content * the content
* @param helpLink * @param helpLink
* the helpLinks * the helpLinks
* @param saveButtonClickListener * @param closeListener
* the saveButtonClickListener * the saveDialogCloseListener
* @param cancelButtonClickListener * @param cancelButtonClickListener
* the cancelButtonClickListener * the cancelButtonClickListener
* @param layout * @param layout
@@ -120,13 +121,13 @@ public class CommonDialogWindow extends Window {
* the i18n service * the i18n service
*/ */
public CommonDialogWindow(final String caption, final Component content, final String helpLink, public CommonDialogWindow(final String caption, final Component content, final String helpLink,
final ClickListener saveButtonClickListener, final ClickListener cancelButtonClickListener, final SaveDialogCloseListener closeListener, final ClickListener cancelButtonClickListener,
final AbstractLayout layout, final I18N i18n) { final AbstractLayout layout, final I18N i18n) {
checkNotNull(saveButtonClickListener); checkNotNull(closeListener);
this.caption = caption; this.caption = caption;
this.content = content; this.content = content;
this.helpLink = helpLink; this.helpLink = helpLink;
this.saveButtonClickListener = saveButtonClickListener; this.closeListener = closeListener;
this.cancelButtonClickListener = cancelButtonClickListener; this.cancelButtonClickListener = cancelButtonClickListener;
this.orginalValues = new HashMap<>(); this.orginalValues = new HashMap<>();
this.allComponents = getAllComponents(layout); this.allComponents = getAllComponents(layout);
@@ -134,6 +135,23 @@ public class CommonDialogWindow extends Window {
init(); init();
} }
private void onCloseEvent(final ClickEvent clickEvent) {
if (!clickEvent.getButton().equals(saveButton)) {
close();
return;
}
if (!closeListener.canWindowSaveOrUpdate()) {
return;
}
closeListener.saveOrUpdate();
if (closeListener.canWindowClose()) {
close();
}
}
@Override @Override
public void close() { public void close() {
super.close(); super.close();
@@ -210,7 +228,7 @@ public class CommonDialogWindow extends Window {
setModal(true); setModal(true);
addStyleName("fontsize"); addStyleName("fontsize");
setOrginaleValues(); setOrginaleValues();
addListeners(); addComponentListeners();
} }
/** /**
@@ -229,12 +247,6 @@ public class CommonDialogWindow extends Window {
saveButton.setEnabled(isSaveButtonEnabledAfterValueChange(null, null)); saveButton.setEnabled(isSaveButtonEnabledAfterValueChange(null, null));
} }
protected void addListeners() {
addComponenetListeners();
addCloseListenerForSaveButton();
addCloseListenerForCancelButton();
}
protected void addCloseListenerForSaveButton() { protected void addCloseListenerForSaveButton() {
saveButton.addClickListener(closeClickListener); saveButton.addClickListener(closeClickListener);
} }
@@ -243,7 +255,7 @@ public class CommonDialogWindow extends Window {
cancelButton.addClickListener(closeClickListener); cancelButton.addClickListener(closeClickListener);
} }
protected void addComponenetListeners() { protected void addComponentListeners() {
for (final AbstractField<?> field : allComponents) { for (final AbstractField<?> field : allComponents) {
if (field instanceof TextChangeNotifier) { if (field instanceof TextChangeNotifier) {
((TextChangeNotifier) field).addTextChangeListener(new ChangeListener(field)); ((TextChangeNotifier) field).addTextChangeListener(new ChangeListener(field));
@@ -431,6 +443,7 @@ public class CommonDialogWindow extends Window {
FontAwesome.TIMES, SPUIButtonStyleNoBorderWithIcon.class); FontAwesome.TIMES, SPUIButtonStyleNoBorderWithIcon.class);
cancelButton.setSizeUndefined(); cancelButton.setSizeUndefined();
cancelButton.addStyleName("default-color"); cancelButton.addStyleName("default-color");
addCloseListenerForCancelButton();
if (cancelButtonClickListener != null) { if (cancelButtonClickListener != null) {
cancelButton.addClickListener(cancelButtonClickListener); cancelButton.addClickListener(cancelButtonClickListener);
} }
@@ -445,7 +458,7 @@ public class CommonDialogWindow extends Window {
FontAwesome.SAVE, SPUIButtonStyleNoBorderWithIcon.class); FontAwesome.SAVE, SPUIButtonStyleNoBorderWithIcon.class);
saveButton.setSizeUndefined(); saveButton.setSizeUndefined();
saveButton.addStyleName("default-color"); saveButton.addStyleName("default-color");
saveButton.addClickListener(saveButtonClickListener); addCloseListenerForSaveButton();
saveButton.setEnabled(false); saveButton.setEnabled(false);
buttonsLayout.addComponent(saveButton); buttonsLayout.addComponent(saveButton);
buttonsLayout.setComponentAlignment(saveButton, Alignment.MIDDLE_RIGHT); buttonsLayout.setComponentAlignment(saveButton, Alignment.MIDDLE_RIGHT);
@@ -505,7 +518,7 @@ public class CommonDialogWindow extends Window {
* @param component * @param component
* AbstractField * AbstractField
*/ */
public void updateAllComponents(final AbstractField component) { public void updateAllComponents(final AbstractField<?> component) {
allComponents.add(component); allComponents.add(component);
component.addValueChangeListener(new ChangeListener(component)); component.addValueChangeListener(new ChangeListener(component));
@@ -522,4 +535,36 @@ public class CommonDialogWindow extends Window {
public void setCancelButtonEnabled(final boolean enabled) { public void setCancelButtonEnabled(final boolean enabled) {
cancelButton.setEnabled(enabled); cancelButton.setEnabled(enabled);
} }
/**
* Check if the safe action can executed. After a the save action the
* listener checks if the dialog can closed.
*
*/
public interface SaveDialogCloseListener {
/**
* Checks if the safe action can executed.
*
* @return <true> = save action can executed <false> = cannot execute
* safe action .
*/
boolean canWindowSaveOrUpdate();
/**
* Checks if the window can closed after the safe action is executed
*
* @return <true> = window will close <false> = will not closed.
*/
default boolean canWindowClose() {
return true;
}
/**
* Saves/Updates action. Is called if canWindowSaveOrUpdate is <true>.
*
*/
void saveOrUpdate();
}
} }

View File

@@ -1,33 +0,0 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.ui.common;
import org.eclipse.hawkbit.ui.utils.I18N;
import com.vaadin.ui.AbstractLayout;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Component;
public class CustomCommonDialogWindow extends CommonDialogWindow {
private static final long serialVersionUID = -4453608850403359992L;
public CustomCommonDialogWindow(final String caption, final Component content, final String helpLink,
final ClickListener saveButtonClickListener, final ClickListener cancelButtonClickListener,
final AbstractLayout layout, final I18N i18n) {
super(caption, content, helpLink, saveButtonClickListener, cancelButtonClickListener, layout, i18n);
}
@Override
protected void addListeners() {
addComponenetListeners();
addCloseListenerForCancelButton();
}
}

View File

@@ -9,7 +9,7 @@
package org.eclipse.hawkbit.ui.common.builder; package org.eclipse.hawkbit.ui.common.builder;
import org.eclipse.hawkbit.ui.common.CommonDialogWindow; import org.eclipse.hawkbit.ui.common.CommonDialogWindow;
import org.eclipse.hawkbit.ui.common.CustomCommonDialogWindow; import org.eclipse.hawkbit.ui.common.CommonDialogWindow.SaveDialogCloseListener;
import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.I18N;
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
@@ -26,7 +26,6 @@ public class WindowBuilder {
private String caption; private String caption;
private Component content; private Component content;
private ClickListener saveButtonClickListener;
private ClickListener cancelButtonClickListener; private ClickListener cancelButtonClickListener;
private String helpLink; private String helpLink;
private AbstractLayout layout; private AbstractLayout layout;
@@ -34,6 +33,8 @@ public class WindowBuilder {
private final String type; private final String type;
private String id; private String id;
private SaveDialogCloseListener saveDialogCloseListener;
/** /**
* Constructor. * Constructor.
* *
@@ -44,6 +45,18 @@ public class WindowBuilder {
this.type = type; this.type = type;
} }
/**
* Set the SaveDialogCloseListener.
*
* @param saveDialogCloseListener
* the saveDialogCloseListener
* @return the window builder
*/
public WindowBuilder saveDialogCloseListener(final SaveDialogCloseListener saveDialogCloseListener) {
this.saveDialogCloseListener = saveDialogCloseListener;
return this;
}
/** /**
* Set the caption. * Set the caption.
* *
@@ -68,18 +81,6 @@ public class WindowBuilder {
return this; return this;
} }
/**
* Set the saveButtonClickListener.
*
* @param saveButtonClickListener
* the saveButtonClickListener
* @return the window builder
*/
public WindowBuilder saveButtonClickListener(final ClickListener saveButtonClickListener) {
this.saveButtonClickListener = saveButtonClickListener;
return this;
}
/** /**
* Set the cancelButtonClickListener. * Set the cancelButtonClickListener.
* *
@@ -143,20 +144,9 @@ public class WindowBuilder {
* @return the window. * @return the window.
*/ */
public CommonDialogWindow buildCommonDialogWindow() { public CommonDialogWindow buildCommonDialogWindow() {
CommonDialogWindow window; final CommonDialogWindow window = new CommonDialogWindow(caption, content, helpLink, saveDialogCloseListener,
cancelButtonClickListener, layout, i18n);
if (SPUIDefinitions.CUSTOM_METADATA_WINDOW.equals(type)) {
window = new CustomCommonDialogWindow(caption, content, helpLink, saveButtonClickListener,
cancelButtonClickListener, layout, i18n);
window.setDraggable(true);
window.setClosable(true);
return window;
}
window = new CommonDialogWindow(caption, content, helpLink, saveButtonClickListener, cancelButtonClickListener,
layout, i18n);
decorateWindow(window); decorateWindow(window);
return window; return window;
} }

View File

@@ -42,7 +42,6 @@ import com.vaadin.spring.annotation.ViewScope;
import com.vaadin.ui.AbstractSelect.ItemDescriptionGenerator; import com.vaadin.ui.AbstractSelect.ItemDescriptionGenerator;
import com.vaadin.ui.Alignment; import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button; import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.CheckBox; import com.vaadin.ui.CheckBox;
import com.vaadin.ui.Component; import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.HorizontalLayout;
@@ -56,7 +55,7 @@ import com.vaadin.ui.themes.ValoTheme;
*/ */
@SpringComponent @SpringComponent
@ViewScope @ViewScope
public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout { public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout<DistributionSetType> {
private static final long serialVersionUID = -5169398523815877767L; private static final long serialVersionUID = -5169398523815877767L;
private static final String DIST_TYPE_NAME = "name"; private static final String DIST_TYPE_NAME = "name";
@@ -456,7 +455,7 @@ public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout {
super.optionValueChanged(event); super.optionValueChanged(event);
if (updateTypeStr.equals(event.getProperty().getValue())) { if (updateTagStr.equals(event.getProperty().getValue())) {
selectedTable.getContainerDataSource().removeAllItems(); selectedTable.getContainerDataSource().removeAllItems();
getSourceTableData(); getSourceTableData();
distTypeSelectLayout.setEnabled(false); distTypeSelectLayout.setEnabled(false);
@@ -568,18 +567,30 @@ public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout {
} }
@Override @Override
protected void save(final ClickEvent event) { protected void updateEntity(final DistributionSetType entity) {
final DistributionSetType existingDistTypeByKey = distributionSetManagement updateDistributionSetType(entity);
.findDistributionSetTypeByKey(typeKey.getValue());
final DistributionSetType existingDistTypeByName = distributionSetManagement }
.findDistributionSetTypeByName(tagName.getValue());
if (optiongroup.getValue().equals(createTypeStr)) { @Override
if (!checkIsDuplicateByKey(existingDistTypeByKey) && !checkIsDuplicate(existingDistTypeByName)) { protected void createEntity() {
createNewDistributionSetType(); createNewDistributionSetType();
}
} else { }
updateDistributionSetType(existingDistTypeByKey);
} @Override
protected DistributionSetType findEntityByKey() {
return distributionSetManagement.findDistributionSetTypeByKey(typeKey.getValue());
}
@Override
protected DistributionSetType findEntityByName() {
return distributionSetManagement.findDistributionSetTypeByName(tagName.getValue());
}
@Override
protected String getDuplicateKeyErrorMessage(final DistributionSetType existingType) {
return i18n.get("message.type.key.duplicate.check", new Object[] { existingType.getKey() });
} }
@Override @Override

View File

@@ -13,12 +13,14 @@ import javax.annotation.PreDestroy;
import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.SpPermissionChecker;
import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.TagManagement;
import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.eclipse.hawkbit.repository.model.NamedEntity;
import org.eclipse.hawkbit.repository.model.Tag; import org.eclipse.hawkbit.repository.model.Tag;
import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.TargetTag;
import org.eclipse.hawkbit.ui.colorpicker.ColorPickerConstants; import org.eclipse.hawkbit.ui.colorpicker.ColorPickerConstants;
import org.eclipse.hawkbit.ui.colorpicker.ColorPickerHelper; import org.eclipse.hawkbit.ui.colorpicker.ColorPickerHelper;
import org.eclipse.hawkbit.ui.colorpicker.ColorPickerLayout; import org.eclipse.hawkbit.ui.colorpicker.ColorPickerLayout;
import org.eclipse.hawkbit.ui.common.CommonDialogWindow; import org.eclipse.hawkbit.ui.common.CommonDialogWindow;
import org.eclipse.hawkbit.ui.common.CommonDialogWindow.SaveDialogCloseListener;
import org.eclipse.hawkbit.ui.common.builder.LabelBuilder; import org.eclipse.hawkbit.ui.common.builder.LabelBuilder;
import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder; import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder;
import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder; import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder;
@@ -55,10 +57,14 @@ import com.vaadin.ui.components.colorpicker.ColorSelector;
import com.vaadin.ui.themes.ValoTheme; import com.vaadin.ui.themes.ValoTheme;
/** /**
*
* Abstract class for create/update target tag layout. * Abstract class for create/update target tag layout.
*
* @param <E>
*/ */
public abstract class AbstractCreateUpdateTagLayout extends CustomComponent public abstract class AbstractCreateUpdateTagLayout<E extends NamedEntity> extends CustomComponent
implements ColorChangeListener, ColorSelector { implements ColorChangeListener, ColorSelector {
private static final long serialVersionUID = 4229177824620576456L; private static final long serialVersionUID = 4229177824620576456L;
private static final String TAG_NAME_DYNAMIC_STYLE = "new-tag-name"; private static final String TAG_NAME_DYNAMIC_STYLE = "new-tag-name";
private static final String TAG_DESC_DYNAMIC_STYLE = "new-tag-desc"; private static final String TAG_DESC_DYNAMIC_STYLE = "new-tag-desc";
@@ -105,14 +111,32 @@ public abstract class AbstractCreateUpdateTagLayout extends CustomComponent
protected String tagNameValue; protected String tagNameValue;
protected String tagDescValue; protected String tagDescValue;
protected abstract String getWindowCaption();
/** /**
* Save new tag / update new tag.
* *
* @param event * Save or update the entity.
*/ */
protected abstract void save(final Button.ClickEvent event); private final class SaveOnDialogCloseListener implements SaveDialogCloseListener {
@Override
public void saveOrUpdate() {
if (isUpdateAction()) {
updateEntity(findEntityByName());
return;
}
createEntity();
}
@Override
public boolean canWindowSaveOrUpdate() {
return isUpdateAction() || !isDuplicate();
}
private boolean isUpdateAction() {
return !optiongroup.getValue().equals(createTagStr);
}
}
/** /**
* Discard the changes and close the popup. * Discard the changes and close the popup.
@@ -400,7 +424,7 @@ public abstract class AbstractCreateUpdateTagLayout extends CustomComponent
* *
* @param colorPickedPreview * @param colorPickedPreview
*/ */
private void getTargetDynamicStyles(final String colorPickedPreview) { private static void getTargetDynamicStyles(final String colorPickedPreview) {
Page.getCurrent().getJavaScript() Page.getCurrent().getJavaScript()
.execute(HawkbitCommonUtil.changeToNewSelectedPreviewColor(colorPickedPreview)); .execute(HawkbitCommonUtil.changeToNewSelectedPreviewColor(colorPickedPreview));
} }
@@ -463,9 +487,8 @@ public abstract class AbstractCreateUpdateTagLayout extends CustomComponent
public CommonDialogWindow getWindow() { public CommonDialogWindow getWindow() {
reset(); reset();
window = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW).caption(getWindowCaption()).content(this) window = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW).caption(getWindowCaption()).content(this)
.saveButtonClickListener(this::save).cancelButtonClickListener(event -> discard()).layout(mainLayout) .cancelButtonClickListener(event -> discard()).layout(mainLayout).i18n(i18n)
.i18n(i18n).buildCommonDialogWindow(); .saveDialogCloseListener(new SaveOnDialogCloseListener()).buildCommonDialogWindow();
return window; return window;
} }
@@ -562,12 +585,19 @@ public abstract class AbstractCreateUpdateTagLayout extends CustomComponent
getPreviewButtonColor(previewColor); getPreviewButtonColor(previewColor);
} }
protected Boolean checkIsDuplicate(final Tag existingTag) { private boolean isDuplicateByName() {
if (existingTag != null) { final E existingType = findEntityByName();
displayValidationError(i18n.get("message.tag.duplicate.check", new Object[] { existingTag.getName() })); if (existingType != null) {
return Boolean.TRUE; uiNotification.displayValidationError(
i18n.get("message.tag.duplicate.check", new Object[] { existingType.getName() }));
return true;
} }
return Boolean.FALSE;
return false;
}
protected boolean isDuplicate() {
return isDuplicateByName();
} }
public String getColorPicked() { public String getColorPicked() {
@@ -610,4 +640,12 @@ public abstract class AbstractCreateUpdateTagLayout extends CustomComponent
public void removeColorChangeListener(final ColorChangeListener listener) { public void removeColorChangeListener(final ColorChangeListener listener) {
} }
protected abstract E findEntityByName();
protected abstract String getWindowCaption();
protected abstract void updateEntity(E entity);
protected abstract void createEntity();
} }

View File

@@ -8,9 +8,7 @@
*/ */
package org.eclipse.hawkbit.ui.layouts; package org.eclipse.hawkbit.ui.layouts;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.NamedEntity; import org.eclipse.hawkbit.repository.model.NamedEntity;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.eclipse.hawkbit.ui.colorpicker.ColorPickerConstants; import org.eclipse.hawkbit.ui.colorpicker.ColorPickerConstants;
import org.eclipse.hawkbit.ui.colorpicker.ColorPickerHelper; import org.eclipse.hawkbit.ui.colorpicker.ColorPickerHelper;
import org.eclipse.hawkbit.ui.common.builder.LabelBuilder; import org.eclipse.hawkbit.ui.common.builder.LabelBuilder;
@@ -23,24 +21,19 @@ import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.server.Page; import com.vaadin.server.Page;
import com.vaadin.shared.ui.colorpicker.Color; import com.vaadin.shared.ui.colorpicker.Color;
import com.vaadin.ui.Button; import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.OptionGroup;
import com.vaadin.ui.TextArea; import com.vaadin.ui.TextArea;
import com.vaadin.ui.TextField; import com.vaadin.ui.TextField;
import com.vaadin.ui.components.colorpicker.ColorChangeEvent; import com.vaadin.ui.components.colorpicker.ColorChangeEvent;
import com.vaadin.ui.components.colorpicker.ColorSelector; import com.vaadin.ui.components.colorpicker.ColorSelector;
import com.vaadin.ui.themes.ValoTheme;
/** /**
* Superclass defining common properties and methods for creating/updating * Superclass defining common properties and methods for creating/updating
* types. * types.
*/ */
public abstract class CreateUpdateTypeLayout extends AbstractCreateUpdateTagLayout { public abstract class CreateUpdateTypeLayout<E extends NamedEntity> extends AbstractCreateUpdateTagLayout<E> {
private static final long serialVersionUID = 5732904956185988397L; private static final long serialVersionUID = 5732904956185988397L;
protected String createTypeStr;
protected String updateTypeStr;
protected TextField typeKey; protected TextField typeKey;
public static final String TYPE_NAME_DYNAMIC_STYLE = "new-tag-name"; public static final String TYPE_NAME_DYNAMIC_STYLE = "new-tag-name";
@@ -55,11 +48,10 @@ public abstract class CreateUpdateTypeLayout extends AbstractCreateUpdateTagLayo
@Override @Override
protected void createRequiredComponents() { protected void createRequiredComponents() {
createTypeStr = i18n.get("label.create.type"); createTagStr = i18n.get("label.create.type");
updateTypeStr = i18n.get("label.update.type"); updateTagStr = i18n.get("label.update.type");
comboLabel = new LabelBuilder().name(i18n.get("label.choose.type")).buildLabel(); comboLabel = new LabelBuilder().name(i18n.get("label.choose.type")).buildLabel();
colorLabel = new LabelBuilder().name(i18n.get("label.choose.type.color")).buildLabel(); colorLabel = new LabelBuilder().name(i18n.get("label.choose.type.color")).buildLabel();
colorLabel.addStyleName(SPUIDefinitions.COLOR_LABEL_STYLE); colorLabel.addStyleName(SPUIDefinitions.COLOR_LABEL_STYLE);
tagNameComboBox = SPUIComponentProvider.getComboBox(i18n.get("label.combobox.type"), "", "", null, null, false, tagNameComboBox = SPUIComponentProvider.getComboBox(i18n.get("label.combobox.type"), "", "", null, null, false,
@@ -137,7 +129,7 @@ public abstract class CreateUpdateTypeLayout extends AbstractCreateUpdateTagLayo
@Override @Override
protected void optionValueChanged(final ValueChangeEvent event) { protected void optionValueChanged(final ValueChangeEvent event) {
if (updateTypeStr.equals(event.getProperty().getValue())) { if (updateTagStr.equals(event.getProperty().getValue())) {
tagName.clear(); tagName.clear();
tagDesc.clear(); tagDesc.clear();
typeKey.clear(); typeKey.clear();
@@ -193,38 +185,6 @@ public abstract class CreateUpdateTypeLayout extends AbstractCreateUpdateTagLayo
typeKey.addStyleName(SPUIDefinitions.TYPE_KEY); typeKey.addStyleName(SPUIDefinitions.TYPE_KEY);
} }
/**
* create option group with Create tag/Update tag based on permissions.
*/
@Override
protected void createOptionGroup(final boolean hasCreatePermission, final boolean hasUpdatePermission) {
optiongroup = new OptionGroup("Select Action");
optiongroup.setId(SPUIComponentIdProvider.OPTION_GROUP);
optiongroup.addStyleName(ValoTheme.OPTIONGROUP_SMALL);
optiongroup.addStyleName("custom-option-group");
optiongroup.setNullSelectionAllowed(false);
if (hasCreatePermission) {
optiongroup.addItem(createTypeStr);
}
if (hasUpdatePermission) {
optiongroup.addItem(updateTypeStr);
}
setOptionGroupDefaultValue(hasCreatePermission, hasUpdatePermission);
}
@Override
protected void setOptionGroupDefaultValue(final boolean hasCreatePermission, final boolean hasUpdatePermission) {
if (hasCreatePermission) {
optiongroup.select(createTypeStr);
}
if (hasUpdatePermission && !hasCreatePermission) {
optiongroup.select(updateTypeStr);
}
}
protected void setColorPickerComponentsColor(final String color) { protected void setColorPickerComponentsColor(final String color) {
if (null == color) { if (null == color) {
@@ -257,37 +217,27 @@ public abstract class CreateUpdateTypeLayout extends AbstractCreateUpdateTagLayo
createDynamicStyleForComponents(tagName, typeKey, tagDesc, event.getColor().getCSS()); createDynamicStyleForComponents(tagName, typeKey, tagDesc, event.getColor().getCSS());
} }
protected Boolean checkIsDuplicate(final NamedEntity existingType) { private boolean isDuplicateByKey() {
final E existingType = findEntityByKey();
if (existingType != null) { if (existingType != null) {
uiNotification.displayValidationError( uiNotification.displayValidationError(getDuplicateKeyErrorMessage(existingType));
i18n.get("message.tag.duplicate.check", new Object[] { existingType.getName() })); return true;
return Boolean.TRUE;
} }
return Boolean.FALSE;
}
protected Boolean checkIsDuplicateByKey(final NamedEntity existingType) { return false;
if (existingType != null) {
if (existingType instanceof DistributionSetType) {
uiNotification.displayValidationError(i18n.get("message.type.key.duplicate.check",
new Object[] { ((DistributionSetType) existingType).getKey() }));
return Boolean.TRUE;
} else if (existingType instanceof SoftwareModuleType) {
uiNotification.displayValidationError(i18n.get("message.type.key.swmodule.duplicate.check",
new Object[] { ((SoftwareModuleType) existingType).getKey() }));
return Boolean.TRUE;
}
}
return Boolean.FALSE;
} }
@Override @Override
protected void save(final ClickEvent event) { protected boolean isDuplicate() {
// is implemented in the inherited class return isDuplicateByKey() || super.isDuplicate();
} }
protected abstract E findEntityByKey();
protected abstract String getDuplicateKeyErrorMessage(E existingType);
@Override @Override
protected void populateTagNameCombo() { protected void populateTagNameCombo() {
// is implemented in the inherited class // is implemented in the inherited class

View File

@@ -18,11 +18,11 @@ import javax.annotation.PostConstruct;
import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.TenantMetaData; import org.eclipse.hawkbit.repository.model.TenantMetaData;
import org.eclipse.hawkbit.ui.common.CommonDialogWindow; import org.eclipse.hawkbit.ui.common.CommonDialogWindow;
import org.eclipse.hawkbit.ui.common.CommonDialogWindow.SaveDialogCloseListener;
import org.eclipse.hawkbit.ui.common.DistributionSetIdName; import org.eclipse.hawkbit.ui.common.DistributionSetIdName;
import org.eclipse.hawkbit.ui.common.DistributionSetTypeBeanQuery; import org.eclipse.hawkbit.ui.common.DistributionSetTypeBeanQuery;
import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder; import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder;
@@ -41,8 +41,6 @@ import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
import org.eclipse.hawkbit.ui.utils.SpringContextHelper; import org.eclipse.hawkbit.ui.utils.SpringContextHelper;
import org.eclipse.hawkbit.ui.utils.UINotification; import org.eclipse.hawkbit.ui.utils.UINotification;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory;
import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer;
@@ -68,8 +66,6 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
private static final long serialVersionUID = -5602182034230568435L; private static final long serialVersionUID = -5602182034230568435L;
private static final Logger LOG = LoggerFactory.getLogger(DistributionAddUpdateWindowLayout.class);
@Autowired @Autowired
private I18N i18n; private I18N i18n;
@@ -87,6 +83,7 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
@Autowired @Autowired
private transient EntityFactory entityFactory; private transient EntityFactory entityFactory;
private TextField distNameTextField; private TextField distNameTextField;
private TextField distVersionTextField; private TextField distVersionTextField;
private TextArea descTextArea; private TextArea descTextArea;
@@ -98,6 +95,27 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
private FormLayout formLayout; private FormLayout formLayout;
/**
* Save or update distribution set.
*
*/
private final class SaveOnCloseDialogListener implements SaveDialogCloseListener {
@Override
public void saveOrUpdate() {
if (editDistribution) {
updateDistribution();
return;
}
addNewDistribution();
}
@Override
public boolean canWindowSaveOrUpdate() {
return !isDuplicate();
}
}
/** /**
* Initialize Distribution Add and Edit Window. * Initialize Distribution Add and Edit Window.
*/ */
@@ -178,42 +196,30 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
return tenantMetaData.getDefaultDsType(); return tenantMetaData.getDefaultDsType();
} }
private void saveDistribution() {
if (editDistribution) {
updateDistribution();
} else {
addNewDistribution();
}
}
/** /**
* Update Distribution. * Update Distribution.
*/ */
private void updateDistribution() { private void updateDistribution() {
if (isDuplicate()) {
return;
}
final String name = HawkbitCommonUtil.trimAndNullIfEmpty(distNameTextField.getValue()); final String name = HawkbitCommonUtil.trimAndNullIfEmpty(distNameTextField.getValue());
final String version = HawkbitCommonUtil.trimAndNullIfEmpty(distVersionTextField.getValue()); final String version = HawkbitCommonUtil.trimAndNullIfEmpty(distVersionTextField.getValue());
final String distSetTypeName = HawkbitCommonUtil final String distSetTypeName = HawkbitCommonUtil
.trimAndNullIfEmpty((String) distsetTypeNameComboBox.getValue()); .trimAndNullIfEmpty((String) distsetTypeNameComboBox.getValue());
final DistributionSet currentDS = distributionSetManagement.findDistributionSetByIdWithDetails(editDistId);
final String desc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue());
final boolean isMigStepReq = reqMigStepCheckbox.getValue();
if (duplicateCheck(name, version)) { /* identify the changes */
final DistributionSet currentDS = distributionSetManagement.findDistributionSetByIdWithDetails(editDistId); setDistributionValues(currentDS, name, version, distSetTypeName, desc, isMigStepReq);
final String desc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue()); distributionSetManagement.updateDistributionSet(currentDS);
final boolean isMigStepReq = reqMigStepCheckbox.getValue(); notificationMessage.displaySuccess(i18n.get("message.new.dist.save.success",
new Object[] { currentDS.getName(), currentDS.getVersion() }));
// update table row+details layout
eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.UPDATED_ENTITY, currentDS));
/* identify the changes */
setDistributionValues(currentDS, name, version, distSetTypeName, desc, isMigStepReq);
try {
distributionSetManagement.updateDistributionSet(currentDS);
notificationMessage.displaySuccess(i18n.get("message.new.dist.save.success",
new Object[] { currentDS.getName(), currentDS.getVersion() }));
// update table row+details layout
eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.UPDATED_ENTITY, currentDS));
} catch (final EntityAlreadyExistsException entityAlreadyExistsException) {
LOG.error("Update distribution failed {}", entityAlreadyExistsException);
notificationMessage.displayValidationError(
i18n.get("message.distribution.no.update", currentDS.getName() + ":" + currentDS.getVersion()));
}
}
} }
/** /**
@@ -221,27 +227,26 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
*/ */
private void addNewDistribution() { private void addNewDistribution() {
editDistribution = Boolean.FALSE; editDistribution = Boolean.FALSE;
final String name = HawkbitCommonUtil.trimAndNullIfEmpty(distNameTextField.getValue()); final String name = HawkbitCommonUtil.trimAndNullIfEmpty(distNameTextField.getValue());
final String version = HawkbitCommonUtil.trimAndNullIfEmpty(distVersionTextField.getValue()); final String version = HawkbitCommonUtil.trimAndNullIfEmpty(distVersionTextField.getValue());
final String distSetTypeName = HawkbitCommonUtil final String distSetTypeName = HawkbitCommonUtil
.trimAndNullIfEmpty((String) distsetTypeNameComboBox.getValue()); .trimAndNullIfEmpty((String) distsetTypeNameComboBox.getValue());
if (duplicateCheck(name, version)) { final String desc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue());
final String desc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue()); final boolean isMigStepReq = reqMigStepCheckbox.getValue();
final boolean isMigStepReq = reqMigStepCheckbox.getValue(); DistributionSet newDist = entityFactory.generateDistributionSet();
DistributionSet newDist = entityFactory.generateDistributionSet();
setDistributionValues(newDist, name, version, distSetTypeName, desc, isMigStepReq); setDistributionValues(newDist, name, version, distSetTypeName, desc, isMigStepReq);
newDist = distributionSetManagement.createDistributionSet(newDist); newDist = distributionSetManagement.createDistributionSet(newDist);
notificationMessage.displaySuccess(i18n.get("message.new.dist.save.success", notificationMessage.displaySuccess(
new Object[] { newDist.getName(), newDist.getVersion() })); i18n.get("message.new.dist.save.success", new Object[] { newDist.getName(), newDist.getVersion() }));
final Set<DistributionSetIdName> s = new HashSet<>(); final Set<DistributionSetIdName> s = new HashSet<>();
s.add(new DistributionSetIdName(newDist.getId(), newDist.getName(), newDist.getVersion())); s.add(new DistributionSetIdName(newDist.getId(), newDist.getName(), newDist.getVersion()));
final DistributionSetTable distributionSetTable = SpringContextHelper.getBean(DistributionSetTable.class); final DistributionSetTable distributionSetTable = SpringContextHelper.getBean(DistributionSetTable.class);
distributionSetTable.setValue(s); distributionSetTable.setValue(s);
}
} }
/** /**
@@ -267,7 +272,10 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
distributionSet.setRequiredMigrationStep(isMigStepReq); distributionSet.setRequiredMigrationStep(isMigStepReq);
} }
private boolean duplicateCheck(final String name, final String version) { private boolean isDuplicate() {
final String name = distNameTextField.getValue();
final String version = distVersionTextField.getValue();
final DistributionSet existingDs = distributionSetManagement.findDistributionSetByNameAndVersion(name, version); final DistributionSet existingDs = distributionSetManagement.findDistributionSetByNameAndVersion(name, version);
/* /*
* Distribution should not exists with the same name & version. Display * Distribution should not exists with the same name & version. Display
@@ -276,15 +284,16 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
* distribution Id of the edit window is different then the "existingDs" * distribution Id of the edit window is different then the "existingDs"
*/ */
if (existingDs != null && !existingDs.getId().equals(editDistId)) { if (existingDs != null && !existingDs.getId().equals(editDistId)) {
distNameTextField.addStyleName("v-textfield-error"); distNameTextField.addStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_LAYOUT_ERROR_HIGHTLIGHT);
distVersionTextField.addStyleName("v-textfield-error"); distVersionTextField.addStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_LAYOUT_ERROR_HIGHTLIGHT);
notificationMessage.displayValidationError( notificationMessage.displayValidationError(
i18n.get("message.duplicate.dist", new Object[] { existingDs.getName(), existingDs.getVersion() })); i18n.get("message.duplicate.dist", new Object[] { existingDs.getName(), existingDs.getVersion() }));
return false;
} else {
return true; return true;
} }
return false;
} }
/** /**
@@ -293,13 +302,12 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
public void resetComponents() { public void resetComponents() {
editDistribution = Boolean.FALSE; editDistribution = Boolean.FALSE;
distNameTextField.clear(); distNameTextField.clear();
distNameTextField.removeStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_ERROR); distNameTextField.removeStyleName("v-textfield-error");
distVersionTextField.clear(); distVersionTextField.clear();
distVersionTextField.removeStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_ERROR); distVersionTextField.removeStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_LAYOUT_ERROR_HIGHTLIGHT);
distsetTypeNameComboBox.removeStyleName(SPUIStyleDefinitions.SP_COMBOFIELD_ERROR); distsetTypeNameComboBox.removeStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_LAYOUT_ERROR_HIGHTLIGHT);
descTextArea.clear(); descTextArea.clear();
reqMigStepCheckbox.clear(); reqMigStepCheckbox.clear();
} }
private void populateValuesOfDistribution(final Long editDistId) { private void populateValuesOfDistribution(final Long editDistId) {
@@ -327,17 +335,21 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
} }
} }
/**
* Returns the dialog window for the distributions.
*
* @param editDistId
* @return window
*/
public CommonDialogWindow getWindow(final Long editDistId) { public CommonDialogWindow getWindow(final Long editDistId) {
eventBus.publish(this, DragEvent.HIDE_DROP_HINT); eventBus.publish(this, DragEvent.HIDE_DROP_HINT);
resetComponents(); resetComponents();
populateDistSetTypeNameCombo(); populateDistSetTypeNameCombo();
populateValuesOfDistribution(editDistId); populateValuesOfDistribution(editDistId);
window = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW).caption(i18n.get("caption.add.new.dist")) window = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW).caption(i18n.get("caption.add.new.dist"))
.content(this).saveButtonClickListener(event -> saveDistribution()).layout(formLayout).i18n(i18n) .content(this).layout(formLayout).i18n(i18n).saveDialogCloseListener(new SaveOnCloseDialogListener())
.buildCommonDialogWindow(); .buildCommonDialogWindow();
window.getButtonsLayout().removeStyleName("actionButtonsMargin");
return window; return window;
} }

View File

@@ -137,9 +137,9 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
final Boolean dsVisible = visibleItemIds.stream().filter(e -> e.getId().equals(ds.getId())).findFirst() final Boolean dsVisible = visibleItemIds.stream().filter(e -> e.getId().equals(ds.getId())).findFirst()
.isPresent(); .isPresent();
if ((ds.isComplete() && !dsVisible)) { if (ds.isComplete() && !dsVisible) {
refreshDistributions(); refreshDistributions();
} else if ((!ds.isComplete() && dsVisible)) { } else if (!ds.isComplete() && dsVisible) {
refreshDistributions(); refreshDistributions();
if (ds.getId().equals(managementUIState.getLastSelectedDsIdName().getId())) { if (ds.getId().equals(managementUIState.getLastSelectedDsIdName().getId())) {
managementUIState.setLastSelectedDistribution(null); managementUIState.setLastSelectedDistribution(null);

View File

@@ -36,7 +36,7 @@ import com.vaadin.ui.UI;
*/ */
@SpringComponent @SpringComponent
@ViewScope @ViewScope
public class CreateUpdateDistributionTagLayoutWindow extends AbstractCreateUpdateTagLayout { public class CreateUpdateDistributionTagLayoutWindow extends AbstractCreateUpdateTagLayout<DistributionSetTag> {
private static final long serialVersionUID = 444276149954167545L; private static final long serialVersionUID = 444276149954167545L;
@@ -80,19 +80,21 @@ public class CreateUpdateDistributionTagLayoutWindow extends AbstractCreateUpdat
optiongroup.addValueChangeListener(this::optionValueChanged); optiongroup.addValueChangeListener(this::optionValueChanged);
} }
/**
* Update DistributionTag.
*/
@Override @Override
public void save(final ClickEvent event) { protected void createEntity() {
final DistributionSetTag existingDistTag = tagManagement.findDistributionSetTag(tagName.getValue()); createNewTag();
if (optiongroup.getValue().equals(createTagStr)) {
if (!checkIsDuplicate(existingDistTag)) { }
createNewTag();
} @Override
} else { protected void updateEntity(final DistributionSetTag entity) {
updateExistingTag(existingDistTag); updateExistingTag(findEntityByName());
}
}
@Override
protected DistributionSetTag findEntityByName() {
return tagManagement.findDistributionSetTag(tagName.getValue());
} }
/** /**

View File

@@ -16,6 +16,7 @@ import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.repository.model.TargetIdName;
import org.eclipse.hawkbit.ui.common.CommonDialogWindow; import org.eclipse.hawkbit.ui.common.CommonDialogWindow;
import org.eclipse.hawkbit.ui.common.CommonDialogWindow.SaveDialogCloseListener;
import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder; import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder;
import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder; import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder;
import org.eclipse.hawkbit.ui.common.builder.WindowBuilder; import org.eclipse.hawkbit.ui.common.builder.WindowBuilder;
@@ -46,6 +47,7 @@ import com.vaadin.ui.Window;
@SpringComponent @SpringComponent
@VaadinSessionScope @VaadinSessionScope
public class TargetAddUpdateWindowLayout extends CustomComponent { public class TargetAddUpdateWindowLayout extends CustomComponent {
private static final long serialVersionUID = -6659290471705262389L; private static final long serialVersionUID = -6659290471705262389L;
@Autowired @Autowired
@@ -66,11 +68,31 @@ public class TargetAddUpdateWindowLayout extends CustomComponent {
private TextField controllerIDTextField; private TextField controllerIDTextField;
private TextField nameTextField; private TextField nameTextField;
private TextArea descTextArea; private TextArea descTextArea;
private boolean editTarget = Boolean.FALSE; private boolean editTarget;
private String controllerId; private String controllerId;
private FormLayout formLayout; private FormLayout formLayout;
private CommonDialogWindow window; private CommonDialogWindow window;
/**
* Save or update the target.
*/
private final class SaveOnDialogCloseListener implements SaveDialogCloseListener {
@Override
public void saveOrUpdate() {
if (editTarget) {
updateTarget();
return;
}
addNewTarget();
}
@Override
public boolean canWindowSaveOrUpdate() {
return editTarget || !isDuplicate();
}
}
/** /**
* Initialize the Add Update Window Component for Target. * Initialize the Add Update Window Component for Target.
*/ */
@@ -125,45 +147,42 @@ public class TargetAddUpdateWindowLayout extends CustomComponent {
eventBus.publish(this, new TargetTableEvent(BaseEntityEventType.UPDATED_ENTITY, latestTarget)); eventBus.publish(this, new TargetTableEvent(BaseEntityEventType.UPDATED_ENTITY, latestTarget));
} }
private void saveTargetListner() {
if (editTarget) {
updateTarget();
} else {
addNewTarget();
}
}
private void addNewTarget() { private void addNewTarget() {
final String newControlllerId = HawkbitCommonUtil.trimAndNullIfEmpty(controllerIDTextField.getValue()); final String newControlllerId = HawkbitCommonUtil.trimAndNullIfEmpty(controllerIDTextField.getValue());
if (duplicateCheck(newControlllerId)) { final String newName = HawkbitCommonUtil.trimAndNullIfEmpty(nameTextField.getValue());
final String newName = HawkbitCommonUtil.trimAndNullIfEmpty(nameTextField.getValue()); final String newDesc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue());
final String newDesc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue());
/* create new target entity */ /* create new target entity */
Target newTarget = entityFactory.generateTarget(newControlllerId); Target newTarget = entityFactory.generateTarget(newControlllerId);
/* set values to the new target entity */ /* set values to the new target entity */
setTargetValues(newTarget, newName, newDesc); setTargetValues(newTarget, newName, newDesc);
/* save new target */ /* save new target */
newTarget = targetManagement.createTarget(newTarget); newTarget = targetManagement.createTarget(newTarget);
final TargetTable targetTable = SpringContextHelper.getBean(TargetTable.class); final TargetTable targetTable = SpringContextHelper.getBean(TargetTable.class);
final Set<TargetIdName> s = new HashSet<>(); final Set<TargetIdName> s = new HashSet<>();
s.add(newTarget.getTargetIdName()); s.add(newTarget.getTargetIdName());
targetTable.setValue(s); targetTable.setValue(s);
/* display success msg */ /* display success msg */
uINotification.displaySuccess(i18n.get("message.save.success", new Object[] { newTarget.getName() })); uINotification.displaySuccess(i18n.get("message.save.success", new Object[] { newTarget.getName() }));
}
} }
public Window getWindow() { public Window getWindow() {
eventBus.publish(this, DragEvent.HIDE_DROP_HINT); eventBus.publish(this, DragEvent.HIDE_DROP_HINT);
window = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW).caption(i18n.get("caption.add.new.target")) window = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW).caption(i18n.get("caption.add.new.target"))
.content(this).saveButtonClickListener(event -> saveTargetListner()).layout(formLayout).i18n(i18n) .content(this).layout(formLayout).i18n(i18n).saveDialogCloseListener(new SaveOnDialogCloseListener())
.buildCommonDialogWindow(); .buildCommonDialogWindow();
return window; return window;
} }
/**
* Returns Target Update window based on the selected Entity Id in the
* target table.
*
* @param entityId
* @return window
*/
public Window getWindow(final String entityId) { public Window getWindow(final String entityId) {
populateValuesOfTarget(entityId); populateValuesOfTarget(entityId);
getWindow(); getWindow();
@@ -189,15 +208,17 @@ public class TargetAddUpdateWindowLayout extends CustomComponent {
target.setDescription(description); target.setDescription(description);
} }
private boolean duplicateCheck(final String newControlllerId) { private boolean isDuplicate() {
final String newControlllerId = controllerIDTextField.getValue();
final Target existingTarget = targetManagement.findTargetByControllerID(newControlllerId.trim()); final Target existingTarget = targetManagement.findTargetByControllerID(newControlllerId.trim());
if (existingTarget != null) { if (existingTarget != null) {
uINotification.displayValidationError( uINotification.displayValidationError(
i18n.get("message.target.duplicate.check", new Object[] { newControlllerId })); i18n.get("message.target.duplicate.check", new Object[] { newControlllerId }));
return false;
} else {
return true; return true;
} else {
return false;
} }
} }
/** /**

View File

@@ -103,9 +103,7 @@ public class TargetTable extends AbstractTable<Target, TargetIdName> {
private static final Logger LOG = LoggerFactory.getLogger(TargetTable.class); private static final Logger LOG = LoggerFactory.getLogger(TargetTable.class);
private static final String TARGET_PINNED = "targetPinned"; private static final String TARGET_PINNED = "targetPinned";
private static final long serialVersionUID = -2300392868806614568L; private static final long serialVersionUID = -2300392868806614568L;
private static final int PROPERTY_DEPT = 3; private static final int PROPERTY_DEPT = 3;
@Autowired @Autowired
@@ -121,7 +119,6 @@ public class TargetTable extends AbstractTable<Target, TargetIdName> {
private ManagementViewAcceptCriteria managementViewAcceptCriteria; private ManagementViewAcceptCriteria managementViewAcceptCriteria;
private Button targetPinnedBtn; private Button targetPinnedBtn;
private Boolean isTargetPinned = Boolean.FALSE; private Boolean isTargetPinned = Boolean.FALSE;
@Override @Override
@@ -228,17 +225,14 @@ public class TargetTable extends AbstractTable<Target, TargetIdName> {
protected Container createContainer() { protected Container createContainer() {
// ADD all the filters to the query config // ADD all the filters to the query config
final Map<String, Object> queryConfig = prepareQueryConfigFilters(); final Map<String, Object> queryConfig = prepareQueryConfigFilters();
// Create TargetBeanQuery factory with the query config. // Create TargetBeanQuery factory with the query config.
final BeanQueryFactory<TargetBeanQuery> targetQF = new BeanQueryFactory<>(TargetBeanQuery.class); final BeanQueryFactory<TargetBeanQuery> targetQF = new BeanQueryFactory<>(TargetBeanQuery.class);
targetQF.setQueryConfiguration(queryConfig); targetQF.setQueryConfiguration(queryConfig);
// create lazy query container with lazy defination and query // create lazy query container with lazy defination and query
final LazyQueryContainer targetTableContainer = new LazyQueryContainer( final LazyQueryContainer targetTableContainer = new LazyQueryContainer(
new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_CONT_ID_NAME), new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_CONT_ID_NAME),
targetQF); targetQF);
targetTableContainer.getQueryView().getQueryDefinition().setMaxNestedPropertyDepth(PROPERTY_DEPT); targetTableContainer.getQueryView().getQueryDefinition().setMaxNestedPropertyDepth(PROPERTY_DEPT);
return targetTableContainer; return targetTableContainer;
} }
@@ -319,7 +313,6 @@ public class TargetTable extends AbstractTable<Target, TargetIdName> {
shouldRefreshTargets = true; shouldRefreshTargets = true;
} }
} }
if (shouldRefreshTargets) { if (shouldRefreshTargets) {
refreshOnDelete(); refreshOnDelete();
} else { } else {

View File

@@ -26,7 +26,6 @@ import org.vaadin.spring.events.annotation.EventBusListenerMethod;
import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.SpringComponent;
import com.vaadin.spring.annotation.ViewScope; import com.vaadin.spring.annotation.ViewScope;
import com.vaadin.ui.Button.ClickEvent;
/** /**
* *
@@ -34,7 +33,7 @@ import com.vaadin.ui.Button.ClickEvent;
*/ */
@SpringComponent @SpringComponent
@ViewScope @ViewScope
public class CreateUpdateTargetTagLayoutWindow extends AbstractCreateUpdateTagLayout { public class CreateUpdateTargetTagLayoutWindow extends AbstractCreateUpdateTagLayout<TargetTag> {
private static final long serialVersionUID = 2446682350481560235L; private static final long serialVersionUID = 2446682350481560235L;
@@ -101,15 +100,18 @@ public class CreateUpdateTargetTagLayoutWindow extends AbstractCreateUpdateTagLa
} }
@Override @Override
public void save(final ClickEvent event) { protected void updateEntity(final TargetTag entity) {
final TargetTag existingTag = tagManagement.findTargetTag(tagName.getValue()); updateExistingTag(entity);
if (optiongroup.getValue().equals(createTagStr)) { }
if (!checkIsDuplicate(existingTag)) {
createNewTag(); @Override
} protected void createEntity() {
} else { createNewTag();
updateExistingTag(existingTag); }
}
@Override
protected TargetTag findEntityByName() {
return tagManagement.findTargetTag(tagName.getValue());
} }
/** /**

View File

@@ -29,6 +29,7 @@ import org.eclipse.hawkbit.repository.model.RolloutGroupConditionBuilder;
import org.eclipse.hawkbit.repository.model.RolloutGroupConditions; import org.eclipse.hawkbit.repository.model.RolloutGroupConditions;
import org.eclipse.hawkbit.ui.UiProperties; import org.eclipse.hawkbit.ui.UiProperties;
import org.eclipse.hawkbit.ui.common.CommonDialogWindow; import org.eclipse.hawkbit.ui.common.CommonDialogWindow;
import org.eclipse.hawkbit.ui.common.CommonDialogWindow.SaveDialogCloseListener;
import org.eclipse.hawkbit.ui.common.DistributionSetIdName; import org.eclipse.hawkbit.ui.common.DistributionSetIdName;
import org.eclipse.hawkbit.ui.common.builder.LabelBuilder; import org.eclipse.hawkbit.ui.common.builder.LabelBuilder;
import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder; import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder;
@@ -144,6 +145,28 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
private final NullValidator nullValidator = new NullValidator(null, false); private final NullValidator nullValidator = new NullValidator(null, false);
/**
* Save or update the rollout.
*/
private final class SaveOnDialogCloseListener implements SaveDialogCloseListener {
@Override
public void saveOrUpdate() {
if (editRolloutEnabled) {
editRollout();
return;
}
createRollout();
}
@Override
public boolean canWindowSaveOrUpdate() {
if (editRolloutEnabled) {
return duplicateCheckForEdit();
}
return duplicateCheck();
}
}
/** /**
* Create components and layout. * Create components and layout.
*/ */
@@ -168,9 +191,11 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
public CommonDialogWindow getWindow() { public CommonDialogWindow getWindow() {
resetComponents(); resetComponents();
return new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW).caption(i18n.get("caption.configure.rollout")) final CommonDialogWindow commonDialogWindow = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW)
.content(this).saveButtonClickListener(event -> onRolloutSave()).layout(this).i18n(i18n) .caption(i18n.get("caption.configure.rollout")).content(this).layout(this).i18n(i18n)
.helpLink(uiProperties.getLinks().getDocumentation().getRolloutView()).buildCommonDialogWindow(); .helpLink(uiProperties.getLinks().getDocumentation().getRolloutView())
.saveDialogCloseListener(new SaveOnDialogCloseListener()).buildCommonDialogWindow();
return commonDialogWindow;
} }
/** /**
@@ -395,35 +420,27 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
targetFilterQF); targetFilterQF);
} }
private void onRolloutSave() {
if (editRolloutEnabled) {
editRollout();
} else {
createRollout();
}
}
private void editRollout() { private void editRollout() {
if (duplicateCheckForEdit() && rolloutForEdit != null) { if (rolloutForEdit == null) {
rolloutForEdit.setName(rolloutName.getValue()); return;
rolloutForEdit.setDescription(description.getValue());
final DistributionSetIdName distributionSetIdName = (DistributionSetIdName) distributionSet.getValue();
rolloutForEdit.setDistributionSet(
distributionSetManagement.findDistributionSetById(distributionSetIdName.getId()));
rolloutForEdit.setActionType(getActionType());
rolloutForEdit.setForcedTime(getForcedTimeStamp());
final int amountGroup = Integer.parseInt(noOfGroups.getValue());
final int errorThresoldPercent = getErrorThresoldPercentage(amountGroup);
for (final RolloutGroup rolloutGroup : rolloutForEdit.getRolloutGroups()) {
rolloutGroup.setErrorConditionExp(triggerThreshold.getValue());
rolloutGroup.setSuccessConditionExp(String.valueOf(errorThresoldPercent));
}
final Rollout updatedRollout = rolloutManagement.updateRollout(rolloutForEdit);
uiNotification
.displaySuccess(i18n.get("message.update.success", new Object[] { updatedRollout.getName() }));
eventBus.publish(this, RolloutEvent.UPDATE_ROLLOUT);
} }
rolloutForEdit.setName(rolloutName.getValue());
rolloutForEdit.setDescription(description.getValue());
final DistributionSetIdName distributionSetIdName = (DistributionSetIdName) distributionSet.getValue();
rolloutForEdit
.setDistributionSet(distributionSetManagement.findDistributionSetById(distributionSetIdName.getId()));
rolloutForEdit.setActionType(getActionType());
rolloutForEdit.setForcedTime(getForcedTimeStamp());
final int amountGroup = Integer.parseInt(noOfGroups.getValue());
final int errorThresoldPercent = getErrorThresoldPercentage(amountGroup);
for (final RolloutGroup rolloutGroup : rolloutForEdit.getRolloutGroups()) {
rolloutGroup.setErrorConditionExp(triggerThreshold.getValue());
rolloutGroup.setSuccessConditionExp(String.valueOf(errorThresoldPercent));
}
final Rollout updatedRollout = rolloutManagement.updateRollout(rolloutForEdit);
uiNotification.displaySuccess(i18n.get("message.update.success", new Object[] { updatedRollout.getName() }));
eventBus.publish(this, RolloutEvent.UPDATE_ROLLOUT);
} }
private boolean duplicateCheckForEdit() { private boolean duplicateCheckForEdit() {
@@ -449,11 +466,8 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
} }
private void createRollout() { private void createRollout() {
if (duplicateCheck()) { final Rollout rolloutToCreate = saveRollout();
final Rollout rolloutToCreate = saveRollout(); uiNotification.displaySuccess(i18n.get("message.save.success", new Object[] { rolloutToCreate.getName() }));
uiNotification.displaySuccess(i18n.get("message.save.success", new Object[] { rolloutToCreate.getName() }));
eventBus.publish(this, RolloutEvent.CREATE_ROLLOUT);
}
} }
private Rollout saveRollout() { private Rollout saveRollout() {

View File

@@ -49,7 +49,6 @@ import com.vaadin.ui.UI;
* Common util class. * Common util class.
*/ */
public final class HawkbitCommonUtil { public final class HawkbitCommonUtil {
/** /**
* Define spaced string. * Define spaced string.
*/ */
@@ -58,21 +57,17 @@ public final class HawkbitCommonUtil {
* Define empty string. * Define empty string.
*/ */
public static final String SP_STRING_EMPTY = ""; public static final String SP_STRING_EMPTY = "";
/** /**
* Html span. * Html span.
*/ */
public static final String SPAN_CLOSE = "</span>"; public static final String SPAN_CLOSE = "</span>";
public static final String HTML_LI_CLOSE_TAG = "</li>"; public static final String HTML_LI_CLOSE_TAG = "</li>";
public static final String HTML_LI_OPEN_TAG = "<li>"; public static final String HTML_LI_OPEN_TAG = "<li>";
public static final String HTML_UL_CLOSE_TAG = "</ul>"; public static final String HTML_UL_CLOSE_TAG = "</ul>";
public static final String HTML_UL_OPEN_TAG = "<ul>"; public static final String HTML_UL_OPEN_TAG = "<ul>";
private static final String JS_DRAG_COUNT_REM_CHILD = " if(x) { document.head.removeChild(x); } "; private static final String JS_DRAG_COUNT_REM_CHILD = " if(x) { document.head.removeChild(x); } ";
public static final String DIV_DESCRIPTION_START = "<div id=\"desc-length\"><p id=\"desciption-p\">"; public static final String DIV_DESCRIPTION_START = "<div id=\"desc-length\"><p id=\"desciption-p\">";
public static final String DIV_DESCRIPTION_END = "</p></div>"; public static final String DIV_DESCRIPTION_END = "</p></div>";
private static final String DRAG_COUNT_ELEMENT = "var x = document.getElementById('sp-drag-count'); "; private static final String DRAG_COUNT_ELEMENT = "var x = document.getElementById('sp-drag-count'); ";
@@ -354,8 +349,6 @@ public final class HawkbitCommonUtil {
} }
/** /**
*
*
* @param newBrowserHeight * @param newBrowserHeight
* new browser height * new browser height
* @param minPopupHeight * @param minPopupHeight
@@ -635,11 +628,9 @@ public final class HawkbitCommonUtil {
final int assignedCount = result.getAssigned(); final int assignedCount = result.getAssigned();
final int alreadyAssignedCount = result.getAlreadyAssigned(); final int alreadyAssignedCount = result.getAlreadyAssigned();
final int unassignedCount = result.getUnassigned(); final int unassignedCount = result.getUnassigned();
if (assignedCount == 1) { if (assignedCount == 1) {
formMsg.append(i18n.get("message.target.assigned.one", formMsg.append(i18n.get("message.target.assigned.one",
new Object[] { result.getAssignedEntity().get(0).getName(), tagName })).append("<br>"); new Object[] { result.getAssignedEntity().get(0).getName(), tagName })).append("<br>");
} else if (assignedCount > 1) { } else if (assignedCount > 1) {
formMsg.append(i18n.get("message.target.assigned.many", new Object[] { assignedCount, tagName })) formMsg.append(i18n.get("message.target.assigned.many", new Object[] { assignedCount, tagName }))
.append("<br>"); .append("<br>");
@@ -650,11 +641,9 @@ public final class HawkbitCommonUtil {
formMsg.append(alreadyAssigned).append("<br>"); formMsg.append(alreadyAssigned).append("<br>");
} }
} }
if (unassignedCount == 1) { if (unassignedCount == 1) {
formMsg.append(i18n.get("message.target.unassigned.one", formMsg.append(i18n.get("message.target.unassigned.one",
new Object[] { result.getUnassignedEntity().get(0).getName(), tagName })).append("<br>"); new Object[] { result.getUnassignedEntity().get(0).getName(), tagName })).append("<br>");
} else if (unassignedCount > 1) { } else if (unassignedCount > 1) {
formMsg.append(i18n.get("message.target.unassigned.many", new Object[] { unassignedCount, tagName })) formMsg.append(i18n.get("message.target.unassigned.many", new Object[] { unassignedCount, tagName }))
.append("<br>"); .append("<br>");
@@ -679,7 +668,6 @@ public final class HawkbitCommonUtil {
} }
/** /**
*
* Create lazy query container for DS type. * Create lazy query container for DS type.
* *
* @param queryFactory * @param queryFactory

View File

@@ -1024,11 +1024,6 @@ public final class SPUIDefinitions {
*/ */
public static final String SOFTWAREMODULE_METADATA_TAB_ID = "swModule.metadata.tab.id"; public static final String SOFTWAREMODULE_METADATA_TAB_ID = "swModule.metadata.tab.id";
/***
* Custom window for metadata.
*/
public static final String CUSTOM_METADATA_WINDOW = "custom.metadata.window";
/** /**
* /** Constructor. * /** Constructor.
*/ */

View File

@@ -31,6 +31,8 @@ public final class SPUIStyleDefinitions {
*/ */
public static final String SP_TEXTFIELD_ERROR = "textfield-error"; public static final String SP_TEXTFIELD_ERROR = "textfield-error";
public static final String SP_TEXTFIELD_LAYOUT_ERROR_HIGHTLIGHT = "v-textfield-error";
/** /**
* STYLE to highlight wrong data combo box field. * STYLE to highlight wrong data combo box field.
*/ */
@@ -137,10 +139,10 @@ public final class SPUIStyleDefinitions {
*/ */
public static final String ARTIFACT_DTLS_ICON = "swm-artifact-dtls-icon"; public static final String ARTIFACT_DTLS_ICON = "swm-artifact-dtls-icon";
/** /**
* Distribution metadata icon style. * Distribution metadata icon style.
*/ */
public static final String DS_METADATA_ICON = "ds-metadata-icon"; public static final String DS_METADATA_ICON = "ds-metadata-icon";
/** /**
* Target table style. * Target table style.