List of usage examples for org.eclipse.jface.viewers StructuredSelection toList
@Override
public List toList()
From source file:org.eclipse.mylyn.internal.context.ui.actions.AbstractInterestManipulationAction.java
License:Open Source License
public void run(IAction action) { IInteractionContext context = getContext(); boolean increment = !isRemove(); if (selection instanceof StructuredSelection) { StructuredSelection structuredSelection = (StructuredSelection) selection; List<IInteractionElement> nodes = new ArrayList<IInteractionElement>(); for (Object object : structuredSelection.toList()) { IInteractionElement node = convertSelectionToInteractionElement(context, object); nodes.add(node);/* w ww.j a v a2 s . c o m*/ } if (nodes != null && nodes.size() > 0) { if (!increment) { try { // NOTE: need to set the selection null so the // automatic reselection does not induce interest PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart() .getSite().getSelectionProvider().setSelection(StructuredSelection.EMPTY); } catch (Exception e) { // ignore } } boolean manipulated = ContextCorePlugin.getContextManager().manipulateInterestForElements(nodes, increment, false, preserveUninteresting, SOURCE_ID, context, true); if (!manipulated) { AbstractInterestManipulationAction.displayInterestManipulationFailure(); } } } else { IInteractionElement node = ContextCore.getContextManager().getActiveElement(); if (node != null) { boolean manipulated = ContextCorePlugin.getContextManager().manipulateInterestForElement(node, increment, false, false, SOURCE_ID, ContextCore.getContextManager().getActiveContext(), true); if (!manipulated) { AbstractInterestManipulationAction.displayInterestManipulationFailure(); } } else { MessageDialog.openInformation(Display.getCurrent().getActiveShell(), Messages.AbstractInterestManipulationAction_Interest_Manipulation, Messages.AbstractInterestManipulationAction_No_task_context_is_active); } } ContextCorePlugin.getContextManager().saveContext(context); }
From source file:org.eclipse.mylyn.internal.github.ui.gist.GistAttachmentPart.java
License:Open Source License
protected void openAttachments(OpenEvent event) { List<ITaskAttachment> attachments = new ArrayList<ITaskAttachment>(); StructuredSelection selection = (StructuredSelection) event.getSelection(); List<?> items = selection.toList(); for (Object item : items) if (item instanceof ITaskAttachment) attachments.add((ITaskAttachment) item); if (attachments.isEmpty()) return;/*from ww w .j av a 2s . c om*/ IWorkbenchPage page = getTaskEditorPage().getSite().getWorkbenchWindow().getActivePage(); try { OpenTaskAttachmentHandler.openAttachments(page, attachments); } catch (OperationCanceledException e) { // canceled } }
From source file:org.eclipse.mylyn.internal.monitor.reports.ui.actions.EclipseUsageSummaryAction.java
License:Open Source License
/** * TODO: move/*ww w .j a va2 s . co m*/ */ public static List<File> getStatsFilesFromSelection(ViewPluginAction objectAction) { final List<File> files = new ArrayList<File>(); if (objectAction.getSelection() instanceof StructuredSelection) { StructuredSelection structuredSelection = (StructuredSelection) objectAction.getSelection(); for (Object object : structuredSelection.toList()) { if (object instanceof IFile) { IFile file = (IFile) object; if (file.getFileExtension().equals("zip")) { files.add(new File(file.getLocation().toString())); } } } } Collections.sort(files); // ensure that they are sorted by date if (files.isEmpty()) { files.add(UiUsageMonitorPlugin.getDefault().getMonitorLogFile()); } return files; }
From source file:org.eclipse.mylyn.internal.tasks.ui.editors.TaskEditorAttachmentPart.java
License:Open Source License
protected void openAttachments(OpenEvent event) { List<ITaskAttachment> attachments = new ArrayList<ITaskAttachment>(); StructuredSelection selection = (StructuredSelection) event.getSelection(); List<?> items = selection.toList(); for (Object item : items) { if (item instanceof ITaskAttachment) { attachments.add((ITaskAttachment) item); }//w ww . j av a 2 s . co m } if (attachments.isEmpty()) { return; } IWorkbenchPage page = getTaskEditorPage().getSite().getWorkbenchWindow().getActivePage(); try { OpenTaskAttachmentHandler.openAttachments(page, attachments); } catch (OperationCanceledException e) { // canceled } }
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 www. j a v a 2s . c o m*/ } } if (selectedElements.size() < originalSelectionSize) { e.getSelectionProvider().setSelection(new StructuredSelection(selectedElements)); } } }
From source file:org.eclipse.paho.mqtt.ui.views.MQTTTab.java
License:Open Source License
private Group createSubscriptionGroup(Composite container) { // XXX topic model - need to save it? final List<Topic> topics = new ArrayList<Topic>(); ///*from w ww.j a v a 2 s .co m*/ final Group group = new Group(container, SWT.NONE); group.setText(Messages.MQTT_TAB_GROUP_SUB); GridLayout subgrpLayout = new GridLayout(); subgrpLayout.numColumns = 1; subgrpLayout.marginTop = 0; subgrpLayout.marginBottom = 0; subgrpLayout.verticalSpacing = 0; group.setLayout(subgrpLayout); GridData subgd = new GridData(GridData.FILL_BOTH); // subgd.heightHint = 100; group.setLayoutData(subgd); // Toolbar ToolBar toolBar = new ToolBar(group, SWT.NONE); // add ToolItem itemAdd = new ToolItem(toolBar, SWT.FLAT); itemAdd.setImage(Images.get(ImageKeys.IMG_ADD)); itemAdd.setDisabledImage(Images.get(ImageKeys.IMG_ADD_GRAY)); itemAdd.setToolTipText(Messages.MQTT_TAB_GROUP_SUB_ADD_BTN_TOOLTIP); itemAdd.addSelectionListener(new SelectionAdapter() { @SuppressWarnings("unchecked") public void widgetSelected(SelectionEvent e) { Display.getDefault().asyncExec(new Runnable() { @Override public void run() { Topic t = new Topic("test", QoS.AT_MOST_ONCE); //$NON-NLS-1$ ((List<Topic>) viewer.getInput()).add(t); viewer.refresh(); viewer.setChecked(t, true); // select the added topic viewer.setSelection(new StructuredSelection(t)); // begin edit the added topic string cell viewer.editElement(t, 1); // update sub/unsub buttons subscribeButtonsUpdater.update(true); } }); } }); // delete final ToolItem itemRemove = new ToolItem(toolBar, SWT.FLAT); itemRemove.setImage(Images.get(ImageKeys.IMG_REMOVE)); itemRemove.setDisabledImage(Images.get(ImageKeys.IMG_REMOVE_GRAY)); itemRemove.setToolTipText(Messages.MQTT_TAB_GROUP_SUB_RM_BTN_TOOLTIP); itemRemove.setEnabled(false); itemRemove.addSelectionListener(new SelectionAdapter() { @SuppressWarnings("unchecked") public void widgetSelected(SelectionEvent e) { Display.getDefault().asyncExec(new Runnable() { @Override public void run() { StructuredSelection selection = (StructuredSelection) viewer.getSelection(); List<Topic> input = ((List<Topic>) viewer.getInput()); int index = -1; for (Topic t : (List<Topic>) selection.toList()) { if (index == -1) { index = input.indexOf(t); } input.remove(t); } viewer.refresh(); // select previous index if (!input.isEmpty()) { index = index - 1 >= 0 ? index - 1 : 0; viewer.setSelection(new StructuredSelection(input.get(index))); } // update sub/unsub buttons subscribeButtonsUpdater.update(viewer.getCheckedElements().length > 0); } }); } }); // clear ToolItem itemClear = new ToolItem(toolBar, SWT.FLAT); itemClear.setImage(Images.get(ImageKeys.IMG_CLEAR)); // itemClear.setDisabledImage(Images.get("clear_gray")); itemClear.setToolTipText(Messages.MQTT_TAB_GROUP_SUB_CLEAR_BTN_TOOLTIP); itemClear.setEnabled(true); itemClear.addSelectionListener(new SelectionAdapter() { @SuppressWarnings("unchecked") public void widgetSelected(SelectionEvent e) { Display.getDefault().asyncExec(new Runnable() { @Override public void run() { ((List<Topic>) viewer.getInput()).clear(); viewer.refresh(); // update sub/unsub buttons subscribeButtonsUpdater.update(false); } }); } }); // Topic Table view Composite subComp = new Composite(group, SWT.NONE); subComp.setLayoutData(new GridData(GridData.FILL_BOTH)); // Note: using V_SCROLL | NO_SCROLL to force disable H_SCROLL TableViewerBuilder builder = new TableViewerBuilder(subComp, SWT.MULTI | SWT.V_SCROLL | SWT.NO_SCROLL | SWT.FULL_SELECTION | SWT.BORDER | SWT.CHECK) .selectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { Display.getDefault().asyncExec(new Runnable() { @Override public void run() { itemRemove.setEnabled(!viewer.getSelection().isEmpty()); } }); } }).checkStateListener(new ICheckStateListener() { @Override public void checkStateChanged(CheckStateChangedEvent event) { Display.getDefault().asyncExec(new Runnable() { @Override public void run() { subscribeButtonsUpdater.update(viewer.getCheckedElements().length > 0); } }); } }).makeEditable().input(topics); viewer = builder.buildCheckable(); // build columns // checkbox column builder.columnBuilder("", SWT.LEFT).pixelWidth(50).emptyCellLabelProvider().build(); // Topic column builder.columnBuilder(Messages.MQTT_TAB_GROUP_SUB_TOPIC, SWT.LEFT).percentWidth(60) .cellLabelProvider(new ColumnLabelProvider() { @Override public String getText(Object element) { Topic t = (Topic) element; return t.getTopicString(); } @Override public String getToolTipText(Object element) { return Messages.TOOLTIP_DBCLICK_TO_EDIT; } }).editingSupport(new TopicStringCellEditor(viewer)).build(); // QoS column builder.columnBuilder(Messages.MQTT_TAB_GROUP_SUB_QOS, SWT.CENTER).percentWidth(40) .editingSupport(new TopicQosCellEditor(viewer)).cellLabelProvider(new ColumnLabelProvider() { @Override public String getText(Object element) { Topic t = (Topic) element; return t.getQos().getLabel(); } @Override public String getToolTipText(Object element) { return Messages.TOOLTIP_DBCLICK_TO_EDIT; } }).build(); // ********************************************** // Row: Sub/Unsub button // ********************************************** Composite subBtnContainerForm = new Composite(group, SWT.NONE); subBtnContainerForm.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); subBtnContainerForm.setLayout(new FormLayout()); // layout Composite subBtnContainerParent = new Composite(subBtnContainerForm, SWT.NONE); FormData fd = new FormData(); // 80: manually checked value fd.left = new FormAttachment(0, 80); fd.top = new FormAttachment(0, 10); fd.right = new FormAttachment(100, 0); subBtnContainerParent.setLayoutData(fd); RowLayout subBtnLayout = new RowLayout(); // all widgets are the same size subBtnLayout.pack = false; // widgets are spread across the available space subBtnLayout.justify = true; subBtnLayout.type = SWT.HORIZONTAL; subBtnLayout.spacing = 0; subBtnContainerParent.setLayout(subBtnLayout); Composite subBtnContainer = new Composite(subBtnContainerParent, SWT.NONE); GridLayout subBtnContainerLayout = new GridLayout(); subBtnContainerLayout.numColumns = 2; subBtnContainerLayout.horizontalSpacing = 10; subBtnContainer.setLayout(subBtnContainerLayout); // sub - btn final Button btnSub = new Button(subBtnContainer, SWT.NONE); btnSub.setText(Messages.MQTT_TAB_GROUP_SUB_BTN_SUB); GridData btnSubGD = new GridData(); btnSubGD.widthHint = BUTTON_WIDTH; btnSub.setLayoutData(btnSubGD); btnSub.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { List<Topic> topics = new ArrayList<Topic>(); for (Object o : viewer.getCheckedElements()) { topics.add((Topic) o); } eventService.sendEvent(Events.of(Selector.ofSubscribe(), Pair.of(connection, topics))); } }); // unsub - btn final Button btnUnsub = new Button(subBtnContainer, SWT.NONE); btnUnsub.setText(Messages.MQTT_TAB_GROUP_SUB_BTN_UNSUB); GridData btnUnsubGD = new GridData(); btnUnsubGD.widthHint = BUTTON_WIDTH; btnUnsub.setLayoutData(btnUnsubGD); btnUnsub.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { List<Topic> topics = new ArrayList<Topic>(); for (Object o : viewer.getCheckedElements()) { topics.add((Topic) o); } eventService.sendEvent(Events.of(Selector.ofUnsubscribe(), Pair.of(connection, topics))); } }); // view updater subscriptionViewUpdater = new ViewUpdater<Boolean>() { @Override public void update(Boolean connected) { Widgets.enable(group, connected); subscribeButtonsUpdater.update(connected && viewer.getCheckedElements().length > 0); } }; subscribeButtonsUpdater = new ViewUpdater<Boolean>() { @Override public void update(Boolean enabled) { btnSub.setEnabled(enabled); btnUnsub.setEnabled(enabled); } }; // disabled for init state Widgets.enable(group, false); return group; }
From source file:org.eclipse.paho.mqtt.ui.views.OptionsTab.java
License:Open Source License
private void createHAGroup(Composite container) { final Group group = new Group(container, SWT.NONE); group.setText(Messages.OPT_TAB_GROUP_HA); // layout// ww w. ja v a2 s.co m GridLayout layout = new GridLayout(); layout.numColumns = 1; layout.marginTop = 0; layout.marginBottom = 10; layout.verticalSpacing = 0; group.setLayout(layout); group.setLayoutData(new GridData(GridData.FILL_BOTH)); // Toolbar ToolBar toolBar = new ToolBar(group, SWT.NONE); // add ToolItem itemAdd = new ToolItem(toolBar, SWT.FLAT); itemAdd.setImage(Images.get(ImageKeys.IMG_ADD)); itemAdd.setDisabledImage(Images.get(ImageKeys.IMG_ADD_GRAY)); itemAdd.setToolTipText(Messages.OPT_TAB_GROUP_HA_ADD_BTN_TOOLTIP); itemAdd.addSelectionListener(new SelectionAdapter() { @SuppressWarnings("unchecked") public void widgetSelected(SelectionEvent e) { Display.getDefault().asyncExec(new Runnable() { @Override public void run() { ServerURI uri = new ServerURI(Constants.TCP_SERVER_URI); ((List<ServerURI>) viewer.getInput()).add(uri); viewer.refresh(); // select the added uri viewer.setSelection(new StructuredSelection(uri)); viewer.editElement(uri, 1); } }); } }); // remove final ToolItem itemRemove = new ToolItem(toolBar, SWT.FLAT); itemRemove.setImage(Images.get(ImageKeys.IMG_REMOVE)); itemRemove.setDisabledImage(Images.get(ImageKeys.IMG_REMOVE_GRAY)); itemRemove.setToolTipText(Messages.OPT_TAB_GROUP_HA_RM_BTN_TOOLTIP); itemRemove.setEnabled(false); itemRemove.addSelectionListener(new SelectionAdapter() { @SuppressWarnings("unchecked") public void widgetSelected(SelectionEvent e) { Display.getDefault().asyncExec(new Runnable() { @Override public void run() { StructuredSelection selection = (StructuredSelection) viewer.getSelection(); List<ServerURI> input = ((List<ServerURI>) viewer.getInput()); int index = -1; for (ServerURI uri : (List<ServerURI>) selection.toList()) { if (index == -1) { index = input.indexOf(uri); } input.remove(uri); } viewer.refresh(); // select previous index if (!input.isEmpty()) { index = index - 1 >= 0 ? index - 1 : 0; viewer.setSelection(new StructuredSelection(input.get(index))); } } }); } }); // clear ToolItem itemClear = new ToolItem(toolBar, SWT.FLAT); itemClear.setImage(Images.get(ImageKeys.IMG_CLEAR)); // itemClear.setDisabledImage(Images.get("clear_gray")); itemClear.setToolTipText(Messages.OPT_TAB_GROUP_HA_CLEAR_BTN_TOOLTIP); itemClear.setEnabled(true); itemClear.addSelectionListener(new SelectionAdapter() { @SuppressWarnings("unchecked") public void widgetSelected(SelectionEvent e) { Display.getDefault().asyncExec(new Runnable() { @Override public void run() { ((List<ServerURI>) viewer.getInput()).clear(); viewer.refresh(); } }); } }); // Table viewer Composite composite = new Composite(group, SWT.NONE); composite.setLayoutData(new GridData(GridData.FILL_BOTH)); // Note: using V_SCROLL | NO_SCROLL to force disable H_SCROLL TableViewerBuilder builder = new TableViewerBuilder(composite, SWT.MULTI | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.NO_SCROLL | SWT.BORDER) .selectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { Display.getDefault().asyncExec(new Runnable() { @Override public void run() { itemRemove.setEnabled(!viewer.getSelection().isEmpty()); } }); } }).makeEditable().input(connection.getOptions().getServerURIs()); // build the table viewer viewer = builder.build(); // table columns // First extra column to display error message builder.columnBuilder("", SWT.LEFT).pixelWidth(20).emptyCellLabelProvider().build(); builder.columnBuilder(Messages.OPT_TAB_GROUP_HA_SERVER_URIS, SWT.LEFT).percentWidth(90) .cellLabelProvider(new ColumnLabelProvider() { @Override public String getText(Object element) { return ((ServerURI) element).getValue(); } @Override public String getToolTipText(Object element) { return Messages.TOOLTIP_DBCLICK_TO_EDIT; } }).editingSupport(new ServerUriCellEditor(viewer)).build(); viewer.refresh(); // initial state Widgets.enable(group, connection.getOptions().isHaEnabled()); haViewUpdater = new ViewUpdater<Boolean>() { @Override public void update(Boolean selected) { Widgets.enable(group, selected); viewer.refresh(); } }; }
From source file:org.eclipse.papyrus.diagram.common.util.DiagramEditPartsUtil.java
License:Open Source License
/** * Finds the <EditPart>s for the <EObject>s in the selection. * /*w w w .j a v a 2s. c o m*/ * @param selection * the selection * @param viewer * the viewer * * @return the edits the parts from selection */ // @unused public static List<EditPart> getEditPartsFromSelection(ISelection selection, IDiagramGraphicalViewer viewer) { if (selection instanceof StructuredSelection && !selection.isEmpty()) { StructuredSelection structuredSelection = (StructuredSelection) selection; // look for Views of the EObjects in the selection List<View> views = new ArrayList<View>(); for (Object o : structuredSelection.toList()) { if (o instanceof EObject) { List referencerViews = getEObjectViews((EObject) o); for (Object ro : referencerViews) { if (ro instanceof View) { views.add((View) ro); } } } } if (!views.isEmpty()) { List<EditPart> editParts = new ArrayList<EditPart>(); for (View view : views) { Object ep = viewer.getEditPartRegistry().get(view); if (ep instanceof EditPart) { editParts.add((EditPart) ep); } } if (!editParts.isEmpty()) { return editParts; } } } return Collections.EMPTY_LIST; }
From source file:org.eclipse.papyrus.modelexplorer.factory.DefaultEMFActionsFactory.java
License:Open Source License
/** * {@inheritDoc}/* w ww .j a va 2 s .co m*/ */ @SuppressWarnings({ "rawtypes", "unchecked" }) public void update(IStructuredSelection structuredSelection) { ArrayList array = new ArrayList(); Iterator iterator = structuredSelection.iterator(); while (iterator.hasNext()) { Object object = iterator.next(); if (NavigatorUtils.resolveSemanticObject(object) != null) { array.add(NavigatorUtils.resolveSemanticObject(object)); } } StructuredSelection st = new StructuredSelection(array); cutAction.updateSelection(st); cutAction.setEnabled((cutAction.createCommand(st.toList())).canExecute()); copyAction.updateSelection(st); copyAction.setEnabled((copyAction.createCommand(st.toList())).canExecute()); pasteAction.updateSelection(st); pasteAction.setEnabled((pasteAction.createCommand(st.toList())).canExecute()); loadResourceAction.update(); }
From source file:org.eclipse.scout.rt.ui.rap.basic.tree.RwtScoutTree.java
License:Open Source License
/** * @param event/*from ww w . j a v a 2 s. c om*/ */ private void handleUiDoubleClick(StructuredSelection sel) { @SuppressWarnings("unchecked") ITreeNode[] nodes = (ITreeNode[]) sel.toList().toArray(new ITreeNode[sel.size()]); if (nodes != null && nodes.length == 1) { // if not leaf expand collapse if (!nodes[0].isLeaf()) { // invert expansion setExpansionFromUi(nodes[0], !getUiTreeViewer().getExpandedState(nodes[0])); } else { handleUiNodeAction(nodes[0]); if (getScoutObject().isCheckable()) { handleUiNodeClick(nodes[0]); } } } }