Package com.cedarsoft.spring.rcp.tbpanel.config

Source Code of com.cedarsoft.spring.rcp.tbpanel.config.PopupConfigurer

package com.cedarsoft.spring.rcp.tbpanel.config;

import com.cedarsoft.spring.SpringSupport;
import com.cedarsoft.spring.rcp.table.ExtendedObjectTable;
import com.cedarsoft.spring.rcp.table.ObjectTable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.richclient.application.config.ApplicationWindowAware;
import org.springframework.richclient.command.ActionCommand;
import org.springframework.richclient.command.CommandGroup;
import org.springframework.richclient.util.RcpSupport;

import java.util.List;

/**
* Configures the popup command group
*
* @param <T> the type
*/
public abstract class PopupConfigurer<T> implements ObjectTableConfigurer<T> {
  @Override
  public void configurePreShow( @NotNull ObjectTable<T> objectTable ) {
  }

  @Override
  public void configurePostShow( @NotNull ObjectTable<T> objectTable ) {
    List<? extends ActionCommand> toAdd = getCommands( objectTable );
    if ( toAdd == null || toAdd.isEmpty() ) {
      return;
    }

    CommandGroup group = objectTable.getPopupCommandGroup();
    if ( group == null ) {
      group = new CommandGroup();
    } else {
      group.addSeparator();
    }

    for ( ActionCommand command : toAdd ) {
      RcpSupport.configure( command );
      if ( command instanceof ApplicationWindowAware ) {
        ( ( ApplicationWindowAware ) command ).setApplicationWindow( SpringSupport.INSTANCE.getActiveApplicationWindow() );
      }
      group.add( command );
    }

    objectTable.setPopupCommandGroup( group );
  }

  //    CommandGroup popup = new CommandGroup();
  //    //todo
  //          popup.add( ( AbstractCommand ) getWindowCommandManager().getCommand( GlobalCommandIds.DELETE, ActionCommand.class ) );
  //    //    popup.addSeparator();
  //    //    popup.add( ( AbstractCommand ) getWindowCommandManager().getCommand( GlobalCommandIds.PROPERTIES, ActionCommand.class ) );
  //    return popup;

  /**
   * Returns the commands
   *
   * @param objectTable the object stable
   * @return the commands or null
   */
  @Nullable
  protected abstract List<? extends ActionCommand> getCommands( @NotNull ObjectTable<T> objectTable );
}
TOP

Related Classes of com.cedarsoft.spring.rcp.tbpanel.config.PopupConfigurer

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.