forked from archduke31/ADBLogger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSlogMainFrame.java
More file actions
817 lines (716 loc) · 31.1 KB
/
Copy pathSlogMainFrame.java
File metadata and controls
817 lines (716 loc) · 31.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package feiw;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabFolder2Adapter;
import org.eclipse.swt.custom.CTabFolderEvent;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.CoolBar;
import org.eclipse.swt.widgets.CoolItem;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import feiw.LogSource.LogFilter;
import feiw.SystemConfigs.LogUrl;
import feiw.ToolBarDes.ToolItemDes;
public final class SlogMainFrame {
private Display mDisplay;
private Shell mShell;
CoolBar mCoolBar = null;
List<ToolItem> mToolItems = new ArrayList<ToolItem>(10);
CTabFolder mTabFolder;
public Display getDisplay() {
return mDisplay;
}
public Shell getShell() {
return mShell;
}
ToolItem getToolItem(String name) {
for (ToolItem it : mToolItems) {
if (name.equals(it.getData())) {
return it;
}
}
return null;
}
public SlogMainFrame(String caption, Display disp) {
mDisplay = disp;
mShell = new Shell(disp);
mShell.setText(caption);
mShell.setImage(Resources.android_log_32);
createContents();
mShell.addListener(SWT.Close, new Listener() {
@Override
public void handleEvent(Event event) {
closeTabFrames();
}
});
}
void createToolBar(ToolBarDes tbdes) {
ToolBar tb = new ToolBar(mCoolBar, SWT.FLAT);
tb.setData(tbdes.mName);
for (ToolItemDes itdes : tbdes.mItems) {
// System.out.println("create tool bar " + itdes.mName);
ToolItem it = new ToolItem(tb, itdes.mStyle);
it.setData(itdes.mName);
it.setData("KeyAccelerators", itdes.mKeyAccelerators);
it.setToolTipText(itdes.mTipText);
if (itdes.mImage != null) {
it.setImage(itdes.mImage);
it.setDisabledImage(new Image(getDisplay(), itdes.mImage, SWT.IMAGE_GRAY));
}
mToolItems.add(it);
}
CoolItem item = new CoolItem(mCoolBar, SWT.NONE);
Point p = tb.computeSize(SWT.DEFAULT, SWT.DEFAULT);
p.x += 2;
tb.setSize(p);
Point p2 = item.computeSize(p.x + 2, p.y);
item.setControl(tb);
item.setSize(p2);
tb.pack();
}
abstract class DropdownListener extends SelectionAdapter {
private ToolItem dropdown;
private Menu menu;
public abstract void init();
public abstract void onToolSelected(ToolItem dropdown);
public abstract void onListSelected(final Object o);
public DropdownListener(ToolItem dropdown) {
this.dropdown = dropdown;
menu = new Menu(dropdown.getParent().getShell());
init();
}
public void clearList() {
menu.dispose();
menu = new Menu(dropdown.getParent().getShell());
}
public void addListItem(String item, Image img, final Object o) {
MenuItem menuItem = new MenuItem(menu, SWT.NONE);
menuItem.setText(item);
menuItem.setImage(img);
menuItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
onListSelected(o);
}
});
}
@Override
public void widgetSelected(SelectionEvent event) {
if (!dropdown.getEnabled()) {
return;
}
if (event.detail == SWT.ARROW) {
init();
ToolItem item = (ToolItem) event.widget;
Rectangle rect = item.getBounds();
Point pt = item.getParent().toDisplay(new Point(rect.x, rect.y));
menu.setLocation(pt.x, pt.y + rect.height);
menu.setVisible(true);
} else {
onToolSelected(dropdown);
}
}
}
public FilterTabFrame openFilterView(LogFilter f) {
SlogTabFrame tbf = (SlogTabFrame) mTabFolder.getSelection();
FilterTabFrame ltab = new FilterTabFrame(mTabFolder, "\"" + f.getName() + "\" on [" + tbf.getText() + "]",
SWT.FLAT | SWT.CLOSE | SWT.ICON, tbf.getLogSource(), f, tbf.getLogView().getLogParser(),
tbf.getLogView());
mTabFolder.setSelection(ltab);
SystemConfigs.instance().addRecentFilter(f);
return ltab;
}
void createToolBars() {
mCoolBar = new CoolBar(getShell(), SWT.FLAT);
mCoolBar.setBackground(new Color(getDisplay(), 255, 255, 255));
mCoolBar.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 4, 1));
for (ToolBarDes tdes : ToolBarDes.TOOBARS) {
createToolBar(tdes);
}
getToolItem(ToolBarDes.TN_NEXT).addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
SlogTabFrame tbf = (SlogTabFrame) mTabFolder.getSelection();
if (tbf != null) {
tbf.onNext();
}
}
});
getToolItem(ToolBarDes.TN_PREV).addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
SlogTabFrame tbf = (SlogTabFrame) mTabFolder.getSelection();
if (tbf != null) {
tbf.onPrev();
}
}
});
getToolItem(ToolBarDes.TN_SEARCH).addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
SearchDlg d = new SearchDlg(Slogmain.getApp().getMainFrame().getShell());
String txt = d.open();
if (txt != null && !(txt.trim().isEmpty())) {
SlogTabFrame tbf = (SlogTabFrame) mTabFolder.getSelection();
if (tbf != null) {
tbf.onSearch(txt.trim(), d.isCaseSenstive());
}
}
}
});
getToolItem(ToolBarDes.TN_CONNECT)
.addSelectionListener(new DropdownListener(getToolItem(ToolBarDes.TN_CONNECT)) {
@Override
public void onToolSelected(ToolItem dropdown) {
SystemConfigs.LogUrl lu = SystemConfigs.instance().getRecentUrl(0);
ConnectDlg dlg = new ConnectDlg(getShell(), lu == null ? "10.222.98.205" : lu.url,
lu == null ? 8000 : lu.port);
if (dlg.open() == SWT.OK) {
QconnTabFrame ltab;
try {
String title = "qconn://" + dlg.getIp() + ":" + dlg.getPort();
ltab = new QconnTabFrame(mTabFolder, title, SWT.FLAT | SWT.CLOSE | SWT.ICON,
dlg.getIp(), dlg.getPort());
mTabFolder.setSelection(ltab);
SystemConfigs.instance().addRecentUrl(new LogUrl("qconn", dlg.getIp(), dlg.getPort()));
updateToolBars(ltab);
} catch (DeviceNotConnected e) {
MessageBox m = new MessageBox(getShell(), SWT.OK | SWT.ICON_ERROR);
m.setText("Error");
m.setMessage(e.getMessage());
m.open();
}
}
}
@Override
public void onListSelected(Object o) {
if (o instanceof LogUrl) {
LogUrl lu = (LogUrl) o;
QconnTabFrame ltab;
try {
ltab = new QconnTabFrame(mTabFolder, lu.toString(), SWT.FLAT | SWT.CLOSE | SWT.ICON,
lu.url, lu.port);
mTabFolder.setSelection(ltab);
SystemConfigs.instance().addRecentUrl(new LogUrl("qconn", lu.url, lu.port));
updateToolBars(ltab);
} catch (DeviceNotConnected e) {
MessageBox m = new MessageBox(getShell(), SWT.OK | SWT.ICON_ERROR);
m.setText("Error");
m.setMessage(e.getMessage());
m.open();
}
}
}
@Override
public void init() {
clearList();
for (int i = 0; i < SystemConfigs.RECENTLIST_SIZE; i++) {
LogUrl lu = SystemConfigs.instance().getRecentUrl(i);
if (lu != null) {
addListItem(lu.toString(), Resources.connected_16, lu);
}
}
}
});
getToolItem(ToolBarDes.TN_OPEN).addSelectionListener(new DropdownListener(getToolItem(ToolBarDes.TN_OPEN)) {
@Override
public void onToolSelected(ToolItem dropdown) {
FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
String[] filterNames = new String[] { "Log Files", "All Files (*)" };
String[] filterExtensions = new String[] { "*.log;*.txt;", "*" };
// String filterPath = "";
/*
* String platform = SWT.getPlatform(); if
* (platform.equals("win32") || platform.equals("wpf")) {
* filterNames = new String [] {"Image Files", "All Files (*.*)"
* }; filterExtensions = new String []
* {"*.gif;*.png;*.bmp;*.jpg;*.jpeg;*.tiff", "*.*"}; filterPath
* = "c:\\"; }
*/
dialog.setFilterNames(filterNames);
dialog.setFilterExtensions(filterExtensions);
// dialog.setFilterPath (filterPath);
String fname = dialog.open();
if (fname != null) {
FileTabFrame ftb;
try {
ftb = new FileTabFrame(mTabFolder, fname, SWT.FLAT | SWT.CLOSE | SWT.ICON, fname);
mTabFolder.setSelection(ftb);
SystemConfigs.instance().addRecentFile(fname);
updateToolBars(ftb);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
@Override
public void onListSelected(Object o) {
if (o instanceof String) {
String fname = (String) o;
FileTabFrame ftb;
try {
ftb = new FileTabFrame(mTabFolder, fname, SWT.FLAT | SWT.CLOSE | SWT.ICON, fname);
mTabFolder.setSelection(ftb);
SystemConfigs.instance().addRecentFile(fname);
updateToolBars(ftb);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
@Override
public void init() {
clearList();
for (int i = 0; i < SystemConfigs.RECENTLIST_SIZE; i++) {
String fname = SystemConfigs.instance().getRecentFile(i);
if (fname != null) {
addListItem(fname, Resources.openfile_16, fname);
}
}
}
});
getToolItem(ToolBarDes.TN_OPENFIFO).addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
String[] filterNames = new String[] { "Fifo", "All Files (*)" };
String[] filterExtensions = new String[] { "*" };
dialog.setFilterNames(filterNames);
dialog.setFilterExtensions(filterExtensions);
// dialog.setFilterPath (filterPath);
String fname = dialog.open();
if (fname != null) {
FifoTabFrame ftb;
try {
ftb = new FifoTabFrame(mTabFolder, fname, SWT.FLAT | SWT.CLOSE | SWT.ICON, fname);
mTabFolder.setSelection(ftb);
SystemConfigs.instance().addRecentFile(fname);
updateToolBars(ftb);
} catch (DeviceNotConnected e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
});
getToolItem(ToolBarDes.TN_FILTER).addSelectionListener(new DropdownListener(getToolItem(ToolBarDes.TN_FILTER)) {
@Override
public void onToolSelected(ToolItem dropdown) {
SlogTabFrame ctab = (SlogTabFrame) mTabFolder.getSelection();
String defaultField = LogFilter.FIELD_CONTENT;
if (ctab.getLogSource() instanceof AndroidLogSource) {
defaultField = LogFilter.FIELD_TAG;
}
FilterDlg fdlg = new FilterDlg(getShell(), ctab.getLogView(), defaultField);
if (fdlg.open() != SWT.OK) {
return;
}
LogFilter f = fdlg.getFilter();
openFilterView(f);
}
@Override
public void onListSelected(final Object o) {
if (o instanceof LogFilter) {
openFilterView((LogFilter) o);
}
}
@Override
public void init() {
clearList();
for (int i = 0; i < SystemConfigs.RECENTLIST_SIZE; i++) {
LogFilter f = SystemConfigs.instance().getRecentFilter(i);
if (f != null) {
addListItem(f.getName(), Resources.filter_16, f);
}
}
}
});
getToolItem(ToolBarDes.TN_CLEAR).addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
SlogTabFrame tbf = (SlogTabFrame) mTabFolder.getSelection();
tbf.onClear();
}
});
getToolItem(ToolBarDes.TN_PAUSE).addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
SlogTabFrame tbf = (SlogTabFrame) mTabFolder.getSelection();
if (tbf != null) {
tbf.onPause();
}
}
});
getToolItem(ToolBarDes.TN_DISCONNECT).addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
SlogTabFrame tbf = (SlogTabFrame) mTabFolder.getSelection();
if (tbf != null) {
tbf.onDisconnect();
}
}
});
getToolItem(ToolBarDes.TN_COPY).addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
SlogTabFrame tbf = (SlogTabFrame) mTabFolder.getSelection();
tbf.onCopy();
}
});
getToolItem(ToolBarDes.TN_COPYALL).addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
SlogTabFrame tbf = (SlogTabFrame) mTabFolder.getSelection();
tbf.onCopyAll();
}
});
getToolItem(ToolBarDes.TN_SAVEAS).addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
final String[] filterNames = new String[] { "Log Files", "All Files (*)" };
final String[] filterExtensions = new String[] { "*.log;*.txt;", "*" };
dialog.setFilterNames(filterNames);
dialog.setFilterExtensions(filterExtensions);
String fname = dialog.open();
if (fname != null) {
SlogTabFrame tbf = (SlogTabFrame) mTabFolder.getSelection();
tbf.onSaveAs(fname);
}
}
});
getToolItem(ToolBarDes.TN_PREFERENCE).addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
PerferenceDlg dlg = new PerferenceDlg(getShell());
dlg.setFontSize(SystemConfigs.instance().getLogFontSize());
if (dlg.open() == SWT.OK) {
int fs = dlg.getFontSize();
SystemConfigs.instance().setLogFontSize(fs);
SlogTabFrame tbf = (SlogTabFrame) mTabFolder.getSelection();
if (tbf != null) {
tbf.setLogFont();
}
}
}
});
getToolItem(ToolBarDes.TN_HELP).addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
MessageBox m = new MessageBox(getShell(), SWT.OK | SWT.ICON_INFORMATION);
m.setText("About SuperLog");
m.setMessage("SuperLog Version " + BuildInfo.VERSION + "\n" + "Build Time: " + BuildInfo.BUILD_TIME + "\n"
+ "Build Server: " + BuildInfo.BUILD_SERVER + "\nBuild OS: " + BuildInfo.BUILD_OS + "\nCommit ID: " + BuildInfo.COMMIT + "\n");
m.open();
}
});
getToolItem(ToolBarDes.TN_CONNECTANDROID).addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (!AndroidLogSource.checkAdb(SystemConfigs.instance().getAdbPath() + "/adb")) {
String adbPath = null;
do {
DirectoryDialog dialog = new DirectoryDialog(getShell());
dialog.setText("ADB not found, Please specify directory that contains ADB");
adbPath = dialog.open();
} while (adbPath != null && !AndroidLogSource.checkAdb(adbPath + "/adb"));
if (adbPath == null) {
return;
}
SystemConfigs.instance().setAdbPath(adbPath);
}
final String [] devs = AndroidLogSource.enumDevices();
if (devs == null) {
MessageBox m = new MessageBox(getShell(), SWT.OK | SWT.ICON_ERROR);
m.setText("Error");
m.setMessage("No Android device connected");
m.open();
return;
}
int selectedDevice = 0;
if (devs.length > 1) {
//multiple device, choice
AndroidDeviceChoiceDlg d = new AndroidDeviceChoiceDlg(getShell(), devs, 0);
if (d.open() != SWT.OK) {
return;
}
selectedDevice = d.getSelection();
}
try {
SlogTabFrame ltab = new AndroidTabFrame(mTabFolder, SWT.FLAT | SWT.CLOSE | SWT.ICON, devs[selectedDevice]);
mTabFolder.setSelection(ltab);
updateToolBars(ltab);
} catch (DeviceNotConnected e1) {
}
}
});
}
void updateToolItem(ToolItem tit) {
String tn = (String) tit.getData();
if (tn == null || tn.isEmpty()) {
tit.setEnabled(false);
return;
}
if (tn.equals(ToolBarDes.TN_CONNECT)) {
tit.setEnabled(true);
} else if (tn.equals(ToolBarDes.TN_OPEN)) {
tit.setEnabled(true);
} else if (tn.equals(ToolBarDes.TN_PREFERENCE)) {
tit.setEnabled(true);
} else if (tn.equals(ToolBarDes.TN_HELP)) {
tit.setEnabled(true);
} else if (tn.equals(ToolBarDes.TN_CONNECTANDROID)) {
tit.setEnabled(true);
} else if (tn.equals(ToolBarDes.TN_OPENFIFO)) {
tit.setEnabled(true);
} else {
tit.setEnabled(false);
}
}
void updateToolBars(SlogTabFrame it) {
for (ToolItem tit : mToolItems) {
if (it == null) {
updateToolItem(tit);
} else {
it.updateToolItem(tit);
}
}
mCoolBar.pack(true);
}
protected Control createContents() {
GridLayout layout = new GridLayout();
layout.numColumns = 4;
getShell().setLayout(layout);
createToolBars();
updateToolBars(null);
mTabFolder = new CTabFolder(getShell(), SWT.BORDER);
mTabFolder.setSimple(false);
mTabFolder.setUnselectedCloseVisible(true);
mTabFolder.setUnselectedImageVisible(true);
mTabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1));
/*
* mTabFolder.addSelectionListener(new SelectionListener() {
*
* @Override public void widgetSelected(SelectionEvent e) { if (e.item
* instanceof SlogTabFrame) { SlogTabFrame it = (SlogTabFrame)e.item; //
* updateToolBars(it); } }
*
* @Override public void widgetDefaultSelected(SelectionEvent e) { if
* (e.item instanceof SlogTabFrame) { SlogTabFrame it =
* (SlogTabFrame)e.item; // updateToolBars(it); } }
*
* });
*/
mTabFolder.addCTabFolder2Listener(new CTabFolder2Adapter() {
@Override
public void close(CTabFolderEvent event) {
if (event.item instanceof SlogTabFrame) {
SlogTabFrame it = (SlogTabFrame) event.item;
it.onClose();
if (mTabFolder.getItemCount() == 1) {
updateToolBars(null);
}
}
}
});
mTabFolder.addListener(SWT.MenuDetect, new Listener() {
@Override
public void handleEvent(Event event) {
Point point = mDisplay.map(null, mTabFolder, new Point(event.x, event.y));
final CTabItem cTabItem = mTabFolder.getItem(point);
if (cTabItem != null) {
final CTabItem [] items = mTabFolder.getItems();
Menu menu = new Menu(mTabFolder);
MenuItem menuItem = new MenuItem(menu, SWT.PUSH);
menuItem.setText("Close");
menuItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
((SlogTabFrame)cTabItem).onClose();
cTabItem.dispose();
}
});
if (items.length < 2) return;
menuItem = new MenuItem(menu, SWT.PUSH);
menuItem.setText("Close All Tabs with same Log source");
menuItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
final LogSource lgsrc = ((SlogTabFrame)cTabItem).getLogSource();
for (int i = 0; i < items.length; i++) {
if (((SlogTabFrame)items[i]).getLogSource().equals(lgsrc)) {
((SlogTabFrame)items[i]).onClose();
items[i].dispose();
}
}
}
});
menuItem = new MenuItem(menu, SWT.PUSH);
menuItem.setText("Close Other Tabs");
menuItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
for (int i = 0; i < items.length; i++) {
if (!items[i].equals(cTabItem)) {
((SlogTabFrame)items[i]).onClose();
items[i].dispose();
}
}
}
});
if (!items[items.length-1].equals(cTabItem)) {
menuItem = new MenuItem(menu, SWT.PUSH);
menuItem.setText("Close Right Tabs");
menuItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
boolean found = false;
for (int i = 0; i < items.length; i++) {
if (found) {
((SlogTabFrame)items[i]).onClose();
items[i].dispose();
} else if (items[i].equals(cTabItem)) {
found = true;
}
}
}
});
}
if (!items[0].equals(cTabItem)) {
menuItem = new MenuItem(menu, SWT.PUSH);
menuItem.setText("Close Left Tabs");
menuItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
for (int i = 0; i < items.length; i++) {
if (!items[i].equals(cTabItem)) {
((SlogTabFrame)items[i]).onClose();
items[i].dispose();
} else {
break;
}
}
}
});
}
menu.setLocation(event.x, event.y);
menu.setVisible(true);
}
}
});
mTabFolder.setFocus();
getDisplay().addFilter(SWT.KeyDown, new Listener() {
@Override
public void handleEvent(Event e) {
for (ToolItem it : mToolItems) {
if (!it.isEnabled())
continue;
int [] keys = (int [])it.getData("KeyAccelerators");
if (keys == null)
continue;
for (int k : keys) {
if (k == (e.stateMask | e.keyCode)) {
it.notifyListeners(SWT.Selection, null);
break;
}
}
}
/*
* if(((e.stateMask & SWT.COMMAND) == SWT.COMMAND) && (e.keyCode
* == SWT.ARROW_RIGHT)) { System.out.print(" mask = " +
* e.stateMask + " key code = " + e.keyCode); int sidx =
* mTabFolder.getSelectionIndex(); if (sidx+1 <
* mTabFolder.getItemCount()) { mTabFolder.setSelection(sidx+1);
* } else if (sidx != 0){ mTabFolder.setSelection(0); } }
*/
}
});
getShell().setSize(1200, 800);
return getShell();
}
public void closeTabFrames() {
for (CTabItem it : mTabFolder.getItems()) {
SlogTabFrame tbf = (SlogTabFrame) it;
tbf.onClose();
}
}
public void closeLeftTabFrames(int index) {
CTabItem it;
if (index < 0)
return;
for (int i = 0; i < index; i++) {
it = mTabFolder.getItem(i);
SlogTabFrame tbf = (SlogTabFrame) it;
tbf.onClose();
it.dispose();
}
}
public void closeThisTabFrames(int index) {
CTabItem it;
if (index >= mTabFolder.getItemCount() || index < 0)
return;
it = mTabFolder.getItem(index);
SlogTabFrame tbf = (SlogTabFrame) it;
tbf.onClose();
it.dispose();
}
public void closeRightTabFrames(int index) {
CTabItem it;
if (index >= mTabFolder.getItemCount())
return;
for (int i = mTabFolder.getItemCount() - 1; i > index; i--) {
it = mTabFolder.getItem(i);
SlogTabFrame tbf = (SlogTabFrame) it;
tbf.onClose();
it.dispose();
}
}
public void run() {
mShell.open();
Display display = getDisplay();
while (!mShell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
SystemConfigs.instance().save();
display.dispose();
}
}