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

Commit

Permalink
Work in progress: implement transunid details and validation section …
Browse files Browse the repository at this point in the history
…only visible when selected
  • Loading branch information
Alex Eng committed Dec 14, 2011
1 parent c169060 commit d92b15f
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 82 deletions.
Expand Up @@ -35,10 +35,10 @@
import org.zanata.webtrans.client.ui.UserConfigConstants;
import org.zanata.webtrans.client.ui.ValidationMessagePanel;
import org.zanata.webtrans.shared.model.TransUnit;
import org.zanata.webtrans.shared.model.TransUnitId;

import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.event.dom.client.BlurEvent;
import com.google.gwt.event.dom.client.BlurHandler;
import com.google.gwt.event.dom.client.ClickEvent;
Expand All @@ -52,7 +52,7 @@
import com.google.gwt.gen2.table.client.CellEditor;
import com.google.gwt.gen2.table.override.client.HTMLTable;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
Expand Down Expand Up @@ -167,16 +167,27 @@ public void onClick(ClickEvent event)

private final EventBus eventBus;

/*
* The minimum height of the target editor
*/
// private static final int MIN_HEIGHT = 48;
private final int REFRESH_INTERVAL = 5000; // ms

private Timer runValidationTimer = new Timer()
{
@Override
public void run()
{
eventBus.fireEvent(new RunValidationEvent(cellValue.getId(), cellValue.getSource(), textArea.getText()));
}
};


/**
* Construct a new {@link InlineTargetCellEditor} with the specified images.
*/
public InlineTargetCellEditor(final NavigationMessages messages, CancelCallback<TransUnit> callback, EditRowCallback rowCallback, final EventBus eventBus)
{
runValidationTimer.scheduleRepeating(REFRESH_INTERVAL);
runValidationTimer.cancel();


final CheckKey checkKey = new CheckKeyImpl(CheckKeyImpl.Context.Edit);
// Wrap contents in a table

Expand Down Expand Up @@ -267,7 +278,7 @@ else if (checkKey.isCloseEditorKey(isEscKeyCloseEditor))
}
else if (checkKey.isUserTyping())
{
// Resize as user types
Log.info("user typing:" + textArea.getText());
autoSize();
}
}
Expand Down Expand Up @@ -338,8 +349,7 @@ public void onBlur(BlurEvent event)

verticalPanel.add(topLayoutPanel);

validationMessagePanel = new ValidationMessagePanel(true);
validationMessagePanel.setHeader(messages.validationMessageHeading());
validationMessagePanel = new ValidationMessagePanel(messages.validationMessageHeading(), true);

verticalPanel.add(validationMessagePanel);
verticalPanel.setCellVerticalAlignment(validationMessagePanel, HasVerticalAlignment.ALIGN_BOTTOM);
Expand Down Expand Up @@ -705,9 +715,4 @@ public void updateValidationMessagePanel(ValidationMessagePanel panel)
{
validationMessagePanel.setContent(panel.getErrors());
}

public void clearValidationMessagePanel()
{
validationMessagePanel.clear();
}
}
Expand Up @@ -22,7 +22,6 @@

import org.zanata.webtrans.client.resources.NavigationMessages;
import org.zanata.webtrans.client.ui.HighlightingLabel;
import org.zanata.webtrans.client.ui.TransUnitDetailsPanel;
import org.zanata.webtrans.shared.model.TransUnit;

import com.google.gwt.event.dom.client.ClickEvent;
Expand All @@ -32,61 +31,46 @@
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DisclosurePanel;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class SourcePanel extends Composite implements HasValue<TransUnit>, HasClickHandlers
{

private final VerticalPanel panel;
private final HorizontalPanel topPanel;
private final HorizontalPanel topRightPanel;
private final HorizontalPanel panel;
private final HorizontalPanel rightPanel;
private final Label sourceLabel;
private TransUnit value;
private final TransUnitDetailsPanel transUnitDetailsContent;

public SourcePanel(TransUnit value, TableResources resources, NavigationMessages messages)
{
this.value = value;
panel = new VerticalPanel();
panel = new HorizontalPanel();
panel.setSize("100%", "100%");

topPanel = new HorizontalPanel();
topPanel.setSize("100%", "100%");

initWidget(panel);
setStylePrimaryName("TableEditorSource");

topRightPanel = new HorizontalPanel();
topRightPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
topRightPanel.setSize("100%", "100%");
rightPanel = new HorizontalPanel();
rightPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
rightPanel.setSize("100%", "100%");

sourceLabel = new HighlightingLabel(value.getSource());
sourceLabel.setStylePrimaryName("TableEditorContent");
sourceLabel.setTitle(messages.sourceCommentLabel() + value.getSourceComment());

topPanel.add(sourceLabel);
topPanel.add(topRightPanel);

transUnitDetailsContent = new TransUnitDetailsPanel(value);
transUnitDetailsContent.setHeader(messages.transUnitDetailsHeading());

panel.add(topPanel);
panel.add(transUnitDetailsContent);
panel.setCellVerticalAlignment(transUnitDetailsContent, HasVerticalAlignment.ALIGN_BOTTOM);
panel.add(sourceLabel);
panel.add(rightPanel);
}



public void add(Widget w)
{
topRightPanel.add(w);
rightPanel.add(w);
}

public Label getLabel()
Expand Down
Expand Up @@ -21,7 +21,6 @@
package org.zanata.webtrans.client.editor.table;

import static org.zanata.webtrans.client.editor.table.TableConstants.MAX_PAGE_ROW;
import static org.zanata.webtrans.client.editor.table.TableConstants.PAGE_SIZE;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -147,6 +146,10 @@ public interface Display extends WidgetDisplay, HasPageNavigation
void updateValidationError(TransUnitId id, List<String> errors);

ValidationMessagePanel getValidationPanel(TransUnitId id);

void setTransUnitDetails(TransUnit selectedTransUnit);

void setValidationMessageVisible(TransUnitId id);
}

private DocumentId documentId;
Expand Down Expand Up @@ -279,6 +282,8 @@ public void onSelection(SelectionEvent<TransUnit> event)
{
if (event.getSelectedItem() != null)
{
display.setTransUnitDetails(event.getSelectedItem());
display.setValidationMessageVisible(event.getSelectedItem().getId());
selectTransUnit(event.getSelectedItem());
}
}
Expand Down
Expand Up @@ -30,6 +30,7 @@
import org.zanata.webtrans.client.events.CopySourceEvent;
import org.zanata.webtrans.client.resources.NavigationMessages;
import org.zanata.webtrans.client.ui.HighlightingLabel;
import org.zanata.webtrans.client.ui.TransUnitDetailsPanel;
import org.zanata.webtrans.client.ui.ValidationMessagePanel;
import org.zanata.webtrans.shared.model.TransUnit;
import org.zanata.webtrans.shared.model.TransUnitId;
Expand All @@ -44,9 +45,11 @@
import com.google.gwt.gen2.table.client.DefaultTableDefinition;
import com.google.gwt.gen2.table.client.RowRenderer;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

public class TableEditorTableDefinition extends DefaultTableDefinition<TransUnit>
Expand All @@ -61,6 +64,8 @@ public class TableEditorTableDefinition extends DefaultTableDefinition<TransUnit
private ArrayList<Image> copyButtons;
private boolean showingCopyButtons;
private EventBus eventBus;

private TransUnitDetailsPanel transUnitDetailsContent;

private final RowRenderer<TransUnit> rowRenderer = new RowRenderer<TransUnit>()
{
Expand Down Expand Up @@ -136,17 +141,21 @@ public void setCellValue(TransUnit rowValue, TransUnit cellValue)
}
};

private Map<TransUnitId, VerticalPanel> sourcePanelMap = new HashMap<TransUnitId, VerticalPanel>();

private final CellRenderer<TransUnit, TransUnit> sourceCellRenderer = new CellRenderer<TransUnit, TransUnit>()
{
@Override
public void renderRowValue(final TransUnit rowValue, ColumnDefinition<TransUnit, TransUnit> columnDef, AbstractCellView<TransUnit> view)
{
view.setStyleName("TableEditorCell TableEditorCell-Source");

VerticalPanel panel = new VerticalPanel();
panel.setSize("100%", "100%");

TableResources images = GWT.create(TableResources.class);
final Image copyButton = new Image(images.copySrcButton());
copyButton.setStyleName("gwt-Button");
// copyButton.setStyleName("gwt-Button-display-onhover");
copyButton.setTitle(messages.copySourcetoTarget());
copyButton.setVisible(showingCopyButtons);
copyButton.addClickHandler(new ClickHandler()
Expand Down Expand Up @@ -182,7 +191,11 @@ public void onClick(ClickEvent event)

sourcePanel.add(copyButton);
copyButtons.add(copyButton);
view.setWidget(sourcePanel);

panel.add(sourcePanel);
sourcePanelMap.put(rowValue.getId(), panel);

view.setWidget(panel);
}
};

Expand Down Expand Up @@ -212,7 +225,7 @@ public void setCellValue(TransUnit rowValue, TransUnit cellValue)

};

private Map<TransUnitId, ValidationMessagePanel> msgPanelMap = new HashMap<TransUnitId, ValidationMessagePanel>();
private Map<TransUnitId, ValidationMessagePanel> messagePanelMap = new HashMap<TransUnitId, ValidationMessagePanel>();

private final CellRenderer<TransUnit, TransUnit> targetCellRenderer = new CellRenderer<TransUnit, TransUnit>()
{
Expand Down Expand Up @@ -251,13 +264,14 @@ public void renderRowValue(TransUnit rowValue, ColumnDefinition<TransUnit, Trans
label.setTitle(messages.clickHere());
targetPanel.add(label);

ValidationMessagePanel msgPanel = msgPanelMap.get(rowValue.getId());
ValidationMessagePanel msgPanel = messagePanelMap.get(rowValue.getId());
if (msgPanel == null)
{
msgPanel = new ValidationMessagePanel(false);
msgPanel.setHeader(messages.validationMessageHeading());
msgPanel = new ValidationMessagePanel(messages.validationMessageHeading(), false);
}
msgPanelMap.put(rowValue.getId(), msgPanel);
msgPanel.setVisible(false);

messagePanelMap.put(rowValue.getId(), msgPanel);

targetPanel.add(msgPanel);

Expand All @@ -282,10 +296,6 @@ public TableEditorTableDefinition(final NavigationMessages messages, final Redir
this.messages = messages;
this.eventBus = eventBus;
setRowRenderer(rowRenderer);
// indicatorColumnDefinition.setMaximumColumnWidth(15);
// indicatorColumnDefinition.setPreferredColumnWidth(15);
// indicatorColumnDefinition.setMinimumColumnWidth(15);
// indicatorColumnDefinition.setCellRenderer(indicatorCellRenderer);
sourceColumnDefinition.setCellRenderer(sourceCellRenderer);
targetColumnDefinition.setCellRenderer(targetCellRenderer);
CancelCallback<TransUnit> cancelCallBack = new CancelCallback<TransUnit>()
Expand Down Expand Up @@ -360,6 +370,7 @@ public void gotoPrevNewRow()
};

this.targetCellEditor = new InlineTargetCellEditor(messages, cancelCallBack, transValueCallBack, eventBus);
this.transUnitDetailsContent = new TransUnitDetailsPanel(messages.transUnitDetailsHeading());
targetColumnDefinition.setCellEditor(targetCellEditor);
// See _INDEX consts above if modifying!
// addColumnDefinition(indicatorColumnDefinition);
Expand All @@ -375,28 +386,53 @@ public InlineTargetCellEditor getTargetCellEditor()
return targetCellEditor;
}


public void updateValidationMessage(TransUnitId id, List<String> errors)
{
ValidationMessagePanel messagePanel = msgPanelMap.get(id);
ValidationMessagePanel messagePanel = messagePanelMap.get(id);
if (messagePanel != null)
{
Log.info("Validation error: " + errors.toString());
messagePanel.setContent(errors);
msgPanelMap.put(id, messagePanel);
messagePanelMap.put(id, messagePanel);
}
}

public ValidationMessagePanel getValidationPanel(TransUnitId id)
public ValidationMessagePanel getValidationMessagePanel(TransUnitId id)
{
ValidationMessagePanel panel = msgPanelMap.get(id);
ValidationMessagePanel panel = messagePanelMap.get(id);

if (panel == null)
{
panel = new ValidationMessagePanel(false);
msgPanelMap.put(id, panel);
panel = new ValidationMessagePanel(messages.validationMessageHeading(), false);
messagePanelMap.put(id, panel);
}
return panel;
}

public void setValidationMessageVisible(TransUnitId id)
{
for (Map.Entry<TransUnitId, ValidationMessagePanel> entry : messagePanelMap.entrySet())
{
if (entry.getKey().equals(id))
{
entry.getValue().setVisible(true);
}
else
{
entry.getValue().setVisible(false);
}
}
}

public void setTransUnitDetails(TransUnit selectedTransUnit)
{
VerticalPanel sourcePanel = sourcePanelMap.get(selectedTransUnit.getId());
if (sourcePanel != null)
{
transUnitDetailsContent.setDetails(selectedTransUnit);
sourcePanel.add(transUnitDetailsContent);
sourcePanel.setCellVerticalAlignment(transUnitDetailsContent,HasVerticalAlignment.ALIGN_BOTTOM);
}
}

}
Expand Up @@ -269,6 +269,20 @@ public void updateValidationError(TransUnitId id, List<String> errors)
@Override
public ValidationMessagePanel getValidationPanel(TransUnitId id)
{
return this.tableDefinition.getValidationPanel(id);
return this.tableDefinition.getValidationMessagePanel(id);
}

@Override
public void setTransUnitDetails(TransUnit selectedTransUnit)
{
this.tableDefinition.setTransUnitDetails(selectedTransUnit);

}

@Override
public void setValidationMessageVisible(TransUnitId id)
{
this.tableDefinition.setValidationMessageVisible(id);

}
}

0 comments on commit d92b15f

Please sign in to comment.