use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.
the class EditorUtility method isOpenInEditor.
/**
* Tests if a CU is currently shown in an editor
*
* @return the IEditorPart if shown, null if element is not open in an
* editor
*/
public static IEditorPart isOpenInEditor(final Object inputElement) {
final Collection<IEditorPart> allErlangEditors = EditorUtility.getAllErlangEditors();
for (final IEditorPart editorPart : allErlangEditors) {
if (inputElement instanceof IErlElement) {
final IErlElement element = (IErlElement) inputElement;
final IErlModule module = ErlangEngine.getInstance().getModelUtilService().getModule(element);
final AbstractErlangEditor editor = (AbstractErlangEditor) editorPart;
if (module.equals(editor.getModule())) {
return editorPart;
}
}
}
final IEditorInput input = EditorUtility.getEditorInput(inputElement);
if (input != null) {
for (final IEditorPart editorPart : allErlangEditors) {
if (editorPart.getEditorInput().equals(input)) {
return editorPart;
}
}
}
return null;
}
use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.
the class ErlangExternalEditorInputFactory method createElement.
@Override
public IAdaptable createElement(final IMemento memento) {
// Get the file name.
final String externalModulePath = memento.getString(ErlangExternalEditorInputFactory.TAG_EXTERNAL_MODULE_PATH);
if (externalModulePath == null) {
return null;
}
IErlModule module;
try {
final IErlModel model = ErlangEngine.getInstance().getModel();
module = ErlangEngine.getInstance().getModelUtilService().getModuleFromExternalModulePath(model, externalModulePath);
} catch (final ErlModelException e1) {
return null;
}
if (module == null) {
return null;
}
// Get the file name.
final String uriString = memento.getString(ErlangExternalEditorInputFactory.TAG_URI);
if (uriString == null) {
return null;
}
URI uri;
try {
uri = new URI(uriString);
} catch (final URISyntaxException e) {
return null;
}
try {
return new ErlangExternalEditorInput(EFS.getStore(uri), module);
} catch (final CoreException e) {
return null;
}
}
use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.
the class RemoteFunctionClauseDialog method createDialogArea.
@Override
protected Control createDialogArea(final Composite parent) {
final Composite composite = (Composite) super.createDialogArea(parent);
final Tree functionClausesTree;
final Label label = new Label(composite, SWT.WRAP);
label.setText("Please select the function clause which against should fold!");
final GridData minToksData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
minToksData.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
label.setLayoutData(minToksData);
label.setFont(parent.getFont());
functionClausesTree = new Tree(composite, SWT.BORDER);
final GridData treeData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
treeData.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
functionClausesTree.setLayoutData(treeData);
try {
final Collection<IErlModule> erlmodules = ErlangEngine.getInstance().getModelUtilService().getProject(GlobalParameters.getWranglerSelection().getErlElement()).getModules();
for (final IErlModule m : erlmodules) {
// must refresh the scanner!
m.open(null);
final TreeItem moduleName = new TreeItem(functionClausesTree, 0);
moduleName.setText(m.getModuleName());
moduleName.setData(m);
final List<IErlFunction> functions = filterFunctions(m.getChildren());
for (final IErlFunction f : functions) {
final TreeItem functionName = new TreeItem(moduleName, 0);
functionName.setText(f.getNameWithArity());
final List<IErlFunctionClause> clauses = filterClauses(f.getChildren());
functionName.setData(f);
for (final IErlFunctionClause c : clauses) {
final TreeItem clauseName = new TreeItem(functionName, 0);
clauseName.setText(String.valueOf(c.getName()));
clauseName.setData(c);
}
}
}
// listen to treeitem selection
functionClausesTree.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(final SelectionEvent e) {
}
// if a function or a function clause is selected, then
// highlight it
// and store the selection
@Override
public void widgetSelected(final SelectionEvent e) {
final TreeItem[] selectedItems = functionClausesTree.getSelection();
if (selectedItems.length > 0) {
final TreeItem treeItem = selectedItems[0];
final Object data = treeItem.getData();
if (data instanceof IErlFunctionClause) {
// enable the ok button
okButton.setEnabled(true);
// highlight
WranglerUtils.highlightSelection((IErlFunctionClause) data);
// store
functionClause = (IErlFunctionClause) data;
} else {
okButton.setEnabled(false);
}
}
}
});
} catch (final ErlModelException e) {
ErlLogger.error(e);
}
applyDialogFont(composite);
return composite;
}
use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.
the class WranglerUtils method notifyErlide.
/**
* Notifies Erlide about the changed files.
*
* @param changedFiles
* changed files
*/
public static void notifyErlide(final List<ChangedFile> changedFiles) {
final IErlModel model = ErlangEngine.getInstance().getModel();
for (final ChangedFile f : changedFiles) {
IFile file;
try {
file = WranglerUtils.getFileFromPath(f.getNewPath());
final IErlElement element = model.findElement(file);
final IErlModule m = (IErlModule) element;
m.resourceChanged(null);
final IEditorPart editor = GlobalParameters.getEditor();
if (editor instanceof ErlangEditor) {
((ErlangEditor) editor).resetAndCacheScannerAndParser();
}
model.notifyChange(m);
} catch (final Exception e) {
ErlLogger.error(e);
}
}
}
use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.
the class AddRefacHandler method checkType.
// check if the refactoring is elementary or composite
private RefacType checkType(final String callbackModule) {
try {
final IErlModule module = ErlangEngine.getInstance().getModel().findModule(callbackModule);
final ScannerService scanner = module.getScanner();
try {
module.resetAndCacheScannerAndParser(null);
} finally {
scanner.dispose();
}
for (final IErlElement el : module.getChildrenOfKind(ErlElementKind.ATTRIBUTE)) {
final IErlAttribute attr = (IErlAttribute) el;
if ("behaviour".equals(attr.getName()) || "behavior".equals(attr.getName())) {
if (attr.getValue().toString().contains("gen_refac")) {
return RefacType.ELEMENTARY;
} else if (attr.getValue().toString().contains("gen_composite_refac")) {
return RefacType.COMPOSITE;
}
}
}
return null;
} catch (final ErlModelException e) {
return null;
}
}
Aggregations