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

Commit

Permalink
Make next/prev entry/fuzzy navigation based on selected row properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmason committed Sep 28, 2011
1 parent 93e991b commit d0ad941
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 56 deletions.
Expand Up @@ -3,11 +3,11 @@

public interface EditRowCallback
{
void gotoNextRow(int row);
void gotoNextRow();

void gotoPrevRow(int row);
void gotoPrevRow();

void gotoNextFuzzy(int row);
void gotoNextFuzzy();

void gotoPrevFuzzy(int row);
void gotoPrevFuzzy();
}
Expand Up @@ -324,23 +324,23 @@ public void gotoRow(NavigationType nav)
{
if (nav == NavigationType.NextEntry)
{
editRowCallback.gotoNextRow(curRow);
editRowCallback.gotoNextRow();
}
else if (nav == NavigationType.PrevEntry)
{
editRowCallback.gotoPrevRow(curRow);
editRowCallback.gotoPrevRow();
}
}

private void gotoFuzzyRow(NavigationType nav)
{
if (nav == NavigationType.NextEntry)
{
editRowCallback.gotoNextFuzzy(curRow);
editRowCallback.gotoNextFuzzy();
}
else if (nav == NavigationType.PrevEntry)
{
editRowCallback.gotoPrevFuzzy(curRow);
editRowCallback.gotoPrevFuzzy();
}
}

Expand Down
Expand Up @@ -26,28 +26,28 @@ public void onCancel(RowType cellValue)
tableModel.onCancel(cellValue);
}

public void gotoNextRow(int row)
public void gotoNextRow()
{
if (tableModel != null)
tableModel.gotoNextRow(row);
tableModel.gotoNextRow();
}

public void gotoPrevRow(int row)
public void gotoPrevRow()
{
if (tableModel != null)
tableModel.gotoPrevRow(row);
tableModel.gotoPrevRow();
}

public void gotoNextFuzzy(int row)
public void gotoNextFuzzy()
{
if (tableModel != null)
tableModel.gotoNextFuzzy(row);
tableModel.gotoNextFuzzy();
}

public void gotoPrevFuzzy(int row)
public void gotoPrevFuzzy()
{
if (tableModel != null)
tableModel.gotoPrevFuzzy(row);
tableModel.gotoPrevFuzzy();
}

public void setRowValueOverride(int row, RowType rowValue)
Expand Down
Expand Up @@ -67,27 +67,27 @@ public TableModelHandler<RowType> getTableModelHandler()
return tableModelHandler;
}

public void gotoNextRow(int row)
public void gotoNextRow()
{
if (tableModelHandler != null)
tableModelHandler.gotoNextRow(row);
tableModelHandler.gotoNextRow();
}

public void gotoPrevRow(int row)
public void gotoPrevRow()
{
if (tableModelHandler != null)
tableModelHandler.gotoPrevRow(row);
tableModelHandler.gotoPrevRow();
}

public void gotoNextFuzzy(int row)
public void gotoNextFuzzy()
{
if (tableModelHandler != null)
tableModelHandler.nextFuzzyIndex(row);
tableModelHandler.nextFuzzyIndex();
}

public void gotoPrevFuzzy(int row)
public void gotoPrevFuzzy()
{
if (tableModelHandler != null)
tableModelHandler.prevFuzzyIndex(row);
tableModelHandler.prevFuzzyIndex();
}
}
Expand Up @@ -116,6 +116,12 @@ public interface Display extends WidgetDisplay, HasPageNavigation

int getCurrentPageNumber();

/**
* @return The index of the 'selected' row on the currently displayed
* page, or 0 if no row is selected
*/
int getSelectedRowIndex();

TransUnit getTransUnitValue(int row);

InlineTargetCellEditor getTargetCellEditor();
Expand Down Expand Up @@ -143,10 +149,27 @@ public interface Display extends WidgetDisplay, HasPageNavigation
private final Identity identity;
private TransUnit selectedTransUnit;
// private int lastRowNum;

/**
* absolute positions in document
*/
private List<Long> transIdNextFuzzyCache = new ArrayList<Long>();

/**
* absolute positions in document
*/
private List<Long> transIdPrevFuzzyCache = new ArrayList<Long>();

/**
* the absolute row in the document. May not be the 'selected' row, call
* updatePageAndRow() to make it the selected row.
*/
private int curRowIndex;

/**
* the current page of the document. Call updatePageAndRow() to synchronize
* with the view table.
*/
private int curPage;

private String findMessage;
Expand Down Expand Up @@ -617,46 +640,40 @@ public void onCancel(TransUnit rowValue)
}

@Override
public void gotoNextRow(int row)
public void gotoNextRow()
{
curPage = display.getCurrentPage();
curRowIndex = curPage * TableConstants.PAGE_SIZE + row;
int rowIndex = curPage * TableConstants.PAGE_SIZE + row + 1;
if (rowIndex < display.getTableModel().getRowCount())
updatePageAndRow();
int newRowIndex = curRowIndex + 1;
if (newRowIndex < display.getTableModel().getRowCount())
{
gotoRow(rowIndex);
gotoRow(newRowIndex);
}
}

@Override
public void gotoPrevRow(int row)
public void gotoPrevRow()
{
curPage = display.getCurrentPage();
curRowIndex = curPage * TableConstants.PAGE_SIZE + row;
int rowIndex = curPage * TableConstants.PAGE_SIZE + row - 1;
if (rowIndex >= 0)
updatePageAndRow();
int newRowIndex = curRowIndex - 1;
if (newRowIndex >= 0)
{
gotoRow(rowIndex);
gotoRow(newRowIndex);
}
}

@Override
public void nextFuzzyIndex(int row)
public void nextFuzzyIndex()
{
// Convert row number to row Index in table
curPage = display.getCurrentPage();
curRowIndex = curPage * TableConstants.PAGE_SIZE + row;
updatePageAndRow();
Log.info("Current Row Index" + curRowIndex);
if (curRowIndex < display.getTableModel().getRowCount())
gotoNextState();
}

@Override
public void prevFuzzyIndex(int row)
public void prevFuzzyIndex()
{
// Convert row number to row Index in table
curPage = display.getCurrentPage();
curRowIndex = curPage * TableConstants.PAGE_SIZE + row;
updatePageAndRow();
Log.info("Current Row Index" + curRowIndex);
if (curRowIndex > 0)
gotoPrevState();
Expand All @@ -683,6 +700,17 @@ public void gotoRow(int rowIndex)
}
};

/**
* Updates page and row parameters from display.
*
* curRowIndex and curPage will be up-to-date after this call
*/
private void updatePageAndRow()
{
curPage = display.getCurrentPage();
curRowIndex = curPage * TableConstants.PAGE_SIZE + display.getSelectedRowIndex();
}

private void stopEditing(TransUnit rowValue)
{
dispatcher.execute(new EditingTranslationAction(rowValue.getId(), EditState.StopEditing), new AsyncCallback<EditingTranslationResult>()
Expand Down Expand Up @@ -717,6 +745,7 @@ public void onSuccess(GetTransUnitsNavigationResult result)
isReqComplete = true;
if (!result.getUnits().isEmpty())
{
updatePageAndRow();
for (Long offset : result.getUnits())
{
transIdNextFuzzyCache.add(offset + curRowIndex);
Expand Down Expand Up @@ -744,6 +773,7 @@ public void onSuccess(GetTransUnitsNavigationResult result)
isReqComplete = true;
if (!result.getUnits().isEmpty())
{
updatePageAndRow();
for (Long offset : result.getUnits())
{
transIdPrevFuzzyCache.add(curRowIndex - offset);
Expand All @@ -764,6 +794,9 @@ private void gotoPrevState()
{
Log.info("Previous FuzzyOrUntranslated State");

// make sure curRowIndex is up-to-date.
updatePageAndRow();

// Clean the cache for Next Fuzzy to avoid issues about cache is
// obsolete
transIdNextFuzzyCache.clear();
Expand Down Expand Up @@ -819,6 +852,9 @@ private void gotoNextState()
{
Log.info("go to Next FuzzyOrUntranslated State");

// make sure curRowIndex is up-to-date.
updatePageAndRow();

transIdPrevFuzzyCache.clear();
// If the cache of next fuzzy is empty, generate one
if (transIdNextFuzzyCache.isEmpty())
Expand Down
Expand Up @@ -262,27 +262,27 @@ public void onCancel(TransUnit cellValue)
EditRowCallback transValueCallBack = new EditRowCallback()
{
@Override
public void gotoNextRow(int row)
public void gotoNextRow()
{
tableModel.gotoNextRow(row);
tableModel.gotoNextRow();
}

@Override
public void gotoPrevRow(int row)
public void gotoPrevRow()
{
tableModel.gotoPrevRow(row);
tableModel.gotoPrevRow();
}

@Override
public void gotoNextFuzzy(int row)
public void gotoNextFuzzy()
{
tableModel.gotoNextFuzzy(row);
tableModel.gotoNextFuzzy();
}

@Override
public void gotoPrevFuzzy(int row)
public void gotoPrevFuzzy()
{
tableModel.gotoPrevFuzzy(row);
tableModel.gotoPrevFuzzy();
}
};

Expand Down
Expand Up @@ -21,6 +21,7 @@
package org.zanata.webtrans.client.editor.table;

import java.util.List;
import java.util.Set;

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

Expand Down Expand Up @@ -225,6 +226,20 @@ public int getCurrentPageNumber()
return getCurrentPage();
}

@Override
public int getSelectedRowIndex()
{
Set<Integer> selectedRows = super.getDataTable().getSelectedRows();
if (selectedRows.isEmpty())
{
return 0;
}
else
{
return selectedRows.iterator().next();
}
}

@Override
public TransUnit getTransUnitValue(int row)
{
Expand Down
Expand Up @@ -21,13 +21,13 @@ protected boolean onRowRemoved(int row)
return true;
}

abstract void gotoNextRow(int row);
abstract void gotoNextRow();

abstract void gotoPrevRow(int row);
abstract void gotoPrevRow();

abstract void nextFuzzyIndex(int row);
abstract void nextFuzzyIndex();

abstract void prevFuzzyIndex(int row);
abstract void prevFuzzyIndex();

abstract void gotoRow(int row);
}

0 comments on commit d0ad941

Please sign in to comment.