1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.ui.incub;
35
36 import info.magnolia.icons.MagnoliaIcons;
37 import info.magnolia.ui.theme.ResurfaceTheme;
38
39 import java.util.Collection;
40
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
43
44 import com.vaadin.ui.AbstractOrderedLayout;
45 import com.vaadin.ui.Alignment;
46 import com.vaadin.ui.Button;
47 import com.vaadin.ui.Button.ClickListener;
48 import com.vaadin.ui.Component;
49 import com.vaadin.ui.CustomField;
50 import com.vaadin.ui.HorizontalLayout;
51 import com.vaadin.ui.NativeButton;
52 import com.vaadin.ui.VerticalLayout;
53
54
55
56
57
58
59 public class MultiField<T> extends CustomField<Collection<T>> {
60
61 private static final Logger log = LoggerFactory.getLogger(MultiField.class);
62
63 protected AbstractOrderedLayout root;
64
65 private final Button addButton = new NativeButton();
66
67 private String buttonCaptionAdd = "Add";
68 private String buttonCaptionRemove = "Remove";
69 private String buttonCaptionMoveUp = "Move Up";
70 private String buttonCaptionMoveDown = "Move Down";
71 private boolean isOrderable = true;
72
73 @Override
74 protected Component initContent() {
75
76 root = new VerticalLayout();
77 root.setStyleName("multifield");
78 root.setSpacing(true);
79 root.setMargin(false);
80 root.setWidth(100, Unit.PERCENTAGE);
81 root.setHeight(-1, Unit.PIXELS);
82
83
84 addButton.setCaption(buttonCaptionAdd);
85 addButton.addStyleName("magnoliabutton");
86 addButton.addClickListener((ClickListener) event -> root.addComponent(createEntryComponent(), root.getComponentCount() - 1));
87 root.addComponent(addButton);
88 return root;
89 }
90
91
92
93
94
95
96
97 private Component createEntryComponent() {
98 final HorizontalLayout layout = new HorizontalLayout();
99 layout.setStyleName("controls-wrapper");
100
101
102 final LinkFieldld.html#LinkField">LinkField field = new LinkField();
103 field.setButtonCaptionNew("Select new");
104 field.setButtonCaptionOther("Select another");
105 field.getSelectButton().setDisableOnClick(true);
106 field.setFieldEditable(true);
107 field.setWidth(100, Unit.PERCENTAGE);
108
109 layout.addComponent(field);
110
111
112
113 layout.setWidth(100, Unit.PERCENTAGE);
114
115
116 layout.setExpandRatio(field, 1);
117
118 if (isOrderable()) {
119
120 final Button moveUpButton = new Button(MagnoliaIcons.ARROW2_N);
121 moveUpButton.addStyleNames(ResurfaceTheme.BUTTON_ICON, "inline");
122 moveUpButton.setDescription(buttonCaptionMoveUp);
123
124 moveUpButton.addClickListener((ClickListener) event -> moveUpButton.focus());
125
126
127 final Button moveDownButton = new Button(MagnoliaIcons.ARROW2_S);
128 moveDownButton.addStyleNames(ResurfaceTheme.BUTTON_ICON, "inline");
129 moveDownButton.setDescription(buttonCaptionMoveDown);
130
131 moveDownButton.addClickListener((ClickListener) event -> moveDownButton.focus());
132 layout.addComponents(moveUpButton, moveDownButton);
133
134 layout.setComponentAlignment(moveUpButton, Alignment.MIDDLE_CENTER);
135 layout.setComponentAlignment(moveDownButton, Alignment.MIDDLE_CENTER);
136 }
137
138
139 Button deleteButton = new Button(MagnoliaIcons.CLOSE);
140 deleteButton.addStyleNames(ResurfaceTheme.BUTTON_ICON, "inline");
141 deleteButton.setDescription(buttonCaptionRemove);
142
143
144 layout.addComponents(deleteButton);
145 layout.setComponentAlignment(deleteButton, Alignment.MIDDLE_CENTER);
146
147 return layout;
148 }
149
150 public boolean isOrderable() {
151 return isOrderable;
152 }
153
154 @Override
155 protected void doSetValue(Collection<T> value) {
156
157 }
158
159 @Override
160 public Collection<T> getValue() {
161 return null;
162 }
163 }