use of org.jboss.tools.hibernate.runtime.spi.IProperty in project jbosstools-hibernate by jbosstools.
the class ServiceImplTest method testNewSpecialRootClass.
@Test
public void testNewSpecialRootClass() {
IProperty property = service.newProperty();
IPersistentClass pc = service.newRootClass();
property.setPersistentClass(pc);
IPersistentClass specialRootClass = service.newSpecialRootClass(property);
Assert.assertNotNull(specialRootClass);
Object target = ((IFacade) specialRootClass).getTarget();
Assert.assertNotNull(target);
Assert.assertTrue(target instanceof RootClass);
Assert.assertSame(property, specialRootClass.getProperty());
}
use of org.jboss.tools.hibernate.runtime.spi.IProperty in project jbosstools-hibernate by jbosstools.
the class PropertyEditPart method createFigure.
protected IFigure createFigure() {
IProperty property = ((PropertyViewAdapter) getModel()).getProperty();
String label = property.getName();
Label propertyLabel = new EditableLabel(label);
propertyLabel.setIcon(((PropertyViewAdapter) getModel()).getImage());
return propertyLabel;
}
use of org.jboss.tools.hibernate.runtime.spi.IProperty in project jbosstools-hibernate by jbosstools.
the class OpenMappingAction method run.
/**
* @param path
* @param consoleConfig
* @return
* @throws PartInitException
* @throws JavaModelException
* @throws FileNotFoundException
*/
public static IEditorPart run(ConsoleConfiguration consoleConfig, TreePath path) throws PartInitException, JavaModelException, FileNotFoundException {
boolean isPropertySel = (path.getLastSegment() instanceof IProperty && ((IProperty) path.getLastSegment()).classIsPropertyClass());
if (isPropertySel) {
IProperty propertySel = (IProperty) path.getLastSegment();
IPersistentClass persClass = propertySel.getPersistentClass();
if (persClass == null || (persClass.isAssignableToRootClass() && !persClass.isRootClass())) {
IProperty parentProp = (IProperty) path.getParentPath().getLastSegment();
return run(consoleConfig, propertySel, parentProp);
}
}
return run(consoleConfig, path.getLastSegment(), null);
}
use of org.jboss.tools.hibernate.runtime.spi.IProperty in project jbosstools-hibernate by jbosstools.
the class OpenSourceAction method run.
/**
* @param consoleConfig
* @param selection
* @param fullyQualifiedName
* @throws JavaModelException
* @throws PartInitException
* @throws FileNotFoundException
*/
public static IEditorPart run(ConsoleConfiguration consoleConfig, Object selection, String fullyQualifiedName) throws JavaModelException, PartInitException, FileNotFoundException {
if (fullyQualifiedName == null) {
return null;
}
IJavaProject[] projs = ProjectUtils.findJavaProjects(consoleConfig);
String remainder = null;
IType type = null;
IJavaProject proj = null;
if (fullyQualifiedName.indexOf("$") > 0) {
// $NON-NLS-1$
// $NON-NLS-1$
remainder = fullyQualifiedName.substring(fullyQualifiedName.indexOf("$") + 1);
// $NON-NLS-1$
fullyQualifiedName = fullyQualifiedName.substring(0, fullyQualifiedName.indexOf("$"));
for (int i = 0; i < projs.length && type == null; i++) {
proj = projs[i];
type = ProjectUtils.findType(proj, fullyQualifiedName);
}
while (remainder.indexOf("$") > 0) {
// $NON-NLS-1$
// $NON-NLS-1$
String subtype = remainder.substring(0, fullyQualifiedName.indexOf("$"));
type = type.getType(subtype);
// $NON-NLS-1$
remainder = remainder.substring(fullyQualifiedName.indexOf("$") + 1);
}
type = type.getType(remainder);
} else {
for (int i = 0; i < projs.length && type == null; i++) {
proj = projs[i];
type = ProjectUtils.findType(proj, fullyQualifiedName);
}
}
IJavaElement jElement = null;
if (selection instanceof IProperty) {
final String selectionName = ((IProperty) selection).getName();
final IType typeSave = type;
while (true) {
jElement = type.getField(selectionName);
if (jElement != null && jElement.exists()) {
break;
}
String parentClassName = ProjectUtils.getParentTypename(proj, type.getFullyQualifiedName());
if (parentClassName == null) {
break;
}
type = ProjectUtils.findType(proj, parentClassName);
for (int i = 0; i < projs.length && type == null; i++) {
proj = projs[i];
type = ProjectUtils.findType(proj, fullyQualifiedName);
}
if (type == null) {
break;
}
}
;
// do not find element - restore type
if (jElement == null || !jElement.exists()) {
type = typeSave;
}
}
if (jElement == null) {
jElement = type;
}
IEditorPart editorPart = JavaUI.openInEditor(type);
if (editorPart instanceof JavaEditor) {
JavaEditor jEditor = (JavaEditor) editorPart;
selectionToEditor(jElement, jEditor);
}
if (editorPart == null) {
String out = NLS.bind(HibernateConsoleMessages.OpenSourceAction_source_file_for_class_not_found, fullyQualifiedName);
throw new FileNotFoundException(out);
}
return editorPart;
}
use of org.jboss.tools.hibernate.runtime.spi.IProperty 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);
}
}
}
Aggregations