1 31 32 package org.opencms.workplace.tools; 33 34 import org.opencms.main.OpenCms; 35 import org.opencms.util.CmsIdentifiableObjectContainer; 36 import org.opencms.workplace.CmsWorkplace; 37 38 import java.util.Iterator ; 39 import java.util.List ; 40 41 55 public class CmsTool { 56 57 58 private final CmsIdentifiableObjectContainer m_container = new CmsIdentifiableObjectContainer(true, true); 59 60 61 private I_CmsToolHandler m_handler; 62 63 64 private final String m_id; 65 66 72 public CmsTool(String id, I_CmsToolHandler handler) { 73 74 m_id = id; 75 m_handler = handler; 76 77 } 78 79 86 public void addToolGroup(CmsToolGroup group) { 87 88 m_container.addIdentifiableObject(group.getName(), group); 89 } 90 91 99 public void addToolGroup(CmsToolGroup group, float position) { 100 101 m_container.addIdentifiableObject(group.getName(), group, position); 102 } 103 104 111 public String buttonHtml(CmsWorkplace wp) { 112 113 if (!m_handler.isVisible(wp.getCms())) { 114 return ""; 115 } 116 String link = CmsToolManager.linkForToolPath( 117 wp.getJsp(), 118 getHandler().getPath(), 119 getHandler().getParameters(wp)); 120 String onClic = "openPage('" + link + "');"; 121 return A_CmsHtmlIconButton.defaultButtonHtml( 122 wp.getJsp(), 123 CmsHtmlIconButtonStyleEnum.BIG_ICON_TEXT, 124 getId(), 125 m_handler.getName(), 126 m_handler.isEnabled(wp.getCms()) ? m_handler.getHelpText() : m_handler.getDisabledHelpText(), 127 m_handler.isEnabled(wp.getCms()), 128 m_handler.getIconPath(), 129 m_handler.getConfirmationMessage(), 130 onClic); 131 } 132 133 140 public boolean equals(Object obj) { 141 142 if (obj == this) { 143 return true; 144 } 145 if (obj instanceof CmsTool) { 146 return ((CmsTool)obj).m_id.equals(m_id); 147 } 148 return false; 149 } 150 151 156 public I_CmsToolHandler getHandler() { 157 158 return m_handler; 159 } 160 161 166 public String getId() { 167 168 return m_id; 169 } 170 171 180 public CmsToolGroup getToolGroup(String name) { 181 182 return (CmsToolGroup)m_container.getObject(name); 183 } 184 185 190 public List getToolGroups() { 191 192 return m_container.elementList(); 193 } 194 195 202 public String groupHtml(CmsWorkplace wp) { 203 204 List subTools = OpenCms.getWorkplaceManager().getToolManager().getToolsForPath(wp, getHandler().getPath(), false); 205 Iterator itSubTools = subTools.iterator(); 206 m_container.clear(); 207 while (itSubTools.hasNext()) { 208 CmsTool subTool = (CmsTool)itSubTools.next(); 209 CmsToolGroup group = null; 211 String groupName = CmsToolMacroResolver.resolveMacros(subTool.getHandler().getGroup(), wp); 212 213 group = getToolGroup(groupName); 215 if (group == null) { 216 String gid = "group" + getToolGroups().size(); 218 group = new CmsToolGroup(gid, groupName); 219 addToolGroup(group, subTool.getHandler().getPosition()); 220 } 221 222 group.addAdminTool(subTool, subTool.getHandler().getPosition()); 224 225 } 226 227 StringBuffer html = new StringBuffer (512); 228 Iterator itHtml = getToolGroups().iterator(); 229 while (itHtml.hasNext()) { 230 CmsToolGroup group = (CmsToolGroup)itHtml.next(); 231 html.append(group.groupHtml(wp)); 232 } 233 return CmsToolMacroResolver.resolveMacros(html.toString(), wp); 234 } 235 236 239 public int hashCode() { 240 241 return m_handler.getName().hashCode(); 242 } 243 } | Popular Tags |