[kune-commits] r1330 - in trunk/src/main/java/cc/kune/gspace/client: . viewers

Vicente J. Ruiz Jurado vjrj_ at ourproject.org
Fri Apr 29 14:57:28 CEST 2011


Author: vjrj_
Date: 2011-04-29 14:57:28 +0200 (Fri, 29 Apr 2011)
New Revision: 1330

Added:
   trunk/src/main/java/cc/kune/gspace/client/viewers/ContentTitleWidget.java
Modified:
   trunk/src/main/java/cc/kune/gspace/client/GSpaceGinModule.java
   trunk/src/main/java/cc/kune/gspace/client/viewers/AbstractFolderViewerPanel.java
   trunk/src/main/java/cc/kune/gspace/client/viewers/DocViewerPanel.java
   trunk/src/main/java/cc/kune/gspace/client/viewers/FolderViewerAsTablePanel.java
   trunk/src/main/java/cc/kune/gspace/client/viewers/FolderViewerPresenter.java
Log:


Modified: trunk/src/main/java/cc/kune/gspace/client/GSpaceGinModule.java
===================================================================
--- trunk/src/main/java/cc/kune/gspace/client/GSpaceGinModule.java	2011-04-29 12:02:17 UTC (rev 1329)
+++ trunk/src/main/java/cc/kune/gspace/client/GSpaceGinModule.java	2011-04-29 12:57:28 UTC (rev 1330)
@@ -20,6 +20,7 @@
 package cc.kune.gspace.client;
 
 import cc.kune.client.ExtendedGinModule;
+import cc.kune.gspace.client.actions.RenameAction;
 import cc.kune.gspace.client.options.GroupOptions;
 import cc.kune.gspace.client.options.GroupOptionsCollection;
 import cc.kune.gspace.client.options.GroupOptionsPanel;
@@ -80,54 +81,56 @@
 
 public class GSpaceGinModule extends ExtendedGinModule {
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see com.google.gwt.inject.client.AbstractGinModule#configure()
-     */
-    @Override
-    protected void configure() {
-        bindPresenter(EntityLicensePresenter.class, EntityLicensePresenter.EntityLicenseView.class,
-                EntityLicensePanel.class, EntityLicensePresenter.EntityLicenseProxy.class);
-        bindPresenter(TagsSummaryPresenter.class, TagsSummaryPresenter.TagsSummaryView.class, TagsSummaryPanel.class,
-                TagsSummaryPresenter.TagsSummaryProxy.class);
-        bind(GSpaceArmorImpl.class).in(Singleton.class);
-        bind(GSpaceArmor.class).to(GSpaceArmorImpl.class).in(Singleton.class);
-        bind(GSpaceParts.class).asEagerSingleton();
-        bindPresenter(ToolSelectorPresenter.class, ToolSelectorPresenter.ToolSelectorView.class,
-                ToolSelectorPanel.class, ToolSelectorPresenter.ToolSelectorProxy.class);
-        bind(ToolSelector.class).to(ToolSelectorPresenter.class).in(Singleton.class);
-        bindPresenter(DocViewerPresenter.class, DocViewerPresenter.DocViewerView.class, DocViewerPanel.class,
-                DocViewerPresenter.DocViewerProxy.class);
-        bindPresenter(FolderViewerPresenter.class, FolderViewerPresenter.FolderViewerView.class,
-                FolderViewerAsTablePanel.class, FolderViewerPresenter.FolderViewerProxy.class);
+  /*
+   * (non-Javadoc)
+   * 
+   * @see com.google.gwt.inject.client.AbstractGinModule#configure()
+   */
+  @Override
+  protected void configure() {
+    bindPresenter(EntityLicensePresenter.class, EntityLicensePresenter.EntityLicenseView.class,
+        EntityLicensePanel.class, EntityLicensePresenter.EntityLicenseProxy.class);
+    bindPresenter(TagsSummaryPresenter.class, TagsSummaryPresenter.TagsSummaryView.class,
+        TagsSummaryPanel.class, TagsSummaryPresenter.TagsSummaryProxy.class);
+    bind(GSpaceArmorImpl.class).in(Singleton.class);
+    bind(GSpaceArmor.class).to(GSpaceArmorImpl.class).in(Singleton.class);
+    bind(GSpaceParts.class).asEagerSingleton();
+    bindPresenter(ToolSelectorPresenter.class, ToolSelectorPresenter.ToolSelectorView.class,
+        ToolSelectorPanel.class, ToolSelectorPresenter.ToolSelectorProxy.class);
+    bind(ToolSelector.class).to(ToolSelectorPresenter.class).in(Singleton.class);
+    bindPresenter(DocViewerPresenter.class, DocViewerPresenter.DocViewerView.class,
+        DocViewerPanel.class, DocViewerPresenter.DocViewerProxy.class);
+    bindPresenter(FolderViewerPresenter.class, FolderViewerPresenter.FolderViewerView.class,
+        FolderViewerAsTablePanel.class, FolderViewerPresenter.FolderViewerProxy.class);
 
-        s(GroupOptions.class, GroupOptionsPresenter.class);
-        s(GroupOptionsView.class, GroupOptionsPanel.class);
-        s(UserOptions.class, UserOptionsPresenter.class);
-        s(UserOptionsView.class, UserOptionsPanel.class);
+    s(GroupOptions.class, GroupOptionsPresenter.class);
+    s(GroupOptionsView.class, GroupOptionsPanel.class);
+    s(UserOptions.class, UserOptionsPresenter.class);
+    s(UserOptionsView.class, UserOptionsPanel.class);
 
-        s(UserOptionsCollection.class);
-        s(GroupOptionsCollection.class);
+    s(UserOptionsCollection.class);
+    s(GroupOptionsCollection.class);
 
-        s(GroupOptionsDefLicense.class, GroupOptionsDefLicensePresenter.class);
-        s(GroupOptionsDefLicenseView.class, GroupOptionsDefLicensePanel.class);
-        s(GroupOptionsPublicSpaceConf.class, GroupOptionsPublicSpaceConfPresenter.class);
-        s(GroupOptionsPublicSpaceConfView.class, GroupOptionsPublicSpaceConfPanel.class);
-        s(GroupOptionsLogo.class, GroupOptionsLogoPresenter.class);
-        s(GroupOptionsLogoView.class, GroupOptionsLogoPanel.class);
-        s(GroupOptionsToolsConf.class, GroupOptionsToolsConfPresenter.class);
-        s(GroupOptionsToolsConfView.class, GroupOptionsToolsConfPanel.class);
+    s(GroupOptionsDefLicense.class, GroupOptionsDefLicensePresenter.class);
+    s(GroupOptionsDefLicenseView.class, GroupOptionsDefLicensePanel.class);
+    s(GroupOptionsPublicSpaceConf.class, GroupOptionsPublicSpaceConfPresenter.class);
+    s(GroupOptionsPublicSpaceConfView.class, GroupOptionsPublicSpaceConfPanel.class);
+    s(GroupOptionsLogo.class, GroupOptionsLogoPresenter.class);
+    s(GroupOptionsLogoView.class, GroupOptionsLogoPanel.class);
+    s(GroupOptionsToolsConf.class, GroupOptionsToolsConfPresenter.class);
+    s(GroupOptionsToolsConfView.class, GroupOptionsToolsConfPanel.class);
 
-        s(UserOptionsDefLicense.class, UserOptionsDefLicensePresenter.class);
-        s(UserOptionsDefLicenseView.class, UserOptionsDefLicensePanel.class);
-        s(UserOptionsPublicSpaceConf.class, UserOptionsPublicSpaceConfPresenter.class);
-        s(UserOptionsPublicSpaceConfView.class, UserOptionsPublicSpaceConfPanel.class);
-        s(UserOptionsLogo.class, UserOptionsLogoPresenter.class);
-        s(UserOptionsLogoView.class, UserOptionsLogoPanel.class);
-        s(UserOptionsToolsConf.class, UserOptionsToolsConfPresenter.class);
-        s(UserOptionsToolsConfView.class, UserOptionsToolsConfPanel.class);
+    s(UserOptionsDefLicense.class, UserOptionsDefLicensePresenter.class);
+    s(UserOptionsDefLicenseView.class, UserOptionsDefLicensePanel.class);
+    s(UserOptionsPublicSpaceConf.class, UserOptionsPublicSpaceConfPresenter.class);
+    s(UserOptionsPublicSpaceConfView.class, UserOptionsPublicSpaceConfPanel.class);
+    s(UserOptionsLogo.class, UserOptionsLogoPresenter.class);
+    s(UserOptionsLogoView.class, UserOptionsLogoPanel.class);
+    s(UserOptionsToolsConf.class, UserOptionsToolsConfPresenter.class);
+    s(UserOptionsToolsConfView.class, UserOptionsToolsConfPanel.class);
 
-        s(GSpaceBackManager.class, GSpaceBackManagerImpl.class);
-    }
+    s(GSpaceBackManager.class, GSpaceBackManagerImpl.class);
+
+    s(RenameAction.class);
+  }
 }
\ No newline at end of file

Modified: trunk/src/main/java/cc/kune/gspace/client/viewers/AbstractFolderViewerPanel.java
===================================================================
--- trunk/src/main/java/cc/kune/gspace/client/viewers/AbstractFolderViewerPanel.java	2011-04-29 12:02:17 UTC (rev 1329)
+++ trunk/src/main/java/cc/kune/gspace/client/viewers/AbstractFolderViewerPanel.java	2011-04-29 12:57:28 UTC (rev 1330)
@@ -1,35 +1,33 @@
 package cc.kune.gspace.client.viewers;
 
 import cc.kune.common.client.actions.ui.descrip.GuiActionDescCollection;
-import cc.kune.common.client.ui.IconLabel;
+import cc.kune.common.client.ui.HasEditHandler;
 import cc.kune.common.client.ui.UiUtils;
 import cc.kune.core.client.registry.ContentCapabilitiesRegistry;
-import cc.kune.core.client.registry.IconsRegistry;
 import cc.kune.core.shared.dto.StateContainerDTO;
 import cc.kune.core.shared.i18n.I18nTranslationService;
 import cc.kune.gspace.client.GSpaceArmor;
 import cc.kune.gspace.client.viewers.FolderViewerPresenter.FolderViewerView;
 
-import com.google.gwt.resources.client.ImageResource;
 import com.google.gwt.user.client.ui.InlineLabel;
 import com.google.gwt.user.client.ui.InsertPanel.ForIsWidget;
 import com.google.gwt.user.client.ui.Widget;
 import com.gwtplatform.mvp.client.ViewImpl;
 
 public abstract class AbstractFolderViewerPanel extends ViewImpl implements FolderViewerView {
+  private final ContentTitleWidget contentTitle;
   private final InlineLabel emptyLabel;
   protected final GSpaceArmor gsArmor;
   protected final I18nTranslationService i18n;
-  private final IconsRegistry iconRegistry;
   protected Widget widget;
 
   public AbstractFolderViewerPanel(final GSpaceArmor gsArmor, final I18nTranslationService i18n,
       final ContentCapabilitiesRegistry capabilitiesRegistry) {
     this.gsArmor = gsArmor;
     this.i18n = i18n;
-    this.iconRegistry = capabilitiesRegistry.getIconsRegistry();
     emptyLabel = new InlineLabel(i18n.t("This folder is empty."));
     emptyLabel.setStyleName("k-empty-msg");
+    contentTitle = new ContentTitleWidget(i18n, gsArmor, capabilitiesRegistry.getIconsRegistry());
   }
 
   @Override
@@ -56,6 +54,11 @@
   }
 
   @Override
+  public HasEditHandler getEditTitle() {
+    return contentTitle.getEditableTitle();
+  }
+
+  @Override
   public void setActions(final GuiActionDescCollection actions) {
     gsArmor.getSubheaderToolbar().clear();
     gsArmor.getSubheaderToolbar().addAll(actions);
@@ -63,14 +66,15 @@
 
   @Override
   public void setContainer(final StateContainerDTO state) {
-    // gsArmor.getDocHeader().add(new InlineLabel(state.getTitle()));
-    final IconLabel label = new IconLabel(
-        (ImageResource) iconRegistry.getContentTypeIcon(state.getTypeId()), state.getTitle());
-    label.setStyleName("k-fl");
-    gsArmor.getDocHeader().add(label);
+    contentTitle.setTitle(state.getTitle(), state.getTypeId(), state.getContainerRights().isEditable());
   }
 
   @Override
+  public void setEditableTitle(final String title) {
+    contentTitle.setText(title);
+  }
+
+  @Override
   public void showEmptyMsg() {
     gsArmor.getDocContainer().add(emptyLabel);
   }

Added: trunk/src/main/java/cc/kune/gspace/client/viewers/ContentTitleWidget.java
===================================================================
--- trunk/src/main/java/cc/kune/gspace/client/viewers/ContentTitleWidget.java	                        (rev 0)
+++ trunk/src/main/java/cc/kune/gspace/client/viewers/ContentTitleWidget.java	2011-04-29 12:57:28 UTC (rev 1330)
@@ -0,0 +1,65 @@
+package cc.kune.gspace.client.viewers;
+
+import cc.kune.common.client.ui.EditableLabel;
+import cc.kune.common.client.ui.HasEditHandler;
+import cc.kune.common.client.ui.UiUtils;
+import cc.kune.core.client.registry.IconsRegistry;
+import cc.kune.core.shared.dto.BasicMimeTypeDTO;
+import cc.kune.core.shared.i18n.I18nTranslationService;
+import cc.kune.gspace.client.GSpaceArmor;
+
+import com.google.gwt.resources.client.ImageResource;
+import com.google.gwt.user.client.ui.Composite;
+import com.google.gwt.user.client.ui.FlowPanel;
+import com.google.gwt.user.client.ui.Image;
+import com.google.gwt.user.client.ui.InsertPanel.ForIsWidget;
+
+public class ContentTitleWidget extends Composite {
+  private final EditableLabel editableTitle;
+  private final GSpaceArmor gsArmor;
+  private final IconsRegistry iconRegistry;
+  private final Image titleIcon;
+
+  public ContentTitleWidget(final I18nTranslationService i18n, final GSpaceArmor gsArmor,
+      final IconsRegistry iconRegistry) {
+    this.gsArmor = gsArmor;
+    this.iconRegistry = iconRegistry;
+    final FlowPanel flow = new FlowPanel();
+    titleIcon = new Image();
+    editableTitle = new EditableLabel();
+    editableTitle.setTooltip(i18n.t("Click to edit"));
+    flow.add(titleIcon);
+    flow.add(editableTitle);
+    initWidget(flow);
+  }
+
+  public HasEditHandler getEditableTitle() {
+    return editableTitle;
+  }
+
+  public void setText(final String text) {
+    editableTitle.setText(text);
+  }
+
+  public void setTitle(final String title, final String typeId, final BasicMimeTypeDTO mime,
+      final boolean editable) {
+    final ForIsWidget docHeader = gsArmor.getDocHeader();
+    UiUtils.clear(docHeader);
+
+    final ImageResource resource = (mime == null ? (ImageResource) iconRegistry.getContentTypeIcon(typeId)
+        : (ImageResource) iconRegistry.getContentTypeIcon(typeId, mime));
+    final boolean hasIcon = resource != null;
+    if (hasIcon) {
+      titleIcon.setResource(resource);
+    }
+    titleIcon.setVisible(hasIcon);
+    editableTitle.setText(title);
+    editableTitle.setEditable(editable);
+    docHeader.add(this);
+  }
+
+  public void setTitle(final String title, final String typeId, final boolean editable) {
+    setTitle(title, typeId, null, editable);
+  }
+
+}


Property changes on: trunk/src/main/java/cc/kune/gspace/client/viewers/ContentTitleWidget.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/src/main/java/cc/kune/gspace/client/viewers/DocViewerPanel.java
===================================================================
--- trunk/src/main/java/cc/kune/gspace/client/viewers/DocViewerPanel.java	2011-04-29 12:02:17 UTC (rev 1329)
+++ trunk/src/main/java/cc/kune/gspace/client/viewers/DocViewerPanel.java	2011-04-29 12:57:28 UTC (rev 1330)
@@ -20,11 +20,9 @@
 
 import cc.kune.common.client.actions.ui.descrip.GuiActionDescCollection;
 import cc.kune.common.client.errors.UIException;
-import cc.kune.common.client.ui.EditableLabel;
 import cc.kune.common.client.ui.HasEditHandler;
 import cc.kune.common.client.ui.UiUtils;
 import cc.kune.core.client.registry.ContentCapabilitiesRegistry;
-import cc.kune.core.client.registry.IconsRegistry;
 import cc.kune.core.shared.dto.StateContentDTO;
 import cc.kune.core.shared.i18n.I18nTranslationService;
 import cc.kune.gspace.client.GSpaceArmor;
@@ -34,14 +32,11 @@
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.dom.client.Document;
 import com.google.gwt.dom.client.Element;
-import com.google.gwt.resources.client.ImageResource;
 import com.google.gwt.safehtml.shared.SafeHtmlUtils;
 import com.google.gwt.uibinder.client.UiBinder;
 import com.google.gwt.uibinder.client.UiField;
 import com.google.gwt.user.client.Command;
 import com.google.gwt.user.client.ui.DeckPanel;
-import com.google.gwt.user.client.ui.FlowPanel;
-import com.google.gwt.user.client.ui.Image;
 import com.google.gwt.user.client.ui.InlineHTML;
 import com.google.gwt.user.client.ui.InsertPanel.ForIsWidget;
 import com.google.gwt.user.client.ui.Widget;
@@ -55,18 +50,15 @@
   private static DocsViewerPanelUiBinder uiBinder = GWT.create(DocsViewerPanelUiBinder.class);
 
   private RemoteViewServiceMultiplexer channel;
+  private final ContentTitleWidget contentTitle;
   @UiField
   DeckPanel deck;
-  private final EditableLabel editableTitle;
   private final GSpaceArmor gsArmor;
-  private final IconsRegistry iconRegistry;
   private IdGenerator idGenerator;
   private final Element loading = new LoadingIndicator().getElement();
   @UiField
   InlineHTML onlyViewPanel;
   private ProfileManager profiles;
-  private final FlowPanel title;
-  private final Image titleIcon;
   /** The wave panel, if a wave is open. */
   private StagesProvider wave;
   @UiField
@@ -80,14 +72,8 @@
   public DocViewerPanel(final GSpaceArmor wsArmor,
       final ContentCapabilitiesRegistry capabilitiesRegistry, final I18nTranslationService i18n) {
     this.gsArmor = wsArmor;
-    this.iconRegistry = capabilitiesRegistry.getIconsRegistry();
     widget = uiBinder.createAndBindUi(this);
-    title = new FlowPanel();
-    titleIcon = new Image();
-    editableTitle = new EditableLabel();
-    editableTitle.setTooltip(i18n.t("Click to edit"));
-    title.add(titleIcon);
-    title.add(editableTitle);
+    contentTitle = new ContentTitleWidget(i18n, gsArmor, capabilitiesRegistry.getIconsRegistry());
   }
 
   @Override
@@ -116,7 +102,7 @@
 
   @Override
   public HasEditHandler getEditTitle() {
-    return editableTitle;
+    return contentTitle.getEditableTitle();
   }
 
   private WaveRef getWaveRef(final String waveRefS) {
@@ -148,7 +134,7 @@
   @Override
   public void setContent(final StateContentDTO state) {
     final boolean editable = state.getContentRights().isEditable();
-    setTitle(state, editable);
+    contentTitle.setTitle(state.getTitle(), state.getTypeId(), state.getMimeType(), editable);
     if (editable) {
       initWaveClientIfNeeded();
       setEditableWaveContent(state.getWaveRef(), false);
@@ -165,7 +151,7 @@
 
   @Override
   public void setEditableTitle(final String title) {
-    editableTitle.setText(title);
+    contentTitle.setText(title);
   }
 
   private void setEditableWaveContent(final String waveRefS, final boolean isNewWave) {
@@ -191,18 +177,4 @@
     });
   }
 
-  private void setTitle(final StateContentDTO state, final boolean editable) {
-    final ForIsWidget docHeader = gsArmor.getDocHeader();
-    UiUtils.clear(docHeader);
-    final ImageResource resource = (ImageResource) iconRegistry.getContentTypeIcon(state.getTypeId(),
-        state.getMimeType());
-    final boolean hasIcon = resource != null;
-    if (hasIcon) {
-      titleIcon.setResource(resource);
-    }
-    titleIcon.setVisible(hasIcon);
-    editableTitle.setText(state.getTitle());
-    editableTitle.setEditable(editable);
-    docHeader.add(title);
-  }
 }

Modified: trunk/src/main/java/cc/kune/gspace/client/viewers/FolderViewerAsTablePanel.java
===================================================================
--- trunk/src/main/java/cc/kune/gspace/client/viewers/FolderViewerAsTablePanel.java	2011-04-29 12:02:17 UTC (rev 1329)
+++ trunk/src/main/java/cc/kune/gspace/client/viewers/FolderViewerAsTablePanel.java	2011-04-29 12:57:28 UTC (rev 1330)
@@ -98,7 +98,7 @@
 
   @Override
   public void clear() {
-    flex.clear();
+    flex.removeAllRows();
     super.clear();
   }
 

Modified: trunk/src/main/java/cc/kune/gspace/client/viewers/FolderViewerPresenter.java
===================================================================
--- trunk/src/main/java/cc/kune/gspace/client/viewers/FolderViewerPresenter.java	2011-04-29 12:02:17 UTC (rev 1329)
+++ trunk/src/main/java/cc/kune/gspace/client/viewers/FolderViewerPresenter.java	2011-04-29 12:57:28 UTC (rev 1330)
@@ -4,6 +4,9 @@
 
 import cc.kune.blogs.shared.BlogsConstants;
 import cc.kune.common.client.actions.ui.descrip.GuiActionDescCollection;
+import cc.kune.common.client.ui.EditEvent;
+import cc.kune.common.client.ui.EditEvent.EditHandler;
+import cc.kune.common.client.ui.HasEditHandler;
 import cc.kune.core.client.actions.ActionRegistryByType;
 import cc.kune.core.client.registry.ContentCapabilitiesRegistry;
 import cc.kune.core.client.registry.IconsRegistry;
@@ -23,6 +26,8 @@
 import cc.kune.core.shared.i18n.I18nTranslationService;
 import cc.kune.docs.shared.DocsConstants;
 import cc.kune.gspace.client.actions.ActionGroups;
+import cc.kune.gspace.client.actions.RenameAction;
+import cc.kune.gspace.client.actions.RenameListener;
 import cc.kune.gspace.client.tool.ContentViewer;
 import cc.kune.gspace.client.tool.ContentViewerSelector;
 
@@ -31,6 +36,7 @@
 import com.google.gwt.event.dom.client.DoubleClickEvent;
 import com.google.gwt.event.dom.client.DoubleClickHandler;
 import com.google.gwt.event.shared.EventBus;
+import com.google.gwt.event.shared.HandlerRegistration;
 import com.google.inject.Inject;
 import com.google.inject.Provider;
 import com.gwtplatform.mvp.client.Presenter;
@@ -40,154 +46,192 @@
 import com.gwtplatform.mvp.client.proxy.RevealRootContentEvent;
 
 public class FolderViewerPresenter extends
-        Presenter<FolderViewerPresenter.FolderViewerView, FolderViewerPresenter.FolderViewerProxy> implements
-        ContentViewer {
+    Presenter<FolderViewerPresenter.FolderViewerView, FolderViewerPresenter.FolderViewerProxy> implements
+    ContentViewer {
 
-    @ProxyCodeSplit
-    public interface FolderViewerProxy extends Proxy<FolderViewerPresenter> {
-    }
+  @ProxyCodeSplit
+  public interface FolderViewerProxy extends Proxy<FolderViewerPresenter> {
+  }
 
-    public interface FolderViewerView extends View {
+  public interface FolderViewerView extends View {
 
-        void addItem(FolderItemDescriptor item, ClickHandler clickHandler, DoubleClickHandler doubleClickHandler);
+    void addItem(FolderItemDescriptor item, ClickHandler clickHandler,
+        DoubleClickHandler doubleClickHandler);
 
-        void attach();
+    void attach();
 
-        void clear();
+    void clear();
 
-        void detach();
+    void detach();
 
-        void setActions(GuiActionDescCollection actions);
+    HasEditHandler getEditTitle();
 
-        void setContainer(StateContainerDTO state);
+    void setActions(GuiActionDescCollection actions);
 
-        void showEmptyMsg();
-    }
+    void setContainer(StateContainerDTO state);
 
-    private final ActionRegistryByType actionsRegistry;
-    private final ContentCapabilitiesRegistry capabilitiesRegistry;
-    private final Provider<FileDownloadUtils> downloadUtilsProvider;
-    private final I18nTranslationService i18n;
-    private final IconsRegistry iconsRegistry;
-    private final Session session;
-    private final StateManager stateManager;
-    private final boolean useGenericImageIcon;
+    void setEditableTitle(String title);
 
-    @Inject
-    public FolderViewerPresenter(final EventBus eventBus, final FolderViewerView view, final FolderViewerProxy proxy,
-            final Session session, final StateManager stateManager, final I18nTranslationService i18n,
-            final ContentViewerSelector viewerSelector, final ActionRegistryByType actionsRegistry,
-            final Provider<FileDownloadUtils> downloadUtilsProvider,
-            final ContentCapabilitiesRegistry capabilitiesRegistry) {
-        super(eventBus, view, proxy);
-        this.session = session;
-        this.stateManager = stateManager;
-        this.i18n = i18n;
-        this.actionsRegistry = actionsRegistry;
-        this.downloadUtilsProvider = downloadUtilsProvider;
-        this.capabilitiesRegistry = capabilitiesRegistry;
-        iconsRegistry = capabilitiesRegistry.getIconsRegistry();
-        viewerSelector.register(this, true, DocsConstants.TYPE_ROOT, DocsConstants.TYPE_FOLDER);
-        viewerSelector.register(this, true, BlogsConstants.TYPE_ROOT, BlogsConstants.TYPE_BLOG);
-        useGenericImageIcon = false;
-    }
+    void showEmptyMsg();
+  }
 
-    private void addItem(final String title, final String contentTypeId, final BasicMimeTypeDTO mimeType,
-            final ContentStatus status, final StateToken stateToken, final StateToken parentStateToken,
-            final AccessRights rights) {
-        final Object icon = getIcon(stateToken, contentTypeId, mimeType);
-        final String tooltip = getTooltip(stateToken, mimeType);
-        final FolderItemDescriptor item = new FolderItemDescriptor(genId(stateToken), genId(parentStateToken), icon,
-                title, tooltip, status, stateToken, capabilitiesRegistry.isDragable(contentTypeId)
-                        && rights.isAdministrable(), capabilitiesRegistry.isDropable(contentTypeId)
-                        && rights.isAdministrable(), actionsRegistry.getCurrentActions(stateToken, contentTypeId,
-                        session.isLogged(), rights, ActionGroups.MENUITEM));
-        if (status.equals(ContentStatus.inTheDustbin) && !session.getShowDeletedContent()) {
-            // Don't show
-            // NotifyUser.info("Deleted, don't show");
-        } else {
-            getView().addItem(item, new ClickHandler() {
-                @Override
-                public void onClick(final ClickEvent event) {
-                    stateManager.gotoStateToken(stateToken);
-                }
-            }, new DoubleClickHandler() {
-                @Override
-                public void onDoubleClick(final DoubleClickEvent event) {
-                    stateManager.gotoStateToken(stateToken);
-                }
-            });
-        }
-    }
+  private final ActionRegistryByType actionsRegistry;
 
-    @Override
-    public void attach() {
-        getView().attach();
-    }
+  private final ContentCapabilitiesRegistry capabilitiesRegistry;
 
-    private void createChildItems(final ContainerDTO container, final AccessRights containerRights) {
-        if (container.getContents().size() + container.getChilds().size() == 0) {
-            getView().showEmptyMsg();
-        } else {
-            // Folders
-            for (final ContainerSimpleDTO childFolder : container.getChilds()) {
-                addItem(childFolder.getName(), childFolder.getTypeId(), null, ContentStatus.publishedOnline,
-                        childFolder.getStateToken(),
-                        childFolder.getStateToken().copy().setFolder(childFolder.getParentFolderId()), containerRights);
-            }
-            // Other contents (docs, etc)
-            for (final ContentSimpleDTO content : container.getContents()) {
-                addItem(content.getTitle(), content.getTypeId(), content.getMimeType(), content.getStatus(),
-                        content.getStateToken(), content.getStateToken().copy().clearDocument(), content.getRights());
-            }
+  private final Provider<FileDownloadUtils> downloadUtilsProvider;
+  private HandlerRegistration editHandler;
+  private final I18nTranslationService i18n;
+  private final IconsRegistry iconsRegistry;
+  private final Provider<RenameAction> renameAction;
+  private final Session session;
+  private final StateManager stateManager;
+  private final boolean useGenericImageIcon;
+
+  @Inject
+  public FolderViewerPresenter(final EventBus eventBus, final FolderViewerView view,
+      final FolderViewerProxy proxy, final Session session, final StateManager stateManager,
+      final I18nTranslationService i18n, final ContentViewerSelector viewerSelector,
+      final ActionRegistryByType actionsRegistry,
+      final Provider<FileDownloadUtils> downloadUtilsProvider,
+      final ContentCapabilitiesRegistry capabilitiesRegistry, final Provider<RenameAction> renameAction) {
+    super(eventBus, view, proxy);
+    this.session = session;
+    this.stateManager = stateManager;
+    this.i18n = i18n;
+    this.actionsRegistry = actionsRegistry;
+    this.downloadUtilsProvider = downloadUtilsProvider;
+    this.capabilitiesRegistry = capabilitiesRegistry;
+    iconsRegistry = capabilitiesRegistry.getIconsRegistry();
+    viewerSelector.register(this, true, DocsConstants.TYPE_ROOT, DocsConstants.TYPE_FOLDER);
+    viewerSelector.register(this, true, BlogsConstants.TYPE_ROOT, BlogsConstants.TYPE_BLOG);
+    useGenericImageIcon = false;
+    this.renameAction = renameAction;
+  }
+
+  private void addItem(final String title, final String contentTypeId, final BasicMimeTypeDTO mimeType,
+      final ContentStatus status, final StateToken stateToken, final StateToken parentStateToken,
+      final AccessRights rights) {
+    final Object icon = getIcon(stateToken, contentTypeId, mimeType);
+    final String tooltip = getTooltip(stateToken, mimeType);
+    final FolderItemDescriptor item = new FolderItemDescriptor(genId(stateToken),
+        genId(parentStateToken), icon, title, tooltip, status, stateToken,
+        capabilitiesRegistry.isDragable(contentTypeId) && rights.isAdministrable(),
+        capabilitiesRegistry.isDropable(contentTypeId) && rights.isAdministrable(),
+        actionsRegistry.getCurrentActions(stateToken, contentTypeId, session.isLogged(), rights,
+            ActionGroups.MENUITEM));
+    if (status.equals(ContentStatus.inTheDustbin) && !session.getShowDeletedContent()) {
+      // Don't show
+      // NotifyUser.info("Deleted, don't show");
+    } else {
+      getView().addItem(item, new ClickHandler() {
+        @Override
+        public void onClick(final ClickEvent event) {
+          stateManager.gotoStateToken(stateToken);
         }
+      }, new DoubleClickHandler() {
+        @Override
+        public void onDoubleClick(final DoubleClickEvent event) {
+          stateManager.gotoStateToken(stateToken);
+        }
+      });
     }
+  }
 
-    @Override
-    public void detach() {
-        getView().detach();
+  @Override
+  public void attach() {
+    getView().attach();
+    if (editHandler == null) {
+      createEditHandler();
     }
+  }
 
-    private String genId(final StateToken token) {
-        return "k-cnav-" + token.toString().replace(StateToken.SEPARATOR, "-");
+  private void createChildItems(final ContainerDTO container, final AccessRights containerRights) {
+    if (container.getContents().size() + container.getChilds().size() == 0) {
+      getView().showEmptyMsg();
+    } else {
+      // Folders
+      for (final ContainerSimpleDTO childFolder : container.getChilds()) {
+        addItem(childFolder.getName(), childFolder.getTypeId(), null, ContentStatus.publishedOnline,
+            childFolder.getStateToken(),
+            childFolder.getStateToken().copy().setFolder(childFolder.getParentFolderId()),
+            containerRights);
+      }
+      // Other contents (docs, etc)
+      for (final ContentSimpleDTO content : container.getContents()) {
+        addItem(content.getTitle(), content.getTypeId(), content.getMimeType(), content.getStatus(),
+            content.getStateToken(), content.getStateToken().copy().clearDocument(), content.getRights());
+      }
     }
+  }
 
-    private Object getIcon(final StateToken token, final String contentTypeId, final BasicMimeTypeDTO mimeType) {
-        if (!useGenericImageIcon && mimeType != null && mimeType.getType().equals("image")) {
-            return downloadUtilsProvider.get().getImageResizedUrl(token, ImageSize.ico);
-        } else {
-            return iconsRegistry.getContentTypeIcon(contentTypeId, mimeType);
-        }
-    }
+  private void createEditHandler() {
+    // Duplicate in DocViewerPresenter
+    editHandler = getView().getEditTitle().addEditHandler(new EditHandler() {
+      @Override
+      public void fire(final EditEvent event) {
+        renameAction.get().rename(session.getCurrentStateToken(), session.getCurrentState().getTitle(),
+            event.getText(), new RenameListener() {
+              @Override
+              public void onFail(final StateToken token, final String oldTitle) {
+                getView().setEditableTitle(oldTitle);
+              }
 
-    private String getTooltip(final StateToken token, final BasicMimeTypeDTO mimeType) {
-        if (mimeType != null && (mimeType.isImage() || mimeType.isPdf())) {
-            // Used for previews
-            return null;
-        } else {
-            return i18n.t("Double click to open");
-        }
-    }
+              @Override
+              public void onSuccess(final StateToken token, final String title) {
+                getView().setEditableTitle(title);
+              }
+            });
+      }
+    });
+  }
 
-    public void refreshState() {
-        setContent((HasContent) session.getCurrentState());
+  @Override
+  public void detach() {
+    getView().detach();
+  }
+
+  private String genId(final StateToken token) {
+    return "k-cnav-" + token.toString().replace(StateToken.SEPARATOR, "-");
+  }
+
+  private Object getIcon(final StateToken token, final String contentTypeId,
+      final BasicMimeTypeDTO mimeType) {
+    if (!useGenericImageIcon && mimeType != null && mimeType.getType().equals("image")) {
+      return downloadUtilsProvider.get().getImageResizedUrl(token, ImageSize.ico);
+    } else {
+      return iconsRegistry.getContentTypeIcon(contentTypeId, mimeType);
     }
+  }
 
-    @Override
-    protected void revealInParent() {
-        RevealRootContentEvent.fire(this, this);
+  private String getTooltip(final StateToken token, final BasicMimeTypeDTO mimeType) {
+    if (mimeType != null && (mimeType.isImage() || mimeType.isPdf())) {
+      // Used for previews
+      return null;
+    } else {
+      return i18n.t("Double click to open");
     }
+  }
 
-    @Override
-    public void setContent(@Nonnull final HasContent state) {
-        getView().clear();
-        final StateContainerDTO stateContainer = (StateContainerDTO) state;
-        getView().setContainer(stateContainer);
-        final AccessRights rights = stateContainer.getContainerRights();
-        final GuiActionDescCollection actions = actionsRegistry.getCurrentActions(stateContainer.getGroup(),
-                stateContainer.getTypeId(), session.isLogged(), rights, ActionGroups.VIEW);
-        getView().setActions(actions);
-        createChildItems(stateContainer.getContainer(), stateContainer.getContainerRights());
-        // view.setEditable(rights.isEditable());
-    }
+  public void refreshState() {
+    setContent((HasContent) session.getCurrentState());
+  }
+
+  @Override
+  protected void revealInParent() {
+    RevealRootContentEvent.fire(this, this);
+  }
+
+  @Override
+  public void setContent(@Nonnull final HasContent state) {
+    getView().clear();
+    final StateContainerDTO stateContainer = (StateContainerDTO) state;
+    getView().setContainer(stateContainer);
+    final AccessRights rights = stateContainer.getContainerRights();
+    final GuiActionDescCollection actions = actionsRegistry.getCurrentActions(stateContainer.getGroup(),
+        stateContainer.getTypeId(), session.isLogged(), rights, ActionGroups.VIEW);
+    getView().setActions(actions);
+    createChildItems(stateContainer.getContainer(), stateContainer.getContainerRights());
+    // view.setEditable(rights.isEditable());
+  }
 }
\ No newline at end of file




More information about the kune-commits mailing list