This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rhbz953734 - draft view and presenter
- Loading branch information
Patrick Huang
committed
May 17, 2013
1 parent
6c1fb94
commit f006a67
Showing
9 changed files
with
351 additions
and
7 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
zanata-war/src/main/java/org/zanata/webtrans/client/presenter/ReviewPresenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package org.zanata.webtrans.client.presenter; | ||
|
||
import org.zanata.webtrans.client.rpc.AbstractAsyncCallback; | ||
import org.zanata.webtrans.client.rpc.CachingDispatchAsync; | ||
import org.zanata.webtrans.client.service.GetTransUnitActionContext; | ||
import org.zanata.webtrans.client.service.GetTransUnitActionContextHolder; | ||
import org.zanata.webtrans.client.view.ReviewDisplay; | ||
import org.zanata.webtrans.shared.rpc.GetTransUnitList; | ||
import org.zanata.webtrans.shared.rpc.GetTransUnitListResult; | ||
|
||
import com.google.gwt.view.client.SelectionChangeEvent; | ||
import com.google.inject.Inject; | ||
|
||
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> | ||
*/ | ||
public class ReviewPresenter extends WidgetPresenter<ReviewDisplay> implements ReviewDisplay.Listener, SelectionChangeEvent.Handler | ||
{ | ||
|
||
private final ReviewDisplay display; | ||
private final EventBus eventBus; | ||
private final ReviewTableSelectionModel selectionModel; | ||
private final ReviewTableDataProvider dataProvider; | ||
private final CachingDispatchAsync dispatcher; | ||
private final GetTransUnitActionContextHolder contextHolder; | ||
|
||
@Inject | ||
public ReviewPresenter(ReviewDisplay display, EventBus eventBus, ReviewTableSelectionModel selectionModel, ReviewTableDataProvider dataProvider, CachingDispatchAsync dispatcher, GetTransUnitActionContextHolder contextHolder) | ||
{ | ||
super(display, eventBus); | ||
this.display = display; | ||
this.eventBus = eventBus; | ||
this.selectionModel = selectionModel; | ||
this.dataProvider = dataProvider; | ||
this.dispatcher = dispatcher; | ||
this.contextHolder = contextHolder; | ||
|
||
init(); | ||
} | ||
|
||
private void init() | ||
{ | ||
display.setListener(this); | ||
selectionModel.addSelectionChangeHandler(this); | ||
display.setSelectionModel(selectionModel); | ||
display.setDataProvider(dataProvider); | ||
} | ||
|
||
@Override | ||
protected void onBind() | ||
{ | ||
GetTransUnitActionContext context = contextHolder.getContext(); | ||
GetTransUnitList getTransUnitList = GetTransUnitList.newAction(context.changeOffset(0).changeTargetTransUnitId(null).setAcceptAll()); | ||
|
||
dataProvider.setLoading(true); | ||
dispatcher.execute(getTransUnitList, new AbstractAsyncCallback<GetTransUnitListResult>() | ||
{ | ||
@Override | ||
public void onSuccess(GetTransUnitListResult result) | ||
{ | ||
dataProvider.setList(result.getUnits()); | ||
} | ||
}); | ||
dataProvider.setLoading(false); | ||
} | ||
|
||
@Override | ||
protected void onUnbind() | ||
{ | ||
//TODO implement | ||
throw new UnsupportedOperationException("Implement me!"); | ||
// | ||
} | ||
|
||
@Override | ||
protected void onRevealDisplay() | ||
{ | ||
|
||
} | ||
|
||
@Override | ||
public void onSelectionChange(SelectionChangeEvent event) | ||
{ | ||
//TODO implement | ||
throw new UnsupportedOperationException("Implement me!"); | ||
// | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
zanata-war/src/main/java/org/zanata/webtrans/client/presenter/ReviewTableDataProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.zanata.webtrans.client.presenter; | ||
|
||
import org.zanata.webtrans.shared.model.TransUnit; | ||
import org.zanata.webtrans.shared.model.TransUnitProvidesKey; | ||
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 ReviewTableDataProvider extends ListDataProvider<TransUnit> | ||
{ | ||
public ReviewTableDataProvider() | ||
{ | ||
super(TransUnitProvidesKey.KEY_PROVIDER); | ||
} | ||
|
||
public void setLoading(boolean loading) | ||
{ | ||
if (loading) | ||
{ | ||
updateRowCount(0, false); | ||
} | ||
else | ||
{ | ||
updateRowCount(getList().size(), true); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
zanata-war/src/main/java/org/zanata/webtrans/client/presenter/ReviewTableSelectionModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.zanata.webtrans.client.presenter; | ||
|
||
import org.zanata.webtrans.shared.model.TransUnit; | ||
import org.zanata.webtrans.shared.model.TransUnitProvidesKey; | ||
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 ReviewTableSelectionModel extends MultiSelectionModel<TransUnit> | ||
{ | ||
public ReviewTableSelectionModel() | ||
{ | ||
super(TransUnitProvidesKey.KEY_PROVIDER); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 0 additions & 6 deletions
6
zanata-war/src/main/java/org/zanata/webtrans/client/ui/TranslationHistoryDisplay.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
zanata-war/src/main/java/org/zanata/webtrans/client/view/ReviewDisplay.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.zanata.webtrans.client.view; | ||
|
||
import org.zanata.webtrans.shared.model.TransUnit; | ||
import com.google.gwt.view.client.ListDataProvider; | ||
import com.google.gwt.view.client.SelectionModel; | ||
import com.google.inject.ImplementedBy; | ||
|
||
import net.customware.gwt.presenter.client.widget.WidgetDisplay; | ||
|
||
@ImplementedBy(ReviewView.class) | ||
public interface ReviewDisplay extends WidgetDisplay | ||
{ | ||
void setSelectionModel(SelectionModel<TransUnit> multiSelectionModel); | ||
|
||
void setDataProvider(ListDataProvider<TransUnit> dataProvider); | ||
|
||
void setListener(Listener listener); | ||
|
||
interface Listener | ||
{ | ||
|
||
} | ||
} |
169 changes: 169 additions & 0 deletions
169
zanata-war/src/main/java/org/zanata/webtrans/client/view/ReviewView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
package org.zanata.webtrans.client.view; | ||
|
||
import java.util.List; | ||
|
||
import org.zanata.webtrans.client.resources.WebTransMessages; | ||
import org.zanata.webtrans.client.ui.CellTableResources; | ||
import org.zanata.webtrans.client.ui.TextContentsDisplay; | ||
import org.zanata.webtrans.shared.model.TransUnit; | ||
import org.zanata.webtrans.shared.model.TransUnitProvidesKey; | ||
import org.zanata.webtrans.shared.util.StringNotEmptyPredicate; | ||
import com.google.common.collect.Iterables; | ||
import com.google.gwt.cell.client.AbstractCell; | ||
import com.google.gwt.cell.client.Cell; | ||
import com.google.gwt.cell.client.CheckboxCell; | ||
import com.google.gwt.core.client.GWT; | ||
import com.google.gwt.dom.client.Style; | ||
import com.google.gwt.safehtml.shared.SafeHtml; | ||
import com.google.gwt.safehtml.shared.SafeHtmlBuilder; | ||
import com.google.gwt.uibinder.client.UiBinder; | ||
import com.google.gwt.uibinder.client.UiField; | ||
import com.google.gwt.user.cellview.client.CellTable; | ||
import com.google.gwt.user.cellview.client.Column; | ||
import com.google.gwt.user.cellview.client.SimplePager; | ||
import com.google.gwt.user.client.ui.Composite; | ||
import com.google.gwt.user.client.ui.Label; | ||
import com.google.gwt.user.client.ui.VerticalPanel; | ||
import com.google.gwt.view.client.DefaultSelectionEventManager; | ||
import com.google.gwt.view.client.ListDataProvider; | ||
import com.google.gwt.view.client.SelectionModel; | ||
|
||
public class ReviewView extends Composite implements ReviewDisplay | ||
{ | ||
private static final int PAGE_SIZE = 50; | ||
private static final CellTableResources CELL_TABLE_RESOURCES = GWT.create(CellTableResources.class); | ||
private static final AbstractCell<List<String>> STRING_LIST_CELL = new AbstractCell<List<String>>() | ||
{ | ||
@Override | ||
public void render(Context context, List<String> contents, SafeHtmlBuilder sb) | ||
{ | ||
Iterable<String> notEmptyContents = Iterables.filter(contents, StringNotEmptyPredicate.INSTANCE); | ||
SafeHtml safeHtml = TextContentsDisplay.asSyntaxHighlight(notEmptyContents).toSafeHtml(); | ||
sb.appendHtmlConstant(safeHtml.asString()); | ||
} | ||
}; | ||
|
||
private static ReviewViewUiBinder ourUiBinder = GWT.create(ReviewViewUiBinder.class); | ||
@UiField | ||
WebTransMessages messages; | ||
|
||
private final CellTable<TransUnit> table; | ||
private Listener listener; | ||
|
||
public ReviewView() | ||
{ | ||
VerticalPanel root = ourUiBinder.createAndBindUi(this); | ||
|
||
table = createTable(); | ||
SimplePager pager = new SimplePager(); | ||
pager.setDisplay(table); | ||
|
||
root.add(table); | ||
root.add(pager); | ||
} | ||
|
||
@Override | ||
public void setSelectionModel(SelectionModel<TransUnit> multiSelectionModel) | ||
{ | ||
table.setSelectionModel(multiSelectionModel, DefaultSelectionEventManager.<TransUnit>createCheckboxManager()); | ||
Column<TransUnit, Boolean> checkboxColumn = createCheckboxColumn(multiSelectionModel); | ||
table.insertColumn(0, checkboxColumn); | ||
table.setColumnWidth(checkboxColumn, 10, Style.Unit.PX); | ||
} | ||
|
||
@Override | ||
public void setDataProvider(ListDataProvider<TransUnit> dataProvider) | ||
{ | ||
dataProvider.addDataDisplay(table); | ||
} | ||
|
||
@Override | ||
public void setListener(Listener listener) | ||
{ | ||
this.listener = listener; | ||
} | ||
|
||
private CellTable<TransUnit> createTable() | ||
{ | ||
CellTable<TransUnit> transUnitTable = new CellTable<TransUnit>(PAGE_SIZE, CELL_TABLE_RESOURCES, TransUnitProvidesKey.KEY_PROVIDER); | ||
transUnitTable.setEmptyTableWidget(new Label(messages.noContent())); | ||
transUnitTable.setLoadingIndicator(new Label(messages.loading())); | ||
|
||
Column<TransUnit, List<String>> sourceColumn = createSourceColumn(); | ||
Column<TransUnit, List<String>> targetColumn = createTargetColumn(); | ||
// Column<TransUnit, String> modifiedByColumn = createModifiedByColumn(); | ||
// Column<TransHistoryItem, String> modifiedDateColumn = createModifiedDateColumn(); | ||
|
||
|
||
transUnitTable.addColumn(sourceColumn, messages.source()); | ||
transUnitTable.setColumnWidth(sourceColumn, 50, Style.Unit.PCT); | ||
|
||
transUnitTable.addColumn(targetColumn, messages.target()); | ||
transUnitTable.setColumnWidth(targetColumn, 50, Style.Unit.PCT); | ||
|
||
// transUnitTable.addColumn(modifiedByColumn, messages.modifiedBy()); | ||
// transUnitTable.setColumnWidth(modifiedByColumn, 10, Style.Unit.PCT); | ||
|
||
// transUnitTable.addColumn(modifiedDateColumn, messages.modifiedDate()); | ||
// transUnitTable.setColumnWidth(modifiedDateColumn, 20, Style.Unit.PCT); | ||
|
||
return transUnitTable; | ||
} | ||
|
||
private static Column<TransUnit, List<String>> createSourceColumn() | ||
{ | ||
return new Column<TransUnit, List<String>>(STRING_LIST_CELL) | ||
{ | ||
@Override | ||
public List<String> getValue(TransUnit transUnit) | ||
{ | ||
return transUnit.getSources(); | ||
} | ||
}; | ||
} | ||
|
||
private static Column<TransUnit, List<String>> createTargetColumn() | ||
{ | ||
return new Column<TransUnit, List<String>>(STRING_LIST_CELL) | ||
{ | ||
@Override | ||
public List<String> getValue(TransUnit transUnit) | ||
{ | ||
return transUnit.getTargets(); | ||
} | ||
|
||
@Override | ||
public String getCellStyleNames(Cell.Context context, TransUnit transUnit) | ||
{ | ||
//TODO do we need state decorator since we are working on approved strings only | ||
// String styleNames = Strings.nullToEmpty(super.getCellStyleNames(context, transUnit)); | ||
// if (transUnit.getStatus() == ContentState.Approved) | ||
// { | ||
// styleNames += " ApprovedStateDecoration"; | ||
// } | ||
// else if (transUnit.getStatus() == ContentState.NeedReview) | ||
// { | ||
// styleNames += " FuzzyStateDecoration"; | ||
// } | ||
// return styleNames; | ||
return null; | ||
} | ||
}; | ||
} | ||
|
||
private static Column<TransUnit, Boolean> createCheckboxColumn(final SelectionModel<TransUnit> selectionModel) | ||
{ | ||
return new Column<TransUnit, Boolean>(new CheckboxCell(true, false)) | ||
{ | ||
@Override | ||
public Boolean getValue(TransUnit object) { | ||
// Get the value from the selection model. | ||
return selectionModel.isSelected(object); | ||
} | ||
}; | ||
} | ||
|
||
interface ReviewViewUiBinder extends UiBinder<VerticalPanel, ReviewView> | ||
{ | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
zanata-war/src/main/java/org/zanata/webtrans/client/view/ReviewView.ui.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder' | ||
xmlns:g='urn:import:com.google.gwt.user.client.ui'> | ||
<ui:with field="messages" type="org.zanata.webtrans.client.resources.WebTransMessages"/> | ||
|
||
<g:VerticalPanel> | ||
|
||
</g:VerticalPanel> | ||
</ui:UiBinder> |