| /** |
| * Copyright (c) 2011, 2015 - Lunifera GmbH (Gross Enzersdorf, Austria), 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 v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Florian Pirchner - Initial implementation |
| */ |
| package org.eclipse.osbp.runtime.web.ecview.presentation.vaadin.internal; |
| |
| import java.util.Locale; |
| |
| import org.eclipse.osbp.ecview.core.common.editpart.IElementEditpart; |
| import org.eclipse.osbp.ecview.core.common.editpart.IEmbeddableEditpart; |
| import org.eclipse.osbp.ecview.core.common.editpart.emf.ElementEditpart; |
| import org.eclipse.osbp.ecview.core.common.presentation.IWidgetPresentation; |
| import org.eclipse.osbp.ecview.core.extension.model.extension.YTab; |
| import org.eclipse.osbp.ecview.core.ui.core.editparts.extension.ITabEditpart; |
| import org.eclipse.osbp.ecview.core.ui.core.editparts.extension.presentation.ITabPresentation; |
| import org.eclipse.osbp.runtime.common.i18n.II18nService; |
| import org.eclipse.osbp.runtime.web.ecview.presentation.vaadin.common.AbstractTabPresenter; |
| |
| import com.vaadin.ui.Component; |
| import com.vaadin.ui.ComponentContainer; |
| import com.vaadin.ui.HorizontalLayout; |
| import com.vaadin.ui.TabSheet; |
| import com.vaadin.ui.TabSheet.Tab; |
| |
| /** |
| * This presenter is responsible to render a tab sheet on the given layout. |
| */ |
| public class TabPresentation extends AbstractTabPresenter<Component> implements |
| ITabPresentation<Component> { |
| |
| private Tab tab; |
| private ModelAccess modelAccess; |
| private HorizontalLayout tabContent; |
| |
| /** |
| * The constructor. |
| * |
| * @param editpart |
| * The editpart of that presentation. |
| */ |
| public TabPresentation(IElementEditpart editpart) { |
| super((ITabEditpart) editpart); |
| this.modelAccess = new ModelAccess((YTab) editpart.getModel()); |
| } |
| |
| @Override |
| public Component createWidget(Object parent) { |
| if (tab == null) { |
| TabSheet tabSheet = (TabSheet) parent; |
| |
| YTab yTab = (YTab) getModel(); |
| IEmbeddableEditpart childEditpart = ElementEditpart.getEditpart( |
| getViewContext(), yTab.getEmbeddable()); |
| |
| tabContent = new HorizontalLayout(); |
| tabContent.setSizeFull(); |
| if (childEditpart == null) { |
| tab = tabSheet.addTab(tabContent, "content missing"); |
| return tabContent; |
| } |
| IWidgetPresentation<Component> childPresentation = childEditpart |
| .getPresentation(); |
| |
| Component childContent = childPresentation.createWidget(tabContent); |
| childContent.setSizeFull(); |
| tabContent.addComponent(childContent); |
| tabContent.setExpandRatio(childContent, 1.0f); |
| |
| tab = tabSheet.addTab(tabContent); |
| |
| if (modelAccess.isCssIdValid()) { |
| tab.setId(modelAccess.getCssID()); |
| } else { |
| tab.setId(getEditpart().getId()); |
| } |
| |
| registerAtLocaleChangedService(); |
| |
| applyCaptions(); |
| } |
| return tab.getComponent(); |
| } |
| |
| @Override |
| protected void doUpdateLocale(Locale locale) { |
| // update the captions |
| applyCaptions(); |
| } |
| |
| /** |
| * Applies the labels to the widgets. |
| */ |
| protected void applyCaptions() { |
| II18nService service = getI18nService(); |
| if (service != null && modelAccess.isLabelI18nKeyValid()) { |
| tab.setCaption(service.getValue(modelAccess.getLabelI18nKey(), |
| getLocale())); |
| } else { |
| if (modelAccess.isLabelValid()) { |
| tab.setCaption(modelAccess.getLabel()); |
| } |
| } |
| } |
| |
| @Override |
| public ComponentContainer getWidget() { |
| return tabContent; |
| } |
| |
| @Override |
| public boolean isRendered() { |
| return tab != null; |
| } |
| |
| @Override |
| protected void internalDispose() { |
| try { |
| unrender(); |
| } finally { |
| super.internalDispose(); |
| } |
| } |
| |
| @Override |
| public void unrender() { |
| if (tab != null) { |
| |
| // unbind all active bindings |
| unbind(); |
| |
| unregisterFromLocaleChangedService(); |
| |
| YTab yTab = (YTab) getModel(); |
| IEmbeddableEditpart editpart = ElementEditpart.getEditpart( |
| getViewContext(), yTab.getEmbeddable()); |
| |
| IWidgetPresentation<Component> childPresentation = editpart |
| .getPresentation(); |
| childPresentation.unrender(); |
| |
| tab = null; |
| tabContent = null; |
| } |
| } |
| |
| /** |
| * An internal helper class. |
| */ |
| private static class ModelAccess { |
| private final YTab yTab; |
| |
| public ModelAccess(YTab yTab) { |
| super(); |
| this.yTab = yTab; |
| } |
| |
| /** |
| * @return |
| * @see org.eclipse.osbp.ecview.core.ui.core.model.core.YCssAble#getCssID() |
| */ |
| public String getCssID() { |
| return yTab.getCssID(); |
| } |
| |
| /** |
| * Returns true, if the css id is not null and not empty. |
| * |
| * @return |
| */ |
| public boolean isCssIdValid() { |
| return getCssID() != null && !getCssID().equals(""); |
| } |
| |
| /** |
| * Returns true, if the label is valid. |
| * |
| * @return |
| */ |
| public boolean isLabelValid() { |
| return yTab.getDatadescription() != null |
| && yTab.getDatadescription().getLabel() != null; |
| } |
| |
| /** |
| * Returns the label. |
| * |
| * @return |
| */ |
| public String getLabel() { |
| return yTab.getDatadescription().getLabel(); |
| } |
| |
| /** |
| * Returns true, if the label is valid. |
| * |
| * @return |
| */ |
| public boolean isLabelI18nKeyValid() { |
| return yTab.getDatadescription() != null |
| && yTab.getDatadescription().getLabelI18nKey() != null; |
| } |
| |
| /** |
| * Returns the label. |
| * |
| * @return |
| */ |
| public String getLabelI18nKey() { |
| return yTab.getDatadescription().getLabelI18nKey(); |
| } |
| } |
| } |