use of org.eclipse.core.resources.ResourceAttributes in project mdw-designer by CenturyLinkCloud.
the class WorkflowAsset method ensureFileWritable.
public void ensureFileWritable() throws CoreException {
IFile file = getFile();
if (file.isReadOnly()) {
ResourceAttributes resourceAttrs = file.getResourceAttributes();
resourceAttrs.setReadOnly(false);
file.setResourceAttributes(resourceAttrs);
}
}
use of org.eclipse.core.resources.ResourceAttributes in project whole by wholeplatform.
the class WorkspaceTemplate method buildDirectory.
protected void buildDirectory(IFolder directory) {
getBindings().wEnterScope();
ab.FolderArtifact_();
String directoryName = directory.getName();
ab.Name(directoryName);
getBindings().wDefValue("file", directory.getLocation().toFile());
getBindings().wDefValue("fileName", directoryName);
ResourceAttributes resourceAttributes = directory.getResourceAttributes();
if (resourceAttributes != null && resourceAttributes.isReadOnly())
buildMetadata("readonly");
else
buildMetadata();
if (!testAndClearPurge()) {
IJavaElement javaElement = JavaCore.create(directory);
if (javaElement != null && javaElement.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT) {
IJavaElement[] children = null;
try {
children = ((IPackageFragmentRoot) javaElement).getChildren();
} catch (JavaModelException e) {
}
if (children != null && children.length > 0) {
Arrays.sort(children, new JavaElementComparator());
ab.Artifacts_(children.length);
for (IJavaElement artifact : children) buildPackage((IPackageFragment) artifact);
ab._Artifacts();
} else
ab.Artifacts();
} else {
IResource[] artifacts = null;
try {
artifacts = directory.members();
} catch (CoreException e) {
}
if (artifacts != null && artifacts.length > 0) {
Arrays.sort(artifacts, new ResourceComparator());
ab.Artifacts_(artifacts.length);
for (IResource artifact : artifacts) buildArtifact(artifact);
ab._Artifacts();
} else
ab.Artifacts();
}
} else
ab.Artifacts();
ab._FolderArtifact();
getBindings().wExitScope();
}
use of org.eclipse.core.resources.ResourceAttributes in project whole by wholeplatform.
the class WorkspaceArtifactsGeneratorVisitor method visitFolderArtifact.
public void visitFolderArtifact(FolderArtifact entity) {
env().wEnterScope();
if (!Matcher.matchImplAndBind(ArtifactsEntityDescriptorEnum.Name, entity.getName(), env(), "folderName"))
throw new VisitException("No Folder name");
entity.getMetadata().accept(this);
try {
IPath path;
if (env().wIsSet("folder")) {
IFolder parentFolder = (IFolder) env().wGetValue("folder");
path = parentFolder.getFullPath();
} else {
IProject project = (IProject) env().wGetValue("project");
path = project.getFullPath();
}
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
IFolder folder = null;
String[] folderPath = env().wStringValue("folderName").split("/");
for (int i = 0; i < folderPath.length; i++) {
path = path.append(folderPath[i]);
folder = workspaceRoot.getFolder(path);
if (!folder.exists())
folder.create(true, true, progressMonitor());
}
env().wDefValue("folder", folder);
if (env().wIsSet("derived"))
folder.setDerived(true, progressMonitor());
if (env().wIsSet("readonly")) {
ResourceAttributes attributes = folder.getResourceAttributes();
if (attributes != null) {
attributes.setReadOnly(true);
folder.setResourceAttributes(attributes);
}
}
if (env().wLocalNames().contains("source") && env().wIsSet("javaProject")) {
List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>();
IJavaProject javaProject = (IJavaProject) env().wGetValue("javaProject");
classpathEntries.addAll(Arrays.asList(javaProject.getRawClasspath()));
IClasspathEntry sourceEntry = JavaCore.newSourceEntry(folder.getFullPath());
if (classpathEntries.size() == 1 && ((IClasspathEntry) classpathEntries.get(0)).getPath().equals(javaProject.getPath()))
classpathEntries.remove(0);
else
for (Iterator<IClasspathEntry> i = classpathEntries.iterator(); i.hasNext(); ) {
IClasspathEntry entry = i.next();
if (entry.getPath().equals(sourceEntry.getPath()))
i.remove();
}
classpathEntries.add(0, sourceEntry);
javaProject.setRawClasspath((IClasspathEntry[]) classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]), progressMonitor());
}
} catch (CoreException e) {
throw new VisitException(e);
// } catch (NullPointerException e) {
// throw new VisitException("No Project");
}
entity.getArtifacts().accept(this);
env().wExitScope();
}
use of org.eclipse.core.resources.ResourceAttributes in project whole by wholeplatform.
the class WorkspaceArtifactsGeneratorVisitor method visitPackageArtifact.
public void visitPackageArtifact(PackageArtifact entity) {
env().wEnterScope();
if (!Matcher.matchImplAndBind(ArtifactsEntityDescriptorEnum.Name, entity.getName(), env(), "packageName"))
throw new VisitException("No Package name");
entity.getMetadata().accept(this);
try {
IPath path;
if (env().wIsSet("folder")) {
IFolder parentFolder = (IFolder) env().wGetValue("folder");
path = parentFolder.getFullPath();
} else {
IProject project = (IProject) env().wGetValue("project");
path = project.getFullPath();
}
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
IFolder folder = null;
String[] packagePath = env().wStringValue("packageName").split("\\.");
for (int i = 0; i < packagePath.length; i++) {
path = path.append(packagePath[i]);
folder = workspaceRoot.getFolder(path);
if (!folder.exists())
folder.create(true, true, progressMonitor());
}
env().wDefValue("folder", folder);
if (env().wIsSet("derived"))
folder.setDerived(true, progressMonitor());
if (env().wIsSet("readonly")) {
ResourceAttributes attributes = folder.getResourceAttributes();
if (attributes != null) {
attributes.setReadOnly(true);
folder.setResourceAttributes(attributes);
}
}
} catch (CoreException e) {
throw new VisitException(e);
// } catch (NullPointerException e) {
// throw new VisitException("No Project");
}
entity.getArtifacts().accept(this);
env().wExitScope();
}
use of org.eclipse.core.resources.ResourceAttributes in project flux by eclipse.
the class Resources method setReadOnly.
static void setReadOnly(IResource resource, boolean readOnly) {
ResourceAttributes resourceAttributes = resource.getResourceAttributes();
if (// not supported on this platform for this resource
resourceAttributes == null)
return;
resourceAttributes.setReadOnly(readOnly);
try {
resource.setResourceAttributes(resourceAttributes);
} catch (CoreException e) {
//JavaPlugin.log(e);
}
}
Aggregations