Search in sources :

Example 1 with IOpenable

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

the class ErlProject method getExternalModules.

@Override
public Collection<IErlModule> getExternalModules() throws ErlModelException {
    final List<IErlModule> result = Lists.newArrayList();
    accept(new IErlElementVisitor() {

        @Override
        public boolean visit(final IErlElement element) throws ErlModelException {
            final boolean isExternalOrProject = element.getKind() == ErlElementKind.EXTERNAL_ROOT || element.getKind() == ErlElementKind.EXTERNAL_APP || element.getKind() == ErlElementKind.EXTERNAL_FOLDER || element.getKind() == ErlElementKind.PROJECT;
            if (element instanceof IErlModule) {
                final IErlModule module = (IErlModule) element;
                if (module.getAncestorOfKind(ErlElementKind.PROJECT) == ErlProject.this) {
                    result.add(module);
                }
                return false;
            } else if (isExternalOrProject && element instanceof IOpenable) {
                final IOpenable openable = (IOpenable) element;
                openable.open(null);
            }
            return isExternalOrProject;
        }
    }, EnumSet.noneOf(AcceptFlags.class), ErlElementKind.MODULE);
    return result;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IOpenable(org.erlide.engine.model.root.IOpenable) ErlModelException(org.erlide.engine.model.ErlModelException) IErlModule(org.erlide.engine.model.root.IErlModule) IErlElementVisitor(org.erlide.engine.model.IErlElementVisitor)

Example 2 with IOpenable

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

the class ErlStructureCreator method recursiveMakeErlNodes.

private ErlNode recursiveMakeErlNodes(final IErlElement element, final ErlNode parent, final IDocument doc) throws ErlModelException {
    final ErlNode n = ErlNode.createErlNode(parent, element, doc);
    if (element instanceof IOpenable) {
        final IOpenable o = (IOpenable) element;
        o.open(null);
    }
    if (element instanceof IParent) {
        final IParent p = (IParent) element;
        final Collection<IErlElement> children = p.getChildren();
        for (final IErlElement child : children) {
            recursiveMakeErlNodes(child, n, doc);
        }
    }
    return n;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IOpenable(org.erlide.engine.model.root.IOpenable) IParent(org.erlide.engine.model.IParent)

Example 3 with IOpenable

use of org.erlide.engine.model.root.IOpenable 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 4 with IOpenable

use of org.erlide.engine.model.root.IOpenable 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)

Example 5 with IOpenable

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

the class ErlangFileContentProvider method getChildren.

/**
 * Return the model elements for a *.erl IFile or NO_CHILDREN for otherwise.
 */
@Override
public Object[] getChildren(final Object parentElement0) {
    Object parentElement = parentElement0;
    try {
        if (parentElement instanceof IFile) {
            parentElement = ErlangEngine.getInstance().getModel().findModule((IFile) parentElement);
        }
        if (parentElement instanceof IOpenable) {
            final IOpenable openable = (IOpenable) parentElement;
            openable.open(null);
        }
        if (parentElement instanceof IParent) {
            final IParent parent = (IParent) parentElement;
            final Collection<IErlElement> children = parent.getChildren();
            return children.toArray();
        }
    } catch (final ErlModelException e) {
        ErlLogger.warn(e);
    }
    return ErlangFileContentProvider.NO_CHILDREN;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IOpenable(org.erlide.engine.model.root.IOpenable) IFile(org.eclipse.core.resources.IFile) IParent(org.erlide.engine.model.IParent) ErlModelException(org.erlide.engine.model.ErlModelException)

Aggregations

IOpenable (org.erlide.engine.model.root.IOpenable)11 IErlElement (org.erlide.engine.model.IErlElement)10 IParent (org.erlide.engine.model.IParent)8 ErlModelException (org.erlide.engine.model.ErlModelException)7 IErlModule (org.erlide.engine.model.root.IErlModule)5 IProject (org.eclipse.core.resources.IProject)2 IErlElementVisitor (org.erlide.engine.model.IErlElementVisitor)2 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)1 Stopwatch (com.google.common.base.Stopwatch)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 IPath (org.eclipse.core.runtime.IPath)1 IErlExternalRoot (org.erlide.engine.model.root.IErlExternalRoot)1 IErlModel (org.erlide.engine.model.root.IErlModel)1 IErlProject (org.erlide.engine.model.root.IErlProject)1