List of usage examples for org.eclipse.jface.viewers IStructuredSelection isEmpty
public boolean isEmpty();
From source file:com.android.sdkuilib.internal.repository.ui.AddonSitesDialog.java
License:Apache License
private void userNewOrEdit(final boolean isEdit) { final SdkSource[] knownSources = mSources.getAllSources(); String title = isEdit ? "Edit Add-on Site URL" : "Add Add-on Site URL"; String msg = "Please enter the URL of the addon.xml:"; IStructuredSelection sel = (IStructuredSelection) mUserTableViewer.getSelection(); final String initialValue = !isEdit || sel.isEmpty() ? null : sel.getFirstElement().toString(); if (isEdit && initialValue == null) { // Edit with no actual value is not supposed to happen. Ignore this case. return;//from ww w . jav a2s. co m } InputDialog dlg = new InputDialog(getShell(), title, msg, initialValue, new IInputValidator() { @Override public String isValid(String newText) { newText = newText == null ? null : newText.trim(); if (newText == null || newText.length() == 0) { return "Error: URL field is empty. Please enter a URL."; } // A URL should have one of the following prefixes if (!newText.startsWith("file://") && //$NON-NLS-1$ !newText.startsWith("ftp://") && //$NON-NLS-1$ !newText.startsWith("http://") && //$NON-NLS-1$ !newText.startsWith("https://")) { //$NON-NLS-1$ return "Error: The URL must start by one of file://, ftp://, http:// or https://"; } if (isEdit && newText.equals(initialValue)) { // Edited value hasn't changed. This isn't an error. return null; } // Reject URLs that are already in the source list. // URLs are generally case-insensitive (except for file:// where it all depends // on the current OS so we'll ignore this case.) for (SdkSource s : knownSources) { if (newText.equalsIgnoreCase(s.getUrl())) { return "Error: This site is already listed."; } } return null; } }); if (dlg.open() == Window.OK) { String url = dlg.getValue().trim(); if (!url.equals(initialValue)) { if (isEdit && initialValue != null) { // Remove the old value before we add the new one, which is we just // asserted will be different. for (SdkSource source : mSources.getSources(SdkSourceCategory.USER_ADDONS)) { if (initialValue.equals(source.getUrl())) { mSources.remove(source); break; } } } // create the source, store it and update the list SdkSource newSource; // use url suffix to decide whether this is a SysImg or Addon; // see SdkSources.loadUserAddons() for another check like this if (url.endsWith(SdkSysImgConstants.URL_DEFAULT_FILENAME)) { newSource = new SdkSysImgSource(url, null/*uiName*/); } else { newSource = new SdkAddonSource(url, null/*uiName*/); } mSources.add(SdkSourceCategory.USER_ADDONS, newSource); setReturnValue(true); // notify sources change listeners. This will invoke our own loadUserUrlsList(). mSources.notifyChangeListeners(); // select the new source IStructuredSelection newSel = new StructuredSelection(newSource); mUserTableViewer.setSelection(newSel, true /*reveal*/); } } }
From source file:com.android.sdkuilib.internal.repository.ui.AddonSitesDialog.java
License:Apache License
private void on_UserButtonDelete_widgetSelected(SelectionEvent e) { IStructuredSelection sel = (IStructuredSelection) mUserTableViewer.getSelection(); String selectedUrl = sel.isEmpty() ? null : sel.getFirstElement().toString(); if (selectedUrl == null) { return;//from w ww. j a va2 s . co m } MessageBox mb = new MessageBox(getShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION | SWT.APPLICATION_MODAL); mb.setText("Delete add-on site"); mb.setMessage(String.format("Do you want to delete the URL %1$s?", selectedUrl)); if (mb.open() == SWT.YES) { for (SdkSource source : mSources.getSources(SdkSourceCategory.USER_ADDONS)) { if (selectedUrl.equals(source.getUrl())) { mSources.remove(source); setReturnValue(true); mSources.notifyChangeListeners(); break; } } } }
From source file:com.appnativa.studio.wizards.ScreenSupport.java
License:Open Source License
public String getWorkspaceViewer() { IStructuredSelection sel = ((IStructuredSelection) workspaceViewer.getSelection()); if ((sel != null) && !sel.isEmpty()) { return ((Node) sel.getFirstElement()).id; }//w w w .ja va2s. c o m return 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 ww w . jav a2 s. c o m 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.preferences.ValidationPreferencePage.java
License:Open Source License
private IBuildParticipantWorkingCopy getSelectedBuildParticipant() { IStructuredSelection selection = (IStructuredSelection) validatorsViewer.getSelection(); if (selection.isEmpty()) { return null; }/*www. j a va2 s. co m*/ 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;/* w w w. j av a 2s. co 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.ide.debug.internal.ui.launchConfigurations.HttpServerSettingsTab.java
License:Open Source License
private void updatePage(IStructuredSelection selection) { fRemoveButton.setEnabled(!selection.isEmpty()); fEditButton.setEnabled(selection.size() == 1); }
From source file:com.aptana.ide.debug.internal.ui.preferences.JSDetailFormattersPreferencePage.java
License:Open Source License
private void updatePage(IStructuredSelection selection) { removeFormatterButton.setEnabled(!selection.isEmpty()); editFormatterButton.setEnabled(selection.size() == 1); sourceViewer.getDocument()/* www . j a v a 2 s .c om*/ .set(selection.size() == 1 ? ((DetailFormatter) selection.getFirstElement()).getSnippet() : StringUtils.EMPTY); }
From source file:com.aptana.ide.search.AptanaFileSearchPage.java
License:Open Source License
private void doAdd(IMenuManager mgr) { IStructuredSelection selection = (IStructuredSelection) getViewer().getSelection(); if (!selection.isEmpty()) { ReplaceAction replaceSelection = new ReplaceAction(getSite().getShell(), (FileSearchResult) getInput(), selection.toArray(), true); replaceSelection.setText(SearchMessages.ReplaceAction_label_selected); mgr.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, replaceSelection); }// w w w .ja va 2s .c o m ReplaceAction replaceAll = new ReplaceAction(getSite().getShell(), (FileSearchResult) getInput(), null, true); replaceAll.setText(SearchMessages.ReplaceAction_label_all); mgr.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, replaceAll); }
From source file:com.aptana.ide.search.ui.filesystem.AptanaFileSystemSearchPage.java
License:Open Source License
/** * @see org.eclipse.search.internal.ui.text.FileSearchPage#fillContextMenu(org.eclipse.jface.action.IMenuManager) */// www .j a v a2s . c o m protected void fillContextMenu(IMenuManager mgr) { super.fillContextMenu(mgr); // should be here if our layout is active IStructuredSelection selection = (IStructuredSelection) getViewer().getSelection(); if (!selection.isEmpty()) { FileSystemReplaceAction replaceSelection = new FileSystemReplaceAction(getSite().getShell(), (FileSystemSearchResult) getInput(), selection.toArray(), true); replaceSelection.setText(SearchMessages.ReplaceAction_label_selected); mgr.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, replaceSelection); } FileSystemReplaceAction replaceAll = new FileSystemReplaceAction(getSite().getShell(), (FileSystemSearchResult) getInput(), null, true); replaceAll.setText(SearchMessages.ReplaceAction_label_all); mgr.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, replaceAll); if (this.layout == AptanaFileSystemSearchPage.LAYOUT_MATCHES) { Separator find = (Separator) mgr.find(IContextMenuConstants.GROUP_VIEWER_SETUP); IContributionItem[] items = find.getParent().getItems(); int indexOf = Arrays.asList(items).indexOf(find); MenuManager contributionItem = (MenuManager) items[indexOf + 1]; IContributionItem[] items2 = contributionItem.getItems(); ActionContributionItem it0 = (ActionContributionItem) items2[0]; ActionContributionItem it1 = (ActionContributionItem) items2[1]; it0.getAction().setChecked(fOrder == AptanaFileSystemSearchPage.SHOW_LABEL_PATH); it1.getAction().setChecked(fOrder == AptanaFileSystemSearchPage.SHOW_PATH_LABEL); } }