List of usage examples for org.eclipse.jface.viewers IStructuredSelection getFirstElement
public Object getFirstElement();
null
if the selection is empty. From source file:ch.uzh.ifi.seal.permo.history.main.ui.view.ProjectHistoryViewMainControl.java
License:Apache License
private void createContent() { final SashForm sashForm = new SashForm(this, SWT.VERTICAL); setRealContent(sashForm, GridDataBuilder.singleCell().alignment(SWT.FILL).grabSpace().create()); final Composite overviewBox = new Composite(sashForm, SWT.NONE); overviewBox.setLayout(GridLayoutBuilder.oneColumn().noMargin().spacing(LayoutConstants.SPACING).create()); title = new ProjectHistoryTitle(overviewBox, SWT.NONE); title.setLayoutData(GridDataBuilder.singleCell().alignment(SWT.FILL).grabHorizontalSpace().create()); projectHistoryTable = new ProjectHistoryTable(overviewBox); projectHistoryTable.getTable()/*from www. j a v a 2 s . co m*/ .setLayoutData(GridDataBuilder.singleCell().alignment(SWT.FILL).grabSpace().create()); projectHistoryTable.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(final SelectionChangedEvent event) { if (event.getSelection() instanceof IStructuredSelection) { final IStructuredSelection selection = (IStructuredSelection) event.getSelection(); if (selection.getFirstElement() instanceof ProjectHistoryEventViewModel) { viewModel.setSelectedEvent((ProjectHistoryEventViewModel) selection.getFirstElement()); } } } }); new EventDetailWrapper(sashForm, viewModel); }
From source file:ch.wess.ezclipse.ini.wizards.internal.NewINIWizardPage.java
License:Open Source License
/** * Tests if the current workbench selection is a suitable container to use. *//*from ww w . ja va 2s . c om*/ private void initialize() { if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) { IStructuredSelection ssel = (IStructuredSelection) selection; if (ssel.size() > 1) return; Object obj = ssel.getFirstElement(); if (obj instanceof IResource) { IContainer container; if (obj instanceof IContainer) container = (IContainer) obj; else container = ((IResource) obj).getParent(); containerText.setText(container.getFullPath().toString()); } } fileText.setText("new_file." + getExtension()); //$NON-NLS-1$ }
From source file:ch.wess.ezclipse.tpl.wizards.internal.NewTemplateWizardPage.java
License:Open Source License
/** * Tests if the current workbench selection is a suitable container to use. *//*from www . j a v a2 s .c om*/ private void initialize() { if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) { IStructuredSelection ssel = (IStructuredSelection) selection; if (ssel.size() > 1) return; Object obj = ssel.getFirstElement(); if (obj instanceof IResource) { IContainer container; if (obj instanceof IContainer) container = (IContainer) obj; else container = ((IResource) obj).getParent(); containerText.setText(container.getFullPath().toString()); } } fileText.setText("new_file.tpl"); //$NON-NLS-1$ }
From source file:ch.wess.ezclipse.varbrowser.handlers.internal.CopyHandler.java
License:Open Source License
/** * This method copy the tree path of the selected element to the clipboard. * //from w w w .jav a2 s .c om * @param event */ @Override public Object execute(ExecutionEvent event) throws ExecutionException { // Retrieve the selected element. ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection(); if (selection != null & selection instanceof IStructuredSelection) { IStructuredSelection strucSelection = (IStructuredSelection) selection; Object selectedElement = strucSelection.getFirstElement(); if (selectedElement instanceof Variable) { String path = ""; //$NON-NLS-1$ Variable currentItem = (Variable) selectedElement; boolean first = true; while (currentItem.getName() != "node") { //$NON-NLS-1$ path = currentItem.getName().concat(first ? "" : "." + path); //$NON-NLS-1$ //$NON-NLS-2$ currentItem = currentItem.getParent(); first = false; } String finalPath = "$node." + path; //$NON-NLS-1$ Clipboard cp = new Clipboard(HandlerUtil.getActivePart(event).getSite().getShell().getDisplay()); TextTransfer tt = TextTransfer.getInstance(); cp.setContents(new String[] { finalPath }, new Transfer[] { tt }); cp.dispose(); } } return null; }
From source file:ch.wess.ezclipse.varbrowser.handlers.internal.RefreshHandler.java
License:Open Source License
/** * Refresh the subtree of the selected element. * /*from w w w . j a va 2 s. c om*/ * @param event */ @Override public Object execute(ExecutionEvent event) throws ExecutionException { // Retrieve the selected element. ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection(); Object selectedElement = null; if (selection != null & selection instanceof IStructuredSelection) { IStructuredSelection strucSelection = (IStructuredSelection) selection; selectedElement = strucSelection.getFirstElement(); } if (selectedElement != null && selectedElement instanceof Variable) { IWorkbenchPart varBrowser = HandlerUtil.getActivePart(event); if (varBrowser instanceof VarBrowser) { if (((Variable) selectedElement).isContainer()) { ((VarBrowser) varBrowser).getTreeViewer().refresh(selectedElement); } else { if (((Variable) selectedElement).getParent() != null) { ((VarBrowser) varBrowser).getTreeViewer().refresh(((Variable) selectedElement).getParent()); } else { ((VarBrowser) varBrowser).getTreeViewer().refresh(); } } } } return null; }
From source file:cideplus.ui.astview.ASTView.java
License:Open Source License
@Override public void createPartControl(Composite parent) { fSash = new SashForm(parent, SWT.VERTICAL | SWT.SMOOTH); fViewer = new TreeViewer(fSash, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); fDrillDownAdapter = new DrillDownAdapter(fViewer); fViewer.setContentProvider(new ASTViewContentProvider()); fASTLabelProvider = new ASTViewLabelProvider(); fViewer.setLabelProvider(fASTLabelProvider); fViewer.addSelectionChangedListener(fSuperListener); fViewer.addDoubleClickListener(fSuperListener); fViewer.addFilter(new ViewerFilter() { @Override//from w w w. ja v a 2 s . com public boolean select(Viewer viewer, Object parentElement, Object element) { if (!fCreateBindings && element instanceof Binding) return false; return true; } }); fViewer.addFilter(fNonRelevantFilter); ViewForm trayForm = new ViewForm(fSash, SWT.NONE); Label label = new Label(trayForm, SWT.NONE); label.setText(" Comparison Tray (* = selection in the upper tree):"); //$NON-NLS-1$ trayForm.setTopLeft(label); fTray = new TreeViewer(trayForm, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); trayForm.setContent(fTray.getTree()); fTrayRoots = new ArrayList(); fTray.setContentProvider(new TrayContentProvider()); final TrayLabelProvider trayLabelProvider = new TrayLabelProvider(); fTray.setLabelProvider(trayLabelProvider); fTray.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS); fTrayUpdater = new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection viewerSelection = (IStructuredSelection) fViewer.getSelection(); if (viewerSelection.size() == 1) { Object first = viewerSelection.getFirstElement(); if (unwrapAttribute(first) != null) { trayLabelProvider.setViewerElement(first); return; } } trayLabelProvider.setViewerElement(null); } }; fTray.addPostSelectionChangedListener(fTrayUpdater); fViewer.addPostSelectionChangedListener(fTrayUpdater); fTray.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { performTrayDoubleClick(); } }); fTray.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); fDeleteAction.setEnabled(selection.size() >= 1 && fTray.getTree().isFocusControl()); } }); fTray.getTree().addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { IStructuredSelection selection = (IStructuredSelection) fTray.getSelection(); fDeleteAction.setEnabled(selection.size() >= 1); } @Override public void focusLost(FocusEvent e) { fDeleteAction.setEnabled(false); } }); makeActions(); hookContextMenu(); hookTrayContextMenu(); contributeToActionBars(); getSite().setSelectionProvider(new ASTViewSelectionProvider()); try { IEditorPart part = EditorUtility.getActiveEditor(); if (part instanceof ITextEditor) { setInput((ITextEditor) part); } } catch (CoreException e) { // ignore } if (fTypeRoot == null) { clearView(); } else { setASTUptoDate(fTypeRoot != null); } }
From source file:cideplus.ui.astview.ASTView.java
License:Open Source License
private ASTNode getASTNodeNearSelection(IStructuredSelection selection) { Object elem = selection.getFirstElement(); if (elem instanceof ASTAttribute) { return ((ASTAttribute) elem).getParentASTNode(); } else if (elem instanceof ASTNode) { return (ASTNode) elem; }/*ww w. j a va 2 s .co m*/ return null; }
From source file:cideplus.ui.astview.ASTView.java
License:Open Source License
protected void handleSelectionChanged(ISelection selection) { fExpandAction.setEnabled(!selection.isEmpty()); fCollapseAction.setEnabled(!selection.isEmpty()); fCopyAction.setEnabled(!selection.isEmpty()); boolean addEnabled = false; IStructuredSelection structuredSelection = (IStructuredSelection) selection; if (structuredSelection.size() == 1 && fViewer.getTree().isFocusControl()) { Object first = structuredSelection.getFirstElement(); Object unwrapped = ASTView.unwrapAttribute(first); addEnabled = unwrapped != null;/*from w ww .jav a 2s.c o m*/ } fAddToTrayAction.setEnabled(addEnabled); }
From source file:cideplus.ui.astview.ASTView.java
License:Open Source License
protected void performAddToTray() { IStructuredSelection selection = (IStructuredSelection) fViewer.getSelection(); Object firstElement = selection.getFirstElement(); if (!fTrayRoots.contains(firstElement)) { fTrayRoots.add(firstElement);//from w ww . ja va 2 s . co m fTray.setInput(fTrayRoots); } if (fSash.getMaximizedControl() != null) { int trayHeight = fTray.getTree().getItemHeight() * (2 + TrayContentProvider.DEFAULT_CHILDREN_COUNT); int sashHeight = fSash.getClientArea().height; fSash.setWeights(new int[] { sashHeight - trayHeight, trayHeight }); fSash.setMaximizedControl(null); } setTraySelection(selection); }
From source file:cideplus.ui.astview.ASTView.java
License:Open Source License
protected void performTrayDoubleClick() { IStructuredSelection selection = (IStructuredSelection) fTray.getSelection(); if (selection.size() != 1) return;/*from w w w. ja v a 2 s .c o m*/ Object obj = selection.getFirstElement(); if (obj instanceof ExceptionAttribute) { Throwable exception = ((ExceptionAttribute) obj).getException(); if (exception != null) { String label = ((ExceptionAttribute) obj).getLabel(); showAndLogError("An error occurred while calculating an AST View Label:\n" + label, exception); //$NON-NLS-1$ return; } } if (obj instanceof Binding) { Binding binding = (Binding) obj; fViewer.setSelection(new StructuredSelection(binding), true); } }