use of org.eclipse.jface.viewers.TreePath in project jbosstools-hibernate by jbosstools.
the class HibernateSearchEnabledPropertyTesterTest method containsHibernateSearchLib.
@Test
public void containsHibernateSearchLib() throws MalformedURLException {
ConsoleConfiguration consoleConfiguration = mock(ConsoleConfiguration.class);
ConsoleConfigurationPreferences prefs = mock(ConsoleConfigurationPreferences.class);
when(consoleConfiguration.getPreferences()).thenReturn(prefs);
when(prefs.getCustomClassPathURLS()).thenReturn(new URL[] { new URL("file", "", "hibernate-search-orm-version") });
TreePath treePath = new TreePath(new Object[] { consoleConfiguration });
ITreeSelection receiver = new TreeSelection(treePath);
HibernateSearchEnabledPropertyTester tester = new HibernateSearchEnabledPropertyTester();
assertTrue(tester.test(receiver, "doesn't matter", null, null));
}
use of org.eclipse.jface.viewers.TreePath in project jbosstools-hibernate by jbosstools.
the class OneParentConfigPropertyTesterTest method testSameConfig.
@Test
public void testSameConfig() {
ConsoleConfiguration consoleConfiguration = mock(ConsoleConfiguration.class);
TreePath treePath1 = new TreePath(new Object[] { consoleConfiguration });
TreePath treePath2 = new TreePath(new Object[] { consoleConfiguration });
ITreeSelection receiver = new TreeSelection(new TreePath[] { treePath1, treePath2 });
OneParentConfigPropertyTester propertyTester = new OneParentConfigPropertyTester();
assertTrue(propertyTester.test(receiver, "doesn't matter", null, null));
}
use of org.eclipse.jface.viewers.TreePath in project jbosstools-hibernate by jbosstools.
the class OpenQueryEditorAction method doRun.
protected boolean doRun(TreePath[] paths) {
boolean showed = false;
for (int i = 0; i < paths.length; i++) {
TreePath path = paths[i];
ConsoleConfiguration config = (ConsoleConfiguration) path.getSegment(0);
try {
openQueryEditor(config, generateQuery(path));
showed = true;
} catch (Exception he) {
HibernateConsolePlugin.getDefault().showError(null, HibernateConsoleMessages.OpenQueryEditorAction_exception_open_hql_editor, he);
}
}
return showed;
}
use of org.eclipse.jface.viewers.TreePath in project jbosstools-hibernate by jbosstools.
the class OpenSourceAction method run.
public void run() {
IStructuredSelection sel = getStructuredSelection();
if (!(sel instanceof TreeSelection)) {
return;
}
TreePath[] paths = ((TreeSelection) sel).getPaths();
for (int i = 0; i < paths.length; i++) {
TreePath path = paths[i];
Object lastSegment = path.getLastSegment();
IPersistentClass persClass = getPersistentClass(lastSegment);
ConsoleConfiguration consoleConfig = (ConsoleConfiguration) (path.getSegment(0));
String fullyQualifiedName = null;
if (lastSegment instanceof IProperty) {
Object prevSegment = path.getParentPath().getLastSegment();
if (prevSegment instanceof IProperty && ((IProperty) prevSegment).isComposite()) {
fullyQualifiedName = ((IValue) ((IProperty) prevSegment).getValue()).getComponentClassName();
}
}
if (fullyQualifiedName == null && persClass != null) {
fullyQualifiedName = persClass.getClassName();
}
try {
run(consoleConfig, lastSegment, fullyQualifiedName);
} catch (JavaModelException e) {
HibernateConsolePlugin.getDefault().logErrorMessage(HibernateConsoleMessages.OpenSourceAction_cannot_find_source_file, e);
} catch (PartInitException e) {
HibernateConsolePlugin.getDefault().logErrorMessage(HibernateConsoleMessages.OpenSourceAction_cannot_open_source_file, e);
} catch (FileNotFoundException e) {
HibernateConsolePlugin.getDefault().logErrorMessage(HibernateConsoleMessages.OpenSourceAction_cannot_find_source_file, e);
}
}
}
use of org.eclipse.jface.viewers.TreePath in project nebula.widgets.nattable by eclipse.
the class NavigationPart method postConstruct.
@PostConstruct
public void postConstruct(Composite parent) {
final TreeViewer navTreeViewer = new TreeViewer(parent);
final NavContentProvider contentProvider = new NavContentProvider() {
@Override
public Object[] getElements(Object inputElement) {
Set<String> topLevelElements = new LinkedHashSet<>();
String[] examplePaths = (String[]) inputElement;
for (final String examplePath : examplePaths) {
String parentPath = "";
String absolutePath = "";
// remove the package name for the tree structure
String path = examplePath;
if (examplePath.startsWith(INatExample.TUTORIAL_EXAMPLES_PREFIX)) {
path = examplePath.replace(INatExample.BASE_PATH, "");
} else if (examplePath.startsWith(INatExample.CLASSIC_EXAMPLES_PREFIX)) {
path = examplePath.replace(INatExample.CLASSIC_BASE_PATH, "");
} else if (examplePath.startsWith(E4_EXAMPLES_PREFIX)) {
path = examplePath.replace(E4_BASE_PATH, "");
}
final StringTokenizer tok = new StringTokenizer(path, "/");
while (tok.hasMoreTokens()) {
final String pathElement = tok.nextToken();
if (parentPath.length() == 0) {
topLevelElements.add("/" + pathElement);
}
absolutePath += "/" + pathElement;
final Collection<String> children = getChildren(parentPath);
children.add(absolutePath);
parentPath = absolutePath;
}
}
return topLevelElements.toArray();
}
};
navTreeViewer.setContentProvider(contentProvider);
navTreeViewer.setLabelProvider(new NavLabelProvider(contentProvider) {
@Override
public String getText(Object element) {
String str = (String) element;
if (!contentProvider.hasChildren(element)) {
INatExample example = getExample(str);
return example.getName();
}
int lastSlashIndex = str.lastIndexOf('/');
if (lastSlashIndex < 0) {
return format(str);
} else {
return format(str.substring(lastSlashIndex + 1));
}
}
});
navTreeViewer.setInput(getExamplePaths());
navTreeViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
TreeSelection selection = (TreeSelection) event.getSelection();
for (TreePath path : selection.getPaths()) {
// check for item - if node expand/collapse, if child open
if (contentProvider.hasChildren(path.getLastSegment().toString())) {
boolean expanded = navTreeViewer.getExpandedState(path);
navTreeViewer.setExpandedState(path, !expanded);
} else {
openExampleInTab(path.getLastSegment().toString());
}
}
}
});
GridLayout layout = new GridLayout();
layout.marginWidth = 0;
layout.marginHeight = 0;
parent.setLayout(layout);
GridDataFactory.fillDefaults().grab(true, true).applyTo(navTreeViewer.getControl());
}
Aggregations