GMF学习系列(二) 一些知识点(续2)

8.插件的国际化,可以参考nwpu.cdcsp.sbpel.diagram.part中messages.java的做法。

9.Text自动提示功能

import org.eclipse.jface.bindings.keys.KeyStroke;

import org.eclipse.jface.dialogs.Dialog;

import org.eclipse.jface.fieldassist.AutoCompleteField;

import org.eclipse.jface.fieldassist.ComboContentAdapter;

import org.eclipse.jface.fieldassist.ContentProposalAdapter;

import org.eclipse.jface.fieldassist.SimpleContentProposalProvider;

import org.eclipse.jface.fieldassist.TextContentAdapter;

import org.eclipse.swt.SWT;

import org.eclipse.swt.layout.GridData;

import org.eclipse.swt.layout.GridLayout;

import org.eclipse.swt.widgets.Combo;

import org.eclipse.swt.widgets.Display;

import org.eclipse.swt.widgets.Label;

import org.eclipse.swt.widgets.Shell;

import org.eclipse.swt.widgets.Text;

 

public class LaunchApp {

    protected Shell shell;

 

    private Text nameT;

    private Combo cityC;

    private Text remarksT;

 

    /**

     * Launch the application

     * @param args

     */

    public static void main(String[] args) {

        try {

            LaunchApp window = new LaunchApp();

            window.open();

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

 

    /**

     * Open the window

     */

    public void open() {

        final Display display = Display.getDefault();

        createContents();

        shell.open();

        shell.layout();

        while (!shell.isDisposed()) {

            if (!display.readAndDispatch())

                display.sleep();

        }

    }

 

    /**

     * Create contents of the window

     */

    protected void createContents() {

        shell = new Shell();

        final GridLayout gridLayout = new GridLayout();

        gridLayout.numColumns = 2;

        shell.setLayout(gridLayout);

        shell.setSize(226, 122);

        shell.setText("Field Assist");

 

        final Label nameL = new Label(shell, SWT.NONE);

        nameL.setText("姓名");

 

        nameT = new Text(shell, SWT.BORDER);

        nameT.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

 

        final Label cityL = new Label(shell, SWT.NONE);

        cityL.setText("城市");

 

        cityC = new Combo(shell, SWT.NONE);

       cityC.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

       

        final Label remarksL = new Label(shell, SWT.NONE);

        remarksL.setText("备注");

 

        remarksT = new Text(shell, SWT.BORDER);

        remarksT.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

       

        //

        Dialog.applyDialogFont(this.shell);

       

        //

        this.addNameTextFieldAssist();

        this.addCityComboFieldAssist();

        this.addRemarksTextFieldAssist();

    }

 

    /**

     * 给名称Text添加自动完成功能

     */

    private void addNameTextFieldAssist() {

        // 让text可以进行代码提示. 提示内容为: "aa", "BB", "无敌".

        // 注意: 不区分大小写. [如: 输入'b', 内容中会出现"BB"]

        new AutoCompleteField(nameT, new TextContentAdapter(), new String[]{"aa", "BB", "无敌"});

    }

   

    /**

     * 给城市Combo添加自动完成功能

     */

    private void addCityComboFieldAssist() {

        // 让combo可以代码提示. 提示内容为: "BeiJing", "南京", "北京"

        new AutoCompleteField(cityC, new ComboContentAdapter(), new String[] {"BeiJing", "南京", "北京"});

    }

   

    /**

     * 给备注Text添加自动完成功能

     */

    private void addRemarksTextFieldAssist() {

        // 下面使用ContentProposalAdapter,而没有继续使用AutoCompleteField.

       // [去查看代码你会发现:AutoCompleteFiled实现和下面的代码几乎一样. ]

        // AutoCompleteFiled使用的同样就将传入的String[]去构造一个SimpleContentProposalProvider.

        // 但是,AutoCompleteFiled内部的ContentProposalAdapter是无法从外部得到的.

        // 所以,为了能够自定义ContentProposalAdapter, 还必须将AutoCompleteField内部实现的代码在外部再写一遍.

        KeyStroke keyStroke = null; // null 表示不接受快捷键

        try {

            keyStroke = KeyStroke.getInstance("Ctrl+1"); // 在text上按Ctrl+1弹出popup的shell.

        } catch (Exception e) {

            e.printStackTrace();

        }

        ContentProposalAdapter adapter = new ContentProposalAdapter(remarksT, new TextContentAdapter(), new SimpleContentProposalProvider(new String[] {"one", "two", "three"}), keyStroke, new char[] {'.', ' '});

        adapter.setAutoActivationDelay(200); // 延时200ms

        adapter.setPropagateKeys(true); // 如果用户的输入值在内容列表中[比如输入'o',而内容中有'one'],则弹出popup的shell

        adapter.setFilterStyle(ContentProposalAdapter.FILTER_CUMULATIVE); // 用户同步输入的内容也过滤列表[如:用户输入'o',则弹出popup的shell中的内容列表被过滤,其中都是'o'开头的, 再输入一个'n', 则内容列表中被过滤,只有以'on'开头的]

        adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_INSERT); // 回写插入

//        adapter.setLabelProvider(new LabelProvider() { // 可以不用指定LabelProvider. 如果指定,则不仅仅可以显示Text, 还可以显示Image.

//            @Override

//            public String getText(Object element) {

//                IContentProposal proposal = (IContentProposal) element;

//                return "XX" + proposal.getContent();

//            }

//            @Override

//            public Image getImage(Object element) {

//                return super.getImage(element);

//            }

//        });

       

        // 上面的代码中使用的是SimpleContentProposalProvider, 则会用每个String去构造默认的一个IContentProposal,

        // 具体逻辑见: SimpleContentProposalProvider.makeContentProposal

       

        // 请注意: 可以不用设置setLabelProvider的, 那么将会直接从IContentProposal中取label或content显示.

        // 有labelProvider则从labelProvider得到在内容list中显示的值.

        // 具体逻辑见: ContentProposalAdapter.getString()方法

//        if (labelProvider == null) {

//            return proposal.getLabel() == null ? proposal.getContent() : proposal.getLabel();

//        }

//        return labelProvider.getText(proposal);

       

        // 同样的, 如果你添加了labelProvider, 那么也可以给每个IContentProposal返回Image.

        // 具体逻辑见: ContentProposalAdapter.getImage()方法

       

    }

 

   

    // ContentProposalAdapter.setAutoActivationDelay 弹出popup的延迟时间

   

    // ContentProposalAdapter.setPropagateKeys(true);

    // 说明: 如果用户敲入的字母在内容列表内时,是否弹出popup内容列表.

    // true 弹出. 用户输入'o'也会弹出popup的shell. 输入'.'也会弹出.

    // false 不弹出. 用户只有输入'.'才弹出popup的shell. 输入'o'等,不弹出.

   

    // ContentProposalAdapter.setFilterStyle(ContentProposalAdapter.FILTER_*);

    // 作用: 在用户敲入字母的时候是否过滤popup弹出的shell里面的内容.

    // ContentProposalAdapter.FILTER_NONE 不过滤. 说明: 下面的内容列表永远不变.

    // ContentProposalAdapter.FILTER_CHARACTER 只用一个输入字符为条件过滤下面的内容列表. 说明:在输入多个字符后,下面的内容列表会被清空.

    // ContentProposalAdapter.FILTER_CUMULATIVE 随着用户输入不停的过滤下面的内容列表. 注意在3.4后被@deprecated了. 说明: 随着用户的输入,下面的内容一直在过滤

   

    // ContentProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_*);

    // 说明: 用户从popup的shell中得到的内容怎么回写到控件上.

    // ContentProposalAdapter.PROPOSAL_INSERT 插入.

    // ContentProposalAdapter.PROPOSAL_REPLACE 覆盖.

    // ContentProposalAdapter.PROPOSAL_IGNORE 忽略. 应该叫追加比较合适.

 

    

    // TextContentAdapter只可以用于Text.

    // ComboContentAdapter只可以用于Combo.

    // 所以, 对于StyledText或Snipper等都需要自定义ContentAdapter.

   

}

转载于:https://www.cnblogs.com/yangqk/archive/2011/10/26/2225463.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/275229.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

新手向:前端程序员必学基本技能——调试JS代码

1前言大家好,我是若川。最近组织了源码共读活动,感兴趣的可以加我微信 ruochuan12 参与,已进行三个月了,大家一起交流学习,共同进步。想学源码,极力推荐之前我写的《学习源码整体架构系列》 包含jQuery、un…

iOS开发ApplePay的介绍与实现

1、Apple Pay的介绍 Apple Pay官方1.1 Apple Pay概念 Apple Pay,简单来说, 就是一种移动支付方式。通过Touch ID/ Passcode,用户可使用存储在iPhone 6, 6p等之后的新设备上的信用卡和借记卡支付证书来授权支付; 它是苹果公司在2014苹果秋季新…

mes建设指南_给予和接受建设性批评的设计师指南

mes建设指南Constructive criticism, or more plainly, feedback, plays a crucial role in a designer’s job. Design is an iterative process, so we are often either asking for feedback on our own work or dishing it out to a fellow designer.建设性的批评&#xff…

面试官:请实现一个通用函数把 callback 转成 promise

1. 前言大家好,我是若川。最近组织了源码共读活动,感兴趣的可以加我微信 ruochuan12 参与,或者在公众号:若川视野,回复"源码"参与,每周大家一起学习200行左右的源码,共同进步。已进行…

java中filter的用法

filter过滤器主要使用于前台向后台传递数据是的过滤操作。程度很简单就不说明了,直接给几个已经写好的代码: 一、使浏览器不缓存页面的过滤器 Java代码 import javax.servlet.*;import javax.servlet.http.HttpServletResponse;import java.io.IOExcept…

我很喜欢玩游戏,那么我就适合做游戏程序员吗?

作者:黄小斜文章来源:【程序员江湖】游戏在今天的普及度已经不是端游时代可以比肩的了。如今人手一台手机、平板就可以吃鸡、打农药,不仅是男生,也有很多女生加入了游戏圈。相信现在在看文章的你也玩游戏,虽然爱玩的程…

open-falcon_NASA在Falcon 9上带回了蠕虫-其背后的故事是什么?

open-falconYes, that’s right. The classic NASA “worm” logo is back! An image of the revived NASA worm logo was released on Twitter by NASA Administrator Jim Bridenstine as well as press release on the NASA.gov website. NASA explained that original NASA …

听说你对 ES6 class 类还不是很了解

大家好,我是若川。最近组织了源码共读活动,感兴趣的可以加我微信 ruochuan12 参与。前言在ES5中是原型函数,到了ES6中出现了"类"的概念。等同于是ES5的语法糖,大大提升了编写代码的速度,本文只讲一些常用的&…

《CSS揭秘》读书笔记

摘要 《CSS揭秘》主要是介绍了使用CSS的技巧,通过47个案例来灵活的使用CSS进行实现,同时在实现过程中注重CSS代码的灵活性与健壮性。通过阅读这本书有利于我们编写高质量的CSS代码以及打破使用CSS时的固定思维,能够更加灵活的使用CSS。 《CSS…

一篇文章带你搞懂前端面试技巧及进阶路线

大家好,我是若川。最近有很多朋友给我后台留言:自己投了不少简历,但是收到的面试邀请却特别少;好不容易收到了大厂的面试邀请,但由于对面试流程不清楚,准备的特别不充分,结果也挂了;…

小屏幕 ui设计_UI设计基础:屏幕

小屏幕 ui设计重点 (Top highlight)第4部分 (Part 4) Welcome to the fourth part of the UI Design basics. This time we’ll cover the screens you’ll likely design for. This is also a part of the free chapters from Designing User Interfaces.欢迎使用UI设计基础知…

RabbitMQ指南之四:路由(Routing)和直连交换机(Direct Exchange)

在上一章中,我们构建了一个简单的日志系统,我们可以把消息广播给很多的消费者。在本章中我们将增加一个特性:我们可以订阅这些信息中的一些信息。例如,我们希望只将error级别的错误存储到硬盘中,同时可以将所有级别&am…

不用任何插件实现 WordPress 的彩色标签云

侧边栏的标签云(Tag Cloud)一直是 WordPress 2.3 以后的内置功能,一般直接调用函数wp_tag_cloud 或者在 Widgets 里开启即可,但是默认的全部是一个颜色,只是大小不一样,很是不顺眼,虽然可以用 S…

随时随地能写代码, vscode.dev 出手了

大家好,我是若川。最近组织了源码共读活动,感兴趣的可以加我微信 ruochuan12 参与。今天偶然看到了 VSCode 官方发布了一条激动人心的 Twitter,vscode.dev[1] 域名上线了!image-20211021211915942新的域名 vscode.dev[2] 它是一个…

七种主流设计风格_您是哪种设计风格?

七种主流设计风格重点 (Top highlight)I had an idea for another mindblowing test, so here it is. Since you guys liked the first one so much, and I got so many nice, funny responses and private messages on how accurate it actually was, I thought you will prob…

算法精讲:分享一道值得分享的算法题

分享一道leetcode上的题,当然,居然不是放在刷题贴里来讲,意味着分享的这道题不仅仅是教你怎么来解决,更重要的是这道题引发出来的一些解题技巧或许可以用在其他地方,下面我们来看看这道题的描述。 问题描述 给定一个未…

正几边形可以实现无缝拼接?

正n边形内角为 (n-2)*180/n ,要保证可以无缝拼接,就是一个圆可以被整数个n边形内角拼接,即 360k*(n-2)*180/n > 2nk(n-2)。(摘自http://blog.csdn.net/ray58750034/article/details/1365813) 以下代码表明&#xff…

React 18 Beta 来了

大家好,我是若川。最近组织了源码共读活动,感兴趣的可以加我微信 ruochuan12 参与,目前近3000人参与。经过「React18工作组」几个月工作,11月16日v18终于从Alpha版本更新到Beta版本。本文会解释:这次更新带来的变化对开…

osg着色语言着色_探索数字着色

osg着色语言着色Learn how to colorize icons with your NounPro subscription and Adobe Illustrator.了解如何使用NounPro订阅和Adobe Illustrator为图标着色。 For those who want to level up their black and white Noun Project icons with a splash of color, unlockin…

upc组队赛15 Supreme Number【打表】

Supreme Number题目链接 题目描述 A prime number (or a prime) is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. Now lets define a number N as the supreme number if and only if each number made up of an non-e…