Package org.latexlab.docs.client.content.menus

Source Code of org.latexlab.docs.client.content.menus.DynamicLatexBigOperatorsMenu

package org.latexlab.docs.client.content.menus;

import org.latexlab.docs.client.commands.SystemPasteCommand;
import org.latexlab.docs.client.content.latex.LatexCommand;
import org.latexlab.docs.client.content.latex.LatexCommandSet;
import org.latexlab.docs.client.content.latex.SetBigOperators;
import org.latexlab.docs.client.widgets.DynamicMenuBar;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.RunAsyncCallback;
import com.google.gwt.user.client.rpc.AsyncCallback;

/**
* Contains a LaTeX Big Operators menu with on-demand loading.
*/
public class DynamicLatexBigOperatorsMenu extends DynamicMenuBar {

  protected static DynamicLatexBigOperatorsMenu instance;
 
  /**
   * Retrieves the single instance of this class.
   */
  public static DynamicLatexBigOperatorsMenu get() {
    if (instance == null) {
      instance = new DynamicLatexBigOperatorsMenu();
    }
    return instance;
  }
 
  /**
   * Constructs a latex big operators menu.
   */
  protected DynamicLatexBigOperatorsMenu() {
    super(true);
  }

  /**
   * Asynchronously loads the MenuBar's sub items.
   *
   * @param callback the callback carrying the sub items
   */
  @Override
  protected void getSubMenu(final AsyncCallback<ExtendedMenuItem[]> callback) {
    GWT.runAsync(new RunAsyncCallback() {
    @Override
    public void onFailure(Throwable reason) {
        callback.onFailure(reason);
    }
    @Override
    public void onSuccess() {
      LatexCommandSet set = SetBigOperators.get();
      LatexCommand[] cmds = set.getCommands();
      ExtendedMenuItem[] items = new ExtendedMenuItem[cmds.length];
      for (int i=0; i<cmds.length; i++) {
      LatexCommand cmd = cmds[i];
      items[i] = new ExtendedMenuItem(cmd.getIcon(), cmd.getTitle(), new SystemPasteCommand(cmd.getText()));
      }
      callback.onSuccess(items);
    }
    });
  }

}
TOP

Related Classes of org.latexlab.docs.client.content.menus.DynamicLatexBigOperatorsMenu

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.