Beispiel #1
2
  protected void runScript(String[] cmd, JTextArea txaMsg) {
    String strg = "";

    if (cmd == null) return;

    Process prcs = null;
    try {
      Messages.postDebug("Running script: " + cmd[2]);
      Runtime rt = Runtime.getRuntime();

      prcs = rt.exec(cmd);

      if (prcs == null) return;

      InputStream istrm = prcs.getInputStream();
      if (istrm == null) return;

      BufferedReader bfr = new BufferedReader(new InputStreamReader(istrm));

      while ((strg = bfr.readLine()) != null) {
        // System.out.println(strg);
        strg = strg.trim();
        // Messages.postDebug(strg);
        strg = strg.toLowerCase();
        if (txaMsg != null) {
          txaMsg.append(strg);
          txaMsg.append("\n");
        }
      }
    } catch (Exception e) {
      // e.printStackTrace();
      Messages.writeStackTrace(e);
      Messages.postDebug(e.toString());
    } finally {
      // It is my understanding that these streams are left
      // open sometimes depending on the garbage collector.
      // So, close them.
      try {
        if (prcs != null) {
          OutputStream os = prcs.getOutputStream();
          if (os != null) os.close();
          InputStream is = prcs.getInputStream();
          if (is != null) is.close();
          is = prcs.getErrorStream();
          if (is != null) is.close();
        }
      } catch (Exception ex) {
        Messages.writeStackTrace(ex);
      }
    }
  }
Beispiel #2
0
    protected void buildPanel(String strPath) {
      BufferedReader reader = WFileUtil.openReadFile(strPath);
      String strLine;

      if (reader == null) return;

      try {
        while ((strLine = reader.readLine()) != null) {
          if (strLine.startsWith("#") || strLine.startsWith("%") || strLine.startsWith("@"))
            continue;

          StringTokenizer sTokLine = new StringTokenizer(strLine, ":");

          // first token is the label e.g. Password Length
          if (sTokLine.hasMoreTokens()) {
            createLabel(sTokLine.nextToken(), this);
          }

          // second token is the value
          String strValue = sTokLine.hasMoreTokens() ? sTokLine.nextToken() : "";
          if (strValue.equalsIgnoreCase("yes") || strValue.equalsIgnoreCase("no"))
            createChkBox(strValue, this);
          else createTxf(strValue, this);
        }
      } catch (Exception e) {
        Messages.writeStackTrace(e);
        // e.printStackTrace();
        Messages.postDebug(e.toString());
      }
    }
Beispiel #3
0
  public void buildPanel() {
    String path = FileUtil.getLayoutPath(layoutDir, fname);
    if (path == null) {
      Messages.postError("Could not open xml file:" + fname);
      return;
    }
    removeAll();
    try {
      LayoutBuilder.build(pane, vnmrIf, path);
    } catch (Exception e) {
      String strError = "Error building file: " + path;
      Messages.postError(strError);
      Messages.writeStackTrace(e);
      return;
    }

    if (bScrollBar) {
      spane =
          new JScrollPane(
              pane,
              JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
              JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
      add(spane);
    } else {
      spane = null;
      add(pane);
    }
    paramsLayout.preferredLayoutSize(pane);
  }
    /** Displays the labels and the values for the panel. */
    protected void displayPnlFields(HashMap hmPnl) {
      if (hmPnl == null || hmPnl.isEmpty()) return;

      Iterator keySetItr = hmPnl.keySet().iterator();
      String strLabel = "";
      String strValue = "";

      // if the file is empty, then create an empty set of textfields.
      if (hmPnl == null || hmPnl.isEmpty()) {
        displayNewTxf("", "");
        return;
      }

      Container container = getParent();
      if (container != null) container.setVisible(false);
      try {
        // Get each set of label and value, and display them.
        while (keySetItr.hasNext()) {
          strLabel = (String) keySetItr.next();
          strValue = (String) hmPnl.get(strLabel);

          displayNewTxf(strLabel, strValue);
        }

        if (container != null) container.setVisible(true);
        revalidate();
        repaint();
      } catch (Exception e) {
        Messages.writeStackTrace(e);
        // e.printStackTrace();
        Messages.postDebug(e.toString());
      }
    }
Beispiel #5
0
  /** Write file with position and size of the login box */
  public static void writePersistence() {

    Messages.postDebug("LoginBox", "LoginBox.writePersistence");
    // If the panel has not been created, don't try to write a file
    if (position == null) return;

    String filepath = FileUtil.savePath("USER/PERSISTENCE/LoginPanel");

    FileWriter fw;
    PrintWriter os;
    try {
      File file = new File(filepath);
      fw = new FileWriter(file);
      os = new PrintWriter(fw);
      os.println("Login Panel");

      os.println(height);
      os.println(width);
      double xd = position.getX();
      int xi = (int) xd;
      os.println(xi);
      double yd = position.getY();
      int yi = (int) yd;
      os.println(yi);

      os.close();
    } catch (Exception er) {
      Messages.postError("Problem creating  " + filepath);
      Messages.writeStackTrace(er);
    }
  }
Beispiel #6
0
 private void setCaretValue(String s) {
   try {
     int i = Integer.parseInt(s);
     setCaretValue(i);
   } catch (NumberFormatException e) {
     Messages.writeStackTrace(e);
     // System.out.println("invalid caret position "+caretValue);
   }
 }
Beispiel #7
0
 public void setVisible(boolean bShow, String title) {
   if (bShow) {
     String strDir = "";
     String strFreq = "";
     String strTraynum = "";
     m_strHelpFile = getHelpFile(title);
     String strSampleName = getSampleName(title);
     String frameBounds = getFrameBounds(title);
     StringTokenizer tok = new QuotedStringTokenizer(title);
     if (tok.hasMoreTokens()) strDir = tok.nextToken();
     if (tok.hasMoreTokens()) strFreq = tok.nextToken();
     if (tok.hasMoreTokens()) strTraynum = tok.nextToken();
     else {
       try {
         Integer.parseInt(strDir);
         // if strdir is number, then strdir is empty, and the
         // strfreq is the number
         strTraynum = strFreq;
         strFreq = strDir;
         strDir = "";
       } catch (Exception e) {
       }
     }
     try {
       setTitle(gettitle(strFreq));
       m_lblSampleName.setText("3");
       boolean bVast = isVast(strTraynum);
       CardLayout layout = (CardLayout) m_pnlSampleName.getLayout();
       if (!bVast) {
         if (strSampleName == null) {
           strSampleName = getSampleName(strDir, strTraynum);
         }
         m_lblSampleName.setText(strSampleName);
         layout.show(m_pnlSampleName, OTHER);
       } else {
         m_strDir = strDir;
         setTrays();
         layout.show(m_pnlSampleName, VAST);
         m_trayTimer.start();
       }
       boolean bSample = bVast || !strSampleName.trim().equals("");
       m_pnlSampleName.setVisible(bSample);
       m_lblLogin.setForeground(getBackground());
       m_lblLogin.setVisible(false);
       m_passwordField.setText("");
       m_passwordField.setCaretPosition(0);
     } catch (Exception e) {
       Messages.writeStackTrace(e);
     }
     setBounds(frameBounds);
     ExpPanel exp = Util.getActiveView();
     if (exp != null) exp.waitLogin(true);
   }
   writePersistence();
   setVisible(bShow);
 }
Beispiel #8
0
  protected String getSampleName(String strDir, String strTray) {
    String strSampleName = "";
    String strSample;
    int nTray = 0;
    try {
      nTray = Integer.parseInt(strTray);
    } catch (Exception e) {
    }

    if (nTray <= 0) return strSampleName;

    String cmd =
        "SELECT loc_,studystatus from study WHERE (autodir=\'"
            + strDir
            + "\') AND (hostname=\'"
            + getHost()
            + "\')";
    // NB: bArrSample[0] is not used; array implicitly initialized false
    boolean[] bArrSample = new boolean[nTray + 1];
    m_dbResult = null;

    try {
      m_dbResult = getdbmanager().executeQuery(cmd);
    } catch (Exception e) {
      return strSampleName;
    }
    if (m_dbResult == null) return strSampleName;

    try {
      while (m_dbResult.next()) {
        strSample = m_dbResult.getString(1);
        int nSample = 0;
        nSample = Integer.parseInt(strSample);
        try {
          bArrSample[nSample] = true;
        } catch (IndexOutOfBoundsException ioobe) {
          Messages.postDebug("getSampleName: index out of bounds: " + nSample);
        }
      }
      for (int i = 1; i < bArrSample.length; i++) {
        if (!bArrSample[i]) {
          strSampleName = String.valueOf(i);
          break;
        }
      }
    } catch (Exception e) {
      // e.printStackTrace();
      Messages.writeStackTrace(e);
    }
    return strSampleName;
  }
Beispiel #9
0
  private void addTool(String key, Class tool) {
    Class[] constructArgs = null;
    if (key.equals("XMLToolPanel")) {
      constructArgs = new Class[3];
      constructArgs[0] = vnmr.ui.SessionShare.class;
      constructArgs[1] = String.class;
      constructArgs[2] = String.class;
    } else {
      constructArgs = new Class[1];
      constructArgs[0] = vnmr.ui.SessionShare.class;
    }

    try {
      Constructor c = tool.getConstructor(constructArgs);
      vobjs.put(key, c);
    } catch (NoSuchMethodException nse) {
      Messages.postError("Problem initiating " + key + " area.");
      Messages.writeStackTrace(nse, tool + " not found.");
    } catch (SecurityException se) {
      Messages.postError("Problem initiating " + key + " area.");
      Messages.writeStackTrace(se);
    }
  }
Beispiel #10
0
  protected void setTrayPresent(String strPath) {
    String strzone = "zones";
    BufferedReader reader = WFileUtil.openReadFile(strPath);
    if (reader == null) return;

    String strLine;
    try {
      // if the zones are set to 0, then there is no tray present
      // set rackInfo(1,zones) 3 => tray 1 present
      // set rackInfo(2,zones) 0 => tray 2 not present
      while ((strLine = reader.readLine()) != null) {
        int index = strLine.indexOf(strzone);
        if (index < 0) continue;

        String strTray = strLine.substring(index - 2, index - 1);
        int nTray = 0;
        try {
          nTray = Integer.parseInt(strTray);
        } catch (Exception e) {
        }

        if (nTray <= 0) continue;

        int nZone = 0;
        try {
          strTray = strLine.substring(index + strzone.length() + 2, strLine.length());
          nZone = Integer.parseInt(strTray);
        } catch (Exception e) {
        }

        Color colorbg = Color.white;
        String strTooltip = TRAY;
        if (nZone <= 0) {
          colorbg = Color.black;
          strTooltip = NOTRAY;
        }
        VBox pnlVast = m_pnlVast[nTray - 1];
        pnlVast.setbackground(colorbg);
        pnlVast.setToolTipText(Util.getTooltipString(strTooltip));
      }
      reader.close();
    } catch (Exception e) {
      // e.printStackTrace();
      Messages.writeStackTrace(e);
    }
  }
Beispiel #11
0
  protected void setTrayActive(String strDir) {
    String strTray;
    String strStudy;
    String strActive = "Active";
    String cmd =
        "SELECT vrack_,studystatus from study WHERE (autodir=\'"
            + strDir
            + "\') AND (hostname=\'"
            + getHost()
            + "\')";
    m_dbResult = null;

    try {
      m_dbResult = getdbmanager().executeQuery(cmd);
    } catch (Exception e) {
      return;
    }
    if (m_dbResult == null) return;

    int nTray = 0;
    try {
      while (m_dbResult.next()) {
        strTray = m_dbResult.getString(1);
        strStudy = m_dbResult.getString(2);
        if (strStudy != null && strStudy.equalsIgnoreCase(strActive)) {
          try {
            nTray = Integer.parseInt(strTray);
          } catch (Exception e) {
          }

          if (nTray > 0) {
            m_pnlVast[nTray - 1].setbackground(Color.blue);
            m_pnlVast[nTray - 1].setToolTipText(Util.getTooltipString(TRAYACTIVE));
            break;
          }
        }
      }
    } catch (Exception e) {
      // e.printStackTrace();
      Messages.writeStackTrace(e);
    }
  }
Beispiel #12
0
  protected static boolean vnmrjPassword(String strUser, char[] password) {
    boolean blogin = false;
    try {
      PasswordService objPassword = PasswordService.getInstance();
      String encrPassword = objPassword.encrypt(new String(password));
      if (pwprops == null) {
        String strPath = FileUtil.openPath(WUserUtil.PASSWORD);
        if (strPath == null) return blogin;
        pwprops = new Properties();
        FileInputStream fis = new FileInputStream(strPath);
        pwprops.load(fis);
        fis.close();
      }
      String stoPassword = pwprops.getProperty(strUser);
      if (encrPassword.equals(stoPassword)) blogin = true;
    } catch (Exception e) {
      // e.printStackTrace();
      Messages.writeStackTrace(e);
    }

    return blogin;
  }
Beispiel #13
0
  protected void setVast() {
    String strPath = FileUtil.openPath("SYSTEM/asm/gilsonNumber");
    if (strPath == null) return;

    BufferedReader reader = WFileUtil.openReadFile(strPath);
    if (reader == null) return;

    String strLine;
    int i = 0;
    try {
      while ((strLine = reader.readLine()) != null) {
        strLine = strLine.trim();
        if (i == 0 || !m_aStrVast[i - 1].equals(strLine)) {
          m_aStrVast[i] = strLine;
          i = i + 1;
        }
      }
      reader.close();
    } catch (Exception e) {
      // e.printStackTrace();
      Messages.writeStackTrace(e);
    }
  }
Beispiel #14
0
  public void buildConfig() {
    BufferedReader in = WFileUtil.openReadFile(m_strPath);
    String strLine = null;

    if (in == null) {
      Messages.postError("Error opening file " + m_strPath);
      return;
    }

    try {
      m_pnlDisplay.removeAll();
      m_pnlDisplay.setLayout(new WGridLayout(0, 2));
      m_aListComp.clear();
      while ((strLine = in.readLine()) != null) {
        if (strLine.startsWith("#") || strLine.startsWith("%") || strLine.startsWith("@")) continue;
        StringTokenizer sTokLine = new StringTokenizer(strLine, File.pathSeparator);
        createJComps(sTokLine);
      }
      setVisible(true);
    } catch (Exception e) {
      // e.printStackTrace();
      Messages.writeStackTrace(e);
    }
  }
Beispiel #15
0
  /**
   * Save the data to the file. Read the data from the file, and copy everything to the
   * stringbuffer. The lines in the file are of the form:
   * auditDir:system:/vnmr/part11/auditTrails:system file:standard:text:yes Based on these formats,
   * get the value of either the directory or the checkbox from the corresponding components, and
   * replace that value in the stringbuffer.
   */
  protected void saveData() {
    BufferedReader reader = WFileUtil.openReadFile(m_strPath);
    String strLine = null;
    StringBuffer sbData = new StringBuffer();
    if (reader == null) return;

    int nLineInd = 0;
    try {
      while ((strLine = reader.readLine()) != null) {
        // if the line starts with a comment from sccs, add '#' to it,
        // to make it a comment
        if (strLine.startsWith("%") || strLine.startsWith("@")) strLine = "# " + strLine;

        if (strLine.startsWith("#")) {
          sbData.append(strLine + "\n");
          continue;
        }
        StringTokenizer sTok = new StringTokenizer(strLine, File.pathSeparator);
        boolean bFile = false;
        boolean bLineEnd = false;
        boolean bDir = false;

        for (int i = 0; sTok.hasMoreTokens(); i++) {
          String strValue = sTok.nextToken();
          if (i == 0) {
            bFile = strValue.equalsIgnoreCase("file") ? true : false;
            bDir = false;
            if (strValue.equalsIgnoreCase("dir")) bDir = true;
          } else {
            // Case => file:standard:procpar:yes
            // skip over 'standard', 'procpar',
            // and get the value 'yes' or 'no' from the checkbox
            if (bFile) {
              if (i == 3) {
                String strNewValue = getValue(nLineInd);
                if (strNewValue != null) strValue = strNewValue;
                bLineEnd = true;
              } else bLineEnd = false;
            } else if (bDir) {
              bLineEnd = false;
              if (i == 3) bLineEnd = true;
            }
            // Case => part11Dir:/vnmr/part11/data 0r
            // Case => dataType:FDA
            // skip over 'part11Dir'
            // and get the value of the directory from the textfield,
            // or from the combobox
            else {
              if (i == 1) {
                String strNewValue = getValue(nLineInd);
                if (strNewValue != null) strValue = strNewValue;
                bLineEnd = true;
              } else bLineEnd = false;
            }
          }
          // copy the value to the stringbuffer
          sbData.append(strValue);
          if (!bLineEnd) sbData.append(File.pathSeparator);
        }
        nLineInd++;
        sbData.append("\n");
      }
      // write the data to the file
      reader.close();
      BufferedWriter writer = WFileUtil.openWriteFile(m_strPath);
      WFileUtil.writeAndClose(writer, sbData);
      m_objTimer =
          new javax.swing.Timer(
              200,
              new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                  VItemAreaIF.firePropertyChng(Global.PART11_CONFIG_FILE, "all", "");
                  m_objTimer.stop();
                }
              });
      m_objTimer.start();
    } catch (Exception e) {
      Messages.writeStackTrace(e);
      // e.printStackTrace();
      Messages.postDebug(e.toString());
    }
  }
    /** Reads the file, and sets the label and the values in the hashmap. */
    protected void setHM(String strPath, HashMap hmPnl) {
      BufferedReader reader = WFileUtil.openReadFile(strPath);
      boolean bFileEmpty = true;
      boolean bPart11Pnl = isPart11Pnl();
      boolean bDefaultFile = isDefaultFile();

      // if the file is empty, then create an empty set of textfields.
      if (reader == null) {
        // displayNewTxf("","");
        return;
      }

      String strLine = null;
      StringTokenizer strTok;

      try {
        // read the file, and create a new set of textfields,
        // with the values from the file.
        while ((strLine = reader.readLine()) != null) {
          String strLabel = "";
          String strValue = "";
          bFileEmpty = false;

          if (strLine.startsWith("#")
              || strLine.startsWith("@")
              || strLine.startsWith("%")
              || strLine.startsWith("\"@")) continue;

          if (strLine.startsWith("\"")) strTok = new StringTokenizer(strLine, "\"");
          else strTok = new StringTokenizer(strLine, File.pathSeparator + ",\n");

          if (!strTok.hasMoreTokens()) continue;

          strLabel = strTok.nextToken();

          // the format for the part11 Default file is a little different
          // only parse out the part11Dir, and don't display other defaults
          if (bPart11Pnl && bDefaultFile) {
            if (!strLabel.equalsIgnoreCase("part11Dir")) continue;
          }

          if (strTok.hasMoreTokens()) {
            while (strTok.hasMoreTokens()) {
              strValue += strTok.nextToken();
              if (strTok.hasMoreTokens()) strValue += " ";
            }
          }

          // append "/data/$name" to part11Dir
          if (bPart11Pnl && bDefaultFile && strLabel.equalsIgnoreCase("part11Dir")) {
            StringBuffer sbDir = new StringBuffer(strValue);
            if (sbDir.lastIndexOf(File.separator) < sbDir.length() - 1)
              sbDir.append(File.separator);
            sbDir.append("data" + File.separator + "$");
            sbDir.append(WGlobal.NAME);
            strValue = sbDir.toString();
          }

          // displayNewTxf(strLabel, strValue);
          if (strLabel != null && strLabel.trim().length() > 0) hmPnl.put(strLabel, strValue);
        }
        reader.close();
      } catch (Exception e) {
        Messages.writeStackTrace(e);
        // e.printStackTrace();
        Messages.postDebug(e.toString());
      }
    }