欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

rcp 自定义工具栏

程序员文章站 2022-05-26 18:43:44
...
//自定义控件  
 
      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);  


             } 
      }

相关标签: 控件