/*
 * DeploymentMenuItem.java
 *
 * Copyright (C) 2009-15 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.studio.client.rsconnect.ui;

import org.rstudio.core.client.StringUtil;
import org.rstudio.core.client.widget.CheckableMenuItem;
import org.rstudio.studio.client.rsconnect.model.RSConnectDeploymentRecord;

import com.google.gwt.user.client.Command;

public class DeploymentMenuItem extends CheckableMenuItem
{
   public DeploymentMenuItem(RSConnectDeploymentRecord record, 
         boolean isChecked,
         Command onInvoked)
   {
      // we don't know the name of RPubs-deployed content, so don't show it
      super(record.getServer() == "rpubs.com" || 
               StringUtil.isNullOrEmpty(record.getDisplayName()) ? 
            record.getServer() : 
            record.getDisplayName() + " (" + record.getServer() + ")");
      
      // show actual name on hover (in case titles conflict)
      setTitle(record.getName());
      isChecked_ = isChecked;
      onInvoked_ = onInvoked;
      onStateChanged();
   }

   @Override
   public String getLabel()
   {
      return getText();
   }

   @Override
   public boolean isChecked()
   {
      return isChecked_;
   }
   
   @Override
   public void onInvoked()
   {
      onInvoked_.execute();
   }
   
   private boolean isChecked_;
   private final Command onInvoked_;
}

@@ -53,9 +53,9 @@
 09-1
-5
+7
  by 
@@ -674,16 +674,236 @@
 ngUtil;%0A
+import org.rstudio.core.client.command.AppCommand;%0Aimport org.rstudio.core.client.resources.ImageResource2x;%0Aimport org.rstudio.core.client.theme.res.ThemeResources;%0Aimport org.rstudio.core.client.theme.res.ThemeStyles;%0A
 import o
@@ -1028,16 +1028,69 @@
 ecord;%0A%0A
+import com.google.gwt.safehtml.shared.SafeHtmlUtils;%0A
 import c
@@ -1320,403 +1320,55 @@
     
-// we don't know the name of RPubs-deployed content, so don't show it%0A      super(record.getServer() == %22rpubs.com%22 %7C%7C %0A               StringUtil.isNullOrEmpty(record.getDisplayName()) ? %0A            record.getServer() : %0A            record.getDisplayName() + %22 (%22 + record.getServer() + %22)%22);%0A      %0A      // show actual name on hover (in case titles conflict)%0A      setTitle(record.getName());
+super(getHTML(isChecked, record), true);%0A      
 %0A   
@@ -1420,24 +1420,48 @@
  onInvoked;%0A
+      record_ = record;%0A
       onStat
@@ -1718,16 +1718,1645 @@
   %7D%0A   %0A
+   @Override%0A   public String getHTMLContent()%0A   %7B%0A      return getHTML(isChecked(), record_);%0A   %7D%0A   %0A   private static String getHTML(boolean isChecked, RSConnectDeploymentRecord record)%0A   %7B%0A      // build title; we don't know the name of RPubs-deployed content, so don't show it%0A      String title = record.getServer() == %22rpubs.com%22 %7C%7C %0A               StringUtil.isNullOrEmpty(record.getDisplayName()) ? %0A            record.getServer() : %0A            record.getDisplayName();%0A%0A      // build subtitle%0A      String subtitle;%0A      if (record.getUsername() != null)%0A         subtitle = record.getUsername();%0A      else%0A         subtitle = record.getAccountName();%0A      subtitle += %22@%22;%0A      if (record.getHostUrl() != null)%0A         subtitle += StringUtil.getHostFromUrl(record.getHostUrl());%0A      else%0A         subtitle += record.getServer();%0A      %0A      String label = %0A            %22%3Cdiv%3E%22 + SafeHtmlUtils.htmlEscape(title) + %22%3C/div%3E%22 +%0A            %22%3Cdiv class=%5C%22%22 + ThemeStyles.INSTANCE.menuItemSubtitle() + %22%5C%22%3E%22 + %0A                  SafeHtmlUtils.htmlEscape(subtitle) + %22%3C/div%3E%22;%0A%0A      return AppCommand.formatMenuLabel(%0A            // icon%0A            isChecked ? %0A                  new ImageResource2x(ThemeResources.INSTANCE.menuCheck2x()) :%0A                  null,%0A            label,   // label%0A            true,    // label is HTML%0A            null,    // no shortcut%0A            null,    // no icon offset%0A            null,    // no right image%0A            null,    // no right image description%0A            ThemeStyles.INSTANCE.menuCheckable());%0A   %7D%0A   %0A   private final RSConnectDeploymentRecord record_;%0A
    priva

create deployment item subtitle with username and path