Search in sources :

Example 1 with IStorage

use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.

the class XbaseEditor method getDocumentProvider.

@Override
public IDocumentProvider getDocumentProvider() {
    if (expectJavaSelection > 0 && reentrantCallFromSelf == 0) {
        if (calleeAnalyzer.isLineBasedOpenEditorAction()) {
            expectLineSelection = true;
            if (isCompiledWithJSR45()) {
                return new DocumentProviderStub() {

                    @Override
                    public IDocument getDocument(Object element) {
                        if (typeRoot == null) {
                            return XbaseEditor.super.getDocumentProvider().getDocument(element);
                        }
                        IResource javaResource = typeRoot.getResource();
                        if (!(javaResource instanceof IStorage)) {
                            return XbaseEditor.super.getDocumentProvider().getDocument(element);
                        }
                        try {
                            String string = Files.readStreamIntoString(((IStorage) javaResource).getContents());
                            final Document document = new Document(string);
                            return document;
                        } catch (CoreException e) {
                            return XbaseEditor.super.getDocumentProvider().getDocument(element);
                        }
                    }

                    @Override
                    public void connect(Object element) throws CoreException {
                    // do nothing
                    }

                    @Override
                    public void disconnect(Object element) {
                    // do nothing
                    }
                };
            }
        }
    }
    return super.getDocumentProvider();
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IStorage(org.eclipse.core.resources.IStorage) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IResource(org.eclipse.core.resources.IResource)

Example 2 with IStorage

use of org.eclipse.core.resources.IStorage in project eclipse.platform.text by eclipse.

the class LastSaveReferenceProvider method readDocument.

/**
 * Reads in the saved document into <code>fReference</code>.
 *
 * @param monitor a progress monitor, or <code>null</code>
 * @param force <code>true</code> if the reference document should also
 *        be read if the current document is <code>null</code>,<code>false</code>
 *        if it should only be updated if it already existed.
 */
private void readDocument(IProgressMonitor monitor, boolean force) {
    // protect against concurrent disposal
    IDocumentProvider prov = fDocumentProvider;
    IEditorInput inp = fEditorInput;
    IDocument doc = fReference;
    ITextEditor editor = fEditor;
    if (prov instanceof IStorageDocumentProvider && inp instanceof IStorageEditorInput) {
        IStorageEditorInput input = (IStorageEditorInput) inp;
        IStorageDocumentProvider provider = (IStorageDocumentProvider) prov;
        if (doc == null)
            if (force || fDocumentRead)
                doc = new Document();
            else
                return;
        IJobManager jobMgr = Job.getJobManager();
        try {
            IStorage storage = input.getStorage();
            // check for null for backward compatibility (we used to check before...)
            if (storage == null)
                return;
            fProgressMonitor = monitor;
            ISchedulingRule rule = getSchedulingRule(storage);
            // delay for any other job requiring the lock on file
            try {
                lockDocument(monitor, jobMgr, rule);
                String encoding;
                if (storage instanceof IEncodedStorage)
                    encoding = ((IEncodedStorage) storage).getCharset();
                else
                    encoding = null;
                boolean skipUTF8BOM = isUTF8BOM(encoding, storage);
                setDocumentContent(doc, storage, encoding, monitor, skipUTF8BOM);
            } finally {
                unlockDocument(jobMgr, rule);
                fProgressMonitor = null;
            }
        } catch (CoreException e) {
            return;
        }
        if (monitor != null && monitor.isCanceled())
            return;
        // update state
        synchronized (fLock) {
            if (fDocumentProvider == provider && fEditorInput == input) {
                // only update state if our provider / input pair has not
                // been updated in between (dispose or setActiveEditor)
                fReference = doc;
                fDocumentRead = true;
                addElementStateListener(editor, prov);
            }
        }
    }
}
Also used : IStorageDocumentProvider(org.eclipse.ui.editors.text.IStorageDocumentProvider) IStorageEditorInput(org.eclipse.ui.IStorageEditorInput) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IEncodedStorage(org.eclipse.core.resources.IEncodedStorage) IJobManager(org.eclipse.core.runtime.jobs.IJobManager) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IStorage(org.eclipse.core.resources.IStorage) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) CoreException(org.eclipse.core.runtime.CoreException) IEditorInput(org.eclipse.ui.IEditorInput) IDocument(org.eclipse.jface.text.IDocument)

Example 3 with IStorage

use of org.eclipse.core.resources.IStorage in project eclipse.platform.text by eclipse.

the class StorageDocumentProvider method updateCache.

/**
 * Updates the internal cache for the given input.
 *
 * @param input the input whose cache will be updated
 * @throws CoreException if the storage cannot be retrieved from the input
 * @since 2.0
 */
protected void updateCache(IStorageEditorInput input) throws CoreException {
    StorageInfo info = (StorageInfo) getElementInfo(input);
    if (info != null) {
        try {
            IStorage storage = input.getStorage();
            if (storage != null) {
                boolean readOnly = storage.isReadOnly();
                info.fIsReadOnly = readOnly;
                info.fIsModifiable = !readOnly;
            }
        } catch (CoreException x) {
            handleCoreException(x, TextEditorMessages.StorageDocumentProvider_updateCache);
        }
        info.fUpdateCache = false;
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IStorage(org.eclipse.core.resources.IStorage)

Example 4 with IStorage

use of org.eclipse.core.resources.IStorage in project liferay-ide by liferay.

the class TaglibVariableInsertionDialog method _isFreemarkerEditor.

private static boolean _isFreemarkerEditor(IEditorPart editorPart) {
    try {
        IStorageEditorInput input = (IStorageEditorInput) editorPart.getEditorInput();
        IStorage storage = input.getStorage();
        if (storage.getName().endsWith(".ftl")) {
            return true;
        }
    } catch (Exception e) {
    // ignore just return false
    }
    return false;
}
Also used : IStorageEditorInput(org.eclipse.ui.IStorageEditorInput) IStorage(org.eclipse.core.resources.IStorage)

Example 5 with IStorage

use of org.eclipse.core.resources.IStorage in project liferay-ide by liferay.

the class AddMacroLibrary method run.

public void run(IAction action) {
    ISelectionProvider provider = part.getSite().getSelectionProvider();
    if (null != provider) {
        if (provider.getSelection() instanceof IStructuredSelection) {
            try {
                IStructuredSelection selection = (IStructuredSelection) provider.getSelection();
                Object[] obj = selection.toArray();
                List documents = new ArrayList();
                for (int i = 0; i < obj.length; i++) {
                    if (obj[i] instanceof IFile) {
                        IFile file = (IFile) obj[i];
                        documents.add(file);
                    } else if (obj[i] instanceof JarEntryFile) {
                        JarEntryFile jef = (JarEntryFile) obj[i];
                        documents.add(jef);
                        System.out.println(jef.getFullPath().makeAbsolute());
                        System.out.println(jef.getFullPath().makeRelative());
                        IPath path = jef.getFullPath();
                        System.out.println(path);
                        System.out.println(jef.getName());
                        IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(jef.getFullPath());
                        System.out.println(resource);
                    } else if (obj[i] instanceof IStorage) {
                    }
                }
                IProject project = null;
                if (documents.size() > 0) {
                    // what project?
                    HashSet projects = new HashSet();
                    IProject[] p = ResourcesPlugin.getWorkspace().getRoot().getProjects();
                    for (int i = 0; i < p.length; i++) {
                        projects.add(p[i]);
                    }
                    ProjectSelectionDialog dialog = new ProjectSelectionDialog(Display.getCurrent().getActiveShell(), projects);
                    dialog.setTitle(Messages.AddMacroLibrary_Title);
                    dialog.setMessage(Messages.AddMacroLibrary_Message);
                    int rtn = dialog.open();
                    if (rtn == IDialogConstants.OK_ID) {
                        if (dialog.getFirstResult() instanceof IJavaProject) {
                            project = ((IJavaProject) dialog.getFirstResult()).getProject();
                        } else {
                            MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.AddMacroLibrary_Error, Messages.AddMacroLibrary_ErrorDesc);
                        }
                    }
                }
                if (null != project) {
                    ConfigurationManager.getInstance(project).associateMappingLibraries(documents, Display.getCurrent().getActiveShell());
                }
            } catch (Exception e) {
                Plugin.error(e);
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) ProjectSelectionDialog(org.eclipse.jdt.internal.ui.preferences.ProjectSelectionDialog) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStorage(org.eclipse.core.resources.IStorage) IProject(org.eclipse.core.resources.IProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ArrayList(java.util.ArrayList) List(java.util.List) JarEntryFile(org.eclipse.jdt.internal.core.JarEntryFile) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet)

Aggregations

IStorage (org.eclipse.core.resources.IStorage)96 URI (org.eclipse.emf.common.util.URI)32 IFile (org.eclipse.core.resources.IFile)31 IProject (org.eclipse.core.resources.IProject)27 CoreException (org.eclipse.core.runtime.CoreException)25 IResource (org.eclipse.core.resources.IResource)20 Pair (org.eclipse.xtext.util.Pair)16 Test (org.junit.Test)15 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)13 IStorageEditorInput (org.eclipse.ui.IStorageEditorInput)12 IPath (org.eclipse.core.runtime.IPath)11 IJavaProject (org.eclipse.jdt.core.IJavaProject)10 IOException (java.io.IOException)7 WrappedException (org.eclipse.emf.common.util.WrappedException)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputStream (java.io.InputStream)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 GitSynchronizeData (org.eclipse.egit.core.synchronize.dto.GitSynchronizeData)6 GitSynchronizeDataSet (org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet)6 Storage2UriMapperJavaImpl (org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl)6