Disable default behaviour for the keystrokes that listbox responds in zk - zk

Lisbox in zk by default answers keystrokes like page up and page down, up and down keys and home and end keys. Ex: I want the currently selected row to come down when user hits down arrow. I gave all above keys in ctrlKeys attribute, to call the back-end bean when specific keys are hit. But it doesn't call for above keys. It calls back end bean for keys like "delete". I want to disable the default behavior for above keys for listbox in zk. Kindly help me. This is the ctrlKeys attribute I gave,
ctrlKeys="#home#end#del#up#down#pgup#pgdn"
onCtrlKey="#command('answerKeyStroke',keyCode=event.getKeyCode(), id=0)"

Maybe you should look at this question.
From that answer, this is the solution (just this is a combobox in stead of a listbox)
<zk xmlns:w="client">
<combobox>
<attribute w:name="_doKeyDown"><![CDATA[
function (evt) {
var keyCode = evt.keyCode;
if (keyCode != 38 && keyCode != 40) {
this.$_doKeyDown(evt);
}
}
]]></attribute>
<comboitem label="item one" />
<comboitem label="item two" />
<comboitem label="item three" />
</combobox>
</zk>

Related

One WPF Window that displays different DataGrid's based on Menu selection?

I want to display different DataSource (SQL) queries in one 'DataGrid' based on Menu selections. Am I barking up the wrong tree by looking at UserControl's? How would this be implemented?
Edit:
I've finally found Changing user control on list selection which seems to answer my question pretty well, or at least modifies my question a little. So one Menu is to list all "Parts" available. The other Menu has MenuItems that correspond to locations and ultimately the inventory of said Parts at each location. Currently I am using a Click handler for each MenuItem and create a new instance of a specific UserControl for Parts and each location.
private void menuParts_Click(object sender, RoutedEventArgs e)
{
dgRoot.Children.Clear();
UserControl control = new ucParts();
this.dgRoot.Children.Add(control);
this.Title = "Inventory Manager - Parts";
}
and
private void menuSG1_Click(object sender, RoutedEventArgs e)
{
dgRoot.Children.Clear();
UserControl control = new ucSG1();
this.dgRoot.Children.Add(control);
this.Title = "Inventory Manager - SG1";
}
My question now is, can I create a reusable UserControl template that the Click handler can feed the location name to? The data is displayed, formatted, used, etc the same way, it's ultimately just the underlying DataSource query that is different.
You seemingly CAN do this. Just create the generic usercontrol Grid in my case.
MainWindow.xaml
<DockPanel>
<Menu DockPanel.Dock="Top" Name="menuMain" Height="27" HorizontalAlignment="Stretch" VerticalAlignment="Top" ScrollViewer.VerticalScrollBarVisibility="Disabled" >
<MenuItem Header="Parts">
<MenuItem Name="menuParts" Header="Parts" Click="menuParts_Click"/>
<Separator />
<MenuItem Name="addPart" Header="Add Part" Click="addPart_Click" />
</MenuItem>
<MenuItem Header="Inventory">
<MenuItem Name="menuBrady" Header="Brady" Click="menuBrady_Click"/>
<MenuItem Name="menuCO" Header="Community" Click="menuCO_Click"/>
<MenuItem Name="menuPoly" Header="Poly" Click="menuPoly_Click"/>
<MenuItem Name="menuSG1" Header="SG1" Click="menuSG1_Click"/>
<MenuItem Name="menuWS" Header="West Shore" Click="menuWS_Click"/>
</MenuItem>
</Menu>
<Grid Name="dgRoot" />
</DockPanel>
Then as shown in my Click handlers above, use them!

Events selection is considered as event moving

I'm using a daypilot scheduler for a booking hotel's rooms.
I want to use events multiselection but when I enable this feature the scheduler is considering it as an event moving and not a selection
I did as following
AllowMultiSelect="true"
OnEventSelect="MonthScheduler_EventSelect"
EDIT:
<div id="colright" style="margin-left:20px;">
<div class="row">
<DayPilot:DayPilotScheduler ID="MonthScheduler"
OnEventMenuClick="Scheduler_EventMenuClick"
runat="server"
RowHeaderWidthAutoFit="true"
DataStartField="Start"
DataEndField="End"
DataTextField="Name"
DataValueField="Id"
DataResourceField="ressource"
HeaderFontSize="9pt"
EventHeight="25"
EventFontSize="11px"
RowHeaderWidth="200"
Width="1050"
Height="500"
HeightSpec="Fixed"
ShowToolTip="false"
CellDuration="1440"
CellGroupBy="Week"
TreeEnabled="true"
TreeIndent="15"
ClientObjectName="dps1"
UseEventBoxes="Always"
EnableViewState="true"
ScrollLabelsVisible="false"
BubbleID="DayPilotBubble1"
ResourceBubbleID="DayPilotBubble1"
DataTagFields="Description"
TimeRangeSelectedHandling="PostBack"
OnTimeRangeMenuClick="DayPilotScheduler1_TimeRangeMenuClick"
OnEventResize="MonthScheduler_EventResize"
OnTimeRangeDoubleClick="MonthScheduler_TimeRangeDoubleClick"
OnTimeRangeSelected="MonthScheduler_TimeRangeSelected"
DragOutAllowed="false"
EventResizeHandling="PostBack"
EventMoveHandling="PostBack"
OnEventMove="MonthScheduler_EventMove"
xCellBubbleID="DayPilotBubble1"
OnBeforeEventRender="MonthScheduler_BeforeEventRender"
OnBeforeResHeaderRender="MonthScheduler_BeforeResHeaderRender"
OnBeforeTimeHeaderRender="MonthScheduler_EventMove_BeforeTimeHeaderRender"
EventMovingStartEndEnabled="true"
EventResizingStartEndEnabled="true"
OnScroll="MonthScheduler_Scroll"
Theme="scheduler_traditional"
BorderColor="#666666"
OnResourceCollapse="MonthScheduler_ResourceCollapse"
TimeRangeSelectingStartEndFormat=""
AllowMultiSelect="true"
OnEventSelect="MonthScheduler_EventSelect"
EventClickHandling="Select"
ContextMenuSelectionID="DayPilotMenuSelection"
TreePreventParentUsage="true"
HourNameBackColor="#F0F0F0">
</DayPilot:DayPilotScheduler>
</div>
<DayPilot:DayPilotBubble ID="DayPilotBubble1" runat="server" ClientObjectName="bubble"
Width="0" OnRenderEventBubble="MonthScheduler_RenderEventBubble" OnRenderContent="MonthScheduler_RenderContent"
Corners="Rounded" Position="Mouse" Animated="false" >
</DayPilot:DayPilotBubble>
<DayPilot:DayPilotMenu ID="DayPilotMenu1" CssClassPrefix="menu_default"
runat="server" ClientObjectName="DayPilotMenu1" MenuTitle="Action" ShowMenuTitle="true">
<DayPilot:MenuItem Action="PostBack" Command="Modifier" Text="Edit" />
<DayPilot:MenuItem Action="PostBack" Command="Delete" Text="Delete" />
</DayPilot:DayPilotMenu>
<DayPilot:DayPilotMenu ID="DayPilotMenuSelection" runat="server" ZIndex="10003" MenuTitle="Action" CssClassPrefix="menu_default" >
<DayPilot:MenuItem Action="PostBack" Command="New" Text="Add new" />
<DayPilot:MenuItem Action="PostBack" Command="Old" Text="Add old" />
</DayPilot:DayPilotMenu>
</div>
and this my event select (which is not fired on selection)
protected void MonthScheduler_EventSelect(object sender, DayPilotEventArgs e)
{
//do }
You need to map one of the user actions to the "Select" behavior.
There are two basic options:
Click
EventClickHandling="Select"
Double click
EventDoubleClickHandling="Select"
See also event selecting topic in the docs. This will of course prevent you from using this action for another behavior (like opening the edit dialog). If you want to open the edit dialog you can also add a special "edit" icon (using active areas).
The upcoming version (8.0) will also support "rectangle event selecting" that will let you select multiple events using Shift + drag, just like in desktop file manager applications. See a preview here:
http://javascript.daypilot.org/sandbox/scheduler/eventmultiselecting.html

I want to use the onSelect event of a ZK tree which is rendered through MVVM

Here is the zul file for reference
<?page title="MVVM Tree POC"?>
<zk>
<borderlayout height="800px">
<west size="25%"></west>
<center>
<window apply="org.zkoss.bind.BindComposer"
viewModel="#id('vm') #init('com.nagarro.viewmodel.TreeViewModel')"
title="Dynamic Tree" border="normal">
<tree checkmark="true" model="#bind(vm.treeModel)"
onSelect="#command('select')" >
<template name="model" var="node" status="s">
<treeitem checkable="#load(node.checkable)"
open="true">
<treerow style="text-align:center;">
<treecell
label="#bind(node.data.firstName)" style="text-align:left;">
</treecell>
</treerow>
</treeitem>
</template>
</tree>
</window>
</center>
</borderlayout>
</zk>
There is a "onSelect" event in the tree tag and there are checkboxes for some treeItems only. Now, I want to create certain components like a combobox for the corresponding tree row when its checkbox is selected. I am trying to do it with the onSelect event of the tree but the problem is I need to pass the reference of the selected checkbox which I am unable to pass as the onSelect event is kept outside the scope of the template through which treeItems are getting rendered.
Is there any other way out to do what I want
This is the page which I get through the above zul file.
I want to know which checkbox is selected ?
You can pass any parameter on every event like that (from ZK docs):
<button label="Delete" onClick="#command('delete', item=item)"/>
and use this parameter in your java code:
#Command
public void delete(#BindingParam("item") Item item ) {
//do some stuff based on what item you've picked
}
In your case I would move onSelect-Event from Tree-Component to Treeitem, like this:
<tree checkmark="true" model="#bind(vm.treeModel)">
<template name="model" var="node" status="s">
<treeitem checkable="#load(node.checkable)"
open="true" onSelect="#command('select', nameParameter=node.data.firstName">
<treerow style="text-align:center;">
<treecell
label="#bind(node.data.firstName)" style="text-align:left;">
</treecell>
</treerow>
</treeitem>
</template>
</tree>
and use parameter in your #Command-method:
#Command
public void select(#BindingParam("nameParameter") String nameParameter ) {
System.out.println(nameParameter + " selected");
}
See ZK MVVM > Advance > Parameter Docs for more information
This is an issue I often run into. My solution has always been to attach data to the component itself; keep a database entity's id or an object itself on the checkbox for retrieval during the event.
checkbox.setAttribute("myAttributeName", myAttributeValue);
This requires a cast to retrieve, which is unfortunate, but with some best practices you can do so confidently.

ASPxGridView: How to disable GridViewDataColumn when a GridViewDataCheckColumn is checked or unchecked?

I have an ASPxGridView with the following columns:
<dx:GridViewDataCheckColumn FieldName="ProtocolEnabled" Caption="Protocol Enabled">
<DataItemTemplate>
<asp:Literal ID="ltProtocolEnabled" runat="server" />
</DataItemTemplate>
</dx:GridViewDataCheckColumn>
<dx:GridViewDataColumn FieldName="ProtocolCount" Width="0" Caption="Protocol Count">
The checkbox column has a template with a literal in it so I can display Yes/No instead of an empty checkbox, but that's probably TMI. What I need to do is this:
In edit mode: When ProtocolEnabled is checked, I need to enable the ProtocolCount textbox. When ProtocolEnabled is unchecked, I need to disable ProtocolCount and set its text to 0.
I am not asking for a step-by-step, but a general pointer in the right direction. I would like to use callbacks if at all possible. I also promise I will not delete this question as you are answering it =P.
Update: Thanks to answerer, I was sent in the direction I needed to go. Here's the code I used:
<dx:GridViewDataCheckColumn FieldName="ProtocolEnabled" Caption="Protocol Enabled" CellStyle-HorizontalAlign="Left">
<DataItemTemplate>
<asp:Literal ID="ltProtocolEnabled" runat="server" />
</DataItemTemplate>
<PropertiesCheckEdit>
<ClientSideEvents CheckedChanged="function(s,e) {ProtocolEnabledChecked(s);}" />
</PropertiesCheckEdit>
</dx:GridViewDataCheckColumn>
<dx:GridViewDataColumn FieldName="ProtocolCount" Width="0" Caption="Protocol Count">
function ProtocolEnabledChecked(ck) {
var x = gvApplicationServer.GetEditor("ProtocolCount");
if (ck.GetValue()) {
x.enabled = true;
}
else {
x.SetValue(0);
x.enabled = false;
}
}
It's clientside code instead of callback.
First of all Check this for Accessing Controls Contained within Templates
To show Yes/No
On HtmlRowCreated Event access control and set it's text property after finding the control in the
Literal literal = ASPxGridView1.FindRowCellTemplateControl(e.VisibleIndex,
ASPxGridView1.Columns["Name"] as GridViewDataColumn, "ASPxButtonEdit1") as Literal ;
literal.Text = (bool)grid.GetRowValues(e.VisibleIndex, "columnName") ? "Yes" : "No";
In Edit Row Template Do as you did as above..
If you want to do some client side functionality then .. create client side event OnClientClick and use checkbox client side method. chkclientinstanceName.getValue(); or other to check with it is checked or not..
these controls are client accessible so enable/ disable by using txtClientName.SetEnabled(true/false);
for more help go to the
DevExpress.Web.ASPxEditors ClientScript namespace..
Try this step by step .. hope it will be helpful..

OpenXML - Limiting the number of buttons showed in the group in custom MS-Word ribbon

I want to limit the number of buttons in the group of a ribbon in Word 2007 as the buttons are getting generated on the basis of data in the database. See the pic below. . I wanted to have limited number, say 6 or so in the ribbon with a dialogboxlauncher which when clicked will open a pane showing all the buttons. Is there any way of doing the same. Can somebody also tell me how to create that pane when somebody clicks on the dialogbox launcher?
The way I did it is to load some (say 6) of the items in the ribbon as buttons and add all the items as the CustomXMlPart in the document. In the document, I added a user control which contained a listbox. On the ribbon load, I get all the items from the CustomXmlPart and put them in the listbox. On the dialogbox launcher button click, I show/hide the user control to show all the items in the list.
Following are the steps in detail :-
a) Get all the items from the database and keep that in collection.
b) Generate the ribbon XML like the following withe the 6 buttons from the above collection :-
<?xml version="1.0" encoding="utf-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="RibbonLoad">
<ribbon>
<tabs>
<tab id="tabMyTab" label="MyTab">
<group id="grpItems" label="My items">
<button id="test1" label="test1"/>
<button id="test2" label="test2"/>
<button id="test3" label="test3"/>
<button id="test4" label="test4"/>
<button id="test5" label="test5"/>
<button id="test6" label="test6"/>
<dialogBoxLauncher>
<button id="btnShowAllItems" label="Show all custom tags" onAction="ShowAllItems" />
</dialogBoxLauncher>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
c) Add the collection as the CustomXMLPart to the document :-
static void AddCustomTableXmlPart(WordprocessingDocument document)
{
MainDocumentPart mainDocumentPart = document.MainDocumentPart;
XDocument customTagsXml = GetAllItemsAsCustomXML();
if (mainDocumentPart.GetPartsCountOfType<CustomXmlPart>() > 0)
mainDocumentPart.DeleteParts<CustomXmlPart>(mainDocumentPart.CustomXmlParts);
//Add a new customXML part and then add content
var customXmlPart = mainDocumentPart.AddCustomXmlPart(CustomXmlPartType.CustomXml);
//copy the XML into the new part...
using (var ts = new StreamWriter(customXmlPart.GetStream()))
{
ts.Write(customTagsXml.ToString());
ts.Flush();
}
}
d) Go to the developer tab of your docm file, add a UserForm to the project and add a listbox to it. Write a subroutine which would load the items from the CustomXMlPart added already to the document and add those items to the listbox in the userform. Something like below :-
Sub LoadItems()
Dim totalItemsCount As Integer
totalItemsCount = ActiveDocument.CustomXMLParts(ActiveDocument.CustomXMLParts.Count).SelectNodes("//Items")(1).ChildNodes.Count
Dim item As String
For i = 1 To totalItemsCount
item = ActiveDocument.CustomXMLParts(ActiveDocument.CustomXMLParts.Count).SelectNodes("//Items")(1).ChildNodes(i).text
' I had to remove the spaced before adding it as It was throwing errors
item = Replace(item, " ", Empty)
If Len(item) > 1 Then
ItemUserControl.lstItems.AddItem pvargItem:item
End If
Next i
End Sub
e) Define the sub named RibbonLoad which is called from the onLoad event of the ribbon (check the RibbonXML). Call the LoadItems sub from this RibbonLoad sub.
Sub RibbonLoad(ribbon As IRibbonUI)
LoadItems
End Sub
f) Define the following sub which will show/hide the user control. This is called on the onAction of the dialogBoxLauncher button. (see the RibbonXML)
Sub ShowAllItemss(control As IRibbonControl)
If ItemsUserControl.Visible = False Then
If ItemsUserControl.lstItems.ListCount = 0 Then
LoadCustomTags
End If
ItemsUserControl.Show
Else
ItemsUserControl.Hide
End If
End Sub