Search in sources :

Example 36 with IBeanDto

use of org.jowidgets.cap.common.api.bean.IBeanDto in project jo-client-platform by jo-source.

the class BeanPasteCommand method doExecution.

private void doExecution() {
    final IBeanSelectionClipboard selectionClipboard = Clipboard.getData(IBeanSelectionClipboard.TRANSFER_TYPE);
    if (selectionClipboard != null) {
        for (final IBeanDto beanDto : selectionClipboard.getBeans()) {
            final IBeanProxy<BEAN_TYPE> transientBean = model.addTransientBean();
            for (final IAttribute<?> attribute : attributes) {
                final String propertyName = attribute.getPropertyName();
                if (!propertyName.equals(IBean.ID_PROPERTY) && !propertyName.equals(IBean.VERSION_PROPERTY) && !IBeanProxy.ALL_META_ATTRIBUTES.contains(propertyName)) {
                    transientBean.setValue(propertyName, beanDto.getValue(propertyName));
                }
            }
            final IBeanProxy<BEAN_TYPE> unmodifiedCopy = transientBean.createUnmodifiedCopy();
            model.removeBeans(Collections.singleton(transientBean));
            model.addBean(unmodifiedCopy);
        }
    }
}
Also used : IBeanSelectionClipboard(org.jowidgets.cap.ui.api.clipboard.IBeanSelectionClipboard) IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto)

Example 37 with IBeanDto

use of org.jowidgets.cap.common.api.bean.IBeanDto in project jo-client-platform by jo-source.

the class BeanDtoComparatorTest method testSortConverter.

@Test
public void testSortConverter() {
    final IBeanDto bean1 = createBeanDto(new Long(1), "2");
    final IBeanDto bean2 = createBeanDto(new Long(2), "12");
    final List<IBeanDto> beans = new ArrayList<IBeanDto>(2);
    beans.add(bean2);
    beans.add(bean1);
    Assert.assertSame(bean2, beans.get(0));
    Assert.assertSame(bean1, beans.get(1));
    Collections.sort(beans, createSortComparator(SORT_STRING_PROPERTY_ASC, STRING_PROPRTY_NAME, STRING_SORT_CONVERTER));
    Assert.assertSame(bean1, beans.get(0));
    Assert.assertSame(bean2, beans.get(1));
    Collections.sort(beans, createSortComparator(SORT_STRING_PROPERTY_DESC, STRING_PROPRTY_NAME, STRING_SORT_CONVERTER));
    Assert.assertSame(bean2, beans.get(0));
    Assert.assertSame(bean1, beans.get(1));
}
Also used : IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 38 with IBeanDto

use of org.jowidgets.cap.common.api.bean.IBeanDto in project jo-client-platform by jo-source.

the class ClipboardSelectionEnabledChecker method getEnabledState.

@Override
public IEnabledState getEnabledState() {
    final IBeanSelectionClipboard selection = Clipboard.getData(IBeanSelectionClipboard.TRANSFER_TYPE);
    if (selection != null) {
        final Collection<IBeanDto> beans = selection.getBeans();
        final Object selectedBeanTypeId = selection.getBeanTypeId();
        final Class<?> selectedBeanType = selection.getBeanType();
        if (beans != null && !beans.isEmpty() && NullCompatibleEquivalence.equals(expectedBeanTypeId, selectedBeanTypeId) && NullCompatibleEquivalence.equals(expectedBeanType, selectedBeanType)) {
            return EnabledState.ENABLED;
        }
    }
    return EnabledState.disabled(EMPTY_CLIPBOARD.get());
}
Also used : IBeanSelectionClipboard(org.jowidgets.cap.ui.api.clipboard.IBeanSelectionClipboard) IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto)

Example 39 with IBeanDto

use of org.jowidgets.cap.common.api.bean.IBeanDto in project jo-client-platform by jo-source.

the class CsvExportExecutor method execute.

@Override
public void execute(final IExecutionContext executionContext, final List<IBeanProxy<BEAN_TYPE>> beans, final ICsvExportParameter parameter) throws Exception {
    final IExecutionTask executionTask = CapUiToolkit.executionTaskFactory().create(executionContext);
    final IExecutionTaskDialog executionTaskDialog = createExecutionTaskDialog(executionContext, executionTask);
    final IResultCallback<String> resultCallback = new ResultCallback(executionTaskDialog);
    final Runnable exportRunnable;
    if (parameter.getExportType() == ExportType.SELECTION) {
        final List<IBeanDto> beanDtos = createBeanDtos(beans, model.getPropertyNames());
        exportRunnable = new CsvExportSelectedRunnable(model, resultCallback, parameter, beanDtos, executionTask);
    } else {
        final List<IBeanDto> addedData = createBeanDtos(model.getAddedData(), model.getPropertyNames());
        exportRunnable = new CsvExportTableRunnable(model, addedData, resultCallback, parameter, executionTask);
    }
    executionTaskDialog.setVisible(true);
    executor.execute(exportRunnable);
}
Also used : AbstractUiResultCallback(org.jowidgets.cap.ui.tools.execution.AbstractUiResultCallback) IResultCallback(org.jowidgets.cap.common.api.execution.IResultCallback) IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) IExecutionTaskDialog(org.jowidgets.cap.ui.api.widgets.IExecutionTaskDialog) IExecutionTask(org.jowidgets.cap.ui.api.execution.IExecutionTask)

Example 40 with IBeanDto

use of org.jowidgets.cap.common.api.bean.IBeanDto in project jo-client-platform by jo-source.

the class PasteLinkCommand method createResultCallback.

private IResultCallback<List<IBeanDto>> createResultCallback(final List<IBeanProxy<SOURCE_BEAN_TYPE>> selection, final IExecutionContext executionContext) {
    return new AbstractUiResultCallback<List<IBeanDto>>() {

        @Override
        protected void finishedUi(final List<IBeanDto> result) {
            for (final IBeanProxy<SOURCE_BEAN_TYPE> bean : selection) {
                bean.setExecutionTask(null);
            }
            if (linkedModel != null) {
                if (Cardinality.LESS_OR_EQUAL_ONE.equals(linkedCardinality)) {
                    linkedModel.removeAllBeans();
                }
                for (final IBeanDto resultBean : result) {
                    linkedModel.addBeanDto(resultBean);
                }
            }
            executionObservable.fireAfterExecutionSuccess(executionContext, result);
        }

        @Override
        protected void exceptionUi(final Throwable exception) {
            int beanIndex = 0;
            for (final IBeanProxy<SOURCE_BEAN_TYPE> bean : selection) {
                bean.setExecutionTask(null);
                if (!(exception instanceof ServiceCanceledException)) {
                    bean.addMessage(exceptionConverter.convert(getShortErrorMessage(), selection, beanIndex++, bean, exception));
                }
            }
            executionObservable.fireAfterExecutionError(executionContext, exception);
        }

        private String getShortErrorMessage() {
            final String actionText = executionContext.getAction().getText().replaceAll("\\.", "").trim();
            return MessageReplacer.replace(SHORT_ERROR.get(), actionText);
        }
    };
}
Also used : AbstractUiResultCallback(org.jowidgets.cap.ui.tools.execution.AbstractUiResultCallback) IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) LinkedList(java.util.LinkedList) List(java.util.List) ServiceCanceledException(org.jowidgets.cap.common.api.exception.ServiceCanceledException)

Aggregations

IBeanDto (org.jowidgets.cap.common.api.bean.IBeanDto)40 LinkedList (java.util.LinkedList)20 ArrayList (java.util.ArrayList)16 List (java.util.List)12 Test (org.junit.Test)12 IBeanKey (org.jowidgets.cap.common.api.bean.IBeanKey)8 IBeanProxy (org.jowidgets.cap.ui.api.bean.IBeanProxy)7 IBeanDtosUpdate (org.jowidgets.cap.common.api.bean.IBeanDtosUpdate)5 IExecutorService (org.jowidgets.cap.common.api.service.IExecutorService)5 BeanDtosInsertionUpdate (org.jowidgets.cap.common.tools.bean.BeanDtosInsertionUpdate)5 SyncResultCallback (org.jowidgets.cap.common.tools.execution.SyncResultCallback)5 IBeanData (org.jowidgets.cap.common.api.bean.IBeanData)4 BeanKey (org.jowidgets.cap.common.tools.bean.BeanKey)4 HashMap (java.util.HashMap)3 ISort (org.jowidgets.cap.common.api.sort.ISort)3 AbstractUiResultCallback (org.jowidgets.cap.ui.tools.execution.AbstractUiResultCallback)3 TableCellBluePrint (org.jowidgets.tools.model.table.TableCellBluePrint)3 ServiceCanceledException (org.jowidgets.cap.common.api.exception.ServiceCanceledException)2 BeanDtosChangeUpdate (org.jowidgets.cap.common.tools.bean.BeanDtosChangeUpdate)2 IBeanSelectionClipboard (org.jowidgets.cap.ui.api.clipboard.IBeanSelectionClipboard)2