因此,我在GWT中有一个“ FlexTable”,我需要在某些单元格上单击鼠标右键来下拉动作列表。鼠标左键单击以检索单元格的“ rowIndex”,我只需使用ClickEvent方法“ getCellForEvent(event).getRowIndex()”。但是在纯GWT中没有右键单击处理程序。因此,我决定使用需要ContextMenuEvent的ContextMenuHandler。而且,当然,我不能将ContextMenuEvent放入ClickEvent方法“ getCellForEvent”中。有什么解决办法吗?或者,也许有人知道更简单的方法来在“ FlexTable”上单击鼠标右键来下拉列表。
答案 0 :(得分:2)
我已经为CellTable或DataGrid小部件完成了此操作,但没有为FlexTable完成此操作。对于前者,我将一个处理程序对象应用于整个网格小部件,并使用该事件计算出事件发生的行或单元格。我看不到如何使用FlexTable来完成。
使用FlexTable,黑客可以为每个单元格创建一个处理程序对象,并在创建时将其告知单元格/行。像这样:
cell.addDomHandler(new ContextMenuHandler() {
@Override
public void onContextMenu(ContextMenuEvent event)
{
// stop the browser from opening the context menu
event.preventDefault();
event.stopPropagation();
NativeEvent nativeClickEvent = event.getNativeEvent();
displayPopupMenuForCell(cell, nativeClickEvent);
}
}, ContextMenuEvent.getType());
在上面,cell
必须是一个小部件。因此,您需要在HTMLTable中获取Element(FlexTable扩展了HTMLTable,HTMLTable是普通的HTML表元素),并将其包装为Widget。我不确定该怎么做,但是有可能。
另一件事,您需要防止浏览器弹出自己的上下文菜单。我将此添加到了body
标签中的html文件中:
<body oncontextmenu="return false" >
答案 1 :(得分:2)
实际上,您可以使用单击处理程序来检查单击的按钮是左,右还是中间,例如:
Button button= new Button();
button.addClickHandler(event -> {
NativeEvent nativeEvent = event.getNativeEvent();
if(NativeEvent.BUTTON_RIGHT == nativeEvent.getButton()){
event.stopPropagation();
//do something
}
});
答案 2 :(得分:1)
如果使用CellTable或DataGrid小部件,则可以处理单击单元格时触发的try
{
// Create the Outlook application.
Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
// Create a new mail item.
Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
// Set HTMLBody.
//add the body of the email
oMsg.HTMLBody = DictMailParam["Body"].ToString();
//Add an attachment.
String sDisplayName = DictMailParam["AttachmentName"].ToString();
int iPosition = (int)oMsg.Body.Length + 1;
int iAttachType = (int)Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue;
//now attached the file
//Microsoft.Office.Interop.Outlook.Attachment oAttach = oMsg.Attachments.Add
// (@"C:\\fileName.jpg", iAttachType, iPosition, sDisplayName);
foreach (string strFile in DictMailParam["Attachments"].ToString().Split(',').ToList())
{
Microsoft.Office.Interop.Outlook.Attachment oAttach = oMsg.Attachments.Add
(strFile, iAttachType, iPosition, sDisplayName);
}
//Subject line
oMsg.Subject = DictMailParam["Subject"].ToString();
// Add a recipient.
Microsoft.Office.Interop.Outlook.Recipients oRecips = (Microsoft.Office.Interop.Outlook.Recipients)oMsg.Recipients;
Microsoft.Office.Interop.Outlook.Recipient oRecip = null;
// Change the recipient in the next line if necessary.
foreach (var MailId in DictMailParam["ToAddress"].ToString().Split(';').ToArray())
{
if (!string.IsNullOrEmpty(MailId))
{
oRecip = (Microsoft.Office.Interop.Outlook.Recipient)oRecips.Add(MailId);//DictMailParam["ToAddress"].ToString()
oRecip.Resolve();
// Send.
}
}
oMsg.Send();
MessageBox.Show("Purchase Order has been sent to your email." + "\n" + "Please check your mail.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
// Clean up.
oRecip = null;
oRecips = null;
oMsg = null;
oApp = null;
}//end of try block
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}//end of catch
}//end of Email Method
,它还可以告诉您事件发生在哪一行/单元格中。以下是一些代码:
CellPreviewEvent