fix NPE on color picking on dist and software types
Signed-off-by: Michael Hirsch <michael.hirsch@bosch-si.com>
This commit is contained in:
committed by
Kai Zimmermann
parent
b2a16613c5
commit
39712b90a3
@@ -16,6 +16,7 @@ import org.eclipse.hawkbit.repository.SoftwareManagement;
|
|||||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||||
import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleTypeEvent;
|
import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleTypeEvent;
|
||||||
import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleTypeEvent.SoftwareModuleTypeEnum;
|
import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleTypeEvent.SoftwareModuleTypeEnum;
|
||||||
|
import org.eclipse.hawkbit.ui.colorpicker.ColorPickerConstants;
|
||||||
import org.eclipse.hawkbit.ui.colorpicker.ColorPickerHelper;
|
import org.eclipse.hawkbit.ui.colorpicker.ColorPickerHelper;
|
||||||
import org.eclipse.hawkbit.ui.common.SoftwareModuleTypeBeanQuery;
|
import org.eclipse.hawkbit.ui.common.SoftwareModuleTypeBeanQuery;
|
||||||
import org.eclipse.hawkbit.ui.common.builder.LabelBuilder;
|
import org.eclipse.hawkbit.ui.common.builder.LabelBuilder;
|
||||||
@@ -93,6 +94,18 @@ public class CreateUpdateSoftwareTypeLayout extends CreateUpdateTypeLayout<Softw
|
|||||||
singleMultiOptionGroup();
|
singleMultiOptionGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Color getColorForColorPicker() {
|
||||||
|
|
||||||
|
final SoftwareModuleType typeSelected = swTypeManagementService
|
||||||
|
.findSoftwareModuleTypeByName(tagNameComboBox.getValue().toString());
|
||||||
|
if (null != typeSelected) {
|
||||||
|
return typeSelected.getColour() != null ? ColorPickerHelper.rgbToColorConverter(typeSelected.getColour())
|
||||||
|
: ColorPickerHelper.rgbToColorConverter(ColorPickerConstants.DEFAULT_COLOR);
|
||||||
|
}
|
||||||
|
return ColorPickerHelper.rgbToColorConverter(ColorPickerConstants.DEFAULT_COLOR);
|
||||||
|
}
|
||||||
|
|
||||||
private TextField createTextField(final String in18Key, final String styleName, final String id) {
|
private TextField createTextField(final String in18Key, final String styleName, final String id) {
|
||||||
return new TextFieldBuilder().caption(i18n.get(in18Key)).styleName(ValoTheme.TEXTFIELD_TINY + " " + styleName)
|
return new TextFieldBuilder().caption(i18n.get(in18Key)).styleName(ValoTheme.TEXTFIELD_TINY + " " + styleName)
|
||||||
.required(true).prompt(i18n.get(in18Key)).immediate(true).id(id).buildTextComponent();
|
.required(true).prompt(i18n.get(in18Key)).immediate(true).id(id).buildTextComponent();
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import org.eclipse.hawkbit.repository.EntityFactory;
|
|||||||
import org.eclipse.hawkbit.repository.SoftwareManagement;
|
import org.eclipse.hawkbit.repository.SoftwareManagement;
|
||||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
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.colorpicker.ColorPickerHelper;
|
||||||
import org.eclipse.hawkbit.ui.common.DistributionSetTypeBeanQuery;
|
import org.eclipse.hawkbit.ui.common.DistributionSetTypeBeanQuery;
|
||||||
import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder;
|
import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder;
|
||||||
@@ -38,6 +39,7 @@ import com.vaadin.data.Item;
|
|||||||
import com.vaadin.data.Property.ValueChangeEvent;
|
import com.vaadin.data.Property.ValueChangeEvent;
|
||||||
import com.vaadin.data.util.IndexedContainer;
|
import com.vaadin.data.util.IndexedContainer;
|
||||||
import com.vaadin.server.FontAwesome;
|
import com.vaadin.server.FontAwesome;
|
||||||
|
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.AbstractSelect.ItemDescriptionGenerator;
|
import com.vaadin.ui.AbstractSelect.ItemDescriptionGenerator;
|
||||||
@@ -121,6 +123,18 @@ public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout<Distri
|
|||||||
mainLayout.addComponent(twinTableLayout, 2, 0);
|
mainLayout.addComponent(twinTableLayout, 2, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Color getColorForColorPicker() {
|
||||||
|
final DistributionSetType existedDistType = distributionSetManagement
|
||||||
|
.findDistributionSetTypeByName(tagNameComboBox.getValue().toString());
|
||||||
|
if (null != existedDistType) {
|
||||||
|
return existedDistType.getColour() != null
|
||||||
|
? ColorPickerHelper.rgbToColorConverter(existedDistType.getColour())
|
||||||
|
: ColorPickerHelper.rgbToColorConverter(ColorPickerConstants.DEFAULT_COLOR);
|
||||||
|
}
|
||||||
|
return ColorPickerHelper.rgbToColorConverter(ColorPickerConstants.DEFAULT_COLOR);
|
||||||
|
}
|
||||||
|
|
||||||
private HorizontalLayout createTwinColumnLayout() {
|
private HorizontalLayout createTwinColumnLayout() {
|
||||||
|
|
||||||
final HorizontalLayout twinColumnLayout = new HorizontalLayout();
|
final HorizontalLayout twinColumnLayout = new HorizontalLayout();
|
||||||
|
|||||||
@@ -250,40 +250,39 @@ public abstract class AbstractCreateUpdateTagLayout<E extends NamedEntity> exten
|
|||||||
* Open color picker on click of preview button. Auto select the color based
|
* Open color picker on click of preview button. Auto select the color based
|
||||||
* on target tag if already selected.
|
* on target tag if already selected.
|
||||||
*/
|
*/
|
||||||
protected void previewButtonClicked() {
|
private void previewButtonClicked() {
|
||||||
if (!tagPreviewBtnClicked) {
|
if (!tagPreviewBtnClicked) {
|
||||||
setColor();
|
final String selectedOption = (String) optiongroup.getValue();
|
||||||
|
if (selectedOption == null || !selectedOption.equalsIgnoreCase(updateTagStr)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tagNameComboBox.getValue() == null) {
|
||||||
|
colorPickerLayout
|
||||||
|
.setSelectedColor(ColorPickerHelper.rgbToColorConverter(ColorPickerConstants.DEFAULT_COLOR));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
colorPickerLayout.setSelectedColor(getColorForColorPicker());
|
||||||
}
|
}
|
||||||
|
|
||||||
tagPreviewBtnClicked = !tagPreviewBtnClicked;
|
tagPreviewBtnClicked = !tagPreviewBtnClicked;
|
||||||
colorPickerLayout.setVisible(tagPreviewBtnClicked);
|
colorPickerLayout.setVisible(tagPreviewBtnClicked);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setColor() {
|
/**
|
||||||
final String selectedOption = (String) optiongroup.getValue();
|
* @return the color which should be selected in the color-picker component.
|
||||||
if (selectedOption == null || !selectedOption.equalsIgnoreCase(updateTagStr)) {
|
*/
|
||||||
return;
|
protected Color getColorForColorPicker() {
|
||||||
}
|
|
||||||
|
|
||||||
if (tagNameComboBox.getValue() == null) {
|
|
||||||
colorPickerLayout
|
|
||||||
.setSelectedColor(ColorPickerHelper.rgbToColorConverter(ColorPickerConstants.DEFAULT_COLOR));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final TargetTag targetTagSelected = tagManagement.findTargetTag(tagNameComboBox.getValue().toString());
|
final TargetTag targetTagSelected = tagManagement.findTargetTag(tagNameComboBox.getValue().toString());
|
||||||
|
|
||||||
if (targetTagSelected == null) {
|
if (targetTagSelected == null) {
|
||||||
final DistributionSetTag distTag = tagManagement
|
final DistributionSetTag distTag = tagManagement
|
||||||
.findDistributionSetTag(tagNameComboBox.getValue().toString());
|
.findDistributionSetTag(tagNameComboBox.getValue().toString());
|
||||||
colorPickerLayout.setSelectedColor(
|
return distTag.getColour() != null ? ColorPickerHelper.rgbToColorConverter(distTag.getColour())
|
||||||
distTag.getColour() != null ? ColorPickerHelper.rgbToColorConverter(distTag.getColour())
|
: ColorPickerHelper.rgbToColorConverter(ColorPickerConstants.DEFAULT_COLOR);
|
||||||
: ColorPickerHelper.rgbToColorConverter(ColorPickerConstants.DEFAULT_COLOR));
|
|
||||||
} else {
|
|
||||||
colorPickerLayout.setSelectedColor(targetTagSelected.getColour() != null
|
|
||||||
? ColorPickerHelper.rgbToColorConverter(targetTagSelected.getColour())
|
|
||||||
: ColorPickerHelper.rgbToColorConverter(ColorPickerConstants.DEFAULT_COLOR));
|
|
||||||
}
|
}
|
||||||
|
return targetTagSelected.getColour() != null
|
||||||
|
? ColorPickerHelper.rgbToColorConverter(targetTagSelected.getColour())
|
||||||
|
: ColorPickerHelper.rgbToColorConverter(ColorPickerConstants.DEFAULT_COLOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tagNameChosen(final ValueChangeEvent event) {
|
private void tagNameChosen(final ValueChangeEvent event) {
|
||||||
|
|||||||
Reference in New Issue
Block a user