UpgradeReports.java 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /**
  2. Licensed Materials - Property of IBM
  3. IBM Cognos Products: DOCS
  4. (C) Copyright IBM Corp. 2005, 2008
  5. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with
  6. IBM Corp.
  7. */
  8. /**
  9. * UpgradeReports.java
  10. *
  11. * Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  12. * Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  13. *
  14. */
  15. import java.awt.BorderLayout;
  16. import java.awt.GridLayout;
  17. import java.awt.event.ActionEvent;
  18. import java.awt.event.ActionListener;
  19. import java.awt.event.WindowAdapter;
  20. import java.awt.event.WindowEvent;
  21. import java.io.File;
  22. import java.net.URL;
  23. import javax.swing.ImageIcon;
  24. import javax.swing.JEditorPane;
  25. import javax.swing.JFrame;
  26. import javax.swing.JLabel;
  27. import javax.swing.JMenu;
  28. import javax.swing.JMenuBar;
  29. import javax.swing.JMenuItem;
  30. import javax.swing.JOptionPane;
  31. import javax.swing.JPanel;
  32. import javax.swing.JScrollPane;
  33. import javax.swing.JTextField;
  34. // This Java class extends the JPanel class so that you can
  35. // display a window.
  36. public class UpgradeReports
  37. extends JFrame
  38. {
  39. public static final String UPGRADE_SPEC_STRING = "Upgrade and replace";
  40. public static final String UPGRADE_COPY_SPEC_STRING = "Upgrade and Copy";
  41. public static final String EXTRACT_UPGRADED_SPEC_STRING = "Save to file (no upgrade)";
  42. public static final String EXTRACT_SPEC_STRING = "Upgrade and Save to file";
  43. private CRNConnect connect;
  44. // The following variables represent the dialog components.
  45. private UpgradeReportsTree outputPane;
  46. private JTextField cmURL;
  47. private JTextField selectedSearchPath;
  48. private static Logon sessionLogon;
  49. // This is the constructor.
  50. public UpgradeReports(String title, CRNConnect connection)
  51. {
  52. // Set the title of the frame, even before the variables are declared.
  53. super(title);
  54. connect = connection;
  55. addComponents();
  56. }
  57. // Add all components to the frame's panel.
  58. private void addComponents()
  59. {
  60. JMenuBar mBar = new JMenuBar();
  61. this.setJMenuBar(mBar);
  62. //
  63. //Add and populate the File menu.
  64. JMenu fileMenu = new JMenu("File");
  65. mBar.add(fileMenu);
  66. JMenuItem exit = new JMenuItem("Exit");
  67. fileMenu.add(exit);
  68. exit.addActionListener(new MenuHandler());
  69. JMenuItem refresh = new JMenuItem("Refresh Tree");
  70. fileMenu.add(refresh);
  71. refresh.addActionListener(new MenuHandler());
  72. //
  73. //Add and populate the Upgrade menu
  74. JMenu upgMenu = new JMenu("Upgrade");
  75. mBar.add(upgMenu);
  76. JMenuItem contentStoreUpgrade = new JMenuItem(UPGRADE_SPEC_STRING);
  77. upgMenu.add(contentStoreUpgrade);
  78. contentStoreUpgrade.addActionListener(new MenuHandler());
  79. JMenuItem contentStoreCopy = new JMenuItem(UPGRADE_COPY_SPEC_STRING);
  80. upgMenu.add(contentStoreCopy);
  81. contentStoreCopy.addActionListener(new MenuHandler());
  82. //
  83. //Add and populate the Extract menu
  84. JMenu extractMenu = new JMenu("Extract");
  85. mBar.add(extractMenu);
  86. JMenuItem localUpgrade = new JMenuItem(EXTRACT_UPGRADED_SPEC_STRING);
  87. extractMenu.add(localUpgrade);
  88. localUpgrade.addActionListener(new MenuHandler());
  89. JMenuItem localCopy = new JMenuItem(EXTRACT_SPEC_STRING);
  90. extractMenu.add(localCopy);
  91. localCopy.addActionListener(new MenuHandler());
  92. //
  93. //Add and populate the Help menu.
  94. JMenu helpMenu = new JMenu("Help");
  95. mBar.add(helpMenu);
  96. JMenuItem about = new JMenuItem("About");
  97. helpMenu.add(about);
  98. about.addActionListener(new MenuHandler());
  99. JMenuItem overview = new JMenuItem("Overview");
  100. helpMenu.add(overview);
  101. overview.addActionListener(new MenuHandler());
  102. JPanel mainPanel = new JPanel(new GridLayout(2, 0));
  103. // create a cmURL panel
  104. JPanel cmURLPanel = new JPanel();
  105. // Add the URL text field and label
  106. cmURL = new JTextField(CRNConnect.CM_URL.length() + 5);
  107. cmURL.setText(CRNConnect.CM_URL);
  108. cmURL.setEditable(false);
  109. cmURLPanel.add(new JLabel("Server URL:"), BorderLayout.WEST);
  110. cmURLPanel.add(cmURL, BorderLayout.EAST);
  111. // Create the Button and Button Panel
  112. selectedSearchPath = new JTextField(CRNConnect.CM_URL.length() + 5);
  113. JPanel searchPathPanel = new JPanel();
  114. searchPathPanel.add(new JLabel("Search Path:"), BorderLayout.WEST);
  115. searchPathPanel.add(selectedSearchPath, BorderLayout.EAST);
  116. // Add the status text pane.
  117. outputPane = new UpgradeReportsTree(connect);
  118. // Add the panels to the mainPanel
  119. mainPanel.add(cmURLPanel);
  120. mainPanel.add(searchPathPanel);
  121. JPanel panel = new JPanel(new BorderLayout());
  122. panel.add(mainPanel, BorderLayout.NORTH);
  123. panel.add(outputPane);
  124. setContentPane(panel);
  125. }
  126. private class MenuHandler implements ActionListener
  127. {
  128. public void actionPerformed(ActionEvent e)
  129. {
  130. if (e.getActionCommand().startsWith("http://"))
  131. {
  132. connect.connectionChange(e.getActionCommand());
  133. }
  134. try
  135. {
  136. JMenuItem menuClicked = (JMenuItem)e.getSource();
  137. if (menuClicked.getText() == "Exit")
  138. {
  139. System.exit(0);
  140. }
  141. if (menuClicked.getText() == "Refresh Tree")
  142. {
  143. recreateTree();
  144. }
  145. if (menuClicked.getText().compareTo("Overview") == 0)
  146. {
  147. JFrame explainWindow =
  148. new JFrame("Overview for Report Upgrade Sample");
  149. File explainFile = new File("Java_ReportUpgrade_Explain.html");
  150. if (! explainFile.exists())
  151. {
  152. JOptionPane.showMessageDialog(null, "Explain file not found");
  153. return;
  154. }
  155. URL explainURL =
  156. new URL("file:///" + explainFile.getAbsolutePath());
  157. JEditorPane explainPane = new JEditorPane();
  158. explainPane.setPage(explainURL);
  159. explainPane.setEditable(false);
  160. JScrollPane explainScroll =
  161. new JScrollPane(
  162. explainPane,
  163. JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
  164. JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  165. explainWindow.getContentPane().add(explainScroll);
  166. explainWindow.setSize(640, 480);
  167. explainWindow.setVisible(true);
  168. }
  169. if (menuClicked.getText() == "About")
  170. {
  171. JOptionPane.showMessageDialog(
  172. ((JMenuItem)e.getSource()).getParent(),
  173. "IBM Cognos Sample Application\n\n"
  174. + "Version 1.0.0\n"
  175. + "This application uses the IBM Cognos Software Development Kit",
  176. "About IBM Cognos Samples",
  177. JOptionPane.INFORMATION_MESSAGE,
  178. new ImageIcon("../Common/about.gif"));
  179. }
  180. if ( menuClicked.getText() == UpgradeReports.UPGRADE_SPEC_STRING )
  181. {
  182. outputPane.showUpgradeDialog(null, connect);
  183. }
  184. if (menuClicked.getText() == UpgradeReports.UPGRADE_COPY_SPEC_STRING)
  185. {
  186. outputPane.showUpgradeCopyDialog(null, connect);
  187. }
  188. if (menuClicked.getText() == UpgradeReports.EXTRACT_SPEC_STRING)
  189. {
  190. outputPane.showExtractDialog(null, connect);
  191. }
  192. if (menuClicked.getText() == UpgradeReports.EXTRACT_UPGRADED_SPEC_STRING)
  193. {
  194. outputPane.showExtractUpgradedDialog(null,connect);
  195. }
  196. }
  197. catch (Exception ex)
  198. {}
  199. }
  200. }
  201. public void updateSelectedSearchPath(String newSearchPath)
  202. {
  203. selectedSearchPath.setText(newSearchPath);
  204. }
  205. public void recreateTree()
  206. {
  207. outputPane.setVisible(false);
  208. getContentPane().remove(outputPane);
  209. outputPane = new UpgradeReportsTree(connect);
  210. getContentPane().add(outputPane);
  211. outputPane.setVisible(true);
  212. }
  213. // Create the main method to execute the application.
  214. public static void main(String args[])
  215. {
  216. CRNConnect connection = new CRNConnect();
  217. connection.connectToCognosServer();
  218. sessionLogon = new Logon();
  219. while (!Logon.loggedIn(connection))
  220. {
  221. sessionLogon.logon(connection);
  222. if (!Logon.loggedIn(connection))
  223. {
  224. int retry =
  225. JOptionPane.showConfirmDialog(
  226. null,
  227. "Login Failed. Please try again.",
  228. "Login Failed",
  229. JOptionPane.OK_CANCEL_OPTION);
  230. if (retry != JOptionPane.OK_OPTION)
  231. {
  232. System.exit(0);
  233. }
  234. }
  235. }
  236. UpgradeReports frame = new UpgradeReports("IBM Cognos Sample", connection);
  237. // Create a WindowAdapter so the application
  238. // is exited when the window is closed.
  239. frame.addWindowListener(new WindowAdapter()
  240. {
  241. public void windowClosing(WindowEvent e)
  242. {
  243. System.exit(0);
  244. }
  245. });
  246. // Set the size of the frame and display it.
  247. frame.setSize(680, 440);
  248. frame.setVisible(true);
  249. frame.setResizable(true);
  250. }
  251. }