1818import java .awt .event .WindowListener ;
1919import java .util .ArrayList ;
2020import java .util .HashMap ;
21+
22+ import org .json .JSONObject ;
2123import org .slf4j .Logger ;
2224import org .slf4j .LoggerFactory ;
2325
@@ -72,6 +74,7 @@ public class OpenFinDesktopDemo extends JPanel implements ActionListener, Window
7274 InterApplicationBus bus ;
7375
7476 protected DesktopConnection desktopConnection ;
77+ protected RuntimeConfiguration runtimeConfiguration ;
7578 protected int desktopPort = -1 ; // if set, assuming Runtime is already running on the port
7679 protected System openfinSystem ;
7780 protected AppCreateDialog appCreateDialog ;
@@ -95,6 +98,7 @@ public OpenFinDesktopDemo() {
9598 }
9699
97100 private void initDesktopConnection () throws DesktopException {
101+ this .runtimeConfiguration = new RuntimeConfiguration ();
98102 if (java .lang .System .getProperty ("com.openfin.demo.port" ) != null ) {
99103 this .desktopPort = Integer .parseInt (java .lang .System .getProperty ("com.openfin.demo.port" ));
100104 }
@@ -109,10 +113,26 @@ private void initDesktopConnection() throws DesktopException {
109113 }
110114 if (securityRealm != null ) {
111115 this .desktopConnection .setRuntimeSecurityRealm (securityRealm );
116+ this .runtimeConfiguration .setSecurityRealm (securityRealm );
117+ }
118+ String desktopVersion = java .lang .System .getProperty ("com.openfin.demo.version" );
119+ if (desktopVersion == null ) {
120+ desktopVersion = "stable" ;
121+ }
122+ this .runtimeConfiguration .setRuntimeVersion (desktopVersion );
123+ String rvmArgs = java .lang .System .getProperty ("com.openfin.demo.rvm.arguments" );
124+ if (rvmArgs != null ) {
125+ updateMessagePanel ("Additional RVM arguments: " + rvmArgs );
126+ this .runtimeConfiguration .setAdditionalRvmArguments (rvmArgs );
112127 }
113- this .desktopConnection .setRdmUrl (java .lang .System .getProperty ("com.openfin.demo.rdmURL" ));
114- this .desktopConnection .setRuntimeAssetsUrl (java .lang .System .getProperty ("com.openfin.demo.assetsURL" ));
115- this .desktopConnection .setAdditionalRuntimeArguments ("--v=1" ); // enable additional logging
128+ this .runtimeConfiguration .setRdmURL (java .lang .System .getProperty ("com.openfin.demo.rdmURL" ));
129+ this .runtimeConfiguration .setRuntimeAssetURL (java .lang .System .getProperty ("com.openfin.demo.assetsURL" ));
130+ this .runtimeConfiguration .setAdditionalRuntimeArguments ("--v=1" ); // enable additional logging
131+ this .runtimeConfiguration .setDevToolsPort (9090 );
132+ JSONObject myconfig = new JSONObject ();
133+ myconfig .put ("key1" , "value1" );
134+ myconfig .put ("PI" , 3.14 );
135+ this .runtimeConfiguration .addConfigurationItem ("myconfig" , myconfig );
116136 }
117137
118138 private JPanel layoutLeftPanel () {
@@ -381,7 +401,8 @@ public void run() {
381401 private void closeDesktop () {
382402 if (desktopConnection != null && desktopConnection .isConnected ()) {
383403 try {
384- new System (desktopConnection ).exit ();
404+ // new System(desktopConnection).exit();
405+ this .desktopConnection .disconnect ();
385406// Application app = Application.wrap(this.startupUUID, this.desktopConnection);
386407// app.close();
387408 setMainButtonsEnabled (false );
@@ -495,22 +516,8 @@ public void onOutgoingMessage(String message) {
495516 updateMessagePanel ("Connecting to Runtime already running at port " + this .desktopPort );
496517 desktopConnection .connect (listener );
497518 } else {
498- String desktopVersion = java .lang .System .getProperty ("com.openfin.demo.version" );
499- if (desktopVersion == null ) {
500- desktopVersion = "stable" ;
501- }
502- String rvmArgs = java .lang .System .getProperty ("com.openfin.demo.rvm.arguments" );
503- if (rvmArgs != null ) {
504- updateMessagePanel ("Additional RVM arguments: " + rvmArgs );
505- desktopConnection .setAdditionalRvmArguments (rvmArgs );
506- }
507- String securityRealm = java .lang .System .getProperty ("com.openfin.demo.securityRealm" );
508- if (securityRealm != null ) {
509- java .lang .System .out .println (String .format ("Using security realm %s" , securityRealm ));
510- desktopConnection .setRuntimeSecurityRealm (securityRealm );
511- }
512- updateMessagePanel ("Connecting to version " + desktopVersion );
513- desktopConnection .connectToVersion (desktopVersion , listener , 10000 );
519+ updateMessagePanel ("Connecting to version " + this .runtimeConfiguration .getRuntimeVersion ());
520+ desktopConnection .connect (this .runtimeConfiguration , listener , 10000 );
514521 }
515522 } catch (Exception ex ) {
516523 ex .printStackTrace ();
@@ -720,6 +727,7 @@ public void onError(Ack ack) {
720727
721728 @ Override
722729 public void onError (Ack ack ) {
730+ java .lang .System .out .println (String .format ("Error creating application: %s" , ack .getReason ()));
723731 }
724732 });
725733 this .applicationList .put (options .getUUID (), app );
0 commit comments