package com.clementscode.mmi.swing;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JPanel;

public class ActionForCategoryItemGui extends AbstractAction {
	private static final long serialVersionUID = 1L;
	private String cmd;
	private GuiForCategoryItem guiForCategoryItem;

	public ActionForCategoryItemGui(String cmd,
			GuiForCategoryItem guiForCategoryItem, String text) {
		super(text);
		this.cmd = cmd;
		this.guiForCategoryItem = guiForCategoryItem;

	}

	public void actionPerformed(ActionEvent e) {
		CrudFrame crudFrame = guiForCategoryItem.getCrudFrame();

		if (CrudFrame.ADD_CATEGORY_ITEM.equals(cmd)) {

			GuiForCategoryItem g4ci = new GuiForCategoryItem(crudFrame);
			crudFrame.getLstGuiForCategoryItems().add(g4ci);
			crudFrame.getDiyTable().add(g4ci);
		} else if (CrudFrame.DELETE_CATEGORY_ITEM.equals(cmd)) {
			JPanel diyTable = crudFrame.getDiyTable();
			diyTable.remove(guiForCategoryItem);
		}
		crudFrame.refreshGui();

	}

}

@@ -30,16 +30,43 @@
 swing;%0A%0A
+import java.awt.Component;%0A
 import j
@@ -92,16 +92,16 @@
 nEvent;%0A
-
 %0Aimport 
@@ -632,17 +632,61 @@
 rame();%0A
+%09%09JPanel diyTable = crudFrame.getDiyTable();
 %0A
-
 %09%09if (Cr
@@ -843,16 +843,273 @@
 (g4ci);%0A
+%09%09%09int oneBellow = 0;%0A%09%09%09int numComponents = diyTable.getComponentCount();%0A%09%09%09for (int n = 0; n %3C numComponents; ++n) %7B%0A%09%09%09%09Component comp = diyTable.getComponent(n);%0A%09%09%09%09if (comp.equals(guiForCategoryItem)) %7B%0A%09%09%09%09%09oneBellow = n + 1;%0A%09%09%09%09%09break;%0A%09%09%09%09%7D%0A%09%09%09%7D%0A
 %09%09%09crudF
@@ -1131,24 +1131,35 @@
 e().add(g4ci
+, oneBellow
 );%0A%09%09%7D else 
@@ -1212,53 +1212,8 @@
 ) %7B%0A
-%09%09%09JPanel diyTable = crudFrame.getDiyTable();
 %0A%09%09%09

Add another button in CrudFrame now adds below the current category item.