Changeset 7758


Ignore:
Timestamp:
Nov 27, 2019, 12:58:04 PM (3 years ago)
Author:
Nicklas Nordborg
Message:

References #2199: Implement a "File viewer" extension point

Implemented functioanlity for easier handling of dynamic attributes to all action implementations that are subclasses to DynamicActionAttributeSupport. This includes the ButtonBean implementation that is used by the file view/download actions.

Location:
trunk/src/clients/web/net/sf/basedb/clients/web/extensions
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/clients/web/net/sf/basedb/clients/web/extensions/DynamicActionAttributeSupport.java

    r6626 r7758  
    2121package net.sf.basedb.clients.web.extensions;
    2222
     23import java.util.HashMap;
    2324import java.util.Iterator;
     25import java.util.Map;
     26
     27import org.apache.commons.collections4.iterators.IteratorChain;
    2428
    2529import net.sf.basedb.util.extensions.Action;
     
    3943  private Iterator<DynamicActionAttribute> dynamicAttributes;
    4044  private DynamicActionAttributes source;
     45  private Map<String, DynamicActionAttribute> moreAttributes;
     46 
    4147 
    4248  /**
     
    8389      it = source.getDynamicActionAttributes();
    8490    }
     91    if (moreAttributes != null)
     92    {
     93      if (it != null)
     94      {
     95        it = new IteratorChain<>(it, moreAttributes.values().iterator());
     96      }
     97      else
     98      {
     99        it = moreAttributes.values().iterator();
     100      }
     101    }
    85102    return it;
    86103  }
     
    96113    this.source = source;
    97114  }
     115 
     116  /**
     117    Adds a dynamic attribute to the action. The name should be unique or it will overwrite any
     118    existing attribute. Attributes that are set via this method are merged with attributes
     119    that are set via {@link #setDynamicActionAttributesSource(DynamicActionAttributes)}.
     120    Duplicates are not removed in this case.
     121    @since 3.16
     122  */
     123  public void setDynamicAttribute(String name, Object value)
     124  {
     125    if (moreAttributes == null) moreAttributes = new HashMap<String, DynamicActionAttribute>();
     126    moreAttributes.put(name, new DynamicActionAttribute(name, value == null ? null : value.toString()));
     127  }
    98128
    99129}
  • trunk/src/clients/web/net/sf/basedb/clients/web/extensions/fileviewer/ViewAndDownloadActionFactory.java

    r7757 r7758  
    4444      String bytes = Values.formatBytes(f.getSize(), 1);
    4545     
    46       // TODO -- we are lacking a simple way to add data-* attributes so the icons are not linked
    47      
    4846      ButtonBean view = new ButtonBean();
    4947      view.setVisible(true);
     
    5149      view.setTitle("View the contents of this file (" + bytes + ")");
    5250      view.setIcon(jspContext.getRoot()+"/images/view.png");
     51      view.setDynamicAttribute("data-file-id", f.getId());
     52      view.setDynamicAttribute("data-auto-init", "view-file");
    5353     
    5454      ButtonBean download = new ButtonBean();
     
    5757      download.setTitle("Download the contents of this file (" + bytes + ")");
    5858      download.setIcon(jspContext.getRoot()+"/images/download.png");
     59      download.setDynamicAttribute("data-file-id", f.getId());
     60      download.setDynamicAttribute("data-auto-init", "download-file");
    5961     
    6062      actions = new ButtonAction[] { view, download };
Note: See TracChangeset for help on using the changeset viewer.