Re-factored the code as per the sonar standards.
Signed-off-by: Gaurav <gaurav.sahay@in.bosch.com>
This commit is contained in:
@@ -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.table.BaseEntityEventType;
|
import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType;
|
||||||
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
|
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
|
||||||
@@ -47,7 +46,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;
|
||||||
|
|
||||||
@@ -183,9 +182,24 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Se
|
|||||||
setCompositionRoot(formLayout);
|
setCompositionRoot(formLayout);
|
||||||
|
|
||||||
window = SPUIWindowDecorator.getWindow(i18n.get("upload.caption.add.new.swmodule"), null,
|
window = SPUIWindowDecorator.getWindow(i18n.get("upload.caption.add.new.swmodule"), null,
|
||||||
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, event -> saveOrUpdate(), null, null, formLayout, i18n);
|
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, null, null, formLayout, i18n);
|
||||||
window.setCloseListener(() -> !isDuplicate());
|
window.setSaveDialogCloseListener(new SaveDialogCloseListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveOrUpdate() {
|
||||||
|
if (editSwModule) {
|
||||||
|
updateSwModule();
|
||||||
|
} else {
|
||||||
|
addNewBaseSoftware();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canWindowClose() {
|
||||||
|
return editSwModule || !isDuplicate();
|
||||||
|
}
|
||||||
|
});
|
||||||
nameTextField.setEnabled(!editSwModule);
|
nameTextField.setEnabled(!editSwModule);
|
||||||
versionTextField.setEnabled(!editSwModule);
|
versionTextField.setEnabled(!editSwModule);
|
||||||
typeComboBox.setEnabled(!editSwModule);
|
typeComboBox.setEnabled(!editSwModule);
|
||||||
@@ -265,14 +279,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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,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.components.colorpicker.ColorChangeListener;
|
import com.vaadin.ui.components.colorpicker.ColorChangeListener;
|
||||||
@@ -122,7 +121,7 @@ public class CreateUpdateSoftwareTypeLayout extends CreateUpdateTypeLayout<Softw
|
|||||||
|
|
||||||
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);
|
||||||
@@ -190,14 +189,13 @@ public class CreateUpdateSoftwareTypeLayout extends CreateUpdateTypeLayout<Softw
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void save(final ClickEvent event) {
|
protected void createEntity() {
|
||||||
if (optiongroup.getValue().equals(createTypeStr)) {
|
|
||||||
if (!isDuplicate()) {
|
|
||||||
createNewSWModuleType();
|
createNewSWModuleType();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
updateSWModuleType(findEntityByName());
|
@Override
|
||||||
}
|
protected void updateEntity(final SoftwareModuleType entity) {
|
||||||
|
updateSWModuleType(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -8,8 +8,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.ui.common;
|
package org.eclipse.hawkbit.ui.common;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -90,8 +88,6 @@ 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 -> onCloseEvent(event);
|
private final ClickListener closeClickListener = event -> onCloseEvent(event);
|
||||||
@@ -102,7 +98,7 @@ public class CommonDialogWindow extends Window {
|
|||||||
|
|
||||||
private final I18N i18n;
|
private final I18N i18n;
|
||||||
|
|
||||||
private transient CommonDialogWindowCloseListener closeListener;
|
private transient SaveDialogCloseListener closeListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@@ -123,13 +119,10 @@ 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 ClickListener cancelButtonClickListener, final AbstractLayout layout, final I18N i18n) {
|
||||||
final AbstractLayout layout, final I18N i18n) {
|
|
||||||
checkNotNull(saveButtonClickListener);
|
|
||||||
this.caption = caption;
|
this.caption = caption;
|
||||||
this.content = content;
|
this.content = content;
|
||||||
this.helpLink = helpLink;
|
this.helpLink = helpLink;
|
||||||
this.saveButtonClickListener = saveButtonClickListener;
|
|
||||||
this.cancelButtonClickListener = cancelButtonClickListener;
|
this.cancelButtonClickListener = cancelButtonClickListener;
|
||||||
this.orginalValues = new HashMap<>();
|
this.orginalValues = new HashMap<>();
|
||||||
this.allComponents = getAllComponents(layout);
|
this.allComponents = getAllComponents(layout);
|
||||||
@@ -137,7 +130,7 @@ public class CommonDialogWindow extends Window {
|
|||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCloseListener(final CommonDialogWindowCloseListener closeListener) {
|
public void setSaveDialogCloseListener(final SaveDialogCloseListener closeListener) {
|
||||||
this.closeListener = closeListener;
|
this.closeListener = closeListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,12 +140,16 @@ public class CommonDialogWindow extends Window {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (closeListener != null && !closeListener.canWindowClose()) {
|
if (closeListener == null || closeListener.canWindowClose()) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (closeListener.canWindowSaveOrUpdate()) {
|
||||||
|
closeListener.saveOrUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
super.close();
|
super.close();
|
||||||
@@ -460,7 +457,6 @@ public class CommonDialogWindow extends Window {
|
|||||||
saveButton.setSizeUndefined();
|
saveButton.setSizeUndefined();
|
||||||
saveButton.addStyleName("default-color");
|
saveButton.addStyleName("default-color");
|
||||||
addCloseListenerForSaveButton();
|
addCloseListenerForSaveButton();
|
||||||
saveButton.addClickListener(saveButtonClickListener);
|
|
||||||
saveButton.setEnabled(false);
|
saveButton.setEnabled(false);
|
||||||
buttonsLayout.addComponent(saveButton);
|
buttonsLayout.addComponent(saveButton);
|
||||||
buttonsLayout.setComponentAlignment(saveButton, Alignment.MIDDLE_RIGHT);
|
buttonsLayout.setComponentAlignment(saveButton, Alignment.MIDDLE_RIGHT);
|
||||||
@@ -542,13 +538,28 @@ public class CommonDialogWindow extends Window {
|
|||||||
* Called before the save happens.
|
* Called before the save happens.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
public interface SaveDialogCloseListener {
|
||||||
public interface CommonDialogWindowCloseListener {
|
|
||||||
|
/**
|
||||||
|
* Default true for all the windows except for DistributionAddUpdate
|
||||||
|
* window.
|
||||||
|
*
|
||||||
|
* @return true/false .
|
||||||
|
*/
|
||||||
|
default boolean canWindowSaveOrUpdate() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true/false based on the dialog window to be closed or not.
|
* @return true/false based on the dialog window to be closed or not.
|
||||||
*/
|
*/
|
||||||
boolean canWindowClose();
|
boolean canWindowClose();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves/Updates
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void saveOrUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
package org.eclipse.hawkbit.ui.decorators;
|
package org.eclipse.hawkbit.ui.decorators;
|
||||||
|
|
||||||
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.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;
|
||||||
@@ -44,15 +45,34 @@ public final class SPUIWindowDecorator {
|
|||||||
* window type
|
* window type
|
||||||
* @return Window
|
* @return Window
|
||||||
*/
|
*/
|
||||||
|
public static CommonDialogWindow getWindow(final String caption, final String id, final String type,
|
||||||
|
final Component content, final ClickListener cancelButtonClickListener, final String helpLink,
|
||||||
|
final AbstractLayout layout, final I18N i18n) {
|
||||||
|
return getWindow(caption, id, type, content, null, cancelButtonClickListener, helpLink, layout, i18n);
|
||||||
|
}
|
||||||
|
|
||||||
public static CommonDialogWindow getWindow(final String caption, final String id, final String type,
|
public static CommonDialogWindow getWindow(final String caption, final String id, final String type,
|
||||||
final Component content, final ClickListener saveButtonClickListener,
|
final Component content, final ClickListener saveButtonClickListener,
|
||||||
final ClickListener cancelButtonClickListener, final String helpLink, final AbstractLayout layout,
|
final ClickListener cancelButtonClickListener, final String helpLink, final AbstractLayout layout,
|
||||||
final I18N i18n) {
|
final I18N i18n) {
|
||||||
final CommonDialogWindow window = new CommonDialogWindow(caption, content, helpLink, saveButtonClickListener,
|
final CommonDialogWindow window = new CommonDialogWindow(caption, content, helpLink, cancelButtonClickListener,
|
||||||
cancelButtonClickListener, layout, i18n);
|
layout, i18n);
|
||||||
|
|
||||||
if (SPUIDefinitions.CUSTOM_METADATA_WINDOW.equals(type)) {
|
if (SPUIDefinitions.CUSTOM_METADATA_WINDOW.equals(type)) {
|
||||||
window.setCloseListener(() -> false);
|
window.setSaveDialogCloseListener(new SaveDialogCloseListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveOrUpdate() {
|
||||||
|
saveButtonClickListener.buttonClick(null);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canWindowClose() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
window.setDraggable(true);
|
window.setDraggable(true);
|
||||||
window.setClosable(true);
|
window.setClosable(true);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -40,7 +40,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;
|
||||||
@@ -453,7 +452,7 @@ public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout<Distri
|
|||||||
|
|
||||||
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);
|
||||||
@@ -565,14 +564,15 @@ public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout<Distri
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void save(final ClickEvent event) {
|
protected void updateEntity(final DistributionSetType entity) {
|
||||||
if (optiongroup.getValue().equals(createTypeStr)) {
|
updateDistributionSetType(entity);
|
||||||
if (!isDuplicate()) {
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void createEntity() {
|
||||||
createNewDistributionSetType();
|
createNewDistributionSetType();
|
||||||
}
|
|
||||||
} else {
|
|
||||||
updateDistributionSetType(findEntityByKey());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ 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.components.SPUIComponentProvider;
|
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
|
||||||
import org.eclipse.hawkbit.ui.decorators.SPUIWindowDecorator;
|
import org.eclipse.hawkbit.ui.decorators.SPUIWindowDecorator;
|
||||||
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
|
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
|
||||||
@@ -106,12 +107,9 @@ public abstract class AbstractCreateUpdateTagLayout<E extends NamedEntity> exten
|
|||||||
|
|
||||||
protected abstract String getWindowCaption();
|
protected abstract String getWindowCaption();
|
||||||
|
|
||||||
/**
|
protected abstract void updateEntity(E entity);
|
||||||
* Save new tag / update new tag.
|
|
||||||
*
|
protected abstract void createEntity();
|
||||||
* @param event
|
|
||||||
*/
|
|
||||||
protected abstract void save(final Button.ClickEvent event);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Discard the changes and close the popup.
|
* Discard the changes and close the popup.
|
||||||
@@ -464,8 +462,29 @@ public abstract class AbstractCreateUpdateTagLayout<E extends NamedEntity> exten
|
|||||||
public CommonDialogWindow getWindow() {
|
public CommonDialogWindow getWindow() {
|
||||||
reset();
|
reset();
|
||||||
window = SPUIWindowDecorator.getWindow(getWindowCaption(), null, SPUIDefinitions.CREATE_UPDATE_WINDOW, this,
|
window = SPUIWindowDecorator.getWindow(getWindowCaption(), null, SPUIDefinitions.CREATE_UPDATE_WINDOW, this,
|
||||||
this::save, this::discard, null, mainLayout, i18n);
|
this::discard, null, mainLayout, i18n);
|
||||||
window.setCloseListener(() -> !isDuplicate());
|
|
||||||
|
window.setSaveDialogCloseListener(new SaveDialogCloseListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveOrUpdate() {
|
||||||
|
if (optiongroup.getValue().equals(createTagStr)) {
|
||||||
|
if (!isDuplicate()) {
|
||||||
|
createEntity();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
updateEntity(findEntityByName());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canWindowClose() {
|
||||||
|
final boolean update = !optiongroup.getValue().equals(createTagStr);
|
||||||
|
return update || !isDuplicate();
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ 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.OptionGroup;
|
||||||
import com.vaadin.ui.TextArea;
|
import com.vaadin.ui.TextArea;
|
||||||
import com.vaadin.ui.TextField;
|
import com.vaadin.ui.TextField;
|
||||||
@@ -32,12 +31,10 @@ 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<E extends NamedEntity> 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";
|
||||||
@@ -52,8 +49,8 @@ public abstract class CreateUpdateTypeLayout<E extends NamedEntity> extends Abst
|
|||||||
@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 = SPUIComponentProvider.getLabel(i18n.get("label.choose.type"), null);
|
comboLabel = SPUIComponentProvider.getLabel(i18n.get("label.choose.type"), null);
|
||||||
colorLabel = SPUIComponentProvider.getLabel(i18n.get("label.choose.type.color"), null);
|
colorLabel = SPUIComponentProvider.getLabel(i18n.get("label.choose.type.color"), null);
|
||||||
colorLabel.addStyleName(SPUIDefinitions.COLOR_LABEL_STYLE);
|
colorLabel.addStyleName(SPUIDefinitions.COLOR_LABEL_STYLE);
|
||||||
@@ -133,7 +130,7 @@ public abstract class CreateUpdateTypeLayout<E extends NamedEntity> extends Abst
|
|||||||
@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();
|
||||||
@@ -202,25 +199,14 @@ public abstract class CreateUpdateTypeLayout<E extends NamedEntity> extends Abst
|
|||||||
optiongroup.setNullSelectionAllowed(false);
|
optiongroup.setNullSelectionAllowed(false);
|
||||||
|
|
||||||
if (hasCreatePermission) {
|
if (hasCreatePermission) {
|
||||||
optiongroup.addItem(createTypeStr);
|
optiongroup.addItem(createTagStr);
|
||||||
}
|
}
|
||||||
if (hasUpdatePermission) {
|
if (hasUpdatePermission) {
|
||||||
optiongroup.addItem(updateTypeStr);
|
optiongroup.addItem(updateTagStr);
|
||||||
}
|
}
|
||||||
setOptionGroupDefaultValue(hasCreatePermission, hasUpdatePermission);
|
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) {
|
||||||
@@ -274,11 +260,6 @@ public abstract class CreateUpdateTypeLayout<E extends NamedEntity> extends Abst
|
|||||||
|
|
||||||
protected abstract String getDuplicateKeyErrorMessage(E existingType);
|
protected abstract String getDuplicateKeyErrorMessage(E existingType);
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void save(final ClickEvent event) {
|
|
||||||
// is implemented in the inherited class
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void populateTagNameCombo() {
|
protected void populateTagNameCombo() {
|
||||||
// is implemented in the inherited class
|
// is implemented in the inherited class
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ 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.table.BaseEntityEventType;
|
import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType;
|
||||||
@@ -179,14 +180,6 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
|
|||||||
return tenantMetaData.getDefaultDsType();
|
return tenantMetaData.getDefaultDsType();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveDistribution() {
|
|
||||||
if (editDistribution) {
|
|
||||||
updateDistribution();
|
|
||||||
} else {
|
|
||||||
addNewDistribution();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update Distribution.
|
* Update Distribution.
|
||||||
*/
|
*/
|
||||||
@@ -223,9 +216,6 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
|
|||||||
*/
|
*/
|
||||||
private void addNewDistribution() {
|
private void addNewDistribution() {
|
||||||
editDistribution = Boolean.FALSE;
|
editDistribution = Boolean.FALSE;
|
||||||
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());
|
||||||
@@ -346,8 +336,30 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
|
|||||||
populateDistSetTypeNameCombo();
|
populateDistSetTypeNameCombo();
|
||||||
populateValuesOfDistribution(editDistId);
|
populateValuesOfDistribution(editDistId);
|
||||||
window = SPUIWindowDecorator.getWindow(i18n.get("caption.add.new.dist"), null,
|
window = SPUIWindowDecorator.getWindow(i18n.get("caption.add.new.dist"), null,
|
||||||
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, event -> saveDistribution(), null, null, formLayout, i18n);
|
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, null, null, formLayout, i18n);
|
||||||
window.setCloseListener(() -> !isDuplicate());
|
|
||||||
|
window.setSaveDialogCloseListener(new SaveDialogCloseListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveOrUpdate() {
|
||||||
|
if (editDistribution) {
|
||||||
|
updateDistribution();
|
||||||
|
} else {
|
||||||
|
addNewDistribution();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canWindowSaveOrUpdate() {
|
||||||
|
return editDistribution || !isDuplicate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canWindowClose() {
|
||||||
|
return !isDuplicate();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,18 +80,16 @@ 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() {
|
||||||
if (optiongroup.getValue().equals(createTagStr)) {
|
|
||||||
if (!isDuplicate()) {
|
|
||||||
createNewTag();
|
createNewTag();
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
|
@Override
|
||||||
|
protected void updateEntity(final DistributionSetTag entity) {
|
||||||
updateExistingTag(findEntityByName());
|
updateExistingTag(findEntityByName());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -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.table.BaseEntityEventType;
|
import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType;
|
||||||
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
|
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
|
||||||
import org.eclipse.hawkbit.ui.decorators.SPUIWindowDecorator;
|
import org.eclipse.hawkbit.ui.decorators.SPUIWindowDecorator;
|
||||||
@@ -134,14 +135,6 @@ 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() {
|
||||||
if (isDuplicate()) {
|
if (isDuplicate()) {
|
||||||
return;
|
return;
|
||||||
@@ -168,8 +161,25 @@ public class TargetAddUpdateWindowLayout extends CustomComponent {
|
|||||||
public Window getWindow() {
|
public Window getWindow() {
|
||||||
eventBus.publish(this, DragEvent.HIDE_DROP_HINT);
|
eventBus.publish(this, DragEvent.HIDE_DROP_HINT);
|
||||||
window = SPUIWindowDecorator.getWindow(i18n.get("caption.add.new.target"), null,
|
window = SPUIWindowDecorator.getWindow(i18n.get("caption.add.new.target"), null,
|
||||||
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, event -> saveTargetListner(), null, null, formLayout, i18n);
|
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, null, null, formLayout, i18n);
|
||||||
window.setCloseListener(() -> !isDuplicate());
|
window.setSaveDialogCloseListener(new SaveDialogCloseListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveOrUpdate() {
|
||||||
|
if (editTarget) {
|
||||||
|
updateTarget();
|
||||||
|
} else {
|
||||||
|
addNewTarget();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canWindowClose() {
|
||||||
|
return editTarget || !isDuplicate();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -101,15 +100,14 @@ public class CreateUpdateTargetTagLayoutWindow extends AbstractCreateUpdateTagLa
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(final ClickEvent event) {
|
protected void updateEntity(final TargetTag entity) {
|
||||||
if (optiongroup.getValue().equals(createTagStr)) {
|
updateExistingTag(entity);
|
||||||
if (!isDuplicate()) {
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void createEntity() {
|
||||||
createNewTag();
|
createNewTag();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
updateExistingTag(findEntityByName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected TargetTag findEntityByName() {
|
protected TargetTag findEntityByName() {
|
||||||
|
|||||||
@@ -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.components.SPUIComponentProvider;
|
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
|
||||||
import org.eclipse.hawkbit.ui.decorators.SPUIWindowDecorator;
|
import org.eclipse.hawkbit.ui.decorators.SPUIWindowDecorator;
|
||||||
@@ -165,9 +166,30 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
|
|||||||
|
|
||||||
public CommonDialogWindow getWindow() {
|
public CommonDialogWindow getWindow() {
|
||||||
resetComponents();
|
resetComponents();
|
||||||
return SPUIWindowDecorator.getWindow(i18n.get("caption.configure.rollout"), null,
|
final CommonDialogWindow window = SPUIWindowDecorator.getWindow(i18n.get("caption.configure.rollout"), null,
|
||||||
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, event -> onRolloutSave(), null,
|
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, null,
|
||||||
uiProperties.getLinks().getDocumentation().getRolloutView(), this, i18n);
|
uiProperties.getLinks().getDocumentation().getRolloutView(), this, i18n);
|
||||||
|
window.setSaveDialogCloseListener(new SaveDialogCloseListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveOrUpdate() {
|
||||||
|
if (editRolloutEnabled) {
|
||||||
|
editRollout();
|
||||||
|
} else {
|
||||||
|
createRollout();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canWindowClose() {
|
||||||
|
if (editRolloutEnabled) {
|
||||||
|
return duplicateCheckForEdit();
|
||||||
|
}
|
||||||
|
return duplicateCheck();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -393,14 +415,6 @@ 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 (duplicateCheckForEdit() && rolloutForEdit != null) {
|
||||||
rolloutForEdit.setName(rolloutName.getValue());
|
rolloutForEdit.setName(rolloutName.getValue());
|
||||||
|
|||||||
Reference in New Issue
Block a user