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:
Michael Hirsch
2016-10-21 13:04:30 +02:00
committed by Kai Zimmermann
parent b2a16613c5
commit 39712b90a3
3 changed files with 48 additions and 22 deletions

View File

@@ -16,6 +16,7 @@ import org.eclipse.hawkbit.repository.SoftwareManagement;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleTypeEvent;
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.common.SoftwareModuleTypeBeanQuery;
import org.eclipse.hawkbit.ui.common.builder.LabelBuilder;
@@ -93,6 +94,18 @@ public class CreateUpdateSoftwareTypeLayout extends CreateUpdateTypeLayout<Softw
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) {
return new TextFieldBuilder().caption(i18n.get(in18Key)).styleName(ValoTheme.TEXTFIELD_TINY + " " + styleName)
.required(true).prompt(i18n.get(in18Key)).immediate(true).id(id).buildTextComponent();

View File

@@ -16,6 +16,7 @@ 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.common.builder.TextAreaBuilder;
@@ -38,6 +39,7 @@ import com.vaadin.data.Item;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.server.FontAwesome;
import com.vaadin.shared.ui.colorpicker.Color;
import com.vaadin.spring.annotation.SpringComponent;
import com.vaadin.spring.annotation.ViewScope;
import com.vaadin.ui.AbstractSelect.ItemDescriptionGenerator;
@@ -121,6 +123,18 @@ public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout<Distri
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() {
final HorizontalLayout twinColumnLayout = new HorizontalLayout();

View File

@@ -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
* on target tag if already selected.
*/
protected void previewButtonClicked() {
private void previewButtonClicked() {
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;
colorPickerLayout.setVisible(tagPreviewBtnClicked);
}
private void 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;
}
/**
* @return the color which should be selected in the color-picker component.
*/
protected Color getColorForColorPicker() {
final TargetTag targetTagSelected = tagManagement.findTargetTag(tagNameComboBox.getValue().toString());
if (targetTagSelected == null) {
final DistributionSetTag distTag = tagManagement
.findDistributionSetTag(tagNameComboBox.getValue().toString());
colorPickerLayout.setSelectedColor(
distTag.getColour() != null ? ColorPickerHelper.rgbToColorConverter(distTag.getColour())
: ColorPickerHelper.rgbToColorConverter(ColorPickerConstants.DEFAULT_COLOR));
} else {
colorPickerLayout.setSelectedColor(targetTagSelected.getColour() != null
? ColorPickerHelper.rgbToColorConverter(targetTagSelected.getColour())
: ColorPickerHelper.rgbToColorConverter(ColorPickerConstants.DEFAULT_COLOR));
return distTag.getColour() != null ? ColorPickerHelper.rgbToColorConverter(distTag.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) {