Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott Kovatch2010-04-26 19:13:37 -0400
committerScott Kovatch2010-04-26 19:13:37 -0400
commit6d49e8bb5d280ae529f3250bc92c8079da1bb4a3 (patch)
tree69ba457d62a773e2c5a6cc322a994a853f4ac297
parentec72bbaf88fcf0880e1111dbed6f65bd82c35c85 (diff)
downloadeclipse.platform.swt-accessibility_work_R3_6.tar.gz
eclipse.platform.swt-accessibility_work_R3_6.tar.xz
eclipse.platform.swt-accessibility_work_R3_6.zip
CTable now fires notifications when the row or column count changes. Changed example to add/remove rows.accessibility_work_R3_6
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/AccessibleTableExample.java77
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/CTable.java52
2 files changed, 126 insertions, 3 deletions
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/AccessibleTableExample.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/AccessibleTableExample.java
index 0a4a446c51..32d7ab5dbe 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/AccessibleTableExample.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/AccessibleTableExample.java
@@ -13,8 +13,9 @@ package org.eclipse.swt.examples.accessibility;
import java.util.*;
import org.eclipse.swt.*;
-import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
+import org.eclipse.swt.widgets.*;
/**
* This example shows how to use AccessibleTableListener and
@@ -23,6 +24,8 @@ import org.eclipse.swt.layout.*;
*/
public class AccessibleTableExample {
static ResourceBundle resourceBundle = ResourceBundle.getBundle("examples_accessibility"); //$NON-NLS-1$
+ static CTable table1;
+
static String getResourceString(String key) {
try {
return resourceBundle.getString(key);
@@ -39,6 +42,58 @@ public class AccessibleTableExample {
AccessibleTableExample.getResourceString("color4"),
AccessibleTableExample.getResourceString("color5"),};
+ private static SelectionListener addButtonHandler = new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ int currSize = table1.getItemCount();
+ int colCount = table1.getColumnCount();
+ CTableItem item = new CTableItem(table1, SWT.NONE);
+ String[] cells = new String[colCount];
+
+ for (int i = 0; i < colCount; i++) {
+ cells[i] = "C" + i + "R" + currSize;
+ }
+ item.setText(cells);
+ }
+ };
+
+ private static SelectionListener removeButtonHandler = new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ int currSize = table1.getItemCount();
+ if (currSize > 0) {
+ table1.remove(currSize - 1);
+ }
+ }
+ };
+
+ private static SelectionListener removeSelectedHandler = new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ CTableItem[] selectedItems = table1.getSelection();
+ for (int i = 0; i < selectedItems.length; i++) {
+ selectedItems[i].dispose();
+ }
+ }
+ };
+
+ private static SelectionListener addColumnHandler = new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ int currSize = table1.getColumnCount();
+ CTableColumn item = new CTableColumn(table1, SWT.NONE);
+ item.setText("Col " + currSize);
+ item.setWidth(50);
+ }
+ };
+
+ private static SelectionListener removeColumnHandler = new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ int colCount = table1.getColumnCount();
+
+ if (colCount > 0) {
+ CTableColumn column = table1.getColumn(colCount - 1);
+ column.dispose();
+ }
+ }
+ };
+
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
@@ -51,7 +106,7 @@ public class AccessibleTableExample {
new Label(group, SWT.NONE).setText("CTable with column headers");
- CTable table1 = new CTable(group, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
+ table1 = new CTable(group, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
table1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
table1.setHeaderVisible(true);
table1.setLinesVisible(true);
@@ -65,6 +120,24 @@ public class AccessibleTableExample {
item.setText(new String [] {"C0R" + row, "C1R" + row, "C2R" + row});
}
+ Composite btnGroup = new Composite(group, SWT.NONE);
+ btnGroup.setLayout(new GridLayout(2, false));
+ Button btn = new Button(btnGroup, SWT.PUSH);
+ btn.setText("Add rows");
+ btn.addSelectionListener(addButtonHandler);
+ btn = new Button(btnGroup, SWT.PUSH);
+ btn.setText("Remove rows");
+ btn.addSelectionListener(removeButtonHandler);
+ btn = new Button(btnGroup, SWT.PUSH);
+ btn.setText("Remove selected rows");
+ btn.addSelectionListener(removeSelectedHandler);
+ btn = new Button(btnGroup, SWT.PUSH);
+ btn.setText("Add column");
+ btn.addSelectionListener(addColumnHandler);
+ btn = new Button(btnGroup, SWT.PUSH);
+ btn.setText("Remove last column");
+ btn.addSelectionListener(removeColumnHandler);
+
new Label(group, SWT.NONE).setText("CTable used as a list");
CTable table2 = new CTable(group, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/CTable.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/CTable.java
index 1d39a3a316..849820a31f 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/CTable.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/CTable.java
@@ -499,6 +499,15 @@ void createItem (CTableColumn column, int index) {
redrawFromItemDownwards (topIndex);
}
}
+
+ /* Columns were added, so notify the accessible. */
+ int[] eventData = new int[5];
+ eventData[0] = ACC.INSERT;
+ eventData[1] = 0;
+ eventData[2] = 0;
+ eventData[3] = index;
+ eventData[4] = 1;
+ getAccessible().sendEvent(ACC.EVENT_TABLE_CHANGED, eventData);
}
void createItem (CTableItem item) {
int index = item.index;
@@ -729,6 +738,14 @@ void destroyItem (CTableColumn column) {
}
}
+ int[] eventData = new int[5];
+ eventData[0] = ACC.DELETE;
+ eventData[1] = 0;
+ eventData[2] = 0;
+ eventData[3] = index;
+ eventData[4] = 1;
+ getAccessible().sendEvent(ACC.EVENT_TABLE_CHANGED, eventData);
+
if (sortColumn == column) {
sortColumn = null;
}
@@ -800,8 +817,15 @@ void destroyItem (CTableItem item) {
*/
if (itemsCount == 0 && isFocusControl ()) {
redraw ();
- return;
}
+
+ int[] eventData = new int[5];
+ eventData[0] = ACC.DELETE;
+ eventData[1] = 0;
+ eventData[2] = 0;
+ eventData[3] = index;
+ eventData[4] = 1;
+ getAccessible().sendEvent(ACC.EVENT_TABLE_CHANGED, eventData);
}
Image getArrowDownImage () {
return (Image) display.getData (ID_ARROWDOWN);
@@ -3360,9 +3384,19 @@ public void removeAll () {
}
items = new CTableItem [0];
selectedItems = new CTableItem [0];
+ int oldCount = itemsCount;
itemsCount = topIndex = 0;
anchorItem = lastClickedItem = null;
lastSelectionEvent = null;
+
+ int[] eventData = new int[5];
+ eventData[0] = ACC.DELETE;
+ eventData[1] = 0;
+ eventData[2] = oldCount;
+ eventData[3] = 0;
+ eventData[4] = 0;
+ getAccessible().sendEvent(ACC.EVENT_TABLE_CHANGED, eventData);
+
ScrollBar vBar = getVerticalBar ();
if (vBar != null) {
vBar.setMaximum (1);
@@ -3777,6 +3811,14 @@ public void setItemCount (int count) {
CTableItem newFocusItem = count > 0 ? items [count - 1] : null;
setFocusItem (newFocusItem, false);
}
+ int[] eventData = new int[5];
+ eventData[0] = ACC.DELETE;
+ eventData[1] = redrawStart;
+ eventData[2] = redrawEnd - redrawStart;
+ eventData[3] = 0;
+ eventData[4] = 0;
+ getAccessible().sendEvent(ACC.EVENT_TABLE_CHANGED, eventData);
+
itemsCount = count;
if (columns.length == 0) updateHorizontalBar ();
} else {
@@ -3789,6 +3831,14 @@ public void setItemCount (int count) {
items [i] = new CTableItem (this, SWT.NONE, i, false);
itemsCount++;
}
+
+ int[] eventData = new int[5];
+ eventData[0] = ACC.INSERT;
+ eventData[1] = redrawStart;
+ eventData[2] = count;
+ eventData[3] = 0;
+ eventData[4] = 0;
+ getAccessible().sendEvent(ACC.EVENT_TABLE_CHANGED, eventData);
if (oldCount == 0) focusItem = items [0];
}

Back to the top