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;
}
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();
}
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;
}
}
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;
}
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;
}
Aggregations