How to expand single column in Aggregatetable Demo

This is the forum for JIDE Common Layer which is open sourced at https://github.com/jidesoft/jide-oss. Please note, JIDE technical support doesn't monitor this forum as often as other forums. Please consider subscribe for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

Moderator: JIDE Support

Forum rules
Community driven forum for open source JIDE Common Layer. JIDE technical support doesn't monitor this forum as often as other forums. If you only use JIDE Common Layer, please consider subscribing for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

How to expand single column in Aggregatetable Demo

Postby RajaRajeswari_V » Wed May 13, 2009 12:50 am

Hi

In the examples that you have provided with the jide-Evaluation version.. In the AggregateTableDemo Class, can we show the expand button depending upon the data...if the related column contains more than one row then only we need to display the expand button of the parent row..
For Ex:
Column1 column2
+Increse Revenues Improved New Product Introduction
Improved New Product Introduction
Reduce Costs Improve customer service operation


is it possible to display the data as shown in the above table. in that increse revenues row should display the expand button and reduce costs should not...


Please do the help asap...
RajaRajeswari_V
 
Posts: 25
Joined: Tue Apr 28, 2009 8:33 pm

Re: How to expand single column in Aggregatetable Demo

Postby JIDE Support » Wed May 13, 2009 8:53 am

Please try override AggregateTable#isExpandIconVisible().

The following code is just a demostration to show you how you get the PivotField instance from the node. After getting the PivotField information, you can add any check by your wish.
Code: Select all
            int index = node.getLevel();
            PivotField[] rowFields = getAggregateTableModel().getPivotDataModel().getRowFields();
            PivotField field;
            if (rowFields.length > index && index >= 0) {
                field = rowFields[index];
                showIcon = field.isExpandable();
            }


Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: How to expand single column in Aggregatetable Demo

Postby RajaRajeswari_V » Wed May 13, 2009 10:10 pm

thanks for your quick reply..by using above code i can show the expand button for the field i want ..but my requirement is to display expand button depending upon the associated data..if the field contains more than 1 associatve data then only we need to show the expand button...

For example

Column 1 Column2

-Increse Revenues Improved New Product
Improve product availabity

-ReduceCosts Improve Customer Service Operation


in the above example reduce costs column is also showing the expand button even it contains only one associated data..

My requirement is i dont want to show the
the expand button for reduce costs and want to show the expand button for increse revenues..

Please Help me in this...
RajaRajeswari_V
 
Posts: 25
Joined: Tue Apr 28, 2009 8:33 pm

Re: How to expand single column in Aggregatetable Demo

Postby JIDE Support » Wed May 13, 2009 10:16 pm

What I meant is that now you have both node and field information, you can do anything you want.

For your request, please use the following code:

Code: Select all
        showIcon = node instanceof Expandable && ((Expandable) node).getAllVisibleChildrenCount() > 1;


Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: How to expand single column in Aggregatetable Demo

Postby RajaRajeswari_V » Thu May 14, 2009 12:50 am

hi,

how will i get the node object..


thanks,
RajaRajeswari_V
 
Posts: 25
Joined: Tue Apr 28, 2009 8:33 pm

Re: How to expand single column in Aggregatetable Demo

Postby jamindhar » Thu May 14, 2009 4:44 am

how can i get the node object...:(
jamindhar
 
Posts: 18
Joined: Mon Aug 25, 2008 11:53 pm

Re: How to expand single column in Aggregatetable Demo

Postby JIDE Support » Thu May 14, 2009 8:39 am

While you override AggregateTable#isExpandIconVisible(Node), the node will be passed in as a parameter.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: How to expand single column in Aggregatetable Demo

Postby jamindhar » Thu May 14, 2009 8:18 pm

when i am using that method..it is not calling automatically...:(
jamindhar
 
Posts: 18
Joined: Mon Aug 25, 2008 11:53 pm

Re: How to expand single column in Aggregatetable Demo

Postby JIDE Support » Thu May 14, 2009 8:39 pm

It's weird. That method is used to decide if we should paint the icon so it should be invoked anyway.

Below is my full test case based on AggregateTableDemo, I just simply returns true if the children count of the node is bigger than 5. Please let me know if you encounter any further issue.

Code: Select all
/*
 * @(#)AggregateTableDemo.java 8/23/2007
 *
 * Copyright 2002 - 2007 JIDE Software Inc. All rights reserved.
 */

import com.jidesoft.converter.MonthNameConverter;
import com.jidesoft.converter.QuarterNameConverter;
import com.jidesoft.converter.YearNameConverter;
import com.jidesoft.grid.*;
import com.jidesoft.grouper.date.DateMonthGrouper;
import com.jidesoft.grouper.date.DateQuarterGrouper;
import com.jidesoft.grouper.date.DateWeekOfYearGrouper;
import com.jidesoft.grouper.date.DateYearGrouper;
import com.jidesoft.hssf.HssfTableUtils;
import com.jidesoft.pivot.*;
import com.jidesoft.plaf.LookAndFeelFactory;
import com.jidesoft.swing.JideBoxLayout;
import com.jidesoft.swing.JideSplitPane;
import com.jidesoft.swing.JideSwingUtilities;
import com.jidesoft.swing.JideTabbedPane;

import javax.swing.*;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.Vector;
import java.util.zip.GZIPInputStream;

/**
 * Demoed Component: {@link com.jidesoft.pivot.PivotTablePane} <br> Required jar files: jide-common.jar, jide-grids.jar
 * <br> Required L&F: any L&F
 */
public class AggregateTableDemo extends AbstractDemo {
    public AggregateTable _aggregateTable;
    public AggregateTablePane _aggregateTablePane;
    private static final long serialVersionUID = -4424254279039211160L;

    public AggregateTableDemo() {
    }

    public String getName() {
        return "Aggregate Table Demo";
    }

    public String getProduct() {
        return PRODUCT_NAME_PIVOT;
    }

    @Override
    public String getDescription() {
        return "\n" +
                "Demoed classes:\n" +
                "com.jidesoft.pivot.AggregateTableModel" +
                "com.jidesoft.pivot.AggregateTable" +
                "com.jidesoft.pivot.AggregateTablePane";
    }

//    static CellStyle HIGH_STYLE = new CellStyle();
//    static CellStyle LOW_STYLE = new CellStyle();
//    static CellStyle SUMMARY_STYLE = new CellStyle();
//    static CellStyle DEFAULT_STYLE = new CellStyle();
//    static CellStyle HEADER_STYLE = new CellStyle();
//
//    static {
//        HIGH_STYLE.setForeground(Color.WHITE);
//        HIGH_STYLE.setBackground(Color.RED);
//
//        LOW_STYLE.setBackground(Color.YELLOW);
//
//        SUMMARY_STYLE.setBackground(new Color(255, 255, 215));
//
//        HEADER_STYLE.setFontStyle(Font.BOLD);
//    }

    private String _lastDirectory = ".";

    public Component getDemoPanel() {
        final TableModel tableModel = createProductReportsTableModel();

        if (tableModel == null) {
            return new JLabel("Failed to read data file");
        }

        QuickTableFilterField field = new QuickTableFilterField(tableModel);

        final CalculatedTableModel calculatedTableModel = setupProductDetailsCalculatedTableModel(field.getDisplayTableModel());

        _aggregateTable = new AggregateTable(calculatedTableModel) {
            @Override
            public boolean isExpandIconVisible(Node node) {
                return node instanceof Expandable && ((Expandable) node).getAllVisibleChildrenCount() > 5;
            }
        };
        _aggregateTable.getAggregateTableModel().getPivotDataModel().getField("Year").setSummaryType(PivotConstants.SUMMARY_NONE);
        _aggregateTable.getAggregateTableModel().getPivotDataModel().getField("Year").setGrandTotalSummaryType(PivotConstants.SUMMARY_NONE);
        _aggregateTable.getAggregateTableModel().getPivotDataModel().getField("Month").setSummaryType(PivotConstants.SUMMARY_NONE);
        _aggregateTable.getAggregateTableModel().getPivotDataModel().getField("Month").setGrandTotalSummaryType(PivotConstants.SUMMARY_NONE);
        _aggregateTable.getAggregateTableModel().getPivotDataModel().getField("Quarter").setSummaryType(PivotConstants.SUMMARY_NONE);
        _aggregateTable.getAggregateTableModel().getPivotDataModel().getField("Quarter").setGrandTotalSummaryType(PivotConstants.SUMMARY_NONE);
        _aggregateTable.getAggregateTableModel().getPivotDataModel().getField("Week").setSummaryType(PivotConstants.SUMMARY_NONE);
        _aggregateTable.getAggregateTableModel().getPivotDataModel().getField("Week").setGrandTotalSummaryType(PivotConstants.SUMMARY_NONE);
        _aggregateTable.getAggregateTableModel().getPivotDataModel().getField("ShippedDate").setSummaryType(PivotConstants.SUMMARY_NONE);
        _aggregateTable.getAggregateTableModel().getPivotDataModel().getField("ShippedDate").setGrandTotalSummaryType(PivotConstants.SUMMARY_NONE);

// the commented code is an example to enable subtotal.
//        _aggregateTable.getAggregateTableModel().getField("CategoryName").setSubtotalType(PivotConstants.SUBTOTAL_CUSTOM);
//        _aggregateTable.getAggregateTableModel().getField("CategoryName").setCustomSubtotals(new int[]{PivotConstants.SUMMARY_COUNT, PivotConstants.SUMMARY_MEAN});
//        _aggregateTable.getAggregateTableModel().setShowSummary(true);

        TableHeaderPopupMenuInstaller installer = new TableHeaderPopupMenuInstaller(_aggregateTable) {
            @Override
            protected void customizeMenuItems(final JTableHeader header, final JPopupMenu popup, final int clickingColumn) {
                super.customizeMenuItems(header, popup, clickingColumn);

                addSeparatorIfNecessary(popup);

                final JMenuItem export = new JMenuItem(new AbstractAction("Export to Excel") {
                    public void actionPerformed(ActionEvent e) {
                        if (!HssfTableUtils.isHssfInstalled()) {
                            JOptionPane.showMessageDialog((Component) e.getSource(), "Export to Excel feature is disabled in the webstart demo because hssf.jar is not in the classpath.");
                            return;
                        }
                        JFileChooser chooser = new JFileChooser() {
                            @Override
                            protected JDialog createDialog(Component parent) throws HeadlessException {
                                JDialog dialog = super.createDialog(parent);
                                dialog.setTitle("Export the content to an \".xls\" file");
                                return dialog;
                            }
                        };
                        chooser.setCurrentDirectory(new File(_lastDirectory));
                        int result = chooser.showDialog(((JMenuItem) e.getSource()).getTopLevelAncestor(), "Export");
                        if (result == JFileChooser.APPROVE_OPTION) {
                            _lastDirectory = chooser.getCurrentDirectory().getAbsolutePath();
                            try {
                                HssfTableUtils.export(_aggregateTable, chooser.getSelectedFile().getAbsolutePath(), "AggregateTable", false);
                            }
                            catch (IOException ex) {
                                ex.printStackTrace();
                            }
                        }
                    }
                });
                popup.add(export);

                JMenuItem verify = new JMenuItem("Verify");
                verify.addActionListener(new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        CellSpanTable.verifyCellSpan(_aggregateTable.getAggregateTableModel().getPivotDataModel().getRowHeaderTableModel());
                    }
                });
                popup.add(verify);

            }
        };
        installer.addTableHeaderPopupMenuCustomizer(new AutoResizePopupMenuCustomizer());
        installer.addTableHeaderPopupMenuCustomizer(new AggregateTablePopupMenuCustomizer());
        AggregateTableColumnChooserPopupMenuCustomizer menuCustomizer = new AggregateTableColumnChooserPopupMenuCustomizer();
        menuCustomizer.setFavoriteColumns(new int[]{0, 1, 3, 4});
        menuCustomizer.setHiddenColumns(new int[]{5});
        menuCustomizer.setFixedColumns(new int[]{0, 3});
        installer.addTableHeaderPopupMenuCustomizer(menuCustomizer);
        installer.addTableHeaderPopupMenuCustomizer(new SelectTablePopupMenuCustomizer());
//        installer.addTableHeaderPopupMenuCustomizer(new TableHeaderPopupMenuCustomizer() {
//            public void customizePopupMenu(JTableHeader header, JPopupMenu popup, int clickingColumn) {
//                popup.add(new JMenuItem(new AbstractAction("Custom...") {
//                    public void actionPerformed(ActionEvent e) {
//                        AggregateTableSettingsDialog dialog = new AggregateTableSettingsDialog((JFrame) _aggregateTable.getTopLevelAncestor(), _aggregateTable, "Custom ...");
//                        dialog.pack();
//                        dialog.setLocationRelativeTo(_aggregateTable.getParent());
//                        dialog.setVisible(true);
//                    }
//                }));
//            }
//        });
        _aggregateTable.getAggregateTableModel().setSummaryMode(true);
//        _aggregateTable.getAggregateTableModel().setShowSummary(true);
//        _aggregateTable.aggregate(new String[]{"Year", "Month", "CategoryName"});
//        _aggregateTable.getAggregateTableModel().setShowSummary(true);
//        _aggregateTable.getAggregateTableModel().setShowSummaryOnly(false);
        _aggregateTable.aggregate(new String[]{"CategoryName", "ProductName"});
        _aggregateTable.setPreferredScrollableViewportSize(new Dimension(400, 400));
//        _aggregateTable.getAggregateTableModel().setCellStyleProvider(new CellStyleProvider() {
//            public CellStyle getCellStyleAt(TableModel model, int rowIndex, int columnIndex) {
//                Object value = model.getValueAt(rowIndex, columnIndex);
//                if (columnIndex == 2) {
//                    if (value instanceof Float && ((Float) value).floatValue() > 2000) {
//                        return HIGH_STYLE;
//                    }
//                    else if (value instanceof Float && ((Float) value).floatValue() < 50) {
//                        return LOW_STYLE;
//                    }
//                }
//
//                return DEFAULT_STYLE;
//            }
//        });
        TableUtils.autoResizeAllColumns(_aggregateTable);

        _aggregateTablePane = new AggregateTablePane(calculatedTableModel, new String[]{"CategoryName", "ProductName"});
        TableUtils.autoResizeAllColumns(_aggregateTablePane.getRowHeaderTable());
        TableUtils.autoResizeAllColumns(_aggregateTablePane.getMainTable());

        TableHeaderPopupMenuInstaller installer2 = new TableHeaderPopupMenuInstaller(_aggregateTablePane.getRowHeaderTable());
        installer2.addTableHeaderPopupMenuCustomizer(new AutoResizePopupMenuCustomizer());
        installer2.addTableHeaderPopupMenuCustomizer(new AggregateTablePopupMenuCustomizer());
        installer2.addTableHeaderPopupMenuCustomizer(new SelectTablePopupMenuCustomizer());
        installer2.addTableHeaderPopupMenuCustomizer(new AggregateTableColumnChooserPopupMenuCustomizer());

        TableHeaderPopupMenuInstaller installer3 = new TableHeaderPopupMenuInstaller(_aggregateTablePane.getMainTable());
        installer3.addTableHeaderPopupMenuCustomizer(new AutoResizePopupMenuCustomizer());
        installer3.addTableHeaderPopupMenuCustomizer(new AggregateTablePopupMenuCustomizer());
        installer3.addTableHeaderPopupMenuCustomizer(new SelectTablePopupMenuCustomizer());
        installer3.addTableHeaderPopupMenuCustomizer(new AggregateTableColumnChooserPopupMenuCustomizer());

        JideSplitPane pane = new JideSplitPane(JideSplitPane.VERTICAL_SPLIT);

        JideTabbedPane tabPane = new JideTabbedPane();
        tabPane.add("AggregateTable", new JScrollPane(_aggregateTable));
        tabPane.add("AggregateTable in TableScrollPane", _aggregateTablePane);

        JPanel panel = new JPanel(new BorderLayout(3, 3));
        panel.add(new JLabel("In comparison, below is the original table model before aggregation", SwingConstants.CENTER), BorderLayout.BEFORE_FIRST_LINE);
        panel.add(new JScrollPane(new SortableTable(field.getDisplayTableModel())));
        panel.add(field, BorderLayout.AFTER_LAST_LINE);

        pane.add(JideSwingUtilities.createLabeledComponent(new JLabel("Right click on the table header to see more options"),
                tabPane, BorderLayout.BEFORE_FIRST_LINE));
        pane.add(panel);
        return pane;
    }

    @Override
    public String getDemoFolder() {
        return "P3.AggregateTable";
    }

    public int getAttributes() {
        return ATTRIBUTE_UPDATED;
    }

    @Override
    public Component getOptionsPanel() {
        final JCheckBox showExpandIcon = new JCheckBox("Show Expand Icon");
        showExpandIcon.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                _aggregateTable.setExpandIconVisible(showExpandIcon.isSelected());
                ((CategorizedTable) _aggregateTablePane.getRowHeaderTable()).setExpandIconVisible(showExpandIcon.isSelected());
            }
        });
        showExpandIcon.setSelected(_aggregateTable.isExpandIconVisible());

        JPanel panel = new JPanel();
        panel.setLayout(new JideBoxLayout(panel, BoxLayout.Y_AXIS, 3));
        panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

        panel.add(showExpandIcon);
        panel.add(Box.createGlue(), JideBoxLayout.VARY);

        return panel;
    }

    static public void main(String[] s) {
        LookAndFeelFactory.installDefaultLookAndFeelAndExtension();
        showAsFrame(new AggregateTableDemo());
    }

    private CalculatedTableModel setupProductDetailsCalculatedTableModel(TableModel tableModel) {
        CalculatedTableModel calculatedTableModel = new CalculatedTableModel(tableModel);
        calculatedTableModel.addAllColumns();
        SingleColumn year = new SingleColumn(tableModel, "ShippedDate", "Year", new DateYearGrouper());
        year.setConverterContext(YearNameConverter.CONTEXT);
        calculatedTableModel.addColumn(year);
        SingleColumn qtr = new SingleColumn(tableModel, "ShippedDate", "Quarter", new DateQuarterGrouper());
        qtr.setConverterContext(QuarterNameConverter.CONTEXT);
        calculatedTableModel.addColumn(qtr);
        SingleColumn month = new SingleColumn(tableModel, "ShippedDate", "Month", new DateMonthGrouper());
        month.setConverterContext(MonthNameConverter.CONTEXT);
        calculatedTableModel.addColumn(month);
        calculatedTableModel.addColumn(new SingleColumn(tableModel, "ShippedDate", "Week", new DateWeekOfYearGrouper()));

        return calculatedTableModel;
    }

    private TableModel createProductReportsTableModel() {
        try {
            InputStream resource = this.getClass().getClassLoader().getResourceAsStream("ProductReports.txt.gz");
            if (resource == null) {
                return null;
            }
            InputStream in = new GZIPInputStream(resource);
            BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
            Vector data = new Vector();
            Vector columnNames = new Vector();

            String columnsLine = reader.readLine(); // skip first line
            String[] columnValues = columnsLine.split("\t");
            columnNames.addAll(Arrays.asList(columnValues));

            int count = 0;
            do {
                String line = reader.readLine();
                if (line == null || line.length() == 0) {
                    break;
                }
                String[] values = line.split("\t");
                Vector lineData = new Vector();
                lineData.add(values[0]); // category  name
                lineData.add(values[1]); // product name
                {
                    String value = values[2];
                    if (value.startsWith("$")) {
                        float f = Float.parseFloat(value.substring(1));
                        lineData.add(f); // product amount
                    }
                }
                {
                    String value = values[3];
                    try {
                        SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
                        Date date = format.parse(value);
                        lineData.add(date); // order date
                    }
                    catch (ParseException e) {
                        e.printStackTrace();
                    }
                }
                for (int i = 0; i < 1; i++) {
                    data.add(lineData);
                }
                count++;
                if (count > 200) {
                    break;
                }
            }
            while (true);
            return new ProductTableModel(data, columnNames);
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    private static class ProductTableModel extends DefaultContextSensitiveTableModel {
        public ProductTableModel(Vector data, Vector columnNames) {
            super(data, columnNames);
        }

        @Override
        public Class<?> getColumnClass(int columnIndex) {
            switch (columnIndex) {
                case 0:
                case 1:
                    return String.class;
                case 2:
                    return Float.class;
                case 3:
                    return Date.class;
            }
            return super.getColumnClass(columnIndex);
        }

        @Override
        public boolean isCellEditable(int row, int column) {
            return true;
        }
    }
}


Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am


Return to JIDE Common Layer Open Source Project Discussion (Community Driven)

Who is online

Users browsing this forum: No registered users and 52 guests