Advertisement
Ladies_Man

custom radio buttons. still need to fix outer la

Mar 10th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.10 KB | None | 0 0
  1.       .radioButton {
  2.         font-size: $my-font-size-small;
  3.         font-weight: 600;
  4.         color: #0055A6;
  5.         background-color: white;
  6.         display: inline-block;
  7.         border: 1px solid #cccccc;
  8.         border-radius: 2px;
  9.         padding: 10px;
  10.         margin: 10px;
  11.         height: 110px;
  12.         cursor: pointer;
  13.  
  14.         .stateActive {
  15.           border: 1px solid #0055A6;
  16.         }
  17.  
  18.         .icon {
  19.  
  20.         }
  21.  
  22.         .description {
  23.           font-size: $my-font-size-small;
  24.           font-weight: 400;
  25.           color: #999999;
  26.           white-space: pre-wrap;
  27.           width: 150px;
  28.           text-align: center;
  29.         }
  30.       }
  31.  
  32.       .radioButton:hover {
  33.         border: 1px solid #4396ea;
  34.       }
  35.  
  36.  
  37.  
  38.  
  39. package ru.pochta.abon.cabinet.ui.layout;
  40.  
  41. import com.vaadin.ui.*;
  42.  
  43. import javax.annotation.PostConstruct;
  44. import java.util.ArrayList;
  45. import java.util.List;
  46.  
  47. public abstract class CustomRadioButtonLayout extends CssLayout{
  48.  
  49.     private List<RadioButtonLayout> radioButtonLayouts;
  50.     private Object activeValue;
  51.  
  52.     List<String> icons;
  53.     List<String> captions;
  54.     List<String> descriptions;
  55.     List<Object> values;
  56.  
  57.     @PostConstruct
  58.     void init() {
  59.         initData();
  60.         fillData();
  61.         initLayout();
  62.     }
  63.  
  64.     void initData() {
  65.         icons = new ArrayList<>();
  66.         captions = new ArrayList<>();
  67.         descriptions = new ArrayList<>();
  68.         values = new ArrayList<>();
  69.  
  70.         radioButtonLayouts = new ArrayList<>();
  71.     }
  72.  
  73.     abstract void fillData();
  74.  
  75.     void initLayout() {
  76.         HorizontalLayout layout = new HorizontalLayout();
  77.         layout.addStyleName("radioButton");
  78.  
  79.         for (int i = 0; i < captions.size(); i++) {
  80.             RadioButtonLayout radioButtonLayout = new RadioButtonLayout(
  81.                     icons.get(i),
  82.                     captions.get(i),
  83.                     descriptions.get(i),
  84.                     values.get(i));
  85.  
  86.             layout.addComponent(radioButtonLayout);
  87.             layout.setComponentAlignment(radioButtonLayout, Alignment.MIDDLE_CENTER);
  88.         }
  89.  
  90.         this.addComponent(layout);
  91.     }
  92.  
  93.     public Object getActiveValue() {
  94.         return activeValue;
  95.     }
  96.  
  97.  
  98.  
  99.     class RadioButtonLayout extends VerticalLayout {
  100.  
  101.         RadioButtonLayout(String pathToIcon, String caption, String description, Object value) {
  102.             this.addStyleName("radioButton");
  103.  
  104.             Component icon = new Label(pathToIcon);
  105.             this.addComponent(icon);
  106.             this.setComponentAlignment(icon, Alignment.MIDDLE_CENTER);
  107.  
  108.             Component cap = new Label(caption);
  109.             this.addComponent(cap);
  110.             this.setComponentAlignment(cap, Alignment.MIDDLE_CENTER);
  111.  
  112.             if (!description.isEmpty()) {
  113.                 Component descr = new Label(description);
  114.                 descr.setPrimaryStyleName("description");
  115.  
  116.                 this.addComponent(descr);
  117.                 this.setComponentAlignment(descr, Alignment.MIDDLE_CENTER);
  118.             }
  119.  
  120.             this.addLayoutClickListener(layoutClickEvent -> {
  121.                 radioButtonLayouts.forEach(buttonLayout -> buttonLayout.removeStyleName("stateActive"));
  122.                 this.addStyleName("stateActive");
  123.  
  124.                 activeValue = value;
  125.             });
  126.  
  127.             radioButtonLayouts.add(this);
  128.         }
  129.     }
  130. }
  131.  
  132.  
  133.  
  134. package ru.pochta.abon.cabinet.ui.layout;
  135.  
  136. import com.vaadin.spring.annotation.SpringComponent;
  137. import com.vaadin.spring.annotation.ViewScope;
  138. import org.springframework.beans.factory.annotation.Autowired;
  139. import org.springframework.context.MessageSource;
  140. import ru.pochta.abon.cabinet.container.SessionContainer;
  141. import ru.pochta.abon.library.dto.abonClient.enumeration.ClientTypeEnum;
  142.  
  143. @SpringComponent
  144. @ViewScope
  145. public class ClientTypeLayout extends CustomRadioButtonLayout {
  146.  
  147.     @Autowired
  148.     private SessionContainer sessionContainer;
  149.  
  150.     @Autowired
  151.     private MessageSource messageSource;
  152.  
  153.     @Override
  154.     void fillData() {
  155.         icons.add("");
  156.         captions.add(messageSource.getMessage("clientTypeLayout.person", null, sessionContainer.getLocale()));
  157.         descriptions.add("");
  158.         values.add(ClientTypeEnum.PERSON.getId());
  159.  
  160.         icons.add("");
  161.         captions.add(messageSource.getMessage("clientTypeLayout.organisation", null, sessionContainer.getLocale()));
  162.         descriptions.add("");
  163.         values.add(ClientTypeEnum.ORGANIZATION.getId());
  164.     }
  165. }
  166.  
  167.  
  168.  
  169.  
  170. package ru.pochta.abon.cabinet.ui.layout;
  171.  
  172. import com.vaadin.spring.annotation.SpringComponent;
  173. import com.vaadin.spring.annotation.ViewScope;
  174. import org.springframework.beans.factory.annotation.Autowired;
  175. import org.springframework.context.MessageSource;
  176. import ru.pochta.abon.cabinet.container.SessionContainer;
  177. import ru.pochta.abon.library.dto.abonClient.enumeration.PaymentMethodEnum;
  178.  
  179. @SpringComponent
  180. @ViewScope
  181. public class PaymentMethodLayout extends CustomRadioButtonLayout{
  182.  
  183.     @Autowired
  184.     private SessionContainer sessionContainer;
  185.  
  186.     @Autowired
  187.     private MessageSource messageSource;
  188.  
  189.     @Override
  190.     void fillData() {
  191.         icons.add("");
  192.         captions.add(messageSource.getMessage("paymentMethodLayout.cashless", null, sessionContainer.getLocale()));
  193.         descriptions.add(messageSource.getMessage("paymentMethodLayout.cashless.description", null, sessionContainer.getLocale()));
  194.         values.add(PaymentMethodEnum.CASHLESS.getId());
  195.  
  196.         icons.add("");
  197.         captions.add(messageSource.getMessage("paymentMethodLayout.cash", null, sessionContainer.getLocale()));
  198.         descriptions.add(messageSource.getMessage("paymentMethodLayout.cash.description", null, sessionContainer.getLocale()));
  199.         values.add(PaymentMethodEnum.CASH.getId());
  200.  
  201.         icons.add("");
  202.         captions.add(messageSource.getMessage("paymentMethodLayout.billing", null, sessionContainer.getLocale()));
  203.         descriptions.add(messageSource.getMessage("paymentMethodLayout.billing.description", null, sessionContainer.getLocale()));
  204.  
  205.         //TODO we only have 2 payment methods in enum
  206.         values.add(3L);
  207.     }
  208. }
  209.  
  210.  
  211.  
  212. clientTypeLayout.person=Физическое лицо
  213. clientTypeLayout.organisation=Юридическое лицо
  214.  
  215. paymentMethodLayout.cashless=Картой
  216. paymentMethodLayout.cashless.description=онлайн оплата через сайт
  217. paymentMethodLayout.cash=Наличными
  218. paymentMethodLayout.cash.description=в почтовом отделении    по номеру заявки
  219. paymentMethodLayout.billing=По счету
  220. paymentMethodLayout.billing.description=бланк можно распечатать из списка заявлений
  221.  
  222.  
  223.  
  224. clientTypeLayout.person=Individual
  225. clientTypeLayout.organisation=Legal entity
  226.  
  227. paymentMethodLayout.cashless=Cashless
  228. paymentMethodLayout.cashless.description=online payment via web site
  229. paymentMethodLayout.cash=Cash
  230. paymentMethodLayout.cash.description=in post office by claim number
  231. paymentMethodLayout.billing=Billing
  232. paymentMethodLayout.billing.description=form can be printed out from the list of claims
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement