use of com.codename1.rad.models.Property.Editable 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.codename1.rad.models.Property.Editable in project CodenameOne by codenameone.
the class CodenameOneInputConnection method getEditable.
public Editable getEditable() {
if (Display.isInitialized() && Display.getInstance().getCurrent() != null) {
Component txtCmp = Display.getInstance().getCurrent().getFocused();
if (txtCmp != null && txtCmp instanceof TextField) {
TextField t = (TextField) txtCmp;
String textFieldText = t.getText();
edit.clear();
edit.append(textFieldText);
return edit;
}
}
return super.getEditable();
}
use of com.codename1.rad.models.Property.Editable in project CodeRAD by shannah.
the class ButtonListPropertyView method updateMultiSelectionModel.
private void updateMultiSelectionModel() {
MultipleSelectionListModel model = getComponent().getMultiListModel();
Entity e = getPropertySelector().getLeafEntity();
Property p = getPropertySelector().getLeafProperty();
Object val = p.getValue(e.getEntity());
int len = model.getSize();
if (getPropertySelector().isEmpty()) {
if (model.getSelectedIndices().length > 0) {
model.setSelectedIndices(new int[0]);
}
} else {
List<Integer> selectedIndices = new ArrayList<>();
if (p.getContentType().isEntityList()) {
// Property contains an entity list
List selectedObjects = new ArrayList();
List<String> selectedIds = new ArrayList<>();
boolean useIds = true;
EntityList el = e.getEntity().getEntityList(p);
for (Object obj : el) {
selectedObjects.add(obj);
if (obj instanceof Entity) {
String id = ((Entity) obj).getEntity().getText(Thing.identifier);
if (id == null) {
useIds = false;
break;
}
selectedIds.add(id);
} else {
useIds = false;
}
}
if (useIds) {
// We will useIds to match rows in options list with rows in entity list
for (int i = 0; i < len; i++) {
Object rowVal = model.getItemAt(i);
if (rowVal instanceof Entity) {
Entity rowEnt = (Entity) rowVal;
String rowId = rowEnt.getEntity().getText(Thing.identifier);
if (rowId == null) {
throw new IllegalStateException("Attempt to use identifiers for matching items in ButtonListPropertyView, but row item " + rowEnt + " has no identifier. Property: " + p + " in entity " + e);
}
if (selectedIds.contains(rowId)) {
selectedIndices.add(i);
}
} else {
throw new IllegalStateException("Options for field should all be entities. Property " + p + " entity " + e);
}
}
} else {
// Not using IDS. We will use direct matching.
for (int i = 0; i < len; i++) {
if (el.contains(model.getItemAt(i))) {
selectedIndices.add(i);
}
}
}
} else if (Collection.class.isAssignableFrom(p.getContentType().getRepresentationClass())) {
// It's a collection
for (int i = 0; i < len; i++) {
if (((Collection) val).contains(model.getItemAt(i))) {
selectedIndices.add(i);
}
}
} else {
throw new IllegalStateException("Property " + p + " must contain either EntityList or Collection in order to be editable by ButtonListPropertyView with a multi-selection options model.");
}
java.util.Collections.sort(selectedIndices, (i1, i2) -> {
return i1 - i2;
});
List<Integer> existingSelectedIndices = new ArrayList<>();
for (int index : model.getSelectedIndices()) {
existingSelectedIndices.add(index);
}
java.util.Collections.sort(existingSelectedIndices, (i1, i2) -> {
return i1 - i2;
});
if (!Objects.deepEquals(selectedIndices, existingSelectedIndices)) {
int size0 = selectedIndices.size();
int[] selectedIndicesArr = new int[size0];
for (int i = 0; i < size0; i++) {
selectedIndicesArr[i] = selectedIndices.get(i);
}
model.setSelectedIndices(selectedIndicesArr);
}
}
}
use of com.codename1.rad.models.Property.Editable in project CodeRAD by shannah.
the class EntityListTableCellRenderer method getTableCellRendererComponent.
@Override
public Component getTableCellRendererComponent(Table table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
EntityListTableModel model = (EntityListTableModel) table.getModel();
FieldNode field = model.getColumnField(column);
FieldNode fieldCopy = field.copy();
fieldCopy.setAttributes(new Editable(false));
Entity entity = model.getEntity(row);
if (entity == null) {
if (parent != null) {
return parent.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
} else {
return new com.codename1.ui.Label();
}
}
return viewFactory.createPropertyView(entity, fieldCopy);
}
Aggregations