|
1
|
|
|
package ui |
|
2
|
|
|
|
|
3
|
|
|
import ( |
|
4
|
|
|
"fmt" |
|
5
|
|
|
|
|
6
|
|
|
"fyne.io/fyne/v2" |
|
7
|
|
|
"fyne.io/fyne/v2/container" |
|
8
|
|
|
"fyne.io/fyne/v2/data/binding" |
|
9
|
|
|
"fyne.io/fyne/v2/layout" |
|
10
|
|
|
"fyne.io/fyne/v2/widget" |
|
11
|
|
|
"github.com/rchargel/hdfs-explorer/files" |
|
12
|
|
|
"github.com/rchargel/hdfs-explorer/log" |
|
13
|
|
|
) |
|
14
|
|
|
|
|
15
|
|
|
var fileSystemRepo files.FileSystemRepository |
|
16
|
|
|
|
|
17
|
|
|
func init() { |
|
18
|
|
|
repository, err := files.GetFileSystemRepository() |
|
19
|
|
|
|
|
20
|
|
|
if err != nil { |
|
21
|
|
|
log.Error.Fatal(err) |
|
22
|
|
|
} |
|
23
|
|
|
fileSystemRepo = repository |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
func fileSystemNames() *[]string { |
|
27
|
|
|
list, err := fileSystemRepo.List() |
|
28
|
|
|
if err != nil { |
|
29
|
|
|
ShowFatalError(err) |
|
30
|
|
|
} |
|
31
|
|
|
names := make([]string, len(list)) |
|
32
|
|
|
for i, fileSystem := range list { |
|
33
|
|
|
names[i] = fileSystem.Name |
|
34
|
|
|
} |
|
35
|
|
|
return &names |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
func OpenFileSystemRepoManager() { |
|
39
|
|
|
fileSystems := binding.BindStringList(fileSystemNames()) |
|
40
|
|
|
name := binding.BindString(nil) |
|
41
|
|
|
description := binding.BindString(nil) |
|
42
|
|
|
addresses := binding.BindString(nil) |
|
43
|
|
|
|
|
44
|
|
|
fsList := fileSystemList(fileSystems) |
|
45
|
|
|
form := createForm(name, description, addresses) |
|
46
|
|
|
dialog := container.NewHBox(fsList, form) |
|
47
|
|
|
|
|
48
|
|
|
ShowCustomDialog( |
|
49
|
|
|
"Connections", |
|
50
|
|
|
dialog, |
|
51
|
|
|
widget.NewButton("New", func() { |
|
52
|
|
|
val := fmt.Sprintf("Next %d", fileSystems.Length()+1) |
|
53
|
|
|
fileSystems.Append(val) |
|
54
|
|
|
}), |
|
55
|
|
|
) |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
func createForm(nameData, descriptionData, addressData binding.String) *fyne.Container { |
|
59
|
|
|
nameLabel := widget.NewLabel("Name: ") |
|
60
|
|
|
nameEntry := widget.NewEntryWithData(nameData) |
|
61
|
|
|
descriptionLabel := widget.NewLabel("Description: ") |
|
62
|
|
|
descriptionEntry := widget.NewEntryWithData(descriptionData) |
|
63
|
|
|
descriptionEntry.MultiLine = true |
|
64
|
|
|
addressLabel := widget.NewLabel("Addresses (new line sperated):") |
|
65
|
|
|
addressEntry := widget.NewEntryWithData(addressData) |
|
66
|
|
|
addressEntry.MultiLine = true |
|
67
|
|
|
|
|
68
|
|
|
return container.NewVBox( |
|
69
|
|
|
nameLabel, |
|
70
|
|
|
nameEntry, |
|
71
|
|
|
descriptionLabel, |
|
72
|
|
|
descriptionEntry, |
|
73
|
|
|
addressLabel, |
|
74
|
|
|
addressEntry, |
|
75
|
|
|
) |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
func fileSystemList(data binding.DataList) *fyne.Container { |
|
79
|
|
|
list := widget.NewListWithData( |
|
80
|
|
|
data, |
|
81
|
|
|
func() fyne.CanvasObject { |
|
82
|
|
|
return widget.NewLabel("Connections") |
|
83
|
|
|
}, |
|
84
|
|
|
func(i binding.DataItem, o fyne.CanvasObject) { |
|
85
|
|
|
o.(*widget.Label).Bind(i.(binding.String)) |
|
86
|
|
|
}, |
|
87
|
|
|
) |
|
88
|
|
|
return container.New(layout.NewMaxLayout(), list) |
|
89
|
|
|
} |
|
90
|
|
|
|