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

Commit

Permalink
rhbz844820 - handle WorkspaceContextUpdateEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Huang committed Aug 23, 2012
1 parent d89e1d8 commit 7f7e77d
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 51 deletions.
Expand Up @@ -176,7 +176,7 @@ public void apply(Event event)
GwtEvent<?> gwtEvent = eventRegistry.getEvent(ed);
if (gwtEvent != null)
{
Log.info("received event " + event + ", GWT event " + gwtEvent.getClass().getName());
Log.debug("received event " + event + ", GWT event " + gwtEvent.getClass().getName());
try
{
eventBus.fireEvent(gwtEvent);
Expand Down
Expand Up @@ -125,7 +125,7 @@ public void gotoFuzzyRow(NavigationType nav) {
}

public boolean isEditing() {
return cellValue != null && targetContentsPresenter.isEditing();
return cellValue != null && targetContentsPresenter.displayIsEditable();
}

public boolean isOpened() {
Expand Down Expand Up @@ -184,7 +184,7 @@ public void savePendingChange(boolean cancelIfUnchanged) {
Log.debug("savePendingChange- cancel edit");
cancelEdit();
}
targetContentsPresenter.setToViewMode();
// targetContentsPresenter.setToViewMode();
}

public boolean hasTargetContentsChanged() {
Expand All @@ -211,7 +211,7 @@ public void acceptEdit() {
cellValue.setTargets(newTargets);
determineStatus(newTargets, ContentState.Approved);

targetContentsPresenter.setToViewMode();
// targetContentsPresenter.setToViewMode();
isOpened = false;

// Send the new cell value to the callback
Expand Down Expand Up @@ -277,7 +277,7 @@ public void cancelEdit() {
return;
}

targetContentsPresenter.setToViewMode();
// targetContentsPresenter.setToViewMode();
isOpened = false;

// Call the callback
Expand Down
Expand Up @@ -351,7 +351,7 @@ public void onTransUnitUpdated(TransUnitUpdatedEvent event)
{
navigationService.updateState(event.getUpdateInfo().getTransUnit().getId().getId(), event.getUpdateInfo().getTransUnit().getStatus());

boolean editing = targetContentsPresenter.isEditing();
boolean editing = !targetContentsPresenter.isReadOnly();
Integer rowIndex = navigationService.getRowNumber(event.getUpdateInfo().getTransUnit(), display.getRowValues());
boolean updateRow = true;
boolean reopen = false;
Expand Down
Expand Up @@ -154,7 +154,7 @@ public void renderRowValue(TransUnit rowValue, ColumnDefinition<TransUnit, Trans
final VerticalPanel targetPanel = new VerticalPanel();

TargetContentsDisplay contentsDisplay = targetContentsPresenter.setValue(rowValue);
targetContentsPresenter.setToViewMode();
// targetContentsPresenter.setToViewMode();

targetPanel.add(contentsDisplay.asWidget());
targetPanel.setWidth("100%");
Expand Down
Expand Up @@ -45,6 +45,8 @@ public interface TargetContentsDisplay extends WidgetDisplay, IsWidget

Integer getVerNum();

void setToMode(ToggleEditor.ViewMode viewMode);

interface Listener
{
void validate(ToggleEditor editor);
Expand Down Expand Up @@ -72,8 +74,6 @@ interface Listener

ArrayList<String> getNewTargets();

void setToView();

boolean isEditing();

ArrayList<ToggleEditor> getEditors();
Expand Down
Expand Up @@ -49,6 +49,8 @@
import org.zanata.webtrans.client.events.TransUnitSaveEvent;
import org.zanata.webtrans.client.events.UserConfigChangeEvent;
import org.zanata.webtrans.client.events.UserConfigChangeHandler;
import org.zanata.webtrans.client.events.WorkspaceContextUpdateEvent;
import org.zanata.webtrans.client.events.WorkspaceContextUpdateEventHandler;
import org.zanata.webtrans.client.keys.KeyShortcut;
import org.zanata.webtrans.client.keys.KeyShortcut.KeyEvent;
import org.zanata.webtrans.client.keys.Keys;
Expand Down Expand Up @@ -95,7 +97,8 @@ public class TargetContentsPresenter implements
UserConfigChangeHandler,
RequestValidationEventHandler,
InsertStringInEditorHandler,
CopyDataToEditorHandler
CopyDataToEditorHandler,
WorkspaceContextUpdateEventHandler
// @formatter:on
{
private static final int LAST_INDEX = -2;
Expand Down Expand Up @@ -363,28 +366,19 @@ private void bindEventHandlers()
eventBus.addHandler(CopyDataToEditorEvent.getType(), this);
eventBus.addHandler(TransUnitEditEvent.getType(), this);
eventBus.addHandler(EnableModalNavigationEvent.getType(), this);
eventBus.addHandler(WorkspaceContextUpdateEvent.getType(), this);
}

private ToggleEditor getCurrentEditor()
{
return currentEditors.get(currentEditorIndex);
}

//TODO to be removed
public boolean isEditing()
public boolean displayIsEditable()
{
return display != null && display.isEditing();
}

public void setToViewMode()
{
for (TargetContentsDisplay targetContentsDisplay : displayList)
{
targetContentsDisplay.setToView();
targetContentsDisplay.showButtons(false);
}
}

public void showEditors(int rowIndex, TransUnitId currentTransUnitId)
{
Log.info("enter show editor with rowIndex:" + rowIndex);
Expand All @@ -394,10 +388,6 @@ public void showEditors(int rowIndex, TransUnitId currentTransUnitId)

for (ToggleEditor editor : display.getEditors())
{
if (!userWorkspaceContext.hasReadOnlyAccess())
{
editor.setViewMode(ToggleEditor.ViewMode.EDIT);
}
editor.clearTranslatorList();
validate(editor);
}
Expand All @@ -406,9 +396,16 @@ public void showEditors(int rowIndex, TransUnitId currentTransUnitId)

normaliseCurrentEditorIndex();

validationMessagePanel.clear();
display.focusEditor(currentEditorIndex);
updateTranslators();
if (!userWorkspaceContext.hasReadOnlyAccess())
{
validationMessagePanel.clear();
display.focusEditor(currentEditorIndex);
updateTranslators();
}
else
{
display.setToMode(ViewMode.VIEW);
}
}

private void normaliseCurrentEditorIndex()
Expand Down Expand Up @@ -556,7 +553,6 @@ public void copySource(ToggleEditor editor)
currentEditorIndex = editor.getIndex();
display.showButtons(isDisplayButtons());
editor.setTextAndValidate(sourceContentsPresenter.getSelectedSource());
editor.setViewMode(ViewMode.EDIT);
editor.autoSize();
editor.setFocus();

Expand Down Expand Up @@ -660,7 +656,6 @@ public void onRequestValidation(RequestValidationEvent event)
{
for (ToggleEditor editor : display.getEditors())
{
editor.setViewMode(ToggleEditor.ViewMode.EDIT);
validate(editor);
}
}
Expand Down Expand Up @@ -728,6 +723,10 @@ public void showData(List<TransUnit> transUnits)
TargetContentsDisplay display = displayProvider.get();
display.setListener(this);
display.setValue(transUnit);
if (userWorkspaceContext.hasReadOnlyAccess())
{
display.setToMode(ViewMode.VIEW);
}
display.showButtons(isDisplayButtons());
builder.add(display);
}
Expand Down Expand Up @@ -762,4 +761,29 @@ public void setFocus()
display.focusEditor(currentEditorIndex);
}
}

@Override
public void onWorkspaceContextUpdated(WorkspaceContextUpdateEvent event)
{
userWorkspaceContext.setProjectActive(event.isProjectActive());
if (displayIsEditable() && userWorkspaceContext.hasReadOnlyAccess())
{
Log.debug("from editable to readonly");
for (TargetContentsDisplay targetContentsDisplay : displayList)
{
targetContentsDisplay.setToMode(ViewMode.VIEW);
targetContentsDisplay.showButtons(false);
}
}
else if (!displayIsEditable() && !userWorkspaceContext.hasReadOnlyAccess())
{
Log.debug("from readonly mode to writable");
for (TargetContentsDisplay targetContentsDisplay : displayList)
{
targetContentsDisplay.setToMode(ViewMode.EDIT);
targetContentsDisplay.showButtons(isDisplayButtons());
}
}

}
}
Expand Up @@ -28,7 +28,6 @@
import org.zanata.webtrans.client.ui.ToggleEditor;
import org.zanata.webtrans.client.ui.UndoLink;
import org.zanata.webtrans.shared.model.TransUnit;
import org.zanata.webtrans.shared.model.TransUnitId;

import com.google.common.base.Objects;
import com.google.common.collect.Lists;
Expand Down Expand Up @@ -114,7 +113,6 @@ public void addUndo(final UndoLink undoLink)
@Override
public void preUndo()
{
setToView();
}

@Override
Expand Down Expand Up @@ -147,7 +145,6 @@ public void setValue(TransUnit transUnit)
rowIndex++;
}
editorGrid.setStyleName(resolveStyleName(transUnit.getStatus()));
undoContainer.clear();
}

private static String resolveStyleName(ContentState status)
Expand Down Expand Up @@ -215,17 +212,6 @@ public ArrayList<String> getNewTargets()
}

@Override
public void setToView()
{
for (ToggleEditor editor : editors)
{
editor.removeValidationMessagePanel();
editor.setViewMode(ToggleEditor.ViewMode.VIEW);
}
}

@Override
//TODO do we need this?
public boolean isEditing()
{
for (ToggleEditor editor : editors)
Expand Down Expand Up @@ -256,6 +242,19 @@ public Integer getVerNum()
return verNum;
}

@Override
public void setToMode(ToggleEditor.ViewMode viewMode)
{
for (ToggleEditor editor : editors)
{
editor.setViewMode(viewMode);
if (viewMode == ToggleEditor.ViewMode.VIEW)
{
editor.removeValidationMessagePanel();
}
}
}

@Override
public Widget asWidget()
{
Expand Down
Expand Up @@ -140,10 +140,6 @@ public Editor(String displayString, String findMessage, int index, final TargetC
label.setTitle(messages.clickHere());
setViewMode(ViewMode.EDIT);
}
else
{
setViewMode(ViewMode.VIEW);
}
}

private void setLabelText(String displayString)
Expand Down Expand Up @@ -338,7 +334,13 @@ public void insertTextInCursorPosition(String suggestion)
@Override
public String toString()
{
return Objects.toStringHelper(this).add("label", label.getText()).add("textArea", textArea.getText()).add("isOpen", textArea.isVisible()).toString();
// @formatter:off
return Objects.toStringHelper(this)
// .add("label", label.getText())
// .add("textArea", textArea.getText())
.add("isOpen", textArea.isVisible())
.toString();
// @formatter:on
}

@Override
Expand Down
Expand Up @@ -129,9 +129,9 @@ private void verifyRevealDisplay()
@Test
public void canSetToViewMode()
{
presenter.setToViewMode();
// presenter.setToViewMode();

verify(display).setToView();
// verify(display).setToView();
verify(display).showButtons(false);
}

Expand Down

0 comments on commit 7f7e77d

Please sign in to comment.