Exemple #1
0
  public static void generateRandomSeed() {

    // create a 160-bit seed
    SecureRandom sr0 = new SecureRandom();
    byte[] seed = sr0.generateSeed(SEED_BYTES);

    // make a string representation
    StringBuffer buffer = new StringBuffer(SEED_BYTES * 3);
    for (int i = 0; i < seed.length; i++) {
      buffer.append(',');
      int seedByte = seed[i] & 0xFF;
      if (seedByte < 16) {
        buffer.append('0');
      }
      buffer.append(Integer.toHexString(seedByte));
    }

    // save it in local.properties (Note: remove leading comma)
    LocalProperties.setProperty("random_seed", buffer.substring(1));
  }
Exemple #2
0
/**
 * The AdminFrame wraps the JTabbedPane and the pages.
 *
 * @author Bill
 */
public final class AdminFrame extends JFrame {

  // the common instance of this singleton class
  private static AdminFrame instance = null;

  private JFrame loginFrame;
  private AbstractPage currentPage;
  public static final String PROPS_SERVER_IP = LocalProperties.getProperty("server_ip");
  /**
   * Creates new form AdminFrame.
   *
   * @param loginFrame used to close the loginFrame upon first showing adminFrame
   */
  private AdminFrame(JFrame loginFrame) {
    this.loginFrame = loginFrame;
    initComponents();

    // set the frame's icon
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Image iconImage;
    iconImage = toolkit.getImage("images/ibase_admin.gif");
    setIconImage(iconImage);
  }

  /**
   * Obtain the singleton instance of this class. Synchronized on the class, so that setup can
   * proceed during login.
   *
   * @param loginFrame used to close the loginFrame upon first showing adminFrame
   */
  public static synchronized AdminFrame getInstance(JFrame loginFrame) {
    if (instance == null) {
      instance = new AdminFrame(loginFrame);
    }
    return instance;
  }
  /**
   * Obtain the singleton instance of this class, even if null. Used in MailreceivedManagedModel to
   * see if the admin mail tab is showing.
   */
  public static AdminFrame getInstance() {
    return instance;
  }

  /**
   * This method is called from within the constructor to initialize the form. WARNING: Do NOT
   * modify this code. The content of this method is always regenerated by the Form Editor.
   */
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    jMenuBar1 = new javax.swing.JMenuBar();
    jMenu1 = new javax.swing.JMenu();
    tabbedPane = new javax.swing.JTabbedPane();
    batchingPanel = new BatchingPage(this);
    projectPanel = new ProjectAdminPage(this);
    tablePanel = new TableAdminPage(this);
    userAdminPanel = new UserAdminPage(this);
    teamAdminPanel = new TeamAdminPage(this);
    sessionPanel = new SessionAdminPage(this);
    receivablesPanel = new CustomerPricePage(this);
    pricePanel = new PricePage(this);
    reportPanel = new ReportPage(this);
    mailPanel = new MailPage(this);
    // importPanel = new ImportPage(this);
    importPanel = new ImportPageWithL1(this);
    exportPanel = new ExportPage(this);
    populatePanel = new PopulatePage(this);
    defaultMenuBar = new javax.swing.JMenuBar();
    fileMenu = new javax.swing.JMenu();
    jSeparator11 = new javax.swing.JSeparator();
    exitMenuItem = new javax.swing.JMenuItem();
    helpMenu = new javax.swing.JMenu();
    contentsMenuItem = new javax.swing.JMenuItem();
    aboutMenuItem = new javax.swing.JMenuItem();

    jMenu1.setText("Menu");
    jMenuBar1.add(jMenu1);

    setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
    setTitle("SPiCA Administration - Conected To server : " + PROPS_SERVER_IP);
    addWindowListener(
        new java.awt.event.WindowAdapter() {
          public void windowClosing(java.awt.event.WindowEvent evt) {
            exitForm(evt);
          }

          public void windowOpened(java.awt.event.WindowEvent evt) {
            formWindowOpened(evt);
          }
        });

    tabbedPane.setTabPlacement(javax.swing.JTabbedPane.BOTTOM);
    tabbedPane.addChangeListener(
        new javax.swing.event.ChangeListener() {
          public void stateChanged(javax.swing.event.ChangeEvent evt) {
            tabbedPaneStateChanged(evt);
          }
        });

    tabbedPane.addTab("Batching", batchingPanel);

    tabbedPane.addTab("Project", projectPanel);

    tabbedPane.addTab("Tables", tablePanel);

    tabbedPane.addTab("Users", userAdminPanel);

    tabbedPane.addTab("Teams", teamAdminPanel);

    tabbedPane.addTab("Sessions", sessionPanel);

    receivablesPanel.setEnabled(false);
    tabbedPane.addTab("Receivables", receivablesPanel);

    pricePanel.setEnabled(false);
    tabbedPane.addTab("Prices", pricePanel);

    tabbedPane.addTab("Reports", reportPanel);

    tabbedPane.addTab("Mail", mailPanel);

    tabbedPane.addTab("Import", importPanel);

    tabbedPane.addTab("Export", exportPanel);

    advanceValidationAdminPanel = new AdvanceValidationPage(this);
    postValidationPanel = new PostValidationPage(this);
    tabbedPane.addTab("Import Data", populatePanel);

    tabbedPane.addTab("Advance Validation", advanceValidationAdminPanel);

    tabbedPane.addTab("Post Validation", postValidationPanel);

    getContentPane().add(tabbedPane, java.awt.BorderLayout.CENTER);

    defaultMenuBar.setFocusable(false);
    fileMenu.setText("File");
    fileMenu.add(jSeparator11);

    exitMenuItem.setMnemonic('E');
    exitMenuItem.setText("Exit");
    exitMenuItem.setToolTipText("Exit this screen and return to the Activity Selection screen.");
    exitMenuItem.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            exitMenuItemActionPerformed(evt);
          }
        });

    fileMenu.add(exitMenuItem);

    defaultMenuBar.add(fileMenu);

    helpMenu.setText("Help");
    contentsMenuItem.setText("Contents");
    helpMenu.add(contentsMenuItem);

    aboutMenuItem.setText("About");
    helpMenu.add(aboutMenuItem);

    defaultMenuBar.add(helpMenu);

    setJMenuBar(defaultMenuBar);

    pack();
  } // </editor-fold>//GEN-END:initComponents

  private void tabbedPaneStateChanged(
      javax.swing.event.ChangeEvent evt) { // GEN-FIRST:event_tabbedPaneStateChanged
    // Add your handling code here:
    try {
      AbstractPage newPage = (AbstractPage) tabbedPane.getSelectedComponent();

      Log.print(
          "AdminFrame.stateChanged: currentPage: "
              + (currentPage == null ? "null" : currentPage.getClass().getName()));

      // ignore if we aren't changing tabs
      // presumably, we failed to change tabs and are now resetting
      // also ignore first time -- we do at window opening
      if (currentPage == newPage || currentPage == null) {
        return;
      }

      // Log.print("AdminFrame.stateChanged: newPage: " + newPage.getClass().getName());

      // tab doesn't get focus before switch, so we need to check here that
      // this tab switch is acceptable
      // Also, initial tab setting could happen before window is visible,
      // so we do the initial call in the WindowOpening event

      if (currentPage.exitPageCheck()) {
        // open the page
        openNewPage(newPage);
      } else {
        // page did not permit exit (e.g., failed save check)
        tabbedPane.setSelectedComponent(currentPage);
      }
    } catch (Throwable t) {
      Log.quit(t);
    }
  } // GEN-LAST:event_tabbedPaneStateChanged

  private void openNewPage(AbstractPage newPage) {

    currentPage = newPage;

    // ????  TBD beans.Focus.setCurrentPage(currentPage); -- in RCAP

    // Install the correct menu bar
    JMenuBar menuBar = newPage.getPageJMenuBar();
    this.setJMenuBar(menuBar);
    // This command cause the new menuBar to be displayed
    menuBar.revalidate();

    // call page-specific initialization code
    // it should do any required enables, etc.
    currentPage.tabSelected();
  }

  private void formWindowOpened(
      java.awt.event.WindowEvent evt) { // GEN-FIRST:event_formWindowOpened
    // Add your handling code here:
    try {
      // Close the login frame, if any.  (This is done the first time the window is made visible.)
      if (loginFrame != null) {
        loginFrame.dispose();
        loginFrame = null;
      }

      // hide any invalid pages
      if (!Global.theServerConnection.getPermissionAdmin()
          && !Global.theServerConnection.getPermissionTeamLeader()) {
        tabbedPane.remove(sessionPanel);
      }
      if (!Global.theServerConnection.getPermissionAdminProject()) {
        tabbedPane.remove(projectPanel);
      }
      if (!Global.theServerConnection.getPermissionAdminUsers()) {
        tabbedPane.remove(userAdminPanel);
        tabbedPane.remove(teamAdminPanel);
      }
      if (!Global.theServerConnection.getPermissionAdminImport()) {
        tabbedPane.remove(importPanel);
        tabbedPane.remove(populatePanel);
      }
      if (!Global.theServerConnection.getPermissionAdminExport()) {
        tabbedPane.remove(exportPanel);
      }
      if (!Global.theServerConnection.getPermissionAdminProfit()) {
        tabbedPane.remove(receivablesPanel);
      }
      if (!Global.theServerConnection.getPermissionAdminBatch()) {
        tabbedPane.remove(batchingPanel);
      }
      if (!Global.theServerConnection.getPermissionAdmin()) {
        tabbedPane.remove(tablePanel);
        tabbedPane.remove(reportPanel);
        tabbedPane.remove(sessionPanel);
      }

      // Open the first page, after window is open
      AbstractPage newPage = (AbstractPage) tabbedPane.getSelectedComponent();
      openNewPage(newPage);
    } catch (Throwable t) {
      Log.quit(t);
    }
  } // GEN-LAST:event_formWindowOpened

  private void exitMenuItemActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_exitMenuItemActionPerformed
    // Add your handling code here:
    exitForm(null);
  } // GEN-LAST:event_exitMenuItemActionPerformed

  /** Exit the Application. Note: This may be called from the various tab pages. */
  public void exitForm(java.awt.event.WindowEvent evt) { // GEN-FIRST:event_exitForm
    try {
      // close the server and image server connections gently
      // TBD: really should be in a client task
      Log.print("AdminFrame.exitForm");
      try {
        client.Global.theServerConnection.shutdown();
        closeSession(evt);
      } catch (Exception e) {
      }
      try {
        synchronized (ImageThread.class) {
          if (Global.theImageConnection != null) {
            Global.theImageConnection.shutdown();
          }
        }
      } catch (Exception e) {
      }
      System.exit(0);
    } catch (Throwable th) {
      Log.quit(th);
    }
    System.exit(0);
  } // GEN-LAST:event_exitForm

  public void closeSession(java.awt.event.WindowEvent evt) {
    try {
      // close the server and image server connections gently
      // TBD: really should be in a client task
      try {
        // client.Global.theServerConnection.shutdown();
        final ClientTask task;
        task = new TaskGoodbye();
        task.enqueue(this);

      } catch (Exception e) {
      }
      //            try {
      //                client.Global.theImageConnection.shutdown();
      //            } catch (Exception e) {
      //            }
      System.exit(0);
    } catch (Throwable th) {
      Log.quit(th);
    }
  }
  /**
   * Make this frame visible. Overrides JFrame.setVisible to record the current visible frame for
   * use in dialogs.
   *
   * @param flag true to set the adminFrame visible, else false
   */
  public void setVisible(boolean flag) {
    if (flag) {
      Global.mainWindow = this;
    } else if (Global.mainWindow == this) {
      Global.mainWindow = null;
    }
    super.setVisible(flag);
  }

  /** Called from model.MailreceivedManagedModel to see if the currently-visible page is "Mail". */
  public String getVisibleName() {
    return currentPage.getClass().getName();
  }

  /** @param args the command line arguments */
  public static void main(String args[]) {
    new AdminFrame(null).setVisible(true);
  }

  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JMenuItem aboutMenuItem;
  private javax.swing.JPanel batchingPanel;
  private javax.swing.JMenuItem contentsMenuItem;
  private javax.swing.JMenuBar defaultMenuBar;
  private javax.swing.JMenuItem exitMenuItem;
  private javax.swing.JPanel exportPanel;
  private javax.swing.JMenu fileMenu;
  private javax.swing.JMenu helpMenu;
  private javax.swing.JPanel importPanel;
  private javax.swing.JMenu jMenu1;
  private javax.swing.JMenuBar jMenuBar1;
  private javax.swing.JSeparator jSeparator11;
  private javax.swing.JPanel mailPanel;
  private javax.swing.JPanel populatePanel;
  private javax.swing.JPanel advanceValidationAdminPanel;
  private javax.swing.JPanel postValidationPanel;
  private javax.swing.JPanel pricePanel;
  private javax.swing.JPanel projectPanel;
  private javax.swing.JPanel receivablesPanel;
  private javax.swing.JPanel reportPanel;
  private javax.swing.JPanel sessionPanel;
  private javax.swing.JTabbedPane tabbedPane;
  private javax.swing.JPanel tablePanel;
  private javax.swing.JPanel teamAdminPanel;
  private javax.swing.JPanel userAdminPanel;
  // End of variables declaration//GEN-END:variables

}