Package org.zanata.webtrans.client.events

Examples of org.zanata.webtrans.client.events.TransUnitSaveEvent


        protected boolean isSaving() {
            return isSaving;
        }

        public TransUnitSaveEvent toEvent() {
            return new TransUnitSaveEvent(newContents, status, id, verNumber,
                    oldContents);
        }
View Full Code Here


            validationWarning.center(display.getId(),
                    userWorkspaceContext.getSelectedDoc(), getNewTargets(),
                    errorMessages);
            return false;
        } else {
            eventBus.fireEvent(new TransUnitSaveEvent(getNewTargets(), status,
                    display.getId(), display.getVerNum(), display
                            .getCachedTargets()));
        }
        return true;
    }
View Full Code Here

    @Override
    public void rejectTranslation(TransUnitId id) {
        ensureRowSelection(id);
        if (display.getCachedState() != ContentState.Rejected) {
            TransUnitSaveEvent event =
                    new TransUnitSaveEvent(getNewTargets(),
                            ContentState.Rejected, display.getId(),
                            display.getVerNum(), display.getCachedTargets());
            eventBus.fireEvent(new CommentBeforeSaveEvent(event));
        }
    }
View Full Code Here

        performSave(idToSave);
    }

    private void performSave(TransUnitId idToSave) {
        TransUnitSaveEvent forSaving = queue.getNextPendingForSaving(idToSave);
        if (forSaving == null) {
            Log.info("no pending save for " + idToSave);
            return;
        }

        targetContentsPresenter.setEditingState(idToSave,
                TargetContentsDisplay.EditingState.SAVING);

        UpdateTransUnit updateTransUnit =
                new UpdateTransUnit(new TransUnitUpdateRequest(idToSave,
                        forSaving.getTargets(), forSaving.getAdjustedStatus(),
                        forSaving.getVerNum()),
                        TransUnitUpdated.UpdateType.WebEditorSave);
        Log.info("about to save translation: " + updateTransUnit);
        dispatcher.execute(
                updateTransUnit,
                new UpdateTransUnitCallback(forSaving, documentListPresenter
View Full Code Here

        queue = new SaveEventQueue();
    }

    private static TransUnitSaveEvent saveEvent(int id, int verNum,
            String newContent, String oldContent) {
        return new TransUnitSaveEvent(Lists.newArrayList(newContent),
                ContentState.NeedReview, new TransUnitId(id), verNum,
                Lists.newArrayList(oldContent));
    }
View Full Code Here

        return eventQueue.get(index).toEvent();
    }

    @Test
    public void testPush() throws Exception {
        TransUnitSaveEvent firstEvent = saveEvent(1, 0, "new", "old");
        queue.push(firstEvent);
        assertThat(queue.getEventQueue(), Matchers.hasSize(1));

        // pushing another event with same id and version should replace the old
        // pending one
        TransUnitSaveEvent anotherEvent = saveEvent(1, 0, "newer", "new");
        queue.push(anotherEvent);
        assertThat(queue.getEventQueue(), Matchers.hasSize(1));
        assertEventEquals(fromQueueAsEvent(queue.getEventQueue(), 0),
                anotherEvent);
        assertThat(queue.hasPending(), Matchers.is(true));

        // pushing another event but doesn't match previous one. It will get
        // discarded
        TransUnitSaveEvent invalidEvent =
                saveEvent(1, 0, "blah", "content don't match previous");
        queue.push(invalidEvent);
        assertThat(queue.getEventQueue(), Matchers.hasSize(1));
        assertEventEquals(fromQueueAsEvent(queue.getEventQueue(), 0),
                anotherEvent);
        assertThat(queue.hasPending(), Matchers.is(true));

        // pushing another event with different id will not conflict with other
        // pending one
        TransUnitSaveEvent differentId = saveEvent(2, 1, "different id", "hi");
        queue.push(differentId);
        assertThat(queue.getEventQueue(), Matchers.hasSize(2));
        assertEventEquals(fromQueueAsEvent(queue.getEventQueue(), 0),
                anotherEvent);
        assertEventEquals(fromQueueAsEvent(queue.getEventQueue(), 1),
View Full Code Here

                differentId);
    }

    @Test
    public void testGetNextPendingForSaving() throws Exception {
        TransUnitSaveEvent firstEvent = saveEvent(1, 0, "new", "old");
        queue.push(firstEvent);
        TransUnitSaveEvent next =
                queue.getNextPendingForSaving(firstEvent.getTransUnitId());
        assertEventEquals(firstEvent, next);
        assertThat(queue.getEventQueue().get(0).isSaving(), Matchers.is(true));
        assertThat(queue.isSaving(firstEvent.getTransUnitId()),
                Matchers.is(true));

        // pushing another event won't replace saving event
        TransUnitSaveEvent anotherSave = saveEvent(1, 0, "newer", "new");
        queue.push(anotherSave);
        assertThat(queue.getEventQueue(), Matchers.hasSize(2));
        assertThat(queue.isSaving(anotherSave.getTransUnitId()),
                Matchers.is(true));
    }
View Full Code Here

                Matchers.is(true));
    }

    @Test
    public void testRemoveSaved() throws Exception {
        TransUnitSaveEvent firstEvent = saveEvent(1, 0, "new", "old");
        queue.push(firstEvent);
        TransUnitSaveEvent goToSave =
                queue.getNextPendingForSaving(firstEvent.getTransUnitId());
        TransUnitSaveEvent pendingBeforeSave = saveEvent(1, 0, "newer", "new");
        queue.push(pendingBeforeSave);

        // after save success we remove saved event
        queue.removeSaved(goToSave, 1);
        assertThat(queue.getEventQueue(), Matchers.hasSize(1));
        TransUnitSaveEvent pendingEventAfterSave =
                queue.getEventQueue().get(0).toEvent();
        assertThat(pendingEventAfterSave.getStatus(),
                Matchers.equalTo(pendingBeforeSave.getStatus()));
        assertThat(pendingEventAfterSave.getTargets(),
                Matchers.equalTo(pendingBeforeSave.getTargets()));
        assertThat(pendingEventAfterSave.getOldContents(),
                Matchers.equalTo(pendingBeforeSave.getOldContents()));
        assertThat(pendingEventAfterSave.getTransUnitId(),
                Matchers.equalTo(pendingBeforeSave.getTransUnitId()));
        // version should be changed
        assertThat(pendingEventAfterSave.getVerNum(), Matchers.equalTo(1));
        assertThat(queue.hasPending(), Matchers.is(true));
    }
View Full Code Here

        assertThat(queue.hasPending(), Matchers.is(true));
    }

    @Test
    public void testRemoveAllPending() throws Exception {
        TransUnitSaveEvent saveEvent = saveEvent(1, 0, "new", "old");
        queue.push(saveEvent);

        queue.removeAllPending(saveEvent.getTransUnitId());

        assertThat(queue.getEventQueue(),
                Matchers.<SaveEventQueue.EventWrapper> empty());
        assertThat(queue.hasPending(), Matchers.is(false));
    }
View Full Code Here

        // When:
        presenter.saveAsFuzzy(selectedTU.getId());

        // Then:
        verify(eventBus, atLeastOnce()).fireEvent(eventCaptor.capture());
        TransUnitSaveEvent event =
                TestFixture.extractFromEvents(eventCaptor.getAllValues(),
                        TransUnitSaveEvent.class);

        assertThat(event.getTransUnitId(), equalTo(selectedTU.getId()));
        assertThat(event.getTargets(), Matchers.equalTo(NEW_TARGETS));
        assertThat(event.getStatus(), equalTo(ContentState.NeedReview));
    }
View Full Code Here

TOP

Related Classes of org.zanata.webtrans.client.events.TransUnitSaveEvent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.