Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge branch 'release' into integration/master
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmason committed May 3, 2013
2 parents eb66993 + 0e46049 commit 07180e3
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 34 deletions.
Expand Up @@ -75,25 +75,29 @@ public SourceContentsPresenter(EventBus eventBus, Provider<SourceContentsDisplay
}

/**
* Select first source in the list when row is selected or reselect previous selected one
*
* Select first source in the list when row is selected or reselect previous
* selected one
*
*/
public void setSelectedSource(TransUnitId id)
{
currentTransUnitId = id;
Log.debug("source content selected id:" + id);

SourceContentsDisplay sourceContentsView = Iterables.find(displayList, new FindByTransUnitIdPredicate(id));
List<HasSelectableSource> sourcePanelList = sourceContentsView.getSourcePanelList();
Optional<HasSelectableSource> selectedSourceOptional = tryFindSelectedSourcePanel(sourcePanelList);
if (selectedSourceOptional.isPresent())
Optional<SourceContentsDisplay> sourceContentsView = findView(id);
if (sourceContentsView.isPresent())
{
selectedSourceOptional.get().clickSelf();
}
else
{
// by default select the first one
sourcePanelList.get(0).clickSelf();
List<HasSelectableSource> sourcePanelList = sourceContentsView.get().getSourcePanelList();
Optional<HasSelectableSource> selectedSource = tryFindSelectedSourcePanel(sourcePanelList);
if (selectedSource.isPresent())
{
selectedSource.get().clickSelf();
}
else
{
// by default select the first one
sourcePanelList.get(0).clickSelf();
}
}
}

Expand Down Expand Up @@ -159,7 +163,7 @@ public void onClick(ClickEvent event)
selectedSource.setSelected(true);

Log.debug("Selected source: " + selectedSource.getSource());
//TODO this is firing every time we click.
// TODO this is firing every time we click.
eventBus.fireEvent(RequestValidationEvent.EVENT);
}
}
Expand All @@ -182,15 +186,58 @@ public void onUserConfigChanged(UserConfigChangeEvent event)
{
for (SourceContentsDisplay sourceContentsDisplay : displayList)
{
sourceContentsDisplay.toggleTransUnitDetails(configHolder.getState().isShowOptionalTransUnitDetails());
sourceContentsDisplay.toggleTransUnitDetails(configHolder.getState().isShowOptionalTransUnitDetails());
}
}

@Override
public void onTransUnitUpdated(TransUnitUpdatedEvent event)
{
SourceContentsDisplay sourceContentsView = Iterables.find(displayList, new FindByTransUnitIdPredicate(event.getUpdateInfo().getTransUnit().getId()));
sourceContentsView.updateTransUnitDetails(event.getUpdateInfo().getTransUnit());
sourceContentsView.refresh();
Optional<SourceContentsDisplay> sourceContentsView = findView(event.getUpdateInfo().getTransUnit().getId());
if (sourceContentsView.isPresent())
{
sourceContentsView.get().updateTransUnitDetails(event.getUpdateInfo().getTransUnit());
sourceContentsView.get().refresh();
}
}

/**
* Find a source display for the given trans unit if it is present on the page.
*/
private Optional<SourceContentsDisplay> findView(TransUnitId id)
{
return Iterables.tryFind(displayList, new FindByTransUnitIdPredicate(id));
}

/**
* Get the source string for a trans unit on the current page. This will be
* the currently selected plural form if any is selected.
*
* @param id for the trans unit to check
* @return currently selected plural, or the first plural if none is
* selected. The value will be absent if the trans unit is not on the
* current page.
*/
public Optional<String> getSourceContent(TransUnitId id)
{
Optional<SourceContentsDisplay> view = findView(id);
if (view.isPresent())
{
List<HasSelectableSource> sourcePanelList = view.get().getSourcePanelList();
Optional<HasSelectableSource> selectedSourceOptional = tryFindSelectedSourcePanel(sourcePanelList);
if (selectedSourceOptional.isPresent())
{
return Optional.of(selectedSourceOptional.get().getSource());
}
else
{
// by default return the first one
return Optional.of(sourcePanelList.get(0).getSource());
}
}
else
{
return Optional.absent();
}
}
}
Expand Up @@ -237,21 +237,21 @@ public void onTransUnitEdit(TransUnitEditEvent event)
@Override
public void validate(ToggleEditor editor)
{
TransUnitId sourceId = sourceContentsPresenter.getCurrentTransUnitIdOrNull();
if (equal(sourceId, currentTransUnitId))
{
RunValidationEvent event = new RunValidationEvent(sourceContentsPresenter.getSelectedSource(), editor.getText(), false);
if (hasSelectedRow() && equal(display.getId(), sourceId))
{
event.addWidget(display);
}
if (equal(sourceId, editor.getId()))
TransUnitId transUnitId = editor.getId();
Optional<String> sourceContent = sourceContentsPresenter.getSourceContent(transUnitId);
if (sourceContent.isPresent())
{
RunValidationEvent event = new RunValidationEvent(sourceContent.get(), editor.getText(), false);
// widget that displays red outline
event.addWidget(editor);
// widget that displays warnings
Optional<TargetContentsDisplay> targetDisplay = findDisplayById(transUnitId);
if (targetDisplay.isPresent())
{
event.addWidget(editor);
event.addWidget(targetDisplay.get());
}
eventBus.fireEvent(event);
}

}

/**
Expand Down
Expand Up @@ -57,6 +57,8 @@
import org.zanata.webtrans.shared.model.TransUnit;
import org.zanata.webtrans.shared.model.TransUnitId;
import org.zanata.webtrans.shared.model.UserWorkspaceContext;

import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.gwt.event.shared.GwtEvent;
Expand Down Expand Up @@ -154,11 +156,9 @@ public void canValidate()
selectedTU = currentPageRows.get(0);
presenter.setStatesForTesting(selectedTU.getId(), 0, display);
when(display.getId()).thenReturn(selectedTU.getId());
when(editor.getIndex()).thenReturn(0);
when(editor.getId()).thenReturn(selectedTU.getId());
when(sourceContentPresenter.getCurrentTransUnitIdOrNull()).thenReturn(selectedTU.getId());
when(sourceContentPresenter.getSelectedSource()).thenReturn("source");
when(editor.getText()).thenReturn("target");
when(sourceContentPresenter.getSourceContent(selectedTU.getId())).thenReturn(Optional.of("source"));

presenter.validate(editor);

Expand Down Expand Up @@ -242,8 +242,10 @@ public void onRequestValidationWillFireRunValidationEvent()
selectedTU = currentPageRows.get(0);
presenter.setStatesForTesting(selectedTU.getId(), 0, display);
when(display.getId()).thenReturn(selectedTU.getId());
when(editor.getId()).thenReturn(selectedTU.getId());
when(display.getEditors()).thenReturn(Lists.newArrayList(editor));
when(sourceContentPresenter.getCurrentTransUnitIdOrNull()).thenReturn(selectedTU.getId());
when(sourceContentPresenter.getSourceContent(selectedTU.getId())).thenReturn(Optional.of("source"));
when(editor.getText()).thenReturn("target");

presenter.onRequestValidation(RequestValidationEvent.EVENT);
Expand Down Expand Up @@ -278,12 +280,12 @@ public void testOnInsertString()
{
// Given:
selectedTU = currentPageRows.get(0);
when(editor.getIndex()).thenReturn(0);
when(editor.getId()).thenReturn(selectedTU.getId());
when(display.getId()).thenReturn(selectedTU.getId());
when(display.getEditors()).thenReturn(Lists.newArrayList(editor));
when(tableEditorMessages.notifyCopied()).thenReturn("copied");
when(sourceContentPresenter.getSelectedSource()).thenReturn("source content");
when(sourceContentPresenter.getCurrentTransUnitIdOrNull()).thenReturn(selectedTU.getId());
when(sourceContentPresenter.getSourceContent(selectedTU.getId())).thenReturn(Optional.of("source content"));

presenter.setStatesForTesting(selectedTU.getId(), 0, display);

// When:
Expand Down Expand Up @@ -788,10 +790,12 @@ public void testShowEditorsInReadOnlyMode()
userWorkspaceContext.setProjectActive(false);
selectedTU = currentPageRows.get(0);
ArrayList<ToggleEditor> currentEditors = Lists.newArrayList(editor);
when(editor.getId()).thenReturn(selectedTU.getId());
ArrayList<ToggleEditor> previousEditors = Lists.newArrayList(editor2);
presenter.setStatesForTesting(null, 0, display);
when(display.getId()).thenReturn(selectedTU.getId());
when(display.getEditors()).thenReturn(previousEditors, currentEditors);
when(sourceContentPresenter.getSourceContent(selectedTU.getId())).thenReturn(Optional.of("source"));

// When:
presenter.setSelected(selectedTU.getId());
Expand Down

0 comments on commit 07180e3

Please sign in to comment.