package com.pcm.chni.equipment.frame; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.Tray; import org.eclipse.swt.widgets.TrayItem; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; import com.pcm.chni.util.*; import com.swtdesigner.SWTResourceManager; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Table; import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.TableViewerColumn; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.MouseAdapter; import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.widgets.Composite; public class HardwareDong { public static String errormsg; protected Shell shell; private Table table; private Combo combo; private Text text_8; private Button button_1; private Button button_2; private Label label_10; private Combo combo_1; private CheckboxTableViewer checkboxTableViewer; private TableViewerColumn tableViewerColumn; private TableViewerColumn tableViewerColumn_1; private TableViewerColumn tableViewerColumn_2; private TableViewerColumn tableViewerColumn_3; private TableViewerColumn tableViewerColumn_4; private TableViewerColumn tableViewerColumn_5; private TableViewerColumn tableViewerColumn_6; private TableViewerColumn tableViewerColumn_7; private TableViewerColumn tableViewerColumn_8; private TableViewerColumn tableViewerColumn_9; private TableViewerColumn tableViewerColumn_10; private TableViewerColumn tableViewerColumn_11; // private Customer customer; private Display display; private ReadRegistry read=new ReadRegistry(); private Label label; private Composite composite; private Label label_1; public HardwareDong(){ } /** * Launch the application. * @param args */ public static void main(String[] args) { try { HardwareDong window = new HardwareDong(); window.open(); } catch (Exception e) { e.printStackTrace(); } } /** * Open the window. */ public void open() { 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(display,SWT.NONE|SWT.NO_TRIM|SWT.MIN); shell.setSize(862, 550); shell.setText("设备数据读取"); FrameCenter.setdileCenter(shell); composite = new Composite(shell, SWT.NONE); composite.setBounds(0, 0, 869, 559); composite.setBackgroundImage(SWTResourceManager.getImage("image/context.jpg")); checkboxTableViewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER | SWT.FULL_SELECTION); table = checkboxTableViewer.getTable(); table.setBounds(22, 147, 834, 283); table.setLinesVisible(true); table.setHeaderVisible(true); table.addListener(SWT.MeasureItem, new Listener() { public void handleEvent(Event event) { event.height = 23; } }); combo = new Combo(composite, SWT.READ_ONLY); combo.setBounds(103, 469, 107, 20); combo.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if(combo.getText().equals("X")){ checkboxTableViewer.getTable().removeAll(); creativeWirelessColumn(); label_10.setVisible(false); combo_1.setVisible(false); text_8.setText(""); }else if(combo.getText().equals("XX")){ checkboxTableViewer.getTable().removeAll(); xuetangColumn(); label_10.setVisible(true); combo_1.setVisible(true); text_8.setText(""); }else if(combo.getText().equals("XXX")){ checkboxTableViewer.getTable().removeAll(); bpColumn(); label_10.setVisible(false); combo_1.setVisible(false); text_8.setText(""); }else if(combo.getText().equals("XXXX")){ checkboxTableViewer.getTable().removeAll(); BelterColumn(); label_10.setVisible(false); combo_1.setVisible(false); text_8.setText(""); } } }); combo.setItems(new String[] {"X", "XX", "XXX", "XXXX"}); combo.select(0); label_10 = new Label(composite, SWT.NONE); label_10.setBounds(255, 474, 36, 21); label_10.setBackground(SWTResourceManager.getColor(255, 255, 255)); label_10.setText("XX:"); label_10.setVisible(false); // label_10.setBackground(bgColor); combo_1 = new Combo(composite, SWT.READ_ONLY); combo_1.setBounds(298, 470, 94, 20); combo_1.setItems(new String[]{"--请选择--","XX","XXX"}); combo_1.select(0); combo_1.setVisible(false); text_8 = new Text(composite, SWT.BORDER); text_8.setBounds(505, 470, 94, 21); text_8.setFont(SWTResourceManager.getFont("宋体", 10, SWT.NORMAL)); text_8.setBackground(SWTResourceManager.getColor(255, 255, 255)); text_8.setEnabled(false); Button button_3 = new Button(composite, SWT.NONE); button_3.setBounds(677, 469, 83, 22); button_3.setImage(SWTResourceManager.getImage("image/03.png")); button_1 = new Button(composite, SWT.NONE); button_1.setBounds(766, 469, 83, 22); button_1.setImage(SWTResourceManager.getImage("image/05.png")); button_2 = new Button(composite, SWT.NONE); button_2.setBounds(769, 514, 83, 22); button_2.setImage(SWTResourceManager.getImage("image/10.png")); shell.setImage(display.getSystemImage(SWT.ICON_WORKING)); final Tray tray = display.getSystemTray(); final TrayItem trayItem = new TrayItem(tray, SWT.NONE); trayItem.setVisible(false); trayItem.setToolTipText(shell.getText()); trayItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { shell.setMinimized(true); } }); label_1 = new Label(composite, SWT.NONE); // label_1.addShellListener(new ShellAdapter() { // // //点击窗口最小化按钮时,窗口隐藏,系统栏显示图标 // public void shellIconified(ShellEvent e) { // toggleDisplay(shell, tray); // } // // }; label_1.addMouseListener(new MouseAdapter() { public void mouseUp(MouseEvent event) { shell.setMinimized(true); } }); label_1.setText(""); label_1.setImage(SWTResourceManager.getImage("image/-.jpg")); label_1.setBounds(806, 0, 27, 27); label = new Label(composite, SWT.NONE); label.setBounds(833, 0, 27, 27); label.addMouseListener(new MouseAdapter() { @Override public void mouseUp(MouseEvent e) { shell.close(); } }); label.setText(""); label.setImage(SWTResourceManager.getImage("image/x.jpg")); Label label_2 = new Label(composite, SWT.NONE); label_2.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE)); label_2.setBounds(105, 91, 107, 21); Label label_3 = new Label(composite, SWT.NONE); label_3.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE)); label_3.setBounds(282, 91, 107, 21); Label label_4 = new Label(composite, SWT.NONE); label_4.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE)); label_4.setBounds(483, 91, 107, 21); Label label_5 = new Label(composite, SWT.NONE); label_5.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE)); label_5.setBounds(690, 91, 107, 21); //初始化页面为 X creativeWirelessColumn(); // xuetangColumn(); } //封装CheckBoxTable列 //x public void creativeWirelessColumn(){ while(table.getColumnCount()>0){ table.getColumns()[0].dispose(); } tableViewerColumn = new TableViewerColumn( checkboxTableViewer, SWT.NONE); TableColumn tableColumn = tableViewerColumn.getColumn(); tableColumn.setText("xx"); tableColumn.setWidth(230); tableViewerColumn_1 = new TableViewerColumn(checkboxTableViewer, SWT.NONE); TableColumn tableColumn_1 = tableViewerColumn_1.getColumn(); tableColumn_1.setWidth(292); tableColumn_1.setText("xxx"); tableViewerColumn_2= new TableViewerColumn(checkboxTableViewer, SWT.NONE); TableColumn tableColumn_2= tableViewerColumn_2.getColumn(); tableColumn_2.setWidth(300); tableColumn_2.setText("xx"); } //xx public void bpColumn(){ while(table.getColumnCount()>0)table.getColumns()[0].dispose(); tableViewerColumn = new TableViewerColumn( checkboxTableViewer, SWT.NONE); TableColumn tableColumn = tableViewerColumn.getColumn(); tableColumn.setText("xx"); tableColumn.setWidth(180); tableViewerColumn_1 = new TableViewerColumn(checkboxTableViewer, SWT.NONE); TableColumn tableColumn_1 = tableViewerColumn_1.getColumn(); tableColumn_1.setWidth(180); tableColumn_1.setText("xx"); tableViewerColumn_2 = new TableViewerColumn(checkboxTableViewer, SWT.NONE); TableColumn tableColumn_2 = tableViewerColumn_2.getColumn(); tableColumn_2.setWidth(180); tableColumn_2.setText("xx"); tableViewerColumn_3 = new TableViewerColumn(checkboxTableViewer, SWT.NONE); TableColumn tableColumn_3 = tableViewerColumn_3.getColumn(); tableColumn_3.setWidth(220); tableColumn_3.setText("xx"); } //xxx public void xuetangColumn(){ while(table.getColumnCount()>0)table.getColumns()[0].dispose(); // for(int i=0;i<table.getColumnCount();i++){ // // table.getColumns()[i].dispose(); // } tableViewerColumn = new TableViewerColumn( checkboxTableViewer, SWT.NONE); TableColumn tableColumn = tableViewerColumn.getColumn(); tableColumn.setText("xx"); tableColumn.setWidth(428); tableViewerColumn_1 = new TableViewerColumn(checkboxTableViewer, SWT.NONE); TableColumn tableColumn_1 = tableViewerColumn_1.getColumn(); tableColumn_1.setWidth(400); tableColumn_1.setText("xx"); } //xxxx public void BelterColumn(){ while(table.getColumnCount()>0)table.getColumns()[0].dispose(); // for(int i=0;i<table.getColumnCount();i++){ // // table.getColumns()[i].dispose(); // } tableViewerColumn = new TableViewerColumn( checkboxTableViewer, SWT.NONE); TableColumn tableColumn = tableViewerColumn.getColumn(); tableColumn.setText("xx"); tableColumn.setWidth(60); tableViewerColumn_1 = new TableViewerColumn(checkboxTableViewer, SWT.NONE); TableColumn tableColumn_1 = tableViewerColumn_1.getColumn(); tableColumn_1.setWidth(60); tableColumn_1.setText("xx"); tableViewerColumn_2 = new TableViewerColumn(checkboxTableViewer, SWT.NONE); TableColumn tableColumn_2 = tableViewerColumn_2.getColumn(); tableColumn_2.setWidth(58); tableColumn_2.setText("xxx"); tableViewerColumn_3 = new TableViewerColumn(checkboxTableViewer, SWT.NONE); TableColumn tableColumn_3 = tableViewerColumn_3.getColumn(); tableColumn_3.setWidth(58); tableColumn_3.setText("xxx"); tableViewerColumn_4 = new TableViewerColumn(checkboxTableViewer, SWT.NONE); TableColumn tableColumn_4 = tableViewerColumn_4.getColumn(); tableColumn_4.setWidth(58); tableColumn_4.setText("xxx"); tableViewerColumn_5 = new TableViewerColumn(checkboxTableViewer, SWT.NONE); TableColumn tableColumn_5 = tableViewerColumn_5.getColumn(); tableColumn_5.setWidth(65); tableColumn_5.setText("xxx"); tableViewerColumn_6 = new TableViewerColumn(checkboxTableViewer, SWT.NONE); TableColumn tableColumn_6 = tableViewerColumn_6.getColumn(); tableColumn_6.setWidth(65); tableColumn_6.setText("xxx"); tableViewerColumn_7 = new TableViewerColumn(checkboxTableViewer, SWT.NONE); TableColumn tableColumn_7 = tableViewerColumn_7.getColumn(); tableColumn_7.setWidth(60); tableColumn_7.setText("xx"); tableViewerColumn_8 = new TableViewerColumn(checkboxTableViewer, SWT.NONE); TableColumn tableColumn_8 = tableViewerColumn_8.getColumn(); tableColumn_8.setWidth(60); tableColumn_8.setText("xx"); tableViewerColumn_9 = new TableViewerColumn(checkboxTableViewer, SWT.NONE); TableColumn tableColumn_9 = tableViewerColumn_9.getColumn(); tableColumn_9.setWidth(60); tableColumn_9.setText("xx"); tableViewerColumn_11 = new TableViewerColumn(checkboxTableViewer, SWT.NONE); TableColumn tableColumn_11 = tableViewerColumn_11.getColumn(); tableColumn_11.setWidth(58); tableColumn_11.setText("xx"); tableViewerColumn_10 = new TableViewerColumn(checkboxTableViewer, SWT.NONE); TableColumn tableColumn_10 = tableViewerColumn_10.getColumn(); tableColumn_10.setWidth(150); tableColumn_10.setText("xx"); } public void readerEquipmentData(String prot){ checkboxTableViewer.setContentProvider(new TableViewContentProvider()); // 内容器 checkboxTableViewer.setLabelProvider(new BeiTaiTableViewLabelProvider());// 标签器 //checkboxTableViewer.setInput("设置对象"); } }