Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 5 commits
  • 19 files changed
  • 0 commit comments
  • 1 contributor
Showing with 409 additions and 317 deletions.
  1. +97 −28 server/zanata-war/src/main/java/org/zanata/webtrans/client/editor/table/InlineTargetCellEditor.java
  2. +6 −18 server/zanata-war/src/main/java/org/zanata/webtrans/client/editor/table/TableEditorPresenter.java
  3. +0 −55 server/zanata-war/src/main/java/org/zanata/webtrans/client/editor/table/TableEditorTableDefinition.java
  4. +0 −22 server/zanata-war/src/main/java/org/zanata/webtrans/client/editor/table/TableEditorView.java
  5. +69 −0 server/zanata-war/src/main/java/org/zanata/webtrans/client/events/RequestValidationEvent.java
  6. +2 −2 ...a/webtrans/client/events/{UpdateValidationErrorEventHandler.java → RequestValidationEventHandler.java}
  7. +7 −19 ...g/zanata/webtrans/client/events/{UpdateValidationErrorEvent.java → UpdateValidationWarningsEvent.java}
  8. +28 −0 server/zanata-war/src/main/java/org/zanata/webtrans/client/events/UpdateValidationWarningsEventHandler.java
  9. +23 −36 server/zanata-war/src/main/java/org/zanata/webtrans/client/presenter/ValidationOptionsPresenter.java
  10. +4 −2 server/zanata-war/src/main/java/org/zanata/webtrans/client/resources/NavigationMessages.java
  11. +20 −20 server/zanata-war/src/main/java/org/zanata/webtrans/client/resources/ValidationMessages.java
  12. +41 −6 server/zanata-war/src/main/java/org/zanata/webtrans/client/ui/ValidationMessagePanel.java
  13. +1 −1  server/zanata-war/src/main/java/org/zanata/webtrans/client/ui/ValidationMessagePanel.ui.xml
  14. +49 −9 server/zanata-war/src/main/java/org/zanata/webtrans/client/validation/ValidationService.java
  15. +9 −41 server/zanata-war/src/main/java/org/zanata/webtrans/client/view/ValidationOptionsView.java
  16. +19 −24 server/zanata-war/src/main/java/org/zanata/webtrans/shared/validation/action/HtmlXmlTagValidation.java
  17. +10 −14 server/zanata-war/src/main/java/org/zanata/webtrans/shared/validation/action/NewlineLeadTrailValidation.java
  18. +10 −2 server/zanata-war/src/main/java/org/zanata/webtrans/shared/validation/action/ValidationAction.java
  19. +14 −18 server/zanata-war/src/main/java/org/zanata/webtrans/shared/validation/action/VariablesValidation.java
View
125 ...ata-war/src/main/java/org/zanata/webtrans/client/editor/table/InlineTargetCellEditor.java
@@ -20,6 +20,7 @@
*/
package org.zanata.webtrans.client.editor.table;
+import java.util.List;
import java.util.Map;
import net.customware.gwt.presenter.client.EventBus;
@@ -29,8 +30,9 @@
import org.zanata.webtrans.client.editor.CheckKeyImpl;
import org.zanata.webtrans.client.events.EditTransUnitEvent;
import org.zanata.webtrans.client.events.NavTransUnitEvent.NavigationType;
+import org.zanata.webtrans.client.events.RequestValidationEvent;
+import org.zanata.webtrans.client.events.RequestValidationEventHandler;
import org.zanata.webtrans.client.events.RunValidationEvent;
-import org.zanata.webtrans.client.events.UpdateValidationErrorEvent;
import org.zanata.webtrans.client.resources.EditorConfigConstants;
import org.zanata.webtrans.client.resources.NavigationMessages;
import org.zanata.webtrans.client.ui.ValidationMessagePanel;
@@ -46,8 +48,6 @@
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;
@@ -166,6 +166,10 @@ public void onClick(ClickEvent event)
private PushButton saveButton, fuzzyButton, cancelButton, validateButton;
private ValidationMessagePanel validationMessagePanel;
+ private boolean keypressed;
+ private boolean typing;
+ private int typingCycles;
+
private final EventBus eventBus;
/**
@@ -176,18 +180,9 @@ public InlineTargetCellEditor(final NavigationMessages messages, CancelCallback<
final CheckKey checkKey = new CheckKeyImpl(CheckKeyImpl.Context.Edit);
// Wrap contents in a table
- final int REFRESH_INTERVAL = 1000; // ms
- final Timer runValidationTimer = new Timer()
- {
- @Override
- public void run()
- {
- if (isEditing() && isOpened())
- {
- eventBus.fireEvent(new RunValidationEvent(cellValue.getId(), cellValue.getSource(), textArea.getText(), false));
- }
- }
- };
+ final int TYPING_TIMER_INTERVAL = 200; // ms
+ final int TYPING_TIMER_RECURRENT_VALIDATION_PERIOD = 5; // intervals
+
verticalPanel = new VerticalPanel();
verticalPanel.setWidth("100%");
@@ -201,16 +196,65 @@ public void run()
editRowCallback = rowCallback;
textArea = new EditorTextArea();
textArea.setStyleName("TableEditorContent-Edit");
+
textArea.addValueChangeHandler(new ValueChangeHandler<String>()
{
@Override
public void onValueChange(ValueChangeEvent<String> event)
{
autoSize();
- runValidationTimer.schedule(REFRESH_INTERVAL);
+ fireValidationEvent(eventBus);
}
});
+
+ final Timer typingTimer = new Timer()
+ {
+ @Override
+ public void run()
+ {
+ if (keypressed)
+ {
+ // still typing, validate periodically
+ keypressed = false;
+ typingCycles++;
+ if (typingCycles % TYPING_TIMER_RECURRENT_VALIDATION_PERIOD == 0)
+ {
+ fireValidationEvent(eventBus);
+ }
+ }
+ else
+ {
+ // finished, validate immediately
+ this.cancel();
+ typing = false;
+ fireValidationEvent(eventBus);
+ }
+ }
+ };
+
+ // used to determine whether user is still typing
+ textArea.addKeyDownHandler(new KeyDownHandler()
+ {
+
+ @Override
+ public void onKeyDown(KeyDownEvent event)
+ {
+ if (typing)
+ {
+ keypressed = true;
+ }
+ else
+ {
+ // set false so that next keypress is detectable
+ keypressed = false;
+ typing = true;
+ typingCycles = 0;
+ typingTimer.scheduleRepeating(TYPING_TIMER_INTERVAL);
+ }
+ }
+ });
+
textArea.addBlurHandler(new BlurHandler()
{
@Override
@@ -228,21 +272,34 @@ public void onFocus(FocusEvent event)
}
});
-
-
- textArea.addKeyUpHandler(new KeyUpHandler()
+ eventBus.addHandler(RequestValidationEvent.getType(), new RequestValidationEventHandler()
{
+
@Override
- public void onKeyUp(KeyUpEvent event)
+ public void onRequestValidation(RequestValidationEvent event)
{
- checkKey.init(event.getNativeEvent());
- if (checkKey.isUserTyping())
+ if (isEditing())
{
- runValidationTimer.schedule(REFRESH_INTERVAL);
+ fireValidationEvent(eventBus);
}
}
});
+ // object creation is probably too much overhead for this, using simpler
+ // boolean implementation.
+ // textArea.addKeyUpHandler(new KeyUpHandler()
+ // {
+ // @Override
+ // public void onKeyUp(KeyUpEvent event)
+ // {
+ // checkKey.init(event.getNativeEvent());
+ // if (checkKey.isUserTyping())
+ // {
+ // runValidationTimer.schedule(REFRESH_INTERVAL);
+ // }
+ // }
+ // });
+
// KeyDown is used to override browser event
textArea.addKeyDownHandler(new KeyDownHandler()
{
@@ -315,7 +372,7 @@ public void onClick(ClickEvent event)
{
if (cellValue != null)
{
- eventBus.fireEvent(new RunValidationEvent(cellValue.getId(), cellValue.getSource(), textArea.getText()));
+ fireValidationEvent(eventBus);
}
}
});
@@ -362,7 +419,8 @@ public void onBlur(BlurEvent event)
verticalPanel.add(topLayoutPanel);
- validationMessagePanel = new ValidationMessagePanel(messages.validationMessageHeading(), true);
+ validationMessagePanel = new ValidationMessagePanel(true, messages);
+ validationMessagePanel.setVisiblePolicy(true);
verticalPanel.add(validationMessagePanel);
verticalPanel.setCellVerticalAlignment(validationMessagePanel, HasVerticalAlignment.ALIGN_BOTTOM);
@@ -507,7 +565,9 @@ public void editCell(CellEditInfo cellEditInfo, TransUnit cellValue, Callback<Tr
isOpened = true;
DOM.scrollIntoView(table.getCellFormatter().getElement(curRow, curCol));
- eventBus.fireEvent(new UpdateValidationErrorEvent(cellValue.getId(), true));
+ // hide until validation results are available
+ validationMessagePanel.setVisible(false);
+ fireValidationEvent(eventBus);
}
public void savePendingChange(boolean cancelIfUnchanged)
@@ -724,8 +784,17 @@ public TransUnit getTargetCell()
return cellValue;
}
- public void updateValidationMessagePanel(ValidationMessagePanel panel)
+ public void updateValidationMessagePanel(List<String> errors)
+ {
+ validationMessagePanel.setContent(errors);
+ validationMessagePanel.setVisible(true);
+ }
+
+ /**
+ * @param eventBus
+ */
+ private void fireValidationEvent(final EventBus eventBus)
{
- validationMessagePanel.setContent(panel.getErrors());
+ eventBus.fireEvent(new RunValidationEvent(cellValue.getId(), cellValue.getSource(), textArea.getText(), false));
}
}
View
24 ...anata-war/src/main/java/org/zanata/webtrans/client/editor/table/TableEditorPresenter.java
@@ -58,11 +58,10 @@
import org.zanata.webtrans.client.events.UndoAddEvent;
import org.zanata.webtrans.client.events.UndoFailureEvent;
import org.zanata.webtrans.client.events.UndoRedoFinishEvent;
-import org.zanata.webtrans.client.events.UpdateValidationErrorEvent;
-import org.zanata.webtrans.client.events.UpdateValidationErrorEventHandler;
+import org.zanata.webtrans.client.events.UpdateValidationWarningsEvent;
+import org.zanata.webtrans.client.events.UpdateValidationWarningsEventHandler;
import org.zanata.webtrans.client.resources.TableEditorMessages;
import org.zanata.webtrans.client.rpc.CachingDispatchAsync;
-import org.zanata.webtrans.client.ui.ValidationMessagePanel;
import org.zanata.webtrans.shared.auth.AuthenticationError;
import org.zanata.webtrans.shared.auth.AuthorizationError;
import org.zanata.webtrans.shared.auth.Identity;
@@ -142,13 +141,7 @@
*/
int getSelectedRowNumber();
- void updateValidationError(TransUnitId id, List<String> errors);
-
- ValidationMessagePanel getValidationPanel(TransUnitId id);
-
void setTransUnitDetails(TransUnit selectedTransUnit);
-
- void setValidationMessageVisible(TransUnitId id);
}
private DocumentId documentId;
@@ -282,7 +275,6 @@ public void onSelection(SelectionEvent<TransUnit> event)
if (event.getSelectedItem() != null)
{
display.setTransUnitDetails(event.getSelectedItem());
- display.setValidationMessageVisible(event.getSelectedItem().getId());
display.getTargetCellEditor().savePendingChange(true);
selectTransUnit(event.getSelectedItem());
}
@@ -404,7 +396,7 @@ public void onNavTransUnit(NavTransUnitEvent event)
{
if (selectedTransUnit != null)
{
- int step = event.getStep();
+ // int step = event.getStep();
// Send message to server to stop editing current selection
// stopEditing(selectedTransUnit);
@@ -488,16 +480,12 @@ public void onButtonDisplayChange(ButtonDisplayChangeEvent event)
}
}));
- registerHandler(eventBus.addHandler(UpdateValidationErrorEvent.getType(), new UpdateValidationErrorEventHandler()
+ registerHandler(eventBus.addHandler(UpdateValidationWarningsEvent.getType(), new UpdateValidationWarningsEventHandler()
{
@Override
- public void onUpdate(UpdateValidationErrorEvent event)
+ public void onUpdate(UpdateValidationWarningsEvent event)
{
- if (!event.isUpdateEditorOnly())
- {
- display.updateValidationError(event.getId(), event.getErrors());
- }
- display.getTargetCellEditor().updateValidationMessagePanel(display.getValidationPanel(event.getId()));
+ display.getTargetCellEditor().updateValidationMessagePanel(event.getErrors());
}
}));
View
55 ...war/src/main/java/org/zanata/webtrans/client/editor/table/TableEditorTableDefinition.java
@@ -22,7 +22,6 @@
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import net.customware.gwt.presenter.client.EventBus;
@@ -31,11 +30,9 @@
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;
-import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
@@ -224,8 +221,6 @@ public void setCellValue(TransUnit rowValue, TransUnit cellValue)
};
- private Map<TransUnitId, ValidationMessagePanel> messagePanelMap = new HashMap<TransUnitId, ValidationMessagePanel>();
-
private final CellRenderer<TransUnit, TransUnit> targetCellRenderer = new CellRenderer<TransUnit, TransUnit>()
{
@Override
@@ -264,18 +259,6 @@ public void renderRowValue(TransUnit rowValue, ColumnDefinition<TransUnit, Trans
label.setTitle(messages.clickHere());
targetPanel.add(label);
- ValidationMessagePanel msgPanel = messagePanelMap.get(rowValue.getId());
- if (msgPanel == null)
- {
- msgPanel = new ValidationMessagePanel(messages.validationMessageHeading(), false);
- }
- msgPanel.setVisible(false);
-
- messagePanelMap.put(rowValue.getId(), msgPanel);
-
- targetPanel.add(msgPanel);
-
- targetPanel.setCellVerticalAlignment(msgPanel, HasVerticalAlignment.ALIGN_BOTTOM);
targetPanel.setSize("100%", "100%");
view.setWidget(targetPanel);
@@ -391,44 +374,6 @@ public InlineTargetCellEditor getTargetCellEditor()
return targetCellEditor;
}
- public void updateValidationMessage(TransUnitId id, List<String> errors)
- {
- ValidationMessagePanel messagePanel = messagePanelMap.get(id);
- if (messagePanel != null)
- {
- Log.info("Validation error: " + errors.toString());
- messagePanel.setContent(errors);
- messagePanelMap.put(id, messagePanel);
- }
- }
-
- public ValidationMessagePanel getValidationMessagePanel(TransUnitId id)
- {
- ValidationMessagePanel panel = messagePanelMap.get(id);
-
- if (panel == null)
- {
- 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());
View
22 server/zanata-war/src/main/java/org/zanata/webtrans/client/editor/table/TableEditorView.java
@@ -29,13 +29,10 @@
import org.zanata.webtrans.client.resources.NavigationMessages;
import org.zanata.webtrans.client.resources.Resources;
import org.zanata.webtrans.client.ui.LoadingPanel;
-import org.zanata.webtrans.client.ui.ValidationMessagePanel;
import org.zanata.webtrans.shared.auth.Identity;
import org.zanata.webtrans.shared.auth.Permission;
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.event.logical.shared.HasSelectionHandlers;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
@@ -256,28 +253,9 @@ public void setShowCopyButtons(boolean showButtons)
}
@Override
- public void updateValidationError(TransUnitId id, List<String> errors)
- {
- this.tableDefinition.updateValidationMessage(id, errors);
- }
-
- @Override
- public ValidationMessagePanel getValidationPanel(TransUnitId 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);
-
- }
}
View
69 ...er/zanata-war/src/main/java/org/zanata/webtrans/client/events/RequestValidationEvent.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2011, Red Hat, Inc. and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.zanata.webtrans.client.events;
+
+import com.google.gwt.event.shared.GwtEvent;
+
+/**
+ * Fired to trigger a new validation event from an object that does not have
+ * access to appropriate details to generate a {@link RunValidationEvent}.
+ *
+ * @author David Mason <a
+ * href="mailto:damason@redhat.com">damason@redhat.com</a>
+ *
+ **/
+public class RequestValidationEvent extends GwtEvent<RequestValidationEventHandler>
+{
+ /**
+ * Handler type.
+ */
+ private static Type<RequestValidationEventHandler> TYPE;
+
+ /**
+ * Gets the type associated with this event.
+ *
+ * @return returns the handler type
+ */
+ public static Type<RequestValidationEventHandler> getType()
+ {
+ return TYPE != null ? TYPE : (TYPE = new Type<RequestValidationEventHandler>());
+ }
+
+ public RequestValidationEvent()
+ {
+ }
+
+ @Override
+ public Type<RequestValidationEventHandler> getAssociatedType()
+ {
+ return getType();
+ }
+
+
+ @Override
+ protected void dispatch(RequestValidationEventHandler handler)
+ {
+ handler.onRequestValidation(this);
+ }
+}
+
+
+
View
4 ...ts/UpdateValidationErrorEventHandler.java → ...events/RequestValidationEventHandler.java
@@ -22,7 +22,7 @@
import com.google.gwt.event.shared.EventHandler;
-public interface UpdateValidationErrorEventHandler extends EventHandler
+public interface RequestValidationEventHandler extends EventHandler
{
- void onUpdate(UpdateValidationErrorEvent event);
+ void onRequestValidation(RequestValidationEvent event);
}
View
26 ...nt/events/UpdateValidationErrorEvent.java → ...events/UpdateValidationWarningsEvent.java
@@ -31,48 +31,41 @@
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a>
*
**/
-public class UpdateValidationErrorEvent extends GwtEvent<UpdateValidationErrorEventHandler>
+public class UpdateValidationWarningsEvent extends GwtEvent<UpdateValidationWarningsEventHandler>
{
/**
* Handler type.
*/
- private static Type<UpdateValidationErrorEventHandler> TYPE;
+ private static Type<UpdateValidationWarningsEventHandler> TYPE;
/**
* Gets the type associated with this event.
*
* @return returns the handler type
*/
- public static Type<UpdateValidationErrorEventHandler> getType()
+ public static Type<UpdateValidationWarningsEventHandler> getType()
{
- return TYPE != null ? TYPE : (TYPE = new Type<UpdateValidationErrorEventHandler>());
+ return TYPE != null ? TYPE : (TYPE = new Type<UpdateValidationWarningsEventHandler>());
}
private TransUnitId id;
private List<String> errors;
- private boolean updateEditorOnly = false;
- public UpdateValidationErrorEvent(TransUnitId id, List<String> errors)
+ public UpdateValidationWarningsEvent(TransUnitId id, List<String> errors)
{
this.id = id;
this.errors = errors;
}
- public UpdateValidationErrorEvent(TransUnitId id, boolean updateEditorOnly)
- {
- this.id = id;
- this.updateEditorOnly = updateEditorOnly;
- }
-
@Override
- public Type<UpdateValidationErrorEventHandler> getAssociatedType()
+ public Type<UpdateValidationWarningsEventHandler> getAssociatedType()
{
return getType();
}
@Override
- protected void dispatch(UpdateValidationErrorEventHandler handler)
+ protected void dispatch(UpdateValidationWarningsEventHandler handler)
{
handler.onUpdate(this);
}
@@ -86,11 +79,6 @@ public TransUnitId getId()
{
return errors;
}
-
- public boolean isUpdateEditorOnly()
- {
- return updateEditorOnly;
- }
}
View
28 ...src/main/java/org/zanata/webtrans/client/events/UpdateValidationWarningsEventHandler.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.zanata.webtrans.client.events;
+
+import com.google.gwt.event.shared.EventHandler;
+
+public interface UpdateValidationWarningsEventHandler extends EventHandler
+{
+ void onUpdate(UpdateValidationWarningsEvent event);
+}
View
59 ...ta-war/src/main/java/org/zanata/webtrans/client/presenter/ValidationOptionsPresenter.java
@@ -24,65 +24,52 @@
import net.customware.gwt.presenter.client.widget.WidgetDisplay;
import net.customware.gwt.presenter.client.widget.WidgetPresenter;
-import org.zanata.webtrans.client.events.DocumentSelectionEvent;
-import org.zanata.webtrans.client.events.DocumentSelectionHandler;
-import org.zanata.webtrans.client.events.TransUnitSelectionEvent;
-import org.zanata.webtrans.client.events.TransUnitSelectionHandler;
-import org.zanata.webtrans.client.events.RunValidationEvent;
-import org.zanata.webtrans.client.events.RunValidationEventHandler;
-import org.zanata.webtrans.shared.model.TransUnitId;
+import org.zanata.webtrans.client.validation.ValidationService;
+import org.zanata.webtrans.shared.validation.ValidationObject;
+import com.google.gwt.event.logical.shared.HasValueChangeHandlers;
+import com.google.gwt.event.logical.shared.ValueChangeEvent;
+import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.inject.Inject;
/**
- *
+ *
+ *
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a>
- *
+ *
**/
public class ValidationOptionsPresenter extends WidgetPresenter<ValidationOptionsPresenter.Display>
{
public interface Display extends WidgetDisplay
{
- void validate(TransUnitId id, String source, String target, boolean fireNotification);
-
- void clearAllMessage();
+ HasValueChangeHandlers<Boolean> addValidationSelector(String label, String tooltip, boolean enabled);
}
+ private ValidationService validationService;
+
@Inject
- public ValidationOptionsPresenter(Display display, EventBus eventBus)
+ public ValidationOptionsPresenter(Display display, EventBus eventBus, final ValidationService validationService)
{
super(display, eventBus);
+ this.validationService = validationService;
}
@Override
protected void onBind()
{
- registerHandler(eventBus.addHandler(TransUnitSelectionEvent.getType(), new TransUnitSelectionHandler()
+ for (final ValidationObject object : validationService.getValidationList())
{
- @Override
- public void onTransUnitSelected(TransUnitSelectionEvent event)
+ HasValueChangeHandlers<Boolean> changeHandler = display.addValidationSelector(object.getId(), object.getDescription(), object.isEnabled());
+ changeHandler.addValueChangeHandler(new ValueChangeHandler<Boolean>()
{
- display.clearAllMessage();
- }
- }));
- registerHandler(eventBus.addHandler(RunValidationEvent.getType(), new RunValidationEventHandler()
- {
- @Override
- public void onValidate(RunValidationEvent event)
- {
- display.validate(event.getId(), event.getSource(), event.getTarget(), event.isFireNotification());
- }
- }));
-
- registerHandler(eventBus.addHandler(DocumentSelectionEvent.getType(), new DocumentSelectionHandler()
- {
- @Override
- public void onDocumentSelected(DocumentSelectionEvent event)
- {
- display.clearAllMessage();
- }
- }));
+ @Override
+ public void onValueChange(ValueChangeEvent<Boolean> event)
+ {
+ validationService.updateStatus(object.getId(), event.getValue());
+ }
+ });
+ }
}
@Override
View
6 server/zanata-war/src/main/java/org/zanata/webtrans/client/resources/NavigationMessages.java
@@ -124,6 +124,8 @@
@DefaultMessage("Translation Unit Details")
String transUnitDetailsHeading();
- @DefaultMessage("Validation Message")
- String validationMessageHeading();
+ @DefaultMessage("Validation Warnings: {0}")
+ @AlternateMessage({ "=0", "Validation Warnings: none" })
+ String validationWarningsHeading(@PluralCount
+ int warningCount);
}
View
40 server/zanata-war/src/main/java/org/zanata/webtrans/client/resources/ValidationMessages.java
@@ -16,65 +16,65 @@
{
// Newline validator
- @DefaultMessage("Newline lead/trail")
+ @DefaultMessage("Leading/trailing newline (¶)")
String newlineValidatorName();
- @DefaultMessage("Newline lead/trail validation")
+ @DefaultMessage("Check for consistent leading and trailing newline (¶)")
String newlineValidatorDescription();
- @DefaultMessage("Leading newline missing from target")
+ @DefaultMessage("Leading newline (¶) is missing")
String leadingNewlineMissing();
- @DefaultMessage("Leading newline added to target")
+ @DefaultMessage("Unexpected leading newline (¶)")
String leadingNewlineAdded();
- @DefaultMessage("Trailing newline missing from target")
+ @DefaultMessage("Trailing newline (¶) is missing")
String trailingNewlineMissing();
- @DefaultMessage("Trailing newline added to target")
+ @DefaultMessage("Unexpected trailing newline (¶)")
String trailingNewlineAdded();
// Variables validator
- @DefaultMessage("Variables check")
+ @DefaultMessage("%x variables")
String variablesValidatorName();
- @DefaultMessage("Variables check validation")
+ @DefaultMessage("Check that printf style (%x) variables are consistent")
String variablesValidatorDescription();
@Description("Lists the variables that are in the original string but have not been included in the target")
- @DefaultMessage("Variables [ {0,list,string} ] missing in target")
- @AlternateMessage({ "one", "Variable [ {0,list,string} ] missing in target" })
+ @DefaultMessage("Missing variables: {0,list,string}")
+ @AlternateMessage({ "one", "Missing variable: {0,list,string}" })
String varsMissing(@PluralCount
List<String> vars);
@Description("Lists the variables that are in the target but are not in the original string")
- @DefaultMessage("Variables [ {0,list,string} ] added in target")
- @AlternateMessage({ "one", "Variable [ {0,list,string} ] added in target" })
+ @DefaultMessage("Unexpected variables: {0,list,string}")
+ @AlternateMessage({ "one", "Unexpected variable: {0,list,string}" })
String varsAdded(@PluralCount
List<String> vars);
// XHM/HTML tag validator
- @DefaultMessage("HTML/XML tag")
+ @DefaultMessage("XML/HTML tags")
String xmlHtmlValidatorName();
- @DefaultMessage("Matching HTML/XML tag validation")
+ @DefaultMessage("Check that XML/HTML tags are consistent")
String xmlHtmlValidatorDescription();
@Description("Lists the xml or html tags that are in the target but are not in the original string")
- @DefaultMessage("Tags [ {0,list,string} ] added in target")
- @AlternateMessage({ "one", "Tag [ {0,list,string} ] added in target" })
+ @DefaultMessage("Unexpected tags: {0,list,string}")
+ @AlternateMessage({ "one", "Unexpected tag: {0,list,string}" })
String tagsAdded(@PluralCount List<String> tags);
@Description("Lists the xml or html tags that are in the original string but have not been included in the target")
- @DefaultMessage("Tags [ {0,list,string} ] missing in target")
- @AlternateMessage({ "one", "Tag [ {0,list,string} ] missing in target" })
+ @DefaultMessage("Missing tags: {0,list,string}")
+ @AlternateMessage({ "one", "Missing tag: {0,list,string}" })
String tagsMissing(@PluralCount List<String> tags);
- @DefaultMessage("Tags [ {0,list,string} ] are in a different order in target and source")
- @AlternateMessage({ "one", "Tag [ {0,list,string} ] is in a different location in target and source" })
+ @DefaultMessage("Tags in unexpected position: {0,list,string}")
+ @AlternateMessage({ "one", "Tag in unexpected position: {0,list,string}" })
String tagsWrongOrder(@PluralCount List<String> tags);
}
View
47 server/zanata-war/src/main/java/org/zanata/webtrans/client/ui/ValidationMessagePanel.java
@@ -20,6 +20,8 @@
import java.util.ArrayList;
import java.util.List;
+import org.zanata.webtrans.client.resources.NavigationMessages;
+
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.resources.client.CssResource;
@@ -62,14 +64,25 @@
private boolean collapsible;
private List<String> errors = new ArrayList<String>();
+ private final NavigationMessages messages;
+
+ private boolean canShow;
- public ValidationMessagePanel(String header, boolean collapsible)
+ public ValidationMessagePanel(boolean collapsible, NavigationMessages messages)
{
contents = new VerticalPanel();
+ this.messages = messages;
initWidget(uiBinder.createAndBindUi(this));
setCollapsible(collapsible);
- headerLabel.setText(header);
+ setHeaderText(messages.validationWarningsHeading(0));
collapse();
+ this.canShow = false;
+ this.setVisible(false);
+ }
+
+ private void setHeaderText(String header)
+ {
+ headerLabel.setText(header);
}
public void setContent(List<String> errors)
@@ -83,7 +96,9 @@ public void setContent(List<String> errors)
contents.add(new Label(error));
}
contentPanel.add(contents);
+ setHeaderText(messages.validationWarningsHeading(errors.size()));
expand();
+ this.canShow = true;
}
@UiHandler("headerLabel")
@@ -109,10 +124,6 @@ public void expand()
contentPanel.setHeight("95px");
contentPanel.setVisible(true);
}
- else
- {
- collapse();
- }
}
public void collapse()
@@ -137,4 +148,28 @@ public void setCollapsible(boolean collapsible)
{
return errors;
}
+
+ public void setVisiblePolicy(boolean canShow)
+ {
+ this.canShow = canShow;
+ if (!canShow)
+ {
+ this.setVisible(false);
+ }
+ }
+
+ @Override
+ public void setVisible(boolean visible)
+ {
+ if (visible && canShow)
+ super.setVisible(true);
+ else
+ super.setVisible(false);
+
+ }
+
+ public boolean getVisiblePolicy()
+ {
+ return canShow;
+ }
}
View
2  server/zanata-war/src/main/java/org/zanata/webtrans/client/ui/ValidationMessagePanel.ui.xml
@@ -31,7 +31,7 @@
.content {
height:100%;
- color:#686868;
+ color:#D14836;
font-style:normal;
}
View
58 server/zanata-war/src/main/java/org/zanata/webtrans/client/validation/ValidationService.java
@@ -27,9 +27,16 @@
import net.customware.gwt.presenter.client.EventBus;
+import org.zanata.webtrans.client.events.DocumentSelectionEvent;
+import org.zanata.webtrans.client.events.DocumentSelectionHandler;
import org.zanata.webtrans.client.events.NotificationEvent;
+import org.zanata.webtrans.client.events.RequestValidationEvent;
+import org.zanata.webtrans.client.events.RunValidationEvent;
+import org.zanata.webtrans.client.events.RunValidationEventHandler;
+import org.zanata.webtrans.client.events.TransUnitSelectionEvent;
+import org.zanata.webtrans.client.events.TransUnitSelectionHandler;
import org.zanata.webtrans.client.events.NotificationEvent.Severity;
-import org.zanata.webtrans.client.events.UpdateValidationErrorEvent;
+import org.zanata.webtrans.client.events.UpdateValidationWarningsEvent;
import org.zanata.webtrans.client.resources.TableEditorMessages;
import org.zanata.webtrans.client.resources.ValidationMessages;
import org.zanata.webtrans.shared.model.TransUnitId;
@@ -66,12 +73,40 @@ public ValidationService(final EventBus eventBus, final TableEditorMessages mess
validationMap.put(htmlxmlValidation.getId(), htmlxmlValidation);
validationMap.put(newlineLeadTrailValidation.getId(), newlineLeadTrailValidation);
validationMap.put(variablesValidation.getId(), variablesValidation);
+
+ eventBus.addHandler(RunValidationEvent.getType(), new RunValidationEventHandler()
+ {
+ @Override
+ public void onValidate(RunValidationEvent event)
+ {
+ execute(event.getId(), event.getSource(), event.getTarget(), event.isFireNotification());
+ }
+ });
+
+ eventBus.addHandler(TransUnitSelectionEvent.getType(), new TransUnitSelectionHandler()
+ {
+ @Override
+ public void onTransUnitSelected(TransUnitSelectionEvent event)
+ {
+ clearAllMessage();
+ }
+ });
+
+ eventBus.addHandler(DocumentSelectionEvent.getType(), new DocumentSelectionHandler()
+ {
+ @Override
+ public void onDocumentSelected(DocumentSelectionEvent event)
+ {
+ clearAllMessage();
+ }
+ });
+
}
/**
- * Execute list of validation actions if the action is enabled
- *
- * @param tu
+ * Run all enabled validators against the given strings. Generates a
+ * {@link UpdateValidationWarningsEvent}, which will be empty if no warnings
+ * were generated by the enabled validators.
*/
public void execute(TransUnitId id, String source, String target, boolean fireNotification)
{
@@ -88,11 +123,12 @@ public void execute(TransUnitId id, String source, String target, boolean fireNo
errors.addAll(action.getError());
}
}
- fireErrorMessage(id, errors, fireNotification);
+ fireValidationWarningsEvent(id, errors, fireNotification);
}
/**
- * enable/disable validation action from UI
+ * Enable/disable validation action. Causes a {@link RequestValidationEvent}
+ * to be fired.
*
* @param key
* @param isEnabled
@@ -101,7 +137,11 @@ public void updateStatus(String key, boolean isEnabled)
{
ValidationAction action = validationMap.get(key);
action.setEnabled(isEnabled);
+ // is this put necessary?
validationMap.put(key, action);
+
+ // request re-run validation with new options
+ eventBus.fireEvent(new RequestValidationEvent());
}
public List<ValidationObject> getValidationList()
@@ -110,7 +150,7 @@ public void updateStatus(String key, boolean isEnabled)
}
/**
- * Clear all validation plugin's error message
+ * Clear all validation plugin's error messages
*/
public void clearAllMessage()
{
@@ -125,13 +165,13 @@ public void clearAllMessage()
}
}
- public void fireErrorMessage(TransUnitId id, List<String> errors, boolean fireNotification)
+ public void fireValidationWarningsEvent(TransUnitId id, List<String> errors, boolean fireNotification)
{
if (!errors.isEmpty() && fireNotification)
{
eventBus.fireEvent(new NotificationEvent(Severity.Info, messages.notifyValidationError()));
}
- eventBus.fireEvent(new UpdateValidationErrorEvent(id, errors));
+ eventBus.fireEvent(new UpdateValidationWarningsEvent(id, errors));
}
}
View
50 server/zanata-war/src/main/java/org/zanata/webtrans/client/view/ValidationOptionsView.java
@@ -1,25 +1,19 @@
package org.zanata.webtrans.client.view;
import org.zanata.webtrans.client.presenter.ValidationOptionsPresenter;
-import org.zanata.webtrans.client.validation.ValidationService;
-import org.zanata.webtrans.shared.model.TransUnitId;
-import org.zanata.webtrans.shared.validation.ValidationObject;
import com.google.gwt.core.client.GWT;
-import com.google.gwt.event.logical.shared.ValueChangeEvent;
-import com.google.gwt.event.logical.shared.ValueChangeHandler;
+import com.google.gwt.event.logical.shared.HasValueChangeHandlers;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
-import com.google.inject.Inject;
public class ValidationOptionsView extends Composite implements ValidationOptionsPresenter.Display
{
- private final ValidationService validationService;
private static ValidationOptionsViewUiBinder uiBinder = GWT.create(ValidationOptionsViewUiBinder.class);
interface ValidationOptionsViewUiBinder extends UiBinder<Widget, ValidationOptionsView>
@@ -29,35 +23,20 @@
@UiField
VerticalPanel contentPanel;
- @Inject
- public ValidationOptionsView(final ValidationService validationService)
+ public ValidationOptionsView()
{
initWidget(uiBinder.createAndBindUi(this));
- this.validationService = validationService;
-
- initValidationList();
-
}
- private void initValidationList()
+ @Override
+ public HasValueChangeHandlers<Boolean> addValidationSelector(String label, String tooltip, boolean enabled)
{
- for (final ValidationObject action : validationService.getValidationList())
- {
- CheckBox chk = new CheckBox(action.getId());
-
- chk.setValue(action.isEnabled());
- chk.addValueChangeHandler(new ValueChangeHandler<Boolean>()
- {
- @Override
- public void onValueChange(ValueChangeEvent<Boolean> event)
- {
- validationService.updateStatus(action.getId(), event.getValue());
- }
- });
- chk.setTitle(action.getDescription());
+ CheckBox chk = new CheckBox(label);
+ chk.setValue(enabled);
+ chk.setTitle(tooltip);
+ contentPanel.add(chk);
- contentPanel.add(chk);
- }
+ return chk;
}
@Override
@@ -66,15 +45,4 @@ public Widget asWidget()
return this;
}
- @Override
- public void validate(TransUnitId id, String source, String target, boolean fireNotification)
- {
- validationService.execute(id, source, target, fireNotification);
- }
-
- @Override
- public void clearAllMessage()
- {
- validationService.clearAllMessage();
- }
}
View
43 ...-war/src/main/java/org/zanata/webtrans/shared/validation/action/HtmlXmlTagValidation.java
@@ -21,10 +21,8 @@
package org.zanata.webtrans.shared.validation.action;
import java.util.ArrayList;
-//import java.util.List;
import org.zanata.webtrans.client.resources.ValidationMessages;
-import org.zanata.webtrans.shared.validation.ValidationUtils;
import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.regexp.shared.MatchResult;
@@ -39,7 +37,7 @@
{
public HtmlXmlTagValidation(final ValidationMessages messages)
{
- super(messages.xmlHtmlValidatorName(), messages.xmlHtmlValidatorDescription(), messages);
+ super(messages.xmlHtmlValidatorName(), messages.xmlHtmlValidatorDescription(), true, messages);
}
// private final static String tagRegex = "<[^>]+>[^<]*</[^>]+>";
@@ -48,33 +46,30 @@ public HtmlXmlTagValidation(final ValidationMessages messages)
private final static RegExp regExp = RegExp.compile(tagRegex, "g");
@Override
- public void validate(String source, String target)
+ public void doValidate(String source, String target)
{
- if (!ValidationUtils.isEmpty(target))
- {
- ArrayList<String> sourceTags = getTagList(source);
- ArrayList<String> targetTags = getTagList(target);
+ ArrayList<String> sourceTags = getTagList(source);
+ ArrayList<String> targetTags = getTagList(target);
- ArrayList<String> error = listMissing(source, target);
- if (!error.isEmpty())
- {
- addError(getMessages().tagsMissing(error));
- }
+ ArrayList<String> error = listMissing(source, target);
+ if (!error.isEmpty())
+ {
+ addError(getMessages().tagsMissing(error));
+ }
- boolean noError = error.isEmpty();
+ boolean noError = error.isEmpty();
- error = listMissing(target, source);
- if (!error.isEmpty())
- {
- addError(getMessages().tagsAdded(error));
- }
+ error = listMissing(target, source);
+ if (!error.isEmpty())
+ {
+ addError(getMessages().tagsAdded(error));
+ }
- noError &= error.isEmpty();
+ noError &= error.isEmpty();
- if (noError)
- {
- orderValidation(sourceTags, targetTags);
- }
+ if (noError)
+ {
+ orderValidation(sourceTags, targetTags);
}
}
View
24 ...rc/main/java/org/zanata/webtrans/shared/validation/action/NewlineLeadTrailValidation.java
@@ -21,7 +21,6 @@
package org.zanata.webtrans.shared.validation.action;
import org.zanata.webtrans.client.resources.ValidationMessages;
-import org.zanata.webtrans.shared.validation.ValidationUtils;
import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.regexp.shared.RegExp;
@@ -35,7 +34,7 @@
{
public NewlineLeadTrailValidation(final ValidationMessages messages)
{
- super(messages.newlineValidatorName(), messages.newlineValidatorDescription(), messages);
+ super(messages.newlineValidatorName(), messages.newlineValidatorDescription(), true, messages);
}
private final static String leadNewlineRegex = "^\n";
@@ -45,22 +44,19 @@ public NewlineLeadTrailValidation(final ValidationMessages messages)
private final static RegExp endRegExp = RegExp.compile(endNewlineRegex);
@Override
- public void validate(String source, String target)
+ public void doValidate(String source, String target)
{
- if (!ValidationUtils.isEmpty(target))
- {
- if (!shareLeading(source, target))
- addError(getMessages().leadingNewlineMissing());
+ if (!shareLeading(source, target))
+ addError(getMessages().leadingNewlineMissing());
- if (!shareLeading(target, source))
- addError(getMessages().leadingNewlineAdded());
+ if (!shareLeading(target, source))
+ addError(getMessages().leadingNewlineAdded());
- if (!shareTrailing(source, target))
- addError(getMessages().trailingNewlineMissing());
+ if (!shareTrailing(source, target))
+ addError(getMessages().trailingNewlineMissing());
- if (!shareTrailing(target, source))
- addError(getMessages().trailingNewlineAdded());
- }
+ if (!shareTrailing(target, source))
+ addError(getMessages().trailingNewlineAdded());
}
/**
View
12 ...nata-war/src/main/java/org/zanata/webtrans/shared/validation/action/ValidationAction.java
@@ -25,6 +25,7 @@
import org.zanata.webtrans.client.resources.ValidationMessages;
import org.zanata.webtrans.shared.validation.ValidationObject;
+import org.zanata.webtrans.shared.validation.ValidationUtils;
/**
*
@@ -47,12 +48,19 @@ protected ValidationMessages getMessages()
private List<String> errorList = new ArrayList<String>();
- public abstract void validate(String source, String target);
+ public void validate(String source, String target)
+ {
+ if (!ValidationUtils.isEmpty(target))
+ doValidate(source, target);
+ }
+
+ public abstract void doValidate(String source, String target);
- public ValidationAction(String id, String description, final ValidationMessages messages)
+ public ValidationAction(String id, String description, boolean enabled, final ValidationMessages messages)
{
this.id = id;
this.description = description;
+ this.isEnabled = enabled;
this.messages = messages;
}
View
32 ...a-war/src/main/java/org/zanata/webtrans/shared/validation/action/VariablesValidation.java
@@ -24,7 +24,6 @@
import java.util.List;
import org.zanata.webtrans.client.resources.ValidationMessages;
-import org.zanata.webtrans.shared.validation.ValidationUtils;
import com.google.gwt.regexp.shared.MatchResult;
import com.google.gwt.regexp.shared.RegExp;
@@ -38,7 +37,7 @@
{
public VariablesValidation(final ValidationMessages messages)
{
- super(messages.variablesValidatorName(), messages.variablesValidatorDescription(), messages);
+ super(messages.variablesValidatorName(), messages.variablesValidatorDescription(), true, messages);
}
@@ -48,25 +47,22 @@ public VariablesValidation(final ValidationMessages messages)
// private final static String varRegex = "%[\\w]+";
@Override
- public void validate(String source, String target)
+ public void doValidate(String source, String target)
{
- if (!ValidationUtils.isEmpty(target))
- {
- ArrayList<String> sourceVars = findVars(source);
- ArrayList<String> targetVars = findVars(target);
+ ArrayList<String> sourceVars = findVars(source);
+ ArrayList<String> targetVars = findVars(target);
- List<String> missing = listMissing(sourceVars, targetVars);
- if (!missing.isEmpty())
- {
- addError(getMessages().varsMissing(missing));
- }
+ List<String> missing = listMissing(sourceVars, targetVars);
+ if (!missing.isEmpty())
+ {
+ addError(getMessages().varsMissing(missing));
+ }
- // missing from source = added
- missing = listMissing(targetVars, sourceVars);
- if (!missing.isEmpty())
- {
- addError(getMessages().varsAdded(missing));
- }
+ // missing from source = added
+ missing = listMissing(targetVars, sourceVars);
+ if (!missing.isEmpty())
+ {
+ addError(getMessages().varsAdded(missing));
}
}

No commit comments for this range

Something went wrong with that request. Please try again.