use of org.eclipse.jdt.core.IPackageFragmentRoot in project tdi-studio-se by Talend.
the class EditPropertiesAction method processRename.
protected void processRename(IRepositoryNode node, String originalName) {
try {
IRunProcessService runProcessService = CorePlugin.getDefault().getRunProcessService();
ITalendProcessJavaProject talendProcessJavaProject = runProcessService.getTalendProcessJavaProject();
if (talendProcessJavaProject == null) {
return;
}
IFolder srcFolder = talendProcessJavaProject.getSrcFolder();
IPackageFragmentRoot root = talendProcessJavaProject.getJavaProject().getPackageFragmentRoot(srcFolder);
// add for bug TDI-24379 on August 23, 2013.
IFolder srcInterFolder = srcFolder.getFolder(JavaUtils.JAVA_INTERNAL_DIRECTORY);
if (srcInterFolder.exists()) {
File file = new File(srcInterFolder.getLocationURI());
for (File f : file.listFiles()) {
if (f.isFile()) {
f.delete();
}
}
}
// qli modified to fix the bug 5400 and 6185.
// update for fix [TESB-6784]
IPackageFragment routinesPkg = getPackageFragment(root, node);
// ICompilationUnit unit = routinesPkg.getCompilationUnit(originalName +
// SuffixConstants.SUFFIX_STRING_java);
//$NON-NLS-1$
ICompilationUnit unit = routinesPkg.getCompilationUnit(originalName + ".java");
if (unit == null) {
return;
}
String newName = node.getObject().getProperty().getLabel();
JavaRenameProcessor processor = new RenameCompilationUnitProcessor(unit);
// processor.setNewElementName(newName + SuffixConstants.SUFFIX_STRING_java);
//$NON-NLS-1$
processor.setNewElementName(newName + ".java");
RenameRefactoring ref = new RenameRefactoring(processor);
final PerformRefactoringOperation operation = new PerformRefactoringOperation(ref, CheckConditionsOperation.ALL_CONDITIONS);
IRunnableWithProgress r = new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
try {
operation.run(monitor);
} catch (CoreException e) {
ExceptionHandler.process(e);
}
}
});
}
};
PlatformUI.getWorkbench().getProgressService().run(true, true, r);
RefactoringStatus conditionStatus = operation.getConditionStatus();
if (conditionStatus.hasError()) {
//$NON-NLS-1$
String errorMessage = Messages.getString("EditPropertiesAction.renameError", unit.getElementName(), newName);
RefactoringStatusEntry[] entries = conditionStatus.getEntries();
for (RefactoringStatusEntry entry : entries) {
//$NON-NLS-1$
errorMessage += "\n>>>" + entry.getMessage();
}
Shell shell = null;
IRepositoryView viewPart = getViewPart();
if (viewPart != null) {
shell = viewPart.getViewSite().getShell();
} else {
shell = Display.getCurrent().getActiveShell();
}
//$NON-NLS-1$
MessageDialog.openError(shell, Messages.getString("EditPropertiesAction.warning"), errorMessage);
return;
}
// ICompilationUnit newUnit = routinesPkg.getCompilationUnit(newName + SuffixConstants.SUFFIX_STRING_java);
//$NON-NLS-1$
ICompilationUnit newUnit = routinesPkg.getCompilationUnit(newName + ".java");
if (newUnit == null) {
return;
}
RoutineItem item = (RoutineItem) node.getObject().getProperty().getItem();
IFile javaFile = (IFile) newUnit.getAdapter(IResource.class);
try {
ByteArray byteArray = item.getContent();
byteArray.setInnerContentFromFile(javaFile);
IRepositoryService service = CorePlugin.getDefault().getRepositoryService();
IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
repFactory.save(item);
} catch (Exception e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
} catch (Exception e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
}
use of org.eclipse.jdt.core.IPackageFragmentRoot in project AutoRefactor by JnRouvignac.
the class JavaCoreHelper method addSourceContainer.
private static IPackageFragmentRoot addSourceContainer(IJavaProject javaProject, String containerName) throws Exception {
final IProject project = javaProject.getProject();
final IFolder folder = project.getFolder(containerName);
createFolder(folder);
IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(folder);
IClasspathEntry cpe = JavaCore.newSourceEntry(root.getPath(), EMPTY_PATHS, EMPTY_PATHS, null);
addToClasspath(javaProject, Arrays.asList(cpe));
return root;
}
use of org.eclipse.jdt.core.IPackageFragmentRoot in project AutoRefactor by JnRouvignac.
the class PrepareApplyRefactoringsJob method addAll.
private void addAll(Queue<RefactoringUnit> results, List<IJavaElement> javaElements) throws JavaModelException {
for (IJavaElement javaElement : javaElements) {
final JavaProjectOptions options = getJavaProjectOptions(javaElement);
if (javaElement instanceof ICompilationUnit) {
add(results, (ICompilationUnit) javaElement, options);
} else if (javaElement instanceof IPackageFragment) {
final IPackageFragment pf = (IPackageFragment) javaElement;
addAll(results, pf.getCompilationUnits(), options);
} else if (javaElement instanceof IPackageFragmentRoot) {
final IPackageFragmentRoot pfr = (IPackageFragmentRoot) javaElement;
addAll(results, Arrays.asList(pfr.getChildren()));
} else if (javaElement instanceof IJavaProject) {
IJavaProject javaProject = (IJavaProject) javaElement;
for (IPackageFragment pf : javaProject.getPackageFragments()) {
addAll(results, pf.getCompilationUnits(), options);
}
}
}
}
use of org.eclipse.jdt.core.IPackageFragmentRoot in project sling by apache.
the class JcrContentContentProvider method getPipelinedChildren.
@Override
public void getPipelinedChildren(Object aParent, Set theCurrentChildren) {
if (aParent instanceof IProject) {
IProject project = (IProject) aParent;
if (ProjectHelper.isContentProject(project)) {
for (Iterator<?> it = theCurrentChildren.iterator(); it.hasNext(); ) {
Object aChild = (Object) it.next();
if (aChild instanceof IPackageFragmentRoot) {
IPackageFragmentRoot ipfr = (IPackageFragmentRoot) aChild;
IResource res = ipfr.getResource();
IFolder syncDir = getSyncDir(project);
if (res != null && syncDir != null && res.equals(syncDir)) {
// then remove this one folder provided via j2ee content provider
// reason: we are showing it too via the sling content provider
it.remove();
// and we can break here since there's only one syncdir currently
break;
}
}
}
}
Object[] children = projectGetChildren(project);
if (children != null && children.length > 0) {
theCurrentChildren.addAll(Arrays.asList(children));
}
return;
} else if (aParent instanceof SyncDir) {
theCurrentChildren.clear();
Object[] children = getChildren(aParent);
if (children != null) {
theCurrentChildren.addAll(Arrays.asList(children));
}
}
}
use of org.eclipse.jdt.core.IPackageFragmentRoot in project bndtools by bndtools.
the class PackageDecorator method updateDecoration.
public static void updateDecoration(IProject project, Project model) throws Exception {
if (!project.isOpen()) {
return;
}
IJavaProject javaProject = JavaCore.create(project);
if (javaProject == null) {
// project is not a java project
return;
}
boolean changed = false;
for (IClasspathEntry cpe : javaProject.getRawClasspath()) {
if (cpe.getEntryKind() != IClasspathEntry.CPE_SOURCE) {
continue;
}
for (IPackageFragmentRoot pkgRoot : javaProject.findPackageFragmentRoots(cpe)) {
assert pkgRoot.getKind() == IPackageFragmentRoot.K_SOURCE;
IResource pkgRootResource = pkgRoot.getCorrespondingResource();
if (pkgRootResource == null) {
continue;
}
File pkgRootFile = pkgRootResource.getLocation().toFile();
boolean pkgInSourcePath = model.getSourcePath().contains(pkgRootFile);
for (IJavaElement child : pkgRoot.getChildren()) {
IPackageFragment pkg = (IPackageFragment) child;
assert pkg.getKind() == IPackageFragmentRoot.K_SOURCE;
IResource pkgResource = pkg.getCorrespondingResource();
if (pkgResource == null) {
continue;
}
String text = pkgResource.getPersistentProperty(packageDecoratorKey);
if (pkgInSourcePath) {
String pkgName = pkg.getElementName();
// Decorate if exported package
Attrs pkgAttrs = model.getExports().getByFQN(pkgName);
if (pkgAttrs != null) {
StringBuilder sb = new StringBuilder(" ").append(Version.parseVersion(pkgAttrs.getVersion()));
pkgAttrs = model.getImports().getByFQN(pkgName);
if (pkgAttrs != null) {
String versionRange = pkgAttrs.getVersion();
if (versionRange != null) {
sb.append('↔').append(versionRange);
}
}
String version = sb.toString();
if (!version.equals(text)) {
pkgResource.setPersistentProperty(packageDecoratorKey, version);
changed = true;
}
continue;
}
// Decorate if non-empty, non-contained package
if (pkg.containsJavaResources() && !model.getContained().containsFQN(pkgName)) {
if (!excluded.equals(text)) {
pkgResource.setPersistentProperty(packageDecoratorKey, excluded);
changed = true;
}
continue;
}
}
// Clear decoration
if (text != null) {
pkgResource.setPersistentProperty(packageDecoratorKey, null);
changed = true;
}
}
}
}
// If decoration change, update display
if (changed) {
Display display = PlatformUI.getWorkbench().getDisplay();
SWTConcurrencyUtil.execForDisplay(display, true, new Runnable() {
@Override
public void run() {
PlatformUI.getWorkbench().getDecoratorManager().update(packageDecoratorId);
}
});
}
}
Aggregations