Author: charles.crouch(a)jboss.com
Date: 2009-03-04 18:31:10 -0500 (Wed, 04 Mar 2009)
New Revision: 176
Added:
trunk/core/src/main/java/org/jboss/on/embedded/ui/NavigationContent.java
Modified:
trunk/core/src/main/java/org/jboss/on/embedded/ui/NavigationAction.java
Log:
EMBJOPR-62 make rootNode APPLICATION scoped
Modified: trunk/core/src/main/java/org/jboss/on/embedded/ui/NavigationAction.java
===================================================================
--- trunk/core/src/main/java/org/jboss/on/embedded/ui/NavigationAction.java 2009-03-03
21:39:27 UTC (rev 175)
+++ trunk/core/src/main/java/org/jboss/on/embedded/ui/NavigationAction.java 2009-03-04
23:31:10 UTC (rev 176)
@@ -121,10 +121,8 @@
return baseUrl;
}
-
- // used by resourceNavigation.xhtml to render the nav
- @In(value = "rootNode", create=true)
- @Out(value = "rootNode", scope = ScopeType.SESSION)
+
+ @In(value = "rootNode", create=true)
private JONTreeNode rootNode;
// Its only SummaryAction.getResourceTypePath which needs this to be public
@@ -134,34 +132,24 @@
return rootNode;
}
- @Factory(value = "rootNode", scope=ScopeType.SESSION)
- public JONTreeNode createJONTreeNode() {
- log.debug("createJONTreeNode factory method being called.");
- DummyTreeNode dummy = new DummyTreeNode();
- PlatformResourceTreeNode platform = new
PlatformResourceTreeNode(ResourceManagerFactory.resourceManager().getPlatform());
- dummy.addChild(platform);
- Events.instance().raiseEvent(ResourceManager.NAV_TREE_INITIALIZED);
- return dummy;
- }
+// @Out(value = "navTree", required = false, scope = ScopeType.EVENT)
+// public HtmlTree getNavTree()
+// {
+//// if (navTree == null)
+//// {
+//// navTree = buildNavTree();
+//// }
+// return navTree;
+// }
+//
+// @In(value = "navTree", required = false, scope = ScopeType.EVENT)
+// public void setNavTree(HtmlTree navTree)
+// {
+// this.navTree = navTree;
+// }
+//
+// private HtmlTree navTree;
- @Out(value = "navTree", required = false, scope = ScopeType.EVENT)
- public HtmlTree getNavTree()
- {
-// if (navTree == null)
-// {
-// navTree = buildNavTree();
-// }
- return navTree;
- }
-
- @In(value = "navTree", required = false, scope = ScopeType.EVENT)
- public void setNavTree(HtmlTree navTree)
- {
- this.navTree = navTree;
- }
-
- private HtmlTree navTree;
-
// @Factory("navTree")
// public HtmlTree buildNavTree()
// {
@@ -441,39 +429,7 @@
{
return getResourcePath(resource.getId());
}
-
- @Observer(ResourceManager.RESOURCE_CREATED_EVENT)
- public void updateNavWithNewResource(ResourceType typeOfNewResource, Resource
parentResource)
- {
- log.info("Resource of type [" + typeOfNewResource + "] added
beneath Resource [" + parentResource + "].");
- JONTreeNode parentNode = findNode(getResourcePath(parentResource));
- JONTreeNode node = findNodeByResourceTypeAndParent(typeOfNewResource,
parentNode);
- node.reInitializeChildrenMap();
- }
-
- @Observer(ResourceManager.RESOURCE_DELETED_EVENT)
- public void updateNavWithDeletedResource(Resource deletedResource)
- {
- log.info("Resource [" + deletedResource + "] deleted.");
- JONTreeNode node = findNode(getResourcePath(deletedResource));
- if (node == null)
- {
- log.warn("Unable to find node for deleted resource [" +
deletedResource + "].");
- return;
- }
- JONTreeNode parentNode = node.getParent();
- parentNode.reInitializeChildrenMap();
- }
- @Observer(ResourceManager.RESOURCE_UPDATED_EVENT)
- public void updateNavWithUpdatedResource(Resource updatedResource)
- {
- // doesn't do anything right now, but in the future this could
- // regenerate the nav similar to how updateNavWithDeletedResource
- // does it. This would catch any resource renames that happened
- // as part of the update
- }
-
// TODO consider have this return TreeNodeWithResourceType
public ResourceTypeTreeNode findNodeByResourceTypeAndParent(ResourceType
resourceType, JONTreeNode parentResourceNode)
{
Added: trunk/core/src/main/java/org/jboss/on/embedded/ui/NavigationContent.java
===================================================================
--- trunk/core/src/main/java/org/jboss/on/embedded/ui/NavigationContent.java
(rev 0)
+++ trunk/core/src/main/java/org/jboss/on/embedded/ui/NavigationContent.java 2009-03-04
23:31:10 UTC (rev 176)
@@ -0,0 +1,128 @@
+/*
+ * Embedded Jopr Project
+ * Copyright (C) 2006-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.jboss.on.embedded.ui;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.on.embedded.manager.ResourceManager;
+import org.jboss.on.embedded.manager.ResourceManagerFactory;
+import org.jboss.on.embedded.ui.nav.BaseTreeNode;
+import org.jboss.on.embedded.ui.nav.DummyTreeNode;
+import org.jboss.on.embedded.ui.nav.JONTreeNode;
+import org.jboss.on.embedded.ui.nav.PlatformResourceTreeNode;
+import org.jboss.on.embedded.ui.nav.ResourceTypeTreeNode;
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.Factory;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Observer;
+import org.jboss.seam.annotations.Out;
+import org.jboss.seam.core.Events;
+import org.rhq.core.domain.resource.Resource;
+import org.rhq.core.domain.resource.ResourceType;
+
+/**
+ * NavigationContent class encapsulates the JONTreeNode object which
+ * contains the objects rendered in the navigation tree.
+ * Contains the methods which will update this structure as resources are added/deleted
+ *
+ * @author Charles Crouch
+ */
+@Name("navigationContent")
+public class NavigationContent
+{
+ private static final Log log = LogFactory.getLog(NavigationContent.class);
+
+ // used by resourceNavigation.xhtml to render the nav
+ @In(value = "rootNode", create=true)
+ @Out(value = "rootNode", scope = ScopeType.APPLICATION)
+ private JONTreeNode rootNode;
+
+ @Factory(value = "rootNode")
+ public JONTreeNode createJONTreeNode() {
+ log.debug("createJONTreeNode factory method being called.");
+ DummyTreeNode dummy = new DummyTreeNode();
+ PlatformResourceTreeNode platform = new
PlatformResourceTreeNode(ResourceManagerFactory.resourceManager().getPlatform());
+ dummy.addChild(platform);
+ Events.instance().raiseEvent(ResourceManager.NAV_TREE_INITIALIZED);
+ return dummy;
+ }
+
+ @Observer(ResourceManager.RESOURCE_CREATED_EVENT)
+ public void updateNavWithNewResource(ResourceType typeOfNewResource, Resource
parentResource)
+ {
+ log.info("Resource of type [" + typeOfNewResource + "] added
beneath Resource [" + parentResource + "].");
+ JONTreeNode parentNode = findNode(getResourcePath(parentResource));
+ JONTreeNode node = findNodeByResourceTypeAndParent(typeOfNewResource,
parentNode);
+ node.reInitializeChildrenMap();
+ }
+
+ @Observer(ResourceManager.RESOURCE_DELETED_EVENT)
+ public void updateNavWithDeletedResource(Resource deletedResource)
+ {
+ log.info("Resource [" + deletedResource + "] deleted.");
+ JONTreeNode node = findNode(getResourcePath(deletedResource));
+ if (node == null)
+ {
+ log.warn("Unable to find node for deleted resource [" +
deletedResource + "].");
+ return;
+ }
+ JONTreeNode parentNode = node.getParent();
+ parentNode.reInitializeChildrenMap();
+ }
+
+ @Observer(ResourceManager.RESOURCE_UPDATED_EVENT)
+ public void updateNavWithUpdatedResource(Resource updatedResource)
+ {
+ // doesn't do anything right now, but in the future this could
+ // regenerate the nav similar to how updateNavWithDeletedResource
+ // does it. This would catch any resource renames that happened
+ // as part of the update
+ }
+
+ // the following methods are all copied from NavigationAction
+
+ private JONTreeNode findNode(String path)
+ {
+ return rootNode.findNode(path);
+ }
+
+ // TODO consider have this return TreeNodeWithResourceType
+ private ResourceTypeTreeNode findNodeByResourceTypeAndParent(ResourceType
resourceType, JONTreeNode parentResourceNode)
+ {
+ return ((BaseTreeNode) parentResourceNode).findNodeByType(resourceType);
+ }
+
+ private String getResourcePath(Resource resource)
+ {
+ return getResourcePath(resource.getId());
+ }
+
+ private String getResourcePath(Integer resourceId)
+ {
+ // this just happens to be the current implementation for generating the path
+ // if we wanted to change it, we just need to change the methods in this class
+ // and ResourceTreeNode
+ // TODO this could call a static method on ResourceTreeNode to keep this
+ // implementation better encapsulated
+ return String.valueOf(resourceId);
+ }
+
+}