Skip to main content
summaryrefslogtreecommitdiffstats
blob: 07648094d3b6241d22c830c1214b8a74c67bf78b (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * 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
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/

package org.eclipse.osee.framework.ui.skynet.results.html;

import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.eclipse.osee.framework.logging.OseeLevel;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.ui.plugin.util.AWorkbench;
import org.eclipse.osee.framework.ui.skynet.internal.Activator;
import org.eclipse.osee.framework.ui.skynet.results.html.XResultPage.Manipulations;
import org.eclipse.osee.framework.ui.skynet.widgets.dialog.Dialogs;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.program.Program;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;

/**
 * @author Donald G. Dunne
 */
public class XResultsComposite extends Composite {

   protected Browser browser;
   private String htmlText;
   private String title = "";

   public XResultsComposite(Composite parent, int style) {
      super(parent, style);

      setLayout(new GridLayout(1, false));
      setLayoutData(new GridData(GridData.FILL_BOTH));

      GridLayout layout = new GridLayout();
      layout.numColumns = 1;
      layout.verticalSpacing = 0;
      layout.marginWidth = 0;
      layout.marginHeight = 0;
      parent.setLayout(layout);
      parent.setLayoutData(new GridData(GridData.FILL_BOTH));

      browser = new Browser(this, SWT.BORDER);
      browser.addLocationListener(new XResultBrowserListener());
      browser.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
      browser.setMenu(getPopup(parent));

   }

   public Menu getPopup(Composite comp) {
      Menu menu = new Menu(comp);

      MenuItem item = new MenuItem(menu, SWT.NONE);
      item.setText("View Source");
      item.addSelectionListener(new SelectionAdapter() {

         @Override
         public void widgetSelected(SelectionEvent e) {
            if (!Strings.isValid(htmlText)) {
               AWorkbench.popup("ERROR", "Nothing to view");
               return;
            }
            String fileName = System.getProperty("user.home") + File.separator + "out.html";
            try {
               Lib.writeStringToFile(htmlText, new File(fileName));
            } catch (IOException ex) {
               OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, ex);
            }
            Program.launch(fileName);
         }
      });

      item = new MenuItem(menu, SWT.NONE);
      item.setText("Print");
      item.addSelectionListener(new SelectionAdapter() {

         @Override
         public void widgetSelected(SelectionEvent e) {
            if (!Strings.isValid(htmlText)) {
               AWorkbench.popup("ERROR", "Nothing to print");
               return;
            }
            browser.setUrl("javascript:print()");
         }
      });

      item = new MenuItem(menu, SWT.NONE);
      item.setText("Email");
      item.addSelectionListener(new SelectionAdapter() {

         @Override
         public void widgetSelected(SelectionEvent e) {
            if (!Strings.isValid(htmlText)) {
               AWorkbench.popup("ERROR", "Nothing to email");
               return;
            }
            Set<Manipulations> manipulations = new HashSet<Manipulations>();
            manipulations.add(Manipulations.ALL);
            manipulations.add(Manipulations.ERROR_WARNING_HEADER);
            Dialogs.emailDialog(title, htmlText);
         }
      });
      item = new MenuItem(menu, SWT.NONE);
      item.setText("Export Table");
      item.addSelectionListener(new SelectionAdapter() {

         @Override
         public void widgetSelected(SelectionEvent e) {
            Dialogs.exportHtmlTableDialog(title, htmlText, true);
         }
      });
      item = new MenuItem(menu, SWT.NONE);
      item.setText("Save to File");
      item.addSelectionListener(new SelectionAdapter() {

         @Override
         public void widgetSelected(SelectionEvent e) {
            Dialogs.saveHtmlDialog(htmlText, true);
         }
      });
      return menu;
   }

   /**
    * @return the browser
    */
   public Browser getBrowser() {
      return browser;
   }

   /**
    * @return the htmlText
    */
   public String getHtmlText() {
      return htmlText;
   }

   /**
    * @param htmlText the htmlText to set
    */
   public void setHtmlText(String htmlText) {
      setHtmlText(htmlText, title);
   }

   public void setHtmlText(String htmlText, String title) {
      this.htmlText = htmlText;
      this.title = title;
      if (browser != null && !browser.isDisposed()) {
         browser.setText(htmlText);
      }
   }

   /**
    * @return the title
    */
   public String getTitle() {
      return title;
   }

   /**
    * @param title the title to set
    */
   public void setTitle(String title) {
      this.title = title;
   }
}

Back to the top