Source Code Cross Referenced for ReportWizard.java in  » Report » pentaho-report » org » pentaho » jfreereport » wizard » 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 » pentaho report » org.pentaho.jfreereport.wizard 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * Copyright 2006 Pentaho Corporation.  All rights reserved. 
0003:         * This software was developed by Pentaho Corporation and is provided under the terms 
0004:         * of the Mozilla Public License, Version 1.1, or any later version. You may not use 
0005:         * this file except in compliance with the license. If you need a copy of the license, 
0006:         * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho 
0007:         * BI Platform.  The Initial Developer is Pentaho Corporation.
0008:         *
0009:         * Software distributed under the Mozilla Public License is distributed on an "AS IS" 
0010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or  implied. Please refer to 
0011:         * the license for the specific language governing your rights and limitations.
0012:         *
0013:         * @created Feb 01, 2006
0014:         * @author Michael D'Amour
0015:         */
0016:        package org.pentaho.jfreereport.wizard;
0017:
0018:        import java.io.BufferedInputStream;
0019:        import java.io.BufferedOutputStream;
0020:        import java.io.ByteArrayOutputStream;
0021:        import java.io.File;
0022:        import java.io.FileInputStream;
0023:        import java.io.FileOutputStream;
0024:        import java.io.InputStream;
0025:        import java.math.BigDecimal;
0026:        import java.net.URL;
0027:        import java.sql.Date;
0028:        import java.sql.Timestamp;
0029:        import java.sql.Types;
0030:        import java.util.ArrayList;
0031:        import java.util.Enumeration;
0032:        import java.util.HashMap;
0033:        import java.util.Iterator;
0034:        import java.util.LinkedList;
0035:        import java.util.List;
0036:        import java.util.Properties;
0037:        import java.util.Random;
0038:        import java.util.zip.ZipEntry;
0039:        import java.util.zip.ZipFile;
0040:        import java.util.zip.ZipOutputStream;
0041:
0042:        import javax.swing.JOptionPane;
0043:
0044:        import org.apache.commons.io.IOUtils;
0045:        import org.apache.commons.lang.StringUtils;
0046:        import org.dom4j.Element;
0047:        import org.dom4j.Node;
0048:        import org.eclipse.swt.SWT;
0049:        import org.eclipse.swt.SWTError;
0050:        import org.eclipse.swt.SWTException;
0051:        import org.eclipse.swt.browser.Browser;
0052:        import org.eclipse.swt.custom.BusyIndicator;
0053:        import org.eclipse.swt.custom.StackLayout;
0054:        import org.eclipse.swt.events.MouseAdapter;
0055:        import org.eclipse.swt.events.MouseEvent;
0056:        import org.eclipse.swt.events.PaintEvent;
0057:        import org.eclipse.swt.events.PaintListener;
0058:        import org.eclipse.swt.events.SelectionAdapter;
0059:        import org.eclipse.swt.events.SelectionEvent;
0060:        import org.eclipse.swt.graphics.Color;
0061:        import org.eclipse.swt.graphics.Cursor;
0062:        import org.eclipse.swt.graphics.Font;
0063:        import org.eclipse.swt.graphics.GC;
0064:        import org.eclipse.swt.graphics.Image;
0065:        import org.eclipse.swt.layout.FillLayout;
0066:        import org.eclipse.swt.layout.GridData;
0067:        import org.eclipse.swt.layout.GridLayout;
0068:        import org.eclipse.swt.widgets.Composite;
0069:        import org.eclipse.swt.widgets.Display;
0070:        import org.eclipse.swt.widgets.Event;
0071:        import org.eclipse.swt.widgets.FileDialog;
0072:        import org.eclipse.swt.widgets.Label;
0073:        import org.eclipse.swt.widgets.Listener;
0074:        import org.eclipse.swt.widgets.Menu;
0075:        import org.eclipse.swt.widgets.MenuItem;
0076:        import org.eclipse.swt.widgets.MessageBox;
0077:        import org.eclipse.swt.widgets.Shell;
0078:        import org.jfree.report.JFreeReportBoot;
0079:        import org.pentaho.commons.mql.ui.mqldesigner.CWMStartup;
0080:        import org.pentaho.core.admin.datasources.DataSourceInfo;
0081:        import org.pentaho.core.admin.datasources.StandaloneSimpleJNDIDatasourceAdmin;
0082:        import org.pentaho.core.admin.datasources.jboss.JBossDatasourceAdmin;
0083:        import org.pentaho.core.connection.DataUtilities;
0084:        import org.pentaho.core.connection.IPentahoConnection;
0085:        import org.pentaho.core.connection.IPentahoResultSet;
0086:        import org.pentaho.core.repository.ISolutionRepository;
0087:        import org.pentaho.core.runtime.IRuntimeContext;
0088:        import org.pentaho.core.session.StandaloneSession;
0089:        import org.pentaho.core.solution.IActionCompleteListener;
0090:        import org.pentaho.core.util.PublisherUtil;
0091:        import org.pentaho.data.connection.mdx.MDXMetaData;
0092:        import org.pentaho.jfreereport.castormodel.reportspec.Field;
0093:        import org.pentaho.jfreereport.castormodel.reportspec.FieldMapping;
0094:        import org.pentaho.jfreereport.castormodel.reportspec.ReportSpec;
0095:        import org.pentaho.jfreereport.castormodel.reportspec.ReportSpecChoice;
0096:        import org.pentaho.jfreereport.castormodel.reportspec.Watermark;
0097:        import org.pentaho.jfreereport.wizard.messages.Messages;
0098:        import org.pentaho.jfreereport.wizard.ui.IDirtyListener;
0099:        import org.pentaho.jfreereport.wizard.ui.IWizardListener;
0100:        import org.pentaho.jfreereport.wizard.ui.NavigationPanel;
0101:        import org.pentaho.jfreereport.wizard.ui.WizardPanel;
0102:        import org.pentaho.jfreereport.wizard.ui.dialog.PentahoSWTMessageBox;
0103:        import org.pentaho.jfreereport.wizard.ui.dialog.PublishDialog;
0104:        import org.pentaho.jfreereport.wizard.ui.step.FieldSetupPanel;
0105:        import org.pentaho.jfreereport.wizard.ui.step.GroupAndDetailPanel;
0106:        import org.pentaho.jfreereport.wizard.ui.step.QueryPanel;
0107:        import org.pentaho.jfreereport.wizard.ui.step.ReportDefinitionPanel;
0108:        import org.pentaho.jfreereport.wizard.utility.ActionSequenceUtility;
0109:        import org.pentaho.jfreereport.wizard.utility.CastorUtility;
0110:        import org.pentaho.jfreereport.wizard.utility.PentahoUtility;
0111:        import org.pentaho.jfreereport.wizard.utility.SWTUtility;
0112:        import org.pentaho.jfreereport.wizard.utility.TinyHTTPd;
0113:        import org.pentaho.jfreereport.wizard.utility.connection.ConnectionUtility;
0114:        import org.pentaho.jfreereport.wizard.utility.report.ReportGenerationUtility;
0115:        import org.pentaho.jfreereport.wizard.utility.report.ReportSpecUtility;
0116:        import org.pentaho.util.VersionHelper;
0117:        import org.pentaho.util.VersionInfo;
0118:        import org.pentaho.util.logging.ILogger;
0119:
0120:        public class ReportWizard implements  IActionCompleteListener,
0121:                IWizardListener, IDirtyListener {
0122:            public static final String PREVIEW_TYPE_PDF = "pdf"; //$NON-NLS-1$
0123:
0124:            public static final String PREVIEW_TYPE_HTML = "html"; //$NON-NLS-1$
0125:
0126:            public static final String PREVIEW_TYPE_XLS = "xls"; //$NON-NLS-1$
0127:
0128:            public static final int TAB_TEMPLATE = 0;
0129:
0130:            public static final int TAB_QUERY = 1;
0131:
0132:            public static final int TAB_LAYOUT = 2;
0133:
0134:            public static final int TAB_FORMAT = 3;
0135:
0136:            public static final int TAB_PAGE = 4;
0137:
0138:            public static final int TAB_REPORT = 5;
0139:
0140:            public static int MODE_APPLICATION = 0;
0141:
0142:            public static int MODE_DIALOG = 1;
0143:
0144:            public static int MODE_EMBEDDED = 2;
0145:
0146:            public static int applicationMode = MODE_APPLICATION;
0147:
0148:            public static final Color background = new Color(Display
0149:                    .getDefault(), 0xf2, 0xf2, 0xf2);
0150:
0151:            public static StandaloneSimpleJNDIDatasourceAdmin dataSourceAdmin;
0152:
0153:            QueryPanel queryPanel = null;
0154:
0155:            GroupAndDetailPanel groupAndDetailPanel = null;
0156:
0157:            NavigationPanel navigationPanel = null;
0158:
0159:            FieldSetupPanel fieldSetupPanel = null;
0160:
0161:            // PageSetupPanel pageSetupPanel = null;
0162:
0163:            // ReportSetupPanel reportSetupPanel = null;
0164:
0165:            ReportDefinitionPanel templatePanel = null;
0166:
0167:            // MappingPanel mappingPanel = null;
0168:
0169:            Browser browser = null;
0170:
0171:            Display display = null;
0172:
0173:            Shell detachedPreviewShell;
0174:
0175:            StackLayout stackLayout;
0176:
0177:            int previousSelectedTabIndex;
0178:
0179:            int maxSelectedTabIndex = 2;
0180:
0181:            public WizardManager wizardManager = null;
0182:
0183:            IPentahoConnection pentahoConnection = null;
0184:
0185:            HashMap typeMap = new HashMap();
0186:
0187:            boolean ignoreWizardEvents = false;
0188:
0189:            public String reportSpecStartupFilePath = null;
0190:
0191:            public String reportSpecFilePath = null;
0192:
0193:            public String templateZipPath = null;
0194:
0195:            ReportSpec reportSpec = new ReportSpec();
0196:
0197:            Composite container = null;
0198:
0199:            Composite parentContainer = null;
0200:
0201:            StackLayout mainStack;
0202:
0203:            String previewType = "pdf"; //$NON-NLS-1$
0204:
0205:            public String defaultNumericFunction = "sum"; //$NON-NLS-1$
0206:
0207:            String exportPath = null;
0208:
0209:            Composite dialogBase;
0210:
0211:            Composite splashScreen;
0212:
0213:            Label splashLabel;
0214:
0215:            int currentTabIndex;
0216:
0217:            boolean handlingTab = false;
0218:
0219:            MenuItem saveItem = null;
0220:
0221:            boolean isSaved = false;
0222:
0223:            String startupQuery = null;
0224:
0225:            HashMap templateImageMap = new HashMap();
0226:
0227:            public static String simpleJNDIPath = "/system/simple-jndi/jdbc.properties"; //$NON-NLS-1$
0228:
0229:            public String jfreeReportOutputPath = "resources/solutions/samples/reporting/"; //$NON-NLS-1$
0230:
0231:            public String templatePath = "templates"; //$NON-NLS-1$
0232:
0233:            public String solutionRootPath = "resources/solutions"; //$NON-NLS-1$
0234:
0235:            public String rdwRoot = "/"; //$NON-NLS-1$
0236:            public String workingDir = "/"; //$NON-NLS-1$
0237:
0238:            protected Properties settings = new Properties();
0239:
0240:            String browseFolder = "./"; //$NON-NLS-1$
0241:
0242:            MenuItem htmlPreviewTypeMenuItem = null;
0243:
0244:            MenuItem pdfPreviewTypeMenuItem = null;
0245:
0246:            MenuItem xlsPreviewTypeMenuItem = null;
0247:
0248:            public boolean removeCrlfFromQuery = false;
0249:
0250:            public String lastCommand = null;
0251:            static {
0252:
0253:                String javaVersion = System.getProperty("java.version"); //$NON-NLS-1$
0254:                if (javaVersion.startsWith("1.0") || javaVersion.startsWith("1.1") || javaVersion.startsWith("1.2") || javaVersion.startsWith("1.3")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
0255:                    System.out.println(Messages.getString("ReportWizard.33")); //$NON-NLS-1$
0256:                    JOptionPane.showMessageDialog(null, Messages
0257:                            .getString("ReportWizard.34")); //$NON-NLS-1$
0258:                    System.exit(0);
0259:                }
0260:            }
0261:
0262:            public ReportWizard(String startupFile, String startupQuery,
0263:                    String rdwRoot, String browseFolder,
0264:                    Composite parentContainer, int appMode) {
0265:                this (startupFile, startupQuery, rdwRoot, rdwRoot, browseFolder,
0266:                        parentContainer, appMode);
0267:            }
0268:
0269:            public ReportWizard(final String startupFile,
0270:                    final String startupQuery, String rdwRoot,
0271:                    String workingDir, String browseFolder,
0272:                    Composite inParentContainer, int appMode) {
0273:
0274:                InputStream iconRes = ReportWizard.class.getClassLoader()
0275:                        .getResourceAsStream("pentaho_icon.ico"); //$NON-NLS-1$
0276:                Image icon = new Image(Display.getDefault(), iconRes);
0277:                SWTUtility.setIcon(icon);
0278:
0279:                ReportWizard.applicationMode = appMode;
0280:                if (inParentContainer == null) {
0281:                    if (appMode == MODE_APPLICATION) {
0282:                        inParentContainer = SWTUtility
0283:                                .createShell(
0284:                                        1024,
0285:                                        768,
0286:                                        new FillLayout(),
0287:                                        Messages
0288:                                                .getString("ReportWizard.USER_PRODUCT_TITLE"), SWT.SHELL_TRIM); //$NON-NLS-1$
0289:                    } else if (appMode == MODE_DIALOG
0290:                            || appMode == MODE_EMBEDDED) {
0291:                        inParentContainer = SWTUtility
0292:                                .createShell(
0293:                                        1024,
0294:                                        768,
0295:                                        new FillLayout(),
0296:                                        Messages
0297:                                                .getString("ReportWizard.USER_PRODUCT_TITLE"), SWT.DIALOG_TRIM); //$NON-NLS-1$
0298:                    }
0299:                }
0300:                this .rdwRoot = rdwRoot;
0301:                this .workingDir = workingDir;
0302:                // force driver load/discovery
0303:                ConnectionUtility.getDrivers(rdwRoot);
0304:
0305:                this .parentContainer = inParentContainer;
0306:
0307:                if (parentContainer instanceof  Shell) {
0308:                    ((Shell) parentContainer).open();
0309:                    final Cursor cursor = new Cursor(display,
0310:                            SWT.CURSOR_APPSTARTING);
0311:                    parentContainer.setCursor(cursor);
0312:                }
0313:
0314:                this .container = new Composite(parentContainer, SWT.NONE);
0315:                this .browseFolder = browseFolder;
0316:                loadSettings();
0317:
0318:                wizardManager = new WizardManager();
0319:                wizardManager.addWizardListener(this );
0320:                try {
0321:                    display = Display.getDefault();
0322:                } catch (Throwable t) {
0323:                    // TODO something nice here
0324:                    System.err
0325:                            .println(Messages
0326:                                    .getString("ReportWizard.ERROR_0001_COULD_NOT_CONFIGURE_GRAPHICS") + t.getMessage()); //$NON-NLS-1$
0327:                    return;
0328:                }
0329:                container.setBackground(background);
0330:                if (ReportWizard.applicationMode == ReportWizard.MODE_APPLICATION) {
0331:                    createMenuBar();
0332:                    setDefaultOutputTypeMenuItem();
0333:                }
0334:                mainStack = new StackLayout();
0335:                container.setLayout(mainStack);
0336:                dialogBase = new Composite(container, SWT.NONE);
0337:                dialogBase.setBackground(background);
0338:                dialogBase.setVisible(false);
0339:                createSplash(container);
0340:
0341:                mainStack.topControl = splashScreen;
0342:                splashScreen.setVisible(true);
0343:
0344:                GridLayout gridLayout = new GridLayout(1, false);
0345:                gridLayout.marginHeight = 0;
0346:                gridLayout.marginWidth = 0;
0347:                GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
0348:                dialogBase.setLayout(gridLayout);
0349:                dialogBase.setLayoutData(gridData);
0350:                navigationPanel = new NavigationPanel(dialogBase, SWT.NONE,
0351:                        this );
0352:                gridData = new GridData(SWT.FILL, SWT.TOP, true, false);
0353:                gridData.heightHint = 80;
0354:                navigationPanel.setLayoutData(gridData);
0355:                navigationPanel.setBackground(background);
0356:                Composite main = new Composite(dialogBase, SWT.NONE);
0357:                GridLayout mainGridLayout = new GridLayout();
0358:                mainGridLayout.numColumns = 2;
0359:                mainGridLayout.marginHeight = 0;
0360:                mainGridLayout.marginWidth = 0;
0361:                main.setLayout(mainGridLayout);
0362:                gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
0363:                main.setLayoutData(gridData);
0364:                main.setBackground(background);
0365:                Composite client = new Composite(main, SWT.NONE);
0366:                stackLayout = new StackLayout();
0367:                client.setLayout(stackLayout);
0368:                client.setBackground(background);
0369:                client.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
0370:                        true));
0371:                templatePanel = new ReportDefinitionPanel(client, SWT.NONE,
0372:                        wizardManager, this );
0373:                templatePanel.setBackground(background);
0374:                templatePanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
0375:                        true, true));
0376:                templatePanel.addDirtyListener(this );
0377:                wizardManager.addStep(templatePanel);
0378:                wizardManager.setCurrentStep(templatePanel);
0379:                queryPanel = new QueryPanel(client, SWT.NONE, wizardManager,
0380:                        this );
0381:                queryPanel.setBackground(background);
0382:                queryPanel.addDirtyListener(this );
0383:                wizardManager.addStep(queryPanel);
0384:                // mappingPanel = new MappingPanel(client, SWT.NONE, wizardManager, this);
0385:                // mappingPanel.setBackground(background);
0386:                // mappingPanel.addDirtyListener(this);
0387:                // wizardManager.addStep(mappingPanel);
0388:                groupAndDetailPanel = new GroupAndDetailPanel(client, SWT.FLAT,
0389:                        wizardManager, this );
0390:                groupAndDetailPanel.setBackground(background);
0391:                groupAndDetailPanel.addDirtyListener(this );
0392:                wizardManager.addStep(groupAndDetailPanel);
0393:                fieldSetupPanel = new FieldSetupPanel(client, SWT.FLAT,
0394:                        wizardManager, this );
0395:                fieldSetupPanel.setBackground(background);
0396:                fieldSetupPanel.addDirtyListener(this );
0397:                wizardManager.addStep(fieldSetupPanel);
0398:                // pageSetupPanel = new PageSetupPanel(client, SWT.FLAT, wizardManager, this);
0399:                // pageSetupPanel.setBackground(background);
0400:                // pageSetupPanel.addDirtyListener(this);
0401:                // wizardManager.addStep(pageSetupPanel);
0402:                // reportSetupPanel = new ReportSetupPanel(client, SWT.FLAT, wizardManager, this);
0403:                // reportSetupPanel.setBackground(background);
0404:                // reportSetupPanel.addDirtyListener(this);
0405:                // wizardManager.addStep(reportSetupPanel);
0406:
0407:                String browserErrorString = "";
0408:                try {
0409:                    browser = new Browser(client, SWT.BORDER | SWT.SHADOW_OUT);
0410:                } catch (SWTError e) {
0411:                    /*
0412:                     * The Browser widget throws an SWTError if it fails to instantiate properly. Application code should catch this SWTError and disable any feature requiring the Browser widget. Platform requirements for the SWT Browser widget are
0413:                     * available from the SWT FAQ website.
0414:                     */
0415:                    browserErrorString = e.getMessage();
0416:                }
0417:                String osName = System.getProperty("os.name").toLowerCase(); //$NON-NLS-1$
0418:                boolean isLinux = osName.indexOf("linux") >= 0; //$NON-NLS-1$ //$NON-NLS-2$
0419:                if (!isLinux && browser == null) {
0420:                    JOptionPane
0421:                            .showMessageDialog(
0422:                                    null,
0423:                                    "Preview not available due to SWT configuration.  Consult SWT documentation for more information.\n"
0424:                                            + browserErrorString);
0425:                }
0426:                queryPanel.setVisible(true);
0427:                Runnable r = new Runnable() {
0428:                    public void run() {
0429:                        init();
0430:                        JFreeReportBoot.getInstance().start();
0431:                        PentahoUtility.startup();
0432:                        StandaloneSession session = new StandaloneSession(
0433:                                "Datasource-Session"); //$NON-NLS-1$
0434:                        session.setLoggingLevel(ILogger.ERROR);
0435:                        dataSourceAdmin = new StandaloneSimpleJNDIDatasourceAdmin(
0436:                                ReportWizard.simpleJNDIPath, session);
0437:                        if (startupFile != null) {
0438:                            reportSpecFilePath = startupFile;
0439:                            reportSpecStartupFilePath = startupFile;
0440:                            doOpen(startupFile, true, true);
0441:                        } else {
0442:                            doNew(false, true);
0443:                        }
0444:                        splashScreen.setVisible(false);
0445:                        dialogBase.setVisible(true);
0446:                        mainStack.topControl = dialogBase;
0447:                        stackLayout.topControl = queryPanel;
0448:                        splashScreen.addMouseListener(new MouseAdapter() {
0449:                            public void mouseUp(MouseEvent e) {
0450:                                mainStack.topControl = dialogBase;
0451:                                splashScreen.setVisible(false);
0452:                                dialogBase.setVisible(true);
0453:                            }
0454:                        });
0455:                        handleTabSelection(TAB_TEMPLATE, true);
0456:                        ReportWizard.this .startupQuery = startupQuery;
0457:                        final Cursor cursor = new Cursor(display,
0458:                                SWT.CURSOR_ARROW);
0459:                        if (parentContainer != null) {
0460:                            parentContainer.setCursor(cursor);
0461:                            parentContainer.redraw();
0462:                            parentContainer.update();
0463:                        }
0464:                        container.redraw();
0465:                        container.update();
0466:                    }
0467:                };
0468:                if (ReportWizard.applicationMode == ReportWizard.MODE_APPLICATION) {
0469:                    try {
0470:                        Display.getCurrent().asyncExec(r);
0471:                        // Thread.sleep(3000);
0472:                    } catch (Exception e) {
0473:                        e.printStackTrace();
0474:                    }
0475:                } else {
0476:                    Display.getCurrent().asyncExec(r);
0477:                }
0478:            }
0479:
0480:            private void createSplash(Composite parent) {
0481:                splashScreen = new Composite(parent, SWT.NONE);
0482:                GridLayout splashLayout = new GridLayout(1, true);
0483:                splashLayout.marginHeight = 0;
0484:                splashLayout.marginWidth = 0;
0485:                splashScreen.setBackground(Display.getDefault().getSystemColor(
0486:                        SWT.COLOR_WHITE));
0487:                splashScreen.setLayout(splashLayout);
0488:                InputStream splashStream = getClass().getResourceAsStream(
0489:                        "/images/reporting_splash.jpg"); //$NON-NLS-1$
0490:                final Image splashImage = new Image(display, splashStream); //$NON-NLS-1$
0491:                splashScreen.addPaintListener(new PaintListener() {
0492:                    public void paintControl(PaintEvent e) {
0493:                        GC gc = e.gc;
0494:                        gc.drawImage(splashImage, 0, 0);
0495:                        gc.setForeground(Display.getDefault().getSystemColor(
0496:                                SWT.COLOR_DARK_GRAY));
0497:                        gc
0498:                                .drawText(SWTUtility.COPYRIGHTMESSAGE, 350,
0499:                                        500, true);
0500:                        Font titleFont = new Font(display, gc.getFont()
0501:                                .getFontData()[0].getName(), 18, SWT.NORMAL); //$NON-NLS-1$
0502:                        gc.setFont(titleFont);
0503:                        // TODO: this code may throw an exception, we need to investigate this in the VersionHelper and/or implement workarounds here
0504:                        VersionInfo versionInfo = VersionHelper
0505:                                .getVersionInfo(ReportWizard.class);
0506:                        gc.drawText(versionInfo.getTitle(), 350, 260, true);
0507:                        Font versionFont = new Font(display, gc.getFont()
0508:                                .getFontData()[0].getName(), 13, SWT.NORMAL); //$NON-NLS-1$
0509:                        gc.setFont(versionFont);
0510:                        gc.drawText(versionInfo.getVersionNumber(), 350, 470,
0511:                                true);
0512:                        gc.dispose();
0513:                    }
0514:                });
0515:            }
0516:
0517:            public void detachPreview() {
0518:                if (detachedPreviewShell == null
0519:                        || detachedPreviewShell.isDisposed()) {
0520:                    detachedPreviewShell = SWTUtility
0521:                            .createShell(
0522:                                    800,
0523:                                    600,
0524:                                    new FillLayout(),
0525:                                    Messages
0526:                                            .getString("ReportWizard.USER_PREVIEW"), SWT.MIN | SWT.MAX | SWT.CLOSE | SWT.RESIZE); //$NON-NLS-1$
0527:                    try {
0528:                        browser = new Browser(detachedPreviewShell, SWT.BORDER);
0529:                    } catch (SWTError e) {
0530:                    }
0531:                    detachedPreviewShell.open();
0532:                }
0533:            }
0534:
0535:            public void destroy() {
0536:                PentahoUtility.shutdown();
0537:                TinyHTTPd.stopServer();
0538:            }
0539:
0540:            public void init() {
0541:                // loadSettings();
0542:                PentahoUtility.setSolutionRoot(solutionRootPath);
0543:                int port = 1024 + (new Random(System.currentTimeMillis()))
0544:                        .nextInt(30720);
0545:                PentahoUtility.setBaseURL("http://localhost:" + port + "/"); //$NON-NLS-1$ //$NON-NLS-2$
0546:                TinyHTTPd.startServer(solutionRootPath, port);
0547:                CWMStartup.loadCWMInstance(
0548:                        "resources/metadata/repository.properties",
0549:                        "resources/metadata/PentahoCWM.xml");
0550:            }
0551:
0552:            public void setDefaultOutputTypeMenuItem() {
0553:                if (previewType != null) {
0554:                    if (previewType.equalsIgnoreCase("html")) { //$NON-NLS-1$
0555:                        htmlPreviewTypeMenuItem.setSelection(true);
0556:                    } else if (previewType.equalsIgnoreCase("pdf")) { //$NON-NLS-1$
0557:                        pdfPreviewTypeMenuItem.setSelection(true);
0558:                    } else if (previewType.equalsIgnoreCase("xls")) { //$NON-NLS-1$
0559:                        xlsPreviewTypeMenuItem.setSelection(true);
0560:                    }
0561:                }
0562:            }
0563:
0564:            public void loadSettings() {
0565:                try {
0566:                    InputStream settingsStream = getClass().getClassLoader()
0567:                            .getResourceAsStream("settings.properties"); //$NON-NLS-1$
0568:                    settings.load(settingsStream);
0569:                    settingsStream.close();
0570:                    solutionRootPath = rdwRoot
0571:                            + settings.getProperty("solutionRoot"); //$NON-NLS-1$
0572:                    String tempPath = workingDir + "/temp"; //$NON-NLS-1$
0573:                    File tempDir = new File(tempPath);
0574:                    tempDir.mkdirs();
0575:                    jfreeReportOutputPath = solutionRootPath
0576:                            + "/samples/reporting/"; //$NON-NLS-1$
0577:                    exportPath = settings.getProperty("publish.location"); //$NON-NLS-1$
0578:                    ConnectionUtility.setRowLimit(Integer.parseInt(settings
0579:                            .getProperty("rowLimit"))); //$NON-NLS-1$
0580:                    if (settings.getProperty("report.output.type") != null && !"".equals(settings.getProperty("report.output.type"))) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
0581:                        previewType = settings
0582:                                .getProperty("report.output.type"); //$NON-NLS-1$
0583:                    }
0584:                    if (settings.getProperty("templatePath") != null && !settings.getProperty("templatePath").equals("")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
0585:                        templatePath = rdwRoot
0586:                                + settings.getProperty("templatePath"); //$NON-NLS-1$
0587:                    }
0588:                    if (!settings
0589:                            .getProperty("default.numeric.function").equals("")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
0590:                        defaultNumericFunction = settings
0591:                                .getProperty("default.numeric.function"); //$NON-NLS-1$
0592:                    }
0593:                    if (!settings.getProperty("simpleJNDIPath").equals("")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
0594:                        simpleJNDIPath = settings.getProperty("simpleJNDIPath"); //$NON-NLS-1$
0595:                    }
0596:
0597:                    removeCrlfFromQuery = "true".equals(settings.getProperty("removeCRLFInQuery")); //$NON-NLS-1$
0598:
0599:                } catch (Exception e) {
0600:                    e.printStackTrace();
0601:                }
0602:            }
0603:
0604:            public void handleTabSelection(int index, boolean fireWizardEvents) {
0605:                try {
0606:                    Cursor cursor = new Cursor(display, SWT.CURSOR_WAIT);
0607:                    container.setCursor(cursor);
0608:                    handlingTab = true;
0609:                    Composite newPanel = null;
0610:                    switch (index) {
0611:                    case TAB_TEMPLATE:
0612:                        newPanel = templatePanel;
0613:                        break;
0614:                    case TAB_QUERY:
0615:                        newPanel = queryPanel;
0616:                        break;
0617:                    case TAB_LAYOUT:
0618:                        newPanel = groupAndDetailPanel;
0619:                        break;
0620:                    // case TAB_MAPPING:
0621:                    // newPanel = mappingPanel;
0622:                    // break;
0623:                    case TAB_FORMAT:
0624:                        newPanel = fieldSetupPanel;
0625:                        break;
0626:                    // case TAB_PAGE:
0627:                    // newPanel = pageSetupPanel;
0628:                    // break;
0629:                    // case TAB_REPORT:
0630:                    // newPanel = reportSetupPanel;
0631:                    // break;
0632:                    }
0633:
0634:                    if (newPanel instanceof  WizardPanel) {
0635:                        WizardPanel wp = (WizardPanel) newPanel;
0636:                        int myIndex = wizardManager.getSteps().indexOf(wp);
0637:
0638:                        boolean validStep = true;
0639:
0640:                        if (fireWizardEvents) {
0641:                            for (int i = 0; i < myIndex; i++) {
0642:                                WizardPanel step = (WizardPanel) wizardManager
0643:                                        .getSteps().get(i);
0644:                                if (step.isContinueAllowed()) {
0645:                                    ignoreWizardEvents = true;
0646:                                    wizardManager.setCurrentStep(step);
0647:                                    wizardManager.next();
0648:                                    ignoreWizardEvents = false;
0649:                                } else {
0650:                                    // uh oh, they can't come here
0651:                                    validStep = false;
0652:                                    MessageBox mb = new MessageBox(
0653:                                            parentContainer.getShell(), SWT.OK);
0654:                                    mb
0655:                                            .setMessage("You must complete prior steps before proceeding.");
0656:                                    mb.setText("Error");
0657:                                    mb.open();
0658:                                }
0659:                            }
0660:                        }
0661:                        if (validStep) {
0662:                            navigationPanel.setIndex(index);
0663:                            templatePanel.setVisible(index == TAB_TEMPLATE);
0664:                            queryPanel.setVisible(index == TAB_QUERY);
0665:                            // mappingPanel.setVisible(index == TAB_MAPPING);
0666:                            fieldSetupPanel.setVisible(index == TAB_FORMAT);
0667:                            groupAndDetailPanel.setVisible(index == TAB_LAYOUT);
0668:                            // pageSetupPanel.setVisible(index == TAB_PAGE);
0669:                            // reportSetupPanel.setVisible(index == TAB_REPORT);
0670:                            if (newPanel != null) {
0671:                                stackLayout.topControl = newPanel;
0672:                            }
0673:                            currentTabIndex = index;
0674:                            wizardManager.setCurrentStep(wp);
0675:                            wizardManager.update();
0676:                        }
0677:                    }
0678:                } catch (Exception ex) {
0679:                    ex.printStackTrace();
0680:                } finally {
0681:                    handlingTab = false;
0682:                    Cursor cursor = new Cursor(display, SWT.CURSOR_ARROW);
0683:                    container.setCursor(cursor);
0684:                }
0685:            }
0686:
0687:            public void createMenuBar() {
0688:                if (parentContainer instanceof  Shell) {
0689:                    Menu bar = new Menu((Shell) parentContainer, SWT.BAR);
0690:                    ((Shell) parentContainer).setMenuBar(bar);
0691:                    MenuItem fileItem = new MenuItem(bar, SWT.CASCADE);
0692:                    fileItem.setText(Messages
0693:                            .getString("ReportWizard.USER_FILE")); //$NON-NLS-1$
0694:                    fileItem.setAccelerator(SWT.CTRL + 'F');
0695:                    Menu fileSubMenu = new Menu((Shell) parentContainer,
0696:                            SWT.DROP_DOWN);
0697:                    fileItem.setMenu(fileSubMenu);
0698:                    // MenuItem editItem = new MenuItem(bar, SWT.CASCADE);
0699:                    // editItem.setText(Messages.getString("ReportWizard.USER_EDIT")); //$NON-NLS-1$
0700:                    // editItem.setAccelerator(SWT.CTRL + 'E');
0701:                    // Menu editSubMenu = new Menu(container, SWT.DROP_DOWN);
0702:                    // editItem.setMenu(editSubMenu);
0703:                    MenuItem viewItem = new MenuItem(bar, SWT.CASCADE);
0704:                    viewItem.setText(Messages
0705:                            .getString("ReportWizard.USER_VIEW")); //$NON-NLS-1$
0706:                    Menu viewSubMenu = new Menu((Shell) parentContainer,
0707:                            SWT.DROP_DOWN);
0708:                    viewItem.setMenu(viewSubMenu);
0709:                    MenuItem item = new MenuItem(viewSubMenu, SWT.PUSH);
0710:                    item.addListener(SWT.Selection, new Listener() {
0711:                        public void handleEvent(Event e) {
0712:                            // Runnable r = new Runnable() {
0713:                            // public void run() {
0714:                            generateReportOutput(reportSpec,
0715:                                    jfreeReportOutputPath
0716:                                            + reportSpec.getReportName()
0717:                                            + ".xml", previewType, true);
0718:                            // }
0719:                            // };
0720:                            // Thread t = new Thread(r);
0721:                            // t.start();
0722:                        }
0723:                    });
0724:                    item.setText(Messages
0725:                            .getString("ReportWizard.USER_GENERATE_PREVIEW")); //$NON-NLS-1$
0726:                    MenuItem previewTypeMenu = new MenuItem(viewSubMenu,
0727:                            SWT.CASCADE);
0728:                    previewTypeMenu.setText(Messages
0729:                            .getString("ReportWizard.USER_PREVIEW_TYPE")); //$NON-NLS-1$
0730:                    Menu previewTypeSubMenu = new Menu(previewTypeMenu);
0731:                    previewTypeMenu.setMenu(previewTypeSubMenu);
0732:                    htmlPreviewTypeMenuItem = new MenuItem(previewTypeSubMenu,
0733:                            SWT.RADIO);
0734:                    htmlPreviewTypeMenuItem.setText(Messages
0735:                            .getString("ReportWizard.USER_HTML")); //$NON-NLS-1$
0736:                    htmlPreviewTypeMenuItem
0737:                            .addSelectionListener(new SelectionAdapter() {
0738:                                public void widgetSelected(SelectionEvent e) {
0739:                                    super .widgetSelected(e);
0740:                                    previewType = "html"; //$NON-NLS-1$
0741:                                }
0742:                            });
0743:                    pdfPreviewTypeMenuItem = new MenuItem(previewTypeSubMenu,
0744:                            SWT.RADIO);
0745:                    pdfPreviewTypeMenuItem.setText(Messages
0746:                            .getString("ReportWizard.USER_PDF")); //$NON-NLS-1$
0747:                    pdfPreviewTypeMenuItem
0748:                            .addSelectionListener(new SelectionAdapter() {
0749:                                public void widgetSelected(SelectionEvent e) {
0750:                                    super .widgetSelected(e);
0751:                                    previewType = "pdf"; //$NON-NLS-1$
0752:                                }
0753:                            });
0754:                    xlsPreviewTypeMenuItem = new MenuItem(previewTypeSubMenu,
0755:                            SWT.RADIO);
0756:                    xlsPreviewTypeMenuItem.setText(Messages
0757:                            .getString("ReportWizard.USER_XLS")); //$NON-NLS-1$
0758:                    xlsPreviewTypeMenuItem
0759:                            .addSelectionListener(new SelectionAdapter() {
0760:                                public void widgetSelected(SelectionEvent e) {
0761:                                    super .widgetSelected(e);
0762:                                    previewType = "xls"; //$NON-NLS-1$
0763:                                }
0764:                            });
0765:                    MenuItem helpItem = new MenuItem(bar, SWT.CASCADE);
0766:                    helpItem.setText(Messages
0767:                            .getString("ReportWizard.USER_HELP")); //$NON-NLS-1$
0768:                    Menu helpSubMenu = new Menu((Shell) parentContainer,
0769:                            SWT.DROP_DOWN);
0770:                    helpItem.setMenu(helpSubMenu);
0771:                    item = new MenuItem(fileSubMenu, SWT.PUSH);
0772:                    item.addListener(SWT.Selection, new Listener() {
0773:                        public void handleEvent(Event e) {
0774:                            MessageBox mb = new MessageBox(parentContainer
0775:                                    .getShell(), SWT.YES | SWT.NO);
0776:                            mb.setText(Messages.getString("ReportWizard.21")); //$NON-NLS-1$
0777:                            mb
0778:                                    .setMessage(Messages
0779:                                            .getString("ReportWizard.23")); //$NON-NLS-1$
0780:                            if (mb.open() == SWT.YES) {
0781:                                doSaveAs();
0782:                            }
0783:                            doNew();
0784:                        }
0785:                    });
0786:                    item.setText(Messages.getString("ReportWizard.USER_NEW")); //$NON-NLS-1$
0787:                    item.setAccelerator(SWT.CTRL + 'N');
0788:                    item = new MenuItem(fileSubMenu, SWT.PUSH);
0789:                    item.addListener(SWT.Selection, new Listener() {
0790:                        public void handleEvent(Event e) {
0791:                            doOpen();
0792:                        }
0793:                    });
0794:                    item.setText(Messages.getString("ReportWizard.USER_OPEN")); //$NON-NLS-1$
0795:                    item.setAccelerator(SWT.CTRL + 'O');
0796:                    saveItem = new MenuItem(fileSubMenu, SWT.PUSH);
0797:                    saveItem.addListener(SWT.Selection, new Listener() {
0798:                        public void handleEvent(Event e) {
0799:                            doSave();
0800:                        }
0801:                    });
0802:                    saveItem.setText(Messages
0803:                            .getString("ReportWizard.USER_SAVE")); //$NON-NLS-1$
0804:                    saveItem.setAccelerator(SWT.CTRL + 'S');
0805:                    saveItem.setEnabled(isSaved);
0806:                    item = new MenuItem(fileSubMenu, SWT.PUSH);
0807:                    item.addListener(SWT.Selection, new Listener() {
0808:                        public void handleEvent(Event e) {
0809:                            doSaveAs();
0810:                        }
0811:                    });
0812:                    item.setText(Messages
0813:                            .getString("ReportWizard.USER_SAVE_AS")); //$NON-NLS-1$
0814:                    item = new MenuItem(fileSubMenu, SWT.SEPARATOR);
0815:                    item = new MenuItem(fileSubMenu, SWT.PUSH);
0816:                    item.setText(Messages.getString("ReportWizard.70")); //$NON-NLS-1$
0817:                    item.addSelectionListener(new SelectionAdapter() {
0818:                        public void widgetSelected(SelectionEvent e) {
0819:                            doPublishReport();
0820:                        }
0821:                    });
0822:                    item = new MenuItem(fileSubMenu, SWT.SEPARATOR);
0823:                    item = new MenuItem(fileSubMenu, SWT.PUSH);
0824:                    item.setText(Messages.getString("ReportWizard.2")); //$NON-NLS-1$
0825:                    item.addSelectionListener(new SelectionAdapter() {
0826:                        public void widgetSelected(SelectionEvent e) {
0827:                            FileOutputStream fos = null;
0828:                            try {
0829:                                FileDialog fileDialog = new FileDialog(
0830:                                        parentContainer.getShell(), SWT.SAVE);
0831:                                String path = fileDialog.open();
0832:                                if (path != null) {
0833:                                    File f = new File(path);
0834:                                    int result = SWT.YES;
0835:                                    if (f.exists()) {
0836:                                        // prompt to overwrite
0837:                                        MessageBox mb = new MessageBox(
0838:                                                parentContainer.getShell(),
0839:                                                SWT.YES | SWT.NO);
0840:                                        mb.setText(Messages
0841:                                                .getString("ReportWizard.0")); //$NON-NLS-1$
0842:                                        mb.setMessage(Messages
0843:                                                .getString("ReportWizard.1")); //$NON-NLS-1$
0844:                                        result = mb.open();
0845:                                    }
0846:                                    if (result == SWT.YES) {
0847:                                        fos = new FileOutputStream(f);
0848:                                        IPentahoResultSet resultSet = (IPentahoResultSet) ConnectionUtility.queryResultSetMap
0849:                                                .get(reportSpec.getQuery());
0850:                                        try {
0851:                                            resultSet.beforeFirst();
0852:                                        } catch (Exception ex) {
0853:                                            ex.printStackTrace();
0854:                                        }
0855:                                        String xmlString = DataUtilities
0856:                                                .getXMLString(resultSet);
0857:                                        fos.write(xmlString.getBytes());
0858:                                        fos.close();
0859:                                    }
0860:                                }
0861:                            } catch (Exception ex) {
0862:                                ex.printStackTrace();
0863:                            } finally {
0864:                                try {
0865:                                    fos.close();
0866:                                } catch (Exception ex) {
0867:                                }
0868:                            }
0869:                        }
0870:                    });
0871:                    item = new MenuItem(fileSubMenu, SWT.SEPARATOR);
0872:                    item = new MenuItem(fileSubMenu, SWT.PUSH);
0873:                    item.addListener(SWT.Selection, new Listener() {
0874:                        public void handleEvent(Event e) {
0875:                            MessageBox mb = new MessageBox(parentContainer
0876:                                    .getShell(), SWT.YES | SWT.NO);
0877:                            mb.setText(Messages.getString("ReportWizard.21")); //$NON-NLS-1$
0878:                            mb
0879:                                    .setMessage(Messages
0880:                                            .getString("ReportWizard.22")); //$NON-NLS-1$
0881:                            if (mb.open() == SWT.YES) {
0882:                                doSaveAs();
0883:                            }
0884:                            parentContainer.dispose();
0885:                        }
0886:                    });
0887:                    item.setText(Messages.getString("ReportWizard.USER_EXIT")); //$NON-NLS-1$
0888:                    item = new MenuItem(viewSubMenu, SWT.SEPARATOR);
0889:                    item = new MenuItem(viewSubMenu, SWT.PUSH);
0890:                    item.addListener(SWT.Selection, new Listener() {
0891:                        public void handleEvent(Event e) {
0892:                            wizardManager.preview();
0893:                            // generateReportOutput(reportSpec, jfreeReportOutputPath, "pdf", true); //$NON-NLS-1$
0894:                        }
0895:                    });
0896:                    item.setText(Messages
0897:                            .getString("ReportWizard.USER_PREVIEW_PDF")); //$NON-NLS-1$
0898:                    item = new MenuItem(viewSubMenu, SWT.PUSH);
0899:                    item.addListener(SWT.Selection, new Listener() {
0900:                        public void handleEvent(Event e) {
0901:                            generateReportOutput(reportSpec,
0902:                                    jfreeReportOutputPath
0903:                                            + reportSpec.getReportName()
0904:                                            + ".xml", "html", true); //$NON-NLS-1$
0905:                        }
0906:                    });
0907:                    item.setText(Messages
0908:                            .getString("ReportWizard.USER_PREVIEW_HTML")); //$NON-NLS-1$
0909:                    item = new MenuItem(viewSubMenu, SWT.PUSH);
0910:                    item.addListener(SWT.Selection, new Listener() {
0911:                        public void handleEvent(Event e) {
0912:                            generateReportOutput(reportSpec,
0913:                                    jfreeReportOutputPath
0914:                                            + reportSpec.getReportName()
0915:                                            + ".xml", "xls", true); //$NON-NLS-1$
0916:                        }
0917:                    });
0918:                    item.setText(Messages
0919:                            .getString("ReportWizard.USER_PREVIEW_EXCEL")); //$NON-NLS-1$
0920:                    item = new MenuItem(helpSubMenu, SWT.PUSH);
0921:                    item.addListener(SWT.Selection, new Listener() {
0922:                        public void handleEvent(Event e) {
0923:                            splashScreen.setVisible(true);
0924:                            dialogBase.setVisible(false);
0925:                            mainStack.topControl = splashScreen;
0926:                            /*
0927:                             * Shell container = SWTUtility.createModalDialogShell(450, 180, "About"); container.setLayout(new FillLayout()); Text text = new Text(container, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); text.setText(SWTUtility.COPYRIGHTMESSAGE);
0928:                             * container.open();
0929:                             */
0930:                        }
0931:                    });
0932:                    item.setText(Messages.getString("ReportWizard.USER_ABOUT")); //$NON-NLS-1$
0933:                }
0934:            }
0935:
0936:            public void doPublishReport() {
0937:                PublishDialog publishDialog = new PublishDialog(Messages
0938:                        .getString("ReportWizard.44"), reportSpec, settings); //$NON-NLS-1$
0939:                if (publishDialog.open()) {
0940:                    try {
0941:                        if (!publishDialog.publishToServer) {
0942:                            String oldName = reportSpec.getReportName();
0943:                            String reportName = publishDialog.name;
0944:                            reportSpec.setReportName(reportName);
0945:                            System.out
0946:                                    .println(Messages
0947:                                            .getString(
0948:                                                    "ReportWizard.DEBUG_WRITING", jfreeReportOutputPath + reportSpec.getReportName() + ".xml")); //$NON-NLS-1$//$NON-NLS-2$
0949:                            // report name
0950:                            String watermarkSrc = reportSpec.getWatermark() != null ? reportSpec
0951:                                    .getWatermark().getSrc()
0952:                                    : null;
0953:                            // need to copy jfreereport
0954:                            String jfreeFile = publishDialog.location
0955:                                    + File.separator + reportName + ".xml"; //$NON-NLS-1$
0956:                            String jfreeDestDir = publishDialog.location
0957:                                    + File.separator;
0958:                            if (reportSpec.getTemplateSrc() != null) {
0959:                                doExportImagesToLocation(jfreeDestDir,
0960:                                        templateImageMap);
0961:                            }
0962:                            if (watermarkSrc != null) {
0963:                                watermarkSrc = new File(reportSpec
0964:                                        .getWatermark().getSrc()).getName();
0965:                                String watermarkFileName = jfreeDestDir
0966:                                        + "/" + watermarkSrc; //$NON-NLS-1$ //$NON-NLS-2$
0967:                                ReportSpecUtility.copyFile(reportSpec
0968:                                        .getWatermark().getSrc(),
0969:                                        watermarkFileName);
0970:                                reportSpec.getWatermark().setSrc(
0971:                                        watermarkFileName);
0972:                            }
0973:                            String includeSrc = reportSpec.getIncludeSrc();
0974:                            if (includeSrc != null
0975:                                    && !includeSrc.equalsIgnoreCase("")) { //$NON-NLS-1$
0976:                                includeSrc = new File(includeSrc).getName();
0977:                                String includeFileName = jfreeDestDir
0978:                                        + "/" + includeSrc; //$NON-NLS-1$ //$NON-NLS-2$
0979:                                ReportSpecUtility.copyFile(reportSpec
0980:                                        .getIncludeSrc(), includeFileName);
0981:                                reportSpec.setIncludeSrc(includeFileName);
0982:                            }
0983:                            if (reportSpec.getTemplateSrc() != null) {
0984:                                File generatedFile = new File(
0985:                                        publishDialog.location + File.separator
0986:                                                + reportSpec.getReportName()
0987:                                                + "_generated.xml");
0988:                                ReportGenerationUtility.createJFreeReportXML(
0989:                                        reportSpec, new FileOutputStream(
0990:                                                generatedFile), 0, 0, false,
0991:                                        "", 0, 0); //$NON-NLS-1$
0992:                                ReportGenerationUtility.mergeTemplate(new File(
0993:                                        reportSpec.getTemplateSrc()),
0994:                                        generatedFile, new FileOutputStream(
0995:                                                jfreeFile)); //$NON-NLS-1$
0996:                                generateReportOutput(reportSpec, jfreeFile,
0997:                                        publishDialog.reportType, false);
0998:                            } else {
0999:                                // need to generate jfreereport xml
1000:                                ReportGenerationUtility.createJFreeReportXML(
1001:                                        reportSpec, new FileOutputStream(
1002:                                                jfreeFile), 0, 0, false,
1003:                                        "", 0, 0); //$NON-NLS-1$
1004:                                generateReportOutput(reportSpec, jfreeFile,
1005:                                        publishDialog.reportType, false); //$NON-NLS-1$
1006:                            }
1007:                            if (jfreeDestDir != null
1008:                                    && !jfreeDestDir.equals("") && reportName != null && !reportName.equals("")) { //$NON-NLS-1$ //$NON-NLS-2$
1009:                                String jfreeDestFile = jfreeDestDir
1010:                                        + "/" + reportName + ".xml"; //$NON-NLS-1$ //$NON-NLS-2$
1011:                                ReportSpecUtility.copyFile(jfreeFile,
1012:                                        jfreeDestFile);
1013:                                String propertyDestFile = jfreeDestDir
1014:                                        + "/" + reportName + ".properties"; //$NON-NLS-1$ //$NON-NLS-2$
1015:                                FileOutputStream propertyFileOutputStream = new FileOutputStream(
1016:                                        propertyDestFile);
1017:                                String nameProp = "title=" + reportName + "\r\n"; //$NON-NLS-1$ //$NON-NLS-2$
1018:                                String descProp = "description=" + reportSpec.getReportDesc() + "\r\n"; //$NON-NLS-1$ //$NON-NLS-2$
1019:                                propertyFileOutputStream.write(nameProp
1020:                                        .getBytes());
1021:                                propertyFileOutputStream.write(descProp
1022:                                        .getBytes());
1023:                                propertyFileOutputStream.flush();
1024:                                propertyFileOutputStream.close();
1025:                                String actionSequenceSrcFile = jfreeReportOutputPath
1026:                                        + reportName + ".xaction"; //$NON-NLS-1$
1027:                                String actionSequenceDestFile = jfreeDestDir
1028:                                        + "/" + reportName + ".xaction"; //$NON-NLS-1$ //$NON-NLS-2$
1029:                                ReportSpecUtility.copyFile(
1030:                                        actionSequenceSrcFile,
1031:                                        actionSequenceDestFile);
1032:                                String reportSpecDestFile = jfreeDestDir
1033:                                        + "/" + reportName + ".xreportspec"; //$NON-NLS-1$ //$NON-NLS-2$
1034:                                if (reportSpecFilePath == null) {
1035:                                    // write reportSpec out
1036:                                    File tempFile = File
1037:                                            .createTempFile(
1038:                                                    "report", ".xreportsec", new File("./temp")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1039:                                    tempFile.deleteOnExit();
1040:                                    CastorUtility.getInstance()
1041:                                            .writeCastorObject(reportSpec,
1042:                                                    tempFile.getAbsolutePath());
1043:                                    ReportSpecUtility.copyFile(tempFile
1044:                                            .getAbsolutePath(),
1045:                                            reportSpecDestFile);
1046:                                } else {
1047:                                    ReportSpecUtility.copyFile(
1048:                                            reportSpecFilePath,
1049:                                            reportSpecDestFile);
1050:                                }
1051:                                ReportSpecUtility
1052:                                        .copyFile(
1053:                                                jfreeReportOutputPath
1054:                                                        + "PentahoReporting.png", jfreeDestDir + "/PentahoReporting.png"); //$NON-NLS-1$ //$NON-NLS-2$
1055:                                String cubeDefPath = reportSpec
1056:                                        .getMondrianCubeDefinitionPath();
1057:                                if (cubeDefPath != null
1058:                                        && !cubeDefPath.equals("")) { //$NON-NLS-1$
1059:                                    File cubePathFile = new File(cubeDefPath);
1060:                                    ReportSpecUtility
1061:                                            .copyFile(
1062:                                                    cubeDefPath,
1063:                                                    jfreeDestDir
1064:                                                            + "/" + cubePathFile.getName()); //$NON-NLS-1$
1065:                                }
1066:                                ReportSpecChoice choice = reportSpec
1067:                                        .getReportSpecChoice();
1068:                                if (choice == null) {
1069:                                    // TODO log this
1070:                                } else {
1071:                                    String xqueryPath = choice.getXqueryUrl();
1072:                                    if (xqueryPath != null
1073:                                            && !xqueryPath.equals("")) { //$NON-NLS-1$
1074:                                        File xqueryPathFile = new File(
1075:                                                xqueryPath);
1076:                                        ReportSpecUtility
1077:                                                .copyFile(
1078:                                                        xqueryPath,
1079:                                                        jfreeDestDir
1080:                                                                + "/" + xqueryPathFile.getName()); //$NON-NLS-1$
1081:                                    }
1082:                                }
1083:                            }
1084:                            if (publishDialog.createDataSource) {
1085:                                String jbossDeployDir = publishDialog.deployDir;
1086:                                String webAppName = publishDialog.webAppName;
1087:                                String jndi = reportSpec.getReportSpecChoice()
1088:                                        .getJndiSource();
1089:                                if (jndi != null) {
1090:                                    JBossDatasourceAdmin jbossDSAdmin = new JBossDatasourceAdmin();
1091:                                    jbossDSAdmin
1092:                                            .setApplicationRoot(jbossDeployDir);
1093:                                    jbossDSAdmin
1094:                                            .setWebApplicationName(webAppName);
1095:                                    Iterator keyIterator = jbossDSAdmin
1096:                                            .listContainerDataSources()
1097:                                            .keySet().iterator();
1098:                                    boolean exists = false;
1099:                                    while (keyIterator.hasNext()) {
1100:                                        String key = (String) keyIterator
1101:                                                .next();
1102:                                        if (jndi.equals(key)) {
1103:                                            exists = true;
1104:                                            break;
1105:                                        }
1106:                                    }
1107:                                    if (!exists) {
1108:                                        MessageBox mb = new MessageBox(
1109:                                                container.getShell(), SWT.YES
1110:                                                        | SWT.NO);
1111:                                        mb.setText(Messages
1112:                                                .getString("ReportWizard.57")); //$NON-NLS-1$
1113:                                        mb
1114:                                                .setMessage(Messages
1115:                                                        .getString("ReportWizard.66") + jndi + Messages.getString("ReportWizard.58")); //$NON-NLS-1$ //$NON-NLS-2$
1116:                                        int result = mb.open();
1117:                                        if (result == SWT.YES) {
1118:                                            DataSourceInfo simpleJNDIDS = dataSourceAdmin
1119:                                                    .getDataSourceInfo(jndi);
1120:                                            jbossDSAdmin.saveDataSource(
1121:                                                    simpleJNDIDS, false);
1122:                                        }
1123:                                    }
1124:                                }
1125:                            }
1126:                            reportSpec.setReportName(oldName);
1127:                            MessageBox mb = new MessageBox(parentContainer
1128:                                    .getShell(), SWT.OK);
1129:                            mb
1130:                                    .setText(Messages
1131:                                            .getString("ReportWizard.USER_PUBLISH_TITLE")); //$NON-NLS-1$
1132:                            mb
1133:                                    .setMessage(Messages
1134:                                            .getString("ReportWizard.USER_PUBLISH_SUCCESSFUL")); //$NON-NLS-1$
1135:                            mb.open();
1136:                        } else {
1137:                            String oldName = reportSpec.getReportName();
1138:                            String reportName = publishDialog.name;
1139:                            reportSpec.setReportName(reportName);
1140:                            System.out
1141:                                    .println(Messages
1142:                                            .getString(
1143:                                                    "ReportWizard.DEBUG_WRITING", jfreeReportOutputPath + reportSpec.getReportName() + ".xml")); //$NON-NLS-1$//$NON-NLS-2$
1144:                            // report name
1145:                            String watermarkSrc = reportSpec.getWatermark() != null ? reportSpec
1146:                                    .getWatermark().getSrc()
1147:                                    : null;
1148:                            // need to copy jfreereport
1149:                            String publishPath = publishDialog.location;
1150:                            publishDialog.location = File
1151:                                    .createTempFile(
1152:                                            Messages
1153:                                                    .getString("ReportWizard.45"), "tmp").getParent() + File.separator + "exportDir" + (new Random(System.currentTimeMillis()).nextLong()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1154:                            File locDir = new File(publishDialog.location);
1155:                            locDir.mkdirs();
1156:                            String jfreeFile = publishDialog.location
1157:                                    + File.separator + reportName + ".xml"; //$NON-NLS-1$
1158:                            String jfreeDestDir = publishDialog.location
1159:                                    + File.separator;
1160:                            if (reportSpec.getTemplateSrc() != null) {
1161:                                doExportImagesToLocation(jfreeDestDir,
1162:                                        templateImageMap);
1163:                            }
1164:                            if (watermarkSrc != null) {
1165:                                watermarkSrc = new File(reportSpec
1166:                                        .getWatermark().getSrc()).getName();
1167:                                String watermarkFileName = jfreeDestDir
1168:                                        + "/" + watermarkSrc; //$NON-NLS-1$ //$NON-NLS-2$
1169:                                ReportSpecUtility.copyFile(reportSpec
1170:                                        .getWatermark().getSrc(),
1171:                                        watermarkFileName);
1172:                                reportSpec.getWatermark().setSrc(
1173:                                        watermarkFileName);
1174:                            }
1175:                            String includeSrc = reportSpec.getIncludeSrc();
1176:                            if (includeSrc != null
1177:                                    && !includeSrc.equalsIgnoreCase("")) { //$NON-NLS-1$
1178:                                includeSrc = new File(includeSrc).getName();
1179:                                String includeFileName = jfreeDestDir
1180:                                        + "/" + includeSrc; //$NON-NLS-1$ //$NON-NLS-2$
1181:                                ReportSpecUtility.copyFile(reportSpec
1182:                                        .getIncludeSrc(), includeFileName);
1183:                                reportSpec.setIncludeSrc(includeFileName);
1184:                            }
1185:                            if (reportSpec.getTemplateSrc() != null) {
1186:                                File generatedFile = new File(
1187:                                        publishDialog.location + File.separator
1188:                                                + reportSpec.getReportName()
1189:                                                + "_generated.xml");
1190:                                ReportGenerationUtility.createJFreeReportXML(
1191:                                        reportSpec, new FileOutputStream(
1192:                                                generatedFile), 0, 0, false,
1193:                                        "", 0, 0); //$NON-NLS-1$
1194:                                ReportGenerationUtility.mergeTemplate(new File(
1195:                                        reportSpec.getTemplateSrc()),
1196:                                        generatedFile, new FileOutputStream(
1197:                                                jfreeFile)); //$NON-NLS-1$
1198:                                generateReportOutput(reportSpec, jfreeFile,
1199:                                        publishDialog.reportType, false);
1200:                            } else {
1201:                                // need to generate jfreereport xml
1202:                                ReportGenerationUtility.createJFreeReportXML(
1203:                                        reportSpec, new FileOutputStream(
1204:                                                jfreeFile), 0, 0, false,
1205:                                        "", 0, 0); //$NON-NLS-1$
1206:                                generateReportOutput(reportSpec, jfreeFile,
1207:                                        publishDialog.reportType, false); //$NON-NLS-1$
1208:                            }
1209:                            if (jfreeDestDir != null
1210:                                    && !jfreeDestDir.equals("") && reportName != null && !reportName.equals("")) { //$NON-NLS-1$ //$NON-NLS-2$
1211:                                String jfreeDestFile = jfreeDestDir
1212:                                        + "/" + reportName + ".xml"; //$NON-NLS-1$ //$NON-NLS-2$
1213:                                ReportSpecUtility.copyFile(jfreeFile,
1214:                                        jfreeDestFile);
1215:                                String propertyDestFile = jfreeDestDir
1216:                                        + "/" + reportName + ".properties"; //$NON-NLS-1$ //$NON-NLS-2$
1217:                                FileOutputStream propertyFileOutputStream = new FileOutputStream(
1218:                                        propertyDestFile);
1219:                                String nameProp = "title=" + reportName + "\r\n"; //$NON-NLS-1$ //$NON-NLS-2$
1220:                                String descProp = "description=" + reportSpec.getReportDesc() + "\r\n"; //$NON-NLS-1$ //$NON-NLS-2$
1221:                                propertyFileOutputStream.write(nameProp
1222:                                        .getBytes());
1223:                                propertyFileOutputStream.write(descProp
1224:                                        .getBytes());
1225:                                propertyFileOutputStream.flush();
1226:                                propertyFileOutputStream.close();
1227:                                String actionSequenceSrcFile = jfreeReportOutputPath
1228:                                        + reportName + ".xaction"; //$NON-NLS-1$
1229:                                String actionSequenceDestFile = jfreeDestDir
1230:                                        + "/" + reportName + ".xaction"; //$NON-NLS-1$ //$NON-NLS-2$
1231:                                ReportSpecUtility.copyFile(
1232:                                        actionSequenceSrcFile,
1233:                                        actionSequenceDestFile);
1234:                                String reportSpecDestFile = jfreeDestDir
1235:                                        + "/" + reportName + ".xreportspec"; //$NON-NLS-1$ //$NON-NLS-2$
1236:                                if (reportSpecFilePath == null) {
1237:                                    // write reportSpec out
1238:                                    File tempFile = File
1239:                                            .createTempFile(
1240:                                                    "report", ".xreportsec", new File("./temp")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1241:                                    tempFile.deleteOnExit();
1242:                                    CastorUtility.getInstance()
1243:                                            .writeCastorObject(reportSpec,
1244:                                                    tempFile.getAbsolutePath());
1245:                                    ReportSpecUtility.copyFile(tempFile
1246:                                            .getAbsolutePath(),
1247:                                            reportSpecDestFile);
1248:                                } else {
1249:                                    ReportSpecUtility.copyFile(
1250:                                            reportSpecFilePath,
1251:                                            reportSpecDestFile);
1252:                                }
1253:                                String cubeDefPath = reportSpec
1254:                                        .getMondrianCubeDefinitionPath();
1255:                                if (cubeDefPath != null
1256:                                        && !cubeDefPath.equals("")) { //$NON-NLS-1$
1257:                                    File cubePathFile = new File(cubeDefPath);
1258:                                    ReportSpecUtility
1259:                                            .copyFile(
1260:                                                    cubeDefPath,
1261:                                                    jfreeDestDir
1262:                                                            + "/" + cubePathFile.getName()); //$NON-NLS-1$
1263:                                }
1264:                                ReportSpecChoice choice = reportSpec
1265:                                        .getReportSpecChoice();
1266:                                if (choice == null) {
1267:                                    // TODO log this
1268:                                } else {
1269:                                    String xqueryPath = choice.getXqueryUrl();
1270:                                    if (xqueryPath != null
1271:                                            && !xqueryPath.equals("")) { //$NON-NLS-1$
1272:                                        File xqueryPathFile = new File(
1273:                                                xqueryPath);
1274:                                        ReportSpecUtility
1275:                                                .copyFile(
1276:                                                        xqueryPath,
1277:                                                        jfreeDestDir
1278:                                                                + "/" + xqueryPathFile.getName()); //$NON-NLS-1$
1279:                                    }
1280:                                }
1281:                            }
1282:                            reportSpec.setReportName(oldName);
1283:                            if (publishPath.startsWith(File.separator)) {
1284:                                publishPath = publishPath.substring(1);
1285:                            }
1286:                            if (!publishPath.endsWith(File.separator)) {
1287:                                publishPath = publishPath + File.separator;
1288:                            }
1289:                            int rtn = ISolutionRepository.FILE_ADD_SUCCESSFUL;
1290:                            if (reportSpec.getReportSpecChoice() != null
1291:                                    && reportSpec.getReportSpecChoice()
1292:                                            .getJndiSource() != null) {
1293:                                rtn = PublisherUtil.publish(
1294:                                        publishDialog.publishURL, publishPath,
1295:                                        locDir.listFiles(), dataSourceAdmin
1296:                                                .getDataSourceInfo(reportSpec
1297:                                                        .getReportSpecChoice()
1298:                                                        .getJndiSource()),
1299:                                        publishDialog.publishPW,
1300:                                        publishDialog.serverUID,
1301:                                        publishDialog.serverPW, false);
1302:                            } else {
1303:                                rtn = PublisherUtil.publish(
1304:                                        publishDialog.publishURL, publishPath,
1305:                                        locDir.listFiles(),
1306:                                        publishDialog.publishPW,
1307:                                        publishDialog.serverUID,
1308:                                        publishDialog.serverPW, false);
1309:                            }
1310:                            MessageBox mb = null;
1311:                            int whichBtns = (rtn == ISolutionRepository.FILE_EXISTS) ? SWT.YES
1312:                                    | SWT.NO
1313:                                    : SWT.OK;
1314:                            mb = new MessageBox(parentContainer.getShell(),
1315:                                    whichBtns);
1316:                            String extraMsg = "";
1317:                            if (rtn == ISolutionRepository.FILE_ADD_FAILED) {
1318:                                extraMsg = " "
1319:                                        + Messages
1320:                                                .getString("ReportWizard.SEE_SERVER_LOGS");
1321:                            } else if (rtn == ISolutionRepository.FILE_EXISTS) {
1322:                                extraMsg = " "
1323:                                        + Messages
1324:                                                .getString("ReportWizard.LIKE_T0_OVERWRITE");
1325:                            }
1326:
1327:                            String msg = ISolutionRepository.FILE_STATUS_MSG[rtn];
1328:                            mb.setMessage(msg + extraMsg);
1329:
1330:                            mb
1331:                                    .setText(Messages
1332:                                            .getString("ReportWizard.USER_PUBLISH_TITLE")); //$NON-NLS-1$
1333:                            int promptStatus = mb.open();
1334:                            if (promptStatus == SWT.YES) {
1335:                                if (reportSpec.getReportSpecChoice()
1336:                                        .getJndiSource() != null) {
1337:                                    rtn = PublisherUtil
1338:                                            .publish(
1339:                                                    publishDialog.publishURL,
1340:                                                    publishPath,
1341:                                                    locDir.listFiles(),
1342:                                                    dataSourceAdmin
1343:                                                            .getDataSourceInfo(reportSpec
1344:                                                                    .getReportSpecChoice()
1345:                                                                    .getJndiSource()),
1346:                                                    publishDialog.publishPW,
1347:                                                    publishDialog.serverUID,
1348:                                                    publishDialog.serverPW,
1349:                                                    true);
1350:                                } else {
1351:                                    rtn = PublisherUtil.publish(
1352:                                            publishDialog.publishURL,
1353:                                            publishPath, locDir.listFiles(),
1354:                                            publishDialog.publishPW,
1355:                                            publishDialog.serverUID,
1356:                                            publishDialog.serverPW, true);
1357:                                }
1358:
1359:                                extraMsg = "";
1360:                                if (rtn == ISolutionRepository.FILE_ADD_FAILED) {
1361:                                    extraMsg = " "
1362:                                            + Messages
1363:                                                    .getString("ReportWizard.SEE_SERVER_LOGS");
1364:                                } else if (rtn == ISolutionRepository.FILE_EXISTS) {
1365:                                    extraMsg = " "
1366:                                            + Messages
1367:                                                    .getString("ReportWizard.CANNOT_OVERWRITE");
1368:                                }
1369:
1370:                                msg = ISolutionRepository.FILE_STATUS_MSG[rtn];
1371:                                mb = new MessageBox(parentContainer.getShell(),
1372:                                        SWT.OK);
1373:                                mb.setMessage(msg + extraMsg);
1374:                                mb.open();
1375:                            }
1376:                            // publish the PentahoReporting.png, fail silently as this file is not critical
1377:                            File files[] = locDir.listFiles();
1378:                            for (int i = 0; i < files.length; i++) {
1379:                                files[i].delete();
1380:                            }
1381:                            ReportSpecUtility
1382:                                    .copyFile(
1383:                                            jfreeReportOutputPath
1384:                                                    + "PentahoReporting.png", jfreeDestDir + "/PentahoReporting.png"); //$NON-NLS-1$ //$NON-NLS-2$
1385:                            PublisherUtil.publish(publishDialog.publishURL,
1386:                                    publishPath, locDir.listFiles(),
1387:                                    publishDialog.publishPW,
1388:                                    publishDialog.serverUID,
1389:                                    publishDialog.serverPW, false);
1390:                        }
1391:                    } catch (Exception e) {
1392:                        e.printStackTrace();
1393:                    }
1394:                }
1395:            }
1396:
1397:            public void doExportImagesToLocation(String jfreeDestDir,
1398:                    HashMap images) {
1399:                try {
1400:                    String templateSrc = reportSpec.getTemplateSrc();
1401:                    FileInputStream fis = new FileInputStream(templateSrc);
1402:                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
1403:                    byte bytes[] = new byte[1024];
1404:                    int numRead = 0;
1405:                    while ((numRead = fis.read(bytes)) != -1) {
1406:                        if (numRead > 0) {
1407:                            baos.write(bytes, 0, numRead);
1408:                        }
1409:                    }
1410:                    String templateStr = baos.toString();
1411:                    Iterator keys = images.keySet().iterator();
1412:                    while (keys.hasNext()) {
1413:                        String key = (String) keys.next();
1414:                        String value = (String) images.get(key);
1415:                        // value is path to image
1416:                        URL fileURL = new URL(value);
1417:                        InputStream is = fileURL.openStream();
1418:                        String name = jfreeDestDir
1419:                                + "/" + (new File(key)).getName(); //$NON-NLS-1$
1420:                        String outFilePath = (new File(name))
1421:                                .getCanonicalPath();
1422:                        FileOutputStream fos = new FileOutputStream(name);
1423:                        while ((numRead = is.read(bytes)) != -1) {
1424:                            if (numRead > 0) {
1425:                                fos.write(bytes, 0, numRead);
1426:                            }
1427:                        }
1428:                        fos.close();
1429:                        templateStr = templateStr.replaceAll(value,
1430:                                "file://" + outFilePath.replace('\\', '/')); //$NON-NLS-1$
1431:                    }
1432:                    FileOutputStream fos = new FileOutputStream(templateSrc);
1433:                    fos.write(templateStr.getBytes());
1434:                    fos.close();
1435:                } catch (Exception e) {
1436:                    e.printStackTrace(System.err);
1437:                }
1438:            }
1439:
1440:            public void doNew(boolean setStep, boolean fireInitializations) {
1441:                // prompt to be sure
1442:                // reportSpec = new ReportSpec();
1443:                if (startupQuery != null) {
1444:                    reportSpec.setQuery(startupQuery);
1445:                }
1446:                reportSpecFilePath = null;
1447:                templateZipPath = null;
1448:                pentahoConnection = null;
1449:                if (fireInitializations) {
1450:                    initWizardPanels(wizardManager.getCurrentStep());
1451:                }
1452:                if (setStep) {
1453:                    handleTabSelection(TAB_TEMPLATE, true);
1454:                }
1455:                wizardManager.update();
1456:                getTypeMap().clear();
1457:                ConnectionUtility.queryColumnMap.clear();
1458:                ConnectionUtility.queryResultSetMap.clear();
1459:            }
1460:
1461:            public void doNew() {
1462:                doNew(true, true);
1463:            }
1464:
1465:            public void doOpenTemplate(String path, boolean setStep,
1466:                    boolean fireInitializations) {
1467:                // clear all settings
1468:                // doNew(false);
1469:                try {
1470:                    // crack archive, pull out thumbnail.png (or jpg)
1471:                    ZipFile zipFile = new ZipFile(path);
1472:                    // ZipEntry thumbnailEntry = zipFile.getEntry("thumbnail.png");
1473:                    // thumbnailImage = new Image(getDisplay(),
1474:                    // zipFile.getInputStream(thumbnailEntry));
1475:                    ZipEntry reportSpecEntry = zipFile
1476:                            .getEntry("report.xreportspec"); //$NON-NLS-1$
1477:                    File tempFile = File.createTempFile(
1478:                            "report", ".xreportsec", new File("./temp")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1479:                    tempFile.deleteOnExit();
1480:                    FileOutputStream fos = new FileOutputStream(tempFile);
1481:                    InputStream inputStream = zipFile
1482:                            .getInputStream(reportSpecEntry);
1483:                    byte[] bytes = new byte[32768];
1484:                    int numRead = 0;
1485:                    while ((numRead = inputStream.read(bytes)) != -1) {
1486:                        if (numRead > 0) {
1487:                            fos.write(bytes, 0, numRead);
1488:                        }
1489:                    }
1490:                    fos.close();
1491:                    reportSpecFilePath = tempFile.getAbsolutePath();
1492:                    doOpen(reportSpecFilePath, false, fireInitializations);
1493:                    ZipEntry jfreereportTemplateEntry = zipFile
1494:                            .getEntry("jfreereport-template.xml"); //$NON-NLS-1$
1495:                    tempFile = File.createTempFile(
1496:                            "jfreereport-template", ".xml", new File("./temp")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1497:                    tempFile.deleteOnExit();
1498:                    fos = new FileOutputStream(tempFile);
1499:                    inputStream = zipFile
1500:                            .getInputStream(jfreereportTemplateEntry);
1501:                    numRead = 0;
1502:                    while ((numRead = inputStream.read(bytes)) != -1) {
1503:                        if (numRead > 0) {
1504:                            fos.write(bytes, 0, numRead);
1505:                        }
1506:                    }
1507:                    fos.close();
1508:                    reportSpec.setTemplateSrc(tempFile.getAbsolutePath());
1509:                    // merge parser-config properties into report-spec (so we have defaults to work with)
1510:                    FieldMapping[] fieldMappings = reportSpec.getFieldMapping();
1511:                    List parserConfigElements = ReportSpecUtility
1512:                            .getParserConfigElements(reportSpec
1513:                                    .getTemplateSrc());
1514:                    reportSpec.removeAllFieldMapping();
1515:                    for (int i = 0; i < parserConfigElements.size(); i++) {
1516:                        Element property = (Element) parserConfigElements
1517:                                .get(i);
1518:                        Node commentNode = property
1519:                                .selectSingleNode("comment()"); //$NON-NLS-1$
1520:                        FieldMapping fm = new FieldMapping();
1521:                        fm.setKey(property.attributeValue("name")); //$NON-NLS-1$
1522:                        fm.setValue(property.getText());
1523:                        if (commentNode != null) {
1524:                            String type = commentNode.getText().trim();
1525:                            fm.setType(type);
1526:                        }
1527:                        boolean mapExists = false;
1528:                        for (int j = 0; fieldMappings != null
1529:                                && j < fieldMappings.length; j++) {
1530:                            FieldMapping fmtmp = fieldMappings[j];
1531:                            if (fmtmp.getKey().equals(fm.getKey())) {
1532:                                // we already have a fieldMapping, use value from report-spec not template
1533:                                mapExists = true;
1534:                                break;
1535:                            }
1536:                        }
1537:                        if (!mapExists) {
1538:                            // create one, add it
1539:                            reportSpec.addFieldMapping(fm);
1540:                        }
1541:                    }
1542:                    ZipEntry xqueryDataEntry = zipFile.getEntry("data.xml"); //$NON-NLS-1$
1543:                    if (xqueryDataEntry != null) {
1544:                        tempFile = File.createTempFile(
1545:                                "data", ".xml", new File("./temp")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1546:                        tempFile.deleteOnExit();
1547:                        fos = new FileOutputStream(tempFile);
1548:                        inputStream = zipFile.getInputStream(xqueryDataEntry);
1549:                        numRead = 0;
1550:                        while ((numRead = inputStream.read(bytes)) != -1) {
1551:                            if (numRead > 0) {
1552:                                fos.write(bytes, 0, numRead);
1553:                            }
1554:                        }
1555:                        reportSpec.getReportSpecChoice().setXqueryUrl(
1556:                                tempFile.getAbsolutePath());
1557:                        fos.close();
1558:                    }
1559:                    Enumeration entries = zipFile.entries();
1560:                    templateImageMap.clear();
1561:                    if (entries != null) {
1562:                        while (entries.hasMoreElements()) {
1563:                            ZipEntry entry = (ZipEntry) entries.nextElement();
1564:                            if (!entry.isDirectory()
1565:                                    && entry.getName().startsWith("images/")) { //$NON-NLS-1$
1566:                                tempFile = File.createTempFile(entry.getName()
1567:                                        .substring(
1568:                                                entry.getName().indexOf('/'),
1569:                                                entry.getName().indexOf('.')),
1570:                                        entry.getName().substring(
1571:                                                entry.getName().indexOf('.')),
1572:                                        new File("./temp")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1573:                                tempFile.deleteOnExit();
1574:                                fos = new FileOutputStream(tempFile);
1575:                                inputStream = zipFile.getInputStream(entry);
1576:                                numRead = 0;
1577:                                if (entry.getName().indexOf("watermark") != -1) { //$NON-NLS-1$
1578:                                    String watermarkFileName = tempFile
1579:                                            .getCanonicalPath();
1580:                                    // update watermark
1581:                                    Watermark wm = reportSpec.getWatermark();
1582:                                    if (wm == null) {
1583:                                        wm = new Watermark();
1584:                                    }
1585:                                    wm.setSrc(watermarkFileName);
1586:                                    reportSpec.setWatermark(wm);
1587:                                }
1588:                                while ((numRead = inputStream.read(bytes)) != -1) {
1589:                                    if (numRead > 0) {
1590:                                        fos.write(bytes, 0, numRead);
1591:                                    }
1592:                                }
1593:                                // map original name to new name
1594:                                templateImageMap
1595:                                        .put(
1596:                                                entry.getName(),
1597:                                                "file://" + tempFile.getCanonicalPath().replace('\\', '/')); //$NON-NLS-1$
1598:                                fos.close();
1599:                            }
1600:                        }
1601:                    }
1602:                    // update jfreereport xml definition with new image paths
1603:                    updateJFreeReportImages(reportSpec.getTemplateSrc(),
1604:                            templateImageMap);
1605:                    zipFile.close();
1606:                    // reconcile reportSpec with query (JDBC)
1607:                    reconcileReportSpec(reportSpec);
1608:                    if (fireInitializations) {
1609:                        initWizardPanels(wizardManager.getCurrentStep());
1610:                    }
1611:                    isSaved = true;
1612:                    if (saveItem != null) {
1613:                        saveItem.setEnabled(isSaved);
1614:                    }
1615:                } catch (Exception e) {
1616:                    e.printStackTrace();
1617:                }
1618:                templateZipPath = path;
1619:            }
1620:
1621:            public void updateJFreeReportImages(String templateSrc,
1622:                    HashMap templateImageMap) {
1623:                // read in templateSrc
1624:                try {
1625:                    FileInputStream inputStream = new FileInputStream(
1626:                            templateSrc);
1627:                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
1628:                    byte bytes[] = new byte[1024];
1629:                    int numRead = 0;
1630:                    while ((numRead = inputStream.read(bytes)) != -1) {
1631:                        if (numRead > 0) {
1632:                            baos.write(bytes, 0, numRead);
1633:                        }
1634:                    }
1635:                    String templateStr = baos.toString();
1636:                    Iterator keys = templateImageMap.keySet().iterator();
1637:                    // replace all references to the keys with the templateImageMaps values in the JFreeReport XML
1638:                    while (keys.hasNext()) {
1639:                        String key = (String) keys.next();
1640:                        String value = (String) templateImageMap.get(key);
1641:                        templateStr = templateStr.replaceAll(key, value);
1642:                    }
1643:                    inputStream.close();
1644:                    FileOutputStream fos = new FileOutputStream(templateSrc);
1645:                    fos.write(templateStr.getBytes());
1646:                    fos.close();
1647:                } catch (Exception e) {
1648:                    e.printStackTrace();
1649:                }
1650:            }
1651:
1652:            public void doOpen(final String path, final boolean setStep,
1653:                    final boolean fireInitialization) {
1654:                try {
1655:                    // clear all settings
1656:                    doNew(setStep, fireInitialization);
1657:                    reportSpecFilePath = path;
1658:                    isSaved = true;
1659:                    if (ReportWizard.applicationMode == ReportWizard.MODE_APPLICATION) {
1660:                        saveItem.setEnabled(isSaved);
1661:                    }
1662:                    Runnable r = new Runnable() {
1663:                        public void run() {
1664:                            boolean isZIPReportSpec = false;
1665:                            try {
1666:                                ZipFile zipFile = new ZipFile(
1667:                                        reportSpecFilePath);
1668:                                if (zipFile
1669:                                        .getEntry("jfreereport-template.xml") != null) { //$NON-NLS-1$
1670:                                    doOpenTemplate(path, setStep,
1671:                                            fireInitialization);
1672:                                    return;
1673:                                }
1674:                                ZipEntry reportSpecEntry = zipFile
1675:                                        .getEntry("report.xreportspec"); //$NON-NLS-1$          
1676:                                File tempFile = File
1677:                                        .createTempFile(
1678:                                                "report", ".xreportspec", new File(workingDir + "/temp")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1679:                                tempFile.deleteOnExit();
1680:                                FileOutputStream fos = new FileOutputStream(
1681:                                        tempFile);
1682:                                InputStream inputStream = zipFile
1683:                                        .getInputStream(reportSpecEntry);
1684:                                int numRead = 0;
1685:                                byte bytes[] = new byte[16384];
1686:                                while ((numRead = inputStream.read(bytes)) != -1) {
1687:                                    if (numRead > 0) {
1688:                                        fos.write(bytes, 0, numRead);
1689:                                    }
1690:                                }
1691:                                fos.close();
1692:                                reportSpec = (ReportSpec) CastorUtility
1693:                                        .getInstance().readCastorObject(
1694:                                                tempFile.getAbsolutePath(),
1695:                                                ReportSpec.class);
1696:                                isZIPReportSpec = true;
1697:                            } catch (Exception e) {
1698:                                // e.printStackTrace(System.err);
1699:                            }
1700:                            if (!isZIPReportSpec) {
1701:                                if (reportSpecFilePath != null) {
1702:                                    reportSpec = (ReportSpec) CastorUtility
1703:                                            .getInstance().readCastorObject(
1704:                                                    reportSpecFilePath,
1705:                                                    ReportSpec.class);
1706:                                }
1707:                            }
1708:                            try {
1709:                                if (startupQuery != null) {
1710:                                    reportSpec.setQuery(startupQuery);
1711:                                }
1712:                                startupQuery = null;
1713:                                if (reportSpec.getReportSpecChoice() != null) {
1714:                                    if (reportSpec.getReportSpecChoice()
1715:                                            .getJndiSource() != null) {
1716:                                        setPentahoConnection(ConnectionUtility
1717:                                                .getConnection(
1718:                                                        reportSpec
1719:                                                                .getReportSpecChoice()
1720:                                                                .getJndiSource(),
1721:                                                        reportSpec
1722:                                                                .getMondrianCubeDefinitionPath(),
1723:                                                        reportSpec
1724:                                                                .getMondrianCubeDefinitionPath() == null ? IPentahoConnection.SQL_DATASOURCE
1725:                                                                : IPentahoConnection.MDX_DATASOURCE));
1726:                                    } else if (reportSpec.getReportSpecChoice()
1727:                                            .getXqueryUrl() != null
1728:                                            && !reportSpec
1729:                                                    .getReportSpecChoice()
1730:                                                    .getXqueryUrl().equals("")) { //$NON-NLS-1$
1731:                                        setPentahoConnection(ConnectionUtility
1732:                                                .getConnection(
1733:                                                        reportSpec
1734:                                                                .getReportSpecChoice()
1735:                                                                .getXqueryUrl(),
1736:                                                        null,
1737:                                                        IPentahoConnection.XML_DATASOURCE));
1738:                                    }
1739:                                } else if (reportSpec.getIsMQL()) {
1740:                                    CWMStartup.loadMetadata(reportSpec
1741:                                            .getXmiPath(), "samples");
1742:                                    setPentahoConnection(ConnectionUtility
1743:                                            .getMQLConnection(reportSpec));
1744:                                }
1745:                                if (reportSpec != null) {
1746:                                    List groups = new ArrayList();
1747:                                    List details = new ArrayList();
1748:                                    Field fields[] = reportSpec.getField();
1749:                                    String columns[] = new String[fields.length];
1750:                                    for (int i = 0; i < fields.length; i++) {
1751:                                        Field field = fields[i];
1752:                                        columns[i] = field.getName();
1753:                                        getTypeMap().put(field.getName(),
1754:                                                new Integer(field.getType()));
1755:                                        if (field.getIsDetail()) {
1756:                                            details.add(field.getName());
1757:                                        } else {
1758:                                            groups.add(field.getName());
1759:                                        }
1760:                                    }
1761:                                }
1762:                                reportSpec.setTemplateSrc(null);
1763:                                if (fireInitialization) {
1764:                                    initWizardPanels(wizardManager
1765:                                            .getCurrentStep());
1766:                                }
1767:                            } catch (Exception e) {
1768:                                e.printStackTrace(System.err);
1769:                                MessageBox mb = new MessageBox(parentContainer
1770:                                        .getShell(), SWT.OK);
1771:                                mb
1772:                                        .setMessage(Messages
1773:                                                .getString("ReportWizard.ERROR_0002_OPEN_REPORT_FAILED") + e.toString()); //$NON-NLS-1$
1774:                                mb.setText(Messages
1775:                                        .getString("ReportWizard.USER_ERROR")); //$NON-NLS-1$
1776:                                mb.open();
1777:                            }
1778:                        }
1779:                    };
1780:                    if (setStep) {
1781:                        handleTabSelection(TAB_TEMPLATE, true);
1782:                    }
1783:                    BusyIndicator.showWhile(display, r);
1784:                } catch (Exception e) {
1785:                    e.printStackTrace(System.err);
1786:                }
1787:            }
1788:
1789:            public void reconcileReportSpec(ReportSpec reportSpec) {
1790:                Object[] cols = null;
1791:                if (reportSpec.getReportSpecChoice() != null) {
1792:                    try {
1793:                        if (reportSpec.getReportSpecChoice().getJndiSource() != null) {
1794:                            if (reportSpec.getIsMDX()) {
1795:                                setPentahoConnection(ConnectionUtility
1796:                                        .getConnection(
1797:                                                reportSpec
1798:                                                        .getReportSpecChoice()
1799:                                                        .getJndiSource(),
1800:                                                reportSpec
1801:                                                        .getMondrianCubeDefinitionPath(),
1802:                                                IPentahoConnection.MDX_DATASOURCE));
1803:                                IPentahoConnection connection = getPentahoConnection();
1804:                                cols = ConnectionUtility.getColumns(connection,
1805:                                        reportSpec.getQuery(), reportSpec
1806:                                                .getReportSpecChoice()
1807:                                                .getXqueryUrl());
1808:                            } else {
1809:                                setPentahoConnection(ConnectionUtility
1810:                                        .getConnection(reportSpec
1811:                                                .getReportSpecChoice()
1812:                                                .getJndiSource()));
1813:                                IPentahoConnection connection = getPentahoConnection();
1814:                                cols = ConnectionUtility.getColumns(connection,
1815:                                        reportSpec.getQuery(), reportSpec
1816:                                                .getReportSpecChoice()
1817:                                                .getXqueryUrl());
1818:                            }
1819:                        } else if (reportSpec.getReportSpecChoice()
1820:                                .getKettleUrl() != null) {
1821:                            setPentahoConnection(null);
1822:                            cols = ConnectionUtility.getKettleColumns(
1823:                                    reportSpec, reportSpec
1824:                                            .getReportSpecChoice()
1825:                                            .getKettleUrl());
1826:                        } else {
1827:                            setPentahoConnection(ConnectionUtility
1828:                                    .getConnection(reportSpec
1829:                                            .getReportSpecChoice()
1830:                                            .getXqueryUrl(), null,
1831:                                            IPentahoConnection.XML_DATASOURCE));
1832:                            IPentahoConnection connection = getPentahoConnection();
1833:                            cols = ConnectionUtility.getColumns(connection,
1834:                                    reportSpec.getQuery(), reportSpec
1835:                                            .getReportSpecChoice()
1836:                                            .getXqueryUrl());
1837:                        }
1838:                    } catch (Exception ex) {
1839:                        MessageBox mb = new MessageBox(parentContainer
1840:                                .getShell(), SWT.OK);
1841:                        mb.setMessage(ex.getMessage());
1842:                        mb.setText("Error");
1843:                        mb.open();
1844:                    }
1845:                }
1846:                if (cols == null) {
1847:                    return;
1848:                }
1849:                // if columns from the query perfectly match the reportSpec, prompt to ask
1850:                // if to overwrite
1851:                boolean perfectMatch = reportSpec.getFieldCount() > 0;
1852:                for (int i = 0; i < reportSpec.getFieldCount(); i++) {
1853:                    Field f = reportSpec.getField(i);
1854:                    boolean found = false;
1855:                    for (int j = 0; j < cols.length; j++) {
1856:                        if (f.getName().equalsIgnoreCase(cols[j].toString())) {
1857:                            found = true;
1858:                        }
1859:                    }
1860:                    if (!found) {
1861:                        perfectMatch = false;
1862:                        break;
1863:                    }
1864:                }
1865:                if (!perfectMatch && reportSpec.getFieldCount() > 0) {
1866:                    // prompt
1867:                    MessageBox mb = new MessageBox(parentContainer.getShell(),
1868:                            SWT.YES | SWT.NO);
1869:                    mb.setText(Messages.getString("ReportWizard.14")); //$NON-NLS-1$
1870:                    mb.setMessage(Messages.getString("ReportWizard.15")); //$NON-NLS-1$
1871:                    int openStatus = mb.open();
1872:                    if (openStatus == SWT.NO) {
1873:                        return;
1874:                    }
1875:                    updateFields(reportSpec, cols);
1876:                } else if (reportSpec.getFieldCount() == 0) {
1877:                    updateFields(reportSpec, cols);
1878:                }
1879:            }
1880:
1881:            public void updateFields(ReportSpec reportSpec, Object[] cols) {
1882:                reportSpec.removeAllField();
1883:                IPentahoResultSet resultSet = ((IPentahoResultSet) ConnectionUtility.queryResultSetMap
1884:                        .get(reportSpec.getQuery()));
1885:                try {
1886:                    resultSet.beforeFirst();
1887:                } catch (Exception e) {
1888:                    e.printStackTrace();
1889:                }
1890:                Object[][] rowHeaders = resultSet.getMetaData().getRowHeaders();
1891:                if (rowHeaders != null) {
1892:                    for (int x = 0; x < rowHeaders[0].length - 1; x++) {
1893:                        // System.out.println("[" + 0 + "][" + x + "] = " + rowHeaders[0][x]);
1894:                        Field f = new Field();
1895:                        f
1896:                                .setName(Messages.getString("QueryPanel.51") + (x + 1)); //$NON-NLS-1$
1897:                        if (resultSet.getMetaData() instanceof  MDXMetaData) {
1898:                            f.setName(((MDXMetaData) resultSet.getMetaData())
1899:                                    .getColumnName(x));
1900:                        }
1901:                        f.setDisplayName(f.getName());
1902:                        f.setIsDetail(true);
1903:                        f.setHorizontalAlignment("left"); //$NON-NLS-1$
1904:                        f.setType(Types.VARCHAR);
1905:                        f.setIsRowHeader(true);
1906:                        f.setUseItemHide(true);
1907:                        getTypeMap().put(f.getName(),
1908:                                new Integer(Types.VARCHAR));
1909:                        reportSpec.addField(f);
1910:                    }
1911:                }
1912:                String columns[] = null;
1913:                if (cols != null) {
1914:                    columns = new String[cols.length];
1915:                    for (int i = 0; i < cols.length; i++) {
1916:                        columns[i] = (String) cols[i];
1917:                        Field f = new Field();
1918:                        f.setName(columns[i]);
1919:                        f.setDisplayName(columns[i]);
1920:                        f.setIsDetail(true);
1921:                        f.setHorizontalAlignment("left"); //$NON-NLS-1$
1922:                        f.setType(Types.VARCHAR);
1923:                        f.setIsRowHeader(false);
1924:                        getTypeMap().put(f.getName(),
1925:                                new Integer(Types.VARCHAR));
1926:                        reportSpec.addField(f);
1927:                    }
1928:                }
1929:                Object row[] = resultSet.next();
1930:                if (row == null) {
1931:                    ConnectionUtility.queryResultSetMap.clear();
1932:                    return;
1933:                }
1934:                for (int i = 0; i < row.length; i++) {
1935:                    // System.out.println("row[" + i + "] value = " + row[i] + " == type = " +
1936:                    // row[i].getClass().getName());
1937:                    if (row[i] instanceof  String) {
1938:                        getTypeMap()
1939:                                .put(columns[i], new Integer(Types.VARCHAR));
1940:                        Field f = ReportSpecUtility.getField(reportSpec
1941:                                .getField(), columns[i], true);
1942:                        f.setType(Types.VARCHAR);
1943:                        f.setHorizontalAlignment("left"); //$NON-NLS-1$
1944:                    } else if (row[i] instanceof  BigDecimal
1945:                            || row[i] instanceof  Integer
1946:                            || row[i] instanceof  Double
1947:                            || row[i] instanceof  Long) {
1948:                        getTypeMap()
1949:                                .put(columns[i], new Integer(Types.NUMERIC));
1950:                        Field f = ReportSpecUtility.getField(reportSpec
1951:                                .getField(), columns[i], true);
1952:                        f.setType(Types.NUMERIC);
1953:                        f.setUseItemHide(false);
1954:                        f.setHorizontalAlignment("right"); //$NON-NLS-1$
1955:                        f.setExpression(defaultNumericFunction); //$NON-NLS-1$
1956:                    } else if (row[i] instanceof  Date
1957:                            || row[i] instanceof  Timestamp) {
1958:                        getTypeMap().put(columns[i], new Integer(Types.DATE));
1959:                        Field f = ReportSpecUtility.getField(reportSpec
1960:                                .getField(), columns[i], true);
1961:                        f.setUseItemHide(false);
1962:                        f.setType(Types.DATE);
1963:                    }
1964:                }
1965:            }
1966:
1967:            public void initWizardPanels(WizardPanel source) {
1968:                if (source == null) {
1969:                    templatePanel.initWizardPanel(reportSpec);
1970:                    queryPanel.initWizardPanel(reportSpec);
1971:                    // mappingPanel.initWizardPanel(reportSpec);
1972:                    fieldSetupPanel.initWizardPanel(reportSpec);
1973:                    // pageSetupPanel.initWizardPanel(reportSpec);
1974:                    // reportSetupPanel.initWizardPanel(reportSpec);
1975:                    groupAndDetailPanel.initWizardPanel(reportSpec);
1976:                } else if (source == templatePanel) {
1977:                    // init everything after templatepanel
1978:                    queryPanel.initWizardPanel(reportSpec);
1979:                    // mappingPanel.initWizardPanel(reportSpec);
1980:                    fieldSetupPanel.initWizardPanel(reportSpec);
1981:                    // pageSetupPanel.initWizardPanel(reportSpec);
1982:                    // reportSetupPanel.initWizardPanel(reportSpec);
1983:                    groupAndDetailPanel.initWizardPanel(reportSpec);
1984:                } else if (source == queryPanel) {
1985:                    // init everything after querypanel
1986:                    // mappingPanel.initWizardPanel(reportSpec);
1987:                    fieldSetupPanel.initWizardPanel(reportSpec);
1988:                    // pageSetupPanel.initWizardPanel(reportSpec);
1989:                    // reportSetupPanel.initWizardPanel(reportSpec);
1990:                    groupAndDetailPanel.initWizardPanel(reportSpec);
1991:                    // } else if (source == mappingPanel) {
1992:                    // init everything after mappingPanel
1993:                    // fieldSetupPanel.initWizardPanel(reportSpec);
1994:                    // pageSetupPanel.initWizardPanel(reportSpec);
1995:                    // reportSetupPanel.initWizardPanel(reportSpec);
1996:                    // groupAndDetailPanel.initWizardPanel(reportSpec);
1997:                } else if (source == groupAndDetailPanel) {
1998:                    fieldSetupPanel.initWizardPanel(reportSpec);
1999:                } else if (source == fieldSetupPanel) {
2000:                    // pageSetupPanel.initWizardPanel(reportSpec);
2001:                    // reportSetupPanel.initWizardPanel(reportSpec);
2002:                    groupAndDetailPanel.initWizardPanel(reportSpec);
2003:                    // } else if (source == pageSetupPanel) {
2004:                    // reportSetupPanel.initWizardPanel(reportSpec);
2005:                    // groupAndDetailPanel.initWizardPanel(reportSpec);
2006:                    // } else if (source == reportSetupPanel) {
2007:                    // groupAndDetailPanel.initWizardPanel(reportSpec);
2008:                }
2009:                wizardManager.update();
2010:            }
2011:
2012:            public void doOpen() {
2013:                FileDialog dialog = new FileDialog(parentContainer.getShell(),
2014:                        SWT.OPEN);
2015:                dialog
2016:                        .setFilterNames(new String[] {
2017:                                Messages
2018:                                        .getString("ReportWizard.USER_REPORT_SPEC_DOCUMENTS"), Messages.getString("ReportWizard.USER_ALL_XML_FILES"), Messages.getString("ReportWizard.USER_TEMPLATE_DOCUMENTS") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
2019:                dialog.setFilterExtensions(SWTUtility.REPORT_SPEC_FILTERS);
2020:                dialog.setFilterPath(browseFolder);
2021:                String openFileName = dialog.open();
2022:                if (openFileName != null) {
2023:                    reportSpecFilePath = openFileName;
2024:                    doOpen(reportSpecFilePath, true, true);
2025:                }
2026:            }
2027:
2028:            public void doSave() {
2029:                if (reportSpecStartupFilePath != null
2030:                        && !reportSpecStartupFilePath.equalsIgnoreCase("")) { //$NON-NLS-1$
2031:                    reportSpecFilePath = reportSpecStartupFilePath;
2032:                }
2033:                if (reportSpecFilePath != null) {
2034:                    if (reportSpec.getTemplateSrc() != null) {
2035:                        // handle template save
2036:                        try {
2037:                            byte data[] = new byte[16384];
2038:                            // write reportSpec out
2039:                            File tempFile = File
2040:                                    .createTempFile(
2041:                                            "report", ".xreportarc", new File(workingDir + "/temp")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
2042:                            CastorUtility.getInstance().writeCastorObject(
2043:                                    reportSpec, tempFile.getAbsolutePath());
2044:                            ZipFile zipFile = new ZipFile(templateZipPath);
2045:                            File reportSpecFile = new File(reportSpecFilePath);
2046:                            reportSpecFile.delete();
2047:                            Enumeration zipEnum = zipFile.entries();
2048:                            FileOutputStream dest = new FileOutputStream(
2049:                                    reportSpecFilePath);
2050:                            ZipOutputStream out = new ZipOutputStream(
2051:                                    new BufferedOutputStream(dest));
2052:                            while (zipEnum.hasMoreElements()) {
2053:                                ZipEntry zipEntry = (ZipEntry) zipEnum
2054:                                        .nextElement();
2055:                                if (!zipEntry.getName().equals(
2056:                                        "report.xreportspec")) { //$NON-NLS-1$
2057:                                    InputStream is = zipFile
2058:                                            .getInputStream(zipEntry);
2059:                                    int count = 0;
2060:                                    ZipEntry newEntry = new ZipEntry(zipEntry
2061:                                            .getName());
2062:                                    out.putNextEntry(newEntry);
2063:                                    while ((count = is.read(data)) != -1) {
2064:                                        out.write(data, 0, count);
2065:                                    }
2066:                                }
2067:                            }
2068:                            ZipEntry reportSpecEntry = new ZipEntry(
2069:                                    "report.xreportspec"); //$NON-NLS-1$
2070:                            out.putNextEntry(reportSpecEntry);
2071:                            int count = 0;
2072:                            FileInputStream fi = new FileInputStream(tempFile);
2073:                            BufferedInputStream origin = new BufferedInputStream(
2074:                                    fi, 16384);
2075:                            while ((count = origin.read(data)) != -1) {
2076:                                out.write(data, 0, count);
2077:                            }
2078:                            origin.close();
2079:                            out.close();
2080:                        } catch (Exception ex) {
2081:                            ex.printStackTrace();
2082:                        }
2083:                    } else {
2084:                        try {
2085:                            File tempFile = File
2086:                                    .createTempFile(
2087:                                            "report", ".xreportspec", new File(workingDir + "/temp")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
2088:                            // create reportSpec if needed
2089:                            if (reportSpec == null) {
2090:                                reportSpec = createReportSpec();
2091:                            }
2092:                            // write reportSpec out
2093:                            CastorUtility.getInstance().writeCastorObject(
2094:                                    reportSpec, tempFile.getAbsolutePath());
2095:                            // create 'zip' of reportspec
2096:                            FileOutputStream dest = new FileOutputStream(
2097:                                    reportSpecFilePath);
2098:                            ZipOutputStream out = new ZipOutputStream(
2099:                                    new BufferedOutputStream(dest));
2100:                            byte data[] = new byte[16384];
2101:                            // get a list of files from current directory
2102:                            FileInputStream fi = new FileInputStream(tempFile);
2103:                            BufferedInputStream origin = new BufferedInputStream(
2104:                                    fi, 16384);
2105:                            ZipEntry reportSpecEntry = new ZipEntry(
2106:                                    "report.xreportspec"); //$NON-NLS-1$
2107:                            out.putNextEntry(reportSpecEntry);
2108:                            int count = 0;
2109:                            while ((count = origin.read(data)) != -1) {
2110:                                out.write(data, 0, count);
2111:                            }
2112:                            origin.close();
2113:                            out.close();
2114:                        } catch (Exception ex) {
2115:                            ex.printStackTrace();
2116:                        }
2117:                    }
2118:                }
2119:                isSaved = true;
2120:                if (saveItem != null) {
2121:                    saveItem.setEnabled(isSaved);
2122:                }
2123:            }
2124:
2125:            public void doSaveAs(String filePath) {
2126:                reportSpecFilePath = filePath;
2127:                doSave();
2128:            }
2129:
2130:            public void doSaveAs() {
2131:                FileDialog dialog = new FileDialog(parentContainer.getShell(),
2132:                        SWT.SAVE);
2133:                dialog
2134:                        .setFilterNames(new String[] {
2135:                                Messages
2136:                                        .getString("ReportWizard.USER_REPORT_SPEC_DOCUMENTS"), Messages.getString("ReportWizard.USER_ALL_XML_FILES") }); //$NON-NLS-1$ //$NON-NLS-2$
2137:                dialog.setFilterExtensions(SWTUtility.REPORT_SPEC_FILTERS); // Windows
2138:                dialog.setFilterPath(browseFolder);
2139:                reportSpecFilePath = dialog.open();
2140:                if (reportSpecFilePath != null
2141:                        && !reportSpecFilePath.endsWith(".xreportspec")) {
2142:                    reportSpecFilePath += ".xreportspec";
2143:                }
2144:                doSave();
2145:            }
2146:
2147:            public boolean generateReportOutput(ReportSpec spec,
2148:                    String jfreeReportOutputPath, final String outputType,
2149:                    boolean execute) {
2150:                boolean status = true;
2151:                try {
2152:                    String solutionRootPath = PentahoUtility.getSolutionRoot();
2153:                    String solution = "samples"; //$NON-NLS-1$
2154:                    String path = "reporting"; //$NON-NLS-1$
2155:                    String query = spec.getQuery();
2156:                    if (spec.getIsMQL()) {
2157:                        query = spec.getMqlQuery();
2158:                    }
2159:                    String jndiSource = null;
2160:                    String xQuerySource = null;
2161:                    String kettleSource = null;
2162:                    if (spec.getReportSpecChoice() != null) {
2163:                        jndiSource = spec.getReportSpecChoice().getJndiSource();
2164:                        xQuerySource = spec.getReportSpecChoice()
2165:                                .getXqueryUrl();
2166:                        kettleSource = spec.getReportSpecChoice()
2167:                                .getKettleUrl();
2168:                    }
2169:                    String driver = null;
2170:                    String connectInfo = null;
2171:                    String username = null;
2172:                    String password = null;
2173:                    if (jndiSource != null && !"".equals(jndiSource)) { //$NON-NLS-1$
2174:                        DataSourceInfo info = dataSourceAdmin
2175:                                .getDataSourceInfo(jndiSource);
2176:                        driver = info.getDriver();
2177:                        connectInfo = info.getUrl();
2178:                        username = info.getUserId();
2179:                        password = info.getPassword();
2180:                    }
2181:                    String actionSequenceTemplateName = "JFree_template.xaction"; //$NON-NLS-1$
2182:                    if (xQuerySource != null && !"".equals(xQuerySource)) { //$NON-NLS-1$
2183:                        actionSequenceTemplateName = "JFree_XQuery_template.xaction"; //$NON-NLS-1$
2184:                    } else if (kettleSource != null && !"".equals(kettleSource)) {
2185:                        actionSequenceTemplateName = "JFree_KettleTransformation.xaction"; //$NON-NLS-1$
2186:                    } else if (reportSpec.getIsMDX()) {
2187:                        actionSequenceTemplateName = "JFree_Mondrian_template.xaction"; //$NON-NLS-1$
2188:                    } else if (reportSpec.getIsMQL()) {
2189:                        actionSequenceTemplateName = "JFree_MQL_template.xaction"; //$NON-NLS-1$
2190:                    }
2191:                    String actionSequenceName = spec.getReportName()
2192:                            + ".xaction"; //$NON-NLS-1$
2193:                    String actionSeqDocPath = solutionRootPath
2194:                            + "/" + solution + "/" + path + "/"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
2195:                    String actionSeqDocInput = actionSeqDocPath
2196:                            + actionSequenceTemplateName;
2197:                    String actionSeqDocOutput = actionSeqDocPath
2198:                            + actionSequenceName;
2199:                    if (reportSpec.getWatermark() != null
2200:                            && !StringUtils.isEmpty(reportSpec.getWatermark()
2201:                                    .getSrc())) {
2202:                        String waterMarkSrc = new File(reportSpec
2203:                                .getWatermark().getSrc()).getName();
2204:                        String watermarkFileName = actionSeqDocPath
2205:                                + "/" + waterMarkSrc; //$NON-NLS-1$ //$NON-NLS-2$
2206:                        ReportSpecUtility.copyFile(reportSpec.getWatermark()
2207:                                .getSrc(), watermarkFileName);
2208:                    }
2209:                    String xactionPropertiesDestination = actionSeqDocPath
2210:                            + reportSpec.getReportName() + ".properties"; //$NON-NLS-1$
2211:                    FileOutputStream propertyFileOutputStream = new FileOutputStream(
2212:                            xactionPropertiesDestination);
2213:                    String nameProp = "title=" + reportSpec.getReportName() + "\r\n"; //$NON-NLS-1$ //$NON-NLS-2$
2214:                    String descProp = "description=" + reportSpec.getReportDesc() + "\r\n"; //$NON-NLS-1$ //$NON-NLS-2$
2215:                    propertyFileOutputStream.write(nameProp.getBytes());
2216:                    propertyFileOutputStream.write(descProp.getBytes());
2217:                    propertyFileOutputStream.flush();
2218:                    propertyFileOutputStream.close();
2219:                    if (!execute) {
2220:                        if (xQuerySource != null && !"".equals(xQuerySource)) { //$NON-NLS-1$
2221:                            // copy xQuerySource file to actionSeqDocPath
2222:                            File f = new File(xQuerySource);
2223:                            xQuerySource = f.getName();
2224:                            String xQueryDestFilePath = actionSeqDocPath
2225:                                    + "/" + xQuerySource; //$NON-NLS-1$ //$NON-NLS-2$
2226:                            ReportSpecUtility.copyFile(f.getAbsolutePath(),
2227:                                    xQueryDestFilePath);
2228:                            ActionSequenceUtility.getInstance()
2229:                                    .createXQueryActionSequence(
2230:                                            actionSeqDocInput,
2231:                                            actionSeqDocOutput, outputType,
2232:                                            jfreeReportOutputPath,
2233:                                            xQuerySource, query);
2234:                        } else if (kettleSource != null
2235:                                && !"".equals(kettleSource)) {
2236:                            // copy xQuerySource file to actionSeqDocPath
2237:                            File f = new File(kettleSource);
2238:                            kettleSource = f.getName();
2239:                            String kettleDestFilePath = actionSeqDocPath
2240:                                    + "/" + kettleSource; //$NON-NLS-1$ //$NON-NLS-2$
2241:                            ReportSpecUtility.copyFile(f.getAbsolutePath(),
2242:                                    kettleDestFilePath);
2243:                            ActionSequenceUtility.getInstance()
2244:                                    .createKettleActionSequence(
2245:                                            actionSeqDocInput,
2246:                                            actionSeqDocOutput, kettleSource,
2247:                                            reportSpec.getKettleStep());
2248:                        } else {
2249:                            String source = "sql"; //$NON-NLS-1$
2250:                            if (reportSpec.getIsMDX()) {
2251:                                source = "mdx"; //$NON-NLS-1$
2252:                            } else if (reportSpec.getIsMQL()) {
2253:                                source = "mql"; //$NON-NLS-1$
2254:                            }
2255:                            String cubeDefDestFilePath = null;
2256:                            if (reportSpec.getMondrianCubeDefinitionPath() != null
2257:                                    && !""  .equals(reportSpec.getMondrianCubeDefinitionPath())) { //$NON-NLS-1$
2258:                                // copy mondrian cube definition file to actionSeqDocPath
2259:                                File f = new File(reportSpec
2260:                                        .getMondrianCubeDefinitionPath());
2261:                                String cubeDefPath = f.getName();
2262:                                cubeDefDestFilePath = actionSeqDocPath
2263:                                        + "/" + cubeDefPath; //$NON-NLS-1$ //$NON-NLS-2$
2264:                                ReportSpecUtility.copyFile(f.getAbsolutePath(),
2265:                                        cubeDefDestFilePath);
2266:                            }
2267:                            ActionSequenceUtility
2268:                                    .getInstance()
2269:                                    .createActionSequence(
2270:                                            actionSeqDocInput,
2271:                                            actionSeqDocOutput,
2272:                                            outputType,
2273:                                            jfreeReportOutputPath,
2274:                                            cubeDefDestFilePath,
2275:                                            source,
2276:                                            "true", jndiSource, driver, connectInfo, username, password, query); //$NON-NLS-1$ //$NON-NLS-2$
2277:                        }
2278:                    } else {
2279:                        IPentahoResultSet resultSet = null;
2280:                        try {
2281:                            resultSet = ConnectionUtility.executeQuery(
2282:                                    getPentahoConnection(), reportSpec
2283:                                            .getQuery(), xQuerySource);
2284:                        } catch (Exception e) {
2285:                            MessageBox mb = new MessageBox(parentContainer
2286:                                    .getShell(), SWT.OK);
2287:                            mb.setMessage(e.getMessage());
2288:                            mb.setText("Error");
2289:                            mb.open();
2290:                            return false;
2291:                        }
2292:                        if (resultSet == null || resultSet.getRowCount() == 0) {
2293:                            status = false;
2294:                            PentahoSWTMessageBox mb = new PentahoSWTMessageBox(
2295:                                    "Error", Messages.getString("QueryPanel.40"), 360, 140); //$NON-NLS-1$ //$NON-NLS-2$
2296:                            mb.open();
2297:                        } else {
2298:                            actionSequenceTemplateName = "JFree_ResultSet_template.xaction"; //$NON-NLS-1$
2299:                            actionSequenceName = spec.getReportName()
2300:                                    + ".xaction"; //$NON-NLS-1$
2301:                            actionSeqDocPath = solutionRootPath
2302:                                    + "/" + solution + "/" + path + "/"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
2303:                            actionSeqDocInput = actionSeqDocPath
2304:                                    + actionSequenceTemplateName;
2305:                            actionSeqDocOutput = actionSeqDocPath
2306:                                    + actionSequenceName;
2307:                            ActionSequenceUtility.getInstance()
2308:                                    .createResultSetActionSequence(
2309:                                            actionSeqDocInput,
2310:                                            actionSeqDocOutput, outputType,
2311:                                            jfreeReportOutputPath, resultSet); //$NON-NLS-1$ //$NON-NLS-2$
2312:                            final File generatedReportFile = ActionSequenceUtility
2313:                                    .getInstance().executeActionSequence(
2314:                                            solutionRootPath, solution, path,
2315:                                            actionSequenceName, outputType,
2316:                                            resultSet, this );
2317:                            if (generatedReportFile == null) {
2318:                                display.asyncExec(new Runnable() {
2319:                                    public void run() {
2320:                                        MessageBox messageBox = new MessageBox(
2321:                                                (Shell) container, SWT.NONE);
2322:                                        messageBox
2323:                                                .setMessage(Messages
2324:                                                        .getString("ReportWizard.USER_REPORT_GENEREATE_FAILED")); //$NON-NLS-1$
2325:                                        messageBox
2326:                                                .setText(Messages
2327:                                                        .getString("ReportWizard.USER_ERROR")); //$NON-NLS-1$
2328:                                        messageBox.open();
2329:                                    }
2330:                                });
2331:                            } else {
2332:                                display.asyncExec(new Runnable() {
2333:                                    public void run() {
2334:                                        try {
2335:
2336:                                            if (outputType.equals("html")) {
2337:                                                IOUtils
2338:                                                        .write(
2339:                                                                IOUtils
2340:                                                                        .toString(
2341:                                                                                new FileInputStream(
2342:                                                                                        generatedReportFile))
2343:                                                                        .replaceFirst(
2344:                                                                                "<link type=\"text/css\" rel=\"stylesheet\" href=\"style",
2345:                                                                                "<link type=\"text/css\" rel=\"stylesheet\" href=\""
2346:                                                                                        + PentahoUtility
2347:                                                                                                .getBaseURL()
2348:                                                                                        + "style"),
2349:                                                                new FileOutputStream(
2350:                                                                        generatedReportFile));
2351:                                            }
2352:
2353:                                            String osName = System.getProperty(
2354:                                                    "os.name").toLowerCase(); //$NON-NLS-1$
2355:
2356:                                            boolean isLinux = osName
2357:                                                    .indexOf("linux") >= 0; //$NON-NLS-1$ //$NON-NLS-2$
2358:                                            if (isLinux) {
2359:                                                if (outputType.equals("pdf")) { //$NON-NLS-1$
2360:                                                    try {
2361:                                                        Runtime
2362:                                                                .getRuntime()
2363:                                                                .exec(
2364:                                                                        "acroread " + generatedReportFile.getAbsolutePath()); //$NON-NLS-1$
2365:                                                    } catch (Throwable t) {
2366:                                                        try {
2367:                                                            Runtime
2368:                                                                    .getRuntime()
2369:                                                                    .exec(
2370:                                                                            "evince " + generatedReportFile.getAbsolutePath()); //$NON-NLS-1$
2371:                                                        } catch (Throwable tt) {
2372:                                                        }
2373:                                                    }
2374:                                                } else if (outputType
2375:                                                        .equals("html")) {
2376:                                                    try {
2377:                                                        Runtime
2378:                                                                .getRuntime()
2379:                                                                .exec(
2380:                                                                        "firefox " + generatedReportFile.getAbsolutePath()); //$NON-NLS-1$
2381:                                                    } catch (Throwable t) {
2382:                                                    }
2383:                                                } else {
2384:                                                    try {
2385:                                                        Runtime
2386:                                                                .getRuntime()
2387:                                                                .exec(
2388:                                                                        "oocalc " + generatedReportFile.getAbsolutePath()); //$NON-NLS-1$
2389:                                                    } catch (Throwable t) {
2390:                                                    }
2391:                                                }
2392:                                                if (detachedPreviewShell != null
2393:                                                        && !detachedPreviewShell
2394:                                                                .isDisposed()) {
2395:                                                    detachedPreviewShell
2396:                                                            .close();
2397:                                                    detachedPreviewShell
2398:                                                            .dispose();
2399:                                                }
2400:                                            } else if (osName
2401:                                                    .equals("mac os x")) { //$NON-NLS-1$
2402:                                                Runtime
2403:                                                        .getRuntime()
2404:                                                        .exec(
2405:                                                                "open " + generatedReportFile.getAbsolutePath()); //$NON-NLS-1$
2406:                                                if (detachedPreviewShell != null
2407:                                                        && !detachedPreviewShell
2408:                                                                .isDisposed()) {
2409:                                                    detachedPreviewShell
2410:                                                            .close();
2411:                                                    detachedPreviewShell
2412:                                                            .dispose();
2413:                                                }
2414:                                            } else {
2415:                                                System.out
2416:                                                        .println(Messages
2417:                                                                .getString("ReportWizard.65") + generatedReportFile.getAbsolutePath()); //$NON-NLS-1$
2418:                                                if (detachedPreviewShell != null
2419:                                                        && !detachedPreviewShell
2420:                                                                .isDisposed()) {
2421:                                                    detachedPreviewShell
2422:                                                            .close();
2423:                                                    detachedPreviewShell
2424:                                                            .dispose();
2425:                                                }
2426:                                                if (outputType.equals("html")) {
2427:                                                    // try {
2428:                                                    // Runtime.getRuntime().exec("cmd /c start firefox.exe " + generatedReportFile.getAbsolutePath()); //$NON-NLS-1$
2429:                                                    // } catch (Throwable t) {
2430:                                                    Runtime
2431:                                                            .getRuntime()
2432:                                                            .exec(
2433:                                                                    "cmd /c start iexplore.exe " + generatedReportFile.getAbsolutePath()); //$NON-NLS-1$
2434:                                                    // }
2435:                                                    // detachPreview();
2436:                                                    // browser.setUrl(generatedReportFile.getAbsolutePath());
2437:                                                    // detachedPreviewShell.moveAbove(null);
2438:                                                } else {
2439:                                                    Runtime
2440:                                                            .getRuntime()
2441:                                                            .exec(
2442:                                                                    "cmd /c start " + generatedReportFile.getAbsolutePath()); //$NON-NLS-1$
2443:                                                }
2444:                                            }
2445:                                        } catch (Exception e) {
2446:                                            e.printStackTrace();
2447:                                        }
2448:                                    }
2449:                                });
2450:                            }
2451:                        }
2452:                    }
2453:                } catch (final Exception e) {
2454:                    e.printStackTrace();
2455:                    display.asyncExec(new Runnable() {
2456:                        public void run() {
2457:                            MessageBox messageBox = new MessageBox(
2458:                                    parentContainer.getShell(), SWT.NONE);
2459:                            messageBox
2460:                                    .setMessage(Messages
2461:                                            .getString("ReportWizard.USER_REPORT_GENEREATE_FAILED") + e.toString()); //$NON-NLS-1$
2462:                            messageBox.setText(Messages
2463:                                    .getString("ReportWizard.USER_ERROR")); //$NON-NLS-1$
2464:                            messageBox.open();
2465:                        }
2466:                    });
2467:                }
2468:                return status;
2469:            }
2470:
2471:            public void actionComplete(IRuntimeContext arg0) {
2472:            }
2473:
2474:            public static void main(String args[]) {
2475:                InputStream iconRes = ReportWizard.class.getClassLoader()
2476:                        .getResourceAsStream("pentaho_icon.ico"); //$NON-NLS-1$
2477:                Image icon = new Image(Display.getDefault(), iconRes);
2478:                SWTUtility.setIcon(icon);
2479:
2480:                Shell shell = SWTUtility
2481:                        .createShell(
2482:                                1024,
2483:                                768,
2484:                                new FillLayout(),
2485:                                Messages
2486:                                        .getString("ReportWizard.USER_PRODUCT_TITLE"), SWT.CLOSE | SWT.MIN | SWT.MAX | SWT.RESIZE); //$NON-NLS-1$
2487:                ReportWizard designer = null;
2488:                if (args.length > 0) {
2489:                    if (args[0].equalsIgnoreCase("file")) { //$NON-NLS-1$
2490:                        designer = new ReportWizard(args[1],
2491:                                args.length == 3 ? args[2] : null,
2492:                                ".", ".", shell, MODE_APPLICATION); //$NON-NLS-1$ //$NON-NLS-2$
2493:                    } else if (args[0].equalsIgnoreCase("query")) { //$NON-NLS-1$
2494:                        designer = new ReportWizard(null, args[1],
2495:                                ".", ".", shell, MODE_APPLICATION); //$NON-NLS-1$ //$NON-NLS-2$
2496:                    }
2497:                } else {
2498:                    designer = new ReportWizard(null, null,
2499:                            ".", ".", shell, MODE_APPLICATION); //$NON-NLS-1$ //$NON-NLS-2$
2500:                }
2501:                if (designer != null) {
2502:                    while (!shell.isDisposed()) {
2503:                        try {
2504:                            if (!shell.getDisplay().readAndDispatch())
2505:                                shell.getDisplay().sleep();
2506:                        } catch (SWTException e) {
2507:                            // probably some stupid DND error, ignore it, we're not disposed, so continue
2508:                        }
2509:                    }
2510:                }
2511:            }
2512:
2513:            public ReportSpec createReportSpec() {
2514:                ReportSpec spec = new ReportSpec();
2515:                return spec;
2516:            }
2517:
2518:            public boolean nextFired(WizardPanel source) {
2519:                if (ignoreWizardEvents) {
2520:                    return true;
2521:                }
2522:                initWizardPanels(source);
2523:                handleTabSelection(currentTabIndex + 1, false);
2524:                // tabFolder.setSelection(tabFolder.getSelectionIndex() + 1);
2525:                return true;
2526:            }
2527:
2528:            public void backFired(WizardPanel source) {
2529:                if (ignoreWizardEvents) {
2530:                    return;
2531:                }
2532:                initWizardPanels(source);
2533:                handleTabSelection(currentTabIndex - 1, false);
2534:                // tabFolder.setSelection(tabFolder.getSelectionIndex() - 1);
2535:            }
2536:
2537:            public boolean previewFired(WizardPanel source) {
2538:                if (ignoreWizardEvents) {
2539:                    return true;
2540:                }
2541:                Cursor cursor = new Cursor(display, SWT.CURSOR_WAIT);
2542:                container.setCursor(cursor);
2543:                // check reportSpec state....
2544:                try {
2545:                    System.out
2546:                            .println(Messages
2547:                                    .getString(
2548:                                            "ReportWizard.DEBUG_WRITING", jfreeReportOutputPath + reportSpec.getReportName() + ".xml")); //$NON-NLS-1$//$NON-NLS-2$
2549:                    // ReportGenerationUtility.createJFreeReportXML(reportSpec, outStream, 0, 0,
2550:                    // false, "", 0, 0); //$NON-NLS-1$
2551:                    // outStream = new FileOutputStream(jfreeReportOutputPath +
2552:                    // reportSpec.getReportName() + ".xml"); //$NON-NLS-1$
2553:                    boolean success = false;
2554:                    if (reportSpec.getTemplateSrc() != null) {
2555:                        FileOutputStream outStream = new FileOutputStream(
2556:                                jfreeReportOutputPath
2557:                                        + reportSpec.getReportName()
2558:                                        + "_generated.xml"); //$NON-NLS-1$
2559:                        ReportGenerationUtility.createJFreeReportXML(
2560:                                reportSpec, outStream, 0, 0, false, "", 0, 0); //$NON-NLS-1$
2561:                        FileOutputStream mergeStream = new FileOutputStream(
2562:                                jfreeReportOutputPath
2563:                                        + reportSpec.getReportName() + ".xml"); //$NON-NLS-1$
2564:                        File templateFile = new File(reportSpec
2565:                                .getTemplateSrc());
2566:                        ReportGenerationUtility.mergeTemplate(templateFile,
2567:                                new File(jfreeReportOutputPath
2568:                                        + reportSpec.getReportName()
2569:                                        + "_generated.xml"), mergeStream); //$NON-NLS-1$
2570:                        success = generateReportOutput(reportSpec,
2571:                                jfreeReportOutputPath
2572:                                        + reportSpec.getReportName() + ".xml",
2573:                                previewType, true);
2574:                    } else {
2575:                        FileOutputStream outStream = new FileOutputStream(
2576:                                jfreeReportOutputPath
2577:                                        + reportSpec.getReportName() + ".xml"); //$NON-NLS-1$
2578:                        ReportGenerationUtility.createJFreeReportXML(
2579:                                reportSpec, outStream, 0, 0, false, "", 0, 0); //$NON-NLS-1$
2580:                        success = generateReportOutput(reportSpec,
2581:                                jfreeReportOutputPath
2582:                                        + reportSpec.getReportName() + ".xml",
2583:                                previewType, true);
2584:                    }
2585:                    if (success) {
2586:                        handlingTab = true;
2587:                        detachPreview();
2588:                        handlingTab = false;
2589:                    }
2590:                    // tabFolder.setSelection(tabPreview);
2591:                } catch (Exception e) {
2592:                    e.printStackTrace();
2593:                } finally {
2594:                    cursor = new Cursor(display, SWT.CURSOR_ARROW);
2595:                    container.setCursor(cursor);
2596:                }
2597:                return true;
2598:            }
2599:
2600:            public void publishFired(WizardPanel source) {
2601:                doPublishReport();
2602:            }
2603:
2604:            public void finishFired(WizardPanel source) {
2605:            }
2606:
2607:            public boolean cancelFired(WizardPanel source) {
2608:                if (ignoreWizardEvents) {
2609:                    return true;
2610:                }
2611:                if (ReportWizard.applicationMode == ReportWizard.MODE_DIALOG) {
2612:                    MessageBox mb = new MessageBox(parentContainer.getShell(),
2613:                            SWT.YES | SWT.NO);
2614:                    mb.setText("Confirm Cancel");
2615:                    mb.setMessage("Are you sure you want to cancel?"); //$NON-NLS-1$
2616:                    if (mb.open() == SWT.YES) {
2617:                        // parentContainer.dispose();
2618:                    } else {
2619:                        return false;
2620:                    }
2621:                }
2622:                if (ReportWizard.applicationMode == ReportWizard.MODE_APPLICATION) {
2623:                    MessageBox mb = new MessageBox(parentContainer.getShell(),
2624:                            SWT.YES | SWT.NO);
2625:                    mb.setText(Messages.getString("ReportWizard.21")); //$NON-NLS-1$
2626:                    mb.setMessage(Messages.getString("ReportWizard.22")); //$NON-NLS-1$
2627:                    if (mb.open() == SWT.YES) {
2628:                        doSaveAs();
2629:                    }
2630:                    container.dispose();
2631:                    System.exit(0);
2632:                }
2633:                return true;
2634:            }
2635:
2636:            /**
2637:             * @return Returns the pentahoConnection.
2638:             */
2639:            public IPentahoConnection getPentahoConnection() {
2640:                return pentahoConnection;
2641:            }
2642:
2643:            /**
2644:             * @param pentahoConnection
2645:             *          The pentahoConnection to set.
2646:             */
2647:            public void setPentahoConnection(
2648:                    IPentahoConnection pentahoConnection) {
2649:                this .pentahoConnection = pentahoConnection;
2650:            }
2651:
2652:            public HashMap getTypeMap() {
2653:                return typeMap;
2654:            }
2655:
2656:            public void setTypeMap(HashMap typeMap) {
2657:                this .typeMap = typeMap;
2658:            }
2659:
2660:            /**
2661:             * @return Returns the reportSpec.
2662:             */
2663:            public ReportSpec getReportSpec() {
2664:                return reportSpec;
2665:            }
2666:
2667:            /**
2668:             * @param reportSpec
2669:             *          The reportSpec to set.
2670:             */
2671:            public void setReportSpec(ReportSpec reportSpec) {
2672:                this .reportSpec = reportSpec;
2673:            }
2674:
2675:            List dirtyListeners = new LinkedList();
2676:
2677:            // only use this method for external use
2678:            public void addDirtyListener(IDirtyListener dirtyListener) {
2679:                dirtyListeners.add(dirtyListener);
2680:            }
2681:
2682:            /*
2683:             * (non-Javadoc)
2684:             * 
2685:             * @see org.pentaho.jfreereport.wizard.IDirtyListener#dirtyFired(boolean)
2686:             */
2687:            public void dirtyFired(boolean dirty) {
2688:                for (int i = 0; i < dirtyListeners.size(); i++) {
2689:                    IDirtyListener dirtyListener = (IDirtyListener) dirtyListeners
2690:                            .get(i);
2691:                    dirtyListener.dirtyFired(dirty);
2692:                }
2693:            }
2694:
2695:            public String getPreviewType() {
2696:                return previewType;
2697:            }
2698:
2699:            public void setPreviewType(String previewType) {
2700:                this.previewType = previewType;
2701:            }
2702:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.