Source Code Cross Referenced for OlapBrowser.java in  » Report » iReport-2.0.5 » it » businesslogic » ireport » data » olap » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Report » iReport 2.0.5 » it.businesslogic.ireport.data.olap 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 2005 - 2008 JasperSoft Corporation.  All rights reserved. 
003:         * http://www.jaspersoft.com.
004:         *
005:         * Unless you have purchased a commercial license agreement from JasperSoft,
006:         * the following license terms apply:
007:         *
008:         * This program is free software; you can redistribute it and/or modify
009:         * it under the terms of the GNU General Public License version 2 as published by
010:         * the Free Software Foundation.
011:         *
012:         * This program is distributed WITHOUT ANY WARRANTY; and without the
013:         * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014:         * See the GNU General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU General Public License
017:         * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018:         * or write to:
019:         *
020:         * Free Software Foundation, Inc.,
021:         * 59 Temple Place - Suite 330,
022:         * Boston, MA  USA  02111-1307
023:         *
024:         *
025:         *
026:         *
027:         * OlapBrowser.java
028:         * 
029:         * Created on June 20, 2006, 4:36 PM
030:         *
031:         */
032:
033:        package it.businesslogic.ireport.data.olap;
034:
035:        import it.businesslogic.ireport.FieldsProviderEditor;
036:        import it.businesslogic.ireport.JRField;
037:        import it.businesslogic.ireport.gui.MainFrame;
038:        import it.businesslogic.ireport.gui.ReportQueryDialog;
039:        import it.businesslogic.ireport.gui.sheet.Tag;
040:        import java.io.StringReader;
041:        import java.util.Vector;
042:        import javax.swing.JOptionPane;
043:        import javax.swing.JTable;
044:        import javax.swing.SwingUtilities;
045:        import javax.swing.table.DefaultTableModel;
046:        import javax.swing.tree.DefaultMutableTreeNode;
047:        import javax.swing.tree.DefaultTreeModel;
048:        import javax.swing.tree.DefaultTreeSelectionModel;
049:        import javax.swing.tree.TreePath;
050:        import mondrian.olap.*;
051:
052:        import net.sf.jasperreports.olap.mapping.MappingLexer;
053:        import net.sf.jasperreports.olap.mapping.MappingParser;
054:        import it.businesslogic.ireport.util.I18n;
055:        import java.util.List;
056:        import mondrian.mdx.ResolvedFunCall;
057:
058:        /**
059:         *
060:         * @author  gtoffoli
061:         */
062:        public class OlapBrowser extends javax.swing.JPanel implements 
063:                FieldsProviderEditor {
064:
065:            private JTable jTableFields = null;
066:            private ReportQueryDialog reportQueryDialog = null;
067:
068:            /** Creates new form OlapBrowser */
069:            public OlapBrowser() {
070:                initComponents();
071:
072:                DefaultMutableTreeNode root = new DefaultMutableTreeNode();
073:                jTree1.setModel(new DefaultTreeModel(root));
074:                jTree1.setCellRenderer(new OlapTreeCellRenderer());
075:
076:                jComboBoxType.addItem(new Tag("java.lang.String", I18n
077:                        .getString("mdx.type.Text", "Text")));
078:                jComboBoxType.addItem(new Tag("java.lang.Number", I18n
079:                        .getString("mdx.type.Numeric", "Numeric")));
080:                jComboBoxType.addItem(new Tag("java.util.Date", I18n.getString(
081:                        "mdx.type.Date", "Date")));
082:                jComboBoxType.addItem(new Tag("java.util.Date", I18n.getString(
083:                        "mdx.type.Boolean", "Boolean")));
084:
085:                jComboBoxType.setSelectedIndex(0);
086:
087:                applyI18n();
088:
089:                ((DefaultTreeSelectionModel) jTree1.getSelectionModel())
090:                        .setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION);
091:            }
092:
093:            public void setOlapQuery(Query query) {
094:
095:                DefaultTreeModel dtm = (DefaultTreeModel) jTree1.getModel();
096:                DefaultMutableTreeNode root = (DefaultMutableTreeNode) dtm
097:                        .getRoot();
098:                root.removeAllChildren();
099:
100:                if (query == null) {
101:                    jTree1.updateUI();
102:                    return;
103:                }
104:
105:                QueryAxis[] axes = query.getAxes();
106:
107:                Hierarchy[][] queryHierarchies = new Hierarchy[axes.length][];
108:                int[][] fieldsMaxDepths = new int[axes.length][];
109:                int[][] maxDepths = new int[axes.length][];
110:
111:                int hCount = 0;
112:                for (int i = 0; i < axes.length; i++) {
113:                    queryHierarchies[i] = query
114:                            .getMdxHierarchiesOnAxis(AxisOrdinal
115:                                    .forLogicalOrdinal(i));
116:
117:                    DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(
118:                            new WalkableWrapper(axes[i], root));
119:
120:                    if (queryHierarchies[i].length == 1
121:                            && queryHierarchies[i][0].getDimension()
122:                                    .isMeasures()) {
123:                        addChildren(childNode, axes[i].getChildren());
124:                    } else {
125:                        addChildren(childNode, queryHierarchies[i]);
126:                    }
127:
128:                    root.add(childNode);
129:
130:                    hCount += queryHierarchies[i].length;
131:                    fieldsMaxDepths[i] = new int[queryHierarchies[i].length];
132:                    maxDepths[i] = new int[queryHierarchies[i].length];
133:                }
134:
135:                jTree1.updateUI();
136:            }
137:
138:            public void setOlapResult2(Result result) {
139:                DefaultTreeModel dtm = (DefaultTreeModel) jTree1.getModel();
140:                DefaultMutableTreeNode root = (DefaultMutableTreeNode) dtm
141:                        .getRoot();
142:                root.removeAllChildren();
143:
144:                if (result == null) {
145:                    jTree1.updateUI();
146:                    return;
147:                }
148:
149:                // Main axes...
150:
151:                QueryAxis[] axis = result.getQuery().getAxes();
152:                Axis[] raxis = result.getAxes();
153:
154:                for (int i = 0; i < axis.length; ++i) {
155:                    DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(
156:                            new WalkableWrapper(axis[i], root));
157:                    addChildren(childNode, axis[i].getChildren());
158:                    root.add(childNode);
159:                }
160:
161:                jTree1.updateUI();
162:            }
163:
164:            public void setOlapResultDataXXX(Result result) {
165:                DefaultTreeModel dtm = (DefaultTreeModel) jTree1.getModel();
166:                DefaultMutableTreeNode root = (DefaultMutableTreeNode) dtm
167:                        .getRoot();
168:                root.removeAllChildren();
169:
170:                if (result == null) {
171:                    jTree1.updateUI();
172:                    return;
173:                }
174:
175:                // Main axes...
176:
177:                QueryAxis[] axis = result.getQuery().getAxes();
178:                Axis[] raxis = result.getAxes();
179:
180:                for (int i = 0; i < axis.length; ++i) {
181:                    DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(
182:                            new WalkableWrapper(axis[i], root));
183:                    Object[] positions = raxis[i].getPositions().toArray();
184:                    addChildren(childNode, positions);
185:                    root.add(childNode);
186:                }
187:
188:                jTree1.updateUI();
189:            }
190:
191:            String r_level = "";
192:
193:            public void addChildren(DefaultMutableTreeNode node,
194:                    Object[] children) {
195:
196:                if (children == null)
197:                    return;
198:
199:                r_level = r_level + "__";
200:                for (int i = 0; i < children.length; ++i) {
201:                    System.out.println(r_level
202:                            + children[i].getClass().getName() + " > "
203:                            + children[i] + " Parent: " + node);
204:
205:                    if (children[i] instanceof  mondrian.mdx.MemberExpr) {
206:
207:                        DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(
208:                                new WalkableWrapper(
209:                                        ((mondrian.mdx.MemberExpr) children[i])
210:                                                .getMember(), node));
211:                        node.add(childNode);
212:                        System.out.println("Adding MemberExpr: " + childNode);
213:                    } else if (children[i] instanceof  ResolvedFunCall) // FunCall interface no longes has the method getChildren...
214:                    {
215:                        addChildren(node, ((ResolvedFunCall) children[i])
216:                                .getChildren());
217:                    } else if (children[i] instanceof  QueryPart) {
218:                        addChildren(node, ((QueryPart) children[i])
219:                                .getChildren());
220:                    } else if (children[i] instanceof  QueryPart) {
221:                        addChildren(node, ((QueryPart) children[i])
222:                                .getChildren());
223:                    } else if (children[i] instanceof  Hierarchy) {
224:                        DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(
225:                                new WalkableWrapper(children[i], node));
226:                        addChildren(childNode, ((Hierarchy) children[i])
227:                                .getLevels());
228:                        node.add(childNode);
229:                    } else if (children[i] instanceof  Level) {
230:                        DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(
231:                                new WalkableWrapper(children[i], node));
232:                        node.add(childNode);
233:                    }
234:                    //else
235:                    /*
236:                    if (children[i] instanceof Position) 
237:                    {
238:                        DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(new WalkableWrapper(children[i], node));
239:                        if (children[i] instanceof Position)
240:                        {
241:                            addChildren(childNode, ((Position)children[i]).getMembers());
242:                        }
243:                        else if (children[i] instanceof Hierarchy)
244:                        {
245:                            addChildren(childNode, ((Hierarchy)children[i]).getLevels());
246:                        }
247:                        
248:                        node.add(childNode );
249:                    }
250:                    
251:                    if (children[i] instanceof Member)
252:                    {
253:                        addChildren(childNode, ((Member)children[i]).getChildren());
254:                    }
255:                     */
256:
257:                }
258:
259:                r_level = r_level.substring(0, r_level.length() - 2);
260:            }
261:
262:            public JTable getJTableFields() {
263:                return jTableFields;
264:            }
265:
266:            public void setJTableFields(JTable jTableFields) {
267:                this .jTableFields = jTableFields;
268:            }
269:
270:            /** This method is called from within the constructor to
271:             * initialize the form.
272:             * WARNING: Do NOT modify this code. The content of this method is
273:             * always regenerated by the Form Editor.
274:             */
275:            // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
276:            private void initComponents() {
277:                java.awt.GridBagConstraints gridBagConstraints;
278:
279:                jScrollPane1 = new javax.swing.JScrollPane();
280:                jTree1 = new javax.swing.JTree();
281:                jLabel4 = new javax.swing.JLabel();
282:                jPanel1 = new javax.swing.JPanel();
283:                jLabel1 = new javax.swing.JLabel();
284:                jTextFieldName = new javax.swing.JTextField();
285:                jLabel3 = new javax.swing.JLabel();
286:                jComboBoxType = new javax.swing.JComboBox();
287:                jLabel2 = new javax.swing.JLabel();
288:                jTextFieldExpression = new javax.swing.JTextField();
289:                jPanel2 = new javax.swing.JPanel();
290:                jButton2 = new javax.swing.JButton();
291:                jButton1 = new javax.swing.JButton();
292:
293:                setLayout(new java.awt.GridBagLayout());
294:
295:                setMinimumSize(new java.awt.Dimension(250, 85));
296:                setPreferredSize(new java.awt.Dimension(405, 384));
297:                jScrollPane1.setPreferredSize(new java.awt.Dimension(400, 322));
298:                jTree1.setRootVisible(false);
299:                jTree1.addMouseListener(new java.awt.event.MouseAdapter() {
300:                    public void mouseClicked(java.awt.event.MouseEvent evt) {
301:                        jTree1MouseClicked(evt);
302:                    }
303:                });
304:
305:                jScrollPane1.setViewportView(jTree1);
306:
307:                gridBagConstraints = new java.awt.GridBagConstraints();
308:                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
309:                gridBagConstraints.weightx = 1.0;
310:                gridBagConstraints.weighty = 1.0;
311:                gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 4);
312:                add(jScrollPane1, gridBagConstraints);
313:
314:                jLabel4.setForeground(new java.awt.Color(0, 51, 255));
315:                jLabel4
316:                        .setText("Double click on a tree element the get it's expression");
317:                gridBagConstraints = new java.awt.GridBagConstraints();
318:                gridBagConstraints.gridx = 0;
319:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
320:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
321:                gridBagConstraints.weightx = 1.0;
322:                gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
323:                add(jLabel4, gridBagConstraints);
324:
325:                jPanel1.setLayout(new java.awt.GridBagLayout());
326:
327:                jLabel1.setText("Field name");
328:                gridBagConstraints = new java.awt.GridBagConstraints();
329:                gridBagConstraints.gridy = 0;
330:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
331:                gridBagConstraints.insets = new java.awt.Insets(4, 4, 0, 0);
332:                jPanel1.add(jLabel1, gridBagConstraints);
333:
334:                gridBagConstraints = new java.awt.GridBagConstraints();
335:                gridBagConstraints.gridy = 0;
336:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
337:                gridBagConstraints.weightx = 0.5;
338:                gridBagConstraints.insets = new java.awt.Insets(4, 4, 0, 0);
339:                jPanel1.add(jTextFieldName, gridBagConstraints);
340:
341:                jLabel3.setText("Type");
342:                gridBagConstraints = new java.awt.GridBagConstraints();
343:                gridBagConstraints.gridy = 0;
344:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
345:                gridBagConstraints.insets = new java.awt.Insets(4, 6, 0, 0);
346:                jPanel1.add(jLabel3, gridBagConstraints);
347:
348:                jComboBoxType.setMinimumSize(new java.awt.Dimension(30, 19));
349:                jComboBoxType.setPreferredSize(new java.awt.Dimension(50, 19));
350:                gridBagConstraints = new java.awt.GridBagConstraints();
351:                gridBagConstraints.gridy = 0;
352:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
353:                gridBagConstraints.weightx = 0.3;
354:                gridBagConstraints.insets = new java.awt.Insets(4, 2, 0, 4);
355:                jPanel1.add(jComboBoxType, gridBagConstraints);
356:
357:                jLabel2.setText("Expression");
358:                gridBagConstraints = new java.awt.GridBagConstraints();
359:                gridBagConstraints.gridy = 1;
360:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
361:                gridBagConstraints.insets = new java.awt.Insets(4, 4, 0, 0);
362:                jPanel1.add(jLabel2, gridBagConstraints);
363:
364:                gridBagConstraints = new java.awt.GridBagConstraints();
365:                gridBagConstraints.gridy = 1;
366:                gridBagConstraints.gridwidth = 3;
367:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
368:                gridBagConstraints.weightx = 1.0;
369:                gridBagConstraints.insets = new java.awt.Insets(4, 4, 0, 4);
370:                jPanel1.add(jTextFieldExpression, gridBagConstraints);
371:
372:                jPanel2.setLayout(new java.awt.GridBagLayout());
373:
374:                jButton2.setText("Clear");
375:                jButton2.addActionListener(new java.awt.event.ActionListener() {
376:                    public void actionPerformed(java.awt.event.ActionEvent evt) {
377:                        jButton2ActionPerformed(evt);
378:                    }
379:                });
380:
381:                gridBagConstraints = new java.awt.GridBagConstraints();
382:                gridBagConstraints.gridy = 5;
383:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
384:                gridBagConstraints.weightx = 1.0;
385:                gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 4);
386:                jPanel2.add(jButton2, gridBagConstraints);
387:
388:                jButton1.setText("Add field");
389:                jButton1.addActionListener(new java.awt.event.ActionListener() {
390:                    public void actionPerformed(java.awt.event.ActionEvent evt) {
391:                        jButton1ActionPerformed(evt);
392:                    }
393:                });
394:
395:                gridBagConstraints = new java.awt.GridBagConstraints();
396:                gridBagConstraints.gridy = 5;
397:                gridBagConstraints.gridwidth = 2;
398:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
399:                gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 4);
400:                jPanel2.add(jButton1, gridBagConstraints);
401:
402:                gridBagConstraints = new java.awt.GridBagConstraints();
403:                gridBagConstraints.gridx = 0;
404:                gridBagConstraints.gridwidth = 5;
405:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
406:                gridBagConstraints.weightx = 1.0;
407:                jPanel1.add(jPanel2, gridBagConstraints);
408:
409:                gridBagConstraints = new java.awt.GridBagConstraints();
410:                gridBagConstraints.gridx = 0;
411:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
412:                gridBagConstraints.weightx = 1.0;
413:                add(jPanel1, gridBagConstraints);
414:
415:            }// </editor-fold>//GEN-END:initComponents
416:
417:            private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
418:
419:                jTextFieldName.setText("");
420:                jComboBoxType.setSelectedIndex(0);
421:                jTextFieldExpression.setText("");
422:
423:            }//GEN-LAST:event_jButton2ActionPerformed
424:
425:            private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
426:
427:                if (jTextFieldName.getText().length() == 0) {
428:                    JOptionPane.showMessageDialog(this , I18n.getString(
429:                            "message.olapBrowser.notValidFieldName",
430:                            "Field name not valid"), I18n.getString(
431:                            "message.title.error", "Error"),
432:                            JOptionPane.ERROR_MESSAGE);
433:                    return;
434:
435:                }
436:                if (jTextFieldExpression.getText().length() == 0) {
437:                    JOptionPane.showMessageDialog(this , I18n.getString(
438:                            "message.olapBrowser.notValidFieldExpression",
439:                            "Field expression not valid"), I18n.getString(
440:                            "message.title.error", "Error"),
441:                            JOptionPane.ERROR_MESSAGE);
442:                    return;
443:                }
444:
445:                JRField field = new JRField(jTextFieldName.getText().trim(), ""
446:                        + ((Tag) jComboBoxType.getSelectedItem()).getValue());
447:                field.setDescription(jTextFieldExpression.getText());
448:
449:                /*  
450:                 try
451:                 {
452:                         MappingLexer lexer = new MappingLexer(new StringReader(jTextFieldExpression.getText()));
453:                         
454:                         //MappingParser parser = new MappingParser(lexer);
455:                         //parser.setMappingMetadata(this);
456:                         parser.mapping();
457:                 }
458:                 catch (Exception e)
459:                 {
460:                     JOptionPane.showMessageDialog(this,"Field expression not valid:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
461:                     return;
462:                 }
463:                 */
464:
465:                if (fieldAlreadyExists(field)) {
466:                    JOptionPane.showMessageDialog(this , I18n.getString(
467:                            "message.olapBrowser.fieldDuplicated",
468:                            "A field with this name is already present"), I18n
469:                            .getString("message.title.error", "Error"),
470:                            JOptionPane.ERROR_MESSAGE);
471:                    return;
472:                }
473:
474:                Vector row = new Vector();
475:                row.addElement(field);
476:                row.addElement(field.getClassType());
477:                row.addElement(field.getDescription());
478:
479:                DefaultTableModel dtm = (DefaultTableModel) getJTableFields()
480:                        .getModel();
481:                dtm.addRow(row);
482:                getJTableFields().getSelectionModel().addSelectionInterval(
483:                        getJTableFields().getRowCount() - 1,
484:                        getJTableFields().getRowCount() - 1);
485:
486:            }//GEN-LAST:event_jButton1ActionPerformed
487:
488:            private void jTree1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTree1MouseClicked
489:
490:                if (evt.getClickCount() == 2 && evt.getButton() == evt.BUTTON1) {
491:                    TreePath tp = jTree1.getSelectionPath();
492:                    if (tp != null) {
493:                        WalkableWrapper ww = (WalkableWrapper) ((DefaultMutableTreeNode) tp
494:                                .getLastPathComponent()).getUserObject();
495:
496:                        String exp = ww.getExpression();
497:                        if (exp != null) {
498:                            if (ww.isMeasure()) {
499:                                jTextFieldName.setText(ww + "");
500:                                jTextFieldExpression.setText(exp);
501:                            } else {
502:                                String newexp = jTextFieldExpression.getText();
503:                                int ss = (jTextFieldExpression
504:                                        .getSelectionStart() >= 0) ? jTextFieldExpression
505:                                        .getSelectionStart()
506:                                        : jTextFieldExpression
507:                                                .getCaretPosition();
508:                                int se = (jTextFieldExpression
509:                                        .getSelectionEnd() >= 0) ? jTextFieldExpression
510:                                        .getSelectionEnd()
511:                                        : jTextFieldExpression
512:                                                .getCaretPosition();
513:                                newexp = newexp.substring(0, ss) + exp
514:                                        + newexp.substring(se);
515:                                jTextFieldExpression.setText(newexp);
516:                                jTextFieldExpression.requestFocusInWindow();
517:                            }
518:                        }
519:                    }
520:
521:                }
522:            }//GEN-LAST:event_jTree1MouseClicked
523:
524:            private boolean fieldAlreadyExists(JRField field) {
525:                boolean found = false;
526:                for (int j = 0; j < getJTableFields().getRowCount(); ++j) {
527:                    Object ff = getJTableFields().getValueAt(j, 0);
528:                    if (ff instanceof  it.businesslogic.ireport.JRField) {
529:                        if (((it.businesslogic.ireport.JRField) ff).getName()
530:                                .equals(field.getName())) {
531:                            found = true;
532:                            break;
533:                        }
534:                    }
535:                }
536:
537:                return found;
538:            }
539:
540:            // Variables declaration - do not modify//GEN-BEGIN:variables
541:            private javax.swing.JButton jButton1;
542:            private javax.swing.JButton jButton2;
543:            private javax.swing.JComboBox jComboBoxType;
544:            private javax.swing.JLabel jLabel1;
545:            private javax.swing.JLabel jLabel2;
546:            private javax.swing.JLabel jLabel3;
547:            private javax.swing.JLabel jLabel4;
548:            private javax.swing.JPanel jPanel1;
549:            private javax.swing.JPanel jPanel2;
550:            private javax.swing.JScrollPane jScrollPane1;
551:            private javax.swing.JTextField jTextFieldExpression;
552:            private javax.swing.JTextField jTextFieldName;
553:            private javax.swing.JTree jTree1;
554:
555:            // End of variables declaration//GEN-END:variables
556:
557:            public void applyI18n() {
558:                // Start autogenerated code ----------------------
559:                jButton1.setText(I18n.getString("olapBrowser.button1",
560:                        "Add field"));
561:                jButton2
562:                        .setText(I18n.getString("olapBrowser.button2", "Clear"));
563:                jLabel1.setText(I18n.getString("olapBrowser.label1",
564:                        "Field name"));
565:                jLabel2.setText(I18n.getString("olapBrowser.label2",
566:                        "Expression"));
567:                jLabel3.setText(I18n.getString("olapBrowser.label3", "Type"));
568:                jLabel4
569:                        .setText(I18n
570:                                .getString("olapBrowser.label4",
571:                                        "Double click on a tree element the get it's expression"));
572:                // End autogenerated code ----------------------
573:            }
574:
575:            int lastExecution = 0;
576:
577:            public void queryChanged(String newQuery) {
578:
579:                lastExecution++;
580:                int this Execution = lastExecution;
581:                // Execute a thread to perform the query change...
582:
583:                String error_msg = "";
584:                lastExecution++;
585:
586:                int in = lastExecution;
587:
588:                getReportQueryDialog().getJLabelStatusSQL().setText(
589:                        "Executing MDX query....");
590:                /////////////////////////////
591:
592:                try {
593:                    Thread.currentThread().setContextClassLoader(
594:                            MainFrame.getMainInstance().getReportClassLoader());
595:                } catch (Exception ex) {
596:                    ex.printStackTrace();
597:                }
598:
599:                if (in < lastExecution)
600:                    return; //Abort, new execution requested
601:
602:                OLAPQueryExecuter olapQE = new OLAPQueryExecuter(newQuery,
603:                        getReportQueryDialog().getSubDataset().getParameters());
604:
605:                String lastError = "";
606:                try {
607:
608:                    //final mondrian.olap.Result result = olapQE.executeOlapQuery();
609:                    final mondrian.olap.Query query = olapQE.createOlapQuery();
610:
611:                    if (in < lastExecution)
612:                        return; //Abort, new execution requested
613:                    SwingUtilities.invokeAndWait(new Runnable() {
614:                        public void run() {
615:                            setOlapQuery(query);
616:                        }
617:                    });
618:
619:                } catch (Exception ex) {
620:                    ex.printStackTrace();
621:                    setOlapQuery(null);
622:                    lastError = " (Last error was " + ex.getMessage() + ")";
623:                }
624:
625:                getReportQueryDialog().getJLabelStatusSQL().setText("Ready");
626:            }
627:
628:            public ReportQueryDialog getReportQueryDialog() {
629:                return reportQueryDialog;
630:            }
631:
632:            public void setReportQueryDialog(ReportQueryDialog reportQueryDialog) {
633:                this.reportQueryDialog = reportQueryDialog;
634:            }
635:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.