Search in sources :

Example 1 with ITableCellPopupEvent

use of org.jowidgets.common.widgets.controller.ITableCellPopupEvent in project jo-client-platform by jo-source.

the class BeanTableBatchEditCommand method execute.

@Override
public void execute(final IExecutionContext executionContext) throws Exception {
    final ITableCellPopupEvent event = executionContext.getValue(IBeanTable.CELL_POPUP_EVENT_CONTEXT_KEY);
    final int rowIndex = event.getRowIndex();
    final Object currentValue = model.getValue(rowIndex, columnIndex);
    final IMaybe<Object> valueMaybe = getNewValue(executionContext, currentValue, model.getAttribute(columnIndex));
    if (valueMaybe.isNothing()) {
        return;
    }
    final Object value = valueMaybe.getValue();
    if (allData) {
        for (int i = 0; i < model.getSize(); i++) {
            final IBeanProxy<?> bean = model.getBean(i);
            if (bean != null && !bean.isDisposed() && !bean.isDummy() && !bean.isLastRowDummy()) {
                bean.setValue(propertyName, value);
            }
        }
    } else {
        final List<IBeanProxy<BEAN_TYPE>> selectedBeans = model.getSelectedBeans();
        for (final IBeanProxy<BEAN_TYPE> bean : selectedBeans) {
            if (bean != null && !bean.isDisposed() && !bean.isDummy() && !bean.isLastRowDummy()) {
                bean.setValue(propertyName, value);
            }
        }
    }
}
Also used : ITableCellPopupEvent(org.jowidgets.common.widgets.controller.ITableCellPopupEvent) IInputDialogBluePrint(org.jowidgets.api.widgets.blueprint.IInputDialogBluePrint) IBeanProxy(org.jowidgets.cap.ui.api.bean.IBeanProxy)

Example 2 with ITableCellPopupEvent

use of org.jowidgets.common.widgets.controller.ITableCellPopupEvent in project jo-client-platform by jo-source.

the class BeanTableSetToAllActionBuilder method build.

@Override
public ICommandAction build() {
    final ICommandAction result = super.build();
    table.addCellMenuListener(new IPopupMenuListener<ITableCellPopupEvent>() {

        @Override
        public void beforeMenuShow(final ITableCellPopupEvent event) {
            final int columnIndex = event.getColumnIndex();
            final int rowIndex = event.getRowIndex();
            final IBeanTableModel<?> model = table.getModel();
            final String entityLabelPlural = model.getEntityLabelPlural();
            final Object cellValue = model.getValue(rowIndex, columnIndex);
            final String cellText;
            if (cellValue != null) {
                cellText = StringUtils.truncateToLength(model.getTableModel().getCell(rowIndex, columnIndex).getText(), 30);
            } else {
                cellText = NOT_SET.get();
            }
            final IAttribute<Object> attribute = model.getAttribute(columnIndex);
            final String columnLabel = attribute.getLabel().get();
            final ArrayList<Integer> selection = model.getSelection();
            if (selection.size() > 1) {
                // set to selection
                result.setText(MessageReplacer.replace(SET_TO_SELECTION.get(), columnLabel, cellText, entityLabelPlural));
            } else if (selection.size() <= 1) {
                // set to all
                result.setText(MessageReplacer.replace(SET_TO_ALL.get(), columnLabel, cellText, entityLabelPlural));
            }
        }
    });
    return result;
}
Also used : ICommandAction(org.jowidgets.api.command.ICommandAction) IAttribute(org.jowidgets.cap.ui.api.attribute.IAttribute) ArrayList(java.util.ArrayList) ITableCellPopupEvent(org.jowidgets.common.widgets.controller.ITableCellPopupEvent) IBeanTableModel(org.jowidgets.cap.ui.api.table.IBeanTableModel)

Example 3 with ITableCellPopupEvent

use of org.jowidgets.common.widgets.controller.ITableCellPopupEvent in project jo-client-platform by jo-source.

the class BeanTableSetToAllCommand method execute.

@Override
public void execute(final IExecutionContext executionContext) throws Exception {
    final ITableCellPopupEvent event = executionContext.getValue(IBeanTable.CELL_POPUP_EVENT_CONTEXT_KEY);
    final int rowIndex = event.getRowIndex();
    final Object value = model.getValue(rowIndex, columnIndex);
    final List<IBeanProxy<BEAN_TYPE>> selectedBeans = model.getSelectedBeans();
    if (model.getSelectedBeans().size() > 1) {
        for (final IBeanProxy<BEAN_TYPE> bean : selectedBeans) {
            if (bean != null && !bean.isDisposed() && !bean.isDummy() && !bean.isLastRowDummy()) {
                bean.setValue(propertyName, value);
            }
        }
    } else {
        for (int i = 0; i < model.getSize(); i++) {
            final IBeanProxy<?> bean = model.getBean(i);
            if (bean != null && !bean.isDisposed() && !bean.isDummy() && !bean.isLastRowDummy()) {
                bean.setValue(propertyName, value);
            }
        }
    }
}
Also used : ITableCellPopupEvent(org.jowidgets.common.widgets.controller.ITableCellPopupEvent) IBeanProxy(org.jowidgets.cap.ui.api.bean.IBeanProxy)

Aggregations

ITableCellPopupEvent (org.jowidgets.common.widgets.controller.ITableCellPopupEvent)3 IBeanProxy (org.jowidgets.cap.ui.api.bean.IBeanProxy)2 ArrayList (java.util.ArrayList)1 ICommandAction (org.jowidgets.api.command.ICommandAction)1 IInputDialogBluePrint (org.jowidgets.api.widgets.blueprint.IInputDialogBluePrint)1 IAttribute (org.jowidgets.cap.ui.api.attribute.IAttribute)1 IBeanTableModel (org.jowidgets.cap.ui.api.table.IBeanTableModel)1