use of org.jboss.tools.hibernate.runtime.spi.IPersistentClass in project jbosstools-hibernate by jbosstools.
the class IndexRebuildHandler method execute.
@SuppressWarnings("unchecked")
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection sel = HandlerUtil.getActiveMenuSelection(event);
if (sel.isEmpty()) {
return null;
}
ITreeSelection selection = (ITreeSelection) sel;
if (selection.getFirstElement() instanceof ConsoleConfiguration) {
indexRebuildForConfiguration(selection.iterator());
}
if (selection.getFirstElement() instanceof IPersistentClass) {
indexRebuildForPersistentClass((ConsoleConfiguration) selection.getPaths()[0].getFirstSegment(), selection.iterator());
}
return null;
}
use of org.jboss.tools.hibernate.runtime.spi.IPersistentClass in project jbosstools-hibernate by jbosstools.
the class IndexRebuildHandler method indexRebuildForPersistentClass.
@SuppressWarnings("rawtypes")
protected void indexRebuildForPersistentClass(ConsoleConfiguration consoleConfig, Iterator<IPersistentClass> persistClasses) {
if (!ConsoleConfigurationUtils.loadSessionFactorySafely(consoleConfig)) {
return;
}
;
ClassLoader classloader = ConsoleConfigurationUtils.getClassLoader(consoleConfig);
final Set<Class> classes = new HashSet<Class>();
try {
while (persistClasses.hasNext()) {
IPersistentClass clazz = persistClasses.next();
classes.add(Class.forName(clazz.getClassName(), true, classloader));
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
run(consoleConfig, classes);
}
use of org.jboss.tools.hibernate.runtime.spi.IPersistentClass in project jbosstools-hibernate by jbosstools.
the class OpenMappingAction method updateEditorSelection.
/**
* @param editorPart
* @param compositeProperty
* @param parentProperty
*/
public static boolean updateEditorSelection(IEditorPart editorPart, IProperty compositeProperty, IProperty parentProperty, IService service) {
ITextEditor[] textEditors = OpenMappingUtils.getTextEditors(editorPart);
if (textEditors.length == 0) {
return false;
}
textEditors[0].selectAndReveal(0, 0);
FindReplaceDocumentAdapter findAdapter = null;
ITextEditor textEditor = null;
for (int i = 0; i < textEditors.length && findAdapter == null; i++) {
textEditor = textEditors[i];
findAdapter = OpenMappingUtils.createFindDocAdapter(textEditor);
}
if (findAdapter == null) {
return false;
}
IJavaProject proj = ProjectUtils.findJavaProject(editorPart);
IRegion parentRegion = OpenMappingUtils.findSelectRegion(proj, findAdapter, parentProperty, service);
if (parentRegion == null) {
return false;
}
int startOffset = parentRegion.getOffset() + parentRegion.getLength();
IRegion propRegion = null;
try {
final String hbmPropertyPattern = OpenMappingUtils.generateHbmPropertyPattern(compositeProperty, service);
propRegion = findAdapter.find(startOffset, hbmPropertyPattern, true, true, false, true);
IPersistentClass rootClass = parentProperty.getPersistentClass();
if (propRegion == null && parentProperty.isComposite() && (parentProperty.equals(rootClass.getIdentifierProperty()) || !rootClass.hasIdentifierProperty())) {
// try to use key-property
// $NON-NLS-1$ //$NON-NLS-2$
String pattern = hbmPropertyPattern.replaceFirst("<property", "<key-property");
propRegion = findAdapter.find(startOffset, pattern, true, true, false, true);
if (propRegion == null) {
// try to use key-many-to-one
// $NON-NLS-1$ //$NON-NLS-2$
pattern = hbmPropertyPattern.replaceFirst("<many-to-one", "<key-many-to-one");
propRegion = findAdapter.find(startOffset, pattern, true, true, false, true);
}
}
} catch (BadLocationException e) {
HibernateConsolePlugin.getDefault().logErrorMessage(HibernateConsoleMessages.OpenMappingAction_selection_not_found, e);
}
if (propRegion == null && parentProperty.isComposite()) {
String[] componentPatterns = new String[] { // $NON-NLS-1$ //$NON-NLS-2$
OpenMappingUtils.createPattern("embeddable", "class", parentProperty.getValue().getComponentClassName()), OpenMappingUtils.createPattern("embeddable", "class", // $NON-NLS-1$//$NON-NLS-2$
OpenMappingUtils.getShortClassName(parentProperty.getValue().getComponentClassName())) };
IRegion componentRegion = null;
for (int i = 0; i < componentPatterns.length && componentRegion == null; i++) {
try {
componentRegion = findAdapter.find(0, componentPatterns[i], true, true, false, true);
} catch (BadLocationException e) {
// ignore
}
}
if (componentRegion != null) {
try {
propRegion = findAdapter.find(parentRegion.getOffset() + parentRegion.getLength(), OpenMappingUtils.generateOrmEmbeddablePropertyPattern(compositeProperty), true, true, false, true);
} catch (BadLocationException e) {
// ignore
}
}
}
if (propRegion == null) {
return false;
}
int length = compositeProperty.getName().length();
int offset = propRegion.getOffset() + propRegion.getLength() - length - 1;
propRegion = new Region(offset, length);
if (editorPart instanceof MultiPageEditorPart) {
((MultiPageEditorPart) editorPart).setActiveEditor(textEditor);
}
textEditor.selectAndReveal(propRegion.getOffset(), propRegion.getLength());
return true;
}
use of org.jboss.tools.hibernate.runtime.spi.IPersistentClass 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.IPersistentClass in project jbosstools-hibernate by jbosstools.
the class OpenMappingAction method run.
/**
* @param consoleConfig
* @param compositeProperty
* @param parentProperty
* @throws JavaModelException
* @throws PartInitException
* @throws FileNotFoundException
* @throws BadLocationException
*/
public static IEditorPart run(ConsoleConfiguration consoleConfig, IProperty compositeProperty, IProperty parentProperty) throws PartInitException, JavaModelException, FileNotFoundException {
IPersistentClass rootClass = parentProperty.getPersistentClass();
IFile file = OpenMappingUtils.searchFileToOpen(consoleConfig, rootClass);
IEditorPart editorPart = null;
if (file != null) {
editorPart = OpenMappingUtils.openFileInEditor(file);
IService service = consoleConfig.getHibernateExtension().getHibernateService();
updateEditorSelection(editorPart, compositeProperty, parentProperty, service);
}
if (editorPart == null && parentProperty.isComposite()) {
if (OpenMappingUtils.hasConfigXMLMappingClassAnnotation(consoleConfig, rootClass)) {
String fullyQualifiedName = parentProperty.getValue().getComponentClassName();
editorPart = OpenSourceAction.run(consoleConfig, compositeProperty, fullyQualifiedName);
}
}
if (editorPart == null) {
final String title = HibernateConsoleMessages.OpenMappingAction_open_mapping_file;
final String msg = NLS.bind(HibernateConsoleMessages.OpenMappingAction_mapping_file_for_property_not_found, compositeProperty.getName());
MessageDialog.openError(null, title, msg);
throw new FileNotFoundException(msg);
}
return editorPart;
}
Aggregations