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

Commit

Permalink
Plural support - integrated with validation event
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Mar 22, 2012
1 parent 57b5e61 commit 969da2b
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 20 deletions.
Expand Up @@ -57,9 +57,6 @@ public class InlineTargetCellEditor implements CellEditor<TransUnit>
*/
public static final String DEFAULT_STYLENAME = "gwt-TargetCellEditor";

private static final int INITIAL_LINES = 3;
private static final int HEIGHT_PER_LINE = 16;

/**
* The click listener used to clone.
*/
Expand Down
Expand Up @@ -24,7 +24,11 @@
import java.util.List;
import java.util.Map;

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

import org.zanata.webtrans.client.editor.table.SourceContentsView;
import org.zanata.webtrans.client.events.RequestValidationEvent;
import org.zanata.webtrans.client.events.RunValidationEvent;
import org.zanata.webtrans.client.ui.HasSelectableSource;
import org.zanata.webtrans.shared.model.TransUnit;

Expand All @@ -44,10 +48,13 @@ public class SourceContentsPresenter
private final Map<Integer, SourceContentsView> sourcePanelMap;
private HasSelectableSource selectedSource;
private HasSelectableSource previousSource;

private final EventBus eventBus;

@Inject
public SourceContentsPresenter()
public SourceContentsPresenter(final EventBus eventBus)
{
this.eventBus = eventBus;
sourcePanelMap = new HashMap<Integer, SourceContentsView>();
}

Expand All @@ -64,7 +71,9 @@ public void onClick(ClickEvent event)
{
previousSource.setSelected(false);
}

Log.debug("Selected source: " + selectedSource.getSource());
eventBus.fireEvent(new RequestValidationEvent());
}
};

Expand Down
Expand Up @@ -3,25 +3,26 @@
import org.zanata.webtrans.client.editor.table.EditorTextArea;
import org.zanata.webtrans.client.editor.table.TableResources;
import org.zanata.webtrans.client.editor.table.TargetContentsDisplay;
import org.zanata.webtrans.client.events.NotificationEvent;
import org.zanata.webtrans.client.events.NotificationEvent.Severity;
import org.zanata.webtrans.client.resources.NavigationMessages;

import com.allen_sauer.gwt.log.client.Log;
import com.google.common.base.Strings;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyDownEvent;
import com.google.gwt.event.dom.client.KeyDownHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.PushButton;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class Editor extends Composite implements ToggleEditor
Expand All @@ -33,10 +34,13 @@ interface EditorUiBinder extends UiBinder<Widget, Editor>
}

private static EditorUiBinder uiBinder = GWT.create(EditorUiBinder.class);
private static final int INITIAL_LINES = 3;

private static final int INITIAL_LINES = 3;
private static final int HEIGHT_PER_LINE = 16;

private final int TYPING_TIMER_INTERVAL = 500; // ms
private final int TYPING_TIMER_RECURRENT_VALIDATION_PERIOD = 5; // intervals

@UiField
HorizontalPanel topContainer;

Expand Down Expand Up @@ -67,7 +71,11 @@ interface EditorUiBinder extends UiBinder<Widget, Editor>
@UiField
PushButton copySourceButton;

public Editor(String displayString, String findMessage, TargetContentsDisplay.Listener listener)
private boolean keypressed;
private boolean typing;
private int typingCycles;

public Editor(String displayString, String findMessage, final TargetContentsDisplay.Listener listener)
{
this.listener = listener;
initWidget(uiBinder.createAndBindUi(this));
Expand Down Expand Up @@ -106,9 +114,64 @@ public Editor(String displayString, String findMessage, TargetContentsDisplay.Li
public void onValueChange(ValueChangeEvent<String> event)
{
autoSize();
fireValidationEvent();
}

});

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();
}
}
else
{
// finished, validate immediately
this.cancel();
typing = false;
fireValidationEvent();
}
}
};

// 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);
}
}
});
}

private void fireValidationEvent()
{
if (!Strings.isNullOrEmpty(getContent()))
{
listener.validate(this);
}
}

@UiHandler("copySourceButton")
Expand All @@ -120,10 +183,7 @@ public void onCopySource(ClickEvent event)
@UiHandler("validateButton")
public void onValidation(ClickEvent event)
{
if (!Strings.isNullOrEmpty(getContent()))
{
listener.validate(this);
}
fireValidationEvent();
}

@UiHandler("saveButton")
Expand Down Expand Up @@ -161,11 +221,8 @@ public void setViewMode(ViewMode viewMode)
if (viewMode == ViewMode.EDIT)
{
textArea.setFocus(true);
listener.setValidationMessagePanel(this);
if (!Strings.isNullOrEmpty(getContent()))
{
listener.validate(this);
}
listener.setValidationMessagePanel(this);
fireValidationEvent();
}
buttons.setVisible(viewMode == ViewMode.EDIT);
}
Expand Down Expand Up @@ -216,7 +273,6 @@ public void onClick(ClickEvent event)
}
};


@Override
public void setSaveButtonTitle(String title)
{
Expand Down
Expand Up @@ -20,7 +20,6 @@
import java.util.ArrayList;
import java.util.List;

import org.zanata.webtrans.client.resources.NavigationMessages;
import org.zanata.webtrans.client.resources.TableEditorMessages;

import com.google.gwt.core.client.GWT;
Expand Down
Expand Up @@ -46,6 +46,7 @@
import org.zanata.webtrans.shared.validation.action.PrintfVariablesValidation;
import org.zanata.webtrans.shared.validation.action.ValidationAction;

import com.allen_sauer.gwt.log.client.Log;
import com.google.inject.Inject;

/**
Expand Down

0 comments on commit 969da2b

Please sign in to comment.