支持HW团队,就支付宝领取下面的红包吧!(2018年3月31前,就几毛,也会几块,可以和其他红包叠加使用),你领取消费,HW有奖励。红包使用无条件限制,有条件请注意是不是有病毒。

小伙伴们,给大家发红包喽!人人可领,领完就能用。祝大家领取的红包金额大大大!#吱口令#长按复制此消息,打开支付宝就能领取!er1OEj73Uj

登入 注册 | 验证
| 搜索
HelloWorld论坛 : > 计算机科学、技术、教学> HelloWorld团队自营项目> HW数据库模型> 【原创】FormEditor 开发——实现一个简单的页面,基于FormPage
 
 
 
 
类别:eclipse 阅读:10795 评论:0 时间:二月 20, 2015, 1:04 p.m. 关键字:FormEditor FormPage

 

 接上次的例子,我们实现一个自定义页面。

第一步添加类:

右击包com.hwcrazy.editor.editors,选择New-》Class,填写类名。如下:

点击Finish。

 类的内容这么写:

package com.hwcrazy.editor.editors;

import java.io.IOException;

import javax.swing.event.HyperlinkEvent;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormPage;
import org.eclipse.ui.forms.events.HyperlinkAdapter;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Hyperlink;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.TableWrapData;
import org.eclipse.ui.forms.widgets.TableWrapLayout;

public class InfoPage extends FormPage {

        InfoPage(HwDbEditor editor, String id) {
                super(editor, id, "信息");
        }
        protected void createFormContent(IManagedForm managedForm) {
                // 一下内容按自己高兴
        FormToolkit toolkit = managedForm.getToolkit();
        ScrolledForm form = managedForm.getForm();
                toolkit.decorateFormHeading(form.getForm());
                form.setText("项目基本信息以及计划");

                TableWrapLayout layout = new TableWrapLayout();
                form.getBody().setLayout(layout);
                
                Hyperlink link = toolkit.createHyperlink(form.getBody(),
                                "HelloWorld论坛", SWT.WRAP);

                link.addHyperlinkListener(new HyperlinkAdapter() {
                        public void linkEntered(HyperlinkEvent e) {
                                // 光标进入超链接区域
                                System.out.println("光标进入超链接区域");
                        }

                        public void linkExited(HyperlinkEvent e) {
                                // 光标离开超链接区域
                                System.out.println("光标离开超链接区域");
                        }

                        public void linkActivated(HyperlinkEvent e) {
                                // 单击超链接激活时
                                System.out.println("超链接被激活");
                                try {
                                        Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler http://hwcrazy.com/");
                                } catch (IOException e1) {
                                        e1.printStackTrace();
                                }
                                //判断当前系统是否支持Java AWT Desktop扩展
                        if(java.awt.Desktop.isDesktopSupported()){
                            try{
                                //创建一个URI实例,注意不是URL
                                java.net.URI uri=java.net.URI.create("http://hwcrazy.com");
                                //获取当前系统桌面扩展
                                java.awt.Desktop dp=java.awt.Desktop.getDesktop();
                                //判断系统桌面是否支持要执行的功能
                                if(dp.isSupported(java.awt.Desktop.Action.BROWSE)){
                                    //获取系统默认浏览器打开链接
                                    dp.browse(uri);
                                }
                            }catch(java.lang.NullPointerException e1){
                                //此为uri为空时抛出异常
                            }catch(java.io.IOException e1){
                                //此为无法获取系统默认浏览器
                            }
                        }
                                
                        }
                });
                layout.numColumns = 2;
                TableWrapData td = new TableWrapData();
                td.colspan = 2;
                link.setLayoutData(td);

                // form.setImage(inputData.getImageDescriptor().createImage());
                GridData gridData6 = new GridData();
                gridData6.horizontalSpan = 3;
                gridData6.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL;
                GridLayout gridLayout3 = new GridLayout();
                gridLayout3.numColumns = 6;
                Composite composite2 = toolkit.createComposite(form.getBody());
                composite2.setLayout(gridLayout3);
                // Composite composite2 = section;
                toolkit.createLabel(composite2, "计划开始:");
                Text textPStart = toolkit.createText(composite2, "2009-12-30 12:30:30",
                                SWT.SINGLE | SWT.BORDER);
                textPStart.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true,
                                false));
                toolkit.createLabel(composite2, "计划完成:");
                Text textPFinish = toolkit.createText(composite2,
                                "2009-12-30 12:30:30", SWT.SINGLE | SWT.BORDER);
                textPFinish.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true,
                                false));
                toolkit.createLabel(composite2, "工期:");
                Text textDur = toolkit.createText(composite2, "2d", SWT.SINGLE
                                | SWT.BORDER);
                textDur.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
                toolkit.createLabel(composite2, "实际开始:");
                Text textAStart = toolkit.createText(composite2,
                                "2009-12-30 12:30:30", SWT.SINGLE | SWT.BORDER);
                textAStart.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true,
                                false));
                toolkit.createLabel(composite2, "实际完成:");
                Text textAFinish = toolkit.createText(composite2,
                                "2009-12-30 12:30:30", SWT.SINGLE | SWT.BORDER);
                textAFinish.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true,
                                false));
                toolkit.createLabel(composite2, "历时:");
                Text textADur = toolkit.createText(composite2, "0.5d", SWT.SINGLE
                                | SWT.BORDER);
                textADur.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true,
                                false));
                toolkit.createLabel(composite2, "负责人:");
                Text textManager = toolkit.createText(composite2, null, SWT.SINGLE
                                | SWT.BORDER);
                textManager.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true,
                                false));
                toolkit.createLabel(composite2, "负责部门:");
                Text textDept = toolkit.createText(composite2, null, SWT.SINGLE
                                | SWT.BORDER);
                textDept.setLayoutData(gridData6);
                toolkit.createLabel(composite2, "项目团队:");
                Text textTeam = toolkit.createText(composite2,
                                "测试显示长文本的状况>测试显示长文本的状况>测试显示长文本的状况>测试显示长文本的状况>测试显示长文本的状况",
                                SWT.SINGLE | SWT.BORDER);
                GridData gd = new GridData(SWT.FILL, SWT.BEGINNING, false, false, 5, 1);
                gd.widthHint = 400;
                textTeam.setLayoutData(gd);
        }
}

 然后,HwDbEditorz中的addPages方法修改为:

        @Override
        protected void addPages() {
                // TODO Auto-generated method stub
                try {
                        addPage(new FormPage(this, "1", "计划"));
                        addPage(new FormPage(this, "2", "任务"));
                        addPage(new InfoPage(this, "3"));
                } catch (PartInitException e) {
                        e.printStackTrace();
                }
        }

运行界面如下:

有个疑问就是我调试了半天,点击HelloWorld论坛,没有反应,请高人帮忙看看!

相关博文 首页 上页 1 2 3 下页 尾页 共3条
文件名 大小 时间 会员 费用 操作
com.hwcrazy.editor.rar(精华) 22K935B 二月 20, 2015, 7:23 p.m. 初学MPEG 积分:0
荣誉:0
会币:0
下载
 
 
[挂载人]初学MPEG [审核人]初学MPEG 推荐

个人签名--------------------------------------------------------------------------------

Please Login (or Sign Up) to leave a comment