当前位置: 首页 > news >正文

上海美容论坛网站建设/黑科技引流工具

上海美容论坛网站建设,黑科技引流工具,网站首页快照怎么做,网站建设知名公司选择主菜单"窗口---->首选项"命令打开"首选项"窗口.此窗口是Eclipse设置项的集中营, 修改plugin.xml文件,设置首选项的扩展点: plug.xml文件 <?xml version"1.0" encoding"UTF-8"?> <?eclipse version"3.4"?…

选择主菜单"窗口---->首选项"命令打开"首选项"窗口.此窗口是Eclipse设置项的集中营,

修改plugin.xml文件,设置首选项的扩展点:

plug.xml文件

复制代码
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin><extension point="org.eclipse.ui.perspectives"><perspectivename="myplugin 透视图"icon="icons/selectall.gif"class="cn.com.kxh.myplugin.SamplePerspective"id="cn.com.kxh.myplugin.SamplePerspective"></perspective></extension><extension point="org.eclipse.ui.views"><viewname="视图1"icon="icons/prev.gif"category="com.glkxh.myplugin.view"class="cn.com.kxh.myplugin.View1"id="cn.com.kxh.myplugin.View1"></view><viewname="视图2"icon="icons/project.gif"category="com.glkxh.myplugin.view"class="cn.com.kxh.myplugin.View2"id="cn.com.kxh.myplugin.View2"></view></extension>
 <extension point="org.eclipse.ui.editors"><editor name="中国Editor"icon="icons/project.gif"class="cn.com.kxh.myplugin.ChinaEditor"id="cn.com.kxh.myplugin.ChinaEditor"></editor><editor name="美国Editor"icon="icons/prev.gif"class="cn.com.kxh.myplugin.UsaEditor"id="cn.com.kxh.myplugin.UsaEditor"></editor><editor name="法国Editor"icon="icons/remove.gif"class="cn.com.kxh.myplugin.FranceEditor"id="cn.com.kxh.myplugin.FranceEditor"></editor></extension><extension point="org.eclipse.ui.preferencePages"><pagename="myplugin插件设置"class="cn.com.kxh.myplugin.RootPreferencePage"id="cn.com.kxh.myplugin.RootPreferencePage"></page><pagename="DB数据库"category="cn.com.kxh.myplugin.RootPreferencePage"class="cn.com.kxh.myplugin.DBPreferencePage"id="cn.com.kxh.myplugin.DBPreferencePage"></page>      </extension>
</plugin>
复制代码

代码说明:

1.org.eclipse.ui.preferencePages 是首选项(Preference)的扩展点

2.name是首选项的树节点显示的名称.

3.class是首选项的树节点所对应的类(还没编写,下一步将完成此类)

4.id是首选项的树节点标识.建议设置成和class一样的名称.

5.category是父节点的id标识,当然,父节点要存在才行.

建立首选项对应的类

在上面的plugin.xml文件中已经定义的两个类.

cn.com.kxh.myplugin.RootPreferencePage和cn.com.kxh.myplugin.DBPreferencePage

首选项的类必须继承PreferencePage抽象类并实现IWorkbenchPreferencepage接口.该接口只有一个init方法,抽象类中则有一些"首选项"窗口固有按钮的处理方法需要被实现.

RootPreferencePage.java

复制代码
 1 public class RootPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
 2 
 3     public void init(IWorkbench workbench) {}
 4 
 5     protected Control createContents(Composite parent) {
 6         Composite topComp = new Composite(parent, SWT.NONE);
 7         topComp.setLayout(new RowLayout());
 8         new Label(topComp, SWT.NONE).setText("欢迎使用myplugin插件");
 9         return topComp;
10     }
11 }
复制代码

DBPreferencePage.java

复制代码
  1 public class DBPreferencePage extends PreferencePage implements IWorkbenchPreferencePage, ModifyListener {
  2     // 为文本框定义三个键值
  3     public static final String URL_KEY = "$URL_KEY";
  4     public static final String USERNAME_KEY = "$USERNAME_KEY";
  5     public static final String PASSWORD_KEY = "$PASSWORD_KEY";
  6     // 为文本框值定义三个默认值
  7     public static final String URL_DEFAULT = "jdbc:db2://127.0.0.1/mydb";
  8     public static final String USERNAME_DEFAULT = "kongxiaohan";
  9     public static final String PASSWORD_DEFAULT = "kxhkxhkxhkxh";
 10     // 定义三个文本框
 11     private Text urlText, usernameText, passwordText;
 12     // 定义一个IPreferenceStore对象
 13     private IPreferenceStore ps;
 14 
 15     // 接口IWorkbenchPreferencePage的方法,它负责初始化。在此方法中设置一个
 16     // PreferenceStore对象,由此对象提供文本框值的读入/写出方法
 17     public void init(IWorkbench workbench) {
 18         setPreferenceStore(Activator.getDefault().getPreferenceStore());
 19     }
 20 
 21     // 父类的界面创建方法
 22     protected Control createContents(Composite parent) {
 23         Composite topComp = new Composite(parent, SWT.NONE);
 24         topComp.setLayout(new GridLayout(2, false));
 25 
 26         // 创建三个文本框及其标签
 27         new Label(topComp, SWT.NONE).setText("URL:");
 28         urlText = new Text(topComp, SWT.BORDER);
 29         urlText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
 30 
 31         new Label(topComp, SWT.NONE).setText("用户名:");
 32         usernameText = new Text(topComp, SWT.BORDER);
 33         usernameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
 34         
 35         new Label(topComp, SWT.NONE).setText("密码:");
 36         passwordText = new Text(topComp, SWT.BORDER | SWT.PASSWORD);
 37         passwordText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
 38         
 39         // 取出以前保存的值,并设置到文本框中。如果取出值为空值或空字串,则填入默认值。
 40         ps = getPreferenceStore();// 取得一个IPreferenceStore对象
 41         String url = ps.getString(URL_KEY);
 42         if (url == null || url.trim().equals(""))
 43             urlText.setText(URL_DEFAULT);
 44         else
 45             urlText.setText(url);
 46 
 47         String username = ps.getString(USERNAME_KEY);
 48         if (username == null || username.trim().equals(""))
 49             usernameText.setText(USERNAME_DEFAULT);
 50         else
 51             usernameText.setText(username);
 52 
 53         String password = ps.getString(PASSWORD_KEY);
 54         if (password == null || password.trim().equals(""))
 55             passwordText.setText(PASSWORD_DEFAULT);
 56         else
 57             passwordText.setText(password);
 58 
 59         // 添加事件监听器。this代表本类,因为本类实现了ModifyListener接口成了监听器
 60         usernameText.addModifyListener(this);
 61         passwordText.addModifyListener(this);
 62         urlText.addModifyListener(this);
 63         return topComp;
 64     }
 65 
 66     // 实现自ModifyListener接口的方法,当三个文本框中发生修改时将执行此方法。
 67     // 方法中对输入值进行了验证并将“确定”、“应用”两按钮使能
 68     public void modifyText(ModifyEvent e) {
 69         String errorStr = null;// 将原错误信息清空
 70         if (urlText.getText().trim().length() == 0) {
 71             errorStr = "URL不能为空!";
 72         } else if (usernameText.getText().trim().length() == 0) {
 73             errorStr = "用户名不能为空!";
 74         } else if (passwordText.getText().trim().length() == 0) {
 75             errorStr = "密码不能为空!";
 76         }
 77         setErrorMessage(errorStr);// errorStr=null时复原为正常的提示文字
 78         setValid(errorStr == null);// “确定”按钮
 79         getApplyButton().setEnabled(errorStr == null);// “应用”按钮
 80     }
 81 
 82     // 父类方法。单击“复原默认值”按钮时将执行此方法,取出默认值设置到文本框中
 83     protected void performDefaults() {
 84         urlText.setText(URL_DEFAULT);
 85         usernameText.setText(USERNAME_DEFAULT);
 86         passwordText.setText(PASSWORD_DEFAULT);
 87     }
 88 
 89     // 父类方法。单击“应用”按钮时执行此方法,将文本框值保存并弹出成功的提示信息
 90     protected void performApply() {
 91         doSave(); // 自定义方法,保存设置
 92         MessageDialog.openInformation(getShell(), "信息", "成功保存修改!");
 93     }
 94 
 95     // 父类方法。单击“确定”按钮时执行此方法,将文本框值保存并弹出成功的提示信息
 96     public boolean performOk() {
 97         doSave();
 98         MessageDialog.openInformation(getShell(), "信息", "修改在下次启动生效");
 99         return true; // true表示成功退出
100     }
101 
102     // 自定义方法。保存文本框的值
103     private void doSave() {
104         ps.setValue(URL_KEY, urlText.getText());
105         ps.setValue(USERNAME_KEY, usernameText.getText());
106         ps.setValue(PASSWORD_KEY, passwordText.getText());
107     }
108 }
复制代码

运行结果:

将其中的密码删除之后得到下面的提示效果.

这个例子中的核心是IPreferenceStroe对象的使用,用它的getString方法来取值,setValue方法来存值.其次和以前的事件代码写法有所不同的是:本类实现了ModifyListener接口,也成为了一个监听器,这样在各文本框的加入监听器的代码就会简洁很多,不过其事件代码必须保证3个文本框可以共用才行.

 

此外还用的其他的程序文件.

Activator.java

复制代码
 1 /**
 2  * The activator class controls the plug-in life cycle
 3  */
 4 public class Activator extends AbstractUIPlugin {
 5 
 6     // The plug-in ID
 7     public static final String PLUGIN_ID = "cn.com.kxh.myplugin"; //$NON-NLS-1$
 8 
 9     // The shared instance
10     private static Activator plugin;
11     
12     /**
13      * The constructor
14      */
15     public Activator() {
16         plugin = this;
17     }
18 
19     /**
20      * Returns the shared instance
21      *
22      * @return the shared instance
23      */
24     public static Activator getDefault() {
25         return plugin;
26     }
27     
28     /*
29      * (non-Javadoc)
30      * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
31      */
32     @Override
33     public void start(BundleContext context) throws Exception {
34         super.start(context);
35     }
36 
37     /*
38      * (non-Javadoc)
39      * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
40      */
41     @Override
42     public void stop(BundleContext context) throws Exception {
43         plugin = null;
44         super.stop(context);
45     }
46 
47     public static ImageDescriptor getImageDescriptor(String path) {
48         return imageDescriptorFromPlugin(PLUGIN_ID, path);
49     }
50 
51 }
复制代码

Messages.java

复制代码
 1 public class Messages {
 2     private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle ("cn.com.kxh.myplugin.messages");
 3 
 4     public static String getString(String key) {
 5         try {
 6             return RESOURCE_BUNDLE.getString(key);
 7         } catch (MissingResourceException e) {
 8             return '!' + key + '!'; 
 9         }
10     }
11 }
复制代码

messages.properties

LanguageDialog.ok=OK
LanguageDialog.remove=Remove

 另外,我在调试程序的时候有一个地方老是报空指针NPE的错误.

最后查到其实是Activator.java这个类要在MANIFEST.MF这个文件中注册正确才行.

MANIFEST.MF

复制代码
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Myplugin插件
Bundle-SymbolicName: cn.com.kxh.myplugin;singleton:=true
Bundle-Version: 1.0.1
Bundle-Activator: cn.com.kxh.myplugin.Activator
Require-Bundle: org.eclipse.ui,org.eclipse.core.runtime
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Bundle-Vendor: Eclipse从入门到精通
复制代码

 


本文转自SummerChill博客园博客,原文链接:http://www.cnblogs.com/DreamDrive/p/4175772.html,如需转载请自行联系原作者

http://www.lbrq.cn/news/1104247.html

相关文章:

  • 网站建设名词解释与简答题/宁波正规优化seo价格
  • 热门网站建设加盟平台/模板网站建设开发
  • 信誉好的龙岗网站制作/seo公司是什么
  • wordpress插件 2017/淘宝怎么优化关键词步骤
  • 江苏省住房和城乡建设部网站/青岛seo网站排名
  • 竹业网站建设/网络推广工作
  • 多语言网站是怎么做的/建网站用什么软件
  • 深圳网站建设公司 概况/中国国家培训网是真的吗
  • 域名网站建设教程/网站优化培训
  • 模板网站怎么做才美观/设计网站排行榜前十名
  • thinkphp租房网站开发/怎样做一个产品营销方案
  • 任家房网站建设/windows10优化软件
  • 冷水江网站定制/seo排名技巧
  • 开发网站多少钱/大众网疫情最新消息
  • 中韩双语网站制作价格/揭阳seo快速排名
  • 成都 网站建设/网络上如何推广网站
  • 云服务器网站解析/seo搜索排名优化是什么意思
  • 北京网站设计公司飞沐/网络营销策划案
  • 初创企业的建站流程/门户网站推广方案
  • drupal做的网站/seo网站推广方案策划书
  • 手机销售网站建设项目书/品牌软文范文
  • 做宣传海报的网站/360广告投放平台
  • seo查询爱站网/电商大数据查询平台免费
  • 莉莉卡是哪个网站做的/美区下载的app怎么更新
  • 海报模板免费下载网站/dw网站制作
  • 网络营销方式哪些/深圳百度网站排名优化
  • 教育兼职网站开发/软文新闻发稿平台
  • 做网贷中介网站赚钱吗/百度seo排名优
  • 绿色国外网站/网站建设与管理就业前景
  • 网站语言切换前端可以做么/广州头条今日头条新闻
  • 详解Mysql Order by排序底层原理
  • C#将【程序集引用-依赖关系】展示到NetronLight图表中
  • stack and queue 之牛刀小试
  • 3D材质总监的“光影魔法”:用Substance Sampler AI,“擦除”照片中的光影
  • JavaScript进阶篇——第八章 原型链、深浅拷贝与原型继承全解析
  • Flutter在Android studio运行出现Error: Entrypoint is not a Dart file