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

Commit

Permalink
Work in progress: refactor menuitem command
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed May 29, 2012
1 parent 6bc5b78 commit 44704a0
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 200 deletions.
Expand Up @@ -41,7 +41,6 @@
import org.zanata.webtrans.client.history.HistoryToken;
import org.zanata.webtrans.client.history.Window;
import org.zanata.webtrans.client.resources.WebTransMessages;
import org.zanata.webtrans.client.ui.HasCommand;
import org.zanata.webtrans.shared.auth.Identity;
import org.zanata.webtrans.shared.model.DocumentId;
import org.zanata.webtrans.shared.model.DocumentInfo;
Expand All @@ -67,7 +66,7 @@ public interface Display extends net.customware.gwt.presenter.client.widget.Widg

HasClickHandlers getDocumentsLink();

void setUserLabel(String userLabel);
void initMenuList(String userLabel, Command helpMenuCommand, Command leaveWorkspaceMenuCommand, Command signOutMenuCommand, Command layoutMenuCommand);

void setWorkspaceNameLabel(String workspaceNameLabel, String workspaceTitle);

Expand All @@ -83,14 +82,6 @@ public interface Display extends net.customware.gwt.presenter.client.widget.Widg

void setReadOnlyVisible(boolean visible);

HasCommand getLeaveWorkspaceMenuItem();

HasCommand getHelpMenuItem();

HasCommand getSignOutMenuItem();

HasCommand getLayoutMenuItem();

HasClickHandlers getSearchAndReplaceLink();

HasClickHandlers getErrorNotificationBtn();
Expand Down Expand Up @@ -287,77 +278,75 @@ public void onClick(ClickEvent event)
}
}));

display.getLeaveWorkspaceMenuItem().setCommand(new Command()
display.getSearchAndReplaceLink().addClickHandler(new ClickHandler()
{
@Override
public void execute()
public void onClick(ClickEvent event)
{
// use when opening workspace in new window
// Application.closeWindow();

// use when opening workspace in same window
Application.exitWorkspace();
Application.redirectToZanataProjectHome(workspaceContext.getWorkspaceId());
HistoryToken token = HistoryToken.fromTokenString(history.getToken());
if (!token.getView().equals(MainView.Search))
{
token.setView(MainView.Search);
history.newItem(token.toTokenString());
}
}
});

display.getHelpMenuItem().setCommand(new Command()
registerHandler(eventBus.addHandler(PresenterRevealedEvent.getType(), new PresenterRevealedHandler()
{

@Override
public void execute()
public void onPresenterRevealed(PresenterRevealedEvent event)
{
com.google.gwt.user.client.Window.open(messages.hrefHelpLink(), messages.hrefHelpLink(), null);
// TODO disabled until tests are updated
// if (event.getPresenter() == searchResultsPresenter)
// {
// display.setDocumentLabel("", messages.projectWideSearchAndReplace());
// currentDisplayStats = projectStats;
// }
}
});
}));


display.getSignOutMenuItem().setCommand(new Command()
Command helpMenuCommand = new Command()
{
@Override
public void execute()
{
Application.redirectToLogout();
com.google.gwt.user.client.Window.open(messages.hrefHelpLink(), messages.hrefHelpLink(), null);
}
});
};

display.getLayoutMenuItem().setCommand(new Command()
Command signOutMenuCommand = new Command()
{
@Override
public void execute()
{
layoutSelectorPresenter.show();
Application.redirectToLogout();
}
});
display.getSearchAndReplaceLink().addClickHandler(new ClickHandler()
};

Command leaveWorkspaceMenuCommand = new Command()
{
@Override
public void onClick(ClickEvent event)
public void execute()
{
HistoryToken token = HistoryToken.fromTokenString(history.getToken());
if (!token.getView().equals(MainView.Search))
{
token.setView(MainView.Search);
history.newItem(token.toTokenString());
}
Application.exitWorkspace();
Application.redirectToZanataProjectHome(workspaceContext.getWorkspaceId());
}
});
};

registerHandler(eventBus.addHandler(PresenterRevealedEvent.getType(), new PresenterRevealedHandler()
Command layoutMenuMenuCommand = new Command()
{

@Override
public void onPresenterRevealed(PresenterRevealedEvent event)
public void execute()
{
// TODO disabled until tests are updated
// if (event.getPresenter() == searchResultsPresenter)
// {
// display.setDocumentLabel("", messages.projectWideSearchAndReplace());
// currentDisplayStats = projectStats;
// }
layoutSelectorPresenter.show();
}
}));
};


display.setUserLabel(identity.getPerson().getName());
display.initMenuList(identity.getPerson().getName(), helpMenuCommand, leaveWorkspaceMenuCommand, signOutMenuCommand, layoutMenuMenuCommand);
String workspaceTitle = windowLocation.getParameter(WORKSPACE_TITLE_QUERY_PARAMETER_KEY);
display.setWorkspaceNameLabel(workspaceContext.getWorkspaceName(), workspaceTitle);
window.setTitle(messages.windowTitle(workspaceContext.getWorkspaceName(), workspaceContext.getLocaleName()));
Expand Down
Expand Up @@ -47,7 +47,6 @@
import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.user.client.Event.NativePreviewEvent;
import com.google.gwt.user.client.Event.NativePreviewHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
Expand Down
Expand Up @@ -278,8 +278,8 @@ public interface WebTransMessages extends Messages
@DefaultMessage("Error notification")
String errorNotification();

@DefaultMessage("Layout")
String layout();
@DefaultMessage("View Selection")
String viewSelection();

@DefaultMessage("Available Keyboard Shortcuts")
String availableKeyShortcutsTitle();
Expand Down

This file was deleted.

This file was deleted.

Expand Up @@ -29,9 +29,7 @@
import org.zanata.webtrans.client.presenter.TranslationPresenter;
import org.zanata.webtrans.client.resources.Resources;
import org.zanata.webtrans.client.resources.WebTransMessages;
import org.zanata.webtrans.client.ui.HasCommand;
import org.zanata.webtrans.client.ui.ImageLabel;
import org.zanata.webtrans.client.ui.MenuCommandItem;
import org.zanata.webtrans.client.ui.TransUnitCountBar;
import org.zanata.webtrans.shared.auth.Identity;

Expand All @@ -52,6 +50,7 @@
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.MenuItem;
import com.google.gwt.user.client.ui.PushButton;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
Expand Down Expand Up @@ -112,13 +111,13 @@ interface Styles extends CssResource

MenuBar menuBar;

MenuCommandItem helpMenuItem;
MenuItem helpMenuItem;

MenuCommandItem leaveWorkspaceMenuItem;
MenuItem leaveWorkspaceMenuItem;

MenuCommandItem signOutMenuItem;
MenuItem signOutMenuItem;

MenuCommandItem layoutMenuItem;
MenuItem layoutMenuItem;

// TODO may be able to make these provided=true widgets
private Widget documentListView;
Expand All @@ -129,13 +128,6 @@ interface Styles extends CssResource

private final String userAvatarUrl;

private Command emptyCommand = new Command()
{
public void execute()
{
}
};

@Inject
public AppView(Resources resources, WebTransMessages messages, DocumentListPresenter.Display documentListView, SearchResultsPresenter.Display searchResultsView, TranslationPresenter.Display translationView, final Identity identity)
{
Expand All @@ -152,22 +144,7 @@ public AppView(Resources resources, WebTransMessages messages, DocumentListPrese

initWidget(uiBinder.createAndBindUi(this));

menuBar = new MenuBar(true);
helpMenuItem = new MenuCommandItem(messages.help(), emptyCommand);
leaveWorkspaceMenuItem = new MenuCommandItem(messages.leaveWorkspace(), emptyCommand);
signOutMenuItem = new MenuCommandItem(messages.signOut(), emptyCommand);
layoutMenuItem = new MenuCommandItem(messages.layout(), emptyCommand);

searchAndReplace.setText(messages.searchAndReplace());


menuBar.addItem(helpMenuItem);
menuBar.addSeparator();
menuBar.addItem(layoutMenuItem);
menuBar.addSeparator();
menuBar.addItem(leaveWorkspaceMenuItem);
menuBar.addItem(signOutMenuItem);

userAvatarUrl = identity.getPerson().getAvatarUrl();

this.documentListView = documentListView.asWidget();
Expand Down Expand Up @@ -244,8 +221,23 @@ public HasClickHandlers getDocumentsLink()
}

@Override
public void setUserLabel(String userLabel)
public void initMenuList(String userLabel, Command helpMenuCommand, Command leaveWorkspaceMenuCommand, Command signOutMenuCommand, Command layoutMenuCommand)
{
menuBar = new MenuBar(true);
helpMenuItem = new MenuItem(messages.help(), helpMenuCommand);
leaveWorkspaceMenuItem = new MenuItem(messages.leaveWorkspace(), leaveWorkspaceMenuCommand);
signOutMenuItem = new MenuItem(messages.signOut(), signOutMenuCommand);

menuBar.addItem(helpMenuItem);
menuBar.addSeparator();

ImageLabel layoutImageLabel = new ImageLabel(resources.viewChoose(), messages.viewSelection());
layoutMenuItem = menuBar.addItem(layoutImageLabel.getElement().getInnerHTML(), true, layoutMenuCommand);

menuBar.addSeparator();
menuBar.addItem(leaveWorkspaceMenuItem);
menuBar.addItem(signOutMenuItem);

ImageLabel userMenu = new ImageLabel(userAvatarUrl, userLabel + " " + messages.downArrow());
userMenu.setLabelStyle(style.userName());
userMenu.setImageStyle(style.image());
Expand Down Expand Up @@ -304,30 +296,6 @@ public void setReadOnlyVisible(boolean visible)
readOnlyLabel.setVisible(visible);
}

@Override
public HasCommand getHelpMenuItem()
{
return helpMenuItem;
}

@Override
public HasCommand getLeaveWorkspaceMenuItem()
{
return leaveWorkspaceMenuItem;
}

@Override
public HasCommand getSignOutMenuItem()
{
return signOutMenuItem;
}

@Override
public HasCommand getLayoutMenuItem()
{
return layoutMenuItem;
}

@Override
public HasClickHandlers getSearchAndReplaceLink()
{
Expand Down

0 comments on commit 44704a0

Please sign in to comment.