Implement the custom listener for drop down menu

Chaklader

Member
Joined
Feb 23, 2021
Posts
6
Likes
0
This is the code from Momentum custom study:


@Override
public void initialize(Defaults defaults) {

var sd = createSD();
var tab = sd.addTab(get("TAB_GENERAL"));

var inputs = tab.addGroup(get("LBL_INPUTS"));
inputs.addRow(new InputDescriptor(Inputs.INPUT, get("LBL_INPUT"), Enums.BarInput.CLOSE));
inputs.addRow(new IntegerDescriptor(Inputs.PERIOD, get("LBL_PERIOD"), 14, 1, 9999, 1));

var lines = tab.addGroup(get("LBL_COLORS"));
lines.addRow(new PathDescriptor(Inputs.PATH, get("LBL_LINE"), defaults.getLineColor(), 1.0f, null));
lines.addRow(new IndicatorDescriptor(Inputs.IND, get("LBL_INDICATOR"), null, null, false, true, true));

// Quick Settings (Tool Bar and Popup Editor)
sd.addQuickSettings(Inputs.INPUT);
sd.addQuickSettings(new SliderDescriptor(Inputs.PERIOD, get("LBL_PERIOD"), 14, 1, 9999, true, Enums.Icon.SINE_WAVE::get));
sd.addQuickSettings(Inputs.PATH);

var desc = createRD();
desc.setLabelSettings(Inputs.INPUT, Inputs.PERIOD);
desc.exportValue(new ValueDescriptor(Values.M, get("LBL_MOMENTUM"), new String[]{Inputs.INPUT, Inputs.PERIOD}));
desc.declarePath(Values.M, Inputs.PATH);
desc.declareIndicator(Values.M, Inputs.IND);
desc.setRangeKeys(Values.M);
}



This line add a drop-down list to the UI:

inputs.addRow(new InputDescriptor(Inputs.INPUT, get("LBL_INPUT"), Enums.BarInput.CLOSE));


How do I find which item is selected in the drop-down menu by the user from the code? I think I need to implement a custom event listener, but I'm not sure how to implement it.
 

Spin

Well-known member
Joined
May 22, 2019
Posts
478
Likes
191
From the MW-SDK-starters-package, the 'Momentum.java' file more specifically:



Line 43 reads:
Java:
inputs.addRow(new InputDescriptor(Inputs.INPUT, get("LBL_INPUT"), Enums.BarInput.CLOSE));

And line 71:
Java:
Object input = getSettings().getInput(Inputs.INPUT);

And finally line 74:
Java:
Double curVal = series.getDouble(index,  input);

I believe that is what you were looking for ? :)
 
Top