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