Permalink
Browse files

rhbz804871 - unit test and refactoring

  • Loading branch information...
1 parent 0c188a2 commit 1e3f0f8019e433f3b24563109b8a8a75545060af @huangp huangp committed Aug 14, 2012
@@ -62,7 +62,6 @@
import org.zanata.webtrans.client.service.UserSessionService;
import org.zanata.webtrans.client.ui.ToggleEditor;
import org.zanata.webtrans.client.ui.ToggleEditor.ViewMode;
-import org.zanata.webtrans.client.ui.TranslationHistoryDisplay;
import org.zanata.webtrans.client.ui.UndoLink;
import org.zanata.webtrans.client.ui.ValidationMessagePanelDisplay;
import org.zanata.webtrans.shared.auth.EditorClientId;
@@ -143,7 +142,7 @@ public TargetContentsPresenter(Provider<TargetContentsDisplay> displayProvider,
this.dispatcher = dispatcher;
this.keyShortcutPresenter = keyShortcutPresenter;
this.historyPresenter = historyPresenter;
- this.historyPresenter.addCurrentValueHolder(this);
+ this.historyPresenter.setCurrentValueHolder(this);
eventBus.addHandler(UserConfigChangeEvent.getType(), this);
eventBus.addHandler(RequestValidationEvent.getType(), this);
@@ -0,0 +1,19 @@
+package org.zanata.webtrans.client.presenter;
+
+import org.zanata.webtrans.client.ui.TranslationHistoryDisplay;
+import org.zanata.webtrans.shared.model.TransHistoryItem;
+
+import com.google.gwt.view.client.ListDataProvider;
+import com.google.inject.Singleton;
+
+/**
+ * @author Patrick Huang <a href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
+ */
+@Singleton
+public class TransHistoryDataProvider extends ListDataProvider<TransHistoryItem>
+{
+ public TransHistoryDataProvider()
+ {
+ super(TranslationHistoryDisplay.HISTORY_ITEM_PROVIDES_KEY);
+ }
+}
@@ -0,0 +1,18 @@
+package org.zanata.webtrans.client.presenter;
+
+import org.zanata.webtrans.client.ui.TranslationHistoryDisplay;
+import org.zanata.webtrans.shared.model.TransHistoryItem;
+import com.google.gwt.view.client.MultiSelectionModel;
+import com.google.inject.Singleton;
+
+/**
+ * @author Patrick Huang <a href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
+ */
+@Singleton
+public class TransHistorySelectionModel extends MultiSelectionModel<TransHistoryItem>
+{
+ public TransHistorySelectionModel()
+ {
+ super(TranslationHistoryDisplay.HISTORY_ITEM_PROVIDES_KEY);
+ }
+}
@@ -0,0 +1,57 @@
+package org.zanata.webtrans.client.presenter;
+
+import java.util.Comparator;
+
+import org.zanata.webtrans.shared.model.TransHistoryItem;
+
+/**
+* @author Patrick Huang <a href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
+*/
+public enum TransHistoryVersionComparator implements Comparator<TransHistoryItem>
+{
+ COMPARATOR;
+
+ @Override
+ public int compare(TransHistoryItem one, TransHistoryItem two)
+ {
+ if (itemIsOldVersion(one) && itemIsOldVersion(two))
+ {
+ Integer verOne = Integer.parseInt(one.getVersionNum());
+ Integer verTwo = Integer.parseInt(two.getVersionNum());
+ return verOne.compareTo(verTwo);
+ }
+ if (itemIsCurrentValue(one))
+ {
+ //first is current value
+ return 1;
+ }
+ if (itemIsLatestVersion(one) && itemIsCurrentValue(two))
+ {
+ //first is latest version but second is current value
+ return -1;
+ }
+ if (itemIsLatestVersion(one) && itemIsOldVersion(two))
+ {
+ return 1;
+ }
+ //else first is old/digit version and second is not
+ return -1;
+ }
+
+ private static boolean itemIsOldVersion(TransHistoryItem one)
+ {
+ return one.getVersionNum().matches("\\d+");
+ }
+
+ private static boolean itemIsLatestVersion(TransHistoryItem one)
+ {
+ //digit following non-digit characters
+ return one.getVersionNum().matches("\\d+\\D+");
+ }
+
+ private static boolean itemIsCurrentValue(TransHistoryItem one)
+ {
+ //anything except digit
+ return one.getVersionNum().matches("\\D+");
+ }
+}
@@ -1,10 +1,13 @@
package org.zanata.webtrans.client.presenter;
-import java.util.ArrayList;
+import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Set;
+import net.customware.gwt.presenter.client.EventBus;
+import net.customware.gwt.presenter.client.widget.WidgetPresenter;
+
import org.zanata.common.ContentState;
import org.zanata.webtrans.client.editor.table.TargetContentsPresenter;
import org.zanata.webtrans.client.events.NotificationEvent;
@@ -15,9 +18,9 @@
import org.zanata.webtrans.shared.model.TransUnitId;
import org.zanata.webtrans.shared.rpc.GetTranslationHistoryAction;
import org.zanata.webtrans.shared.rpc.GetTranslationHistoryResult;
+
import com.allen_sauer.gwt.log.client.Log;
import com.google.common.base.Objects;
-import com.google.common.collect.Lists;
import com.google.gwt.user.cellview.client.ColumnSortEvent;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.view.client.ListDataProvider;
@@ -26,9 +29,6 @@
import com.google.inject.Inject;
import com.google.inject.Singleton;
-import net.customware.gwt.presenter.client.EventBus;
-import net.customware.gwt.presenter.client.widget.WidgetPresenter;
-
/**
* @author Patrick Huang <a href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
*/
@@ -39,27 +39,28 @@
private final EventBus eventBus;
private final CachingDispatchAsync dispatcher;
private final WebTransMessages messages;
- private final ListDataProvider<TransHistoryItem> listDataProvider;
- private final MultiSelectionModel<TransHistoryItem> selectionModel;
+ private final TransHistoryDataProvider listDataProvider;
+ private final TransHistorySelectionModel selectionModel;
private TargetContentsPresenter targetContentsPresenter;
@Inject
- public TranslationHistoryPresenter(TranslationHistoryDisplay display, EventBus eventBus, CachingDispatchAsync dispatcher, WebTransMessages messages)
+ public TranslationHistoryPresenter(TranslationHistoryDisplay display, EventBus eventBus, CachingDispatchAsync dispatcher, WebTransMessages messages, TransHistorySelectionModel selectionModel, TransHistoryDataProvider dataProvider)
{
super(display, eventBus);
this.display = display;
this.eventBus = eventBus;
this.dispatcher = dispatcher;
this.messages = messages;
- listDataProvider = new ListDataProvider<TransHistoryItem>(TranslationHistoryDisplay.HISTORY_ITEM_PROVIDES_KEY);
- listDataProvider.addDataDisplay(display.getHistoryTable());
+ this.selectionModel = selectionModel;
+
+ listDataProvider = dataProvider;
+ this.display.setDataProvider(listDataProvider);
+
ColumnSortEvent.ListHandler<TransHistoryItem> sortHandler = new ColumnSortEvent.ListHandler<TransHistoryItem>(listDataProvider.getList());
- sortHandler.setComparator(display.getVersionColumn(), TransHistoryVersionComparator.COMPARATOR);
- display.addVersionSortHandler(sortHandler);
+ this.display.addVersionSortHandler(sortHandler);
- selectionModel = new MultiSelectionModel<TransHistoryItem>(TranslationHistoryDisplay.HISTORY_ITEM_PROVIDES_KEY);
- selectionModel.addSelectionChangeHandler(this);
- display.setSelectionModel(selectionModel);
+ this.selectionModel.addSelectionChangeHandler(this);
+ this.display.setSelectionModel(this.selectionModel);
}
public void showTranslationHistory(final TransUnitId transUnitId)
@@ -93,6 +94,8 @@ public void onSuccess(GetTranslationHistoryResult result)
listDataProvider.getList().add(latest);
}
listDataProvider.getList().addAll(result.getHistoryItems());
+ Comparator<TransHistoryItem> reverseComparator = Collections.reverseOrder(TransHistoryVersionComparator.COMPARATOR);
+ Collections.sort(listDataProvider.getList(), reverseComparator);
}
});
}
@@ -130,51 +133,9 @@ protected void onRevealDisplay()
{
}
- public void addCurrentValueHolder(TargetContentsPresenter targetContentsPresenter)
+ public void setCurrentValueHolder(TargetContentsPresenter targetContentsPresenter)
{
this.targetContentsPresenter = targetContentsPresenter;
}
- private static enum TransHistoryVersionComparator implements Comparator<TransHistoryItem>
- {
- COMPARATOR;
-
- @Override
- public int compare(TransHistoryItem one, TransHistoryItem two)
- {
- if (itemIsOldVersion(one) && itemIsOldVersion(two))
- {
- Integer verOne = Integer.parseInt(one.getVersionNum());
- Integer verTwo = Integer.parseInt(two.getVersionNum());
- return verOne.compareTo(verTwo);
- }
- if (itemIsCurrentValue(one))
- {
- //first is current value
- return 1;
- }
- if (itemIsLatestVersion(one) && itemIsCurrentValue(two))
- {
- //first is latest version but second is current value
- return -1;
- }
- //else first is old version and second is not old version
- return -1;
- }
-
- private static boolean itemIsOldVersion(TransHistoryItem one)
- {
- return one.getVersionNum().matches("\\d+");
- }
-
- private static boolean itemIsLatestVersion(TransHistoryItem one)
- {
- return one.getVersionNum().matches("\\d+\\w+");
- }
-
- private static boolean itemIsCurrentValue(TransHistoryItem one)
- {
- return one.getVersionNum().matches("\\w+");
- }
- }
}
@@ -97,8 +97,14 @@ public void onFlipButtonClick(ClickEvent event)
String historyEntry();
- String versionLabel();
-
String header();
+
+ String grid();
+
+ String contentCell();
+
+ String originRow();
+
+ String versionCell();
}
}
@@ -5,13 +5,18 @@
<ui:style field="style" type="org.zanata.webtrans.client.ui.HistoryEntryComparisonPanel.Styles">
.historyEntry {
- padding-left: 5px;
+ padding-left: 10px;
+ padding-bottom: 5px;
border-bottom: 1px dotted grey;
}
- .versionLabel {
+ .versionCell {
width: 15%;
- background-color: #d3d3d3;
+ padding-left: 10px;
+ }
+
+ .contentCell {
+ width: 85%;
padding-left: 10px;
}
@@ -23,13 +28,28 @@
color: #4B4A4A;
text-shadow: #DDF 1px 1px 0;
overflow: hidden;
+ font-weight: bold;
+ }
+
+ .grid {
+ border-collapse: collapse;
+ width: 100%;
+ height: 100%;
+ }
+
+ .originRow {
+ background-color: #EEE;
+ }
+
+ .flipButton {
+ padding: 5px;
}
</ui:style>
<g:ScrollPanel>
- <g:Grid width="100%" height="100%" ui:field="grid">
+ <g:Grid ui:field="grid" styleName="{style.grid}">
<g:row>
- <g:customCell>
+ <g:customCell styleName="{style.flipButton}">
<g:PushButton ui:field="flipButton" text="{messages.flipComparingEntries}"/>
</g:customCell>
<g:cell/>
@@ -38,15 +58,15 @@
<g:cell styleName="{style.header}">Version</g:cell>
<g:cell styleName="{style.header}">Contents</g:cell>
</g:row>
- <g:row>
- <g:cell styleName="{style.versionLabel}"/>
- <g:customCell>
+ <g:row styleName="{style.originRow}">
+ <g:cell styleName="{style.versionCell}"/>
+ <g:customCell styleName="{style.contentCell}">
<g:VerticalPanel ui:field="itemOnePanel" width="100%" />
</g:customCell>
</g:row>
<g:row>
- <g:cell styleName="{style.versionLabel}" />
- <g:customCell>
+ <g:cell styleName="{style.versionCell}" />
+ <g:customCell styleName="{style.contentCell}">
<g:VerticalPanel ui:field="itemTwoPanel" width="100%" />
</g:customCell>
</g:row>
@@ -7,6 +7,7 @@
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.cellview.client.ColumnSortEvent;
import com.google.gwt.view.client.HasData;
+import com.google.gwt.view.client.ListDataProvider;
import com.google.gwt.view.client.MultiSelectionModel;
import com.google.gwt.view.client.ProvidesKey;
import com.google.gwt.view.client.SelectionModel;
@@ -32,15 +33,13 @@ public Object getKey(TransHistoryItem item)
void resetView();
- HasData<TransHistoryItem> getHistoryTable();
-
void showDiff(TransHistoryItem one, TransHistoryItem two, String description);
void disableComparison();
void addVersionSortHandler(ColumnSortEvent.ListHandler<TransHistoryItem> sortHandler);
- Column<TransHistoryItem, String> getVersionColumn();
-
void setSelectionModel(SelectionModel<TransHistoryItem> multiSelectionModel);
+
+ void setDataProvider(ListDataProvider<TransHistoryItem> dataProvider);
}
Oops, something went wrong.

0 comments on commit 1e3f0f8

Please sign in to comment.