Search in sources :

Example 81 with TextSelection

use of org.eclipse.jface.text.TextSelection in project webtools.sourceediting by eclipse.

the class StructuredSelectPreviousXMLActionDelegate method getNewSelectionRegion.

protected Region getNewSelectionRegion(IndexedRegion indexedRegion, ITextSelection textSelection) {
    Region newRegion = null;
    if (indexedRegion instanceof Node) {
        Node cursorNode = (Node) indexedRegion;
        // use parent node for empty text node
        if ((cursorNode.getNodeType() == Node.TEXT_NODE) && (cursorNode.getNodeValue().trim().length() == 0)) {
            cursorNode = cursorNode.getParentNode();
            if (cursorNode instanceof IndexedRegion) {
                indexedRegion = (IndexedRegion) cursorNode;
            }
        }
        Region cursorNodeRegion = new Region(indexedRegion.getStartOffset(), indexedRegion.getEndOffset() - indexedRegion.getStartOffset());
        if ((cursorNodeRegion.getOffset() >= textSelection.getOffset()) && (cursorNodeRegion.getOffset() <= textSelection.getOffset() + textSelection.getLength()) && (cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() >= textSelection.getOffset()) && (cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() <= textSelection.getOffset() + textSelection.getLength())) {
            Node newNode = cursorNode.getPreviousSibling();
            if (newNode == null) {
                newNode = cursorNode.getParentNode();
                if (newNode instanceof IndexedRegion) {
                    IndexedRegion newIndexedRegion = (IndexedRegion) newNode;
                    newRegion = new Region(newIndexedRegion.getStartOffset(), newIndexedRegion.getEndOffset() - newIndexedRegion.getStartOffset());
                }
            } else {
                if (newNode instanceof IndexedRegion) {
                    IndexedRegion newIndexedRegion = (IndexedRegion) newNode;
                    newRegion = new Region(newIndexedRegion.getStartOffset(), textSelection.getOffset() + textSelection.getLength() - newIndexedRegion.getStartOffset());
                    if (newNode.getNodeType() == Node.TEXT_NODE) {
                        newRegion = getNewSelectionRegion(newIndexedRegion, new TextSelection(newRegion.getOffset(), newRegion.getLength()));
                    }
                }
            }
        } else {
            newRegion = cursorNodeRegion;
        }
    }
    return newRegion;
}
Also used : TextSelection(org.eclipse.jface.text.TextSelection) ITextSelection(org.eclipse.jface.text.ITextSelection) Node(org.w3c.dom.Node) Region(org.eclipse.jface.text.Region) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)

Example 82 with TextSelection

use of org.eclipse.jface.text.TextSelection in project abstools by abstools.

the class OpenTypeHierarchyDelegate method run.

@Override
public void run(IAction action) {
    if (!(editor instanceof ABSEditor)) {
        return;
    }
    ABSEditor abseditor = (ABSEditor) editor;
    TextSelection sel = (TextSelection) abseditor.getSelectionProvider().getSelection();
    TypeHierarchyView view = TypeHierarchyView.get();
    if (view == null) {
        return;
    }
    InternalASTNode<?> node = getNodeUnderCursor(abseditor, sel);
    view.setNode(node);
    view.bringToTop();
}
Also used : TextSelection(org.eclipse.jface.text.TextSelection) ABSEditor(org.absmodels.abs.plugin.editor.ABSEditor)

Example 83 with TextSelection

use of org.eclipse.jface.text.TextSelection in project jbosstools-hibernate by jbosstools.

the class JPAMapToolActor method updateSelectedItems.

/**
 * @param sel - current selected workspace element for processing
 */
private synchronized void updateSelectedItems(ISelection sel) {
    // System.out.println("Blah! " + selection); //$NON-NLS-1$
    if (sel instanceof TextSelection) {
        // $NON-NLS-1$
        String fullyQualifiedName = "";
        IDocument fDocument = null;
        SynchronizableDocument sDocument = null;
        org.eclipse.jdt.core.dom.CompilationUnit resultCU = null;
        Class<?> clazz = sel.getClass();
        Field fd = null;
        try {
            // $NON-NLS-1$
            fd = clazz.getDeclaredField("fDocument");
        } catch (NoSuchFieldException e) {
        // just ignore it!
        }
        if (fd != null) {
            try {
                fd.setAccessible(true);
                fDocument = (IDocument) fd.get(sel);
                if (fDocument instanceof SynchronizableDocument) {
                    sDocument = (SynchronizableDocument) fDocument;
                }
                if (sDocument != null) {
                    ASTParser parser = ASTParser.newParser(AST.JLS9);
                    parser.setSource(sDocument.get().toCharArray());
                    parser.setResolveBindings(false);
                    resultCU = (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(null);
                }
                if (resultCU != null && resultCU.types().size() > 0) {
                    if (resultCU.getPackage() != null) {
                        // $NON-NLS-1$
                        fullyQualifiedName = resultCU.getPackage().getName().getFullyQualifiedName() + ".";
                    } else {
                        // $NON-NLS-1$
                        fullyQualifiedName = "";
                    }
                    Object tmp = resultCU.types().get(0);
                    if (tmp instanceof AbstractTypeDeclaration) {
                        fullyQualifiedName += ((AbstractTypeDeclaration) tmp).getName();
                    }
                    if (!(tmp instanceof TypeDeclaration)) {
                        // ignore EnumDeclaration & AnnotationTypeDeclaration
                        // $NON-NLS-1$
                        fullyQualifiedName = "";
                    }
                }
            } catch (IllegalArgumentException e) {
                // $NON-NLS-1$
                HibernateConsolePlugin.getDefault().logErrorMessage("IllegalArgumentException: ", e);
            } catch (IllegalAccessException e) {
                // $NON-NLS-1$
                HibernateConsolePlugin.getDefault().logErrorMessage("IllegalAccessException: ", e);
            } catch (SecurityException e) {
                // $NON-NLS-1$
                HibernateConsolePlugin.getDefault().logErrorMessage("SecurityException: ", e);
            }
        }
        clearSelectionCU();
        if (fullyQualifiedName.length() > 0) {
            ICompilationUnit cu = Utils.findCompilationUnit(fullyQualifiedName);
            addCompilationUnit(cu);
        }
    } else if (sel instanceof TreeSelection) {
        clearSelectionCU();
        TreeSelection treeSelection = (TreeSelection) sel;
        Iterator<?> it = treeSelection.iterator();
        while (it.hasNext()) {
            Object obj = it.next();
            processJavaElements(obj);
        }
    } else {
        // System.out.println("2 Blah! " + selection); //$NON-NLS-1$
        sel = null;
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) TextSelection(org.eclipse.jface.text.TextSelection) Field(java.lang.reflect.Field) SynchronizableDocument(org.eclipse.core.internal.filebuffers.SynchronizableDocument) TreeSelection(org.eclipse.jface.viewers.TreeSelection) Iterator(java.util.Iterator) ASTParser(org.eclipse.jdt.core.dom.ASTParser) AbstractTypeDeclaration(org.eclipse.jdt.core.dom.AbstractTypeDeclaration) TypeDeclaration(org.eclipse.jdt.core.dom.TypeDeclaration) IDocument(org.eclipse.jface.text.IDocument) AbstractTypeDeclaration(org.eclipse.jdt.core.dom.AbstractTypeDeclaration)

Example 84 with TextSelection

use of org.eclipse.jface.text.TextSelection in project mylyn.docs by eclipse.

the class ShowInTargetBridge method show.

public boolean show(ShowInContext context) {
    ISelection selection = context.getSelection();
    if (selection instanceof IStructuredSelection) {
        for (Object element : ((IStructuredSelection) selection).toArray()) {
            if (element instanceof OutlineItem) {
                OutlineItem item = (OutlineItem) element;
                viewer.setSelection(new TextSelection(item.getOffset(), item.getLength()), true);
                return true;
            }
        }
    } else if (selection instanceof ITextSelection) {
        viewer.setSelection(selection, true);
        return true;
    }
    return false;
}
Also used : TextSelection(org.eclipse.jface.text.TextSelection) ITextSelection(org.eclipse.jface.text.ITextSelection) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ITextSelection(org.eclipse.jface.text.ITextSelection) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 85 with TextSelection

use of org.eclipse.jface.text.TextSelection in project ecf by eclipse.

the class ConsoleShareRosterEntryContributionItem method makeActions.

protected IAction[] makeActions() {
    final TextSelection selection = ConsoleShare.getSelection();
    if (selection == null)
        return null;
    // Else check for Roster entry
    final IRosterEntry entry = getSelectedRosterEntry();
    final IContainer c = getContainerForRosterEntry(entry);
    // If roster entry is selected and it has a container
    if (entry != null && c != null) {
        final IChannelContainerAdapter channelAdapter = (IChannelContainerAdapter) c.getAdapter(IChannelContainerAdapter.class);
        // If the container has channel container adapter and is online/available
        if (channelAdapter != null && isAvailable(entry)) {
            final ConsoleShare tmp = ConsoleShare.getStackShare(c.getID());
            // If there is an URL share associated with this container
            if (tmp != null) {
                final ConsoleShare stackshare = tmp;
                final IAction action = new Action() {

                    public void run() {
                        stackshare.sendShareConsoleSelection(entry.getRoster().getUser().getName(), entry.getUser().getID(), selection.getText());
                    }
                };
                action.setText(Messages.ConsoleShare_RosterEntryMenu);
                action.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, Messages.ConsoleShare_RosterContributionItem_CONSOLE_ICON));
                return new IAction[] { action };
            }
        }
    }
    return null;
}
Also used : IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) IAction(org.eclipse.jface.action.IAction) TextSelection(org.eclipse.jface.text.TextSelection) IChannelContainerAdapter(org.eclipse.ecf.datashare.IChannelContainerAdapter) IRosterEntry(org.eclipse.ecf.presence.roster.IRosterEntry) IContainer(org.eclipse.ecf.core.IContainer)

Aggregations

TextSelection (org.eclipse.jface.text.TextSelection)105 IFile (org.eclipse.core.resources.IFile)35 ITextSelection (org.eclipse.jface.text.ITextSelection)24 ISelection (org.eclipse.jface.viewers.ISelection)24 Test (org.junit.Test)23 IDocument (org.eclipse.jface.text.IDocument)21 IEditorPart (org.eclipse.ui.IEditorPart)19 InputStream (java.io.InputStream)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 Path (org.eclipse.core.runtime.Path)13 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)11 BadLocationException (org.eclipse.jface.text.BadLocationException)10 IRegion (org.eclipse.jface.text.IRegion)10 XtextResource (org.eclipse.xtext.resource.XtextResource)9 IPreferencesService (org.eclipse.core.runtime.preferences.IPreferencesService)8 Module (org.eclipse.titan.designer.AST.Module)8 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)8 XExpression (org.eclipse.xtext.xbase.XExpression)8 TTCN3Editor (org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor)7 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)7