/** * Implemented as specified by the {@link Importer} interface. * * @see Importer#getSelectedGroup() */ public GroupData getSelectedGroup() { Collection<GroupData> m = loadGroups(); if (m == null) { ExperimenterData exp = ImporterAgent.getUserDetails(); return exp.getDefaultGroup(); } long id = model.getGroupId(); for (GroupData group : m) { if (group.getId() == id) return group; } ExperimenterData exp = ImporterAgent.getUserDetails(); return exp.getDefaultGroup(); }
/** * Indicates that the group has been successfully switched if <code>true</code>, unsuccessfully if * <code>false</code>. * * @param success Pass <code>true</code> if successful, <code>false</code> otherwise. */ void onGroupSwitched(boolean success) { if (!model.isMaster()) return; if (!success) return; ExperimenterData exp = ImporterAgent.getUserDetails(); GroupData group = exp.getDefaultGroup(); long oldGroup = model.getGroupId(); model.setGroupId(group.getId()); ImportLocationDetails details = new ImportLocationDetails(chooser.getType()); refreshContainers(details); firePropertyChange(CHANGED_GROUP_PROPERTY, oldGroup, model.getGroupId()); }
/** 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()); }
/** 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(); } }); } }