private void fillColumns() {

      // remove all columns.
      this.tableColumns.removeAllElements();

      FunctionalGroup g = controller.getSelectedFunctionalGroup();

      if (g != null) {

        Collection<String> stages = g.getStageNames();
        // Sort the stage names alphabetically
        ArrayList<String> stage_names = new ArrayList<String>();
        for (String s : stages) {
          stage_names.add(s);
        }
        Collections.sort(stage_names);
        int modelIndex = 1;

        for (String s : stage_names) {
          TableColumn c = new TableColumn(modelIndex);
          c.setHeaderValue(s);
          this.addColumn(c);
          modelIndex++;
        }
      }
    }
 /**
  * Presents the user with a dialog box to allow them to add a stage to the current functional
  * group
  */
 public void add_stage() {
   if (this.controller.getSelectedCatagory() == null) return;
   String name = JOptionPane.showInputDialog(this, "Choose a name for the stage", "Name Stage", 1);
   if (name == null) {
     return;
   }
   // If the stage cannot be added, inform the user
   if (!controller.addStage(name)) {
     JOptionPane.showMessageDialog(this, "A Stage with that name already exists");
   }
 }
 /**
  * Returns a list of all stage names in the current functional group
  *
  * @return - <code>Collection</code> of Strings corresponding to stage names
  */
 public Collection<String> get_stages() {
   // Get all available stages
   FunctionalGroup g = controller.getSelectedFunctionalGroup();
   if (g != null) {
     Collection<String> stages = g.getStageNames();
     ArrayList<String> stage_names = new ArrayList<String>();
     for (String s : stages) {
       stage_names.add(s);
     }
     // Alphabetise them
     Collections.sort(stage_names);
     return stage_names;
   }
   return null;
 }
    @Override
    /**
     * if x < 2 it returns the function name at y
     *
     * <p>else it returns whether the function(y) is called in the stage(x)
     *
     * @param x
     * @param y return correct value at cell (x, y)
     */
    public Object getValueAt(int x, int y) {

      if (controller.getSelectedFunctionalGroup() == null) {

        return "No Selected Functional Group.";

      } else {
        String stageName = this.getColumnName(y - 1);

        return this.controller.stageIsCalledIn(stageName, x);
      }
    }
 public ColumnModel(FunctionalGroupController controller) {
   super();
   this.controller = controller;
   controller.addObserver(this);
   fillColumns();
 }
 @Override
 public Object getValueAt(int x, int y) {
   return controller.getFunctionalNameAtIndex(x);
 }
 @Override
 public int getRowCount() {
   return controller.getNoFunctions();
 }
 public RowModel(FunctionalGroupController controller) {
   super();
   this.controller = controller;
   controller.addObserver(this);
 }
 /**
  * Rename a chosen stage in the model
  *
  * @param name - The previous name of the stage
  * @param new_name - The new name for the stage
  */
 public void stage_rename(String name, String new_name) {
   controller.rename_stage(name, new_name);
 }
 /**
  * Remove a chosen stage fro mthe model
  *
  * @param select - The name of the selected stage
  */
 public void remove_stage(String select) {
   controller.delete_stage(select);
 }