OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 110 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 110 Rev 159
Line 1... Line 1...
1
package org.openconcerto.modules.reports.olap;
1
package org.openconcerto.modules.reports.olap;
2
 
2
 
3
import java.awt.BorderLayout;
3
import java.awt.BorderLayout;
-
 
4
import java.awt.Dimension;
-
 
5
import java.awt.FlowLayout;
4
import java.awt.GridBagConstraints;
6
import java.awt.GridBagConstraints;
5
import java.awt.GridBagLayout;
7
import java.awt.GridBagLayout;
6
import java.awt.Insets;
8
import java.awt.Insets;
7
import java.awt.event.ActionEvent;
9
import java.awt.event.ActionEvent;
8
import java.awt.event.ActionListener;
10
import java.awt.event.ActionListener;
9
import java.awt.event.MouseAdapter;
11
import java.awt.event.MouseAdapter;
10
import java.awt.event.MouseEvent;
12
import java.awt.event.MouseEvent;
-
 
13
import java.io.File;
-
 
14
import java.io.FileWriter;
-
 
15
import java.io.IOException;
11
 
16
 
-
 
17
import javax.swing.JButton;
-
 
18
import javax.swing.JFileChooser;
12
import javax.swing.JLabel;
19
import javax.swing.JLabel;
13
import javax.swing.JMenuItem;
20
import javax.swing.JMenuItem;
14
import javax.swing.JPanel;
21
import javax.swing.JPanel;
15
import javax.swing.JPopupMenu;
22
import javax.swing.JPopupMenu;
16
import javax.swing.JSeparator;
23
import javax.swing.JSeparator;
17
import javax.swing.JSplitPane;
24
import javax.swing.JSplitPane;
18
import javax.swing.JTabbedPane;
25
import javax.swing.JTabbedPane;
19
 
26
 
-
 
27
import org.jopendocument.panel.Messages;
20
import org.olap4j.OlapConnection;
28
import org.olap4j.OlapConnection;
21
import org.olap4j.metadata.Schema;
29
import org.olap4j.metadata.Schema;
-
 
30
import org.openconcerto.modules.reports.olap.renderer.Matrix;
22
import org.openconcerto.ui.JLabelBold;
31
import org.openconcerto.ui.JLabelBold;
-
 
32
import org.openconcerto.utils.ExceptionHandler;
-
 
33
import org.openconcerto.utils.text.CSVWriter;
23
 
34
 
24
public class OLAPMainPanel extends JPanel {
35
public class OLAPMainPanel extends JPanel {
25
    OLAPMainPanel(OlapConnection oConnection, Schema schema, final OLAPPanel olapPanel) {
36
    OLAPMainPanel(OlapConnection oConnection, Schema schema, final OLAPPanel olapPanel) {
26
        this.setLayout(new GridBagLayout());
37
        this.setLayout(new GridBagLayout());
27
        this.setOpaque(false);
38
        this.setOpaque(false);
Line 30... Line 41...
30
        JLabel label = new JLabel("Sélectionnez au minimum une colonne et une ligne pour visualiser l'hypercube.");
41
        JLabel label = new JLabel("Sélectionnez au minimum une colonne et une ligne pour visualiser l'hypercube.");
31
        c.gridx = 0;
42
        c.gridx = 0;
32
        c.gridy = 0;
43
        c.gridy = 0;
33
        c.fill = GridBagConstraints.HORIZONTAL;
44
        c.fill = GridBagConstraints.HORIZONTAL;
34
        final JLabelBold title = new JLabelBold("Analyse multidimensionnelle des données");
45
        final JLabelBold title = new JLabelBold("Analyse multidimensionnelle des données");
-
 
46
        title.setToolTipText(olapPanel.getLoadInfo());
35
        this.addMouseListener(new MouseAdapter() {
47
        this.addMouseListener(new MouseAdapter() {
36
            @Override
48
            @Override
37
            public void mouseReleased(MouseEvent e) {
49
            public void mouseReleased(MouseEvent e) {
38
 
50
 
39
                final JPopupMenu menu = new JPopupMenu();
51
                final JPopupMenu menu = new JPopupMenu();
Line 62... Line 74...
62
        c.insets = new Insets(0, 0, 0, 0);
74
        c.insets = new Insets(0, 0, 0, 0);
63
        c.fill = GridBagConstraints.BOTH;
75
        c.fill = GridBagConstraints.BOTH;
64
        JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
76
        JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
65
        split.setBorder(null);
77
        split.setBorder(null);
66
        final OLAPParametersPanel parameters = new OLAPParametersPanel(schema);
78
        final OLAPParametersPanel parameters = new OLAPParametersPanel(schema);
-
 
79
        parameters.setMinimumSize(new Dimension(200, 200));
67
        parameters.setOpaque(false);
80
        parameters.setOpaque(false);
68
        split.setLeftComponent(parameters);
81
        split.setLeftComponent(parameters);
-
 
82
        split.setDividerLocation(200);
69
        split.setOpaque(true);
83
        split.setOpaque(true);
70
 
84
 
71
        JPanel rightPanel = new JPanel();
85
        JPanel rightPanel = new JPanel();
72
        rightPanel.setOpaque(false);
86
        rightPanel.setOpaque(false);
73
        rightPanel.setLayout(new BorderLayout());
87
        rightPanel.setLayout(new BorderLayout());
74
 
88
 
75
        final OLAPRenderer renderer = new OLAPRenderer();
89
        final OLAPRenderer renderer = new OLAPRenderer();
76
 
90
 
77
        final OLAPMDXPanel mdxPanel = new OLAPMDXPanel(parameters, oConnection, renderer);
91
        final OLAPMDXPanel mdxPanel = new OLAPMDXPanel(parameters, oConnection, renderer);
-
 
92
 
-
 
93
        final OLAPSQLPanel sqlPanel = new OLAPSQLPanel(renderer);
-
 
94
 
78
        final OLAPConfigurationPanel confPanel = new OLAPConfigurationPanel(parameters, oConnection, renderer, mdxPanel);
95
        final OLAPConfigurationPanel confPanel = new OLAPConfigurationPanel(parameters, oConnection, renderer, mdxPanel);
79
        parameters.setConfigurationPanel(confPanel);
96
        parameters.setConfigurationPanel(confPanel);
80
        JTabbedPane t = new JTabbedPane();
97
        JTabbedPane t = new JTabbedPane();
81
        t.add("Mode simplifié", confPanel);
98
        t.add("Mode simplifié", confPanel);
82
        t.add("Requête MDX", mdxPanel);
99
        t.add("Requête MDX", mdxPanel);
83
 
-
 
-
 
100
        t.add("Requête SQL", sqlPanel);
84
        renderer.setOpaque(false);
101
        renderer.setOpaque(false);
85
        t.setOpaque(false);
102
        t.setOpaque(false);
-
 
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
        //
86
        rightPanel.add(t, BorderLayout.NORTH);
148
        rightPanel.add(t, BorderLayout.NORTH);
87
        rightPanel.add(renderer, BorderLayout.CENTER);
149
        rightPanel.add(renderer, BorderLayout.CENTER);
-
 
150
        rightPanel.add(p, BorderLayout.SOUTH);
88
        split.setRightComponent(rightPanel);
151
        split.setRightComponent(rightPanel);
89
        c.weightx = 1;
152
        c.weightx = 1;
90
        c.weighty = 1;
153
        c.weighty = 1;
91
        split.setDividerLocation(0.33D);
154
        split.setDividerLocation(0.33D);
92
        this.add(split, c);
155
        this.add(split, c);