List of usage examples for org.eclipse.jface.viewers IStructuredSelection toList
public List toList();
List
. From source file:net.sourceforge.tagsea.core.ui.internal.waypoints.WaypointTableDoubleClickListener.java
License:Open Source License
public void doubleClick(DoubleClickEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); for (Object o : selection.toList()) { IAdaptable a = (IAdaptable) o;//from w w w . j a v a2s. co m IWaypoint waypoint = (IWaypoint) a.getAdapter(IWaypoint.class); if (waypoint != null) { TagSEAPlugin.getDefault().navigate(waypoint); } } }
From source file:net.sourceforge.tagsea.core.ui.tags.WaypointPropertiesDialog.java
License:Open Source License
@Override protected Control createDialogArea(Composite parent) { Composite propertiesComposite = (Composite) super.createDialogArea(parent); propertiesComposite.setLayout(new GridLayout(2, false)); //Tag area//from w w w. j a v a 2 s . c o m Group area = new Group(propertiesComposite, SWT.FLAT); area.setText("Tags"); area.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); area.setLayout(new GridLayout(1, false)); // List of tags Composite listComposite = new Composite(area, SWT.FLAT); GridLayout layout = new GridLayout(); layout.horizontalSpacing = 0; layout.verticalSpacing = 0; listComposite.setLayout(layout); GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); data.heightHint = 100; data.widthHint = 200; listComposite.setLayoutData(data); List tagNameList = new List(listComposite, SWT.FLAT | SWT.BORDER | SWT.V_SCROLL | SWT.MULTI); tagNameListViewer = new ListViewer(tagNameList); tagNameListViewer.setContentProvider(new ArrayContentProvider()); tagNameList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); tagNameListViewer.setInput(tagNames); // Area for buttons // Group area2 = new Group(area, SWT.FLAT); // area2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); // area2.setLayout(new GridLayout(3, false)); Composite textComposite = new Composite(listComposite, SWT.FLAT); layout = new GridLayout(); layout.numColumns = 2; layout.horizontalSpacing = 0; layout.verticalSpacing = 0; textComposite.setLayout(layout); data = new GridData(SWT.FILL, SWT.FILL, true, false); textComposite.setLayoutData(data); ContentAssistCommandAdapter tagAssist = createTagText(textComposite, SWT.BORDER); tagText = (Text) tagAssist.getControl(); tagText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { String text = tagText.getText(); text = text.trim(); if ("".equals(text)) { updateStatus(Status.OK_STATUS); addButton.setEnabled(false); return; } int valid = TagSEAUtils.isValidTagName(text); switch (valid) { case TagSEAUtils.TAG_NAME_BAD_CHARACTER: updateStatus(new Status(IStatus.ERROR, TagSEAPlugin.PLUGIN_ID, IStatus.ERROR, "Tag name contains an invalid character.", null)); break; case TagSEAUtils.TAG_NAME_SYNTAX_ERROR: updateStatus(new Status(IStatus.ERROR, TagSEAPlugin.PLUGIN_ID, IStatus.ERROR, "Tag name has bad syntax.", null)); break; case TagSEAUtils.TAG_NAME_VALID: updateStatus(Status.OK_STATUS); break; } addButton.setEnabled(getStatus().isOK()); } }); tagText.addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { getShell().setDefaultButton(addButton); } public void focusLost(FocusEvent e) { getShell().setDefaultButton(getButton(Dialog.OK)); } }); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false); gd.horizontalIndent = 15; tagText.setLayoutData(gd); addButton = new Button(textComposite, SWT.PUSH); addButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); addButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); } public void widgetSelected(SelectionEvent e) { updateTagsForText(); tagText.setText(""); } }); addButton.setText("Add"); tagText.setText(""); // Delete tag button Button deleteTagButton = new Button(area, SWT.PUSH); deleteTagButton.setText("Delete"); // deleteTagButton.setEnabled(false); deleteTagButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); } public void widgetSelected(SelectionEvent e) { IStructuredSelection selection = (IStructuredSelection) tagNameListViewer.getSelection(); for (Object o : selection.toList()) { tagNames.remove(o); } tagNameListViewer.refresh(); } }); data = new GridData(SWT.END, SWT.END, false, false); data.horizontalAlignment = SWT.END; deleteTagButton.setLayoutData(data); //create a table to display the properties Table table = new Table(propertiesComposite, SWT.FLAT | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER); GridData tableGridData = new GridData(SWT.FILL, SWT.FILL, true, true); tableGridData.widthHint = 350; table.setLayoutData(tableGridData); this.propertyEditorMap = new HashMap<Object, CellEditor>(); this.propertiesViewer = new TableViewer(table); table.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); TableLayout tableLayout = new TableLayout(); tableLayout.addColumnData(new ColumnWeightData(40)); TableColumn column = new TableColumn(table, SWT.FLAT); column.setText("Property"); column.setMoveable(true); tableLayout.addColumnData(new ColumnWeightData(100)); column = new TableColumn(table, SWT.FLAT); column.setMoveable(true); column.setText("Value"); table.setLinesVisible(true); table.setLayout(tableLayout); propertiesViewer.setContentProvider(new PropertiesContentProvider()); propertiesViewer.setLabelProvider(new PropertiesLabelProvider()); this.editors = new CellEditor[] { new TextCellEditor(), new TextCellEditor() }; table.setHeaderVisible(true); propertiesViewer.setCellEditors(editors); propertiesViewer.setColumnProperties(COLUMN_PROPERTIES); propertiesViewer.setCellModifier(new WaypointCellModifier()); propertiesViewer.setInput(propertiesMap); table.addMouseListener(new CellEditorAdapter()); return propertiesComposite; }
From source file:net.sourceforge.tagsea.core.ui.TagSEAView.java
License:Open Source License
public ITag[] getSelectedTags() { ISelection selection = new StructuredSelection(); if (isViewAsCloud()) { selection = cloudViewer.getSelection(); } else {//from www .j a v a2s . c o m selection = tagTreeViewer.getViewer().getSelection(); } if (selection instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) selection; List<?> selectionList = ss.toList(); HashSet<ITag> tags = new HashSet<ITag>(); for (Object o : selectionList) { if (o instanceof ITag) { tags.add((ITag) o); } else if (o instanceof TagTreeItem) { TagTreeItem tti = (TagTreeItem) o; if (tti.getTag() != null) { tags.add(tti.getTag()); } tags.addAll(tti.getChildTags()); } } return tags.toArray(new ITag[tags.size()]); } return new ITag[0]; }
From source file:net.sourceforge.tagsea.core.ui.WaypointActionGroup.java
License:Open Source License
public WaypointActionGroup(TagSEAView view) { this.view = view; deleteAction = new Action() { @Override/*w w w.java2 s .co m*/ public void run() { ISelection selection = getContext().getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) selection; final LinkedList<IWaypoint> waypoints = new LinkedList<IWaypoint>(); for (Object o : ss.toList()) { IWaypoint wp = (IWaypoint) ((IAdaptable) o).getAdapter(IWaypoint.class); IWaypointUIExtension extension = TagSEAPlugin.getDefault().getUI() .getWaypointUI(wp.getType()); if (extension.canUIDelete(wp)) { waypoints.add(wp); } } TagSEAPlugin.run(new TagSEAOperation("Deleting Waypoints...") { public IStatus run(IProgressMonitor monitor) throws InvocationTargetException { monitor.beginTask("Deleting Waypoints", waypoints.size()); MultiStatus status = new MultiStatus(TagSEAPlugin.PLUGIN_ID, IStatus.OK, "", null); for (IWaypoint wp : waypoints) { status.merge(TagSEAPlugin.getWaypointsModel().removeWaypoint(wp).getStatus()); monitor.worked(1); if (monitor.isCanceled()) return Status.CANCEL_STATUS; } return status; } }, false); } } }; deleteAction.setText("Delete Tagged Location"); deleteAction.setToolTipText("Delete selected"); deleteAction.setImageDescriptor( TagSEAPlugin.getDefault().getImageRegistry().getDescriptor(ITagSEAImageConstants.IMG_DELETE)); //getViewSite().getActionBars().setGlobalActionHandler(ActionFactory.DELETE.getId(), deleteAction); deleteUnusedAction = new DeleteUnusedWaypointsAction(view.getSite().getShell()); deleteUnusedAction.setImageDescriptor(TagSEAPlugin.getDefault().getImageRegistry() .getDescriptor(ITagSEAImageConstants.IMG_DELETE_UNUSED)); deleteUnusedAction.setText("Cleanup Untagged Locations..."); deleteUnusedAction.setToolTipText("Cleanup TagSEA locations that do not have tags"); openFiltersAction = new Action() { @Override public void run() { WaypointFilteringDialog dialog = new WaypointFilteringDialog( WaypointActionGroup.this.view.getSite().getShell()); dialog.open(); WaypointActionGroup.this.view.scheduleRefresh(); } }; openFiltersAction.setImageDescriptor( TagSEAPlugin.getDefault().getImageRegistry().getDescriptor(ITagSEAImageConstants.IMG_FILTER)); openFiltersAction.setText("Filters..."); }
From source file:net.sourceforge.tagsea.core.ui.waypoints.TagEditDialog.java
License:Open Source License
@Override protected Control createDialogArea(Composite parent) { parent.setLayout(new GridLayout()); Composite page = new Composite(parent, SWT.FLAT); page.setLayout(new GridLayout(2, false)); page.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); Composite listComposite = new Composite(page, SWT.FLAT); GridLayout layout = new GridLayout(); layout.horizontalSpacing = 0;//from ww w .ja v a2 s . com layout.verticalSpacing = 0; listComposite.setLayout(layout); GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); data.heightHint = 200; data.widthHint = 200; listComposite.setLayoutData(data); List tagNameList = new List(listComposite, SWT.FLAT | SWT.BORDER | SWT.V_SCROLL | SWT.MULTI); tagNameListViewer = new ListViewer(tagNameList); tagNameListViewer.setContentProvider(new ArrayContentProvider()); tagNameList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); Composite textComposite = new Composite(listComposite, SWT.FLAT); layout = new GridLayout(); layout.numColumns = 2; layout.horizontalSpacing = 0; layout.verticalSpacing = 0; textComposite.setLayout(layout); data = new GridData(SWT.FILL, SWT.FILL, true, false); textComposite.setLayoutData(data); tagText = createTagText(textComposite, SWT.BORDER); tagText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { String text = tagText.getText(); text = text.trim(); if ("".equals(text)) { updateStatus(Status.OK_STATUS); addButton.setEnabled(false); return; } int valid = TagSEAUtils.isValidTagName(text); switch (valid) { case TagSEAUtils.TAG_NAME_BAD_CHARACTER: updateStatus(new Status(IStatus.ERROR, TagSEAPlugin.PLUGIN_ID, IStatus.ERROR, "Tag name contains an invalid character.", null)); break; case TagSEAUtils.TAG_NAME_SYNTAX_ERROR: updateStatus(new Status(IStatus.ERROR, TagSEAPlugin.PLUGIN_ID, IStatus.ERROR, "Tag name has bad syntax.", null)); break; case TagSEAUtils.TAG_NAME_VALID: updateStatus(Status.OK_STATUS); break; } addButton.setEnabled(getStatus().isOK()); } }); tagText.addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { getShell().setDefaultButton(addButton); } public void focusLost(FocusEvent e) { getShell().setDefaultButton(getButton(Dialog.OK)); } }); tagText.getParent().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); addButton = new Button(textComposite, SWT.PUSH); addButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); addButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); } public void widgetSelected(SelectionEvent e) { updateTagsForText(); tagText.setText(""); } }); addButton.setText("Add"); tagText.setText(""); Composite buttonComposite = new Composite(page, SWT.NONE); buttonComposite.setLayout(new GridLayout()); buttonComposite.setLayoutData(new GridData(SWT.FILL, GridData.BEGINNING, true, true)); Button selectButton = new Button(buttonComposite, SWT.PUSH); selectButton.setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false)); selectButton.setText("Select..."); selectButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); } public void widgetSelected(SelectionEvent e) { TagSelectionDialog selectionDialog = new TagSelectionDialog(TagEditDialog.this.getShell()); ArrayList<ITag> tags = new ArrayList<ITag>(); for (String name : tagNames) { ITag tag = TagSEAPlugin.getTagsModel().getTag(name); if (tag != null) { tags.add(tag); } } selectionDialog.setInitialChecks(tags.toArray(new ITag[tags.size()])); int result = selectionDialog.open(); if (result == OK) { setInitialTags(selectionDialog.getSelectedTags()); tagNameListViewer.refresh(); } } }); Button deleteButton = new Button(buttonComposite, SWT.PUSH); deleteButton.setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false)); deleteButton.setText("Remove..."); deleteButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); } public void widgetSelected(SelectionEvent e) { IStructuredSelection selection = (IStructuredSelection) tagNameListViewer.getSelection(); for (Object o : selection.toList()) { tagNames.remove(o); } tagNameListViewer.refresh(); } }); tagNameListViewer.setInput(tagNames); return page; }
From source file:net.sourceforge.tagsea.mylyn.views.TaskWaypointsDragListener.java
License:Open Source License
@Override public void dragSetData(DragSourceEvent event) { System.err.println("--> dragSetData"); IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); if (WaypointTransfer.getInstance().isSupportedType(event.dataType)) { System.err.println("Waypoint transfer"); IWaypoint[] waypoints = (IWaypoint[]) selection.toList().toArray(new IWaypoint[selection.size()]); event.data = waypoints;/* ww w . j ava 2 s . co m*/ } else if (TagTreeItemTransfer.getInstance().isSupportedType(event.dataType)) { System.err.println("Tag Tree transfer"); ITag[] tags = (ITag[]) selection.toList().toArray(new ITag[selection.size()]); event.data = tags; } else if (TagNameTransfer.getInstance().isSupportedType(event.dataType)) { System.err.println("Tag name transfer"); String[] tagNames = (String[]) selection.toList().toArray(new String[selection.size()]); event.data = tagNames; } else if (PluginTransfer.getInstance().isSupportedType(event.dataType)) { System.err.println("Plug-in transfer"); System.err.println("Event data type: " + event.dataType); byte[] data = "Test".getBytes(); event.data = new PluginTransferData("net.sourceforge.tagsea.mylyn.drop", data); //byte[] data = GadgetTransfer.getInstance().toByteArray(gadgets); //event.data = new PluginTransferData("org.eclipse.ui.examples.gdt.gadgetDrop", data); } }
From source file:net.sourceforge.tagsea.mylyn.waypoints.WaypointsUtils.java
License:Open Source License
public static List<IWaypoint> getWaypoints(StructuredSelection structuredSelection) { IStructuredSelection ss = (IStructuredSelection) ((IStructuredSelection) structuredSelection); Object o = ss.getFirstElement(); if (o instanceof TagTreeItem) { TagTreeItem[] items = new TagTreeItem[ss.size()]; int index = 0; for (Object selection : ss.toList()) { items[index] = (TagTreeItem) selection; index++;//ww w. j a v a 2 s . co m } return WaypointsUtils.convertTagsToWaypoints(items); } if (o instanceof IWaypoint) { IWaypoint waypoint = (IWaypoint) o; List<IWaypoint> waypointList = new ArrayList<IWaypoint>(); waypointList.add(waypoint); return waypointList; } return Collections.EMPTY_LIST; }
From source file:no.javatime.util.messages.views.MessageView.java
License:Open Source License
/** * Create all actions and assign text, tool tip and images *//*from ww w .j av a 2 s . c o m*/ private void makeActions() { traceEventsAction = new Action("Trace Bundle Events", Action.AS_CHECK_BOX) { //$NON-NLS-1$ public void run() { Boolean traceEvents = traceEventsAction.isChecked(); Category.setState(Category.bundleEvents, traceEvents); if (traceEvents) { traceEventsAction .setImageDescriptor(Activator.getImageDescriptor("icons/enable_trace_events.png")); //$NON-NLS-1$ } else { traceEventsAction .setImageDescriptor(Activator.getImageDescriptor("icons/disable_trace_events.png")); //$NON-NLS-1$ } } }; traceEventsAction.setId("traceEventsAction"); //$NON-NLS-1$ traceEventsAction.setToolTipText("Trace Bundle and Framework Events"); //$NON-NLS-1$ traceOperationsAction = new Action("Trace Bundle Operations", Action.AS_CHECK_BOX) { //$NON-NLS-1$ public void run() { Boolean traceOp = traceOperationsAction.isChecked(); Category.setState(Category.bundleOperations, traceOp); if (traceOp) { traceOperationsAction .setImageDescriptor(Activator.getImageDescriptor("icons/enable_trace_op.png")); //$NON-NLS-1$ } else { traceOperationsAction .setImageDescriptor(Activator.getImageDescriptor("icons/disable_trace_op.png")); //$NON-NLS-1$ } } }; traceOperationsAction.setId("traceOperationsAction"); //$NON-NLS-1$ traceOperationsAction.setToolTipText("Trace Bundle Life Cycle Operations"); //$NON-NLS-1$ infoMessageAction = new Action("Information Messages", Action.AS_CHECK_BOX) { //$NON-NLS-1$ public void run() { Boolean infoEvents = infoMessageAction.isChecked(); Category.setState(Category.infoMessages, infoEvents); if (infoEvents) { infoMessageAction.setImageDescriptor(Activator.getImageDescriptor("icons/process_info.png")); //$NON-NLS-1$ } else { infoMessageAction.setImageDescriptor(Activator.getImageDescriptor("icons/no_process_info.png")); //$NON-NLS-1$ } } }; infoMessageAction.setId("infoMessageAction"); //$NON-NLS-1$ infoMessageAction.setToolTipText("Information Messages"); //$NON-NLS-1$ clearAction = new Action("C&lear") { //$NON-NLS-1$ public void run() { MessageContainer.getInstance().clearMessages(); viewer.refresh(); toggleClipboardActions((contentProvider.size()) > 0 ? true : false); } }; clearAction.setToolTipText("Clear the message view"); //$NON-NLS-1$ clearAction.setImageDescriptor(Activator.getImageDescriptor("icons/clear.gif")); //$NON-NLS-1$ clearAction.setEnabled(true); copyAction = new Action("&Copy \tCtrl+C") { //$NON-NLS-1$ public void run() { IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); if (null != selection) { Collection<IStructuredSelection> values = selection.toList(); copyValues(values); } } }; copyAction.setToolTipText("Copy selected message(s)"); //$NON-NLS-1$ copyAction.setImageDescriptor( PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_COPY)); selectAllAction = new Action("Select &All \tCtrl+A") { //$NON-NLS-1$ public void run() { viewer.getTable().selectAll(); toggleClipboardActions(true); } }; selectAllAction.setToolTipText("Select all message(s)"); //$NON-NLS-1$ selectAllAction.setImageDescriptor(Activator.getImageDescriptor("icons/select_all.png")); //$NON-NLS-1$ doubleClickAction = new Action() { public void run() { ISelection selection = viewer.getSelection(); Object obj = ((IStructuredSelection) selection).getFirstElement(); showMessage(obj.toString()); } }; }
From source file:org.apache.directory.studio.connection.ui.actions.SelectionUtils.java
License:Apache License
/** * Gets all beans of the requested type contained in the given selection. * * @param selection the selection/* w w w . jav a 2 s .c om*/ * @param type the requested type * @return a list containg beans of the requesten type */ private static List<Object> getTypes(ISelection selection, Class<?> type) { List<Object> list = new ArrayList<>(); if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; for (Object object : structuredSelection.toList()) { if (type.isInstance(object)) { list.add(object); } } } return list; }
From source file:org.apache.hadoop.eclipse.actions.DFSActionImpl.java
License:Apache License
/** * Extract the list of <T> from the structured selection * // w w w. j ava 2s . co m * @param clazz the class T * @param selection the structured selection * @return the list of <T> it contains */ private static <T> List<T> filterSelection(Class<T> clazz, IStructuredSelection selection) { List<T> list = new ArrayList<T>(); for (Object obj : selection.toList()) { if (clazz.isAssignableFrom(obj.getClass())) { list.add((T) obj); } } return list; }