Search in sources :

Example 1 with EntityItem

use of com.vaadin.addon.jpacontainer.EntityItem in project VaadinUtils by rlsutton1.

the class BaseCrudView method initButtons.

private void initButtons() {
    actionNewButton.addClickListener(new ClickEventLogged.ClickListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void clicked(ClickEvent event) {
            if (isDirty()) {
                Notification.show("You must Save or Discard your changes first", Type.ERROR_MESSAGE);
                return;
            }
            newClicked();
        }
    });
    actionApplyButton.addClickListener(new ClickEventLogged.ClickListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void clicked(ClickEvent event) {
            final Object entityId = entityTable.getValue();
            if (entityId != null) {
                @SuppressWarnings("unchecked") CrudAction<E> action = (CrudAction<E>) actionCombo.getValue();
                if (action != null) {
                    if (action.showPreparingDialog()) {
                        performActionWithWaitDialog(entityId, action);
                    } else {
                        performAction(entityId, action);
                    }
                } else {
                    Notification.show("Please select an Action first.");
                }
            } else {
                Notification.show("Please select record first.");
            }
        }

        private void performAction(final Object entityId, final CrudAction<E> action) {
            EntityItem<E> entity = container.getItem(entityId);
            if (interceptAction(action, entity)) {
                action.exec(BaseCrudView.this, entity);
            }
            container.commit();
            container.refreshItem(entity.getItemId());
        // actionCombo.select(actionCombo.getNullSelectionItemId());
        }

        private void performActionWithWaitDialog(final Object entityId, final CrudAction<E> action) {
            final ConfirmDialog pleaseWaitMessage = createPleaseWaitDialog();
            if (action != null) {
                // we have to delay, because if we try to close the window
                // before it's created - that won't work.
                final ScheduledExecutorService exec = Executors.newScheduledThreadPool(1);
                final EntityManagerRunnable runner = invokeAction(entityId, pleaseWaitMessage, action);
                exec.schedule(runner, 1, TimeUnit.SECONDS);
                exec.shutdown();
                UI.getCurrent().setPollInterval(500);
            }
        }

        private EntityManagerRunnable invokeAction(final Object entityId, final ConfirmDialog pleaseWaitMessage, final CrudAction<E> action) {
            final EntityManagerRunnable runner = new EntityManagerRunnable(new RunnableUI(UI.getCurrent()) {

                @Override
                protected void run(final UI ui) {
                    ui.access(new Runnable() {

                        @Override
                        public void run() {
                            try {
                                EntityItem<E> entity = container.getItem(entityId);
                                if (interceptAction(action, entity)) {
                                    action.exec(BaseCrudView.this, entity);
                                }
                                container.commit();
                                container.refreshItem(entity.getItemId());
                            // actionCombo.select(actionCombo.getNullSelectionItemId());
                            } finally {
                                pleaseWaitMessage.close();
                                ui.setPollInterval(-1);
                            }
                        }
                    });
                }
            });
            return runner;
        }

        private ConfirmDialog createPleaseWaitDialog() {
            final ConfirmDialog pleaseWaitMessage = ConfirmDialog.show(UI.getCurrent(), "Please wait...", new ConfirmDialog.Listener() {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClose(ConfirmDialog dialog) {
                }
            });
            pleaseWaitMessage.setClosable(false);
            pleaseWaitMessage.getCancelButton().setVisible(false);
            pleaseWaitMessage.getOkButton().setVisible(false);
            pleaseWaitMessage.setModal(true);
            pleaseWaitMessage.setCaption("Preparing Action");
            return pleaseWaitMessage;
        }
    });
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ClickListener(com.vaadin.ui.Button.ClickListener) ItemSetChangeListener(com.vaadin.data.Container.ItemSetChangeListener) ValueChangeListener(com.vaadin.data.Property.ValueChangeListener) TextChangeListener(com.vaadin.event.FieldEvents.TextChangeListener) ClickEventLogged(au.com.vaadinutils.listener.ClickEventLogged) ClickEvent(com.vaadin.ui.Button.ClickEvent) RunnableUI(au.com.vaadinutils.dao.RunnableUI) UI(com.vaadin.ui.UI) RunnableUI(au.com.vaadinutils.dao.RunnableUI) EntityManagerRunnable(au.com.vaadinutils.dao.EntityManagerRunnable) EntityManagerRunnable(au.com.vaadinutils.dao.EntityManagerRunnable) EntityItem(com.vaadin.addon.jpacontainer.EntityItem) ConfirmDialog(org.vaadin.dialogs.ConfirmDialog)

Example 2 with EntityItem

use of com.vaadin.addon.jpacontainer.EntityItem in project VaadinUtils by rlsutton1.

the class BaseCrudView method enableDragAndDropOrdering.

/**
 * allows the user to sort the items in the list via drag and drop
 *
 * @param ordinalField
 */
public void enableDragAndDropOrdering(final SingularAttribute<E, Long> ordinalField) {
    dragAndDropOrderingEnabled = true;
    this.ordinalField = ordinalField;
    container.sort(new Object[] { ordinalField.getName() }, new boolean[] { true });
    this.entityTable.setDragMode(TableDragMode.ROW);
    this.entityTable.setDropHandler(new DropHandler() {

        private static final long serialVersionUID = -6024948983201516170L;

        @Override
        public AcceptCriterion getAcceptCriterion() {
            return SourceIsTarget.get();
        }

        @SuppressWarnings("unchecked")
        @Override
        public void drop(DragAndDropEvent event) {
            if (isDirty()) {
                Notification.show("You must save first", Type.WARNING_MESSAGE);
                return;
            }
            Object draggedItemId = event.getTransferable().getData("itemId");
            EntityItem<E> dragged = container.getItem(draggedItemId);
            if (dragged != null) {
                EntityItemProperty draggedOrdinalProp = dragged.getItemProperty(ordinalField.getName());
                if (draggedOrdinalProp != null) {
                    AbstractSelectTargetDetails td = (AbstractSelectTargetDetails) event.getTargetDetails();
                    VerticalDropLocation dl = td.getDropLocation();
                    Object targetId = ((AbstractSelectTargetDetails) event.getTargetDetails()).getItemIdOver();
                    int idx = container.indexOfId(targetId);
                    if (dl == VerticalDropLocation.BOTTOM) {
                        // drop below so move the idx down one
                        idx++;
                    }
                    if (idx > -1) {
                        targetId = container.getIdByIndex(idx);
                    }
                    boolean added = false;
                    Long ctr = 1l;
                    for (Object id : container.getItemIds()) {
                        if (id.equals(targetId)) {
                            draggedOrdinalProp.setValue(ctr++);
                            added = true;
                        }
                        if (!id.equals(draggedItemId)) {
                            container.getItem(id).getItemProperty(ordinalField.getName()).setValue(ctr++);
                        }
                    }
                    if (!added) {
                        draggedOrdinalProp.setValue(ctr++);
                    }
                    container.commit();
                    if (dragAndDropListener != null) {
                        dragAndDropListener.dropped();
                    }
                    // to save.
                    try {
                        invokeTopLevelCrudSave();
                    } catch (Exception e) {
                        ErrorWindow.showErrorWindow(e);
                    }
                } else {
                    logger.error("draggedOrdinalProp is null");
                }
            } else {
                logger.error("dragged is null");
            }
        }
    });
}
Also used : AbstractSelectTargetDetails(com.vaadin.ui.AbstractSelect.AbstractSelectTargetDetails) VerticalDropLocation(com.vaadin.shared.ui.dd.VerticalDropLocation) DragAndDropEvent(com.vaadin.event.dd.DragAndDropEvent) EntityItemProperty(com.vaadin.addon.jpacontainer.EntityItemProperty) CommitException(com.vaadin.data.fieldgroup.FieldGroup.CommitException) EntityNotFoundException(javax.persistence.EntityNotFoundException) InvalidValueException(com.vaadin.data.Validator.InvalidValueException) ExecutionException(java.util.concurrent.ExecutionException) DropHandler(com.vaadin.event.dd.DropHandler) EntityItem(com.vaadin.addon.jpacontainer.EntityItem) AcceptCriterion(com.vaadin.event.dd.acceptcriteria.AcceptCriterion)

Example 3 with EntityItem

use of com.vaadin.addon.jpacontainer.EntityItem in project VaadinUtils by rlsutton1.

the class JasperReportScheduleLayout method getStatusColumnGenerator.

private ColumnGenerator getStatusColumnGenerator() {
    return new ColumnGenerator() {

        private static final long serialVersionUID = -1873561613938103218L;

        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            @SuppressWarnings("unchecked") EntityItem<ReportEmailScheduleEntity> item = (EntityItem<ReportEmailScheduleEntity>) source.getItem(itemId);
            ReportEmailScheduleEntity schedule = item.getEntity();
            final Label label = new Label("<font color='green'>Scheduled</font>");
            label.setContentMode(ContentMode.HTML);
            if (schedule.getReportLog() != null && schedule.getReportLog().length() > 0 && !schedule.getReportLog().equals(Scheduler.REPORT_SUCCESSFULLY_RUN)) {
                label.setValue("<font color='red'><b>Error</b></font>");
            } else {
                if (!schedule.isEnabled()) {
                    label.setValue("<font color='orange'><b>Disabled</b></font>");
                }
            }
            return label;
        }
    };
}
Also used : EntityTable(au.com.vaadinutils.crud.EntityTable) Table(com.vaadin.ui.Table) ColumnGenerator(com.vaadin.ui.Table.ColumnGenerator) ReportEmailScheduleEntity(au.com.vaadinutils.jasper.scheduler.entities.ReportEmailScheduleEntity) Label(com.vaadin.ui.Label) EntityItem(com.vaadin.addon.jpacontainer.EntityItem)

Aggregations

EntityItem (com.vaadin.addon.jpacontainer.EntityItem)3 EntityTable (au.com.vaadinutils.crud.EntityTable)1 EntityManagerRunnable (au.com.vaadinutils.dao.EntityManagerRunnable)1 RunnableUI (au.com.vaadinutils.dao.RunnableUI)1 ReportEmailScheduleEntity (au.com.vaadinutils.jasper.scheduler.entities.ReportEmailScheduleEntity)1 ClickEventLogged (au.com.vaadinutils.listener.ClickEventLogged)1 EntityItemProperty (com.vaadin.addon.jpacontainer.EntityItemProperty)1 ItemSetChangeListener (com.vaadin.data.Container.ItemSetChangeListener)1 ValueChangeListener (com.vaadin.data.Property.ValueChangeListener)1 InvalidValueException (com.vaadin.data.Validator.InvalidValueException)1 CommitException (com.vaadin.data.fieldgroup.FieldGroup.CommitException)1 TextChangeListener (com.vaadin.event.FieldEvents.TextChangeListener)1 DragAndDropEvent (com.vaadin.event.dd.DragAndDropEvent)1 DropHandler (com.vaadin.event.dd.DropHandler)1 AcceptCriterion (com.vaadin.event.dd.acceptcriteria.AcceptCriterion)1 VerticalDropLocation (com.vaadin.shared.ui.dd.VerticalDropLocation)1 AbstractSelectTargetDetails (com.vaadin.ui.AbstractSelect.AbstractSelectTargetDetails)1 ClickEvent (com.vaadin.ui.Button.ClickEvent)1 ClickListener (com.vaadin.ui.Button.ClickListener)1 Label (com.vaadin.ui.Label)1