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 //-----------------------------------------------------------------
24 #include "TObjString.h"
25 #include "TGTextEntry.h"
27 #include "TGNumberEntry.h"
29 #include "TGTableLayout.h"
30 #include "TGListView.h"
35 #include "TGridResult.h"
37 #include "AliFileListFrame.h"
39 ClassImp(AliFileListFrame)
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.
45 // use hierarchical cleaning
46 SetCleanup(kDeepCleanup);
48 fHFrame1 = new TGHorizontalFrame(this, 300, 100, kFixedWidth);
49 AddFrame(fHFrame1, new TGLayoutHints(kLHintsTop|kLHintsExpandX));
52 BuildQueryPathFrame();
54 // creates the Tags for Query display
56 fTags = new TObjArray();
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"));
67 gClient->GetColorByName("white", white);
69 fCanvas = new TGCanvas(this, 300, 300, kFixedWidth);
70 fContents = new TGCompositeFrame(fCanvas->GetViewPort(), 300, 300,
71 kSunkenFrame | kFixedWidth, white);
73 fCanvas->SetContainer(fContents);
74 AddFrame(fCanvas, new TGLayoutHints(kLHintsBottom|kLHintsExpandX, 5,5,5,0));
81 //___________________________________________________________________________
82 AliFileListFrame::~AliFileListFrame() {
83 // AliFileListFrame Destructor
87 DeleteWindow(); // deletes fMain
90 //___________________________________________________________________________
91 void AliFileListFrame::SetQueryPath(const char* path) {
93 fTextQueryPath->SetText(path);
96 //___________________________________________________________________________
97 const char* AliFileListFrame::GetQueryPath() {
99 return fTextQueryPath->GetText();
102 //___________________________________________________________________________
103 const char* AliFileListFrame::GetQueryPattern() {
104 // Get the Query Patttern
105 return fTextQueryPattern->GetText();
108 //___________________________________________________________________________
109 void AliFileListFrame::BuildQueryPathFrame() {
110 // Build the Query Path Frame
112 fHFrame1 = new TGHorizontalFrame(this, 100, 100, kRaisedFrame);
113 AddFrame(fHFrame1, new TGLayoutHints(kLHintsTop, 5,5,5,5));
115 fVFrame1 = new TGVerticalFrame(fHFrame1, 100, 50);
116 fHFrame1->AddFrame(fVFrame1, new TGLayoutHints(kLHintsLeft, 5,5,5,5));
118 fVFrame2 = new TGVerticalFrame(fHFrame1, 100, 50);
119 fHFrame1->AddFrame(fVFrame2, new TGLayoutHints(kLHintsRight, 5,5,5,5));
121 // fVFrame1, for the labels
123 fLabel1 = new TGLabel(fVFrame1, new TGString("Query Path"));
124 fVFrame1->AddFrame(fLabel1, new TGLayoutHints(kLHintsTop, 5,5,10,5));
126 fLabel2 = new TGLabel(fVFrame1, new TGString("Query Pattern"));
127 fVFrame1->AddFrame(fLabel2, new TGLayoutHints(kLHintsCenterY, 5,5,10,5));
129 fLabel3 = new TGLabel(fVFrame1, new TGString("Max. Results"));
130 fVFrame1->AddFrame(fLabel3, new TGLayoutHints(kLHintsCenterY, 5,5,10,5));
132 // fVFrame2 for the text boxes
134 fTextQueryPath = new TGTextEntry(fVFrame2, new TGTextBuffer(50));
135 fTextQueryPath->SetEnabled(false);
136 fVFrame2->AddFrame(fTextQueryPath,
137 new TGLayoutHints(kLHintsTop, 5,5,5,5));
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");
144 fNumMaxResults = new TGNumberEntry(fVFrame2, 100);
145 fNumMaxResults->SetLimits(TGNumberFormat::kNELLimitMin, 0);
146 fVFrame2->AddFrame(fNumMaxResults,
147 new TGLayoutHints(kLHintsTop, 5,5,5,5));
149 fButtonRun = new TGTextButton(fVFrame2, " Run ", 0);
150 fVFrame2->AddFrame(fButtonRun,
151 new TGLayoutHints(kLHintsRight, 0,5,0,0));
153 fButtonRun->Connect("Clicked()", "AliFileListFrame", this, "RunQuery()");
156 //___________________________________________________________________________
157 void AliFileListFrame::RunQuery() {
163 SetCleanup(kDeepCleanup);
165 fContents->Cleanup();
167 TGridResult *result = gGrid->Query(GetQueryPath(), GetQueryPattern());
172 int nrows = result->GetEntries();
173 int ncols = fTags->GetEntries();
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);
182 //if(fTableLayout != NULL) delete fTableLayout;
183 fTableLayout = new TGTableLayout(fContents, nrows+1, ncols);
184 fContents->SetLayoutManager(fTableLayout);
187 gClient->GetColorByName("white", white);
191 for (int i=0; i < ncols; i++) {
192 for (int j=0; j < nrows; j++) {
193 tag = (TObjString*) (fTags->At(i));
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);
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);
217 //___________________________________________________________________________
218 void AliFileListFrame::DisplayObject(const TString& fname,const TString& name) const {
219 // Browse object located in file.
221 TDirectory *sav = gDirectory;
223 static TFile *file = 0;
224 if (file) delete file; // close
225 file = new TFile(fname); // reopen
227 TObject* obj = file->Get(name);
229 if (!obj->IsFolder()) {
236 //___________________________________________________________________________
237 void AliFileListFrame::OnDoubleClick(TGLVEntry *f, Int_t btn) {
238 // Handle double click.
240 if (btn != kButton1) return;
243 ULong_t cur = gVirtualX->CreateCursor(kWatch);
244 gVirtualX->SetCursor(fContents->GetId(), cur);
246 TString name(f->GetTitle());
247 const char* fname = (const char*)f->GetUserData();
250 DisplayObject(fname, name);
251 } else if (name.EndsWith(".root")) {
252 // DisplayFile(name);
254 // DisplayDirectory(name);
257 // set kPointer cursor
258 cur = gVirtualX->CreateCursor(kPointer);
259 gVirtualX->SetCursor(fContents->GetId(), cur);