Extra header added to the list
[u/mrichter/AliRoot.git] / EVE / EveBase / AliEveFileDialog.cxx
CommitLineData
2e29a658 1#include <TGLabel.h>
2#include <TGComboBox.h>
3#include <TGButton.h>
4#include <TG3DLine.h>
5#include <TGTextEntry.h>
6#include <TMath.h>
be736e6d 7#include <TSystem.h>
2e29a658 8
9#include <TGFileDialog.h>
10
11#include "AliEveUtil.h"
12#include "AliEveFileDialog.h"
13
14ClassImp(AliEveFileDialog)
15
16AliEveFileDialog::AliEveFileDialog(const TGWindow* p,const TGWindow* main, EAliEveFileDialogMode mode)
be736e6d 17 : TGTransientFrame(p, main, 100,50, kVerticalFrame),
18 fESDFilesFrame(0),
19 fAdvancedOptsButton(0),
20 fAdvancedOptsFrame(0),
21 fESDfriendFilesFrame(0),
22 fAODFilesFrame(0),
23 fAODfriendFilesFrame(0),
24 fRawFilesFrame(0),
25 fUrlFrame(0),
26 fCDBFrame(0),
27 fDialogButtonsFrame(0),
28 fPathEntryESD(0),
29 fPathEntryESDfriend(0),
30 fPathEntryAOD(0),
31 fPathEntryAODfriend(0),
32 fPathEntryRawFile(0),
33 fPathEntryUrl(0),
34 fCDBPathCB(0),
35 fIsAccepted(kFALSE),
36 fMode(mode)
2e29a658 37{
38 SetCleanup(kDeepCleanup);
39
40 /************************
41 *** Local Files Frame ***
42 *************************/
43 //ESD Frame
44 fESDFilesFrame = new TGHorizontalFrame(this, 100, 100);
45 TGLabel* esdLabel = new TGLabel(fESDFilesFrame, "ESD File:");
46 esdLabel->Resize(110, esdLabel->GetDefaultHeight());
47 esdLabel->SetMargins(0,0,0,0);
48
49 fPathEntryESD= new TGTextEntry(fESDFilesFrame);
50 fPathEntryESD->Resize(250, fPathEntryESD->GetDefaultHeight());
51
52 TGTextButton* browseButtonESD = new TGTextButton(fESDFilesFrame, "Browse...");
53 browseButtonESD->Connect("Clicked()", "AliEveFileDialog", this, "onBrowseESDFile()");
54
55 fESDFilesFrame->AddFrame(esdLabel, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 3, 3, 3));
56 fESDFilesFrame->AddFrame(fPathEntryESD, new TGLayoutHints(kLHintsExpandX, 3, 3, 3, 3));
57 fESDFilesFrame->AddFrame(browseButtonESD, new TGLayoutHints(kLHintsNormal, 3, 3, 3, 3));
58
59 AddFrame(fESDFilesFrame, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 3, 3, 3, 3));
be736e6d 60
61 //Advanced Options Button
62 fAdvancedOptsButton = new TGCheckButton(this, "Advanced Options");
2e29a658 63 fAdvancedOptsButton->Connect("Toggled(Bool_t)", "AliEveFileDialog", this, "showAdvancedOpts(Bool_t)");
64
be736e6d 65 AddFrame(fAdvancedOptsButton,new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 3, 3, 3, 3));
66
67//Advanced Options Frame
68 //ESDfriend Frame
69 fAdvancedOptsFrame = new TGGroupFrame(this, "Advanced Options");
70
71 fESDfriendFilesFrame = new TGHorizontalFrame(fAdvancedOptsFrame, 100, 100);
72 TGLabel* esdFriendLabel = new TGLabel(fESDfriendFilesFrame, "ESDfriend File:");
73 esdFriendLabel->Resize(110, esdFriendLabel->GetDefaultHeight());
74 esdFriendLabel->SetMargins(0,0,0,0);
75
76 fPathEntryESDfriend= new TGTextEntry(fESDfriendFilesFrame);
77 fPathEntryESDfriend->Resize(250, fPathEntryESDfriend->GetDefaultHeight());
2e29a658 78
be736e6d 79 TGTextButton* browseButtonESDfriend = new TGTextButton(fESDfriendFilesFrame, "Browse...");
80 browseButtonESDfriend->Connect("Clicked()", "AliEveFileDialog", this, "onBrowseESDfriendFile()");
2e29a658 81
be736e6d 82 fESDfriendFilesFrame->AddFrame(esdFriendLabel, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 3, 3, 3));
83 fESDfriendFilesFrame->AddFrame(fPathEntryESDfriend, new TGLayoutHints(kLHintsExpandX, 3, 3, 3, 3));
84 fESDfriendFilesFrame->AddFrame(browseButtonESDfriend, new TGLayoutHints(kLHintsNormal, 3, 3, 3, 3));
85
86 fAdvancedOptsFrame->AddFrame(fESDfriendFilesFrame, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 3, 3, 3, 3));
87
2e29a658 88 // AOD Frame
be736e6d 89 fAODFilesFrame = new TGHorizontalFrame(fAdvancedOptsFrame, 100, 100);
2e29a658 90 TGLabel* aodLabel = new TGLabel(fAODFilesFrame, "AOD File:");
91 aodLabel->Resize(110, aodLabel->GetDefaultHeight());
92
93 fPathEntryAOD = new TGTextEntry(fAODFilesFrame);
94 fPathEntryAOD->Resize(250, fPathEntryAOD->GetDefaultHeight());
95
96 TGTextButton* browseButtonAOD = new TGTextButton(fAODFilesFrame, "Browse...");
97 browseButtonAOD->Connect("Clicked()", "AliEveFileDialog", this, "onBrowseAODFile()");
98
99 fAODFilesFrame->AddFrame(aodLabel, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 3, 3, 3));
100 fAODFilesFrame->AddFrame(fPathEntryAOD, new TGLayoutHints(kLHintsExpandX, 3, 3, 3, 3));
101 fAODFilesFrame->AddFrame(browseButtonAOD, new TGLayoutHints(kLHintsNormal, 3, 3, 3, 3));
102
be736e6d 103 fAdvancedOptsFrame->AddFrame(fAODFilesFrame, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 3, 3, 3, 3));
2e29a658 104
105 // AODfriend Frame
be736e6d 106 fAODfriendFilesFrame = new TGHorizontalFrame(fAdvancedOptsFrame, 100, 100);
2e29a658 107 TGLabel* aodFriendLabel = new TGLabel(fAODfriendFilesFrame, "AODfriend File:");
108 aodFriendLabel->Resize(110, aodFriendLabel->GetDefaultHeight());
109
110 fPathEntryAODfriend = new TGTextEntry(fAODfriendFilesFrame);
111 fPathEntryAODfriend->Resize(250, fPathEntryAODfriend->GetDefaultHeight());
112
113 TGTextButton* browseButtonAODfriend = new TGTextButton(fAODfriendFilesFrame, "Browse...");
114 browseButtonAODfriend->Connect("Clicked()", "AliEveFileDialog", this, "onBrowseAODfriendFile()");
115
116 fAODfriendFilesFrame->AddFrame(aodFriendLabel, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 3, 3, 3));
117 fAODfriendFilesFrame->AddFrame(fPathEntryAODfriend, new TGLayoutHints(kLHintsExpandX, 3, 3, 3, 3));
118 fAODfriendFilesFrame->AddFrame(browseButtonAODfriend, new TGLayoutHints(kLHintsNormal, 3, 3, 3, 3));
119
be736e6d 120 fAdvancedOptsFrame->AddFrame(fAODfriendFilesFrame, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 3, 3, 3, 3));
2e29a658 121
122 // Raw Frame
be736e6d 123 fRawFilesFrame = new TGHorizontalFrame(fAdvancedOptsFrame, 100, 100);
2e29a658 124 TGLabel* rawLabel = new TGLabel(fRawFilesFrame, "Raw File:");
125 rawLabel->Resize(110, rawLabel->GetDefaultHeight());
126
127 fPathEntryRawFile = new TGTextEntry(fRawFilesFrame);
128 fPathEntryRawFile->Resize(250, fPathEntryRawFile->GetDefaultHeight());
129
130 TGTextButton* browseButtonRawFile = new TGTextButton(fRawFilesFrame, "Browse...");
131 browseButtonRawFile->Connect("Clicked()", "AliEveFileDialog", this, "onBrowseRawFile()");
132
133 fRawFilesFrame->AddFrame(rawLabel, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 3, 3, 3));
134 fRawFilesFrame->AddFrame(fPathEntryRawFile, new TGLayoutHints(kLHintsExpandX, 3, 3, 3, 3));
135 fRawFilesFrame->AddFrame(browseButtonRawFile, new TGLayoutHints(kLHintsNormal, 3, 3, 3, 3));
136
be736e6d 137 fAdvancedOptsFrame->AddFrame(fRawFilesFrame, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 3, 3, 3, 3));
2e29a658 138
be736e6d 139 AddFrame(fAdvancedOptsFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 3, 3, 3, 3) );
2e29a658 140
be736e6d 141 /****************
2e29a658 142 *** Url Frame ***
143 *****************/
144 fUrlFrame = new TGHorizontalFrame(this, 100, 100);
145 TGLabel* urlLabel = new TGLabel(fUrlFrame, "Url:");
146 urlLabel->Resize(110, urlLabel->GetDefaultHeight());
147
148 fPathEntryUrl= new TGTextEntry(fUrlFrame, "alien:///alice/");
149 fPathEntryUrl->Resize(250, fPathEntryUrl->GetDefaultHeight());
150
151 fUrlFrame->AddFrame(urlLabel, new TGLayoutHints(kLHintsLeft | kLHintsCenterY , 3, 3, 3, 3));
152 fUrlFrame->AddFrame(fPathEntryUrl, new TGLayoutHints(kLHintsExpandX, 3, 3, 3, 3));
153
154 AddFrame(fUrlFrame, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 3, 3, 3, 3));
155
156 /****************
157 *** CDB Frame ***
158 *****************/
159 fCDBFrame = new TGHorizontalFrame(this, 100, 100);
160 TGLabel *cdbLabel = new TGLabel(fCDBFrame, "CDB Storage:");
161 fCDBPathCB = new TGComboBox(fCDBFrame);
162 fCDBPathCB->SetEditable(kFALSE);
163
164 fCDBPathCB->AddEntry("local", AliEveUtil::CDB_LOCAL);
165 fCDBPathCB->AddEntry("raw", AliEveUtil::CDB_RAW);
166 fCDBPathCB->AddEntry("mcideal", AliEveUtil::CDB_MCIDEAL);
167 fCDBPathCB->AddEntry("mcresidual", AliEveUtil::CDB_MCRESIDUAL);
168 fCDBPathCB->AddEntry("mcfull", AliEveUtil::CDB_MCFULL);
169
170 fCDBPathCB->Resize(100, fPathEntryESD->GetDefaultHeight());
171 fCDBPathCB->Select(0, kTRUE);
172
173 fCDBFrame->AddFrame(cdbLabel, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 3, 3, 3) );
174 fCDBFrame->AddFrame(fCDBPathCB, new TGLayoutHints(kLHintsNormal | kLHintsCenterY, 3, 3, 3, 3) );
175
176 AddFrame(fCDBFrame, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 3, 3, 3, 3) );
177
178 /***************************
179 *** Dialog Buttons Frame ***
180 ****************************/
181 fDialogButtonsFrame = new TGHorizontalFrame(this, 100, 100);
182
183 TGTextButton* okButton = new TGTextButton(fDialogButtonsFrame, "OK");
184 okButton->Associate(this);
185 okButton->Resize(50, okButton->GetDefaultHeight());
186 okButton->Connect("Clicked()", "AliEveFileDialog", this, "onAccept()");
187
188 TGTextButton* cancelButton = new TGTextButton(fDialogButtonsFrame, "Cancel");
189 okButton->Associate(this);
190 cancelButton->Connect("Clicked()", "AliEveFileDialog", this, "onReject()");
191 cancelButton->Resize(50, cancelButton->GetDefaultHeight());
192
193 fDialogButtonsFrame->AddFrame(new TGHorizontal3DLine, new TGLayoutHints(kLHintsExpandX, 3, 3, 3, 3));
194 fDialogButtonsFrame->AddFrame(okButton, new TGLayoutHints(kLHintsExpandX | kLHintsCenterY, 3, 3, 3, 3));
195 fDialogButtonsFrame->AddFrame(cancelButton,new TGLayoutHints(kLHintsExpandX | kLHintsCenterY, 3, 3, 3, 3));
196
197 AddFrame(fDialogButtonsFrame, new TGLayoutHints(kLHintsNormal | kLHintsExpandX , 3, 3, 3, 3) );
198
199 setMode(mode);
200
201 TGDimension size = GetDefaultSize();
202
203 Resize(size);
204 SetWindowName("Open File...");
205
206 Layout();
207 HideFrame(this);
208 UnmapWindow();
209}
210
211AliEveFileDialog::~AliEveFileDialog()
212{
213
214}
215
216const TString AliEveFileDialog::GetPathESD() const
217{
218 return TString(fPathEntryESD->GetText());
219}
220
be736e6d 221const TString AliEveFileDialog::GetPathESDfriend() const
222{
223 return TString(fPathEntryESDfriend->GetText());
224}
225
2e29a658 226const TString AliEveFileDialog::GetPathAOD() const
227{
228 return TString(fPathEntryAOD->GetText());
229}
230
231const TString AliEveFileDialog::GetPathAODfriend() const
232{
233 return TString(fPathEntryAODfriend->GetText());
234}
235
236const TString AliEveFileDialog::GetPathRaw() const
237{
238 return TString(fPathEntryRawFile->GetText());
239}
240
241const TString AliEveFileDialog::GetUrl() const
242{
243 return TString(fPathEntryUrl->GetText());
244}
245
246const TString AliEveFileDialog::GetCDBStoragePath() const
247{
248 TString cdbSelected;
249
250 switch(fCDBPathCB->GetSelected()){
251 case AliEveUtil::CDB_LOCAL:
252 cdbSelected = "local://";
253 break;
254 case AliEveUtil::CDB_MCFULL:
255 cdbSelected = "mcfull://";
256 break;
257 case AliEveUtil::CDB_MCIDEAL:
258 cdbSelected = "mcideal://";
259 break;
260 case AliEveUtil::CDB_MCRESIDUAL:
261 cdbSelected = "mcresidual://";
262 break;
263 case AliEveUtil::CDB_RAW:
264 cdbSelected = "raw://";
265 break;
266 default:
267 cdbSelected= "local://";
268 }
269
270
271 return cdbSelected;
272}
273
274void AliEveFileDialog::onBrowseESDFile()
275{
276 TGFileInfo* fileInfo = new TGFileInfo;
277
278 const char* types[] = { "ALICE ESD file", "*.root",
279 "ROOT Archive", "*.zip",
280 0, 0};
281
282 fileInfo->fFileTypes = types;
283
284 new TGFileDialog(GetParent(), GetMain(), kFDOpen, fileInfo);
285
286 fPathEntryESD->SetText(fileInfo->fFilename);
be736e6d 287
288 // look for the other files in the current directory
289
290
291
292 delete fileInfo;
293
294}
295
296void AliEveFileDialog::onBrowseESDfriendFile()
297{
298 TGFileInfo* fileInfo = new TGFileInfo;
299
300 const char* types[] = { "ALICE ESDfriends file", "*.root",
301 "ROOT Archive", "*.zip",
302 0, 0};
303
304 fileInfo->fFileTypes = types;
305
306 new TGFileDialog(GetParent(), GetMain(), kFDOpen, fileInfo);
307
308 fPathEntryESDfriend->SetText(fileInfo->fFilename);
2e29a658 309
310 delete fileInfo;
311
312}
313
314void AliEveFileDialog::onBrowseAODFile()
315{
316 TGFileInfo* fileInfo = new TGFileInfo;
317
318 const char* types[] = { "ALICE AOD file", "*.root",
319 "ROOT Archive", "*.zip",
320 0, 0};
321
322 fileInfo->fFileTypes = types;
323
324 new TGFileDialog(GetParent(), GetMain(), kFDOpen, fileInfo);
325
326 fPathEntryAOD->SetText(fileInfo->fFilename);
327
328 delete fileInfo;
329
330}
331
332void AliEveFileDialog::onBrowseAODfriendFile()
333{
334 TGFileInfo* fileInfo = new TGFileInfo;
335
336 const char* types[] = { "ALICE AODfriend file", "*.root",
337 "ROOT Archive", "*.zip",
338 0, 0};
339
340 fileInfo->fFileTypes = types;
341
342 new TGFileDialog(GetParent(), GetMain(), kFDOpen, fileInfo);
343
344 fPathEntryAODfriend->SetText(fileInfo->fFilename);
345
346 delete fileInfo;
347
348}
349
350void AliEveFileDialog::onBrowseRawFile()
351{
352 TGFileInfo* fileInfo = new TGFileInfo;
353
354 const char* types[] = { "ALICE RAW file", "*.root",
355 "ROOT Archive", "*.zip",
356 0, 0};
357
358 fileInfo->fFileTypes = types;
359
360 new TGFileDialog(GetParent(), GetMain(), kFDOpen, fileInfo);
361
362 fPathEntryRawFile->SetText(fileInfo->fFilename);
363
364 delete fileInfo;
365
366}
367
368void AliEveFileDialog::onAccept()
369{
370 fIsAccepted = kTRUE;
371 UnmapWindow();
372}
373
374void AliEveFileDialog::onReject()
375{
376 fIsAccepted = kFALSE;
377 UnmapWindow();
378}
379
380void AliEveFileDialog::setMode(EAliEveFileDialogMode mode)
381{
382 fMode = mode;
383}
384
385void AliEveFileDialog::MapWindow()
386{
387 if(IsMapped()) return;
388
389 MapSubwindows();
390 TGTransientFrame::MapWindow();
391 Layout();
392
393 gClient->WaitFor(this);
394}
395
396void AliEveFileDialog::UnmapWindow()
397{
398 TGTransientFrame::UnmapWindow();
399 gClient->ResetWaitFor(this);
400}
401
402void AliEveFileDialog::MapSubwindows()
403{
404 TGTransientFrame::MapSubwindows();
405
406 // Show/Hide Widgets according to the current Mode
407 if(fMode==kAliEveFDLocal){
408 ShowFrame(fESDFilesFrame);
be736e6d 409 ShowFrame(fAdvancedOptsButton);
2e29a658 410 showAdvancedOpts(fAdvancedOptsButton->IsDown());
411
412 HideFrame(fUrlFrame);
413 }
414 else{ // remote file
415 HideFrame(fESDFilesFrame);
be736e6d 416 HideFrame(fAdvancedOptsButton);
2e29a658 417 HideFrame(fAdvancedOptsFrame);
2e29a658 418
419 ShowFrame(fUrlFrame);
420 }
421
422}
423
424void AliEveFileDialog::showAdvancedOpts(Bool_t shown)
425{
426 UInt_t w, h;
427 if(shown){
be736e6d 428 ShowFrame(fAdvancedOptsFrame);
429 fAdvancedOptsFrame->MapWindow();
2e29a658 430 Layout();
431
be736e6d 432 h = fESDFilesFrame->GetSize().fHeight+fAdvancedOptsFrame->GetSize().fHeight+fAdvancedOptsButton->GetSize().fHeight+fCDBFrame->GetSize().fHeight+fDialogButtonsFrame->GetSize().fHeight;
2e29a658 433 }else{
be736e6d 434 HideFrame(fAdvancedOptsFrame);
435 fAdvancedOptsFrame->UnmapWindow();
2e29a658 436 Layout();
437
be736e6d 438 h = fESDFilesFrame->GetSize().fHeight+fAdvancedOptsButton->GetSize().fHeight+fCDBFrame->GetSize().fHeight+fDialogButtonsFrame->GetSize().fHeight;
2e29a658 439 }
440
441 TGDimension size = GetSize();
442 w = size.fWidth;
443
be736e6d 444 Resize(w,h+30);
2e29a658 445
446}
447
448void AliEveFileDialog::CloseWindow()
449{
450 onReject();
451}