Search in sources :

Example 1 with IErlExternal

use of org.erlide.engine.model.root.IErlExternal in project erlide_eclipse by erlang.

the class ModelInternalUtils method isOtpModule.

@Override
public boolean isOtpModule(final IErlModule module) {
    IParent parent = module.getParent();
    while (parent instanceof IErlExternal) {
        final IErlExternal external = (IErlExternal) parent;
        if (external.isOTP()) {
            return true;
        }
        parent = external.getParent();
    }
    return false;
}
Also used : IErlExternal(org.erlide.engine.model.root.IErlExternal) IParent(org.erlide.engine.model.IParent)

Example 2 with IErlExternal

use of org.erlide.engine.model.root.IErlExternal in project erlide_eclipse by erlang.

the class ModelInternalUtils method getExternalModulePath.

@Override
public String getExternalModulePath(final IErlElementLocator model, final IErlModule module) {
    final List<String> result = Lists.newArrayList();
    IErlElement element = module;
    while (element != model) {
        if (element instanceof IErlExternal) {
            final IErlExternal external = (IErlExternal) element;
            result.add(external.getName());
        } else {
            result.add(element.getName());
        }
        element = (IErlElement) element.getParent();
    }
    return Joiner.on(ModelInternalUtils.DELIMITER).join(Lists.reverse(result));
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlExternal(org.erlide.engine.model.root.IErlExternal)

Example 3 with IErlExternal

use of org.erlide.engine.model.root.IErlExternal in project erlide_eclipse by erlang.

the class OpenErlangAction method run.

@Override
public void run() {
    if (isEnabled()) {
        try {
            if (selectedElement != null) {
                if (selectedElement instanceof IErlExternal) {
                    final StructuredViewer structuredViewer = site.getStructuredViewer();
                    if (structuredViewer instanceof AbstractTreeViewer) {
                        final AbstractTreeViewer treeViewer = (AbstractTreeViewer) structuredViewer;
                        final boolean expanded = treeViewer.getExpandedState(selectedElement);
                        treeViewer.setExpandedState(selectedElement, !expanded);
                    }
                } else {
                    final IEditorPart part = EditorUtility.openInEditor(selectedElement, true);
                    EditorUtility.revealInEditor(part, selectedElement);
                }
            } else if (!selectedClosedProjects.isEmpty()) {
                openResourceAction.selectionChanged((IStructuredSelection) provider.getSelection());
                openResourceAction.run();
            }
        } catch (final PartInitException e) {
            ErlLogger.warn(e);
        }
    }
}
Also used : IErlExternal(org.erlide.engine.model.root.IErlExternal) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) IEditorPart(org.eclipse.ui.IEditorPart) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PartInitException(org.eclipse.ui.PartInitException)

Example 4 with IErlExternal

use of org.erlide.engine.model.root.IErlExternal in project erlide_eclipse by erlang.

the class EditorUtility method getEditorInput.

private static IEditorInput getEditorInput(final IErlElement element0) {
    IErlElement element = element0;
    final IResource resource = element.getResource();
    if (resource instanceof IFile) {
        IFile file = (IFile) resource;
        file = EditorUtility.resolveFile(file);
        return new FileEditorInput(file);
    }
    String filePath = element.getFilePath();
    while (filePath == null) {
        final IParent parent = element.getParent();
        if (parent instanceof IErlElement) {
            element = (IErlElement) parent;
            filePath = element.getFilePath();
        } else {
            break;
        }
    }
    if (filePath != null) {
        final IPath path = new Path(filePath);
        IFileStore fileStore = EFS.getLocalFileSystem().getStore(path.removeLastSegments(1));
        fileStore = fileStore.getChild(path.lastSegment());
        final IFileInfo fetchInfo = fileStore.fetchInfo();
        if (!fetchInfo.isDirectory() && fetchInfo.exists()) {
            if (element instanceof IErlModule && element.getParent() instanceof IErlExternal) {
                return new ErlangExternalEditorInput(fileStore, (IErlModule) element);
            }
            return new FileStoreEditorInput(fileStore);
        }
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IParent(org.erlide.engine.model.IParent) IErlElement(org.erlide.engine.model.IErlElement) IFileInfo(org.eclipse.core.filesystem.IFileInfo) IErlExternal(org.erlide.engine.model.root.IErlExternal) IFileEditorInput(org.eclipse.ui.IFileEditorInput) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IErlModule(org.erlide.engine.model.root.IErlModule) IFileStore(org.eclipse.core.filesystem.IFileStore) IResource(org.eclipse.core.resources.IResource) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Example 5 with IErlExternal

use of org.erlide.engine.model.root.IErlExternal in project erlide_eclipse by erlang.

the class ErlExternalReferenceEntryList method addExternalEntries.

private void addExternalEntries(final IProgressMonitor pm, final List<ExternalTreeEntry> externalTree, final IErlModel model, final String rootName, final List<String> otherItems, final boolean includeDir) throws ErlModelException {
    final Map<IPath, IErlExternal> pathToEntryMap = Maps.newHashMap();
    pathToEntryMap.put(new Path("root"), this);
    IErlExternal parent = null;
    if (externalTree != null && !externalTree.isEmpty()) {
        for (final ExternalTreeEntry entry : externalTree) {
            final IPath path = entry.getPath();
            parent = pathToEntryMap.get(entry.getParentPath());
            if (entry.isModule()) {
                final IErlModule module = model.getModuleFromFile(parent, getNameFromPath(path), path, null);
                parent.addChild(module);
            } else {
                final String name = ErlExternalReferenceEntryList.getNameFromExternalPath(path);
                final ErlExternalReferenceEntry externalReferenceEntry = new ErlExternalReferenceEntry(parent, name, path, true, includeDir);
                pathToEntryMap.put(path, externalReferenceEntry);
                externalReferenceEntry.open(pm);
                parent.addChild(externalReferenceEntry);
            }
        }
    }
    if (otherItems != null) {
        if (parent == null) {
            parent = new ErlExternalReferenceEntry(this, rootName, new Path("." + rootName + "."), true, includeDir);
            addChild(parent);
        }
        for (final String path : otherItems) {
            IPath apath = new Path(path);
            final IErlModule module = model.getModuleFromFile(parent, getNameFromPath(apath), apath, null);
            parent.addChild(module);
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IErlExternal(org.erlide.engine.model.root.IErlExternal) IPath(org.eclipse.core.runtime.IPath) IErlModule(org.erlide.engine.model.root.IErlModule) ExternalTreeEntry(org.erlide.engine.services.search.ExternalTreeEntry)

Aggregations

IErlExternal (org.erlide.engine.model.root.IErlExternal)10 IErlElement (org.erlide.engine.model.IErlElement)6 Test (org.junit.Test)4 IErlModule (org.erlide.engine.model.root.IErlModule)3 IPath (org.eclipse.core.runtime.IPath)2 Path (org.eclipse.core.runtime.Path)2 IParent (org.erlide.engine.model.IParent)2 IFileInfo (org.eclipse.core.filesystem.IFileInfo)1 IFileStore (org.eclipse.core.filesystem.IFileStore)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 AbstractTreeViewer (org.eclipse.jface.viewers.AbstractTreeViewer)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredViewer (org.eclipse.jface.viewers.StructuredViewer)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IFileEditorInput (org.eclipse.ui.IFileEditorInput)1 PartInitException (org.eclipse.ui.PartInitException)1 FileStoreEditorInput (org.eclipse.ui.ide.FileStoreEditorInput)1 FileEditorInput (org.eclipse.ui.part.FileEditorInput)1 ErlProject (org.erlide.engine.internal.model.root.ErlProject)1