Search in sources :

Example 6 with IParent

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

the class ErlangExternalsContentProvider method hasChildren.

@Override
public boolean hasChildren(final Object element0) {
    Object element = element0;
    if (element instanceof IProject) {
        final IProject project = (IProject) element;
        if (project.isOpen()) {
            element = ErlangEngine.getInstance().getModel().findProject(project);
        }
    }
    if (element instanceof IErlModule) {
        return erlangFileContentProvider.hasChildren(element);
    }
    if (element instanceof IParent) {
        if (element instanceof IErlExternalRoot || element instanceof IErlProject || element instanceof IErlModel) {
            // we know these have children
            return true;
        }
        final Stopwatch clock = Stopwatch.createStarted();
        if (element instanceof IOpenable) {
            final IOpenable openable = (IOpenable) element;
            try {
                openable.open(null);
            } catch (final ErlModelException e) {
            }
        }
        final IParent parent = (IParent) element;
        final boolean result = parent.hasChildrenOfKind(ErlElementKind.EXTERNAL_ROOT, ErlElementKind.EXTERNAL_APP, ErlElementKind.EXTERNAL_FOLDER, ErlElementKind.MODULE);
        if (clock.elapsed(TimeUnit.MILLISECONDS) > 100) {
            ErlLogger.debug("TIME open " + element.getClass() + " " + element + "  " + clock.elapsed(TimeUnit.MILLISECONDS) + " ms");
        }
        return result;
    }
    return false;
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IOpenable(org.erlide.engine.model.root.IOpenable) IErlModel(org.erlide.engine.model.root.IErlModel) IParent(org.erlide.engine.model.IParent) ErlModelException(org.erlide.engine.model.ErlModelException) IErlExternalRoot(org.erlide.engine.model.root.IErlExternalRoot) IErlModule(org.erlide.engine.model.root.IErlModule) Stopwatch(com.google.common.base.Stopwatch) IProject(org.eclipse.core.resources.IProject)

Example 7 with IParent

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

the class ErlangFileContentProvider method getParent.

/**
 * Load the model from the given file, if possible.
 *
 * @param modelFile
 *            The IFile which contains the persisted model
 */
@Override
public Object getParent(final Object element) {
    if (element instanceof IErlElement) {
        final IErlElement elt = (IErlElement) element;
        final IParent parent = elt.getParent();
        if (parent instanceof IErlModule || parent instanceof IErlProject) {
            final IErlElement e = (IErlElement) parent;
            return e.getCorrespondingResource();
        }
    }
    return null;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlProject(org.erlide.engine.model.root.IErlProject) IParent(org.erlide.engine.model.IParent) IErlModule(org.erlide.engine.model.root.IErlModule)

Example 8 with IParent

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

the class DefaultErlangFoldingStructureProvider method computeAdditions.

private void computeAdditions(final Collection<? extends IErlElement> elements, final Map<ErlangProjectionAnnotation, Position> map) throws ErlModelException {
    if (elements == null) {
        return;
    }
    for (final IErlElement element : elements) {
        computeAdditions(element, map);
        if (element instanceof IParent) {
            final IParent parent = (IParent) element;
            computeAdditions(parent.getChildren(), map);
        }
    }
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IParent(org.erlide.engine.model.IParent)

Example 9 with IParent

use of org.erlide.engine.model.IParent 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 10 with IParent

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

the class ErlangExternalsContentProvider method getChildren.

@Override
public Object[] getChildren(final Object parentElement0) {
    Object parentElement = parentElement0;
    try {
        if (parentElement instanceof IProject) {
            final IProject project = (IProject) parentElement;
            if (project.isOpen()) {
                parentElement = ErlangEngine.getInstance().getModel().findProject(project);
            }
        }
        if (parentElement instanceof IErlModule) {
            return erlangFileContentProvider.getChildren(parentElement);
        }
        if (parentElement instanceof IParent) {
            if (parentElement instanceof IOpenable) {
                final IOpenable openable = (IOpenable) parentElement;
                openable.open(null);
            }
            final IParent parent = (IParent) parentElement;
            final Collection<IErlElement> children = parent.getChildrenOfKind(ErlElementKind.EXTERNAL_ROOT, ErlElementKind.EXTERNAL_APP, ErlElementKind.EXTERNAL_FOLDER);
            return children.toArray();
        }
    } catch (final ErlModelException e) {
    }
    return ErlangExternalsContentProvider.NO_CHILDREN;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IOpenable(org.erlide.engine.model.root.IOpenable) IParent(org.erlide.engine.model.IParent) ErlModelException(org.erlide.engine.model.ErlModelException) IErlModule(org.erlide.engine.model.root.IErlModule) IProject(org.eclipse.core.resources.IProject)

Aggregations

IParent (org.erlide.engine.model.IParent)24 IErlElement (org.erlide.engine.model.IErlElement)18 IErlModule (org.erlide.engine.model.root.IErlModule)10 IOpenable (org.erlide.engine.model.root.IOpenable)8 IResource (org.eclipse.core.resources.IResource)5 ErlModelException (org.erlide.engine.model.ErlModelException)5 IErlProject (org.erlide.engine.model.root.IErlProject)3 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)2 HashSet (java.util.HashSet)2 IFile (org.eclipse.core.resources.IFile)2 IProject (org.eclipse.core.resources.IProject)2 IPath (org.eclipse.core.runtime.IPath)2 IErlExternal (org.erlide.engine.model.root.IErlExternal)2 IErlFolder (org.erlide.engine.model.root.IErlFolder)2 ErlSearchScope (org.erlide.engine.services.search.ErlSearchScope)2 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)1 Stopwatch (com.google.common.base.Stopwatch)1 IFileInfo (org.eclipse.core.filesystem.IFileInfo)1 IFileStore (org.eclipse.core.filesystem.IFileStore)1 IContainer (org.eclipse.core.resources.IContainer)1