List of usage examples for org.eclipse.jface.viewers StructuredSelection toArray
@Override
public Object[] toArray()
From source file:com.nokia.tools.variant.editor.actions.AddSequenceItemAction.java
License:Open Source License
@Override public void run() { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); if (page != null) { IEditorPart activeEditor = page.getActiveEditor(); CPFEditor editor = null;//from ww w .j a va2 s . c o m if (activeEditor != null && activeEditor instanceof CPFEditor) { editor = (CPFEditor) activeEditor; CommandStack commandStack = editor.getCommandStack(); ISelection selection = editor.getSelection(); int position = -1; if (selection instanceof StructuredSelection) { StructuredSelection structuredSelection = (StructuredSelection) selection; Object[] selections = structuredSelection.toArray(); for (int i = 0; i < selections.length; i++) { Object next = selections[i]; if (next instanceof Setting) { Setting setting = (Setting) next; EObject container = setting.eContainer(); if (container instanceof SequenceItem) { SequenceItem si = (SequenceItem) setting.eContainer(); SequenceSetting sqSetting = (SequenceSetting) si.eContainer(); int index = sqSetting.getSequenceItem().indexOf(si); if (position < index) { position = index; } } } } } Object data = widget.getData(); ((SequenceWidget) widget).setCollapsed(false); if (data instanceof UISetting) { UISetting uiSetting = (UISetting) data; Setting setting = uiSetting.getSetting(); int realPosition = 0; if (setting instanceof SequenceSetting) { SequenceSetting ss = (SequenceSetting) setting; SequenceItem template = ss.getTemplate(); if (template == null && ss.getSequenceItem().size() > 0) { template = ss.getSequenceItem().get(0); } if (template == null && ss.getDefaultStructure().size() > 0) { template = ss.getDefaultStructure().get(0); } if (template != null) { SequenceItem copy = (SequenceItem) EcoreUtil.copy(template); realPosition = (position == -1) ? ss.getSequenceItem().size() : position + 1; Command addCommand = new AddSequenceItemCommand(ss, copy, realPosition); commandStack.execute(addCommand); } else { MessageDialog.openWarning(widget.getShell(), "Warning", "Sequence setting doesn't have tepmlate or any data."); } Setting settingToSelect = ss.getSequenceItem().get(realPosition).getSetting().get(0); StructuredSelection structuredSelection = new StructuredSelection(settingToSelect); editor.setSelection(structuredSelection); } } } } }
From source file:com.nokia.tools.variant.editor.actions.RemoveSequenceItemsAction.java
License:Open Source License
@Override public void run() { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); if (page != null) { IEditorPart activeEditor = page.getActiveEditor(); if (activeEditor != null && activeEditor instanceof CPFEditor) { CPFEditor editor = (CPFEditor) activeEditor; CommandStack commandStack = editor.getCommandStack(); ISelection selection = editor.getEditorSite().getSelectionProvider().getSelection(); if (selection instanceof StructuredSelection) { StructuredSelection sel = (StructuredSelection) selection; Object[] selections = sel.toArray(); Set<SequenceItem> items2remove = new HashSet<SequenceItem>(); SequenceSetting parentSq = null; for (int i = 0; i < selections.length; i++) { Object object = selections[i]; if (object instanceof SimpleSetting) { SimpleSetting ss = (SimpleSetting) object; EObject ssParent = ss.eContainer(); SequenceSetting sqSetting = remove(items2remove, ssParent, parentSq); if (parentSq == null) { parentSq = sqSetting; }//w w w .j av a 2 s . c o m } else if (object instanceof FileSystemEntrySetting) { if (object instanceof FilePath) { FilePath ss = (FilePath) object; EObject ssParent = ss.eContainer().eContainer(); SequenceSetting sqSetting = remove(items2remove, ssParent, parentSq); if (parentSq == null) { parentSq = sqSetting; } } else { FileSystemEntrySetting fses = (FileSystemEntrySetting) object; EObject fsesParent = fses.eContainer(); SequenceSetting sqSetting = remove(items2remove, fsesParent, parentSq); if (parentSq == null) { parentSq = sqSetting; } } } if (object instanceof FilePath) { FilePath ss = (FilePath) object; EObject ssParent = ss.eContainer(); SequenceSetting sqSetting = remove(items2remove, ssParent, parentSq); if (parentSq == null) { parentSq = sqSetting; } } } if (parentSq != null) { commandStack.execute(new RemoveSequenceItemsCommand(parentSq, items2remove)); } } } } }
From source file:com.redhat.ceylon.eclipse.code.open.FilteredItemsSelectionDialog.java
License:Open Source License
/** * Handle selection in the items list by updating labels of selected and * unselected items and refresh the details field using the selection. * //w ww.ja v a 2 s . com * @param selection * the new selection */ protected void handleSelected(StructuredSelection selection) { IStatus status = new Status(IStatus.OK, PlatformUI.PLUGIN_ID, IStatus.OK, EMPTY_STRING, null); Object[] lastSelection = currentSelection; currentSelection = selection.toArray(); if (selection.size() == 0) { status = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.ERROR, EMPTY_STRING, null); if (lastSelection != null /*&& getListSelectionLabelDecorator() != null*/) { list.update(lastSelection, null); } currentSelection = null; } else { status = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.ERROR, EMPTY_STRING, null); List items = selection.toList(); Object item = null; IStatus tempStatus = null; for (Iterator it = items.iterator(); it.hasNext();) { Object o = it.next(); if (o instanceof ItemsListSeparator) { continue; } item = o; tempStatus = validateItem(item); if (tempStatus.isOK()) { status = new Status(IStatus.OK, PlatformUI.PLUGIN_ID, IStatus.OK, EMPTY_STRING, null); } else { status = tempStatus; // if any selected element is not valid status is set to // ERROR break; } } if (lastSelection != null /*&& getListSelectionLabelDecorator() != null*/) { list.update(lastSelection, null); } // if (getListSelectionLabelDecorator() != null) { list.update(currentSelection, null); // } } if (enableDocArea()) { refreshBrowserContent(browser, currentSelection); } refreshDetails(); updateStatus(status); }
From source file:de.weingardt.mylyn.gitlab.ui.GitlabQueryPage.java
License:Open Source License
private void removeSelection() { StructuredSelection selection = (StructuredSelection) labelsViewer.getSelection(); if (!selection.isEmpty()) { labelsViewer.remove(selection.toArray()); }/*from w ww . ja v a 2s . c o m*/ }
From source file:edu.uchicago.cs.hao.texdojo.bibeditor.editors.EditorUI.java
License:Open Source License
public BibEntry[] allSelected() { StructuredSelection sel = (StructuredSelection) table.getSelection(); if (sel == null || sel.isEmpty()) return null; Object[] sels = sel.toArray(); BibEntry[] allsels = new BibEntry[sels.length]; for (int i = 0; i < sels.length; i++) { allsels[i] = (BibEntry) sels[i]; }/* ww w. j av a 2s .c o m*/ return allsels; }
From source file:info.novatec.inspectit.rcp.preferences.page.CmrRepositoryPreferencePage.java
/** * {@inheritDoc}//from w ww. j a va 2 s .c o m */ @Override protected Control createContents(Composite parent) { Composite mainComposite = new Composite(parent, SWT.INHERIT_DEFAULT); GridLayout layout = new GridLayout(2, false); layout.marginHeight = 0; layout.marginWidth = 0; mainComposite.setLayout(layout); Label info = new Label(mainComposite, SWT.NONE); info.setText("Add, remove and manage repositories"); GridData labelGridData = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false); labelGridData.horizontalSpan = 2; info.setLayoutData(labelGridData); Table table = new Table(mainComposite, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.VIRTUAL); table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); table.setHeaderVisible(true); table.setLinesVisible(true); tableViewer = new TableViewer(table); createColumns(); tableViewer.setContentProvider(new ArrayContentProvider()); tableViewer.setInput(inputList.keySet()); tableViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { updateButtonsState(); } }); Composite buttonComposite = new Composite(mainComposite, SWT.INHERIT_DEFAULT); GridLayout buttonLayout = new GridLayout(1, true); buttonLayout.marginHeight = 0; buttonLayout.marginWidth = 0; buttonComposite.setLayout(buttonLayout); buttonComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false)); addButton = new Button(buttonComposite, SWT.PUSH); addButton.setText("Add"); addButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); addButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { AddCmrRepositoryDefinitionDialog dialog = new AddCmrRepositoryDefinitionDialog(getShell()); dialog.open(); if (dialog.getReturnCode() == Dialog.OK && null != dialog.getCmrRepositoryDefinition()) { inputList.put(dialog.getCmrRepositoryDefinition(), OnlineStatus.OFFLINE); cmrRepositoryManager.forceCmrRepositoryOnlineStatusUpdate(dialog.getCmrRepositoryDefinition()); tableViewer.refresh(); } } }); removeButton = new Button(buttonComposite, SWT.PUSH); removeButton.setText("Remove"); removeButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); removeButton.setEnabled(false); removeButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { StructuredSelection selection = (StructuredSelection) tableViewer.getSelection(); for (Object selectedObject : selection.toArray()) { if (selectedObject instanceof CmrRepositoryDefinition) { inputList.remove((CmrRepositoryDefinition) selectedObject); } } tableViewer.refresh(); } }); refreshButton = new Button(buttonComposite, SWT.PUSH); refreshButton.setText("Refresh"); refreshButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); refreshButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { for (CmrRepositoryDefinition cmrRepositoryDefinition : inputList.keySet()) { cmrRepositoryManager.forceCmrRepositoryOnlineStatusUpdate(cmrRepositoryDefinition); } } }); manageLabelsButton = new Button(buttonComposite, SWT.PUSH); manageLabelsButton.setText("Manage Labels"); manageLabelsButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); manageLabelsButton.setEnabled(false); manageLabelsButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { StructuredSelection selection = (StructuredSelection) tableViewer.getSelection(); for (Object selectedObject : selection.toArray()) { if (selectedObject instanceof CmrRepositoryDefinition) { ManageLabelWizard mlw = new ManageLabelWizard((CmrRepositoryDefinition) selectedObject); WizardDialog wizardDialog = new WizardDialog(getShell(), mlw); wizardDialog.open(); } } } }); return mainComposite; }
From source file:lu.uni.geko.commands.AbstractFileHandler.java
License:Open Source License
/** * Returns a list containing lists of URIs that contain the selected files that correspond to each file type. * * @param event// www .j av a2s. c o m * the execution event * @return a list containing a list of URIs for each file type */ public List<List<URI>> getSelectedFileURIs(final ExecutionEvent event) { StructuredSelection structuredSelection = EclipseBridge.getCurrentStructuredSelection(event); List<List<URI>> selectedFileURIs = new ArrayList<List<URI>>(); for (int type = 0; type < getTypeCount(); type++) { selectedFileURIs.add(new ArrayList<URI>()); } for (Object selectedElement : structuredSelection.toArray()) { if (selectedElement instanceof IFile) { IFile selectedFile = ((IFile) selectedElement); int type = getTypeNoIfSelectable(selectedFile); if (type >= 0 && type < getTypeCount()) { if (selectedFile.exists()) { URI selectedURI = EMFBridge.getEMFUriForIResource(selectedFile); selectedFileURIs.get(type).add(selectedURI); } } } } return selectedFileURIs; }
From source file:lu.uni.geko.commands.AbstractFolderHandler.java
License:Open Source License
/** * Returns a list containing all the selected folders. * * @param event//from ww w . j av a 2s. co m * execution event * @return list of folders */ public List<IFolder> getSelectedFolders(final ExecutionEvent event) { StructuredSelection structuredSelection = EclipseBridge.getCurrentStructuredSelection(event); List<IFolder> selectedFolders = new ArrayList<IFolder>(); for (Object selectedElement : structuredSelection.toArray()) { if (selectedElement instanceof IFolder) { IFolder selectedFolder = ((IFolder) selectedElement); if (selectedFolder.exists()) { selectedFolders.add(selectedFolder); } } } return selectedFolders; }
From source file:net.karlmartens.ui.widget.GridChooser.java
License:Apache License
private static int minSelectionOrder(TableViewer viewer) { final StructuredSelection selection = (StructuredSelection) viewer.getSelection(); if (selection.isEmpty()) return -1; final GridChooserItem[] items = new GridChooserItem[selection.size()]; System.arraycopy(selection.toArray(), 0, items, 0, selection.size()); int index = items[0].getSelectionOrder(); for (int i = 1; i < items.length; i++) { final int candidate = items[i].getSelectionOrder(); if (index > candidate) { index = candidate;/*from w ww . ja v a 2s .c o m*/ } } return index; }
From source file:net.karlmartens.ui.widget.GridChooser.java
License:Apache License
private static int maxSelectionOrder(TableViewer viewer) { final StructuredSelection selection = (StructuredSelection) viewer.getSelection(); if (selection.isEmpty()) return -1; final GridChooserItem[] items = new GridChooserItem[selection.size()]; System.arraycopy(selection.toArray(), 0, items, 0, selection.size()); int index = items[0].getSelectionOrder(); for (int i = 1; i < items.length; i++) { final int candidate = items[i].getSelectionOrder(); if (index < candidate) { index = candidate;/*from w ww . j a v a 2 s . c o m*/ } } return index; }