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

Commit

Permalink
Merge branch 'integration/master' of github.com:zanata/zanata into in…
Browse files Browse the repository at this point in the history
…tegration/master
  • Loading branch information
Alex Eng committed Oct 17, 2012
2 parents 38ce7e5 + 3d4d31a commit e5eae7f
Show file tree
Hide file tree
Showing 22 changed files with 181 additions and 129 deletions.
Expand Up @@ -23,10 +23,12 @@
import java.util.Collections;
import java.util.List;

import javax.annotation.Nullable;
import javax.inject.Provider;

import net.customware.gwt.presenter.client.EventBus;

import org.zanata.webtrans.client.events.TableRowSelectedEvent;
import org.zanata.webtrans.client.view.SourceContentsDisplay;
import org.zanata.webtrans.client.events.RequestValidationEvent;
import org.zanata.webtrans.client.ui.HasSelectableSource;
Expand All @@ -35,6 +37,9 @@
import org.zanata.webtrans.shared.util.FindByTransUnitIdPredicate;

import com.allen_sauer.gwt.log.client.Log;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.gwt.dom.client.Document;
Expand Down Expand Up @@ -74,8 +79,29 @@ public void setSelectedSource(TransUnitId id)
Log.debug("source content selected id:" + id);

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

private Optional<HasSelectableSource> tryFindSelectedSourcePanel(List<HasSelectableSource> sourcePanelList)
{
return Iterables.tryFind(sourcePanelList, new Predicate<HasSelectableSource>()
{
@Override
public boolean apply(HasSelectableSource input)
{
return input == selectedSource;
}
});
}

public String getSelectedSource()
Expand Down Expand Up @@ -117,6 +143,7 @@ public void onClick(ClickEvent event)
HasSelectableSource previousSource = selectedSource;

selectedSource = (HasSelectableSource) event.getSource();
ensureRowSelection(selectedSource.getId());

if (previousSource != null)
{
Expand All @@ -131,6 +158,14 @@ public void onClick(ClickEvent event)
}
}

private void ensureRowSelection(TransUnitId id)
{
if (!Objects.equal(id, currentTransUnitId))
{
eventBus.fireEvent(new TableRowSelectedEvent(id));
}
}

public TransUnitId getCurrentTransUnitIdOrNull()
{
return currentTransUnitId;
Expand Down
Expand Up @@ -55,6 +55,7 @@
import org.zanata.webtrans.shared.util.FindByTransUnitIdPredicate;
import com.allen_sauer.gwt.log.client.Log;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.gwt.core.client.GWT;
Expand Down Expand Up @@ -158,14 +159,14 @@ private ToggleEditor getCurrentEditor()
return currentEditors.get(currentEditorIndex);
}

public void showEditors(final TransUnitId currentTransUnitId)
public void setSelected(final TransUnitId currentTransUnitId)
{
this.currentTransUnitId = currentTransUnitId;

editorTranslators.clearTranslatorList(currentEditors); // clear previous selection's translator list

display = findDisplayById(currentTransUnitId);
Log.info("enter show editor with id:" + currentTransUnitId + " version: " + display.getVerNum());
display = findDisplayById(currentTransUnitId).get();
Log.info("selecting id:" + currentTransUnitId + " version: " + display.getVerNum());

currentEditors = display.getEditors();

Expand All @@ -191,17 +192,9 @@ public void showEditors(final TransUnitId currentTransUnitId)
}
}

private TargetContentsDisplay findDisplayById(TransUnitId currentTransUnitId)
private Optional<TargetContentsDisplay> findDisplayById(TransUnitId currentTransUnitId)
{
try
{
return Iterables.find(displayList, new FindByTransUnitIdPredicate(currentTransUnitId));
}
catch (NoSuchElementException e)
{
Log.error("cannot find display by id:" + currentTransUnitId + ". Page has changed?! returning null");
return null;
}
return Iterables.tryFind(displayList, new FindByTransUnitIdPredicate(currentTransUnitId));
}

private void normaliseCurrentEditorIndex()
Expand All @@ -218,7 +211,7 @@ private void normaliseCurrentEditorIndex()
}

@Override
public void onTransUnitEdit(final TransUnitEditEvent event)
public void onTransUnitEdit(TransUnitEditEvent event)
{
if (event.getSelectedTransUnit() != null)
{
Expand Down Expand Up @@ -309,11 +302,6 @@ public TransUnitId getCurrentTransUnitIdOrNull()
return currentTransUnitId;
}

public TransUnit getCachedValue()
{
return hasSelectedRow() ? display.getCachedValue() : null;
}

@Override
public boolean isDisplayButtons()
{
Expand All @@ -334,10 +322,10 @@ public void showHistory(TransUnitId transUnitId)
}

@Override
public void onFocus(TransUnitId id, int editorIndex)
public void onEditorClicked(TransUnitId id, int editorIndex)
{
ensureRowSelection(id);
currentEditorIndex = editorIndex;
ensureRowSelection(id);
}

@Override
Expand All @@ -359,16 +347,16 @@ private void ensureRowSelection(TransUnitId transUnitId)
{
if (!equal(currentTransUnitId, transUnitId))
{
//user click on buttons that is not on current selected row
//user click on editor area that is not on current selected row
eventBus.fireEvent(new TableRowSelectedEvent(transUnitId));
}
}

@Override
public void copySource(ToggleEditor editor, TransUnitId id)
{
ensureRowSelection(id);
currentEditorIndex = editor.getIndex();
ensureRowSelection(id);
editor.setTextAndValidate(sourceContentsPresenter.getSelectedSource());
editor.setFocus();

Expand Down Expand Up @@ -497,9 +485,10 @@ public void highlightSearch(String message)
*/
public void updateRow(TransUnit updatedTransUnit)
{
TargetContentsDisplay contentsDisplay = findDisplayById(updatedTransUnit.getId());
if (contentsDisplay != null)
Optional<TargetContentsDisplay> contentsDisplayOptional = findDisplayById(updatedTransUnit.getId());
if (contentsDisplayOptional.isPresent())
{
TargetContentsDisplay contentsDisplay = contentsDisplayOptional.get();
contentsDisplay.setValue(updatedTransUnit);
contentsDisplay.setState(TargetContentsDisplay.EditingState.SAVED);
}
Expand All @@ -512,9 +501,10 @@ public void updateRow(TransUnit updatedTransUnit)
*/
public void confirmSaved(TransUnit updatedTU)
{
TargetContentsDisplay contentsDisplay = findDisplayById(updatedTU.getId());
if (contentsDisplay != null)
Optional<TargetContentsDisplay> contentsDisplayOptional = findDisplayById(updatedTU.getId());
if (contentsDisplayOptional.isPresent())
{
TargetContentsDisplay contentsDisplay = contentsDisplayOptional.get();
contentsDisplay.updateCachedTargetsAndVersion(updatedTU.getTargets(), updatedTU.getVerNum(), updatedTU.getStatus());
setEditingState(updatedTU.getId(), TargetContentsDisplay.EditingState.SAVED);
}
Expand Down Expand Up @@ -571,17 +561,18 @@ else if (!userWorkspaceContext.hasReadOnlyAccess())
@Override
public void setEditingState(TransUnitId transUnitId, TargetContentsDisplay.EditingState editingState)
{
TargetContentsDisplay display = findDisplayById(transUnitId);
if (display != null && editingState != display.getEditingState())
Optional<TargetContentsDisplay> displayOptional = findDisplayById(transUnitId);
TargetContentsDisplay contentsDisplay = displayOptional.orNull();
if (contentsDisplay != null && editingState != contentsDisplay.getEditingState())
{
if (editingState != TargetContentsDisplay.EditingState.SAVED)
{
display.setState(editingState);
contentsDisplay.setState(editingState);
}
else if (Objects.equal(display.getCachedTargets(), display.getNewTargets()))
else if (Objects.equal(contentsDisplay.getCachedTargets(), contentsDisplay.getNewTargets()))
{
// we set editing state to SAVED only if cached targets and in editor targets are equal
display.setState(TargetContentsDisplay.EditingState.SAVED);
contentsDisplay.setState(TargetContentsDisplay.EditingState.SAVED);
}
}
}
Expand Down
Expand Up @@ -151,7 +151,7 @@ public void onTransUnitSelected(TransUnitSelectionEvent event)
selectedId = selection.getId();
Log.debug("selected id: " + selectedId);
sourceContentsPresenter.setSelectedSource(selectedId);
targetContentsPresenter.showEditors(selectedId);
targetContentsPresenter.setSelected(selectedId);
translatorService.transUnitSelected(selection);
}

Expand Down
Expand Up @@ -85,17 +85,17 @@ public void onSuccess(GetTranslationHistoryResult result)

protected void popupAndShowLoading(String title)
{

//here we CANNOT use listDataProvider.setList() because we need to retain the same list reference which is used by ColumnSortEvent.ListHandler
listDataProvider.getList().clear();
listDataProvider.setLoading(true);
selectionModel.clear();
display.setTitle(title);
display.resetView();
display.center();
}

protected void displayEntries(TransHistoryItem latest, List<TransHistoryItem> otherEntries)
{
//here we CANNOT use listDataProvider.setList() because we need to retain the same list reference which is used by ColumnSortEvent.ListHandler
listDataProvider.getList().clear();
if (latest != null)
{
//add indicator for latest version
Expand Down
Expand Up @@ -348,7 +348,7 @@ public interface WebTransMessages extends Messages
@DefaultMessage("User")
String modifiedBy();

@DefaultMessage("Modified Date")
@DefaultMessage("Date")
String modifiedDate();

@DefaultMessage("Paste into Editor")
Expand Down
14 changes: 4 additions & 10 deletions zanata-war/src/main/java/org/zanata/webtrans/client/ui/Editor.java
Expand Up @@ -10,7 +10,6 @@
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.BlurEvent;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.FocusEvent;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.resources.client.CssResource;
import com.google.gwt.uibinder.client.UiBinder;
Expand Down Expand Up @@ -50,9 +49,6 @@ interface Styles extends CssResource

private static EditorUiBinder uiBinder = GWT.create(EditorUiBinder.class);

private static final int TYPING_TIMER_INTERVAL = 500; // ms
private static final int TYPING_TIMER_RECURRENT_VALIDATION_PERIOD = 5; // intervals

private final int index;
private final TransUnitId id;

Expand Down Expand Up @@ -117,12 +113,11 @@ public void onValueChange(ValueChangeEvent<String> event)
listener.setEditingState(id, editingState);
}

@UiHandler("textArea")
public void onTextAreaFocus(FocusEvent event)
@UiHandler("rootContainer")
public void onEditorClick(ClickEvent event)
{
listener.onFocus(id, index);
listener.onEditorClicked(id, index);
fireValidationEvent();
isFocused = true;
}

@UiHandler("textArea")
Expand Down Expand Up @@ -186,6 +181,7 @@ public String getText()
@Override
public void setFocus()
{
isFocused = true;
textArea.setFocus(true);
}

Expand Down Expand Up @@ -230,12 +226,10 @@ public void updateValidationWarning(List<String> errors)
if (!errors.isEmpty())
{
targetWrapper.addStyleName(style.hasValidationError());
// addStyleName(style.hasValidationError());
}
else
{
targetWrapper.removeStyleName(style.hasValidationError());
// removeStyleName(style.hasValidationError());
}
}

Expand Down
@@ -1,8 +1,9 @@
package org.zanata.webtrans.client.ui;

import org.zanata.webtrans.shared.model.HasTransUnitId;
import com.google.gwt.event.dom.client.HasClickHandlers;

public interface HasSelectableSource extends HasClickHandlers
public interface HasSelectableSource extends HasClickHandlers, HasTransUnitId
{
String getSource();

Expand Down
Expand Up @@ -51,11 +51,11 @@ public void compare(TransHistoryItem itemOne, TransHistoryItem itemTwo)

grid.setText(ITEM_ONE_ROW, 0, itemOne.getVersionNum());
List<String> itemOneContents = itemOne.getContents();
itemOnePanel.setWidget(new InlineHTML(TranslationDisplay.asSyntaxHighlight(itemOneContents).toSafeHtml()));
itemOnePanel.setWidget(new InlineHTML(TextContentsDisplay.asSyntaxHighlight(itemOneContents).toSafeHtml()));

grid.setText(ITEM_TWO_ROW, 0, itemTwo.getVersionNum());
List<String> itemTwoContents = itemTwo.getContents();
itemTwoPanel.setWidget(new InlineHTML(TranslationDisplay.asDiff(itemOneContents, itemTwoContents).toSafeHtml()));
itemTwoPanel.setWidget(new InlineHTML(TextContentsDisplay.asDiff(itemOneContents, itemTwoContents).toSafeHtml()));
}

public void clear()
Expand Down
Expand Up @@ -226,7 +226,7 @@ private static Column<TransUnitReplaceInfo, List<String>> buildSourceColumn()
public void render(Context context, List<String> contents, SafeHtmlBuilder sb)
{
Iterable<String> notEmptyContents = Iterables.filter(contents, StringNotEmptyPredicate.INSTANCE);
SafeHtml safeHtml = TranslationDisplay.asSyntaxHighlightAndSearch(notEmptyContents, highlightString).toSafeHtml();
SafeHtml safeHtml = TextContentsDisplay.asSyntaxHighlightAndSearch(notEmptyContents, highlightString).toSafeHtml();
sb.appendHtmlConstant(safeHtml.asString());
}
})
Expand All @@ -252,12 +252,12 @@ public void render(Context context, TransUnitReplaceInfo info, SafeHtmlBuilder s
List<String> contents = info.getTransUnit().getTargets();
if (info.getPreviewState() == PreviewState.Show)
{
SafeHtml safeHtml = TranslationDisplay.asDiff(contents, info.getPreview().getContents()).toSafeHtml();
SafeHtml safeHtml = TextContentsDisplay.asDiff(contents, info.getPreview().getContents()).toSafeHtml();
sb.appendHtmlConstant(safeHtml.asString());
}
else
{
SafeHtml safeHtml = TranslationDisplay.asSyntaxHighlightAndSearch(contents, highlightString).toSafeHtml();
SafeHtml safeHtml = TextContentsDisplay.asSyntaxHighlightAndSearch(contents, highlightString).toSafeHtml();
sb.appendHtmlConstant(safeHtml.asString());
}
}
Expand Down

0 comments on commit e5eae7f

Please sign in to comment.