public List<DefinitionMapping> getMappings() { List<DefinitionMapping> mappings = new ArrayList<DefinitionMapping>(); for (int i = 0; i < definitions.size(); i++) { UIDefinition definition = definitions.get(i); DefinitionMapping mapping = new DefinitionMapping(); boolean mapped = includeCheckBoxes.get(i).getValue(); mapping.setMapped(mapped); Widget targetWidget = targetWidgets.isEmpty() ? null : targetWidgets.get(i); T target = widgetProvider.getTarget(targetWidget); mapping.setTarget(target); mapping.setDefinition(definition); mappings.add(mapping); } return mappings; }
/** {@inheritDoc} */ @SuppressWarnings("unchecked") public void setMappings(List<DefinitionMapping> mappings) { table.removeAllRows(); definitionsPanels.clear(); includeCheckBoxes.clear(); targetWidgets.clear(); definitions.clear(); setupTableHeaders(includeTargetColumn); table.getColumnFormatter().setWidth(DEFINITION_COLUMN, "100%"); // table.getColumnFormatter().setWidth(ARROW_COLUMN, "70px"); if (mappings.isEmpty()) { Label noAttributesLabel = new Label("No attributes or links"); table.setWidget(1, 0, noAttributesLabel); table.getFlexCellFormatter().setColSpan(1, 0, includeTargetColumn ? 3 : 4); table.getFlexCellFormatter().setStyleName(1, 0, style.emptyCell()); } else { FlexCellFormatter cellFormatter = table.getFlexCellFormatter(); for (DefinitionMapping mapping : mappings) { final int row = table.getRowCount(); UIDefinition definition = mapping.getDefinition(); definitions.add(definition); DefinitionPanel definitionPanel = new DefinitionPanel(); definitionPanel.setDefinition(definition); definitionPanel.setEnabled(mapping.isMapped()); definitionsPanels.add(definitionPanel); table.setWidget(row, DEFINITION_COLUMN, definitionPanel); cellFormatter.setVerticalAlignment( row, DEFINITION_COLUMN, HasVerticalAlignment.ALIGN_MIDDLE); final SimpleCheckBox includeCheckBox = new SimpleCheckBox(); includeCheckBox.setStyleName( CommonResources.INSTANCE.css().simpleCheckbox() + " " + style.checkbox()); includeCheckBox.addClickHandler( new ClickHandler() { @Override public void onClick(ClickEvent event) { setInclude(row, includeCheckBox.getValue()); } }); includeCheckBox.setValue(mapping.isMapped()); table.setWidget(row, INCLUDE_COLUMN, includeCheckBox); cellFormatter.setVerticalAlignment(row, INCLUDE_COLUMN, HasVerticalAlignment.ALIGN_MIDDLE); includeCheckBoxes.add(includeCheckBox); Widget targetWidget = widgetProvider.getTargetWidget((T) mapping.getTarget()); if (targetWidget != null) { Image arrow = new Image(Resources.INSTANCE.arrow()); arrow.setStyleName(style.arrow()); table.setWidget(row, ARROW_COLUMN, arrow); cellFormatter.setVerticalAlignment(row, ARROW_COLUMN, HasVerticalAlignment.ALIGN_MIDDLE); // table.getCellFormatter().setWidth(row, ARROW_COLUMN, "60px"); table.getCellFormatter().setHeight(row, ARROW_COLUMN, "40px"); widgetProvider.include(targetWidget, mapping.isMapped()); table.setWidget(row, TARGET_COLUMN, targetWidget); cellFormatter.setVerticalAlignment(row, TARGET_COLUMN, HasVerticalAlignment.ALIGN_MIDDLE); targetWidgets.add(targetWidget); } } } }