AbstractSettingsApplication.st
changeset 4724 57b61d7d19ad
parent 4718 05f2668bebad
child 4726 8d022e0a5389
--- a/AbstractSettingsApplication.st	Wed Mar 26 16:03:56 2003 +0100
+++ b/AbstractSettingsApplication.st	Wed Mar 26 18:16:49 2003 +0100
@@ -68,6 +68,14 @@
 	privateIn:AbstractSettingsApplication
 !
 
+AbstractSettingsApplication subclass:#HTTPStartServerSettingsApplication
+	instanceVariableNames:'portNumberChannel informationLabel hasNoCreatedServerChannel
+		hasCreatedServerChannel'
+	classVariableNames:''
+	poolDictionaries:''
+	privateIn:AbstractSettingsApplication
+!
+
 AbstractSettingsApplication subclass:#KbdMappingSettingsAppl
 	instanceVariableNames:'selectedRawKey macroTextHolder selectedFunctionKey
 		labelTextHolder functionKeyList rawKeyList mappings'
@@ -3056,6 +3064,404 @@
     )
 ! !
 
+!AbstractSettingsApplication::HTTPStartServerSettingsApplication class methodsFor:'documentation'!
+
+version
+    ^ '$Header: /cvs/stx/stx/libtool/AbstractSettingsApplication.st,v 1.41 2003-03-26 17:16:49 cg Exp $'
+! !
+
+!AbstractSettingsApplication::HTTPStartServerSettingsApplication class methodsFor:'image specs'!
+
+defaultIcon
+    "This resource specification was automatically generated
+     by the ImageEditor of ST/X."
+
+    "Do not manually edit this!! If it is corrupted,
+     the ImageEditor may not be able to read the specification."
+
+    "
+     self defaultIcon inspect
+     ImageEditor openOnClass:self andSelector:#defaultIcon
+     Icon flushCachedIcons
+    "
+
+    <resource: #image>
+
+    ^Icon
+        constantNamed:#'HTTPStartServerSettingsApplication class defaultIcon'
+        ifAbsentPut:[(Depth8Image new) width: 22; height: 22; photometric:(#palette); bitsPerSample:(#(8 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'
+@@@@@HQ-M!!T6M&5-\@@@@@@@@@@@@@@@@GT4HB,1DS$9NUQ0@@@@@@@@@@@@@F<3JP\MG X9NSL9RG@@@@@@@@@@@GT2GQ\C@0LIJ%L3O11J\@@@@@@@(XP4
+LA$C@0LCAA<''F"8,F4V3@KT@+0A-JCD]@0LCNT-MSEAPS49V$7L@@@@@MQ@XFPLCNE!!XVE!!XVE!!XVE!!X@@@@@AT$APLC@5"9-K6?1LSD1LFJQ@@@@@@KEBT&
+CPMX**R-+Z2+(JZX\DP@@@@@@RL1LR,NVJ8:.K"7-%&I%GAD@@@@@D$OK3D1HU"[%IRT%IRT%I]0Q@@@@@A=@!!L1KQYX*J"(*J"(.8:T\DP@@@@@)THRLQ$C
+VJ"(*J"(*IBO%''AD@@@@@@B:P2HL@5"K"8.K"8.K"8M0Q@@@@@@@@J]FB@MX0K0:N#(:N,B2\DP@@@@@@@@@,T\;VJ#B0<OC0<N>&GAD@@@@@@@@@@@@*U"(
+0<OC0<OC0I!!0Q@@@@@@@@@@@@@AX*LU<#HVF$,BX\DP@@@@@@@@@@@@@VJ#C@@@@@@CC&GAD@@@@@@@@@@@@@E"(''92\''I2\(9!!0Q@@@@@@@@@@@@@AX*IVO
+#8>O#9*X\DP@@@@@@@@@@@@@VJ!!>&Y:B"I:M&GAD@@@@@@@a') ; colorMapFromArray:#[0 0 0 0 0 80 0 0 159 0 0 255 0 2 253 0 7 248 0 8 235 0 8 247 0 14 223 0 16 239 0 20 55 0 20 60 0 32 223 0 35 220 0 47 207 0 50 205 0 60 195 0 64 175 0 64 181 0 64 191 0 74 181 0 80 0 0 87 167 0 90 164 0 92 163 0 97 157 0 102 142 0 103 133 0 107 112 0 111 143 0 114 140 0 115 139 0 127 79 0 127 127 0 150 76 0 159 95 0 165 89 0 184 71 0 191 64 0 200 33 0 207 0 0 208 45 0 213 0 0 225 30 0 235 20 0 240 15 0 243 0 0 244 11 0 245 8 0 255 0 6 132 42 6 168 6 10 149 10 17 41 72 17 96 17 25 25 25 25 25 232 28 28 227 30 30 30 33 32 152 35 35 35 35 35 133 40 40 40 42 131 42 45 45 45 50 50 50 51 51 111 51 55 105 52 52 52 54 60 76 54 116 54 60 60 88 60 60 103 62 61 141 62 62 125 65 64 193 65 104 153 65 112 145 65 136 121 65 160 97 65 192 65 68 68 68 71 111 71 76 121 76 77 76 205 80 80 80 85 100 85 95 95 95 97 97 97 98 207 98 103 103 103 104 104 104 107 105 186 107 106 235 109 108 236 109 109 109 111 109 147 111 111 111 111 111 255 114 113 162 114 114 210 116 116 116 117 117 117 118 116 165 118 117 245 118 118 118 119 117 158 119 119 119 120 120 120 120 159 120 127 127 127 130 146 130 131 129 131 132 131 191 135 135 135 136 135 136 138 138 246 142 142 142 143 143 143 143 143 255 147 145 147 147 146 174 147 146 227 150 148 230 151 149 151 151 151 151 153 150 153 155 153 155 156 154 156 156 155 240 157 156 157 159 157 86 159 159 159 162 160 162 162 161 162 162 162 242 163 161 163 164 163 164 165 164 165 166 164 76 166 164 166 168 165 168 168 166 168 172 169 172 173 170 173 173 171 222 174 172 174 175 174 175 176 173 176 178 175 178 181 178 181 182 179 182 184 181 184 184 182 184 186 183 186 187 184 187 187 187 251 188 186 188 189 188 189 189 188 237 189 197 189 190 190 190 191 189 191 192 191 220 194 192 194 194 194 194 195 193 195 196 196 196 197 194 197 197 197 197 198 195 198 200 191 194 200 192 195 200 197 200 201 199 201 202 202 202 203 202 203 204 204 204 205 203 205 206 206 206 207 204 207 207 207 207 208 147 148 208 157 158 208 207 208 211 208 211 211 211 211 214 213 214 215 213 224 217 215 217 218 217 218 219 217 219 222 220 222 223 222 223 224 223 229 228 227 236 229 228 229 233 232 233]; mask:((ImageMask new) width: 22; height: 22; photometric:(#blackIs0); bitsPerSample:(#(1 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'C? @G?0@O?8@_?<D??>(???@???@???@???@???@???@???@???@_??@O??@G??@A??@@??@@??@@??@@??@@??@') ; yourself); yourself]
+! !
+
+!AbstractSettingsApplication::HTTPStartServerSettingsApplication class methodsFor:'interface specs'!
+
+windowSpec
+    "This resource specification was automatically generated
+     by the UIPainter of ST/X."
+
+    "Do not manually edit this!! If it is corrupted,
+     the UIPainter may not be able to read the specification."
+
+    "
+     UIPainter new openOnClass:HTTPStartServerSettingsApplication andSelector:#windowSpec
+     HTTPStartServerSettingsApplication new openInterface:#windowSpec
+     HTTPStartServerSettingsApplication open
+    "
+
+    <resource: #canvas>
+
+    ^ 
+     #(#FullSpec
+        #name: #windowSpec
+        #window: 
+       #(#WindowSpec
+          #label: 'HTTP Server Settings'
+          #name: 'HTTP Server Settings'
+          #min: #(#Point 10 10)
+          #max: #(#Point 2048 1024)
+          #bounds: #(#Rectangle 16 42 555 672)
+        )
+        #component: 
+       #(#SpecCollection
+          #collection: #(
+           #(#VerticalPanelViewSpec
+              #name: 'VerticalPanel1'
+              #layout: #(#LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0)
+              #horizontalLayout: #fit
+              #verticalLayout: #top
+              #horizontalSpace: 3
+              #verticalSpace: 3
+              #component: 
+             #(#SpecCollection
+                #collection: #(
+                 #(#VerticalPanelViewSpec
+                    #name: 'VerticalPanel4'
+                    #horizontalLayout: #fit
+                    #verticalLayout: #topSpace
+                    #horizontalSpace: 3
+                    #verticalSpace: 3
+                    #component: 
+                   #(#SpecCollection
+                      #collection: #(
+                       #(#ViewSpec
+                          #name: 'Box19'
+                          #component: 
+                         #(#SpecCollection
+                            #collection: #(
+                             #(#LabelSpec
+                                #label: 'Label'
+                                #name: 'Label2'
+                                #layout: #(#LayoutFrame 5 0.0 0 0.0 -5 1 0 1.0)
+                                #translateLabel: true
+                                #labelChannel: #informationLabel
+                                #adjust: #left
+                              )
+                             )
+                           
+                          )
+                          #extent: #(#Point 539 95)
+                        )
+                       #(#ViewSpec
+                          #name: 'Box18'
+                          #component: 
+                         #(#SpecCollection
+                            #collection: #(
+                             #(#LabelSpec
+                                #label: 'Port:'
+                                #name: 'Label1'
+                                #layout: #(#LayoutFrame 0 0 0 0 140 0 22 0)
+                                #translateLabel: true
+                                #adjust: #right
+                              )
+                             #(#InputFieldSpec
+                                #name: 'EntryField1'
+                                #layout: #(#LayoutFrame 150 0 0 0 210 0 22 0)
+                                #model: #portNumberChannel
+                                #type: #number
+                                #acceptOnReturn: true
+                                #acceptOnTab: true
+                                #acceptOnLostFocus: true
+                                #acceptOnPointerLeave: false
+                              )
+                             )
+                           
+                          )
+                          #extent: #(#Point 539 20)
+                        )
+                       #(#ViewSpec
+                          #name: 'Box17'
+                          #component: 
+                         #(#SpecCollection
+                            #collection: #(
+                             #(#ActionButtonSpec
+                                #label: 'Create new HTTP Server'
+                                #name: 'Button4'
+                                #layout: #(#LayoutFrame 5 0 20 0 -5 1 42 0)
+                                #translateLabel: true
+                                #model: #createServer
+                              )
+                             #(#ActionButtonSpec
+                                #label: 'Remove all HTTP Server'
+                                #name: 'Button5'
+                                #layout: #(#LayoutFrame 5 0 51 0 -5 1 73 0)
+                                #translateLabel: true
+                                #model: #removeAllServer
+                                #enableChannel: #hasCreatedServerChannel
+                              )
+                             )
+                           
+                          )
+                          #extent: #(#Point 539 90)
+                        )
+                       )
+                     
+                    )
+                    #extent: #(#Point 539 620)
+                  )
+                 )
+               
+              )
+            )
+           )
+         
+        )
+      )
+! !
+
+!AbstractSettingsApplication::HTTPStartServerSettingsApplication methodsFor:'actions'!
+
+basicSaveSettings
+
+    ^ self
+!
+
+createServer
+
+    | newServer port runningServers|
+
+    port := self portNumberChannel value.
+    runningServers := HTTPServer runningServers.
+    runningServers notEmpty ifTrue:[
+        runningServers do:[:aServer |
+            aServer port = port asInteger ifTrue:[
+                Dialog warn:'There is already a Server for port ', port asString.
+                ^ self
+            ]
+        ]
+    ].
+    self withWaitCursorDo:[
+        newServer := HTTPServer new.
+        newServer setParametersToDefault.
+        newServer port:port.
+        self createServerApplication:newServer forDefault:false.
+    ]
+!
+
+createServerApplication:aServerInstance
+
+    self createServerApplication:aServerInstance forDefault:false.
+!
+
+createServerApplication:aServerInstance forDefault:isDefaultApplication
+
+
+    |settingsApp settingsAppPosition newItem openApps|
+
+    openApps := self requestor getAllChildrenAppsForApplication:self childrenClass:HTTPServerSettingsAppl.
+    ((openApps detect:[:app | app httpServerInstance == aServerInstance] ifNone:[nil]) notNil) ifTrue:[
+        " already have an Item for this application "
+        ^ self 
+    ].
+    settingsApp := HTTPServerSettingsAppl basicNew.
+    settingsApp requestor:self requestor.
+    isDefaultApplication ifTrue:[
+        settingsApp isDefaultSettingsDialog:isDefaultApplication
+    ] ifFalse:[
+        settingsApp httpServerInstance:aServerInstance.
+    ].
+    settingsApp basicInitialize.
+    settingsAppPosition := requestor getNameOfApplication:self.
+    isDefaultApplication ifTrue:[
+        settingsAppPosition := settingsAppPosition , '/HTTPServer Default Settings'.
+    ] ifFalse:[
+        settingsAppPosition := settingsAppPosition , '/HTTPServer Port ', aServerInstance port asString.
+    ].
+    newItem := requestor addApplClass:#'HTTPServerSettingsAppl' withName:settingsAppPosition.
+    newItem application:settingsApp.
+    self createdServerChanged.
+    requestor expandItemForApplication:self.
+    settingsApp initialize.
+!
+
+createServerSubApplicationsForRunningServer
+
+    |runningServers|
+
+    self createServerApplication:nil forDefault:true.
+    runningServers := HTTPServer runningServers asOrderedCollection.
+    runningServers isEmpty ifTrue:[ ^ self].
+    runningServers sort:[:a :b | a port < b port].
+    runningServers do:[:aHttpServerInstance |
+        self createServerApplication:aHttpServerInstance forDefault:false.
+    ]
+!
+
+readSettings
+
+    HTTPServer runningServers removeDependent:self.
+    HTTPServer runningServers addDependent:self.
+    self createServerSubApplicationsForRunningServer.
+    self createdServerChanged.
+    self modifiedChannel value:false.
+!
+
+removeAllServer
+
+    HTTPServer terminateAllServers.
+    self removeAllServerSubApplications.
+    self createdServerChanged.
+!
+
+removeAllServerSubApplications
+
+    |apps|
+
+    apps := requestor getApplicationsByClass:HTTPServerSettingsAppl.
+    apps do:[:aApp |
+        aApp isDefaultSettingsDialog ifFalse:[
+            requestor removeByApplication:aApp.
+        ]
+    ].
+!
+
+setPortOnFreePort
+
+    | createdServer |
+    createdServer := (self requestor getAllChildrenAppsForApplication:self childrenClass:HTTPServerSettingsAppl) collect:[:setApp |
+        setApp httpServerInstance.
+    ].
+    createdServer size = 1 ifTrue:[
+        self portNumberChannel value:(HTTPServer defaultPort).
+        ^ self
+    ].
+    self portNumberChannel value:0.
+    createdServer do:[:aHttpServer |
+        (aHttpServer notNil and:[aHttpServer port >= (self portNumberChannel value asInteger)]) ifTrue:[
+            self portNumberChannel value:(aHttpServer port + 1).
+        ].
+    ]
+! !
+
+!AbstractSettingsApplication::HTTPStartServerSettingsApplication methodsFor:'aspects'!
+
+hasCreatedServerChannel
+    "automatically generated by UIPainter ..."
+
+    "*** the code below creates a default model when invoked."
+    "*** (which may not be the one you wanted)"
+    "*** Please change as required and accept it in the browser."
+    "*** (and replace this comment by something more useful ;-)"
+
+    hasCreatedServerChannel isNil ifTrue:[
+        hasCreatedServerChannel := true asValue.
+"/ if your app needs to be notified of changes, uncomment one of the lines below:
+"/       hasCreatedServerChannel addDependent:self.
+"/       hasCreatedServerChannel onChangeSend:#hasCreatedServerChannelChanged to:self.
+    ].
+    ^ hasCreatedServerChannel.
+!
+
+informationLabel
+
+    informationLabel isNil ifTrue:[
+        informationLabel := ('Create a new HTTP Server on a specific port', 
+                            Character cr, 
+                            'the default server settings are taken from the HTTPServer Default Settings',
+                            Character cr, 
+                            'entry, you can change the defaults there',
+                            Character cr, 
+                            'change and start the new Server in the new Entry created',
+                            Character cr ,
+                            'as children under this Entry of the SettingsDialog'
+                            ) asValue.
+    ].
+    ^ informationLabel.
+!
+
+portNumberChannel
+
+    portNumberChannel isNil ifTrue:[
+        portNumberChannel := ValueHolder new.
+    ].
+    ^ portNumberChannel.
+! !
+
+!AbstractSettingsApplication::HTTPStartServerSettingsApplication methodsFor:'change & update'!
+
+createdServerChanged
+
+    self hasCreatedServerChannel value:self hasCreatedServer.
+    self setPortOnFreePort.
+!
+
+runningServersChanged
+
+    |runningServers|
+
+    runningServers := HTTPServer runningServers.
+    self createServerSubApplicationsForRunningServer.
+    self setPortOnFreePort.
+!
+
+update:something with:aParameter from:changedObject
+    "Invoked when an object that I depend upon sends a change notification."
+
+    "stub code automatically generated - please change as required"
+
+
+    changedObject == HTTPServer runningServers ifTrue:[
+        self runningServersChanged.
+        ^ self.
+    ].
+    super update:something with:aParameter from:changedObject
+! !
+
+!AbstractSettingsApplication::HTTPStartServerSettingsApplication methodsFor:'initialization & release'!
+
+basicInitialize
+
+"/    self createServerSubApplicationsForRunningServer.
+    super basicInitialize
+!
+
+release
+
+    HTTPServer runningServers removeDependent:self.
+! !
+
+!AbstractSettingsApplication::HTTPStartServerSettingsApplication methodsFor:'queries'!
+
+hasCreatedServer
+
+    ^ ((self requestor getAllChildrenAppsForApplication:self childrenClass:HTTPServerSettingsAppl) size > 1)
+!
+
+hasUnsavedChanges
+
+    ^ false
+!
+
+help
+
+    self warn:'no help available here'.
+"/    self withWaitCursorDo:[HTMLDocumentView openFullOnHelpFile:'Launcher/compilerSettings.html'].
+! !
+
 !AbstractSettingsApplication::KbdMappingSettingsAppl class methodsFor:'image specs'!
 
 defaultIcon
@@ -10622,5 +11028,5 @@
 !AbstractSettingsApplication class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/AbstractSettingsApplication.st,v 1.40 2003-03-24 18:36:42 penk Exp $'
-! !
+    ^ '$Header: /cvs/stx/stx/libtool/AbstractSettingsApplication.st,v 1.41 2003-03-26 17:16:49 cg Exp $'
+! !