List of usage examples for org.eclipse.jface.viewers StructuredSelection size
@Override public int size()
From source file:org.eclipse.mylyn.internal.java.ui.actions.FocusPackageExplorerAction.java
License:Open Source License
@Override protected ISelection resolveSelection(IEditorPart part, ITextSelection changedSelection, StructuredViewer viewer) throws CoreException { Object elementToSelect = null; if (changedSelection instanceof TextSelection && part instanceof JavaEditor) { TextSelection textSelection = (TextSelection) changedSelection; IJavaElement javaElement = SelectionConverter.resolveEnclosingElement((JavaEditor) part, textSelection); if (javaElement != null) { elementToSelect = javaElement; }//from w ww . java 2s . co m } if (elementToSelect != null) { StructuredSelection currentSelection = (StructuredSelection) viewer.getSelection(); if (currentSelection.size() <= 1) { if (elementToSelect instanceof IMember) { if (viewer.getContentProvider() instanceof StandardJavaElementContentProvider) { if (!((StandardJavaElementContentProvider) viewer.getContentProvider()) .getProvideMembers()) { elementToSelect = ((IMember) elementToSelect).getCompilationUnit(); return new StructuredSelection(elementToSelect); } } for (ViewerFilter filter : Arrays.asList(viewer.getFilters())) { if (filter instanceof JavaDeclarationsFilter) { elementToSelect = ((IMember) elementToSelect).getCompilationUnit(); return new StructuredSelection(elementToSelect); } } } } return new StructuredSelection(elementToSelect); } else { return null; } }
From source file:org.eclipse.mylyn.internal.tasks.ui.deprecated.AbstractRepositoryTaskEditor.java
License:Open Source License
protected void createAttachmentLayout(Composite composite) { // TODO: expand to show new attachments Section section = createSection(composite, getSectionLabel(SECTION_NAME.ATTACHMENTS_SECTION), false); section.setText(section.getText() + " (" + taskData.getAttachments().size() + ")"); final Composite attachmentsComposite = toolkit.createComposite(section); attachmentsComposite.setLayout(new GridLayout(1, false)); attachmentsComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); section.setClient(attachmentsComposite); if (taskData.getAttachments().size() > 0) { attachmentsTable = toolkit.createTable(attachmentsComposite, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION); attachmentsTable.setLinesVisible(true); attachmentsTable.setHeaderVisible(true); attachmentsTable.setLayout(new GridLayout()); GridData tableGridData = new GridData(SWT.FILL, SWT.FILL, true, true); attachmentsTable.setLayoutData(tableGridData); for (int i = 0; i < attachmentsColumns.length; i++) { TableColumn column = new TableColumn(attachmentsTable, SWT.LEFT, i); column.setText(attachmentsColumns[i]); column.setWidth(attachmentsColumnWidths[i]); }/* w w w . ja v a 2 s . c om*/ attachmentsTable.getColumn(3).setAlignment(SWT.RIGHT); attachmentsTableViewer = new TableViewer(attachmentsTable); attachmentsTableViewer.setUseHashlookup(true); attachmentsTableViewer.setColumnProperties(attachmentsColumns); ColumnViewerToolTipSupport.enableFor(attachmentsTableViewer, ToolTip.NO_RECREATE); final AbstractTaskDataHandler offlineHandler = connector.getLegacyTaskDataHandler(); if (offlineHandler != null) { attachmentsTableViewer.setSorter(new ViewerSorter() { @Override public int compare(Viewer viewer, Object e1, Object e2) { RepositoryAttachment attachment1 = (RepositoryAttachment) e1; RepositoryAttachment attachment2 = (RepositoryAttachment) e2; Date created1 = taskData.getAttributeFactory().getDateForAttributeType( RepositoryTaskAttribute.ATTACHMENT_DATE, attachment1.getDateCreated()); Date created2 = taskData.getAttributeFactory().getDateForAttributeType( RepositoryTaskAttribute.ATTACHMENT_DATE, attachment2.getDateCreated()); if (created1 != null && created2 != null) { return created1.compareTo(created2); } else if (created1 == null && created2 != null) { return -1; } else if (created1 != null && created2 == null) { return 1; } else { return 0; } } }); } attachmentsTableViewer .setContentProvider(new AttachmentsTableContentProvider(taskData.getAttachments())); attachmentsTableViewer.setLabelProvider(new AttachmentTableLabelProvider(this, new LabelProvider(), PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator())); attachmentsTableViewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { if (!event.getSelection().isEmpty()) { StructuredSelection selection = (StructuredSelection) event.getSelection(); RepositoryAttachment attachment = (RepositoryAttachment) selection.getFirstElement(); TasksUiUtil.openUrl(attachment.getUrl()); } } }); attachmentsTableViewer.setInput(taskData); final Action openWithBrowserAction = new Action(LABEL_BROWSER) { @Override public void run() { RepositoryAttachment attachment = (RepositoryAttachment) (((StructuredSelection) attachmentsTableViewer .getSelection()).getFirstElement()); if (attachment != null) { TasksUiUtil.openUrl(attachment.getUrl()); } } }; final Action openWithDefaultAction = new Action(LABEL_DEFAULT_EDITOR) { @Override public void run() { // browser shortcut RepositoryAttachment attachment = (RepositoryAttachment) (((StructuredSelection) attachmentsTableViewer .getSelection()).getFirstElement()); if (attachment == null) { return; } if (attachment.getContentType().endsWith(CTYPE_HTML)) { TasksUiUtil.openUrl(attachment.getUrl()); return; } IStorageEditorInput input = new RepositoryAttachmentEditorInput(repository, attachment); IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); if (page == null) { return; } IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry() .getDefaultEditor(input.getName()); try { page.openEditor(input, desc.getId()); } catch (PartInitException e) { StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Unable to open editor for: " + attachment.getDescription(), e)); } } }; final Action openWithTextEditorAction = new Action(LABEL_TEXT_EDITOR) { @Override public void run() { RepositoryAttachment attachment = (RepositoryAttachment) (((StructuredSelection) attachmentsTableViewer .getSelection()).getFirstElement()); IStorageEditorInput input = new RepositoryAttachmentEditorInput(repository, attachment); IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); if (page == null) { return; } try { page.openEditor(input, "org.eclipse.ui.DefaultTextEditor"); } catch (PartInitException e) { StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Unable to open editor for: " + attachment.getDescription(), e)); } } }; final Action saveAction = new Action(LABEL_SAVE) { @Override public void run() { ITaskAttachment attachment = (ITaskAttachment) (((StructuredSelection) attachmentsTableViewer .getSelection()).getFirstElement()); /* Launch Browser */ FileDialog fileChooser = new FileDialog(attachmentsTable.getShell(), SWT.SAVE); String fname = attachment.getFileName(); // Default name if none is found if (fname.equals("")) { String ctype = attachment.getContentType(); if (ctype.endsWith(CTYPE_HTML)) { fname = ATTACHMENT_DEFAULT_NAME + ".html"; } else if (ctype.startsWith(CTYPE_TEXT)) { fname = ATTACHMENT_DEFAULT_NAME + ".txt"; } else if (ctype.endsWith(CTYPE_OCTET_STREAM)) { fname = ATTACHMENT_DEFAULT_NAME; } else if (ctype.endsWith(CTYPE_ZIP)) { fname = ATTACHMENT_DEFAULT_NAME + "." + CTYPE_ZIP; } else { fname = ATTACHMENT_DEFAULT_NAME + "." + ctype.substring(ctype.indexOf("/") + 1); } } fileChooser.setFileName(fname); String filePath = fileChooser.open(); // Check if the dialog was canceled or an error occurred if (filePath == null) { return; } DownloadAttachmentJob job = new DownloadAttachmentJob(attachment, new File(filePath)); job.setUser(true); job.schedule(); } }; final Action copyURLToClipAction = new Action(LABEL_COPY_URL_TO_CLIPBOARD) { @Override public void run() { RepositoryAttachment attachment = (RepositoryAttachment) (((StructuredSelection) attachmentsTableViewer .getSelection()).getFirstElement()); Clipboard clip = new Clipboard(PlatformUI.getWorkbench().getDisplay()); clip.setContents(new Object[] { attachment.getUrl() }, new Transfer[] { TextTransfer.getInstance() }); clip.dispose(); } }; final Action copyToClipAction = new Action(LABEL_COPY_TO_CLIPBOARD) { @Override public void run() { RepositoryAttachment attachment = (RepositoryAttachment) (((StructuredSelection) attachmentsTableViewer .getSelection()).getFirstElement()); CopyAttachmentToClipboardJob job = new CopyAttachmentToClipboardJob(attachment); job.setUser(true); job.schedule(); } }; final MenuManager popupMenu = new MenuManager(); final Menu menu = popupMenu.createContextMenu(attachmentsTable); attachmentsTable.setMenu(menu); final MenuManager openMenu = new MenuManager("Open With"); popupMenu.addMenuListener(new IMenuListener() { public void menuAboutToShow(IMenuManager manager) { popupMenu.removeAll(); IStructuredSelection selection = (IStructuredSelection) attachmentsTableViewer.getSelection(); if (selection.isEmpty()) { return; } if (selection.size() == 1) { RepositoryAttachment att = (RepositoryAttachment) ((StructuredSelection) selection) .getFirstElement(); // reinitialize open menu popupMenu.add(openMenu); openMenu.removeAll(); IStorageEditorInput input = new RepositoryAttachmentEditorInput(repository, att); IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry() .getDefaultEditor(input.getName()); if (desc != null) { openMenu.add(openWithDefaultAction); } openMenu.add(openWithBrowserAction); openMenu.add(openWithTextEditorAction); popupMenu.add(new Separator()); popupMenu.add(saveAction); popupMenu.add(copyURLToClipAction); if (att.getContentType().startsWith(CTYPE_TEXT) || att.getContentType().endsWith("xml")) { popupMenu.add(copyToClipAction); } } popupMenu.add(new Separator("actions")); // TODO: use workbench mechanism for this? ObjectActionContributorManager.getManager().contributeObjectActions( AbstractRepositoryTaskEditor.this, popupMenu, attachmentsTableViewer); } }); } else { Label label = toolkit.createLabel(attachmentsComposite, "No attachments"); registerDropListener(label); } final Composite attachmentControlsComposite = toolkit.createComposite(attachmentsComposite); attachmentControlsComposite.setLayout(new GridLayout(2, false)); attachmentControlsComposite.setLayoutData(new GridData(GridData.BEGINNING)); Button attachFileButton = toolkit.createButton(attachmentControlsComposite, AttachAction.LABEL, SWT.PUSH); attachFileButton.setImage(WorkbenchImages.getImage(ISharedImages.IMG_OBJ_FILE)); Button attachScreenshotButton = toolkit.createButton(attachmentControlsComposite, AttachScreenshotAction.LABEL, SWT.PUSH); attachScreenshotButton.setImage(CommonImages.getImage(CommonImages.IMAGE_CAPTURE)); final ITask task = TasksUiInternal.getTaskList().getTask(repository.getRepositoryUrl(), taskData.getTaskId()); if (task == null) { attachFileButton.setEnabled(false); attachScreenshotButton.setEnabled(false); } attachFileButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { // ignore } public void widgetSelected(SelectionEvent e) { AbstractTaskEditorAction attachFileAction = new AttachAction(); attachFileAction.selectionChanged(new StructuredSelection(task)); attachFileAction.setEditor(parentEditor); attachFileAction.run(); } }); attachScreenshotButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { // ignore } public void widgetSelected(SelectionEvent e) { AttachScreenshotAction attachScreenshotAction = new AttachScreenshotAction(); attachScreenshotAction.selectionChanged(new StructuredSelection(task)); attachScreenshotAction.setEditor(parentEditor); attachScreenshotAction.run(); } }); Button deleteAttachmentButton = null; if (supportsAttachmentDelete()) { deleteAttachmentButton = toolkit.createButton(attachmentControlsComposite, "Delete Attachment...", SWT.PUSH); deleteAttachmentButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { // ignore } public void widgetSelected(SelectionEvent e) { ITask task = TasksUiInternal.getTaskList().getTask(repository.getRepositoryUrl(), taskData.getTaskId()); if (task == null) { // Should not happen return; } if (AbstractRepositoryTaskEditor.this.isDirty || task.getSynchronizationState().equals(SynchronizationState.OUTGOING)) { MessageDialog.openInformation(attachmentsComposite.getShell(), "Task not synchronized or dirty editor", "Commit edits or synchronize task before deleting attachments."); return; } else { if (attachmentsTableViewer != null && attachmentsTableViewer.getSelection() != null && ((StructuredSelection) attachmentsTableViewer.getSelection()) .getFirstElement() != null) { RepositoryAttachment attachment = (RepositoryAttachment) (((StructuredSelection) attachmentsTableViewer .getSelection()).getFirstElement()); deleteAttachment(attachment); submitToRepository(); } } } }); } registerDropListener(section); registerDropListener(attachmentsComposite); registerDropListener(attachFileButton); if (supportsAttachmentDelete()) { registerDropListener(deleteAttachmentButton); } }
From source file:org.eclipse.mylyn.internal.tasks.ui.views.TaskListView.java
License:Open Source License
public static AbstractTask getSelectedTask(ISelection selection) { if (selection instanceof StructuredSelection) { StructuredSelection structuredSelection = (StructuredSelection) selection; if (structuredSelection.size() != 1) { return null; }/* w ww .ja va 2s . co m*/ Object element = structuredSelection.getFirstElement(); if (element instanceof ITask) { return (AbstractTask) structuredSelection.getFirstElement(); } } return null; }
From source file:org.eclipse.mylyn.internal.xplanner.ui.wizard.XPlannerCustomQueryPage.java
License:Open Source License
@SuppressWarnings("unchecked") private void ensureSingleTypeSelected(SelectionChangedEvent e) { StructuredSelection selection = (StructuredSelection) e.getSelection(); List<?> selectedElements = new ArrayList<Object>(selection.toList()); if (selectedElements.size() > 1) { Object firstElement = selection.getFirstElement(); int originalSelectionSize = selection.size(); for (Iterator<?> iter = selectedElements.iterator(); iter.hasNext();) { Object element = iter.next(); if (!element.getClass().equals(firstElement.getClass())) { iter.remove();//from w w w .j ava 2 s. c om } } if (selectedElements.size() < originalSelectionSize) { e.getSelectionProvider().setSelection(new StructuredSelection(selectedElements)); } } }
From source file:org.eclipse.mylyn.internal.xplanner.ui.wizard.XPlannerCustomQueryPage.java
License:Open Source License
private List<Integer> getSelectedContentIds() { ArrayList<Integer> selectedIds = new ArrayList<Integer>(); StructuredSelection selection = (StructuredSelection) projectsViewer.getSelection(); if (selection.size() == 0) { selectedIds.add(XPlannerAttributeMapper.INVALID_ID); } else {//ww w. ja va2 s .c o m for (Iterator<?> iter = selection.iterator(); iter.hasNext();) { Object selectedElement = iter.next(); if (selectedElement instanceof ProjectData) { selectedIds.add(((ProjectData) selectedElement).getId()); } else if (selectedElement instanceof IterationData) { selectedIds.add(((IterationData) selectedElement).getId()); } else if (selectedElement instanceof UserStoryData) { selectedIds.add(((UserStoryData) selectedElement).getId()); } } } return selectedIds; }
From source file:org.eclipse.objectteams.otdt.internal.ui.bindingeditor.BindingConfiguration.java
License:Open Source License
private boolean createMethodMapping() { int methMapModifier = 0; boolean calloutOverride = false; boolean signatureFlag = true; _newCallout = true;/*w w w .j a va2s . c o m*/ Button selectedButton = _methMapBtnComp.getSelectedButton(); if (_calloutBtn.equals(selectedButton)) { methMapModifier = 0; _newCallout = true; } if (_calloutOverrideBtn.equals(selectedButton)) { calloutOverride = true; methMapModifier = 0; _newCallout = true; } if (_callinReplaceBtn.equals(selectedButton)) { methMapModifier = Modifier.OT_REPLACE_CALLIN; _newCallout = false; } if (_callinBeforeBtn.equals(selectedButton)) { methMapModifier = Modifier.OT_BEFORE_CALLIN; _newCallout = false; } if (_callinAfterBtn.equals(selectedButton)) { methMapModifier = Modifier.OT_AFTER_CALLIN; _newCallout = false; } StructuredSelection selectedRoleMethod = (StructuredSelection) _roleMethListViewer.getSelection(); if (selectedRoleMethod.isEmpty()) { return false; } StructuredSelection selectedBaseMethods = (StructuredSelection) _baseMethListViewer.getSelection(); if (selectedBaseMethods.isEmpty()) { return false; } IMethod roleMethod = (IMethod) selectedRoleMethod.getFirstElement(); IMember[] baseMethods = new IMember[selectedBaseMethods.size()]; int baseMethodsCount = 0; for (Iterator iter = selectedBaseMethods.iterator(); iter.hasNext();) { IMember baseMethod = (IMember) iter.next(); baseMethods[baseMethodsCount++] = baseMethod; } AST ast = _selectedRole.getAST(); if (_newCallout) { if (baseMethods[0] instanceof IField) { this._calloutMappings = new CalloutMappingDeclaration[] { createCalloutMapping(ast, roleMethod, baseMethods[0], Modifier.OT_GET_CALLOUT, calloutOverride, signatureFlag), createCalloutMapping(ast, roleMethod, baseMethods[0], Modifier.OT_SET_CALLOUT, calloutOverride, signatureFlag) }; return this._calloutMappings[0] != null && this._calloutMappings[1] != null; } else { this._calloutMappings = new CalloutMappingDeclaration[] { createCalloutMapping(ast, roleMethod, baseMethods[0], methMapModifier, calloutOverride, signatureFlag) }; return this._calloutMappings[0] != null; } } else { return createCallinMapping(ast, roleMethod, baseMethods, methMapModifier, signatureFlag); } }
From source file:org.eclipse.osee.ote.ui.define.viewers.DragDropHandler.java
License:Open Source License
private void performDrop(DropTargetEvent e) throws OseeCoreException { Object object = e.data;/*from w ww.j a va2 s.c om*/ if (object instanceof ArtifactData) { handleArtifactDrops((ArtifactData) object); } else if (object instanceof TreeSelection) { StructuredSelection selection = (StructuredSelection) object; if (selection.size() > 0) { URI[] iFiles = toResourceArray(selection.toArray()); if (iFiles.length > 0) { try { handleResourceDrops(iFiles); } catch (OseeCoreException ex) { OseeLog.log(OteUiDefinePlugin.class, Level.SEVERE, ex); } } else { OseeLog.log(OteUiDefinePlugin.class, Level.WARNING, "No valid files dropped"); } } } }
From source file:org.eclipse.papyrus.diagram.common.sheet.UMLPropertySection.java
License:Open Source License
public void setInput(IWorkbenchPart part, ISelection selection) { if (selection.isEmpty() || false == selection instanceof StructuredSelection) { super.setInput(part, selection); return;//from ww w . ja v a 2s.c o m } final StructuredSelection structuredSelection = ((StructuredSelection) selection); ArrayList transformedSelection = new ArrayList(structuredSelection.size()); for (Iterator it = structuredSelection.iterator(); it.hasNext();) { Object r = transformSelection(it.next()); if (r != null) { transformedSelection.add(r); } } super.setInput(part, new StructuredSelection(transformedSelection)); }
From source file:org.eclipse.php.composer.ui.editor.composer.AuthorSection.java
License:Open Source License
@SuppressWarnings("unchecked") private void handleRemove() { StructuredSelection selection = ((StructuredSelection) authorViewer.getSelection()); Iterator<Object> it = selection.iterator(); String[] names = new String[selection.size()]; List<Person> persons = new ArrayList<Person>(); for (int i = 0; it.hasNext(); i++) { Person person = (Person) it.next(); persons.add(person);// w w w. j av a2 s .c o m names[i] = person.getName(); } String title = selection.size() > 1 ? Messages.AuthorSection_RemoveDialogTitlePlural : Messages.AuthorSection_RemoveDialogTitle; MessageDialog diag = new MessageDialog(authorViewer.getTable().getShell(), title, null, NLS.bind(Messages.AuthorSection_RemoveDialogMessage, StringUtils.join(names, ", ")), //$NON-NLS-1$ MessageDialog.WARNING, new String[] { Messages.AuthorSection_YesButton, Messages.AuthorSection_NoButton }, 0); if (diag.open() == Dialog.OK) { for (Person person : persons) { composerPackage.getAuthors().remove(person); } } }
From source file:org.eclipse.php.composer.ui.editor.composer.DependencySection.java
License:Open Source License
@SuppressWarnings("unchecked") private void handleRemove() { StructuredSelection selection = ((StructuredSelection) dependencyViewer.getSelection()); Iterator<Object> it = selection.iterator(); String[] names = new String[selection.size()]; List<VersionedPackage> deps = new ArrayList<VersionedPackage>(); for (int i = 0; it.hasNext(); i++) { VersionedPackage dep = (VersionedPackage) it.next(); deps.add(dep);//from ww w . ja va 2s . c o m names[i] = dep.getName(); } String title = selection.size() > 1 ? Messages.DependencySection_RemoveDialogTitlePlural : Messages.DependencySection_RemoveDialogTitle; MessageDialog diag = new MessageDialog(dependencyViewer.getTable().getShell(), title, null, NLS.bind(Messages.DependencySection_RemoveDialogMessage, StringUtils.join(names, ", ")), //$NON-NLS-1$ MessageDialog.WARNING, new String[] { Messages.DependencySection_YesButton, Messages.DependencySection_NoButton }, 0); if (diag.open() == Dialog.OK) { for (VersionedPackage dep : deps) { dependencies.remove(dep); } } }