use of org.uberfire.ext.wires.core.grids.client.widget.context.GridBodyCellEditContext in project kie-wb-common by kiegroup.
the class EditablePopupHeaderMetaDataTest method testEditWithRelationLocation.
@Test
public void testEditWithRelationLocation() {
final GridBodyCellEditContext context = new GridBodyCellEditContext(ABSOLUTE_CELL_X, ABSOLUTE_CELL_Y, CELL_WIDTH, CELL_HEIGHT, CLIP_MIN_Y, CLIP_MIN_X, ROW_INDEX, COLUMN_INDEX, IS_FLOATING, transform, renderer, Optional.of(new Point2D(RELATIVE_X, RELATIVE_Y)));
header.edit(context);
verify(editor).bind(eq(gridWidget), eq(ROW_INDEX), eq(COLUMN_INDEX));
verify(cellEditorControls).show(eq(editor), eq((int) RELATIVE_X), eq((int) RELATIVE_Y));
}
use of org.uberfire.ext.wires.core.grids.client.widget.context.GridBodyCellEditContext in project kie-wb-common by kiegroup.
the class EditableHeaderGridWidgetEditCellMouseEventHandlerTest method assertHeaderCellEdited.
private void assertHeaderCellEdited(final int uiHeaderColumnIndex) {
assertThat(handler.handleHeaderCell(gridWidget, relativeLocation, 0, uiHeaderColumnIndex, clickEvent)).isTrue();
verify(editableHeaderMetaData).edit(gridBodyCellEditContextCaptor.capture());
final GridBodyCellEditContext gridBodyCellEditContext = gridBodyCellEditContextCaptor.getValue();
assertThat(gridBodyCellEditContext).isNotNull();
assertThat(gridBodyCellEditContext.getRelativeLocation()).isPresent();
final Point2D relativeLocation = gridBodyCellEditContext.getRelativeLocation().get();
assertThat(relativeLocation.getX()).isEqualTo(MOUSE_EVENT_X + GRID_COMPUTED_LOCATION_X);
assertThat(relativeLocation.getY()).isEqualTo(MOUSE_EVENT_Y + GRID_COMPUTED_LOCATION_Y);
}
use of org.uberfire.ext.wires.core.grids.client.widget.context.GridBodyCellEditContext in project kie-wb-common by kiegroup.
the class EditableHeaderGridWidgetMouseDoubleClickHandler method handleHeaderCellDoubleClick.
@Override
protected boolean handleHeaderCellDoubleClick(final NodeMouseDoubleClickEvent event) {
// Convert Canvas co-ordinate to Grid co-ordinate
final Point2D rp = CoordinateUtilities.convertDOMToGridCoordinate(gridWidget, new Point2D(event.getX(), event.getY()));
final double cx = rp.getX();
final double cy = rp.getY();
final Group header = gridWidget.getHeader();
final double headerRowsYOffset = getHeaderRowsYOffset();
final double headerMinY = (header == null ? headerRowsYOffset : header.getY() + headerRowsYOffset);
final double headerMaxY = (header == null ? renderer.getHeaderHeight() : renderer.getHeaderHeight() + header.getY());
if (cx < 0 || cx > gridWidget.getWidth()) {
return false;
}
if (cy < headerMinY || cy > headerMaxY) {
return false;
}
// Get column information
final BaseGridRendererHelper rendererHelper = gridWidget.getRendererHelper();
final BaseGridRendererHelper.RenderingInformation ri = rendererHelper.getRenderingInformation();
if (ri == null) {
return false;
}
final BaseGridRendererHelper.ColumnInformation ci = rendererHelper.getColumnInformation(cx);
final GridColumn<?> column = ci.getColumn();
if (column == null) {
return false;
}
if (!hasEditableHeader(column)) {
return false;
}
// Get row index
final Integer uiHeaderRowIndex = EditableHeaderUtilities.getUiHeaderRowIndex(gridWidget, column, cy);
if (uiHeaderRowIndex == null) {
return false;
}
if (!isEditableHeader(column, uiHeaderRowIndex)) {
return false;
}
// Get rendering information
final EditableHeaderMetaData headerMetaData = (EditableHeaderMetaData) column.getHeaderMetaData().get(uiHeaderRowIndex);
final GridBodyCellEditContext context = EditableHeaderUtilities.makeRenderContext(gridWidget, ri, ci, rp, uiHeaderRowIndex);
headerMetaData.edit(context);
return true;
}
use of org.uberfire.ext.wires.core.grids.client.widget.context.GridBodyCellEditContext in project kie-wb-common by kiegroup.
the class BaseGrid method doShowContextMenu.
@SuppressWarnings("unchecked")
private boolean doShowContextMenu(final HasCellEditorControls.Editor editor, final BiFunction<RenderingInformation, ColumnInformation, GridBodyCellEditContext> contextSupplier, final int uiRowIndex, final int uiColumnIndex, final Object binding) {
final GridColumn<?> column = model.getColumns().get(uiColumnIndex);
final RenderingInformation ri = rendererHelper.getRenderingInformation();
final double columnXCoordinate = rendererHelper.getColumnOffset(column) + column.getWidth() / 2;
final ColumnInformation ci = rendererHelper.getColumnInformation(columnXCoordinate);
final GridBodyCellEditContext context = contextSupplier.apply(ri, ci);
final double cellWidth = context.getCellWidth();
final double cellHeight = context.getCellHeight();
editor.bind(binding, uiRowIndex, uiColumnIndex);
cellEditorControls.show(editor, (int) (context.getAbsoluteCellX() + cellWidth / 2), (int) (context.getAbsoluteCellY() + cellHeight / 2));
return true;
}
use of org.uberfire.ext.wires.core.grids.client.widget.context.GridBodyCellEditContext in project kie-wb-common by kiegroup.
the class EditableNameAndDataTypeColumn method edit.
@Override
public void edit(final GridCell<InformationItemCell.HasNameCell> cell, final GridBodyCellRenderContext context, final Consumer<GridCellValue<InformationItemCell.HasNameCell>> callback) {
final int rowIndex = context.getRowIndex();
if (!isEditable.test(rowIndex)) {
return;
}
final int uiRowIndex = context.getRowIndex();
final int uiColumnIndex = context.getColumnIndex();
final double cellWidth = context.getCellWidth();
final double cellHeight = context.getCellHeight();
final double absoluteCellX = context.getAbsoluteCellX();
final double absoluteCellY = context.getAbsoluteCellY();
final InformationItemCell.HasNameAndDataTypeCell binding = (InformationItemCell.HasNameAndDataTypeCell) cell.getValue().getValue();
editor.bind(new HasValueAndTypeRef<Name>() {
@Override
public QName getTypeRef() {
return binding.getTypeRef();
}
@Override
public void setTypeRef(final QName typeRef) {
if (Objects.equals(typeRef, getTypeRef())) {
return;
}
setTypeRefConsumer.accept(binding, typeRef);
}
@Override
public Name getValue() {
return binding.getName();
}
@Override
public void setValue(final Name name) {
if (Objects.equals(name, getValue())) {
return;
}
if (name == null || name.getValue() == null || name.getValue().trim().isEmpty()) {
clearValueConsumer.accept(binding);
} else {
setValueConsumer.accept(binding, name);
}
}
@Override
public String getPopoverTitle() {
return EditableNameAndDataTypeColumn.this.getPopoverTitle();
}
@Override
public Name toModelValue(final String componentValue) {
return new Name(componentValue);
}
@Override
public String toWidgetValue(final Name modelValue) {
return modelValue.getValue();
}
@Override
public String getValueLabel() {
return translationService.getTranslation(DMNEditorConstants.NameAndDataTypePopover_NameLabel);
}
@Override
public String normaliseValue(final String componentValue) {
return NameUtils.normaliseName(componentValue);
}
@Override
public DMNModelInstrumentedBase asDMNModelInstrumentedBase() {
return binding.asDMNModelInstrumentedBase();
}
@Override
public List<HasTypeRef> getHasTypeRefs() {
return getNotNullHasTypeRefs(binding);
}
}, uiRowIndex, uiColumnIndex);
final double[] dxy = { absoluteCellX + cellWidth / 2, absoluteCellY + cellHeight / 2 };
final Optional<Point2D> rx = ((GridBodyCellEditContext) context).getRelativeLocation();
rx.ifPresent(r -> {
dxy[0] = r.getX();
dxy[1] = r.getY();
});
cellEditorControls.show(editor, (int) (dxy[0]), (int) (dxy[1]));
}
Aggregations