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

Commit

Permalink
Merge pull request #1 from zanata/show-reference-lang
Browse files Browse the repository at this point in the history
Merge Reformat to Seam style and Update zanata module versions
  • Loading branch information
HannesEskebaek committed Sep 10, 2013
2 parents 5bf0f1e + 6d12b95 commit d7a4b40
Show file tree
Hide file tree
Showing 43 changed files with 1,561 additions and 35 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Expand Up @@ -32,10 +32,10 @@
<gwteventservice.version>1.2.1</gwteventservice.version>
<okapi.version>0.22</okapi.version>

<zanata.api.version>3.0.1-SNAPSHOT</zanata.api.version>
<zanata.api.version>3.0.1</zanata.api.version>
<!-- This should always be the previous version of the used api version above -->
<zanata.api.compat.version>3.0.1-SNAPSHOT</zanata.api.compat.version>
<zanata.client.version>3.0.1-SNAPSHOT</zanata.client.version>
<zanata.api.compat.version>3.0.1</zanata.api.compat.version>
<zanata.client.version>3.0.1</zanata.client.version>
<zanata.common.version>3.0.0</zanata.common.version>

<richfaces.version>4.3.2.Final</richfaces.version>
Expand Down
10 changes: 5 additions & 5 deletions zanata-war/pom.xml
Expand Up @@ -1399,11 +1399,11 @@
<artifactId>hibernate-search-analyzers</artifactId>
</dependency>

<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>javax.el</groupId>
Expand Down
@@ -0,0 +1,57 @@
package org.zanata.webtrans.client.events;

import com.google.gwt.event.shared.GwtEvent;
import org.zanata.webtrans.shared.model.Locale;

public class ReferenceVisibleEvent extends GwtEvent<ReferenceVisibleEventHandler>
{

/**
* Handler type.
*/
private static Type<ReferenceVisibleEventHandler> TYPE;

/**
* Gets the type associated with this event.
*
* @return returns the handler type
*/
public static Type<ReferenceVisibleEventHandler> getType()
{
if (TYPE == null)
{
TYPE = new Type<ReferenceVisibleEventHandler>();
}
return TYPE;
}

private Locale selectedLocale;
private boolean isVisible;

public ReferenceVisibleEvent(Locale selectedLocale, boolean isVisble)
{
this.selectedLocale = selectedLocale;
this.isVisible = isVisible;
}

public Locale getSelectedLocale() {
return selectedLocale;
}

public boolean isVisible()
{
return isVisible;
}

@Override
public Type<ReferenceVisibleEventHandler> getAssociatedType()
{
return getType();
}

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

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

public interface ReferenceVisibleEventHandler extends EventHandler
{
void onShowHideReference(ReferenceVisibleEvent event);
}
Expand Up @@ -128,6 +128,9 @@

import de.novanic.eventservice.client.event.RemoteEventService;
import de.novanic.eventservice.client.event.RemoteEventServiceFactory;
import org.zanata.webtrans.client.presenter.TransUnitChangeSourceLangPresenter;
import org.zanata.webtrans.client.view.TransUnitChangeSourceLangDisplay;
import org.zanata.webtrans.client.view.TransUnitChangeSourceLangView;

public class WebTransClientModule extends AbstractPresenterModule
{
Expand Down Expand Up @@ -166,6 +169,7 @@ protected void configure()
bindPresenter(TransUnitsTablePresenter.class, TransUnitsTableDisplay.class, TransUnitsTableView.class);
bindPresenter(SideMenuPresenter.class, SideMenuDisplay.class, SideMenuView.class);
bind(ForceReviewCommentPresenter.class).asEagerSingleton();
bindPresenter(TransUnitChangeSourceLangPresenter.class, TransUnitChangeSourceLangDisplay.class, TransUnitChangeSourceLangView.class);

bind(SourceContentsPresenter.class).in(Singleton.class);
bind(TargetContentsDisplay.class).to(TargetContentsView.class);
Expand Down
Expand Up @@ -187,6 +187,16 @@ public void onTMOrGlossaryDisplayOptionsChanged(Boolean showTMChkValue, Boolean
boolean displaySouthPanel = showTMChkValue || showGlossaryChkValue;
eventBus.fireEvent(new DisplaySouthPanelEvent(displaySouthPanel));
}

@Override
public void onEnableReferenceForSourceLangOptionChanged(Boolean displayReference)
{
if (userOptionsService.getConfigHolder().getState().isEnabledReferenceForSourceLang() != displayReference)
{
userOptionsService.getConfigHolder().setEnableReferenceForSourceLang(displayReference);
}
eventBus.fireEvent(UserConfigChangeEvent.EDITOR_CONFIG_CHANGE_EVENT);
}

@Override
public void onDisplayTransUnitDetailsOptionChanged(Boolean showTransUnitDetailsChkValue)
Expand Down
Expand Up @@ -47,31 +47,47 @@
import com.google.common.collect.Iterables;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.inject.Inject;
import org.zanata.webtrans.client.events.NotificationEvent;
import org.zanata.webtrans.client.events.RefreshPageEvent;
import org.zanata.webtrans.client.events.RefreshPageEventHandler;
import org.zanata.webtrans.client.events.ReferenceVisibleEvent;
import org.zanata.webtrans.client.events.ReferenceVisibleEventHandler;
import org.zanata.webtrans.client.rpc.CachingDispatchAsync;
import org.zanata.webtrans.shared.model.Locale;
import org.zanata.webtrans.shared.rpc.GetTargetForLocale;
import org.zanata.webtrans.shared.rpc.GetTargetForLocaleResult;

/**
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a>
*
*/
public class SourceContentsPresenter implements ClickHandler, UserConfigChangeHandler, TransUnitUpdatedEventHandler
public class SourceContentsPresenter implements ClickHandler, UserConfigChangeHandler, TransUnitUpdatedEventHandler, ReferenceVisibleEventHandler, RefreshPageEventHandler
{
private final EventBus eventBus;
private final Provider<SourceContentsDisplay> displayProvider;
private final UserConfigHolder configHolder;

private final CachingDispatchAsync dispatcher;

// states
private List<SourceContentsDisplay> displayList = Collections.emptyList();
private TransUnitId currentTransUnitId;
private HasSelectableSource selectedSource;
private Boolean isReferenceShowing = false;
private Locale selectedReferenceLocale;

@Inject
public SourceContentsPresenter(EventBus eventBus, Provider<SourceContentsDisplay> displayProvider, UserConfigHolder configHolder)
public SourceContentsPresenter(EventBus eventBus, Provider<SourceContentsDisplay> displayProvider, CachingDispatchAsync dispatcher, UserConfigHolder configHolder)
{
this.eventBus = eventBus;
this.displayProvider = displayProvider;
this.configHolder = configHolder;
this.dispatcher = dispatcher;
eventBus.addHandler(UserConfigChangeEvent.TYPE, this);
eventBus.addHandler(TransUnitUpdatedEvent.getType(), this);
eventBus.addHandler(ReferenceVisibleEvent.getType(), this);
eventBus.addHandler(RefreshPageEvent.TYPE, this);
}

/**
Expand Down Expand Up @@ -130,6 +146,10 @@ public void showData(List<TransUnit> transUnits)
builder.add(display);
}
displayList = builder.build();
if (isReferenceShowing)
{
showReference();
}
}

public List<SourceContentsDisplay> getDisplays()
Expand Down Expand Up @@ -201,6 +221,61 @@ public void onTransUnitUpdated(TransUnitUpdatedEvent event)
}
}

@Override
public void onShowHideReference(ReferenceVisibleEvent event)
{
if (event.isVisible())
{
isReferenceShowing = true;
selectedReferenceLocale = event.getSelectedLocale();
showReference();
}
else
{
hideReference();
}
}

private void showReference()
{
for (final SourceContentsDisplay display : displayList)
{
GetTargetForLocale action = new GetTargetForLocale(display.getId(), selectedReferenceLocale);
dispatcher.execute(action, new AsyncCallback<GetTargetForLocaleResult>()
{
@Override
public void onFailure(Throwable caught)
{
eventBus.fireEvent(new NotificationEvent(NotificationEvent.Severity.Error, "Failed to fetch target"));
}

@Override
public void onSuccess(GetTargetForLocaleResult result)
{
display.showReference(result.getTarget());
}
});
}
}

public void hideReference()
{
for (SourceContentsDisplay display : displayList)
{
display.hideReference();
}
isReferenceShowing = false;
}

@Override
public void onRefreshPage(RefreshPageEvent event)
{
if (isReferenceShowing)
{
showReference();
}
}

/**
* Get the source string for a trans unit on the current page. This will be
* the currently selected plural form if any is selected.
Expand Down
@@ -0,0 +1,126 @@
/*
* Copyright (C) 2013 Zanata Project.
*
* This library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.zanata.webtrans.client.presenter;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.inject.Inject;
import net.customware.gwt.presenter.client.EventBus;
import net.customware.gwt.presenter.client.widget.WidgetPresenter;
import org.zanata.webtrans.client.events.NotificationEvent;
import org.zanata.webtrans.client.events.ReferenceVisibleEvent;
import org.zanata.webtrans.client.events.UserConfigChangeEvent;
import org.zanata.webtrans.client.events.UserConfigChangeHandler;
import org.zanata.webtrans.client.rpc.CachingDispatchAsync;
import org.zanata.webtrans.client.view.TransUnitChangeSourceLangDisplay;
import org.zanata.webtrans.shared.model.Locale;
import org.zanata.webtrans.shared.rpc.GetLocaleList;
import org.zanata.webtrans.shared.rpc.GetLocaleListResult;

/**
*
* @author Hannes Eskebaek <hannes.eskebaek@databyran.se>
*/
public class TransUnitChangeSourceLangPresenter extends WidgetPresenter<TransUnitChangeSourceLangDisplay> implements TransUnitChangeSourceLangDisplay.Listener, UserConfigChangeHandler
{
private final CachingDispatchAsync dispatcher;

private final UserConfigHolder configHolder;

@Inject
public TransUnitChangeSourceLangPresenter(TransUnitChangeSourceLangDisplay display, EventBus eventBus, CachingDispatchAsync dispatcher, UserConfigHolder configHolder)
{
super(display, eventBus);
this.dispatcher = dispatcher;
this.configHolder = configHolder;
display.setListener(this);

setDisplayMode();
}

@Override
protected void onBind()
{
buildListBox();
registerHandler(eventBus.addHandler(UserConfigChangeEvent.TYPE, this));
}

@Override
protected void onUnbind()
{
}

@Override
protected void onRevealDisplay()
{
}

private void buildListBox()
{
GetLocaleList action = new GetLocaleList();

dispatcher.execute(action, new AsyncCallback<GetLocaleListResult>()
{
@Override
public void onFailure(Throwable caught)
{
eventBus.fireEvent(new NotificationEvent(NotificationEvent.Severity.Error, "Failed to fetch locales"));
}

@Override
public void onSuccess(GetLocaleListResult result)
{
display.buildListBox(result.getLocales());
}
});
}

@Override
public void onShowReference(Locale selectedLocale)
{
eventBus.fireEvent(new ReferenceVisibleEvent(selectedLocale, true));
}

@Override
public void onHideReference()
{
eventBus.fireEvent(new ReferenceVisibleEvent(null, false));
}

@Override
public void onUserConfigChanged(UserConfigChangeEvent event)
{
if (event == UserConfigChangeEvent.EDITOR_CONFIG_CHANGE_EVENT)
{
setDisplayMode();
}
}

private void setDisplayMode()
{
if (configHolder.getState().isEnabledReferenceForSourceLang())
{
display.showReferenceList();
}
else
{
eventBus.fireEvent(new ReferenceVisibleEvent(null, false));
display.hideReferenceList();
}
}
}

0 comments on commit d7a4b40

Please sign in to comment.