| /** |
| * |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| * |
| */ |
| package org.eclipse.osbp.vaaclipse.addons.softwarefactory.welcome; |
| |
| import java.util.Locale; |
| |
| import javax.annotation.PostConstruct; |
| import javax.inject.Inject; |
| |
| import org.eclipse.e4.core.contexts.IEclipseContext; |
| import org.eclipse.e4.ui.model.application.MApplication; |
| import org.eclipse.osbp.ui.api.themes.IThemeResourceService; |
| import org.eclipse.osbp.ui.api.user.IUser; |
| |
| import com.vaadin.server.ClientConnector; |
| import com.vaadin.server.ClientConnector.AttachEvent; |
| import com.vaadin.server.ClientConnector.DetachEvent; |
| import com.vaadin.shared.ui.label.ContentMode; |
| import com.vaadin.ui.AbstractComponent; |
| import com.vaadin.ui.Label; |
| import com.vaadin.ui.VerticalLayout; |
| |
| public class WelcomeView implements IUser.UserLocaleListener, ClientConnector.DetachListener, ClientConnector.AttachListener { |
| |
| private static final long serialVersionUID = 1L; |
| private AbstractComponent label = null; |
| private VerticalLayout parent; |
| private IThemeResourceService themeResourceService; |
| private IUser user; |
| private Locale locale; |
| |
| @Inject |
| public WelcomeView(VerticalLayout parent, IEclipseContext context, MApplication app) { |
| this.parent = parent; |
| this.themeResourceService = context.get(IThemeResourceService.class); |
| this.user = context.get(IUser.class); |
| locale = user.getLocale(); |
| parent.addStyleName("os-welcome"); |
| parent.addAttachListener(this); |
| parent.addDetachListener(this); |
| } |
| |
| @PostConstruct |
| public void render() { |
| renderView(); |
| } |
| |
| private void renderView() { |
| if (label != null) { |
| parent.removeComponent(label); |
| } |
| label = new Label(themeResourceService.getThemeResourceHTML("WelcomeTRANSLATABLE", locale), ContentMode.HTML); |
| label.setSizeFull(); |
| parent.addComponent(label); |
| parent.setMargin(true); |
| } |
| |
| @Override |
| public void attach(AttachEvent event) { |
| user.addUserLocaleListener(this); |
| } |
| |
| @Override |
| public void detach(DetachEvent event) { |
| user.removeUserLocaleListener(this); |
| } |
| |
| @Override |
| public void localeChanged(Locale locale) { |
| this.locale = locale; |
| parent.removeAllComponents(); |
| renderView(); |
| } |
| } |