Permalink
Browse files

Review activation sequence (see #7815)

  • Loading branch information...
1 parent 4cda05d commit 623eab6ef200dd00d4ac1ef0679c9ac93c6b30eb @jburel committed Jan 25, 2012
@@ -51,6 +51,7 @@
import org.openmicroscopy.shoola.agents.treeviewer.RefreshExperimenterDef;
import org.openmicroscopy.shoola.agents.treeviewer.TreeViewerAgent;
import org.openmicroscopy.shoola.agents.treeviewer.cmd.EditVisitor;
+import org.openmicroscopy.shoola.agents.treeviewer.cmd.ExperimenterVisitor;
import org.openmicroscopy.shoola.agents.treeviewer.cmd.ParentVisitor;
import org.openmicroscopy.shoola.agents.treeviewer.cmd.RefreshVisitor;
import org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewer;
@@ -370,7 +371,8 @@ public void activate()
int state = model.getState();
switch (state) {
case NEW:
- view.loadExperimenterData();
+ TreeImageDisplay node = getLoggedExperimenterNode();
+ view.expandNode(node, true);
break;
case READY:
refreshBrowser(); //do we want to automatically refresh?
@@ -816,7 +818,7 @@ public void refreshEdition(DataObject object, DataObject parent, int op)
Object o = object;
List nodes = null;
TreeImageDisplay parentDisplay = null;
- TreeImageDisplay loggedUser = view.getLoggedExperimenterNode();
+ TreeImageDisplay loggedUser = getLoggedExperimenterNode();
if (op == TreeViewer.CREATE_OBJECT) {
TreeImageDisplay node = getLastSelectedDisplay();
if ((object instanceof ProjectData) ||
@@ -872,7 +874,7 @@ public void onOrphanDataObjectCreated(DataObject data)
} else if (data instanceof TagAnnotationData) {
if (type != TAGS_EXPLORER) return;
}
- TreeImageDisplay loggedUser = view.getLoggedExperimenterNode();
+ TreeImageDisplay loggedUser = getLoggedExperimenterNode();
List<TreeImageDisplay> nodes = new ArrayList<TreeImageDisplay>(1);
nodes.add(loggedUser);
long userID = model.getUserID();
@@ -1206,7 +1208,13 @@ public void refreshExperimenterData()
*/
public TreeImageDisplay getLoggedExperimenterNode()
{
- return view.getLoggedExperimenterNode();
+ SecurityContext ctx = model.getSecurityContext(null);
+ ExperimenterVisitor visitor = new ExperimenterVisitor(this,
+ model.getUserID(), ctx.getGroupID());
+ accept(visitor, TreeImageDisplayVisitor.TREEIMAGE_SET_ONLY);
+ List<TreeImageDisplay> nodes = visitor.getNodes();
+ if (nodes.size() != 1) return null;
+ return nodes.get(0);
}
/**
@@ -1224,7 +1232,7 @@ public void refreshLoggedExperimenterData()
//ignore
return;
}
- TreeImageDisplay node = view.getLoggedExperimenterNode();
+ TreeImageDisplay node = getLoggedExperimenterNode();
if (node == null) return;
Object ho = node.getUserObject();
if (!(ho instanceof ExperimenterData)) return;
@@ -1722,7 +1730,8 @@ public void reActivate()
view.reActivate();
if (!model.isSelected()) return;
//Reload data.
- view.loadExperimenterData();
+ TreeImageDisplay node = getLoggedExperimenterNode();
+ view.expandNode(node, true);
}
/**
@@ -73,6 +73,7 @@
//Application-internal dependencies
import org.openmicroscopy.shoola.agents.treeviewer.TreeViewerAgent;
import org.openmicroscopy.shoola.agents.treeviewer.actions.BrowserManageAction;
+import org.openmicroscopy.shoola.agents.treeviewer.cmd.ExperimenterVisitor;
import org.openmicroscopy.shoola.agents.treeviewer.cmd.ViewCmd;
import org.openmicroscopy.shoola.agents.treeviewer.util.TreeCellRenderer;
import org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewer;
@@ -89,6 +90,7 @@
import org.openmicroscopy.shoola.agents.util.dnd.DnDTree;
import org.openmicroscopy.shoola.agents.util.dnd.ObjectToTransfer;
import org.openmicroscopy.shoola.env.data.FSFileSystemView;
+import org.openmicroscopy.shoola.env.data.util.SecurityContext;
import org.openmicroscopy.shoola.util.ui.UIUtilities;
import pojos.DataObject;
import pojos.DatasetData;
@@ -1600,17 +1602,9 @@ void sortNodes(int type)
while (j.hasNext()) {
setExpandedParent((TreeImageDisplay) j.next(), true);
}
- }
+ }
}
}
-
- /** Loads the children of the currently logged in experimenter. */
- void loadExperimenterData()
- {
- TreeImageDisplay root = getTreeRoot();
- TreeImageDisplay child = (TreeImageDisplay) root.getFirstChild();
- treeDisplay.expandPath(new TreePath(child.getPath()));
- }
/**
* Reacts to state change.
@@ -2022,17 +2016,6 @@ void reActivate()
DefaultTreeModel tm = (DefaultTreeModel) treeDisplay.getModel();
tm.reload();
}
-
- /**
- * Returns the node hosting the logged in user.
- *
- * @return See above.
- */
- TreeImageDisplay getLoggedExperimenterNode()
- {
- TreeImageDisplay root = getTreeRoot();
- return (TreeImageDisplay) root.getChildAt(0);
- }
/** Refreshes the experimenter data. */
void refreshExperimenter()
@@ -2136,19 +2119,33 @@ void reloadNode(TreeImageDisplay node)
/** Expands the node corresponding to the user currently logged in. */
void expandUser()
{
+ SecurityContext ctx = model.getSecurityContext(
+ model.getLastSelectedDisplay());
+ long groupId = ctx.getGroupID();
TreeImageDisplay root = getTreeRoot();
- TreeImageDisplay element;
- Object ho;
+ List<TreeImageDisplay> nodesToKeep;
+ List l = root.getChildrenDisplay();
+ if (l == null || l.size() == 0) return;
+ Iterator j = l.iterator();
+ TreeImageDisplay element, n, node;
+ Object ho, h;
ExperimenterData exp;
long id = model.getUserID();
- for (int i = 0; i < root.getChildCount(); i++) {
- element = (TreeImageDisplay) root.getChildAt(i);
- ho = element.getUserObject();
- if (ho instanceof ExperimenterData) {
- exp = (ExperimenterData) ho;
- if (exp.getId() == id && !element.isExpanded()) {
- expandNode(element);
- break;
+ while (j.hasNext()) {
+ node = null;
+ element = (TreeImageDisplay) j.next();
+ h = element.getUserObject();
+ if (h instanceof GroupData && ((GroupData) h).getId() == groupId) {
+ for (int i = 0; i < element.getChildCount(); i++) {
+ n = (TreeImageDisplay) element.getChildAt(i);
+ ho = n.getUserObject();
+ if (ho instanceof ExperimenterData) {
+ exp = (ExperimenterData) ho;
+ if (exp.getId() == id && !n.isExpanded()) {
+ expandNode(element);
+ break;
+ }
+ }
}
}
}
@@ -2163,6 +2160,7 @@ void expandUser()
void expandNode(TreeImageDisplay node, boolean withListener)
{
//First remove listener otherwise an event is fired.
+ if (node == null) return;
node.setExpanded(true);
if (withListener) {
treeDisplay.expandPath(new TreePath(node.getPath()));

0 comments on commit 623eab6

Please sign in to comment.