Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean Code for apitools/org.eclipse.pde.api.tools.ui #1641

Merged
merged 2 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apitools/org.eclipse.pde.api.tools.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.pde.api.tools.ui; singleton:=true
Bundle-Version: 1.4.0.qualifier
Bundle-Version: 1.4.100.qualifier
Bundle-Localization: plugin
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %providerName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,20 @@ public TreeViewerNavigator(TreeViewer viewer) {

public void navigateNext(boolean forward) {
TreeItem currentItem = getCurrentItem(forward);
if (currentItem == null)
if (currentItem == null) {
return;
}
TreeItem nextItem = null;
if (forward) {
nextItem = getNextItemForward(currentItem);
if (nextItem == null)
if (nextItem == null) {
nextItem = getFirstItem();
}
} else {
nextItem = getNextItemBackward(currentItem);
if (nextItem == null)
if (nextItem == null) {
nextItem = getLastItem();
}
}
if (nextItem != null) {
internalSetSelection(nextItem);
Expand All @@ -51,22 +54,26 @@ public void navigateNext(boolean forward) {

private TreeItem getFirstItem() {
TreeItem[] roots = fViewer.getTree().getItems();
if (roots.length == 0)
if (roots.length == 0) {
return null;
}
for (TreeItem root : roots) {
if (hasMatches(root))
if (hasMatches(root)) {
return root;
}
TreeItem firstChild = getFirstChildWithMatches(roots[0]);
if (firstChild != null)
if (firstChild != null) {
return firstChild;
}
}
return null;
}

private TreeItem getLastItem() {
TreeItem[] roots = fViewer.getTree().getItems();
if (roots.length == 0)
if (roots.length == 0) {
return null;
}
return getLastChildWithMatches(roots[roots.length-1]);
}

Expand All @@ -75,47 +82,55 @@ private TreeItem getNextItemBackward(TreeItem currentItem) {
TreeItem previousSibling = getNextSibling(currentItem, false);
if (previousSibling != null) {
TreeItem lastChild = getLastChildWithMatches(previousSibling);
if (lastChild != null)
if (lastChild != null) {
return lastChild;
if (hasMatches(previousSibling))
}
if (hasMatches(previousSibling)) {
return previousSibling;
}
return null;
}
TreeItem parent = currentItem.getParentItem();
if (parent != null) {
if (hasMatches(parent))
if (hasMatches(parent)) {
return parent;
}
return getNextItemBackward(parent);
}
return null;
}

private TreeItem getLastChildWithMatches(TreeItem currentItem) {
TreeItem[] children = getChildren(currentItem);
if (children.length == 0)
if (children.length == 0) {
return null;
}
TreeItem recursiveChild = getLastChildWithMatches(children[children.length-1]);
if (recursiveChild == null)
if (recursiveChild == null) {
return children[children.length-1];
}
return recursiveChild;
}

private TreeItem getNextItemForward(TreeItem currentItem) {
TreeItem child = getFirstChildWithMatches(currentItem);
if (child != null)
if (child != null) {
return child;
}
TreeItem nextSibling = getNextSibling(currentItem, true);
if (nextSibling != null) {
if (hasMatches(nextSibling))
if (hasMatches(nextSibling)) {
return nextSibling;
}
return getFirstChildWithMatches(nextSibling);
}
TreeItem parent = currentItem.getParentItem();
while (parent != null) {
nextSibling = getNextSibling(parent, true);
if (nextSibling != null) {
if (hasMatches(nextSibling))
if (hasMatches(nextSibling)) {
return nextSibling;
}
return getFirstChildWithMatches(nextSibling);
}
parent = parent.getParentItem();
Expand All @@ -125,12 +140,14 @@ private TreeItem getNextItemForward(TreeItem currentItem) {

private TreeItem getFirstChildWithMatches(TreeItem item) {
TreeItem[] children = getChildren(item);
if (children.length == 0)
if (children.length == 0) {
return null;
}
TreeItem child = children[0];

if (hasMatches(child))
if (hasMatches(child)) {
return child;
}
return getFirstChildWithMatches(child);
}

Expand All @@ -141,8 +158,9 @@ private TreeItem[] getChildren(TreeItem item) {

private TreeItem getNextSibling(TreeItem currentItem, boolean forward) {
TreeItem[] siblings = getSiblings(currentItem);
if (siblings.length < 2)
if (siblings.length < 2) {
return null;
}
int index = -1;
for (int i = 0; i <siblings.length; i++) {
if (siblings[i] == currentItem) {
Expand All @@ -161,8 +179,9 @@ private TreeItem getNextSibling(TreeItem currentItem, boolean forward) {
private TreeItem[] getSiblings(TreeItem currentItem) {
Tree tree = fViewer.getTree();
TreeItem parentItem = currentItem.getParentItem();
if (parentItem != null)
if (parentItem != null) {
return parentItem.getItems();
}
return tree.getItems();
}

Expand Down
Loading