Class: KeyPathMonitor

Inherits:
Object
  • Object
show all
Defined in:
lib/fxmlloader/j8_expression_value.rb

Defined Under Namespace

Classes: ChangeListenerImpl, ListChangeImpl, MapChangeImpl

Instance Method Summary collapse

Constructor Details

#initialize(this, keyPathIterator) ⇒ KeyPathMonitor

Returns a new instance of KeyPathMonitor.



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/fxmlloader/j8_expression_value.rb', line 146

def initialize(this, keyPathIterator)
  @key = keyPathIterator.next();
  @this = this


  @listChangeListener = ListChangeImpl.new(self)


  @mapChangeListener = MapChangeImpl.new(self)


  @propertyChangeListener = ChangeListenerImpl.new(self)

  if (keyPathIterator.hasNext())
    @next = KeyPathMonitor.new(this, keyPathIterator);
  else
    @next = nil;
  end
end

Instance Method Details

#list_changed(change) ⇒ Object



166
167
168
169
170
171
172
173
174
175
# File 'lib/fxmlloader/j8_expression_value.rb', line 166

def list_changed(change)
  while (change.next())
    index = @key.to_i

    if (index >= change.getFrom() && index < change.getTo())
      @this.fireValueChangedEvent();
      remonitor();
    end
  end
end

#map_changed(change) ⇒ Object



177
178
179
180
181
182
# File 'lib/fxmlloader/j8_expression_value.rb', line 177

def map_changed(change)
  if (@key == (change.getKey()))
    @this.fireValueChangedEvent();
    remonitor();
  end
end

#monitor(namespace) ⇒ Object



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/fxmlloader/j8_expression_value.rb', line 192

def monitor(namespace)
  if (namespace.is_a? ObservableList)
    old_verbose = $VERBOSE
    begin
      $VERBOSE = nil
      namespace.addListener @listChangeListener
    ensure
      # always re-set to old value, even if block raises an exception
      $VERBOSE = old_verbose
    end
  elsif (namespace.is_a? ObservableMap)
    old_verbose = $VERBOSE
    begin
      $VERBOSE = nil
      namespace.addListener @mapChangeListener
    ensure
      # always re-set to old value, even if block raises an exception
      $VERBOSE = old_verbose
    end
  else
    namespaceAdapter = RubyWrapperBeanAdapter.for(namespace);
    propertyModel = namespaceAdapter.getPropertyModel(@key).to_java
    if (propertyModel != nil)
      old_verbose = $VERBOSE
      begin
        $VERBOSE = nil
        propertyModel.addListener @propertyChangeListener
      ensure
        # always re-set to old value, even if block raises an exception
        $VERBOSE = old_verbose
      end
    end

    @namespace = namespaceAdapter;
  end

  @namespace = namespace;

  if (@next != nil)
    value = Expression.get(@namespace, @key)
    if (value != nil)
      @next.monitor(value);
    end
  end
end

#normal_changed(observable, oldValue, newValue) ⇒ Object



184
185
186
187
188
189
190
# File 'lib/fxmlloader/j8_expression_value.rb', line 184

def normal_changed(observable, oldValue, newValue)
  if (@key == (observable.getName()))

    @this.fireValueChangedEvent();
    remonitor();
  end
end

#remonitorObject



280
281
282
283
284
285
286
287
288
# File 'lib/fxmlloader/j8_expression_value.rb', line 280

def remonitor()
  if (@next != nil)
    @next.unmonitor();
    value = Expression.get(@namespace, @key);
    if (value != nil)
      @next.monitor(value);
    end
  end
end

#unmonitorObject



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/fxmlloader/j8_expression_value.rb', line 238

def unmonitor()
  if (@namespace.is_a? ObservableList)
    old_verbose = $VERBOSE
    begin
      $VERBOSE = nil
      @namespace.removeListener @listChangeListener
    ensure
      # always re-set to old value, even if block raises an exception
      $VERBOSE = old_verbose
    end
  elsif (@namespace.is_a? ObservableMap)
    old_verbose = $VERBOSE
    begin
      $VERBOSE = nil
      @namespace.removeListener @mapChangeListener
    ensure
      # always re-set to old value, even if block raises an exception
      $VERBOSE = old_verbose
    end
  elsif (@namespace != nil)
    namespaceAdapter = @namespace;
    propertyModel = namespaceAdapter.getPropertyModel(@key);

    if (propertyModel != nil)
      old_verbose = $VERBOSE
      begin
        $VERBOSE = nil
        propertyModel.removeListener @propertyChangeListener
      ensure
        # always re-set to old value, even if block raises an exception
        $VERBOSE = old_verbose
      end
    end
  end

  @namespace = nil;

  if (@next != nil)
    @next.unmonitor();
  end
end