/[eiffelstudio]/branches/Eiffel_57_docking/Src/Eiffel/interface/new_graphical/commands/eb_metric_new_definition_cmd.e
ViewVC logotype

Contents of /branches/Eiffel_57_docking/Src/Eiffel/interface/new_graphical/commands/eb_metric_new_definition_cmd.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 62171 - (show annotations)
Tue Aug 1 01:27:17 2006 UTC (13 years, 6 months ago) by larryl
File size: 13552 byte(s)
First commit docking tabbed Eiffel Studio.
1 indexing
2 description: "Command to open a dialog which allows%N%
3 %composite metric definition."
4 legal: "See notice at end of class."
5 status: "See notice at end of class."
6 author: ""
7 date: "$Date$"
8 revision: "$Revision$"
9
10 class
11 EB_METRIC_NEW_DEFINITION_CMD
12
13 inherit
14 EB_METRIC_COMMAND
15
16 EB_CONSTANTS
17
18 SHARED_XML_ROUTINES
19
20 EV_KEY_CONSTANTS
21
22 create
23 make
24
25 feature -- Initialization
26
27 pixmap: EV_PIXMAP is
28 -- Pixmap representing the command.
29 do
30 Result := Pixmaps.Icon_new_metric
31 end
32
33 pixel_buffer: EV_PIXEL_BUFFER is
34 -- Pixel buffer representing the command.
35 do
36 -- Currently there is no pixel buffer for this command.
37 end
38
39 tooltip: STRING is
40 -- Tooltip for the toolbar button.
41 do
42 Result := "Define new metric formula"
43 end
44
45 description: STRING is
46 -- Description for this command.
47 do
48 Result := "New metric formula"
49 end
50
51 name: STRING is "new"
52 -- Name of the command. Used to store the command in the
53 -- preferences.
54
55 feature -- Widget
56
57 build_new_metric_definition_dialog is
58 -- Build `new_metric_definition_dialog' to define new metrics of type: derived, linear, metric ratio and scope ratio.
59 local
60 ok_button, cancel_button: EV_BUTTON
61 hb: EV_HORIZONTAL_BOX
62 vb: EV_VERTICAL_BOX
63 ev_any: EV_WIDGET
64 do
65 -- once
66 create new_metric_definition_dialog
67 new_metric_definition_dialog.set_title ("New metric formula")
68 new_metric_definition_dialog.set_icon_pixmap (pixmaps.icon_pixmaps.general_dialog_icon)
69
70 create vb
71 vb.set_padding (5)
72 vb.set_border_width (5)
73
74 create notebook
75 create derived_tab.make (Current)
76 notebook.extend (derived_tab)
77 notebook.set_item_text (derived_tab, "Derived")
78
79 create linear_tab.make (Current)
80 notebook.extend (linear_tab)
81 notebook.set_item_text (linear_tab, "Linear")
82
83 create ratio_metric_tab.make (Current)
84 notebook.extend (ratio_metric_tab)
85 notebook.set_item_text (ratio_metric_tab, "Metric Ratio")
86
87 create ratio_scope_tab.make (Current)
88 notebook.extend (ratio_scope_tab)
89 notebook.set_item_text (ratio_scope_tab, "Scope Ratio")
90
91 notebook.selection_actions.extend (agent on_tab_changed)
92 vb.extend (notebook)
93
94 -- create frame
95 -- frame.set_style ((create {EV_FRAME_CONSTANTS}).Ev_frame_lowered)
96 -- frame.set_minimum_height (50)
97 -- vb.extend (frame)
98 -- vb.disable_item_expand (frame)
99
100 create hb
101 create ok_button.make_with_text_and_action ("OK", agent ok_action)
102 ok_button.set_minimum_width (80)
103 hb.extend (create {EV_CELL})
104 hb.extend (ok_button)
105 hb.disable_item_expand (ok_button)
106
107 create save_button.make_with_text_and_action ("Save", agent save_action)
108 save_button.set_minimum_width (80)
109 create {EV_CELL} ev_any
110 ev_any.set_minimum_width (20)
111 hb.extend (ev_any)
112 hb.disable_item_expand (ev_any)
113 hb.extend (save_button)
114 hb.disable_item_expand (save_button)
115
116 create cancel_button.make_with_text_and_action ("Cancel", agent cancel_action)
117 cancel_button.set_minimum_width (80)
118 create {EV_CELL} ev_any
119 ev_any.set_minimum_width (20)
120 hb.extend (ev_any)
121 hb.disable_item_expand (ev_any)
122 hb.extend (cancel_button)
123 hb.disable_item_expand (cancel_button)
124 hb.extend (create {EV_CELL})
125
126 vb.extend (hb)
127 vb.disable_item_expand (hb)
128
129 new_metric_definition_dialog.extend (vb)
130 new_metric_definition_dialog.set_default_push_button (ok_button)
131 new_metric_definition_dialog.set_default_cancel_button (cancel_button)
132
133 ok_button.key_press_actions.extend (agent key_enter_pressed (?, ok_button))
134 save_button.key_press_actions.extend (agent key_enter_pressed (?, save_button))
135 cancel_button.key_press_actions.extend (agent key_enter_pressed (?, cancel_button))
136 is_derived := True
137 is_linear := False
138 is_metric_ratio := False
139 is_scope_ratio := False
140 tab ?= linear_tab
141 end
142
143 fill_metric_combobox (combobox: EV_COMBO_BOX)is
144 -- Fill `combobox' with all available metrics whose unit is different from ratio.
145 require
146 existing_tool: tool /= Void
147 existing_combobox: combobox /= Void
148 local
149 measure_item: EV_LIST_ITEM
150 do
151 from
152 tool.metrics.start
153 until
154 tool.metrics.after
155 loop
156 if not equal (tool.metrics.item.unit, interface_names.metric_ratio_unit) then
157 create measure_item.make_with_text (tool.metrics.item.name)
158 combobox.extend (measure_item)
159 end
160 tool.metrics.forth
161 end
162 end
163
164 feature -- Access
165
166 new_metric_definition_dialog: EV_DIALOG
167 -- Dialog to define new metrics of type: derived, linear, metric ratio and scope ratio.
168
169 notebook: EV_NOTEBOOK
170 -- Notebook containing tabs.
171
172 derived_tab: EB_METRIC_DERIVED_TAB
173 -- Tab to define derived metrics.
174
175 linear_tab: EB_METRIC_LINEAR_TAB
176 -- Tab to define linear composite metrics.
177
178 ratio_metric_tab: EB_METRIC_RATIO_TAB
179 -- Tab to define ratio composite metrics.
180
181 ratio_scope_tab: EB_METRIC_RATIO_SCOPE_TAB
182 -- Tab to define ratio composite metrics over 2 scopes.
183
184 tab: EB_METRIC_NEW_DEFINITION_TAB
185 -- Currentlu selected tab
186
187 save_button: EV_BUTTON
188 -- Button to save new metric characteristics.
189
190 valid_metric_definition: BOOLEAN
191 -- Is new metric's definition syntaxly correct?
192
193 metric_definition: XM_ELEMENT
194 -- Definition part of the newly defined metric.
195
196 is_derived: BOOLEAN
197 -- Is the new composite metric a derived one?
198
199 is_linear: BOOLEAN
200 -- Is the new composite metric a linear one?
201
202 is_metric_ratio: BOOLEAN
203 -- Is the new composite metric a ratio over metrics one?
204
205 is_scope_ratio: BOOLEAN
206 -- Is the new composite metric a ratio over scopes one?
207
208 feature -- Overwrite a metric
209
210 overwrite: BOOLEAN
211 -- Overwrite metric of same name?
212
213 set_overwrite (o: BOOLEAN) is
214 -- Assign `o' to `overwrite'.
215 do
216 overwrite := o
217 end
218
219 feature -- Edit a metric
220
221 edition: BOOLEAN
222 -- Is `new_metric_definition_dialog' displayed for editing a previously defined metric?
223
224 set_edition (e: BOOLEAN) is
225 -- Assign `e' to `edition'.
226 do
227 edition := e
228 end
229
230 feature -- Action
231
232 on_tab_changed is
233 -- Adjust attributes regarding selected tab.
234 do
235 if notebook.selected_item = derived_tab then
236 is_derived := True
237 is_linear := False
238 is_metric_ratio := False
239 is_scope_ratio := False
240 elseif notebook.selected_item = linear_tab then
241 is_derived := False
242 is_linear := True
243 is_metric_ratio := False
244 is_scope_ratio := False
245 elseif notebook.selected_item = ratio_metric_tab then
246 is_derived := False
247 is_linear := False
248 is_metric_ratio := True
249 is_scope_ratio := False
250 elseif notebook.selected_item = ratio_scope_tab then
251 is_derived := False
252 is_linear := False
253 is_metric_ratio := False
254 is_scope_ratio := True
255 end
256 tab ?= notebook.selected_item
257 if tab.saved then
258 save_button.disable_sensitive
259 else
260 save_button.enable_sensitive
261 end
262 -- tab.name_field.set_focus
263 ensure
264 tab_set: tab /= Void
265 end
266
267 ok_action is
268 -- Action to be performed on clicking on `ok_button'.
269 -- Save if anything to save and exit.
270 require
271 tab_set: tab /= Void
272 do
273 if not tab.saved and then tab.something_to_save then
274 save_action
275 if not tab.error then
276 new_metric_definition_dialog.hide
277 end
278 end
279 if not tab.something_to_save or tab.saved then
280 edition := False
281 new_metric_definition_dialog.hide
282 end
283 end
284
285 save_action is
286 -- Action to be performed on clicking on `save_button'.
287 -- Save if anything to save and do not exit.
288 require
289 tab_set: tab /= Void
290 local
291 new_metric_element: XM_ELEMENT
292 retried: BOOLEAN
293 x_pos, y_pos, index_of_metric: INTEGER
294 error_dialog: EB_INFORMATION_DIALOG
295 new_metric: EB_METRIC
296 index: INTEGER
297 do
298 x_pos := new_metric_definition_dialog.x_position + 40
299 y_pos := new_metric_definition_dialog.y_position + 80
300
301 if not retried then
302 if tab.error then
303 tab.throw_error
304 else
305 if tab.existing_name and not overwrite then
306 tab.build_confirm_dialog
307 tab.confirm_dialog.show_modal_to_window (new_metric_definition_dialog)
308 -- tab.existing_name_dialog.set_position (x_pos, y_pos)
309 -- tab.existing_name_dialog.show_modal_to_window (new_metric_definition_dialog)
310 end
311 if not tab.existing_name or overwrite then
312 if overwrite then
313 index_of_metric := tool.file_manager.index_of_metric (tab.name_field.text)
314 end
315
316 new_metric_element := tab.new_metric_element
317 new_metric := tab.new_metric
318 if tab.new_metric_successful then
319 if overwrite then
320 tool.file_manager.replace_metric (index_of_metric, new_metric_element)
321 else
322 index := index_insert (new_metric)
323 tool.file_manager.add_metric (new_metric_element, index)
324 end
325 if not tool.file_manager.metric_file.exists then
326 tool.file_manager.destroy_file_name
327 tool.set_file_loaded (False)
328 tool.file_handler.load_files
329 end
330 check tool.file_manager.metric_file.exists end
331 tool.file_manager.store
332 tool.file_manager.metric_file.close
333
334 -- Build tree formula starting from xml definition.
335 -- Notify all observers. Caution: definition part only is provided via `metric_definition'.
336 -- Update interface and create the corresponding metric object.
337 tool.file_manager.new_metric_notify_all (new_metric, new_metric_element, overwrite, index)
338
339 tab.disable_save
340 overwrite := False
341 if edition then
342 tool.manage.refresh (new_metric, new_metric_element)
343 end
344 else
345 tab.enable_save
346 create error_dialog.make_with_text ("Error in metric definition.%NSave aborted.")
347 error_dialog.set_position (x_pos, y_pos)
348 error_dialog.show_modal_to_window (new_metric_definition_dialog)
349 end
350 end
351 end
352 end
353 rescue
354 retried := True
355 create error_dialog.make_with_text ("Unable to read file:%N"
356 + tool.file_manager.metric_file_name )
357 error_dialog.set_position (x_pos, y_pos)
358 error_dialog.show_modal_to_window (new_metric_definition_dialog)
359 retry
360 end
361
362 cancel_action is
363 -- Action to be performed on clicking on `cancel_button'.
364 do
365 new_metric_definition_dialog.hide
366 edition := False
367 end
368
369 key_enter_pressed (a_key: EV_KEY; a_button: EV_BUTTON) is
370 -- On CR, call `a_button' associated action.
371 do
372 if a_key.code = Key_enter then
373 a_button.select_actions.call (Void)
374 end
375 end
376
377 index_insert (a_metric: EB_METRIC): INTEGER is
378 -- index `a_metric' should be inserted in `tool.metrics'.
379 require
380 valid_metric: a_metric /= Void
381 local
382 comp_metrics: ARRAYED_LIST [EB_METRIC]
383 sorted_list: SORTED_TWO_WAY_LIST [EB_METRIC]
384 cursor: CURSOR
385 do
386 cursor := tool.metrics.cursor
387 tool.metrics.go_i_th (tool.nb_basic_metrics + 1)
388 comp_metrics := tool.metrics.duplicate (tool.metrics.count - tool.nb_basic_metrics)
389 check tool.metrics.count = comp_metrics.count + tool.nb_basic_metrics end
390 create sorted_list.make
391 from
392 comp_metrics.start
393 until
394 comp_metrics.after
395 loop
396 sorted_list.extend (comp_metrics.item)
397 comp_metrics.forth
398 end
399 check sorted_list.count = comp_metrics.count end
400 sorted_list.extend (a_metric)
401 Result := sorted_list.index_of (a_metric, 1)
402 end
403
404 feature -- Initialization
405
406 execute is
407 -- Display `new_metric_definition_dialog' and reset all needed fields and tabs.
408 require else
409 existing_tool: tool /= Void
410 local
411 x_pos, y_pos: INTEGER
412 do
413 tool.development_window.window.set_pointer_style (tool.development_window.Wait_cursor)
414 if new_metric_definition_dialog = Void then
415 build_new_metric_definition_dialog
416 end
417 x_pos := tool.development_window.window.x_position + 200
418 y_pos := tool.development_window.window.y_position + 40
419 new_metric_definition_dialog.set_position (x_pos, y_pos)
420 derived_tab.preset
421 linear_tab.preset
422 ratio_metric_tab.preset
423 ratio_scope_tab.preset
424 tab ?= notebook.selected_item
425 -- new_metric_definition_dialog.show
426 -- tab.name_field.set_focus
427 tool.development_window.window.set_pointer_style (tool.development_window.Standard_cursor)
428 new_metric_definition_dialog.show_modal_to_window (tool.development_window.window)
429 end
430
431 indexing
432 copyright: "Copyright (c) 1984-2006, Eiffel Software"
433 license: "GPL version 2 (see http://www.eiffel.com/licensing/gpl.txt)"
434 licensing_options: "http://www.eiffel.com/licensing"
435 copying: "[
436 This file is part of Eiffel Software's Eiffel Development Environment.
437
438 Eiffel Software's Eiffel Development Environment is free
439 software; you can redistribute it and/or modify it under
440 the terms of the GNU General Public License as published
441 by the Free Software Foundation, version 2 of the License
442 (available at the URL listed under "license" above).
443
444 Eiffel Software's Eiffel Development Environment is
445 distributed in the hope that it will be useful, but
446 WITHOUT ANY WARRANTY; without even the implied warranty
447 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
448 See the GNU General Public License for more details.
449
450 You should have received a copy of the GNU General Public
451 License along with Eiffel Software's Eiffel Development
452 Environment; if not, write to the Free Software Foundation,
453 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
454 ]"
455 source: "[
456 Eiffel Software
457 356 Storke Road, Goleta, CA 93117 USA
458 Telephone 805-685-1006, Fax 805-685-6869
459 Website http://www.eiffel.com
460 Customer support http://support.eiffel.com
461 ]"
462
463 end -- class EB_METRIC_NEW_DEFINITION_CMD

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.23