OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 110 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
110 ilm 1
package org.openconcerto.modules.reports.olap;
2
 
3
import java.awt.BorderLayout;
159 ilm 4
import java.awt.Dimension;
5
import java.awt.FlowLayout;
110 ilm 6
import java.awt.GridBagConstraints;
7
import java.awt.GridBagLayout;
8
import java.awt.Insets;
9
import java.awt.event.ActionEvent;
10
import java.awt.event.ActionListener;
11
import java.awt.event.MouseAdapter;
12
import java.awt.event.MouseEvent;
159 ilm 13
import java.io.File;
14
import java.io.FileWriter;
15
import java.io.IOException;
110 ilm 16
 
159 ilm 17
import javax.swing.JButton;
18
import javax.swing.JFileChooser;
110 ilm 19
import javax.swing.JLabel;
20
import javax.swing.JMenuItem;
21
import javax.swing.JPanel;
22
import javax.swing.JPopupMenu;
23
import javax.swing.JSeparator;
24
import javax.swing.JSplitPane;
25
import javax.swing.JTabbedPane;
26
 
159 ilm 27
import org.jopendocument.panel.Messages;
110 ilm 28
import org.olap4j.OlapConnection;
29
import org.olap4j.metadata.Schema;
159 ilm 30
import org.openconcerto.modules.reports.olap.renderer.Matrix;
110 ilm 31
import org.openconcerto.ui.JLabelBold;
159 ilm 32
import org.openconcerto.utils.ExceptionHandler;
33
import org.openconcerto.utils.text.CSVWriter;
110 ilm 34
 
35
public class OLAPMainPanel extends JPanel {
36
    OLAPMainPanel(OlapConnection oConnection, Schema schema, final OLAPPanel olapPanel) {
37
        this.setLayout(new GridBagLayout());
38
        this.setOpaque(false);
39
        GridBagConstraints c = new GridBagConstraints();
40
        c.insets = new Insets(2, 3, 2, 2);
41
        JLabel label = new JLabel("Sélectionnez au minimum une colonne et une ligne pour visualiser l'hypercube.");
42
        c.gridx = 0;
43
        c.gridy = 0;
44
        c.fill = GridBagConstraints.HORIZONTAL;
45
        final JLabelBold title = new JLabelBold("Analyse multidimensionnelle des données");
159 ilm 46
        title.setToolTipText(olapPanel.getLoadInfo());
110 ilm 47
        this.addMouseListener(new MouseAdapter() {
48
            @Override
49
            public void mouseReleased(MouseEvent e) {
50
 
51
                final JPopupMenu menu = new JPopupMenu();
52
                final JMenuItem menuItem = new JMenuItem("Recharger la configuration");
53
                menu.add(menuItem);
54
                menuItem.addActionListener(new ActionListener() {
55
 
56
                    @Override
57
                    public void actionPerformed(ActionEvent e) {
58
 
59
                        olapPanel.reload();
60
 
61
                    }
62
                });
63
                menu.show(title, e.getX(), e.getY());
64
 
65
            }
66
        });
67
        this.add(title, c);
68
        c.gridy++;
69
        this.add(label, c);
70
        c.gridy++;
71
        c.insets = new Insets(2, 0, 0, 0);
72
        this.add(new JSeparator(JSeparator.HORIZONTAL), c);
73
        c.gridy++;
74
        c.insets = new Insets(0, 0, 0, 0);
75
        c.fill = GridBagConstraints.BOTH;
76
        JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
77
        split.setBorder(null);
78
        final OLAPParametersPanel parameters = new OLAPParametersPanel(schema);
159 ilm 79
        parameters.setMinimumSize(new Dimension(200, 200));
110 ilm 80
        parameters.setOpaque(false);
81
        split.setLeftComponent(parameters);
159 ilm 82
        split.setDividerLocation(200);
110 ilm 83
        split.setOpaque(true);
84
 
85
        JPanel rightPanel = new JPanel();
86
        rightPanel.setOpaque(false);
87
        rightPanel.setLayout(new BorderLayout());
88
 
89
        final OLAPRenderer renderer = new OLAPRenderer();
90
 
91
        final OLAPMDXPanel mdxPanel = new OLAPMDXPanel(parameters, oConnection, renderer);
159 ilm 92
 
93
        final OLAPSQLPanel sqlPanel = new OLAPSQLPanel(renderer);
94
 
110 ilm 95
        final OLAPConfigurationPanel confPanel = new OLAPConfigurationPanel(parameters, oConnection, renderer, mdxPanel);
96
        parameters.setConfigurationPanel(confPanel);
97
        JTabbedPane t = new JTabbedPane();
98
        t.add("Mode simplifié", confPanel);
99
        t.add("Requête MDX", mdxPanel);
159 ilm 100
        t.add("Requête SQL", sqlPanel);
110 ilm 101
        renderer.setOpaque(false);
102
        t.setOpaque(false);
159 ilm 103
        // Bottom panel
104
        JPanel p = new JPanel();
105
        p.setLayout(new FlowLayout(FlowLayout.LEFT));
106
        JButton bExport = new JButton("Exporter");
107
        bExport.addActionListener(new ActionListener() {
108
 
109
            @Override
110
            public void actionPerformed(ActionEvent e) {
111
 
112
                Matrix m = renderer.getMatrix();
113
                if (m == null) {
114
                    return;
115
                }
116
                JFileChooser fileChooser = new JFileChooser();
117
                fileChooser.setSelectedFile(new File("export_olap.csv"));
118
                fileChooser.setDialogTitle(Messages.getString("ODSViewerPanel.saveAs"));
119
 
120
                int userSelection = fileChooser.showSaveDialog(OLAPMainPanel.this);
121
 
122
                if (userSelection == JFileChooser.APPROVE_OPTION) {
123
                    File file = fileChooser.getSelectedFile();
124
 
125
                    try {
126
                        int witdth = m.getWidth();
127
                        final FileWriter writer = new FileWriter(file);
128
                        CSVWriter w = new CSVWriter(writer);
129
                        for (int y = 0; y < m.getHeight(); y++) {
130
                            String[] a = new String[witdth];
131
                            for (int x = 0; x < witdth; x++) {
132
                                a[x] = m.get(x, y).getValue();
133
                            }
134
                            w.writeNext(a);
135
                            w.flush();
136
                        }
137
                        w.close();
138
                        writer.close();
139
                    } catch (IOException e1) {
140
                        ExceptionHandler.handle("Erreur lors de l'export", e1);
141
                    }
142
                }
143
            }
144
        });
145
 
146
        p.add(bExport);
147
        //
110 ilm 148
        rightPanel.add(t, BorderLayout.NORTH);
149
        rightPanel.add(renderer, BorderLayout.CENTER);
159 ilm 150
        rightPanel.add(p, BorderLayout.SOUTH);
110 ilm 151
        split.setRightComponent(rightPanel);
152
        c.weightx = 1;
153
        c.weighty = 1;
154
        split.setDividerLocation(0.33D);
155
        this.add(split, c);
156
 
157
    }
158
 
159
}