List of usage examples for org.eclipse.jface.viewers StructuredSelection toArray
@Override
public Object[] toArray()
From source file:org.rssowl.ui.internal.dialogs.preferences.SharingPreferencesPage.java
License:Open Source License
private void onMove(StructuredSelection selection, ShareProvider destination, int location) { /* Determine Moved Items */ List<ShareProvider> movedItems = new ArrayList<ShareProvider>(); Object[] selectedElements = selection.toArray(); for (Object element : selectedElements) { movedItems.add((ShareProvider) element); }/*from w ww .j a va2s . co m*/ /* Determine Visible Items */ List<ShareProvider> visibleItems = new ArrayList<ShareProvider>(); TableItem[] items = fViewer.getTable().getItems(); for (TableItem item : items) { visibleItems.add((ShareProvider) item.getData()); } /* Return in these unlikely cases */ if (movedItems.isEmpty() || visibleItems.isEmpty()) return; /* Remove all Moved Items from Visible */ visibleItems.removeAll(movedItems); /* Put Moved Items to Destination Index if possible */ int destinationIndex = visibleItems.indexOf(destination); if (destinationIndex >= 0) { /* Adjust Destination */ if (location == ViewerDropAdapter.LOCATION_ON || location == ViewerDropAdapter.LOCATION_AFTER) destinationIndex++; /* Add to Visible */ visibleItems.addAll(destinationIndex, movedItems); /* Save Visible */ int[] newState = new int[items.length]; for (int i = 0; i < visibleItems.size(); i++) { ShareProvider provider = visibleItems.get(i); int index = provider.getIndex(); index++; //Adjust to non-zero indexing if (!provider.isEnabled()) index = index * -1; newState[i] = index; } fPreferences.putIntegers(DefaultPreferences.SHARE_PROVIDER_STATE, newState); /* Show Updates */ fViewer.refresh(); /* Restore Selection */ fViewer.getTable().setSelection(destinationIndex, destinationIndex + movedItems.size() - 1); /* Update */ updateCheckedState(); updateMoveEnablement(); } }
From source file:org.springframework.ide.eclipse.wizard.ui.BeanPropertiesWizardPage.java
License:Open Source License
private void createCombo(Composite sectionComposite) { constructorCombo = new ComboViewer(sectionComposite); comboContentProvider = new IStructuredContentProvider() { public void dispose() { }/*from ww w . j av a 2s. c o m*/ public Object[] getElements(Object inputElement) { IFile beanFile = wizard.getBeanFile(); if (beanFile == null) { return new Object[0]; } String className = BeansEditorUtils.getClassNameForBean(beanFile, wizard.getOriginalDocument(), wizard.getNewBean()); IType type = JdtUtils.getJavaType(beanFile.getProject(), className); Set<IMethod> constructors = null; try { constructors = Introspector.findAllConstructors(type); } catch (JavaModelException e) { StatusHandler.log(new Status(IStatus.ERROR, WizardPlugin.PLUGIN_ID, "Failed to populate constructor combo.", e)); } if (constructors == null) { return new Object[0]; } return constructors.toArray(); } public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } }; constructorCombo.setContentProvider(comboContentProvider); constructorCombo.setInput(this); constructorCombo.setLabelProvider(new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT)); constructorCombo.addFilter(new ViewerFilter() { @Override public boolean select(Viewer viewer, Object parentElement, Object element) { if (element instanceof IMethod) { IMethod method = (IMethod) element; try { return method.getParameterNames().length > 0; } catch (JavaModelException e) { StatusHandler.log(new Status(IStatus.ERROR, WizardPlugin.PLUGIN_ID, "Failed to populate constructor combo.", e)); } } return false; } }); GridData comboData = new GridData(SWT.FILL, SWT.FILL, true, false); comboData.horizontalSpan = 2; comboData.widthHint = 400; constructorCombo.getControl().setLayoutData(comboData); constructorCombo.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { ISelection selection = constructorCombo.getSelection(); if (selection instanceof StructuredSelection) { StructuredSelection structuredSelection = (StructuredSelection) selection; Object[] items = structuredSelection.toArray(); if (items.length == 1) { IMethod constructor = (IMethod) items[0]; int numParam = constructor.getNumberOfParameters(); int itemCount = constructorArgsTable.getItemCount(); if (itemCount != numParam) { if (itemCount > 0) { boolean confirmed = MessageDialog.openConfirm(getShell(), Messages.getString( "BeanPropertiesWizardPage.CHANG_CONSTRUCTOR_ARGS_CONFIRM_DIALOG_TITLE"), //$NON-NLS-1$ Messages.getString( "BeanPropertiesWizardPage.CHANG_CONSTRUCTOR_ARGS_CONFIRM_DIALOG_MESSAGE")); //$NON-NLS-1$ if (!confirmed) { return; } constructorArgsTable.removeAll(); } for (int i = 0; i < numParam; i++) { IDOMElement child = createNewChild(CONSTRUCTOR_ARG, BeansSchemaConstants.ELEM_CONSTRUCTOR_ARG); createElementItem(CONSTRUCTOR_ARG, child); } constructorArgsTable.redraw(); } } } } }); }
From source file:org.talend.commons.ui.swt.advanced.dataeditor.button.CopyPushButtonForExtendedTable.java
License:Open Source License
@Override protected Command getCommandToExecute() { AbstractExtendedTableViewer extendedTableViewer = (AbstractExtendedTableViewer) extendedControlViewer; TableViewer tableViewer = extendedTableViewer.getTableViewerCreator().getTableViewer(); ISelection selection = tableViewer.getSelection(); StructuredSelection structuredSelection = (StructuredSelection) selection; Object[] objects = structuredSelection.toArray(); return new ExtendedTableCopyCommand(Arrays.asList(objects)); }
From source file:org.talend.designer.core.ui.editor.TalendSelectionManager.java
License:Open Source License
@Override public void appendSelection(EditPart arg0) { // judge whether the refresh operation is executed. // see bug 3315. boolean needRefresh = false; if (getSelection() instanceof StructuredSelection) { StructuredSelection selection = (StructuredSelection) getSelection(); Object selected = null;// w w w. jav a2s .c o m for (Object element : selection.toArray()) { selected = element; } if (getSelection().isEmpty() || (selected instanceof ProcessPart)) { this.selectionType = ETalendSelectionType.SINGLE; needRefresh = true; } if (!(arg0 instanceof NodeLabelEditPart) && !(arg0 instanceof ConnLabelEditPart) && !(arg0 instanceof ConnectionPart)) { // removes old selections of labels by calling setSelection for (Object element : selection.toArray()) { if (element instanceof NodeLabelEditPart) { this.deselect(((AbstractGraphicalEditPart) element)); } else if (element instanceof ConnLabelEditPart) { this.deselect(((AbstractGraphicalEditPart) element)); } else if (element instanceof ConnectionPart) { this.deselect(((AbstractConnectionEditPart) element)); } } needRefresh = true; } if (arg0 instanceof ConnectionPerformanceEditPart && getSelectPoint() != null) { if (needRefresh) { EditPart transferPart = transferFocus((ConnectionPerformanceEditPart) arg0); if (transferPart == null) { needRefresh = false; setSelectPoint(null); return; } super.appendSelection(transferPart); needRefresh = false; return; } } if (needRefresh) { super.appendSelection(arg0); needRefresh = false; setSelectPoint(null); } } }
From source file:org.talend.designer.core.ui.editor.TalendSelectionManager.java
License:Open Source License
private StructuredSelection filterSelection(StructuredSelection selection) { List newSelection = new ArrayList(selection.toList()); for (Object element : selection.toArray()) { if (element instanceof SubjobContainerPart) { // childrens are NodeContainer part newSelection.remove(element); List<NodeContainerPart> nodeContainerParts = ((SubjobContainerPart) element).getChildren(); for (NodeContainerPart nodeContainerPart : nodeContainerParts) { for (Object object : nodeContainerPart.getChildren()) { if (object instanceof NodePart) { if (!newSelection.contains(object)) { newSelection.add(object); }/* w w w . ja va 2 s . co m*/ } } } } else if (element instanceof NoteEditPart) { if (!newSelection.contains(element)) { newSelection.add(element); } } else if (!(element instanceof NodePart)) { newSelection.remove(element); } } StructuredSelection newList = new StructuredSelection(newSelection); return newList; }
From source file:rocks.inspectit.ui.rcp.preferences.page.CmrRepositoryPreferencePage.java
/** * {@inheritDoc}/*from www .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() == Window.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(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:scouter.client.views.ObjectClassListView.java
License:Apache License
private void createTableContextMenu() { MenuManager manager = new MenuManager(); tableViewer.getControl().setMenu(manager.createContextMenu(tableViewer.getControl())); manager.add(new Action("&Copy", ImageDescriptor.createFromImage(Images.copy)) { public void run() { selectionCopyToClipboard();//from w w w.j ava2s .co m } }); Server server = ServerManager.getInstance().getServer(serverId); if (server.isAllowAction(GroupPolicyConstants.ALLOW_EXPORTCLASS)) { manager.add(new Action("&Export Class") { public void run() { StructuredSelection selection = (StructuredSelection) tableViewer.getSelection(); ClassData data = (ClassData) selection.getFirstElement(); final String className = data.name; if (StringUtil.isEmpty(className)) { return; } ExUtil.asyncRun(new Runnable() { public void run() { TcpProxy tcp = TcpProxy.getTcpProxy(serverId); MapPack p = null; try { MapPack param = new MapPack(); param.put("objHash", objHash); param.put("class", className); p = (MapPack) tcp.getSingle(RequestCmd.OBJECT_LOAD_CLASS_BY_STREAM, param); } catch (Exception e) { ConsoleProxy.errorSafe(e.getMessage()); } finally { TcpProxy.putTcpProxy(tcp); } if (p != null) { String error = CastUtil.cString(p.get("error")); if (StringUtil.isNotEmpty(error)) { ConsoleProxy.errorSafe(error); } Value v = p.get("class"); if (v != null) { final BlobValue bv = (BlobValue) v; ExUtil.exec(tableViewer.getTable(), new Runnable() { public void run() { saveClassFile(className, bv); } }); } } } }); } }); manager.add(new Action("&Export Jar") { public void run() { StructuredSelection selection = (StructuredSelection) tableViewer.getSelection(); final ClassData data = (ClassData) selection.getFirstElement(); final String resource = data.resources; if (StringUtil.isEmpty(resource)) { return; } ExUtil.asyncRun(new Runnable() { public void run() { TcpProxy tcp = TcpProxy.getTcpProxy(serverId); MapPack p = null; try { MapPack param = new MapPack(); param.put("objHash", objHash); param.put("resource", resource); p = (MapPack) tcp.getSingle(RequestCmd.OBJECT_CHECK_RESOURCE_FILE, param); } catch (Exception e) { ConsoleProxy.errorSafe(e.getMessage()); } finally { TcpProxy.putTcpProxy(tcp); } if (p != null) { String error = p.getText("error"); if (StringUtil.isNotEmpty(error)) { ConsoleProxy.errorSafe(error); } else { final String name = p.getText("name"); final long size = p.getLong("size"); ExUtil.exec(tableViewer.getTable(), new Runnable() { public void run() { if (MessageDialog.openQuestion(tableViewer.getTable().getShell(), data.name, name + "(" + ScouterUtil.humanReadableByteCount(size, true) + ") will be downloaded.\nContinue?")) { Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow() .getShell(); FileDialog dialog = new FileDialog(shell, SWT.SAVE); dialog.setOverwrite(true); dialog.setFileName(name); dialog.setFilterExtensions(new String[] { "*.jar", "*.*" }); dialog.setFilterNames( new String[] { "Jar File(*.jar)", "All Files" }); String fileSelected = dialog.open(); if (fileSelected != null) { new DownloadJarFileJob(name, resource, fileSelected).schedule(); } } } }); } } } }); } }); } manager.add(new Action("&Description") { public void run() { openDescription(); } }); manager.add(new Separator()); if (server.isAllowAction(GroupPolicyConstants.ALLOW_REDEFINECLASS)) { manager.add(new Action("&Redefine class") { public void run() { StructuredSelection selection = (StructuredSelection) tableViewer.getSelection(); final ListValue classLv = new ListValue(); Object[] datas = selection.toArray(); for (int i = 0; i < datas.length; i++) { ClassData data = (ClassData) datas[i]; classLv.add(data.name); } if (MessageDialog.openQuestion(tableViewer.getTable().getShell(), classLv.size() + " class(es) selected", "Redefine class may affect this server.\nContinue?")) { new RedefineClassJob(classLv).schedule(); } } }); } tableViewer.getTable().addListener(SWT.KeyDown, new Listener() { public void handleEvent(Event e) { if (e.stateMask == SWT.CTRL) { if (e.keyCode == 'c' || e.keyCode == 'C') { selectionCopyToClipboard(); } } } }); }
From source file:tinyos.dlrc.make.dialog.pages.IncludePage.java
License:Open Source License
private void performeDelete() { StructuredSelection selection = (StructuredSelection) includeList.getSelection(); if (selection != null) { Object[] array = selection.toArray(); if (array != null) { for (Object entry : array) { contentProvider.remove((TableEntry) entry); }/*w w w . j a va 2s. c o m*/ contentChanged(); } } }