CHAPTER 4 INTRODUCTION TO QUADRANT
101
In this case, I’ll click the As Original option, and a check mark will appear next to the value in the
Original column, indicating this is the selected value for resolving the conflict (see Figure 4-29).
Figure 4-29. After selecting As Original to resolve the conflict
The exclamation point (!) next to the Shock Absorbers entity has now changed to an asterisk (*), and
if you close the Changes view, you will see the same indication in the CarComponents Explorer. The data
conflict has been resolved, but the change has not yet been committed. You can take this last step of
committing this change by using Ctrl+S or the File
Save Changes menu option, which will make the
data consistent again.
Finally, there can be situations where the local copy of the data can become stale because
something has changed in the database, but the local copy of the data hasn’t refreshed since the
database change. Suppose the suspension engineering team has decided to go with two shock absorbers
per wheel rather than one, and they have just changed the Description value for Shock Absorbers to Two
for Each Wheel and the corresponding Quantity value from 4 to 8 in the database. This would mean the
local copy of the data displayed by Quadrant is stale and no longer matches what is in the database.
Figure 4-30 shows the resulting Quadrant view.
Download from Wow! eBook <www.wowebook.com>
CHAPTER 4 INTRODUCTION TO QUADRANT
102
Figure 4-30. Stale data in Quadrant after a recent change in the database
This situation is resolved by simply refreshing the data from the data store using the F5 refresh key.
Figure 4-31 shows the result.
Figure 4-31. After using F5 to refresh stale data
Using the Quadrant Explorer Query Bar
The area immediately above the column titles and below the menu bar in the Explorer window is called
the Query Bar. The default entry normally displayed in the Query Bar is the name of the extent, or table,
that is displayed in the Explorer window; in the case of this example, it is Car.Model.CarComponents.
Download from Wow! eBook <www.wowebook.com>
CHAPTER 4 INTRODUCTION TO QUADRANT
103
You can enter any SQL query in this bar to filter what is being displayed in the Explorer pane. For
instance, if you wanted to see the top-level subsystem in the model, you could enter the following query
in the Query Bar:
Car.Model.CarComponents where value.PartOfComponent.Name == "My Car"
The query is executed by pressing the Enter key with the cursor in the Query Bar. Figure 4-32 shows
the result of this query, which is exactly what you would expect: The query returns all of the top-level
subsystems. SQL keywords such as where and value are automatically bolded as the query is entered.
Figure 4-32. Using the Query Bar to find the top-level subsystems
Another example of a query you could perform would be to find all subsystems that have a quantity
greater than 1. Figure 4-33 shows the results of such a query. To make the display more useful, you can
click the Quantity column label to sort by ascending or descending quantities, as indicated by an up or
down arrow to the right of the column label.
Download from Wow! eBook <www.wowebook.com>
CHAPTER 4 INTRODUCTION TO QUADRANT
104
Figure 4-33. Using the Query Bar to find the components with a quantity greater than 1
As a last example, you can add .Count to any query to return the number of records found by the
query. This is useful with very large tables with hundreds or thousands of records. Figures 4-34 and 4-35
show two examples.
Figure 4-34. Getting a count of records for a query
Figure 4-35. Getting a count of all items in the extent
Download from Wow! eBook <www.wowebook.com>
CHAPTER 4 INTRODUCTION TO QUADRANT
105
To return to the normal table display after executing a query, click on the title bar of the Query pane
to make sure the pane is active, press the Esc key to restore the default query, and then press the Enter
key.
If you are not using the Query Bar in an Explorer workpad, you can remove it by right-clicking the
title bar of the workpad, and clicking the Query Bar option in the context menu.
More on Customizing the View
“Know Your Audience” is an important credo in designing user interfaces, and it is just as important
when designing a simple table view as it is for developing an entire application interface. A database
administrator or a power user (one who is experienced in SQL and generating ad hoc queries) is usually
going to want to see the data in a different format than a manager or an end user who is not conversant
in SQL.
You can customize Explorer workpad views in a number of ways to give the user a more productive
and convenient viewing experience. Here are a number of ways you could improve the table view of the
car model for a user who is primarily interested in the domain data rather than running queries or other
more technical aspects:
• Remove the Id column, since this is typically not meaningful information to the
user.
• Move the PartOfComponent column to the right of the Name column, since this is
probably the most significant data after the Name.
• Change the PartOfComponent label to Part Of, since this is a little more user
friendly.
• Move the Level column to the right of the Description column.
• Remove the Query Bar, since this is a feature only power users would need.
Based on these requirements, the sequence of visible columns would be as follows:
• Name
• Part Of
• Description
• Level
• Quantity
To remove the Id column, right-click on any column heading, select the Column Settings option,
and uncheck the Id column by clicking that menu item (see Figure 4-36). (You could also make this
column visible by modifying the generated source for the view, as you will see shortly.)
Download from Wow! eBook <www.wowebook.com>
CHAPTER 4 INTRODUCTION TO QUADRANT
106
Figure 4-36. Hiding the Id column
Making the other changes you’ve decided on will require some simple modifications to the
generated M source code for the view. To do this, bring up the source by invoking the context-sensitive
menu: Right-click in the title bar of the Explorer window, and click the View Source option, as shown in
Figure 4-37.
Figure 4-37. Setting up to view the source code for the table view
Figure 4-38 shows the portion of the source code you’re interested in—the part where the positions
and other properties of the data columns are defined. Note that you are in a Quadrant session now (as
shown in the lower-right corner of the window), rather than the CarModel session, because you are
Download from Wow! eBook <www.wowebook.com>
CHAPTER 4 INTRODUCTION TO QUADRANT
107
changing the source code for several Quadrant modules. Once the modified source for the workpad view
is deployed, you will be back in the CarModel session.
Figure 4-38. Viewing the source code for the Table view
Looking at this code, you can see there is a collection named TableColumns. Each item in this
collection corresponds to the properties of a column in the table and has the following four attributes:
DisplayName, IsVisible, Position, and PropertyName. It’s a simple matter to modify these four attributes
to provide the view you’re after. The IsVisible property of the Id column is set to false because of the
earlier Column Settings change, as you would expect.
To get the table as you would like it to appear, you will need to change the column positions for each
of the column properties, as well as the DisplayName property for two of the columns: PartOfComponent
and Quantity. The code fragment in Listing 4-1 reflects the code changes:
Download from Wow! eBook <www.wowebook.com>
CHAPTER 4 INTRODUCTION TO QUADRANT
108
Listing 4-1. Modified Column Properties to Customize the Table View
M
TableColumns =>
{
{
DisplayName => "Id",
IsVisible => false,
Position => 0,
PropertyName => "Id",
},
{
DisplayName => "Name",
IsVisible => true,
Position => 1,
PropertyName => "Name",
},
{
DisplayName => "Level",
IsVisible => true,
Position => 5,
PropertyName => "Level",
},
{
DisplayName => "Description",
IsVisible => true,
Position => 3,
PropertyName => "Description",
},
{
DisplayName => "Quantity",
IsVisible => true,
Position => 4,
PropertyName => "No.",
},
{
DisplayName => "CarComponents_PartOfComponent",
IsVisible => false,
Position => 5,
PropertyName => "CarComponents_PartOfComponent",
},
{
DisplayName => "PartOfComponent",
IsVisible => true,
Position => 2,
PropertyName => "PartOf",
},
}
Download from Wow! eBook <www.wowebook.com>
CHAPTER 4 INTRODUCTION TO QUADRANT
109
To change the name of the view, locate the portion of the code in the Microsoft.Quadrant module
where the table is defined, and change the DisplayName property from "Table" to "System Designer
Table", as Figure 4-39 illustrates. If you are doing this exercise on your own computer, note that the Name
property of the table (shown in the figure as "Table_0", may be different in the generated code on your
computer. These are system-assigned names, so don’t be concerned if you see these kinds of differences
between your system and what is shown here in the text.
Figure 4-39. Changing the Table view name
To deploy your customized code for the CarModel view, right click in the source code window and
select the Deploy option, as shown in Figure 4-40. An alternative way of doing this is to press Ctrl+F5.
Download from Wow! eBook <www.wowebook.com>
CHAPTER 4 INTRODUCTION TO QUADRANT
110
Figure 4-40. Deploying the source for the modified view
This will bring up a Deploy dialog box (see Figure 4-41) to allow you to select which database
session to use for deployment. Accept the default Use Existing Database Session and click the Deploy
button.
Figure 4-41. Select the existing database session to deploy.
Download from Wow! eBook <www.wowebook.com>
CHAPTER 4 INTRODUCTION TO QUADRANT
111
After you’ve deployed the code changes, if everything goes as planned, you should see a notification
dialog saying the deployment was successful (shown in Figure 4-42).
Figure 4-42. Successful deployment of the modified source
You’ll likely notice that nothing has changed in the Explorer view (shown in Figure 4-43) after the
customized code has been successfully deployed. This is because the customized view was saved under
its new name: System Designer Table. To see the new custom view, click on the down arrow at the right
of the view’s title bar and select the new name.
Figure 4-43. Selecting the customized view: System Designer Table
Figure 4-44 shows your customized view, with the name at the right in the title bar. To show another
way of renaming the view, this time without having to modify the code, let’s change the name from
System Designer Table to System Design Table.
Download from Wow! eBook <www.wowebook.com>
CHAPTER 4 INTRODUCTION TO QUADRANT
112
Figure 4-44. Customized Table view
Right-click in the title bar of the Table view and select the Save View As option, as shown in Figure
4-45.
Figure 4-45. Changing the view name from the title bar context menu
A dialog box will prompt you for the viewer name. Enter System Design Table and click the Save
button. Figure 4-46 shows the new title.
Download from Wow! eBook <www.wowebook.com>
CHAPTER 4 INTRODUCTION TO QUADRANT
113
As the last requirement of the customization, you’ll remove the Query Bar. Right-click on the
CarComponents title bar and click the Query Bar option to uncheck this feature. The Query Bar can be
restored at any time a particular user my want to execute a query by using the same procedure.
Figure 4-46. Removing the Query Bar
Finally, you’d like to save this customized view as the default view for the CarComponents table so
that the user will normally see this view any time she brings up an Explorer view of the table. To do this,
right-click on the window’s title bar and select Set Default View, as shown in Figure 4-47. The name of
the view in the title bar will disappear once it becomes the default view. You can always bring the
standard table view back by clicking the Table option on the right side of the title bar.
Figure 4-47. Setting the table view to be the
default view.
Download from Wow! eBook <www.wowebook.com>
CHAPTER 4 INTRODUCTION TO QUADRANT
114
Summary
In this chapter, I have covered some, but certainly not all, of Quadrant’s functionality; I’ve also shown
how to build and edit a model using Quadrant’s Explorer windows. You used the composite design
pattern to build a self-referential design model for a car. This approach could be used to build any model
that is amenable to analysis using subsystems and components. Mechanical systems, such as cars or
other kinds of machines, can be modeled with this approach, but the composite pattern can be applied
to a wide range of other types of entities. I reviewed the facilities for managing and reverting changes to
data in the model, reconciling concurrency conflicts, and refreshing data from the database any time
you see indications of stale data. I also touched on the use of the Query Bar in the Explorer window and
customizing Explorer views to make them more useful to end users, using both source M code for views
and menu functions.
In sum, here’s a list of what I’ve covered in this chapter:
• Writing and saving model code in an M file
• Creating types and extents (tables) of types
• Deploying your model to the database
• Viewing and editing the model in SQL Server using SQL Server Management
Studio
• Adding new entities and records using Quadrant Explorer views
• Using Quadrant Explorer views to view and edit the model
• Customizing an Explorer view
• Managing changes, concurrency conflicts, and stale data
• Using the Query Bar
Download from Wow! eBook <www.wowebook.com>
Không có nhận xét nào:
Đăng nhận xét