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

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

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

import org.latexlab.docs.client.commands.CurrentDocumentCopyCommand;
import org.latexlab.docs.client.commands.CurrentDocumentDeleteCommand;
import org.latexlab.docs.client.commands.CurrentDocumentRenameCommand;
import org.latexlab.docs.client.commands.CurrentDocumentRevisionHistoryCommand;
import org.latexlab.docs.client.commands.CurrentDocumentSaveCommand;
import org.latexlab.docs.client.commands.NewDocumentStartCommand;
import org.latexlab.docs.client.commands.SystemShowDialogCommand;
import org.latexlab.docs.client.commands.SystemUploadDocumentsCommand;
import org.latexlab.docs.client.content.dialogs.DynamicFileListDialog;
import org.latexlab.docs.client.content.icons.Icons;
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 File menu with on-demand loading.
*/
public class DynamicFileMenu extends DynamicMenuBar {

  protected static DynamicFileMenu instance;
 
  /**
   * Retrieves the single instance of this class.
   */
  public static DynamicFileMenu get() {
    if (instance == null) {
      instance = new DynamicFileMenu();
    }
    return instance;
  }
 
  /**
   * Constructs a file menu.
   */
  protected DynamicFileMenu() {
    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() {
      callback.onSuccess(new ExtendedMenuItem[] {
      new ExtendedMenuItem(Icons.editorIcons.Blank(), "New", new NewDocumentStartCommand()),
      null,
      new ExtendedMenuItem(Icons.editorIcons.OpenDocument(), "Open", new SystemShowDialogCommand(DynamicFileListDialog.class)),
      new ExtendedMenuItem(Icons.editorIcons.Save(), "Save", new CurrentDocumentSaveCommand(false)),
      new ExtendedMenuItem(Icons.editorIcons.Blank(), "Save as new copy", new CurrentDocumentCopyCommand()),
      new ExtendedMenuItem(Icons.editorIcons.Blank(), "Rename...", new CurrentDocumentRenameCommand()),
      new ExtendedMenuItem(Icons.editorIcons.Blank(), "Delete...", new CurrentDocumentDeleteCommand()),
      new ExtendedMenuItem(Icons.editorIcons.Blank(), "Revision History", new CurrentDocumentRevisionHistoryCommand()),
      null,
      new ExtendedMenuItem(Icons.editorIcons.Blank(), "Export...", DynamicExportMenu.get()),
      null,
      new ExtendedMenuItem(Icons.editorIcons.UploadDocument(), "Upload Files...", new SystemUploadDocumentsCommand()),
      });
    }
    });
  }

}
TOP

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

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.