use of com.github.bordertech.wcomponents.WRepeater.SubUIContext in project wcomponents by BorderTech.
the class WTableRowRenderer method getCurrentRowIdWrapper.
/**
* Retrieve the current {@link RowIdWrapper}.
* <p>
* Intended for internal use only.
* </p>
*
* @return the current row id wrapper, or null if not found
*/
public RowIdWrapper getCurrentRowIdWrapper() {
UIContext uic = UIContextHolder.getCurrent();
if (uic instanceof SubUIContext) {
int index = ((SubUIContext) uic).getRowIndex();
RowIdWrapper wrapper = table.getRepeater().getBeanList().get(index);
return wrapper;
}
return null;
}
use of com.github.bordertech.wcomponents.WRepeater.SubUIContext in project wcomponents by BorderTech.
the class WebUtilities method findClosestContext.
/**
* Finds the closest context for the given component id. This handles the case where the component no longer exists
* due to having been removed from the UI, or having a SubUIContext removed.
*
* @param id the id of the component to search for.
* @return the component and context for the given id, or null if not found.
*/
public static UIContext findClosestContext(final String id) {
UIContext uic = UIContextHolder.getCurrent();
WComponent root = uic.getUI();
UIContext closest = TreeUtil.getClosestContextForId(root, id);
return closest;
}
use of com.github.bordertech.wcomponents.WRepeater.SubUIContext in project wcomponents by BorderTech.
the class TableUtil method getCurrentRowIndex.
/**
* This can be used by column components on a {@link WTable} to determine the current row index.
*
* @param component the column component
* @return the row index for the current row, or null if no row details
*/
public static List<Integer> getCurrentRowIndex(final WComponent component) {
UIContext uic = UIContextHolder.getCurrent();
// Check have correct context
if (!(uic instanceof SubUIContext)) {
return null;
}
// Find the table
WTable table = WebUtilities.getAncestorOfClass(WTable.class, component);
if (table == null) {
return null;
}
int repeaterIdx = ((SubUIContext) uic).getRowIndex();
RowIdWrapper wrapper = table.getRepeater().getBeanList().get(repeaterIdx);
return wrapper.getRowIndex();
}
use of com.github.bordertech.wcomponents.WRepeater.SubUIContext in project wcomponents by BorderTech.
the class UIContextImpl_Test method testFocusableInWRepeaterNestedBeanBound.
@Test
public void testFocusableInWRepeaterNestedBeanBound() {
// Beans list
final MyBean option1 = new MyBean();
final MyBean option2 = new MyBean();
final MyBean option3 = new MyBean();
final List<MyBean> beans = Arrays.asList(new MyBean[] { option1, option2, option3 });
// Another beans list for nested repeater
final String optionA = "A";
final String optionB = "B";
final String optionC = "C";
final List<String> beans2 = Arrays.asList(new String[] { optionA, optionB, optionC });
// Add beans to Option1 for nested repeater
option1.setRows(beans2);
// Setup the nested repeater
WRepeater repeater2 = new WRepeater();
repeater2.setBeanProperty("rows");
WComponent content2 = new WBeanComponent() {
@Override
public void handleRequest(final Request request) {
super.handleRequest(request);
UIContext uic = UIContextHolder.getCurrent();
if (uic instanceof SubUIContext) {
SubUIContext suic = (SubUIContext) uic;
// Set the component on the second row to have focus
if (suic.getRowIndex() == 1) {
uic.setFocussed(this, uic);
}
}
}
};
repeater2.setRepeatedComponent(content2);
// Setup the top level repeater
WRepeater repeater = new WRepeater();
WBeanContainer content = new WBeanContainer();
content.add(repeater2);
repeater.setRepeatedComponent(content);
// Lock component
repeater.setLocked(true);
// Set the repeater as the "UI" for context
UIContext uic = new UIContextImpl();
uic.setUI(repeater);
setActiveContext(uic);
// Setup the bean list on the top level repeater
repeater.setBeanList(beans);
// ServiceRequest on the repeater (to create the SubUiContexts)
MockRequest request = new MockRequest();
repeater.serviceRequest(request);
// Simulate clearing of scratch map
uic.clearScratchMap();
// Get the focused component
String focusId = uic.getFocussedId();
// Get the ID of the component on the second row
String rowComponentId = null;
try {
UIContext suic = repeater.getRowContext(option1);
UIContextHolder.pushContext(suic);
UIContext suic2 = repeater2.getRowContext(optionB);
UIContextHolder.pushContext(suic2);
rowComponentId = content2.getId();
} finally {
UIContextHolder.reset();
}
Assert.assertNotNull("Focus ID should not be null", focusId);
Assert.assertEquals("Focus ID should be the ID for the component on the 2nd row", rowComponentId, focusId);
}
use of com.github.bordertech.wcomponents.WRepeater.SubUIContext in project wcomponents by BorderTech.
the class WDataTable_Test method testTableInternalIds.
@Test
public void testTableInternalIds() {
WNamingContext context = new WNamingContext("TEST");
WDataTable table = new WDataTable();
table.setDataModel(new SimpleTableDataModel(new String[][] { { "1" }, { "3" }, { "2" } }));
WComponent repeated = new WBeanComponent();
table.addColumn(new WTableColumn("dummy", repeated));
context.add(table);
context.setLocked(true);
setActiveContext(new UIContextImpl());
// Table ID
Assert.assertEquals("Incorrect internal id for table", WComponent.DEFAULT_INTERNAL_ID + "0", table.getInternalId());
String tableId = table.getInternalId();
// Table Repeater ID
Assert.assertEquals("Incorrect internal id for table repeater", tableId + "c", table.getRepeater().getInternalId());
// Table Repeater root ID
Assert.assertEquals("Incorrect internal id for table repeater root", tableId + "cr", table.getRepeater().getRepeatRoot().getInternalId());
String rowPrefix = table.getRepeater().getRepeatRoot().getInternalId();
// Allow for WTableColumn between repeated component
String rowSuffix = "a1a";
// Row IDs
for (UIContext uic : table.getRepeater().getRowContexts()) {
// Id has uic row render id in it
int row = ((SubUIContext) uic).getContextId();
String repeatedId = rowPrefix + row + rowSuffix;
try {
UIContextHolder.pushContext(uic);
Assert.assertEquals("Incorrect internal id for repeated component", repeatedId, repeated.getInternalId());
} finally {
UIContextHolder.popContext();
}
}
}
Aggregations