PlotTabPanel.js
6.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/**
* Project : AMDA-NG
* Name : PlotTabPanel.js
* @class amdaPlotComp.PlotTabPanel
* @extends Ext.tab.Panel
* @brief Component use to show Plot tabs definition
* @author Benjamin Renard
* @version $Id: PlotTabPanel.js benjamin $
*/
Ext.define('amdaPlotComp.PlotTabPanel', {
extend: 'Ext.tab.Panel',
requires: [
'amdaPlotComp.PlotTabContent'
],
//Link to the Plot UI
plotUI : null,
//Multiplot object
multiplot_object: null,
tabbar_destroy : false,
constructor: function(config) {
this.init(config);
this.callParent(arguments);
},
setMultiplotObject: function(multiplot_object) {
var me = this;
this.removeAll();
this.multiplot_object = multiplot_object;
this.multiplot_object.plots().each(function (rec, index) {
this.addPlotNode(rec, index == 0);
}, this);
},
reloadPlot : function(plotNode) {
for (i = 0; i < this.items.getCount(); ++i)
{
var tabItem = this.items.getAt(i);
var tabContent = tabItem.items.getAt(0);
if (plotNode == tabContent.plotNode) {
tabContent.updateUI();
}
}
},
addPlotNode: function(plotNode, selectTab)
{
for (i = 0; i < this.items.getCount(); ++i)
{
var tabItem = this.items.getAt(i);
var tabContent = tabItem.items.getAt(0);
if (plotNode == tabContent.plotNode) {
//Already opened => select tab
this.setActiveTab(tabItem);
return;
}
}
var tabNumber = this.getTabBar().items.getCount();
var tabContent = new amdaPlotComp.PlotTabContent({plotNode: plotNode, tabIndex: tabNumber-1, plotTabPanel: this});
var me = this;
var tabComp = this.add({
title: tabContent.getPlotTitle(),
closable: true,
layout: 'fit',
bodyStyle: 'background: none',
defaults: {
border: false
},
items: [
tabContent
],
listeners : {
scope : this,
beforeclose: function( tab, eOpts ) {
if (this.items.getCount() == 1)
{
myDesktopApp.warningMsg('You need to keep at least one plot definition');
return false;
}
return true;
},
close: function( tab, eOpts ) {
if (tab.items.getAt(0).plotNode) {
tab.items.getAt(0).resetModif();
this.multiplot_object.removePlotByInternalId(tab.items.getAt(0).plotNode.internalId);
}
},
destroy: function(tab, eOpts) {
if (tab.items.getAt(0) && tab.items.getAt(0).plotNode) {
tab.items.getAt(0).resetModif();
}
if (!this.tabbar_destroy)
this.updatePlotTabs();
}
}
});
if (selectTab)
this.setActiveTab(tabComp);
return tabContent;
},
duplicatePlotNode: function(plotNode)
{
var newPlotNode = this.multiplot_object.duplicatePlot(plotNode);
if (!newPlotNode)
return null;
return newPlotNode;
},
updatePlotTabs: function()
{
for (i = 0; i < this.items.getCount(); ++i)
{
var tabItem = this.items.getAt(i);
var tabContent = tabItem.items.getAt(0);
tabContent.tabIndex = i;
var plotNode = tabContent.plotNode;
var title = tabContent.getPlotTitle();
tabItem.setTitle(title);
if (!this.getActiveTab())
this.setActiveTab(tabItem);
}
},
closePlotTabIfOpened: function(plotNodeToClose) {
for (i = 0; i < this.items.getCount(); ++i)
{
var tabItem = this.items.getAt(i);
var tabContent = tabItem.items.getAt(0);
var plotNode = tabContent.plotNode;
if (plotNode == renamedNode) {
this.remove(tabItem.getId());
}
}
},
updateRequestName: function(renamedNode)
{
for (i = 0; i < this.items.getCount(); ++i)
{
var tabItem = this.items.getAt(i);
var tabContent = tabItem.items.getAt(0);
var plotNode = tabContent.plotNode;
if (plotNode == renamedNode) {
plotNode.get('object').set('name', renamedNode.get('text'));
tabContent.updateUI();
}
}
},
getCurrentPlotTabContent : function() {
if (this.getActiveTab())
return this.getActiveTab().child();
return null;
},
updateTimeObjects : function() {
for (i = 0; i < this.items.getCount(); ++i)
{
this.items.getAt(i).items.getAt(0).updateTimeObject();
}
},
getTreeFromPlotTab: function(plotTab)
{
return plotTab.child().treePlot;
},
init : function(config) {
var me = this;
this.plotUI = config.plotUI;
var myConf = {
plain: true,
bodyStyle: { background : '#dfe8f6' },
border : false,
defaults: {
border: false
},
tabBar:{
items:[
{
text:'+',
closable: false,
handler:function(btn,e){
var tabContent = me.addPlotNode(me.multiplot_object.createNewPlot(), true);
}
}
],
listeners: {
beforedestroy: function(tabbar, eOpts) {
me.tabbar_destroy = true;
}
}
}
};
Ext.apply (this , Ext.apply (arguments, myConf));
}
});