Add download server api
Signed-off-by: SirWayne <dennis.melzer@bosch-si.com>
This commit is contained in:
1
hawkbit-ui/src/main/.gitignore
vendored
1
hawkbit-ui/src/main/.gitignore
vendored
@@ -1 +0,0 @@
|
||||
/webapp/
|
||||
@@ -1,50 +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.push;
|
||||
|
||||
import org.atmosphere.container.JSR356AsyncSupport;
|
||||
import org.atmosphere.cpr.ApplicationConfig;
|
||||
import org.springframework.boot.context.embedded.ServletRegistrationBean;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import com.vaadin.spring.boot.internal.VaadinServletConfiguration;
|
||||
import com.vaadin.spring.boot.internal.VaadinServletConfigurationProperties;
|
||||
|
||||
/**
|
||||
* {@link VaadinServletConfiguration} that sets the context path for
|
||||
* {@link JSR356AsyncSupport} that registers
|
||||
* {@link SpringSecurityAtmosphereInterceptor} for spring security integration.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(VaadinServletConfigurationProperties.class)
|
||||
@Import(VaadinServletConfiguration.class)
|
||||
public class AsyncVaadinServletConfiguration extends VaadinServletConfiguration {
|
||||
|
||||
@Override
|
||||
@Bean
|
||||
protected ServletRegistrationBean vaadinServletRegistration() {
|
||||
return createServletRegistrationBean();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addInitParameters(final ServletRegistrationBean servletRegistrationBean) {
|
||||
super.addInitParameters(servletRegistrationBean);
|
||||
|
||||
servletRegistrationBean.addInitParameter(ApplicationConfig.JSR356_MAPPING_PATH, "/UI");
|
||||
servletRegistrationBean.addInitParameter(ApplicationConfig.ATMOSPHERE_INTERCEPTORS,
|
||||
SpringSecurityAtmosphereInterceptor.class.getName());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,52 +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.push;
|
||||
|
||||
import org.atmosphere.config.service.AtmosphereInterceptorService;
|
||||
import org.atmosphere.cpr.Action;
|
||||
import org.atmosphere.cpr.AtmosphereInterceptor;
|
||||
import org.atmosphere.cpr.AtmosphereInterceptorAdapter;
|
||||
import org.atmosphere.cpr.AtmosphereResource;
|
||||
import org.springframework.security.core.context.SecurityContext;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.web.context.HttpSessionSecurityContextRepository;
|
||||
|
||||
/**
|
||||
* An {@link AtmosphereInterceptor} implementation which retrieves the
|
||||
* {@link SecurityContext} from the http-session and set in into the
|
||||
* {@link SecurityContextHolder}. This is necessary due that websocket requests
|
||||
* are not going through the spring security filter chain and the
|
||||
* {@link SecurityContext} will not be present in the current Thread.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@AtmosphereInterceptorService
|
||||
public class SpringSecurityAtmosphereInterceptor extends AtmosphereInterceptorAdapter {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.atmosphere.cpr.AtmosphereInterceptor#inspect(org.atmosphere.cpr.
|
||||
* AtmosphereResource)
|
||||
*/
|
||||
@Override
|
||||
public Action inspect(final AtmosphereResource r) {
|
||||
final SecurityContext context = (SecurityContext) r.getRequest().getSession()
|
||||
.getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY);
|
||||
SecurityContextHolder.setContext(context);
|
||||
return Action.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postInspect(final AtmosphereResource r) {
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
}
|
||||
@@ -1,69 +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.repository;
|
||||
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
/**
|
||||
* An implementation of the {@link PageRequest} which is offset based by means
|
||||
* the offset is given and not the page number as in the original
|
||||
* {@link PageRequest} implemntation where the offset is generated. Due that the
|
||||
* REST-API is working with {@code offset} and {@code limit} parameter we need
|
||||
* an offset based page request for JPA.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public final class OffsetBasedPageRequest extends PageRequest {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final int offset;
|
||||
|
||||
/**
|
||||
* Creates a new {@link OffsetBasedPageRequest}. Offsets are zero indexed,
|
||||
* thus providing 0 for {@code offset} will return the first entry.
|
||||
*
|
||||
* @param offset
|
||||
* zero-based offset index.
|
||||
* @param limit
|
||||
* the limit of the page to be returned.
|
||||
*/
|
||||
public OffsetBasedPageRequest(final int offset, final int limit) {
|
||||
this(offset, limit, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link OffsetBasedPageRequest}. Offsets are zero indexed,
|
||||
* thus providing 0 for {@code offset} will return the first entry.
|
||||
*
|
||||
* @param offset
|
||||
* zero-based offset index.
|
||||
* @param limit
|
||||
* the limit of the page to be returned.
|
||||
* @param sort
|
||||
* sort can be {@literal null}.
|
||||
*/
|
||||
public OffsetBasedPageRequest(final int offset, final int limit, final Sort sort) {
|
||||
super(0, limit, sort);
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "OffsetBasedPageRequest [offset=" + offset + ", getPageSize()=" + getPageSize() + ", getPageNumber()="
|
||||
+ getPageNumber() + "]";
|
||||
}
|
||||
}
|
||||
@@ -1,180 +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.repository;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.eclipse.hawkbit.im.authentication.PermissionService;
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
/**
|
||||
* Bean which contains all SP permissions.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Validated
|
||||
@Service
|
||||
public class SpPermissionChecker implements Serializable {
|
||||
private static final long serialVersionUID = 2757865286212875704L;
|
||||
|
||||
@Autowired
|
||||
private transient PermissionService permissionService;
|
||||
|
||||
/**
|
||||
* Gets the SP monitor View Permission.
|
||||
*
|
||||
* @return SYSTEM_MONITOR boolean value
|
||||
*/
|
||||
public boolean hasSpMonitorViewPermission() {
|
||||
return permissionService.hasPermission(SpPermission.SYSTEM_MONITOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SP diagnosis retrieval Permission.
|
||||
*
|
||||
* @return SYSTEM_DIAG boolean value
|
||||
*/
|
||||
public boolean hasSpdiagnosisViewPermission() {
|
||||
return permissionService.hasPermission(SpPermission.SYSTEM_DIAG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SP administration retrieval Permission.
|
||||
*
|
||||
* @return SYSTEM_ADMIN boolean value
|
||||
*/
|
||||
public boolean hasSpAdminViewPermission() {
|
||||
return permissionService.hasPermission(SpPermission.SYSTEM_ADMIN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SP read Target & Dist Permission.
|
||||
*
|
||||
* @return TARGET_REPOSITORY_READ boolean value
|
||||
*/
|
||||
public boolean hasTargetAndRepositoryReadPermission() {
|
||||
return hasTargetReadPermission() && hasReadDistributionPermission();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SP read Target Permission.
|
||||
*
|
||||
* @return READ_TARGET boolean value
|
||||
*/
|
||||
public boolean hasTargetReadPermission() {
|
||||
return permissionService.hasPermission(SpPermission.READ_TARGET);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SP create Target Permission.
|
||||
*
|
||||
* @return READ_TARGET boolean value
|
||||
*/
|
||||
public boolean hasCreateTargetPermission() {
|
||||
return hasTargetReadPermission() && permissionService.hasPermission(SpPermission.CREATE_TARGET);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SP update Target Permission.
|
||||
*
|
||||
* @return READ_TARGET boolean value
|
||||
*/
|
||||
public boolean hasUpdateTargetPermission() {
|
||||
return hasTargetReadPermission() && permissionService.hasPermission(SpPermission.UPDATE_TARGET);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SP delete Target Permission.
|
||||
*
|
||||
* @return READ_TARGET boolean value
|
||||
*/
|
||||
public boolean hasDeleteTargetPermission() {
|
||||
return hasTargetReadPermission() && permissionService.hasPermission(SpPermission.DELETE_TARGET);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SP READ Distribution Permission.
|
||||
*
|
||||
* @return READ_REPOSITORY boolean value
|
||||
*/
|
||||
public boolean hasReadDistributionPermission() {
|
||||
return permissionService.hasPermission(SpPermission.READ_REPOSITORY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SP create Distribution Permission.
|
||||
*
|
||||
* @return CREATE_REPOSITORY boolean value
|
||||
*/
|
||||
public boolean hasCreateDistributionPermission() {
|
||||
return hasReadDistributionPermission() && permissionService.hasPermission(SpPermission.CREATE_REPOSITORY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SP update Distribution Permission.
|
||||
*
|
||||
* @return UPDATE_REPOSITORY boolean value
|
||||
*/
|
||||
public boolean hasUpdateDistributionPermission() {
|
||||
return hasReadDistributionPermission() && permissionService.hasPermission(SpPermission.UPDATE_REPOSITORY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SP delete Distribution Permission.
|
||||
*
|
||||
* @return DELETE_REPOSITORY boolean value
|
||||
*/
|
||||
public boolean hasDeleteDistributionPermission() {
|
||||
return hasReadDistributionPermission() && permissionService.hasPermission(SpPermission.DELETE_REPOSITORY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SP rollout create permission.
|
||||
*
|
||||
* @return permission for rollout update
|
||||
*/
|
||||
public boolean hasRolloutUpdatePermission() {
|
||||
return hasUpdateTargetPermission() && hasReadDistributionPermission()
|
||||
&& permissionService.hasPermission(SpPermission.ROLLOUT_MANAGEMENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SP rollout create permission.
|
||||
*
|
||||
* @return permission for rollout create
|
||||
*/
|
||||
public boolean hasRolloutCreatePermission() {
|
||||
return hasUpdateTargetPermission() && hasReadDistributionPermission()
|
||||
&& permissionService.hasPermission(SpPermission.ROLLOUT_MANAGEMENT);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Gets the SP rollout read permission.
|
||||
*
|
||||
* @return Gets the SP rollout read permission.
|
||||
*/
|
||||
public boolean hasRolloutReadPermission() {
|
||||
return permissionService.hasPermission(SpPermission.ROLLOUT_MANAGEMENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SP rollout targets read permission.
|
||||
*
|
||||
* @return permission to read rollout targets
|
||||
*/
|
||||
public boolean hasRolloutTargetsReadPermission() {
|
||||
return hasTargetReadPermission() && permissionService.hasPermission(SpPermission.ROLLOUT_MANAGEMENT);
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
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
|
||||
|
||||
-->
|
||||
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.5.1//EN" "http://google-web-toolkit.googlecode.com/svn/tags/2.5.1/distro-source/core/src/gwt-module.dtd">
|
||||
<module>
|
||||
<!-- This file is automatically updated based on new dependencies by the
|
||||
goal "vaadin:update-widgetset". -->
|
||||
|
||||
<!-- Inherit DefaultWidgetSet -->
|
||||
<inherits name="com.vaadin.DefaultWidgetSet" />
|
||||
|
||||
<inherits
|
||||
name="org.vaadin.hene.flexibleoptiongroup.widgetset.FlexibleOptionGroupWidgetset" />
|
||||
|
||||
<inherits name="org.vaadin.tokenfield.TokenfieldWidgetset" />
|
||||
|
||||
|
||||
<inherits
|
||||
name="org.vaadin.alump.distributionbar.gwt.DistributionBarWidgetset" />
|
||||
|
||||
|
||||
|
||||
<inherits name="org.vaadin.peter.contextmenu.ContextmenuWidgetset" />
|
||||
|
||||
<inherits
|
||||
name="org.vaadin.hene.flexibleoptiongroup.widgetset.FlexibleOptionGroupWidgetset" />
|
||||
|
||||
<inherits
|
||||
name="org.vaadin.alump.distributionbar.gwt.DistributionBarWidgetset" />
|
||||
|
||||
<inherits name="org.eclipse.hawkbit.ui.customrenderers.CustomRendererWidgetSet" />
|
||||
|
||||
<inherits name="org.vaadin.hene.flexibleoptiongroup.widgetset.FlexibleOptionGroupWidgetset" />
|
||||
|
||||
<inherits name="org.vaadin.alump.distributionbar.gwt.DistributionBarWidgetset" />
|
||||
</module>
|
||||
@@ -1,29 +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;
|
||||
|
||||
import org.eclipse.hawkbit.ui.themes.HawkbitTheme;
|
||||
|
||||
import com.vaadin.annotations.Theme;
|
||||
import com.vaadin.annotations.Widgetset;
|
||||
import com.vaadin.ui.UI;
|
||||
|
||||
/**
|
||||
* Abstract class for the ui to set widgetset and theme.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
@Widgetset(value = HawkbitTheme.WIDGET_SET_NAME)
|
||||
@Theme(HawkbitTheme.THEME_NAME)
|
||||
public abstract class DefaultHawkbitUI extends UI {
|
||||
|
||||
}
|
||||
@@ -1,66 +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;
|
||||
|
||||
import org.eclipse.hawkbit.eventbus.event.Event;
|
||||
import org.springframework.security.core.context.SecurityContext;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.vaadin.spring.events.EventBus;
|
||||
|
||||
import com.vaadin.server.VaadinSession;
|
||||
import com.vaadin.ui.UI;
|
||||
import com.vaadin.util.CurrentInstance;
|
||||
|
||||
/**
|
||||
* A {@link Runnable} implementation for the {@link UI#access(Runnable)} to
|
||||
* dispatch events to the UI in the UI thread.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class DispatcherRunnable implements Runnable {
|
||||
|
||||
private final SecurityContext userContext;
|
||||
private final Event event;
|
||||
private final VaadinSession session;
|
||||
private final EventBus eventBus;
|
||||
|
||||
/**
|
||||
* @param eventBus
|
||||
* the event bus to distribute the event to
|
||||
* @param session
|
||||
* the current Vaadin session
|
||||
* @param userContext
|
||||
* the context of the currently logged in user to distribute the
|
||||
* event to
|
||||
* @param event
|
||||
* the event which is distributed to the UI.
|
||||
*/
|
||||
public DispatcherRunnable(final EventBus eventBus, final VaadinSession session, final SecurityContext userContext,
|
||||
final Event event) {
|
||||
this.eventBus = eventBus;
|
||||
this.session = session;
|
||||
this.userContext = userContext;
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
CurrentInstance.setCurrent(session.getUIs().iterator().next());
|
||||
CurrentInstance.setCurrent(session);
|
||||
SecurityContextHolder.setContext(userContext);
|
||||
eventBus.publish(this, event);
|
||||
}
|
||||
}
|
||||
@@ -1,78 +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;
|
||||
|
||||
import org.eclipse.hawkbit.ui.menu.DashboardMenu;
|
||||
import org.eclipse.hawkbit.ui.menu.DashboardMenuItem;
|
||||
import org.eclipse.hawkbit.ui.utils.I18N;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.vaadin.navigator.Navigator;
|
||||
import com.vaadin.navigator.View;
|
||||
import com.vaadin.navigator.ViewChangeListener;
|
||||
import com.vaadin.shared.Position;
|
||||
import com.vaadin.spring.annotation.SpringComponent;
|
||||
import com.vaadin.spring.annotation.UIScope;
|
||||
import com.vaadin.ui.Label;
|
||||
import com.vaadin.ui.Notification;
|
||||
import com.vaadin.ui.Notification.Type;
|
||||
import com.vaadin.ui.UI;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
|
||||
/**
|
||||
* View class that is instantiated when no other view matches the navigation
|
||||
* state.
|
||||
*
|
||||
*
|
||||
*
|
||||
* @see Navigator#setErrorView(Class)
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
@SpringComponent
|
||||
@UIScope
|
||||
class ErrorView extends VerticalLayout implements View {
|
||||
|
||||
private final Label message;
|
||||
|
||||
@Autowired
|
||||
private I18N i18n;
|
||||
|
||||
@Autowired
|
||||
private DashboardMenu dashboardMenu;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public ErrorView() {
|
||||
setMargin(true);
|
||||
message = new Label();
|
||||
addComponent(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enter(final ViewChangeListener.ViewChangeEvent event) {
|
||||
final DashboardMenuItem view = dashboardMenu.getByViewName(event.getViewName());
|
||||
if (view == null) {
|
||||
message.setValue(i18n.get("message.error.view", new Object[] { event.getViewName() }));
|
||||
return;
|
||||
}
|
||||
if (dashboardMenu.isAccessDenied(event.getViewName())) {
|
||||
final Notification nt = new Notification("Access denied",
|
||||
i18n.get("message.accessdenied.view", new Object[] { event.getViewName() }), Type.ERROR_MESSAGE,
|
||||
false);
|
||||
nt.setStyleName(SPUILabelDefinitions.SP_NOTIFICATION_ERROR_MESSAGE_STYLE);
|
||||
nt.setPosition(Position.BOTTOM_RIGHT);
|
||||
nt.show(UI.getCurrent().getPage());
|
||||
message.setValue(i18n.get("message.accessdenied.view", new Object[] { event.getViewName() }));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,58 +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;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.hawkbit.eventbus.event.DistributionSetTagCreatedBulkEvent;
|
||||
import org.eclipse.hawkbit.eventbus.event.DistributionSetTagDeletedEvent;
|
||||
import org.eclipse.hawkbit.eventbus.event.DistributionSetTagUpdateEvent;
|
||||
import org.eclipse.hawkbit.eventbus.event.Event;
|
||||
import org.eclipse.hawkbit.eventbus.event.RolloutChangeEvent;
|
||||
import org.eclipse.hawkbit.eventbus.event.RolloutGroupChangeEvent;
|
||||
import org.eclipse.hawkbit.eventbus.event.TargetCreatedEvent;
|
||||
import org.eclipse.hawkbit.eventbus.event.TargetDeletedEvent;
|
||||
import org.eclipse.hawkbit.eventbus.event.TargetInfoUpdateEvent;
|
||||
import org.eclipse.hawkbit.eventbus.event.TargetTagCreatedBulkEvent;
|
||||
import org.eclipse.hawkbit.eventbus.event.TargetTagDeletedEvent;
|
||||
|
||||
/**
|
||||
* The default hawkbit event provider.
|
||||
*/
|
||||
public class HawkbitEventProvider implements UIEventProvider {
|
||||
|
||||
private static final Set<Class<? extends Event>> SINGLE_EVENTS = new HashSet<>(6);
|
||||
private static final Set<Class<? extends Event>> BULK_EVENTS = new HashSet<>(3);
|
||||
|
||||
static {
|
||||
SINGLE_EVENTS.add(TargetTagCreatedBulkEvent.class);
|
||||
SINGLE_EVENTS.add(DistributionSetTagCreatedBulkEvent.class);
|
||||
SINGLE_EVENTS.add(DistributionSetTagDeletedEvent.class);
|
||||
SINGLE_EVENTS.add(TargetTagDeletedEvent.class);
|
||||
SINGLE_EVENTS.add(DistributionSetTagUpdateEvent.class);
|
||||
SINGLE_EVENTS.add(RolloutGroupChangeEvent.class);
|
||||
SINGLE_EVENTS.add(RolloutChangeEvent.class);
|
||||
|
||||
BULK_EVENTS.add(TargetCreatedEvent.class);
|
||||
BULK_EVENTS.add(TargetInfoUpdateEvent.class);
|
||||
BULK_EVENTS.add(TargetDeletedEvent.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Class<? extends Event>> getSingleEvents() {
|
||||
return SINGLE_EVENTS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Class<? extends Event>> getBulkEvents() {
|
||||
return BULK_EVENTS;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,260 +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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
|
||||
import org.eclipse.hawkbit.ui.components.SPUIErrorHandler;
|
||||
import org.eclipse.hawkbit.ui.menu.DashboardEvent.PostViewChangeEvent;
|
||||
import org.eclipse.hawkbit.ui.menu.DashboardMenu;
|
||||
import org.eclipse.hawkbit.ui.menu.DashboardMenuItem;
|
||||
import org.eclipse.hawkbit.ui.push.EventPushStrategy;
|
||||
import org.eclipse.hawkbit.ui.utils.I18N;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SpringContextHelper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.vaadin.spring.events.EventBus;
|
||||
|
||||
import com.vaadin.annotations.Title;
|
||||
import com.vaadin.navigator.Navigator;
|
||||
import com.vaadin.navigator.View;
|
||||
import com.vaadin.navigator.ViewChangeListener;
|
||||
import com.vaadin.navigator.ViewProvider;
|
||||
import com.vaadin.server.ClientConnector.DetachListener;
|
||||
import com.vaadin.server.Responsive;
|
||||
import com.vaadin.server.VaadinRequest;
|
||||
import com.vaadin.server.VaadinService;
|
||||
import com.vaadin.spring.navigator.SpringViewProvider;
|
||||
import com.vaadin.ui.Component;
|
||||
import com.vaadin.ui.CssLayout;
|
||||
import com.vaadin.ui.CustomLayout;
|
||||
import com.vaadin.ui.HorizontalLayout;
|
||||
import com.vaadin.ui.UI;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
import com.vaadin.ui.themes.ValoTheme;
|
||||
|
||||
/**
|
||||
* Vaadin management UI.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
@Title("hawkBit Update Server")
|
||||
public class HawkbitUI extends DefaultHawkbitUI implements DetachListener {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(HawkbitUI.class);
|
||||
|
||||
private static final String EMPTY_VIEW = "";
|
||||
|
||||
private transient EventPushStrategy pushStrategy;
|
||||
|
||||
@Autowired
|
||||
private SpringViewProvider viewProvider;
|
||||
|
||||
@Autowired
|
||||
private transient ApplicationContext context;
|
||||
|
||||
@Autowired
|
||||
private I18N i18n;
|
||||
|
||||
@Autowired
|
||||
private DashboardMenu dashboardMenu;
|
||||
|
||||
private HorizontalLayout content;
|
||||
|
||||
@Autowired
|
||||
private ErrorView errorview;
|
||||
|
||||
@Autowired
|
||||
protected transient EventBus.SessionEventBus eventBus;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public HawkbitUI() {
|
||||
// is empty, is ok.
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor taking the push strategy.
|
||||
*
|
||||
* @param pushStrategy
|
||||
* the strategy to push events from the backend to the UI
|
||||
*/
|
||||
public HawkbitUI(final EventPushStrategy pushStrategy) {
|
||||
this.pushStrategy = pushStrategy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detach(final DetachEvent event) {
|
||||
LOG.info("ManagementUI is detached uiid - {}", getUIId());
|
||||
eventBus.unsubscribe(this);
|
||||
if (pushStrategy != null) {
|
||||
pushStrategy.clean();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init(final VaadinRequest vaadinRequest) {
|
||||
LOG.info("ManagementUI init starts uiid - {}", getUI().getUIId());
|
||||
if (pushStrategy != null) {
|
||||
pushStrategy.init(getUI());
|
||||
}
|
||||
addDetachListener(this);
|
||||
SpringContextHelper.setContext(context);
|
||||
|
||||
Responsive.makeResponsive(this);
|
||||
addStyleName(ValoTheme.UI_WITH_MENU);
|
||||
setResponsive(Boolean.TRUE);
|
||||
|
||||
final HorizontalLayout rootLayout = new HorizontalLayout();
|
||||
rootLayout.setSizeFull();
|
||||
|
||||
dashboardMenu.init();
|
||||
dashboardMenu.setResponsive(Boolean.TRUE);
|
||||
|
||||
final VerticalLayout contentVerticalLayout = new VerticalLayout();
|
||||
contentVerticalLayout.addComponent(buildHeader());
|
||||
contentVerticalLayout.setSizeFull();
|
||||
|
||||
rootLayout.addComponent(dashboardMenu);
|
||||
rootLayout.addComponent(contentVerticalLayout);
|
||||
|
||||
content = new HorizontalLayout();
|
||||
contentVerticalLayout.addComponent(content);
|
||||
content.setStyleName("view-content");
|
||||
content.setSizeFull();
|
||||
rootLayout.setExpandRatio(contentVerticalLayout, 1.0f);
|
||||
contentVerticalLayout.setStyleName("main-content");
|
||||
contentVerticalLayout.setExpandRatio(content, 1.0F);
|
||||
setContent(rootLayout);
|
||||
final Resource resource = context
|
||||
.getResource("classpath:/VAADIN/themes/" + UI.getCurrent().getTheme() + "/layouts/footer.html");
|
||||
try {
|
||||
final CustomLayout customLayout = new CustomLayout(resource.getInputStream());
|
||||
customLayout.setSizeUndefined();
|
||||
contentVerticalLayout.addComponent(customLayout);
|
||||
} catch (final IOException ex) {
|
||||
LOG.error("Footer file is missing", ex);
|
||||
}
|
||||
final Navigator navigator = new Navigator(this, content);
|
||||
navigator.addViewChangeListener(new ViewChangeListener() {
|
||||
@Override
|
||||
public boolean beforeViewChange(final ViewChangeEvent event) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterViewChange(final ViewChangeEvent event) {
|
||||
final DashboardMenuItem view = dashboardMenu.getByViewName(event.getViewName());
|
||||
dashboardMenu.postViewChange(new PostViewChangeEvent(view));
|
||||
if (view == null) {
|
||||
content.setCaption(null);
|
||||
return;
|
||||
}
|
||||
content.setCaption(view.getDashboardCaptionLong());
|
||||
}
|
||||
});
|
||||
|
||||
navigator.setErrorView(errorview);
|
||||
navigator.addProvider(new ManagementViewProvider());
|
||||
setNavigator(navigator);
|
||||
navigator.addView(EMPTY_VIEW, new Navigator.EmptyView());
|
||||
// set locale is required for I18N class also, to get the locale from
|
||||
// cookie
|
||||
final String locale = getLocaleId(SPUIDefinitions.getAvailableLocales());
|
||||
setLocale(new Locale(locale));
|
||||
|
||||
UI.getCurrent().setErrorHandler(new SPUIErrorHandler());
|
||||
LOG.info("Current locale of the application is : {}", i18n.getLocale());
|
||||
}
|
||||
|
||||
private Component buildHeader() {
|
||||
final CssLayout cssLayout = new CssLayout();
|
||||
cssLayout.setStyleName("view-header");
|
||||
return cssLayout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Specific Locale.
|
||||
*
|
||||
* @param availableLocalesInApp
|
||||
* as set
|
||||
* @return String as preferred locale
|
||||
*/
|
||||
private String getLocaleId(final Set<String> availableLocalesInApp) {
|
||||
final String[] localeChain = getLocaleChain();
|
||||
String spLocale = SPUIDefinitions.DEFAULT_LOCALE;
|
||||
if (null != localeChain) {
|
||||
// Find best matching locale
|
||||
for (final String localeId : localeChain) {
|
||||
if (availableLocalesInApp.contains(localeId)) {
|
||||
spLocale = localeId;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return spLocale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Locale for i18n.
|
||||
*
|
||||
* @return String as locales
|
||||
*/
|
||||
private String[] getLocaleChain() {
|
||||
String[] localeChain = null;
|
||||
// Fetch all cookies from the request
|
||||
final Cookie[] cookies = VaadinService.getCurrentRequest().getCookies();
|
||||
if (cookies != null) {
|
||||
for (final Cookie c : cookies) {
|
||||
if (c.getName().equals(SPUIDefinitions.COOKIE_NAME) && !c.getValue().isEmpty()) {
|
||||
localeChain = c.getValue().split("#");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return localeChain;
|
||||
}
|
||||
|
||||
private class ManagementViewProvider implements ViewProvider {
|
||||
|
||||
@Override
|
||||
public String getViewName(final String viewAndParameters) {
|
||||
return viewProvider.getViewName(getStartView(viewAndParameters));
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(final String viewName) {
|
||||
return viewProvider.getView(getStartView(viewName));
|
||||
}
|
||||
|
||||
private String getStartView(final String viewName) {
|
||||
final DashboardMenuItem view = dashboardMenu.getByViewName(viewName);
|
||||
if ("".equals(viewName) && !dashboardMenu.isAccessibleViewsEmpty()) {
|
||||
return dashboardMenu.getInitialViewName();
|
||||
}
|
||||
if (view == null || dashboardMenu.isAccessDenied(viewName)) {
|
||||
return " ";
|
||||
}
|
||||
return viewName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,60 +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;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.eventbus.event.Event;
|
||||
|
||||
/**
|
||||
* The UI event provider hold all supported repository events which will
|
||||
* delegated to the UI. A event type can delegated as single event or bulk
|
||||
* event. Bulk event means, that all events from one type is collected by the
|
||||
* provider. The delegater and delegated as a list of this events.
|
||||
*/
|
||||
public interface UIEventProvider {
|
||||
|
||||
/**
|
||||
* Return all supported repository single event types. All events which this
|
||||
* type are delegated to the UI as single event.
|
||||
*
|
||||
* @return list of provided event types. Should not be null
|
||||
*/
|
||||
default Set<Class<? extends Event>> getSingleEvents() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all supported repository bulk event types. All events which this
|
||||
* type are delegated to the UI as a list. This list contains all collected
|
||||
* events from one type.
|
||||
*
|
||||
* @return list of provided bulk event types. Should not be null
|
||||
*/
|
||||
default Set<Class<? extends Event>> getBulkEvents() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all filtered bulk event types by the given events. The default
|
||||
* maps the events by class.
|
||||
*
|
||||
* @param allEvents
|
||||
* the events
|
||||
* @return list of provided bulk event types which are filtered. Should not
|
||||
* be null
|
||||
*/
|
||||
default Set<Class<?>> getFilteredBulkEventsType(final List<Event> allEvents) {
|
||||
return allEvents.stream().map(Event::getClass).filter(getBulkEvents()::contains).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,280 +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;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Properties for Management UI customization.
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
@ConfigurationProperties("hawkbit.server.ui")
|
||||
public class UiProperties {
|
||||
|
||||
/**
|
||||
* Demo account login information.
|
||||
*
|
||||
*/
|
||||
public static class Demo {
|
||||
|
||||
/**
|
||||
* Demo tenant.
|
||||
*/
|
||||
private String tenant = "";
|
||||
/**
|
||||
* Demo user name.
|
||||
*/
|
||||
private String user = "";
|
||||
|
||||
/**
|
||||
* Demo user password.
|
||||
*/
|
||||
private String password = "";
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public String getTenant() {
|
||||
return tenant;
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setPassword(final String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public void setTenant(final String tenant) {
|
||||
this.tenant = tenant;
|
||||
}
|
||||
|
||||
public void setUser(final String user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Links to potentially other systems (e.g. support, user management,
|
||||
* documentation etc.).
|
||||
*
|
||||
*/
|
||||
public static class Links {
|
||||
/**
|
||||
* Configuration of UI documentation links.
|
||||
*
|
||||
*/
|
||||
public static class Documentation {
|
||||
/**
|
||||
* Link to root of documentation and user guides.
|
||||
*/
|
||||
private String root = "";
|
||||
|
||||
/**
|
||||
* Link to documentation of deployment view.
|
||||
*/
|
||||
private String deploymentView = "";
|
||||
|
||||
/**
|
||||
* Link to documentation of distribution view.
|
||||
*/
|
||||
private String distributionView = "";
|
||||
|
||||
/**
|
||||
* Link to documentation of upload view.
|
||||
*/
|
||||
private String uploadView = "";
|
||||
|
||||
/**
|
||||
* Link to documentation of system configuration view.
|
||||
*/
|
||||
private String systemConfigurationView = "";
|
||||
|
||||
/**
|
||||
* Link to security related documentation.
|
||||
*/
|
||||
private String security = "";
|
||||
|
||||
/**
|
||||
* Link to target filter view.
|
||||
*/
|
||||
private String targetfilterView = "";
|
||||
|
||||
/**
|
||||
* Link to documentation of rollout view.
|
||||
*/
|
||||
private String rolloutView = "";
|
||||
|
||||
public String getDeploymentView() {
|
||||
return deploymentView;
|
||||
}
|
||||
|
||||
public String getDistributionView() {
|
||||
return distributionView;
|
||||
}
|
||||
|
||||
public String getRolloutView() {
|
||||
return rolloutView;
|
||||
}
|
||||
|
||||
public String getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
public String getSecurity() {
|
||||
return security;
|
||||
}
|
||||
|
||||
public String getSystemConfigurationView() {
|
||||
return systemConfigurationView;
|
||||
}
|
||||
|
||||
public String getTargetfilterView() {
|
||||
return targetfilterView;
|
||||
}
|
||||
|
||||
public String getUploadView() {
|
||||
return uploadView;
|
||||
}
|
||||
|
||||
public void setDeploymentView(final String deploymentView) {
|
||||
this.deploymentView = deploymentView;
|
||||
}
|
||||
|
||||
public void setDistributionView(final String distributionView) {
|
||||
this.distributionView = distributionView;
|
||||
}
|
||||
|
||||
public void setRolloutView(final String rolloutView) {
|
||||
this.rolloutView = rolloutView;
|
||||
}
|
||||
|
||||
public void setRoot(final String root) {
|
||||
this.root = root;
|
||||
}
|
||||
|
||||
public void setSecurity(final String security) {
|
||||
this.security = security;
|
||||
}
|
||||
|
||||
public void setSystemConfigurationView(final String systemConfigurationView) {
|
||||
this.systemConfigurationView = systemConfigurationView;
|
||||
}
|
||||
|
||||
public void setTargetfilterView(final String targetfilterView) {
|
||||
this.targetfilterView = targetfilterView;
|
||||
}
|
||||
|
||||
public void setUploadView(final String uploadView) {
|
||||
this.uploadView = uploadView;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private final Documentation documentation = new Documentation();
|
||||
|
||||
/**
|
||||
* Link to product support.
|
||||
*/
|
||||
private String support = "";
|
||||
|
||||
/**
|
||||
* Link to request a system account, access.
|
||||
*/
|
||||
private String requestAccount = "";
|
||||
|
||||
/**
|
||||
* Link to user management.
|
||||
*/
|
||||
private String userManagement = "";
|
||||
|
||||
public Documentation getDocumentation() {
|
||||
return documentation;
|
||||
}
|
||||
|
||||
public String getRequestAccount() {
|
||||
return requestAccount;
|
||||
}
|
||||
|
||||
public String getSupport() {
|
||||
return support;
|
||||
}
|
||||
|
||||
public String getUserManagement() {
|
||||
return userManagement;
|
||||
}
|
||||
|
||||
public void setRequestAccount(final String requestAccount) {
|
||||
this.requestAccount = requestAccount;
|
||||
}
|
||||
|
||||
public void setSupport(final String support) {
|
||||
this.support = support;
|
||||
}
|
||||
|
||||
public void setUserManagement(final String userManagement) {
|
||||
this.userManagement = userManagement;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Configuration of login view.
|
||||
*
|
||||
*/
|
||||
public static class Login {
|
||||
|
||||
/**
|
||||
* Cookie configuration for login credential cookie.
|
||||
*
|
||||
*/
|
||||
public static class Cookie {
|
||||
/**
|
||||
* Secure cookie enabled.
|
||||
*/
|
||||
private boolean secure = true;
|
||||
|
||||
public boolean isSecure() {
|
||||
return secure;
|
||||
}
|
||||
|
||||
public void setSecure(final boolean secure) {
|
||||
this.secure = secure;
|
||||
}
|
||||
}
|
||||
|
||||
private final Cookie cookie = new Cookie();
|
||||
|
||||
public Cookie getCookie() {
|
||||
return cookie;
|
||||
}
|
||||
}
|
||||
|
||||
private final Links links = new Links();
|
||||
|
||||
private final Login login = new Login();
|
||||
|
||||
private final Demo demo = new Demo();
|
||||
|
||||
public Demo getDemo() {
|
||||
return demo;
|
||||
}
|
||||
|
||||
public Links getLinks() {
|
||||
return links;
|
||||
}
|
||||
|
||||
public Login getLogin() {
|
||||
return login;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,273 +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.artifacts;
|
||||
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import org.eclipse.hawkbit.repository.SpPermissionChecker;
|
||||
import org.eclipse.hawkbit.ui.HawkbitUI;
|
||||
import org.eclipse.hawkbit.ui.artifacts.details.ArtifactDetailsLayout;
|
||||
import org.eclipse.hawkbit.ui.artifacts.event.ArtifactDetailsEvent;
|
||||
import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent;
|
||||
import org.eclipse.hawkbit.ui.artifacts.footer.SMDeleteActionsLayout;
|
||||
import org.eclipse.hawkbit.ui.artifacts.smtable.SoftwareModuleTableLayout;
|
||||
import org.eclipse.hawkbit.ui.artifacts.smtype.SMTypeFilterLayout;
|
||||
import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState;
|
||||
import org.eclipse.hawkbit.ui.artifacts.upload.UploadLayout;
|
||||
import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType;
|
||||
import org.eclipse.hawkbit.ui.management.event.DragEvent;
|
||||
import org.eclipse.hawkbit.ui.utils.I18N;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.UINotification;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.vaadin.spring.events.EventBus;
|
||||
import org.vaadin.spring.events.EventScope;
|
||||
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
|
||||
|
||||
import com.vaadin.event.MouseEvents.ClickListener;
|
||||
import com.vaadin.navigator.View;
|
||||
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
|
||||
import com.vaadin.server.Page;
|
||||
import com.vaadin.server.Page.BrowserWindowResizeEvent;
|
||||
import com.vaadin.server.Page.BrowserWindowResizeListener;
|
||||
import com.vaadin.spring.annotation.SpringView;
|
||||
import com.vaadin.spring.annotation.ViewScope;
|
||||
import com.vaadin.ui.Alignment;
|
||||
import com.vaadin.ui.DragAndDropWrapper;
|
||||
import com.vaadin.ui.GridLayout;
|
||||
import com.vaadin.ui.HorizontalLayout;
|
||||
import com.vaadin.ui.UI;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
|
||||
/**
|
||||
* Display artifacts upload view.
|
||||
*
|
||||
*
|
||||
*/
|
||||
@SpringView(name = UploadArtifactView.VIEW_NAME, ui = HawkbitUI.class)
|
||||
@ViewScope
|
||||
public class UploadArtifactView extends VerticalLayout implements View, BrowserWindowResizeListener {
|
||||
|
||||
public static final String VIEW_NAME = "spUpload";
|
||||
private static final long serialVersionUID = 8754632011301553682L;
|
||||
|
||||
@Autowired
|
||||
private transient EventBus.SessionEventBus eventBus;
|
||||
|
||||
@Autowired
|
||||
private SpPermissionChecker permChecker;
|
||||
|
||||
@Autowired
|
||||
private I18N i18n;
|
||||
|
||||
@Autowired
|
||||
private transient UINotification uiNotification;
|
||||
|
||||
@Autowired
|
||||
private ArtifactUploadState artifactUploadState;
|
||||
|
||||
@Autowired
|
||||
private SMTypeFilterLayout filterByTypeLayout;
|
||||
|
||||
@Autowired
|
||||
private SoftwareModuleTableLayout smTableLayout;
|
||||
|
||||
@Autowired
|
||||
private ArtifactDetailsLayout artifactDetailsLayout;
|
||||
|
||||
@Autowired
|
||||
private UploadLayout uploadLayout;
|
||||
|
||||
@Autowired
|
||||
private SMDeleteActionsLayout deleteActionsLayout;
|
||||
|
||||
private VerticalLayout detailAndUploadLayout;
|
||||
|
||||
private HorizontalLayout uplaodButtonsLayout;
|
||||
|
||||
private GridLayout mainLayout;
|
||||
private DragAndDropWrapper dadw;
|
||||
|
||||
@Override
|
||||
public void enter(final ViewChangeEvent event) {
|
||||
buildLayout();
|
||||
restoreState();
|
||||
checkNoDataAvaialble();
|
||||
eventBus.subscribe(this);
|
||||
Page.getCurrent().addBrowserWindowResizeListener(this);
|
||||
showOrHideFilterButtons(Page.getCurrent().getBrowserWindowWidth());
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
void destroy() {
|
||||
eventBus.unsubscribe(this);
|
||||
}
|
||||
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void onEvent(final SoftwareModuleEvent event) {
|
||||
if (BaseEntityEventType.MINIMIZED == event.getEventType()) {
|
||||
minimizeSwTable();
|
||||
} else if (BaseEntityEventType.MAXIMIZED == event.getEventType()) {
|
||||
maximizeSwTable();
|
||||
}
|
||||
}
|
||||
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void onEvent(final ArtifactDetailsEvent event) {
|
||||
if (event == ArtifactDetailsEvent.MINIMIZED) {
|
||||
minimizeArtifactoryDetails();
|
||||
} else if (event == ArtifactDetailsEvent.MAXIMIZED) {
|
||||
maximizeArtifactoryDetails();
|
||||
}
|
||||
}
|
||||
|
||||
private void restoreState() {
|
||||
if (artifactUploadState.isSwModuleTableMaximized()) {
|
||||
maximizeSwTable();
|
||||
}
|
||||
if (artifactUploadState.isArtifactDetailsMaximized()) {
|
||||
maximizeArtifactoryDetails();
|
||||
}
|
||||
}
|
||||
|
||||
private void buildLayout() {
|
||||
if (permChecker.hasReadDistributionPermission() || permChecker.hasCreateDistributionPermission()) {
|
||||
setSizeFull();
|
||||
createMainLayout();
|
||||
addComponents(mainLayout);
|
||||
setExpandRatio(mainLayout, 1);
|
||||
hideDropHints();
|
||||
}
|
||||
}
|
||||
|
||||
private VerticalLayout createDetailsAndUploadLayout() {
|
||||
detailAndUploadLayout = new VerticalLayout();
|
||||
|
||||
detailAndUploadLayout.addComponent(artifactDetailsLayout);
|
||||
detailAndUploadLayout.setComponentAlignment(artifactDetailsLayout, Alignment.MIDDLE_CENTER);
|
||||
|
||||
if (permChecker.hasCreateDistributionPermission()) {
|
||||
dadw = uploadLayout.getDropAreaWrapper();
|
||||
detailAndUploadLayout.addComponent(dadw);
|
||||
detailAndUploadLayout.setComponentAlignment(dadw, Alignment.MIDDLE_CENTER);
|
||||
}
|
||||
|
||||
detailAndUploadLayout.setExpandRatio(artifactDetailsLayout, 1.0f);
|
||||
detailAndUploadLayout.setSizeFull();
|
||||
detailAndUploadLayout.addStyleName("group");
|
||||
detailAndUploadLayout.setSpacing(true);
|
||||
return detailAndUploadLayout;
|
||||
|
||||
}
|
||||
|
||||
private GridLayout createMainLayout() {
|
||||
createDetailsAndUploadLayout();
|
||||
createUploadButtonLayout();
|
||||
mainLayout = new GridLayout(3, 2);
|
||||
mainLayout.setSizeFull();
|
||||
mainLayout.setSpacing(true);
|
||||
mainLayout.addComponent(filterByTypeLayout, 0, 0);
|
||||
mainLayout.addComponent(smTableLayout, 1, 0);
|
||||
mainLayout.addComponent(detailAndUploadLayout, 2, 0);
|
||||
mainLayout.addComponent(deleteActionsLayout, 1, 1);
|
||||
mainLayout.addComponent(uplaodButtonsLayout, 2, 1);
|
||||
mainLayout.setRowExpandRatio(0, 1.0f);
|
||||
mainLayout.setColumnExpandRatio(1, 0.5f);
|
||||
mainLayout.setColumnExpandRatio(2, 0.5f);
|
||||
mainLayout.setComponentAlignment(deleteActionsLayout, Alignment.BOTTOM_CENTER);
|
||||
mainLayout.setComponentAlignment(uplaodButtonsLayout, Alignment.BOTTOM_CENTER);
|
||||
return mainLayout;
|
||||
}
|
||||
|
||||
private void createUploadButtonLayout() {
|
||||
uplaodButtonsLayout = new HorizontalLayout();
|
||||
if (permChecker.hasCreateDistributionPermission()) {
|
||||
uplaodButtonsLayout = uploadLayout.getFileUploadLayout();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void minimizeSwTable() {
|
||||
mainLayout.addComponent(detailAndUploadLayout, 2, 0);
|
||||
addOtherComponents();
|
||||
}
|
||||
|
||||
private void maximizeSwTable() {
|
||||
mainLayout.removeComponent(detailAndUploadLayout);
|
||||
removeOtherComponents();
|
||||
mainLayout.setColumnExpandRatio(1, 1f);
|
||||
mainLayout.setColumnExpandRatio(2, 0f);
|
||||
}
|
||||
|
||||
private void minimizeArtifactoryDetails() {
|
||||
mainLayout.setSpacing(true);
|
||||
detailAndUploadLayout.addComponent(dadw);
|
||||
mainLayout.addComponent(filterByTypeLayout, 0, 0);
|
||||
mainLayout.addComponent(smTableLayout, 1, 0);
|
||||
addOtherComponents();
|
||||
}
|
||||
|
||||
private void maximizeArtifactoryDetails() {
|
||||
mainLayout.setSpacing(false);
|
||||
mainLayout.removeComponent(filterByTypeLayout);
|
||||
mainLayout.removeComponent(smTableLayout);
|
||||
detailAndUploadLayout.removeComponent(dadw);
|
||||
removeOtherComponents();
|
||||
mainLayout.setColumnExpandRatio(1, 0f);
|
||||
mainLayout.setColumnExpandRatio(2, 1f);
|
||||
}
|
||||
|
||||
private void addOtherComponents() {
|
||||
mainLayout.addComponent(deleteActionsLayout, 1, 1);
|
||||
mainLayout.addComponent(uplaodButtonsLayout, 2, 1);
|
||||
mainLayout.setColumnExpandRatio(1, 0.5f);
|
||||
mainLayout.setColumnExpandRatio(2, 0.5f);
|
||||
mainLayout.setComponentAlignment(deleteActionsLayout, Alignment.BOTTOM_CENTER);
|
||||
mainLayout.setComponentAlignment(uplaodButtonsLayout, Alignment.BOTTOM_CENTER);
|
||||
}
|
||||
|
||||
private void removeOtherComponents() {
|
||||
mainLayout.removeComponent(deleteActionsLayout);
|
||||
mainLayout.removeComponent(uplaodButtonsLayout);
|
||||
|
||||
}
|
||||
|
||||
private void hideDropHints() {
|
||||
UI.getCurrent().addClickListener(new ClickListener() {
|
||||
@Override
|
||||
public void click(final com.vaadin.event.MouseEvents.ClickEvent event) {
|
||||
eventBus.publish(this, DragEvent.HIDE_DROP_HINT);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void checkNoDataAvaialble() {
|
||||
if (artifactUploadState.isNoDataAvilableSoftwareModule()) {
|
||||
|
||||
uiNotification.displayValidationError(i18n.get("message.no.data"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void browserWindowResized(final BrowserWindowResizeEvent event) {
|
||||
showOrHideFilterButtons(event.getWidth());
|
||||
}
|
||||
|
||||
private void showOrHideFilterButtons(final int browserWidth) {
|
||||
if (browserWidth < SPUIDefinitions.REQ_MIN_BROWSER_WIDTH) {
|
||||
|
||||
filterByTypeLayout.setVisible(false);
|
||||
smTableLayout.setShowFilterButtonVisible(true);
|
||||
} else if (!artifactUploadState.isSwTypeFilterClosed()) {
|
||||
filterByTypeLayout.setVisible(true);
|
||||
smTableLayout.setShowFilterButtonVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,57 +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.artifacts;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
import org.eclipse.hawkbit.ui.menu.DashboardMenuItem;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.vaadin.server.FontAwesome;
|
||||
import com.vaadin.server.Resource;
|
||||
|
||||
/**
|
||||
* Display artifacts upload view menu item.
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
@Order(500)
|
||||
public class UploadArtifactViewMenuItem implements DashboardMenuItem {
|
||||
|
||||
private static final long serialVersionUID = 4096851897640769726L;
|
||||
|
||||
@Override
|
||||
public String getViewName() {
|
||||
return UploadArtifactView.VIEW_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resource getDashboardIcon() {
|
||||
return FontAwesome.UPLOAD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDashboardCaption() {
|
||||
return "Upload";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDashboardCaptionLong() {
|
||||
return "Upload Management";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getPermissions() {
|
||||
return Arrays.asList(SpPermission.CREATE_REPOSITORY, SpPermission.READ_REPOSITORY);
|
||||
}
|
||||
}
|
||||
@@ -1,118 +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.artifacts.details;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.hawkbit.repository.ArtifactManagement;
|
||||
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
|
||||
import org.eclipse.hawkbit.repository.model.LocalArtifact;
|
||||
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SpringContextHelper;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
import org.vaadin.addons.lazyquerycontainer.AbstractBeanQuery;
|
||||
import org.vaadin.addons.lazyquerycontainer.QueryDefinition;
|
||||
|
||||
/**
|
||||
* Simple implementation of generics bean query which dynamically loads artifact
|
||||
* beans.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ArtifactBeanQuery extends AbstractBeanQuery<LocalArtifact> {
|
||||
private static final long serialVersionUID = -333786310371208962L;
|
||||
private Sort sort = new Sort(Direction.DESC, "filename");
|
||||
private transient ArtifactManagement artifactManagement = null;
|
||||
private transient Page<LocalArtifact> firstPagetArtifacts = null;
|
||||
private Long baseSwModuleId = null;
|
||||
|
||||
/**
|
||||
* Parametric Constructor.
|
||||
*
|
||||
* @param definition
|
||||
* as Def
|
||||
* @param queryConfig
|
||||
* as Config
|
||||
* @param sortIds
|
||||
* as sort
|
||||
* @param sortStates
|
||||
* as Sort status
|
||||
*/
|
||||
public ArtifactBeanQuery(final QueryDefinition definition, final Map<String, Object> queryConfig,
|
||||
final Object[] sortIds, final boolean[] sortStates) {
|
||||
super(definition, queryConfig, sortIds, sortStates);
|
||||
|
||||
if (HawkbitCommonUtil.mapCheckStrKey(queryConfig)) {
|
||||
baseSwModuleId = (Long) queryConfig.get(SPUIDefinitions.BY_BASE_SOFTWARE_MODULE);
|
||||
}
|
||||
|
||||
if (HawkbitCommonUtil.checkBolArray(sortStates)) {
|
||||
// Initalize Sor
|
||||
sort = new Sort(sortStates[0] ? Direction.ASC : Direction.DESC, (String) sortIds[0]);
|
||||
// Add sort.
|
||||
for (int targetId = 1; targetId < sortIds.length; targetId++) {
|
||||
sort.and(new Sort(sortStates[targetId] ? Direction.ASC : Direction.DESC, (String) sortIds[targetId]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LocalArtifact constructBean() {
|
||||
return new LocalArtifact();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<LocalArtifact> loadBeans(final int startIndex, final int count) {
|
||||
Page<LocalArtifact> artifactBeans;
|
||||
if (startIndex == 0 && firstPagetArtifacts != null) {
|
||||
artifactBeans = firstPagetArtifacts;
|
||||
} else {
|
||||
artifactBeans = getArtifactManagement().findLocalArtifactBySoftwareModule(
|
||||
new OffsetBasedPageRequest(startIndex, count, sort), baseSwModuleId);
|
||||
}
|
||||
|
||||
return artifactBeans.getContent();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveBeans(final List<LocalArtifact> addedTargets, final List<LocalArtifact> modifiedTargets,
|
||||
final List<LocalArtifact> removedTargets) {
|
||||
// CRUD operations on Target will be done through repository methods
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
long size = 0;
|
||||
if (baseSwModuleId != null) {
|
||||
firstPagetArtifacts = getArtifactManagement().findLocalArtifactBySoftwareModule(
|
||||
new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort), baseSwModuleId);
|
||||
size = firstPagetArtifacts.getTotalElements();
|
||||
}
|
||||
if (size > Integer.MAX_VALUE) {
|
||||
size = Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
return (int) size;
|
||||
}
|
||||
|
||||
private ArtifactManagement getArtifactManagement() {
|
||||
if (artifactManagement == null) {
|
||||
artifactManagement = SpringContextHelper.getBean(ArtifactManagement.class);
|
||||
}
|
||||
return artifactManagement;
|
||||
}
|
||||
}
|
||||
@@ -1,519 +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.artifacts.details;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import org.eclipse.hawkbit.repository.ArtifactManagement;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.ui.artifacts.event.ArtifactDetailsEvent;
|
||||
import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent;
|
||||
import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType;
|
||||
import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState;
|
||||
import org.eclipse.hawkbit.ui.common.ConfirmationDialog;
|
||||
import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType;
|
||||
import org.eclipse.hawkbit.ui.components.SPUIButton;
|
||||
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
|
||||
import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder;
|
||||
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.I18N;
|
||||
import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SpringContextHelper;
|
||||
import org.eclipse.hawkbit.ui.utils.UINotification;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory;
|
||||
import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer;
|
||||
import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition;
|
||||
import org.vaadin.spring.events.EventBus;
|
||||
import org.vaadin.spring.events.EventScope;
|
||||
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.vaadin.data.Container;
|
||||
import com.vaadin.server.FontAwesome;
|
||||
import com.vaadin.shared.ui.label.ContentMode;
|
||||
import com.vaadin.spring.annotation.SpringComponent;
|
||||
import com.vaadin.spring.annotation.ViewScope;
|
||||
import com.vaadin.ui.Alignment;
|
||||
import com.vaadin.ui.Button;
|
||||
import com.vaadin.ui.HorizontalLayout;
|
||||
import com.vaadin.ui.Label;
|
||||
import com.vaadin.ui.Table;
|
||||
import com.vaadin.ui.Table.ColumnGenerator;
|
||||
import com.vaadin.ui.Table.TableDragMode;
|
||||
import com.vaadin.ui.UI;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
import com.vaadin.ui.themes.ValoTheme;
|
||||
|
||||
/**
|
||||
* Display the details of the artifacts for a selected software module.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
@SpringComponent
|
||||
@ViewScope
|
||||
public class ArtifactDetailsLayout extends VerticalLayout {
|
||||
|
||||
private static final long serialVersionUID = -5189069028037133891L;
|
||||
|
||||
private static final String PROVIDED_FILE_NAME = "filename";
|
||||
|
||||
private static final String LAST_MODIFIED_DATE = "lastModifiedAt";
|
||||
|
||||
private static final String CREATE_MODIFIED_DATE_UPLOAD = "Created/Modified Date";
|
||||
|
||||
private static final String ACTION = "action";
|
||||
|
||||
private static final String CREATED_DATE = "createdAt";
|
||||
|
||||
private static final String SIZE = "size";
|
||||
|
||||
private static final String SHA1HASH = "sha1Hash";
|
||||
|
||||
private static final String MD5HASH = "md5Hash";
|
||||
|
||||
@Autowired
|
||||
private I18N i18n;
|
||||
|
||||
@Autowired
|
||||
private transient EventBus.SessionEventBus eventBus;
|
||||
|
||||
@Autowired
|
||||
private ArtifactUploadState artifactUploadState;
|
||||
|
||||
@Autowired
|
||||
private transient UINotification uINotification;
|
||||
|
||||
private Label titleOfArtifactDetails;
|
||||
|
||||
private SPUIButton maxMinButton;
|
||||
|
||||
private Table artifactDetailsTable;
|
||||
|
||||
private Table maxArtifactDetailsTable;
|
||||
|
||||
private boolean fullWindowMode = false;
|
||||
|
||||
private boolean readOnly = false;
|
||||
|
||||
/**
|
||||
* Initialize the artifact details layout.
|
||||
*/
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
createComponents();
|
||||
buildLayout();
|
||||
eventBus.subscribe(this);
|
||||
if (artifactUploadState.getSelectedBaseSoftwareModule().isPresent()) {
|
||||
final SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get();
|
||||
populateArtifactDetails(selectedSoftwareModule.getId(), HawkbitCommonUtil
|
||||
.getFormattedNameVersion(selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion()));
|
||||
}
|
||||
if (isMaximized()) {
|
||||
maximizedArtifactDetailsView();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the artifact details layout in readonly mode (will not show
|
||||
* the delete icon) .
|
||||
*
|
||||
* @param readOnly
|
||||
* value true for read only.
|
||||
*/
|
||||
public void init(final boolean readOnly) {
|
||||
this.readOnly = readOnly;
|
||||
init();
|
||||
}
|
||||
|
||||
private void createComponents() {
|
||||
String labelStr = "";
|
||||
if (artifactUploadState.getSelectedBaseSoftwareModule().isPresent()) {
|
||||
final SoftwareModule softwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get();
|
||||
labelStr = HawkbitCommonUtil.getFormattedNameVersion(softwareModule.getName(), softwareModule.getVersion());
|
||||
}
|
||||
titleOfArtifactDetails = SPUIComponentProvider.getLabel(
|
||||
HawkbitCommonUtil.getArtifactoryDetailsLabelId(labelStr), SPUILabelDefinitions.SP_WIDGET_CAPTION);
|
||||
titleOfArtifactDetails.setContentMode(ContentMode.HTML);
|
||||
titleOfArtifactDetails.setSizeFull();
|
||||
titleOfArtifactDetails.setImmediate(true);
|
||||
maxMinButton = createMaxMinButton();
|
||||
|
||||
artifactDetailsTable = createArtifactDetailsTable();
|
||||
|
||||
artifactDetailsTable.setContainerDataSource(createArtifactLazyQueryContainer());
|
||||
addGeneratedColumn(artifactDetailsTable);
|
||||
if (!readOnly) {
|
||||
addGeneratedColumnButton(artifactDetailsTable);
|
||||
}
|
||||
setTableColumnDetails(artifactDetailsTable);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
private SPUIButton createMaxMinButton() {
|
||||
final SPUIButton button = (SPUIButton) SPUIComponentProvider.getButton(SPUIDefinitions.EXPAND_ACTION_HISTORY,
|
||||
"", "", null, true, FontAwesome.EXPAND, SPUIButtonStyleSmallNoBorder.class);
|
||||
button.addClickListener(event -> maxArtifactDetails());
|
||||
return button;
|
||||
}
|
||||
|
||||
private void buildLayout() {
|
||||
|
||||
final HorizontalLayout header = new HorizontalLayout();
|
||||
header.addStyleName("artifact-details-header");
|
||||
header.addStyleName("bordered-layout");
|
||||
header.addStyleName("no-border-bottom");
|
||||
header.setSpacing(false);
|
||||
header.setMargin(false);
|
||||
header.setSizeFull();
|
||||
header.setHeightUndefined();
|
||||
header.setImmediate(true);
|
||||
header.addComponents(titleOfArtifactDetails, maxMinButton);
|
||||
header.setComponentAlignment(titleOfArtifactDetails, Alignment.TOP_LEFT);
|
||||
header.setComponentAlignment(maxMinButton, Alignment.TOP_RIGHT);
|
||||
header.setExpandRatio(titleOfArtifactDetails, 1.0f);
|
||||
|
||||
setSizeFull();
|
||||
setImmediate(true);
|
||||
addStyleName("artifact-table");
|
||||
addStyleName("table-layout");
|
||||
addComponent(header);
|
||||
setComponentAlignment(header, Alignment.MIDDLE_CENTER);
|
||||
addComponent(artifactDetailsTable);
|
||||
setComponentAlignment(artifactDetailsTable, Alignment.MIDDLE_CENTER);
|
||||
setExpandRatio(artifactDetailsTable, 1.0f);
|
||||
|
||||
}
|
||||
|
||||
private Container createArtifactLazyQueryContainer() {
|
||||
final Map<String, Object> queryConfiguration = new HashMap<>();
|
||||
return getArtifactLazyQueryContainer(queryConfiguration);
|
||||
}
|
||||
|
||||
private LazyQueryContainer getArtifactLazyQueryContainer(final Map<String, Object> queryConfig) {
|
||||
|
||||
final BeanQueryFactory<ArtifactBeanQuery> artifactQF = new BeanQueryFactory<>(ArtifactBeanQuery.class);
|
||||
artifactQF.setQueryConfiguration(queryConfig);
|
||||
final LazyQueryContainer artifactCont = new LazyQueryContainer(new LazyQueryDefinition(true, 10, "id"),
|
||||
artifactQF);
|
||||
addArtifactTableProperties(artifactCont);
|
||||
return artifactCont;
|
||||
}
|
||||
|
||||
private void addArtifactTableProperties(final LazyQueryContainer artifactCont) {
|
||||
artifactCont.addContainerProperty(PROVIDED_FILE_NAME, Label.class, "", false, false);
|
||||
artifactCont.addContainerProperty(SIZE, Long.class, null, false, false);
|
||||
artifactCont.addContainerProperty(SHA1HASH, String.class, null, false, false);
|
||||
artifactCont.addContainerProperty(MD5HASH, String.class, null, false, false);
|
||||
artifactCont.addContainerProperty(CREATED_DATE, Date.class, null, false, false);
|
||||
artifactCont.addContainerProperty(LAST_MODIFIED_DATE, Date.class, null, false, false);
|
||||
if (!readOnly) {
|
||||
artifactCont.addContainerProperty(ACTION, Label.class, null, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void addGeneratedColumn(final Table table) {
|
||||
table.addGeneratedColumn(CREATE_MODIFIED_DATE_UPLOAD, new ColumnGenerator() {
|
||||
private static final long serialVersionUID = -866800417175863258L;
|
||||
|
||||
@Override
|
||||
public String generateCell(final Table source, final Object itemId, final Object columnId) {
|
||||
final Long createdDate = (Long) table.getContainerDataSource().getItem(itemId)
|
||||
.getItemProperty(CREATED_DATE).getValue();
|
||||
final Long modifiedDATE = (Long) table.getContainerDataSource().getItem(itemId)
|
||||
.getItemProperty(LAST_MODIFIED_DATE).getValue();
|
||||
if (modifiedDATE != null) {
|
||||
return SPDateTimeUtil.getFormattedDate(modifiedDATE);
|
||||
}
|
||||
return SPDateTimeUtil.getFormattedDate(createdDate);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void addGeneratedColumnButton(final Table table) {
|
||||
table.addGeneratedColumn(ACTION, new ColumnGenerator() {
|
||||
private static final long serialVersionUID = -866800417175863258L;
|
||||
|
||||
@Override
|
||||
public Button generateCell(final Table source, final Object itemId, final Object columnId) {
|
||||
final String fileName = (String) table.getContainerDataSource().getItem(itemId)
|
||||
.getItemProperty(PROVIDED_FILE_NAME).getValue();
|
||||
final Button deleteIcon = SPUIComponentProvider.getButton(
|
||||
fileName + "-" + SPUIComponetIdProvider.UPLOAD_FILE_DELETE_ICON, "",
|
||||
SPUILabelDefinitions.DISCARD, ValoTheme.BUTTON_TINY + " " + "redicon", true,
|
||||
FontAwesome.TRASH_O, SPUIButtonStyleSmallNoBorder.class);
|
||||
deleteIcon.setData(itemId);
|
||||
deleteIcon.addClickListener(event -> confirmAndDeleteArtifact((Long) itemId, fileName));
|
||||
return deleteIcon;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void confirmAndDeleteArtifact(final Long id, final String fileName) {
|
||||
|
||||
final ConfirmationDialog confirmDialog = new ConfirmationDialog(i18n.get("caption.delete.artifact.confirmbox"),
|
||||
i18n.get("message.delete.artifact", new Object[] { fileName }), i18n.get("button.ok"),
|
||||
i18n.get("button.cancel"), ok -> {
|
||||
if (ok) {
|
||||
final ArtifactManagement artifactManagement = SpringContextHelper
|
||||
.getBean(ArtifactManagement.class);
|
||||
artifactManagement.deleteLocalArtifact(id);
|
||||
uINotification.displaySuccess(i18n.get("message.artifact.deleted", fileName));
|
||||
if (artifactUploadState.getSelectedBaseSwModuleId().isPresent()) {
|
||||
populateArtifactDetails(artifactUploadState.getSelectedBaseSwModuleId().get(),
|
||||
HawkbitCommonUtil.getFormattedNameVersion(
|
||||
artifactUploadState.getSelectedBaseSoftwareModule().get().getName(),
|
||||
artifactUploadState.getSelectedBaseSoftwareModule().get().getVersion()));
|
||||
} else {
|
||||
populateArtifactDetails(null, null);
|
||||
}
|
||||
}
|
||||
});
|
||||
UI.getCurrent().addWindow(confirmDialog.getWindow());
|
||||
confirmDialog.getWindow().bringToFront();
|
||||
|
||||
}
|
||||
|
||||
private void setTableColumnDetails(final Table table) {
|
||||
|
||||
table.setColumnHeader(PROVIDED_FILE_NAME, i18n.get("upload.file.name"));
|
||||
table.setColumnHeader(SIZE, i18n.get("upload.size"));
|
||||
if (fullWindowMode) {
|
||||
table.setColumnHeader(SHA1HASH, i18n.get("upload.sha1"));
|
||||
table.setColumnHeader(MD5HASH, i18n.get("upload.md5"));
|
||||
}
|
||||
table.setColumnHeader(CREATE_MODIFIED_DATE_UPLOAD, i18n.get("upload.last.modified.date"));
|
||||
if (!readOnly) {
|
||||
table.setColumnHeader(ACTION, i18n.get("upload.action"));
|
||||
}
|
||||
|
||||
table.setColumnExpandRatio(PROVIDED_FILE_NAME, 3.5f);
|
||||
table.setColumnExpandRatio(SIZE, 2f);
|
||||
if (fullWindowMode) {
|
||||
table.setColumnExpandRatio(SHA1HASH, 2.8f);
|
||||
table.setColumnExpandRatio(MD5HASH, 2.4f);
|
||||
}
|
||||
table.setColumnExpandRatio(CREATE_MODIFIED_DATE_UPLOAD, 3f);
|
||||
if (!readOnly) {
|
||||
table.setColumnExpandRatio(ACTION, 2.5f);
|
||||
}
|
||||
|
||||
table.setVisibleColumns(getVisbleColumns().toArray());
|
||||
}
|
||||
|
||||
private List<Object> getVisbleColumns() {
|
||||
final List<Object> visibileColumn = new ArrayList<>();
|
||||
visibileColumn.add(PROVIDED_FILE_NAME);
|
||||
visibileColumn.add(SIZE);
|
||||
if (fullWindowMode) {
|
||||
visibileColumn.add(SHA1HASH);
|
||||
visibileColumn.add(MD5HASH);
|
||||
}
|
||||
visibileColumn.add(CREATE_MODIFIED_DATE_UPLOAD);
|
||||
if (!readOnly) {
|
||||
visibileColumn.add(ACTION);
|
||||
}
|
||||
return visibileColumn;
|
||||
}
|
||||
|
||||
private Table createArtifactDetailsTable() {
|
||||
final Table detailsTable = new Table();
|
||||
detailsTable.addStyleName("sp-table");
|
||||
|
||||
detailsTable.setImmediate(true);
|
||||
detailsTable.setSizeFull();
|
||||
|
||||
detailsTable.setId(SPUIComponetIdProvider.UPLOAD_ARTIFACT_DETAILS_TABLE);
|
||||
detailsTable.addStyleName(ValoTheme.TABLE_NO_VERTICAL_LINES);
|
||||
detailsTable.addStyleName(ValoTheme.TABLE_SMALL);
|
||||
return detailsTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* will be used by button click listener of action history expand icon.
|
||||
*/
|
||||
private void maxArtifactDetails() {
|
||||
final Boolean flag = (Boolean) maxMinButton.getData();
|
||||
if (flag == null || Boolean.FALSE.equals(flag)) {
|
||||
// Clicked on max Button
|
||||
maximizedArtifactDetailsView();
|
||||
} else {
|
||||
// Clicked on min Button
|
||||
minimizeArtifactDetailsView();
|
||||
}
|
||||
}
|
||||
|
||||
private void minimizeArtifactDetailsView() {
|
||||
fullWindowMode = Boolean.FALSE;
|
||||
showMaxIcon();
|
||||
setTableColumnDetails(artifactDetailsTable);
|
||||
createArtifactDetailsMinView();
|
||||
|
||||
}
|
||||
|
||||
private void maximizedArtifactDetailsView() {
|
||||
fullWindowMode = Boolean.TRUE;
|
||||
showMinIcon();
|
||||
setTableColumnDetails(artifactDetailsTable);
|
||||
createArtifactDetailsMaxView();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Max artifact details Table.
|
||||
*/
|
||||
public void createMaxArtifactDetailsTable() {
|
||||
maxArtifactDetailsTable = createArtifactDetailsTable();
|
||||
maxArtifactDetailsTable.setId(SPUIComponetIdProvider.UPLOAD_ARTIFACT_DETAILS_TABLE_MAX);
|
||||
maxArtifactDetailsTable.setContainerDataSource(artifactDetailsTable.getContainerDataSource());
|
||||
addGeneratedColumn(maxArtifactDetailsTable);
|
||||
if (!readOnly) {
|
||||
addGeneratedColumnButton(maxArtifactDetailsTable);
|
||||
}
|
||||
setTableColumnDetails(maxArtifactDetailsTable);
|
||||
}
|
||||
|
||||
private void createArtifactDetailsMaxView() {
|
||||
|
||||
artifactDetailsTable.setValue(null);
|
||||
artifactDetailsTable.setSelectable(false);
|
||||
artifactDetailsTable.setMultiSelect(false);
|
||||
artifactDetailsTable.setDragMode(TableDragMode.NONE);
|
||||
artifactDetailsTable.setColumnCollapsingAllowed(true);
|
||||
artifactUploadState.setArtifactDetailsMaximized(Boolean.TRUE);
|
||||
eventBus.publish(this, ArtifactDetailsEvent.MAXIMIZED);
|
||||
}
|
||||
|
||||
private void createArtifactDetailsMinView() {
|
||||
artifactUploadState.setArtifactDetailsMaximized(Boolean.FALSE);
|
||||
artifactDetailsTable.setColumnCollapsingAllowed(false);
|
||||
eventBus.publish(this, ArtifactDetailsEvent.MINIMIZED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate artifact details.
|
||||
*
|
||||
* @param baseSwModuleId
|
||||
* software module id
|
||||
* @param swModuleName
|
||||
* software module name
|
||||
*/
|
||||
public void populateArtifactDetails(final Long baseSwModuleId, final String swModuleName) {
|
||||
if (!readOnly) {
|
||||
if (Strings.isNullOrEmpty(swModuleName)) {
|
||||
setTitleOfLayoutHeader();
|
||||
} else {
|
||||
titleOfArtifactDetails.setValue(HawkbitCommonUtil.getArtifactoryDetailsLabelId(swModuleName));
|
||||
titleOfArtifactDetails.setContentMode(ContentMode.HTML);
|
||||
}
|
||||
}
|
||||
final Map<String, Object> queryConfiguration = new HashMap<>();
|
||||
if (baseSwModuleId != null) {
|
||||
queryConfiguration.put(SPUIDefinitions.BY_BASE_SOFTWARE_MODULE, baseSwModuleId);
|
||||
}
|
||||
final LazyQueryContainer artifactContainer = getArtifactLazyQueryContainer(queryConfiguration);
|
||||
artifactDetailsTable.setContainerDataSource(artifactContainer);
|
||||
if (fullWindowMode && maxArtifactDetailsTable != null) {
|
||||
maxArtifactDetailsTable.setContainerDataSource(artifactContainer);
|
||||
}
|
||||
setTableColumnDetails(artifactDetailsTable);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set title of artifact details header layout.
|
||||
*/
|
||||
public void setTitleOfLayoutHeader() {
|
||||
titleOfArtifactDetails.setValue(HawkbitCommonUtil.getArtifactoryDetailsLabelId(""));
|
||||
titleOfArtifactDetails.setContentMode(ContentMode.HTML);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close artifact details layout.
|
||||
*/
|
||||
public void closeArtifactDetails() {
|
||||
removeAllComponents();
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void onEvent(final SoftwareModuleEvent softwareModuleEvent) {
|
||||
if (BaseEntityEventType.SELECTED_ENTITY == softwareModuleEvent.getEventType()) {
|
||||
UI.getCurrent().access(() -> {
|
||||
if (softwareModuleEvent.getEntity() != null) {
|
||||
populateArtifactDetails(softwareModuleEvent.getEntity().getId(),
|
||||
HawkbitCommonUtil.getFormattedNameVersion(softwareModuleEvent.getEntity().getName(),
|
||||
softwareModuleEvent.getEntity().getVersion()));
|
||||
} else {
|
||||
populateArtifactDetails(null, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (softwareModuleEvent.getSoftwareModuleEventType() == SoftwareModuleEventType.ARTIFACTS_CHANGED) {
|
||||
UI.getCurrent().access(() -> {
|
||||
if (softwareModuleEvent.getEntity() != null) {
|
||||
populateArtifactDetails(softwareModuleEvent.getEntity().getId(),
|
||||
HawkbitCommonUtil.getFormattedNameVersion(softwareModuleEvent.getEntity().getName(),
|
||||
softwareModuleEvent.getEntity().getVersion()));
|
||||
} else {
|
||||
populateArtifactDetails(null, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
void destroy() {
|
||||
eventBus.unsubscribe(this); // It's good manners to do this, even though
|
||||
// we should be
|
||||
// automatically unsubscribed when the UI is
|
||||
// garbage collected
|
||||
}
|
||||
|
||||
public Table getArtifactDetailsTable() {
|
||||
return artifactDetailsTable;
|
||||
}
|
||||
|
||||
public Table getMaxArtifactDetailsTable() {
|
||||
return maxArtifactDetailsTable;
|
||||
}
|
||||
|
||||
public void setFullWindowMode(final boolean fullWindowMode) {
|
||||
this.fullWindowMode = fullWindowMode;
|
||||
}
|
||||
|
||||
private void showMinIcon() {
|
||||
maxMinButton.togleIcon(FontAwesome.COMPRESS);
|
||||
maxMinButton.setData(Boolean.TRUE);
|
||||
}
|
||||
|
||||
private void showMaxIcon() {
|
||||
maxMinButton.togleIcon(FontAwesome.EXPAND);
|
||||
maxMinButton.setData(Boolean.FALSE);
|
||||
}
|
||||
|
||||
private boolean isMaximized() {
|
||||
return artifactUploadState.isArtifactDetailsMaximized();
|
||||
}
|
||||
}
|
||||
@@ -1,18 +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.artifacts.event;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public enum ArtifactDetailsEvent {
|
||||
MAXIMIZED, MINIMIZED,
|
||||
|
||||
}
|
||||
@@ -1,26 +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.artifacts.event;
|
||||
|
||||
/**
|
||||
* Software module filter events.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public enum SMFilterEvent {
|
||||
|
||||
FILTER_BY_TYPE,
|
||||
|
||||
FILTER_BY_TEXT,
|
||||
|
||||
REMOVER_FILTER_BY_TYPE,
|
||||
|
||||
REMOVER_FILTER_BY_TEXT
|
||||
}
|
||||
@@ -1,61 +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.artifacts.event;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.ui.common.table.BaseEntityEvent;
|
||||
import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType;
|
||||
|
||||
/**
|
||||
* Event to represent software add, update or delete.
|
||||
*
|
||||
*/
|
||||
public class SoftwareModuleEvent extends BaseEntityEvent<SoftwareModule> {
|
||||
|
||||
/**
|
||||
* Software module events in the Upload UI.
|
||||
*
|
||||
*/
|
||||
public enum SoftwareModuleEventType {
|
||||
ARTIFACTS_CHANGED, ASSIGN_SOFTWARE_MODULE
|
||||
}
|
||||
|
||||
private SoftwareModuleEventType softwareModuleEventType;
|
||||
|
||||
/**
|
||||
* Creates software module event.
|
||||
*
|
||||
* @param entityEventType
|
||||
* the event type
|
||||
* @param softwareModule
|
||||
* the module
|
||||
*/
|
||||
public SoftwareModuleEvent(final BaseEntityEventType entityEventType, final SoftwareModule softwareModule) {
|
||||
super(entityEventType, softwareModule);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates software module event.
|
||||
*
|
||||
* @param softwareModuleEventType
|
||||
* the event type
|
||||
* @param softwareModule
|
||||
* the module
|
||||
*/
|
||||
public SoftwareModuleEvent(final SoftwareModuleEventType softwareModuleEventType,
|
||||
final SoftwareModule softwareModule) {
|
||||
super(null, softwareModule);
|
||||
this.softwareModuleEventType = softwareModuleEventType;
|
||||
}
|
||||
|
||||
public SoftwareModuleEventType getSoftwareModuleEventType() {
|
||||
return softwareModuleEventType;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,57 +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.artifacts.event;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
|
||||
/**
|
||||
* Event to represent software module type add, update or delete.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class SoftwareModuleTypeEvent {
|
||||
|
||||
/**
|
||||
* Software module type events in the Upload UI.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public enum SoftwareModuleTypeEnum {
|
||||
ADD_SOFTWARE_MODULE_TYPE, DELETE_SOFTWARE_MODULE_TYPE, UPDATE_SOFTWARE_MODULE_TYPE
|
||||
}
|
||||
|
||||
private SoftwareModuleType softwareModuleType;
|
||||
|
||||
private final SoftwareModuleTypeEnum softwareModuleTypeEnum;
|
||||
|
||||
/**
|
||||
* @param softwareModuleTypeEnum
|
||||
* @param softwareModuleType
|
||||
*/
|
||||
public SoftwareModuleTypeEvent(final SoftwareModuleTypeEnum softwareModuleTypeEnum,
|
||||
final SoftwareModuleType softwareModuleType) {
|
||||
this.softwareModuleTypeEnum = softwareModuleTypeEnum;
|
||||
this.softwareModuleType = softwareModuleType;
|
||||
}
|
||||
|
||||
public SoftwareModuleTypeEnum getSoftwareModuleTypeEnum() {
|
||||
return softwareModuleTypeEnum;
|
||||
}
|
||||
|
||||
public SoftwareModuleType getSoftwareModuleType() {
|
||||
return softwareModuleType;
|
||||
}
|
||||
|
||||
public void setSoftwareModuleType(final SoftwareModuleType softwareModuleType) {
|
||||
this.softwareModuleType = softwareModuleType;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +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.artifacts.event;
|
||||
|
||||
/**
|
||||
* Event generated in Upload artifact UI.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public enum UploadArtifactUIEvent {
|
||||
|
||||
SHOW_DROP_HINTS, HIDE_DROP_HINTS, SOFTWARE_DRAG_START, SOFTWARE_TYPE_DRAG_START, UPDATE_UPLOAD_COUNT, ENABLE_PROCESS_BUTTON, HIDE_FILTER_BY_TYPE, SHOW_FILTER_BY_TYPE, DISCARD_DELETE_SOFTWARE, DISCARD_ALL_DELETE_SOFTWARE, DELETED_ALL_SOFWARE, DISABLE_PROCESS_BUTTON, DISCARD_DELETE_SOFTWARE_TYPE, DISCARD_ALL_DELETE_SOFTWARE_TYPE, DELETED_ALL_SOFWARE_TYPE
|
||||
}
|
||||
@@ -1,71 +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.artifacts.event;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.hawkbit.ui.common.AbstractAcceptCriteria;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider;
|
||||
|
||||
import com.vaadin.spring.annotation.SpringComponent;
|
||||
import com.vaadin.spring.annotation.ViewScope;
|
||||
import com.vaadin.ui.Component;
|
||||
|
||||
/**
|
||||
* Upload UI View for Accept criteria.
|
||||
*
|
||||
*/
|
||||
@SpringComponent
|
||||
@ViewScope
|
||||
public class UploadViewAcceptCriteria extends AbstractAcceptCriteria {
|
||||
|
||||
private static final long serialVersionUID = 5158811326115667378L;
|
||||
|
||||
private static final Map<String, List<String>> DROP_CONFIGS = createDropConfigurations();
|
||||
|
||||
private static final Map<String, Object> DROP_HINTS_CONFIGS = createDropHintConfigurations();
|
||||
|
||||
@Override
|
||||
protected String getComponentId(final Component component) {
|
||||
String id = component.getId();
|
||||
if (id != null && id.startsWith(SPUIComponetIdProvider.UPLOAD_TYPE_BUTTON_PREFIX)) {
|
||||
id = SPUIComponetIdProvider.UPLOAD_TYPE_BUTTON_PREFIX;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> getDropHintConfigurations() {
|
||||
return DROP_HINTS_CONFIGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, List<String>> getDropConfigurations() {
|
||||
return DROP_CONFIGS;
|
||||
}
|
||||
|
||||
private static Map<String, List<String>> createDropConfigurations() {
|
||||
final Map<String, List<String>> config = new HashMap<>();
|
||||
// Delete drop area droppable components
|
||||
config.put(SPUIComponetIdProvider.DELETE_BUTTON_WRAPPER_ID, Arrays.asList(
|
||||
SPUIComponetIdProvider.UPLOAD_SOFTWARE_MODULE_TABLE, SPUIComponetIdProvider.UPLOAD_TYPE_BUTTON_PREFIX));
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
private static Map<String, Object> createDropHintConfigurations() {
|
||||
final Map<String, Object> config = new HashMap<>();
|
||||
config.put(SPUIComponetIdProvider.UPLOAD_TYPE_BUTTON_PREFIX, UploadArtifactUIEvent.SOFTWARE_TYPE_DRAG_START);
|
||||
config.put(SPUIComponetIdProvider.UPLOAD_SOFTWARE_MODULE_TABLE, UploadArtifactUIEvent.SOFTWARE_DRAG_START);
|
||||
return config;
|
||||
}
|
||||
}
|
||||
@@ -1,198 +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.artifacts.footer;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent;
|
||||
import org.eclipse.hawkbit.ui.artifacts.event.UploadViewAcceptCriteria;
|
||||
import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState;
|
||||
import org.eclipse.hawkbit.ui.common.footer.AbstractDeleteActionsLayout;
|
||||
import org.eclipse.hawkbit.ui.common.table.AbstractTable;
|
||||
import org.eclipse.hawkbit.ui.management.event.DragEvent;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.vaadin.spring.events.EventScope;
|
||||
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
|
||||
|
||||
import com.vaadin.event.dd.DragAndDropEvent;
|
||||
import com.vaadin.event.dd.acceptcriteria.AcceptCriterion;
|
||||
import com.vaadin.spring.annotation.SpringComponent;
|
||||
import com.vaadin.spring.annotation.ViewScope;
|
||||
import com.vaadin.ui.Component;
|
||||
import com.vaadin.ui.Table;
|
||||
import com.vaadin.ui.Table.TableTransferable;
|
||||
import com.vaadin.ui.UI;
|
||||
|
||||
/**
|
||||
* Upload view footer layout implementation.
|
||||
*
|
||||
*/
|
||||
@SpringComponent
|
||||
@ViewScope
|
||||
public class SMDeleteActionsLayout extends AbstractDeleteActionsLayout {
|
||||
|
||||
private static final long serialVersionUID = -3273982053389866299L;
|
||||
|
||||
@Autowired
|
||||
private ArtifactUploadState artifactUploadState;
|
||||
|
||||
@Autowired
|
||||
private UploadViewConfirmationWindowLayout uploadViewConfirmationWindowLayout;
|
||||
|
||||
@Autowired
|
||||
private UploadViewAcceptCriteria uploadViewAcceptCriteria;
|
||||
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void onEvent(final UploadArtifactUIEvent event) {
|
||||
|
||||
if (isSoftwareEvent(event) || isSoftwareTypeEvent(event)) {
|
||||
|
||||
UI.getCurrent().access(() -> {
|
||||
if (!hasUnsavedActions()) {
|
||||
closeUnsavedActionsWindow();
|
||||
final String message = uploadViewConfirmationWindowLayout.getConsolidatedMessage();
|
||||
if (message != null && message.length() > 0) {
|
||||
notification.displaySuccess(message);
|
||||
}
|
||||
}
|
||||
updateSWActionCount();
|
||||
});
|
||||
}
|
||||
if (event == UploadArtifactUIEvent.SOFTWARE_DRAG_START
|
||||
|| event == UploadArtifactUIEvent.SOFTWARE_TYPE_DRAG_START) {
|
||||
showDropHints();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isSoftwareEvent(final UploadArtifactUIEvent event) {
|
||||
return event == UploadArtifactUIEvent.DISCARD_ALL_DELETE_SOFTWARE
|
||||
|| event == UploadArtifactUIEvent.DELETED_ALL_SOFWARE
|
||||
|| event == UploadArtifactUIEvent.DISCARD_DELETE_SOFTWARE;
|
||||
}
|
||||
|
||||
private boolean isSoftwareTypeEvent(final UploadArtifactUIEvent event) {
|
||||
return event == UploadArtifactUIEvent.DISCARD_ALL_DELETE_SOFTWARE_TYPE
|
||||
|| event == UploadArtifactUIEvent.DELETED_ALL_SOFWARE_TYPE
|
||||
|| event == UploadArtifactUIEvent.DISCARD_DELETE_SOFTWARE_TYPE;
|
||||
}
|
||||
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void onEvent(final DragEvent event) {
|
||||
if (event == DragEvent.HIDE_DROP_HINT) {
|
||||
UI.getCurrent().access(() -> hideDropHints());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasDeletePermission() {
|
||||
return permChecker.hasDeleteDistributionPermission();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasUpdatePermission() {
|
||||
/**
|
||||
* Footer layout should be displayed only when software modeule has
|
||||
* delete permission.So update permission need not be checked in this
|
||||
* case.
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDeleteAreaLabel() {
|
||||
return i18n.get("label.software.module.drop.area");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDeleteAreaId() {
|
||||
return SPUIComponetIdProvider.DELETE_BUTTON_WRAPPER_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AcceptCriterion getDeleteLayoutAcceptCriteria() {
|
||||
return uploadViewAcceptCriteria;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processDroppedComponent(final DragAndDropEvent event) {
|
||||
final Component sourceComponent = event.getTransferable().getSourceComponent();
|
||||
if (sourceComponent instanceof Table) {
|
||||
final Table sourceTable = (Table) event.getTransferable().getSourceComponent();
|
||||
addToDeleteList(sourceTable, (TableTransferable) event.getTransferable());
|
||||
updateSWActionCount();
|
||||
}
|
||||
if (sourceComponent.getId().startsWith(SPUIComponetIdProvider.UPLOAD_TYPE_BUTTON_PREFIX)) {
|
||||
|
||||
final String swModuleTypeName = sourceComponent.getId()
|
||||
.replace(SPUIComponetIdProvider.UPLOAD_TYPE_BUTTON_PREFIX, "");
|
||||
if (artifactUploadState.getSoftwareModuleFilters().getSoftwareModuleType().isPresent()
|
||||
&& artifactUploadState.getSoftwareModuleFilters().getSoftwareModuleType().get().getName()
|
||||
.equalsIgnoreCase(swModuleTypeName)) {
|
||||
notification.displayValidationError(
|
||||
i18n.get("message.swmodule.type.check.delete", new Object[] { swModuleTypeName }));
|
||||
} else {
|
||||
deleteSWModuleType(swModuleTypeName);
|
||||
updateSWActionCount();
|
||||
}
|
||||
|
||||
}
|
||||
hideDropHints();
|
||||
}
|
||||
|
||||
private void deleteSWModuleType(final String swModuleTypeName) {
|
||||
artifactUploadState.getSelectedDeleteSWModuleTypes().add(swModuleTypeName);
|
||||
}
|
||||
|
||||
private void addToDeleteList(final Table sourceTable, final TableTransferable transferable) {
|
||||
@SuppressWarnings("unchecked")
|
||||
final AbstractTable<?, Long> swTable = (AbstractTable<?, Long>) sourceTable;
|
||||
final Set<Long> swModuleIdNameSet = swTable.getDeletedEntityByTransferable(transferable);
|
||||
|
||||
swModuleIdNameSet.forEach(id -> {
|
||||
final String swModuleName = (String) sourceTable.getContainerDataSource().getItem(id)
|
||||
.getItemProperty(SPUILabelDefinitions.NAME_VERSION).getValue();
|
||||
artifactUploadState.getDeleteSofwareModules().put(id, swModuleName);
|
||||
});
|
||||
}
|
||||
|
||||
private void updateSWActionCount() {
|
||||
final int count = artifactUploadState.getDeleteSofwareModules().size()
|
||||
+ artifactUploadState.getSelectedDeleteSWModuleTypes().size();
|
||||
updateActionsCount(count);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void restoreActionCount() {
|
||||
updateSWActionCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void unsavedActionsWindowClosed() {
|
||||
final String message = uploadViewConfirmationWindowLayout.getConsolidatedMessage();
|
||||
if (message != null && message.length() > 0) {
|
||||
notification.displaySuccess(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component getUnsavedActionsWindowContent() {
|
||||
uploadViewConfirmationWindowLayout.initialize();
|
||||
return uploadViewConfirmationWindowLayout;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasUnsavedActions() {
|
||||
return !artifactUploadState.getDeleteSofwareModules().isEmpty()
|
||||
|| !artifactUploadState.getSelectedDeleteSWModuleTypes().isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,260 +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.artifacts.footer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.hawkbit.repository.SoftwareManagement;
|
||||
import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent;
|
||||
import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState;
|
||||
import org.eclipse.hawkbit.ui.artifacts.state.CustomFile;
|
||||
import org.eclipse.hawkbit.ui.common.confirmwindow.layout.AbstractConfirmationWindowLayout;
|
||||
import org.eclipse.hawkbit.ui.common.confirmwindow.layout.ConfirmationTab;
|
||||
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.vaadin.data.Container;
|
||||
import com.vaadin.data.Item;
|
||||
import com.vaadin.data.util.IndexedContainer;
|
||||
import com.vaadin.server.FontAwesome;
|
||||
import com.vaadin.spring.annotation.SpringComponent;
|
||||
import com.vaadin.spring.annotation.ViewScope;
|
||||
import com.vaadin.ui.Button;
|
||||
import com.vaadin.ui.Button.ClickListener;
|
||||
import com.vaadin.ui.Table.Align;
|
||||
|
||||
/**
|
||||
* Abstract layout of confirm actions window.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@SpringComponent
|
||||
@ViewScope
|
||||
public class UploadViewConfirmationWindowLayout extends AbstractConfirmationWindowLayout {
|
||||
|
||||
private static final long serialVersionUID = 1804036019105286988L;
|
||||
|
||||
private static final String SW_MODULE_NAME_MSG = "SW MOdule Name";
|
||||
|
||||
private static final String SW_DISCARD_CHGS = "DiscardChanges";
|
||||
|
||||
private static final String SW_MODULE_TYPE_NAME = "SoftwareModuleTypeName";
|
||||
|
||||
private static final String DISCARD = "Discard";
|
||||
|
||||
@Autowired
|
||||
private transient SoftwareManagement softwareManagement;
|
||||
|
||||
@Autowired
|
||||
private ArtifactUploadState artifactUploadState;
|
||||
|
||||
@Override
|
||||
protected Map<String, ConfirmationTab> getConfimrationTabs() {
|
||||
final Map<String, ConfirmationTab> tabs = new HashMap<>();
|
||||
if (!artifactUploadState.getDeleteSofwareModules().isEmpty()) {
|
||||
tabs.put(i18n.get("caption.delete.swmodule.accordion.tab"), createSMDeleteConfirmationTab());
|
||||
}
|
||||
if (!artifactUploadState.getSelectedDeleteSWModuleTypes().isEmpty()) {
|
||||
tabs.put(i18n.get("caption.delete.sw.module.type.accordion.tab"), createSMtypeDeleteConfirmationTab());
|
||||
}
|
||||
return tabs;
|
||||
}
|
||||
|
||||
private ConfirmationTab createSMDeleteConfirmationTab() {
|
||||
final ConfirmationTab tab = new ConfirmationTab();
|
||||
|
||||
tab.getConfirmAll().setId(SPUIComponetIdProvider.SW_DELETE_ALL);
|
||||
tab.getConfirmAll().setIcon(FontAwesome.TRASH_O);
|
||||
tab.getConfirmAll().setCaption(i18n.get("button.delete.all"));
|
||||
tab.getConfirmAll().addClickListener(event -> deleteSMAll(tab));
|
||||
|
||||
tab.getDiscardAll().setCaption(i18n.get("button.discard.all"));
|
||||
tab.getDiscardAll().addClickListener(event -> discardSMAll(tab));
|
||||
|
||||
// Add items container to the table.
|
||||
tab.getTable().setContainerDataSource(getSWModuleTableContainer());
|
||||
|
||||
// Add the discard action column
|
||||
tab.getTable().addGeneratedColumn(SW_DISCARD_CHGS, (source, itemId, columnId) -> {
|
||||
final ClickListener clickListener = event -> discardSoftwareDelete(event, itemId, tab);
|
||||
return createDiscardButton(itemId, clickListener);
|
||||
});
|
||||
|
||||
tab.getTable().setVisibleColumns(SW_MODULE_NAME_MSG, SW_DISCARD_CHGS);
|
||||
tab.getTable().setColumnHeaders(i18n.get("upload.swModuleTable.header"),
|
||||
i18n.get("header.second.deletetarget.table"));
|
||||
|
||||
tab.getTable().setColumnExpandRatio(SW_MODULE_NAME_MSG, SPUIDefinitions.TARGET_DISTRIBUTION_COLUMN_WIDTH);
|
||||
tab.getTable().setColumnExpandRatio(SW_DISCARD_CHGS, SPUIDefinitions.DISCARD_COLUMN_WIDTH);
|
||||
tab.getTable().setColumnAlignment(SW_DISCARD_CHGS, Align.CENTER);
|
||||
return tab;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get SWModule table container.
|
||||
*
|
||||
* @return IndexedContainer
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private IndexedContainer getSWModuleTableContainer() {
|
||||
final IndexedContainer swcontactContainer = new IndexedContainer();
|
||||
swcontactContainer.addContainerProperty("SWModuleId", String.class, "");
|
||||
swcontactContainer.addContainerProperty(SW_MODULE_NAME_MSG, String.class, "");
|
||||
for (final Long swModuleID : artifactUploadState.getDeleteSofwareModules().keySet()) {
|
||||
final Item item = swcontactContainer.addItem(swModuleID);
|
||||
item.getItemProperty("SWModuleId").setValue(swModuleID.toString());
|
||||
item.getItemProperty(SW_MODULE_NAME_MSG)
|
||||
.setValue(artifactUploadState.getDeleteSofwareModules().get(swModuleID));
|
||||
}
|
||||
return swcontactContainer;
|
||||
}
|
||||
|
||||
private void discardSoftwareDelete(final Button.ClickEvent event, final Object itemId, final ConfirmationTab tab) {
|
||||
|
||||
final Long swmoduleId = (Long) ((Button) event.getComponent()).getData();
|
||||
if (null != artifactUploadState.getDeleteSofwareModules()
|
||||
&& !artifactUploadState.getDeleteSofwareModules().isEmpty()
|
||||
&& artifactUploadState.getDeleteSofwareModules().containsKey(swmoduleId)) {
|
||||
artifactUploadState.getDeleteSofwareModules().remove(swmoduleId);
|
||||
}
|
||||
tab.getTable().getContainerDataSource().removeItem(itemId);
|
||||
final int deleteCount = tab.getTable().size();
|
||||
if (0 == deleteCount) {
|
||||
removeCurrentTab(tab);
|
||||
eventBus.publish(this, UploadArtifactUIEvent.DISCARD_ALL_DELETE_SOFTWARE);
|
||||
} else {
|
||||
eventBus.publish(this, UploadArtifactUIEvent.DISCARD_DELETE_SOFTWARE);
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteSMAll(final ConfirmationTab tab) {
|
||||
final Set<Long> swmoduleIds = artifactUploadState.getDeleteSofwareModules().keySet();
|
||||
softwareManagement.deleteSoftwareModules(swmoduleIds);
|
||||
addToConsolitatedMsg(FontAwesome.TRASH_O.getHtml() + SPUILabelDefinitions.HTML_SPACE
|
||||
+ i18n.get("message.swModule.deleted", artifactUploadState.getDeleteSofwareModules().size()));
|
||||
/*
|
||||
* Check if any information / files pending to upload for the deleted
|
||||
* software modules. If so, then delete the files from the upload list.
|
||||
*/
|
||||
final List<CustomFile> tobeRemoved = new ArrayList<>();
|
||||
for (final Long id : swmoduleIds) {
|
||||
final String deleteSoftwareNameVersion = artifactUploadState.getDeleteSofwareModules().get(id);
|
||||
|
||||
for (final CustomFile customFile : artifactUploadState.getFileSelected()) {
|
||||
final String swNameVersion = HawkbitCommonUtil.getFormattedNameVersion(
|
||||
customFile.getBaseSoftwareModuleName(), customFile.getBaseSoftwareModuleVersion());
|
||||
if (deleteSoftwareNameVersion != null && deleteSoftwareNameVersion.equals(swNameVersion)) {
|
||||
tobeRemoved.add(customFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!tobeRemoved.isEmpty()) {
|
||||
artifactUploadState.getFileSelected().removeAll(tobeRemoved);
|
||||
}
|
||||
artifactUploadState.getDeleteSofwareModules().clear();
|
||||
removeCurrentTab(tab);
|
||||
setActionMessage(i18n.get("message.software.delete.success"));
|
||||
eventBus.publish(this, UploadArtifactUIEvent.DELETED_ALL_SOFWARE);
|
||||
}
|
||||
|
||||
private void discardSMAll(final ConfirmationTab tab) {
|
||||
removeCurrentTab(tab);
|
||||
artifactUploadState.getDeleteSofwareModules().clear();
|
||||
setActionMessage(i18n.get("message.software.discard.success"));
|
||||
eventBus.publish(this, UploadArtifactUIEvent.DISCARD_ALL_DELETE_SOFTWARE);
|
||||
}
|
||||
|
||||
private ConfirmationTab createSMtypeDeleteConfirmationTab() {
|
||||
final ConfirmationTab tab = new ConfirmationTab();
|
||||
|
||||
tab.getConfirmAll().setId(SPUIComponetIdProvider.SAVE_DELETE_SW_MODULE_TYPE);
|
||||
tab.getConfirmAll().setIcon(FontAwesome.TRASH_O);
|
||||
tab.getConfirmAll().setCaption(i18n.get("button.delete.all"));
|
||||
tab.getConfirmAll().addClickListener(event -> deleteSMtypeAll(tab));
|
||||
|
||||
tab.getDiscardAll().setCaption(i18n.get("button.discard.all"));
|
||||
tab.getDiscardAll().addClickListener(event -> discardSMtypeAll(tab));
|
||||
|
||||
// Add items container to the table.
|
||||
tab.getTable().setContainerDataSource(getSWModuleTypeTableContainer());
|
||||
|
||||
// Add the discard action column
|
||||
tab.getTable().addGeneratedColumn(DISCARD, (source, itemId, columnId) -> {
|
||||
final ClickListener clickListener = event -> discardSoftwareTypeDelete(
|
||||
(String) ((Button) event.getComponent()).getData(), itemId, tab);
|
||||
return createDiscardButton(itemId, clickListener);
|
||||
});
|
||||
|
||||
tab.getTable().setVisibleColumns(SW_MODULE_TYPE_NAME, DISCARD);
|
||||
tab.getTable().setColumnHeaders(i18n.get("header.first.delete.swmodule.type.table"),
|
||||
i18n.get("header.second.delete.swmodule.type.table"));
|
||||
|
||||
tab.getTable().setColumnExpandRatio(SW_MODULE_TYPE_NAME, 2);
|
||||
tab.getTable().setColumnExpandRatio(SW_DISCARD_CHGS, SPUIDefinitions.DISCARD_COLUMN_WIDTH);
|
||||
tab.getTable().setColumnAlignment(SW_DISCARD_CHGS, Align.CENTER);
|
||||
return tab;
|
||||
}
|
||||
|
||||
private Container getSWModuleTypeTableContainer() {
|
||||
final IndexedContainer contactContainer = new IndexedContainer();
|
||||
contactContainer.addContainerProperty(SW_MODULE_TYPE_NAME, String.class, "");
|
||||
for (final String swModuleTypeName : artifactUploadState.getSelectedDeleteSWModuleTypes()) {
|
||||
final Item saveTblitem = contactContainer.addItem(swModuleTypeName);
|
||||
saveTblitem.getItemProperty(SW_MODULE_TYPE_NAME).setValue(swModuleTypeName);
|
||||
}
|
||||
return contactContainer;
|
||||
}
|
||||
|
||||
private void discardSoftwareTypeDelete(final String discardSWModuleType, final Object itemId,
|
||||
final ConfirmationTab tab) {
|
||||
if (null != artifactUploadState.getSelectedDeleteSWModuleTypes()
|
||||
&& !artifactUploadState.getSelectedDeleteSWModuleTypes().isEmpty()
|
||||
&& artifactUploadState.getSelectedDeleteSWModuleTypes().contains(discardSWModuleType)) {
|
||||
artifactUploadState.getSelectedDeleteSWModuleTypes().remove(discardSWModuleType);
|
||||
}
|
||||
tab.getTable().getContainerDataSource().removeItem(itemId);
|
||||
final int deleteCount = tab.getTable().size();
|
||||
if (0 == deleteCount) {
|
||||
removeCurrentTab(tab);
|
||||
eventBus.publish(this, UploadArtifactUIEvent.DISCARD_ALL_DELETE_SOFTWARE_TYPE);
|
||||
} else {
|
||||
eventBus.publish(this, UploadArtifactUIEvent.DISCARD_DELETE_SOFTWARE_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteSMtypeAll(final ConfirmationTab tab) {
|
||||
final int deleteSWModuleTypeCount = artifactUploadState.getSelectedDeleteSWModuleTypes().size();
|
||||
for (final String swModuleTypeName : artifactUploadState.getSelectedDeleteSWModuleTypes()) {
|
||||
|
||||
softwareManagement
|
||||
.deleteSoftwareModuleType(softwareManagement.findSoftwareModuleTypeByName(swModuleTypeName));
|
||||
}
|
||||
addToConsolitatedMsg(FontAwesome.TASKS.getHtml() + SPUILabelDefinitions.HTML_SPACE
|
||||
+ i18n.get("message.sw.module.type.delete", new Object[] { deleteSWModuleTypeCount }));
|
||||
artifactUploadState.getSelectedDeleteSWModuleTypes().clear();
|
||||
removeCurrentTab(tab);
|
||||
setActionMessage(i18n.get("message.software.type.delete.success"));
|
||||
eventBus.publish(this, UploadArtifactUIEvent.DELETED_ALL_SOFWARE_TYPE);
|
||||
}
|
||||
|
||||
private void discardSMtypeAll(final ConfirmationTab tab) {
|
||||
removeCurrentTab(tab);
|
||||
artifactUploadState.getSelectedDeleteSWModuleTypes().clear();
|
||||
setActionMessage(i18n.get("message.software.type.discard.success"));
|
||||
eventBus.publish(this, UploadArtifactUIEvent.DISCARD_ALL_DELETE_SOFTWARE_TYPE);
|
||||
}
|
||||
}
|
||||
@@ -1,138 +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.artifacts.smtable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
|
||||
import org.eclipse.hawkbit.repository.SoftwareManagement;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SpringContextHelper;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
import org.vaadin.addons.lazyquerycontainer.AbstractBeanQuery;
|
||||
import org.vaadin.addons.lazyquerycontainer.QueryDefinition;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
/**
|
||||
* Simple implementation of generics bean query which dynamically loads a batch
|
||||
* of beans.
|
||||
*
|
||||
*/
|
||||
public class BaseSwModuleBeanQuery extends AbstractBeanQuery<ProxyBaseSoftwareModuleItem> {
|
||||
private static final long serialVersionUID = 4362142538539335466L;
|
||||
private transient SoftwareManagement softwareManagementService;
|
||||
private SoftwareModuleType type;
|
||||
private String searchText = null;
|
||||
private final Sort sort = new Sort(Direction.ASC, "name", "version");
|
||||
|
||||
/**
|
||||
* Parametric Constructor.
|
||||
*
|
||||
* @param definition
|
||||
* as Def
|
||||
* @param queryConfig
|
||||
* as Config
|
||||
* @param sortIds
|
||||
* as sort
|
||||
* @param sortStates
|
||||
* as Sort status
|
||||
*/
|
||||
public BaseSwModuleBeanQuery(final QueryDefinition definition, final Map<String, Object> queryConfig,
|
||||
final Object[] sortIds, final boolean[] sortStates) {
|
||||
super(definition, queryConfig, sortIds, sortStates);
|
||||
if (HawkbitCommonUtil.mapCheckStrKey(queryConfig)) {
|
||||
type = (SoftwareModuleType) queryConfig.get(SPUIDefinitions.BY_SOFTWARE_MODULE_TYPE);
|
||||
searchText = (String) queryConfig.get(SPUIDefinitions.FILTER_BY_TEXT);
|
||||
if (!Strings.isNullOrEmpty(searchText)) {
|
||||
searchText = String.format("%%%s%%", searchText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ProxyBaseSoftwareModuleItem constructBean() {
|
||||
return new ProxyBaseSoftwareModuleItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<ProxyBaseSoftwareModuleItem> loadBeans(final int startIndex, final int count) {
|
||||
final Slice<SoftwareModule> swModuleBeans;
|
||||
final List<ProxyBaseSoftwareModuleItem> proxyBeans = new ArrayList<>();
|
||||
|
||||
if (type == null && Strings.isNullOrEmpty(searchText)) {
|
||||
swModuleBeans = getSoftwareManagementService()
|
||||
.findSoftwareModulesAll(new OffsetBasedPageRequest(startIndex, count, sort));
|
||||
|
||||
} else {
|
||||
swModuleBeans = getSoftwareManagementService()
|
||||
.findSoftwareModuleByFilters(new OffsetBasedPageRequest(startIndex, count, sort), searchText, type);
|
||||
}
|
||||
|
||||
for (final SoftwareModule swModule : swModuleBeans) {
|
||||
proxyBeans.add(getProxyBean(swModule));
|
||||
}
|
||||
|
||||
return proxyBeans;
|
||||
}
|
||||
|
||||
private ProxyBaseSoftwareModuleItem getProxyBean(final SoftwareModule bean) {
|
||||
final ProxyBaseSoftwareModuleItem proxy = new ProxyBaseSoftwareModuleItem();
|
||||
proxy.setSwId(bean.getId());
|
||||
final String swNameVersion = HawkbitCommonUtil.concatStrings(":", bean.getName(), bean.getVersion());
|
||||
proxy.setNameAndVersion(swNameVersion);
|
||||
proxy.setCreatedDate(SPDateTimeUtil.getFormattedDate(bean.getCreatedAt()));
|
||||
proxy.setLastModifiedDate(SPDateTimeUtil.getFormattedDate(bean.getLastModifiedAt()));
|
||||
proxy.setName(bean.getName());
|
||||
proxy.setVersion(bean.getVersion());
|
||||
proxy.setVendor(bean.getVendor());
|
||||
proxy.setDescription(bean.getDescription());
|
||||
proxy.setCreatedByUser(HawkbitCommonUtil.getIMUser(bean.getCreatedBy()));
|
||||
proxy.setModifiedByUser(HawkbitCommonUtil.getIMUser(bean.getLastModifiedBy()));
|
||||
return proxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
long size;
|
||||
if (type == null && Strings.isNullOrEmpty(searchText)) {
|
||||
size = getSoftwareManagementService().countSoftwareModulesAll();
|
||||
} else {
|
||||
size = getSoftwareManagementService().countSoftwareModuleByFilters(searchText, type);
|
||||
}
|
||||
|
||||
if (size > Integer.MAX_VALUE) {
|
||||
size = Integer.MAX_VALUE;
|
||||
}
|
||||
return (int) size;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveBeans(final List<ProxyBaseSoftwareModuleItem> addedBeans,
|
||||
final List<ProxyBaseSoftwareModuleItem> modifiedBeans,
|
||||
final List<ProxyBaseSoftwareModuleItem> removedBeans) {
|
||||
// save of the entity not required from this method
|
||||
}
|
||||
|
||||
private SoftwareManagement getSoftwareManagementService() {
|
||||
if (softwareManagementService == null) {
|
||||
softwareManagementService = SpringContextHelper.getBean(SoftwareManagement.class);
|
||||
}
|
||||
return softwareManagementService;
|
||||
}
|
||||
}
|
||||
@@ -1,106 +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.artifacts.smtable;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
|
||||
/**
|
||||
*
|
||||
* Proxy for software module to display details in Software modules table.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ProxyBaseSoftwareModuleItem extends SoftwareModule {
|
||||
|
||||
private static final long serialVersionUID = -1555306616599140635L;
|
||||
|
||||
private static final SecureRandom RANDOM_OBJ = new SecureRandom();
|
||||
|
||||
private String nameAndVersion;
|
||||
|
||||
private Long swId;
|
||||
|
||||
private boolean assigned;
|
||||
|
||||
private String createdDate;
|
||||
|
||||
private String lastModifiedDate;
|
||||
|
||||
private String createdByUser;
|
||||
|
||||
private String modifiedByUser;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public ProxyBaseSoftwareModuleItem() {
|
||||
super();
|
||||
swId = RANDOM_OBJ.nextLong();
|
||||
}
|
||||
|
||||
public String getCreatedByUser() {
|
||||
return createdByUser;
|
||||
}
|
||||
|
||||
public Long getSwId() {
|
||||
return swId;
|
||||
}
|
||||
|
||||
public void setCreatedByUser(final String createdByUser) {
|
||||
this.createdByUser = createdByUser;
|
||||
}
|
||||
|
||||
public void setSwId(final Long swId) {
|
||||
this.swId = swId;
|
||||
}
|
||||
|
||||
public String getModifiedByUser() {
|
||||
return modifiedByUser;
|
||||
}
|
||||
|
||||
public void setModifiedByUser(final String modifiedByUser) {
|
||||
this.modifiedByUser = modifiedByUser;
|
||||
}
|
||||
|
||||
public String getCreatedDate() {
|
||||
return createdDate;
|
||||
}
|
||||
|
||||
public void setCreatedDate(final String createdDate) {
|
||||
this.createdDate = createdDate;
|
||||
}
|
||||
|
||||
public String getLastModifiedDate() {
|
||||
return lastModifiedDate;
|
||||
}
|
||||
|
||||
public void setLastModifiedDate(final String lastModifiedDate) {
|
||||
this.lastModifiedDate = lastModifiedDate;
|
||||
}
|
||||
|
||||
public String getNameAndVersion() {
|
||||
return nameAndVersion;
|
||||
}
|
||||
|
||||
public void setNameAndVersion(final String nameAndVersion) {
|
||||
this.nameAndVersion = nameAndVersion;
|
||||
}
|
||||
|
||||
public boolean isAssigned() {
|
||||
return assigned;
|
||||
}
|
||||
|
||||
public void setAssigned(final boolean assigned) {
|
||||
this.assigned = assigned;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,362 +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.artifacts.smtable;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.eclipse.hawkbit.repository.SoftwareManagement;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent;
|
||||
import org.eclipse.hawkbit.ui.common.SoftwareModuleTypeBeanQuery;
|
||||
import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType;
|
||||
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
|
||||
import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder;
|
||||
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.I18N;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.UINotification;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory;
|
||||
import org.vaadin.spring.events.EventBus;
|
||||
|
||||
import com.vaadin.server.FontAwesome;
|
||||
import com.vaadin.spring.annotation.SpringComponent;
|
||||
import com.vaadin.spring.annotation.ViewScope;
|
||||
import com.vaadin.ui.Alignment;
|
||||
import com.vaadin.ui.Button;
|
||||
import com.vaadin.ui.ComboBox;
|
||||
import com.vaadin.ui.HorizontalLayout;
|
||||
import com.vaadin.ui.Label;
|
||||
import com.vaadin.ui.TextArea;
|
||||
import com.vaadin.ui.TextField;
|
||||
import com.vaadin.ui.UI;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
import com.vaadin.ui.Window;
|
||||
import com.vaadin.ui.themes.ValoTheme;
|
||||
|
||||
/**
|
||||
* Generates window for Software module add or update.
|
||||
*
|
||||
*
|
||||
*/
|
||||
@SpringComponent
|
||||
@ViewScope
|
||||
public class SoftwareModuleAddUpdateWindow implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -5217675246477211483L;
|
||||
|
||||
@Autowired
|
||||
private I18N i18n;
|
||||
|
||||
@Autowired
|
||||
private transient UINotification uiNotifcation;
|
||||
|
||||
@Autowired
|
||||
private transient EventBus.SessionEventBus eventBus;
|
||||
|
||||
@Autowired
|
||||
private transient SoftwareManagement softwareManagement;
|
||||
|
||||
private Label madatoryLabel;
|
||||
|
||||
private TextField nameTextField;
|
||||
|
||||
private TextField versionTextField;
|
||||
|
||||
private TextField vendorTextField;
|
||||
|
||||
private Button saveSoftware;
|
||||
|
||||
private Button closeWindow;
|
||||
|
||||
private ComboBox typeComboBox;
|
||||
|
||||
private TextArea descTextArea;
|
||||
|
||||
private Window window;
|
||||
|
||||
private String oldDescriptionValue;
|
||||
|
||||
private String oldVendorValue;
|
||||
|
||||
private Boolean editSwModule = Boolean.FALSE;
|
||||
|
||||
private Long baseSwModuleId;
|
||||
|
||||
/**
|
||||
* Create window for new software module.
|
||||
*
|
||||
* @return reference of {@link com.vaadin.ui.Window} to add new software
|
||||
* module.
|
||||
*/
|
||||
public Window createAddSoftwareModuleWindow() {
|
||||
editSwModule = Boolean.FALSE;
|
||||
createRequiredComponents();
|
||||
createWindow();
|
||||
return window;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create window for update software module.
|
||||
*
|
||||
* @param baseSwModuleId
|
||||
* is id of the software module to edit.
|
||||
* @return reference of {@link com.vaadin.ui.Window} to update software
|
||||
* module.
|
||||
*/
|
||||
public Window createUpdateSoftwareModuleWindow(final Long baseSwModuleId) {
|
||||
editSwModule = Boolean.TRUE;
|
||||
this.baseSwModuleId = baseSwModuleId;
|
||||
createRequiredComponents();
|
||||
createWindow();
|
||||
/* populate selected target values to edit. */
|
||||
populateValuesOfSwModule();
|
||||
nameTextField.setEnabled(false);
|
||||
versionTextField.setEnabled(false);
|
||||
typeComboBox.setEnabled(false);
|
||||
return window;
|
||||
}
|
||||
|
||||
private void createRequiredComponents() {
|
||||
/* name textfield */
|
||||
nameTextField = SPUIComponentProvider.getTextField("", ValoTheme.TEXTFIELD_TINY, true, null,
|
||||
i18n.get("textfield.name"), true, SPUILabelDefinitions.TEXT_FIELD_MAX_LENGTH);
|
||||
nameTextField.setId(SPUIComponetIdProvider.SOFT_MODULE_NAME);
|
||||
|
||||
/* version text field */
|
||||
versionTextField = SPUIComponentProvider.getTextField("", ValoTheme.TEXTFIELD_TINY, true, null,
|
||||
i18n.get("textfield.version"), true, SPUILabelDefinitions.TEXT_FIELD_MAX_LENGTH);
|
||||
versionTextField.setId(SPUIComponetIdProvider.SOFT_MODULE_VERSION);
|
||||
|
||||
/* Vendor text field */
|
||||
vendorTextField = SPUIComponentProvider.getTextField("", ValoTheme.TEXTFIELD_TINY, false, null,
|
||||
i18n.get("textfield.vendor"), true, SPUILabelDefinitions.TEXT_FIELD_MAX_LENGTH);
|
||||
vendorTextField.setId(SPUIComponetIdProvider.SOFT_MODULE_VENDOR);
|
||||
|
||||
descTextArea = SPUIComponentProvider.getTextArea("text-area-style", ValoTheme.TEXTAREA_TINY, false, null,
|
||||
i18n.get("textfield.description"), SPUILabelDefinitions.TEXT_AREA_MAX_LENGTH);
|
||||
descTextArea.setId(SPUIComponetIdProvider.ADD_SW_MODULE_DESCRIPTION);
|
||||
addDescriptionTextChangeListener();
|
||||
addVendorTextChangeListener();
|
||||
|
||||
/* Label for mandatory symbol */
|
||||
madatoryLabel = new Label(i18n.get("label.mandatory.field"));
|
||||
madatoryLabel.setStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_ERROR);
|
||||
madatoryLabel.addStyleName(ValoTheme.LABEL_SMALL);
|
||||
|
||||
typeComboBox = SPUIComponentProvider.getComboBox("", "", null, null, false, null,
|
||||
i18n.get("upload.swmodule.type"));
|
||||
typeComboBox.setId(SPUIComponetIdProvider.SW_MODULE_TYPE);
|
||||
typeComboBox.setStyleName(SPUIDefinitions.COMBO_BOX_SPECIFIC_STYLE + " " + ValoTheme.COMBOBOX_TINY);
|
||||
typeComboBox.setNewItemsAllowed(Boolean.FALSE);
|
||||
typeComboBox.setImmediate(Boolean.TRUE);
|
||||
|
||||
populateTypeNameCombo();
|
||||
|
||||
/* save or update button */
|
||||
saveSoftware = SPUIComponentProvider.getButton(SPUIComponetIdProvider.SOFT_MODULE_SAVE, "", "", "", true,
|
||||
FontAwesome.SAVE, SPUIButtonStyleSmallNoBorder.class);
|
||||
saveSoftware.addClickListener(event -> {
|
||||
if (editSwModule) {
|
||||
updateSwModule();
|
||||
} else {
|
||||
/* add new or update software module */
|
||||
addNewBaseSoftware();
|
||||
}
|
||||
});
|
||||
|
||||
/* close button */
|
||||
closeWindow = SPUIComponentProvider.getButton(SPUIComponetIdProvider.SOFT_MODULE_DISCARD, "", "", "", true,
|
||||
FontAwesome.TIMES, SPUIButtonStyleSmallNoBorder.class);
|
||||
/* Just close this window when this button is clicked */
|
||||
closeWindow.addClickListener(event -> closeThisWindow());
|
||||
|
||||
resetOldValues();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void populateTypeNameCombo() {
|
||||
typeComboBox.setContainerDataSource(HawkbitCommonUtil.createLazyQueryContainer(
|
||||
new BeanQueryFactory<SoftwareModuleTypeBeanQuery>(SoftwareModuleTypeBeanQuery.class)));
|
||||
typeComboBox.setItemCaptionPropertyId(SPUILabelDefinitions.VAR_NAME);
|
||||
|
||||
}
|
||||
|
||||
private void resetOldValues() {
|
||||
oldDescriptionValue = null;
|
||||
oldVendorValue = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep UI components on Layout.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private void createWindow() {
|
||||
/* action button layout (save & dicard) */
|
||||
final HorizontalLayout buttonsLayout = new HorizontalLayout();
|
||||
buttonsLayout.setSizeFull();
|
||||
buttonsLayout.addComponents(saveSoftware, closeWindow);
|
||||
buttonsLayout.setComponentAlignment(saveSoftware, Alignment.BOTTOM_LEFT);
|
||||
buttonsLayout.setComponentAlignment(closeWindow, Alignment.BOTTOM_RIGHT);
|
||||
buttonsLayout.addStyleName("window-style");
|
||||
|
||||
final Label madatoryStarLabel = new Label("*");
|
||||
madatoryStarLabel.setStyleName("v-caption v-required-field-indicator");
|
||||
madatoryStarLabel.setWidth(null);
|
||||
final HorizontalLayout hLayout = new HorizontalLayout();
|
||||
hLayout.setSizeFull();
|
||||
hLayout.addComponents(typeComboBox, madatoryStarLabel);
|
||||
hLayout.setComponentAlignment(typeComboBox, Alignment.TOP_LEFT);
|
||||
hLayout.setComponentAlignment(madatoryStarLabel, Alignment.TOP_RIGHT);
|
||||
hLayout.setExpandRatio(typeComboBox, 0.8f);
|
||||
|
||||
/*
|
||||
* The main layout of the window contains mandatory info, textboxes
|
||||
* (controller Id, name & description) and action buttons layout
|
||||
*/
|
||||
final VerticalLayout mainLayout = new VerticalLayout();
|
||||
mainLayout.setSpacing(Boolean.TRUE);
|
||||
mainLayout.addStyleName("lay-color");
|
||||
mainLayout.addComponent(madatoryLabel);
|
||||
mainLayout.setComponentAlignment(madatoryLabel, Alignment.MIDDLE_LEFT);
|
||||
mainLayout.addComponent(hLayout);
|
||||
mainLayout.setComponentAlignment(hLayout, Alignment.MIDDLE_LEFT);
|
||||
mainLayout.addComponents(nameTextField, versionTextField, vendorTextField, descTextArea, buttonsLayout);
|
||||
|
||||
/* add main layout to the window */
|
||||
window = SPUIComponentProvider.getWindow(i18n.get("upload.caption.add.new.swmodule"), null,
|
||||
SPUIDefinitions.CREATE_UPDATE_WINDOW);
|
||||
window.setContent(mainLayout);
|
||||
window.setModal(true);
|
||||
}
|
||||
|
||||
private void addDescriptionTextChangeListener() {
|
||||
descTextArea.addTextChangeListener(event -> {
|
||||
if (event.getText().equals(oldDescriptionValue) && vendorTextField.getValue().equals(oldVendorValue)) {
|
||||
saveSoftware.setEnabled(false);
|
||||
} else {
|
||||
saveSoftware.setEnabled(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void addVendorTextChangeListener() {
|
||||
vendorTextField.addTextChangeListener(event -> {
|
||||
if (event.getText().equals(oldVendorValue) && descTextArea.getValue().equals(oldDescriptionValue)) {
|
||||
saveSoftware.setEnabled(false);
|
||||
} else {
|
||||
saveSoftware.setEnabled(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new SW module.
|
||||
*/
|
||||
private void addNewBaseSoftware() {
|
||||
final String name = HawkbitCommonUtil.trimAndNullIfEmpty(nameTextField.getValue());
|
||||
final String version = HawkbitCommonUtil.trimAndNullIfEmpty(versionTextField.getValue());
|
||||
final String vendor = HawkbitCommonUtil.trimAndNullIfEmpty(vendorTextField.getValue());
|
||||
final String description = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue());
|
||||
final String type = typeComboBox.getValue() != null ? typeComboBox.getValue().toString() : null;
|
||||
if (mandatoryCheck(name, version, type)) {
|
||||
if (HawkbitCommonUtil.isDuplicate(name, version, type)) {
|
||||
uiNotifcation.displayValidationError(
|
||||
i18n.get("message.duplicate.softwaremodule", new Object[] { name, version }));
|
||||
} else {
|
||||
final SoftwareModule newBaseSoftwareModule = HawkbitCommonUtil.addNewBaseSoftware(name, version, vendor,
|
||||
softwareManagement.findSoftwareModuleTypeByName(type), description);
|
||||
if (newBaseSoftwareModule != null) {
|
||||
/* display success message */
|
||||
uiNotifcation.displaySuccess(i18n.get("message.save.success", new Object[] {
|
||||
newBaseSoftwareModule.getName() + ":" + newBaseSoftwareModule.getVersion() }));
|
||||
eventBus.publish(this,
|
||||
new SoftwareModuleEvent(BaseEntityEventType.NEW_ENTITY, newBaseSoftwareModule));
|
||||
}
|
||||
// close the window
|
||||
closeThisWindow();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSwModule() {
|
||||
final String newDesc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue());
|
||||
final String newVendor = HawkbitCommonUtil.trimAndNullIfEmpty(vendorTextField.getValue());
|
||||
SoftwareModule newSWModule = softwareManagement.findSoftwareModuleById(baseSwModuleId);
|
||||
newSWModule.setVendor(newVendor);
|
||||
newSWModule.setDescription(newDesc);
|
||||
newSWModule = softwareManagement.updateSoftwareModule(newSWModule);
|
||||
if (newSWModule != null) {
|
||||
uiNotifcation.displaySuccess(i18n.get("message.save.success",
|
||||
new Object[] { newSWModule.getName() + ":" + newSWModule.getVersion() }));
|
||||
|
||||
eventBus.publish(this, new SoftwareModuleEvent(BaseEntityEventType.UPDATED_ENTITY, newSWModule));
|
||||
}
|
||||
closeThisWindow();
|
||||
}
|
||||
|
||||
private void populateValuesOfSwModule() {
|
||||
final SoftwareModule swModle = softwareManagement.findSoftwareModuleById(baseSwModuleId);
|
||||
nameTextField.setValue(swModle.getName());
|
||||
versionTextField.setValue(swModle.getVersion());
|
||||
vendorTextField.setValue(swModle.getVendor() == null ? HawkbitCommonUtil.SP_STRING_EMPTY
|
||||
: HawkbitCommonUtil.trimAndNullIfEmpty(swModle.getVendor()));
|
||||
descTextArea.setValue(swModle.getDescription() == null ? HawkbitCommonUtil.SP_STRING_EMPTY
|
||||
: HawkbitCommonUtil.trimAndNullIfEmpty(swModle.getDescription()));
|
||||
oldDescriptionValue = descTextArea.getValue();
|
||||
oldVendorValue = vendorTextField.getValue();
|
||||
if (swModle.getType().isDeleted()) {
|
||||
typeComboBox.addItem(swModle.getType().getName());
|
||||
}
|
||||
typeComboBox.setValue(swModle.getType().getName());
|
||||
saveSoftware.setEnabled(Boolean.FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to close window.
|
||||
*/
|
||||
private void closeThisWindow() {
|
||||
window.close();
|
||||
UI.getCurrent().removeWindow(window);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation check - Mandatory.
|
||||
*
|
||||
* @param name
|
||||
* as String
|
||||
* @param version
|
||||
* as version
|
||||
* @return boolena as flag
|
||||
*/
|
||||
private boolean mandatoryCheck(final String name, final String version, final String type) {
|
||||
boolean isValid = true;
|
||||
if (name == null || version == null || type == null) {
|
||||
if (name == null) {
|
||||
nameTextField.addStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_ERROR);
|
||||
}
|
||||
if (version == null) {
|
||||
versionTextField.addStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_ERROR);
|
||||
}
|
||||
if (type == null) {
|
||||
typeComboBox.addStyleName(SPUIStyleDefinitions.SP_COMBOFIELD_ERROR);
|
||||
}
|
||||
|
||||
uiNotifcation.displayValidationError(i18n.get("message.mandatory.check"));
|
||||
isValid = false;
|
||||
}
|
||||
return isValid;
|
||||
}
|
||||
}
|
||||
@@ -1,144 +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.artifacts.smtable;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent;
|
||||
import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState;
|
||||
import org.eclipse.hawkbit.ui.common.detailslayout.AbstractNamedVersionedEntityTableDetailsLayout;
|
||||
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
|
||||
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.vaadin.spring.events.EventScope;
|
||||
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
|
||||
|
||||
import com.vaadin.spring.annotation.SpringComponent;
|
||||
import com.vaadin.spring.annotation.ViewScope;
|
||||
import com.vaadin.ui.Button.ClickEvent;
|
||||
import com.vaadin.ui.Label;
|
||||
import com.vaadin.ui.TabSheet;
|
||||
import com.vaadin.ui.UI;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
import com.vaadin.ui.Window;
|
||||
|
||||
/**
|
||||
* Software module details.
|
||||
*
|
||||
*
|
||||
*/
|
||||
@SpringComponent
|
||||
@ViewScope
|
||||
public class SoftwareModuleDetails extends AbstractNamedVersionedEntityTableDetailsLayout<SoftwareModule> {
|
||||
|
||||
private static final long serialVersionUID = -4900381301076646366L;
|
||||
|
||||
@Autowired
|
||||
private SoftwareModuleAddUpdateWindow softwareModuleAddUpdateWindow;
|
||||
|
||||
@Autowired
|
||||
private ArtifactUploadState artifactUploadState;
|
||||
|
||||
@Override
|
||||
protected String getEditButtonId() {
|
||||
return SPUIComponetIdProvider.UPLOAD_SW_MODULE_EDIT_BUTTON;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addTabs(final TabSheet detailsTab) {
|
||||
detailsTab.addTab(createDetailsLayout(), getI18n().get("caption.tab.details"), null);
|
||||
detailsTab.addTab(createDescriptionLayout(), getI18n().get("caption.tab.description"), null);
|
||||
detailsTab.addTab(createLogLayout(), getI18n().get("caption.logs.tab"), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEdit(final ClickEvent event) {
|
||||
final Window addSoftwareModule = softwareModuleAddUpdateWindow
|
||||
.createUpdateSoftwareModuleWindow(getSelectedBaseEntityId());
|
||||
addSoftwareModule.setCaption(getI18n().get("upload.caption.update.swmodule"));
|
||||
UI.getCurrent().addWindow(addSoftwareModule);
|
||||
addSoftwareModule.setVisible(Boolean.TRUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void populateDetailsWidget() {
|
||||
String maxAssign = HawkbitCommonUtil.SP_STRING_EMPTY;
|
||||
if (getSelectedBaseEntity() != null) {
|
||||
if (getSelectedBaseEntity().getType().getMaxAssignments() == Integer.MAX_VALUE) {
|
||||
maxAssign = getI18n().get("label.multiAssign.type");
|
||||
} else {
|
||||
maxAssign = getI18n().get("label.singleAssign.type");
|
||||
}
|
||||
updateSoftwareModuleDetailsLayout(getSelectedBaseEntity().getType().getName(),
|
||||
getSelectedBaseEntity().getVendor(), maxAssign);
|
||||
} else {
|
||||
updateSoftwareModuleDetailsLayout(HawkbitCommonUtil.SP_STRING_EMPTY, HawkbitCommonUtil.SP_STRING_EMPTY,
|
||||
maxAssign);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSoftwareModuleDetailsLayout(final String type, final String vendor, final String maxAssign) {
|
||||
final VerticalLayout detailsTabLayout = getDetailsLayout();
|
||||
|
||||
detailsTabLayout.removeAllComponents();
|
||||
|
||||
final Label vendorLabel = SPUIComponentProvider.createNameValueLabel(getI18n().get("label.dist.details.vendor"),
|
||||
HawkbitCommonUtil.trimAndNullIfEmpty(vendor) == null ? "" : vendor);
|
||||
vendorLabel.setId(SPUIComponetIdProvider.DETAILS_VENDOR_LABEL_ID);
|
||||
detailsTabLayout.addComponent(vendorLabel);
|
||||
|
||||
if (type != null) {
|
||||
final Label typeLabel = SPUIComponentProvider.createNameValueLabel(getI18n().get("label.dist.details.type"),
|
||||
type);
|
||||
typeLabel.setId(SPUIComponetIdProvider.DETAILS_TYPE_LABEL_ID);
|
||||
detailsTabLayout.addComponent(typeLabel);
|
||||
}
|
||||
|
||||
final Label assignLabel = SPUIComponentProvider.createNameValueLabel(getI18n().get("label.assigned.type"),
|
||||
HawkbitCommonUtil.trimAndNullIfEmpty(maxAssign) == null ? "" : maxAssign);
|
||||
assignLabel.setId(SPUIComponetIdProvider.SWM_DTLS_MAX_ASSIGN);
|
||||
detailsTabLayout.addComponent(assignLabel);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultCaption() {
|
||||
return getI18n().get("upload.swModuleTable.header");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean onLoadIsTableRowSelected() {
|
||||
return artifactUploadState.getSelectedBaseSoftwareModule().isPresent();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean onLoadIsTableMaximized() {
|
||||
return artifactUploadState.isSwModuleTableMaximized();
|
||||
}
|
||||
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void onEvent(final SoftwareModuleEvent softwareModuleEvent) {
|
||||
onBaseEntityEvent(softwareModuleEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean hasEditPermission() {
|
||||
return getPermissionChecker().hasUpdateDistributionPermission();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTabSheetId() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDetailsHeaderCaptionId() {
|
||||
return SPUIComponetIdProvider.TARGET_DETAILS_HEADER_LABEL_ID;
|
||||
}
|
||||
}
|
||||
@@ -1,214 +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.artifacts.smtable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.hawkbit.repository.SoftwareManagement;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.ui.artifacts.event.SMFilterEvent;
|
||||
import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent;
|
||||
import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent;
|
||||
import org.eclipse.hawkbit.ui.artifacts.event.UploadViewAcceptCriteria;
|
||||
import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState;
|
||||
import org.eclipse.hawkbit.ui.common.table.AbstractNamedVersionTable;
|
||||
import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType;
|
||||
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.TableColumn;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory;
|
||||
import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer;
|
||||
import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition;
|
||||
import org.vaadin.spring.events.EventScope;
|
||||
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
|
||||
|
||||
import com.vaadin.data.Container;
|
||||
import com.vaadin.data.Item;
|
||||
import com.vaadin.event.dd.DragAndDropEvent;
|
||||
import com.vaadin.event.dd.DropHandler;
|
||||
import com.vaadin.event.dd.acceptcriteria.AcceptCriterion;
|
||||
import com.vaadin.spring.annotation.SpringComponent;
|
||||
import com.vaadin.spring.annotation.ViewScope;
|
||||
import com.vaadin.ui.UI;
|
||||
|
||||
/**
|
||||
* Header of Software module table.
|
||||
*
|
||||
*/
|
||||
@SpringComponent
|
||||
@ViewScope
|
||||
public class SoftwareModuleTable extends AbstractNamedVersionTable<SoftwareModule, Long> {
|
||||
|
||||
private static final long serialVersionUID = 6469417305487144809L;
|
||||
|
||||
@Autowired
|
||||
private ArtifactUploadState artifactUploadState;
|
||||
|
||||
@Autowired
|
||||
private transient SoftwareManagement softwareManagement;
|
||||
|
||||
@Autowired
|
||||
private UploadViewAcceptCriteria uploadViewAcceptCriteria;
|
||||
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void onEvent(final SMFilterEvent filterEvent) {
|
||||
UI.getCurrent().access(() -> {
|
||||
|
||||
if (filterEvent == SMFilterEvent.FILTER_BY_TYPE || filterEvent == SMFilterEvent.FILTER_BY_TEXT
|
||||
|| filterEvent == SMFilterEvent.REMOVER_FILTER_BY_TYPE
|
||||
|| filterEvent == SMFilterEvent.REMOVER_FILTER_BY_TEXT) {
|
||||
refreshFilter();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTableId() {
|
||||
return SPUIComponetIdProvider.UPLOAD_SOFTWARE_MODULE_TABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Container createContainer() {
|
||||
final Map<String, Object> queryConfiguration = prepareQueryConfigFilters();
|
||||
|
||||
final BeanQueryFactory<BaseSwModuleBeanQuery> swQF = new BeanQueryFactory<>(BaseSwModuleBeanQuery.class);
|
||||
swQF.setQueryConfiguration(queryConfiguration);
|
||||
|
||||
return new LazyQueryContainer(new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, "swId"), swQF);
|
||||
}
|
||||
|
||||
private Map<String, Object> prepareQueryConfigFilters() {
|
||||
final Map<String, Object> queryConfig = new HashMap<>();
|
||||
artifactUploadState.getSoftwareModuleFilters().getSearchText()
|
||||
.ifPresent(value -> queryConfig.put(SPUIDefinitions.FILTER_BY_TEXT, value));
|
||||
|
||||
artifactUploadState.getSoftwareModuleFilters().getSoftwareModuleType()
|
||||
.ifPresent(type -> queryConfig.put(SPUIDefinitions.BY_SOFTWARE_MODULE_TYPE, type));
|
||||
|
||||
return queryConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addContainerProperties(final Container container) {
|
||||
final LazyQueryContainer lqc = (LazyQueryContainer) container;
|
||||
lqc.addContainerProperty("nameAndVersion", String.class, null, false, false);
|
||||
lqc.addContainerProperty(SPUILabelDefinitions.VAR_ID, Long.class, null, false, false);
|
||||
lqc.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, "", false, true);
|
||||
lqc.addContainerProperty(SPUILabelDefinitions.VAR_VERSION, String.class, null, false, false);
|
||||
lqc.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, null, false, true);
|
||||
lqc.addContainerProperty(SPUILabelDefinitions.VAR_VENDOR, String.class, null, false, true);
|
||||
lqc.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_BY, String.class, null, false, true);
|
||||
lqc.addContainerProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, String.class, null, false, true);
|
||||
lqc.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, String.class, null, false, true);
|
||||
lqc.addContainerProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, String.class, null, false, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isFirstRowSelectedOnLoad() {
|
||||
return artifactUploadState.getSelectedSoftwareModules().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getItemIdToSelect() {
|
||||
return artifactUploadState.getSelectedSoftwareModules();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isMaximized() {
|
||||
return artifactUploadState.isSwModuleTableMaximized();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SoftwareModule findEntityByTableValue(final Long entityTableId) {
|
||||
return softwareManagement.findSoftwareModuleById(entityTableId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ArtifactUploadState getManagmentEntityState() {
|
||||
return artifactUploadState;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void publishEntityAfterValueChange(final SoftwareModule lastSoftwareModule) {
|
||||
artifactUploadState.setSelectedBaseSoftwareModule(lastSoftwareModule);
|
||||
eventBus.publish(this, new SoftwareModuleEvent(BaseEntityEventType.SELECTED_ENTITY, lastSoftwareModule));
|
||||
}
|
||||
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void onEvent(final SoftwareModuleEvent event) {
|
||||
onBaseEntityEvent(event);
|
||||
}
|
||||
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void onEvent(final UploadArtifactUIEvent event) {
|
||||
if (event == UploadArtifactUIEvent.DELETED_ALL_SOFWARE) {
|
||||
UI.getCurrent().access(() -> refreshFilter());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Item addEntity(final SoftwareModule baseEntity) {
|
||||
final Item item = super.addEntity(baseEntity);
|
||||
if (!artifactUploadState.getSelectedSoftwareModules().isEmpty()) {
|
||||
artifactUploadState.getSelectedSoftwareModules().stream().forEach(this::unselect);
|
||||
}
|
||||
select(baseEntity.getId());
|
||||
return item;
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected void updateEntity(final SoftwareModule baseEntity, final Item item) {
|
||||
final String swNameVersion = HawkbitCommonUtil.concatStrings(":", baseEntity.getName(),
|
||||
baseEntity.getVersion());
|
||||
item.getItemProperty(SPUILabelDefinitions.NAME_VERSION).setValue(swNameVersion);
|
||||
item.getItemProperty("swId").setValue(baseEntity.getId());
|
||||
item.getItemProperty(SPUILabelDefinitions.VAR_VENDOR).setValue(baseEntity.getVendor());
|
||||
super.updateEntity(baseEntity, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<TableColumn> getTableVisibleColumns() {
|
||||
final List<TableColumn> columnList = super.getTableVisibleColumns();
|
||||
if (!isMaximized()) {
|
||||
return columnList;
|
||||
}
|
||||
columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VENDOR, i18n.get("header.vendor"), 0.1F));
|
||||
return columnList;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DropHandler getTableDropHandler() {
|
||||
return new DropHandler() {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public AcceptCriterion getAcceptCriterion() {
|
||||
return uploadViewAcceptCriteria;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drop(final DragAndDropEvent event) {
|
||||
/* Not required */
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setDataAvailable(final boolean available) {
|
||||
artifactUploadState.setNoDataAvilableSoftwareModule(!available);
|
||||
}
|
||||
}
|
||||
@@ -1,207 +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.artifacts.smtable;
|
||||
|
||||
import org.eclipse.hawkbit.ui.artifacts.event.SMFilterEvent;
|
||||
import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent;
|
||||
import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent;
|
||||
import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState;
|
||||
import org.eclipse.hawkbit.ui.common.table.AbstractTableHeader;
|
||||
import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.vaadin.spring.events.EventScope;
|
||||
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
|
||||
|
||||
import com.vaadin.event.dd.DropHandler;
|
||||
import com.vaadin.spring.annotation.SpringComponent;
|
||||
import com.vaadin.spring.annotation.ViewScope;
|
||||
import com.vaadin.ui.Button.ClickEvent;
|
||||
import com.vaadin.ui.UI;
|
||||
import com.vaadin.ui.Window;
|
||||
|
||||
/**
|
||||
* Header of Software module table.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@SpringComponent
|
||||
@ViewScope
|
||||
public class SoftwareModuleTableHeader extends AbstractTableHeader {
|
||||
|
||||
private static final long serialVersionUID = 242961845006626297L;
|
||||
|
||||
@Autowired
|
||||
private ArtifactUploadState artifactUploadState;
|
||||
|
||||
@Autowired
|
||||
private SoftwareModuleAddUpdateWindow softwareModuleAddUpdateWindow;
|
||||
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void onEvent(final UploadArtifactUIEvent event) {
|
||||
if (event == UploadArtifactUIEvent.HIDE_FILTER_BY_TYPE) {
|
||||
setFilterButtonsIconVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getHeaderCaption() {
|
||||
return i18n.get("upload.swModuleTable.header");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSearchBoxId() {
|
||||
return SPUIComponetIdProvider.SW_MODULE_SEARCH_TEXT_FIELD;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSearchRestIconId() {
|
||||
return SPUIComponetIdProvider.SW_MODULE_SEARCH_RESET_ICON;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getAddIconId() {
|
||||
return SPUIComponetIdProvider.SW_MODULE_ADD_BUTTON;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String onLoadSearchBoxValue() {
|
||||
if (artifactUploadState.getSoftwareModuleFilters().getSearchText().isPresent()) {
|
||||
return artifactUploadState.getSoftwareModuleFilters().getSearchText().get();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDropFilterId() {
|
||||
/* No dropping on software module table header in Upload View */
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasCreatePermission() {
|
||||
return permChecker.hasCreateDistributionPermission();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isDropHintRequired() {
|
||||
/* No dropping on software module table header in Upload View */
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isDropFilterRequired() {
|
||||
/* No dropping on software module table header in Upload View */
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getShowFilterButtonLayoutId() {
|
||||
return "show.type.icon";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void showFilterButtonsLayout() {
|
||||
artifactUploadState.setSwTypeFilterClosed(false);
|
||||
eventbus.publish(this, UploadArtifactUIEvent.SHOW_FILTER_BY_TYPE);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void resetSearchText() {
|
||||
if (artifactUploadState.getSoftwareModuleFilters().getSearchText().isPresent()) {
|
||||
artifactUploadState.getSoftwareModuleFilters().setSearchText(null);
|
||||
eventbus.publish(this, SMFilterEvent.REMOVER_FILTER_BY_TEXT);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getMaxMinIconId() {
|
||||
return SPUIComponetIdProvider.SW_MAX_MIN_TABLE_ICON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void maximizeTable() {
|
||||
artifactUploadState.setSwModuleTableMaximized(Boolean.TRUE);
|
||||
eventbus.publish(this, new SoftwareModuleEvent(BaseEntityEventType.MAXIMIZED, null));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void minimizeTable() {
|
||||
artifactUploadState.setSwModuleTableMaximized(Boolean.FALSE);
|
||||
eventbus.publish(this, new SoftwareModuleEvent(BaseEntityEventType.MINIMIZED, null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean onLoadIsTableMaximized() {
|
||||
return artifactUploadState.isSwModuleTableMaximized();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean onLoadIsShowFilterButtonDisplayed() {
|
||||
return artifactUploadState.isSwTypeFilterClosed();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void searchBy(final String newSearchText) {
|
||||
artifactUploadState.getSoftwareModuleFilters().setSearchText(newSearchText);
|
||||
eventbus.publish(this, SMFilterEvent.FILTER_BY_TEXT);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addNewItem(final ClickEvent event) {
|
||||
final Window addSoftwareModule = softwareModuleAddUpdateWindow.createAddSoftwareModuleWindow();
|
||||
addSoftwareModule.setCaption(i18n.get("upload.caption.add.new.swmodule"));
|
||||
UI.getCurrent().addWindow(addSoftwareModule);
|
||||
addSoftwareModule.setVisible(Boolean.TRUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isAddNewItemAllowed() {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getFilterIconStyle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDropFilterWrapperId() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DropHandler getDropFilterHandler() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBulkUploadIconId() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bulkUpload(final ClickEvent event) {
|
||||
// No implementation as no bulk upload is supported.
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isBulkUploadAllowed() {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isBulkUploadInProgress() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,47 +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.artifacts.smtable;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.eclipse.hawkbit.ui.common.table.AbstractTableLayout;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.vaadin.spring.annotation.SpringComponent;
|
||||
import com.vaadin.spring.annotation.ViewScope;
|
||||
|
||||
/**
|
||||
* Software module table layout.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@SpringComponent
|
||||
@ViewScope
|
||||
public class SoftwareModuleTableLayout extends AbstractTableLayout {
|
||||
|
||||
private static final long serialVersionUID = 6464291374980641235L;
|
||||
|
||||
@Autowired
|
||||
private SoftwareModuleDetails softwareModuleDetails;
|
||||
|
||||
@Autowired
|
||||
private SoftwareModuleTableHeader smTableHeader;
|
||||
|
||||
@Autowired
|
||||
private SoftwareModuleTable smTable;
|
||||
|
||||
/**
|
||||
* Initialize the filter layout.
|
||||
*/
|
||||
@PostConstruct
|
||||
void init() {
|
||||
super.init(smTableHeader, smTable, softwareModuleDetails);
|
||||
}
|
||||
}
|
||||
@@ -1,814 +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.artifacts.smtype;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.hawkbit.repository.SoftwareManagement;
|
||||
import org.eclipse.hawkbit.repository.SpPermissionChecker;
|
||||
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.common.CoordinatesToColor;
|
||||
import org.eclipse.hawkbit.ui.common.SoftwareModuleTypeBeanQuery;
|
||||
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
|
||||
import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder;
|
||||
import org.eclipse.hawkbit.ui.management.tag.SpColorPickerPreview;
|
||||
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.I18N;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.UINotification;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory;
|
||||
import org.vaadin.spring.events.EventBus;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.vaadin.data.Property.ValueChangeEvent;
|
||||
import com.vaadin.data.Property.ValueChangeListener;
|
||||
import com.vaadin.server.FontAwesome;
|
||||
import com.vaadin.server.Page;
|
||||
import com.vaadin.shared.ui.colorpicker.Color;
|
||||
import com.vaadin.spring.annotation.SpringComponent;
|
||||
import com.vaadin.spring.annotation.ViewScope;
|
||||
import com.vaadin.ui.AbstractColorPicker.Coordinates2Color;
|
||||
import com.vaadin.ui.Alignment;
|
||||
import com.vaadin.ui.Button;
|
||||
import com.vaadin.ui.ComboBox;
|
||||
import com.vaadin.ui.CustomComponent;
|
||||
import com.vaadin.ui.HorizontalLayout;
|
||||
import com.vaadin.ui.Label;
|
||||
import com.vaadin.ui.OptionGroup;
|
||||
import com.vaadin.ui.Slider;
|
||||
import com.vaadin.ui.Slider.ValueOutOfBoundsException;
|
||||
import com.vaadin.ui.TextArea;
|
||||
import com.vaadin.ui.TextField;
|
||||
import com.vaadin.ui.UI;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
import com.vaadin.ui.Window;
|
||||
import com.vaadin.ui.components.colorpicker.ColorChangeEvent;
|
||||
import com.vaadin.ui.components.colorpicker.ColorChangeListener;
|
||||
import com.vaadin.ui.components.colorpicker.ColorPickerGradient;
|
||||
import com.vaadin.ui.components.colorpicker.ColorSelector;
|
||||
import com.vaadin.ui.themes.ValoTheme;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
@SpringComponent
|
||||
@ViewScope
|
||||
public class CreateUpdateSoftwareTypeLayout extends CustomComponent implements ColorChangeListener, ColorSelector {
|
||||
|
||||
private static final long serialVersionUID = -5169398523815919367L;
|
||||
private static final Logger LOG = LoggerFactory.getLogger(CreateUpdateSoftwareTypeLayout.class);
|
||||
|
||||
@Autowired
|
||||
private SpPermissionChecker permChecker;
|
||||
|
||||
@Autowired
|
||||
private I18N i18n;
|
||||
|
||||
/**
|
||||
* Instance of ColorPickerPreview.
|
||||
*/
|
||||
private SpColorPickerPreview selPreview;
|
||||
|
||||
@Autowired
|
||||
private transient UINotification uiNotification;
|
||||
|
||||
@Autowired
|
||||
private transient SoftwareManagement swTypeManagementService;
|
||||
|
||||
@Autowired
|
||||
private transient EventBus.SessionEventBus eventBus;
|
||||
|
||||
private String createTypeStr;
|
||||
private String updateTypeStr;
|
||||
private String singleAssignStr;
|
||||
private String multiAssignStr;
|
||||
private Label createType;
|
||||
private Label updateType;
|
||||
private Label singleAssign;
|
||||
private Label multiAssign;
|
||||
private Label comboLabel;
|
||||
private Label colorLabel;
|
||||
private Label madatoryLabel;
|
||||
private TextField typeName;
|
||||
private TextField typeKey;
|
||||
private TextArea typeDesc;
|
||||
private Button saveTag;
|
||||
private Button discardTag;
|
||||
private Button tagColorPreviewBtn;
|
||||
private OptionGroup createOptiongroup;
|
||||
private OptionGroup assignOptiongroup;
|
||||
private ComboBox typeNameComboBox;
|
||||
protected static final String DEFAULT_COLOR = "rgb(44,151,32)";
|
||||
private static final String TYPE_NAME_DYNAMIC_STYLE = "new-tag-name";
|
||||
private static final String TYPE_DESC_DYNAMIC_STYLE = "new-tag-desc";
|
||||
private static final String TAG_DYNAMIC_STYLE = "tag-color-preview";
|
||||
private Set<ColorSelector> selectors;
|
||||
private Color selectedColor;
|
||||
private ColorPickerGradient colorSelect;
|
||||
private Slider redSlider;
|
||||
private Slider greenSlider;
|
||||
private Slider blueSlider;
|
||||
private Window swTypeWindow;
|
||||
protected boolean tagPreviewBtnClicked = false;
|
||||
private VerticalLayout comboLayout;
|
||||
private VerticalLayout sliders;
|
||||
private VerticalLayout colorPickerLayout;
|
||||
private HorizontalLayout mainLayout;
|
||||
private VerticalLayout fieldLayout;
|
||||
|
||||
/** RGB color converter. */
|
||||
private final Coordinates2Color rgbConverter = new CoordinatesToColor();
|
||||
|
||||
/**
|
||||
* Initialize the artifact details layout.
|
||||
*/
|
||||
public void init() {
|
||||
createComponents();
|
||||
buildLayout();
|
||||
addListeners();
|
||||
}
|
||||
|
||||
private void createComponents() {
|
||||
createTypeStr = i18n.get("label.create.type");
|
||||
updateTypeStr = i18n.get("label.update.type");
|
||||
singleAssignStr = i18n.get("label.singleAssign.type");
|
||||
multiAssignStr = i18n.get("label.multiAssign.type");
|
||||
createType = SPUIComponentProvider.getLabel(createTypeStr, null);
|
||||
updateType = SPUIComponentProvider.getLabel(updateTypeStr, null);
|
||||
singleAssign = SPUIComponentProvider.getLabel(singleAssignStr, null);
|
||||
multiAssign = SPUIComponentProvider.getLabel(multiAssignStr, null);
|
||||
comboLabel = SPUIComponentProvider.getLabel(i18n.get("label.choose.type"), null);
|
||||
madatoryLabel = getMandatoryLabel();
|
||||
colorLabel = SPUIComponentProvider.getLabel(i18n.get("label.choose.type.color"), null);
|
||||
colorLabel.addStyleName(SPUIDefinitions.COLOR_LABEL_STYLE);
|
||||
|
||||
typeName = SPUIComponentProvider.getTextField("", ValoTheme.TEXTFIELD_TINY + " " + SPUIDefinitions.TYPE_NAME,
|
||||
true, "", i18n.get("textfield.name"), true, SPUILabelDefinitions.TEXT_FIELD_MAX_LENGTH);
|
||||
typeName.setId(SPUIDefinitions.NEW_SOFTWARE_TYPE_NAME);
|
||||
|
||||
typeKey = SPUIComponentProvider.getTextField("", ValoTheme.TEXTFIELD_TINY + " " + SPUIDefinitions.TYPE_KEY,
|
||||
true, "", i18n.get("textfield.key"), true, SPUILabelDefinitions.TEXT_FIELD_MAX_LENGTH);
|
||||
typeKey.setId(SPUIDefinitions.NEW_SOFTWARE_TYPE_KEY);
|
||||
|
||||
typeDesc = SPUIComponentProvider.getTextArea("", ValoTheme.TEXTFIELD_TINY + " " + SPUIDefinitions.TYPE_DESC,
|
||||
false, "", i18n.get("textfield.description"), SPUILabelDefinitions.TEXT_AREA_MAX_LENGTH);
|
||||
|
||||
typeDesc.setId(SPUIDefinitions.NEW_SOFTWARE_TYPE_DESC);
|
||||
typeDesc.setImmediate(true);
|
||||
typeDesc.setNullRepresentation("");
|
||||
|
||||
typeNameComboBox = SPUIComponentProvider.getComboBox("", "", null, null, false, "",
|
||||
i18n.get("label.combobox.type"));
|
||||
typeNameComboBox.addStyleName(SPUIDefinitions.FILTER_TYPE_COMBO_STYLE);
|
||||
typeNameComboBox.setImmediate(true);
|
||||
|
||||
saveTag = SPUIComponentProvider.getButton(SPUIDefinitions.NEW_SW_TYPE_SAVE, "", "", "", true, FontAwesome.SAVE,
|
||||
SPUIButtonStyleSmallNoBorder.class);
|
||||
saveTag.addStyleName(ValoTheme.BUTTON_BORDERLESS);
|
||||
|
||||
discardTag = SPUIComponentProvider.getButton(SPUIDefinitions.NEW_TARGET_TAG_DISRACD, "", "",
|
||||
"discard-button-style", true, FontAwesome.TIMES, SPUIButtonStyleSmallNoBorder.class);
|
||||
discardTag.addStyleName(ValoTheme.BUTTON_BORDERLESS);
|
||||
|
||||
tagColorPreviewBtn = new Button();
|
||||
tagColorPreviewBtn.setId(SPUIComponetIdProvider.TAG_COLOR_PREVIEW_ID);
|
||||
getPreviewButtonColor(DEFAULT_COLOR);
|
||||
tagColorPreviewBtn.setStyleName(TAG_DYNAMIC_STYLE);
|
||||
|
||||
selectors = new HashSet<>();
|
||||
selectedColor = new Color(44, 151, 32);
|
||||
selPreview = new SpColorPickerPreview(selectedColor);
|
||||
|
||||
colorSelect = new ColorPickerGradient("rgb-gradient", rgbConverter);
|
||||
colorSelect.setColor(selectedColor);
|
||||
colorSelect.setWidth("220px");
|
||||
|
||||
redSlider = createRGBSlider("", "red");
|
||||
greenSlider = createRGBSlider("", "green");
|
||||
blueSlider = createRGBSlider("", "blue");
|
||||
setRgbSliderValues(selectedColor);
|
||||
|
||||
createUpdateOptionGroup();
|
||||
|
||||
singleMultiOptionGroup();
|
||||
|
||||
}
|
||||
|
||||
private void buildLayout() {
|
||||
comboLayout = new VerticalLayout();
|
||||
|
||||
sliders = new VerticalLayout();
|
||||
sliders.addComponents(redSlider, greenSlider, blueSlider);
|
||||
|
||||
selectors.add(colorSelect);
|
||||
|
||||
colorPickerLayout = new VerticalLayout();
|
||||
colorPickerLayout.setStyleName("rgb-vertical-layout");
|
||||
colorPickerLayout.addComponent(selPreview);
|
||||
colorPickerLayout.addComponent(colorSelect);
|
||||
|
||||
fieldLayout = new VerticalLayout();
|
||||
fieldLayout.setSpacing(true);
|
||||
fieldLayout.setMargin(false);
|
||||
fieldLayout.setWidth("100%");
|
||||
fieldLayout.setHeight(null);
|
||||
fieldLayout.addComponent(createOptiongroup);
|
||||
fieldLayout.addComponent(comboLayout);
|
||||
fieldLayout.addComponent(madatoryLabel);
|
||||
fieldLayout.addComponent(typeName);
|
||||
fieldLayout.addComponent(typeKey);
|
||||
fieldLayout.addComponent(typeDesc);
|
||||
fieldLayout.addComponent(assignOptiongroup);
|
||||
|
||||
final HorizontalLayout colorLabelLayout = new HorizontalLayout();
|
||||
colorLabelLayout.addComponents(colorLabel, tagColorPreviewBtn);
|
||||
fieldLayout.addComponent(colorLabelLayout);
|
||||
|
||||
final HorizontalLayout buttonLayout = new HorizontalLayout();
|
||||
buttonLayout.addComponent(saveTag);
|
||||
buttonLayout.addComponent(discardTag);
|
||||
buttonLayout.setComponentAlignment(discardTag, Alignment.BOTTOM_RIGHT);
|
||||
buttonLayout.setComponentAlignment(saveTag, Alignment.BOTTOM_LEFT);
|
||||
buttonLayout.addStyleName("window-style");
|
||||
buttonLayout.setWidth("152px");
|
||||
|
||||
final VerticalLayout fieldButtonLayout = new VerticalLayout();
|
||||
fieldButtonLayout.addComponent(fieldLayout);
|
||||
fieldButtonLayout.addComponent(buttonLayout);
|
||||
|
||||
mainLayout = new HorizontalLayout();
|
||||
mainLayout.addComponent(fieldButtonLayout);
|
||||
setCompositionRoot(mainLayout);
|
||||
}
|
||||
|
||||
private void addListeners() {
|
||||
saveTag.addClickListener(event -> save());
|
||||
discardTag.addClickListener(event -> discard());
|
||||
colorSelect.addColorChangeListener(this);
|
||||
selPreview.addColorChangeListener(this);
|
||||
tagColorPreviewBtn.addClickListener(event -> previewButtonClicked());
|
||||
createOptiongroup.addValueChangeListener(event -> createOptionValueChanged(event));
|
||||
typeNameComboBox.addValueChangeListener(event -> typeNameChosen(event));
|
||||
slidersValueChangeListeners();
|
||||
}
|
||||
|
||||
public Window getWindow() {
|
||||
reset();
|
||||
swTypeWindow = SPUIComponentProvider.getWindow(i18n.get("caption.add.type"), null,
|
||||
SPUIDefinitions.CREATE_UPDATE_WINDOW);
|
||||
swTypeWindow.setContent(this);
|
||||
return swTypeWindow;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener for option group - Create tag/Update.
|
||||
*
|
||||
* @param event
|
||||
* ValueChangeEvent
|
||||
*/
|
||||
private void createOptionValueChanged(final ValueChangeEvent event) {
|
||||
if ("Update Type".equals(event.getProperty().getValue())) {
|
||||
typeName.clear();
|
||||
typeDesc.clear();
|
||||
typeKey.clear();
|
||||
typeKey.setEnabled(false);
|
||||
typeName.setEnabled(false);
|
||||
assignOptiongroup.setEnabled(false);
|
||||
|
||||
populateTypeNameCombo();
|
||||
// show target name combo
|
||||
comboLayout.addComponent(comboLabel);
|
||||
comboLayout.addComponent(typeNameComboBox);
|
||||
} else {
|
||||
typeKey.setEnabled(true);
|
||||
typeName.setEnabled(true);
|
||||
typeName.clear();
|
||||
typeDesc.clear();
|
||||
typeKey.clear();
|
||||
assignOptiongroup.setEnabled(true);
|
||||
// hide target name combo
|
||||
comboLayout.removeComponent(comboLabel);
|
||||
comboLayout.removeComponent(typeNameComboBox);
|
||||
}
|
||||
// close the color picker layout
|
||||
tagPreviewBtnClicked = false;
|
||||
// reset the selected color - Set defualt color
|
||||
restoreComponentStyles();
|
||||
getPreviewButtonColor(DEFAULT_COLOR);
|
||||
selPreview.setColor(rgbToColorConverter(DEFAULT_COLOR));
|
||||
// remove the sliders and color picker layout
|
||||
fieldLayout.removeComponent(sliders);
|
||||
mainLayout.removeComponent(colorPickerLayout);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate Software Module Type name combo.
|
||||
*/
|
||||
public void populateTypeNameCombo() {
|
||||
typeNameComboBox.setContainerDataSource(HawkbitCommonUtil.createLazyQueryContainer(
|
||||
new BeanQueryFactory<SoftwareModuleTypeBeanQuery>(SoftwareModuleTypeBeanQuery.class)));
|
||||
typeNameComboBox.setItemCaptionPropertyId(SPUILabelDefinitions.VAR_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* reset the components.
|
||||
*/
|
||||
private void reset() {
|
||||
typeName.setEnabled(true);
|
||||
typeName.clear();
|
||||
typeKey.clear();
|
||||
typeDesc.clear();
|
||||
restoreComponentStyles();
|
||||
|
||||
// hide target name combo
|
||||
comboLayout.removeComponent(comboLabel);
|
||||
comboLayout.removeComponent(typeNameComboBox);
|
||||
fieldLayout.removeComponent(sliders);
|
||||
mainLayout.removeComponent(colorPickerLayout);
|
||||
|
||||
createOptiongroup.select(createTypeStr);
|
||||
assignOptiongroup.select(singleAssignStr);
|
||||
// Default green color
|
||||
selectedColor = new Color(44, 151, 32);
|
||||
selPreview.setColor(selectedColor);
|
||||
tagPreviewBtnClicked = false;
|
||||
}
|
||||
|
||||
private void typeNameChosen(final ValueChangeEvent event) {
|
||||
final String tagSelected = (String) event.getProperty().getValue();
|
||||
if (null != tagSelected) {
|
||||
setTypeTagCombo(tagSelected);
|
||||
} else {
|
||||
resetTagNameField();
|
||||
}
|
||||
}
|
||||
|
||||
private void resetTagNameField() {
|
||||
typeName.setEnabled(false);
|
||||
typeName.clear();
|
||||
|
||||
typeKey.clear();
|
||||
typeDesc.clear();
|
||||
restoreComponentStyles();
|
||||
fieldLayout.removeComponent(sliders);
|
||||
mainLayout.removeComponent(colorPickerLayout);
|
||||
|
||||
assignOptiongroup.select(singleAssignStr);
|
||||
// Default green color
|
||||
selectedColor = new Color(44, 151, 32);
|
||||
selPreview.setColor(selectedColor);
|
||||
tagPreviewBtnClicked = false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Select tag & set tag name & tag desc values corresponding to selected
|
||||
* tag.
|
||||
*
|
||||
* @param targetTagSelected
|
||||
* as the selected tag from combo
|
||||
*/
|
||||
private void setTypeTagCombo(final String targetTagSelected) {
|
||||
typeName.setValue(targetTagSelected);
|
||||
final SoftwareModuleType selectedTypeTag = swTypeManagementService
|
||||
.findSoftwareModuleTypeByName(targetTagSelected);
|
||||
if (null != selectedTypeTag) {
|
||||
typeDesc.setValue(selectedTypeTag.getDescription());
|
||||
typeKey.setValue(selectedTypeTag.getKey());
|
||||
if (selectedTypeTag.getMaxAssignments() == Integer.MAX_VALUE) {
|
||||
assignOptiongroup.setValue(multiAssignStr);
|
||||
} else {
|
||||
assignOptiongroup.setValue(singleAssignStr);
|
||||
}
|
||||
|
||||
if (null == selectedTypeTag.getColour()) {
|
||||
selectedColor = new Color(44, 151, 32);
|
||||
selPreview.setColor(selectedColor);
|
||||
colorSelect.setColor(selectedColor);
|
||||
createDynamicStyleForComponents(typeName, typeKey, typeDesc, DEFAULT_COLOR);
|
||||
getPreviewButtonColor(DEFAULT_COLOR);
|
||||
} else {
|
||||
selectedColor = rgbToColorConverter(selectedTypeTag.getColour());
|
||||
selPreview.setColor(selectedColor);
|
||||
colorSelect.setColor(selectedColor);
|
||||
createDynamicStyleForComponents(typeName, typeKey, typeDesc, selectedTypeTag.getColour());
|
||||
getPreviewButtonColor(selectedTypeTag.getColour());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic styles for window.
|
||||
*
|
||||
* @param top
|
||||
* int value
|
||||
* @param marginLeft
|
||||
* int value
|
||||
*/
|
||||
private void getPreviewButtonColor(final String color) {
|
||||
Page.getCurrent().getJavaScript().execute(HawkbitCommonUtil.getPreviewButtonColorScript(color));
|
||||
}
|
||||
|
||||
private void createUpdateOptionGroup() {
|
||||
final List<String> optionValues = new ArrayList<>();
|
||||
if (permChecker.hasCreateDistributionPermission()) {
|
||||
optionValues.add(createType.getValue());
|
||||
}
|
||||
if (permChecker.hasUpdateDistributionPermission()) {
|
||||
optionValues.add(updateType.getValue());
|
||||
}
|
||||
createOptionGroupByValues(optionValues);
|
||||
}
|
||||
|
||||
private void singleMultiOptionGroup() {
|
||||
final List<String> optionValues = new ArrayList<>();
|
||||
optionValues.add(singleAssign.getValue());
|
||||
optionValues.add(multiAssign.getValue());
|
||||
assignOptionGroupByValues(optionValues);
|
||||
}
|
||||
|
||||
private void createOptionGroupByValues(final List<String> tagOptions) {
|
||||
createOptiongroup = new OptionGroup("", tagOptions);
|
||||
createOptiongroup.setStyleName(ValoTheme.OPTIONGROUP_SMALL);
|
||||
createOptiongroup.addStyleName("custom-option-group");
|
||||
createOptiongroup.setNullSelectionAllowed(false);
|
||||
if (!tagOptions.isEmpty()) {
|
||||
createOptiongroup.select(tagOptions.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
private void assignOptionGroupByValues(final List<String> tagOptions) {
|
||||
assignOptiongroup = new OptionGroup("", tagOptions);
|
||||
assignOptiongroup.setStyleName(ValoTheme.OPTIONGROUP_SMALL);
|
||||
assignOptiongroup.addStyleName("custom-option-group");
|
||||
assignOptiongroup.setNullSelectionAllowed(false);
|
||||
assignOptiongroup.select(tagOptions.get(0));
|
||||
}
|
||||
|
||||
private Label getMandatoryLabel() {
|
||||
final Label label = new Label(i18n.get("label.mandatory.field"));
|
||||
label.setStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_ERROR + " " + ValoTheme.LABEL_SMALL);
|
||||
return label;
|
||||
}
|
||||
|
||||
private Slider createRGBSlider(final String caption, final String styleName) {
|
||||
final Slider slider = new Slider(caption, 0, 255);
|
||||
slider.setImmediate(true);
|
||||
slider.setWidth("150px");
|
||||
slider.addStyleName(styleName);
|
||||
return slider;
|
||||
}
|
||||
|
||||
private void setRgbSliderValues(final Color color) {
|
||||
try {
|
||||
final double redColorValue = color.getRed();
|
||||
redSlider.setValue(new Double(redColorValue));
|
||||
final double blueColorValue = color.getBlue();
|
||||
blueSlider.setValue(new Double(blueColorValue));
|
||||
final double greenColorValue = color.getGreen();
|
||||
greenSlider.setValue(new Double(greenColorValue));
|
||||
} catch (final ValueOutOfBoundsException e) {
|
||||
LOG.error("Unable to set RGB color value to " + color.getRed() + "," + color.getGreen() + ","
|
||||
+ color.getBlue(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Value change listeners implementations of sliders.
|
||||
*/
|
||||
private void slidersValueChangeListeners() {
|
||||
redSlider.addValueChangeListener(new ValueChangeListener() {
|
||||
private static final long serialVersionUID = -8336732888800920839L;
|
||||
|
||||
@Override
|
||||
public void valueChange(final ValueChangeEvent event) {
|
||||
final double red = (Double) event.getProperty().getValue();
|
||||
final Color newColor = new Color((int) red, selectedColor.getGreen(), selectedColor.getBlue());
|
||||
setColorToComponents(newColor);
|
||||
}
|
||||
});
|
||||
greenSlider.addValueChangeListener(new ValueChangeListener() {
|
||||
private static final long serialVersionUID = 1236358037766775663L;
|
||||
|
||||
@Override
|
||||
public void valueChange(final ValueChangeEvent event) {
|
||||
final double green = (Double) event.getProperty().getValue();
|
||||
final Color newColor = new Color(selectedColor.getRed(), (int) green, selectedColor.getBlue());
|
||||
setColorToComponents(newColor);
|
||||
}
|
||||
});
|
||||
blueSlider.addValueChangeListener(new ValueChangeListener() {
|
||||
private static final long serialVersionUID = 8466370763686043947L;
|
||||
|
||||
@Override
|
||||
public void valueChange(final ValueChangeEvent event) {
|
||||
final double blue = (Double) event.getProperty().getValue();
|
||||
final Color newColor = new Color(selectedColor.getRed(), selectedColor.getGreen(), (int) blue);
|
||||
setColorToComponents(newColor);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setColorToComponents(final Color newColor) {
|
||||
setColor(newColor);
|
||||
colorSelect.setColor(newColor);
|
||||
getPreviewButtonColor(newColor.getCSS());
|
||||
createDynamicStyleForComponents(typeName, typeKey, typeDesc, newColor.getCSS());
|
||||
}
|
||||
|
||||
/**
|
||||
* reset the tag name and tag description component border color.
|
||||
*/
|
||||
private void restoreComponentStyles() {
|
||||
typeName.removeStyleName(TYPE_NAME_DYNAMIC_STYLE);
|
||||
typeDesc.removeStyleName(TYPE_DESC_DYNAMIC_STYLE);
|
||||
typeKey.removeStyleName(TYPE_NAME_DYNAMIC_STYLE);
|
||||
getPreviewButtonColor(DEFAULT_COLOR);
|
||||
}
|
||||
|
||||
private void save() {
|
||||
if (mandatoryValuesPresent()) {
|
||||
final SoftwareModuleType existingType = swTypeManagementService
|
||||
.findSoftwareModuleTypeByName(typeName.getValue());
|
||||
if (createOptiongroup.getValue().equals(createTypeStr)) {
|
||||
if (!checkIsKeyDuplicate(typeKey.getValue()) && !checkIsDuplicate(existingType)) {
|
||||
crateNewSWModuleType();
|
||||
}
|
||||
} else {
|
||||
|
||||
updateSWModuleType(existingType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkIsKeyDuplicate(final String key) {
|
||||
final SoftwareModuleType existingKeyType = swTypeManagementService.findSoftwareModuleTypeByKey(key);
|
||||
if (existingKeyType != null) {
|
||||
uiNotification.displayValidationError(
|
||||
i18n.get("message.type.key.swmodule.duplicate.check", new Object[] { existingKeyType.getKey() }));
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
private Boolean mandatoryValuesPresent() {
|
||||
if (Strings.isNullOrEmpty(typeName.getValue()) && Strings.isNullOrEmpty(typeKey.getValue())) {
|
||||
if (createOptiongroup.getValue().equals(createTypeStr)) {
|
||||
uiNotification.displayValidationError(SPUILabelDefinitions.MISSING_TYPE_NAME_KEY);
|
||||
}
|
||||
if (createOptiongroup.getValue().equals(updateTypeStr)) {
|
||||
if (null == typeNameComboBox.getValue()) {
|
||||
uiNotification.displayValidationError(i18n.get("message.error.missing.typename"));
|
||||
} else {
|
||||
uiNotification.displayValidationError(SPUILabelDefinitions.MISSING_TAG_NAME);
|
||||
}
|
||||
}
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
private Boolean checkIsDuplicate(final SoftwareModuleType existingType) {
|
||||
if (existingType != null) {
|
||||
uiNotification.displayValidationError(
|
||||
i18n.get("message.tag.duplicate.check", new Object[] { existingType.getName() }));
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
private void closeWindow() {
|
||||
swTypeWindow.close();
|
||||
UI.getCurrent().removeWindow(swTypeWindow);
|
||||
}
|
||||
|
||||
private void discard() {
|
||||
UI.getCurrent().removeWindow(swTypeWindow);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new tag.
|
||||
*/
|
||||
private void crateNewSWModuleType() {
|
||||
int assignNumber = 0;
|
||||
final String colorPicked = getColorPickedSting();
|
||||
final String typeNameValue = HawkbitCommonUtil.trimAndNullIfEmpty(typeName.getValue());
|
||||
final String typeKeyValue = HawkbitCommonUtil.trimAndNullIfEmpty(typeKey.getValue());
|
||||
final String typeDescValue = HawkbitCommonUtil.trimAndNullIfEmpty(typeDesc.getValue());
|
||||
final String assignValue = (String) assignOptiongroup.getValue();
|
||||
if (null != assignValue && assignValue.equalsIgnoreCase(singleAssignStr)) {
|
||||
assignNumber = 1;
|
||||
} else if (null != assignValue && assignValue.equalsIgnoreCase(multiAssignStr)) {
|
||||
assignNumber = Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
if (null != typeNameValue && null != typeKeyValue) {
|
||||
SoftwareModuleType newSWType = new SoftwareModuleType(typeKeyValue, typeNameValue, typeDescValue,
|
||||
assignNumber, colorPicked);
|
||||
if (null != typeDescValue) {
|
||||
newSWType.setDescription(typeDescValue);
|
||||
}
|
||||
|
||||
newSWType.setColour(colorPicked);
|
||||
|
||||
newSWType = swTypeManagementService.createSoftwareModuleType(newSWType);
|
||||
uiNotification.displaySuccess(i18n.get("message.save.success", new Object[] { newSWType.getName() }));
|
||||
closeWindow();
|
||||
eventBus.publish(this,
|
||||
new SoftwareModuleTypeEvent(SoftwareModuleTypeEnum.ADD_SOFTWARE_MODULE_TYPE, newSWType));
|
||||
|
||||
} else {
|
||||
uiNotification.displayValidationError(i18n.get("message.error.missing.typenameorkey"));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get color picked value in string.
|
||||
*
|
||||
* @return String of color picked value.
|
||||
*/
|
||||
private String getColorPickedSting() {
|
||||
return "rgb(" + getSelPreview().getColor().getRed() + "," + getSelPreview().getColor().getGreen() + ","
|
||||
+ getSelPreview().getColor().getBlue() + ")";
|
||||
}
|
||||
|
||||
/**
|
||||
* Color view.
|
||||
*
|
||||
* @return ColorPickerPreview as UI
|
||||
*/
|
||||
public SpColorPickerPreview getSelPreview() {
|
||||
return selPreview;
|
||||
}
|
||||
|
||||
/**
|
||||
* update tag.
|
||||
*/
|
||||
private void updateSWModuleType(final SoftwareModuleType existingType) {
|
||||
|
||||
final String typeNameValue = HawkbitCommonUtil.trimAndNullIfEmpty(typeName.getValue());
|
||||
final String typeDescValue = HawkbitCommonUtil.trimAndNullIfEmpty(typeDesc.getValue());
|
||||
if (null != typeNameValue) {
|
||||
existingType.setName(typeNameValue);
|
||||
|
||||
existingType.setDescription(null != typeDescValue ? typeDescValue : null);
|
||||
|
||||
existingType.setColour(getColorPickedSting());
|
||||
swTypeManagementService.updateSoftwareModuleType(existingType);
|
||||
uiNotification.displaySuccess(i18n.get("message.update.success", new Object[] { existingType.getName() }));
|
||||
closeWindow();
|
||||
eventBus.publish(this,
|
||||
new SoftwareModuleTypeEvent(SoftwareModuleTypeEnum.UPDATE_SOFTWARE_MODULE_TYPE, existingType));
|
||||
|
||||
} else {
|
||||
uiNotification.displayValidationError(i18n.get("message.tag.update.mandatory"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Open color picker on click of preview button. Auto select the color based
|
||||
* on target tag if already selected.
|
||||
*/
|
||||
private void previewButtonClicked() {
|
||||
if (!tagPreviewBtnClicked) {
|
||||
final String selectedOption = (String) createOptiongroup.getValue();
|
||||
if (null != selectedOption && selectedOption.equalsIgnoreCase(updateTypeStr)) {
|
||||
if (null != typeNameComboBox.getValue()) {
|
||||
|
||||
final SoftwareModuleType typeSelected = swTypeManagementService
|
||||
.findSoftwareModuleTypeByName(typeNameComboBox.getValue().toString());
|
||||
if (null != typeSelected) {
|
||||
selectedColor = typeSelected.getColour() != null ? rgbToColorConverter(typeSelected.getColour())
|
||||
: rgbToColorConverter(DEFAULT_COLOR);
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
selectedColor = rgbToColorConverter(DEFAULT_COLOR);
|
||||
}
|
||||
}
|
||||
selPreview.setColor(selectedColor);
|
||||
fieldLayout.addComponent(sliders);
|
||||
mainLayout.addComponent(colorPickerLayout);
|
||||
mainLayout.setComponentAlignment(colorPickerLayout, Alignment.BOTTOM_CENTER);
|
||||
}
|
||||
tagPreviewBtnClicked = !tagPreviewBtnClicked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Covert RGB code to {@Color}.
|
||||
*
|
||||
* @param value
|
||||
* RGB vale
|
||||
* @return Color
|
||||
*/
|
||||
protected Color rgbToColorConverter(final String value) {
|
||||
if (value.startsWith("rgb")) {
|
||||
final String[] colors = value.substring(value.indexOf('(') + 1, value.length() - 1).split(",");
|
||||
final int red = Integer.parseInt(colors[0]);
|
||||
final int green = Integer.parseInt(colors[1]);
|
||||
final int blue = Integer.parseInt(colors[2]);
|
||||
if (colors.length > 3) {
|
||||
final int alpha = (int) (Double.parseDouble(colors[3]) * 255d);
|
||||
return new Color(red, green, blue, alpha);
|
||||
} else {
|
||||
return new Color(red, green, blue);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addColorChangeListener(final ColorChangeListener listener) {
|
||||
LOG.debug("inside addColorChangeListener");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeColorChangeListener(final ColorChangeListener listener) {
|
||||
LOG.debug("inside removeColorChangeListener");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColor(final Color color) {
|
||||
if (color == null) {
|
||||
return;
|
||||
}
|
||||
selectedColor = color;
|
||||
selPreview.setColor(selectedColor);
|
||||
final String colorPickedPreview = selPreview.getColor().getCSS();
|
||||
if (typeName.isEnabled() && null != colorSelect) {
|
||||
createDynamicStyleForComponents(typeName, typeKey, typeDesc, colorPickedPreview);
|
||||
colorSelect.setColor(selPreview.getColor());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getColor() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void colorChanged(final ColorChangeEvent event) {
|
||||
setColor(event.getColor());
|
||||
for (final ColorSelector select : selectors) {
|
||||
if (!event.getSource().equals(select) && select.equals(this) && !select.getColor().equals(selectedColor)) {
|
||||
select.setColor(selectedColor);
|
||||
}
|
||||
}
|
||||
setRgbSliderValues(selectedColor);
|
||||
getPreviewButtonColor(event.getColor().getCSS());
|
||||
createDynamicStyleForComponents(typeName, typeKey, typeDesc, event.getColor().getCSS());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set tag name and desc field border color based on chosen color.
|
||||
*
|
||||
* @param tagName
|
||||
* @param tagDesc
|
||||
* @param taregtTagColor
|
||||
*/
|
||||
private void createDynamicStyleForComponents(final TextField typeName, final TextField typeKey,
|
||||
final TextArea typeDesc, final String typeTagColor) {
|
||||
getTargetDynamicStyles(typeTagColor);
|
||||
typeName.addStyleName(TYPE_NAME_DYNAMIC_STYLE);
|
||||
typeKey.addStyleName(TYPE_NAME_DYNAMIC_STYLE);
|
||||
typeDesc.addStyleName(TYPE_DESC_DYNAMIC_STYLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get target style - Dynamically as per the color picked, cannot be done
|
||||
* from the static css.
|
||||
*
|
||||
* @param colorPickedPreview
|
||||
*/
|
||||
private void getTargetDynamicStyles(final String colorPickedPreview) {
|
||||
Page.getCurrent().getJavaScript()
|
||||
.execute(HawkbitCommonUtil.changeToNewSelectedPreviewColor(colorPickedPreview));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,72 +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.artifacts.smtype;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.eclipse.hawkbit.repository.SoftwareManagement;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.eclipse.hawkbit.ui.artifacts.event.SMFilterEvent;
|
||||
import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState;
|
||||
import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterSingleButtonClick;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.vaadin.spring.events.EventBus;
|
||||
|
||||
import com.vaadin.spring.annotation.SpringComponent;
|
||||
import com.vaadin.spring.annotation.ViewScope;
|
||||
import com.vaadin.ui.Button;
|
||||
|
||||
/**
|
||||
* Single button click behaviour of filter buttons layout.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@SpringComponent
|
||||
@ViewScope
|
||||
public class SMTypeFilterButtonClick extends AbstractFilterSingleButtonClick implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 3707945900524967887L;
|
||||
|
||||
@Autowired
|
||||
private transient EventBus.SessionEventBus eventBus;
|
||||
|
||||
@Autowired
|
||||
private ArtifactUploadState artifactUploadState;
|
||||
|
||||
@Autowired
|
||||
private transient SoftwareManagement softwareManagement;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.hawkbit.server.ui.layouts.SPFilterButtonClickBehaviour#
|
||||
* filterUnClicked(com.vaadin.ui. Button)
|
||||
*/
|
||||
@Override
|
||||
protected void filterUnClicked(final Button clickedButton) {
|
||||
artifactUploadState.getSoftwareModuleFilters().setSoftwareModuleType(null);
|
||||
eventBus.publish(this, SMFilterEvent.FILTER_BY_TYPE);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see hawkbit.server.ui.layouts.SPFilterButtonClickBehaviour#filterClicked
|
||||
* (com.vaadin.ui.Button )
|
||||
*/
|
||||
@Override
|
||||
protected void filterClicked(final Button clickedButton) {
|
||||
final SoftwareModuleType softwareModuleType = softwareManagement
|
||||
.findSoftwareModuleTypeByName(clickedButton.getData().toString());
|
||||
artifactUploadState.getSoftwareModuleFilters().setSoftwareModuleType(softwareModuleType);
|
||||
eventBus.publish(this, SMFilterEvent.FILTER_BY_TYPE);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,113 +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.artifacts.smtype;
|
||||
|
||||
import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleTypeEvent;
|
||||
import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent;
|
||||
import org.eclipse.hawkbit.ui.artifacts.event.UploadViewAcceptCriteria;
|
||||
import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState;
|
||||
import org.eclipse.hawkbit.ui.common.SoftwareModuleTypeBeanQuery;
|
||||
import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterButtons;
|
||||
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory;
|
||||
import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer;
|
||||
import org.vaadin.spring.events.EventScope;
|
||||
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
|
||||
|
||||
import com.vaadin.event.dd.DragAndDropEvent;
|
||||
import com.vaadin.event.dd.DropHandler;
|
||||
import com.vaadin.event.dd.acceptcriteria.AcceptCriterion;
|
||||
import com.vaadin.spring.annotation.SpringComponent;
|
||||
import com.vaadin.spring.annotation.ViewScope;
|
||||
|
||||
/**
|
||||
* Software module type filter buttons.
|
||||
*
|
||||
*/
|
||||
@SpringComponent
|
||||
@ViewScope
|
||||
public class SMTypeFilterButtons extends AbstractFilterButtons {
|
||||
|
||||
private static final long serialVersionUID = 169198312654380358L;
|
||||
|
||||
@Autowired
|
||||
private ArtifactUploadState artifactUploadState;
|
||||
|
||||
@Autowired
|
||||
private UploadViewAcceptCriteria uploadViewAcceptCriteria;
|
||||
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void onEvent(final SoftwareModuleTypeEvent event) {
|
||||
if (event.getSoftwareModuleTypeEnum() == SoftwareModuleTypeEvent.SoftwareModuleTypeEnum.ADD_SOFTWARE_MODULE_TYPE
|
||||
|| event.getSoftwareModuleTypeEnum() == SoftwareModuleTypeEvent.SoftwareModuleTypeEnum.UPDATE_SOFTWARE_MODULE_TYPE
|
||||
|| event.getSoftwareModuleTypeEnum() == SoftwareModuleTypeEvent.SoftwareModuleTypeEnum.DELETE_SOFTWARE_MODULE_TYPE
|
||||
&& event.getSoftwareModuleType() != null) {
|
||||
refreshTable();
|
||||
}
|
||||
}
|
||||
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void onEvent(final UploadArtifactUIEvent event) {
|
||||
if (event == UploadArtifactUIEvent.DELETED_ALL_SOFWARE_TYPE) {
|
||||
refreshTable();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getButtonsTableId() {
|
||||
return SPUIComponetIdProvider.SW_MODULE_TYPE_TABLE_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LazyQueryContainer createButtonsLazyQueryContainer() {
|
||||
return HawkbitCommonUtil.createLazyQueryContainer(
|
||||
new BeanQueryFactory<SoftwareModuleTypeBeanQuery>(SoftwareModuleTypeBeanQuery.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isClickedByDefault(final String typeName) {
|
||||
return artifactUploadState.getSoftwareModuleFilters().getSoftwareModuleType().isPresent() && artifactUploadState
|
||||
.getSoftwareModuleFilters().getSoftwareModuleType().get().getName().equals(typeName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String createButtonId(final String name) {
|
||||
return SPUIComponetIdProvider.SM_TYPE_FILTER_BTN_ID + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DropHandler getFilterButtonDropHandler() {
|
||||
return new DropHandler() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public AcceptCriterion getAcceptCriterion() {
|
||||
return uploadViewAcceptCriteria;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drop(final DragAndDropEvent event) {
|
||||
/* Not required */
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getButttonWrapperIdPrefix() {
|
||||
return SPUIComponetIdProvider.UPLOAD_TYPE_BUTTON_PREFIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getButtonWrapperData() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,96 +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.artifacts.smtype;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent;
|
||||
import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState;
|
||||
import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterHeader;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.vaadin.spring.annotation.SpringComponent;
|
||||
import com.vaadin.spring.annotation.ViewScope;
|
||||
import com.vaadin.ui.Button.ClickEvent;
|
||||
import com.vaadin.ui.UI;
|
||||
import com.vaadin.ui.Window;
|
||||
|
||||
/**
|
||||
* Software module type filter buttons header.
|
||||
*/
|
||||
@SpringComponent
|
||||
@ViewScope
|
||||
public class SMTypeFilterHeader extends AbstractFilterHeader {
|
||||
|
||||
private static final long serialVersionUID = -4855810338059032342L;
|
||||
|
||||
@Autowired
|
||||
private ArtifactUploadState artifactUploadState;
|
||||
|
||||
@Autowired
|
||||
private CreateUpdateSoftwareTypeLayout createUpdateSWTypeLayout;
|
||||
|
||||
/**
|
||||
* Initialize the components.
|
||||
*/
|
||||
@Override
|
||||
@PostConstruct
|
||||
protected void init() {
|
||||
super.init();
|
||||
if (permChecker.hasCreateDistributionPermission() || permChecker.hasUpdateDistributionPermission()) {
|
||||
createUpdateSWTypeLayout.init();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasCreateUpdatePermission() {
|
||||
return permChecker.hasCreateDistributionPermission() || permChecker.hasUpdateDistributionPermission();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTitle() {
|
||||
return SPUILabelDefinitions.TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void settingsIconClicked(final ClickEvent event) {
|
||||
final Window addUpdateWindow = createUpdateSWTypeLayout.getWindow();
|
||||
UI.getCurrent().addWindow(addUpdateWindow);
|
||||
addUpdateWindow.setVisible(Boolean.TRUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean dropHitsRequired() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void hideFilterButtonLayout() {
|
||||
artifactUploadState.setSwTypeFilterClosed(true);
|
||||
eventBus.publish(this, UploadArtifactUIEvent.HIDE_FILTER_BY_TYPE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getConfigureFilterButtonId() {
|
||||
return SPUIDefinitions.ADD_SOFTWARE_MODULE_TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getHideButtonId() {
|
||||
return SPUIComponetIdProvider.SM_SHOW_FILTER_BUTTON_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isAddTagRequired() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,91 +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.artifacts.smtype;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent;
|
||||
import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState;
|
||||
import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterLayout;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.vaadin.spring.events.EventBus;
|
||||
import org.vaadin.spring.events.EventScope;
|
||||
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
|
||||
|
||||
import com.vaadin.spring.annotation.SpringComponent;
|
||||
import com.vaadin.spring.annotation.ViewScope;
|
||||
|
||||
/**
|
||||
* Software module type filter buttons layout.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@SpringComponent
|
||||
@ViewScope
|
||||
public class SMTypeFilterLayout extends AbstractFilterLayout {
|
||||
|
||||
private static final long serialVersionUID = 1581066345157393665L;
|
||||
|
||||
@Autowired
|
||||
private transient EventBus.SessionEventBus eventbus;
|
||||
|
||||
@Autowired
|
||||
private SMTypeFilterHeader smTypeFilterHeader;
|
||||
|
||||
@Autowired
|
||||
private SMTypeFilterButtons smTypeFilterButtons;
|
||||
|
||||
@Autowired
|
||||
private SMTypeFilterButtonClick smTypeFilterButtonClick;
|
||||
|
||||
@Autowired
|
||||
private ArtifactUploadState artifactUploadState;
|
||||
|
||||
/**
|
||||
* Initialize the filter layout.
|
||||
*/
|
||||
@PostConstruct
|
||||
void init() {
|
||||
super.init(smTypeFilterHeader, smTypeFilterButtons, smTypeFilterButtonClick);
|
||||
eventbus.subscribe(this);
|
||||
}
|
||||
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void onEvent(final UploadArtifactUIEvent event) {
|
||||
if (event == UploadArtifactUIEvent.HIDE_FILTER_BY_TYPE) {
|
||||
setVisible(false);
|
||||
}
|
||||
if (event == UploadArtifactUIEvent.SHOW_FILTER_BY_TYPE) {
|
||||
setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
void destroy() {
|
||||
/*
|
||||
* It's good manners to do this, even though vaadin-spring will
|
||||
* automatically unsubscribe when this UI is garbage collected.
|
||||
*/
|
||||
eventbus.unsubscribe(this);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.hawkbit.server.ui.common.filterlayout.SPFilterLayout#
|
||||
* onLoadIsTypeFilterIsClosed()
|
||||
*/
|
||||
@Override
|
||||
public Boolean onLoadIsTypeFilterIsClosed() {
|
||||
return artifactUploadState.isSwTypeFilterClosed();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,188 +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.artifacts.state;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.ui.common.ManagmentEntityState;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.vaadin.spring.annotation.SpringComponent;
|
||||
import com.vaadin.spring.annotation.VaadinSessionScope;
|
||||
|
||||
/**
|
||||
* User status of Artifact upload.
|
||||
*
|
||||
*
|
||||
*/
|
||||
@VaadinSessionScope
|
||||
@SpringComponent
|
||||
public class ArtifactUploadState implements ManagmentEntityState<Long>, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 8273440375917450859L;
|
||||
|
||||
@Autowired
|
||||
private SoftwareModuleFilters softwareModuleFilters;
|
||||
|
||||
private final Map<Long, String> deleteSofwareModules = new HashMap<>();
|
||||
|
||||
private final Set<CustomFile> fileSelected = new HashSet<>();
|
||||
|
||||
private Long selectedBaseSwModuleId;
|
||||
|
||||
private SoftwareModule selectedBaseSoftwareModule;
|
||||
|
||||
private final Map<String, SoftwareModule> baseSwModuleList = new HashMap<>();
|
||||
|
||||
private Set<Long> selectedSoftwareModules = Collections.emptySet();
|
||||
|
||||
private boolean swTypeFilterClosed = Boolean.FALSE;
|
||||
|
||||
private boolean swModuleTableMaximized = Boolean.FALSE;
|
||||
|
||||
private boolean artifactDetailsMaximized = Boolean.FALSE;
|
||||
|
||||
private final Set<String> selectedDeleteSWModuleTypes = new HashSet<>();
|
||||
|
||||
private boolean noDataAvilableSoftwareModule = Boolean.FALSE;
|
||||
|
||||
/**
|
||||
* Set software.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public SoftwareModuleFilters getSoftwareModuleFilters() {
|
||||
return softwareModuleFilters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the selectedSofwareModules
|
||||
*/
|
||||
public Map<Long, String> getDeleteSofwareModules() {
|
||||
return deleteSofwareModules;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the fileSelected
|
||||
*/
|
||||
public Set<CustomFile> getFileSelected() {
|
||||
return fileSelected;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the selectedBaseSwModuleId
|
||||
*/
|
||||
public Optional<Long> getSelectedBaseSwModuleId() {
|
||||
return Optional.ofNullable(selectedBaseSwModuleId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the baseSwModuleList
|
||||
*/
|
||||
public Map<String, SoftwareModule> getBaseSwModuleList() {
|
||||
return baseSwModuleList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the selectedSoftwareModules
|
||||
*/
|
||||
public Set<Long> getSelectedSoftwareModules() {
|
||||
return selectedSoftwareModules;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLastSelectedEntity(final Long value) {
|
||||
this.selectedBaseSwModuleId = value;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelectedEnitities(final Set<Long> values) {
|
||||
this.selectedSoftwareModules = values;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the swTypeFilterClosed
|
||||
*/
|
||||
public boolean isSwTypeFilterClosed() {
|
||||
return swTypeFilterClosed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param swTypeFilterClosed
|
||||
* the swTypeFilterClosed to set
|
||||
*/
|
||||
public void setSwTypeFilterClosed(final boolean swTypeFilterClosed) {
|
||||
this.swTypeFilterClosed = swTypeFilterClosed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the isSwModuleTableMaximized
|
||||
*/
|
||||
public boolean isSwModuleTableMaximized() {
|
||||
return swModuleTableMaximized;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param isSwModuleTableMaximized
|
||||
* the isSwModuleTableMaximized to set
|
||||
*/
|
||||
public void setSwModuleTableMaximized(final boolean swModuleTableMaximized) {
|
||||
this.swModuleTableMaximized = swModuleTableMaximized;
|
||||
}
|
||||
|
||||
public Set<String> getSelectedDeleteSWModuleTypes() {
|
||||
return selectedDeleteSWModuleTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the isArtifactDetailsMaximized
|
||||
*/
|
||||
public boolean isArtifactDetailsMaximized() {
|
||||
return artifactDetailsMaximized;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param isArtifactDetailsMaximized
|
||||
* the isArtifactDetailsMaximized to set
|
||||
*/
|
||||
public void setArtifactDetailsMaximized(final boolean artifactDetailsMaximized) {
|
||||
this.artifactDetailsMaximized = artifactDetailsMaximized;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the noDataAvilableSoftwareModule
|
||||
*/
|
||||
public boolean isNoDataAvilableSoftwareModule() {
|
||||
return noDataAvilableSoftwareModule;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param noDataAvilableSoftwareModule
|
||||
* the noDataAvilableSoftwareModule to set
|
||||
*/
|
||||
public void setNoDataAvilableSoftwareModule(final boolean noDataAvilableSoftwareModule) {
|
||||
this.noDataAvilableSoftwareModule = noDataAvilableSoftwareModule;
|
||||
}
|
||||
|
||||
public Optional<SoftwareModule> getSelectedBaseSoftwareModule() {
|
||||
return Optional.ofNullable(selectedBaseSoftwareModule);
|
||||
}
|
||||
|
||||
public void setSelectedBaseSoftwareModule(final SoftwareModule selectedBaseSoftwareModule) {
|
||||
this.selectedBaseSoftwareModule = selectedBaseSoftwareModule;
|
||||
}
|
||||
}
|
||||
@@ -1,215 +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.artifacts.state;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Custom file to hold details of uploaded file.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class CustomFile implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -5902321650745311767L;
|
||||
|
||||
private final String fileName;
|
||||
|
||||
private long fileSize;
|
||||
|
||||
private String filePath;
|
||||
|
||||
private String baseSoftwareModuleName;
|
||||
|
||||
private String baseSoftwareModuleVersion;
|
||||
|
||||
private String mimeType;
|
||||
|
||||
/**
|
||||
* Used to specify if the file is uploaded successfully.
|
||||
*/
|
||||
private Boolean isValid = Boolean.TRUE;
|
||||
|
||||
/**
|
||||
* Reason if upload fails.
|
||||
*/
|
||||
private String failureReason;
|
||||
|
||||
/**
|
||||
* Initialize details.
|
||||
*
|
||||
* @param fileName
|
||||
* uploaded file name
|
||||
* @param fileSize
|
||||
* uploaded file size
|
||||
* @param filePath
|
||||
* uploaded file path
|
||||
* @param baseSoftwareModuleName
|
||||
* software module name
|
||||
* @param baseSoftwareModuleVersion
|
||||
* software module version
|
||||
* @param mimeType
|
||||
* the mimeType of the file
|
||||
*/
|
||||
public CustomFile(final String fileName, final long fileSize, final String filePath,
|
||||
final String baseSoftwareModuleName, final String baseSoftwareModuleVersion, final String mimeType) {
|
||||
this.fileName = fileName;
|
||||
this.fileSize = fileSize;
|
||||
this.filePath = filePath;
|
||||
this.baseSoftwareModuleName = baseSoftwareModuleName;
|
||||
this.baseSoftwareModuleVersion = baseSoftwareModuleVersion;
|
||||
this.mimeType = mimeType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize details.
|
||||
*
|
||||
* @param fileName
|
||||
* uploaded file name
|
||||
* @param baseSoftwareModuleName
|
||||
* software module name
|
||||
* @param baseSoftwareModuleVersion
|
||||
* software module version
|
||||
*/
|
||||
public CustomFile(final String fileName, final String baseSoftwareModuleName,
|
||||
final String baseSoftwareModuleVersion) {
|
||||
this.fileName = fileName;
|
||||
this.baseSoftwareModuleName = baseSoftwareModuleName;
|
||||
this.baseSoftwareModuleVersion = baseSoftwareModuleVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor with the immutable fileName set.
|
||||
*
|
||||
* @param fileName
|
||||
* uploaded file name
|
||||
*/
|
||||
public CustomFile(final String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public String getBaseSoftwareModuleName() {
|
||||
return baseSoftwareModuleName;
|
||||
}
|
||||
|
||||
public void setBaseSoftwareModuleName(final String baseSoftwareModuleName) {
|
||||
this.baseSoftwareModuleName = baseSoftwareModuleName;
|
||||
}
|
||||
|
||||
public String getBaseSoftwareModuleVersion() {
|
||||
return baseSoftwareModuleVersion;
|
||||
}
|
||||
|
||||
public void setBaseSoftwareModuleVersion(final String baseSoftwareModuleVersion) {
|
||||
this.baseSoftwareModuleVersion = baseSoftwareModuleVersion;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public long getFileSize() {
|
||||
return fileSize;
|
||||
}
|
||||
|
||||
public void setFileSize(final long fileSize) {
|
||||
this.fileSize = fileSize;
|
||||
}
|
||||
|
||||
public String getFilePath() {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
public void setFilePath(final String filePath) {
|
||||
this.filePath = filePath;
|
||||
}
|
||||
|
||||
public String getMimeType() {
|
||||
return mimeType;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the isValid
|
||||
*/
|
||||
public Boolean getIsValid() {
|
||||
return isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param isValid
|
||||
* the isValid to set
|
||||
*/
|
||||
public void setIsValid(final Boolean isValid) {
|
||||
this.isValid = isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mimeType
|
||||
* the mimeType to set
|
||||
*/
|
||||
public void setMimeType(final String mimeType) {
|
||||
this.mimeType = mimeType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the failureReason
|
||||
*/
|
||||
public String getFailureReason() {
|
||||
return failureReason;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((baseSoftwareModuleName == null) ? 0 : baseSoftwareModuleName.hashCode());
|
||||
result = prime * result + ((baseSoftwareModuleVersion == null) ? 0 : baseSoftwareModuleVersion.hashCode());
|
||||
result = prime * result + ((fileName == null) ? 0 : fileName.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final CustomFile other = (CustomFile) obj;
|
||||
if (baseSoftwareModuleName == null) {
|
||||
if (other.baseSoftwareModuleName != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!baseSoftwareModuleName.equals(other.baseSoftwareModuleName)) {
|
||||
return false;
|
||||
}
|
||||
if (baseSoftwareModuleVersion == null) {
|
||||
if (other.baseSoftwareModuleVersion != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!baseSoftwareModuleVersion.equals(other.baseSoftwareModuleVersion)) {
|
||||
return false;
|
||||
}
|
||||
if (fileName == null) {
|
||||
if (other.fileName != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!fileName.equals(other.fileName)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,50 +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.artifacts.state;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
|
||||
import com.vaadin.spring.annotation.SpringComponent;
|
||||
import com.vaadin.spring.annotation.VaadinSessionScope;
|
||||
|
||||
/**
|
||||
* Softwrae module filters.
|
||||
*
|
||||
*
|
||||
*/
|
||||
@VaadinSessionScope
|
||||
@SpringComponent
|
||||
public class SoftwareModuleFilters implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -5251492630546463593L;
|
||||
|
||||
private SoftwareModuleType softwareModuleType;
|
||||
|
||||
private String searchText;
|
||||
|
||||
public Optional<SoftwareModuleType> getSoftwareModuleType() {
|
||||
return softwareModuleType == null ? Optional.empty() : Optional.of(softwareModuleType);
|
||||
}
|
||||
|
||||
public void setSoftwareModuleType(final SoftwareModuleType softwareModuleType) {
|
||||
this.softwareModuleType = softwareModuleType;
|
||||
}
|
||||
|
||||
public Optional<String> getSearchText() {
|
||||
return searchText == null ? Optional.empty() : Optional.of(searchText);
|
||||
}
|
||||
|
||||
public void setSearchText(final String searchText) {
|
||||
this.searchText = searchText;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,701 +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.artifacts.upload;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.repository.ArtifactManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.ArtifactUploadFailedException;
|
||||
import org.eclipse.hawkbit.repository.exception.InvalidMD5HashException;
|
||||
import org.eclipse.hawkbit.repository.exception.InvalidSHA1HashException;
|
||||
import org.eclipse.hawkbit.repository.model.LocalArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState;
|
||||
import org.eclipse.hawkbit.ui.artifacts.state.CustomFile;
|
||||
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
|
||||
import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder;
|
||||
import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleTiny;
|
||||
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.I18N;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SpringContextHelper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.vaadin.data.Item;
|
||||
import com.vaadin.data.util.IndexedContainer;
|
||||
import com.vaadin.event.FieldEvents.TextChangeEvent;
|
||||
import com.vaadin.server.FontAwesome;
|
||||
import com.vaadin.server.Page;
|
||||
import com.vaadin.shared.ui.label.ContentMode;
|
||||
import com.vaadin.ui.Alignment;
|
||||
import com.vaadin.ui.Button;
|
||||
import com.vaadin.ui.Button.ClickEvent;
|
||||
import com.vaadin.ui.HorizontalLayout;
|
||||
import com.vaadin.ui.Label;
|
||||
import com.vaadin.ui.Table;
|
||||
import com.vaadin.ui.TextField;
|
||||
import com.vaadin.ui.UI;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
import com.vaadin.ui.Window;
|
||||
import com.vaadin.ui.themes.ValoTheme;
|
||||
|
||||
/**
|
||||
* Artifact upload confirmation popup.
|
||||
*
|
||||
*/
|
||||
public class UploadConfirmationwindow implements Button.ClickListener {
|
||||
|
||||
private static final long serialVersionUID = -1679035890140031740L;
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(UploadConfirmationwindow.class);
|
||||
|
||||
private static final String MD5_CHECKSUM = "md5Checksum";
|
||||
|
||||
private static final String SHA1_CHECKSUM = "sha1Checksum";
|
||||
|
||||
private static final String FILE_NAME = "fileName";
|
||||
|
||||
private static final String SW_MODULE_NAME = "swModuleName";
|
||||
|
||||
private static final String SIZE = "size";
|
||||
|
||||
private static final String ACTION = "action";
|
||||
|
||||
private static final String BASE_SOFTWARE_ID = "softwareModuleId";
|
||||
|
||||
private static final String FILE_NAME_LAYOUT = "fileNameLayout";
|
||||
|
||||
private static final String WARNING_ICON = "warningIcon";
|
||||
|
||||
private static final String CUSTOM_FILE = "customFile";
|
||||
|
||||
private static final String ARTIFACT_UPLOAD_EXCEPTION = "Artifact upload exception:";
|
||||
|
||||
private static final String ALREADY_EXISTS_MSG = "upload.artifact.alreadyExists";
|
||||
|
||||
private final I18N i18n;
|
||||
|
||||
private Window uploadConfrimationWindow;
|
||||
|
||||
private Button uploadBtn;
|
||||
|
||||
private Button cancelBtn;
|
||||
|
||||
private Table uploadDetailsTable;
|
||||
|
||||
private final UploadLayout uploadLayout;
|
||||
|
||||
private IndexedContainer tabelContainer;
|
||||
|
||||
private final List<UploadStatus> uploadResultList = new ArrayList<>();
|
||||
|
||||
private VerticalLayout uploadArtifactDetails;
|
||||
|
||||
private UploadResultWindow currentUploadResultWindow;
|
||||
|
||||
private int redErrorLabelCount = 0;
|
||||
|
||||
private final ArtifactUploadState artifactUploadState;
|
||||
|
||||
/**
|
||||
* Initialize the upload confirmation window.
|
||||
*
|
||||
* @param artifactUploadView
|
||||
* reference of upload layout.
|
||||
* @param artifactUploadState
|
||||
* reference of session variable {@link ArtifactUploadState}.
|
||||
*/
|
||||
public UploadConfirmationwindow(final UploadLayout artifactUploadView,
|
||||
final ArtifactUploadState artifactUploadState) {
|
||||
this.uploadLayout = artifactUploadView;
|
||||
this.artifactUploadState = artifactUploadState;
|
||||
i18n = artifactUploadView.getI18n();
|
||||
createRequiredComponents();
|
||||
buildLayout();
|
||||
}
|
||||
|
||||
private Boolean checkIfArtifactDetailsDispalyed(final Long bSoftwareModuleId) {
|
||||
if (artifactUploadState.getSelectedBaseSoftwareModule().isPresent()
|
||||
&& artifactUploadState.getSelectedBaseSoftwareModule().get().getId().equals(bSoftwareModuleId)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private Boolean preUploadValidation(final List<String> itemIds) {
|
||||
Boolean validationSuccess = true;
|
||||
for (final String itemId : itemIds) {
|
||||
final Item item = tabelContainer.getItem(itemId);
|
||||
final String providedFileName = (String) item.getItemProperty(FILE_NAME).getValue();
|
||||
if (HawkbitCommonUtil.trimAndNullIfEmpty(providedFileName) == null) {
|
||||
validationSuccess = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return validationSuccess;
|
||||
}
|
||||
|
||||
private void createRequiredComponents() {
|
||||
uploadBtn = SPUIComponentProvider.getButton(SPUIComponetIdProvider.UPLOAD_BUTTON, SPUILabelDefinitions.SUBMIT,
|
||||
SPUILabelDefinitions.SUBMIT, ValoTheme.BUTTON_PRIMARY, false, null, SPUIButtonStyleTiny.class);
|
||||
uploadBtn.addClickListener(this);
|
||||
cancelBtn = SPUIComponentProvider.getButton(SPUIComponetIdProvider.UPLOAD_DISCARD_DETAILS_BUTTON,
|
||||
SPUILabelDefinitions.DISCARD, SPUILabelDefinitions.DISCARD, null, false, null,
|
||||
SPUIButtonStyleTiny.class);
|
||||
cancelBtn.addClickListener(this);
|
||||
|
||||
uploadDetailsTable = new Table();
|
||||
uploadDetailsTable.addStyleName("artifact-table");
|
||||
uploadDetailsTable.setSizeFull();
|
||||
uploadDetailsTable.setId(SPUIComponetIdProvider.UPLOAD_ARTIFACT_DETAILS_TABLE);
|
||||
uploadDetailsTable.addStyleName(ValoTheme.TABLE_BORDERLESS);
|
||||
uploadDetailsTable.addStyleName(ValoTheme.TABLE_NO_VERTICAL_LINES);
|
||||
uploadDetailsTable.addStyleName(ValoTheme.TABLE_SMALL);
|
||||
|
||||
setTableContainer();
|
||||
populateUploadDetailsTable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Warning icon is displayed, if an artifact exists with same provided file
|
||||
* name. Error icon is displayed ,if file name entered is duplicate.
|
||||
*
|
||||
* @param warningIconLabel
|
||||
* warning/error label
|
||||
* @param fileName
|
||||
* provided file name
|
||||
* @param itemId
|
||||
* item id of the current row
|
||||
*/
|
||||
private void setWarningIcon(final Label warningIconLabel, final String fileName, final Object itemId) {
|
||||
final Item item = uploadDetailsTable.getItem(itemId);
|
||||
final ArtifactManagement artifactManagement = SpringContextHelper.getBean(ArtifactManagement.class);
|
||||
if (HawkbitCommonUtil.trimAndNullIfEmpty(fileName) != null) {
|
||||
final Long baseSwId = (Long) item.getItemProperty(BASE_SOFTWARE_ID).getValue();
|
||||
final List<LocalArtifact> artifactList = artifactManagement.findByFilenameAndSoftwareModule(fileName,
|
||||
baseSwId);
|
||||
if (!artifactList.isEmpty()) {
|
||||
warningIconLabel.setVisible(true);
|
||||
if (isErrorIcon(warningIconLabel)) {
|
||||
warningIconLabel.removeStyleName(SPUIStyleDefinitions.ERROR_LABEL);
|
||||
redErrorLabelCount--;
|
||||
}
|
||||
warningIconLabel.setDescription(i18n.get(ALREADY_EXISTS_MSG));
|
||||
if (checkForDuplicate(fileName, itemId, baseSwId)) {
|
||||
warningIconLabel.setDescription(i18n.get("message.duplicate.filename"));
|
||||
warningIconLabel.addStyleName(SPUIStyleDefinitions.ERROR_LABEL);
|
||||
redErrorLabelCount++;
|
||||
}
|
||||
} else {
|
||||
warningIconLabel.setVisible(false);
|
||||
if (warningIconLabel.getStyleName().contains(SPUIStyleDefinitions.ERROR_LABEL)) {
|
||||
warningIconLabel.removeStyleName(SPUIStyleDefinitions.ERROR_LABEL);
|
||||
warningIconLabel.setDescription(i18n.get(ALREADY_EXISTS_MSG));
|
||||
redErrorLabelCount--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Boolean checkForDuplicate(final String fileName, final Object itemId, final Long currentBaseSwId) {
|
||||
for (final Object newItemId : tabelContainer.getItemIds()) {
|
||||
final Item newItem = tabelContainer.getItem(newItemId);
|
||||
final Long newBaseSwId = (Long) newItem.getItemProperty(BASE_SOFTWARE_ID).getValue();
|
||||
final String newFileName = (String) newItem.getItemProperty(FILE_NAME).getValue();
|
||||
if (!newItemId.equals(itemId) && newBaseSwId.equals(currentBaseSwId) && newFileName.equals(fileName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void populateUploadDetailsTable() {
|
||||
for (final CustomFile customFile : uploadLayout.getFileSelected()) {
|
||||
final String swNameVersion = HawkbitCommonUtil.getFormattedNameVersion(
|
||||
customFile.getBaseSoftwareModuleName(), customFile.getBaseSoftwareModuleVersion());
|
||||
final String itemId = swNameVersion + "/" + customFile.getFileName();
|
||||
final Item newItem = tabelContainer.addItem(itemId);
|
||||
final SoftwareModule bSoftwareModule = artifactUploadState.getBaseSwModuleList().get(swNameVersion);
|
||||
newItem.getItemProperty(BASE_SOFTWARE_ID).setValue(bSoftwareModule.getId());
|
||||
|
||||
addFileNameLayout(newItem, swNameVersion, customFile.getFileName(), itemId);
|
||||
|
||||
newItem.getItemProperty(SW_MODULE_NAME).setValue(HawkbitCommonUtil.getFormatedLabel(swNameVersion));
|
||||
newItem.getItemProperty(SIZE).setValue(customFile.getFileSize());
|
||||
final Button deleteIcon = SPUIComponentProvider.getButton(
|
||||
SPUIComponetIdProvider.UPLOAD_DELETE_ICON + "-" + itemId, "", SPUILabelDefinitions.DISCARD,
|
||||
ValoTheme.BUTTON_TINY + " " + "redicon", true, FontAwesome.TRASH_O,
|
||||
SPUIButtonStyleSmallNoBorder.class);
|
||||
deleteIcon.addClickListener(this);
|
||||
deleteIcon.setData(itemId);
|
||||
newItem.getItemProperty(ACTION).setValue(deleteIcon);
|
||||
|
||||
final TextField sha1 = SPUIComponentProvider.getTextField("", ValoTheme.TEXTFIELD_TINY, false, null, null,
|
||||
true, SPUILabelDefinitions.TEXT_FIELD_MAX_LENGTH);
|
||||
sha1.setId(swNameVersion + "/" + customFile.getFileName() + "/sha1");
|
||||
|
||||
final TextField md5 = SPUIComponentProvider.getTextField("", ValoTheme.TEXTFIELD_TINY, false, null, null,
|
||||
true, SPUILabelDefinitions.TEXT_FIELD_MAX_LENGTH);
|
||||
md5.setId(swNameVersion + "/" + customFile.getFileName() + "/md5");
|
||||
|
||||
final TextField customFileName = SPUIComponentProvider.getTextField("", ValoTheme.TEXTFIELD_TINY, false,
|
||||
null, null, true, SPUILabelDefinitions.TEXT_FIELD_MAX_LENGTH);
|
||||
customFileName.setId(swNameVersion + "/" + customFile.getFileName() + "/customFileName");
|
||||
newItem.getItemProperty(SHA1_CHECKSUM).setValue(sha1);
|
||||
newItem.getItemProperty(MD5_CHECKSUM).setValue(md5);
|
||||
newItem.getItemProperty(CUSTOM_FILE).setValue(customFile);
|
||||
}
|
||||
}
|
||||
|
||||
private void addFileNameLayout(final Item newItem, final String baseSoftwareModuleNameVersion,
|
||||
final String customFileName, final String itemId) {
|
||||
final HorizontalLayout horizontalLayout = new HorizontalLayout();
|
||||
final TextField fileNameTextField = SPUIComponentProvider.getTextField("", ValoTheme.TEXTFIELD_TINY, false,
|
||||
null, null, true, SPUILabelDefinitions.TEXT_FIELD_MAX_LENGTH);
|
||||
fileNameTextField.setId(baseSoftwareModuleNameVersion + "/" + customFileName + "/customFileName");
|
||||
fileNameTextField.setData(baseSoftwareModuleNameVersion + "/" + customFileName);
|
||||
fileNameTextField.setValue(customFileName);
|
||||
|
||||
newItem.getItemProperty(FILE_NAME).setValue(fileNameTextField.getValue());
|
||||
|
||||
final Label warningIconLabel = getWarningLabel();
|
||||
warningIconLabel.setId(baseSoftwareModuleNameVersion + "/" + customFileName + "/icon");
|
||||
setWarningIcon(warningIconLabel, fileNameTextField.getValue(), itemId);
|
||||
newItem.getItemProperty(WARNING_ICON).setValue(warningIconLabel);
|
||||
|
||||
horizontalLayout.addComponent(fileNameTextField);
|
||||
horizontalLayout.setComponentAlignment(fileNameTextField, Alignment.MIDDLE_LEFT);
|
||||
horizontalLayout.addComponent(warningIconLabel);
|
||||
horizontalLayout.setComponentAlignment(warningIconLabel, Alignment.MIDDLE_RIGHT);
|
||||
newItem.getItemProperty(FILE_NAME_LAYOUT).setValue(horizontalLayout);
|
||||
|
||||
fileNameTextField.addTextChangeListener(event -> onFileNameChange(event, warningIconLabel, newItem));
|
||||
}
|
||||
|
||||
private void onFileNameChange(final TextChangeEvent event, final Label warningIconLabel, final Item newItem) {
|
||||
|
||||
final String itemId = (String) ((TextField) event.getComponent()).getData();
|
||||
final String fileName = event.getText();
|
||||
|
||||
final Boolean isWarningIconDisplayed = isWarningIcon(warningIconLabel);
|
||||
setWarningIcon(warningIconLabel, fileName, itemId);
|
||||
|
||||
final Long currentSwId = (Long) newItem.getItemProperty(BASE_SOFTWARE_ID).getValue();
|
||||
final String oldFileName = (String) newItem.getItemProperty(FILE_NAME).getValue();
|
||||
newItem.getItemProperty(FILE_NAME).setValue(event.getText());
|
||||
|
||||
// if warning was displayed prior and not displayed currently
|
||||
if (isWarningIconDisplayed && !warningIconLabel.isVisible()) {
|
||||
modifyIconOfSameSwId(itemId, currentSwId, oldFileName);
|
||||
}
|
||||
checkDuplicateEntry(itemId, currentSwId, event.getText(), oldFileName);
|
||||
enableOrDisableUploadBtn();
|
||||
}
|
||||
|
||||
private void enableOrDisableUploadBtn() {
|
||||
if (redErrorLabelCount == 0) {
|
||||
uploadBtn.setEnabled(true);
|
||||
} else {
|
||||
uploadBtn.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If warning was displayed prior and not displayed currently ,the update
|
||||
* other warning labels accordingly.
|
||||
*
|
||||
* @param itemId
|
||||
* id of row which is deleted/whose file name modified.
|
||||
* @param oldSwId
|
||||
* software module id
|
||||
* @param oldFileName
|
||||
* file name before modification
|
||||
*/
|
||||
private void modifyIconOfSameSwId(final Object itemId, final Long oldSwId, final String oldFileName) {
|
||||
for (final Object rowId : tabelContainer.getItemIds()) {
|
||||
final Item newItem = tabelContainer.getItem(rowId);
|
||||
final Long newBaseSwId = (Long) newItem.getItemProperty(BASE_SOFTWARE_ID).getValue();
|
||||
final String newFileName = (String) newItem.getItemProperty(FILE_NAME).getValue();
|
||||
if (!rowId.equals(itemId) && newBaseSwId.equals(oldSwId) && newFileName.equals(oldFileName)) {
|
||||
final HorizontalLayout layout = (HorizontalLayout) newItem.getItemProperty(FILE_NAME_LAYOUT).getValue();
|
||||
final Label warningLabel = (Label) layout.getComponent(1);
|
||||
if (warningLabel.isVisible()) {
|
||||
warningLabel.removeStyleName(SPUIStyleDefinitions.ERROR_LABEL);
|
||||
warningLabel.setDescription(i18n.get(ALREADY_EXISTS_MSG));
|
||||
newItem.getItemProperty(WARNING_ICON).setValue(warningLabel);
|
||||
redErrorLabelCount--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if icon is warning icon and visible.
|
||||
*
|
||||
* @param icon
|
||||
* label
|
||||
* @return Boolean
|
||||
*/
|
||||
private Boolean isWarningIcon(final Label icon) {
|
||||
if (icon.isVisible() && !icon.getStyleName().contains(SPUIStyleDefinitions.ERROR_LABEL)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if icon is error icon and visible.
|
||||
*
|
||||
* @param icon
|
||||
* label
|
||||
* @return Boolean
|
||||
*/
|
||||
private Boolean isErrorIcon(final Label icon) {
|
||||
if (icon.isVisible() && icon.getStyleName().contains(SPUIStyleDefinitions.ERROR_LABEL)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private Label getWarningLabel() {
|
||||
final Label warningIconLabel = new Label();
|
||||
warningIconLabel.addStyleName(ValoTheme.LABEL_SMALL);
|
||||
warningIconLabel.setHeightUndefined();
|
||||
warningIconLabel.setContentMode(ContentMode.HTML);
|
||||
warningIconLabel.setValue(FontAwesome.WARNING.getHtml());
|
||||
warningIconLabel.addStyleName("warningLabel");
|
||||
warningIconLabel.setVisible(false);
|
||||
return warningIconLabel;
|
||||
}
|
||||
|
||||
private void newFileNameIsDuplicate(final Object itemId, final Long currentSwId, final String currentChangedText) {
|
||||
for (final Object rowId : tabelContainer.getItemIds()) {
|
||||
final Item currentItem = tabelContainer.getItem(itemId);
|
||||
final Item newItem = tabelContainer.getItem(rowId);
|
||||
final Long newBaseSwId = (Long) newItem.getItemProperty(BASE_SOFTWARE_ID).getValue();
|
||||
final String fileName = (String) newItem.getItemProperty(FILE_NAME).getValue();
|
||||
if (!rowId.equals(itemId) && newBaseSwId.equals(currentSwId) && fileName.equals(currentChangedText)) {
|
||||
final HorizontalLayout layout = (HorizontalLayout) currentItem.getItemProperty(FILE_NAME_LAYOUT)
|
||||
.getValue();
|
||||
final Label iconLabel = (Label) layout.getComponent(1);
|
||||
if (!iconLabel.getStyleName().contains(SPUIStyleDefinitions.ERROR_LABEL)) {
|
||||
iconLabel.setVisible(true);
|
||||
iconLabel.setDescription(i18n.get("message.duplicate.filename"));
|
||||
iconLabel.addStyleName(SPUIStyleDefinitions.ERROR_LABEL);
|
||||
redErrorLabelCount++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void reValidateOtherFileNamesOfSameBaseSw(final Object itemId, final Long currentSwId,
|
||||
final String oldFileName) {
|
||||
Label warningLabel = null;
|
||||
Label errorLabel = null;
|
||||
int errorLabelCount = 0;
|
||||
int duplicateCount = 0;
|
||||
for (final Object rowId : tabelContainer.getItemIds()) {
|
||||
final Item newItem = tabelContainer.getItem(rowId);
|
||||
final Long newBaseSwId = (Long) newItem.getItemProperty(BASE_SOFTWARE_ID).getValue();
|
||||
final String newFileName = (String) newItem.getItemProperty(FILE_NAME).getValue();
|
||||
if (!rowId.equals(itemId) && newBaseSwId.equals(currentSwId) && newFileName.equals(oldFileName)) {
|
||||
final HorizontalLayout layout = (HorizontalLayout) newItem.getItemProperty(FILE_NAME_LAYOUT).getValue();
|
||||
final Label icon = (Label) layout.getComponent(1);
|
||||
duplicateCount++;
|
||||
if (icon.isVisible()) {
|
||||
if (!icon.getStyleName().contains(SPUIStyleDefinitions.ERROR_LABEL)) {
|
||||
warningLabel = icon;
|
||||
break;
|
||||
}
|
||||
errorLabel = icon;
|
||||
errorLabelCount++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
hideErrorIcon(warningLabel, errorLabelCount, duplicateCount, errorLabel, oldFileName, currentSwId);
|
||||
}
|
||||
|
||||
private void hideErrorIcon(final Label warningLabel, final int errorLabelCount, final int duplicateCount,
|
||||
final Label errorLabel, final String oldFileName, final Long currentSwId) {
|
||||
if (warningLabel == null && (errorLabelCount > 1 || duplicateCount == 1 && errorLabelCount == 1)) {
|
||||
final ArtifactManagement artifactManagement = SpringContextHelper.getBean(ArtifactManagement.class);
|
||||
final List<LocalArtifact> artifactList = artifactManagement.findByFilenameAndSoftwareModule(oldFileName,
|
||||
currentSwId);
|
||||
errorLabel.removeStyleName(SPUIStyleDefinitions.ERROR_LABEL);
|
||||
errorLabel.setDescription(i18n.get(ALREADY_EXISTS_MSG));
|
||||
if (artifactList.isEmpty()) {
|
||||
errorLabel.setVisible(false);
|
||||
}
|
||||
redErrorLabelCount--;
|
||||
}
|
||||
}
|
||||
|
||||
private void checkDuplicateEntry(final Object itemId, final Long currentSwId, final String newChangedText,
|
||||
final String oldFileName) {
|
||||
/**
|
||||
* Check if newly entered file name is a duplicate.
|
||||
*/
|
||||
newFileNameIsDuplicate(itemId, currentSwId, newChangedText);
|
||||
/**
|
||||
* After the current changed file name is validated ,other files of same
|
||||
* software module as has be revalidated. And icons are updated
|
||||
* accordingly.
|
||||
*/
|
||||
reValidateOtherFileNamesOfSameBaseSw(itemId, currentSwId, oldFileName);
|
||||
|
||||
}
|
||||
|
||||
private void setTableContainer() {
|
||||
tabelContainer = new IndexedContainer();
|
||||
tabelContainer.addContainerProperty(FILE_NAME_LAYOUT, HorizontalLayout.class, null);
|
||||
tabelContainer.addContainerProperty(SW_MODULE_NAME, Label.class, null);
|
||||
tabelContainer.addContainerProperty(SHA1_CHECKSUM, TextField.class, null);
|
||||
tabelContainer.addContainerProperty(MD5_CHECKSUM, TextField.class, null);
|
||||
tabelContainer.addContainerProperty(SIZE, Long.class, null);
|
||||
tabelContainer.addContainerProperty(ACTION, Button.class, "");
|
||||
tabelContainer.addContainerProperty(FILE_NAME, String.class, null);
|
||||
tabelContainer.addContainerProperty(BASE_SOFTWARE_ID, Long.class, null);
|
||||
tabelContainer.addContainerProperty(WARNING_ICON, Label.class, null);
|
||||
tabelContainer.addContainerProperty(CUSTOM_FILE, CustomFile.class, null);
|
||||
|
||||
uploadDetailsTable.setContainerDataSource(tabelContainer);
|
||||
uploadDetailsTable.setPageLength(10);
|
||||
uploadDetailsTable.setColumnHeader(FILE_NAME_LAYOUT, i18n.get("upload.file.name"));
|
||||
uploadDetailsTable.setColumnHeader(SW_MODULE_NAME, i18n.get("upload.swModuleTable.header"));
|
||||
uploadDetailsTable.setColumnHeader(SHA1_CHECKSUM, i18n.get("upload.sha1"));
|
||||
uploadDetailsTable.setColumnHeader(MD5_CHECKSUM, i18n.get("upload.md5"));
|
||||
uploadDetailsTable.setColumnHeader(SIZE, i18n.get("upload.size"));
|
||||
uploadDetailsTable.setColumnHeader(ACTION, i18n.get("upload.action"));
|
||||
|
||||
uploadDetailsTable.setColumnExpandRatio(FILE_NAME_LAYOUT, 0.25f);
|
||||
uploadDetailsTable.setColumnExpandRatio(SW_MODULE_NAME, 0.17f);
|
||||
uploadDetailsTable.setColumnExpandRatio(SHA1_CHECKSUM, 0.2f);
|
||||
uploadDetailsTable.setColumnExpandRatio(MD5_CHECKSUM, 0.2f);
|
||||
uploadDetailsTable.setColumnExpandRatio(SIZE, 0.12f);
|
||||
uploadDetailsTable.setColumnExpandRatio(ACTION, 0.06f);
|
||||
|
||||
final Object[] visibileColumn = { FILE_NAME_LAYOUT, SW_MODULE_NAME, SHA1_CHECKSUM, MD5_CHECKSUM, SIZE, ACTION };
|
||||
uploadDetailsTable.setVisibleColumns(visibileColumn);
|
||||
}
|
||||
|
||||
private void buildLayout() {
|
||||
final HorizontalLayout footer = getFooterLayout();
|
||||
|
||||
uploadArtifactDetails = new VerticalLayout();
|
||||
uploadArtifactDetails.setWidth(SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_WIDTH + "px");
|
||||
uploadArtifactDetails.addStyleName("confirmation-popup");
|
||||
uploadArtifactDetails.addComponent(uploadDetailsTable);
|
||||
uploadArtifactDetails.setComponentAlignment(uploadDetailsTable, Alignment.MIDDLE_CENTER);
|
||||
uploadArtifactDetails.addComponent(footer);
|
||||
uploadArtifactDetails.setComponentAlignment(footer, Alignment.MIDDLE_CENTER);
|
||||
|
||||
uploadConfrimationWindow = new Window();
|
||||
uploadConfrimationWindow.setContent(uploadArtifactDetails);
|
||||
uploadConfrimationWindow.setResizable(Boolean.FALSE);
|
||||
uploadConfrimationWindow.setClosable(Boolean.TRUE);
|
||||
uploadConfrimationWindow.setDraggable(Boolean.TRUE);
|
||||
uploadConfrimationWindow.setModal(true);
|
||||
uploadConfrimationWindow.addCloseListener(event -> onPopupClose());
|
||||
uploadConfrimationWindow.setCaption(i18n.get("header.caption.upload.details"));
|
||||
uploadConfrimationWindow.addStyleName(SPUIStyleDefinitions.CONFIRMATION_WINDOW_CAPTION);
|
||||
}
|
||||
|
||||
private void onPopupClose() {
|
||||
uploadLayout.setCurrentUploadConfirmationwindow(null);
|
||||
}
|
||||
|
||||
private HorizontalLayout getFooterLayout() {
|
||||
final HorizontalLayout footer = new HorizontalLayout();
|
||||
footer.setSizeUndefined();
|
||||
footer.addStyleName("confirmation-window-footer");
|
||||
footer.setSpacing(true);
|
||||
footer.setMargin(false);
|
||||
footer.addComponents(uploadBtn, cancelBtn);
|
||||
footer.setComponentAlignment(uploadBtn, Alignment.TOP_LEFT);
|
||||
footer.setComponentAlignment(cancelBtn, Alignment.TOP_RIGHT);
|
||||
return footer;
|
||||
}
|
||||
|
||||
public Window getUploadConfrimationWindow() {
|
||||
return uploadConfrimationWindow;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonClick(final ClickEvent event) {
|
||||
if (event.getComponent().getId().equals(SPUIComponetIdProvider.UPLOAD_ARTIFACT_DETAILS_CLOSE)) {
|
||||
uploadConfrimationWindow.close();
|
||||
} else if (event.getComponent().getId().equals(SPUIComponetIdProvider.UPLOAD_DISCARD_DETAILS_BUTTON)) {
|
||||
uploadLayout.clearFileList();
|
||||
uploadConfrimationWindow.close();
|
||||
} else if (event.getComponent().getId().equals(SPUIComponetIdProvider.UPLOAD_BUTTON)) {
|
||||
processArtifactUpload();
|
||||
}
|
||||
|
||||
else if (event.getComponent().getId().startsWith(SPUIComponetIdProvider.UPLOAD_DELETE_ICON)) {
|
||||
final String itemId = ((Button) event.getComponent()).getData().toString();
|
||||
final Item item = uploadDetailsTable.getItem(((Button) event.getComponent()).getData());
|
||||
final Long swId = (Long) item.getItemProperty(BASE_SOFTWARE_ID).getValue();
|
||||
final CustomFile customFile = (CustomFile) item.getItemProperty(CUSTOM_FILE).getValue();
|
||||
final String fileName = (String) item.getItemProperty(FILE_NAME).getValue();
|
||||
final Label warningIconLabel = (Label) item.getItemProperty(WARNING_ICON).getValue();
|
||||
final Boolean isWarningIconDisplayed = isWarningIcon(warningIconLabel);
|
||||
if (isWarningIconDisplayed) {
|
||||
modifyIconOfSameSwId(itemId, swId, fileName);
|
||||
} else if (isErrorIcon(warningIconLabel)) {
|
||||
redErrorLabelCount--;
|
||||
}
|
||||
reValidateOtherFileNamesOfSameBaseSw(((Button) event.getComponent()).getData(), swId, fileName);
|
||||
enableOrDisableUploadBtn();
|
||||
|
||||
uploadDetailsTable.removeItem(((Button) event.getComponent()).getData());
|
||||
uploadLayout.getFileSelected().remove(customFile);
|
||||
uploadLayout.updateActionCount();
|
||||
if (uploadDetailsTable.getItemIds().isEmpty()) {
|
||||
uploadLayout.clearFileList();
|
||||
uploadConfrimationWindow.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void processArtifactUpload() {
|
||||
final List<String> itemIds = (List<String>) uploadDetailsTable.getItemIds();
|
||||
if (preUploadValidation(itemIds)) {
|
||||
final ArtifactManagement artifactManagement = SpringContextHelper.getBean(ArtifactManagement.class);
|
||||
Boolean refreshArtifactDetailsLayout = false;
|
||||
for (final String itemId : itemIds) {
|
||||
final String[] itemDet = itemId.split("/");
|
||||
final String baseSoftwareModuleNameVersion = itemDet[0];
|
||||
final String fileName = itemDet[1];
|
||||
final SoftwareModule bSoftwareModule = artifactUploadState.getBaseSwModuleList()
|
||||
.get(baseSoftwareModuleNameVersion);
|
||||
for (final CustomFile customFile : uploadLayout.getFileSelected()) {
|
||||
final String baseSwModuleNameVersion = HawkbitCommonUtil.getFormattedNameVersion(
|
||||
customFile.getBaseSoftwareModuleName(), customFile.getBaseSoftwareModuleVersion());
|
||||
if (customFile.getFileName().equals(fileName)
|
||||
&& baseSwModuleNameVersion.equals(baseSoftwareModuleNameVersion)) {
|
||||
createLocalArtifact(itemId, customFile.getFilePath(), artifactManagement, bSoftwareModule);
|
||||
}
|
||||
}
|
||||
refreshArtifactDetailsLayout = checkIfArtifactDetailsDispalyed(bSoftwareModule.getId());
|
||||
}
|
||||
if (refreshArtifactDetailsLayout) {
|
||||
uploadLayout.refreshArtifactDetailsLayout(artifactUploadState.getSelectedBaseSoftwareModule().get());
|
||||
}
|
||||
uploadLayout.clearFileList();
|
||||
uploadConfrimationWindow.close();
|
||||
// call upload result window
|
||||
currentUploadResultWindow = new UploadResultWindow(uploadResultList, i18n);
|
||||
UI.getCurrent().addWindow(currentUploadResultWindow.getUploadResultsWindow());
|
||||
currentUploadResultWindow.getUploadResultsWindow().addCloseListener(event -> onResultDetailsPopupClose());
|
||||
uploadLayout.setResultPopupHeightWidth(Page.getCurrent().getBrowserWindowWidth(),
|
||||
Page.getCurrent().getBrowserWindowHeight());
|
||||
} else {
|
||||
uploadLayout.getUINotification()
|
||||
.displayValidationError(uploadLayout.getI18n().get("message.error.noProvidedName"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void onResultDetailsPopupClose() {
|
||||
currentUploadResultWindow = null;
|
||||
}
|
||||
|
||||
private void createLocalArtifact(final String itemId, final String filePath,
|
||||
final ArtifactManagement artifactManagement, final SoftwareModule baseSw) {
|
||||
final File newFile = new File(filePath);
|
||||
final Item item = tabelContainer.getItem(itemId);
|
||||
final String sha1Checksum = ((TextField) item.getItemProperty(SHA1_CHECKSUM).getValue()).getValue();
|
||||
final String md5Checksum = ((TextField) item.getItemProperty(MD5_CHECKSUM).getValue()).getValue();
|
||||
final String providedFileName = (String) item.getItemProperty(FILE_NAME).getValue();
|
||||
final CustomFile customFile = (CustomFile) item.getItemProperty(CUSTOM_FILE).getValue();
|
||||
final String[] itemDet = itemId.split("/");
|
||||
final String swModuleNameVersion = itemDet[0];
|
||||
|
||||
FileInputStream fis = null;
|
||||
try {
|
||||
fis = new FileInputStream(newFile);
|
||||
artifactManagement.createLocalArtifact(fis, baseSw.getId(), providedFileName,
|
||||
HawkbitCommonUtil.trimAndNullIfEmpty(md5Checksum),
|
||||
HawkbitCommonUtil.trimAndNullIfEmpty(sha1Checksum), true, customFile.getMimeType());
|
||||
saveUploadStatus(providedFileName, swModuleNameVersion, SPUILabelDefinitions.SUCCESS, "");
|
||||
} catch (final FileNotFoundException e) {
|
||||
saveUploadStatus(providedFileName, swModuleNameVersion, SPUILabelDefinitions.FAILED, e.getMessage());
|
||||
LOG.error(ARTIFACT_UPLOAD_EXCEPTION, e);
|
||||
} catch (final ArtifactUploadFailedException e) {
|
||||
saveUploadStatus(providedFileName, swModuleNameVersion, SPUILabelDefinitions.FAILED, e.getMessage());
|
||||
LOG.error(ARTIFACT_UPLOAD_EXCEPTION, e);
|
||||
} catch (final InvalidSHA1HashException e) {
|
||||
saveUploadStatus(providedFileName, swModuleNameVersion, SPUILabelDefinitions.FAILED, e.getMessage());
|
||||
LOG.error(ARTIFACT_UPLOAD_EXCEPTION, e);
|
||||
} catch (final InvalidMD5HashException e) {
|
||||
saveUploadStatus(providedFileName, swModuleNameVersion, SPUILabelDefinitions.FAILED, e.getMessage());
|
||||
LOG.error(ARTIFACT_UPLOAD_EXCEPTION, e);
|
||||
} finally {
|
||||
closeFileStream(fis, newFile);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveUploadStatus(final String fileName, final String baseSwModuleName, final String status,
|
||||
final String message) {
|
||||
final UploadStatus result = new UploadStatus();
|
||||
result.setFileName(fileName);
|
||||
result.setBaseSwModuleName(baseSwModuleName);
|
||||
result.setUploadResult(status);
|
||||
result.setReason(message);
|
||||
uploadResultList.add(result);
|
||||
|
||||
}
|
||||
|
||||
private void closeFileStream(final FileInputStream fis, final File newFile) {
|
||||
|
||||
if (fis != null) {
|
||||
try {
|
||||
fis.close();
|
||||
} catch (final IOException e) {
|
||||
LOG.error(ARTIFACT_UPLOAD_EXCEPTION, e);
|
||||
}
|
||||
}
|
||||
if (newFile.exists() && !newFile.delete()) {
|
||||
LOG.error("Could not delete temporary file: {}", newFile);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Table getUploadDetailsTable() {
|
||||
return uploadDetailsTable;
|
||||
}
|
||||
|
||||
public VerticalLayout getUploadArtifactDetails() {
|
||||
return uploadArtifactDetails;
|
||||
}
|
||||
|
||||
public UploadResultWindow getCurrentUploadResultWindow() {
|
||||
return currentUploadResultWindow;
|
||||
}
|
||||
|
||||
public void setCurrentUploadResultWindow(final UploadResultWindow currentUploadResultWindow) {
|
||||
this.currentUploadResultWindow = currentUploadResultWindow;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,381 +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.artifacts.upload;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.eclipse.hawkbit.repository.exception.ArtifactUploadFailedException;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.ui.artifacts.state.CustomFile;
|
||||
import org.eclipse.hawkbit.ui.utils.I18N;
|
||||
import org.eclipse.hawkbit.ui.utils.SpringContextHelper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.vaadin.server.StreamVariable;
|
||||
import com.vaadin.ui.Upload;
|
||||
import com.vaadin.ui.Upload.FailedEvent;
|
||||
import com.vaadin.ui.Upload.FailedListener;
|
||||
import com.vaadin.ui.Upload.FinishedEvent;
|
||||
import com.vaadin.ui.Upload.FinishedListener;
|
||||
import com.vaadin.ui.Upload.ProgressListener;
|
||||
import com.vaadin.ui.Upload.Receiver;
|
||||
import com.vaadin.ui.Upload.StartedEvent;
|
||||
import com.vaadin.ui.Upload.StartedListener;
|
||||
import com.vaadin.ui.Upload.SucceededEvent;
|
||||
import com.vaadin.ui.Upload.SucceededListener;
|
||||
|
||||
/**
|
||||
* Implementation to read file selected for upload. both for {@link Upload} and
|
||||
* {@link StreamVariable} upload variants.
|
||||
*
|
||||
* The handler manages the output to the user and at the same time ensures that
|
||||
* the upload does not exceed the configued max file size.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class UploadHandler implements StreamVariable, Receiver, SucceededListener, FailedListener, FinishedListener,
|
||||
ProgressListener, StartedListener {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(UploadHandler.class);
|
||||
|
||||
private final long fileSize;
|
||||
private final UploadLayout view;
|
||||
private final UploadStatusInfoWindow infoWindow;
|
||||
private final long maxSize;
|
||||
private final Upload upload;
|
||||
|
||||
private volatile String fileName = null;
|
||||
private volatile String mimeType = null;
|
||||
private volatile boolean interrupted = false;
|
||||
private String failureReason;
|
||||
private final I18N i18n;
|
||||
|
||||
UploadHandler(final String fileName, final long fileSize, final UploadLayout view,
|
||||
final UploadStatusInfoWindow infoWindow, final long maxSize, final Upload upload, final String mimeType) {
|
||||
super();
|
||||
this.fileName = fileName;
|
||||
this.fileSize = fileSize;
|
||||
this.view = view;
|
||||
this.infoWindow = infoWindow;
|
||||
this.maxSize = maxSize;
|
||||
this.upload = upload;
|
||||
this.mimeType = mimeType;
|
||||
this.i18n = SpringContextHelper.getBean(I18N.class);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create stream for {@link StreamVariable} variant.
|
||||
*
|
||||
* @see com.vaadin.server.StreamVariable#getOutputStream()
|
||||
*/
|
||||
@Override
|
||||
public final OutputStream getOutputStream() {
|
||||
try {
|
||||
return view.saveUploadedFileDetails(fileName, fileSize, mimeType);
|
||||
} catch (final ArtifactUploadFailedException e) {
|
||||
LOG.error("Atifact upload failed {} ", e);
|
||||
failureReason = e.getMessage();
|
||||
interrupted = true;
|
||||
return new NullOutputStream();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create stream for {@link Upload} variant.
|
||||
*
|
||||
* @see com.vaadin.ui.Upload.Receiver#receiveUpload(java.lang.String,
|
||||
* java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public OutputStream receiveUpload(final String fileName, final String mimeType) {
|
||||
this.fileName = fileName;
|
||||
this.mimeType = mimeType;
|
||||
//reset has directory flag before upload
|
||||
view.setHasDirectory(false);
|
||||
try {
|
||||
if (view.checkIfSoftwareModuleIsSelected()) {
|
||||
if (view.checkForDuplicate(fileName)) {
|
||||
view.showDuplicateMessage();
|
||||
} else {
|
||||
view.increaseNumberOfFileUploadsExpected();
|
||||
return view.saveUploadedFileDetails(fileName, 0, mimeType);
|
||||
}
|
||||
}
|
||||
} catch (final ArtifactUploadFailedException e) {
|
||||
LOG.error("Atifact upload failed {} ", e);
|
||||
failureReason = e.getMessage();
|
||||
upload.interruptUpload();
|
||||
}
|
||||
// if final validation fails ,final no upload ,return NullOutputStream
|
||||
return new NullOutputStream();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Upload sucessfull for {@link Upload} variant.
|
||||
*
|
||||
* @see com.vaadin.ui.Upload.SucceededListener#uploadSucceeded(com.vaadin.ui.Upload.SucceededEvent)
|
||||
*/
|
||||
@Override
|
||||
public void uploadSucceeded(final SucceededEvent event) {
|
||||
LOG.debug("Streaming finished for file :{}", event.getFilename());
|
||||
view.updateFileSize(event.getFilename(), event.getLength());
|
||||
|
||||
// recorded that we now one more uploaded
|
||||
view.increaseNumberOfFilesActuallyUpload();
|
||||
|
||||
// inform upload status window
|
||||
infoWindow.uploadSucceeded(event.getFilename());
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload finished for {@link StreamVariable} variant. Called only in good
|
||||
* case. So a combination of {@link #uploadSucceeded(SucceededEvent)} and
|
||||
* {@link #uploadFinished(FinishedEvent)}.
|
||||
*
|
||||
* @see com.vaadin.server.StreamVariable#streamingFinished(com.vaadin.server.StreamVariable.StreamingEndEvent)
|
||||
*/
|
||||
@Override
|
||||
public void streamingFinished(final StreamingEndEvent event) {
|
||||
LOG.debug("Streaming finished for file :{}", event.getFileName());
|
||||
// record that we now one more uploaded
|
||||
view.increaseNumberOfFilesActuallyUpload();
|
||||
|
||||
// inform upload status window
|
||||
infoWindow.uploadSucceeded(event.getFileName());
|
||||
|
||||
// check if we are finished
|
||||
if (view.enableProcessBtn()) {
|
||||
infoWindow.uploadSessionFinished();
|
||||
}
|
||||
view.updateActionCount();
|
||||
|
||||
// display the duplicate message after streaming all files
|
||||
view.displayDuplicateValidationMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload finished for {@link Upload} variant. Both for good and error
|
||||
* variant.
|
||||
*
|
||||
* @see com.vaadin.ui.Upload.FinishedListener#uploadFinished(com.vaadin.ui.Upload.FinishedEvent)
|
||||
*/
|
||||
@Override
|
||||
public void uploadFinished(final FinishedEvent event) {
|
||||
LOG.debug("Upload finished for file :{}", event.getFilename());
|
||||
// check if we are finished
|
||||
if (view.enableProcessBtn()) {
|
||||
infoWindow.uploadSessionFinished();
|
||||
}
|
||||
view.updateActionCount();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload started for {@link StreamVariable} variant.
|
||||
*
|
||||
* @see com.vaadin.server.StreamVariable#streamingStarted(com.vaadin.server.StreamVariable.StreamingStartEvent)
|
||||
*/
|
||||
@Override
|
||||
public void streamingStarted(final StreamingStartEvent event) {
|
||||
LOG.debug("Streaming started for file :{}", fileName);
|
||||
infoWindow.uploadStarted(fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload started for {@link Upload} variant.
|
||||
*
|
||||
* @see com.vaadin.ui.Upload.StartedListener#uploadStarted(com.vaadin.ui.Upload.StartedEvent)
|
||||
*/
|
||||
@Override
|
||||
public void uploadStarted(final StartedEvent event) {
|
||||
// single file session
|
||||
if (view.isSoftwareModuleSelected() && !view.checkIfFileIsDuplicate(event.getFilename())) {
|
||||
infoWindow.uploadSessionStarted();
|
||||
LOG.debug("Upload started for file :{}", event.getFilename());
|
||||
infoWindow.uploadStarted(event.getFilename());
|
||||
} else {
|
||||
failureReason = i18n.get("message.upload.failed");
|
||||
upload.interruptUpload();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* listen progress.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean listenProgress() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports progress in {@link Upload} variant.
|
||||
*
|
||||
* @see com.vaadin.ui.Upload.ProgressListener#updateProgress(long, long)
|
||||
*/
|
||||
@Override
|
||||
public void updateProgress(final long readBytes, final long contentLength) {
|
||||
if (readBytes > maxSize || contentLength > maxSize) {
|
||||
LOG.error("User tried to upload more than was allowed ({}).", maxSize);
|
||||
view.decreaseNumberOfFileUploadsExpected();
|
||||
final SoftwareModule sw = view.getSoftwareModuleSelected();
|
||||
view.getFileSelected().remove(new CustomFile(fileName, sw.getName(), sw.getVersion()));
|
||||
view.updateActionCount();
|
||||
failureReason = i18n.get("message.uploadedfile.size.exceeded", maxSize);
|
||||
infoWindow.uploadFailed(fileName, failureReason);
|
||||
upload.interruptUpload();
|
||||
interrupted = true;
|
||||
return;
|
||||
}
|
||||
|
||||
infoWindow.updateProgress(fileName, readBytes, contentLength);
|
||||
LOG.info("Update progress - {} : {}", fileName, (double) readBytes / (double) contentLength);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports progress in {@link StreamVariable} variant. Interrupts
|
||||
*
|
||||
* @see com.vaadin.server.StreamVariable#onProgress(com.vaadin.server.StreamVariable.StreamingProgressEvent)
|
||||
*/
|
||||
@Override
|
||||
public void onProgress(final StreamingProgressEvent event) {
|
||||
if (event.getBytesReceived() > maxSize || event.getContentLength() > maxSize) {
|
||||
LOG.error("User tried to upload more than was allowed ({}).", maxSize);
|
||||
view.decreaseNumberOfFileUploadsExpected();
|
||||
final SoftwareModule sw = view.getSoftwareModuleSelected();
|
||||
view.getFileSelected().remove(new CustomFile(fileName, sw.getName(), sw.getVersion()));
|
||||
view.updateActionCount();
|
||||
failureReason = i18n.get("message.uploadedfile.size.exceeded", maxSize);
|
||||
infoWindow.uploadFailed(event.getFileName(), failureReason);
|
||||
interrupted = true;
|
||||
return;
|
||||
}
|
||||
|
||||
infoWindow.updateProgress(event.getFileName(), event.getBytesReceived(), event.getContentLength());
|
||||
// Logging to solve sonar issue
|
||||
LOG.trace("Streaming in progress for file :{}", event.getFileName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload failed for{@link StreamVariable} variant.
|
||||
*
|
||||
* @param event
|
||||
* StreamingEndEvent
|
||||
*/
|
||||
@Override
|
||||
public void streamingFailed(final StreamingErrorEvent event) {
|
||||
LOG.info("Streaming failed for file :{}", event.getFileName());
|
||||
view.decreaseNumberOfFileUploadsExpected();
|
||||
final SoftwareModule sw = view.getSoftwareModuleSelected();
|
||||
view.getFileSelected().remove(new CustomFile(fileName, sw.getName(), sw.getVersion()));
|
||||
view.updateActionCount();
|
||||
infoWindow.uploadFailed(event.getFileName(), failureReason);
|
||||
// check if we are finished
|
||||
if (view.enableProcessBtn()) {
|
||||
infoWindow.uploadSessionFinished();
|
||||
}
|
||||
view.displayDuplicateValidationMessage();
|
||||
|
||||
LOG.info("Streaming failed due to :{}", event.getException());
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload failed for {@link Upload} variant.
|
||||
*
|
||||
* @see com.vaadin.ui.Upload.FailedListener#uploadFailed(com.vaadin.ui.Upload.FailedEvent)
|
||||
*/
|
||||
@Override
|
||||
public void uploadFailed(final FailedEvent event) {
|
||||
LOG.info("Upload failed for file :{}", event.getFilename());
|
||||
view.decreaseNumberOfFileUploadsExpected();
|
||||
/**
|
||||
* If upload interrupted because of duplicate file,do not remove the
|
||||
* file already in upload list
|
||||
**/
|
||||
if (!view.getDuplicateFileNamesList().isEmpty()) {
|
||||
final SoftwareModule sw = view.getSoftwareModuleSelected();
|
||||
view.getFileSelected().remove(new CustomFile(fileName, sw.getName(), sw.getVersion()));
|
||||
}
|
||||
view.updateActionCount();
|
||||
infoWindow.uploadFailed(event.getFilename(), failureReason);
|
||||
LOG.info("Upload failed for file :{}", event.getReason());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* to check if upload is interrupted.
|
||||
*/
|
||||
@Override
|
||||
public boolean isInterrupted() {
|
||||
return interrupted;
|
||||
}
|
||||
|
||||
private static class NullOutputStream extends OutputStream {
|
||||
/**
|
||||
* null output stream.
|
||||
*
|
||||
* @param i
|
||||
* byte
|
||||
*/
|
||||
@Override
|
||||
public void write(final int i) throws IOException {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + (fileName == null ? 0 : fileName.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof UploadHandler)) {
|
||||
return false;
|
||||
}
|
||||
final UploadHandler other = (UploadHandler) obj;
|
||||
if (fileName == null && other.fileName != null) {
|
||||
return false;
|
||||
} else if (!fileName.equals(other.fileName)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,658 +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.artifacts.upload;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import org.eclipse.hawkbit.repository.exception.ArtifactUploadFailedException;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent;
|
||||
import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType;
|
||||
import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent;
|
||||
import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState;
|
||||
import org.eclipse.hawkbit.ui.artifacts.state.CustomFile;
|
||||
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
|
||||
import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmall;
|
||||
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.I18N;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.UINotification;
|
||||
import org.eclipse.hawkbit.util.SPInfo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.vaadin.spring.events.EventBus;
|
||||
import org.vaadin.spring.events.EventScope;
|
||||
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.vaadin.event.dd.DragAndDropEvent;
|
||||
import com.vaadin.event.dd.DropHandler;
|
||||
import com.vaadin.event.dd.acceptcriteria.AcceptAll;
|
||||
import com.vaadin.event.dd.acceptcriteria.AcceptCriterion;
|
||||
import com.vaadin.server.FontAwesome;
|
||||
import com.vaadin.server.Page;
|
||||
import com.vaadin.server.StreamVariable;
|
||||
import com.vaadin.shared.ui.label.ContentMode;
|
||||
import com.vaadin.spring.annotation.SpringComponent;
|
||||
import com.vaadin.spring.annotation.ViewScope;
|
||||
import com.vaadin.ui.Alignment;
|
||||
import com.vaadin.ui.Button;
|
||||
import com.vaadin.ui.DragAndDropWrapper;
|
||||
import com.vaadin.ui.DragAndDropWrapper.WrapperTransferable;
|
||||
import com.vaadin.ui.HorizontalLayout;
|
||||
import com.vaadin.ui.Html5File;
|
||||
import com.vaadin.ui.Label;
|
||||
import com.vaadin.ui.UI;
|
||||
import com.vaadin.ui.Upload;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
|
||||
/**
|
||||
* Upload files layout.
|
||||
*/
|
||||
@ViewScope
|
||||
@SpringComponent
|
||||
public class UploadLayout extends VerticalLayout {
|
||||
|
||||
private static final long serialVersionUID = -566164756606779220L;
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(UploadLayout.class);
|
||||
|
||||
@Autowired
|
||||
private UploadStatusInfoWindow uploadInfoWindow;
|
||||
|
||||
@Autowired
|
||||
private I18N i18n;
|
||||
|
||||
@Autowired
|
||||
private transient UINotification uiNotification;
|
||||
|
||||
@Autowired
|
||||
private transient EventBus.SessionEventBus eventBus;
|
||||
|
||||
@Autowired
|
||||
private ArtifactUploadState artifactUploadState;
|
||||
|
||||
@Autowired
|
||||
private transient SPInfo spInfo;
|
||||
|
||||
private final AtomicInteger numberOfFileUploadsExpected = new AtomicInteger();
|
||||
|
||||
private final AtomicInteger numberOfFilesActuallyUpload = new AtomicInteger();
|
||||
|
||||
private final List<String> duplicateFileNamesList = new ArrayList<>();
|
||||
|
||||
private Button processBtn;
|
||||
|
||||
private Button discardBtn;
|
||||
|
||||
private UploadConfirmationwindow currentUploadConfirmationwindow;
|
||||
|
||||
private VerticalLayout dropAreaLayout;
|
||||
|
||||
private UI ui;
|
||||
|
||||
private HorizontalLayout fileUploadLayout;
|
||||
|
||||
private DragAndDropWrapper dropAreaWrapper;
|
||||
|
||||
private Boolean hasDirectory = Boolean.FALSE;
|
||||
|
||||
/**
|
||||
* Initialize the upload layout.
|
||||
*/
|
||||
@PostConstruct
|
||||
void init() {
|
||||
createComponents();
|
||||
buildLayout();
|
||||
updateActionCount();
|
||||
eventBus.subscribe(this);
|
||||
ui = UI.getCurrent();
|
||||
}
|
||||
|
||||
private void createComponents() {
|
||||
|
||||
createProcessButton();
|
||||
createDiscardBtn();
|
||||
}
|
||||
|
||||
private void buildLayout() {
|
||||
|
||||
final Upload upload = new Upload();
|
||||
final UploadHandler uploadHandler = new UploadHandler(null, 0, this, uploadInfoWindow,
|
||||
spInfo.getMaxArtifactFileSize(), upload, null);
|
||||
upload.setButtonCaption(i18n.get("upload.file"));
|
||||
upload.setImmediate(true);
|
||||
upload.setReceiver(uploadHandler);
|
||||
upload.addSucceededListener(uploadHandler);
|
||||
upload.addFailedListener(uploadHandler);
|
||||
upload.addFinishedListener(uploadHandler);
|
||||
upload.addProgressListener(uploadHandler);
|
||||
upload.addStartedListener(uploadHandler);
|
||||
upload.addStyleName(SPUIStyleDefinitions.ACTION_BUTTON);
|
||||
|
||||
fileUploadLayout = new HorizontalLayout();
|
||||
fileUploadLayout.setSpacing(true);
|
||||
fileUploadLayout.addComponent(upload);
|
||||
fileUploadLayout.setComponentAlignment(upload, Alignment.MIDDLE_LEFT);
|
||||
fileUploadLayout.addComponent(processBtn);
|
||||
fileUploadLayout.setComponentAlignment(processBtn, Alignment.MIDDLE_RIGHT);
|
||||
fileUploadLayout.addComponent(discardBtn);
|
||||
fileUploadLayout.setComponentAlignment(discardBtn, Alignment.MIDDLE_RIGHT);
|
||||
setMargin(false);
|
||||
|
||||
/* create drag-drop wrapper for drop area */
|
||||
dropAreaWrapper = new DragAndDropWrapper(createDropAreaLayout());
|
||||
dropAreaWrapper.setDropHandler(new DropAreahandler());
|
||||
setSizeFull();
|
||||
setSpacing(true);
|
||||
|
||||
}
|
||||
|
||||
public DragAndDropWrapper getDropAreaWrapper() {
|
||||
return dropAreaWrapper;
|
||||
}
|
||||
|
||||
private class DropAreahandler implements DropHandler {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public AcceptCriterion getAcceptCriterion() {
|
||||
return AcceptAll.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drop(final DragAndDropEvent event) {
|
||||
if (validate(event)) {
|
||||
final Html5File[] files = ((WrapperTransferable) event.getTransferable()).getFiles();
|
||||
// reset the flag
|
||||
hasDirectory = Boolean.FALSE;
|
||||
for (final Html5File file : files) {
|
||||
processFile(file);
|
||||
}
|
||||
if (numberOfFileUploadsExpected.get() > 0) {
|
||||
processBtn.setEnabled(false);
|
||||
// reset before we start
|
||||
uploadInfoWindow.uploadSessionStarted();
|
||||
} else {
|
||||
// If the upload is not started, it signifies all
|
||||
// dropped files as either duplicate or directory.So
|
||||
// display message accordingly
|
||||
displayCompositeMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void processFile(final Html5File file) {
|
||||
if (!isDirectory(file)) {
|
||||
if (!checkForDuplicate(file.getFileName())) {
|
||||
numberOfFileUploadsExpected.incrementAndGet();
|
||||
file.setStreamVariable(createStreamVariable(file));
|
||||
}
|
||||
} else {
|
||||
hasDirectory = Boolean.TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
private StreamVariable createStreamVariable(final Html5File file) {
|
||||
return new UploadHandler(file.getFileName(), file.getFileSize(), UploadLayout.this, uploadInfoWindow,
|
||||
spInfo.getMaxArtifactFileSize(), null, file.getType());
|
||||
}
|
||||
|
||||
private boolean isDirectory(final Html5File file) {
|
||||
return Strings.isNullOrEmpty(file.getType()) && file.getFileSize() % 4096 == 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void displayCompositeMessage() {
|
||||
final String duplicateMessage = getDuplicateFileValidationMessage();
|
||||
final StringBuilder compositeMessage = new StringBuilder();
|
||||
if (!Strings.isNullOrEmpty(duplicateMessage)) {
|
||||
compositeMessage.append(duplicateMessage);
|
||||
}
|
||||
if (hasDirectory) {
|
||||
if (compositeMessage.length() > 0) {
|
||||
compositeMessage.append("<br>");
|
||||
}
|
||||
compositeMessage.append(i18n.get("message.no.directory.upload"));
|
||||
}
|
||||
if (!compositeMessage.toString().isEmpty()) {
|
||||
uiNotification.displayValidationError(compositeMessage.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private VerticalLayout createDropAreaLayout() {
|
||||
dropAreaLayout = new VerticalLayout();
|
||||
final Label dropHereLabel = new Label("Drop files to upload");
|
||||
dropHereLabel.setWidth(null);
|
||||
|
||||
final Label dropIcon = new Label(FontAwesome.ARROW_DOWN.getHtml(), ContentMode.HTML);
|
||||
dropIcon.addStyleName("drop-icon");
|
||||
dropIcon.setWidth(null);
|
||||
|
||||
dropAreaLayout.addComponent(dropIcon);
|
||||
dropAreaLayout.setComponentAlignment(dropIcon, Alignment.BOTTOM_CENTER);
|
||||
dropAreaLayout.addComponent(dropHereLabel);
|
||||
dropAreaLayout.setComponentAlignment(dropHereLabel, Alignment.TOP_CENTER);
|
||||
dropAreaLayout.setSizeFull();
|
||||
dropAreaLayout.setStyleName("upload-drop-area-layout-info");
|
||||
dropAreaLayout.setSpacing(false);
|
||||
return dropAreaLayout;
|
||||
}
|
||||
|
||||
private void createProcessButton() {
|
||||
processBtn = SPUIComponentProvider.getButton(SPUIComponetIdProvider.UPLOAD_PROCESS_BUTTON,
|
||||
SPUILabelDefinitions.PROCESS, SPUILabelDefinitions.PROCESS, null, false, null,
|
||||
SPUIButtonStyleSmall.class);
|
||||
processBtn.setIcon(FontAwesome.BELL);
|
||||
processBtn.addStyleName(SPUIStyleDefinitions.ACTION_BUTTON);
|
||||
processBtn.addClickListener(event -> displayConfirmWindow(event));
|
||||
processBtn.setHtmlContentAllowed(true);
|
||||
if (artifactUploadState.getFileSelected().isEmpty()) {
|
||||
processBtn.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void createDiscardBtn() {
|
||||
discardBtn = SPUIComponentProvider.getButton(SPUIComponetIdProvider.UPLOAD_DISCARD_BUTTON,
|
||||
SPUILabelDefinitions.DISCARD, SPUILabelDefinitions.DISCARD, null, false, null,
|
||||
SPUIButtonStyleSmall.class);
|
||||
discardBtn.setIcon(FontAwesome.TRASH_O);
|
||||
discardBtn.addStyleName(SPUIStyleDefinitions.ACTION_BUTTON);
|
||||
discardBtn.addClickListener(event -> discardUploadData(event));
|
||||
}
|
||||
|
||||
boolean checkForDuplicate(final String filename) {
|
||||
final Boolean isDuplicate = checkIfFileIsDuplicate(filename);
|
||||
if (isDuplicate) {
|
||||
getDuplicateFileNamesList().add(filename);
|
||||
}
|
||||
return isDuplicate;
|
||||
}
|
||||
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void toggleProcessButton(final UploadArtifactUIEvent event) {
|
||||
if (event == UploadArtifactUIEvent.ENABLE_PROCESS_BUTTON) {
|
||||
processBtn.setEnabled(true);
|
||||
} else if (event == UploadArtifactUIEvent.DISABLE_PROCESS_BUTTON) {
|
||||
processBtn.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save uploaded file details.
|
||||
*
|
||||
* @param stream
|
||||
* read from uploaded file
|
||||
* @param name
|
||||
* file name
|
||||
* @param size
|
||||
* file size
|
||||
* @param mimeType
|
||||
* the mimeType of the file
|
||||
* @throws IOException
|
||||
* in case of upload errors
|
||||
*/
|
||||
OutputStream saveUploadedFileDetails(final String name, final long size, final String mimeType) {
|
||||
File tempFile = null;
|
||||
try {
|
||||
tempFile = File.createTempFile("spUiArtifactUpload", null);
|
||||
|
||||
final OutputStream out = new FileOutputStream(tempFile);
|
||||
|
||||
final SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get();
|
||||
|
||||
final String currentBaseSoftwareModuleKey = HawkbitCommonUtil
|
||||
.getFormattedNameVersion(selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion());
|
||||
|
||||
final CustomFile customFile = new CustomFile(name, size, tempFile.getAbsolutePath(),
|
||||
selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion(), mimeType);
|
||||
|
||||
artifactUploadState.getFileSelected().add(customFile);
|
||||
processBtn.setEnabled(false);
|
||||
|
||||
if (!artifactUploadState.getBaseSwModuleList().keySet().contains(currentBaseSoftwareModuleKey)) {
|
||||
artifactUploadState.getBaseSwModuleList().put(currentBaseSoftwareModuleKey, selectedSoftwareModule);
|
||||
}
|
||||
return out;
|
||||
} catch (final FileNotFoundException e) {
|
||||
LOG.error("Upload failed {}", e);
|
||||
throw new ArtifactUploadFailedException(i18n.get("message.file.not.found"));
|
||||
} catch (final IOException e) {
|
||||
LOG.error("Upload failed {}", e);
|
||||
throw new ArtifactUploadFailedException(i18n.get("message.upload.failed"));
|
||||
}
|
||||
}
|
||||
|
||||
Boolean validate(final DragAndDropEvent event) {
|
||||
// check if drop is valid.If valid ,check if software module is
|
||||
// selected.
|
||||
if (!isFilesDropped(event)) {
|
||||
uiNotification.displayValidationError(i18n.get("message.action.not.allowed"));
|
||||
return false;
|
||||
}
|
||||
return checkIfSoftwareModuleIsSelected();
|
||||
}
|
||||
|
||||
private boolean isFilesDropped(final DragAndDropEvent event) {
|
||||
if (event.getTransferable() instanceof WrapperTransferable) {
|
||||
final Html5File[] files = ((WrapperTransferable) event.getTransferable()).getFiles();
|
||||
// other components can also be wrapped in WrapperTransferable , so
|
||||
// additional check on files
|
||||
if (files == null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Boolean checkIfSoftwareModuleIsSelected() {
|
||||
if (!isSoftwareModuleSelected()) {
|
||||
uiNotification.displayValidationError(i18n.get("message.error.noSwModuleSelected"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
SoftwareModule getSoftwareModuleSelected() {
|
||||
if (artifactUploadState.getSelectedBaseSoftwareModule().isPresent()) {
|
||||
return artifactUploadState.getSelectedBaseSoftwareModule().get();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Boolean isSoftwareModuleSelected() {
|
||||
if (!artifactUploadState.getSelectedBaseSwModuleId().isPresent()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if file selected is duplicate.i,e already selected for upload for
|
||||
* same software module.
|
||||
*
|
||||
* @param name
|
||||
* file name
|
||||
* @return Boolean
|
||||
*/
|
||||
public Boolean checkIfFileIsDuplicate(final String name) {
|
||||
Boolean isDuplicate = false;
|
||||
final SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get();
|
||||
final String currentBaseSoftwareModuleKey = HawkbitCommonUtil
|
||||
.getFormattedNameVersion(selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion());
|
||||
|
||||
for (final CustomFile customFile : artifactUploadState.getFileSelected()) {
|
||||
final String fileSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion(
|
||||
customFile.getBaseSoftwareModuleName(), customFile.getBaseSoftwareModuleVersion());
|
||||
if (customFile.getFileName().equals(name) && currentBaseSoftwareModuleKey.equals(fileSoftwareModuleKey)) {
|
||||
isDuplicate = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return isDuplicate;
|
||||
}
|
||||
|
||||
void decreaseNumberOfFileUploadsExpected() {
|
||||
numberOfFileUploadsExpected.decrementAndGet();
|
||||
}
|
||||
|
||||
List<String> getDuplicateFileNamesList() {
|
||||
return duplicateFileNamesList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update pending action count.
|
||||
*/
|
||||
void updateActionCount() {
|
||||
if (!artifactUploadState.getFileSelected().isEmpty()) {
|
||||
processBtn.setCaption(SPUILabelDefinitions.PROCESS + "<div class='unread'>"
|
||||
+ artifactUploadState.getFileSelected().size() + "</div>");
|
||||
} else {
|
||||
processBtn.setCaption(SPUILabelDefinitions.PROCESS);
|
||||
}
|
||||
}
|
||||
|
||||
void displayDuplicateValidationMessage() {
|
||||
// check if streaming of all dropped files are completed
|
||||
if (numberOfFilesActuallyUpload.intValue() == numberOfFileUploadsExpected.intValue()) {
|
||||
displayCompositeMessage();
|
||||
}
|
||||
}
|
||||
|
||||
private String getDuplicateFileValidationMessage() {
|
||||
final StringBuilder message = new StringBuilder();
|
||||
if (!duplicateFileNamesList.isEmpty()) {
|
||||
final String fileNames = StringUtils.collectionToCommaDelimitedString(duplicateFileNamesList);
|
||||
if (duplicateFileNamesList.size() == 1) {
|
||||
message.append(i18n.get("message.no.duplicateFile") + fileNames);
|
||||
|
||||
} else if (duplicateFileNamesList.size() > 1) {
|
||||
message.append(i18n.get("message.no.duplicateFiles"));
|
||||
}
|
||||
duplicateFileNamesList.clear();
|
||||
}
|
||||
return message.toString();
|
||||
}
|
||||
|
||||
public void showDuplicateMessage() {
|
||||
uiNotification.displayValidationError(getDuplicateFileValidationMessage());
|
||||
}
|
||||
|
||||
void increaseNumberOfFileUploadsExpected() {
|
||||
numberOfFileUploadsExpected.incrementAndGet();
|
||||
}
|
||||
|
||||
void updateFileSize(final String name, final long size) {
|
||||
final SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get();
|
||||
final String currentBaseSoftwareModuleKey = HawkbitCommonUtil
|
||||
.getFormattedNameVersion(selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion());
|
||||
|
||||
for (final CustomFile customFile : artifactUploadState.getFileSelected()) {
|
||||
final String fileSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion(
|
||||
customFile.getBaseSoftwareModuleName(), customFile.getBaseSoftwareModuleVersion());
|
||||
if (customFile.getFileName().equals(name) && currentBaseSoftwareModuleKey.equals(fileSoftwareModuleKey)) {
|
||||
customFile.setFileSize(size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void increaseNumberOfFilesActuallyUpload() {
|
||||
numberOfFilesActuallyUpload.incrementAndGet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable process button once upload is completed.
|
||||
*/
|
||||
boolean enableProcessBtn() {
|
||||
if (numberOfFilesActuallyUpload.intValue() >= numberOfFileUploadsExpected.intValue()) {
|
||||
processBtn.setEnabled(true);
|
||||
numberOfFileUploadsExpected.set(0);
|
||||
numberOfFilesActuallyUpload.set(0);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Set<CustomFile> getFileSelected() {
|
||||
return artifactUploadState.getFileSelected();
|
||||
}
|
||||
|
||||
private void discardUploadData(final Button.ClickEvent event) {
|
||||
if (event.getButton().equals(discardBtn)) {
|
||||
if (artifactUploadState.getFileSelected().isEmpty()) {
|
||||
uiNotification.displayValidationError(i18n.get("message.error.noFileSelected"));
|
||||
|
||||
} else {
|
||||
clearFileList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear details.
|
||||
*/
|
||||
void clearFileList() {
|
||||
// delete file system zombies
|
||||
artifactUploadState.getFileSelected().forEach(customFile -> {
|
||||
final File file = new File(customFile.getFilePath());
|
||||
file.delete();
|
||||
});
|
||||
|
||||
artifactUploadState.getFileSelected().clear();
|
||||
artifactUploadState.getBaseSwModuleList().clear();
|
||||
processBtn.setCaption(SPUILabelDefinitions.PROCESS);
|
||||
/* disable when there is no files to upload. */
|
||||
processBtn.setEnabled(false);
|
||||
numberOfFileUploadsExpected.set(0);
|
||||
numberOfFilesActuallyUpload.set(0);
|
||||
duplicateFileNamesList.clear();
|
||||
}
|
||||
|
||||
private void setConfirmationPopupHeightWidth(final float newWidth, final float newHeight) {
|
||||
if (currentUploadConfirmationwindow != null) {
|
||||
currentUploadConfirmationwindow.getUploadArtifactDetails().setWidth(HawkbitCommonUtil
|
||||
.getArtifactUploadPopupWidth(newWidth, SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_WIDTH),
|
||||
Unit.PIXELS);
|
||||
currentUploadConfirmationwindow.getUploadDetailsTable().setHeight(HawkbitCommonUtil
|
||||
.getArtifactUploadPopupHeight(newHeight, SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_HEIGHT),
|
||||
Unit.PIXELS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set artifact upload result pop up size changes.
|
||||
*
|
||||
* @param newWidth
|
||||
* new width of result pop up
|
||||
* @param newHeight
|
||||
* new height of result pop up
|
||||
*/
|
||||
void setResultPopupHeightWidth(final float newWidth, final float newHeight) {
|
||||
if (currentUploadConfirmationwindow != null
|
||||
&& currentUploadConfirmationwindow.getCurrentUploadResultWindow() != null) {
|
||||
final UploadResultWindow uploadResultWindow = currentUploadConfirmationwindow
|
||||
.getCurrentUploadResultWindow();
|
||||
uploadResultWindow.getUploadResultsWindow().setWidth(HawkbitCommonUtil.getArtifactUploadPopupWidth(newWidth,
|
||||
SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_WIDTH), Unit.PIXELS);
|
||||
uploadResultWindow.getUploadResultTable().setHeight(HawkbitCommonUtil.getArtifactUploadPopupHeight(
|
||||
newHeight, SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_HEIGHT), Unit.PIXELS);
|
||||
}
|
||||
}
|
||||
|
||||
private void displayConfirmWindow(final Button.ClickEvent event) {
|
||||
if (event.getComponent().getId().equals(SPUIComponetIdProvider.UPLOAD_PROCESS_BUTTON)) {
|
||||
if (artifactUploadState.getFileSelected().isEmpty()) {
|
||||
uiNotification.displayValidationError(i18n.get("message.error.noFileSelected"));
|
||||
} else {
|
||||
currentUploadConfirmationwindow = new UploadConfirmationwindow(this, artifactUploadState);
|
||||
UI.getCurrent().addWindow(currentUploadConfirmationwindow.getUploadConfrimationWindow());
|
||||
setConfirmationPopupHeightWidth(Page.getCurrent().getBrowserWindowWidth(),
|
||||
Page.getCurrent().getBrowserWindowHeight());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
I18N getI18n() {
|
||||
return i18n;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
SPInfo getSPInfo() {
|
||||
return spInfo;
|
||||
}
|
||||
|
||||
void setCurrentUploadConfirmationwindow(final UploadConfirmationwindow currentUploadConfirmationwindow) {
|
||||
this.currentUploadConfirmationwindow = currentUploadConfirmationwindow;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
|
||||
VerticalLayout getDropAreaLayout() {
|
||||
return dropAreaLayout;
|
||||
}
|
||||
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void onEvent(final UploadArtifactUIEvent event) {
|
||||
if (event == UploadArtifactUIEvent.DELETED_ALL_SOFWARE) {
|
||||
ui.access(() -> updateActionCount());
|
||||
}
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
void destroy() {
|
||||
/*
|
||||
* It's good manners to do this, even though vaadin-spring will
|
||||
* automatically unsubscribe when this UI is garbage collected.
|
||||
*/
|
||||
eventBus.unsubscribe(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* set upload status and confirmation window.
|
||||
*
|
||||
* @param newWidth
|
||||
* browser width
|
||||
* @param newHeight
|
||||
* browser height
|
||||
*/
|
||||
public void setUploadPopupSize(final float newWidth, final float newHeight) {
|
||||
setConfirmationPopupHeightWidth(newWidth, newHeight);
|
||||
setResultPopupHeightWidth(newWidth, newHeight);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param selectedBaseSoftwareModule
|
||||
*/
|
||||
public void refreshArtifactDetailsLayout(final SoftwareModule selectedBaseSoftwareModule) {
|
||||
eventBus.publish(this,
|
||||
new SoftwareModuleEvent(SoftwareModuleEventType.ARTIFACTS_CHANGED, selectedBaseSoftwareModule));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the fileUploadLayout
|
||||
*/
|
||||
public HorizontalLayout getFileUploadLayout() {
|
||||
return fileUploadLayout;
|
||||
}
|
||||
|
||||
public UINotification getUINotification() {
|
||||
return uiNotification;
|
||||
}
|
||||
|
||||
public void setHasDirectory(final Boolean hasDirectory) {
|
||||
this.hasDirectory = hasDirectory;
|
||||
}
|
||||
}
|
||||
@@ -1,198 +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.artifacts.upload;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
|
||||
import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleTiny;
|
||||
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.I18N;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
|
||||
|
||||
import com.vaadin.data.Item;
|
||||
import com.vaadin.data.util.IndexedContainer;
|
||||
import com.vaadin.ui.Alignment;
|
||||
import com.vaadin.ui.Button;
|
||||
import com.vaadin.ui.Button.ClickEvent;
|
||||
import com.vaadin.ui.HorizontalLayout;
|
||||
import com.vaadin.ui.Label;
|
||||
import com.vaadin.ui.Table;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
import com.vaadin.ui.Window;
|
||||
import com.vaadin.ui.themes.ValoTheme;
|
||||
|
||||
/**
|
||||
* Upload status popup.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class UploadResultWindow implements Button.ClickListener {
|
||||
|
||||
private static final long serialVersionUID = 5205927189362269027L;
|
||||
|
||||
private List<UploadStatus> uploadResultList = new ArrayList<>();
|
||||
|
||||
private Button closeBtn;
|
||||
|
||||
private Table uploadResultTable;
|
||||
|
||||
private Window uploadResultsWindow;
|
||||
|
||||
private IndexedContainer tabelContainer;
|
||||
|
||||
private final I18N i18n;
|
||||
|
||||
private static final String FILE_NAME = "fileName";
|
||||
|
||||
private static final String BASE_SW_MODULE = "baseSwModuleName";
|
||||
|
||||
private static final String UPLOAD_RESULT = "uploadResult";
|
||||
|
||||
private static final String REASON = "reason";
|
||||
|
||||
/**
|
||||
* Initialize upload status popup.
|
||||
*
|
||||
* @param uploadResultList
|
||||
* upload status details
|
||||
* @param i18n
|
||||
* I18N
|
||||
*/
|
||||
public UploadResultWindow(final List<UploadStatus> uploadResultList, final I18N i18n) {
|
||||
this.uploadResultList = uploadResultList;
|
||||
this.i18n = i18n;
|
||||
createComponents();
|
||||
createLayout();
|
||||
}
|
||||
|
||||
private void createComponents() {
|
||||
closeBtn = SPUIComponentProvider.getButton(SPUIComponetIdProvider.UPLOAD_ARTIFACT_RESULT_CLOSE,
|
||||
SPUILabelDefinitions.CLOSE, SPUILabelDefinitions.CLOSE, ValoTheme.BUTTON_PRIMARY, false, null,
|
||||
SPUIButtonStyleTiny.class);
|
||||
closeBtn.addClickListener(this);
|
||||
|
||||
uploadResultTable = new Table();
|
||||
uploadResultTable.addStyleName("artifact-table");
|
||||
uploadResultTable.setSizeFull();
|
||||
uploadResultTable.setImmediate(true);
|
||||
uploadResultTable.setId(SPUIComponetIdProvider.UPLOAD_RESULT_TABLE);
|
||||
uploadResultTable.addStyleName(ValoTheme.TABLE_BORDERLESS);
|
||||
uploadResultTable.addStyleName(ValoTheme.TABLE_SMALL);
|
||||
uploadResultTable.addStyleName(ValoTheme.TABLE_NO_VERTICAL_LINES);
|
||||
uploadResultTable.addStyleName("accordion-tab-table-style");
|
||||
|
||||
populateUploadResultTable();
|
||||
}
|
||||
|
||||
private void populateUploadResultTable() {
|
||||
setTableContainer();
|
||||
Label statusLabel;
|
||||
Label reasonLabel;
|
||||
for (final UploadStatus uploadResult : uploadResultList) {
|
||||
final Item newItem = tabelContainer
|
||||
.addItem(uploadResult.getBaseSwModuleName() + "/" + uploadResult.getFileName());
|
||||
newItem.getItemProperty(FILE_NAME).setValue(HawkbitCommonUtil.getFormatedLabel(uploadResult.getFileName()));
|
||||
newItem.getItemProperty(BASE_SW_MODULE)
|
||||
.setValue(HawkbitCommonUtil.getFormatedLabel(uploadResult.getBaseSwModuleName()));
|
||||
|
||||
if (uploadResult.getUploadResult().equals(SPUILabelDefinitions.SUCCESS)) {
|
||||
statusLabel = new Label(HawkbitCommonUtil.getFormatedLabel(i18n.get("upload.success")));
|
||||
statusLabel.addStyleName("validation-success");
|
||||
newItem.getItemProperty(UPLOAD_RESULT).setValue(statusLabel);
|
||||
} else {
|
||||
statusLabel = new Label(HawkbitCommonUtil.getFormatedLabel(i18n.get("upload.failed")));
|
||||
statusLabel.addStyleName("validation-failed");
|
||||
newItem.getItemProperty(UPLOAD_RESULT).setValue(statusLabel);
|
||||
}
|
||||
|
||||
reasonLabel = HawkbitCommonUtil.getFormatedLabel(uploadResult.getReason());
|
||||
reasonLabel.setDescription(uploadResult.getReason());
|
||||
final String idStr = SPUIComponetIdProvider.UPLOAD_ERROR_REASON + uploadResult.getBaseSwModuleName() + "/"
|
||||
+ uploadResult.getFileName();
|
||||
reasonLabel.setId(idStr);
|
||||
newItem.getItemProperty(REASON).setValue(reasonLabel);
|
||||
}
|
||||
}
|
||||
|
||||
private void setTableContainer() {
|
||||
tabelContainer = new IndexedContainer();
|
||||
|
||||
tabelContainer.addContainerProperty(FILE_NAME, Label.class, null);
|
||||
tabelContainer.addContainerProperty(BASE_SW_MODULE, Label.class, null);
|
||||
tabelContainer.addContainerProperty(UPLOAD_RESULT, Label.class, null);
|
||||
tabelContainer.addContainerProperty(REASON, Label.class, null);
|
||||
|
||||
uploadResultTable.setContainerDataSource(tabelContainer);
|
||||
uploadResultTable.setPageLength(10);
|
||||
uploadResultTable.setColumnHeader(FILE_NAME, i18n.get("upload.file.name"));
|
||||
uploadResultTable.setColumnHeader(BASE_SW_MODULE, i18n.get("upload.swModuleTable.header"));
|
||||
uploadResultTable.setColumnHeader(UPLOAD_RESULT, i18n.get("upload.result.status"));
|
||||
uploadResultTable.setColumnHeader(REASON, i18n.get("upload.reason"));
|
||||
|
||||
uploadResultTable.setColumnExpandRatio(FILE_NAME, 0.2f);
|
||||
uploadResultTable.setColumnExpandRatio(BASE_SW_MODULE, 0.2f);
|
||||
uploadResultTable.setColumnExpandRatio(UPLOAD_RESULT, 0.12f);
|
||||
uploadResultTable.setColumnExpandRatio(REASON, 0.48f);
|
||||
final Object[] visibileColumn = { FILE_NAME, BASE_SW_MODULE, UPLOAD_RESULT, REASON };
|
||||
uploadResultTable.setVisibleColumns(visibileColumn);
|
||||
}
|
||||
|
||||
private void createLayout() {
|
||||
final HorizontalLayout footer = new HorizontalLayout();
|
||||
footer.setSizeUndefined();
|
||||
footer.addStyleName("confirmation-window-footer");
|
||||
footer.setSpacing(true);
|
||||
footer.setMargin(false);
|
||||
footer.addComponents(closeBtn);
|
||||
footer.setComponentAlignment(closeBtn, Alignment.TOP_CENTER);
|
||||
|
||||
final VerticalLayout uploadResultDetails = new VerticalLayout();
|
||||
uploadResultDetails.setWidth(SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_WIDTH + "px");
|
||||
uploadResultDetails.addStyleName("confirmation-popup");
|
||||
uploadResultDetails.addComponent(uploadResultTable);
|
||||
uploadResultDetails.setComponentAlignment(uploadResultTable, Alignment.MIDDLE_CENTER);
|
||||
uploadResultDetails.addComponent(footer);
|
||||
uploadResultDetails.setComponentAlignment(footer, Alignment.MIDDLE_CENTER);
|
||||
|
||||
uploadResultsWindow = new Window();
|
||||
uploadResultsWindow.setContent(uploadResultDetails);
|
||||
uploadResultsWindow.setResizable(Boolean.FALSE);
|
||||
uploadResultsWindow.setClosable(Boolean.FALSE);
|
||||
uploadResultsWindow.setDraggable(Boolean.TRUE);
|
||||
uploadResultsWindow.setModal(true);
|
||||
uploadResultsWindow.setCaption(SPUILabelDefinitions.UPLOAD_RESULT);
|
||||
uploadResultsWindow.addStyleName(SPUIStyleDefinitions.CONFIRMATION_WINDOW_CAPTION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonClick(final ClickEvent event) {
|
||||
if (event.getComponent().getId().equals(SPUIComponetIdProvider.UPLOAD_ARTIFACT_RESULT_CLOSE)
|
||||
|| event.getComponent().getId().equals(SPUIComponetIdProvider.UPLOAD_ARTIFACT_RESULT_POPUP_CLOSE)) {
|
||||
uploadResultsWindow.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Window getUploadResultsWindow() {
|
||||
return uploadResultsWindow;
|
||||
}
|
||||
|
||||
public Table getUploadResultTable() {
|
||||
return uploadResultTable;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,65 +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.artifacts.upload;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Artifact upload status.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class UploadStatus implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 8500552533390925782L;
|
||||
|
||||
private String uploadResult;
|
||||
|
||||
private String reason;
|
||||
|
||||
private String fileName;
|
||||
|
||||
private String baseSwModuleName;
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public String getBaseSwModuleName() {
|
||||
return baseSwModuleName;
|
||||
}
|
||||
|
||||
public void setBaseSwModuleName(String baseSwModuleName) {
|
||||
this.baseSwModuleName = baseSwModuleName;
|
||||
}
|
||||
|
||||
public String getUploadResult() {
|
||||
return uploadResult;
|
||||
}
|
||||
|
||||
public void setUploadResult(String uploadResult) {
|
||||
this.uploadResult = uploadResult;
|
||||
}
|
||||
|
||||
public String getReason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
public void setReason(String reason) {
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,225 +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.artifacts.upload;
|
||||
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
|
||||
|
||||
import com.vaadin.data.Item;
|
||||
import com.vaadin.data.util.IndexedContainer;
|
||||
import com.vaadin.server.FontAwesome;
|
||||
import com.vaadin.shared.ui.window.WindowMode;
|
||||
import com.vaadin.spring.annotation.SpringComponent;
|
||||
import com.vaadin.spring.annotation.ViewScope;
|
||||
import com.vaadin.ui.Grid;
|
||||
import com.vaadin.ui.Grid.SelectionMode;
|
||||
import com.vaadin.ui.UI;
|
||||
import com.vaadin.ui.Window;
|
||||
import com.vaadin.ui.renderers.HtmlRenderer;
|
||||
import com.vaadin.ui.renderers.ProgressBarRenderer;
|
||||
|
||||
import elemental.json.JsonValue;
|
||||
|
||||
/**
|
||||
* Shows upload status during upload.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
@ViewScope
|
||||
@SpringComponent
|
||||
public class UploadStatusInfoWindow extends Window implements Window.CloseListener, Window.WindowModeChangeListener {
|
||||
|
||||
private static final String PROGRESS = "Progress";
|
||||
|
||||
private static final String FILE_NAME = "File name";
|
||||
|
||||
private static final String STATUS = "Status";
|
||||
|
||||
private static final String REASON = "Reason";
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Grid grid;
|
||||
|
||||
private final IndexedContainer uploads;
|
||||
|
||||
private volatile boolean errorOccured = false;
|
||||
|
||||
/**
|
||||
* Default Constructor.
|
||||
*/
|
||||
UploadStatusInfoWindow() {
|
||||
super("Upload Status");
|
||||
|
||||
addStyleName(SPUIStyleDefinitions.UPLOAD_INFO);
|
||||
center();
|
||||
setImmediate(true);
|
||||
setResizable(true);
|
||||
setDraggable(true);
|
||||
setClosable(true);
|
||||
uploads = new IndexedContainer();
|
||||
uploads.addContainerProperty(STATUS, String.class, "Active");
|
||||
uploads.addContainerProperty(FILE_NAME, String.class, null);
|
||||
uploads.addContainerProperty(PROGRESS, Double.class, 0D);
|
||||
uploads.addContainerProperty(REASON, String.class, "");
|
||||
|
||||
grid = new Grid(uploads);
|
||||
grid.addStyleName(SPUIStyleDefinitions.UPLOAD_STATUS_GRID);
|
||||
grid.setSelectionMode(SelectionMode.NONE);
|
||||
grid.getColumn(STATUS).setRenderer(new StatusRenderer());
|
||||
grid.getColumn(PROGRESS).setRenderer(new ProgressBarRenderer());
|
||||
setColumnWidth();
|
||||
grid.setFrozenColumnCount(4);
|
||||
grid.setColumnOrder(STATUS, PROGRESS, FILE_NAME, REASON);
|
||||
grid.setHeaderVisible(true);
|
||||
grid.setImmediate(true);
|
||||
setPopupSizeInMinMode();
|
||||
|
||||
setContent(grid);
|
||||
addCloseListener(this);
|
||||
addWindowModeChangeListener(this);
|
||||
}
|
||||
|
||||
private void setColumnWidth() {
|
||||
grid.getColumn(STATUS).setWidth(70);
|
||||
grid.getColumn(PROGRESS).setWidth(150);
|
||||
grid.getColumn(FILE_NAME).setWidth(280);
|
||||
grid.getColumn(REASON).setWidth(300);
|
||||
}
|
||||
|
||||
private void resetColumnWidth() {
|
||||
grid.getColumn(STATUS).setWidthUndefined();
|
||||
grid.getColumn(PROGRESS).setWidthUndefined();
|
||||
grid.getColumn(FILE_NAME).setWidthUndefined();
|
||||
grid.getColumn(REASON).setWidthUndefined();
|
||||
|
||||
}
|
||||
|
||||
private static class StatusRenderer extends HtmlRenderer {
|
||||
|
||||
@Override
|
||||
public JsonValue encode(final String value) {
|
||||
|
||||
String result = "";
|
||||
switch (value) {
|
||||
case "Finished":
|
||||
result = "<div class=\"statusIconGreen\">" + FontAwesome.CHECK_CIRCLE.getHtml() + "</div>";
|
||||
break;
|
||||
case "Failed":
|
||||
result = "<div class=\"statusIconRed\">" + FontAwesome.EXCLAMATION_CIRCLE.getHtml() + "</div>";
|
||||
break;
|
||||
default:
|
||||
result = "<div class=\"statusIconActive\"></div>";
|
||||
}
|
||||
|
||||
return super.encode(result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatically close if not error has occured.
|
||||
*/
|
||||
void uploadSessionFinished() {
|
||||
if (!errorOccured) {
|
||||
close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void uploadSessionStarted() {
|
||||
close();
|
||||
UI.getCurrent().addWindow(this);
|
||||
center();
|
||||
}
|
||||
|
||||
void uploadStarted(final String filename) {
|
||||
final Item item = uploads.addItem(filename);
|
||||
item.getItemProperty(FILE_NAME).setValue(filename);
|
||||
grid.scrollToEnd();
|
||||
|
||||
}
|
||||
|
||||
void updateProgress(final String filename, final long readBytes, final long contentLength) {
|
||||
final Item item = uploads.getItem(filename);
|
||||
if (item != null) {
|
||||
item.getItemProperty(PROGRESS).setValue((double) readBytes / (double) contentLength);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when each file upload is success.
|
||||
*
|
||||
* @param filename
|
||||
* of the uploaded file.
|
||||
*/
|
||||
public void uploadSucceeded(final String filename) {
|
||||
final Item item = uploads.getItem(filename);
|
||||
if (item != null) {
|
||||
item.getItemProperty(STATUS).setValue("Finished");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void uploadFailed(final String filename, final String errorReason) {
|
||||
final Item item = uploads.getItem(filename);
|
||||
if (item != null) {
|
||||
if (!errorOccured) {
|
||||
errorOccured = true;
|
||||
}
|
||||
item.getItemProperty(REASON).setValue(errorReason);
|
||||
item.getItemProperty(STATUS).setValue("Failed");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.vaadin.ui.Window.CloseListener#windowClose(com.vaadin.ui.Window.
|
||||
* CloseEvent)
|
||||
*/
|
||||
@Override
|
||||
public void windowClose(final CloseEvent e) {
|
||||
clearWindow();
|
||||
}
|
||||
|
||||
private void clearWindow() {
|
||||
errorOccured = false;
|
||||
uploads.removeAllItems();
|
||||
setWindowMode(WindowMode.NORMAL);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.vaadin.ui.Window.WindowModeChangeListener#windowModeChanged(com.
|
||||
* vaadin.ui.Window. WindowModeChangeEvent)
|
||||
*/
|
||||
@Override
|
||||
public void windowModeChanged(final WindowModeChangeEvent event) {
|
||||
if (event.getWindow().getWindowMode() == WindowMode.MAXIMIZED) {
|
||||
resetColumnWidth();
|
||||
grid.getColumn(STATUS).setExpandRatio(0);
|
||||
grid.getColumn(PROGRESS).setExpandRatio(1);
|
||||
grid.getColumn(FILE_NAME).setExpandRatio(2);
|
||||
grid.getColumn(REASON).setExpandRatio(3);
|
||||
grid.setSizeFull();
|
||||
} else {
|
||||
setColumnWidth();
|
||||
setPopupSizeInMinMode();
|
||||
}
|
||||
}
|
||||
|
||||
private void setPopupSizeInMinMode() {
|
||||
grid.setWidth(800, Unit.PIXELS);
|
||||
grid.setHeight(510, Unit.PIXELS);
|
||||
}
|
||||
}
|
||||
@@ -1,190 +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.common;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.hawkbit.ui.management.event.DragEvent;
|
||||
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.UINotification;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.vaadin.spring.events.EventBus;
|
||||
|
||||
import com.vaadin.event.dd.DragAndDropEvent;
|
||||
import com.vaadin.event.dd.acceptcriteria.ServerSideCriterion;
|
||||
import com.vaadin.server.Page;
|
||||
import com.vaadin.ui.Component;
|
||||
import com.vaadin.ui.DragAndDropWrapper;
|
||||
import com.vaadin.ui.DragAndDropWrapper.WrapperTargetDetails;
|
||||
import com.vaadin.ui.Table;
|
||||
|
||||
/**
|
||||
* Abstract class for Accept criteria.
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractAcceptCriteria extends ServerSideCriterion {
|
||||
|
||||
private static final long serialVersionUID = 3218899104852691974L;
|
||||
|
||||
private int previousRowCount;
|
||||
|
||||
@Autowired
|
||||
protected transient UINotification uiNotification;
|
||||
|
||||
@Autowired
|
||||
protected transient EventBus.SessionEventBus eventBus;
|
||||
|
||||
@Override
|
||||
public boolean accept(final DragAndDropEvent dragEvent) {
|
||||
final Component compsource = dragEvent.getTransferable().getSourceComponent();
|
||||
final Component compdestination = dragEvent.getTargetDetails().getTarget();
|
||||
final int typeVal = getMouseEventType(compdestination, dragEvent);
|
||||
|
||||
showHideDropAreaHighlights(typeVal, compsource, dragEvent);
|
||||
if (isValidDrop(compsource, compdestination)) {
|
||||
return true;
|
||||
} else {
|
||||
// Display action not allowed notification for invalid drop
|
||||
/* mouse event will be Event.ONMOUSEUP on drop */
|
||||
// From com.google.gwt.user.client.Event
|
||||
if (typeVal == 8) {
|
||||
invalidDrop();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private int getMouseEventType(final Component compdestination, final DragAndDropEvent dragEvent) {
|
||||
int typeVal = 0;
|
||||
if (compdestination instanceof DragAndDropWrapper) {
|
||||
final WrapperTargetDetails details = (WrapperTargetDetails) dragEvent.getTargetDetails();
|
||||
typeVal = details.getMouseEvent().getType();
|
||||
|
||||
} else if (compdestination instanceof Table && dragEvent.getTargetDetails().getData("mouseEvent") != null) {
|
||||
final String mouseEventDetails = dragEvent.getTargetDetails().getData("mouseEvent").toString();
|
||||
final String[] strArray = mouseEventDetails.split("\\,");
|
||||
typeVal = Integer.parseInt(strArray[7]);
|
||||
}
|
||||
return typeVal;
|
||||
}
|
||||
|
||||
private void showHideDropAreaHighlights(final int typeVal, final Component compsource,
|
||||
final DragAndDropEvent dragEvent) {
|
||||
/* mouse event will be Event.ONMOUSEUP on drop */
|
||||
// From com.google.gwt.user.client.Event
|
||||
if (typeVal == 8) {
|
||||
hideDropHints();
|
||||
} else {
|
||||
if (compsource instanceof Table) {
|
||||
showRowCount(dragEvent, (Table) compsource);
|
||||
}
|
||||
analyseDragComponent(compsource);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param dragEvent
|
||||
* @param compsource
|
||||
*/
|
||||
protected void showRowCount(final DragAndDropEvent dragEvent, final Table compsource) {
|
||||
/* Show the number of rows that are dragging in the drag image */
|
||||
final Set<String> targetSelectedList = new HashSet<>((Set<String>) compsource.getValue());
|
||||
/**
|
||||
* Remove null value if any .
|
||||
*/
|
||||
targetSelectedList.remove(null);
|
||||
|
||||
if (previousRowCount != targetSelectedList.size()) {
|
||||
previousRowCount = targetSelectedList.size();
|
||||
/*
|
||||
* Prepare the hava script to add the <style> tag to the head of the
|
||||
* html
|
||||
*/
|
||||
if (!targetSelectedList.contains(dragEvent.getTransferable().getData(SPUIDefinitions.ITEMID))) {
|
||||
previousRowCount = 1;
|
||||
}
|
||||
final String exeJS = HawkbitCommonUtil.getDragRowCountJavaScript(previousRowCount);
|
||||
Page.getCurrent().getJavaScript().execute(exeJS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyze the dragging component and do respective actions.
|
||||
*
|
||||
* @param compsource
|
||||
* reference of drag component.
|
||||
*/
|
||||
protected void analyseDragComponent(final Component compsource) {
|
||||
final String sourceID = getComponentId(compsource);
|
||||
final Object event = getDropHintConfigurations().get(sourceID);
|
||||
eventBus.publish(this, event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if source is valid drop on destination.
|
||||
*
|
||||
* @param compsource
|
||||
* is the component which is dragging.
|
||||
* @param compdestination
|
||||
* is the destination component trying to drop.
|
||||
* @return
|
||||
*/
|
||||
private boolean isValidDrop(final Component compsource, final Component compdestination) {
|
||||
final String sourceID = getComponentId(compsource);
|
||||
final String destinationID = getComponentId(compdestination);
|
||||
final List<String> acceptableComponents = getDropConfigurations().get(destinationID);
|
||||
// check if the destination component Id is available in acceptable
|
||||
// components
|
||||
return acceptableComponents != null && acceptableComponents.contains(sourceID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the id the component if it is button get its prefix.
|
||||
*
|
||||
* @param component
|
||||
* for the id has to identify.
|
||||
* @return 'id' of the component.
|
||||
*/
|
||||
protected abstract String getComponentId(final Component component);
|
||||
|
||||
/**
|
||||
* Hide the drop hints. Dragging is stopped.
|
||||
*/
|
||||
protected void hideDropHints() {
|
||||
eventBus.publish(this, DragEvent.HIDE_DROP_HINT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display invalid drop message.
|
||||
*/
|
||||
protected void invalidDrop() {
|
||||
uiNotification.displayValidationError(SPUILabelDefinitions.ACTION_NOT_ALLOWED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
protected abstract Map<String, Object> getDropHintConfigurations();
|
||||
|
||||
/**
|
||||
* Get drop configurations in Map collection like component Id as "key" and
|
||||
* its list of acceptable component Id as "value".
|
||||
*
|
||||
* @return reference of {@link Map} of component Id
|
||||
*/
|
||||
protected abstract Map<String, List<String>> getDropConfigurations();
|
||||
|
||||
}
|
||||
@@ -1,158 +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.common;
|
||||
|
||||
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
|
||||
import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleTiny;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
|
||||
|
||||
import com.vaadin.server.Resource;
|
||||
import com.vaadin.shared.ui.label.ContentMode;
|
||||
import com.vaadin.ui.Alignment;
|
||||
import com.vaadin.ui.Button;
|
||||
import com.vaadin.ui.Button.ClickEvent;
|
||||
import com.vaadin.ui.HorizontalLayout;
|
||||
import com.vaadin.ui.Label;
|
||||
import com.vaadin.ui.UI;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
import com.vaadin.ui.Window;
|
||||
import com.vaadin.ui.themes.ValoTheme;
|
||||
|
||||
/**
|
||||
*
|
||||
* module.
|
||||
*
|
||||
*/
|
||||
public class ConfirmationDialog implements Button.ClickListener {
|
||||
/** Serial version UID. */
|
||||
private static final long serialVersionUID = 1L;
|
||||
/** The confirmation callback. */
|
||||
private transient ConfirmationDialogCallback callback;
|
||||
private final Button okButton;
|
||||
private final Window window;
|
||||
|
||||
/**
|
||||
* Constructor for configuring confirmation dialog.
|
||||
*
|
||||
* @param caption
|
||||
* the dialog caption.
|
||||
* @param question
|
||||
* the question.
|
||||
* @param okLabel
|
||||
* the Ok button label.
|
||||
* @param cancelLabel
|
||||
* the cancel button label.
|
||||
* @param callback
|
||||
* the callback.
|
||||
*/
|
||||
public ConfirmationDialog(final String caption, final String question, final String okLabel,
|
||||
final String cancelLabel, final ConfirmationDialogCallback callback) {
|
||||
this(caption, question, okLabel, cancelLabel, callback, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for configuring confirmation dialog.
|
||||
*
|
||||
* @param caption
|
||||
* the dialog caption.
|
||||
* @param question
|
||||
* the question.
|
||||
* @param okLabel
|
||||
* the Ok button label.
|
||||
* @param cancelLabel
|
||||
* the cancel button label.
|
||||
* @param callback
|
||||
* the callback.
|
||||
* @param icon
|
||||
* the icon of the dialog
|
||||
*/
|
||||
public ConfirmationDialog(final String caption, final String question, final String okLabel,
|
||||
final String cancelLabel, final ConfirmationDialogCallback callback, final Resource icon) {
|
||||
window = new Window(caption);
|
||||
window.addStyleName(SPUIStyleDefinitions.CONFIRMATION_WINDOW_CAPTION);
|
||||
|
||||
if (icon != null) {
|
||||
window.setIcon(icon);
|
||||
}
|
||||
|
||||
okButton = SPUIComponentProvider.getButton(SPUIComponetIdProvider.OK_BUTTON, okLabel, "",
|
||||
ValoTheme.BUTTON_PRIMARY, false, null, SPUIButtonStyleTiny.class);
|
||||
okButton.addClickListener(this);
|
||||
|
||||
final Button cancelButton = SPUIComponentProvider.getButton(null, cancelLabel, "", null, false, null,
|
||||
SPUIButtonStyleTiny.class);
|
||||
cancelButton.addClickListener(this);
|
||||
window.setModal(true);
|
||||
window.addStyleName(SPUIStyleDefinitions.CONFIRMBOX_WINDOW_SYLE);
|
||||
if (this.callback == null) {
|
||||
this.callback = callback;
|
||||
}
|
||||
final VerticalLayout vLayout = new VerticalLayout();
|
||||
|
||||
if (question != null) {
|
||||
final Label questionLbl = new Label(String.format("<p>%s</p>", question.replaceAll("\n", "<br/>")),
|
||||
ContentMode.HTML);
|
||||
questionLbl.addStyleName(SPUIStyleDefinitions.CONFIRMBOX_QUESTION_LABEL);
|
||||
vLayout.addComponent(questionLbl);
|
||||
|
||||
}
|
||||
|
||||
final HorizontalLayout hButtonLayout = new HorizontalLayout();
|
||||
hButtonLayout.setSpacing(true);
|
||||
hButtonLayout.addComponent(okButton);
|
||||
hButtonLayout.addComponent(cancelButton);
|
||||
hButtonLayout.setSizeUndefined();
|
||||
hButtonLayout.setComponentAlignment(okButton, Alignment.TOP_CENTER);
|
||||
hButtonLayout.setComponentAlignment(cancelButton, Alignment.TOP_CENTER);
|
||||
|
||||
vLayout.addComponent(hButtonLayout);
|
||||
vLayout.setComponentAlignment(hButtonLayout, Alignment.BOTTOM_CENTER);
|
||||
window.setContent(vLayout);
|
||||
window.setResizable(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Event handler for button clicks.
|
||||
*
|
||||
* @param event
|
||||
* the click event.
|
||||
*/
|
||||
@Override
|
||||
public void buttonClick(final ClickEvent event) {
|
||||
if (window.getParent() != null) {
|
||||
UI.getCurrent().removeWindow(window);
|
||||
}
|
||||
callback.response(event.getSource().equals(okButton));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the window which holds the confirmation dialog
|
||||
*
|
||||
* @return the window which holds the confirmation dialog
|
||||
*/
|
||||
public Window getWindow() {
|
||||
return window;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface for confirmation dialog callbacks.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface ConfirmationDialogCallback {
|
||||
/**
|
||||
* The user response.
|
||||
*
|
||||
* @param ok
|
||||
* True if user clicked ok.
|
||||
*/
|
||||
void response(boolean ok);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,63 +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.common;
|
||||
|
||||
import com.vaadin.shared.ui.colorpicker.Color;
|
||||
import com.vaadin.ui.AbstractColorPicker.Coordinates2Color;
|
||||
|
||||
/**
|
||||
* Converts 2d-coordinates to a Color.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class CoordinatesToColor implements Coordinates2Color {
|
||||
|
||||
private static final long serialVersionUID = 9145071998551210789L;
|
||||
|
||||
@Override
|
||||
public Color calculate(final int x, final int y) {
|
||||
return calculateHSVColor(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] calculate(final Color color) {
|
||||
final float[] hsv = color.getHSV();
|
||||
final int x = Math.round(hsv[0] * 220f);
|
||||
int y = 0;
|
||||
y = calculateYCoordinateOfColor(hsv);
|
||||
return new int[] { x, y };
|
||||
}
|
||||
|
||||
private Color calculateHSVColor(final int x, final int y) {
|
||||
final float h = x / 220f;
|
||||
float s = 1f;
|
||||
float v = 1f;
|
||||
if (y < 110) {
|
||||
s = y / 110f;
|
||||
} else if (y > 110) {
|
||||
v = 1f - (y - 110f) / 110f;
|
||||
}
|
||||
return new Color(Color.HSVtoRGB(h, s, v));
|
||||
}
|
||||
|
||||
private int calculateYCoordinateOfColor(final float[] hsv) {
|
||||
int y;
|
||||
// lower half
|
||||
/* Assuming hsv[] array value will have in the range of 0 to 1 */
|
||||
if (hsv[1] < 1f) {
|
||||
y = Math.round(hsv[1] * 110f);
|
||||
} else {
|
||||
y = Math.round(110f - (hsv[1] + hsv[2]) * 110f);
|
||||
}
|
||||
return y;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,104 +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.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SpringContextHelper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
import org.vaadin.addons.lazyquerycontainer.AbstractBeanQuery;
|
||||
import org.vaadin.addons.lazyquerycontainer.QueryDefinition;
|
||||
|
||||
/**
|
||||
* Distribution Set Type Bean query.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class DistributionSetTypeBeanQuery extends AbstractBeanQuery<DistributionSetType> {
|
||||
|
||||
private static final long serialVersionUID = 1329137292955215629L;
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(DistributionSetTypeBeanQuery.class);
|
||||
|
||||
private final Sort sort = new Sort(Direction.ASC, "name");
|
||||
private transient Page<DistributionSetType> firstPageDistSetType = null;
|
||||
private transient DistributionSetManagement distributionSetManagement;
|
||||
|
||||
/**
|
||||
* Parametric constructor.
|
||||
*
|
||||
* @param definition
|
||||
* @param queryConfig
|
||||
* @param sortIds
|
||||
* @param sortStates
|
||||
*/
|
||||
public DistributionSetTypeBeanQuery(final QueryDefinition definition, final Map<String, Object> queryConfig,
|
||||
final Object[] sortIds, final boolean[] sortStates) {
|
||||
super(definition, queryConfig, sortIds, sortStates);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DistributionSetType constructBean() {
|
||||
|
||||
return new DistributionSetType("", "", "", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
|
||||
firstPageDistSetType = getDistributionSetManagement()
|
||||
.findDistributionSetTypesAll(new OffsetBasedPageRequest(0, SPUIDefinitions.PAGE_SIZE, sort));
|
||||
long size = firstPageDistSetType.getTotalElements();
|
||||
if (size > Integer.MAX_VALUE) {
|
||||
size = Integer.MAX_VALUE;
|
||||
}
|
||||
return (int) size;
|
||||
}
|
||||
|
||||
private DistributionSetManagement getDistributionSetManagement() {
|
||||
if (distributionSetManagement == null) {
|
||||
distributionSetManagement = SpringContextHelper.getBean(DistributionSetManagement.class);
|
||||
}
|
||||
return distributionSetManagement;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<DistributionSetType> loadBeans(final int startIndex, final int count) {
|
||||
Page<DistributionSetType> typeBeans;
|
||||
final List<DistributionSetType> distSetTypeList = new ArrayList<>();
|
||||
if (startIndex == 0 && firstPageDistSetType != null) {
|
||||
typeBeans = firstPageDistSetType;
|
||||
} else {
|
||||
typeBeans = getDistributionSetManagement()
|
||||
.findDistributionSetTypesAll(new OffsetBasedPageRequest(startIndex, count, sort));
|
||||
}
|
||||
|
||||
distSetTypeList.addAll(typeBeans.getContent());
|
||||
return distSetTypeList;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveBeans(final List<DistributionSetType> arg0, final List<DistributionSetType> arg1,
|
||||
final List<DistributionSetType> arg2) {
|
||||
LOG.info("in side of save Bean()");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,35 +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.common;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Interface for all entity states UI to show the details to a entity.
|
||||
*/
|
||||
public interface ManagmentEntityState<T> {
|
||||
|
||||
/**
|
||||
* The selected entities for the detail.
|
||||
*
|
||||
* @param values
|
||||
* the selected entities.
|
||||
*
|
||||
*/
|
||||
void setSelectedEnitities(Set<T> values);
|
||||
|
||||
/**
|
||||
* The last selected value.
|
||||
*
|
||||
* @param value
|
||||
* the value
|
||||
*/
|
||||
void setLastSelectedEntity(T value);
|
||||
|
||||
}
|
||||
@@ -1,89 +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.common;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
|
||||
import org.eclipse.hawkbit.repository.SoftwareManagement;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SpringContextHelper;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
import org.vaadin.addons.lazyquerycontainer.AbstractBeanQuery;
|
||||
import org.vaadin.addons.lazyquerycontainer.QueryDefinition;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class SoftwareModuleTypeBeanQuery extends AbstractBeanQuery<SoftwareModuleType> {
|
||||
private static final long serialVersionUID = 7824925429198339644L;
|
||||
private final Sort sort = new Sort(Direction.ASC, "name");
|
||||
private transient Page<SoftwareModuleType> firstPageSwModuleType = null;
|
||||
private transient SoftwareManagement softwareManagement;
|
||||
|
||||
/**
|
||||
* Parametric constructor.
|
||||
*
|
||||
* @param definition
|
||||
* @param queryConfig
|
||||
* @param sortIds
|
||||
* @param sortStates
|
||||
*/
|
||||
public SoftwareModuleTypeBeanQuery(final QueryDefinition definition, final Map<String, Object> queryConfig,
|
||||
final Object[] sortIds, final boolean[] sortStates) {
|
||||
super(definition, queryConfig, sortIds, sortStates);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SoftwareModuleType constructBean() {
|
||||
return new SoftwareModuleType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
firstPageSwModuleType = getSoftwareManagement()
|
||||
.findSoftwareModuleTypesAll(new OffsetBasedPageRequest(0, SPUIDefinitions.PAGE_SIZE, sort));
|
||||
long size = firstPageSwModuleType.getTotalElements();
|
||||
if (size > Integer.MAX_VALUE) {
|
||||
size = Integer.MAX_VALUE;
|
||||
}
|
||||
return (int) size;
|
||||
}
|
||||
|
||||
private SoftwareManagement getSoftwareManagement() {
|
||||
if (softwareManagement == null) {
|
||||
softwareManagement = SpringContextHelper.getBean(SoftwareManagement.class);
|
||||
}
|
||||
return softwareManagement;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<SoftwareModuleType> loadBeans(final int startIndex, final int count) {
|
||||
Page<SoftwareModuleType> swModuleTypeBeans;
|
||||
if (startIndex == 0 && firstPageSwModuleType != null) {
|
||||
swModuleTypeBeans = firstPageSwModuleType;
|
||||
} else {
|
||||
swModuleTypeBeans = getSoftwareManagement()
|
||||
.findSoftwareModuleTypesAll(new OffsetBasedPageRequest(startIndex, count, sort));
|
||||
}
|
||||
return swModuleTypeBeans.getContent();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveBeans(final List<SoftwareModuleType> addedBeans, final List<SoftwareModuleType> modifiedBeans,
|
||||
final List<SoftwareModuleType> removedBeans) {
|
||||
// CRUD operations on Target will be done through repository methods
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,151 +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.common.confirmwindow.layout;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
|
||||
import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder;
|
||||
import org.eclipse.hawkbit.ui.utils.I18N;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.vaadin.spring.events.EventBus;
|
||||
|
||||
import com.vaadin.server.FontAwesome;
|
||||
import com.vaadin.ui.Accordion;
|
||||
import com.vaadin.ui.Alignment;
|
||||
import com.vaadin.ui.Button;
|
||||
import com.vaadin.ui.Button.ClickListener;
|
||||
import com.vaadin.ui.Label;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
import com.vaadin.ui.themes.ValoTheme;
|
||||
|
||||
/**
|
||||
* Abstract layout of confirm actions window.
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractConfirmationWindowLayout extends VerticalLayout {
|
||||
|
||||
private static final long serialVersionUID = -4042317361561298155L;
|
||||
|
||||
private Label actionMessage;
|
||||
|
||||
private Accordion accordion;
|
||||
|
||||
private String consolidatedMessage;
|
||||
|
||||
@Autowired
|
||||
protected I18N i18n;
|
||||
|
||||
@Autowired
|
||||
protected transient EventBus.SessionEventBus eventBus;
|
||||
|
||||
@PostConstruct
|
||||
public void initialize() {
|
||||
removeAllComponents();
|
||||
consolidatedMessage = "";
|
||||
createComponents();
|
||||
buildLayout();
|
||||
}
|
||||
|
||||
private void createComponents() {
|
||||
createAccordian();
|
||||
createActionMessgaeLabel();
|
||||
}
|
||||
|
||||
private void createActionMessgaeLabel() {
|
||||
actionMessage = SPUIComponentProvider.getLabel("", null);
|
||||
actionMessage.addStyleName(SPUIStyleDefinitions.CONFIRM_WINDOW_INFO_BOX);
|
||||
actionMessage.setId(SPUIComponetIdProvider.ACTION_LABEL);
|
||||
actionMessage.setVisible(false);
|
||||
}
|
||||
|
||||
private void createAccordian() {
|
||||
accordion = new Accordion();
|
||||
accordion.setSizeFull();
|
||||
}
|
||||
|
||||
private void buildLayout() {
|
||||
final Map<String, ConfirmationTab> confimrationTabs = getConfimrationTabs();
|
||||
for (final Entry<String, ConfirmationTab> captionConfirmationTab : confimrationTabs.entrySet()) {
|
||||
accordion.addTab(captionConfirmationTab.getValue(), captionConfirmationTab.getKey(), null);
|
||||
}
|
||||
final VerticalLayout confirmActionsLayout = new VerticalLayout();
|
||||
confirmActionsLayout.addStyleName(SPUIStyleDefinitions.CONFIRM_WINDOW_ACCORDIAN);
|
||||
confirmActionsLayout.setSpacing(false);
|
||||
confirmActionsLayout.setMargin(false);
|
||||
confirmActionsLayout.addComponent(actionMessage);
|
||||
confirmActionsLayout.addComponent(accordion);
|
||||
|
||||
addComponent(confirmActionsLayout);
|
||||
setComponentAlignment(confirmActionsLayout, Alignment.MIDDLE_CENTER);
|
||||
setSpacing(false);
|
||||
setMargin(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add to the consolidated result message which will be displayed in the
|
||||
* notification on closing the window. Each message that will be added in
|
||||
* new line of previous messages using html <br>
|
||||
*
|
||||
* @param message
|
||||
* to be added to the consolidated messages.
|
||||
*/
|
||||
public void addToConsolitatedMsg(final String message) {
|
||||
if (consolidatedMessage != null && consolidatedMessage.length() > 0) {
|
||||
consolidatedMessage = consolidatedMessage + "<br>";
|
||||
}
|
||||
consolidatedMessage = consolidatedMessage + message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tab
|
||||
*/
|
||||
protected void removeCurrentTab(final ConfirmationTab tab) {
|
||||
accordion.removeComponent(tab);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param message
|
||||
*/
|
||||
protected void setActionMessage(final String message) {
|
||||
actionMessage.setValue(message);
|
||||
actionMessage.setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get contents for each tab to be displayed in the accordian.
|
||||
*
|
||||
* @return map of caption and content for each tab.
|
||||
*/
|
||||
protected abstract Map<String, ConfirmationTab> getConfimrationTabs();
|
||||
|
||||
/**
|
||||
* @return the consolidatedMessage
|
||||
*/
|
||||
public String getConsolidatedMessage() {
|
||||
return consolidatedMessage;
|
||||
}
|
||||
|
||||
protected Button createDiscardButton(final Object itemId, final ClickListener clickListener) {
|
||||
final Button deletesDsIcon = SPUIComponentProvider.getButton("", "", SPUILabelDefinitions.DISCARD,
|
||||
ValoTheme.BUTTON_TINY + " " + SPUIStyleDefinitions.REDICON, true, FontAwesome.REPLY,
|
||||
SPUIButtonStyleSmallNoBorder.class);
|
||||
deletesDsIcon.setData(itemId);
|
||||
deletesDsIcon.setImmediate(true);
|
||||
deletesDsIcon.addClickListener(clickListener);
|
||||
return deletesDsIcon;
|
||||
}
|
||||
}
|
||||
@@ -1,154 +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.common.confirmwindow.layout;
|
||||
|
||||
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
|
||||
import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleTiny;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
|
||||
|
||||
import com.vaadin.server.FontAwesome;
|
||||
import com.vaadin.ui.Alignment;
|
||||
import com.vaadin.ui.Button;
|
||||
import com.vaadin.ui.HorizontalLayout;
|
||||
import com.vaadin.ui.Table;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
import com.vaadin.ui.themes.ValoTheme;
|
||||
|
||||
/**
|
||||
* Confirmation tab of confirmation window.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ConfirmationTab extends VerticalLayout {
|
||||
|
||||
private static final long serialVersionUID = -5211351556595775554L;
|
||||
|
||||
private Table table;
|
||||
|
||||
private Button confirmAll;
|
||||
|
||||
private Button discardAll;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public ConfirmationTab() {
|
||||
createComponents();
|
||||
buildLayout();
|
||||
}
|
||||
|
||||
private void createComponents() {
|
||||
// Create table
|
||||
createTable();
|
||||
|
||||
// Create confirm all button
|
||||
createConfirmAllButton();
|
||||
|
||||
// Create discard all button
|
||||
createDiscardAllButton();
|
||||
|
||||
}
|
||||
|
||||
private void buildLayout() {
|
||||
final HorizontalLayout btnLayout = new HorizontalLayout();
|
||||
btnLayout.setSpacing(true);
|
||||
|
||||
btnLayout.addStyleName(SPUIStyleDefinitions.SP_ACCORDION_TAB_BTN);
|
||||
btnLayout.addComponent(confirmAll);
|
||||
btnLayout.setComponentAlignment(confirmAll, Alignment.MIDDLE_CENTER);
|
||||
btnLayout.addComponent(discardAll);
|
||||
btnLayout.setComponentAlignment(discardAll, Alignment.MIDDLE_CENTER);
|
||||
|
||||
setSizeFull();
|
||||
setMargin(false);
|
||||
setSpacing(false);
|
||||
|
||||
addComponent(table);
|
||||
setComponentAlignment(table, Alignment.MIDDLE_CENTER);
|
||||
addComponent(btnLayout);
|
||||
setComponentAlignment(btnLayout, Alignment.MIDDLE_CENTER);
|
||||
}
|
||||
|
||||
private void createDiscardAllButton() {
|
||||
discardAll = SPUIComponentProvider.getButton(null, SPUILabelDefinitions.DISCARD_ALL, "", null, false, null,
|
||||
SPUIButtonStyleTiny.class);
|
||||
discardAll.setIcon(FontAwesome.REPLY);
|
||||
}
|
||||
|
||||
private void createConfirmAllButton() {
|
||||
confirmAll = SPUIComponentProvider.getButton(null, "", "", ValoTheme.BUTTON_PRIMARY, false, null,
|
||||
SPUIButtonStyleTiny.class);
|
||||
confirmAll.setIcon(FontAwesome.REPLY);
|
||||
}
|
||||
|
||||
private void createTable() {
|
||||
table = new Table();
|
||||
table.setSizeFull();
|
||||
table.setPageLength(SPUIDefinitions.ACCORDION_TAB_DETAILS_PAGE_LENGTH);
|
||||
// Build Style
|
||||
final StringBuilder style = new StringBuilder(ValoTheme.TABLE_COMPACT);
|
||||
style.append(' ');
|
||||
style.append(ValoTheme.TABLE_SMALL);
|
||||
style.append(' ');
|
||||
style.append(ValoTheme.TABLE_NO_VERTICAL_LINES);
|
||||
// Set style
|
||||
table.addStyleName(style.toString());
|
||||
table.addStyleName("accordion-tab-table-style");
|
||||
table.setImmediate(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the table
|
||||
*/
|
||||
public Table getTable() {
|
||||
return table;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param table
|
||||
* the table to set
|
||||
*/
|
||||
public void setTable(final Table table) {
|
||||
this.table = table;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the confirmAll
|
||||
*/
|
||||
public Button getConfirmAll() {
|
||||
return confirmAll;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param confirmAll
|
||||
* the confirmAll to set
|
||||
*/
|
||||
public void setConfirmAll(final Button confirmAll) {
|
||||
this.confirmAll = confirmAll;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the discardAll
|
||||
*/
|
||||
public Button getDiscardAll() {
|
||||
return discardAll;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param discardAll
|
||||
* the discardAll to set
|
||||
*/
|
||||
public void setDiscardAll(final Button discardAll) {
|
||||
this.discardAll = discardAll;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +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.common.confirmwindow.layout;
|
||||
|
||||
/**
|
||||
* Confirm window action events.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public enum ConfirmationWindowEvents {
|
||||
DISCARD_DELETE_SOFTWARE_TYPE, DISCARD_ALL_DELETE_SOFTWARE_TYPE, DELETE_ALL_SOFWARE_TYPE, DISCARD_DELETE_DIST_TYPE, DISCARD_ALL_DELETE_DIST_TYPE, DELETE_ALL_DIST_TYPE, DISCARD_DELETE_SOFTWARE_MODULE, DISCARD_ALL_DELETE_SOFTWARE_MODULE, DELETE_ALL_SOFTWARE_MODULE, DISCARD_DELETE_DISTRIBUTION, DISCARD_ALL_DELETE_DISTRIBUTION, DELETE_ALL_DISTRIBUTION, DISCARD_DELETE_TARGET, DISCARD_ALL_DELETE_TARGET, DELETE_ALL_TARGET, SAVED_ASSIGNMENTS, DISCARD_ALL_ASSIGNMENTS, DISCARD_ASSIGNMENTS
|
||||
}
|
||||
@@ -1,28 +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.common.detailslayout;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.NamedVersionedEntity;
|
||||
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractNamedVersionedEntityTableDetailsLayout<T extends NamedVersionedEntity>
|
||||
extends AbstractTableDetailsLayout<T> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
protected String getName() {
|
||||
return HawkbitCommonUtil.getFormattedNameVersion(getSelectedBaseEntity().getName(),
|
||||
getSelectedBaseEntity().getVersion());
|
||||
}
|
||||
}
|
||||
@@ -1,354 +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.common.detailslayout;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.hawkbit.repository.SpPermissionChecker;
|
||||
import org.eclipse.hawkbit.repository.model.NamedEntity;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.ui.common.table.BaseEntityEvent;
|
||||
import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType;
|
||||
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
|
||||
import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder;
|
||||
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.I18N;
|
||||
import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.vaadin.spring.events.EventBus;
|
||||
|
||||
import com.vaadin.server.FontAwesome;
|
||||
import com.vaadin.shared.ui.label.ContentMode;
|
||||
import com.vaadin.ui.Alignment;
|
||||
import com.vaadin.ui.Button;
|
||||
import com.vaadin.ui.HorizontalLayout;
|
||||
import com.vaadin.ui.Label;
|
||||
import com.vaadin.ui.TabSheet;
|
||||
import com.vaadin.ui.UI;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
|
||||
/**
|
||||
* Abstract Layout to show the entity details.
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractTableDetailsLayout<T extends NamedEntity> extends VerticalLayout {
|
||||
|
||||
private static final long serialVersionUID = 4862529368471627190L;
|
||||
|
||||
@Autowired
|
||||
private I18N i18n;
|
||||
|
||||
@Autowired
|
||||
private transient EventBus.SessionEventBus eventBus;
|
||||
|
||||
@Autowired
|
||||
private SpPermissionChecker permissionChecker;
|
||||
|
||||
private T selectedBaseEntity;
|
||||
|
||||
private Label caption;
|
||||
|
||||
private Button editButton;
|
||||
|
||||
private TabSheet detailsTab;
|
||||
|
||||
private VerticalLayout detailsLayout;
|
||||
|
||||
private VerticalLayout descriptionLayout;
|
||||
|
||||
private VerticalLayout logLayout;
|
||||
|
||||
private VerticalLayout attributesLayout;
|
||||
|
||||
/**
|
||||
* Initialize components.
|
||||
*/
|
||||
@PostConstruct
|
||||
protected void init() {
|
||||
createComponents();
|
||||
buildLayout();
|
||||
restoreState();
|
||||
eventBus.subscribe(this);
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
void destroy() {
|
||||
eventBus.unsubscribe(this);
|
||||
}
|
||||
|
||||
protected SpPermissionChecker getPermissionChecker() {
|
||||
return permissionChecker;
|
||||
}
|
||||
|
||||
protected EventBus.SessionEventBus getEventBus() {
|
||||
return eventBus;
|
||||
}
|
||||
|
||||
protected I18N getI18n() {
|
||||
return i18n;
|
||||
}
|
||||
|
||||
protected T getSelectedBaseEntity() {
|
||||
return selectedBaseEntity;
|
||||
}
|
||||
|
||||
public void setSelectedBaseEntity(final T selectedBaseEntity) {
|
||||
this.selectedBaseEntity = selectedBaseEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default implementation to handle an entity event.
|
||||
*
|
||||
* @param baseEntityEvent
|
||||
* the event
|
||||
*/
|
||||
protected void onBaseEntityEvent(final BaseEntityEvent<T> baseEntityEvent) {
|
||||
final BaseEntityEventType eventType = baseEntityEvent.getEventType();
|
||||
if (BaseEntityEventType.SELECTED_ENTITY == eventType || BaseEntityEventType.UPDATED_ENTITY == eventType) {
|
||||
UI.getCurrent().access(() -> populateData(baseEntityEvent.getEntity()));
|
||||
} else if (BaseEntityEventType.MINIMIZED == eventType) {
|
||||
UI.getCurrent().access(() -> setVisible(true));
|
||||
} else if (BaseEntityEventType.MAXIMIZED == eventType) {
|
||||
UI.getCurrent().access(() -> setVisible(false));
|
||||
}
|
||||
}
|
||||
|
||||
private void createComponents() {
|
||||
caption = createHeaderCaption();
|
||||
caption.setImmediate(true);
|
||||
caption.setContentMode(ContentMode.HTML);
|
||||
caption.setId(getDetailsHeaderCaptionId());
|
||||
|
||||
editButton = SPUIComponentProvider.getButton("", "", "", null, false, FontAwesome.PENCIL_SQUARE_O,
|
||||
SPUIButtonStyleSmallNoBorder.class);
|
||||
editButton.setId(getEditButtonId());
|
||||
editButton.addClickListener(this::onEdit);
|
||||
|
||||
editButton.setEnabled(false);
|
||||
|
||||
detailsTab = SPUIComponentProvider.getDetailsTabSheet();
|
||||
detailsTab.setImmediate(true);
|
||||
detailsTab.setWidth(98, Unit.PERCENTAGE);
|
||||
detailsTab.setHeight(90, Unit.PERCENTAGE);
|
||||
detailsTab.addStyleName(SPUIStyleDefinitions.DETAILS_LAYOUT_STYLE);
|
||||
detailsTab.setId(getTabSheetId());
|
||||
addTabs(detailsTab);
|
||||
}
|
||||
|
||||
private void buildLayout() {
|
||||
final HorizontalLayout nameEditLayout = new HorizontalLayout();
|
||||
nameEditLayout.setWidth(100.0f, Unit.PERCENTAGE);
|
||||
nameEditLayout.addComponent(caption);
|
||||
nameEditLayout.setComponentAlignment(caption, Alignment.MIDDLE_LEFT);
|
||||
if (hasEditPermission()) {
|
||||
nameEditLayout.addComponent(editButton);
|
||||
nameEditLayout.setComponentAlignment(editButton, Alignment.MIDDLE_RIGHT);
|
||||
}
|
||||
nameEditLayout.setExpandRatio(caption, 1.0f);
|
||||
nameEditLayout.addStyleName(SPUIStyleDefinitions.WIDGET_TITLE);
|
||||
|
||||
addComponent(nameEditLayout);
|
||||
setComponentAlignment(nameEditLayout, Alignment.MIDDLE_CENTER);
|
||||
addComponent(detailsTab);
|
||||
setComponentAlignment(nameEditLayout, Alignment.MIDDLE_CENTER);
|
||||
|
||||
setSizeFull();
|
||||
setHeightUndefined();
|
||||
addStyleName(SPUIStyleDefinitions.WIDGET_STYLE);
|
||||
}
|
||||
|
||||
private Label createHeaderCaption() {
|
||||
final Label captionLabel = SPUIComponentProvider.getLabel(getDefaultCaption(),
|
||||
SPUILabelDefinitions.SP_WIDGET_CAPTION);
|
||||
return captionLabel;
|
||||
}
|
||||
|
||||
protected VerticalLayout getTabLayout() {
|
||||
final VerticalLayout tabLayout = SPUIComponentProvider.getDetailTabLayout();
|
||||
tabLayout.addStyleName("details-layout");
|
||||
return tabLayout;
|
||||
}
|
||||
|
||||
protected void setName(final String headerCaption, final String value) {
|
||||
caption.setValue(HawkbitCommonUtil.getSoftwareModuleName(headerCaption, value));
|
||||
}
|
||||
|
||||
private void restoreState() {
|
||||
if (onLoadIsTableRowSelected()) {
|
||||
populateData(null);
|
||||
editButton.setEnabled(true);
|
||||
}
|
||||
if (onLoadIsTableMaximized()) {
|
||||
setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If no data in table (i,e no row selected),then disable the edit button.
|
||||
* If row is selected ,enable edit button.
|
||||
*/
|
||||
private void populateData(final T selectedBaseEntity) {
|
||||
this.selectedBaseEntity = selectedBaseEntity;
|
||||
editButton.setEnabled(selectedBaseEntity != null);
|
||||
if (selectedBaseEntity == null) {
|
||||
setName(getDefaultCaption(), StringUtils.EMPTY);
|
||||
} else {
|
||||
setName(getDefaultCaption(), getName());
|
||||
}
|
||||
populateLog();
|
||||
populateDescription();
|
||||
populateDetailsWidget();
|
||||
}
|
||||
|
||||
protected void updateLogLayout(final VerticalLayout changeLogLayout, final Long lastModifiedAt,
|
||||
final String lastModifiedBy, final Long createdAt, final String createdBy, final I18N i18n) {
|
||||
changeLogLayout.removeAllComponents();
|
||||
changeLogLayout.addComponent(SPUIComponentProvider.createNameValueLabel(i18n.get("label.created.at"),
|
||||
createdAt == null ? "" : SPDateTimeUtil.getFormattedDate(createdAt)));
|
||||
|
||||
changeLogLayout.addComponent(SPUIComponentProvider.createNameValueLabel(i18n.get("label.created.by"),
|
||||
createdBy == null ? "" : HawkbitCommonUtil.getIMUser(createdBy)));
|
||||
|
||||
if (null != lastModifiedAt) {
|
||||
changeLogLayout.addComponent(SPUIComponentProvider.createNameValueLabel(i18n.get("label.modified.date"),
|
||||
SPDateTimeUtil.getFormattedDate(lastModifiedAt)));
|
||||
|
||||
changeLogLayout.addComponent(SPUIComponentProvider.createNameValueLabel(i18n.get("label.modified.by"),
|
||||
lastModifiedBy == null ? "" : HawkbitCommonUtil.getIMUser(lastModifiedBy)));
|
||||
}
|
||||
}
|
||||
|
||||
protected void updateDescriptionLayout(final String descriptionLabel, final String description) {
|
||||
descriptionLayout.removeAllComponents();
|
||||
final Label descLabel = SPUIComponentProvider.createNameValueLabel(descriptionLabel,
|
||||
HawkbitCommonUtil.trimAndNullIfEmpty(description) == null ? "" : description);
|
||||
/**
|
||||
* By default text will be truncated based on layout width .so removing
|
||||
* it as we need full description.
|
||||
*/
|
||||
descLabel.removeStyleName("label-style");
|
||||
descLabel.setId(SPUIComponetIdProvider.DETAILS_DESCRIPTION_LABEL_ID);
|
||||
descriptionLayout.addComponent(descLabel);
|
||||
}
|
||||
|
||||
/*
|
||||
* display Attributes details in Target details.
|
||||
*/
|
||||
|
||||
protected void updateAttributesLayout(final Target target) {
|
||||
if (null != target && null != target.getTargetInfo()
|
||||
&& null != target.getTargetInfo().getControllerAttributes()) {
|
||||
attributesLayout.removeAllComponents();
|
||||
for (final Map.Entry<String, String> entry : target.getTargetInfo().getControllerAttributes().entrySet()) {
|
||||
final Label conAttributeLabel = SPUIComponentProvider.createNameValueLabel(
|
||||
entry.getKey().concat(" : "),
|
||||
HawkbitCommonUtil.trimAndNullIfEmpty(entry.getValue()) == null ? "" : entry.getValue());
|
||||
conAttributeLabel.setDescription(entry.getKey().concat(" : ") + entry.getValue());
|
||||
conAttributeLabel.addStyleName("label-style");
|
||||
attributesLayout.addComponent(conAttributeLabel);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected VerticalLayout createLogLayout() {
|
||||
logLayout = getTabLayout();
|
||||
return logLayout;
|
||||
}
|
||||
|
||||
protected VerticalLayout createAttributesLayout() {
|
||||
attributesLayout = getTabLayout();
|
||||
return attributesLayout;
|
||||
}
|
||||
|
||||
protected VerticalLayout createDetailsLayout() {
|
||||
detailsLayout = getTabLayout();
|
||||
return detailsLayout;
|
||||
}
|
||||
|
||||
protected VerticalLayout createDescriptionLayout() {
|
||||
descriptionLayout = getTabLayout();
|
||||
return descriptionLayout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default caption of header to be displayed when no data row selected in
|
||||
* table.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
protected abstract String getDefaultCaption();
|
||||
|
||||
/**
|
||||
* Add tabs.
|
||||
*
|
||||
* @param detailsTab
|
||||
*/
|
||||
protected abstract void addTabs(final TabSheet detailsTab);
|
||||
|
||||
/**
|
||||
* Click listener for edit button.
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
protected abstract void onEdit(Button.ClickEvent event);
|
||||
|
||||
protected abstract String getEditButtonId();
|
||||
|
||||
protected abstract Boolean onLoadIsTableRowSelected();
|
||||
|
||||
protected abstract Boolean onLoadIsTableMaximized();
|
||||
|
||||
protected abstract String getTabSheetId();
|
||||
|
||||
protected abstract Boolean hasEditPermission();
|
||||
|
||||
public VerticalLayout getDetailsLayout() {
|
||||
return detailsLayout;
|
||||
}
|
||||
|
||||
public VerticalLayout getLogLayout() {
|
||||
return logLayout;
|
||||
}
|
||||
|
||||
private void populateLog() {
|
||||
if (selectedBaseEntity == null) {
|
||||
updateLogLayout(getLogLayout(), null, StringUtils.EMPTY, null, null, i18n);
|
||||
return;
|
||||
}
|
||||
updateLogLayout(getLogLayout(), selectedBaseEntity.getLastModifiedAt(), selectedBaseEntity.getLastModifiedBy(),
|
||||
selectedBaseEntity.getCreatedAt(), selectedBaseEntity.getCreatedBy(), i18n);
|
||||
}
|
||||
|
||||
private void populateDescription() {
|
||||
if (selectedBaseEntity != null) {
|
||||
updateDescriptionLayout(i18n.get("label.description"), selectedBaseEntity.getDescription());
|
||||
} else {
|
||||
updateDescriptionLayout(i18n.get("label.description"), null);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void populateDetailsWidget();
|
||||
|
||||
protected Long getSelectedBaseEntityId() {
|
||||
return selectedBaseEntity == null ? null : selectedBaseEntity.getId();
|
||||
}
|
||||
|
||||
protected abstract String getDetailsHeaderCaptionId();
|
||||
|
||||
protected abstract String getName();
|
||||
|
||||
}
|
||||
@@ -1,269 +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.common.detailslayout;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.SpPermissionChecker;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityLockedException;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType;
|
||||
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
|
||||
import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder;
|
||||
import org.eclipse.hawkbit.ui.distributions.event.DistributionsUIEvent;
|
||||
import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState;
|
||||
import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent;
|
||||
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.I18N;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SpringContextHelper;
|
||||
import org.eclipse.hawkbit.ui.utils.UINotification;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.vaadin.spring.events.EventBus.SessionEventBus;
|
||||
|
||||
import com.vaadin.data.Item;
|
||||
import com.vaadin.data.util.IndexedContainer;
|
||||
import com.vaadin.server.FontAwesome;
|
||||
import com.vaadin.ui.Button;
|
||||
import com.vaadin.ui.Button.ClickEvent;
|
||||
import com.vaadin.ui.Label;
|
||||
import com.vaadin.ui.Table;
|
||||
import com.vaadin.ui.themes.ValoTheme;
|
||||
|
||||
/**
|
||||
* Software module details table.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class SoftwareModuleDetailsTable extends Table {
|
||||
|
||||
private static final long serialVersionUID = 2913758200611837718L;
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(SoftwareModuleDetailsTable.class);
|
||||
|
||||
private static final String SOFT_TYPE_NAME = "name";
|
||||
|
||||
private static final String SOFT_MODULE = "softwareModule";
|
||||
|
||||
private static final String SOFT_TYPE_MANDATORY = "mandatory";
|
||||
|
||||
private static final String UNASSIGN_SOFT_MODULE = "unassignSoftModule";
|
||||
|
||||
private boolean isTargetAssigned;
|
||||
|
||||
private boolean isUnassignSoftModAllowed;
|
||||
private SpPermissionChecker permissionChecker;
|
||||
|
||||
private transient DistributionSetManagement distributionSetManagement;
|
||||
|
||||
private I18N i18n;
|
||||
|
||||
private transient SessionEventBus eventBus;
|
||||
|
||||
private transient ManageDistUIState manageDistUIState;
|
||||
|
||||
private transient UINotification uiNotification;
|
||||
|
||||
/**
|
||||
* Initialize software module table- to be displayed in details layout.
|
||||
*
|
||||
* @param i18n
|
||||
* I18N
|
||||
* @param isUnassignSoftModAllowed
|
||||
* boolean flag to check for unassign functionality allowed for
|
||||
* the view.
|
||||
* @param distributionSetManagement
|
||||
* DistributionSetManagement
|
||||
* @param permissionChecker
|
||||
* SpPermissionChecker
|
||||
* @param eventBus
|
||||
* SessionEventBus
|
||||
* @param manageDistUIState
|
||||
* ManageDistUIState
|
||||
*/
|
||||
public void init(final I18N i18n, final boolean isUnassignSoftModAllowed,
|
||||
final SpPermissionChecker permissionChecker, final DistributionSetManagement distributionSetManagement,
|
||||
final SessionEventBus eventBus, final ManageDistUIState manageDistUIState) {
|
||||
this.i18n = i18n;
|
||||
this.isUnassignSoftModAllowed = isUnassignSoftModAllowed;
|
||||
this.permissionChecker = permissionChecker;
|
||||
this.distributionSetManagement = distributionSetManagement;
|
||||
this.manageDistUIState = manageDistUIState;
|
||||
this.eventBus = eventBus;
|
||||
this.uiNotification = SpringContextHelper.getBean(UINotification.class);
|
||||
createSwModuleTable();
|
||||
}
|
||||
|
||||
private void createSwModuleTable() {
|
||||
addStyleName(ValoTheme.TABLE_NO_HORIZONTAL_LINES);
|
||||
addStyleName(ValoTheme.TABLE_NO_STRIPES);
|
||||
setSelectable(false);
|
||||
setImmediate(true);
|
||||
setContainerDataSource(getSwModuleContainer());
|
||||
setColumnHeaderMode(ColumnHeaderMode.EXPLICIT);
|
||||
addSWModuleTableHeader();
|
||||
setSizeFull(); // check if this style is required
|
||||
addStyleName(SPUIStyleDefinitions.SW_MODULE_TABLE);
|
||||
}
|
||||
|
||||
private IndexedContainer getSwModuleContainer() {
|
||||
final IndexedContainer container = new IndexedContainer();
|
||||
container.addContainerProperty(SOFT_TYPE_MANDATORY, Label.class, "");
|
||||
container.addContainerProperty(SOFT_TYPE_NAME, Label.class, "");
|
||||
container.addContainerProperty(SOFT_MODULE, Label.class, "");
|
||||
if (isUnassignSoftModAllowed && permissionChecker.hasUpdateDistributionPermission()) {
|
||||
container.addContainerProperty(UNASSIGN_SOFT_MODULE, Button.class, "");
|
||||
}
|
||||
setColumnExpandRatio(SOFT_TYPE_MANDATORY, 0.1f);
|
||||
setColumnExpandRatio(SOFT_TYPE_NAME, 0.4f);
|
||||
setColumnExpandRatio(SOFT_MODULE, 0.3f);
|
||||
if (isUnassignSoftModAllowed && permissionChecker.hasUpdateDistributionPermission()) {
|
||||
setColumnExpandRatio(UNASSIGN_SOFT_MODULE, 0.2F);
|
||||
}
|
||||
setColumnAlignment(SOFT_TYPE_MANDATORY, Align.RIGHT);
|
||||
setColumnAlignment(SOFT_TYPE_NAME, Align.LEFT);
|
||||
setColumnAlignment(SOFT_MODULE, Align.LEFT);
|
||||
if (isUnassignSoftModAllowed && permissionChecker.hasUpdateDistributionPermission()) {
|
||||
setColumnAlignment(UNASSIGN_SOFT_MODULE, Align.RIGHT);
|
||||
}
|
||||
return container;
|
||||
}
|
||||
|
||||
private void addSWModuleTableHeader() {
|
||||
setColumnHeader(SOFT_TYPE_MANDATORY, "");
|
||||
setColumnHeader(SOFT_TYPE_NAME, i18n.get("header.caption.typename"));
|
||||
setColumnHeader(SOFT_MODULE, i18n.get("header.caption.softwaremodule"));
|
||||
if (isUnassignSoftModAllowed && permissionChecker.hasUpdateDistributionPermission()) {
|
||||
setColumnHeader(UNASSIGN_SOFT_MODULE, i18n.get("header.caption.unassign"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate software module table.
|
||||
*
|
||||
* @param distributionSet
|
||||
*/
|
||||
public void populateModule(final DistributionSet distributionSet) {
|
||||
removeAllItems();
|
||||
if (null != distributionSet) {
|
||||
if (isUnassignSoftModAllowed && permissionChecker.hasUpdateDistributionPermission()) {
|
||||
try {
|
||||
isTargetAssigned = false;
|
||||
} catch (final EntityLockedException exception) {
|
||||
isTargetAssigned = true;
|
||||
LOG.info("Target already assigned for the distribution set: " + distributionSet.getName(),
|
||||
exception);
|
||||
}
|
||||
}
|
||||
final Set<SoftwareModuleType> swModuleMandatoryTypes = distributionSet.getType().getMandatoryModuleTypes();
|
||||
final Set<SoftwareModuleType> swModuleOptionalTypes = distributionSet.getType().getOptionalModuleTypes();
|
||||
|
||||
if (null != swModuleMandatoryTypes && !swModuleMandatoryTypes.isEmpty()) {
|
||||
swModuleMandatoryTypes.forEach(swModule -> setSwModuleProperties(swModule, true, distributionSet));
|
||||
}
|
||||
if (null != swModuleOptionalTypes && !swModuleOptionalTypes.isEmpty()) {
|
||||
swModuleOptionalTypes.forEach(swModule -> setSwModuleProperties(swModule, false, distributionSet));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void setSwModuleProperties(final SoftwareModuleType swModType, final Boolean isMandatory,
|
||||
final DistributionSet distributionSet) {
|
||||
final Set<SoftwareModule> alreadyAssignedSwModules = distributionSet.getModules();
|
||||
final Item saveTblitem = getContainerDataSource().addItem(swModType.getName());
|
||||
final Label mandatoryLabel = createMandatoryLabel(isMandatory);
|
||||
final Label typeName = HawkbitCommonUtil.getFormatedLabel(swModType.getName());
|
||||
|
||||
final Label softwareModule = HawkbitCommonUtil.getFormatedLabel(HawkbitCommonUtil.SP_STRING_EMPTY);
|
||||
final Button reassignSoftModule = SPUIComponentProvider.getButton(swModType.getName(), "", "", "", true,
|
||||
FontAwesome.TIMES, SPUIButtonStyleSmallNoBorder.class);
|
||||
|
||||
reassignSoftModule.addClickListener(event -> unassignSW(event, distributionSet, alreadyAssignedSwModules));
|
||||
if (null != alreadyAssignedSwModules && !alreadyAssignedSwModules.isEmpty()) {
|
||||
final String swModuleName = getSwModuleName(alreadyAssignedSwModules, swModType);
|
||||
softwareModule.setValue(swModuleName);
|
||||
softwareModule.setDescription(swModuleName);
|
||||
}
|
||||
saveTblitem.getItemProperty(SOFT_TYPE_MANDATORY).setValue(mandatoryLabel);
|
||||
saveTblitem.getItemProperty(SOFT_TYPE_NAME).setValue(typeName);
|
||||
saveTblitem.getItemProperty(SOFT_MODULE).setValue(softwareModule);
|
||||
if (isUnassignSoftModAllowed && permissionChecker.hasUpdateDistributionPermission() && !isTargetAssigned
|
||||
&& (isSoftModAvaiableForSoftType(alreadyAssignedSwModules, swModType))) {
|
||||
saveTblitem.getItemProperty(UNASSIGN_SOFT_MODULE).setValue(reassignSoftModule);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void unassignSW(final ClickEvent event, final DistributionSet distributionSet,
|
||||
final Set<SoftwareModule> alreadyAssignedSwModules) {
|
||||
final SoftwareModule unAssignedSw = getSoftwareModule((Label) getContainerDataSource()
|
||||
.getItem(event.getButton().getId()).getItemProperty(SOFT_MODULE).getValue(), alreadyAssignedSwModules);
|
||||
final DistributionSet newDistributionSet = distributionSetManagement.unassignSoftwareModule(distributionSet,
|
||||
unAssignedSw);
|
||||
manageDistUIState.setLastSelectedEntity(newDistributionSet.getDistributionSetIdName());
|
||||
eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.SELECTED_ENTITY, newDistributionSet));
|
||||
eventBus.publish(this, DistributionsUIEvent.ORDER_BY_DISTRIBUTION);
|
||||
uiNotification.displaySuccess(i18n.get("message.sw.unassigned", unAssignedSw.getName()));
|
||||
}
|
||||
|
||||
private static boolean isSoftModAvaiableForSoftType(final Set<SoftwareModule> swModulesSet,
|
||||
final SoftwareModuleType swModType) {
|
||||
for (final SoftwareModule sw : swModulesSet) {
|
||||
if (swModType.getName().equals(sw.getType().getName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value
|
||||
* @param alreadyAssignedSwModules
|
||||
* @return
|
||||
*/
|
||||
protected SoftwareModule getSoftwareModule(final Label softwareModule,
|
||||
final Set<SoftwareModule> alreadyAssignedSwModules) {
|
||||
for (final SoftwareModule sw : alreadyAssignedSwModules) {
|
||||
if (softwareModule.getValue().contains(sw.getName())) {
|
||||
return sw;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Label createMandatoryLabel(final boolean mandatory) {
|
||||
final Label mandatoryLable = mandatory ? HawkbitCommonUtil.getFormatedLabel(" * ")
|
||||
: HawkbitCommonUtil.getFormatedLabel(" ");
|
||||
if (mandatory) {
|
||||
mandatoryLable.setStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_ERROR);
|
||||
}
|
||||
return mandatoryLable;
|
||||
}
|
||||
|
||||
private String getSwModuleName(final Set<SoftwareModule> swModulesSet, final SoftwareModuleType swModType) {
|
||||
final StringBuilder assignedSWModules = new StringBuilder();
|
||||
for (final SoftwareModule sw : swModulesSet) {
|
||||
if (swModType.getKey().equals(sw.getType().getKey())) {
|
||||
assignedSWModules.append(HawkbitCommonUtil.getFormattedNameVersion(sw.getName(), sw.getVersion()))
|
||||
.append("</br>");
|
||||
}
|
||||
}
|
||||
return assignedSWModules.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,46 +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.common.filterlayout;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.vaadin.ui.Button;
|
||||
|
||||
/**
|
||||
* Abstract button click behaviour of filter buttons layout.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractFilterButtonClickBehaviour implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 5486557136906648322L;
|
||||
|
||||
/**
|
||||
* @param event
|
||||
*/
|
||||
protected abstract void processFilterButtonClick(Button.ClickEvent event);
|
||||
|
||||
/**
|
||||
* @param clickedButton
|
||||
*/
|
||||
protected abstract void filterUnClicked(final Button clickedButton);
|
||||
|
||||
/**
|
||||
* @param clickedButton
|
||||
*/
|
||||
protected abstract void filterClicked(final Button clickedButton);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param button
|
||||
*/
|
||||
protected abstract void setDefaultClickedButton(final Button button);
|
||||
}
|
||||
@@ -1,251 +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.common.filterlayout;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
|
||||
import org.eclipse.hawkbit.ui.decorators.SPUITagButtonStyle;
|
||||
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer;
|
||||
import org.vaadin.spring.events.EventBus;
|
||||
|
||||
import com.vaadin.data.Item;
|
||||
import com.vaadin.event.dd.DropHandler;
|
||||
import com.vaadin.server.FontAwesome;
|
||||
import com.vaadin.ui.Button;
|
||||
import com.vaadin.ui.DragAndDropWrapper;
|
||||
import com.vaadin.ui.DragAndDropWrapper.DragStartMode;
|
||||
import com.vaadin.ui.Table;
|
||||
import com.vaadin.ui.themes.ValoTheme;
|
||||
|
||||
/**
|
||||
* Parent class for filter button layout.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractFilterButtons extends Table {
|
||||
|
||||
private static final long serialVersionUID = 7783305719009746375L;
|
||||
|
||||
private static final String DEFAULT_GREEN = "rgb(44,151,32)";
|
||||
|
||||
protected static final String FILTER_BUTTON_COLUMN = "filterButton";
|
||||
|
||||
@Autowired
|
||||
protected transient EventBus.SessionEventBus eventBus;
|
||||
|
||||
private AbstractFilterButtonClickBehaviour filterButtonClickBehaviour;
|
||||
|
||||
/**
|
||||
* Initialize layout of filter buttons.
|
||||
*
|
||||
* @param filterButtonClickBehaviour
|
||||
* click behaviour of filter buttons.
|
||||
*/
|
||||
public void init(final AbstractFilterButtonClickBehaviour filterButtonClickBehaviour) {
|
||||
this.filterButtonClickBehaviour = filterButtonClickBehaviour;
|
||||
createTable();
|
||||
eventBus.subscribe(this);
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
void destroy() {
|
||||
eventBus.unsubscribe(this);
|
||||
}
|
||||
|
||||
private void createTable() {
|
||||
setImmediate(true);
|
||||
setId(getButtonsTableId());
|
||||
setStyleName("type-button-layout");
|
||||
setStyle();
|
||||
setContainerDataSource(createButtonsLazyQueryContainer());
|
||||
addTableProperties();
|
||||
addColumn();
|
||||
setTableVisibleColumns();
|
||||
setDragMode(TableDragMode.NONE);
|
||||
setSelectable(false);
|
||||
setSizeFull();
|
||||
}
|
||||
|
||||
private void setStyle() {
|
||||
addStyleName(ValoTheme.TABLE_NO_STRIPES);
|
||||
addStyleName(ValoTheme.TABLE_NO_HORIZONTAL_LINES);
|
||||
addStyleName(ValoTheme.TABLE_NO_VERTICAL_LINES);
|
||||
addStyleName(ValoTheme.TABLE_BORDERLESS);
|
||||
addStyleName(ValoTheme.TABLE_COMPACT);
|
||||
}
|
||||
|
||||
private void addTableProperties() {
|
||||
final LazyQueryContainer container = (LazyQueryContainer) getContainerDataSource();
|
||||
container.addContainerProperty(SPUILabelDefinitions.VAR_ID, Long.class, null, true, true);
|
||||
container.addContainerProperty(SPUILabelDefinitions.VAR_COLOR, String.class, "", true, true);
|
||||
container.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, "", true, true);
|
||||
container.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, null, true, true);
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
protected void addColumn() {
|
||||
addGeneratedColumn(FILTER_BUTTON_COLUMN, (source, itemId, columnId) -> addGeneratedCell(itemId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param itemId
|
||||
* @return
|
||||
*/
|
||||
private DragAndDropWrapper addGeneratedCell(final Object itemId) {
|
||||
final Item item = getItem(itemId);
|
||||
final Long id = (Long) item.getItemProperty(SPUILabelDefinitions.VAR_ID).getValue();
|
||||
final String name = (String) item.getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue();
|
||||
final String desc = HawkbitCommonUtil
|
||||
.trimAndNullIfEmpty((String) item.getItemProperty(SPUILabelDefinitions.VAR_DESC).getValue()) != null
|
||||
? item.getItemProperty(SPUILabelDefinitions.VAR_DESC).getValue().toString() : null;
|
||||
final String color = HawkbitCommonUtil
|
||||
.trimAndNullIfEmpty((String) item.getItemProperty(SPUILabelDefinitions.VAR_COLOR).getValue()) != null
|
||||
? item.getItemProperty(SPUILabelDefinitions.VAR_COLOR).getValue().toString() : DEFAULT_GREEN;
|
||||
final Button typeButton = createFilterButton(id, name, desc, color, itemId);
|
||||
typeButton.addClickListener(event -> filterButtonClickBehaviour.processFilterButtonClick(event));
|
||||
if (typeButton.getData().equals(SPUIDefinitions.NO_TAG_BUTTON_ID) && isNoTagSateSelected()) {
|
||||
filterButtonClickBehaviour.setDefaultClickedButton(typeButton);
|
||||
} else if (id != null && isClickedByDefault(name)) {
|
||||
filterButtonClickBehaviour.setDefaultClickedButton(typeButton);
|
||||
}
|
||||
final DragAndDropWrapper wrapper = createDragAndDropWrapper(typeButton, name, id);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
protected boolean isNoTagSateSelected() {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
private DragAndDropWrapper createDragAndDropWrapper(final Button tagButton, final String name, final Long id) {
|
||||
final DragAndDropWrapper bsmBtnWrapper = new DragAndDropWrapper(tagButton);
|
||||
bsmBtnWrapper.addStyleName(ValoTheme.DRAG_AND_DROP_WRAPPER_NO_VERTICAL_DRAG_HINTS);
|
||||
bsmBtnWrapper.addStyleName(ValoTheme.DRAG_AND_DROP_WRAPPER_NO_HORIZONTAL_DRAG_HINTS);
|
||||
bsmBtnWrapper.addStyleName(SPUIStyleDefinitions.FILTER_BUTTON_WRAPPER);
|
||||
if (getButtonWrapperData() != null) {
|
||||
if (id != null) {
|
||||
bsmBtnWrapper.setData(getButtonWrapperData().concat(id.toString()));
|
||||
} else {
|
||||
bsmBtnWrapper.setData(getButtonWrapperData());
|
||||
}
|
||||
}
|
||||
bsmBtnWrapper.setId(getButttonWrapperIdPrefix().concat(name));
|
||||
bsmBtnWrapper.setDragStartMode(DragStartMode.WRAPPER);
|
||||
bsmBtnWrapper.setDropHandler(getFilterButtonDropHandler());
|
||||
return bsmBtnWrapper;
|
||||
}
|
||||
|
||||
private void setTableVisibleColumns() {
|
||||
final List<Object> columnIds = new ArrayList<>();
|
||||
columnIds.add(FILTER_BUTTON_COLUMN);
|
||||
setVisibleColumns(columnIds.toArray());
|
||||
setColumnHeaderMode(ColumnHeaderMode.HIDDEN);
|
||||
}
|
||||
|
||||
private Button createFilterButton(final Long id, final String name, final String description, final String color,
|
||||
final Object itemId) {
|
||||
/**
|
||||
* No icon displayed for "NO TAG" button.
|
||||
*/
|
||||
final Button button = SPUIComponentProvider.getButton("", name, description, "", false, null,
|
||||
SPUITagButtonStyle.class);
|
||||
button.setId(createButtonId(name));
|
||||
button.setCaptionAsHtml(true);
|
||||
if (id != null) {
|
||||
// Use button.getCaption() since the caption name is modified
|
||||
// according to the length
|
||||
// available in UI.
|
||||
button.setCaption(prepareFilterButtonCaption(button.getCaption(), color));
|
||||
}
|
||||
|
||||
if (HawkbitCommonUtil.trimAndNullIfEmpty(description) != null) {
|
||||
button.setDescription(description);
|
||||
} else {
|
||||
button.setDescription(name);
|
||||
}
|
||||
button.setData(id == null ? SPUIDefinitions.NO_TAG_BUTTON_ID : itemId);
|
||||
return button;
|
||||
}
|
||||
|
||||
private String prepareFilterButtonCaption(final String name, final String color) {
|
||||
final StringBuilder caption = new StringBuilder();
|
||||
caption.append("<span style=\"color: ").append(color).append(" !important;\">");
|
||||
caption.append(FontAwesome.CIRCLE.getHtml());
|
||||
caption.append("</span> ");
|
||||
caption.append(name);
|
||||
return caption.toString();
|
||||
}
|
||||
|
||||
protected void refreshTable() {
|
||||
setContainerDataSource(createButtonsLazyQueryContainer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Id of the buttons table to be used in test cases.
|
||||
*
|
||||
* @return Id of the Button table.
|
||||
*/
|
||||
protected abstract String getButtonsTableId();
|
||||
|
||||
/**
|
||||
* create new lazyquery container to display the buttons.
|
||||
*
|
||||
* @return reference of {@link LazyQueryContainer}
|
||||
*/
|
||||
protected abstract LazyQueryContainer createButtonsLazyQueryContainer();
|
||||
|
||||
/**
|
||||
* Check if button should be displayed as clicked by default.
|
||||
*
|
||||
* @param buttonCaption
|
||||
* button caption
|
||||
* @return true if button is clicked
|
||||
*/
|
||||
protected abstract boolean isClickedByDefault(final String buttonCaption);
|
||||
|
||||
/**
|
||||
* Get filter button Id.
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
protected abstract String createButtonId(String name);
|
||||
|
||||
/**
|
||||
* Get Drop Handler for Filter Buttons.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract DropHandler getFilterButtonDropHandler();
|
||||
|
||||
/**
|
||||
* Get prefix Id of Button Wrapper to be used for drag and drop, delete and
|
||||
* test cases.
|
||||
*
|
||||
* @return prefix Id of Button Wrapper
|
||||
*/
|
||||
protected abstract String getButttonWrapperIdPrefix();
|
||||
|
||||
/**
|
||||
* Get info to be set for the button wrapper.
|
||||
*
|
||||
* @return button wrapper info.
|
||||
*/
|
||||
protected abstract String getButtonWrapperData();
|
||||
}
|
||||
@@ -1,149 +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.common.filterlayout;
|
||||
|
||||
import org.eclipse.hawkbit.repository.SpPermissionChecker;
|
||||
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
|
||||
import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.vaadin.spring.events.EventBus;
|
||||
|
||||
import com.vaadin.server.FontAwesome;
|
||||
import com.vaadin.ui.Alignment;
|
||||
import com.vaadin.ui.Button;
|
||||
import com.vaadin.ui.HorizontalLayout;
|
||||
import com.vaadin.ui.Label;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
|
||||
/**
|
||||
* Parent class for filter button header layout.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractFilterHeader extends VerticalLayout {
|
||||
|
||||
private static final long serialVersionUID = -1388340600522323332L;
|
||||
|
||||
|
||||
@Autowired
|
||||
protected SpPermissionChecker permChecker;
|
||||
|
||||
@Autowired
|
||||
protected transient EventBus.SessionEventBus eventBus;
|
||||
|
||||
private Label title;
|
||||
|
||||
private Button config;
|
||||
|
||||
private Button hideIcon;
|
||||
|
||||
/**
|
||||
* Initialize the header layout.
|
||||
*/
|
||||
protected void init() {
|
||||
createComponents();
|
||||
buildLayout();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create required components.
|
||||
*/
|
||||
private void createComponents() {
|
||||
title = createHeaderCaption();
|
||||
|
||||
if (hasCreateUpdatePermission() && isAddTagRequired()) {
|
||||
config = SPUIComponentProvider.getButton(getConfigureFilterButtonId(), "", "", "", true, FontAwesome.COG,
|
||||
SPUIButtonStyleSmallNoBorder.class);
|
||||
config.addClickListener(event -> settingsIconClicked(event));
|
||||
}
|
||||
hideIcon = SPUIComponentProvider.getButton(getHideButtonId(), "", "", "", true, FontAwesome.TIMES,
|
||||
SPUIButtonStyleSmallNoBorder.class);
|
||||
hideIcon.addClickListener(event -> hideFilterButtonLayout());
|
||||
}
|
||||
|
||||
/**
|
||||
* Build layout.
|
||||
*/
|
||||
private void buildLayout() {
|
||||
setStyleName("filter-btns-header-layout");
|
||||
final HorizontalLayout typeHeaderLayout = new HorizontalLayout();
|
||||
typeHeaderLayout.setWidth(100.0f, Unit.PERCENTAGE);
|
||||
typeHeaderLayout.addComponentAsFirst(title);
|
||||
typeHeaderLayout.addStyleName(SPUIStyleDefinitions.WIDGET_TITLE);
|
||||
typeHeaderLayout.setComponentAlignment(title, Alignment.TOP_LEFT);
|
||||
if (config != null && hasCreateUpdatePermission()) {
|
||||
typeHeaderLayout.addComponent(config);
|
||||
typeHeaderLayout.setComponentAlignment(config, Alignment.TOP_RIGHT);
|
||||
}
|
||||
typeHeaderLayout.addComponent(hideIcon);
|
||||
typeHeaderLayout.setComponentAlignment(hideIcon, Alignment.TOP_RIGHT);
|
||||
typeHeaderLayout.setExpandRatio(title, 1.0f);
|
||||
addComponent(typeHeaderLayout);
|
||||
}
|
||||
|
||||
private Label createHeaderCaption() {
|
||||
final Label captionLabel = SPUIComponentProvider.getLabel(getTitle(), SPUILabelDefinitions.SP_WIDGET_CAPTION);
|
||||
return captionLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract String getHideButtonId();
|
||||
|
||||
/**
|
||||
* Check if user is authorized for this action.
|
||||
*
|
||||
* @return true if user has permission otherwise false.
|
||||
*/
|
||||
protected abstract boolean hasCreateUpdatePermission();
|
||||
|
||||
/**
|
||||
* Get the title to be displayed on the header of filter button layout.
|
||||
*
|
||||
* @return title to be displayed.
|
||||
*/
|
||||
protected abstract String getTitle();
|
||||
|
||||
/**
|
||||
* This method will be called when settings icon (or) clicked on the header.
|
||||
*
|
||||
* @param event
|
||||
* reference of {@link Button.ClicEvent}.
|
||||
*/
|
||||
protected abstract void settingsIconClicked(final Button.ClickEvent event);
|
||||
|
||||
/**
|
||||
* Space required to show drop hits in the filter layout header.
|
||||
*
|
||||
* @return true to display drop hit.
|
||||
*/
|
||||
protected abstract boolean dropHitsRequired();
|
||||
|
||||
/**
|
||||
* This method will be called when hide button (X) is clicked.
|
||||
*/
|
||||
protected abstract void hideFilterButtonLayout();
|
||||
|
||||
/**
|
||||
* Add/update type button id.
|
||||
*/
|
||||
protected abstract String getConfigureFilterButtonId();
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
protected abstract boolean isAddTagRequired();
|
||||
|
||||
}
|
||||
@@ -1,70 +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.common.filterlayout;
|
||||
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
|
||||
import com.vaadin.ui.Alignment;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
|
||||
/**
|
||||
* Parent class for filter button layout.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractFilterLayout extends VerticalLayout {
|
||||
|
||||
private static final long serialVersionUID = 9190616426688385851L;
|
||||
|
||||
private AbstractFilterHeader filterHeader;
|
||||
|
||||
private AbstractFilterButtons filterButtons;
|
||||
|
||||
/**
|
||||
* Initialize the artifact details layout.
|
||||
*/
|
||||
protected void init(final AbstractFilterHeader filterHeader, final AbstractFilterButtons filterButtons,
|
||||
final AbstractFilterButtonClickBehaviour filterButtonClickBehaviour) {
|
||||
this.filterHeader = filterHeader;
|
||||
this.filterButtons = filterButtons;
|
||||
filterButtons.init(filterButtonClickBehaviour);
|
||||
buildLayout();
|
||||
restoreState();
|
||||
}
|
||||
|
||||
private void buildLayout() {
|
||||
setWidth(SPUIDefinitions.FILTER_BY_TYPE_WIDTH, Unit.PIXELS);
|
||||
setStyleName("filter-btns-main-layout");
|
||||
setHeight(100.0f, Unit.PERCENTAGE);
|
||||
setSpacing(false);
|
||||
setMargin(false);
|
||||
|
||||
addComponents(filterHeader, filterButtons);
|
||||
|
||||
setComponentAlignment(filterHeader, Alignment.TOP_CENTER);
|
||||
setComponentAlignment(filterButtons, Alignment.TOP_CENTER);
|
||||
|
||||
setExpandRatio(filterButtons, 1.0f);
|
||||
}
|
||||
|
||||
private void restoreState() {
|
||||
if (onLoadIsTypeFilterIsClosed()) {
|
||||
setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* On load, software module type filter is cloaed.
|
||||
*
|
||||
* @return true if filter is cleaned before.
|
||||
*/
|
||||
public abstract Boolean onLoadIsTypeFilterIsClosed();
|
||||
}
|
||||
@@ -1,69 +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.common.filterlayout;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
|
||||
|
||||
import com.vaadin.ui.Button;
|
||||
import com.vaadin.ui.Button.ClickEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractFilterMultiButtonClick extends AbstractFilterButtonClickBehaviour {
|
||||
|
||||
protected final Set<Button> alreadyClickedButtons = new HashSet<>();
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.hawkbit.server.ui.layouts.SPFilterButtonClick#
|
||||
* processFilterButtonClick(com.vaadin.ui. Button.ClickEvent)
|
||||
*/
|
||||
@Override
|
||||
public void processFilterButtonClick(final ClickEvent event) {
|
||||
final Button clickedButton = (Button) event.getComponent();
|
||||
if (isButtonUnClicked(clickedButton)) {
|
||||
/* If same button clicked */
|
||||
clickedButton.removeStyleName(SPUIStyleDefinitions.SP_FILTER_BTN_CLICKED_STYLE);
|
||||
alreadyClickedButtons.remove(clickedButton);
|
||||
filterUnClicked(clickedButton);
|
||||
} else {
|
||||
clickedButton.addStyleName(SPUIStyleDefinitions.SP_FILTER_BTN_CLICKED_STYLE);
|
||||
alreadyClickedButtons.add(clickedButton);
|
||||
filterClicked(clickedButton);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.hawkbit.server.ui.layouts.SPFilterButtonClickBehaviour#
|
||||
* setDefaultClickedButton(com.vaadin .ui.Button)
|
||||
*/
|
||||
@Override
|
||||
protected void setDefaultClickedButton(final Button button) {
|
||||
if (button != null) {
|
||||
alreadyClickedButtons.add(button);
|
||||
button.addStyleName(SPUIStyleDefinitions.SP_FILTER_BTN_CLICKED_STYLE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param clickedButton
|
||||
* @return
|
||||
*/
|
||||
private boolean isButtonUnClicked(final Button clickedButton) {
|
||||
return !alreadyClickedButtons.isEmpty() && alreadyClickedButtons.contains(clickedButton);
|
||||
}
|
||||
}
|
||||
@@ -1,94 +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.common.filterlayout;
|
||||
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
|
||||
|
||||
import com.vaadin.ui.Button;
|
||||
import com.vaadin.ui.Button.ClickEvent;
|
||||
|
||||
/**
|
||||
* Abstract Single button click behaviour of filter buttons layout.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractFilterSingleButtonClick extends AbstractFilterButtonClickBehaviour {
|
||||
|
||||
private static final long serialVersionUID = 478874092615793581L;
|
||||
|
||||
private Button alreadyClickedButton;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.hawkbit.server.ui.layouts.SPFilterButtonClick#
|
||||
* processFilterButtonClick(com.vaadin.ui. Button.ClickEvent)
|
||||
*/
|
||||
@Override
|
||||
protected void processFilterButtonClick(final ClickEvent event) {
|
||||
final Button clickedButton = (Button) event.getComponent();
|
||||
if (isButtonUnClicked(clickedButton)) {
|
||||
/* If same button clicked */
|
||||
clickedButton.removeStyleName(SPUIStyleDefinitions.SP_FILTER_BTN_CLICKED_STYLE);
|
||||
alreadyClickedButton = null;
|
||||
filterUnClicked(clickedButton);
|
||||
} else if (alreadyClickedButton != null) {
|
||||
/* If button clicked and some other button is already clicked */
|
||||
alreadyClickedButton.removeStyleName(SPUIStyleDefinitions.SP_FILTER_BTN_CLICKED_STYLE);
|
||||
clickedButton.addStyleName(SPUIStyleDefinitions.SP_FILTER_BTN_CLICKED_STYLE);
|
||||
alreadyClickedButton = clickedButton;
|
||||
filterClicked(clickedButton);
|
||||
} else {
|
||||
/* If button clicked and not other button is clicked currently */
|
||||
clickedButton.addStyleName(SPUIStyleDefinitions.SP_FILTER_BTN_CLICKED_STYLE);
|
||||
alreadyClickedButton = clickedButton;
|
||||
filterClicked(clickedButton);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param clickedButton
|
||||
* @return
|
||||
*/
|
||||
private boolean isButtonUnClicked(final Button clickedButton) {
|
||||
return alreadyClickedButton != null && alreadyClickedButton.equals(clickedButton);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.hawkbit.server.ui.layouts.SPFilterButtonClickBehaviour#
|
||||
* setDefaultClickedButton(com.vaadin .ui.Button)
|
||||
*/
|
||||
@Override
|
||||
protected void setDefaultClickedButton(final Button button) {
|
||||
alreadyClickedButton = button;
|
||||
if (button != null) {
|
||||
button.addStyleName(SPUIStyleDefinitions.SP_FILTER_BTN_CLICKED_STYLE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the alreadyClickedButton
|
||||
*/
|
||||
public Button getAlreadyClickedButton() {
|
||||
return alreadyClickedButton;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param alreadyClickedButton
|
||||
* the alreadyClickedButton to set
|
||||
*/
|
||||
public void setAlreadyClickedButton(final Button alreadyClickedButton) {
|
||||
this.alreadyClickedButton = alreadyClickedButton;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,415 +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.common.footer;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import org.eclipse.hawkbit.repository.SpPermissionChecker;
|
||||
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
|
||||
import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmall;
|
||||
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.I18N;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.UINotification;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.vaadin.spring.events.EventBus;
|
||||
|
||||
import com.vaadin.event.dd.DragAndDropEvent;
|
||||
import com.vaadin.event.dd.DropHandler;
|
||||
import com.vaadin.event.dd.acceptcriteria.AcceptCriterion;
|
||||
import com.vaadin.server.FontAwesome;
|
||||
import com.vaadin.server.Page;
|
||||
import com.vaadin.ui.Alignment;
|
||||
import com.vaadin.ui.Button;
|
||||
import com.vaadin.ui.Component;
|
||||
import com.vaadin.ui.DragAndDropWrapper;
|
||||
import com.vaadin.ui.HorizontalLayout;
|
||||
import com.vaadin.ui.Label;
|
||||
import com.vaadin.ui.UI;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
import com.vaadin.ui.Window;
|
||||
import com.vaadin.ui.themes.ValoTheme;
|
||||
|
||||
/**
|
||||
* Parent class for footer layout.
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractDeleteActionsLayout extends VerticalLayout implements DropHandler {
|
||||
|
||||
private static final long serialVersionUID = -6047975388519155509L;
|
||||
|
||||
@Autowired
|
||||
protected I18N i18n;
|
||||
|
||||
@Autowired
|
||||
protected SpPermissionChecker permChecker;
|
||||
|
||||
@Autowired
|
||||
protected transient EventBus.SessionEventBus eventBus;
|
||||
|
||||
@Autowired
|
||||
protected transient UINotification notification;
|
||||
|
||||
private DragAndDropWrapper deleteWrapper;
|
||||
|
||||
private Button noActionBtn;
|
||||
|
||||
private Window unsavedActionsWindow;
|
||||
|
||||
private Button bulkUploadStatusButton;
|
||||
|
||||
/**
|
||||
* Initialize.
|
||||
*/
|
||||
@PostConstruct
|
||||
protected void init() {
|
||||
if (hasCountMessage() || hasDeletePermission() || hasUpdatePermission() || hasBulkUploadPermission()) {
|
||||
createComponents();
|
||||
buildLayout();
|
||||
reload();
|
||||
}
|
||||
eventBus.subscribe(this);
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
void destroy() {
|
||||
eventBus.unsubscribe(this);
|
||||
}
|
||||
|
||||
private void reload() {
|
||||
restoreActionCount();
|
||||
restoreBulkUploadStatusCount();
|
||||
}
|
||||
|
||||
private void createComponents() {
|
||||
if (hasDeletePermission()) {
|
||||
deleteWrapper = createDeleteWrapperLayout();
|
||||
}
|
||||
if (hasDeletePermission() || hasUpdatePermission()) {
|
||||
noActionBtn = createActionsButton();
|
||||
}
|
||||
if (hasBulkUploadPermission()) {
|
||||
bulkUploadStatusButton = createBulkUploadStatusButton();
|
||||
}
|
||||
}
|
||||
|
||||
private void buildLayout() {
|
||||
final HorizontalLayout dropHintLayout = new HorizontalLayout();
|
||||
if (hasCountMessage()) {
|
||||
dropHintLayout.addComponent(getCountMessageLabel());
|
||||
}
|
||||
final HorizontalLayout hLayout = new HorizontalLayout();
|
||||
hLayout.setSpacing(true);
|
||||
hLayout.setSizeUndefined();
|
||||
if (null != deleteWrapper) {
|
||||
hLayout.addComponent(deleteWrapper);
|
||||
hLayout.setComponentAlignment(deleteWrapper, Alignment.BOTTOM_LEFT);
|
||||
}
|
||||
if (null != noActionBtn) {
|
||||
hLayout.addComponent(noActionBtn);
|
||||
hLayout.setComponentAlignment(noActionBtn, Alignment.BOTTOM_LEFT);
|
||||
}
|
||||
if (null != bulkUploadStatusButton) {
|
||||
hLayout.addComponent(bulkUploadStatusButton);
|
||||
hLayout.setComponentAlignment(bulkUploadStatusButton, Alignment.BOTTOM_LEFT);
|
||||
}
|
||||
if (dropHintLayout.getComponentCount() > 0) {
|
||||
addComponent(dropHintLayout);
|
||||
setComponentAlignment(dropHintLayout, Alignment.BOTTOM_CENTER);
|
||||
}
|
||||
if (hLayout.getComponentCount() > 0) {
|
||||
addComponent(hLayout);
|
||||
setComponentAlignment(hLayout, Alignment.BOTTOM_CENTER);
|
||||
}
|
||||
setStyleName("footer-layout");
|
||||
setWidth("100%");
|
||||
}
|
||||
|
||||
private DragAndDropWrapper createDeleteWrapperLayout() {
|
||||
final Button dropToDelete = new Button("Drop here to delete");
|
||||
dropToDelete.setCaptionAsHtml(true);
|
||||
dropToDelete.setIcon(FontAwesome.TRASH_O);
|
||||
dropToDelete.addStyleName(ValoTheme.BUTTON_BORDERLESS);
|
||||
dropToDelete.addStyleName("drop-to-delete-button");
|
||||
dropToDelete.addStyleName(SPUIStyleDefinitions.ACTION_BUTTON);
|
||||
dropToDelete.addStyleName("del-action-button");
|
||||
dropToDelete.addStyleName("delete-icon");
|
||||
|
||||
final DragAndDropWrapper wrapper = new DragAndDropWrapper(dropToDelete);
|
||||
wrapper.setStyleName(ValoTheme.BUTTON_PRIMARY);
|
||||
wrapper.setId(getDeleteAreaId());
|
||||
wrapper.setDropHandler(this);
|
||||
wrapper.addStyleName("delete-button-border");
|
||||
wrapper.addStyleName(SPUIStyleDefinitions.SHOW_DELETE_DROP_HINT);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
private Button createActionsButton() {
|
||||
final Button button = SPUIComponentProvider.getButton(SPUIComponetIdProvider.PENDING_ACTION_BUTTON,
|
||||
getNoActionsButtonLabel(), "", "", false, FontAwesome.BELL, SPUIButtonStyleSmall.class);
|
||||
button.setStyleName(SPUIStyleDefinitions.ACTION_BUTTON);
|
||||
button.addStyleName("del-action-button");
|
||||
|
||||
button.addClickListener(event -> actionButtonClicked());
|
||||
button.setHtmlContentAllowed(true);
|
||||
return button;
|
||||
}
|
||||
|
||||
private Button createBulkUploadStatusButton() {
|
||||
final Button button = SPUIComponentProvider.getButton(SPUIComponetIdProvider.BULK_UPLOAD_STATUS_BUTTON, "", "",
|
||||
"", false, null, SPUIButtonStyleSmall.class);
|
||||
button.setStyleName(SPUIStyleDefinitions.ACTION_BUTTON);
|
||||
button.addStyleName(SPUIStyleDefinitions.BULK_UPLOAD_PROGRESS_INDICATOR_STYLE);
|
||||
button.setWidth("100px");
|
||||
button.setHtmlContentAllowed(true);
|
||||
button.addClickListener(event -> onClickBulkUploadNotificationButton());
|
||||
button.setVisible(false);
|
||||
return button;
|
||||
}
|
||||
|
||||
private void onClickBulkUploadNotificationButton() {
|
||||
hideBulkUploadStatusButton();
|
||||
showBulkUploadWindow();
|
||||
}
|
||||
|
||||
protected void setUploadStatusButtonCaption(final Long count) {
|
||||
if (bulkUploadStatusButton == null) {
|
||||
return;
|
||||
}
|
||||
bulkUploadStatusButton.setCaption("<div class='unread'>" + count + "</div>");
|
||||
}
|
||||
|
||||
protected void enableBulkUploadStatusButton() {
|
||||
if (bulkUploadStatusButton == null) {
|
||||
return;
|
||||
}
|
||||
bulkUploadStatusButton.setVisible(true);
|
||||
}
|
||||
|
||||
protected void updateUploadBtnIconToComplete() {
|
||||
if (bulkUploadStatusButton == null) {
|
||||
return;
|
||||
}
|
||||
bulkUploadStatusButton.removeStyleName(SPUIStyleDefinitions.BULK_UPLOAD_PROGRESS_INDICATOR_STYLE);
|
||||
bulkUploadStatusButton.setIcon(FontAwesome.UPLOAD);
|
||||
}
|
||||
|
||||
protected void updateUploadBtnIconToProgressIndicator() {
|
||||
if (bulkUploadStatusButton == null) {
|
||||
return;
|
||||
}
|
||||
bulkUploadStatusButton.addStyleName(SPUIStyleDefinitions.BULK_UPLOAD_PROGRESS_INDICATOR_STYLE);
|
||||
bulkUploadStatusButton.setIcon(null);
|
||||
}
|
||||
|
||||
protected void actionButtonClicked() {
|
||||
if (!hasUnsavedActions()) {
|
||||
return;
|
||||
}
|
||||
unsavedActionsWindow = SPUIComponentProvider.getWindow(getUnsavedActionsWindowCaption(),
|
||||
SPUIComponetIdProvider.SAVE_ACTIONS_POPUP, SPUIDefinitions.CONFIRMATION_WINDOW);
|
||||
unsavedActionsWindow.addCloseListener(event -> unsavedActionsWindowClosed());
|
||||
unsavedActionsWindow.setContent(getUnsavedActionsWindowContent());
|
||||
unsavedActionsWindow.setId(SPUIComponetIdProvider.CONFIRMATION_POPUP_ID);
|
||||
UI.getCurrent().addWindow(unsavedActionsWindow);
|
||||
}
|
||||
|
||||
/**
|
||||
* It will close the unsaved actions window.
|
||||
*/
|
||||
protected void closeUnsavedActionsWindow() {
|
||||
UI.getCurrent().removeWindow(unsavedActionsWindow);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AcceptCriterion getAcceptCriterion() {
|
||||
return getDeleteLayoutAcceptCriteria();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drop(final DragAndDropEvent event) {
|
||||
processDroppedComponent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the pending actions count.
|
||||
*
|
||||
* @param newCount
|
||||
* new count value.
|
||||
*/
|
||||
protected void updateActionsCount(final int newCount) {
|
||||
if (noActionBtn != null) {
|
||||
if (newCount > 0) {
|
||||
noActionBtn.setCaption(getActionsButtonLabel() + "<div class='unread'>" + newCount + "</div>");
|
||||
} else {
|
||||
noActionBtn.setCaption(getNoActionsButtonLabel());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide the drop hints.
|
||||
*/
|
||||
protected void hideDropHints() {
|
||||
if (hasDeletePermission()) {
|
||||
Page.getCurrent().getJavaScript().execute(HawkbitCommonUtil.hideDeleteDropHintScript());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* show the drop hints.
|
||||
*/
|
||||
protected void showDropHints() {
|
||||
if (hasDeletePermission()) {
|
||||
Page.getCurrent().getJavaScript().execute(HawkbitCommonUtil.dispDeleteDropHintScript());
|
||||
}
|
||||
}
|
||||
|
||||
protected void hideBulkUploadStatusButton() {
|
||||
if (null != bulkUploadStatusButton) {
|
||||
bulkUploadStatusButton.setCaption(null);
|
||||
bulkUploadStatusButton.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return true if the count label is displayed false is not displayed
|
||||
*/
|
||||
protected boolean hasCountMessage() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the count message label
|
||||
*/
|
||||
protected Label getCountMessageLabel() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if bulk upload is allowed and has required create
|
||||
* permissions.
|
||||
*/
|
||||
protected boolean hasBulkUploadPermission() {
|
||||
// can be overriden
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void showBulkUploadWindow() {
|
||||
// can be overriden
|
||||
}
|
||||
|
||||
/**
|
||||
* restore the upload status count.
|
||||
*/
|
||||
protected void restoreBulkUploadStatusCount() {
|
||||
// can be overriden
|
||||
}
|
||||
|
||||
/**
|
||||
* Check user has delete permission.
|
||||
*
|
||||
* @return true if user has permission, otherwise return false.
|
||||
*/
|
||||
protected abstract boolean hasDeletePermission();
|
||||
|
||||
/**
|
||||
* Check if user has update permission.
|
||||
*
|
||||
* @return true if user has permission, otherwise return false.
|
||||
*/
|
||||
protected abstract boolean hasUpdatePermission();
|
||||
|
||||
/**
|
||||
* Get label for delete drop area.
|
||||
*
|
||||
* @return label of delete drop area.
|
||||
*/
|
||||
protected abstract String getDeleteAreaLabel();
|
||||
|
||||
/**
|
||||
* Get Id of the delete drop area.
|
||||
*
|
||||
* @return Id of the delete drop area.
|
||||
*/
|
||||
protected abstract String getDeleteAreaId();
|
||||
|
||||
/**
|
||||
* Get the accept criteria for the delete layout drop.
|
||||
*
|
||||
* @return reference of {@link AcceptCriteria}
|
||||
*/
|
||||
protected abstract AcceptCriterion getDeleteLayoutAcceptCriteria();
|
||||
|
||||
/**
|
||||
* Process the dropped component.
|
||||
*
|
||||
* @param event
|
||||
* reference of {@link DragAndDropEvent}
|
||||
*/
|
||||
protected abstract void processDroppedComponent(DragAndDropEvent event);
|
||||
|
||||
/**
|
||||
* Get the no actions button label.
|
||||
*
|
||||
* @return the no actions label.
|
||||
*/
|
||||
protected String getNoActionsButtonLabel() {
|
||||
return i18n.get("button.no.actions");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the pending actions button label.
|
||||
*
|
||||
* @return the actions label.
|
||||
*/
|
||||
protected String getActionsButtonLabel() {
|
||||
return i18n.get("button.actions");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get caption of unsaved actions window.
|
||||
*
|
||||
* @return caption of the window.
|
||||
*/
|
||||
protected String getUnsavedActionsWindowCaption() {
|
||||
return i18n.get("caption.save.window");
|
||||
}
|
||||
|
||||
/**
|
||||
* reload the count value.
|
||||
*/
|
||||
protected abstract void restoreActionCount();
|
||||
|
||||
/**
|
||||
* This method will be called when unsaved actions window is closed.
|
||||
*/
|
||||
protected abstract void unsavedActionsWindowClosed();
|
||||
|
||||
/**
|
||||
* Get the content to be displayed in unsaved actions window.
|
||||
*
|
||||
* @return reference of the component.
|
||||
*/
|
||||
protected abstract Component getUnsavedActionsWindowContent();
|
||||
|
||||
/**
|
||||
* Check if any unsaved actions done by the user.
|
||||
*
|
||||
* @return 'true' if any unsaved actions available, otherwise retrun
|
||||
* 'false'.
|
||||
*/
|
||||
protected abstract boolean hasUnsavedActions();
|
||||
|
||||
}
|
||||
@@ -1,102 +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.common.grid;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import org.eclipse.hawkbit.ui.utils.I18N;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.vaadin.spring.events.EventBus;
|
||||
|
||||
import com.vaadin.data.Container;
|
||||
import com.vaadin.data.Container.Indexed;
|
||||
import com.vaadin.ui.Grid;
|
||||
|
||||
/**
|
||||
* Abstract table class.
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractGrid extends Grid {
|
||||
|
||||
private static final long serialVersionUID = 4856562746502217630L;
|
||||
|
||||
@Autowired
|
||||
protected I18N i18n;
|
||||
|
||||
@Autowired
|
||||
protected transient EventBus.SessionEventBus eventBus;
|
||||
|
||||
|
||||
/**
|
||||
* Initialize the components.
|
||||
*/
|
||||
@PostConstruct
|
||||
protected void init() {
|
||||
setSizeFull();
|
||||
setImmediate(true);
|
||||
setId(getGridId());
|
||||
setSelectionMode(SelectionMode.NONE);
|
||||
setColumnReorderingAllowed(true);
|
||||
addNewContainerDS();
|
||||
eventBus.subscribe(this);
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
void destroy() {
|
||||
eventBus.unsubscribe(this);
|
||||
}
|
||||
|
||||
public void addNewContainerDS() {
|
||||
final Container container = createContainer();
|
||||
setContainerDataSource((Indexed) container);
|
||||
addContainerProperties();
|
||||
setColumnExpandRatio();
|
||||
setColumnProperties();
|
||||
setColumnHeaderNames();
|
||||
addColumnRenderes();
|
||||
|
||||
final CellDescriptionGenerator cellDescriptionGenerator = getDescriptionGenerator();
|
||||
if (getDescriptionGenerator() != null) {
|
||||
setCellDescriptionGenerator(cellDescriptionGenerator);
|
||||
}
|
||||
|
||||
// Allow column hiding
|
||||
for (final Column c : getColumns()) {
|
||||
c.setHidable(true);
|
||||
}
|
||||
setHiddenColumns();
|
||||
int size = 0;
|
||||
if (container != null) {
|
||||
size = container.size();
|
||||
}
|
||||
if (size == 0) {
|
||||
setData(SPUIDefinitions.NO_DATA);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract Container createContainer();
|
||||
|
||||
protected abstract void addContainerProperties();
|
||||
|
||||
protected abstract void setColumnExpandRatio();
|
||||
|
||||
protected abstract void setColumnHeaderNames();
|
||||
|
||||
protected abstract String getGridId();
|
||||
|
||||
protected abstract void setColumnProperties();
|
||||
|
||||
protected abstract void addColumnRenderes();
|
||||
|
||||
protected abstract void setHiddenColumns();
|
||||
|
||||
protected abstract CellDescriptionGenerator getDescriptionGenerator();
|
||||
}
|
||||
@@ -1,273 +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.common.grid;
|
||||
|
||||
import org.eclipse.hawkbit.ui.components.SPUIButton;
|
||||
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
|
||||
import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.vaadin.server.FontAwesome;
|
||||
import com.vaadin.ui.AbstractTextField.TextChangeEventMode;
|
||||
import com.vaadin.ui.Alignment;
|
||||
import com.vaadin.ui.Button;
|
||||
import com.vaadin.ui.HorizontalLayout;
|
||||
import com.vaadin.ui.TextField;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
|
||||
/**
|
||||
*
|
||||
* Abstract grid header.
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractGridHeader extends VerticalLayout {
|
||||
|
||||
private static final long serialVersionUID = -24429876573255519L;
|
||||
|
||||
private HorizontalLayout headerCaptionLayout;
|
||||
|
||||
private TextField searchField;
|
||||
|
||||
private SPUIButton searchResetIcon;
|
||||
|
||||
private Button addButton;
|
||||
|
||||
private Button closeButton;
|
||||
|
||||
protected void init() {
|
||||
createComponents();
|
||||
buildLayout();
|
||||
restoreState();
|
||||
}
|
||||
|
||||
private void restoreState() {
|
||||
final String onLoadSearchBoxValue = onLoadSearchBoxValue();
|
||||
if (!Strings.isNullOrEmpty(onLoadSearchBoxValue)) {
|
||||
openSearchTextField();
|
||||
searchField.setValue(onLoadSearchBoxValue);
|
||||
}
|
||||
restoreCaption();
|
||||
}
|
||||
|
||||
private void createComponents() {
|
||||
headerCaptionLayout = getHeaderCaptionLayout();
|
||||
if (isRollout()) {
|
||||
searchField = createSearchField();
|
||||
searchResetIcon = createSearchResetIcon();
|
||||
addButton = createAddButton();
|
||||
}
|
||||
closeButton = createCloseButton();
|
||||
}
|
||||
|
||||
private void buildLayout() {
|
||||
final HorizontalLayout titleFilterIconsLayout = createHeaderFilterIconLayout();
|
||||
titleFilterIconsLayout.addComponents(headerCaptionLayout);
|
||||
|
||||
if (isAllowSearch() && isRollout()) {
|
||||
titleFilterIconsLayout.addComponents(searchField, searchResetIcon);
|
||||
titleFilterIconsLayout.setExpandRatio(headerCaptionLayout, 0.3F);
|
||||
titleFilterIconsLayout.setExpandRatio(searchField, 0.7F);
|
||||
}
|
||||
if (hasCreatePermission() && isRollout()) {
|
||||
titleFilterIconsLayout.addComponent(addButton);
|
||||
titleFilterIconsLayout.setComponentAlignment(addButton, Alignment.TOP_LEFT);
|
||||
}
|
||||
if (showCloseButton()) {
|
||||
titleFilterIconsLayout.addComponent(closeButton);
|
||||
titleFilterIconsLayout.setComponentAlignment(closeButton, Alignment.TOP_RIGHT);
|
||||
}
|
||||
|
||||
titleFilterIconsLayout.setHeight("40px");
|
||||
addComponent(titleFilterIconsLayout);
|
||||
addStyleName("bordered-layout");
|
||||
addStyleName("no-border-bottom");
|
||||
}
|
||||
|
||||
private HorizontalLayout createHeaderFilterIconLayout() {
|
||||
final HorizontalLayout titleFilterIconsLayout = new HorizontalLayout();
|
||||
titleFilterIconsLayout.addStyleName(SPUIStyleDefinitions.WIDGET_TITLE);
|
||||
titleFilterIconsLayout.setSpacing(false);
|
||||
titleFilterIconsLayout.setMargin(false);
|
||||
titleFilterIconsLayout.setSizeFull();
|
||||
return titleFilterIconsLayout;
|
||||
}
|
||||
|
||||
private TextField createSearchField() {
|
||||
final TextField textField = SPUIComponentProvider.getTextField("filter-box", "text-style filter-box-hide",
|
||||
false, "", "", false, SPUILabelDefinitions.TEXT_FIELD_MAX_LENGTH);
|
||||
textField.setId(getSearchBoxId());
|
||||
textField.setWidth(100.0f, Unit.PERCENTAGE);
|
||||
textField.addTextChangeListener(event -> searchBy(event.getText()));
|
||||
textField.setTextChangeEventMode(TextChangeEventMode.LAZY);
|
||||
textField.setTextChangeTimeout(1000);
|
||||
return textField;
|
||||
}
|
||||
|
||||
private SPUIButton createSearchResetIcon() {
|
||||
final SPUIButton button = (SPUIButton) SPUIComponentProvider.getButton(getSearchRestIconId(), "", "", null,
|
||||
false, FontAwesome.SEARCH, SPUIButtonStyleSmallNoBorder.class);
|
||||
button.addClickListener(event -> onSearchResetClick());
|
||||
button.setData(Boolean.FALSE);
|
||||
return button;
|
||||
}
|
||||
|
||||
private Button createAddButton() {
|
||||
final Button button = SPUIComponentProvider.getButton(getAddIconId(), "", "", null, false, FontAwesome.PLUS,
|
||||
SPUIButtonStyleSmallNoBorder.class);
|
||||
button.addClickListener(event -> addNewItem(event));
|
||||
return button;
|
||||
}
|
||||
|
||||
private Button createCloseButton() {
|
||||
final Button button = SPUIComponentProvider.getButton(getCloseButtonId(), "", "", null, false,
|
||||
FontAwesome.TIMES, SPUIButtonStyleSmallNoBorder.class);
|
||||
button.addClickListener(event -> onClose(event));
|
||||
return button;
|
||||
}
|
||||
|
||||
private void onSearchResetClick() {
|
||||
final Boolean flag = isSearchFieldOpen();
|
||||
if (flag == null || Boolean.FALSE.equals(flag)) {
|
||||
// Clicked on search Icon
|
||||
openSearchTextField();
|
||||
} else {
|
||||
// Clicked on rest icon
|
||||
closeSearchTextField();
|
||||
}
|
||||
}
|
||||
|
||||
protected Boolean isSearchFieldOpen() {
|
||||
return (Boolean) searchResetIcon.getData();
|
||||
}
|
||||
|
||||
private void openSearchTextField() {
|
||||
searchResetIcon.addStyleName(SPUIDefinitions.FILTER_RESET_ICON);
|
||||
searchResetIcon.togleIcon(FontAwesome.TIMES);
|
||||
searchResetIcon.setData(Boolean.TRUE);
|
||||
searchField.removeStyleName(SPUIDefinitions.FILTER_BOX_HIDE);
|
||||
searchField.focus();
|
||||
}
|
||||
|
||||
private void closeSearchTextField() {
|
||||
searchField.setValue("");
|
||||
searchField.addStyleName(SPUIDefinitions.FILTER_BOX_HIDE);
|
||||
searchResetIcon.removeStyleName(SPUIDefinitions.FILTER_RESET_ICON);
|
||||
searchResetIcon.togleIcon(FontAwesome.SEARCH);
|
||||
searchResetIcon.setData(Boolean.FALSE);
|
||||
resetSearchText();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called when user resets the search text means on
|
||||
* click of (X) icon.
|
||||
*/
|
||||
protected abstract void resetSearchText();
|
||||
|
||||
/**
|
||||
* get Id of search text field.
|
||||
*
|
||||
* @return Id of the text field.
|
||||
*/
|
||||
protected abstract String getSearchBoxId();
|
||||
|
||||
/**
|
||||
* Get search reset Icon Id.
|
||||
*
|
||||
* @return Id of search reset icon.
|
||||
*/
|
||||
protected abstract String getSearchRestIconId();
|
||||
|
||||
/**
|
||||
* On search by text.
|
||||
*
|
||||
* @param newSearchText
|
||||
* search text
|
||||
*/
|
||||
protected abstract void searchBy(String newSearchText);
|
||||
|
||||
/**
|
||||
* Get Id of add Icon.
|
||||
*
|
||||
* @return String of add Icon.
|
||||
*/
|
||||
protected abstract String getAddIconId();
|
||||
|
||||
/**
|
||||
* On click add button.
|
||||
*
|
||||
* @param event
|
||||
* add button click event
|
||||
*/
|
||||
protected abstract void addNewItem(final Button.ClickEvent event);
|
||||
|
||||
/**
|
||||
* On click of close button.
|
||||
*
|
||||
* @param event
|
||||
* close button click event
|
||||
*/
|
||||
protected abstract void onClose(final Button.ClickEvent event);
|
||||
|
||||
/**
|
||||
* Checks create permission.
|
||||
*
|
||||
* @return boolean Returns true if user has create permission
|
||||
*/
|
||||
protected abstract boolean hasCreatePermission();
|
||||
|
||||
/**
|
||||
* Get close button id.
|
||||
*
|
||||
* @return String button id
|
||||
*/
|
||||
protected abstract String getCloseButtonId();
|
||||
|
||||
/**
|
||||
* Checks if close button to be displayed.
|
||||
*
|
||||
* @return true if close button has to be displayed
|
||||
*/
|
||||
protected abstract boolean showCloseButton();
|
||||
|
||||
/**
|
||||
* Checks if search is allowed.
|
||||
*
|
||||
* @return boolean if true search field is displayed.
|
||||
*/
|
||||
protected abstract boolean isAllowSearch();
|
||||
|
||||
/**
|
||||
* Get search box on load text value.
|
||||
*
|
||||
* @return value of search box.
|
||||
*/
|
||||
protected abstract String onLoadSearchBoxValue();
|
||||
|
||||
/**
|
||||
* Checks for the rollout group.
|
||||
*
|
||||
* @return boolean value for Rollout Group.
|
||||
*/
|
||||
protected abstract boolean isRollout();
|
||||
|
||||
/**
|
||||
* Get header caption layout.
|
||||
*
|
||||
* @return layout with caption
|
||||
*/
|
||||
protected abstract HorizontalLayout getHeaderCaptionLayout();
|
||||
|
||||
/**
|
||||
* Restore caption details on refresh.
|
||||
*/
|
||||
protected abstract void restoreCaption();
|
||||
}
|
||||
@@ -1,94 +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.common.grid;
|
||||
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider;
|
||||
|
||||
import com.vaadin.ui.Alignment;
|
||||
import com.vaadin.ui.HorizontalLayout;
|
||||
import com.vaadin.ui.Label;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
|
||||
/**
|
||||
*
|
||||
* Abstract grid layout class which builds layout with grid
|
||||
* {@link AbstractGrid} and table header
|
||||
* {@link AbstractGridHeader}.
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractGridLayout extends VerticalLayout {
|
||||
|
||||
private static final long serialVersionUID = 8611248179949245460L;
|
||||
|
||||
private AbstractGridHeader tableHeader;
|
||||
|
||||
private AbstractGrid grid;
|
||||
|
||||
|
||||
protected void init(final AbstractGridHeader tableHeader,final AbstractGrid grid) {
|
||||
this.tableHeader = tableHeader;
|
||||
this.grid = grid;
|
||||
buildLayout();
|
||||
}
|
||||
|
||||
private void buildLayout() {
|
||||
setSizeFull();
|
||||
setSpacing(true);
|
||||
setMargin(false);
|
||||
setStyleName("group");
|
||||
final VerticalLayout tableHeaderLayout = new VerticalLayout();
|
||||
tableHeaderLayout.setSizeFull();
|
||||
tableHeaderLayout.setSpacing(false);
|
||||
tableHeaderLayout.setMargin(false);
|
||||
|
||||
tableHeaderLayout.setStyleName("table-layout");
|
||||
tableHeaderLayout.addComponent(tableHeader);
|
||||
|
||||
tableHeaderLayout.setComponentAlignment(tableHeader, Alignment.TOP_CENTER);
|
||||
tableHeaderLayout.addComponent(grid);
|
||||
tableHeaderLayout.setComponentAlignment(grid, Alignment.TOP_CENTER);
|
||||
tableHeaderLayout.setExpandRatio(grid, 1.0f);
|
||||
|
||||
|
||||
addComponent(tableHeaderLayout);
|
||||
setComponentAlignment(tableHeaderLayout, Alignment.TOP_CENTER);
|
||||
setExpandRatio(tableHeaderLayout, 1.0f);
|
||||
if (hasCountMessage()) {
|
||||
final HorizontalLayout rolloutGroupTargetsCountLayout = createCountMessageComponent();
|
||||
addComponent(rolloutGroupTargetsCountLayout);
|
||||
setComponentAlignment(rolloutGroupTargetsCountLayout, Alignment.BOTTOM_CENTER);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private HorizontalLayout createCountMessageComponent() {
|
||||
final HorizontalLayout rolloutGroupTargetsCountLayout = new HorizontalLayout();
|
||||
final Label countMessageLabel = getCountMessageLabel();
|
||||
countMessageLabel.setId(SPUIComponetIdProvider.ROLLOUT_GROUP_TARGET_LABEL);
|
||||
rolloutGroupTargetsCountLayout.addComponent(getCountMessageLabel());
|
||||
rolloutGroupTargetsCountLayout.setStyleName("footer-layout");
|
||||
rolloutGroupTargetsCountLayout.setWidth("100%");
|
||||
return rolloutGroupTargetsCountLayout;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Only in rollout group targets view count message is displayed.
|
||||
*
|
||||
* @return true if count message has to be displayed
|
||||
*/
|
||||
protected abstract boolean hasCountMessage();
|
||||
|
||||
/**
|
||||
* Get the count message label.
|
||||
*
|
||||
* @return count message
|
||||
*/
|
||||
protected abstract Label getCountMessageLabel();
|
||||
}
|
||||
@@ -1,47 +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.common.table;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.NamedVersionedEntity;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.TableColumn;
|
||||
|
||||
import com.vaadin.data.Item;
|
||||
|
||||
/**
|
||||
* Abstract table to handling {@link NamedVersionedEntity}
|
||||
*
|
||||
* @param <E>
|
||||
* e is the entity class
|
||||
* @param <I>
|
||||
* i is the id of the table
|
||||
*/
|
||||
public abstract class AbstractNamedVersionTable<E extends NamedVersionedEntity, I> extends AbstractTable<E, I> {
|
||||
|
||||
private static final long serialVersionUID = 780050712209750719L;
|
||||
|
||||
@Override
|
||||
protected List<TableColumn> getTableVisibleColumns() {
|
||||
final List<TableColumn> columnList = super.getTableVisibleColumns();
|
||||
final float versionColumnSize = isMaximized() ? 0.1F : 0.2F;
|
||||
columnList
|
||||
.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), versionColumnSize));
|
||||
return columnList;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected void updateEntity(final E baseEntity, final Item item) {
|
||||
super.updateEntity(baseEntity, item);
|
||||
item.getItemProperty(SPUILabelDefinitions.VAR_VERSION).setValue(baseEntity.getVersion());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,348 +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.common.table;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.NamedEntity;
|
||||
import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent;
|
||||
import org.eclipse.hawkbit.ui.common.ManagmentEntityState;
|
||||
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.I18N;
|
||||
import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.TableColumn;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.vaadin.spring.events.EventBus;
|
||||
|
||||
import com.google.gwt.thirdparty.guava.common.collect.Iterables;
|
||||
import com.vaadin.data.Container;
|
||||
import com.vaadin.data.Item;
|
||||
import com.vaadin.event.dd.DropHandler;
|
||||
import com.vaadin.ui.Table;
|
||||
import com.vaadin.ui.UI;
|
||||
import com.vaadin.ui.themes.ValoTheme;
|
||||
|
||||
/**
|
||||
* Abstract table to handling entity
|
||||
*
|
||||
* @param <E>
|
||||
* e is the entity class
|
||||
* @param <I>
|
||||
* i is the id of the table
|
||||
*/
|
||||
public abstract class AbstractTable<E extends NamedEntity, I> extends Table {
|
||||
|
||||
private static final long serialVersionUID = 4856562746502217630L;
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AbstractTable.class);
|
||||
|
||||
@Autowired
|
||||
protected transient EventBus.SessionEventBus eventBus;
|
||||
|
||||
@Autowired
|
||||
protected I18N i18n;
|
||||
|
||||
/**
|
||||
* Initialize the components.
|
||||
*/
|
||||
@PostConstruct
|
||||
protected void init() {
|
||||
setStyleName("sp-table");
|
||||
setSizeFull();
|
||||
setImmediate(true);
|
||||
setHeight(100.0F, Unit.PERCENTAGE);
|
||||
addStyleName(ValoTheme.TABLE_NO_VERTICAL_LINES);
|
||||
addStyleName(ValoTheme.TABLE_SMALL);
|
||||
setSortEnabled(false);
|
||||
setId(getTableId());
|
||||
addCustomGeneratedColumns();
|
||||
addNewContainerDS();
|
||||
setColumnProperties();
|
||||
setDefault();
|
||||
addValueChangeListener(event -> onValueChange());
|
||||
selectRow();
|
||||
setPageLength(SPUIDefinitions.PAGE_SIZE);
|
||||
|
||||
setDataAvailable(getContainerDataSource().size() != 0);
|
||||
eventBus.subscribe(this);
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
protected void destroy() {
|
||||
eventBus.unsubscribe(this);
|
||||
}
|
||||
|
||||
public static <T> Set<T> getTableValue(final Table table) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Set<T> values = (Set<T>) table.getValue();
|
||||
if (values == null) {
|
||||
values = Collections.emptySet();
|
||||
}
|
||||
if (values.contains(null)) {
|
||||
LOG.warn("Null values in table content. How could this happen?");
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
private void onValueChange() {
|
||||
eventBus.publish(this, UploadArtifactUIEvent.HIDE_DROP_HINTS);
|
||||
|
||||
final Set<I> values = getTableValue(this);
|
||||
|
||||
E entity = null;
|
||||
I lastId = null;
|
||||
if (!values.isEmpty()) {
|
||||
lastId = Iterables.getLast(values);
|
||||
entity = findEntityByTableValue(lastId);
|
||||
}
|
||||
setManagementEntitiyStateValues(values, lastId);
|
||||
publishEntityAfterValueChange(entity);
|
||||
}
|
||||
|
||||
protected void setManagementEntitiyStateValues(final Set<I> values, final I lastId) {
|
||||
final ManagmentEntityState<I> managmentEntityState = getManagmentEntityState();
|
||||
if (managmentEntityState == null) {
|
||||
return;
|
||||
}
|
||||
managmentEntityState.setLastSelectedEntity(lastId);
|
||||
managmentEntityState.setSelectedEnitities(values);
|
||||
}
|
||||
|
||||
private void setDefault() {
|
||||
setSelectable(true);
|
||||
setMultiSelect(true);
|
||||
setDragMode(TableDragMode.MULTIROW);
|
||||
setColumnCollapsingAllowed(false);
|
||||
setDropHandler(getTableDropHandler());
|
||||
}
|
||||
|
||||
private void addNewContainerDS() {
|
||||
final Container container = createContainer();
|
||||
addContainerProperties(container);
|
||||
setContainerDataSource(container);
|
||||
final int size = container.size();
|
||||
if (size == 0) {
|
||||
setData(SPUIDefinitions.NO_DATA);
|
||||
}
|
||||
}
|
||||
|
||||
protected void selectRow() {
|
||||
if (!isMaximized()) {
|
||||
if (isFirstRowSelectedOnLoad()) {
|
||||
selectFirstRow();
|
||||
} else {
|
||||
setValue(getItemIdToSelect());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setColumnProperties() {
|
||||
final List<TableColumn> columnList = getTableVisibleColumns();
|
||||
final List<Object> swColumnIds = new ArrayList<>();
|
||||
for (final TableColumn column : columnList) {
|
||||
setColumnHeader(column.getColumnPropertyId(), column.getColumnHeader());
|
||||
setColumnExpandRatio(column.getColumnPropertyId(), column.getExpandRatio());
|
||||
swColumnIds.add(column.getColumnPropertyId());
|
||||
}
|
||||
setVisibleColumns(swColumnIds.toArray());
|
||||
}
|
||||
|
||||
private void selectFirstRow() {
|
||||
final Container container = getContainerDataSource();
|
||||
final int size = container.size();
|
||||
if (size > 0) {
|
||||
select(firstItemId());
|
||||
}
|
||||
}
|
||||
|
||||
protected void applyMaxTableSettings() {
|
||||
setColumnProperties();
|
||||
setValue(null);
|
||||
setSelectable(false);
|
||||
setMultiSelect(false);
|
||||
setDragMode(TableDragMode.NONE);
|
||||
setColumnCollapsingAllowed(true);
|
||||
}
|
||||
|
||||
protected void applyMinTableSettings() {
|
||||
setDefault();
|
||||
setColumnProperties();
|
||||
selectRow();
|
||||
}
|
||||
|
||||
protected void refreshFilter() {
|
||||
addNewContainerDS();
|
||||
setColumnProperties();
|
||||
selectRow();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new software module to table.
|
||||
*
|
||||
* @param baseEntity
|
||||
* new software module
|
||||
*/
|
||||
protected Item addEntity(final E baseEntity) {
|
||||
final Object addItem = addItem();
|
||||
final Item item = getItem(addItem);
|
||||
updateEntity(baseEntity, item);
|
||||
return item;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void updateEntity(final E baseEntity, final Item item) {
|
||||
item.getItemProperty(SPUILabelDefinitions.VAR_NAME).setValue(baseEntity.getName());
|
||||
item.getItemProperty(SPUILabelDefinitions.VAR_ID).setValue(baseEntity.getId());
|
||||
item.getItemProperty(SPUILabelDefinitions.VAR_DESC).setValue(baseEntity.getDescription());
|
||||
item.getItemProperty(SPUILabelDefinitions.VAR_CREATED_BY)
|
||||
.setValue(HawkbitCommonUtil.getIMUser(baseEntity.getCreatedBy()));
|
||||
item.getItemProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY)
|
||||
.setValue(HawkbitCommonUtil.getIMUser(baseEntity.getLastModifiedBy()));
|
||||
item.getItemProperty(SPUILabelDefinitions.VAR_CREATED_DATE)
|
||||
.setValue(SPDateTimeUtil.getFormattedDate(baseEntity.getCreatedAt()));
|
||||
item.getItemProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE)
|
||||
.setValue(SPDateTimeUtil.getFormattedDate(baseEntity.getLastModifiedAt()));
|
||||
|
||||
}
|
||||
|
||||
protected void onBaseEntityEvent(final BaseEntityEvent<E> event) {
|
||||
if (BaseEntityEventType.MINIMIZED == event.getEventType()) {
|
||||
UI.getCurrent().access(() -> applyMinTableSettings());
|
||||
} else if (BaseEntityEventType.MAXIMIZED == event.getEventType()) {
|
||||
UI.getCurrent().access(() -> applyMaxTableSettings());
|
||||
} else if (BaseEntityEventType.NEW_ENTITY == event.getEventType()) {
|
||||
UI.getCurrent().access(() -> addEntity(event.getEntity()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the entity which should be deleted by a transferable
|
||||
*
|
||||
* @param transferable
|
||||
* the table transferable
|
||||
* @return set of entities id which will deleted
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Set<I> getDeletedEntityByTransferable(final TableTransferable transferable) {
|
||||
final Set<I> selectedEntities = (Set<I>) getTableValue(this);
|
||||
final Set<I> ids = new HashSet<>();
|
||||
final Object tranferableData = transferable.getData(SPUIDefinitions.ITEMID);
|
||||
if (tranferableData == null) {
|
||||
return ids;
|
||||
}
|
||||
|
||||
if (!selectedEntities.contains(tranferableData)) {
|
||||
ids.add((I) tranferableData);
|
||||
} else {
|
||||
ids.addAll(selectedEntities);
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
protected abstract E findEntityByTableValue(I lastSelectedId);
|
||||
|
||||
protected abstract void publishEntityAfterValueChange(E selectedLastEntity);
|
||||
|
||||
protected abstract ManagmentEntityState<I> getManagmentEntityState();
|
||||
|
||||
/**
|
||||
* Get Id of the table.
|
||||
*
|
||||
* @return Id.
|
||||
*/
|
||||
protected abstract String getTableId();
|
||||
|
||||
/**
|
||||
* Create container of the data to be displayed by the table.
|
||||
*/
|
||||
protected abstract Container createContainer();
|
||||
|
||||
/**
|
||||
* Add container properties to the container passed in the reference.
|
||||
*
|
||||
* @param container
|
||||
* reference of {@link Container}
|
||||
*/
|
||||
protected abstract void addContainerProperties(Container container);
|
||||
|
||||
/**
|
||||
* Add any generated columns if required.
|
||||
*/
|
||||
protected void addCustomGeneratedColumns() {
|
||||
// can be overriden
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if first row should be selected by default on load.
|
||||
*
|
||||
* @return true if it should be selected otherwise return false.
|
||||
*/
|
||||
protected abstract boolean isFirstRowSelectedOnLoad();
|
||||
|
||||
/**
|
||||
* Get Item Id should be displayed as selected.
|
||||
*
|
||||
* @return reference of Item Id of the Row.
|
||||
*/
|
||||
protected abstract Object getItemIdToSelect();
|
||||
|
||||
/**
|
||||
* Check if the table is maximized or minimized.
|
||||
*
|
||||
* @return true if maximized, otherwise false.
|
||||
*/
|
||||
protected abstract boolean isMaximized();
|
||||
|
||||
/**
|
||||
* Based on table state (max/min) columns to be shown are returned.
|
||||
*
|
||||
* @return List<TableColumn> list of visible columns
|
||||
*/
|
||||
protected List<TableColumn> getTableVisibleColumns() {
|
||||
final List<TableColumn> columnList = new ArrayList<>();
|
||||
if (!isMaximized()) {
|
||||
columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"),
|
||||
getColumnNameMinimizedSize()));
|
||||
return columnList;
|
||||
}
|
||||
columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.2F));
|
||||
columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_BY, i18n.get("header.createdBy"), 0.1F));
|
||||
columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_DATE, i18n.get("header.createdDate"), 0.1F));
|
||||
columnList.add(new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, i18n.get("header.modifiedBy"), 0.1F));
|
||||
columnList.add(
|
||||
new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, i18n.get("header.modifiedDate"), 0.1F));
|
||||
columnList.add(new TableColumn(SPUILabelDefinitions.VAR_DESC, i18n.get("header.description"), 0.2F));
|
||||
return columnList;
|
||||
}
|
||||
|
||||
protected float getColumnNameMinimizedSize() {
|
||||
return 0.8F;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get drop handler for the table.
|
||||
*
|
||||
* @return reference of {@link DropHandler}
|
||||
*/
|
||||
protected abstract DropHandler getTableDropHandler();
|
||||
|
||||
protected abstract void setDataAvailable(boolean available);
|
||||
|
||||
}
|
||||
@@ -1,536 +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.common.table;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import org.eclipse.hawkbit.repository.SpPermissionChecker;
|
||||
import org.eclipse.hawkbit.ui.components.SPUIButton;
|
||||
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
|
||||
import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder;
|
||||
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.I18N;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.vaadin.spring.events.EventBus;
|
||||
|
||||
import com.vaadin.event.dd.DropHandler;
|
||||
import com.vaadin.server.FontAwesome;
|
||||
import com.vaadin.ui.AbstractTextField.TextChangeEventMode;
|
||||
import com.vaadin.ui.Alignment;
|
||||
import com.vaadin.ui.Button;
|
||||
import com.vaadin.ui.DragAndDropWrapper;
|
||||
import com.vaadin.ui.HorizontalLayout;
|
||||
import com.vaadin.ui.Label;
|
||||
import com.vaadin.ui.TextField;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
|
||||
/**
|
||||
* Parent class for table header.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractTableHeader extends VerticalLayout {
|
||||
|
||||
private static final long serialVersionUID = 4881626370291837175L;
|
||||
|
||||
@Autowired
|
||||
protected I18N i18n;
|
||||
|
||||
@Autowired
|
||||
protected SpPermissionChecker permChecker;
|
||||
|
||||
@Autowired
|
||||
protected transient EventBus.SessionEventBus eventbus;
|
||||
|
||||
|
||||
private Label headerCaption;
|
||||
|
||||
private TextField searchField;
|
||||
|
||||
private SPUIButton searchResetIcon;
|
||||
|
||||
private Button showFilterButtonLayout;
|
||||
|
||||
private Button addIcon;
|
||||
|
||||
private SPUIButton maxMinIcon;
|
||||
|
||||
private HorizontalLayout filterDroppedInfo;
|
||||
|
||||
private DragAndDropWrapper dropFilterLayout;
|
||||
|
||||
private Button bulkUploadIcon;
|
||||
|
||||
/**
|
||||
* Initialze components.
|
||||
*/
|
||||
@PostConstruct
|
||||
protected void init() {
|
||||
createComponents();
|
||||
buildLayout();
|
||||
restoreState();
|
||||
eventbus.subscribe(this);
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
void destroy() {
|
||||
eventbus.unsubscribe(this);
|
||||
}
|
||||
|
||||
private void createComponents() {
|
||||
headerCaption = createHeaderCaption();
|
||||
searchField = createSearchField();
|
||||
|
||||
searchResetIcon = createSearchResetIcon();
|
||||
|
||||
addIcon = createAddIcon();
|
||||
|
||||
bulkUploadIcon = createBulkUploadIcon();
|
||||
|
||||
showFilterButtonLayout = createShowFilterButtonLayout();
|
||||
// Not visible by default.
|
||||
showFilterButtonLayout.setVisible(false);
|
||||
|
||||
maxMinIcon = createMaxMinIcon();
|
||||
|
||||
final String onLoadSearchBoxValue = onLoadSearchBoxValue();
|
||||
|
||||
if (onLoadSearchBoxValue != null && onLoadSearchBoxValue.length() > 0) {
|
||||
openSearchTextField();
|
||||
searchField.setValue(onLoadSearchBoxValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void restoreState() {
|
||||
|
||||
final String onLoadSearchBoxValue = onLoadSearchBoxValue();
|
||||
if (HawkbitCommonUtil.trimAndNullIfEmpty(onLoadSearchBoxValue) != null) {
|
||||
openSearchTextField();
|
||||
searchField.setValue(onLoadSearchBoxValue);
|
||||
}
|
||||
|
||||
if (onLoadIsTableMaximized()) {
|
||||
/**
|
||||
* If table is maximized display the minimize icon.
|
||||
*/
|
||||
showMinIcon();
|
||||
hideAddAndUploadIcon();
|
||||
}
|
||||
|
||||
if (onLoadIsShowFilterButtonDisplayed()) {
|
||||
/**
|
||||
* Show filter button will be displayed when filter button layout is
|
||||
* closed.
|
||||
*/
|
||||
setFilterButtonsIconVisible(true);
|
||||
}
|
||||
if (isBulkUploadInProgress()) {
|
||||
disableBulkUpload();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void hideAddAndUploadIcon() {
|
||||
addIcon.setVisible(false);
|
||||
bulkUploadIcon.setVisible(false);
|
||||
}
|
||||
|
||||
private void showAddAndUploadIcon() {
|
||||
addIcon.setVisible(true);
|
||||
bulkUploadIcon.setVisible(true);
|
||||
}
|
||||
|
||||
private void buildLayout() {
|
||||
final HorizontalLayout titleFilterIconsLayout = createHeaderFilterIconLayout();
|
||||
|
||||
titleFilterIconsLayout.addComponents(headerCaption, searchField, searchResetIcon, showFilterButtonLayout);
|
||||
titleFilterIconsLayout.setComponentAlignment(headerCaption, Alignment.TOP_LEFT);
|
||||
titleFilterIconsLayout.setComponentAlignment(searchField, Alignment.TOP_RIGHT);
|
||||
titleFilterIconsLayout.setComponentAlignment(searchResetIcon, Alignment.TOP_RIGHT);
|
||||
titleFilterIconsLayout.setComponentAlignment(showFilterButtonLayout, Alignment.TOP_RIGHT);
|
||||
if (hasCreatePermission() && isAddNewItemAllowed()) {
|
||||
titleFilterIconsLayout.addComponent(addIcon);
|
||||
titleFilterIconsLayout.setComponentAlignment(addIcon, Alignment.TOP_RIGHT);
|
||||
}
|
||||
if (hasCreatePermission() && isBulkUploadAllowed()) {
|
||||
titleFilterIconsLayout.addComponent(bulkUploadIcon);
|
||||
titleFilterIconsLayout.setComponentAlignment(bulkUploadIcon, Alignment.TOP_RIGHT);
|
||||
}
|
||||
titleFilterIconsLayout.addComponent(maxMinIcon);
|
||||
titleFilterIconsLayout.setComponentAlignment(maxMinIcon, Alignment.TOP_RIGHT);
|
||||
titleFilterIconsLayout.setExpandRatio(headerCaption, 0.4f);
|
||||
titleFilterIconsLayout.setExpandRatio(searchField, 0.6f);
|
||||
|
||||
addComponent(titleFilterIconsLayout);
|
||||
|
||||
final HorizontalLayout dropHintDropFilterLayout = new HorizontalLayout();
|
||||
dropHintDropFilterLayout.addStyleName("filter-drop-hint-layout");
|
||||
dropHintDropFilterLayout.setWidth(100, Unit.PERCENTAGE);
|
||||
if (isDropFilterRequired()) {
|
||||
filterDroppedInfo = new HorizontalLayout();
|
||||
filterDroppedInfo.setImmediate(true);
|
||||
filterDroppedInfo.setStyleName("target-dist-filter-info");
|
||||
filterDroppedInfo.setHeightUndefined();
|
||||
filterDroppedInfo.setSizeUndefined();
|
||||
displayFilterDropedInfoOnLoad();
|
||||
dropFilterLayout = new DragAndDropWrapper(filterDroppedInfo);
|
||||
dropFilterLayout.setId(getDropFilterId());
|
||||
dropFilterLayout.setDropHandler(getDropFilterHandler());
|
||||
|
||||
dropHintDropFilterLayout.addComponent(dropFilterLayout);
|
||||
dropHintDropFilterLayout.setComponentAlignment(dropFilterLayout, Alignment.TOP_CENTER);
|
||||
dropHintDropFilterLayout.setExpandRatio(dropFilterLayout, 1.0f);
|
||||
}
|
||||
addComponent(dropHintDropFilterLayout);
|
||||
setComponentAlignment(dropHintDropFilterLayout, Alignment.MIDDLE_CENTER);
|
||||
addStyleName("bordered-layout");
|
||||
addStyleName("no-border-bottom");
|
||||
}
|
||||
|
||||
/**
|
||||
* to be overridden by concrete implementation.
|
||||
*/
|
||||
protected void displayFilterDropedInfoOnLoad() {
|
||||
filterDroppedInfo.removeAllComponents();
|
||||
}
|
||||
|
||||
private Label createHeaderCaption() {
|
||||
final Label captionLabel = SPUIComponentProvider.getLabel(getHeaderCaption(),
|
||||
SPUILabelDefinitions.SP_WIDGET_CAPTION);
|
||||
return captionLabel;
|
||||
}
|
||||
|
||||
private TextField createSearchField() {
|
||||
final TextField textField = SPUIComponentProvider.getTextField("filter-box", "text-style filter-box-hide",
|
||||
false, "", "", false, SPUILabelDefinitions.TEXT_FIELD_MAX_LENGTH);
|
||||
textField.setId(getSearchBoxId());
|
||||
textField.setWidth(100.0f, Unit.PERCENTAGE);
|
||||
textField.addTextChangeListener(event -> searchBy(event.getText()));
|
||||
textField.setTextChangeEventMode(TextChangeEventMode.LAZY);
|
||||
// 1 seconds timeout.
|
||||
textField.setTextChangeTimeout(1000);
|
||||
return textField;
|
||||
}
|
||||
|
||||
private SPUIButton createSearchResetIcon() {
|
||||
final SPUIButton button = (SPUIButton) SPUIComponentProvider.getButton(getSearchRestIconId(), "", "", null,
|
||||
false, FontAwesome.SEARCH, SPUIButtonStyleSmallNoBorder.class);
|
||||
button.addClickListener(event -> onSearchResetClick());
|
||||
button.setData(Boolean.FALSE);
|
||||
return button;
|
||||
}
|
||||
|
||||
private Button createAddIcon() {
|
||||
final Button button = SPUIComponentProvider.getButton(getAddIconId(), "", "", null, false, FontAwesome.PLUS,
|
||||
SPUIButtonStyleSmallNoBorder.class);
|
||||
button.addClickListener(event -> addNewItem(event));
|
||||
return button;
|
||||
}
|
||||
|
||||
private Button createBulkUploadIcon() {
|
||||
final Button button = SPUIComponentProvider.getButton(getBulkUploadIconId(), "", "", null, false,
|
||||
FontAwesome.UPLOAD, SPUIButtonStyleSmallNoBorder.class);
|
||||
button.addClickListener(event -> bulkUpload(event));
|
||||
return button;
|
||||
}
|
||||
|
||||
private Button createShowFilterButtonLayout() {
|
||||
final Button button = SPUIComponentProvider.getButton(getShowFilterButtonLayoutId(), null, null, null, false,
|
||||
FontAwesome.TAGS, SPUIButtonStyleSmallNoBorder.class);
|
||||
button.setVisible(false);
|
||||
button.addClickListener(event -> showFilterButtonsIconClicked());
|
||||
return button;
|
||||
}
|
||||
|
||||
private SPUIButton createMaxMinIcon() {
|
||||
final SPUIButton button = (SPUIButton) SPUIComponentProvider.getButton(getMaxMinIconId(), "", "", null, false,
|
||||
FontAwesome.EXPAND, SPUIButtonStyleSmallNoBorder.class);
|
||||
button.addClickListener(event -> maxMinButtonClicked());
|
||||
return button;
|
||||
}
|
||||
|
||||
private void onSearchResetClick() {
|
||||
final Boolean flag = isSearchFieldOpen();
|
||||
if (flag == null || Boolean.FALSE.equals(flag)) {
|
||||
// Clicked on search Icon
|
||||
openSearchTextField();
|
||||
} else {
|
||||
// Clicked on rest icon
|
||||
closeSearchTextField();
|
||||
}
|
||||
}
|
||||
|
||||
protected Boolean isSearchFieldOpen() {
|
||||
return (Boolean) searchResetIcon.getData();
|
||||
}
|
||||
|
||||
private void openSearchTextField() {
|
||||
searchResetIcon.addStyleName(SPUIDefinitions.FILTER_RESET_ICON);
|
||||
searchResetIcon.togleIcon(FontAwesome.TIMES);
|
||||
searchResetIcon.setData(Boolean.TRUE);
|
||||
searchField.removeStyleName(SPUIDefinitions.FILTER_BOX_HIDE);
|
||||
searchField.focus();
|
||||
}
|
||||
|
||||
private void closeSearchTextField() {
|
||||
searchField.setValue("");
|
||||
searchField.addStyleName(SPUIDefinitions.FILTER_BOX_HIDE);
|
||||
searchResetIcon.removeStyleName(SPUIDefinitions.FILTER_RESET_ICON);
|
||||
searchResetIcon.togleIcon(FontAwesome.SEARCH);
|
||||
searchResetIcon.setData(Boolean.FALSE);
|
||||
resetSearchText();
|
||||
}
|
||||
|
||||
private void maxMinButtonClicked() {
|
||||
final Boolean flag = (Boolean) maxMinIcon.getData();
|
||||
if (flag == null || Boolean.FALSE.equals(flag)) {
|
||||
// Clicked on max Icon
|
||||
maximizedTableView();
|
||||
} else {
|
||||
// Clicked on min icon
|
||||
minimizeTableView();
|
||||
}
|
||||
}
|
||||
|
||||
private void maximizedTableView() {
|
||||
showMinIcon();
|
||||
hideAddAndUploadIcon();
|
||||
maximizeTable();
|
||||
}
|
||||
|
||||
private void minimizeTableView() {
|
||||
showMaxIcon();
|
||||
showAddAndUploadIcon();
|
||||
minimizeTable();
|
||||
}
|
||||
|
||||
private void showMinIcon() {
|
||||
maxMinIcon.togleIcon(FontAwesome.COMPRESS);
|
||||
maxMinIcon.setData(Boolean.TRUE);
|
||||
}
|
||||
|
||||
private void showMaxIcon() {
|
||||
maxMinIcon.togleIcon(FontAwesome.EXPAND);
|
||||
maxMinIcon.setData(Boolean.FALSE);
|
||||
}
|
||||
|
||||
private HorizontalLayout createHeaderFilterIconLayout() {
|
||||
final HorizontalLayout titleFilterIconsLayout = new HorizontalLayout();
|
||||
titleFilterIconsLayout.addStyleName(SPUIStyleDefinitions.WIDGET_TITLE);
|
||||
titleFilterIconsLayout.setSpacing(false);
|
||||
titleFilterIconsLayout.setMargin(false);
|
||||
titleFilterIconsLayout.setSizeFull();
|
||||
return titleFilterIconsLayout;
|
||||
}
|
||||
|
||||
private void showFilterButtonsIconClicked() {
|
||||
/* Remove the show filter Buttons button */
|
||||
setFilterButtonsIconVisible(false);
|
||||
/* Show the filter buttons layout */
|
||||
showFilterButtonsLayout();
|
||||
}
|
||||
|
||||
protected void setFilterButtonsIconVisible(final boolean isVisible) {
|
||||
showFilterButtonLayout.setVisible(isVisible);
|
||||
}
|
||||
|
||||
protected HorizontalLayout getFilterDroppedInfo() {
|
||||
return filterDroppedInfo;
|
||||
}
|
||||
|
||||
protected void enableBulkUpload() {
|
||||
bulkUploadIcon.setEnabled(true);
|
||||
}
|
||||
|
||||
protected void disableBulkUpload() {
|
||||
bulkUploadIcon.setEnabled(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets search text and closed search field when complex filters are
|
||||
* applied.
|
||||
*/
|
||||
protected void resetSearch() {
|
||||
closeSearchTextField();
|
||||
}
|
||||
|
||||
/**
|
||||
* Once user switches to custom filters search functionality is re-enabled.
|
||||
*/
|
||||
protected void disableSearch() {
|
||||
searchResetIcon.setEnabled(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Once user switches to simple filters search functionality is re-enabled.
|
||||
*/
|
||||
protected void reEnableSearch() {
|
||||
searchResetIcon.setEnabled(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the title of the table.
|
||||
*
|
||||
* @return title as String.
|
||||
*/
|
||||
protected abstract String getHeaderCaption();
|
||||
|
||||
/**
|
||||
* get Id of search text field.
|
||||
*
|
||||
* @return Id of the text field.
|
||||
*/
|
||||
protected abstract String getSearchBoxId();
|
||||
|
||||
/**
|
||||
* Get search reset Icon Id.
|
||||
*
|
||||
* @return Id of search reset icon.
|
||||
*/
|
||||
protected abstract String getSearchRestIconId();
|
||||
|
||||
/**
|
||||
* Get Id of add Icon.
|
||||
*
|
||||
* @return String of add Icon.
|
||||
*/
|
||||
protected abstract String getAddIconId();
|
||||
|
||||
/**
|
||||
* Get Id of bulk upload Icon.
|
||||
*
|
||||
* @return String of bulk upload Icon.
|
||||
*/
|
||||
protected abstract String getBulkUploadIconId();
|
||||
|
||||
/**
|
||||
* Get search box on load text value.
|
||||
*
|
||||
* @return value of search box.
|
||||
*/
|
||||
protected abstract String onLoadSearchBoxValue();
|
||||
|
||||
/**
|
||||
* Get the Id value of the drop filter in the table header.
|
||||
*
|
||||
* @return Id of the drop filter if filter is displayed, otherwise returns
|
||||
* null.
|
||||
*/
|
||||
protected abstract String getDropFilterId();
|
||||
|
||||
/**
|
||||
* Get style of the filter Icon.
|
||||
*
|
||||
* @return style of the filter Icon
|
||||
*/
|
||||
protected abstract String getFilterIconStyle();
|
||||
|
||||
/**
|
||||
* Get the Id value of the drop filter wrapper in the table header.
|
||||
*
|
||||
* @return Id of the drop filter if filter is displayed, otherwise returns
|
||||
* null.
|
||||
*/
|
||||
protected abstract String getDropFilterWrapperId();
|
||||
|
||||
/**
|
||||
* Check if logged in user has create permission..
|
||||
*
|
||||
* @return true of user has create permission, otherwise return false.
|
||||
*/
|
||||
protected abstract boolean hasCreatePermission();
|
||||
|
||||
/**
|
||||
* Check if drop hits required to display and user has permissions for that.
|
||||
*
|
||||
* @return true if drop hits should be displayed and user has permission,
|
||||
* otherwise false.
|
||||
*/
|
||||
protected abstract boolean isDropHintRequired();
|
||||
|
||||
/**
|
||||
* Check if drop filter is required.
|
||||
*
|
||||
* @return true if drop filter is required to display, otherwise return
|
||||
* false.
|
||||
*/
|
||||
protected abstract boolean isDropFilterRequired();
|
||||
|
||||
/**
|
||||
* Get Id of the show filter buttons layout.
|
||||
*
|
||||
* @return Id of the show filter buttons Icon.
|
||||
*/
|
||||
protected abstract String getShowFilterButtonLayoutId();
|
||||
|
||||
/**
|
||||
* Show the filter buttons layout logic. This method will be called when
|
||||
* show filter buttons Icon is clicked displayed on the header.
|
||||
*/
|
||||
protected abstract void showFilterButtonsLayout();
|
||||
|
||||
/**
|
||||
* This method will be called when user resets the search text means on
|
||||
* click of (X) icon.
|
||||
*/
|
||||
protected abstract void resetSearchText();
|
||||
|
||||
/**
|
||||
* Get the Id of min/max button for the table.
|
||||
*
|
||||
* @return Id of min/max button.
|
||||
*/
|
||||
protected abstract String getMaxMinIconId();
|
||||
|
||||
/**
|
||||
* Called when table is maximized.
|
||||
*/
|
||||
public abstract void maximizeTable();
|
||||
|
||||
/**
|
||||
* Called when table is minimized.
|
||||
*/
|
||||
public abstract void minimizeTable();
|
||||
|
||||
/**
|
||||
* Get the max/min icon state on load.
|
||||
*
|
||||
* @return true if table should be maximized.
|
||||
*/
|
||||
public abstract Boolean onLoadIsTableMaximized();
|
||||
|
||||
protected abstract DropHandler getDropFilterHandler();
|
||||
|
||||
/**
|
||||
* On load show filter button is displayed.
|
||||
*
|
||||
* @return true if requires to delete, otherwise false.
|
||||
*/
|
||||
public abstract Boolean onLoadIsShowFilterButtonDisplayed();
|
||||
|
||||
protected abstract boolean isBulkUploadInProgress();
|
||||
|
||||
protected abstract void searchBy(String newSearchText);
|
||||
|
||||
protected abstract void addNewItem(final Button.ClickEvent event);
|
||||
|
||||
protected abstract void bulkUpload(final Button.ClickEvent event);
|
||||
|
||||
protected abstract Boolean isAddNewItemAllowed();
|
||||
|
||||
protected abstract Boolean isBulkUploadAllowed();
|
||||
|
||||
}
|
||||
@@ -1,104 +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.common.table;
|
||||
|
||||
import org.eclipse.hawkbit.ui.common.detailslayout.AbstractTableDetailsLayout;
|
||||
|
||||
import com.vaadin.event.Action.Handler;
|
||||
import com.vaadin.ui.Alignment;
|
||||
import com.vaadin.ui.Panel;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
import com.vaadin.ui.themes.ValoTheme;
|
||||
|
||||
/**
|
||||
* Parent class for table layout.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractTableLayout extends VerticalLayout {
|
||||
|
||||
private static final long serialVersionUID = 8611248179949245460L;
|
||||
|
||||
private AbstractTableHeader tableHeader;
|
||||
|
||||
private AbstractTable table;
|
||||
|
||||
private AbstractTableDetailsLayout detailsLayout;
|
||||
|
||||
protected void init(final AbstractTableHeader tableHeader, final AbstractTable table,
|
||||
final AbstractTableDetailsLayout detailsLayout) {
|
||||
this.tableHeader = tableHeader;
|
||||
this.table = table;
|
||||
this.detailsLayout = detailsLayout;
|
||||
buildLayout();
|
||||
}
|
||||
|
||||
private void buildLayout() {
|
||||
setSizeFull();
|
||||
setSpacing(true);
|
||||
setMargin(false);
|
||||
setStyleName("group");
|
||||
final VerticalLayout tableHeaderLayout = new VerticalLayout();
|
||||
tableHeaderLayout.setSizeFull();
|
||||
tableHeaderLayout.setSpacing(false);
|
||||
tableHeaderLayout.setMargin(false);
|
||||
|
||||
tableHeaderLayout.setStyleName("table-layout");
|
||||
tableHeaderLayout.addComponent(tableHeader);
|
||||
|
||||
tableHeaderLayout.setComponentAlignment(tableHeader, Alignment.TOP_CENTER);
|
||||
if (isShortCutKeysRequired()) {
|
||||
final Panel tablePanel = new Panel();
|
||||
tablePanel.setStyleName("table-panel");
|
||||
tablePanel.setHeight(100.0f, Unit.PERCENTAGE);
|
||||
tablePanel.setContent(table);
|
||||
tablePanel.addActionHandler(getShortCutKeysHandler());
|
||||
tablePanel.addStyleName(ValoTheme.PANEL_BORDERLESS);
|
||||
tableHeaderLayout.addComponent(tablePanel);
|
||||
tableHeaderLayout.setComponentAlignment(tablePanel, Alignment.TOP_CENTER);
|
||||
tableHeaderLayout.setExpandRatio(tablePanel, 1.0f);
|
||||
} else {
|
||||
tableHeaderLayout.addComponent(table);
|
||||
tableHeaderLayout.setComponentAlignment(table, Alignment.TOP_CENTER);
|
||||
tableHeaderLayout.setExpandRatio(table, 1.0f);
|
||||
}
|
||||
|
||||
addComponent(tableHeaderLayout);
|
||||
addComponent(detailsLayout);
|
||||
setComponentAlignment(tableHeaderLayout, Alignment.TOP_CENTER);
|
||||
setComponentAlignment(detailsLayout, Alignment.TOP_CENTER);
|
||||
setExpandRatio(tableHeaderLayout, 1.0f);
|
||||
}
|
||||
|
||||
/**
|
||||
* If any short cut keys required on the table.
|
||||
*
|
||||
* @return true if required else false. Default is 'false'.
|
||||
*/
|
||||
protected boolean isShortCutKeysRequired() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the action handler for the short cut keys.
|
||||
*
|
||||
* @return reference of {@link Handler} to handler the short cut keys.
|
||||
* Default is null.
|
||||
*/
|
||||
protected Handler getShortCutKeysHandler() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setShowFilterButtonVisible(final boolean visible) {
|
||||
tableHeader.setFilterButtonsIconVisible(visible);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,44 +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.common.table;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.BaseEntity;
|
||||
|
||||
/**
|
||||
* Event to represent add, update or delete.
|
||||
*
|
||||
*/
|
||||
public class BaseEntityEvent<T extends BaseEntity> {
|
||||
|
||||
private final BaseEntityEventType eventType;
|
||||
|
||||
private final T entity;
|
||||
|
||||
/**
|
||||
* Base entity event
|
||||
*
|
||||
* @param eventType
|
||||
* the event type
|
||||
* @param entity
|
||||
* the entity reference
|
||||
*/
|
||||
public BaseEntityEvent(final BaseEntityEventType eventType, final T entity) {
|
||||
this.eventType = eventType;
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
public T getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
public BaseEntityEventType getEventType() {
|
||||
return eventType;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,17 +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.common.table;
|
||||
|
||||
/**
|
||||
* Types of the entity event.
|
||||
*
|
||||
*/
|
||||
public enum BaseEntityEventType {
|
||||
NEW_ENTITY, UPDATED_ENTITY, DELETE_ENTITY, SELECTED_ENTITY, MAXIMIZED, MINIMIZED;
|
||||
}
|
||||
@@ -1,354 +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.common.tagdetails;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import org.eclipse.hawkbit.repository.SpPermissionChecker;
|
||||
import org.eclipse.hawkbit.repository.model.BaseEntity;
|
||||
import org.eclipse.hawkbit.ui.common.table.BaseEntityEvent;
|
||||
import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType;
|
||||
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.SPUIStyleDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.UINotification;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.vaadin.spring.events.EventBus;
|
||||
import org.vaadin.tokenfield.TokenField;
|
||||
import org.vaadin.tokenfield.TokenField.InsertPosition;
|
||||
|
||||
import com.vaadin.data.Container;
|
||||
import com.vaadin.data.Item;
|
||||
import com.vaadin.data.Property;
|
||||
import com.vaadin.data.util.IndexedContainer;
|
||||
import com.vaadin.server.FontAwesome;
|
||||
import com.vaadin.shared.ui.combobox.FilteringMode;
|
||||
import com.vaadin.ui.Button;
|
||||
import com.vaadin.ui.CssLayout;
|
||||
import com.vaadin.ui.UI;
|
||||
import com.vaadin.ui.themes.ValoTheme;
|
||||
|
||||
/**
|
||||
* Abstract class for target/ds tag token layout.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractTagToken<T extends BaseEntity> implements Serializable {
|
||||
|
||||
private static final String COLOR_PROPERTY = "color";
|
||||
|
||||
private static final long serialVersionUID = 6599386705285184783L;
|
||||
|
||||
protected TokenField tokenField;
|
||||
|
||||
protected IndexedContainer container;
|
||||
|
||||
protected final Map<Long, TagData> tagDetails = new HashMap<>();
|
||||
|
||||
protected final Map<Long, TagData> tokensAdded = new HashMap<>();
|
||||
|
||||
protected CssLayout tokenLayout = new CssLayout();
|
||||
|
||||
@Autowired
|
||||
protected SpPermissionChecker checker;
|
||||
|
||||
@Autowired
|
||||
protected I18N i18n;
|
||||
|
||||
@Autowired
|
||||
protected UINotification uinotification;
|
||||
|
||||
@Autowired
|
||||
protected transient EventBus.SessionEventBus eventBus;
|
||||
|
||||
@Autowired
|
||||
protected ManagementUIState managementUIState;
|
||||
|
||||
protected T selectedEntity;
|
||||
|
||||
@PostConstruct
|
||||
protected void init() {
|
||||
createTokenField();
|
||||
checkIfTagAssignedIsAllowed();
|
||||
eventBus.subscribe(this);
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
protected void destroy() {
|
||||
eventBus.unsubscribe(this);
|
||||
}
|
||||
|
||||
protected void onBaseEntityEvent(final BaseEntityEvent<T> baseEntityEvent) {
|
||||
if (BaseEntityEventType.SELECTED_ENTITY != baseEntityEvent.getEventType()) {
|
||||
return;
|
||||
}
|
||||
UI.getCurrent().access(() -> {
|
||||
final T entity = baseEntityEvent.getEntity();
|
||||
if (entity != null) {
|
||||
selectedEntity = entity;
|
||||
repopulateToken();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void createTokenField() {
|
||||
final Container tokenContainer = createContainer();
|
||||
tokenField = createTokenField(tokenContainer);
|
||||
tokenField.setContainerDataSource(tokenContainer);
|
||||
tokenField.setNewTokensAllowed(false);
|
||||
tokenField.setFilteringMode(FilteringMode.CONTAINS);
|
||||
tokenField.setInputPrompt(getTokenInputPrompt());
|
||||
tokenField.setTokenInsertPosition(InsertPosition.AFTER);
|
||||
tokenField.setImmediate(true);
|
||||
tokenField.addStyleName(ValoTheme.COMBOBOX_TINY);
|
||||
tokenField.setSizeFull();
|
||||
tokenField.setTokenCaptionPropertyId("name");
|
||||
}
|
||||
|
||||
protected void repopulateToken() {
|
||||
populateContainer();
|
||||
displayAlreadyAssignedTags();
|
||||
}
|
||||
|
||||
private Container createContainer() {
|
||||
container = new IndexedContainer();
|
||||
container.addContainerProperty("name", String.class, "");
|
||||
container.addContainerProperty("id", Long.class, "");
|
||||
container.addContainerProperty(COLOR_PROPERTY, String.class, "");
|
||||
return container;
|
||||
}
|
||||
|
||||
protected void addNewToken(final Long tagId) {
|
||||
tokenField.addToken(tagId);
|
||||
removeTagAssignedFromCombo(tagId);
|
||||
}
|
||||
|
||||
private void removeTagAssignedFromCombo(final Long tagId) {
|
||||
tokensAdded.put(tagId, new TagData(tagId, getTagName(tagId), getColor(tagId)));
|
||||
container.removeItem(tagId);
|
||||
}
|
||||
|
||||
protected void setContainerPropertValues(final Long tagId, final String tagName, final String tagColor) {
|
||||
tagDetails.put(tagId, new TagData(tagId, tagName, tagColor));
|
||||
final Item item = container.addItem(tagId);
|
||||
item.getItemProperty("id").setValue(tagId);
|
||||
updateItem(tagName, tagColor, item);
|
||||
}
|
||||
|
||||
protected void updateItem(final String tagName, final String tagColor, final Item item) {
|
||||
item.getItemProperty("name").setValue(tagName);
|
||||
item.getItemProperty(COLOR_PROPERTY).setValue(tagColor);
|
||||
}
|
||||
|
||||
protected void checkIfTagAssignedIsAllowed() {
|
||||
if (!isToggleTagAssignmentAllowed()) {
|
||||
tokenField.addStyleName("hideTokenFieldcombo");
|
||||
}
|
||||
}
|
||||
|
||||
private TokenField createTokenField(final Container tokenContainer) {
|
||||
return new CustomTokenField(tokenLayout, tokenContainer);
|
||||
}
|
||||
|
||||
class CustomTokenField extends TokenField {
|
||||
private static final long serialVersionUID = 694216966472937436L;
|
||||
|
||||
Container tokenContainer;
|
||||
|
||||
CustomTokenField(final CssLayout cssLayout, final Container tokenContainer) {
|
||||
super(cssLayout);
|
||||
this.tokenContainer = tokenContainer;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureTokenButton(final Object tokenId, final Button button) {
|
||||
super.configureTokenButton(tokenId, button);
|
||||
updateTokenStyle(tokenId, button);
|
||||
button.addStyleName(SPUIDefinitions.TEXT_STYLE + " " + SPUIStyleDefinitions.DETAILS_LAYOUT_STYLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTokenInput(final Object tokenId) {
|
||||
super.addToken(tokenId);
|
||||
onTokenSearch(tokenId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTokenClick(final Object tokenId) {
|
||||
if (isToggleTagAssignmentAllowed()) {
|
||||
super.onTokenClick(tokenId);
|
||||
tokenClick(tokenId);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTokenStyle(final Object tokenId, final Button button) {
|
||||
final String color = getColor(tokenId);
|
||||
button.setCaption("<span style=\"color:" + color + " !important;\">" + FontAwesome.CIRCLE.getHtml()
|
||||
+ "</span>" + " " + getItemNameProperty(tokenId).getValue().toString().concat(" ×"));
|
||||
button.setCaptionAsHtml(true);
|
||||
}
|
||||
|
||||
private void onTokenSearch(final Object tokenId) {
|
||||
assignTag(getItemNameProperty(tokenId).getValue().toString());
|
||||
removeTagAssignedFromCombo((Long) tokenId);
|
||||
}
|
||||
|
||||
private void tokenClick(final Object tokenId) {
|
||||
final Item item = tokenField.getContainerDataSource().addItem(tokenId);
|
||||
item.getItemProperty("name").setValue(tagDetails.get(tokenId).getName());
|
||||
item.getItemProperty(COLOR_PROPERTY).setValue(tagDetails.get(tokenId).getColor());
|
||||
unassignTag(tagDetails.get(tokenId).getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Property getItemNameProperty(final Object tokenId) {
|
||||
final Item item = tokenField.getContainerDataSource().getItem(tokenId);
|
||||
return item.getItemProperty("name");
|
||||
}
|
||||
|
||||
private String getColor(final Object tokenId) {
|
||||
final Item item = tokenField.getContainerDataSource().getItem(tokenId);
|
||||
if (item.getItemProperty(COLOR_PROPERTY).getValue() != null) {
|
||||
return (String) item.getItemProperty(COLOR_PROPERTY).getValue();
|
||||
} else {
|
||||
return SPUIDefinitions.DEFAULT_COLOR;
|
||||
}
|
||||
}
|
||||
|
||||
private String getTagName(final Object tokenId) {
|
||||
final Item item = tokenField.getContainerDataSource().getItem(tokenId);
|
||||
return (String) item.getItemProperty("name").getValue();
|
||||
}
|
||||
|
||||
protected void removePreviouslyAddedTokens() {
|
||||
tokensAdded.keySet().forEach(previouslyAddedToken -> tokenField.removeToken(previouslyAddedToken));
|
||||
}
|
||||
|
||||
protected Long getTagIdByTagName(final String tagName) {
|
||||
final Optional<Map.Entry<Long, TagData>> mapEntry = tagDetails.entrySet().stream()
|
||||
.filter(entry -> entry.getValue().getName().equals(tagName)).findFirst();
|
||||
if (mapEntry.isPresent()) {
|
||||
return mapEntry.get().getKey();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void removeTokenItem(final Long tokenId, final String name) {
|
||||
tokenField.removeToken(tokenId);
|
||||
setContainerPropertValues(tokenId, name, tokensAdded.get(tokenId).getColor());
|
||||
}
|
||||
|
||||
protected void removeTagFromCombo(final Long deletedTagId) {
|
||||
if (deletedTagId != null) {
|
||||
container.removeItem(deletedTagId);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract String getTagStyleName();
|
||||
|
||||
protected abstract String getTokenInputPrompt();
|
||||
|
||||
protected abstract void assignTag(final String tagNameSelected);
|
||||
|
||||
protected abstract void unassignTag(final String tagName);
|
||||
|
||||
protected abstract Boolean isToggleTagAssignmentAllowed();
|
||||
|
||||
protected abstract void displayAlreadyAssignedTags();
|
||||
|
||||
protected abstract void populateContainer();
|
||||
|
||||
public TokenField getTokenField() {
|
||||
return tokenField;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tag details.
|
||||
*
|
||||
*/
|
||||
public static class TagData implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String name;
|
||||
|
||||
private Long id;
|
||||
|
||||
private String color;
|
||||
|
||||
/**
|
||||
* Tag data constructor.
|
||||
*
|
||||
* @param id
|
||||
* @param name
|
||||
* @param color
|
||||
*/
|
||||
public TagData(final Long id, final String name, final String color) {
|
||||
this.color = color;
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* the name to set
|
||||
*/
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* the id to set
|
||||
*/
|
||||
public void setId(final Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the color
|
||||
*/
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param color
|
||||
* the color to set
|
||||
*/
|
||||
public void setColor(final String color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,43 +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.common.tagdetails;
|
||||
|
||||
import org.eclipse.hawkbit.eventbus.event.TargetTagCreatedBulkEvent;
|
||||
import org.eclipse.hawkbit.eventbus.event.TargetTagDeletedEvent;
|
||||
import org.eclipse.hawkbit.repository.TagManagement;
|
||||
import org.eclipse.hawkbit.repository.model.BaseEntity;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.vaadin.spring.events.EventScope;
|
||||
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
|
||||
|
||||
/**
|
||||
* Abstract class for target tag token layout.
|
||||
*/
|
||||
public abstract class AbstractTargetTagToken<T extends BaseEntity> extends AbstractTagToken<T> {
|
||||
|
||||
private static final long serialVersionUID = 7772876588903171201L;
|
||||
|
||||
@Autowired
|
||||
protected transient TagManagement tagManagement;
|
||||
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void onEventTargetTagCreated(final TargetTagCreatedBulkEvent event) {
|
||||
for (final TargetTag tag : event.getEntities()) {
|
||||
setContainerPropertValues(tag.getId(), tag.getName(), tag.getColour());
|
||||
}
|
||||
}
|
||||
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void onTargetDeletedEvent(final TargetTagDeletedEvent event) {
|
||||
final Long deletedTagId = getTagIdByTagName(event.getEntity().getName());
|
||||
removeTagFromCombo(deletedTagId);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,191 +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.common.tagdetails;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.eventbus.event.DistributionSetTagAssigmentResultEvent;
|
||||
import org.eclipse.hawkbit.eventbus.event.DistributionSetTagCreatedBulkEvent;
|
||||
import org.eclipse.hawkbit.eventbus.event.DistributionSetTagDeletedEvent;
|
||||
import org.eclipse.hawkbit.eventbus.event.DistributionSetTagUpdateEvent;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.TagManagement;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult;
|
||||
import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent;
|
||||
import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent;
|
||||
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.vaadin.spring.events.EventScope;
|
||||
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
|
||||
|
||||
import com.vaadin.data.Item;
|
||||
import com.vaadin.spring.annotation.SpringComponent;
|
||||
import com.vaadin.spring.annotation.ViewScope;
|
||||
|
||||
/**
|
||||
* Implementation of target/ds tag token layout.
|
||||
*
|
||||
*/
|
||||
@SpringComponent
|
||||
@ViewScope
|
||||
public class DistributionTagToken extends AbstractTagToken<DistributionSet> {
|
||||
|
||||
private static final long serialVersionUID = -8022738301736043396L;
|
||||
@Autowired
|
||||
private transient TagManagement tagManagement;
|
||||
|
||||
@Autowired
|
||||
private transient DistributionSetManagement distributionSetManagement;
|
||||
|
||||
// To Be Done : have to set this value based on view???
|
||||
private static final Boolean NOTAGS_SELECTED = Boolean.FALSE;
|
||||
|
||||
@Override
|
||||
protected String getTagStyleName() {
|
||||
return "distribution-tag-";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTokenInputPrompt() {
|
||||
return i18n.get("combo.type.tag.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void assignTag(final String tagNameSelected) {
|
||||
if (tagNameSelected != null) {
|
||||
final DistributionSetTagAssignmentResult result = toggleAssignment(tagNameSelected);
|
||||
if (result.getAssigned() >= 1 && NOTAGS_SELECTED) {
|
||||
eventBus.publish(this, ManagementUIEvent.ASSIGN_DISTRIBUTION_TAG);
|
||||
}
|
||||
} else {
|
||||
uinotification.displayValidationError(i18n.get("message.error.missing.tagname"));
|
||||
}
|
||||
}
|
||||
|
||||
private DistributionSetTagAssignmentResult toggleAssignment(final String tagNameSelected) {
|
||||
final Set<Long> distributionList = new HashSet<>();
|
||||
distributionList.add(selectedEntity.getId());
|
||||
final DistributionSetTagAssignmentResult result = distributionSetManagement
|
||||
.toggleTagAssignment(distributionList, tagNameSelected);
|
||||
uinotification.displaySuccess(HawkbitCommonUtil.createAssignmentMessage(tagNameSelected, result, i18n));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void unassignTag(final String tagName) {
|
||||
final DistributionSetTagAssignmentResult result = toggleAssignment(tagName);
|
||||
if (result.getUnassigned() >= 1 && (isClickedTagListEmpty() || getClickedTagList().contains(tagName))) {
|
||||
eventBus.publish(this, ManagementUIEvent.UNASSIGN_DISTRIBUTION_TAG);
|
||||
}
|
||||
}
|
||||
|
||||
private Boolean isClickedTagListEmpty() {
|
||||
if (getClickedTagList() == null || getClickedTagList() != null && !getClickedTagList().isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* To Be Done : this implementation will vary in views */
|
||||
private List<String> getClickedTagList() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isToggleTagAssignmentAllowed() {
|
||||
return checker.hasUpdateDistributionPermission();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayAlreadyAssignedTags() {
|
||||
removePreviouslyAddedTokens();
|
||||
if (selectedEntity != null) {
|
||||
for (final DistributionSetTag tag : selectedEntity.getTags()) {
|
||||
addNewToken(tag.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void populateContainer() {
|
||||
container.removeAllItems();
|
||||
for (final DistributionSetTag tag : tagManagement.findAllDistributionSetTags()) {
|
||||
setContainerPropertValues(tag.getId(), tag.getName(), tag.getColour());
|
||||
}
|
||||
}
|
||||
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void onEvent(final DistributionTableEvent distributionTableEvent) {
|
||||
onBaseEntityEvent(distributionTableEvent);
|
||||
}
|
||||
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void onDistributionSetTagCreatedBulkEvent(final DistributionSetTagCreatedBulkEvent event) {
|
||||
for (final DistributionSetTag distributionSetTag : event.getEntities()) {
|
||||
setContainerPropertValues(distributionSetTag.getId(), distributionSetTag.getName(),
|
||||
distributionSetTag.getColour());
|
||||
}
|
||||
}
|
||||
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void onDistributionSetTagDeletedEventBulkEvent(final DistributionSetTagDeletedEvent event) {
|
||||
final Long deletedTagId = getTagIdByTagName(event.getEntity().getName());
|
||||
removeTagFromCombo(deletedTagId);
|
||||
}
|
||||
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void onDistributionSetTagUpdateEvent(final DistributionSetTagUpdateEvent event) {
|
||||
final DistributionSetTag entity = event.getEntity();
|
||||
final Item item = container.getItem(entity.getId());
|
||||
if (item != null) {
|
||||
updateItem(entity.getName(), entity.getColour(), item);
|
||||
}
|
||||
}
|
||||
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void onTargetTagAssigmentResultEvent(final DistributionSetTagAssigmentResultEvent event) {
|
||||
final DistributionSetTagAssignmentResult assignmentResult = event.getAssigmentResult();
|
||||
final DistributionSetTag tag = assignmentResult.getDistributionSetTag();
|
||||
if (isAssign(assignmentResult)) {
|
||||
addNewToken(tag.getId());
|
||||
} else if (isUnassign(assignmentResult)) {
|
||||
removeTokenItem(tag.getId(), tag.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected boolean isAssign(final DistributionSetTagAssignmentResult assignmentResult) {
|
||||
if (assignmentResult.getAssigned() > 0) {
|
||||
final List<Long> assignedDsNames = assignmentResult.getAssignedEntity().stream().map(t -> t.getId())
|
||||
.collect(Collectors.toList());
|
||||
if (assignedDsNames.contains(managementUIState.getLastSelectedDsIdName().getId())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean isUnassign(final DistributionSetTagAssignmentResult assignmentResult) {
|
||||
if (assignmentResult.getUnassigned() > 0) {
|
||||
final List<Long> assignedDsNames = assignmentResult.getUnassignedEntity().stream().map(t -> t.getId())
|
||||
.collect(Collectors.toList());
|
||||
if (assignedDsNames.contains(managementUIState.getLastSelectedDsIdName().getId())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,176 +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.common.tagdetails;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.eventbus.event.TargetTagAssigmentResultEvent;
|
||||
import org.eclipse.hawkbit.eventbus.event.TargetTagUpdateEvent;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult;
|
||||
import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent;
|
||||
import org.eclipse.hawkbit.ui.management.event.TargetTableEvent;
|
||||
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.UINotification;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.vaadin.spring.events.EventScope;
|
||||
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
|
||||
|
||||
import com.vaadin.data.Item;
|
||||
import com.vaadin.spring.annotation.SpringComponent;
|
||||
import com.vaadin.spring.annotation.ViewScope;
|
||||
|
||||
/**
|
||||
* Implementation of Target tag token.
|
||||
*
|
||||
*
|
||||
*/
|
||||
@SpringComponent
|
||||
@ViewScope
|
||||
public class TargetTagToken extends AbstractTargetTagToken<Target> {
|
||||
|
||||
private static final long serialVersionUID = 7124887018280196721L;
|
||||
|
||||
// To Be Done : have to set this value based on view???
|
||||
private static final Boolean NOTAGS_SELECTED = Boolean.FALSE;
|
||||
|
||||
@Autowired
|
||||
private UINotification uinotification;
|
||||
|
||||
@Autowired
|
||||
private transient TargetManagement targetManagement;
|
||||
|
||||
@Override
|
||||
protected String getTagStyleName() {
|
||||
return "target-tag-";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTokenInputPrompt() {
|
||||
return i18n.get("combo.type.tag.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void assignTag(final String tagNameSelected) {
|
||||
if (tagNameSelected != null) {
|
||||
final TargetTagAssignmentResult result = toggleAssignment(tagNameSelected);
|
||||
if (result.getAssigned() >= 1 && NOTAGS_SELECTED) {
|
||||
eventBus.publish(this, ManagementUIEvent.ASSIGN_TARGET_TAG);
|
||||
}
|
||||
} else {
|
||||
uinotification.displayValidationError(i18n.get("message.error.missing.tagname"));
|
||||
}
|
||||
}
|
||||
|
||||
private TargetTagAssignmentResult toggleAssignment(final String tagNameSelected) {
|
||||
final Set<String> targetList = new HashSet<>();
|
||||
targetList.add(selectedEntity.getControllerId());
|
||||
final TargetTagAssignmentResult result = targetManagement.toggleTagAssignment(targetList, tagNameSelected);
|
||||
uinotification.displaySuccess(HawkbitCommonUtil.createAssignmentMessage(tagNameSelected, result, i18n));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void unassignTag(final String tagName) {
|
||||
final TargetTagAssignmentResult result = toggleAssignment(tagName);
|
||||
if (result.getUnassigned() >= 1 && (isClickedTagListEmpty() || getClickedTagList().contains(tagName))) {
|
||||
eventBus.publish(this, ManagementUIEvent.UNASSIGN_TARGET_TAG);
|
||||
}
|
||||
}
|
||||
|
||||
private Boolean isClickedTagListEmpty() {
|
||||
if (getClickedTagList() == null || getClickedTagList() != null && !getClickedTagList().isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* To Be Done : this implementation will vary in views */
|
||||
private List<String> getClickedTagList() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isToggleTagAssignmentAllowed() {
|
||||
return checker.hasUpdateTargetPermission();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void displayAlreadyAssignedTags() {
|
||||
removePreviouslyAddedTokens();
|
||||
if (selectedEntity != null) {
|
||||
for (final TargetTag tag : selectedEntity.getTags()) {
|
||||
addNewToken(tag.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void populateContainer() {
|
||||
container.removeAllItems();
|
||||
for (final TargetTag tag : tagManagement.findAllTargetTags()) {
|
||||
setContainerPropertValues(tag.getId(), tag.getName(), tag.getColour());
|
||||
}
|
||||
}
|
||||
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void onTargetTagUpdateEvent(final TargetTagUpdateEvent event) {
|
||||
final TargetTag entity = event.getEntity();
|
||||
final Item item = container.getItem(entity.getId());
|
||||
if (item != null) {
|
||||
updateItem(entity.getName(), entity.getColour(), item);
|
||||
}
|
||||
}
|
||||
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void onTargetTagAssigmentResultEvent(final TargetTagAssigmentResultEvent event) {
|
||||
final TargetTagAssignmentResult assignmentResult = event.getAssigmentResult();
|
||||
final TargetTag targetTag = assignmentResult.getTargetTag();
|
||||
if (isAssign(assignmentResult)) {
|
||||
addNewToken(targetTag.getId());
|
||||
} else if (isUnassign(assignmentResult)) {
|
||||
removeTokenItem(targetTag.getId(), targetTag.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected boolean isAssign(final TargetTagAssignmentResult assignmentResult) {
|
||||
if (assignmentResult.getAssigned() > 0) {
|
||||
final List<String> assignedTargetNames = assignmentResult.getAssignedEntity().stream()
|
||||
.map(t -> t.getControllerId()).collect(Collectors.toList());
|
||||
if (assignedTargetNames.contains(managementUIState.getLastSelectedTargetIdName().getControllerId())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean isUnassign(final TargetTagAssignmentResult assignmentResult) {
|
||||
if (assignmentResult.getUnassigned() > 0) {
|
||||
final List<String> unassignedTargetNamesList = assignmentResult.getUnassignedEntity().stream()
|
||||
.map(t -> t.getControllerId()).collect(Collectors.toList());
|
||||
if (unassignedTargetNamesList.contains(managementUIState.getLastSelectedTargetIdName().getControllerId())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void onEvent(final TargetTableEvent targetTableEvent) {
|
||||
onBaseEntityEvent(targetTableEvent);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,97 +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.components;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.ui.utils.I18N;
|
||||
import org.eclipse.hawkbit.ui.utils.SpringContextHelper;
|
||||
|
||||
import com.vaadin.ui.Label;
|
||||
import com.vaadin.ui.Panel;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
|
||||
/**
|
||||
* Distribution set panel for Target.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class DistributionSetInfoPanel extends Panel {
|
||||
|
||||
/**
|
||||
* Parametric constructor.
|
||||
*
|
||||
* @param distributionSet
|
||||
* as DistributionSet
|
||||
* @param caption
|
||||
* as String
|
||||
* @param style1
|
||||
* as String
|
||||
* @param style2
|
||||
* as String
|
||||
*/
|
||||
public DistributionSetInfoPanel(final DistributionSet distributionSet, final String caption, final String style1,
|
||||
final String style2) {
|
||||
super();
|
||||
setImmediate(false);
|
||||
decorate(distributionSet, caption, style1, style2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decorate.
|
||||
*
|
||||
* @param distributionSet
|
||||
* as DistributionSet
|
||||
* @param caption
|
||||
* as String
|
||||
* @param style1
|
||||
* as String
|
||||
* @param style2
|
||||
* as String
|
||||
*/
|
||||
private void decorate(final DistributionSet distributionSet, final String caption, final String style1,
|
||||
final String style2) {
|
||||
final I18N i18n = SpringContextHelper.getBean(I18N.class);
|
||||
final VerticalLayout layout = new VerticalLayout();
|
||||
// Display distribution set name
|
||||
layout.addComponent(SPUIComponentProvider.createNameValueLabel(i18n.get("label.dist.details.name"),
|
||||
distributionSet.getName(), distributionSet.getVersion()));
|
||||
|
||||
/* Module info */
|
||||
distributionSet.getModules()
|
||||
.forEach(module -> layout.addComponent(getSWModlabel(module.getType().getName(), module)));
|
||||
|
||||
layout.setSizeFull();
|
||||
layout.setMargin(false);
|
||||
layout.setSpacing(false);
|
||||
|
||||
setContent(layout);
|
||||
// Decorate specific
|
||||
setCaption(caption);
|
||||
addStyleName(style1);
|
||||
addStyleName(style2);
|
||||
addStyleName("small");
|
||||
setImmediate(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Label for SW Module.
|
||||
*
|
||||
* @param labelName
|
||||
* as Name
|
||||
* @param swModule
|
||||
* as Module (JVM|OS|AH)
|
||||
* @return Label as UI
|
||||
*/
|
||||
private Label getSWModlabel(final String labelName, final SoftwareModule swModule) {
|
||||
return SPUIComponentProvider.createNameValueLabel(labelName + " : ", swModule.getName(), swModule.getVersion());
|
||||
}
|
||||
}
|
||||
@@ -1,99 +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.components;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
|
||||
/**
|
||||
* Proxy for {@link DistributionSet}.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ProxyDistribution extends DistributionSet {
|
||||
|
||||
private static final long serialVersionUID = -8891449133620645310L;
|
||||
|
||||
private Long distId;
|
||||
|
||||
private String createdDate;
|
||||
|
||||
private String lastModifiedDate;
|
||||
|
||||
private String createdByUser;
|
||||
|
||||
private String modifiedByUser;
|
||||
|
||||
private Boolean isComplete;
|
||||
|
||||
private String nameVersion;
|
||||
|
||||
/**
|
||||
* @return the nameVersion
|
||||
*/
|
||||
public String getNameVersion() {
|
||||
return nameVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nameVersion
|
||||
* the nameVersion to set
|
||||
*/
|
||||
public void setNameVersion(final String nameVersion) {
|
||||
this.nameVersion = nameVersion;
|
||||
}
|
||||
|
||||
public Boolean getIsComplete() {
|
||||
return isComplete;
|
||||
}
|
||||
|
||||
public void setIsComplete(final Boolean isComplete) {
|
||||
this.isComplete = isComplete;
|
||||
}
|
||||
|
||||
public Long getDistId() {
|
||||
return distId;
|
||||
}
|
||||
|
||||
public void setDistId(final Long distId) {
|
||||
this.distId = distId;
|
||||
}
|
||||
|
||||
public String getCreatedDate() {
|
||||
return createdDate;
|
||||
}
|
||||
|
||||
public void setCreatedDate(final String createdDate) {
|
||||
this.createdDate = createdDate;
|
||||
}
|
||||
|
||||
public String getLastModifiedDate() {
|
||||
return lastModifiedDate;
|
||||
}
|
||||
|
||||
public void setLastModifiedDate(final String lastModifiedDate) {
|
||||
this.lastModifiedDate = lastModifiedDate;
|
||||
}
|
||||
|
||||
public String getCreatedByUser() {
|
||||
return createdByUser;
|
||||
}
|
||||
|
||||
public void setCreatedByUser(final String createdByUser) {
|
||||
this.createdByUser = createdByUser;
|
||||
}
|
||||
|
||||
public String getModifiedByUser() {
|
||||
return modifiedByUser;
|
||||
}
|
||||
|
||||
public void setModifiedByUser(final String modifiedByUser) {
|
||||
this.modifiedByUser = modifiedByUser;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,300 +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.components;
|
||||
|
||||
import java.net.URI;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetIdName;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
|
||||
/**
|
||||
* Proxy for {@link Target}.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ProxyTarget extends Target {
|
||||
private static final long serialVersionUID = -8891449133620645310L;
|
||||
private String controllerId;
|
||||
private URI address = null;
|
||||
private Long lastTargetQuery = null;
|
||||
private Long installationDate;
|
||||
|
||||
private TargetUpdateStatus updateStatus = TargetUpdateStatus.UNKNOWN;
|
||||
|
||||
private DistributionSet installedDistributionSet;
|
||||
|
||||
private TargetIdName targetIdName;
|
||||
|
||||
private String assignedDistNameVersion;
|
||||
|
||||
private String installedDistNameVersion;
|
||||
|
||||
private String pollStatusToolTip;
|
||||
|
||||
private String createdByUser;
|
||||
|
||||
private String createdDate;
|
||||
|
||||
private String lastModifiedDate;
|
||||
|
||||
private String modifiedByUser;
|
||||
|
||||
private Status status;
|
||||
|
||||
/**
|
||||
* @param controllerId
|
||||
*/
|
||||
public ProxyTarget() {
|
||||
super(null);
|
||||
final Integer generatedId = new SecureRandom().nextInt(Integer.MAX_VALUE) - Integer.MAX_VALUE;
|
||||
targetIdName = new TargetIdName(generatedId, generatedId.toString(), generatedId.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the createdByUser
|
||||
*/
|
||||
public String getCreatedByUser() {
|
||||
return createdByUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param createdByUser
|
||||
* the createdByUser to set
|
||||
*/
|
||||
public void setCreatedByUser(final String createdByUser) {
|
||||
this.createdByUser = createdByUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the createdDate
|
||||
*/
|
||||
public String getCreatedDate() {
|
||||
return createdDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param createdDate
|
||||
* the createdDate to set
|
||||
*/
|
||||
public void setCreatedDate(final String createdDate) {
|
||||
this.createdDate = createdDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the modifiedByUser
|
||||
*/
|
||||
public String getModifiedByUser() {
|
||||
return modifiedByUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param modifiedByUser
|
||||
* the modifiedByUser to set
|
||||
*/
|
||||
public void setModifiedByUser(final String modifiedByUser) {
|
||||
this.modifiedByUser = modifiedByUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the lastModifiedDate
|
||||
*/
|
||||
public String getLastModifiedDate() {
|
||||
return lastModifiedDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param lastModifiedDate
|
||||
* the lastModifiedDate to set
|
||||
*/
|
||||
public void setLastModifiedDate(final String lastModifiedDate) {
|
||||
this.lastModifiedDate = lastModifiedDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the assignedDistNameVersion
|
||||
*/
|
||||
public String getAssignedDistNameVersion() {
|
||||
return assignedDistNameVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param assignedDistNameVersion
|
||||
* the assignedDistNameVersion to set
|
||||
*/
|
||||
public void setAssignedDistNameVersion(final String assignedDistNameVersion) {
|
||||
this.assignedDistNameVersion = assignedDistNameVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the installedDistNameVersion
|
||||
*/
|
||||
public String getInstalledDistNameVersion() {
|
||||
return installedDistNameVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param installedDistNameVersion
|
||||
* the installedDistNameVersion to set
|
||||
*/
|
||||
public void setInstalledDistNameVersion(final String installedDistNameVersion) {
|
||||
this.installedDistNameVersion = installedDistNameVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* GET - ID.
|
||||
*
|
||||
* @return String as ID.
|
||||
*/
|
||||
@Override
|
||||
public String getControllerId() {
|
||||
return controllerId;
|
||||
}
|
||||
|
||||
/**
|
||||
* SET - ID.
|
||||
*
|
||||
* @param controllerId
|
||||
* as ID
|
||||
*/
|
||||
@Override
|
||||
public void setControllerId(final String controllerId) {
|
||||
this.controllerId = controllerId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the ipAddress
|
||||
*/
|
||||
public URI getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ipAddress
|
||||
* the ipAddress to set
|
||||
*/
|
||||
public void setAddress(final URI address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the lastTargetQuery
|
||||
*/
|
||||
public Long getLastTargetQuery() {
|
||||
return lastTargetQuery;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param lastTargetQuery
|
||||
* the lastTargetQuery to set
|
||||
*/
|
||||
public void setLastTargetQuery(final Long lastTargetQuery) {
|
||||
this.lastTargetQuery = lastTargetQuery;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the installationDate
|
||||
*/
|
||||
public Long getInstallationDate() {
|
||||
return installationDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param installationDate
|
||||
* the installationDate to set
|
||||
*/
|
||||
public void setInstallationDate(final Long installationDate) {
|
||||
this.installationDate = installationDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the updateStatus
|
||||
*/
|
||||
public TargetUpdateStatus getUpdateStatus() {
|
||||
return updateStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param updateStatus
|
||||
* the updateStatus to set
|
||||
*/
|
||||
public void setUpdateStatus(final TargetUpdateStatus updateStatus) {
|
||||
this.updateStatus = updateStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the installedDistributionSet
|
||||
*/
|
||||
public DistributionSet getInstalledDistributionSet() {
|
||||
return installedDistributionSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param installedDistributionSet
|
||||
* the installedDistributionSet to set
|
||||
*/
|
||||
public void setInstalledDistributionSet(final DistributionSet installedDistributionSet) {
|
||||
this.installedDistributionSet = installedDistributionSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the targetIdName
|
||||
*/
|
||||
@Override
|
||||
public TargetIdName getTargetIdName() {
|
||||
if (this.targetIdName == null) {
|
||||
return super.getTargetIdName();
|
||||
}
|
||||
return this.targetIdName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param targetIdName
|
||||
* the targetIdName to set
|
||||
*/
|
||||
public void setTargetIdName(final TargetIdName targetIdName) {
|
||||
this.targetIdName = targetIdName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the pollStatusToolTip
|
||||
*/
|
||||
public String getPollStatusToolTip() {
|
||||
return pollStatusToolTip;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param pollStatusToolTip
|
||||
* the pollStatusToolTip to set
|
||||
*/
|
||||
public void setPollStatusToolTip(final String pollStatusToolTip) {
|
||||
this.pollStatusToolTip = pollStatusToolTip;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the status
|
||||
*/
|
||||
public Status getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param status
|
||||
* the status to set
|
||||
*/
|
||||
public void setStatus(final Status status) {
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
@@ -1,49 +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.components;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ProxyTargetFilter extends TargetFilterQuery {
|
||||
|
||||
private static final long serialVersionUID = 6622060929679084419L;
|
||||
|
||||
private String createdDate;
|
||||
|
||||
private String modifiedDate;
|
||||
|
||||
public String getCreatedDate() {
|
||||
return createdDate;
|
||||
}
|
||||
|
||||
public void setCreatedDate(final String createdDate) {
|
||||
this.createdDate = createdDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the modifiedDate
|
||||
*/
|
||||
public String getModifiedDate() {
|
||||
return modifiedDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param modifiedDate
|
||||
* the modifiedDate to set
|
||||
*/
|
||||
public void setModifiedDate(final String modifiedDate) {
|
||||
this.modifiedDate = modifiedDate;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,83 +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.components;
|
||||
|
||||
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
|
||||
|
||||
import com.vaadin.server.Page;
|
||||
import com.vaadin.shared.Position;
|
||||
import com.vaadin.ui.Notification;
|
||||
|
||||
/**
|
||||
* Notification message component.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class SPNotificationMessage extends Notification {
|
||||
|
||||
/**
|
||||
* ID.
|
||||
*/
|
||||
private static final long serialVersionUID = -6512576924243195753L;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public SPNotificationMessage() {
|
||||
super("");
|
||||
}
|
||||
|
||||
/**
|
||||
* Notification message component.
|
||||
*
|
||||
* @param styleName
|
||||
* style name of message
|
||||
* @param caption
|
||||
* message caption
|
||||
* @param description
|
||||
* message description
|
||||
* @param autoClose
|
||||
* flag to indicate enable close option
|
||||
* @param page
|
||||
* current {@link Page}
|
||||
*/
|
||||
public void showNotification(final String styleName, final String caption, final String description,
|
||||
final Boolean autoClose, final Page page) {
|
||||
decorate(styleName, caption, description, autoClose);
|
||||
this.show(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decorate.
|
||||
*
|
||||
* @param styleName
|
||||
* style name of message
|
||||
* @param caption
|
||||
* message caption
|
||||
* @param description
|
||||
* message description
|
||||
* @param autoClose
|
||||
* flag to indicate enable close option
|
||||
*/
|
||||
private void decorate(final String styleName, final String caption, final String description,
|
||||
final Boolean autoClose) {
|
||||
setCaption(caption);
|
||||
setDescription(description);
|
||||
setStyleName(styleName);
|
||||
setHtmlContentAllowed(true);
|
||||
setPosition(Position.BOTTOM_RIGHT);
|
||||
if (autoClose) {
|
||||
setDelayMsec(SPUILabelDefinitions.SP_DELAY);
|
||||
} else {
|
||||
setDelayMsec(-1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,71 +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.components;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.I18N;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SpringContextHelper;
|
||||
|
||||
import com.vaadin.shared.ui.label.ContentMode;
|
||||
import com.vaadin.ui.Label;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
|
||||
/**
|
||||
* Attributes Vertical layout for Target.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class SPTargetAttributesLayout {
|
||||
private final VerticalLayout targetAttributesLayout;
|
||||
|
||||
/**
|
||||
* Parametric constructor.
|
||||
*
|
||||
* @param controllerAttibs
|
||||
* controller attributes
|
||||
*
|
||||
*/
|
||||
public SPTargetAttributesLayout(final Map<String, String> controllerAttibs) {
|
||||
targetAttributesLayout = new VerticalLayout();
|
||||
targetAttributesLayout.setSpacing(true);
|
||||
targetAttributesLayout.setMargin(true);
|
||||
decorate(controllerAttibs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom Decorate.
|
||||
*
|
||||
* @param controllerAttibs
|
||||
*/
|
||||
private void decorate(final Map<String, String> controllerAttibs) {
|
||||
final I18N i18n = SpringContextHelper.getBean(I18N.class);
|
||||
final Label title = new Label(i18n.get("label.target.controller.attrs"), ContentMode.HTML);
|
||||
title.addStyleName(SPUIDefinitions.TEXT_STYLE);
|
||||
targetAttributesLayout.addComponent(title);
|
||||
if (HawkbitCommonUtil.mapCheckStrings(controllerAttibs)) {
|
||||
for (final Map.Entry<String, String> entry : controllerAttibs.entrySet()) {
|
||||
targetAttributesLayout.addComponent(
|
||||
SPUIComponentProvider.createNameValueLabel(entry.getKey() + ": ", entry.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GET Target Attributes Layout.
|
||||
*
|
||||
* @return VerticalLayout as UI
|
||||
*/
|
||||
public VerticalLayout getTargetAttributesLayout() {
|
||||
return targetAttributesLayout;
|
||||
}
|
||||
}
|
||||
@@ -1,56 +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.components;
|
||||
|
||||
import com.vaadin.server.Resource;
|
||||
import com.vaadin.ui.Button;
|
||||
|
||||
/**
|
||||
* Basic button for SPUI. Any commonality can be decorated.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class SPUIButton extends Button {
|
||||
|
||||
/**
|
||||
* ID.
|
||||
*/
|
||||
private static final long serialVersionUID = -7327726430436273739L;
|
||||
|
||||
/**
|
||||
* Parametric constructor.
|
||||
*
|
||||
* @param id
|
||||
* as String
|
||||
* @param buttonName
|
||||
* as String
|
||||
* @param buttonDesc
|
||||
* as String
|
||||
*/
|
||||
public SPUIButton(final String id, final String buttonName, final String buttonDesc) {
|
||||
super(buttonName);
|
||||
setDescription(buttonDesc);
|
||||
setImmediate(false);
|
||||
if (null != id) {
|
||||
setId(id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toogle Icon on action.
|
||||
*
|
||||
* @param icon
|
||||
* as Resource
|
||||
*/
|
||||
public void togleIcon(Resource icon) {
|
||||
setIcon(icon);
|
||||
}
|
||||
}
|
||||
@@ -1,81 +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.components;
|
||||
|
||||
import com.vaadin.ui.CheckBox;
|
||||
import com.vaadin.ui.themes.ValoTheme;
|
||||
|
||||
/**
|
||||
* ComboBox with required style.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class SPUICheckBox extends CheckBox {
|
||||
|
||||
private static final long serialVersionUID = 2270323611612189225L;
|
||||
|
||||
/**
|
||||
* Parametric constructor to decorate.
|
||||
*
|
||||
* @param caption
|
||||
* as caption for checkbox
|
||||
* @param style
|
||||
* style of the CheckBox
|
||||
* @param styleName
|
||||
* styleName of the CheckBox
|
||||
* @param required
|
||||
* required check for Checkbox
|
||||
* @param data
|
||||
* data of the CheckBox
|
||||
*
|
||||
*/
|
||||
public SPUICheckBox(final String caption, final String style, final String styleName, final boolean required,
|
||||
final String data) {
|
||||
super();
|
||||
decorate(caption, style, styleName, required, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* decorate.
|
||||
*
|
||||
* @param style
|
||||
* style of the CheckBox
|
||||
* @param styleName
|
||||
* styleName of the CheckBox
|
||||
* @param required
|
||||
* required check for Checkbox
|
||||
* @param data
|
||||
* data of the CheckBox
|
||||
* @param promt
|
||||
* inputpromt of the CheckBox
|
||||
*/
|
||||
private void decorate(final String caption, final String style, final String styleName, final boolean required,
|
||||
final String data) {
|
||||
// Default settings
|
||||
setRequired(required);
|
||||
addStyleName(ValoTheme.CHECKBOX_SMALL);
|
||||
if (null != caption) {
|
||||
setCaption(caption);
|
||||
}
|
||||
// Add style
|
||||
if (null != style) {
|
||||
setStyleName(style);
|
||||
}
|
||||
// Add style Name
|
||||
if (null != styleName) {
|
||||
addStyleName(styleName);
|
||||
}
|
||||
// Set Data
|
||||
if (null != data) {
|
||||
setData(data);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,428 +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.components;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.ui.decorators.SPUIButtonDecorator;
|
||||
import org.eclipse.hawkbit.ui.decorators.SPUIComboBoxDecorator;
|
||||
import org.eclipse.hawkbit.ui.decorators.SPUIHeaderLayoutDecorator;
|
||||
import org.eclipse.hawkbit.ui.decorators.SPUILabelDecorator;
|
||||
import org.eclipse.hawkbit.ui.decorators.SPUITextAreaDecorator;
|
||||
import org.eclipse.hawkbit.ui.decorators.SPUITextFieldDecorator;
|
||||
import org.eclipse.hawkbit.ui.decorators.SPUIWindowDecorator;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.vaadin.server.ExternalResource;
|
||||
import com.vaadin.server.FontAwesome;
|
||||
import com.vaadin.server.Resource;
|
||||
import com.vaadin.shared.ui.label.ContentMode;
|
||||
import com.vaadin.ui.Button;
|
||||
import com.vaadin.ui.CheckBox;
|
||||
import com.vaadin.ui.ComboBox;
|
||||
import com.vaadin.ui.HorizontalLayout;
|
||||
import com.vaadin.ui.Label;
|
||||
import com.vaadin.ui.Link;
|
||||
import com.vaadin.ui.Panel;
|
||||
import com.vaadin.ui.TabSheet;
|
||||
import com.vaadin.ui.TextArea;
|
||||
import com.vaadin.ui.TextField;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
import com.vaadin.ui.Window;
|
||||
import com.vaadin.ui.themes.ValoTheme;
|
||||
|
||||
/**
|
||||
* Util class to get the Vaadin UI components for the SP-OS main UI. Factory
|
||||
* Approach to create necessary UI component which are decorated Aspect of fine
|
||||
* tuning the component or extending the component is separated.
|
||||
*
|
||||
*/
|
||||
public final class SPUIComponentProvider {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(SPUIComponentProvider.class);
|
||||
|
||||
/**
|
||||
* Prevent Instance creation as utility class.
|
||||
*/
|
||||
private SPUIComponentProvider() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param className
|
||||
* @return
|
||||
*/
|
||||
public static HorizontalLayout getHorizontalLayout(final Class<? extends HorizontalLayout> className) {
|
||||
HorizontalLayout hLayout = null;
|
||||
try {
|
||||
|
||||
hLayout = className.newInstance();
|
||||
} catch (final InstantiationException exception) {
|
||||
LOG.error("Error occured while creating HorizontalLayout-" + className, exception);
|
||||
} catch (final IllegalAccessException exception) {
|
||||
LOG.error("Error occured while acessing HorizontalLayout-" + className, exception);
|
||||
}
|
||||
|
||||
return hLayout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get HorizontalLayout UI component.
|
||||
*
|
||||
* @param className
|
||||
* as Layout
|
||||
* @return HorizontalLayout as UI
|
||||
*/
|
||||
public static HorizontalLayout getHorizontalLayout() {
|
||||
HorizontalLayout hLayout = null;
|
||||
try {
|
||||
hLayout = HorizontalLayout.class.newInstance();
|
||||
} catch (final InstantiationException exception) {
|
||||
LOG.error("Error occured while creating HorizontalLayout-", exception);
|
||||
} catch (final IllegalAccessException exception) {
|
||||
LOG.error("Error occured while acessing HorizontalLayout-", exception);
|
||||
}
|
||||
|
||||
return hLayout;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tableHeaderLayoutDecorator
|
||||
* @return
|
||||
*/
|
||||
public static HorizontalLayout getHeaderLayout(
|
||||
final Class<? extends SPUIHeaderLayoutDecorator> tableHeaderLayoutDecorator) {
|
||||
// Do we really need this???
|
||||
HorizontalLayout hLayout = getHorizontalLayout(new SPUIHorizontalLayout().getUiHorizontalLayout().getClass());
|
||||
|
||||
if (tableHeaderLayoutDecorator == null) {
|
||||
return hLayout;
|
||||
}
|
||||
|
||||
try {
|
||||
final SPUIHeaderLayoutDecorator layoutDecorator = tableHeaderLayoutDecorator.newInstance();
|
||||
hLayout = layoutDecorator.decorate(hLayout);
|
||||
|
||||
} catch (final InstantiationException | IllegalAccessException exception) {
|
||||
LOG.error("Error occured while creating horizontal decorator " + SPUIHeaderLayoutDecorator.class,
|
||||
exception);
|
||||
}
|
||||
|
||||
return hLayout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Label UI component.
|
||||
*
|
||||
* @param name
|
||||
* label caption
|
||||
* @param type
|
||||
* string simple|Confirm|Message
|
||||
* @return Label
|
||||
*/
|
||||
public static Label getLabel(final String name, final String type) {
|
||||
return SPUILabelDecorator.getDeocratedLabel(name, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get window component.
|
||||
*
|
||||
* @param caption
|
||||
* window caption
|
||||
* @param id
|
||||
* window id
|
||||
* @param type
|
||||
* type of window
|
||||
* @return Window
|
||||
*/
|
||||
public static Window getWindow(final String caption, final String id, final String type) {
|
||||
return SPUIWindowDecorator.getDeocratedWindow(caption, id, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Label UI component.
|
||||
*
|
||||
* @param style
|
||||
* set style
|
||||
* @param styleName
|
||||
* add style
|
||||
* @param required
|
||||
* to set field as mandatory
|
||||
* @param data
|
||||
* component data
|
||||
* @param promt
|
||||
* prompt user for input
|
||||
* @param immediate
|
||||
* set component's immediate mode specified mode
|
||||
* @param maxLengthAllowed
|
||||
* maximum characters allowed
|
||||
* @return TextField text field
|
||||
*/
|
||||
public static TextField getTextField(final String style, final String styleName, final boolean required,
|
||||
final String data, final String promt, final boolean immediate, final int maxLengthAllowed) {
|
||||
return SPUITextFieldDecorator.decorate(style, styleName, required, data, promt, immediate, maxLengthAllowed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Label UI component. *
|
||||
*
|
||||
* @param style
|
||||
* set style
|
||||
* @param styleName
|
||||
* add style
|
||||
* @param required
|
||||
* to set field as mandatory
|
||||
* @param data
|
||||
* component data
|
||||
* @param promt
|
||||
* prompt user for input
|
||||
* @param maxLength
|
||||
* maximum characters allowed
|
||||
* @return TextArea text area
|
||||
*/
|
||||
public static TextArea getTextArea(final String style, final String styleName, final boolean required,
|
||||
final String data, final String promt, final int maxLength) {
|
||||
return SPUITextAreaDecorator.decorate(style, styleName, required, data, promt, maxLength);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Label UI component.
|
||||
*
|
||||
* @param height
|
||||
* combo box height
|
||||
* @param width
|
||||
* combo box width
|
||||
* @param style
|
||||
* combo style to add
|
||||
* @param styleName
|
||||
* combo style to set
|
||||
* @param required
|
||||
* signifies if combo is mandatory
|
||||
* @param data
|
||||
* combo box data
|
||||
* @param promt
|
||||
* input prompt
|
||||
* @return ComboBox
|
||||
*/
|
||||
public static ComboBox getComboBox(final String height, final String width, final String style,
|
||||
final String styleName, final boolean required, final String data, final String promt) {
|
||||
return SPUIComboBoxDecorator.decorate(height, width, style, styleName, required, data, promt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Label UI component.
|
||||
*
|
||||
* @param caption
|
||||
* as caption
|
||||
* @param style
|
||||
* combo style to add
|
||||
* @param styleName
|
||||
* combo style to set
|
||||
* @param required
|
||||
* signifies if combo is mandatory
|
||||
* @param data
|
||||
* combo box data
|
||||
* @return ComboBox
|
||||
*/
|
||||
public static CheckBox getCheckBox(final String caption, final String style, final String styleName,
|
||||
final boolean required, final String data) {
|
||||
return new SPUICheckBox(caption, style, styleName, required, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Button - Factory Approach for decoration.
|
||||
*
|
||||
* @param id
|
||||
* as string
|
||||
* @param buttonName
|
||||
* as string
|
||||
* @param buttonDesc
|
||||
* as string
|
||||
* @param style
|
||||
* string as string
|
||||
* @param setStyle
|
||||
* string as boolean
|
||||
* @param icon
|
||||
* as image
|
||||
* @param buttonDecoratorclassName
|
||||
* as decorator
|
||||
* @return Button as UI
|
||||
*/
|
||||
public static Button getButton(final String id, final String buttonName, final String buttonDesc,
|
||||
final String style, final boolean setStyle, final Resource icon,
|
||||
final Class<? extends SPUIButtonDecorator> buttonDecoratorclassName) {
|
||||
Button button = null;
|
||||
SPUIButtonDecorator buttonDecorator = null;
|
||||
try {
|
||||
// Create instance
|
||||
buttonDecorator = buttonDecoratorclassName.newInstance();
|
||||
// Decorate button
|
||||
button = buttonDecorator.decorate(new SPUIButton(id, buttonName, buttonDesc), style, setStyle, icon);
|
||||
} catch (final InstantiationException exception) {
|
||||
LOG.error("Error occured while creating Button decorator-" + buttonName, exception);
|
||||
} catch (final IllegalAccessException exception) {
|
||||
LOG.error("Error occured while acessing Button decorator-" + buttonName, exception);
|
||||
}
|
||||
return button;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the style required.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public static String getPinButtonStyle() {
|
||||
final StringBuilder pinStyle = new StringBuilder(ValoTheme.BUTTON_BORDERLESS_COLORED);
|
||||
pinStyle.append(' ');
|
||||
pinStyle.append(ValoTheme.BUTTON_SMALL);
|
||||
pinStyle.append(' ');
|
||||
pinStyle.append(ValoTheme.BUTTON_ICON_ONLY);
|
||||
pinStyle.append(' ');
|
||||
pinStyle.append("pin-icon");
|
||||
return pinStyle.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get DistributionSet Info Panel.
|
||||
*
|
||||
* @param distributionSet
|
||||
* as DistributionSet
|
||||
* @param caption
|
||||
* as string
|
||||
* @param style1
|
||||
* as string
|
||||
* @param style2
|
||||
* as string
|
||||
* @return Panel
|
||||
*/
|
||||
public static Panel getDistributionSetInfo(final DistributionSet distributionSet, final String caption,
|
||||
final String style1, final String style2) {
|
||||
return new DistributionSetInfoPanel(distributionSet, caption, style1, style2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to CreateName value labels.
|
||||
*
|
||||
* @param label
|
||||
* as string
|
||||
* @param values
|
||||
* as string
|
||||
* @return Label
|
||||
*/
|
||||
public static Label createNameValueLabel(final String label, final String... values) {
|
||||
final String valueStr = StringUtils.join(Arrays.asList(values), " ");
|
||||
final Label nameValueLabel = new Label(getBoldHTMLText(label) + valueStr, ContentMode.HTML);
|
||||
nameValueLabel.setSizeFull();
|
||||
nameValueLabel.addStyleName(SPUIDefinitions.TEXT_STYLE);
|
||||
nameValueLabel.addStyleName("label-style");
|
||||
return nameValueLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Bold Text.
|
||||
*
|
||||
* @param text
|
||||
* as String
|
||||
* @return String as bold
|
||||
*/
|
||||
public static String getBoldHTMLText(final String text) {
|
||||
return "<b>" + text + "</b>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the layout for Target:Controller Attributes.
|
||||
*
|
||||
* @param controllerAttibs
|
||||
* as Map
|
||||
* @return VerticalLayout
|
||||
*/
|
||||
public static VerticalLayout getControllerAttributePanel(final Map<String, String> controllerAttibs) {
|
||||
return new SPTargetAttributesLayout(controllerAttibs).getTargetAttributesLayout();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Tabsheet.
|
||||
*
|
||||
* @return SPUITabSheet
|
||||
*/
|
||||
public static TabSheet getDetailsTabSheet() {
|
||||
return new SPUITabSheet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Layout of tabs in detail tabsheet.
|
||||
*
|
||||
* @return VerticalLayout
|
||||
*/
|
||||
public static VerticalLayout getDetailTabLayout() {
|
||||
final VerticalLayout layout = new VerticalLayout();
|
||||
layout.setSpacing(true);
|
||||
layout.setMargin(true);
|
||||
layout.setImmediate(true);
|
||||
return layout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create a link.
|
||||
*
|
||||
* @param id
|
||||
* of the link
|
||||
* @param name
|
||||
* of the link
|
||||
* @param resource
|
||||
* path of the link
|
||||
* @param icon
|
||||
* of the link
|
||||
* @param targetOpen
|
||||
* specify how the link should be open (f. e. new windows =
|
||||
* _blank)
|
||||
* @param style
|
||||
* chosen style of the link
|
||||
* @param setStyle
|
||||
* set true if the style should be used
|
||||
* @return a link UI component
|
||||
*/
|
||||
public static Link getLink(final String id, final String name, final String resource, final FontAwesome icon,
|
||||
final String targetOpen, final String style, final boolean setStyle) {
|
||||
|
||||
final Link link = new Link(name, new ExternalResource(resource));
|
||||
link.setId(id);
|
||||
link.setIcon(icon);
|
||||
|
||||
link.setTargetName(targetOpen);
|
||||
if (setStyle) {
|
||||
link.setStyleName(style);
|
||||
}
|
||||
|
||||
return link;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates help/documentation links from within management UI.
|
||||
*
|
||||
* @param uri
|
||||
* to documentation site
|
||||
*
|
||||
* @return generated link
|
||||
*/
|
||||
public static Link getHelpLink(final String uri) {
|
||||
|
||||
final Link link = new Link("", new ExternalResource(uri));
|
||||
link.setTargetName("_blank");
|
||||
link.setIcon(FontAwesome.QUESTION_CIRCLE);
|
||||
link.setDescription("Documentation");
|
||||
return link;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,65 +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.components;
|
||||
|
||||
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.I18N;
|
||||
import org.eclipse.hawkbit.ui.utils.SpringContextHelper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.vaadin.server.DefaultErrorHandler;
|
||||
import com.vaadin.server.ErrorEvent;
|
||||
import com.vaadin.ui.Component;
|
||||
import com.vaadin.ui.themes.ValoTheme;
|
||||
|
||||
/**
|
||||
*
|
||||
* Default handler for SP UI.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class SPUIErrorHandler extends DefaultErrorHandler {
|
||||
|
||||
/**
|
||||
* Comment for <code>serialVersionUID</code>.
|
||||
*/
|
||||
private static final long serialVersionUID = 1877326479308824191L;
|
||||
/**
|
||||
* logger.
|
||||
*/
|
||||
private static final Logger LOG = LoggerFactory.getLogger(SPUIErrorHandler.class);
|
||||
|
||||
@Override
|
||||
public void error(final ErrorEvent event) {
|
||||
final SPNotificationMessage notification = new SPNotificationMessage();
|
||||
// Build error style
|
||||
final StringBuilder style = new StringBuilder(ValoTheme.NOTIFICATION_FAILURE);
|
||||
style.append(' ');
|
||||
style.append(ValoTheme.NOTIFICATION_SMALL);
|
||||
style.append(' ');
|
||||
style.append(ValoTheme.NOTIFICATION_CLOSABLE);
|
||||
final I18N i18n = SpringContextHelper.getBean(I18N.class);
|
||||
String exceptionName = null;
|
||||
// From the exception trace we get the expected exception class name
|
||||
for (Throwable error = event.getThrowable(); error != null; error = error.getCause()) {
|
||||
exceptionName = HawkbitCommonUtil.getLastSequenceBySplitByDot(error.getClass().getName());
|
||||
LOG.error("Error in SP-UI:", error);
|
||||
}
|
||||
final Component errorOrgin = findAbstractComponent(event);
|
||||
if (null != errorOrgin && errorOrgin.getUI() != null) {
|
||||
notification.showNotification(style.toString(), i18n.get("caption.error"),
|
||||
i18n.get("message.error.temp", new Object[] { exceptionName }), false,
|
||||
errorOrgin.getUI().getPage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,49 +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.components;
|
||||
|
||||
import com.vaadin.ui.HorizontalLayout;
|
||||
|
||||
/**
|
||||
* Plain Horizontal Layout.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class SPUIHorizontalLayout {
|
||||
private final HorizontalLayout uiHorizontalLayout;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public SPUIHorizontalLayout() {
|
||||
uiHorizontalLayout = new HorizontalLayout();
|
||||
decorate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Decorate.
|
||||
*/
|
||||
private void decorate() {
|
||||
uiHorizontalLayout.setImmediate(false);
|
||||
uiHorizontalLayout.setMargin(false);
|
||||
uiHorizontalLayout.setSpacing(true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get HorizontalLayout.
|
||||
*
|
||||
* @return HorizontalLayout as UI
|
||||
*/
|
||||
public HorizontalLayout getUiHorizontalLayout() {
|
||||
return uiHorizontalLayout;
|
||||
}
|
||||
}
|
||||
@@ -1,39 +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.components;
|
||||
|
||||
import com.vaadin.ui.TabSheet;
|
||||
import com.vaadin.ui.themes.ValoTheme;
|
||||
|
||||
/**
|
||||
* Tabs required for discription - Down arrow.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class SPUITabSheet extends TabSheet {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public SPUITabSheet() {
|
||||
super();
|
||||
decorate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Decorate.
|
||||
*/
|
||||
private void decorate() {
|
||||
addStyleName(ValoTheme.TABSHEET_COMPACT_TABBAR);
|
||||
addStyleName(ValoTheme.TABSHEET_FRAMED);
|
||||
}
|
||||
}
|
||||
@@ -1,42 +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.components;
|
||||
|
||||
import com.vaadin.ui.HorizontalLayout;
|
||||
|
||||
/**
|
||||
* Table Horizonatl layout with Style.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class SPUITableHorizonatlLayout {
|
||||
|
||||
private HorizontalLayout tableHorizonatlLayout;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public SPUITableHorizonatlLayout() {
|
||||
tableHorizonatlLayout = new HorizontalLayout();
|
||||
decorate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Decorate.
|
||||
*/
|
||||
private void decorate() {
|
||||
tableHorizonatlLayout.setSpacing(false);
|
||||
tableHorizonatlLayout.setMargin(false);
|
||||
}
|
||||
|
||||
public HorizontalLayout getTableHorizonatlLayout() {
|
||||
return tableHorizonatlLayout;
|
||||
}
|
||||
}
|
||||
@@ -1,83 +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.components;
|
||||
|
||||
import org.eclipse.hawkbit.ui.utils.I18N;
|
||||
import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.SpringContextHelper;
|
||||
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
|
||||
/**
|
||||
* ChangeLog Vertical layout for Target and Distribution.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class SPUIUpdateLogLayout {
|
||||
private final VerticalLayout changeLogLayout;
|
||||
|
||||
/**
|
||||
* Parametric constructor.
|
||||
*
|
||||
* @param changeLogLayout
|
||||
* as layout
|
||||
* @param lastModifiedAt
|
||||
* as Date
|
||||
* @param lastModifiedBy
|
||||
* as string
|
||||
* @param createdAt
|
||||
* as date
|
||||
* @param createdBy
|
||||
* as string
|
||||
*/
|
||||
public SPUIUpdateLogLayout(final VerticalLayout changeLogLayout, final Long lastModifiedAt,
|
||||
final String lastModifiedBy, final Long createdAt, final String createdBy) {
|
||||
this.changeLogLayout = changeLogLayout;
|
||||
changeLogLayout.setSpacing(true);
|
||||
changeLogLayout.setMargin(true);
|
||||
decorate(lastModifiedAt, lastModifiedBy, createdAt, createdBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decorate.
|
||||
*
|
||||
* @param lastModifiedAt
|
||||
* @param lastModifiedBy
|
||||
* @param createdAt
|
||||
* @param createdBy
|
||||
*/
|
||||
private void decorate(final Long lastModifiedAt, final String lastModifiedBy, final Long createdAt,
|
||||
final String createdBy) {
|
||||
final I18N i18n = SpringContextHelper.getBean(I18N.class);
|
||||
changeLogLayout.addComponent(SPUIComponentProvider.createNameValueLabel(i18n.get("label.created.at"),
|
||||
createdAt == null ? "" : SPDateTimeUtil.getFormattedDate(createdAt)));
|
||||
|
||||
changeLogLayout.addComponent(SPUIComponentProvider.createNameValueLabel(i18n.get("label.created.by"),
|
||||
createdBy == null ? "" : createdBy));
|
||||
|
||||
if (null != lastModifiedAt) {
|
||||
changeLogLayout.addComponent(SPUIComponentProvider.createNameValueLabel(i18n.get("label.modified.date"),
|
||||
SPDateTimeUtil.getFormattedDate(lastModifiedAt)));
|
||||
|
||||
changeLogLayout.addComponent(SPUIComponentProvider.createNameValueLabel(i18n.get("label.modified.by"),
|
||||
lastModifiedBy == null ? "" : lastModifiedBy));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* GET Change LogLayout.
|
||||
*
|
||||
* @return VerticalLayout as UI
|
||||
*/
|
||||
public VerticalLayout getChangeLogLayout() {
|
||||
return changeLogLayout;
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
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
|
||||
|
||||
-->
|
||||
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.5.1//EN" "http://google-web-toolkit.googlecode.com/svn/tags/2.5.1/distro-source/core/src/gwt-module.dtd">
|
||||
<module>
|
||||
<!-- Inherit DefaultWidgetSet -->
|
||||
<inherits name="com.vaadin.DefaultWidgetSet"/>
|
||||
|
||||
<inherits name="org.vaadin.alump.distributionbar.gwt.DistributionBarWidgetset" />
|
||||
|
||||
<inherits name="org.eclipse.hawkbit.ui.AppWidgetSet" />
|
||||
|
||||
<inherits name="org.vaadin.peter.contextmenu.ContextmenuWidgetset" />
|
||||
|
||||
<inherits name="org.vaadin.tokenfield.TokenfieldWidgetset" />
|
||||
|
||||
<inherits name="org.vaadin.hene.flexibleoptiongroup.widgetset.FlexibleOptionGroupWidgetset" />
|
||||
|
||||
</module>
|
||||
@@ -1,28 +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.customrenderers.client;
|
||||
|
||||
import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlButtonRenderer;
|
||||
|
||||
import com.vaadin.client.connectors.ButtonRendererConnector;
|
||||
import com.vaadin.shared.ui.Connect;
|
||||
|
||||
/**
|
||||
* A connector for {@link HtmlButtonRenderer}.
|
||||
*
|
||||
*/
|
||||
@Connect(org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlButtonRenderer.class)
|
||||
public class HtmlButtonRendererConnector extends ButtonRendererConnector {
|
||||
private static final long serialVersionUID = 7987417436367399331L;
|
||||
|
||||
@Override
|
||||
public org.eclipse.hawkbit.ui.customrenderers.client.renderers.HtmlButtonRenderer getRenderer() {
|
||||
return (org.eclipse.hawkbit.ui.customrenderers.client.renderers.HtmlButtonRenderer) super.getRenderer();
|
||||
}
|
||||
}
|
||||
@@ -1,31 +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.customrenderers.client;
|
||||
|
||||
import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlLabelRenderer;
|
||||
|
||||
import com.vaadin.client.connectors.AbstractRendererConnector;
|
||||
import com.vaadin.shared.ui.Connect;
|
||||
|
||||
/**
|
||||
*
|
||||
* A connector for {@link HtmlLabelRenderer}.
|
||||
*
|
||||
*/
|
||||
@Connect(org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlLabelRenderer.class)
|
||||
public class HtmlLabelRendererConnector extends AbstractRendererConnector<String> {
|
||||
|
||||
private static final long serialVersionUID = 7697966991925490786L;
|
||||
|
||||
@Override
|
||||
public org.eclipse.hawkbit.ui.customrenderers.client.renderers.HtmlLabelRenderer getRenderer() {
|
||||
return (org.eclipse.hawkbit.ui.customrenderers.client.renderers.HtmlLabelRenderer) super.getRenderer();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,29 +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.customrenderers.client;
|
||||
|
||||
import org.eclipse.hawkbit.ui.customrenderers.renderers.LinkRenderer;
|
||||
|
||||
import com.vaadin.client.connectors.ButtonRendererConnector;
|
||||
import com.vaadin.shared.ui.Connect;
|
||||
|
||||
/**
|
||||
*
|
||||
* A connector for {@link LinkRenderer}.
|
||||
*
|
||||
*/
|
||||
@Connect(org.eclipse.hawkbit.ui.customrenderers.renderers.LinkRenderer.class)
|
||||
public class LinkRendererConnector extends ButtonRendererConnector {
|
||||
private static final long serialVersionUID = 7987417436367399331L;
|
||||
|
||||
@Override
|
||||
public org.eclipse.hawkbit.ui.customrenderers.client.renderers.LinkRenderer getRenderer() {
|
||||
return (org.eclipse.hawkbit.ui.customrenderers.client.renderers.LinkRenderer) super.getRenderer();
|
||||
}
|
||||
}
|
||||
@@ -1,46 +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.customrenderers.client.renderers;
|
||||
|
||||
import com.google.gwt.user.client.ui.Button;
|
||||
import com.vaadin.client.renderers.ButtonRenderer;
|
||||
import com.vaadin.client.ui.VButton;
|
||||
import com.vaadin.client.widget.grid.RendererCellReference;
|
||||
|
||||
/**
|
||||
*
|
||||
* Renders button with provided HTML content.
|
||||
* Used to display button with icons.
|
||||
*
|
||||
*/
|
||||
public class HtmlButtonRenderer extends ButtonRenderer {
|
||||
@Override
|
||||
public void render(RendererCellReference cell, String text, Button button) {
|
||||
if (text != null) {
|
||||
button.setHTML(text);
|
||||
}
|
||||
applystyles(button);
|
||||
// this is to allow the button to disappear, if the text is null
|
||||
button.setVisible(text != null);
|
||||
button.getElement().setId("rollout.action.button.id");
|
||||
}
|
||||
|
||||
private void applystyles(Button button) {
|
||||
button.setStyleName(VButton.CLASSNAME);
|
||||
button.addStyleName(getStyle("tiny"));
|
||||
button.addStyleName(getStyle("borderless"));
|
||||
button.addStyleName(getStyle("icon-only"));
|
||||
button.addStyleName(getStyle("button-no-border"));
|
||||
}
|
||||
|
||||
|
||||
private String getStyle(final String style) {
|
||||
return new StringBuilder(style).append(" ").append(VButton.CLASSNAME).append("-").append(style).toString();
|
||||
}
|
||||
}
|
||||
@@ -1,69 +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.customrenderers.client.renderers;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.vaadin.client.renderers.WidgetRenderer;
|
||||
import com.vaadin.client.ui.VLabel;
|
||||
import com.vaadin.client.widget.grid.RendererCellReference;
|
||||
|
||||
/**
|
||||
*
|
||||
* Renders label with provided value and style.
|
||||
*
|
||||
*/
|
||||
public class HtmlLabelRenderer extends WidgetRenderer<String, VLabel> {
|
||||
|
||||
@Override
|
||||
public VLabel createWidget() {
|
||||
return GWT.create(VLabel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(RendererCellReference cell, String input, VLabel label) {
|
||||
Map<String, String> map = formatInput(input);
|
||||
String value = map.containsKey("value") ? map.get("value") : null;
|
||||
String style = map.containsKey("style") ? map.get("style") : null;
|
||||
String id = map.containsKey("id") ? map.get("id") : null;
|
||||
|
||||
if (value != null) {
|
||||
label.setHTML("<span>&#x" + Integer.toHexString(Integer.parseInt(value)) + ";</span>");
|
||||
} else {
|
||||
label.setHTML("<span></span>");
|
||||
}
|
||||
applyStyle(label, style);
|
||||
label.getElement().setId(id);
|
||||
}
|
||||
|
||||
private void applyStyle(VLabel label, String style) {
|
||||
label.setStyleName(VLabel.CLASSNAME);
|
||||
label.addStyleName(getStyle("small"));
|
||||
label.addStyleName(getStyle("font-icon"));
|
||||
if (style != null) {
|
||||
label.addStyleName(getStyle(style));
|
||||
}
|
||||
}
|
||||
|
||||
private String getStyle(final String style) {
|
||||
return new StringBuilder(style).append(" ").append(VLabel.CLASSNAME).append("-").append(style).toString();
|
||||
}
|
||||
|
||||
private Map<String, String> formatInput(String input) {
|
||||
Map<String, String> details = new HashMap<>();
|
||||
String[] tempData = input.split(",");
|
||||
for (String statusWithCount : tempData) {
|
||||
String[] statusWithCountList = statusWithCount.split(":");
|
||||
details.put(statusWithCountList[0], statusWithCountList[1]);
|
||||
}
|
||||
return details;
|
||||
}
|
||||
}
|
||||
@@ -1,42 +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.customrenderers.client.renderers;
|
||||
|
||||
import com.google.gwt.user.client.ui.Button;
|
||||
import com.vaadin.client.renderers.ButtonRenderer;
|
||||
import com.vaadin.client.ui.VButton;
|
||||
import com.vaadin.client.widget.grid.RendererCellReference;
|
||||
|
||||
/**
|
||||
*
|
||||
* Renders link with provided text.
|
||||
*
|
||||
*/
|
||||
public class LinkRenderer extends ButtonRenderer {
|
||||
@Override
|
||||
public void render(RendererCellReference cell, String text, Button button) {
|
||||
button.setText(text);
|
||||
applystyle(button);
|
||||
// this is to allow the button to disappear, if the text is null
|
||||
button.setVisible(text != null);
|
||||
button.getElement().setId(new StringBuilder("link").append(".").append(text).toString());
|
||||
}
|
||||
|
||||
private void applystyle(Button button) {
|
||||
button.setStyleName(VButton.CLASSNAME);
|
||||
button.addStyleName(getStyle("borderless"));
|
||||
button.addStyleName(getStyle("small"));
|
||||
button.addStyleName(getStyle("on-focus-no-border"));
|
||||
button.addStyleName(getStyle("link"));
|
||||
}
|
||||
|
||||
private String getStyle(final String style) {
|
||||
return new StringBuilder(style).append(" ").append(VButton.CLASSNAME).append("-").append(style).toString();
|
||||
}
|
||||
}
|
||||
@@ -1,37 +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.customrenderers.renderers;
|
||||
|
||||
import com.vaadin.ui.renderers.ButtonRenderer;
|
||||
|
||||
/**
|
||||
*
|
||||
* Renders button with provided HTML content. Used to display button with icons.
|
||||
*
|
||||
*/
|
||||
public class HtmlButtonRenderer extends ButtonRenderer {
|
||||
private static final long serialVersionUID = -1242995370043404892L;
|
||||
|
||||
/**
|
||||
* Intialize button renderer.
|
||||
*/
|
||||
public HtmlButtonRenderer() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Intialize button renderer with {@link RendererClickListener}
|
||||
*
|
||||
* @param listener
|
||||
* RendererClickListener
|
||||
*/
|
||||
public HtmlButtonRenderer(RendererClickListener listener) {
|
||||
super(listener);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user