use of com.vaadin.v7.ui.CheckBox in project CodenameOne by codenameone.
the class StringPickerSample method testStringPicker.
private void testStringPicker() {
Form hi = new Form("Hi World", BoxLayout.y());
Picker languagePicker = new Picker();
languagePicker.setName("LanguagePicker");
languagePicker.setType(Display.PICKER_TYPE_STRINGS);
languagePicker.setStrings("Italian", "English", "German");
languagePicker.setSelectedString("English");
languagePicker.addActionListener((ev) -> {
Log.p("Action Event fired");
String newLanguage = languagePicker.getSelectedString();
if (newLanguage != null && newLanguage.length() > 0) {
Log.p("Language selected: " + newLanguage);
}
});
Picker datePicker = new Picker();
datePicker.setType(Display.PICKER_TYPE_DATE);
Picker timePicker = new Picker();
timePicker.setType(Display.PICKER_TYPE_TIME);
Picker dateTimePicker = new Picker();
dateTimePicker.setType(Display.PICKER_TYPE_DATE_AND_TIME);
Picker durationPicker = new Picker();
durationPicker.setType(Display.PICKER_TYPE_DURATION);
Picker durationHoursPicker = new Picker();
durationHoursPicker.setType(Display.PICKER_TYPE_DURATION_HOURS);
Picker durationMinutesPicker = new Picker();
durationMinutesPicker.setType(Display.PICKER_TYPE_DURATION_MINUTES);
Picker calendarPicker = new Picker();
calendarPicker.setType(Display.PICKER_TYPE_CALENDAR);
CheckBox lightweight = new CheckBox("LightWeight");
lightweight.setSelected(languagePicker.isUseLightweightPopup());
lightweight.addActionListener(e -> {
languagePicker.setUseLightweightPopup(lightweight.isSelected());
datePicker.setUseLightweightPopup(lightweight.isSelected());
timePicker.setUseLightweightPopup(lightweight.isSelected());
dateTimePicker.setUseLightweightPopup(lightweight.isSelected());
durationPicker.setUseLightweightPopup(lightweight.isSelected());
durationHoursPicker.setUseLightweightPopup(lightweight.isSelected());
durationMinutesPicker.setUseLightweightPopup(lightweight.isSelected());
calendarPicker.setUseLightweightPopup(lightweight.isSelected());
});
TextField tf = new TextField();
createFocusChain(tf, languagePicker, datePicker, timePicker, lightweight, dateTimePicker, durationPicker, durationHoursPicker, durationMinutesPicker, calendarPicker);
hi.add(tf);
hi.add(languagePicker);
hi.add(datePicker);
hi.add(timePicker);
hi.add(lightweight);
hi.add(dateTimePicker);
hi.add(durationPicker);
hi.add(durationHoursPicker);
hi.add(durationMinutesPicker);
hi.add(calendarPicker);
PickerComponent gender = PickerComponent.createStrings("Male", "Female", "Other", "Don't ask me").label("Gender");
gender.getPicker().setUseLightweightPopup(true);
PickerComponent date = PickerComponent.createDate(new Date()).label("Birthday");
date.getPicker().setUseLightweightPopup(true);
hi.add(gender).add(date);
hi.add(new SpanLabel("Date Time between July 7 and July 12 2019"));
Picker rangePicker1 = new Picker();
rangePicker1.setType(Display.PICKER_TYPE_DATE_AND_TIME);
System.out.println("Start date " + newDate(119, 6, 7));
rangePicker1.setStartDate(newDate(119, 6, 7));
rangePicker1.setEndDate(newDate(119, 6, 12));
hi.add(rangePicker1);
hi.add(new SpanLabel("Date Time between July 7 and July 12 2019 between 8am and 11am"));
rangePicker1 = new Picker();
rangePicker1.setType(Display.PICKER_TYPE_DATE_AND_TIME);
System.out.println("Start date " + newDate(119, 6, 7));
rangePicker1.setStartDate(newDate(119, 6, 7));
rangePicker1.setEndDate(newDate(119, 6, 12));
rangePicker1.setHourRange(8, 11);
hi.add(rangePicker1);
hi.add(new SpanLabel("Date Time between July 7 and July 12 2019 between 8am and 11am, with current time at 9am"));
rangePicker1 = new Picker();
rangePicker1.setType(Display.PICKER_TYPE_DATE_AND_TIME);
System.out.println("Start date " + newDate(119, 6, 7));
rangePicker1.setStartDate(newDate(119, 6, 7));
rangePicker1.setEndDate(newDate(119, 6, 12));
rangePicker1.setHourRange(8, 11);
rangePicker1.setDate(newDate(119, 6, 8, 9));
hi.add(rangePicker1);
hi.add(new SpanLabel("Date Time with current time at 9am"));
rangePicker1 = new Picker();
rangePicker1.setType(Display.PICKER_TYPE_DATE_AND_TIME);
rangePicker1.setDate(newDate(118, 6, 8, 9));
hi.add(rangePicker1);
hi.show();
}
use of com.vaadin.v7.ui.CheckBox in project CodenameOne by codenameone.
the class Table method createCell.
/**
* Creates a cell based on the given value
*
* @param value the new value object
* @param row row number, -1 for the header rows
* @param column column number
* @param editable true if the cell is editable
* @return cell component instance
*/
protected Component createCell(Object value, int row, final int column, boolean editable) {
if (row == -1) {
Button header = new Button((String) value, getUIID() + "Header");
header.getAllStyles().setAlignment(titleAlignment);
header.setTextPosition(LEFT);
if (isSortSupported()) {
header.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Comparator cmp = createColumnSortComparator(column);
if (cmp == null) {
return;
}
if (column == sortedColumn) {
ascending = !ascending;
} else {
sortedColumn = column;
ascending = false;
}
if (model instanceof SortableTableModel) {
model = ((SortableTableModel) model).getUnderlying();
}
setModel(new SortableTableModel(sortedColumn, ascending, model, cmp));
}
});
if (sortedColumn == column) {
if (ascending) {
FontImage.setMaterialIcon(header, FontImage.MATERIAL_ARROW_DROP_UP);
} else {
FontImage.setMaterialIcon(header, FontImage.MATERIAL_ARROW_DROP_DOWN);
}
}
}
return header;
}
int constraint = TextArea.ANY;
Constraint validation = null;
if (isAbstractTableModel()) {
Class type = ((AbstractTableModel) model).getCellType(row, column);
if (type == Boolean.class) {
CheckBox cell = new CheckBox();
cell.setSelected(Util.toBooleanValue(value));
cell.setUIID(getUIID() + "Cell");
cell.setEnabled(editable);
return cell;
}
if (editable && (type == null || type == String.class)) {
String[] multiChoice = ((AbstractTableModel) model).getMultipleChoiceOptions(row, column);
if (multiChoice != null) {
Picker cell = new Picker();
cell.setStrings(multiChoice);
if (value != null) {
cell.setSelectedString((String) value);
}
cell.setUIID(getUIID() + "Cell");
return cell;
}
}
if (editable && type == Date.class) {
Picker cell = new Picker();
cell.setType(Display.PICKER_TYPE_DATE);
if (value != null) {
cell.setDate((Date) value);
}
cell.setUIID(getUIID() + "Cell");
return cell;
}
if (type == Integer.class || type == Long.class || type == Short.class || type == Byte.class) {
constraint = TextArea.NUMERIC;
} else {
if (type == Float.class || type == Double.class) {
constraint = TextArea.DECIMAL;
}
}
if (((AbstractTableModel) model).getValidator() != null) {
validation = ((AbstractTableModel) model).getValidationConstraint(row, column);
}
}
if (editable) {
TextField cell = new TextField(value == null ? "" : "" + value, -1);
cell.setConstraint(constraint);
cell.setLeftAndRightEditingTrigger(false);
cell.setUIID(getUIID() + "Cell");
if (validation != null) {
Validator v = ((AbstractTableModel) model).getValidator();
v.addConstraint(cell, validation);
}
return cell;
}
Label cell = new Label(value == null ? "" : "" + value);
cell.setUIID(getUIID() + "Cell");
cell.getUnselectedStyle().setAlignment(cellAlignment);
cell.getSelectedStyle().setAlignment(cellAlignment);
cell.setFocusable(true);
return cell;
}
use of com.vaadin.v7.ui.CheckBox in project CodenameOne by codenameone.
the class LazyValueC method createComponent.
private Component createComponent(DataInputStream in, Container parent, Container root, Resources res, Hashtable componentListeners, EmbeddedContainer embedded) throws Exception {
String name = in.readUTF();
int property = in.readInt();
// special case for the base form
if (property == PROPERTY_BASE_FORM) {
String baseFormName = name;
initBaseForm(baseFormName);
if (!ignorBaseForm) {
Form base = (Form) createContainer(res, baseFormName);
Container destination = (Container) findByName("destination", base);
// try finding an appropriate empty container if no "fixed" destination is defined
if (destination == null) {
destination = findEmptyContainer(base.getContentPane());
if (destination == null) {
System.out.println("Couldn't find appropriate 'destination' container in base form: " + baseFormName);
return null;
}
}
root = base;
Component cmp = createComponent(in, destination, root, res, componentListeners, embedded);
if (destination.getLayout() instanceof BorderLayout) {
destination.addComponent(BorderLayout.CENTER, cmp);
} else {
destination.addComponent(cmp);
}
return root;
} else {
name = in.readUTF();
property = in.readInt();
}
}
Component cmp = createComponentType(name);
if (componentListeners != null) {
Object listeners = componentListeners.get(name);
if (listeners != null) {
if (listeners instanceof Vector) {
Vector v = (Vector) listeners;
for (int iter = 0; iter < v.size(); iter++) {
bindListenerToComponent(cmp, v.elementAt(iter));
}
} else {
bindListenerToComponent(cmp, listeners);
}
}
}
Component actualLead = cmp;
if (actualLead instanceof Container) {
Container cnt = (Container) actualLead;
actualLead = cnt.getLeadComponent();
if (actualLead == null) {
actualLead = cmp;
}
}
if (actualLead instanceof Button) {
ActionListener l = getFormListenerInstance(root, embedded);
if (l != null) {
((Button) actualLead).addActionListener(l);
}
} else {
if (actualLead instanceof TextArea) {
ActionListener l = getFormListenerInstance(root, embedded);
if (l != null) {
((TextArea) actualLead).addActionListener(l);
}
} else {
if (actualLead instanceof List) {
ActionListener l = getFormListenerInstance(root, embedded);
if (l != null) {
((List) actualLead).addActionListener(l);
}
} else {
if (actualLead instanceof ContainerList) {
ActionListener l = getFormListenerInstance(root, embedded);
if (l != null) {
((ContainerList) actualLead).addActionListener(l);
}
} else {
if (actualLead instanceof com.codename1.ui.Calendar) {
ActionListener l = getFormListenerInstance(root, embedded);
if (l != null) {
((com.codename1.ui.Calendar) actualLead).addActionListener(l);
}
}
}
}
}
}
cmp.putClientProperty(TYPE_KEY, name);
if (root == null) {
root = (Container) cmp;
}
while (property != -1) {
modifyingProperty(cmp, property);
switch(property) {
case PROPERTY_CUSTOM:
String customPropertyName = in.readUTF();
modifyingCustomProperty(cmp, customPropertyName);
boolean isNull = in.readBoolean();
if (isNull) {
cmp.setPropertyValue(customPropertyName, null);
break;
}
boolean cl = cmp instanceof ContainerList;
String[] propertyNames = cmp.getPropertyNames();
for (int iter = 0; iter < propertyNames.length; iter++) {
if (propertyNames[iter].equals(customPropertyName)) {
Class type = cmp.getPropertyTypes()[iter];
String[] typeNames = cmp.getPropertyTypeNames();
String typeName = null;
if (typeNames != null && typeNames.length > iter) {
typeName = typeNames[iter];
}
Object value = readCustomPropertyValue(in, type, typeName, res, propertyNames[iter]);
if (cl && customPropertyName.equals("ListItems") && setListModel((ContainerList) cmp)) {
break;
}
cmp.setPropertyValue(customPropertyName, value);
break;
}
}
break;
case PROPERTY_EMBED:
root.putClientProperty(EMBEDDED_FORM_FLAG, "");
((EmbeddedContainer) cmp).setEmbed(in.readUTF());
Container embed = createContainer(res, ((EmbeddedContainer) cmp).getEmbed(), (EmbeddedContainer) cmp);
if (embed != null) {
if (embed instanceof Form) {
embed = formToContainer((Form) embed);
}
((EmbeddedContainer) cmp).addComponent(BorderLayout.CENTER, embed);
// this isn't exactly the "right thing" but its the best we can do to make all
// use cases work
beforeShowContainer(embed);
postShowContainer(embed);
}
break;
case PROPERTY_TOGGLE_BUTTON:
((Button) cmp).setToggle(in.readBoolean());
break;
case PROPERTY_RADIO_GROUP:
((RadioButton) cmp).setGroup(in.readUTF());
break;
case PROPERTY_SELECTED:
boolean isSelected = in.readBoolean();
if (cmp instanceof RadioButton) {
((RadioButton) cmp).setSelected(isSelected);
} else {
((CheckBox) cmp).setSelected(isSelected);
}
break;
case PROPERTY_SCROLLABLE_X:
((Container) cmp).setScrollableX(in.readBoolean());
break;
case PROPERTY_SCROLLABLE_Y:
((Container) cmp).setScrollableY(in.readBoolean());
break;
case PROPERTY_TENSILE_DRAG_ENABLED:
cmp.setTensileDragEnabled(in.readBoolean());
break;
case PROPERTY_TACTILE_TOUCH:
cmp.setTactileTouch(in.readBoolean());
break;
case PROPERTY_SNAP_TO_GRID:
cmp.setSnapToGrid(in.readBoolean());
break;
case PROPERTY_FLATTEN:
cmp.setFlatten(in.readBoolean());
break;
case PROPERTY_TEXT:
if (cmp instanceof Label) {
((Label) cmp).setText(in.readUTF());
} else {
((TextArea) cmp).setText(in.readUTF());
}
break;
case PROPERTY_TEXT_MAX_LENGTH:
((TextArea) cmp).setMaxSize(in.readInt());
break;
case PROPERTY_TEXT_CONSTRAINT:
((TextArea) cmp).setConstraint(in.readInt());
if (cmp instanceof TextField) {
int cons = ((TextArea) cmp).getConstraint();
if ((cons & TextArea.NUMERIC) == TextArea.NUMERIC) {
((TextField) cmp).setInputModeOrder(new String[] { "123" });
}
}
break;
case PROPERTY_ALIGNMENT:
if (cmp instanceof Label) {
((Label) cmp).setAlignment(in.readInt());
} else {
((TextArea) cmp).setAlignment(in.readInt());
}
break;
case PROPERTY_TEXT_AREA_GROW:
((TextArea) cmp).setGrowByContent(in.readBoolean());
break;
case PROPERTY_LAYOUT:
Layout layout = null;
switch(in.readShort()) {
case LAYOUT_BORDER_LEGACY:
layout = new BorderLayout();
break;
case LAYOUT_BORDER_ANOTHER_LEGACY:
{
BorderLayout b = new BorderLayout();
if (in.readBoolean()) {
b.defineLandscapeSwap(BorderLayout.NORTH, in.readUTF());
}
if (in.readBoolean()) {
b.defineLandscapeSwap(BorderLayout.EAST, in.readUTF());
}
if (in.readBoolean()) {
b.defineLandscapeSwap(BorderLayout.WEST, in.readUTF());
}
if (in.readBoolean()) {
b.defineLandscapeSwap(BorderLayout.SOUTH, in.readUTF());
}
if (in.readBoolean()) {
b.defineLandscapeSwap(BorderLayout.CENTER, in.readUTF());
}
layout = b;
break;
}
case LAYOUT_BORDER:
{
BorderLayout b = new BorderLayout();
if (in.readBoolean()) {
b.defineLandscapeSwap(BorderLayout.NORTH, in.readUTF());
}
if (in.readBoolean()) {
b.defineLandscapeSwap(BorderLayout.EAST, in.readUTF());
}
if (in.readBoolean()) {
b.defineLandscapeSwap(BorderLayout.WEST, in.readUTF());
}
if (in.readBoolean()) {
b.defineLandscapeSwap(BorderLayout.SOUTH, in.readUTF());
}
if (in.readBoolean()) {
b.defineLandscapeSwap(BorderLayout.CENTER, in.readUTF());
}
b.setAbsoluteCenter(in.readBoolean());
layout = b;
break;
}
case LAYOUT_BOX_X:
layout = new BoxLayout(BoxLayout.X_AXIS);
break;
case LAYOUT_BOX_Y:
layout = new BoxLayout(BoxLayout.Y_AXIS);
break;
case LAYOUT_FLOW_LEGACY:
layout = new FlowLayout();
break;
case LAYOUT_FLOW:
FlowLayout f = new FlowLayout();
f.setFillRows(in.readBoolean());
f.setAlign(in.readInt());
f.setValign(in.readInt());
layout = f;
break;
case LAYOUT_LAYERED:
layout = new LayeredLayout();
break;
case LAYOUT_GRID:
layout = new GridLayout(in.readInt(), in.readInt());
break;
case LAYOUT_TABLE:
layout = new TableLayout(in.readInt(), in.readInt());
break;
}
((Container) cmp).setLayout(layout);
break;
case PROPERTY_TAB_PLACEMENT:
((Tabs) cmp).setTabPlacement(in.readInt());
break;
case PROPERTY_TAB_TEXT_POSITION:
((Tabs) cmp).setTabTextPosition(in.readInt());
break;
case PROPERTY_PREFERRED_WIDTH:
cmp.setPreferredW(in.readInt());
break;
case PROPERTY_PREFERRED_HEIGHT:
cmp.setPreferredH(in.readInt());
break;
case PROPERTY_UIID:
cmp.setUIID(in.readUTF());
break;
case PROPERTY_DIALOG_UIID:
((Dialog) cmp).setDialogUIID(in.readUTF());
break;
case PROPERTY_DISPOSE_WHEN_POINTER_OUT:
((Dialog) cmp).setDisposeWhenPointerOutOfBounds(in.readBoolean());
break;
case PROPERTY_CLOUD_BOUND_PROPERTY:
cmp.setCloudBoundProperty(in.readUTF());
break;
case PROPERTY_CLOUD_DESTINATION_PROPERTY:
cmp.setCloudDestinationProperty(in.readUTF());
break;
case PROPERTY_DIALOG_POSITION:
String pos = in.readUTF();
if (pos.length() > 0) {
((Dialog) cmp).setDialogPosition(pos);
}
break;
case PROPERTY_FOCUSABLE:
cmp.setFocusable(in.readBoolean());
break;
case PROPERTY_ENABLED:
cmp.setEnabled(in.readBoolean());
break;
case PROPERTY_SCROLL_VISIBLE:
cmp.setScrollVisible(in.readBoolean());
break;
case PROPERTY_ICON:
((Label) cmp).setIcon(res.getImage(in.readUTF()));
break;
case PROPERTY_ROLLOVER_ICON:
((Button) cmp).setRolloverIcon(res.getImage(in.readUTF()));
break;
case PROPERTY_PRESSED_ICON:
((Button) cmp).setPressedIcon(res.getImage(in.readUTF()));
break;
case PROPERTY_DISABLED_ICON:
((Button) cmp).setDisabledIcon(res.getImage(in.readUTF()));
break;
case PROPERTY_GAP:
((Label) cmp).setGap(in.readInt());
break;
case PROPERTY_VERTICAL_ALIGNMENT:
if (cmp instanceof TextArea) {
((TextArea) cmp).setVerticalAlignment(in.readInt());
} else {
((Label) cmp).setVerticalAlignment(in.readInt());
}
break;
case PROPERTY_TEXT_POSITION:
((Label) cmp).setTextPosition(in.readInt());
break;
case PROPERTY_CLIENT_PROPERTIES:
int count = in.readInt();
StringBuilder sb = new StringBuilder();
for (int iter = 0; iter < count; iter++) {
String k = in.readUTF();
String v = in.readUTF();
cmp.putClientProperty(k, v);
sb.append(k);
if (iter < count - 1) {
sb.append(",");
}
}
cmp.putClientProperty("cn1$Properties", sb.toString());
break;
case PROPERTY_NAME:
String componentName = in.readUTF();
cmp.setName(componentName);
root.putClientProperty("%" + componentName + "%", cmp);
break;
case PROPERTY_LAYOUT_CONSTRAINT:
if (parent.getLayout() instanceof BorderLayout) {
cmp.putClientProperty("layoutConstraint", in.readUTF());
} else {
TableLayout tl = (TableLayout) parent.getLayout();
TableLayout.Constraint con = tl.createConstraint(in.readInt(), in.readInt());
con.setHeightPercentage(in.readInt());
con.setWidthPercentage(in.readInt());
con.setHorizontalAlign(in.readInt());
con.setHorizontalSpan(in.readInt());
con.setVerticalAlign(in.readInt());
con.setVerticalSpan(in.readInt());
cmp.putClientProperty("layoutConstraint", con);
}
break;
case PROPERTY_TITLE:
((Form) cmp).setTitle(in.readUTF());
break;
case PROPERTY_COMPONENTS:
int componentCount = in.readInt();
if (cmp instanceof Tabs) {
for (int iter = 0; iter < componentCount; iter++) {
String tab = in.readUTF();
Component child = createComponent(in, (Container) cmp, root, res, componentListeners, embedded);
((Tabs) cmp).addTab(tab, child);
}
} else {
for (int iter = 0; iter < componentCount; iter++) {
Component child = createComponent(in, (Container) cmp, root, res, componentListeners, embedded);
Object con = child.getClientProperty("layoutConstraint");
if (con != null) {
((Container) cmp).addComponent(con, child);
} else {
((Container) cmp).addComponent(child);
}
}
}
break;
case PROPERTY_COLUMNS:
((TextArea) cmp).setColumns(in.readInt());
break;
case PROPERTY_ROWS:
((TextArea) cmp).setRows(in.readInt());
break;
case PROPERTY_HINT:
if (cmp instanceof List) {
((List) cmp).setHint(in.readUTF());
} else {
((TextArea) cmp).setHint(in.readUTF());
}
break;
case PROPERTY_HINT_ICON:
if (cmp instanceof List) {
((List) cmp).setHintIcon(res.getImage(in.readUTF()));
} else {
((TextArea) cmp).setHintIcon(res.getImage(in.readUTF()));
}
break;
case PROPERTY_ITEM_GAP:
((List) cmp).setItemGap(in.readInt());
break;
case PROPERTY_LIST_FIXED:
((List) cmp).setFixedSelection(in.readInt());
break;
case PROPERTY_LIST_ORIENTATION:
((List) cmp).setOrientation(in.readInt());
break;
case PROPERTY_LIST_ITEMS_LEGACY:
String[] items = new String[in.readInt()];
for (int iter = 0; iter < items.length; iter++) {
items[iter] = in.readUTF();
}
if (!setListModel(((List) cmp))) {
((List) cmp).setModel(new DefaultListModel((Object[]) items));
}
break;
case PROPERTY_LIST_ITEMS:
Object[] elements = readObjectArrayForListModel(in, res);
if (!setListModel(((List) cmp))) {
((List) cmp).setModel(new DefaultListModel(elements));
}
break;
case PROPERTY_LIST_RENDERER:
if (cmp instanceof ContainerList) {
((ContainerList) cmp).setRenderer(readRendererer(res, in));
} else {
((List) cmp).setRenderer(readRendererer(res, in));
}
break;
case PROPERTY_NEXT_FORM:
String nextForm = in.readUTF();
setNextForm(cmp, nextForm, res, root);
break;
case PROPERTY_COMMANDS:
readCommands(in, cmp, res, false);
break;
case PROPERTY_COMMANDS_LEGACY:
readCommands(in, cmp, res, true);
break;
case PROPERTY_CYCLIC_FOCUS:
((Form) cmp).setCyclicFocus(in.readBoolean());
break;
case PROPERTY_RTL:
cmp.setRTL(in.readBoolean());
break;
case PROPERTY_SLIDER_THUMB:
((Slider) cmp).setThumbImage(res.getImage(in.readUTF()));
break;
case PROPERTY_INFINITE:
((Slider) cmp).setInfinite(in.readBoolean());
break;
case PROPERTY_PROGRESS:
((Slider) cmp).setProgress(in.readInt());
break;
case PROPERTY_VERTICAL:
((Slider) cmp).setVertical(in.readBoolean());
break;
case PROPERTY_EDITABLE:
if (cmp instanceof TextArea) {
((TextArea) cmp).setEditable(in.readBoolean());
} else {
((Slider) cmp).setEditable(in.readBoolean());
}
break;
case PROPERTY_INCREMENTS:
((Slider) cmp).setIncrements(in.readInt());
break;
case PROPERTY_RENDER_PERCENTAGE_ON_TOP:
((Slider) cmp).setRenderPercentageOnTop(in.readBoolean());
break;
case PROPERTY_MAX_VALUE:
((Slider) cmp).setMaxValue(in.readInt());
break;
case PROPERTY_MIN_VALUE:
((Slider) cmp).setMinValue(in.readInt());
break;
}
property = in.readInt();
}
postCreateComponent(cmp);
return cmp;
}
use of com.vaadin.v7.ui.CheckBox in project CodenameOne by codenameone.
the class FileChooserSample method start.
public void start() {
if (current != null) {
current.show();
return;
}
Form hi = new Form("Hi World");
hi.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
hi.addComponent(new Label("Hi World"));
Button b = new Button("Browse Files");
CheckBox multiSelect = new CheckBox("Multi-select");
b.addActionListener(e -> {
if (FileChooser.isAvailable()) {
FileChooser.setOpenFilesInPlace(true);
FileChooser.showOpenDialog(multiSelect.isSelected(), ".xls, .csv, text/plain", e2 -> {
if (e2 == null || e2.getSource() == null) {
hi.add("No file was selected");
hi.revalidate();
return;
}
if (multiSelect.isSelected()) {
String[] paths = (String[]) e2.getSource();
for (String path : paths) {
System.out.println(path);
CN.execute(path);
}
return;
}
String file = (String) e2.getSource();
if (file == null) {
hi.add("No file was selected");
hi.revalidate();
} else {
System.out.println("File path: " + file);
String extension = null;
if (file.lastIndexOf(".") > 0) {
extension = file.substring(file.lastIndexOf(".") + 1);
}
FileSystemStorage fs = FileSystemStorage.getInstance();
if ("txt".equals(extension)) {
try {
InputStream fis = fs.openInputStream(file);
hi.addComponent(new SpanLabel(Util.readToString(fis)));
} catch (Exception ex) {
Log.e(ex);
}
} else {
hi.add("Selected file " + file);
}
File f = new File(file);
String contents = "";
try (InputStream fis = fs.openInputStream(file)) {
contents = Util.readToString(fis);
} catch (Exception ex) {
Log.e(ex);
return;
}
contents += "\nTest";
try (OutputStreamWriter writer = new OutputStreamWriter(fs.openOutputStream(file, 0), "UTF-8")) {
writer.write(contents);
} catch (IOException ex) {
Log.e(ex);
return;
}
}
hi.revalidate();
});
}
});
hi.addComponent(b);
Button testImage = new Button("Browse Images");
testImage.addActionListener(e -> {
if (FileChooser.isAvailable()) {
FileChooser.showOpenDialog(multiSelect.isSelected(), ".pdf,application/pdf,.gif,image/gif,.png,image/png,.jpg,image/jpg,.tif,image/tif,.jpeg,.bmp", e2 -> {
if (multiSelect.isSelected()) {
String[] paths = (String[]) e2.getSource();
for (String path : paths) {
System.out.println(path);
try {
Image img = Image.createImage(path);
hi.add(new Label(img));
} catch (Exception ex) {
Log.e(ex);
}
}
return;
}
if (e2 != null && e2.getSource() != null) {
String file = (String) e2.getSource();
try {
Image img = Image.createImage(file);
hi.add(new Label(img));
if (true)
return;
} catch (Exception ex) {
Log.e(ex);
}
String filestack = "http://solutions.weblite.ca/testupload.php";
MultipartRequest request = new MultipartRequest();
request.setUrl(filestack);
request.setPost(true);
try {
request.addData("fileUpload", file, "/");
request.setFilename("fileUpload", "myfile.png");
request.setReadResponseForErrors(true);
NetworkManager.getInstance().addToQueueAndWait(request);
} catch (Throwable t) {
Log.e(t);
}
}
});
}
});
hi.add(testImage);
hi.add(multiSelect);
hi.show();
}
use of com.vaadin.v7.ui.CheckBox in project SORMAS-Project by hzi-braunschweig.
the class ContactDataForm method addFields.
@SuppressWarnings("deprecation")
@Override
protected void addFields() {
if (viewMode == null) {
return;
}
Label contactDataHeadingLabel = new Label(I18nProperties.getString(Strings.headingContactData));
contactDataHeadingLabel.addStyleName(H3);
getContent().addComponent(contactDataHeadingLabel, CONTACT_DATA_HEADING_LOC);
Label followUpStausHeadingLabel = new Label(I18nProperties.getString(Strings.headingFollowUpStatus));
followUpStausHeadingLabel.addStyleName(H3);
getContent().addComponent(followUpStausHeadingLabel, FOLLOW_UP_STATUS_HEADING_LOC);
addField(ContactDto.CONTACT_CLASSIFICATION, NullableOptionGroup.class);
addField(ContactDto.CONTACT_STATUS, NullableOptionGroup.class);
addField(ContactDto.UUID, TextField.class);
addField(ContactDto.EXTERNAL_ID, TextField.class);
TextField externalTokenField = addField(ContactDto.EXTERNAL_TOKEN, TextField.class);
Label externalTokenWarningLabel = new Label(I18nProperties.getString(Strings.messageContactExternalTokenWarning));
externalTokenWarningLabel.addStyleNames(VSPACE_3, LABEL_WHITE_SPACE_NORMAL);
getContent().addComponent(externalTokenWarningLabel, EXTERNAL_TOKEN_WARNING_LOC);
addField(ContactDto.INTERNAL_TOKEN, TextField.class);
addField(ContactDto.REPORTING_USER, ComboBox.class);
multiDayContact = addField(ContactDto.MULTI_DAY_CONTACT, CheckBox.class);
firstContactDate = addDateField(ContactDto.FIRST_CONTACT_DATE, DateField.class, 0);
lastContactDate = addField(ContactDto.LAST_CONTACT_DATE, DateField.class);
reportDate = addField(ContactDto.REPORT_DATE_TIME, DateField.class);
List<AbstractField<Date>> validatedFields = Arrays.asList(firstContactDate, lastContactDate, reportDate);
validatedFields.forEach(field -> field.addValueChangeListener(r -> {
validatedFields.forEach(otherField -> {
otherField.setValidationVisible(!otherField.isValid());
});
}));
FieldHelper.setVisibleWhen(getFieldGroup(), ContactDto.FIRST_CONTACT_DATE, ContactDto.MULTI_DAY_CONTACT, Collections.singletonList(true), true);
initContactDateValidation();
addInfrastructureField(ContactDto.REPORTING_DISTRICT).addItems(FacadeProvider.getDistrictFacade().getAllActiveAsReference());
addField(ContactDto.CONTACT_IDENTIFICATION_SOURCE, ComboBox.class);
TextField contactIdentificationSourceDetails = addField(ContactDto.CONTACT_IDENTIFICATION_SOURCE_DETAILS, TextField.class);
contactIdentificationSourceDetails.setInputPrompt(I18nProperties.getString(Strings.pleaseSpecify));
// contactIdentificationSourceDetails.setVisible(false);
ComboBox tracingApp = addField(ContactDto.TRACING_APP, ComboBox.class);
TextField tracingAppDetails = addField(ContactDto.TRACING_APP_DETAILS, TextField.class);
tracingAppDetails.setInputPrompt(I18nProperties.getString(Strings.pleaseSpecify));
// tracingAppDetails.setVisible(false);
if (isConfiguredServer(CountryHelper.COUNTRY_CODE_GERMANY)) {
FieldHelper.setVisibleWhen(getFieldGroup(), ContactDto.CONTACT_IDENTIFICATION_SOURCE_DETAILS, ContactDto.CONTACT_IDENTIFICATION_SOURCE, Arrays.asList(ContactIdentificationSource.OTHER), true);
FieldHelper.setVisibleWhen(getFieldGroup(), ContactDto.TRACING_APP, ContactDto.CONTACT_IDENTIFICATION_SOURCE, Arrays.asList(ContactIdentificationSource.TRACING_APP), true);
FieldHelper.setVisibleWhen(getFieldGroup(), ContactDto.TRACING_APP_DETAILS, ContactDto.TRACING_APP, Arrays.asList(TracingApp.OTHER), true);
}
contactProximity = addField(ContactDto.CONTACT_PROXIMITY, NullableOptionGroup.class);
contactProximity.setCaption(I18nProperties.getCaption(Captions.Contact_contactProximityLongForm));
contactProximity.removeStyleName(ValoTheme.OPTIONGROUP_HORIZONTAL);
if (isConfiguredServer(CountryHelper.COUNTRY_CODE_GERMANY)) {
addField(ContactDto.CONTACT_PROXIMITY_DETAILS, TextField.class);
contactCategory = addField(ContactDto.CONTACT_CATEGORY, NullableOptionGroup.class);
contactProximity.addValueChangeListener(e -> {
if (getInternalValue().getContactProximity() != e.getProperty().getValue() || contactCategory.isModified()) {
updateContactCategory((ContactProximity) contactProximity.getNullableValue());
}
});
}
ComboBox relationToCase = addField(ContactDto.RELATION_TO_CASE, ComboBox.class);
addField(ContactDto.RELATION_DESCRIPTION, TextField.class);
cbDisease = addDiseaseField(ContactDto.DISEASE, false);
cbDisease.setNullSelectionAllowed(false);
addField(ContactDto.DISEASE_DETAILS, TextField.class);
addField(ContactDto.PROHIBITION_TO_WORK, NullableOptionGroup.class).addStyleName(ValoTheme.OPTIONGROUP_HORIZONTAL);
DateField prohibitionToWorkFrom = addField(ContactDto.PROHIBITION_TO_WORK_FROM);
DateField prohibitionToWorkUntil = addDateField(ContactDto.PROHIBITION_TO_WORK_UNTIL, DateField.class, -1);
FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(ContactDto.PROHIBITION_TO_WORK_FROM, ContactDto.PROHIBITION_TO_WORK_UNTIL), ContactDto.PROHIBITION_TO_WORK, YesNoUnknown.YES, true);
prohibitionToWorkFrom.addValidator(new DateComparisonValidator(prohibitionToWorkFrom, prohibitionToWorkUntil, true, false, I18nProperties.getValidationError(Validations.beforeDate, prohibitionToWorkFrom.getCaption(), prohibitionToWorkUntil.getCaption())));
prohibitionToWorkUntil.addValidator(new DateComparisonValidator(prohibitionToWorkUntil, prohibitionToWorkFrom, false, false, I18nProperties.getValidationError(Validations.afterDate, prohibitionToWorkUntil.getCaption(), prohibitionToWorkFrom.getCaption())));
quarantine = addField(ContactDto.QUARANTINE);
quarantine.addValueChangeListener(e -> onQuarantineValueChange());
quarantineFrom = addField(ContactDto.QUARANTINE_FROM, DateField.class);
dfQuarantineTo = addDateField(ContactDto.QUARANTINE_TO, DateField.class, -1);
quarantineFrom.addValidator(new DateComparisonValidator(quarantineFrom, dfQuarantineTo, true, false, I18nProperties.getValidationError(Validations.beforeDate, quarantineFrom.getCaption(), dfQuarantineTo.getCaption())));
dfQuarantineTo.addValidator(new DateComparisonValidator(dfQuarantineTo, quarantineFrom, false, false, I18nProperties.getValidationError(Validations.afterDate, dfQuarantineTo.getCaption(), quarantineFrom.getCaption())));
quarantineChangeComment = addField(ContactDto.QUARANTINE_CHANGE_COMMENT);
dfPreviousQuarantineTo = addDateField(ContactDto.PREVIOUS_QUARANTINE_TO, DateField.class, -1);
setReadOnly(true, ContactDto.PREVIOUS_QUARANTINE_TO);
setVisible(false, ContactDto.QUARANTINE_CHANGE_COMMENT, ContactDto.PREVIOUS_QUARANTINE_TO);
quarantineOrderedVerbally = addField(ContactDto.QUARANTINE_ORDERED_VERBALLY, CheckBox.class);
CssStyles.style(quarantineOrderedVerbally, CssStyles.FORCE_CAPTION);
addField(ContactDto.QUARANTINE_ORDERED_VERBALLY_DATE, DateField.class);
quarantineOrderedOfficialDocument = addField(ContactDto.QUARANTINE_ORDERED_OFFICIAL_DOCUMENT, CheckBox.class);
CssStyles.style(quarantineOrderedOfficialDocument, CssStyles.FORCE_CAPTION);
addField(ContactDto.QUARANTINE_ORDERED_OFFICIAL_DOCUMENT_DATE, DateField.class);
CheckBox quarantineOfficialOrderSent = addField(ContactDto.QUARANTINE_OFFICIAL_ORDER_SENT, CheckBox.class);
CssStyles.style(quarantineOfficialOrderSent, FORCE_CAPTION);
addField(ContactDto.QUARANTINE_OFFICIAL_ORDER_SENT_DATE, DateField.class);
FieldHelper.setVisibleWhen(getFieldGroup(), ContactDto.QUARANTINE_OFFICIAL_ORDER_SENT, ContactDto.QUARANTINE_ORDERED_OFFICIAL_DOCUMENT, Collections.singletonList(Boolean.TRUE), true);
cbQuarantineExtended = addField(ContactDto.QUARANTINE_EXTENDED, CheckBox.class);
cbQuarantineExtended.setEnabled(false);
cbQuarantineExtended.setVisible(false);
CssStyles.style(cbQuarantineExtended, CssStyles.FORCE_CAPTION);
cbQuarantineReduced = addField(ContactDto.QUARANTINE_REDUCED, CheckBox.class);
cbQuarantineReduced.setEnabled(false);
cbQuarantineReduced.setVisible(false);
CssStyles.style(cbQuarantineReduced, CssStyles.FORCE_CAPTION);
TextField quarantineHelpNeeded = addField(ContactDto.QUARANTINE_HELP_NEEDED, TextField.class);
quarantineHelpNeeded.setInputPrompt(I18nProperties.getString(Strings.pleaseSpecify));
TextField quarantineTypeDetails = addField(ContactDto.QUARANTINE_TYPE_DETAILS, TextField.class);
quarantineTypeDetails.setInputPrompt(I18nProperties.getString(Strings.pleaseSpecify));
addField(ContactDto.QUARANTINE_HOME_POSSIBLE, NullableOptionGroup.class);
addField(ContactDto.QUARANTINE_HOME_POSSIBLE_COMMENT, TextField.class);
addField(ContactDto.QUARANTINE_HOME_SUPPLY_ENSURED, NullableOptionGroup.class);
addField(ContactDto.QUARANTINE_HOME_SUPPLY_ENSURED_COMMENT, TextField.class);
FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(ContactDto.QUARANTINE_FROM, ContactDto.QUARANTINE_TO, ContactDto.QUARANTINE_HELP_NEEDED), ContactDto.QUARANTINE, QuarantineType.QUARANTINE_IN_EFFECT, true);
if (isConfiguredServer(CountryHelper.COUNTRY_CODE_GERMANY) || isConfiguredServer(CountryHelper.COUNTRY_CODE_SWITZERLAND)) {
FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(ContactDto.QUARANTINE_ORDERED_VERBALLY, ContactDto.QUARANTINE_ORDERED_OFFICIAL_DOCUMENT), ContactDto.QUARANTINE, QuarantineType.QUARANTINE_IN_EFFECT, true);
}
FieldHelper.setVisibleWhen(getFieldGroup(), ContactDto.QUARANTINE_HOME_POSSIBLE_COMMENT, ContactDto.QUARANTINE_HOME_POSSIBLE, Arrays.asList(YesNoUnknown.NO), true);
FieldHelper.setVisibleWhen(getFieldGroup(), ContactDto.QUARANTINE_HOME_SUPPLY_ENSURED, ContactDto.QUARANTINE_HOME_POSSIBLE, Arrays.asList(YesNoUnknown.YES), true);
FieldHelper.setVisibleWhen(getFieldGroup(), ContactDto.QUARANTINE_HOME_SUPPLY_ENSURED_COMMENT, ContactDto.QUARANTINE_HOME_SUPPLY_ENSURED, Arrays.asList(YesNoUnknown.NO), true);
FieldHelper.setVisibleWhen(getFieldGroup(), ContactDto.QUARANTINE_TYPE_DETAILS, ContactDto.QUARANTINE, Arrays.asList(QuarantineType.OTHER), true);
FieldHelper.setVisibleWhen(getFieldGroup(), ContactDto.QUARANTINE_ORDERED_VERBALLY_DATE, ContactDto.QUARANTINE_ORDERED_VERBALLY, Arrays.asList(Boolean.TRUE), true);
FieldHelper.setVisibleWhen(getFieldGroup(), ContactDto.QUARANTINE_ORDERED_OFFICIAL_DOCUMENT_DATE, ContactDto.QUARANTINE_ORDERED_OFFICIAL_DOCUMENT, Arrays.asList(Boolean.TRUE), true);
FieldHelper.setVisibleWhen(getFieldGroup(), ContactDto.QUARANTINE_OFFICIAL_ORDER_SENT_DATE, ContactDto.QUARANTINE_OFFICIAL_ORDER_SENT, Collections.singletonList(Boolean.TRUE), true);
addField(ContactDto.DESCRIPTION, TextArea.class).setRows(6);
addField(ContactDto.VACCINATION_STATUS);
addField(ContactDto.RETURNING_TRAVELER, NullableOptionGroup.class);
addField(ContactDto.CASE_ID_EXTERNAL_SYSTEM, TextField.class);
addField(ContactDto.CASE_OR_EVENT_INFORMATION, TextArea.class).setRows(4);
addField(ContactDto.FOLLOW_UP_STATUS, ComboBox.class);
addField(ContactDto.FOLLOW_UP_STATUS_CHANGE_DATE);
addField(ContactDto.FOLLOW_UP_STATUS_CHANGE_USER);
addField(ContactDto.FOLLOW_UP_COMMENT, TextArea.class).setRows(3);
dfFollowUpUntil = addDateField(ContactDto.FOLLOW_UP_UNTIL, DateField.class, -1);
dfFollowUpUntil.addValueChangeListener(v -> onFollowUpUntilChanged(v, dfQuarantineTo, cbQuarantineExtended, cbQuarantineReduced));
cbOverwriteFollowUpUntil = addField(ContactDto.OVERWRITE_FOLLOW_UP_UTIL, CheckBox.class);
cbOverwriteFollowUpUntil.addValueChangeListener(e -> {
if (!(Boolean) e.getProperty().getValue()) {
dfFollowUpUntil.discard();
}
});
dfQuarantineTo.addValueChangeListener(e -> onQuarantineEndChange());
addValueChangeListener(e -> {
ValidationUtils.initComponentErrorValidator(externalTokenField, getValue().getExternalToken(), Validations.duplicateExternalToken, externalTokenWarningLabel, (externalToken) -> FacadeProvider.getContactFacade().doesExternalTokenExist(externalToken, getValue().getUuid()));
onQuarantineValueChange();
});
ComboBox contactOfficerField = addField(ContactDto.CONTACT_OFFICER, ComboBox.class);
contactOfficerField.setNullSelectionAllowed(true);
ComboBox region = addInfrastructureField(ContactDto.REGION);
region.setDescription(I18nProperties.getPrefixDescription(ContactDto.I18N_PREFIX, ContactDto.REGION));
ComboBox district = addInfrastructureField(ContactDto.DISTRICT);
district.setDescription(I18nProperties.getPrefixDescription(ContactDto.I18N_PREFIX, ContactDto.DISTRICT));
ComboBox community = addInfrastructureField(ContactDto.COMMUNITY);
community.setDescription(I18nProperties.getPrefixDescription(ContactDto.I18N_PREFIX, ContactDto.COMMUNITY));
region.addValueChangeListener(e -> {
RegionReferenceDto regionDto = (RegionReferenceDto) e.getProperty().getValue();
FieldHelper.updateItems(district, regionDto != null ? FacadeProvider.getDistrictFacade().getAllActiveByRegion(regionDto.getUuid()) : null);
});
district.addValueChangeListener(e -> {
DistrictReferenceDto districtDto = (DistrictReferenceDto) e.getProperty().getValue();
FieldHelper.updateItems(community, districtDto != null ? FacadeProvider.getCommunityFacade().getAllActiveByDistrict(districtDto.getUuid()) : null);
List<DistrictReferenceDto> officerDistricts = new ArrayList<>();
officerDistricts.add(districtDto);
if (districtDto == null && getValue().getCaze() != null) {
CaseDataDto caseDto = FacadeProvider.getCaseFacade().getCaseDataByUuid(getValue().getCaze().getUuid());
FieldHelper.updateOfficersField(contactOfficerField, caseDto, UserRight.CONTACT_RESPONSIBLE);
} else {
FieldHelper.updateItems(contactOfficerField, districtDto != null ? FacadeProvider.getUserFacade().getUserRefsByDistrict(districtDto, getSelectedDisease(), UserRight.CONTACT_RESPONSIBLE) : null);
}
});
region.addItems(FacadeProvider.getRegionFacade().getAllActiveByServerCountry());
CheckBox cbHighPriority = addField(ContactDto.HIGH_PRIORITY, CheckBox.class);
tfExpectedFollowUpUntilDate = new TextField();
tfExpectedFollowUpUntilDate.setCaption(I18nProperties.getCaption(Captions.Contact_expectedFollowUpUntil));
getContent().addComponent(tfExpectedFollowUpUntilDate, EXPECTED_FOLLOW_UP_UNTIL_DATE_LOC);
NullableOptionGroup ogImmunosuppressiveTherapyBasicDisease = addField(ContactDto.IMMUNOSUPPRESSIVE_THERAPY_BASIC_DISEASE, NullableOptionGroup.class);
addField(ContactDto.IMMUNOSUPPRESSIVE_THERAPY_BASIC_DISEASE_DETAILS, TextField.class);
NullableOptionGroup ogCareForPeopleOver60 = addField(ContactDto.CARE_FOR_PEOPLE_OVER_60, NullableOptionGroup.class);
cbDisease.addValueChangeListener(e -> updateDiseaseConfiguration((Disease) e.getProperty().getValue()));
HealthConditionsForm clinicalCourseForm = addField(ContactDto.HEALTH_CONDITIONS, HealthConditionsForm.class);
clinicalCourseForm.setCaption(null);
Label generalCommentLabel = new Label(I18nProperties.getPrefixCaption(ContactDto.I18N_PREFIX, ContactDto.ADDITIONAL_DETAILS));
generalCommentLabel.addStyleName(H3);
getContent().addComponent(generalCommentLabel, GENERAL_COMMENT_LOC);
TextArea additionalDetails = addField(ContactDto.ADDITIONAL_DETAILS, TextArea.class);
additionalDetails.setRows(6);
additionalDetails.setDescription(I18nProperties.getPrefixDescription(ContactDto.I18N_PREFIX, ContactDto.ADDITIONAL_DETAILS, "") + "\n" + I18nProperties.getDescription(Descriptions.descGdpr));
CssStyles.style(additionalDetails, CssStyles.CAPTION_HIDDEN);
addField(ContactDto.DELETION_REASON);
addField(ContactDto.OTHER_DELETION_REASON, TextArea.class).setRows(3);
setVisible(false, ContactDto.DELETION_REASON, ContactDto.OTHER_DELETION_REASON);
addFields(ContactDto.END_OF_QUARANTINE_REASON, ContactDto.END_OF_QUARANTINE_REASON_DETAILS);
FieldHelper.setVisibleWhen(getFieldGroup(), ContactDto.END_OF_QUARANTINE_REASON_DETAILS, ContactDto.END_OF_QUARANTINE_REASON, Collections.singletonList(EndOfQuarantineReason.OTHER), true);
initializeVisibilitiesAndAllowedVisibilities();
initializeAccessAndAllowedAccesses();
setReadOnly(true, ContactDto.UUID, ContactDto.REPORTING_USER, ContactDto.CONTACT_STATUS, ContactDto.FOLLOW_UP_STATUS, ContactDto.FOLLOW_UP_STATUS_CHANGE_DATE, ContactDto.FOLLOW_UP_STATUS_CHANGE_USER);
FieldHelper.setRequiredWhen(getFieldGroup(), ContactDto.FOLLOW_UP_STATUS, Arrays.asList(ContactDto.FOLLOW_UP_COMMENT), Arrays.asList(FollowUpStatus.CANCELED, FollowUpStatus.LOST));
FieldHelper.setVisibleWhenSourceNotNull(getFieldGroup(), Arrays.asList(ContactDto.FOLLOW_UP_STATUS_CHANGE_DATE, ContactDto.FOLLOW_UP_STATUS_CHANGE_USER), ContactDto.FOLLOW_UP_STATUS_CHANGE_DATE, true);
FieldHelper.setVisibleWhen(getFieldGroup(), ContactDto.RELATION_DESCRIPTION, ContactDto.RELATION_TO_CASE, Arrays.asList(ContactRelation.OTHER), true);
FieldHelper.setVisibleWhen(getFieldGroup(), ContactDto.IMMUNOSUPPRESSIVE_THERAPY_BASIC_DISEASE_DETAILS, ContactDto.IMMUNOSUPPRESSIVE_THERAPY_BASIC_DISEASE, Arrays.asList(YesNoUnknown.YES), true);
FieldHelper.setVisibleWhen(getFieldGroup(), ContactDto.DISEASE_DETAILS, ContactDto.DISEASE, Arrays.asList(Disease.OTHER), true);
FieldHelper.setRequiredWhen(getFieldGroup(), ContactDto.DISEASE, Arrays.asList(ContactDto.DISEASE_DETAILS), Arrays.asList(Disease.OTHER));
FieldHelper.setReadOnlyWhen(getFieldGroup(), Arrays.asList(ContactDto.FOLLOW_UP_UNTIL), ContactDto.OVERWRITE_FOLLOW_UP_UTIL, Arrays.asList(Boolean.FALSE), false, true);
FieldHelper.setRequiredWhen(getFieldGroup(), ContactDto.OVERWRITE_FOLLOW_UP_UTIL, Arrays.asList(ContactDto.FOLLOW_UP_UNTIL), Arrays.asList(Boolean.TRUE));
FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(ContactDto.FOLLOW_UP_UNTIL, ContactDto.OVERWRITE_FOLLOW_UP_UTIL), ContactDto.FOLLOW_UP_STATUS, Arrays.asList(FollowUpStatus.CANCELED, FollowUpStatus.COMPLETED, FollowUpStatus.FOLLOW_UP, FollowUpStatus.LOST), true);
initializeVisibilitiesAndAllowedVisibilities();
addValueChangeListener(e -> {
if (getValue() != null) {
CaseDataDto caseDto = null;
if (getValue().getCaze() != null) {
setVisible(false, ContactDto.DISEASE, ContactDto.CASE_ID_EXTERNAL_SYSTEM, ContactDto.CASE_OR_EVENT_INFORMATION);
caseDto = FacadeProvider.getCaseFacade().getCaseDataByUuid(getValue().getCaze().getUuid());
} else {
setRequired(true, ContactDto.DISEASE, ContactDto.REGION, ContactDto.DISTRICT);
}
updateDateComparison();
updateDiseaseConfiguration(getValue().getDisease());
updateFollowUpStatusComponents();
DistrictReferenceDto referenceDistrict = getValue().getDistrict() != null ? getValue().getDistrict() : caseDto != null ? caseDto.getDistrict() : null;
if (referenceDistrict != null) {
contactOfficerField.addItems(FacadeProvider.getUserFacade().getUserRefsByDistrict(referenceDistrict, getSelectedDisease(), UserRight.CONTACT_RESPONSIBLE));
}
getContent().removeComponent(TO_CASE_BTN_LOC);
if (getValue().getResultingCase() != null) {
// link to case
Link linkToData = ControllerProvider.getCaseController().createLinkToData(getValue().getResultingCase().getUuid(), I18nProperties.getCaption(Captions.contactOpenContactCase));
getContent().addComponent(linkToData, TO_CASE_BTN_LOC);
} else if (!ContactClassification.NO_CONTACT.equals(getValue().getContactClassification())) {
if (UserProvider.getCurrent().hasUserRight(UserRight.CONTACT_CONVERT)) {
toCaseButton = ButtonHelper.createButton(Captions.contactCreateContactCase);
toCaseButton.addStyleName(ValoTheme.BUTTON_LINK);
getContent().addComponent(toCaseButton, TO_CASE_BTN_LOC);
}
}
if (!isConfiguredServer(CountryHelper.COUNTRY_CODE_GERMANY)) {
setVisible(false, ContactDto.IMMUNOSUPPRESSIVE_THERAPY_BASIC_DISEASE, ContactDto.IMMUNOSUPPRESSIVE_THERAPY_BASIC_DISEASE_DETAILS, ContactDto.CARE_FOR_PEOPLE_OVER_60);
} else {
ogImmunosuppressiveTherapyBasicDisease.addValueChangeListener(getHighPriorityValueChangeListener(cbHighPriority));
ogCareForPeopleOver60.addValueChangeListener(getHighPriorityValueChangeListener(cbHighPriority));
}
// Add follow-up until validator
FollowUpPeriodDto followUpPeriod = ContactLogic.getFollowUpStartDate(lastContactDate.getValue(), reportDate.getValue(), FacadeProvider.getSampleFacade().getByContactUuids(Collections.singletonList(getValue().getUuid())));
Date minimumFollowUpUntilDate = FollowUpLogic.calculateFollowUpUntilDate(followUpPeriod, null, FacadeProvider.getVisitFacade().getVisitsByContact(new ContactReferenceDto(getValue().getUuid())), FacadeProvider.getDiseaseConfigurationFacade().getFollowUpDuration(getSelectedDisease()), FacadeProvider.getFeatureConfigurationFacade().isPropertyValueTrue(FeatureType.CONTACT_TRACING, FeatureTypeProperty.ALLOW_FREE_FOLLOW_UP_OVERWRITE)).getFollowUpEndDate();
if (FacadeProvider.getFeatureConfigurationFacade().isPropertyValueTrue(FeatureType.CONTACT_TRACING, FeatureTypeProperty.ALLOW_FREE_FOLLOW_UP_OVERWRITE)) {
dfFollowUpUntil.addValueChangeListener(valueChangeEvent -> {
if (DateHelper.getEndOfDay(dfFollowUpUntil.getValue()).before(minimumFollowUpUntilDate)) {
dfFollowUpUntil.setComponentError(new ErrorMessage() {
@Override
public ErrorLevel getErrorLevel() {
return ErrorLevel.INFO;
}
@Override
public String getFormattedHtmlMessage() {
return I18nProperties.getValidationError(Validations.contactFollowUpUntilDateSoftValidation, I18nProperties.getPrefixCaption(ContactDto.I18N_PREFIX, ContactDto.FOLLOW_UP_UNTIL));
}
});
}
});
} else {
dfFollowUpUntil.addValidator(new DateRangeValidator(I18nProperties.getValidationError(Validations.contactFollowUpUntilDate), minimumFollowUpUntilDate, null, Resolution.DAY));
}
}
// Overwrite visibility for quarantine fields
if (!isConfiguredServer(CountryHelper.COUNTRY_CODE_GERMANY) && !isConfiguredServer(CountryHelper.COUNTRY_CODE_SWITZERLAND)) {
setVisible(false, ContactDto.QUARANTINE_ORDERED_OFFICIAL_DOCUMENT, ContactDto.QUARANTINE_ORDERED_OFFICIAL_DOCUMENT_DATE, ContactDto.QUARANTINE_ORDERED_VERBALLY, ContactDto.QUARANTINE_ORDERED_VERBALLY_DATE, ContactDto.QUARANTINE_OFFICIAL_ORDER_SENT, ContactDto.QUARANTINE_OFFICIAL_ORDER_SENT_DATE);
}
});
setRequired(true, ContactDto.CONTACT_CLASSIFICATION, ContactDto.CONTACT_STATUS, ContactDto.REPORT_DATE_TIME);
FieldHelper.addSoftRequiredStyle(firstContactDate, lastContactDate, contactProximity, relationToCase);
}
Aggregations