Skip to main content
summaryrefslogtreecommitdiffstats
blob: c9623e9b30cb0ae9662c05cc4758b9934e517cb5 (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
/*******************************************************************************
 * 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.preferences;

import java.text.DateFormat;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.osee.framework.core.client.ClientSessionManager;
import org.eclipse.osee.framework.database.core.ConnectionHandler;
import org.eclipse.osee.framework.database.core.IOseeStatement;
import org.eclipse.osee.framework.database.core.OseeInfo;
import org.eclipse.osee.framework.jdk.core.util.AHTML;
import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.eclipse.osee.framework.ui.skynet.internal.Activator;
import org.eclipse.osee.framework.ui.swt.Displays;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;

/**
 * @author Roberto E. Escobar
 */
public class DataSourceDetails extends PreferencePage implements IWorkbenchPreferencePage {
   private static final String HTML_HEADER =
      "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html14/loose.dtd\">\n";

   private static final String CSS_SHEET =
      "<style type=\"text/css\"> table.oseeTable { font: 0.7em \"arial\", serif; border-width: 1px 1px 1px 1px; border-spacing: 2px; border-style: solid solid solid solid; border-color: blue blue blue blue; border-collapse: separate; background-color: rgb(255, 250, 250); } " + " table.oseeTable th { border-width: 1px 1px 1px 1px; padding: 4px 4px 4px 4px; border-style: solid solid solid solid; border-color: black black black black; background-color: white; -moz-border-radius: 0px 0px 0px 0px; } " + " table.oseeTable td { border-width: 1px 1px 1px 1px; padding: 4px 4px 4px 4px; border-style: solid solid solid solid; border-color: black black black black; background-color: white; -moz-border-radius: 0px 0px 0px 0px; } </style>\n";

   private static final String PAGE_TEMPLATE =
      HTML_HEADER + "<html>\n<head>\n" + CSS_SHEET + "</head>\n<body>\n%s</body>\n</html>";

   private Browser browser;

   public DataSourceDetails() {
      super();
      this.browser = null;
   }

   @Override
   public void init(IWorkbench workbench) {
      setPreferenceStore(Activator.getInstance().getPreferenceStore());
      setDescription("See below for OSEE Data Source Details.");
   }

   @Override
   protected Control createContents(Composite parent) {
      Composite content = new Composite(parent, SWT.NONE);
      GridLayout layout = new GridLayout();
      layout.marginHeight = 0;
      layout.marginWidth = 0;
      content.setLayout(layout);
      content.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

      Group composite = new Group(content, SWT.NONE);
      composite.setLayout(new GridLayout());
      composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
      composite.setText("Data Source(s)");

      browser = new Browser(composite, SWT.READ_ONLY | SWT.BORDER);
      browser.setLayout(new FillLayout());
      browser.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));

      Displays.ensureInDisplayThread(new Runnable() {
         @Override
         public void run() {
            generatePage();
         }
      });
      return content;
   }

   private void generatePage() {
      StringBuilder builder = new StringBuilder();
      builder.append(getDatabaseSourceInfo());
      builder.append("<br/>");
      builder.append(getDatabaseImportSource());
      browser.setText(String.format(PAGE_TEMPLATE, builder.toString()));
   }

   private String getDatabaseSourceInfo() {
      StringBuilder builder = new StringBuilder();
      builder.append("<table class=\"oseeTable\" width=\"100%\">");
      builder.append(AHTML.addHeaderRowMultiColumnTable(new String[] {"Data Source"}));
      try {
         builder.append(AHTML.addRowMultiColumnTable(String.format(
            "<b>Name:</b> %s<br/><b>Schema:</b> %s<br/><b>Driver:</b> %s<br/><b>Is Production:</b> %s<br/><b>ID:</b> %s<br/>",
            ClientSessionManager.getDataStoreName(), ClientSessionManager.getDataStoreLoginName(),
            ClientSessionManager.getDataStoreDriver(), ClientSessionManager.isProductionDataStore(),
            OseeInfo.getDatabaseGuid())));
      } catch (Exception ex) {
         builder.append(Lib.exceptionToString(ex));
      } finally {
         builder.append(AHTML.endMultiColumnTable());
      }
      return builder.toString();
   }

   private String getDatabaseImportSource() {
      DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
      StringBuilder builder = new StringBuilder();
      builder.append("<table class=\"oseeTable\" width=\"100%\">");
      builder.append(AHTML.addHeaderRowMultiColumnTable(new String[] {"Source Id", "Exported On", "Imported On"}));
      IOseeStatement chStmt = null;
      try {
         chStmt = ConnectionHandler.getStatement();
         chStmt.runPreparedQuery("select * from osee_import_source");
         while (chStmt.next()) {
            builder.append(AHTML.addRowMultiColumnTable(chStmt.getString("db_source_guid"),
               dateFormat.format(chStmt.getTimestamp("source_export_date")),
               dateFormat.format(chStmt.getTimestamp("date_imported"))));
         }
      } catch (Exception ex) {
         builder.append(AHTML.addRowSpanMultiColumnTable(Lib.exceptionToString(ex), 3));
      } finally {
         builder.append(AHTML.endMultiColumnTable());
         chStmt.close();
      }
      return builder.toString().replaceAll("\n", "<br/>");
   }
}

Back to the top