List of usage examples for org.eclipse.jface.viewers IStructuredSelection getFirstElement
public Object getFirstElement();
null
if the selection is empty. From source file:com.aptana.deploy.wizard.DeployWizardPage.java
License:Open Source License
protected void updateMessage() { setMessage(com.aptana.deploy.wizard.WorkbenchMessages.DeployWizardPage_SelectYourDesiredDeploymentOption); TreeViewer viewer = getTreeViewer(); if (viewer != null) { ISelection selection = viewer.getSelection(); IStructuredSelection ss = (IStructuredSelection) selection; Object sel = ss.getFirstElement(); if (sel instanceof WorkbenchWizardElement) { updateSelectedNode((WorkbenchWizardElement) sel); } else {//from w w w . j a va 2 s. c om setSelectedNode(null); } } else { descriptionLabel.setText(null); } }
From source file:com.aptana.deploy.wizard.DeployWizardPage.java
License:Open Source License
protected void listSelectionChanged(ISelection selection) { setErrorMessage(null);/*from www. j a v a2 s . co m*/ IStructuredSelection ss = (IStructuredSelection) selection; Object sel = ss.getFirstElement(); if (sel instanceof WorkbenchWizardElement) { WorkbenchWizardElement currentWizardSelection = (WorkbenchWizardElement) sel; updateSelectedNode(currentWizardSelection); } else { updateSelectedNode(null); } }
From source file:com.aptana.editor.common.outline.CommonOutlinePage.java
License:Open Source License
@Override public void createControl(Composite parent) { fMainControl = new Composite(parent, SWT.NONE); fMainControl.setLayout(GridLayoutFactory.fillDefaults().spacing(0, 2).create()); fMainControl.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create()); fSearchBox = new Text(fMainControl, SWT.SINGLE | SWT.BORDER | SWT.SEARCH); fSearchBox.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).indent(0, 3).create()); fSearchBox.setText(INITIAL_FILTER_TEXT); fSearchBox.setForeground(fSearchBox.getDisplay().getSystemColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND)); fSearchBox.addModifyListener(fSearchModifyListener); fSearchBox.addFocusListener(new FocusListener() { public void focusLost(FocusEvent e) { if (fSearchBox.getText().length() == 0) { fSearchBox.removeModifyListener(fSearchModifyListener); fSearchBox.setText(INITIAL_FILTER_TEXT); fSearchBox.addModifyListener(fSearchModifyListener); }/*from w w w . j av a 2s .c om*/ fSearchBox .setForeground(fSearchBox.getDisplay().getSystemColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND)); } public void focusGained(FocusEvent e) { if (fSearchBox.getText().equals(INITIAL_FILTER_TEXT)) { fSearchBox.removeModifyListener(fSearchModifyListener); fSearchBox.setText(StringUtil.EMPTY); fSearchBox.addModifyListener(fSearchModifyListener); } fSearchBox.setForeground(null); } }); fTreeViewer = new TreeViewer(fMainControl, SWT.VIRTUAL | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); fTreeViewer.addSelectionChangedListener(this); fTreeViewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create()); ((IContextService) getSite().getService(IContextService.class)).activateContext(OUTLINE_CONTEXT); final TreeViewer viewer = getTreeViewer(); viewer.setUseHashlookup(true); viewer.setContentProvider(fContentProvider); viewer.setLabelProvider(fLabelProvider); fInput = new CommonOutlinePageInput(fEditor.getAST()); // Note: the input remains the same (we change its internal contents with a new ast and call refresh, // so that the outline structure is maintained). viewer.setInput(fInput); viewer.setComparator(isSortingEnabled() ? new ViewerComparator() : null); fFilter = new PatternFilter() { @Override protected boolean isLeafMatch(Viewer viewer, Object element) { String label = null; if (element instanceof CommonOutlineItem) { label = ((CommonOutlineItem) element).getLabel(); } else if (element instanceof IParseNode) { label = ((IParseNode) element).getText(); } if (label == null) { return true; } return wordMatches(label); } }; fFilter.setIncludeLeadingWildcard(true); viewer.addFilter(fFilter); viewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); // expands the selection one level if applicable viewer.expandToLevel(selection.getFirstElement(), 1); // selects the corresponding text in editor if (!isLinkedWithEditor()) { setEditorSelection(selection, true); } } }); viewer.getTree().addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { } public void keyReleased(KeyEvent e) { if (e.keyCode == '\r' && isLinkedWithEditor()) { ISelection selection = viewer.getSelection(); if (!selection.isEmpty() && selection instanceof IStructuredSelection) { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); if (page != null) { // brings editor to focus page.activate(fEditor); // deselects the current selection but keeps the cursor position Object widget = fEditor.getAdapter(Control.class); if (widget instanceof StyledText) fEditor.selectAndReveal(((StyledText) widget).getCaretOffset(), 0); } } } } }); hookToThemes(); IActionBars actionBars = getSite().getActionBars(); registerActions(actionBars); actionBars.updateActionBars(); fPrefs.addPropertyChangeListener(this); fFilterRefreshJob = new WorkbenchJob("Refresh Filter") //$NON-NLS-1$ { @Override public IStatus runInUIThread(IProgressMonitor monitor) { if (isDisposed()) { return Status.CANCEL_STATUS; } fTreeViewer.refresh(); String text = fSearchBox.getText(); if (!StringUtil.isEmpty(text) && !INITIAL_FILTER_TEXT.equals(text)) { fTreeViewer.expandAll(); } return Status.OK_STATUS; } }; EclipseUtil.setSystemForJob(fFilterRefreshJob); }
From source file:com.aptana.editor.common.outline.CommonOutlinePage.java
License:Open Source License
private void setEditorSelection(IStructuredSelection selection, boolean checkIfActive) { if (selection.size() == 1) { Object element = selection.getFirstElement(); if (element instanceof IRange) { // selects the range in the editor fEditor.select((IRange) element, checkIfActive); }/* w w w. j a v a 2 s. c o m*/ } }
From source file:com.aptana.editor.common.outline.CommonQuickOutlinePage.java
License:Open Source License
private void gotoSelectedElement() { ISelection selection = getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection structured = (IStructuredSelection) selection; // If a node in the outline view is selected if (structured.size() == 1) { Object element = structured.getFirstElement(); if (element instanceof CommonOutlineItem) { CommonOutlineItem item = (CommonOutlineItem) element; this._editor.selectAndReveal(item.getStartingOffset(), item.getLength()); closeDialog();// w w w . j a va 2 s .c o m } else if (element instanceof IParseNode) { int position = ((IParseNode) element).getStartingOffset(); this._editor.selectAndReveal(position, 0); closeDialog(); } return; } } this._editor.getISourceViewer().removeRangeIndication(); }
From source file:com.aptana.editor.common.preferences.ValidationPreferencePage.java
License:Open Source License
private IBuildParticipantWorkingCopy getSelectedBuildParticipant() { IStructuredSelection selection = (IStructuredSelection) validatorsViewer.getSelection(); if (selection.isEmpty()) { return null; }/* w ww. j a va2s .com*/ return (IBuildParticipantWorkingCopy) selection.getFirstElement(); }
From source file:com.aptana.editor.php.internal.ui.preferences.PHPLibrariesPreferencePage.java
License:Open Source License
@Override protected Control createContents(Composite parent) { Composite body = new Composite(parent, SWT.NONE); body.setLayout(new GridLayout(1, false)); Label label = new Label(body, SWT.NONE | SWT.WRAP); label.setText(Messages.PHPLibrariesPreferencePage_librariesTitle); final Map<URL, Image> images = new HashMap<URL, Image>(); Composite tableAndButton = new Composite(body, SWT.NONE); tableAndButton.setLayout(new GridLayout(2, false)); newCheckList = CheckboxTableViewer.newCheckList(tableAndButton, SWT.BORDER); newCheckList.setContentProvider(new ArrayContentProvider()); newCheckList.setInput(LibraryManager.getInstance().getAllLibraries()); Composite buttons = new Composite(tableAndButton, SWT.NONE); buttons.setLayout(new GridLayout(1, false)); newCheckList.setComparator(new ViewerComparator()); newCheckList.setLabelProvider(new LibraryLabelProvider(images)); GridData layoutData = new GridData(GridData.FILL_BOTH); layoutData.minimumHeight = 400;/*from w ww .j a v a 2s . c o m*/ newCheckList.getControl().setLayoutData(layoutData); body.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { for (Image m : images.values()) { m.dispose(); } } }); layoutData = new GridData(); layoutData.heightHint = 400; body.setLayoutData(layoutData); for (IPHPLibrary l : LibraryManager.getInstance().getAllLibraries()) { newCheckList.setChecked(l, l.isTurnedOn()); } buttons.setLayoutData(new GridData(GridData.FILL_VERTICAL)); Button add = new Button(buttons, SWT.PUSH); add.setText(Messages.PHPLibrariesPreferencePage_newUserLibrary); add.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); add.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { PHPLibraryDialog libraryDialog = new PHPLibraryDialog(Display.getCurrent().getActiveShell(), null, getContent()); if (libraryDialog.open() == Dialog.OK) { UserLibrary result = libraryDialog.getResult(); newCheckList.add(result); newCheckList.setChecked(result, true); } } }); final Button edit = new Button(buttons, SWT.PUSH); edit.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { // empty } public void widgetSelected(SelectionEvent e) { IStructuredSelection ss = (IStructuredSelection) newCheckList.getSelection(); UserLibrary firstElement = (UserLibrary) ss.getFirstElement(); PHPLibraryDialog libraryDialog = new PHPLibraryDialog(Display.getCurrent().getActiveShell(), firstElement, getContent()); if (libraryDialog.open() == Dialog.OK) { newCheckList.remove(firstElement); newCheckList.add(libraryDialog.getResult()); } } }); edit.setText(Messages.PHPLibrariesPreferencePage_editLibrary); edit.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); final Button remove = new Button(buttons, SWT.PUSH); remove.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { IStructuredSelection ss = (IStructuredSelection) newCheckList.getSelection(); for (Object o : ss.toArray()) { newCheckList.remove(o); } } }); remove.setText(Messages.PHPLibrariesPreferencePage_removeLibrary); tableAndButton.setLayoutData(new GridData(GridData.FILL_BOTH)); remove.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); newCheckList.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection ss = (IStructuredSelection) event.getSelection(); if (ss.isEmpty() || ss.getFirstElement() instanceof PHPLibrary) { edit.setEnabled(false); remove.setEnabled(false); return; } edit.setEnabled(true); remove.setEnabled(true); } }); Button selectAll = new Button(buttons, SWT.PUSH); selectAll.setText(Messages.LibrariesPage_selectAll); selectAll.addSelectionListener(new SelectAction(true)); Button deselectAll = new Button(buttons, SWT.PUSH); deselectAll.setText(Messages.LibrariesPage_deselectAll); selectAll.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); deselectAll.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); deselectAll.addSelectionListener(new SelectAction(false)); edit.setEnabled(false); remove.setEnabled(false); return body; }
From source file:com.aptana.git.ui.actions.AbstractDynamicBranchItem.java
License:Open Source License
protected IResource getSelectedResource() { IEvaluationService evalService = (IEvaluationService) serviceLocator.getService(IEvaluationService.class); if (evalService != null) { IEvaluationContext context = evalService.getCurrentState(); IWorkbenchPart activePart = (IWorkbenchPart) context.getVariable(ISources.ACTIVE_PART_NAME); if (activePart instanceof IEditorPart) { IEditorInput input = (IEditorInput) context.getVariable(ISources.ACTIVE_EDITOR_INPUT_NAME); return (IResource) input.getAdapter(IResource.class); }//from ww w . j a va 2 s .c om ISelection selection = (ISelection) context.getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME); if (selection instanceof IStructuredSelection) { IStructuredSelection struct = (IStructuredSelection) selection; Object firstElement = struct.getFirstElement(); if (firstElement instanceof IResource) { return (IResource) firstElement; } else if (firstElement instanceof IAdaptable) { IAdaptable adaptable = (IAdaptable) firstElement; return (IResource) adaptable.getAdapter(IResource.class); } } } return null; }
From source file:com.aptana.git.ui.internal.actions.AttachGitRepoHandler.java
License:Open Source License
private IProject getSelectedProject(Object applicationContext) { ISelection sel = getSelection(applicationContext); if (sel == null || sel.isEmpty() || !(sel instanceof IStructuredSelection)) { return null; }/*from w w w . j a v a 2s. co m*/ IStructuredSelection structured = (IStructuredSelection) sel; Object first = structured.getFirstElement(); IResource resource = null; if (first instanceof IResource) { resource = (IResource) first; } else if (first instanceof IAdaptable) { IAdaptable adaptable = (IAdaptable) first; resource = (IResource) adaptable.getAdapter(IResource.class); } if (resource != null) { return resource.getProject(); } return null; }
From source file:com.aptana.git.ui.internal.actions.CherryPickHandler.java
License:Open Source License
private GitCommit getCommit(IEvaluationContext evaluationContext) { ISelection selection = null;/*from w ww. j av a 2 s.c o m*/ Object part = evaluationContext.getVariable(ISources.ACTIVE_PART_NAME); if (part instanceof IHistoryView) { IHistoryView view = (IHistoryView) part; IHistoryPage page = view.getHistoryPage(); if (page instanceof GitHistoryPage) { GitHistoryPage ghp = (GitHistoryPage) page; selection = ghp.getSelectionProvider().getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) selection; Object selected = ss.getFirstElement(); if (selected instanceof GitCommit) { return (GitCommit) selected; } } } } return null; }