use of org.eclipse.jface.viewers.ITreeSelection in project jbosstools-hibernate by jbosstools.
the class HibernateSearchEnabledPropertyTester method test.
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (!(receiver instanceof ITreeSelection)) {
return false;
}
ITreeSelection selection = (ITreeSelection) receiver;
Set<ConsoleConfiguration> consoleConfigs = new HashSet<ConsoleConfiguration>();
for (TreePath path : selection.getPaths()) {
if (path.getFirstSegment() instanceof ConsoleConfiguration) {
consoleConfigs.add((ConsoleConfiguration) path.getFirstSegment());
} else {
return false;
}
}
for (ConsoleConfiguration consoleConfig : consoleConfigs) {
boolean isHibernateSearch = false;
URL[] classPathURLs = PreferencesClassPathUtils.getCustomClassPathURLs(consoleConfig.getPreferences());
for (URL url : classPathURLs) {
if (url.getFile().contains("hibernate-search")) {
isHibernateSearch = true;
break;
}
}
if (!isHibernateSearch) {
return false;
}
}
return true;
}
use of org.eclipse.jface.viewers.ITreeSelection in project jbosstools-hibernate by jbosstools.
the class HibernateSearchEnabledPropertyTesterTest method allMustContainHibernateSearchLib.
@Test
public void allMustContainHibernateSearchLib() throws MalformedURLException {
ConsoleConfiguration consoleConfiguration1 = mock(ConsoleConfiguration.class);
ConsoleConfiguration consoleConfiguration2 = mock(ConsoleConfiguration.class);
ConsoleConfigurationPreferences prefs1 = mock(ConsoleConfigurationPreferences.class);
ConsoleConfigurationPreferences prefs2 = mock(ConsoleConfigurationPreferences.class);
when(consoleConfiguration1.getPreferences()).thenReturn(prefs1);
when(consoleConfiguration2.getPreferences()).thenReturn(prefs2);
when(prefs1.getCustomClassPathURLS()).thenReturn(new URL[] { new URL("file", "", "hibernate-search-orm-version") });
when(prefs1.getCustomClassPathURLS()).thenReturn(new URL[] { new URL("file", "", "something"), new URL("file", "", "dont-we-need") });
TreePath treePath = new TreePath(new Object[] { consoleConfiguration1, consoleConfiguration2 });
ITreeSelection receiver = new TreeSelection(treePath);
HibernateSearchEnabledPropertyTester tester = new HibernateSearchEnabledPropertyTester();
assertFalse(tester.test(receiver, "doesn't matter", null, null));
}
use of org.eclipse.jface.viewers.ITreeSelection in project jbosstools-hibernate by jbosstools.
the class OneParentConfigPropertyTesterTest method testDifferentConfigs.
@Test
public void testDifferentConfigs() {
ConsoleConfiguration consoleConfiguration1 = mock(ConsoleConfiguration.class);
ConsoleConfiguration consoleConfiguration2 = mock(ConsoleConfiguration.class);
TreePath treePath1 = new TreePath(new Object[] { consoleConfiguration1 });
TreePath treePath2 = new TreePath(new Object[] { consoleConfiguration2 });
ITreeSelection receiver = new TreeSelection(new TreePath[] { treePath1, treePath2 });
OneParentConfigPropertyTester propertyTester = new OneParentConfigPropertyTester();
assertFalse(propertyTester.test(receiver, "doesn't matter", null, null));
}
use of org.eclipse.jface.viewers.ITreeSelection in project ServiceStack.Java by ServiceStack.
the class SelectionTester method test.
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if ("hasNonEmptyTextSelection".equals(property)) {
if (!(receiver instanceof ITreeSelection)) {
return false;
}
TreeSelection treeSelection = (TreeSelection) receiver;
if (!(treeSelection.getFirstElement() instanceof ICompilationUnit)) {
return false;
}
ICompilationUnit compilationUnit = (ICompilationUnit) treeSelection.getFirstElement();
IResource resource = extractSelection(treeSelection);
IProject project = resource.getProject();
IImportDeclaration importDeclaration = compilationUnit.getImport("net.servicestack.client");
if (importDeclaration == null) {
return false;
}
IFile file = project.getFile(stripFirstDirectoryFromPath(compilationUnit.getPath()));
InputStream contents = null;
try {
contents = file.getContents();
InputStreamReader is = new InputStreamReader(contents);
BufferedReader br = new BufferedReader(is);
String read;
try {
for (int i = 0; i < 10; i++) {
String line = br.readLine();
if (line.trim().startsWith("/* Options:")) {
UpdateReferenceCurrentSelection.getInstance().UpdateReferenceFile = file;
return true;
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (contents == null) {
return false;
}
System.out.println("File selected");
}
return true;
}
use of org.eclipse.jface.viewers.ITreeSelection in project mechanoid by robotoworks.
the class MechanoidWizard method extractSelectionInfo.
private void extractSelectionInfo() {
if (mSelection.isEmpty()) {
return;
}
if (mSelection instanceof ITreeSelection) {
ITreeSelection treeSelection = (ITreeSelection) mSelection;
TreePath[] paths = treeSelection.getPaths();
if (paths.length > 0) {
for (int i = 0; i < paths[0].getSegmentCount(); i++) {
Object segment = paths[0].getSegment(i);
if (segment instanceof IJavaProject) {
mSelectedJavaProject = (IJavaProject) segment;
mSelectedProject = mSelectedJavaProject.getProject();
}
if (segment instanceof IFolder) {
mSelectedFolder = (IFolder) segment;
}
if (segment instanceof IProject) {
mSelectedProject = (IProject) segment;
}
}
}
}
}
Aggregations