-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
"A suspicious use of an incrementer in for loop"
- Loading branch information
Showing
2 changed files
with
122 additions
and
105 deletions.
There are no files selected for viewing
210 changes: 105 additions & 105 deletions
210
....runtime/src/com/windowtester/runtime/swt/internal/finder/eclipse/views/ViewExplorer.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 |
---|---|---|
@@ -1,105 +1,105 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012 Google, Inc. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Google, Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package com.windowtester.runtime.swt.internal.finder.eclipse.views; | ||
|
||
import org.eclipse.ui.views.IViewCategory; | ||
import org.eclipse.ui.views.IViewDescriptor; | ||
import org.eclipse.ui.views.IViewRegistry; | ||
|
||
import com.windowtester.runtime.swt.internal.finder.eclipse.WorkbenchFinder; | ||
import com.windowtester.runtime.swt.internal.finder.eclipse.views.ViewFinder.IViewMatcher; | ||
|
||
/** | ||
* A helper for navigating and exploring views. | ||
*/ | ||
public class ViewExplorer { | ||
|
||
public void spelunk() { | ||
IViewDescriptor[] views = getViews(); | ||
for (int i = 0; i < views.length; i++) { | ||
IViewDescriptor view = views[i]; | ||
// System.out.println(Arrays.toString(view.getCategoryPath())); | ||
System.out.println(view); | ||
System.out.println(findCategoryPath(view)); | ||
System.out.println("----"); | ||
} | ||
|
||
} | ||
|
||
|
||
private IViewDescriptor[] getViews() { | ||
return getViewRegistry().getViews(); | ||
} | ||
|
||
|
||
public String findCategory(String viewName) { | ||
return findCategoryPath(findView(viewName)); | ||
|
||
} | ||
|
||
|
||
public String findCategoryPath(IViewDescriptor view) { | ||
if (view == null) | ||
return null; | ||
IViewCategory[] categories = getViewRegistry().getCategories(); | ||
for (int i = 0; i < categories.length; i++) { | ||
IViewCategory category = categories[i]; | ||
IViewDescriptor[] views = category.getViews(); | ||
for (int j = 0; j < views.length; j++) { | ||
IViewDescriptor candidateView = views[i]; | ||
if (view == candidateView) | ||
return category.getLabel(); | ||
} | ||
} | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
|
||
private IViewRegistry getViewRegistry() { | ||
return WorkbenchFinder.getWorkbench().getViewRegistry(); | ||
} | ||
|
||
|
||
public IViewDescriptor findView(String name) { | ||
if (name == null) | ||
return null; | ||
IViewDescriptor[] views = getViews(); | ||
for (int i = 0; i < views.length; i++) { | ||
IViewDescriptor view = views[i]; | ||
String label = view.getLabel(); | ||
if (label == null) | ||
continue; | ||
if (name.equals(view.getLabel())) | ||
return view; | ||
} | ||
return null; | ||
} | ||
|
||
|
||
|
||
|
||
public IViewDescriptor findMatchInRegistry(IViewMatcher matcher) { | ||
IViewDescriptor[] views = getViews(); | ||
for (int i = 0; i < views.length; i++) { | ||
IViewDescriptor view = views[i]; | ||
if (matcher.matches(view)) | ||
return view; | ||
} | ||
return null; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
} | ||
/******************************************************************************* | ||
* Copyright (c) 2012 Google, Inc. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Google, Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package com.windowtester.runtime.swt.internal.finder.eclipse.views; | ||
|
||
import org.eclipse.ui.views.IViewCategory; | ||
import org.eclipse.ui.views.IViewDescriptor; | ||
import org.eclipse.ui.views.IViewRegistry; | ||
|
||
import com.windowtester.runtime.swt.internal.finder.eclipse.WorkbenchFinder; | ||
import com.windowtester.runtime.swt.internal.finder.eclipse.views.ViewFinder.IViewMatcher; | ||
|
||
/** | ||
* A helper for navigating and exploring views. | ||
*/ | ||
public class ViewExplorer { | ||
|
||
public void spelunk() { | ||
IViewDescriptor[] views = getViews(); | ||
for (int i = 0; i < views.length; i++) { | ||
IViewDescriptor view = views[i]; | ||
// System.out.println(Arrays.toString(view.getCategoryPath())); | ||
System.out.println(view); | ||
System.out.println(findCategoryPath(view)); | ||
System.out.println("----"); | ||
} | ||
|
||
} | ||
|
||
|
||
private IViewDescriptor[] getViews() { | ||
return getViewRegistry().getViews(); | ||
} | ||
|
||
|
||
public String findCategory(String viewName) { | ||
return findCategoryPath(findView(viewName)); | ||
|
||
} | ||
|
||
|
||
public String findCategoryPath(IViewDescriptor view) { | ||
if (view == null) | ||
return null; | ||
IViewCategory[] categories = getViewRegistry().getCategories(); | ||
for (int i = 0; i < categories.length; i++) { | ||
IViewCategory category = categories[i]; | ||
IViewDescriptor[] views = category.getViews(); | ||
for (int j = 0; j < views.length; j++) { | ||
IViewDescriptor candidateView = views[j]; | ||
if (view == candidateView) | ||
return category.getLabel(); | ||
} | ||
} | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
|
||
private IViewRegistry getViewRegistry() { | ||
return WorkbenchFinder.getWorkbench().getViewRegistry(); | ||
} | ||
|
||
|
||
public IViewDescriptor findView(String name) { | ||
if (name == null) | ||
return null; | ||
IViewDescriptor[] views = getViews(); | ||
for (int i = 0; i < views.length; i++) { | ||
IViewDescriptor view = views[i]; | ||
String label = view.getLabel(); | ||
if (label == null) | ||
continue; | ||
if (name.equals(view.getLabel())) | ||
return view; | ||
} | ||
return null; | ||
} | ||
|
||
|
||
|
||
|
||
public IViewDescriptor findMatchInRegistry(IViewMatcher matcher) { | ||
IViewDescriptor[] views = getViews(); | ||
for (int i = 0; i < views.length; i++) { | ||
IViewDescriptor view = views[i]; | ||
if (matcher.matches(view)) | ||
return view; | ||
} | ||
return null; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
} |
17 changes: 17 additions & 0 deletions
17
com.windowtester_test/src/com/windowtester/test/eclipse/ViewExplorerTest.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,17 @@ | ||
package com.windowtester.test.eclipse; | ||
|
||
import com.windowtester.runtime.swt.internal.finder.eclipse.views.ViewExplorer; | ||
|
||
public class ViewExplorerTest extends BaseTest { | ||
|
||
ViewExplorer viewExplorer = new ViewExplorer(); | ||
|
||
public void testSpelunk() { | ||
viewExplorer.spelunk(); | ||
} | ||
|
||
public void testFindCategory() { | ||
assertEquals("General", viewExplorer.findCategory("Welcome")); | ||
} | ||
|
||
} |