otsdaq_utilities  v2_05_02_indev
Drawing.js
1 sap.ui.define([
2  'sap/ui/core/Control',
3  'sap/ui/core/ResizeHandler'
4 ], function (Control, ResizeHandler) {
5 
6  "use strict";
7 
8  return Control.extend("NavExample.Drawing", {
9 
10  metadata : {
11  // setter and getter are created behind the scenes, incl. data binding and type validation
12  properties : {
13  "file" : { type: "sap.ui.model.type.String", defaultValue: "" },
14  "item" : { type: "sap.ui.model.type.String", defaultValue: "" },
15  "drawopt" : { type: "sap.ui.model.type.String", defaultValue: "" },
16  "jsonfile" : { type: "sap.ui.model.type.String", defaultValue: "" }
17  }
18  },
19 
20  // the part creating the HTML:
21  renderer: function(oRm, oControl) { // static function, so use the given "oControl" instance instead of "this" in the renderer function
22  oRm.write("<div");
23  oRm.writeControlData(oControl); // writes the Control ID and enables event handling - important!
24  // oRm.addStyle("background-color", oControl.getColor()); // write the color property; UI5 has validated it to be a valid CSS color
25  oRm.addStyle("width", "100%");
26  oRm.addStyle("height", "100%");
27  oRm.addStyle("overflow", "hidden");
28  oRm.writeStyles();
29  oRm.writeClasses(); // this call writes the above class plus enables support for Square.addStyleClass(...)
30  oRm.write(">");
31  oRm.write("</div>"); // no text content to render; close the tag
32  },
33 
34  onBeforeRendering: function() {
35  if (this.resizeid) {
36  ResizeHandler.deregister(this.resizeid);
37  delete this.resizeid;
38  }
39  if (this.object_painter) {
40  this.object_painter.Cleanup();
41  delete this.object_painter;
42  }
43  },
44 
45  drawObject: function(obj, options, call_back) {
46  this.object = obj;
47  this.options = options;
48  JSROOT.draw(this.getDomRef(), obj, options, function(painter) {
49  this.object_painter = painter;
50  this.resizeid = ResizeHandler.register(this, painter.CheckResize.bind(painter));
51  }.bind(this));
52  },
53 
54  onAfterRendering: function() {
55  var fname = this.getFile();
56  var jsonfile = this.getJsonfile();
57  var ctrl = this;
58 
59  if (this.object) {
60  // object was already loaded
61  this.drawObject(this.object, this.options);
62  } else if (jsonfile) {
63  JSROOT.NewHttpRequest(jsonfile, 'object', function(obj) {
64  ctrl.drawObject(obj, ctrl.getDrawopt());
65  }).send();
66  } else if (fname) {
67  JSROOT.OpenFile(fname, function(file) {
68  file.ReadObject(ctrl.getItem(), function(obj) {
69  ctrl.drawObject(obj, ctrl.getDrawopt());
70  });
71  });
72  }
73  },
74 
75  getPainter: function() {
76  return this.object_painter;
77  }
78 
79  });
80 
81 });