use of org.jboss.tools.hibernate.runtime.spi.IProperty in project jbosstools-hibernate by jbosstools.
the class HQLScratchpadAction method generateQuery.
/* (non-Javadoc)
* @see org.hibernate.eclipse.console.actions.OpenQueryEditorAction#generateQuery(org.eclipse.jface.viewers.TreePath)
*/
protected String generateQuery(TreePath path) {
Object node = path.getLastSegment();
if (node instanceof IPersistentClass) {
String name = ((IPersistentClass) node).getEntityName();
// $NON-NLS-1$
return "from " + name;
} else if (node instanceof IProperty) {
String prName = ((IProperty) node).getName();
IPersistentClass pClass = ((IProperty) node).getPersistentClass();
// $NON-NLS-1$
String enName = "";
if (pClass != null) {
enName = pClass.getEntityName();
enName = enName.substring(enName.lastIndexOf('.') + 1);
} else {
// Generate script for Component property
for (int i = path.getSegmentCount() - 2; i > 0; i--) {
if (path.getSegment(i) instanceof IPersistentClass) {
enName = ((IPersistentClass) path.getSegment(i)).getEntityName();
enName = enName.substring(enName.lastIndexOf('.') + 1);
} else if (path.getSegment(i) instanceof IProperty) {
// $NON-NLS-1$
prName = ((IProperty) path.getSegment(i)).getName() + "." + prName;
}
}
}
// $NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
return "select o." + prName + " from " + enName + " o";
} else if (node instanceof BaseNode) {
BaseNode baseNode = (BaseNode) node;
ConsoleConfiguration consoleConfiguration = baseNode.getConsoleConfiguration();
if (consoleConfiguration.isSessionFactoryCreated()) {
return baseNode.getHQL();
}
}
// $NON-NLS-1$
return "";
}
use of org.jboss.tools.hibernate.runtime.spi.IProperty in project jbosstools-hibernate by jbosstools.
the class OpenMappingAction method run.
/**
* @param consoleConfig
* @param selection
* @param selectionParent
* @throws JavaModelException
* @throws PartInitException
* @throws PresistanceClassNotFoundException
* @throws FileNotFoundException
*/
public static IEditorPart run(ConsoleConfiguration consoleConfig, Object selection, Object selectionParent) throws PartInitException, JavaModelException, FileNotFoundException {
IEditorPart editorPart = null;
IFile file = null;
if (selection instanceof IProperty) {
IProperty p = (IProperty) selection;
if (p.getPersistentClass() != null) {
// use PersistentClass to open editor
file = OpenMappingUtils.searchFileToOpen(consoleConfig, p.getPersistentClass());
}
} else {
if (selectionParent != null) {
file = OpenMappingUtils.searchFileToOpen(consoleConfig, selectionParent);
} else {
file = OpenMappingUtils.searchFileToOpen(consoleConfig, selection);
}
}
if (file != null) {
editorPart = OpenMappingUtils.openFileInEditor(file);
IService service = consoleConfig.getHibernateExtension().getHibernateService();
boolean updateRes = updateEditorSelection(editorPart, selection, service);
if (!updateRes && selectionParent != null) {
// if it is not possible to select object, try to select it's parent
updateRes = updateEditorSelection(editorPart, selectionParent, service);
}
}
if (editorPart == null) {
// try to find hibernate-annotations
IPersistentClass rootClass = null;
if (selection instanceof IPersistentClass) {
rootClass = (IPersistentClass) selection;
} else if (selection instanceof IProperty) {
IProperty p = (IProperty) selection;
if (p.getPersistentClass() != null) {
rootClass = p.getPersistentClass();
}
}
if (rootClass != null) {
if (OpenMappingUtils.hasConfigXMLMappingClassAnnotation(consoleConfig, rootClass)) {
String fullyQualifiedName = rootClass.getClassName();
editorPart = OpenSourceAction.run(consoleConfig, selection, fullyQualifiedName);
}
}
}
if (editorPart == null) {
final String title = HibernateConsoleMessages.OpenMappingAction_open_mapping_file;
final String msg = NLS.bind(HibernateConsoleMessages.OpenMappingAction_mapping_for_not_found, selection);
MessageDialog.openError(null, title, msg);
throw new FileNotFoundException(msg);
}
return editorPart;
}
use of org.jboss.tools.hibernate.runtime.spi.IProperty in project jbosstools-hibernate by jbosstools.
the class PersistentClassWorkbenchAdapter method getChildren.
public Object[] getChildren(Object o) {
IPersistentClass pc = (IPersistentClass) o;
IProperty identifierProperty = pc.getIdentifierProperty();
List<IProperty> properties = new ArrayList<IProperty>();
if (identifierProperty != null) {
properties.add(identifierProperty);
}
Iterator<IProperty> propertyClosureIterator = new JoinedIterator<IProperty>(properties.iterator(), pc.getPropertyClosureIterator());
return BasicWorkbenchAdapter.toArray(propertyClosureIterator, IProperty.class, null);
}
use of org.jboss.tools.hibernate.runtime.spi.IProperty in project jbosstools-hibernate by jbosstools.
the class PropertyWorkbenchAdapter method getLabel.
public String getLabel(Object o) {
IProperty property = ((IProperty) o);
IValue value = property.getValue();
String typeName = (String) (new ValueTypeNameHelper(true).getTypeName(value));
if (typeName != null) {
// $NON-NLS-1$
return property.getName() + " : " + typeName;
}
return property.getName();
}
use of org.jboss.tools.hibernate.runtime.spi.IProperty in project jbosstools-hibernate by jbosstools.
the class TypeVisitor method endVisit.
@Override
public void endVisit(TypeDeclaration node) {
if (currentType == node && rootClass.getIdentifierProperty() == null) {
// root class should always has id
IValue sValue = service.newSimpleValue();
// $NON-NLS-1$
sValue.addColumn(service.newColumn("id".toUpperCase()));
sValue.setTypeName(Long.class.getName());
IProperty prop = service.newProperty();
// $NON-NLS-1$
prop.setName("id");
prop.setValue(sValue);
rootClass.setIdentifierProperty(prop);
}
}
Aggregations