use of org.erlide.engine.model.root.IErlModule 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;
}
use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.
the class ErlangFileContentProvider method elementChanged.
@Override
public void elementChanged(final IErlElement element) {
if (element instanceof IErlModule) {
final IErlModule m = (IErlModule) element;
final IResource r = m.getResource();
if (r instanceof IFile) {
doRefresh((IFile) r);
}
}
}
use of org.erlide.engine.model.root.IErlModule 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;
}
use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.
the class FindAction method run.
/*
* Method declared on SelectionChangedAction.
*/
@Override
public void run(final ITextSelection selection) {
try {
final IErlModule module = fEditor.getModule();
if (module == null) {
return;
}
final ISelection sel = getSelection();
final ITextSelection textSel = (ITextSelection) sel;
final int offset = textSel.getOffset();
final OpenResult res = ErlangEngine.getInstance().getOpenService().open(module.getScannerName(), offset, ErlangEngine.getInstance().getModelUtilService().getImportsAsList(module), "", ErlangEngine.getInstance().getModel().getPathVars());
ErlLogger.debug("find " + res);
final ErlangSearchPattern ref = SearchUtil.getSearchPatternFromOpenResultAndLimitTo(module, offset, res, getLimitTo(), true);
if (ref != null) {
SearchUtil.runQuery(ref, getScope(), getScopeDescription(), getShell());
}
} catch (final Exception e) {
handleException(e);
}
}
use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.
the class ErlangAbstractHandler method getTextSelection.
/**
* Provide the text selection that is needed to execute the command. Default
* implementation, extend to Erlang elements selected.
*
* @param document
* text {@link IDocument}
* @param selection
* selection affected by command (extended by extendSelection)
* @return new {@link ITextSelection} with all text up to selection
*/
protected ITextSelection getTextSelection(final IDocument document, final ITextSelection selection, final ITextEditor editor) {
if (editor instanceof ErlangEditor) {
final AbstractErlangEditor erlangEditor = (AbstractErlangEditor) editor;
final IErlModule module = erlangEditor.getModule();
if (module != null) {
final int offset1 = selection.getOffset();
final int offset2 = offset1 + selection.getLength();
try {
final IErlElement e1 = module.getElementAt(offset1);
final IErlElement e2 = module.getElementAt(offset2);
if (e1 instanceof ISourceReference) {
final ISourceReference ref1 = (ISourceReference) e1;
final ISourceRange r1 = ref1.getSourceRange();
final int offset = r1.getOffset();
int length = r1.getLength();
if (e1 == e2) {
final int docLength = document.getLength();
if (offset + length > docLength) {
length = docLength - offset;
}
return ErlangAbstractHandler.extendSelectionToWholeLines(document, new TextSelection(document, offset, length));
} else if (e2 == null) {
return ErlangAbstractHandler.extendSelectionToWholeLines(document, new TextSelection(document, offset, selection.getLength() + selection.getOffset() - offset));
} else if (e2 instanceof ISourceReference) {
final ISourceReference ref2 = (ISourceReference) e2;
final ISourceRange r2 = ref2.getSourceRange();
return ErlangAbstractHandler.extendSelectionToWholeLines(document, new TextSelection(document, offset, r2.getOffset() - offset + r2.getLength()));
}
}
} catch (final ErlModelException e) {
}
}
}
return ErlangAbstractHandler.extendSelectionToWholeLines(document, selection);
}
Aggregations