List of usage examples for org.eclipse.jface.viewers StructuredSelection toList
@Override
public List toList()
From source file:net.sourceforge.tagsea.mylyn.task.TaskUtils.java
License:Open Source License
public static List<IMarker> getTasks(StructuredSelection selection) { List<IMarker> tasks = new ArrayList<IMarker>(); try {//w w w . j av a 2s . c o m for (IMarker marker : (List<IMarker>) selection.toList()) { if (marker.isSubtypeOf(IMarker.TASK)) { tasks.add(marker); } } } catch (CoreException e) { // TODO Better logging technique System.err.println("Core exception occurred while creating new task."); } return tasks; }
From source file:net.sourceforge.tagsea.mylyn.todo.TodoUtils.java
License:Open Source License
public static List<IMarker> getTodos(StructuredSelection selection) { List<IMarker> todos = new ArrayList<IMarker>(); try {/*from w w w . j a v a2 s .co m*/ for (IMarker marker : (List<IMarker>) selection.toList()) { if (marker.isSubtypeOf(IMarker.TASK)) { todos.add(marker); } } } catch (CoreException e) { // TODO Better logging technique System.err.println("Core exception occurred while creating new task."); } return todos; }
From source file:net.tourbook.preferences.TagDropAdapter.java
License:Open Source License
@Override public boolean performDrop(final Object dropData) { boolean returnValue = false; /*// w w w . ja va 2 s. c o m * check if drag was startet from this tree */ if (LocalSelectionTransfer.getTransfer().getSelectionSetTime() != _prefPageTags.getDragStartTime()) { return false; } if (dropData instanceof StructuredSelection) { final StructuredSelection selection = (StructuredSelection) dropData; final Object firstElement = selection.getFirstElement(); if (selection.size() == 1 && firstElement instanceof TVIPrefTagCategory) { /* * drop a category, to avoid confusion only one category is supported to be dragged * & dropped */ returnValue = dropCategory((TVIPrefTagCategory) firstElement); } else { // drop all tags, categories will be ignored for (final Object element : selection.toList()) { if (element instanceof TVIPrefTag) { returnValue |= dropTag((TVIPrefTag) element); } } } if (returnValue) { _prefPageTags.setIsModified(); } } return returnValue; }
From source file:no.sintef.bvr.papyrusdiagram.adapter.PapyrusBVREditorAdapter.java
License:LGPL
@Override public List<Object> getSelectedObjects() { ISelection selection = editor.getSite().getSelectionProvider().getSelection(); StructuredSelection structuredSelection = (StructuredSelection) selection; return structuredSelection.toList(); }
From source file:no.sintef.bvr.papyrusdiagramadapter2.editors.PapyrusBVREditor.java
License:LGPL
@Override public List<Object> getSelectedObjects() { ISelection selection = getSite().getSelectionProvider().getSelection(); StructuredSelection structuredSelection = (StructuredSelection) selection; return structuredSelection.toList(); }
From source file:no.sintef.bvr.tool.context.ThirdpartyEditorSelector.java
License:LGPL
@Override public List<Object> getSelections() { IEditorPart activeEditor = workbenchWindow.getActivePage().getActiveEditor(); if (activeEditor == null) { Context.eINSTANCE.logger.debug("can not find any active aditor in the ActivePage of the workbench"); return new ArrayList<Object>(); }/*from ww w .ja v a 2s . c om*/ IBVREnabledEditor bvrEnabledEditor = (IBVREnabledEditor) Platform.getAdapterManager() .getAdapter(activeEditor, IBVREnabledEditor.class); if (bvrEnabledEditor != null) { Context.eINSTANCE.logger .debug("found suitabale adapter: " + bvrEnabledEditor + " for the editor: " + activeEditor); return bvrEnabledEditor.getSelectedObjects(); } if (activeEditor instanceof IBVREnabledEditor) { Context.eINSTANCE.logger.debug("editor implements IBVREnabledEditor: " + activeEditor); return ((IBVREnabledEditor) activeEditor).getSelectedObjects(); } if (activeEditor.getSite().getSelectionProvider() == null) { Context.eINSTANCE.logger .debug("can not find selection provider for editor, nothing to grab from selection, editor: " + activeEditor); return new ArrayList<Object>(); } Context.eINSTANCE.logger .debug("using default selection provider to grab selected elements, editor: " + activeEditor); ISelection selection = activeEditor.getSite().getSelectionProvider().getSelection(); StructuredSelection structuredSelection = (StructuredSelection) selection; return structuredSelection.toList(); }
From source file:org.csstudio.utility.adlconverter.ui.ADLConverterMainView.java
License:Open Source License
/** * @param sourceGroup/* ww w . j a v a2 s .co m*/ * the Parent composite. * @param initial * The Workspace resource. */ private void generateSourceBlock(final Group sourceGroup, final IResource initial) { GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1); gridData.minimumWidth = 40; gridData.minimumHeight = 40; _avaibleFiles = new ListViewer(sourceGroup); _avaibleFiles.getList().setLayoutData(gridData); _avaibleFiles.setContentProvider(new ArrayContentProvider()); _avaibleFiles.setLabelProvider(new LabelProvider()); makeMenu(); gridData = new GridData(SWT.FILL, SWT.FILL, true, false, 4, 1); gridData.minimumWidth = 40; gridData.minimumHeight = 40; Composite buttonComposite = new Composite(sourceGroup, SWT.NONE); buttonComposite.setLayoutData(gridData); // buttonComposite.setLayoutData(GridDataFactory.fillDefaults().span(4, // 1).create()); buttonComposite.setLayout(new RowLayout()); Button openSourceButton = new Button(buttonComposite, SWT.PUSH); openSourceButton.setLayoutData(new RowData(80, 25)); openSourceButton.setText(Messages.ADLConverterMainView_ADLSourceFileDialogButton); Button subFolderButton = new Button(buttonComposite, SWT.PUSH); subFolderButton.setLayoutData(new RowData(80, 25)); subFolderButton.setText(Messages.ADLConverterMainView_ADLSourceFolderDialogButton); Button clearSourceButton = new Button(buttonComposite, SWT.PUSH); clearSourceButton.setText(Messages.ADLConverterMainView_ClearButtonText); RowData rowData = new RowData(80, 25); clearSourceButton.setLayoutData(rowData); final Button convertButton = new Button(buttonComposite, SWT.PUSH); convertButton.setText(Messages.ADLConverterMainView_ConvcertButtonText); rowData = new RowData(80, 25); convertButton.setLayoutData(rowData); final Button generateFpButton = new Button(buttonComposite, SWT.PUSH); generateFpButton.setText("Faceplates"); rowData = new RowData(80, 25); generateFpButton.setLayoutData(rowData); // Listener openSourceButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { FileDialog dialog = new FileDialog(_shell, SWT.MULTI); String[] names = new String[] { Messages.ADLConverterMainView_BothFileSourceDialogFileDes, Messages.ADLConverterMainView_ADLFileSourceDialogFileDes, Messages.ADLConverterMainView_MDPFileSourceDialogFileDes, Messages.ADLConverterMainView_STCFileSourceDialogFileDes, Messages.ADLConverterMainView_AllFileSourceDialogFileDes }; dialog.setFilterNames(names); String[] ext = new String[] { "*.adl;*.mfp;*.stc", "*.adl", "*.mfp", "*.stc", "*.*" }; // Windows wild cards //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5 dialog.setFilterExtensions(ext); String path = _preferences.getString(ADLConverterPreferenceConstants.P_STRING_Path_Source); dialog.setFilterPath(path); dialog.open(); path = dialog.getFilterPath(); String[] files = dialog.getFileNames(); for (String name : files) { _avaibleFilesList.add(new File(path, name)); } setAvaibleFilesInput(); _avaibleFiles.getList().selectAll(); refreshexamplePathLabel(); checkRelativPath(); } }); subFolderButton.addSelectionListener(new SelectionListener() { @Override public void widgetDefaultSelected(SelectionEvent e) { // TODO Auto-generated method stub } @Override public void widgetSelected(SelectionEvent e) { final DirectoryDialog dialog = new DirectoryDialog(_shell, SWT.MULTI); String path = _preferences.getString(ADLConverterPreferenceConstants.P_STRING_Path_Source); // path = initial.getProjectRelativePath().toOSString(); System.out.println("Path_: " + path); //$NON-NLS-1$ dialog.setFilterPath(path); String open = dialog.open(); if (open == null) { return; } Job job = new Job("ADL File Reader") { @Override protected IStatus run(IProgressMonitor monitor) { monitor.beginTask("ADL FileReader Worker", -1); try { final String filterPath = dialog.getFilterPath(); File file = new File(filterPath); fillFiles(file); PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { @Override public void run() { _avaibleFiles.setInput(_avaibleFilesList); _avaibleFiles.getList().selectAll(); refreshexamplePathLabel(); checkRelativPath(); _preferences.setValue(ADLConverterPreferenceConstants.P_STRING_Path_Source, filterPath); } }); monitor.done(); } catch (Exception e1) { LOG.error("Error: ", e1); monitor.setCanceled(true); return Status.CANCEL_STATUS; } return Status.OK_STATUS; } }; job.setUser(true); job.schedule(); } protected void fillFiles(File file) { String[] list = file.list(new FilenameFilter() { @Override public boolean accept(File dir, String name) { if (name.endsWith(".adl") || name.endsWith(".mfp") || name.endsWith(".stc")) { //$NON-NLS-1$ return true; } File file2 = new File(dir, name); return file2.isDirectory(); } }); if (list != null) { for (String name : list) { File element = new File(file, name); if (element.isFile()) { _avaibleFilesList.add(element); } else { fillFiles(element); } } } } }); clearSourceButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { _avaibleFilesList.clear(); setAvaibleFilesInput(); setPathPos(0); } }); convertButton.addSelectionListener(new SelectionAdapter() { @Override @SuppressWarnings("unchecked") //$NON-NLS-1$ public void widgetSelected(final SelectionEvent e) { StructuredSelection sel = (StructuredSelection) _avaibleFiles.getSelection(); final ArrayList<Object> list = new ArrayList<Object>(sel.toList()); Job job = new Job("Convert ADL Files") { @Override protected IStatus run(final IProgressMonitor monitor) { final int startSize = list.size(); int adlCount = 0; int mpfCout = 0; int stcCount = 0; DebugHelper.clear(); monitor.beginTask("Start Convert Files", startSize); ADLDisplayImporter.reset(); while (list.size() > 0) { final ADLDisplayImporter di = new ADLDisplayImporter(); final File file = (File) list.remove(0); // IPath targetProject; String format = String.format("Convert File: %1$40s\t(%2$4d/%3$4d)", file.getName(), +(startSize - list.size()), startSize); monitor.setTaskName(format); // monitor.setTaskName("Convert File: "+file.getName()+"\t("+(startSize-list.size())+"/"+startSize+")"); final SelectContainer selection = new SelectContainer(); PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { @Override public void run() { selection.setBool(_isRelativePath.getSelection()); } }); if (selection.getBool()) { selection.setiPath(getRelativPath(file).removeLastSegments(1)); } else { selection.setiPath(initial.getProjectRelativePath().append(_targetPath)); } try { if (file.getName().endsWith(".adl")) {//$NON-NLS-1$ adlCount++; PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { @Override public void run() { try { if (!di.importDisplay(file.getAbsolutePath(), selection.getiPath(), file.getName().replace(".adl", ".css-sds"))) { //$NON-NLS-1$ //$NON-NLS-2$ } } catch (CoreException e1) { // TODO Auto-generated // catch block LOG.error("Error: ", e1); } } }); if (di.getStatus() == 5) { // Job is canceled. break; } } else if (file.getName().endsWith(".mfp")) {//$NON-NLS-1$ mpfCout++; PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { @Override public void run() { try { if (!di.importFaceplate(file.getAbsolutePath(), selection.getiPath(), file.getName().concat(".css-sds"))) { //$NON-NLS-1$ //$NON-NLS-2$ } } catch (CoreException ce) { // TODO Auto-generated // catch block LOG.error("Error: ", ce); } } }); if (di.getStatus() == 5) { // Job is canceled. break; } } else if (file.getName().endsWith(".stc")) {//$NON-NLS-1$ stcCount++; PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { @Override public void run() { // parse Strip Tool Files try { if (!di.importStripTool(file.getAbsolutePath(), selection.getiPath(), file.getName().replace(".stc", ".css-plt"))) { //$NON-NLS-1$ //$NON-NLS-2$ } } catch (CoreException ce) { // TODO Auto-generated // catch block LOG.error("Error: ", ce); } catch (IOException ioE) { // TODO Auto-generated // catch block LOG.error("Error: ", ioE); } } }); if (di.getStatus() == 5) { // Job is canceled. break; } } } catch (Exception e1) { LOG.error("Error: ", e1); } // file = null; PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { @Override public void run() { _avaibleFiles.setSelection(new StructuredSelection(list), true); _avaibleFiles.getList().getParent().layout(); } }); monitor.worked(1); } DebugHelper.showAll(); DebugHelper.showPath(); DebugHelper.showWithoutPath(); DebugHelper.showAllCaller(); DebugHelper.showPathCaller(); DebugHelper.closeLogFile(); final int adlCount2 = adlCount; final int mpfCount2 = mpfCout; final int stcCount2 = stcCount; PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { @Override public void run() { MessageDialog.openInformation(convertButton.getShell(), "Finish", String.format( "Es waren %1$s Datein Ausgewhlt.\r\n" + "Es wurden \r\n" + "\tADL Files:\t%2$4s\r\n" + "\tMPF Files:\t%3$4s\r\n" + "\tSTC Files:\t%4$4s\r\n" + "Convertiert", startSize, adlCount2, mpfCount2, stcCount2)); } }); return Status.OK_STATUS; } }; job.setUser(true); job.schedule(); } }); generateFpButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { Creator.createDisplays(); } }); }
From source file:org.eclipse.birt.chart.reportitem.ui.dialogs.ChartCubeFilterConditionBuilder.java
License:Open Source License
protected void checkEditDelButtonStatus() { if (tableViewer == null || table.isDisposed()) { return;/*from w w w.j a v a 2s.co m*/ } boolean enabled = (tableViewer.getSelection() == null) ? false : true; if (enabled == true && tableViewer.getSelection() instanceof StructuredSelection) { StructuredSelection selection = (StructuredSelection) tableViewer.getSelection(); if (selection.toList().size() <= 0) { enabled = false; } } editBtn.setEnabled(enabled); delBtn.setEnabled(enabled); enabled = table.getItemCount() > 0 ? true : false; delAllBtn.setEnabled(enabled); }
From source file:org.eclipse.birt.report.designer.internal.ui.editors.parts.GraphicalEditorWithFlyoutPalette.java
License:Open Source License
private List getModelList(ISelection selection) { List list = new ArrayList(); if (selection == null) return list; if (!(selection instanceof StructuredSelection)) return list; StructuredSelection structured = (StructuredSelection) selection; if (structured.getFirstElement() instanceof ReportElementEditPart) { boolean bool = false; for (Iterator it = structured.iterator(); it.hasNext();) { ReportElementEditPart object = (ReportElementEditPart) it.next(); if (object instanceof DummyEditpart) { list.add(object.getModel()); bool = true;//ww w. ja v a2 s. c o m } if (!bool) { list.add(object.getModel()); } } } else { list = structured.toList(); } return list; }
From source file:org.eclipse.birt.report.designer.internal.ui.editors.parts.TableCellKeyDelegate.java
License:Open Source License
/** * Finds the appropriate Table Cell siblings when SHIFT is pressed. * /*from w w w . j a v a2 s . co m*/ * @param siblings * @param pStart * @param direction * @param exclude * @return */ protected List findTableCellSiblings(List siblings, Point pStart, int direction, EditPart exclude) { AbstractCellEditPart start = (AbstractCellEditPart) exclude; AbstractTableEditPart parent = (AbstractTableEditPart) start.getParent(); StructuredSelection selection = (StructuredSelection) getViewer().getSelection(); Object obj = selection.getFirstElement(); if (obj instanceof AbstractCellEditPart) { AbstractCellEditPart first = (AbstractCellEditPart) obj; Rectangle constraint = TableCellSelectionHelper.getSelectionRectangle(first, selection.toList()); boolean refined = TableCellSelectionHelper.increaseSelectionRectangle(constraint, parent); while (refined) { refined = TableCellSelectionHelper.increaseSelectionRectangle(constraint, parent); } translateRectangle(parent, constraint, direction); alterRectangle(constraint, direction, parent); return TableCellSelectionHelper.getRectangleSelection(constraint, parent); } return NULL_LIST; }