1 package com.atlassian.maven.plugins.amps.codegen.prompter.common.web;
2
3 import java.util.List;
4 import java.util.Map;
5
6 import com.atlassian.maven.plugins.amps.codegen.annotations.ModuleCreatorClass;
7 import com.atlassian.plugins.codegen.modules.PluginModuleLocation;
8 import com.atlassian.plugins.codegen.modules.common.Icon;
9 import com.atlassian.plugins.codegen.modules.common.Label;
10 import com.atlassian.plugins.codegen.modules.common.Link;
11 import com.atlassian.plugins.codegen.modules.common.Tooltip;
12 import com.atlassian.plugins.codegen.modules.common.web.WebItemModuleCreator;
13 import com.atlassian.plugins.codegen.modules.common.web.WebItemProperties;
14
15 import org.codehaus.plexus.components.interactivity.Prompter;
16 import org.codehaus.plexus.components.interactivity.PrompterException;
17
18
19
20
21 @ModuleCreatorClass(WebItemModuleCreator.class)
22 public class WebItemPrompter extends AbstractWebFragmentPrompter<WebItemProperties>
23 {
24
25 public WebItemPrompter(Prompter prompter)
26 {
27 super(prompter);
28
29 }
30
31 @Override
32 public WebItemProperties promptForBasicProperties(PluginModuleLocation moduleLocation) throws PrompterException
33 {
34 String moduleName = promptNotBlank("Enter Plugin Module Name", "My Web Item");
35 String section = promptNotBlank("Enter Section (e.g. system.admin/globalsettings)");
36
37 WebItemProperties props = new WebItemProperties(moduleName, section);
38
39 String linkPath = promptNotBlank("Enter Link URL (e.g. /secure/CreateIssue!default.jspa)");
40 Link link = new Link(linkPath);
41 link.setLinkId(props.getModuleKey() + "-link");
42 props.setLink(link);
43
44 Label label = new Label(props.getModuleKey() + ".label", props.getModuleName());
45 props.setLabel(label);
46
47 suppressAdvancedNamePrompt();
48
49 return props;
50 }
51
52 @Override
53 public void promptForAdvancedProperties(WebItemProperties props, PluginModuleLocation moduleLocation) throws PrompterException
54 {
55
56 props.setWeight(promptForInt("Weight", 1000));
57
58
59 props.getLink()
60 .setLinkId(promptNotBlank("Link Id", props.getLink()
61 .getLinkId()));
62
63
64 Label label = props.getLabel();
65 String labelKey = promptNotBlank("Enter Label Key", props.getLabel()
66 .getKey());
67 String labelValue = promptNotBlank("Enter Label Value", props.getLabel()
68 .getValue());
69
70 label.setKey(labelKey);
71 label.setValue(labelValue);
72
73 props.addI18nProperty(labelKey, labelValue);
74
75 List<String> labelParamVals = promptForList("Add Label Param?", "Enter Param Value");
76 if (!labelParamVals.isEmpty())
77 {
78 for (String labelVal : labelParamVals)
79 {
80 label.addParam(labelVal);
81 }
82 }
83
84
85 if (promptForBoolean("Add Icon?", "N"))
86 {
87 String iconPath = promptNotBlank("Icon Location (e.g. /images/icons/print.gif)");
88 int width = promptForInt("Icon Width", 16);
89 int height = promptForInt("Icon Height", 16);
90
91 Link iconLink = new Link(iconPath);
92 iconLink.setLinkId(props.getModuleKey() + "-icon");
93
94 Icon icon = new Icon(width, height);
95 icon.setLink(iconLink);
96
97 props.setIcon(icon);
98 }
99
100
101 if (promptForBoolean("Add Tooltip?", "N"))
102 {
103 String tooltipKey = promptNotBlank("Enter Tooltip Key", props.getModuleKey() + ".tooltip");
104 String tooltipValue = promptNotBlank("Enter Tooltip Value", props.getModuleName() + " Tooltip");
105 Tooltip tooltip = new Tooltip(tooltipKey, tooltipValue);
106
107 List<String> tooltipParamVals = promptForList("Add Tooltip Param?", "Enter Param Value");
108 if (!tooltipParamVals.isEmpty())
109 {
110 for (String tipVal : tooltipParamVals)
111 {
112 tooltip.addParam(tipVal);
113 }
114 }
115
116 props.setTooltip(tooltip);
117 props.addI18nProperty(tooltipKey, tooltipValue);
118 }
119
120
121 props.setResources(promptForResources());
122
123
124 props.setContextProvider(promptForContextProvider());
125
126
127 Map<String, String> moduleParams = promptForParams("Add Plugin Module Param?");
128 props.setParams(moduleParams);
129
130
131 props.setConditions(promptForConditions());
132
133 }
134 }