How to access a "Configurable" Parameter

janvanrijn
New Altair Community Member
The document "How to Extend RapidMiner 5" describes how to create Configurables, for example to store Connections to certain servers (Chapter 8 ). I try to do so for a RapidMiner Studio, and as it turns out, many of the code is applicable for this version. However, I ran into some difficulties.
I have for my Operator overridden the getParameterTypes function:
Now, if I want to access the integer parameter, I can easily access it in the doWork function:
I have for my Operator overridden the getParameterTypes function:
public List<ParameterType> getParameterTypes() {Hence, I can see both the integer and configurable parameter fields.
List<ParameterType> types = super.getParameterTypes();
types.add(new ParameterTypeConfigurable(PARAMETER_CONFIG, "Choose a Connection", "Config"));
types.add(new ParameterTypeInt(PARAMETER_TASKID, "The Task that needs to be executed", 1, Integer.MAX_VALUE, false));
return types;
}
Now, if I want to access the integer parameter, I can easily access it in the doWork function:
getParameterAsInt(PARAMETER_TASKID);I would assume there is a similar way to obtain the Configurable? Yet, I can't find it, and it is not documented in the manual. Many thanks for helping out.
Tagged:
0
Answers
-
Hi,
I have some example code from our own Amazon S3 configurable for you which should be helpful.
The parameter type defintion:
@Override
public List<ParameterType> getParameterTypes() {
ParameterType type = new ParameterTypeConfigurable(PARAMETER_CONNECTION, "The Amazon S3 connection.",
AmazonS3ConnectionConfigurator.TYPE_ID);
type.setOptional(false);
parameterTypes.add(type);
//...
}
The doWork() method of the operator:
Regards,
@Override
public void doWork() throws OperatorException {
AmazonS3Connection connection = null;
try {
connection = (AmazonS3Connection) ConfigurationManager.getInstance().lookup(
AmazonS3ConnectionConfigurator.TYPE_ID, getParameterAsString(PARAMETER_CONNECTION),
getProcess().getRepositoryAccessor());
} catch (ConfigurationException e) {
throw new UserError(this, e, "amazon.configuration_read");
}
// access configurable settings
String bucketName = connection.getBucketName(filePath);
String fileName = connection.getFileName(filePath);
AmazonS3 client = connection.createConnection();
// do stuff with S3
}
Marco0 -
Dear Marco,
You just made my day! Thanks.
One more question regarding the GUI description, as described on page 73. I copied these values, of course changing ofcourse "crmconfig" into my own I18NBaseKey. However, these didn't change anything. Did something change between version 5 and RM Studio? Or am I changing the wrong config file? I work in src/main/resources/com/rapidminer/resources/i18n/GUITemplate.properties, since I found a reference to this file in some META-INF from a shadow Jar. Coudn't find any other references...0 -
Hi,
Seems to be out of date. Amazon S3 example again:
Regards,
gui.configurable.{baseKey}.name = Amazon S3 Connection
gui.configurable.{baseKey}.description = Specifies the details to establish a connection to Amazon S3.
gui.configurable.{baseKey}.icon = data_cloud.png
Marco0 -
Seems to work, great.
Just not the icon. I tried some different ones, but the button is still empty.
Are you sure it's this one? In the manual it hints atgui.action.configuration.crmconfig.icon = data_cloud.png
but replacing crmconfig with {baseKey} doesn't work0 -
Hi,
1. Where is your icon located? Should be "resources/icons/16/my_icon.png"
2. What version of RapidMiner Studio are we talking about? I looked at the 6.4 sources.
Ultimately, it should work if you can successfully get the icon in your code via
Regards,
this.getClass().getClassLoader().getResource("icons/16/my_icon.png");
Marco0 -
Yeah, I'm using version 6.4 as well. It could be that the icon is not in the right directory, the code you showed me returns null.
I tried using resources from the RapidMiner resources, like I do for the operators. Apparently that is not possible. In which subfolder of my plugin should I locate resources/icons/16/? I tried some different options, but apparently not the right one.0 -
Hi,
sorry, the code should have been:
Regards,
this.getClass().getClassLoader().getResource("com/rapidminer/resources/icons/16/my_icon.png");
Marco0 -
So the following code:
System.err.println("res: " + this.getClass().getClassLoader().getResource("com/rapidminer/resources/icons/16/my_icon.png") ); // my own icon, in resources folder
Now returns the following output:
System.err.println("res: " + this.getClass().getClassLoader().getResource("com/rapidminer/resources/icons/24/import.png") ); // icon borrowed from rapidminer iconsres: jar:file:/vol/home/rijnjnvan/apps/rapidminer-studio/lib/plugins/OpenmlConnector-1.0.0-all.jar!/com/rapidminer/resources/icons/16/my_icon.png
This is what the GUITemplate.properties reads:
res: jar:file:/vol/home/rijnjnvan/apps/rapidminer-studio/lib/rapidminer-studio-core-6.4.0.jar!/com/rapidminer/resources/icons/24/import.pnggui.configurable.{baseKey}.name = OpenML Connection
# also this doesn't work: com/rapidminer/resources/icons/16/my_icon.png
gui.configurable.{baseKey}.description = An entry decribing an OpenML Connector
gui.configurable.{baseKey}.icon = my_icon.png
When I open my operator, I can see in the parameter list "OpenML Connection" and when I hoover over the info button it also says "An entry decribing an OpenML Connector". However, the button still shows no icon which makes it both small and hard to understand for end users.
Is there somewhere documentation on this GUI properties file, apart from the Extension manual?0 -
Hi,
the i18n files themselves are not documented, usually (at least for newer classes) the i18n key format is part of the JavaDoc for the classes.
Your code looks good, it should work - I don't know why it does not. Does it work if you change the icon in the i18n file to "import.png", i.e. an icon from Studio itself?
Regards,
Marco0 -
No that does still not work.
Just to be sure we're talking about the same thing, I have attached a screenshot about where I would expect an icon.
(any icon would be fine by me.)
[img=http://s1.postimg.org/wqydhjyxn/screen.jpg]0 -
Hi,
when you add a configurable instance to the operator (so it is selected) and the click the button again, is the correct configurable preselected in the dialog? Is the icon in the dialog correct?
Regards,
Marco0 -
Yes.Marco Boeck wrote:
when you add a configurable instance to the operator (so it is selected) and the click the button again, is the correct configurable preselected in the dialog?
As I did not attempt to change the default icon of the dialog, there is a gear/plug icon displayed top left.Is the icon in the dialog correct? 0 -
Hi,
this icon:
Regards,
Marco0 -
No Icon at all ...0