Author: lucaa
Date: 2008-02-17 02:28:27 +0100 (Sun, 17 Feb 2008)
New Revision: 7769

Added:
   
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/data/Group.java
   
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/ui/dialog/GroupDialog.java
Removed:
   
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/ui/dialog/AddGroupDialog.java
Modified:
   
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/Config.java
   
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/Watch.java
   
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/data/DataManager.java
   
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/ui/dialog/AddKeywordDialog.java
   
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/ui/dialog/FeedDialog.java
   
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/ui/menu/FeedTreeWidget.java
   
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/ui/menu/KeywordsWidget.java
   
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/ui/wizard/ConfigWizard.java
   
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/public/Watch.css
   
xwiki-products/xwiki-watch/trunk/wikis/watch/src/main/resources/WatchCode/Translations
   
xwiki-products/xwiki-watch/trunk/wikis/watch/src/main/resources/WatchCode/Translations.fr
   
xwiki-products/xwiki-watch/trunk/wikis/watch/src/main/resources/WatchSheets/GroupSheet
Log:
XWATCH-96: Adding a "delete" button under group names in the list on the left
* Added class for groups (com.xpn.xwiki.watch.client.data.Group)
* Added the delete and edit buttons under the group name in the feedtree; 
delete triggers update on the feeds in the group and the keywords defined for 
the group 
* Fixed the WatchSheets.GroupSheet  to  correctly display the feeds in the group


Modified: 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/Config.java
===================================================================
--- 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/Config.java
   2008-02-15 22:20:07 UTC (rev 7768)
+++ 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/Config.java
   2008-02-17 01:28:27 UTC (rev 7769)
@@ -4,6 +4,7 @@
 import com.xpn.xwiki.gwt.api.client.Document;
 import com.xpn.xwiki.gwt.api.client.XObject;
 import com.xpn.xwiki.watch.client.data.FeedArticle;
+import com.xpn.xwiki.watch.client.data.Group;
 import com.xpn.xwiki.watch.client.data.Keyword;
 import com.google.gwt.user.client.rpc.AsyncCallback;
 
@@ -131,7 +132,7 @@
         }
     }
 
-    private void addToGroup(String group, String groupTitle, Feed feed) {
+    private void addToGroup(String group, Feed feed) {
         Map feeds = (Map) feedsByGroupList.get(group);
         if (feeds == null) {
             feeds = new HashMap();
@@ -139,8 +140,11 @@
         }
         if (feed!=null)
          feeds.put(feed.getName(), feed);
-        if (!groups.containsKey(group))
-          groups.put(group, groupTitle);
+        if (!groups.containsKey(group)) {
+            Group newGroup = new Group();
+            newGroup.setName(group);
+            groups.put(group, newGroup);
+        }
     }
 
     private void addToConfig(Document feedpage) {
@@ -153,11 +157,11 @@
                 if (feedgroups!=null) {
                     for (int j=0;j<feedgroups.size();j++) {
                         String groupFullName = (String) feedgroups.get(j);
-                        addToGroup(groupFullName, groupFullName, feed);
+                        addToGroup(groupFullName, feed);
                     }
                 }
                 String all = watch.getTranslation("all");
-                addToGroup(all, all, feed);
+                addToGroup(all, feed);
                 feedsList.put(feed.getName(), feed);
             }
         }
@@ -174,9 +178,9 @@
         if (gobjects!=null) {
             for (int j=0;j<gobjects.size();j++) {
                 XObject xobj = (XObject) gobjects.get(j);
-                String name = (String) xobj.getViewProperty("name");
-                if ((name!=null)&&(!name.equals("")))
-                    groups.put(feedpage.getFullName(), name);
+                Group group = new Group(xobj);
+                if ((group.getName()!=null)&&(!group.getName().equals("")))
+                    groups.put(feedpage.getFullName(), group);
             }
          }
 

Modified: 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/Watch.java
===================================================================
--- 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/Watch.java
    2008-02-15 22:20:07 UTC (rev 7768)
+++ 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/Watch.java
    2008-02-17 01:28:27 UTC (rev 7769)
@@ -9,6 +9,7 @@
 import com.xpn.xwiki.watch.client.ui.wizard.ConfigWizard;
 import com.xpn.xwiki.watch.client.ui.wizard.PressReviewWizard;
 import com.xpn.xwiki.watch.client.data.DataManager;
+import com.xpn.xwiki.watch.client.data.Group;
 import com.xpn.xwiki.watch.client.data.Keyword;
 import com.google.gwt.user.client.Window;
 import com.google.gwt.user.client.rpc.AsyncCallback;
@@ -341,6 +342,8 @@
             getFilterStatus().setGroup(groupName);
         getFilterStatus().setStart(0);
         refreshArticleList();
+        //also refresh the tree, to set the current selected group
+        refreshFeedTree();
     }
 
     /**
@@ -515,7 +518,7 @@
         });
     }
 
-    public void addGroup(final String group, final AsyncCallback cb) {
+    public void addGroup(final Group group, final AsyncCallback cb) {
         getDataManager().addGroup(group, new XWikiAsyncCallback(this) {
             public void onFailure(Throwable caught) {
                 super.onFailure(caught);

Modified: 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/data/DataManager.java
===================================================================
--- 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/data/DataManager.java
 2008-02-15 22:20:07 UTC (rev 7768)
+++ 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/data/DataManager.java
 2008-02-17 01:28:27 UTC (rev 7769)
@@ -4,6 +4,7 @@
 import com.xpn.xwiki.watch.client.FilterStatus;
 import com.xpn.xwiki.watch.client.Constants;
 import com.xpn.xwiki.watch.client.Feed;
+import com.xpn.xwiki.gwt.api.client.app.ModalMessageDialogBox;
 import com.xpn.xwiki.gwt.api.client.app.XWikiAsyncCallback;
 import com.xpn.xwiki.gwt.api.client.XWikiService;
 import com.xpn.xwiki.gwt.api.client.XObject;
@@ -126,7 +127,56 @@
             }
         });
     }
+    
+    public void updateGroup(Group group, final XWikiAsyncCallback cb) {
+        final String pageName = group.getPageName();
+        if (pageName == null || pageName.equals("") || 
group.getName().equals("")) {
+            cb.onFailure(null);
+        }
+        //create a group object and save it
+        XObject groupObj = new XObject();
+        groupObj.setName(pageName);
+        groupObj.setClassName(Constants.CLASS_AGGREGATOR_GROUP);
+        groupObj.setNumber(0);
+        groupObj.setProperty(Constants.PROPERTY_GROUP_NAME, group.getName());
+        watch.getXWikiServiceInstance().saveObject(groupObj, new 
AsyncCallback() {
+            public void onFailure(Throwable throwable) {
+                cb.onFailure(throwable);
+            }
+            public void onSuccess(Object object) {
+                // We return the page name
+                if (!((Boolean)object).booleanValue()) {
+                    cb.onFailure(null);
+                } else {
+                    cb.onSuccess(pageName);
+                }
+            }
+        });
+    }
+    
+    public void updateKeyword(Keyword keyword, final XWikiAsyncCallback cb) {
+        final String pageName = keyword.getPageName();
+        XObject kwObject = new XObject();
+        kwObject.setName(pageName);
+        kwObject.setClassName(Constants.CLASS_AGGREGATOR_KEYWORD);
+        kwObject.setNumber(0);
+        kwObject.setProperty(Constants.PROPERTY_KEYWORD_NAME, 
keyword.getName());
+        kwObject.setProperty(Constants.PROPERTY_KEYWORD_GROUP, 
keyword.getGroup());
+        watch.getXWikiServiceInstance().saveObject(kwObject, new 
AsyncCallback() {
+            public void onFailure(Throwable throwable) {
+                cb.onFailure(throwable);
+            }
 
+            public void onSuccess(Object object) {
+                // We return the page name
+                if (!((Boolean)object).booleanValue())
+                    cb.onFailure(null);
+                else
+                    cb.onSuccess(pageName);
+            }
+        });        
+    }
+
     public void addKeyword(final String keyword, final String group, final 
AsyncCallback cb) {
         if (keyword==null)
             cb.onFailure(null);
@@ -178,11 +228,12 @@
         });
     }
 
-    public void addGroup(final String group, final AsyncCallback cb) {
+    public void addGroup(final Group group, final AsyncCallback cb) {
         if (group==null)
             cb.onFailure(null);
 
-        
watch.getXWikiServiceInstance().getUniquePageName(watch.getWatchSpace(), 
"Group_" + group, new XWikiAsyncCallback(watch) {
+        
watch.getXWikiServiceInstance().getUniquePageName(watch.getWatchSpace(), 
+                "Group_" + group.getName(), new XWikiAsyncCallback(watch) {
             public void onFailure(Throwable caught) {
                 super.onFailure(caught);
                 // We failed to get a unique page name
@@ -198,7 +249,7 @@
                 feedObj.setName(pageName);
                 feedObj.setClassName(Constants.CLASS_AGGREGATOR_GROUP);
                 feedObj.setNumber(0);
-                feedObj.setProperty(Constants.PROPERTY_KEYWORD_NAME, group);
+                feedObj.setProperty(Constants.PROPERTY_GROUP_NAME, 
group.getName());
                 watch.getXWikiServiceInstance().saveObject(feedObj, new 
AsyncCallback() {
                     public void onFailure(Throwable throwable) {
                         cb.onFailure(throwable);
@@ -249,12 +300,50 @@
         }
     }
 
-    public void removeGroup(String group, final AsyncCallback cb) {
+    public void removeGroup(Group group, final AsyncCallback cb) {
         try {
-            if ((group==null)||(group.equals("")))
+            if ((group==null)||(group.equals(""))) {
                 cb.onFailure(null);
-
-            watch.getXWikiServiceInstance().deleteDocument(group, new 
XWikiAsyncCallback(watch) {
+                return;
+            }
+            //first update feeds in this group to unset the group
+            //TODO: decide what to do if one update fails
+            Collection feedList = 
(Collection)((Map)watch.getConfig().getFeedsByGroupList()
+                                  .get(group.getPageName())).values();
+                   for (Iterator feedListIt = feedList.iterator(); 
feedListIt.hasNext();) {
+                       Feed currentFeed = (Feed)feedListIt.next();
+                       currentFeed.getGroups().remove(group.getPageName());
+                       this.updateFeed(currentFeed, new 
XWikiAsyncCallback(watch) {
+                           public void onSuccess(Object result) {
+                               super.onSuccess(result);
+                           }
+                           public void onFailure(Throwable caught) {
+                               super.onFailure(caught);
+                           }
+                       });
+                   }
+            
+            //update the keywords for this group and delete them
+            List keywords = watch.getConfig().getKeywords();
+            for (Iterator kwIt = keywords.iterator(); kwIt.hasNext();) {
+                Keyword kw = (Keyword)kwIt.next();
+                if (kw.getGroup().equals(group.getPageName())) {
+                    //update keyword remove group
+                    kw.setGroup("");
+                    this.updateKeyword(kw, new XWikiAsyncCallback(watch) {
+                        public void onSuccess(Object result) {
+                            super.onSuccess(result);
+                        }
+                        public void onFailure(Throwable caught) {
+                            super.onFailure(caught);
+                        }
+                    });                    
+                }
+            }
+            
+                   //now delete the group
+                   
watch.getXWikiServiceInstance().deleteDocument(group.getPageName(), 
+                           new XWikiAsyncCallback(watch) {
                 public void onFailure(Throwable caught) {
                     super.onFailure(caught);
                     cb.onFailure(caught);

Added: 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/data/Group.java
===================================================================
--- 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/data/Group.java
                               (rev 0)
+++ 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/data/Group.java
       2008-02-17 01:28:27 UTC (rev 7769)
@@ -0,0 +1,57 @@
+/**
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ * <p/>
+ * This 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 version2.1of
+ * the License,or(at your option)any later version.
+ * <p/>
+ * This software 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.
+ * <p/>
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software;if not,write to the Free
+ * Software Foundation,Inc.,51 Franklin St,Fifth Floor,Boston,MA
+ * 02110-1301 USA,or see the FSF site:http://www.fsf.org.
+ *
+ */
+
+package com.xpn.xwiki.watch.client.data;
+
+import com.xpn.xwiki.gwt.api.client.XObject;
+
+public class Group
+{
+    private String name;
+    private String pageName;
+    
+    public Group() {}
+    
+    public Group(XObject xobj) {
+        setName((String) xobj.getProperty("name"));
+        setPageName(xobj.getName());
+    }
+
+    public String getName()
+    {
+        return name == null ? "" : name;
+    }
+
+    public void setName(String name)
+    {
+        this.name = name;
+    }
+
+    public String getPageName()
+    {
+        return pageName == null ? "" : pageName;
+    }
+
+    public void setPageName(String pageName)
+    {
+        this.pageName = pageName;
+    }    
+}

Deleted: 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/ui/dialog/AddGroupDialog.java
===================================================================
--- 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/ui/dialog/AddGroupDialog.java
 2008-02-15 22:20:07 UTC (rev 7768)
+++ 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/ui/dialog/AddGroupDialog.java
 2008-02-17 01:28:27 UTC (rev 7769)
@@ -1,113 +0,0 @@
-package com.xpn.xwiki.watch.client.ui.dialog;
-
-import com.google.gwt.user.client.ui.*;
-import com.google.gwt.user.client.Window;
-import com.google.gwt.user.client.rpc.AsyncCallback;
-import com.xpn.xwiki.gwt.api.client.app.XWikiGWTApp;
-import com.xpn.xwiki.gwt.api.client.dialog.Dialog;
-import com.xpn.xwiki.watch.client.Watch;
-
-import java.util.List;
-import java.util.ArrayList;
-
-/**
- * See the NOTICE file distributed with this work for additional
- * information regarding copyright ownership.
- * <p/>
- * This 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 version2.1of
- * the License,or(at your option)any later version.
- * <p/>
- * This software 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.
- * <p/>
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software;if not,write to the Free
- * Software Foundation,Inc.,51 Franklin St,Fifth Floor,Boston,MA
- * 02110-1301 USA,or see the FSF site:http://www.fsf.org.
- *
- * @author ldubost
- */
-
-public class AddGroupDialog extends Dialog {
-    protected TextBox groupTextBox;
-    protected String group;
-
-    /**
-     * Choice dialog
-     * @param app  XWiki GWT App object to access translations and css prefix 
names
-     * @param name dialog name
-     * @param buttonModes button modes Dialog.BUTTON_CANCEL|Dialog.BUTTON_NEXT 
for Cancel / Next
-     */
-    public AddGroupDialog(XWikiGWTApp app, String name, int buttonModes, 
String group) {
-        super(app, name, buttonModes);
-        this.group = group;
-
-        FlowPanel main = new FlowPanel();
-        main.addStyleName(getCSSName("main"));
-
-        HTMLPanel invitationPanel = new 
HTMLPanel(app.getTranslation(getDialogTranslationName() + ".invitation"));
-        invitationPanel.addStyleName(getCssPrefix() + "-invitation");
-        main.add(invitationPanel);
-        main.add(getParametersPanel());
-        main.add(getActionsPanel());
-        add(main);
-    }
-
-    protected boolean updateData() {
-        group = groupTextBox.getText();
-
-        if (group.equals("")) {
-            Window.alert(app.getTranslation(getDialogTranslationName() + 
".nogroup"));
-            return false;
-        }
-
-        return true;
-    }
-
-    protected Widget getParametersPanel() {
-        FlowPanel paramsPanel = new FlowPanel();
-        Label groupLabel = new Label();
-        groupLabel.setStyleName("group-label");
-        groupLabel.setText(app.getTranslation(getDialogTranslationName() + 
".group"));
-        paramsPanel.add(groupLabel);
-        groupTextBox = new TextBox();
-        if (group!=null)
-            groupTextBox.setText(group);
-        groupTextBox.setVisibleLength(20);
-        groupTextBox.setName("group");
-        groupTextBox.setStyleName(getCSSName("group"));
-        paramsPanel.add(groupTextBox);
-        paramsPanel.add(getGroupsFields());
-        return paramsPanel;
-    }
-
-    protected Widget getGroupsFields() {
-        return new FlowPanel();
-    }
-
-    protected void endDialog() {
-        if (updateData()) {
-            setCurrentResult(group);
-            ((Watch)app).addGroup(group, new AsyncCallback() {
-                public void onFailure(Throwable throwable) {
-                    // There should already have been an error display
-                    ((Watch)app).refreshFeedTree();
-                }
-
-                public void onSuccess(Object object) {
-                    endDialog2();
-                    ((Watch)app).refreshFeedTree();
-                }
-            });
-        }
-    }
-
-    private void endDialog2() {
-        super.endDialog();
-    }
-
-}

Modified: 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/ui/dialog/AddKeywordDialog.java
===================================================================
--- 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/ui/dialog/AddKeywordDialog.java
       2008-02-15 22:20:07 UTC (rev 7768)
+++ 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/ui/dialog/AddKeywordDialog.java
       2008-02-17 01:28:27 UTC (rev 7769)
@@ -22,6 +22,7 @@
 import com.xpn.xwiki.gwt.api.client.app.XWikiGWTApp;
 import com.xpn.xwiki.gwt.api.client.dialog.Dialog;
 import com.xpn.xwiki.watch.client.Watch;
+import com.xpn.xwiki.watch.client.data.Group;
 import com.google.gwt.user.client.ui.*;
 import com.google.gwt.user.client.Window;
 import com.google.gwt.user.client.rpc.AsyncCallback;
@@ -103,11 +104,16 @@
         while (it.hasNext()) {
             String groupname = (String) it.next();
             if (!groupname.equals(all)) {
-                String grouptitle = (String) groupMap.get(groupname);
-                groupListBox.addItem(grouptitle,groupname);
-                if (group.equals(groupname)) {
-                    selected = true;
-                    groupListBox.setItemSelected(groupListBox.getItemCount(), 
true);
+                //get group for this key
+                Group currentGroup = (Group)groupMap.get(groupname);
+                //don't add it unless it is a real group
+                if (!currentGroup.getPageName().equals("") || 
group.equals(groupname)) {
+                    String grouptitle = currentGroup.getName();
+                    groupListBox.addItem(grouptitle,groupname);
+                    if (group.equals(groupname)) {
+                        selected = true;
+                        
groupListBox.setItemSelected(groupListBox.getItemCount(), true);
+                    }
                 }
             }
         }
@@ -131,8 +137,6 @@
                 public void onSuccess(Object object) 
                 {
                     endDialog2();
-                    // We don't need to refresh keywords here as it as been 
taken care by the addKeyword call
-                    //((Watch)app).refreshOnNewKeyword()
                 }
             });
         }

Modified: 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/ui/dialog/FeedDialog.java
===================================================================
--- 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/ui/dialog/FeedDialog.java
     2008-02-15 22:20:07 UTC (rev 7768)
+++ 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/ui/dialog/FeedDialog.java
     2008-02-17 01:28:27 UTC (rev 7769)
@@ -5,6 +5,7 @@
 import com.xpn.xwiki.gwt.api.client.dialog.Dialog;
 import com.xpn.xwiki.watch.client.Feed;
 import com.xpn.xwiki.watch.client.Watch;
+import com.xpn.xwiki.watch.client.data.Group;
 import com.google.gwt.user.client.ui.*;
 import com.google.gwt.user.client.rpc.AsyncCallback;
 
@@ -113,12 +114,17 @@
             String groupname = (String) it.next();
             String all = ((Watch)app).getTranslation("all");
             if (!groupname.equals(all)) {
-                String grouptitle = (String) groupMap.get(groupname);
-                if (groupname.indexOf(".")==-1)
-                 grouptitle = "[" + grouptitle + "]";
-                groupsListBox.addItem(grouptitle, groupname);
-                if (currentGroups.contains(groupname)) {
-                    
groupsListBox.setItemSelected(groupsListBox.getItemCount()-1, true);
+                //get group for this key
+                Group currentGroup = (Group)groupMap.get(groupname);
+                //don't add unless it is a real group
+                if (!currentGroup.getPageName().equals("") || 
currentGroups.contains(groupname)) {
+                    String grouptitle = currentGroup.getName();
+                    if (groupname.indexOf(".")==-1)
+                     grouptitle = "[" + grouptitle + "]";
+                    groupsListBox.addItem(grouptitle, groupname);
+                    if (currentGroups.contains(groupname)) {
+                        
groupsListBox.setItemSelected(groupsListBox.getItemCount()-1, true);
+                    }
                 }
             }
         }

Added: 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/ui/dialog/GroupDialog.java
===================================================================
--- 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/ui/dialog/GroupDialog.java
                            (rev 0)
+++ 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/ui/dialog/GroupDialog.java
    2008-02-17 01:28:27 UTC (rev 7769)
@@ -0,0 +1,119 @@
+package com.xpn.xwiki.watch.client.ui.dialog;
+
+import com.google.gwt.user.client.ui.*;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.xpn.xwiki.gwt.api.client.app.XWikiGWTApp;
+import com.xpn.xwiki.gwt.api.client.dialog.Dialog;
+import com.xpn.xwiki.watch.client.Watch;
+import com.xpn.xwiki.watch.client.data.Group;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ * <p/>
+ * This 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 version2.1of
+ * the License,or(at your option)any later version.
+ * <p/>
+ * This software 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.
+ * <p/>
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software;if not,write to the Free
+ * Software Foundation,Inc.,51 Franklin St,Fifth Floor,Boston,MA
+ * 02110-1301 USA,or see the FSF site:http://www.fsf.org.
+ *
+ * @author ldubost
+ */
+
+public class GroupDialog extends Dialog {
+    protected TextBox groupTextBox;
+    protected Group group;
+
+    /**
+     * Choice dialog
+     * @param app  XWiki GWT App object to access translations and css prefix 
names
+     * @param name dialog name
+     * @param buttonModes button modes Dialog.BUTTON_CANCEL|Dialog.BUTTON_NEXT 
for Cancel / Next
+     */
+    public GroupDialog(XWikiGWTApp app, String name, int buttonModes, Group 
group) {
+        super(app, name, buttonModes);
+        this.group = group;
+
+        FlowPanel main = new FlowPanel();
+        main.addStyleName(getCSSName("main"));
+
+        HTMLPanel invitationPanel = new 
HTMLPanel(app.getTranslation(getDialogTranslationName() + ".invitation"));
+        invitationPanel.addStyleName(getCssPrefix() + "-invitation");
+        main.add(invitationPanel);
+        main.add(getParametersPanel());
+        main.add(getActionsPanel());
+        add(main);
+    }
+
+    protected boolean updateData() {
+        String groupName = groupTextBox.getText();
+
+        if (groupName.equals("")) {
+            Window.alert(app.getTranslation(getDialogTranslationName() + 
".nogroup"));
+            return false;
+        } else {
+            this.group.setName(groupName);
+            return true;
+        }
+    }
+
+    protected Widget getParametersPanel() {
+        FlowPanel paramsPanel = new FlowPanel();
+        Label groupLabel = new Label();
+        groupLabel.setStyleName("group-label");
+        groupLabel.setText(app.getTranslation(getDialogTranslationName() + 
".group"));
+        paramsPanel.add(groupLabel);
+        groupTextBox = new TextBox();
+        if (group!=null)
+            groupTextBox.setText(group.getName());
+        groupTextBox.setVisibleLength(20);
+        groupTextBox.setName("group");
+        groupTextBox.setStyleName(getCSSName("group"));
+        paramsPanel.add(groupTextBox);
+        paramsPanel.add(getGroupsFields());
+        return paramsPanel;
+    }
+
+    protected Widget getGroupsFields() {
+        return new FlowPanel();
+    }
+
+    protected void endDialog() {
+        if (updateData()) {
+            setCurrentResult(group);
+            if (this.group.getPageName().equals("")) {
+                   ((Watch)app).addGroup(group, new AsyncCallback() {
+                       public void onFailure(Throwable throwable) {
+                           // There should already have been an error display
+                           ((Watch)app).refreshFeedTree();
+                       }
+       
+                       public void onSuccess(Object object) {
+                           endDialog2();
+                           ((Watch)app).refreshFeedTree();
+                       }
+                   });
+            } else {
+                endDialog2();
+            }
+        }
+    }
+
+    private void endDialog2() {
+        super.endDialog();
+    }
+
+}

Modified: 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/ui/menu/FeedTreeWidget.java
===================================================================
--- 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/ui/menu/FeedTreeWidget.java
   2008-02-15 22:20:07 UTC (rev 7768)
+++ 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/ui/menu/FeedTreeWidget.java
   2008-02-17 01:28:27 UTC (rev 7769)
@@ -1,6 +1,8 @@
 package com.xpn.xwiki.watch.client.ui.menu;
 
+import com.xpn.xwiki.watch.client.data.Group;
 import com.xpn.xwiki.watch.client.ui.WatchWidget;
+import com.xpn.xwiki.watch.client.ui.dialog.GroupDialog;
 import com.xpn.xwiki.watch.client.ui.dialog.FeedDialog;
 import com.xpn.xwiki.watch.client.ui.dialog.StandardFeedDialog;
 import com.xpn.xwiki.watch.client.Watch;
@@ -8,6 +10,7 @@
 import com.xpn.xwiki.watch.client.Constants;
 import com.xpn.xwiki.gwt.api.client.app.XWikiAsyncCallback;
 import com.xpn.xwiki.gwt.api.client.dialog.Dialog;
+import com.google.gwt.user.client.Window;
 import com.google.gwt.user.client.ui.*;
 import com.google.gwt.user.client.rpc.AsyncCallback;
 
@@ -110,14 +113,16 @@
         Iterator groupit = keys.iterator();
         while (groupit.hasNext()) {
             final String groupname = (String) groupit.next();
-            String groupTitle = (String) groups.get(groupname);
-            if (groupTitle==null)
-             groupTitle = groupname;
+            Group currentGroup = (Group) groups.get(groupname);
+            if (currentGroup == null) {
+                currentGroup = new Group();
+                currentGroup.setName(groupname);
+            }
             if ((groupname!=null)&&(!groupname.trim().equals(""))) {
-                Map group = (Map) feedsbygroup.get(groupname);
+                Map groupFeeds = (Map) feedsbygroup.get(groupname);
                 TreeItem groupItemTree = new TreeItem();
                 //set the TreeItem's object
-                GroupTreeItemObject groupObj = new 
GroupTreeItemObject(groupname, groupTitle);
+                GroupTreeItemObject groupObj = new 
GroupTreeItemObject(groupname, currentGroup);
                 groupItemTree.setUserObject(groupObj);
                 //check if selected
                 boolean selected = false;
@@ -127,12 +132,12 @@
                 }
                 groupItemTree.setWidget(groupObj.getWidget(selected));
                 groupTree.addItem(groupItemTree);
-                List feedList = new ArrayList(group.keySet());
+                List feedList = new ArrayList(groupFeeds.keySet());
                 Collections.sort(feedList);
                 Iterator feedgroupit = feedList.iterator();
                 while (feedgroupit.hasNext()) {
                     String feedname = (String) feedgroupit.next();
-                    Feed feed = (Feed) group.get(feedname);
+                    Feed feed = (Feed) groupFeeds.get(feedname);
                     //set it's userObject to the name of the group + name of 
the feed since a 
                     //feed can be part of multiple groups and we need to 
identify it uniquely.
                     String itemTreeKey = groupname + "." + feedname;
@@ -195,31 +200,85 @@
             super(key, data);
         }
 
-        public GroupTreeItemObject(String groupname, String groupTitle)
-        {
-            super(groupname, null);
-            //can only instantiate groupdata obj from class.
-            //TODO: declare it static or not inner once all the data classes 
are moved.
-            this.data = new String[2];
-            ((String[])this.data)[0] = groupname;
-            ((String[])this.data)[1] = groupTitle;
-        }
-
         public Widget getWidget(boolean selected)
         {
-            final String[] gData = (String[])this.data;
-            Hyperlink link = new Hyperlink(gData[1], "");
+            final Group group = (Group)this.data;
+            Hyperlink link = new Hyperlink(group.getName(), "");
             link.setStyleName(watch.getStyleName("feedtree","link"));
             link.addClickListener(new ClickListener() {
                 public void onClick(Widget widget) {
-                    watch.refreshOnGroupChange(gData[0]);
+                    
watch.refreshOnGroupChange(group.getPageName().trim().equals("") 
+                                               ? group.getName() : 
group.getPageName());
                 }
             });            
             Widget widget = link;
-            if (selected) {
+            //if group is All group or it is a non-existent group, we 
shouldn't be able to edit it
+            if (selected && 
(!group.getName().equals(watch.getTranslation("all")))
+                && !group.getPageName().equals("")) {
                 //create a composite with link as main widget and some actions
                 widget = new HyperlinkComposite(link);
-                //no actions for now
+                Hyperlink editHyperlink = new 
Hyperlink(watch.getTranslation("feedtree.edit"), "#");
+                editHyperlink.addClickListener(new ClickListener() {
+                    public void onClick (Widget widget) {
+                        GroupDialog gDialog = new GroupDialog(watch, 
"addgroup", 
+                            Dialog.BUTTON_CANCEL | Dialog.BUTTON_NEXT, group);
+                        gDialog.setAsyncCallback(new AsyncCallback() {
+                            public void onFailure(Throwable throwable) {
+                                //nothing
+                            }
+                            public void onSuccess(Object object) {
+                                Group newGroup = (Group)object;
+                                watch.getDataManager().updateGroup(newGroup, 
new XWikiAsyncCallback(watch) {
+                                    public void onFailure(Throwable caught) {
+                                        super.onFailure(caught);
+                                    }
+    
+                                    public void onSuccess(Object result) {
+                                        super.onSuccess(result);
+                                        // We need to refreshData the tree
+                                        watch.refreshOnNewGroup();
+                                        watch.refreshOnNewKeyword();
+                                    }
+                                });
+                            }
+                        });
+                        gDialog.show();
+                    }
+                });
+                HyperlinkComposite editHyperlinkComposite = new 
HyperlinkComposite(editHyperlink);
+                Hyperlink deleteHyperlink = new 
Hyperlink(watch.getTranslation("feedtree.delete"), "");
+                deleteHyperlink.addClickListener(new ClickListener() {
+                   public void onClick(Widget widget) {
+                       String confirmString = 
watch.getTranslation("removegroup.confirm", 
+                                                                   new 
String[] {group.getName()});
+                       boolean confirm = Window.confirm(confirmString);
+                       if (confirm) {
+                           watch.getDataManager().removeGroup(group, new 
XWikiAsyncCallback(watch) {
+                               public void onFailure(Throwable caught) {
+                                   super.onFailure(caught);
+                               }
+                               public void onSuccess(Object result) {
+                                   super.onSuccess(result);
+                                   // We need to refreshData the tree
+                                   watch.refreshOnNewGroup();
+                                   watch.refreshOnNewKeyword();
+                               }
+                           });
+                       } else {
+                           //nothing
+                       }
+                   } 
+                });
+                HyperlinkComposite deleteHyperlinkComposite = new 
HyperlinkComposite(deleteHyperlink);
+                //set styles
+                
editHyperlinkComposite.setStyleName(watch.getStyleName("feedtree", 
"groupaction") 
+                    + " " + watch.getStyleName("feedtree", "editgroup"));
+                
deleteHyperlinkComposite.setStyleName(watch.getStyleName("feedtree", 
"groupaction") 
+                    + " " + watch.getStyleName("feedtree", "deletegroup"));
+                //add the two actions to the hyperlink composite, in reverse 
order since they will
+                //be floated to the right
+                ((HyperlinkComposite)widget).add(deleteHyperlinkComposite);
+                ((HyperlinkComposite)widget).add(editHyperlinkComposite);
             }
             return widget;
         }
@@ -290,7 +349,7 @@
                    public void onClick(Widget widget) {
                        String confirmString = 
watch.getTranslation("removefeed.confirm", 
                                                                    new 
String[] {feed.getName()});
-                       boolean confirm = 
com.google.gwt.user.client.Window.confirm(confirmString);
+                       boolean confirm = Window.confirm(confirmString);
                        if (confirm) {
                            watch.getDataManager().removeFeed(feed, new 
XWikiAsyncCallback(watch) {
                                public void onFailure(Throwable caught) {

Modified: 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/ui/menu/KeywordsWidget.java
===================================================================
--- 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/ui/menu/KeywordsWidget.java
   2008-02-15 22:20:07 UTC (rev 7768)
+++ 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/ui/menu/KeywordsWidget.java
   2008-02-17 01:28:27 UTC (rev 7769)
@@ -2,6 +2,7 @@
 
 import com.xpn.xwiki.watch.client.ui.WatchWidget;
 import com.xpn.xwiki.watch.client.Watch;
+import com.xpn.xwiki.watch.client.data.Group;
 import com.xpn.xwiki.watch.client.data.Keyword;
 import com.google.gwt.user.client.ui.*;
 
@@ -86,10 +87,13 @@
             while (it.hasNext()) {
                 final Keyword keyword = (Keyword) it.next();
                 if ((keyword.getName()!=null)&&(!keyword.equals(""))) {
-                    String groupDisplayName = (String) 
watch.getConfig().getGroups()
+                    Group kwGroup = (Group) watch.getConfig().getGroups()
                                                        
.get(keyword.getGroup());
-                    if (groupDisplayName == null) {
+                    String groupDisplayName;
+                    if (kwGroup == null) {
                         groupDisplayName = keyword.getGroup();
+                    } else {
+                        groupDisplayName = kwGroup.getName();
                     }
                     String keywordDisplayName = keyword.getName() 
                         + ((!groupDisplayName.trim().equals("")) ?  (" - " + 
groupDisplayName) : "");

Modified: 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/ui/wizard/ConfigWizard.java
===================================================================
--- 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/ui/wizard/ConfigWizard.java
   2008-02-15 22:20:07 UTC (rev 7768)
+++ 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/client/ui/wizard/ConfigWizard.java
   2008-02-17 01:28:27 UTC (rev 7769)
@@ -2,6 +2,7 @@
 
 import com.xpn.xwiki.watch.client.Watch;
 import com.xpn.xwiki.watch.client.Feed;
+import com.xpn.xwiki.watch.client.data.Group;
 import com.xpn.xwiki.watch.client.ui.dialog.*;
 import com.xpn.xwiki.gwt.api.client.wizard.Wizard;
 import com.xpn.xwiki.gwt.api.client.dialog.ChoiceDialog;
@@ -66,7 +67,7 @@
         AddKeywordDialog addKeywordDialog = new AddKeywordDialog(watch, 
"addkeyword", Dialog.BUTTON_PREVIOUS | Dialog.BUTTON_CANCEL | 
Dialog.BUTTON_NEXT, "", "");
         addDialog(addKeywordDialog, "end");
 
-        AddGroupDialog addGroupDialog = new AddGroupDialog(watch, "addgroup", 
Dialog.BUTTON_PREVIOUS | Dialog.BUTTON_CANCEL | Dialog.BUTTON_NEXT, "");
+        GroupDialog addGroupDialog = new GroupDialog(watch, "addgroup", 
Dialog.BUTTON_PREVIOUS | Dialog.BUTTON_CANCEL | Dialog.BUTTON_NEXT, new 
Group());
         addDialog(addGroupDialog, "end");
 
         LoadingStatusDialog loadingStatusDialog = new 
LoadingStatusDialog(watch, "loadingstatus", Dialog.BUTTON_CANCEL);

Modified: 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/public/Watch.css
===================================================================
--- 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/public/Watch.css
     2008-02-15 22:20:07 UTC (rev 7768)
+++ 
xwiki-products/xwiki-watch/trunk/gwt/src/main/java/com/xpn/xwiki/watch/public/Watch.css
     2008-02-17 01:28:27 UTC (rev 7769)
@@ -219,17 +219,17 @@
        white-space: normal;
 }
 
-.watch-feedtree-feedaction {
+.watch-feedtree-feedaction, .watch-feedtree-groupaction {
        float: right;
        padding-left: 0.5em;
        padding-right: 0.5em;
 }
 
-div.watch-feedtree-editfeed {
+div.watch-feedtree-editfeed, div.watch-feedtree-editgroup{
        background-color: #FFAA00;
 }
 
-div.watch-feedtree-deletefeed {
+div.watch-feedtree-deletefeed, div.watch-feedtree-deletegroup{
        background-color: #FF0000;
 }
 

Modified: 
xwiki-products/xwiki-watch/trunk/wikis/watch/src/main/resources/WatchCode/Translations
===================================================================
--- 
xwiki-products/xwiki-watch/trunk/wikis/watch/src/main/resources/WatchCode/Translations
      2008-02-15 22:20:07 UTC (rev 7768)
+++ 
xwiki-products/xwiki-watch/trunk/wikis/watch/src/main/resources/WatchCode/Translations
      2008-02-17 01:28:27 UTC (rev 7769)
@@ -138,6 +138,7 @@
 watch.addfeed.button.wikio.description=Create and add a Feed from Wikio
 
 watch.removefeed.confirm=Are you sure you want to delete feed "{0}"?
+watch.removegroup.confirm=Are you sure you want to delete group "{0}"?
 
 watch.addgroup.invitation=Please add a group below
 watch.addgroup.group=Group Name

Modified: 
xwiki-products/xwiki-watch/trunk/wikis/watch/src/main/resources/WatchCode/Translations.fr
===================================================================
--- 
xwiki-products/xwiki-watch/trunk/wikis/watch/src/main/resources/WatchCode/Translations.fr
   2008-02-15 22:20:07 UTC (rev 7768)
+++ 
xwiki-products/xwiki-watch/trunk/wikis/watch/src/main/resources/WatchCode/Translations.fr
   2008-02-17 01:28:27 UTC (rev 7769)
@@ -126,6 +126,7 @@
 watch.addfeed.button.wikio.description=Cr�ez et ajoutez un flux depuis Wikio
 
 watch.removefeed.confirm=�tes-vous s�r de vouloir effacer le flux "{0}"?
+watch.removegroup.confirm=�tes-vous s�r de vouloir effacer le group "{0}"?
 
 watch.addgroup.invitation=Veuillez ajouter le nom du groupe ci dessous
 watch.addgroup.group=Noms du groupe:

Modified: 
xwiki-products/xwiki-watch/trunk/wikis/watch/src/main/resources/WatchSheets/GroupSheet
===================================================================
--- 
xwiki-products/xwiki-watch/trunk/wikis/watch/src/main/resources/WatchSheets/GroupSheet
      2008-02-15 22:20:07 UTC (rev 7768)
+++ 
xwiki-products/xwiki-watch/trunk/wikis/watch/src/main/resources/WatchSheets/GroupSheet
      2008-02-17 01:28:27 UTC (rev 7769)
@@ -57,7 +57,7 @@
 #set($groupObj = $doc.getObject("XWiki.AggregatorGroupClass"))
 #if ($groupObj)
   ## for a reason or another, a feed holds in its group value, the name of a 
group document and not a group name, so the query is very simple:
-  #set($feedsQuery =" , BaseObject as obj, XWiki.AggregatorURLClass as feed 
where doc.fullName = obj.name and doc.web = '${doc.space}' and obj.id = feed.id 
and obj.className = 'XWiki.AggregatorUrlClass' and '${groupObj.name}' in 
elements(feed.group)")
+  #set($feedsQuery =" , BaseObject as obj, XWiki.AggregatorURLClass as feed 
where doc.fullName = obj.name and doc.web = '${doc.space}' and obj.id = feed.id 
and obj.className = 'XWiki.AggregatorURLClass' and '${groupObj.name}' in 
elements(feed.group)")
   #set($list = $xwiki.searchDocuments($feedsQuery))
   #set($parList = $xwiki.arrayList)
   #set($dispose = $parList.add($groupObj.getProperty("name").value))

_______________________________________________
notifications mailing list
notifications@xwiki.org
http://lists.xwiki.org/mailman/listinfo/notifications

Reply via email to