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

@@ -8,8 +8,6 @@
*/
package org.eclipse.hawkbit.ui.artifacts.smtable;
import java.io.Serializable;
import javax.annotation.PostConstruct;
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.ui.artifacts.event.SoftwareModuleEvent;
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.builder.TextAreaBuilder;
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.SPUIDefinitions;
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
import org.eclipse.hawkbit.ui.utils.SpringContextHelper;
import org.eclipse.hawkbit.ui.utils.UINotification;
import org.springframework.beans.factory.annotation.Autowired;
import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory;
@@ -48,7 +48,7 @@ import com.vaadin.ui.themes.ValoTheme;
*/
@SpringComponent
@ViewScope
public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Serializable {
public class SoftwareModuleAddUpdateWindow extends CustomComponent {
private static final long serialVersionUID = -5217675246477211483L;
@@ -85,6 +85,25 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Se
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.
*/
@@ -180,12 +199,8 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Se
setCompositionRoot(formLayout);
window = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW)
.caption(i18n.get("upload.caption.add.new.swmodule")).content(this)
.saveButtonClickListener(event -> saveOrUpdate()).layout(formLayout).i18n(i18n)
.buildCommonDialogWindow();
window.getButtonsLayout().removeStyleName("actionButtonsMargin");
.caption(i18n.get("upload.caption.add.new.swmodule")).content(this).layout(formLayout).i18n(i18n)
.saveDialogCloseListener(new SaveOnDialogCloseListener()).buildCommonDialogWindow();
nameTextField.setEnabled(!editSwModule);
versionTextField.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 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(
i18n.get("message.duplicate.softwaremodule", new Object[] { name, version }));
} else {
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 true;
}
return false;
}
/**
@@ -254,14 +281,6 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Se
typeComboBox.setValue(swModle.getType().getName());
}
private void saveOrUpdate() {
if (editSwModule) {
updateSwModule();
} else {
addNewBaseSoftware();
}
}
public FormLayout getFormLayout() {
return formLayout;
}

View File

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

View File

@@ -332,6 +332,7 @@ public class UploadStatusInfoWindow extends Window {
restoreState();
}
@SuppressWarnings("unchecked")
private void uploadRecevied(final String filename, final SoftwareModule softwareModule) {
final Item item = uploads.addItem(getItemid(filename, softwareModule));
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.model.MetaData;
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.TextAreaBuilder;
import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder;
@@ -97,6 +98,27 @@ public abstract class AbstractMetadataPopupLayout<E extends NamedVersionedEntity
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
void init() {
createComponents();
@@ -117,11 +139,11 @@ public abstract class AbstractMetadataPopupLayout<E extends NamedVersionedEntity
selectedEntity = entity;
final String nameVersion = HawkbitCommonUtil.getFormattedNameVersion(entity.getName(), entity.getVersion());
metadataWindow = new WindowBuilder(SPUIDefinitions.CUSTOM_METADATA_WINDOW)
.caption(getMetadataCaption(nameVersion)).content(this).saveButtonClickListener(event -> onSave())
.cancelButtonClickListener(event -> onCancel()).layout(mainLayout).i18n(i18n).buildCommonDialogWindow();
metadataWindow = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW)
.caption(getMetadataCaption(nameVersion)).content(this).cancelButtonClickListener(event -> onCancel())
.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.setWidth(800, Unit.PIXELS);
metadataWindow.getMainLayout().setSizeFull();

View File

@@ -50,6 +50,7 @@ import com.vaadin.ui.AbstractLayout;
import com.vaadin.ui.AbstractOrderedLayout;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.Component;
@@ -89,11 +90,9 @@ public class CommonDialogWindow extends Window {
protected ValueChangeListener buttonEnableListener;
private final ClickListener saveButtonClickListener;
private final ClickListener cancelButtonClickListener;
private final ClickListener closeClickListener = event -> close();
private final ClickListener closeClickListener = event -> onCloseEvent(event);
private final transient Map<Component, Object> orginalValues;
@@ -101,6 +100,8 @@ public class CommonDialogWindow extends Window {
private final I18N i18n;
private transient SaveDialogCloseListener closeListener;
/**
* Constructor.
*
@@ -110,8 +111,8 @@ public class CommonDialogWindow extends Window {
* the content
* @param helpLink
* the helpLinks
* @param saveButtonClickListener
* the saveButtonClickListener
* @param closeListener
* the saveDialogCloseListener
* @param cancelButtonClickListener
* the cancelButtonClickListener
* @param layout
@@ -120,13 +121,13 @@ public class CommonDialogWindow extends Window {
* the i18n service
*/
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) {
checkNotNull(saveButtonClickListener);
checkNotNull(closeListener);
this.caption = caption;
this.content = content;
this.helpLink = helpLink;
this.saveButtonClickListener = saveButtonClickListener;
this.closeListener = closeListener;
this.cancelButtonClickListener = cancelButtonClickListener;
this.orginalValues = new HashMap<>();
this.allComponents = getAllComponents(layout);
@@ -134,6 +135,23 @@ public class CommonDialogWindow extends Window {
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
public void close() {
super.close();
@@ -210,7 +228,7 @@ public class CommonDialogWindow extends Window {
setModal(true);
addStyleName("fontsize");
setOrginaleValues();
addListeners();
addComponentListeners();
}
/**
@@ -229,12 +247,6 @@ public class CommonDialogWindow extends Window {
saveButton.setEnabled(isSaveButtonEnabledAfterValueChange(null, null));
}
protected void addListeners() {
addComponenetListeners();
addCloseListenerForSaveButton();
addCloseListenerForCancelButton();
}
protected void addCloseListenerForSaveButton() {
saveButton.addClickListener(closeClickListener);
}
@@ -243,7 +255,7 @@ public class CommonDialogWindow extends Window {
cancelButton.addClickListener(closeClickListener);
}
protected void addComponenetListeners() {
protected void addComponentListeners() {
for (final AbstractField<?> field : allComponents) {
if (field instanceof TextChangeNotifier) {
((TextChangeNotifier) field).addTextChangeListener(new ChangeListener(field));
@@ -431,6 +443,7 @@ public class CommonDialogWindow extends Window {
FontAwesome.TIMES, SPUIButtonStyleNoBorderWithIcon.class);
cancelButton.setSizeUndefined();
cancelButton.addStyleName("default-color");
addCloseListenerForCancelButton();
if (cancelButtonClickListener != null) {
cancelButton.addClickListener(cancelButtonClickListener);
}
@@ -445,7 +458,7 @@ public class CommonDialogWindow extends Window {
FontAwesome.SAVE, SPUIButtonStyleNoBorderWithIcon.class);
saveButton.setSizeUndefined();
saveButton.addStyleName("default-color");
saveButton.addClickListener(saveButtonClickListener);
addCloseListenerForSaveButton();
saveButton.setEnabled(false);
buttonsLayout.addComponent(saveButton);
buttonsLayout.setComponentAlignment(saveButton, Alignment.MIDDLE_RIGHT);
@@ -505,7 +518,7 @@ public class CommonDialogWindow extends Window {
* @param component
* AbstractField
*/
public void updateAllComponents(final AbstractField component) {
public void updateAllComponents(final AbstractField<?> component) {
allComponents.add(component);
component.addValueChangeListener(new ChangeListener(component));
@@ -522,4 +535,36 @@ public class CommonDialogWindow extends Window {
public void setCancelButtonEnabled(final boolean 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;
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.SPUIDefinitions;
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
@@ -26,7 +26,6 @@ public class WindowBuilder {
private String caption;
private Component content;
private ClickListener saveButtonClickListener;
private ClickListener cancelButtonClickListener;
private String helpLink;
private AbstractLayout layout;
@@ -34,6 +33,8 @@ public class WindowBuilder {
private final String type;
private String id;
private SaveDialogCloseListener saveDialogCloseListener;
/**
* Constructor.
*
@@ -44,6 +45,18 @@ public class WindowBuilder {
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.
*
@@ -68,18 +81,6 @@ public class WindowBuilder {
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.
*
@@ -143,20 +144,9 @@ public class WindowBuilder {
* @return the window.
*/
public CommonDialogWindow buildCommonDialogWindow() {
CommonDialogWindow window;
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);
final CommonDialogWindow window = new CommonDialogWindow(caption, content, helpLink, saveDialogCloseListener,
cancelButtonClickListener, layout, i18n);
decorateWindow(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.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout;
@@ -56,7 +55,7 @@ import com.vaadin.ui.themes.ValoTheme;
*/
@SpringComponent
@ViewScope
public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout {
public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout<DistributionSetType> {
private static final long serialVersionUID = -5169398523815877767L;
private static final String DIST_TYPE_NAME = "name";
@@ -456,7 +455,7 @@ public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout {
super.optionValueChanged(event);
if (updateTypeStr.equals(event.getProperty().getValue())) {
if (updateTagStr.equals(event.getProperty().getValue())) {
selectedTable.getContainerDataSource().removeAllItems();
getSourceTableData();
distTypeSelectLayout.setEnabled(false);
@@ -568,18 +567,30 @@ public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout {
}
@Override
protected void save(final ClickEvent event) {
final DistributionSetType existingDistTypeByKey = distributionSetManagement
.findDistributionSetTypeByKey(typeKey.getValue());
final DistributionSetType existingDistTypeByName = distributionSetManagement
.findDistributionSetTypeByName(tagName.getValue());
if (optiongroup.getValue().equals(createTypeStr)) {
if (!checkIsDuplicateByKey(existingDistTypeByKey) && !checkIsDuplicate(existingDistTypeByName)) {
createNewDistributionSetType();
}
} else {
updateDistributionSetType(existingDistTypeByKey);
}
protected void updateEntity(final DistributionSetType entity) {
updateDistributionSetType(entity);
}
@Override
protected void createEntity() {
createNewDistributionSetType();
}
@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

View File

@@ -13,12 +13,14 @@ import javax.annotation.PreDestroy;
import org.eclipse.hawkbit.repository.SpPermissionChecker;
import org.eclipse.hawkbit.repository.TagManagement;
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.TargetTag;
import org.eclipse.hawkbit.ui.colorpicker.ColorPickerConstants;
import org.eclipse.hawkbit.ui.colorpicker.ColorPickerHelper;
import org.eclipse.hawkbit.ui.colorpicker.ColorPickerLayout;
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.TextAreaBuilder;
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;
/**
*
* 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 {
private static final long serialVersionUID = 4229177824620576456L;
private static final String TAG_NAME_DYNAMIC_STYLE = "new-tag-name";
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 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.
@@ -400,7 +424,7 @@ public abstract class AbstractCreateUpdateTagLayout extends CustomComponent
*
* @param colorPickedPreview
*/
private void getTargetDynamicStyles(final String colorPickedPreview) {
private static void getTargetDynamicStyles(final String colorPickedPreview) {
Page.getCurrent().getJavaScript()
.execute(HawkbitCommonUtil.changeToNewSelectedPreviewColor(colorPickedPreview));
}
@@ -463,9 +487,8 @@ public abstract class AbstractCreateUpdateTagLayout extends CustomComponent
public CommonDialogWindow getWindow() {
reset();
window = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW).caption(getWindowCaption()).content(this)
.saveButtonClickListener(this::save).cancelButtonClickListener(event -> discard()).layout(mainLayout)
.i18n(i18n).buildCommonDialogWindow();
.cancelButtonClickListener(event -> discard()).layout(mainLayout).i18n(i18n)
.saveDialogCloseListener(new SaveOnDialogCloseListener()).buildCommonDialogWindow();
return window;
}
@@ -562,12 +585,19 @@ public abstract class AbstractCreateUpdateTagLayout extends CustomComponent
getPreviewButtonColor(previewColor);
}
protected Boolean checkIsDuplicate(final Tag existingTag) {
if (existingTag != null) {
displayValidationError(i18n.get("message.tag.duplicate.check", new Object[] { existingTag.getName() }));
return Boolean.TRUE;
private boolean isDuplicateByName() {
final E existingType = findEntityByName();
if (existingType != null) {
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() {
@@ -610,4 +640,12 @@ public abstract class AbstractCreateUpdateTagLayout extends CustomComponent
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;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
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.ColorPickerHelper;
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.shared.ui.colorpicker.Color;
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.TextField;
import com.vaadin.ui.components.colorpicker.ColorChangeEvent;
import com.vaadin.ui.components.colorpicker.ColorSelector;
import com.vaadin.ui.themes.ValoTheme;
/**
* Superclass defining common properties and methods for creating/updating
* types.
*/
public abstract class CreateUpdateTypeLayout extends AbstractCreateUpdateTagLayout {
public abstract class CreateUpdateTypeLayout<E extends NamedEntity> extends AbstractCreateUpdateTagLayout<E> {
private static final long serialVersionUID = 5732904956185988397L;
protected String createTypeStr;
protected String updateTypeStr;
protected TextField typeKey;
public static final String TYPE_NAME_DYNAMIC_STYLE = "new-tag-name";
@@ -55,11 +48,10 @@ public abstract class CreateUpdateTypeLayout extends AbstractCreateUpdateTagLayo
@Override
protected void createRequiredComponents() {
createTypeStr = i18n.get("label.create.type");
updateTypeStr = i18n.get("label.update.type");
createTagStr = i18n.get("label.create.type");
updateTagStr = i18n.get("label.update.type");
comboLabel = new LabelBuilder().name(i18n.get("label.choose.type")).buildLabel();
colorLabel = new LabelBuilder().name(i18n.get("label.choose.type.color")).buildLabel();
colorLabel.addStyleName(SPUIDefinitions.COLOR_LABEL_STYLE);
tagNameComboBox = SPUIComponentProvider.getComboBox(i18n.get("label.combobox.type"), "", "", null, null, false,
@@ -137,7 +129,7 @@ public abstract class CreateUpdateTypeLayout extends AbstractCreateUpdateTagLayo
@Override
protected void optionValueChanged(final ValueChangeEvent event) {
if (updateTypeStr.equals(event.getProperty().getValue())) {
if (updateTagStr.equals(event.getProperty().getValue())) {
tagName.clear();
tagDesc.clear();
typeKey.clear();
@@ -193,38 +185,6 @@ public abstract class CreateUpdateTypeLayout extends AbstractCreateUpdateTagLayo
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) {
if (null == color) {
@@ -257,37 +217,27 @@ public abstract class CreateUpdateTypeLayout extends AbstractCreateUpdateTagLayo
createDynamicStyleForComponents(tagName, typeKey, tagDesc, event.getColor().getCSS());
}
protected Boolean checkIsDuplicate(final NamedEntity existingType) {
private boolean isDuplicateByKey() {
final E existingType = findEntityByKey();
if (existingType != null) {
uiNotification.displayValidationError(
i18n.get("message.tag.duplicate.check", new Object[] { existingType.getName() }));
return Boolean.TRUE;
uiNotification.displayValidationError(getDuplicateKeyErrorMessage(existingType));
return true;
}
return Boolean.FALSE;
}
protected Boolean checkIsDuplicateByKey(final NamedEntity existingType) {
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;
return false;
}
@Override
protected void save(final ClickEvent event) {
// is implemented in the inherited class
protected boolean isDuplicate() {
return isDuplicateByKey() || super.isDuplicate();
}
protected abstract E findEntityByKey();
protected abstract String getDuplicateKeyErrorMessage(E existingType);
@Override
protected void populateTagNameCombo() {
// 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.EntityFactory;
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.DistributionSetType;
import org.eclipse.hawkbit.repository.model.TenantMetaData;
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.DistributionSetTypeBeanQuery;
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.SpringContextHelper;
import org.eclipse.hawkbit.ui.utils.UINotification;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory;
import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer;
@@ -68,8 +66,6 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
private static final long serialVersionUID = -5602182034230568435L;
private static final Logger LOG = LoggerFactory.getLogger(DistributionAddUpdateWindowLayout.class);
@Autowired
private I18N i18n;
@@ -87,6 +83,7 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
@Autowired
private transient EntityFactory entityFactory;
private TextField distNameTextField;
private TextField distVersionTextField;
private TextArea descTextArea;
@@ -98,6 +95,27 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
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.
*/
@@ -178,42 +196,30 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
return tenantMetaData.getDefaultDsType();
}
private void saveDistribution() {
if (editDistribution) {
updateDistribution();
} else {
addNewDistribution();
}
}
/**
* Update Distribution.
*/
private void updateDistribution() {
if (isDuplicate()) {
return;
}
final String name = HawkbitCommonUtil.trimAndNullIfEmpty(distNameTextField.getValue());
final String version = HawkbitCommonUtil.trimAndNullIfEmpty(distVersionTextField.getValue());
final String distSetTypeName = HawkbitCommonUtil
.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)) {
final DistributionSet currentDS = distributionSetManagement.findDistributionSetByIdWithDetails(editDistId);
final String desc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue());
final boolean isMigStepReq = reqMigStepCheckbox.getValue();
/* identify the changes */
setDistributionValues(currentDS, name, version, distSetTypeName, desc, isMigStepReq);
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));
/* 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() {
editDistribution = Boolean.FALSE;
final String name = HawkbitCommonUtil.trimAndNullIfEmpty(distNameTextField.getValue());
final String version = HawkbitCommonUtil.trimAndNullIfEmpty(distVersionTextField.getValue());
final String distSetTypeName = HawkbitCommonUtil
.trimAndNullIfEmpty((String) distsetTypeNameComboBox.getValue());
if (duplicateCheck(name, version)) {
final String desc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue());
final boolean isMigStepReq = reqMigStepCheckbox.getValue();
DistributionSet newDist = entityFactory.generateDistributionSet();
final String desc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue());
final boolean isMigStepReq = reqMigStepCheckbox.getValue();
DistributionSet newDist = entityFactory.generateDistributionSet();
setDistributionValues(newDist, name, version, distSetTypeName, desc, isMigStepReq);
newDist = distributionSetManagement.createDistributionSet(newDist);
setDistributionValues(newDist, name, version, distSetTypeName, desc, isMigStepReq);
newDist = distributionSetManagement.createDistributionSet(newDist);
notificationMessage.displaySuccess(i18n.get("message.new.dist.save.success",
new Object[] { newDist.getName(), newDist.getVersion() }));
notificationMessage.displaySuccess(
i18n.get("message.new.dist.save.success", new Object[] { newDist.getName(), newDist.getVersion() }));
final Set<DistributionSetIdName> s = new HashSet<>();
s.add(new DistributionSetIdName(newDist.getId(), newDist.getName(), newDist.getVersion()));
final DistributionSetTable distributionSetTable = SpringContextHelper.getBean(DistributionSetTable.class);
distributionSetTable.setValue(s);
}
final Set<DistributionSetIdName> s = new HashSet<>();
s.add(new DistributionSetIdName(newDist.getId(), newDist.getName(), newDist.getVersion()));
final DistributionSetTable distributionSetTable = SpringContextHelper.getBean(DistributionSetTable.class);
distributionSetTable.setValue(s);
}
/**
@@ -267,7 +272,10 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
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);
/*
* 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"
*/
if (existingDs != null && !existingDs.getId().equals(editDistId)) {
distNameTextField.addStyleName("v-textfield-error");
distVersionTextField.addStyleName("v-textfield-error");
distNameTextField.addStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_LAYOUT_ERROR_HIGHTLIGHT);
distVersionTextField.addStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_LAYOUT_ERROR_HIGHTLIGHT);
notificationMessage.displayValidationError(
i18n.get("message.duplicate.dist", new Object[] { existingDs.getName(), existingDs.getVersion() }));
return false;
} else {
return true;
}
return false;
}
/**
@@ -293,13 +302,12 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
public void resetComponents() {
editDistribution = Boolean.FALSE;
distNameTextField.clear();
distNameTextField.removeStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_ERROR);
distNameTextField.removeStyleName("v-textfield-error");
distVersionTextField.clear();
distVersionTextField.removeStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_ERROR);
distsetTypeNameComboBox.removeStyleName(SPUIStyleDefinitions.SP_COMBOFIELD_ERROR);
distVersionTextField.removeStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_LAYOUT_ERROR_HIGHTLIGHT);
distsetTypeNameComboBox.removeStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_LAYOUT_ERROR_HIGHTLIGHT);
descTextArea.clear();
reqMigStepCheckbox.clear();
}
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) {
eventBus.publish(this, DragEvent.HIDE_DROP_HINT);
resetComponents();
populateDistSetTypeNameCombo();
populateValuesOfDistribution(editDistId);
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();
window.getButtonsLayout().removeStyleName("actionButtonsMargin");
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()
.isPresent();
if ((ds.isComplete() && !dsVisible)) {
if (ds.isComplete() && !dsVisible) {
refreshDistributions();
} else if ((!ds.isComplete() && dsVisible)) {
} else if (!ds.isComplete() && dsVisible) {
refreshDistributions();
if (ds.getId().equals(managementUIState.getLastSelectedDsIdName().getId())) {
managementUIState.setLastSelectedDistribution(null);

View File

@@ -36,7 +36,7 @@ import com.vaadin.ui.UI;
*/
@SpringComponent
@ViewScope
public class CreateUpdateDistributionTagLayoutWindow extends AbstractCreateUpdateTagLayout {
public class CreateUpdateDistributionTagLayoutWindow extends AbstractCreateUpdateTagLayout<DistributionSetTag> {
private static final long serialVersionUID = 444276149954167545L;
@@ -80,19 +80,21 @@ public class CreateUpdateDistributionTagLayoutWindow extends AbstractCreateUpdat
optiongroup.addValueChangeListener(this::optionValueChanged);
}
/**
* Update DistributionTag.
*/
@Override
public void save(final ClickEvent event) {
final DistributionSetTag existingDistTag = tagManagement.findDistributionSetTag(tagName.getValue());
if (optiongroup.getValue().equals(createTagStr)) {
if (!checkIsDuplicate(existingDistTag)) {
createNewTag();
}
} else {
updateExistingTag(existingDistTag);
}
protected void createEntity() {
createNewTag();
}
@Override
protected void updateEntity(final DistributionSetTag entity) {
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.TargetIdName;
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.TextFieldBuilder;
import org.eclipse.hawkbit.ui.common.builder.WindowBuilder;
@@ -46,6 +47,7 @@ import com.vaadin.ui.Window;
@SpringComponent
@VaadinSessionScope
public class TargetAddUpdateWindowLayout extends CustomComponent {
private static final long serialVersionUID = -6659290471705262389L;
@Autowired
@@ -66,11 +68,31 @@ public class TargetAddUpdateWindowLayout extends CustomComponent {
private TextField controllerIDTextField;
private TextField nameTextField;
private TextArea descTextArea;
private boolean editTarget = Boolean.FALSE;
private boolean editTarget;
private String controllerId;
private FormLayout formLayout;
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.
*/
@@ -125,45 +147,42 @@ public class TargetAddUpdateWindowLayout extends CustomComponent {
eventBus.publish(this, new TargetTableEvent(BaseEntityEventType.UPDATED_ENTITY, latestTarget));
}
private void saveTargetListner() {
if (editTarget) {
updateTarget();
} else {
addNewTarget();
}
}
private void addNewTarget() {
final String newControlllerId = HawkbitCommonUtil.trimAndNullIfEmpty(controllerIDTextField.getValue());
if (duplicateCheck(newControlllerId)) {
final String newName = HawkbitCommonUtil.trimAndNullIfEmpty(nameTextField.getValue());
final String newDesc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue());
final String newName = HawkbitCommonUtil.trimAndNullIfEmpty(nameTextField.getValue());
final String newDesc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue());
/* create new target entity */
Target newTarget = entityFactory.generateTarget(newControlllerId);
/* set values to the new target entity */
setTargetValues(newTarget, newName, newDesc);
/* save new target */
newTarget = targetManagement.createTarget(newTarget);
final TargetTable targetTable = SpringContextHelper.getBean(TargetTable.class);
final Set<TargetIdName> s = new HashSet<>();
s.add(newTarget.getTargetIdName());
targetTable.setValue(s);
/* create new target entity */
Target newTarget = entityFactory.generateTarget(newControlllerId);
/* set values to the new target entity */
setTargetValues(newTarget, newName, newDesc);
/* save new target */
newTarget = targetManagement.createTarget(newTarget);
final TargetTable targetTable = SpringContextHelper.getBean(TargetTable.class);
final Set<TargetIdName> s = new HashSet<>();
s.add(newTarget.getTargetIdName());
targetTable.setValue(s);
/* display success msg */
uINotification.displaySuccess(i18n.get("message.save.success", new Object[] { newTarget.getName() }));
}
/* display success msg */
uINotification.displaySuccess(i18n.get("message.save.success", new Object[] { newTarget.getName() }));
}
public Window getWindow() {
eventBus.publish(this, DragEvent.HIDE_DROP_HINT);
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();
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) {
populateValuesOfTarget(entityId);
getWindow();
@@ -189,15 +208,17 @@ public class TargetAddUpdateWindowLayout extends CustomComponent {
target.setDescription(description);
}
private boolean duplicateCheck(final String newControlllerId) {
private boolean isDuplicate() {
final String newControlllerId = controllerIDTextField.getValue();
final Target existingTarget = targetManagement.findTargetByControllerID(newControlllerId.trim());
if (existingTarget != null) {
uINotification.displayValidationError(
i18n.get("message.target.duplicate.check", new Object[] { newControlllerId }));
return false;
} else {
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 String TARGET_PINNED = "targetPinned";
private static final long serialVersionUID = -2300392868806614568L;
private static final int PROPERTY_DEPT = 3;
@Autowired
@@ -121,7 +119,6 @@ public class TargetTable extends AbstractTable<Target, TargetIdName> {
private ManagementViewAcceptCriteria managementViewAcceptCriteria;
private Button targetPinnedBtn;
private Boolean isTargetPinned = Boolean.FALSE;
@Override
@@ -228,17 +225,14 @@ public class TargetTable extends AbstractTable<Target, TargetIdName> {
protected Container createContainer() {
// ADD all the filters to the query config
final Map<String, Object> queryConfig = prepareQueryConfigFilters();
// Create TargetBeanQuery factory with the query config.
final BeanQueryFactory<TargetBeanQuery> targetQF = new BeanQueryFactory<>(TargetBeanQuery.class);
targetQF.setQueryConfiguration(queryConfig);
// create lazy query container with lazy defination and query
final LazyQueryContainer targetTableContainer = new LazyQueryContainer(
new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_CONT_ID_NAME),
targetQF);
targetTableContainer.getQueryView().getQueryDefinition().setMaxNestedPropertyDepth(PROPERTY_DEPT);
return targetTableContainer;
}
@@ -319,7 +313,6 @@ public class TargetTable extends AbstractTable<Target, TargetIdName> {
shouldRefreshTargets = true;
}
}
if (shouldRefreshTargets) {
refreshOnDelete();
} 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.ViewScope;
import com.vaadin.ui.Button.ClickEvent;
/**
*
@@ -34,7 +33,7 @@ import com.vaadin.ui.Button.ClickEvent;
*/
@SpringComponent
@ViewScope
public class CreateUpdateTargetTagLayoutWindow extends AbstractCreateUpdateTagLayout {
public class CreateUpdateTargetTagLayoutWindow extends AbstractCreateUpdateTagLayout<TargetTag> {
private static final long serialVersionUID = 2446682350481560235L;
@@ -101,15 +100,18 @@ public class CreateUpdateTargetTagLayoutWindow extends AbstractCreateUpdateTagLa
}
@Override
public void save(final ClickEvent event) {
final TargetTag existingTag = tagManagement.findTargetTag(tagName.getValue());
if (optiongroup.getValue().equals(createTagStr)) {
if (!checkIsDuplicate(existingTag)) {
createNewTag();
}
} else {
updateExistingTag(existingTag);
}
protected void updateEntity(final TargetTag entity) {
updateExistingTag(entity);
}
@Override
protected void createEntity() {
createNewTag();
}
@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.ui.UiProperties;
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.builder.LabelBuilder;
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);
/**
* 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.
*/
@@ -168,9 +191,11 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
public CommonDialogWindow getWindow() {
resetComponents();
return new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW).caption(i18n.get("caption.configure.rollout"))
.content(this).saveButtonClickListener(event -> onRolloutSave()).layout(this).i18n(i18n)
.helpLink(uiProperties.getLinks().getDocumentation().getRolloutView()).buildCommonDialogWindow();
final CommonDialogWindow commonDialogWindow = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW)
.caption(i18n.get("caption.configure.rollout")).content(this).layout(this).i18n(i18n)
.helpLink(uiProperties.getLinks().getDocumentation().getRolloutView())
.saveDialogCloseListener(new SaveOnDialogCloseListener()).buildCommonDialogWindow();
return commonDialogWindow;
}
/**
@@ -395,35 +420,27 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
targetFilterQF);
}
private void onRolloutSave() {
if (editRolloutEnabled) {
editRollout();
} else {
createRollout();
}
}
private void editRollout() {
if (duplicateCheckForEdit() && rolloutForEdit != null) {
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);
if (rolloutForEdit == null) {
return;
}
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() {
@@ -449,11 +466,8 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
}
private void createRollout() {
if (duplicateCheck()) {
final Rollout rolloutToCreate = saveRollout();
uiNotification.displaySuccess(i18n.get("message.save.success", new Object[] { rolloutToCreate.getName() }));
eventBus.publish(this, RolloutEvent.CREATE_ROLLOUT);
}
final Rollout rolloutToCreate = saveRollout();
uiNotification.displaySuccess(i18n.get("message.save.success", new Object[] { rolloutToCreate.getName() }));
}
private Rollout saveRollout() {

View File

@@ -49,7 +49,6 @@ import com.vaadin.ui.UI;
* Common util class.
*/
public final class HawkbitCommonUtil {
/**
* Define spaced string.
*/
@@ -58,21 +57,17 @@ public final class HawkbitCommonUtil {
* Define empty string.
*/
public static final String SP_STRING_EMPTY = "";
/**
* Html span.
*/
public static final String SPAN_CLOSE = "</span>";
public static final String HTML_LI_CLOSE_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_OPEN_TAG = "<ul>";
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_END = "</p></div>";
private static final String DRAG_COUNT_ELEMENT = "var x = document.getElementById('sp-drag-count'); ";
@@ -119,7 +114,7 @@ public final class HawkbitCommonUtil {
/**
* Trim the text and convert into null in case of empty string.
*
*
* @param text
* as text to be trimed
* @return null if the text is null or if the text is blank, text.trim() if
@@ -136,7 +131,7 @@ public final class HawkbitCommonUtil {
/**
* Concatenate the given text all the string arguments with the given
* delimiter.
*
*
* @param delimiter
* the delimiter text to be used while concatenation.
* @param texts
@@ -162,7 +157,7 @@ public final class HawkbitCommonUtil {
/**
* Returns the input text within html bold tag <b>..</b>.
*
*
* @param text
* is the text to be converted in to Bold
* @return null if the input text param is null returns text with <b>...</b>
@@ -181,7 +176,7 @@ public final class HawkbitCommonUtil {
/**
* Get target label Id.
*
*
* @param controllerId
* as String
* @return String as label name
@@ -192,7 +187,7 @@ public final class HawkbitCommonUtil {
/**
* Get distribution table cell id.
*
*
* @param name
* distribution name
* @param version
@@ -205,7 +200,7 @@ public final class HawkbitCommonUtil {
/**
* Get software module label id.
*
*
* @param name
* software module name
* @param version
@@ -218,7 +213,7 @@ public final class HawkbitCommonUtil {
/**
* Get label with software module name and description.
*
*
* @param name
* software module name
* @param desc
@@ -233,7 +228,7 @@ public final class HawkbitCommonUtil {
/**
* Get Label for Artifact Details.
*
*
* @param name
* @return
*/
@@ -245,7 +240,7 @@ public final class HawkbitCommonUtil {
/**
* Get Label for Artifact Details.
*
*
* @param caption
* as caption of the details
* @param name
@@ -260,7 +255,7 @@ public final class HawkbitCommonUtil {
/**
* Get Label for Action History Details.
*
*
* @param name
* @return
*/
@@ -272,7 +267,7 @@ public final class HawkbitCommonUtil {
/**
* Get tool tip for Poll status.
*
*
* @param pollStatus
* @param i18N
* @return
@@ -290,7 +285,7 @@ public final class HawkbitCommonUtil {
/**
* Null check for text.
*
*
* @param orgText
* text to be formatted
* @return String formatted text
@@ -302,7 +297,7 @@ public final class HawkbitCommonUtil {
/**
* Find extra height required to increase by all the components to utilize
* the full height of browser for the responsive UI.
*
*
* @param newBrowserHeight
* as current browser height.
* @return extra height required to increase.
@@ -314,7 +309,7 @@ public final class HawkbitCommonUtil {
/**
* Find required extra height of software module.
*
*
* @param newBrowserHeight
* new browser height
* @return float heigth of software module table
@@ -354,8 +349,6 @@ public final class HawkbitCommonUtil {
}
/**
*
*
* @param newBrowserHeight
* new browser height
* @param minPopupHeight
@@ -401,7 +394,7 @@ public final class HawkbitCommonUtil {
/**
* Get target table width based on screen width.
*
*
* @param newBrowserWidth
* new browser width.
* @param minTargetTableLength
@@ -554,7 +547,7 @@ public final class HawkbitCommonUtil {
/**
* Duplicate check - Unique Key.
*
*
* @param name
* as string
* @param version
@@ -635,11 +628,9 @@ public final class HawkbitCommonUtil {
final int assignedCount = result.getAssigned();
final int alreadyAssignedCount = result.getAlreadyAssigned();
final int unassignedCount = result.getUnassigned();
if (assignedCount == 1) {
formMsg.append(i18n.get("message.target.assigned.one",
new Object[] { result.getAssignedEntity().get(0).getName(), tagName })).append("<br>");
} else if (assignedCount > 1) {
formMsg.append(i18n.get("message.target.assigned.many", new Object[] { assignedCount, tagName }))
.append("<br>");
@@ -650,11 +641,9 @@ public final class HawkbitCommonUtil {
formMsg.append(alreadyAssigned).append("<br>");
}
}
if (unassignedCount == 1) {
formMsg.append(i18n.get("message.target.unassigned.one",
new Object[] { result.getUnassignedEntity().get(0).getName(), tagName })).append("<br>");
} else if (unassignedCount > 1) {
formMsg.append(i18n.get("message.target.unassigned.many", new Object[] { unassignedCount, tagName }))
.append("<br>");
@@ -679,7 +668,6 @@ public final class HawkbitCommonUtil {
}
/**
*
* Create lazy query container for DS type.
*
* @param queryFactory

View File

@@ -1024,11 +1024,6 @@ public final class SPUIDefinitions {
*/
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.
*/

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_LAYOUT_ERROR_HIGHTLIGHT = "v-textfield-error";
/**
* STYLE to highlight wrong data combo box field.
*/
@@ -136,11 +138,11 @@ public final class SPUIStyleDefinitions {
* Artifact Details icon in Distribution View.
*/
public static final String ARTIFACT_DTLS_ICON = "swm-artifact-dtls-icon";
/**
* Distribution metadata icon style.
*/
public static final String DS_METADATA_ICON = "ds-metadata-icon";
/**
* Distribution metadata icon style.
*/
public static final String DS_METADATA_ICON = "ds-metadata-icon";
/**
* Target table style.
@@ -302,11 +304,11 @@ public final class SPUIStyleDefinitions {
* Grid style.
*/
public static final String METADATA_GRID = "metadata-grid";
/**
* Footer layout style.
*/
public static final String FOOTER_LAYOUT = "footer-layout";
public static final String FOOTER_LAYOUT = "footer-layout";
/**
* Constructor.