Schultz’s PowerBuilder Notes

PFC Treeview (u_tvs)


I had a GUI where I was selecting available resources from a tree view called tv_resources. The tree view levels were Business Area, Region, Plant, Resource Group (Type), and finally specific machine (resource).

Once a specific machine was selected on the tree view, it could be removed from the available machines and copied to the datawindow of selected resources called dw_selected. Selected resources could later be removed from the selected datawindow and returned to the tree view.

Setting up the Tree View

In the Constructor event of the Tree View:

integer       li_rc
long          ll_root
n_tr          ltr_temp
TreeViewItem  ltvi_root

this.of_SetPrint(TRUE)
this.of_SetLevelSource(TRUE)
li_rc = gnv_app.inv_trRegistration.of_GetByName(gcs_trans_object_name_scheduling, ltr_temp)

//Add the root item
ltvi_root.label = "QG"
ltvi_root.PictureIndex = 1
ltvi_root.SelectedPictureIndex = 1
ltvi_root.Children = True
ll_root = this.InsertItemLast(0, ltvi_root)

//Assign labels, datastores and retrieval arguments for various levels
li_rc = this.inv_levelsource.of_Register(ICI_BUS_AREA, "c_nm", "1", "ds_business_area",  ltr_temp, "bus_area_id")
li_rc = this.inv_levelsource.of_Register(ICI_REGION, "c_nm", "", "ds_region",         ltr_temp, "")
li_rc = this.inv_levelsource.of_Register(ICI_QG_PLANT, "nm", ":parent.1.st_prvnc_cd", "ds_plant", ltr_temp, "")
li_rc = this.inv_levelsource.of_Register(ICI_QG_RES_GRP, "c_nm", ":parent.1.fcl_id, :parent.3.bus_area_id", "ds_resource_group", ltr_temp, "")
li_rc = this.inv_levelsource.of_Register(ICI_QG_RESOURCES, "c_nm", ":parent.1.resrc_grp_id", "ds_resources", ltr_temp, "")

//Assign pictures to the various levels
this.AddPicture("custom041!")
this.AddPicture("custom048!")
this.AddPicture("custom067!")
this.AddPicture("Structure!")
this.AddPicture("ArrangeTables!")
this.AddPicture("UserObject5!")

this.inv_levelsource.of_SetPictureColumn(ICI_QG, "1")
this.inv_levelsource.of_SetPictureColumn(ICI_BUS_AREA, "2")
this.inv_levelsource.of_SetPictureColumn(ICI_REGION, "3")
this.inv_levelsource.of_SetPictureColumn(ICI_QG_PLANT, "4")
this.inv_levelsource.of_SetPictureColumn(ICI_QG_RES_GRP, "5")
this.inv_levelsource.of_SetPictureColumn(ICI_QG_RESOURCES, "6")

this.inv_levelsource.of_SetSelectedPictureColumn(ICI_QG, "1")
this.inv_levelsource.of_SetSelectedPictureColumn(ICI_BUS_AREA, "2")
this.inv_levelsource.of_SetSelectedPictureColumn(ICI_REGION, "3")
this.inv_levelsource.of_SetSelectedPictureColumn(ICI_QG_PLANT, "4")
this.inv_levelsource.of_SetSelectedPictureColumn(ICI_QG_RES_GRP, "5")
this.inv_levelsource.of_SetSelectedPictureColumn(ICI_QG_RESOURCES, "6")

Removing items from tree view (tv_resources) and adding the item to dw_selected.

This sample removes items from tv_resources and adds them to the datawindow dw_selected

////////////////////////////////////////////////////////////////////////////
//
// of_AddResource()
//
// Access: Protected
//
// Arguments: treeviewitem atvi_add
//
// Returnss: integer
//
// Description: Returns resource ids collected in dw_selected.
//
////////////////////////////////////////////////////////////////////////////
// Revision history:
// -----------------
// 04/05/01 fjs Created
//
////////////////////////////////////////////////////////////////////////////
n_ds    lds_resources
integer li_rc, li_count, li_col
long    ll_handle, ll_parent_handle, ll_row, ll_key, ll_resrc_grp, ll_ids_row
string  ls_lable, ls_data

if atvi_add.level <> ICI_QG_RESOURCES then
   Return NO_ACTION
end if

//Get values
ls_lable  = atvi_add.label
ll_handle = atvi_add.itemhandle
ls_data   = atvi_add.data
li_rc = tv_resources.SelectItem(ll_handle)
ll_parent_handle = tv_resources.FindItem(ParentTreeItem!, ll_handle)
li_rc        = tv_resources.inv_levelsource.of_GetDataRow( ll_handle, lds_resources, ll_row )
if li_rc = -1 then
   MessageBox("of_add_resource", "error with of_GetDataRow()")
   Return FAILURE
end if
ll_key       = lds_resources.GetItemNumber(ll_row, "resrc_id")
ll_resrc_grp = lds_resources.GetItemNumber(ll_row, "resrc_grp_id")

// Copy values to datastore.  This datastore is needed if the item is returned to
// the treeview
if NOT IsValid(ids_resources) then
   ids_resources = CREATE n_ds
   ids_resources.dataobject= 'ds_resources'
end if
lds_resources.RowsCopy(ll_row, ll_row, Primary!, ids_resources, 1, Primary!)

//Delete item from treeview
tv_resources.Event pfc_deleteitem()

//Insert rows into datawindow
ll_row = dw_selected.InsertRow(0)
dw_selected.SetItem(ll_row, "s_label", ls_lable)
dw_selected.SetItem(ll_row, "n_key", ll_key)
dw_selected.SetItem(ll_row, "handle", ll_handle)
dw_selected.SetItem(ll_row, "parent_handle", ll_parent_handle)
dw_selected.SetItem(ll_row, "resrc_grp_id", ll_resrc_grp)
dw_selected.SetItem(ll_row, "ltvi_data", ls_data)

dw_selected.Sort()

cb_remove.enabled = TRUE

Return SUCCESS

Returning items in dw_selected back to the tree view

If an item is removed from a treeview, special care must be done before returning it. Note use of datastore ids_resources. It contains the same datawindow as the level.

 ////////////////////////////////////////////////////////////////////////
//
// Clicked for cb_remove
//
// Description: Remove item from dw_selected and return it to treeview.
//
////////////////////////////////////////////////////////////////////////////
// Revision history:
// -----------------
// 04/05/01 fjs Created
//
////////////////////////////////////////////////////////////////////////////

treeviewitem ltvi_remove
long         ll_parent_handle, ll_row, ll_findrow, ll_removehandle
string       ls_label, ls_find

ll_row = dw_selected.GetRow()
if ll_row > 0 then
   ls_label          = dw_selected.GetItemString(ll_row, "s_label")
   ll_parent_handle  = dw_selected.GetItemNumber(ll_row, "parent_handle")

   ls_find = 'c_nm = "' + ls_label + '"'
   ll_findrow = ids_resources.Find(ls_find, 0, ids_resources.RowCount())
   if ll_findrow > 0 then
      ll_removehandle = tv_resources.Event pfc_additem(ll_parent_handle, ids_resources, ll_findrow)
      tv_resources.GetItem(ll_removehandle, ltvi_remove)
      ltvi_remove.label = ls_label
      ltvi_remove.level = ICI_QG_RESOURCES
      ltvi_remove.PictureIndex = ICI_QG_RESOURCES
      ltvi_remove.SelectedPictureIndex = ICI_QG_RESOURCES
      tv_resources.SetItem(ll_removehandle, ltvi_remove)
      dw_selected.DeleteRow(ll_row)

      //disable this button if no more items exist in dw_selected.
      if dw_selected.RowCount() < 1 then
         this.Enabled = False
      end if
   else
      MessageBox("error", "Unable to find '" + ls_find + '"')
   end if
end if
About these ads

June 17, 2008 - Posted by | 3. PFC, PFC Standard User Objects | , , , , , , , , , , , , , , ,

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: