001/* 002 * (C) Copyright 2006-2007 Nuxeo SAS <http://nuxeo.com> and others 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Jean-Marc Orliaguet, Chalmers 011 * 012 * $Id$ 013 */ 014 015package org.nuxeo.theme.html.ui; 016 017import java.util.HashMap; 018import java.util.Map; 019 020import org.nuxeo.theme.html.Utils; 021 022public class Button { 023 024 public static String render(Map<String, String> params) { 025 StringBuilder sb = new StringBuilder(); 026 027 String identifier = params.get("identifier"); 028 String controlledBy = params.get("controlledBy"); 029 String switchTo = params.get("switchTo"); 030 String link = params.get("link"); 031 String menu = params.get("menu"); 032 String label = params.get("label"); 033 String classNames = params.get("classNames"); 034 String icon = params.get("icon"); 035 036 // view 037 Map<String, Object> view = new HashMap<String, Object>(); 038 view.put("id", identifier); 039 Map<String, Object> widget = new HashMap<String, Object>(); 040 widget.put("type", "button"); 041 view.put("widget", widget); 042 if (null != switchTo) { 043 String[] p = switchTo.split("/"); 044 if (p.length > 1) { 045 view.put("perspectiveController", p[0]); 046 view.put("toPerspective", p[1]); 047 } 048 } 049 if (null != controlledBy) { 050 view.put("controllers", controlledBy.split(",")); 051 } 052 if (null != link) { 053 view.put("link", link); 054 } 055 if (null != menu) { 056 view.put("menu", menu); 057 } 058 if (null != classNames) { 059 view.put("classNames", classNames); 060 } 061 if (null != icon) { 062 view.put("icon", icon); 063 } 064 view.put("label", label); 065 066 sb.append(String.format("<ins class=\"view\">%s</ins>", Utils.toJson(view))); 067 return sb.toString(); 068 } 069 070}