Search in sources :

Example 6 with ResourceAttributes

use of org.eclipse.core.resources.ResourceAttributes in project tmdm-studio-se by Talend.

the class Utilities method getReadonlyFiles.

private static List getReadonlyFiles(IResource[] resources) {
    List readOnlyFiles = new ArrayList();
    for (int i = 0; i < resources.length; i++) {
        IResource resource = resources[i];
        ResourceAttributes resourceAttributes = resource.getResourceAttributes();
        if (resource.getType() == IResource.FILE && resourceAttributes != null && resourceAttributes.isReadOnly())
            readOnlyFiles.add(resource);
    }
    return readOnlyFiles;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ListenerList(org.eclipse.core.runtime.ListenerList) ArrayList(java.util.ArrayList) IResource(org.eclipse.core.resources.IResource) ResourceAttributes(org.eclipse.core.resources.ResourceAttributes)

Example 7 with ResourceAttributes

use of org.eclipse.core.resources.ResourceAttributes in project eclipse-cs by checkstyle.

the class CheckstyleNature method ensureProjectFileWritable.

private void ensureProjectFileWritable() throws CoreException {
    IFile projectFile = mProject.getFile(".project");
    if (projectFile.isReadOnly()) {
        ResourceAttributes attrs = ResourceAttributes.fromFile(projectFile.getFullPath().toFile());
        attrs.setReadOnly(true);
        projectFile.setResourceAttributes(attrs);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ResourceAttributes(org.eclipse.core.resources.ResourceAttributes)

Example 8 with ResourceAttributes

use of org.eclipse.core.resources.ResourceAttributes in project whole by wholeplatform.

the class IFilePersistenceProvider method openOutputStream.

public OutputStream openOutputStream() throws Exception {
    return new ByteArrayOutputStream(4096) {

        @Override
        public void close() throws IOException {
            super.close();
            int updateFlags = IResource.FORCE;
            if (getBindings().wIsSet("derived"))
                updateFlags |= IResource.DERIVED;
            try {
                InputStream is = new ByteArrayInputStream(toByteArray());
                if (file.exists())
                    file.setContents(is, updateFlags | IResource.KEEP_HISTORY, ResourceUtils.getProgressMonitor(getBindings()));
                else
                    file.create(is, updateFlags, ResourceUtils.getProgressMonitor(getBindings()));
                if (getBindings().wIsSet("readonly")) {
                    ResourceAttributes attributes = file.getResourceAttributes();
                    if (attributes != null) {
                        attributes.setReadOnly(true);
                        file.setResourceAttributes(attributes);
                    }
                }
            } catch (CoreException e) {
                throw new IOException(e);
            }
        }
    };
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ResourceAttributes(org.eclipse.core.resources.ResourceAttributes)

Example 9 with ResourceAttributes

use of org.eclipse.core.resources.ResourceAttributes in project mdw-designer by CenturyLinkCloud.

the class ArtifactEditor method openTempFile.

public void openTempFile(IProgressMonitor monitor) {
    tempFileEditor = null;
    try {
        IFolder folder = getTempFolder();
        if (!folder.exists())
            PluginUtil.createFoldersAsNeeded(getElement().getProject().getSourceProject(), folder, monitor);
        final IFile file = getTempFile(folder);
        final IWorkbenchPage activePage = MdwPlugin.getActivePage();
        if (file.exists()) {
            IEditorInput editorInput = new FileEditorInput(file);
            tempFileEditor = activePage.findEditor(editorInput);
            if (tempFileEditor == null) {
                // we'll refresh from attribute value
                new TempFileRemover(folder, file).remove(monitor);
            } else {
                // activate existing editor
                tempFileEditor = IDE.openEditor(activePage, file, true);
            }
        }
        if (tempFileEditor == null) {
            // either the file didn't exist or it was not currently open,
            // set from value
            byte[] value = valueProvider.getArtifactContent();
            if (value == null)
                value = "".getBytes();
            InputStream source = new ByteArrayInputStream(value);
            file.create(source, true, monitor);
            if (getElement().isReadOnly()) {
                ResourceAttributes resourceAttrs = file.getResourceAttributes();
                resourceAttrs.setReadOnly(true);
                file.setResourceAttributes(resourceAttrs);
            }
            final Display display = Display.getCurrent();
            if (display != null) {
                display.syncExec(new Runnable() {

                    public void run() {
                        try {
                            if (!valueProvider.beforeTempFileOpened())
                                return;
                            tempFileEditor = IDE.openEditor(activePage, file, true);
                            if (tempFileEditor != null) {
                                // listen for artifact made dirty and
                                // propagate to process canvas
                                tempFileEditor.addPropertyListener(new IPropertyListener() {

                                    public void propertyChanged(Object source, int propId) {
                                        if (source instanceof EditorPart && propId == IWorkbenchPartConstants.PROP_DIRTY) {
                                            if (((EditorPart) source).isDirty())
                                                // process
                                                fireValueChanged(null, true);
                                        // editor
                                        // should
                                        // show
                                        // dirty
                                        }
                                    }
                                });
                                // listen for artifact resource changes
                                ArtifactResourceListener resourceListener = new ArtifactResourceListener(getElement(), valueProvider, file);
                                getProject().addArtifactResourceListener(resourceListener);
                                // listen for workbench closed to prevent
                                // re-opening editor when the workbench is
                                // next opened
                                PlatformUI.getWorkbench().addWorkbenchListener(new ArtifactEditorWorkbenchListener(tempFileEditor));
                            }
                            valueProvider.afterTempFileOpened(tempFileEditor);
                        } catch (PartInitException ex) {
                            PluginMessages.log(ex);
                        }
                    }
                });
            }
            // register to listen to process editor events
            WorkflowProcess processVersion = null;
            if (getElement() instanceof Activity)
                processVersion = ((Activity) getElement()).getProcess();
            else if (getElement() instanceof WorkflowProcess)
                processVersion = (WorkflowProcess) getElement();
            if (processVersion != null) {
                IEditorPart processEditor = activePage.findEditor(processVersion);
                if (processEditor != null && tempFileEditor != null)
                    ((ProcessEditor) processEditor).addActiveScriptEditor(tempFileEditor);
            }
        }
    } catch (Exception ex) {
        PluginMessages.uiError(ex, "Open Temp File", getElement().getProject());
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Activity(com.centurylink.mdw.plugin.designer.model.Activity) IEditorPart(org.eclipse.ui.IEditorPart) EditorPart(org.eclipse.ui.part.EditorPart) ArtifactResourceListener(com.centurylink.mdw.plugin.workspace.ArtifactResourceListener) IEditorPart(org.eclipse.ui.IEditorPart) ResourceAttributes(org.eclipse.core.resources.ResourceAttributes) IPropertyListener(org.eclipse.ui.IPropertyListener) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) TempFileRemover(com.centurylink.mdw.plugin.workspace.TempFileRemover) ByteArrayInputStream(java.io.ByteArrayInputStream) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) WorkflowProcess(com.centurylink.mdw.plugin.designer.model.WorkflowProcess) IEditorInput(org.eclipse.ui.IEditorInput) IFolder(org.eclipse.core.resources.IFolder) Display(org.eclipse.swt.widgets.Display)

Example 10 with ResourceAttributes

use of org.eclipse.core.resources.ResourceAttributes in project mdw-designer by CenturyLinkCloud.

the class WorkflowAsset method createTempFile.

public void createTempFile(IFile file, IProgressMonitor monitor) throws CoreException {
    load();
    file.create(new ByteArrayInputStream(getFileContent()), true, monitor);
    if (isReadOnly()) {
        ResourceAttributes resourceAttrs = file.getResourceAttributes();
        resourceAttrs.setReadOnly(true);
        file.setResourceAttributes(resourceAttrs);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ResourceAttributes(org.eclipse.core.resources.ResourceAttributes)

Aggregations

ResourceAttributes (org.eclipse.core.resources.ResourceAttributes)26 IFile (org.eclipse.core.resources.IFile)10 CoreException (org.eclipse.core.runtime.CoreException)9 IResource (org.eclipse.core.resources.IResource)7 ByteArrayInputStream (java.io.ByteArrayInputStream)4 IFolder (org.eclipse.core.resources.IFolder)4 InputStream (java.io.InputStream)3 IProject (org.eclipse.core.resources.IProject)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)2 IPath (org.eclipse.core.runtime.IPath)2 IJavaProject (org.eclipse.jdt.core.IJavaProject)2 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)2 JavaModelException (org.eclipse.jdt.core.JavaModelException)2 Activity (com.centurylink.mdw.plugin.designer.model.Activity)1 WorkflowProcess (com.centurylink.mdw.plugin.designer.model.WorkflowProcess)1 ArtifactResourceListener (com.centurylink.mdw.plugin.workspace.ArtifactResourceListener)1 TempFileRemover (com.centurylink.mdw.plugin.workspace.TempFileRemover)1 BufferedInputStream (java.io.BufferedInputStream)1