JAVA.SWT/JFace: SWT高级控件之表格(一)

2014-11-24 02:33:33 · 作者: · 浏览: 0

package com.wjc.tree;

import java.util.Hashtable;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.custom.ControlEditor;
import org.eclipse.swt.custom.TableCursor;
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.custom.ViewForm;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;

public class TableSample {
public class TableItemControls{

Text text;
CCombo combo;
TableEditor tableeditor;
TableEditor tableeditor1;

public TableItemControls(Text text, CCombo combo, TableEditor tableeditor, TableEditor tableeditor1) {
// super();
this.text = text;
this.combo = combo;
this.tableeditor = tableeditor;
this.tableeditor1 = tableeditor1;
}
public void dispose()
{
text.dispose();
combo.dispose();
tableeditor.dispose();
tableeditor1.dispose();
}
};
private Shell sShell = null; // @jve:decl-index=0:visual-constraint="10,10"
private ViewForm viewForm = null;
private ToolBar toolBar = null;
private Composite composite = null;
private Table table = null;
private Menu menu = null;
private Hashtable tablecontrols = new Hashtable();

//创建ViewForm面板放置工具栏和表格
private void createViewForm() {
viewForm = new ViewForm(sShell, SWT.NONE);
viewForm.setTopCenterSeparate(true);
createToolBar();
viewForm.setTopLeft(toolBar);
createComposite();
viewForm.setContent(composite);
}

//创建工具栏
private void createToolBar() {
toolBar = new ToolBar(viewForm, SWT.FLAT);
final ToolItem add = new ToolItem(toolBar, SWT.PUSH);
add.setText("添加");
// add.setImage( ImageFactory.loadImage( toolBar.getDisplay() , ImageFactory.ADD_OBJ));
final ToolItem del = new ToolItem(toolBar, SWT.PUSH);
del.setText("删除");
// del.setImage( ImageFactory.loadImage( toolBar.getDisplay() , ImageFactory.DELETE_OBJ));
final ToolItem back = new ToolItem(toolBar, SWT.PUSH);
back.setText("上移");
// back.setImage( ImageFactory.loadImage( toolB