forked from eclipse-platform/eclipse.platform.ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the ToolBar in the Find/Replace Overlay accessible eclipse-platf…
…orm#1910 Makes the Find/Replace Overlay options accessible by tabbing through the different option buttons. Implements a new "AccessibleToolBar" class which wraps the ToolBar and allows for being natively accessible by using the normal traversal mechanism provided by SWT. fixes eclipse-platform#1910
- Loading branch information
Showing
4 changed files
with
223 additions
and
82 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
.../org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AccessibleToolBar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package org.eclipse.ui.texteditor; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.events.TraverseEvent; | ||
import org.eclipse.swt.events.TraverseListener; | ||
import org.eclipse.swt.graphics.Color; | ||
import org.eclipse.swt.layout.GridLayout; | ||
import org.eclipse.swt.widgets.Composite; | ||
import org.eclipse.swt.widgets.ToolBar; | ||
import org.eclipse.swt.widgets.ToolItem; | ||
|
||
import org.eclipse.jface.layout.GridLayoutFactory; | ||
|
||
/** | ||
* This class wraps the ToolBar to make it possible to use tabulator-keys to | ||
* navigate between the buttons of a ToolBar. For this, we simulate a singular | ||
* ToolBar by putting each ToolItem into it's own ToolBar and composing them | ||
* into a Composite. Since the "Enter" keypress could not previously trigger | ||
* activation behavior, we listen for it manually and send according events if | ||
* necessary. | ||
* | ||
* @since 3.18 | ||
*/ | ||
class AccessibleToolBar extends Composite { | ||
|
||
private List<ToolBar> toolBars = new ArrayList<>(); | ||
|
||
public AccessibleToolBar(Composite parent) { | ||
super(parent, SWT.NONE); | ||
GridLayoutFactory.fillDefaults().numColumns(0).spacing(0, 0).margins(0, 0).applyTo(this); | ||
} | ||
|
||
/** | ||
* Creates a ToolItem handled by this ToolBar and returns it. Will add a | ||
* KeyListener which will catch all "Enter"-Keypresses. | ||
* | ||
* @param styleBits the StyleBits to apply to the created ToolItem | ||
* @return a newly created ToolItem | ||
*/ | ||
public ToolItem createToolItem(int styleBits) { | ||
ToolBar parent = new ToolBar(this, SWT.FLAT | SWT.HORIZONTAL); | ||
ToolItem result = new ToolItem(parent, styleBits); | ||
|
||
addToolItemTraverseListener(parent, result); | ||
|
||
((GridLayout) getLayout()).numColumns++; | ||
|
||
toolBars.add(parent); | ||
return result; | ||
} | ||
|
||
private void addToolItemTraverseListener(ToolBar parent, ToolItem result) { | ||
parent.addTraverseListener(new TraverseListener() { | ||
|
||
@Override | ||
public void keyTraversed(TraverseEvent e) { | ||
if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) { | ||
result.setSelection(!result.getSelection()); | ||
e.doit = false; | ||
} | ||
} | ||
|
||
}); | ||
} | ||
|
||
@Override | ||
public void setBackground(Color color) { | ||
super.setBackground(color); | ||
for (ToolBar bar : toolBars) { // we need to color each toolbar separately | ||
bar.setBackground(color); | ||
} | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
...ipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AccessibleToolItemBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.eclipse.ui.texteditor; | ||
|
||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.events.SelectionListener; | ||
import org.eclipse.swt.graphics.Image; | ||
import org.eclipse.swt.widgets.ToolItem; | ||
|
||
/** | ||
* Builder for ToolItems for {@link AccessibleToolBars}. | ||
* | ||
* @since 3.17 | ||
*/ | ||
public class AccessibleToolItemBuilder { | ||
private AccessibleToolBar accessibleToolBar; | ||
private int styleBits = SWT.NONE; | ||
private Image image; | ||
private String toolTipText; | ||
private SelectionListener selectionListener; | ||
|
||
public AccessibleToolItemBuilder(AccessibleToolBar accessibleToolBar) { | ||
this.accessibleToolBar = accessibleToolBar; | ||
} | ||
|
||
public AccessibleToolItemBuilder withStyleBits(int newStyleBits) { | ||
this.styleBits = newStyleBits; | ||
return this; | ||
} | ||
|
||
public AccessibleToolItemBuilder withImage(Image newImage) { | ||
this.image = newImage; | ||
return this; | ||
} | ||
|
||
public AccessibleToolItemBuilder withToolTipText(String newToolTipText) { | ||
this.toolTipText = newToolTipText; | ||
return this; | ||
} | ||
|
||
public AccessibleToolItemBuilder withSelectionListener(SelectionListener newSelectionListener) { | ||
this.selectionListener = newSelectionListener; | ||
return this; | ||
} | ||
|
||
public ToolItem build() { | ||
ToolItem toolItem = accessibleToolBar.createToolItem(styleBits); | ||
|
||
if (image != null) { | ||
toolItem.setImage(image); | ||
} | ||
|
||
if (toolTipText != null) { | ||
toolItem.setToolTipText(toolTipText); | ||
} | ||
|
||
if (selectionListener != null) { | ||
toolItem.addSelectionListener(selectionListener); | ||
} | ||
|
||
return toolItem; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters