Package com.cedarsoft.spring.rcp.tbpanel.aspects

Source Code of com.cedarsoft.spring.rcp.tbpanel.aspects.DoubleClickCommandAspect

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

import com.cedarsoft.spring.rcp.commands.CommandProvider;
import com.cedarsoft.spring.rcp.table.ExtendedObjectTable;
import com.cedarsoft.spring.rcp.table.ObjectTable;
import com.cedarsoft.spring.rcp.tbpanel.SidePanelCommandsProvider;
import com.cedarsoft.spring.rcp.tbpanel.ObjectTablePanel;
import com.cedarsoft.spring.rcp.tbpanel.config.DoubleClickConfigurer;
import com.cedarsoft.spring.rcp.tbpanel.config.PopupConfigurer;
import org.jetbrains.annotations.NotNull;
import org.springframework.binding.value.ValueModel;
import org.springframework.richclient.application.PageComponentContext;
import org.springframework.richclient.command.ActionCommand;
import org.springframework.richclient.command.support.GlobalCommandIds;
import org.springframework.richclient.list.ListSingleSelectionGuard;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;

/**
* An aspect that adds a souble click command
*
* @param <T> the type
*/
public class DoubleClickCommandAspect<T> implements ObjectTablePanelAspect<T> {
  @NotNull
  private final CommandProvider<ObjectTablePanel<T>> commandProvider;

  public DoubleClickCommandAspect( @NotNull CommandProvider<ObjectTablePanel<T>> commandProvider ) {
    this.commandProvider = commandProvider;
  }

  @Override
  public void apply( @NotNull final ObjectTablePanel<T> panel ) {
    final ActionCommand command = commandProvider.getCommand( panel );

    //Adds the double click
    panel.addConfigurer( new DoubleClickConfigurer<T>( new CommandProvider<ObjectTable<T>>() {
      @Override
      @NotNull
      public ActionCommand getCommand( @NotNull ObjectTable<T> object ) {
        return commandProvider.getCommand( panel );
      }
    } ) );

    //Adds the action to the popup
    panel.addConfigurer( new PopupConfigurer<T>() {
      @NotNull
      @Override
      protected List<? extends ActionCommand> getCommands( @NotNull ObjectTable<T> objectTable ) {
        return Arrays.asList( command );
      }
    } );

    //Adds the action to the side
    panel.addCommandProvider( new SidePanelCommandsProvider() {
      @Override
      @NotNull
      public Collection<? extends ActionCommand> getCommands( @NotNull ValueModel selectionHolder ) {
        //noinspection ResultOfObjectAllocationIgnored
        new ListSingleSelectionGuard( selectionHolder, command );
        return Arrays.asList( command );
      }

      @Override
      public void registerLocalCommandExecutors( @NotNull PageComponentContext context ) {
        context.register( GlobalCommandIds.RUN, command );
      }
    } );
  }

}
TOP

Related Classes of com.cedarsoft.spring.rcp.tbpanel.aspects.DoubleClickCommandAspect

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.