<commit_before>/*
 * ImageButtonColumn.java
 *
 * Copyright (C) 2009-12 by RStudio, Inc.
 *
 * Unless you have received this program directly from RStudio pursuant
 * to the terms of a commercial license agreement with RStudio, then
 * this program is licensed to you under the terms of version 3 of the
 * GNU Affero General Public License. This program is distributed WITHOUT
 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
 *
 */
package org.rstudio.core.client.cellview;

import org.rstudio.core.client.widget.OperationWithInput;

import com.google.gwt.cell.client.ButtonCell;
import com.google.gwt.cell.client.FieldUpdater;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.cellview.client.Column;

public class ImageButtonColumn<T> extends Column<T, String>
{
   public ImageButtonColumn(final ImageResource2x image,
                            final OperationWithInput<T> onClick,
                            final String title)
   {
      super(new ButtonCell(){
         @Override
         public void render(Context context, 
                            SafeHtml value, 
                            SafeHtmlBuilder sb) 
         {   
            if (value != null)
            {
               sb.appendHtmlConstant("<span title=\"" + title + "\" " +
                                     "style=\"cursor: pointer;\">");
               sb.appendHtmlConstant(image.getSafeHtml());
               sb.appendHtmlConstant("</span>");
            }
         }                                
      });

      setFieldUpdater(new FieldUpdater<T,String>() {
         public void update(int index, T object, String value)
         {
            if (value != null)
               onClick.execute(object);
         }
      });
   }


   @Override
   public String getValue(T object)
   {
      if (showButton(object))
         return new String();
      else
         return null;
   }
   
   protected boolean showButton(T object)<commit_msg>add missing ref to imagebuttoncolumn<commit_after>/*
 * ImageButtonColumn.java
 *
 * Copyright (C) 2009-12 by RStudio, Inc.
 *
 * Unless you have received this program directly from RStudio pursuant
 * to the terms of a commercial license agreement with RStudio, then
 * this program is licensed to you under the terms of version 3 of the
 * GNU Affero General Public License. This program is distributed WITHOUT
 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
 *
 */
package org.rstudio.core.client.cellview;

import org.rstudio.core.client.resources.ImageResource2x;
import org.rstudio.core.client.widget.OperationWithInput;

import com.google.gwt.cell.client.ButtonCell;
import com.google.gwt.cell.client.FieldUpdater;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.cellview.client.Column;

public class ImageButtonColumn<T> extends Column<T, String>
{
   public ImageButtonColumn(final ImageResource2x image,
                            final OperationWithInput<T> onClick,
                            final String title)
   {
      super(new ButtonCell(){
         @Override
         public void render(Context context, 
                            SafeHtml value, 
                            SafeHtmlBuilder sb) 
         {   
            if (value != null)
            {
               sb.appendHtmlConstant("<span title=\"" + title + "\" " +
                                     "style=\"cursor: pointer;\">");
               sb.append(image.getSafeHtml());
               sb.appendHtmlConstant("</span>");
            }
         }                                
      });

      setFieldUpdater(new FieldUpdater<T,String>() {
         public void update(int index, T object, String value)
         {
            if (value != null)
               onClick.execute(object);
         }
      });
   }


   @Override
   public String getValue(T object)
   {
      if (showButton(object))
         return new String();
      else
         return null;
   }
   
   protected boolean showButton(T object)
{'fraction_non_alphanumeric': 0.09256415880675586, 'fraction_numerical': 0.004606273305549463, 'mean_word_length': 2.131868131868132, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3020658', 'n_tokens_mistral': 1234, 'n_tokens_neox': 1198, 'n_words': 329}