Package org.jboss.bpm.console.client.report

Source Code of org.jboss.bpm.console.client.report.ReportView

/*
* JBoss, Home of Professional Open Source.
* Copyright 2006, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.bpm.console.client.report;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.Frame;
import com.google.gwt.user.client.ui.Widget;
import com.mvc4g.client.Controller;
import com.mvc4g.client.Event;
import org.gwt.mosaic.ui.client.Label;
import org.gwt.mosaic.ui.client.PopupMenu;
import org.gwt.mosaic.ui.client.ToolBar;
import org.gwt.mosaic.ui.client.ToolButton;
import org.gwt.mosaic.ui.client.layout.BoxLayout;
import org.gwt.mosaic.ui.client.layout.BoxLayoutData;
import org.gwt.mosaic.ui.client.layout.LayoutPanel;
import org.jboss.bpm.console.client.ApplicationContext;
import org.jboss.bpm.console.client.URLBuilder;
import org.jboss.bpm.console.client.common.AbstractView;
import org.jboss.bpm.console.client.icons.ConsoleIconBundle;
import org.jboss.bpm.console.client.search.SearchDefinitionView;
import org.jboss.bpm.console.client.search.SearchDelegate;
import org.jboss.bpm.console.client.search.SearchWindow;
import org.jboss.bpm.console.client.search.UpdateSearchDefinitionsAction;

import java.util.Date;

/**
* @author Heiko.Braun <heiko.braun@jboss.com>
*/
public class ReportView extends AbstractView
{
  public final static String ID = ReportView.class.getName();

  private Controller controller;
  private boolean isInitialized;
  private ApplicationContext appContext;
  private LayoutPanel layout;
  private Frame frame;

  private SearchDefinitionView search;

  private LayoutPanel loadingPanel;

  public ReportView(ApplicationContext appContext)
  {
    super();
    this.appContext = appContext;
    ConsoleIconBundle icons = GWT.create(ConsoleIconBundle.class);
    setTitle("Process Reports");
    setIcon(icons.reportIcon());
  }

  public boolean isInitialized()
  {
    return isInitialized;
  }

  public void initialize()
  {
    if(!isInitialized)
    {

      // layout
      layout = new LayoutPanel( new BoxLayout(BoxLayout.Orientation.VERTICAL));
      layout.setPadding(0);
      layout.setWidgetSpacing(0);

      // search capabilities
      search = new SearchDefinitionView(
          appContext,
          new SearchDelegate()
          {
            public void handleResult(String procDefId)
            {
              String reportUrl = URLBuilder.getInstance().getProcessSummaryReportUrl(procDefId);

              // load report
              controller.handleEvent(
                  new Event(RenderReportAction.ID,
                      new RenderDispatchEvent(
                          ReportView.ID, reportUrl
                      )
                  )
              );
            }

            public String getActionName()
            {
              return "Open report";
            }
          }
      );


      // report frame
      frame = new Frame();
      DOM.setStyleAttribute(frame.getElement(), "border", "none");

      // toolbar
      final LayoutPanel toolBox = new LayoutPanel();
      toolBox.setPadding(0);
      toolBox.setWidgetSpacing(5);
      //toolBox.setLayout(new BoxLayout(BoxLayout.Orientation.VERTICAL));

      final ToolBar toolBar = new ToolBar();
      toolBar.add(createMenuBtn());
      toolBox.add(toolBar, new BoxLayoutData(BoxLayoutData.FillStyle.HORIZONTAL));

      // loading panel
      loadingPanel = new LayoutPanel();
      loadingPanel.add(new Label("Loading, please wait..."));
      loadingPanel.setVisible(false);

      // assembly
      layout.add(toolBox, new BoxLayoutData(BoxLayoutData.FillStyle.HORIZONTAL));
      layout.add(loadingPanel, new BoxLayoutData(BoxLayoutData.FillStyle.HORIZONTAL));
      layout.add(frame, new BoxLayoutData(BoxLayoutData.FillStyle.BOTH));

      this.add(layout);

      // views and actions
      controller.addView(
          "report.definition.search", search
      );

      controller.addAction(UpdateSearchDefinitionsAction.ID, new UpdateSearchDefinitionsAction());
      controller.addAction(RenderReportAction.ID, new RenderReportAction());

      // initial report
      controller.handleEvent(
          new Event(RenderReportAction.ID,
              new RenderDispatchEvent(
                  ReportView.ID, URLBuilder.getInstance().getOverallReportUrl()
              )
          )
      );

      this.isInitialized = true;
    }
  }


  public void onClick(Widget widget)
  {
    System.out.println(widget);
  }


  private Widget createMenuBtn()
  {
    // Add a menu button
    ToolButton menuButton = new ToolButton("Available Reports");
    menuButton.setStyle(ToolButton.ToolButtonStyle.MENU);

    // Make a command that we will execute from all menu items.
    Command cmd1 = new Command() {
      public void execute() {
        setFrameUrl(URLBuilder.getInstance().getOverallReportUrl());
      }
    };

    Command cmd2 = new Command() {
      public void execute()
      {
        SearchWindow sw = new SearchWindow("Open process summary report", search);
        sw.center();

        controller.handleEvent(
            new Event(
                UpdateSearchDefinitionsAction.ID,
                "report.definition.search"
            )
        );

      }
    };

    PopupMenu menuBtnMenu = new PopupMenu();
    menuBtnMenu.addItem("Overall System Activity", cmd1);
    menuBtnMenu.addItem("Process Summary", cmd2);

    menuButton.setMenu(menuBtnMenu);

    return menuButton;
  }

  public void setController(Controller controller)
  {
    this.controller = controller;
  }

  private void setFrameUrl(String url)
  {
    // https://jira.jboss.org/jira/browse/JBPM-2244
    frame.getElement().setId(
        String.valueOf( new Date().getTime())
    );

    frame.setUrl(url);

  }

  public void update(String reportUrl)
  {
    setFrameUrl(reportUrl);
  }

  void setLoading(boolean b)
  {
    loadingPanel.setVisible(b);
    if(!b)
    {
      Timer t = new Timer()
      {

        public void run()
        {
          frame.setVisible(true);
          appContext.refreshView();
        }
      };

      t.schedule(1500);
    }
    else
    {
      frame.setVisible(false);     
    }
  }
}
TOP

Related Classes of org.jboss.bpm.console.client.report.ReportView

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.