/*
 * ARX: Efficient, Stable and Optimal Data Anonymization
 * Copyright (C) 2012 - 2014 Florian Kohlmayer, Fabian Prasser
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

package org.deidentifier.arx.gui.view.impl.wizard;

import org.deidentifier.arx.AttributeType.Hierarchy;
import org.deidentifier.arx.gui.view.SWTUtil;
import org.deidentifier.arx.gui.view.impl.define.ViewHierarchy;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

/**
 * The final page that shows an overview of the resulting hierarchy
 * @author Fabian Prasser
 *
 * @param <T>
 */
public class HierarchyWizardPageFinal<T> extends WizardPage{

    /** Var */
    private final HierarchyWizard<T> wizard;
    /** Var */
    private Composite                composite;
    /** Var */
    private Table                    table;
    /** Var */
    private TableColumn              column1;
    /** Var */
    private ViewHierarchy            view;
    /** Var */
    private int[]                    groups;
    /** Var */
    private Hierarchy                hierarchy;
    
    /**
     * Creates a new instance
     * @param wizard
     */
    public HierarchyWizardPageFinal(final HierarchyWizard<T> wizard) {
        super("");
        this.wizard = wizard;
        setTitle("Review the hierarchy");
        setDescription("Overview of groups and values");
        setPageComplete(true);
    }

    @Override
    public boolean canFlipToNextPage() {
        return isPageComplete();
    }

    @Override
    public void  createControl(final Composite parent) {
        composite = new Composite(parent, SWT.NONE);
        composite.setLayout(SWTUtil.createGridLayout(2, false));

        final Group center = new Group(composite, SWT.SHADOW_ETCHED_IN);
        center.setText("Groups");
        center.setLayoutData(SWTUtil.createFillVerticallyGridData());
        center.setLayout(SWTUtil.createGridLayout(1, false));
        
        Composite base = new Composite(center, SWT.NONE);
        base.setLayoutData(SWTUtil.createFillGridData());
        base.setLayout(SWTUtil.createGridLayout(1, false));
        
        table = new Table(base, SWT.BORDER);
        table.setLayoutData(SWTUtil.createFillGridData());
        table.setHeaderVisible(true);
        column1 = new TableColumn(table, SWT.LEFT);
        column1.setText("Count");
        column1.pack();
        
        final Group right = new Group(composite, SWT.SHADOW_ETCHED_IN);
        right.setText("Table");
        right.setLayoutData(SWTUtil.createFillGridData());
        right.setLayout(SWTUtil.createGridLayout(1, false));
        view = new ViewHierarchy(right);

        setControl(composite);
    }

    @Override
    public boolean isPageComplete() {
        return false;
    }
    
    /**
     * Sets the groups
     * @param groups
     */
    public void setGroups(int[] groups){
        this.groups = groups;
    }
    
    /**
     * Sets the hierarchy
     * @param hierarchy
     */
    public void setHierarchy(Hierarchy hierarchy){
        this.hierarchy = hierarchy;
    }
    
    @Override
    public void setVisible(boolean value){
        
        if (value) {
            this.composite.setRedraw(false);
            
            // Reset
            for (TableItem item : table.getItems()) {
                item.dispose();
            }
            this.view.setHierarchy(Hierarchy.create());
            
            if (groups != null) {
                for (int count : groups){
                    TableItem item = new TableItem(table, SWT.NONE);
                    item.setText(new String[]{String.valueOf(count)});
                }
                column1.pack();
            }
            if (hierarchy != null) {
                view.setHierarchy(hierarchy);
            }
            
            this.composite.setRedraw(true);

            // Deactivate buttons
            Button load = this.wizard.getLoadButton();
            if (load != null) load.setEnabled(false);
            Button save = this.wizard.getSaveButton();
            if (save != null) save.setEnabled(false);
        }
        super.setVisible(value);
    }
}

@@ -1212,99 +1212,12 @@
 ets.
-Table;%0Aimport org.eclipse.swt.widgets.TableColumn;%0Aimport org.eclipse.swt.widgets.TableItem
+List
 ;%0A%0A/
@@ -1550,78 +1550,19 @@
 ate 
-Table                    table;%0A    /** Var */%0A    private TableColumn
+List       
     
@@ -1571,23 +1571,20 @@
         
-column1
+list
 ;%0A    /*
@@ -2469,16 +2469,17 @@
 etText(%22
+#
 Groups%22)
@@ -2818,25 +2818,23 @@
     
-table
+list
  = new 
-Table
+List
 (bas
@@ -2846,16 +2846,44 @@
 T.BORDER
+ %7C SWT.V_SCROLL %7C SWT.SINGLE
 );%0A     
@@ -2881,29 +2881,28 @@
 E);%0A        
-table
+list
 .setLayoutDa
@@ -2939,156 +2939,8 @@
 ));%0A
-        table.setHeaderVisible(true);%0A        column1 = new TableColumn(table, SWT.LEFT);%0A        column1.setText(%22Count%22);%0A        column1.pack();%0A
     
@@ -3821,95 +3821,25 @@
     
-for (TableItem item : table.getItems()) %7B%0A                item.dispose();%0A            %7D
+list.removeAll();
 %0A   
@@ -4004,103 +4004,17 @@
     
-TableItem item = new TableItem(table, SWT.NONE);%0A                    item.setText(new String%5B%5D%7B
+list.add(
 Stri
@@ -4030,17 +4030,16 @@
 f(count)
-%7D
 );%0A     
@@ -4055,40 +4055,8 @@
   %7D%0A
-                column1.pack();%0A
     

Replace table with list