Search in sources :

Example 1 with ErlMemberSelection

use of org.erlide.wrangler.refactoring.selection.internal.ErlMemberSelection 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

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 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)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 ErlTextMemberSelection (org.erlide.wrangler.refactoring.selection.internal.ErlTextMemberSelection)1