[kune-commits] r869 - in trunk/src/main/java/org/ourproject/kune: platf/client/services platf/client/state workspace/client/ctxnav workspace/client/title

vjrj vjrj at ourproject.org
Sat Sep 13 05:32:52 CEST 2008


Author: vjrj
Date: 2008-09-13 05:32:44 +0200 (Sat, 13 Sep 2008)
New Revision: 869

Modified:
   trunk/src/main/java/org/ourproject/kune/platf/client/services/KuneModule.java
   trunk/src/main/java/org/ourproject/kune/platf/client/state/StateManager.java
   trunk/src/main/java/org/ourproject/kune/platf/client/state/StateManagerDefault.java
   trunk/src/main/java/org/ourproject/kune/workspace/client/ctxnav/ContextNavigator.java
   trunk/src/main/java/org/ourproject/kune/workspace/client/ctxnav/ContextNavigatorPanel.java
   trunk/src/main/java/org/ourproject/kune/workspace/client/ctxnav/ContextNavigatorPresenter.java
   trunk/src/main/java/org/ourproject/kune/workspace/client/ctxnav/ContextNavigatorView.java
   trunk/src/main/java/org/ourproject/kune/workspace/client/title/EntityTitlePresenter.java
Log:
context navigator dinamic toolbars and menus working (but new folder/content action buggy)

Modified: trunk/src/main/java/org/ourproject/kune/platf/client/services/KuneModule.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/client/services/KuneModule.java	2008-09-12 08:10:16 UTC (rev 868)
+++ trunk/src/main/java/org/ourproject/kune/platf/client/services/KuneModule.java	2008-09-13 03:32:44 UTC (rev 869)
@@ -450,7 +450,8 @@
 	register(SingletonScope.class, new Factory<EntityTitle>(EntityTitle.class) {
 	    public EntityTitle create() {
 		final EntityTitlePresenter presenter = new EntityTitlePresenter(i18n, $(KuneErrorHandler.class),
-			$(StateManager.class), $(Session.class), $$(ContentServiceAsync.class));
+			$(StateManager.class), $(Session.class), $$(ContentServiceAsync.class),
+			$$(ContextNavigator.class));
 		final EntityTitlePanel panel = new EntityTitlePanel(ws, presenter);
 		presenter.init(panel);
 		return presenter;
@@ -589,9 +590,9 @@
 	register(SingletonScope.class, new Factory<ContextNavigator>(ContextNavigator.class) {
 	    public ContextNavigator create() {
 		final ContextNavigatorPresenter presenter = new ContextNavigatorPresenter($(StateManager.class),
-			$(Session.class), $$(ContentServiceAsync.class), i18n, $(EntityTitle.class));
-		final ContextNavigatorPanel panel = new ContextNavigatorPanel(presenter, i18n, $(StateManager.class),
-			ws, $$(ActionManager.class));
+			$(Session.class), $$(ContentServiceAsync.class), i18n, $(EntityTitle.class),
+			$$(ActionManager.class));
+		final ContextNavigatorPanel panel = new ContextNavigatorPanel(presenter, i18n, ws);
 		presenter.init(panel);
 		return presenter;
 	    }

Modified: trunk/src/main/java/org/ourproject/kune/platf/client/state/StateManager.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/client/state/StateManager.java	2008-09-12 08:10:16 UTC (rev 868)
+++ trunk/src/main/java/org/ourproject/kune/platf/client/state/StateManager.java	2008-09-13 03:32:44 UTC (rev 869)
@@ -48,8 +48,6 @@
 
     void reload();
 
-    void reloadContextAndTitles();
-
     void removeSiteToken(String token);
 
     void setRetrievedState(StateDTO content);

Modified: trunk/src/main/java/org/ourproject/kune/platf/client/state/StateManagerDefault.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/client/state/StateManagerDefault.java	2008-09-12 08:10:16 UTC (rev 868)
+++ trunk/src/main/java/org/ourproject/kune/platf/client/state/StateManagerDefault.java	2008-09-13 03:32:44 UTC (rev 869)
@@ -80,7 +80,7 @@
     public void gotoContainer(final Long containerId) {
 	final StateToken newStateToken = session.getCurrentState().getStateToken().clone();
 	newStateToken.clearDocument();
-	newStateToken.setFolder(containerId.toString());
+	newStateToken.setFolder(containerId);
 	gotoToken(newStateToken);
     }
 
@@ -135,20 +135,6 @@
 	onHistoryChanged(history.getToken());
     }
 
-    @Deprecated
-    public void reloadContextAndTitles() {
-	contentProvider.getContent(session.getUserHash(), new StateToken(history.getToken()),
-		new AsyncCallbackSimple<StateDTO>() {
-		    public void onSuccess(final StateDTO newStateDTO) {
-			loadContextOnly(newStateDTO);
-			oldState = newStateDTO;
-			// workspace.getContentTitleComponent().setState(oldState);
-			// workspace.getContentSubTitleComponent().setState(oldState);
-			Site.hideProgress();
-		    }
-		});
-    }
-
     public void removeSiteToken(final String token) {
 	siteTokens.remove(token);
     }
@@ -183,7 +169,6 @@
 	if (oldState == null || !oldToolName.equals(newToolName)) {
 	    onToolChanged.fire(oldToolName, newToolName);
 	}
-
     }
 
     private void loadContent(final StateDTO state) {
@@ -191,15 +176,6 @@
 	Site.hideProgress();
     }
 
-    @Deprecated
-    private void loadContextOnly(final StateDTO state) {
-	session.setCurrent(state);
-	// /final String toolName = state.getToolName();
-	// /final ClientTool clientTool = app.getTool(toolName);
-	// /clientTool.setContext(state);
-	// /workspace.setContext(clientTool.getContext());
-    }
-
     private void onHistoryChanged(final StateToken newState) {
 	contentProvider.getContent(session.getUserHash(), newState, new AsyncCallbackSimple<StateDTO>() {
 	    public void onSuccess(final StateDTO newState) {

Modified: trunk/src/main/java/org/ourproject/kune/workspace/client/ctxnav/ContextNavigator.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/workspace/client/ctxnav/ContextNavigator.java	2008-09-12 08:10:16 UTC (rev 868)
+++ trunk/src/main/java/org/ourproject/kune/workspace/client/ctxnav/ContextNavigator.java	2008-09-13 03:32:44 UTC (rev 869)
@@ -43,6 +43,8 @@
 
     void selectItem(StateToken stateToken);
 
+    void setItemText(StateToken stateToken, String name);
+
     void setState(StateDTO state);
 
 }

Modified: trunk/src/main/java/org/ourproject/kune/workspace/client/ctxnav/ContextNavigatorPanel.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/workspace/client/ctxnav/ContextNavigatorPanel.java	2008-09-12 08:10:16 UTC (rev 868)
+++ trunk/src/main/java/org/ourproject/kune/workspace/client/ctxnav/ContextNavigatorPanel.java	2008-09-13 03:32:44 UTC (rev 869)
@@ -20,21 +20,21 @@
 
 package org.ourproject.kune.workspace.client.ctxnav;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 
 import org.ourproject.kune.platf.client.actions.ActionCollection;
 import org.ourproject.kune.platf.client.actions.ActionDescriptor;
-import org.ourproject.kune.platf.client.actions.ActionManager;
+import org.ourproject.kune.platf.client.actions.ActionPosition;
 import org.ourproject.kune.platf.client.dto.StateToken;
 import org.ourproject.kune.platf.client.services.I18nTranslationService;
-import org.ourproject.kune.platf.client.state.StateManager;
 import org.ourproject.kune.workspace.client.skel.Toolbar;
 import org.ourproject.kune.workspace.client.skel.WorkspaceSkeleton;
 
 import com.allen_sauer.gwt.log.client.Log;
-import com.calclab.suco.client.provider.Provider;
 import com.google.gwt.user.client.Command;
 import com.google.gwt.user.client.DeferredCommand;
+import com.google.gwt.user.client.ui.Widget;
 import com.gwtext.client.core.EventObject;
 import com.gwtext.client.data.Node;
 import com.gwtext.client.widgets.Button;
@@ -59,22 +59,40 @@
     private final HashMap<String, Menu> contextMenus;
     private final HashMap<String, Menu> toolbarMenus;
     private final WorkspaceSkeleton ws;
-    private final Provider<ActionManager> actionManagerProvider;
-    private final StateManager stateManager;
     private final ContextNavigatorPresenter presenter;
+    private final ArrayList<ToolbarButton> buttons;
+    private final HashMap<String, Item> menuItems;
 
     public ContextNavigatorPanel(final ContextNavigatorPresenter presenter, final I18nTranslationService i18n,
-	    final StateManager stateManager, final WorkspaceSkeleton ws,
-	    final Provider<ActionManager> actionManagerProvider) {
+	    final WorkspaceSkeleton ws) {
 	this.presenter = presenter;
-	this.stateManager = stateManager;
 	this.ws = ws;
-	this.actionManagerProvider = actionManagerProvider;
 
 	contextMenus = new HashMap<String, Menu>();
 	toolbarMenus = new HashMap<String, Menu>();
+	buttons = new ArrayList<ToolbarButton>();
+	menuItems = new HashMap<String, Item>();
     }
 
+    public void addButtonAction(final ActionDescriptor<StateToken> action) {
+	final ActionPosition pos = action.getActionPosition();
+	final ToolbarButton button = new ToolbarButton();
+	final String text = action.getText();
+	if (text != null) {
+	    button.setText(text);
+	}
+	button.addListener(new ButtonListenerAdapter() {
+	    @Override
+	    public void onClick(final Button button, final EventObject e) {
+		doAction(action, presenter.getCurrentStateToken());
+	    }
+	});
+	button.setIcon(action.getIconUrl());
+	button.setTooltip(action.getToolTip());
+	getToolbar(pos).add(button);
+	buttons.add(button);
+    }
+
     public void addItem(final ContextNavigatorItem item) {
 	final String nodeId = item.getId();
 	if (treePanel.getNodeById(nodeId) == null) {
@@ -111,14 +129,16 @@
 		    }
 		});
 		if (!item.getStateToken().hasAll()) {
+		    // is a container
 		    child.setExpandable(true);
 		    child.addListener(new TreeNodeListenerAdapter() {
 			public void onExpand(final Node node) {
 			    treePanel.getNodeById(node.getId()).select();
-			    stateManager.gotoToken(getToken(node));
+			    presenter.gotoToken(getToken(node));
 			}
 		    });
 		} else {
+		    // is a document
 		    child.setLeaf(true);
 		}
 		parent.appendChild(child);
@@ -131,23 +151,61 @@
 
     }
 
+    public void addMenuAction(final ActionDescriptor<StateToken> action, final boolean enable) {
+	final String menuTitle = action.getParentMenuTitle();
+	final String menuSubTitle = action.getParentSubMenuTitle();
+	final ActionPosition pos = action.getActionPosition();
+	final String itemKey = genMenuKey(pos, menuTitle, menuSubTitle, action.getText());
+	Item item = menuItems.get(itemKey);
+	if (item == null) {
+	    item = createMenuItem(pos, menuTitle, menuSubTitle, action);
+	    menuItems.put(itemKey, item);
+	} else {
+	}
+	if (enable) {
+	    item.enable();
+	} else {
+	    item.disable();
+	}
+	doLayoutIfNeeded(pos);
+    }
+
     public void clear() {
 	if (treePanel != null) {
 	    treePanel.clear();
 	}
+	ws.getEntityWorkspace().getContextTopBar().removeAll();
+	ws.getEntityWorkspace().getContextBottomBar().removeAll();
 	contextMenus.clear();
 	toolbarMenus.clear();
+	menuItems.clear();
+	buttons.clear();
     }
 
+    public void disableAllMenuItems() {
+	for (final Item item : menuItems.values()) {
+	    item.disable();
+	}
+	doLayoutIfNeeded();
+    }
+
     public void editItem(final String id) {
 	treeEditor.startEdit(getNode(id));
     }
 
+    public void removeAllButtons() {
+	for (final ToolbarButton button : buttons) {
+	    button.removeFromParent();
+	}
+	buttons.clear();
+	doLayoutIfNeeded();
+    }
+
     public void selectItem(final String id) {
 	final TreeNode item = getNode(id);
 	if (item != null) {
 	    item.select();
-	    item.ensureVisible();
+	    // Errore item.ensureVisible();
 	    if (item.getChildNodes().length > 0) {
 		item.expand();
 	    }
@@ -156,11 +214,6 @@
 	}
     }
 
-    public void setBottomActions(final StateToken stateToken, final ActionCollection<StateToken> actions) {
-	final Toolbar toolBar = ws.getEntityWorkspace().getContextBottomBar();
-	setToolbarActions(toolBar, stateToken, actions);
-    }
-
     public void setItemText(final String genId, final String text) {
 	final TreeNode node = getNode(genId);
 	node.setText(text);
@@ -168,13 +221,12 @@
 
     public void setRootItem(final String id, final String text, final StateToken stateToken) {
 	if (treePanel == null || treePanel.getNodeById(id) == null) {
-	    createTreePanel(id);
+	    createTreePanel(id, text, stateToken);
 	}
     }
 
-    public void setTopActions(final StateToken stateToken, final ActionCollection<StateToken> actions) {
-	final Toolbar toolBar = ws.getEntityWorkspace().getContextTopBar();
-	setToolbarActions(toolBar, stateToken, actions);
+    private void add(final ActionPosition toolbar, final Widget widget) {
+	getToolbar(toolbar).add(widget);
     }
 
     private void createItemMenu(final String nodeId, final ActionCollection<StateToken> actionCollection,
@@ -193,7 +245,7 @@
 			    public void onClick(final BaseItem item, final EventObject e) {
 				DeferredCommand.addCommand(new Command() {
 				    public void execute() {
-					actionManagerProvider.get().doAction(action, stateToken);
+					doAction(action, stateToken);
 				    }
 				});
 			    }
@@ -205,7 +257,45 @@
 	});
     }
 
-    private Menu createToolbarMenu(final Toolbar bar, final String iconUrl, final String menuTitle) {
+    private Item createMenuItem(final ActionPosition toolBarPos, final String menuTitle, final String menuSubTitle,
+	    final ActionDescriptor<StateToken> action) {
+	final Item item = new Item(action.getText(), new BaseItemListenerAdapter() {
+	    @Override
+	    public void onClick(BaseItem item, EventObject e) {
+		doAction(action, presenter.getCurrentStateToken());
+	    }
+	});
+	item.setIcon(action.getIconUrl());
+
+	final String menuKey = genMenuKey(toolBarPos, menuTitle, null, null);
+	final String subMenuKey = genMenuKey(toolBarPos, menuTitle, menuSubTitle, null);
+	Menu menu = toolbarMenus.get(menuKey);
+	Menu subMenu = toolbarMenus.get(subMenuKey);
+	if (menuSubTitle != null) {
+	    if (subMenu == null) {
+		subMenu = new Menu();
+		final MenuItem subMenuItem = new MenuItem(menuSubTitle, subMenu);
+		if (menu == null) {
+		    menu = createToolbarMenu(toolBarPos, action.getParentMenuIconUrl(), menuTitle, menuKey);
+		}
+		menu.addItem(subMenuItem);
+		toolbarMenus.put(subMenuKey, subMenu);
+	    }
+	    subMenu.addItem(item);
+
+	} else {
+	    // Menu action without submenu
+	    if (menu == null) {
+		menu = createToolbarMenu(toolBarPos, action.getParentMenuIconUrl(), menuTitle, menuKey);
+	    }
+	    menu.addItem(item);
+	}
+	doLayoutIfNeeded(toolBarPos);
+	return item;
+    }
+
+    private Menu createToolbarMenu(final ActionPosition barPosition, final String iconUrl, final String menuTitle,
+	    final String menuKey) {
 	final Menu menu = new Menu();
 	final ToolbarButton toolbarMenu = new ToolbarButton(menuTitle);
 	if (iconUrl != null) {
@@ -217,24 +307,26 @@
 		menu.showAt(e.getXY());
 	    }
 	});
-	toolbarMenus.put(menuTitle, menu);
-	bar.add(toolbarMenu);
+	toolbarMenus.put(menuKey, menu);
+	add(barPosition, toolbarMenu);
 	return menu;
     }
 
-    private void createTreePanel(final String rootId) {
+    private void createTreePanel(final String rootId, final String text, final StateToken stateToken) {
 	if (treePanel != null) {
 	    clear();
 	}
 	treePanel = new TreePanel();
 	treePanel.setAnimate(true);
 	treePanel.setBorder(false);
-	treePanel.setRootVisible(false);
+	treePanel.setRootVisible(true);
 	treePanel.setUseArrows(true);
 	final TreeNode root = new TreeNode();
 	root.setAllowDrag(false);
 	root.setExpanded(true);
 	root.setId(rootId);
+	root.setText(text);
+	root.setHref("#" + stateToken);
 	root.expand();
 	treePanel.addListener(new TreePanelListenerAdapter() {
 	    public void onContextMenu(final TreeNode node, final EventObject e) {
@@ -258,9 +350,26 @@
     }
 
     private void doAction(final ActionDescriptor<StateToken> action, final StateToken stateToken) {
-	actionManagerProvider.get().doAction(action, stateToken);
+	presenter.doAction(action, stateToken);
     }
 
+    private void doLayoutIfNeeded() {
+	doLayoutIfNeeded(ActionPosition.topbar);
+	doLayoutIfNeeded(ActionPosition.bottombar);
+    }
+
+    private void doLayoutIfNeeded(final ActionPosition pos) {
+	getToolbar(pos).doLayoutIfNeeded();
+    }
+
+    private String genMenuKey(final ActionPosition pos, final String menuTitle, final String menuSubTitle,
+	    final String actionText) {
+	final String basePart = "km-" + pos.toString() + "-" + menuTitle;
+	final String subMenuPart = menuSubTitle != null ? "-subm-" + menuSubTitle : "";
+	final String itemPart = actionText != null ? "-item-" + actionText : "";
+	return basePart + subMenuPart + itemPart;
+    }
+
     private TreeNode getNode(final String id) {
 	final TreeNode node = treePanel.getNodeById(id);
 	if (node == null) {
@@ -273,62 +382,15 @@
 	return node.getAttribute("href").substring(1);
     }
 
-    private void setToolbarActions(final Toolbar toolBar, final StateToken stateToken,
-	    final ActionCollection<StateToken> actions) {
-	toolBar.removeAll();
-	for (final ActionDescriptor<StateToken> action : actions) {
-	    Log.info("Procesing action: " + action.getText());
-	    if (!action.isMenuAction()) {
-		final ToolbarButton button = new ToolbarButton();
-		final String text = action.getText();
-		if (text != null) {
-		    button.setText(text);
-		}
-		button.addListener(new ButtonListenerAdapter() {
-		    @Override
-		    public void onClick(final Button button, final EventObject e) {
-			doAction(action, stateToken);
-		    }
-		});
-		button.setIcon(action.getIconUrl());
-		button.setTooltip(action.getToolTip());
-		toolBar.add(button);
-	    } else {
-		// Menu action
-		final Item item = new Item(action.getText(), new BaseItemListenerAdapter() {
-		    @Override
-		    public void onClick(BaseItem item, EventObject e) {
-			doAction(action, stateToken);
-		    }
-		});
-		item.setIcon(action.getIconUrl());
-
-		final String menuTitle = action.getParentMenuTitle();
-		final String menuSubTitle = action.getParentSubMenuTitle();
-		final String subMenuKey = menuTitle + "-" + menuSubTitle;
-		Menu menu = toolbarMenus.get(menuTitle);
-		Menu subMenu = toolbarMenus.get(subMenuKey);
-		if (menuSubTitle != null) {
-		    if (subMenu == null) {
-			subMenu = new Menu();
-			final MenuItem subMenuItem = new MenuItem(menuSubTitle, subMenu);
-			if (menu == null) {
-			    menu = createToolbarMenu(toolBar, action.getParentMenuIconUrl(), menuTitle);
-			}
-			menu.addItem(subMenuItem);
-			toolBar.doLayoutIfNeeded();
-			toolbarMenus.put(subMenuKey, subMenu);
-		    }
-		    subMenu.addItem(item);
-		} else {
-		    // Menu action without submenu
-		    if (menu == null) {
-			menu = createToolbarMenu(toolBar, action.getParentMenuIconUrl(), menuTitle);
-		    }
-		    menu.addItem(item);
-		    toolBar.doLayoutIfNeeded();
-		}
-	    }
+    private Toolbar getToolbar(final ActionPosition pos) {
+	switch (pos) {
+	case bootombarAndItemMenu:
+	case bottombar:
+	    return ws.getEntityWorkspace().getContextBottomBar();
+	case topbar:
+	case topbarAndItemMenu:
+	default:
+	    return ws.getEntityWorkspace().getContextTopBar();
 	}
     }
 }

Modified: trunk/src/main/java/org/ourproject/kune/workspace/client/ctxnav/ContextNavigatorPresenter.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/workspace/client/ctxnav/ContextNavigatorPresenter.java	2008-09-12 08:10:16 UTC (rev 868)
+++ trunk/src/main/java/org/ourproject/kune/workspace/client/ctxnav/ContextNavigatorPresenter.java	2008-09-13 03:32:44 UTC (rev 869)
@@ -26,6 +26,7 @@
 import org.ourproject.kune.platf.client.View;
 import org.ourproject.kune.platf.client.actions.ActionCollection;
 import org.ourproject.kune.platf.client.actions.ActionDescriptor;
+import org.ourproject.kune.platf.client.actions.ActionManager;
 import org.ourproject.kune.platf.client.dto.AccessRightsDTO;
 import org.ourproject.kune.platf.client.dto.ContainerDTO;
 import org.ourproject.kune.platf.client.dto.ContainerSimpleDTO;
@@ -55,20 +56,24 @@
     private final Provider<ContentServiceAsync> contentServiceProvider;
     private final I18nUITranslationService i18n;
     private final HashMap<String, ActionCollection<StateToken>> actions;
+    private final HashMap<StateToken, ActionCollection<StateToken>> actionsByItem;
     private final ArrayList<String> draggables;
     private final ArrayList<String> droppables;
     private final HashMap<String, String> contentTypesIcons;
     private final EntityTitle entityTitle;
+    private final Provider<ActionManager> actionManagerProvider;
 
     public ContextNavigatorPresenter(final StateManager stateManager, final Session session,
 	    final Provider<ContentServiceAsync> contentServiceProvider, final I18nUITranslationService i18n,
-	    final EntityTitle entityTitle) {
+	    final EntityTitle entityTitle, final Provider<ActionManager> actionManagerProvider) {
 	this.stateManager = stateManager;
 	this.session = session;
 	this.contentServiceProvider = contentServiceProvider;
 	this.i18n = i18n;
 	this.entityTitle = entityTitle;
+	this.actionManagerProvider = actionManagerProvider;
 	actions = new HashMap<String, ActionCollection<StateToken>>();
+	actionsByItem = new HashMap<StateToken, ActionCollection<StateToken>>();
 	draggables = new ArrayList<String>();
 	droppables = new ArrayList<String>();
 	contentTypesIcons = new HashMap<String, String>();
@@ -83,38 +88,50 @@
 	actionColl.add(action);
     }
 
+    public void doAction(final ActionDescriptor<StateToken> action, final StateToken stateToken) {
+	actionManagerProvider.get().doAction(action, stateToken);
+    }
+
     public void editItem(final StateToken stateToken) {
 	view.editItem(genId(stateToken));
     }
 
+    public StateToken getCurrentStateToken() {
+	return session.getCurrentState().getStateToken();
+    }
+
     public View getView() {
 	return view;
     }
 
+    public void gotoToken(final String token) {
+	stateManager.gotoToken(token);
+    }
+
     public void init(final ContextNavigatorView view) {
 	this.view = view;
 	stateManager.onGroupChanged(new Slot2<String, String>() {
 	    public void onEvent(final String oldGroup, final String newGroup) {
 		if (oldGroup != null) {
-		    view.clear();
+		    clear();
 		}
 	    }
 	});
 	stateManager.onToolChanged(new Slot2<String, String>() {
 	    public void onEvent(final String oldTool, final String newTool) {
 		if (oldTool != null) {
-		    view.clear();
+		    clear();
 		}
 	    }
 	});
 	session.onUserSignIn(new Slot<UserInfoDTO>() {
 	    public void onEvent(final UserInfoDTO parameter) {
-		view.clear();
+		clear();
 	    }
 	});
 	session.onUserSignOut(new Slot0() {
 	    public void onEvent() {
-		view.clear();
+		clear();
 	    }
 	});
     }
@@ -126,7 +143,7 @@
 	    contentServiceProvider.get().rename(session.getUserHash(), currentState.getGroup().getShortName(), token,
 		    newName, new AsyncCallback<String>() {
 			public void onFailure(final Throwable caught) {
-			    view.setItemText(genId(new StateToken(token)), oldName);
+			    setItemText(new StateToken(token), oldName);
 			    Site.error(i18n.t("Error renaming"));
 			    Site.hideProgress();
 			}
@@ -160,54 +177,73 @@
 
     public void selectItem(final StateToken stateToken) {
 	view.selectItem(genId(stateToken));
+	view.removeAllButtons();
+	view.disableAllMenuItems();
+	setActions(actionsByItem.get(stateToken), true);
     }
 
+    public void setItemText(final StateToken stateToken, final String name) {
+	view.setItemText(genId(stateToken), name);
+    }
+
     public void setState(final StateDTO state) {
 	final ContainerDTO container = state.getFolder();
 
-	createTreePath(state.getStateToken(), container.getAbsolutePath(), state.getFolderRights());
+	final StateToken stateToken = state.getStateToken();
+	createTreePath(stateToken, container.getAbsolutePath(), state.getFolderRights());
 
+	ActionCollection<StateToken> selectedToolbarActions;
+
 	if (state.hasDocument()) {
-	    addItem(state.getTitle(), state.getTypeId(), state.getStatus(), state.getStateToken(), container
-		    .getStateToken(), state.getContentRights());
+	    selectedToolbarActions = addItem(state.getTitle(), state.getTypeId(), state.getStatus(), stateToken,
+		    container.getStateToken(), state.getContentRights(), false);
 	} else {
-	    addItem(container.getName(), container.getTypeId(), ContentStatusDTO.publishedOnline, container
-		    .getStateToken(), container.getStateToken().clone().setFolder(container.getParentFolderId()), state
-		    .getFolderRights());
+	    selectedToolbarActions = addItem(container.getName(), container.getTypeId(),
+		    ContentStatusDTO.publishedOnline, container.getStateToken(), container.getStateToken().clone()
+			    .setFolder(container.getParentFolderId()), state.getFolderRights(), false);
 	}
 
 	for (final ContentDTO content : container.getContents()) {
 	    addItem(content.getTitle(), content.getTypeId(), content.getStatus(), content.getStateToken(), content
-		    .getStateToken().clone().clearDocument(), content.getRights());
+		    .getStateToken().clone().clearDocument(), content.getRights(), false);
 	}
 
 	for (final ContainerSimpleDTO siblingFolder : container.getChilds()) {
 	    addItem(siblingFolder.getName(), siblingFolder.getTypeId(), ContentStatusDTO.publishedOnline, siblingFolder
 		    .getStateToken(), siblingFolder.getStateToken().clone()
-		    .setFolder(siblingFolder.getParentFolderId()), state.getFolderRights());
+		    .setFolder(siblingFolder.getParentFolderId()), state.getFolderRights(), false);
 	}
-	view.selectItem(genId(state.getStateToken()));
+
+	actionsByItem.put(stateToken, selectedToolbarActions);
+
+	selectItem(stateToken);
     }
 
-    private void addItem(final String title, final String contentTypeId, final ContentStatusDTO status,
-	    final StateToken stateToken, final StateToken parentStateToken, final AccessRightsDTO rights) {
-	final ActionCollection<StateToken> topActions = new ActionCollection<StateToken>();
+    private ActionCollection<StateToken> addItem(final String title, final String contentTypeId,
+	    final ContentStatusDTO status, final StateToken stateToken, final StateToken parentStateToken,
+	    final AccessRightsDTO rights, final boolean isNodeSelected) {
+	final ActionCollection<StateToken> toolbarActions = new ActionCollection<StateToken>();
 	final ActionCollection<StateToken> itemActions = new ActionCollection<StateToken>();
-	final ActionCollection<StateToken> bottomActions = new ActionCollection<StateToken>();
 
-	createItemActions(rights, contentTypeId, topActions, itemActions, bottomActions);
+	createItemActions(rights, contentTypeId, toolbarActions, itemActions);
 
-	view.setTopActions(stateToken, topActions);
-	view.setBottomActions(stateToken, bottomActions);
+	setActions(toolbarActions, isNodeSelected);
+
 	final ContextNavigatorItem item = new ContextNavigatorItem(genId(stateToken), genId(parentStateToken),
 		getContentTypeIcon(contentTypeId), title, status, stateToken, isDraggable(contentTypeId, rights
 			.isAdministrable()), isDroppable(contentTypeId, rights.isAdministrable()), itemActions);
 	view.addItem(item);
+
+	return toolbarActions;
     }
 
+    private void clear() {
+	view.clear();
+	actionsByItem.clear();
+    }
+
     private void createItemActions(final AccessRightsDTO rights, final String contentTypeId,
-	    final ActionCollection<StateToken> topActions, final ActionCollection<StateToken> itemActions,
-	    final ActionCollection<StateToken> bottomActions) {
+	    final ActionCollection<StateToken> toolbarActionas, final ActionCollection<StateToken> itemActions) {
 	boolean add = false;
 
 	for (final ActionDescriptor<StateToken> action : actions.get(contentTypeId)) {
@@ -227,12 +263,12 @@
 		case topbarAndItemMenu:
 		    itemActions.add(action);
 		case topbar:
-		    topActions.add(action);
+		    toolbarActionas.add(action);
 		    break;
 		case bootombarAndItemMenu:
 		    itemActions.add(action);
 		case bottombar:
-		    bottomActions.add(action);
+		    toolbarActionas.add(action);
 		    break;
 		case itemMenu:
 		    itemActions.add(action);
@@ -251,10 +287,10 @@
 
 	    if (folder.getParentFolderId() != null) {
 		addItem(folder.getName(), folder.getTypeId(), ContentStatusDTO.publishedOnline, folderStateToken,
-			parentStateToken, rights);
+			parentStateToken, rights, false);
 	    } else {
 		// create root folder
-		view.setRootItem(genId(folderStateToken), i18n.t("contents"), folderStateToken);
+		view.setRootItem(genId(folderStateToken), i18n.t(folder.getName()), folderStateToken);
 	    }
 	}
     }
@@ -265,7 +301,6 @@
 
     private String getContentTypeIcon(final String typeId) {
 	final String icon = contentTypesIcons.get(typeId);
-	// TODO Auto-generated method stub
 	return icon == null ? "" : icon;
     }
 
@@ -277,4 +312,15 @@
 	return administrable && droppables.contains(typeId);
     }
 
+    private void setActions(final ActionCollection<StateToken> actions, final boolean isNodeSelected) {
+	for (final ActionDescriptor<StateToken> action : actions) {
+	    if (action.isMenuAction()) {
+		view.addMenuAction(action, isNodeSelected);
+	    } else {
+		if (isNodeSelected) {
+		    view.addButtonAction(action);
+		}
+	    }
+	}
+    }
 }

Modified: trunk/src/main/java/org/ourproject/kune/workspace/client/ctxnav/ContextNavigatorView.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/workspace/client/ctxnav/ContextNavigatorView.java	2008-09-12 08:10:16 UTC (rev 868)
+++ trunk/src/main/java/org/ourproject/kune/workspace/client/ctxnav/ContextNavigatorView.java	2008-09-13 03:32:44 UTC (rev 869)
@@ -21,25 +21,29 @@
 package org.ourproject.kune.workspace.client.ctxnav;
 
 import org.ourproject.kune.platf.client.View;
-import org.ourproject.kune.platf.client.actions.ActionCollection;
+import org.ourproject.kune.platf.client.actions.ActionDescriptor;
 import org.ourproject.kune.platf.client.dto.StateToken;
 
 public interface ContextNavigatorView extends View {
 
+    void addButtonAction(ActionDescriptor<StateToken> action);
+
     void addItem(ContextNavigatorItem contextNavigatorItem);
 
+    void addMenuAction(ActionDescriptor<StateToken> action, boolean enable);
+
     void clear();
 
+    void disableAllMenuItems();
+
     void editItem(String id);
 
+    void removeAllButtons();
+
     void selectItem(String id);
 
-    void setBottomActions(StateToken stateToken, ActionCollection<StateToken> actions);
+    void setItemText(String id, String text);
 
-    void setItemText(String genId, String text);
-
     void setRootItem(String id, String text, StateToken stateToken);
 
-    void setTopActions(StateToken stateToken, ActionCollection<StateToken> actions);
-
 }

Modified: trunk/src/main/java/org/ourproject/kune/workspace/client/title/EntityTitlePresenter.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/workspace/client/title/EntityTitlePresenter.java	2008-09-12 08:10:16 UTC (rev 868)
+++ trunk/src/main/java/org/ourproject/kune/workspace/client/title/EntityTitlePresenter.java	2008-09-13 03:32:44 UTC (rev 869)
@@ -24,11 +24,13 @@
 
 import org.ourproject.kune.platf.client.View;
 import org.ourproject.kune.platf.client.dto.StateDTO;
+import org.ourproject.kune.platf.client.dto.StateToken;
 import org.ourproject.kune.platf.client.rpc.ContentServiceAsync;
 import org.ourproject.kune.platf.client.services.I18nTranslationService;
 import org.ourproject.kune.platf.client.services.KuneErrorHandler;
 import org.ourproject.kune.platf.client.state.Session;
 import org.ourproject.kune.platf.client.state.StateManager;
+import org.ourproject.kune.workspace.client.ctxnav.ContextNavigator;
 import org.ourproject.kune.workspace.client.site.Site;
 
 import com.calclab.suco.client.provider.Provider;
@@ -41,18 +43,19 @@
     private EntityTitleView view;
     private final I18nTranslationService i18n;
     private final KuneErrorHandler errorHandler;
-    private final StateManager stateManager;
     private final Provider<ContentServiceAsync> contentServiceProvider;
     private final Session session;
+    private final Provider<ContextNavigator> contextNavigatorProvider;
 
     public EntityTitlePresenter(final I18nTranslationService i18n, final KuneErrorHandler errorHandler,
 	    final StateManager stateManager, final Session session,
-	    final Provider<ContentServiceAsync> contentServiceProvider) {
+	    final Provider<ContentServiceAsync> contentServiceProvider,
+	    final Provider<ContextNavigator> contextNavigatorProvider) {
 	this.i18n = i18n;
 	this.errorHandler = errorHandler;
-	this.stateManager = stateManager;
 	this.session = session;
 	this.contentServiceProvider = contentServiceProvider;
+	this.contextNavigatorProvider = contextNavigatorProvider;
 	stateManager.onStateChanged(new Slot<StateDTO>() {
 	    public void onEvent(final StateDTO state) {
 		setState(state);
@@ -88,8 +91,9 @@
     protected void onTitleRename(final String newName) {
 	Site.showProgressSaving();
 	final StateDTO currentState = session.getCurrentState();
+	final StateToken stateToken = currentState.getStateToken();
 	contentServiceProvider.get().rename(session.getUserHash(), currentState.getGroup().getShortName(),
-		currentState.getStateToken().getEncoded(), newName, new AsyncCallback<String>() {
+		stateToken.getEncoded(), newName, new AsyncCallback<String>() {
 		    public void onFailure(final Throwable caught) {
 			view.restoreOldTitle();
 			errorHandler.process(caught);
@@ -98,7 +102,7 @@
 		    public void onSuccess(final String result) {
 			Site.hideProgress();
 			view.setContentTitle(result);
-			stateManager.reloadContextAndTitles();
+			contextNavigatorProvider.get().setItemText(stateToken, newName);
 		    }
 		});
 	Site.hideProgress();




More information about the kune-commits mailing list