Package com.cedarsoft.spring.rcp.tree.layered.aspects

Source Code of com.cedarsoft.spring.rcp.tree.layered.aspects.EditAspect$Editor

package com.cedarsoft.spring.rcp.tree.layered.aspects;

import com.cedarsoft.spring.rcp.commands.CommandIds;
import com.cedarsoft.spring.rcp.tree.layered.DefaultTreeLayer;
import com.cedarsoft.spring.rcp.tree.layered.config.PopupConfigurer;
import org.jetbrains.annotations.NotNull;
import org.springframework.richclient.command.ActionCommand;

import javax.swing.JTree;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
*
*/
public class EditAspect<P, C> implements TreeLayerAspect<P, C> {
  @NotNull
  private final Editor<P, C> editor;

  public EditAspect( @NotNull Editor<P, C> editor ) {
    this.editor = editor;
  }

  @Override
  public void apply( @NotNull DefaultTreeLayer<P, C> layer ) {
    layer.addPopupConfigurer( new PopupConfigurer<P, C>() {
      @Override
      protected List<? extends ActionCommand> getCommands( @NotNull final P parent, @NotNull final C selectedChild, @NotNull final JTree source ) {
        List<ActionCommand> commands = new ArrayList<ActionCommand>();

        ActionCommand editCommand = new ActionCommand( CommandIds.EDIT ) {
          @Override
          protected void doExecuteCommand() {
            editor.editEntry( parent, selectedChild, source );
          }
        };

        return Collections.singletonList( editCommand );
      }
    } );
  }

  /**
   * Edits an entry
   *
   * @param <P> the parent type
   * @param <C> the child type
   */
  public interface Editor<P, C> {
    /**
     * Edits an object
     *
     * @param parent        the parent
     * @param selectedChild the selected child
     * @param source        the source tree
     */
    void editEntry( @NotNull P parent, @NotNull C selectedChild, @NotNull JTree source );
  }
}
TOP

Related Classes of com.cedarsoft.spring.rcp.tree.layered.aspects.EditAspect$Editor

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.