Package waelti.statistics.views

Source Code of waelti.statistics.views.OutputView

package waelti.statistics.views;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.part.ViewPart;

import waelti.statistics.actions.NewQueryAction;
import waelti.statistics.queries.AbstractQuery;

/**
* This class contains all methods needed to display the output created by any
* query.
*
* @author Michael Waelti
*/

public class OutputView extends ViewPart {

  private Composite parent;

  /**
   * Header block containing all information displayed at the head of the
   * output. E.g. creating date, queries name.
   */
  private Label header;

  /** A composite containing the result */
  private ResultTable resultView;

  /** this action starts the query and redraws the view. */
  private Action startQueryAction;

  /**
   * The constructor.
   */
  public OutputView() {
  }

  /**
   * This is a callback that will allow us to create the viewer and initialize
   * it.
   */
  public void createPartControl(Composite parent) {
    this.parent = parent;
    this.parent.setLayout(new GridLayout());

    this.makeAction();
    this.contributeAction();

    // header
    initHeader("Keine Auswertung gestartet. Wählen Sie \"new query\", "
        + "um eine neue Auswertung zu starten.");
  }

  private void initHeader(String labelText) {
    header = new Label(this.parent, SWT.WRAP);
    header.setText(labelText);

    GridData data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.grabExcessHorizontalSpace = true;
    header.setLayoutData(data);
  }

  /**
   * Disposes of any actual result display and initiates a new one with the
   * given query.
   */
  public void createOrUpdateResultTable(AbstractQuery query) {

    if (this.resultView != null) {
      this.resultView.dispose();
    }

    resultView = new ResultTable(this.parent, SWT.BORDER, query);
    this.parent.layout();

    GridData data = new GridData();
    data.verticalAlignment = GridData.FILL;
    data.horizontalAlignment = GridData.FILL;
    data.grabExcessVerticalSpace = true;
    data.grabExcessHorizontalSpace = true;
    resultView.setLayoutData(data);

    resultView.createContent();
    this.parent.layout();
  }

  private void contributeAction() {
    IActionBars bars = this.getViewSite().getActionBars();
    this.fillLocalToolBar(bars.getToolBarManager());
  }

  private void fillLocalToolBar(IToolBarManager manager) {
    manager.add(this.startQueryAction);
  }

  private void makeAction() {
    this.startQueryAction = new NewQueryAction(this);
  }

  /**
   * Passing the focus request to the viewer's control.
   */
  public void setFocus() {
    // viewer.getControl().setFocus();
  }

  /**
   * Set the header to be displayed for the result composite. E.g. contaings
   * information like the date of the query, the query's name.
   */
  public void setHeader(String headerText) {
    this.header.setText(headerText);
    this.parent.layout();
  }

  public Action getStartQueryAction() {
    return startQueryAction;
  }
}
TOP

Related Classes of waelti.statistics.views.OutputView

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.