]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/Aliengui/AliFileListFrame.cxx
TPCNoiseMapComponent included into build (Kelly)
[u/mrichter/AliRoot.git] / ANALYSIS / Aliengui / AliFileListFrame.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 //-----------------------------------------------------------------
19 //           AliFileListFrame class
20 //   The class that deals with the file list frame of the GUI
21 //   Origin: Panos Christakoglou, UOA-CERN, Panos.Christakoglou@cern.ch
22 //-----------------------------------------------------------------
23
24 #include <TFile.h>
25 #include <TGLabel.h>
26 #include <TGListView.h>
27 #include <TGMsgBox.h>
28 #include <TGNumberEntry.h>
29 #include <TGTableLayout.h>
30 #include <TGTextEntry.h>
31 #include <TGrid.h>
32 #include <TGridResult.h>
33 #include <TObjArray.h>
34 #include <TObjString.h>
35
36 #include "AliFileListFrame.h"
37
38 ClassImp(AliFileListFrame)
39
40 //___________________________________________________________________________
41 AliFileListFrame::AliFileListFrame(const TGWindow *main, UInt_t w, UInt_t h): 
42   TGCompositeFrame(main, w, h), 
43   fHFrame1(0), fVFrame1(0), fVFrame2(0),
44   fHFrame2(0), fLabel1(0), fLabel2(0), fLabel3(0),
45   fTextQueryPath(0), fNumMaxResults(0), fTextQueryPattern(0),
46   fButtonRun(0), fContents(0), fCanvas(0),
47   fTableLayout(0), fTags(0) {
48   // Creates a composite frame containing a filelist widget.
49    
50   // use hierarchical cleaning
51   SetCleanup(kDeepCleanup);
52   
53   fHFrame1 = new TGHorizontalFrame(this, 300, 100, kFixedWidth);
54   AddFrame(fHFrame1, new TGLayoutHints(kLHintsTop|kLHintsExpandX));
55   
56   
57   BuildQueryPathFrame();
58   
59   // creates the Tags for Query display
60   
61   fTags = new TObjArray();
62   
63   fTags->Add(new TObjString("type"));
64   fTags->Add(new TObjString("owner"));
65   fTags->Add(new TObjString("gowner"));
66   fTags->Add(new TObjString("perm"));
67   fTags->Add(new TObjString("size"));
68   fTags->Add(new TObjString("ctime"));
69   fTags->Add(new TObjString("lfn"));
70   
71   Pixel_t white;
72   gClient->GetColorByName("white", white);
73   
74   fCanvas = new TGCanvas(this, 300, 300, kFixedWidth);
75   fContents = new TGCompositeFrame(fCanvas->GetViewPort(), 300, 300, 
76                                    kSunkenFrame | kFixedWidth, white);
77   
78   fCanvas->SetContainer(fContents);
79   AddFrame(fCanvas, new TGLayoutHints(kLHintsBottom|kLHintsExpandX, 5,5,5,0));
80   
81   MapSubwindows();
82   MapWindow();
83   Resize();
84 }
85
86 //___________________________________________________________________________
87 AliFileListFrame::~AliFileListFrame() {
88   // AliFileListFrame Destructor
89   // Cleanup.
90   
91   delete fContents;
92   DeleteWindow();  // deletes fMain
93 }
94
95 //___________________________________________________________________________
96 void AliFileListFrame::SetQueryPath(const char* path) {
97   // Set the Query Path
98   fTextQueryPath->SetText(path);
99 }
100
101 //___________________________________________________________________________
102 const char* AliFileListFrame::GetQueryPath() {
103   // Get the Query Path
104   return fTextQueryPath->GetText();
105 }
106
107 //___________________________________________________________________________
108 const char* AliFileListFrame::GetQueryPattern() {
109   // Get the Query Patttern
110   return fTextQueryPattern->GetText();
111 }
112
113 //___________________________________________________________________________
114 void AliFileListFrame::BuildQueryPathFrame() {
115   // Build the Query Path Frame
116   
117   fHFrame1 = new TGHorizontalFrame(this, 100, 100, kRaisedFrame);
118   AddFrame(fHFrame1, new TGLayoutHints(kLHintsTop, 5,5,5,5));
119   
120   fVFrame1 = new TGVerticalFrame(fHFrame1, 100, 50);
121   fHFrame1->AddFrame(fVFrame1, new TGLayoutHints(kLHintsLeft, 5,5,5,5));  
122   
123   fVFrame2 = new TGVerticalFrame(fHFrame1, 100, 50);
124   fHFrame1->AddFrame(fVFrame2, new TGLayoutHints(kLHintsRight, 5,5,5,5));
125   
126   // fVFrame1, for the labels   
127   
128   fLabel1 = new TGLabel(fVFrame1, new TGString("Query Path"));
129   fVFrame1->AddFrame(fLabel1, new TGLayoutHints(kLHintsTop, 5,5,10,5));
130   
131   fLabel2 = new TGLabel(fVFrame1, new TGString("Query Pattern"));
132   fVFrame1->AddFrame(fLabel2, new TGLayoutHints(kLHintsCenterY, 5,5,10,5));
133   
134   fLabel3 = new TGLabel(fVFrame1, new TGString("Max. Results"));
135   fVFrame1->AddFrame(fLabel3, new TGLayoutHints(kLHintsCenterY, 5,5,10,5));
136    
137   // fVFrame2 for the text boxes
138   
139   fTextQueryPath = new TGTextEntry(fVFrame2, new TGTextBuffer(50));
140   fTextQueryPath->SetEnabled(false);
141   fVFrame2->AddFrame(fTextQueryPath, 
142                      new TGLayoutHints(kLHintsTop, 5,5,5,5));
143   
144   fTextQueryPattern = new TGTextEntry(fVFrame2, new TGTextBuffer(20), 0);
145   fVFrame2->AddFrame(fTextQueryPattern, 
146                      new TGLayoutHints(kLHintsTop, 5,5,5,5));
147   fTextQueryPattern->SetText("*.root");
148   
149   fNumMaxResults = new TGNumberEntry(fVFrame2, 100);
150   fNumMaxResults->SetLimits(TGNumberFormat::kNELLimitMin, 0);
151   fVFrame2->AddFrame(fNumMaxResults, 
152                      new TGLayoutHints(kLHintsTop, 5,5,5,5));
153   
154   fButtonRun =  new TGTextButton(fVFrame2, "          Run         ", 0);
155   fVFrame2->AddFrame(fButtonRun, 
156                      new TGLayoutHints(kLHintsRight, 0,5,0,0));
157   
158   fButtonRun->Connect("Clicked()", "AliFileListFrame", this, "RunQuery()");
159 }
160
161 //___________________________________________________________________________
162 void AliFileListFrame::RunQuery() {
163   // Run Query
164   
165   if(!gGrid)
166     return;
167   
168   SetCleanup(kDeepCleanup);   
169   
170   fContents->Cleanup();
171   
172   TGridResult *result = gGrid->Query(GetQueryPath(), GetQueryPattern());
173   
174   if(!result)
175     return;
176
177   int nrows = result->GetEntries();
178   int ncols = fTags->GetEntries();
179   
180   if(nrows == 0){ // there is nothing to show
181     TString msg = TString("The query of \"");
182     (msg+=GetQueryPattern())+="\" pattern is empty ";
183     new TGMsgBox(gClient->GetRoot(), this, "Empty query", msg.Data(), 0, kMBOk);
184     return;
185   }
186   
187   //if(fTableLayout != NULL) delete fTableLayout;
188   fTableLayout = new TGTableLayout(fContents, nrows+1, ncols);
189   fContents->SetLayoutManager(fTableLayout);
190   
191   Pixel_t white;
192   gClient->GetColorByName("white", white);
193   
194   TObjString * tag;
195   
196   for (int i=0; i < ncols; i++) {
197     for (int j=0; j < nrows; j++) {
198       tag = (TObjString*) (fTags->At(i));
199       TGLabel * label = 
200         new TGLabel(fContents, new TGString(result->GetKey(j,tag->GetName())));        
201       label->SetBackgroundColor(white);
202       TGTableLayoutHints *thint = 
203         new TGTableLayoutHints(i,i+1,j+1,j+2, kLHintsExpandX | kLHintsLeft, 5,30,5,5);
204       fContents->AddFrame(label,thint); 
205     }//for_j
206   }//for_i
207   
208   for (int j=0; j < ncols; j++) {
209     tag = (TObjString*) (fTags->At(j));
210     TGTextButton * button = new TGTextButton(fContents, tag->GetName(), 0);
211     TGTableLayoutHints *thint = 
212       new TGTableLayoutHints(j,j+1,0,1, kLHintsFillX, 0,0,0,0);
213     fContents->AddFrame(button,thint);
214   }
215   
216   MapSubwindows();
217   MapWindow();
218   
219   Resize();
220 }
221
222 //___________________________________________________________________________
223 void AliFileListFrame::DisplayObject(const TString& fname,const TString& name) const {
224   // Browse object located in file.
225   
226   TDirectory *sav = gDirectory;
227   
228   static TFile *file = 0;
229   if (file) delete file;     // close
230   file = new TFile(fname);   // reopen
231   
232   TObject* obj = file->Get(name);
233   if (obj) {
234     if (!obj->IsFolder()) {
235       obj->Browse(0);
236     } else obj->Print();
237   }
238   gDirectory = sav;
239 }
240
241 //___________________________________________________________________________
242 void AliFileListFrame::OnDoubleClick(TGLVEntry *f, Int_t btn) {
243   // Handle double click.
244   
245   if (btn != kButton1) return;
246   
247   // set kWatch cursor
248   ULong_t cur = gVirtualX->CreateCursor(kWatch);
249   gVirtualX->SetCursor(fContents->GetId(), cur);
250   
251   TString name(f->GetTitle());
252   const char* fname = (const char*)f->GetUserData();
253   
254   if (fname) {
255     DisplayObject(fname, name);
256   } else if (name.EndsWith(".root")) {
257     //      DisplayFile(name);
258   } else {
259     // DisplayDirectory(name);
260   }
261   
262   // set kPointer cursor
263   cur = gVirtualX->CreateCursor(kPointer);
264   gVirtualX->SetCursor(fContents->GetId(), cur);
265 }
266