Skip to content

Commit

Permalink
fix NPE on color picking on dist and software types
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Hirsch <[email protected]>
  • Loading branch information
michahirsch authored and kaizimmerm committed Oct 27, 2016
1 parent b2a1661 commit 39712b9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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;
Expand Down Expand Up @@ -93,6 +94,18 @@ protected void createRequiredComponents() {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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;
Expand All @@ -38,6 +39,7 @@
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;
Expand Down Expand Up @@ -121,6 +123,18 @@ protected void buildLayout() {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,40 +250,39 @@ protected void addListeners() {
* 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) {
Expand Down

0 comments on commit 39712b9

Please sign in to comment.