CSExplorer.java 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. * CSExplorer.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 CSExplorer extends JFrame
  37. {
  38. private CRNConnect connect;
  39. // The following variables represent the dialog components.
  40. private JPanel outputPane;
  41. private JPanel outputPanel;
  42. private JTextField cmURL;
  43. private JTextField selectedSearchPath;
  44. private static Logon sessionLogon;
  45. // This is the constructor.
  46. public CSExplorer(String title, CRNConnect connection)
  47. {
  48. // Set the title of the frame, even before the variables are declared.
  49. super(title);
  50. connect = connection;
  51. addComponents();
  52. }
  53. // Add all components to the frame's panel.
  54. private void addComponents()
  55. {
  56. JMenuBar mBar = new JMenuBar();
  57. this.setJMenuBar(mBar);
  58. //declare menuItems
  59. JMenuItem exit;
  60. JMenuItem refresh;
  61. JMenuItem about;
  62. JMenuItem overview;
  63. //Add and populate the File menu.
  64. JMenu fileMenu = new JMenu("File");
  65. mBar.add(fileMenu);
  66. refresh = new JMenuItem("Refresh Tree");
  67. fileMenu.add(refresh);
  68. refresh.addActionListener(new MenuHandler());
  69. exit = new JMenuItem("Exit");
  70. fileMenu.add(exit);
  71. exit.addActionListener(new MenuHandler());
  72. //Add and populate the Help menu.
  73. JMenu helpMenu = new JMenu("Help");
  74. mBar.add(helpMenu);
  75. about = new JMenuItem("About");
  76. helpMenu.add(about);
  77. about.addActionListener(new MenuHandler());
  78. overview = new JMenuItem("Overview");
  79. helpMenu.add(overview);
  80. overview.addActionListener(new MenuHandler());
  81. JPanel mainPanel = new JPanel(new GridLayout(2, 0));
  82. // create a cmURL panel
  83. JPanel cmURLPanel = new JPanel();
  84. // Add the URL text field and label
  85. cmURL = new JTextField(CRNConnect.CM_URL.length() + 5);
  86. cmURL.setText(CRNConnect.CM_URL);
  87. cmURL.setEditable(false);
  88. cmURLPanel.add(new JLabel("Server URL:"), BorderLayout.WEST);
  89. cmURLPanel.add(cmURL, BorderLayout.EAST);
  90. // Create the Button and Button Panel
  91. selectedSearchPath = new JTextField(CRNConnect.CM_URL.length() + 5);
  92. JPanel searchPathPanel = new JPanel();
  93. searchPathPanel.add(new JLabel("Search Path:"), BorderLayout.WEST);
  94. searchPathPanel.add(selectedSearchPath, BorderLayout.EAST);
  95. // Add the status text pane.
  96. outputPane = new CSExplorerTree(connect);
  97. // Add the panels to the mainPanel
  98. mainPanel.add(cmURLPanel);
  99. mainPanel.add(searchPathPanel);
  100. outputPanel = new JPanel(new GridLayout(0, 1));
  101. outputPanel.add(outputPane);
  102. JPanel panel = new JPanel(new BorderLayout());
  103. panel.add(mainPanel, BorderLayout.NORTH);
  104. panel.add(outputPanel);
  105. setContentPane(panel);
  106. }
  107. private class MenuHandler implements ActionListener
  108. {
  109. public void actionPerformed(ActionEvent e)
  110. {
  111. if (e.getActionCommand().startsWith("http://"))
  112. {
  113. connect.connectionChange(e.getActionCommand());
  114. }
  115. try
  116. {
  117. JMenuItem menuClicked = (JMenuItem)e.getSource();
  118. if (menuClicked.getText() == "Exit")
  119. {
  120. System.exit(0);
  121. }
  122. if (menuClicked.getText() == "Refresh Tree")
  123. {
  124. recreateTree();
  125. }
  126. if (menuClicked.getText() == "About")
  127. {
  128. JOptionPane.showMessageDialog(
  129. ((JMenuItem)e.getSource()).getParent(),
  130. "IBM Cognos Sample Application\n\n"
  131. + "Version 1.0.0\n"
  132. + "This application uses the IBM Cognos Software Development Kit",
  133. "About IBM Cognos Samples",
  134. JOptionPane.INFORMATION_MESSAGE,
  135. new ImageIcon("../Common/about.gif"));
  136. }
  137. if (menuClicked.getText().compareTo("Overview") == 0)
  138. {
  139. JFrame explainWindow =
  140. new JFrame("Overview for CSExplorer");
  141. File explainFile = new File("Java_CSExplorer_Explain.html");
  142. if (! explainFile.exists())
  143. {
  144. JOptionPane.showMessageDialog(null, "Explain file not found");
  145. return;
  146. }
  147. URL explainURL =
  148. new URL("file:///" + explainFile.getAbsolutePath());
  149. JEditorPane explainPane = new JEditorPane();
  150. explainPane.setPage(explainURL);
  151. explainPane.setEditable(false);
  152. JScrollPane explainScroll =
  153. new JScrollPane(
  154. explainPane,
  155. JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
  156. JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  157. explainWindow.getContentPane().add(explainScroll);
  158. explainWindow.setSize(640, 480);
  159. explainWindow.setVisible(true);
  160. }
  161. }
  162. catch (Exception ex)
  163. {
  164. JOptionPane.showMessageDialog(
  165. null,
  166. "Exception caught:" + ex.toString());
  167. }
  168. }
  169. }
  170. public void recreateTree()
  171. {
  172. outputPanel.setVisible(false);
  173. outputPanel.remove(outputPane);
  174. outputPane = new CSExplorerTree(connect);
  175. outputPanel.add(outputPane);
  176. outputPanel.setVisible(true);
  177. }
  178. public void updateSelectedSearchPath(String newSearchPath)
  179. {
  180. selectedSearchPath.setText(newSearchPath);
  181. }
  182. // Create the main method to execute the application.
  183. public static void main(String args[])
  184. {
  185. CRNConnect connection = new CRNConnect();
  186. connection.connectToCognosServer();
  187. sessionLogon = new Logon();
  188. while (!Logon.loggedIn(connection))
  189. {
  190. sessionLogon.logon(connection);
  191. if (!Logon.loggedIn(connection))
  192. {
  193. int retry =
  194. JOptionPane.showConfirmDialog(
  195. null,
  196. "Login Failed. Please try again.",
  197. "Login Failed",
  198. JOptionPane.OK_CANCEL_OPTION);
  199. if (retry != JOptionPane.OK_OPTION)
  200. {
  201. System.exit(0);
  202. }
  203. }
  204. }
  205. CSExplorer frame = new CSExplorer("IBM Cognos Sample", connection);
  206. // Create a WindowAdapter so the application
  207. // is exited when the window is closed.
  208. frame.addWindowListener(new WindowAdapter()
  209. {
  210. public void windowClosing(WindowEvent e)
  211. {
  212. System.exit(0);
  213. }
  214. });
  215. //frame.textAreaPane.setText(output);
  216. // Set the size of the frame and display it.
  217. frame.setSize(680, 440);
  218. frame.setVisible(true);
  219. frame.setResizable(true);
  220. }
  221. }