| /** |
| * Copyright (c) 2011, 2014 - 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 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: |
| * Florian Pirchner - Initial implementation |
| */ |
| |
| package org.eclipse.osbp.runtime.web.ecview.presentation.vaadin.tests.ui.samples; |
| |
| import java.util.Date; |
| import java.util.Locale; |
| |
| import org.eclipse.osbp.ecview.core.common.context.ContextException; |
| import org.eclipse.osbp.ecview.core.common.context.IViewContext; |
| import org.eclipse.osbp.ecview.core.common.model.binding.YBindingSet; |
| import org.eclipse.osbp.ecview.core.common.model.core.YView; |
| import org.eclipse.osbp.ecview.core.extension.model.datatypes.ExtDatatypesFactory; |
| import org.eclipse.osbp.ecview.core.extension.model.datatypes.YDateTimeDatatype; |
| import org.eclipse.osbp.ecview.core.extension.model.datatypes.YDateTimeFormat; |
| import org.eclipse.osbp.ecview.core.extension.model.extension.YButton; |
| import org.eclipse.osbp.ecview.core.extension.model.extension.YDateTime; |
| import org.eclipse.osbp.ecview.core.extension.model.extension.YHorizontalLayout; |
| import org.eclipse.osbp.ecview.core.extension.model.extension.YTextField; |
| import org.eclipse.osbp.ecview.core.extension.model.extension.YVerticalLayout; |
| import org.eclipse.osbp.ecview.core.extension.model.extension.listener.YButtonClickListener; |
| import org.eclipse.osbp.ecview.core.extension.model.extension.util.SimpleExtensionModelFactory; |
| import org.eclipse.osbp.runtime.web.ecview.presentation.vaadin.VaadinRenderer; |
| |
| import com.vaadin.ui.CssLayout; |
| import com.vaadin.ui.CustomComponent; |
| import com.vaadin.ui.Label; |
| |
| public class EnabledSample extends CustomComponent { |
| |
| private final SimpleExtensionModelFactory factory = new SimpleExtensionModelFactory(); |
| |
| private CssLayout layout; |
| |
| private YView yView; |
| |
| private YBindingSet yBindingSet; |
| |
| private YVerticalLayout yLayout; |
| |
| private IViewContext context; |
| |
| public EnabledSample() { |
| layout = new CssLayout(); |
| setCompositionRoot(layout); |
| |
| init(); |
| } |
| |
| protected void init() { |
| |
| Locale.setDefault(Locale.GERMANY); |
| |
| yView = factory.createView(); |
| yLayout = factory.createVerticalLayout(); |
| yView.setContent(yLayout); |
| |
| yBindingSet = yView.getOrCreateBindingSet(); |
| |
| row2(); |
| |
| // render now, fill in values later |
| // to avoid overwriting values with bindings to empty fields |
| VaadinRenderer renderer = new VaadinRenderer(); |
| try { |
| context = renderer.render(layout, yView, null); |
| } catch (ContextException e) { |
| layout.addComponent(new Label(e.toString())); |
| } |
| } |
| |
| public void row2() { |
| // test row 2 |
| YHorizontalLayout row2 = factory.createHorizontalLayout(); |
| yLayout.addElement(row2); |
| |
| final YTextField yText = factory.createTextField(); |
| yText.setLabel("text"); |
| yText.setValue("Huhu"); |
| row2.addElement(yText); |
| |
| final YDateTime yDate = factory.createDateTime(); |
| yDate.setLabel("time"); |
| yDate.setValue(new Date()); |
| row2.addElement(yDate); |
| YDateTimeDatatype yDt2_1 = createDateTimeDatatype(); |
| yDt2_1.setFormat(YDateTimeFormat.TIME); |
| yDate.setDatatype(yDt2_1); |
| |
| YButton yLocaleSwitcher = factory.createButton(); |
| yLocaleSwitcher.setLabel("enable"); |
| row2.addElement(yLocaleSwitcher); |
| yLocaleSwitcher.addClickListener(new YButtonClickListener() { |
| @Override |
| public void clicked(YButton yButton) { |
| yText.setEnabled(!yText.isEnabled()); |
| yDate.setEnabled(!yDate.isEnabled()); |
| } |
| }); |
| } |
| |
| protected YDateTimeDatatype createDateTimeDatatype() { |
| return ExtDatatypesFactory.eINSTANCE.createYDateTimeDatatype(); |
| } |
| |
| } |