final MultiKeyMap<String, JPanel> panelPartsMap = new MultiKeyMap<String, JPanel>();
final Collection<PanelPart> panelPartsList = new ArrayList<PanelPart>();
final MultiKeyMap<String, Integer> panelPartRowsMap = new MultiKeyMap<String, Integer>();
for (final String param : params) {
final Widget paramWi = createWidget(param, prefix, rightWidth);
/* sub panel */
final String section = getSection(param);
final JPanel panel;
final AccessMode.Type accessType = getAccessType(param);
final String accessTypeString = accessType.toString();
final Boolean advanced = isAdvanced(param);
final String advancedString = advanced.toString();
if (panelPartsMap.containsKey(section, accessTypeString, advancedString)) {
panel = panelPartsMap.get(section, accessTypeString, advancedString);
panelPartRowsMap.put(section,
accessTypeString,
advancedString,
panelPartRowsMap.get(section, accessTypeString, advancedString) + 1);
} else {
panel = new JPanel(new SpringLayout());
panel.setBackground(getSectionColor(section));
if (advanced) {
advancedPanelList.add(panel);
panel.setVisible(application.isAdvancedMode());
}
panelPartsMap.put(section, accessTypeString, advancedString, panel);
panelPartsList.add(new PanelPart(section, accessType, advanced));
panelPartRowsMap.put(section, accessTypeString, advancedString, 1);
}
/* label */
final JLabel label = new JLabel(getParamShortDesc(param));
final String longDesc = getParamLongDesc(param);
paramWi.setLabel(label, longDesc);
/* tool tip */
paramWi.setToolTipText(getToolTipText(param, paramWi));
label.setToolTipText(longDesc + additionalToolTip(param));
int height = 0;
if (paramWi instanceof Label) {
height = application.getDefaultSize("Browser.LabelFieldHeight");
}
addField(panel, label, paramWi.getComponent(), leftWidth, rightWidth, height);
}
final boolean wizard = Widget.WIZARD_PREFIX.equals(prefix);
for (final String param : params) {
final Widget paramWi = getWidget(param, prefix);
if (wizard) {
final Widget rpwi = getWidget(param, null);
if (rpwi == null) {
LOG.error("addParams: unknown param: " + param);
continue;
}
if (paramWi.getValue() == null
|| paramWi.getValue().isNothingSelected()) {
rpwi.setValueAndWait(null);
} else {
final Value value = paramWi.getValue();
rpwi.setValueAndWait(value);
}
}
}
for (final String param : params) {
final Widget paramWi = getWidget(param, prefix);
Widget rpwi = null;
if (wizard) {
rpwi = getWidget(param, null);
}
final Widget realParamWi = rpwi;
paramWi.addListeners(new WidgetListener() {
@Override
public void check(final Value value) {
checkParameterFields(paramWi, realParamWi, param, getParametersFromXML(), thisApplyButton);
}
});
}
/* add sub panels to the option panel */
final Map<String, JPanel> sectionMap = new HashMap<String, JPanel>();
final Collection<JPanel> notAdvancedSections = new HashSet<JPanel>();
final Collection<JPanel> advancedSections = new HashSet<JPanel>();
for (final PanelPart panelPart : panelPartsList) {
final String section = panelPart.getSection();
final AccessMode.Type accessType = panelPart.getType();
final String accessTypeString = accessType.toString();
final Boolean advanced = panelPart.isAdvanced();
final String advancedString = advanced.toString();
final JPanel panel = panelPartsMap.get(section, accessTypeString, advancedString);
final int rows = panelPartRowsMap.get(section, accessTypeString, advancedString);
final int columns = 2;
SpringUtilities.makeCompactGrid(panel, rows, columns,
1, 1, // initX, initY
1, 1); // xPad, yPad
final JPanel sectionPanel;
if (sectionMap.containsKey(section)) {
sectionPanel = sectionMap.get(section);
} else {
sectionPanel = getParamPanel(getSectionDisplayName(section), getSectionColor(section));
sectionMap.put(section, sectionPanel);
addSectionPanel(section, wizard, sectionPanel);
optionsPanel.add(sectionPanel);
if (sameAsFields != null) {
final Widget sameAsCombo = sameAsFields.get(section);
if (sameAsCombo != null) {
final JPanel saPanel = new JPanel(new SpringLayout());
saPanel.setBackground(Browser.BUTTON_PANEL_BACKGROUND);
final JLabel label = new JLabel(Tools.getString("ClusterBrowser.SameAs"));
sameAsCombo.setLabel(label, "");
addField(saPanel, label, sameAsCombo.getComponent(), leftWidth, rightWidth, 0);
SpringUtilities.makeCompactGrid(saPanel, 1, 2,
1, 1, // initX, initY
1, 1); // xPad, yPad
sectionPanel.add(saPanel);
}