/** * Sets the rendering settings associated to the image. * * @param viewedBy The value to set. */ void setViewedBy(Map viewedBy) { Map m = new LinkedHashMap(); if (viewedBy != null) { long id = MetadataViewerAgent.getUserDetails().getId(); Entry entry; Iterator i = viewedBy.entrySet().iterator(); ExperimenterData exp; while (i.hasNext()) { entry = (Entry) i.next(); exp = (ExperimenterData) entry.getKey(); if (exp.getId() == id) { m.put(exp, entry.getValue()); } } i = viewedBy.entrySet().iterator(); while (i.hasNext()) { entry = (Entry) i.next(); exp = (ExperimenterData) entry.getKey(); if (exp.getId() != id) { m.put(exp, entry.getValue()); } } } this.viewedBy = m; }
/** * Returns <code>true</code> if the user is an administrator, <code>false</code> otherwise. * * @return See above. */ private boolean isUserAdministrator() { ExperimenterData user = (ExperimenterData) model.getRefObject(); ExperimenterData loggedInUser = MetadataViewerAgent.getUserDetails(); if (user.getId() == loggedInUser.getId()) return MetadataViewerAgent.isAdministrator(); List<GroupData> groups = user.getGroups(); Iterator<GroupData> i = groups.iterator(); GroupData g; while (i.hasNext()) { g = i.next(); if (GroupData.SYSTEM.equals(g.getName())) return true; } return false; }
/** * Implemented as specified by the {@link Importer} interface. * * @see Importer#activate(int, TreeImageDisplay, Collection) */ public void activate( int type, TreeImageDisplay selectedContainer, Collection<TreeImageDisplay> objects) { if (model.getState() == DISCARDED) return; if (chooser == null) { chooser = new ImportDialog( view, model.getSupportedFormats(), selectedContainer, objects, type, ImporterAgent.getAvailableUserGroups()); chooser.addPropertyChangeListener(controller); view.addComponent(chooser); } else { ExperimenterData exp = ImporterAgent.getUserDetails(); chooser.reset(selectedContainer, objects, type, model.getGroupId(), exp.getId()); chooser.requestFocusInWindow(); view.selectChooser(); } chooser.setSelectedGroup(getSelectedGroup()); if (model.isMaster() || objects == null || objects.size() == 0) refreshContainers(new ImportLocationDetails(type)); // load available disk space model.fireDiskSpaceLoading(); view.setOnScreen(); view.toFront(); }
/** * Selects or not the {@link #ownerBox} if the selected user is an owner. Returns <code>true * </code> if the currently logged in user is an owner of the group. * * @param group The group to handle. */ private boolean setGroupOwner(GroupData group) { ExperimenterData ref = (ExperimenterData) model.getRefObject(); long userID = MetadataViewerAgent.getUserDetails().getId(); Set leaders = group.getLeaders(); ExperimenterData exp; boolean isOwner = false; if (leaders != null) { Iterator i = leaders.iterator(); while (i.hasNext()) { exp = (ExperimenterData) i.next(); if (exp.getId() == ref.getId()) { groupOwner = true; ownerBox.setSelected(true); } if (exp.getId() == userID) isOwner = true; } } return isOwner; }
/** * Tests the <code>lookupExperimenter</code> method. Retrieves an experimenter and converts the * group into the corresponding POJO. * * @throws Exception Thrown if an error occurred. */ @Test public void testLookupExperimenter() throws Exception { IAdminPrx svc = root.getSession().getAdminService(); Experimenter exp = svc.lookupExperimenter("root"); assertNotNull(exp); // Test the conversion into the corresponding POJO ExperimenterData data = new ExperimenterData(exp); assertTrue(data.getId() == exp.getId().getValue()); assertTrue(data.getUserName() == exp.getOmeName().getValue()); }
/** Refreshes the view when a user reconnects. */ void onReconnected() { ExperimenterData exp = ImporterAgent.getUserDetails(); GroupData group = exp.getDefaultGroup(); long oldGroup = -1; if (model.getExperimenterId() == exp.getId() && group.getId() == model.getGroupId()) return; view.reset(); model.setGroupId(group.getId()); ImportLocationDetails info = new ImportLocationDetails(chooser.getType()); refreshContainers(info); firePropertyChange(CHANGED_GROUP_PROPERTY, oldGroup, model.getGroupId()); }
/** * Sets the action enabled depending on the selected type. * * @see TreeViewerAction#onDisplayChange(TreeImageDisplay) */ protected void onDisplayChange(TreeImageDisplay selectedDisplay) { if (nodeType == GROUP || nodeType == EXPERIMENTER) { setEnabled(TreeViewerAgent.isAdministrator()); return; } if (nodeType != EXPERIMENTER) { if (selectedDisplay != null) { Object ho = selectedDisplay.getUserObject(); if (ho instanceof ExperimenterData) { ExperimenterData data = (ExperimenterData) ho; long id = TreeViewerAgent.getUserDetails().getId(); setEnabled(data.getId() == id); return; } /* switch (nodeType) { case TAG: if (ho instanceof TagAnnotationData) { TagAnnotationData tag = (TagAnnotationData) ho; String ns = tag.getNameSpace(); if (TagAnnotationData.INSIGHT_TAGSET_NS.equals(ns)) { setEnabled(model.isUserOwner(ho)); } else setEnabled(false); } //setEnabled(model.isUserOwner(ho)); break; case DATASET: if (ho instanceof DatasetData) { setEnabled(false); } else setEnabled(model.isUserOwner(ho)); break; default: setEnabled(true); } */ setEnabled(true); } } else { Browser browser = model.getSelectedBrowser(); if (browser == null || selectedDisplay == null) { setEnabled(false); return; } Object ho = selectedDisplay.getUserObject(); if (ho instanceof GroupData) { TreeImageDisplay[] selected = browser.getSelectedDisplays(); setEnabled(selected.length == 1); } else setEnabled(false); } }
/** Initializes the components composing this display. */ private void initComponents() { admin = false; active = false; groupOwner = false; userPicture = new UserProfileCanvas(); userPicture.setBackground(UIUtilities.BACKGROUND_COLOR); userPicture.setToolTipText("Click to upload your picture."); IconManager icons = IconManager.getInstance(); userPicture.setImage(icons.getImageIcon(IconManager.USER_PHOTO_32).getImage()); loginArea = new JTextField(); boolean a = MetadataViewerAgent.isAdministrator(); loginArea.setEnabled(a); loginArea.setEditable(a); adminBox = new JCheckBox(); adminBox.setVisible(false); adminBox.setBackground(UIUtilities.BACKGROUND_COLOR); ownerBox = new JCheckBox(); ownerBox.setBackground(UIUtilities.BACKGROUND_COLOR); activeBox = new JCheckBox(); activeBox.setBackground(UIUtilities.BACKGROUND_COLOR); activeBox.setVisible(false); passwordButton = new JButton("Change password"); passwordButton.setEnabled(false); passwordButton.setBackground(UIUtilities.BACKGROUND_COLOR); passwordButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { changePassword(); } }); manageButton = new JButton("Group"); manageButton.setEnabled(false); manageButton.setBackground(UIUtilities.BACKGROUND_COLOR); manageButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { manageGroup(); } }); passwordNew = new JPasswordField(); passwordNew.setBackground(UIUtilities.BACKGROUND_COLOR); passwordConfirm = new JPasswordField(); passwordConfirm.setBackground(UIUtilities.BACKGROUND_COLOR); oldPassword = new JPasswordField(); oldPassword.setBackground(UIUtilities.BACKGROUND_COLOR); items = new HashMap<String, JTextField>(); ExperimenterData user = (ExperimenterData) model.getRefObject(); GroupData defaultGroup = user.getDefaultGroup(); permissionsPane = new PermissionsPane(defaultGroup.getPermissions(), UIUtilities.BACKGROUND_COLOR); permissionsPane.disablePermissions(); groupLabel = new JLabel(defaultGroup.getName()); groupLabel.setBackground(UIUtilities.BACKGROUND_COLOR); long groupID = defaultGroup.getId(); boolean owner = false; /* if (defaultGroup.getLeaders() != null) owner = setGroupOwner(defaultGroup); else { GroupData g = model.loadGroup(groupID); if (g != null) owner = setGroupOwner(g); } */ Object parentRootObject = model.getParentRootObject(); if (parentRootObject instanceof GroupData) { owner = setGroupOwner((GroupData) parentRootObject); } // Build the array for box. /* Iterator i = userGroups.iterator(); GroupData g; List<GroupData> validGroups = new ArrayList<GroupData>(); while (i.hasNext()) { g = (GroupData) i.next(); if (model.isValidGroup(g)) validGroups.add(g); } groupData = new GroupData[validGroups.size()]; admin = false; active = false; int selectedIndex = 0; int index = 0; i = validGroups.iterator(); boolean owner = false; while (i.hasNext()) { g = (GroupData) i.next(); groupData[index] = g; if (g.getId() == groupID) { if (g.getLeaders() != null) { owner = setGroupOwner(g); originalIndex = index; } } index++; } selectedIndex = originalIndex; groups = EditorUtil.createComboBox(groupData, 0); groups.setEnabled(false); groups.setRenderer(new GroupsRenderer()); if (groupData.length != 0) groups.setSelectedIndex(selectedIndex); */ if (MetadataViewerAgent.isAdministrator()) { // Check that the user is not the one currently logged. oldPassword.setVisible(false); owner = true; adminBox.setVisible(true); activeBox.setVisible(true); adminBox.addChangeListener(this); active = user.isActive(); activeBox.setSelected(active); activeBox.setEnabled(!model.isSelf()); activeBox.addChangeListener(this); // indicate if the user is an administrator.a admin = isUserAdministrator(); adminBox.setSelected(admin); ownerBox.addChangeListener(this); // admin = false; // Now check if the user is the last administrator } else { ownerBox.setEnabled(false); passwordConfirm .getDocument() .addDocumentListener( new DocumentListener() { /** * Allows the user to interact with the password controls depending on the value * entered. * * @see DocumentListener#removeUpdate(DocumentEvent) */ public void removeUpdate(DocumentEvent e) { handlePasswordEntered(); } /** * Allows the user to interact with the password controls depending on the value * entered. * * @see DocumentListener#insertUpdate(DocumentEvent) */ public void insertUpdate(DocumentEvent e) { handlePasswordEntered(); } /** * Required by the {@link DocumentListener} I/F but no-operation implementation in * our case. * * @see DocumentListener#changedUpdate(DocumentEvent) */ public void changedUpdate(DocumentEvent e) {} }); } passwordNew .getDocument() .addDocumentListener( new DocumentListener() { /** * Allows the user to interact with the password controls depending on the value * entered. * * @see DocumentListener#removeUpdate(DocumentEvent) */ public void removeUpdate(DocumentEvent e) { handlePasswordEntered(); } /** * Allows the user to interact with the password controls depending on the value * entered. * * @see DocumentListener#insertUpdate(DocumentEvent) */ public void insertUpdate(DocumentEvent e) { handlePasswordEntered(); } /** * Required by the {@link DocumentListener} I/F but no-operation implementation in our * case. * * @see DocumentListener#changedUpdate(DocumentEvent) */ public void changedUpdate(DocumentEvent e) {} }); ExperimenterData logUser = MetadataViewerAgent.getUserDetails(); if (user.getId() == logUser.getId()) { userPicture.addMouseListener( new MouseAdapter() { /** Brings up a chooser to load the user image. */ public void mouseReleased(MouseEvent e) { uploadPicture(); } }); } }