List of usage examples for org.eclipse.jface.viewers IStructuredSelection getFirstElement
public Object getFirstElement();
null
if the selection is empty. From source file:ca.mcgill.cs.swevo.qualyzer.providers.TreeDragListener.java
License:Open Source License
/** * Builds the drag data so that the drop listener knows it's coming from the tree and can build the node. *//* www. j av a 2 s .co m*/ @Override public void dragSetData(DragSourceEvent event) { if (TextTransfer.getInstance().isSupportedType(event.dataType)) { IStructuredSelection selection = (IStructuredSelection) fViewer.getSelection(); Node node = (Node) selection.getFirstElement(); String data = node.getPersistenceId() + SPLIT + node.getPathToRoot(); event.data = data; } }
From source file:ca.mcgill.cs.swevo.qualyzer.providers.TreeDragListener.java
License:Open Source License
/** * Sets the selection transfer so that the validate drop method can work. *///from ww w. ja va 2s . co m @Override public void dragStart(DragSourceEvent event) { IStructuredSelection selection = (IStructuredSelection) fViewer.getSelection(); Node node = (Node) selection.getFirstElement(); String data = node.getPersistenceId() + SPLIT + node.getPathToRoot(); LocalSelectionTransfer tran = LocalSelectionTransfer.getTransfer(); tran.setSelection(new StructuredSelection(data)); }
From source file:ca.mcgill.cs.swevo.qualyzer.providers.TreeDropListener.java
License:Open Source License
/** * Verifies that the drop is allowed by checking for cycles and duplicates. *///from w ww . ja va 2 s . c om @Override public boolean validateDrop(Object target, int operation, TransferData transferType) { LocalSelectionTransfer sel = LocalSelectionTransfer.getTransfer(); IStructuredSelection selection = (IStructuredSelection) sel.getSelection(); Node nTarget = (Node) target; if (nTarget == null) { nTarget = (Node) fViewer.getInput(); } String data = (String) selection.getFirstElement(); String[] values = data.split(SPLIT); Long id = null; boolean valid = true; if (nTarget != null) { if (values.length == TABLE_DATA_SIZE) { id = Long.parseLong(values[1]); //if(hardCycleExists(nTarget, id, fPage.getTreeModel())) if (containsCycle(id, nTarget)) { valid = false; } } else if (values.length == TREE_DATA_SIZE) { id = Long.parseLong(values[0]); Node node = findNode(values[1], id); if (depthFirstContainsCycle(node, nTarget)) { valid = false; } } Node child = nTarget.getChild(id); if (child != null) { valid = false; } return valid && TextTransfer.getInstance().isSupportedType(transferType); } return false; }
From source file:ca.mcgill.sable.soot.editors.JimpleContentOutlinePage.java
License:Open Source License
public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); if (!selection.isEmpty()) { Object elem = selection.getFirstElement(); if (elem instanceof JimpleOutlineObject) { String toHighlight = ((JimpleOutlineObject) elem).getLabel(); int start = getJimpleFileParser().getStartOfSelected(toHighlight); int length = getJimpleFileParser().getLength(toHighlight); getEd().selectAndReveal(start, length); }//from w ww . j a v a 2s . c om } }
From source file:ca.mcgill.sable.soot.ui.AbstractOptionsDialog.java
License:Open Source License
public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); if (!selection.isEmpty()) { Object elem = selection.getFirstElement(); if (elem instanceof SootOption) { SootOption sel = (SootOption) elem; Control[] children = getPageContainer().getChildren(); String childTitle = null; for (int i = 0; i < children.length; i++) { if (children[i] instanceof Composite) { if (children[i] instanceof Group) { childTitle = (String) ((Group) children[i]).getData("id"); }/* w w w . j a v a 2 s . co m*/ if (childTitle.compareTo(sel.getAlias()) == 0) { ((StackLayout) getPageContainer().getLayout()).topControl = children[i]; getPageContainer().layout(); } else { children[i].setVisible(false); } } } } } }
From source file:ca.mcgill.sable.soot.ui.AnalysisVisManipDialog.java
License:Open Source License
public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); if (selection.isEmpty()) { checkTypes.setInput(getCheckInput("")); } else {/* www. jav a 2 s .c o m*/ Object elem = selection.getFirstElement(); if (!(elem instanceof IFile)) return; ArrayList list = (ArrayList) getCheckInput(elem); handleLast(); checkTypes.setInput(list); Object[] checkElems; if ((currentSettingsMap != null) && (currentSettingsMap.containsKey(elem))) { checkElems = (Object[]) currentSettingsMap.get(elem); checkTypes.setCheckedElements(checkElems); } else { SootAttributesHandler handler = getHandlerForFile((IFile) elem); if (handler != null) { if (handler.isShowAllTypes()) { if (list != null) { Object[] elems = new Object[list.size()]; for (int i = 0; i < list.size(); i++) { elems[i] = checkTypes.getElementAt(i); } checkTypes.setCheckedElements(elems); } } else { Iterator it = handler.getTypesToShow().iterator(); Object[] elems = new Object[handler.getTypesToShow().size()]; int i = 0; while (it.hasNext()) { elems[i] = it.next(); i++; } checkTypes.setCheckedElements(elems); } } } if (getAllSelected() == null) { setAllSelected(new ArrayList()); } getAllSelected().add(elem); } }
From source file:ca.mcgill.sable.soot.ui.SootConfigManagerDialog.java
License:Open Source License
public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); if (!selection.isEmpty()) { Object elem = selection.getFirstElement(); if (elem instanceof SootConfiguration) { SootConfiguration sel = (SootConfiguration) elem; setSelected(sel.getLabel()); }// w w w. ja v a 2s . c o m enableButtons(); } }
From source file:ca.uvic.chisel.diver.mylyn.logger.logging.PageSelectionListener.java
License:Open Source License
/** * @param selection//from ww w . j ava 2 s. co m * @return */ private Object getSelectionObject(IWorkbenchPart part, ISelection selection) { if (selection instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) selection; if (!ss.isEmpty()) { Object o = ss.getFirstElement(); if (o instanceof IJavaElement) { return o; } else if (o instanceof ITraceModel) { return o; } } } else if (selection instanceof ITextSelection) { ITextSelection ts = (ITextSelection) selection; if (part instanceof ITextEditor) { ITextEditor editor = (ITextEditor) part; ITypeRoot typeRoot = null; IEditorInput input = editor.getEditorInput(); //using internal stuff, but I don't care if (input instanceof IClassFileEditorInput) { typeRoot = ((IClassFileEditorInput) input).getClassFile(); } else if (input instanceof IFileEditorInput) { IFile file = ((IFileEditorInput) input).getFile(); IJavaElement element = JavaCore.create(file); if (element instanceof ITypeRoot) { typeRoot = (ITypeRoot) element; } } if (typeRoot != null) { IType type = typeRoot.findPrimaryType(); if (type != null) { try { IJavaElement je = typeRoot.getElementAt(ts.getOffset()); return je; } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } } return null; }
From source file:ca.uvic.chisel.javasketch.ui.internal.presentation.BreadCrumbHook.java
License:Open Source License
@Override public void selectionChanged(SelectionChangedEvent event) { if (event.getSelection() instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) event.getSelection(); Object element = ss.getFirstElement(); IActivation newRoot = null;/* ww w .j a v a2s .c om*/ if (element instanceof ICall) { try { if (((ICall) element).getActivation() != null) { newRoot = ((ICall) element).getTarget().getActivation(); } } catch (NullPointerException e) { } } if (newRoot == null) { newRoot = ((IThread) viewer.getInput()).getRoot().getActivation(); } viewer.setRootActivation(newRoot); } }
From source file:ca.uvic.chisel.javasketch.ui.internal.presentation.commands.ToggleSketchActivationHandler.java
License:Open Source License
/** * @param selection//from w ww. java 2 s. c o m * @return */ private IProgramSketch getSelectedSketch(ISelection selection) { if (selection instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) selection; if (ss.getFirstElement() instanceof IProgramSketch) { return (IProgramSketch) ss.getFirstElement(); } } return null; }