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

Commit

Permalink
rhbz844820 - add user config to switch between code mirror and plain …
Browse files Browse the repository at this point in the history
…textarea
  • Loading branch information
Patrick Huang committed Sep 13, 2012
1 parent 245d1e6 commit 54b574a
Show file tree
Hide file tree
Showing 15 changed files with 159 additions and 35 deletions.
Expand Up @@ -20,6 +20,7 @@
*/
package org.zanata.webtrans.client.editor.table;

import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.NativeEvent;
Expand All @@ -31,14 +32,14 @@

public class EditorTextArea extends TextArea
{
// TODO this should go into UserConfigHolder and be part of user config
private boolean useCodeMirrorFlag = true;

private JavaScriptObject codeMirrorEditor;

public EditorTextArea()
public EditorTextArea(boolean isUseCodeMirror)
{
super();
useCodeMirrorFlag = isUseCodeMirror;
}

// see http://codemirror.net/doc/manual.html#usage
Expand Down
Expand Up @@ -85,5 +85,7 @@ interface Listener
void showHistory(TransUnitId transUnitId);

void onFocus(TransUnitId id, int editorIndex);

boolean isUsingCodeMirror();
}
}
Expand Up @@ -530,6 +530,12 @@ public void onFocus(TransUnitId id, int editorIndex)
currentEditorIndex = editorIndex;
}

@Override
public boolean isUsingCodeMirror()
{
return configuration.isUseCodeMirrorEditor();
}

@Override
public void onCancel(TransUnitId transUnitId)
{
Expand All @@ -539,14 +545,6 @@ public void onCancel(TransUnitId transUnitId)
setFocus();
}

/**
* user is able to click on buttons on different rows now. (save, save as fuzzy, cancel, show history, undo, validate)
* TODO discuss solution for above scenario:
* 1. (current solution) ensure row selection first and then continue with button action. Drawback: continue save may not be user's intention.
* 2. disable buttons not on selected row. Drawback: disabled buttons may not be able to receive focus event and row selection won't trigger if click on them??
* 3. hide buttons not on selected row. Drawback: show and hide buttons cause screen movement and distraction.
* @param transUnitId coming from the display that user is clicked on
*/
private void ensureRowSelection(TransUnitId transUnitId)
{
if (!Objects.equal(currentTransUnitId, transUnitId))
Expand Down
Expand Up @@ -120,7 +120,10 @@ public void focusEditor(final int currentEditorIndex)
@Override
public void execute()
{
editors.get(currentEditorIndex).setFocus();
if (currentEditorIndex >= 0 && currentEditorIndex < editors.size())
{
editors.get(currentEditorIndex).setFocus();
}
}
});
}
Expand Down
@@ -0,0 +1,23 @@
package org.zanata.webtrans.client.events;

import com.google.gwt.event.shared.GwtEvent;

public class ReloadPageEvent extends GwtEvent<ReloadPageEventHandler>
{
public static Type<ReloadPageEventHandler> TYPE = new Type<ReloadPageEventHandler>();
public static final ReloadPageEvent EVENT = new ReloadPageEvent();

private ReloadPageEvent()
{
}

public Type<ReloadPageEventHandler> getAssociatedType()
{
return TYPE;
}

protected void dispatch(ReloadPageEventHandler handler)
{
handler.onReloadPage(this);
}
}
@@ -0,0 +1,8 @@
package org.zanata.webtrans.client.events;

import com.google.gwt.event.shared.EventHandler;

public interface ReloadPageEventHandler extends EventHandler
{
void onReloadPage(ReloadPageEvent event);
}
Expand Up @@ -26,6 +26,7 @@
import org.zanata.webtrans.client.events.FilterViewEvent;
import org.zanata.webtrans.client.events.FilterViewEventHandler;
import org.zanata.webtrans.client.events.PageSizeChangeEvent;
import org.zanata.webtrans.client.events.ReloadPageEvent;
import org.zanata.webtrans.client.events.UserConfigChangeEvent;
import org.zanata.webtrans.client.events.WorkspaceContextUpdateEvent;
import org.zanata.webtrans.client.events.WorkspaceContextUpdateEventHandler;
Expand Down Expand Up @@ -168,6 +169,17 @@ public void onShowErrorsOptionChanged(Boolean showErrorChkValue)
configHolder.setShowError(showErrorChkValue);
}

@Override
public void onUseCodeMirrorOptionChanged(Boolean useCodeMirrorChkValue)
{
if (configHolder.isUseCodeMirrorEditor() != useCodeMirrorChkValue)
{
configHolder.setUseCodeMirrorEditor(useCodeMirrorChkValue);
eventBus.fireEvent(UserConfigChangeEvent.EVENT);
eventBus.fireEvent(ReloadPageEvent.EVENT);
}
}

@Override
protected void onUnbind()
{
Expand Down
Expand Up @@ -55,7 +55,7 @@ public boolean apply(ContentState contentState)
};

// default state
private ConfigurationState state = new ConfigurationState(false, false, true, 10, NavOption.FUZZY_UNTRANSLATED, false);
private ConfigurationState state = new ConfigurationState(false, false, true, 10, NavOption.FUZZY_UNTRANSLATED, false, true);

public boolean isEnterSavesApproved()
{
Expand All @@ -64,7 +64,7 @@ public boolean isEnterSavesApproved()

protected void setEnterSavesApproved(boolean enterSavesApproved)
{
state = new ConfigurationState(enterSavesApproved, state.isEscClosesEditor(), state.isDisplayButtons(), state.getPageSize(), state.getNavOption(), state.isShowError());
state = new ConfigurationState(enterSavesApproved, state.isEscClosesEditor(), state.isDisplayButtons(), state.getPageSize(), state.getNavOption(), state.isShowError(), state.isUseCodeMirrorEditor());
}

public boolean isEscClosesEditor()
Expand All @@ -74,7 +74,7 @@ public boolean isEscClosesEditor()

protected void setEscClosesEditor(boolean escClosesEditor)
{
state = new ConfigurationState(state.isEnterSavesApproved(), escClosesEditor, state.isDisplayButtons(), state.getPageSize(), state.getNavOption(), state.isShowError());
state = new ConfigurationState(state.isEnterSavesApproved(), escClosesEditor, state.isDisplayButtons(), state.getPageSize(), state.getNavOption(), state.isShowError(), state.isUseCodeMirrorEditor());
}

public boolean isDisplayButtons()
Expand All @@ -84,12 +84,12 @@ public boolean isDisplayButtons()

protected void setDisplayButtons(boolean displayButtons)
{
state = new ConfigurationState(state.isEnterSavesApproved(), state.isEscClosesEditor(), displayButtons, state.getPageSize(), state.getNavOption(), state.isShowError());
state = new ConfigurationState(state.isEnterSavesApproved(), state.isEscClosesEditor(), displayButtons, state.getPageSize(), state.getNavOption(), state.isShowError(), state.isUseCodeMirrorEditor());
}

protected void setNavOption(NavOption navOption)
{
state = new ConfigurationState(state.isEnterSavesApproved(), state.isEscClosesEditor(), state.isDisplayButtons(), state.getPageSize(), navOption, state.isShowError());
state = new ConfigurationState(state.isEnterSavesApproved(), state.isEscClosesEditor(), state.isDisplayButtons(), state.getPageSize(), navOption, state.isShowError(), state.isUseCodeMirrorEditor());
}

public NavOption getNavOption()
Expand Down Expand Up @@ -120,7 +120,7 @@ public int getPageSize()

protected void setPageSize(int pageSize)
{
state = new ConfigurationState(state.isEnterSavesApproved(), state.isEscClosesEditor(), state.isDisplayButtons(), pageSize, state.getNavOption(), state.isShowError());
state = new ConfigurationState(state.isEnterSavesApproved(), state.isEscClosesEditor(), state.isDisplayButtons(), pageSize, state.getNavOption(), state.isShowError(), state.isUseCodeMirrorEditor());
}

public ConfigurationState getState()
Expand All @@ -135,7 +135,17 @@ public boolean isShowError()

public void setShowError(boolean showError)
{
state = new ConfigurationState(state.isEnterSavesApproved(), state.isEscClosesEditor(), state.isDisplayButtons(), state.getPageSize(), state.getNavOption(), showError);
state = new ConfigurationState(state.isEnterSavesApproved(), state.isEscClosesEditor(), state.isDisplayButtons(), state.getPageSize(), state.getNavOption(), showError, state.isUseCodeMirrorEditor());
}

public boolean isUseCodeMirrorEditor()
{
return state.isUseCodeMirrorEditor();
}

public void setUseCodeMirrorEditor(boolean useCodeMirrorEditor)
{
state = new ConfigurationState(state.isEnterSavesApproved(), state.isEscClosesEditor(), state.isDisplayButtons(), state.getPageSize(), state.getNavOption(), state.isShowError(), useCodeMirrorEditor);
}

/**
Expand All @@ -149,15 +159,17 @@ public static class ConfigurationState
private int pageSize;
private NavOption navOption;
private boolean showError;
private boolean useCodeMirrorEditor;

private ConfigurationState(boolean enterSavesApproved, boolean escClosesEditor, boolean displayButtons, int pageSize, NavOption navOption, boolean showError)
private ConfigurationState(boolean enterSavesApproved, boolean escClosesEditor, boolean displayButtons, int pageSize, NavOption navOption, boolean showError, boolean useCodeMirrorEditor)
{
this.enterSavesApproved = enterSavesApproved;
this.escClosesEditor = escClosesEditor;
this.displayButtons = displayButtons;
this.pageSize = pageSize;
this.navOption = navOption;
this.showError = showError;
this.useCodeMirrorEditor = useCodeMirrorEditor;
}

public boolean isEnterSavesApproved()
Expand Down Expand Up @@ -189,5 +201,10 @@ public boolean isShowError()
{
return showError;
}

public boolean isUseCodeMirrorEditor()
{
return useCodeMirrorEditor;
}
}
}
Expand Up @@ -407,9 +407,12 @@ public interface WebTransMessages extends Messages
@DefaultMessage("Read only")
String readOnly();

@DefaultMessage("Other configuration")
@DefaultMessage("Advance user configuration")
String otherConfiguration();

@DefaultMessage("When unexpected error happens, a popup window will display and show it.")
@DefaultMessage("When unexpected error happens, a popup window will display and show it")
String showErrorsTooltip();

@DefaultMessage("Switch between CodeMirror Editor (supports syntax highlight) and plain textarea (no syntax highlight)")
String useCodeMirrorEditorTooltip();
}
Expand Up @@ -37,6 +37,8 @@
import org.zanata.webtrans.client.events.PageCountChangeEvent;
import org.zanata.webtrans.client.events.PageSizeChangeEvent;
import org.zanata.webtrans.client.events.PageSizeChangeEventHandler;
import org.zanata.webtrans.client.events.ReloadPageEvent;
import org.zanata.webtrans.client.events.ReloadPageEventHandler;
import org.zanata.webtrans.client.events.TableRowSelectedEvent;
import org.zanata.webtrans.client.events.TransUnitSelectionEvent;
import org.zanata.webtrans.client.events.TransUnitUpdatedEvent;
Expand All @@ -58,7 +60,6 @@
import com.allen_sauer.gwt.log.client.Log;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.inject.Inject;
Expand All @@ -70,7 +71,7 @@
* @author Patrick Huang <a href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
*/
@Singleton
public class NavigationController implements TransUnitUpdatedEventHandler, FindMessageHandler, DocumentSelectionHandler, NavTransUnitHandler, PageSizeChangeEventHandler
public class NavigationController implements TransUnitUpdatedEventHandler, FindMessageHandler, DocumentSelectionHandler, NavTransUnitHandler, PageSizeChangeEventHandler, ReloadPageEventHandler
{
public static final int FIRST_PAGE = 0;
public static final int UNSELECTED = -1;
Expand All @@ -85,6 +86,8 @@ public class NavigationController implements TransUnitUpdatedEventHandler, FindM
//tracking variables
private GetTransUnitActionContext context;
private String findMessage;
private boolean isLoadingTU = false;
private boolean isLoadingIndex =false;

@Inject
public NavigationController(EventBus eventBus, CachingDispatchAsync dispatcher, TransUnitNavigationService navigationService, UserConfigHolder configHolder, TableEditorMessages messages)
Expand All @@ -105,6 +108,7 @@ private void bindHandlers()
eventBus.addHandler(FindMessageEvent.getType(), this);
eventBus.addHandler(NavTransUnitEvent.getType(), this);
eventBus.addHandler(PageSizeChangeEvent.TYPE, this);
eventBus.addHandler(ReloadPageEvent.TYPE, this);
}

protected void init(GetTransUnitActionContext context)
Expand All @@ -117,7 +121,8 @@ protected void init(GetTransUnitActionContext context)
private void requestTransUnitsAndUpdatePageIndex(final GetTransUnitActionContext context)
{
Log.info("requesting transUnits: " + context);
eventBus.fireEvent(LoadingEvent.START_EVENT);
isLoadingTU = true;
startLoading();
final int itemPerPage = context.getCount();
final int offset = context.getOffset();

Expand All @@ -135,7 +140,8 @@ public void onFailure(Throwable caught)
Log.error("GetTransUnits failure " + caught, caught);
eventBus.fireEvent(new NotificationEvent(NotificationEvent.Severity.Error, messages.notifyLoadFailed()));
}
eventBus.fireEvent(LoadingEvent.FINISH_EVENT);
isLoadingTU = false;
finishLoading();
}

@Override
Expand Down Expand Up @@ -163,14 +169,34 @@ public void onSuccess(GetTransUnitListResult result)
eventBus.fireEvent(new TableRowSelectedEvent(units.get(gotoRow).getId()));
}
eventBus.fireEvent(new PageChangeEvent(navigationService.getCurrentPage()));
eventBus.fireEvent(LoadingEvent.FINISH_EVENT);
isLoadingTU = false;
finishLoading();
}
});
}

private void startLoading()
{
if (isLoadingTU || isLoadingIndex)
{
eventBus.fireEvent(LoadingEvent.START_EVENT);
}
}

private void finishLoading()
{
// we only send finish event when all loading are finished
if (!isLoadingTU && !isLoadingIndex)
{
eventBus.fireEvent(LoadingEvent.FINISH_EVENT);
}
}

private void requestNavigationIndex(GetTransUnitActionContext context)
{
Log.info("requesting navigation index: " + context);
isLoadingIndex = true;
startLoading();
final int itemPerPage = context.getCount();
dispatcher.execute(GetTransUnitsNavigation.newAction(context), new AbstractAsyncCallback<GetTransUnitsNavigationResult>()
{
Expand All @@ -179,6 +205,8 @@ public void onSuccess(GetTransUnitsNavigationResult result)
{
navigationService.init(result.getTransIdStateList(), result.getIdIndexList(), itemPerPage);
eventBus.fireEvent(new PageCountChangeEvent(navigationService.getPageCount()));
isLoadingIndex = false;
finishLoading();
}
});
}
Expand All @@ -189,7 +217,7 @@ public void gotoPage(int pageIndex)
if (page != navigationService.getCurrentPage())
{
GetTransUnitActionContext newContext = context.changeOffset(context.getCount() * page).changeTargetTransUnitId(null);
Log.info("page index: " + pageIndex + " page context: " + newContext);
Log.info("page index: " + page + " page context: " + newContext);
requestTransUnitsAndUpdatePageIndex(newContext);
}
}
Expand All @@ -198,7 +226,7 @@ private void loadPageAndGoToRow(int pageIndex, TransUnitId transUnitId)
{
int page = normalizePageIndex(pageIndex);
GetTransUnitActionContext newContext = context.changeOffset(context.getCount() * page).changeTargetTransUnitId(transUnitId);
Log.debug("page index: " + pageIndex + " page context: " + newContext);
Log.debug("page index: " + page + " page context: " + newContext);
requestTransUnitsAndUpdatePageIndex(newContext);
}

Expand Down Expand Up @@ -297,6 +325,17 @@ public void onPageSizeChange(PageSizeChangeEvent pageSizeChangeEvent)
eventBus.fireEvent(new PageCountChangeEvent(navigationService.getPageCount()));
}

@Override
public void onReloadPage(ReloadPageEvent event)
{
Log.info("refreshing page");
isLoadingTU = true;
startLoading();
pageDataChangeListener.showDataForCurrentPage(pageModel.getData());
isLoadingTU = false;
finishLoading();
}

public void execute(UpdateContextCommand command)
{
if (context == null)
Expand Down

0 comments on commit 54b574a

Please sign in to comment.