List of usage examples for org.eclipse.jface.viewers IStructuredSelection iterator
@Override
public Iterator iterator();
From source file:com.nokia.carbide.cdt.builder.CarbideBuilderPlugin.java
License:Open Source License
/** * A utility function. Gets the owning project(s) of the selected object(s) if any * @param selection the current selection * @return a list of projects - may be empty *//*from w w w. ja v a2 s . c om*/ public static List<IProject> getProjectsFromSelection(ISelection selection) { List<IProject> projects = new ArrayList<IProject>(); if (selection != null && !selection.isEmpty()) { if (selection instanceof ITextSelection) { IWorkbenchWindow activeWindow = getDefault().getWorkbench().getActiveWorkbenchWindow(); ; IWorkbenchPage wpage = activeWindow.getActivePage(); if (wpage != null) { IEditorPart ep = wpage.getActiveEditor(); if (ep != null) { IEditorInput editorInput = ep.getEditorInput(); if (editorInput instanceof IFileEditorInput) { IFile file = ((IFileEditorInput) editorInput).getFile(); if (file != null) { projects.add(file.getProject()); } } } } } else if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; for (Iterator iter = structuredSelection.iterator(); iter.hasNext();) { Object element = (Object) iter.next(); if (element != null) { if (element instanceof ICProject) { projects.add(((ICProject) element).getProject()); } else if (element instanceof IResource) { projects.add(((IResource) element).getProject()); } else if (element instanceof ICElement) { ICElement unit = (ICElement) element; // Get parent of the Element until we reach the owner project. while (unit != null && !(unit instanceof ICProject)) unit = unit.getParent(); if (unit != null) { projects.add(((ICProject) unit).getProject()); } } else if (element instanceof IAdaptable) { Object adapter = ((IAdaptable) element).getAdapter(IResource.class); if (adapter != null && adapter instanceof IResource) { projects.add(((IResource) adapter).getProject()); } else { adapter = ((IAdaptable) element).getAdapter(ICProject.class); if (adapter != null && adapter instanceof ICProject) { projects.add(((ICProject) adapter).getProject()); } } } } } } } return projects; }
From source file:com.nokia.carbide.cdt.internal.api.builder.ui.MMPSelectionUI.java
License:Open Source License
/** * Create the composite//from w ww . ja va 2 s . c o m * @param parent * @param style */ public MMPSelectionUI(Composite parent, int style, IRunnableContext runnableContext) { super(parent, style); this.runnableContext = runnableContext; // layout self final GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 2; gridLayout.marginBottom = 5; gridLayout.marginRight = 10; gridLayout.marginLeft = 10; setLayout(gridLayout); // viewer viewer = CheckboxTableViewer.newCheckList(this, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION); viewer.setContentProvider(new ArrayContentProvider()); viewer.setLabelProvider(new LabelProvider()); Table table = viewer.getTable(); table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); table.setData(AUTOTEST_UID, "table"); //$NON-NLS-1$ // build order column TableColumn buildOrderColumn = new TableColumn(table, SWT.NONE); // alignment ignored when checkboxes in column buildOrderColumn.setText(Messages.getString("MMPSelectionUI.BuildOrderColumnLabel")); //$NON-NLS-1$ buildOrderColumn.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { updateSortDirection(BUILD_ORDER_COLUMN); ViewerComparator comparator = getViewerComparator(BUILD_ORDER_COLUMN); viewer.setComparator(comparator); setColumnSorting((TableColumn) e.getSource(), sortDirection); } }); buildOrderColumn.setData(AUTOTEST_UID, "buildOrderColumn"); //$NON-NLS-1$ // file name column TableColumn fileNameColumn = new TableColumn(table, SWT.LEFT); fileNameColumn.setText(Messages.getString("MMPSelectionUI.FileNameColumnLabel")); //$NON-NLS-1$ fileNameColumn.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { updateSortDirection(FILENAME_COLUMN); ViewerComparator comparator = getViewerComparator(FILENAME_COLUMN); viewer.setComparator(comparator); setColumnSorting((TableColumn) e.getSource(), sortDirection); } }); fileNameColumn.setData(AUTOTEST_UID, "fileNameColumn"); //$NON-NLS-1$ // location column final TableColumn locationColumn = new TableColumn(table, SWT.LEFT); locationColumn.setText(Messages.getString("MMPSelectionUI.LocationColumnLabel")); //$NON-NLS-1$ locationColumn.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { updateSortDirection(LOCATION_COLUMN); ViewerComparator comparator = getViewerComparator(LOCATION_COLUMN); viewer.setComparator(comparator); setColumnSorting((TableColumn) e.getSource(), sortDirection); } }); locationColumn.setData(AUTOTEST_UID, "locationColumn"); //$NON-NLS-1$ setColumnSorting(buildOrderColumn, sortDirection); table.setHeaderVisible(true); // listen to checks viewer.addCheckStateListener(new ICheckStateListener() { public void checkStateChanged(CheckStateChangedEvent event) { FileInfo info = (FileInfo) event.getElement(); info.setChecked(event.getChecked()); fireSelectionChanged(); } }); // listen to double clicks viewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); for (Iterator iterator = selection.iterator(); iterator.hasNext();) { FileInfo info = (FileInfo) iterator.next(); info.setChecked(!info.isChecked()); viewer.setChecked(info, info.isChecked()); fireSelectionChanged(); } } }); // select all/deselect all buttons final Composite composite = new Composite(this, SWT.NONE); composite.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false)); composite.setLayout(new GridLayout()); selectAllButton = new Button(composite, SWT.NONE); selectAllButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); selectAllButton.setText(Messages.getString("MMPSelectionUI.SelectAllLabel")); //$NON-NLS-1$ selectAllButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { setAllChecked(true); } }); selectAllButton.setData(AUTOTEST_UID, "selectAllButton"); //$NON-NLS-1$ deselectAllButton = new Button(composite, SWT.NONE); deselectAllButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); deselectAllButton.setText(Messages.getString("MMPSelectionUI.DeselectAllLabel")); //$NON-NLS-1$ deselectAllButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { setAllChecked(false); } }); deselectAllButton.setData(AUTOTEST_UID, "deselectAllButton"); //$NON-NLS-1$ // exclude extension makefiles check box excludeExtensionMakefilesCheckbox = new Button(this, SWT.CHECK); excludeExtensionMakefilesCheckbox.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1)); excludeExtensionMakefilesCheckbox.setText(Messages.getString("MMPSelectionUI.ExcludeExtMakefilesLabel")); //$NON-NLS-1$ excludeExtensionMakefilesCheckbox.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { boolean exclude = ((Button) e.getSource()).getSelection(); if (extMakFileFilter == null) { extMakFileFilter = new ViewerFilter() { @Override public boolean select(Viewer viewer, Object parentElement, Object element) { FileInfo info = (FileInfo) element; boolean select = info.isMMP(); if (!select) info.setChecked(false); return select; } }; } if (exclude) { viewer.addFilter(extMakFileFilter); fireSelectionChanged(); } else { viewer.removeFilter(extMakFileFilter); } updateCheckedStateFromViewer(); } }); excludeExtensionMakefilesCheckbox.setData(AUTOTEST_UID, "excludeExtensionMakefilesCheckbox"); //$NON-NLS-1$ // exclude test components checkbox excludeTestComponentsCheckbox = new Button(this, SWT.CHECK); excludeTestComponentsCheckbox.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1)); excludeTestComponentsCheckbox.setText(Messages.getString("MMPSelectionUI.ExcludeTestCompsLabel")); //$NON-NLS-1$ excludeTestComponentsCheckbox.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { boolean exclude = ((Button) e.getSource()).getSelection(); if (testFileFilter == null) { testFileFilter = new ViewerFilter() { @Override public boolean select(Viewer viewer, Object parentElement, Object element) { FileInfo info = (FileInfo) element; boolean select = !info.isTest(); if (!select) info.setChecked(false); return select; } }; } if (exclude) { viewer.addFilter(testFileFilter); fireSelectionChanged(); } else { viewer.removeFilter(testFileFilter); } updateCheckedStateFromViewer(); } }); excludeTestComponentsCheckbox.setData(AUTOTEST_UID, "excludeTestComponentsCheckbox"); //$NON-NLS-1$ }
From source file:com.nokia.carbide.cdt.internal.api.builder.ui.MMPSelectionUI.java
License:Open Source License
/** * Expects structured selection FileInfos from which will update checked state * FileInfos must be those received from getSelection() * @see org.eclipse.jface.viewers.ISelectionProvider#getSelection() * @see org.eclipse.jface.viewers.ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection) *//*from ww w.j ava 2 s . c o m*/ public void setSelection(ISelection selection) { Check.checkState(selection instanceof IStructuredSelection); IStructuredSelection structuredSelection = (IStructuredSelection) selection; for (Iterator iterator = structuredSelection.iterator(); iterator.hasNext();) { Object element = iterator.next(); Check.checkContract(element instanceof FileInfo); FileInfo info = (FileInfo) element; viewer.setChecked(info, info.isChecked()); } }
From source file:com.nokia.carbide.cdt.internal.builder.ui.CarbideCPPProjectSettingsPage.java
License:Open Source License
private void initMMPSelectionUI(CarbideProjectInfo cpi) { selectionUI.setToolTipText(//w ww . ja v a 2 s .co m Messages.getString("CarbideCPPProjectSettingsPage.checked_items_are_built_tooltip")); //$NON-NLS-1$ // set layout data final GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); gridData.widthHint = 270; gridData.heightHint = 190; selectionUI.setLayoutData(gridData); // set the data List<ISymbianBuildContext> buildContexts = new ArrayList<ISymbianBuildContext>(); for (ICarbideBuildConfiguration config : cpi.getBuildConfigurations()) { buildContexts.add(config.getBuildContext()); } selectionUI.setBldInfFile(cpi.getAbsoluteBldInfPath(), buildContexts, CarbideBuilderPlugin.getBuildManager().isCarbideSBSv2Project(cpi.getProject())); // set checked state selectionUI.setAllChecked(false); IStructuredSelection selection = (IStructuredSelection) selectionUI.getSelection(); // Get the list of components from INF file that are to be built, these are the checked elements List<String> infCheckedComponentsList = cpi.getInfBuildComponentsRawSettings(); for (String compstr : infCheckedComponentsList) { if (compstr.endsWith(ICarbideProjectInfo.TEST_COMPONENT_LABEL)) { // remove the test component label and space! compstr = compstr.substring(0, compstr.length() - ICarbideProjectInfo.TEST_COMPONENT_LABEL.length() - 1); } IPath path = new Path(compstr); for (Iterator iterator = selection.iterator(); iterator.hasNext();) { FileInfo info = (FileInfo) iterator.next(); if (info.hasPath(path)) { info.setChecked(true); } } } selectionUI.setSelection(selection); }
From source file:com.nokia.carbide.cdt.internal.builder.ui.CarbideCPPProjectSettingsPage.java
License:Open Source License
private List<String> getCheckedComponentFilenames() { List<String> componentFileNames = new ArrayList<String>(); IStructuredSelection selection = (IStructuredSelection) selectionUI.getSelection(); for (Iterator iterator = selection.iterator(); iterator.hasNext();) { FileInfo info = (FileInfo) iterator.next(); if (info.isChecked()) componentFileNames.add(//from w w w .j a va 2 s. c o m info.getFileName() + (info.isTest() ? " " + ICarbideProjectInfo.TEST_COMPONENT_LABEL : "")); //$NON-NLS-1$ //$NON-NLS-2$ } return componentFileNames; }
From source file:com.nokia.carbide.cdt.internal.builder.ui.MMPChangedActionDialog.java
License:Open Source License
@SuppressWarnings("unchecked") private void setSelectedMMPsAction(int action) { // remove any editors Control oldEditor = tableEditor.getEditor(); if (oldEditor != null) { oldEditor.dispose();/*from w ww. j ava 2s . c o m*/ } IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection(); for (Iterator iter = selection.iterator(); iter.hasNext();) { ((MMPChangedAction) iter.next()).mmpAction = action; } tableViewer.refresh(); }
From source file:com.nokia.carbide.cdt.internal.builder.ui.SisFilesBlock.java
License:Open Source License
private void removeFiles() { IStructuredSelection selection = (IStructuredSelection) fFileList.getSelection(); ISISBuilderInfo[] files = new ISISBuilderInfo[selection.size()]; Iterator iter = selection.iterator(); int i = 0;//from w ww .j a va2 s. c o m while (iter.hasNext()) { files[i] = (ISISBuilderInfo) iter.next(); i++; } removeFiles(files); }
From source file:com.nokia.carbide.cpp.internal.project.ui.importWizards.MMPSelectionPage.java
License:Open Source License
public List<String> getSelectedMakMakeReferences() { List<String> names = new ArrayList<String>(); IStructuredSelection selection = (IStructuredSelection) selectionUI.getSelection(); for (Iterator iterator = selection.iterator(); iterator.hasNext();) { FileInfo info = (FileInfo) iterator.next(); if (info.isChecked()) { String name = info.getFileName(); if (info.isTest()) name += " " + ICarbideProjectInfo.TEST_COMPONENT_LABEL; //$NON-NLS-1$ names.add(name);// ww w. j a va 2 s . c o m } } return names; }
From source file:com.nokia.carbide.cpp.internal.project.ui.mmpEditor.dialogs.AddLibraryDialog.java
License:Open Source License
@Override protected void okPressed() { libraryNames = new ArrayList<String>(); String customName = libraryTextControl.getText(); ISelection selection = libraryViewer.getSelection(); if (selection.isEmpty()) { if (customName.length() > 0) { libraryNames.add(customName); }/* w w w. jav a 2s . c om*/ } else { if (selection instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) selection; for (Iterator iter = ss.iterator(); iter.hasNext();) { libraryNames.add(iter.next().toString()); } } } super.okPressed(); }
From source file:com.nokia.carbide.cpp.internal.project.ui.mmpEditor.MissingSourcesSectionPart.java
License:Open Source License
protected void removeButtonPressed() { List<Integer> indices = new ArrayList<Integer>(); List sourceList = EMMPListSelector.SOURCES.fetchList(editorContext.mmpView); IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection(); Iterator iter = selection.iterator(); while (iter.hasNext()) { int index = sourceList.indexOf(iter.next()); if (index >= 0) { indices.add(index);//from w ww. j a va2 s.co m } } RemoveListValueOperation command = new RemoveListValueOperation(editorContext.mmpView, new FormEditorEditingContext(editorContext.editor, tableViewer.getControl()), ControlHandler.getHandlerForViewer(tableViewer), EMMPListSelector.SOURCES, indices); editorContext.executeOperation(command); missingFilePaths.removeAll(selection.toList()); tableViewer.refresh(); }