1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
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 //-----------------------------------------------------------------
26 #include <TGListView.h>
28 #include <TGNumberEntry.h>
29 #include <TGTableLayout.h>
30 #include <TGTextEntry.h>
32 #include <TGridResult.h>
33 #include <TObjArray.h>
34 #include <TObjString.h>
36 #include "AliFileListFrame.h"
38 ClassImp(AliFileListFrame)
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.
50 // use hierarchical cleaning
51 SetCleanup(kDeepCleanup);
53 fHFrame1 = new TGHorizontalFrame(this, 300, 100, kFixedWidth);
54 AddFrame(fHFrame1, new TGLayoutHints(kLHintsTop|kLHintsExpandX));
57 BuildQueryPathFrame();
59 // creates the Tags for Query display
61 fTags = new TObjArray();
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"));
72 gClient->GetColorByName("white", white);
74 fCanvas = new TGCanvas(this, 300, 300, kFixedWidth);
75 fContents = new TGCompositeFrame(fCanvas->GetViewPort(), 300, 300,
76 kSunkenFrame | kFixedWidth, white);
78 fCanvas->SetContainer(fContents);
79 AddFrame(fCanvas, new TGLayoutHints(kLHintsBottom|kLHintsExpandX, 5,5,5,0));
86 //___________________________________________________________________________
87 AliFileListFrame::~AliFileListFrame() {
88 // AliFileListFrame Destructor
92 DeleteWindow(); // deletes fMain
95 //___________________________________________________________________________
96 void AliFileListFrame::SetQueryPath(const char* path) {
98 fTextQueryPath->SetText(path);
101 //___________________________________________________________________________
102 const char* AliFileListFrame::GetQueryPath() {
103 // Get the Query Path
104 return fTextQueryPath->GetText();
107 //___________________________________________________________________________
108 const char* AliFileListFrame::GetQueryPattern() {
109 // Get the Query Patttern
110 return fTextQueryPattern->GetText();
113 //___________________________________________________________________________
114 void AliFileListFrame::BuildQueryPathFrame() {
115 // Build the Query Path Frame
117 fHFrame1 = new TGHorizontalFrame(this, 100, 100, kRaisedFrame);
118 AddFrame(fHFrame1, new TGLayoutHints(kLHintsTop, 5,5,5,5));
120 fVFrame1 = new TGVerticalFrame(fHFrame1, 100, 50);
121 fHFrame1->AddFrame(fVFrame1, new TGLayoutHints(kLHintsLeft, 5,5,5,5));
123 fVFrame2 = new TGVerticalFrame(fHFrame1, 100, 50);
124 fHFrame1->AddFrame(fVFrame2, new TGLayoutHints(kLHintsRight, 5,5,5,5));
126 // fVFrame1, for the labels
128 fLabel1 = new TGLabel(fVFrame1, new TGString("Query Path"));
129 fVFrame1->AddFrame(fLabel1, new TGLayoutHints(kLHintsTop, 5,5,10,5));
131 fLabel2 = new TGLabel(fVFrame1, new TGString("Query Pattern"));
132 fVFrame1->AddFrame(fLabel2, new TGLayoutHints(kLHintsCenterY, 5,5,10,5));
134 fLabel3 = new TGLabel(fVFrame1, new TGString("Max. Results"));
135 fVFrame1->AddFrame(fLabel3, new TGLayoutHints(kLHintsCenterY, 5,5,10,5));
137 // fVFrame2 for the text boxes
139 fTextQueryPath = new TGTextEntry(fVFrame2, new TGTextBuffer(50));
140 fTextQueryPath->SetEnabled(false);
141 fVFrame2->AddFrame(fTextQueryPath,
142 new TGLayoutHints(kLHintsTop, 5,5,5,5));
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");
149 fNumMaxResults = new TGNumberEntry(fVFrame2, 100);
150 fNumMaxResults->SetLimits(TGNumberFormat::kNELLimitMin, 0);
151 fVFrame2->AddFrame(fNumMaxResults,
152 new TGLayoutHints(kLHintsTop, 5,5,5,5));
154 fButtonRun = new TGTextButton(fVFrame2, " Run ", 0);
155 fVFrame2->AddFrame(fButtonRun,
156 new TGLayoutHints(kLHintsRight, 0,5,0,0));
158 fButtonRun->Connect("Clicked()", "AliFileListFrame", this, "RunQuery()");
161 //___________________________________________________________________________
162 void AliFileListFrame::RunQuery() {
168 SetCleanup(kDeepCleanup);
170 fContents->Cleanup();
172 TGridResult *result = gGrid->Query(GetQueryPath(), GetQueryPattern());
177 int nrows = result->GetEntries();
178 int ncols = fTags->GetEntries();
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);
187 //if(fTableLayout != NULL) delete fTableLayout;
188 fTableLayout = new TGTableLayout(fContents, nrows+1, ncols);
189 fContents->SetLayoutManager(fTableLayout);
192 gClient->GetColorByName("white", white);
196 for (int i=0; i < ncols; i++) {
197 for (int j=0; j < nrows; j++) {
198 tag = (TObjString*) (fTags->At(i));
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);
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);
222 //___________________________________________________________________________
223 void AliFileListFrame::DisplayObject(const TString& fname,const TString& name) const {
224 // Browse object located in file.
226 TDirectory *sav = gDirectory;
228 static TFile *file = 0;
229 if (file) delete file; // close
230 file = new TFile(fname); // reopen
232 TObject* obj = file->Get(name);
234 if (!obj->IsFolder()) {
241 //___________________________________________________________________________
242 void AliFileListFrame::OnDoubleClick(TGLVEntry *f, Int_t btn) {
243 // Handle double click.
245 if (btn != kButton1) return;
248 ULong_t cur = gVirtualX->CreateCursor(kWatch);
249 gVirtualX->SetCursor(fContents->GetId(), cur);
251 TString name(f->GetTitle());
252 const char* fname = (const char*)f->GetUserData();
255 DisplayObject(fname, name);
256 } else if (name.EndsWith(".root")) {
257 // DisplayFile(name);
259 // DisplayDirectory(name);
262 // set kPointer cursor
263 cur = gVirtualX->CreateCursor(kPointer);
264 gVirtualX->SetCursor(fContents->GetId(), cur);