Merge branch 'master' into feature_ui_metadata

Conflicts:
	hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/CommonDialogWindow.java
	hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/popup-common.scss
This commit is contained in:
gah6kor
2016-07-18 18:10:09 +02:00
6 changed files with 462 additions and 467 deletions

View File

@@ -21,7 +21,7 @@ import org.eclipse.hawkbit.repository.model.MetaData;
import org.eclipse.hawkbit.repository.model.NamedVersionedEntity; import org.eclipse.hawkbit.repository.model.NamedVersionedEntity;
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlButtonRenderer; import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlButtonRenderer;
import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleBorderWithIcon; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleNoBorderWithIcon;
import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder;
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;
@@ -510,7 +510,7 @@ public abstract class AbstractMetadataPopupLayout<E extends NamedVersionedEntity
private Button createDiscardButton() { private Button createDiscardButton() {
final Button discardButton = SPUIComponentProvider.getButton(SPUIComponentIdProvider.CANCEL_BUTTON, final Button discardButton = SPUIComponentProvider.getButton(SPUIComponentIdProvider.CANCEL_BUTTON,
i18n.get("button.discard"), "", "", true, FontAwesome.UNDO, SPUIButtonStyleBorderWithIcon.class); i18n.get("button.discard"), "", "", true, FontAwesome.UNDO, SPUIButtonStyleNoBorderWithIcon.class);
discardButton.setSizeUndefined(); discardButton.setSizeUndefined();
discardButton.addStyleName("default-color"); discardButton.addStyleName("default-color");
discardButton.addClickListener(event -> onDiscard()); discardButton.addClickListener(event -> onDiscard());

View File

@@ -25,7 +25,7 @@ import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.eclipse.hawkbit.ui.artifacts.smtable.SoftwareModuleAddUpdateWindow; import org.eclipse.hawkbit.ui.artifacts.smtable.SoftwareModuleAddUpdateWindow;
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleBorderWithIcon; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleNoBorderWithIcon;
import org.eclipse.hawkbit.ui.layouts.AbstractCreateUpdateTagLayout; import org.eclipse.hawkbit.ui.layouts.AbstractCreateUpdateTagLayout;
import org.eclipse.hawkbit.ui.management.targettable.TargetAddUpdateWindowLayout; import org.eclipse.hawkbit.ui.management.targettable.TargetAddUpdateWindowLayout;
import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.I18N;
@@ -72,455 +72,449 @@ import com.vaadin.ui.themes.ValoTheme;
*/ */
public class CommonDialogWindow extends Window implements Serializable { public class CommonDialogWindow extends Window implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private final VerticalLayout mainLayout = new VerticalLayout(); private final VerticalLayout mainLayout = new VerticalLayout();
private final String caption; private final String caption;
private final Component content; private final Component content;
private final String helpLink; private final String helpLink;
private Button saveButton; private Button saveButton;
private Button cancelButton; private Button cancelButton;
private HorizontalLayout buttonsLayout; private HorizontalLayout buttonsLayout;
protected ValueChangeListener buttonEnableListener; protected ValueChangeListener buttonEnableListener;
private final ClickListener saveButtonClickListener; private final ClickListener saveButtonClickListener;
private final ClickListener cancelButtonClickListener; private final ClickListener cancelButtonClickListener;
private final ClickListener close = event -> close(); private final ClickListener close = event -> close();
private final transient Map<Component, Object> orginalValues; private final transient Map<Component, Object> orginalValues;
private final List<AbstractField<?>> allComponents; private final List<AbstractField<?>> allComponents;
private final I18N i18n; private final I18N i18n;
/** /**
* Constructor. * Constructor.
* *
* @param caption * @param caption
* the caption * the caption
* @param content * @param content
* the content * the content
* @param helpLink * @param helpLink
* the helpLinks * the helpLinks
* @param saveButtonClickListener * @param saveButtonClickListener
* the saveButtonClickListener * the saveButtonClickListener
* @param cancelButtonClickListener * @param cancelButtonClickListener
* the cancelButtonClickListener * the cancelButtonClickListener
*/ */
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 saveButtonClickListener, final ClickListener cancelButtonClickListener,
final AbstractLayout layout, final I18N i18n) { final AbstractLayout layout, final I18N i18n) {
checkNotNull(saveButtonClickListener); checkNotNull(saveButtonClickListener);
this.caption = caption; this.caption = caption;
this.content = content; this.content = content;
this.helpLink = helpLink; this.helpLink = helpLink;
this.saveButtonClickListener = saveButtonClickListener; 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);
this.i18n = i18n; this.i18n = i18n;
init(); init();
} }
@Override @Override
public void close() { public void close() {
super.close(); super.close();
orginalValues.clear(); orginalValues.clear();
removeListeners(); removeListeners();
allComponents.clear(); allComponents.clear();
this.saveButton.setEnabled(false); this.saveButton.setEnabled(false);
} }
private void removeListeners() { private void removeListeners() {
for (final AbstractField<?> field : allComponents) { for (final AbstractField<?> field : allComponents) {
removeTextListener(field); removeTextListener(field);
removeValueChangeListener(field); removeValueChangeListener(field);
removeItemSetChangeistener(field); removeItemSetChangeistener(field);
} }
} }
private void removeItemSetChangeistener(final AbstractField<?> field) { private void removeItemSetChangeistener(final AbstractField<?> field) {
if (!(field instanceof Table)) { if (!(field instanceof Table)) {
return; return;
} }
for (final Object listener : field.getListeners(ItemSetChangeEvent.class)) { for (final Object listener : field.getListeners(ItemSetChangeEvent.class)) {
if (listener instanceof ChangeListener) { if (listener instanceof ChangeListener) {
((Table) field).removeItemSetChangeListener((ChangeListener) listener); ((Table) field).removeItemSetChangeListener((ChangeListener) listener);
} }
} }
} }
private void removeTextListener(final AbstractField<?> field) { private void removeTextListener(final AbstractField<?> field) {
if (!(field instanceof TextChangeNotifier)) { if (!(field instanceof TextChangeNotifier)) {
return; return;
} }
for (final Object listener : field.getListeners(TextChangeEvent.class)) { for (final Object listener : field.getListeners(TextChangeEvent.class)) {
if (listener instanceof ChangeListener) { if (listener instanceof ChangeListener) {
((TextChangeNotifier) field).removeTextChangeListener((ChangeListener) listener); ((TextChangeNotifier) field).removeTextChangeListener((ChangeListener) listener);
} }
} }
} }
private void removeValueChangeListener(final AbstractField<?> field) { private void removeValueChangeListener(final AbstractField<?> field) {
for (final Object listener : field.getListeners(ValueChangeEvent.class)) { for (final Object listener : field.getListeners(ValueChangeEvent.class)) {
if (listener instanceof ChangeListener) { if (listener instanceof ChangeListener) {
field.removeValueChangeListener((ChangeListener) listener); field.removeValueChangeListener((ChangeListener) listener);
} }
} }
} }
private final void init() { private final void init() {
if (content instanceof AbstractOrderedLayout) { if (content instanceof AbstractOrderedLayout) {
((AbstractOrderedLayout) content).setSpacing(true); ((AbstractOrderedLayout) content).setSpacing(true);
((AbstractOrderedLayout) content).setMargin(true); ((AbstractOrderedLayout) content).setMargin(true);
} }
if (content instanceof GridLayout) { if (content instanceof GridLayout) {
addStyleName("marginTop"); addStyleName("marginTop");
} }
if (null != content) { if (null != content) {
mainLayout.addComponent(content); mainLayout.addComponent(content);
mainLayout.setExpandRatio(content, 1.0F); mainLayout.setExpandRatio(content, 1.0F);
} }
createMandatoryLabel(); createMandatoryLabel();
final HorizontalLayout buttonLayout = createActionButtonsLayout(); final HorizontalLayout buttonLayout = createActionButtonsLayout();
mainLayout.addComponent(buttonLayout); mainLayout.addComponent(buttonLayout);
mainLayout.setComponentAlignment(buttonLayout, Alignment.TOP_CENTER); mainLayout.setComponentAlignment(buttonLayout, Alignment.TOP_CENTER);
setCaption(caption); setCaption(caption);
setCaptionAsHtml(true); setCaptionAsHtml(true);
setContent(mainLayout); setContent(mainLayout);
setResizable(false); setResizable(false);
center(); center();
setModal(true); setModal(true);
addStyleName("fontsize"); addStyleName("fontsize");
setOrginaleValues(); setOrginaleValues();
addListeners(); addListeners();
} }
/** /**
* saves the original values in a Map so we can use them for detecting * saves the original values in a Map so we can use them for detecting
* changes * changes
*/ */
public final void setOrginaleValues() { public final void setOrginaleValues() {
for (final AbstractField<?> field : allComponents) { for (final AbstractField<?> field : allComponents) {
Object value = field.getValue(); Object value = field.getValue();
if (field instanceof Table) { if (field instanceof Table) {
value = Sets.newHashSet(((Table) field).getContainerDataSource().getItemIds()); value = Sets.newHashSet(((Table) field).getContainerDataSource().getItemIds());
} }
orginalValues.put(field, value); orginalValues.put(field, value);
} }
saveButton.setEnabled(isSaveButtonEnabledAfterValueChange(null, null)); saveButton.setEnabled(isSaveButtonEnabledAfterValueChange(null, null));
} }
protected void addListeners() { protected void addListeners() {
addComponenetListeners(); addComponenetListeners();
addCloseListenerForSaveButton(); addCloseListenerForSaveButton();
addCloseListenerForCancelButton(); addCloseListenerForCancelButton();
} }
protected void addCloseListenerForSaveButton() {
protected void addCloseListenerForSaveButton() { saveButton.addClickListener(close);
saveButton.addClickListener(close); }
}
protected void addCloseListenerForCancelButton() {
protected void addCloseListenerForCancelButton() { cancelButton.addClickListener(close);
cancelButton.addClickListener(close); }
}
protected void addComponenetListeners() {
protected void addComponenetListeners() { for (final AbstractField<?> field : allComponents) {
for (final AbstractField<?> field : allComponents) { if (field instanceof TextChangeNotifier) {
if (field instanceof TextChangeNotifier) { ((TextChangeNotifier) field).addTextChangeListener(new ChangeListener(field));
((TextChangeNotifier) field).addTextChangeListener(new ChangeListener(field)); }
}
if (field instanceof Table) {
if (field instanceof Table) { ((Table) field).addItemSetChangeListener(new ChangeListener(field));
((Table) field).addItemSetChangeListener(new ChangeListener(field)); } else {
} else { field.addValueChangeListener(new ChangeListener(field));
field.addValueChangeListener(new ChangeListener(field)); }
} }
} }
}
private boolean isSaveButtonEnabledAfterValueChange(final Component currentChangedComponent,
private boolean isSaveButtonEnabledAfterValueChange(final Component currentChangedComponent, final Object newValue) {
final Object newValue) { return isMandatoryFieldNotEmptyAndValid(currentChangedComponent, newValue)
return isMandatoryFieldNotEmptyAndValid(currentChangedComponent, newValue) && isValuesChanged(currentChangedComponent, newValue);
&& isValuesChanged(currentChangedComponent, newValue); }
}
private boolean isValuesChanged(final Component currentChangedComponent, final Object newValue) {
private boolean isValuesChanged(final Component currentChangedComponent, final Object newValue) { for (final AbstractField<?> field : allComponents) {
for (final AbstractField<?> field : allComponents) { Object originalValue = orginalValues.get(field);
Object originalValue = orginalValues.get(field); if (field instanceof CheckBox && originalValue == null) {
if (field instanceof CheckBox && originalValue == null) { originalValue = Boolean.FALSE;
originalValue = Boolean.FALSE; }
} final Object currentValue = getCurrentVaue(currentChangedComponent, newValue, field);
final Object currentValue = getCurrentVaue(currentChangedComponent, newValue, field);
if (!isValueEquals(field, originalValue, currentValue)) {
if (!isValueEquals(field, originalValue, currentValue)) { return true;
return true; }
} }
} return false;
return false; }
}
private boolean isValueEquals(final AbstractField<?> field, final Object orginalValue, final Object currentValue) {
private boolean isValueEquals(final AbstractField<?> field, final Object orginalValue, final Object currentValue) { if (Set.class.equals(field.getType())) {
if (Set.class.equals(field.getType())) { return CollectionUtils.isEqualCollection(CollectionUtils.emptyIfNull((Collection<?>) orginalValue),
return CollectionUtils.isEqualCollection(CollectionUtils.emptyIfNull((Collection<?>) orginalValue), CollectionUtils.emptyIfNull((Collection<?>) currentValue));
CollectionUtils.emptyIfNull((Collection<?>) currentValue)); }
}
if (String.class.equals(field.getType())) {
if (String.class.equals(field.getType())) { return Objects.equals(Strings.emptyToNull((String) orginalValue),
return Objects.equals(Strings.emptyToNull((String) orginalValue), Strings.emptyToNull((String) currentValue));
Strings.emptyToNull((String) currentValue)); }
}
return Objects.equals(orginalValue, currentValue);
return Objects.equals(orginalValue, currentValue); }
}
private Object getCurrentVaue(final Component currentChangedComponent, final Object newValue,
private Object getCurrentVaue(final Component currentChangedComponent, final Object newValue, final AbstractField<?> field) {
final AbstractField<?> field) { Object currentValue = field.getValue();
Object currentValue = field.getValue(); if (field instanceof Table) {
if (field instanceof Table) { currentValue = ((Table) field).getContainerDataSource().getItemIds();
currentValue = ((Table) field).getContainerDataSource().getItemIds(); }
}
if (field.equals(currentChangedComponent)) {
if (field.equals(currentChangedComponent)) { currentValue = newValue;
currentValue = newValue; }
} return currentValue;
return currentValue; }
}
private boolean shouldMandatoryLabelShown() {
private boolean shouldMandatoryLabelShown() { for (final AbstractField<?> field : allComponents) {
for (final AbstractField<?> field : allComponents) { if (field.isRequired()) {
if (field.isRequired()) { return true;
return true; }
} }
}
return false;
return false; }
}
private boolean isMandatoryFieldNotEmptyAndValid(final Component currentChangedComponent, final Object newValue) {
private boolean isMandatoryFieldNotEmptyAndValid(final Component currentChangedComponent, final Object newValue) {
boolean valid = true;
boolean valid = true; final List<AbstractField<?>> requiredComponents = allComponents.stream().filter(field -> field.isRequired())
final List<AbstractField<?>> requiredComponents = allComponents.stream().filter(field -> field.isRequired()) .collect(Collectors.toList());
.collect(Collectors.toList());
requiredComponents.addAll(allComponents.stream().filter(this::hasNullValidator).collect(Collectors.toList()));
requiredComponents.addAll(allComponents.stream().filter(this::hasNullValidator).collect(Collectors.toList()));
for (final AbstractField field : requiredComponents) {
for (final AbstractField field : requiredComponents) { Object value = getCurrentVaue(currentChangedComponent, newValue, field);
Object value = getCurrentVaue(currentChangedComponent, newValue, field);
if (String.class.equals(field.getType())) {
if (String.class.equals(field.getType())) { value = Strings.emptyToNull((String) value);
value = Strings.emptyToNull((String) value); }
}
if (Set.class.equals(field.getType())) {
if (Set.class.equals(field.getType())) { value = emptyToNull((Collection<?>) value);
value = emptyToNull((Collection<?>) value); }
}
if (value == null) {
if (value == null) { return false;
return false; }
}
// We need to loop through the entire loop for validity testing.
// We need to loop through the entire loop for validity testing. // Otherwise the UI will only mark the
// Otherwise the UI will only mark the // first field with errors and then stop. If there are several
// first field with errors and then stop. If there are several // fields with errors, this is bad.
// fields with errors, this is bad. field.setValue(value);
field.setValue(value); if (!field.isValid()) {
if (!field.isValid()) { valid = false;
valid = false; }
} }
}
return valid;
return valid; }
}
private static Object emptyToNull(final Collection<?> c) {
private static Object emptyToNull(final Collection<?> c) { return (c == null || c.isEmpty()) ? null : c;
return (c == null || c.isEmpty()) ? null : c; }
}
private boolean hasNullValidator(final Component component) {
private boolean hasNullValidator(final Component component) {
if (component instanceof AbstractField<?>) {
if (component instanceof AbstractField<?>) { final AbstractField<?> fieldComponent = (AbstractField<?>) component;
final AbstractField<?> fieldComponent = (AbstractField<?>) component; for (final Validator validator : fieldComponent.getValidators()) {
for (final Validator validator : fieldComponent.getValidators()) { if (validator instanceof NullValidator) {
if (validator instanceof NullValidator) { return true;
return true; }
} }
} }
} return false;
return false; }
}
private List<AbstractField<?>> getAllComponents(final AbstractLayout abstractLayout) {
private List<AbstractField<?>> getAllComponents(final AbstractLayout abstractLayout) { final List<AbstractField<?>> components = new ArrayList<>();
final List<AbstractField<?>> components = new ArrayList<>();
final Iterator<Component> iterate = abstractLayout.iterator();
final Iterator<Component> iterate = abstractLayout.iterator(); while (iterate.hasNext()) {
while (iterate.hasNext()) { final Component c = iterate.next();
final Component c = iterate.next(); if (c instanceof AbstractLayout) {
if (c instanceof AbstractLayout) { components.addAll(getAllComponents((AbstractLayout) c));
components.addAll(getAllComponents((AbstractLayout) c)); }
}
if (c instanceof AbstractField) {
if (c instanceof AbstractField) { components.add((AbstractField<?>) c);
components.add((AbstractField<?>) c); }
}
if (c instanceof FlexibleOptionGroupItemComponent) {
if (c instanceof FlexibleOptionGroupItemComponent) { components.add(((FlexibleOptionGroupItemComponent) c).getOwner());
components.add(((FlexibleOptionGroupItemComponent) c).getOwner()); }
} }
} return components;
return components; }
}
private HorizontalLayout createActionButtonsLayout() {
private HorizontalLayout createActionButtonsLayout() {
buttonsLayout = new HorizontalLayout();
buttonsLayout = new HorizontalLayout(); buttonsLayout.setSizeFull();
buttonsLayout.setSizeUndefined(); buttonsLayout.setSpacing(true);
buttonsLayout.setSpacing(true); buttonsLayout.setSpacing(true);
createSaveButton(); buttonsLayout.addStyleName("actionButtonsMargin");
createCancelButton(); createSaveButton();
buttonsLayout.addStyleName("actionButtonsMargin"); createCancelButton();
addHelpLink(); addHelpLink();
return buttonsLayout; return buttonsLayout;
} }
private void createMandatoryLabel() { private void createMandatoryLabel() {
if (!shouldMandatoryLabelShown()) { if (!shouldMandatoryLabelShown()) {
return; return;
} }
final Label mandatoryLabel = new Label(i18n.get("label.mandatory.field")); final Label mandatoryLabel = new Label(i18n.get("label.mandatory.field"));
mandatoryLabel.addStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_ERROR + " " + ValoTheme.LABEL_TINY); mandatoryLabel.addStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_ERROR + " " + ValoTheme.LABEL_TINY);
if (content instanceof TargetAddUpdateWindowLayout) { if (content instanceof TargetAddUpdateWindowLayout) {
((TargetAddUpdateWindowLayout) content).getFormLayout().addComponent(mandatoryLabel); ((TargetAddUpdateWindowLayout) content).getFormLayout().addComponent(mandatoryLabel);
} else if (content instanceof SoftwareModuleAddUpdateWindow) { } else if (content instanceof SoftwareModuleAddUpdateWindow) {
((SoftwareModuleAddUpdateWindow) content).getFormLayout().addComponent(mandatoryLabel); ((SoftwareModuleAddUpdateWindow) content).getFormLayout().addComponent(mandatoryLabel);
} else if (content instanceof AbstractCreateUpdateTagLayout) { } else if (content instanceof AbstractCreateUpdateTagLayout) {
((AbstractCreateUpdateTagLayout) content).getMainLayout().addComponent(mandatoryLabel); ((AbstractCreateUpdateTagLayout) content).getMainLayout().addComponent(mandatoryLabel);
} }
mainLayout.addComponent(mandatoryLabel); mainLayout.addComponent(mandatoryLabel);
} }
private void createCancelButton() { private void createCancelButton() {
cancelButton = SPUIComponentProvider.getButton(SPUIComponentIdProvider.CANCEL_BUTTON, "Cancel", "", "", true, cancelButton = SPUIComponentProvider.getButton(SPUIComponentIdProvider.CANCEL_BUTTON, "Cancel", "", "", true,
FontAwesome.TIMES, SPUIButtonStyleBorderWithIcon.class); FontAwesome.TIMES, SPUIButtonStyleNoBorderWithIcon.class);
cancelButton.setSizeUndefined(); cancelButton.setSizeUndefined();
cancelButton.addStyleName("default-color"); cancelButton.addStyleName("default-color");
if (cancelButtonClickListener != null) { if (cancelButtonClickListener != null) {
cancelButton.addClickListener(cancelButtonClickListener); cancelButton.addClickListener(cancelButtonClickListener);
} }
buttonsLayout.addComponent(cancelButton); buttonsLayout.addComponent(cancelButton);
buttonsLayout.setComponentAlignment(cancelButton, Alignment.MIDDLE_LEFT); buttonsLayout.setComponentAlignment(cancelButton, Alignment.MIDDLE_LEFT);
buttonsLayout.setExpandRatio(cancelButton, 1.0F); buttonsLayout.setExpandRatio(cancelButton, 1.0F);
} }
private void createSaveButton() { private void createSaveButton() {
saveButton = SPUIComponentProvider.getButton(SPUIComponentIdProvider.SAVE_BUTTON, "Save", "", "", true, saveButton = SPUIComponentProvider.getButton(SPUIComponentIdProvider.SAVE_BUTTON, "Save", "", "", true,
FontAwesome.SAVE, SPUIButtonStyleBorderWithIcon.class); FontAwesome.SAVE, SPUIButtonStyleNoBorderWithIcon.class);
saveButton.setSizeUndefined(); saveButton.setSizeUndefined();
saveButton.addStyleName("default-color"); saveButton.addStyleName("default-color");
saveButton.addClickListener(saveButtonClickListener); 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);
buttonsLayout.setExpandRatio(saveButton, 1.0F); buttonsLayout.setExpandRatio(saveButton, 1.0F);
} }
private void addHelpLink() { private void addHelpLink() {
if (StringUtils.isEmpty(helpLink)) { if (StringUtils.isEmpty(helpLink)) {
return; return;
} }
final Link helpLinkComponent = SPUIComponentProvider.getHelpLink(helpLink); final Link helpLinkComponent = SPUIComponentProvider.getHelpLink(helpLink);
buttonsLayout.addComponent(helpLinkComponent); buttonsLayout.addComponent(helpLinkComponent);
buttonsLayout.setComponentAlignment(helpLinkComponent, Alignment.MIDDLE_RIGHT); buttonsLayout.setComponentAlignment(helpLinkComponent, Alignment.MIDDLE_RIGHT);
} }
public AbstractComponent getButtonsLayout() {
public AbstractComponent getButtonsLayout() { return this.buttonsLayout;
return this.buttonsLayout; }
}
private class ChangeListener implements ValueChangeListener, TextChangeListener, ItemSetChangeListener {
private class ChangeListener implements ValueChangeListener, TextChangeListener, ItemSetChangeListener { private final Field<?> field;
private final Field<?> field; public ChangeListener(final Field<?> field) {
super();
public ChangeListener(final Field<?> field) { this.field = field;
super(); }
this.field = field;
} @Override
public void textChange(final TextChangeEvent event) {
@Override saveButton.setEnabled(isSaveButtonEnabledAfterValueChange(field, event.getText()));
public void textChange(final TextChangeEvent event) { }
saveButton.setEnabled(isSaveButtonEnabledAfterValueChange(field, event.getText()));
} @Override
public void valueChange(final ValueChangeEvent event) {
@Override saveButton.setEnabled(isSaveButtonEnabledAfterValueChange(field, field.getValue()));
public void valueChange(final ValueChangeEvent event) { }
saveButton.setEnabled(isSaveButtonEnabledAfterValueChange(field, field.getValue()));
} @Override
public void containerItemSetChange(final ItemSetChangeEvent event) {
@Override if (!(field instanceof Table)) {
public void containerItemSetChange(final ItemSetChangeEvent event) { return;
if (!(field instanceof Table)) { }
return; final Table table = (Table) field;
} saveButton.setEnabled(
final Table table = (Table) field; isSaveButtonEnabledAfterValueChange(table, table.getContainerDataSource().getItemIds()));
saveButton.setEnabled( }
isSaveButtonEnabledAfterValueChange(table, table.getContainerDataSource().getItemIds())); }
}
} /**
* Adds the component manually to the allComponents-List and adds a
* ValueChangeListener to it. Necessary in Update Distribution Type as the
* CheckBox concerned is an ItemProperty...
/** *
* Adds the component manually to the allComponents-List and adds a * @param component
* ValueChangeListener to it. Necessary in Update Distribution Type as the * AbstractField
* CheckBox concerned is an ItemProperty... */
* public void updateAllComponents(final AbstractField component) {
* @param component
* AbstractField allComponents.add(component);
*/ component.addValueChangeListener(new ChangeListener(component));
public void updateAllComponents(final AbstractField component) { }
allComponents.add(component); public VerticalLayout getMainLayout() {
component.addValueChangeListener(new ChangeListener(component)); return mainLayout;
} }
public VerticalLayout getMainLayout() { public void setSaveButtonEnabled(final boolean enabled) {
return mainLayout; saveButton.setEnabled(enabled);
} }
public void setSaveButtonEnabled(final boolean enabled) { public void setCancelButtonEnabled(final boolean enabled) {
saveButton.setEnabled(enabled); cancelButton.setEnabled(enabled);
} }
public void setCancelButtonEnabled(final boolean enabled) {
cancelButton.setEnabled(enabled);
}
} }

View File

@@ -8,15 +8,16 @@
*/ */
package org.eclipse.hawkbit.ui.decorators; package org.eclipse.hawkbit.ui.decorators;
import org.apache.commons.lang3.StringUtils;
import com.vaadin.server.Resource; import com.vaadin.server.Resource;
import com.vaadin.ui.Button; import com.vaadin.ui.Button;
import com.vaadin.ui.themes.ValoTheme; import com.vaadin.ui.themes.ValoTheme;
/** /**
* Button with icon decorator. * Decorator class for a borderless Button with an icon.
*
*/ */
public class SPUIButtonStyleBorderWithIcon implements SPUIButtonDecorator { public class SPUIButtonStyleNoBorderWithIcon implements SPUIButtonDecorator {
private Button button; private Button button;
@@ -24,23 +25,25 @@ public class SPUIButtonStyleBorderWithIcon implements SPUIButtonDecorator {
public Button decorate(final Button button, final String style, final boolean setStyle, final Resource icon) { public Button decorate(final Button button, final String style, final boolean setStyle, final Resource icon) {
this.button = button; this.button = button;
button.setSizeFull();
setButtonStyle(style, setStyle);
setButtonIcon(icon);
button.addStyleName(ValoTheme.LABEL_SMALL); button.addStyleName(ValoTheme.LABEL_SMALL);
button.setSizeFull(); button.addStyleName(ValoTheme.BUTTON_BORDERLESS_COLORED);
setOrAddButtonStyle(style, setStyle);
setButtonIcon(icon);
return button; return button;
} }
private void setButtonStyle(final String style, final boolean setStyle) { private void setOrAddButtonStyle(final String style, final boolean setStyle) {
if (style == null) { if (StringUtils.isEmpty(style)) {
return; return;
} }
if (setStyle) { if (setStyle) {
// overwrite all other styles
button.setStyleName(style); button.setStyleName(style);
} else { } else {
button.addStyleName(style); button.addStyleName(style);

View File

@@ -293,8 +293,4 @@
padding-bottom: 12px !important; padding-bottom: 12px !important;
} }
.v-button-default-color {
color: #551f62;
}
} }

View File

@@ -60,4 +60,5 @@
.metadata-table-margin { .metadata-table-margin {
margin-top:3px; margin-top:3px;
} }
} }

View File

@@ -164,5 +164,6 @@
.actionButtonsMargin { .actionButtonsMargin {
margin-top: 30px; margin-top: 30px;
margin-bottom: 10px;
} }
} }