Package tableHandlers

Source Code of tableHandlers.MenuPolicyTableCellEditor

package tableHandlers;

import java.awt.Component;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.util.ArrayList;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JTable;

import com.clowtown.mealplanner.policy.Frequency;
import com.clowtown.mealplanner.policy.MenuPolicy;
import com.clowtown.mealplanner.policy.PolicyEnum;
import com.clowtown.mealplanner.policy.Season;

@SuppressWarnings("serial")
public class MenuPolicyTableCellEditor extends AbsTableCellEditor {

  MenuPolicyChooserDialog dialog;
  MenuPolicy p;
  public MenuPolicyTableCellEditor(JFrame mainMenu,Season[] seasons, Frequency frequency){
    super();
    dialog = new MenuPolicyChooserDialog(mainMenu,seasons,frequency,this);
  }
 
  protected JDialog getDialog(){
    return dialog;
  }
  public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
    MenuPolicy p = ((MenuPolicy)table.getModel().getValueAt(row, column));
    dialog = new MenuPolicyChooserDialog((Frame)dialog.getOwner(),p.getSeasons(),p.getFrequency(),this);
    return button;
  }
  public void actionPerformed(ActionEvent arg0) {
    super.actionPerformed(arg0);
         System.out.println(arg0.getActionCommand());
    if("OK".equalsIgnoreCase(arg0.getActionCommand())){
      Frequency f = dialog.getChosenFrequency();
      ArrayList<Season> s = dialog.getChosenSeasons();
      PolicyEnum[] pe = s.toArray(new PolicyEnum[]{});
      p = new MenuPolicy(pe);
      p.editPolicy(MenuPolicy.ADD, f);
      fireEditingStopped();
      dialog.setVisible(false);
    }
    else if ("Reset".equalsIgnoreCase(arg0.getActionCommand())){
      dialog.resetPolicies();
    }
    else{
      fireEditingCanceled();
      dialog.setVisible(false);
    }
  }

  @Override
  public Object getCellEditorValue() {
    return p;
  }


}
TOP

Related Classes of tableHandlers.MenuPolicyTableCellEditor

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.