/* (non-Javadoc)
   * @see edu.ku.brc.af.ui.forms.validation.TypeSearchForQueryFactory#getDOMFromResource(java.lang.String, java.lang.String)
   */
  public Element getDOMFromResource(final String name, final String localPath) {
    SpecifyAppContextMgr acMgr = (SpecifyAppContextMgr) AppContextMgr.getInstance();
    DataProviderSessionIFace session = null;
    try {
      session = DataProviderFactory.getInstance().createSession();

      String[] dirs = {SpecifyAppContextMgr.COMMONDIR, SpecifyAppContextMgr.BACKSTOPDIR};
      for (String dirName : dirs) {
        SpAppResourceDir appResDir = acMgr.getSpAppResourceDirByName(dirName);
        if (appResDir != null) {
          SpAppResource appRes = appResDir.getResourceByName(name);
          if (appRes != null) {
            session.close();
            session = null;

            return AppContextMgr.getInstance().getResourceAsDOM(appRes);
          }
        }
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
      edu.ku.brc.exceptions.ExceptionTracker.getInstance()
          .capture(SpecifyUIFieldFormatterMgr.class, ex);

    } finally {
      if (session != null) {
        session.close();
      }
    }

    return XMLHelper.readDOMFromConfigDir(localPath); // $NON-NLS-1$
  }
  /**
   * Saves an Discipline level XML document to a Database Resource.
   *
   * @param resName the name of the resource
   * @param xml the XML to be saved.
   */
  public void saveResource(final String resName, final String xml) {
    // System.out.println("Saved");
    // System.out.println(xml);
    // System.out.println();

    SpecifyAppContextMgr acMgr = (SpecifyAppContextMgr) AppContextMgr.getInstance();
    DataProviderSessionIFace session = null;
    try {
      session = DataProviderFactory.getInstance().createSession();

      SpAppResource appRes = null;
      SpAppResourceDir commonResDir =
          acMgr.getSpAppResourceDirByName(SpecifyAppContextMgr.COMMONDIR);
      if (commonResDir != null) {
        appRes = commonResDir.getResourceByName(resName);
        if (appRes == null) {
          SpAppResourceDir backStopResDir =
              acMgr.getSpAppResourceDirByName(SpecifyAppContextMgr.BACKSTOPDIR);
          appRes = backStopResDir.getResourceByName(resName);
          if (appRes != null) {
            backStopResDir.getSpAppResources().remove(appRes);
            commonResDir.getSpAppResources().add(appRes);
            appRes.setSpAppResourceDir(commonResDir);
          } else {
            // major error
            UIRegistry.showError("Major Error");
          }
        }

        if (appRes != null) {
          session.close();
          session = null;

          appRes.setDataAsString(xml);
          AppContextMgr.getInstance().saveResource(appRes);

        } else {
          UIRegistry.showError("Major Error #2");
        }
      }

      /*if (appRes == null)
      {
          SpAppResource backStopDir = acMgr.getSpAppResourceDirByName(BACKSTOPDIR).getResourceByName(resName);
          if (appResDir != null)
          {
              SpAppResource newAppRes  = new SpAppResource();
              newAppRes.initialize();
              if (diskAppRes != null)
              {
                  newAppRes.setMetaData(diskAppRes.getMetaData());
                  newAppRes.setDescription(diskAppRes.getDescription());
                  newAppRes.setFileName(diskAppRes.getFileName());
                  newAppRes.setMimeType(diskAppRes.getMimeType());
                  newAppRes.setName(diskAppRes.getName());

                  newAppRes.setLevel(diskAppRes.getLevel());
              } else
              {
                  newAppRes.setName(resName);
                  newAppRes.setLevel((short)0);
                  newAppRes.setMimeType("text/xml");
              }

              Agent agent = AppContextMgr.getInstance().getClassObject(Agent.class);
              newAppRes.setCreatedByAgent(agent);
              newAppRes.setSpecifyUser(user);

              newAppRes.setSpAppResourceDir(appResDir);
              appResDir.getSpAppResources().add(newAppRes);
              newAppRes.setDataAsString(xml);

              session.close();
              session = null;
              ((SpecifyAppContextMgr) AppContextMgr.getInstance()).saveResource(newAppRes);

          } else
          {
              AppContextMgr.getInstance().putResourceAsXML(resName, xml); //$NON-NLS-1$
          }
      }*/

    } catch (Exception ex) {
      ex.printStackTrace();
      edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
      edu.ku.brc.exceptions.ExceptionTracker.getInstance()
          .capture(SpecifyUIFieldFormatterMgr.class, ex);

    } finally {
      if (session != null) {
        session.close();
      }
    }
  }
예제 #3
0
  public void generateFormImages() {
    if (setup()) {
      createFormImagesIndexFile();
    }

    int userChoice =
        JOptionPane.showConfirmDialog(
            getTopWindow(),
            getResourceString("FormDisplayer.CHOOSE_VIEWLIST"), // $NON-NLS-1$
            getResourceString("FormDisplayer.CHOOSE_VIEWLIST_TITLE"), // $NON-NLS-1$
            JOptionPane.YES_NO_OPTION);

    doAll = userChoice == JOptionPane.YES_OPTION ? true : false;

    if (setup()) {

      SpecifyAppContextMgr appContext = (SpecifyAppContextMgr) AppContextMgr.getInstance();

      viewList = doAll ? appContext.getEntirelyAllViews() : appContext.getAllViews();
      SwingUtilities.invokeLater(
          new Runnable() {

            /* (non-Javadoc)
             * @see java.lang.Runnable#run()
             */
            public void run() {
              showView();
            }
          });
    }

    JButton stopBtn = UIHelper.createButton("Stop Generating Images");
    PanelBuilder pb = new PanelBuilder(new FormLayout("p", "p"));
    pb.add(stopBtn, (new CellConstraints()).xy(1, 1));
    pb.setDefaultDialogBorder();
    cancelDlg =
        new CustomDialog(
            (Frame) null, "Stop Image Generation", false, CustomDialog.OK_BTN, pb.getPanel());
    cancelDlg.setOkLabel(getResourceString("CLOSE"));

    cancelDlg.setAlwaysOnTop(true);
    cancelDlg.setVisible(true);

    // Insets    screenInsets =
    // Toolkit.getDefaultToolkit().getScreenInsets(cancelDlg.getGraphicsConfiguration());;
    Rectangle screenRect = cancelDlg.getGraphicsConfiguration().getBounds();
    int y = screenRect.height - (cancelDlg.getSize().height * 2);
    cancelDlg.setLocation(screenRect.x, y);

    stopBtn.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    synchronized (okToProc) {
                      okToProc.set(false);
                      viewInx = viewList.size();
                    }
                  }
                });
          }
        });
  }