示例#1
0
  public FormDisplayer() {
    UIHelper.adjustUIDefaults();

    setBaseFont((createLabel("")).getFont()); // $NON-NLS-1$

    Specify.setUpSystemProperties();

    AppPreferences localPrefs = AppPreferences.getLocalPrefs();
    localPrefs.setDirPath(getAppDataDir());

    UIFieldFormatterMgr.setDoingLocal(true);
    DataObjFieldFormatMgr.setDoingLocal(true);
    TypeSearchForQueryFactory.setDoingLocal(true);
  }
示例#2
0
  /** Create the UI for the panel */
  protected void createUI() {
    createForm("Preferences", "LoansPrefs");
    AppPreferences prefs = AppPreferences.getRemote();

    Integer dueInMonths = prefs.getInt(DUEINMONTHS, 6);
    String shippingMethod = prefs.get(LoanGiftShipmentBusRules.SHIPMETHOD, null);
    Integer shippedByAgentId = prefs.getInt(LoanGiftShipmentBusRules.SHIPPEDBY, null);

    FormViewObj fvo = (FormViewObj) form;

    ValSpinner dueSpinner = fvo.getCompById("OVERDUETIME");
    if (dueSpinner != null) {
      dueSpinner.setValue(dueInMonths);
    }

    ValComboBox shipMeth = fvo.getCompById("SHIPMETH");
    if (shipMeth != null) {
      shipMeth.setValue(shippingMethod, null);
    }

    ValComboBoxFromQuery shippedBy = fvo.getCompById("SHIPPEDBY");
    if (shippedBy != null && shippedByAgentId != null) {
      DataProviderSessionIFace session = null;
      try {
        session = DataProviderFactory.getInstance().createSession();
        Agent agent = session.get(Agent.class, shippedByAgentId);
        shippedBy.setValue(agent, null);

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

      } finally {
        if (session != null) {
          session.close();
        }
      }
    }
  }
示例#3
0
  /* (non-Javadoc)
   * @see edu.ku.brc.af.prefs.GenericPrefsPanel#savePrefs()
   */
  @Override
  public void savePrefs() {
    AppPreferences prefs = AppPreferences.getRemote();

    FormViewObj fvo = (FormViewObj) form;

    ValSpinner dueSpinner = fvo.getCompById("OVERDUETIME");
    if (dueSpinner != null) {
      Integer val = (Integer) dueSpinner.getValue();
      if (val != null) {
        prefs.putInt(DUEINMONTHS, val);
      }
    }

    ValComboBox shipMeth = fvo.getCompById("SHIPMETH");
    if (shipMeth != null) {
      String method = (String) shipMeth.getValue();
      if (method != null) {
        prefs.put(LoanGiftShipmentBusRules.SHIPMETHOD, method);
      }
    }

    ValComboBoxFromQuery shippedBy = fvo.getCompById("SHIPPEDBY");
    if (shippedBy != null) {
      Agent agent = (Agent) shippedBy.getValue();
      if (agent != null) {
        prefs.putInt(LoanGiftShipmentBusRules.SHIPPEDBY, agent.getAgentId());
      } else {
        prefs.remove(LoanGiftShipmentBusRules.SHIPPEDBY);
      }
    }
  }
  /* (non-Javadoc)
   * @see edu.ku.brc.af.core.expresssearch.QueryAdjusterForDomain#adjustSQL(java.lang.String, boolean)
   */
  @Override
  public String adjustSQL(final String sql) {
    AppPreferences locPrefs = AppPreferences.getLocalPrefs();
    boolean doGlobalSearch =
        permsOKForGlobalSearch
            && locPrefs.getBoolean("GLOBAL_SEARCH_AVAIL", false)
            && locPrefs.getBoolean("GLOBAL_SEARCH", false);
    // divisionCnt++;
    // disciplineCnt++;
    // collectionCnt++;

    // SpecifyUser should NEVER be null nor the Id !
    SpecifyUser user = AppContextMgr.getInstance().getClassObject(SpecifyUser.class);
    if (user != null) {
      Integer id = user.getId();
      if (id != null) {
        String adjSQL = sql;
        if (StringUtils.contains(adjSQL, SPECIFYUSERID)) {
          adjSQL = StringUtils.replace(adjSQL, SPECIFYUSERID, Integer.toString(id));
        }

        if (StringUtils.contains(adjSQL, DIVID)) {
          String adjustedSQL = null;
          if (doGlobalSearch || divisionCnt == 1) {
            adjustedSQL = removeSpecialFilter(adjSQL, DIVID);
          }

          if (adjustedSQL == null) {
            Integer divId = null;
            Division division = AppContextMgr.getInstance().getClassObject(Division.class);
            if (division != null) {
              divId = division.getId();
            } else {
              divId =
                  Agent.getUserAgent().getDivision() != null
                      ? Agent.getUserAgent().getDivision().getDivisionId()
                      : null;
            }

            if (divId != null) {
              adjSQL = StringUtils.replace(adjSQL, DIVID, Integer.toString(divId));
            }
          } else {
            adjSQL = adjustedSQL;
          }
        }

        // System.out.println(adjSQL);
        if (StringUtils.contains(adjSQL, COLMEMID)) {
          String adjustedSQL = null;
          if (doGlobalSearch || collectionCnt == 1) {
            adjustedSQL = removeSpecialFilter(adjSQL, COLMEMID);
          }

          if (adjustedSQL == null) {
            Collection collection = AppContextMgr.getInstance().getClassObject(Collection.class);
            if (collection != null) {
              adjSQL =
                  StringUtils.replace(
                      adjSQL, COLMEMID, Integer.toString(collection.getCollectionId()));
            }
          } else {
            adjSQL = adjustedSQL;
          }
        }

        if (StringUtils.contains(adjSQL, COLLID)) {
          String adjustedSQL = null;
          if (doGlobalSearch || collectionCnt == 1) {
            adjustedSQL = removeSpecialFilter(adjSQL, COLLID);
          }

          if (adjustedSQL == null) {
            Collection collection = AppContextMgr.getInstance().getClassObject(Collection.class);
            if (collection != null) {
              adjSQL =
                  StringUtils.replace(
                      adjSQL, COLLID, Integer.toString(collection.getCollectionId()));
            }
          } else {
            adjSQL = adjustedSQL;
          }
        }

        if (StringUtils.contains(adjSQL, DSPLNID)) {
          String adjustedSQL = null;
          if (doGlobalSearch || disciplineCnt == 1) {
            adjustedSQL = removeSpecialFilter(adjSQL, DSPLNID);
          }

          if (adjustedSQL == null) {
            Discipline discipline = AppContextMgr.getInstance().getClassObject(Discipline.class);
            if (discipline != null) {
              adjSQL =
                  StringUtils.replace(
                      adjSQL, DSPLNID, Integer.toString(discipline.getDisciplineId()));
            }
          } else {
            adjSQL = adjustedSQL;
          }
        }

        if (StringUtils.contains(adjSQL, TAXTREEDEFID)) {
          TaxonTreeDef taxonTreeDef =
              AppContextMgr.getInstance().getClassObject(TaxonTreeDef.class);
          if (taxonTreeDef != null) {
            adjSQL =
                StringUtils.replace(
                    adjSQL, TAXTREEDEFID, Integer.toString(taxonTreeDef.getTaxonTreeDefId()));
          }
        }

        if (StringUtils.contains(adjSQL, GTPTREEDEFID)) {
          GeologicTimePeriodTreeDef gtpTreeDef =
              AppContextMgr.getInstance().getClassObject(GeologicTimePeriodTreeDef.class);
          if (gtpTreeDef != null) {
            adjSQL =
                StringUtils.replace(
                    adjSQL,
                    GTPTREEDEFID,
                    Integer.toString(gtpTreeDef.getGeologicTimePeriodTreeDefId()));
          } else {
            return null;
          }
        }

        if (StringUtils.contains(adjSQL, STORTREEDEFID)) {
          StorageTreeDef locTreeDef =
              AppContextMgr.getInstance().getClassObject(StorageTreeDef.class);
          if (locTreeDef != null) {
            adjSQL =
                StringUtils.replace(
                    adjSQL, STORTREEDEFID, Integer.toString(locTreeDef.getStorageTreeDefId()));
          }
        }

        if (StringUtils.contains(adjSQL, LITHOTREEDEFID)) {
          LithoStratTreeDef lithoTreeDef =
              AppContextMgr.getInstance().getClassObject(LithoStratTreeDef.class);
          if (lithoTreeDef != null) {
            adjSQL =
                StringUtils.replace(
                    adjSQL,
                    LITHOTREEDEFID,
                    Integer.toString(lithoTreeDef.getLithoStratTreeDefId()));
          } else {
            return null;
          }
        }

        if (StringUtils.contains(adjSQL, GEOTREEDEFID)) {
          GeographyTreeDef lithoTreeDef =
              AppContextMgr.getInstance().getClassObject(GeographyTreeDef.class);
          if (lithoTreeDef != null) {
            adjSQL =
                StringUtils.replace(
                    adjSQL, GEOTREEDEFID, Integer.toString(lithoTreeDef.getGeographyTreeDefId()));
          }
        }

        return adjSQL;
      }
      throw new RuntimeException("The SpecifyUser ID cannot be null!");

    } else {
      throw new RuntimeException("The SpecifyUser cannot be null!");
    }
  }
  /* (non-Javadoc)
   * @see edu.ku.brc.ui.forms.formatters.DataObjFieldFormatPanelBuilder#buildUI()
   */
  protected void buildUI() {
    CellConstraints cc = new CellConstraints();

    JLabel currentFieldsLbl = createI18NLabel("DOF_DISPLAY_FORMAT");
    formatEditor = new JTextPane();
    // to make sure the component shrinks with the dialog
    formatEditor.setMinimumSize(new Dimension(200, 50));
    formatEditor.setPreferredSize(new Dimension(350, 100));

    formatEditor
        .getDocument()
        .addDocumentListener(
            new DocumentAdaptor() {
              @Override
              public void changed(DocumentEvent e) {
                updateUIEnabled();
              }
            });

    PanelBuilder addFieldPB = new PanelBuilder(new FormLayout("p,2px,p,f:p:g,r:m", "p,2px,p"));
    sepText = createTextField(4);
    addFieldBtn = createButton(getResourceString("DOF_ADD_FIELD"));
    sepLbl = createI18NFormLabel("DOF_SEP_TXT");

    addFieldPB.add(sepLbl, cc.xy(1, 1));
    addFieldPB.add(sepText, cc.xy(3, 1));
    addFieldPB.add(addFieldBtn, cc.xy(5, 1));

    sepText.setDocument(new FilteredDoc());

    addFieldBtn.setEnabled(false);
    sepLbl.setEnabled(false);
    sepText.setEnabled(false);

    // For when it is standalone
    if (AppPreferences.hasRemotePrefs()) {
      sepText.setText(AppPreferences.getRemote().get("DOF_SEP", ", "));

    } else {
      sepText.setText(", ");
    }

    PanelBuilder pb =
        new PanelBuilder(
            new FormLayout(
                "f:d:g",
                "10px,"
                    + // empty space on top of panel
                    "p,f:p:g,"
                    + // Label & format text editor
                    "2px,p,"
                    + // separator & add field
                    "10px,p,"
                    + // separator & label
                    "f:250px:g," // list box for available fields
                ),
            this);

    // layout components on main panel
    int y = 2; // leave first row blank

    pb.add(currentFieldsLbl, cc.xy(1, y));
    y += 1;
    pb.add(UIHelper.createScrollPane(formatEditor), cc.xy(1, y));
    y += 2;

    pb.add(addFieldPB.getPanel(), cc.xy(1, y));
    y += 2;

    JLabel availableFieldsLbl = createI18NFormLabel("DOF_AVAILABLE_FIELDS", SwingConstants.LEFT);
    pb.add(availableFieldsLbl, cc.xy(1, y));
    y += 1;

    // create field tree that will be re-used in all instances of single switch formatter editing
    // panel
    availableFieldsComp =
        new AvailableFieldsComponent(
            tableInfo, dataObjFieldFormatMgrCache, uiFieldFormatterMgrCache);

    pb.add(UIHelper.createScrollPane(availableFieldsComp.getTree()), cc.xy(1, y));
    y += 2;

    availableFieldsComp
        .getTree()
        .addTreeSelectionListener(
            new TreeSelectionListener() {
              @Override
              public void valueChanged(TreeSelectionEvent e) {
                boolean enable = availableFieldsComp.getTree().getSelectionCount() > 0;
                addFieldBtn.setEnabled(enable);
                sepText.setEnabled(enable);
                sepLbl.setEnabled(enable);
              }
            });

    this.mainPanelBuilder = pb;

    fillWithObjFormatter(formatContainer.getSelectedFormatter());

    addFormatTextListeners();

    // must be called after list of available fields has been created
    addFieldListeners();
  }