org.pentaho.support.bi.client.BISupportUtility.java Source code

Java tutorial

Introduction

Here is the source code for org.pentaho.support.bi.client.BISupportUtility.java

Source

/*
 * Copyright 2007 Pentaho Corporation. All rights reserved.
 * 
 * This software was developed by Pentaho Corporation and is provided under the terms
 * of the Mozilla Public License, Version 1.1, or any later version. You may not use
 * this file except in compliance with the license. If you need a copy of the license,
 * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
 * BI Platform. The Initial Developer is Pentaho Corporation.
 *
 * Software distributed under the Mozilla Public License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
 * the license for the specific language governing your rights and limitations.
 *
 * Created
 * @author
 * 
 */
package org.pentaho.support.bi.client;

import java.util.ArrayList;
import java.util.List;

import org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox;
import org.pentaho.support.bi.shared.BIConstant;
import org.pentaho.support.bi.shared.BISelectedItem;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.widgetideas.client.ProgressBar;

public class BISupportUtility implements EntryPoint {

    public List<String> selectedItem = null;

    BISelectedItem selectObj = new BISelectedItem();

    private final BISupportUtilityServiceAsync bisupportService = GWT.create(BISupportUtilityService.class);

    AbsolutePanel mainPanel;
    Image bck_img;
    Image logo_img;

    RadioButton rdbtnInstaller;
    RadioButton rdbtnArchive;
    RadioButton rdbtnManual;

    CheckBox selectDselect;

    CheckBox license;
    CheckBox secure;
    CheckBox md5;
    CheckBox running;
    CheckBox environment;
    CheckBox datasource;

    CheckBox logs;
    CheckBox structure;
    CheckBox serverXml;
    CheckBox tomcatXml;
    CheckBox serverbat;
    CheckBox serverProp;

    TextBox browserText;

    Button button;

    MessageDialogBox message = null;

    /**
     * called when module starts
     */
    @Override
    public void onModuleLoad() {
        selectObj.setInstallType("Installer");
        ((ServiceDefTarget) bisupportService).setServiceEntryPoint(getBaseUrl());
        RootPanel panel = RootPanel.get("maincontainer");
        mainPanel = new AbsolutePanel();
        mainPanel.setStyleName("mainPanel");
        panel.add(mainPanel, 0, 0);
        mainPanel.setSize("809px", "565px");

        bck_img = new Image("Images/login-crystal-bg.jpg");
        mainPanel.add(bck_img, 0, 0);
        bck_img.setSize("809px", "565px");

        logo_img = new Image("Images/puc-login-logo.png");
        mainPanel.add(logo_img, 10, 33);
        logo_img.setSize("360px", "93px");

        Label pentahoCustomerSupport = new Label("Pentaho Customer Support Wizard");
        mainPanel.add(pentahoCustomerSupport, 255, 132);
        pentahoCustomerSupport.setStyleName("pentaho-label");

        Label lblSelectInstallationType = new Label("Select Installation Type :");
        lblSelectInstallationType.setStyleName("gwt-Label-header");
        mainPanel.add(lblSelectInstallationType, 47, 184);

        rdbtnInstaller = new RadioButton("type", "Installer");
        rdbtnInstaller.setValue(true);
        rdbtnInstaller.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                selectObj.setInstallType("Installer");
            }
        });
        mainPanel.add(rdbtnInstaller, 196, 225);

        rdbtnArchive = new RadioButton("type", "Archive");
        rdbtnArchive.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                selectObj.setInstallType("Archive");
            }
        });
        mainPanel.add(rdbtnArchive, 353, 225);

        rdbtnManual = new RadioButton("type", "Manual");
        rdbtnManual.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                selectObj.setInstallType("Manual");
            }
        });
        mainPanel.add(rdbtnManual, 504, 225);

        AbsolutePanel absolutePanel = new AbsolutePanel();
        mainPanel.add(absolutePanel, 102, 254);
        absolutePanel.setSize("611px", "201px");

        selectDselect = new CheckBox("Select/De-Select");
        selectDselect.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                onSelectDselect();
            }
        });
        absolutePanel.add(selectDselect, 10, 10);

        VerticalPanel absolutePanel_left = new VerticalPanel();
        absolutePanel.add(absolutePanel_left, 68, 36);
        absolutePanel_left.setSize("200px", "160px");

        license = new CheckBox("License File");
        license.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                checkList();
            }
        });

        secure = new CheckBox("Secure Files");
        secure.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                checkList();
            }
        });

        md5 = new CheckBox("MD5 Hash Value");
        md5.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                checkList();
            }
        });
        running = new CheckBox("Running Process");
        running.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                checkList();
            }
        });

        environment = new CheckBox("Environment");
        environment.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                checkList();
            }
        });

        datasource = new CheckBox("Datasource Details");
        datasource.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                checkList();
            }
        });

        absolutePanel_left.add(license);
        absolutePanel_left.add(secure);
        absolutePanel_left.add(md5);
        absolutePanel_left.add(running);
        absolutePanel_left.add(environment);
        absolutePanel_left.add(datasource);

        VerticalPanel absolutePanel_right = new VerticalPanel();
        absolutePanel.add(absolutePanel_right, 362, 36);
        absolutePanel_right.setSize("200px", "160px");

        logs = new CheckBox("Logs");
        logs.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                checkList();
            }
        });

        structure = new CheckBox("Structure Details");
        structure.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                checkList();
            }
        });

        serverXml = new CheckBox("XML files from Server");
        serverXml.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                checkList();
            }
        });

        tomcatXml = new CheckBox("XML files from Tomcat");
        tomcatXml.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                checkList();
            }
        });

        serverbat = new CheckBox("Start up files from server");
        serverbat.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                checkList();
            }
        });

        serverProp = new CheckBox("Properites files from server");
        serverProp.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                checkList();
            }
        });

        absolutePanel_right.add(logs);
        absolutePanel_right.add(structure);
        absolutePanel_right.add(serverXml);
        absolutePanel_right.add(tomcatXml);
        absolutePanel_right.add(serverbat);
        absolutePanel_right.add(serverProp);

        Label information = new Label("Browser Information :");
        mainPanel.add(information, 74, 461);
        information.setSize("179px", "20px");
        information.setStyleName("label-browser");

        browserText = new TextBox();
        mainPanel.add(browserText, 255, 464);
        browserText.setSize("417px", "27px");

        button = new Button("Package");
        button.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {

                boolean result = false;
                selectObj.setServerName("biserver");

                // checks and set value based on selected
                if (selectDselect.getValue()) {
                    selectObj.setBidiXml(true);
                    selectObj.setBidiBatFile(true);
                    selectObj.setBidiProrperties(true);
                    selectObj.setTomcatXml(true);

                    selectedItem = new ArrayList<String>();
                    for (String item : BIConstant.SELECTEDITEM) {

                        selectedItem.add(item);
                    }
                    if (!browserText.getText().isEmpty()) {
                        selectObj.setBrowserInfo(browserText.getText());
                        selectedItem.add(BIConstant.BROWSER_INFO);
                    }

                    result = true;
                } else if (checkSelected()) {
                    result = true;
                } else {
                    message = null;
                    message = new MessageDialogBox("Message", "Please select options to proceed", false, true,
                            true);
                    showDialog();
                }

                if (result) {

                    disableAll();

                    final ProgressBar progressBar = new ProgressBar(0);
                    DOM.setElementAttribute(progressBar.getElement(), "id", "progressBar");
                    mainPanel.add(progressBar, 58, 508);

                    Timer timer = new Timer() {
                        public void run() {
                            double progress = progressBar.getProgress() + 1;
                            if (progress > 100) {
                                cancel();
                            }
                            progressBar.setProgress(progress);
                        }
                    };
                    timer.scheduleRepeating(1500);

                    // call the service
                    bisupportService.readandsaveSelectedConfiguration(selectedItem, selectObj,
                            new AsyncCallback<Boolean>() {

                                @Override
                                public void onFailure(Throwable caught) {
                                    message = new MessageDialogBox("Error", caught.getMessage(), false, true, true);
                                    showDialog();
                                }

                                @Override
                                public void onSuccess(Boolean result) {
                                    progressBar.removeFromParent();
                                    button.setVisible(true);
                                    selectedItem.clear();
                                    enableAll();
                                }

                            });

                }
            }
        });
        mainPanel.add(button, 58, 508);
        button.setSize("661px", "30px");

    }

    /**
     * disable all options on package click
     */
    private void disableAll() {

        selectDselect.setEnabled(false);
        license.setEnabled(false);
        secure.setEnabled(false);
        md5.setEnabled(false);
        running.setEnabled(false);
        environment.setEnabled(false);
        datasource.setEnabled(false);
        logs.setEnabled(false);
        structure.setEnabled(false);
        serverXml.setEnabled(false);
        tomcatXml.setEnabled(false);
        serverbat.setEnabled(false);
        serverProp.setEnabled(false);
        rdbtnInstaller.setEnabled(false);
        rdbtnArchive.setEnabled(false);
        rdbtnManual.setEnabled(false);
        button.setEnabled(false);
        browserText.setEnabled(false);
    }

    /**
     * enables all options on package release
     */
    private void enableAll() {

        selectDselect.setEnabled(true);
        license.setEnabled(true);
        secure.setEnabled(true);
        md5.setEnabled(true);
        running.setEnabled(true);
        environment.setEnabled(true);
        datasource.setEnabled(true);
        logs.setEnabled(true);
        structure.setEnabled(true);
        serverXml.setEnabled(true);
        tomcatXml.setEnabled(true);
        serverbat.setEnabled(true);
        serverProp.setEnabled(true);
        button.setEnabled(true);
        browserText.setEnabled(true);
        rdbtnInstaller.setEnabled(true);
        rdbtnArchive.setEnabled(true);
        rdbtnManual.setEnabled(true);
    }

    /**
     * checks selected options and add respective value to list
     * 
     * @return boolean
     */
    private boolean checkSelected() {

        Boolean result = false;

        selectedItem = new ArrayList<String>();

        if (license.getValue()) {
            selectedItem.add(BIConstant.LICENSE);
            result = true;
        }

        if (secure.getValue()) {
            selectedItem.add(BIConstant.SECURITY);
            result = true;
        }

        if (md5.getValue()) {
            selectedItem.add(BIConstant.MD5);
            result = true;
        }

        if (running.getValue()) {
            selectedItem.add(BIConstant.RUNNING_TASK);
            result = true;
        }

        if (environment.getValue()) {
            selectedItem.add(BIConstant.ENVIRONMENT);
            result = true;
        }

        if (datasource.getValue()) {
            selectedItem.add(BIConstant.DATASOURCE);
            result = true;
        }

        if (logs.getValue()) {
            selectedItem.add(BIConstant.LOGS);
            result = true;
        }

        if (structure.getValue()) {
            selectedItem.add(BIConstant.STRUCT);
            result = true;
        }

        if (serverXml.getValue()) {
            selectObj.setBidiXml(true);
            selectedItem.add(BIConstant.FILE);
            result = true;
        }

        if (tomcatXml.getValue()) {
            selectObj.setTomcatXml(true);

            if (!selectedItem.contains(BIConstant.FILE)) {
                selectedItem.add(BIConstant.FILE);
            }
            result = true;
        }

        if (serverbat.getValue()) {
            selectObj.setBidiBatFile(true);

            if (!selectedItem.contains(BIConstant.FILE)) {
                selectedItem.add(BIConstant.FILE);
            }
            result = true;
        }

        if (serverProp.getValue()) {
            selectObj.setBidiProrperties(true);

            if (!selectedItem.contains(BIConstant.FILE)) {
                selectedItem.add(BIConstant.FILE);
            }
            result = true;
        }

        if (!browserText.getText().isEmpty()) {
            selectObj.setBrowserInfo(browserText.getText());
            selectedItem.add(BIConstant.BROWSER_INFO);

            result = true;
        }

        return result;

    }

    /**
     * un-checks all select based on selection
     */
    private void checkList() {
        if (selectDselect.getValue()) {
            selectDselect.setValue(false);
        } else if (checkall()) {
            selectDselect.setValue(true);
        }
    }

    /**
     * 
     * @return
     */
    private boolean checkall() {
        Boolean result = true;
        if (!license.getValue()) {
            result = false;
        }
        if (!secure.getValue()) {
            result = false;
        }
        if (!md5.getValue()) {
            result = false;
        }
        if (!running.getValue()) {
            result = false;
        }
        if (!environment.getValue()) {
            result = false;
        }
        if (!datasource.getValue()) {
            result = false;
        }
        if (!logs.getValue()) {
            result = false;
        }
        if (!structure.getValue()) {
            result = false;
        }
        if (!serverXml.getValue()) {
            result = false;
        }
        if (!tomcatXml.getValue()) {
            result = false;
        }
        if (!serverbat.getValue()) {
            result = false;
        }
        if (!serverProp.getValue()) {
            result = false;
        }
        return result;
    }

    /**
     * on D-select un checks selected
     */
    private void onSelectDselect() {

        if (selectDselect.getValue()) {

            license.setValue(true);
            secure.setValue(true);
            md5.setValue(true);
            running.setValue(true);
            environment.setValue(true);
            datasource.setValue(true);
            logs.setValue(true);
            structure.setValue(true);
            serverXml.setValue(true);
            tomcatXml.setValue(true);
            serverbat.setValue(true);
            serverProp.setValue(true);
        } else {

            license.setValue(false);
            secure.setValue(false);
            md5.setValue(false);
            running.setValue(false);
            environment.setValue(false);
            datasource.setValue(false);
            logs.setValue(false);
            structure.setValue(false);
            serverXml.setValue(false);
            tomcatXml.setValue(false);
            serverbat.setValue(false);
            serverProp.setValue(false);
        }

    }

    /**
     * gets the base url to call service
     * 
     * @return
     */
    private String getBaseUrl() {

        String moduleUrl = GWT.getModuleBaseURL();
        if (moduleUrl.indexOf("content") > -1) {
            String baseUrl = moduleUrl.substring(0, moduleUrl.indexOf("content"));
            return baseUrl + "gwtrpc/BISupportUtilityService";
        }
        return moduleUrl + "gwtrpc";

    }

    /**
     * shows the dialog box
     */
    private void showDialog() {
        message.show();
        message.center();
    }

}