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