/**
   * Computes the maximum number of thumbnails to fetch depending on the initial value and the speed
   * of the connection.
   */
  private void computeFetchSize() {
    int value = -1;
    Object fSize = context.lookup(LookupNames.THUMBNAIL_FETCH_SZ);

    if (fSize != null && (fSize instanceof Integer)) value = (Integer) fSize;
    else context.getLogger().warn(this, "Thumbnail fetching size not set");
    if (value <= 0) value = FETCH_SIZE;
    UserCredentials uc = (UserCredentials) context.lookup(LookupNames.USER_CREDENTIALS);
    double f = 0;
    Object fSpeed = null;
    switch (uc.getSpeedLevel()) {
      case UserCredentials.MEDIUM:
        fSpeed = context.lookup(LookupNames.THUMBNAIL_FETCH_MEDIUM_SPEED);
        if (fSpeed != null && (fSpeed instanceof Double)) f = (Double) fSpeed;
        else context.getLogger().warn(this, "Thumbnail " + "fetching factor not set");
        if (f <= 0 || f > 1) f = FETCH_MEDIUM_SPEED;
        fetchSize = (int) (value * f);
        break;
      case UserCredentials.LOW:
        fSpeed = context.lookup(LookupNames.THUMBNAIL_FETCH_LOW_SPEED);
        if (fSpeed != null && (fSpeed instanceof Double)) f = (Double) fSpeed;
        else context.getLogger().warn(this, "Thumbnail " + "fetching factor not set");
        if (f <= 0 || f > 1) f = FETCH_LOW_SPEED;
        fetchSize = (int) (value * f);
        break;
      default:
        fetchSize = value;
    }
  }
Esempio n. 2
0
  /**
   * Returns the experimenter to save.
   *
   * @return See above.
   */
  Object getExperimenterToSave() {
    ExperimenterData original = (ExperimenterData) model.getRefObject();
    // Required fields first

    String v = loginArea.getText();
    if (v == null || v.trim().length() == 0) showRequiredField();
    original.setLastName(v);
    JTextField f = items.get(EditorUtil.EMAIL);
    v = f.getText();
    if (v == null || v.trim().length() == 0) v = ""; // showRequiredField();
    original.setEmail(v);
    f = items.get(EditorUtil.INSTITUTION);
    v = f.getText();
    if (v == null) v = "";
    original.setInstitution(v.trim());
    f = items.get(EditorUtil.LAST_NAME);
    v = f.getText();
    if (v == null) v = "";
    original.setLastName(v.trim());

    f = items.get(EditorUtil.FIRST_NAME);
    v = f.getText();
    if (v == null) v = "";
    original.setFirstName(v.trim());

    f = items.get(EditorUtil.MIDDLE_NAME);
    v = f.getText();
    if (v == null) v = "";
    original.setMiddleName(v.trim());

    // set the groups
    GroupData g = null;
    /*

     	if (selectedIndex != originalIndex) {
     		if (selectedIndex < groupData.length)
     			g = groupData[selectedIndex];
     		ExperimenterData user = (ExperimenterData) model.getRefObject();
     		List userGroups = user.getGroups();
     		List<GroupData> newGroups = new ArrayList<GroupData>();
     		if (g != null) newGroups.add(g);
     		Iterator i = userGroups.iterator();
     		long id = -1;
     		if (g != null) id = g.getId();
     		GroupData group;
     		while (i.hasNext()) {
    	group = (GroupData) i.next();
    	if (group.getId() != id)
    		newGroups.add(group);
    }
     		//Need to see what to do b/c no ExperimenterGroupMap
     		original.setGroups(newGroups);
     	}
     	*/
    String value = loginArea.getText().trim();
    UserCredentials uc = new UserCredentials(value, "");
    Boolean b = ownerBox.isSelected();
    // if (g == null) g = original.getDefaultGroup();
    boolean a = false;
    if (b.compareTo(groupOwner) != 0) {
      a = true;
      uc.setOwner(b);
      Object parent = model.getParentRootObject();
      if (parent instanceof GroupData) {
        Map<GroupData, Boolean> map = new HashMap<GroupData, Boolean>();
        map.put((GroupData) parent, b);
        uc.setGroupsOwner(map);
      }
    }
    if (adminBox.isVisible()) {
      b = adminBox.isSelected();
      if (b.compareTo(admin) != 0) {
        a = true;
        uc.setAdministrator(b);
      }
    }
    if (activeBox.isVisible()) {
      b = activeBox.isSelected();
      if (b.compareTo(active) != 0) {
        a = true;
        uc.setActive(b);
      }
    }
    if (!original.getUserName().equals(value)) a = true;
    // if admin
    if (MetadataViewerAgent.isAdministrator()) a = true;
    if (a) {
      Map<ExperimenterData, UserCredentials> m = new HashMap<ExperimenterData, UserCredentials>();
      m.put(original, uc);
      AdminObject object = new AdminObject(g, m, AdminObject.UPDATE_EXPERIMENTER);
      return object;
    }
    return original; // newOne;
  }