Skip to main content
summaryrefslogtreecommitdiffstats
blob: 24446c532e6646e3527785cb1e56d3391c9bb5f9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 * Copyright (c) 2012 Robert Bosch Engineering and Business Solutions Ltd India. All rights reserved. This program and
 * the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies
 * this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.eclipse.osee.ats.reports.internal;

import java.net.URL;
import org.eclipse.birt.report.viewer.utilities.WebViewer;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.osee.framework.core.exception.OseeExceptions;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.logging.OseeLevel;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.ui.skynet.results.IResultsEditorTab;
import org.eclipse.osee.framework.ui.skynet.results.ResultsEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.widgets.Composite;
import org.osgi.framework.Bundle;

/**
 * Class that implements IResultsEditorTab to crate the tab in the UI
 * 
 * @author Praveen Joseph
 */
public class BirtReportViewerTab implements IResultsEditorTab {

   private final String tabName;
   private final String bundleId;
   private final String rptDesingPath;

   public BirtReportViewerTab(String bundleId, String tabName, String rptDesingPath) {
      this.tabName = tabName;
      this.bundleId = bundleId;
      this.rptDesingPath = rptDesingPath;
   }

   @SuppressWarnings("deprecation")
   @Override
   public Composite createTab(final Composite parent, final ResultsEditor resultsEditor) {
      Browser browser = new Browser(parent, SWT.NONE);
      try {
         URL reportLocation = getReportPath(bundleId, rptDesingPath);
         WebViewer.display(reportLocation.getPath(), WebViewer.HTML, browser, "frameset");
         browser.refresh();
      } catch (Exception ex) {
         OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, ex);
      }
      return browser;
   }

   @Override
   public String getTabName() {
      return tabName;
   }

   private URL getReportPath(String bundleId, String reportPath) throws OseeCoreException {
      URL url = null;
      try {
         Bundle bundle = Platform.getBundle(bundleId);
         url = FileLocator.find(bundle, new Path(reportPath), null);
         url = FileLocator.toFileURL(url);
      } catch (Exception ex) {
         OseeExceptions.wrapAndThrow(ex);
      }
      return url;
   }
}

Back to the top