How to create a simple view
There are three options for you to begin.
Create the view from scratch
The only thing that your view needs to do to be a legal Site Manager view is to inherit from the base Site Manager view:
public partial class SimpleView : LSOne.ViewCore.ViewBase
You will then have to overwrite key methods from the base class to get your functionality ready. To get an idea of which functions to overload, see the functions overview below.
Copy Simple view from the Hello World plugin
You can copy almost any view from the Site Manager and customize it based on your needs. To make this process simpler we have created view templates with minimal functionality included. You can find a template view for a simple view in the Hello World plugin from the Site Manager part of the development package. The view is called SimpleView and you can copy it into your plugin. The view contains a shell for the basic functionality of a simple view.
Functions overview
Base functions
This is a list of functions that are most commonly overwritten to add logic to your view:
Base functions |
Description |
void LoadData( bool isRevert) |
Here we load the data for our view. This involves fetching the data object and populating the view. The isRevert variable is false unless the user pressed the Revert button above the Context bar. That function is supposed to revert to the last saved state of the view (basically reverting all changes that have not yet been saved). |
bool DataIsModified() |
In this function you determine if the view needs to be saved or not. Here you check to see if any of your data has been changed, and if it has this function should return true and then the SaveData() function will automatically be called. |
bool SaveData()
|
Here you save the data in your view. Please note that you NEVER call this function yourself, the Site Manager framework handles calling it at appropriate times. |
void OnDelete()
|
Occurs when the user presses the Delete button above the Context bar on the view. |
RecordIdentifier ID
|
Returns the ID of the view and is used to determine if the view is already visible and does not need to be reloaded. Usually you return the ID of the object you are working with, or if you have a list view you return RecordIdentifier.Empty |
string LogicalContextName
|
Returns the string that should appear directly above the Context bar. |
void GetAuditDescriptors( List<AuditDescriptor> contexts)
|
Connects the view with an audit view. See chapter Auditing for more details. |
Sample code walkthrough
public SimpleView(RecordIdentifier objectId)
: this()
{
this.storeID = objectId;
}
private SimpleView()
{
InitializeComponent();
// These are the attributes that the view should support.
Attributes = ViewAttributes.Revert |
ViewAttributes.Save |
ViewAttributes.Delete |
ViewAttributes.Audit |
ViewAttributes.Help |
ViewAttributes.Close |
ViewAttributes.ContextBar;
ReadOnly = !PluginEntry.DataModel.HasPermission(Permissions.SimpleViewPermission);
}
As you can see we have two constructors but one of them is private and not accessible. In the private constructor with no parameter we are setting the functional attributes of the view. These attributes decide which operations the view supports. If you, for example, choose not to include a ViewAttributes.Close parameter in attributes then the user will not get a Close button above the Context bar.
Next we set the ReadOnly property of the view. This flag controls if the view can be saved or not. You see here that we are checking for a permission called SimpleViewPermission. If the user does not have this permission then the view will not save. To learn more about permissions please refer to chapter Permissions.
The last thing that we do in our constructors is to store the ID of the object that we are viewing.
protected override void LoadData(bool isRevert)
{
store = PluginProviders.StoreData.Get(PluginEntry.DataModel, storeID);
tbDescription.Text = store.Text;
}
Here we have our LoadData function. As you can see it fetches the store data object based on the object ID that we have from the constructor. We then populate all of the controls that we have on the view with the store information.
protected override bool DataIsModified()
{
if (tbDescription.Text != store.Text) return true;
return false;
}
protected override bool SaveData()
{
store.Text = tbDescription.Text;
PluginProviders.StoreData.Save(PluginEntry.DataModel, store);
PluginEntry.Framework.ViewController.NotifyDataChanged(this, DataEntityChangeType.Edit, "store", store.ID, null);
return true;
}
Here we have two functions that are always connected. When the Site Manager wants to save the view data (or when the user presses the Save button above the Context bar) it first checks if DataIsModified() returns true. If DataIsModified() return false then we are telling the Site Manager that nothing has changed in the view and there is no reason to save.
We simply check to see if the current values of the controls in the view are the same as the values we used to populate them with in the beginning.
When the DataIsModified() returns true, the Site Manager calls the SaveData() function. There you need to repopulate the data object of the view with the values from the controls of the view. Then we use our datalayer to save the data.
You see an extra line on the bottom of the SaveData function that calls a function called NotifyDataChanged. This function is used to tell other open views that data has changed in our view. Other views can then respond to changes in our view and reload its data or make some other changes. The function required in the receiving view is called OnDataChanged and it has the same parameters as NotifyDataChanged.
This was the simple view next learn about the single list view: How to create a single list view