rcp 自定义工具栏

来源:互联网 发布:东邪西毒黄药师知乎 编辑:程序博客网 时间:2024/05/22 03:42
//自定义控件  
 
      class ComboContribution extends ContributionItem{       


             private ToolItem toolitem;  


             private Combo fFindCombo;  


             private Button upFindbutton;  


             private Button downFindbutton;  


             private Button allFindbutton;  
             
             private Label label;  


 


             public ComboContribution() {  


                 super();  


             }                    


             protected Control createControl(Composite parent) {  


            int width = parent.getMonitor().getClientArea().width;
            int height = parent.getMonitor().getClientArea().height;
            int x = parent.getSize().x;
            int y = parent.getSize().y;
            if (x > width) {
            parent.getSize().x = width;
            }
            if (y > height) {
            parent.getSize().y = height;
            }
//             Toolkit kit = Toolkit.getDefaultToolkit();
//             Dimension screeSize = kit.getScreenSize();
//             int width = screeSize.width;
            System.out.println("屏幕宽度 : "+width);
//                 Composite composite = new Composite(parent, SWT.NONE);                  
                 parent.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
                 // 语言切换关闭所有的视图再展示
                 PlatformUtils.closeAllView();
              parent.setLayout(new FormLayout());
             
              Composite composite = new Composite(parent,SWT.SHADOW_OUT);
                 composite.setBackground(SWTResourceManager.getColor(220, 20, 60));
                 composite.setLayoutData(new FormData());
                 FormData fd_grpWaybill = new FormData();
                 fd_grpWaybill.bottom = new FormAttachment(0, 50);
          fd_grpWaybill.right = new FormAttachment(100, 0);
          fd_grpWaybill.top = new FormAttachment(0);
          fd_grpWaybill.left = new FormAttachment(0);
          composite.setLayoutData(fd_grpWaybill);
                 //查询框  
          label = new Label(composite, SWT.NONE);
                 fFindCombo = new Combo(composite,SWT.NONE);  


                 fFindCombo.setLocation(0, 2);  


                 fFindCombo.setSize(130,20);  


                 System.out.println(" fFindCombo == " + fFindCombo.getBounds());  


                 //向上查  


                 upFindbutton = new Button(composite, SWT.NONE);  


                 upFindbutton.setLocation(135, 2);  


                 upFindbutton.setSize(30,20);  


                 upFindbutton.setText("上查");     


                 upFindbutton.addSelectionListener(new SelectionListener(){  


                     public void widgetDefaultSelected(SelectionEvent e) {  


                         // TODO 自动生成方法存根  


                          


                     }  


                     public void widgetSelected(SelectionEvent e) {  


                         fFindCombo.add(fFindCombo.getText());  
                         


                     }                      


                 });  


                 System.out.println(" upFindbutton == " + upFindbutton.getBounds());  


                 //向下查  


                 downFindbutton = new Button(composite, SWT.NONE);  


                 downFindbutton.setLocation(170, 2);  


                 downFindbutton.setSize(30,20);  


                 downFindbutton.setText("下查");  


                 //全部查询  


                 allFindbutton = new Button(composite, SWT.NONE);  


                 allFindbutton.setLocation(205, 2);  


                 allFindbutton.setSize(30,20);  


                 allFindbutton.setText("全部");   


                 toolitem.setWidth(width);  


                 return composite;  


             }
             public void fill(ToolBar parent, int index) {  
             
                 toolitem = new ToolItem(parent, SWT.SEPARATOR, index);  


                 Control control = createControl(parent);  


                 toolitem.setControl(control);  


             } 
      }
原创粉丝点击