PluginInterface default_pi = PluginInitializer.getDefaultInterface();
final UIManager ui_manager = default_pi.getUIManager();
BasicPluginConfigModel configModel = ui_manager.createBasicPluginConfigModel(
ConfigSection.SECTION_CONNECTION, "Pairing");
configModel.addHyperlinkParameter2( "ConfigView.label.please.visit.here", MessageText.getString( "ConfigView.section.connection.pairing.url" ));
param_enable = configModel.addBooleanParameter2( "pairing.enable", "pairing.enable", false );
String access_code = readAccessCode();
param_ac_info = configModel.addInfoParameter2( "pairing.accesscode", access_code);
param_status_info = configModel.addInfoParameter2( "pairing.status.info", "" );
param_last_error = configModel.addInfoParameter2( "pairing.last.error", "" );
param_view = configModel.addHyperlinkParameter2( "pairing.view.registered", SERVICE_URL + "/web/view?ac=" + access_code);
if ( access_code.length() == 0 ){
param_view.setEnabled( false );
}
final ActionParameter ap = configModel.addActionParameter2( "pairing.ac.getnew", "pairing.ac.getnew.create" );
ap.addListener(
new ParameterListener()
{
public void
parameterChanged(
Parameter param )
{
try{
ap.setEnabled( false );
allocateAccessCode( false );
SimpleTimer.addEvent(
"PM:enabler",
SystemTime.getOffsetTime(30*1000),
new TimerEventPerformer()
{
public void
perform(
TimerEvent event )
{
ap.setEnabled( true );
}
});
}catch( Throwable e ){
ap.setEnabled( true );
String details = MessageText.getString(
"pairing.alloc.fail",
new String[]{ Debug.getNestedExceptionMessage( e )});
ui_manager.showMessageBox(
"pairing.op.fail",
"!" + details + "!",
UIManagerEvent.MT_OK );
}
}
});
LabelParameter param_e_info = configModel.addLabelParameter2( "pairing.explicit.info" );
param_e_enable = configModel.addBooleanParameter2( "pairing.explicit.enable", "pairing.explicit.enable", false );
param_public_ipv4 = configModel.addStringParameter2( "pairing.ipv4", "pairing.ipv4", "" );
param_public_ipv6 = configModel.addStringParameter2( "pairing.ipv6", "pairing.ipv6", "" );
param_host = configModel.addStringParameter2( "pairing.host", "pairing.host", "" );
LabelParameter spacer = configModel.addLabelParameter2( "blank.resource" );
param_local_ipv4 = configModel.addStringParameter2( "pairing.local.ipv4", "pairing.local.ipv4", "" );
param_local_ipv6 = configModel.addStringParameter2( "pairing.local.ipv6", "pairing.local.ipv6", "" );
param_public_ipv4.setGenerateIntermediateEvents( false );
param_public_ipv6.setGenerateIntermediateEvents( false );
param_host.setGenerateIntermediateEvents( false );
ParameterListener change_listener =
new ParameterListener()
{
public void
parameterChanged(
Parameter param )
{
updateNeeded();
if ( param == param_enable ){
fireChanged();
}
}
};
param_enable.addListener( change_listener );
param_e_enable.addListener( change_listener );
param_public_ipv4.addListener( change_listener );
param_public_ipv6.addListener( change_listener );
param_local_ipv4.addListener( change_listener );
param_local_ipv6.addListener( change_listener );
param_host.addListener( change_listener );
param_e_enable.addEnabledOnSelection( param_public_ipv4 );
param_e_enable.addEnabledOnSelection( param_public_ipv6 );
param_e_enable.addEnabledOnSelection( param_local_ipv4 );
param_e_enable.addEnabledOnSelection( param_local_ipv6 );
param_e_enable.addEnabledOnSelection( param_host );
configModel.createGroup(
"pairing.group.explicit",
new Parameter[]{
param_e_info,
param_e_enable,
param_public_ipv4,