Refactor multiselect code

Signed-off-by: Melanie Retter <melanie.retter@bosch-si.com>
This commit is contained in:
Melanie Retter
2016-06-14 13:24:58 +02:00
parent b99d2a1112
commit c3f2c4fc70
12 changed files with 47 additions and 270 deletions

View File

@@ -11,12 +11,8 @@ package org.eclipse.hawkbit.ui.artifacts.smtable;
import javax.annotation.PostConstruct;
import org.eclipse.hawkbit.ui.common.table.AbstractTableLayout;
import org.eclipse.hawkbit.ui.distributions.event.SoftwareModuleTableEvent;
import org.eclipse.hawkbit.ui.distributions.event.SoftwareModuleTableEvent.SoftwareModuleComponentEvent;
import org.springframework.beans.factory.annotation.Autowired;
import com.vaadin.event.Action;
import com.vaadin.event.Action.Handler;
import com.vaadin.spring.annotation.SpringComponent;
import com.vaadin.spring.annotation.ViewScope;
@@ -46,41 +42,9 @@ public class SoftwareModuleTableLayout extends AbstractTableLayout {
super.init(smTableHeader, smTable, softwareModuleDetails);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.hawkbit.server.ui.common.table.AbstractTableLayout#
* isShortCutKeysRequired()
*/
@Override
protected boolean isShortCutKeysRequired() {
return true;
protected void publishEvent() {
// nothing to publish
}
/*
* (non-Javadoc)
*
* @see org.eclipse.hawkbit.server.ui.common.table.AbstractTableLayout#
* getShortCutKeysHandler()
*/
@Override
protected Handler getShortCutKeysHandler() {
return new Handler() {
private static final long serialVersionUID = 1L;
@Override
public void handleAction(final Action action, final Object sender, final Object target) {
if (ACTION_CTRL_A.equals(action)) {
smTable.selectAll();
getEventBus().publish(this, new SoftwareModuleTableEvent(SoftwareModuleComponentEvent.SELECT_ALL));
}
}
@Override
public Action[] getActions(final Object target, final Object sender) {
return new Action[] { ACTION_CTRL_A };
}
};
}
}

View File

@@ -54,12 +54,4 @@ public abstract class AbstractNamedVersionTable<E extends NamedVersionedEntity,
item.getItemProperty(SPUILabelDefinitions.VAR_VERSION).setValue(baseEntity.getVersion());
}
/**
* Select all rows in the table.
*/
public void selectAll() {
// only contains the ItemIds of the visible items in the table
setValue(getItemIds());
}
}

View File

@@ -153,6 +153,14 @@ public abstract class AbstractTable<E extends NamedEntity, I> extends Table {
}
}
/**
* Select all rows in the table.
*/
protected void selectAll() {
// only contains the ItemIds of the visible items in the table
setValue(getItemIds());
}
private void setColumnProperties() {
final List<TableColumn> columnList = getTableVisibleColumns();
final List<Object> swColumnIds = new ArrayList<>();

View File

@@ -12,6 +12,7 @@ import org.eclipse.hawkbit.ui.common.detailslayout.AbstractTableDetailsLayout;
import org.springframework.beans.factory.annotation.Autowired;
import org.vaadin.spring.events.EventBus;
import com.vaadin.event.Action;
import com.vaadin.event.Action.Handler;
import com.vaadin.event.ShortcutAction;
import com.vaadin.ui.Alignment;
@@ -89,10 +90,10 @@ public abstract class AbstractTableLayout extends VerticalLayout {
/**
* If any short cut keys required on the table.
*
* @return true if required else false. Default is 'false'.
* @return true if required else false. Default is 'true'.
*/
protected boolean isShortCutKeysRequired() {
return false;
return true;
}
/**
@@ -101,7 +102,27 @@ public abstract class AbstractTableLayout extends VerticalLayout {
* @return reference of {@link Handler} to handler the short cut keys.
* Default is null.
*/
protected abstract Handler getShortCutKeysHandler();
protected Handler getShortCutKeysHandler() {
return new Handler() {
private static final long serialVersionUID = 1L;
@Override
public void handleAction(final Action action, final Object sender, final Object target) {
if (ACTION_CTRL_A.equals(action)) {
table.selectAll();
publishEvent();
}
}
@Override
public Action[] getActions(final Object target, final Object sender) {
return new Action[] { ACTION_CTRL_A };
}
};
}
protected abstract void publishEvent();
public void setShowFilterButtonVisible(final boolean visible) {
tableHeader.setFilterButtonsIconVisible(visible);

View File

@@ -11,17 +11,13 @@ package org.eclipse.hawkbit.ui.distributions.dstable;
import javax.annotation.PostConstruct;
import org.eclipse.hawkbit.ui.common.table.AbstractTableLayout;
import org.eclipse.hawkbit.ui.distributions.event.DistributionSetTableEvent;
import org.eclipse.hawkbit.ui.distributions.event.DistributionSetTableEvent.DistributionTableComponentEvent;
import org.springframework.beans.factory.annotation.Autowired;
import com.vaadin.event.Action;
import com.vaadin.event.Action.Handler;
import com.vaadin.spring.annotation.SpringComponent;
import com.vaadin.spring.annotation.ViewScope;
/**
* DistributionSet table layout.
* DistributionSet table layout
*/
@SpringComponent
@ViewScope
@@ -50,42 +46,9 @@ public class DistributionSetTableLayout extends AbstractTableLayout {
super.init(dsTableHeader, dsTable, distributionDetails);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.hawkbit.server.ui.common.table.AbstractTableLayout#
* isShortCutKeysRequired()
*/
@Override
protected boolean isShortCutKeysRequired() {
return true;
protected void publishEvent() {
// nothing to publish
}
/*
* (non-Javadoc)
*
* @see org.eclipse.hawkbit.server.ui.common.table.AbstractTableLayout#
* getShortCutKeysHandler()
*/
@Override
protected Handler getShortCutKeysHandler() {
return new Handler() {
private static final long serialVersionUID = 1L;
@Override
public void handleAction(final Action action, final Object sender, final Object target) {
if (ACTION_CTRL_A.equals(action)) {
dsTable.selectAll();
getEventBus().publish(this,
new DistributionSetTableEvent(DistributionTableComponentEvent.SELECT_ALL));
}
}
@Override
public Action[] getActions(final Object target, final Object sender) {
return new Action[] { ACTION_CTRL_A };
}
};
}
}

View File

@@ -1,25 +0,0 @@
package org.eclipse.hawkbit.ui.distributions.event;
public class DistributionSetTableEvent {
private final DistributionTableComponentEvent distributionSetTableEvent;
/**
* The component event.
*
* @param distributionSetTableEvent
* the distributionSet component event.
*/
public DistributionSetTableEvent(final DistributionTableComponentEvent distributionSetTableEvent) {
this.distributionSetTableEvent = distributionSetTableEvent;
}
/**
* DistributionSet table components events.
*
*/
public enum DistributionTableComponentEvent {
SELECT_ALL
}
}

View File

@@ -1,40 +0,0 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.ui.distributions.event;
/**
* Class which contains the Event when selecting all entries of the
* softwareModule table
*/
public class SoftwareModuleTableEvent {
/**
* SoftwareModule table components events.
*/
public enum SoftwareModuleComponentEvent {
SELECT_ALL
}
private final SoftwareModuleComponentEvent softwareModuleComponentEvent;
/**
* The component event.
*
* @param softwareModuleComponentEvent
* the softwareModule component event.
*/
public SoftwareModuleTableEvent(final SoftwareModuleComponentEvent softwareModuleComponentEvent) {
this.softwareModuleComponentEvent = softwareModuleComponentEvent;
}
public SoftwareModuleComponentEvent getSoftwareModuleComponentEvent() {
return softwareModuleComponentEvent;
}
}

View File

@@ -11,17 +11,13 @@ package org.eclipse.hawkbit.ui.distributions.smtable;
import javax.annotation.PostConstruct;
import org.eclipse.hawkbit.ui.common.table.AbstractTableLayout;
import org.eclipse.hawkbit.ui.distributions.event.SoftwareModuleTableEvent;
import org.eclipse.hawkbit.ui.distributions.event.SoftwareModuleTableEvent.SoftwareModuleComponentEvent;
import org.springframework.beans.factory.annotation.Autowired;
import com.vaadin.event.Action;
import com.vaadin.event.Action.Handler;
import com.vaadin.spring.annotation.SpringComponent;
import com.vaadin.spring.annotation.ViewScope;
/**
* Implementation of software module Layout .
* Implementation of software module Layout
*/
@SpringComponent
@ViewScope
@@ -46,41 +42,9 @@ public class SwModuleTableLayout extends AbstractTableLayout {
super.init(swModuleTableHeader, swModuleTable, swModuleDetails);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.hawkbit.server.ui.common.table.AbstractTableLayout#
* isShortCutKeysRequired()
*/
@Override
protected boolean isShortCutKeysRequired() {
return true;
protected void publishEvent() {
// nothing to publish
}
/*
* (non-Javadoc)
*
* @see org.eclipse.hawkbit.server.ui.common.table.AbstractTableLayout#
* getShortCutKeysHandler()
*/
@Override
protected Handler getShortCutKeysHandler() {
return new Handler() {
private static final long serialVersionUID = 1L;
@Override
public void handleAction(final Action action, final Object sender, final Object target) {
if (ACTION_CTRL_A.equals(action)) {
swModuleTable.selectAll();
getEventBus().publish(this, new SoftwareModuleTableEvent(SoftwareModuleComponentEvent.SELECT_ALL));
}
}
@Override
public Action[] getActions(final Object target, final Object sender) {
return new Action[] { ACTION_CTRL_A };
}
};
}
}

View File

@@ -11,12 +11,8 @@ package org.eclipse.hawkbit.ui.management.dstable;
import javax.annotation.PostConstruct;
import org.eclipse.hawkbit.ui.common.table.AbstractTableLayout;
import org.eclipse.hawkbit.ui.distributions.event.DistributionSetTableEvent;
import org.eclipse.hawkbit.ui.distributions.event.DistributionSetTableEvent.DistributionTableComponentEvent;
import org.springframework.beans.factory.annotation.Autowired;
import com.vaadin.event.Action;
import com.vaadin.event.Action.Handler;
import com.vaadin.spring.annotation.SpringComponent;
import com.vaadin.spring.annotation.ViewScope;
@@ -46,42 +42,9 @@ public class DistributionTableLayout extends AbstractTableLayout {
super.init(dsTableHeader, dsTable, distributionDetails);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.hawkbit.server.ui.common.table.AbstractTableLayout#
* isShortCutKeysRequired()
*/
@Override
protected boolean isShortCutKeysRequired() {
return true;
protected void publishEvent() {
// nothing to publish
}
/*
* (non-Javadoc)
*
* @see org.eclipse.hawkbit.server.ui.common.table.AbstractTableLayout#
* getShortCutKeysHandler()
*/
@Override
protected Handler getShortCutKeysHandler() {
return new Handler() {
private static final long serialVersionUID = 1L;
@Override
public void handleAction(final Action action, final Object sender, final Object target) {
if (ACTION_CTRL_A.equals(action)) {
dsTable.selectAll();
getEventBus().publish(this,
new DistributionSetTableEvent(DistributionTableComponentEvent.SELECT_ALL));
}
}
@Override
public Action[] getActions(final Object target, final Object sender) {
return new Action[] { ACTION_CTRL_A };
}
};
}
}

View File

@@ -22,7 +22,7 @@ public class TargetTableEvent extends BaseEntityEvent<Target> {
*
*/
public enum TargetComponentEvent {
REFRESH_TARGETS, SELLECT_ALL, BULK_TARGET_CREATED, BULK_UPLOAD_COMPLETED, BULK_TARGET_UPLOAD_STARTED, BULK_UPLOAD_PROCESS_STARTED
REFRESH_TARGETS, SELECT_ALL, BULK_TARGET_CREATED, BULK_UPLOAD_COMPLETED, BULK_TARGET_UPLOAD_STARTED, BULK_UPLOAD_PROCESS_STARTED
}
private TargetComponentEvent targetComponentEvent;

View File

@@ -95,7 +95,7 @@ public class CountMessageLabel extends Label {
@EventBusListenerMethod(scope = EventScope.SESSION)
void onEvent(final TargetTableEvent event) {
if (TargetTableEvent.TargetComponentEvent.SELLECT_ALL == event.getTargetComponentEvent()
if (TargetTableEvent.TargetComponentEvent.SELECT_ALL == event.getTargetComponentEvent()
|| TargetComponentEvent.REFRESH_TARGETS == event.getTargetComponentEvent()) {
displayTargetCountStatus();
}

View File

@@ -16,8 +16,6 @@ import org.eclipse.hawkbit.ui.management.event.TargetTableEvent.TargetComponentE
import org.springframework.beans.factory.annotation.Autowired;
import org.vaadin.spring.events.EventBus;
import com.vaadin.event.Action;
import com.vaadin.event.Action.Handler;
import com.vaadin.spring.annotation.SpringComponent;
import com.vaadin.spring.annotation.ViewScope;
@@ -47,45 +45,14 @@ public class TargetTableLayout extends AbstractTableLayout {
*/
@PostConstruct
void init() {
super.init(targetTableHeader, targetTable, targetDetails);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.hawkbit.server.ui.common.table.AbstractTableLayout#
* isShortCutKeysRequired()
*/
@Override
protected boolean isShortCutKeysRequired() {
return true;
}
protected void publishEvent() {
/*
* (non-Javadoc)
*
* @see org.eclipse.hawkbit.server.ui.common.table.AbstractTableLayout#
* getShortCutKeysHandler()
*/
@Override
protected Handler getShortCutKeysHandler() {
return new Handler() {
private static final long serialVersionUID = 1L;
@Override
public void handleAction(final Action action, final Object sender, final Object target) {
if (ACTION_CTRL_A.equals(action)) {
targetTable.selectAll();
eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.SELLECT_ALL));
}
}
@Override
public Action[] getActions(final Object target, final Object sender) {
return new Action[] { ACTION_CTRL_A };
}
};
eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.SELECT_ALL));
}
}