Responder Overview > Application Framework - Responder > Commands in Responder > Context Menu Command Code Sample |
Version: 10.2.1a |
Product Availability: Responder
This section discusses how to create a context menu (or right-click) command in Responder Explorer or Archive Explorer. The code sample below demonstrates how you may create a right-click command. The Add Responder Command to the User Interface page discusses how to include this command in your Responder Explorer or Archive Explorer user interface.
The right-click command shown below allows the user to select multiple crews on the Crews tab in Responder Explorer and locate the incidents in the Incident grid to which the crews are assigned.
Context menu commands on the Crews tab
Once you completed the project for your custom context menu command it just be added to a custom layout file as well as the ControlStylesConfig.xml or ArchiveStylesConfig.xml. These steps are discussed on the Add Responder Command to User Interface page.
Context Menu Command |
Copy Code
|
---|---|
using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Windows.Forms; using Miner.Windows.Commands; using Miner.Windows; using Miner.Responder.Shared; using Miner.Responder.Shared.Requests; using Miner.Data.Access; using Miner.Data.Decoration; using Miner.Responder.Windows; namespace RxContext { // this command allows the user to select several crews in the crew tree in responder explorer // and find the incidents in the incident grid that are associated with them public class ShowCrewIncidents : ButtonCommand { // assign a string to identify the command private const string _CmdKey = "Show_Crew_Incidents"; // this list will be modified when the user right clicks on one or more crews // to contain a list of those crews selected private List<int> _crews = new List<int>(); public ShowCrewIncidents() : base(_CmdKey) { base.Caption = "Select Incidents for a crew"; base.Tooltip = base.Caption; this.Description = base.Caption; // add event handler to monitor when right click occurs in responder explorer Miner.Data.Decoration.DataSelectionMonitor.DataSelectionChanged += new EventHandler<DataSelectionEventArgs>(DataSelectionMonitor_DataSelectionChanged); } public static string CmdKey { get { return _CmdKey; } } #region ButtonCommand overrides public override bool Enabled { get { return base.Enabled; } set { base.Enabled = value; } } // select incidents when user clicks the command protected override void OnClick(EventArgs args) { // save cursor setting and switch to the hourglass/wait cursor Cursor saveCursor = Cursor.Current; Cursor.Current = Cursors.WaitCursor; try { // get the dataServices so that we can submit requests and get information IDataServices dataServices = ResponderServices.GetDataServices(); // using the FindCriteriaRequest without any criteria returns all rows in the table // get all of the incidents FindCriteriaRequest request = new FindCriteriaRequest(RxDb.Tables.Incidents.TableName); request = (FindCriteriaRequest)dataServices.ExecuteRequest(request); DataTable incidents = request.RequestedDataSet.Tables[RxDb.Tables.Incidents]; bool first = true; foreach (DataRow incidentRow in incidents.Rows) { int incidentID = DbConvert.ToInt32(incidentRow[RxDb.Tables.Incidents.ID], -1); if (incidentID > -1) { //find crews assigned to this incident using the FindCrewAssignmentsDataRequest FindCrewAssignmentsDataRequest findCrewAssignmentDataRequest = new FindCrewAssignmentsDataRequest(incidentID); findCrewAssignmentDataRequest = (FindCrewAssignmentsDataRequest)dataServices.ExecuteRequest(findCrewAssignmentDataRequest); DataTable crews = findCrewAssignmentDataRequest.RequestedDataSet.Tables[RxDb.Tables.CrewAssignments]; if (crews != null) { foreach (DataRow crew in crews.Rows) { int crewid = DbConvert.ToInt32(crew[RxDb.Tables.CrewAssignments.CrewID], -1); if (crewid > -1) { // if the crew is in our list of crews that we have selected, activate the // incident row in the incident grid if (_crews.Contains(crewid)) { if (first) { DataManager.Instance.OnDataRowActivated(incidentRow, "IncidentActivation", false, false, false); first = false; } else { DataManager.Instance.OnDataRowActivated(incidentRow, "IncidentActivation", false, false, true); } } } } } } } } finally { // before we exit the method, switch back to the original cursor Cursor.Current = saveCursor; } } #endregion // if the user is right clicking on a crew which is assigned, then enable this command private void DataSelectionMonitor_DataSelectionChanged(object sender, DataSelectionEventArgs args) { // make sure we are using the crews table (from the crews tab) string tableName = args.TableName; DataRow[] rows = args.GetDataRows(); this.Visible = (tableName == RxDb.TableRepresents.Crews.TableName && rows != null && rows.Length > 0); if (this.Visible) { // recreate the selected crews list based upon what is selected _crews.Clear(); foreach (DataRow row in rows) { // look at assignments DataRow[] assignments = row.GetChildRows(RxDb.Relations.Crews_CrewAssignments); if (assignments.Length > 0) { int id = DbConvert.ToInt32(row[RxDb.Tables.Crews.ID], -1); if (id != -1) { if (!_crews.Contains(id)) { _crews.Add(id); } } } } // if we have at least one crew assignment, set visible to true for the command this.Visible = _crews.Count > 0 ? true : false; } } } } |