Search in sources :

Example 36 with IErlElement

use of org.erlide.engine.model.IErlElement 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 IErlElement

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

the class ErlElementSorter method compare.

@Override
public int compare(final Viewer viewer, final Object o1, final Object o2) {
    if (o1 instanceof IErlElement && o2 instanceof IErlElement) {
        final IErlElement e1 = (IErlElement) o1;
        final IErlElement e2 = (IErlElement) o2;
        if (e1.getKind() == ErlElementKind.CLAUSE && e2.getKind() == ErlElementKind.CLAUSE) {
            return comparePositions(viewer, (ISourceReference) o1, (ISourceReference) o2);
        }
    }
    return super.compare(viewer, o1, o2);
}
Also used : IErlElement(org.erlide.engine.model.IErlElement)

Example 38 with IErlElement

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

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

the class OpenErlangAction method isEnabled.

@Override
public boolean isEnabled() {
    selectedElement = null;
    selectedClosedProjects.clear();
    final ISelection selection = provider.getSelection();
    if (!selection.isEmpty()) {
        final IStructuredSelection sSelection = (IStructuredSelection) selection;
        if (sSelection.size() == 1 && sSelection.getFirstElement() instanceof IErlElement) {
            selectedElement = (IErlElement) sSelection.getFirstElement();
            return true;
        }
        for (final Object element : sSelection.toList()) {
            if (element instanceof IProject) {
                final IProject project = (IProject) element;
                if (!project.isOpen()) {
                    selectedClosedProjects.add(project);
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject)

Example 40 with IErlElement

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

the class FindAction method run.

// private IErlElement findType(ICompilationUnit cu, final boolean silent)
// {
// IType[] types = null;
// try {
// types = cu.getAllTypes();
// } catch (JavaModelException ex) {
// if (JavaModelUtil.isExceptionToBeLogged(ex)) {
// ExceptionHandler.log(ex,
// SearchMessages.JavaElementAction_error_open_message);
// }
// if (silent) {
// return RETURN_WITHOUT_BEEP;
// } else {
// return null;
// }
// }
// if (types.length == 1 || silent && types.length > 0) {
// return types[0];
// }
// if (silent) {
// return RETURN_WITHOUT_BEEP;
// }
// if (types.length == 0) {
// return null;
// }
// final String title =
// SearchMessages.JavaElementAction_typeSelectionDialog_title;
// final String message =
// SearchMessages.JavaElementAction_typeSelectionDialog_message;
// final int flags = JavaElementLabelProvider.SHOW_DEFAULT;
// 
// final ElementListSelectionDialog dialog = new ElementListSelectionDialog(
// getShell(), new JavaElementLabelProvider(flags));
// dialog.setTitle(title);
// dialog.setMessage(message);
// dialog.setElements(types);
// 
// if (dialog.open() == Window.OK) {
// return (IType) dialog.getFirstResult();
// } else {
// return RETURN_WITHOUT_BEEP;
// }
// }
/*
     * Method declared on SelectionChangedAction.
     */
@Override
public void run(final IStructuredSelection selection) {
    final IErlElement element = getErlElement(selection, false);
    if (element == null || !element.exists()) {
        showOperationUnavailableDialog();
        return;
    }
    // else if (element == RETURN_WITHOUT_BEEP) {
    // return;
    // }
    run(element);
}
Also used : IErlElement(org.erlide.engine.model.IErlElement)

Aggregations

IErlElement (org.erlide.engine.model.IErlElement)123 Test (org.junit.Test)36 IErlModule (org.erlide.engine.model.root.IErlModule)35 ErlModelException (org.erlide.engine.model.ErlModelException)28 IParent (org.erlide.engine.model.IParent)17 IFile (org.eclipse.core.resources.IFile)16 ArrayList (java.util.ArrayList)12 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)11 IResource (org.eclipse.core.resources.IResource)11 IErlProject (org.erlide.engine.model.root.IErlProject)10 IOpenable (org.erlide.engine.model.root.IOpenable)10 IProject (org.eclipse.core.resources.IProject)9 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)8 IErlModel (org.erlide.engine.model.root.IErlModel)8 WranglerException (org.erlide.wrangler.refactoring.exception.WranglerException)8 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)7 IFolder (org.eclipse.core.resources.IFolder)7 CoreException (org.eclipse.core.runtime.CoreException)7 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)6 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)6