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.
Work in progress: Plural support -Editor
- Loading branch information
1 parent
46a1808
commit 4b91d4f
Showing
5 changed files
with
239 additions
and
138 deletions.
There are no files selected for viewing
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
192 changes: 192 additions & 0 deletions
192
...ar/src/main/java/org/zanata/webtrans/client/editor/table/TargetEditorTableDefinition.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,192 @@ | ||
package org.zanata.webtrans.client.editor.table; | ||
|
||
import net.customware.gwt.presenter.client.EventBus; | ||
|
||
import org.zanata.webtrans.client.events.OpenEditorEvent; | ||
import org.zanata.webtrans.client.resources.NavigationMessages; | ||
import org.zanata.webtrans.client.ui.HighlightingLabel; | ||
import org.zanata.webtrans.shared.model.TransUnit; | ||
|
||
import com.google.gwt.dom.client.NativeEvent; | ||
import com.google.gwt.event.dom.client.MouseDownEvent; | ||
import com.google.gwt.event.dom.client.MouseDownHandler; | ||
import com.google.gwt.gen2.table.client.AbstractColumnDefinition; | ||
import com.google.gwt.gen2.table.client.CellRenderer; | ||
import com.google.gwt.gen2.table.client.ColumnDefinition; | ||
import com.google.gwt.gen2.table.client.DefaultTableDefinition; | ||
import com.google.gwt.user.client.Event; | ||
import com.google.gwt.user.client.ui.VerticalPanel; | ||
|
||
public class TargetEditorTableDefinition extends DefaultTableDefinition<TransUnit> | ||
{ | ||
private final EventBus eventBus; | ||
private final boolean isReadOnly; | ||
private final NavigationMessages messages; | ||
|
||
private String findMessage; | ||
private InlineTargetCellEditor targetCellEditor; | ||
|
||
public void setFindMessage(String findMessage) | ||
{ | ||
this.findMessage = findMessage; | ||
} | ||
|
||
private final AbstractColumnDefinition<TransUnit, TransUnit> targetColumnDefinition = new AbstractColumnDefinition<TransUnit, TransUnit>() | ||
{ | ||
@Override | ||
public TransUnit getCellValue(TransUnit rowValue) | ||
{ | ||
return rowValue; | ||
} | ||
|
||
@Override | ||
public void setCellValue(TransUnit rowValue, TransUnit cellValue) | ||
{ | ||
cellValue.setTargets(rowValue.getTargets()); | ||
} | ||
|
||
}; | ||
|
||
private final CellRenderer<TransUnit, TransUnit> targetCellRenderer = new CellRenderer<TransUnit, TransUnit>() | ||
{ | ||
@Override | ||
public void renderRowValue(TransUnit rowValue, ColumnDefinition<TransUnit, TransUnit> columnDef, final AbstractCellView<TransUnit> view) | ||
{ | ||
view.setStyleName("TableEditorCell TableEditorCell-Target"); | ||
final VerticalPanel targetPanel = new VerticalPanel(); | ||
targetPanel.addStyleName("TableEditorCell-Target-Table"); | ||
final HighlightingLabel label = new HighlightingLabel(); | ||
|
||
/** | ||
* if editor is opening, do not render target cell, otherwise editor | ||
* will be closed. targetCellEditor.isEditing not suitable since when | ||
* we click the save button, cellValue is not null. | ||
**/ | ||
if (targetCellEditor.isOpened() && targetCellEditor.getTargetCell().getId().equals(rowValue.getId())) | ||
{ | ||
return; | ||
} | ||
|
||
if (rowValue.getTargets().isEmpty() && !isReadOnly) | ||
{ | ||
label.setText(messages.clickHere()); | ||
label.setStylePrimaryName("TableEditorContent-Empty"); | ||
} | ||
else | ||
{ | ||
label.setText(rowValue.getTargets().get(view.getRowIndex())); | ||
label.setStylePrimaryName("TableEditorContent"); | ||
} | ||
|
||
if (findMessage != null && !findMessage.isEmpty()) | ||
{ | ||
label.highlightSearch(findMessage); | ||
} | ||
label.setTitle(messages.clickHere()); | ||
|
||
label.sinkEvents(Event.ONMOUSEDOWN); | ||
final int rowIndex = view.getRowIndex(); | ||
label.addMouseDownHandler(new MouseDownHandler() | ||
{ | ||
@Override | ||
public void onMouseDown(MouseDownEvent event) | ||
{ | ||
if (!isReadOnly && event.getNativeButton() == NativeEvent.BUTTON_LEFT) | ||
{ | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
eventBus.fireEvent(new OpenEditorEvent(rowIndex)); | ||
} | ||
} | ||
}); | ||
targetPanel.add(label); | ||
targetPanel.setWidth("100%"); | ||
view.setWidget(targetPanel); | ||
} | ||
}; | ||
|
||
public TargetEditorTableDefinition(final NavigationMessages messages, EventBus eventBus, final RedirectingCachedTableModel<TransUnit> tableModel, boolean isReadOnly) | ||
{ | ||
this.eventBus = eventBus; | ||
this.isReadOnly = isReadOnly; | ||
this.messages = messages; | ||
|
||
CancelCallback<TransUnit> cancelCallBack = new CancelCallback<TransUnit>() | ||
{ | ||
@Override | ||
public void onCancel(TransUnit cellValue) | ||
{ | ||
tableModel.onCancel(cellValue); | ||
} | ||
}; | ||
|
||
EditRowCallback transValueCallBack = new EditRowCallback() | ||
{ | ||
@Override | ||
public void gotoNextRow() | ||
{ | ||
tableModel.gotoNextRow(); | ||
} | ||
|
||
@Override | ||
public void gotoPrevRow() | ||
{ | ||
tableModel.gotoPrevRow(); | ||
} | ||
|
||
@Override | ||
public void gotoFirstRow() | ||
{ | ||
tableModel.gotoFirstRow(); | ||
} | ||
|
||
@Override | ||
public void gotoLastRow() | ||
{ | ||
tableModel.gotoLastRow(); | ||
} | ||
|
||
@Override | ||
public void gotoNextFuzzyNewRow() | ||
{ | ||
tableModel.gotoNextFuzzyNew(); | ||
} | ||
|
||
@Override | ||
public void gotoPrevFuzzyNewRow() | ||
{ | ||
tableModel.gotoPrevFuzzyNew(); | ||
} | ||
|
||
@Override | ||
public void gotoNextFuzzyRow() | ||
{ | ||
tableModel.gotoNextFuzzy(); | ||
} | ||
|
||
@Override | ||
public void gotoPrevFuzzyRow() | ||
{ | ||
tableModel.gotoPrevFuzzy(); | ||
} | ||
|
||
@Override | ||
public void gotoNextNewRow() | ||
{ | ||
tableModel.gotoNextNew(); | ||
} | ||
|
||
@Override | ||
public void gotoPrevNewRow() | ||
{ | ||
tableModel.gotoPrevNew(); | ||
} | ||
}; | ||
|
||
targetColumnDefinition.setCellRenderer(targetCellRenderer); | ||
this.targetCellEditor = new InlineTargetCellEditor(messages, cancelCallBack, transValueCallBack, eventBus, isReadOnly); | ||
targetColumnDefinition.setCellEditor(targetCellEditor); | ||
|
||
addColumnDefinition(targetColumnDefinition); | ||
} | ||
} |
Oops, something went wrong.