Search in sources :

Example 1 with ErlTextMemberSelection

use of org.erlide.wrangler.refactoring.selection.internal.ErlTextMemberSelection in project erlide_eclipse by erlang.

the class GlobalParameters method setEditor.

/**
 * Stores the editor marked as 'current'
 *
 * @param _editor
 *            stored editor
 */
public static void setEditor(final IEditorPart _editor) {
    GlobalParameters.editor = _editor;
    GlobalParameters.wranglerSelection = new ErlTextMemberSelection((ITextEditor) GlobalParameters.editor);
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) ErlTextMemberSelection(org.erlide.wrangler.refactoring.selection.internal.ErlTextMemberSelection)

Example 2 with ErlTextMemberSelection

use of org.erlide.wrangler.refactoring.selection.internal.ErlTextMemberSelection in project erlide_eclipse by erlang.

the class GlobalParameters method setSelection.

/**
 * Stores a selection marked 'current'
 *
 * @param selection
 *            Erlang selection
 */
public static void setSelection(final ISelection selection) throws WranglerException {
    // TODO:: if the module is selected it is not handled
    try {
        if (GlobalParameters.editor == null) {
            final IWorkbench instance = PlatformUI.getWorkbench();
            final IWorkbenchWindow activeWorkbenchWindow = instance.getActiveWorkbenchWindow();
            GlobalParameters.editor = activeWorkbenchWindow.getActivePage().getActiveEditor();
        }
        if (selection instanceof ITextSelection) {
            final IWorkbench instance = PlatformUI.getWorkbench();
            final IWorkbenchWindow activeWorkbenchWindow = instance.getActiveWorkbenchWindow();
            GlobalParameters.editor = activeWorkbenchWindow.getActivePage().getActiveEditor();
            GlobalParameters.wranglerSelection = new ErlTextMemberSelection((ITextSelection) selection, (ITextEditor) GlobalParameters.editor);
        } else if (selection instanceof ITreeSelection) {
            final Object firstElement = ((ITreeSelection) selection).getFirstElement();
            if (firstElement instanceof IErlElement) {
                final IErlElement element = (IErlElement) firstElement;
                final IFile file = (IFile) element.getResource();
                GlobalParameters.wranglerSelection = new ErlMemberSelection(element, file, WranglerUtils.getDocument(file));
            } else if (firstElement instanceof IFile) {
                final IFile file = (IFile) firstElement;
                final IErlModule module = ErlangEngine.getInstance().getModel().findModule(file);
                GlobalParameters.wranglerSelection = new ErlModuleSelection(module, file);
            } else {
                GlobalParameters.wranglerSelection = null;
                throw new WranglerException("Please select an Erlang element!");
            }
        } else {
            GlobalParameters.wranglerSelection = null;
            throw new WranglerException("Please select an Erlang element!");
        }
    } catch (final ClassCastException e) {
        ErlLogger.error(e);
    }
/*
         * System.out.println(wranglerSelection.getStartLine() + "," +
         * wranglerSelection.getStartCol() + ";" +
         * wranglerSelection.getEndLine() + "," +
         * wranglerSelection.getEndCol());
         */
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IFile(org.eclipse.core.resources.IFile) ErlTextMemberSelection(org.erlide.wrangler.refactoring.selection.internal.ErlTextMemberSelection) ErlModuleSelection(org.erlide.wrangler.refactoring.selection.internal.ErlModuleSelection) WranglerException(org.erlide.wrangler.refactoring.exception.WranglerException) ITextSelection(org.eclipse.jface.text.ITextSelection) IWorkbench(org.eclipse.ui.IWorkbench) IErlElement(org.erlide.engine.model.IErlElement) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) ErlMemberSelection(org.erlide.wrangler.refactoring.selection.internal.ErlMemberSelection) IErlModule(org.erlide.engine.model.root.IErlModule)

Aggregations

ITextEditor (org.eclipse.ui.texteditor.ITextEditor)2 ErlTextMemberSelection (org.erlide.wrangler.refactoring.selection.internal.ErlTextMemberSelection)2 IFile (org.eclipse.core.resources.IFile)1 ITextSelection (org.eclipse.jface.text.ITextSelection)1 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)1 IWorkbench (org.eclipse.ui.IWorkbench)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 IErlElement (org.erlide.engine.model.IErlElement)1 IErlModule (org.erlide.engine.model.root.IErlModule)1 WranglerException (org.erlide.wrangler.refactoring.exception.WranglerException)1 ErlMemberSelection (org.erlide.wrangler.refactoring.selection.internal.ErlMemberSelection)1 ErlModuleSelection (org.erlide.wrangler.refactoring.selection.internal.ErlModuleSelection)1