Fix window open issues and set values when a entity is selected
Signed-off-by: SirWayne <dennis.melzer@bosch-si.com>
This commit is contained in:
@@ -10,6 +10,8 @@ package org.eclipse.hawkbit.ui.artifacts.smtable;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.SoftwareManagement;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
@@ -39,7 +41,6 @@ import com.vaadin.ui.Label;
|
||||
import com.vaadin.ui.TextArea;
|
||||
import com.vaadin.ui.TextField;
|
||||
import com.vaadin.ui.UI;
|
||||
import com.vaadin.ui.Window;
|
||||
import com.vaadin.ui.themes.ValoTheme;
|
||||
|
||||
/**
|
||||
@@ -84,6 +85,14 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Se
|
||||
|
||||
private FormLayout formLayout;
|
||||
|
||||
/**
|
||||
* Initialize Distribution Add and Edit Window.
|
||||
*/
|
||||
@PostConstruct
|
||||
void init() {
|
||||
createRequiredComponents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create window for new software module.
|
||||
*
|
||||
@@ -91,11 +100,7 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Se
|
||||
* module.
|
||||
*/
|
||||
public CommonDialogWindow createAddSoftwareModuleWindow() {
|
||||
|
||||
editSwModule = Boolean.FALSE;
|
||||
createRequiredComponents();
|
||||
createWindow();
|
||||
return window;
|
||||
return createUpdateSoftwareModuleWindow(null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,15 +111,11 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Se
|
||||
* @return reference of {@link com.vaadin.ui.Window} to update software
|
||||
* module.
|
||||
*/
|
||||
public Window createUpdateSoftwareModuleWindow(final Long baseSwModuleId) {
|
||||
|
||||
editSwModule = Boolean.TRUE;
|
||||
public CommonDialogWindow createUpdateSoftwareModuleWindow(final Long baseSwModuleId) {
|
||||
this.baseSwModuleId = baseSwModuleId;
|
||||
createRequiredComponents();
|
||||
resetComponents();
|
||||
populateValuesOfSwModule();
|
||||
createWindow();
|
||||
nameTextField.setEnabled(false);
|
||||
versionTextField.setEnabled(false);
|
||||
typeComboBox.setEnabled(false);
|
||||
return window;
|
||||
}
|
||||
|
||||
@@ -162,12 +163,10 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Se
|
||||
versionTextField.clear();
|
||||
descTextArea.clear();
|
||||
typeComboBox.clear();
|
||||
editSwModule = Boolean.FALSE;
|
||||
}
|
||||
|
||||
private void createWindow() {
|
||||
|
||||
resetComponents();
|
||||
|
||||
final Label madatoryStarLabel = new Label("*");
|
||||
madatoryStarLabel.setStyleName("v-caption v-required-field-indicator");
|
||||
madatoryStarLabel.setWidth(null);
|
||||
@@ -184,11 +183,15 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Se
|
||||
|
||||
setCompositionRoot(formLayout);
|
||||
|
||||
populateValuesOfSwModule();
|
||||
window = SPUIWindowDecorator.getWindow(i18n.get("upload.caption.add.new.swmodule"), null,
|
||||
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, event -> saveOrUpdate(), event -> closeThisWindow(), null,
|
||||
formLayout, i18n);
|
||||
window.getButtonsLayout().removeStyleName("actionButtonsMargin");
|
||||
|
||||
nameTextField.setEnabled(!editSwModule);
|
||||
versionTextField.setEnabled(!editSwModule);
|
||||
typeComboBox.setEnabled(!editSwModule);
|
||||
|
||||
typeComboBox.focus();
|
||||
}
|
||||
|
||||
@@ -243,6 +246,9 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Se
|
||||
* fill the data of a softwareModule in the content of the window
|
||||
*/
|
||||
private void populateValuesOfSwModule() {
|
||||
if (baseSwModuleId == null) {
|
||||
return;
|
||||
}
|
||||
final SoftwareModule swModle = softwareManagement.findSoftwareModuleById(baseSwModuleId);
|
||||
nameTextField.setValue(swModle.getName());
|
||||
versionTextField.setValue(swModle.getVersion());
|
||||
|
||||
@@ -31,6 +31,8 @@ import org.eclipse.hawkbit.ui.utils.SPUIComponentIdProvider;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.vaadin.data.Container.ItemSetChangeEvent;
|
||||
import com.vaadin.data.Container.ItemSetChangeListener;
|
||||
import com.vaadin.data.Property.ValueChangeEvent;
|
||||
import com.vaadin.data.Property.ValueChangeListener;
|
||||
import com.vaadin.event.FieldEvents.TextChangeEvent;
|
||||
@@ -50,6 +52,7 @@ import com.vaadin.ui.GridLayout;
|
||||
import com.vaadin.ui.HorizontalLayout;
|
||||
import com.vaadin.ui.Label;
|
||||
import com.vaadin.ui.Link;
|
||||
import com.vaadin.ui.Table;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
import com.vaadin.ui.Window;
|
||||
import com.vaadin.ui.themes.ValoTheme;
|
||||
@@ -132,6 +135,18 @@ public class CommonDialogWindow extends Window implements Serializable {
|
||||
for (final AbstractField<?> field : allComponents) {
|
||||
removeTextListener(field);
|
||||
removeValueChangeListener(field);
|
||||
removeItemSetChangeistener(field);
|
||||
}
|
||||
}
|
||||
|
||||
private void removeItemSetChangeistener(final AbstractField<?> field) {
|
||||
if (!(field instanceof Table)) {
|
||||
return;
|
||||
}
|
||||
for (final Object listener : field.getListeners(ItemSetChangeEvent.class)) {
|
||||
if (listener instanceof ChangeListener) {
|
||||
((Table) field).removeItemSetChangeListener((ChangeListener) listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,8 +201,14 @@ public class CommonDialogWindow extends Window implements Serializable {
|
||||
|
||||
public final void setOrginaleValues() {
|
||||
for (final AbstractField<?> field : allComponents) {
|
||||
orginalValues.put(field, field.getValue());
|
||||
Object value = field.getValue();
|
||||
|
||||
if (field instanceof Table) {
|
||||
value = ((Table) field).getContainerDataSource().getItemIds();
|
||||
}
|
||||
orginalValues.put(field, value);
|
||||
}
|
||||
|
||||
saveButton.setEnabled(isSaveButtonEnabledAfterValueChange(null, null));
|
||||
}
|
||||
|
||||
@@ -197,6 +218,10 @@ public class CommonDialogWindow extends Window implements Serializable {
|
||||
if (field instanceof TextChangeNotifier) {
|
||||
((TextChangeNotifier) field).addTextChangeListener(new ChangeListener(field));
|
||||
}
|
||||
|
||||
if (field instanceof Table) {
|
||||
((Table) field).addItemSetChangeListener(new ChangeListener(field));
|
||||
}
|
||||
}
|
||||
|
||||
saveButton.addClickListener(event -> close());
|
||||
@@ -360,7 +385,7 @@ public class CommonDialogWindow extends Window implements Serializable {
|
||||
return this.buttonsLayout;
|
||||
}
|
||||
|
||||
private class ChangeListener implements ValueChangeListener, TextChangeListener {
|
||||
private class ChangeListener implements ValueChangeListener, TextChangeListener, ItemSetChangeListener {
|
||||
|
||||
private final Field<?> field;
|
||||
|
||||
@@ -380,6 +405,11 @@ public class CommonDialogWindow extends Window implements Serializable {
|
||||
saveButton.setEnabled(isSaveButtonEnabledAfterValueChange(field, field.getValue()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void containerItemSetChange(final ItemSetChangeEvent event) {
|
||||
saveButton.setEnabled(isSaveButtonEnabledAfterValueChange(field, event.getContainer().getItemIds()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ package org.eclipse.hawkbit.ui.distributions.disttype;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
@@ -18,7 +17,6 @@ import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.SoftwareManagement;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
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.DistributionSetTypeBeanQuery;
|
||||
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
|
||||
@@ -26,7 +24,6 @@ import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder;
|
||||
import org.eclipse.hawkbit.ui.distributions.event.DistributionSetTypeEvent;
|
||||
import org.eclipse.hawkbit.ui.distributions.event.DistributionSetTypeEvent.DistributionSetTypeEnum;
|
||||
import org.eclipse.hawkbit.ui.layouts.CreateUpdateTypeLayout;
|
||||
import org.eclipse.hawkbit.ui.utils.CommonDialogWindowHelper;
|
||||
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
|
||||
@@ -647,13 +644,6 @@ public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout
|
||||
return i18n.get("caption.add.type");
|
||||
}
|
||||
|
||||
protected Map<String, Boolean> getMandatoryFields() {
|
||||
final Map<String, Boolean> requiredFields = CommonDialogWindowHelper.getMandatoryFields(getFormLayout());
|
||||
// Selected SoftwareModulesType
|
||||
requiredFields.put(selectedTable.getId(), Boolean.FALSE);
|
||||
return requiredFields;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createOptionGroup(final boolean hasCreatePermission, final boolean hasUpdatePermission) {
|
||||
|
||||
@@ -661,5 +651,4 @@ public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout
|
||||
optiongroup.setId(SPUIDefinitions.CREATE_OPTION_GROUP_DISTRIBUTION_SET_TYPE_ID);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -259,8 +259,7 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet
|
||||
|
||||
@Override
|
||||
protected void onEdit(final ClickEvent event) {
|
||||
distributionAddUpdateWindowLayout.populateValuesOfDistribution(getSelectedBaseEntityId());
|
||||
final Window newDistWindow = distributionAddUpdateWindowLayout.getWindow();
|
||||
final Window newDistWindow = distributionAddUpdateWindowLayout.getWindow(getSelectedBaseEntityId());
|
||||
newDistWindow.setCaption(getI18n().get("caption.update.dist"));
|
||||
UI.getCurrent().addWindow(newDistWindow);
|
||||
newDistWindow.setVisible(Boolean.TRUE);
|
||||
|
||||
@@ -152,7 +152,7 @@ public class DistributionSetTableHeader extends AbstractTableHeader {
|
||||
|
||||
@Override
|
||||
protected void addNewItem(final ClickEvent event) {
|
||||
final Window newDistWindow = addUpdateWindowLayout.getWindow();
|
||||
final Window newDistWindow = addUpdateWindowLayout.getWindow(null);
|
||||
newDistWindow.setCaption(i18n.get("caption.add.new.dist"));
|
||||
UI.getCurrent().addWindow(newDistWindow);
|
||||
newDistWindow.setVisible(Boolean.TRUE);
|
||||
|
||||
@@ -331,6 +331,7 @@ public abstract class AbstractCreateUpdateTagLayout extends CustomComponent
|
||||
comboLayout.removeComponent(tagNameComboBox);
|
||||
|
||||
// Default green color
|
||||
colorPickerLayout.setVisible(false);
|
||||
colorPickerLayout.setSelectedColor(colorPickerLayout.getDefaultColor());
|
||||
colorPickerLayout.getSelPreview().setColor(colorPickerLayout.getSelectedColor());
|
||||
tagPreviewBtnClicked = false;
|
||||
@@ -424,9 +425,6 @@ public abstract class AbstractCreateUpdateTagLayout extends CustomComponent
|
||||
colorPickerLayout.getColorSelect().setColor(colorPickerLayout.getSelPreview().getColor());
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// window.checkColorChange(colorPickerLayout.getId(),
|
||||
// colorPickerLayout.getSelectedColor(), originalSelectedColor);
|
||||
}
|
||||
|
||||
protected void closeWindow() {
|
||||
|
||||
@@ -90,11 +90,6 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
|
||||
private boolean editDistribution = Boolean.FALSE;
|
||||
private Long editDistId;
|
||||
private CommonDialogWindow window;
|
||||
private String originalDistName;
|
||||
private String originalDistVersion;
|
||||
private String originalDistDescription;
|
||||
private Boolean originalReqMigStep;
|
||||
private String originalDistSetType;
|
||||
|
||||
private FormLayout formLayout;
|
||||
|
||||
@@ -108,11 +103,6 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
|
||||
}
|
||||
|
||||
private void buildLayout() {
|
||||
|
||||
/*
|
||||
* The main layout of the window contains mandatory info, textboxes
|
||||
* (controller Id, name & description) and action buttons layout
|
||||
*/
|
||||
addStyleName("lay-color");
|
||||
setSizeUndefined();
|
||||
|
||||
@@ -354,50 +344,38 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
|
||||
descTextArea.clear();
|
||||
reqMigStepCheckbox.clear();
|
||||
|
||||
originalDistDescription = null;
|
||||
originalDistName = null;
|
||||
originalDistSetType = null;
|
||||
originalDistVersion = null;
|
||||
originalReqMigStep = Boolean.FALSE;
|
||||
|
||||
}
|
||||
|
||||
private void populateRequiredComponents() {
|
||||
private void populateValuesOfDistribution(final Long editDistId) {
|
||||
this.editDistId = editDistId;
|
||||
if (editDistId == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final DistributionSet distSet = distributionSetManagement.findDistributionSetByIdWithDetails(editDistId);
|
||||
if (distSet == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
editDistribution = Boolean.TRUE;
|
||||
distNameTextField.setValue(distSet.getName());
|
||||
distVersionTextField.setValue(distSet.getVersion());
|
||||
if (distSet.getType().isDeleted()) {
|
||||
distsetTypeNameComboBox.addItem(distSet.getType().getName());
|
||||
}
|
||||
distsetTypeNameComboBox.setValue(distSet.getType().getName());
|
||||
reqMigStepCheckbox.setValue(distSet.isRequiredMigrationStep());
|
||||
if (distSet.getDescription() != null) {
|
||||
descTextArea.setValue(distSet.getDescription());
|
||||
}
|
||||
populateDistSetTypeNameCombo();
|
||||
}
|
||||
|
||||
/**
|
||||
* populate data.
|
||||
*
|
||||
* @param editDistId
|
||||
*/
|
||||
public void populateValuesOfDistribution(final Long editDistId) {
|
||||
this.editDistId = editDistId;
|
||||
editDistribution = Boolean.TRUE;
|
||||
final DistributionSet distSet = distributionSetManagement.findDistributionSetByIdWithDetails(editDistId);
|
||||
if (distSet != null) {
|
||||
distNameTextField.setValue(distSet.getName());
|
||||
distVersionTextField.setValue(distSet.getVersion());
|
||||
if (distSet.getType().isDeleted()) {
|
||||
distsetTypeNameComboBox.addItem(distSet.getType().getName());
|
||||
}
|
||||
distsetTypeNameComboBox.setValue(distSet.getType().getName());
|
||||
reqMigStepCheckbox.setValue(distSet.isRequiredMigrationStep());
|
||||
if (distSet.getDescription() != null) {
|
||||
descTextArea.setValue(distSet.getDescription());
|
||||
}
|
||||
originalDistName = distSet.getName();
|
||||
originalDistVersion = distSet.getVersion();
|
||||
originalDistDescription = distSet.getDescription();
|
||||
originalReqMigStep = distSet.isRequiredMigrationStep();
|
||||
originalDistSetType = distSet.getType().getName();
|
||||
}
|
||||
}
|
||||
|
||||
public CommonDialogWindow getWindow() {
|
||||
public CommonDialogWindow getWindow(final Long editDistId) {
|
||||
eventBus.publish(this, DragEvent.HIDE_DROP_HINT);
|
||||
populateRequiredComponents();
|
||||
resetComponents();
|
||||
|
||||
populateValuesOfDistribution(editDistId);
|
||||
window = SPUIWindowDecorator.getWindow(i18n.get("caption.add.new.dist"), null,
|
||||
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, event -> saveDistribution(), event -> discardDistribution(),
|
||||
null, formLayout, i18n);
|
||||
|
||||
@@ -77,8 +77,7 @@ public class DistributionDetails extends AbstractNamedVersionedEntityTableDetail
|
||||
|
||||
@Override
|
||||
protected void onEdit(final ClickEvent event) {
|
||||
distributionAddUpdateWindowLayout.populateValuesOfDistribution(getSelectedBaseEntityId());
|
||||
final Window newDistWindow = distributionAddUpdateWindowLayout.getWindow();
|
||||
final Window newDistWindow = distributionAddUpdateWindowLayout.getWindow(getSelectedBaseEntityId());
|
||||
newDistWindow.setCaption(getI18n().get("caption.update.dist"));
|
||||
UI.getCurrent().addWindow(newDistWindow);
|
||||
newDistWindow.setVisible(Boolean.TRUE);
|
||||
|
||||
@@ -154,7 +154,7 @@ public class DistributionTableHeader extends AbstractTableHeader {
|
||||
|
||||
@Override
|
||||
protected void addNewItem(final ClickEvent event) {
|
||||
final Window newDistWindow = distributionAddUpdateWindowLayout.getWindow();
|
||||
final Window newDistWindow = distributionAddUpdateWindowLayout.getWindow(null);
|
||||
newDistWindow.setCaption(i18n.get("caption.add.new.dist"));
|
||||
UI.getCurrent().addWindow(newDistWindow);
|
||||
newDistWindow.setVisible(Boolean.TRUE);
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
package org.eclipse.hawkbit.ui.utils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import com.vaadin.ui.AbstractField;
|
||||
import com.vaadin.ui.Component;
|
||||
import com.vaadin.ui.FormLayout;
|
||||
|
||||
public class CommonDialogWindowHelper {
|
||||
|
||||
/**
|
||||
* Run through a FormLayout and collect all required Component's IDs in a
|
||||
* Map
|
||||
*
|
||||
* @param formLayout
|
||||
* Form to be analysed
|
||||
* @return Map with all required component's IDs
|
||||
*/
|
||||
public static Map<String, Boolean> getMandatoryFields(final FormLayout formLayout) {
|
||||
final Map<String, Boolean> requiredFields = new HashMap<>();
|
||||
final Iterator<Component> iterate = formLayout.iterator();
|
||||
while (iterate.hasNext()) {
|
||||
final Component c = iterate.next();
|
||||
if (c instanceof AbstractField && ((AbstractField) c).isRequired()) {
|
||||
requiredFields.put(c.getId(), Boolean.FALSE);
|
||||
}
|
||||
}
|
||||
return requiredFields;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user