List of usage examples for org.eclipse.jface.viewers StructuredSelection isEmpty
@Override public boolean isEmpty()
From source file:org.eclipse.mdht.uml.cda.ui.builder.ToggleNatureAction.java
License:Open Source License
public void selectionChanged(IAction action, ISelection selection) { this.selection = selection; boolean enabled = false; if (selection instanceof StructuredSelection) { StructuredSelection structuredSelection = (StructuredSelection) selection; if (!structuredSelection.isEmpty()) { if (structuredSelection.getFirstElement() instanceof IProject) { IProject project = (IProject) structuredSelection.getFirstElement(); try { if (project.hasNature(CDANature.NATURE_ID) || project.getName().endsWith(".doc")) { enabled = true;/* w w w .ja va 2 s .c o m*/ } else { Manifest projectManifest; projectManifest = new Manifest(CDAUIUtil.getManifest(project).getContents()); Attributes attributes = projectManifest.getMainAttributes(); String requiredBundles = attributes.getValue("Require-Bundle"); if (requiredBundles.contains("org.eclipse.mdht.uml.cda") && CDAUIUtil.getGeneratorModelFile(project) != null) { enabled = true; } } } catch (IOException e) { } catch (CoreException e) { } } } } action.setEnabled(enabled); }
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]); }/*from ww w . j av a 2 s . c o m*/ 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.xplanner.ui.wizard.XPlannerCustomQueryPage.java
License:Open Source License
public void validatePage() { String errorMessage = null;/*ww w . ja v a2 s.c om*/ // need query name if (getQueryTitle().length() == 0) { errorMessage = Messages.XPlannerCustomQueryPage_QUERY_NAME_NEEDED; } if (errorMessage == null && selectedTasksButton.getSelection()) { StructuredSelection selection = (StructuredSelection) projectsViewer.getSelection(); if (selection == null || selection.isEmpty()) { errorMessage = Messages.XPlannerCustomQueryPage_PROJECT_ELEMENT_NEEDED; } } setErrorMessage(errorMessage); setPageComplete(errorMessage == null); if (getSearchContainer() != null) { getSearchContainer().setPerformActionEnabled(isPageComplete()); } }
From source file:org.eclipse.objectteams.otdt.internal.ui.bindingeditor.BindingConfiguration.java
License:Open Source License
private boolean validateSelections() { StructuredSelection selectedBaseIMembers = (StructuredSelection) _baseMethListViewer.getSelection(); for (Iterator iter = selectedBaseIMembers.iterator(); iter.hasNext();) { IMember baseIMember = (IMember) iter.next(); try {/*from ww w .jav a 2 s .c o m*/ if (Flags.isAbstract(baseIMember.getFlags())) { _methMapBtnComp.deselectAll(); _methMapBtnComp.disableAll(); toggleApplyButton(); return false; } } catch (JavaModelException ex) { return false; } } StructuredSelection selectedRoleIMethod = (StructuredSelection) _roleMethListViewer.getSelection(); if (selectedRoleIMethod.isEmpty()) { return true; } IMethod roleMethod = (IMethod) selectedRoleIMethod.getFirstElement(); try { if (roleMethod.getElementName().equals(FAKED_METHOD_NAME)) { toggleModifierButtons(OT_CALLOUT_OVERRIDE | Modifier.OT_AFTER_CALLIN | Modifier.OT_BEFORE_CALLIN | Modifier.OT_REPLACE_CALLIN, DESELECT_DISABLE_BUTTONS); toggleApplyButton(); return false; } if (!roleMethod.getElementName().equals(FAKED_METHOD_NAME) && !Flags.isCallin(roleMethod.getFlags()) && !Flags.isAbstract(roleMethod.getFlags())) { toggleModifierButtons(Modifier.OT_REPLACE_CALLIN | OT_CALLOUT, DESELECT_DISABLE_BUTTONS); toggleApplyButton(); return false; } if (!roleMethod.getElementName().equals(FAKED_METHOD_NAME) && Flags.isCallin(roleMethod.getFlags()) && !Flags.isAbstract(roleMethod.getFlags())) { toggleModifierButtons( OT_CALLOUT_OVERRIDE | OT_CALLOUT | Modifier.OT_AFTER_CALLIN | Modifier.OT_BEFORE_CALLIN, DESELECT_DISABLE_BUTTONS); toggleApplyButton(); return false; } } catch (JavaModelException ex) { return false; } return true; }
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;//from www . j av a2 s .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.test.manager.preferences.environment.EnvironmentPageEventHandler.java
License:Open Source License
public void handleRemoveSelectedViewEvent() { StructuredSelection sel = (StructuredSelection) treeViewer.getSelection(); if (!sel.isEmpty()) { Iterator<?> it = sel.iterator(); while (it.hasNext()) { TreeObject leaf = (TreeObject) it.next(); if (leaf instanceof TreeParent) { treeInputList.remove(leaf); environmentPageDataViewer.setNodeToDisplay(null); } else { leaf.getParent().removeChild(leaf); environmentPageDataViewer.update(); }/* w ww . j a v a2 s . com*/ } treeViewer.refresh(); } }
From source file:org.eclipse.papyrus.diagram.menu.selection.SelectByTypeHandler.java
License:Open Source License
public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); IEditorPart editorPart = window.getActivePage().getActiveEditor(); if (editorPart instanceof IMultiDiagramEditor) { IMultiDiagramEditor editor = (IMultiDiagramEditor) editorPart; editorPart = editor.getActiveEditor(); if (editorPart instanceof DiagramEditor) { StructuredSelection selection = (StructuredSelection) editorPart.getEditorSite() .getSelectionProvider().getSelection(); if (selection.isEmpty()) { return null; }//from w ww .ja va 2 s .c o m if (verifySameTypeOfSelectedElements(selection)) { Object elem = selection.getFirstElement(); IGraphicalEditPart part = (IGraphicalEditPart) elem; EObject o1 = getEObject(part); Map<?, ?> elements = part.getViewer().getEditPartRegistry(); Object[] values = elements.values().toArray(); ArrayList<Object> listElement = new ArrayList<Object>(); add(listElement, part); for (int i = 0; i < values.length; i++) { if (values[i] instanceof IGraphicalEditPart) { IGraphicalEditPart nextPart = (IGraphicalEditPart) values[i]; EObject o2 = getEObject(nextPart); if (part instanceof ConnectionEditPart && nextPart instanceof ConnectionEditPart) { if (o1 != o2 && (o1.eClass().equals(o2.eClass()))) { add(listElement, nextPart); } } else if (o1 != o2 && (o1.eClass().equals(o2.eClass())) && (isEquivalent(part.getParent(), nextPart.getParent()))) { add(listElement, nextPart); } } } part.getViewer().setSelection(new StructuredSelection(listElement)); } } } return null; }
From source file:org.eclipse.php.internal.debug.ui.views.DebugViewHelper.java
License:Open Source License
public IPHPDebugTarget getSelectionElement(ISelection selection) { IDebugElement element = getAdaptableElement(); if (element == null) { if (selection != null) { if (selection instanceof StructuredSelection) { StructuredSelection sSelection = (StructuredSelection) selection; if (!sSelection.isEmpty()) { Object first = sSelection.getFirstElement(); if (first instanceof IDebugElement) element = (IDebugElement) first; }/* w w w .j ava 2 s . com*/ } } } IPHPDebugTarget target = getDebugTarget(element); // If target is null try to get target from the last debug process to // run if (target == null) { IProcess process = DebugUITools.getCurrentProcess(); if (process != null) { if (process instanceof PHPProcess) { target = (IPHPDebugTarget) ((PHPProcess) process).getDebugTarget(); } } } return target; }
From source file:org.eclipse.php.internal.ui.functions.PHPFunctionsPart.java
License:Open Source License
private void addDoubleClickListener() { fViewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { IEditorPart editor = EditorUtility .getPHPStructuredEditor(getViewSite().getPage().getActiveEditor()); StructuredSelection selection = (StructuredSelection) fViewer.getSelection(); if (editor != null && editor instanceof ITextEditor && selection != null && !selection.isEmpty()) { if (selection.getFirstElement() instanceof IModelElement) { IModelElement codeData = (IModelElement) selection.getFirstElement(); ITextEditor textEditor = (ITextEditor) editor; int caretPosition = ((ITextSelection) textEditor.getSelectionProvider().getSelection()) .getOffset(); IDocument document = textEditor.getDocumentProvider() .getDocument(textEditor.getEditorInput()); try { document.replace(caretPosition, 0, codeData.getElementName()); } catch (BadLocationException e) { Logger.logException(e); }/*from ww w . ja v a 2 s . c o m*/ textEditor.setFocus(); textEditor.getSelectionProvider().setSelection( new TextSelection(document, caretPosition + codeData.getElementName().length(), 0)); } } } }); }
From source file:org.eclipse.scout.rt.ui.rap.basic.table.RwtScoutTable.java
License:Open Source License
@Override public ITableRow[] getUiSelectedRows() { StructuredSelection uiSelection = (StructuredSelection) getUiTableViewer().getSelection(); TreeSet<ITableRow> sortedRows = new TreeSet<ITableRow>(new RowIndexComparator()); if (uiSelection != null && !uiSelection.isEmpty()) { for (Object o : uiSelection.toArray()) { ITableRow row = (ITableRow) o; sortedRows.add(row);//from w ww. j av a2s . c om } } return sortedRows.toArray(new ITableRow[sortedRows.size()]); }