List of usage examples for org.eclipse.jface.viewers IStructuredSelection size
public int size();
From source file:com.salesforce.ide.ui.handlers.BaseHandler.java
License:Open Source License
protected static final IProject getProjectChecked(final ExecutionEvent event) throws ExecutionException { final IStructuredSelection selection = getStructuredSelection(event); switch (selection.size()) { case 0:/*from ww w . j a v a 2s . co m*/ throw new ExecutionException("No project found while executing " + event.getCommand().getId()); //$NON-NLS-1$ case 1: break; default: throw new ExecutionException("Too many projects found while executing " + event.getCommand().getId()); //$NON-NLS-1$ } final Object firstElement = selection.getFirstElement(); final IProject project = (IProject) Platform.getAdapterManager().getAdapter(firstElement, IProject.class); if (null == project) { throw new ExecutionException("Incorrect type for project found while executing " //$NON-NLS-1$ + event.getCommand().getId() + ", expected " + IProject.class.getName() //$NON-NLS-1$ + " found " + firstElement.getClass().getName()); //$NON-NLS-1$ } return project; }
From source file:com.salesforce.ide.ui.wizards.components.AbstractTemplateSelectionPage.java
License:Open Source License
/** * Get the currently selected template.//from ww w .j av a 2s.c om */ private Template getSelectedTemplate() { Template template = null; IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection(); if (selection.size() == 1) { template = (Template) selection.getFirstElement(); } return template; }
From source file:com.sap.dirigible.ide.workspace.ui.commands.RenameCommandHandler.java
License:Open Source License
private void renameSelection(IStructuredSelection selection) { if (selection.size() != 1) { log.warn(RENAME_OPERATION_CANCELLED_CAN_ONLY_RENAME_A_SINGLE_RESOURCE_AT_A_TIME); return;/*from ww w . j a va 2 s .co m*/ } final Object element = selection.getFirstElement(); if (!(element instanceof IResource)) { log.warn(RENAME_OPERATION_CANCELLED_CAN_ONLY_RENAME_INSTANCES_OF_I_RESOURCE); return; } String newValue = renameResource((IResource) element); if (newValue != null) { renameFileInEditor(((IResource) element).getName(), newValue); } }
From source file:com.sap.dirigible.ide.workspace.wizard.project.commands.DownloadProjectHandler.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event); if (selection.size() == 1) { Object firstElement = selection.getFirstElement(); if (firstElement instanceof IProject) { IProject project = (IProject) firstElement; DownloadDialog downloadDialog = new DownloadDialog(HandlerUtil.getActiveShell(event)); downloadDialog.setURL(DownloadProjectServiceHandler.getUrl(project.getName())); downloadDialog.open();/*from w w w . j a v a 2 s . com*/ } } else if (selection.size() > 1) { StringBuffer projectNames = new StringBuffer(); Iterator<?> iterator = selection.iterator(); boolean dot = false; while (iterator.hasNext()) { Object element = iterator.next(); if (element instanceof IProject) { IProject project = (IProject) element; if (dot) { projectNames.append(RepositoryDataStore.PROJECT_NAME_SEPARATOR); } projectNames.append(project.getName()); dot = true; } } DownloadDialog downloadDialog = new DownloadDialog(HandlerUtil.getActiveShell(event)); downloadDialog.setURL(DownloadProjectServiceHandler.getUrl(projectNames.toString())); downloadDialog.open(); } return null; }
From source file:com.se.simplicity.editor.ui.wizards.NewSceneWizardPage.java
License:Open Source License
/** * Tests if the current workbench selection is a suitable container to use. */// w ww .j av a 2 s .c o m private void initialize() { if (fSelection != null && !fSelection.isEmpty() && fSelection instanceof IStructuredSelection) { IStructuredSelection ssel = (IStructuredSelection) fSelection; 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(); } fContainerText.setText(container.getFullPath().toString()); } } fFileText.setText("new_scene.sss"); }
From source file:com.siteview.mde.internal.runtime.spy.sections.ActiveSelectionSection.java
License:Open Source License
public void build(ScrolledForm form, SpyFormToolkit toolkit, ExecutionEvent event) { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); if (window == null) // if we don't have an active workbench, we don't have a valid selection to analyze return;/*from www . j a va2 s. co m*/ // analyze the selection ISelection selection = HandlerUtil.getCurrentSelection(event); if (selection != null) { Section section = toolkit.createSection(form.getBody(), ExpandableComposite.TITLE_BAR); section.clientVerticalSpacing = 9; section.setText(MDERuntimeMessages.SpyDialog_activeSelection_title); FormText text = toolkit.createFormText(section, true); section.setClient(text); TableWrapData td = new TableWrapData(); td.align = TableWrapData.FILL; td.grabHorizontal = true; section.setLayoutData(td); // time to analyze the selection Class clazz = selection.getClass(); StringBuffer buffer = new StringBuffer(); buffer.append("<form>"); //$NON-NLS-1$ buffer.append(toolkit.createClassSection(text, MDERuntimeMessages.SpyDialog_activeSelection_desc, new Class[] { clazz })); Class[] interfaces = clazz.getInterfaces(); buffer.append(toolkit.createInterfaceSection(text, MDERuntimeMessages.SpyDialog_activeSelectionInterfaces_desc, interfaces)); if (selection instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) selection; int size = ss.size(); if (size == 1) { clazz = ss.getFirstElement().getClass(); buffer.append(toolkit.createClassSection(text, MDERuntimeMessages.SpyDialog_activeSelectedElement_desc, new Class[] { clazz })); interfaces = clazz.getInterfaces(); buffer.append(toolkit.createInterfaceSection(text, MDERuntimeMessages.SpyDialog_activeSelectedElementInterfaces_desc, interfaces)); } else if (size > 1) { buffer.append(NLS.bind(MDERuntimeMessages.SpyDialog_activeSelectedElementsCount_desc, new Integer(size))); } } buffer.append("</form>"); //$NON-NLS-1$ text.setText(buffer.toString(), true, false); } }
From source file:com.siteview.mde.internal.ui.editor.build.BuildClasspathSection.java
License:Open Source License
protected void selectionChanged(IStructuredSelection selection) { getPage().getMDEEditor().setSelection(selection); getTablePart().setButtonEnabled(1, selection != null && selection.size() > 0 && fEnabled); }
From source file:com.siteview.mde.internal.ui.editor.build.RuntimeInfoSection.java
License:Open Source License
private void doRename() { IStructuredSelection selection = (IStructuredSelection) fLibraryViewer.getSelection(); if (selection.size() == 1) { IBuildEntry entry = (IBuildEntry) selection.getFirstElement(); String oldName = entry.getName().substring(7); RenameDialog dialog = new RenameDialog(fLibraryViewer.getControl().getShell(), true, getLibraryNames(), oldName);/*w w w.j a va2 s .c o m*/ dialog.setInputValidator(new IInputValidator() { public String isValid(String newText) { if (newText.indexOf(' ') != -1) return MDEUIMessages.AddLibraryDialog_nospaces; return null; } }); dialog.create(); dialog.setTitle(MDEUIMessages.RuntimeInfoSection_rename); dialog.getShell().setSize(300, 150); if (dialog.open() == Window.OK) entryModified(entry, dialog.getNewName()); } }
From source file:com.siteview.mde.internal.ui.editor.feature.DataSection.java
License:Open Source License
private void handleDelete() { IStructuredSelection ssel = (IStructuredSelection) fDataViewer.getSelection(); if (ssel.isEmpty()) return;/* ww w . java 2 s .c om*/ IFeatureModel model = (IFeatureModel) getPage().getModel(); if (!model.isEditable()) { return; } IFeature feature = model.getFeature(); try { IFeatureData[] removed = new IFeatureData[ssel.size()]; int i = 0; for (Iterator iter = ssel.iterator(); iter.hasNext();) { IFeatureData iobj = (IFeatureData) iter.next(); removed[i++] = iobj; } feature.removeData(removed); } catch (CoreException e) { MDEPlugin.logException(e); } }
From source file:com.siteview.mde.internal.ui.editor.feature.IncludedFeaturesSection.java
License:Open Source License
private void handleDelete() { IStructuredSelection ssel = (IStructuredSelection) fIncludesViewer.getSelection(); if (ssel.isEmpty()) return;/*from ww w . j ava 2 s .c o m*/ IFeatureModel model = (IFeatureModel) getPage().getModel(); if (!model.isEditable()) { return; } IFeature feature = model.getFeature(); try { IFeatureChild[] removed = new IFeatureChild[ssel.size()]; int i = 0; for (Iterator iter = ssel.iterator(); iter.hasNext();) { IFeatureChild iobj = (IFeatureChild) iter.next(); removed[i++] = iobj; } feature.removeIncludedFeatures(removed); } catch (CoreException e) { MDEPlugin.logException(e); } }