概述
public class SampleHandler extends AbstractHandler {
public Object execute(ExecutionEvent event) throws ExecutionException {
//方法一:新建一个application window的display类,在该类实现对话框功能,直接调用open()
MyDisplay display = new MyDisplay();
display.start();
//方法二:创建一个shell,把实现了功能的对话框dialog加入shell
Shell shell = new Shell();
Dialog2 dialog = new Dialog2(shell, SWT.NONE);
dialog.open();
return null;
}
}
//给按钮添加一个鼠标监听事件,有两种方式实现:
方法一:// button.addListener(SWT.MouseUp, new MouseListener(text));
//button.addListener(eventType, listener);
//定义一个监听类,然后把自定义的监听类对象传给button的addListener(),enventType定义了button发生listener事件的条件。
class MouseListener implements Listener{
private Text text;
public MouseListener(Text text)
{
this.text = text;
}
public void handleEvent(Event arg0) {
if(text.getText()==null)
{
MessageBox.post("please input folder-name", "提示:", MessageBox.ERROR);
}
else
{
TCSession session = (TCSession) AIFUtility.getDefaultSession();
TCComponentFolderType foldertype;
try {
InterfaceAIFComponent target = AIFUtility.getTargetComponent();
foldertype = (TCComponentFolderType) session.getTypeComponent("Folder");
TCComponentFolder folder = foldertype.create(text.getText(), "create a folder", "Folder");
if(target instanceof TCComponentFolder){
((TCComponentFolder) target).add("contents", folder);
}
}
catch (TCException e1)
{
e1.printStackTrace();
}
}
}}
//方法二:添加addMouseListener()监听事件,并定义mouseUp(event)执行的操作
button.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
if(text.getText()==null)
{
MessageBox.post(“please input folder-name”, “提示:”, MessageBox.ERROR);
}
else
{
TCSession session = (TCSession) AIFUtility.getDefaultSession();
TCComponentFolderType foldertype;
try
{
MessageBox.post(“please ….”, “提示:”, MessageBox.ERROR);
foldertype = (TCComponentFolderType) session.getTypeComponent(“Folder”);
TCComponentFolder folder = foldertype.create(text.getText(), “create a folder”, “Folder”);
}
catch (TCException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
});
FormData fd_button = new FormData();
fd_button.top = new FormAttachment(0, 5);
fd_button.left = new FormAttachment(0, 157);
button.setLayoutData(fd_button);
button.setText(“u786Eu5B9A”);
}
最后
以上就是危机大山为你收集整理的TC的handler类调用swt窗口的全部内容,希望文章能够帮你解决TC的handler类调用swt窗口所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复