Share My Creation MashPropertyBag

Hi there

THIS PROJECT IS NO LONGER BEING MAINTAINED, THERE IS A BETTER ALTERNATIVE, SEARCH FOR B4XPREFERANCE DIALOG

Version 1.07 (with source code) attached below.

The aim has been to make this lib faster and thus re-wrote the tableview functionality to be more functional and quick. The source code is attached (if you want most of the events) and I have removed these for most controls for my needs, only toggle and combo fire events)

Other Examples of use (same library, attached herein)

TableView: Magical Inline Editing
Master Details using EditableTableView with CRUD
MashSkeletor

To Do

TableView paging and printing...


Version 1.04 attached below

PropertyBag.gif


What's New

  • Slider
  • Spinner
  • Radio Group
  • Toggle Button
  • Toggle Icon Button
  • Toggle Switch (experimenting with DonManfred's toggle switch)
  • Using designer views - better performance
  • fixed some minor bugs

Version 1.03 attached below

It is with pleasure to post here my latest creation with B4J, well this will be a growing project as for now I have been able to work my own propertybag. Reason, well...

PropertyBag.gif


Problem Statement

I'm working on a tool and noted that my views were getting more and more and my code included as all the controls e.g. textboxed, checkboxes, comboboxes. I knew this will be one day be an admin nightmare for me. Well, I promised myself that I wont change what works.

So I started this three days ago. I did some research here of everything tableviews did, well, I have never used a TableView before and my oh my, I was missing out.

Anyway to cut a long story short, here is it. So for me, instead of creating multiple controls inside views, I'm just using this, saves me a lot of time. I'ts not fancy, it just works for my purposes.

What you can do???

For now these controls, TextField, ComboBox, CheckBox, ColorPicker, FilePicker, Label can be used.
The resulting content of the PropertyBag are a map that can be set / also get in the grid.

You can also hide the third column. The next version of this will be in table format that you can edit, save etc.

FilePicker Credits:

Thanks to @rwblinn for his amazing ButtonTextField that I used here for the FilePicker here and offcourse @Erel
 

Attachments

  • MashPropertyBag Source Code 1.07.zip
    60.9 KB · Views: 570
  • MashPropertyBag Lib 1.07.zip
    190.2 KB · Views: 487
  • MashPropertyBag Lib 1.08.zip
    190.2 KB · Views: 562
  • MashPropertyBag Source Code 1.08.zip
    109.5 KB · Views: 564
Last edited:

Mashiane

Expert
Licensed User
Longtime User
Create your view and add a TableView in it, the attached one uses vColumns with a tableview called tblView. You can have the code below running in a sub after you have loaded the layout.

B4X:
' initialize the control, we want to trap file selected of "PropertyBag", this event does not show in the designer, so type it in
    clsTableView.Initialize(tblView, Me, "PropertyBag")
    'you can specify any valid date format for the date picker control.
    clsTableView.DateFormat = "yyyy-MM-dd"
    ' set folder to look for images from
    clsTableView.ImagesFolder = File.DirApp
    'make it a property bag: tell it to have three columns, Property, Value and Description
    clsTableView.SetPropertyViewer
    'hide the description column, if you want
    'clsTableView.HideColumn("Description")
    'same as tableview set columns, this specifies sortable, widths, etc. Remember there is only 3 columns for now with default properties
    clsTableView.SetColumns
    ' add a property for first name, the content here will be a textbox, the last variable passed here is the map property to store the content
    clsTableView.AddTextBoxProperty("First Name",  "", "First Name of a person", "FirstName")
    ' add a propert for last name
    clsTableView.AddTextBoxProperty("Last Name",  "", "Last Name of a person", "LastName")
    Dim xl As List
    xl.Initialize
    xl.Add("Male")
    xl.Add("Female")
    ' what is the gender of the person
    clsTableView.AddComboBoxProperty("Gender", "Male", "The gender of the person", "ActionButton", xl)
    clsTableView.AddDatePickerProperty("Date of Birth","","The date of birth", "DateOfBirth")
    clsTableView.AddColorPickerProperty("Eye Color", fx.Colors.Green, "The eye color of the person", "EyeColor")
    clsTableView.AddCheckBoxProperty("Living", "1", "Is the person living", "Living")
    clsTableView.AddFilePickerProperty("Profile Picture","","Profile Picture","ProfilePicture")
    clsTableView.AddLabelProperty("End of Record","*****","End of record","eof")
    'this just for demonstrating how to set individual properties
    ' set the external combo box to property values
    jMash.ComboBoxFromList(cboProperty,clsTableView.PropertyNames,True)
    ' set existing file to property bag, you can save your map as a table record and read it to the property bag
    Dim OrMap As Map
    Dim OrName As String
    OrName = "AneleMbanga.map"
    If File.Exists(File.DirApp,OrName) Then
        OrMap = File.ReadMap(File.DirApp,OrName)
        Log(OrMap)
        clsTableView.SetPropertyBag(OrMap)
    End If
 

Mashiane

Expert
Licensed User
Longtime User
Earlier I showed how to pass a map to the propertybag, this here saves the propertybag to a file

B4X:
Sub btnSave_Action
    ' get the properties including any changes made
    clsTableView.GetPropertyBag
    ' get the first and last names
    Dim fName As String
    Dim lName As String
    Dim keyFile As String
    fName = clsTableView.GetProperty("First Name")
    lName = clsTableView.GetProperty("Last Name")
    keyFile = fName & lName & ".map"
    ' file map record to file, the details are stored in a map called PropertyBag
    File.WriteMap(File.DirApp, keyFile,clsTableView.PropertyBag)
   
End Sub

It is important that before you can process the propertybag contents you call xxx.GetPropertyBag, this will ensure you have the latest contents.
 

Mashiane

Expert
Licensed User
Longtime User
This is an update of this class however can be turned into a library.

1. Compress the Files to res.MashPropertyBag.jar, copy this to your Libraries folder.
2. Copy FontAwesome.jar and MaterialIcons.jar from the internal libraries folder to the external folders (it does not work without this process)
3. Refer it to your projects..
4. Drop it on your Designer

The example below loads an existing map file..

B4X:
Dim xl As List
    xl.initialize
    etvComponent.NoAlternateRows
    etvComponent.AddLabelProperty1("Some description goes here...")
    etvComponent.AddTextBoxProperty("TextBox","","A textbox property","TextBox")
    etvComponent.AddCheckBoxProperty("CheckBox",0,"This is a checkbox","CheckBox")
    etvComponent.AddBiggerTextAreaProperty("BiggerTextArea","","","BiggerTextArea")
    etvComponent.AddTextAreaProperty("TextArea","","This is a text area","TextArea")
    xl.AddAll(Array As String("One","Two","Three"))
    etvComponent.AddCheckComboBoxProperty("CheckCombo","","Check Combo","CheckCombo",xl)
    etvComponent.AddComboBoxProperty("Combo","","Combo","Combo",xl)
    'etvComponent.AddColorPickerProperty("ColorPick","","Color Picker","ColorPick")
    etvComponent.AddDatePickerProperty("DatePicker","","Date Picker","DatePicker")
    etvComponent.AddIconPickerProperty("IconPicker","","Icon Picker","IconPicker")
    etvComponent.AddImageFileChooserProperty("ImageFile","","Image File","ImageFile")
    etvComponent.AddButton("Save","","Save the bag","btnSave")
    
    'if we have a map saved, load it
    If File.Exists(File.DirApp,"propbag.txt") Then
        Dim pb As Map = File.ReadMap(File.DirApp,"propbag.txt")
        etvComponent.SetPropertyBag(pb)
    End If

We are trapping the button here, so we can extract the contents of the propertybag by...

B4X:
Sub etvComponent_Clicked (Property As String, Value As Map)
    'properties are returned in lowercase
    Select Case Property
        Case "btnsave"
            'save the propertybag map to a file
            etvComponent.GetProperties
            File.WriteMap(File.DirApp,"propbag.txt",etvComponent.propertybag)
    End Select
End Sub

PropBag.png
 

Attachments

  • MashPropertyBag.zip
    15.8 KB · Views: 485
Top