📄 tableview.java
字号:
// Listeners to size the folder
sash.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
final boolean FASTDRAG = true;
if (FASTDRAG && e.detail == SWT.DRAG)
return;
if (tabFolder.getMinimized()) {
tabFolder.setMinimized(false);
refreshSelectedSubView();
configMan.setParameter(sPropertiesPrefix + ".subViews.minimized", false);
}
Rectangle area = form.getClientArea();
tabFolderData.height = area.height - e.y - e.height - iFolderHeightAdj;
form.layout();
Double l = new Double((double) tabFolder.getBounds().height
/ form.getBounds().height);
sash.setData("PCT", l);
if (e.detail != SWT.DRAG)
configMan.setParameter(sPropertiesPrefix + ".SplitAt", (int) (l
.doubleValue() * 10000));
}
});
final CTabFolder2Adapter folderListener = new CTabFolder2Adapter() {
public void minimize(CTabFolderEvent event) {
tabFolder.setMinimized(true);
tabFolderData.height = iFolderHeightAdj;
form.layout();
configMan.setParameter(sPropertiesPrefix + ".subViews.minimized", true);
}
public void restore(CTabFolderEvent event) {
tabFolder.setMinimized(false);
form.notifyListeners(SWT.Resize, null);
refreshSelectedSubView();
configMan.setParameter(sPropertiesPrefix + ".subViews.minimized", false);
}
};
tabFolder.addCTabFolder2Listener(folderListener);
tabFolder.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
if (tabFolder.getMinimized()) {
folderListener.restore(null);
// If the user clicked down on the restore button, and we restore
// before the CTabFolder does, CTabFolder will minimize us again
// There's no way that I know of to determine if the mouse is
// on that button!
// one of these will tell tabFolder to cancel
e.button = 0;
tabFolder.notifyListeners(SWT.MouseExit, null);
}
}
});
form.addListener(SWT.Resize, new Listener() {
public void handleEvent(Event e) {
if (tabFolder.getMinimized())
return;
Double l = (Double) sash.getData("PCT");
if (l != null) {
tabFolderData.height = (int) (form.getBounds().height * l
.doubleValue())
- iFolderHeightAdj;
form.layout();
}
}
});
if (coreTabViews != null)
for (int i = 0; i < coreTabViews.length; i++)
addTabView(coreTabViews[i]);
// Call plugin listeners
if (pluginViews != null) {
String[] sNames = (String[]) pluginViews.keySet().toArray(new String[0]);
for (int i = 0; i < sNames.length; i++) {
UISWTViewEventListener l = (UISWTViewEventListener) pluginViews
.get(sNames[i]);
if (l != null) {
try {
UISWTViewImpl view = new UISWTViewImpl(sTableID, sNames[i], l);
addTabView(view);
} catch (Exception e) {
// skip, plugin probably specifically asked to not be added
}
}
}
}
if (configMan.getBooleanParameter(
sPropertiesPrefix + ".subViews.minimized", false)) {
tabFolder.setMinimized(true);
tabFolderData.height = iFolderHeightAdj;
} else {
tabFolder.setMinimized(false);
}
tabFolder.setSelection(0);
return form;
}
/** Creates a composite within the specified composite and sets its layout
* to a default FillLayout().
*
* @param composite to create your Composite under
* @return The newly created composite
*/
public Composite createMainPanel(Composite composite) {
Composite panel = new Composite(composite,SWT.NULL);
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
panel.setLayout(layout);
return panel;
}
/** Creates the Table.
*
* @return The created Table.
*/
public Table createTable(Composite panel) {
table = new Table(panel, iTableStyle);
table.setLayoutData(new GridData(GridData.FILL_BOTH));
return table;
}
/** Sets up the sorter, columns, and context menu.
*
* @param table Table to be initialized
*/
public void initializeTable(final Table table) {
initializeColumnDefs();
iTableStyle = table.getStyle();
bTableVirtual = (iTableStyle & SWT.VIRTUAL) != 0;
table.setLinesVisible(Constants.isLinux || Constants.isSolaris);
table.setMenu(menu);
table.setData("Name", sTableID);
table.setData("TableView", this);
// Setup table
// -----------
// XXX On linux (an other OSes?), changing the column indicator doesn't
// work until the table is shown. Since SWT.Show doesn't trigger,
// use the first paint trigger.
table.addPaintListener(new PaintListener() {
boolean first = true;
public void paintControl(PaintEvent event) {
if (first) {
changeColumnIndicator();
first = false;
}
if(event.width == 0 || event.height == 0) return;
doPaint(event.gc);
}
});
// Deselect rows if user clicks on a black spot (a spot with no row)
table.addMouseListener(new MouseAdapter() {
private TableCellMouseEvent createMouseEvent(TableCellCore cell,
MouseEvent e, int type) {
TableCellMouseEvent event = new TableCellMouseEvent();
event.cell = cell;
event.eventType = type;
event.button = e.button;
// TODO: Change to not use SWT masks
event.keyboardState = e.stateMask;
event.skipCoreFunctionality = false;
Rectangle r = cell.getBounds();
event.x = e.x - r.x + VerticalAligner.getTableAdjustHorizontallyBy(table);
event.y = e.y - r.y + VerticalAligner.getTableAdjustVerticalBy(table);
return event;
}
public void mouseDoubleClick(MouseEvent e) {
TableColumnCore tc = getTableColumnByOffset(e.x);
TableCellCore cell = getTableCell(e.x, e.y);
if (cell != null && tc != null) {
TableCellMouseEvent event = createMouseEvent(cell, e,
TableCellMouseEvent.EVENT_MOUSEDOUBLECLICK);
tc.invokeCellMouseListeners(event);
cell.invokeMouseListeners(event);
if (event.skipCoreFunctionality)
lCancelSelectionTriggeredOn = System.currentTimeMillis();
}
}
public void mouseUp(MouseEvent e) {
TableColumnCore tc = getTableColumnByOffset(e.x);
TableCellCore cell = getTableCell(e.x, e.y);
if (cell != null && tc != null) {
TableCellMouseEvent event = createMouseEvent(cell, e,
TableCellMouseEvent.EVENT_MOUSEUP);
tc.invokeCellMouseListeners(event);
cell.invokeMouseListeners(event);
if (event.skipCoreFunctionality)
lCancelSelectionTriggeredOn = System.currentTimeMillis();
}
}
public void mouseDown(MouseEvent e) {
TableColumnCore tc = getTableColumnByOffset(e.x);
TableCellCore cell = getTableCell(e.x, e.y);
if (cell != null && tc != null) {
TableCellMouseEvent event = createMouseEvent(cell, e,
TableCellMouseEvent.EVENT_MOUSEDOWN);
tc.invokeCellMouseListeners(event);
cell.invokeMouseListeners(event);
if (event.skipCoreFunctionality)
lCancelSelectionTriggeredOn = System.currentTimeMillis();
}
iMouseX = e.x;
try {
if (table.getItemCount() <= 0)
return;
// skip if outside client area (ie. scrollbars)
Rectangle rTableArea = table.getClientArea();
//System.out.println("Mouse="+iMouseX+"x"+e.y+";TableArea="+rTableArea);
Point pMousePosition = new Point(e.x, e.y);
if (rTableArea.contains(pMousePosition)) {
TableItem ti = table.getItem(table.getItemCount() - 1);
Rectangle cellBounds = ti.getBounds(table.getColumnCount() - 1);
// OSX returns 0 size if the cell is not on screen (sometimes? all the time?)
if (cellBounds.width <= 0 || cellBounds.height <= 0)
return;
//System.out.println("cellbounds="+cellBounds);
if (e.x > cellBounds.x + cellBounds.width ||
e.y > cellBounds.y + cellBounds.height) {
table.deselectAll();
}
/* // This doesn't work because of OS inconsistencies when table is scrolled
// Re-enable once SWT fixes the problem
// Bug 103934: Table.getItem(Point) uses incorrect calculation on Motif
// Fixed 20050718 SWT 3.2M1 (3201) & SWT 3.1.1 (3139)
// TODO: Get Build IDs and use this code (if it works)
TableItem ti = table.getItem(pMousePosition);
if (ti == null)
table.deselectAll();
*/
}
} catch (Exception ex) {
System.out.println("MouseDownError");
Debug.printStackTrace( ex );
}
}
});
// XXX this may not be needed if all platforms process mouseDown
// before the menu
table.addMouseMoveListener(new MouseMoveListener() {
public void mouseMove(MouseEvent e) {
iMouseX = e.x;
}
});
table.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent event) {
// Refresh rows when top index has changed
visibleRowsChanged();
if (tabViews == null && tabViews.size() == 0)
return;
// Set Data Object for all tabs. Tabs of PluginView are sent the plugin
// Peer object, while Tabs of IView are sent the core PEPeer object.
// TODO: Send all datasources
Object[] dataSourcesCore = getSelectedDataSources(true);
Object[] dataSourcesPlugin = null;
for (int i = 0; i < tabViews.size(); i++) {
IView view = (IView) tabViews.get(i);
if (view != null) {
if (view instanceof UISWTViewImpl) {
if (dataSourcesPlugin == null)
dataSourcesPlugin = getSelectedDataSources(false);
((UISWTViewImpl) view)
.dataSourceChanged(dataSourcesPlugin.length == 0 ? null
: dataSourcesPlugin);
} else {
view.dataSourceChanged(dataSourcesCore.length == 0 ? null
: dataSourcesCore);
}
}
}
}
public void widgetDefaultSelected(SelectionEvent e) {
if (lCancelSelectionTriggeredOn > 0
&& System.currentTimeMillis() - lCancelSelectionTriggeredOn < 200) {
e.doit = false;
lCancelSelectionTriggeredOn = -1;
} else {
runDefaultAction();
}
}
});
// Refresh rows when table has grown in height
table.addListener(SWT.Resize, new Listener() {
public void handleEvent(Event e) {
visibleRowsChanged();
}
});
if (bTableVirtual)
table.addListener(SWT.SetData, new Listener() {
public void handleEvent(Event e) {
final TableItem item = (TableItem) e.item;
// This is catch is temporary for SWT 3212, because there are cases where
// it says it isn't disposed, when it really almost is
try {
item.setData("SD", "1");
} catch (NullPointerException badSWT) {
return;
}
int tableIndex = table.indexOf(item);
if (tableIndex < 0) {
System.out.println("XXX TI < 0!!");
return;
}
TableRowCore row = (TableRowCore) item.getData("TableRow");
if (row == null || row.getIndex() != tableIndex) {
//System.out.println("SetData " + tableIndex + ": Sort..");
fillRowGaps(false);
row = (TableRowCore) item.getData("TableRow");
if (row == null || row.getIndex() != tableIndex) {
// row's been deleted. tableitem probably about to be remove
// (hopefully!)
if (DEBUGADDREMOVE)
Debug.outStackTrace();
return;
}
} else {
//System.out.println("SetData " + tableIndex + ": invalidate");
row.invalidate();
}
// User made the row visible, they want satisfaction now!
if (row.setIconSize(ptIconSize))
visibleRowsChanged();
else
row.refresh(true);
if (!Constants.isLinux) {
Utils.alternateRowBackground(item);
// Bug, background color doesn't fully draw in SetData
Rectangle r = item.getBounds(0);
table.redraw(0, r.y, table.getClientArea().width, r.height, false);
}
}
});
// bypasses disappearing graphic glitch on Mac OS X
/* Temporarily Disabled to see if we need it anymore
if(Constants.isOSX) {
table.addSelectionListener(new SelectionAdapter() {
public void widgetSelected( SelectionEvent event) {
GroupTableRowRunner refresher = new GroupTableRowRunner() {
public void run(TableRowCore row) {
row.setValid(false);
row.refresh(true);
}
};
TableItem[] sel = table.getSelection();
ArrayList toRefresh = new ArrayList(sel.length);
if(oldSelectedItems != null) {
runForTableItems(oldSelectedItems, refresher);
for (int i = 0; i < sel.length; i++) {
if(!oldSelectedItems.contains(sel[i]))
toRefresh.add(sel[i]);
}
}
else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -