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

Commit

Permalink
Implement 1 sec interval validation check
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Dec 14, 2011
1 parent d92b15f commit fc087b0
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 51 deletions.
Expand Up @@ -38,7 +38,6 @@

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 @@ -47,6 +46,8 @@
import com.google.gwt.event.dom.client.FocusHandler;
import com.google.gwt.event.dom.client.KeyDownEvent;
import com.google.gwt.event.dom.client.KeyDownHandler;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.gen2.table.client.CellEditor;
Expand Down Expand Up @@ -167,27 +168,11 @@ public void onClick(ClickEvent event)

private final EventBus eventBus;

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 @@ -229,6 +214,32 @@ public void onFocus(FocusEvent event)
}
});

final int DELAY_INTERVAL = 1000; // ms
final Timer runValidationTimer = new Timer()
{
@Override
public void run()
{
if (isEditing() && isOpened() && isFocused())
{
eventBus.fireEvent(new RunValidationEvent(cellValue.getId(), cellValue.getSource(), textArea.getText(), false));
}
}
};

textArea.addKeyUpHandler(new KeyUpHandler()
{
@Override
public void onKeyUp(KeyUpEvent event)
{
checkKey.init(event.getNativeEvent());
if (checkKey.isUserTyping())
{
runValidationTimer.schedule(DELAY_INTERVAL);
}
}
});

// KeyDown is used to override browser event
textArea.addKeyDownHandler(new KeyDownHandler()
{
Expand Down Expand Up @@ -278,7 +289,6 @@ else if (checkKey.isCloseEditorKey(isEscKeyCloseEditor))
}
else if (checkKey.isUserTyping())
{
Log.info("user typing:" + textArea.getText());
autoSize();
}
}
Expand Down
Expand Up @@ -47,6 +47,7 @@
import org.zanata.webtrans.client.events.NotificationEvent;
import org.zanata.webtrans.client.events.NotificationEvent.Severity;
import org.zanata.webtrans.client.events.RedoFailureEvent;
import org.zanata.webtrans.client.events.RunValidationEvent;
import org.zanata.webtrans.client.events.TransMemoryCopyEvent;
import org.zanata.webtrans.client.events.TransMemoryCopyHandler;
import org.zanata.webtrans.client.events.TransUnitEditEvent;
Expand Down Expand Up @@ -284,6 +285,7 @@ public void onSelection(SelectionEvent<TransUnit> event)
{
display.setTransUnitDetails(event.getSelectedItem());
display.setValidationMessageVisible(event.getSelectedItem().getId());
display.getTargetCellEditor().savePendingChange(true);
selectTransUnit(event.getSelectedItem());
}
}
Expand Down Expand Up @@ -336,6 +338,7 @@ public void onTransUnitUpdated(TransUnitUpdatedEvent event)
{
Log.info("selected TU updated; clear selection");
display.getTargetCellEditor().cancelEdit();
eventBus.fireEvent(new RunValidationEvent(event.getTransUnit().getId(), event.getTransUnit().getSource(), event.getTransUnit().getTarget()));
}

final Integer rowOffset = getRowOffset(event.getTransUnit().getId());
Expand Down
Expand Up @@ -49,7 +49,6 @@
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 @@ -60,7 +59,7 @@ public class TableEditorTableDefinition extends DefaultTableDefinition<TransUnit
public static final int TARGET_COL = 1;

private String findMessage;
private SourcePanel sourcePanel;
private SourcePanel topSourcePanel;
private ArrayList<Image> copyButtons;
private boolean showingCopyButtons;
private EventBus eventBus;
Expand Down Expand Up @@ -149,7 +148,6 @@ public void setCellValue(TransUnit rowValue, TransUnit cellValue)
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%");

Expand All @@ -169,14 +167,14 @@ public void onClick(ClickEvent event)

});

sourcePanel = new SourcePanel(rowValue, images, messages);
topSourcePanel = new SourcePanel(rowValue, images, messages);

if (findMessage != null && !findMessage.isEmpty())
{
sourcePanel.highlightSearch(findMessage);
topSourcePanel.highlightSearch(findMessage);
}
sourcePanel.getLabel().sinkEvents(Event.ONCLICK);
sourcePanel.getLabel().addClickHandler(new ClickHandler()
topSourcePanel.getLabel().sinkEvents(Event.ONCLICK);
topSourcePanel.getLabel().addClickHandler(new ClickHandler()
{
@Override
public void onClick(ClickEvent event)
Expand All @@ -189,10 +187,10 @@ public void onClick(ClickEvent event)

});

sourcePanel.add(copyButton);
topSourcePanel.add(copyButton);
copyButtons.add(copyButton);

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

view.setWidget(panel);
Expand Down
Expand Up @@ -48,6 +48,7 @@ public static Type<RunValidationEventHandler> getType()

private String source, target;
private TransUnitId id;
private boolean fireNotification = true;

public RunValidationEvent(TransUnitId id, String source, String target)
{
Expand All @@ -56,6 +57,14 @@ public RunValidationEvent(TransUnitId id, String source, String target)
this.target = target;
}

public RunValidationEvent(TransUnitId id, String source, String target, boolean fireNotification)
{
this.id = id;
this.source = source;
this.target = target;
this.fireNotification = fireNotification;
}

@Override
public Type<RunValidationEventHandler> getAssociatedType()
{
Expand Down Expand Up @@ -83,6 +92,11 @@ public TransUnitId getId()
{
return id;
}

public boolean isFireNotification()
{
return fireNotification;
}
}


Expand Down
Expand Up @@ -43,7 +43,7 @@ public class ValidationDetailsPresenter extends WidgetPresenter<ValidationDetail
{
public interface Display extends WidgetDisplay
{
void validate(TransUnitId id, String source, String target);
void validate(TransUnitId id, String source, String target, boolean fireNotification);

void clearAllMessage();
}
Expand Down Expand Up @@ -71,7 +71,7 @@ public void onTransUnitSelected(TransUnitSelectionEvent event)
@Override
public void onValidate(RunValidationEvent event)
{
display.validate(event.getId(), event.getSource(), event.getTarget());
display.validate(event.getId(), event.getSource(), event.getTarget(), event.isFireNotification());
}
}));

Expand Down
Expand Up @@ -22,12 +22,14 @@
}

.content {
height:100%;
}

.scrollSection {
border-bottom:1px solid #E0E8EE;
border-left:1px solid #E0E8EE;
border-right:1px solid #E0E8EE;
height:100%;
}


.tuDetailsLabel {
font-weight: bold;
Expand All @@ -47,10 +49,10 @@
<g:VerticalPanel styleName="{style.container}">
<g:Label ui:field="headerLabel" styleName="{style.header}"/>

<g:ScrollPanel>
<g:ScrollPanel styleName="{style.scrollSection}">
<g:LayoutPanel ui:field="contentPanel" styleName="{style.content}">
<g:layer width="100%">
<g:VerticalPanel width="100%" height="100%">
<g:VerticalPanel height="100%">
<g:HorizontalPanel>
<g:Label ui:field="resIdLabel" styleName="{style.tuDetailsLabel}" />
<g:Label ui:field="resId" styleName="{style.tuDetails}"/>
Expand Down
Expand Up @@ -27,6 +27,7 @@
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
Expand All @@ -51,7 +52,9 @@ interface Styles extends CssResource
Label headerLabel;

@UiField
VerticalPanel contentPanel;
FlowPanel contentPanel;

VerticalPanel contents;

@UiField
Styles style;
Expand All @@ -62,6 +65,7 @@ interface Styles extends CssResource

public ValidationMessagePanel(String header, boolean collapsible)
{
contents = new VerticalPanel();
initWidget(uiBinder.createAndBindUi(this));
setCollapsible(collapsible);
headerLabel.setText(header);
Expand All @@ -72,10 +76,13 @@ public void setContent(List<String> errors)
{
this.errors = errors;
contentPanel.clear();
contents.clear();

for (String error : errors)
{
contentPanel.add(new Label(error));
contents.add(new Label(error));
}
contentPanel.add(contents);
expand();
}

Expand All @@ -97,7 +104,7 @@ else if (contentPanel.isVisible())

public void expand()
{
if (contentPanel.getWidgetCount() > 0)
if (contents.getWidgetCount() > 0)
{
contentPanel.setHeight("95px");
contentPanel.setVisible(true);
Expand Down
Expand Up @@ -30,21 +30,23 @@
}

.content {
border-bottom:1px solid #E0E8EE;
border-left:1px solid #E0E8EE;
border-right:1px solid #E0E8EE;
height:100%;
color:#686868;
font-style:normal;
width:100%;
}

.scrollSection {
border-bottom:1px solid #E0E8EE;
border-left:1px solid #E0E8EE;
border-right:1px solid #E0E8EE;
}

</ui:style>

<g:VerticalPanel styleName="{style.container}">
<g:Label ui:field="headerLabel"/>
<g:ScrollPanel>
<g:VerticalPanel ui:field="contentPanel" styleName="{style.content}"/>
<g:ScrollPanel styleName="{style.scrollSection}">
<g:FlowPanel ui:field="contentPanel" styleName="{style.content}"/>
</g:ScrollPanel>

</g:VerticalPanel>
Expand Down
Expand Up @@ -65,7 +65,7 @@ public ValidationService(final EventBus eventBus, final TableEditorMessages mess
*
* @param tu
*/
public void execute(TransUnitId id, String source, String target)
public void execute(TransUnitId id, String source, String target, boolean fireNotification)
{
List<String> errors = new ArrayList<String>();

Expand All @@ -80,7 +80,7 @@ public void execute(TransUnitId id, String source, String target)
errors.addAll(action.getError());
}
}
fireErrorMessage(id, errors);
fireErrorMessage(id, errors, fireNotification);
}

/**
Expand Down Expand Up @@ -117,9 +117,9 @@ public void clearAllMessage()
}
}

public void fireErrorMessage(TransUnitId id, List<String> errors)
public void fireErrorMessage(TransUnitId id, List<String> errors, boolean fireNotification)
{
if (!errors.isEmpty())
if (!errors.isEmpty() && fireNotification)
{
eventBus.fireEvent(new NotificationEvent(Severity.Info, messages.notifyValidationError()));
}
Expand Down
Expand Up @@ -89,9 +89,9 @@ public Widget asWidget()
}

@Override
public void validate(TransUnitId id, String source, String target)
public void validate(TransUnitId id, String source, String target, boolean fireNotification)
{
validationService.execute(id, source, target);
validationService.execute(id, source, target, fireNotification);
}

@Override
Expand Down
Expand Up @@ -44,14 +44,14 @@ public HtmlXmlTagValidation(String id, String description)
@Override
public void validate(String source, String target)
{
Log.info("Source:" + source);
Log.info("target:" + target);
Log.debug("Source:" + source);
Log.debug("target:" + target);

MatchResult result = regExp.exec(source);
while (result != null)
{
String node = result.getGroup(0);
Log.info("Found Node:" + node);
Log.debug("Found Node:" + node);
if (!target.contains(node))
{
addError(getId() + ":" + node + " not found in target");
Expand Down

0 comments on commit fc087b0

Please sign in to comment.