Search in sources :

Example 36 with IErlProject

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

the class ErlangNodeLaunchShortcut method launch.

@Override
public void launch(final ISelection selection, final String mode) {
    ErlLogger.debug("** Launch:: " + selection.toString());
    if (selection.isEmpty()) {
        return;
    }
    if (!(selection instanceof IStructuredSelection)) {
        return;
    }
    final Set<IErlProject> projects = Sets.newHashSet();
    final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
    for (final Object element : structuredSelection.toArray()) {
        if (!(element instanceof IResource)) {
            return;
        }
        final IErlElement erlElement = ErlangEngine.getInstance().getModel().findElement((IResource) element);
        final IErlProject project = ErlangEngine.getInstance().getModelUtilService().getProject(erlElement);
        if (project != null) {
            projects.add(project);
        }
    }
    if (projects.isEmpty()) {
        return;
    }
    projects.addAll(getDependentProjects(projects));
    final List<IErlProject> projectList = Lists.newArrayList(projects);
    projectList.sort(new Comparator<IErlProject>() {

        @Override
        public int compare(final IErlProject o1, final IErlProject o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    try {
        doLaunch(mode, projectList);
    } catch (final CoreException e) {
        final IWorkbench workbench = PlatformUI.getWorkbench();
        final Shell shell = workbench.getActiveWorkbenchWindow().getShell();
        MessageDialog.openError(shell, "Error", e.getStatus().getMessage());
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlElement(org.erlide.engine.model.IErlElement) IWorkbench(org.eclipse.ui.IWorkbench) Shell(org.eclipse.swt.widgets.Shell) CoreException(org.eclipse.core.runtime.CoreException) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IResource(org.eclipse.core.resources.IResource)

Example 37 with IErlProject

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

the class ErlangNodeLaunchShortcut method getProjectAndModuleNames.

private List<String> getProjectAndModuleNames(final Collection<IErlProject> projects) throws ErlModelException {
    final List<String> moduleNames = Lists.newArrayList();
    for (final IErlProject project : projects) {
        final Collection<IErlModule> modules = project.getModules();
        final String projectNameColon = project.getName() + ":";
        for (final IErlModule module : modules) {
            moduleNames.add(projectNameColon + module.getName());
        }
    }
    return moduleNames;
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule)

Example 38 with IErlProject

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

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

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

the class CompilerPreferencePage method doLinkActivated.

void doLinkActivated(final Link widget) {
    if (isProjectPreferencePage()) {
        openWorkspacePreferences(null);
    } else {
        final List<IProject> erlProjects = new ArrayList<>();
        final Set<IProject> projectsWithSpecifics = new HashSet<>();
        final IErlModel model = ErlangEngine.getInstance().getModel();
        try {
            for (final IErlProject ep : model.getErlangProjects()) {
                final IProject p = ep.getWorkspaceProject();
                if (hasProjectSpecificOptions(p)) {
                    projectsWithSpecifics.add(p);
                }
                erlProjects.add(p);
            }
        } catch (final ErlModelException e) {
        }
        final ProjectSelectionDialog dialog = new ProjectSelectionDialog(getShell(), erlProjects, projectsWithSpecifics);
        if (dialog.open() == Window.OK) {
            final IProject res = (IProject) dialog.getFirstResult();
            openProjectProperties(res);
        }
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlModel(org.erlide.engine.model.root.IErlModel) ErlModelException(org.erlide.engine.model.ErlModelException) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) HashSet(java.util.HashSet)

Aggregations

IErlProject (org.erlide.engine.model.root.IErlProject)123 IErlModule (org.erlide.engine.model.root.IErlModule)57 Test (org.junit.Test)47 IPath (org.eclipse.core.runtime.IPath)30 IProject (org.eclipse.core.resources.IProject)29 ErlProject (org.erlide.engine.internal.model.root.ErlProject)25 File (java.io.File)19 Path (org.eclipse.core.runtime.Path)16 CoreException (org.eclipse.core.runtime.CoreException)13 ErlModelException (org.erlide.engine.model.ErlModelException)13 IErlElementLocator (org.erlide.engine.model.root.IErlElementLocator)13 IErlModel (org.erlide.engine.model.root.IErlModel)13 ArrayList (java.util.ArrayList)11 IErlElement (org.erlide.engine.model.IErlElement)10 IFile (org.eclipse.core.resources.IFile)9 IResource (org.eclipse.core.resources.IResource)9 HashSet (java.util.HashSet)7 IProjectDescription (org.eclipse.core.resources.IProjectDescription)7 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)6 IErlPreprocessorDef (org.erlide.engine.model.erlang.IErlPreprocessorDef)6