Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi groups #129

Merged
merged 16 commits into from Mar 28, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -172,7 +172,8 @@ public boolean isSameGroup(long groupID)
*/
public void actionPerformed(ActionEvent e)
{
model.setUserGroup(group, add);
model.retrieveUserGroups(null, group);
//model.setUserGroup(group, add);
}

}
@@ -0,0 +1,137 @@
/*
* org.openmicroscopy.shoola.agents.treeviewer.actions.SwitchGroup
*
*------------------------------------------------------------------------------
* Copyright (C) 2006-2012 University of Dundee & Open Microscopy Environment.
* All rights reserved.
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*------------------------------------------------------------------------------
*/
package org.openmicroscopy.shoola.agents.treeviewer.actions;


//Java imports
import java.awt.Component;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.Action;
import javax.swing.SwingUtilities;

//Third-party libraries

//Application-internal dependencies
import org.openmicroscopy.shoola.agents.treeviewer.IconManager;
import org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewer;
import org.openmicroscopy.shoola.util.ui.UIUtilities;

/**
* Selects the groups to add to the display.
*
* @author Jean-Marie Burel     
* <a href="mailto:j.burel@dundee.ac.uk">j.burel@dundee.ac.uk</a>
* @since Beta4.4
*/
public class SwitchGroup
extends TreeViewerAction
implements MouseListener
{

/** The name of the action. */
public static final String NAME = "Display Group...";

/** The description of the action. */
public static final String DESCRIPTION = "Select the groups to " +
"add to the tree.";

/** The location of the mouse pressed. */
private Point point;

/**
* Creates a new instance.
*
* @param model Reference to the Model. Mustn't be <code>null</code>.
*/
public SwitchGroup(TreeViewer model)
{
super(model);
setEnabled(true);
name = NAME;
putValue(Action.SHORT_DESCRIPTION,
UIUtilities.formatToolTipText(DESCRIPTION));
IconManager im = IconManager.getInstance();
putValue(Action.SMALL_ICON, im.getIcon(IconManager.OWNER_GROUP));
}

/**
* Sets the mouse pressed point.
*
* @param point The value to set.
*/
public void setPoint(Point point) { this.point = point; }

/**
* Brings up the switch user dialog.
* @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
*/
public void actionPerformed(ActionEvent e)
{
if (point != null) {
SwingUtilities.convertPointToScreen(point,
((Component) e.getSource()));
}
model.displayUserGroups(point);
}

/**
* Sets the location of the point where the <code>mousePressed</code>
* event occurred.
* @see MouseListener#mousePressed(MouseEvent)
*/
public void mousePressed(MouseEvent me) { point = me.getPoint(); }

/**
* Required by {@link MouseListener} I/F but not actually needed in our
* case, no-operation implementation.
* @see MouseListener#mouseReleased(MouseEvent)
*/
public void mouseReleased(MouseEvent me) {}

/**
* Required by {@link MouseListener} I/F but not actually needed in our
* case, no-operation implementation.
* @see MouseListener#mouseEntered(MouseEvent)
*/
public void mouseEntered(MouseEvent e) {}

/**
* Required by {@link MouseListener} I/F but not actually needed in our
* case, no-operation implementation.
* @see MouseListener#mouseExited(MouseEvent)
*/
public void mouseExited(MouseEvent e) {}

/**
* Required by {@link MouseListener} I/F but not actually needed in our
* case, no-operation implementation.
* @see MouseListener#mouseClicked(MouseEvent)
*/
public void mouseClicked(MouseEvent e) {}

}
Expand Up @@ -63,11 +63,14 @@ public class SwitchUserAction
{

/** The name of the action. */
public static final String NAME = "Add User...";
public static final String NAME = "Display User...";

/** The name of the action. */
public static final String NAME_TO = "Display User from";

/** The description of the action. */
private static final String DESCRIPTION = "Select another " +
"user and view his/her data.";
public static final String DESCRIPTION = "Select users and view their" +
" data.";

/** The location of the mouse pressed. */
private Point point;
Expand All @@ -84,7 +87,10 @@ private void handleGroupSelection(GroupData group)
return;
}
Collection l = group.getExperimenters();
if (l == null) return;
if (l == null) {
setEnabled(false);
return;
}
int level = model.getGroupPermissions(group);
boolean b = false;
if (level == AdminObject.PERMISSIONS_PRIVATE) {
Expand Down Expand Up @@ -160,7 +166,7 @@ protected void onBrowserSelection(Browser browser)
public SwitchUserAction(TreeViewer model)
{
super(model);
setEnabled(true);
setEnabled(false);
name = NAME;
putValue(Action.SHORT_DESCRIPTION,
UIUtilities.formatToolTipText(DESCRIPTION));
Expand All @@ -178,7 +184,7 @@ public void actionPerformed(ActionEvent e)
SwingUtilities.convertPointToScreen(point,
((Component) e.getSource()));
}
model.retrieveUserGroups(point);
model.retrieveUserGroups(point, null);
}

/**
Expand Down
Expand Up @@ -528,8 +528,9 @@ public void loadExperimenterData(TreeImageDisplay expNode,
* Removes the experimenter's data from the display.
*
* @param exp The experimenter to remove. Mustn't be <code>null</code>.
* @param groupID The group's id the experimenter is member of.
*/
public void removeExperimenter(ExperimenterData exp);
public void removeExperimenter(ExperimenterData exp, long groupID);

/** Refreshes the experimenter node. */
public void refreshExperimenterData();
Expand Down Expand Up @@ -799,7 +800,7 @@ public void onDeselectedNode(Object parent, Object selected,
*
* @param group The selected group.
*/
void setUserGroup(GroupData group, boolean add);
void setUserGroup(GroupData group);

/**
* Removes the specified group from the display
Expand Down
Expand Up @@ -1215,7 +1215,6 @@ public void addExperimenter(ExperimenterData experimenter, long groupID)
node = view.getTreeRoot();
} else {
//Find the group
System.err.println("group:"+groupID);
ExperimenterVisitor v = new ExperimenterVisitor(this, groupID);
accept(v, TreeImageDisplayVisitor.TREEIMAGE_SET_ONLY);
List<TreeImageDisplay> list = v.getNodes();
Expand All @@ -1236,13 +1235,21 @@ public void addExperimenter(ExperimenterData experimenter, long groupID)

/**
* Implemented as specified by the {@link Browser} interface.
* @see Browser#removeExperimenter(ExperimenterData)
* @see Browser#removeExperimenter(ExperimenterData, GroupData)
*/
public void removeExperimenter(ExperimenterData exp)
public void removeExperimenter(ExperimenterData exp, long groupID)
{
if (exp == null)
throw new IllegalArgumentException("Experimenter cannot be null.");
view.removeExperimenter(exp);
TreeImageDisplay node = null;
if (groupID >= 0) {
ExperimenterVisitor v = new ExperimenterVisitor(this, groupID);
accept(v);
List<TreeImageDisplay> nodes = v.getNodes();
if (nodes.size() == 1) node = nodes.get(0);
}

view.removeExperimenter(exp, node);
}

/**
Expand Down Expand Up @@ -2130,13 +2137,13 @@ public void rejectTransfer()

/**
* Implemented as specified by the {@link Browser} interface.
* @see Browser#setUserGroup(GroupData, boolean)
* @see Browser#setUserGroup(GroupData)
*/
public void setUserGroup(GroupData group, boolean add)
public void setUserGroup(GroupData group)
{
if (group == null)
throw new IllegalArgumentException("Group cannot be null.");
view.setUserGroup(group, add);
view.setUserGroup(group);
}

/**
Expand Down