Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
Fix error reporting if access bridge DLL not available.
Browse files Browse the repository at this point in the history
  • Loading branch information
rpaquay committed Mar 2, 2016
1 parent 4a3ba9b commit c503018
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 41 deletions.
3 changes: 2 additions & 1 deletion AccessBridgeExplorer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AccessBridgeExplorer", "src
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{739A6BD0-482B-48A0-97C1-F80A266661B4}"
ProjectSection(SolutionItems) = preProject
LICENSE = LICENSE
screenshots\AccessBridgeExplorer.png = screenshots\AccessBridgeExplorer.png
CONTRIBUTING.md = CONTRIBUTING.md
LICENSE = LICENSE
README.md = README.md
EndProjectSection
EndProject
Expand Down
6 changes: 3 additions & 3 deletions src/AboutForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public void FillForm(Assembly application, AccessBridge accessBridge) {
accessBridgeVersionText.Text = string.Format("{0}", libraryVersion.FileVersion);
accessBridgePathText.Text = string.Format("{0}", libraryVersion.FileName);
} catch (Exception e) {
accessBridgeProductText.Text = @"<Error loading Access Bridge>";
accessBridgeVersionText.Text = e.Message;
accessBridgePathText.Text = "";
accessBridgePathText.Text = e.Message;
accessBridgeProductText.Text = @"<Error>";
accessBridgeVersionText.Text = @"<Error>";
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/ExplorerForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,13 @@ public ExplorerForm() {

private void MainForm_Shown(object sender, EventArgs e) {
InvokeLater(() => {
_controller.Initialize();
_controller.LogIntroMessages();
_controller.Initialize();
try {
_hotKeyHandler.Register(this, 1, CaptureKey);
} catch (Exception ex) {
_controller.LogErrorMessage(ex);
}
_controller.LogMessage("Ready!");
Application.Idle += ApplicationOnIdle;
});
}
Expand Down
59 changes: 36 additions & 23 deletions src/ExplorerFormController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -62,9 +63,6 @@ public ExplorerFormController(IExplorerFormView explorerFormView) {
PropertyOptions.AccessibleSelection |
PropertyOptions.AccessibleTable |
PropertyOptions.AccessibleActions;

CreateEventMenuItems();
CreatePropertyOptionsMenuItems();
}

public PropertyOptions PropertyOptions { get; set; }
Expand Down Expand Up @@ -227,6 +225,10 @@ public void Initialize() {
//TODO: We initialize now so that the access bridge DLL has time to
// discover the list of JVMs by the time we enumerate all windows.
_accessBridge.Initialize();
CreateEventMenuItems();
CreatePropertyOptionsMenuItems();
LogMessage("Ready!");
});
}

Expand Down Expand Up @@ -400,31 +402,42 @@ public void RefreshTree() {
return;

UiAction(() => {
var windows = _accessBridge.EnumWindows();
_view.AccessibilityTree.BeginUpdate();
try {
DisposeTreeNodeList(_view.AccessibilityTree.Nodes);
_view.AccessibilityTree.Nodes.Clear();
if (!windows.Any()) {
_view.AccessibilityTree.Nodes.Add("No JVM/Java window found. Try Refresh Again?");
return;
}
var topLevelNodes = windows.Select(x => new AccessibleNodeModel(_accessibleNodeModelResources, x));
topLevelNodes.ForEach(x => {
var node = x.CreateTreeNode();
_view.AccessibilityTree.Nodes.Add(node);
node.Expand();
});
} finally {
_view.AccessibilityTree.EndUpdate();
_accessBridge.Initialize();
var windows = _accessBridge.EnumWindows();
RefreshTree(windows);
} catch {
RefreshTree(new List<AccessibleJvm>());
throw;
}
_view.StatusLabel.Text = @"Ready.";
HideOverlayWindow();
HideToolTip();
_navigation.Clear();
});
}

private void RefreshTree(List<AccessibleJvm> windows) {
_view.AccessibilityTree.BeginUpdate();
try {
DisposeTreeNodeList(_view.AccessibilityTree.Nodes);
_view.AccessibilityTree.Nodes.Clear();

var topLevelNodes = windows.Select(x => new AccessibleNodeModel(_accessibleNodeModelResources, x));
topLevelNodes.ForEach(x => {
var node = x.CreateTreeNode();
_view.AccessibilityTree.Nodes.Add(node);
node.Expand();
});

if (_view.AccessibilityTree.Nodes.Count == 0) {
_view.AccessibilityTree.Nodes.Add("No JVM/Java window found. Try Refresh Again?");
}
} finally {
_view.AccessibilityTree.EndUpdate();
}
_view.StatusLabel.Text = @"Ready.";
HideOverlayWindow();
HideToolTip();
_navigation.Clear();
}

private static void DisposeTreeNodeList(TreeNodeCollection list) {
foreach (TreeNode node in list) {
DisposeTreeNode(node);
Expand Down
3 changes: 3 additions & 0 deletions src/ExplorerFormNavigation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public IEnumerable<NavigationEntry> ForwardEntries {
}

public void Clear() {
if (_currentEntry == null)
return;

_backwardEntries.Clear();
_forwardEntries.Clear();
_currentEntry = null;
Expand Down
26 changes: 16 additions & 10 deletions src/WindowsAccessBridge/AccessBridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public UnmanagedLibrary Library {
}
}

public bool IsLoaded { get { return _library != null; } }

public void Initialize() {
ThrowIfDisposed();
if (_library != null)
Expand Down Expand Up @@ -97,7 +99,8 @@ private void ThrowIfDisposed() {
}

public List<AccessibleJvm> EnumWindows() {
Initialize();
if (_library == null)
return new List<AccessibleJvm>();

var windows = new List<AccessibleWindow>();
var success = Win32.NativeMethods.EnumWindows((hWnd, lParam) => {
Expand Down Expand Up @@ -126,16 +129,19 @@ public List<AccessibleJvm> EnumWindows() {
}

private static UnmanagedLibrary LoadLibrary() {
UnmanagedLibrary library;
if (IntPtr.Size == 4) {
library = new UnmanagedLibrary("WindowsAccessBridge-32.dll");
} else if (IntPtr.Size == 8) {
library = new UnmanagedLibrary("WindowsAccessBridge-64.dll");
} else {
throw new InvalidOperationException("Unknown platform.");
try {
UnmanagedLibrary library;
if (IntPtr.Size == 4) {
library = new UnmanagedLibrary("WindowsAccessBridge-32.dll");
} else if (IntPtr.Size == 8) {
library = new UnmanagedLibrary("WindowsAccessBridge-64.dll");
} else {
throw new InvalidOperationException("Unknown platform.");
}
return library;
} catch (Exception e) {
throw new ApplicationException("Error loading Java Access Bridge DLL. Please install Java Runtime 7 or later.", e);
}

return library;
}

private static AccessBridgeFunctions LoadFunctions(UnmanagedLibrary library) {
Expand Down

0 comments on commit c503018

Please sign in to comment.