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.Label;
9 import com.atlassian.plugins.codegen.modules.common.Tooltip;
10 import com.atlassian.plugins.codegen.modules.common.web.WebSectionModuleCreator;
11 import com.atlassian.plugins.codegen.modules.common.web.WebSectionProperties;
12
13 import org.codehaus.plexus.components.interactivity.Prompter;
14 import org.codehaus.plexus.components.interactivity.PrompterException;
15
16
17
18
19 @ModuleCreatorClass(WebSectionModuleCreator.class)
20 public class WebSectionPrompter extends AbstractWebFragmentPrompter<WebSectionProperties>
21 {
22
23 public WebSectionPrompter(Prompter prompter)
24 {
25 super(prompter);
26
27 }
28
29 @Override
30 public WebSectionProperties promptForBasicProperties(PluginModuleLocation moduleLocation) throws PrompterException
31 {
32 String moduleName = promptNotBlank("Enter Plugin Module Name", "My Web Section");
33 String location = promptNotBlank("Enter Location (e.g. system.admin/mynewsection)");
34
35 WebSectionProperties props = new WebSectionProperties(moduleName, location);
36
37 Label label = new Label(props.getModuleKey() + ".label", props.getModuleName());
38 props.setLabel(label);
39
40 suppressAdvancedNamePrompt();
41
42 return props;
43 }
44
45 @Override
46 public void promptForAdvancedProperties(WebSectionProperties props, PluginModuleLocation moduleLocation) throws PrompterException
47 {
48
49 props.setWeight(promptForInt("Weight", 1000));
50
51
52 Label label = props.getLabel();
53 String labelKey = promptNotBlank("Enter Label Key", props.getLabel()
54 .getKey());
55 String labelValue = promptNotBlank("Enter Label Value", props.getLabel()
56 .getValue());
57
58 label.setKey(labelKey);
59 label.setValue(labelValue);
60
61 props.addI18nProperty(labelKey, labelValue);
62
63 List<String> labelParamVals = promptForList("Add Label Param?", "Enter Param Value");
64 if (!labelParamVals.isEmpty())
65 {
66 for (String labelVal : labelParamVals)
67 {
68 label.addParam(labelVal);
69 }
70 }
71
72
73 if (promptForBoolean("Add Tooltip?", "N"))
74 {
75 String tooltipKey = promptNotBlank("Enter Tooltip Key", props.getModuleKey() + ".tooltip");
76 String tooltipValue = promptNotBlank("Enter Tooltip Value", props.getModuleName() + " Tooltip");
77 Tooltip tooltip = new Tooltip(tooltipKey, tooltipValue);
78
79 List<String> tooltipParamVals = promptForList("Add Tooltip Param?", "Enter Param Value");
80 if (!tooltipParamVals.isEmpty())
81 {
82 for (String tipVal : tooltipParamVals)
83 {
84 tooltip.addParam(tipVal);
85 }
86 }
87
88 props.setTooltip(tooltip);
89 props.addI18nProperty(tooltipKey, tooltipValue);
90 }
91
92
93 props.setResources(promptForResources());
94
95
96 props.setContextProvider(promptForContextProvider());
97
98
99 Map<String, String> moduleParams = promptForParams("Add Plugin Module Param?");
100 props.setParams(moduleParams);
101
102
103 props.setConditions(promptForConditions());
104 }
105 }