Reduce more code

Signed-off-by: SirWayne <dennis.melzer@bosch-si.com>
This commit is contained in:
SirWayne
2016-04-05 12:35:01 +02:00
parent c47c29519d
commit 5c0257adb9
4 changed files with 39 additions and 74 deletions

View File

@@ -13,10 +13,17 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import org.eclipse.hawkbit.repository.SpPermissionChecker;
import org.eclipse.hawkbit.ui.management.state.ManagementUIState; import org.eclipse.hawkbit.ui.management.state.ManagementUIState;
import org.eclipse.hawkbit.ui.utils.I18N;
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
import org.eclipse.hawkbit.ui.utils.UINotification;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.vaadin.spring.events.EventBus;
import org.vaadin.tokenfield.TokenField; import org.vaadin.tokenfield.TokenField;
import org.vaadin.tokenfield.TokenField.InsertPosition; import org.vaadin.tokenfield.TokenField.InsertPosition;
@@ -52,13 +59,33 @@ public abstract class AbstractTagToken implements Serializable {
protected final Map<Long, TagData> tokensAdded = new HashMap<>(); protected final Map<Long, TagData> tokensAdded = new HashMap<>();
protected CssLayout tokenLayout = new CssLayout(); protected CssLayout tokenLayout = new CssLayout();
@Autowired
protected SpPermissionChecker checker;
@Autowired
protected I18N i18n;
@Autowired
protected UINotification uinotification;
@Autowired
protected transient EventBus.SessionEventBus eventBus;
@Autowired @Autowired
protected ManagementUIState managementUIState; protected ManagementUIState managementUIState;
@PostConstruct
protected void init() { protected void init() {
createTokenField(); createTokenField();
checkIfTagAssignedIsAllowed(); checkIfTagAssignedIsAllowed();
eventBus.subscribe(this);
}
@PreDestroy
void destroy() {
eventBus.unsubscribe(this);
} }
private void createTokenField() { private void createTokenField() {

View File

@@ -8,54 +8,25 @@
*/ */
package org.eclipse.hawkbit.ui.common.tagdetails; package org.eclipse.hawkbit.ui.common.tagdetails;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import org.eclipse.hawkbit.eventbus.event.TargetTagCreatedBulkEvent; import org.eclipse.hawkbit.eventbus.event.TargetTagCreatedBulkEvent;
import org.eclipse.hawkbit.eventbus.event.TargetTagDeletedEvent; import org.eclipse.hawkbit.eventbus.event.TargetTagDeletedEvent;
import org.eclipse.hawkbit.repository.SpPermissionChecker;
import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.TagManagement;
import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.TargetTag;
import org.eclipse.hawkbit.ui.utils.I18N;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.vaadin.spring.events.EventBus;
import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.EventScope;
import org.vaadin.spring.events.annotation.EventBusListenerMethod; import org.vaadin.spring.events.annotation.EventBusListenerMethod;
import com.vaadin.ui.UI;
/** /**
* Abstract class for target tag token layout. * Abstract class for target tag token layout.
*/ */
public abstract class AbstractTargetTagToken extends AbstractTagToken { public abstract class AbstractTargetTagToken extends AbstractTagToken {
private static final long serialVersionUID = 7772876588903171201L; private static final long serialVersionUID = 7772876588903171201L;
protected UI ui;
@Autowired
protected transient EventBus.SessionEventBus eventBus;
@Autowired
protected I18N i18n;
@Autowired @Autowired
protected transient TagManagement tagManagement; protected transient TagManagement tagManagement;
@Autowired
protected SpPermissionChecker checker;
@Override
@PostConstruct
protected void init() {
super.init();
ui = UI.getCurrent();
eventBus.subscribe(this);
}
@PreDestroy
void destroy() {
eventBus.unsubscribe(this);
}
@EventBusListenerMethod(scope = EventScope.SESSION) @EventBusListenerMethod(scope = EventScope.SESSION)
void onEventTargetTagCreated(final TargetTagCreatedBulkEvent event) { void onEventTargetTagCreated(final TargetTagCreatedBulkEvent event) {

View File

@@ -14,7 +14,6 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy; import javax.annotation.PreDestroy;
import org.eclipse.hawkbit.eventbus.event.DistributionSetTagAssigmentResultEvent; import org.eclipse.hawkbit.eventbus.event.DistributionSetTagAssigmentResultEvent;
@@ -22,7 +21,6 @@ import org.eclipse.hawkbit.eventbus.event.DistributionSetTagCreatedBulkEvent;
import org.eclipse.hawkbit.eventbus.event.DistributionSetTagDeletedEvent; import org.eclipse.hawkbit.eventbus.event.DistributionSetTagDeletedEvent;
import org.eclipse.hawkbit.eventbus.event.DistributionSetTagUpdateEvent; import org.eclipse.hawkbit.eventbus.event.DistributionSetTagUpdateEvent;
import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.SpPermissionChecker;
import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.TagManagement;
import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetTag;
@@ -31,10 +29,7 @@ import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent;
import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent.DistributionComponentEvent; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent.DistributionComponentEvent;
import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent;
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
import org.eclipse.hawkbit.ui.utils.I18N;
import org.eclipse.hawkbit.ui.utils.UINotification;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.vaadin.spring.events.EventBus;
import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.EventScope;
import org.vaadin.spring.events.annotation.EventBusListenerMethod; import org.vaadin.spring.events.annotation.EventBusListenerMethod;
@@ -52,19 +47,6 @@ import com.vaadin.ui.UI;
public class DistributionTagToken extends AbstractTagToken { public class DistributionTagToken extends AbstractTagToken {
private static final long serialVersionUID = -8022738301736043396L; private static final long serialVersionUID = -8022738301736043396L;
@Autowired
private SpPermissionChecker spChecker;
@Autowired
private I18N i18n;
@Autowired
private UINotification uinotification;
@Autowired
private transient EventBus.SessionEventBus eventBus;
@Autowired @Autowired
private transient TagManagement tagManagement; private transient TagManagement tagManagement;
@@ -73,20 +55,9 @@ public class DistributionTagToken extends AbstractTagToken {
private DistributionSet selectedDS; private DistributionSet selectedDS;
private UI ui;
// To Be Done : have to set this value based on view??? // To Be Done : have to set this value based on view???
private static final Boolean NOTAGS_SELECTED = Boolean.FALSE; private static final Boolean NOTAGS_SELECTED = Boolean.FALSE;
@Override
@PostConstruct
protected void init() {
super.init();
ui = UI.getCurrent();
eventBus.subscribe(this);
}
@Override @Override
protected String getTagStyleName() { protected String getTagStyleName() {
return "distribution-tag-"; return "distribution-tag-";
@@ -140,7 +111,7 @@ public class DistributionTagToken extends AbstractTagToken {
@Override @Override
protected Boolean isToggleTagAssignmentAllowed() { protected Boolean isToggleTagAssignmentAllowed() {
return spChecker.hasUpdateDistributionPermission(); return checker.hasUpdateDistributionPermission();
} }
@Override @Override
@@ -163,18 +134,15 @@ public class DistributionTagToken extends AbstractTagToken {
@EventBusListenerMethod(scope = EventScope.SESSION) @EventBusListenerMethod(scope = EventScope.SESSION)
void onEvent(final DistributionTableEvent distributionTableEvent) { void onEvent(final DistributionTableEvent distributionTableEvent) {
if (distributionTableEvent.getDistributionComponentEvent() == DistributionComponentEvent.ON_VALUE_CHANGE) { if (distributionTableEvent.getDistributionComponentEvent() != DistributionComponentEvent.ON_VALUE_CHANGE) {
ui.access(() -> { return;
/**
* distributionTableEvent.getDistributionSet() is null when
* table has no data.
*/
if (distributionTableEvent.getDistributionSet() != null) {
selectedDS = distributionTableEvent.getDistributionSet();
repopulateToken();
}
});
} }
UI.getCurrent().access(() -> {
if (distributionTableEvent.getDistributionSet() != null) {
selectedDS = distributionTableEvent.getDistributionSet();
repopulateToken();
}
});
} }
@EventBusListenerMethod(scope = EventScope.SESSION) @EventBusListenerMethod(scope = EventScope.SESSION)
@@ -234,6 +202,7 @@ public class DistributionTagToken extends AbstractTagToken {
return false; return false;
} }
@Override
@PreDestroy @PreDestroy
void destroy() { void destroy() {
eventBus.unsubscribe(this); eventBus.unsubscribe(this);

View File

@@ -32,6 +32,7 @@ import org.vaadin.spring.events.annotation.EventBusListenerMethod;
import com.vaadin.data.Item; import com.vaadin.data.Item;
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.UI;
/** /**
* Implementation of Target tag token. * Implementation of Target tag token.
@@ -175,10 +176,7 @@ public class TargetTagToken extends AbstractTargetTagToken {
void onEvent(final TargetTableEvent targetTableEvent) { void onEvent(final TargetTableEvent targetTableEvent) {
if (targetTableEvent.getTargetComponentEvent() == TargetComponentEvent.SELECTED_TARGET if (targetTableEvent.getTargetComponentEvent() == TargetComponentEvent.SELECTED_TARGET
&& targetTableEvent.getTarget() != null) { && targetTableEvent.getTarget() != null) {
ui.access(() -> { UI.getCurrent().access(() -> {
/**
* targetTableEvent.getTarget() is null when table has no data.
*/
selectedTarget = targetTableEvent.getTarget(); selectedTarget = targetTableEvent.getTarget();
repopulateToken(); repopulateToken();
}); });